+#if defined(CONFIG_I2C_CMD_TREE)
+#if defined(CONFIG_I2C_MULTI_BUS)
+int do_i2c_bus_num(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+{
+ int bus_idx, ret=0;
+
+ if (argc == 1) /* querying current setting */
+ {
+ printf("Current bus is %d\n", i2c_get_bus_num());
+ }
+ else
+ {
+ bus_idx = simple_strtoul(argv[1], NULL, 10);
+ printf("Setting bus to %d\n", bus_idx);
+ ret = i2c_set_bus_num(bus_idx);
+ if(ret)
+ {
+ printf("Failure changing bus number (%d)\n", ret);
+ }
+ }
+ return ret;
+}
+#endif /* CONFIG_I2C_MULTI_BUS */
+
+int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+{
+ int speed, ret=0;
+
+ if (argc == 1) /* querying current speed */
+ {
+ printf("Current bus speed=%d\n", i2c_get_bus_speed());
+ }
+ else
+ {
+ speed = simple_strtoul(argv[1], NULL, 10);
+ printf("Setting bus speed to %d Hz\n", speed);
+ ret = i2c_set_bus_speed(speed);
+ if(ret)
+ {
+ printf("Failure changing bus speed (%d)\n", ret);
+ }
+ }
+ return ret;
+}
+
+int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+{
+#if defined(CONFIG_I2C_MULTI_BUS)
+ if(!strncmp(argv[1], "de", 2))
+ {
+ return do_i2c_bus_num(cmdtp, flag, --argc, ++argv);
+ }
+#endif /* CONFIG_I2C_MULTI_BUS */
+ if(!strncmp(argv[1], "sp", 2))
+ {
+ return do_i2c_bus_speed(cmdtp, flag, --argc, ++argv);
+ }
+ if(!strncmp(argv[1], "md", 2))
+ {
+ return do_i2c_md(cmdtp, flag, --argc, ++argv);
+ }
+ if(!strncmp(argv[1], "mm", 2))
+ {
+ return do_i2c_mm(cmdtp, flag, --argc, ++argv);
+ }
+ if(!strncmp(argv[1], "mw", 2))
+ {
+ return do_i2c_mw(cmdtp, flag, --argc, ++argv);
+ }
+ if(!strncmp(argv[1], "nm", 2))
+ {
+ return do_i2c_nm(cmdtp, flag, --argc, ++argv);
+ }
+ if(!strncmp(argv[1], "cr", 2))
+ {
+ return do_i2c_crc(cmdtp, flag, --argc, ++argv);
+ }
+ if(!strncmp(argv[1], "pr", 2))
+ {
+ return do_i2c_probe(cmdtp, flag, --argc, ++argv);
+ }
+ if(!strncmp(argv[1], "lo", 2))
+ {
+ return do_i2c_loop(cmdtp, flag, --argc, ++argv);
+ }
+#if (CONFIG_COMMANDS & CFG_CMD_SDRAM)
+ if(!strncmp(argv[1], "sd", 2))
+ {
+ return do_sdram(cmdtp, flag, --argc, ++argv);
+ }
+#endif /* CFG_CMD_SDRAM */
+ else
+ {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ }
+ return 0;
+}
+#endif /* CONFIG_I2C_CMD_TREE */