Merge branch 'master' of git://git.kernel.org/pub/scm/fs/xfs/xfs
[pandora-kernel.git] / arch / arm / mach-omap2 / board-overo.c
1 /*
2  * board-overo.c (Gumstix Overo)
3  *
4  * Initial code: Steve Sakoman <steve@sakoman.com>
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
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  */
21
22 #include <linux/clk.h>
23 #include <linux/delay.h>
24 #include <linux/err.h>
25 #include <linux/init.h>
26 #include <linux/io.h>
27 #include <linux/kernel.h>
28 #include <linux/platform_device.h>
29 #include <linux/i2c/twl4030.h>
30
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/nand.h>
33 #include <linux/mtd/partitions.h>
34
35 #include <asm/mach-types.h>
36 #include <asm/mach/arch.h>
37 #include <asm/mach/flash.h>
38 #include <asm/mach/map.h>
39
40 #include <mach/board.h>
41 #include <mach/common.h>
42 #include <mach/gpio.h>
43 #include <mach/gpmc.h>
44 #include <mach/hardware.h>
45 #include <mach/nand.h>
46 #include <mach/usb.h>
47
48 #include "mmc-twl4030.h"
49
50 #define OVERO_GPIO_BT_XGATE     15
51 #define OVERO_GPIO_W2W_NRESET   16
52 #define OVERO_GPIO_BT_NRESET    164
53 #define OVERO_GPIO_USBH_CPEN    168
54 #define OVERO_GPIO_USBH_NRESET  183
55
56 #define NAND_BLOCK_SIZE SZ_128K
57 #define GPMC_CS0_BASE  0x60
58 #define GPMC_CS_SIZE   0x30
59
60 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
61         defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
62
63 #include <mach/mcspi.h>
64 #include <linux/spi/spi.h>
65 #include <linux/spi/ads7846.h>
66
67 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
68         .turbo_mode     = 0,
69         .single_channel = 1,    /* 0: slave, 1: master */
70 };
71
72 static int ads7846_get_pendown_state(void)
73 {
74         return !gpio_get_value(OVERO_GPIO_PENDOWN);
75 }
76
77 static struct ads7846_platform_data ads7846_config = {
78         .x_max                  = 0x0fff,
79         .y_max                  = 0x0fff,
80         .x_plate_ohms           = 180,
81         .pressure_max           = 255,
82         .debounce_max           = 10,
83         .debounce_tol           = 3,
84         .debounce_rep           = 1,
85         .get_pendown_state      = ads7846_get_pendown_state,
86         .keep_vref_on           = 1,
87 };
88
89 static struct spi_board_info overo_spi_board_info[] __initdata = {
90         {
91                 .modalias               = "ads7846",
92                 .bus_num                = 1,
93                 .chip_select            = 0,
94                 .max_speed_hz           = 1500000,
95                 .controller_data        = &ads7846_mcspi_config,
96                 .irq                    = OMAP_GPIO_IRQ(OVERO_GPIO_PENDOWN),
97                 .platform_data          = &ads7846_config,
98         }
99 };
100
101 static void __init overo_ads7846_init(void)
102 {
103         if ((gpio_request(OVERO_GPIO_PENDOWN, "ADS7846_PENDOWN") == 0) &&
104             (gpio_direction_input(OVERO_GPIO_PENDOWN) == 0)) {
105                 gpio_export(OVERO_GPIO_PENDOWN, 0);
106         } else {
107                 printk(KERN_ERR "could not obtain gpio for ADS7846_PENDOWN\n");
108                 return;
109         }
110
111         spi_register_board_info(overo_spi_board_info,
112                         ARRAY_SIZE(overo_spi_board_info));
113 }
114
115 #else
116 static inline void __init overo_ads7846_init(void) { return; }
117 #endif
118
119 static struct mtd_partition overo_nand_partitions[] = {
120         {
121                 .name           = "xloader",
122                 .offset         = 0,                    /* Offset = 0x00000 */
123                 .size           = 4 * NAND_BLOCK_SIZE,
124                 .mask_flags     = MTD_WRITEABLE
125         },
126         {
127                 .name           = "uboot",
128                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
129                 .size           = 14 * NAND_BLOCK_SIZE,
130         },
131         {
132                 .name           = "uboot environment",
133                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x240000 */
134                 .size           = 2 * NAND_BLOCK_SIZE,
135         },
136         {
137                 .name           = "linux",
138                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
139                 .size           = 32 * NAND_BLOCK_SIZE,
140         },
141         {
142                 .name           = "rootfs",
143                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
144                 .size           = MTDPART_SIZ_FULL,
145         },
146 };
147
148 static struct omap_nand_platform_data overo_nand_data = {
149         .parts = overo_nand_partitions,
150         .nr_parts = ARRAY_SIZE(overo_nand_partitions),
151         .dma_channel = -1,      /* disable DMA in OMAP NAND driver */
152 };
153
154 static struct resource overo_nand_resource = {
155         .flags          = IORESOURCE_MEM,
156 };
157
158 static struct platform_device overo_nand_device = {
159         .name           = "omap2-nand",
160         .id             = -1,
161         .dev            = {
162                 .platform_data  = &overo_nand_data,
163         },
164         .num_resources  = 1,
165         .resource       = &overo_nand_resource,
166 };
167
168
169 static void __init overo_flash_init(void)
170 {
171         u8 cs = 0;
172         u8 nandcs = GPMC_CS_NUM + 1;
173
174         u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
175
176         /* find out the chip-select on which NAND exists */
177         while (cs < GPMC_CS_NUM) {
178                 u32 ret = 0;
179                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
180
181                 if ((ret & 0xC00) == 0x800) {
182                         printk(KERN_INFO "Found NAND on CS%d\n", cs);
183                         if (nandcs > GPMC_CS_NUM)
184                                 nandcs = cs;
185                 }
186                 cs++;
187         }
188
189         if (nandcs > GPMC_CS_NUM) {
190                 printk(KERN_INFO "NAND: Unable to find configuration "
191                                  "in GPMC\n ");
192                 return;
193         }
194
195         if (nandcs < GPMC_CS_NUM) {
196                 overo_nand_data.cs = nandcs;
197                 overo_nand_data.gpmc_cs_baseaddr = (void *)
198                         (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
199                 overo_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
200
201                 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
202                 if (platform_device_register(&overo_nand_device) < 0)
203                         printk(KERN_ERR "Unable to register NAND device\n");
204         }
205 }
206 static struct omap_uart_config overo_uart_config __initdata = {
207         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
208 };
209
210 static struct twl4030_gpio_platform_data overo_gpio_data = {
211         .gpio_base      = OMAP_MAX_GPIO_LINES,
212         .irq_base       = TWL4030_GPIO_IRQ_BASE,
213         .irq_end        = TWL4030_GPIO_IRQ_END,
214 };
215
216 static struct twl4030_platform_data overo_twldata = {
217         .irq_base       = TWL4030_IRQ_BASE,
218         .irq_end        = TWL4030_IRQ_END,
219         .gpio           = &overo_gpio_data,
220 };
221
222 static struct i2c_board_info __initdata overo_i2c_boardinfo[] = {
223         {
224                 I2C_BOARD_INFO("twl4030", 0x48),
225                 .flags = I2C_CLIENT_WAKE,
226                 .irq = INT_34XX_SYS_NIRQ,
227                 .platform_data = &overo_twldata,
228         },
229 };
230
231 static int __init overo_i2c_init(void)
232 {
233         omap_register_i2c_bus(1, 2600, overo_i2c_boardinfo,
234                         ARRAY_SIZE(overo_i2c_boardinfo));
235         /* i2c2 pins are used for gpio */
236         omap_register_i2c_bus(3, 400, NULL, 0);
237         return 0;
238 }
239
240 static void __init overo_init_irq(void)
241 {
242         omap2_init_common_hw(NULL);
243         omap_init_irq();
244         omap_gpio_init();
245 }
246
247 static struct platform_device overo_lcd_device = {
248         .name           = "overo_lcd",
249         .id             = -1,
250 };
251
252 static struct omap_lcd_config overo_lcd_config __initdata = {
253         .ctrl_name      = "internal",
254 };
255
256 static struct omap_board_config_kernel overo_config[] __initdata = {
257         { OMAP_TAG_UART,        &overo_uart_config },
258         { OMAP_TAG_LCD,         &overo_lcd_config },
259 };
260
261 static struct platform_device *overo_devices[] __initdata = {
262         &overo_lcd_device,
263 };
264
265 static struct twl4030_hsmmc_info mmc[] __initdata = {
266         {
267                 .mmc            = 1,
268                 .wires          = 4,
269                 .gpio_cd        = -EINVAL,
270                 .gpio_wp        = -EINVAL,
271         },
272         {
273                 .mmc            = 2,
274                 .wires          = 4,
275                 .gpio_cd        = -EINVAL,
276                 .gpio_wp        = -EINVAL,
277                 .transceiver    = true,
278         },
279         {}      /* Terminator */
280 };
281
282 static void __init overo_init(void)
283 {
284         overo_i2c_init();
285         platform_add_devices(overo_devices, ARRAY_SIZE(overo_devices));
286         omap_board_config = overo_config;
287         omap_board_config_size = ARRAY_SIZE(overo_config);
288         omap_serial_init();
289         twl4030_mmc_init(mmc);
290         overo_flash_init();
291         usb_musb_init();
292         overo_ads7846_init();
293
294         if ((gpio_request(OVERO_GPIO_W2W_NRESET,
295                           "OVERO_GPIO_W2W_NRESET") == 0) &&
296             (gpio_direction_output(OVERO_GPIO_W2W_NRESET, 1) == 0)) {
297                 gpio_export(OVERO_GPIO_W2W_NRESET, 0);
298                 gpio_set_value(OVERO_GPIO_W2W_NRESET, 0);
299                 udelay(10);
300                 gpio_set_value(OVERO_GPIO_W2W_NRESET, 1);
301         } else {
302                 printk(KERN_ERR "could not obtain gpio for "
303                                         "OVERO_GPIO_W2W_NRESET\n");
304         }
305
306         if ((gpio_request(OVERO_GPIO_BT_XGATE, "OVERO_GPIO_BT_XGATE") == 0) &&
307             (gpio_direction_output(OVERO_GPIO_BT_XGATE, 0) == 0))
308                 gpio_export(OVERO_GPIO_BT_XGATE, 0);
309         else
310                 printk(KERN_ERR "could not obtain gpio for OVERO_GPIO_BT_XGATE\n");
311
312         if ((gpio_request(OVERO_GPIO_BT_NRESET, "OVERO_GPIO_BT_NRESET") == 0) &&
313             (gpio_direction_output(OVERO_GPIO_BT_NRESET, 1) == 0)) {
314                 gpio_export(OVERO_GPIO_BT_NRESET, 0);
315                 gpio_set_value(OVERO_GPIO_BT_NRESET, 0);
316                 mdelay(6);
317                 gpio_set_value(OVERO_GPIO_BT_NRESET, 1);
318         } else {
319                 printk(KERN_ERR "could not obtain gpio for "
320                                         "OVERO_GPIO_BT_NRESET\n");
321         }
322
323         if ((gpio_request(OVERO_GPIO_USBH_CPEN, "OVERO_GPIO_USBH_CPEN") == 0) &&
324             (gpio_direction_output(OVERO_GPIO_USBH_CPEN, 1) == 0))
325                 gpio_export(OVERO_GPIO_USBH_CPEN, 0);
326         else
327                 printk(KERN_ERR "could not obtain gpio for "
328                                         "OVERO_GPIO_USBH_CPEN\n");
329
330         if ((gpio_request(OVERO_GPIO_USBH_NRESET,
331                           "OVERO_GPIO_USBH_NRESET") == 0) &&
332             (gpio_direction_output(OVERO_GPIO_USBH_NRESET, 1) == 0))
333                 gpio_export(OVERO_GPIO_USBH_NRESET, 0);
334         else
335                 printk(KERN_ERR "could not obtain gpio for "
336                                         "OVERO_GPIO_USBH_NRESET\n");
337 }
338
339 static void __init overo_map_io(void)
340 {
341         omap2_set_globals_343x();
342         omap2_map_common_io();
343 }
344
345 MACHINE_START(OVERO, "Gumstix Overo")
346         .phys_io        = 0x48000000,
347         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
348         .boot_params    = 0x80000100,
349         .map_io         = overo_map_io,
350         .init_irq       = overo_init_irq,
351         .init_machine   = overo_init,
352         .timer          = &omap_timer,
353 MACHINE_END