]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tegra: i2c: Enable new CONFIG_SYS_I2C framework
authorSimon Glass <sjg@chromium.org>
Tue, 30 Oct 2012 07:28:53 +0000 (07:28 +0000)
committerHeiko Schocher <hs@denx.de>
Tue, 23 Jul 2013 06:34:55 +0000 (08:34 +0200)
This enables CONFIG_SYS_I2C on Tegra, updating existing boards and the Tegra
i2c driver to support this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Heiko Schocher <hs@denx.de>
README
board/nvidia/common/board.c
drivers/i2c/Makefile
drivers/i2c/tegra_i2c.c
include/configs/beaver.h
include/configs/cardhu.h
include/configs/dalmore.h
include/configs/seaboard.h
include/configs/tegra-common-post.h
include/configs/trimslice.h
include/configs/whistler.h

diff --git a/README b/README
index f00e41b9adbf04a6bd7c6a112c5bc1acb0ada3fb..c67106d9ade64599682cb33b6e30841cdc3b0826 100644 (file)
--- a/README
+++ b/README
@@ -1980,6 +1980,11 @@ CBFS (Coreboot Filesystem) support
                    CONFIG_SYS_FSL_I2C2_SLAVE for the slave address of the
                    second bus.
 
+               - drivers/i2c/tegra_i2c.c:
+                - activate this driver with CONFIG_SYS_I2C_TEGRA
+                - This driver adds 4 i2c buses with a fix speed from
+                  100000 and the slave addr 0!
+
                additional defines:
 
                CONFIG_SYS_NUM_I2C_BUSES
index f60f21f39f1103517bdd5c70d7d63e53a5105ac1..4cb65c12c0be5124be74129f7911e4a358906630 100644 (file)
@@ -151,7 +151,7 @@ int board_init(void)
 
        power_det_init();
 
-#ifdef CONFIG_TEGRA_I2C
+#ifdef CONFIG_SYS_I2C_TEGRA
 #ifndef CONFIG_SYS_I2C_INIT_BOARD
 #error "You must define CONFIG_SYS_I2C_INIT_BOARD to use i2c on Nvidia boards"
 #endif
@@ -165,7 +165,7 @@ int board_init(void)
                debug("Memory controller init failed: %d\n", err);
 #  endif
 # endif /* CONFIG_TEGRA_PMU */
-#endif /* CONFIG_TEGRA_I2C */
+#endif /* CONFIG_SYS_I2C_TEGRA */
 
 #ifdef CONFIG_USB_EHCI_TEGRA
        pin_mux_usb();
index 1202d2454e20a39049e1d30e3782f0a75d9ef768..e1da58d7bc1677555d263aa80ae589556e8a7961 100644 (file)
@@ -39,7 +39,6 @@ COBJS-$(CONFIG_PCA9564_I2C) += pca9564_i2c.o
 COBJS-$(CONFIG_PPC4XX_I2C) += ppc4xx_i2c.o
 COBJS-$(CONFIG_DRIVER_S3C24X0_I2C) += s3c24x0_i2c.o
 COBJS-$(CONFIG_S3C44B0_I2C) += s3c44b0_i2c.o
-COBJS-$(CONFIG_TEGRA_I2C) += tegra_i2c.o
 COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
 COBJS-$(CONFIG_U8500_I2C) += u8500_i2c.o
 COBJS-$(CONFIG_SH_I2C) += sh_i2c.o
@@ -47,6 +46,7 @@ COBJS-$(CONFIG_SH_SH7734_I2C) += sh_sh7734_i2c.o
 COBJS-$(CONFIG_SYS_I2C) += i2c_core.o
 COBJS-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o
 COBJS-$(CONFIG_SYS_I2C_SOFT) += soft_i2c.o
+COBJS-$(CONFIG_SYS_I2C_TEGRA) += tegra_i2c.o
 COBJS-$(CONFIG_ZYNQ_I2C) += zynq_i2c.o
 
 COBJS  := $(COBJS-y)
