]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-3430sdp.c
55691b52e0fd42e57aca914343c367e4b9540264
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / board-3430sdp.c
1 /*
2  * linux/arch/arm/mach-omap2/board-3430sdp.c
3  *
4  * Copyright (C) 2007 Texas Instruments
5  *
6  * Modified from mach-omap2/board-generic.c
7  *
8  * Initial code: Syed Mohammed Khasim
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 version 2 as
12  * published by the Free Software Foundation.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/partitions.h>
20 #include <linux/delay.h>
21 #include <linux/input.h>
22 #include <linux/workqueue.h>
23 #include <linux/err.h>
24 #include <linux/clk.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/ads7846.h>
27
28 #include <asm/hardware.h>
29 #include <asm/mach-types.h>
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
32 #include <asm/mach/flash.h>
33
34 #include <asm/arch/twl4030.h>
35 #include <asm/arch/mcspi.h>
36 #include <asm/arch/gpio.h>
37 #include <asm/arch/mux.h>
38 #include <asm/arch/board.h>
39 #include <asm/arch/common.h>
40 #include <asm/arch/keypad.h>
41 #include <asm/arch/dma.h>
42 #include <asm/arch/gpmc.h>
43
44 #include <asm/io.h>
45 #include <asm/delay.h>
46
47 #define SDP3430_FLASH_CS        0
48 #define SDP3430_SMC91X_CS       3
49
50 #define ENABLE_VAUX3_DEDICATED  0x03
51 #define ENABLE_VAUX3_DEV_GRP    0x20
52
53 static struct mtd_partition sdp3430_partitions[] = {
54         /* bootloader (U-Boot, etc) in first sector */
55         {
56                   .name         = "bootloader",
57                   .offset               = 0,
58                   .size         = SZ_256K,
59                   .mask_flags   = MTD_WRITEABLE, /* force read-only */
60         },
61         /* bootloader params in the next sector */
62         {
63                   .name         = "params",
64                   .offset               = MTDPART_OFS_APPEND,
65                   .size         = SZ_128K,
66                   .mask_flags   = 0,
67         },
68         /* kernel */
69         {
70                   .name         = "kernel",
71                   .offset               = MTDPART_OFS_APPEND,
72                   .size         = SZ_2M,
73                   .mask_flags   = 0
74         },
75         /* file system */
76         {
77                   .name         = "filesystem",
78                   .offset               = MTDPART_OFS_APPEND,
79                   .size         = MTDPART_SIZ_FULL,
80                   .mask_flags   = 0
81         }
82 };
83
84 static struct flash_platform_data sdp3430_flash_data = {
85         .map_name       = "cfi_probe",
86         .width          = 2,
87         .parts          = sdp3430_partitions,
88         .nr_parts       = ARRAY_SIZE(sdp3430_partitions),
89 };
90
91 static struct resource sdp3430_flash_resource = {
92         .start          = FLASH_BASE,
93         .end            = FLASH_BASE + SZ_64M - 1,
94         .flags          = IORESOURCE_MEM,
95 };
96
97 static struct platform_device sdp3430_flash_device = {
98         .name           = "omapflash",
99         .id             = 0,
100         .dev            = {
101                 .platform_data  = &sdp3430_flash_data,
102         },
103         .num_resources  = 1,
104         .resource       = &sdp3430_flash_resource,
105 };
106
107 static struct resource sdp3430_smc91x_resources[] = {
108         [0] = {
109                 .start  = OMAP34XX_ETHR_START,
110                 .end    = OMAP34XX_ETHR_START + SZ_4K,
111                 .flags          = IORESOURCE_MEM,
112         },
113         [1] = {
114                 .start          = OMAP_GPIO_IRQ(OMAP34XX_ETHR_GPIO_IRQ),
115                 .end    = 0,
116                 .flags          = IORESOURCE_IRQ,
117         },
118 };
119
120 static struct platform_device sdp3430_smc91x_device = {
121         .name           = "smc91x",
122         .id             = -1,
123         .num_resources  = ARRAY_SIZE(sdp3430_smc91x_resources),
124         .resource       = sdp3430_smc91x_resources,
125 };
126
127 static int sdp3430_keymap[] = {
128         KEY(0, 0, KEY_LEFT),
129         KEY(0, 1, KEY_RIGHT),
130         KEY(0, 2, KEY_A),
131         KEY(0, 3, KEY_B),
132         KEY(0, 4, KEY_C),
133         KEY(1, 0, KEY_DOWN),
134         KEY(1, 1, KEY_UP),
135         KEY(1, 2, KEY_E),
136         KEY(1, 3, KEY_F),
137         KEY(1, 4, KEY_G),
138         KEY(2, 0, KEY_ENTER),
139         KEY(2, 1, KEY_I),
140         KEY(2, 2, KEY_J),
141         KEY(2, 3, KEY_K),
142         KEY(2, 4, KEY_3),
143         KEY(3, 0, KEY_M),
144         KEY(3, 1, KEY_N),
145         KEY(3, 2, KEY_O),
146         KEY(3, 3, KEY_P),
147         KEY(3, 4, KEY_Q),
148         KEY(4, 0, KEY_R),
149         KEY(4, 1, KEY_4),
150         KEY(4, 2, KEY_T),
151         KEY(4, 3, KEY_U),
152         KEY(4, 4, KEY_D),
153         KEY(5, 0, KEY_V),
154         KEY(5, 1, KEY_W),
155         KEY(5, 2, KEY_L),
156         KEY(5, 3, KEY_S),
157         KEY(5, 4, KEY_H),
158         0
159 };
160
161 static struct omap_kp_platform_data sdp3430_kp_data = {
162         .rows           = 5,
163         .cols           = 6,
164         .keymap         = sdp3430_keymap,
165         .keymapsize     = ARRAY_SIZE(sdp3430_keymap),
166         .rep            = 1,
167 };
168
169 static struct platform_device sdp3430_kp_device = {
170         .name           = "omap_twl4030keypad",
171         .id             = -1,
172         .dev            = {
173                 .platform_data  = &sdp3430_kp_data,
174         },
175 };
176
177 /**
178  * @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
179  *
180  * @return - void. If request gpio fails then Flag KERN_ERR.
181  */
182 static void ads7846_dev_init(void)
183 {
184         if (omap_request_gpio(TS_GPIO) < 0) {
185                 printk(KERN_ERR "can't get ads746 pen down GPIO\n");
186                 return;
187         }
188
189         omap_set_gpio_direction(TS_GPIO, 1);
190
191         omap_set_gpio_debounce(TS_GPIO, 1);
192         omap_set_gpio_debounce_time(TS_GPIO, 0xa);
193 }
194
195 static int ads7846_get_pendown_state(void)
196 {
197         return !omap_get_gpio_datain(TS_GPIO);
198 }
199
200 /*
201  * This enable(1)/disable(0) the voltage for TS: uses twl4030 calls
202  */
203 static int ads7846_vaux_control(int vaux_cntrl)
204 {
205         int ret = 0;
206
207 #ifdef CONFIG_TWL4030_CORE
208         /* check for return value of ldo_use: if success it returns 0 */
209         if (vaux_cntrl == VAUX_ENABLE) {
210                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
211                         ENABLE_VAUX3_DEDICATED, TWL4030_VAUX3_DEDICATED))
212                         return -EIO;
213                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
214                         ENABLE_VAUX3_DEV_GRP, TWL4030_VAUX3_DEV_GRP))
215                         return -EIO;
216         } else if (vaux_cntrl == VAUX_DISABLE) {
217                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
218                         0x00, TWL4030_VAUX3_DEDICATED))
219                         return -EIO;
220                 if (ret != twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
221                         0x00, TWL4030_VAUX3_DEV_GRP))
222                         return -EIO;
223         }
224 #else
225         ret = -EIO;
226 #endif
227         return ret;
228 }
229
230 static struct ads7846_platform_data tsc2046_config __initdata = {
231         .get_pendown_state      = ads7846_get_pendown_state,
232         .keep_vref_on           = 1,
233         .vaux_control           = ads7846_vaux_control,
234 };
235
236
237 static struct omap2_mcspi_device_config tsc2046_mcspi_config = {
238         .turbo_mode     = 0,
239         .single_channel = 1,  /* 0: slave, 1: master */
240 };
241
242 static struct spi_board_info sdp3430_spi_board_info[] __initdata = {
243         [0] = {
244                 /*
245                  * TSC2046 operates at a max freqency of 2MHz, so
246                  * operate slightly below at 1.5MHz
247                  */
248                 .modalias               = "ads7846",
249                 .bus_num                = 1,
250                 .chip_select            = 0,
251                 .max_speed_hz           = 1500000,
252                 .controller_data        = &tsc2046_mcspi_config,
253                 .irq                    = OMAP_GPIO_IRQ(TS_GPIO),
254                 .platform_data          = &tsc2046_config,
255         },
256 };
257 static struct platform_device *sdp3430_devices[] __initdata = {
258         &sdp3430_smc91x_device,
259         &sdp3430_flash_device,
260         &sdp3430_kp_device,
261 };
262
263 static inline void __init sdp3430_init_smc91x(void)
264 {
265         int eth_cs;
266         unsigned long cs_mem_base;
267
268         eth_cs  = SDP3430_SMC91X_CS;
269
270         if (gpmc_cs_request(eth_cs, SZ_16M, &cs_mem_base) < 0) {
271                 printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
272                 return;
273         }
274
275         sdp3430_smc91x_resources[0].start = cs_mem_base + 0x0;
276         sdp3430_smc91x_resources[0].end   = cs_mem_base + 0xf;
277         udelay(100);
278
279         if (omap_request_gpio(OMAP34XX_ETHR_GPIO_IRQ) < 0) {
280                 printk(KERN_ERR "Failed to request GPIO%d for smc91x IRQ\n",
281                         OMAP34XX_ETHR_GPIO_IRQ);
282                 return;
283         }
284         omap_set_gpio_direction(OMAP34XX_ETHR_GPIO_IRQ, 1);
285 }
286
287 static void __init omap_3430sdp_init_irq(void)
288 {
289         omap2_init_common_hw();
290         omap_init_irq();
291         omap_gpio_init();
292         sdp3430_init_smc91x();
293 }
294
295 static struct omap_uart_config sdp3430_uart_config __initdata = {
296         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
297 };
298
299 static struct omap_board_config_kernel sdp3430_config[] = {
300         { OMAP_TAG_UART,        &sdp3430_uart_config },
301 };
302 static int __init omap3430_i2c_init(void)
303 {
304         omap_register_i2c_bus(1, 2600, NULL, 0);
305         omap_register_i2c_bus(2, 400, NULL, 0);
306         omap_register_i2c_bus(3, 400, NULL, 0);
307         return 0;
308 }
309
310 static void __init omap_3430sdp_init(void)
311 {
312         platform_add_devices(sdp3430_devices, ARRAY_SIZE(sdp3430_devices));
313         omap_board_config = sdp3430_config;
314         omap_board_config_size = ARRAY_SIZE(sdp3430_config);
315         spi_register_board_info(sdp3430_spi_board_info,
316                                 ARRAY_SIZE(sdp3430_spi_board_info));
317         ads7846_dev_init();
318         omap_serial_init();
319 }
320
321 static void __init omap_3430sdp_map_io(void)
322 {
323         omap2_set_globals_343x();
324         omap2_map_common_io();
325 }
326 arch_initcall(omap3430_i2c_init);
327
328 MACHINE_START(OMAP_3430SDP, "OMAP3430 3430SDP board")
329         /* Maintainer: Syed Khasim - Texas Instruments Inc */
330         .phys_io        = 0x48000000,
331         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
332         .boot_params    = 0x80000100,
333         .map_io         = omap_3430sdp_map_io,
334         .init_irq       = omap_3430sdp_init_irq,
335         .init_machine   = omap_3430sdp_init,
336         .timer          = &omap_timer,
337 MACHINE_END