blob: b78c6b4625e8e386e9266ae159e7213de7f0ff29 [file] [log] [blame]
Sergey Lapinc49e1e62008-08-29 15:47:52 +01001/*
2 * Hardware definitions for Palm Zire72
3 *
4 * Authors:
5 * Vladimir "Farcaller" Pouzanov <farcaller@gmail.com>
6 * Sergey Lapin <slapin@ossfans.org>
7 * Alex Osborne <bobofdoom@gmail.com>
8 * Jan Herman <2hp@seznam.cz>
9 *
10 * Rewrite for mainline:
11 * Marek Vasut <marek.vasut@gmail.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 *
17 * (find more info at www.hackndev.com)
18 *
19 */
20
21#include <linux/platform_device.h>
22#include <linux/sysdev.h>
23#include <linux/delay.h>
24#include <linux/irq.h>
25#include <linux/gpio_keys.h>
26#include <linux/input.h>
27#include <linux/pda_power.h>
28#include <linux/pwm_backlight.h>
29#include <linux/gpio.h>
Marek Vasut241cf472010-06-04 03:07:33 +020030#include <linux/wm97xx.h>
Sergey Lapinc49e1e62008-08-29 15:47:52 +010031#include <linux/power_supply.h>
Marek Vasuteb73e622009-06-01 22:34:14 +020032#include <linux/usb/gpio_vbus.h>
Sergey Lapinc49e1e62008-08-29 15:47:52 +010033
34#include <asm/mach-types.h>
35#include <asm/mach/arch.h>
36#include <asm/mach/map.h>
37
Eric Miao51c62982009-01-02 23:17:22 +080038#include <mach/pxa27x.h>
Sergey Lapinc49e1e62008-08-29 15:47:52 +010039#include <mach/audio.h>
40#include <mach/palmz72.h>
41#include <mach/mmc.h>
42#include <mach/pxafb.h>
Sergey Lapinc49e1e62008-08-29 15:47:52 +010043#include <mach/irda.h>
44#include <mach/pxa27x_keypad.h>
45#include <mach/udc.h>
Marek Vasuteb73e622009-06-01 22:34:14 +020046#include <mach/palmasoc.h>
47
Sergey Lapinc49e1e62008-08-29 15:47:52 +010048#include <mach/pm.h>
49
50#include "generic.h"
51#include "devices.h"
52
53/******************************************************************************
54 * Pin configuration
55 ******************************************************************************/
56static unsigned long palmz72_pin_config[] __initdata = {
57 /* MMC */
58 GPIO32_MMC_CLK,
59 GPIO92_MMC_DAT_0,
60 GPIO109_MMC_DAT_1,
61 GPIO110_MMC_DAT_2,
62 GPIO111_MMC_DAT_3,
63 GPIO112_MMC_CMD,
64 GPIO14_GPIO, /* SD detect */
65 GPIO115_GPIO, /* SD RO */
66 GPIO98_GPIO, /* SD power */
67
68 /* AC97 */
69 GPIO28_AC97_BITCLK,
70 GPIO29_AC97_SDATA_IN_0,
71 GPIO30_AC97_SDATA_OUT,
72 GPIO31_AC97_SYNC,
Marek Vasuteb73e622009-06-01 22:34:14 +020073 GPIO89_AC97_SYSCLK,
74 GPIO113_AC97_nRESET,
Sergey Lapinc49e1e62008-08-29 15:47:52 +010075
76 /* IrDA */
77 GPIO49_GPIO, /* ir disable */
78 GPIO46_FICP_RXD,
79 GPIO47_FICP_TXD,
80
81 /* PWM */
82 GPIO16_PWM0_OUT,
83
84 /* USB */
85 GPIO15_GPIO, /* usb detect */
Marek Vasuteb73e622009-06-01 22:34:14 +020086 GPIO95_GPIO, /* usb pullup */
Sergey Lapinc49e1e62008-08-29 15:47:52 +010087
88 /* Matrix keypad */
89 GPIO100_KP_MKIN_0 | WAKEUP_ON_LEVEL_HIGH,
90 GPIO101_KP_MKIN_1 | WAKEUP_ON_LEVEL_HIGH,
91 GPIO102_KP_MKIN_2 | WAKEUP_ON_LEVEL_HIGH,
92 GPIO97_KP_MKIN_3 | WAKEUP_ON_LEVEL_HIGH,
93 GPIO103_KP_MKOUT_0,
94 GPIO104_KP_MKOUT_1,
95 GPIO105_KP_MKOUT_2,
96
97 /* LCD */
Eric Miaobedbda92010-01-04 11:37:14 +080098 GPIOxx_LCD_TFT_16BPP,
99
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100100 GPIO20_GPIO, /* bl power */
101 GPIO21_GPIO, /* LCD border switch */
102 GPIO22_GPIO, /* LCD border color */
103 GPIO96_GPIO, /* lcd power */
104
105 /* Misc. */
106 GPIO0_GPIO | WAKEUP_ON_LEVEL_HIGH, /* power detect */
107 GPIO88_GPIO, /* green led */
108 GPIO27_GPIO, /* WM9712 IRQ */
109};
110
111/******************************************************************************
112 * SD/MMC card controller
113 ******************************************************************************/
Robert Jarzmik7a648252009-07-06 22:16:42 +0200114/* SD_POWER is not actually power, but it is more like chip
115 * select, i.e. it is inverted */
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100116static struct pxamci_platform_data palmz72_mci_platform_data = {
Robert Jarzmik7a648252009-07-06 22:16:42 +0200117 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
118 .gpio_card_detect = GPIO_NR_PALMZ72_SD_DETECT_N,
119 .gpio_card_ro = GPIO_NR_PALMZ72_SD_RO,
120 .gpio_power = GPIO_NR_PALMZ72_SD_POWER_N,
121 .gpio_power_invert = 1,
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100122};
123
124/******************************************************************************
125 * GPIO keyboard
126 ******************************************************************************/
127static unsigned int palmz72_matrix_keys[] = {
128 KEY(0, 0, KEY_POWER),
129 KEY(0, 1, KEY_F1),
130 KEY(0, 2, KEY_ENTER),
131
132 KEY(1, 0, KEY_F2),
133 KEY(1, 1, KEY_F3),
134 KEY(1, 2, KEY_F4),
135
136 KEY(2, 0, KEY_UP),
137 KEY(2, 2, KEY_DOWN),
138
139 KEY(3, 0, KEY_RIGHT),
140 KEY(3, 2, KEY_LEFT),
141};
142
143static struct pxa27x_keypad_platform_data palmz72_keypad_platform_data = {
144 .matrix_key_rows = 4,
145 .matrix_key_cols = 3,
146 .matrix_key_map = palmz72_matrix_keys,
147 .matrix_key_map_size = ARRAY_SIZE(palmz72_matrix_keys),
148
149 .debounce_interval = 30,
150};
151
152/******************************************************************************
153 * Backlight
154 ******************************************************************************/
155static int palmz72_backlight_init(struct device *dev)
156{
157 int ret;
158
159 ret = gpio_request(GPIO_NR_PALMZ72_BL_POWER, "BL POWER");
160 if (ret)
161 goto err;
162 ret = gpio_direction_output(GPIO_NR_PALMZ72_BL_POWER, 0);
163 if (ret)
164 goto err2;
165 ret = gpio_request(GPIO_NR_PALMZ72_LCD_POWER, "LCD POWER");
166 if (ret)
167 goto err2;
168 ret = gpio_direction_output(GPIO_NR_PALMZ72_LCD_POWER, 0);
169 if (ret)
170 goto err3;
171
172 return 0;
173err3:
174 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
175err2:
176 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
177err:
178 return ret;
179}
180
Eric Miao2d51a522010-01-04 11:42:01 +0800181static int palmz72_backlight_notify(struct device *dev, int brightness)
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100182{
183 gpio_set_value(GPIO_NR_PALMZ72_BL_POWER, brightness);
184 gpio_set_value(GPIO_NR_PALMZ72_LCD_POWER, brightness);
185 return brightness;
186}
187
188static void palmz72_backlight_exit(struct device *dev)
189{
190 gpio_free(GPIO_NR_PALMZ72_BL_POWER);
191 gpio_free(GPIO_NR_PALMZ72_LCD_POWER);
192}
193
194static struct platform_pwm_backlight_data palmz72_backlight_data = {
195 .pwm_id = 0,
196 .max_brightness = PALMZ72_MAX_INTENSITY,
197 .dft_brightness = PALMZ72_MAX_INTENSITY,
198 .pwm_period_ns = PALMZ72_PERIOD_NS,
199 .init = palmz72_backlight_init,
200 .notify = palmz72_backlight_notify,
201 .exit = palmz72_backlight_exit,
202};
203
204static struct platform_device palmz72_backlight = {
205 .name = "pwm-backlight",
206 .dev = {
207 .parent = &pxa27x_device_pwm0.dev,
208 .platform_data = &palmz72_backlight_data,
209 },
210};
211
212/******************************************************************************
213 * IrDA
214 ******************************************************************************/
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100215static struct pxaficp_platform_data palmz72_ficp_platform_data = {
Marek Vasutc4bd0172009-07-17 12:50:43 +0200216 .gpio_pwdown = GPIO_NR_PALMZ72_IR_DISABLE,
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100217 .transceiver_cap = IR_SIRMODE | IR_OFF,
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100218};
219
220/******************************************************************************
221 * LEDs
222 ******************************************************************************/
223static struct gpio_led gpio_leds[] = {
224 {
225 .name = "palmz72:green:led",
226 .default_trigger = "none",
227 .gpio = GPIO_NR_PALMZ72_LED_GREEN,
228 },
229};
230
231static struct gpio_led_platform_data gpio_led_info = {
232 .leds = gpio_leds,
233 .num_leds = ARRAY_SIZE(gpio_leds),
234};
235
236static struct platform_device palmz72_leds = {
237 .name = "leds-gpio",
238 .id = -1,
239 .dev = {
240 .platform_data = &gpio_led_info,
241 }
242};
243
244/******************************************************************************
Marek Vasuteb73e622009-06-01 22:34:14 +0200245 * UDC
246 ******************************************************************************/
247static struct gpio_vbus_mach_info palmz72_udc_info = {
248 .gpio_vbus = GPIO_NR_PALMZ72_USB_DETECT_N,
249 .gpio_pullup = GPIO_NR_PALMZ72_USB_PULLUP,
250};
251
252static struct platform_device palmz72_gpio_vbus = {
253 .name = "gpio-vbus",
254 .id = -1,
255 .dev = {
256 .platform_data = &palmz72_udc_info,
257 },
258};
259
260/******************************************************************************
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100261 * Power supply
262 ******************************************************************************/
263static int power_supply_init(struct device *dev)
264{
265 int ret;
266
267 ret = gpio_request(GPIO_NR_PALMZ72_POWER_DETECT, "CABLE_STATE_AC");
268 if (ret)
269 goto err1;
270 ret = gpio_direction_input(GPIO_NR_PALMZ72_POWER_DETECT);
271 if (ret)
272 goto err2;
273
274 ret = gpio_request(GPIO_NR_PALMZ72_USB_DETECT_N, "CABLE_STATE_USB");
275 if (ret)
276 goto err2;
277 ret = gpio_direction_input(GPIO_NR_PALMZ72_USB_DETECT_N);
278 if (ret)
279 goto err3;
280
281 return 0;
282err3:
283 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
284err2:
285 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
286err1:
287 return ret;
288}
289
290static int palmz72_is_ac_online(void)
291{
292 return gpio_get_value(GPIO_NR_PALMZ72_POWER_DETECT);
293}
294
295static int palmz72_is_usb_online(void)
296{
297 return !gpio_get_value(GPIO_NR_PALMZ72_USB_DETECT_N);
298}
299
300static void power_supply_exit(struct device *dev)
301{
302 gpio_free(GPIO_NR_PALMZ72_USB_DETECT_N);
303 gpio_free(GPIO_NR_PALMZ72_POWER_DETECT);
304}
305
306static char *palmz72_supplicants[] = {
307 "main-battery",
308};
309
310static struct pda_power_pdata power_supply_info = {
311 .init = power_supply_init,
312 .is_ac_online = palmz72_is_ac_online,
313 .is_usb_online = palmz72_is_usb_online,
314 .exit = power_supply_exit,
315 .supplied_to = palmz72_supplicants,
316 .num_supplicants = ARRAY_SIZE(palmz72_supplicants),
317};
318
319static struct platform_device power_supply = {
320 .name = "pda-power",
321 .id = -1,
322 .dev = {
323 .platform_data = &power_supply_info,
324 },
325};
326
327/******************************************************************************
Marek Vasut241cf472010-06-04 03:07:33 +0200328 * WM97xx audio, battery
Marek Vasuteb73e622009-06-01 22:34:14 +0200329 ******************************************************************************/
Marek Vasut241cf472010-06-04 03:07:33 +0200330static struct wm97xx_batt_pdata palmz72_batt_pdata = {
Marek Vasuteb73e622009-06-01 22:34:14 +0200331 .batt_aux = WM97XX_AUX_ID3,
332 .temp_aux = WM97XX_AUX_ID2,
333 .charge_gpio = -1,
334 .max_voltage = PALMZ72_BAT_MAX_VOLTAGE,
335 .min_voltage = PALMZ72_BAT_MIN_VOLTAGE,
336 .batt_mult = 1000,
337 .batt_div = 414,
338 .temp_mult = 1,
339 .temp_div = 1,
340 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LIPO,
341 .batt_name = "main-batt",
342};
343
Marek Vasut241cf472010-06-04 03:07:33 +0200344static struct wm97xx_pdata palmz72_wm97xx_pdata = {
345 .batt_pdata = &palmz72_batt_pdata,
346};
347
348static pxa2xx_audio_ops_t palmz72_ac97_pdata = {
349 .codec_pdata = { &palmz72_wm97xx_pdata, },
350};
351
Marek Vasuteb73e622009-06-01 22:34:14 +0200352static struct platform_device palmz72_asoc = {
353 .name = "palm27x-asoc",
354 .id = -1,
355};
356
357/******************************************************************************
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100358 * Framebuffer
359 ******************************************************************************/
360static struct pxafb_mode_info palmz72_lcd_modes[] = {
361{
362 .pixclock = 115384,
363 .xres = 320,
364 .yres = 320,
365 .bpp = 16,
366
367 .left_margin = 27,
368 .right_margin = 7,
369 .upper_margin = 7,
370 .lower_margin = 8,
371
372 .hsync_len = 6,
373 .vsync_len = 1,
374},
375};
376
377static struct pxafb_mach_info palmz72_lcd_screen = {
378 .modes = palmz72_lcd_modes,
379 .num_modes = ARRAY_SIZE(palmz72_lcd_modes),
380 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
381};
382
Sergey Lapinfda50a12008-08-29 15:53:24 +0100383#ifdef CONFIG_PM
384
385/* We have some black magic here
386 * PalmOS ROM on recover expects special struct physical address
387 * to be transferred via PSPR. Using this struct PalmOS restores
388 * its state after sleep. As for Linux, we need to setup it the
389 * same way. More than that, PalmOS ROM changes some values in memory.
390 * For now only one location is found, which needs special treatment.
391 * Thanks to Alex Osborne, Andrzej Zaborowski, and lots of other people
392 * for reading backtraces for me :)
393 */
394
395#define PALMZ72_SAVE_DWORD ((unsigned long *)0xc0000050)
396
397static struct palmz72_resume_info palmz72_resume_info = {
398 .magic0 = 0xb4e6,
399 .magic1 = 1,
400
401 /* reset state, MMU off etc */
402 .arm_control = 0,
403 .aux_control = 0,
404 .ttb = 0,
405 .domain_access = 0,
406 .process_id = 0,
407};
408
409static unsigned long store_ptr;
410
411/* sys_device for Palm Zire 72 PM */
412
413static int palmz72_pm_suspend(struct sys_device *dev, pm_message_t msg)
414{
415 /* setup the resume_info struct for the original bootloader */
416 palmz72_resume_info.resume_addr = (u32) pxa_cpu_resume;
417
418 /* Storing memory touched by ROM */
419 store_ptr = *PALMZ72_SAVE_DWORD;
420
421 /* Setting PSPR to a proper value */
422 PSPR = virt_to_phys(&palmz72_resume_info);
423
424 return 0;
425}
426
427static int palmz72_pm_resume(struct sys_device *dev)
428{
429 *PALMZ72_SAVE_DWORD = store_ptr;
430 return 0;
431}
432
433static struct sysdev_class palmz72_pm_sysclass = {
434 .name = "palmz72_pm",
435 .suspend = palmz72_pm_suspend,
436 .resume = palmz72_pm_resume,
437};
438
439static struct sys_device palmz72_pm_device = {
440 .cls = &palmz72_pm_sysclass,
441};
442
443static int __init palmz72_pm_init(void)
444{
445 int ret = -ENODEV;
446 if (machine_is_palmz72()) {
447 ret = sysdev_class_register(&palmz72_pm_sysclass);
448 if (ret == 0)
449 ret = sysdev_register(&palmz72_pm_device);
450 }
451 return ret;
452}
453
454device_initcall(palmz72_pm_init);
455#endif
456
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100457/******************************************************************************
458 * Machine init
459 ******************************************************************************/
460static struct platform_device *devices[] __initdata = {
461 &palmz72_backlight,
462 &palmz72_leds,
Marek Vasuteb73e622009-06-01 22:34:14 +0200463 &palmz72_asoc,
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100464 &power_supply,
Marek Vasuteb73e622009-06-01 22:34:14 +0200465 &palmz72_gpio_vbus,
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100466};
467
Marek Vasuteb73e622009-06-01 22:34:14 +0200468/* setup udc GPIOs initial state */
469static void __init palmz72_udc_init(void)
470{
471 if (!gpio_request(GPIO_NR_PALMZ72_USB_PULLUP, "USB Pullup")) {
472 gpio_direction_output(GPIO_NR_PALMZ72_USB_PULLUP, 0);
473 gpio_free(GPIO_NR_PALMZ72_USB_PULLUP);
474 }
475}
476
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100477static void __init palmz72_init(void)
478{
479 pxa2xx_mfp_config(ARRAY_AND_SIZE(palmz72_pin_config));
Marek Vasuteb73e622009-06-01 22:34:14 +0200480
Russell Kingcc155c62009-11-09 13:34:08 +0800481 pxa_set_ffuart_info(NULL);
482 pxa_set_btuart_info(NULL);
483 pxa_set_stuart_info(NULL);
484
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100485 set_pxa_fb_info(&palmz72_lcd_screen);
486 pxa_set_mci_info(&palmz72_mci_platform_data);
Marek Vasuteb73e622009-06-01 22:34:14 +0200487 palmz72_udc_init();
Marek Vasut241cf472010-06-04 03:07:33 +0200488 pxa_set_ac97_info(&palmz72_ac97_pdata);
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100489 pxa_set_ficp_info(&palmz72_ficp_platform_data);
490 pxa_set_keypad_info(&palmz72_keypad_platform_data);
Marek Vasuteb73e622009-06-01 22:34:14 +0200491
Sergey Lapinc49e1e62008-08-29 15:47:52 +0100492 platform_add_devices(devices, ARRAY_SIZE(devices));
493}
494
495MACHINE_START(PALMZ72, "Palm Zire72")
496 .phys_io = 0x40000000,
497 .io_pg_offst = io_p2v(0x40000000),
498 .boot_params = 0xa0000100,
499 .map_io = pxa_map_io,
500 .init_irq = pxa27x_init_irq,
501 .timer = &pxa_timer,
502 .init_machine = palmz72_init
503MACHINE_END