OSDN Git Service

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