Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Common code for Palm LD, T5, TX, Z72
0004  *
0005  * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com>
0006  */
0007 
0008 #include <linux/platform_device.h>
0009 #include <linux/delay.h>
0010 #include <linux/irq.h>
0011 #include <linux/gpio_keys.h>
0012 #include <linux/input.h>
0013 #include <linux/pda_power.h>
0014 #include <linux/pwm.h>
0015 #include <linux/pwm_backlight.h>
0016 #include <linux/gpio/machine.h>
0017 #include <linux/gpio.h>
0018 #include <linux/wm97xx.h>
0019 #include <linux/power_supply.h>
0020 #include <linux/regulator/max1586.h>
0021 #include <linux/platform_data/i2c-pxa.h>
0022 
0023 #include <asm/mach-types.h>
0024 #include <asm/mach/arch.h>
0025 #include <asm/mach/map.h>
0026 
0027 #include "pxa27x.h"
0028 #include <linux/platform_data/asoc-pxa.h>
0029 #include <linux/platform_data/mmc-pxamci.h>
0030 #include <linux/platform_data/video-pxafb.h>
0031 #include <linux/platform_data/irda-pxaficp.h>
0032 #include "udc.h"
0033 #include <linux/platform_data/asoc-palm27x.h>
0034 #include "palm27x.h"
0035 
0036 #include "generic.h"
0037 #include "devices.h"
0038 
0039 /******************************************************************************
0040  * SD/MMC card controller
0041  ******************************************************************************/
0042 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
0043 static struct pxamci_platform_data palm27x_mci_platform_data = {
0044     .ocr_mask       = MMC_VDD_32_33 | MMC_VDD_33_34,
0045     .detect_delay_ms    = 200,
0046 };
0047 
0048 void __init palm27x_mmc_init(struct gpiod_lookup_table *gtable)
0049 {
0050     if (gtable)
0051         gpiod_add_lookup_table(gtable);
0052     pxa_set_mci_info(&palm27x_mci_platform_data);
0053 }
0054 #endif
0055 
0056 /******************************************************************************
0057  * Power management - standby
0058  ******************************************************************************/
0059 #if defined(CONFIG_SUSPEND)
0060 void __init palm27x_pm_init(unsigned long str_base)
0061 {
0062     static const unsigned long resume[] = {
0063         0xe3a00101, /* mov  r0, #0x40000000 */
0064         0xe380060f, /* orr  r0, r0, #0x00f00000 */
0065         0xe590f008, /* ldr  pc, [r0, #0x08] */
0066     };
0067 
0068     /*
0069      * Copy the bootloader.
0070      * NOTE: PalmZ72 uses a different wakeup method!
0071      */
0072     memcpy(phys_to_virt(str_base), resume, sizeof(resume));
0073 }
0074 #endif
0075 
0076 /******************************************************************************
0077  * Framebuffer
0078  ******************************************************************************/
0079 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
0080 struct pxafb_mode_info palm_320x480_lcd_mode = {
0081     .pixclock   = 57692,
0082     .xres       = 320,
0083     .yres       = 480,
0084     .bpp        = 16,
0085 
0086     .left_margin    = 32,
0087     .right_margin   = 1,
0088     .upper_margin   = 7,
0089     .lower_margin   = 1,
0090 
0091     .hsync_len  = 4,
0092     .vsync_len  = 1,
0093 };
0094 
0095 struct pxafb_mode_info palm_320x320_lcd_mode = {
0096     .pixclock   = 115384,
0097     .xres       = 320,
0098     .yres       = 320,
0099     .bpp        = 16,
0100 
0101     .left_margin    = 27,
0102     .right_margin   = 7,
0103     .upper_margin   = 7,
0104     .lower_margin   = 8,
0105 
0106     .hsync_len  = 6,
0107     .vsync_len  = 1,
0108 };
0109 
0110 struct pxafb_mode_info palm_320x320_new_lcd_mode = {
0111     .pixclock   = 86538,
0112     .xres       = 320,
0113     .yres       = 320,
0114     .bpp        = 16,
0115 
0116     .left_margin    = 20,
0117     .right_margin   = 8,
0118     .upper_margin   = 8,
0119     .lower_margin   = 5,
0120 
0121     .hsync_len  = 4,
0122     .vsync_len  = 1,
0123 };
0124 
0125 static struct pxafb_mach_info palm27x_lcd_screen = {
0126     .num_modes  = 1,
0127     .lcd_conn   = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
0128 };
0129 
0130 static int palm27x_lcd_power;
0131 static void palm27x_lcd_ctl(int on, struct fb_var_screeninfo *info)
0132 {
0133     gpio_set_value(palm27x_lcd_power, on);
0134 }
0135 
0136 void __init palm27x_lcd_init(int power, struct pxafb_mode_info *mode)
0137 {
0138     palm27x_lcd_screen.modes = mode;
0139 
0140     if (gpio_is_valid(power)) {
0141         if (!gpio_request(power, "LCD power")) {
0142             pr_err("Palm27x: failed to claim lcd power gpio!\n");
0143             return;
0144         }
0145         if (!gpio_direction_output(power, 1)) {
0146             pr_err("Palm27x: lcd power configuration failed!\n");
0147             return;
0148         }
0149         palm27x_lcd_power = power;
0150         palm27x_lcd_screen.pxafb_lcd_power = palm27x_lcd_ctl;
0151     }
0152 
0153     pxa_set_fb_info(NULL, &palm27x_lcd_screen);
0154 }
0155 #endif
0156 
0157 /******************************************************************************
0158  * USB Gadget
0159  ******************************************************************************/
0160 #if defined(CONFIG_USB_PXA27X) || \
0161     defined(CONFIG_USB_PXA27X_MODULE)
0162 
0163 /* The actual GPIO offsets get filled in in the palm27x_udc_init() call */
0164 static struct gpiod_lookup_table palm27x_udc_gpiod_table = {
0165     .dev_id = "gpio-vbus",
0166     .table = {
0167         GPIO_LOOKUP("gpio-pxa", 0,
0168                 "vbus", GPIO_ACTIVE_HIGH),
0169         GPIO_LOOKUP("gpio-pxa", 0,
0170                 "pullup", GPIO_ACTIVE_HIGH),
0171         { },
0172     },
0173 };
0174 
0175 static struct platform_device palm27x_gpio_vbus = {
0176     .name   = "gpio-vbus",
0177     .id = -1,
0178 };
0179 
0180 void __init palm27x_udc_init(int vbus, int pullup, int vbus_inverted)
0181 {
0182     palm27x_udc_gpiod_table.table[0].chip_hwnum = vbus;
0183     palm27x_udc_gpiod_table.table[1].chip_hwnum = pullup;
0184     if (vbus_inverted)
0185         palm27x_udc_gpiod_table.table[0].flags = GPIO_ACTIVE_LOW;
0186 
0187     gpiod_add_lookup_table(&palm27x_udc_gpiod_table);
0188     platform_device_register(&palm27x_gpio_vbus);
0189 }
0190 #endif
0191 
0192 /******************************************************************************
0193  * IrDA
0194  ******************************************************************************/
0195 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
0196 static struct pxaficp_platform_data palm27x_ficp_platform_data = {
0197     .transceiver_cap    = IR_SIRMODE | IR_OFF,
0198 };
0199 
0200 void __init palm27x_irda_init(int pwdn)
0201 {
0202     palm27x_ficp_platform_data.gpio_pwdown = pwdn;
0203     pxa_set_ficp_info(&palm27x_ficp_platform_data);
0204 }
0205 #endif
0206 
0207 /******************************************************************************
0208  * WM97xx audio, battery
0209  ******************************************************************************/
0210 #if defined(CONFIG_TOUCHSCREEN_WM97XX) || \
0211     defined(CONFIG_TOUCHSCREEN_WM97XX_MODULE)
0212 static struct wm97xx_batt_pdata palm27x_batt_pdata = {
0213     .batt_aux   = WM97XX_AUX_ID3,
0214     .temp_aux   = WM97XX_AUX_ID2,
0215     .batt_mult  = 1000,
0216     .batt_div   = 414,
0217     .temp_mult  = 1,
0218     .temp_div   = 1,
0219     .batt_tech  = POWER_SUPPLY_TECHNOLOGY_LIPO,
0220     .batt_name  = "main-batt",
0221 };
0222 
0223 static struct wm97xx_pdata palm27x_wm97xx_pdata = {
0224     .batt_pdata = &palm27x_batt_pdata,
0225 };
0226 
0227 static pxa2xx_audio_ops_t palm27x_ac97_pdata = {
0228     .codec_pdata    = { &palm27x_wm97xx_pdata, },
0229 };
0230 
0231 static struct palm27x_asoc_info palm27x_asoc_pdata = {
0232     .jack_gpio  = -1,
0233 };
0234 
0235 static struct platform_device palm27x_asoc = {
0236     .name = "palm27x-asoc",
0237     .id   = -1,
0238     .dev  = {
0239         .platform_data = &palm27x_asoc_pdata,
0240     },
0241 };
0242 
0243 void __init palm27x_ac97_init(int minv, int maxv, int jack, int reset)
0244 {
0245     palm27x_ac97_pdata.reset_gpio   = reset;
0246     palm27x_asoc_pdata.jack_gpio    = jack;
0247 
0248     if (minv < 0 || maxv < 0) {
0249         palm27x_ac97_pdata.codec_pdata[0] = NULL;
0250         pxa_set_ac97_info(&palm27x_ac97_pdata);
0251     } else {
0252         palm27x_batt_pdata.min_voltage  = minv,
0253         palm27x_batt_pdata.max_voltage  = maxv,
0254 
0255         pxa_set_ac97_info(&palm27x_ac97_pdata);
0256         platform_device_register(&palm27x_asoc);
0257     }
0258 }
0259 #endif
0260 
0261 /******************************************************************************
0262  * Backlight
0263  ******************************************************************************/
0264 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
0265 static struct pwm_lookup palm27x_pwm_lookup[] = {
0266     PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight.0", NULL, 3500 * 1024,
0267            PWM_POLARITY_NORMAL),
0268 };
0269 
0270 static int palm_bl_power;
0271 static int palm_lcd_power;
0272 
0273 static int palm27x_backlight_init(struct device *dev)
0274 {
0275     int ret;
0276 
0277     ret = gpio_request(palm_bl_power, "BL POWER");
0278     if (ret)
0279         goto err;
0280     ret = gpio_direction_output(palm_bl_power, 0);
0281     if (ret)
0282         goto err2;
0283 
0284     if (gpio_is_valid(palm_lcd_power)) {
0285         ret = gpio_request(palm_lcd_power, "LCD POWER");
0286         if (ret)
0287             goto err2;
0288         ret = gpio_direction_output(palm_lcd_power, 0);
0289         if (ret)
0290             goto err3;
0291     }
0292 
0293     return 0;
0294 err3:
0295     gpio_free(palm_lcd_power);
0296 err2:
0297     gpio_free(palm_bl_power);
0298 err:
0299     return ret;
0300 }
0301 
0302 static int palm27x_backlight_notify(struct device *dev, int brightness)
0303 {
0304     gpio_set_value(palm_bl_power, brightness);
0305     if (gpio_is_valid(palm_lcd_power))
0306         gpio_set_value(palm_lcd_power, brightness);
0307     return brightness;
0308 }
0309 
0310 static void palm27x_backlight_exit(struct device *dev)
0311 {
0312     gpio_free(palm_bl_power);
0313     if (gpio_is_valid(palm_lcd_power))
0314         gpio_free(palm_lcd_power);
0315 }
0316 
0317 static struct platform_pwm_backlight_data palm27x_backlight_data = {
0318     .max_brightness = 0xfe,
0319     .dft_brightness = 0x7e,
0320     .init       = palm27x_backlight_init,
0321     .notify     = palm27x_backlight_notify,
0322     .exit       = palm27x_backlight_exit,
0323 };
0324 
0325 static struct platform_device palm27x_backlight = {
0326     .name   = "pwm-backlight",
0327     .dev    = {
0328         .parent     = &pxa27x_device_pwm0.dev,
0329         .platform_data  = &palm27x_backlight_data,
0330     },
0331 };
0332 
0333 void __init palm27x_pwm_init(int bl, int lcd)
0334 {
0335     palm_bl_power   = bl;
0336     palm_lcd_power  = lcd;
0337     pwm_add_table(palm27x_pwm_lookup, ARRAY_SIZE(palm27x_pwm_lookup));
0338     platform_device_register(&palm27x_backlight);
0339 }
0340 #endif
0341 
0342 /******************************************************************************
0343  * Power supply
0344  ******************************************************************************/
0345 #if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
0346 static int palm_ac_state;
0347 static int palm_usb_state;
0348 
0349 static int palm27x_power_supply_init(struct device *dev)
0350 {
0351     int ret;
0352 
0353     ret = gpio_request(palm_ac_state, "AC state");
0354     if (ret)
0355         goto err1;
0356     ret = gpio_direction_input(palm_ac_state);
0357     if (ret)
0358         goto err2;
0359 
0360     if (gpio_is_valid(palm_usb_state)) {
0361         ret = gpio_request(palm_usb_state, "USB state");
0362         if (ret)
0363             goto err2;
0364         ret = gpio_direction_input(palm_usb_state);
0365         if (ret)
0366             goto err3;
0367     }
0368 
0369     return 0;
0370 err3:
0371     gpio_free(palm_usb_state);
0372 err2:
0373     gpio_free(palm_ac_state);
0374 err1:
0375     return ret;
0376 }
0377 
0378 static void palm27x_power_supply_exit(struct device *dev)
0379 {
0380     gpio_free(palm_usb_state);
0381     gpio_free(palm_ac_state);
0382 }
0383 
0384 static int palm27x_is_ac_online(void)
0385 {
0386     return gpio_get_value(palm_ac_state);
0387 }
0388 
0389 static int palm27x_is_usb_online(void)
0390 {
0391     return !gpio_get_value(palm_usb_state);
0392 }
0393 static char *palm27x_supplicants[] = {
0394     "main-battery",
0395 };
0396 
0397 static struct pda_power_pdata palm27x_ps_info = {
0398     .init           = palm27x_power_supply_init,
0399     .exit           = palm27x_power_supply_exit,
0400     .is_ac_online       = palm27x_is_ac_online,
0401     .is_usb_online      = palm27x_is_usb_online,
0402     .supplied_to        = palm27x_supplicants,
0403     .num_supplicants    = ARRAY_SIZE(palm27x_supplicants),
0404 };
0405 
0406 static struct platform_device palm27x_power_supply = {
0407     .name = "pda-power",
0408     .id   = -1,
0409     .dev  = {
0410         .platform_data = &palm27x_ps_info,
0411     },
0412 };
0413 
0414 void __init palm27x_power_init(int ac, int usb)
0415 {
0416     palm_ac_state   = ac;
0417     palm_usb_state  = usb;
0418     platform_device_register(&palm27x_power_supply);
0419 }
0420 #endif
0421 
0422 /******************************************************************************
0423  * Core power regulator
0424  ******************************************************************************/
0425 #if defined(CONFIG_REGULATOR_MAX1586) || \
0426     defined(CONFIG_REGULATOR_MAX1586_MODULE)
0427 static struct regulator_consumer_supply palm27x_max1587a_consumers[] = {
0428     REGULATOR_SUPPLY("vcc_core", NULL),
0429 };
0430 
0431 static struct regulator_init_data palm27x_max1587a_v3_info = {
0432     .constraints = {
0433         .name       = "vcc_core range",
0434         .min_uV     = 900000,
0435         .max_uV     = 1705000,
0436         .always_on  = 1,
0437         .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
0438     },
0439     .consumer_supplies  = palm27x_max1587a_consumers,
0440     .num_consumer_supplies  = ARRAY_SIZE(palm27x_max1587a_consumers),
0441 };
0442 
0443 static struct max1586_subdev_data palm27x_max1587a_subdevs[] = {
0444     {
0445         .name       = "vcc_core",
0446         .id     = MAX1586_V3,
0447         .platform_data  = &palm27x_max1587a_v3_info,
0448     }
0449 };
0450 
0451 static struct max1586_platform_data palm27x_max1587a_info = {
0452     .subdevs     = palm27x_max1587a_subdevs,
0453     .num_subdevs = ARRAY_SIZE(palm27x_max1587a_subdevs),
0454     .v3_gain     = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
0455 };
0456 
0457 static struct i2c_board_info __initdata palm27x_pi2c_board_info[] = {
0458     {
0459         I2C_BOARD_INFO("max1586", 0x14),
0460         .platform_data  = &palm27x_max1587a_info,
0461     },
0462 };
0463 
0464 static struct i2c_pxa_platform_data palm27x_i2c_power_info = {
0465     .use_pio    = 1,
0466 };
0467 
0468 void __init palm27x_pmic_init(void)
0469 {
0470     i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info));
0471     pxa27x_set_i2c_power_info(&palm27x_i2c_power_info);
0472 }
0473 #endif