board.c 3.7 KB

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