board-omapl138-hawk.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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_warning("%s: cpgmac/mii mux setup failed: %d\n",
  45. __func__, ret);
  46. return;
  47. }
  48. /* configure the CFGCHIP3 register for MII */
  49. __raw_writel(val, cfgchip3);
  50. pr_info("EMAC: MII PHY configured\n");
  51. soc_info->emac_pdata->phy_id = HAWKBOARD_PHY_ID;
  52. ret = da8xx_register_emac();
  53. if (ret)
  54. pr_warning("%s: emac registration failed: %d\n",
  55. __func__, ret);
  56. }
  57. /*
  58. * The following EDMA channels/slots are not being used by drivers (for
  59. * example: Timer, GPIO, UART events etc) on da850/omap-l138 EVM/Hawkboard,
  60. * hence they are being reserved for codecs on the DSP side.
  61. */
  62. static const s16 da850_dma0_rsv_chans[][2] = {
  63. /* (offset, number) */
  64. { 8, 6},
  65. {24, 4},
  66. {30, 2},
  67. {-1, -1}
  68. };
  69. static const s16 da850_dma0_rsv_slots[][2] = {
  70. /* (offset, number) */
  71. { 8, 6},
  72. {24, 4},
  73. {30, 50},
  74. {-1, -1}
  75. };
  76. static const s16 da850_dma1_rsv_chans[][2] = {
  77. /* (offset, number) */
  78. { 0, 28},
  79. {30, 2},
  80. {-1, -1}
  81. };
  82. static const s16 da850_dma1_rsv_slots[][2] = {
  83. /* (offset, number) */
  84. { 0, 28},
  85. {30, 90},
  86. {-1, -1}
  87. };
  88. static struct edma_rsv_info da850_edma_cc0_rsv = {
  89. .rsv_chans = da850_dma0_rsv_chans,
  90. .rsv_slots = da850_dma0_rsv_slots,
  91. };
  92. static struct edma_rsv_info da850_edma_cc1_rsv = {
  93. .rsv_chans = da850_dma1_rsv_chans,
  94. .rsv_slots = da850_dma1_rsv_slots,
  95. };
  96. static struct edma_rsv_info *da850_edma_rsv[2] = {
  97. &da850_edma_cc0_rsv,
  98. &da850_edma_cc1_rsv,
  99. };
  100. static const short hawk_mmcsd0_pins[] = {
  101. DA850_MMCSD0_DAT_0, DA850_MMCSD0_DAT_1, DA850_MMCSD0_DAT_2,
  102. DA850_MMCSD0_DAT_3, DA850_MMCSD0_CLK, DA850_MMCSD0_CMD,
  103. DA850_GPIO3_12, DA850_GPIO3_13,
  104. -1
  105. };
  106. static int da850_hawk_mmc_get_ro(int index)
  107. {
  108. return gpio_get_value(DA850_HAWK_MMCSD_WP_PIN);
  109. }
  110. static int da850_hawk_mmc_get_cd(int index)
  111. {
  112. return !gpio_get_value(DA850_HAWK_MMCSD_CD_PIN);
  113. }
  114. static struct davinci_mmc_config da850_mmc_config = {
  115. .get_ro = da850_hawk_mmc_get_ro,
  116. .get_cd = da850_hawk_mmc_get_cd,
  117. .wires = 4,
  118. .max_freq = 50000000,
  119. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  120. .version = MMC_CTLR_VERSION_2,
  121. };
  122. static __init void omapl138_hawk_mmc_init(void)
  123. {
  124. int ret;
  125. ret = davinci_cfg_reg_list(hawk_mmcsd0_pins);
  126. if (ret) {
  127. pr_warning("%s: MMC/SD0 mux setup failed: %d\n",
  128. __func__, ret);
  129. return;
  130. }
  131. ret = gpio_request_one(DA850_HAWK_MMCSD_CD_PIN,
  132. GPIOF_DIR_IN, "MMC CD");
  133. if (ret < 0) {
  134. pr_warning("%s: can not open GPIO %d\n",
  135. __func__, DA850_HAWK_MMCSD_CD_PIN);
  136. return;
  137. }
  138. ret = gpio_request_one(DA850_HAWK_MMCSD_WP_PIN,
  139. GPIOF_DIR_IN, "MMC WP");
  140. if (ret < 0) {
  141. pr_warning("%s: can not open GPIO %d\n",
  142. __func__, DA850_HAWK_MMCSD_WP_PIN);
  143. goto mmc_setup_wp_fail;
  144. }
  145. ret = da8xx_register_mmcsd0(&da850_mmc_config);
  146. if (ret) {
  147. pr_warning("%s: MMC/SD0 registration failed: %d\n",
  148. __func__, ret);
  149. goto mmc_setup_mmcsd_fail;
  150. }
  151. return;
  152. mmc_setup_mmcsd_fail:
  153. gpio_free(DA850_HAWK_MMCSD_WP_PIN);
  154. mmc_setup_wp_fail:
  155. gpio_free(DA850_HAWK_MMCSD_CD_PIN);
  156. }
  157. static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id);
  158. static da8xx_ocic_handler_t hawk_usb_ocic_handler;
  159. static const short da850_hawk_usb11_pins[] = {
  160. DA850_GPIO2_4, DA850_GPIO6_13,
  161. -1
  162. };
  163. static int hawk_usb_set_power(unsigned port, int on)
  164. {
  165. gpio_set_value(DA850_USB1_VBUS_PIN, on);
  166. return 0;
  167. }
  168. static int hawk_usb_get_power(unsigned port)
  169. {
  170. return gpio_get_value(DA850_USB1_VBUS_PIN);
  171. }
  172. static int hawk_usb_get_oci(unsigned port)
  173. {
  174. return !gpio_get_value(DA850_USB1_OC_PIN);
  175. }
  176. static int hawk_usb_ocic_notify(da8xx_ocic_handler_t handler)
  177. {
  178. int irq = gpio_to_irq(DA850_USB1_OC_PIN);
  179. int error = 0;
  180. if (handler != NULL) {
  181. hawk_usb_ocic_handler = handler;
  182. error = request_irq(irq, omapl138_hawk_usb_ocic_irq,
  183. IRQF_DISABLED | IRQF_TRIGGER_RISING |
  184. IRQF_TRIGGER_FALLING,
  185. "OHCI over-current indicator", NULL);
  186. if (error)
  187. pr_err("%s: could not request IRQ to watch "
  188. "over-current indicator changes\n", __func__);
  189. } else {
  190. free_irq(irq, NULL);
  191. }
  192. return error;
  193. }
  194. static struct da8xx_ohci_root_hub omapl138_hawk_usb11_pdata = {
  195. .set_power = hawk_usb_set_power,
  196. .get_power = hawk_usb_get_power,
  197. .get_oci = hawk_usb_get_oci,
  198. .ocic_notify = hawk_usb_ocic_notify,
  199. /* TPS2087 switch @ 5V */
  200. .potpgt = (3 + 1) / 2, /* 3 ms max */
  201. };
  202. static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id)
  203. {
  204. hawk_usb_ocic_handler(&omapl138_hawk_usb11_pdata, 1);
  205. return IRQ_HANDLED;
  206. }
  207. static __init void omapl138_hawk_usb_init(void)
  208. {
  209. int ret;
  210. u32 cfgchip2;
  211. ret = davinci_cfg_reg_list(da850_hawk_usb11_pins);
  212. if (ret) {
  213. pr_warning("%s: USB 1.1 PinMux setup failed: %d\n",
  214. __func__, ret);
  215. return;
  216. }
  217. /* Setup the Ref. clock frequency for the HAWK at 24 MHz. */
  218. cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
  219. cfgchip2 &= ~CFGCHIP2_REFFREQ;
  220. cfgchip2 |= CFGCHIP2_REFFREQ_24MHZ;
  221. __raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
  222. ret = gpio_request_one(DA850_USB1_VBUS_PIN,
  223. GPIOF_DIR_OUT, "USB1 VBUS");
  224. if (ret < 0) {
  225. pr_err("%s: failed to request GPIO for USB 1.1 port "
  226. "power control: %d\n", __func__, ret);
  227. return;
  228. }
  229. ret = gpio_request_one(DA850_USB1_OC_PIN,
  230. GPIOF_DIR_IN, "USB1 OC");
  231. if (ret < 0) {
  232. pr_err("%s: failed to request GPIO for USB 1.1 port "
  233. "over-current indicator: %d\n", __func__, ret);
  234. goto usb11_setup_oc_fail;
  235. }
  236. ret = da8xx_register_usb11(&omapl138_hawk_usb11_pdata);
  237. if (ret) {
  238. pr_warning("%s: USB 1.1 registration failed: %d\n",
  239. __func__, ret);
  240. goto usb11_setup_fail;
  241. }
  242. return;
  243. usb11_setup_fail:
  244. gpio_free(DA850_USB1_OC_PIN);
  245. usb11_setup_oc_fail:
  246. gpio_free(DA850_USB1_VBUS_PIN);
  247. }
  248. static struct davinci_uart_config omapl138_hawk_uart_config __initdata = {
  249. .enabled_uarts = 0x7,
  250. };
  251. static __init void omapl138_hawk_init(void)
  252. {
  253. int ret;
  254. davinci_serial_init(&omapl138_hawk_uart_config);
  255. omapl138_hawk_config_emac();
  256. ret = da850_register_edma(da850_edma_rsv);
  257. if (ret)
  258. pr_warning("%s: EDMA registration failed: %d\n",
  259. __func__, ret);
  260. omapl138_hawk_mmc_init();
  261. omapl138_hawk_usb_init();
  262. ret = da8xx_register_watchdog();
  263. if (ret)
  264. pr_warning("omapl138_hawk_init: "
  265. "watchdog registration failed: %d\n",
  266. ret);
  267. }
  268. #ifdef CONFIG_SERIAL_8250_CONSOLE
  269. static int __init omapl138_hawk_console_init(void)
  270. {
  271. if (!machine_is_omapl138_hawkboard())
  272. return 0;
  273. return add_preferred_console("ttyS", 2, "115200");
  274. }
  275. console_initcall(omapl138_hawk_console_init);
  276. #endif
  277. static void __init omapl138_hawk_map_io(void)
  278. {
  279. da850_init();
  280. }
  281. MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
  282. .atag_offset = 0x100,
  283. .map_io = omapl138_hawk_map_io,
  284. .init_irq = cp_intc_init,
  285. .timer = &davinci_timer,
  286. .init_machine = omapl138_hawk_init,
  287. .dma_zone_size = SZ_128M,
  288. .restart = da8xx_restart,
  289. MACHINE_END