mach-pca100.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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 <mach/i2c.h>
  38. #include <asm/mach/time.h>
  39. #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
  40. #include <mach/spi.h>
  41. #endif
  42. #include <mach/imx-uart.h>
  43. #include <mach/audmux.h>
  44. #include <mach/ssi.h>
  45. #include <mach/mxc_nand.h>
  46. #include <mach/irqs.h>
  47. #include <mach/mmc.h>
  48. #include <mach/mxc_ehci.h>
  49. #include <mach/ulpi.h>
  50. #include "devices-imx27.h"
  51. #include "devices.h"
  52. #define OTG_PHY_CS_GPIO (GPIO_PORTB + 23)
  53. #define USBH2_PHY_CS_GPIO (GPIO_PORTB + 24)
  54. static int pca100_pins[] = {
  55. /* UART1 */
  56. PE12_PF_UART1_TXD,
  57. PE13_PF_UART1_RXD,
  58. PE14_PF_UART1_CTS,
  59. PE15_PF_UART1_RTS,
  60. /* SDHC */
  61. PB4_PF_SD2_D0,
  62. PB5_PF_SD2_D1,
  63. PB6_PF_SD2_D2,
  64. PB7_PF_SD2_D3,
  65. PB8_PF_SD2_CMD,
  66. PB9_PF_SD2_CLK,
  67. /* FEC */
  68. PD0_AIN_FEC_TXD0,
  69. PD1_AIN_FEC_TXD1,
  70. PD2_AIN_FEC_TXD2,
  71. PD3_AIN_FEC_TXD3,
  72. PD4_AOUT_FEC_RX_ER,
  73. PD5_AOUT_FEC_RXD1,
  74. PD6_AOUT_FEC_RXD2,
  75. PD7_AOUT_FEC_RXD3,
  76. PD8_AF_FEC_MDIO,
  77. PD9_AIN_FEC_MDC,
  78. PD10_AOUT_FEC_CRS,
  79. PD11_AOUT_FEC_TX_CLK,
  80. PD12_AOUT_FEC_RXD0,
  81. PD13_AOUT_FEC_RX_DV,
  82. PD14_AOUT_FEC_RX_CLK,
  83. PD15_AOUT_FEC_COL,
  84. PD16_AIN_FEC_TX_ER,
  85. PF23_AIN_FEC_TX_EN,
  86. /* SSI1 */
  87. PC20_PF_SSI1_FS,
  88. PC21_PF_SSI1_RXD,
  89. PC22_PF_SSI1_TXD,
  90. PC23_PF_SSI1_CLK,
  91. /* onboard I2C */
  92. PC5_PF_I2C2_SDA,
  93. PC6_PF_I2C2_SCL,
  94. /* external I2C */
  95. PD17_PF_I2C_DATA,
  96. PD18_PF_I2C_CLK,
  97. /* SPI1 */
  98. PD25_PF_CSPI1_RDY,
  99. PD29_PF_CSPI1_SCLK,
  100. PD30_PF_CSPI1_MISO,
  101. PD31_PF_CSPI1_MOSI,
  102. /* OTG */
  103. OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
  104. PC7_PF_USBOTG_DATA5,
  105. PC8_PF_USBOTG_DATA6,
  106. PC9_PF_USBOTG_DATA0,
  107. PC10_PF_USBOTG_DATA2,
  108. PC11_PF_USBOTG_DATA1,
  109. PC12_PF_USBOTG_DATA4,
  110. PC13_PF_USBOTG_DATA3,
  111. PE0_PF_USBOTG_NXT,
  112. PE1_PF_USBOTG_STP,
  113. PE2_PF_USBOTG_DIR,
  114. PE24_PF_USBOTG_CLK,
  115. PE25_PF_USBOTG_DATA7,
  116. /* USBH2 */
  117. USBH2_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
  118. PA0_PF_USBH2_CLK,
  119. PA1_PF_USBH2_DIR,
  120. PA2_PF_USBH2_DATA7,
  121. PA3_PF_USBH2_NXT,
  122. PA4_PF_USBH2_STP,
  123. PD19_AF_USBH2_DATA4,
  124. PD20_AF_USBH2_DATA3,
  125. PD21_AF_USBH2_DATA6,
  126. PD22_AF_USBH2_DATA0,
  127. PD23_AF_USBH2_DATA2,
  128. PD24_AF_USBH2_DATA1,
  129. PD26_AF_USBH2_DATA5,
  130. };
  131. static struct imxuart_platform_data uart_pdata = {
  132. .flags = IMXUART_HAVE_RTSCTS,
  133. };
  134. static const struct mxc_nand_platform_data
  135. pca100_nand_board_info __initconst = {
  136. .width = 1,
  137. .hw_ecc = 1,
  138. };
  139. static struct platform_device *platform_devices[] __initdata = {
  140. &mxc_w1_master_device,
  141. &mxc_fec_device,
  142. &mxc_wdt,
  143. };
  144. static struct imxi2c_platform_data pca100_i2c_1_data = {
  145. .bitrate = 100000,
  146. };
  147. static struct at24_platform_data board_eeprom = {
  148. .byte_len = 4096,
  149. .page_size = 32,
  150. .flags = AT24_FLAG_ADDR16,
  151. };
  152. static struct i2c_board_info pca100_i2c_devices[] = {
  153. {
  154. I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
  155. .platform_data = &board_eeprom,
  156. }, {
  157. I2C_BOARD_INFO("rtc-pcf8563", 0x51),
  158. .type = "pcf8563"
  159. }, {
  160. I2C_BOARD_INFO("lm75", 0x4a),
  161. .type = "lm75"
  162. }
  163. };
  164. #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
  165. static struct spi_eeprom at25320 = {
  166. .name = "at25320an",
  167. .byte_len = 4096,
  168. .page_size = 32,
  169. .flags = EE_ADDR2,
  170. };
  171. static struct spi_board_info pca100_spi_board_info[] __initdata = {
  172. {
  173. .modalias = "at25",
  174. .max_speed_hz = 30000,
  175. .bus_num = 0,
  176. .chip_select = 1,
  177. .platform_data = &at25320,
  178. },
  179. };
  180. static int pca100_spi_cs[] = {GPIO_PORTD + 28, GPIO_PORTD + 27};
  181. static struct spi_imx_master pca100_spi_0_data = {
  182. .chipselect = pca100_spi_cs,
  183. .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
  184. };
  185. #endif
  186. static void pca100_ac97_warm_reset(struct snd_ac97 *ac97)
  187. {
  188. mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT);
  189. gpio_set_value(GPIO_PORTC + 20, 1);
  190. udelay(2);
  191. gpio_set_value(GPIO_PORTC + 20, 0);
  192. mxc_gpio_mode(PC20_PF_SSI1_FS);
  193. msleep(2);
  194. }
  195. static void pca100_ac97_cold_reset(struct snd_ac97 *ac97)
  196. {
  197. mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT); /* FS */
  198. gpio_set_value(GPIO_PORTC + 20, 0);
  199. mxc_gpio_mode(GPIO_PORTC | 22 | GPIO_GPIO | GPIO_OUT); /* TX */
  200. gpio_set_value(GPIO_PORTC + 22, 0);
  201. mxc_gpio_mode(GPIO_PORTC | 28 | GPIO_GPIO | GPIO_OUT); /* reset */
  202. gpio_set_value(GPIO_PORTC + 28, 0);
  203. udelay(10);
  204. gpio_set_value(GPIO_PORTC + 28, 1);
  205. mxc_gpio_mode(PC20_PF_SSI1_FS);
  206. mxc_gpio_mode(PC22_PF_SSI1_TXD);
  207. msleep(2);
  208. }
  209. static struct imx_ssi_platform_data pca100_ssi_pdata = {
  210. .ac97_reset = pca100_ac97_cold_reset,
  211. .ac97_warm_reset = pca100_ac97_warm_reset,
  212. .flags = IMX_SSI_USE_AC97,
  213. };
  214. static int pca100_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
  215. void *data)
  216. {
  217. int ret;
  218. ret = request_irq(IRQ_GPIOC(29), detect_irq,
  219. IRQF_DISABLED | IRQF_TRIGGER_FALLING,
  220. "imx-mmc-detect", data);
  221. if (ret)
  222. printk(KERN_ERR
  223. "pca100: Failed to reuest irq for sd/mmc detection\n");
  224. return ret;
  225. }
  226. static void pca100_sdhc2_exit(struct device *dev, void *data)
  227. {
  228. free_irq(IRQ_GPIOC(29), data);
  229. }
  230. static struct imxmmc_platform_data sdhc_pdata = {
  231. .init = pca100_sdhc2_init,
  232. .exit = pca100_sdhc2_exit,
  233. };
  234. static int otg_phy_init(struct platform_device *pdev)
  235. {
  236. gpio_set_value(OTG_PHY_CS_GPIO, 0);
  237. return 0;
  238. }
  239. static struct mxc_usbh_platform_data otg_pdata = {
  240. .init = otg_phy_init,
  241. .portsc = MXC_EHCI_MODE_ULPI,
  242. .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
  243. };
  244. static int usbh2_phy_init(struct platform_device *pdev)
  245. {
  246. gpio_set_value(USBH2_PHY_CS_GPIO, 0);
  247. return 0;
  248. }
  249. static struct mxc_usbh_platform_data usbh2_pdata = {
  250. .init = usbh2_phy_init,
  251. .portsc = MXC_EHCI_MODE_ULPI,
  252. .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
  253. };
  254. static struct fsl_usb2_platform_data otg_device_pdata = {
  255. .operating_mode = FSL_USB2_DR_DEVICE,
  256. .phy_mode = FSL_USB2_PHY_ULPI,
  257. };
  258. static int otg_mode_host;
  259. static int __init pca100_otg_mode(char *options)
  260. {
  261. if (!strcmp(options, "host"))
  262. otg_mode_host = 1;
  263. else if (!strcmp(options, "device"))
  264. otg_mode_host = 0;
  265. else
  266. pr_info("otg_mode neither \"host\" nor \"device\". "
  267. "Defaulting to device\n");
  268. return 0;
  269. }
  270. __setup("otg_mode=", pca100_otg_mode);
  271. static void __init pca100_init(void)
  272. {
  273. int ret;
  274. /* SSI unit */
  275. mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
  276. MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
  277. MXC_AUDMUX_V1_PCR_TFCSEL(3) |
  278. MXC_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */
  279. MXC_AUDMUX_V1_PCR_RXDSEL(3));
  280. mxc_audmux_v1_configure_port(3,
  281. MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
  282. MXC_AUDMUX_V1_PCR_TFCSEL(0) |
  283. MXC_AUDMUX_V1_PCR_TFSDIR |
  284. MXC_AUDMUX_V1_PCR_RXDSEL(0));
  285. ret = mxc_gpio_setup_multiple_pins(pca100_pins,
  286. ARRAY_SIZE(pca100_pins), "PCA100");
  287. if (ret)
  288. printk(KERN_ERR "pca100: Failed to setup pins (%d)\n", ret);
  289. mxc_register_device(&imx_ssi_device0, &pca100_ssi_pdata);
  290. mxc_register_device(&imx2x_uart_device0, &uart_pdata);
  291. mxc_gpio_mode(GPIO_PORTC | 29 | GPIO_GPIO | GPIO_IN);
  292. mxc_register_device(&mxc_sdhc_device1, &sdhc_pdata);
  293. imx27_add_mxc_nand(&pca100_nand_board_info);
  294. /* only the i2c master 1 is used on this CPU card */
  295. i2c_register_board_info(1, pca100_i2c_devices,
  296. ARRAY_SIZE(pca100_i2c_devices));
  297. mxc_register_device(&mxc_i2c_device1, &pca100_i2c_1_data);
  298. mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
  299. mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_OUT);
  300. /* GPIO0_IRQ */
  301. mxc_gpio_mode(GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN);
  302. /* GPIO1_IRQ */
  303. mxc_gpio_mode(GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN);
  304. /* GPIO2_IRQ */
  305. mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN);
  306. #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
  307. spi_register_board_info(pca100_spi_board_info,
  308. ARRAY_SIZE(pca100_spi_board_info));
  309. mxc_register_device(&mxc_spi_device0, &pca100_spi_0_data);
  310. #endif
  311. gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs");
  312. gpio_direction_output(OTG_PHY_CS_GPIO, 1);
  313. gpio_request(USBH2_PHY_CS_GPIO, "usb-host2-cs");
  314. gpio_direction_output(USBH2_PHY_CS_GPIO, 1);
  315. #if defined(CONFIG_USB_ULPI)
  316. if (otg_mode_host) {
  317. otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
  318. USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
  319. mxc_register_device(&mxc_otg_host, &otg_pdata);
  320. }
  321. usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
  322. USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
  323. mxc_register_device(&mxc_usbh2, &usbh2_pdata);
  324. #endif
  325. if (!otg_mode_host) {
  326. gpio_set_value(OTG_PHY_CS_GPIO, 0);
  327. mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
  328. }
  329. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  330. }
  331. static void __init pca100_timer_init(void)
  332. {
  333. mx27_clocks_init(26000000);
  334. }
  335. static struct sys_timer pca100_timer = {
  336. .init = pca100_timer_init,
  337. };
  338. MACHINE_START(PCA100, "phyCARD-i.MX27")
  339. .phys_io = MX27_AIPI_BASE_ADDR,
  340. .io_pg_offst = ((MX27_AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc,
  341. .boot_params = MX27_PHYS_OFFSET + 0x100,
  342. .map_io = mx27_map_io,
  343. .init_irq = mx27_init_irq,
  344. .init_machine = pca100_init,
  345. .timer = &pca100_timer,
  346. MACHINE_END