board.c 4.3 KB

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