blob: 9d87f1dcf7bbc8cea73b30e571ec131793b41b9c [file] [log] [blame]
Fabio Estevam1553a1e2008-11-12 15:38:39 +01001/*
2 * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
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.
Fabio Estevam1553a1e2008-11-12 15:38:39 +010013 */
14
Magnus Liljaa2ef4562010-05-14 17:08:29 +020015#include <linux/delay.h>
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000016#include <linux/dma-mapping.h>
Fabio Estevam1553a1e2008-11-12 15:38:39 +010017#include <linux/types.h>
18#include <linux/init.h>
19#include <linux/clk.h>
20#include <linux/irq.h>
Magnus Lilja135cad32009-05-17 20:18:08 +020021#include <linux/gpio.h>
Magnus Lilja2b0c3672009-05-18 18:46:33 +020022#include <linux/platform_device.h>
Alberto Panizzoae7a3f12010-03-23 19:51:45 +010023#include <linux/mfd/mc13783.h>
24#include <linux/spi/spi.h>
Alberto Panizzoe42010e2011-03-07 11:46:38 +010025#include <linux/spi/l4f00242t03.h>
Alberto Panizzoae7a3f12010-03-23 19:51:45 +010026#include <linux/regulator/machine.h>
Fabio Estevam1c50e672010-12-21 16:38:21 -020027#include <linux/usb/otg.h>
28#include <linux/usb/ulpi.h>
Fabio Estevam1553a1e2008-11-12 15:38:39 +010029
Fabio Estevam1553a1e2008-11-12 15:38:39 +010030#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32#include <asm/mach/time.h>
33#include <asm/memory.h>
34#include <asm/mach/map.h>
Uwe Kleine-Königa2ceeef2010-06-16 12:23:11 +020035
Shawn Guo3ed0bcb2012-09-13 09:37:49 +080036#include "3ds_debugboard.h"
Shawn Guoe3372472012-09-13 21:01:00 +080037#include "common.h"
Uwe Kleine-Königa2ceeef2010-06-16 12:23:11 +020038#include "devices-imx31.h"
Shawn Guo641dfe82014-05-19 20:41:52 +080039#include "ehci.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080040#include "hardware.h"
Shawn Guo267dd342012-09-13 13:26:00 +080041#include "iomux-mx3.h"
Shawn Guo39ef6342012-09-13 21:46:09 +080042#include "ulpi.h"
Fabio Estevam1553a1e2008-11-12 15:38:39 +010043
Alberto Panizzo11a332adf2010-03-23 19:46:57 +010044static int mx31_3ds_pins[] = {
Magnus Lilja153fa1d2009-05-16 12:43:10 +020045 /* UART1 */
Valentin Longchamp63d976672009-01-28 15:13:53 +010046 MX31_PIN_CTS1__CTS1,
47 MX31_PIN_RTS1__RTS1,
48 MX31_PIN_TXD1__TXD1,
Magnus Lilja135cad32009-05-17 20:18:08 +020049 MX31_PIN_RXD1__RXD1,
50 IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO),
Alberto Panizzoe42010e2011-03-07 11:46:38 +010051 /*SPI0*/
Fabio Estevamb2a08e32011-06-20 10:37:13 -030052 IOMUX_MODE(MX31_PIN_DSR_DCE1, IOMUX_CONFIG_ALT1),
53 IOMUX_MODE(MX31_PIN_RI_DCE1, IOMUX_CONFIG_ALT1),
Alberto Panizzoa1ac4422010-03-23 19:50:28 +010054 /* SPI 1 */
55 MX31_PIN_CSPI2_SCLK__SCLK,
56 MX31_PIN_CSPI2_MOSI__MOSI,
57 MX31_PIN_CSPI2_MISO__MISO,
58 MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
59 MX31_PIN_CSPI2_SS0__SS0,
60 MX31_PIN_CSPI2_SS2__SS2, /*CS for MC13783 */
Alberto Panizzoae7a3f12010-03-23 19:51:45 +010061 /* MC13783 IRQ */
62 IOMUX_MODE(MX31_PIN_GPIO1_3, IOMUX_CONFIG_GPIO),
Magnus Liljaa2ef4562010-05-14 17:08:29 +020063 /* USB OTG reset */
64 IOMUX_MODE(MX31_PIN_USB_PWR, IOMUX_CONFIG_GPIO),
65 /* USB OTG */
66 MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
67 MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
68 MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
69 MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
70 MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
71 MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
72 MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
73 MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
74 MX31_PIN_USBOTG_CLK__USBOTG_CLK,
75 MX31_PIN_USBOTG_DIR__USBOTG_DIR,
76 MX31_PIN_USBOTG_NXT__USBOTG_NXT,
77 MX31_PIN_USBOTG_STP__USBOTG_STP,
Alberto Panizzo54c1f632010-05-19 11:34:43 +020078 /*Keyboard*/
79 MX31_PIN_KEY_ROW0_KEY_ROW0,
80 MX31_PIN_KEY_ROW1_KEY_ROW1,
81 MX31_PIN_KEY_ROW2_KEY_ROW2,
82 MX31_PIN_KEY_COL0_KEY_COL0,
83 MX31_PIN_KEY_COL1_KEY_COL1,
84 MX31_PIN_KEY_COL2_KEY_COL2,
85 MX31_PIN_KEY_COL3_KEY_COL3,
Fabio Estevam0d95b752010-12-21 16:38:22 -020086 /* USB Host 2 */
87 IOMUX_MODE(MX31_PIN_USBH2_CLK, IOMUX_CONFIG_FUNC),
88 IOMUX_MODE(MX31_PIN_USBH2_DIR, IOMUX_CONFIG_FUNC),
89 IOMUX_MODE(MX31_PIN_USBH2_NXT, IOMUX_CONFIG_FUNC),
90 IOMUX_MODE(MX31_PIN_USBH2_STP, IOMUX_CONFIG_FUNC),
91 IOMUX_MODE(MX31_PIN_USBH2_DATA0, IOMUX_CONFIG_FUNC),
92 IOMUX_MODE(MX31_PIN_USBH2_DATA1, IOMUX_CONFIG_FUNC),
93 IOMUX_MODE(MX31_PIN_PC_VS2, IOMUX_CONFIG_ALT1),
94 IOMUX_MODE(MX31_PIN_PC_BVD1, IOMUX_CONFIG_ALT1),
95 IOMUX_MODE(MX31_PIN_PC_BVD2, IOMUX_CONFIG_ALT1),
96 IOMUX_MODE(MX31_PIN_PC_RST, IOMUX_CONFIG_ALT1),
97 IOMUX_MODE(MX31_PIN_IOIS16, IOMUX_CONFIG_ALT1),
98 IOMUX_MODE(MX31_PIN_PC_RW_B, IOMUX_CONFIG_ALT1),
99 /* USB Host2 reset */
100 IOMUX_MODE(MX31_PIN_USB_BYP, IOMUX_CONFIG_GPIO),
Fabio Estevam3d943022011-03-01 16:59:45 -0300101 /* I2C1 */
102 MX31_PIN_I2C_CLK__I2C1_SCL,
103 MX31_PIN_I2C_DAT__I2C1_SDA,
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100104 /* SDHC1 */
105 MX31_PIN_SD1_DATA3__SD1_DATA3,
106 MX31_PIN_SD1_DATA2__SD1_DATA2,
107 MX31_PIN_SD1_DATA1__SD1_DATA1,
108 MX31_PIN_SD1_DATA0__SD1_DATA0,
109 MX31_PIN_SD1_CLK__SD1_CLK,
110 MX31_PIN_SD1_CMD__SD1_CMD,
111 MX31_PIN_GPIO3_1__GPIO3_1, /* Card detect */
112 MX31_PIN_GPIO3_0__GPIO3_0, /* OE */
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100113 /* Framebuffer */
114 MX31_PIN_LD0__LD0,
115 MX31_PIN_LD1__LD1,
116 MX31_PIN_LD2__LD2,
117 MX31_PIN_LD3__LD3,
118 MX31_PIN_LD4__LD4,
119 MX31_PIN_LD5__LD5,
120 MX31_PIN_LD6__LD6,
121 MX31_PIN_LD7__LD7,
122 MX31_PIN_LD8__LD8,
123 MX31_PIN_LD9__LD9,
124 MX31_PIN_LD10__LD10,
125 MX31_PIN_LD11__LD11,
126 MX31_PIN_LD12__LD12,
127 MX31_PIN_LD13__LD13,
128 MX31_PIN_LD14__LD14,
129 MX31_PIN_LD15__LD15,
130 MX31_PIN_LD16__LD16,
131 MX31_PIN_LD17__LD17,
132 MX31_PIN_VSYNC3__VSYNC3,
133 MX31_PIN_HSYNC__HSYNC,
134 MX31_PIN_FPSHIFT__FPSHIFT,
135 MX31_PIN_CONTRAST__CONTRAST,
Philippe Rétornaz5fb86e52012-05-15 18:42:26 +0200136 /* SSI */
137 MX31_PIN_STXD4__STXD4,
138 MX31_PIN_SRXD4__SRXD4,
139 MX31_PIN_SCK4__SCK4,
140 MX31_PIN_SFS4__SFS4,
Alberto Panizzo164f7b52011-03-07 11:47:37 +0100141};
142
143/*
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100144 * FB support
145 */
146static const struct fb_videomode fb_modedb[] = {
147 { /* 480x640 @ 60 Hz */
148 .name = "Epson-VGA",
149 .refresh = 60,
150 .xres = 480,
151 .yres = 640,
152 .pixclock = 41701,
153 .left_margin = 20,
154 .right_margin = 41,
155 .upper_margin = 10,
156 .lower_margin = 5,
157 .hsync_len = 20,
158 .vsync_len = 10,
159 .sync = FB_SYNC_OE_ACT_HIGH | FB_SYNC_CLK_INVERT,
160 .vmode = FB_VMODE_NONINTERLACED,
161 .flag = 0,
162 },
163};
164
Uwe Kleine-Königafa77ef2011-03-03 21:32:02 +0100165static struct mx3fb_platform_data mx3fb_pdata __initdata = {
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100166 .name = "Epson-VGA",
167 .mode = fb_modedb,
168 .num_modes = ARRAY_SIZE(fb_modedb),
169};
170
171/* LCD */
172static struct l4f00242t03_pdata mx31_3ds_l4f00242t03_pdata = {
173 .reset_gpio = IOMUX_TO_GPIO(MX31_PIN_LCS1),
174 .data_enable_gpio = IOMUX_TO_GPIO(MX31_PIN_SER_RS),
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100175};
176
177/*
178 * Support for SD card slot in personality board
179 */
180#define MX31_3DS_GPIO_SDHC1_CD IOMUX_TO_GPIO(MX31_PIN_GPIO3_1)
181#define MX31_3DS_GPIO_SDHC1_BE IOMUX_TO_GPIO(MX31_PIN_GPIO3_0)
182
183static struct gpio mx31_3ds_sdhc1_gpios[] = {
184 { MX31_3DS_GPIO_SDHC1_CD, GPIOF_IN, "sdhc1-card-detect" },
185 { MX31_3DS_GPIO_SDHC1_BE, GPIOF_OUT_INIT_LOW, "sdhc1-bus-en" },
186};
187
188static int mx31_3ds_sdhc1_init(struct device *dev,
189 irq_handler_t detect_irq,
190 void *data)
191{
192 int ret;
193
194 ret = gpio_request_array(mx31_3ds_sdhc1_gpios,
195 ARRAY_SIZE(mx31_3ds_sdhc1_gpios));
196 if (ret) {
Joe Perches75fd32b2014-09-13 11:31:15 -0700197 pr_warn("Unable to request the SD/MMC GPIOs.\n");
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100198 return ret;
199 }
200
Shawn Guoed175342011-12-02 20:00:33 +0800201 ret = request_irq(gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_GPIO3_1)),
Michael Opdenacker4c1dd3e2013-09-04 07:04:39 +0200202 detect_irq,
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100203 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
204 "sdhc1-detect", data);
205 if (ret) {
Joe Perches75fd32b2014-09-13 11:31:15 -0700206 pr_warn("Unable to request the SD/MMC card-detect IRQ.\n");
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100207 goto gpio_free;
208 }
209
210 return 0;
211
212gpio_free:
213 gpio_free_array(mx31_3ds_sdhc1_gpios,
214 ARRAY_SIZE(mx31_3ds_sdhc1_gpios));
215 return ret;
216}
217
218static void mx31_3ds_sdhc1_exit(struct device *dev, void *data)
219{
Shawn Guoed175342011-12-02 20:00:33 +0800220 free_irq(gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_GPIO3_1)), data);
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100221 gpio_free_array(mx31_3ds_sdhc1_gpios,
222 ARRAY_SIZE(mx31_3ds_sdhc1_gpios));
223}
224
225static void mx31_3ds_sdhc1_setpower(struct device *dev, unsigned int vdd)
226{
227 /*
228 * While the voltage stuff is done by the driver, activate the
229 * Buffer Enable Pin only if there is a card in slot to fix the card
230 * voltage issue caused by bi-directional chip TXB0108 on 3Stack.
231 * Done here because at this stage we have for sure a debounced value
232 * of the presence of the card, showed by the value of vdd.
233 * 7 == ilog2(MMC_VDD_165_195)
234 */
235 if (vdd > 7)
236 gpio_set_value(MX31_3DS_GPIO_SDHC1_BE, 1);
237 else
238 gpio_set_value(MX31_3DS_GPIO_SDHC1_BE, 0);
239}
240
241static struct imxmmc_platform_data sdhc1_pdata = {
242 .init = mx31_3ds_sdhc1_init,
243 .exit = mx31_3ds_sdhc1_exit,
244 .setpower = mx31_3ds_sdhc1_setpower,
Alberto Panizzo54c1f632010-05-19 11:34:43 +0200245};
246
247/*
248 * Matrix keyboard
249 */
250
251static const uint32_t mx31_3ds_keymap[] = {
252 KEY(0, 0, KEY_UP),
253 KEY(0, 1, KEY_DOWN),
254 KEY(1, 0, KEY_RIGHT),
255 KEY(1, 1, KEY_LEFT),
256 KEY(1, 2, KEY_ENTER),
257 KEY(2, 0, KEY_F6),
258 KEY(2, 1, KEY_F8),
259 KEY(2, 2, KEY_F9),
260 KEY(2, 3, KEY_F10),
261};
262
Uwe Kleine-Königd690b4c2010-11-16 21:27:33 +0100263static const struct matrix_keymap_data mx31_3ds_keymap_data __initconst = {
Alberto Panizzo54c1f632010-05-19 11:34:43 +0200264 .keymap = mx31_3ds_keymap,
265 .keymap_size = ARRAY_SIZE(mx31_3ds_keymap),
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100266};
267
268/* Regulators */
269static struct regulator_init_data pwgtx_init = {
270 .constraints = {
271 .boot_on = 1,
272 .always_on = 1,
273 },
274};
275
Fabio Estevam0d95b752010-12-21 16:38:22 -0200276static struct regulator_init_data gpo_init = {
277 .constraints = {
278 .boot_on = 1,
279 .always_on = 1,
280 }
281};
282
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100283static struct regulator_consumer_supply vmmc2_consumers[] = {
Shawn Guo7f917a82012-09-16 16:54:30 +0800284 REGULATOR_SUPPLY("vmmc", "imx31-mmc.0"),
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100285};
286
287static struct regulator_init_data vmmc2_init = {
288 .constraints = {
289 .min_uV = 3000000,
290 .max_uV = 3000000,
291 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
292 REGULATOR_CHANGE_STATUS,
293 },
294 .num_consumer_supplies = ARRAY_SIZE(vmmc2_consumers),
295 .consumer_supplies = vmmc2_consumers,
296};
297
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100298static struct regulator_consumer_supply vmmc1_consumers[] = {
Mark Brown0556dc32011-10-31 17:11:48 -0700299 REGULATOR_SUPPLY("vcore", "spi0.0"),
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100300};
301
302static struct regulator_init_data vmmc1_init = {
303 .constraints = {
304 .min_uV = 2800000,
305 .max_uV = 2800000,
306 .apply_uV = 1,
307 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
308 REGULATOR_CHANGE_STATUS,
309 },
310 .num_consumer_supplies = ARRAY_SIZE(vmmc1_consumers),
311 .consumer_supplies = vmmc1_consumers,
312};
313
314static struct regulator_consumer_supply vgen_consumers[] = {
Mark Brown0556dc32011-10-31 17:11:48 -0700315 REGULATOR_SUPPLY("vdd", "spi0.0"),
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100316};
317
318static struct regulator_init_data vgen_init = {
319 .constraints = {
320 .min_uV = 1800000,
321 .max_uV = 1800000,
322 .apply_uV = 1,
323 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
324 REGULATOR_CHANGE_STATUS,
325 },
326 .num_consumer_supplies = ARRAY_SIZE(vgen_consumers),
327 .consumer_supplies = vgen_consumers,
328};
329
David Jander58363722011-02-10 10:59:44 +0100330static struct mc13xxx_regulator_init_data mx31_3ds_regulators[] = {
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100331 {
Yong Shen57c78e32010-12-14 14:00:53 +0800332 .id = MC13783_REG_PWGT1SPI, /* Power Gate for ARM core. */
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100333 .init_data = &pwgtx_init,
334 }, {
Yong Shen57c78e32010-12-14 14:00:53 +0800335 .id = MC13783_REG_PWGT2SPI, /* Power Gate for L2 Cache. */
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100336 .init_data = &pwgtx_init,
Fabio Estevam0d95b752010-12-21 16:38:22 -0200337 }, {
338
Sascha Hauerc97b7392011-01-14 09:44:02 +0100339 .id = MC13783_REG_GPO1, /* Turn on 1.8V */
Fabio Estevam0d95b752010-12-21 16:38:22 -0200340 .init_data = &gpo_init,
341 }, {
Sascha Hauerc97b7392011-01-14 09:44:02 +0100342 .id = MC13783_REG_GPO3, /* Turn on 3.3V */
Fabio Estevam0d95b752010-12-21 16:38:22 -0200343 .init_data = &gpo_init,
Alberto Panizzo0ce88b32011-03-07 11:45:07 +0100344 }, {
345 .id = MC13783_REG_VMMC2, /* Power MMC/SD, WiFi/Bluetooth. */
346 .init_data = &vmmc2_init,
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100347 }, {
348 .id = MC13783_REG_VMMC1, /* Power LCD, CMOS, FM, GPS, Accel. */
349 .init_data = &vmmc1_init,
350 }, {
351 .id = MC13783_REG_VGEN, /* Power LCD */
352 .init_data = &vgen_init,
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100353 },
354};
355
356/* MC13783 */
Philippe Rétornaz5fb86e52012-05-15 18:42:26 +0200357static struct mc13xxx_codec_platform_data mx31_3ds_codec = {
358 .dac_ssi_port = MC13783_SSI1_PORT,
359 .adc_ssi_port = MC13783_SSI1_PORT,
360};
361
Andres Salomon4ec1b542011-02-17 19:07:23 -0800362static struct mc13xxx_platform_data mc13783_pdata = {
363 .regulators = {
364 .regulators = mx31_3ds_regulators,
365 .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
366 },
Philippe Rétornaz5fb86e52012-05-15 18:42:26 +0200367 .codec = &mx31_3ds_codec,
368 .flags = MC13XXX_USE_TOUCHSCREEN | MC13XXX_USE_RTC | MC13XXX_USE_CODEC,
369
370};
371
372static struct imx_ssi_platform_data mx31_3ds_ssi_pdata = {
373 .flags = IMX_SSI_DMA | IMX_SSI_NET,
Alberto Panizzoa1ac4422010-03-23 19:50:28 +0100374};
375
376/* SPI */
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100377static const struct spi_imx_master spi0_pdata __initconst = {
Trent Piephofe1bd782018-04-02 13:06:05 -0700378 .num_chipselect = 3,
Alberto Panizzoa1ac4422010-03-23 19:50:28 +0100379};
380
Uwe Kleine-König06606ff2010-06-22 10:09:14 +0200381static const struct spi_imx_master spi1_pdata __initconst = {
Trent Piephofe1bd782018-04-02 13:06:05 -0700382 .num_chipselect = 3,
Valentin Longchamp63d976672009-01-28 15:13:53 +0100383};
384
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100385static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
386 {
387 .modalias = "mc13783",
388 .max_speed_hz = 1000000,
389 .bus_num = 1,
Greg Ungerer901f26b2017-03-17 15:03:02 +1000390 .chip_select = 2, /* SS2 */
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100391 .platform_data = &mc13783_pdata,
Shawn Guoed175342011-12-02 20:00:33 +0800392 /* irq number is run-time assigned */
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100393 .mode = SPI_CS_HIGH,
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100394 }, {
395 .modalias = "l4f00242t03",
396 .max_speed_hz = 5000000,
397 .bus_num = 0,
Greg Ungerer901f26b2017-03-17 15:03:02 +1000398 .chip_select = 2, /* SS2 */
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100399 .platform_data = &mx31_3ds_l4f00242t03_pdata,
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100400 },
401};
402
Alberto Panizzoa1b67b92010-03-23 19:49:35 +0100403/*
404 * NAND Flash
405 */
Uwe Kleine-Königa2ceeef2010-06-16 12:23:11 +0200406static const struct mxc_nand_platform_data
407mx31_3ds_nand_board_info __initconst = {
Alberto Panizzoa1b67b92010-03-23 19:49:35 +0100408 .width = 1,
409 .hw_ecc = 1,
Paul Bolle5328ecb2011-10-12 14:04:22 +0200410#ifdef CONFIG_MACH_MX31_3DS_MXC_NAND_USE_BBT
Alberto Panizzoa1b67b92010-03-23 19:49:35 +0100411 .flash_bbt = 1,
412#endif
413};
414
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200415/*
416 * USB OTG
417 */
418
419#define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
420 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
421
422#define USBOTG_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_PWR)
Fabio Estevam0d95b752010-12-21 16:38:22 -0200423#define USBH2_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_BYP)
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200424
Fabio Estevam41f63472010-06-21 13:33:05 -0700425static int mx31_3ds_usbotg_init(void)
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200426{
Fabio Estevam41f63472010-06-21 13:33:05 -0700427 int err;
428
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200429 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
430 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
431 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
432 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);
433 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);
434 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);
435 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);
436 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);
437 mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);
438 mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);
439 mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
440 mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
441
Fabio Estevam41f63472010-06-21 13:33:05 -0700442 err = gpio_request(USBOTG_RST_B, "otgusb-reset");
443 if (err) {
444 pr_err("Failed to request the USB OTG reset gpio\n");
445 return err;
446 }
447
448 err = gpio_direction_output(USBOTG_RST_B, 0);
449 if (err) {
450 pr_err("Failed to drive the USB OTG reset gpio\n");
451 goto usbotg_free_reset;
452 }
453
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200454 mdelay(1);
455 gpio_set_value(USBOTG_RST_B, 1);
Fabio Estevam41f63472010-06-21 13:33:05 -0700456 return 0;
457
458usbotg_free_reset:
459 gpio_free(USBOTG_RST_B);
460 return err;
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200461}
462
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100463static int mx31_3ds_otg_init(struct platform_device *pdev)
464{
465 return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
466}
467
468static int mx31_3ds_host2_init(struct platform_device *pdev)
Fabio Estevam0d95b752010-12-21 16:38:22 -0200469{
470 int err;
471
472 mxc_iomux_set_pad(MX31_PIN_USBH2_CLK, USB_PAD_CFG);
473 mxc_iomux_set_pad(MX31_PIN_USBH2_DIR, USB_PAD_CFG);
474 mxc_iomux_set_pad(MX31_PIN_USBH2_NXT, USB_PAD_CFG);
475 mxc_iomux_set_pad(MX31_PIN_USBH2_STP, USB_PAD_CFG);
476 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA0, USB_PAD_CFG);
477 mxc_iomux_set_pad(MX31_PIN_USBH2_DATA1, USB_PAD_CFG);
478 mxc_iomux_set_pad(MX31_PIN_PC_VS2, USB_PAD_CFG);
479 mxc_iomux_set_pad(MX31_PIN_PC_BVD1, USB_PAD_CFG);
480 mxc_iomux_set_pad(MX31_PIN_PC_BVD2, USB_PAD_CFG);
481 mxc_iomux_set_pad(MX31_PIN_PC_RST, USB_PAD_CFG);
482 mxc_iomux_set_pad(MX31_PIN_IOIS16, USB_PAD_CFG);
483 mxc_iomux_set_pad(MX31_PIN_PC_RW_B, USB_PAD_CFG);
484
485 err = gpio_request(USBH2_RST_B, "usbh2-reset");
486 if (err) {
487 pr_err("Failed to request the USB Host 2 reset gpio\n");
488 return err;
489 }
490
491 err = gpio_direction_output(USBH2_RST_B, 0);
492 if (err) {
493 pr_err("Failed to drive the USB Host 2 reset gpio\n");
494 goto usbotg_free_reset;
495 }
496
497 mdelay(1);
498 gpio_set_value(USBH2_RST_B, 1);
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100499
500 mdelay(10);
501
502 return mx31_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
Fabio Estevam0d95b752010-12-21 16:38:22 -0200503
504usbotg_free_reset:
505 gpio_free(USBH2_RST_B);
506 return err;
507}
508
Fabio Estevam1c50e672010-12-21 16:38:21 -0200509static struct mxc_usbh_platform_data otg_pdata __initdata = {
Sascha Hauer4bd597b2011-01-03 11:30:28 +0100510 .init = mx31_3ds_otg_init,
Fabio Estevam1c50e672010-12-21 16:38:21 -0200511 .portsc = MXC_EHCI_MODE_ULPI,
Fabio Estevam1c50e672010-12-21 16:38:21 -0200512};
Fabio Estevam0d95b752010-12-21 16:38:22 -0200513
514static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
515 .init = mx31_3ds_host2_init,
516 .portsc = MXC_EHCI_MODE_ULPI,
Fabio Estevam0d95b752010-12-21 16:38:22 -0200517};
Fabio Estevam1c50e672010-12-21 16:38:21 -0200518
Uwe Kleine-König9e1dde32010-11-12 16:40:06 +0100519static const struct fsl_usb2_platform_data usbotg_pdata __initconst = {
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200520 .operating_mode = FSL_USB2_DR_DEVICE,
521 .phy_mode = FSL_USB2_PHY_ULPI,
522};
523
Benoît Thébaudeau33a264d2012-06-12 19:46:43 +0200524static bool otg_mode_host __initdata;
Fabio Estevam1c50e672010-12-21 16:38:21 -0200525
526static int __init mx31_3ds_otg_mode(char *options)
527{
528 if (!strcmp(options, "host"))
Benoît Thébaudeau33a264d2012-06-12 19:46:43 +0200529 otg_mode_host = true;
Fabio Estevam1c50e672010-12-21 16:38:21 -0200530 else if (!strcmp(options, "device"))
Benoît Thébaudeau33a264d2012-06-12 19:46:43 +0200531 otg_mode_host = false;
Fabio Estevam1c50e672010-12-21 16:38:21 -0200532 else
533 pr_info("otg_mode neither \"host\" nor \"device\". "
534 "Defaulting to device\n");
Benoît Thébaudeau33a264d2012-06-12 19:46:43 +0200535 return 1;
Fabio Estevam1c50e672010-12-21 16:38:21 -0200536}
537__setup("otg_mode=", mx31_3ds_otg_mode);
538
Uwe Kleine-König16cf5c42010-06-23 11:46:16 +0200539static const struct imxuart_platform_data uart_pdata __initconst = {
Magnus Lilja153fa1d2009-05-16 12:43:10 +0200540 .flags = IMXUART_HAVE_RTSCTS,
541};
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100542
Fabio Estevam3d943022011-03-01 16:59:45 -0300543static const struct imxi2c_platform_data mx31_3ds_i2c0_data __initconst = {
544 .bitrate = 100000,
545};
546
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100547static void __init mx31_3ds_init(void)
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100548{
Shawn Guob78d8e52011-06-06 00:07:55 +0800549 imx31_soc_init();
550
Fabio Estevamb2a08e32011-06-20 10:37:13 -0300551 /* Configure SPI1 IOMUX */
552 mxc_iomux_set_gpr(MUX_PGP_CSPI_BB, true);
553
Alberto Panizzo11a332adf2010-03-23 19:46:57 +0100554 mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
555 "mx31_3ds");
Magnus Lilja153fa1d2009-05-16 12:43:10 +0200556
Uwe Kleine-König16cf5c42010-06-23 11:46:16 +0200557 imx31_add_imx_uart0(&uart_pdata);
Uwe Kleine-Königa2ceeef2010-06-16 12:23:11 +0200558 imx31_add_mxc_nand(&mx31_3ds_nand_board_info);
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100559
Rogerio Pimentel4a74bdd2010-10-25 12:55:14 -0200560 imx31_add_spi_imx1(&spi1_pdata);
Alberto Panizzo164f7b52011-03-07 11:47:37 +0100561
Uwe Kleine-Königd690b4c2010-11-16 21:27:33 +0100562 imx31_add_imx_keypad(&mx31_3ds_keymap_data);
Alberto Panizzo54c1f632010-05-19 11:34:43 +0200563
Vladimir Zapolskiyce689b02016-09-19 04:37:18 +0300564 imx31_add_imx2_wdt();
565 imx31_add_imx_i2c0(&mx31_3ds_i2c0_data);
566
567 imx31_add_spi_imx0(&spi0_pdata);
568 imx31_add_ipu_core();
569 imx31_add_mx3_sdc_fb(&mx3fb_pdata);
570
571 imx31_add_imx_ssi(0, &mx31_3ds_ssi_pdata);
572
573 imx_add_platform_device("imx_mc13783", 0, NULL, 0, NULL, 0);
574}
575
576static void __init mx31_3ds_late(void)
577{
Vladimir Zapolskiyce689b02016-09-19 04:37:18 +0300578 mx31_3ds_spi_devs[0].irq = gpio_to_irq(IOMUX_TO_GPIO(MX31_PIN_GPIO1_3));
579 spi_register_board_info(mx31_3ds_spi_devs,
580 ARRAY_SIZE(mx31_3ds_spi_devs));
581
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200582 mx31_3ds_usbotg_init();
Fabio Estevam1c50e672010-12-21 16:38:21 -0200583 if (otg_mode_host) {
Sascha Hauer48f6b092011-03-02 09:27:42 +0100584 otg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
585 ULPI_OTG_DRVVBUS_EXT);
586 if (otg_pdata.otg)
587 imx31_add_mxc_ehci_otg(&otg_pdata);
Fabio Estevam1c50e672010-12-21 16:38:21 -0200588 }
Sascha Hauer48f6b092011-03-02 09:27:42 +0100589 usbh2_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
590 ULPI_OTG_DRVVBUS_EXT);
591 if (usbh2_pdata.otg)
592 imx31_add_mxc_ehci_hs(2, &usbh2_pdata);
593
Fabio Estevam1c50e672010-12-21 16:38:21 -0200594 if (!otg_mode_host)
595 imx31_add_fsl_usb2_udc(&usbotg_pdata);
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200596
Shawn Guoed4a7fb2012-06-13 15:58:08 +0800597 if (mxc_expio_init(MX31_CS5_BASE_ADDR, IOMUX_TO_GPIO(MX31_PIN_GPIO1_1)))
Rogerio Pimentelb8be7b9a2010-10-25 12:54:24 -0200598 printk(KERN_WARNING "Init of the debug board failed, all "
Vladimir Zapolskiyce689b02016-09-19 04:37:18 +0300599 "devices on the debug board are unusable.\n");
Alberto Panizzoe42010e2011-03-07 11:46:38 +0100600
Vladimir Zapolskiyce689b02016-09-19 04:37:18 +0300601 imx31_add_mxc_mmc(0, &sdhc1_pdata);
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100602}
603
Alberto Panizzo11a332adf2010-03-23 19:46:57 +0100604static void __init mx31_3ds_timer_init(void)
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100605{
Sascha Hauer30c730f2009-02-16 14:36:49 +0100606 mx31_clocks_init(26000000);
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100607}
608
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100609MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
610 /* Maintainer: Freescale Semiconductor, Inc. */
Nicolas Pitredc8f1902011-07-05 22:38:12 -0400611 .atag_offset = 0x100,
Uwe Kleine-König97976e22011-02-07 16:35:20 +0100612 .map_io = mx31_map_io,
613 .init_early = imx31_init_early,
614 .init_irq = mx31_init_irq,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700615 .init_time = mx31_3ds_timer_init,
Uwe Kleine-Könige134fb22011-02-11 10:23:19 +0100616 .init_machine = mx31_3ds_init,
Vladimir Zapolskiyce689b02016-09-19 04:37:18 +0300617 .init_late = mx31_3ds_late,
Russell King65ea7882011-11-06 17:12:08 +0000618 .restart = mxc_restart,
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100619MACHINE_END