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