]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
exynos: i2c: Change FDT bus setup code to enumerate ports correctly
authorSimon Glass <sjg@chromium.org>
Tue, 15 Oct 2013 10:32:10 +0000 (16:02 +0530)
committerHeiko Schocher <hs@denx.de>
Thu, 17 Oct 2013 05:20:26 +0000 (07:20 +0200)
At present the i2c ports are enumerated in a strange way - the
fdtdec_find_aliases_for_id() function is used, but then the ID returned
is ignored and the ports are renumbered. The effect is the same provided
that the device tree has the ports in the same order, or uses aliases,
and has no gaps, but it is not correct.

Adjust the code to use the function as intended. This will allows device
tree aliases to change the device order if required.

As a result, the i2c_busses variable is dropped. We can't be sure that
there are no 'holes' in the list of buses, so must check the whole
array.

Note: it seems that non-FDT operation is now broken in this drive and
will need to be reinstated for upstream.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/59369
Signed-off-by: Naveen Krishna Chatradhi <ch.naveen@samsung.com>
drivers/i2c/s3c24x0_i2c.c
drivers/i2c/s3c24x0_i2c.h

index c65360d0ffce51b5447cf51d0a3b0eb9722c133a..0e6f2414f0c96d61dcea283134a247ebb030bfe1 100644 (file)
@@ -52,7 +52,6 @@
  */
 static unsigned int g_current_bus __attribute__((section(".data")));
 #ifdef CONFIG_OF_CONTROL
-static int i2c_busses __attribute__((section(".data")));
 static struct s3c24x0_i2c_bus i2c_bus[CONFIG_MAX_I2C_NUM]
                        __attribute__((section(".data")));
 #endif
@@ -164,8 +163,8 @@ int i2c_set_bus_num(unsigned int bus)
 {
        struct s3c24x0_i2c *i2c;
 
-       if ((bus < 0) || (bus >= CONFIG_MAX_I2C_NUM)) {
-               debug("Bad bus: %d\n", bus);
+       i2c_bus = get_bus(bus);
+       if (!i2c_bus)
                return -1;
        }
 
@@ -483,19 +482,31 @@ void board_i2c_init(const void *blob)
                if (node <= 0)
                        continue;
                bus = &i2c_bus[i];
+               bus->active = true;
                bus->regs = (struct s3c24x0_i2c *)
                        fdtdec_get_addr(blob, node, "reg");
                bus->id = pinmux_decode_periph_id(blob, node);
                bus->node = node;
-               bus->bus_num = i2c_busses++;
+               bus->bus_num = i;
                exynos_pinmux_config(bus->id, 0);
        }
 }
 
+/**
+ * Get a pointer to the given bus index
+ *
+ * @bus_idx: Bus index to look up
+ * @return pointer to bus, or NULL if invalid or not available
+ */
 static struct s3c24x0_i2c_bus *get_bus(unsigned int bus_idx)
 {
-       if (bus_idx < i2c_busses)
-               return &i2c_bus[bus_idx];
+       if (bus_idx < ARRAY_SIZE(i2c_bus)) {
+               struct s3c24x0_i2c_bus *bus;
+
+               bus = &i2c_bus[bus_idx];
+               if (bus->active)
+                       return bus;
+       }
 
        debug("Undefined bus: %d\n", bus_idx);
        return NULL;
@@ -505,7 +516,7 @@ int i2c_get_bus_num_fdt(int node)
 {
        int i;
 
-       for (i = 0; i < i2c_busses; i++) {
+       for (i = 0; i < ARRAY_SIZE(i2c_bus); i++) {
                if (node == i2c_bus[i].node)
                        return i;
        }
index b4a337a57bd81624b5e780fd29a48e74648d5c90..882af62063efd80354549b6ab60e035fa5678d37 100644 (file)
@@ -16,6 +16,7 @@ struct s3c24x0_i2c {
 };
 
 struct s3c24x0_i2c_bus {
+       bool active;    /* port is active and available */
        int node;       /* device tree node */
        int bus_num;    /* i2c bus number */
        struct s3c24x0_i2c *regs;