board-omapl138-hawk.c 8.1 KB

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