blob: 2164b7f96ef202aaaab2c78a3a76e4f542a1a60b [file] [log] [blame]
Luotao Fu33731692009-08-06 11:19:39 +02001/*
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
20#include <linux/platform_device.h>
21#include <linux/io.h>
22#include <linux/i2c.h>
23#include <linux/i2c/at24.h>
24#include <linux/dma-mapping.h>
25#include <linux/spi/spi.h>
26#include <linux/spi/eeprom.h>
27#include <linux/irq.h>
Sascha Hauerc8a68852010-02-08 16:42:28 +010028#include <linux/delay.h>
Luotao Fu33731692009-08-06 11:19:39 +020029#include <linux/gpio.h>
Sascha Hauereee7c492010-02-03 17:13:29 +010030#include <linux/usb/otg.h>
31#include <linux/usb/ulpi.h>
32#include <linux/fsl_devices.h>
Luotao Fu33731692009-08-06 11:19:39 +020033
34#include <asm/mach/arch.h>
35#include <asm/mach-types.h>
36#include <mach/common.h>
37#include <mach/hardware.h>
Uwe Kleine-Könige835d882010-02-16 11:07:49 +010038#include <mach/iomux-mx27.h>
Luotao Fu33731692009-08-06 11:19:39 +020039#include <mach/i2c.h>
40#include <asm/mach/time.h>
41#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
42#include <mach/spi.h>
43#endif
44#include <mach/imx-uart.h>
Sascha Hauerc8a68852010-02-08 16:42:28 +010045#include <mach/audmux.h>
46#include <mach/ssi.h>
Luotao Fu33731692009-08-06 11:19:39 +020047#include <mach/mxc_nand.h>
48#include <mach/irqs.h>
49#include <mach/mmc.h>
Sascha Hauereee7c492010-02-03 17:13:29 +010050#include <mach/mxc_ehci.h>
51#include <mach/ulpi.h>
Luotao Fu42216fc2010-06-18 09:23:18 +020052#include <mach/imxfb.h>
Luotao Fu33731692009-08-06 11:19:39 +020053
54#include "devices.h"
55
Sascha Hauereee7c492010-02-03 17:13:29 +010056#define OTG_PHY_CS_GPIO (GPIO_PORTB + 23)
57#define USBH2_PHY_CS_GPIO (GPIO_PORTB + 24)
Luotao Fub725aba2010-06-18 09:23:19 +020058#define SPI1_SS0 (GPIO_PORTD + 28)
59#define SPI1_SS1 (GPIO_PORTD + 27)
60#define SD2_CD (GPIO_PORTC + 29)
Sascha Hauereee7c492010-02-03 17:13:29 +010061
Luotao Fu33731692009-08-06 11:19:39 +020062static int pca100_pins[] = {
63 /* UART1 */
64 PE12_PF_UART1_TXD,
65 PE13_PF_UART1_RXD,
66 PE14_PF_UART1_CTS,
67 PE15_PF_UART1_RTS,
68 /* SDHC */
69 PB4_PF_SD2_D0,
70 PB5_PF_SD2_D1,
71 PB6_PF_SD2_D2,
72 PB7_PF_SD2_D3,
73 PB8_PF_SD2_CMD,
74 PB9_PF_SD2_CLK,
Luotao Fub725aba2010-06-18 09:23:19 +020075 SD2_CD | GPIO_GPIO | GPIO_IN,
Luotao Fu33731692009-08-06 11:19:39 +020076 /* FEC */
77 PD0_AIN_FEC_TXD0,
78 PD1_AIN_FEC_TXD1,
79 PD2_AIN_FEC_TXD2,
80 PD3_AIN_FEC_TXD3,
81 PD4_AOUT_FEC_RX_ER,
82 PD5_AOUT_FEC_RXD1,
83 PD6_AOUT_FEC_RXD2,
84 PD7_AOUT_FEC_RXD3,
85 PD8_AF_FEC_MDIO,
86 PD9_AIN_FEC_MDC,
87 PD10_AOUT_FEC_CRS,
88 PD11_AOUT_FEC_TX_CLK,
89 PD12_AOUT_FEC_RXD0,
90 PD13_AOUT_FEC_RX_DV,
91 PD14_AOUT_FEC_RX_CLK,
92 PD15_AOUT_FEC_COL,
93 PD16_AIN_FEC_TX_ER,
94 PF23_AIN_FEC_TX_EN,
95 /* SSI1 */
96 PC20_PF_SSI1_FS,
97 PC21_PF_SSI1_RXD,
98 PC22_PF_SSI1_TXD,
99 PC23_PF_SSI1_CLK,
100 /* onboard I2C */
101 PC5_PF_I2C2_SDA,
102 PC6_PF_I2C2_SCL,
103 /* external I2C */
104 PD17_PF_I2C_DATA,
105 PD18_PF_I2C_CLK,
106 /* SPI1 */
107 PD25_PF_CSPI1_RDY,
108 PD29_PF_CSPI1_SCLK,
109 PD30_PF_CSPI1_MISO,
110 PD31_PF_CSPI1_MOSI,
Sascha Hauereee7c492010-02-03 17:13:29 +0100111 /* OTG */
112 OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
113 PC7_PF_USBOTG_DATA5,
114 PC8_PF_USBOTG_DATA6,
115 PC9_PF_USBOTG_DATA0,
116 PC10_PF_USBOTG_DATA2,
117 PC11_PF_USBOTG_DATA1,
118 PC12_PF_USBOTG_DATA4,
119 PC13_PF_USBOTG_DATA3,
120 PE0_PF_USBOTG_NXT,
121 PE1_PF_USBOTG_STP,
122 PE2_PF_USBOTG_DIR,
123 PE24_PF_USBOTG_CLK,
124 PE25_PF_USBOTG_DATA7,
125 /* USBH2 */
126 USBH2_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
127 PA0_PF_USBH2_CLK,
128 PA1_PF_USBH2_DIR,
129 PA2_PF_USBH2_DATA7,
130 PA3_PF_USBH2_NXT,
131 PA4_PF_USBH2_STP,
132 PD19_AF_USBH2_DATA4,
133 PD20_AF_USBH2_DATA3,
134 PD21_AF_USBH2_DATA6,
135 PD22_AF_USBH2_DATA0,
136 PD23_AF_USBH2_DATA2,
137 PD24_AF_USBH2_DATA1,
138 PD26_AF_USBH2_DATA5,
Luotao Fu42216fc2010-06-18 09:23:18 +0200139 /* display */
140 PA5_PF_LSCLK,
141 PA6_PF_LD0,
142 PA7_PF_LD1,
143 PA8_PF_LD2,
144 PA9_PF_LD3,
145 PA10_PF_LD4,
146 PA11_PF_LD5,
147 PA12_PF_LD6,
148 PA13_PF_LD7,
149 PA14_PF_LD8,
150 PA15_PF_LD9,
151 PA16_PF_LD10,
152 PA17_PF_LD11,
153 PA18_PF_LD12,
154 PA19_PF_LD13,
155 PA20_PF_LD14,
156 PA21_PF_LD15,
157 PA22_PF_LD16,
158 PA23_PF_LD17,
159 PA26_PF_PS,
160 PA28_PF_HSYNC,
161 PA29_PF_VSYNC,
162 PA31_PF_OE_ACD,
Luotao Fub725aba2010-06-18 09:23:19 +0200163 /* free GPIO */
164 GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN, /* GPIO0_IRQ */
165 GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN, /* GPIO1_IRQ */
166 GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN, /* GPIO2_IRQ */
Luotao Fu33731692009-08-06 11:19:39 +0200167};
168
169static struct imxuart_platform_data uart_pdata = {
170 .flags = IMXUART_HAVE_RTSCTS,
171};
172
173static struct mxc_nand_platform_data pca100_nand_board_info = {
174 .width = 1,
175 .hw_ecc = 1,
176};
177
178static struct platform_device *platform_devices[] __initdata = {
179 &mxc_w1_master_device,
180 &mxc_fec_device,
Wolfram Sangf13899d2010-04-29 10:03:20 +0200181 &mxc_wdt,
Luotao Fu33731692009-08-06 11:19:39 +0200182};
183
184static struct imxi2c_platform_data pca100_i2c_1_data = {
185 .bitrate = 100000,
186};
187
188static struct at24_platform_data board_eeprom = {
189 .byte_len = 4096,
190 .page_size = 32,
191 .flags = AT24_FLAG_ADDR16,
192};
193
194static struct i2c_board_info pca100_i2c_devices[] = {
195 {
196 I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
197 .platform_data = &board_eeprom,
198 }, {
199 I2C_BOARD_INFO("rtc-pcf8563", 0x51),
200 .type = "pcf8563"
201 }, {
202 I2C_BOARD_INFO("lm75", 0x4a),
203 .type = "lm75"
204 }
205};
206
207#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
208static struct spi_eeprom at25320 = {
209 .name = "at25320an",
210 .byte_len = 4096,
211 .page_size = 32,
212 .flags = EE_ADDR2,
213};
214
215static struct spi_board_info pca100_spi_board_info[] __initdata = {
216 {
217 .modalias = "at25",
218 .max_speed_hz = 30000,
219 .bus_num = 0,
220 .chip_select = 1,
221 .platform_data = &at25320,
222 },
223};
224
Luotao Fub725aba2010-06-18 09:23:19 +0200225static int pca100_spi_cs[] = {SPI1_SS0, SPI1_SS1};
Luotao Fu33731692009-08-06 11:19:39 +0200226
227static struct spi_imx_master pca100_spi_0_data = {
228 .chipselect = pca100_spi_cs,
229 .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
230};
231#endif
232
Sascha Hauerc8a68852010-02-08 16:42:28 +0100233static void pca100_ac97_warm_reset(struct snd_ac97 *ac97)
234{
235 mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT);
236 gpio_set_value(GPIO_PORTC + 20, 1);
237 udelay(2);
238 gpio_set_value(GPIO_PORTC + 20, 0);
239 mxc_gpio_mode(PC20_PF_SSI1_FS);
240 msleep(2);
241}
242
243static void pca100_ac97_cold_reset(struct snd_ac97 *ac97)
244{
245 mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT); /* FS */
246 gpio_set_value(GPIO_PORTC + 20, 0);
247 mxc_gpio_mode(GPIO_PORTC | 22 | GPIO_GPIO | GPIO_OUT); /* TX */
248 gpio_set_value(GPIO_PORTC + 22, 0);
249 mxc_gpio_mode(GPIO_PORTC | 28 | GPIO_GPIO | GPIO_OUT); /* reset */
250 gpio_set_value(GPIO_PORTC + 28, 0);
251 udelay(10);
252 gpio_set_value(GPIO_PORTC + 28, 1);
253 mxc_gpio_mode(PC20_PF_SSI1_FS);
254 mxc_gpio_mode(PC22_PF_SSI1_TXD);
255 msleep(2);
256}
257
258static struct imx_ssi_platform_data pca100_ssi_pdata = {
259 .ac97_reset = pca100_ac97_cold_reset,
260 .ac97_warm_reset = pca100_ac97_warm_reset,
261 .flags = IMX_SSI_USE_AC97,
262};
263
Luotao Fu33731692009-08-06 11:19:39 +0200264static int pca100_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
265 void *data)
266{
267 int ret;
268
269 ret = request_irq(IRQ_GPIOC(29), detect_irq,
270 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
271 "imx-mmc-detect", data);
272 if (ret)
273 printk(KERN_ERR
274 "pca100: Failed to reuest irq for sd/mmc detection\n");
275
276 return ret;
277}
278
279static void pca100_sdhc2_exit(struct device *dev, void *data)
280{
281 free_irq(IRQ_GPIOC(29), data);
282}
283
284static struct imxmmc_platform_data sdhc_pdata = {
285 .init = pca100_sdhc2_init,
286 .exit = pca100_sdhc2_exit,
287};
288
Wolfram Sangc18e8fa2010-05-21 06:52:06 +0200289#if defined(CONFIG_USB_ULPI)
Sascha Hauereee7c492010-02-03 17:13:29 +0100290static int otg_phy_init(struct platform_device *pdev)
291{
292 gpio_set_value(OTG_PHY_CS_GPIO, 0);
293 return 0;
294}
295
296static struct mxc_usbh_platform_data otg_pdata = {
297 .init = otg_phy_init,
298 .portsc = MXC_EHCI_MODE_ULPI,
299 .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
300};
301
302static int usbh2_phy_init(struct platform_device *pdev)
303{
304 gpio_set_value(USBH2_PHY_CS_GPIO, 0);
305 return 0;
306}
307
308static struct mxc_usbh_platform_data usbh2_pdata = {
309 .init = usbh2_phy_init,
310 .portsc = MXC_EHCI_MODE_ULPI,
311 .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
312};
Wolfram Sangc18e8fa2010-05-21 06:52:06 +0200313#endif
Sascha Hauereee7c492010-02-03 17:13:29 +0100314
315static struct fsl_usb2_platform_data otg_device_pdata = {
316 .operating_mode = FSL_USB2_DR_DEVICE,
317 .phy_mode = FSL_USB2_PHY_ULPI,
318};
319
320static int otg_mode_host;
321
322static int __init pca100_otg_mode(char *options)
323{
324 if (!strcmp(options, "host"))
325 otg_mode_host = 1;
326 else if (!strcmp(options, "device"))
327 otg_mode_host = 0;
328 else
329 pr_info("otg_mode neither \"host\" nor \"device\". "
330 "Defaulting to device\n");
331 return 0;
332}
333__setup("otg_mode=", pca100_otg_mode);
334
Luotao Fu42216fc2010-06-18 09:23:18 +0200335/* framebuffer info */
336static struct imx_fb_videomode pca100_fb_modes[] = {
337 {
338 .mode = {
339 .name = "EMERGING-ETV570G0DHU",
340 .refresh = 60,
341 .xres = 640,
342 .yres = 480,
343 .pixclock = 39722, /* in ps (25.175 MHz) */
344 .hsync_len = 30,
345 .left_margin = 114,
346 .right_margin = 16,
347 .vsync_len = 3,
348 .upper_margin = 32,
349 .lower_margin = 0,
350 },
351 /*
352 * TFT
353 * Pixel pol active high
354 * HSYNC active low
355 * VSYNC active low
356 * use HSYNC for ACD count
357 * line clock disable while idle
358 * always enable line clock even if no data
359 */
360 .pcr = 0xf0c08080,
361 .bpp = 16,
362 },
363};
364
365static struct imx_fb_platform_data pca100_fb_data = {
366 .mode = pca100_fb_modes,
367 .num_modes = ARRAY_SIZE(pca100_fb_modes),
368
369 .pwmr = 0x00A903FF,
370 .lscr1 = 0x00120300,
371 .dmacr = 0x00020010,
372};
373
Luotao Fu33731692009-08-06 11:19:39 +0200374static void __init pca100_init(void)
375{
376 int ret;
377
Sascha Hauerc8a68852010-02-08 16:42:28 +0100378 /* SSI unit */
379 mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
380 MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
381 MXC_AUDMUX_V1_PCR_TFCSEL(3) |
382 MXC_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */
383 MXC_AUDMUX_V1_PCR_RXDSEL(3));
384 mxc_audmux_v1_configure_port(3,
385 MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
386 MXC_AUDMUX_V1_PCR_TFCSEL(0) |
387 MXC_AUDMUX_V1_PCR_TFSDIR |
388 MXC_AUDMUX_V1_PCR_RXDSEL(0));
389
Luotao Fu33731692009-08-06 11:19:39 +0200390 ret = mxc_gpio_setup_multiple_pins(pca100_pins,
391 ARRAY_SIZE(pca100_pins), "PCA100");
392 if (ret)
393 printk(KERN_ERR "pca100: Failed to setup pins (%d)\n", ret);
394
Sascha Hauerc8a68852010-02-08 16:42:28 +0100395 mxc_register_device(&imx_ssi_device0, &pca100_ssi_pdata);
396
Luotao Fu33731692009-08-06 11:19:39 +0200397 mxc_register_device(&mxc_uart_device0, &uart_pdata);
398
Luotao Fu33731692009-08-06 11:19:39 +0200399 mxc_register_device(&mxc_sdhc_device1, &sdhc_pdata);
400
Uwe Kleine-König3636a142010-02-11 16:31:49 +0100401 mxc_register_device(&imx27_nand_device, &pca100_nand_board_info);
Luotao Fu33731692009-08-06 11:19:39 +0200402
403 /* only the i2c master 1 is used on this CPU card */
404 i2c_register_board_info(1, pca100_i2c_devices,
405 ARRAY_SIZE(pca100_i2c_devices));
406
407 mxc_register_device(&mxc_i2c_device1, &pca100_i2c_1_data);
408
Luotao Fu33731692009-08-06 11:19:39 +0200409#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
Luotao Fub725aba2010-06-18 09:23:19 +0200410 mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_IN);
411 mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_IN);
Luotao Fu33731692009-08-06 11:19:39 +0200412 spi_register_board_info(pca100_spi_board_info,
413 ARRAY_SIZE(pca100_spi_board_info));
414 mxc_register_device(&mxc_spi_device0, &pca100_spi_0_data);
415#endif
416
Sascha Hauereee7c492010-02-03 17:13:29 +0100417 gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs");
418 gpio_direction_output(OTG_PHY_CS_GPIO, 1);
419 gpio_request(USBH2_PHY_CS_GPIO, "usb-host2-cs");
420 gpio_direction_output(USBH2_PHY_CS_GPIO, 1);
421
422#if defined(CONFIG_USB_ULPI)
423 if (otg_mode_host) {
424 otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
425 USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
426
427 mxc_register_device(&mxc_otg_host, &otg_pdata);
428 }
429
430 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
431 USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
432
433 mxc_register_device(&mxc_usbh2, &usbh2_pdata);
434#endif
435 if (!otg_mode_host) {
436 gpio_set_value(OTG_PHY_CS_GPIO, 0);
437 mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
438 }
439
Luotao Fu42216fc2010-06-18 09:23:18 +0200440 mxc_register_device(&mxc_fb_device, &pca100_fb_data);
441
Luotao Fu33731692009-08-06 11:19:39 +0200442 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
443}
444
445static void __init pca100_timer_init(void)
446{
447 mx27_clocks_init(26000000);
448}
449
450static struct sys_timer pca100_timer = {
451 .init = pca100_timer_init,
452};
453
454MACHINE_START(PCA100, "phyCARD-i.MX27")
Uwe Kleine-König3f35d1f2009-12-09 11:32:11 +0100455 .phys_io = MX27_AIPI_BASE_ADDR,
456 .io_pg_offst = ((MX27_AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc,
Uwe Kleine-König34101232010-01-29 17:36:05 +0100457 .boot_params = MX27_PHYS_OFFSET + 0x100,
Luotao Fu33731692009-08-06 11:19:39 +0200458 .map_io = mx27_map_io,
Sascha Hauerf6f1bc62009-11-12 11:30:08 +0100459 .init_irq = mx27_init_irq,
Luotao Fu33731692009-08-06 11:19:39 +0200460 .init_machine = pca100_init,
461 .timer = &pca100_timer,
462MACHINE_END
463