Skip to contentSkip to conversation

Driver model implementation, tests, demo and GPIO

PATCH Superseded Simon Glass 6 participants 24 messages Nov 28, 2013 – Dec 4, 2013

Subsystems (3)

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

This series 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. The old driver model documentation is removed.

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.

There is also a presentation on driver model at this page:

http://www.denx.de/wiki/U-Boot/MiniSummitELCE2013

You can find a test version of the code used here in branch dm7 at:

http://git.denx.de/u-boot-x86.git

(Branch dm contains the original implementation)

Changes in v7:
- Fix typo in README
- Rebase to master
- Update Makefile libraries to specify only the directory
- Update cover letter to point to ELCE 2013 presentation, etc.

Changes in v6:
- Add a test script for driver model
- Add dev_get_platdata to access devices's platdata
- Add dev_get_priv() to access device's private data
- Add ofdata_to_pdata method to convert device tree data to platdata
- Convert Makefiles to new Kconfig format
- Rename platform_data to platdata
- Revise and update README
- Use ofdata_to_platdata feature
- Use ofdata_to_platdata method to convert device tree data to platdata

Changes in v5:
- Adjust patch to completely remove old driver model documentation
- Change to new SPDX license headers
- Correct >80col line missed last time
- Fix style nit on for() loop

Changes in v4:
- Change 'dm dump' command to 'dm tree'
- Correct 'out.dtb' typo
- Move common/dm to drivers/core
- Remove duplicated .op line
- device_chld_unbind() continues on error

Changes in v3:
- Add a flag for tracking whether DM allocates/frees platform_data
- Add function/struct comments to tests
- Add new patch to build a device tree file for sandbox
- Add new patch to move driver model documentation
- Fix up demo command help
- Rename per_device_priv_size to per_device_auto_alloc_size, etc.
- Tidy up commenting of functions and structures
- Tidy up comments/documentation in GPIO module
- Update GPIO support to use new struct member names
- Update demo driver to use device tree
- Update sandbox GPIO header file comments
- Updated README.txt to cover changes since version 2

Changes in v2:
- Add GPIO uclass and tests
- Add U_BOOT_DEVICE to declare platform_data
- Add a single include/dm.h to bring in driver model code
- Add auto-probing feature for platform_data to avoid driver_bind() calls
- Add automatic allocation of device-specific priv data for uclasses
- Add automatic allocation of platform_data for FDT
- Add automatic allocation of priv data for devices
- Add device tree support in driver model
- Add dm_warn() to warn about impending doom
- Add integration tests for driver model
- Add new header file for lists
- Add new util file to hold utility functions
- Add sandbox GPIO driver
- Add script to run tests
- Add simple unit test functions
- Add test infrastructure for driver model
- Add tests for core code
- Allow a driver to bind to only one uclass
- Allow driver_bind() to support a NULL parent
- Put platform_data definitions in their own header file
- Remove relocation functions
- Remove unneeded arguments to uclass_bind(), uclass_unbind()
- Removed pointer return values in favour of integer
- Rename data structures to hopefully be clearer
- Rename struct device's 'bus' to 'parent'
- Standardise variable names (e.g. uclass instead of class)
- Update gpio command to use driver model
- Use driver_bind() in dm_init() instead of writing new code

