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