[U-Boot] [PATCH 0/25] Introduce driver model support for SPI, SPI flash, cros_ec

Simon Glass sjg at chromium.org
Tue Jul 15 02:56:07 CEST 2014


Up until now driver model has not been used for any type of bus. Buses
have some unique properties and needs, so we cannot claim that driver
model can cover all the common cases unless we have converted a bus over
to driver model.

SPI is a reasonable choice for this next step. It has a fairly simple
API and not too many dependencies. The main one is SPI flash so we may
as well convert that also. Since the boards I test with have cros_ec I
have also included that, for SPI only.

The technique used is make use of driver model's supported data structures
to hold information currently kept by each subsystem in a private data
structure. Since 'struct spi_slave' relates to the slave device on the bus
it is stored in the 'parent' data with each child device of the bus.
Since 'struct spi_flash' is a standard interface used for each SPI flash
driver, it is stored in the SPI FLash uclass's private data for each
device.

New defines are created to enable driver model for each subsystem. These
are:

   CONFIG_DM_SPI
   CONFIG_DM_SPI_FLASH
   CONFIG_DM_CROS_EC

This allows us to move some boards and drivers to driver model, while
leaving others behind. A 'big bang' conversion of everything to driver
model, event at a subsystem level, is never going to work.

On the other hand, we change the driver at the same time as the CONFIG
option is enabled. Keeping both version of the driver around involves a
flock of #ifdefs, the benefit of which is not apparent to me, since the
old code is removed anyway.

There is some cost in changing the uclass interface after it is created,
so if you have limited time, please spend it reviewing the uclass
interfaces in spi.h and spi_flash.h. These need to be supported by each
driver, so changing them later may involve changing multiple drivers.

To help with conversion of SPI drivers to driver model, documentation is
provided which takes the happy camper through the process with an example.

As always, driver model patches are available at u-boot-dm.git branch
'working'.

Note: This series is not fully ready - e.g. some header files are missing
comments. But I wanted to get it out for review early since some SPI work
is ongoing which might depend on it.


Simon Glass (25):
  sandbox: Convert SPI flash emulation to use sf_params
  sandbox: config: Enable all SPI flash chips
  sandbox: dts: Add a SPI device and cros_ec device
  dm: spi: Move cmd device code into its own function
  spi: Add brackets and tidy defines in spi.h
  dm: spi: Add a uclass for SPI
  dm: sandbox: Add a SPI emulation uclass
  dm: Remove spi_init() from board_r.c when using driver model
  dm: Add spi.h header to a few files
  dm: spi: Adjust cmd_spi to work with driver model
  dm: sandbox: spi: Move to driver model
  dm: spi: Add documentation on how to convert over SPI drivers
  dm: exynos: Convert SPI to driver model
  sf: Add an empty entry to the parameter list
  sf: Tidy up public and private header files
  spi: Use error return value in sf_ops
  dm: sf: Add a uclass for SPI flash
  dm: Convert spi_flash_probe() and 'sf probe' to use driver model
  dm: sf: sandbox: Convert SPI flash driver to driver model
  dm: exynos: config: Use driver model for SPI flash
  dm: spi: Add tests
  dm: sf: Add tests for SPI flash
  dm: cros_ec: Add support for driver model
  dm: sandbox: cros_ec: Move sandbox cros_ec to driver module
  dm: exynos: cros_ec: Move cros_ec_spi to driver model

 arch/arm/dts/exynos5250-snow.dts            |   8 +
 arch/arm/dts/exynos5420-peach-pit.dts       |   1 +
 arch/sandbox/dts/sandbox.dts                |  25 ++
 arch/sandbox/include/asm/spi.h              |  13 -
 arch/sandbox/include/asm/state.h            |   2 +-
 board/buffalo/lsxl/lsxl.c                   |   3 +-
 board/samsung/common/board.c                |   3 -
 common/board_r.c                            |   2 +-
 common/cmd_sf.c                             |  24 ++
 common/cmd_spi.c                            |  73 +++-
 common/cros_ec.c                            |  30 ++
 common/env_sf.c                             |   1 +
 common/exports.c                            |   4 +-
 doc/device-tree-bindings/mtd/spi/m25p80.txt |  29 ++
 doc/driver-model/spi-howto.txt              | 570 ++++++++++++++++++++++++++++
 drivers/misc/cros_ec.c                      | 122 +++++-
 drivers/misc/cros_ec_sandbox.c              |  99 ++++-
 drivers/misc/cros_ec_spi.c                  |  68 +++-
 drivers/mtd/spi/Makefile                    |   7 +-
 drivers/mtd/spi/ramtron.c                   |   1 +
 drivers/mtd/spi/sandbox.c                   | 438 +++++++++++++++------
 drivers/mtd/spi/sf-uclass.c                 |  63 +++
 drivers/mtd/spi/sf_internal.h               |  67 +++-
 drivers/mtd/spi/sf_params.c                 |   2 +
 drivers/mtd/spi/sf_probe.c                  | 153 ++++++--
 drivers/mtd/spi/spi_spl_load.c              |   1 +
 drivers/spi/Makefile                        |   5 +
 drivers/spi/exynos_spi.c                    | 509 +++++++++----------------
 drivers/spi/sandbox_spi.c                   | 198 ++++------
 drivers/spi/spi-emul-uclass.c               |  15 +
 drivers/spi/spi-uclass.c                    | 253 ++++++++++++
 include/configs/exynos5-dt.h                |   2 +
 include/configs/sandbox.h                   |  13 +-
 include/configs/smdk5420.h                  |   1 +
 include/cros_ec.h                           |  27 +-
 include/dm/uclass-id.h                      |   4 +
 include/spi.h                               | 194 +++++++++-
 include/spi_flash.h                         | 127 ++++---
 test/dm/Makefile                            |   2 +
 test/dm/sf.c                                |  43 +++
 test/dm/spi.c                               |  47 +++
 test/dm/test.dts                            |  17 +-
 42 files changed, 2504 insertions(+), 762 deletions(-)
 create mode 100644 doc/device-tree-bindings/mtd/spi/m25p80.txt
 create mode 100644 doc/driver-model/spi-howto.txt
 create mode 100644 drivers/mtd/spi/sf-uclass.c
 create mode 100644 drivers/spi/spi-emul-uclass.c
 create mode 100644 drivers/spi/spi-uclass.c
 create mode 100644 test/dm/sf.c
 create mode 100644 test/dm/spi.c

-- 
2.0.0.526.g5318336



More information about the U-Boot mailing list