Simon Glass (13):
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 +-
 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       | 368 ++++++++++++++++++++++++++
 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      | 428 ------------------------------
 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   | 159 -----------
 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             |   7 +
 drivers/core/device.c             | 348 ++++++++++++++++++++++++
 drivers/core/lists.c              | 155 +++++++++++
 drivers/core/root.c               | 102 +++++++
 drivers/core/uclass.c             | 285 ++++++++++++++++++++
 drivers/core/util.c               |  37 +++
 drivers/demo/Makefile             |   9 +
 drivers/demo/demo-pdata.c         |  47 ++++
 drivers/demo/demo-shape.c         | 127 +++++++++
 drivers/demo/demo-simple.c        |  47 ++++
 drivers/demo/demo-uclass.c        |  58 ++++
 drivers/gpio/Makefile             |   2 +
 drivers/gpio/gpio-uclass.c        | 266 +++++++++++++++++++
 drivers/gpio/sandbox.c            | 217 +++++++++------
 include/asm-generic/global_data.h |   8 +
 include/asm-generic/gpio.h        | 104 ++++++++
 include/command.h                 |   9 +
 include/configs/sandbox.h         |   9 +
 include/dm-demo.h                 |  36 +++
 include/dm.h                      |  14 +
 include/dm/device-internal.h      |  87 ++++++
 include/dm/device.h               | 159 +++++++++++
 include/dm/lists.h                |  39 +++
 include/dm/platdata.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 ++
 test/dm/.gitignore                |   1 +
 test/dm/Makefile                  |  18 ++
 test/dm/cmd_dm.c                  | 133 ++++++++++
 test/dm/core.c                    | 544 ++++++++++++++++++++++++++++++++++++++
 test/dm/gpio.c                    | 111 ++++++++
 test/dm/test-dm.sh                |   7 +
 test/dm/test-driver.c             | 146 ++++++++++
 test/dm/test-fdt.c                | 144 ++++++++++
 test/dm/test-main.c               | 107 ++++++++
 test/dm/test-uclass.c             | 104 ++++++++
 test/dm/test.dts                  |  59 +++++
 test/dm/ut.c                      |  33 +++
 75 files changed, 4787 insertions(+), 3771 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/platdata.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/.gitignore
 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 100755 test/dm/test-dm.sh
 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.1
#1 lore raw

PATCH v7 1/13 sandbox: Build a device tree file for sandbox

Add 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 v7: None
Changes in v6: None
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
index a2fb037..bd4ea1f 100644
@@ -343,6 +343,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
index 6142dd4..60b7262 100644
@@ -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
new file mode 100644
index 0000000..96a4438
@@ -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
index a4edc62..8eee781 100644
@@ -32,6 +32,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.1
#2 lore raw

PATCH v7 2/13 Add cmd_process_error() to report and process errors

In reply to Simon Glass

U-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 v7: None
Changes in v6: None
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
index 625571d..668aa8b 100644
@@ -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
index f782779..d3f700f 100644
@@ -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.1
#3 lore raw

PATCH v7 3/13 dm: Add README for driver model

In reply to Simon Glass

This adds a README to help with understanding of this series.

---

Changes in v7:
- Fix typo in README
- Rebase to master
- Update cover letter to point to ELCE 2013 presentation, etc.

Changes in v6:
- Rename platform_data to platdata
- Revise and update README

Changes in v5: None
Changes in v4: None
Changes in v3:
- Updated README.txt to cover changes since version 2

Changes in v2:
- Add GPIO uclass and tests
- Add U_BOOT_DEVICE to declare platform_data
- Add a single include/dm.h to bring in driver model code
- Add auto-probing feature for platform_data to avoid driver_bind() calls
- Add automatic allocation of device-specific priv data for uclasses
- Add automatic allocation of platform_data for FDT
- Add automatic allocation of priv data for devices
- Add device tree support in driver model
- Add dm_warn() to warn about impending doom
- Add integration tests for driver model
- Add new header file for lists
- Add new util file to hold utility functions
- Add sandbox GPIO driver
- Add script to run tests
- Add simple unit test functions
- Add test infrastructure for driver model
- Add tests for core code
- Allow a driver to bind to only one uclass
- Allow driver_bind() to support a NULL parent
- Put platform_data definitions in their own header file
- Remove relocation functions
- Remove unneeded arguments to uclass_bind(), uclass_unbind()
- Removed pointer return values in favour of integer
- Rename data structures to hopefully be clearer
- Rename struct device's 'bus' to 'parent'
- Standardise variable names (e.g. uclass instead of class)
- Update gpio command to use driver model
- Use driver_bind() in dm_init() instead of writing new code

 doc/driver-model/README.txt | 368 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 368 insertions(+)
 create mode 100644 doc/driver-model/README.txt
