Armadillo500 Add support for onboard GPIO Buttons.
[platform/kernel/linux-arm64.git] / arch / arm / mach-mx3 / armadillo5x0.c
1 /*
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>
34 #include <linux/mtd/physmap.h>
35 #include <linux/io.h>
36 #include <linux/input.h>
37 #include <linux/gpio_keys.h>
38
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>
53 #include <mach/mxc_nand.h>
54
55 #include "devices.h"
56 #include "crm_regs.h"
57
58 static 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*/
102 };
103 /* GPIO BUTTONS */
104 static struct gpio_keys_button armadillo5x0_buttons[] = {
105         {
106                 .code           = KEY_ENTER, /*28*/
107                 .gpio           = IOMUX_TO_GPIO(MX31_PIN_SCLK0),
108                 .active_low     = 1,
109                 .desc           = "menu",
110                 .wakeup         = 1,
111         }, {
112                 .code           = KEY_BACK, /*158*/
113                 .gpio           = IOMUX_TO_GPIO(MX31_PIN_SRST0),
114                 .active_low     = 1,
115                 .desc           = "back",
116                 .wakeup         = 1,
117         }
118 };
119
120 static struct gpio_keys_platform_data armadillo5x0_button_data = {
121         .buttons        = armadillo5x0_buttons,
122         .nbuttons       = ARRAY_SIZE(armadillo5x0_buttons),
123 };
124
125 static struct platform_device armadillo5x0_button_device = {
126         .name           = "gpio-keys",
127         .id             = -1,
128         .num_resources  = 0,
129         .dev            = {
130                 .platform_data  = &armadillo5x0_button_data,
131         }
132 };
133
134 /*
135  * NAND Flash
136  */
137 static struct mxc_nand_platform_data armadillo5x0_nand_flash_pdata = {
138         .width          = 1,
139         .hw_ecc         = 1,
140 };
141
142 /*
143  * MTD NOR Flash
144  */
145 static struct mtd_partition armadillo5x0_nor_flash_partitions[] = {
146         {
147                 .name           = "nor.bootloader",
148                 .offset         = 0x00000000,
149                 .size           = 4*32*1024,
150         }, {
151                 .name           = "nor.kernel",
152                 .offset         = MTDPART_OFS_APPEND,
153                 .size           = 16*128*1024,
154         }, {
155                 .name           = "nor.userland",
156                 .offset         = MTDPART_OFS_APPEND,
157                 .size           = 110*128*1024,
158         }, {
159                 .name           = "nor.config",
160                 .offset         = MTDPART_OFS_APPEND,
161                 .size           = 1*128*1024,
162         },
163 };
164
165 static struct physmap_flash_data armadillo5x0_nor_flash_pdata = {
166         .width          = 2,
167         .parts          = armadillo5x0_nor_flash_partitions,
168         .nr_parts       = ARRAY_SIZE(armadillo5x0_nor_flash_partitions),
169 };
170
171 static struct resource armadillo5x0_nor_flash_resource = {
172         .flags          = IORESOURCE_MEM,
173         .start          = CS0_BASE_ADDR,
174         .end            = CS0_BASE_ADDR + SZ_64M - 1,
175 };
176
177 static struct platform_device armadillo5x0_nor_flash = {
178         .name                   = "physmap-flash",
179         .id                     = -1,
180         .num_resources          = 1,
181         .resource               = &armadillo5x0_nor_flash_resource,
182 };
183
184 /*
185  * FB support
186  */
187 static const struct fb_videomode fb_modedb[] = {
188         {       /* 640x480 @ 60 Hz */
189                 .name           = "CRT-VGA",
190                 .refresh        = 60,
191                 .xres           = 640,
192                 .yres           = 480,
193                 .pixclock       = 39721,
194                 .left_margin    = 35,
195                 .right_margin   = 115,
196                 .upper_margin   = 43,
197                 .lower_margin   = 1,
198                 .hsync_len      = 10,
199                 .vsync_len      = 1,
200                 .sync           = FB_SYNC_OE_ACT_HIGH,
201                 .vmode          = FB_VMODE_NONINTERLACED,
202                 .flag           = 0,
203         }, {/* 800x600 @ 56 Hz */
204                 .name           = "CRT-SVGA",
205                 .refresh        = 56,
206                 .xres           = 800,
207                 .yres           = 600,
208                 .pixclock       = 30000,
209                 .left_margin    = 30,
210                 .right_margin   = 108,
211                 .upper_margin   = 13,
212                 .lower_margin   = 10,
213                 .hsync_len      = 10,
214                 .vsync_len      = 1,
215                 .sync           = FB_SYNC_OE_ACT_HIGH | FB_SYNC_HOR_HIGH_ACT |
216                                   FB_SYNC_VERT_HIGH_ACT,
217                 .vmode          = FB_VMODE_NONINTERLACED,
218                 .flag           = 0,
219         },
220 };
221
222 static struct ipu_platform_data mx3_ipu_data = {
223         .irq_base = MXC_IPU_IRQ_START,
224 };
225
226 static struct mx3fb_platform_data mx3fb_pdata = {
227         .dma_dev        = &mx3_ipu.dev,
228         .name           = "CRT-VGA",
229         .mode           = fb_modedb,
230         .num_modes      = ARRAY_SIZE(fb_modedb),
231 };
232
233 /*
234  * SDHC 1
235  * MMC support
236  */
237 static int armadillo5x0_sdhc1_get_ro(struct device *dev)
238 {
239         return gpio_get_value(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
240 }
241
242 static int armadillo5x0_sdhc1_init(struct device *dev,
243                                    irq_handler_t detect_irq, void *data)
244 {
245         int ret;
246         int gpio_det, gpio_wp;
247
248         gpio_det = IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK);
249         gpio_wp = IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B);
250
251         ret = gpio_request(gpio_det, "sdhc-card-detect");
252         if (ret)
253                 return ret;
254
255         gpio_direction_input(gpio_det);
256
257         ret = gpio_request(gpio_wp, "sdhc-write-protect");
258         if (ret)
259                 goto err_gpio_free;
260
261         gpio_direction_input(gpio_wp);
262
263         /* When supported the trigger type have to be BOTH */
264         ret = request_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), detect_irq,
265                           IRQF_DISABLED | IRQF_TRIGGER_FALLING,
266                           "sdhc-detect", data);
267
268         if (ret)
269                 goto err_gpio_free_2;
270
271         return 0;
272
273 err_gpio_free_2:
274         gpio_free(gpio_wp);
275
276 err_gpio_free:
277         gpio_free(gpio_det);
278
279         return ret;
280
281 }
282
283 static void armadillo5x0_sdhc1_exit(struct device *dev, void *data)
284 {
285         free_irq(IOMUX_TO_IRQ(MX31_PIN_ATA_DMACK), data);
286         gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK));
287         gpio_free(IOMUX_TO_GPIO(MX31_PIN_ATA_RESET_B));
288 }
289
290 static struct imxmmc_platform_data sdhc_pdata = {
291         .get_ro = armadillo5x0_sdhc1_get_ro,
292         .init = armadillo5x0_sdhc1_init,
293         .exit = armadillo5x0_sdhc1_exit,
294 };
295
296 /*
297  * SMSC 9118
298  * Network support
299  */
300 static struct resource armadillo5x0_smc911x_resources[] = {
301         {
302                 .start  = CS3_BASE_ADDR,
303                 .end    = CS3_BASE_ADDR + SZ_32M - 1,
304                 .flags  = IORESOURCE_MEM,
305         }, {
306                 .start  = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
307                 .end    = IOMUX_TO_IRQ(MX31_PIN_GPIO1_0),
308                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
309         },
310 };
311
312 static struct smsc911x_platform_config smsc911x_info = {
313         .flags          = SMSC911X_USE_32BIT,
314         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
315         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
316 };
317
318 static struct platform_device armadillo5x0_smc911x_device = {
319         .name           = "smsc911x",
320         .id             = -1,
321         .num_resources  = ARRAY_SIZE(armadillo5x0_smc911x_resources),
322         .resource       = armadillo5x0_smc911x_resources,
323         .dev            = {
324                 .platform_data = &smsc911x_info,
325         },
326 };
327
328 /* UART device data */
329 static struct imxuart_platform_data uart_pdata = {
330         .flags = IMXUART_HAVE_RTSCTS,
331 };
332
333 static struct platform_device *devices[] __initdata = {
334         &armadillo5x0_smc911x_device,
335         &armadillo5x0_button_device,
336 };
337
338 /*
339  * Perform board specific initializations
340  */
341 static void __init armadillo5x0_init(void)
342 {
343         mxc_iomux_setup_multiple_pins(armadillo5x0_pins,
344                         ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
345
346         platform_add_devices(devices, ARRAY_SIZE(devices));
347
348         /* Register UART */
349         mxc_register_device(&mxc_uart_device0, &uart_pdata);
350         mxc_register_device(&mxc_uart_device1, &uart_pdata);
351
352         /* SMSC9118 IRQ pin */
353         gpio_direction_input(MX31_PIN_GPIO1_0);
354
355         /* Register SDHC */
356         mxc_register_device(&mxcsdhc_device0, &sdhc_pdata);
357
358         /* Register FB */
359         mxc_register_device(&mx3_ipu, &mx3_ipu_data);
360         mxc_register_device(&mx3_fb, &mx3fb_pdata);
361
362         /* Register NOR Flash */
363         mxc_register_device(&armadillo5x0_nor_flash,
364                             &armadillo5x0_nor_flash_pdata);
365
366         /* Register NAND Flash */
367         mxc_register_device(&mxc_nand_device, &armadillo5x0_nand_flash_pdata);
368
369         /* set NAND page size to 2k if not configured via boot mode pins */
370         __raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR);
371 }
372
373 static void __init armadillo5x0_timer_init(void)
374 {
375         mx31_clocks_init(26000000);
376 }
377
378 static struct sys_timer armadillo5x0_timer = {
379         .init   = armadillo5x0_timer_init,
380 };
381
382 MACHINE_START(ARMADILLO5X0, "Armadillo-500")
383         /* Maintainer: Alberto Panizzo  */
384         .phys_io        = AIPS1_BASE_ADDR,
385         .io_pg_offst    = ((AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
386         .boot_params    = PHYS_OFFSET + 0x00000100,
387         .map_io         = mx31_map_io,
388         .init_irq       = mx31_init_irq,
389         .timer          = &armadillo5x0_timer,
390         .init_machine   = armadillo5x0_init,
391 MACHINE_END