board.c 4.3 KB

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