]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/board-overo.c
f357de9681c7308d43af80837f70c2c608a108e7
[linux-2.6-omap-h63xx.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 #include <linux/regulator/machine.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/nand.h>
47 #include <mach/usb.h>
48
49 #include "sdram-micron-mt46h32m32lf-6.h"
50 #include "twl4030-generic-scripts.h"
51 #include "mmc-twl4030.h"
52
53 #define OVERO_GPIO_BT_XGATE     15
54 #define OVERO_GPIO_W2W_NRESET   16
55 #define OVERO_GPIO_BT_NRESET    164
56 #define OVERO_GPIO_USBH_CPEN    168
57 #define OVERO_GPIO_USBH_NRESET  183
58
59 #define NAND_BLOCK_SIZE SZ_128K
60 #define GPMC_CS0_BASE  0x60
61 #define GPMC_CS_SIZE   0x30
62
63 #define OVERO_SMSC911X_CS       5
64 #define OVERO_SMSC911X_GPIO     176
65
66 #if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
67         defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
68
69 #include <mach/mcspi.h>
70 #include <linux/spi/spi.h>
71 #include <linux/spi/ads7846.h>
72
73 static struct omap2_mcspi_device_config ads7846_mcspi_config = {
74         .turbo_mode     = 0,
75         .single_channel = 1,    /* 0: slave, 1: master */
76 };
77
78 static int ads7846_get_pendown_state(void)
79 {
80         return !gpio_get_value(OVERO_GPIO_PENDOWN);
81 }
82
83 static struct ads7846_platform_data ads7846_config = {
84         .x_max                  = 0x0fff,
85         .y_max                  = 0x0fff,
86         .x_plate_ohms           = 180,
87         .pressure_max           = 255,
88         .debounce_max           = 10,
89         .debounce_tol           = 3,
90         .debounce_rep           = 1,
91         .get_pendown_state      = ads7846_get_pendown_state,
92         .keep_vref_on           = 1,
93 };
94
95 static struct spi_board_info overo_spi_board_info[] __initdata = {
96         {
97                 .modalias               = "ads7846",
98                 .bus_num                = 1,
99                 .chip_select            = 0,
100                 .max_speed_hz           = 1500000,
101                 .controller_data        = &ads7846_mcspi_config,
102                 .irq                    = OMAP_GPIO_IRQ(OVERO_GPIO_PENDOWN),
103                 .platform_data          = &ads7846_config,
104         }
105 };
106
107 static void __init overo_ads7846_init(void)
108 {
109         if ((gpio_request(OVERO_GPIO_PENDOWN, "ADS7846_PENDOWN") == 0) &&
110             (gpio_direction_input(OVERO_GPIO_PENDOWN) == 0)) {
111                 gpio_export(OVERO_GPIO_PENDOWN, 0);
112         } else {
113                 printk(KERN_ERR "could not obtain gpio for ADS7846_PENDOWN\n");
114                 return;
115         }
116
117         spi_register_board_info(overo_spi_board_info,
118                         ARRAY_SIZE(overo_spi_board_info));
119 }
120
121 #else
122 static inline void __init overo_ads7846_init(void) { return; }
123 #endif
124
125 #if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
126
127 #include <linux/smsc911x.h>
128
129 static struct resource overo_smsc911x_resources[] = {
130         {
131                 .name   = "smsc911x-memory",
132                 .flags  = IORESOURCE_MEM,
133         },
134         {
135                 .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
136         },
137 };
138
139 static struct smsc911x_platform_config overo_smsc911x_config = {
140         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
141         .irq_type       = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
142         .flags          = SMSC911X_USE_32BIT ,
143         .phy_interface  = PHY_INTERFACE_MODE_MII,
144 };
145
146 static struct platform_device overo_smsc911x_device = {
147         .name           = "smsc911x",
148         .id             = -1,
149         .num_resources  = ARRAY_SIZE(overo_smsc911x_resources),
150         .resource       = &overo_smsc911x_resources,
151         .dev            = {
152                 .platform_data = &overo_smsc911x_config,
153         },
154 };
155
156 static inline void __init overo_init_smsc911x(void)
157 {
158         unsigned long cs_mem_base;
159
160         if (gpmc_cs_request(OVERO_SMSC911X_CS, SZ_16M, &cs_mem_base) < 0) {
161                 printk(KERN_ERR "Failed request for GPMC mem for smsc911x\n");
162                 return;
163         }
164
165         overo_smsc911x_resources[0].start = cs_mem_base + 0x0;
166         overo_smsc911x_resources[0].end   = cs_mem_base + 0xff;
167
168         if ((gpio_request(OVERO_SMSC911X_GPIO, "SMSC911X IRQ") == 0) &&
169             (gpio_direction_input(OVERO_SMSC911X_GPIO) == 0)) {
170                 gpio_export(OVERO_SMSC911X_GPIO, 0);
171         } else {
172                 printk(KERN_ERR "could not obtain gpio for SMSC911X IRQ\n");
173                 return;
174         }
175
176         overo_smsc911x_resources[1].start = OMAP_GPIO_IRQ(OVERO_SMSC911X_GPIO);
177         overo_smsc911x_resources[1].end   = 0;
178
179         platform_device_register(&overo_smsc911x_device);
180 }
181
182 #else
183 static inline void __init overo_init_smsc911x(void) { return; }
184 #endif
185
186
187
188 static struct mtd_partition overo_nand_partitions[] = {
189         {
190                 .name           = "xloader",
191                 .offset         = 0,                    /* Offset = 0x00000 */
192                 .size           = 4 * NAND_BLOCK_SIZE,
193                 .mask_flags     = MTD_WRITEABLE
194         },
195         {
196                 .name           = "uboot",
197                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x80000 */
198                 .size           = 14 * NAND_BLOCK_SIZE,
199         },
200         {
201                 .name           = "uboot environment",
202                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x240000 */
203                 .size           = 2 * NAND_BLOCK_SIZE,
204         },
205         {
206                 .name           = "linux",
207                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x280000 */
208                 .size           = 32 * NAND_BLOCK_SIZE,
209         },
210         {
211                 .name           = "rootfs",
212                 .offset         = MTDPART_OFS_APPEND,   /* Offset = 0x680000 */
213                 .size           = MTDPART_SIZ_FULL,
214         },
215 };
216
217 static struct omap_nand_platform_data overo_nand_data = {
218         .parts = overo_nand_partitions,
219         .nr_parts = ARRAY_SIZE(overo_nand_partitions),
220         .dma_channel = -1,      /* disable DMA in OMAP NAND driver */
221 };
222
223 static struct resource overo_nand_resource = {
224         .flags          = IORESOURCE_MEM,
225 };
226
227 static struct platform_device overo_nand_device = {
228         .name           = "omap2-nand",
229         .id             = -1,
230         .dev            = {
231                 .platform_data  = &overo_nand_data,
232         },
233         .num_resources  = 1,
234         .resource       = &overo_nand_resource,
235 };
236
237
238 static void __init overo_flash_init(void)
239 {
240         u8 cs = 0;
241         u8 nandcs = GPMC_CS_NUM + 1;
242
243         u32 gpmc_base_add = OMAP34XX_GPMC_VIRT;
244
245         /* find out the chip-select on which NAND exists */
246         while (cs < GPMC_CS_NUM) {
247                 u32 ret = 0;
248                 ret = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1);
249
250                 if ((ret & 0xC00) == 0x800) {
251                         printk(KERN_INFO "Found NAND on CS%d\n", cs);
252                         if (nandcs > GPMC_CS_NUM)
253                                 nandcs = cs;
254                 }
255                 cs++;
256         }
257
258         if (nandcs > GPMC_CS_NUM) {
259                 printk(KERN_INFO "NAND: Unable to find configuration "
260                                  "in GPMC\n ");
261                 return;
262         }
263
264         if (nandcs < GPMC_CS_NUM) {
265                 overo_nand_data.cs = nandcs;
266                 overo_nand_data.gpmc_cs_baseaddr = (void *)
267                         (gpmc_base_add + GPMC_CS0_BASE + nandcs * GPMC_CS_SIZE);
268                 overo_nand_data.gpmc_baseaddr = (void *) (gpmc_base_add);
269
270                 printk(KERN_INFO "Registering NAND on CS%d\n", nandcs);
271                 if (platform_device_register(&overo_nand_device) < 0)
272                         printk(KERN_ERR "Unable to register NAND device\n");
273         }
274 }
275 static struct omap_uart_config overo_uart_config __initdata = {
276         .enabled_uarts  = ((1 << 0) | (1 << 1) | (1 << 2)),
277 };
278
279 static struct twl4030_hsmmc_info mmc[] = {
280         {
281                 .mmc            = 1,
282                 .wires          = 4,
283                 .gpio_cd        = -EINVAL,
284                 .gpio_wp        = -EINVAL,
285         },
286         {
287                 .mmc            = 2,
288                 .wires          = 4,
289                 .gpio_cd        = -EINVAL,
290                 .gpio_wp        = -EINVAL,
291                 .transceiver    = true,
292                 .ocr_mask       = 0x00100000,   /* 3.3V */
293         },
294         {}      /* Terminator */
295 };
296
297 static struct regulator_consumer_supply overo_vmmc1_supply = {
298         .supply                 = "vmmc",
299 };
300
301 static int overo_twl_gpio_setup(struct device *dev,
302                 unsigned gpio, unsigned ngpio)
303 {
304         twl4030_mmc_init(mmc);
305
306         overo_vmmc1_supply.dev = mmc[0].dev;
307
308         return 0;
309 }
310
311 static struct twl4030_gpio_platform_data overo_gpio_data = {
312         .gpio_base      = OMAP_MAX_GPIO_LINES,
313         .irq_base       = TWL4030_GPIO_IRQ_BASE,
314         .irq_end        = TWL4030_GPIO_IRQ_END,
315         .setup          = overo_twl_gpio_setup,
316 };
317
318 static struct twl4030_usb_data overo_usb_data = {
319         .usb_mode       = T2_USB_MODE_ULPI,
320 };
321
322 static struct regulator_init_data overo_vmmc1 = {
323         .constraints = {
324                 .min_uV                 = 1850000,
325                 .max_uV                 = 3150000,
326                 .valid_modes_mask       = REGULATOR_MODE_NORMAL
327                                         | REGULATOR_MODE_STANDBY,
328                 .valid_ops_mask         = REGULATOR_CHANGE_VOLTAGE
329                                         | REGULATOR_CHANGE_MODE
330                                         | REGULATOR_CHANGE_STATUS,
331         },
332         .num_consumer_supplies  = 1,
333         .consumer_supplies      = &overo_vmmc1_supply,
334 };
335
336 /* mmc2 (WLAN) and Bluetooth don't use twl4030 regulators */
337
338 static struct twl4030_platform_data overo_twldata = {
339         .irq_base       = TWL4030_IRQ_BASE,
340         .irq_end        = TWL4030_IRQ_END,
341         .gpio           = &overo_gpio_data,
342         .usb            = &overo_usb_data,
343         .power          = GENERIC3430_T2SCRIPTS_DATA,
344         .vmmc1          = &overo_vmmc1,
345 };
346
347 static struct i2c_board_info __initdata overo_i2c_boardinfo[] = {
348         {
349                 I2C_BOARD_INFO("tps65950", 0x48),
350                 .flags = I2C_CLIENT_WAKE,
351                 .irq = INT_34XX_SYS_NIRQ,
352                 .platform_data = &overo_twldata,
353         },
354 };
355
356 static int __init overo_i2c_init(void)
357 {
358         omap_register_i2c_bus(1, 2600, overo_i2c_boardinfo,
359                         ARRAY_SIZE(overo_i2c_boardinfo));
360         /* i2c2 pins are used for gpio */
361         omap_register_i2c_bus(3, 400, NULL, 0);
362         return 0;
363 }
364
365 static void __init overo_init_irq(void)
366 {
367         omap2_init_common_hw(mt46h32m32lf6_sdrc_params);
368         omap_init_irq();
369         omap_gpio_init();
370 }
371
372 static struct platform_device overo_lcd_device = {
373         .name           = "overo_lcd",
374         .id             = -1,
375 };
376
377 static struct omap_lcd_config overo_lcd_config __initdata = {
378         .ctrl_name      = "internal",
379 };
380
381 static struct omap_board_config_kernel overo_config[] __initdata = {
382         { OMAP_TAG_UART,        &overo_uart_config },
383         { OMAP_TAG_LCD,         &overo_lcd_config },
384 };
385
386 static struct platform_device *overo_devices[] __initdata = {
387         &overo_lcd_device,
388 };
389
390 static void __init overo_init(void)
391 {
392         overo_i2c_init();
393         platform_add_devices(overo_devices, ARRAY_SIZE(overo_devices));
394         omap_board_config = overo_config;
395         omap_board_config_size = ARRAY_SIZE(overo_config);
396         omap_serial_init();
397         usb_musb_init();
398         usb_ehci_init();
399         overo_flash_init();
400         overo_init_smsc911x();
401         overo_ads7846_init();
402         overo_init_smsc911x();
403
404         if ((gpio_request(OVERO_GPIO_W2W_NRESET,
405                           "OVERO_GPIO_W2W_NRESET") == 0) &&
406             (gpio_direction_output(OVERO_GPIO_W2W_NRESET, 1) == 0)) {
407                 gpio_export(OVERO_GPIO_W2W_NRESET, 0);
408                 gpio_set_value(OVERO_GPIO_W2W_NRESET, 0);
409                 udelay(10);
410                 gpio_set_value(OVERO_GPIO_W2W_NRESET, 1);
411         } else {
412                 printk(KERN_ERR "could not obtain gpio for "
413                                         "OVERO_GPIO_W2W_NRESET\n");
414         }
415
416         if ((gpio_request(OVERO_GPIO_BT_XGATE, "OVERO_GPIO_BT_XGATE") == 0) &&
417             (gpio_direction_output(OVERO_GPIO_BT_XGATE, 0) == 0))
418                 gpio_export(OVERO_GPIO_BT_XGATE, 0);
419         else
420                 printk(KERN_ERR "could not obtain gpio for OVERO_GPIO_BT_XGATE\n");
421
422         if ((gpio_request(OVERO_GPIO_BT_NRESET, "OVERO_GPIO_BT_NRESET") == 0) &&
423             (gpio_direction_output(OVERO_GPIO_BT_NRESET, 1) == 0)) {
424                 gpio_export(OVERO_GPIO_BT_NRESET, 0);
425                 gpio_set_value(OVERO_GPIO_BT_NRESET, 0);
426                 mdelay(6);
427                 gpio_set_value(OVERO_GPIO_BT_NRESET, 1);
428         } else {
429                 printk(KERN_ERR "could not obtain gpio for "
430                                         "OVERO_GPIO_BT_NRESET\n");
431         }
432
433         if ((gpio_request(OVERO_GPIO_USBH_CPEN, "OVERO_GPIO_USBH_CPEN") == 0) &&
434             (gpio_direction_output(OVERO_GPIO_USBH_CPEN, 1) == 0))
435                 gpio_export(OVERO_GPIO_USBH_CPEN, 0);
436         else
437                 printk(KERN_ERR "could not obtain gpio for "
438                                         "OVERO_GPIO_USBH_CPEN\n");
439
440         if ((gpio_request(OVERO_GPIO_USBH_NRESET,
441                           "OVERO_GPIO_USBH_NRESET") == 0) &&
442             (gpio_direction_output(OVERO_GPIO_USBH_NRESET, 1) == 0))
443                 gpio_export(OVERO_GPIO_USBH_NRESET, 0);
444         else
445                 printk(KERN_ERR "could not obtain gpio for "
446                                         "OVERO_GPIO_USBH_NRESET\n");
447 }
448
449 static void __init overo_map_io(void)
450 {
451         omap2_set_globals_343x();
452         omap2_map_common_io();
453 }
454
455 MACHINE_START(OVERO, "Gumstix Overo")
456         .phys_io        = 0x48000000,
457         .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
458         .boot_params    = 0x80000100,
459         .map_io         = overo_map_io,
460         .init_irq       = overo_init_irq,
461         .init_machine   = overo_init,
462         .timer          = &omap_timer,
463 MACHINE_END