board-omapl138-hawk.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * Hawkboard.org based on TI's OMAP-L138 Platform
  3. *
  4. * Initial code: Syed Mohammed Khasim
  5. *
  6. * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com
  7. *
  8. * This file is licensed under the terms of the GNU General Public License
  9. * version 2. This program is licensed "as is" without any warranty of
  10. * any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/console.h>
  15. #include <linux/gpio.h>
  16. #include <asm/mach-types.h>
  17. #include <asm/mach/arch.h>
  18. #include <mach/cp_intc.h>
  19. #include <mach/da8xx.h>
  20. #include <mach/mux.h>
  21. #define HAWKBOARD_PHY_ID "davinci_mdio-0:07"
  22. #define DA850_HAWK_MMCSD_CD_PIN GPIO_TO_PIN(3, 12)
  23. #define DA850_HAWK_MMCSD_WP_PIN GPIO_TO_PIN(3, 13)
  24. #define DA850_USB1_VBUS_PIN GPIO_TO_PIN(2, 4)
  25. #define DA850_USB1_OC_PIN GPIO_TO_PIN(6, 13)
  26. static short omapl138_hawk_mii_pins[] __initdata = {
  27. DA850_MII_TXEN, DA850_MII_TXCLK, DA850_MII_COL, DA850_MII_TXD_3,
  28. DA850_MII_TXD_2, DA850_MII_TXD_1, DA850_MII_TXD_0, DA850_MII_RXER,
  29. DA850_MII_CRS, DA850_MII_RXCLK, DA850_MII_RXDV, DA850_MII_RXD_3,
  30. DA850_MII_RXD_2, DA850_MII_RXD_1, DA850_MII_RXD_0, DA850_MDIO_CLK,
  31. DA850_MDIO_D,
  32. -1
  33. };
  34. static __init void omapl138_hawk_config_emac(void)
  35. {
  36. void __iomem *cfgchip3 = DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP3_REG);
  37. int ret;
  38. u32 val;
  39. struct davinci_soc_info *soc_info = &davinci_soc_info;
  40. val = __raw_readl(cfgchip3);
  41. val &= ~BIT(8);
  42. ret = davinci_cfg_reg_list(omapl138_hawk_mii_pins);
  43. if (ret) {
  44. pr_warn("%s: CPGMAC/MII mux setup failed: %d\n", __func__, ret);
  45. return;
  46. }
  47. /* configure the CFGCHIP3 register for MII */
  48. __raw_writel(val, cfgchip3);
  49. pr_info("EMAC: MII PHY configured\n");
  50. soc_info->emac_pdata->phy_id = HAWKBOARD_PHY_ID;
  51. ret = da8xx_register_emac();
  52. if (ret)
  53. pr_warn("%s: EMAC registration failed: %d\n", __func__, ret);
  54. }
  55. /*
  56. * The following EDMA channels/slots are not being used by drivers (for
  57. * example: Timer, GPIO, UART events etc) on da850/omap-l138 EVM/Hawkboard,
  58. * hence they are being reserved for codecs on the DSP side.
  59. */
  60. static const s16 da850_dma0_rsv_chans[][2] = {
  61. /* (offset, number) */
  62. { 8, 6},
  63. {24, 4},
  64. {30, 2},
  65. {-1, -1}
  66. };
  67. static const s16 da850_dma0_rsv_slots[][2] = {
  68. /* (offset, number) */
  69. { 8, 6},
  70. {24, 4},
  71. {30, 50},
  72. {-1, -1}
  73. };
  74. static const s16 da850_dma1_rsv_chans[][2] = {
  75. /* (offset, number) */
  76. { 0, 28},
  77. {30, 2},
  78. {-1, -1}
  79. };
  80. static const s16 da850_dma1_rsv_slots[][2] = {
  81. /* (offset, number) */
  82. { 0, 28},
  83. {30, 90},
  84. {-1, -1}
  85. };
  86. static struct edma_rsv_info da850_edma_cc0_rsv = {
  87. .rsv_chans = da850_dma0_rsv_chans,
  88. .rsv_slots = da850_dma0_rsv_slots,
  89. };
  90. static struct edma_rsv_info da850_edma_cc1_rsv = {
  91. .rsv_chans = da850_dma1_rsv_chans,
  92. .rsv_slots = da850_dma1_rsv_slots,
  93. };
  94. static struct edma_rsv_info *da850_edma_rsv[2] = {
  95. &da850_edma_cc0_rsv,
  96. &da850_edma_cc1_rsv,
  97. };
  98. static const short hawk_mmcsd0_pins[] = {
  99. DA850_MMCSD0_DAT_0, DA850_MMCSD0_DAT_1, DA850_MMCSD0_DAT_2,
  100. DA850_MMCSD0_DAT_3, DA850_MMCSD0_CLK, DA850_MMCSD0_CMD,
  101. DA850_GPIO3_12, DA850_GPIO3_13,
  102. -1
  103. };
  104. static int da850_hawk_mmc_get_ro(int index)
  105. {
  106. return gpio_get_value(DA850_HAWK_MMCSD_WP_PIN);
  107. }
  108. static int da850_hawk_mmc_get_cd(int index)
  109. {
  110. return !gpio_get_value(DA850_HAWK_MMCSD_CD_PIN);
  111. }
  112. static struct davinci_mmc_config da850_mmc_config = {
  113. .get_ro = da850_hawk_mmc_get_ro,
  114. .get_cd = da850_hawk_mmc_get_cd,
  115. .wires = 4,
  116. .max_freq = 50000000,
  117. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  118. .version = MMC_CTLR_VERSION_2,
  119. };
  120. static __init void omapl138_hawk_mmc_init(void)
  121. {
  122. int ret;
  123. ret = davinci_cfg_reg_list(hawk_mmcsd0_pins);
  124. if (ret) {
  125. pr_warn("%s: MMC/SD0 mux setup failed: %d\n", __func__, ret);
  126. return;
  127. }
  128. ret = gpio_request_one(DA850_HAWK_MMCSD_CD_PIN,
  129. GPIOF_DIR_IN, "MMC CD");
  130. if (ret < 0) {
  131. pr_warn("%s: can not open GPIO %d\n",
  132. __func__, DA850_HAWK_MMCSD_CD_PIN);
  133. return;
  134. }
  135. ret = gpio_request_one(DA850_HAWK_MMCSD_WP_PIN,
  136. GPIOF_DIR_IN, "MMC WP");
  137. if (ret < 0) {
  138. pr_warn("%s: can not open GPIO %d\n",
  139. __func__, DA850_HAWK_MMCSD_WP_PIN);
  140. goto mmc_setup_wp_fail;
  141. }
  142. ret = da8xx_register_mmcsd0(&da850_mmc_config);
  143. if (ret) {
  144. pr_warn("%s: MMC/SD0 registration failed: %d\n", __func__, ret);
  145. goto mmc_setup_mmcsd_fail;
  146. }
  147. return;
  148. mmc_setup_mmcsd_fail:
  149. gpio_free(DA850_HAWK_MMCSD_WP_PIN);
  150. mmc_setup_wp_fail:
  151. gpio_free(DA850_HAWK_MMCSD_CD_PIN);
  152. }
  153. static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id);
  154. static da8xx_ocic_handler_t hawk_usb_ocic_handler;
  155. static const short da850_hawk_usb11_pins[] = {
  156. DA850_GPIO2_4, DA850_GPIO6_13,
  157. -1
  158. };
  159. static int hawk_usb_set_power(unsigned port, int on)
  160. {
  161. gpio_set_value(DA850_USB1_VBUS_PIN, on);
  162. return 0;
  163. }
  164. static int hawk_usb_get_power(unsigned port)
  165. {
  166. return gpio_get_value(DA850_USB1_VBUS_PIN);
  167. }
  168. static int hawk_usb_get_oci(unsigned port)
  169. {
  170. return !gpio_get_value(DA850_USB1_OC_PIN);
  171. }
  172. static int hawk_usb_ocic_notify(da8xx_ocic_handler_t handler)
  173. {
  174. int irq = gpio_to_irq(DA850_USB1_OC_PIN);
  175. int error = 0;
  176. if (handler != NULL) {
  177. hawk_usb_ocic_handler = handler;
  178. error = request_irq(irq, omapl138_hawk_usb_ocic_irq,
  179. IRQF_DISABLED | IRQF_TRIGGER_RISING |
  180. IRQF_TRIGGER_FALLING,
  181. "OHCI over-current indicator", NULL);
  182. if (error)
  183. pr_err("%s: could not request IRQ to watch "
  184. "over-current indicator changes\n", __func__);
  185. } else {
  186. free_irq(irq, NULL);
  187. }
  188. return error;
  189. }
  190. static struct da8xx_ohci_root_hub omapl138_hawk_usb11_pdata = {
  191. .set_power = hawk_usb_set_power,
  192. .get_power = hawk_usb_get_power,
  193. .get_oci = hawk_usb_get_oci,
  194. .ocic_notify = hawk_usb_ocic_notify,
  195. /* TPS2087 switch @ 5V */
  196. .potpgt = (3 + 1) / 2, /* 3 ms max */
  197. };
  198. static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id)
  199. {
  200. hawk_usb_ocic_handler(&omapl138_hawk_usb11_pdata, 1);
  201. return IRQ_HANDLED;
  202. }
  203. static __init void omapl138_hawk_usb_init(void)
  204. {
  205. int ret;
  206. u32 cfgchip2;
  207. ret = davinci_cfg_reg_list(da850_hawk_usb11_pins);
  208. if (ret) {
  209. pr_warn("%s: USB 1.1 PinMux setup failed: %d\n", __func__, ret);
  210. return;
  211. }
  212. /* Setup the Ref. clock frequency for the HAWK at 24 MHz. */
  213. cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
  214. cfgchip2 &= ~CFGCHIP2_REFFREQ;
  215. cfgchip2 |= CFGCHIP2_REFFREQ_24MHZ;
  216. __raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
  217. ret = gpio_request_one(DA850_USB1_VBUS_PIN,
  218. GPIOF_DIR_OUT, "USB1 VBUS");
  219. if (ret < 0) {
  220. pr_err("%s: failed to request GPIO for USB 1.1 port "
  221. "power control: %d\n", __func__, ret);
  222. return;
  223. }
  224. ret = gpio_request_one(DA850_USB1_OC_PIN,
  225. GPIOF_DIR_IN, "USB1 OC");
  226. if (ret < 0) {
  227. pr_err("%s: failed to request GPIO for USB 1.1 port "
  228. "over-current indicator: %d\n", __func__, ret);
  229. goto usb11_setup_oc_fail;
  230. }
  231. ret = da8xx_register_usb11(&omapl138_hawk_usb11_pdata);
  232. if (ret) {
  233. pr_warn("%s: USB 1.1 registration failed: %d\n", __func__, ret);
  234. goto usb11_setup_fail;
  235. }
  236. return;
  237. usb11_setup_fail:
  238. gpio_free(DA850_USB1_OC_PIN);
  239. usb11_setup_oc_fail:
  240. gpio_free(DA850_USB1_VBUS_PIN);
  241. }
  242. static struct davinci_uart_config omapl138_hawk_uart_config __initdata = {
  243. .enabled_uarts = 0x7,
  244. };
  245. static __init void omapl138_hawk_init(void)
  246. {
  247. int ret;
  248. davinci_serial_init(&omapl138_hawk_uart_config);
  249. omapl138_hawk_config_emac();
  250. ret = da850_register_edma(da850_edma_rsv);
  251. if (ret)
  252. pr_warn("%s: EDMA registration failed: %d\n", __func__, ret);
  253. omapl138_hawk_mmc_init();
  254. omapl138_hawk_usb_init();
  255. ret = da8xx_register_watchdog();
  256. if (ret)
  257. pr_warn("%s: watchdog registration failed: %d\n",
  258. __func__, ret);
  259. }
  260. #ifdef CONFIG_SERIAL_8250_CONSOLE
  261. static int __init omapl138_hawk_console_init(void)
  262. {
  263. if (!machine_is_omapl138_hawkboard())
  264. return 0;
  265. return add_preferred_console("ttyS", 2, "115200");
  266. }
  267. console_initcall(omapl138_hawk_console_init);
  268. #endif
  269. static void __init omapl138_hawk_map_io(void)
  270. {
  271. da850_init();
  272. }
  273. MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
  274. .atag_offset = 0x100,
  275. .map_io = omapl138_hawk_map_io,
  276. .init_irq = cp_intc_init,
  277. .init_time = davinci_timer_init,
  278. .init_machine = omapl138_hawk_init,
  279. .init_late = davinci_init_late,
  280. .dma_zone_size = SZ_128M,
  281. .restart = da8xx_restart,
  282. MACHINE_END