cm_t54.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * Board functions for Compulab CM-T54 board
  3. *
  4. * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
  5. *
  6. * Author: Dmitry Lifshitz <lifshitz@compulab.co.il>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.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_essential(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_params.omap_bootmode;
  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_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
  83. #define SB_T54_CD_GPIO 228
  84. #define SB_T54_WP_GPIO 229
  85. int board_mmc_getcd(struct mmc *mmc)
  86. {
  87. return !gpio_get_value(SB_T54_CD_GPIO);
  88. }
  89. int board_mmc_init(bd_t *bis)
  90. {
  91. int ret0, ret1;
  92. ret0 = omap_mmc_init(0, 0, 0, -1, SB_T54_WP_GPIO);
  93. if (ret0)
  94. printf("cm_t54: failed to initialize mmc0\n");
  95. ret1 = omap_mmc_init(1, 0, 0, -1, -1);
  96. if (ret1)
  97. printf("cm_t54: failed to initialize mmc1\n");
  98. if (ret0 && ret1)
  99. return -1;
  100. return 0;
  101. }
  102. #endif
  103. #ifdef CONFIG_USB_HOST_ETHER
  104. void ft_board_setup(void *blob, bd_t *bd)
  105. {
  106. uint8_t enetaddr[6];
  107. /* MAC addr */
  108. if (eth_getenv_enetaddr("usbethaddr", enetaddr)) {
  109. fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address",
  110. enetaddr, 6, 1);
  111. }
  112. }
  113. static void generate_mac_addr(uint8_t *enetaddr)
  114. {
  115. int reg;
  116. reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET;
  117. /*
  118. * create a fake MAC address from the processor ID code.
  119. * first byte is 0x02 to signify locally administered.
  120. */
  121. enetaddr[0] = 0x02;
  122. enetaddr[1] = readl(reg + 0x10) & 0xff;
  123. enetaddr[2] = readl(reg + 0xC) & 0xff;
  124. enetaddr[3] = readl(reg + 0x8) & 0xff;
  125. enetaddr[4] = readl(reg) & 0xff;
  126. enetaddr[5] = (readl(reg) >> 8) & 0xff;
  127. }
  128. /*
  129. * Routine: handle_mac_address
  130. * Description: prepare MAC address for on-board Ethernet.
  131. */
  132. static int handle_mac_address(void)
  133. {
  134. uint8_t enetaddr[6];
  135. int ret;
  136. ret = eth_getenv_enetaddr("usbethaddr", enetaddr);
  137. if (ret)
  138. return 0;
  139. ret = cl_eeprom_read_mac_addr(enetaddr);
  140. if (ret || !is_valid_ether_addr(enetaddr))
  141. generate_mac_addr(enetaddr);
  142. if (!is_valid_ether_addr(enetaddr))
  143. return -1;
  144. return eth_setenv_enetaddr("usbethaddr", enetaddr);
  145. }
  146. int board_eth_init(bd_t *bis)
  147. {
  148. return handle_mac_address();
  149. }
  150. #endif
  151. #ifdef CONFIG_USB_EHCI
  152. static struct omap_usbhs_board_data usbhs_bdata = {
  153. .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
  154. .port_mode[1] = OMAP_EHCI_PORT_MODE_HSIC,
  155. .port_mode[2] = OMAP_EHCI_PORT_MODE_HSIC,
  156. };
  157. static void setup_host_clocks(bool enable)
  158. {
  159. int usbhost_clk = OPTFCLKEN_HSIC60M_P3_CLK |
  160. OPTFCLKEN_HSIC480M_P3_CLK |
  161. OPTFCLKEN_HSIC60M_P2_CLK |
  162. OPTFCLKEN_HSIC480M_P2_CLK |
  163. OPTFCLKEN_UTMI_P3_CLK |
  164. OPTFCLKEN_UTMI_P2_CLK;
  165. int usbtll_clk = OPTFCLKEN_USB_CH1_CLK_ENABLE |
  166. OPTFCLKEN_USB_CH2_CLK_ENABLE;
  167. int usbhub_clk = CKOBUFFER_CLK_ENABLE_MASK;
  168. if (enable) {
  169. /* Enable port 2 and 3 clocks*/
  170. setbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
  171. /* Enable port 2 and 3 usb host ports tll clocks*/
  172. setbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
  173. /* Request FREF_XTAL_CLK clock for HSIC USB Hub */
  174. setbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
  175. } else {
  176. clrbits_le32((*ctrl)->control_ckobuffer, usbhub_clk);
  177. clrbits_le32((*prcm)->cm_l3init_hsusbtll_clkctrl, usbtll_clk);
  178. clrbits_le32((*prcm)->cm_l3init_hsusbhost_clkctrl, usbhost_clk);
  179. }
  180. }
  181. int ehci_hcd_init(int index, enum usb_init_type init,
  182. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  183. {
  184. int ret;
  185. /* VCC_3V3_ETH */
  186. cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_3V3, SMPS9_CTRL,
  187. SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO);
  188. setup_host_clocks(true);
  189. ret = omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
  190. if (ret < 0)
  191. printf("cm_t54: Failed to initialize ehci : %d\n", ret);
  192. return ret;
  193. }
  194. int ehci_hcd_stop(void)
  195. {
  196. int ret = omap_ehci_hcd_stop();
  197. setup_host_clocks(false);
  198. cm_t54_palmas_regulator_set(SMPS9_VOLTAGE, SMPS_VOLT_OFF,
  199. SMPS9_CTRL, SMPS_MODE_SLP_AUTO);
  200. return ret;
  201. }
  202. void usb_hub_reset_devices(int port)
  203. {
  204. /* The LAN9730 needs to be reset after the port power has been set. */
  205. if (port == 3) {
  206. gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 0);
  207. udelay(10);
  208. gpio_direction_output(CONFIG_OMAP_EHCI_PHY3_RESET_GPIO, 1);
  209. }
  210. }
  211. #endif