cm_t54.c 5.7 KB

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