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