]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/arm/mach-pxa/palmt5.c
Merge branch 'omap-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind...
[mirror_ubuntu-jammy-kernel.git] / arch / arm / mach-pxa / palmt5.c
1 /*
2 * Hardware definitions for Palm Tungsten|T5
3 *
4 * Author: Marek Vasut <marek.vasut@gmail.com>
5 *
6 * Based on work of:
7 * Ales Snuparek <snuparek@atlas.cz>
8 * Justin Kendrick <twilightsentry@gmail.com>
9 * RichardT5 <richard_t5@users.sourceforge.net>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 * (find more info at www.hackndev.com)
16 *
17 */
18
19 #include <linux/platform_device.h>
20 #include <linux/delay.h>
21 #include <linux/irq.h>
22 #include <linux/gpio_keys.h>
23 #include <linux/input.h>
24 #include <linux/pda_power.h>
25 #include <linux/pwm_backlight.h>
26 #include <linux/gpio.h>
27 #include <linux/wm97xx_batt.h>
28 #include <linux/power_supply.h>
29 #include <linux/usb/gpio_vbus.h>
30
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34
35 #include <mach/pxa27x.h>
36 #include <mach/audio.h>
37 #include <mach/palmt5.h>
38 #include <mach/mmc.h>
39 #include <mach/pxafb.h>
40 #include <mach/irda.h>
41 #include <mach/pxa27x_keypad.h>
42 #include <mach/udc.h>
43 #include <mach/palmasoc.h>
44
45 #include "generic.h"
46 #include "devices.h"
47
48 /******************************************************************************
49 * Pin configuration
50 ******************************************************************************/
51 static unsigned long palmt5_pin_config[] __initdata = {
52 /* MMC */
53 GPIO32_MMC_CLK,
54 GPIO92_MMC_DAT_0,
55 GPIO109_MMC_DAT_1,
56 GPIO110_MMC_DAT_2,
57 GPIO111_MMC_DAT_3,
58 GPIO112_MMC_CMD,
59 GPIO14_GPIO, /* SD detect */
60 GPIO114_GPIO, /* SD power */
61 GPIO115_GPIO, /* SD r/o switch */
62
63 /* AC97 */
64 GPIO28_AC97_BITCLK,
65 GPIO29_AC97_SDATA_IN_0,
66 GPIO30_AC97_SDATA_OUT,
67 GPIO31_AC97_SYNC,
68 GPIO89_AC97_SYSCLK,
69 GPIO95_AC97_nRESET,
70
71 /* IrDA */
72 GPIO40_GPIO, /* ir disable */
73 GPIO46_FICP_RXD,
74 GPIO47_FICP_TXD,
75
76 /* USB */
77 GPIO15_GPIO, /* usb detect */
78 GPIO93_GPIO, /* usb power */
79
80 /* MATRIX KEYPAD */
81 GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
82 GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
83 GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
84 GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
85 GPIO103_KP_MKOUT_0,
86 GPIO104_KP_MKOUT_1,
87 GPIO105_KP_MKOUT_2,
88
89 /* LCD */
90 GPIO58_LCD_LDD_0,
91 GPIO59_LCD_LDD_1,
92 GPIO60_LCD_LDD_2,
93 GPIO61_LCD_LDD_3,
94 GPIO62_LCD_LDD_4,
95 GPIO63_LCD_LDD_5,
96 GPIO64_LCD_LDD_6,
97 GPIO65_LCD_LDD_7,
98 GPIO66_LCD_LDD_8,
99 GPIO67_LCD_LDD_9,
100 GPIO68_LCD_LDD_10,
101 GPIO69_LCD_LDD_11,
102 GPIO70_LCD_LDD_12,
103 GPIO71_LCD_LDD_13,
104 GPIO72_LCD_LDD_14,
105 GPIO73_LCD_LDD_15,
106 GPIO74_LCD_FCLK,
107 GPIO75_LCD_LCLK,
108 GPIO76_LCD_PCLK,
109 GPIO77_LCD_BIAS,
110
111 /* PWM */
112 GPIO16_PWM0_OUT,
113
114 /* FFUART */
115 GPIO34_FFUART_RXD,
116 GPIO39_FFUART_TXD,
117
118 /* MISC */
119 GPIO10_GPIO, /* hotsync button */
120 GPIO90_GPIO, /* power detect */
121 GPIO107_GPIO, /* earphone detect */
122 };
123
124 /******************************************************************************
125 * SD/MMC card controller
126 ******************************************************************************/
127 static int palmt5_mci_init(struct device *dev, irq_handler_t palmt5_detect_int,
128 void *data)
129 {
130 int err = 0;
131
132 /* Setup an interrupt for detecting card insert/remove events */
133 err = gpio_request(GPIO_NR_PALMT5_SD_DETECT_N, "SD IRQ");
134 if (err)
135 goto err;
136 err = gpio_direction_input(GPIO_NR_PALMT5_SD_DETECT_N);
137 if (err)
138 goto err2;
139 err = request_irq(gpio_to_irq(GPIO_NR_PALMT5_SD_DETECT_N),
140 palmt5_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
141 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
142 "SD/MMC card detect", data);
143 if (err) {
144 printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
145 __func__);
146 goto err2;
147 }
148
149 err = gpio_request(GPIO_NR_PALMT5_SD_POWER, "SD_POWER");
150 if (err)
151 goto err3;
152 err = gpio_direction_output(GPIO_NR_PALMT5_SD_POWER, 0);
153 if (err)
154 goto err4;
155
156 err = gpio_request(GPIO_NR_PALMT5_SD_READONLY, "SD_READONLY");
157 if (err)
158 goto err4;
159 err = gpio_direction_input(GPIO_NR_PALMT5_SD_READONLY);
160 if (err)
161 goto err5;
162
163 printk(KERN_DEBUG "%s: irq registered\n", __func__);
164
165 return 0;
166
167 err5:
168 gpio_free(GPIO_NR_PALMT5_SD_READONLY);
169 err4:
170 gpio_free(GPIO_NR_PALMT5_SD_POWER);
171 err3:
172 free_irq(gpio_to_irq(GPIO_NR_PALMT5_SD_DETECT_N), data);
173 err2:
174 gpio_free(GPIO_NR_PALMT5_SD_DETECT_N);
175 err:
176 return err;
177 }
178
179 static void palmt5_mci_exit(struct device *dev, void *data)
180 {
181 gpio_free(GPIO_NR_PALMT5_SD_READONLY);
182 gpio_free(GPIO_NR_PALMT5_SD_POWER);
183 free_irq(IRQ_GPIO_PALMT5_SD_DETECT_N, data);
184 gpio_free(GPIO_NR_PALMT5_SD_DETECT_N);
185 }
186
187 static void palmt5_mci_power(struct device *dev, unsigned int vdd)
188 {
189 struct pxamci_platform_data *p_d = dev->platform_data;
190 gpio_set_value(GPIO_NR_PALMT5_SD_POWER, p_d->ocr_mask & (1 << vdd));
191 }
192
193 static int palmt5_mci_get_ro(struct device *dev)
194 {
195 return gpio_get_value(GPIO_NR_PALMT5_SD_READONLY);
196 }
197
198 static struct pxamci_platform_data palmt5_mci_platform_data = {
199 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
200 .setpower = palmt5_mci_power,
201 .get_ro = palmt5_mci_get_ro,
202 .init = palmt5_mci_init,
203 .exit = palmt5_mci_exit,
204 };
205
206 /******************************************************************************
207 * GPIO keyboard
208 ******************************************************************************/
209 static unsigned int palmt5_matrix_keys[] = {
210 KEY(0, 0, KEY_POWER),
211 KEY(0, 1, KEY_F1),
212 KEY(0, 2, KEY_ENTER),
213
214 KEY(1, 0, KEY_F2),
215 KEY(1, 1, KEY_F3),
216 KEY(1, 2, KEY_F4),
217
218 KEY(2, 0, KEY_UP),
219 KEY(2, 2, KEY_DOWN),
220
221 KEY(3, 0, KEY_RIGHT),
222 KEY(3, 2, KEY_LEFT),
223 };
224
225 static struct pxa27x_keypad_platform_data palmt5_keypad_platform_data = {
226 .matrix_key_rows = 4,
227 .matrix_key_cols = 3,
228 .matrix_key_map = palmt5_matrix_keys,
229 .matrix_key_map_size = ARRAY_SIZE(palmt5_matrix_keys),
230
231 .debounce_interval = 30,
232 };
233
234 /******************************************************************************
235 * GPIO keys
236 ******************************************************************************/
237 static struct gpio_keys_button palmt5_pxa_buttons[] = {
238 {KEY_F8, GPIO_NR_PALMT5_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
239 };
240
241 static struct gpio_keys_platform_data palmt5_pxa_keys_data = {
242 .buttons = palmt5_pxa_buttons,
243 .nbuttons = ARRAY_SIZE(palmt5_pxa_buttons),
244 };
245
246 static struct platform_device palmt5_pxa_keys = {
247 .name = "gpio-keys",
248 .id = -1,
249 .dev = {
250 .platform_data = &palmt5_pxa_keys_data,
251 },
252 };
253
254 /******************************************************************************
255 * Backlight
256 ******************************************************************************/
257 static int palmt5_backlight_init(struct device *dev)
258 {
259 int ret;
260
261 ret = gpio_request(GPIO_NR_PALMT5_BL_POWER, "BL POWER");
262 if (ret)
263 goto err;
264 ret = gpio_direction_output(GPIO_NR_PALMT5_BL_POWER, 0);
265 if (ret)
266 goto err2;
267 ret = gpio_request(GPIO_NR_PALMT5_LCD_POWER, "LCD POWER");
268 if (ret)
269 goto err2;
270 ret = gpio_direction_output(GPIO_NR_PALMT5_LCD_POWER, 0);
271 if (ret)
272 goto err3;
273
274 return 0;
275 err3:
276 gpio_free(GPIO_NR_PALMT5_LCD_POWER);
277 err2:
278 gpio_free(GPIO_NR_PALMT5_BL_POWER);
279 err:
280 return ret;
281 }
282
283 static int palmt5_backlight_notify(int brightness)
284 {
285 gpio_set_value(GPIO_NR_PALMT5_BL_POWER, brightness);
286 gpio_set_value(GPIO_NR_PALMT5_LCD_POWER, brightness);
287 return brightness;
288 }
289
290 static void palmt5_backlight_exit(struct device *dev)
291 {
292 gpio_free(GPIO_NR_PALMT5_BL_POWER);
293 gpio_free(GPIO_NR_PALMT5_LCD_POWER);
294 }
295
296 static struct platform_pwm_backlight_data palmt5_backlight_data = {
297 .pwm_id = 0,
298 .max_brightness = PALMT5_MAX_INTENSITY,
299 .dft_brightness = PALMT5_MAX_INTENSITY,
300 .pwm_period_ns = PALMT5_PERIOD_NS,
301 .init = palmt5_backlight_init,
302 .notify = palmt5_backlight_notify,
303 .exit = palmt5_backlight_exit,
304 };
305
306 static struct platform_device palmt5_backlight = {
307 .name = "pwm-backlight",
308 .dev = {
309 .parent = &pxa27x_device_pwm0.dev,
310 .platform_data = &palmt5_backlight_data,
311 },
312 };
313
314 /******************************************************************************
315 * IrDA
316 ******************************************************************************/
317 static int palmt5_irda_startup(struct device *dev)
318 {
319 int err;
320 err = gpio_request(GPIO_NR_PALMT5_IR_DISABLE, "IR DISABLE");
321 if (err)
322 goto err;
323 err = gpio_direction_output(GPIO_NR_PALMT5_IR_DISABLE, 1);
324 if (err)
325 gpio_free(GPIO_NR_PALMT5_IR_DISABLE);
326 err:
327 return err;
328 }
329
330 static void palmt5_irda_shutdown(struct device *dev)
331 {
332 gpio_free(GPIO_NR_PALMT5_IR_DISABLE);
333 }
334
335 static void palmt5_irda_transceiver_mode(struct device *dev, int mode)
336 {
337 gpio_set_value(GPIO_NR_PALMT5_IR_DISABLE, mode & IR_OFF);
338 pxa2xx_transceiver_mode(dev, mode);
339 }
340
341 static struct pxaficp_platform_data palmt5_ficp_platform_data = {
342 .startup = palmt5_irda_startup,
343 .shutdown = palmt5_irda_shutdown,
344 .transceiver_cap = IR_SIRMODE | IR_FIRMODE | IR_OFF,
345 .transceiver_mode = palmt5_irda_transceiver_mode,
346 };
347
348 /******************************************************************************
349 * UDC
350 ******************************************************************************/
351 static struct gpio_vbus_mach_info palmt5_udc_info = {
352 .gpio_vbus = GPIO_NR_PALMT5_USB_DETECT_N,
353 .gpio_vbus_inverted = 1,
354 .gpio_pullup = GPIO_NR_PALMT5_USB_PULLUP,
355 };
356
357 static struct platform_device palmt5_gpio_vbus = {
358 .name = "gpio-vbus",
359 .id = -1,
360 .dev = {
361 .platform_data = &palmt5_udc_info,
362 },
363 };
364
365 /******************************************************************************
366 * Power supply
367 ******************************************************************************/
368 static int power_supply_init(struct device *dev)
369 {
370 int ret;
371
372 ret = gpio_request(GPIO_NR_PALMT5_POWER_DETECT, "CABLE_STATE_AC");
373 if (ret)
374 goto err1;
375 ret = gpio_direction_input(GPIO_NR_PALMT5_POWER_DETECT);
376 if (ret)
377 goto err2;
378
379 return 0;
380 err2:
381 gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
382 err1:
383 return ret;
384 }
385
386 static int palmt5_is_ac_online(void)
387 {
388 return gpio_get_value(GPIO_NR_PALMT5_POWER_DETECT);
389 }
390
391 static void power_supply_exit(struct device *dev)
392 {
393 gpio_free(GPIO_NR_PALMT5_POWER_DETECT);
394 }
395
396 static char *palmt5_supplicants[] = {
397 "main-battery",
398 };
399
400 static struct pda_power_pdata power_supply_info = {
401 .init = power_supply_init,
402 .is_ac_online = palmt5_is_ac_online,
403 .exit = power_supply_exit,
404 .supplied_to = palmt5_supplicants,
405 .num_supplicants = ARRAY_SIZE(palmt5_supplicants),
406 };
407
408 static struct platform_device power_supply = {
409 .name = "pda-power",
410 .id = -1,
411 .dev = {
412 .platform_data = &power_supply_info,
413 },
414 };
415
416 /******************************************************************************
417 * WM97xx battery
418 ******************************************************************************/
419 static struct wm97xx_batt_info wm97xx_batt_pdata = {
420 .batt_aux = WM97XX_AUX_ID3,
421 .temp_aux = WM97XX_AUX_ID2,
422 .charge_gpio = -1,
423 .max_voltage = PALMT5_BAT_MAX_VOLTAGE,
424 .min_voltage = PALMT5_BAT_MIN_VOLTAGE,
425 .batt_mult = 1000,
426 .batt_div = 414,
427 .temp_mult = 1,
428 .temp_div = 1,
429 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
430 .batt_name = "main-batt",
431 };
432
433 /******************************************************************************
434 * aSoC audio
435 ******************************************************************************/
436 static struct palm27x_asoc_info palmt5_asoc_pdata = {
437 .jack_gpio = GPIO_NR_PALMT5_EARPHONE_DETECT,
438 };
439
440 static pxa2xx_audio_ops_t palmt5_ac97_pdata = {
441 .reset_gpio = 95,
442 };
443
444 static struct platform_device palmt5_asoc = {
445 .name = "palm27x-asoc",
446 .id = -1,
447 .dev = {
448 .platform_data = &palmt5_asoc_pdata,
449 },
450 };
451
452 /******************************************************************************
453 * Framebuffer
454 ******************************************************************************/
455 static struct pxafb_mode_info palmt5_lcd_modes[] = {
456 {
457 .pixclock = 57692,
458 .xres = 320,
459 .yres = 480,
460 .bpp = 16,
461
462 .left_margin = 32,
463 .right_margin = 1,
464 .upper_margin = 7,
465 .lower_margin = 1,
466
467 .hsync_len = 4,
468 .vsync_len = 1,
469 },
470 };
471
472 static struct pxafb_mach_info palmt5_lcd_screen = {
473 .modes = palmt5_lcd_modes,
474 .num_modes = ARRAY_SIZE(palmt5_lcd_modes),
475 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
476 };
477
478 /******************************************************************************
479 * Power management - standby
480 ******************************************************************************/
481 static void __init palmt5_pm_init(void)
482 {
483 static u32 resume[] = {
484 0xe3a00101, /* mov r0, #0x40000000 */
485 0xe380060f, /* orr r0, r0, #0x00f00000 */
486 0xe590f008, /* ldr pc, [r0, #0x08] */
487 };
488
489 /* copy the bootloader */
490 memcpy(phys_to_virt(PALMT5_STR_BASE), resume, sizeof(resume));
491 }
492
493 /******************************************************************************
494 * Machine init
495 ******************************************************************************/
496 static struct platform_device *devices[] __initdata = {
497 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
498 &palmt5_pxa_keys,
499 #endif
500 &palmt5_backlight,
501 &power_supply,
502 &palmt5_asoc,
503 &palmt5_gpio_vbus,
504 };
505
506 /* setup udc GPIOs initial state */
507 static void __init palmt5_udc_init(void)
508 {
509 if (!gpio_request(GPIO_NR_PALMT5_USB_PULLUP, "UDC Vbus")) {
510 gpio_direction_output(GPIO_NR_PALMT5_USB_PULLUP, 1);
511 gpio_free(GPIO_NR_PALMT5_USB_PULLUP);
512 }
513 }
514
515 static void __init palmt5_init(void)
516 {
517 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmt5_pin_config));
518
519 palmt5_pm_init();
520 set_pxa_fb_info(&palmt5_lcd_screen);
521 pxa_set_mci_info(&palmt5_mci_platform_data);
522 palmt5_udc_init();
523 pxa_set_ac97_info(&palmt5_ac97_pdata);
524 pxa_set_ficp_info(&palmt5_ficp_platform_data);
525 pxa_set_keypad_info(&palmt5_keypad_platform_data);
526 wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
527
528 platform_add_devices(devices, ARRAY_SIZE(devices));
529 }
530
531 MACHINE_START(PALMT5, "Palm Tungsten|T5")
532 .phys_io = PALMT5_PHYS_IO_START,
533 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
534 .boot_params = 0xa0000100,
535 .map_io = pxa_map_io,
536 .init_irq = pxa27x_init_irq,
537 .timer = &pxa_timer,
538 .init_machine = palmt5_init
539 MACHINE_END