1/* 2 * Common code for Palm LD, T5, TX, Z72 3 * 4 * Copyright (C) 2010 5 * Marek Vasut <marek.vasut@gmail.com> 6 * 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. 10 * 11 */ 12 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 26#include <asm/mach-types.h> 27#include <asm/mach/arch.h> 28#include <asm/mach/map.h> 29 30#include <mach/pxa27x.h> 31#include <mach/audio.h> 32#include <mach/mmc.h> 33#include <mach/pxafb.h> 34#include <mach/irda.h> 35#include <mach/udc.h> 36#include <mach/palmasoc.h> 37#include <mach/palm27x.h> 38 39#include <plat/i2c.h> 40 41#include "generic.h" 42#include "devices.h" 43 44/****************************************************************************** 45 * SD/MMC card controller 46 ******************************************************************************/ 47#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE) 48static struct pxamci_platform_data palm27x_mci_platform_data = { 49 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, 50 .detect_delay_ms = 200, 51}; 52 53void __init palm27x_mmc_init(int detect, int ro, int power, 54 int power_inverted) 55{ 56 palm27x_mci_platform_data.gpio_card_detect = detect; 57 palm27x_mci_platform_data.gpio_card_ro = ro; 58 palm27x_mci_platform_data.gpio_power = power; 59 palm27x_mci_platform_data.gpio_power_invert = power_inverted; 60 61 pxa_set_mci_info(&palm27x_mci_platform_data); 62} 63#endif 64 65/****************************************************************************** 66 * Power management - standby 67 ******************************************************************************/ 68#if defined(CONFIG_SUSPEND) 69void __init palm27x_pm_init(unsigned long str_base) 70{ 71 static const unsigned long resume[] = { 72 0xe3a00101, /* mov r0, #0x40000000 */ 73 0xe380060f, /* orr r0, r0, #0x00f00000 */ 74 0xe590f008, /* ldr pc, [r0, #0x08] */ 75 }; 76 77 /* 78 * Copy the bootloader. 79 * NOTE: PalmZ72 uses a different wakeup method! 80 */ 81 memcpy(phys_to_virt(str_base), resume, sizeof(resume)); 82} 83#endif 84 85/****************************************************************************** 86 * Framebuffer 87 ******************************************************************************/ 88#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE) 89struct pxafb_mode_info palm_320x480_lcd_mode = { 90 .pixclock = 57692, 91 .xres = 320, 92 .yres = 480, 93 .bpp = 16, 94 95 .left_margin = 32, 96 .right_margin = 1, 97 .upper_margin = 7, 98 .lower_margin = 1, 99 100 .hsync_len = 4, 101 .vsync_len = 1, 102}; 103 104struct pxafb_mode_info palm_320x320_lcd_mode = { 105 .pixclock = 115384, 106 .xres = 320, 107 .yres = 320, 108 .bpp = 16, 109 110 .left_margin = 27, 111 .right_margin = 7, 112 .upper_margin = 7, 113 .lower_margin = 8, 114 115 .hsync_len = 6, 116 .vsync_len = 1, 117}; 118 119struct pxafb_mode_info palm_320x320_new_lcd_mode = { 120 .pixclock = 86538, 121 .xres = 320, 122 .yres = 320, 123 .bpp = 16, 124 125 .left_margin = 20, 126 .right_margin = 8, 127 .upper_margin = 8, 128 .lower_margin = 5, 129 130 .hsync_len = 4, 131 .vsync_len = 1, 132}; 133 134static struct pxafb_mach_info palm27x_lcd_screen = { 135 .num_modes = 1, 136 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL, 137}; 138 139static int palm27x_lcd_power; 140static void palm27x_lcd_ctl(int on, struct fb_var_screeninfo *info) 141{ 142 gpio_set_value(palm27x_lcd_power, on); 143} 144 145void __init palm27x_lcd_init(int power, struct pxafb_mode_info *mode) 146{ 147 palm27x_lcd_screen.modes = mode; 148 149 if (gpio_is_valid(power)) { 150 if (!gpio_request(power, "LCD power")) { 151 pr_err("Palm27x: failed to claim lcd power gpio!\n"); 152 return; 153 } 154 if (!gpio_direction_output(power, 1)) { 155 pr_err("Palm27x: lcd power configuration failed!\n"); 156 return; 157 } 158 palm27x_lcd_power = power; 159 palm27x_lcd_screen.pxafb_lcd_power = palm27x_lcd_ctl; 160 } 161 162 set_pxa_fb_info(&palm27x_lcd_screen); 163} 164#endif 165 166/****************************************************************************** 167 * USB Gadget 168 ******************************************************************************/ 169#if defined(CONFIG_USB_GADGET_PXA27X) || defined(CONFIG_USB_GADGET_PXA27X_MODULE) 170static struct gpio_vbus_mach_info palm27x_udc_info = { 171 .gpio_vbus_inverted = 1, 172}; 173 174static struct platform_device palm27x_gpio_vbus = { 175 .name = "gpio-vbus", 176 .id = -1, 177 .dev = { 178 .platform_data = &palm27x_udc_info, 179 }, 180}; 181 182void __init palm27x_udc_init(int vbus, int pullup, int vbus_inverted) 183{ 184 palm27x_udc_info.gpio_vbus = vbus; 185 palm27x_udc_info.gpio_pullup = pullup; 186 187 palm27x_udc_info.gpio_vbus_inverted = vbus_inverted; 188 189 if (!gpio_request(pullup, "USB Pullup")) { 190 gpio_direction_output(pullup, 191 palm27x_udc_info.gpio_vbus_inverted); 192 gpio_free(pullup); 193 } else 194 return; 195 196 platform_device_register(&palm27x_gpio_vbus); 197} 198#endif 199 200/****************************************************************************** 201 * IrDA 202 ******************************************************************************/ 203#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE) 204static struct pxaficp_platform_data palm27x_ficp_platform_data = { 205 .transceiver_cap = IR_SIRMODE | IR_OFF, 206}; 207 208void __init palm27x_irda_init(int pwdn) 209{ 210 palm27x_ficp_platform_data.gpio_pwdown = pwdn; 211 pxa_set_ficp_info(&palm27x_ficp_platform_data); 212} 213#endif 214 215/****************************************************************************** 216 * WM97xx audio, battery 217 ******************************************************************************/ 218#if defined(CONFIG_TOUCHSCREEN_WM97XX) || defined(CONFIG_TOUCHSCREEN_WM97XX_MODULE) 219static struct wm97xx_batt_pdata palm27x_batt_pdata = { 220 .batt_aux = WM97XX_AUX_ID3, 221 .temp_aux = WM97XX_AUX_ID2, 222 .charge_gpio = -1, 223 .batt_mult = 1000, 224 .batt_div = 414, 225 .temp_mult = 1, 226 .temp_div = 1, 227 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO, 228 .batt_name = "main-batt", 229}; 230 231static struct wm97xx_pdata palm27x_wm97xx_pdata = { 232 .batt_pdata = &palm27x_batt_pdata, 233}; 234 235static pxa2xx_audio_ops_t palm27x_ac97_pdata = { 236 .codec_pdata = { &palm27x_wm97xx_pdata, }, 237}; 238 239static struct palm27x_asoc_info palm27x_asoc_pdata = { 240 .jack_gpio = -1, 241}; 242 243static struct platform_device palm27x_asoc = { 244 .name = "palm27x-asoc", 245 .id = -1, 246 .dev = { 247 .platform_data = &palm27x_asoc_pdata, 248 }, 249}; 250 251void __init palm27x_ac97_init(int minv, int maxv, int jack, int reset) 252{ 253 palm27x_ac97_pdata.reset_gpio = reset; 254 palm27x_asoc_pdata.jack_gpio = jack; 255 256 if (minv < 0 || maxv < 0) { 257 palm27x_ac97_pdata.codec_pdata[0] = NULL; 258 pxa_set_ac97_info(&palm27x_ac97_pdata); 259 } else { 260 palm27x_batt_pdata.min_voltage = minv, 261 palm27x_batt_pdata.max_voltage = maxv, 262 263 pxa_set_ac97_info(&palm27x_ac97_pdata); 264 platform_device_register(&palm27x_asoc); 265 } 266} 267#endif 268 269/****************************************************************************** 270 * Backlight 271 ******************************************************************************/ 272#if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE) 273static int palm_bl_power; 274static int palm_lcd_power; 275 276static int palm27x_backlight_init(struct device *dev) 277{ 278 int ret; 279 280 ret = gpio_request(palm_bl_power, "BL POWER"); 281 if (ret) 282 goto err; 283 ret = gpio_direction_output(palm_bl_power, 0); 284 if (ret) 285 goto err2; 286 287 if (gpio_is_valid(palm_lcd_power)) { 288 ret = gpio_request(palm_lcd_power, "LCD POWER"); 289 if (ret) 290 goto err2; 291 ret = gpio_direction_output(palm_lcd_power, 0); 292 if (ret) 293 goto err3; 294 } 295 296 return 0; 297err3: 298 gpio_free(palm_lcd_power); 299err2: 300 gpio_free(palm_bl_power); 301err: 302 return ret; 303} 304 305static int palm27x_backlight_notify(struct device *dev, int brightness) 306{ 307 gpio_set_value(palm_bl_power, brightness); 308 if (gpio_is_valid(palm_lcd_power)) 309 gpio_set_value(palm_lcd_power, brightness); 310 return brightness; 311} 312 313static void palm27x_backlight_exit(struct device *dev) 314{ 315 gpio_free(palm_bl_power); 316 if (gpio_is_valid(palm_lcd_power)) 317 gpio_free(palm_lcd_power); 318} 319 320static struct platform_pwm_backlight_data palm27x_backlight_data = { 321 .pwm_id = 0, 322 .max_brightness = 0xfe, 323 .dft_brightness = 0x7e, 324 .pwm_period_ns = 3500, 325 .init = palm27x_backlight_init, 326 .notify = palm27x_backlight_notify, 327 .exit = palm27x_backlight_exit, 328}; 329 330static struct platform_device palm27x_backlight = { 331 .name = "pwm-backlight", 332 .dev = { 333 .parent = &pxa27x_device_pwm0.dev, 334 .platform_data = &palm27x_backlight_data, 335 }, 336}; 337 338void __init palm27x_pwm_init(int bl, int lcd) 339{ 340 palm_bl_power = bl; 341 palm_lcd_power = lcd; 342 platform_device_register(&palm27x_backlight); 343} 344#endif 345 346/****************************************************************************** 347 * Power supply 348 ******************************************************************************/ 349#if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE) 350static int palm_ac_state; 351static int palm_usb_state; 352 353static int palm27x_power_supply_init(struct device *dev) 354{ 355 int ret; 356 357 ret = gpio_request(palm_ac_state, "AC state"); 358 if (ret) 359 goto err1; 360 ret = gpio_direction_input(palm_ac_state); 361 if (ret) 362 goto err2; 363 364 if (gpio_is_valid(palm_usb_state)) { 365 ret = gpio_request(palm_usb_state, "USB state"); 366 if (ret) 367 goto err2; 368 ret = gpio_direction_input(palm_usb_state); 369 if (ret) 370 goto err3; 371 } 372 373 return 0; 374err3: 375 gpio_free(palm_usb_state); 376err2: 377 gpio_free(palm_ac_state); 378err1: 379 return ret; 380} 381 382static void palm27x_power_supply_exit(struct device *dev) 383{ 384 gpio_free(palm_usb_state); 385 gpio_free(palm_ac_state); 386} 387 388static int palm27x_is_ac_online(void) 389{ 390 return gpio_get_value(palm_ac_state); 391} 392 393static int palm27x_is_usb_online(void) 394{ 395 return !gpio_get_value(palm_usb_state); 396} 397static char *palm27x_supplicants[] = { 398 "main-battery", 399}; 400 401static 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), 408}; 409 410static struct platform_device palm27x_power_supply = { 411 .name = "pda-power", 412 .id = -1, 413 .dev = { 414 .platform_data = &palm27x_ps_info, 415 }, 416}; 417 418void __init palm27x_power_init(int ac, int usb) 419{ 420 palm_ac_state = ac; 421 palm_usb_state = usb; 422 platform_device_register(&palm27x_power_supply); 423} 424#endif 425 426/****************************************************************************** 427 * Core power regulator 428 ******************************************************************************/ 429#if defined(CONFIG_REGULATOR_MAX1586) || defined(CONFIG_REGULATOR_MAX1586_MODULE) 430static struct regulator_consumer_supply palm27x_max1587a_consumers[] = { 431 { 432 .supply = "vcc_core", 433 } 434}; 435 436static struct regulator_init_data palm27x_max1587a_v3_info = { 437 .constraints = { 438 .name = "vcc_core range", 439 .min_uV = 900000, 440 .max_uV = 1705000, 441 .always_on = 1, 442 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE, 443 }, 444 .consumer_supplies = palm27x_max1587a_consumers, 445 .num_consumer_supplies = ARRAY_SIZE(palm27x_max1587a_consumers), 446}; 447 448static struct max1586_subdev_data palm27x_max1587a_subdevs[] = { 449 { 450 .name = "vcc_core", 451 .id = MAX1586_V3, 452 .platform_data = &palm27x_max1587a_v3_info, 453 } 454}; 455 456static struct max1586_platform_data palm27x_max1587a_info = { 457 .subdevs = palm27x_max1587a_subdevs, 458 .num_subdevs = ARRAY_SIZE(palm27x_max1587a_subdevs), 459 .v3_gain = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */ 460}; 461 462static struct i2c_board_info __initdata palm27x_pi2c_board_info[] = { 463 { 464 I2C_BOARD_INFO("max1586", 0x14), 465 .platform_data = &palm27x_max1587a_info, 466 }, 467}; 468 469static struct i2c_pxa_platform_data palm27x_i2c_power_info = { 470 .use_pio = 1, 471}; 472 473void __init palm27x_pmic_init(void) 474{ 475 i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info)); 476 pxa27x_set_i2c_power_info(&palm27x_i2c_power_info); 477} 478#endif 479