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