xref: /rk3399_rockchip-uboot/doc/driver-model/README.txt (revision 33fcd1bbd577d2b8f1e762dd69014f20259eb3aa)
165c70539SSimon GlassDriver Model
265c70539SSimon Glass============
365c70539SSimon Glass
465c70539SSimon GlassThis README contains high-level information about driver model, a unified
565c70539SSimon Glassway of declaring and accessing drivers in U-Boot. The original work was done
665c70539SSimon Glassby:
765c70539SSimon Glass
865c70539SSimon Glass   Marek Vasut <marex@denx.de>
965c70539SSimon Glass   Pavel Herrmann <morpheus.ibis@gmail.com>
1065c70539SSimon Glass   Viktor Křivák <viktor.krivak@gmail.com>
1165c70539SSimon Glass   Tomas Hlavacek <tmshlvck@gmail.com>
1265c70539SSimon Glass
1365c70539SSimon GlassThis has been both simplified and extended into the current implementation
1465c70539SSimon Glassby:
1565c70539SSimon Glass
1665c70539SSimon Glass   Simon Glass <sjg@chromium.org>
1765c70539SSimon Glass
1865c70539SSimon Glass
1965c70539SSimon GlassTerminology
2065c70539SSimon Glass-----------
2165c70539SSimon Glass
2265c70539SSimon GlassUclass - a group of devices which operate in the same way. A uclass provides
2334e4a2ecSChris Packham	a way of accessing individual devices within the group, but always
2465c70539SSimon Glass	using the same interface. For example a GPIO uclass provides
2565c70539SSimon Glass	operations for get/set value. An I2C uclass may have 10 I2C ports,
2665c70539SSimon Glass	4 with one driver, and 6 with another.
2765c70539SSimon Glass
2865c70539SSimon GlassDriver - some code which talks to a peripheral and presents a higher-level
2965c70539SSimon Glass	interface to it.
3065c70539SSimon Glass
3165c70539SSimon GlassDevice - an instance of a driver, tied to a particular port or peripheral.
3265c70539SSimon Glass
3365c70539SSimon Glass
3465c70539SSimon GlassHow to try it
3565c70539SSimon Glass-------------
3665c70539SSimon Glass
3765c70539SSimon GlassBuild U-Boot sandbox and run it:
3865c70539SSimon Glass
39*33fcd1bbSMasahiro Yamada   make sandbox_defconfig
4065c70539SSimon Glass   make
41*33fcd1bbSMasahiro Yamada   ./u-boot -d u-boot.dtb
4265c70539SSimon Glass
4365c70539SSimon Glass   (type 'reset' to exit U-Boot)
4465c70539SSimon Glass
4565c70539SSimon Glass
4665c70539SSimon GlassThere is a uclass called 'demo'. This uclass handles
4765c70539SSimon Glasssaying hello, and reporting its status. There are two drivers in this
4865c70539SSimon Glassuclass:
4965c70539SSimon Glass
5065c70539SSimon Glass   - simple: Just prints a message for hello, doesn't implement status
5165c70539SSimon Glass   - shape: Prints shapes and reports number of characters printed as status
5265c70539SSimon Glass
5365c70539SSimon GlassThe demo class is pretty simple, but not trivial. The intention is that it
5465c70539SSimon Glasscan be used for testing, so it will implement all driver model features and
5565c70539SSimon Glassprovide good code coverage of them. It does have multiple drivers, it
5665c70539SSimon Glasshandles parameter data and platdata (data which tells the driver how
5765c70539SSimon Glassto operate on a particular platform) and it uses private driver data.
5865c70539SSimon Glass
5965c70539SSimon GlassTo try it, see the example session below:
6065c70539SSimon Glass
6165c70539SSimon Glass=>demo hello 1
6265c70539SSimon GlassHello '@' from 07981110: red 4
6365c70539SSimon Glass=>demo status 2
6465c70539SSimon GlassStatus: 0
6565c70539SSimon Glass=>demo hello 2
6665c70539SSimon Glassg
6765c70539SSimon Glassr@
6865c70539SSimon Glasse@@
6965c70539SSimon Glasse@@@
7065c70539SSimon Glassn@@@@
7165c70539SSimon Glassg@@@@@
7265c70539SSimon Glass=>demo status 2
7365c70539SSimon GlassStatus: 21
7465c70539SSimon Glass=>demo hello 4 ^
7565c70539SSimon Glass  y^^^
7665c70539SSimon Glass e^^^^^
7765c70539SSimon Glassl^^^^^^^
7865c70539SSimon Glassl^^^^^^^
7965c70539SSimon Glass o^^^^^
8065c70539SSimon Glass  w^^^
8165c70539SSimon Glass=>demo status 4
8265c70539SSimon GlassStatus: 36
8365c70539SSimon Glass=>
8465c70539SSimon Glass
8565c70539SSimon Glass
8665c70539SSimon GlassRunning the tests
8765c70539SSimon Glass-----------------
8865c70539SSimon Glass
8965c70539SSimon GlassThe intent with driver model is that the core portion has 100% test coverage
9065c70539SSimon Glassin sandbox, and every uclass has its own test. As a move towards this, tests
9165c70539SSimon Glassare provided in test/dm. To run them, try:
9265c70539SSimon Glass
9365c70539SSimon Glass   ./test/dm/test-dm.sh
9465c70539SSimon Glass
9565c70539SSimon GlassYou should see something like this:
9665c70539SSimon Glass
9765c70539SSimon Glass    <...U-Boot banner...>
984324174dSSimon Glass    Running 29 driver model tests
9965c70539SSimon Glass    Test: dm_test_autobind
10065c70539SSimon Glass    Test: dm_test_autoprobe
1011ca7e206SSimon Glass    Test: dm_test_bus_children
1021ca7e206SSimon Glass    Device 'd-test': seq 3 is in use by 'b-test'
1031ca7e206SSimon Glass    Device 'c-test@0': seq 0 is in use by 'a-test'
1041ca7e206SSimon Glass    Device 'c-test@1': seq 1 is in use by 'd-test'
105997c87bbSSimon Glass    Test: dm_test_bus_children_funcs
106a8981d4fSSimon Glass    Test: dm_test_bus_children_iterators
107e59f458dSSimon Glass    Test: dm_test_bus_parent_data
108a327dee0SSimon Glass    Test: dm_test_bus_parent_ops
10965c70539SSimon Glass    Test: dm_test_children
11065c70539SSimon Glass    Test: dm_test_fdt
1115a66a8ffSSimon Glass    Device 'd-test': seq 3 is in use by 'b-test'
112f4cdead2SSimon Glass    Test: dm_test_fdt_offset
11300606d7eSSimon Glass    Test: dm_test_fdt_pre_reloc
1145a66a8ffSSimon Glass    Test: dm_test_fdt_uclass_seq
1155a66a8ffSSimon Glass    Device 'd-test': seq 3 is in use by 'b-test'
1165a66a8ffSSimon Glass    Device 'a-test': seq 0 is in use by 'd-test'
11765c70539SSimon Glass    Test: dm_test_gpio
1184b8f11c2SSimon Glass    extra-gpios: get_value: error: gpio b5 not reserved
1194b8f11c2SSimon Glass    Test: dm_test_gpio_anon
1204324174dSSimon Glass    Test: dm_test_gpio_copy
1214324174dSSimon Glass    Test: dm_test_gpio_leak
1224324174dSSimon Glass    extra-gpios: get_value: error: gpio b5 not reserved
123d44f597bSSimon Glass    Test: dm_test_gpio_requestf
12465c70539SSimon Glass    Test: dm_test_leak
12565c70539SSimon Glass    Test: dm_test_lifecycle
12665c70539SSimon Glass    Test: dm_test_operations
12765c70539SSimon Glass    Test: dm_test_ordering
12865c70539SSimon Glass    Test: dm_test_platdata
12900606d7eSSimon Glass    Test: dm_test_pre_reloc
13065c70539SSimon Glass    Test: dm_test_remove
1314b8f11c2SSimon Glass    Test: dm_test_spi_find
1324b8f11c2SSimon Glass    Invalid chip select 0:0 (err=-19)
1334b8f11c2SSimon Glass    SF: Failed to get idcodes
1344b8f11c2SSimon Glass    Device 'name-emul': seq 0 is in use by 'name-emul'
1354b8f11c2SSimon Glass    SF: Detected M25P16 with page size 256 Bytes, erase size 64 KiB, total 2 MiB
1364b8f11c2SSimon Glass    Test: dm_test_spi_flash
1374b8f11c2SSimon Glass    2097152 bytes written in 0 ms
1384b8f11c2SSimon Glass    SF: Detected M25P16 with page size 256 Bytes, erase size 64 KiB, total 2 MiB
1394b8f11c2SSimon Glass    SPI flash test:
1404b8f11c2SSimon Glass    0 erase: 0 ticks, 65536000 KiB/s 524288.000 Mbps
1414b8f11c2SSimon Glass    1 check: 0 ticks, 65536000 KiB/s 524288.000 Mbps
1424b8f11c2SSimon Glass    2 write: 0 ticks, 65536000 KiB/s 524288.000 Mbps
1434b8f11c2SSimon Glass    3 read: 0 ticks, 65536000 KiB/s 524288.000 Mbps
1444b8f11c2SSimon Glass    Test passed
1454b8f11c2SSimon Glass    0 erase: 0 ticks, 65536000 KiB/s 524288.000 Mbps
1464b8f11c2SSimon Glass    1 check: 0 ticks, 65536000 KiB/s 524288.000 Mbps
1474b8f11c2SSimon Glass    2 write: 0 ticks, 65536000 KiB/s 524288.000 Mbps
1484b8f11c2SSimon Glass    3 read: 0 ticks, 65536000 KiB/s 524288.000 Mbps
1494b8f11c2SSimon Glass    Test: dm_test_spi_xfer
1504b8f11c2SSimon Glass    SF: Detected M25P16 with page size 256 Bytes, erase size 64 KiB, total 2 MiB
15165c70539SSimon Glass    Test: dm_test_uclass
152c910e2e2SSimon Glass    Test: dm_test_uclass_before_ready
15365c70539SSimon Glass    Failures: 0
15465c70539SSimon Glass
15565c70539SSimon Glass
15665c70539SSimon GlassWhat is going on?
15765c70539SSimon Glass-----------------
15865c70539SSimon Glass
15965c70539SSimon GlassLet's start at the top. The demo command is in common/cmd_demo.c. It does
16034e4a2ecSChris Packhamthe usual command processing and then:
16165c70539SSimon Glass
16254c5d08aSHeiko Schocher	struct udevice *demo_dev;
16365c70539SSimon Glass
16465c70539SSimon Glass	ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev);
16565c70539SSimon Glass
16665c70539SSimon GlassUCLASS_DEMO means the class of devices which implement 'demo'. Other
16765c70539SSimon Glassclasses might be MMC, or GPIO, hashing or serial. The idea is that the
16865c70539SSimon Glassdevices in the class all share a particular way of working. The class
16965c70539SSimon Glasspresents a unified view of all these devices to U-Boot.
17065c70539SSimon Glass
17165c70539SSimon GlassThis function looks up a device for the demo uclass. Given a device
17265c70539SSimon Glassnumber we can find the device because all devices have registered with
17365c70539SSimon Glassthe UCLASS_DEMO uclass.
17465c70539SSimon Glass
17565c70539SSimon GlassThe device is automatically activated ready for use by uclass_get_device().
17665c70539SSimon Glass
17765c70539SSimon GlassNow that we have the device we can do things like:
17865c70539SSimon Glass
17965c70539SSimon Glass	return demo_hello(demo_dev, ch);
18065c70539SSimon Glass
18165c70539SSimon GlassThis function is in the demo uclass. It takes care of calling the 'hello'
18265c70539SSimon Glassmethod of the relevant driver. Bearing in mind that there are two drivers,
18365c70539SSimon Glassthis particular device may use one or other of them.
18465c70539SSimon Glass
18565c70539SSimon GlassThe code for demo_hello() is in drivers/demo/demo-uclass.c:
18665c70539SSimon Glass
18754c5d08aSHeiko Schocherint demo_hello(struct udevice *dev, int ch)
18865c70539SSimon Glass{
18965c70539SSimon Glass	const struct demo_ops *ops = device_get_ops(dev);
19065c70539SSimon Glass
19165c70539SSimon Glass	if (!ops->hello)
19265c70539SSimon Glass		return -ENOSYS;
19365c70539SSimon Glass
19465c70539SSimon Glass	return ops->hello(dev, ch);
19565c70539SSimon Glass}
19665c70539SSimon Glass
19765c70539SSimon GlassAs you can see it just calls the relevant driver method. One of these is
19865c70539SSimon Glassin drivers/demo/demo-simple.c:
19965c70539SSimon Glass
20054c5d08aSHeiko Schocherstatic int simple_hello(struct udevice *dev, int ch)
20165c70539SSimon Glass{
20265c70539SSimon Glass	const struct dm_demo_pdata *pdata = dev_get_platdata(dev);
20365c70539SSimon Glass
20465c70539SSimon Glass	printf("Hello from %08x: %s %d\n", map_to_sysmem(dev),
20565c70539SSimon Glass	       pdata->colour, pdata->sides);
20665c70539SSimon Glass
20765c70539SSimon Glass	return 0;
20865c70539SSimon Glass}
20965c70539SSimon Glass
21065c70539SSimon Glass
21165c70539SSimon GlassSo that is a trip from top (command execution) to bottom (driver action)
21265c70539SSimon Glassbut it leaves a lot of topics to address.
21365c70539SSimon Glass
21465c70539SSimon Glass
21565c70539SSimon GlassDeclaring Drivers
21665c70539SSimon Glass-----------------
21765c70539SSimon Glass
21865c70539SSimon GlassA driver declaration looks something like this (see
21965c70539SSimon Glassdrivers/demo/demo-shape.c):
22065c70539SSimon Glass
22165c70539SSimon Glassstatic const struct demo_ops shape_ops = {
22265c70539SSimon Glass	.hello = shape_hello,
22365c70539SSimon Glass	.status = shape_status,
22465c70539SSimon Glass};
22565c70539SSimon Glass
22665c70539SSimon GlassU_BOOT_DRIVER(demo_shape_drv) = {
22765c70539SSimon Glass	.name	= "demo_shape_drv",
22865c70539SSimon Glass	.id	= UCLASS_DEMO,
22965c70539SSimon Glass	.ops	= &shape_ops,
23065c70539SSimon Glass	.priv_data_size = sizeof(struct shape_data),
23165c70539SSimon Glass};
23265c70539SSimon Glass
23365c70539SSimon Glass
23465c70539SSimon GlassThis driver has two methods (hello and status) and requires a bit of
23565c70539SSimon Glassprivate data (accessible through dev_get_priv(dev) once the driver has
23665c70539SSimon Glassbeen probed). It is a member of UCLASS_DEMO so will register itself
23765c70539SSimon Glassthere.
23865c70539SSimon Glass
23965c70539SSimon GlassIn U_BOOT_DRIVER it is also possible to specify special methods for bind
24065c70539SSimon Glassand unbind, and these are called at appropriate times. For many drivers
24165c70539SSimon Glassit is hoped that only 'probe' and 'remove' will be needed.
24265c70539SSimon Glass
24365c70539SSimon GlassThe U_BOOT_DRIVER macro creates a data structure accessible from C,
24465c70539SSimon Glassso driver model can find the drivers that are available.
24565c70539SSimon Glass
24665c70539SSimon GlassThe methods a device can provide are documented in the device.h header.
24765c70539SSimon GlassBriefly, they are:
24865c70539SSimon Glass
24965c70539SSimon Glass    bind - make the driver model aware of a device (bind it to its driver)
25065c70539SSimon Glass    unbind - make the driver model forget the device
25165c70539SSimon Glass    ofdata_to_platdata - convert device tree data to platdata - see later
25265c70539SSimon Glass    probe - make a device ready for use
25365c70539SSimon Glass    remove - remove a device so it cannot be used until probed again
25465c70539SSimon Glass
25565c70539SSimon GlassThe sequence to get a device to work is bind, ofdata_to_platdata (if using
25665c70539SSimon Glassdevice tree) and probe.
25765c70539SSimon Glass
25865c70539SSimon Glass
25965c70539SSimon GlassPlatform Data
26065c70539SSimon Glass-------------
26165c70539SSimon Glass
26222ec1363SSimon GlassPlatform data is like Linux platform data, if you are familiar with that.
26322ec1363SSimon GlassIt provides the board-specific information to start up a device.
26422ec1363SSimon Glass
26522ec1363SSimon GlassWhy is this information not just stored in the device driver itself? The
26622ec1363SSimon Glassidea is that the device driver is generic, and can in principle operate on
26722ec1363SSimon Glassany board that has that type of device. For example, with modern
26822ec1363SSimon Glasshighly-complex SoCs it is common for the IP to come from an IP vendor, and
26922ec1363SSimon Glasstherefore (for example) the MMC controller may be the same on chips from
27022ec1363SSimon Glassdifferent vendors. It makes no sense to write independent drivers for the
27122ec1363SSimon GlassMMC controller on each vendor's SoC, when they are all almost the same.
27222ec1363SSimon GlassSimilarly, we may have 6 UARTs in an SoC, all of which are mostly the same,
27322ec1363SSimon Glassbut lie at different addresses in the address space.
27422ec1363SSimon Glass
27522ec1363SSimon GlassUsing the UART example, we have a single driver and it is instantiated 6
27622ec1363SSimon Glasstimes by supplying 6 lots of platform data. Each lot of platform data
27722ec1363SSimon Glassgives the driver name and a pointer to a structure containing information
27822ec1363SSimon Glassabout this instance - e.g. the address of the register space. It may be that
27922ec1363SSimon Glassone of the UARTS supports RS-485 operation - this can be added as a flag in
28022ec1363SSimon Glassthe platform data, which is set for this one port and clear for the rest.
28122ec1363SSimon Glass
28222ec1363SSimon GlassThink of your driver as a generic piece of code which knows how to talk to
28322ec1363SSimon Glassa device, but needs to know where it is, any variant/option information and
28422ec1363SSimon Glassso on. Platform data provides this link between the generic piece of code
28522ec1363SSimon Glassand the specific way it is bound on a particular board.
28622ec1363SSimon Glass
28722ec1363SSimon GlassExamples of platform data include:
28822ec1363SSimon Glass
28922ec1363SSimon Glass   - The base address of the IP block's register space
29022ec1363SSimon Glass   - Configuration options, like:
29122ec1363SSimon Glass         - the SPI polarity and maximum speed for a SPI controller
29222ec1363SSimon Glass         - the I2C speed to use for an I2C device
29322ec1363SSimon Glass         - the number of GPIOs available in a GPIO device
29422ec1363SSimon Glass
29522ec1363SSimon GlassWhere does the platform data come from? It is either held in a structure
29622ec1363SSimon Glasswhich is compiled into U-Boot, or it can be parsed from the Device Tree
29722ec1363SSimon Glass(see 'Device Tree' below).
29822ec1363SSimon Glass
29922ec1363SSimon GlassFor an example of how it can be compiled in, see demo-pdata.c which
30065c70539SSimon Glasssets up a table of driver names and their associated platform data.
30165c70539SSimon GlassThe data can be interpreted by the drivers however they like - it is
30265c70539SSimon Glassbasically a communication scheme between the board-specific code and
30365c70539SSimon Glassthe generic drivers, which are intended to work on any board.
30465c70539SSimon Glass
30534e4a2ecSChris PackhamDrivers can access their data via dev->info->platdata. Here is
30665c70539SSimon Glassthe declaration for the platform data, which would normally appear
30765c70539SSimon Glassin the board file.
30865c70539SSimon Glass
30965c70539SSimon Glass	static const struct dm_demo_cdata red_square = {
31065c70539SSimon Glass		.colour = "red",
31165c70539SSimon Glass		.sides = 4.
31265c70539SSimon Glass	};
31365c70539SSimon Glass	static const struct driver_info info[] = {
31465c70539SSimon Glass		{
31565c70539SSimon Glass			.name = "demo_shape_drv",
31665c70539SSimon Glass			.platdata = &red_square,
31765c70539SSimon Glass		},
31865c70539SSimon Glass	};
31965c70539SSimon Glass
32065c70539SSimon Glass	demo1 = driver_bind(root, &info[0]);
32165c70539SSimon Glass
32265c70539SSimon Glass
32365c70539SSimon GlassDevice Tree
32465c70539SSimon Glass-----------
32565c70539SSimon Glass
32665c70539SSimon GlassWhile platdata is useful, a more flexible way of providing device data is
32765c70539SSimon Glassby using device tree. With device tree we replace the above code with the
32865c70539SSimon Glassfollowing device tree fragment:
32965c70539SSimon Glass
33065c70539SSimon Glass	red-square {
33165c70539SSimon Glass		compatible = "demo-shape";
33265c70539SSimon Glass		colour = "red";
33365c70539SSimon Glass		sides = <4>;
33465c70539SSimon Glass	};
33565c70539SSimon Glass
33622ec1363SSimon GlassThis means that instead of having lots of U_BOOT_DEVICE() declarations in
33722ec1363SSimon Glassthe board file, we put these in the device tree. This approach allows a lot
33822ec1363SSimon Glassmore generality, since the same board file can support many types of boards
33922ec1363SSimon Glass(e,g. with the same SoC) just by using different device trees. An added
34022ec1363SSimon Glassbenefit is that the Linux device tree can be used, thus further simplifying
34122ec1363SSimon Glassthe task of board-bring up either for U-Boot or Linux devs (whoever gets to
34222ec1363SSimon Glassthe board first!).
34365c70539SSimon Glass
34465c70539SSimon GlassThe easiest way to make this work it to add a few members to the driver:
34565c70539SSimon Glass
34665c70539SSimon Glass	.platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
34765c70539SSimon Glass	.ofdata_to_platdata = testfdt_ofdata_to_platdata,
34865c70539SSimon Glass
34965c70539SSimon GlassThe 'auto_alloc' feature allowed space for the platdata to be allocated
35022ec1363SSimon Glassand zeroed before the driver's ofdata_to_platdata() method is called. The
35122ec1363SSimon Glassofdata_to_platdata() method, which the driver write supplies, should parse
35222ec1363SSimon Glassthe device tree node for this device and place it in dev->platdata. Thus
35322ec1363SSimon Glasswhen the probe method is called later (to set up the device ready for use)
35422ec1363SSimon Glassthe platform data will be present.
35565c70539SSimon Glass
35665c70539SSimon GlassNote that both methods are optional. If you provide an ofdata_to_platdata
35722ec1363SSimon Glassmethod then it will be called first (during activation). If you provide a
35822ec1363SSimon Glassprobe method it will be called next. See Driver Lifecycle below for more
35922ec1363SSimon Glassdetails.
36065c70539SSimon Glass
36165c70539SSimon GlassIf you don't want to have the platdata automatically allocated then you
36265c70539SSimon Glasscan leave out platdata_auto_alloc_size. In this case you can use malloc
36365c70539SSimon Glassin your ofdata_to_platdata (or probe) method to allocate the required memory,
36465c70539SSimon Glassand you should free it in the remove method.
36565c70539SSimon Glass
36665c70539SSimon Glass
36765c70539SSimon GlassDeclaring Uclasses
36865c70539SSimon Glass------------------
36965c70539SSimon Glass
37065c70539SSimon GlassThe demo uclass is declared like this:
37165c70539SSimon Glass
37265c70539SSimon GlassU_BOOT_CLASS(demo) = {
37365c70539SSimon Glass	.id		= UCLASS_DEMO,
37465c70539SSimon Glass};
37565c70539SSimon Glass
37665c70539SSimon GlassIt is also possible to specify special methods for probe, etc. The uclass
37765c70539SSimon Glassnumbering comes from include/dm/uclass.h. To add a new uclass, add to the
37865c70539SSimon Glassend of the enum there, then declare your uclass as above.
37965c70539SSimon Glass
38065c70539SSimon Glass
3815a66a8ffSSimon GlassDevice Sequence Numbers
3825a66a8ffSSimon Glass-----------------------
3835a66a8ffSSimon Glass
3845a66a8ffSSimon GlassU-Boot numbers devices from 0 in many situations, such as in the command
3855a66a8ffSSimon Glassline for I2C and SPI buses, and the device names for serial ports (serial0,
3865a66a8ffSSimon Glassserial1, ...). Driver model supports this numbering and permits devices
387547cea19SSimon Glassto be locating by their 'sequence'. This numbering unique identifies a
388547cea19SSimon Glassdevice in its uclass, so no two devices within a particular uclass can have
389547cea19SSimon Glassthe same sequence number.
3905a66a8ffSSimon Glass
3915a66a8ffSSimon GlassSequence numbers start from 0 but gaps are permitted. For example, a board
3925a66a8ffSSimon Glassmay have I2C buses 0, 1, 4, 5 but no 2 or 3. The choice of how devices are
3935a66a8ffSSimon Glassnumbered is up to a particular board, and may be set by the SoC in some
3945a66a8ffSSimon Glasscases. While it might be tempting to automatically renumber the devices
3955a66a8ffSSimon Glasswhere there are gaps in the sequence, this can lead to confusion and is
3965a66a8ffSSimon Glassnot the way that U-Boot works.
3975a66a8ffSSimon Glass
3985a66a8ffSSimon GlassEach device can request a sequence number. If none is required then the
3995a66a8ffSSimon Glassdevice will be automatically allocated the next available sequence number.
4005a66a8ffSSimon Glass
4015a66a8ffSSimon GlassTo specify the sequence number in the device tree an alias is typically
4025a66a8ffSSimon Glassused.
4035a66a8ffSSimon Glass
4045a66a8ffSSimon Glassaliases {
4055a66a8ffSSimon Glass	serial2 = "/serial@22230000";
4065a66a8ffSSimon Glass};
4075a66a8ffSSimon Glass
4085a66a8ffSSimon GlassThis indicates that in the uclass called "serial", the named node
4095a66a8ffSSimon Glass("/serial@22230000") will be given sequence number 2. Any command or driver
4105a66a8ffSSimon Glasswhich requests serial device 2 will obtain this device.
4115a66a8ffSSimon Glass
4125a66a8ffSSimon GlassSome devices represent buses where the devices on the bus are numbered or
4135a66a8ffSSimon Glassaddressed. For example, SPI typically numbers its slaves from 0, and I2C
4145a66a8ffSSimon Glassuses a 7-bit address. In these cases the 'reg' property of the subnode is
4155a66a8ffSSimon Glassused, for example:
4165a66a8ffSSimon Glass
4175a66a8ffSSimon Glass{
4185a66a8ffSSimon Glass	aliases {
4195a66a8ffSSimon Glass		spi2 = "/spi@22300000";
4205a66a8ffSSimon Glass	};
4215a66a8ffSSimon Glass
4225a66a8ffSSimon Glass	spi@22300000 {
4235a66a8ffSSimon Glass		#address-cells = <1>;
4245a66a8ffSSimon Glass		#size-cells = <1>;
4255a66a8ffSSimon Glass		spi-flash@0 {
4265a66a8ffSSimon Glass			reg = <0>;
4275a66a8ffSSimon Glass			...
4285a66a8ffSSimon Glass		}
4295a66a8ffSSimon Glass		eeprom@1 {
4305a66a8ffSSimon Glass			reg = <1>;
4315a66a8ffSSimon Glass		};
4325a66a8ffSSimon Glass	};
4335a66a8ffSSimon Glass
4345a66a8ffSSimon GlassIn this case we have a SPI bus with two slaves at 0 and 1. The SPI bus
4355a66a8ffSSimon Glassitself is numbered 2. So we might access the SPI flash with:
4365a66a8ffSSimon Glass
4375a66a8ffSSimon Glass	sf probe 2:0
4385a66a8ffSSimon Glass
4395a66a8ffSSimon Glassand the eeprom with
4405a66a8ffSSimon Glass
4415a66a8ffSSimon Glass	sspi 2:1 32 ef
4425a66a8ffSSimon Glass
4435a66a8ffSSimon GlassThese commands simply need to look up the 2nd device in the SPI uclass to
4445a66a8ffSSimon Glassfind the right SPI bus. Then, they look at the children of that bus for the
4455a66a8ffSSimon Glassright sequence number (0 or 1 in this case).
4465a66a8ffSSimon Glass
4475a66a8ffSSimon GlassTypically the alias method is used for top-level nodes and the 'reg' method
4485a66a8ffSSimon Glassis used only for buses.
4495a66a8ffSSimon Glass
4505a66a8ffSSimon GlassDevice sequence numbers are resolved when a device is probed. Before then
4515a66a8ffSSimon Glassthe sequence number is only a request which may or may not be honoured,
4525a66a8ffSSimon Glassdepending on what other devices have been probed. However the numbering is
4535a66a8ffSSimon Glassentirely under the control of the board author so a conflict is generally
4545a66a8ffSSimon Glassan error.
4555a66a8ffSSimon Glass
4565a66a8ffSSimon Glass
457a327dee0SSimon GlassBus Drivers
458a327dee0SSimon Glass-----------
459a327dee0SSimon Glass
460a327dee0SSimon GlassA common use of driver model is to implement a bus, a device which provides
461a327dee0SSimon Glassaccess to other devices. Example of buses include SPI and I2C. Typically
462a327dee0SSimon Glassthe bus provides some sort of transport or translation that makes it
463a327dee0SSimon Glasspossible to talk to the devices on the bus.
464a327dee0SSimon Glass
465a327dee0SSimon GlassDriver model provides a few useful features to help with implementing
466a327dee0SSimon Glassbuses. Firstly, a bus can request that its children store some 'parent
467a327dee0SSimon Glassdata' which can be used to keep track of child state. Secondly, the bus can
468a327dee0SSimon Glassdefine methods which are called when a child is probed or removed. This is
469a327dee0SSimon Glasssimilar to the methods the uclass driver provides.
470a327dee0SSimon Glass
471a327dee0SSimon GlassHere an explanation of how a bus fits with a uclass may be useful. Consider
472a327dee0SSimon Glassa USB bus with several devices attached to it, each from a different (made
473a327dee0SSimon Glassup) uclass:
474a327dee0SSimon Glass
475a327dee0SSimon Glass   xhci_usb (UCLASS_USB)
476a327dee0SSimon Glass      eth (UCLASS_ETHERNET)
477a327dee0SSimon Glass      camera (UCLASS_CAMERA)
478a327dee0SSimon Glass      flash (UCLASS_FLASH_STORAGE)
479a327dee0SSimon Glass
480a327dee0SSimon GlassEach of the devices is connected to a different address on the USB bus.
481a327dee0SSimon GlassThe bus device wants to store this address and some other information such
482a327dee0SSimon Glassas the bus speed for each device.
483a327dee0SSimon Glass
484a327dee0SSimon GlassTo achieve this, the bus device can use dev->parent_priv in each of its
485a327dee0SSimon Glassthree children. This can be auto-allocated if the bus driver has a non-zero
486a327dee0SSimon Glassvalue for per_child_auto_alloc_size. If not, then the bus device can
487a327dee0SSimon Glassallocate the space itself before the child device is probed.
488a327dee0SSimon Glass
489a327dee0SSimon GlassAlso the bus driver can define the child_pre_probe() and child_post_remove()
490a327dee0SSimon Glassmethods to allow it to do some processing before the child is activated or
491a327dee0SSimon Glassafter it is deactivated.
492a327dee0SSimon Glass
493a327dee0SSimon GlassNote that the information that controls this behaviour is in the bus's
494a327dee0SSimon Glassdriver, not the child's. In fact it is possible that child has no knowledge
495a327dee0SSimon Glassthat it is connected to a bus. The same child device may even be used on two
496a327dee0SSimon Glassdifferent bus types. As an example. the 'flash' device shown above may also
497a327dee0SSimon Glassbe connected on a SATA bus or standalone with no bus:
498a327dee0SSimon Glass
499a327dee0SSimon Glass   xhci_usb (UCLASS_USB)
500a327dee0SSimon Glass      flash (UCLASS_FLASH_STORAGE)  - parent data/methods defined by USB bus
501a327dee0SSimon Glass
502a327dee0SSimon Glass   sata (UCLASS_SATA)
503a327dee0SSimon Glass      flash (UCLASS_FLASH_STORAGE)  - parent data/methods defined by SATA bus
504a327dee0SSimon Glass
505a327dee0SSimon Glass   flash (UCLASS_FLASH_STORAGE)  - no parent data/methods (not on a bus)
506a327dee0SSimon Glass
507a327dee0SSimon GlassAbove you can see that the driver for xhci_usb/sata controls the child's
508a327dee0SSimon Glassbus methods. In the third example the device is not on a bus, and therefore
509a327dee0SSimon Glasswill not have these methods at all. Consider the case where the flash
510a327dee0SSimon Glassdevice defines child methods. These would be used for *its* children, and
511a327dee0SSimon Glasswould be quite separate from the methods defined by the driver for the bus
512a327dee0SSimon Glassthat the flash device is connetced to. The act of attaching a device to a
513a327dee0SSimon Glassparent device which is a bus, causes the device to start behaving like a
514a327dee0SSimon Glassbus device, regardless of its own views on the matter.
515a327dee0SSimon Glass
516a327dee0SSimon GlassThe uclass for the device can also contain data private to that uclass.
517a327dee0SSimon GlassBut note that each device on the bus may be a memeber of a different
518a327dee0SSimon Glassuclass, and this data has nothing to do with the child data for each child
519a327dee0SSimon Glasson the bus.
520a327dee0SSimon Glass
521a327dee0SSimon Glass
52222ec1363SSimon GlassDriver Lifecycle
52322ec1363SSimon Glass----------------
52422ec1363SSimon Glass
52522ec1363SSimon GlassHere are the stages that a device goes through in driver model. Note that all
52622ec1363SSimon Glassmethods mentioned here are optional - e.g. if there is no probe() method for
52722ec1363SSimon Glassa device then it will not be called. A simple device may have very few
52822ec1363SSimon Glassmethods actually defined.
52922ec1363SSimon Glass
53022ec1363SSimon Glass1. Bind stage
53122ec1363SSimon Glass
53222ec1363SSimon GlassA device and its driver are bound using one of these two methods:
53322ec1363SSimon Glass
53422ec1363SSimon Glass   - Scan the U_BOOT_DEVICE() definitions. U-Boot It looks up the
53522ec1363SSimon Glassname specified by each, to find the appropriate driver. It then calls
53622ec1363SSimon Glassdevice_bind() to create a new device and bind' it to its driver. This will
53722ec1363SSimon Glasscall the device's bind() method.
53822ec1363SSimon Glass
53922ec1363SSimon Glass   - Scan through the device tree definitions. U-Boot looks at top-level
54022ec1363SSimon Glassnodes in the the device tree. It looks at the compatible string in each node
54122ec1363SSimon Glassand uses the of_match part of the U_BOOT_DRIVER() structure to find the
54222ec1363SSimon Glassright driver for each node. It then calls device_bind() to bind the
54322ec1363SSimon Glassnewly-created device to its driver (thereby creating a device structure).
54422ec1363SSimon GlassThis will also call the device's bind() method.
54522ec1363SSimon Glass
54622ec1363SSimon GlassAt this point all the devices are known, and bound to their drivers. There
54722ec1363SSimon Glassis a 'struct udevice' allocated for all devices. However, nothing has been
54822ec1363SSimon Glassactivated (except for the root device). Each bound device that was created
54922ec1363SSimon Glassfrom a U_BOOT_DEVICE() declaration will hold the platdata pointer specified
55022ec1363SSimon Glassin that declaration. For a bound device created from the device tree,
55122ec1363SSimon Glassplatdata will be NULL, but of_offset will be the offset of the device tree
55222ec1363SSimon Glassnode that caused the device to be created. The uclass is set correctly for
55322ec1363SSimon Glassthe device.
55422ec1363SSimon Glass
55522ec1363SSimon GlassThe device's bind() method is permitted to perform simple actions, but
55622ec1363SSimon Glassshould not scan the device tree node, not initialise hardware, nor set up
55722ec1363SSimon Glassstructures or allocate memory. All of these tasks should be left for
55822ec1363SSimon Glassthe probe() method.
55922ec1363SSimon Glass
56022ec1363SSimon GlassNote that compared to Linux, U-Boot's driver model has a separate step of
56122ec1363SSimon Glassprobe/remove which is independent of bind/unbind. This is partly because in
56222ec1363SSimon GlassU-Boot it may be expensive to probe devices and we don't want to do it until
56322ec1363SSimon Glassthey are needed, or perhaps until after relocation.
56422ec1363SSimon Glass
56522ec1363SSimon Glass2. Activation/probe
56622ec1363SSimon Glass
56722ec1363SSimon GlassWhen a device needs to be used, U-Boot activates it, by following these
56822ec1363SSimon Glasssteps (see device_probe()):
56922ec1363SSimon Glass
57022ec1363SSimon Glass   a. If priv_auto_alloc_size is non-zero, then the device-private space
57122ec1363SSimon Glass   is allocated for the device and zeroed. It will be accessible as
57222ec1363SSimon Glass   dev->priv. The driver can put anything it likes in there, but should use
57322ec1363SSimon Glass   it for run-time information, not platform data (which should be static
57422ec1363SSimon Glass   and known before the device is probed).
57522ec1363SSimon Glass
57622ec1363SSimon Glass   b. If platdata_auto_alloc_size is non-zero, then the platform data space
57722ec1363SSimon Glass   is allocated. This is only useful for device tree operation, since
57822ec1363SSimon Glass   otherwise you would have to specific the platform data in the
57922ec1363SSimon Glass   U_BOOT_DEVICE() declaration. The space is allocated for the device and
58022ec1363SSimon Glass   zeroed. It will be accessible as dev->platdata.
58122ec1363SSimon Glass
58222ec1363SSimon Glass   c. If the device's uclass specifies a non-zero per_device_auto_alloc_size,
58322ec1363SSimon Glass   then this space is allocated and zeroed also. It is allocated for and
58422ec1363SSimon Glass   stored in the device, but it is uclass data. owned by the uclass driver.
58522ec1363SSimon Glass   It is possible for the device to access it.
58622ec1363SSimon Glass
587e59f458dSSimon Glass   d. If the device's immediate parent specifies a per_child_auto_alloc_size
588e59f458dSSimon Glass   then this space is allocated. This is intended for use by the parent
589e59f458dSSimon Glass   device to keep track of things related to the child. For example a USB
590e59f458dSSimon Glass   flash stick attached to a USB host controller would likely use this
591e59f458dSSimon Glass   space. The controller can hold information about the USB state of each
592e59f458dSSimon Glass   of its children.
593e59f458dSSimon Glass
594e59f458dSSimon Glass   e. All parent devices are probed. It is not possible to activate a device
59522ec1363SSimon Glass   unless its predecessors (all the way up to the root device) are activated.
59622ec1363SSimon Glass   This means (for example) that an I2C driver will require that its bus
59722ec1363SSimon Glass   be activated.
59822ec1363SSimon Glass
599e59f458dSSimon Glass   f. The device's sequence number is assigned, either the requested one
6005a66a8ffSSimon Glass   (assuming no conflicts) or the next available one if there is a conflict
6015a66a8ffSSimon Glass   or nothing particular is requested.
6025a66a8ffSSimon Glass
603e59f458dSSimon Glass   g. If the driver provides an ofdata_to_platdata() method, then this is
60422ec1363SSimon Glass   called to convert the device tree data into platform data. This should
60522ec1363SSimon Glass   do various calls like fdtdec_get_int(gd->fdt_blob, dev->of_offset, ...)
60622ec1363SSimon Glass   to access the node and store the resulting information into dev->platdata.
60722ec1363SSimon Glass   After this point, the device works the same way whether it was bound
60822ec1363SSimon Glass   using a device tree node or U_BOOT_DEVICE() structure. In either case,
60922ec1363SSimon Glass   the platform data is now stored in the platdata structure. Typically you
61022ec1363SSimon Glass   will use the platdata_auto_alloc_size feature to specify the size of the
61122ec1363SSimon Glass   platform data structure, and U-Boot will automatically allocate and zero
61222ec1363SSimon Glass   it for you before entry to ofdata_to_platdata(). But if not, you can
61322ec1363SSimon Glass   allocate it yourself in ofdata_to_platdata(). Note that it is preferable
61422ec1363SSimon Glass   to do all the device tree decoding in ofdata_to_platdata() rather than
61522ec1363SSimon Glass   in probe(). (Apart from the ugliness of mixing configuration and run-time
61622ec1363SSimon Glass   data, one day it is possible that U-Boot will cache platformat data for
61722ec1363SSimon Glass   devices which are regularly de/activated).
61822ec1363SSimon Glass
619e59f458dSSimon Glass   h. The device's probe() method is called. This should do anything that
62022ec1363SSimon Glass   is required by the device to get it going. This could include checking
62122ec1363SSimon Glass   that the hardware is actually present, setting up clocks for the
62222ec1363SSimon Glass   hardware and setting up hardware registers to initial values. The code
62322ec1363SSimon Glass   in probe() can access:
62422ec1363SSimon Glass
62522ec1363SSimon Glass      - platform data in dev->platdata (for configuration)
62622ec1363SSimon Glass      - private data in dev->priv (for run-time state)
62722ec1363SSimon Glass      - uclass data in dev->uclass_priv (for things the uclass stores
62822ec1363SSimon Glass        about this device)
62922ec1363SSimon Glass
63022ec1363SSimon Glass   Note: If you don't use priv_auto_alloc_size then you will need to
63122ec1363SSimon Glass   allocate the priv space here yourself. The same applies also to
63222ec1363SSimon Glass   platdata_auto_alloc_size. Remember to free them in the remove() method.
63322ec1363SSimon Glass
634e59f458dSSimon Glass   i. The device is marked 'activated'
63522ec1363SSimon Glass
636e59f458dSSimon Glass   j. The uclass's post_probe() method is called, if one exists. This may
63722ec1363SSimon Glass   cause the uclass to do some housekeeping to record the device as
63822ec1363SSimon Glass   activated and 'known' by the uclass.
63922ec1363SSimon Glass
64022ec1363SSimon Glass3. Running stage
64122ec1363SSimon Glass
64222ec1363SSimon GlassThe device is now activated and can be used. From now until it is removed
64322ec1363SSimon Glassall of the above structures are accessible. The device appears in the
64422ec1363SSimon Glassuclass's list of devices (so if the device is in UCLASS_GPIO it will appear
64522ec1363SSimon Glassas a device in the GPIO uclass). This is the 'running' state of the device.
64622ec1363SSimon Glass
64722ec1363SSimon Glass4. Removal stage
64822ec1363SSimon Glass
64922ec1363SSimon GlassWhen the device is no-longer required, you can call device_remove() to
65022ec1363SSimon Glassremove it. This performs the probe steps in reverse:
65122ec1363SSimon Glass
65222ec1363SSimon Glass   a. The uclass's pre_remove() method is called, if one exists. This may
65322ec1363SSimon Glass   cause the uclass to do some housekeeping to record the device as
65422ec1363SSimon Glass   deactivated and no-longer 'known' by the uclass.
65522ec1363SSimon Glass
65622ec1363SSimon Glass   b. All the device's children are removed. It is not permitted to have
65722ec1363SSimon Glass   an active child device with a non-active parent. This means that
65822ec1363SSimon Glass   device_remove() is called for all the children recursively at this point.
65922ec1363SSimon Glass
66022ec1363SSimon Glass   c. The device's remove() method is called. At this stage nothing has been
66122ec1363SSimon Glass   deallocated so platform data, private data and the uclass data will all
66222ec1363SSimon Glass   still be present. This is where the hardware can be shut down. It is
66322ec1363SSimon Glass   intended that the device be completely inactive at this point, For U-Boot
66422ec1363SSimon Glass   to be sure that no hardware is running, it should be enough to remove
66522ec1363SSimon Glass   all devices.
66622ec1363SSimon Glass
667e59f458dSSimon Glass   d. The device memory is freed (platform data, private data, uclass data,
668e59f458dSSimon Glass   parent data).
66922ec1363SSimon Glass
67022ec1363SSimon Glass   Note: Because the platform data for a U_BOOT_DEVICE() is defined with a
67122ec1363SSimon Glass   static pointer, it is not de-allocated during the remove() method. For
67222ec1363SSimon Glass   a device instantiated using the device tree data, the platform data will
67322ec1363SSimon Glass   be dynamically allocated, and thus needs to be deallocated during the
67422ec1363SSimon Glass   remove() method, either:
67522ec1363SSimon Glass
67622ec1363SSimon Glass      1. if the platdata_auto_alloc_size is non-zero, the deallocation
67722ec1363SSimon Glass      happens automatically within the driver model core; or
67822ec1363SSimon Glass
67922ec1363SSimon Glass      2. when platdata_auto_alloc_size is 0, both the allocation (in probe()
68022ec1363SSimon Glass      or preferably ofdata_to_platdata()) and the deallocation in remove()
68122ec1363SSimon Glass      are the responsibility of the driver author.
68222ec1363SSimon Glass
6835a66a8ffSSimon Glass   e. The device sequence number is set to -1, meaning that it no longer
6845a66a8ffSSimon Glass   has an allocated sequence. If the device is later reactivated and that
6855a66a8ffSSimon Glass   sequence number is still free, it may well receive the name sequence
6865a66a8ffSSimon Glass   number again. But from this point, the sequence number previously used
6875a66a8ffSSimon Glass   by this device will no longer exist (think of SPI bus 2 being removed
6885a66a8ffSSimon Glass   and bus 2 is no longer available for use).
6895a66a8ffSSimon Glass
6905a66a8ffSSimon Glass   f. The device is marked inactive. Note that it is still bound, so the
69122ec1363SSimon Glass   device structure itself is not freed at this point. Should the device be
69222ec1363SSimon Glass   activated again, then the cycle starts again at step 2 above.
69322ec1363SSimon Glass
69422ec1363SSimon Glass5. Unbind stage
69522ec1363SSimon Glass
69622ec1363SSimon GlassThe device is unbound. This is the step that actually destroys the device.
69722ec1363SSimon GlassIf a parent has children these will be destroyed first. After this point
69822ec1363SSimon Glassthe device does not exist and its memory has be deallocated.
69922ec1363SSimon Glass
70022ec1363SSimon Glass
70165c70539SSimon GlassData Structures
70265c70539SSimon Glass---------------
70365c70539SSimon Glass
70465c70539SSimon GlassDriver model uses a doubly-linked list as the basic data structure. Some
70565c70539SSimon Glassnodes have several lists running through them. Creating a more efficient
70665c70539SSimon Glassdata structure might be worthwhile in some rare cases, once we understand
70765c70539SSimon Glasswhat the bottlenecks are.
70865c70539SSimon Glass
70965c70539SSimon Glass
71065c70539SSimon GlassChanges since v1
71165c70539SSimon Glass----------------
71265c70539SSimon Glass
71365c70539SSimon GlassFor the record, this implementation uses a very similar approach to the
71465c70539SSimon Glassoriginal patches, but makes at least the following changes:
71565c70539SSimon Glass
71634e4a2ecSChris Packham- Tried to aggressively remove boilerplate, so that for most drivers there
71765c70539SSimon Glassis little or no 'driver model' code to write.
71865c70539SSimon Glass- Moved some data from code into data structure - e.g. store a pointer to
71965c70539SSimon Glassthe driver operations structure in the driver, rather than passing it
72065c70539SSimon Glassto the driver bind function.
721ae7f4513SSimon Glass- Rename some structures to make them more similar to Linux (struct udevice
72265c70539SSimon Glassinstead of struct instance, struct platdata, etc.)
72365c70539SSimon Glass- Change the name 'core' to 'uclass', meaning U-Boot class. It seems that
72465c70539SSimon Glassthis concept relates to a class of drivers (or a subsystem). We shouldn't
72565c70539SSimon Glassuse 'class' since it is a C++ reserved word, so U-Boot class (uclass) seems
72665c70539SSimon Glassbetter than 'core'.
72754c5d08aSHeiko Schocher- Remove 'struct driver_instance' and just use a single 'struct udevice'.
72865c70539SSimon GlassThis removes a level of indirection that doesn't seem necessary.
72965c70539SSimon Glass- Built in device tree support, to avoid the need for platdata
73065c70539SSimon Glass- Removed the concept of driver relocation, and just make it possible for
73165c70539SSimon Glassthe new driver (created after relocation) to access the old driver data.
73265c70539SSimon GlassI feel that relocation is a very special case and will only apply to a few
73365c70539SSimon Glassdrivers, many of which can/will just re-init anyway. So the overhead of
73465c70539SSimon Glassdealing with this might not be worth it.
73565c70539SSimon Glass- Implemented a GPIO system, trying to keep it simple
73665c70539SSimon Glass
73765c70539SSimon Glass
73800606d7eSSimon GlassPre-Relocation Support
73900606d7eSSimon Glass----------------------
74000606d7eSSimon Glass
74100606d7eSSimon GlassFor pre-relocation we simply call the driver model init function. Only
74200606d7eSSimon Glassdrivers marked with DM_FLAG_PRE_RELOC or the device tree
74300606d7eSSimon Glass'u-boot,dm-pre-reloc' flag are initialised prior to relocation. This helps
74400606d7eSSimon Glassto reduce the driver model overhead.
74500606d7eSSimon Glass
74600606d7eSSimon GlassThen post relocation we throw that away and re-init driver model again.
74700606d7eSSimon GlassFor drivers which require some sort of continuity between pre- and
74800606d7eSSimon Glasspost-relocation devices, we can provide access to the pre-relocation
74900606d7eSSimon Glassdevice pointers, but this is not currently implemented (the root device
75000606d7eSSimon Glasspointer is saved but not made available through the driver model API).
75100606d7eSSimon Glass
75200606d7eSSimon Glass
75338687ae6SSimon GlassSPL Support
75438687ae6SSimon Glass-----------
75538687ae6SSimon Glass
75638687ae6SSimon GlassDriver model can operate in SPL. Its efficient implementation and small code
75738687ae6SSimon Glasssize provide for a small overhead which is acceptable for all but the most
75838687ae6SSimon Glassconstrained systems.
75938687ae6SSimon Glass
76038687ae6SSimon GlassTo enable driver model in SPL, define CONFIG_SPL_DM. You might want to
76138687ae6SSimon Glassconsider the following option also. See the main README for more details.
76238687ae6SSimon Glass
76338687ae6SSimon Glass   - CONFIG_SYS_MALLOC_SIMPLE
76438687ae6SSimon Glass   - CONFIG_DM_WARN
76538687ae6SSimon Glass   - CONFIG_DM_DEVICE_REMOVE
76638687ae6SSimon Glass   - CONFIG_DM_STDIO
76738687ae6SSimon Glass
76838687ae6SSimon Glass
76938687ae6SSimon GlassEnabling Driver Model
77038687ae6SSimon Glass---------------------
77138687ae6SSimon Glass
77238687ae6SSimon GlassDriver model is being brought into U-Boot gradually. As each subsystems gets
77338687ae6SSimon Glasssupport, a uclass is created and a CONFIG to enable use of driver model for
77438687ae6SSimon Glassthat subsystem.
77538687ae6SSimon Glass
77638687ae6SSimon GlassFor example CONFIG_DM_SERIAL enables driver model for serial. With that
77738687ae6SSimon Glassdefined, the old serial support is not enabled, and your serial driver must
77838687ae6SSimon Glassconform to driver model. With that undefined, the old serial support is
77938687ae6SSimon Glassenabled and driver model is not available for serial. This means that when
78038687ae6SSimon Glassyou convert a driver, you must either convert all its boards, or provide for
78138687ae6SSimon Glassthe driver to be compiled both with and without driver model (generally this
78238687ae6SSimon Glassis not very hard).
78338687ae6SSimon Glass
78438687ae6SSimon GlassSee the main README for full details of the available driver model CONFIG
78538687ae6SSimon Glassoptions.
78638687ae6SSimon Glass
78738687ae6SSimon Glass
78865c70539SSimon GlassThings to punt for later
78965c70539SSimon Glass------------------------
79065c70539SSimon Glass
79165c70539SSimon GlassUclasses are statically numbered at compile time. It would be possible to
79265c70539SSimon Glasschange this to dynamic numbering, but then we would require some sort of
79365c70539SSimon Glasslookup service, perhaps searching by name. This is slightly less efficient
79465c70539SSimon Glassso has been left out for now. One small advantage of dynamic numbering might
79565c70539SSimon Glassbe fewer merge conflicts in uclass-id.h.
79665c70539SSimon Glass
79765c70539SSimon Glass
79865c70539SSimon GlassSimon Glass
79965c70539SSimon Glasssjg@chromium.org
80065c70539SSimon GlassApril 2013
80165c70539SSimon GlassUpdated 7-May-13
80265c70539SSimon GlassUpdated 14-Jun-13
80365c70539SSimon GlassUpdated 18-Oct-13
80465c70539SSimon GlassUpdated 5-Nov-13
805