cm_t3517.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_STATUS_LED) && defined(STATUS_LED_BOOT)
  80. status_led_set(STATUS_LED_BOOT, STATUS_LED_ON);
  81. #endif
  82. cm_t3517_musb_init();
  83. return 0;
  84. }
  85. int misc_init_r(void)
  86. {
  87. cl_print_pcb_info();
  88. omap_die_id_display();
  89. return 0;
  90. }
  91. #if defined(CONFIG_GENERIC_MMC) && !defined(CONFIG_SPL_BUILD)
  92. #define SB_T35_CD_GPIO 144
  93. #define SB_T35_WP_GPIO 59
  94. int board_mmc_init(bd_t *bis)
  95. {
  96. return omap_mmc_init(0, 0, 0, SB_T35_CD_GPIO, SB_T35_WP_GPIO);
  97. }
  98. #endif
  99. #ifdef CONFIG_DRIVER_TI_EMAC
  100. #define CONTROL_EFUSE_EMAC_LSB 0x48002380
  101. #define CONTROL_EFUSE_EMAC_MSB 0x48002384
  102. static int am3517_get_efuse_enetaddr(u8 *enetaddr)
  103. {
  104. u32 lsb = __raw_readl(CONTROL_EFUSE_EMAC_LSB);
  105. u32 msb = __raw_readl(CONTROL_EFUSE_EMAC_MSB);
  106. enetaddr[0] = (u8)((msb >> 16) & 0xff);
  107. enetaddr[1] = (u8)((msb >> 8) & 0xff);
  108. enetaddr[2] = (u8)(msb & 0xff);
  109. enetaddr[3] = (u8)((lsb >> 16) & 0xff);
  110. enetaddr[4] = (u8)((lsb >> 8) & 0xff);
  111. enetaddr[5] = (u8)(lsb & 0xff);
  112. return is_valid_ethaddr(enetaddr);
  113. }
  114. static inline int cm_t3517_init_emac(bd_t *bis)
  115. {
  116. int ret = cpu_eth_init(bis);
  117. if (ret > 0)
  118. return ret;
  119. printf("Failed initializing EMAC! ");
  120. return 0;
  121. }
  122. #else /* !CONFIG_DRIVER_TI_EMAC */
  123. static inline int am3517_get_efuse_enetaddr(u8 *enetaddr) { return 1; }
  124. static inline int cm_t3517_init_emac(bd_t *bis) { return 0; }
  125. #endif /* CONFIG_DRIVER_TI_EMAC */
  126. /*
  127. * Routine: handle_mac_address
  128. * Description: prepare MAC address for on-board Ethernet.
  129. */
  130. static int cm_t3517_handle_mac_address(void)
  131. {
  132. unsigned char enetaddr[6];
  133. int ret;
  134. ret = eth_getenv_enetaddr("ethaddr", enetaddr);
  135. if (ret)
  136. return 0;
  137. ret = cl_eeprom_read_mac_addr(enetaddr, CONFIG_SYS_I2C_EEPROM_BUS);
  138. if (ret) {
  139. ret = am3517_get_efuse_enetaddr(enetaddr);
  140. if (ret)
  141. return ret;
  142. }
  143. if (!is_valid_ethaddr(enetaddr))
  144. return -1;
  145. return eth_setenv_enetaddr("ethaddr", enetaddr);
  146. }
  147. #define SB_T35_ETH_RST_GPIO 164
  148. /*
  149. * Routine: board_eth_init
  150. * Description: initialize module and base-board Ethernet chips
  151. */
  152. int board_eth_init(bd_t *bis)
  153. {
  154. int rc = 0, rc1 = 0;
  155. rc1 = cm_t3517_handle_mac_address();
  156. if (rc1)
  157. printf("No MAC address found! ");
  158. rc1 = cm_t3517_init_emac(bis);
  159. if (rc1 > 0)
  160. rc++;
  161. rc1 = cl_omap3_smc911x_init(0, 4, CONFIG_SMC911X_BASE,
  162. NULL, SB_T35_ETH_RST_GPIO);
  163. if (rc1 > 0)
  164. rc++;
  165. return rc;
  166. }
  167. #ifdef CONFIG_USB_EHCI_OMAP
  168. static struct omap_usbhs_board_data cm_t3517_usbhs_bdata = {
  169. .port_mode[0] = OMAP_EHCI_PORT_MODE_PHY,
  170. .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
  171. .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED,
  172. };
  173. #define CM_T3517_USB_HUB_RESET_GPIO 152
  174. #define SB_T35_USB_HUB_RESET_GPIO 98
  175. int ehci_hcd_init(int index, enum usb_init_type init,
  176. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  177. {
  178. cl_usb_hub_init(CM_T3517_USB_HUB_RESET_GPIO, "cm-t3517 hub rst");
  179. cl_usb_hub_init(SB_T35_USB_HUB_RESET_GPIO, "sb-t35 hub rst");
  180. return omap_ehci_hcd_init(index, &cm_t3517_usbhs_bdata, hccr, hcor);
  181. }
  182. int ehci_hcd_stop(void)
  183. {
  184. cl_usb_hub_deinit(CM_T3517_USB_HUB_RESET_GPIO);
  185. cl_usb_hub_deinit(SB_T35_USB_HUB_RESET_GPIO);
  186. return omap_ehci_hcd_stop();
  187. }
  188. #endif /* CONFIG_USB_EHCI_OMAP */