OSDN Git Service

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