Add touchscreen support for Pandora
[pandora-kernel.git] / arch / arm / mach-omap2 / board-omap3pandora.c
1 /*
2  * board-omap3pandora.c (Pandora Handheld Console)
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  *
18  */
19
20 #include <linux/clk.h>
21 #include <linux/delay.h>
22 #include <linux/err.h>
23 #include <linux/init.h>
24 #include <linux/io.h>
25 #include <linux/kernel.h>
26 #include <linux/platform_device.h>
27
28 #include <linux/spi/spi.h>
29 #include <linux/spi/ads7846.h>
30 #include <linux/i2c/twl4030.h>
31
32 #include <linux/mtd/mtd.h>
33 #include <linux/mtd/nand.h>
34 #include <linux/mtd/partitions.h>
35
36 #include <asm/mach-types.h>
37 #include <asm/mach/arch.h>
38 #include <asm/mach/flash.h>
39 #include <asm/mach/map.h>
40
41 #include <mach/board.h>
42 #include <mach/common.h>
43 #include <mach/gpio.h>
44 #include <mach/gpmc.h>
45 #include <mach/hardware.h>
46 #include <mach/hsmmc.h>
47 #include <mach/nand.h>
48 #include <mach/usb-ehci.h>
49 #include <mach/usb-musb.h>
50 #include <mach/mcspi.h>
51
52 #include "sdram-micron-mt46h32m32lf-6.h"
53
54 #define NAND_BLOCK_SIZE SZ_128K
55 #define GPMC_CS0_BASE  0x60
56 #define GPMC_CS_SIZE   0x30
57
58 static struct mtd_partition omap3pandora_nand_partitions[] = {
59         {
60                 .name           = "xloader",
61                 .offset         = 0,                    /* Offset = 0x00000 */
62                 .size           = 4 * NAND_BLOCK_SIZE,
63                 .mask_flags     = MTD_WRITEABLE
64         }, {
65                 .name           = "uboot",
66                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
67                 .size           = 14 * NAND_BLOCK_SIZE,
68         }, {
69                 .name           = "uboot environment",
70                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x240000 */
71                 .size           = 2 * NAND_BLOCK_SIZE,
72         }, {
73                 .name           = "linux",
74                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
75                 .size           = 32 * NAND_BLOCK_SIZE,
76         }, {
77                 .name           = "rootfs",
78                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
79                 .size           = MTDPART_SIZ_FULL,
80         },
81 };
82
83 static struct omap_nand_platform_data omap3pandora_nand_data = {
84         .parts          = omap3pandora_nand_partitions,
85         .nr_parts       = ARRAY_SIZE(omap3pandora_nand_partitions),
86         .dma_channel    = -1,   /* disable DMA in OMAP NAND driver */
87 };
88
89 static struct resource omap3pandora_nand_resource[] = {
90         {
91                 .flags          = IORESOURCE_MEM,
92         },
93 };
94
95 static struct platform_device omap3pandora_nand_device = {
96         .name           = "omap2-nand",
97         .id             = -1,
98         .dev            = {
99                 .platform_data  = &omap3pandora_nand_data,
100         },
101         .num_resources  = ARRAY_SIZE(omap3pandora_nand_resource),
102         .resource       = omap3pandora_nand_resource,
103 };
104
105 static void __init omap3pandora_flash_init(void)
106 {
107         u8 cs = 0;
108         u8 nandcs = GPMC_CS_NUM + 1;
109
110         u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
111
112         /* find out the chip-select on which NAND exists */
113         while (cs < GPMC_CS_NUM) {
114                 u32 ret = 0;
115                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
116
117                 if ((ret & 0xC00) == 0x800) {
118                         printk(KERN_INFO "Found NAND on CS%d\n", cs);
119                         if (nandcs > GPMC_CS_NUM)
120                                 nandcs = cs;
121                 }
122                 cs++;
123         }
124
125         if (nandcs > GPMC_CS_NUM) {
126                 printk(KERN_INFO "NAND: Unable to find configuration "
127                                  "in GPMC\n ");
128                 return;
129         }
130
131         if (nandcs < GPMC_CS_NUM) {
132                 omap3pandora_nand_data.cs = nandcs;
133                 omap3pandora_nand_data.gpmc_cs_baseaddr = (void *)
134                         (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
135                 omap3pandora_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
136
137                 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
138                 if (platform_device_register(&omap3pandora_nand_device) < 0)
139                         printk(KERN_ERR "Unable to register NAND device\n");
140         }
141 }
142
143 static struct omap_uart_config omap3pandora_uart_config __initdata = {
144         .enabled_uarts  = (1 << 2), /* UART3 */
145 };
146
147 static struct twl4030_gpio_platform_data omap3pandora_gpio_data = {
148         .gpio_base      = OMAP_MAX_GPIO_LINES,
149         .irq_base       = TWL4030_GPIO_IRQ_BASE,
150         .irq_end        = TWL4030_GPIO_IRQ_END,
151 };
152
153 static struct twl4030_usb_data omap3pandora_usb_data = {
154         .usb_mode       = T2_USB_MODE_ULPI,
155 };
156
157 static struct twl4030_platform_data omap3pandora_twldata = {
158         .irq_base       = TWL4030_IRQ_BASE,
159         .irq_end        = TWL4030_IRQ_END,
160         .gpio           = &omap3pandora_gpio_data,
161         .usb            = &omap3pandora_usb_data,
162 };
163
164 static struct i2c_board_info __initdata omap3pandora_i2c_boardinfo[] = {
165         {
166                 I2C_BOARD_INFO("twl4030", 0x48),
167                 .flags = I2C_CLIENT_WAKE,
168                 .irq = INT_34XX_SYS_NIRQ,
169                 .platform_data = &omap3pandora_twldata,
170         },
171 };
172
173 static int __init omap3pandora_i2c_init(void)
174 {
175         omap_register_i2c_bus(1, 2600, omap3pandora_i2c_boardinfo,
176                         ARRAY_SIZE(omap3pandora_i2c_boardinfo));
177         /* i2c2 pins are not connected */
178         omap_register_i2c_bus(3, 400, NULL, 0);
179         return 0;
180 }
181
182 static void __init omap3pandora_init_irq(void)
183 {
184         omap2_init_common_hw(mt46h32m32lf6_sdrc_params);
185         omap_init_irq();
186         omap_gpio_init();
187 }
188
189 static void __init omap3pandora_ads7846_init(void)
190 {
191         int gpio = OMAP3_PANDORA_TS_GPIO;
192         int ret;
193
194         ret = gpio_request(gpio, "ads7846_pen_down");
195         if (ret < 0) {
196                 printk(KERN_ERR "Failed to request GPIO %d for "
197                                 "ads7846 pen down IRQ\n", gpio);
198                 return;
199         }
200
201         gpio_direction_input(gpio);
202 }
203
204 static int ads7846_get_pendown_state(void)
205 {
206         return !omap_get_gpio_datain(OMAP3_PANDORA_TS_GPIO);
207 }
208
209 static struct ads7846_platform_data ads7846_config = {
210         .x_max                  = 0x0fff,
211         .y_max                  = 0x0fff,
212         .x_plate_ohms           = 180,
213         .pressure_max           = 255,
214         .debounce_max           = 10,
215         .debounce_tol           = 3,
216         .debounce_rep           = 1,
217         .get_pendown_state      = ads7846_get_pendown_state,
218         .keep_vref_on           = 1,
219 };
220
221 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
222         .turbo_mode     = 0,
223         .single_channel = 1,  /* 0: slave, 1: master */
224 };
225
226 static struct spi_board_info omap3pandora_spi_board_info[] = {
227         {
228                 .modalias               = "ads7846",
229                 .bus_num                = 1,
230                 .chip_select            = 0,
231                 .max_speed_hz           = 1500000,
232                 .controller_data        = &ads7846_mcspi_config,
233                 .irq                    = OMAP_GPIO_IRQ(OMAP3_PANDORA_TS_GPIO),
234                 .platform_data          = &ads7846_config,
235         }
236 };
237
238 static struct platform_device omap3pandora_lcd_device = {
239         .name           = "pandora_lcd",
240         .id             = -1,
241 };
242
243 static struct omap_lcd_config omap3pandora_lcd_config __initdata = {
244         .ctrl_name      = "internal",
245 };
246
247 static struct omap_board_config_kernel omap3pandora_config[] __initdata = {
248         { OMAP_TAG_UART,        &omap3pandora_uart_config },
249         { OMAP_TAG_LCD,         &omap3pandora_lcd_config },
250 };
251
252 static struct platform_device *omap3pandora_devices[] __initdata = {
253         &omap3pandora_lcd_device,
254 };
255
256 static void __init omap3pandora_init(void)
257 {
258         omap3pandora_i2c_init();
259         platform_add_devices(omap3pandora_devices, ARRAY_SIZE(omap3pandora_devices));
260         omap_board_config = omap3pandora_config;
261         omap_board_config_size = ARRAY_SIZE(omap3pandora_config);
262         spi_register_board_info(omap3pandora_spi_board_info,
263                         ARRAY_SIZE(omap3pandora_spi_board_info));
264         omap_serial_init();
265         hsmmc_init();
266         usb_musb_init();
267         usb_ehci_init();
268         omap3pandora_flash_init();
269         omap3pandora_ads7846_init();
270 }
271
272 static void __init omap3pandora_map_io(void)
273 {
274         omap2_set_globals_343x();
275         omap2_map_common_io();
276 }
277
278 MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
279         .phys_io        = 0x48000000,
280         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
281         .boot_params    = 0x80000100,
282         .map_io         = omap3pandora_map_io,
283         .init_irq       = omap3pandora_init_irq,
284         .init_machine   = omap3pandora_init,
285         .timer          = &omap_timer,
286 MACHINE_END