coreboot/src
Duncan Laurie ec00968f08 device: i2c: Add support for I2C bus operations
In order to support doing bus operations on an I2C device that is
described in the devicetree there needs to be some linkage of the
device and the existing opaque I2C controller bus number.

This is provided in a similar fashion to the existing SMBUS operations
but modified to fit within the existing I2C infrastructure.

Variants of the existing I2C helper functions are provided that will
obtain the bus number that corresponds to this device by looking for
the SOC-provided I2C bus operation structure to provide a function
that will make that translation.

For example an SOC using a PCI I2C controller at 0:15.0 could use:

soc/intel/.../i2c.c:
  static int i2c_dev_to_bus(struct device *dev)
  {
    if (dev->path.pci.devfn == PCI_DEVFN(0x15, 0))
      return 0;
    return -1;
  }
  static struct i2c_bus_operation i2c_bus_ops = {
    .dev_to_bus = &i2c_dev_to_bus
  }
  static struct device_operations i2c_dev_ops = {
    .ops_i2c_bus = &i2c_bus_ops
    ...
  }

With an I2C device on that bus at address 0x1a described in the tree:

devicetree.cb:
  device pci 15.0 on # I2C0
    chip drivers/i2c/sample
      device i2c 1a.0 on end
    end
  end

That driver can then do I2C transactions with the device object
without needing to know that the SOC-specific bus number that this
I2C device lives on is "0".

For example it could read a version value from register address 0
with a byte transaction:

drivers/i2c/sample/sample.c:
  static void i2c_sample_enable(struct device *dev)
  {
    uint8_t ver;
    if (!i2c_dev_readb(dev, 0x00, &ver))
      printk(BIOS_INFO, "I2C %s version 0x02x\n", dev_path(dev), ver);
  }

Change-Id: I6c41c8e0d10caabe01cc41da96382074de40e91e
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/15100
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
2016-06-09 17:05:40 +02:00
..
acpi acpi/: add missing license header 2016-01-14 22:52:11 +01:00
arch SMBIOS: Implement SKU field 2016-06-02 06:24:24 +02:00
commonlib commonlib/lz4: Avoid unaligned memory access on RISC-V 2016-05-31 21:07:03 +02:00
console console/post: be explicit about conditional cmos_post_log() compiling 2016-05-25 18:04:11 +02:00
cpu AGESA vendorcode: Build a common amdlib 2016-05-18 10:44:43 +02:00
device device: i2c: Add support for I2C bus operations 2016-06-09 17:05:40 +02:00
drivers drivers/intel/fsp2.0: Add semantic patch for FspUpdVpd.h header 2016-06-08 22:35:18 +02:00
ec chromeec: Move EC image hash to separate file in CBFS 2016-06-03 17:24:26 +02:00
include device: i2c: Add support for I2C bus operations 2016-06-09 17:05:40 +02:00
lib cbfs: Use NO_XIP_EARLY_STAGES to decide if stage is XIP 2016-06-02 17:21:39 +02:00
mainboard rockchip: rk3399: Add support i2s 2016-06-08 23:27:01 +02:00
northbridge nb/intel/x4x: Fix unpopulated value 2016-06-04 23:46:05 +02:00
soc soc/intel/quark: Pass serial port address to FSP 2016-06-09 17:02:26 +02:00
southbridge drivers/lenovo: Add hybrid graphics driver 2016-06-01 23:22:01 +02:00
superio sio/winbond/w83667hg-a: Add pinmux defines for UART B 2016-05-29 19:34:54 +02:00
vendorcode soc/intel/quark: Pass serial port address to FSP 2016-06-09 17:02:26 +02:00
Kconfig Add Board Checklist Support 2016-06-03 17:29:13 +02:00