[U-Boot] [PATCH v6 0/11] dm: Add I2C support and convert sandbox, tegra

Simon Glass sjg at chromium.org
Wed Dec 10 16:55:46 CET 2014


This series adds I2C support to driver model. It has become apparent that
this is a high priority as it is widely used. It follows along to some
extent from the SPI conversion.

Several changes are made from the original I2C implementations.

Firstly it is not necessary to specify the chip address with every call,
since each chip knows its own address - it is stored in struct dm_i2c_chip
which is attached to each chip on the I2C bus. However, this information
*is* passed to the driver since I presume most drivers need it and it would
be cumbersome to look up in every call.

Secondly there is no concept of a 'current' I2C bus so all associated logic
is removed. With driver model i2c_set_bus_num() and i2c_get_bus_num() are
not available. Since the chip device specifies both the bus and the chip
address, there is no need for this concept. It also causes problems when
one driver changes the current bus and forgets to change it back.

Thirdly initialisation is handled by driver model's normal probe() method
on each device so there should be no need for i2c_init_all(), i2c_init(),
i2c_init_board(), i2c_board_late_init() and board_i2c_init().

I2C muxes are not yet supported. To support these we will need to maintain
state of the current mux settings to avoid resetting every mux every time.
Probably we need to add a sandbox I2C mux driver to permit testing of this.
This can probably be done later.

Platform data is not yet supported either, only device tree. The
U_BOOT_I2C_MKENT_COMPLETE() and U_BOOT_I2C_ADAP_COMPLETE() macros are not
used. Also struct i2c_adapter is not defined anymore. This will need to be
addressed, perhaps as part of converting over a board that does not use
device tree, assuming that we want to support this.

The following I2C CONFIGs are no-longer needed when driver model is used:

  CONFIG_SYS_I2C_INIT_BOARD - each I2C bus is inited in its probe() method
  CONFIG_I2C_MULTI_BUS      - we always support multi-bus with driver model
  CONFIG_SYS_MAX_I2C_BUS    - the device tree aliases define available buses
  CONFIG_SYS_I2C_SPEED      - the device tree specifies the speed for each bus
  CONFIG_SYS_I2C            - this is the 'new old' API, now deprecated

There are a few SPI patches included here due to a dependency on a new
device binding function.

v3 changes the uclass to driver interface significantly. It is now a list of
messages to be processed by the driver. This matches the Linux user space
API which may be a benefit. It does introduce one complication, which is
that the protocol does not support separate chip offset and data. I have
enhanced it to do so.

This series is available at u-boot-dm/i2c-working2.

Changes in v6:
- Drop a stale comment
- Drop the probe_chip() method which is not needed
- Pass value from i2c_get_chip() to get_emul()
- Use dm_scan_fdt_node() to find emulator

Changes in v5:
- Add a function comment for i2c_probe_chip()
- Add an assert for offset_len in i2c_setup_offset()
- Add more detail to return value comment on get_buf_speed()
- Add more detail to return value comment on xfer() method
- Adjust tests for DM_I2C_CHIP_RE_ADDRESS split
- Fix -INVAL typo
- Make i2c_get_bus_speed() independent of i2c_set_bus_speed()
- Split DM_I2C_CHIP_RD_ADDRESS into read and write varaints
- Update comments in struct i2c_msg to allow buf to be NULL
- Use a NULL buffer in i2c_probe_chip()

Changes in v4:
- Add a constant for I2C_MAX_OFFSET_LEN
- Add a probe_chip() method for the eeprom
- Add a probe_chip() method to the uclass
- Add a remove() method for the eeprom
- Add an assert for non-null
- Add an eeprom test mode
- Add chip flags to i2c_probe()
- Add comment to i2c_setup_offset()
- Add comments to indicate which methods are optional
- Add comments to set_bus_speed() method
- Add eeprom debugging output
- Add new patch to add newline to debug() messages
- Add probe_chip() method
- Add support for eeprom offset length
- Add tests for offset length
- Adjust i2c_bind_driver() to avoid calloc()/free()
- Adjust tests to match uclass changes
- Drop set_offset_len() method
- Fix copying of chip flags to message in i2c_setup_offset()
- Fix endianness of i2c_setup_offset()
- Fix method comment for xfer()
- Invert return value of i2c_setup_offset()
- Probe with a message length of 0
- Rename i2c_generic_drv to i2c_generic_chip_drv
- Rename i2c_read_bytewise() and implement a real one
- Update call to i2c_probe()

Changes in v3:
- Add a helper to query chip flags
- Add new 'i2c flags' command to get/set chip flags
- Add support for reading a byte at a time with an address for each byte
- Adjust for slightly altered I2C uclass API
- Change driver to support new message-based I2C uclass API
- Change uclass <=> driver API to use a message list
- Correct bogus address len code (was confused with chip address length)
- Drop extra call to i2c_bind_driver() in i2c_probe()
- Update emulator for new uclass interface
- Update for new uclass <=> driver interface
- Update for new uclass <=> emulateor interface

