1 // SPDX-License-Identifier: GPL-2.0-only
3 * Common code for Palm LD, T5, TX, Z72
5 * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com>
8 #include <linux/platform_device.h>
9 #include <linux/delay.h>
10 #include <linux/irq.h>
11 #include <linux/gpio_keys.h>
12 #include <linux/input.h>
13 #include <linux/pda_power.h>
14 #include <linux/pwm.h>
15 #include <linux/pwm_backlight.h>
16 #include <linux/gpio/machine.h>
17 #include <linux/gpio.h>
18 #include <linux/wm97xx.h>
19 #include <linux/power_supply.h>
20 #include <linux/regulator/max1586.h>
21 #include <linux/platform_data/i2c-pxa.h>
23 #include <asm/mach-types.h>
24 #include <asm/mach/arch.h>
25 #include <asm/mach/map.h>
28 #include <linux/platform_data/asoc-pxa.h>
29 #include <linux/platform_data/mmc-pxamci.h>
30 #include <linux/platform_data/video-pxafb.h>
31 #include <linux/platform_data/irda-pxaficp.h>
33 #include <linux/platform_data/asoc-palm27x.h>
39 /******************************************************************************
40 * SD/MMC card controller
41 ******************************************************************************/
42 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
43 static struct pxamci_platform_data palm27x_mci_platform_data = {
44 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
45 .detect_delay_ms = 200,
48 void __init palm27x_mmc_init(struct gpiod_lookup_table *gtable)
51 gpiod_add_lookup_table(gtable);
52 pxa_set_mci_info(&palm27x_mci_platform_data);
56 /******************************************************************************
57 * Power management - standby
58 ******************************************************************************/
59 #if defined(CONFIG_SUSPEND)
60 void __init palm27x_pm_init(unsigned long str_base)
62 static const unsigned long resume[] = {
63 0xe3a00101, /* mov r0, #0x40000000 */
64 0xe380060f, /* orr r0, r0, #0x00f00000 */
65 0xe590f008, /* ldr pc, [r0, #0x08] */
69 * Copy the bootloader.
70 * NOTE: PalmZ72 uses a different wakeup method!
72 memcpy(phys_to_virt(str_base), resume, sizeof(resume));
76 /******************************************************************************
78 ******************************************************************************/
79 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
80 struct pxafb_mode_info palm_320x480_lcd_mode = {
95 struct pxafb_mode_info palm_320x320_lcd_mode = {
110 struct pxafb_mode_info palm_320x320_new_lcd_mode = {
125 static struct pxafb_mach_info palm27x_lcd_screen = {
127 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
130 static int palm27x_lcd_power;
131 static void palm27x_lcd_ctl(int on, struct fb_var_screeninfo *info)
133 gpio_set_value(palm27x_lcd_power, on);
136 void __init palm27x_lcd_init(int power, struct pxafb_mode_info *mode)
138 palm27x_lcd_screen.modes = mode;
140 if (gpio_is_valid(power)) {
141 if (!gpio_request(power, "LCD power")) {
142 pr_err("Palm27x: failed to claim lcd power gpio!\n");
145 if (!gpio_direction_output(power, 1)) {
146 pr_err("Palm27x: lcd power configuration failed!\n");
149 palm27x_lcd_power = power;
150 palm27x_lcd_screen.pxafb_lcd_power = palm27x_lcd_ctl;
153 pxa_set_fb_info(NULL, &palm27x_lcd_screen);
157 /******************************************************************************
159 ******************************************************************************/
160 #if defined(CONFIG_USB_PXA27X) || \
161 defined(CONFIG_USB_PXA27X_MODULE)
163 /* The actual GPIO offsets get filled in in the palm27x_udc_init() call */
164 static struct gpiod_lookup_table palm27x_udc_gpiod_table = {
165 .dev_id = "gpio-vbus",
167 GPIO_LOOKUP("gpio-pxa", 0,
168 "vbus", GPIO_ACTIVE_HIGH),
169 GPIO_LOOKUP("gpio-pxa", 0,
170 "pullup", GPIO_ACTIVE_HIGH),
175 static struct platform_device palm27x_gpio_vbus = {
180 void __init palm27x_udc_init(int vbus, int pullup, int vbus_inverted)
182 palm27x_udc_gpiod_table.table[0].chip_hwnum = vbus;
183 palm27x_udc_gpiod_table.table[1].chip_hwnum = pullup;
185 palm27x_udc_gpiod_table.table[0].flags = GPIO_ACTIVE_LOW;
187 gpiod_add_lookup_table(&palm27x_udc_gpiod_table);
188 platform_device_register(&palm27x_gpio_vbus);
192 /******************************************************************************
194 ******************************************************************************/
195 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
196 static struct pxaficp_platform_data palm27x_ficp_platform_data = {
197 .transceiver_cap = IR_SIRMODE | IR_OFF,
200 void __init palm27x_irda_init(int pwdn)
202 palm27x_ficp_platform_data.gpio_pwdown = pwdn;
203 pxa_set_ficp_info(&palm27x_ficp_platform_data);
207 /******************************************************************************
208 * WM97xx audio, battery
209 ******************************************************************************/
210 #if defined(CONFIG_TOUCHSCREEN_WM97XX) || \
211 defined(CONFIG_TOUCHSCREEN_WM97XX_MODULE)
212 static struct wm97xx_batt_pdata palm27x_batt_pdata = {
213 .batt_aux = WM97XX_AUX_ID3,
214 .temp_aux = WM97XX_AUX_ID2,
219 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
220 .batt_name = "main-batt",
223 static struct wm97xx_pdata palm27x_wm97xx_pdata = {
224 .batt_pdata = &palm27x_batt_pdata,
227 static pxa2xx_audio_ops_t palm27x_ac97_pdata = {
228 .codec_pdata = { &palm27x_wm97xx_pdata, },
231 static struct palm27x_asoc_info palm27x_asoc_pdata = {
235 static struct platform_device palm27x_asoc = {
236 .name = "palm27x-asoc",
239 .platform_data = &palm27x_asoc_pdata,
243 void __init palm27x_ac97_init(int minv, int maxv, int jack, int reset)
245 palm27x_ac97_pdata.reset_gpio = reset;
246 palm27x_asoc_pdata.jack_gpio = jack;
248 if (minv < 0 || maxv < 0) {
249 palm27x_ac97_pdata.codec_pdata[0] = NULL;
250 pxa_set_ac97_info(&palm27x_ac97_pdata);
252 palm27x_batt_pdata.min_voltage = minv,
253 palm27x_batt_pdata.max_voltage = maxv,
255 pxa_set_ac97_info(&palm27x_ac97_pdata);
256 platform_device_register(&palm27x_asoc);
261 /******************************************************************************
263 ******************************************************************************/
264 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
265 static struct pwm_lookup palm27x_pwm_lookup[] = {
266 PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight.0", NULL, 3500 * 1024,
267 PWM_POLARITY_NORMAL),
270 static int palm_bl_power;
271 static int palm_lcd_power;
273 static int palm27x_backlight_init(struct device *dev)
277 ret = gpio_request(palm_bl_power, "BL POWER");
280 ret = gpio_direction_output(palm_bl_power, 0);
284 if (gpio_is_valid(palm_lcd_power)) {
285 ret = gpio_request(palm_lcd_power, "LCD POWER");
288 ret = gpio_direction_output(palm_lcd_power, 0);
295 gpio_free(palm_lcd_power);
297 gpio_free(palm_bl_power);
302 static int palm27x_backlight_notify(struct device *dev, int brightness)
304 gpio_set_value(palm_bl_power, brightness);
305 if (gpio_is_valid(palm_lcd_power))
306 gpio_set_value(palm_lcd_power, brightness);
310 static void palm27x_backlight_exit(struct device *dev)
312 gpio_free(palm_bl_power);
313 if (gpio_is_valid(palm_lcd_power))
314 gpio_free(palm_lcd_power);
317 static struct platform_pwm_backlight_data palm27x_backlight_data = {
318 .max_brightness = 0xfe,
319 .dft_brightness = 0x7e,
320 .init = palm27x_backlight_init,
321 .notify = palm27x_backlight_notify,
322 .exit = palm27x_backlight_exit,
325 static struct platform_device palm27x_backlight = {
326 .name = "pwm-backlight",
328 .parent = &pxa27x_device_pwm0.dev,
329 .platform_data = &palm27x_backlight_data,
333 void __init palm27x_pwm_init(int bl, int lcd)
336 palm_lcd_power = lcd;
337 pwm_add_table(palm27x_pwm_lookup, ARRAY_SIZE(palm27x_pwm_lookup));
338 platform_device_register(&palm27x_backlight);
342 /******************************************************************************
344 ******************************************************************************/
345 #if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
346 static int palm_ac_state;
347 static int palm_usb_state;
349 static int palm27x_power_supply_init(struct device *dev)
353 ret = gpio_request(palm_ac_state, "AC state");
356 ret = gpio_direction_input(palm_ac_state);
360 if (gpio_is_valid(palm_usb_state)) {
361 ret = gpio_request(palm_usb_state, "USB state");
364 ret = gpio_direction_input(palm_usb_state);
371 gpio_free(palm_usb_state);
373 gpio_free(palm_ac_state);
378 static void palm27x_power_supply_exit(struct device *dev)
380 gpio_free(palm_usb_state);
381 gpio_free(palm_ac_state);
384 static int palm27x_is_ac_online(void)
386 return gpio_get_value(palm_ac_state);
389 static int palm27x_is_usb_online(void)
391 return !gpio_get_value(palm_usb_state);
393 static char *palm27x_supplicants[] = {
397 static struct pda_power_pdata palm27x_ps_info = {
398 .init = palm27x_power_supply_init,
399 .exit = palm27x_power_supply_exit,
400 .is_ac_online = palm27x_is_ac_online,
401 .is_usb_online = palm27x_is_usb_online,
402 .supplied_to = palm27x_supplicants,
403 .num_supplicants = ARRAY_SIZE(palm27x_supplicants),
406 static struct platform_device palm27x_power_supply = {
410 .platform_data = &palm27x_ps_info,
414 void __init palm27x_power_init(int ac, int usb)
417 palm_usb_state = usb;
418 platform_device_register(&palm27x_power_supply);
422 /******************************************************************************
423 * Core power regulator
424 ******************************************************************************/
425 #if defined(CONFIG_REGULATOR_MAX1586) || \
426 defined(CONFIG_REGULATOR_MAX1586_MODULE)
427 static struct regulator_consumer_supply palm27x_max1587a_consumers[] = {
428 REGULATOR_SUPPLY("vcc_core", NULL),
431 static struct regulator_init_data palm27x_max1587a_v3_info = {
433 .name = "vcc_core range",
437 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
439 .consumer_supplies = palm27x_max1587a_consumers,
440 .num_consumer_supplies = ARRAY_SIZE(palm27x_max1587a_consumers),
443 static struct max1586_subdev_data palm27x_max1587a_subdevs[] = {
447 .platform_data = &palm27x_max1587a_v3_info,
451 static struct max1586_platform_data palm27x_max1587a_info = {
452 .subdevs = palm27x_max1587a_subdevs,
453 .num_subdevs = ARRAY_SIZE(palm27x_max1587a_subdevs),
454 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
457 static struct i2c_board_info __initdata palm27x_pi2c_board_info[] = {
459 I2C_BOARD_INFO("max1586", 0x14),
460 .platform_data = &palm27x_max1587a_info,
464 static struct i2c_pxa_platform_data palm27x_i2c_power_info = {
468 void __init palm27x_pmic_init(void)
470 i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info));
471 pxa27x_set_i2c_power_info(&palm27x_i2c_power_info);