summaryrefslogtreecommitdiff
path: root/include/driver.h
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'for-next/usb'Sascha Hauer2023-04-191-0/+2
|\
| * driver: Add unregister_driver()Sascha Hauer2023-03-211-0/+2
| | | | | | | | | | | | | | Registering drivers is one thing, getting rid of them another. Add unregister_driver() which is used in the coming USB gadget update. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | usb: dwc3: populate parent of xHCI devAhmad Fatoum2023-04-171-2/+10
|/ | | | | | | | | | Reparent xHCIs instantiated from DWC3 controllers to their parents instead of them being direct children of the bus. Apart from improving devinfo/drvinfo output, this should introduce no functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230414145259.3644816-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Add rescan hook to struct deviceSascha Hauer2023-03-101-0/+6
| | | | | | | | | | | | | When devices are enabled with a device tree overlay the newly enabled devices can be probed by doing a of_probe(). This works fine for the regular platform devices, but doesn't work for devices which are not probed by the core, but by the subsystem. Prominent examples are I2C or SPI devices. This patch adds a struct device::rescan hook that subsystems can implement to trigger rescanning the device nodes. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: devfs: implement cdev_fdopenAhmad Fatoum2023-01-311-0/+1
| | | | | | | | | | | As an alternative to cdev_open and using cdev_read/write, we define a new cdev_fdopen function that returns a file descriptor. The benefit of this is that code using it may use all the more high level helpers we have for reading/writing file descriptors. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20230130072707.2423294-2-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: alias of_match_ptr and DRV_OF_COMPATAhmad Fatoum2023-01-231-1/+3
| | | | | | | | | Linux calls our DRV_OF_COMPAT of_match_ptr. Support both names for a while with the intention of removing DRV_OF_COMPAT Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230116134501.2006391-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc-struct-rename'Sascha Hauer2023-01-201-3/+0
|\
| * driver: drop no longer used RW_SIZE/_MASK macrosAhmad Fatoum2023-01-121-3/+0
| | | | | | | | | | | | | | | | | | | | O_RWSIZE_MASK is what's now used and it's passed as argument to open. There remain no users of either RW_SIZE or RW_SIZE_MASK. Remove to avoid confusion. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230111120002.1104864-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | mtd: nand: atmel: import Linux NAND controller driverAhmad Fatoum2023-01-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | For a few years, Linux has been using the new EBI bindings for NAND controllers on all AT91 SoCs newer than the AT91RM2000. We have so far only supported the old bindings by hacking the DT, but this doesn't suffice for the SAMA5D4. Therefore import a new state of the Linux NAND controller driver. We still keep around the old barebox driver to support the non-DT enabled AT91 platforms. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230111174023.1719129-13-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/kernelcode-helpers' into HEADSascha Hauer2023-01-171-2/+2
|\ \
| * | include: driver: make dev_(get_priv|is_probed) argument const pointerAhmad Fatoum2023-01-101-2/+2
| |/ | | | | | | | | | | | | | | | | This enables us to use the helpers in functions that themselves take a const pointer to document their usage. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230109151152.2052493-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | driver: implement dev_request_resourceAhmad Fatoum2023-01-161-0/+3
| | | | | | | | | | | | | | | | | | dev_request_resource is useful for porting kernel drivers that use devm_request_source on a resource retrieved via <linux/of_address.h>. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230111174023.1719129-9-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | driver: always ensure probe of RAM registered with mem_platform_driverAhmad Fatoum2023-01-121-2/+11
|/ | | | | | | | | | | | | | | | | | | Normally, SDRAM controllers are already set up by the time barebox proper runs. The function of SDRAM controller drivers is thus limited to reading out configured SDRAM size and registering the result as a barebox memory bank. This needs to happen before MMU setup, so the whole of RAM can be initially mapped cacheable. Therefore, probe order is enforced either via initcall level or via of_devices_ensure_probed_by_dev_id on deep-probe-enabled systems. We have this opencoded at two places and instead of adding a third, just rewrite mem_platform_driver to do the expected thing. Acked-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230109130822.1657470-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: add of_match_table as alias to of_compatibleAhmad Fatoum2023-01-101-1/+4
| | | | | | | | | | In order to reduce trivial differences between barebox and Linux to simplify driver porting. Add of_match_table as alias to of_compatible in struct driver. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230109152926.2191465-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct driver_d to driverSascha Hauer2023-01-101-8/+9
| | | | | | | | | | | The '_d' suffix was originally meant to distinguish barebox struct names from Linux struct names. struct driver doesn't exist in Linux, so we can rename it and remove the meaningless suffix. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-64/+70
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename device_d::device_node to device_d::of_nodeSascha Hauer2023-01-101-2/+5
| | | | | | | | | | | | | | | | | | | | Linux struct device has the member of_node for the device_node pointer. Rename this in barebox accordingly to minimize the necessary changes when porting Linux code. This was done with the semantic patch: @@ struct device_d E; @@ - E.device_node + E.of_node @@ struct device_d *E; @@ - E->device_node + E->of_node Plus some manual adjustments. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: have dev_name(unregistered device) behave as expectedAhmad Fatoum2023-01-091-1/+3
| | | | | | | | | | | | | For drivers that create new virtual child devices, error paths often tend to use dev_name() on the uninitialized device via the dev_ family of logging functions. Many such uninitialized devices have a name set already though, but just lacks registration, which leads to dev_id returning dev->unique_name, which may be NULL. Change dev_name to return dev->name if dev->unique_name is NULL. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Link: https://lore.barebox.org/20230109083600.1820078-1-ahmad@a3f.at Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/misc'Sascha Hauer2022-10-131-0/+2
|\
| * driver: don't crash when dev_name/dev_id is called with NULL devAhmad Fatoum2022-10-111-0/+2
| | | | | | | | | | | | | | | | | | | | cdev->dev being NULL is normal for virtual device files like /dev/null, but can trip developers over. Ensure dev_name(cdev->dev) returns NULL instead of crashing for more robustness. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221010061122.2084009-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | driver: add dev_is_probed() helper functionOleksij Rempel2022-10-041-0/+5
|/ | | | | | | | Add function to get device/driver probe state. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220926081740.76968-2-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: implement find_device() helperAhmad Fatoum2022-09-131-0/+5
| | | | | | | | | | For use in commands like done in the follow-up commits, it can be useful to have a best effort find_device, that not only finds by device name, but also by device tree path or alias. Add such a helper. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220905103546.1476277-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/rk808'Sascha Hauer2022-08-111-1/+1
|\
| * mfd: implement mfd_add_devicesAhmad Fatoum2022-08-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | This makes it easier to port Linux drivers like PMICs, where a device tree probed MFD node exists and the driver matching against it then registers a number of MFD cell devices, which don't have their own DT compatibles. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220724190006.2160802-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | base: driver: print dev_err_probe message on permanent probe deferralJohannes Zink2022-07-121-0/+5
|/ | | | | | | | | | | | | | | This stores the probe deferral reason in the device structure. If a probe is permanently deferred, the last reason is displayed. Example output on a permanently deferred probe: ERROR: imx-pgc-domain0: probe permanently deferred (Failed to get domain's regulator) Other dev_err_probe outputs are displayed as before. Signed-off-by: Johannes Zink <j.zink@pengutronix.de> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220708094138.112060-1-j.zink@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: add dev_get_priv() helperOleksij Rempel2022-04-141-0/+5
| | | | | | | | | Add dev_get_priv() to make driver porting easier. Needed for SJA11xx switch driver. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220413082205.429509-6-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* clk: stm32mp1: sync with Linux v5.17-rc1Ahmad Fatoum2022-03-081-0/+5
| | | | | | | | | | | | Linux has meanwhile extended the RCC driver to support both reset and clocks as well as peaceful co-existence with the SCMI driver. Import these changes into barebox and remove the reset controller handling from the old RCC reset driver. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220220124736.3052502-22-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* firmware: import Linux v5.13 SCMI supportAhmad Fatoum2022-02-231-0/+3
| | | | | | | | | | | | | | | | | The ARM System Control and Management Interface (SCMI) is a standard way to offload handling of system resources like clocks, resets and power domain handling to the firmware. This should replace Silicon Provider specific conduits for new SoCs. Systems where this is already relevant: - STM32MP1: For trusted boot, the clock and reset controller are managed from secure world. This is not yet supported by barebox and must be disabled in TF-A - RK3568: At least the CPU clock is only controllable via SCMI - i.MX8X: Communication with the SCU occurs via SCMI Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220220124736.3052502-13-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: create iterator for cdev listSascha Hauer2022-02-081-0/+4
| | | | | | | | This creates an iterator to iterate over all availabe cdevs. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-7-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: Create missing cdev_* functionsSascha Hauer2022-02-081-0/+5
| | | | | | | | | | We have several functions like cdev_read(), cdev_write() and others. For consistency create the remaining functions: cdev_lseek(), cdev_protect(), cdev_discard_range(), cdev_memmap() and cdev_truncate() Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-6-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: Add functions to free devicesSascha Hauer2022-02-081-0/+4
| | | | | | | | | | | | | | | | | struct device_d has some dynamically allocated members, namely .name and .unique_name. These are normally not freed when a device is freed. Add two functions to free these resources. free_device_res() only frees the allocated members, but not the device itself. This is suitable for cases where the device is embedded in another struct. free_device() frees the allocated members along with the device itself. This can be called when the device itself has been directly allocated. Some users which should use these functions are also fixed in this patch. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-5-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: implement cdev_open()Sascha Hauer2022-02-081-1/+1
| | | | | | | | | | | Implement cdev_open() with the expected semantics that takes a struct cdev * argument. We already have an unimplemented prototype cdev_do_open(), remove this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-4-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* rename cdev_open() -> cdev_open_by_name()Sascha Hauer2022-02-081-1/+1
| | | | | | | | | | | | The cdev_* functions normally take a struct cdev * argument, with the exception of cdev_open(). Rename cdev_open() to cdev_open_by_name() to be able to implement cdev_open() with the expected semantics in the next step. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: add diskuuid supportMichael Olbrich2022-02-081-0/+1
| | | | | | | | | | | | This allows identifying disks by UUID. For disks with GPT the disk GUID is used. For DOS partition tables the NT signature ist used, similar to how the partuuid is generated. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Link: https://lore.barebox.org/20220124100458.2924679-3-m.olbrich@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: rename partuuid to uuidMichael Olbrich2022-02-081-2/+2
| | | | | | | | | | | Partitions are not the only devices that can have UUIDs. Change the name to something more generic to prepare for other users. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> Link: https://lore.barebox.org/20220124100458.2924679-2-m.olbrich@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20220207094953.949868-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: add new devunbind debugging commandAhmad Fatoum2022-01-141-0/+4
| | | | | | | | | | | | Memory corruption around device removal may go unnoticed, because barebox is shutting down anyway and doing no new allocations. Add a new devunbind command that should help with debugging such issues by allowing selective unbinding and removal of devices. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220113160414.3943151-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* cdev: Add function to get unallocated space at start of deviceSascha Hauer2021-10-121-0/+1
| | | | | | | | | | | On several SoCs barebox is written to the raw device in front of the first partition. So far we blindly trust that there is enough space available for the barebox image. Start changing this by adding a function that retrieves the available space. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20211012073352.4071559-8-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nvmem: add support for new read-only memory (rmem) bindingAhmad Fatoum2021-06-211-0/+3
| | | | | | | | | | | | | Only upstream user of this binding is the raspberry pi 4 DT, where it's used to pass along bootloader-provided info to Linux. We have instances in barebox, where a previous stage bootloader passes along a memory region with info for barebox to interpret. This could in future be modelled as nvmem-rmem nodes. The binding is also quite handy for debugging. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210619034516.6737-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: add flag to check if cdev is an mci deviceMarco Felsch2021-05-121-0/+6
| | | | | | | | | | We need this during mount() to check if the cdev is an mmc/mci main|user hardware partition device. Later on we add the feature to pass "root=/dev/mmcblkXpN" as kernel command line. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20210510102523.7147-1-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: provide dev_request_mem_resource_by_name() helperAhmad Fatoum2021-01-051-0/+5
| | | | | | | | | | | There are both dev_request_mem_resource() and dev_request_mem_region(), which return the struct resource and a IOMEM(.start) respectively. There is only dev_request_mem_region_by_name(), but no dev_request_mem_resource_by_name(), so add the latter for symmetry. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/driver-macro' into masterSascha Hauer2020-10-141-0/+6
|\
| * treewide: Use driver macroSascha Hauer2020-09-291-0/+6
| | | | | | | | | | | | | | We have several macros for a oneline driver registration. Add some missing and use them consistently where possible througout the tree. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | driver: introduce less error-prone dev_get_drvdata alternativeAhmad Fatoum2020-10-091-0/+18
|/ | | | | | | | | | | | | | | | | | | | | | | | | | We use dev_get_drvdata to get the driver match data associated with a device. This has two shortcomings: - Linux has dev_get_drvdata too, which returns a private pointer for driver specific info to associate with a device. We use dev->priv (or more often container_of) for that in barebox instead - It nearly always involves a cast to a double pointer, which is error-prone as size and alignment match need to be ensured on the programmer's part and can easily be gotten wrong: enum dev_type type; dev_get_drvdata(dev, (const void **)&type); // UB! Add a new function that instead of using a double pointer argument, returns the pointer directly: - For normal pointer driver data, no cast is necessary - For integer driver data casted to a pointer for storage, the cast is still necessary, but it's only a single pointer this way Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/block'Sascha Hauer2020-03-181-0/+1
|\
| * cdev: Add discard_range hookSascha Hauer2020-02-141-0/+1
| | | | | | | | | | | | | | To pass though discard_range() to the underlying drivers add a discard_range hook to struct cdev_operations. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | include: add SPDX GPL-2.0-or-later license tags where applicableRoland Hieber2020-02-171-11/+1
|/ | | | | | Signed-off-by: Roland Hieber <rohieb@rohieb.name> Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* device: Introduce dma_offsetSascha Hauer2019-12-201-0/+2
| | | | | | | | | | For devices that do not have a 1:1 mapping between DMA and CPU we need a dma_offset. This adds dma_offset to struct device_d and starts honoring it in ARM dma_(un)map_single(). Also we add some comments to functions that would normally need a device argument to make the DMA <-> CPU translations device specific. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* driver: add missing parentheses around macro argumentAhmad Fatoum2019-12-091-2/+2
| | | | | | | | Currently, the macro can't be used for more complex expressions like &pci_dev->dev. Fix this by adding the missing parentheses. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/ubootenv'Sascha Hauer2019-06-111-0/+4
|\