mach-pca100.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /*
  2. * Copyright 2007 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
  3. * Copyright (C) 2009 Sascha Hauer (kernel@pengutronix.de)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. * MA 02110-1301, USA.
  18. */
  19. #include <linux/platform_device.h>
  20. #include <linux/io.h>
  21. #include <linux/i2c.h>
  22. #include <linux/platform_data/at24.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/spi/spi.h>
  25. #include <linux/spi/eeprom.h>
  26. #include <linux/irq.h>
  27. #include <linux/delay.h>
  28. #include <linux/gpio.h>
  29. #include <linux/usb/otg.h>
  30. #include <linux/usb/ulpi.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach-types.h>
  33. #include <asm/mach/time.h>
  34. #include "common.h"
  35. #include "devices-imx27.h"
  36. #include "ehci.h"
  37. #include "hardware.h"
  38. #include "iomux-mx27.h"
  39. #include "ulpi.h"
  40. #define OTG_PHY_CS_GPIO (GPIO_PORTB + 23)
  41. #define USBH2_PHY_CS_GPIO (GPIO_PORTB + 24)
  42. #define SPI1_SS0 (GPIO_PORTD + 28)
  43. #define SPI1_SS1 (GPIO_PORTD + 27)
  44. #define SD2_CD (GPIO_PORTC + 29)
  45. static const int pca100_pins[] __initconst = {
  46. /* UART1 */
  47. PE12_PF_UART1_TXD,
  48. PE13_PF_UART1_RXD,
  49. PE14_PF_UART1_CTS,
  50. PE15_PF_UART1_RTS,
  51. /* SDHC */
  52. PB4_PF_SD2_D0,
  53. PB5_PF_SD2_D1,
  54. PB6_PF_SD2_D2,
  55. PB7_PF_SD2_D3,
  56. PB8_PF_SD2_CMD,
  57. PB9_PF_SD2_CLK,
  58. SD2_CD | GPIO_GPIO | GPIO_IN,
  59. /* FEC */
  60. PD0_AIN_FEC_TXD0,
  61. PD1_AIN_FEC_TXD1,
  62. PD2_AIN_FEC_TXD2,
  63. PD3_AIN_FEC_TXD3,
  64. PD4_AOUT_FEC_RX_ER,
  65. PD5_AOUT_FEC_RXD1,
  66. PD6_AOUT_FEC_RXD2,
  67. PD7_AOUT_FEC_RXD3,
  68. PD8_AF_FEC_MDIO,
  69. PD9_AIN_FEC_MDC,
  70. PD10_AOUT_FEC_CRS,
  71. PD11_AOUT_FEC_TX_CLK,
  72. PD12_AOUT_FEC_RXD0,
  73. PD13_AOUT_FEC_RX_DV,
  74. PD14_AOUT_FEC_RX_CLK,
  75. PD15_AOUT_FEC_COL,
  76. PD16_AIN_FEC_TX_ER,
  77. PF23_AIN_FEC_TX_EN,
  78. /* SSI1 */
  79. PC20_PF_SSI1_FS,
  80. PC21_PF_SSI1_RXD,
  81. PC22_PF_SSI1_TXD,
  82. PC23_PF_SSI1_CLK,
  83. /* onboard I2C */
  84. PC5_PF_I2C2_SDA,
  85. PC6_PF_I2C2_SCL,
  86. /* external I2C */
  87. PD17_PF_I2C_DATA,
  88. PD18_PF_I2C_CLK,
  89. /* SPI1 */
  90. PD25_PF_CSPI1_RDY,
  91. PD29_PF_CSPI1_SCLK,
  92. PD30_PF_CSPI1_MISO,
  93. PD31_PF_CSPI1_MOSI,
  94. /* OTG */
  95. OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
  96. PC7_PF_USBOTG_DATA5,
  97. PC8_PF_USBOTG_DATA6,
  98. PC9_PF_USBOTG_DATA0,
  99. PC10_PF_USBOTG_DATA2,
  100. PC11_PF_USBOTG_DATA1,
  101. PC12_PF_USBOTG_DATA4,
  102. PC13_PF_USBOTG_DATA3,
  103. PE0_PF_USBOTG_NXT,
  104. PE1_PF_USBOTG_STP,
  105. PE2_PF_USBOTG_DIR,
  106. PE24_PF_USBOTG_CLK,
  107. PE25_PF_USBOTG_DATA7,
  108. /* USBH2 */
  109. USBH2_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
  110. PA0_PF_USBH2_CLK,
  111. PA1_PF_USBH2_DIR,
  112. PA2_PF_USBH2_DATA7,
  113. PA3_PF_USBH2_NXT,
  114. PA4_PF_USBH2_STP,
  115. PD19_AF_USBH2_DATA4,
  116. PD20_AF_USBH2_DATA3,
  117. PD21_AF_USBH2_DATA6,
  118. PD22_AF_USBH2_DATA0,
  119. PD23_AF_USBH2_DATA2,
  120. PD24_AF_USBH2_DATA1,
  121. PD26_AF_USBH2_DATA5,
  122. /* display */
  123. PA5_PF_LSCLK,
  124. PA6_PF_LD0,
  125. PA7_PF_LD1,
  126. PA8_PF_LD2,
  127. PA9_PF_LD3,
  128. PA10_PF_LD4,
  129. PA11_PF_LD5,
  130. PA12_PF_LD6,
  131. PA13_PF_LD7,
  132. PA14_PF_LD8,
  133. PA15_PF_LD9,
  134. PA16_PF_LD10,
  135. PA17_PF_LD11,
  136. PA18_PF_LD12,
  137. PA19_PF_LD13,
  138. PA20_PF_LD14,
  139. PA21_PF_LD15,
  140. PA22_PF_LD16,
  141. PA23_PF_LD17,
  142. PA26_PF_PS,
  143. PA28_PF_HSYNC,
  144. PA29_PF_VSYNC,
  145. PA31_PF_OE_ACD,
  146. /* free GPIO */
  147. GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN, /* GPIO0_IRQ */
  148. GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN, /* GPIO1_IRQ */
  149. GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN, /* GPIO2_IRQ */
  150. };
  151. static const struct imxuart_platform_data uart_pdata __initconst = {
  152. .flags = IMXUART_HAVE_RTSCTS,
  153. };
  154. static const struct mxc_nand_platform_data
  155. pca100_nand_board_info __initconst = {
  156. .width = 1,
  157. .hw_ecc = 1,
  158. };
  159. static const struct imxi2c_platform_data pca100_i2c1_data __initconst = {
  160. .bitrate = 100000,
  161. };
  162. static struct at24_platform_data board_eeprom = {
  163. .byte_len = 4096,
  164. .page_size = 32,
  165. .flags = AT24_FLAG_ADDR16,
  166. };
  167. static struct i2c_board_info pca100_i2c_devices[] = {
  168. {
  169. I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
  170. .platform_data = &board_eeprom,
  171. }, {
  172. I2C_BOARD_INFO("pcf8563", 0x51),
  173. }, {
  174. I2C_BOARD_INFO("lm75", 0x4a),
  175. }
  176. };
  177. static struct spi_eeprom at25320 = {
  178. .name = "at25320an",
  179. .byte_len = 4096,
  180. .page_size = 32,
  181. .flags = EE_ADDR2,
  182. };
  183. static struct spi_board_info pca100_spi_board_info[] __initdata = {
  184. {
  185. .modalias = "at25",
  186. .max_speed_hz = 30000,
  187. .bus_num = 0,
  188. .chip_select = 1,
  189. .platform_data = &at25320,
  190. },
  191. };
  192. static int pca100_spi_cs[] = {SPI1_SS0, SPI1_SS1};
  193. static const struct spi_imx_master pca100_spi0_data __initconst = {
  194. .chipselect = pca100_spi_cs,
  195. .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
  196. };
  197. static void pca100_ac97_warm_reset(struct snd_ac97 *ac97)
  198. {
  199. mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT);
  200. gpio_set_value(GPIO_PORTC + 20, 1);
  201. udelay(2);
  202. gpio_set_value(GPIO_PORTC + 20, 0);
  203. mxc_gpio_mode(PC20_PF_SSI1_FS);
  204. msleep(2);
  205. }
  206. static void pca100_ac97_cold_reset(struct snd_ac97 *ac97)
  207. {
  208. mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT); /* FS */
  209. gpio_set_value(GPIO_PORTC + 20, 0);
  210. mxc_gpio_mode(GPIO_PORTC | 22 | GPIO_GPIO | GPIO_OUT); /* TX */
  211. gpio_set_value(GPIO_PORTC + 22, 0);
  212. mxc_gpio_mode(GPIO_PORTC | 28 | GPIO_GPIO | GPIO_OUT); /* reset */
  213. gpio_set_value(GPIO_PORTC + 28, 0);
  214. udelay(10);
  215. gpio_set_value(GPIO_PORTC + 28, 1);
  216. mxc_gpio_mode(PC20_PF_SSI1_FS);
  217. mxc_gpio_mode(PC22_PF_SSI1_TXD);
  218. msleep(2);
  219. }
  220. static const struct imx_ssi_platform_data pca100_ssi_pdata __initconst = {
  221. .ac97_reset = pca100_ac97_cold_reset,
  222. .ac97_warm_reset = pca100_ac97_warm_reset,
  223. .flags = IMX_SSI_USE_AC97,
  224. };
  225. static int pca100_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
  226. void *data)
  227. {
  228. int ret;
  229. ret = request_irq(gpio_to_irq(IMX_GPIO_NR(3, 29)), detect_irq,
  230. IRQF_TRIGGER_FALLING, "imx-mmc-detect", data);
  231. if (ret)
  232. printk(KERN_ERR
  233. "pca100: Failed to request irq for sd/mmc detection\n");
  234. return ret;
  235. }
  236. static void pca100_sdhc2_exit(struct device *dev, void *data)
  237. {
  238. free_irq(gpio_to_irq(IMX_GPIO_NR(3, 29)), data);
  239. }
  240. static const struct imxmmc_platform_data sdhc_pdata __initconst = {
  241. .init = pca100_sdhc2_init,
  242. .exit = pca100_sdhc2_exit,
  243. };
  244. static int otg_phy_init(struct platform_device *pdev)
  245. {
  246. gpio_set_value(OTG_PHY_CS_GPIO, 0);
  247. mdelay(10);
  248. return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_INTERFACE_DIFF_UNI);
  249. }
  250. static struct mxc_usbh_platform_data otg_pdata __initdata = {
  251. .init = otg_phy_init,
  252. .portsc = MXC_EHCI_MODE_ULPI,
  253. };
  254. static int usbh2_phy_init(struct platform_device *pdev)
  255. {
  256. gpio_set_value(USBH2_PHY_CS_GPIO, 0);
  257. mdelay(10);
  258. return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_INTERFACE_DIFF_UNI);
  259. }
  260. static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
  261. .init = usbh2_phy_init,
  262. .portsc = MXC_EHCI_MODE_ULPI,
  263. };
  264. static const struct fsl_usb2_platform_data otg_device_pdata __initconst = {
  265. .operating_mode = FSL_USB2_DR_DEVICE,
  266. .phy_mode = FSL_USB2_PHY_ULPI,
  267. };
  268. static bool otg_mode_host __initdata;
  269. static int __init pca100_otg_mode(char *options)
  270. {
  271. if (!strcmp(options, "host"))
  272. otg_mode_host = true;
  273. else if (!strcmp(options, "device"))
  274. otg_mode_host = false;
  275. else
  276. pr_info("otg_mode neither \"host\" nor \"device\". "
  277. "Defaulting to device\n");
  278. return 1;
  279. }
  280. __setup("otg_mode=", pca100_otg_mode);
  281. /* framebuffer info */
  282. static struct imx_fb_videomode pca100_fb_modes[] = {
  283. {
  284. .mode = {
  285. .name = "EMERGING-ETV570G0DHU",
  286. .refresh = 60,
  287. .xres = 640,
  288. .yres = 480,
  289. .pixclock = 39722, /* in ps (25.175 MHz) */
  290. .hsync_len = 30,
  291. .left_margin = 114,
  292. .right_margin = 16,
  293. .vsync_len = 3,
  294. .upper_margin = 32,
  295. .lower_margin = 0,
  296. },
  297. /*
  298. * TFT
  299. * Pixel pol active high
  300. * HSYNC active low
  301. * VSYNC active low
  302. * use HSYNC for ACD count
  303. * line clock disable while idle
  304. * always enable line clock even if no data
  305. */
  306. .pcr = 0xf0c08080,
  307. .bpp = 16,
  308. },
  309. };
  310. static const struct imx_fb_platform_data pca100_fb_data __initconst = {
  311. .mode = pca100_fb_modes,
  312. .num_modes = ARRAY_SIZE(pca100_fb_modes),
  313. .pwmr = 0x00A903FF,
  314. .lscr1 = 0x00120300,
  315. .dmacr = 0x00020010,
  316. };
  317. static void __init pca100_init(void)
  318. {
  319. int ret;
  320. imx27_soc_init();
  321. ret = mxc_gpio_setup_multiple_pins(pca100_pins,
  322. ARRAY_SIZE(pca100_pins), "PCA100");
  323. if (ret)
  324. printk(KERN_ERR "pca100: Failed to setup pins (%d)\n", ret);
  325. imx27_add_imx_uart0(&uart_pdata);
  326. imx27_add_mxc_nand(&pca100_nand_board_info);
  327. /* only the i2c master 1 is used on this CPU card */
  328. i2c_register_board_info(1, pca100_i2c_devices,
  329. ARRAY_SIZE(pca100_i2c_devices));
  330. imx27_add_imx_i2c(1, &pca100_i2c1_data);
  331. mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_IN);
  332. mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_IN);
  333. spi_register_board_info(pca100_spi_board_info,
  334. ARRAY_SIZE(pca100_spi_board_info));
  335. imx27_add_spi_imx0(&pca100_spi0_data);
  336. imx27_add_imx_fb(&pca100_fb_data);
  337. imx27_add_fec(NULL);
  338. imx27_add_imx2_wdt();
  339. imx27_add_mxc_w1();
  340. }
  341. static void __init pca100_late_init(void)
  342. {
  343. imx27_add_imx_ssi(0, &pca100_ssi_pdata);
  344. imx27_add_mxc_mmc(1, &sdhc_pdata);
  345. gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs");
  346. gpio_direction_output(OTG_PHY_CS_GPIO, 1);
  347. gpio_request(USBH2_PHY_CS_GPIO, "usb-host2-cs");
  348. gpio_direction_output(USBH2_PHY_CS_GPIO, 1);
  349. if (otg_mode_host) {
  350. otg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
  351. ULPI_OTG_DRVVBUS_EXT);
  352. if (otg_pdata.otg)
  353. imx27_add_mxc_ehci_otg(&otg_pdata);
  354. } else {
  355. gpio_set_value(OTG_PHY_CS_GPIO, 0);
  356. imx27_add_fsl_usb2_udc(&otg_device_pdata);
  357. }
  358. usbh2_pdata.otg = imx_otg_ulpi_create(
  359. ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
  360. if (usbh2_pdata.otg)
  361. imx27_add_mxc_ehci_hs(2, &usbh2_pdata);
  362. }
  363. static void __init pca100_timer_init(void)
  364. {
  365. mx27_clocks_init(26000000);
  366. }
  367. MACHINE_START(PCA100, "phyCARD-i.MX27")
  368. .atag_offset = 0x100,
  369. .map_io = mx27_map_io,
  370. .init_early = imx27_init_early,
  371. .init_irq = mx27_init_irq,
  372. .init_machine = pca100_init,
  373. .init_late = pca100_late_init,
  374. .init_time = pca100_timer_init,
  375. .restart = mxc_restart,
  376. MACHINE_END