board.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Stefan Roese <sr@denx.de>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <i2c.h>
  8. #include <asm/io.h>
  9. #include <asm/arch/cpu.h>
  10. #include <asm/arch/soc.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. /*
  13. * Information specific to the DB-88F7040 eval board. We strive to use
  14. * DT for such platform specfic configurations. At some point, this
  15. * might be removed here and implemented via DT.
  16. */
  17. /* IO expander I2C device */
  18. #define I2C_IO_EXP_ADDR 0x21
  19. #define I2C_IO_CFG_REG_0 0x6
  20. #define I2C_IO_DATA_OUT_REG_0 0x2
  21. /* VBus enable */
  22. #define I2C_IO_REG_0_USB_H0_OFF 0
  23. #define I2C_IO_REG_0_USB_H1_OFF 1
  24. #define I2C_IO_REG_VBUS ((1 << I2C_IO_REG_0_USB_H0_OFF) | \
  25. (1 << I2C_IO_REG_0_USB_H1_OFF))
  26. /* Current limit */
  27. #define I2C_IO_REG_0_USB_H0_CL 4
  28. #define I2C_IO_REG_0_USB_H1_CL 5
  29. #define I2C_IO_REG_CL ((1 << I2C_IO_REG_0_USB_H0_CL) | \
  30. (1 << I2C_IO_REG_0_USB_H1_CL))
  31. static int usb_enabled = 0;
  32. /* Board specific xHCI dis-/enable code */
  33. /*
  34. * Set USB VBUS signals (via I2C IO expander/GPIO) as output and set
  35. * output value as disabled
  36. *
  37. * Set USB Current Limit signals (via I2C IO expander/GPIO) as output
  38. * and set output value as enabled
  39. */
  40. int board_xhci_config(void)
  41. {
  42. struct udevice *dev;
  43. int ret;
  44. u8 buf[8];
  45. if (of_machine_is_compatible("marvell,armada7040-db")) {
  46. /* Configure IO exander PCA9555: 7bit address 0x21 */
  47. ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev);
  48. if (ret) {
  49. printf("Cannot find PCA9555: %d\n", ret);
  50. return 0;
  51. }
  52. /*
  53. * Read configuration (direction) and set VBUS pin as output
  54. * (reset pin = output)
  55. */
  56. ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1);
  57. if (ret) {
  58. printf("Failed to read IO expander value via I2C\n");
  59. return -EIO;
  60. }
  61. buf[0] &= ~I2C_IO_REG_VBUS;
  62. buf[0] &= ~I2C_IO_REG_CL;
  63. ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1);
  64. if (ret) {
  65. printf("Failed to set IO expander via I2C\n");
  66. return -EIO;
  67. }
  68. /* Read output value and configure it */
  69. ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
  70. if (ret) {
  71. printf("Failed to read IO expander value via I2C\n");
  72. return -EIO;
  73. }
  74. buf[0] &= ~I2C_IO_REG_VBUS;
  75. buf[0] |= I2C_IO_REG_CL;
  76. ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
  77. if (ret) {
  78. printf("Failed to set IO expander via I2C\n");
  79. return -EIO;
  80. }
  81. mdelay(500); /* required delay to let output value settle */
  82. }
  83. return 0;
  84. }
  85. int board_xhci_enable(fdt_addr_t base)
  86. {
  87. struct udevice *dev;
  88. int ret;
  89. u8 buf[8];
  90. if (of_machine_is_compatible("marvell,armada7040-db")) {
  91. /*
  92. * This function enables all USB ports simultaniously,
  93. * it only needs to get called once
  94. */
  95. if (usb_enabled)
  96. return 0;
  97. /* Configure IO exander PCA9555: 7bit address 0x21 */
  98. ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev);
  99. if (ret) {
  100. printf("Cannot find PCA9555: %d\n", ret);
  101. return 0;
  102. }
  103. /* Read VBUS output value */
  104. ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
  105. if (ret) {
  106. printf("Failed to read IO expander value via I2C\n");
  107. return -EIO;
  108. }
  109. /* Enable VBUS power: Set output value of VBUS pin as enabled */
  110. buf[0] |= I2C_IO_REG_VBUS;
  111. ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1);
  112. if (ret) {
  113. printf("Failed to set IO expander via I2C\n");
  114. return -EIO;
  115. }
  116. mdelay(500); /* required delay to let output value settle */
  117. usb_enabled = 1;
  118. }
  119. return 0;
  120. }
  121. int board_early_init_f(void)
  122. {
  123. /* Nothing to do (yet), perhaps later some pin-muxing etc */
  124. return 0;
  125. }
  126. int board_init(void)
  127. {
  128. /* adress of boot parameters */
  129. gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
  130. return 0;
  131. }
  132. int board_late_init(void)
  133. {
  134. /* Pre-configure the USB ports (overcurrent, VBus) */
  135. board_xhci_config();
  136. return 0;
  137. }