1 /*
2  * Support for HP iPAQ hx4700 PDAs.
3  *
4  * Copyright (c) 2008-2009 Philipp Zabel
5  *
6  * Based on code:
7  *    Copyright (c) 2004 Hewlett-Packard Company.
8  *    Copyright (c) 2005 SDG Systems, LLC
9  *    Copyright (c) 2006 Anton Vorontsov <cbou@mail.ru>
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  */
16 
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/platform_device.h>
20 #include <linux/delay.h>
21 #include <linux/fb.h>
22 #include <linux/gpio.h>
23 #include <linux/gpio_keys.h>
24 #include <linux/input.h>
25 #include <linux/input/navpoint.h>
26 #include <linux/lcd.h>
27 #include <linux/mfd/asic3.h>
28 #include <linux/mtd/physmap.h>
29 #include <linux/pda_power.h>
30 #include <linux/platform_data/gpio-htc-egpio.h>
31 #include <linux/pwm.h>
32 #include <linux/pwm_backlight.h>
33 #include <linux/regulator/driver.h>
34 #include <linux/regulator/gpio-regulator.h>
35 #include <linux/regulator/machine.h>
36 #include <linux/regulator/max1586.h>
37 #include <linux/spi/ads7846.h>
38 #include <linux/spi/spi.h>
39 #include <linux/spi/pxa2xx_spi.h>
40 #include <linux/usb/gpio_vbus.h>
41 #include <linux/platform_data/i2c-pxa.h>
42 
43 #include <mach/hardware.h>
44 #include <asm/mach-types.h>
45 #include <asm/mach/arch.h>
46 
47 #include "pxa27x.h"
48 #include <mach/hx4700.h>
49 #include <linux/platform_data/irda-pxaficp.h>
50 
51 #include <sound/ak4641.h>
52 #include <video/platform_lcd.h>
53 #include <video/w100fb.h>
54 
55 #include "devices.h"
56 #include "generic.h"
57 #include "udc.h"
58 
59 /* Physical address space information */
60 
61 #define ATI_W3220_PHYS  PXA_CS2_PHYS /* ATI Imageon 3220 Graphics */
62 #define ASIC3_PHYS      PXA_CS3_PHYS
63 #define ASIC3_SD_PHYS   (PXA_CS3_PHYS + 0x02000000)
64 
65 static unsigned long hx4700_pin_config[] __initdata = {
66 
67 	/* SDRAM and Static Memory I/O Signals */
68 	GPIO20_nSDCS_2,
69 	GPIO21_nSDCS_3,
70 	GPIO15_nCS_1,
71 	GPIO78_nCS_2,   /* W3220 */
72 	GPIO79_nCS_3,   /* ASIC3 */
73 	GPIO80_nCS_4,
74 	GPIO33_nCS_5,	/* EGPIO, WLAN */
75 
76 	/* PC CARD */
77 	GPIO48_nPOE,
78 	GPIO49_nPWE,
79 	GPIO50_nPIOR,
80 	GPIO51_nPIOW,
81 	GPIO54_nPCE_2,
82 	GPIO55_nPREG,
83 	GPIO56_nPWAIT,
84 	GPIO57_nIOIS16,
85 	GPIO85_nPCE_1,
86 	GPIO104_PSKTSEL,
87 
88 	/* I2C */
89 	GPIO117_I2C_SCL,
90 	GPIO118_I2C_SDA,
91 
92 	/* FFUART (RS-232) */
93 	GPIO34_FFUART_RXD,
94 	GPIO35_FFUART_CTS,
95 	GPIO36_FFUART_DCD,
96 	GPIO37_FFUART_DSR,
97 	GPIO38_FFUART_RI,
98 	GPIO39_FFUART_TXD,
99 	GPIO40_FFUART_DTR,
100 	GPIO41_FFUART_RTS,
101 
102 	/* BTUART */
103 	GPIO42_BTUART_RXD,
104 	GPIO43_BTUART_TXD_LPM_LOW,
105 	GPIO44_BTUART_CTS,
106 	GPIO45_BTUART_RTS_LPM_LOW,
107 
108 	/* STUART (IRDA) */
109 	GPIO46_STUART_RXD,
110 	GPIO47_STUART_TXD,
111 
112 	/* PWM 1 (Backlight) */
113 	GPIO17_PWM1_OUT,
114 
115 	/* I2S */
116 	GPIO28_I2S_BITCLK_OUT,
117 	GPIO29_I2S_SDATA_IN,
118 	GPIO30_I2S_SDATA_OUT,
119 	GPIO31_I2S_SYNC,
120 	GPIO113_I2S_SYSCLK,
121 
122 	/* SSP 1 (NavPoint) */
123 	GPIO23_SSP1_SCLK_IN,
124 	GPIO24_SSP1_SFRM,
125 	GPIO25_SSP1_TXD,
126 	GPIO26_SSP1_RXD,
127 
128 	/* SSP 2 (TSC2046) */
129 	GPIO19_SSP2_SCLK,
130 	GPIO86_SSP2_RXD,
131 	GPIO87_SSP2_TXD,
132 	GPIO88_GPIO | MFP_LPM_DRIVE_HIGH,	/* TSC2046_CS */
133 
134 	/* BQ24022 Regulator */
135 	GPIO72_GPIO | MFP_LPM_KEEP_OUTPUT,	/* BQ24022_nCHARGE_EN */
136 	GPIO96_GPIO | MFP_LPM_KEEP_OUTPUT,	/* BQ24022_ISET2 */
137 
138 	/* HX4700 specific input GPIOs */
139 	GPIO12_GPIO | WAKEUP_ON_EDGE_RISE,	/* ASIC3_IRQ */
140 	GPIO13_GPIO,	/* W3220_IRQ */
141 	GPIO14_GPIO,	/* nWLAN_IRQ */
142 
143 	/* HX4700 specific output GPIOs */
144 	GPIO61_GPIO | MFP_LPM_DRIVE_HIGH,	/* W3220_nRESET */
145 	GPIO71_GPIO | MFP_LPM_DRIVE_HIGH,	/* ASIC3_nRESET */
146 	GPIO81_GPIO | MFP_LPM_DRIVE_HIGH,	/* CPU_GP_nRESET */
147 	GPIO116_GPIO | MFP_LPM_DRIVE_HIGH,	/* CPU_HW_nRESET */
148 	GPIO102_GPIO | MFP_LPM_DRIVE_LOW,	/* SYNAPTICS_POWER_ON */
149 
150 	GPIO10_GPIO,	/* GSM_IRQ */
151 	GPIO13_GPIO,	/* CPLD_IRQ */
152 	GPIO107_GPIO,	/* DS1WM_IRQ */
153 	GPIO108_GPIO,	/* GSM_READY */
154 	GPIO58_GPIO,	/* TSC2046_nPENIRQ */
155 	GPIO66_GPIO,	/* nSDIO_IRQ */
156 };
157 
158 /*
159  * IRDA
160  */
161 
162 static struct pxaficp_platform_data ficp_info = {
163 	.gpio_pwdown		= GPIO105_HX4700_nIR_ON,
164 	.transceiver_cap	= IR_SIRMODE | IR_OFF,
165 };
166 
167 /*
168  * GPIO Keys
169  */
170 
171 #define INIT_KEY(_code, _gpio, _active_low, _desc)	\
172 	{						\
173 		.code       = KEY_##_code,		\
174 		.gpio       = _gpio,			\
175 		.active_low = _active_low,		\
176 		.desc       = _desc,			\
177 		.type       = EV_KEY,			\
178 		.wakeup     = 1,			\
179 	}
180 
181 static struct gpio_keys_button gpio_keys_buttons[] = {
182 	INIT_KEY(POWER,       GPIO0_HX4700_nKEY_POWER,   1, "Power button"),
183 	INIT_KEY(MAIL,        GPIO94_HX4700_KEY_MAIL,    0, "Mail button"),
184 	INIT_KEY(ADDRESSBOOK, GPIO99_HX4700_KEY_CONTACTS,0, "Contacts button"),
185 	INIT_KEY(RECORD,      GPIOD6_nKEY_RECORD,        1, "Record button"),
186 	INIT_KEY(CALENDAR,    GPIOD1_nKEY_CALENDAR,      1, "Calendar button"),
187 	INIT_KEY(HOMEPAGE,    GPIOD3_nKEY_HOME,          1, "Home button"),
188 };
189 
190 static struct gpio_keys_platform_data gpio_keys_data = {
191 	.buttons = gpio_keys_buttons,
192 	.nbuttons = ARRAY_SIZE(gpio_keys_buttons),
193 };
194 
195 static struct platform_device gpio_keys = {
196 	.name = "gpio-keys",
197 	.dev  = {
198 		.platform_data = &gpio_keys_data,
199 	},
200 	.id   = -1,
201 };
202 
203 /*
204  * Synaptics NavPoint connected to SSP1
205  */
206 
207 static struct navpoint_platform_data navpoint_platform_data = {
208 	.port	= 1,
209 	.gpio	= GPIO102_HX4700_SYNAPTICS_POWER_ON,
210 };
211 
212 static struct platform_device navpoint = {
213 	.name	= "navpoint",
214 	.id	= -1,
215 	.dev = {
216 		.platform_data = &navpoint_platform_data,
217 	},
218 };
219 
220 /*
221  * ASIC3
222  */
223 
224 static u16 asic3_gpio_config[] = {
225 	/* ASIC3 GPIO banks A and B along with some of C and D
226 	   implement the buffering for the CF slot. */
227 	ASIC3_CONFIG_GPIO(0, 1, 1, 0),
228 	ASIC3_CONFIG_GPIO(1, 1, 1, 0),
229 	ASIC3_CONFIG_GPIO(2, 1, 1, 0),
230 	ASIC3_CONFIG_GPIO(3, 1, 1, 0),
231 	ASIC3_CONFIG_GPIO(4, 1, 1, 0),
232 	ASIC3_CONFIG_GPIO(5, 1, 1, 0),
233 	ASIC3_CONFIG_GPIO(6, 1, 1, 0),
234 	ASIC3_CONFIG_GPIO(7, 1, 1, 0),
235 	ASIC3_CONFIG_GPIO(8, 1, 1, 0),
236 	ASIC3_CONFIG_GPIO(9, 1, 1, 0),
237 	ASIC3_CONFIG_GPIO(10, 1, 1, 0),
238 	ASIC3_CONFIG_GPIO(11, 1, 1, 0),
239 	ASIC3_CONFIG_GPIO(12, 1, 1, 0),
240 	ASIC3_CONFIG_GPIO(13, 1, 1, 0),
241 	ASIC3_CONFIG_GPIO(14, 1, 1, 0),
242 	ASIC3_CONFIG_GPIO(15, 1, 1, 0),
243 
244 	ASIC3_CONFIG_GPIO(16, 1, 1, 0),
245 	ASIC3_CONFIG_GPIO(17, 1, 1, 0),
246 	ASIC3_CONFIG_GPIO(18, 1, 1, 0),
247 	ASIC3_CONFIG_GPIO(19, 1, 1, 0),
248 	ASIC3_CONFIG_GPIO(20, 1, 1, 0),
249 	ASIC3_CONFIG_GPIO(21, 1, 1, 0),
250 	ASIC3_CONFIG_GPIO(22, 1, 1, 0),
251 	ASIC3_CONFIG_GPIO(23, 1, 1, 0),
252 	ASIC3_CONFIG_GPIO(24, 1, 1, 0),
253 	ASIC3_CONFIG_GPIO(25, 1, 1, 0),
254 	ASIC3_CONFIG_GPIO(26, 1, 1, 0),
255 	ASIC3_CONFIG_GPIO(27, 1, 1, 0),
256 	ASIC3_CONFIG_GPIO(28, 1, 1, 0),
257 	ASIC3_CONFIG_GPIO(29, 1, 1, 0),
258 	ASIC3_CONFIG_GPIO(30, 1, 1, 0),
259 	ASIC3_CONFIG_GPIO(31, 1, 1, 0),
260 
261 	/* GPIOC - CF, LEDs, SD */
262 	ASIC3_GPIOC0_LED0,		/* red */
263 	ASIC3_GPIOC1_LED1,		/* green */
264 	ASIC3_GPIOC2_LED2,		/* blue */
265 	ASIC3_GPIOC5_nCIOW,
266 	ASIC3_GPIOC6_nCIOR,
267 	ASIC3_GPIOC7_nPCE_1,
268 	ASIC3_GPIOC8_nPCE_2,
269 	ASIC3_GPIOC9_nPOE,
270 	ASIC3_GPIOC10_nPWE,
271 	ASIC3_GPIOC11_PSKTSEL,
272 	ASIC3_GPIOC12_nPREG,
273 	ASIC3_GPIOC13_nPWAIT,
274 	ASIC3_GPIOC14_nPIOIS16,
275 	ASIC3_GPIOC15_nPIOR,
276 
277 	/* GPIOD: input GPIOs, CF */
278 	ASIC3_GPIOD4_CF_nCD,
279 	ASIC3_GPIOD11_nCIOIS16,
280 	ASIC3_GPIOD12_nCWAIT,
281 	ASIC3_GPIOD15_nPIOW,
282 };
283 
284 static struct asic3_led asic3_leds[ASIC3_NUM_LEDS] = {
285 	[0] = {
286 		.name = "hx4700:amber",
287 		.default_trigger = "ds2760-battery.0-charging-blink-full-solid",
288 	},
289 	[1] = {
290 		.name = "hx4700:green",
291 		.default_trigger = "unused",
292 	},
293 	[2] = {
294 		.name = "hx4700:blue",
295 		.default_trigger = "hx4700-radio",
296 	},
297 };
298 
299 static struct resource asic3_resources[] = {
300 	/* GPIO part */
301 	[0] = DEFINE_RES_MEM(ASIC3_PHYS, ASIC3_MAP_SIZE_16BIT),
302 	[1] = DEFINE_RES_IRQ(PXA_GPIO_TO_IRQ(GPIO12_HX4700_ASIC3_IRQ)),
303 	/* SD part */
304 	[2] = DEFINE_RES_MEM(ASIC3_SD_PHYS, ASIC3_MAP_SIZE_16BIT),
305 	[3] = DEFINE_RES_IRQ(PXA_GPIO_TO_IRQ(GPIO66_HX4700_ASIC3_nSDIO_IRQ)),
306 };
307 
308 static struct asic3_platform_data asic3_platform_data = {
309 	.gpio_config     = asic3_gpio_config,
310 	.gpio_config_num = ARRAY_SIZE(asic3_gpio_config),
311 	.irq_base        = IRQ_BOARD_START,
312 	.gpio_base       = HX4700_ASIC3_GPIO_BASE,
313 	.clock_rate      = 4000000,
314 	.leds            = asic3_leds,
315 };
316 
317 static struct platform_device asic3 = {
318 	.name          = "asic3",
319 	.id            = -1,
320 	.resource      = asic3_resources,
321 	.num_resources = ARRAY_SIZE(asic3_resources),
322 	.dev = {
323 		.platform_data = &asic3_platform_data,
324 	},
325 };
326 
327 /*
328  * EGPIO
329  */
330 
331 static struct resource egpio_resources[] = {
332 	[0] = DEFINE_RES_MEM(PXA_CS5_PHYS, 0x4),
333 };
334 
335 static struct htc_egpio_chip egpio_chips[] = {
336 	[0] = {
337 		.reg_start = 0,
338 		.gpio_base = HX4700_EGPIO_BASE,
339 		.num_gpios = 8,
340 		.direction = HTC_EGPIO_OUTPUT,
341 	},
342 };
343 
344 static struct htc_egpio_platform_data egpio_info = {
345 	.reg_width = 16,
346 	.bus_width = 16,
347 	.chip      = egpio_chips,
348 	.num_chips = ARRAY_SIZE(egpio_chips),
349 };
350 
351 static struct platform_device egpio = {
352 	.name          = "htc-egpio",
353 	.id            = -1,
354 	.resource      = egpio_resources,
355 	.num_resources = ARRAY_SIZE(egpio_resources),
356 	.dev = {
357 		.platform_data = &egpio_info,
358 	},
359 };
360 
361 /*
362  * LCD - Sony display connected to ATI Imageon w3220
363  */
364 
sony_lcd_init(void)365 static void sony_lcd_init(void)
366 {
367 	gpio_set_value(GPIO84_HX4700_LCD_SQN, 1);
368 	gpio_set_value(GPIO110_HX4700_LCD_LVDD_3V3_ON, 0);
369 	gpio_set_value(GPIO111_HX4700_LCD_AVDD_3V3_ON, 0);
370 	gpio_set_value(GPIO70_HX4700_LCD_SLIN1, 0);
371 	gpio_set_value(GPIO62_HX4700_LCD_nRESET, 0);
372 	mdelay(10);
373 	gpio_set_value(GPIO59_HX4700_LCD_PC1, 0);
374 	gpio_set_value(GPIO110_HX4700_LCD_LVDD_3V3_ON, 0);
375 	mdelay(20);
376 
377 	gpio_set_value(GPIO110_HX4700_LCD_LVDD_3V3_ON, 1);
378 	mdelay(5);
379 	gpio_set_value(GPIO111_HX4700_LCD_AVDD_3V3_ON, 1);
380 
381 	/* FIXME: init w3220 registers here */
382 
383 	mdelay(5);
384 	gpio_set_value(GPIO70_HX4700_LCD_SLIN1, 1);
385 	mdelay(10);
386 	gpio_set_value(GPIO62_HX4700_LCD_nRESET, 1);
387 	mdelay(10);
388 	gpio_set_value(GPIO59_HX4700_LCD_PC1, 1);
389 	mdelay(10);
390 	gpio_set_value(GPIO112_HX4700_LCD_N2V7_7V3_ON, 1);
391 }
392 
sony_lcd_off(void)393 static void sony_lcd_off(void)
394 {
395 	gpio_set_value(GPIO59_HX4700_LCD_PC1, 0);
396 	gpio_set_value(GPIO62_HX4700_LCD_nRESET, 0);
397 	mdelay(10);
398 	gpio_set_value(GPIO112_HX4700_LCD_N2V7_7V3_ON, 0);
399 	mdelay(10);
400 	gpio_set_value(GPIO111_HX4700_LCD_AVDD_3V3_ON, 0);
401 	mdelay(10);
402 	gpio_set_value(GPIO110_HX4700_LCD_LVDD_3V3_ON, 0);
403 }
404 
405 #ifdef CONFIG_PM
w3220_lcd_suspend(struct w100fb_par * wfb)406 static void w3220_lcd_suspend(struct w100fb_par *wfb)
407 {
408 	sony_lcd_off();
409 }
410 
w3220_lcd_resume(struct w100fb_par * wfb)411 static void w3220_lcd_resume(struct w100fb_par *wfb)
412 {
413 	sony_lcd_init();
414 }
415 #else
416 #define w3220_lcd_resume	NULL
417 #define w3220_lcd_suspend	NULL
418 #endif
419 
420 static struct w100_tg_info w3220_tg_info = {
421 	.suspend	= w3220_lcd_suspend,
422 	.resume		= w3220_lcd_resume,
423 };
424 
425 /*  				 W3220_VGA		QVGA */
426 static struct w100_gen_regs w3220_regs = {
427 	.lcd_format =        0x00000003,
428 	.lcdd_cntl1 =        0x00000000,
429 	.lcdd_cntl2 =        0x0003ffff,
430 	.genlcd_cntl1 =      0x00abf003,	/* 0x00fff003 */
431 	.genlcd_cntl2 =      0x00000003,
432 	.genlcd_cntl3 =      0x000102aa,
433 };
434 
435 static struct w100_mode w3220_modes[] = {
436 {
437 	.xres 		= 480,
438 	.yres 		= 640,
439 	.left_margin 	= 15,
440 	.right_margin 	= 16,
441 	.upper_margin 	= 8,
442 	.lower_margin 	= 7,
443 	.crtc_ss	= 0x00000000,
444 	.crtc_ls	= 0xa1ff01f9,	/* 0x21ff01f9 */
445 	.crtc_gs	= 0xc0000000,	/* 0x40000000 */
446 	.crtc_vpos_gs	= 0x0000028f,
447 	.crtc_ps1_active = 0x00000000,	/* 0x41060010 */
448 	.crtc_rev	= 0,
449 	.crtc_dclk	= 0x80000000,
450 	.crtc_gclk	= 0x040a0104,
451 	.crtc_goe	= 0,
452 	.pll_freq 	= 95,
453 	.pixclk_divider = 4,
454 	.pixclk_divider_rotated = 4,
455 	.pixclk_src     = CLK_SRC_PLL,
456 	.sysclk_divider = 0,
457 	.sysclk_src     = CLK_SRC_PLL,
458 },
459 {
460 	.xres 		= 240,
461 	.yres 		= 320,
462 	.left_margin 	= 9,
463 	.right_margin 	= 8,
464 	.upper_margin 	= 5,
465 	.lower_margin 	= 4,
466 	.crtc_ss	= 0x80150014,
467 	.crtc_ls        = 0xa0fb00f7,
468 	.crtc_gs	= 0xc0080007,
469 	.crtc_vpos_gs	= 0x00080007,
470 	.crtc_rev	= 0x0000000a,
471 	.crtc_dclk	= 0x81700030,
472 	.crtc_gclk	= 0x8015010f,
473 	.crtc_goe	= 0x00000000,
474 	.pll_freq 	= 95,
475 	.pixclk_divider = 4,
476 	.pixclk_divider_rotated = 4,
477 	.pixclk_src     = CLK_SRC_PLL,
478 	.sysclk_divider = 0,
479 	.sysclk_src     = CLK_SRC_PLL,
480 },
481 };
482 
483 struct w100_mem_info w3220_mem_info = {
484 	.ext_cntl        = 0x09640011,
485 	.sdram_mode_reg  = 0x00600021,
486 	.ext_timing_cntl = 0x1a001545,	/* 0x15001545 */
487 	.io_cntl         = 0x7ddd7333,
488 	.size            = 0x1fffff,
489 };
490 
491 struct w100_bm_mem_info w3220_bm_mem_info = {
492 	.ext_mem_bw = 0x50413e01,
493 	.offset = 0,
494 	.ext_timing_ctl = 0x00043f7f,
495 	.ext_cntl = 0x00000010,
496 	.mode_reg = 0x00250000,
497 	.io_cntl = 0x0fff0000,
498 	.config = 0x08301480,
499 };
500 
501 static struct w100_gpio_regs w3220_gpio_info = {
502 	.init_data1 = 0xdfe00100,	/* GPIO_DATA */
503 	.gpio_dir1  = 0xffff0000,	/* GPIO_CNTL1 */
504 	.gpio_oe1   = 0x00000000,	/* GPIO_CNTL2 */
505 	.init_data2 = 0x00000000,	/* GPIO_DATA2 */
506 	.gpio_dir2  = 0x00000000,	/* GPIO_CNTL3 */
507 	.gpio_oe2   = 0x00000000,	/* GPIO_CNTL4 */
508 };
509 
510 static struct w100fb_mach_info w3220_info = {
511 	.tg        = &w3220_tg_info,
512 	.mem       = &w3220_mem_info,
513 	.bm_mem    = &w3220_bm_mem_info,
514 	.gpio      = &w3220_gpio_info,
515 	.regs      = &w3220_regs,
516 	.modelist  = w3220_modes,
517 	.num_modes = 2,
518 	.xtal_freq = 16000000,
519 };
520 
521 static struct resource w3220_resources[] = {
522 	[0] = DEFINE_RES_MEM(ATI_W3220_PHYS, SZ_16M),
523 };
524 
525 static struct platform_device w3220 = {
526 	.name	= "w100fb",
527 	.id	= -1,
528 	.dev	= {
529 		.platform_data = &w3220_info,
530 	},
531 	.num_resources = ARRAY_SIZE(w3220_resources),
532 	.resource      = w3220_resources,
533 };
534 
hx4700_lcd_set_power(struct plat_lcd_data * pd,unsigned int power)535 static void hx4700_lcd_set_power(struct plat_lcd_data *pd, unsigned int power)
536 {
537 	if (power)
538 		sony_lcd_init();
539 	else
540 		sony_lcd_off();
541 }
542 
543 static struct plat_lcd_data hx4700_lcd_data = {
544 	.set_power = hx4700_lcd_set_power,
545 };
546 
547 static struct platform_device hx4700_lcd = {
548 	.name = "platform-lcd",
549 	.id   = -1,
550 	.dev  = {
551 		.platform_data = &hx4700_lcd_data,
552 		.parent        = &w3220.dev,
553 	},
554 };
555 
556 /*
557  * Backlight
558  */
559 
560 static struct platform_pwm_backlight_data backlight_data = {
561 	.max_brightness = 200,
562 	.dft_brightness = 100,
563 	.enable_gpio    = -1,
564 };
565 
566 static struct platform_device backlight = {
567 	.name = "pwm-backlight",
568 	.id   = -1,
569 	.dev  = {
570 		.parent        = &pxa27x_device_pwm1.dev,
571 		.platform_data = &backlight_data,
572 	},
573 };
574 
575 static struct pwm_lookup hx4700_pwm_lookup[] = {
576 	PWM_LOOKUP("pxa27x-pwm.1", 0, "pwm-backlight", NULL,
577 		   30923, PWM_POLARITY_NORMAL),
578 };
579 
580 /*
581  * USB "Transceiver"
582  */
583 
584 static struct gpio_vbus_mach_info gpio_vbus_info = {
585 	.gpio_pullup        = GPIO76_HX4700_USBC_PUEN,
586 	.gpio_vbus          = GPIOD14_nUSBC_DETECT,
587 	.gpio_vbus_inverted = 1,
588 };
589 
590 static struct platform_device gpio_vbus = {
591 	.name          = "gpio-vbus",
592 	.id            = -1,
593 	.dev = {
594 		.platform_data = &gpio_vbus_info,
595 	},
596 };
597 
598 static struct pxa2xx_udc_mach_info hx4700_udc_info;
599 
600 /*
601  * Touchscreen - TSC2046 connected to SSP2
602  */
603 
604 static const struct ads7846_platform_data tsc2046_info = {
605 	.model            = 7846,
606 	.vref_delay_usecs = 100,
607 	.pressure_max     = 1024,
608 	.debounce_max     = 10,
609 	.debounce_tol     = 3,
610 	.debounce_rep     = 1,
611 	.gpio_pendown     = GPIO58_HX4700_TSC2046_nPENIRQ,
612 };
613 
614 static struct pxa2xx_spi_chip tsc2046_chip = {
615 	.tx_threshold = 1,
616 	.rx_threshold = 2,
617 	.timeout      = 64,
618 	.gpio_cs      = GPIO88_HX4700_TSC2046_CS,
619 };
620 
621 static struct spi_board_info tsc2046_board_info[] __initdata = {
622 	{
623 		.modalias        = "ads7846",
624 		.bus_num         = 2,
625 		.max_speed_hz    = 2600000, /* 100 kHz sample rate */
626 		.irq             = PXA_GPIO_TO_IRQ(GPIO58_HX4700_TSC2046_nPENIRQ),
627 		.platform_data   = &tsc2046_info,
628 		.controller_data = &tsc2046_chip,
629 	},
630 };
631 
632 static struct pxa2xx_spi_master pxa_ssp2_master_info = {
633 	.num_chipselect = 1,
634 	.enable_dma     = 1,
635 };
636 
637 /*
638  * External power
639  */
640 
power_supply_init(struct device * dev)641 static int power_supply_init(struct device *dev)
642 {
643 	return gpio_request(GPIOD9_nAC_IN, "AC charger detect");
644 }
645 
hx4700_is_ac_online(void)646 static int hx4700_is_ac_online(void)
647 {
648 	return !gpio_get_value(GPIOD9_nAC_IN);
649 }
650 
power_supply_exit(struct device * dev)651 static void power_supply_exit(struct device *dev)
652 {
653 	gpio_free(GPIOD9_nAC_IN);
654 }
655 
656 static char *hx4700_supplicants[] = {
657 	"ds2760-battery.0", "backup-battery"
658 };
659 
660 static struct pda_power_pdata power_supply_info = {
661 	.init            = power_supply_init,
662 	.is_ac_online    = hx4700_is_ac_online,
663 	.exit            = power_supply_exit,
664 	.supplied_to     = hx4700_supplicants,
665 	.num_supplicants = ARRAY_SIZE(hx4700_supplicants),
666 };
667 
668 static struct resource power_supply_resources[] = {
669 	[0] = DEFINE_RES_NAMED(PXA_GPIO_TO_IRQ(GPIOD9_nAC_IN), 1, "ac",
670 		IORESOURCE_IRQ |
671 		IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE),
672 	[1] = DEFINE_RES_NAMED(PXA_GPIO_TO_IRQ(GPIOD14_nUSBC_DETECT), 1, "usb",
673 		IORESOURCE_IRQ |
674 		IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE),
675 };
676 
677 static struct platform_device power_supply = {
678 	.name = "pda-power",
679 	.id   = -1,
680 	.dev  = {
681 		.platform_data = &power_supply_info,
682 	},
683 	.resource      = power_supply_resources,
684 	.num_resources = ARRAY_SIZE(power_supply_resources),
685 };
686 
687 /*
688  * Battery charger
689  */
690 
691 static struct regulator_consumer_supply bq24022_consumers[] = {
692 	REGULATOR_SUPPLY("vbus_draw", NULL),
693 	REGULATOR_SUPPLY("ac_draw", NULL),
694 };
695 
696 static struct regulator_init_data bq24022_init_data = {
697 	.constraints = {
698 		.max_uA         = 500000,
699 		.valid_ops_mask = REGULATOR_CHANGE_CURRENT|REGULATOR_CHANGE_STATUS,
700 	},
701 	.num_consumer_supplies  = ARRAY_SIZE(bq24022_consumers),
702 	.consumer_supplies      = bq24022_consumers,
703 };
704 
705 static struct gpio bq24022_gpios[] = {
706 	{ GPIO96_HX4700_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" },
707 };
708 
709 static struct gpio_regulator_state bq24022_states[] = {
710 	{ .value = 100000, .gpios = (0 << 0) },
711 	{ .value = 500000, .gpios = (1 << 0) },
712 };
713 
714 static struct gpio_regulator_config bq24022_info = {
715 	.supply_name = "bq24022",
716 
717 	.enable_gpio = GPIO72_HX4700_BQ24022_nCHARGE_EN,
718 	.enable_high = 0,
719 	.enabled_at_boot = 0,
720 
721 	.gpios = bq24022_gpios,
722 	.nr_gpios = ARRAY_SIZE(bq24022_gpios),
723 
724 	.states = bq24022_states,
725 	.nr_states = ARRAY_SIZE(bq24022_states),
726 
727 	.type = REGULATOR_CURRENT,
728 	.init_data = &bq24022_init_data,
729 };
730 
731 static struct platform_device bq24022 = {
732 	.name = "gpio-regulator",
733 	.id   = -1,
734 	.dev  = {
735 		.platform_data = &bq24022_info,
736 	},
737 };
738 
739 /*
740  * StrataFlash
741  */
742 
hx4700_set_vpp(struct platform_device * pdev,int vpp)743 static void hx4700_set_vpp(struct platform_device *pdev, int vpp)
744 {
745 	gpio_set_value(GPIO91_HX4700_FLASH_VPEN, vpp);
746 }
747 
748 static struct resource strataflash_resource[] = {
749 	[0] = DEFINE_RES_MEM(PXA_CS0_PHYS, SZ_64M),
750 	[1] = DEFINE_RES_MEM(PXA_CS0_PHYS + SZ_64M, SZ_64M),
751 };
752 
753 static struct physmap_flash_data strataflash_data = {
754 	.width = 4,
755 	.set_vpp = hx4700_set_vpp,
756 };
757 
758 static struct platform_device strataflash = {
759 	.name          = "physmap-flash",
760 	.id            = -1,
761 	.resource      = strataflash_resource,
762 	.num_resources = ARRAY_SIZE(strataflash_resource),
763 	.dev = {
764 		.platform_data = &strataflash_data,
765 	},
766 };
767 
768 /*
769  * Maxim MAX1587A on PI2C
770  */
771 
772 static struct regulator_consumer_supply max1587a_consumer =
773 	REGULATOR_SUPPLY("vcc_core", NULL);
774 
775 static struct regulator_init_data max1587a_v3_info = {
776 	.constraints = {
777 		.name = "vcc_core range",
778 		.min_uV =  900000,
779 		.max_uV = 1705000,
780 		.always_on = 1,
781 		.valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
782 	},
783 	.num_consumer_supplies = 1,
784 	.consumer_supplies     = &max1587a_consumer,
785 };
786 
787 static struct max1586_subdev_data max1587a_subdev = {
788 	.name = "vcc_core",
789 	.id   = MAX1586_V3,
790 	.platform_data = &max1587a_v3_info,
791 };
792 
793 static struct max1586_platform_data max1587a_info = {
794 	.num_subdevs = 1,
795 	.subdevs     = &max1587a_subdev,
796 	.v3_gain     = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
797 };
798 
799 static struct i2c_board_info __initdata pi2c_board_info[] = {
800 	{
801 		I2C_BOARD_INFO("max1586", 0x14),
802 		.platform_data = &max1587a_info,
803 	},
804 };
805 
806 /*
807  * Asahi Kasei AK4641 on I2C
808  */
809 
810 static struct ak4641_platform_data ak4641_info = {
811 	.gpio_power = GPIO27_HX4700_CODEC_ON,
812 	.gpio_npdn  = GPIO109_HX4700_CODEC_nPDN,
813 };
814 
815 static struct i2c_board_info i2c_board_info[] __initdata = {
816 	{
817 		I2C_BOARD_INFO("ak4641", 0x12),
818 		.platform_data = &ak4641_info,
819 	},
820 };
821 
822 static struct platform_device audio = {
823 	.name	= "hx4700-audio",
824 	.id	= -1,
825 };
826 
827 
828 /*
829  * Platform devices
830  */
831 
832 static struct platform_device *devices[] __initdata = {
833 	&asic3,
834 	&gpio_keys,
835 	&navpoint,
836 	&backlight,
837 	&w3220,
838 	&hx4700_lcd,
839 	&egpio,
840 	&bq24022,
841 	&gpio_vbus,
842 	&power_supply,
843 	&strataflash,
844 	&audio,
845 };
846 
847 static struct gpio global_gpios[] = {
848 	{ GPIO12_HX4700_ASIC3_IRQ, GPIOF_IN, "ASIC3_IRQ" },
849 	{ GPIO13_HX4700_W3220_IRQ, GPIOF_IN, "W3220_IRQ" },
850 	{ GPIO14_HX4700_nWLAN_IRQ, GPIOF_IN, "WLAN_IRQ" },
851 	{ GPIO59_HX4700_LCD_PC1,          GPIOF_OUT_INIT_HIGH, "LCD_PC1" },
852 	{ GPIO62_HX4700_LCD_nRESET,       GPIOF_OUT_INIT_HIGH, "LCD_RESET" },
853 	{ GPIO70_HX4700_LCD_SLIN1,        GPIOF_OUT_INIT_HIGH, "LCD_SLIN1" },
854 	{ GPIO84_HX4700_LCD_SQN,          GPIOF_OUT_INIT_HIGH, "LCD_SQN" },
855 	{ GPIO110_HX4700_LCD_LVDD_3V3_ON, GPIOF_OUT_INIT_HIGH, "LCD_LVDD" },
856 	{ GPIO111_HX4700_LCD_AVDD_3V3_ON, GPIOF_OUT_INIT_HIGH, "LCD_AVDD" },
857 	{ GPIO32_HX4700_RS232_ON,         GPIOF_OUT_INIT_HIGH, "RS232_ON" },
858 	{ GPIO61_HX4700_W3220_nRESET,     GPIOF_OUT_INIT_HIGH, "W3220_nRESET" },
859 	{ GPIO71_HX4700_ASIC3_nRESET,     GPIOF_OUT_INIT_HIGH, "ASIC3_nRESET" },
860 	{ GPIO81_HX4700_CPU_GP_nRESET,    GPIOF_OUT_INIT_HIGH, "CPU_GP_nRESET" },
861 	{ GPIO82_HX4700_EUART_RESET,      GPIOF_OUT_INIT_HIGH, "EUART_RESET" },
862 	{ GPIO116_HX4700_CPU_HW_nRESET,   GPIOF_OUT_INIT_HIGH, "CPU_HW_nRESET" },
863 };
864 
hx4700_init(void)865 static void __init hx4700_init(void)
866 {
867 	int ret;
868 
869 	PCFR = PCFR_GPR_EN | PCFR_OPDE;
870 
871 	pxa2xx_mfp_config(ARRAY_AND_SIZE(hx4700_pin_config));
872 	gpio_set_wake(GPIO12_HX4700_ASIC3_IRQ, 1);
873 	ret = gpio_request_array(ARRAY_AND_SIZE(global_gpios));
874 	if (ret)
875 		pr_err ("hx4700: Failed to request GPIOs.\n");
876 
877 	pxa_set_ffuart_info(NULL);
878 	pxa_set_btuart_info(NULL);
879 	pxa_set_stuart_info(NULL);
880 
881 	platform_add_devices(devices, ARRAY_SIZE(devices));
882 	pwm_add_table(hx4700_pwm_lookup, ARRAY_SIZE(hx4700_pwm_lookup));
883 
884 	pxa_set_ficp_info(&ficp_info);
885 	pxa27x_set_i2c_power_info(NULL);
886 	pxa_set_i2c_info(NULL);
887 	i2c_register_board_info(0, ARRAY_AND_SIZE(i2c_board_info));
888 	i2c_register_board_info(1, ARRAY_AND_SIZE(pi2c_board_info));
889 	pxa2xx_set_spi_info(2, &pxa_ssp2_master_info);
890 	spi_register_board_info(ARRAY_AND_SIZE(tsc2046_board_info));
891 
892 	gpio_set_value(GPIO71_HX4700_ASIC3_nRESET, 0);
893 	mdelay(10);
894 	gpio_set_value(GPIO71_HX4700_ASIC3_nRESET, 1);
895 	mdelay(10);
896 
897 	pxa_set_udc_info(&hx4700_udc_info);
898 	regulator_has_full_constraints();
899 }
900 
901 MACHINE_START(H4700, "HP iPAQ HX4700")
902 	.atag_offset  = 0x100,
903 	.map_io       = pxa27x_map_io,
904 	.nr_irqs      = HX4700_NR_IRQS,
905 	.init_irq     = pxa27x_init_irq,
906 	.handle_irq     = pxa27x_handle_irq,
907 	.init_machine = hx4700_init,
908 	.init_time	= pxa_timer_init,
909 	.restart	= pxa_restart,
910 MACHINE_END
911