Merge branch 'merge' into next
[linux-2.6] / arch / arm / mach-omap1 / board-palmz71.c
1 /*
2  * linux/arch/arm/mach-omap1/board-palmz71.c
3  *
4  * Modified from board-generic.c
5  *
6  * Support for the Palm Zire71 PDA.
7  *
8  * Original version : Laurent Gonzalez
9  *
10  * Modified for zire71 : Marek Vasut
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License version 2 as
14  * published by the Free Software Foundation.
15  */
16
17 #include <linux/delay.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/notifier.h>
22 #include <linux/clk.h>
23 #include <linux/irq.h>
24 #include <linux/input.h>
25 #include <linux/interrupt.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/partitions.h>
28
29 #include <mach/hardware.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33 #include <asm/mach/flash.h>
34
35 #include <mach/mcbsp.h>
36 #include <mach/gpio.h>
37 #include <mach/mux.h>
38 #include <mach/usb.h>
39 #include <mach/dma.h>
40 #include <mach/tc.h>
41 #include <mach/board.h>
42 #include <mach/irda.h>
43 #include <mach/keypad.h>
44 #include <mach/common.h>
45 #include <mach/omap-alsa.h>
46
47 #include <linux/spi/spi.h>
48 #include <linux/spi/ads7846.h>
49
50 static void __init
51 omap_palmz71_init_irq(void)
52 {
53         omap1_init_common_hw();
54         omap_init_irq();
55         omap_gpio_init();
56 }
57
58 static int palmz71_keymap[] = {
59         KEY(0, 0, KEY_F1),
60         KEY(0, 1, KEY_F2),
61         KEY(0, 2, KEY_F3),
62         KEY(0, 3, KEY_F4),
63         KEY(0, 4, KEY_POWER),
64         KEY(1, 0, KEY_LEFT),
65         KEY(1, 1, KEY_DOWN),
66         KEY(1, 2, KEY_UP),
67         KEY(1, 3, KEY_RIGHT),
68         KEY(1, 4, KEY_ENTER),
69         KEY(2, 0, KEY_CAMERA),
70         0,
71 };
72
73 static struct omap_kp_platform_data palmz71_kp_data = {
74         .rows   = 8,
75         .cols   = 8,
76         .keymap = palmz71_keymap,
77         .rep    = 1,
78         .delay  = 80,
79 };
80
81 static struct resource palmz71_kp_resources[] = {
82         [0] = {
83                 .start  = INT_KEYBOARD,
84                 .end    = INT_KEYBOARD,
85                 .flags  = IORESOURCE_IRQ,
86         },
87 };
88
89 static struct platform_device palmz71_kp_device = {
90         .name   = "omap-keypad",
91         .id     = -1,
92         .dev    = {
93                 .platform_data = &palmz71_kp_data,
94         },
95         .num_resources  = ARRAY_SIZE(palmz71_kp_resources),
96         .resource       = palmz71_kp_resources,
97 };
98
99 static struct mtd_partition palmz71_rom_partitions[] = {
100         /* PalmOS "Small ROM", contains the bootloader and the debugger */
101         {
102                 .name           = "smallrom",
103                 .offset         = 0,
104                 .size           = 0xa000,
105                 .mask_flags     = MTD_WRITEABLE,
106         },
107         /* PalmOS "Big ROM", a filesystem with all the OS code and data */
108         {
109                 .name   = "bigrom",
110                 .offset = SZ_128K,
111                 /*
112                  * 0x5f0000 bytes big in the multi-language ("EFIGS") version,
113                  * 0x7b0000 bytes in the English-only ("enUS") version.
114                  */
115                 .size           = 0x7b0000,
116                 .mask_flags     = MTD_WRITEABLE,
117         },
118 };
119
120 static struct flash_platform_data palmz71_rom_data = {
121         .map_name       = "map_rom",
122         .name           = "onboardrom",
123         .width          = 2,
124         .parts          = palmz71_rom_partitions,
125         .nr_parts       = ARRAY_SIZE(palmz71_rom_partitions),
126 };
127
128 static struct resource palmz71_rom_resource = {
129         .start  = OMAP_CS0_PHYS,
130         .end    = OMAP_CS0_PHYS + SZ_8M - 1,
131         .flags  = IORESOURCE_MEM,
132 };
133
134 static struct platform_device palmz71_rom_device = {
135         .name   = "omapflash",
136         .id     = -1,
137         .dev = {
138                 .platform_data = &palmz71_rom_data,
139         },
140         .num_resources  = 1,
141         .resource       = &palmz71_rom_resource,
142 };
143
144 static struct platform_device palmz71_lcd_device = {
145         .name   = "lcd_palmz71",
146         .id     = -1,
147 };
148
149 static struct omap_irda_config palmz71_irda_config = {
150         .transceiver_cap        = IR_SIRMODE,
151         .rx_channel             = OMAP_DMA_UART3_RX,
152         .tx_channel             = OMAP_DMA_UART3_TX,
153         .dest_start             = UART3_THR,
154         .src_start              = UART3_RHR,
155         .tx_trigger             = 0,
156         .rx_trigger             = 0,
157 };
158
159 static struct resource palmz71_irda_resources[] = {
160         [0] = {
161                 .start  = INT_UART3,
162                 .end    = INT_UART3,
163                 .flags  = IORESOURCE_IRQ,
164         },
165 };
166
167 static struct platform_device palmz71_irda_device = {
168         .name   = "omapirda",
169         .id     = -1,
170         .dev = {
171                 .platform_data = &palmz71_irda_config,
172         },
173         .num_resources  = ARRAY_SIZE(palmz71_irda_resources),
174         .resource       = palmz71_irda_resources,
175 };
176
177 static struct platform_device palmz71_spi_device = {
178         .name   = "spi_palmz71",
179         .id     = -1,
180 };
181
182 #define DEFAULT_BITPERSAMPLE 16
183
184 static struct omap_mcbsp_reg_cfg mcbsp_regs = {
185         .spcr2  = FREE | FRST | GRST | XRST | XINTM(3),
186         .spcr1  = RINTM(3) | RRST,
187         .rcr2   = RPHASE | RFRLEN2(OMAP_MCBSP_WORD_8) |
188                         RWDLEN2(OMAP_MCBSP_WORD_16) | RDATDLY(0),
189         .rcr1   = RFRLEN1(OMAP_MCBSP_WORD_8) | RWDLEN1(OMAP_MCBSP_WORD_16),
190         .xcr2   = XPHASE | XFRLEN2(OMAP_MCBSP_WORD_8) |
191                         XWDLEN2(OMAP_MCBSP_WORD_16) | XDATDLY(0) | XFIG,
192         .xcr1   = XFRLEN1(OMAP_MCBSP_WORD_8) | XWDLEN1(OMAP_MCBSP_WORD_16),
193         .srgr1  = FWID(DEFAULT_BITPERSAMPLE - 1),
194         .srgr2  = GSYNC | CLKSP | FSGM | FPER(DEFAULT_BITPERSAMPLE * 2 - 1),
195         .pcr0   = CLKXP | CLKRP,        /* mcbsp: slave */
196 };
197
198 static struct omap_alsa_codec_config alsa_config = {
199         .name                   = "PalmZ71 AIC23",
200         .mcbsp_regs_alsa        = &mcbsp_regs,
201         .codec_configure_dev    = NULL, /* aic23_configure */
202         .codec_set_samplerate   = NULL, /* aic23_set_samplerate */
203         .codec_clock_setup      = NULL, /* aic23_clock_setup */
204         .codec_clock_on         = NULL, /* aic23_clock_on */
205         .codec_clock_off        = NULL, /* aic23_clock_off */
206         .get_default_samplerate = NULL, /* aic23_get_default_samplerate */
207 };
208
209 static struct platform_device palmz71_mcbsp1_device = {
210         .name   = "omap_alsa_mcbsp",
211         .id     = 1,
212         .dev = {
213                 .platform_data = &alsa_config,
214         },
215 };
216
217 static struct omap_backlight_config palmz71_backlight_config = {
218         .default_intensity      = 0xa0,
219 };
220
221 static struct platform_device palmz71_backlight_device = {
222         .name   = "omap-bl",
223         .id     = -1,
224         .dev    = {
225                 .platform_data = &palmz71_backlight_config,
226         },
227 };
228
229 static struct platform_device *devices[] __initdata = {
230         &palmz71_rom_device,
231         &palmz71_kp_device,
232         &palmz71_mcbsp1_device,
233         &palmz71_lcd_device,
234         &palmz71_irda_device,
235         &palmz71_spi_device,
236         &palmz71_backlight_device,
237 };
238
239 static int
240 palmz71_get_pendown_state(void)
241 {
242         return !omap_get_gpio_datain(PALMZ71_PENIRQ_GPIO);
243 }
244
245 static const struct ads7846_platform_data palmz71_ts_info = {
246         .model                  = 7846,
247         .vref_delay_usecs       = 100,  /* internal, no capacitor */
248         .x_plate_ohms           = 419,
249         .y_plate_ohms           = 486,
250         .get_pendown_state      = palmz71_get_pendown_state,
251 };
252
253 static struct spi_board_info __initdata palmz71_boardinfo[] = { {
254         /* MicroWire (bus 2) CS0 has an ads7846e */
255         .modalias       = "ads7846",
256         .platform_data  = &palmz71_ts_info,
257         .irq            = OMAP_GPIO_IRQ(PALMZ71_PENIRQ_GPIO),
258         .max_speed_hz   = 120000        /* max sample rate at 3V */
259                                 * 26    /* command + data + overhead */,
260         .bus_num        = 2,
261         .chip_select    = 0,
262 } };
263
264 static struct omap_usb_config palmz71_usb_config __initdata = {
265         .register_dev   = 1,    /* Mini-B only receptacle */
266         .hmc_mode       = 0,
267         .pins[0]        = 2,
268 };
269
270 static struct omap_mmc_config palmz71_mmc_config __initdata = {
271         .mmc[0] = {
272                 .enabled        = 1,
273                 .wire4          = 0,
274                 .wp_pin         = PALMZ71_MMC_WP_GPIO,
275                 .power_pin      = -1,
276                 .switch_pin     = PALMZ71_MMC_IN_GPIO,
277         },
278 };
279
280 static struct omap_lcd_config palmz71_lcd_config __initdata = {
281         .ctrl_name = "internal",
282 };
283
284 static struct omap_uart_config palmz71_uart_config __initdata = {
285         .enabled_uarts = (1 << 0) | (1 << 1) | (0 << 2),
286 };
287
288 static struct omap_board_config_kernel palmz71_config[] __initdata = {
289         {OMAP_TAG_USB,  &palmz71_usb_config},
290         {OMAP_TAG_MMC,  &palmz71_mmc_config},
291         {OMAP_TAG_LCD,  &palmz71_lcd_config},
292         {OMAP_TAG_UART, &palmz71_uart_config},
293 };
294
295 static irqreturn_t
296 palmz71_powercable(int irq, void *dev_id)
297 {
298         if (omap_get_gpio_datain(PALMZ71_USBDETECT_GPIO)) {
299                 printk(KERN_INFO "PM: Power cable connected\n");
300                 set_irq_type(OMAP_GPIO_IRQ(PALMZ71_USBDETECT_GPIO),
301                                 IRQ_TYPE_EDGE_FALLING);
302         } else {
303                 printk(KERN_INFO "PM: Power cable disconnected\n");
304                 set_irq_type(OMAP_GPIO_IRQ(PALMZ71_USBDETECT_GPIO),
305                                 IRQ_TYPE_EDGE_RISING);
306         }
307         return IRQ_HANDLED;
308 }
309
310 static void __init
311 omap_mpu_wdt_mode(int mode)
312 {
313         if (mode)
314                 omap_writew(0x8000, OMAP_WDT_TIMER_MODE);
315         else {
316                 omap_writew(0x00f5, OMAP_WDT_TIMER_MODE);
317                 omap_writew(0x00a0, OMAP_WDT_TIMER_MODE);
318         }
319 }
320
321 static void __init
322 palmz71_gpio_setup(int early)
323 {
324         if (early) {
325                 /* Only set GPIO1 so we have a working serial */
326                 omap_set_gpio_dataout(1, 1);
327                 omap_set_gpio_direction(1, 0);
328         } else {
329                 /* Set MMC/SD host WP pin as input */
330                 if (omap_request_gpio(PALMZ71_MMC_WP_GPIO)) {
331                         printk(KERN_ERR "Could not reserve WP GPIO!\n");
332                         return;
333                 }
334                 omap_set_gpio_direction(PALMZ71_MMC_WP_GPIO, 1);
335
336                 /* Monitor the Power-cable-connected signal */
337                 if (omap_request_gpio(PALMZ71_USBDETECT_GPIO)) {
338                         printk(KERN_ERR
339                                 "Could not reserve cable signal GPIO!\n");
340                         return;
341                 }
342                 omap_set_gpio_direction(PALMZ71_USBDETECT_GPIO, 1);
343                 if (request_irq(OMAP_GPIO_IRQ(PALMZ71_USBDETECT_GPIO),
344                                 palmz71_powercable, IRQF_SAMPLE_RANDOM,
345                                 "palmz71-cable", 0))
346                         printk(KERN_ERR
347                                         "IRQ request for power cable failed!\n");
348                 palmz71_powercable(OMAP_GPIO_IRQ(PALMZ71_USBDETECT_GPIO), 0);
349         }
350 }
351
352 static void __init
353 omap_palmz71_init(void)
354 {
355         palmz71_gpio_setup(1);
356         omap_mpu_wdt_mode(0);
357
358         omap_board_config = palmz71_config;
359         omap_board_config_size = ARRAY_SIZE(palmz71_config);
360
361         platform_add_devices(devices, ARRAY_SIZE(devices));
362
363         spi_register_board_info(palmz71_boardinfo,
364                                 ARRAY_SIZE(palmz71_boardinfo));
365         omap_serial_init();
366         omap_register_i2c_bus(1, 100, NULL, 0);
367         palmz71_gpio_setup(0);
368 }
369
370 static void __init
371 omap_palmz71_map_io(void)
372 {
373         omap1_map_common_io();
374 }
375
376 MACHINE_START(OMAP_PALMZ71, "OMAP310 based Palm Zire71")
377         .phys_io = 0xfff00000,
378         .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
379         .boot_params = 0x10000100,.map_io = omap_palmz71_map_io,
380         .init_irq = omap_palmz71_init_irq,
381         .init_machine = omap_palmz71_init,
382         .timer = &omap_timer,
383 MACHINE_END