cm_t3517.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * (C) Copyright 2014 CompuLab, Ltd. <www.compulab.co.il>
  3. *
  4. * Authors: Igor Grinberg <grinberg@compulab.co.il>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <status_led.h>
  10. #include <net.h>
  11. #include <netdev.h>
  12. #include <usb.h>
  13. #include <mmc.h>
  14. #include <linux/compiler.h>
  15. #include <linux/usb/musb.h>
  16. #include <asm/io.h>
  17. #include <asm/arch/mem.h>
  18. #include <asm/arch/am35x_def.h>
  19. #include <asm/arch/mmc_host_def.h>
  20. #include <asm/arch/sys_proto.h>
  21. #include <asm/arch/musb.h>
  22. #include <asm/omap_musb.h>
  23. #include <asm/ehci-omap.h>
  24. #include "../common/common.h"
  25. #include "../common/eeprom.h"
  26. DECLARE_GLOBAL_DATA_PTR;
  27. const omap3_sysinfo sysinfo = {
  28. DDR_DISCRETE,
  29. "CM-T3517 board",
  30. "NAND 128/512M",
  31. };
  32. #ifdef CONFIG_USB_MUSB_AM35X
  33. static struct musb_hdrc_config cm_t3517_musb_config = {
  34. .multipoint = 1,
  35. .dyn_fifo = 1,
  36. .num_eps = 16,
  37. .ram_bits = 12,
  38. };
  39. static struct omap_musb_board_data cm_t3517_musb_board_data = {
  40. .set_phy_power = am35x_musb_phy_power,
  41. .clear_irq = am35x_musb_clear_irq,
  42. .reset = am35x_musb_reset,
  43. };
  44. static struct musb_hdrc_platform_data cm_t3517_musb_pdata = {
  45. #if defined(CONFIG_USB_MUSB_HOST)
  46. .mode = MUSB_HOST,
  47. #elif defined(CONFIG_USB_MUSB_GADGET)
  48. .mode = MUSB_PERIPHERAL,
  49. #else
  50. #error "Please define either CONFIG_USB_MUSB_HOST or CONFIG_USB_MUSB_GADGET"
  51. #endif
  52. .config = &cm_t3517_musb_config,
  53. .power = 250,
  54. .platform_ops = &am35x_ops,
  55. .board_data = &cm_t3517_musb_board_data,
  56. };
  57. static void cm_t3517_musb_init(void)
  58. {
  59. /*
  60. * Set up USB clock/mode in the DEVCONF2 register.
  61. * USB2.0 PHY reference clock is 13 MHz
  62. */
  63. clrsetbits_le32(&am35x_scm_general_regs->devconf2,
  64. CONF2_REFFREQ | CONF2_OTGMODE | CONF2_PHY_GPIOMODE,
  65. CONF2_REFFREQ_13MHZ | CONF2_SESENDEN |
  66. CONF2_VBDTCTEN | CONF2_DATPOL);
  67. if (musb_register(&cm_t3517_musb_pdata, &cm_t3517_musb_board_data,
  68. (void *)AM35XX_IPSS_USBOTGSS_BASE))
  69. printf("Failed initializing AM35x MUSB!\n");
  70. }
  71. #else
  72. static inline void am3517_evm_musb_init(void) {}
  73. #endif
  74. int board_init(void)
  75. {
  76. gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
  77. /* boot param addr */
  78. gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
  79. #if defined(CONFIG_LED_STATUS) && defined(CONFIG_LED_STATUS_BOOT_ENABLE)
  80. status_led_set(CONFIG_LED_STATUS_BOOT, CONFIG_LED_STATUS_ON);
  81. #endif
  82. cm_t3517_musb_init();
  83. return 0;
  84. }
  85. /*
  86. * Routine: get_board_rev
  87. * Description: read system revision
  88. */
  89. u32 get_board_rev(void)
  90. {
  91. return cl_eeprom_get_board_rev(CONFIG_SYS_I2C_EEPROM_BUS);
  92. };
  93. int misc_init_r(void)
  94. {
  95. cl_print_pcb_info();
  96. omap_die_id_display();
  97. return 0;
  98. }
  99. #if defined(CONFIG_MMC)
  100. #define SB_T35_CD_GPIO 144
  101. #define SB_T35_WP_GPIO 59
  102. int board_mmc_init(bd_t *bis)
  103. {
  104. return omap_mmc_init(0, 0, 0, SB_T35_CD_GPIO, SB_T35_WP_GPIO);
  105. }
  106. #endif
  107. #ifdef CONFIG_DRIVER_TI_EMAC
  108. #define CONTROL_EFUSE_EMAC_LSB 0x48002380
  109. #define CONTROL_EFUSE_EMAC_MSB 0x48002384
  110. static int am3517_get_efuse_enetaddr(u8 *enetaddr)
  111. {
  112. u32 lsb = __raw_readl(CONTROL_EFUSE_EMAC_LSB);
  113. u32 msb = __raw_readl(CONTROL_EFUSE_EMAC_MSB);
  114. enetaddr[0] = (u8)((msb >> 16) & 0xff);
  115. enetaddr[1] = (u8)((msb >> 8) & 0xff);
  116. enetaddr[2] = (u8)(msb & 0xff);
  117. enetaddr[3] = (u8)((lsb >> 16) & 0xff);
  118. enetaddr[4] = (u8)((lsb >> 8) & 0xff);
  119. enetaddr[5] = (u8)(lsb & 0xff);
  120. return is_valid_ethaddr(enetaddr);
  121. }
  122. static inline int cm_t3517_init_emac(bd_t *bis)
  123. {
  124. int ret = cpu_eth_init(bis);
  125. if (ret > 0)
  126. return ret;
  127. printf("Failed initializing EMAC! ");
  128. return 0;
  129. }
  130. #else /* !CONFIG_DRIVER_TI_EMAC */
  131. static inline int am3517_get_efuse_enetaddr(u8 *enetaddr) { return 1; }
  132. static inline int cm_t3517_init_emac(bd_t *bis) { return 0; }
  133. #endif /* CONFIG_DRIVER_TI_EMAC */
  134. /*
  135. * Routine: handle_mac_address
  136. * Description: prepare MAC address for on-board Ethernet.
  137. */
  138. static int cm_t3517_handle_mac_address(void)
  139. {
  140. unsigned char enetaddr[6];
  141. int ret;
  142. ret = eth_env_get_enetaddr("ethaddr", enetaddr);
  143. if (ret)
  144. return 0;
  145. ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
  146. if (ret) {
  147. ret = am3517_get_efuse_enetaddr(enetaddr);
  148. if (ret)
  149. return ret;
  150. }
  151. if (!is_valid_ethaddr(enetaddr))
  152. return -1;
  153. return eth_env_set_enetaddr("ethaddr", enetaddr);
  154. }
  155. #define SB_T35_ETH_RST_GPIO 164
  156. /*
  157. * Routine: board_eth_init
  158. * Description: initialize module and base-board Ethernet chips
  159. */
  160. int board_eth_init(bd_t *bis)
  161. {
  162. int rc = 0, rc1 = 0;
  163. rc1 = cm_t3517_handle_mac_address();
  164. if (rc1)
  165. printf("No MAC address found! ");
  166. rc1 = cm_t3517_init_emac(bis);
  167. if (rc1 > 0)
  168. rc++;
  169. rc1 = cl_omap3_smc911x_init(0, 4, CONFIG_SMC911X_BASE,
  170. NULL, SB_T35_ETH_RST_GPIO);
  171. if (rc1 > 0)
  172. rc++;
  173. return rc;
  174. }
  175. #ifdef CONFIG_USB_EHCI_OMAP
  176. static struct omap_usbhs_board_data cm_t3517_usbhs_bdata = {
  177. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  178. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  179. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
  180. };
  181. #define CM_T3517_USB_HUB_RESET_GPIO 152
  182. #define SB_T35_USB_HUB_RESET_GPIO 98
  183. int ehci_hcd_init(int index, enum usb_init_type init,
  184. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  185. {
  186. cl_usb_hub_init(CM_T3517_USB_HUB_RESET_GPIO, "cm-t3517 hub rst");
  187. cl_usb_hub_init(SB_T35_USB_HUB_RESET_GPIO, "sb-t35 hub rst");
  188. return omap_ehci_hcd_init(index, &cm_t3517_usbhs_bdata, hccr, hcor);
  189. }
  190. int ehci_hcd_stop(void)
  191. {
  192. cl_usb_hub_deinit(CM_T3517_USB_HUB_RESET_GPIO);
  193. cl_usb_hub_deinit(SB_T35_USB_HUB_RESET_GPIO);
  194. return omap_ehci_hcd_stop();
  195. }
  196. #endif /* CONFIG_USB_EHCI_OMAP */