blob: ff3cf1ef31b48bcc9f49fc7807fb203d7733bc25 [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 <asm/mach/time.h>
Sascha Hauerc8a68852010-02-08 16:42:28 +010040#include <mach/audmux.h>
41#include <mach/ssi.h>
Luotao Fu33731692009-08-06 11:19:39 +020042#include <mach/mxc_nand.h>
43#include <mach/irqs.h>
44#include <mach/mmc.h>
Sascha Hauereee7c492010-02-03 17:13:29 +010045#include <mach/mxc_ehci.h>
46#include <mach/ulpi.h>
Luotao Fu33731692009-08-06 11:19:39 +020047
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +020048#include "devices-imx27.h"
Luotao Fu33731692009-08-06 11:19:39 +020049#include "devices.h"
50
Sascha Hauereee7c492010-02-03 17:13:29 +010051#define OTG_PHY_CS_GPIO (GPIO_PORTB + 23)
52#define USBH2_PHY_CS_GPIO (GPIO_PORTB + 24)
53
Luotao Fu33731692009-08-06 11:19:39 +020054static 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,
Sascha Hauereee7c492010-02-03 17:13:29 +0100102 /* 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,
Luotao Fu33731692009-08-06 11:19:39 +0200130};
131
Uwe Kleine-Königd5dac4a2010-06-23 09:36:01 +0200132static const struct imxuart_platform_data uart_pdata __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200133 .flags = IMXUART_HAVE_RTSCTS,
134};
135
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +0200136static const struct mxc_nand_platform_data
137pca100_nand_board_info __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200138 .width = 1,
139 .hw_ecc = 1,
140};
141
142static struct platform_device *platform_devices[] __initdata = {
143 &mxc_w1_master_device,
144 &mxc_fec_device,
Wolfram Sangf13899d2010-04-29 10:03:20 +0200145 &mxc_wdt,
Luotao Fu33731692009-08-06 11:19:39 +0200146};
147
Uwe Kleine-Königc6987152010-06-16 17:25:40 +0200148static const struct imxi2c_platform_data pca100_i2c1_data __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200149 .bitrate = 100000,
150};
151
152static struct at24_platform_data board_eeprom = {
153 .byte_len = 4096,
154 .page_size = 32,
155 .flags = AT24_FLAG_ADDR16,
156};
157
158static struct i2c_board_info pca100_i2c_devices[] = {
159 {
160 I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
161 .platform_data = &board_eeprom,
162 }, {
163 I2C_BOARD_INFO("rtc-pcf8563", 0x51),
164 .type = "pcf8563"
165 }, {
166 I2C_BOARD_INFO("lm75", 0x4a),
167 .type = "lm75"
168 }
169};
170
171#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
172static struct spi_eeprom at25320 = {
173 .name = "at25320an",
174 .byte_len = 4096,
175 .page_size = 32,
176 .flags = EE_ADDR2,
177};
178
179static struct spi_board_info pca100_spi_board_info[] __initdata = {
180 {
181 .modalias = "at25",
182 .max_speed_hz = 30000,
183 .bus_num = 0,
184 .chip_select = 1,
185 .platform_data = &at25320,
186 },
187};
188
189static int pca100_spi_cs[] = {GPIO_PORTD + 28, GPIO_PORTD + 27};
190
Uwe Kleine-König7536cf92010-06-22 09:00:22 +0200191static const struct spi_imx_master pca100_spi0_data __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200192 .chipselect = pca100_spi_cs,
193 .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
194};
195#endif
196
Sascha Hauerc8a68852010-02-08 16:42:28 +0100197static 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
207static 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
222static struct imx_ssi_platform_data pca100_ssi_pdata = {
223 .ac97_reset = pca100_ac97_cold_reset,
224 .ac97_warm_reset = pca100_ac97_warm_reset,
225 .flags = IMX_SSI_USE_AC97,
226};
227
Luotao Fu33731692009-08-06 11:19:39 +0200228static int pca100_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
229 void *data)
230{
231 int ret;
232
233 ret = request_irq(IRQ_GPIOC(29), detect_irq,
234 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
235 "imx-mmc-detect", data);
236 if (ret)
237 printk(KERN_ERR
238 "pca100: Failed to reuest irq for sd/mmc detection\n");
239
240 return ret;
241}
242
243static void pca100_sdhc2_exit(struct device *dev, void *data)
244{
245 free_irq(IRQ_GPIOC(29), data);
246}
247
248static struct imxmmc_platform_data sdhc_pdata = {
249 .init = pca100_sdhc2_init,
250 .exit = pca100_sdhc2_exit,
251};
252
Sascha Hauereee7c492010-02-03 17:13:29 +0100253static int otg_phy_init(struct platform_device *pdev)
254{
255 gpio_set_value(OTG_PHY_CS_GPIO, 0);
256 return 0;
257}
258
259static struct mxc_usbh_platform_data otg_pdata = {
260 .init = otg_phy_init,
261 .portsc = MXC_EHCI_MODE_ULPI,
262 .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
263};
264
265static int usbh2_phy_init(struct platform_device *pdev)
266{
267 gpio_set_value(USBH2_PHY_CS_GPIO, 0);
268 return 0;
269}
270
271static struct mxc_usbh_platform_data usbh2_pdata = {
272 .init = usbh2_phy_init,
273 .portsc = MXC_EHCI_MODE_ULPI,
274 .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
275};
276
277static struct fsl_usb2_platform_data otg_device_pdata = {
278 .operating_mode = FSL_USB2_DR_DEVICE,
279 .phy_mode = FSL_USB2_PHY_ULPI,
280};
281
282static int otg_mode_host;
283
284static int __init pca100_otg_mode(char *options)
285{
286 if (!strcmp(options, "host"))
287 otg_mode_host = 1;
288 else if (!strcmp(options, "device"))
289 otg_mode_host = 0;
290 else
291 pr_info("otg_mode neither \"host\" nor \"device\". "
292 "Defaulting to device\n");
293 return 0;
294}
295__setup("otg_mode=", pca100_otg_mode);
296
Luotao Fu33731692009-08-06 11:19:39 +0200297static void __init pca100_init(void)
298{
299 int ret;
300
Sascha Hauerc8a68852010-02-08 16:42:28 +0100301 /* SSI unit */
302 mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
303 MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
304 MXC_AUDMUX_V1_PCR_TFCSEL(3) |
305 MXC_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */
306 MXC_AUDMUX_V1_PCR_RXDSEL(3));
307 mxc_audmux_v1_configure_port(3,
308 MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
309 MXC_AUDMUX_V1_PCR_TFCSEL(0) |
310 MXC_AUDMUX_V1_PCR_TFSDIR |
311 MXC_AUDMUX_V1_PCR_RXDSEL(0));
312
Luotao Fu33731692009-08-06 11:19:39 +0200313 ret = mxc_gpio_setup_multiple_pins(pca100_pins,
314 ARRAY_SIZE(pca100_pins), "PCA100");
315 if (ret)
316 printk(KERN_ERR "pca100: Failed to setup pins (%d)\n", ret);
317
Sascha Hauerc8a68852010-02-08 16:42:28 +0100318 mxc_register_device(&imx_ssi_device0, &pca100_ssi_pdata);
319
Uwe Kleine-Königd5dac4a2010-06-23 09:36:01 +0200320 imx27_add_imx_uart0(&uart_pdata);
Luotao Fu33731692009-08-06 11:19:39 +0200321
322 mxc_gpio_mode(GPIO_PORTC | 29 | GPIO_GPIO | GPIO_IN);
323 mxc_register_device(&mxc_sdhc_device1, &sdhc_pdata);
324
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +0200325 imx27_add_mxc_nand(&pca100_nand_board_info);
Luotao Fu33731692009-08-06 11:19:39 +0200326
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
Uwe Kleine-Königc6987152010-06-16 17:25:40 +0200331 imx27_add_i2c_imx1(&pca100_i2c1_data);
Luotao Fu33731692009-08-06 11:19:39 +0200332
333 mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
334 mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_OUT);
335
336 /* GPIO0_IRQ */
337 mxc_gpio_mode(GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN);
338 /* GPIO1_IRQ */
339 mxc_gpio_mode(GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN);
340 /* GPIO2_IRQ */
341 mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN);
342
343#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
344 spi_register_board_info(pca100_spi_board_info,
345 ARRAY_SIZE(pca100_spi_board_info));
Uwe Kleine-König7536cf92010-06-22 09:00:22 +0200346 imx27_add_spi_imx0(&pca100_spi_0_data);
Luotao Fu33731692009-08-06 11:19:39 +0200347#endif
348
Sascha Hauereee7c492010-02-03 17:13:29 +0100349 gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs");
350 gpio_direction_output(OTG_PHY_CS_GPIO, 1);
351 gpio_request(USBH2_PHY_CS_GPIO, "usb-host2-cs");
352 gpio_direction_output(USBH2_PHY_CS_GPIO, 1);
353
354#if defined(CONFIG_USB_ULPI)
355 if (otg_mode_host) {
356 otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
357 USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
358
359 mxc_register_device(&mxc_otg_host, &otg_pdata);
360 }
361
362 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
363 USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
364
365 mxc_register_device(&mxc_usbh2, &usbh2_pdata);
366#endif
367 if (!otg_mode_host) {
368 gpio_set_value(OTG_PHY_CS_GPIO, 0);
369 mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
370 }
371
Luotao Fu33731692009-08-06 11:19:39 +0200372 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
373}
374
375static void __init pca100_timer_init(void)
376{
377 mx27_clocks_init(26000000);
378}
379
380static struct sys_timer pca100_timer = {
381 .init = pca100_timer_init,
382};
383
384MACHINE_START(PCA100, "phyCARD-i.MX27")
Uwe Kleine-König3f35d1f2009-12-09 11:32:11 +0100385 .phys_io = MX27_AIPI_BASE_ADDR,
386 .io_pg_offst = ((MX27_AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc,
Uwe Kleine-König34101232010-01-29 17:36:05 +0100387 .boot_params = MX27_PHYS_OFFSET + 0x100,
Luotao Fu33731692009-08-06 11:19:39 +0200388 .map_io = mx27_map_io,
Sascha Hauerf6f1bc62009-11-12 11:30:08 +0100389 .init_irq = mx27_init_irq,
Luotao Fu33731692009-08-06 11:19:39 +0200390 .init_machine = pca100_init,
391 .timer = &pca100_timer,
392MACHINE_END
393