board-omapl138-hawk.c 8.2 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 <linux/platform_data/gpio-davinci.h>
  17. #include <asm/mach-types.h>
  18. #include <asm/mach/arch.h>
  19. #include <mach/common.h>
  20. #include "cp_intc.h"
  21. #include <mach/da8xx.h>
  22. #include <mach/mux.h>
  23. #define HAWKBOARD_PHY_ID "davinci_mdio-0:07"
  24. #define DA850_HAWK_MMCSD_CD_PIN GPIO_TO_PIN(3, 12)
  25. #define DA850_HAWK_MMCSD_WP_PIN GPIO_TO_PIN(3, 13)
  26. #define DA850_USB1_VBUS_PIN GPIO_TO_PIN(2, 4)
  27. #define DA850_USB1_OC_PIN GPIO_TO_PIN(6, 13)
  28. static short omapl138_hawk_mii_pins[] __initdata = {
  29. DA850_MII_TXEN, DA850_MII_TXCLK, DA850_MII_COL, DA850_MII_TXD_3,
  30. DA850_MII_TXD_2, DA850_MII_TXD_1, DA850_MII_TXD_0, DA850_MII_RXER,
  31. DA850_MII_CRS, DA850_MII_RXCLK, DA850_MII_RXDV, DA850_MII_RXD_3,
  32. DA850_MII_RXD_2, DA850_MII_RXD_1, DA850_MII_RXD_0, DA850_MDIO_CLK,
  33. DA850_MDIO_D,
  34. -1
  35. };
  36. static __init void omapl138_hawk_config_emac(void)
  37. {
  38. void __iomem *cfgchip3 = DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP3_REG);
  39. int ret;
  40. u32 val;
  41. struct davinci_soc_info *soc_info = &davinci_soc_info;
  42. val = __raw_readl(cfgchip3);
  43. val &= ~BIT(8);
  44. ret = davinci_cfg_reg_list(omapl138_hawk_mii_pins);
  45. if (ret) {
  46. pr_warn("%s: CPGMAC/MII mux setup failed: %d\n", __func__, ret);
  47. return;
  48. }
  49. /* configure the CFGCHIP3 register for MII */
  50. __raw_writel(val, cfgchip3);
  51. pr_info("EMAC: MII PHY configured\n");
  52. soc_info->emac_pdata->phy_id = HAWKBOARD_PHY_ID;
  53. ret = da8xx_register_emac();
  54. if (ret)
  55. pr_warn("%s: EMAC registration failed: %d\n", __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. };
  121. static __init void omapl138_hawk_mmc_init(void)
  122. {
  123. int ret;
  124. ret = davinci_cfg_reg_list(hawk_mmcsd0_pins);
  125. if (ret) {
  126. pr_warn("%s: MMC/SD0 mux setup failed: %d\n", __func__, ret);
  127. return;
  128. }
  129. ret = gpio_request_one(DA850_HAWK_MMCSD_CD_PIN,
  130. GPIOF_DIR_IN, "MMC CD");
  131. if (ret < 0) {
  132. pr_warn("%s: can not open GPIO %d\n",
  133. __func__, DA850_HAWK_MMCSD_CD_PIN);
  134. return;
  135. }
  136. ret = gpio_request_one(DA850_HAWK_MMCSD_WP_PIN,
  137. GPIOF_DIR_IN, "MMC WP");
  138. if (ret < 0) {
  139. pr_warn("%s: can not open GPIO %d\n",
  140. __func__, DA850_HAWK_MMCSD_WP_PIN);
  141. goto mmc_setup_wp_fail;
  142. }
  143. ret = da8xx_register_mmcsd0(&da850_mmc_config);
  144. if (ret) {
  145. pr_warn("%s: MMC/SD0 registration failed: %d\n", __func__, ret);
  146. goto mmc_setup_mmcsd_fail;
  147. }
  148. return;
  149. mmc_setup_mmcsd_fail:
  150. gpio_free(DA850_HAWK_MMCSD_WP_PIN);
  151. mmc_setup_wp_fail:
  152. gpio_free(DA850_HAWK_MMCSD_CD_PIN);
  153. }
  154. static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id);
  155. static da8xx_ocic_handler_t hawk_usb_ocic_handler;
  156. static const short da850_hawk_usb11_pins[] = {
  157. DA850_GPIO2_4, DA850_GPIO6_13,
  158. -1
  159. };
  160. static int hawk_usb_set_power(unsigned port, int on)
  161. {
  162. gpio_set_value(DA850_USB1_VBUS_PIN, on);
  163. return 0;
  164. }
  165. static int hawk_usb_get_power(unsigned port)
  166. {
  167. return gpio_get_value(DA850_USB1_VBUS_PIN);
  168. }
  169. static int hawk_usb_get_oci(unsigned port)
  170. {
  171. return !gpio_get_value(DA850_USB1_OC_PIN);
  172. }
  173. static int hawk_usb_ocic_notify(da8xx_ocic_handler_t handler)
  174. {
  175. int irq = gpio_to_irq(DA850_USB1_OC_PIN);
  176. int error = 0;
  177. if (handler != NULL) {
  178. hawk_usb_ocic_handler = handler;
  179. error = request_irq(irq, omapl138_hawk_usb_ocic_irq,
  180. IRQF_TRIGGER_RISING |
  181. IRQF_TRIGGER_FALLING,
  182. "OHCI over-current indicator", NULL);
  183. if (error)
  184. pr_err("%s: could not request IRQ to watch "
  185. "over-current indicator changes\n", __func__);
  186. } else {
  187. free_irq(irq, NULL);
  188. }
  189. return error;
  190. }
  191. static struct da8xx_ohci_root_hub omapl138_hawk_usb11_pdata = {
  192. .set_power = hawk_usb_set_power,
  193. .get_power = hawk_usb_get_power,
  194. .get_oci = hawk_usb_get_oci,
  195. .ocic_notify = hawk_usb_ocic_notify,
  196. /* TPS2087 switch @ 5V */
  197. .potpgt = (3 + 1) / 2, /* 3 ms max */
  198. };
  199. static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id)
  200. {
  201. hawk_usb_ocic_handler(&omapl138_hawk_usb11_pdata, 1);
  202. return IRQ_HANDLED;
  203. }
  204. static __init void omapl138_hawk_usb_init(void)
  205. {
  206. int ret;
  207. u32 cfgchip2;
  208. ret = davinci_cfg_reg_list(da850_hawk_usb11_pins);
  209. if (ret) {
  210. pr_warn("%s: USB 1.1 PinMux setup failed: %d\n", __func__, ret);
  211. return;
  212. }
  213. /* Setup the Ref. clock frequency for the HAWK at 24 MHz. */
  214. cfgchip2 = __raw_readl(DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
  215. cfgchip2 &= ~CFGCHIP2_REFFREQ;
  216. cfgchip2 |= CFGCHIP2_REFFREQ_24MHZ;
  217. __raw_writel(cfgchip2, DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG));
  218. ret = gpio_request_one(DA850_USB1_VBUS_PIN,
  219. GPIOF_DIR_OUT, "USB1 VBUS");
  220. if (ret < 0) {
  221. pr_err("%s: failed to request GPIO for USB 1.1 port "
  222. "power control: %d\n", __func__, ret);
  223. return;
  224. }
  225. ret = gpio_request_one(DA850_USB1_OC_PIN,
  226. GPIOF_DIR_IN, "USB1 OC");
  227. if (ret < 0) {
  228. pr_err("%s: failed to request GPIO for USB 1.1 port "
  229. "over-current indicator: %d\n", __func__, ret);
  230. goto usb11_setup_oc_fail;
  231. }
  232. ret = da8xx_register_usb11(&omapl138_hawk_usb11_pdata);
  233. if (ret) {
  234. pr_warn("%s: USB 1.1 registration failed: %d\n", __func__, ret);
  235. goto usb11_setup_fail;
  236. }
  237. return;
  238. usb11_setup_fail:
  239. gpio_free(DA850_USB1_OC_PIN);
  240. usb11_setup_oc_fail:
  241. gpio_free(DA850_USB1_VBUS_PIN);
  242. }
  243. static __init void omapl138_hawk_init(void)
  244. {
  245. int ret;
  246. ret = da850_register_gpio();
  247. if (ret)
  248. pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
  249. davinci_serial_init(da8xx_serial_device);
  250. omapl138_hawk_config_emac();
  251. ret = da850_register_edma(da850_edma_rsv);
  252. if (ret)
  253. pr_warn("%s: EDMA registration failed: %d\n", __func__, ret);
  254. omapl138_hawk_mmc_init();
  255. omapl138_hawk_usb_init();
  256. ret = da8xx_register_watchdog();
  257. if (ret)
  258. pr_warn("%s: watchdog registration failed: %d\n",
  259. __func__, ret);
  260. ret = da8xx_register_rproc();
  261. if (ret)
  262. pr_warn("%s: dsp/rproc registration failed: %d\n",
  263. __func__, ret);
  264. }
  265. #ifdef CONFIG_SERIAL_8250_CONSOLE
  266. static int __init omapl138_hawk_console_init(void)
  267. {
  268. if (!machine_is_omapl138_hawkboard())
  269. return 0;
  270. return add_preferred_console("ttyS", 2, "115200");
  271. }
  272. console_initcall(omapl138_hawk_console_init);
  273. #endif
  274. static void __init omapl138_hawk_map_io(void)
  275. {
  276. da850_init();
  277. }
  278. MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
  279. .atag_offset = 0x100,
  280. .map_io = omapl138_hawk_map_io,
  281. .init_irq = cp_intc_init,
  282. .init_time = davinci_timer_init,
  283. .init_machine = omapl138_hawk_init,
  284. .init_late = davinci_init_late,
  285. .dma_zone_size = SZ_128M,
  286. .restart = da8xx_restart,
  287. .reserve = da8xx_rproc_reserve_cma,
  288. MACHINE_END