blob: fa973e40329ef066cede1da68996bc6b26c09a83 [file] [log] [blame]
Alberto Panizzo5e9145e2009-05-19 10:01:03 +02001/*
2 * armadillo5x0.c
3 *
4 * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
5 * updates in http://alberdroid.blogspot.com/
6 *
7 * Based on Atmark Techno, Inc. armadillo 500 BSP 2008
8 * Based on mx31ads.c and pcm037.c Great Work!
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 * MA 02110-1301, USA.
24 */
25
26#include <linux/types.h>
27#include <linux/init.h>
28#include <linux/clk.h>
29#include <linux/platform_device.h>
30#include <linux/gpio.h>
31#include <linux/smsc911x.h>
32#include <linux/interrupt.h>
33#include <linux/irq.h>
Alberto Panizzoc3a9c7f2009-06-17 15:05:21 +020034#include <linux/mtd/physmap.h>
Alberto Panizzo0c8bad62009-06-17 15:06:30 +020035#include <linux/io.h>
Alberto Panizzoe33c0492009-10-15 19:24:51 +020036#include <linux/input.h>
37#include <linux/gpio_keys.h>
Alberto Panizzo5e9145e2009-05-19 10:01:03 +020038
39#include <mach/hardware.h>
40#include <asm/mach-types.h>
41#include <asm/mach/arch.h>
42#include <asm/mach/time.h>
43#include <asm/memory.h>
44#include <asm/mach/map.h>
45
46#include <mach/common.h>
47#include <mach/imx-uart.h>
48#include <mach/iomux-mx3.h>
49#include <mach/board-armadillo5x0.h>
50#include <mach/mmc.h>
51#include <mach/ipu.h>
52#include <mach/mx3fb.h>
Alberto Panizzo0c8bad62009-06-17 15:06:30 +020053#include <mach/mxc_nand.h>
Alberto Panizzo5e9145e2009-05-19 10:01:03 +020054
55#include "devices.h"
Alberto Panizzo0c8bad62009-06-17 15:06:30 +020056#include "crm_regs.h"
Alberto Panizzo5e9145e2009-05-19 10:01:03 +020057
58static int armadillo5x0_pins[] = {
59 /* UART1 */
60 MX31_PIN_CTS1__CTS1,
61 MX31_PIN_RTS1__RTS1,
62 MX31_PIN_TXD1__TXD1,
63 MX31_PIN_RXD1__RXD1,
64 /* UART2 */
65 MX31_PIN_CTS2__CTS2,
66 MX31_PIN_RTS2__RTS2,
67 MX31_PIN_TXD2__TXD2,
68 MX31_PIN_RXD2__RXD2,
69 /* LAN9118_IRQ */
70 IOMUX_MODE(MX31_PIN_GPIO1_0, IOMUX_CONFIG_GPIO),
71 /* SDHC1 */
72 MX31_PIN_SD1_DATA3__SD1_DATA3,
73 MX31_PIN_SD1_DATA2__SD1_DATA2,
74 MX31_PIN_SD1_DATA1__SD1_DATA1,
75 MX31_PIN_SD1_DATA0__SD1_DATA0,
76 MX31_PIN_SD1_CLK__SD1_CLK,
77 MX31_PIN_SD1_CMD__SD1_CMD,
78 /* Framebuffer */
79 MX31_PIN_LD0__LD0,
80 MX31_PIN_LD1__LD1,
81 MX31_PIN_LD2__LD2,
82 MX31_PIN_LD3__LD3,
83 MX31_PIN_LD4__LD4,
84 MX31_PIN_LD5__LD5,
85 MX31_PIN_LD6__LD6,
86 MX31_PIN_LD7__LD7,
87 MX31_PIN_LD8__LD8,
88 MX31_PIN_LD9__LD9,
89 MX31_PIN_LD10__LD10,
90 MX31_PIN_LD11__LD11,
91 MX31_PIN_LD12__LD12,
92 MX31_PIN_LD13__LD13,
93 MX31_PIN_LD14__LD14,
94 MX31_PIN_LD15__LD15,
95 MX31_PIN_LD16__LD16,
96 MX31_PIN_LD17__LD17,
97 MX31_PIN_VSYNC3__VSYNC3,
98 MX31_PIN_HSYNC__HSYNC,
99 MX31_PIN_FPSHIFT__FPSHIFT,
100 MX31_PIN_DRDY0__DRDY0,
101 IOMUX_MODE(MX31_PIN_LCS1, IOMUX_CONFIG_GPIO), /*ADV7125_PSAVE*/
Alberto Panizzoe9a6c5d2009-10-15 19:31:07 +0200102 /* I2C2 */
103 MX31_PIN_CSPI2_MOSI__SCL,
104 MX31_PIN_CSPI2_MISO__SDA,
Alberto Panizzo0c8bad62009-06-17 15:06:30 +0200105};
Alberto Panizzoe9a6c5d2009-10-15 19:31:07 +0200106
Alberto Panizzoe33c0492009-10-15 19:24:51 +0200107/* GPIO BUTTONS */
108static struct gpio_keys_button armadillo5x0_buttons[] = {
109 {
110 .code = KEY_ENTER, /*28*/
111 .gpio = IOMUX_TO_GPIO(MX31_PIN_SCLK0),
112 .active_low = 1,
113 .desc = "menu",
114 .wakeup = 1,
115 }, {
116 .code = KEY_BACK, /*158*/
117 .gpio = IOMUX_TO_GPIO(MX31_PIN_SRST0),
118 .active_low = 1,
119 .desc = "back",
120 .wakeup = 1,
121 }
122};
123
124static struct gpio_keys_platform_data armadillo5x0_button_data = {
125 .buttons = armadillo5x0_buttons,
126 .nbuttons = ARRAY_SIZE(armadillo5x0_buttons),
127};
128
129static struct platform_device armadillo5x0_button_device = {
130 .name = "gpio-keys",
131 .id = -1,
132 .num_resources = 0,
133 .dev = {
134 .platform_data = &armadillo5x0_button_data,
135 }
136};
Alberto Panizzo5e9145e2009-05-19 10:01:03 +0200137
Alberto Panizzo0c8bad62009-06-17 15:06:30 +0200138/*
139 * NAND Flash
140 */
141static struct mxc_nand_platform_data armadillo5x0_nand_flash_pdata = {
142 .width = 1,
143 .hw_ecc = 1,
Alberto Panizzo5e9145e2009-05-19 10:01:03 +0200144};
145
146/*
Alberto Panizzoc3a9c7f2009-06-17 15:05:21 +0200147 * MTD NOR Flash
148 */
149static struct mtd_partition armadillo5x0_nor_flash_partitions[] = {
150 {
151 .name = "nor.bootloader",
152 .offset = 0x00000000,
153 .size = 4*32*1024,
154 }, {
155 .name = "nor.kernel",
156 .offset = MTDPART_OFS_APPEND,
157 .size = 16*128*1024,
158 }, {
159 .name = "nor.userland",
160 .offset = MTDPART_OFS_APPEND,
161 .size = 110*128*1024,
162 }, {
163 .name = "nor.config",
164 .offset = MTDPART_OFS_APPEND,
165 .size = 1*128*1024,
166 },
167};
168
169static struct physmap_flash_data armadillo5x0_nor_flash_pdata = {
170 .width = 2,
171 .parts = armadillo5x0_nor_flash_partitions,
172 .nr_parts = ARRAY_SIZE(armadillo5x0_nor_flash_partitions),
173};
174
175static struct resource armadillo5x0_nor_flash_resource = {
176 .flags = IORESOURCE_MEM,
177 .start = CS0_BASE_ADDR,
178 .end = CS0_BASE_ADDR + SZ_64M - 1,
179};
180
181static struct platform_device armadillo5x0_nor_flash = {
182 .name = "physmap-flash",
183 .id = -1,
184 .num_resources = 1,
185 .resource = &armadillo5x0_nor_flash_resource,
186};
187
188/*
Alberto Panizzo5e9145e2009-05-19 10:01:03 +0200189 * FB support
190 */
191static const struct fb_videomode fb_modedb[] = {
192 { /* 640x480 @ 60 Hz */
193 .name = "CRT-VGA",
194 .refresh = 60,
195 .xres = 640,
196 .yres = 480,
197 .pixclock = 39721,
198 .left_margin = 35,
199 .right_margin = 115,
200 .upper_margin = 43,
201 .lower_margin = 1,
202 .hsync_len = 10,
203 .vsync_len = 1,
204 .sync = FB_SYNC_OE_ACT_HIGH,
205 .vmode = FB_VMODE_NONINTERLACED,
206 .flag = 0,
207 }, {/* 800x600 @ 56 Hz */
208 .name = "CRT-SVGA",
209 .refresh = 56,
210 .xres = 800,
211 .yres = 600,
212 .pixclock = 30000,
213 .left_margin = 30,
214 .right_margin = 108,
215 .upper_margin = 13,
216 .lower_margin = 10,
217 .hsync_len = 10,
218 .vsync_len = 1,
219 .sync = FB_SYNC_OE_ACT_HIGH | FB_SYNC_HOR_HIGH_ACT |
220 FB_SYNC_VERT_HIGH_ACT,
221 .vmode = FB_VMODE_NONINTERLACED,
222 .flag = 0,
223 },
224};
225
226static struct ipu_platform_data mx3_ipu_data = {
227 .irq_base = MXC_IPU_IRQ_START,
228};
229
230static struct mx3fb_platform_data mx3fb_pdata = {
231 .dma_dev = &mx3_ipu.dev,
232 .name = "CRT-VGA",
233 .mode = fb_modedb,
234 .num_modes = ARRAY_SIZE(fb_modedb),
235};
236
237/*
238 * SDHC 1
239 * MMC support
240 */
241static int armadillo5x0_sdhc1_get_ro(struct device *dev)
242{
243 return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
244}
245
246static int armadillo5x0_sdhc1_init(struct device *dev,
247 irq_handler_t detect_irq, void *data)
248{
249 int ret;
250 int gpio_det, gpio_wp;
251
252 gpio_det = IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK);
253 gpio_wp = IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B);
254
255 ret = gpio_request(gpio_det, "sdhc-card-detect");
256 if (ret)
257 return ret;
258
259 gpio_direction_input(gpio_det);
260
261 ret = gpio_request(gpio_wp, "sdhc-write-protect");
262 if (ret)
263 goto err_gpio_free;
264
265 gpio_direction_input(gpio_wp);
266
267 /* When supported the trigger type have to be BOTH */
268 ret = request_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), detect_irq,
269 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
270 "sdhc-detect", data);
271
272 if (ret)
273 goto err_gpio_free_2;
274
275 return 0;
276
277err_gpio_free_2:
278 gpio_free(gpio_wp);
279
280err_gpio_free:
281 gpio_free(gpio_det);
282
283 return ret;
284
285}
286
287static void armadillo5x0_sdhc1_exit(struct device *dev, void *data)
288{
289 free_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), data);
290 gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK));
291 gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
292}
293
294static struct imxmmc_platform_data sdhc_pdata = {
295 .get_ro = armadillo5x0_sdhc1_get_ro,
296 .init = armadillo5x0_sdhc1_init,
297 .exit = armadillo5x0_sdhc1_exit,
298};
299
300/*
301 * SMSC 9118
302 * Network support
303 */
304static struct resource armadillo5x0_smc911x_resources[] = {
305 {
306 .start = CS3_BASE_ADDR,
307 .end = CS3_BASE_ADDR + SZ_32M - 1,
308 .flags = IORESOURCE_MEM,
309 }, {
310 .start = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
311 .end = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
312 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
313 },
314};
315
316static struct smsc911x_platform_config smsc911x_info = {
Alberto Panizzo07299ca2009-10-15 19:29:05 +0200317 .flags = SMSC911X_USE_16BIT,
Alberto Panizzo5e9145e2009-05-19 10:01:03 +0200318 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
319 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
320};
321
322static struct platform_device armadillo5x0_smc911x_device = {
323 .name = "smsc911x",
324 .id = -1,
325 .num_resources = ARRAY_SIZE(armadillo5x0_smc911x_resources),
326 .resource = armadillo5x0_smc911x_resources,
327 .dev = {
328 .platform_data = &smsc911x_info,
329 },
330};
331
332/* UART device data */
333static struct imxuart_platform_data uart_pdata = {
334 .flags = IMXUART_HAVE_RTSCTS,
335};
336
337static struct platform_device *devices[] __initdata = {
338 &armadillo5x0_smc911x_device,
Alberto Panizzoe9a6c5d2009-10-15 19:31:07 +0200339 &mxc_i2c_device1,
Alberto Panizzoe33c0492009-10-15 19:24:51 +0200340 &armadillo5x0_button_device,
Alberto Panizzo5e9145e2009-05-19 10:01:03 +0200341};
342
343/*
344 * Perform board specific initializations
345 */
346static void __init armadillo5x0_init(void)
347{
348 mxc_iomux_setup_multiple_pins(armadillo5x0_pins,
349 ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
350
351 platform_add_devices(devices, ARRAY_SIZE(devices));
352
353 /* Register UART */
354 mxc_register_device(&mxc_uart_device0, &uart_pdata);
355 mxc_register_device(&mxc_uart_device1, &uart_pdata);
356
357 /* SMSC9118 IRQ pin */
358 gpio_direction_input(MX31_PIN_GPIO1_0);
359
360 /* Register SDHC */
361 mxc_register_device(&mxcsdhc_device0, &sdhc_pdata);
362
363 /* Register FB */
364 mxc_register_device(&mx3_ipu, &mx3_ipu_data);
365 mxc_register_device(&mx3_fb, &mx3fb_pdata);
Alberto Panizzoc3a9c7f2009-06-17 15:05:21 +0200366
367 /* Register NOR Flash */
368 mxc_register_device(&armadillo5x0_nor_flash,
369 &armadillo5x0_nor_flash_pdata);
Alberto Panizzo0c8bad62009-06-17 15:06:30 +0200370
371 /* Register NAND Flash */
372 mxc_register_device(&mxc_nand_device, &armadillo5x0_nand_flash_pdata);
373
374 /* set NAND page size to 2k if not configured via boot mode pins */
375 __raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR);
Alberto Panizzo5e9145e2009-05-19 10:01:03 +0200376}
377
Alberto Panizzo5e9145e2009-05-19 10:01:03 +0200378static void __init armadillo5x0_timer_init(void)
379{
380 mx31_clocks_init(26000000);
381}
382
383static struct sys_timer armadillo5x0_timer = {
384 .init = armadillo5x0_timer_init,
385};
386
387MACHINE_START(ARMADILLO5X0, "Armadillo-500")
388 /* Maintainer: Alberto Panizzo */
389 .phys_io = AIPS1_BASE_ADDR,
390 .io_pg_offst = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
391 .boot_params = PHYS_OFFSET + 0x00000100,
Alberto Panizzo4e0f08812009-05-25 22:35:38 +0200392 .map_io = mx31_map_io,
Sascha Hauerc5aa0ad2009-05-25 17:36:19 +0200393 .init_irq = mx31_init_irq,
Alberto Panizzo5e9145e2009-05-19 10:01:03 +0200394 .timer = &armadillo5x0_timer,
395 .init_machine = armadillo5x0_init,
396MACHINE_END