blob: 55d6117fbae974b0ac5878a047ed8c52e2fcea6e [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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
Magnus Liljaa2ef4562010-05-14 17:08:29 +020019#include <linux/delay.h>
Fabio Estevam1553a1e2008-11-12 15:38:39 +010020#include <linux/types.h>
21#include <linux/init.h>
22#include <linux/clk.h>
23#include <linux/irq.h>
Magnus Lilja135cad32009-05-17 20:18:08 +020024#include <linux/gpio.h>
Magnus Lilja2b0c3672009-05-18 18:46:33 +020025#include <linux/smsc911x.h>
26#include <linux/platform_device.h>
Alberto Panizzoae7a3f12010-03-23 19:51:45 +010027#include <linux/mfd/mc13783.h>
28#include <linux/spi/spi.h>
29#include <linux/regulator/machine.h>
Magnus Liljaa2ef4562010-05-14 17:08:29 +020030#include <linux/fsl_devices.h>
Fabio Estevam1553a1e2008-11-12 15:38:39 +010031
32#include <mach/hardware.h>
33#include <asm/mach-types.h>
34#include <asm/mach/arch.h>
35#include <asm/mach/time.h>
36#include <asm/memory.h>
37#include <asm/mach/map.h>
38#include <mach/common.h>
Alberto Panizzo11a332a2010-03-23 19:46:57 +010039#include <mach/board-mx31_3ds.h>
Fabio Estevam1553a1e2008-11-12 15:38:39 +010040#include <mach/imx-uart.h>
41#include <mach/iomux-mx3.h>
Alberto Panizzoa1b67b92010-03-23 19:49:35 +010042#include <mach/mxc_nand.h>
Alberto Panizzoa1ac4422010-03-23 19:50:28 +010043#include <mach/spi.h>
Fabio Estevam1553a1e2008-11-12 15:38:39 +010044#include "devices.h"
45
46/*!
Alberto Panizzo11a332a2010-03-23 19:46:57 +010047 * @file mx31_3ds.c
Fabio Estevam1553a1e2008-11-12 15:38:39 +010048 *
49 * @brief This file contains the board-specific initialization routines.
50 *
51 * @ingroup System
52 */
53
Alberto Panizzo11a332a2010-03-23 19:46:57 +010054static int mx31_3ds_pins[] = {
Magnus Lilja153fa1d2009-05-16 12:43:10 +020055 /* UART1 */
Valentin Longchamp63d976672009-01-28 15:13:53 +010056 MX31_PIN_CTS1__CTS1,
57 MX31_PIN_RTS1__RTS1,
58 MX31_PIN_TXD1__TXD1,
Magnus Lilja135cad32009-05-17 20:18:08 +020059 MX31_PIN_RXD1__RXD1,
60 IOMUX_MODE(MX31_PIN_GPIO1_1, IOMUX_CONFIG_GPIO),
Alberto Panizzoa1ac4422010-03-23 19:50:28 +010061 /* SPI 1 */
62 MX31_PIN_CSPI2_SCLK__SCLK,
63 MX31_PIN_CSPI2_MOSI__MOSI,
64 MX31_PIN_CSPI2_MISO__MISO,
65 MX31_PIN_CSPI2_SPI_RDY__SPI_RDY,
66 MX31_PIN_CSPI2_SS0__SS0,
67 MX31_PIN_CSPI2_SS2__SS2, /*CS for MC13783 */
Alberto Panizzoae7a3f12010-03-23 19:51:45 +010068 /* MC13783 IRQ */
69 IOMUX_MODE(MX31_PIN_GPIO1_3, IOMUX_CONFIG_GPIO),
Magnus Liljaa2ef4562010-05-14 17:08:29 +020070 /* USB OTG reset */
71 IOMUX_MODE(MX31_PIN_USB_PWR, IOMUX_CONFIG_GPIO),
72 /* USB OTG */
73 MX31_PIN_USBOTG_DATA0__USBOTG_DATA0,
74 MX31_PIN_USBOTG_DATA1__USBOTG_DATA1,
75 MX31_PIN_USBOTG_DATA2__USBOTG_DATA2,
76 MX31_PIN_USBOTG_DATA3__USBOTG_DATA3,
77 MX31_PIN_USBOTG_DATA4__USBOTG_DATA4,
78 MX31_PIN_USBOTG_DATA5__USBOTG_DATA5,
79 MX31_PIN_USBOTG_DATA6__USBOTG_DATA6,
80 MX31_PIN_USBOTG_DATA7__USBOTG_DATA7,
81 MX31_PIN_USBOTG_CLK__USBOTG_CLK,
82 MX31_PIN_USBOTG_DIR__USBOTG_DIR,
83 MX31_PIN_USBOTG_NXT__USBOTG_NXT,
84 MX31_PIN_USBOTG_STP__USBOTG_STP,
Alberto Panizzoae7a3f12010-03-23 19:51:45 +010085};
86
87/* Regulators */
88static struct regulator_init_data pwgtx_init = {
89 .constraints = {
90 .boot_on = 1,
91 .always_on = 1,
92 },
93};
94
95static struct mc13783_regulator_init_data mx31_3ds_regulators[] = {
96 {
97 .id = MC13783_REGU_PWGT1SPI, /* Power Gate for ARM core. */
98 .init_data = &pwgtx_init,
99 }, {
100 .id = MC13783_REGU_PWGT2SPI, /* Power Gate for L2 Cache. */
101 .init_data = &pwgtx_init,
102 },
103};
104
105/* MC13783 */
106static struct mc13783_platform_data mc13783_pdata __initdata = {
107 .regulators = mx31_3ds_regulators,
108 .num_regulators = ARRAY_SIZE(mx31_3ds_regulators),
109 .flags = MC13783_USE_REGULATOR,
Alberto Panizzoa1ac4422010-03-23 19:50:28 +0100110};
111
112/* SPI */
113static int spi1_internal_chipselect[] = {
114 MXC_SPI_CS(0),
115 MXC_SPI_CS(2),
116};
117
118static struct spi_imx_master spi1_pdata = {
119 .chipselect = spi1_internal_chipselect,
120 .num_chipselect = ARRAY_SIZE(spi1_internal_chipselect),
Valentin Longchamp63d976672009-01-28 15:13:53 +0100121};
122
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100123static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
124 {
125 .modalias = "mc13783",
126 .max_speed_hz = 1000000,
127 .bus_num = 1,
128 .chip_select = 1, /* SS2 */
129 .platform_data = &mc13783_pdata,
130 .irq = IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
131 .mode = SPI_CS_HIGH,
132 },
133};
134
Alberto Panizzoa1b67b92010-03-23 19:49:35 +0100135/*
136 * NAND Flash
137 */
138static struct mxc_nand_platform_data imx31_3ds_nand_flash_pdata = {
139 .width = 1,
140 .hw_ecc = 1,
141#ifdef MACH_MX31_3DS_MXC_NAND_USE_BBT
142 .flash_bbt = 1,
143#endif
144};
145
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200146/*
147 * USB OTG
148 */
149
150#define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
151 PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
152
153#define USBOTG_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_PWR)
154
155static void mx31_3ds_usbotg_init(void)
156{
157 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
158 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
159 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
160 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA3, USB_PAD_CFG);
161 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA4, USB_PAD_CFG);
162 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA5, USB_PAD_CFG);
163 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA6, USB_PAD_CFG);
164 mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA7, USB_PAD_CFG);
165 mxc_iomux_set_pad(MX31_PIN_USBOTG_CLK, USB_PAD_CFG);
166 mxc_iomux_set_pad(MX31_PIN_USBOTG_DIR, USB_PAD_CFG);
167 mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
168 mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
169
170 gpio_request(USBOTG_RST_B, "otgusb-reset");
171 gpio_direction_output(USBOTG_RST_B, 0);
172 mdelay(1);
173 gpio_set_value(USBOTG_RST_B, 1);
174}
175
176static struct fsl_usb2_platform_data usbotg_pdata = {
177 .operating_mode = FSL_USB2_DR_DEVICE,
178 .phy_mode = FSL_USB2_PHY_ULPI,
179};
180
Magnus Lilja153fa1d2009-05-16 12:43:10 +0200181static struct imxuart_platform_data uart_pdata = {
182 .flags = IMXUART_HAVE_RTSCTS,
183};
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100184
Magnus Lilja135cad32009-05-17 20:18:08 +0200185/*
Magnus Lilja2b0c3672009-05-18 18:46:33 +0200186 * Support for the SMSC9217 on the Debug board.
187 */
188
189static struct smsc911x_platform_config smsc911x_config = {
190 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
191 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
192 .flags = SMSC911X_USE_16BIT | SMSC911X_FORCE_INTERNAL_PHY,
193 .phy_interface = PHY_INTERFACE_MODE_MII,
194};
195
196static struct resource smsc911x_resources[] = {
197 {
198 .start = LAN9217_BASE_ADDR,
199 .end = LAN9217_BASE_ADDR + 0xff,
200 .flags = IORESOURCE_MEM,
201 }, {
202 .start = EXPIO_INT_ENET,
203 .end = EXPIO_INT_ENET,
204 .flags = IORESOURCE_IRQ,
205 },
206};
207
208static struct platform_device smsc911x_device = {
209 .name = "smsc911x",
210 .id = -1,
211 .num_resources = ARRAY_SIZE(smsc911x_resources),
212 .resource = smsc911x_resources,
213 .dev = {
214 .platform_data = &smsc911x_config,
215 },
216};
217
218/*
Magnus Lilja135cad32009-05-17 20:18:08 +0200219 * Routines for the CPLD on the debug board. It contains a CPLD handling
220 * LEDs, switches, interrupts for Ethernet.
221 */
222
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100223static void mx31_3ds_expio_irq_handler(uint32_t irq, struct irq_desc *desc)
Magnus Lilja135cad32009-05-17 20:18:08 +0200224{
225 uint32_t imr_val;
226 uint32_t int_valid;
227 uint32_t expio_irq;
228
229 imr_val = __raw_readw(CPLD_INT_MASK_REG);
230 int_valid = __raw_readw(CPLD_INT_STATUS_REG) & ~imr_val;
231
232 expio_irq = MXC_EXP_IO_BASE;
233 for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
234 if ((int_valid & 1) == 0)
235 continue;
236 generic_handle_irq(expio_irq);
237 }
238}
239
240/*
241 * Disable an expio pin's interrupt by setting the bit in the imr.
242 * @param irq an expio virtual irq number
243 */
244static void expio_mask_irq(uint32_t irq)
245{
246 uint16_t reg;
247 uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
248
249 /* mask the interrupt */
250 reg = __raw_readw(CPLD_INT_MASK_REG);
251 reg |= 1 << expio;
252 __raw_writew(reg, CPLD_INT_MASK_REG);
253}
254
255/*
256 * Acknowledge an expanded io pin's interrupt by clearing the bit in the isr.
257 * @param irq an expanded io virtual irq number
258 */
259static void expio_ack_irq(uint32_t irq)
260{
261 uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
262
263 /* clear the interrupt status */
264 __raw_writew(1 << expio, CPLD_INT_RESET_REG);
265 __raw_writew(0, CPLD_INT_RESET_REG);
266 /* mask the interrupt */
267 expio_mask_irq(irq);
268}
269
270/*
271 * Enable a expio pin's interrupt by clearing the bit in the imr.
272 * @param irq a expio virtual irq number
273 */
274static void expio_unmask_irq(uint32_t irq)
275{
276 uint16_t reg;
277 uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
278
279 /* unmask the interrupt */
280 reg = __raw_readw(CPLD_INT_MASK_REG);
281 reg &= ~(1 << expio);
282 __raw_writew(reg, CPLD_INT_MASK_REG);
283}
284
285static struct irq_chip expio_irq_chip = {
286 .ack = expio_ack_irq,
287 .mask = expio_mask_irq,
288 .unmask = expio_unmask_irq,
289};
290
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100291static int __init mx31_3ds_init_expio(void)
Magnus Lilja135cad32009-05-17 20:18:08 +0200292{
293 int i;
294 int ret;
295
296 /* Check if there's a debug board connected */
297 if ((__raw_readw(CPLD_MAGIC_NUMBER1_REG) != 0xAAAA) ||
298 (__raw_readw(CPLD_MAGIC_NUMBER2_REG) != 0x5555) ||
299 (__raw_readw(CPLD_MAGIC_NUMBER3_REG) != 0xCAFE)) {
300 /* No Debug board found */
301 return -ENODEV;
302 }
303
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100304 pr_info("i.MX31 3DS Debug board detected, rev = 0x%04X\n",
Magnus Lilja135cad32009-05-17 20:18:08 +0200305 __raw_readw(CPLD_CODE_VER_REG));
306
307 /*
308 * Configure INT line as GPIO input
309 */
310 ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1), "sms9217-irq");
311 if (ret)
312 pr_warning("could not get LAN irq gpio\n");
313 else
314 gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1));
315
316 /* Disable the interrupts and clear the status */
317 __raw_writew(0, CPLD_INT_MASK_REG);
318 __raw_writew(0xFFFF, CPLD_INT_RESET_REG);
319 __raw_writew(0, CPLD_INT_RESET_REG);
320 __raw_writew(0x1F, CPLD_INT_MASK_REG);
321 for (i = MXC_EXP_IO_BASE;
322 i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES);
323 i++) {
324 set_irq_chip(i, &expio_irq_chip);
325 set_irq_handler(i, handle_level_irq);
326 set_irq_flags(i, IRQF_VALID);
327 }
328 set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_LOW);
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100329 set_irq_chained_handler(EXPIO_PARENT_INT, mx31_3ds_expio_irq_handler);
Magnus Lilja135cad32009-05-17 20:18:08 +0200330
331 return 0;
332}
333
334/*
335 * This structure defines the MX31 memory map.
336 */
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100337static struct map_desc mx31_3ds_io_desc[] __initdata = {
Magnus Lilja135cad32009-05-17 20:18:08 +0200338 {
Uwe Kleine-Königf568dd72009-12-09 11:57:21 +0100339 .virtual = MX31_CS5_BASE_ADDR_VIRT,
340 .pfn = __phys_to_pfn(MX31_CS5_BASE_ADDR),
341 .length = MX31_CS5_SIZE,
Magnus Lilja135cad32009-05-17 20:18:08 +0200342 .type = MT_DEVICE,
343 },
344};
345
346/*
347 * Set up static virtual mappings.
348 */
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100349static void __init mx31_3ds_map_io(void)
Magnus Lilja135cad32009-05-17 20:18:08 +0200350{
351 mx31_map_io();
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100352 iotable_init(mx31_3ds_io_desc, ARRAY_SIZE(mx31_3ds_io_desc));
Magnus Lilja135cad32009-05-17 20:18:08 +0200353}
354
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100355/*!
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100356 * Board specific initialization.
357 */
358static void __init mxc_board_init(void)
359{
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100360 mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
361 "mx31_3ds");
Magnus Lilja153fa1d2009-05-16 12:43:10 +0200362
363 mxc_register_device(&mxc_uart_device0, &uart_pdata);
Alberto Panizzoa1b67b92010-03-23 19:49:35 +0100364 mxc_register_device(&mxc_nand_device, &imx31_3ds_nand_flash_pdata);
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100365
Alberto Panizzoa1ac4422010-03-23 19:50:28 +0100366 mxc_register_device(&mxc_spi_device1, &spi1_pdata);
Alberto Panizzoae7a3f12010-03-23 19:51:45 +0100367 spi_register_board_info(mx31_3ds_spi_devs,
368 ARRAY_SIZE(mx31_3ds_spi_devs));
Magnus Lilja135cad32009-05-17 20:18:08 +0200369
Magnus Liljaa2ef4562010-05-14 17:08:29 +0200370 mx31_3ds_usbotg_init();
371 mxc_register_device(&mxc_otg_udc_device, &usbotg_pdata);
372
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100373 if (!mx31_3ds_init_expio())
Magnus Lilja2b0c3672009-05-18 18:46:33 +0200374 platform_device_register(&smsc911x_device);
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100375}
376
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100377static void __init mx31_3ds_timer_init(void)
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100378{
Sascha Hauer30c730f2009-02-16 14:36:49 +0100379 mx31_clocks_init(26000000);
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100380}
381
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100382static struct sys_timer mx31_3ds_timer = {
383 .init = mx31_3ds_timer_init,
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100384};
385
386/*
387 * The following uses standard kernel macros defined in arch.h in order to
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100388 * initialize __mach_desc_MX31_3DS data structure.
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100389 */
390MACHINE_START(MX31_3DS, "Freescale MX31PDK (3DS)")
391 /* Maintainer: Freescale Semiconductor, Inc. */
Uwe Kleine-Königf568dd72009-12-09 11:57:21 +0100392 .phys_io = MX31_AIPS1_BASE_ADDR,
Uwe Kleine-König321ed162009-12-10 10:41:26 +0100393 .io_pg_offst = (MX31_AIPS1_BASE_ADDR_VIRT >> 18) & 0xfffc,
Uwe Kleine-König34101232010-01-29 17:36:05 +0100394 .boot_params = MX3x_PHYS_OFFSET + 0x100,
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100395 .map_io = mx31_3ds_map_io,
Sascha Hauerc5aa0ad2009-05-25 17:36:19 +0200396 .init_irq = mx31_init_irq,
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100397 .init_machine = mxc_board_init,
Alberto Panizzo11a332a2010-03-23 19:46:57 +0100398 .timer = &mx31_3ds_timer,
Fabio Estevam1553a1e2008-11-12 15:38:39 +0100399MACHINE_END