mach-pca100.c 11 KB

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