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 / palmtc.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * linux/arch/arm/mach-pxa/palmtc.c
4  *
5  * Support for the Palm Tungsten|C
6  *
7  * Author:      Marek Vasut <marek.vasut@gmail.com>
8  *
9  * Based on work of:
10  *              Petr Blaha <p3t3@centrum.cz>
11  *              Chetan S. Kumar <shivakumar.chetan@gmail.com>
12  */
13
14 #include <linux/platform_device.h>
15 #include <linux/delay.h>
16 #include <linux/irq.h>
17 #include <linux/input.h>
18 #include <linux/pwm.h>
19 #include <linux/pwm_backlight.h>
20 #include <linux/gpio/machine.h>
21 #include <linux/input/matrix_keypad.h>
22 #include <linux/ucb1400.h>
23 #include <linux/power_supply.h>
24 #include <linux/gpio_keys.h>
25 #include <linux/mtd/physmap.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 <mach/palmtc.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
39 #include "generic.h"
40 #include "devices.h"
41
42 /******************************************************************************
43  * Pin configuration
44  ******************************************************************************/
45 static unsigned long palmtc_pin_config[] __initdata = {
46         /* MMC */
47         GPIO6_MMC_CLK,
48         GPIO8_MMC_CS0,
49         GPIO12_GPIO,    /* detect */
50         GPIO32_GPIO,    /* power */
51         GPIO54_GPIO,    /* r/o switch */
52
53         /* PCMCIA */
54         GPIO52_nPCE_1,
55         GPIO53_nPCE_2,
56         GPIO50_nPIOR,
57         GPIO51_nPIOW,
58         GPIO49_nPWE,
59         GPIO48_nPOE,
60         GPIO52_nPCE_1,
61         GPIO53_nPCE_2,
62         GPIO57_nIOIS16,
63         GPIO56_nPWAIT,
64
65         /* AC97 */
66         GPIO28_AC97_BITCLK,
67         GPIO29_AC97_SDATA_IN_0,
68         GPIO30_AC97_SDATA_OUT,
69         GPIO31_AC97_SYNC,
70
71         /* IrDA */
72         GPIO45_GPIO,    /* ir disable */
73         GPIO46_FICP_RXD,
74         GPIO47_FICP_TXD,
75
76         /* PWM */
77         GPIO17_PWM1_OUT,
78
79         /* USB */
80         GPIO4_GPIO,     /* detect */
81         GPIO36_GPIO,    /* pullup */
82
83         /* LCD */
84         GPIOxx_LCD_TFT_16BPP,
85
86         /* MATRIX KEYPAD */
87         GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH,       /* in 0 */
88         GPIO9_GPIO | WAKEUP_ON_EDGE_BOTH,       /* in 1 */
89         GPIO10_GPIO | WAKEUP_ON_EDGE_BOTH,      /* in 2 */
90         GPIO11_GPIO | WAKEUP_ON_EDGE_BOTH,      /* in 3 */
91         GPIO18_GPIO | MFP_LPM_DRIVE_LOW,        /* out 0 */
92         GPIO19_GPIO | MFP_LPM_DRIVE_LOW,        /* out 1 */
93         GPIO20_GPIO | MFP_LPM_DRIVE_LOW,        /* out 2 */
94         GPIO21_GPIO | MFP_LPM_DRIVE_LOW,        /* out 3 */
95         GPIO22_GPIO | MFP_LPM_DRIVE_LOW,        /* out 4 */
96         GPIO23_GPIO | MFP_LPM_DRIVE_LOW,        /* out 5 */
97         GPIO24_GPIO | MFP_LPM_DRIVE_LOW,        /* out 6 */
98         GPIO25_GPIO | MFP_LPM_DRIVE_LOW,        /* out 7 */
99         GPIO26_GPIO | MFP_LPM_DRIVE_LOW,        /* out 8 */
100         GPIO27_GPIO | MFP_LPM_DRIVE_LOW,        /* out 9 */
101         GPIO79_GPIO | MFP_LPM_DRIVE_LOW,        /* out 10 */
102         GPIO80_GPIO | MFP_LPM_DRIVE_LOW,        /* out 11 */
103
104         /* PXA GPIO KEYS */
105         GPIO7_GPIO | WAKEUP_ON_EDGE_BOTH,       /* hotsync button on cradle */
106
107         /* MISC */
108         GPIO1_RST,      /* reset */
109         GPIO2_GPIO,     /* earphone detect */
110         GPIO16_GPIO,    /* backlight switch */
111 };
112
113 /******************************************************************************
114  * SD/MMC card controller
115  ******************************************************************************/
116 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
117 static struct pxamci_platform_data palmtc_mci_platform_data = {
118         .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
119         .detect_delay_ms        = 200,
120 };
121
122 static struct gpiod_lookup_table palmtc_mci_gpio_table = {
123         .dev_id = "pxa2xx-mci.0",
124         .table = {
125                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTC_SD_DETECT_N,
126                             "cd", GPIO_ACTIVE_LOW),
127                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTC_SD_READONLY,
128                             "wp", GPIO_ACTIVE_LOW),
129                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTC_SD_POWER,
130                             "power", GPIO_ACTIVE_HIGH),
131                 { },
132         },
133 };
134
135 static void __init palmtc_mmc_init(void)
136 {
137         gpiod_add_lookup_table(&palmtc_mci_gpio_table);
138         pxa_set_mci_info(&palmtc_mci_platform_data);
139 }
140 #else
141 static inline void palmtc_mmc_init(void) {}
142 #endif
143
144 /******************************************************************************
145  * GPIO keys
146  ******************************************************************************/
147 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
148 static struct gpio_keys_button palmtc_pxa_buttons[] = {
149         {KEY_F8, GPIO_NR_PALMTC_HOTSYNC_BUTTON, 1, "HotSync Button", EV_KEY, 1},
150 };
151
152 static struct gpio_keys_platform_data palmtc_pxa_keys_data = {
153         .buttons        = palmtc_pxa_buttons,
154         .nbuttons       = ARRAY_SIZE(palmtc_pxa_buttons),
155 };
156
157 static struct platform_device palmtc_pxa_keys = {
158         .name   = "gpio-keys",
159         .id     = -1,
160         .dev    = {
161                 .platform_data = &palmtc_pxa_keys_data,
162         },
163 };
164
165 static void __init palmtc_keys_init(void)
166 {
167         platform_device_register(&palmtc_pxa_keys);
168 }
169 #else
170 static inline void palmtc_keys_init(void) {}
171 #endif
172
173 /******************************************************************************
174  * Backlight
175  ******************************************************************************/
176 #if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
177 static struct pwm_lookup palmtc_pwm_lookup[] = {
178         PWM_LOOKUP("pxa25x-pwm.1", 0, "pwm-backlight.0", NULL, PALMTC_PERIOD_NS,
179                    PWM_POLARITY_NORMAL),
180 };
181
182 static struct platform_pwm_backlight_data palmtc_backlight_data = {
183         .max_brightness = PALMTC_MAX_INTENSITY,
184         .dft_brightness = PALMTC_MAX_INTENSITY,
185         .enable_gpio    = GPIO_NR_PALMTC_BL_POWER,
186 };
187
188 static struct platform_device palmtc_backlight = {
189         .name   = "pwm-backlight",
190         .dev    = {
191                 .parent         = &pxa25x_device_pwm1.dev,
192                 .platform_data  = &palmtc_backlight_data,
193         },
194 };
195
196 static void __init palmtc_pwm_init(void)
197 {
198         pwm_add_table(palmtc_pwm_lookup, ARRAY_SIZE(palmtc_pwm_lookup));
199         platform_device_register(&palmtc_backlight);
200 }
201 #else
202 static inline void palmtc_pwm_init(void) {}
203 #endif
204
205 /******************************************************************************
206  * IrDA
207  ******************************************************************************/
208 #if defined(CONFIG_IRDA) || defined(CONFIG_IRDA_MODULE)
209 static struct pxaficp_platform_data palmtc_ficp_platform_data = {
210         .gpio_pwdown            = GPIO_NR_PALMTC_IR_DISABLE,
211         .transceiver_cap        = IR_SIRMODE | IR_OFF,
212 };
213
214 static void __init palmtc_irda_init(void)
215 {
216         pxa_set_ficp_info(&palmtc_ficp_platform_data);
217 }
218 #else
219 static inline void palmtc_irda_init(void) {}
220 #endif
221
222 /******************************************************************************
223  * Keyboard
224  ******************************************************************************/
225 #if defined(CONFIG_KEYBOARD_MATRIX) || defined(CONFIG_KEYBOARD_MATRIX_MODULE)
226 static const uint32_t palmtc_matrix_keys[] = {
227         KEY(0, 0, KEY_F1),
228         KEY(0, 1, KEY_X),
229         KEY(0, 2, KEY_POWER),
230         KEY(0, 3, KEY_TAB),
231         KEY(0, 4, KEY_A),
232         KEY(0, 5, KEY_Q),
233         KEY(0, 6, KEY_LEFTSHIFT),
234         KEY(0, 7, KEY_Z),
235         KEY(0, 8, KEY_S),
236         KEY(0, 9, KEY_W),
237         KEY(0, 10, KEY_E),
238         KEY(0, 11, KEY_UP),
239
240         KEY(1, 0, KEY_F2),
241         KEY(1, 1, KEY_DOWN),
242         KEY(1, 3, KEY_D),
243         KEY(1, 4, KEY_C),
244         KEY(1, 5, KEY_F),
245         KEY(1, 6, KEY_R),
246         KEY(1, 7, KEY_SPACE),
247         KEY(1, 8, KEY_V),
248         KEY(1, 9, KEY_G),
249         KEY(1, 10, KEY_T),
250         KEY(1, 11, KEY_LEFT),
251
252         KEY(2, 0, KEY_F3),
253         KEY(2, 1, KEY_LEFTCTRL),
254         KEY(2, 3, KEY_H),
255         KEY(2, 4, KEY_Y),
256         KEY(2, 5, KEY_N),
257         KEY(2, 6, KEY_J),
258         KEY(2, 7, KEY_U),
259         KEY(2, 8, KEY_M),
260         KEY(2, 9, KEY_K),
261         KEY(2, 10, KEY_I),
262         KEY(2, 11, KEY_RIGHT),
263
264         KEY(3, 0, KEY_F4),
265         KEY(3, 1, KEY_ENTER),
266         KEY(3, 3, KEY_DOT),
267         KEY(3, 4, KEY_L),
268         KEY(3, 5, KEY_O),
269         KEY(3, 6, KEY_LEFTALT),
270         KEY(3, 7, KEY_ENTER),
271         KEY(3, 8, KEY_BACKSPACE),
272         KEY(3, 9, KEY_P),
273         KEY(3, 10, KEY_B),
274         KEY(3, 11, KEY_FN),
275 };
276
277 const struct matrix_keymap_data palmtc_keymap_data = {
278         .keymap                 = palmtc_matrix_keys,
279         .keymap_size            = ARRAY_SIZE(palmtc_matrix_keys),
280 };
281
282 static const unsigned int palmtc_keypad_row_gpios[] = {
283         0, 9, 10, 11
284 };
285
286 static const unsigned int palmtc_keypad_col_gpios[] = {
287         18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 79, 80
288 };
289
290 static struct matrix_keypad_platform_data palmtc_keypad_platform_data = {
291         .keymap_data    = &palmtc_keymap_data,
292         .row_gpios      = palmtc_keypad_row_gpios,
293         .num_row_gpios  = ARRAY_SIZE(palmtc_keypad_row_gpios),
294         .col_gpios      = palmtc_keypad_col_gpios,
295         .num_col_gpios  = ARRAY_SIZE(palmtc_keypad_col_gpios),
296         .active_low     = 1,
297
298         .debounce_ms            = 20,
299         .col_scan_delay_us      = 5,
300 };
301
302 static struct platform_device palmtc_keyboard = {
303         .name   = "matrix-keypad",
304         .id     = -1,
305         .dev    = {
306                 .platform_data = &palmtc_keypad_platform_data,
307         },
308 };
309 static void __init palmtc_mkp_init(void)
310 {
311         platform_device_register(&palmtc_keyboard);
312 }
313 #else
314 static inline void palmtc_mkp_init(void) {}
315 #endif
316
317 /******************************************************************************
318  * UDC
319  ******************************************************************************/
320 #if defined(CONFIG_USB_PXA25X)||defined(CONFIG_USB_PXA25X_MODULE)
321 static struct gpiod_lookup_table palmtc_udc_gpiod_table = {
322         .dev_id = "gpio-vbus",
323         .table = {
324                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTC_USB_DETECT_N,
325                             "vbus", GPIO_ACTIVE_LOW),
326                 GPIO_LOOKUP("gpio-pxa", GPIO_NR_PALMTC_USB_POWER,
327                             "pullup", GPIO_ACTIVE_HIGH),
328                 { },
329         },
330 };
331
332 static struct platform_device palmtc_gpio_vbus = {
333         .name   = "gpio-vbus",
334         .id     = -1,
335 };
336
337 static void __init palmtc_udc_init(void)
338 {
339         gpiod_add_lookup_table(&palmtc_udc_gpiod_table);
340         platform_device_register(&palmtc_gpio_vbus);
341 };
342 #else
343 static inline void palmtc_udc_init(void) {}
344 #endif
345
346 /******************************************************************************
347  * Touchscreen / Battery / GPIO-extender
348  ******************************************************************************/
349 #if     defined(CONFIG_TOUCHSCREEN_UCB1400) || \
350         defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
351 static struct platform_device palmtc_ucb1400_device = {
352         .name   = "ucb1400_core",
353         .id     = -1,
354 };
355
356 static void __init palmtc_ts_init(void)
357 {
358         pxa_set_ac97_info(NULL);
359         platform_device_register(&palmtc_ucb1400_device);
360 }
361 #else
362 static inline void palmtc_ts_init(void) {}
363 #endif
364
365 /******************************************************************************
366  * LEDs
367  ******************************************************************************/
368 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
369 struct gpio_led palmtc_gpio_leds[] = {
370 {
371         .name                   = "palmtc:green:user",
372         .default_trigger        = "none",
373         .gpio                   = GPIO_NR_PALMTC_LED_POWER,
374         .active_low             = 1,
375 }, {
376         .name                   = "palmtc:vibra:vibra",
377         .default_trigger        = "none",
378         .gpio                   = GPIO_NR_PALMTC_VIBRA_POWER,
379         .active_low             = 1,
380 }
381
382 };
383
384 static struct gpio_led_platform_data palmtc_gpio_led_info = {
385         .leds           = palmtc_gpio_leds,
386         .num_leds       = ARRAY_SIZE(palmtc_gpio_leds),
387 };
388
389 static struct platform_device palmtc_leds = {
390         .name   = "leds-gpio",
391         .id     = -1,
392         .dev    = {
393                 .platform_data  = &palmtc_gpio_led_info,
394         }
395 };
396
397 static void __init palmtc_leds_init(void)
398 {
399         platform_device_register(&palmtc_leds);
400 }
401 #else
402 static inline void palmtc_leds_init(void) {}
403 #endif
404
405 /******************************************************************************
406  * NOR Flash
407  ******************************************************************************/
408 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
409 static struct resource palmtc_flash_resource = {
410         .start  = PXA_CS0_PHYS,
411         .end    = PXA_CS0_PHYS + SZ_16M - 1,
412         .flags  = IORESOURCE_MEM,
413 };
414
415 static struct mtd_partition palmtc_flash_parts[] = {
416         {
417                 .name   = "U-Boot Bootloader",
418                 .offset = 0x0,
419                 .size   = 0x40000,
420         },
421         {
422                 .name   = "Linux Kernel",
423                 .offset = 0x40000,
424                 .size   = 0x2c0000,
425         },
426         {
427                 .name   = "Filesystem",
428                 .offset = 0x300000,
429                 .size   = 0xcc0000,
430         },
431         {
432                 .name   = "U-Boot Environment",
433                 .offset = 0xfc0000,
434                 .size   = MTDPART_SIZ_FULL,
435         },
436 };
437
438 static struct physmap_flash_data palmtc_flash_data = {
439         .width          = 4,
440         .parts          = palmtc_flash_parts,
441         .nr_parts       = ARRAY_SIZE(palmtc_flash_parts),
442 };
443
444 static struct platform_device palmtc_flash = {
445         .name           = "physmap-flash",
446         .id             = -1,
447         .resource       = &palmtc_flash_resource,
448         .num_resources  = 1,
449         .dev = {
450                 .platform_data  = &palmtc_flash_data,
451         },
452 };
453
454 static void __init palmtc_nor_init(void)
455 {
456         platform_device_register(&palmtc_flash);
457 }
458 #else
459 static inline void palmtc_nor_init(void) {}
460 #endif
461
462 /******************************************************************************
463  * Framebuffer
464  ******************************************************************************/
465 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
466 static struct pxafb_mode_info palmtc_lcd_modes[] = {
467         {
468                 .pixclock       = 115384,
469                 .xres           = 320,
470                 .yres           = 320,
471                 .bpp            = 16,
472
473                 .left_margin    = 27,
474                 .right_margin   = 7,
475                 .upper_margin   = 7,
476                 .lower_margin   = 8,
477
478                 .hsync_len      = 6,
479                 .vsync_len      = 1,
480         },
481 };
482
483 static struct pxafb_mach_info palmtc_lcd_screen = {
484         .modes                  = palmtc_lcd_modes,
485         .num_modes              = ARRAY_SIZE(palmtc_lcd_modes),
486         .lcd_conn               = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
487 };
488
489 static void __init palmtc_lcd_init(void)
490 {
491         pxa_set_fb_info(NULL, &palmtc_lcd_screen);
492 }
493 #else
494 static inline void palmtc_lcd_init(void) {}
495 #endif
496
497 /******************************************************************************
498  * Machine init
499  ******************************************************************************/
500 static void __init palmtc_init(void)
501 {
502         pxa2xx_mfp_config(ARRAY_AND_SIZE(palmtc_pin_config));
503
504         pxa_set_ffuart_info(NULL);
505         pxa_set_btuart_info(NULL);
506         pxa_set_stuart_info(NULL);
507         pxa_set_hwuart_info(NULL);
508
509         palmtc_mmc_init();
510         palmtc_keys_init();
511         palmtc_pwm_init();
512         palmtc_irda_init();
513         palmtc_mkp_init();
514         palmtc_udc_init();
515         palmtc_ts_init();
516         palmtc_nor_init();
517         palmtc_lcd_init();
518         palmtc_leds_init();
519 };
520
521 MACHINE_START(PALMTC, "Palm Tungsten|C")
522         .atag_offset    = 0x100,
523         .map_io         = pxa25x_map_io,
524         .nr_irqs        = PXA_NR_IRQS,
525         .init_irq       = pxa25x_init_irq,
526         .handle_irq     = pxa25x_handle_irq,
527         .init_time      = pxa_timer_init,
528         .init_machine   = palmtc_init,
529         .restart        = pxa_restart,
530 MACHINE_END