Driver model implementation, tests, demo and GPIO
Subsystems (4)
v5 cover Driver model implementation, tests, demo and GPIO
Note: If you are reviewing this code, but don't have a lot of time, please consider starting with the 'demo' driver (patch 'dm: Add a demonstration/example driver') since it clearly shows how devices and uclasses work. Much of this series consists of test code and plumbing, so is of less interest to driver authors.
This patch adds a driver model implementation. It is taken from the driver model code developed by:
Marek Vasut <[email protected]>
Pavel Herrmann <[email protected]>
Viktor K?iv?k <[email protected]>
Tomas Hlavacek <[email protected]>
Please see doc/driver-model/README.txt for details of how to run this and what to look for. So far the documentation in doc/driver-model has not been updated.
You can find a test version of the code used here in branch dm4 at:
http://git.denx.de/u-boot-x86.git
(Branch dm contains the original implementation)
Changes in v5:
- Change to new SPDX license headers
- Correct >80col line missed last time
- Change to new SPDX license headers
- Fix style nit on for() loop
- Change to new SPDX license headers
- Change to new SPDX license headers
- Change to new SPDX license headers
- Adjust patch to completely remove old driver model documentation
Changes in v4:
- Move common/dm to drivers/core
- device_chld_unbind() continues on error
- Correct 'out.dtb' typo
- Change 'dm dump' command to 'dm tree'
- Remove duplicated .op line
Changes in v3:
- Add new patch to build a device tree file for sandbox
- Updated README.txt to cover changes since version 2
- Tidy up commenting of functions and structures
- Rename per_device_priv_size to per_device_auto_alloc_size, etc.
- Add a flag for tracking whether DM allocates/frees platform_data
- Add function/struct comments to tests
- Fix up demo command help
- Update demo driver to use device tree
- Update GPIO support to use new struct member names
- Tidy up comments/documentation in GPIO module
- Update sandbox GPIO header file comments
- Add new patch to move driver model documentation
Changes in v2:
- Removed pointer return values in favour of integer
- Use driver_bind() in dm_init() instead of writing new code
- Allow driver_bind() to support a NULL parent
- Add dm_warn() to warn about impending doom
- Standardise variable names (e.g. uclass instead of class)
- Remove relocation functions
- Add new header file for lists
- Add new util file to hold utility functions
- Allow a driver to bind to only one uclass
- Remove unneeded arguments to uclass_bind(), uclass_unbind()
- Rename struct device's 'bus' to 'parent'
- Rename data structures to hopefully be clearer
- Put platform_data definitions in their own header file
- Add U_BOOT_DEVICE to declare platform_data
- Add auto-probing feature for platform_data to avoid driver_bind() calls
- Add simple unit test functions
- Add test infrastructure for driver model
- Add integration tests for driver model
- Add device tree support in driver model
- Add automatic allocation of platform_data for FDT
- Add automatic allocation of priv data for devices
- Add automatic allocation of device-specific priv data for uclasses
- Add GPIO uclass and tests
- Add sandbox GPIO driver
- Update gpio command to use driver model
- Add tests for core code
- Add script to run tests
- Add a single include/dm.h to bring in driver model code
Simon Glass (16):
sandbox: Make map_to_sysmem() use a constant pointer
sandbox: Correct data sizes and printf() strings in fdtdec.c
sandbox: config: Don't use 64-bit physical memory
sandbox: Build a device tree file for sandbox
Add cmd_process_error() to report and process errors
dm: Add README for driver model
dm: Add base driver model support
sandbox: config: Enable driver model
dm: Set up driver model after relocation
dm: Add basic tests
dm: Add a 'dm' command for testing
dm: Add a demonstration/example driver
dm: Add GPIO support and tests
sandbox: Convert GPIOs to use driver model
dm: Enable gpio command to support driver model
dm: Remove old driver model documentation
Makefile | 4 + arch/sandbox/config.mk | 2 + arch/sandbox/include/asm/gpio.h | 14 +- arch/sandbox/include/asm/io.h | 2 +- arch/sandbox/include/asm/types.h | 4 +- board/sandbox/dts/sandbox.dts | 20 ++ board/sandbox/sandbox/sandbox.c | 7 +- common/Makefile | 1 + common/board_r.c | 33 +++ common/cmd_demo.c | 102 +++++++ common/cmd_gpio.c | 127 ++++++++- common/command.c | 10 + doc/driver-model/README.txt | 321 ++++++++++++++++++++++ doc/driver-model/UDM-block.txt | 278 ------------------- doc/driver-model/UDM-cores.txt | 126 --------- doc/driver-model/UDM-design.txt | 315 ---------------------- doc/driver-model/UDM-fpga.txt | 115 -------- doc/driver-model/UDM-gpio.txt | 106 -------- doc/driver-model/UDM-hwmon.txt | 118 --------- doc/driver-model/UDM-keyboard.txt | 47 ---- doc/driver-model/UDM-mmc.txt | 319 ---------------------- doc/driver-model/UDM-net.txt | 434 ------------------------------ doc/driver-model/UDM-pci.txt | 257 ------------------ doc/driver-model/UDM-pcmcia.txt | 78 ------ doc/driver-model/UDM-power.txt | 88 ------ doc/driver-model/UDM-rtc.txt | 253 ------------------ doc/driver-model/UDM-serial.txt | 175 ------------ doc/driver-model/UDM-spi.txt | 200 -------------- doc/driver-model/UDM-stdio.txt | 191 ------------- doc/driver-model/UDM-tpm.txt | 48 ---- doc/driver-model/UDM-twserial.txt | 47 ---- doc/driver-model/UDM-usb.txt | 94 ------- doc/driver-model/UDM-video.txt | 74 ------ doc/driver-model/UDM-watchdog.txt | 329 ----------------------- drivers/core/Makefile | 27 ++ drivers/core/device.c | 323 ++++++++++++++++++++++ drivers/core/lists.c | 155 +++++++++++ drivers/core/root.c | 102 +++++++ drivers/core/uclass.c | 285 ++++++++++++++++++++ drivers/core/util.c | 37 +++ drivers/demo/Makefile | 31 +++ drivers/demo/demo-pdata.c | 47 ++++ drivers/demo/demo-shape.c | 130 +++++++++ drivers/demo/demo-simple.c | 47 ++++ drivers/demo/demo-uclass.c | 60 +++++ drivers/gpio/Makefile | 2 + drivers/gpio/gpio-uclass.c | 266 +++++++++++++++++++ drivers/gpio/sandbox.c | 210 +++++++++------ include/asm-generic/global_data.h | 8 + include/asm-generic/gpio.h | 104 ++++++++ include/command.h | 9 + include/common.h | 2 +- include/configs/sandbox.h | 10 +- include/dm-demo.h | 36 +++ include/dm.h | 14 + include/dm/device-internal.h | 87 ++++++ include/dm/device.h | 136 ++++++++++ include/dm/lists.h | 39 +++ include/dm/platform_data.h | 22 ++ include/dm/root.h | 53 ++++ include/dm/test.h | 167 ++++++++++++ include/dm/uclass-id.h | 28 ++ include/dm/uclass-internal.h | 85 ++++++ include/dm/uclass.h | 142 ++++++++++ include/dm/ut.h | 95 +++++++ include/dm/util.h | 29 ++ lib/fdtdec.c | 8 +- test/dm/Makefile | 40 +++ test/dm/cmd_dm.c | 133 ++++++++++ test/dm/core.c | 544 ++++++++++++++++++++++++++++++++++++++ test/dm/gpio.c | 111 ++++++++ test/dm/test-driver.c | 146 ++++++++++ test/dm/test-fdt.c | 135 ++++++++++ test/dm/test-main.c | 107 ++++++++ test/dm/test-uclass.c | 104 ++++++++ test/dm/test.dts | 59 +++++ test/dm/ut.c | 33 +++ 77 files changed, 4745 insertions(+), 3802 deletions(-) create mode 100644 board/sandbox/dts/sandbox.dts create mode 100644 common/cmd_demo.c create mode 100644 doc/driver-model/README.txt delete mode 100644 doc/driver-model/UDM-block.txt delete mode 100644 doc/driver-model/UDM-cores.txt delete mode 100644 doc/driver-model/UDM-design.txt delete mode 100644 doc/driver-model/UDM-fpga.txt delete mode 100644 doc/driver-model/UDM-gpio.txt delete mode 100644 doc/driver-model/UDM-hwmon.txt delete mode 100644 doc/driver-model/UDM-keyboard.txt delete mode 100644 doc/driver-model/UDM-mmc.txt delete mode 100644 doc/driver-model/UDM-net.txt delete mode 100644 doc/driver-model/UDM-pci.txt delete mode 100644 doc/driver-model/UDM-pcmcia.txt delete mode 100644 doc/driver-model/UDM-power.txt delete mode 100644 doc/driver-model/UDM-rtc.txt delete mode 100644 doc/driver-model/UDM-serial.txt delete mode 100644 doc/driver-model/UDM-spi.txt delete mode 100644 doc/driver-model/UDM-stdio.txt delete mode 100644 doc/driver-model/UDM-tpm.txt delete mode 100644 doc/driver-model/UDM-twserial.txt delete mode 100644 doc/driver-model/UDM-usb.txt delete mode 100644 doc/driver-model/UDM-video.txt delete mode 100644 doc/driver-model/UDM-watchdog.txt create mode 100644 drivers/core/Makefile create mode 100644 drivers/core/device.c create mode 100644 drivers/core/lists.c create mode 100644 drivers/core/root.c create mode 100644 drivers/core/uclass.c create mode 100644 drivers/core/util.c create mode 100644 drivers/demo/Makefile create mode 100644 drivers/demo/demo-pdata.c create mode 100644 drivers/demo/demo-shape.c create mode 100644 drivers/demo/demo-simple.c create mode 100644 drivers/demo/demo-uclass.c create mode 100644 drivers/gpio/gpio-uclass.c create mode 100644 include/dm-demo.h create mode 100644 include/dm.h create mode 100644 include/dm/device-internal.h create mode 100644 include/dm/device.h create mode 100644 include/dm/lists.h create mode 100644 include/dm/platform_data.h create mode 100644 include/dm/root.h create mode 100644 include/dm/test.h create mode 100644 include/dm/uclass-id.h create mode 100644 include/dm/uclass-internal.h create mode 100644 include/dm/uclass.h create mode 100644 include/dm/ut.h create mode 100644 include/dm/util.h create mode 100644 test/dm/Makefile create mode 100644 test/dm/cmd_dm.c create mode 100644 test/dm/core.c create mode 100644 test/dm/gpio.c create mode 100644 test/dm/test-driver.c create mode 100644 test/dm/test-fdt.c create mode 100644 test/dm/test-main.c create mode 100644 test/dm/test-uclass.c create mode 100644 test/dm/test.dts create mode 100644 test/dm/ut.c
Signature · 1 line
1.8.4
PATCH v5 1/16 sandbox: Make map_to_sysmem() use a constant pointer
Very often a constant pointer is passed to this function, so we should declare this, since map_to_sysmem() does not change the pointer.
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
arch/sandbox/include/asm/io.h | 2 +- include/common.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/sandbox/include/asm/io.h +1 -1
@@ -38,6 +38,6 @@ static inline void unmap_sysmem(const void *vaddr) }/* Map from a pointer to our RAM buffer */ -phys_addr_t map_to_sysmem (void *ptr); +phys_addr_t map_to_sysmem (const void *ptr);#endif
include/common.h +1 -1
@@ -923,7 +923,7 @@ static inline void unmap_sysmem(const void *vaddr) { } -static inline phys_addr_t map_to_sysmem (void *ptr) +static inline phys_addr_t map_to_sysmem (const void *ptr) {return (phys_addr_t )(uintptr_t )ptr; }
Signature · 1 line
1.8.4
PATCH v5 2/16 sandbox: Correct data sizes and printf() strings in fdtdec.c
In reply to Simon GlassThere are a few warnings in this file when building for sandbox. Addresses coming from the device tree need to be treated as ulong as elsewhere in U-Boot and we must use map_sysmem() to convert to a pointer when needed.
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
lib/fdtdec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/fdtdec.c +4 -4
@@ -84,10 +84,10 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node, size = (fdt_size_t *)((char *)cell +sizeof (fdt_addr_t)); *sizep =fdt_size_to_cpu (*size); -debug ("addr=%p, size=%p\n" , (void *)addr, - (void *)*sizep); +debug ("addr=%08lx, size=%08x\n" , + (ulong )addr, *sizep); }else { -debug ("%p\n" , (void *)addr); +debug ("%08lx\n" , (ulong )addr); }return addr; }
@@ -609,7 +609,7 @@ int fdtdec_decode_region(const void *blob, int node,if (!cell || (len !=sizeof (fdt_addr_t) *2 ))return -1 ; - *ptrp = (void *)fdt_addr_to_cpu (*cell); + *ptrp =map_sysmem (fdt_addr_to_cpu (*cell), *size); *size =fdt_size_to_cpu (cell[1 ]);debug ("%s: size=%zx\n" , __func__, *size);return 0 ;
Signature · 1 line
1.8.4
PATCH v5 3/16 sandbox: config: Don't use 64-bit physical memory
In reply to Simon GlassSandbox uses an emulated memory map which is quite small. We don't need the CONFIG_PHYS_64BIT option since we can address memory with a 32-bit offset into our ram_buf.
Adjust the phys_addr_t and phys_size_t types accordingly.
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
arch/sandbox/include/asm/types.h | 4 ++-- include/configs/sandbox.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-)
arch/sandbox/include/asm/types.h +2 -2
@@ -48,8 +48,8 @@ typedef unsigned long long u64;#define BITS_PER_LONG CONFIG_SANDBOX_BITS_PER_LONGtypedef unsigned long dma_addr_t ; -typedef unsigned long phys_addr_t ; -typedef unsigned long phys_size_t ; +typedef u32 phys_addr_t ; +typedef u32 phys_size_t ;#endif /* __KERNEL__ */
include/configs/sandbox.h +0 -1
@@ -72,7 +72,6 @@#define CONFIG_SYS_LOAD_ADDR 0x00000000#define CONFIG_SYS_MEMTEST_START 0x00100000#define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_MEMTEST_START + 0x1000) -#define CONFIG_PHYS_64BIT #define CONFIG_SYS_FDT_LOAD_ADDR 0x1000000/* Size of our emulated memory */
Signature · 1 line
1.8.4
PATCH v5 4/16 sandbox: Build a device tree file for sandbox
In reply to Simon GlassAdd support for building a device tree for sandbox's CONFIG_OF_HOSTFILE option to make it easier to use device tree with sandbox.
This adjusts the Makefile to build a u-boot.dtb file which can be passed to sandbox U-Boot with:
./u-boot -d u-boot.dtb
---
Changes in v5: None
Changes in v4: None
Changes in v3:
- Add new patch to build a device tree file for sandbox
Changes in v2: None
Makefile | 1 + arch/sandbox/config.mk | 2 ++ board/sandbox/dts/sandbox.dts | 20 ++++++++++++++++++++ include/configs/sandbox.h | 1 + 4 files changed, 24 insertions(+) create mode 100644 board/sandbox/dts/sandbox.dts
Makefile +1 -0
@@ -402,6 +402,7 @@ ALL-$(CONFIG_SPL) += $(obj)spl/u-boot-spl.bin ALL-$(CONFIG_SPL_FRAMEWORK) += $(obj)u-boot.img ALL-$(CONFIG_TPL) += $(obj)tpl/u-boot-tpl.bin ALL-$(CONFIG_OF_SEPARATE) += $(obj)u-boot.dtb $(obj)u-boot-dtb.bin +ALL-$(CONFIG_OF_HOSTFILE) += $(obj)u-boot.dtb ifneq ($(CONFIG_SPL_TARGET),) ALL-$(CONFIG_SPL) += $(obj)$(subst ",,$(CONFIG_SPL_TARGET)) endif
arch/sandbox/config.mk +2 -0
@@ -7,3 +7,5 @@ PLATFORM_LIBS += -lrt # Support generic board on sandbox __HAVE_ARCH_GENERIC_BOARD := y + +CONFIG_ARCH_DEVICE_TREE := sandbox
board/sandbox/dts/sandbox.dts new file +20 -0
@@ -0,0 +1,20 @@ +/dts-v1/; + +/ { + triangle { + compatible = "demo-shape"; + colour = "cyan"; + sides = <3>; + character = <83>; + }; + square { + compatible = "demo-shape"; + colour = "blue"; + sides = <4>; + }; + hexagon { + compatible = "demo-simple"; + colour = "white"; + sides = <6>; + }; +};
include/configs/sandbox.h +1 -0
@@ -30,6 +30,7 @@#define CONFIG_FIT_SIGNATURE #define CONFIG_RSA #define CONFIG_CMD_FDT +#define CONFIG_DEFAULT_DEVICE_TREE sandbox#define CONFIG_FS_FAT #define CONFIG_FS_EXT4
Signature · 1 line
1.8.4
PATCH v5 5/16 Add cmd_process_error() to report and process errors
In reply to Simon GlassU-Boot now uses errors defined in include/errno.h which are negative integers. Commands which fail need to report the error and return 1 to indicate failure. Add this functionality in cmd_process_error().
For now this merely reports the error number. It would be possible also to produce a helpful error message by storing the error strings in U-Boot.
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
common/command.c | 10 ++++++++++ include/command.h | 9 +++++++++ 2 files changed, 19 insertions(+)
common/command.c +10 -0
@@ -538,3 +538,13 @@ enum command_ret_t cmd_process(int flag, int argc, char * const argv[], rc =cmd_usage (cmdtp);return rc; } + +int cmd_process_error (cmd_tbl_t *cmdtp,int err) +{ +if (err) { +printf ("Command '%s' failed: Error %d\n" , cmdtp->name, err); +return 1 ; + } + +return 0 ; +}
include/command.h +9 -0
@@ -64,6 +64,15 @@ extern int var_complete(int argc, char * const argv[], char last_char, int maxv,extern int cmd_auto_complete (const char *const prompt,char *buf,int *np,int *colp);#endif +/** +* cmd_process_error() - report and process a possible error +* +* @cmdtp: Command which caused the error +* @err: Error code (0 if none, -ve for error, like -EIO) +* @return 0 if there is not error, 1 (CMD_RET_FAILURE) if an error is found +*/ +int cmd_process_error (cmd_tbl_t *cmdtp,int err); +/* * Monitor Command *
Signature · 1 line
1.8.4
PATCH v5 6/16 dm: Add README for driver model
In reply to Simon GlassThis adds a README to help with understanding of this series.
---
Changes in v5: None
Changes in v4: None
Changes in v3:
- Updated README.txt to cover changes since version 2
Changes in v2:
- Removed pointer return values in favour of integer
- Use driver_bind() in dm_init() instead of writing new code
- Allow driver_bind() to support a NULL parent
- Add dm_warn() to warn about impending doom
- Standardise variable names (e.g. uclass instead of class)
- Remove relocation functions
- Add new header file for lists
- Add new util file to hold utility functions
- Allow a driver to bind to only one uclass
- Remove unneeded arguments to uclass_bind(), uclass_unbind()
- Rename struct device's 'bus' to 'parent'
- Rename data structures to hopefully be clearer
- Put platform_data definitions in their own header file
- Add U_BOOT_DEVICE to declare platform_data
- Add auto-probing feature for platform_data to avoid driver_bind() calls
- Add simple unit test functions
- Add test infrastructure for driver model
- Add integration tests for driver model
- Add device tree support in driver model
- Add automatic allocation of platform_data for FDT
- Add automatic allocation of priv data for devices
- Add automatic allocation of device-specific priv data for uclasses
- Add GPIO uclass and tests
- Add sandbox GPIO driver
- Update gpio command to use driver model
- Add tests for core code
- Add script to run tests
- Add a single include/dm.h to bring in driver model code
doc/driver-model/README.txt | 321 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 doc/driver-model/README.txt
doc/driver-model/README.txt new file +321 -0
@@ -0,0 +1,321 @@ +Driver Model +============ + +This README contains high-level information about driver model, a unified +way of declaring and accessing drivers in U-Boot. The original work was done +by: + + Marek Vasut <[email protected]> + Pavel Herrmann <[email protected]> + Viktor K?iv?k <[email protected]> + Tomas Hlavacek <[email protected]> + +This has been both simplified and extended into the current implementation +by: + + Simon Glass <[email protected]> + + +Terminology +----------- + +Uclass - a group of device which operate in the same way. A uclass provides + a way of accessing invidual devices within the group, but always + using the same interface. For example a GPIO uclass provides + operations for get/set value. An I2C uclass may have 10 I2C ports, + 4 with one driver, and 6 with another. + +Driver - some code which talks to a peripheral and presents a higher-level + interface to it. + +Device - an instance of a driver, tied to a particular port or peripheral. + + +How to try it +------------- + +Build U-Boot sandbox and run it: + + make sandbox_config + make + ./u-boot + + (type 'reset' to exit U-Boot) + + +There is a uclass called 'demo'. This uclass handles +saying hello, and reporting its status. There are two drivers in this +uclass: + + - simple: Just prints a message for hello, doesn't implement status + - shape: Prints shapes and reports number of characters printed as status + +The demo class is pretty simple, but not trivial. The intention is that it +can be used for testing, so it will implement all driver model features and +provide 100% code coverage of them. It does have multiple drivers, it +handles parameter data and platform_data (data which tells the driver how +to operate on a particular platform) and it uses private driver data. + +To try it, see the example session below: + +=>demo hello 1 +Hello '@' from 07981110: red 4 +=>demo status 2 +Status: 0 +=>demo hello 2 +g +r@ +e@@ +e@@@ +n@@@@ +g@@@@@ +=>demo status 2 +Status: 21 +=>demo hello 4 ^ + y^^^ + e^^^^^ +l^^^^^^^ +l^^^^^^^ + o^^^^^ + w^^^ +=>demo status 4 +Status: 36 +=> + + +Running the tests +----------------- + +The intent with driver model is that the core portion has 100% test coverage +in sandbox, and every uclass has its own test. As a move towards this, tests +are provided in test/dm. To run them, try: + + ./test/dm/test-dm.sh + + +What is going on? +----------------- + +Let's start at the top. The demo command is in common/cmd_demo.c. It does +the usual command procesing and then: + + struct device *demo_dev; + + ret = uclass_get_device(UCLASS_DEMO, &demo_dev); + +UCLASS_DEMO means the class of devices which implement 'demo'. Other +classes might be MMC, or GPIO, hashing or serial. The idea is that the +devices in the class all share a particular way of working. The class +presents a unified view of all these devices to U-Boot. + +This function looks up the device for the demo uclass. Given a device +number we can find the device because all devices have registered with +the UCLASS_DEMO uclass. + +Having found the device, we activate it with: + + ret = driver_activate(demo_dev); + +This is because all devices are inactive until used in U-Boot. The exact +mechanism of activating a driver will hopefully change. For example, i +may be possible to combine uclass_get_child() and driver_activate(). + +Now that we have the device we can do things like: + + return demo_hello(demo_dev, ch); + +This function is in the demo uclass. It takes care of calling the 'hello' +method of the relevant driver. Bearing in mind that there are two drivers, +this particular device may use one or other of them. + +The code for demo_hello() is in drivers/demo/demo-uclass.c: + +int demo_hello(struct device *dev, int ch) +{ + const struct demo_ops *ops = device_get_ops(dev); + + if (!ops->hello) + return -ENOSYS; + + return ops->hello(dev, ch); +} + +As you can see it just calls the relevant driver method. One of these is +in drivers/demo/demo-simple.c: + +static int simple_hello(struct device *dev, int ch) +{ + const struct dm_demo_pdata *pdata = dev->platform_data; + + printf("Hello from %08x: %s %d\n", map_to_sysmem(dev), + pdata->colour, pdata->sides); + + return 0; +} + + +So that is a trip from top to bottom but it leaves a lot of topics to +address. + + +Declaring Drivers +----------------- + +A driver declaration looks something like this (see +drivers/demo/demo-shape.c): + +static const struct demo_ops simple_ops = { + .hello = shape_hello, + .status = shape_status, +}; + +U_BOOT_DRIVER(demo_shape_drv) = { + .name = "demo_shape_drv", + .id = UCLASS_DEMO, + .ops = &simple_ops, + .priv_data_size = sizeof(struct shape_data), +}; + + +This driver has two methods (hello and status) and requires a bit +of private data (accessible through dev->priv once the driver has +been probed). It is a member of UCLASS_DEMO so will register itself +there. + +In U_BOOT_DRIVER it is also possible to specify special methods for probe, +and bind, and these are called at appropriate times. For many drivers +it is hoped that only 'probe' and 'remove' will be needed. + +The U_BOOT_DRIVER macro creates a data structure accessible from C, +so driver model can find the drivers that are available. + + +Platform Data +------------- + +Where does the platform data come from? See demo-pdata.c which +sets up a table of driver names and their associated platform data. +The data can be interpreted by the drivers however they like - it is +basically a communication scheme between the board-specific code and +the generic drivers, which are intended to work on any board. + +Drivers can acceess their data via dev->info->platform_data. Here is +the declaration for the platform data, which would normally appear +in the board file. + + static const struct dm_demo_cdata red_square = { + .colour = "red", + .sides = 4. + }; + static const struct driver_info info[] = { + { + .name = "demo_shape_drv", + .platform_data = &red_square, + }, + }; + + demo1 = driver_bind(root, &info[0]); + + +Device Tree +----------- + +While platform_data is useful, a more flexible way of providing device data is +by using device tree. With device tree we replace the above code with the +following device treefragment: + + red-square { + compatible = "demo-shape"; + colour = "red"; + sides = <4>; + }; + + +The easiest way to make this work it to add a platform_data_size member to +the driver: + + .platform_data_auto_alloc_size = sizeof(struct dm_test_pdata), + +This will be allocated and zeroed before the driver's probe method is called. +The driver can then read the information out of the device tree and put it +in dev->priv, typically using a ..._parse_dt() function. + + +Declaring Uclasses +------------------ + +The demo uclass is declared like this: + +U_BOOT_CLASS(demo) = { + .id = UCLASS_DEMO, +}; + +It is also possible to specify special methods for probe, etc. The uclass +numbering comes from include/dm/uclass.h. To add a new uclass, add to the +end of the enum there, then declare your uclass as above. + + +Data Structures +--------------- + +Driver model uses a doubly-linked list as the basic data structure. Some +nodes have several lists running through them. Creating a more efficient +data structure might be worthwhile in some rare cases, once we understand +what the bottlenecks are. + + +Changes since v1 +---------------- + +For the record, this implementation uses a very similar approach to the +original patches, but makes at least the following changes: + +- Tried to agressively remove boilerplate, so that for most drivers there +is little or no 'driver model' code to write. +- Moved some data from code into data structure - e.g. store a pointer to +the driver operations structure in the driver, rather than passing it +to the driver bind function. +- Rename some structures to make them more similar to Linux (struct device +instead of struct instance, struct platform_data, etc.) +- Change the name 'core' to 'uclass', meaning U-Boot class. It seems that +this concept relates to a class of drivers (or a subsystem). We shouldn't +use 'class' since it is a C++ reserved word, so U-Boot class (uclass) seems +better than 'core'. +- Remove 'struct driver_instance' and just use a single 'struct device'. +This removes a level of indirection that doesn't seem necessary. +- Built in device tree support, to avoid the need for platform_data +- Removed the concept of driver relocation, and just make it possible for +the new driver (created after relocation) to access the old driver data. +I feel that relocation is a very special case and will only apply to a few +drivers, many of which can/will just re-init anyway. So the overhead of +dealing with this might not be worth it. +- Implemented a GPIO system, trying to keep it simple + + +Things to punt for later +------------------------ + +- SPL support - this will have to be present before many drivers can be +converted, but it seems like we can add it once we are happy with the +core implementation. +- Pre-relocation support - similar story + +That is not to say that no thinking has gone into these - in fact there +is quite a lot there. However, getting these right is non-trivial and +there is a high cost associated with going down the wrong path. + +For SPL, it may be possible to fit in a simplified driver model with only +bind and probe methods, to reduce size. + +For pre-relocation we can simply call the driver model init function. Then +post relocation we throw that away and re-init driver model again. For drivers +which require some sort of continuity between pre- and post-relocation +devices, we can provide access to the pre-relocatoin device pointers. + + +Simon Glass +sjg at chromium.org +April 2013 +Updated 7-May-13 +Updated 14-Jun-13 +Updated 18-Oct-13
Signature · 1 line
1.8.4
PATCH v5 6/16 dm: Add README for driver model
Dear Simon Glass,
[...]
doc/driver-model/README.txt line 104
Quoted 9 lines
doc/driver-model/README.txt new file +9
-0+What is going on? +----------------- + +Let's start at the top. The demo command is in common/cmd_demo.c. It does +the usual command procesing and then: + + struct device *demo_dev; + + ret = uclass_get_device(UCLASS_DEMO, &demo_dev);
Which device will this assign into demo_dev if there are multiple devices registered with the demo uclass ?
Quoted 4 lines
doc/driver-model/README.txt new file +4
-0+UCLASS_DEMO means the class of devices which implement 'demo'. Other +classes might be MMC, or GPIO, hashing or serial. The idea is that the +devices in the class all share a particular way of working. The class +presents a unified view of all these devices to U-Boot.
[...]
Quoted 7 lines
doc/driver-model/README.txt new file +7
-0+Declaring Drivers +----------------- + +A driver declaration looks something like this (see +drivers/demo/demo-shape.c): + +static const struct demo_ops simple_ops = {
doc/driver-model/README.txt line 177
Quoted 10 lines
doc/driver-model/README.txt new file +10
-0+ .hello = shape_hello, + .status = shape_status, +}; + +U_BOOT_DRIVER(demo_shape_drv) = { + .name = "demo_shape_drv", + .id = UCLASS_DEMO, + .ops = &simple_ops, + .priv_data_size = sizeof(struct shape_data), +};
We are not discussing relocation here yet, right ?
Quoted 28 lines
doc/driver-model/README.txt new file +28
-0+This driver has two methods (hello and status) and requires a bit +of private data (accessible through dev->priv once the driver has +been probed). It is a member of UCLASS_DEMO so will register itself +there. + +In U_BOOT_DRIVER it is also possible to specify special methods for probe, +and bind, and these are called at appropriate times. For many drivers +it is hoped that only 'probe' and 'remove' will be needed. + +The U_BOOT_DRIVER macro creates a data structure accessible from C, +so driver model can find the drivers that are available. + + +Platform Data +------------- + +Where does the platform data come from? See demo-pdata.c which +sets up a table of driver names and their associated platform data. +The data can be interpreted by the drivers however they like - it is +basically a communication scheme between the board-specific code and +the generic drivers, which are intended to work on any board. + +Drivers can acceess their data via dev->info->platform_data. Here is +the declaration for the platform data, which would normally appear +in the board file. + + static const struct dm_demo_cdata red_square = { + .colour = "red",
doc/driver-model/README.txt line 217
Quoted 10 lines
doc/driver-model/README.txt new file +10
-0+ .sides = 4. + }; + static const struct driver_info info[] = { + { + .name = "demo_shape_drv", + .platform_data = &red_square, + }, + }; + + demo1 = driver_bind(root, &info[0]);
We need dev_get_platdata() call or something, otherwise someone will shoot himself in the face with a NULL pointer.
Quoted 20 lines
doc/driver-model/README.txt new file +4
-0+Device Tree +----------- + +While platform_data is useful, a more flexible way of providing devicedata is +by using device tree. With device tree we replace the above code with the +following device treefragment:
doc/driver-model/README.txt new file +14
-0+ + red-square { + compatible = "demo-shape"; + colour = "red"; + sides = <4>; + }; + + +The easiest way to make this work it to add a platform_data_size member to +the driver: + + .platform_data_auto_alloc_size = sizeof(struct dm_test_pdata), + +This will be allocated and zeroed before the driver's probe method is
Quoted 2 lines
called. +The driver can then read the information out of the device tree and put it +in
dev->priv, typically using a ..._parse_dt() function.
Can the driver maybe implement some ofdata_to_pdata() callback?
doc/driver-model/README.txt line 255
Quoted 12 lines
doc/driver-model/README.txt new file +12
-0+Declaring Uclasses +------------------ + +The demo uclass is declared like this: + +U_BOOT_CLASS(demo) = { + .id = UCLASS_DEMO, +}; + +It is also possible to specify special methods for probe, etc. The uclass +numbering comes from include/dm/uclass.h. To add a new uclass, add to the +end of the enum there, then declare your uclass as above.
I wonder if we cannot even automate the numbering here ;-)
[...]
PATCH v5 6/16 dm: Add README for driver model
Hi Marek,
Quoted 5 lines · Marek Vasut
Dear Simon Glass,
[...]
Quoted 12 lines
doc/driver-model/README.txt line 104
Quoted 9 lines
doc/driver-model/README.txt new file +9
-0+What is going on? +----------------- + +Let's start at the top. The demo command is in common/cmd_demo.c. It does +the usual command procesing and then: + + struct device *demo_dev; + + ret = uclass_get_device(UCLASS_DEMO, &demo_dev);Which device will this assign into
demo_devif there are multiple devices registered with the demo uclass ?
Actually there is a missing parameter there in the README - will fix this.
Quoted 19 lines
Quoted 5 lines
doc/driver-model/README.txt new file +4
-0+UCLASS_DEMO means the class of devices which implement 'demo'. Other +classes might be MMC, or GPIO, hashing or serial. The idea is that the +devices in the class all share a particular way of working. The class +presents a unified view of all these devices to U-Boot.[...]
Quoted 11 lines
doc/driver-model/README.txt new file +11
-0+Declaring Drivers +----------------- + +A driver declaration looks something like this (see +drivers/demo/demo-shape.c): + +static const struct demo_ops simple_ops = { + .hello = shape_hello, + .status = shape_status, +}; +
Quoted 8 lines
doc/driver-model/README.txt line 177
Quoted 6 lines
doc/driver-model/README.txt new file +6
-0+U_BOOT_DRIVER(demo_shape_drv) = { + .name = "demo_shape_drv", + .id = UCLASS_DEMO, + .ops = &simple_ops, + .priv_data_size = sizeof(struct shape_data), +};We are not discussing relocation here yet, right ?
Nope.
Quoted 34 lines
Quoted 34 lines
doc/driver-model/README.txt new file +33
-0+This driver has two methods (hello and status) and requires a bit +of private data (accessible through dev->priv once the driver has +been probed). It is a member of UCLASS_DEMO so will register itself +there. + +In U_BOOT_DRIVER it is also possible to specify special methods for probe, +and bind, and these are called at appropriate times. For many drivers +it is hoped that only 'probe' and 'remove' will be needed. + +The U_BOOT_DRIVER macro creates a data structure accessible from C, +so driver model can find the drivers that are available. + + +Platform Data +------------- + +Where does the platform data come from? See demo-pdata.c which +sets up a table of driver names and their associated platform data. +The data can be interpreted by the drivers however they like - it is +basically a communication scheme between the board-specific code and +the generic drivers, which are intended to work on any board. + +Drivers can acceess their data via dev->info->platform_data. Here is +the declaration for the platform data, which would normally appear +in the board file. + + static const struct dm_demo_cdata red_square = { + .colour = "red", + .sides = 4. + }; + static const struct driver_info info[] = { + { + .name = "demo_shape_drv",
Quoted 8 lines
doc/driver-model/README.txt line 217
Quoted 5 lines
doc/driver-model/README.txt new file +5
-0+ .platform_data = &red_square, + }, + }; + + demo1 = driver_bind(root, &info[0]);We need
dev_get_platdata()call or something, otherwise someone will shoot himself in the face with a NULL pointer.
OK I'll add that, also something for private data.
Quoted 17 lines
Quoted 17 lines
doc/driver-model/README.txt new file +4
-0+Device Tree +----------- + +While platform_data is useful, a more flexible way of providing devicedata is +by using device tree. With device tree we replace the above code with the +following device treefragment:
doc/driver-model/README.txt new file +10
-0+ + red-square { + compatible = "demo-shape"; + colour = "red"; + sides = <4>; + }; + + +The easiest way to make this work it to add a platform_data_size member to +the driver:
Quoted 8 lines
Quoted 6 lines
doc/driver-model/README.txt new file +4
-0+ + .platform_data_auto_alloc_size = sizeof(struct dm_test_pdata), + +This will be allocated and zeroed before the driver's probe method iscalled. +The driver can then read the information out of the device tree and put it +in
dev->priv, typically using a ..._parse_dt() function.Can the driver maybe implement some
ofdata_to_pdata()callback?
OK I'll add that to the driver interface.
Quoted 15 lines
doc/driver-model/README.txt line 255
Quoted 13 lines
doc/driver-model/README.txt new file +12
-0+Declaring Uclasses +------------------ + +The demo uclass is declared like this: + +U_BOOT_CLASS(demo) = { + .id = UCLASS_DEMO, +}; + +It is also possible to specify special methods for probe, etc. The uclass +numbering comes from include/dm/uclass.h. To add a new uclass, add to the +end of the enum there, then declare your uclass as above.I wonder if we cannot even automate the numbering here ;-)
We could but it would need some lookup mechanism. String search? I'll leave it as is at the moment but add something to the bottom of the README.
Regards,
Simon
PATCH v5 6/16 dm: Add README for driver model
Hi Simon,
[...]
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
doc/driver-model/README.txt new file +6
-0+Declaring Uclasses +------------------ + +The demo uclass is declared like this: + +U_BOOT_CLASS(demo) = {Quoted 8 lines
Quoted 6 lines
doc/driver-model/README.txt new file +4
-0+ .id = UCLASS_DEMO, +}; + +It is also possible to specify special methods for probe, etc. Theuclass +numbering comes from
include/dm/uclass.h. To add a new uclass, add to the +end of the enum there, then declare your uclass as above.I wonder if we cannot even automate the numbering here ;-)
Quoted 3 lines
We could but it would need some lookup mechanism. String search? I'll leave it as is at the moment but add something to the bottom of the README.
Yep, full ACK. Thanks!
Best regards,
Marek Vasut
PATCH v5 6/16 dm: Add README for driver model
In reply to Simon GlassHi
Quoted 17 lines · On Tuesday 05 of November 2013 14:34:03 Simon Glass wrote:
Quoted 8 lines
Quoted 8 lines
doc/driver-model/README.txt new file +8
-0+Declaring Uclasses +------------------ + +The demo uclass is declared like this: + +U_BOOT_CLASS(demo) = { + .id = UCLASS_DEMO, +};Quoted 8 lines
Quoted 6 lines
(quoted diff) +2
-0+ +It is also possible to specify special methods for probe, etc. Theuclass
+numbering comes frominclude/dm/uclass.h. To add a new uclass, add to the
+end of the enum there, then declare your uclass as above.I wonder if we cannot even automate the numbering here ;-)
Quoted 3 lines
We could but it would need some lookup mechanism. String search? I'll leave it as is at the moment but add something to the bottom of the README.
please keep in mind that the original design was done with the possibility of loading drivers as modules at runtime, while only having certain uclasses compiled in. having dynamic ID numbers would complicate things (more precisely, no dynamic uclass loading, uclass id map would be part of the driver ABI).
if you have ditched the whole idea of runtime loading then please ignore me, i havent cought up with all the changes
Regards
Pavel Herrmann
PATCH v5 7/16 dm: Add base driver model support
In reply to Simon GlassAdd driver model functionality for generic board.
This includes data structures and base code for registering devices and uclasses (groups of devices with the same purpose, e.g. all I2C ports will be in the same uclass).
The feature is enabled with CONFIG_DM.
---
Changes in v5:
- Change to new SPDX license headers
- Correct >80col line missed last time
Changes in v4:
- Move common/dm to drivers/core
- device_chld_unbind() continues on error
Changes in v3:
- Tidy up commenting of functions and structures
- Rename per_device_priv_size to per_device_auto_alloc_size, etc.
- Add a flag for tracking whether DM allocates/frees platform_data
Changes in v2: None
Makefile | 1 + drivers/core/Makefile | 27 ++++ drivers/core/device.c | 323 ++++++++++++++++++++++++++++++++++++++ drivers/core/lists.c | 155 ++++++++++++++++++ drivers/core/root.c | 102 ++++++++++++ drivers/core/uclass.c | 285 +++++++++++++++++++++++++++++++++ drivers/core/util.c | 37 +++++ include/asm-generic/global_data.h | 8 + include/dm.h | 14 ++ include/dm/device-internal.h | 87 ++++++++++ include/dm/device.h | 136 ++++++++++++++++ include/dm/lists.h | 39 +++++ include/dm/platform_data.h | 22 +++ include/dm/root.h | 53 +++++++ include/dm/uclass-id.h | 28 ++++ include/dm/uclass-internal.h | 85 ++++++++++ include/dm/uclass.h | 142 +++++++++++++++++ include/dm/util.h | 29 ++++ 18 files changed, 1573 insertions(+) create mode 100644 drivers/core/Makefile create mode 100644 drivers/core/device.c create mode 100644 drivers/core/lists.c create mode 100644 drivers/core/root.c create mode 100644 drivers/core/uclass.c create mode 100644 drivers/core/util.c create mode 100644 include/dm.h create mode 100644 include/dm/device-internal.h create mode 100644 include/dm/device.h create mode 100644 include/dm/lists.h create mode 100644 include/dm/platform_data.h create mode 100644 include/dm/root.h create mode 100644 include/dm/uclass-id.h create mode 100644 include/dm/uclass-internal.h create mode 100644 include/dm/uclass.h create mode 100644 include/dm/util.h
Makefile +1 -0
@@ -323,6 +323,7 @@ LIBS-y += lib/libfdt/libfdt.o LIBS-y += api/libapi.o LIBS-y += post/libpost.o LIBS-y += test/libtest.o +LIBS-$(CONFIG_DM) += drivers/core/libdm.o ifneq ($(CONFIG_OMAP_COMMON),) LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
drivers/core/Makefile new file +27 -0
@@ -0,0 +1,27 @@ +# +# Copyright (c) 2013 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +include $(TOPDIR)/config.mk + +LIB := $(obj)libdm.o + +COBJS := device.o lists.o root.o uclass.o util.o +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +#########################################################################
drivers/core/device.c new file +323 -0
323 lines not on this page · raw message
drivers/core/lists.c new file +155 -0
155 lines not on this page · raw message
drivers/core/root.c new file +102 -0
102 lines not on this page · raw message
drivers/core/uclass.c new file +285 -0
285 lines not on this page · raw message
drivers/core/util.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <vsprintf.h> + +void dm_warn (const char *fmt, ...) +{ +va_list args; + +va_start (args, fmt); +vprintf (fmt, args); +va_end (args); +} + +void dm_dbg (const char *fmt, ...) +{ +va_list args; + +va_start (args, fmt); +vprintf (fmt, args); +va_end (args); +} + +int list_count_items (struct list_head *head) +{ +struct list_head *node; +int count =0 ; + +list_for_each (node, head) + count++; + +return count; +}
include/asm-generic/global_data.h +8 -0
@@ -21,6 +21,8 @@*/ #ifndef __ASSEMBLY__ +#include <linux/list.h> + typedef struct global_data { bd_t *bd; unsigned long flags;
@@ -61,6 +63,12 @@ typedef struct global_data {unsigned long start_addr_sp;/* start_addr_stackpointer */ unsigned long reloc_off;struct global_data *new_gd;/* relocated global data */ + +#ifdef CONFIG_DM +struct device *dm_root;/* Root instance for Driver Model */ +struct list_head uclass_root;/* Head of core tree */ +#endif +const void *fdt_blob;/* Our device tree, NULL if none */ void *new_fdt;/* Relocated FDT */ unsigned long fdt_size;/* Space reserved for relocated FDT */
include/dm.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _DM_H_ +#define _DM_H + +#include <dm/device.h> +#include <dm/platform_data.h> +#include <dm/uclass.h> + +#endif
include/dm/device-internal.h new file +87 -0
87 lines not on this page · raw message
include/dm/device.h new file +136 -0
136 lines not on this page · raw message
include/dm/lists.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* (C) Copyright 2012 +* Pavel Herrmann <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _DM_LISTS_H_ +#define _DM_LISTS_H_ + +#include <dm/uclass-id.h> + +/** +* lists_driver_lookup_name() - Return u_boot_driver corresponding to name +* +* This function returns a pointer to a driver given its name. This is used +* for binding a driver given its name and platform_data. +* +* @name: Name of driver to look up +* @return pointer to driver, or NULL if not found +*/ +struct driver *lists_driver_lookup_name (const char *name); + +/** +* lists_uclass_lookup() - Return uclass_driver based on ID of the class +* id: ID of the class +* +* This function returns the pointer to uclass_driver, which is the class's +* base structure based on the ID of the class. Returns NULL on error. +*/ +struct uclass_driver *lists_uclass_lookup (enum uclass_id id); + +int lists_bind_drivers (struct device *parent); + +int lists_bind_fdt (struct device *parent,const void *blob,int offset); + +#endif
include/dm/platform_data.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* (C) Copyright 2012 +* Pavel Herrmann <[email protected]> +* Marek Vasut <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _DM_PLATFORM_DATA_H +#define _DM_PLATFORM_DATA_H + +struct driver_info { +const char *name; +const void *platform_data; +}; + +#define U_BOOT_DEVICE (__name) \ + ll_entry_declare(struct driver_info, __name, driver_info) + +#endif
include/dm/root.h new file +53 -0
53 lines not on this page · raw message
include/dm/uclass-id.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* (C) Copyright 2012 +* Pavel Herrmann <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _DM_UCLASS_ID_H +#define _DM_UCLASS_ID_H + +/* TODO(sjg at chromium.org): this could be compile-time generated */ +enum uclass_id { +/* These are used internally by driver model */ +UCLASS_ROOT =0 , +UCLASS_DEMO , +UCLASS_TEST , +UCLASS_TEST_FDT , + +/* U-Boot uclasses start here */ +UCLASS_GPIO , + +UCLASS_COUNT , +UCLASS_INVALID =-1 , +}; + +#endif
include/dm/uclass-internal.h new file +85 -0
85 lines not on this page · raw message
include/dm/uclass.h new file +142 -0
142 lines not on this page · raw message
include/dm/util.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __DM_UTIL_H + +void dm_warn (const char *fmt, ...); + +#ifdef DEBUG +void dm_dbg (const char *fmt, ...); +#else +static inline void dm_dbg (const char *fmt, ...) +{ +} +#endif + +struct list_head ; + +/** +* list_count_items() - Count number of items in a list +* +* @param head: Head of list +* @return number of items, or 0 if empty +*/ +int list_count_items (struct list_head *head); + +#endif
Signature · 1 line
1.8.4
PATCH v5 8/16 sandbox: config: Enable driver model
In reply to Simon GlassUse driver model in sandbox to permit running of driver model unit test.
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
include/configs/sandbox.h | 1 + 1 file changed, 1 insertion(+)
include/configs/sandbox.h +1 -0
@@ -18,6 +18,7 @@#define CONFIG_BOOTSTAGE #define CONFIG_BOOTSTAGE_REPORT +#define CONFIG_DM /* Number of bits in a C 'long' on this architecture */ #define CONFIG_SANDBOX_BITS_PER_LONG 64
Signature · 1 line
1.8.4
PATCH v5 9/16 dm: Set up driver model after relocation
In reply to Simon GlassMake driver model available after relocation, by setting up data structures and scanning for devices using compiled-in platform_data and (when available) the device tree.
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
common/board_r.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
common/board_r.c +33 -0
@@ -18,6 +18,7 @@#ifdef CONFIG_HAS_DATAFLASH #include <dataflash.h> #endif +#include <dm.h> #include <environment.h> #include <fdtdec.h> #if defined(CONFIG_CMD_IDE )
@@ -51,7 +52,9 @@#ifdef CONFIG_X86 #include <asm/init_helpers.h> #endif +#include <dm/root.h> #include <linux/compiler.h> +#include <linux/err.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -263,6 +266,33 @@ static int initr_malloc(void)return 0 ; } +#ifdef CONFIG_DM +static int initr_dm (void ) +{ +int ret; + + ret =dm_init (); +if (ret) { +debug ("dm_init() failed: %d\n" , ret); +return ret; + } + ret =dm_scan_platform_data (); +if (ret) { +debug ("dm_scan_platform_data() failed: %d\n" , ret); +return ret; + } +#ifdef CONFIG_OF_CONTROL + ret =dm_scan_fdt (gd->fdt_blob); +if (ret) { +debug ("dm_scan_fdt() failed: %d\n" , ret); +return ret; + } +#endif + +return 0 ; +} +#endif +__weak int power_init_board (void ) {return 0 ;
@@ -761,6 +791,9 @@ init_fnc_t init_sequence_r[] = { initr_barrier, initr_malloc, bootstage_relocate, +#ifdef CONFIG_DM + initr_dm, +#endif #ifdef CONFIG_ARCH_EARLY_INIT_R arch_early_init_r, #endif
Signature · 1 line
1.8.4
PATCH v5 10/16 dm: Add basic tests
In reply to Simon GlassAdd some tests of driver model functionality. Coverage includes:
- basic init
- binding of drivers to devices using platform_data
- automatic probing of devices when referenced
- availability of platform data to devices
- lifecycle from bind to probe to remove to unbind
- renumbering within a uclass when devices are probed/removed
- calling driver-defined operations
- deactivation of drivers when removed
- memory leak across creation and destruction of drivers/uclasses
- uclass init/destroy methods
- automatic probe/remove of children/parents when needed
This function is enabled for sandbox, using CONFIG_DM_TEST.
---
Changes in v5:
- Change to new SPDX license headers
- Fix style nit on for() loop
Changes in v4:
- Correct 'out.dtb' typo
Changes in v3:
- Add function/struct comments to tests
Changes in v2: None
Makefile | 1 + include/configs/sandbox.h | 1 + include/dm/test.h | 167 ++++++++++++++ include/dm/ut.h | 95 ++++++++ test/dm/Makefile | 39 ++++ test/dm/core.c | 544 ++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-driver.c | 146 +++++++++++++ test/dm/test-fdt.c | 135 ++++++++++++ test/dm/test-main.c | 107 +++++++++ test/dm/test-uclass.c | 104 +++++++++ test/dm/test.dts | 59 +++++ test/dm/ut.c | 33 +++ 12 files changed, 1431 insertions(+) create mode 100644 include/dm/test.h create mode 100644 include/dm/ut.h create mode 100644 test/dm/Makefile create mode 100644 test/dm/core.c create mode 100644 test/dm/test-driver.c create mode 100644 test/dm/test-fdt.c create mode 100644 test/dm/test-main.c create mode 100644 test/dm/test-uclass.c create mode 100644 test/dm/test.dts create mode 100644 test/dm/ut.c
Makefile +1 -0
@@ -324,6 +324,7 @@ LIBS-y += api/libapi.o LIBS-y += post/libpost.o LIBS-y += test/libtest.o LIBS-$(CONFIG_DM) += drivers/core/libdm.o +LIBS-y += test/dm/libtestdm.o ifneq ($(CONFIG_OMAP_COMMON),) LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
include/configs/sandbox.h +1 -0
@@ -19,6 +19,7 @@#define CONFIG_BOOTSTAGE #define CONFIG_BOOTSTAGE_REPORT #define CONFIG_DM +#define CONFIG_DM_TEST /* Number of bits in a C 'long' on this architecture */ #define CONFIG_SANDBOX_BITS_PER_LONG 64
include/dm/test.h new file +167 -0
167 lines not on this page · raw message
include/dm/ut.h new file +95 -0
95 lines not on this page · raw message
test/dm/Makefile new file +39 -0
@@ -0,0 +1,39 @@ +# +# Copyright (c) 2013 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +include $(TOPDIR)/config.mk + +LIB = $(obj)libtestdm.o + +COBJS-$(CONFIG_DM_TEST) += test-driver.o +COBJS-$(CONFIG_DM_TEST) += test-fdt.o +COBJS-$(CONFIG_DM_TEST) += test-main.o +COBJS-$(CONFIG_DM_TEST) += test-uclass.o +COBJS-$(CONFIG_DM_TEST) += ut.o + +# Tests for particular subsystems - when enabling driver model for a new +# subsystem you must add sandbox tests here. +COBJS-$(CONFIG_DM_TEST) += core.o +COBJS-$(CONFIG_DM_TEST) += ut.o +COBJS-$(CONFIG_DM_GPIO) += gpio.o + +COBJS := $(sort $(COBJS-y)) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) $(XOBJS) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +#########################################################################
test/dm/core.c new file +544 -0
544 lines not on this page · raw message
test/dm/test-driver.c new file +146 -0
146 lines not on this page · raw message
test/dm/test-fdt.c new file +135 -0
135 lines not on this page · raw message
test/dm/test-main.c new file +107 -0
107 lines not on this page · raw message
test/dm/test-uclass.c new file +104 -0
104 lines not on this page · raw message
test/dm/test.dts new file +59 -0
59 lines not on this page · raw message
test/dm/ut.c new file +33 -0
@@ -0,0 +1,33 @@ +/* +* Simple unit test library for driver model +* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <dm/test.h> +#include <dm/ut.h> + +struct dm_test_state ; + +void ut_fail (struct dm_test_state *dms,const char *fname,int line, +const char *func,const char *cond) +{ +printf ("%s:%d, %s(): %s\n" , fname, line, func, cond); + dms->fail_count++; +} + +void ut_failf (struct dm_test_state *dms,const char *fname,int line, +const char *func,const char *cond,const char *fmt, ...) +{ +va_list args; + +printf ("%s:%d, %s(): %s: " , fname, line, func, cond); +va_start (args, fmt); +vprintf (fmt, args); +va_end (args); +putc ('\n' ); + dms->fail_count++; +}
Signature · 1 line
1.8.4
PATCH v5 11/16 dm: Add a 'dm' command for testing
In reply to Simon GlassThis command is not required for driver model operation, but can be useful for testing. It provides simple dumps of internal data structures.
---
Changes in v5:
- Change to new SPDX license headers
Changes in v4:
- Change 'dm dump' command to 'dm tree'
Changes in v3: None
Changes in v2: None
include/configs/sandbox.h | 1 + test/dm/Makefile | 1 + test/dm/cmd_dm.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 test/dm/cmd_dm.c
include/configs/sandbox.h +1 -0
@@ -19,6 +19,7 @@#define CONFIG_BOOTSTAGE #define CONFIG_BOOTSTAGE_REPORT #define CONFIG_DM +#define CONFIG_CMD_DM #define CONFIG_DM_TEST /* Number of bits in a C 'long' on this architecture */
test/dm/Makefile +1 -0
@@ -8,6 +8,7 @@ include $(TOPDIR)/config.mk LIB = $(obj)libtestdm.o +COBJS-$(CONFIG_CMD_DM) += cmd_dm.o COBJS-$(CONFIG_DM_TEST) += test-driver.o COBJS-$(CONFIG_DM_TEST) += test-fdt.o COBJS-$(CONFIG_DM_TEST) += test-main.o
test/dm/cmd_dm.c new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
1.8.4
PATCH v5 12/16 dm: Add a demonstration/example driver
In reply to Simon GlassAs an example of how to write a uclass and a driver, provide a demo version of each, accessible through the 'demo' command.
To use these with driver model, define CONFIG_CMD_DEMO and CONFIG_DM_DEMO.
The two demo drivers are enabled with CONFIG_DM_DEMO_SIMPLE and CONFIG_DM_DEMO_SHAPE.
---
Changes in v5:
- Change to new SPDX license headers
Changes in v4:
- Remove duplicated .op line
Changes in v3:
- Fix up demo command help
- Update demo driver to use device tree
Changes in v2: None
Makefile | 1 + common/Makefile | 1 + common/cmd_demo.c | 102 +++++++++++++++++++++++++++++++++++ drivers/demo/Makefile | 31 +++++++++++ drivers/demo/demo-pdata.c | 47 ++++++++++++++++ drivers/demo/demo-shape.c | 130 +++++++++++++++++++++++++++++++++++++++++++++ drivers/demo/demo-simple.c | 47 ++++++++++++++++ drivers/demo/demo-uclass.c | 60 +++++++++++++++++++++ include/configs/sandbox.h | 4 ++ include/dm-demo.h | 36 +++++++++++++ 10 files changed, 459 insertions(+) create mode 100644 common/cmd_demo.c create mode 100644 drivers/demo/Makefile create mode 100644 drivers/demo/demo-pdata.c create mode 100644 drivers/demo/demo-shape.c create mode 100644 drivers/demo/demo-simple.c create mode 100644 drivers/demo/demo-uclass.c create mode 100644 include/dm-demo.h
Makefile +1 -0
@@ -325,6 +325,7 @@ LIBS-y += post/libpost.o LIBS-y += test/libtest.o LIBS-$(CONFIG_DM) += drivers/core/libdm.o LIBS-y += test/dm/libtestdm.o +LIBS-$(CONFIG_DM_DEMO) += drivers/demo/libdemo.o ifneq ($(CONFIG_OMAP_COMMON),) LIBS-y += $(CPUDIR)/omap-common/libomap-common.o
common/Makefile +1 -0
@@ -67,6 +67,7 @@ COBJS-$(CONFIG_CMD_CONSOLE) += cmd_console.o COBJS-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o COBJS-$(CONFIG_DATAFLASH_MMC_SELECT) += cmd_dataflash_mmc_mux.o COBJS-$(CONFIG_CMD_DATE) += cmd_date.o +COBJS-$(CONFIG_CMD_DEMO) += cmd_demo.o COBJS-$(CONFIG_CMD_SOUND) += cmd_sound.o ifdef CONFIG_4xx COBJS-$(CONFIG_CMD_SETGETDCR) += cmd_dcr.o
common/cmd_demo.c new file +102 -0
102 lines not on this page · raw message
drivers/demo/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +# +# Copyright (c) 2013 Google, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +include $(TOPDIR)/config.mk + +LIB := $(obj)libdemo.o + +COBJS-$(CONFIG_DM_DEMO) += demo-uclass.o demo-pdata.o +COBJS-$(CONFIG_DM_DEMO_SIMPLE) += demo-simple.o +COBJS-$(CONFIG_DM_DEMO_SHAPE) += demo-shape.o + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(call cmd_link_o_target, $(OBJS)) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +#########################################################################
drivers/demo/demo-pdata.c new file +47 -0
47 lines not on this page · raw message
drivers/demo/demo-shape.c new file +130 -0
130 lines not on this page · raw message
drivers/demo/demo-simple.c new file +47 -0
47 lines not on this page · raw message
drivers/demo/demo-uclass.c new file +60 -0
60 lines not on this page · raw message
include/configs/sandbox.h +4 -0
@@ -19,7 +19,11 @@#define CONFIG_BOOTSTAGE #define CONFIG_BOOTSTAGE_REPORT #define CONFIG_DM +#define CONFIG_CMD_DEMO #define CONFIG_CMD_DM +#define CONFIG_DM_DEMO +#define CONFIG_DM_DEMO_SIMPLE +#define CONFIG_DM_DEMO_SHAPE #define CONFIG_DM_TEST /* Number of bits in a C 'long' on this architecture */
include/dm-demo.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (c) 2013 Google, Inc +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __DM_DEMO_H +#define __DM_DEMO_H + +#include <dm.h> + +/** +* struct dm_demo_pdata - configuration data for demo instance +* +* @colour: Color of the demo +* @sides: Numbers of sides +* @default_char: Default ASCII character to output (65 = 'A') +*/ +struct dm_demo_pdata { +const char *colour; +int sides; +int default_char; +}; + +struct demo_ops { +int (*hello)(struct device *dev,int ch); +int (*status)(struct device *dev,int *status); +}; + +int demo_hello (struct device *dev,int ch); +int demo_status (struct device *dev,int *status); +int demo_list (void ); + +int demo_parse_dt (struct device *dev); + +#endif
Signature · 1 line
1.8.4
PATCH v5 13/16 dm: Add GPIO support and tests
In reply to Simon GlassAdd driver model support for GPIOs. Since existing GPIO drivers do not use driver model, this feature must be enabled by CONFIG_DM_GPIO. After all GPO drivers are converted over we can perhaps remove this config.
Tests are provided for the sandbox implementation, and are a sufficient sanity check for basic operation.
The GPIO uclass understands the concept of named banks of GPIOs, with each GPIO device providing a single bank. Within each bank the GPIOs are numbered using an offset from 0 to n-1. For example a bank named 'b' with 20 offsets will provide GPIOs named b0 to b19.
Anonymous GPIO banks are also supported, and are just numbered without any prefix.
Each time a GPIO driver is added to the uclass, the GPIOs are renumbered accordinging, so there is always a global GPIO numbering order.
---
Changes in v5:
- Change to new SPDX license headers
Changes in v4: None
Changes in v3:
- Update GPIO support to use new struct member names
- Tidy up comments/documentation in GPIO module
Changes in v2: None
drivers/gpio/Makefile | 2 + drivers/gpio/gpio-uclass.c | 266 +++++++++++++++++++++++++++++++++++++++++++++ include/asm-generic/gpio.h | 104 ++++++++++++++++++ test/dm/gpio.c | 111 +++++++++++++++++++ 4 files changed, 483 insertions(+) create mode 100644 drivers/gpio/gpio-uclass.c create mode 100644 test/dm/gpio.c
drivers/gpio/Makefile +2 -0
@@ -9,6 +9,8 @@ include $(TOPDIR)/config.mk LIB := $(obj)libgpio.o +COBJS-$(CONFIG_DM_GPIO) += gpio-uclass.o + COBJS-$(CONFIG_AT91_GPIO) += at91_gpio.o COBJS-$(CONFIG_INTEL_ICH6_GPIO) += intel_ich6_gpio.o COBJS-$(CONFIG_KIRKWOOD_GPIO) += kw_gpio.o
drivers/gpio/gpio-uclass.c new file +266 -0
266 lines not on this page · raw message
include/asm-generic/gpio.h +104 -0
108 lines not on this page · raw message
test/dm/gpio.c new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
1.8.4
PATCH v5 14/16 sandbox: Convert GPIOs to use driver model
In reply to Simon GlassConvert sandbox over to use driver model GPIOs.
---
Changes in v5: None
Changes in v4: None
Changes in v3:
- Update sandbox GPIO header file comments
Changes in v2: None
arch/sandbox/include/asm/gpio.h | 14 +-- board/sandbox/sandbox/sandbox.c | 7 +- drivers/gpio/sandbox.c | 210 +++++++++++++++++++++++++--------------- include/configs/sandbox.h | 1 + 4 files changed, 144 insertions(+), 88 deletions(-)
arch/sandbox/include/asm/gpio.h +5 -9
@@ -29,7 +29,7 @@* @param gp GPIO number * @return -1 on error, 0 if GPIO is low, >0 if high */ -int sandbox_gpio_get_value (unsigned gp); +int sandbox_gpio_get_value (struct device *dev,unsigned int offset);/** * Set the simulated value of a GPIO (used only in sandbox test code)
@@ -38,7 +38,7 @@ int sandbox_gpio_get_value(unsigned gp);* @param value value to set (0 for low, non-zero for high) * @return -1 on error, 0 if ok */ -int sandbox_gpio_set_value (unsigned gp,int value); +int sandbox_gpio_set_value (struct device *dev,unsigned int offset,int value);/** * Return the simulated direction of a GPIO (used only in sandbox test code)
@@ -46,7 +46,7 @@ int sandbox_gpio_set_value(unsigned gp, int value);* @param gp GPIO number * @return -1 on error, 0 if GPIO is input, >0 if output */ -int sandbox_gpio_get_direction (unsigned gp); +int sandbox_gpio_get_direction (struct device *dev,unsigned int offset);/** * Set the simulated direction of a GPIO (used only in sandbox test code)
@@ -55,11 +55,7 @@ int sandbox_gpio_get_direction(unsigned gp);* @param output 0 to set as input, 1 to set as output * @return -1 on error, 0 if ok */ -int sandbox_gpio_set_direction (unsigned gp,int output); - -/* Display information about each GPIO */ -void gpio_info (void ); - -#define gpio_status () gpio_info() +int sandbox_gpio_set_direction (struct device *dev,unsigned int offset, +int output);#endif
board/sandbox/sandbox/sandbox.c +6 -1
@@ -4,7 +4,7 @@*/ #include <common.h> - +#include <dm.h> #include <os.h> /*
@@ -14,6 +14,11 @@*/ gd_t *gd; +/* Add a simple GPIO device */ +U_BOOT_DEVICE (gpio_sandbox) = { + .name ="gpio_sandbox" , +}; +void flush_cache (unsigned long start,unsigned long size) { }
drivers/gpio/sandbox.c +132 -78
311 lines not on this page · raw message
include/configs/sandbox.h +1 -0
@@ -24,6 +24,7 @@#define CONFIG_DM_DEMO #define CONFIG_DM_DEMO_SIMPLE #define CONFIG_DM_DEMO_SHAPE +#define CONFIG_DM_GPIO #define CONFIG_DM_TEST /* Number of bits in a C 'long' on this architecture */
Signature · 1 line
1.8.4
PATCH v5 15/16 dm: Enable gpio command to support driver model
In reply to Simon GlassNow that named GPIO banks are supported, along with a way of obtaining the status of a GPIO (input or output), we can provide an enhanced GPIO command for driver model. Where the driver provides its own operation for obtaining the GPIO state, this is used, otherwise a generic version is sufficient.
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
common/cmd_gpio.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 114 insertions(+), 13 deletions(-)
common/cmd_gpio.c +114 -13
@@ -8,7 +8,7 @@#include <common.h> #include <command.h> - +#include <dm.h> #include <asm/gpio.h> #ifndef name_to_gpio
@@ -22,25 +22,115 @@ enum gpio_cmd { GPIO_TOGGLE, }; +#if defined(CONFIG_DM_GPIO ) && !defined(gpio_status) +static const char *const gpio_function[] = { +"input" , +"output" , +"unknown" , +}; + +static void show_gpio (struct device *dev,const char *bank_name,int offset) +{ +struct dm_gpio_ops *ops =gpio_get_ops (dev); +char buf[80 ]; +int ret; + + *buf ='\0' ; +if (ops->get_state) { + ret = ops->get_state (dev, offset, buf,sizeof (buf)); +if (ret) { +puts ("<unknown>" ); +return ; + } + }else { +int func =GPIOF_UNKNOWN ; +int ret; + +if (ops->get_function) { + ret = ops->get_function (dev, offset); +if (ret >=0 && ret <ARRAY_SIZE (gpio_function)) + func = ret; + } +sprintf (buf,"%s%u: %8s %d" , bank_name, offset, + gpio_function[func], ops->get_value (dev, offset)); + } + +puts (buf); +puts ("\n" ); +} + +static int do_gpio_status (const char *gpio_name) +{ +struct device *dev; +int newline =0 ; +int ret; + +if (gpio_name && !*gpio_name) + gpio_name =NULL ; +for (ret =uclass_first_device (UCLASS_GPIO , &dev); + dev; + ret =uclass_next_device (&dev)) { +const char *bank_name; +int num_bits; + + bank_name =gpio_get_bank_info (dev, &num_bits); + +if (!gpio_name || !bank_name || + !strncmp (gpio_name, bank_name,strlen (bank_name))) { +const char *p =NULL ; +int offset; + +if (bank_name) { +if (newline) +putc ('\n' ); +printf ("Bank %s:\n" , bank_name); + } + newline =1 ; +if (gpio_name && bank_name) { + p = gpio_name +strlen (bank_name); + offset =simple_strtoul (p,NULL ,10 ); +show_gpio (dev, bank_name, offset); + }else { +for (offset =0 ; offset < num_bits; offset++) +show_gpio (dev, bank_name, offset); + } + } + } + +return ret; +} +#endif +static int do_gpio (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { -int gpio; +unsigned int gpio;enum gpio_cmd sub_cmd;ulong value; -const char *str_cmd, *str_gpio; +const char *str_cmd, *str_gpio =NULL ; +#ifdef CONFIG_DM_GPIO +int ret; +#endif +if (argc <2 ) + show_usage: +return CMD_RET_USAGE ; + str_cmd = argv[1 ]; +if (argc >2 ) + str_gpio = argv[2 ]; +if (!strcmp (str_cmd,"status" )) { +/* Support deprecated gpio_status() */ #ifdef gpio_status -if (argc ==2 && !strcmp (argv[1 ],"status" )) {gpio_status ();return 0 ; - } +#elif defined(CONFIG_DM_GPIO ) +return cmd_process_error (cmdtp,do_gpio_status (str_gpio)); +#else + goto show_usage;#endif + } -if (argc !=3 ) - show_usage: -return CMD_RET_USAGE ; - str_cmd = argv[1 ]; - str_gpio = argv[2 ]; +if (!str_gpio) + goto show_usage;/* parse the behavior */ switch (*str_cmd) {
@@ -51,11 +141,21 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])default : goto show_usage; } +#if defined(CONFIG_DM_GPIO ) +/* +* TODO(sjg at chromium.org): Convert this code over to use the GPIO +* uclass interface instead of the numbered GPIO compatibility +* layer. +*/ + ret =gpio_lookup_name (str_gpio,NULL ,NULL , &gpio); +if (ret) +return cmd_process_error (cmdtp, ret); +#else /* turn the gpio name into a gpio number */ gpio =name_to_gpio (str_gpio);if (gpio <0 ) goto show_usage; - +#endif /* grab the pin before we tweak it */ if (gpio_request (gpio,"cmd_gpio" )) {printf ("gpio: requesting pin %u failed\n" , gpio);
@@ -84,6 +184,7 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }U_BOOT_CMD (gpio,3 ,0 , do_gpio, -"input/set/clear/toggle gpio pins" , +"query and control gpio pins" ,"<input|set|clear|toggle> <pin>\n" -" - input/set/clear/toggle the specified pin" ); +" - input/set/clear/toggle the specified pin\n" +"gpio status [<bank> | <pin>]" );
Signature · 1 line
1.8.4
PATCH v5 16/16 dm: Remove old driver model documentation
In reply to Simon GlassThis documentation pertains to the planned implementation of driver model in U-Boot for each subsystem, but it has not been superseded. It is probably better to have this documentation in the source code for each subsystem where possible, so that docbook will pick it up. Where this does not make sense, new documentation can be placed in some suitable file in doc/driver-model.
---
Changes in v5:
- Adjust patch to completely remove old driver model documentation
Changes in v4: None
Changes in v3:
- Add new patch to move driver model documentation
Changes in v2: None
doc/driver-model/UDM-block.txt | 278 ------------------------ doc/driver-model/UDM-cores.txt | 126 ----------- doc/driver-model/UDM-design.txt | 315 --------------------------- doc/driver-model/UDM-fpga.txt | 115 ---------- doc/driver-model/UDM-gpio.txt | 106 ---------- doc/driver-model/UDM-hwmon.txt | 118 ----------- doc/driver-model/UDM-keyboard.txt | 47 ----- doc/driver-model/UDM-mmc.txt | 319 ---------------------------- doc/driver-model/UDM-net.txt | 434 -------------------------------------- doc/driver-model/UDM-pci.txt | 257 ---------------------- doc/driver-model/UDM-pcmcia.txt | 78 ------- doc/driver-model/UDM-power.txt | 88 -------- doc/driver-model/UDM-rtc.txt | 253 ---------------------- doc/driver-model/UDM-serial.txt | 175 --------------- doc/driver-model/UDM-spi.txt | 200 ------------------ doc/driver-model/UDM-stdio.txt | 191 ----------------- doc/driver-model/UDM-tpm.txt | 48 ----- doc/driver-model/UDM-twserial.txt | 47 ----- doc/driver-model/UDM-usb.txt | 94 --------- doc/driver-model/UDM-video.txt | 74 ------- doc/driver-model/UDM-watchdog.txt | 329 ----------------------------- 21 files changed, 3692 deletions(-) delete mode 100644 doc/driver-model/UDM-block.txt delete mode 100644 doc/driver-model/UDM-cores.txt delete mode 100644 doc/driver-model/UDM-design.txt delete mode 100644 doc/driver-model/UDM-fpga.txt delete mode 100644 doc/driver-model/UDM-gpio.txt delete mode 100644 doc/driver-model/UDM-hwmon.txt delete mode 100644 doc/driver-model/UDM-keyboard.txt delete mode 100644 doc/driver-model/UDM-mmc.txt delete mode 100644 doc/driver-model/UDM-net.txt delete mode 100644 doc/driver-model/UDM-pci.txt delete mode 100644 doc/driver-model/UDM-pcmcia.txt delete mode 100644 doc/driver-model/UDM-power.txt delete mode 100644 doc/driver-model/UDM-rtc.txt delete mode 100644 doc/driver-model/UDM-serial.txt delete mode 100644 doc/driver-model/UDM-spi.txt delete mode 100644 doc/driver-model/UDM-stdio.txt delete mode 100644 doc/driver-model/UDM-tpm.txt delete mode 100644 doc/driver-model/UDM-twserial.txt delete mode 100644 doc/driver-model/UDM-usb.txt delete mode 100644 doc/driver-model/UDM-video.txt delete mode 100644 doc/driver-model/UDM-watchdog.txt
doc/driver-model/UDM-block.txt deleted +0 -278
@@ -1,278 +0,0 @@ -The U-Boot Driver Model Project -=============================== -Block device subsystem analysis -=============================== - -Pavel Herrmann <[email protected]> -2012-03-08 - -I) Overview ------------ - - U-Boot currently implements several distinct APIs for block devices - some - drivers use the SATA API, some drivers use the IDE API, sym53c8xx and - AHCI use the SCSI API, mg_disk has a separate API, and systemace also has a - separate API. There are also MMC and USB APIs used outside of drivers/block, - those will be detailed in their specific documents. - - Block devices are described by block_dev_desc structure, that holds, among - other things, the read/write/erase callbacks. Block device structures are - stored in any way depending on the API, but can be accessed by - - block_dev_desc_t * $api_get_dev(int dev) - - function, as seen in disk/part.c. - - 1) SATA interface - ----------------- - - The SATA interface drivers implement the following functions: - - int init_sata(int dev) - int scan_sata(int dev) - ulong sata_read(int dev, ulong blknr, ulong blkcnt, void *buffer) - ulong sata_write(int dev, ulong blknr, ulong blkcnt, const void *buffer) - - Block devices are kept in sata_dev_desc[], which is prefilled with values - common to all SATA devices in cmd_sata.c, and then modified in init_sata - function in the drivers. Callbacks of the block device use SATA API - directly. The sata_get_dev function is defined in cmd_sata.c. - - 2) SCSI interface - ----------------- - - The SCSI interface drivers implement the following functions: - - void scsi_print_error(ccb *pccb) - int scsi_exec(ccb *pccb) - void scsi_bus_reset(void) - void scsi_low_level_init(int busdevfunc) - - The SCSI API works through the scsi_exec function, the actual operation - requested is found in the ccb structure. - - Block devices are kept in scsi_dev_desc[], which lives only in cmd_scsi.c. - Callbacks of the block device use functions from cmd_scsi.c, which in turn - call scsi_exec of the controller. The scsi_get_dev function is also defined - in cmd_scsi.c. - - 3) mg_disk interface - -------------------- - - The mg_disk interface drivers implement the following functions: - - struct mg_drv_data* mg_get_drv_data (void) - uint mg_disk_init (void) - uint mg_disk_read (u32 addr, u8 *buff, u32 len) - uint mg_disk_write(u32 addr, u8 *buff, u32 len) - uint mg_disk_write_sects(void *buff, u32 sect_num, u32 sect_cnt) - uint mg_disk_read_sects(void *buff, u32 sect_num, u32 sect_cnt) - - The mg_get_drv_data function is to be overridden per-board, but there are no - board in-tree that do this. - - Only one driver for this API exists, and it only supports one block device. - Callbacks for this device are implemented in mg_disk.c and call the mg_disk - API. The mg_disk_get_dev function is defined in mg_disk.c and ignores the - device number, always returning the same device. - - 4) systemace interface - ---------------------- - - The systemace interface does not define any driver API, and has no command - itself. The single defined function is systemace_get_devs() from - systemace.c, which returns a single static structure for the only supported - block device. Callbacks for this device are also implemented in systemace.c. - - 5) IDE interface - ---------------- - - The IDE interface drivers implement the following functions, but only if - CONFIG_IDE_AHB is set: - - uchar ide_read_register(int dev, unsigned int port); - void ide_write_register(int dev, unsigned int port, unsigned char val); - void ide_read_data(int dev, ulong *sect_buf, int words); - void ide_write_data(int dev, const ulong *sect_buf, int words); - - The first two functions are called from ide_inb()/ide_outb(), and will - default to direct memory access if CONFIG_IDE_AHB is not set, or - ide_inb()/ide_outb() functions will get overridden by the board altogether. - - The second two functions are called from input_data()/output_data() - functions, and also default to direct memory access, but cannot be - overridden by the board. - - One function shared by IDE drivers (but not defined in ide.h) is - int ide_preinit(void) - This function gets called from ide_init in cmd_ide.c if CONFIG_IDE_PREINIT - is defined, and will do the driver-specific initialization of the device. - - Block devices are kept in ide_dev_desc[], which is filled in cmd_ide.c. - Callbacks of the block device are defined in cmd_ide.c, and use the - ide_inb()/ide_outb()/input_data()/output_data() functions mentioned above. - The ide_get_dev function is defined in cmd_ide.c. - -II) Approach ------------- - - A new block controller core and an associated API will be created to mimic the - current SATA API, its drivers will have the following ops: - - struct block_ctrl_ops { - int scan(instance *i); - int reset(instance *i, int port); - lbaint_t read(instance *i, int port, lbaint_t start, lbatin_t length, - void *buffer); - lbaint_t write(instance *i, int port, lbaint_t start, lbatin_t length, - void*buffer); - } - - The current sata_init() function will be changed into the driver probe() - function. The read() and write() functions should never be called directly, - instead they should be called by block device driver for disks. - - Other block APIs would either be transformed into this API, or be kept as - legacy for old drivers, or be dropped altogether. - - Legacy driver APIs will each have its own driver core that will contain the - shared logic, which is currently located mostly in cmd_* files. Callbacks for - block device drivers will then probably be implemented as a part of the core - logic, and will use the driver ops (which will copy current state of - respective APIs) to do the work. - - All drivers will be cleaned up, most ifdefs should be converted into - platform_data, to enable support for multiple devices with different settings. - - A new block device core will also be created, and will keep track of all - block devices on all interfaces. - - Current block_dev_desc structure will be changed to fit the driver model, all - identification and configuration will be placed in private data, and - a single accessor and modifier will be defined, to accommodate the need for - different sets of options for different interfaces, while keeping the - structure small. The new block device drivers will have the following ops - structure (lbaint_t is either 32bit or 64bit unsigned, depending on - CONFIG_LBA48): - - struct blockdev_ops { - lbaint_t (*block_read)(struct instance *i, lbaint_t start, lbaint_t blkcnt, - void *buffer); - lbaint_t (*block_write)(struct instance *i, lbaint_t start, lbaint_t blkcnt, - void *buffer); - lbaint_t (*block_erase)(struct instance *i, lbaint_t start, lbaint_t blkcnt - ); - int (*get_option)(struct instance *i, enum blockdev_option_code op, - struct option *res); - int (*set_option)(struct instance *i, enum blockdev_option_code op, - struct option *val); - } - - struct option { - uint32_t flags - union data { - uint64_t data_u; - char* data_s; - void* data_p; - } - } - - enum blockdev_option_code { - BLKD_OPT_IFTYPE=0, - BLKD_OPT_TYPE, - BLKD_OPT_BLOCKSIZE, - BLKD_OPT_BLOCKCOUNT, - BLKD_OPT_REMOVABLE, - BLKD_OPT_LBA48, - BLKD_OPT_VENDOR, - BLKD_OPT_PRODICT, - BLKD_OPT_REVISION, - BLKD_OPT_SCSILUN, - BLKD_OPT_SCSITARGET, - BLKD_OPT_OFFSET - } - - Flags in option above will contain the type of returned data (which should be - checked against what is expected, even though the option requested should - specify it), and a flag to indicate whether the returned pointer needs to be - free()'d. - - The block device core will contain the logic now located in disk/part.c and - related files, and will be used to forward requests to block devices. The API - for the block device core will copy the ops of a block device (with a string - identifier instead of instance pointer). This means that partitions will also - be handled by the block device core, and exported as block devices, making - them transparent to the rest of the code. - - Sadly, this will change how file systems can access the devices, and thus will - affect a lot of places. However, these changes should be localized and easy to - implement. - - AHCI driver will be rewritten to fit the new unified block controller API, - making SCSI API easy to merge with sym53c8xx, or remove it once the device - driver has died. - - Optionally, IDE core may be changed into one driver with unified block - controller API, as most of it is already in one place and device drivers are - just sets of hooks. Additionally, mg_disk driver is unused and may be removed - in near future. - - -III) Analysis of in-tree drivers --------------------------------- - - 1) ahci.c - --------- - SCSI API, will be rewritten for a different API. - - 2) ata_piix.c - ------------- - SATA API, easy to port. - - 3) fsl_sata.c - ------------- - SATA API, few CONFIG macros, easy to port. - - 4) ftide020.c - ------------- - IDE API, defines CONFIG_IDE_AHB and ide_preinit hook functions. - - 5) mg_disk.c - ------------ - Single driver with mg_disk API, not much to change, easy to port. - - 6) mvsata_ide.c - --------------- - IDE API, only defines ide_preinit hook function. - - 7) mxc_ata.c - ------------ - IDE API, only defines ide_preinit hook function. - - 8) pata_bfin.c - -------------- - SATA API, easy to port. - - 9) sata_dwc.c - ------------- - SATA API, easy to port. - - 10) sata_sil3114.c - ------------------ - SATA API, easy to port. - - 11) sata_sil.c - -------------- - SATA API, easy to port. - - 12) sil680.c - ------------ - IDE API, only defines ide_preinit hook function. - - 13) sym53c8xx.c - --------------- - SCSI API, may be merged with code from cmd_scsi. - - 14) systemace.c - --------------- - Single driver with systemace API, not much to change, easy to port.
doc/driver-model/UDM-cores.txt deleted +0 -126
126 lines not on this page · raw message
doc/driver-model/UDM-design.txt deleted +0 -315
315 lines not on this page · raw message
doc/driver-model/UDM-fpga.txt deleted +0 -115
115 lines not on this page · raw message
doc/driver-model/UDM-gpio.txt deleted +0 -106
106 lines not on this page · raw message
doc/driver-model/UDM-hwmon.txt deleted +0 -118
118 lines not on this page · raw message
doc/driver-model/UDM-keyboard.txt deleted +0 -47
47 lines not on this page · raw message
doc/driver-model/UDM-mmc.txt deleted +0 -319
319 lines not on this page · raw message
doc/driver-model/UDM-net.txt deleted +0 -434
434 lines not on this page · raw message
doc/driver-model/UDM-pci.txt deleted +0 -257
257 lines not on this page · raw message
doc/driver-model/UDM-pcmcia.txt deleted +0 -78
78 lines not on this page · raw message
doc/driver-model/UDM-power.txt deleted +0 -88
88 lines not on this page · raw message
doc/driver-model/UDM-rtc.txt deleted +0 -253
253 lines not on this page · raw message
doc/driver-model/UDM-serial.txt deleted +0 -175
175 lines not on this page · raw message
doc/driver-model/UDM-spi.txt deleted +0 -200
200 lines not on this page · raw message
doc/driver-model/UDM-stdio.txt deleted +0 -191
91 lines not on this page · raw message
doc/driver-model/UDM-tpm.txt deleted +0 -48
48 lines not on this page · raw message
doc/driver-model/UDM-twserial.txt deleted +0 -47
47 lines not on this page · raw message
doc/driver-model/UDM-usb.txt deleted +0 -94
94 lines not on this page · raw message
doc/driver-model/UDM-video.txt deleted +0 -74
74 lines not on this page · raw message
doc/driver-model/UDM-watchdog.txt deleted +0 -329
329 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.4
Part of the diff is not shown here. View the raw message.