Merge branch 'virtio' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux...
[pandora-kernel.git] / arch / arm / mach-pxa / palmt5.c
1 /*
2  * Hardware definitions for Palm Tungsten|T5
3  *
4  * Author:      Marek Vasut <marek.vasut@gmail.com>
5  *
6  * Based on work of:
7  *              Ales Snuparek <snuparek@atlas.cz>
8  *              Justin Kendrick <twilightsentry@gmail.com>
9  *              RichardT5 <richard_t5@users.sourceforge.net>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14  *
15  * (find more info at www.hackndev.com)
16  *
17  */
18
19 #include <linux/platform_device.h>
20 #include <linux/delay.h>
21 #include <linux/irq.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/input.h>
24 #include <linux/pda_power.h>
25 #include <linux/pwm_backlight.h>
26 #include <linux/gpio.h>
27 #include <linux/wm97xx_batt.h>
28 #include <linux/power_supply.h>
29 #include <linux/usb/gpio_vbus.h>
30
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34
35 #include <mach/pxa27x.h>
36 #include <mach/audio.h>
37 #include <mach/palmt5.h>
38 #include <mach/mmc.h>
39 #include <mach/pxafb.h>
40 #include <mach/irda.h>
41 #include <mach/pxa27x_keypad.h>
42 #include <mach/udc.h>
43 #include <mach/palmasoc.h>
44
45 #include "generic.h"
46 #include "devices.h"
47
48 /******************************************************************************
49  * Pin configuration
50  ******************************************************************************/
51 static unsigned long palmt5_pin_config[] __initdata = {
52         /* MMC */
53         GPIO32_MMC_CLK,
54         GPIO92_MMC_DAT_0,
55         GPIO109_MMC_DAT_1,
56         GPIO110_MMC_DAT_2,
57         GPIO111_MMC_DAT_3,
58         GPIO112_MMC_CMD,
59         GPIO14_GPIO,    /* SD detect */
60         GPIO114_GPIO,   /* SD power */
61         GPIO115_GPIO,   /* SD r/o switch */
62
63         /* AC97 */
64         GPIO28_AC97_BITCLK,
65         GPIO29_AC97_SDATA_IN_0,
66         GPIO30_AC97_SDATA_OUT,
67         GPIO31_AC97_SYNC,
68         GPIO89_AC97_SYSCLK,
69         GPIO95_AC97_nRESET,
70
71         /* IrDA */
72         GPIO40_GPIO,    /* ir disable */
73         GPIO46_FICP_RXD,
74         GPIO47_FICP_TXD,
75
76         /* USB */
77         GPIO15_GPIO,    /* usb detect */
78         GPIO93_GPIO,    /* usb power */
79
80         /* MATRIX KEYPAD */
81         GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
82         GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
83         GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
84         GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
85         GPIO103_KP_MKOUT_0,
86         GPIO104_KP_MKOUT_1,
87         GPIO105_KP_MKOUT_2,
88
89         /* LCD */
90         GPIOxx_LCD_TFT_16BPP,
91
92         /* PWM */
93         GPIO16_PWM0_OUT,
94
95         /* FFUART */
96         GPIO34_FFUART_RXD,
97         GPIO39_FFUART_TXD,
98
99         /* MISC */
100         GPIO10_GPIO,    /* hotsync button */
101         GPIO90_GPIO,    /* power detect */
102         GPIO107_GPIO,   /* earphone detect */
103 };
104
105 /******************************************************************************
106  * SD/MMC card controller
107  ******************************************************************************/
108 static struct pxamci_platform_data palmt5_mci_platform_data = {
109         .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
110         .gpio_card_detect       = GPIO_NR_PALMT5_SD_DETECT_N,
111         .gpio_card_ro           = GPIO_NR_PALMT5_SD_READONLY,
112         .gpio_power             = GPIO_NR_PALMT5_SD_POWER,
113         .detect_delay_ms        = 200,
114 };
115
116 /******************************************************************************
117  * GPIO keyboard
118  ******************************************************************************/
119 static unsigned int palmt5_matrix_keys[] = {
120         KEY(0, 0, KEY_POWER),
121         KEY(0, 1, KEY_F1),
122         KEY(0, 2, KEY_ENTER),
123
124         KEY(1, 0, KEY_F2),
125         KEY(1, 1, KEY_F3),
126         KEY(1, 2, KEY_F4),
127
128         KEY(2, 0, KEY_UP),
129         KEY(2, 2, KEY_DOWN),
130
131         KEY(3, 0, KEY_RIGHT),
132         KEY(3, 2, KEY_LEFT),
133 };
134
135 static struct pxa27x_keypad_platform_data palmt5_keypad_platform_data = {
136         .matrix_key_rows        = 4,
137         .matrix_key_cols        = 3,
138         .matrix_key_map         = palmt5_matrix_keys,
139         .matrix_key_map_size    = ARRAY_SIZE(palmt5_matrix_keys),
140
141         .debounce_interval      = 30,
142 };
143
144 /******************************************************************************
145  * GPIO keys
146  ******************************************************************************/
147 static struct gpio_keys_button palmt5_pxa_buttons[] = {
148         {KEY_F8, GPIO_NR_PALMT5_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
149 };
150
151 static struct gpio_keys_platform_data palmt5_pxa_keys_data = {
152         .buttons        = palmt5_pxa_buttons,
153         .nbuttons       = ARRAY_SIZE(palmt5_pxa_buttons),
154 };
155
156 static struct platform_device palmt5_pxa_keys = {
157         .name   = "gpio-keys",
158         .id     = -1,
159         .dev    = {
160                 .platform_data = &palmt5_pxa_keys_data,
161         },
162 };
163
164 /******************************************************************************
165  * Backlight
166  ******************************************************************************/
167 static int palmt5_backlight_init(struct device *dev)
168 {
169         int ret;
170
171         ret = gpio_request(GPIO_NR_PALMT5_BL_POWER, "BL POWER");
172         if (ret)
173                 goto err;
174         ret = gpio_direction_output(GPIO_NR_PALMT5_BL_POWER, 0);
175         if (ret)
176                 goto err2;
177         ret = gpio_request(GPIO_NR_PALMT5_LCD_POWER, "LCD POWER");
178         if (ret)
179                 goto err2;
180         ret = gpio_direction_output(GPIO_NR_PALMT5_LCD_POWER, 0);
181         if (ret)
182                 goto err3;
183
184         return 0;
185 err3:
186         gpio_free(GPIO_NR_PALMT5_LCD_POWER);
187 err2:
188         gpio_free(GPIO_NR_PALMT5_BL_POWER);
189 err:
190         return ret;
191 }
192
193 static int palmt5_backlight_notify(struct device *dev, int brightness)
194 {
195         gpio_set_value(GPIO_NR_PALMT5_BL_POWER, brightness);
196         gpio_set_value(GPIO_NR_PALMT5_LCD_POWER, brightness);
197         return brightness;
198 }
199
200 static void palmt5_backlight_exit(struct device *dev)
201 {
202         gpio_free(GPIO_NR_PALMT5_BL_POWER);
203         gpio_free(GPIO_NR_PALMT5_LCD_POWER);
204 }
205
206 static struct platform_pwm_backlight_data palmt5_backlight_data = {
207         .pwm_id         = 0,
208         .max_brightness = PALMT5_MAX_INTENSITY,
209         .dft_brightness = PALMT5_MAX_INTENSITY,
210         .pwm_period_ns  = PALMT5_PERIOD_NS,
211         .init           = palmt5_backlight_init,
212         .notify         = palmt5_backlight_notify,
213         .exit           = palmt5_backlight_exit,
214 };
215
216 static struct platform_device palmt5_backlight = {
217         .name   = "pwm-backlight",
218         .dev    = {
219                 .parent         = &pxa27x_device_pwm0.dev,
220                 .platform_data  = &palmt5_backlight_data,
221         },
222 };
223
224 /******************************************************************************
225  * IrDA
226  ******************************************************************************/
227 static struct pxaficp_platform_data palmt5_ficp_platform_data = {
228         .gpio_pwdown            = GPIO_NR_PALMT5_IR_DISABLE,
229         .transceiver_cap        = IR_SIRMODE | IR_OFF,
230 };
231
232 /******************************************************************************
233  * UDC
234  ******************************************************************************/
235 static struct gpio_vbus_mach_info palmt5_udc_info = {
236         .gpio_vbus              = GPIO_NR_PALMT5_USB_DETECT_N,
237         .gpio_vbus_inverted     = 1,
238         .gpio_pullup            = GPIO_NR_PALMT5_USB_PULLUP,
239 };
240
241 static struct platform_device palmt5_gpio_vbus = {
242         .name   = "gpio-vbus",
243         .id     = -1,
244         .dev    = {
245                 .platform_data  = &palmt5_udc_info,
246         },
247 };
248
249 /******************************************************************************
250  * Power supply
251  ******************************************************************************/
252 static int power_supply_init(struct device *dev)
253 {
254         int ret;
255
256         ret = gpio_request(GPIO_NR_PALMT5_POWER_DETECT, "CABLE_STATE_AC");
257         if (ret)
258                 goto err1;
259         ret = gpio_direction_input(GPIO_NR_PALMT5_POWER_DETECT);
260         if (ret)
261                 goto err2;
262
263         return 0;
264 err2:
265         gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
266 err1:
267         return ret;
268 }
269
270 static int palmt5_is_ac_online(void)
271 {
272         return gpio_get_value(GPIO_NR_PALMT5_POWER_DETECT);
273 }
274
275 static void power_supply_exit(struct device *dev)
276 {
277         gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
278 }
279
280 static char *palmt5_supplicants[] = {
281         "main-battery",
282 };
283
284 static struct pda_power_pdata power_supply_info = {
285         .init            = power_supply_init,
286         .is_ac_online    = palmt5_is_ac_online,
287         .exit            = power_supply_exit,
288         .supplied_to     = palmt5_supplicants,
289         .num_supplicants = ARRAY_SIZE(palmt5_supplicants),
290 };
291
292 static struct platform_device power_supply = {
293         .name = "pda-power",
294         .id   = -1,
295         .dev  = {
296                 .platform_data = &power_supply_info,
297         },
298 };
299
300 /******************************************************************************
301  * WM97xx battery
302  ******************************************************************************/
303 static struct wm97xx_batt_info wm97xx_batt_pdata = {
304         .batt_aux       = WM97XX_AUX_ID3,
305         .temp_aux       = WM97XX_AUX_ID2,
306         .charge_gpio    = -1,
307         .max_voltage    = PALMT5_BAT_MAX_VOLTAGE,
308         .min_voltage    = PALMT5_BAT_MIN_VOLTAGE,
309         .batt_mult      = 1000,
310         .batt_div       = 414,
311         .temp_mult      = 1,
312         .temp_div       = 1,
313         .batt_tech      = POWER_SUPPLY_TECHNOLOGY_LIPO,
314         .batt_name      = "main-batt",
315 };
316
317 /******************************************************************************
318  * aSoC audio
319  ******************************************************************************/
320 static struct palm27x_asoc_info palmt5_asoc_pdata = {
321         .jack_gpio      = GPIO_NR_PALMT5_EARPHONE_DETECT,
322 };
323
324 static pxa2xx_audio_ops_t palmt5_ac97_pdata = {
325         .reset_gpio     = 95,
326 };
327
328 static struct platform_device palmt5_asoc = {
329         .name = "palm27x-asoc",
330         .id   = -1,
331         .dev  = {
332                 .platform_data = &palmt5_asoc_pdata,
333         },
334 };
335
336 /******************************************************************************
337  * Framebuffer
338  ******************************************************************************/
339 static struct pxafb_mode_info palmt5_lcd_modes[] = {
340 {
341         .pixclock       = 57692,
342         .xres           = 320,
343         .yres           = 480,
344         .bpp            = 16,
345
346         .left_margin    = 32,
347         .right_margin   = 1,
348         .upper_margin   = 7,
349         .lower_margin   = 1,
350
351         .hsync_len      = 4,
352         .vsync_len      = 1,
353 },
354 };
355
356 static struct pxafb_mach_info palmt5_lcd_screen = {
357         .modes          = palmt5_lcd_modes,
358         .num_modes      = ARRAY_SIZE(palmt5_lcd_modes),
359         .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
360 };
361
362 /******************************************************************************
363  * Power management - standby
364  ******************************************************************************/
365 static void __init palmt5_pm_init(void)
366 {
367         static u32 resume[] = {
368                 0xe3a00101,     /* mov  r0,     #0x40000000 */
369                 0xe380060f,     /* orr  r0, r0, #0x00f00000 */
370                 0xe590f008,     /* ldr  pc, [r0, #0x08] */
371         };
372
373         /* copy the bootloader */
374         memcpy(phys_to_virt(PALMT5_STR_BASE), resume, sizeof(resume));
375 }
376
377 /******************************************************************************
378  * Machine init
379  ******************************************************************************/
380 static struct platform_device *devices[] __initdata = {
381 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
382         &palmt5_pxa_keys,
383 #endif
384         &palmt5_backlight,
385         &power_supply,
386         &palmt5_asoc,
387         &palmt5_gpio_vbus,
388 };
389
390 /* setup udc GPIOs initial state */
391 static void __init palmt5_udc_init(void)
392 {
393         if (!gpio_request(GPIO_NR_PALMT5_USB_PULLUP, "UDC Vbus")) {
394                 gpio_direction_output(GPIO_NR_PALMT5_USB_PULLUP, 1);
395                 gpio_free(GPIO_NR_PALMT5_USB_PULLUP);
396         }
397 }
398
399 static void __init palmt5_init(void)
400 {
401         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmt5_pin_config));
402
403         pxa_set_ffuart_info(NULL);
404         pxa_set_btuart_info(NULL);
405         pxa_set_stuart_info(NULL);
406
407         palmt5_pm_init();
408         set_pxa_fb_info(&palmt5_lcd_screen);
409         pxa_set_mci_info(&palmt5_mci_platform_data);
410         palmt5_udc_init();
411         pxa_set_ac97_info(&palmt5_ac97_pdata);
412         pxa_set_ficp_info(&palmt5_ficp_platform_data);
413         pxa_set_keypad_info(&palmt5_keypad_platform_data);
414         wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
415
416         platform_add_devices(devices, ARRAY_SIZE(devices));
417 }
418
419 MACHINE_START(PALMT5, "Palm Tungsten|T5")
420         .phys_io        = PALMT5_PHYS_IO_START,
421         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
422         .boot_params    = 0xa0000100,
423         .map_io         = pxa_map_io,
424         .init_irq       = pxa27x_init_irq,
425         .timer          = &pxa_timer,
426         .init_machine   = palmt5_init
427 MACHINE_END