2 * Common code for Palm LD, T5, TX, Z72
5 * Marek Vasut <marek.vasut@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #include <linux/platform_device.h>
14 #include <linux/delay.h>
15 #include <linux/irq.h>
16 #include <linux/gpio_keys.h>
17 #include <linux/input.h>
18 #include <linux/pda_power.h>
19 #include <linux/pwm_backlight.h>
20 #include <linux/gpio.h>
21 #include <linux/wm97xx.h>
22 #include <linux/power_supply.h>
23 #include <linux/usb/gpio_vbus.h>
24 #include <linux/regulator/max1586.h>
25 #include <linux/i2c/pxa-i2c.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
31 #include <mach/pxa27x.h>
32 #include <mach/audio.h>
34 #include <mach/pxafb.h>
35 #include <mach/irda.h>
37 #include <mach/palmasoc.h>
38 #include <mach/palm27x.h>
43 /******************************************************************************
44 * SD/MMC card controller
45 ******************************************************************************/
46 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
47 static struct pxamci_platform_data palm27x_mci_platform_data = {
48 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
49 .detect_delay_ms = 200,
52 void __init palm27x_mmc_init(int detect, int ro, int power,
55 palm27x_mci_platform_data.gpio_card_detect = detect;
56 palm27x_mci_platform_data.gpio_card_ro = ro;
57 palm27x_mci_platform_data.gpio_power = power;
58 palm27x_mci_platform_data.gpio_power_invert = power_inverted;
60 pxa_set_mci_info(&palm27x_mci_platform_data);
64 /******************************************************************************
65 * Power management - standby
66 ******************************************************************************/
67 #if defined(CONFIG_SUSPEND)
68 void __init palm27x_pm_init(unsigned long str_base)
70 static const unsigned long resume[] = {
71 0xe3a00101, /* mov r0, #0x40000000 */
72 0xe380060f, /* orr r0, r0, #0x00f00000 */
73 0xe590f008, /* ldr pc, [r0, #0x08] */
77 * Copy the bootloader.
78 * NOTE: PalmZ72 uses a different wakeup method!
80 memcpy(phys_to_virt(str_base), resume, sizeof(resume));
84 /******************************************************************************
86 ******************************************************************************/
87 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
88 struct pxafb_mode_info palm_320x480_lcd_mode = {
103 struct pxafb_mode_info palm_320x320_lcd_mode = {
118 struct pxafb_mode_info palm_320x320_new_lcd_mode = {
133 static struct pxafb_mach_info palm27x_lcd_screen = {
135 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
138 static int palm27x_lcd_power;
139 static void palm27x_lcd_ctl(int on, struct fb_var_screeninfo *info)
141 gpio_set_value(palm27x_lcd_power, on);
144 void __init palm27x_lcd_init(int power, struct pxafb_mode_info *mode)
146 palm27x_lcd_screen.modes = mode;
148 if (gpio_is_valid(power)) {
149 if (!gpio_request(power, "LCD power")) {
150 pr_err("Palm27x: failed to claim lcd power gpio!\n");
153 if (!gpio_direction_output(power, 1)) {
154 pr_err("Palm27x: lcd power configuration failed!\n");
157 palm27x_lcd_power = power;
158 palm27x_lcd_screen.pxafb_lcd_power = palm27x_lcd_ctl;
161 set_pxa_fb_info(&palm27x_lcd_screen);
165 /******************************************************************************
167 ******************************************************************************/
168 #if defined(CONFIG_USB_GADGET_PXA27X) || \
169 defined(CONFIG_USB_GADGET_PXA27X_MODULE)
170 static struct gpio_vbus_mach_info palm27x_udc_info = {
171 .gpio_vbus_inverted = 1,
174 static struct platform_device palm27x_gpio_vbus = {
178 .platform_data = &palm27x_udc_info,
182 void __init palm27x_udc_init(int vbus, int pullup, int vbus_inverted)
184 palm27x_udc_info.gpio_vbus = vbus;
185 palm27x_udc_info.gpio_pullup = pullup;
187 palm27x_udc_info.gpio_vbus_inverted = vbus_inverted;
189 if (!gpio_request(pullup, "USB Pullup")) {
190 gpio_direction_output(pullup,
191 palm27x_udc_info.gpio_vbus_inverted);
196 platform_device_register(&palm27x_gpio_vbus);
200 /******************************************************************************
202 ******************************************************************************/
203 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
204 static struct pxaficp_platform_data palm27x_ficp_platform_data = {
205 .transceiver_cap = IR_SIRMODE | IR_OFF,
208 void __init palm27x_irda_init(int pwdn)
210 palm27x_ficp_platform_data.gpio_pwdown = pwdn;
211 pxa_set_ficp_info(&palm27x_ficp_platform_data);
215 /******************************************************************************
216 * WM97xx audio, battery
217 ******************************************************************************/
218 #if defined(CONFIG_TOUCHSCREEN_WM97XX) || \
219 defined(CONFIG_TOUCHSCREEN_WM97XX_MODULE)
220 static struct wm97xx_batt_pdata palm27x_batt_pdata = {
221 .batt_aux = WM97XX_AUX_ID3,
222 .temp_aux = WM97XX_AUX_ID2,
228 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
229 .batt_name = "main-batt",
232 static struct wm97xx_pdata palm27x_wm97xx_pdata = {
233 .batt_pdata = &palm27x_batt_pdata,
236 static pxa2xx_audio_ops_t palm27x_ac97_pdata = {
237 .codec_pdata = { &palm27x_wm97xx_pdata, },
240 static struct palm27x_asoc_info palm27x_asoc_pdata = {
244 static struct platform_device palm27x_asoc = {
245 .name = "palm27x-asoc",
248 .platform_data = &palm27x_asoc_pdata,
252 void __init palm27x_ac97_init(int minv, int maxv, int jack, int reset)
254 palm27x_ac97_pdata.reset_gpio = reset;
255 palm27x_asoc_pdata.jack_gpio = jack;
257 if (minv < 0 || maxv < 0) {
258 palm27x_ac97_pdata.codec_pdata[0] = NULL;
259 pxa_set_ac97_info(&palm27x_ac97_pdata);
261 palm27x_batt_pdata.min_voltage = minv,
262 palm27x_batt_pdata.max_voltage = maxv,
264 pxa_set_ac97_info(&palm27x_ac97_pdata);
265 platform_device_register(&palm27x_asoc);
270 /******************************************************************************
272 ******************************************************************************/
273 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
274 static int palm_bl_power;
275 static int palm_lcd_power;
277 static int palm27x_backlight_init(struct device *dev)
281 ret = gpio_request(palm_bl_power, "BL POWER");
284 ret = gpio_direction_output(palm_bl_power, 0);
288 if (gpio_is_valid(palm_lcd_power)) {
289 ret = gpio_request(palm_lcd_power, "LCD POWER");
292 ret = gpio_direction_output(palm_lcd_power, 0);
299 gpio_free(palm_lcd_power);
301 gpio_free(palm_bl_power);
306 static int palm27x_backlight_notify(struct device *dev, int brightness)
308 gpio_set_value(palm_bl_power, brightness);
309 if (gpio_is_valid(palm_lcd_power))
310 gpio_set_value(palm_lcd_power, brightness);
314 static void palm27x_backlight_exit(struct device *dev)
316 gpio_free(palm_bl_power);
317 if (gpio_is_valid(palm_lcd_power))
318 gpio_free(palm_lcd_power);
321 static struct platform_pwm_backlight_data palm27x_backlight_data = {
323 .max_brightness = 0xfe,
324 .dft_brightness = 0x7e,
325 .pwm_period_ns = 3500 * 1024,
326 .init = palm27x_backlight_init,
327 .notify = palm27x_backlight_notify,
328 .exit = palm27x_backlight_exit,
331 static struct platform_device palm27x_backlight = {
332 .name = "pwm-backlight",
334 .parent = &pxa27x_device_pwm0.dev,
335 .platform_data = &palm27x_backlight_data,
339 void __init palm27x_pwm_init(int bl, int lcd)
342 palm_lcd_power = lcd;
343 platform_device_register(&palm27x_backlight);
347 /******************************************************************************
349 ******************************************************************************/
350 #if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
351 static int palm_ac_state;
352 static int palm_usb_state;
354 static int palm27x_power_supply_init(struct device *dev)
358 ret = gpio_request(palm_ac_state, "AC state");
361 ret = gpio_direction_input(palm_ac_state);
365 if (gpio_is_valid(palm_usb_state)) {
366 ret = gpio_request(palm_usb_state, "USB state");
369 ret = gpio_direction_input(palm_usb_state);
376 gpio_free(palm_usb_state);
378 gpio_free(palm_ac_state);
383 static void palm27x_power_supply_exit(struct device *dev)
385 gpio_free(palm_usb_state);
386 gpio_free(palm_ac_state);
389 static int palm27x_is_ac_online(void)
391 return gpio_get_value(palm_ac_state);
394 static int palm27x_is_usb_online(void)
396 return !gpio_get_value(palm_usb_state);
398 static char *palm27x_supplicants[] = {
402 static struct pda_power_pdata palm27x_ps_info = {
403 .init = palm27x_power_supply_init,
404 .exit = palm27x_power_supply_exit,
405 .is_ac_online = palm27x_is_ac_online,
406 .is_usb_online = palm27x_is_usb_online,
407 .supplied_to = palm27x_supplicants,
408 .num_supplicants = ARRAY_SIZE(palm27x_supplicants),
411 static struct platform_device palm27x_power_supply = {
415 .platform_data = &palm27x_ps_info,
419 void __init palm27x_power_init(int ac, int usb)
422 palm_usb_state = usb;
423 platform_device_register(&palm27x_power_supply);
427 /******************************************************************************
428 * Core power regulator
429 ******************************************************************************/
430 #if defined(CONFIG_REGULATOR_MAX1586) || \
431 defined(CONFIG_REGULATOR_MAX1586_MODULE)
432 static struct regulator_consumer_supply palm27x_max1587a_consumers[] = {
434 .supply = "vcc_core",
438 static struct regulator_init_data palm27x_max1587a_v3_info = {
440 .name = "vcc_core range",
444 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
446 .consumer_supplies = palm27x_max1587a_consumers,
447 .num_consumer_supplies = ARRAY_SIZE(palm27x_max1587a_consumers),
450 static struct max1586_subdev_data palm27x_max1587a_subdevs[] = {
454 .platform_data = &palm27x_max1587a_v3_info,
458 static struct max1586_platform_data palm27x_max1587a_info = {
459 .subdevs = palm27x_max1587a_subdevs,
460 .num_subdevs = ARRAY_SIZE(palm27x_max1587a_subdevs),
461 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
464 static struct i2c_board_info __initdata palm27x_pi2c_board_info[] = {
466 I2C_BOARD_INFO("max1586", 0x14),
467 .platform_data = &palm27x_max1587a_info,
471 static struct i2c_pxa_platform_data palm27x_i2c_power_info = {
475 void __init palm27x_pmic_init(void)
477 i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info));
478 pxa27x_set_i2c_power_info(&palm27x_i2c_power_info);