• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Hardware definitions for PalmTX
3  *
4  * Author:     Marek Vasut <marek.vasut@gmail.com>
5  *
6  * Based on work of:
7  *		Alex Osborne <ato@meshy.org>
8  *		Cristiano P. <cristianop@users.sourceforge.net>
9  *		Jan Herman <2hp@seznam.cz>
10  *		Michal Hrusecky
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License version 2 as
14  * published by the Free Software Foundation.
15  *
16  * (find more info at www.hackndev.com)
17  *
18  */
19 
20 #include <linux/platform_device.h>
21 #include <linux/delay.h>
22 #include <linux/irq.h>
23 #include <linux/gpio_keys.h>
24 #include <linux/input.h>
25 #include <linux/pda_power.h>
26 #include <linux/pwm_backlight.h>
27 #include <linux/gpio.h>
28 #include <linux/wm97xx_batt.h>
29 #include <linux/power_supply.h>
30 
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 
35 #include <mach/audio.h>
36 #include <mach/palmtx.h>
37 #include <mach/mmc.h>
38 #include <mach/pxafb.h>
39 #include <mach/pxa-regs.h>
40 #include <mach/mfp-pxa27x.h>
41 #include <mach/irda.h>
42 #include <mach/pxa27x_keypad.h>
43 #include <mach/udc.h>
44 
45 #include "generic.h"
46 #include "devices.h"
47 
48 /******************************************************************************
49  * Pin configuration
50  ******************************************************************************/
51 static unsigned long palmtx_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 
69 	/* IrDA */
70 	GPIO40_GPIO,	/* ir disable */
71 	GPIO46_FICP_RXD,
72 	GPIO47_FICP_TXD,
73 
74 	/* PWM */
75 	GPIO16_PWM0_OUT,
76 
77 	/* USB */
78 	GPIO13_GPIO,	/* usb detect */
79 	GPIO95_GPIO,	/* usb power */
80 
81 	/* PCMCIA */
82 	GPIO48_nPOE,
83 	GPIO49_nPWE,
84 	GPIO50_nPIOR,
85 	GPIO51_nPIOW,
86 	GPIO85_nPCE_1,
87 	GPIO54_nPCE_2,
88 	GPIO79_PSKTSEL,
89 	GPIO55_nPREG,
90 	GPIO56_nPWAIT,
91 	GPIO57_nIOIS16,
92 	GPIO94_GPIO,	/* wifi power 1 */
93 	GPIO108_GPIO,	/* wifi power 2 */
94 	GPIO116_GPIO,	/* wifi ready */
95 
96 	/* MATRIX KEYPAD */
97 	GPIO100_KP_MKIN_0,
98 	GPIO101_KP_MKIN_1,
99 	GPIO102_KP_MKIN_2,
100 	GPIO97_KP_MKIN_3,
101 	GPIO103_KP_MKOUT_0,
102 	GPIO104_KP_MKOUT_1,
103 	GPIO105_KP_MKOUT_2,
104 
105 	/* LCD */
106 	GPIO58_LCD_LDD_0,
107 	GPIO59_LCD_LDD_1,
108 	GPIO60_LCD_LDD_2,
109 	GPIO61_LCD_LDD_3,
110 	GPIO62_LCD_LDD_4,
111 	GPIO63_LCD_LDD_5,
112 	GPIO64_LCD_LDD_6,
113 	GPIO65_LCD_LDD_7,
114 	GPIO66_LCD_LDD_8,
115 	GPIO67_LCD_LDD_9,
116 	GPIO68_LCD_LDD_10,
117 	GPIO69_LCD_LDD_11,
118 	GPIO70_LCD_LDD_12,
119 	GPIO71_LCD_LDD_13,
120 	GPIO72_LCD_LDD_14,
121 	GPIO73_LCD_LDD_15,
122 	GPIO74_LCD_FCLK,
123 	GPIO75_LCD_LCLK,
124 	GPIO76_LCD_PCLK,
125 	GPIO77_LCD_BIAS,
126 
127 	/* MISC. */
128 	GPIO10_GPIO,	/* hotsync button */
129 	GPIO12_GPIO,	/* power detect */
130 	GPIO107_GPIO,	/* earphone detect */
131 };
132 
133 /******************************************************************************
134  * SD/MMC card controller
135  ******************************************************************************/
palmtx_mci_init(struct device * dev,irq_handler_t palmtx_detect_int,void * data)136 static int palmtx_mci_init(struct device *dev, irq_handler_t palmtx_detect_int,
137 				void *data)
138 {
139 	int err = 0;
140 
141 	/* Setup an interrupt for detecting card insert/remove events */
142 	err = gpio_request(GPIO_NR_PALMTX_SD_DETECT_N, "SD IRQ");
143 	if (err)
144 		goto err;
145 	err = gpio_direction_input(GPIO_NR_PALMTX_SD_DETECT_N);
146 	if (err)
147 		goto err2;
148 	err = request_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N),
149 			palmtx_detect_int, IRQF_DISABLED | IRQF_SAMPLE_RANDOM |
150 			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
151 			"SD/MMC card detect", data);
152 	if (err) {
153 		printk(KERN_ERR "%s: cannot request SD/MMC card detect IRQ\n",
154 				__func__);
155 		goto err2;
156 	}
157 
158 	err = gpio_request(GPIO_NR_PALMTX_SD_POWER, "SD_POWER");
159 	if (err)
160 		goto err3;
161 	err = gpio_direction_output(GPIO_NR_PALMTX_SD_POWER, 0);
162 	if (err)
163 		goto err4;
164 
165 	err = gpio_request(GPIO_NR_PALMTX_SD_READONLY, "SD_READONLY");
166 	if (err)
167 		goto err4;
168 	err = gpio_direction_input(GPIO_NR_PALMTX_SD_READONLY);
169 	if (err)
170 		goto err5;
171 
172 	printk(KERN_DEBUG "%s: irq registered\n", __func__);
173 
174 	return 0;
175 
176 err5:
177 	gpio_free(GPIO_NR_PALMTX_SD_READONLY);
178 err4:
179 	gpio_free(GPIO_NR_PALMTX_SD_POWER);
180 err3:
181 	free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
182 err2:
183 	gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
184 err:
185 	return err;
186 }
187 
palmtx_mci_exit(struct device * dev,void * data)188 static void palmtx_mci_exit(struct device *dev, void *data)
189 {
190 	gpio_free(GPIO_NR_PALMTX_SD_READONLY);
191 	gpio_free(GPIO_NR_PALMTX_SD_POWER);
192 	free_irq(gpio_to_irq(GPIO_NR_PALMTX_SD_DETECT_N), data);
193 	gpio_free(GPIO_NR_PALMTX_SD_DETECT_N);
194 }
195 
palmtx_mci_power(struct device * dev,unsigned int vdd)196 static void palmtx_mci_power(struct device *dev, unsigned int vdd)
197 {
198 	struct pxamci_platform_data *p_d = dev->platform_data;
199 	gpio_set_value(GPIO_NR_PALMTX_SD_POWER, p_d->ocr_mask & (1 << vdd));
200 }
201 
palmtx_mci_get_ro(struct device * dev)202 static int palmtx_mci_get_ro(struct device *dev)
203 {
204 	return gpio_get_value(GPIO_NR_PALMTX_SD_READONLY);
205 }
206 
207 static struct pxamci_platform_data palmtx_mci_platform_data = {
208 	.ocr_mask	= MMC_VDD_32_33 | MMC_VDD_33_34,
209 	.setpower	= palmtx_mci_power,
210 	.get_ro		= palmtx_mci_get_ro,
211 	.init 		= palmtx_mci_init,
212 	.exit		= palmtx_mci_exit,
213 };
214 
215 /******************************************************************************
216  * GPIO keyboard
217  ******************************************************************************/
218 static unsigned int palmtx_matrix_keys[] = {
219 	KEY(0, 0, KEY_POWER),
220 	KEY(0, 1, KEY_F1),
221 	KEY(0, 2, KEY_ENTER),
222 
223 	KEY(1, 0, KEY_F2),
224 	KEY(1, 1, KEY_F3),
225 	KEY(1, 2, KEY_F4),
226 
227 	KEY(2, 0, KEY_UP),
228 	KEY(2, 2, KEY_DOWN),
229 
230 	KEY(3, 0, KEY_RIGHT),
231 	KEY(3, 2, KEY_LEFT),
232 };
233 
234 static struct pxa27x_keypad_platform_data palmtx_keypad_platform_data = {
235 	.matrix_key_rows	= 4,
236 	.matrix_key_cols	= 3,
237 	.matrix_key_map		= palmtx_matrix_keys,
238 	.matrix_key_map_size	= ARRAY_SIZE(palmtx_matrix_keys),
239 
240 	.debounce_interval	= 30,
241 };
242 
243 /******************************************************************************
244  * GPIO keys
245  ******************************************************************************/
246 static struct gpio_keys_button palmtx_pxa_buttons[] = {
247 	{KEY_F8, GPIO_NR_PALMTX_HOTSYNC_BUTTON_N, 1, "HotSync Button" },
248 };
249 
250 static struct gpio_keys_platform_data palmtx_pxa_keys_data = {
251 	.buttons	= palmtx_pxa_buttons,
252 	.nbuttons	= ARRAY_SIZE(palmtx_pxa_buttons),
253 };
254 
255 static struct platform_device palmtx_pxa_keys = {
256 	.name	= "gpio-keys",
257 	.id	= -1,
258 	.dev	= {
259 		.platform_data = &palmtx_pxa_keys_data,
260 	},
261 };
262 
263 /******************************************************************************
264  * Backlight
265  ******************************************************************************/
palmtx_backlight_init(struct device * dev)266 static int palmtx_backlight_init(struct device *dev)
267 {
268 	int ret;
269 
270 	ret = gpio_request(GPIO_NR_PALMTX_BL_POWER, "BL POWER");
271 	if (ret)
272 		goto err;
273 	ret = gpio_direction_output(GPIO_NR_PALMTX_BL_POWER, 0);
274 	if (ret)
275 		goto err2;
276 	ret = gpio_request(GPIO_NR_PALMTX_LCD_POWER, "LCD POWER");
277 	if (ret)
278 		goto err2;
279 	ret = gpio_direction_output(GPIO_NR_PALMTX_LCD_POWER, 0);
280 	if (ret)
281 		goto err3;
282 
283 	return 0;
284 err3:
285 	gpio_free(GPIO_NR_PALMTX_LCD_POWER);
286 err2:
287 	gpio_free(GPIO_NR_PALMTX_BL_POWER);
288 err:
289 	return ret;
290 }
291 
palmtx_backlight_notify(int brightness)292 static int palmtx_backlight_notify(int brightness)
293 {
294 	gpio_set_value(GPIO_NR_PALMTX_BL_POWER, brightness);
295 	gpio_set_value(GPIO_NR_PALMTX_LCD_POWER, brightness);
296 	return brightness;
297 }
298 
palmtx_backlight_exit(struct device * dev)299 static void palmtx_backlight_exit(struct device *dev)
300 {
301 	gpio_free(GPIO_NR_PALMTX_BL_POWER);
302 	gpio_free(GPIO_NR_PALMTX_LCD_POWER);
303 }
304 
305 static struct platform_pwm_backlight_data palmtx_backlight_data = {
306 	.pwm_id		= 0,
307 	.max_brightness	= PALMTX_MAX_INTENSITY,
308 	.dft_brightness	= PALMTX_MAX_INTENSITY,
309 	.pwm_period_ns	= PALMTX_PERIOD_NS,
310 	.init		= palmtx_backlight_init,
311 	.notify		= palmtx_backlight_notify,
312 	.exit		= palmtx_backlight_exit,
313 };
314 
315 static struct platform_device palmtx_backlight = {
316 	.name	= "pwm-backlight",
317 	.dev	= {
318 		.parent		= &pxa27x_device_pwm0.dev,
319 		.platform_data	= &palmtx_backlight_data,
320 	},
321 };
322 
323 /******************************************************************************
324  * IrDA
325  ******************************************************************************/
palmtx_irda_startup(struct device * dev)326 static int palmtx_irda_startup(struct device *dev)
327 {
328 	int err;
329 	err = gpio_request(GPIO_NR_PALMTX_IR_DISABLE, "IR DISABLE");
330 	if (err)
331 		goto err;
332 	err = gpio_direction_output(GPIO_NR_PALMTX_IR_DISABLE, 1);
333 	if (err)
334 		gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
335 err:
336 	return err;
337 }
338 
palmtx_irda_shutdown(struct device * dev)339 static void palmtx_irda_shutdown(struct device *dev)
340 {
341 	gpio_free(GPIO_NR_PALMTX_IR_DISABLE);
342 }
343 
palmtx_irda_transceiver_mode(struct device * dev,int mode)344 static void palmtx_irda_transceiver_mode(struct device *dev, int mode)
345 {
346 	gpio_set_value(GPIO_NR_PALMTX_IR_DISABLE, mode & IR_OFF);
347 	pxa2xx_transceiver_mode(dev, mode);
348 }
349 
350 static struct pxaficp_platform_data palmtx_ficp_platform_data = {
351 	.startup		= palmtx_irda_startup,
352 	.shutdown		= palmtx_irda_shutdown,
353 	.transceiver_cap	= IR_SIRMODE | IR_FIRMODE | IR_OFF,
354 	.transceiver_mode	= palmtx_irda_transceiver_mode,
355 };
356 
357 /******************************************************************************
358  * UDC
359  ******************************************************************************/
360 static struct pxa2xx_udc_mach_info palmtx_udc_info __initdata = {
361 	.gpio_vbus		= GPIO_NR_PALMTX_USB_DETECT_N,
362 	.gpio_vbus_inverted	= 1,
363 	.gpio_pullup		= GPIO_NR_PALMTX_USB_POWER,
364 	.gpio_pullup_inverted	= 0,
365 };
366 
367 /******************************************************************************
368  * Power supply
369  ******************************************************************************/
power_supply_init(struct device * dev)370 static int power_supply_init(struct device *dev)
371 {
372 	int ret;
373 
374 	ret = gpio_request(GPIO_NR_PALMTX_POWER_DETECT, "CABLE_STATE_AC");
375 	if (ret)
376 		goto err1;
377 	ret = gpio_direction_input(GPIO_NR_PALMTX_POWER_DETECT);
378 	if (ret)
379 		goto err2;
380 
381 	return 0;
382 
383 err2:
384 	gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
385 err1:
386 	return ret;
387 }
388 
palmtx_is_ac_online(void)389 static int palmtx_is_ac_online(void)
390 {
391 	return gpio_get_value(GPIO_NR_PALMTX_POWER_DETECT);
392 }
393 
power_supply_exit(struct device * dev)394 static void power_supply_exit(struct device *dev)
395 {
396 	gpio_free(GPIO_NR_PALMTX_POWER_DETECT);
397 }
398 
399 static char *palmtx_supplicants[] = {
400 	"main-battery",
401 };
402 
403 static struct pda_power_pdata power_supply_info = {
404 	.init            = power_supply_init,
405 	.is_ac_online    = palmtx_is_ac_online,
406 	.exit            = power_supply_exit,
407 	.supplied_to     = palmtx_supplicants,
408 	.num_supplicants = ARRAY_SIZE(palmtx_supplicants),
409 };
410 
411 static struct platform_device power_supply = {
412 	.name = "pda-power",
413 	.id   = -1,
414 	.dev  = {
415 		.platform_data = &power_supply_info,
416 	},
417 };
418 
419 /******************************************************************************
420  * WM97xx battery
421  ******************************************************************************/
422 static struct wm97xx_batt_info wm97xx_batt_pdata = {
423 	.batt_aux	= WM97XX_AUX_ID3,
424 	.temp_aux	= WM97XX_AUX_ID2,
425 	.charge_gpio	= -1,
426 	.max_voltage	= PALMTX_BAT_MAX_VOLTAGE,
427 	.min_voltage	= PALMTX_BAT_MIN_VOLTAGE,
428 	.batt_mult	= 1000,
429 	.batt_div	= 414,
430 	.temp_mult	= 1,
431 	.temp_div	= 1,
432 	.batt_tech	= POWER_SUPPLY_TECHNOLOGY_LIPO,
433 	.batt_name	= "main-batt",
434 };
435 
436 /******************************************************************************
437  * Framebuffer
438  ******************************************************************************/
439 static struct pxafb_mode_info palmtx_lcd_modes[] = {
440 {
441 	.pixclock	= 57692,
442 	.xres		= 320,
443 	.yres		= 480,
444 	.bpp		= 16,
445 
446 	.left_margin	= 32,
447 	.right_margin	= 1,
448 	.upper_margin	= 7,
449 	.lower_margin	= 1,
450 
451 	.hsync_len	= 4,
452 	.vsync_len	= 1,
453 },
454 };
455 
456 static struct pxafb_mach_info palmtx_lcd_screen = {
457 	.modes		= palmtx_lcd_modes,
458 	.num_modes	= ARRAY_SIZE(palmtx_lcd_modes),
459 	.lcd_conn	= LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
460 };
461 
462 /******************************************************************************
463  * Machine init
464  ******************************************************************************/
465 static struct platform_device *devices[] __initdata = {
466 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
467 	&palmtx_pxa_keys,
468 #endif
469 	&palmtx_backlight,
470 	&power_supply,
471 };
472 
473 static struct map_desc palmtx_io_desc[] __initdata = {
474 {
475 	.virtual	= PALMTX_PCMCIA_VIRT,
476 	.pfn		= __phys_to_pfn(PALMTX_PCMCIA_PHYS),
477 	.length		= PALMTX_PCMCIA_SIZE,
478 	.type		= MT_DEVICE
479 },
480 };
481 
palmtx_map_io(void)482 static void __init palmtx_map_io(void)
483 {
484 	pxa_map_io();
485 	iotable_init(palmtx_io_desc, ARRAY_SIZE(palmtx_io_desc));
486 }
487 
488 /* setup udc GPIOs initial state */
palmtx_udc_init(void)489 static void __init palmtx_udc_init(void)
490 {
491 	if (!gpio_request(GPIO_NR_PALMTX_USB_POWER, "UDC Vbus")) {
492 		gpio_direction_output(GPIO_NR_PALMTX_USB_POWER, 1);
493 		gpio_free(GPIO_NR_PALMTX_USB_POWER);
494 	}
495 }
496 
497 
palmtx_init(void)498 static void __init palmtx_init(void)
499 {
500 	pxa2xx_mfp_config(ARRAY_AND_SIZE(palmtx_pin_config));
501 
502 	set_pxa_fb_info(&palmtx_lcd_screen);
503 	pxa_set_mci_info(&palmtx_mci_platform_data);
504 	palmtx_udc_init();
505 	pxa_set_udc_info(&palmtx_udc_info);
506 	pxa_set_ac97_info(NULL);
507 	pxa_set_ficp_info(&palmtx_ficp_platform_data);
508 	pxa_set_keypad_info(&palmtx_keypad_platform_data);
509 	wm97xx_bat_set_pdata(&wm97xx_batt_pdata);
510 
511 	platform_add_devices(devices, ARRAY_SIZE(devices));
512 }
513 
514 MACHINE_START(PALMTX, "Palm T|X")
515 	.phys_io	= PALMTX_PHYS_IO_START,
516 	.io_pg_offst	= io_p2v(0x40000000),
517 	.boot_params	= 0xa0000100,
518 	.map_io		= palmtx_map_io,
519 	.init_irq	= pxa27x_init_irq,
520 	.timer		= &pxa_timer,
521 	.init_machine	= palmtx_init
522 MACHINE_END
523