board-da830-evm.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * TI DA830/OMAP L137 EVM board
  3. *
  4. * Author: Mark A. Greer <mgreer@mvista.com>
  5. * Derived from: arch/arm/mach-davinci/board-dm644x-evm.c
  6. *
  7. * 2007, 2009 (c) MontaVista Software, Inc. This file is licensed under
  8. * the terms of the GNU General Public License version 2. This program
  9. * is licensed "as is" without any warranty of any kind, whether express
  10. * 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/i2c.h>
  18. #include <linux/i2c/pcf857x.h>
  19. #include <linux/i2c/at24.h>
  20. #include <asm/mach-types.h>
  21. #include <asm/mach/arch.h>
  22. #include <mach/cp_intc.h>
  23. #include <mach/mux.h>
  24. #include <mach/da8xx.h>
  25. #include <mach/usb.h>
  26. #define DA830_EVM_PHY_MASK 0x0
  27. #define DA830_EVM_MDIO_FREQUENCY 2200000 /* PHY bus frequency */
  28. static struct at24_platform_data da830_evm_i2c_eeprom_info = {
  29. .byte_len = SZ_256K / 8,
  30. .page_size = 64,
  31. .flags = AT24_FLAG_ADDR16,
  32. .setup = davinci_get_mac_addr,
  33. .context = (void *)0x7f00,
  34. };
  35. static int da830_evm_ui_expander_setup(struct i2c_client *client, int gpio,
  36. unsigned ngpio, void *context)
  37. {
  38. gpio_request(gpio + 6, "MUX_MODE");
  39. #ifdef CONFIG_DA830_UI_LCD
  40. gpio_direction_output(gpio + 6, 0);
  41. #else /* Must be NAND or NOR */
  42. gpio_direction_output(gpio + 6, 1);
  43. #endif
  44. return 0;
  45. }
  46. static int da830_evm_ui_expander_teardown(struct i2c_client *client, int gpio,
  47. unsigned ngpio, void *context)
  48. {
  49. gpio_free(gpio + 6);
  50. return 0;
  51. }
  52. static struct pcf857x_platform_data da830_evm_ui_expander_info = {
  53. .gpio_base = DAVINCI_N_GPIO,
  54. .setup = da830_evm_ui_expander_setup,
  55. .teardown = da830_evm_ui_expander_teardown,
  56. };
  57. static struct i2c_board_info __initdata da830_evm_i2c_devices[] = {
  58. {
  59. I2C_BOARD_INFO("24c256", 0x50),
  60. .platform_data = &da830_evm_i2c_eeprom_info,
  61. },
  62. {
  63. I2C_BOARD_INFO("tlv320aic3x", 0x18),
  64. },
  65. {
  66. I2C_BOARD_INFO("pcf8574", 0x3f),
  67. .platform_data = &da830_evm_ui_expander_info,
  68. },
  69. };
  70. static struct davinci_i2c_platform_data da830_evm_i2c_0_pdata = {
  71. .bus_freq = 100, /* kHz */
  72. .bus_delay = 0, /* usec */
  73. };
  74. /*
  75. * USB1 VBUS is controlled by GPIO1[15], over-current is reported on GPIO2[4].
  76. */
  77. #define ON_BD_USB_DRV GPIO_TO_PIN(1, 15)
  78. #define ON_BD_USB_OVC GPIO_TO_PIN(2, 4)
  79. static const short da830_evm_usb11_pins[] = {
  80. DA830_GPIO1_15, DA830_GPIO2_4,
  81. -1
  82. };
  83. static da8xx_ocic_handler_t da830_evm_usb_ocic_handler;
  84. static int da830_evm_usb_set_power(unsigned port, int on)
  85. {
  86. gpio_set_value(ON_BD_USB_DRV, on);
  87. return 0;
  88. }
  89. static int da830_evm_usb_get_power(unsigned port)
  90. {
  91. return gpio_get_value(ON_BD_USB_DRV);
  92. }
  93. static int da830_evm_usb_get_oci(unsigned port)
  94. {
  95. return !gpio_get_value(ON_BD_USB_OVC);
  96. }
  97. static irqreturn_t da830_evm_usb_ocic_irq(int, void *);
  98. static int da830_evm_usb_ocic_notify(da8xx_ocic_handler_t handler)
  99. {
  100. int irq = gpio_to_irq(ON_BD_USB_OVC);
  101. int error = 0;
  102. if (handler != NULL) {
  103. da830_evm_usb_ocic_handler = handler;
  104. error = request_irq(irq, da830_evm_usb_ocic_irq, IRQF_DISABLED |
  105. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  106. "OHCI over-current indicator", NULL);
  107. if (error)
  108. printk(KERN_ERR "%s: could not request IRQ to watch "
  109. "over-current indicator changes\n", __func__);
  110. } else
  111. free_irq(irq, NULL);
  112. return error;
  113. }
  114. static struct da8xx_ohci_root_hub da830_evm_usb11_pdata = {
  115. .set_power = da830_evm_usb_set_power,
  116. .get_power = da830_evm_usb_get_power,
  117. .get_oci = da830_evm_usb_get_oci,
  118. .ocic_notify = da830_evm_usb_ocic_notify,
  119. /* TPS2065 switch @ 5V */
  120. .potpgt = (3 + 1) / 2, /* 3 ms max */
  121. };
  122. static irqreturn_t da830_evm_usb_ocic_irq(int irq, void *dev_id)
  123. {
  124. da830_evm_usb_ocic_handler(&da830_evm_usb11_pdata, 1);
  125. return IRQ_HANDLED;
  126. }
  127. static __init void da830_evm_usb_init(void)
  128. {
  129. u32 cfgchip2;
  130. int ret;
  131. /*
  132. * Set up USB clock/mode in the CFGCHIP2 register.
  133. * FYI: CFGCHIP2 is 0x0000ef00 initially.
  134. */
  135. cfgchip2 = __raw_readl(DA8XX_SYSCFG_VIRT(DA8XX_CFGCHIP2_REG));
  136. /* USB2.0 PHY reference clock is 24 MHz */
  137. cfgchip2 &= ~CFGCHIP2_REFFREQ;
  138. cfgchip2 |= CFGCHIP2_REFFREQ_24MHZ;
  139. /*
  140. * Select internal reference clock for USB 2.0 PHY
  141. * and use it as a clock source for USB 1.1 PHY
  142. * (this is the default setting anyway).
  143. */
  144. cfgchip2 &= ~CFGCHIP2_USB1PHYCLKMUX;
  145. cfgchip2 |= CFGCHIP2_USB2PHYCLKMUX;
  146. /*
  147. * We have to override VBUS/ID signals when MUSB is configured into the
  148. * host-only mode -- ID pin will float if no cable is connected, so the
  149. * controller won't be able to drive VBUS thinking that it's a B-device.
  150. * Otherwise, we want to use the OTG mode and enable VBUS comparators.
  151. */
  152. cfgchip2 &= ~CFGCHIP2_OTGMODE;
  153. #ifdef CONFIG_USB_MUSB_HOST
  154. cfgchip2 |= CFGCHIP2_FORCE_HOST;
  155. #else
  156. cfgchip2 |= CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;
  157. #endif
  158. __raw_writel(cfgchip2, DA8XX_SYSCFG_VIRT(DA8XX_CFGCHIP2_REG));
  159. /* USB_REFCLKIN is not used. */
  160. ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);
  161. if (ret)
  162. pr_warning("%s: USB 2.0 PinMux setup failed: %d\n",
  163. __func__, ret);
  164. else {
  165. /*
  166. * TPS2065 switch @ 5V supplies 1 A (sustains 1.5 A),
  167. * with the power on to power good time of 3 ms.
  168. */
  169. ret = da8xx_register_usb20(1000, 3);
  170. if (ret)
  171. pr_warning("%s: USB 2.0 registration failed: %d\n",
  172. __func__, ret);
  173. }
  174. ret = da8xx_pinmux_setup(da830_evm_usb11_pins);
  175. if (ret) {
  176. pr_warning("%s: USB 1.1 PinMux setup failed: %d\n",
  177. __func__, ret);
  178. return;
  179. }
  180. ret = gpio_request(ON_BD_USB_DRV, "ON_BD_USB_DRV");
  181. if (ret) {
  182. printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port "
  183. "power control: %d\n", __func__, ret);
  184. return;
  185. }
  186. gpio_direction_output(ON_BD_USB_DRV, 0);
  187. ret = gpio_request(ON_BD_USB_OVC, "ON_BD_USB_OVC");
  188. if (ret) {
  189. printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port "
  190. "over-current indicator: %d\n", __func__, ret);
  191. return;
  192. }
  193. gpio_direction_input(ON_BD_USB_OVC);
  194. ret = da8xx_register_usb11(&da830_evm_usb11_pdata);
  195. if (ret)
  196. pr_warning("%s: USB 1.1 registration failed: %d\n",
  197. __func__, ret);
  198. }
  199. static struct davinci_uart_config da830_evm_uart_config __initdata = {
  200. .enabled_uarts = 0x7,
  201. };
  202. static const short da830_evm_mcasp1_pins[] = {
  203. DA830_AHCLKX1, DA830_ACLKX1, DA830_AFSX1, DA830_AHCLKR1, DA830_AFSR1,
  204. DA830_AMUTE1, DA830_AXR1_0, DA830_AXR1_1, DA830_AXR1_2, DA830_AXR1_5,
  205. DA830_ACLKR1, DA830_AXR1_6, DA830_AXR1_7, DA830_AXR1_8, DA830_AXR1_10,
  206. DA830_AXR1_11,
  207. -1
  208. };
  209. static u8 da830_iis_serializer_direction[] = {
  210. RX_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE,
  211. INACTIVE_MODE, TX_MODE, INACTIVE_MODE, INACTIVE_MODE,
  212. INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE, INACTIVE_MODE,
  213. };
  214. static struct snd_platform_data da830_evm_snd_data = {
  215. .tx_dma_offset = 0x2000,
  216. .rx_dma_offset = 0x2000,
  217. .op_mode = DAVINCI_MCASP_IIS_MODE,
  218. .num_serializer = ARRAY_SIZE(da830_iis_serializer_direction),
  219. .tdm_slots = 2,
  220. .serial_dir = da830_iis_serializer_direction,
  221. .eventq_no = EVENTQ_0,
  222. .version = MCASP_VERSION_2,
  223. .txnumevt = 1,
  224. .rxnumevt = 1,
  225. };
  226. /*
  227. * GPIO2[1] is used as MMC_SD_WP and GPIO2[2] as MMC_SD_INS.
  228. */
  229. static const short da830_evm_mmc_sd_pins[] = {
  230. DA830_MMCSD_DAT_0, DA830_MMCSD_DAT_1, DA830_MMCSD_DAT_2,
  231. DA830_MMCSD_DAT_3, DA830_MMCSD_DAT_4, DA830_MMCSD_DAT_5,
  232. DA830_MMCSD_DAT_6, DA830_MMCSD_DAT_7, DA830_MMCSD_CLK,
  233. DA830_MMCSD_CMD, DA830_GPIO2_1, DA830_GPIO2_2,
  234. -1
  235. };
  236. #define DA830_MMCSD_WP_PIN GPIO_TO_PIN(2, 1)
  237. static int da830_evm_mmc_get_ro(int index)
  238. {
  239. return gpio_get_value(DA830_MMCSD_WP_PIN);
  240. }
  241. static struct davinci_mmc_config da830_evm_mmc_config = {
  242. .get_ro = da830_evm_mmc_get_ro,
  243. .wires = 4,
  244. .version = MMC_CTLR_VERSION_2,
  245. };
  246. static inline void da830_evm_init_mmc(void)
  247. {
  248. int ret;
  249. ret = da8xx_pinmux_setup(da830_evm_mmc_sd_pins);
  250. if (ret) {
  251. pr_warning("da830_evm_init: mmc/sd mux setup failed: %d\n",
  252. ret);
  253. return;
  254. }
  255. ret = gpio_request(DA830_MMCSD_WP_PIN, "MMC WP");
  256. if (ret) {
  257. pr_warning("da830_evm_init: can not open GPIO %d\n",
  258. DA830_MMCSD_WP_PIN);
  259. return;
  260. }
  261. gpio_direction_input(DA830_MMCSD_WP_PIN);
  262. ret = da8xx_register_mmcsd0(&da830_evm_mmc_config);
  263. if (ret) {
  264. pr_warning("da830_evm_init: mmc/sd registration failed: %d\n",
  265. ret);
  266. gpio_free(DA830_MMCSD_WP_PIN);
  267. }
  268. }
  269. static __init void da830_evm_init(void)
  270. {
  271. struct davinci_soc_info *soc_info = &davinci_soc_info;
  272. int ret;
  273. ret = da8xx_register_edma();
  274. if (ret)
  275. pr_warning("da830_evm_init: edma registration failed: %d\n",
  276. ret);
  277. ret = da8xx_pinmux_setup(da830_i2c0_pins);
  278. if (ret)
  279. pr_warning("da830_evm_init: i2c0 mux setup failed: %d\n",
  280. ret);
  281. ret = da8xx_register_i2c(0, &da830_evm_i2c_0_pdata);
  282. if (ret)
  283. pr_warning("da830_evm_init: i2c0 registration failed: %d\n",
  284. ret);
  285. da830_evm_usb_init();
  286. soc_info->emac_pdata->phy_mask = DA830_EVM_PHY_MASK;
  287. soc_info->emac_pdata->mdio_max_freq = DA830_EVM_MDIO_FREQUENCY;
  288. soc_info->emac_pdata->rmii_en = 1;
  289. ret = da8xx_pinmux_setup(da830_cpgmac_pins);
  290. if (ret)
  291. pr_warning("da830_evm_init: cpgmac mux setup failed: %d\n",
  292. ret);
  293. ret = da8xx_register_emac();
  294. if (ret)
  295. pr_warning("da830_evm_init: emac registration failed: %d\n",
  296. ret);
  297. ret = da8xx_register_watchdog();
  298. if (ret)
  299. pr_warning("da830_evm_init: watchdog registration failed: %d\n",
  300. ret);
  301. davinci_serial_init(&da830_evm_uart_config);
  302. i2c_register_board_info(1, da830_evm_i2c_devices,
  303. ARRAY_SIZE(da830_evm_i2c_devices));
  304. ret = da8xx_pinmux_setup(da830_evm_mcasp1_pins);
  305. if (ret)
  306. pr_warning("da830_evm_init: mcasp1 mux setup failed: %d\n",
  307. ret);
  308. da8xx_register_mcasp(1, &da830_evm_snd_data);
  309. da830_evm_init_mmc();
  310. #ifdef CONFIG_DA830_UI_LCD
  311. ret = da8xx_pinmux_setup(da830_lcdcntl_pins);
  312. if (ret)
  313. pr_warning("da830_evm_init: lcdcntl mux setup failed: %d\n",
  314. ret);
  315. ret = da8xx_register_lcdc(&sharp_lcd035q3dg01_pdata);
  316. if (ret)
  317. pr_warning("da830_evm_init: lcd setup failed: %d\n", ret);
  318. #endif
  319. ret = da8xx_register_rtc();
  320. if (ret)
  321. pr_warning("da830_evm_init: rtc setup failed: %d\n", ret);
  322. }
  323. #ifdef CONFIG_SERIAL_8250_CONSOLE
  324. static int __init da830_evm_console_init(void)
  325. {
  326. return add_preferred_console("ttyS", 2, "115200");
  327. }
  328. console_initcall(da830_evm_console_init);
  329. #endif
  330. static __init void da830_evm_irq_init(void)
  331. {
  332. struct davinci_soc_info *soc_info = &davinci_soc_info;
  333. cp_intc_init((void __iomem *)DA8XX_CP_INTC_VIRT, DA830_N_CP_INTC_IRQ,
  334. soc_info->intc_irq_prios);
  335. }
  336. static void __init da830_evm_map_io(void)
  337. {
  338. da830_init();
  339. }
  340. MACHINE_START(DAVINCI_DA830_EVM, "DaVinci DA830/OMAP-L137 EVM")
  341. .phys_io = IO_PHYS,
  342. .io_pg_offst = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
  343. .boot_params = (DA8XX_DDR_BASE + 0x100),
  344. .map_io = da830_evm_map_io,
  345. .init_irq = da830_evm_irq_init,
  346. .timer = &davinci_timer,
  347. .init_machine = da830_evm_init,
  348. MACHINE_END