index 8fa1cdac0252fe79d8f281384ba80a6a28583237..9bf71a689f1f8d8b19e697186384e6b0b0fbaa8e 100644 (file)
@@ -35,8 +35,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static unsigned int i2c_bus_num;
-
 /* Information about i2c controller */
 struct i2c_bus {
        int                     id;
@@ -332,38 +330,25 @@ static int tegra_i2c_read_data(struct i2c_bus *bus, u32 addr, u8 *data,
  * @param bus_num      Bus number to check / return
  * @return pointer to bus, if valid, else NULL
  */
-static struct i2c_bus *tegra_i2c_get_bus(unsigned int bus_num)
+static struct i2c_bus *tegra_i2c_get_bus(struct i2c_adapter *adap)
 {
        struct i2c_bus *bus;
 
-       if (bus_num >= TEGRA_I2C_NUM_CONTROLLERS) {
-               debug("%s: Invalid bus number %u\n", __func__, bus_num);
-               return NULL;
-       }
-       bus = &i2c_controllers[bus_num];
+       bus = &i2c_controllers[adap->hwadapnr];
        if (!bus->inited) {
-               debug("%s: Bus %u not available\n", __func__, bus_num);
+               debug("%s: Bus %u not available\n", __func__, adap->hwadapnr);
                return NULL;
        }
 
        return bus;
 }
 
-unsigned int i2c_get_bus_speed(void)
-{
-       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)
+static unsigned int tegra_i2c_set_bus_speed(struct i2c_adapter *adap,
+                       unsigned int speed)
 {
        struct i2c_bus *bus;
 
-       bus = tegra_i2c_get_bus(i2c_bus_num);
+       bus = tegra_i2c_get_bus(adap);
        if (!bus)
                return 0;
        bus->speed = speed;
@@ -482,7 +467,7 @@ void i2c_init_board(void)
                return;
 }
 
-void i2c_init(int speed, int slaveaddr)
+static void tegra_i2c_init(struct i2c_adapter *adap, 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);
@@ -532,14 +517,14 @@ 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(struct i2c_adapter *adap, uchar chip)
 {
        struct i2c_bus *bus;
        int rc;
        uchar reg;
 
        debug("i2c_probe: addr=0x%x\n", chip);
-       bus = tegra_i2c_get_bus(i2c_get_bus_num());
+       bus = tegra_i2c_get_bus(adap);
        if (!bus)
                return 1;
        reg = 0;
@@ -558,7 +543,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(struct i2c_adapter *adap, uchar chip, uint addr,
+                       int alen, uchar *buffer, int len)
 {
        struct i2c_bus *bus;
        uint offset;
@@ -566,7 +552,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(adap);
        if (!bus)
                return 1;
        if (!i2c_addr_ok(addr, alen)) {
@@ -596,7 +582,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(struct i2c_adapter *adap, uchar chip, uint addr,
+                       int alen, uchar *buffer, int len)
 {
        struct i2c_bus *bus;
        uint offset;
@@ -604,7 +591,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(adap);
        if (!bus)
                return 1;
        if (!i2c_addr_ok(addr, alen)) {
@@ -625,30 +612,11 @@ 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;
 
-       for (i = 0; i < CONFIG_SYS_MAX_I2C_BUS; i++) {
+       for (i = 0; i < TEGRA_I2C_NUM_CONTROLLERS; i++) {
                struct i2c_bus *bus = &i2c_controllers[i];
 
                if (bus->inited && bus->is_dvc)
@@ -657,3 +625,19 @@ int tegra_i2c_get_dvc_bus_num(void)
 
        return -1;
 }
+
+/*
+ * Register soft i2c adapters
+ */
+U_BOOT_I2C_ADAP_COMPLETE(tegra0, tegra_i2c_init, tegra_i2c_probe,
+                        tegra_i2c_read, tegra_i2c_write,
+                        tegra_i2c_set_bus_speed, 100000, 0, 0)
+U_BOOT_I2C_ADAP_COMPLETE(tegra1, tegra_i2c_init, tegra_i2c_probe,
+                        tegra_i2c_read, tegra_i2c_write,
+                        tegra_i2c_set_bus_speed, 100000, 0, 1)
+U_BOOT_I2C_ADAP_COMPLETE(tegra2, tegra_i2c_init, tegra_i2c_probe,
+                        tegra_i2c_read, tegra_i2c_write,
+                        tegra_i2c_set_bus_speed, 100000, 0, 2)
+U_BOOT_I2C_ADAP_COMPLETE(tegra3, tegra_i2c_init, tegra_i2c_probe,
+                        tegra_i2c_read, tegra_i2c_write,
+                        tegra_i2c_set_bus_speed, 100000, 0, 3)
index 628d5d3db144bb00b889f1b2eb73de3d13cc4921..801caca24f129cd68c184eabc2dea57784d10252 100644 (file)
 #define CONFIG_BOARD_EARLY_INIT_F
 
 /* I2C */
-#define CONFIG_TEGRA_I2C
+#define CONFIG_SYS_I2C_TEGRA
 #define CONFIG_SYS_I2C_INIT_BOARD
-#define CONFIG_I2C_MULTI_BUS
-#define CONFIG_SYS_MAX_I2C_BUS         TEGRA_I2C_NUM_CONTROLLERS
 #define CONFIG_SYS_I2C_SPEED           100000
 #define CONFIG_CMD_I2C
+#define CONFIG_SYS_I2C
 
 /* SD/MMC */
 #define CONFIG_MMC
index 142d20b5c53b3655d5e9d6f57a2a1f44a2c1e74e..4abb03ea56dd76cdc1797bd08caa2e156a6c51ab 100644 (file)
 #define CONFIG_BOARD_EARLY_INIT_F
 
 /* I2C */
-#define CONFIG_TEGRA_I2C
+#define CONFIG_SYS_I2C_TEGRA
 #define CONFIG_SYS_I2C_INIT_BOARD
 #define CONFIG_I2C_MULTI_BUS
 #define CONFIG_SYS_MAX_I2C_BUS         TEGRA_I2C_NUM_CONTROLLERS
 #define CONFIG_SYS_I2C_SPEED           100000
 #define CONFIG_CMD_I2C
+#define CONFIG_SYS_I2C
 
 /* SD/MMC */
 #define CONFIG_MMC
index b6e01617c828ebb0adf4aff9170557084ba2140c..145e7ac926db17df54b818f3d0db7fd2bccd1e96 100644 (file)
 #define CONFIG_BOARD_EARLY_INIT_F
 
 /* I2C */
-#define CONFIG_TEGRA_I2C
+#define CONFIG_SYS_I2C_TEGRA
 #define CONFIG_SYS_I2C_INIT_BOARD
 #define CONFIG_I2C_MULTI_BUS
 #define CONFIG_SYS_MAX_I2C_BUS         TEGRA_I2C_NUM_CONTROLLERS
 #define CONFIG_SYS_I2C_SPEED           100000
 #define CONFIG_CMD_I2C
+#define CONFIG_SYS_I2C
 
 /* SD/MMC */
 #define CONFIG_MMC
index f0da1fcf1f69dc1fed0227fac19d53e95cad1c42..4048b6e2da784306d1da350a5d95022f5bb84626 100644 (file)
 #define CONFIG_BOARD_LATE_INIT         /* Make sure LCD init is complete */
 
 /* I2C */
-#define CONFIG_TEGRA_I2C
+#define CONFIG_SYS_I2C_TEGRA
 #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
 
 /* SD/MMC */
 #define CONFIG_MMC
index 6ed2fde3f365a830f04d0cd1b7201e9825a67c73..b784263ebcd598f448f24638a045413c58ad82a3 100644 (file)
 #endif
 
 /* remove I2C support */
-#ifdef CONFIG_TEGRA_I2C
-#undef CONFIG_TEGRA_I2C
+#ifdef CONFIG_SYS_I2C_TEGRA
+#undef CONFIG_SYS_I2C_TEGRA
 #endif
 #ifdef CONFIG_CMD_I2C
 #undef CONFIG_CMD_I2C
index b92531477e78580edf1e0a0e2b4e60c3eb54ae48..209c60e43efada124959214949c86e4058668470 100644 (file)
 #define CONFIG_CMD_SF
 
 /* I2C */
-#define CONFIG_TEGRA_I2C
+#define CONFIG_SYS_I2C_TEGRA
 #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
 
 /* SD/MMC */
 #define CONFIG_MMC
index 994edecaab3aa53bc807a31b5f4addc096053eb1..34e451d0c748cd6025942dd7363c54a018cfc4c1 100644 (file)
 #define CONFIG_BOARD_EARLY_INIT_F
 
 /* I2C */
-#define CONFIG_TEGRA_I2C
+#define CONFIG_SYS_I2C_TEGRA
 #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
 
 /* SD/MMC */
 #define CONFIG_MMC