blob: 953cc74bb07ffe210af7c3a7fbf6c96adfb36b17 [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>
Luotao Fu33731692009-08-06 11:19:39 +020040#include <mach/imx-uart.h>
Sascha Hauerc8a68852010-02-08 16:42:28 +010041#include <mach/audmux.h>
42#include <mach/ssi.h>
Luotao Fu33731692009-08-06 11:19:39 +020043#include <mach/mxc_nand.h>
44#include <mach/irqs.h>
45#include <mach/mmc.h>
Sascha Hauereee7c492010-02-03 17:13:29 +010046#include <mach/mxc_ehci.h>
47#include <mach/ulpi.h>
Luotao Fu33731692009-08-06 11:19:39 +020048
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +020049#include "devices-imx27.h"
Luotao Fu33731692009-08-06 11:19:39 +020050#include "devices.h"
51
Sascha Hauereee7c492010-02-03 17:13:29 +010052#define OTG_PHY_CS_GPIO (GPIO_PORTB + 23)
53#define USBH2_PHY_CS_GPIO (GPIO_PORTB + 24)
54
Luotao Fu33731692009-08-06 11:19:39 +020055static int pca100_pins[] = {
56 /* UART1 */
57 PE12_PF_UART1_TXD,
58 PE13_PF_UART1_RXD,
59 PE14_PF_UART1_CTS,
60 PE15_PF_UART1_RTS,
61 /* SDHC */
62 PB4_PF_SD2_D0,
63 PB5_PF_SD2_D1,
64 PB6_PF_SD2_D2,
65 PB7_PF_SD2_D3,
66 PB8_PF_SD2_CMD,
67 PB9_PF_SD2_CLK,
68 /* FEC */
69 PD0_AIN_FEC_TXD0,
70 PD1_AIN_FEC_TXD1,
71 PD2_AIN_FEC_TXD2,
72 PD3_AIN_FEC_TXD3,
73 PD4_AOUT_FEC_RX_ER,
74 PD5_AOUT_FEC_RXD1,
75 PD6_AOUT_FEC_RXD2,
76 PD7_AOUT_FEC_RXD3,
77 PD8_AF_FEC_MDIO,
78 PD9_AIN_FEC_MDC,
79 PD10_AOUT_FEC_CRS,
80 PD11_AOUT_FEC_TX_CLK,
81 PD12_AOUT_FEC_RXD0,
82 PD13_AOUT_FEC_RX_DV,
83 PD14_AOUT_FEC_RX_CLK,
84 PD15_AOUT_FEC_COL,
85 PD16_AIN_FEC_TX_ER,
86 PF23_AIN_FEC_TX_EN,
87 /* SSI1 */
88 PC20_PF_SSI1_FS,
89 PC21_PF_SSI1_RXD,
90 PC22_PF_SSI1_TXD,
91 PC23_PF_SSI1_CLK,
92 /* onboard I2C */
93 PC5_PF_I2C2_SDA,
94 PC6_PF_I2C2_SCL,
95 /* external I2C */
96 PD17_PF_I2C_DATA,
97 PD18_PF_I2C_CLK,
98 /* SPI1 */
99 PD25_PF_CSPI1_RDY,
100 PD29_PF_CSPI1_SCLK,
101 PD30_PF_CSPI1_MISO,
102 PD31_PF_CSPI1_MOSI,
Sascha Hauereee7c492010-02-03 17:13:29 +0100103 /* OTG */
104 OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
105 PC7_PF_USBOTG_DATA5,
106 PC8_PF_USBOTG_DATA6,
107 PC9_PF_USBOTG_DATA0,
108 PC10_PF_USBOTG_DATA2,
109 PC11_PF_USBOTG_DATA1,
110 PC12_PF_USBOTG_DATA4,
111 PC13_PF_USBOTG_DATA3,
112 PE0_PF_USBOTG_NXT,
113 PE1_PF_USBOTG_STP,
114 PE2_PF_USBOTG_DIR,
115 PE24_PF_USBOTG_CLK,
116 PE25_PF_USBOTG_DATA7,
117 /* USBH2 */
118 USBH2_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
119 PA0_PF_USBH2_CLK,
120 PA1_PF_USBH2_DIR,
121 PA2_PF_USBH2_DATA7,
122 PA3_PF_USBH2_NXT,
123 PA4_PF_USBH2_STP,
124 PD19_AF_USBH2_DATA4,
125 PD20_AF_USBH2_DATA3,
126 PD21_AF_USBH2_DATA6,
127 PD22_AF_USBH2_DATA0,
128 PD23_AF_USBH2_DATA2,
129 PD24_AF_USBH2_DATA1,
130 PD26_AF_USBH2_DATA5,
Luotao Fu33731692009-08-06 11:19:39 +0200131};
132
133static struct imxuart_platform_data uart_pdata = {
134 .flags = IMXUART_HAVE_RTSCTS,
135};
136
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +0200137static const struct mxc_nand_platform_data
138pca100_nand_board_info __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200139 .width = 1,
140 .hw_ecc = 1,
141};
142
143static struct platform_device *platform_devices[] __initdata = {
144 &mxc_w1_master_device,
145 &mxc_fec_device,
Wolfram Sangf13899d2010-04-29 10:03:20 +0200146 &mxc_wdt,
Luotao Fu33731692009-08-06 11:19:39 +0200147};
148
Uwe Kleine-Königc6987152010-06-16 17:25:40 +0200149static const struct imxi2c_platform_data pca100_i2c1_data __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200150 .bitrate = 100000,
151};
152
153static struct at24_platform_data board_eeprom = {
154 .byte_len = 4096,
155 .page_size = 32,
156 .flags = AT24_FLAG_ADDR16,
157};
158
159static struct i2c_board_info pca100_i2c_devices[] = {
160 {
161 I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
162 .platform_data = &board_eeprom,
163 }, {
164 I2C_BOARD_INFO("rtc-pcf8563", 0x51),
165 .type = "pcf8563"
166 }, {
167 I2C_BOARD_INFO("lm75", 0x4a),
168 .type = "lm75"
169 }
170};
171
172#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
173static struct spi_eeprom at25320 = {
174 .name = "at25320an",
175 .byte_len = 4096,
176 .page_size = 32,
177 .flags = EE_ADDR2,
178};
179
180static struct spi_board_info pca100_spi_board_info[] __initdata = {
181 {
182 .modalias = "at25",
183 .max_speed_hz = 30000,
184 .bus_num = 0,
185 .chip_select = 1,
186 .platform_data = &at25320,
187 },
188};
189
190static int pca100_spi_cs[] = {GPIO_PORTD + 28, GPIO_PORTD + 27};
191
Uwe Kleine-König7536cf92010-06-22 09:00:22 +0200192static const struct spi_imx_master pca100_spi0_data __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200193 .chipselect = pca100_spi_cs,
194 .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
195};
196#endif
197
Sascha Hauerc8a68852010-02-08 16:42:28 +0100198static 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
208static void pca100_ac97_cold_reset(struct snd_ac97 *ac97)
209{
210 mxc_gpio_mode(GPIO_PORTC | 20 | GPIO_GPIO | GPIO_OUT); /* FS */
211 gpio_set_value(GPIO_PORTC + 20, 0);
212 mxc_gpio_mode(GPIO_PORTC | 22 | GPIO_GPIO | GPIO_OUT); /* TX */
213 gpio_set_value(GPIO_PORTC + 22, 0);
214 mxc_gpio_mode(GPIO_PORTC | 28 | GPIO_GPIO | GPIO_OUT); /* reset */
215 gpio_set_value(GPIO_PORTC + 28, 0);
216 udelay(10);
217 gpio_set_value(GPIO_PORTC + 28, 1);
218 mxc_gpio_mode(PC20_PF_SSI1_FS);
219 mxc_gpio_mode(PC22_PF_SSI1_TXD);
220 msleep(2);
221}
222
223static struct imx_ssi_platform_data pca100_ssi_pdata = {
224 .ac97_reset = pca100_ac97_cold_reset,
225 .ac97_warm_reset = pca100_ac97_warm_reset,
226 .flags = IMX_SSI_USE_AC97,
227};
228
Luotao Fu33731692009-08-06 11:19:39 +0200229static int pca100_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
230 void *data)
231{
232 int ret;
233
234 ret = request_irq(IRQ_GPIOC(29), detect_irq,
235 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
236 "imx-mmc-detect", data);
237 if (ret)
238 printk(KERN_ERR
239 "pca100: Failed to reuest irq for sd/mmc detection\n");
240
241 return ret;
242}
243
244static void pca100_sdhc2_exit(struct device *dev, void *data)
245{
246 free_irq(IRQ_GPIOC(29), data);
247}
248
249static struct imxmmc_platform_data sdhc_pdata = {
250 .init = pca100_sdhc2_init,
251 .exit = pca100_sdhc2_exit,
252};
253
Sascha Hauereee7c492010-02-03 17:13:29 +0100254static int otg_phy_init(struct platform_device *pdev)
255{
256 gpio_set_value(OTG_PHY_CS_GPIO, 0);
257 return 0;
258}
259
260static struct mxc_usbh_platform_data otg_pdata = {
261 .init = otg_phy_init,
262 .portsc = MXC_EHCI_MODE_ULPI,
263 .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
264};
265
266static int usbh2_phy_init(struct platform_device *pdev)
267{
268 gpio_set_value(USBH2_PHY_CS_GPIO, 0);
269 return 0;
270}
271
272static struct mxc_usbh_platform_data usbh2_pdata = {
273 .init = usbh2_phy_init,
274 .portsc = MXC_EHCI_MODE_ULPI,
275 .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
276};
277
278static struct fsl_usb2_platform_data otg_device_pdata = {
279 .operating_mode = FSL_USB2_DR_DEVICE,
280 .phy_mode = FSL_USB2_PHY_ULPI,
281};
282
283static int otg_mode_host;
284
285static 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
Luotao Fu33731692009-08-06 11:19:39 +0200298static void __init pca100_init(void)
299{
300 int ret;
301
Sascha Hauerc8a68852010-02-08 16:42:28 +0100302 /* SSI unit */
303 mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
304 MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
305 MXC_AUDMUX_V1_PCR_TFCSEL(3) |
306 MXC_AUDMUX_V1_PCR_TCLKDIR | /* clock is output */
307 MXC_AUDMUX_V1_PCR_RXDSEL(3));
308 mxc_audmux_v1_configure_port(3,
309 MXC_AUDMUX_V1_PCR_SYN | /* 4wire mode */
310 MXC_AUDMUX_V1_PCR_TFCSEL(0) |
311 MXC_AUDMUX_V1_PCR_TFSDIR |
312 MXC_AUDMUX_V1_PCR_RXDSEL(0));
313
Luotao Fu33731692009-08-06 11:19:39 +0200314 ret = mxc_gpio_setup_multiple_pins(pca100_pins,
315 ARRAY_SIZE(pca100_pins), "PCA100");
316 if (ret)
317 printk(KERN_ERR "pca100: Failed to setup pins (%d)\n", ret);
318
Sascha Hauerc8a68852010-02-08 16:42:28 +0100319 mxc_register_device(&imx_ssi_device0, &pca100_ssi_pdata);
320
Uwe Kleine-König551823e2010-06-11 09:08:02 +0200321 mxc_register_device(&imx2x_uart_device0, &uart_pdata);
Luotao Fu33731692009-08-06 11:19:39 +0200322
323 mxc_gpio_mode(GPIO_PORTC | 29 | GPIO_GPIO | GPIO_IN);
324 mxc_register_device(&mxc_sdhc_device1, &sdhc_pdata);
325
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +0200326 imx27_add_mxc_nand(&pca100_nand_board_info);
Luotao Fu33731692009-08-06 11:19:39 +0200327
328 /* only the i2c master 1 is used on this CPU card */
329 i2c_register_board_info(1, pca100_i2c_devices,
330 ARRAY_SIZE(pca100_i2c_devices));
331
Uwe Kleine-Königc6987152010-06-16 17:25:40 +0200332 imx27_add_i2c_imx1(&pca100_i2c1_data);
Luotao Fu33731692009-08-06 11:19:39 +0200333
334 mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
335 mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_OUT);
336
337 /* GPIO0_IRQ */
338 mxc_gpio_mode(GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN);
339 /* GPIO1_IRQ */
340 mxc_gpio_mode(GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN);
341 /* GPIO2_IRQ */
342 mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN);
343
344#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
345 spi_register_board_info(pca100_spi_board_info,
346 ARRAY_SIZE(pca100_spi_board_info));
Uwe Kleine-König7536cf92010-06-22 09:00:22 +0200347 imx27_add_spi_imx0(&pca100_spi_0_data);
Luotao Fu33731692009-08-06 11:19:39 +0200348#endif
349
Sascha Hauereee7c492010-02-03 17:13:29 +0100350 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
355#if defined(CONFIG_USB_ULPI)
356 if (otg_mode_host) {
357 otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
358 USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
359
360 mxc_register_device(&mxc_otg_host, &otg_pdata);
361 }
362
363 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
364 USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
365
366 mxc_register_device(&mxc_usbh2, &usbh2_pdata);
367#endif
368 if (!otg_mode_host) {
369 gpio_set_value(OTG_PHY_CS_GPIO, 0);
370 mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
371 }
372
Luotao Fu33731692009-08-06 11:19:39 +0200373 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
374}
375
376static void __init pca100_timer_init(void)
377{
378 mx27_clocks_init(26000000);
379}
380
381static struct sys_timer pca100_timer = {
382 .init = pca100_timer_init,
383};
384
385MACHINE_START(PCA100, "phyCARD-i.MX27")
Uwe Kleine-König3f35d1f2009-12-09 11:32:11 +0100386 .phys_io = MX27_AIPI_BASE_ADDR,
387 .io_pg_offst = ((MX27_AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc,
Uwe Kleine-König34101232010-01-29 17:36:05 +0100388 .boot_params = MX27_PHYS_OFFSET + 0x100,
Luotao Fu33731692009-08-06 11:19:39 +0200389 .map_io = mx27_map_io,
Sascha Hauerf6f1bc62009-11-12 11:30:08 +0100390 .init_irq = mx27_init_irq,
Luotao Fu33731692009-08-06 11:19:39 +0200391 .init_machine = pca100_init,
392 .timer = &pca100_timer,
393MACHINE_END
394