From 581738642fbeacdf97fc737a41b3128d72cf1a1c Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Tue, 1 Aug 2017 17:09:35 +0200 Subject: Reinvent I2C ops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not use the global platform_i2c_transfer() function that can only be implemented by a single driver. Instead, make a `struct device` aware transfer() function the only interface function for I2C controller dri- vers to implement. To not force the slave device drivers to be implemented either above generic I2C or specialized SMBus operations, we support SMBus control- lers in the slave device interface too. We start with four simple slave functions: i2c_readb(), i2c_writeb(), i2c_readb_at() and i2c_writeb_at(). They are all compatible to respec- tive SMBus functions. But we keep aliases because it would be weird to force e.g. an I2C EEPROM driver to call smbus_read_byte(). Change-Id: I98386f91bf4799ba3df84ec8bc0f64edd4142818 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/20846 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin Reviewed-by: Kyösti Mälkki --- src/device/i2c.c | 83 -------------------------------------------------------- 1 file changed, 83 deletions(-) (limited to 'src/device/i2c.c') diff --git a/src/device/i2c.c b/src/device/i2c.c index 6fdd5cff26..aa695caf03 100644 --- a/src/device/i2c.c +++ b/src/device/i2c.c @@ -13,92 +13,9 @@ * GNU General Public License for more details. */ -#include -#include #include #include -#if ENV_RAMSTAGE -/* Return I2C operations for a bus */ -static inline const struct i2c_bus_operations *ops_i2c_bus(struct bus *bus) -{ - if (bus && bus->dev && bus->dev->ops) - return bus->dev->ops->ops_i2c_bus; - return NULL; -} - -int i2c_dev_find_bus(struct device *dev) -{ - const struct i2c_bus_operations *ops; - struct bus *pbus; - - if (!dev) - return -1; - - /* Locate parent bus with I2C controller ops */ - pbus = dev->bus; - while (pbus && pbus->dev && !ops_i2c_bus(pbus)) - if (pbus->dev->bus != pbus) - pbus = pbus->dev->bus; - - /* Check if this I2C controller ops implements dev_to_bus() */ - ops = ops_i2c_bus(pbus); - if (!ops || !ops->dev_to_bus) - return -1; - - /* Use controller ops to determine the bus number */ - return ops->dev_to_bus(pbus->dev); -} - -int i2c_dev_transfer(struct device *dev, struct i2c_msg *segments, int count) -{ - int bus = i2c_dev_find_bus(dev); - if (bus < 0) - return -1; - return i2c_transfer(bus, segments, count); -} - -int i2c_dev_readb(struct device *dev, uint8_t reg, uint8_t *data) -{ - int bus = i2c_dev_find_bus(dev); - if (bus < 0) - return -1; - return i2c_readb(bus, dev->path.i2c.device, reg, data); -} - -int i2c_dev_writeb(struct device *dev, uint8_t reg, uint8_t data) -{ - int bus = i2c_dev_find_bus(dev); - if (bus < 0) - return -1; - return i2c_writeb(bus, dev->path.i2c.device, reg, data); -} - -int i2c_dev_read_bytes(struct device *dev, uint8_t reg, uint8_t *data, int len) -{ - int bus = i2c_dev_find_bus(dev); - if (bus < 0) - return -1; - return i2c_read_bytes(bus, dev->path.i2c.device, reg, data, len); -} - -int i2c_dev_read_raw(struct device *dev, uint8_t *data, int len) -{ - int bus = i2c_dev_find_bus(dev); - if (bus < 0) - return -1; - return i2c_read_raw(bus, dev->path.i2c.device, data, len); -} - -int i2c_dev_write_raw(struct device *dev, uint8_t *data, int len) -{ - int bus = i2c_dev_find_bus(dev); - if (bus < 0) - return -1; - return i2c_write_raw(bus, dev->path.i2c.device, data, len); -} -#endif - int i2c_read_field(unsigned bus, uint8_t chip, uint8_t reg, uint8_t *data, uint8_t mask, uint8_t shift) { -- cgit v1.2.3