Commit 59aa9df383b85a7701cefbe997d242d79b452e3b

Authored by Simon Glass
1 parent 28b5404ca1

dm: i2c: Implement 'i2c bus' command for driver model

This command was missed in the conversion. Add it back for driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Heiko Schocher <hs@denx.de>

Showing 1 changed file with 55 additions and 8 deletions Side-by-side Diff

... ... @@ -1623,6 +1623,27 @@
1623 1623 }
1624 1624 #endif /* CONFIG_I2C_EDID */
1625 1625  
  1626 +#ifdef CONFIG_DM_I2C
  1627 +static void show_bus(struct udevice *bus)
  1628 +{
  1629 + struct udevice *dev;
  1630 +
  1631 + printf("Bus %d:\t%s", bus->req_seq, bus->name);
  1632 + if (device_active(bus))
  1633 + printf(" (active %d)", bus->seq);
  1634 + printf("\n");
  1635 + for (device_find_first_child(bus, &dev);
  1636 + dev;
  1637 + device_find_next_child(&dev)) {
  1638 + struct dm_i2c_chip *chip = dev_get_parent_platdata(dev);
  1639 +
  1640 + printf(" %02x: %s, offset len %x, flags %x\n",
  1641 + chip->chip_addr, dev->name, chip->offset_len,
  1642 + chip->flags);
  1643 + }
  1644 +}
  1645 +#endif
  1646 +
1626 1647 /**
1627 1648 * do_i2c_show_bus() - Handle the "i2c bus" command-line command
1628 1649 * @cmdtp: Command data struct pointer
1629 1650  
1630 1651  
1631 1652  
... ... @@ -1632,20 +1653,30 @@
1632 1653 *
1633 1654 * Returns zero always.
1634 1655 */
1635   -#if defined(CONFIG_SYS_I2C)
  1656 +#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
1636 1657 static int do_i2c_show_bus(cmd_tbl_t *cmdtp, int flag, int argc,
1637 1658 char * const argv[])
1638 1659 {
1639   - int i;
1640   -#ifndef CONFIG_SYS_I2C_DIRECT_BUS
1641   - int j;
1642   -#endif
1643   -
1644 1660 if (argc == 1) {
1645 1661 /* show all busses */
  1662 +#ifdef CONFIG_DM_I2C
  1663 + struct udevice *bus;
  1664 + struct uclass *uc;
  1665 + int ret;
  1666 +
  1667 + ret = uclass_get(UCLASS_I2C, &uc);
  1668 + if (ret)
  1669 + return CMD_RET_FAILURE;
  1670 + uclass_foreach_dev(bus, uc)
  1671 + show_bus(bus);
  1672 +#else
  1673 + int i;
  1674 +
1646 1675 for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSES; i++) {
1647 1676 printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
1648 1677 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  1678 + int j;
  1679 +
1649 1680 for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
1650 1681 if (i2c_bus[i].next_hop[j].chip == 0)
1651 1682 break;
1652 1683  
1653 1684  
1654 1685  
... ... @@ -1657,15 +1688,30 @@
1657 1688 #endif
1658 1689 printf("\n");
1659 1690 }
  1691 +#endif
1660 1692 } else {
  1693 + int i;
  1694 +
1661 1695 /* show specific bus */
1662 1696 i = simple_strtoul(argv[1], NULL, 10);
  1697 +#ifdef CONFIG_DM_I2C
  1698 + struct udevice *bus;
  1699 + int ret;
  1700 +
  1701 + ret = uclass_get_device_by_seq(UCLASS_I2C, i, &bus);
  1702 + if (ret) {
  1703 + printf("Invalid bus %d: err=%d\n", i, ret);
  1704 + return CMD_RET_FAILURE;
  1705 + }
  1706 + show_bus(bus);
  1707 +#else
1663 1708 if (i >= CONFIG_SYS_NUM_I2C_BUSES) {
1664 1709 printf("Invalid bus %d\n", i);
1665 1710 return -1;
1666 1711 }
1667 1712 printf("Bus %d:\t%s", i, I2C_ADAP_NR(i)->name);
1668 1713 #ifndef CONFIG_SYS_I2C_DIRECT_BUS
  1714 + int j;
1669 1715 for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
1670 1716 if (i2c_bus[i].next_hop[j].chip == 0)
1671 1717 break;
... ... @@ -1676,6 +1722,7 @@
1676 1722 }
1677 1723 #endif
1678 1724 printf("\n");
  1725 +#endif
1679 1726 }
1680 1727  
1681 1728 return 0;
... ... @@ -1835,7 +1882,7 @@
1835 1882 }
1836 1883  
1837 1884 static cmd_tbl_t cmd_i2c_sub[] = {
1838   -#if defined(CONFIG_SYS_I2C)
  1885 +#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
1839 1886 U_BOOT_CMD_MKENT(bus, 1, 1, do_i2c_show_bus, "", ""),
1840 1887 #endif
1841 1888 U_BOOT_CMD_MKENT(crc32, 3, 1, do_i2c_crc, "", ""),
... ... @@ -1902,7 +1949,7 @@
1902 1949 /***************************************************/
1903 1950 #ifdef CONFIG_SYS_LONGHELP
1904 1951 static char i2c_help_text[] =
1905   -#if defined(CONFIG_SYS_I2C)
  1952 +#if defined(CONFIG_SYS_I2C) || defined(CONFIG_DM_I2C)
1906 1953 "bus [muxtype:muxaddr:muxchannel] - show I2C bus info\n"
1907 1954 #endif
1908 1955 "crc32 chip address[.0, .1, .2] count - compute CRC32 checksum\n"