doc/driver-model/README.txt new file +368 -0
new file mode 100644
index 0000000..6fab272
@@ -0,0 +1,368 @@
+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 devices 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 good code coverage of them. It does have multiple drivers, it
+handles parameter data and platdata (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
+
+You should see something like this:
+
+    <...U-Boot banner...>
+    Running 12 driver model tests
+    Test: dm_test_autobind
+    Test: dm_test_autoprobe
+    Test: dm_test_children
+    Test: dm_test_fdt
+    Test: dm_test_gpio
+    sandbox_gpio: sb_gpio_get_value: error: offset 4 not reserved
+    Test: dm_test_leak
+    Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c
+    Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c
+    Test: dm_test_lifecycle
+    Test: dm_test_operations
+    Test: dm_test_ordering
+    Test: dm_test_platdata
+    Test: dm_test_remove
+    Test: dm_test_uclass
+    Failures: 0
+
+(You can add '#define DEBUG' as suggested to check for memory leaks)
+
+
+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, devnum, &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 a device for the demo uclass. Given a device
+number we can find the device because all devices have registered with
+the UCLASS_DEMO uclass.
+
+The device is automatically activated ready for use by uclass_get_device().
+
+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_get_platdata(dev);
+
+	printf("Hello from %08x: %s %d\n", map_to_sysmem(dev),
+	       pdata->colour, pdata->sides);
+
+	return 0;
+}
+
+
+So that is a trip from top (command execution) to bottom (driver action)
+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_get_priv(dev) 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 bind
+and unbind, 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.
+
+The methods a device can provide are documented in the device.h header.
+Briefly, they are:
+
+    bind - make the driver model aware of a device (bind it to its driver)
+    unbind - make the driver model forget the device
+    ofdata_to_platdata - convert device tree data to platdata - see later
+    probe - make a device ready for use
+    remove - remove a device so it cannot be used until probed again
+
+The sequence to get a device to work is bind, ofdata_to_platdata (if using
+device tree) and probe.
+
+
+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->platdata. 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",
+			.platdata = &red_square,
+		},
+	};
+
+	demo1 = driver_bind(root, &info[0]);
+
+
+Device Tree
+-----------
+
+While platdata 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 tree fragment:
+
+	red-square {
+		compatible = "demo-shape";
+		colour = "red";
+		sides = <4>;
+	};
+
+
+The easiest way to make this work it to add a few members to the driver:
+
+	.platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
+	.ofdata_to_platdata = testfdt_ofdata_to_platdata,
+	.probe	= testfdt_drv_probe,
+
+The 'auto_alloc' feature allowed space for the platdata to be allocated
+and zeroed before the driver's ofdata_to_platdata method is called. This
+method reads the information out of the device tree and puts it in
+dev->platdata. Then the probe method is called to set up the device.
+
+Note that both methods are optional. If you provide an ofdata_to_platdata
+method then it wlil be called first (after bind). If you provide a probe
+method it will be called next.
+
+If you don't want to have the platdata automatically allocated then you
+can leave out platdata_auto_alloc_size. In this case you can use malloc
+in your ofdata_to_platdata (or probe) method to allocate the required memory,
+and you should free it in the remove method.
+
+
+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 platdata, 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 platdata
+- 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.
+
+Uclasses are statically numbered at compile time. It would be possible to
+change this to dynamic numbering, but then we would require some sort of
+lookup service, perhaps searching by name. This is slightly less efficient
+so has been left out for now. One small advantage of dynamic numbering might
+be fewer merge conflicts in uclass-id.h.
+
+
+Simon Glass
+sjg at chromium.org
+April 2013
+Updated 7-May-13
+Updated 14-Jun-13
+Updated 18-Oct-13
+Updated 5-Nov-13
Signature · 1 line
1.8.4.1
#4 lore raw

PATCH v7 4/13 dm: Add base driver model support

In reply to Simon Glass

Add 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 v7:
- Update Makefile libraries to specify only the directory

