Merge branch 'linux-next' of git://git.infradead.org/ubifs-2.6
[pandora-kernel.git] / arch / arm / mach-pxa / palmtx.c
1 /*
2  * Hardware definitions for PalmTX
3  *
4  * Author:     Marek Vasut <marek.vasut@gmail.com>
5  *
6  * Based on work of:
7  *              Alex Osborne <ato@meshy.org>
8  *              Cristiano P. <cristianop@users.sourceforge.net>
9  *              Jan Herman <2hp@seznam.cz>
10  *              Michal Hrusecky
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  * (find more info at www.hackndev.com)
17  *
18  */
19
20 #include <linux/platform_device.h>
21 #include <linux/delay.h>
22 #include <linux/irq.h>
23 #include <linux/gpio_keys.h>
24 #include <linux/input.h>
25 #include <linux/pda_power.h>
26 #include <linux/pwm_backlight.h>
27 #include <linux/gpio.h>
28 #include <linux/wm97xx_batt.h>
29 #include <linux/power_supply.h>
30
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34
35 #include <mach/audio.h>
36 #include <mach/palmtx.h>
37 #include <mach/mmc.h>
38 #include <mach/pxafb.h>
39 #include <mach/pxa-regs.h>
40 #include <mach/mfp-pxa27x.h>
41 #include <mach/irda.h>
42 #include <mach/pxa27x_keypad.h>
43 #include <mach/udc.h>
44
45 #include "generic.h"
46 #include "devices.h"
47
48 /******************************************************************************
49  * Pin configuration
50  ******************************************************************************/
51 static unsigned long palmtx_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
60         /* AC97 */
61         GPIO28_AC97_BITCLK,
62         GPIO29_AC97_SDATA_IN_0,
63         GPIO30_AC97_SDATA_OUT,
64         GPIO31_AC97_SYNC,
65
66         /* IrDA */
67         GPIO46_FICP_RXD,
68         GPIO47_FICP_TXD,
69
70         /* PWM */
71         GPIO16_PWM0_OUT,
72
73         /* USB */
74         GPIO13_GPIO,
75
76         /* PCMCIA */
77         GPIO48_nPOE,
78         GPIO49_nPWE,
79         GPIO50_nPIOR,
80         GPIO51_nPIOW,
81         GPIO85_nPCE_1,
82         GPIO54_nPCE_2,
83         GPIO79_PSKTSEL,
84         GPIO55_nPREG,
85         GPIO56_nPWAIT,
86         GPIO57_nIOIS16,
87 };
88
89 /******************************************************************************
90  * SD/MMC card controller
91  ******************************************************************************/
92 static int palmtx_mci_init(struct device *dev, irq_handler_t palmtx_detect_int,
93                                 void *data)
94 {
95         int err = 0;
96
97         /* Setup an interrupt for detecting card insert/remove events */
98         err = request_irq(IRQ_GPIO_PALMTX_SD_DETECT_N, palmtx_detect_int,
99                         IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
100                         IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
101                         "SD/MMC card detect", data);
102         if (err) {
103                 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
104                                 __func__);
105                 return err;
106         }
107
108         err = gpio_request(GPIO_NR_PALMTX_SD_POWER, "SD_POWER");
109         if (err)
110                 goto pwr_err;
111
112         err = gpio_request(GPIO_NR_PALMTX_SD_READONLY, "SD_READONLY");
113         if (err)
114                 goto ro_err;
115
116         printk(KERN_DEBUG "%s: irq registered\n", __func__);
117
118         return 0;
119
120 ro_err:
121         gpio_free(GPIO_NR_PALMTX_SD_POWER);
122 pwr_err:
123         free_irq(IRQ_GPIO_PALMTX_SD_DETECT_N, data);
124         return err;
125 }
126
127 static void palmtx_mci_exit(struct device *dev, void *data)
128 {
129         gpio_free(GPIO_NR_PALMTX_SD_READONLY);
130         gpio_free(GPIO_NR_PALMTX_SD_POWER);
131         free_irq(IRQ_GPIO_PALMTX_SD_DETECT_N, data);
132 }
133
134 static void palmtx_mci_power(struct device *dev, unsigned int vdd)
135 {
136         struct pxamci_platform_data *p_d = dev->platform_data;
137         gpio_set_value(GPIO_NR_PALMTX_SD_POWER, p_d->ocr_mask & (1 << vdd));
138 }
139
140 static int palmtx_mci_get_ro(struct device *dev)
141 {
142         return gpio_get_value(GPIO_NR_PALMTX_SD_READONLY);
143 }
144
145 static struct pxamci_platform_data palmtx_mci_platform_data = {
146         .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
147         .setpower       = palmtx_mci_power,
148         .get_ro         = palmtx_mci_get_ro,
149         .init           = palmtx_mci_init,
150         .exit           = palmtx_mci_exit,
151 };
152
153 /******************************************************************************
154  * GPIO keyboard
155  ******************************************************************************/
156 static unsigned int palmtx_matrix_keys[] = {
157         KEY(0, 0, KEY_POWER),
158         KEY(0, 1, KEY_F1),
159         KEY(0, 2, KEY_ENTER),
160
161         KEY(1, 0, KEY_F2),
162         KEY(1, 1, KEY_F3),
163         KEY(1, 2, KEY_F4),
164
165         KEY(2, 0, KEY_UP),
166         KEY(2, 2, KEY_DOWN),
167
168         KEY(3, 0, KEY_RIGHT),
169         KEY(3, 2, KEY_LEFT),
170
171 };
172
173 static struct pxa27x_keypad_platform_data palmtx_keypad_platform_data = {
174         .matrix_key_rows        = 4,
175         .matrix_key_cols        = 3,
176         .matrix_key_map         = palmtx_matrix_keys,
177         .matrix_key_map_size    = ARRAY_SIZE(palmtx_matrix_keys),
178
179         .debounce_interval      = 30,
180 };
181
182 /******************************************************************************
183  * GPIO keys
184  ******************************************************************************/
185 static struct gpio_keys_button palmtx_pxa_buttons[] = {
186         {KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
187 };
188
189 static struct gpio_keys_platform_data palmtx_pxa_keys_data = {
190         .buttons        = palmtx_pxa_buttons,
191         .nbuttons       = ARRAY_SIZE(palmtx_pxa_buttons),
192 };
193
194 static struct platform_device palmtx_pxa_keys = {
195         .name   = "gpio-keys",
196         .id     = -1,
197         .dev    = {
198                 .platform_data = &palmtx_pxa_keys_data,
199         },
200 };
201
202 /******************************************************************************
203  * Backlight
204  ******************************************************************************/
205 static int palmtx_backlight_init(struct device *dev)
206 {
207         int ret;
208
209         ret = gpio_request(GPIO_NR_PALMTX_BL_POWER, "BL POWER");
210         if (ret)
211                 goto err;
212         ret = gpio_request(GPIO_NR_PALMTX_LCD_POWER, "LCD POWER");
213         if (ret)
214                 goto err2;
215
216         return 0;
217 err2:
218         gpio_free(GPIO_NR_PALMTX_BL_POWER);
219 err:
220         return ret;
221 }
222
223 static int palmtx_backlight_notify(int brightness)
224 {
225         gpio_set_value(GPIO_NR_PALMTX_BL_POWER, brightness);
226         gpio_set_value(GPIO_NR_PALMTX_LCD_POWER, brightness);
227         return brightness;
228 }
229
230 static void palmtx_backlight_exit(struct device *dev)
231 {
232         gpio_free(GPIO_NR_PALMTX_BL_POWER);
233         gpio_free(GPIO_NR_PALMTX_LCD_POWER);
234 }
235
236 static struct platform_pwm_backlight_data palmtx_backlight_data = {
237         .pwm_id         = 0,
238         .max_brightness = PALMTX_MAX_INTENSITY,
239         .dft_brightness = PALMTX_MAX_INTENSITY,
240         .pwm_period_ns  = PALMTX_PERIOD_NS,
241         .init           = palmtx_backlight_init,
242         .notify         = palmtx_backlight_notify,
243         .exit           = palmtx_backlight_exit,
244 };
245
246 static struct platform_device palmtx_backlight = {
247         .name   = "pwm-backlight",
248         .dev    = {
249                 .parent         = &pxa27x_device_pwm0.dev,
250                 .platform_data  = &palmtx_backlight_data,
251         },
252 };
253
254 /******************************************************************************
255  * IrDA
256  ******************************************************************************/
257 static void palmtx_irda_transceiver_mode(struct device *dev, int mode)
258 {
259         gpio_set_value(GPIO_NR_PALMTX_IR_DISABLE, mode & IR_OFF);
260         pxa2xx_transceiver_mode(dev, mode);
261 }
262
263 static struct pxaficp_platform_data palmtx_ficp_platform_data = {
264         .transceiver_cap        = IR_SIRMODE | IR_FIRMODE | IR_OFF,
265         .transceiver_mode       = palmtx_irda_transceiver_mode,
266 };
267
268 /******************************************************************************
269  * UDC
270  ******************************************************************************/
271 static void palmtx_udc_command(int cmd)
272 {
273         gpio_set_value(GPIO_NR_PALMTX_USB_POWER, !cmd);
274         udelay(50);
275         gpio_set_value(GPIO_NR_PALMTX_USB_PULLUP, !cmd);
276 }
277
278 static struct pxa2xx_udc_mach_info palmtx_udc_info __initdata = {
279         .gpio_vbus              = GPIO_NR_PALMTX_USB_DETECT_N,
280         .gpio_vbus_inverted     = 1,
281         .udc_command            = palmtx_udc_command,
282 };
283
284 /******************************************************************************
285  * Power supply
286  ******************************************************************************/
287 static int power_supply_init(struct device *dev)
288 {
289         int ret;
290
291         ret = gpio_request(GPIO_NR_PALMTX_POWER_DETECT, "CABLE_STATE_AC");
292         if (ret)
293                 goto err_cs_ac;
294
295         ret = gpio_request(GPIO_NR_PALMTX_USB_DETECT_N, "CABLE_STATE_USB");
296         if (ret)
297                 goto err_cs_usb;
298
299         return 0;
300
301 err_cs_usb:
302         gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
303 err_cs_ac:
304         return ret;
305 }
306
307 static int palmtx_is_ac_online(void)
308 {
309         return gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT);
310 }
311
312 static int palmtx_is_usb_online(void)
313 {
314         return !gpio_get_value(GPIO_NR_PALMTX_USB_DETECT_N);
315 }
316
317 static void power_supply_exit(struct device *dev)
318 {
319         gpio_free(GPIO_NR_PALMTX_USB_DETECT_N);
320         gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
321 }
322
323 static char *palmtx_supplicants[] = {
324         "main-battery",
325 };
326
327 static struct pda_power_pdata power_supply_info = {
328         .init            = power_supply_init,
329         .is_ac_online    = palmtx_is_ac_online,
330         .is_usb_online   = palmtx_is_usb_online,
331         .exit            = power_supply_exit,
332         .supplied_to     = palmtx_supplicants,
333         .num_supplicants = ARRAY_SIZE(palmtx_supplicants),
334 };
335
336 static struct platform_device power_supply = {
337         .name = "pda-power",
338         .id   = -1,
339         .dev  = {
340                 .platform_data = &power_supply_info,
341         },
342 };
343
344 /******************************************************************************
345  * WM97xx battery
346  ******************************************************************************/
347 static struct wm97xx_batt_info wm97xx_batt_pdata = {
348         .batt_aux       = WM97XX_AUX_ID3,
349         .temp_aux       = WM97XX_AUX_ID2,
350         .charge_gpio    = -1,
351         .max_voltage    = PALMTX_BAT_MAX_VOLTAGE,
352         .min_voltage    = PALMTX_BAT_MIN_VOLTAGE,
353         .batt_mult      = 1000,
354         .batt_div       = 414,
355         .temp_mult      = 1,
356         .temp_div       = 1,
357         .batt_tech      = POWER_SUPPLY_TECHNOLOGY_LIPO,
358         .batt_name      = "main-batt",
359 };
360
361 /******************************************************************************
362  * Framebuffer
363  ******************************************************************************/
364 static struct pxafb_mode_info palmtx_lcd_modes[] = {
365 {
366         .pixclock       = 57692,
367         .xres           = 320,
368         .yres           = 480,
369         .bpp            = 16,
370
371         .left_margin    = 32,
372         .right_margin   = 1,
373         .upper_margin   = 7,
374         .lower_margin   = 1,
375
376         .hsync_len      = 4,
377         .vsync_len      = 1,
378 },
379 };
380
381 static struct pxafb_mach_info palmtx_lcd_screen = {
382         .modes          = palmtx_lcd_modes,
383         .num_modes      = ARRAY_SIZE(palmtx_lcd_modes),
384         .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
385 };
386
387 /******************************************************************************
388  * Machine init
389  ******************************************************************************/
390 static struct platform_device *devices[] __initdata = {
391 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
392         &palmtx_pxa_keys,
393 #endif
394         &palmtx_backlight,
395         &power_supply,
396 };
397
398 static struct map_desc palmtx_io_desc[] __initdata = {
399 {
400         .virtual        = PALMTX_PCMCIA_VIRT,
401         .pfn            = __phys_to_pfn(PALMTX_PCMCIA_PHYS),
402         .length         = PALMTX_PCMCIA_SIZE,
403         .type           = MT_DEVICE
404 },
405 };
406
407 static void __init palmtx_map_io(void)
408 {
409         pxa_map_io();
410         iotable_init(palmtx_io_desc, ARRAY_SIZE(palmtx_io_desc));
411 }
412
413 static void __init palmtx_init(void)
414 {
415         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmtx_pin_config));
416
417         set_pxa_fb_info(&palmtx_lcd_screen);
418         pxa_set_mci_info(&palmtx_mci_platform_data);
419         pxa_set_udc_info(&palmtx_udc_info);
420         pxa_set_ac97_info(NULL);
421         pxa_set_ficp_info(&palmtx_ficp_platform_data);
422         pxa_set_keypad_info(&palmtx_keypad_platform_data);
423         wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
424
425         platform_add_devices(devices, ARRAY_SIZE(devices));
426 }
427
428 MACHINE_START(PALMTX, "Palm T|X")
429         .phys_io        = PALMTX_PHYS_IO_START,
430         .io_pg_offst    = io_p2v(0x40000000),
431         .boot_params    = 0xa0000100,
432         .map_io         = palmtx_map_io,
433         .init_irq       = pxa27x_init_irq,
434         .timer          = &pxa_timer,
435         .init_machine   = palmtx_init
436 MACHINE_END