OMAP3: PM: Ensure MUSB block can idle when driver not loaded
[linux-ginger.git] / arch / arm / mach-pxa / palmte2.c
blob43fcf2e868875cd17bb738f1df1ca0a6a6ea9813
1 /*
2 * Hardware definitions for Palm Tungsten|E2
4 * Author:
5 * Carlos Eduardo Medaglia Dyonisio <cadu@nerdfeliz.com>
7 * Rewrite for mainline:
8 * Marek Vasut <marek.vasut@gmail.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * (find more info at www.hackndev.com)
18 #include <linux/platform_device.h>
19 #include <linux/delay.h>
20 #include <linux/irq.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/input.h>
23 #include <linux/pda_power.h>
24 #include <linux/pwm_backlight.h>
25 #include <linux/gpio.h>
26 #include <linux/wm97xx_batt.h>
27 #include <linux/power_supply.h>
29 #include <asm/mach-types.h>
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
33 #include <mach/audio.h>
34 #include <mach/palmte2.h>
35 #include <mach/mmc.h>
36 #include <mach/pxafb.h>
37 #include <mach/mfp-pxa25x.h>
38 #include <mach/irda.h>
39 #include <mach/udc.h>
41 #include "generic.h"
42 #include "devices.h"
44 /******************************************************************************
45 * Pin configuration
46 ******************************************************************************/
47 static unsigned long palmte2_pin_config[] __initdata = {
48 /* MMC */
49 GPIO6_MMC_CLK,
50 GPIO8_MMC_CS0,
51 GPIO10_GPIO, /* SD detect */
52 GPIO55_GPIO, /* SD power */
53 GPIO51_GPIO, /* SD r/o switch */
55 /* AC97 */
56 GPIO28_AC97_BITCLK,
57 GPIO29_AC97_SDATA_IN_0,
58 GPIO30_AC97_SDATA_OUT,
59 GPIO31_AC97_SYNC,
61 /* PWM */
62 GPIO16_PWM0_OUT,
64 /* USB */
65 GPIO15_GPIO, /* usb detect */
66 GPIO53_GPIO, /* usb power */
68 /* IrDA */
69 GPIO48_GPIO, /* ir disable */
70 GPIO46_FICP_RXD,
71 GPIO47_FICP_TXD,
73 /* LCD */
74 GPIO58_LCD_LDD_0,
75 GPIO59_LCD_LDD_1,
76 GPIO60_LCD_LDD_2,
77 GPIO61_LCD_LDD_3,
78 GPIO62_LCD_LDD_4,
79 GPIO63_LCD_LDD_5,
80 GPIO64_LCD_LDD_6,
81 GPIO65_LCD_LDD_7,
82 GPIO66_LCD_LDD_8,
83 GPIO67_LCD_LDD_9,
84 GPIO68_LCD_LDD_10,
85 GPIO69_LCD_LDD_11,
86 GPIO70_LCD_LDD_12,
87 GPIO71_LCD_LDD_13,
88 GPIO72_LCD_LDD_14,
89 GPIO73_LCD_LDD_15,
90 GPIO74_LCD_FCLK,
91 GPIO75_LCD_LCLK,
92 GPIO76_LCD_PCLK,
93 GPIO77_LCD_BIAS,
95 /* GPIO KEYS */
96 GPIO5_GPIO, /* notes */
97 GPIO7_GPIO, /* tasks */
98 GPIO11_GPIO, /* calendar */
99 GPIO13_GPIO, /* contacts */
100 GPIO14_GPIO, /* center */
101 GPIO19_GPIO, /* left */
102 GPIO20_GPIO, /* right */
103 GPIO21_GPIO, /* down */
104 GPIO22_GPIO, /* up */
106 /* MISC */
107 GPIO1_RST, /* reset */
108 GPIO4_GPIO, /* Hotsync button */
109 GPIO9_GPIO, /* power detect */
110 GPIO37_GPIO, /* LCD power */
111 GPIO56_GPIO, /* Backlight power */
114 /******************************************************************************
115 * SD/MMC card controller
116 ******************************************************************************/
117 static int palmte2_mci_init(struct device *dev,
118 irq_handler_t palmte2_detect_int, void *data)
120 int err = 0;
122 /* Setup an interrupt for detecting card insert/remove events */
123 err = gpio_request(GPIO_NR_PALMTE2_SD_DETECT_N, "SD IRQ");
124 if (err)
125 goto err;
126 err = gpio_direction_input(GPIO_NR_PALMTE2_SD_DETECT_N);
127 if (err)
128 goto err2;
129 err = request_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N),
130 palmte2_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
131 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
132 "SD/MMC card detect", data);
133 if (err) {
134 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
135 __func__);
136 goto err2;
139 err = gpio_request(GPIO_NR_PALMTE2_SD_POWER, "SD_POWER");
140 if (err)
141 goto err3;
142 err = gpio_direction_output(GPIO_NR_PALMTE2_SD_POWER, 0);
143 if (err)
144 goto err4;
146 err = gpio_request(GPIO_NR_PALMTE2_SD_READONLY, "SD_READONLY");
147 if (err)
148 goto err4;
149 err = gpio_direction_input(GPIO_NR_PALMTE2_SD_READONLY);
150 if (err)
151 goto err5;
153 printk(KERN_DEBUG "%s: irq registered\n", __func__);
155 return 0;
157 err5:
158 gpio_free(GPIO_NR_PALMTE2_SD_READONLY);
159 err4:
160 gpio_free(GPIO_NR_PALMTE2_SD_POWER);
161 err3:
162 free_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N), data);
163 err2:
164 gpio_free(GPIO_NR_PALMTE2_SD_DETECT_N);
165 err:
166 return err;
169 static void palmte2_mci_exit(struct device *dev, void *data)
171 gpio_free(GPIO_NR_PALMTE2_SD_READONLY);
172 gpio_free(GPIO_NR_PALMTE2_SD_POWER);
173 free_irq(gpio_to_irq(GPIO_NR_PALMTE2_SD_DETECT_N), data);
174 gpio_free(GPIO_NR_PALMTE2_SD_DETECT_N);
177 static void palmte2_mci_power(struct device *dev, unsigned int vdd)
179 struct pxamci_platform_data *p_d = dev->platform_data;
180 gpio_set_value(GPIO_NR_PALMTE2_SD_POWER, p_d->ocr_mask & (1 << vdd));
183 static int palmte2_mci_get_ro(struct device *dev)
185 return gpio_get_value(GPIO_NR_PALMTE2_SD_READONLY);
188 static struct pxamci_platform_data palmte2_mci_platform_data = {
189 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
190 .setpower = palmte2_mci_power,
191 .get_ro = palmte2_mci_get_ro,
192 .init = palmte2_mci_init,
193 .exit = palmte2_mci_exit,
196 /******************************************************************************
197 * GPIO keys
198 ******************************************************************************/
199 static struct gpio_keys_button palmte2_pxa_buttons[] = {
200 {KEY_F1, GPIO_NR_PALMTE2_KEY_CONTACTS, 1, "Contacts" },
201 {KEY_F2, GPIO_NR_PALMTE2_KEY_CALENDAR, 1, "Calendar" },
202 {KEY_F3, GPIO_NR_PALMTE2_KEY_TASKS, 1, "Tasks" },
203 {KEY_F4, GPIO_NR_PALMTE2_KEY_NOTES, 1, "Notes" },
204 {KEY_ENTER, GPIO_NR_PALMTE2_KEY_CENTER, 1, "Center" },
205 {KEY_LEFT, GPIO_NR_PALMTE2_KEY_LEFT, 1, "Left" },
206 {KEY_RIGHT, GPIO_NR_PALMTE2_KEY_RIGHT, 1, "Right" },
207 {KEY_DOWN, GPIO_NR_PALMTE2_KEY_DOWN, 1, "Down" },
208 {KEY_UP, GPIO_NR_PALMTE2_KEY_UP, 1, "Up" },
211 static struct gpio_keys_platform_data palmte2_pxa_keys_data = {
212 .buttons = palmte2_pxa_buttons,
213 .nbuttons = ARRAY_SIZE(palmte2_pxa_buttons),
216 static struct platform_device palmte2_pxa_keys = {
217 .name = "gpio-keys",
218 .id = -1,
219 .dev = {
220 .platform_data = &palmte2_pxa_keys_data,
224 /******************************************************************************
225 * Backlight
226 ******************************************************************************/
227 static int palmte2_backlight_init(struct device *dev)
229 int ret;
231 ret = gpio_request(GPIO_NR_PALMTE2_BL_POWER, "BL POWER");
232 if (ret)
233 goto err;
234 ret = gpio_direction_output(GPIO_NR_PALMTE2_BL_POWER, 0);
235 if (ret)
236 goto err2;
237 ret = gpio_request(GPIO_NR_PALMTE2_LCD_POWER, "LCD POWER");
238 if (ret)
239 goto err2;
240 ret = gpio_direction_output(GPIO_NR_PALMTE2_LCD_POWER, 0);
241 if (ret)
242 goto err3;
244 return 0;
245 err3:
246 gpio_free(GPIO_NR_PALMTE2_LCD_POWER);
247 err2:
248 gpio_free(GPIO_NR_PALMTE2_BL_POWER);
249 err:
250 return ret;
253 static int palmte2_backlight_notify(int brightness)
255 gpio_set_value(GPIO_NR_PALMTE2_BL_POWER, brightness);
256 gpio_set_value(GPIO_NR_PALMTE2_LCD_POWER, brightness);
257 return brightness;
260 static void palmte2_backlight_exit(struct device *dev)
262 gpio_free(GPIO_NR_PALMTE2_BL_POWER);
263 gpio_free(GPIO_NR_PALMTE2_LCD_POWER);
266 static struct platform_pwm_backlight_data palmte2_backlight_data = {
267 .pwm_id = 0,
268 .max_brightness = PALMTE2_MAX_INTENSITY,
269 .dft_brightness = PALMTE2_MAX_INTENSITY,
270 .pwm_period_ns = PALMTE2_PERIOD_NS,
271 .init = palmte2_backlight_init,
272 .notify = palmte2_backlight_notify,
273 .exit = palmte2_backlight_exit,
276 static struct platform_device palmte2_backlight = {
277 .name = "pwm-backlight",
278 .dev = {
279 .parent = &pxa25x_device_pwm0.dev,
280 .platform_data = &palmte2_backlight_data,
284 /******************************************************************************
285 * IrDA
286 ******************************************************************************/
287 static int palmte2_irda_startup(struct device *dev)
289 int err;
290 err = gpio_request(GPIO_NR_PALMTE2_IR_DISABLE, "IR DISABLE");
291 if (err)
292 goto err;
293 err = gpio_direction_output(GPIO_NR_PALMTE2_IR_DISABLE, 1);
294 if (err)
295 gpio_free(GPIO_NR_PALMTE2_IR_DISABLE);
296 err:
297 return err;
300 static void palmte2_irda_shutdown(struct device *dev)
302 gpio_free(GPIO_NR_PALMTE2_IR_DISABLE);
305 static void palmte2_irda_transceiver_mode(struct device *dev, int mode)
307 gpio_set_value(GPIO_NR_PALMTE2_IR_DISABLE, mode & IR_OFF);
308 pxa2xx_transceiver_mode(dev, mode);
311 static struct pxaficp_platform_data palmte2_ficp_platform_data = {
312 .startup = palmte2_irda_startup,
313 .shutdown = palmte2_irda_shutdown,
314 .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
315 .transceiver_mode = palmte2_irda_transceiver_mode,
318 /******************************************************************************
319 * UDC
320 ******************************************************************************/
321 static struct pxa2xx_udc_mach_info palmte2_udc_info __initdata = {
322 .gpio_vbus = GPIO_NR_PALMTE2_USB_DETECT_N,
323 .gpio_vbus_inverted = 1,
324 .gpio_pullup = GPIO_NR_PALMTE2_USB_PULLUP,
325 .gpio_pullup_inverted = 0,
328 /******************************************************************************
329 * Power supply
330 ******************************************************************************/
331 static int power_supply_init(struct device *dev)
333 int ret;
335 ret = gpio_request(GPIO_NR_PALMTE2_POWER_DETECT, "CABLE_STATE_AC");
336 if (ret)
337 goto err1;
338 ret = gpio_direction_input(GPIO_NR_PALMTE2_POWER_DETECT);
339 if (ret)
340 goto err2;
342 return 0;
344 err2:
345 gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
346 err1:
347 return ret;
350 static int palmte2_is_ac_online(void)
352 return gpio_get_value(GPIO_NR_PALMTE2_POWER_DETECT);
355 static void power_supply_exit(struct device *dev)
357 gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
360 static char *palmte2_supplicants[] = {
361 "main-battery",
364 static struct pda_power_pdata power_supply_info = {
365 .init = power_supply_init,
366 .is_ac_online = palmte2_is_ac_online,
367 .exit = power_supply_exit,
368 .supplied_to = palmte2_supplicants,
369 .num_supplicants = ARRAY_SIZE(palmte2_supplicants),
372 static struct platform_device power_supply = {
373 .name = "pda-power",
374 .id = -1,
375 .dev = {
376 .platform_data = &power_supply_info,
380 /******************************************************************************
381 * WM97xx battery
382 ******************************************************************************/
383 static struct wm97xx_batt_info wm97xx_batt_pdata = {
384 .batt_aux = WM97XX_AUX_ID3,
385 .temp_aux = WM97XX_AUX_ID2,
386 .charge_gpio = -1,
387 .max_voltage = PALMTE2_BAT_MAX_VOLTAGE,
388 .min_voltage = PALMTE2_BAT_MIN_VOLTAGE,
389 .batt_mult = 1000,
390 .batt_div = 414,
391 .temp_mult = 1,
392 .temp_div = 1,
393 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
394 .batt_name = "main-batt",
397 /******************************************************************************
398 * Framebuffer
399 ******************************************************************************/
400 static struct pxafb_mode_info palmte2_lcd_modes[] = {
402 .pixclock = 77757,
403 .xres = 320,
404 .yres = 320,
405 .bpp = 16,
407 .left_margin = 28,
408 .right_margin = 7,
409 .upper_margin = 7,
410 .lower_margin = 5,
412 .hsync_len = 4,
413 .vsync_len = 1,
417 static struct pxafb_mach_info palmte2_lcd_screen = {
418 .modes = palmte2_lcd_modes,
419 .num_modes = ARRAY_SIZE(palmte2_lcd_modes),
420 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
423 /******************************************************************************
424 * Machine init
425 ******************************************************************************/
426 static struct platform_device *devices[] __initdata = {
427 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
428 &palmte2_pxa_keys,
429 #endif
430 &palmte2_backlight,
431 &power_supply,
434 /* setup udc GPIOs initial state */
435 static void __init palmte2_udc_init(void)
437 if (!gpio_request(GPIO_NR_PALMTE2_USB_PULLUP, "UDC Vbus")) {
438 gpio_direction_output(GPIO_NR_PALMTE2_USB_PULLUP, 1);
439 gpio_free(GPIO_NR_PALMTE2_USB_PULLUP);
443 static void __init palmte2_init(void)
445 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmte2_pin_config));
447 set_pxa_fb_info(&palmte2_lcd_screen);
448 pxa_set_mci_info(&palmte2_mci_platform_data);
449 palmte2_udc_init();
450 pxa_set_udc_info(&palmte2_udc_info);
451 pxa_set_ac97_info(NULL);
452 pxa_set_ficp_info(&palmte2_ficp_platform_data);
453 wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
455 platform_add_devices(devices, ARRAY_SIZE(devices));
458 MACHINE_START(PALMTE2, "Palm Tungsten|E2")
459 .phys_io = 0x40000000,
460 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
461 .boot_params = 0xa0000100,
462 .map_io = pxa_map_io,
463 .init_irq = pxa25x_init_irq,
464 .timer = &pxa_timer,
465 .init_machine = palmte2_init
466 MACHINE_END