2 * Common code for Palm LD, T5, TX, Z72
4 * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/platform_device.h>
13 #include <linux/delay.h>
14 #include <linux/irq.h>
15 #include <linux/gpio_keys.h>
16 #include <linux/input.h>
17 #include <linux/pda_power.h>
18 #include <linux/pwm_backlight.h>
19 #include <linux/gpio.h>
20 #include <linux/wm97xx.h>
21 #include <linux/power_supply.h>
22 #include <linux/usb/gpio_vbus.h>
23 #include <linux/regulator/max1586.h>
24 #include <linux/i2c/pxa-i2c.h>
26 #include <asm/mach-types.h>
27 #include <asm/mach/arch.h>
28 #include <asm/mach/map.h>
30 #include <mach/pxa27x.h>
31 #include <mach/audio.h>
32 #include <linux/platform_data/mmc-pxamci.h>
33 #include <linux/platform_data/video-pxafb.h>
34 #include <linux/platform_data/irda-pxaficp.h>
36 #include <linux/platform_data/asoc-palm27x.h>
37 #include <mach/palm27x.h>
42 /******************************************************************************
43 * SD/MMC card controller
44 ******************************************************************************/
45 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
46 static struct pxamci_platform_data palm27x_mci_platform_data
= {
47 .ocr_mask
= MMC_VDD_32_33
| MMC_VDD_33_34
,
48 .detect_delay_ms
= 200,
51 void __init
palm27x_mmc_init(int detect
, int ro
, int power
,
54 palm27x_mci_platform_data
.gpio_card_detect
= detect
;
55 palm27x_mci_platform_data
.gpio_card_ro
= ro
;
56 palm27x_mci_platform_data
.gpio_power
= power
;
57 palm27x_mci_platform_data
.gpio_power_invert
= power_inverted
;
59 pxa_set_mci_info(&palm27x_mci_platform_data
);
63 /******************************************************************************
64 * Power management - standby
65 ******************************************************************************/
66 #if defined(CONFIG_SUSPEND)
67 void __init
palm27x_pm_init(unsigned long str_base
)
69 static const unsigned long resume
[] = {
70 0xe3a00101, /* mov r0, #0x40000000 */
71 0xe380060f, /* orr r0, r0, #0x00f00000 */
72 0xe590f008, /* ldr pc, [r0, #0x08] */
76 * Copy the bootloader.
77 * NOTE: PalmZ72 uses a different wakeup method!
79 memcpy(phys_to_virt(str_base
), resume
, sizeof(resume
));
83 /******************************************************************************
85 ******************************************************************************/
86 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
87 struct pxafb_mode_info palm_320x480_lcd_mode
= {
102 struct pxafb_mode_info palm_320x320_lcd_mode
= {
117 struct pxafb_mode_info palm_320x320_new_lcd_mode
= {
132 static struct pxafb_mach_info palm27x_lcd_screen
= {
134 .lcd_conn
= LCD_COLOR_TFT_16BPP
| LCD_PCLK_EDGE_FALL
,
137 static int palm27x_lcd_power
;
138 static void palm27x_lcd_ctl(int on
, struct fb_var_screeninfo
*info
)
140 gpio_set_value(palm27x_lcd_power
, on
);
143 void __init
palm27x_lcd_init(int power
, struct pxafb_mode_info
*mode
)
145 palm27x_lcd_screen
.modes
= mode
;
147 if (gpio_is_valid(power
)) {
148 if (!gpio_request(power
, "LCD power")) {
149 pr_err("Palm27x: failed to claim lcd power gpio!\n");
152 if (!gpio_direction_output(power
, 1)) {
153 pr_err("Palm27x: lcd power configuration failed!\n");
156 palm27x_lcd_power
= power
;
157 palm27x_lcd_screen
.pxafb_lcd_power
= palm27x_lcd_ctl
;
160 pxa_set_fb_info(NULL
, &palm27x_lcd_screen
);
164 /******************************************************************************
166 ******************************************************************************/
167 #if defined(CONFIG_USB_PXA27X) || \
168 defined(CONFIG_USB_PXA27X_MODULE)
169 static struct gpio_vbus_mach_info palm27x_udc_info
= {
170 .gpio_vbus_inverted
= 1,
173 static struct platform_device palm27x_gpio_vbus
= {
177 .platform_data
= &palm27x_udc_info
,
181 void __init
palm27x_udc_init(int vbus
, int pullup
, int vbus_inverted
)
183 palm27x_udc_info
.gpio_vbus
= vbus
;
184 palm27x_udc_info
.gpio_pullup
= pullup
;
186 palm27x_udc_info
.gpio_vbus_inverted
= vbus_inverted
;
188 if (!gpio_request(pullup
, "USB Pullup")) {
189 gpio_direction_output(pullup
,
190 palm27x_udc_info
.gpio_vbus_inverted
);
195 platform_device_register(&palm27x_gpio_vbus
);
199 /******************************************************************************
201 ******************************************************************************/
202 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
203 static struct pxaficp_platform_data palm27x_ficp_platform_data
= {
204 .transceiver_cap
= IR_SIRMODE
| IR_OFF
,
207 void __init
palm27x_irda_init(int pwdn
)
209 palm27x_ficp_platform_data
.gpio_pwdown
= pwdn
;
210 pxa_set_ficp_info(&palm27x_ficp_platform_data
);
214 /******************************************************************************
215 * WM97xx audio, battery
216 ******************************************************************************/
217 #if defined(CONFIG_TOUCHSCREEN_WM97XX) || \
218 defined(CONFIG_TOUCHSCREEN_WM97XX_MODULE)
219 static struct wm97xx_batt_pdata palm27x_batt_pdata
= {
220 .batt_aux
= WM97XX_AUX_ID3
,
221 .temp_aux
= WM97XX_AUX_ID2
,
227 .batt_tech
= POWER_SUPPLY_TECHNOLOGY_LIPO
,
228 .batt_name
= "main-batt",
231 static struct wm97xx_pdata palm27x_wm97xx_pdata
= {
232 .batt_pdata
= &palm27x_batt_pdata
,
235 static pxa2xx_audio_ops_t palm27x_ac97_pdata
= {
236 .codec_pdata
= { &palm27x_wm97xx_pdata
, },
239 static struct palm27x_asoc_info palm27x_asoc_pdata
= {
243 static struct platform_device palm27x_asoc
= {
244 .name
= "palm27x-asoc",
247 .platform_data
= &palm27x_asoc_pdata
,
251 void __init
palm27x_ac97_init(int minv
, int maxv
, int jack
, int reset
)
253 palm27x_ac97_pdata
.reset_gpio
= reset
;
254 palm27x_asoc_pdata
.jack_gpio
= jack
;
256 if (minv
< 0 || maxv
< 0) {
257 palm27x_ac97_pdata
.codec_pdata
[0] = NULL
;
258 pxa_set_ac97_info(&palm27x_ac97_pdata
);
260 palm27x_batt_pdata
.min_voltage
= minv
,
261 palm27x_batt_pdata
.max_voltage
= maxv
,
263 pxa_set_ac97_info(&palm27x_ac97_pdata
);
264 platform_device_register(&palm27x_asoc
);
269 /******************************************************************************
271 ******************************************************************************/
272 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
273 static int palm_bl_power
;
274 static int palm_lcd_power
;
276 static int palm27x_backlight_init(struct device
*dev
)
280 ret
= gpio_request(palm_bl_power
, "BL POWER");
283 ret
= gpio_direction_output(palm_bl_power
, 0);
287 if (gpio_is_valid(palm_lcd_power
)) {
288 ret
= gpio_request(palm_lcd_power
, "LCD POWER");
291 ret
= gpio_direction_output(palm_lcd_power
, 0);
298 gpio_free(palm_lcd_power
);
300 gpio_free(palm_bl_power
);
305 static int palm27x_backlight_notify(struct device
*dev
, int brightness
)
307 gpio_set_value(palm_bl_power
, brightness
);
308 if (gpio_is_valid(palm_lcd_power
))
309 gpio_set_value(palm_lcd_power
, brightness
);
313 static void palm27x_backlight_exit(struct device
*dev
)
315 gpio_free(palm_bl_power
);
316 if (gpio_is_valid(palm_lcd_power
))
317 gpio_free(palm_lcd_power
);
320 static struct platform_pwm_backlight_data palm27x_backlight_data
= {
322 .max_brightness
= 0xfe,
323 .dft_brightness
= 0x7e,
324 .pwm_period_ns
= 3500 * 1024,
325 .init
= palm27x_backlight_init
,
326 .notify
= palm27x_backlight_notify
,
327 .exit
= palm27x_backlight_exit
,
330 static struct platform_device palm27x_backlight
= {
331 .name
= "pwm-backlight",
333 .parent
= &pxa27x_device_pwm0
.dev
,
334 .platform_data
= &palm27x_backlight_data
,
338 void __init
palm27x_pwm_init(int bl
, int lcd
)
341 palm_lcd_power
= lcd
;
342 platform_device_register(&palm27x_backlight
);
346 /******************************************************************************
348 ******************************************************************************/
349 #if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
350 static int palm_ac_state
;
351 static int palm_usb_state
;
353 static int palm27x_power_supply_init(struct device
*dev
)
357 ret
= gpio_request(palm_ac_state
, "AC state");
360 ret
= gpio_direction_input(palm_ac_state
);
364 if (gpio_is_valid(palm_usb_state
)) {
365 ret
= gpio_request(palm_usb_state
, "USB state");
368 ret
= gpio_direction_input(palm_usb_state
);
375 gpio_free(palm_usb_state
);
377 gpio_free(palm_ac_state
);
382 static void palm27x_power_supply_exit(struct device
*dev
)
384 gpio_free(palm_usb_state
);
385 gpio_free(palm_ac_state
);
388 static int palm27x_is_ac_online(void)
390 return gpio_get_value(palm_ac_state
);
393 static int palm27x_is_usb_online(void)
395 return !gpio_get_value(palm_usb_state
);
397 static char *palm27x_supplicants
[] = {
401 static struct pda_power_pdata palm27x_ps_info
= {
402 .init
= palm27x_power_supply_init
,
403 .exit
= palm27x_power_supply_exit
,
404 .is_ac_online
= palm27x_is_ac_online
,
405 .is_usb_online
= palm27x_is_usb_online
,
406 .supplied_to
= palm27x_supplicants
,
407 .num_supplicants
= ARRAY_SIZE(palm27x_supplicants
),
410 static struct platform_device palm27x_power_supply
= {
414 .platform_data
= &palm27x_ps_info
,
418 void __init
palm27x_power_init(int ac
, int usb
)
421 palm_usb_state
= usb
;
422 platform_device_register(&palm27x_power_supply
);
426 /******************************************************************************
427 * Core power regulator
428 ******************************************************************************/
429 #if defined(CONFIG_REGULATOR_MAX1586) || \
430 defined(CONFIG_REGULATOR_MAX1586_MODULE)
431 static struct regulator_consumer_supply palm27x_max1587a_consumers
[] = {
432 REGULATOR_SUPPLY("vcc_core", NULL
),
435 static struct regulator_init_data palm27x_max1587a_v3_info
= {
437 .name
= "vcc_core range",
441 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
443 .consumer_supplies
= palm27x_max1587a_consumers
,
444 .num_consumer_supplies
= ARRAY_SIZE(palm27x_max1587a_consumers
),
447 static struct max1586_subdev_data palm27x_max1587a_subdevs
[] = {
451 .platform_data
= &palm27x_max1587a_v3_info
,
455 static struct max1586_platform_data palm27x_max1587a_info
= {
456 .subdevs
= palm27x_max1587a_subdevs
,
457 .num_subdevs
= ARRAY_SIZE(palm27x_max1587a_subdevs
),
458 .v3_gain
= MAX1586_GAIN_R24_3k32
, /* 730..1550 mV */
461 static struct i2c_board_info __initdata palm27x_pi2c_board_info
[] = {
463 I2C_BOARD_INFO("max1586", 0x14),
464 .platform_data
= &palm27x_max1587a_info
,
468 static struct i2c_pxa_platform_data palm27x_i2c_power_info
= {
472 void __init
palm27x_pmic_init(void)
474 i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info
));
475 pxa27x_set_i2c_power_info(&palm27x_i2c_power_info
);