cm_t54.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board functions for Compulab CM-T54 board
  4. *
  5. * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
  6. *
  7. * Author: Dmitry Lifshitz <lifshitz@compulab.co.il>
  8. */
  9. #include <common.h>
  10. #include <env.h>
  11. #include <fdt_support.h>
  12. #include <usb.h>
  13. #include <mmc.h>
  14. #include <palmas.h>
  15. #include <spl.h>
  16. #include <asm/gpio.h>
  17. #include <asm/arch/sys_proto.h>
  18. #include <asm/arch/mmc_host_def.h>
  19. #include <asm/arch/clock.h>
  20. #include <asm/arch/ehci.h>
  21. #include <asm/ehci-omap.h>
  22. #include "../common/eeprom.h"
  23. #define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000)
  24. #define DIE_ID_REG_OFFSET 0x200
  25. DECLARE_GLOBAL_DATA_PTR;
  26. #if !defined(CONFIG_SPL_BUILD)
  27. inline void set_muxconf_regs(void){};
  28. #endif
  29. const struct omap_sysinfo sysinfo = {
  30. "Board: CM-T54\n"
  31. };
  32. /*
  33. * Routine: board_init
  34. * Description: hardware init.
  35. */
  36. int board_init(void)
  37. {
  38. gd->bd->bi_boot_params = (CONFIG_SYS_SDRAM_BASE + 0x100);
  39. return 0;
  40. }
  41. /*
  42. * Routine: cm_t54_palmas_regulator_set
  43. * Description: select voltage and turn on/off Palmas PMIC regulator.
  44. */
  45. static int cm_t54_palmas_regulator_set(u8 vreg, u8 vval, u8 creg, u8 cval)
  46. {
  47. int err;
  48. /* Setup voltage */
  49. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, vreg, vval);
  50. if (err) {
  51. printf("cm_t54: could not set regulator 0x%02x voltage : %d\n",
  52. vreg, err);
  53. return err;
  54. }
  55. /* Turn on/off regulator */
  56. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, creg, cval);
  57. if (err) {
  58. printf("cm_t54: could not turn on/off regulator 0x%02x : %d\n",
  59. creg, err);
  60. return err;
  61. }
  62. return 0;
  63. }
  64. /*
  65. * Routine: mmc_get_env_part
  66. * Description: setup environment storage device partition.
  67. */
  68. #ifdef CONFIG_SYS_MMC_ENV_PART
  69. uint mmc_get_env_part(struct mmc *mmc)
  70. {
  71. u32 bootmode = gd->arch.omap_boot_mode;
  72. uint bootpart = CONFIG_SYS_MMC_ENV_PART;
  73. /*
  74. * If booted from eMMC boot partition then force eMMC
  75. * FIRST boot partition to be env storage
  76. */
  77. if (bootmode == BOOT_DEVICE_MMC2)
  78. bootpart = 1;
  79. return bootpart;
  80. }
  81. #endif
  82. #if defined(CONFIG_MMC)
  83. #define SB_T54_CD_GPIO 228
  84. #define SB_T54_WP_GPIO 229
  85. int board_mmc_init(bd_t *bis)
  86. {
  87. int ret0, ret1;
  88. ret0 = omap_mmc_init(0, 0, 0, SB_T54_CD_GPIO, SB_T54_WP_GPIO);
  89. if (ret0)
  90. printf("cm_t54: failed to initialize mmc0\n");
  91. ret1 = omap_mmc_init(1, 0, 0, -1, -1);
  92. if (ret1)
  93. printf("cm_t54: failed to initialize mmc1\n");
  94. if (ret0 && ret1)
  95. return -1;
  96. return 0;
  97. }
  98. #endif
  99. #ifdef CONFIG_USB_HOST_ETHER
  100. int ft_board_setup(void *blob, bd_t *bd)
  101. {
  102. uint8_t enetaddr[6];
  103. /* MAC addr */
  104. if (eth_env_get_enetaddr("usbethaddr", enetaddr)) {
  105. fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address",
  106. enetaddr, 6, 1);
  107. }
  108. return 0;
  109. }
  110. static void generate_mac_addr(uint8_t *enetaddr)
  111. {
  112. int reg;
  113. reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET;
  114. /*
  115. * create a fake MAC address from the processor ID code.
  116. * first byte is 0x02 to signify locally administered.
  117. */
  118. enetaddr[0] = 0x02;
  119. enetaddr[1] = readl(reg + 0x10) & 0xff;
  120. enetaddr[2] = readl(reg + 0xC) & 0xff;
  121. enetaddr[3] = readl(reg + 0x8) & 0xff;
  122. enetaddr[4] = readl(reg) & 0xff;
  123. enetaddr[5] = (readl(reg) >> 8) & 0xff;
  124. }
  125. /*
  126. * Routine: handle_mac_address
  127. * Description: prepare MAC address for on-board Ethernet.
  128. */
  129. static int handle_mac_address(void)
  130. {
  131. uint8_t enetaddr[6];
  132. int ret;
  133. ret = eth_env_get_enetaddr("usbethaddr", enetaddr);
  134. if (ret)
  135. return 0;
  136. ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
  137. if (ret || !is_valid_ethaddr(enetaddr))
  138. generate_mac_addr(enetaddr);
  139. if (!is_valid_ethaddr(enetaddr))
  140. return -1;
  141. return eth_env_set_enetaddr("usbethaddr", enetaddr);
  142. }
  143. int board_eth_init(bd_t *bis)
  144. {
  145. return handle_mac_address();
  146. }
  147. #endif
  148. #ifdef CONFIG_USB_EHCI_HCD
  149. static struct omap_usbhs_board_data usbhs_bdata = {
  150. .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
  151. .port_mode[1] = OMAP_EHCI_PORT_MODE_HSIC,
  152. .port_mode[2] = OMAP_EHCI_PORT_MODE_HSIC,
  153. };
  154. static void setup_host_clocks(bool enable)
  155. {
  156. int usbhost_clk = OPTFCLKEN_HSIC60M_P3_CLK |
  157. OPTFCLKEN_HSIC480M_P3_CLK |
  158. OPTFCLKEN_HSIC60M_P2_CLK |
  159. OPTFCLKEN_HSIC480M_P2_CLK |
  160. OPTFCLKEN_UTMI_P3_CLK |
  161. OPTFCLKEN_UTMI_P2_CLK;
  162. int usbtll_clk = OPTFCLKEN_USB_CH1_CLK_ENABLE |
  163. OPTFCLKEN_USB_CH2_CLK_ENABLE;
  164. int usbhub_clk = CKOBUFFER_CLK_ENABLE_MASK;
  165. if (enable) {
  166. /* Enable port 2 and 3 clocks*/
  167. setbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
  168. /* Enable port 2 and 3 usb host ports tll clocks*/
  169. setbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
  170. /* Request FREF_XTAL_CLK clock for HSIC USB Hub */
  171. setbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
  172. } else {
  173. clrbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
  174. clrbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
  175. clrbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
  176. }
  177. }
  178. int ehci_hcd_init(int index, enum usb_init_type init,
  179. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  180. {
  181. int ret;
  182. /* VCC_3V3_ETH */
  183. cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_3V3, SMPS9_CTRL,
  184. SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO);
  185. setup_host_clocks(true);
  186. ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  187. if (ret < 0)
  188. printf("cm_t54: Failed to initialize ehci : %d\n", ret);
  189. return ret;
  190. }
  191. int ehci_hcd_stop(void)
  192. {
  193. int ret = omap_ehci_hcd_stop();
  194. setup_host_clocks(false);
  195. cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_OFF,
  196. SMPS9_CTRL, SMPS_MODE_SLP_AUTO);
  197. return ret;
  198. }
  199. void usb_hub_reset_devices(struct usb_hub_device *hub, int port)
  200. {
  201. /* The LAN9730 needs to be reset after the port power has been set. */
  202. if (port == 3) {
  203. gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 0);
  204. udelay(10);
  205. gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 1);
  206. }
  207. }
  208. #endif