Merge master.kernel.org:/pub/scm/linux/kernel/git/lethal/genesis-2.6 into devel-stable
[pandora-kernel.git] / arch / arm / mach-davinci / board-tnetv107x-evm.c
1 /*
2  * Texas Instruments TNETV107X EVM Board Support
3  *
4  * Copyright (C) 2010 Texas Instruments
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation version 2.
9  *
10  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11  * kind, whether express or implied; without even the implied warranty
12  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/console.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/interrupt.h>
20 #include <linux/gpio.h>
21 #include <linux/delay.h>
22 #include <linux/platform_device.h>
23 #include <linux/ratelimit.h>
24 #include <linux/mtd/mtd.h>
25 #include <linux/mtd/partitions.h>
26 #include <linux/input.h>
27 #include <linux/input/matrix_keypad.h>
28
29 #include <asm/mach/arch.h>
30 #include <asm/mach-types.h>
31
32 #include <mach/irqs.h>
33 #include <mach/edma.h>
34 #include <mach/mux.h>
35 #include <mach/cp_intc.h>
36 #include <mach/tnetv107x.h>
37
38 #define EVM_MMC_WP_GPIO         21
39 #define EVM_MMC_CD_GPIO         24
40
41 static int initialize_gpio(int gpio, char *desc)
42 {
43         int ret;
44
45         ret = gpio_request(gpio, desc);
46         if (ret < 0) {
47                 pr_err_ratelimited("cannot open %s gpio\n", desc);
48                 return -ENOSYS;
49         }
50         gpio_direction_input(gpio);
51         return gpio;
52 }
53
54 static int mmc_get_cd(int index)
55 {
56         static int gpio;
57
58         if (!gpio)
59                 gpio = initialize_gpio(EVM_MMC_CD_GPIO, "mmc card detect");
60
61         if (gpio < 0)
62                 return gpio;
63
64         return gpio_get_value(gpio) ? 0 : 1;
65 }
66
67 static int mmc_get_ro(int index)
68 {
69         static int gpio;
70
71         if (!gpio)
72                 gpio = initialize_gpio(EVM_MMC_WP_GPIO, "mmc write protect");
73
74         if (gpio < 0)
75                 return gpio;
76
77         return gpio_get_value(gpio) ? 1 : 0;
78 }
79
80 static struct davinci_mmc_config mmc_config = {
81         .get_cd         = mmc_get_cd,
82         .get_ro         = mmc_get_ro,
83         .wires          = 4,
84         .max_freq       = 50000000,
85         .caps           = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
86         .version        = MMC_CTLR_VERSION_1,
87 };
88
89 static const short sdio1_pins[] __initdata = {
90         TNETV107X_SDIO1_CLK_1,          TNETV107X_SDIO1_CMD_1,
91         TNETV107X_SDIO1_DATA0_1,        TNETV107X_SDIO1_DATA1_1,
92         TNETV107X_SDIO1_DATA2_1,        TNETV107X_SDIO1_DATA3_1,
93         TNETV107X_GPIO21,               TNETV107X_GPIO24,
94         -1
95 };
96
97 static const short uart1_pins[] __initdata = {
98         TNETV107X_UART1_RD,             TNETV107X_UART1_TD,
99         -1
100 };
101
102 static struct mtd_partition nand_partitions[] = {
103         /* bootloader (U-Boot, etc) in first 12 sectors */
104         {
105                 .name           = "bootloader",
106                 .offset         = 0,
107                 .size           = (12*SZ_128K),
108                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
109         },
110         /* bootloader params in the next sector */
111         {
112                 .name           = "params",
113                 .offset         = MTDPART_OFS_NXTBLK,
114                 .size           = SZ_128K,
115                 .mask_flags     = MTD_WRITEABLE,        /* force read-only */
116         },
117         /* kernel */
118         {
119                 .name           = "kernel",
120                 .offset         = MTDPART_OFS_NXTBLK,
121                 .size           = SZ_4M,
122                 .mask_flags     = 0,
123         },
124         /* file system */
125         {
126                 .name           = "filesystem",
127                 .offset         = MTDPART_OFS_NXTBLK,
128                 .size           = MTDPART_SIZ_FULL,
129                 .mask_flags     = 0,
130         }
131 };
132
133 static struct davinci_nand_pdata nand_config = {
134         .mask_cle       = 0x4000,
135         .mask_ale       = 0x2000,
136         .parts          = nand_partitions,
137         .nr_parts       = ARRAY_SIZE(nand_partitions),
138         .ecc_mode       = NAND_ECC_HW,
139         .options        = NAND_USE_FLASH_BBT,
140         .ecc_bits       = 1,
141 };
142
143 static struct davinci_uart_config serial_config __initconst = {
144         .enabled_uarts  = BIT(1),
145 };
146
147 static const uint32_t keymap[] = {
148         KEY(0, 0, KEY_NUMERIC_1),
149         KEY(0, 1, KEY_NUMERIC_2),
150         KEY(0, 2, KEY_NUMERIC_3),
151         KEY(0, 3, KEY_FN_F1),
152         KEY(0, 4, KEY_MENU),
153
154         KEY(1, 0, KEY_NUMERIC_4),
155         KEY(1, 1, KEY_NUMERIC_5),
156         KEY(1, 2, KEY_NUMERIC_6),
157         KEY(1, 3, KEY_UP),
158         KEY(1, 4, KEY_FN_F2),
159
160         KEY(2, 0, KEY_NUMERIC_7),
161         KEY(2, 1, KEY_NUMERIC_8),
162         KEY(2, 2, KEY_NUMERIC_9),
163         KEY(2, 3, KEY_LEFT),
164         KEY(2, 4, KEY_ENTER),
165
166         KEY(3, 0, KEY_NUMERIC_STAR),
167         KEY(3, 1, KEY_NUMERIC_0),
168         KEY(3, 2, KEY_NUMERIC_POUND),
169         KEY(3, 3, KEY_DOWN),
170         KEY(3, 4, KEY_RIGHT),
171
172         KEY(4, 0, KEY_FN_F3),
173         KEY(4, 1, KEY_FN_F4),
174         KEY(4, 2, KEY_MUTE),
175         KEY(4, 3, KEY_HOME),
176         KEY(4, 4, KEY_BACK),
177
178         KEY(5, 0, KEY_VOLUMEDOWN),
179         KEY(5, 1, KEY_VOLUMEUP),
180         KEY(5, 2, KEY_F1),
181         KEY(5, 3, KEY_F2),
182         KEY(5, 4, KEY_F3),
183 };
184
185 static const struct matrix_keymap_data keymap_data = {
186         .keymap         = keymap,
187         .keymap_size    = ARRAY_SIZE(keymap),
188 };
189
190 static struct matrix_keypad_platform_data keypad_config = {
191         .keymap_data    = &keymap_data,
192         .num_row_gpios  = 6,
193         .num_col_gpios  = 5,
194         .debounce_ms    = 0, /* minimum */
195         .active_low     = 0, /* pull up realization */
196         .no_autorepeat  = 0,
197 };
198
199 static struct tnetv107x_device_info evm_device_info __initconst = {
200         .serial_config          = &serial_config,
201         .mmc_config[1]          = &mmc_config,  /* controller 1 */
202         .nand_config[0]         = &nand_config, /* chip select 0 */
203         .keypad_config          = &keypad_config,
204 };
205
206 static __init void tnetv107x_evm_board_init(void)
207 {
208         davinci_cfg_reg_list(sdio1_pins);
209         davinci_cfg_reg_list(uart1_pins);
210
211         tnetv107x_devices_init(&evm_device_info);
212 }
213
214 #ifdef CONFIG_SERIAL_8250_CONSOLE
215 static int __init tnetv107x_evm_console_init(void)
216 {
217         return add_preferred_console("ttyS", 0, "115200");
218 }
219 console_initcall(tnetv107x_evm_console_init);
220 #endif
221
222 MACHINE_START(TNETV107X, "TNETV107X EVM")
223         .boot_params    = (TNETV107X_DDR_BASE + 0x100),
224         .map_io         = tnetv107x_init,
225         .init_irq       = cp_intc_init,
226         .timer          = &davinci_timer,
227         .init_machine   = tnetv107x_evm_board_init,
228 MACHINE_END