Changes in v2:
- Add a 'deblock' method to recover an I2C bus stuck in mid-transaction
- Add a helper function to find a chip on a particular bus number
- Add a new asm/test.h header for tests in sandbox
- Add a test for automatic binding of generic I2C devices
- Add some debugging for generic I2C device binding
- Adjust tegra_i2c_child_pre_probe() to permit generic I2C devices
- Call the deblock() method for 'i2c reset'
- Change alen to int so that it can be -1 (this was a bug)
- Correct the compatible strings for I2C buses
- Don't init if the speed is 0, since this breaks the controller
- Expand coverage to all Tegra boards
- Fix cihp typo
- Implement generic I2C devices to allow 'i2c probe' on unknown devices
- Return the probed device from i2c_probe()
- Set the bus speed after the bus is probed
- Update commit message for EEPROM driver

Simon Glass (11):
  dm: i2c: Add a uclass for I2C
  dm: i2c: Implement driver model support in the i2c command
  dm: i2c: Add I2C emulation driver for sandbox
  dm: i2c: Add a sandbox I2C driver
  dm: i2c: Add an I2C EEPROM simulator
  dm: i2c: config: Enable I2C for sandbox using driver model
  dm: i2c: dts: Add an I2C bus for sandbox
  dm: Add a simple EEPROM driver
  dm: i2c: Add tests for I2C
  dm: device: Add newline to debug() messages
  dm: i2c: tegra: Convert to driver model

 arch/arm/cpu/tegra20-common/pmu.c           |  21 +-
 arch/arm/dts/tegra124-jetson-tk1.dts        |   1 -
 arch/arm/dts/tegra30-tec-ng.dts             |   4 +
 arch/arm/include/asm/arch-tegra/tegra_i2c.h |   2 +-
 arch/sandbox/dts/sandbox.dts                |  17 +
 arch/sandbox/include/asm/test.h             |  26 ++
 board/avionic-design/common/tamonten-ng.c   |  12 +-
 board/nvidia/cardhu/cardhu.c                |  13 +-
 board/nvidia/common/board.c                 |   4 -
 board/nvidia/dalmore/dalmore.c              |  21 +-
 board/nvidia/whistler/whistler.c            |  29 +-
 board/toradex/apalis_t30/apalis_t30.c       |  19 +-
 common/cmd_i2c.c                            | 376 ++++++++++++++++++----
 drivers/core/device.c                       |   6 +-
 drivers/i2c/Makefile                        |   2 +
 drivers/i2c/i2c-emul-uclass.c               |  14 +
 drivers/i2c/i2c-uclass.c                    | 466 ++++++++++++++++++++++++++++
 drivers/i2c/sandbox_i2c.c                   | 111 +++++++
 drivers/i2c/tegra_i2c.c                     | 366 +++++++---------------
 drivers/misc/Makefile                       |   4 +
 drivers/misc/i2c_eeprom.c                   |  51 +++
 drivers/misc/i2c_eeprom_emul.c              | 168 ++++++++++
 drivers/power/tps6586x.c                    |  27 +-
 include/config_fallbacks.h                  |   6 +
 include/configs/apalis_t30.h                |   3 -
 include/configs/beaver.h                    |   3 -
 include/configs/cardhu.h                    |   5 -
 include/configs/colibri_t30.h               |   3 -
 include/configs/dalmore.h                   |   5 -
 include/configs/jetson-tk1.h                |   5 -
 include/configs/nyan-big.h                  |   5 -
 include/configs/sandbox.h                   |   6 +
 include/configs/seaboard.h                  |   3 -
 include/configs/tec-ng.h                    |   5 -
 include/configs/tegra-common.h              |   1 +
 include/configs/tegra114-common.h           |   3 -
 include/configs/tegra124-common.h           |   3 -
 include/configs/tegra20-common.h            |   3 -
 include/configs/tegra30-common.h            |   3 -
 include/configs/trimslice.h                 |   3 -
 include/configs/venice2.h                   |   5 -
 include/configs/whistler.h                  |   3 -
 include/dm/uclass-id.h                      |   4 +
 include/dm/ut.h                             |  12 +
 include/i2c.h                               | 352 +++++++++++++++++++++
 include/i2c_eeprom.h                        |  19 ++
 include/tps6586x.h                          |   4 +-
 test/dm/Makefile                            |   1 +
 test/dm/i2c.c                               | 216 +++++++++++++
 test/dm/test.dts                            |  17 +
 50 files changed, 2028 insertions(+), 430 deletions(-)
 create mode 100644 arch/sandbox/include/asm/test.h
 create mode 100644 drivers/i2c/i2c-emul-uclass.c
 create mode 100644 drivers/i2c/i2c-uclass.c
 create mode 100644 drivers/i2c/sandbox_i2c.c
 create mode 100644 drivers/misc/i2c_eeprom.c
 create mode 100644 drivers/misc/i2c_eeprom_emul.c
 create mode 100644 include/i2c_eeprom.h
 create mode 100644 test/dm/i2c.c

-- 
2.2.0.rc0.207.ga3a616c



More information about the U-Boot mailing list