[U-Boot] [PATCH 2/2] WIP: tegra: i2c: Enable new CONFIG_SYS_I2C framework
Simon Glass
sjg at chromium.org
Tue Oct 30 18:28:53 CET 2012
(just for illustration, please don't merge)
This enables CONFIG_SYS_I2C on Tegra, updating existing boards and the Tegra
i2c driver to support this.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
drivers/i2c/i2c_core.c | 3 ++
drivers/i2c/tegra_i2c.c | 64 +++++++++++++++++--------------------------
include/configs/seaboard.h | 4 ++-
include/configs/trimslice.h | 4 ++-
include/configs/whistler.h | 4 ++-
5 files changed, 37 insertions(+), 42 deletions(-)
diff --git a/drivers/i2c/i2c_core.c b/drivers/i2c/i2c_core.c
index 5a738d5..44f1297 100644
--- a/drivers/i2c/i2c_core.c
+++ b/drivers/i2c/i2c_core.c
@@ -9,6 +9,9 @@
#ifdef CONFIG_SYS_I2C_SOFT
extern struct i2c_adapter soft_i2c_adap[];
#endif
+#ifdef CONFIG_TEGRA_I2C
+extern struct i2c_adapter tegra_i2c_adap[];
+#endif
struct i2c_adapter *i2c_adap[CONFIG_SYS_NUM_I2C_ADAPTERS] =
CONFIG_SYS_I2C_ADAPTERS;
diff --git a/drivers/i2c/tegra_i2c.c b/drivers/i2c/tegra_i2c.c
index 3e157f4..b92bcf1 100644
--- a/drivers/i2c/tegra_i2c.c
+++ b/drivers/i2c/tegra_i2c.c
@@ -35,8 +35,6 @@
DECLARE_GLOBAL_DATA_PTR;
-static unsigned int i2c_bus_num;
-
/* Information about i2c controller */
struct i2c_bus {
int id;
@@ -327,21 +325,11 @@ static struct i2c_bus *tegra_i2c_get_bus(unsigned int bus_num)
return bus;
}
-unsigned int i2c_get_bus_speed(void)
+static unsigned int tegra_i2c_set_bus_speed(unsigned int speed)
{
struct i2c_bus *bus;
- bus = tegra_i2c_get_bus(i2c_bus_num);
- if (!bus)
- return 0;
- return bus->speed;
-}
-
-int i2c_set_bus_speed(unsigned int speed)
-{
- struct i2c_bus *bus;
-
- bus = tegra_i2c_get_bus(i2c_bus_num);
+ bus = tegra_i2c_get_bus(i2c_get_bus_num());
if (!bus)
return 0;
bus->speed = speed;
@@ -450,7 +438,7 @@ void i2c_init_board(void)
return;
}
-void i2c_init(int speed, int slaveaddr)
+static void tegra_i2c_init(int speed, int slaveaddr)
{
/* This will override the speed selected in the fdt for that port */
debug("i2c_init(speed=%u, slaveaddr=0x%x)\n", speed, slaveaddr);
@@ -500,7 +488,7 @@ int i2c_read_data(struct i2c_bus *bus, uchar chip, uchar *buffer, int len)
}
/* Probe to see if a chip is present. */
-int i2c_probe(uchar chip)
+static int tegra_i2c_probe(uchar chip)
{
struct i2c_bus *bus;
int rc;
@@ -526,7 +514,8 @@ static int i2c_addr_ok(const uint addr, const int alen)
}
/* Read bytes */
-int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
+static int tegra_i2c_read(uchar chip, uint addr, int alen, uchar *buffer,
+ int len)
{
struct i2c_bus *bus;
uint offset;
@@ -534,7 +523,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
debug("i2c_read: chip=0x%x, addr=0x%x, len=0x%x\n",
chip, addr, len);
- bus = tegra_i2c_get_bus(i2c_bus_num);
+ bus = tegra_i2c_get_bus(i2c_get_bus_num());
if (!bus)
return 1;
if (!i2c_addr_ok(addr, alen)) {
@@ -564,7 +553,8 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
}
/* Write bytes */
-int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
+static int tegra_i2c_write(uchar chip, uint addr, int alen, uchar *buffer,
+ int len)
{
struct i2c_bus *bus;
uint offset;
@@ -572,7 +562,7 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
debug("i2c_write: chip=0x%x, addr=0x%x, len=0x%x\n",
chip, addr, len);
- bus = tegra_i2c_get_bus(i2c_bus_num);
+ bus = tegra_i2c_get_bus(i2c_get_bus_num());
if (!bus)
return 1;
if (!i2c_addr_ok(addr, alen)) {
@@ -593,25 +583,6 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
return 0;
}
-#if defined(CONFIG_I2C_MULTI_BUS)
-/*
- * Functions for multiple I2C bus handling
- */
-unsigned int i2c_get_bus_num(void)
-{
- return i2c_bus_num;
-}
-
-int i2c_set_bus_num(unsigned int bus)
-{
- if (bus >= TEGRA_I2C_NUM_CONTROLLERS || !i2c_controllers[bus].inited)
- return -1;
- i2c_bus_num = bus;
-
- return 0;
-}
-#endif
-
int tegra_i2c_get_dvc_bus_num(void)
{
int i;
@@ -625,3 +596,18 @@ int tegra_i2c_get_dvc_bus_num(void)
return -1;
}
+
+struct i2c_adapter tegra_i2c_adap[] = {
+ {
+ .init = tegra_i2c_init,
+ .probe = tegra_i2c_probe,
+ .read = tegra_i2c_read,
+ .write = tegra_i2c_write,
+ .set_bus_speed = tegra_i2c_set_bus_speed,
+ .speed = 100000,
+ .slaveaddr = 0,
+ .name = "tegra-i2c",
+ .init_done = 0,
+ .hwadapnr = 0,
+ }
+};
diff --git a/include/configs/seaboard.h b/include/configs/seaboard.h
index 0727a4c..61aca66 100644
--- a/include/configs/seaboard.h
+++ b/include/configs/seaboard.h
@@ -58,10 +58,12 @@
/* I2C */
#define CONFIG_TEGRA_I2C
#define CONFIG_SYS_I2C_INIT_BOARD
-#define CONFIG_I2C_MULTI_BUS
#define CONFIG_SYS_MAX_I2C_BUS 4
#define CONFIG_SYS_I2C_SPEED 100000
#define CONFIG_CMD_I2C
+#define CONFIG_SYS_I2C
+#define CONFIG_SYS_I2C_ADAPTERS {&tegra_i2c_adap[0]}
+#define CONFIG_SYS_NUM_I2C_ADAPTERS TEGRA_I2C_NUM_CONTROLLERS
/* SD/MMC */
#define CONFIG_MMC
diff --git a/include/configs/trimslice.h b/include/configs/trimslice.h
index eeb0dbe..333930b 100644
--- a/include/configs/trimslice.h
+++ b/include/configs/trimslice.h
@@ -56,10 +56,12 @@
/* I2C */
#define CONFIG_TEGRA_I2C
#define CONFIG_SYS_I2C_INIT_BOARD
-#define CONFIG_I2C_MULTI_BUS
#define CONFIG_SYS_MAX_I2C_BUS 4
#define CONFIG_SYS_I2C_SPEED 100000
#define CONFIG_CMD_I2C
+#define CONFIG_SYS_I2C
+#define CONFIG_SYS_I2C_ADAPTERS {&tegra_i2c_adap[0]}
+#define CONFIG_SYS_NUM_I2C_ADAPTERS TEGRA_I2C_NUM_CONTROLLERS
/* SD/MMC */
#define CONFIG_MMC
diff --git a/include/configs/whistler.h b/include/configs/whistler.h
index 1c7803b..22aff0b 100644
--- a/include/configs/whistler.h
+++ b/include/configs/whistler.h
@@ -48,10 +48,12 @@
/* I2C */
#define CONFIG_TEGRA_I2C
#define CONFIG_SYS_I2C_INIT_BOARD
-#define CONFIG_I2C_MULTI_BUS
#define CONFIG_SYS_MAX_I2C_BUS 4
#define CONFIG_SYS_I2C_SPEED 100000
#define CONFIG_CMD_I2C
+#define CONFIG_SYS_I2C
+#define CONFIG_SYS_I2C_ADAPTERS {&tegra_i2c_adap[0]}
+#define CONFIG_SYS_NUM_I2C_ADAPTERS TEGRA_I2C_NUM_CONTROLLERS
/* SD/MMC */
#define CONFIG_MMC
--
1.7.7.3
More information about the U-Boot
mailing list