Changes in v6:
- Add dev_get_platdata to access devices's platdata
- Add dev_get_priv() to access device's private data
- Add ofdata_to_pdata method to convert device tree data to platdata
- Convert Makefiles to new Kconfig format
- Rename platform_data to platdata

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:
- Add a flag for tracking whether DM allocates/frees platform_data
- Rename per_device_priv_size to per_device_auto_alloc_size, etc.
- Tidy up commenting of functions and structures

Changes in v2: None

 Makefile                          |   1 +
 drivers/core/Makefile             |   7 +
 drivers/core/device.c             | 348 ++++++++++++++++++++++++++++++++++++++
 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               | 159 +++++++++++++++++
 include/dm/lists.h                |  39 +++++
 include/dm/platdata.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, 1601 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/platdata.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
index bd4ea1f..939110f 100644
@@ -243,6 +243,7 @@ LIBS-y += fs/
 LIBS-y += net/
 LIBS-y += disk/
 LIBS-y += drivers/
+LIBS-$(CONFIG_DM) += drivers/core/
 LIBS-y += drivers/dma/
 LIBS-y += drivers/gpio/
 LIBS-y += drivers/i2c/
drivers/core/Makefile new file +7 -0
new file mode 100644
index 0000000..90b2a7f
@@ -0,0 +1,7 @@
+#
+# Copyright (c) 2013 Google, Inc
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM)	:= device.o lists.o root.o uclass.o util.o
drivers/core/device.c new file +348 -0

348 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
new file mode 100644
index 0000000..e01dd06
@@ -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
index 0de0bea..707400e 100644
@@ -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
new file mode 100644
index 0000000..8bbb21b
@@ -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/platdata.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 +159 -0

159 lines not on this page · raw message

include/dm/lists.h new file +39 -0
new file mode 100644
index 0000000..0d09f9a
@@ -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 platdata.
+ *
+ * @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/platdata.h new file +22 -0
new file mode 100644
index 0000000..0ef3353
@@ -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_PLATDATA_H
+#define _DM_PLATDATA_H
+
+struct driver_info {
+	const char	*name;
+	const void	*platdata;
+};
+
+#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
new file mode 100644
index 0000000..f0e691c
@@ -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
new file mode 100644
index 0000000..8be64a9
@@ -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.1
#5 lore raw

PATCH v7 5/13 sandbox: config: Enable driver model

In reply to Simon Glass

Use driver model in sandbox to permit running of driver model unit test.

---

Changes in v7: None
Changes in v6: None
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
index 8eee781..67becdc 100644
@@ -20,6 +20,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.1
#6 lore raw

PATCH v7 6/13 dm: Set up driver model after relocation

In reply to Simon Glass

Make 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 v7: None
Changes in v6:
- Rename platform_data to platdata

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
index 86ca1cb..162562b 100644
@@ -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_platdata();
+	if (ret) {
+		debug("dm_scan_platdata() 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.1
#7 lore raw

PATCH v7 7/13 dm: Add basic tests

In reply to Simon Glass

Add 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 v7:
- Update Makefile libraries to specify only the directory

Changes in v6:
- Add a test script for driver model
- Convert Makefiles to new Kconfig format
- Rename platform_data to platdata
- Use ofdata_to_platdata feature

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/.gitignore        |   1 +
 test/dm/Makefile          |  17 ++
 test/dm/core.c            | 544 ++++++++++++++++++++++++++++++++++++++++++++++
 test/dm/test-dm.sh        |   7 +
 test/dm/test-driver.c     | 146 +++++++++++++
 test/dm/test-fdt.c        | 144 ++++++++++++
 test/dm/test-main.c       | 107 +++++++++
 test/dm/test-uclass.c     | 104 +++++++++
 test/dm/test.dts          |  59 +++++
 test/dm/ut.c              |  33 +++
 14 files changed, 1426 insertions(+)
 create mode 100644 include/dm/test.h
 create mode 100644 include/dm/ut.h
 create mode 100644 test/dm/.gitignore
 create mode 100644 test/dm/Makefile
 create mode 100644 test/dm/core.c
 create mode 100755 test/dm/test-dm.sh
 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
index 939110f..6132a1e 100644
@@ -277,6 +277,7 @@ LIBS-y += lib/libfdt/
 LIBS-$(CONFIG_API) += api/
 LIBS-y += post/
 LIBS-y += test/
+LIBS-y += test/dm/
 
 ifneq (,$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35 mxs vf610))
 LIBS-y += arch/$(ARCH)/imx-common/
include/configs/sandbox.h +1 -0
index 67becdc..e412047 100644
@@ -21,6 +21,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/.gitignore new file +1 -0
new file mode 100644
index 0000000..b741b8a
@@ -0,0 +1 @@
+/test.dtb
test/dm/Makefile new file +17 -0
new file mode 100644
index 0000000..6af85b9
@@ -0,0 +1,17 @@
+#
+# Copyright (c) 2013 Google, Inc
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TEST) += test-driver.o
+obj-$(CONFIG_DM_TEST) += test-fdt.o
+obj-$(CONFIG_DM_TEST) += test-main.o
+obj-$(CONFIG_DM_TEST) += test-uclass.o
+obj-$(CONFIG_DM_TEST) += ut.o
+
+# Tests for particular subsystems - when enabling driver model for a new
+# subsystem you must add sandbox tests here.
+obj-$(CONFIG_DM_TEST) += core.o
+obj-$(CONFIG_DM_TEST) += ut.o
+obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/core.c new file +544 -0

