blob: 2e28e1b5cddfdc49fea55900b0d2997253ed9469 [file] [log] [blame]
Thomas Gleixner16216332019-05-19 15:51:31 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Luotao Fu33731692009-08-06 11:19:39 +02002/*
3 * Copyright 2007 Robert Schwebel <r.schwebel@pengutronix.de>, Pengutronix
4 * Copyright (C) 2009 Sascha Hauer (kernel@pengutronix.de)
Luotao Fu33731692009-08-06 11:19:39 +02005 */
6
7#include <linux/platform_device.h>
8#include <linux/io.h>
9#include <linux/i2c.h>
Bartosz Golaszewski6a7836b2018-04-04 15:16:26 +020010#include <linux/property.h>
Luotao Fu33731692009-08-06 11:19:39 +020011#include <linux/dma-mapping.h>
12#include <linux/spi/spi.h>
13#include <linux/spi/eeprom.h>
14#include <linux/irq.h>
Sascha Hauerc8a68852010-02-08 16:42:28 +010015#include <linux/delay.h>
Luotao Fu33731692009-08-06 11:19:39 +020016#include <linux/gpio.h>
Sascha Hauereee7c492010-02-03 17:13:29 +010017#include <linux/usb/otg.h>
18#include <linux/usb/ulpi.h>
Luotao Fu33731692009-08-06 11:19:39 +020019
20#include <asm/mach/arch.h>
21#include <asm/mach-types.h>
Luotao Fu33731692009-08-06 11:19:39 +020022#include <asm/mach/time.h>
Luotao Fu33731692009-08-06 11:19:39 +020023
Shawn Guoe3372472012-09-13 21:01:00 +080024#include "common.h"
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +020025#include "devices-imx27.h"
Shawn Guo641dfe82014-05-19 20:41:52 +080026#include "ehci.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080027#include "hardware.h"
Shawn Guo267dd342012-09-13 13:26:00 +080028#include "iomux-mx27.h"
Shawn Guo39ef6342012-09-13 21:46:09 +080029#include "ulpi.h"
Luotao Fu33731692009-08-06 11:19:39 +020030
Sascha Hauereee7c492010-02-03 17:13:29 +010031#define OTG_PHY_CS_GPIO (GPIO_PORTB + 23)
32#define USBH2_PHY_CS_GPIO (GPIO_PORTB + 24)
Luotao Fub725aba2010-06-18 09:23:19 +020033#define SPI1_SS0 (GPIO_PORTD + 28)
34#define SPI1_SS1 (GPIO_PORTD + 27)
35#define SD2_CD (GPIO_PORTC + 29)
Sascha Hauereee7c492010-02-03 17:13:29 +010036
Uwe Kleine-König6c80ee52010-09-28 21:53:31 +020037static const int pca100_pins[] __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +020038 /* UART1 */
39 PE12_PF_UART1_TXD,
40 PE13_PF_UART1_RXD,
41 PE14_PF_UART1_CTS,
42 PE15_PF_UART1_RTS,
43 /* SDHC */
44 PB4_PF_SD2_D0,
45 PB5_PF_SD2_D1,
46 PB6_PF_SD2_D2,
47 PB7_PF_SD2_D3,
48 PB8_PF_SD2_CMD,
49 PB9_PF_SD2_CLK,
Luotao Fub725aba2010-06-18 09:23:19 +020050 SD2_CD | GPIO_GPIO | GPIO_IN,
Luotao Fu33731692009-08-06 11:19:39 +020051 /* FEC */
52 PD0_AIN_FEC_TXD0,
53 PD1_AIN_FEC_TXD1,
54 PD2_AIN_FEC_TXD2,
55 PD3_AIN_FEC_TXD3,
56 PD4_AOUT_FEC_RX_ER,
57 PD5_AOUT_FEC_RXD1,
58 PD6_AOUT_FEC_RXD2,
59 PD7_AOUT_FEC_RXD3,
60 PD8_AF_FEC_MDIO,
61 PD9_AIN_FEC_MDC,
62 PD10_AOUT_FEC_CRS,
63 PD11_AOUT_FEC_TX_CLK,
64 PD12_AOUT_FEC_RXD0,
65 PD13_AOUT_FEC_RX_DV,
66 PD14_AOUT_FEC_RX_CLK,
67 PD15_AOUT_FEC_COL,
68 PD16_AIN_FEC_TX_ER,
69 PF23_AIN_FEC_TX_EN,
70 /* SSI1 */
71 PC20_PF_SSI1_FS,
72 PC21_PF_SSI1_RXD,
73 PC22_PF_SSI1_TXD,
74 PC23_PF_SSI1_CLK,
75 /* onboard I2C */
76 PC5_PF_I2C2_SDA,
77 PC6_PF_I2C2_SCL,
78 /* external I2C */
79 PD17_PF_I2C_DATA,
80 PD18_PF_I2C_CLK,
81 /* SPI1 */
82 PD25_PF_CSPI1_RDY,
83 PD29_PF_CSPI1_SCLK,
84 PD30_PF_CSPI1_MISO,
85 PD31_PF_CSPI1_MOSI,
Sascha Hauereee7c492010-02-03 17:13:29 +010086 /* OTG */
87 OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
88 PC7_PF_USBOTG_DATA5,
89 PC8_PF_USBOTG_DATA6,
90 PC9_PF_USBOTG_DATA0,
91 PC10_PF_USBOTG_DATA2,
92 PC11_PF_USBOTG_DATA1,
93 PC12_PF_USBOTG_DATA4,
94 PC13_PF_USBOTG_DATA3,
95 PE0_PF_USBOTG_NXT,
96 PE1_PF_USBOTG_STP,
97 PE2_PF_USBOTG_DIR,
98 PE24_PF_USBOTG_CLK,
99 PE25_PF_USBOTG_DATA7,
100 /* USBH2 */
101 USBH2_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
102 PA0_PF_USBH2_CLK,
103 PA1_PF_USBH2_DIR,
104 PA2_PF_USBH2_DATA7,
105 PA3_PF_USBH2_NXT,
106 PA4_PF_USBH2_STP,
107 PD19_AF_USBH2_DATA4,
108 PD20_AF_USBH2_DATA3,
109 PD21_AF_USBH2_DATA6,
110 PD22_AF_USBH2_DATA0,
111 PD23_AF_USBH2_DATA2,
112 PD24_AF_USBH2_DATA1,
113 PD26_AF_USBH2_DATA5,
Luotao Fu42216fc2010-06-18 09:23:18 +0200114 /* display */
115 PA5_PF_LSCLK,
116 PA6_PF_LD0,
117 PA7_PF_LD1,
118 PA8_PF_LD2,
119 PA9_PF_LD3,
120 PA10_PF_LD4,
121 PA11_PF_LD5,
122 PA12_PF_LD6,
123 PA13_PF_LD7,
124 PA14_PF_LD8,
125 PA15_PF_LD9,
126 PA16_PF_LD10,
127 PA17_PF_LD11,
128 PA18_PF_LD12,
129 PA19_PF_LD13,
130 PA20_PF_LD14,
131 PA21_PF_LD15,
132 PA22_PF_LD16,
133 PA23_PF_LD17,
134 PA26_PF_PS,
135 PA28_PF_HSYNC,
136 PA29_PF_VSYNC,
137 PA31_PF_OE_ACD,
Luotao Fub725aba2010-06-18 09:23:19 +0200138 /* free GPIO */
139 GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN, /* GPIO0_IRQ */
140 GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN, /* GPIO1_IRQ */
141 GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN, /* GPIO2_IRQ */
Luotao Fu33731692009-08-06 11:19:39 +0200142};
143
Uwe Kleine-Königd5dac4a2010-06-23 09:36:01 +0200144static const struct imxuart_platform_data uart_pdata __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200145 .flags = IMXUART_HAVE_RTSCTS,
146};
147
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +0200148static const struct mxc_nand_platform_data
149pca100_nand_board_info __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200150 .width = 1,
151 .hw_ecc = 1,
152};
153
Uwe Kleine-Königc6987152010-06-16 17:25:40 +0200154static const struct imxi2c_platform_data pca100_i2c1_data __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200155 .bitrate = 100000,
156};
157
Bartosz Golaszewski6a7836b2018-04-04 15:16:26 +0200158static const struct property_entry board_eeprom_properties[] = {
159 PROPERTY_ENTRY_U32("pagesize", 32),
160 { }
Luotao Fu33731692009-08-06 11:19:39 +0200161};
162
163static struct i2c_board_info pca100_i2c_devices[] = {
164 {
Bartosz Golaszewski6a7836b2018-04-04 15:16:26 +0200165 I2C_BOARD_INFO("24c32", 0x52), /* E0=0, E1=1, E2=0 */
166 .properties = board_eeprom_properties,
Luotao Fu33731692009-08-06 11:19:39 +0200167 }, {
Uwe Kleine-Königbd9e3102010-09-28 22:04:01 +0200168 I2C_BOARD_INFO("pcf8563", 0x51),
Luotao Fu33731692009-08-06 11:19:39 +0200169 }, {
170 I2C_BOARD_INFO("lm75", 0x4a),
Luotao Fu33731692009-08-06 11:19:39 +0200171 }
172};
173
Luotao Fu33731692009-08-06 11:19:39 +0200174static struct spi_eeprom at25320 = {
175 .name = "at25320an",
176 .byte_len = 4096,
177 .page_size = 32,
178 .flags = EE_ADDR2,
179};
180
181static struct spi_board_info pca100_spi_board_info[] __initdata = {
182 {
183 .modalias = "at25",
184 .max_speed_hz = 30000,
185 .bus_num = 0,
186 .chip_select = 1,
187 .platform_data = &at25320,
188 },
189};
190
Luotao Fub725aba2010-06-18 09:23:19 +0200191static int pca100_spi_cs[] = {SPI1_SS0, SPI1_SS1};
Luotao Fu33731692009-08-06 11:19:39 +0200192
Uwe Kleine-König7536cf92010-06-22 09:00:22 +0200193static const struct spi_imx_master pca100_spi0_data __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200194 .chipselect = pca100_spi_cs,
195 .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
196};
Luotao Fu33731692009-08-06 11:19:39 +0200197
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
Uwe Kleine-König4697bb922010-08-25 17:37:45 +0200223static const struct imx_ssi_platform_data pca100_ssi_pdata __initconst = {
Sascha Hauerc8a68852010-02-08 16:42:28 +0100224 .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
Shawn Guo438196c2011-12-05 10:12:28 +0800234 ret = request_irq(gpio_to_irq(IMX_GPIO_NR(3, 29)), detect_irq,
Juan Solanod4e7d942014-05-07 17:09:59 +0200235 IRQF_TRIGGER_FALLING, "imx-mmc-detect", data);
Luotao Fu33731692009-08-06 11:19:39 +0200236 if (ret)
237 printk(KERN_ERR
Masanari Iida77d84ff2013-12-09 00:22:53 +0900238 "pca100: Failed to request irq for sd/mmc detection\n");
Luotao Fu33731692009-08-06 11:19:39 +0200239
240 return ret;
241}
242
243static void pca100_sdhc2_exit(struct device *dev, void *data)
244{
Shawn Guo438196c2011-12-05 10:12:28 +0800245 free_irq(gpio_to_irq(IMX_GPIO_NR(3, 29)), data);
Luotao Fu33731692009-08-06 11:19:39 +0200246}
247
Uwe Kleine-König9d3d9452010-11-05 17:26:09 +0100248static const struct imxmmc_platform_data sdhc_pdata __initconst = {
Luotao Fu33731692009-08-06 11:19:39 +0200249 .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);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100256
257 mdelay(10);
258
259 return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_INTERFACE_DIFF_UNI);
Sascha Hauereee7c492010-02-03 17:13:29 +0100260}
261
Uwe Kleine-König2eb42d52010-11-05 18:52:09 +0100262static struct mxc_usbh_platform_data otg_pdata __initdata = {
Sascha Hauereee7c492010-02-03 17:13:29 +0100263 .init = otg_phy_init,
264 .portsc = MXC_EHCI_MODE_ULPI,
Sascha Hauereee7c492010-02-03 17:13:29 +0100265};
266
267static int usbh2_phy_init(struct platform_device *pdev)
268{
269 gpio_set_value(USBH2_PHY_CS_GPIO, 0);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100270
271 mdelay(10);
272
273 return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_INTERFACE_DIFF_UNI);
Sascha Hauereee7c492010-02-03 17:13:29 +0100274}
275
Uwe Kleine-König2eb42d52010-11-05 18:52:09 +0100276static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
Sascha Hauereee7c492010-02-03 17:13:29 +0100277 .init = usbh2_phy_init,
278 .portsc = MXC_EHCI_MODE_ULPI,
Sascha Hauereee7c492010-02-03 17:13:29 +0100279};
280
Uwe Kleine-Königbd455ed2010-11-09 17:52:14 +0100281static const struct fsl_usb2_platform_data otg_device_pdata __initconst = {
Sascha Hauereee7c492010-02-03 17:13:29 +0100282 .operating_mode = FSL_USB2_DR_DEVICE,
283 .phy_mode = FSL_USB2_PHY_ULPI,
284};
285
Benoît Thébaudeau33a264d2012-06-12 19:46:43 +0200286static bool otg_mode_host __initdata;
Sascha Hauereee7c492010-02-03 17:13:29 +0100287
288static int __init pca100_otg_mode(char *options)
289{
290 if (!strcmp(options, "host"))
Benoît Thébaudeau33a264d2012-06-12 19:46:43 +0200291 otg_mode_host = true;
Sascha Hauereee7c492010-02-03 17:13:29 +0100292 else if (!strcmp(options, "device"))
Benoît Thébaudeau33a264d2012-06-12 19:46:43 +0200293 otg_mode_host = false;
Sascha Hauereee7c492010-02-03 17:13:29 +0100294 else
295 pr_info("otg_mode neither \"host\" nor \"device\". "
296 "Defaulting to device\n");
Benoît Thébaudeau33a264d2012-06-12 19:46:43 +0200297 return 1;
Sascha Hauereee7c492010-02-03 17:13:29 +0100298}
299__setup("otg_mode=", pca100_otg_mode);
300
Luotao Fu42216fc2010-06-18 09:23:18 +0200301/* framebuffer info */
302static struct imx_fb_videomode pca100_fb_modes[] = {
303 {
304 .mode = {
305 .name = "EMERGING-ETV570G0DHU",
306 .refresh = 60,
307 .xres = 640,
308 .yres = 480,
309 .pixclock = 39722, /* in ps (25.175 MHz) */
310 .hsync_len = 30,
311 .left_margin = 114,
312 .right_margin = 16,
313 .vsync_len = 3,
314 .upper_margin = 32,
315 .lower_margin = 0,
316 },
317 /*
318 * TFT
319 * Pixel pol active high
320 * HSYNC active low
321 * VSYNC active low
322 * use HSYNC for ACD count
323 * line clock disable while idle
324 * always enable line clock even if no data
325 */
326 .pcr = 0xf0c08080,
327 .bpp = 16,
328 },
329};
330
Uwe Kleine-Königad851bf2010-11-04 17:07:48 +0100331static const struct imx_fb_platform_data pca100_fb_data __initconst = {
Luotao Fu42216fc2010-06-18 09:23:18 +0200332 .mode = pca100_fb_modes,
333 .num_modes = ARRAY_SIZE(pca100_fb_modes),
334
335 .pwmr = 0x00A903FF,
336 .lscr1 = 0x00120300,
337 .dmacr = 0x00020010,
338};
339
Luotao Fu33731692009-08-06 11:19:39 +0200340static void __init pca100_init(void)
341{
342 int ret;
343
Shawn Guob78d8e52011-06-06 00:07:55 +0800344 imx27_soc_init();
345
Luotao Fu33731692009-08-06 11:19:39 +0200346 ret = mxc_gpio_setup_multiple_pins(pca100_pins,
347 ARRAY_SIZE(pca100_pins), "PCA100");
348 if (ret)
349 printk(KERN_ERR "pca100: Failed to setup pins (%d)\n", ret);
350
Uwe Kleine-Königd5dac4a2010-06-23 09:36:01 +0200351 imx27_add_imx_uart0(&uart_pdata);
Luotao Fu33731692009-08-06 11:19:39 +0200352
Uwe Kleine-König0e7a29a2010-06-16 07:35:31 +0200353 imx27_add_mxc_nand(&pca100_nand_board_info);
Luotao Fu33731692009-08-06 11:19:39 +0200354
355 /* only the i2c master 1 is used on this CPU card */
356 i2c_register_board_info(1, pca100_i2c_devices,
357 ARRAY_SIZE(pca100_i2c_devices));
358
Uwe Kleine-König77a406d2010-08-25 12:19:50 +0200359 imx27_add_imx_i2c(1, &pca100_i2c1_data);
Luotao Fu33731692009-08-06 11:19:39 +0200360
Luotao Fub725aba2010-06-18 09:23:19 +0200361 mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_IN);
362 mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_IN);
Luotao Fu33731692009-08-06 11:19:39 +0200363 spi_register_board_info(pca100_spi_board_info,
364 ARRAY_SIZE(pca100_spi_board_info));
Uwe Kleine-König4df772d2010-08-10 21:18:57 +0100365 imx27_add_spi_imx0(&pca100_spi0_data);
Luotao Fu33731692009-08-06 11:19:39 +0200366
Vladimir Zapolskiy23fe1fd2016-09-19 04:37:31 +0300367 imx27_add_imx_fb(&pca100_fb_data);
368
369 imx27_add_fec(NULL);
370 imx27_add_imx2_wdt();
371 imx27_add_mxc_w1();
372}
373
374static void __init pca100_late_init(void)
375{
376 imx27_add_imx_ssi(0, &pca100_ssi_pdata);
377
378 imx27_add_mxc_mmc(1, &sdhc_pdata);
379
Sascha Hauereee7c492010-02-03 17:13:29 +0100380 gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs");
381 gpio_direction_output(OTG_PHY_CS_GPIO, 1);
382 gpio_request(USBH2_PHY_CS_GPIO, "usb-host2-cs");
383 gpio_direction_output(USBH2_PHY_CS_GPIO, 1);
384
Sascha Hauereee7c492010-02-03 17:13:29 +0100385 if (otg_mode_host) {
Sascha Hauer48f6b092011-03-02 09:27:42 +0100386 otg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
387 ULPI_OTG_DRVVBUS_EXT);
Sascha Hauereee7c492010-02-03 17:13:29 +0100388
Sascha Hauer48f6b092011-03-02 09:27:42 +0100389 if (otg_pdata.otg)
390 imx27_add_mxc_ehci_otg(&otg_pdata);
391 } else {
392 gpio_set_value(OTG_PHY_CS_GPIO, 0);
393 imx27_add_fsl_usb2_udc(&otg_device_pdata);
Sascha Hauereee7c492010-02-03 17:13:29 +0100394 }
395
Markus Pargmann794987a2013-06-06 14:41:57 +0200396 usbh2_pdata.otg = imx_otg_ulpi_create(
397 ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
Sascha Hauereee7c492010-02-03 17:13:29 +0100398
Sascha Hauer48f6b092011-03-02 09:27:42 +0100399 if (usbh2_pdata.otg)
400 imx27_add_mxc_ehci_hs(2, &usbh2_pdata);
Luotao Fu33731692009-08-06 11:19:39 +0200401}
402
403static void __init pca100_timer_init(void)
404{
405 mx27_clocks_init(26000000);
406}
407
Luotao Fu33731692009-08-06 11:19:39 +0200408MACHINE_START(PCA100, "phyCARD-i.MX27")
Nicolas Pitredc8f1902011-07-05 22:38:12 -0400409 .atag_offset = 0x100,
Uwe Kleine-König3dac2192011-02-07 16:35:19 +0100410 .map_io = mx27_map_io,
411 .init_early = imx27_init_early,
412 .init_irq = mx27_init_irq,
Vladimir Zapolskiy23fe1fd2016-09-19 04:37:31 +0300413 .init_machine = pca100_init,
414 .init_late = pca100_late_init,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700415 .init_time = pca100_timer_init,
Russell King65ea7882011-11-06 17:12:08 +0000416 .restart = mxc_restart,
Luotao Fu33731692009-08-06 11:19:39 +0200417MACHINE_END