board-omapl138-hawk.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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/gpio/machine.h>
  17. #include <linux/platform_data/gpio-davinci.h>
  18. #include <linux/regulator/machine.h>
  19. #include <asm/mach-types.h>
  20. #include <asm/mach/arch.h>
  21. #include <mach/common.h>
  22. #include "cp_intc.h"
  23. #include <mach/da8xx.h>
  24. #include <mach/mux.h>
  25. #define HAWKBOARD_PHY_ID "davinci_mdio-0:07"
  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 struct gpiod_lookup_table mmc_gpios_table = {
  107. .dev_id = "da830-mmc.0",
  108. .table = {
  109. /* CD: gpio3_12: gpio60: chip 1 contains gpio range 32-63*/
  110. GPIO_LOOKUP("davinci_gpio.1", 28, "cd", GPIO_ACTIVE_LOW),
  111. GPIO_LOOKUP("davinci_gpio.1", 29, "wp", GPIO_ACTIVE_LOW),
  112. },
  113. };
  114. static struct davinci_mmc_config da850_mmc_config = {
  115. .wires = 4,
  116. .max_freq = 50000000,
  117. .caps = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
  118. };
  119. static __init void omapl138_hawk_mmc_init(void)
  120. {
  121. int ret;
  122. ret = davinci_cfg_reg_list(hawk_mmcsd0_pins);
  123. if (ret) {
  124. pr_warn("%s: MMC/SD0 mux setup failed: %d\n", __func__, ret);
  125. return;
  126. }
  127. gpiod_add_lookup_table(&mmc_gpios_table);
  128. ret = da8xx_register_mmcsd0(&da850_mmc_config);
  129. if (ret) {
  130. pr_warn("%s: MMC/SD0 registration failed: %d\n", __func__, ret);
  131. goto mmc_setup_mmcsd_fail;
  132. }
  133. return;
  134. mmc_setup_mmcsd_fail:
  135. gpiod_remove_lookup_table(&mmc_gpios_table);
  136. }
  137. static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id);
  138. static da8xx_ocic_handler_t hawk_usb_ocic_handler;
  139. static const short da850_hawk_usb11_pins[] = {
  140. DA850_GPIO2_4, DA850_GPIO6_13,
  141. -1
  142. };
  143. static int hawk_usb_set_power(unsigned port, int on)
  144. {
  145. gpio_set_value(DA850_USB1_VBUS_PIN, on);
  146. return 0;
  147. }
  148. static int hawk_usb_get_power(unsigned port)
  149. {
  150. return gpio_get_value(DA850_USB1_VBUS_PIN);
  151. }
  152. static int hawk_usb_get_oci(unsigned port)
  153. {
  154. return !gpio_get_value(DA850_USB1_OC_PIN);
  155. }
  156. static int hawk_usb_ocic_notify(da8xx_ocic_handler_t handler)
  157. {
  158. int irq = gpio_to_irq(DA850_USB1_OC_PIN);
  159. int error = 0;
  160. if (handler != NULL) {
  161. hawk_usb_ocic_handler = handler;
  162. error = request_irq(irq, omapl138_hawk_usb_ocic_irq,
  163. IRQF_TRIGGER_RISING |
  164. IRQF_TRIGGER_FALLING,
  165. "OHCI over-current indicator", NULL);
  166. if (error)
  167. pr_err("%s: could not request IRQ to watch "
  168. "over-current indicator changes\n", __func__);
  169. } else {
  170. free_irq(irq, NULL);
  171. }
  172. return error;
  173. }
  174. static struct da8xx_ohci_root_hub omapl138_hawk_usb11_pdata = {
  175. .set_power = hawk_usb_set_power,
  176. .get_power = hawk_usb_get_power,
  177. .get_oci = hawk_usb_get_oci,
  178. .ocic_notify = hawk_usb_ocic_notify,
  179. /* TPS2087 switch @ 5V */
  180. .potpgt = (3 + 1) / 2, /* 3 ms max */
  181. };
  182. static irqreturn_t omapl138_hawk_usb_ocic_irq(int irq, void *dev_id)
  183. {
  184. hawk_usb_ocic_handler(&omapl138_hawk_usb11_pdata, 1);
  185. return IRQ_HANDLED;
  186. }
  187. static __init void omapl138_hawk_usb_init(void)
  188. {
  189. int ret;
  190. ret = davinci_cfg_reg_list(da850_hawk_usb11_pins);
  191. if (ret) {
  192. pr_warn("%s: USB 1.1 PinMux setup failed: %d\n", __func__, ret);
  193. return;
  194. }
  195. ret = da8xx_register_usb20_phy_clk(false);
  196. if (ret)
  197. pr_warn("%s: USB 2.0 PHY CLK registration failed: %d\n",
  198. __func__, ret);
  199. ret = da8xx_register_usb11_phy_clk(false);
  200. if (ret)
  201. pr_warn("%s: USB 1.1 PHY CLK registration failed: %d\n",
  202. __func__, ret);
  203. ret = da8xx_register_usb_phy();
  204. if (ret)
  205. pr_warn("%s: USB PHY registration failed: %d\n",
  206. __func__, ret);
  207. ret = gpio_request_one(DA850_USB1_VBUS_PIN,
  208. GPIOF_DIR_OUT, "USB1 VBUS");
  209. if (ret < 0) {
  210. pr_err("%s: failed to request GPIO for USB 1.1 port "
  211. "power control: %d\n", __func__, ret);
  212. return;
  213. }
  214. ret = gpio_request_one(DA850_USB1_OC_PIN,
  215. GPIOF_DIR_IN, "USB1 OC");
  216. if (ret < 0) {
  217. pr_err("%s: failed to request GPIO for USB 1.1 port "
  218. "over-current indicator: %d\n", __func__, ret);
  219. goto usb11_setup_oc_fail;
  220. }
  221. ret = da8xx_register_usb11(&omapl138_hawk_usb11_pdata);
  222. if (ret) {
  223. pr_warn("%s: USB 1.1 registration failed: %d\n", __func__, ret);
  224. goto usb11_setup_fail;
  225. }
  226. return;
  227. usb11_setup_fail:
  228. gpio_free(DA850_USB1_OC_PIN);
  229. usb11_setup_oc_fail:
  230. gpio_free(DA850_USB1_VBUS_PIN);
  231. }
  232. static __init void omapl138_hawk_init(void)
  233. {
  234. int ret;
  235. ret = da8xx_register_cfgchip();
  236. if (ret)
  237. pr_warn("%s: CFGCHIP registration failed: %d\n", __func__, ret);
  238. ret = da850_register_gpio();
  239. if (ret)
  240. pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
  241. davinci_serial_init(da8xx_serial_device);
  242. omapl138_hawk_config_emac();
  243. ret = da850_register_edma(da850_edma_rsv);
  244. if (ret)
  245. pr_warn("%s: EDMA registration failed: %d\n", __func__, ret);
  246. omapl138_hawk_mmc_init();
  247. omapl138_hawk_usb_init();
  248. ret = da8xx_register_watchdog();
  249. if (ret)
  250. pr_warn("%s: watchdog registration failed: %d\n",
  251. __func__, ret);
  252. ret = da8xx_register_rproc();
  253. if (ret)
  254. pr_warn("%s: dsp/rproc registration failed: %d\n",
  255. __func__, ret);
  256. regulator_has_full_constraints();
  257. }
  258. #ifdef CONFIG_SERIAL_8250_CONSOLE
  259. static int __init omapl138_hawk_console_init(void)
  260. {
  261. if (!machine_is_omapl138_hawkboard())
  262. return 0;
  263. return add_preferred_console("ttyS", 2, "115200");
  264. }
  265. console_initcall(omapl138_hawk_console_init);
  266. #endif
  267. static void __init omapl138_hawk_map_io(void)
  268. {
  269. da850_init();
  270. }
  271. MACHINE_START(OMAPL138_HAWKBOARD, "AM18x/OMAP-L138 Hawkboard")
  272. .atag_offset = 0x100,
  273. .map_io = omapl138_hawk_map_io,
  274. .init_irq = cp_intc_init,
  275. .init_time = davinci_timer_init,
  276. .init_machine = omapl138_hawk_init,
  277. .init_late = davinci_init_late,
  278. .dma_zone_size = SZ_128M,
  279. .restart = da8xx_restart,
  280. .reserve = da8xx_rproc_reserve_cma,
  281. MACHINE_END