544 lines not on this page · raw message

test/dm/test-dm.sh new file +7 -0
new file mode 100755
index 0000000..ef5aca5
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor)
+dtc -I dts -O dtb test/dm/test.dts -o test/dm/test.dtb
+make O=sandbox sandbox_config
+make O=sandbox -s -j${NUM_CPUS}
+./sandbox/u-boot -d test/dm/test.dtb -c "dm test"
test/dm/test-driver.c new file +146 -0

146 lines not on this page · raw message

test/dm/test-fdt.c new file +144 -0

144 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
new file mode 100644
index 0000000..8b69bc2
@@ -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.1
#8 lore raw

PATCH v7 8/13 dm: Add a 'dm' command for testing

In reply to Simon Glass

This command is not required for driver model operation, but can be useful for testing. It provides simple dumps of internal data structures.

---

Changes in v7: None
Changes in v6: None
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
index e412047..734f90b 100644
@@ -21,6 +21,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
index 6af85b9..4e9afe6 100644
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_CMD_DM) += cmd_dm.o
 obj-$(CONFIG_DM_TEST) += test-driver.o
 obj-$(CONFIG_DM_TEST) += test-fdt.o
 obj-$(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.1
#9 lore raw

PATCH v7 9/13 dm: Add a demonstration/example driver

In reply to Simon Glass

As 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 v7:
- Update Makefile libraries to specify only the directory

Changes in v6:
- Convert Makefiles to new Kconfig format
- Rename platform_data to platdata
- Use ofdata_to_platdata method to convert device tree data to platdata

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      |   9 ++++
 drivers/demo/demo-pdata.c  |  47 +++++++++++++++++
 drivers/demo/demo-shape.c  | 127 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/demo/demo-simple.c |  47 +++++++++++++++++
 drivers/demo/demo-uclass.c |  58 +++++++++++++++++++++
 include/configs/sandbox.h  |   4 ++
 include/dm-demo.h          |  36 +++++++++++++
 10 files changed, 432 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
index 6132a1e..2518ea9 100644
@@ -278,6 +278,7 @@ LIBS-$(CONFIG_API) += api/
 LIBS-y += post/
 LIBS-y += test/
 LIBS-y += test/dm/
+LIBS-$(CONFIG_DM_DEMO) += drivers/demo/
 
 ifneq (,$(filter $(SOC), mx25 mx27 mx5 mx6 mx31 mx35 mxs vf610))
 LIBS-y += arch/$(ARCH)/imx-common/
common/Makefile +1 -0
index 74404be..a2a9e01 100644
@@ -63,6 +63,7 @@ obj-$(CONFIG_CMD_CONSOLE) += cmd_console.o
 obj-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o
 obj-$(CONFIG_DATAFLASH_MMC_SELECT) += cmd_dataflash_mmc_mux.o
 obj-$(CONFIG_CMD_DATE) += cmd_date.o
+obj-$(CONFIG_CMD_DEMO) += cmd_demo.o
 obj-$(CONFIG_CMD_SOUND) += cmd_sound.o
 ifdef CONFIG_4xx
 obj-$(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 +9 -0
new file mode 100644
index 0000000..baaa2ba
@@ -0,0 +1,9 @@
+#
+# Copyright (c) 2013 Google, Inc
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM_DEMO) += demo-uclass.o demo-pdata.o
+obj-$(CONFIG_DM_DEMO_SIMPLE) += demo-simple.o
+obj-$(CONFIG_DM_DEMO_SHAPE) += demo-shape.o
drivers/demo/demo-pdata.c new file +47 -0

47 lines not on this page · raw message

drivers/demo/demo-shape.c new file +127 -0

127 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 +58 -0

58 lines not on this page · raw message

include/configs/sandbox.h +4 -0
index 734f90b..de94514 100644
@@ -21,7 +21,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
new file mode 100644
index 0000000..6e38d3c
@@ -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.1
#10 lore raw

PATCH v7 10/13 dm: Add GPIO support and tests

In reply to Simon Glass

Add 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 v7: None
Changes in v6:
- Rename platform_data to platdata

Changes in v5:
- Change to new SPDX license headers

Changes in v4: None
Changes in v3:
- Tidy up comments/documentation in GPIO module
- Update GPIO support to use new struct member names

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
index b903c45..cd581e8 100644
@@ -5,6 +5,8 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_DM_GPIO)		+= gpio-uclass.o
+
 obj-$(CONFIG_AT91_GPIO)	+= at91_gpio.o
 obj-$(CONFIG_INTEL_ICH6_GPIO)	+= intel_ich6_gpio.o
 obj-$(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.1
#11 lore raw

PATCH v7 11/13 sandbox: Convert GPIOs to use driver model

In reply to Simon Glass

Convert sandbox over to use driver model GPIOs.

---

Changes in v7: None
Changes in v6:
- Rename platform_data to platdata
- Use ofdata_to_platdata feature

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          | 217 +++++++++++++++++++++++++---------------
 include/configs/sandbox.h       |   1 +
 4 files changed, 151 insertions(+), 88 deletions(-)
arch/sandbox/include/asm/gpio.h +5 -9
index afb9c78..95b59da 100644
@@ -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
index 65dcce8..9e0e6e2 100644
@@ -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 +139 -78

318 lines not on this page · raw message

include/configs/sandbox.h +1 -0
index de94514..674f6e1 100644
@@ -26,6 +26,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.1
#12 lore raw

PATCH v7 12/13 dm: Enable gpio command to support driver model

In reply to Simon Glass

Now 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 v7: None
Changes in v6: None
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
index 47eee89..c6758c1 100644
@@ -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.1
#13 lore raw

PATCH v7 13/13 dm: Remove old driver model documentation

In reply to Simon Glass

This 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 v7: None
Changes in v6: None
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      | 428 --------------------------------------
 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   | 159 --------------
 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, 3670 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
deleted file mode 100644
index 0437d9b..0000000
@@ -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
---------------------------------
-
-  ahci.c
-  ------
-    SCSI API, will be rewritten for a different API.
-
-  ata_piix.c
-  ----------
-    SATA API, easy to port.
-
-  fsl_sata.c
-  ----------
-    SATA API, few CONFIG macros, easy to port.
-
-  ftide020.c
-  ----------
-    IDE API, defines CONFIG_IDE_AHB and ide_preinit hook functions.
-
-  mg_disk.c
-  ---------
-    Single driver with mg_disk API, not much to change, easy to port.
-
-  mvsata_ide.c
-  ------------
-    IDE API, only defines ide_preinit hook function.
-
-  mxc_ata.c
-  ---------
-    IDE API, only defines ide_preinit hook function.
-
-  pata_bfin.c
-  -----------
-    SATA API, easy to port.
-
-  sata_dwc.c
-  ----------
-    SATA API, easy to port.
-
-  sata_sil3114.c
-  --------------
-    SATA API, easy to port.
-
-  sata_sil.c
-  ----------
-    SATA API, easy to port.
-
-  sil680.c
-  --------
-    IDE API, only defines ide_preinit hook function.
-
-  sym53c8xx.c
-  -----------
-    SCSI API, may be merged with code from cmd_scsi.
-
-  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 -428

428 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 -159

159 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

113 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.1

Part of the diff is not shown here. View the raw message.

#15 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

Dear Masahiro Yamada,

Quoted 4 lines

Hello

How come 13/13 is missing?

I see it here.

Best regards,
Marek Vasut

#16 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

In reply to Masahiro Yamada
Quoted 1 line · Masahiro Yamada

How come 13/13 is missing?

It's not.

Signature · 2 lines
Mateusz Zalega
Samsung R&D Institute Poland
#17 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

+Tom

Hi,

Quoted 4 lines · Mateusz Zalega
Quoted 1 line · Masahiro Yamada

How come 13/13 is missing?

It's not.

I think it was missing until someone approved it, since it was over the 100KB limit.

Regards,
Simon

#18 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

Hi Tom,

Quoted 4 lines · Simon Glass

+Tom

Hi,

Quoted 8 lines
Quoted 4 lines · Mateusz Zalega
Quoted 1 line · Masahiro Yamada

How come 13/13 is missing?

It's not.

I think it was missing until someone approved it, since it was over the 100KB limit.

What do you think of this series? Do you think it is ready to apply?

Regards,
Simon

#19 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

Quoted 9 lines · Simon Glass

Hi Tom,

Quoted 6 lines · Simon Glass

+Tom

Hi,

Quoted 1 line · Mateusz Zalega

On 11/29/13 02:00, Masahiro Yamada wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

How come 13/13 is missing?

It's not.

I think it was missing until someone approved it, since it was over the 100KB limit.

What do you think of this series? Do you think it is ready to apply?

I think we're where it needs wider testing now, yes. But given that we've stumbled onto another problem or two with the bootm refactoring series, I'm really hesitant to pull something else big in for this release. Kbuild style Makefiles this time, start DM for v2014.04 is my plan currently.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20131203/4de5cf5f/attachment.pgp>
#20 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

Hi Tom,

Quoted 17 lines · Tom Rini
Quoted 16 lines · Simon Glass

Hi Tom,

Quoted 12 lines · Simon Glass

+Tom

Hi,

Quoted 4 lines · Mateusz Zalega
Quoted 1 line · Masahiro Yamada

How come 13/13 is missing?

It's not.

I think it was missing until someone approved it, since it was over the 100KB limit.

Quoted 7 lines
Quoted 1 line

What do you think of this series? Do you think it is ready to apply?

I think we're where it needs wider testing now, yes. But given that we've stumbled onto another problem or two with the bootm refactoring series, I'm really hesitant to pull something else big in for this release. Kbuild style Makefiles this time, start DM for v2014.04 is my plan currently.

Sounds reasonable. It's ready to go, hopefully won't need a lot of care and feeding before then.

Re bootm I am still not thrilled with the outcome. We flushed out quite a few cases in dark corners at great expense, but don't have a lot of automated tests (only the vboot test actually runs bootm I think). Any ideas on what we should do here?

Regards,
Simon

Quoted 3 lines

--
Tom

#21 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

Quoted 28 lines · Simon Glass

Hi Tom,

Quoted 17 lines · Tom Rini
Quoted 16 lines · Simon Glass

Hi Tom,

Quoted 12 lines · Simon Glass

+Tom

Hi,

Quoted 4 lines · Mateusz Zalega
Quoted 1 line · Masahiro Yamada

How come 13/13 is missing?

It's not.

I think it was missing until someone approved it, since it was over the 100KB limit.

Quoted 7 lines
Quoted 1 line

What do you think of this series? Do you think it is ready to apply?

I think we're where it needs wider testing now, yes. But given that we've stumbled onto another problem or two with the bootm refactoring series, I'm really hesitant to pull something else big in for this release. Kbuild style Makefiles this time, start DM for v2014.04 is my plan currently.

Quoted 7 lines

Sounds reasonable. It's ready to go, hopefully won't need a lot of care and feeding before then.

Re bootm I am still not thrilled with the outcome. We flushed out quite a few cases in dark corners at great expense, but don't have a lot of automated tests (only the vboot test actually runs bootm I think). Any ideas on what we should do here?

Well, did you see where Michal's test case was? It looks like that should fail anywhere, not just microblaze. For now, I really just want to get this latest bug fixed.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20131203/e3d8ec85/attachment.pgp>
#22 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

Hi Tom,

Quoted 32 lines · Tom Rini
Quoted 31 lines · Simon Glass

Hi Tom,

Quoted 17 lines · Tom Rini
Quoted 16 lines · Simon Glass

Hi Tom,

Quoted 12 lines · Simon Glass

+Tom

Hi,

Quoted 4 lines · Mateusz Zalega
Quoted 1 line · Masahiro Yamada

How come 13/13 is missing?

It's not.

I think it was missing until someone approved it, since it was over the 100KB limit.

Quoted 7 lines
Quoted 1 line

What do you think of this series? Do you think it is ready to apply?

I think we're where it needs wider testing now, yes. But given that we've stumbled onto another problem or two with the bootm refactoring series, I'm really hesitant to pull something else big in for this release. Kbuild style Makefiles this time, start DM for v2014.04 is my plan currently.

Sounds reasonable. It's ready to go, hopefully won't need a lot of care and feeding before then.

Quoted 8 lines
Quoted 4 lines

Re bootm I am still not thrilled with the outcome. We flushed out quite a few cases in dark corners at great expense, but don't have a lot of automated tests (only the vboot test actually runs bootm I think). Any ideas on what we should do here?

Well, did you see where Michal's test case was? It looks like that should fail anywhere, not just microblaze. For now, I really just want to get this latest bug fixed.

OK I see it, will take a look.

Regards,
Simon

#23 lore raw

v7 cover Driver model implementation, tests, demo and GPIO

Quoted 40 lines · Simon Glass

Hi Tom,

Quoted 37 lines · Tom Rini
Quoted 35 lines · Simon Glass

Hi Tom,

Quoted 17 lines · Tom Rini
Quoted 16 lines · Simon Glass

Hi Tom,

Quoted 12 lines · Simon Glass

+Tom

Hi,

Quoted 4 lines · Mateusz Zalega
Quoted 1 line · Masahiro Yamada

How come 13/13 is missing?

It's not.

I think it was missing until someone approved it, since it was over the 100KB limit.

Quoted 7 lines
Quoted 1 line

What do you think of this series? Do you think it is ready to apply?

I think we're where it needs wider testing now, yes. But given that we've stumbled onto another problem or two with the bootm refactoring series, I'm really hesitant to pull something else big in for this release. Kbuild style Makefiles this time, start DM for v2014.04 is my plan currently.

Sounds reasonable. It's ready to go, hopefully won't need a lot of care and feeding before then.

Re bootm I am still not thrilled with the outcome. We flushed out quite a few cases in dark corners at great expense, but don't have a lot of automated tests (only the vboot test actually runs bootm I think). Any ideas on what we should do here?

Quoted 5 lines
Quoted 3 lines

Well, did you see where Michal's test case was? It looks like that should fail anywhere, not just microblaze. For now, I really just want to get this latest bug fixed.

OK I see it, will take a look.

Thanks Simon. I wanted to look at it but I am too busy with others things which have higher priority.

Thanks,
Michal

Signature · 14 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Microblaze cpu - http://www.monstr.eu/fdt/
Maintainer of Linux kernel - Xilinx Zynq ARM architecture
Microblaze U-BOOT custodian and responsible for u-boot arm zynq platform


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 263 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20131204/4ee73c4f/attachment.pgp>