]>
Commit | Line | Data |
---|---|---|
33731698 LF |
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 | ||
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> | |
c8a6885f | 28 | #include <linux/delay.h> |
33731698 | 29 | #include <linux/gpio.h> |
eee7c497 SH |
30 | #include <linux/usb/otg.h> |
31 | #include <linux/usb/ulpi.h> | |
32 | #include <linux/fsl_devices.h> | |
33731698 LF |
33 | |
34 | #include <asm/mach/arch.h> | |
35 | #include <asm/mach-types.h> | |
36 | #include <mach/common.h> | |
37 | #include <mach/hardware.h> | |
e835d88e | 38 | #include <mach/iomux-mx27.h> |
33731698 | 39 | #include <asm/mach/time.h> |
33731698 | 40 | #include <mach/imx-uart.h> |
c8a6885f SH |
41 | #include <mach/audmux.h> |
42 | #include <mach/ssi.h> | |
33731698 LF |
43 | #include <mach/mxc_nand.h> |
44 | #include <mach/irqs.h> | |
45 | #include <mach/mmc.h> | |
eee7c497 SH |
46 | #include <mach/mxc_ehci.h> |
47 | #include <mach/ulpi.h> | |
33731698 | 48 | |
0e7a29a8 | 49 | #include "devices-imx27.h" |
33731698 LF |
50 | #include "devices.h" |
51 | ||
eee7c497 SH |
52 | #define OTG_PHY_CS_GPIO (GPIO_PORTB + 23) |
53 | #define USBH2_PHY_CS_GPIO (GPIO_PORTB + 24) | |
54 | ||
33731698 LF |
55 | static 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, | |
eee7c497 SH |
103 | /* 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, | |
33731698 LF |
131 | }; |
132 | ||
133 | static struct imxuart_platform_data uart_pdata = { | |
134 | .flags = IMXUART_HAVE_RTSCTS, | |
135 | }; | |
136 | ||
0e7a29a8 UKK |
137 | static const struct mxc_nand_platform_data |
138 | pca100_nand_board_info __initconst = { | |
33731698 LF |
139 | .width = 1, |
140 | .hw_ecc = 1, | |
141 | }; | |
142 | ||
143 | static struct platform_device *platform_devices[] __initdata = { | |
144 | &mxc_w1_master_device, | |
145 | &mxc_fec_device, | |
f13899da | 146 | &mxc_wdt, |
33731698 LF |
147 | }; |
148 | ||
c6987159 | 149 | static const struct imxi2c_platform_data pca100_i2c1_data __initconst = { |
33731698 LF |
150 | .bitrate = 100000, |
151 | }; | |
152 | ||
153 | static struct at24_platform_data board_eeprom = { | |
154 | .byte_len = 4096, | |
155 | .page_size = 32, | |
156 | .flags = AT24_FLAG_ADDR16, | |
157 | }; | |
158 | ||
159 | static 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) | |
173 | static struct spi_eeprom at25320 = { | |
174 | .name = "at25320an", | |
175 | .byte_len = 4096, | |
176 | .page_size = 32, | |
177 | .flags = EE_ADDR2, | |
178 | }; | |
179 | ||
180 | static 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 | ||
190 | static int pca100_spi_cs[] = {GPIO_PORTD + 28, GPIO_PORTD + 27}; | |
191 | ||
7536cf99 | 192 | static const struct spi_imx_master pca100_spi0_data __initconst = { |
33731698 LF |
193 | .chipselect = pca100_spi_cs, |
194 | .num_chipselect = ARRAY_SIZE(pca100_spi_cs), | |
195 | }; | |
196 | #endif | |
197 | ||
c8a6885f SH |
198 | static 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 | ||
208 | static 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 | ||
223 | static 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 | ||
33731698 LF |
229 | static 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 | ||
244 | static void pca100_sdhc2_exit(struct device *dev, void *data) | |
245 | { | |
246 | free_irq(IRQ_GPIOC(29), data); | |
247 | } | |
248 | ||
249 | static struct imxmmc_platform_data sdhc_pdata = { | |
250 | .init = pca100_sdhc2_init, | |
251 | .exit = pca100_sdhc2_exit, | |
252 | }; | |
253 | ||
eee7c497 SH |
254 | static int otg_phy_init(struct platform_device *pdev) |
255 | { | |
256 | gpio_set_value(OTG_PHY_CS_GPIO, 0); | |
257 | return 0; | |
258 | } | |
259 | ||
260 | static 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 | ||
266 | static int usbh2_phy_init(struct platform_device *pdev) | |
267 | { | |
268 | gpio_set_value(USBH2_PHY_CS_GPIO, 0); | |
269 | return 0; | |
270 | } | |
271 | ||
272 | static 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 | ||
278 | static struct fsl_usb2_platform_data otg_device_pdata = { | |
279 | .operating_mode = FSL_USB2_DR_DEVICE, | |
280 | .phy_mode = FSL_USB2_PHY_ULPI, | |
281 | }; | |
282 | ||
283 | static int otg_mode_host; | |
284 | ||
285 | static 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 | ||
33731698 LF |
298 | static void __init pca100_init(void) |
299 | { | |
300 | int ret; | |
301 | ||
c8a6885f SH |
302 | /* 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 | ||
33731698 LF |
314 | 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 | ||
c8a6885f SH |
319 | mxc_register_device(&imx_ssi_device0, &pca100_ssi_pdata); |
320 | ||
551823e7 | 321 | mxc_register_device(&imx2x_uart_device0, &uart_pdata); |
33731698 LF |
322 | |
323 | mxc_gpio_mode(GPIO_PORTC | 29 | GPIO_GPIO | GPIO_IN); | |
324 | mxc_register_device(&mxc_sdhc_device1, &sdhc_pdata); | |
325 | ||
0e7a29a8 | 326 | imx27_add_mxc_nand(&pca100_nand_board_info); |
33731698 LF |
327 | |
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 | ||
c6987159 | 332 | imx27_add_i2c_imx1(&pca100_i2c1_data); |
33731698 LF |
333 | |
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)); | |
7536cf99 | 347 | imx27_add_spi_imx0(&pca100_spi_0_data); |
33731698 LF |
348 | #endif |
349 | ||
eee7c497 SH |
350 | 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 | ||
33731698 LF |
373 | platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices)); |
374 | } | |
375 | ||
376 | static void __init pca100_timer_init(void) | |
377 | { | |
378 | mx27_clocks_init(26000000); | |
379 | } | |
380 | ||
381 | static struct sys_timer pca100_timer = { | |
382 | .init = pca100_timer_init, | |
383 | }; | |
384 | ||
385 | MACHINE_START(PCA100, "phyCARD-i.MX27") | |
3f35d1f5 UKK |
386 | .phys_io = MX27_AIPI_BASE_ADDR, |
387 | .io_pg_offst = ((MX27_AIPI_BASE_ADDR_VIRT) >> 18) & 0xfffc, | |
34101237 | 388 | .boot_params = MX27_PHYS_OFFSET + 0x100, |
33731698 | 389 | .map_io = mx27_map_io, |
f6f1bc64 | 390 | .init_irq = mx27_init_irq, |
33731698 LF |
391 | .init_machine = pca100_init, |
392 | .timer = &pca100_timer, | |
393 | MACHINE_END | |
394 |