blob: e54a296fb81f8b045f814860c0dc729edb71d2c4 [file] [log] [blame]
Marek Vasut95045942010-07-13 14:08:57 +02001/*
2 * Common code for Palm LD, T5, TX, Z72
3 *
Marek Vasut9ed3fbf2011-01-15 19:22:19 +01004 * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com>
Marek Vasut95045942010-07-13 14:08:57 +02005 *
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.
9 *
10 */
11
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>
Sebastian Andrzej Siewiorb4593962011-02-23 12:38:16 +010024#include <linux/i2c/pxa-i2c.h>
Marek Vasut95045942010-07-13 14:08:57 +020025
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>
Arnd Bergmann293b2da2012-08-24 15:16:48 +020032#include <linux/platform_data/mmc-pxamci.h>
33#include <linux/platform_data/video-pxafb.h>
34#include <linux/platform_data/irda-pxaficp.h>
Marek Vasut95045942010-07-13 14:08:57 +020035#include <mach/udc.h>
Arnd Bergmann293b2da2012-08-24 15:16:48 +020036#include <linux/platform_data/asoc-palm27x.h>
Marek Vasut95045942010-07-13 14:08:57 +020037#include <mach/palm27x.h>
38
Marek Vasut95045942010-07-13 14:08:57 +020039#include "generic.h"
40#include "devices.h"
41
42/******************************************************************************
43 * SD/MMC card controller
44 ******************************************************************************/
45#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
46static struct pxamci_platform_data palm27x_mci_platform_data = {
47 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
48 .detect_delay_ms = 200,
49};
50
51void __init palm27x_mmc_init(int detect, int ro, int power,
52 int power_inverted)
53{
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;
58
59 pxa_set_mci_info(&palm27x_mci_platform_data);
60}
61#endif
62
63/******************************************************************************
64 * Power management - standby
65 ******************************************************************************/
66#if defined(CONFIG_SUSPEND)
67void __init palm27x_pm_init(unsigned long str_base)
68{
69 static const unsigned long resume[] = {
70 0xe3a00101, /* mov r0, #0x40000000 */
71 0xe380060f, /* orr r0, r0, #0x00f00000 */
72 0xe590f008, /* ldr pc, [r0, #0x08] */
73 };
74
75 /*
76 * Copy the bootloader.
77 * NOTE: PalmZ72 uses a different wakeup method!
78 */
79 memcpy(phys_to_virt(str_base), resume, sizeof(resume));
80}
81#endif
82
83/******************************************************************************
84 * Framebuffer
85 ******************************************************************************/
86#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
87struct pxafb_mode_info palm_320x480_lcd_mode = {
88 .pixclock = 57692,
89 .xres = 320,
90 .yres = 480,
91 .bpp = 16,
92
93 .left_margin = 32,
94 .right_margin = 1,
95 .upper_margin = 7,
96 .lower_margin = 1,
97
98 .hsync_len = 4,
99 .vsync_len = 1,
100};
101
102struct pxafb_mode_info palm_320x320_lcd_mode = {
103 .pixclock = 115384,
104 .xres = 320,
105 .yres = 320,
106 .bpp = 16,
107
108 .left_margin = 27,
109 .right_margin = 7,
110 .upper_margin = 7,
111 .lower_margin = 8,
112
113 .hsync_len = 6,
114 .vsync_len = 1,
115};
116
117struct pxafb_mode_info palm_320x320_new_lcd_mode = {
118 .pixclock = 86538,
119 .xres = 320,
120 .yres = 320,
121 .bpp = 16,
122
123 .left_margin = 20,
124 .right_margin = 8,
125 .upper_margin = 8,
126 .lower_margin = 5,
127
128 .hsync_len = 4,
129 .vsync_len = 1,
130};
131
132static struct pxafb_mach_info palm27x_lcd_screen = {
133 .num_modes = 1,
134 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
135};
136
137static int palm27x_lcd_power;
138static void palm27x_lcd_ctl(int on, struct fb_var_screeninfo *info)
139{
140 gpio_set_value(palm27x_lcd_power, on);
141}
142
143void __init palm27x_lcd_init(int power, struct pxafb_mode_info *mode)
144{
145 palm27x_lcd_screen.modes = mode;
146
147 if (gpio_is_valid(power)) {
148 if (!gpio_request(power, "LCD power")) {
149 pr_err("Palm27x: failed to claim lcd power gpio!\n");
150 return;
151 }
152 if (!gpio_direction_output(power, 1)) {
153 pr_err("Palm27x: lcd power configuration failed!\n");
154 return;
155 }
156 palm27x_lcd_power = power;
157 palm27x_lcd_screen.pxafb_lcd_power = palm27x_lcd_ctl;
158 }
159
Russell King - ARM Linux4321e1a2011-02-15 15:37:30 +0800160 pxa_set_fb_info(NULL, &palm27x_lcd_screen);
Marek Vasut95045942010-07-13 14:08:57 +0200161}
162#endif
163
164/******************************************************************************
165 * USB Gadget
166 ******************************************************************************/
Haojian Zhuangc0a39152011-11-10 07:13:07 +0800167#if defined(CONFIG_USB_PXA27X) || \
168 defined(CONFIG_USB_PXA27X_MODULE)
Marek Vasut95045942010-07-13 14:08:57 +0200169static struct gpio_vbus_mach_info palm27x_udc_info = {
170 .gpio_vbus_inverted = 1,
171};
172
173static struct platform_device palm27x_gpio_vbus = {
174 .name = "gpio-vbus",
175 .id = -1,
176 .dev = {
177 .platform_data = &palm27x_udc_info,
178 },
179};
180
181void __init palm27x_udc_init(int vbus, int pullup, int vbus_inverted)
182{
183 palm27x_udc_info.gpio_vbus = vbus;
184 palm27x_udc_info.gpio_pullup = pullup;
185
186 palm27x_udc_info.gpio_vbus_inverted = vbus_inverted;
187
188 if (!gpio_request(pullup, "USB Pullup")) {
189 gpio_direction_output(pullup,
190 palm27x_udc_info.gpio_vbus_inverted);
191 gpio_free(pullup);
192 } else
193 return;
194
195 platform_device_register(&palm27x_gpio_vbus);
196}
197#endif
198
199/******************************************************************************
200 * IrDA
201 ******************************************************************************/
202#if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
203static struct pxaficp_platform_data palm27x_ficp_platform_data = {
204 .transceiver_cap = IR_SIRMODE | IR_OFF,
205};
206
207void __init palm27x_irda_init(int pwdn)
208{
209 palm27x_ficp_platform_data.gpio_pwdown = pwdn;
210 pxa_set_ficp_info(&palm27x_ficp_platform_data);
211}
212#endif
213
214/******************************************************************************
215 * WM97xx audio, battery
216 ******************************************************************************/
217#if defined(CONFIG_TOUCHSCREEN_WM97XX) || \
218 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,
Marek Vasut285ca2e2011-01-31 23:06:53 +0100324 .pwm_period_ns = 3500 * 1024,
Thierry Redingdb011202013-08-30 12:15:24 +0200325 .enable_gpio = -1,
Marek Vasut95045942010-07-13 14:08:57 +0200326 .init = palm27x_backlight_init,
327 .notify = palm27x_backlight_notify,
328 .exit = palm27x_backlight_exit,
329};
330
331static struct platform_device palm27x_backlight = {
332 .name = "pwm-backlight",
333 .dev = {
334 .parent = &pxa27x_device_pwm0.dev,
335 .platform_data = &palm27x_backlight_data,
336 },
337};
338
339void __init palm27x_pwm_init(int bl, int lcd)
340{
341 palm_bl_power = bl;
342 palm_lcd_power = lcd;
343 platform_device_register(&palm27x_backlight);
344}
345#endif
346
347/******************************************************************************
348 * Power supply
349 ******************************************************************************/
350#if defined(CONFIG_PDA_POWER) || defined(CONFIG_PDA_POWER_MODULE)
351static int palm_ac_state;
352static int palm_usb_state;
353
354static int palm27x_power_supply_init(struct device *dev)
355{
356 int ret;
357
358 ret = gpio_request(palm_ac_state, "AC state");
359 if (ret)
360 goto err1;
361 ret = gpio_direction_input(palm_ac_state);
362 if (ret)
363 goto err2;
364
365 if (gpio_is_valid(palm_usb_state)) {
366 ret = gpio_request(palm_usb_state, "USB state");
367 if (ret)
368 goto err2;
369 ret = gpio_direction_input(palm_usb_state);
370 if (ret)
371 goto err3;
372 }
373
374 return 0;
375err3:
376 gpio_free(palm_usb_state);
377err2:
378 gpio_free(palm_ac_state);
379err1:
380 return ret;
381}
382
383static void palm27x_power_supply_exit(struct device *dev)
384{
385 gpio_free(palm_usb_state);
386 gpio_free(palm_ac_state);
387}
388
389static int palm27x_is_ac_online(void)
390{
391 return gpio_get_value(palm_ac_state);
392}
393
394static int palm27x_is_usb_online(void)
395{
396 return !gpio_get_value(palm_usb_state);
397}
398static char *palm27x_supplicants[] = {
399 "main-battery",
400};
401
402static 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),
409};
410
411static struct platform_device palm27x_power_supply = {
412 .name = "pda-power",
413 .id = -1,
414 .dev = {
415 .platform_data = &palm27x_ps_info,
416 },
417};
418
419void __init palm27x_power_init(int ac, int usb)
420{
421 palm_ac_state = ac;
422 palm_usb_state = usb;
423 platform_device_register(&palm27x_power_supply);
424}
425#endif
426
427/******************************************************************************
428 * Core power regulator
429 ******************************************************************************/
430#if defined(CONFIG_REGULATOR_MAX1586) || \
431 defined(CONFIG_REGULATOR_MAX1586_MODULE)
432static struct regulator_consumer_supply palm27x_max1587a_consumers[] = {
Axel Lin0bf189a2012-05-08 16:25:10 +0800433 REGULATOR_SUPPLY("vcc_core", NULL),
Marek Vasut95045942010-07-13 14:08:57 +0200434};
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
Marek Vasutcf625362010-08-14 06:08:30 +0200469static struct i2c_pxa_platform_data palm27x_i2c_power_info = {
470 .use_pio = 1,
471};
472
Marek Vasut95045942010-07-13 14:08:57 +0200473void __init palm27x_pmic_init(void)
474{
475 i2c_register_board_info(1, ARRAY_AND_SIZE(palm27x_pi2c_board_info));
Marek Vasutcf625362010-08-14 06:08:30 +0200476 pxa27x_set_i2c_power_info(&palm27x_i2c_power_info);
Marek Vasut95045942010-07-13 14:08:57 +0200477}
478#endif