Merge tag 'dmaengine-4.21-rc1' of git://git.infradead.org/users/vkoul/slave-dma
[linux-2.6-microblaze.git] / arch / arm / mach-pxa / palmte2.c
1 /*
2  * Hardware definitions for Palm Tungsten|E2
3  *
4  * Author:
5  *      Carlos Eduardo Medaglia Dyonisio <cadu@nerdfeliz.com>
6  *
7  * Rewrite for mainline:
8  *      Marek Vasut <marek.vasut@gmail.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  * (find more info at www.hackndev.com)
15  *
16  */
17
18 #include <linux/platform_device.h>
19 #include <linux/delay.h>
20 #include <linux/irq.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/gpio/machine.h>
23 #include <linux/input.h>
24 #include <linux/pda_power.h>
25 #include <linux/pwm.h>
26 #include <linux/pwm_backlight.h>
27 #include <linux/gpio.h>
28 #include <linux/wm97xx.h>
29 #include <linux/power_supply.h>
30 #include <linux/usb/gpio_vbus.h>
31
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35
36 #include "pxa25x.h"
37 #include <mach/audio.h>
38 #include "palmte2.h"
39 #include <linux/platform_data/mmc-pxamci.h>
40 #include <linux/platform_data/video-pxafb.h>
41 #include <linux/platform_data/irda-pxaficp.h>
42 #include "udc.h"
43 #include <linux/platform_data/asoc-palm27x.h>
44
45 #include "generic.h"
46 #include "devices.h"
47
48 /******************************************************************************
49  * Pin configuration
50  ******************************************************************************/
51 static unsigned long palmte2_pin_config[] __initdata = {
52         /* MMC */
53         GPIO6_MMC_CLK,
54         GPIO8_MMC_CS0,
55         GPIO10_GPIO,    /* SD detect */
56         GPIO55_GPIO,    /* SD power */
57         GPIO51_GPIO,    /* SD r/o switch */
58
59         /* AC97 */
60         GPIO28_AC97_BITCLK,
61         GPIO29_AC97_SDATA_IN_0,
62         GPIO30_AC97_SDATA_OUT,
63         GPIO31_AC97_SYNC,
64
65         /* PWM */
66         GPIO16_PWM0_OUT,
67
68         /* USB */
69         GPIO15_GPIO,    /* usb detect */
70         GPIO53_GPIO,    /* usb power */
71
72         /* IrDA */
73         GPIO48_GPIO,    /* ir disable */
74         GPIO46_FICP_RXD,
75         GPIO47_FICP_TXD,
76
77         /* LCD */
78         GPIOxx_LCD_TFT_16BPP,
79
80         /* GPIO KEYS */
81         GPIO5_GPIO,     /* notes */
82         GPIO7_GPIO,     /* tasks */
83         GPIO11_GPIO,    /* calendar */
84         GPIO13_GPIO,    /* contacts */
85         GPIO14_GPIO,    /* center */
86         GPIO19_GPIO,    /* left */
87         GPIO20_GPIO,    /* right */
88         GPIO21_GPIO,    /* down */
89         GPIO22_GPIO,    /* up */
90
91         /* MISC */
92         GPIO1_RST,      /* reset */
93         GPIO4_GPIO,     /* Hotsync button */
94         GPIO9_GPIO,     /* power detect */
95         GPIO15_GPIO,    /* earphone detect */
96         GPIO37_GPIO,    /* LCD power */
97         GPIO56_GPIO,    /* Backlight power */
98 };
99
100 /******************************************************************************
101  * SD/MMC card controller
102  ******************************************************************************/
103 static struct pxamci_platform_data palmte2_mci_platform_data = {
104         .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
105 };
106
107 static struct gpiod_lookup_table palmte2_mci_gpio_table = {
108         .dev_id = "pxa2xx-mci.0",
109         .table = {
110                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_SD_DETECT_N,
111                             "cd", GPIO_ACTIVE_LOW),
112                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_SD_READONLY,
113                             "wp", GPIO_ACTIVE_LOW),
114                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTE2_SD_POWER,
115                             "power", GPIO_ACTIVE_HIGH),
116                 { },
117         },
118 };
119
120 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
121 /******************************************************************************
122  * GPIO keys
123  ******************************************************************************/
124 static struct gpio_keys_button palmte2_pxa_buttons[] = {
125         {KEY_F1,        GPIO_NR_PALMTE2_KEY_CONTACTS,   1, "Contacts" },
126         {KEY_F2,        GPIO_NR_PALMTE2_KEY_CALENDAR,   1, "Calendar" },
127         {KEY_F3,        GPIO_NR_PALMTE2_KEY_TASKS,      1, "Tasks" },
128         {KEY_F4,        GPIO_NR_PALMTE2_KEY_NOTES,      1, "Notes" },
129         {KEY_ENTER,     GPIO_NR_PALMTE2_KEY_CENTER,     1, "Center" },
130         {KEY_LEFT,      GPIO_NR_PALMTE2_KEY_LEFT,       1, "Left" },
131         {KEY_RIGHT,     GPIO_NR_PALMTE2_KEY_RIGHT,      1, "Right" },
132         {KEY_DOWN,      GPIO_NR_PALMTE2_KEY_DOWN,       1, "Down" },
133         {KEY_UP,        GPIO_NR_PALMTE2_KEY_UP,         1, "Up" },
134 };
135
136 static struct gpio_keys_platform_data palmte2_pxa_keys_data = {
137         .buttons        = palmte2_pxa_buttons,
138         .nbuttons       = ARRAY_SIZE(palmte2_pxa_buttons),
139 };
140
141 static struct platform_device palmte2_pxa_keys = {
142         .name   = "gpio-keys",
143         .id     = -1,
144         .dev    = {
145                 .platform_data = &palmte2_pxa_keys_data,
146         },
147 };
148 #endif
149
150 /******************************************************************************
151  * Backlight
152  ******************************************************************************/
153 static struct pwm_lookup palmte2_pwm_lookup[] = {
154         PWM_LOOKUP("pxa25x-pwm.0", 0, "pwm-backlight.0", NULL,
155                    PALMTE2_PERIOD_NS, PWM_POLARITY_NORMAL),
156 };
157
158 static struct gpio palmte_bl_gpios[] = {
159         { GPIO_NR_PALMTE2_BL_POWER, GPIOF_INIT_LOW, "Backlight power" },
160         { GPIO_NR_PALMTE2_LCD_POWER, GPIOF_INIT_LOW, "LCD power" },
161 };
162
163 static int palmte2_backlight_init(struct device *dev)
164 {
165         return gpio_request_array(ARRAY_AND_SIZE(palmte_bl_gpios));
166 }
167
168 static int palmte2_backlight_notify(struct device *dev, int brightness)
169 {
170         gpio_set_value(GPIO_NR_PALMTE2_BL_POWER, brightness);
171         gpio_set_value(GPIO_NR_PALMTE2_LCD_POWER, brightness);
172         return brightness;
173 }
174
175 static void palmte2_backlight_exit(struct device *dev)
176 {
177         gpio_free_array(ARRAY_AND_SIZE(palmte_bl_gpios));
178 }
179
180 static struct platform_pwm_backlight_data palmte2_backlight_data = {
181         .max_brightness = PALMTE2_MAX_INTENSITY,
182         .dft_brightness = PALMTE2_MAX_INTENSITY,
183         .enable_gpio    = -1,
184         .init           = palmte2_backlight_init,
185         .notify         = palmte2_backlight_notify,
186         .exit           = palmte2_backlight_exit,
187 };
188
189 static struct platform_device palmte2_backlight = {
190         .name   = "pwm-backlight",
191         .dev    = {
192                 .parent         = &pxa25x_device_pwm0.dev,
193                 .platform_data  = &palmte2_backlight_data,
194         },
195 };
196
197 /******************************************************************************
198  * IrDA
199  ******************************************************************************/
200 static struct pxaficp_platform_data palmte2_ficp_platform_data = {
201         .gpio_pwdown            = GPIO_NR_PALMTE2_IR_DISABLE,
202         .transceiver_cap        = IR_SIRMODE | IR_OFF,
203 };
204
205 /******************************************************************************
206  * UDC
207  ******************************************************************************/
208 static struct gpio_vbus_mach_info palmte2_udc_info = {
209         .gpio_vbus              = GPIO_NR_PALMTE2_USB_DETECT_N,
210         .gpio_vbus_inverted     = 1,
211         .gpio_pullup            = GPIO_NR_PALMTE2_USB_PULLUP,
212 };
213
214 static struct platform_device palmte2_gpio_vbus = {
215         .name   = "gpio-vbus",
216         .id     = -1,
217         .dev    = {
218                 .platform_data  = &palmte2_udc_info,
219         },
220 };
221
222 /******************************************************************************
223  * Power supply
224  ******************************************************************************/
225 static int power_supply_init(struct device *dev)
226 {
227         int ret;
228
229         ret = gpio_request(GPIO_NR_PALMTE2_POWER_DETECT, "CABLE_STATE_AC");
230         if (ret)
231                 goto err1;
232         ret = gpio_direction_input(GPIO_NR_PALMTE2_POWER_DETECT);
233         if (ret)
234                 goto err2;
235
236         return 0;
237
238 err2:
239         gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
240 err1:
241         return ret;
242 }
243
244 static int palmte2_is_ac_online(void)
245 {
246         return gpio_get_value(GPIO_NR_PALMTE2_POWER_DETECT);
247 }
248
249 static void power_supply_exit(struct device *dev)
250 {
251         gpio_free(GPIO_NR_PALMTE2_POWER_DETECT);
252 }
253
254 static char *palmte2_supplicants[] = {
255         "main-battery",
256 };
257
258 static struct pda_power_pdata power_supply_info = {
259         .init            = power_supply_init,
260         .is_ac_online    = palmte2_is_ac_online,
261         .exit            = power_supply_exit,
262         .supplied_to     = palmte2_supplicants,
263         .num_supplicants = ARRAY_SIZE(palmte2_supplicants),
264 };
265
266 static struct platform_device power_supply = {
267         .name = "pda-power",
268         .id   = -1,
269         .dev  = {
270                 .platform_data = &power_supply_info,
271         },
272 };
273
274 /******************************************************************************
275  * WM97xx audio, battery
276  ******************************************************************************/
277 static struct wm97xx_batt_pdata palmte2_batt_pdata = {
278         .batt_aux       = WM97XX_AUX_ID3,
279         .temp_aux       = WM97XX_AUX_ID2,
280         .charge_gpio    = -1,
281         .max_voltage    = PALMTE2_BAT_MAX_VOLTAGE,
282         .min_voltage    = PALMTE2_BAT_MIN_VOLTAGE,
283         .batt_mult      = 1000,
284         .batt_div       = 414,
285         .temp_mult      = 1,
286         .temp_div       = 1,
287         .batt_tech      = POWER_SUPPLY_TECHNOLOGY_LIPO,
288         .batt_name      = "main-batt",
289 };
290
291 static struct wm97xx_pdata palmte2_wm97xx_pdata = {
292         .batt_pdata     = &palmte2_batt_pdata,
293 };
294
295 static pxa2xx_audio_ops_t palmte2_ac97_pdata = {
296         .codec_pdata    = { &palmte2_wm97xx_pdata, },
297 };
298
299 static struct palm27x_asoc_info palmte2_asoc_pdata = {
300         .jack_gpio      = GPIO_NR_PALMTE2_EARPHONE_DETECT,
301 };
302
303 static struct platform_device palmte2_asoc = {
304         .name = "palm27x-asoc",
305         .id   = -1,
306         .dev  = {
307                 .platform_data = &palmte2_asoc_pdata,
308         },
309 };
310
311 /******************************************************************************
312  * Framebuffer
313  ******************************************************************************/
314 static struct pxafb_mode_info palmte2_lcd_modes[] = {
315 {
316         .pixclock       = 77757,
317         .xres           = 320,
318         .yres           = 320,
319         .bpp            = 16,
320
321         .left_margin    = 28,
322         .right_margin   = 7,
323         .upper_margin   = 7,
324         .lower_margin   = 5,
325
326         .hsync_len      = 4,
327         .vsync_len      = 1,
328 },
329 };
330
331 static struct pxafb_mach_info palmte2_lcd_screen = {
332         .modes          = palmte2_lcd_modes,
333         .num_modes      = ARRAY_SIZE(palmte2_lcd_modes),
334         .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
335 };
336
337 /******************************************************************************
338  * Machine init
339  ******************************************************************************/
340 static struct platform_device *devices[] __initdata = {
341 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
342         &palmte2_pxa_keys,
343 #endif
344         &palmte2_backlight,
345         &power_supply,
346         &palmte2_asoc,
347         &palmte2_gpio_vbus,
348 };
349
350 /* setup udc GPIOs initial state */
351 static void __init palmte2_udc_init(void)
352 {
353         if (!gpio_request(GPIO_NR_PALMTE2_USB_PULLUP, "UDC Vbus")) {
354                 gpio_direction_output(GPIO_NR_PALMTE2_USB_PULLUP, 1);
355                 gpio_free(GPIO_NR_PALMTE2_USB_PULLUP);
356         }
357 }
358
359 static void __init palmte2_init(void)
360 {
361         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmte2_pin_config));
362
363         pxa_set_ffuart_info(NULL);
364         pxa_set_btuart_info(NULL);
365         pxa_set_stuart_info(NULL);
366
367         pxa_set_fb_info(NULL, &palmte2_lcd_screen);
368         gpiod_add_lookup_table(&palmte2_mci_gpio_table);
369         pxa_set_mci_info(&palmte2_mci_platform_data);
370         palmte2_udc_init();
371         pxa_set_ac97_info(&palmte2_ac97_pdata);
372         pxa_set_ficp_info(&palmte2_ficp_platform_data);
373
374         pwm_add_table(palmte2_pwm_lookup, ARRAY_SIZE(palmte2_pwm_lookup));
375         platform_add_devices(devices, ARRAY_SIZE(devices));
376 }
377
378 MACHINE_START(PALMTE2, "Palm Tungsten|E2")
379         .atag_offset    = 0x100,
380         .map_io         = pxa25x_map_io,
381         .nr_irqs        = PXA_NR_IRQS,
382         .init_irq       = pxa25x_init_irq,
383         .handle_irq     = pxa25x_handle_irq,
384         .init_time      = pxa_timer_init,
385         .init_machine   = palmte2_init,
386         .restart        = pxa_restart,
387 MACHINE_END