cm_t54.c 5.7 KB

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