summaryrefslogtreecommitdiff
path: root/drivers/core/uclass.c
AgeCommit message (Collapse)AuthorFilesLines
2021-09-25treewide: Simply conditions with the new OF_REALSimon Glass1-1/+1
Use this new Kconfig to simplify the compilation conditions where appropriate. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-08-08dm: core: Don't allow uclass use before readySimon Glass1-0/+3
At present it is possible to call uclass_get() before driver model is inited. In fact this happens on x86 boards which use Intel FSPv1, since mrccache_get_region() tries to get the SPI flash device very early during init. This has always been undefined behaviour. Previously it generally worked, i.e. returned an error code without crashing, because gd->uclass_root_s is zeroed and the uclass can be added despite driver model not being ready, due to the way lists are implemented. With the change to use a gd->uclass_root pointer, this no-longer works. For example, it causes a hang on minnowmax. Fix this by adding a check that driver model is ready when uclass_get() is called. This function is called in the process of locating any device, so it is a good place to add the check. This fixes booting on minnowmax. Signed-off-by: Simon Glass <sjg@chromium.org> Fixes: 8a715530bb1 ("dm: core: Allow the uclass list to move")
2021-03-26dm: core: Drop uclass_find_device_by_phandle() with of-platdataSimon Glass1-1/+1
At present this function is included in the build but with of-platdata it only services to produce a confusing link error complaining about a call to dev_read_u32_default(). Drop it so that any call to uclass_find_device_by_phandle() is flagged as an error, making it easier to see what is going on. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-22dm: core: Skip adding uclasses with OF_PLATDATA_INSTSimon Glass1-1/+4
There is no need to ever add new uclasses since these are set up at build time. Update the code to return an error if this is attempted. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
2021-02-02common: Drop asm/global_data.h from common headerSimon Glass1-0/+1
Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
2021-01-16dm: core: add function uclass_probe_all() to probe all devicesVabhav Sharma1-0/+19
Support a common method to probe all devices associated with uclass. This includes data structures and code for finding the first device and looping for remaining devices associated with uclasses (groups of devices with the same purpose, e.g. all SERIAL ports will be in the same uclass). An example is SBSA compliant PL011 UART IP, where firmware does the serial port initialization and prepare uart device to let the kernel use it for sending and reveiving the characters.SERIAL uclass will use this function to initialize PL011 UART ports. The feature is enabled with CONFIG_DM. Signed-off-by: Vabhav Sharma <vabhav.sharma@nxp.com> Reviewed-by: Stefan Roese <sr@denx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Sean Anderson <seanga2@gmail.com>
2021-01-05dm: core: Allow the uclass list to moveSimon Glass1-2/+2
At present the uclass list head is in global_data. This is convenient but with the new of-platdata we need the list head to be declared by the generated code. Change this over to be a pointer. Provide a 'static' version in global_data to retain the current behaviour. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dm: core: Rename sqq to seq_Simon Glass1-4/+4
Now that the sequence-numbering migration is complete, rename this member back to seq_, adding an underscore to indicate it is internal to driver model. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2021-01-05dm: core: Rename the priv/plat membersSimon Glass1-2/+2
These are supposed to be private to driver model, not accessed by any code outside. Add a trailing underscore to indicate this. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dm: core: Use access methods for dev/uclass private dataSimon Glass1-5/+8
Use these functions in the core code as much as possible. With this, there are only two places where each priv/plat pointer is accessed, one for read and one for write. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-01-05dm: core: Add function to access uclass privSimon Glass1-0/+10
Add functions so this information is not accessed directly. This will be needed for of-platdata which stores it in a different place. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-19dm: core: Update uclass_find_next_free_req_seq() for new schemeSimon Glass1-6/+13
This function current deals with req_seq which is deprecated. Update it to use the new sequence numbers, putting them above existing aliases. Rename the function to make this clear. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-19dm: Drop the unused arg in uclass_find_device_by_seq()Simon Glass1-15/+7
Now that there is only one sequence number (rather than both requested and assigned ones) we can simplify this function. Also update its caller to simplify the logic. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-19dm: Drop uclass_resolve_seq()Simon Glass1-39/+0
This function is not needed anymore. Drop it. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-19dm: Switch over to use new sequence number for dev_seq()Simon Glass1-4/+2
Update this function to use the new sequence number and fix up the test that deals with this. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-19dm: core: Update uclass_find_next_free_req_seq() argsSimon Glass1-7/+1
At present this is passed a uclass ID and it has to do a lookup. The callers all have the uclass pointer, except for the I2C uclass where the code will soon be deleted. Update the argument to a uclass * instead of an ID since it is more efficient. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-19dm: Avoid accessing seq directlySimon Glass1-3/+3
At present various drivers etc. access the device's 'seq' member directly. This makes it harder to change the meaning of that member. Change access to go through a function instead. The drivers/i2c/lpc32xx_i2c.c file is left unchanged for now. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13dm: treewide: Rename auto_alloc_size members to be shorterSimon Glass1-4/+4
This construct is quite long-winded. In earlier days it made some sense since auto-allocation was a strange concept. But with driver model now used pretty universally, we can shorten this to 'auto'. This reduces verbosity and makes it easier to read. Coincidentally it also ensures that every declaration is on one line, thus making dtoc's job easier. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-06-12dm: uclass: don't assign aliased seq numbersMichael Walle1-6/+15
If there are aliases for an uclass, set the base for the "dynamically" allocated numbers next to the highest alias. Please note, that this might lead to holes in the sequences, depending on the device tree. For example if there is only an alias "ethernet1", the next device seq number would be 2. In particular this fixes a problem with boards which are using ethernet aliases but also might have network add-in cards like the E1000. If the board is started with the add-in card and depending on the order of the drivers, the E1000 might occupy the first ethernet device and mess up all the hardware addresses, because the devices are now shifted by one. Also adapt the test cases to the new handling and add test cases checking the holes in the seq numbers. Signed-off-by: Michael Walle <michael@walle.cc> Reviewed-by: Alex Marginean <alexandru.marginean@nxp.com> Tested-by: Alex Marginean <alexandru.marginean@nxp.com> Acked-by: Vladimir Oltean <olteanv@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Michal Simek <michal.simek@xilinx.com> [on zcu102-revA]
2020-05-19common: Drop log.h from common headerSimon Glass1-0/+1
Move this header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-04-16dm: core: Add a way to skip powering down power domainsSimon Glass1-1/+1
When removing a device the power domains it uses are generally powered off. But when we are trying to unbind all devices (e.g. for running tests) we don't want to probe a device in the 'remove' path. Add a new flag to skip this power-down step. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-04-16dm: core: Add logging on unbind failureSimon Glass1-2/+2
This failure path is tricky to debug since it continues after failure and there are a lot of error paths. Add logging to help. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-02-11Merge tag 'dm-pull-6feb20' of https://gitlab.denx.de/u-boot/custodians/u-boot-dmTom Rini1-4/+0
sandbox conversion to SDL2 TPM TEE driver Various minor sandbox video enhancements New driver model core utility functions
2020-02-07dm: core: Add a function to find a device by drvdataSimon Glass1-0/+17
It is sometimes useful to find a device in a uclass using only its driver data. The driver data often indicates the 'subtype' of the device, e,g, via its compatible string. Add a function to handle this. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2020-02-06dm: core: Drop uclass_find_next_free_req_seq() conditionsSimon Glass1-4/+0
These conditions are not needed and just reduce build coverage. Drop them. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-10-27dm: core: Update log method for uclass_find_device_by_seqKever Yang1-4/+7
Use log() insted of debug() for uclass_find_device_by_seq function, since this print is very much and we can filter it out with log() interface. Signed-off-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Simon Glass <sjg@chromium.org> Move #define to top of file as per docs: Signed-off-by: Simon Glass <sjg@chromium.org>
2019-10-15dm: device: Request next sequence numberThomas Fitzsimmons1-1/+3
For CONFIG_OF_PRIOR_STAGE, in the absence of a device tree alias for a given device, use the next request number for that type of device. This allows aliases to be used when they're available, while still allowing unaliased devices to be probed. Signed-off-by: Thomas Fitzsimmons <fitzsim@fitzsim.org> Cc: Bin Meng <bmeng.cn@gmail.com> Cc: Simon Glass <sjg@chromium.org>
2019-10-08dm: core: Correct the return value for uclass_find_first_device()Simon Glass1-1/+1
This function returns -ENODEV when there is no device. This is inconsistent with other functions, such as uclass_find_next_device(), which returns 0. Update it and tidy up the incorrect '-1' values in the comments. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com>
2019-10-08dm: core: Drop a few early returnsSimon Glass1-4/+10
Two functions in this file return early for no good reason. Adjust the code to match the standard DM style of returning 0 at the end of the function on success. Oddly enough this save 12 bytes of code size on ARM. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-07-13drivers: core: use strcmp when find device by namePeng Fan1-1/+1
`if (!strncmp(dev->name, name, strlen(name)))` might find out the wrong device, it might find out `dram_pll_ref_sel`, when name is `dram_pll`. So use strcmp to avoid such issue. Signed-off-by: Peng Fan <peng.fan@nxp.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-07-05dm: Add a No-op uclassJean-Jacques Hiblot1-0/+5
This uclass is intended for devices that do not need any features from the uclass, including binding children. This will typically be used by devices that are used to bind child devices but do not use dm_scan_fdt_dev() to do it. That is for example the case of several USB wrappers that have 2 child devices (1 for device and 1 for host) but bind only one at a any given time. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-02-09dm: device: fail uclass_find_first_device() if list_emptyMarcel Ziswiler1-1/+1
While uclass_find_device() fails with -ENODEV in case of list_empty strangely uclass_find_first_device() returns 0. Fix uclass_find_first_device() to also fail with -ENODEV instead. Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-12-10dm: device: Allow using uclass_find_device_by_seq() without OF_CONTROLJean-Jacques Hiblot1-0/+24
If OF_CONTROL is not enabled and DM_SEQ_ALIAS is enabled, we must assign an alias (requested sequence number) to devices that belongs to a class with the DM_UC_FLAG_SEQ_ALIAS flag. Otherwise uclass_find_device_by_seq() cannot be used to get/probe a device. In particular i2c_get_chip_for_busnum() cannot be used. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heiko Schocher <hs@denx.de>
2018-11-29dm: core: Export uclass_find_device_by_phandle()Simon Glass1-4/+2
This function may be useful to code outside of the code driver-model implementation. Export it and add a test. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-11-17dm: uclass: Add uclass_next_device_err() to return a valid devicePatrice Chotard1-0/+13
Similarly to uclass_first_device_err(), add uclass_next_device_err() which returns an error if there are no next devices in that uclass. Signed-off-by: Patrice Chotard <patrice.chotard@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-11-14uclass: Use uclass_foreach_dev() macro instead of open codingLiviu Dudau1-9/+9
Use the uclass_foreach_dev() macro instead of the open coded version. Signed-off-by: Liviu Dudau <liviu.dudau@foss.arm.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-11-14dm: core: Allow uclass to set up a device's child after it is probedBin Meng1-1/+12
Some buses need to set up their child devices after they are probed. Support a common child_post_probe() method for the uclass. With this change, the two APIs uclass_pre_probe_device() and uclass_post_probe_device() become symmetric. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-08-21uclass: Add dev_get_uclass_index() to get the uclass/index of a deviceJean-Jacques Hiblot1-0/+21
This function is the reciprocal of uclass_find_device(). It will be used to print the index information in dm tree dump. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
2018-07-09dm: core: Add logging of some common errorsSimon Glass1-2/+12
Add additional logging so that common errors when finding a device by ofnode are easier to debug. Signed-off-by: Simon Glass <sjg@chromium.org>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini1-2/+1
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
2018-03-31core: add uclass_get_device_by_phandle_id() apiKever Yang1-0/+26
Add api for who can not get phandle from a device property. Signed-off-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
2018-02-03dm: core: Add a function to look up a uclass by nameSimon Glass1-0/+14
Each uclass has a driver name which we can use to look up the uclass. This is useful for logging, where the uclass ID is used as the category. Add a function to handle this, as well as a test. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dm: core: Add uclass_first/next_device_check()Simon Glass1-0/+27
Sometimes it is useful to iterate through all devices in a uclass and skip over those which do not work correctly (e.g fail to probe). Add two new functions to provide this feature. The caller must check the return value each time to make sure that the device is valid. But the device pointer is always returned. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-11dm: core: Clarify uclass_first/next_device() commentsSimon Glass1-2/+1
These are not as clear as they could be. Tidy them up a bit. Also fix a tiny code-style nit. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-01dm: core: Update uclass_find_device_by_phandle() for livetreeSimon Glass1-3/+2
Adjust this function to work with livetree. Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-01dm: core: Add a way to find a device by ofnodeSimon Glass1-0/+37
Add a function which looks up a device by its node (either in live tree or flat tree). Signed-off-by: Simon Glass <sjg@chromium.org>
2017-04-13core/uclass: Print name of device in uclass_find_device_by_seq()Alexandru Gagniuc1-1/+1
uclass_find_device_by_seq() prints seq and req_seq when debugging is enabled, but this information is not very useful by itself. Add the name of he driver to this information. This improves debugging as it shows which devices are being considered. Signed-off-by: Alexandru Gagniuc <alex.g@adaptrum.com> Acked-by: Simon Glass <sjg@chromium.org>
2017-04-05dm: core: Add flags parameter to device_remove()Stefan Roese1-1/+1
This patch adds the flags parameter to device_remove() and changes all calls to this function to provide the default value of DM_REMOVE_NORMAL for "normal" device removal. This is in preparation for the driver specific pre-OS (e.g. DMA cancelling) remove support. Signed-off-by: Stefan Roese <sr@denx.de> Cc: Simon Glass <sjg@chromium.org> Acked-by: Simon Glass <sjg@chromium.org>
2017-02-08dm: core: Replace of_offset with accessorSimon Glass1-3/+5
At present devices use a simple integer offset to record the device tree node associated with the device. In preparation for supporting a live device tree, which uses a node pointer instead, refactor existing code to access this field through an inline function. Signed-off-by: Simon Glass <sjg@chromium.org>
2016-10-11dm: core: Add a function to get a uclass nameSimon Glass1-0/+9
It is useful in debug() statements to display the name of the uclass for a device. Add a simple function to provide this. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>