mach-pca100.c 10 KB

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