Merge git://git.linux-nfs.org/projects/trondmy/nfs-2.6
[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 !gpio_get_value(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_lcd_config palmz71_lcd_config __initdata = {
271         .ctrl_name = "internal",
272 };
273
274 static struct omap_uart_config palmz71_uart_config __initdata = {
275         .enabled_uarts = (1 << 0) | (1 << 1) | (0 << 2),
276 };
277
278 static struct omap_board_config_kernel palmz71_config[] __initdata = {
279         {OMAP_TAG_USB,  &palmz71_usb_config},
280         {OMAP_TAG_LCD,  &palmz71_lcd_config},
281         {OMAP_TAG_UART, &palmz71_uart_config},
282 };
283
284 static irqreturn_t
285 palmz71_powercable(int irq, void *dev_id)
286 {
287         if (gpio_get_value(PALMZ71_USBDETECT_GPIO)) {
288                 printk(KERN_INFO "PM: Power cable connected\n");
289                 set_irq_type(gpio_to_irq(PALMZ71_USBDETECT_GPIO),
290                                 IRQ_TYPE_EDGE_FALLING);
291         } else {
292                 printk(KERN_INFO "PM: Power cable disconnected\n");
293                 set_irq_type(gpio_to_irq(PALMZ71_USBDETECT_GPIO),
294                                 IRQ_TYPE_EDGE_RISING);
295         }
296         return IRQ_HANDLED;
297 }
298
299 static void __init
300 omap_mpu_wdt_mode(int mode)
301 {
302         if (mode)
303                 omap_writew(0x8000, OMAP_WDT_TIMER_MODE);
304         else {
305                 omap_writew(0x00f5, OMAP_WDT_TIMER_MODE);
306                 omap_writew(0x00a0, OMAP_WDT_TIMER_MODE);
307         }
308 }
309
310 static void __init
311 palmz71_gpio_setup(int early)
312 {
313         if (early) {
314                 /* Only set GPIO1 so we have a working serial */
315                 gpio_direction_output(1, 1);
316         } else {
317                 /* Set MMC/SD host WP pin as input */
318                 if (gpio_request(PALMZ71_MMC_WP_GPIO, "MMC WP") < 0) {
319                         printk(KERN_ERR "Could not reserve WP GPIO!\n");
320                         return;
321                 }
322                 gpio_direction_input(PALMZ71_MMC_WP_GPIO);
323
324                 /* Monitor the Power-cable-connected signal */
325                 if (gpio_request(PALMZ71_USBDETECT_GPIO, "USB detect") < 0) {
326                         printk(KERN_ERR
327                                 "Could not reserve cable signal GPIO!\n");
328                         return;
329                 }
330                 gpio_direction_input(PALMZ71_USBDETECT_GPIO);
331                 if (request_irq(gpio_to_irq(PALMZ71_USBDETECT_GPIO),
332                                 palmz71_powercable, IRQF_SAMPLE_RANDOM,
333                                 "palmz71-cable", 0))
334                         printk(KERN_ERR
335                                         "IRQ request for power cable failed!\n");
336                 palmz71_powercable(gpio_to_irq(PALMZ71_USBDETECT_GPIO), 0);
337         }
338 }
339
340 static void __init
341 omap_palmz71_init(void)
342 {
343         palmz71_gpio_setup(1);
344         omap_mpu_wdt_mode(0);
345
346         omap_board_config = palmz71_config;
347         omap_board_config_size = ARRAY_SIZE(palmz71_config);
348
349         platform_add_devices(devices, ARRAY_SIZE(devices));
350
351         spi_register_board_info(palmz71_boardinfo,
352                                 ARRAY_SIZE(palmz71_boardinfo));
353         omap_serial_init();
354         omap_register_i2c_bus(1, 100, NULL, 0);
355         palmz71_gpio_setup(0);
356 }
357
358 static void __init
359 omap_palmz71_map_io(void)
360 {
361         omap1_map_common_io();
362 }
363
364 MACHINE_START(OMAP_PALMZ71, "OMAP310 based Palm Zire71")
365         .phys_io = 0xfff00000,
366         .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
367         .boot_params = 0x10000100,.map_io = omap_palmz71_map_io,
368         .init_irq = omap_palmz71_init_irq,
369         .init_machine = omap_palmz71_init,
370         .timer = &omap_timer,
371 MACHINE_END