summaryrefslogtreecommitdiff
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/Kconfig2
-rw-r--r--drivers/i2c/Makefile2
-rw-r--r--drivers/i2c/i2c-emul-uclass.c34
-rw-r--r--drivers/i2c/i2c-gpio.c19
4 files changed, 28 insertions, 29 deletions
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 1844941eb21..57a4efb88ed 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -479,7 +479,7 @@ config SYS_I2C_UNIPHIER_F
config SYS_I2C_VERSATILE
bool "Arm Ltd Versatile I2C bus driver"
- depends on DM_I2C && (TARGET_VEXPRESS_CA15_TC2 || TARGET_VEXPRESS64_JUNO)
+ depends on DM_I2C && TARGET_VEXPRESS64_JUNO
help
Add support for the Arm Ltd Versatile Express I2C driver. The I2C host
controller is present in the development boards manufactured by Arm Ltd.
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index acd27ac29d2..8c9f1fcd8b9 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -39,9 +39,7 @@ obj-$(CONFIG_SYS_I2C_RCAR_I2C) += rcar_i2c.o
obj-$(CONFIG_SYS_I2C_RCAR_IIC) += rcar_iic.o
obj-$(CONFIG_SYS_I2C_ROCKCHIP) += rk_i2c.o
obj-$(CONFIG_SYS_I2C_S3C24X0) += s3c24x0_i2c.o exynos_hs_i2c.o
-ifndef CONFIG_SPL_BUILD
obj-$(CONFIG_SYS_I2C_SANDBOX) += sandbox_i2c.o i2c-emul-uclass.o
-endif
obj-$(CONFIG_SYS_I2C_SH) += sh_i2c.o
obj-$(CONFIG_SYS_I2C_SOFT) += soft_i2c.o
obj-$(CONFIG_SYS_I2C_STM32F7) += stm32f7_i2c.o
diff --git a/drivers/i2c/i2c-emul-uclass.c b/drivers/i2c/i2c-emul-uclass.c
index 085b824e895..7917b63c55b 100644
--- a/drivers/i2c/i2c-emul-uclass.c
+++ b/drivers/i2c/i2c-emul-uclass.c
@@ -7,6 +7,7 @@
#include <dm.h>
#include <i2c.h>
#include <log.h>
+#include <asm/i2c.h>
#include <dm/device-internal.h>
#include <dm/uclass-internal.h>
@@ -23,18 +24,6 @@
* uclass so avoid having strange devices on the I2C bus.
*/
-/**
- * struct i2c_emul_uc_plat - information about the emulator for this device
- *
- * This is used by devices in UCLASS_I2C_EMUL to record information about the
- * device being emulated. It is accessible with dev_get_uclass_plat()
- *
- * @dev: Device being emulated
- */
-struct i2c_emul_uc_plat {
- struct udevice *dev;
-};
-
struct udevice *i2c_emul_get_device(struct udevice *emul)
{
struct i2c_emul_uc_plat *uc_plat = dev_get_uclass_plat(emul);
@@ -42,14 +31,27 @@ struct udevice *i2c_emul_get_device(struct udevice *emul)
return uc_plat->dev;
}
+void i2c_emul_set_idx(struct udevice *dev, int emul_idx)
+{
+ struct dm_i2c_chip *plat = dev_get_parent_plat(dev);
+
+ plat->emul_idx = emul_idx;
+}
+
int i2c_emul_find(struct udevice *dev, struct udevice **emulp)
{
struct i2c_emul_uc_plat *uc_plat;
struct udevice *emul;
int ret;
- ret = uclass_find_device_by_phandle(UCLASS_I2C_EMUL, dev,
- "sandbox,emul", &emul);
+ if (!CONFIG_IS_ENABLED(OF_PLATDATA)) {
+ ret = uclass_find_device_by_phandle(UCLASS_I2C_EMUL, dev,
+ "sandbox,emul", &emul);
+ } else {
+ struct dm_i2c_chip *plat = dev_get_parent_plat(dev);
+
+ ret = device_get_by_ofplat_idx(plat->emul_idx, &emul);
+ }
if (ret) {
log_err("No emulators for device '%s'\n", dev->name);
return ret;
@@ -85,8 +87,8 @@ static const struct udevice_id i2c_emul_parent_ids[] = {
{ }
};
-U_BOOT_DRIVER(i2c_emul_parent_drv) = {
- .name = "i2c_emul_parent_drv",
+U_BOOT_DRIVER(sandbox_i2c_emul_parent) = {
+ .name = "sandbox_i2c_emul_parent",
.id = UCLASS_I2C_EMUL_PARENT,
.of_match = i2c_emul_parent_ids,
};
diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c
index a301a4460b3..cf8f8f40359 100644
--- a/drivers/i2c/i2c-gpio.c
+++ b/drivers/i2c/i2c-gpio.c
@@ -48,12 +48,13 @@ static int i2c_gpio_sda_get(struct i2c_gpio_bus *bus)
static void i2c_gpio_sda_set(struct i2c_gpio_bus *bus, int bit)
{
struct gpio_desc *sda = &bus->gpios[PIN_SDA];
+ ulong flags;
if (bit)
- sda->flags = (sda->flags & ~GPIOD_IS_OUT) | GPIOD_IS_IN;
+ flags = GPIOD_IS_IN;
else
- sda->flags = (sda->flags & (~GPIOD_IS_IN & ~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
- dm_gpio_set_dir(sda);
+ flags = GPIOD_IS_OUT;
+ dm_gpio_clrset_flags(sda, GPIOD_MASK_DIR, flags);
}
static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int bit)
@@ -62,16 +63,14 @@ static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int bit)
int count = 0;
if (bit) {
- scl->flags = (scl->flags & ~GPIOD_IS_OUT) | GPIOD_IS_IN;
- dm_gpio_set_dir(scl);
+ dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, GPIOD_IS_IN);
while (!dm_gpio_get_value(scl) && count++ < 100000)
udelay(1);
if (!dm_gpio_get_value(scl))
pr_err("timeout waiting on slave to release scl\n");
} else {
- scl->flags = (scl->flags & (~GPIOD_IS_IN & ~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
- dm_gpio_set_dir(scl);
+ dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, GPIOD_IS_OUT);
}
}
@@ -79,11 +78,11 @@ static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int bit)
static void i2c_gpio_scl_set_output_only(struct i2c_gpio_bus *bus, int bit)
{
struct gpio_desc *scl = &bus->gpios[PIN_SCL];
- scl->flags = (scl->flags & (~GPIOD_IS_IN & ~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
+ ulong flags = GPIOD_IS_OUT;
if (bit)
- scl->flags |= GPIOD_IS_OUT_ACTIVE;
- dm_gpio_set_dir(scl);
+ flags |= GPIOD_IS_OUT_ACTIVE;
+ dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, flags);
}
static void i2c_gpio_write_bit(struct i2c_gpio_bus *bus, int delay, uchar bit)