From 0f2dd1eff9930e30dddd9aabceb5d85ee3b4e980 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Tue, 1 Aug 2017 14:02:40 +0200 Subject: include/device: Split i2c.h into three Split `i2c.h` into three pieces to ease reuse of the generic defi- nitions. No code is changed. * `i2c.h` - keeps the generic definitions * `i2c_simple.h` - holds the current, limited to one controller driver per board, devicetree independent I2C interface * `i2c_bus.h` - will become the devicetree compatible interface for native I2C (e.g. non-SMBus) controllers Change-Id: I382d45c70f9314588663e1284f264f877469c74d Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/20845 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/arch/x86/acpi_device.c | 1 - src/cpu/allwinner/a10/twi.c | 2 +- src/device/i2c.c | 3 +- src/device/software_i2c.c | 2 +- src/drivers/ams/as3722rtc.c | 2 +- src/drivers/i2c/da7219/da7219.c | 2 +- src/drivers/i2c/generic/chip.h | 2 +- src/drivers/i2c/generic/generic.c | 2 +- src/drivers/i2c/max98927/max98927.c | 2 +- src/drivers/i2c/nau8825/nau8825.c | 2 +- src/drivers/i2c/rx6110sa/rx6110sa.c | 2 +- src/drivers/i2c/tpm/chip.c | 2 +- src/drivers/i2c/tpm/chip.h | 2 +- src/drivers/i2c/tpm/cr50.c | 2 +- src/drivers/i2c/tpm/tis.c | 2 +- src/drivers/i2c/tpm/tis_atmel.c | 2 +- src/drivers/i2c/tpm/tpm.c | 2 +- src/drivers/i2c/ww_ring/ww_ring.c | 2 +- src/drivers/intel/mipi_camera/camera.c | 2 +- src/drivers/maxim/max77686/max77686.c | 2 +- src/drivers/parade/ps8625/ps8625.c | 2 +- src/drivers/parade/ps8640/ps8640.c | 2 +- src/drivers/ti/tps65090/tps65090.c | 2 +- src/drivers/ti/tps65913/tps65913rtc.c | 2 +- src/drivers/xpowers/axp209/axp209.c | 2 +- src/ec/google/chromeec/ec_i2c.c | 2 +- src/include/device/i2c.h | 159 --------------------- src/include/device/i2c_bus.h | 44 ++++++ src/include/device/i2c_simple.h | 157 ++++++++++++++++++++ src/mainboard/google/daisy/mainboard.c | 2 +- src/mainboard/google/daisy/romstage.c | 2 +- src/mainboard/google/foster/bootblock.c | 2 +- src/mainboard/google/foster/pmic.c | 2 +- src/mainboard/google/gru/mainboard.c | 2 +- src/mainboard/google/nyan/bootblock.c | 2 +- src/mainboard/google/nyan/pmic.c | 2 +- src/mainboard/google/nyan_big/bootblock.c | 2 +- src/mainboard/google/nyan_big/pmic.c | 2 +- src/mainboard/google/nyan_blaze/bootblock.c | 2 +- src/mainboard/google/nyan_blaze/pmic.c | 2 +- src/mainboard/google/peach_pit/mainboard.c | 2 +- src/mainboard/google/peach_pit/romstage.c | 2 +- src/mainboard/google/smaug/bootblock.c | 2 +- src/mainboard/google/smaug/mainboard.c | 2 +- src/mainboard/google/smaug/pmic.c | 2 +- src/mainboard/google/smaug/romstage.c | 2 +- src/mainboard/google/veyron/mainboard.c | 2 +- src/mainboard/google/veyron_mickey/mainboard.c | 2 +- src/mainboard/google/veyron_rialto/mainboard.c | 2 +- src/mainboard/intel/galileo/reg_access.c | 2 +- src/mainboard/intel/galileo/vboot.c | 2 +- src/mainboard/intel/kblrvp/ramstage.c | 2 +- src/mainboard/siemens/mc_apl1/ptn3460.c | 2 +- src/soc/broadcom/cygnus/i2c.c | 2 +- src/soc/intel/apollolake/chip.h | 2 +- src/soc/intel/common/block/i2c/i2c.c | 2 +- src/soc/intel/common/block/i2c/i2c_early.c | 2 +- src/soc/intel/common/block/i2c/lpss_i2c.c | 2 +- .../common/block/include/intelblocks/lpss_i2c.h | 1 + src/soc/intel/quark/gpio_i2c.c | 2 +- src/soc/intel/quark/i2c.c | 2 +- src/soc/intel/skylake/chip.h | 2 +- src/soc/mediatek/mt8173/da9212.c | 2 +- src/soc/mediatek/mt8173/i2c.c | 2 +- src/soc/mediatek/mt8173/mt6311.c | 2 +- src/soc/nvidia/tegra/i2c.c | 2 +- src/soc/nvidia/tegra/software_i2c.c | 2 +- src/soc/nvidia/tegra124/dp.c | 2 +- src/soc/nvidia/tegra210/dp.c | 2 +- src/soc/qualcomm/ipq40xx/i2c.c | 2 +- src/soc/qualcomm/ipq806x/i2c.c | 2 +- src/soc/rockchip/common/i2c.c | 2 +- src/soc/rockchip/common/rk808.c | 2 +- src/soc/rockchip/rk3288/software_i2c.c | 2 +- src/soc/samsung/exynos5250/i2c.c | 2 +- src/soc/samsung/exynos5420/i2c.c | 2 +- 76 files changed, 274 insertions(+), 231 deletions(-) create mode 100644 src/include/device/i2c_bus.h create mode 100644 src/include/device/i2c_simple.h (limited to 'src') diff --git a/src/arch/x86/acpi_device.c b/src/arch/x86/acpi_device.c index 49439cc4a9..aac7b88497 100644 --- a/src/arch/x86/acpi_device.c +++ b/src/arch/x86/acpi_device.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #if IS_ENABLED(CONFIG_GENERIC_GPIO_LIB) #include diff --git a/src/cpu/allwinner/a10/twi.c b/src/cpu/allwinner/a10/twi.c index 123d34ec05..6601db3dde 100644 --- a/src/cpu/allwinner/a10/twi.c +++ b/src/cpu/allwinner/a10/twi.c @@ -25,7 +25,7 @@ #include #include -#include +#include #define TWI_BASE(n) (A1X_TWI0_BASE + 0x400 * (n)) diff --git a/src/device/i2c.c b/src/device/i2c.c index 67470d4921..6fdd5cff26 100644 --- a/src/device/i2c.c +++ b/src/device/i2c.c @@ -14,7 +14,8 @@ */ #include -#include +#include +#include #include #if ENV_RAMSTAGE diff --git a/src/device/software_i2c.c b/src/device/software_i2c.c index 368d145b3e..ec6722bbed 100644 --- a/src/device/software_i2c.c +++ b/src/device/software_i2c.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include /* * The implementation is based on Wikipedia. diff --git a/src/drivers/ams/as3722rtc.c b/src/drivers/ams/as3722rtc.c index 4afcdcc22c..40285d4ef2 100644 --- a/src/drivers/ams/as3722rtc.c +++ b/src/drivers/ams/as3722rtc.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/src/drivers/i2c/da7219/da7219.c b/src/drivers/i2c/da7219/da7219.c index b29a4a15af..2e7d46010e 100644 --- a/src/drivers/i2c/da7219/da7219.c +++ b/src/drivers/i2c/da7219/da7219.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/generic/chip.h b/src/drivers/i2c/generic/chip.h index 5810db801f..c5d458b6ee 100644 --- a/src/drivers/i2c/generic/chip.h +++ b/src/drivers/i2c/generic/chip.h @@ -17,7 +17,7 @@ #define __I2C_GENERIC_CHIP_H__ #include -#include +#include struct drivers_i2c_generic_config { const char *hid; /* ACPI _HID (required) */ diff --git a/src/drivers/i2c/generic/generic.c b/src/drivers/i2c/generic/generic.c index f8de1c22d9..b7a535e47f 100644 --- a/src/drivers/i2c/generic/generic.c +++ b/src/drivers/i2c/generic/generic.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/max98927/max98927.c b/src/drivers/i2c/max98927/max98927.c index a3e6661a00..976c2f259a 100644 --- a/src/drivers/i2c/max98927/max98927.c +++ b/src/drivers/i2c/max98927/max98927.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/nau8825/nau8825.c b/src/drivers/i2c/nau8825/nau8825.c index a86eff41f3..42dd8478e6 100644 --- a/src/drivers/i2c/nau8825/nau8825.c +++ b/src/drivers/i2c/nau8825/nau8825.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/rx6110sa/rx6110sa.c b/src/drivers/i2c/rx6110sa/rx6110sa.c index 2c62f230bd..2402d59ebf 100644 --- a/src/drivers/i2c/rx6110sa/rx6110sa.c +++ b/src/drivers/i2c/rx6110sa/rx6110sa.c @@ -13,7 +13,7 @@ * GNU General Public License for more details. */ -#include +#include #include #include #include diff --git a/src/drivers/i2c/tpm/chip.c b/src/drivers/i2c/tpm/chip.c index 1781e996e5..595a05cdbc 100644 --- a/src/drivers/i2c/tpm/chip.c +++ b/src/drivers/i2c/tpm/chip.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/tpm/chip.h b/src/drivers/i2c/tpm/chip.h index 83df998c96..5abd3a94f3 100644 --- a/src/drivers/i2c/tpm/chip.h +++ b/src/drivers/i2c/tpm/chip.h @@ -1,5 +1,5 @@ #include -#include +#include struct drivers_i2c_tpm_config { const char *hid; /* ACPI _HID (required) */ diff --git a/src/drivers/i2c/tpm/cr50.c b/src/drivers/i2c/tpm/cr50.c index 3505dcec1d..baf5fe0cce 100644 --- a/src/drivers/i2c/tpm/cr50.c +++ b/src/drivers/i2c/tpm/cr50.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/tpm/tis.c b/src/drivers/i2c/tpm/tis.c index 7cdb2a23b5..20c2d7136a 100644 --- a/src/drivers/i2c/tpm/tis.c +++ b/src/drivers/i2c/tpm/tis.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/tpm/tis_atmel.c b/src/drivers/i2c/tpm/tis_atmel.c index b6e13513f3..151209974a 100644 --- a/src/drivers/i2c/tpm/tis_atmel.c +++ b/src/drivers/i2c/tpm/tis_atmel.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/tpm/tpm.c b/src/drivers/i2c/tpm/tpm.c index 1b078f4c19..2ce04018b3 100644 --- a/src/drivers/i2c/tpm/tpm.c +++ b/src/drivers/i2c/tpm/tpm.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/i2c/ww_ring/ww_ring.c b/src/drivers/i2c/ww_ring/ww_ring.c index 5fb593c727..61dfae7dcf 100644 --- a/src/drivers/i2c/ww_ring/ww_ring.c +++ b/src/drivers/i2c/ww_ring/ww_ring.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include "drivers/i2c/ww_ring/ww_ring_programs.h" diff --git a/src/drivers/intel/mipi_camera/camera.c b/src/drivers/intel/mipi_camera/camera.c index 7752f0aff3..00ffad903f 100644 --- a/src/drivers/intel/mipi_camera/camera.c +++ b/src/drivers/intel/mipi_camera/camera.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/drivers/maxim/max77686/max77686.c b/src/drivers/maxim/max77686/max77686.c index d806484ded..f1ee32f4fe 100644 --- a/src/drivers/maxim/max77686/max77686.c +++ b/src/drivers/maxim/max77686/max77686.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include "max77686.h" diff --git a/src/drivers/parade/ps8625/ps8625.c b/src/drivers/parade/ps8625/ps8625.c index 3943b8455d..3e90cbb3e4 100644 --- a/src/drivers/parade/ps8625/ps8625.c +++ b/src/drivers/parade/ps8625/ps8625.c @@ -13,7 +13,7 @@ * GNU General Public License for more details. */ -#include +#include #include #include diff --git a/src/drivers/parade/ps8640/ps8640.c b/src/drivers/parade/ps8640/ps8640.c index 62bbf635b8..c8f414002a 100644 --- a/src/drivers/parade/ps8640/ps8640.c +++ b/src/drivers/parade/ps8640/ps8640.c @@ -14,7 +14,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/drivers/ti/tps65090/tps65090.c b/src/drivers/ti/tps65090/tps65090.c index 58bb3ce95d..6eae6fb1ae 100644 --- a/src/drivers/ti/tps65090/tps65090.c +++ b/src/drivers/ti/tps65090/tps65090.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include "tps65090.h" /* TPS65090 register addresses */ diff --git a/src/drivers/ti/tps65913/tps65913rtc.c b/src/drivers/ti/tps65913/tps65913rtc.c index f6fed9822b..0c19b160bf 100644 --- a/src/drivers/ti/tps65913/tps65913rtc.c +++ b/src/drivers/ti/tps65913/tps65913rtc.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/src/drivers/xpowers/axp209/axp209.c b/src/drivers/xpowers/axp209/axp209.c index de11fbe1bd..da575ccffd 100644 --- a/src/drivers/xpowers/axp209/axp209.c +++ b/src/drivers/xpowers/axp209/axp209.c @@ -13,7 +13,7 @@ #include #include -#include +#include /* Hide these definitions from the rest of the source, so keep them here */ enum registers { diff --git a/src/ec/google/chromeec/ec_i2c.c b/src/ec/google/chromeec/ec_i2c.c index 40bd0bb219..22b491ace3 100644 --- a/src/ec/google/chromeec/ec_i2c.c +++ b/src/ec/google/chromeec/ec_i2c.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/include/device/i2c.h b/src/include/device/i2c.h index 9939bc60bf..d6ee15aa5a 100644 --- a/src/include/device/i2c.h +++ b/src/include/device/i2c.h @@ -17,7 +17,6 @@ #define _DEVICE_I2C_H_ #include -#include /** * struct i2c_msg - an I2C transaction segment beginning with START @@ -67,162 +66,4 @@ enum i2c_address_mode { I2C_MODE_10_BIT }; - -int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, - int count); - -#define SOFTWARE_I2C_MAX_BUS 10 /* increase as necessary */ - -struct software_i2c_ops { - void (*set_sda)(unsigned int bus, int high); - void (*set_scl)(unsigned int bus, int high); - int (*get_sda)(unsigned int bus); - int (*get_scl)(unsigned int bus); -}; - -extern struct software_i2c_ops *software_i2c[]; - -int software_i2c_transfer(unsigned int bus, struct i2c_msg *segments, - int count); -void software_i2c_wedge_ack(unsigned int bus, u8 slave); -void software_i2c_wedge_read(unsigned int bus, u8 slave, u8 reg, int bit_count); -void software_i2c_wedge_write(unsigned int bus, u8 slave, u8 reg, - int bit_count); - -int i2c_read_field(unsigned int bus, uint8_t slave, uint8_t reg, uint8_t *data, - uint8_t mask, uint8_t shift); -int i2c_write_field(unsigned int bus, uint8_t slave, uint8_t reg, uint8_t data, - uint8_t mask, uint8_t shift); - -/* - * software_i2c is supposed to be a debug feature. It's usually not compiled in, - * but when it is it can be dynamically enabled at runtime for certain busses. - * Need this ugly stub to arbitrate since I2C device drivers hardcode - * 'i2c_transfer()' as their entry point. - */ -static inline int i2c_transfer(unsigned int bus, struct i2c_msg *segments, - int count) -{ - if (CONFIG_SOFTWARE_I2C) - if (bus < SOFTWARE_I2C_MAX_BUS && software_i2c[bus]) - return software_i2c_transfer(bus, segments, count); - - return platform_i2c_transfer(bus, segments, count); -} - -/* - * Read a raw chunk of data in one segment and one frame. - * - * [start][slave addr][r][data][stop] - */ -static inline int i2c_read_raw(unsigned int bus, uint8_t slave, uint8_t *data, - int len) -{ - struct i2c_msg seg = { - .flags = I2C_M_RD, .slave = slave, .buf = data, .len = len - }; - - return i2c_transfer(bus, &seg, 1); -} - -/* - * Write a raw chunk of data in one segment and one frame. - * - * [start][slave addr][w][data][stop] - */ -static inline int i2c_write_raw(unsigned int bus, uint8_t slave, uint8_t *data, - int len) -{ - struct i2c_msg seg = { - .flags = 0, .slave = slave, .buf = data, .len = len - }; - - return i2c_transfer(bus, &seg, 1); -} - -/** - * Read multi-bytes with two segments in one frame - * - * [start][slave addr][w][register addr][start][slave addr][r][data...][stop] - */ -static inline int i2c_read_bytes(unsigned int bus, uint8_t slave, uint8_t reg, - uint8_t *data, int len) -{ - struct i2c_msg seg[2]; - - seg[0].flags = 0; - seg[0].slave = slave; - seg[0].buf = ® - seg[0].len = 1; - seg[1].flags = I2C_M_RD; - seg[1].slave = slave; - seg[1].buf = data; - seg[1].len = len; - - return i2c_transfer(bus, seg, ARRAY_SIZE(seg)); -} - -/** - * Read a byte with two segments in one frame - * - * [start][slave addr][w][register addr][start][slave addr][r][data][stop] - */ -static inline int i2c_readb(unsigned int bus, uint8_t slave, uint8_t reg, - uint8_t *data) -{ - struct i2c_msg seg[2]; - - seg[0].flags = 0; - seg[0].slave = slave; - seg[0].buf = ® - seg[0].len = 1; - seg[1].flags = I2C_M_RD; - seg[1].slave = slave; - seg[1].buf = data; - seg[1].len = 1; - - return i2c_transfer(bus, seg, ARRAY_SIZE(seg)); -} - -/** - * Write a byte with one segment in one frame. - * - * [start][slave addr][w][register addr][data][stop] - */ -static inline int i2c_writeb(unsigned int bus, uint8_t slave, uint8_t reg, - uint8_t data) -{ - struct i2c_msg seg; - uint8_t buf[] = {reg, data}; - - seg.flags = 0; - seg.slave = slave; - seg.buf = buf; - seg.len = ARRAY_SIZE(buf); - - return i2c_transfer(bus, &seg, 1); -} - -/* I2C bus operation for ramstage drivers */ -struct device; -struct i2c_bus_operations { - /* - * This is an SOC specific method that can be provided to translate the - * 'struct device' for an I2C controller into a unique I2C bus number. - * Returns -1 if the bus number for this device cannot be determined. - */ - int (*dev_to_bus)(struct device *dev); -}; - -/* Return I2C bus number for provided device, -1 if not found */ -int i2c_dev_find_bus(struct device *dev); - -/* Variants of I2C helper functions that take a device instead of bus number */ -int i2c_dev_transfer(struct device *dev, struct i2c_msg *segments, int count); -int i2c_dev_readb(struct device *dev, uint8_t reg, uint8_t *data); -int i2c_dev_writeb(struct device *dev, uint8_t reg, uint8_t data); -int i2c_dev_read_bytes(struct device *dev, uint8_t reg, uint8_t *data, int len); -int i2c_dev_read_raw(struct device *dev, uint8_t *data, int len); -int i2c_dev_write_raw(struct device *dev, uint8_t *data, int len); - #endif /* _DEVICE_I2C_H_ */ diff --git a/src/include/device/i2c_bus.h b/src/include/device/i2c_bus.h new file mode 100644 index 0000000000..474d9e5b2c --- /dev/null +++ b/src/include/device/i2c_bus.h @@ -0,0 +1,44 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2014 Google, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _DEVICE_I2C_BUS_H_ +#define _DEVICE_I2C_BUS_H_ + +#include +#include +#include + +/* I2C bus operation for ramstage drivers */ +struct i2c_bus_operations { + /* + * This is an SOC specific method that can be provided to translate the + * 'struct device' for an I2C controller into a unique I2C bus number. + * Returns -1 if the bus number for this device cannot be determined. + */ + int (*dev_to_bus)(struct device *dev); +}; + +/* Return I2C bus number for provided device, -1 if not found */ +int i2c_dev_find_bus(struct device *dev); + +/* Variants of I2C helper functions that take a device instead of bus number */ +int i2c_dev_transfer(struct device *dev, struct i2c_msg *segments, int count); +int i2c_dev_readb(struct device *dev, uint8_t reg, uint8_t *data); +int i2c_dev_writeb(struct device *dev, uint8_t reg, uint8_t data); +int i2c_dev_read_bytes(struct device *dev, uint8_t reg, uint8_t *data, int len); +int i2c_dev_read_raw(struct device *dev, uint8_t *data, int len); +int i2c_dev_write_raw(struct device *dev, uint8_t *data, int len); + +#endif /* _DEVICE_I2C_BUS_H_ */ diff --git a/src/include/device/i2c_simple.h b/src/include/device/i2c_simple.h new file mode 100644 index 0000000000..dcde601994 --- /dev/null +++ b/src/include/device/i2c_simple.h @@ -0,0 +1,157 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2014 Google, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _DEVICE_I2C_SIMPLE_H_ +#define _DEVICE_I2C_SIMPLE_H_ + +#include +#include + +int platform_i2c_transfer(unsigned int bus, struct i2c_msg *segments, + int count); + +#define SOFTWARE_I2C_MAX_BUS 10 /* increase as necessary */ + +struct software_i2c_ops { + void (*set_sda)(unsigned int bus, int high); + void (*set_scl)(unsigned int bus, int high); + int (*get_sda)(unsigned int bus); + int (*get_scl)(unsigned int bus); +}; + +extern struct software_i2c_ops *software_i2c[]; + +int software_i2c_transfer(unsigned int bus, struct i2c_msg *segments, + int count); +void software_i2c_wedge_ack(unsigned int bus, u8 slave); +void software_i2c_wedge_read(unsigned int bus, u8 slave, u8 reg, int bit_count); +void software_i2c_wedge_write(unsigned int bus, u8 slave, u8 reg, + int bit_count); + +int i2c_read_field(unsigned int bus, uint8_t slave, uint8_t reg, uint8_t *data, + uint8_t mask, uint8_t shift); +int i2c_write_field(unsigned int bus, uint8_t slave, uint8_t reg, uint8_t data, + uint8_t mask, uint8_t shift); + +/* + * software_i2c is supposed to be a debug feature. It's usually not compiled in, + * but when it is it can be dynamically enabled at runtime for certain busses. + * Need this ugly stub to arbitrate since I2C device drivers hardcode + * 'i2c_transfer()' as their entry point. + */ +static inline int i2c_transfer(unsigned int bus, struct i2c_msg *segments, + int count) +{ + if (CONFIG_SOFTWARE_I2C) + if (bus < SOFTWARE_I2C_MAX_BUS && software_i2c[bus]) + return software_i2c_transfer(bus, segments, count); + + return platform_i2c_transfer(bus, segments, count); +} + +/* + * Read a raw chunk of data in one segment and one frame. + * + * [start][slave addr][r][data][stop] + */ +static inline int i2c_read_raw(unsigned int bus, uint8_t slave, uint8_t *data, + int len) +{ + struct i2c_msg seg = { + .flags = I2C_M_RD, .slave = slave, .buf = data, .len = len + }; + + return i2c_transfer(bus, &seg, 1); +} + +/* + * Write a raw chunk of data in one segment and one frame. + * + * [start][slave addr][w][data][stop] + */ +static inline int i2c_write_raw(unsigned int bus, uint8_t slave, uint8_t *data, + int len) +{ + struct i2c_msg seg = { + .flags = 0, .slave = slave, .buf = data, .len = len + }; + + return i2c_transfer(bus, &seg, 1); +} + +/** + * Read multi-bytes with two segments in one frame + * + * [start][slave addr][w][register addr][start][slave addr][r][data...][stop] + */ +static inline int i2c_read_bytes(unsigned int bus, uint8_t slave, uint8_t reg, + uint8_t *data, int len) +{ + struct i2c_msg seg[2]; + + seg[0].flags = 0; + seg[0].slave = slave; + seg[0].buf = ® + seg[0].len = 1; + seg[1].flags = I2C_M_RD; + seg[1].slave = slave; + seg[1].buf = data; + seg[1].len = len; + + return i2c_transfer(bus, seg, ARRAY_SIZE(seg)); +} + +/** + * Read a byte with two segments in one frame + * + * [start][slave addr][w][register addr][start][slave addr][r][data][stop] + */ +static inline int i2c_readb(unsigned int bus, uint8_t slave, uint8_t reg, + uint8_t *data) +{ + struct i2c_msg seg[2]; + + seg[0].flags = 0; + seg[0].slave = slave; + seg[0].buf = ® + seg[0].len = 1; + seg[1].flags = I2C_M_RD; + seg[1].slave = slave; + seg[1].buf = data; + seg[1].len = 1; + + return i2c_transfer(bus, seg, ARRAY_SIZE(seg)); +} + +/** + * Write a byte with one segment in one frame. + * + * [start][slave addr][w][register addr][data][stop] + */ +static inline int i2c_writeb(unsigned int bus, uint8_t slave, uint8_t reg, + uint8_t data) +{ + struct i2c_msg seg; + uint8_t buf[] = {reg, data}; + + seg.flags = 0; + seg.slave = slave; + seg.buf = buf; + seg.len = ARRAY_SIZE(buf); + + return i2c_transfer(bus, &seg, 1); +} + +#endif /* _DEVICE_I2C_SIMPLE_H_ */ diff --git a/src/mainboard/google/daisy/mainboard.c b/src/mainboard/google/daisy/mainboard.c index e67bdcfe09..336a9e5f4a 100644 --- a/src/mainboard/google/daisy/mainboard.c +++ b/src/mainboard/google/daisy/mainboard.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/daisy/romstage.c b/src/mainboard/google/daisy/romstage.c index 3c6ff5ebef..33efdf7cba 100644 --- a/src/mainboard/google/daisy/romstage.c +++ b/src/mainboard/google/daisy/romstage.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/foster/bootblock.c b/src/mainboard/google/foster/bootblock.c index a4449f54ed..e986ee3c1c 100644 --- a/src/mainboard/google/foster/bootblock.c +++ b/src/mainboard/google/foster/bootblock.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/foster/pmic.c b/src/mainboard/google/foster/pmic.c index 2eeccb2241..b73983b614 100644 --- a/src/mainboard/google/foster/pmic.c +++ b/src/mainboard/google/foster/pmic.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/mainboard/google/gru/mainboard.c b/src/mainboard/google/gru/mainboard.c index 240a5493e8..77c185cb3d 100644 --- a/src/mainboard/google/gru/mainboard.c +++ b/src/mainboard/google/gru/mainboard.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/nyan/bootblock.c b/src/mainboard/google/nyan/bootblock.c index 98c6fb963e..92c0e1a443 100644 --- a/src/mainboard/google/nyan/bootblock.c +++ b/src/mainboard/google/nyan/bootblock.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/nyan/pmic.c b/src/mainboard/google/nyan/pmic.c index 5c56cbe36b..f115586b0f 100644 --- a/src/mainboard/google/nyan/pmic.c +++ b/src/mainboard/google/nyan/pmic.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/nyan_big/bootblock.c b/src/mainboard/google/nyan_big/bootblock.c index c10af7173a..dcc18146ea 100644 --- a/src/mainboard/google/nyan_big/bootblock.c +++ b/src/mainboard/google/nyan_big/bootblock.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/nyan_big/pmic.c b/src/mainboard/google/nyan_big/pmic.c index 2436febc87..77b6545341 100644 --- a/src/mainboard/google/nyan_big/pmic.c +++ b/src/mainboard/google/nyan_big/pmic.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/nyan_blaze/bootblock.c b/src/mainboard/google/nyan_blaze/bootblock.c index c10af7173a..dcc18146ea 100644 --- a/src/mainboard/google/nyan_blaze/bootblock.c +++ b/src/mainboard/google/nyan_blaze/bootblock.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/nyan_blaze/pmic.c b/src/mainboard/google/nyan_blaze/pmic.c index 2436febc87..77b6545341 100644 --- a/src/mainboard/google/nyan_blaze/pmic.c +++ b/src/mainboard/google/nyan_blaze/pmic.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/peach_pit/mainboard.c b/src/mainboard/google/peach_pit/mainboard.c index 4cc72f1ceb..14d3e2f51e 100644 --- a/src/mainboard/google/peach_pit/mainboard.c +++ b/src/mainboard/google/peach_pit/mainboard.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/peach_pit/romstage.c b/src/mainboard/google/peach_pit/romstage.c index 2bcf83672e..1268df2689 100644 --- a/src/mainboard/google/peach_pit/romstage.c +++ b/src/mainboard/google/peach_pit/romstage.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/smaug/bootblock.c b/src/mainboard/google/smaug/bootblock.c index 783705dffe..fd5d293b6c 100644 --- a/src/mainboard/google/smaug/bootblock.c +++ b/src/mainboard/google/smaug/bootblock.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/smaug/mainboard.c b/src/mainboard/google/smaug/mainboard.c index 8c445d8365..c783ca4727 100644 --- a/src/mainboard/google/smaug/mainboard.c +++ b/src/mainboard/google/smaug/mainboard.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/smaug/pmic.c b/src/mainboard/google/smaug/pmic.c index 25e870a123..77de277afa 100644 --- a/src/mainboard/google/smaug/pmic.c +++ b/src/mainboard/google/smaug/pmic.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/mainboard/google/smaug/romstage.c b/src/mainboard/google/smaug/romstage.c index 213fad7437..fd7c07f84d 100644 --- a/src/mainboard/google/smaug/romstage.c +++ b/src/mainboard/google/smaug/romstage.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/veyron/mainboard.c b/src/mainboard/google/veyron/mainboard.c index a6bbf881e3..15e2a574e8 100644 --- a/src/mainboard/google/veyron/mainboard.c +++ b/src/mainboard/google/veyron/mainboard.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/veyron_mickey/mainboard.c b/src/mainboard/google/veyron_mickey/mainboard.c index ef085b2f07..26fcbb9467 100644 --- a/src/mainboard/google/veyron_mickey/mainboard.c +++ b/src/mainboard/google/veyron_mickey/mainboard.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/google/veyron_rialto/mainboard.c b/src/mainboard/google/veyron_rialto/mainboard.c index b9b6a2225a..91bf46a526 100644 --- a/src/mainboard/google/veyron_rialto/mainboard.c +++ b/src/mainboard/google/veyron_rialto/mainboard.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/intel/galileo/reg_access.c b/src/mainboard/intel/galileo/reg_access.c index c595dffba7..cff69aba4a 100644 --- a/src/mainboard/intel/galileo/reg_access.c +++ b/src/mainboard/intel/galileo/reg_access.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include "reg_access.h" diff --git a/src/mainboard/intel/galileo/vboot.c b/src/mainboard/intel/galileo/vboot.c index 90d8f0a93e..ffea7698b0 100644 --- a/src/mainboard/intel/galileo/vboot.c +++ b/src/mainboard/intel/galileo/vboot.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mainboard/intel/kblrvp/ramstage.c b/src/mainboard/intel/kblrvp/ramstage.c index d733341f4a..1e6aa1141b 100644 --- a/src/mainboard/intel/kblrvp/ramstage.c +++ b/src/mainboard/intel/kblrvp/ramstage.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/src/mainboard/siemens/mc_apl1/ptn3460.c b/src/mainboard/siemens/mc_apl1/ptn3460.c index 7fc5507356..1877e8b9fa 100644 --- a/src/mainboard/siemens/mc_apl1/ptn3460.c +++ b/src/mainboard/siemens/mc_apl1/ptn3460.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "ptn3460.h" /** diff --git a/src/soc/broadcom/cygnus/i2c.c b/src/soc/broadcom/cygnus/i2c.c index bc43a8886f..ac431e734a 100644 --- a/src/soc/broadcom/cygnus/i2c.c +++ b/src/soc/broadcom/cygnus/i2c.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include struct cygnus_i2c_regs { diff --git a/src/soc/intel/apollolake/chip.h b/src/soc/intel/apollolake/chip.h index 7b36089b3c..33e2dade88 100644 --- a/src/soc/intel/apollolake/chip.h +++ b/src/soc/intel/apollolake/chip.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/soc/intel/common/block/i2c/i2c.c b/src/soc/intel/common/block/i2c/i2c.c index f4b1e8c5ff..aeb6d8f2ed 100644 --- a/src/soc/intel/common/block/i2c/i2c.c +++ b/src/soc/intel/common/block/i2c/i2c.c @@ -14,7 +14,7 @@ */ #include -#include +#include #include #include #include diff --git a/src/soc/intel/common/block/i2c/i2c_early.c b/src/soc/intel/common/block/i2c/i2c_early.c index 7c9ce60513..74fc994ca3 100644 --- a/src/soc/intel/common/block/i2c/i2c_early.c +++ b/src/soc/intel/common/block/i2c/i2c_early.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/intel/common/block/i2c/lpss_i2c.c b/src/soc/intel/common/block/i2c/lpss_i2c.c index 711517f6d3..868a6ad300 100644 --- a/src/soc/intel/common/block/i2c/lpss_i2c.c +++ b/src/soc/intel/common/block/i2c/lpss_i2c.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/intel/common/block/include/intelblocks/lpss_i2c.h b/src/soc/intel/common/block/include/intelblocks/lpss_i2c.h index 2f60d654b1..033081f4b9 100644 --- a/src/soc/intel/common/block/include/intelblocks/lpss_i2c.h +++ b/src/soc/intel/common/block/include/intelblocks/lpss_i2c.h @@ -16,6 +16,7 @@ #ifndef SOC_INTEL_COMMON_BLOCK_LPSS_I2C_H #define SOC_INTEL_COMMON_BLOCK_LPSS_I2C_H +#include #include #include diff --git a/src/soc/intel/quark/gpio_i2c.c b/src/soc/intel/quark/gpio_i2c.c index 5580894ee1..d5543b803c 100644 --- a/src/soc/intel/quark/gpio_i2c.c +++ b/src/soc/intel/quark/gpio_i2c.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/intel/quark/i2c.c b/src/soc/intel/quark/i2c.c index e8dba5376f..2a194af768 100644 --- a/src/soc/intel/quark/i2c.c +++ b/src/soc/intel/quark/i2c.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/intel/skylake/chip.h b/src/soc/intel/skylake/chip.h index efd3566f76..ea985db11a 100644 --- a/src/soc/intel/skylake/chip.h +++ b/src/soc/intel/skylake/chip.h @@ -20,7 +20,7 @@ #define _SOC_CHIP_H_ #include -#include +#include #include #include #include diff --git a/src/soc/mediatek/mt8173/da9212.c b/src/soc/mediatek/mt8173/da9212.c index 8161667fa9..cc20979f50 100644 --- a/src/soc/mediatek/mt8173/da9212.c +++ b/src/soc/mediatek/mt8173/da9212.c @@ -14,7 +14,7 @@ */ #include -#include +#include #include enum { diff --git a/src/soc/mediatek/mt8173/i2c.c b/src/soc/mediatek/mt8173/i2c.c index 1d541e5d0f..9ca6803011 100644 --- a/src/soc/mediatek/mt8173/i2c.c +++ b/src/soc/mediatek/mt8173/i2c.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/soc/mediatek/mt8173/mt6311.c b/src/soc/mediatek/mt8173/mt6311.c index 8390dfd4d0..8f0b274cfa 100644 --- a/src/soc/mediatek/mt8173/mt6311.c +++ b/src/soc/mediatek/mt8173/mt6311.c @@ -14,7 +14,7 @@ */ #include -#include +#include #include enum { diff --git a/src/soc/nvidia/tegra/i2c.c b/src/soc/nvidia/tegra/i2c.c index e371a9d30f..7d3e0bff90 100644 --- a/src/soc/nvidia/tegra/i2c.c +++ b/src/soc/nvidia/tegra/i2c.c @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/nvidia/tegra/software_i2c.c b/src/soc/nvidia/tegra/software_i2c.c index fe2f61edbf..50aac8c45a 100644 --- a/src/soc/nvidia/tegra/software_i2c.c +++ b/src/soc/nvidia/tegra/software_i2c.c @@ -13,7 +13,7 @@ * GNU General Public License for more details. */ -#include +#include #include #include diff --git a/src/soc/nvidia/tegra124/dp.c b/src/soc/nvidia/tegra124/dp.c index 0132369073..d646e8ebdc 100644 --- a/src/soc/nvidia/tegra124/dp.c +++ b/src/soc/nvidia/tegra124/dp.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/nvidia/tegra210/dp.c b/src/soc/nvidia/tegra210/dp.c index 350eb8254d..119b4a74c8 100644 --- a/src/soc/nvidia/tegra210/dp.c +++ b/src/soc/nvidia/tegra210/dp.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/qualcomm/ipq40xx/i2c.c b/src/soc/qualcomm/ipq40xx/i2c.c index 0cffaacbb2..133f56435f 100644 --- a/src/soc/qualcomm/ipq40xx/i2c.c +++ b/src/soc/qualcomm/ipq40xx/i2c.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/qualcomm/ipq806x/i2c.c b/src/soc/qualcomm/ipq806x/i2c.c index 009cb94c1f..9660ec84d6 100644 --- a/src/soc/qualcomm/ipq806x/i2c.c +++ b/src/soc/qualcomm/ipq806x/i2c.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/rockchip/common/i2c.c b/src/soc/rockchip/common/i2c.c index 5847f1658f..09b56246fd 100644 --- a/src/soc/rockchip/common/i2c.c +++ b/src/soc/rockchip/common/i2c.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/rockchip/common/rk808.c b/src/soc/rockchip/common/rk808.c index a68b838f48..9b4708cfab 100644 --- a/src/soc/rockchip/common/rk808.c +++ b/src/soc/rockchip/common/rk808.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/rockchip/rk3288/software_i2c.c b/src/soc/rockchip/rk3288/software_i2c.c index 886e2d1e91..dbe058eea6 100644 --- a/src/soc/rockchip/rk3288/software_i2c.c +++ b/src/soc/rockchip/rk3288/software_i2c.c @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/soc/samsung/exynos5250/i2c.c b/src/soc/samsung/exynos5250/i2c.c index 6319a10b34..19ef667896 100644 --- a/src/soc/samsung/exynos5250/i2c.c +++ b/src/soc/samsung/exynos5250/i2c.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/soc/samsung/exynos5420/i2c.c b/src/soc/samsung/exynos5420/i2c.c index ae9560ffdd..dd5ffd20d0 100644 --- a/src/soc/samsung/exynos5420/i2c.c +++ b/src/soc/samsung/exynos5420/i2c.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include -- cgit v1.2.3