]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_i2c.c
x86: ivybridge: Use syscon for the GMA device
[u-boot] / common / cmd_i2c.c
index ad38cbf6e17fe28198ef053b089cf19ffb167292..b3bb64408fe18af0c2a754ed653384bd55dee880 100644 (file)
@@ -69,6 +69,7 @@
 #include <bootretry.h>
 #include <cli.h>
 #include <command.h>
+#include <console.h>
 #include <dm.h>
 #include <edid.h>
 #include <environment.h>
@@ -453,6 +454,37 @@ static int do_i2c_flags(cmd_tbl_t *cmdtp, int flag, int argc,
 
        return 0;
 }
+
+static int do_i2c_olen(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+       struct udevice *dev;
+       uint olen;
+       int chip;
+       int ret;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       chip = simple_strtoul(argv[1], NULL, 16);
+       ret = i2c_get_cur_bus_chip(chip, &dev);
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+
+       if (argc > 2) {
+               olen = simple_strtoul(argv[2], NULL, 16);
+               ret = i2c_set_chip_offset_len(dev, olen);
+       } else  {
+               ret = i2c_get_chip_offset_len(dev);
+               if (ret >= 0) {
+                       printf("%x\n", ret);
+                       ret = 0;
+               }
+       }
+       if (ret)
+               return i2c_report_err(ret, I2C_ERR_READ);
+
+       return 0;
+}
 #endif
 
 /**
@@ -1623,6 +1655,27 @@ int do_edid(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 }
 #endif /* CONFIG_I2C_EDID */
 
+#ifdef CONFIG_DM_I2C
+static void show_bus(struct udevice *bus)
+{
+       struct udevice *dev;
+
+       printf("Bus %d:\t%s", bus->req_seq, bus->name);
+       if (device_active(bus))
+               printf("  (active %d)", bus->seq);
+       printf("\n");
+       for (device_find_first_child(bus, &dev);
+            dev;
+            device_find_next_child(&dev)) {
+               struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
+
+               printf("   %02x: %s, offset len %x, flags %x\n",
+                      chip->chip_addr, dev->name, chip->offset_len,
+                      chip->flags);
+       }
+}
+#endif
+
 /**
  * do_i2c_show_bus() - Handle the "i2c bus" command-line command
  * @cmdtp:     Command data struct pointer
@@ -1632,20 +1685,30 @@ int do_edid(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  *
  * Returns zero always.
  */
-#if defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
 static int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc,
                                char * const argv[])
 {
-       int     i;
-#ifndef CONFIG_SYS_I2C_DIRECT_BUS
-       int     j;
-#endif
-
        if (argc == 1) {
                /* show all busses */
+#ifdef CONFIG_DM_I2C
+               struct udevice *bus;
+               struct uclass *uc;
+               int ret;
+
+               ret = uclass_get(UCLASS_I2C, &uc);
+               if (ret)
+                       return CMD_RET_FAILURE;
+               uclass_foreach_dev(bus, uc)
+                       show_bus(bus);
+#else
+               int i;
+
                for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) {
                        printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
+                       int j;
+
                        for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
                                if (i2c_bus[i].next_hop[j].chip == 0)
                                        break;
@@ -1657,15 +1720,30 @@ static int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc,
 #endif
                        printf("\n");
                }
+#endif
        } else {
+               int i;
+
                /* show specific bus */
                i = simple_strtoul(argv[1], NULL, 10);
+#ifdef CONFIG_DM_I2C
+               struct udevice *bus;
+               int ret;
+
+               ret = uclass_get_device_by_seq(UCLASS_I2C, i, &bus);
+               if (ret) {
+                       printf("Invalid bus %d: err=%d\n", i, ret);
+                       return CMD_RET_FAILURE;
+               }
+               show_bus(bus);
+#else
                if (i >= CONFIG_SYS_NUM_I2C_BUSES) {
                        printf("Invalid bus %d\n", i);
                        return -1;
                }
                printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
+                       int j;
                        for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
                                if (i2c_bus[i].next_hop[j].chip == 0)
                                        break;
@@ -1676,6 +1754,7 @@ static int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc,
                        }
 #endif
                printf("\n");
+#endif
        }
 
        return 0;
@@ -1730,7 +1809,8 @@ static int do_i2c_bus_num(cmd_tbl_t *cmdtp, int flag, int argc,
                if (ret)
                        printf("Failure changing bus number (%d)\n", ret);
        }
-       return ret;
+
+       return ret ? CMD_RET_FAILURE : 0;
 }
 #endif  /* defined(CONFIG_SYS_I2C) */
 
@@ -1773,7 +1853,8 @@ static int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char * const
                if (ret)
                        printf("Failure changing bus speed (%d)\n", ret);
        }
-       return ret;
+
+       return ret ? CMD_RET_FAILURE : 0;
 }
 
 /**
@@ -1835,7 +1916,7 @@ static int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv
 }
 
 static cmd_tbl_t cmd_i2c_sub[] = {
-#if defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
        U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
 #endif
        U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
@@ -1856,6 +1937,7 @@ static cmd_tbl_t cmd_i2c_sub[] = {
        U_BOOT_CMD_MKENT(write, 6, 0, do_i2c_write, "", ""),
 #ifdef CONFIG_DM_I2C
        U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""),
+       U_BOOT_CMD_MKENT(olen, 2, 1, do_i2c_olen, "", ""),
 #endif
        U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""),
 #if defined(CONFIG_CMD_SDRAM)
@@ -1864,11 +1946,15 @@ static cmd_tbl_t cmd_i2c_sub[] = {
        U_BOOT_CMD_MKENT(speed, 1, 1, do_i2c_bus_speed, "", ""),
 };
 
-#ifdef CONFIG_NEEDS_MANUAL_RELOC
-void i2c_reloc(void) {
-       fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub));
+static __maybe_unused void i2c_reloc(void)
+{
+       static int relocated;
+
+       if (!relocated) {
+               fixup_cmdtable(cmd_i2c_sub, ARRAY_SIZE(cmd_i2c_sub));
+               relocated = 1;
+       };
 }
-#endif
 
 /**
  * do_i2c() - Handle the "i2c" command-line command
@@ -1884,6 +1970,10 @@ static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 {
        cmd_tbl_t *c;
 
+#ifdef CONFIG_NEEDS_MANUAL_RELOC
+       i2c_reloc();
+#endif
+
        if (argc < 2)
                return CMD_RET_USAGE;
 
@@ -1902,7 +1992,7 @@ static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 /***************************************************/
 #ifdef CONFIG_SYS_LONGHELP
 static char i2c_help_text[] =
-#if defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
        "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
 #endif
        "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"
@@ -1924,6 +2014,7 @@ static char i2c_help_text[] =
        "          to I2C; the -s option selects bulk write in a single transaction\n"
 #ifdef CONFIG_DM_I2C
        "i2c flags chip [flags] - set or get chip flags\n"
+       "i2c olen chip [offset_length] - set or get chip offset length\n"
 #endif
        "i2c reset - re-init the I2C Controller\n"
 #if defined(CONFIG_CMD_SDRAM)