blob: cda52a6a32909527dac1d019000a9615ad75dd87 [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>
28#include <linux/gpio.h>
Sascha Hauereee7c492010-02-03 17:13:29 +010029#include <linux/usb/otg.h>
30#include <linux/usb/ulpi.h>
31#include <linux/fsl_devices.h>
Luotao Fu33731692009-08-06 11:19:39 +020032
33#include <asm/mach/arch.h>
34#include <asm/mach-types.h>
35#include <mach/common.h>
36#include <mach/hardware.h>
37#include <mach/iomux.h>
38#include <mach/i2c.h>
39#include <asm/mach/time.h>
40#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
41#include <mach/spi.h>
42#endif
43#include <mach/imx-uart.h>
44#include <mach/mxc_nand.h>
45#include <mach/irqs.h>
46#include <mach/mmc.h>
Sascha Hauereee7c492010-02-03 17:13:29 +010047#include <mach/mxc_ehci.h>
48#include <mach/ulpi.h>
Luotao Fu33731692009-08-06 11:19:39 +020049
50#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
137static struct mxc_nand_platform_data pca100_nand_board_info = {
138 .width = 1,
139 .hw_ecc = 1,
140};
141
142static struct platform_device *platform_devices[] __initdata = {
143 &mxc_w1_master_device,
144 &mxc_fec_device,
145};
146
147static struct imxi2c_platform_data pca100_i2c_1_data = {
148 .bitrate = 100000,
149};
150
151static struct at24_platform_data board_eeprom = {
152 .byte_len = 4096,
153 .page_size = 32,
154 .flags = AT24_FLAG_ADDR16,
155};
156
157static struct i2c_board_info pca100_i2c_devices[] = {
158 {
159 I2C_BOARD_INFO("at24", 0x52), /* E0=0, E1=1, E2=0 */
160 .platform_data = &board_eeprom,
161 }, {
162 I2C_BOARD_INFO("rtc-pcf8563", 0x51),
163 .type = "pcf8563"
164 }, {
165 I2C_BOARD_INFO("lm75", 0x4a),
166 .type = "lm75"
167 }
168};
169
170#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
171static struct spi_eeprom at25320 = {
172 .name = "at25320an",
173 .byte_len = 4096,
174 .page_size = 32,
175 .flags = EE_ADDR2,
176};
177
178static struct spi_board_info pca100_spi_board_info[] __initdata = {
179 {
180 .modalias = "at25",
181 .max_speed_hz = 30000,
182 .bus_num = 0,
183 .chip_select = 1,
184 .platform_data = &at25320,
185 },
186};
187
188static int pca100_spi_cs[] = {GPIO_PORTD + 28, GPIO_PORTD + 27};
189
190static struct spi_imx_master pca100_spi_0_data = {
191 .chipselect = pca100_spi_cs,
192 .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
193};
194#endif
195
196static int pca100_sdhc2_init(struct device *dev, irq_handler_t detect_irq,
197 void *data)
198{
199 int ret;
200
201 ret = request_irq(IRQ_GPIOC(29), detect_irq,
202 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
203 "imx-mmc-detect", data);
204 if (ret)
205 printk(KERN_ERR
206 "pca100: Failed to reuest irq for sd/mmc detection\n");
207
208 return ret;
209}
210
211static void pca100_sdhc2_exit(struct device *dev, void *data)
212{
213 free_irq(IRQ_GPIOC(29), data);
214}
215
216static struct imxmmc_platform_data sdhc_pdata = {
217 .init = pca100_sdhc2_init,
218 .exit = pca100_sdhc2_exit,
219};
220
Sascha Hauereee7c492010-02-03 17:13:29 +0100221static int otg_phy_init(struct platform_device *pdev)
222{
223 gpio_set_value(OTG_PHY_CS_GPIO, 0);
224 return 0;
225}
226
227static struct mxc_usbh_platform_data otg_pdata = {
228 .init = otg_phy_init,
229 .portsc = MXC_EHCI_MODE_ULPI,
230 .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
231};
232
233static int usbh2_phy_init(struct platform_device *pdev)
234{
235 gpio_set_value(USBH2_PHY_CS_GPIO, 0);
236 return 0;
237}
238
239static struct mxc_usbh_platform_data usbh2_pdata = {
240 .init = usbh2_phy_init,
241 .portsc = MXC_EHCI_MODE_ULPI,
242 .flags = MXC_EHCI_INTERFACE_DIFF_UNI,
243};
244
245static struct fsl_usb2_platform_data otg_device_pdata = {
246 .operating_mode = FSL_USB2_DR_DEVICE,
247 .phy_mode = FSL_USB2_PHY_ULPI,
248};
249
250static int otg_mode_host;
251
252static int __init pca100_otg_mode(char *options)
253{
254 if (!strcmp(options, "host"))
255 otg_mode_host = 1;
256 else if (!strcmp(options, "device"))
257 otg_mode_host = 0;
258 else
259 pr_info("otg_mode neither \"host\" nor \"device\". "
260 "Defaulting to device\n");
261 return 0;
262}
263__setup("otg_mode=", pca100_otg_mode);
264
Luotao Fu33731692009-08-06 11:19:39 +0200265static void __init pca100_init(void)
266{
267 int ret;
268
269 ret = mxc_gpio_setup_multiple_pins(pca100_pins,
270 ARRAY_SIZE(pca100_pins), "PCA100");
271 if (ret)
272 printk(KERN_ERR "pca100: Failed to setup pins (%d)\n", ret);
273
274 mxc_register_device(&mxc_uart_device0, &uart_pdata);
275
276 mxc_gpio_mode(GPIO_PORTC | 29 | GPIO_GPIO | GPIO_IN);
277 mxc_register_device(&mxc_sdhc_device1, &sdhc_pdata);
278
279 mxc_register_device(&mxc_nand_device, &pca100_nand_board_info);
280
281 /* only the i2c master 1 is used on this CPU card */
282 i2c_register_board_info(1, pca100_i2c_devices,
283 ARRAY_SIZE(pca100_i2c_devices));
284
285 mxc_register_device(&mxc_i2c_device1, &pca100_i2c_1_data);
286
287 mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
288 mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_OUT);
289
290 /* GPIO0_IRQ */
291 mxc_gpio_mode(GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN);
292 /* GPIO1_IRQ */
293 mxc_gpio_mode(GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN);
294 /* GPIO2_IRQ */
295 mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN);
296
297#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
298 spi_register_board_info(pca100_spi_board_info,
299 ARRAY_SIZE(pca100_spi_board_info));
300 mxc_register_device(&mxc_spi_device0, &pca100_spi_0_data);
301#endif
302
Sascha Hauereee7c492010-02-03 17:13:29 +0100303 gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs");
304 gpio_direction_output(OTG_PHY_CS_GPIO, 1);
305 gpio_request(USBH2_PHY_CS_GPIO, "usb-host2-cs");
306 gpio_direction_output(USBH2_PHY_CS_GPIO, 1);
307
308#if defined(CONFIG_USB_ULPI)
309 if (otg_mode_host) {
310 otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
311 USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
312
313 mxc_register_device(&mxc_otg_host, &otg_pdata);
314 }
315
316 usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
317 USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
318
319 mxc_register_device(&mxc_usbh2, &usbh2_pdata);
320#endif
321 if (!otg_mode_host) {
322 gpio_set_value(OTG_PHY_CS_GPIO, 0);
323 mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
324 }
325
Luotao Fu33731692009-08-06 11:19:39 +0200326 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
327}
328
329static void __init pca100_timer_init(void)
330{
331 mx27_clocks_init(26000000);
332}
333
334static struct sys_timer pca100_timer = {
335 .init = pca100_timer_init,
336};
337
338MACHINE_START(PCA100, "phyCARD-i.MX27")
Uwe Kleine-König3f35d1f2009-12-09 11:32:11 +0100339 .phys_io = MX27_AIPI_BASE_ADDR,
340 .io_pg_offst = ((MX27_AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc,
Uwe Kleine-König34101232010-01-29 17:36:05 +0100341 .boot_params = MX27_PHYS_OFFSET + 0x100,
Luotao Fu33731692009-08-06 11:19:39 +0200342 .map_io = mx27_map_io,
Sascha Hauerf6f1bc62009-11-12 11:30:08 +0100343 .init_irq = mx27_init_irq,
Luotao Fu33731692009-08-06 11:19:39 +0200344 .init_machine = pca100_init,
345 .timer = &pca100_timer,
346MACHINE_END
347