Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Support for HP iPAQ hx4700 PDAs.
0004  *
0005  * Copyright (c) 2008-2009 Philipp Zabel
0006  *
0007  * Based on code:
0008  *    Copyright (c) 2004 Hewlett-Packard Company.
0009  *    Copyright (c) 2005 SDG Systems, LLC
0010  *    Copyright (c) 2006 Anton Vorontsov <cbou@mail.ru>
0011  */
0012 
0013 #include <linux/kernel.h>
0014 #include <linux/init.h>
0015 #include <linux/platform_device.h>
0016 #include <linux/delay.h>
0017 #include <linux/fb.h>
0018 #include <linux/gpio/machine.h>
0019 #include <linux/gpio.h>
0020 #include <linux/gpio_keys.h>
0021 #include <linux/input.h>
0022 #include <linux/input/navpoint.h>
0023 #include <linux/lcd.h>
0024 #include <linux/mfd/asic3.h>
0025 #include <linux/mtd/physmap.h>
0026 #include <linux/pda_power.h>
0027 #include <linux/platform_data/gpio-htc-egpio.h>
0028 #include <linux/pwm.h>
0029 #include <linux/pwm_backlight.h>
0030 #include <linux/regulator/driver.h>
0031 #include <linux/regulator/gpio-regulator.h>
0032 #include <linux/regulator/machine.h>
0033 #include <linux/regulator/max1586.h>
0034 #include <linux/spi/ads7846.h>
0035 #include <linux/spi/spi.h>
0036 #include <linux/spi/pxa2xx_spi.h>
0037 #include <linux/platform_data/i2c-pxa.h>
0038 
0039 #include <asm/mach-types.h>
0040 #include <asm/mach/arch.h>
0041 
0042 #include "pxa27x.h"
0043 #include "addr-map.h"
0044 #include "hx4700.h"
0045 #include <linux/platform_data/irda-pxaficp.h>
0046 
0047 #include <sound/ak4641.h>
0048 #include <video/platform_lcd.h>
0049 #include <video/w100fb.h>
0050 
0051 #include "devices.h"
0052 #include "generic.h"
0053 #include "udc.h"
0054 
0055 /* Physical address space information */
0056 
0057 #define ATI_W3220_PHYS  PXA_CS2_PHYS /* ATI Imageon 3220 Graphics */
0058 #define ASIC3_PHYS      PXA_CS3_PHYS
0059 #define ASIC3_SD_PHYS   (PXA_CS3_PHYS + 0x02000000)
0060 
0061 static unsigned long hx4700_pin_config[] __initdata = {
0062 
0063     /* SDRAM and Static Memory I/O Signals */
0064     GPIO20_nSDCS_2,
0065     GPIO21_nSDCS_3,
0066     GPIO15_nCS_1,
0067     GPIO78_nCS_2,   /* W3220 */
0068     GPIO79_nCS_3,   /* ASIC3 */
0069     GPIO80_nCS_4,
0070     GPIO33_nCS_5,   /* EGPIO, WLAN */
0071 
0072     /* PC CARD */
0073     GPIO48_nPOE,
0074     GPIO49_nPWE,
0075     GPIO50_nPIOR,
0076     GPIO51_nPIOW,
0077     GPIO54_nPCE_2,
0078     GPIO55_nPREG,
0079     GPIO56_nPWAIT,
0080     GPIO57_nIOIS16,
0081     GPIO85_nPCE_1,
0082     GPIO104_PSKTSEL,
0083 
0084     /* I2C */
0085     GPIO117_I2C_SCL,
0086     GPIO118_I2C_SDA,
0087 
0088     /* FFUART (RS-232) */
0089     GPIO34_FFUART_RXD,
0090     GPIO35_FFUART_CTS,
0091     GPIO36_FFUART_DCD,
0092     GPIO37_FFUART_DSR,
0093     GPIO38_FFUART_RI,
0094     GPIO39_FFUART_TXD,
0095     GPIO40_FFUART_DTR,
0096     GPIO41_FFUART_RTS,
0097 
0098     /* BTUART */
0099     GPIO42_BTUART_RXD,
0100     GPIO43_BTUART_TXD_LPM_LOW,
0101     GPIO44_BTUART_CTS,
0102     GPIO45_BTUART_RTS_LPM_LOW,
0103 
0104     /* STUART (IRDA) */
0105     GPIO46_STUART_RXD,
0106     GPIO47_STUART_TXD,
0107 
0108     /* PWM 1 (Backlight) */
0109     GPIO17_PWM1_OUT,
0110 
0111     /* I2S */
0112     GPIO28_I2S_BITCLK_OUT,
0113     GPIO29_I2S_SDATA_IN,
0114     GPIO30_I2S_SDATA_OUT,
0115     GPIO31_I2S_SYNC,
0116     GPIO113_I2S_SYSCLK,
0117 
0118     /* SSP 1 (NavPoint) */
0119     GPIO23_SSP1_SCLK_IN,
0120     GPIO24_SSP1_SFRM,
0121     GPIO25_SSP1_TXD,
0122     GPIO26_SSP1_RXD,
0123 
0124     /* SSP 2 (TSC2046) */
0125     GPIO19_SSP2_SCLK,
0126     GPIO86_SSP2_RXD,
0127     GPIO87_SSP2_TXD,
0128     GPIO88_GPIO | MFP_LPM_DRIVE_HIGH,   /* TSC2046_CS */
0129 
0130     /* BQ24022 Regulator */
0131     GPIO72_GPIO | MFP_LPM_KEEP_OUTPUT,  /* BQ24022_nCHARGE_EN */
0132     GPIO96_GPIO | MFP_LPM_KEEP_OUTPUT,  /* BQ24022_ISET2 */
0133 
0134     /* HX4700 specific input GPIOs */
0135     GPIO12_GPIO | WAKEUP_ON_EDGE_RISE,  /* ASIC3_IRQ */
0136     GPIO13_GPIO,    /* W3220_IRQ */
0137     GPIO14_GPIO,    /* nWLAN_IRQ */
0138 
0139     /* HX4700 specific output GPIOs */
0140     GPIO61_GPIO | MFP_LPM_DRIVE_HIGH,   /* W3220_nRESET */
0141     GPIO71_GPIO | MFP_LPM_DRIVE_HIGH,   /* ASIC3_nRESET */
0142     GPIO81_GPIO | MFP_LPM_DRIVE_HIGH,   /* CPU_GP_nRESET */
0143     GPIO116_GPIO | MFP_LPM_DRIVE_HIGH,  /* CPU_HW_nRESET */
0144     GPIO102_GPIO | MFP_LPM_DRIVE_LOW,   /* SYNAPTICS_POWER_ON */
0145 
0146     GPIO10_GPIO,    /* GSM_IRQ */
0147     GPIO13_GPIO,    /* CPLD_IRQ */
0148     GPIO107_GPIO,   /* DS1WM_IRQ */
0149     GPIO108_GPIO,   /* GSM_READY */
0150     GPIO58_GPIO,    /* TSC2046_nPENIRQ */
0151     GPIO66_GPIO,    /* nSDIO_IRQ */
0152 };
0153 
0154 /*
0155  * IRDA
0156  */
0157 
0158 static struct pxaficp_platform_data ficp_info = {
0159     .gpio_pwdown        = GPIO105_HX4700_nIR_ON,
0160     .transceiver_cap    = IR_SIRMODE | IR_OFF,
0161 };
0162 
0163 /*
0164  * GPIO Keys
0165  */
0166 
0167 #define INIT_KEY(_code, _gpio, _active_low, _desc)  \
0168     {                       \
0169         .code       = KEY_##_code,      \
0170         .gpio       = _gpio,            \
0171         .active_low = _active_low,      \
0172         .desc       = _desc,            \
0173         .type       = EV_KEY,           \
0174         .wakeup     = 1,            \
0175     }
0176 
0177 static struct gpio_keys_button gpio_keys_buttons[] = {
0178     INIT_KEY(POWER,       GPIO0_HX4700_nKEY_POWER,   1, "Power button"),
0179     INIT_KEY(MAIL,        GPIO94_HX4700_KEY_MAIL,    0, "Mail button"),
0180     INIT_KEY(ADDRESSBOOK, GPIO99_HX4700_KEY_CONTACTS,0, "Contacts button"),
0181     INIT_KEY(RECORD,      GPIOD6_nKEY_RECORD,        1, "Record button"),
0182     INIT_KEY(CALENDAR,    GPIOD1_nKEY_CALENDAR,      1, "Calendar button"),
0183     INIT_KEY(HOMEPAGE,    GPIOD3_nKEY_HOME,          1, "Home button"),
0184 };
0185 
0186 static struct gpio_keys_platform_data gpio_keys_data = {
0187     .buttons = gpio_keys_buttons,
0188     .nbuttons = ARRAY_SIZE(gpio_keys_buttons),
0189 };
0190 
0191 static struct platform_device gpio_keys = {
0192     .name = "gpio-keys",
0193     .dev  = {
0194         .platform_data = &gpio_keys_data,
0195     },
0196     .id   = -1,
0197 };
0198 
0199 /*
0200  * Synaptics NavPoint connected to SSP1
0201  */
0202 
0203 static struct navpoint_platform_data navpoint_platform_data = {
0204     .port   = 1,
0205     .gpio   = GPIO102_HX4700_SYNAPTICS_POWER_ON,
0206 };
0207 
0208 static struct platform_device navpoint = {
0209     .name   = "navpoint",
0210     .id = -1,
0211     .dev = {
0212         .platform_data = &navpoint_platform_data,
0213     },
0214 };
0215 
0216 /*
0217  * ASIC3
0218  */
0219 
0220 static u16 asic3_gpio_config[] = {
0221     /* ASIC3 GPIO banks A and B along with some of C and D
0222        implement the buffering for the CF slot. */
0223     ASIC3_CONFIG_GPIO(0, 1, 1, 0),
0224     ASIC3_CONFIG_GPIO(1, 1, 1, 0),
0225     ASIC3_CONFIG_GPIO(2, 1, 1, 0),
0226     ASIC3_CONFIG_GPIO(3, 1, 1, 0),
0227     ASIC3_CONFIG_GPIO(4, 1, 1, 0),
0228     ASIC3_CONFIG_GPIO(5, 1, 1, 0),
0229     ASIC3_CONFIG_GPIO(6, 1, 1, 0),
0230     ASIC3_CONFIG_GPIO(7, 1, 1, 0),
0231     ASIC3_CONFIG_GPIO(8, 1, 1, 0),
0232     ASIC3_CONFIG_GPIO(9, 1, 1, 0),
0233     ASIC3_CONFIG_GPIO(10, 1, 1, 0),
0234     ASIC3_CONFIG_GPIO(11, 1, 1, 0),
0235     ASIC3_CONFIG_GPIO(12, 1, 1, 0),
0236     ASIC3_CONFIG_GPIO(13, 1, 1, 0),
0237     ASIC3_CONFIG_GPIO(14, 1, 1, 0),
0238     ASIC3_CONFIG_GPIO(15, 1, 1, 0),
0239 
0240     ASIC3_CONFIG_GPIO(16, 1, 1, 0),
0241     ASIC3_CONFIG_GPIO(17, 1, 1, 0),
0242     ASIC3_CONFIG_GPIO(18, 1, 1, 0),
0243     ASIC3_CONFIG_GPIO(19, 1, 1, 0),
0244     ASIC3_CONFIG_GPIO(20, 1, 1, 0),
0245     ASIC3_CONFIG_GPIO(21, 1, 1, 0),
0246     ASIC3_CONFIG_GPIO(22, 1, 1, 0),
0247     ASIC3_CONFIG_GPIO(23, 1, 1, 0),
0248     ASIC3_CONFIG_GPIO(24, 1, 1, 0),
0249     ASIC3_CONFIG_GPIO(25, 1, 1, 0),
0250     ASIC3_CONFIG_GPIO(26, 1, 1, 0),
0251     ASIC3_CONFIG_GPIO(27, 1, 1, 0),
0252     ASIC3_CONFIG_GPIO(28, 1, 1, 0),
0253     ASIC3_CONFIG_GPIO(29, 1, 1, 0),
0254     ASIC3_CONFIG_GPIO(30, 1, 1, 0),
0255     ASIC3_CONFIG_GPIO(31, 1, 1, 0),
0256 
0257     /* GPIOC - CF, LEDs, SD */
0258     ASIC3_GPIOC0_LED0,      /* red */
0259     ASIC3_GPIOC1_LED1,      /* green */
0260     ASIC3_GPIOC2_LED2,      /* blue */
0261     ASIC3_GPIOC5_nCIOW,
0262     ASIC3_GPIOC6_nCIOR,
0263     ASIC3_GPIOC7_nPCE_1,
0264     ASIC3_GPIOC8_nPCE_2,
0265     ASIC3_GPIOC9_nPOE,
0266     ASIC3_GPIOC10_nPWE,
0267     ASIC3_GPIOC11_PSKTSEL,
0268     ASIC3_GPIOC12_nPREG,
0269     ASIC3_GPIOC13_nPWAIT,
0270     ASIC3_GPIOC14_nPIOIS16,
0271     ASIC3_GPIOC15_nPIOR,
0272 
0273     /* GPIOD: input GPIOs, CF */
0274     ASIC3_GPIOD4_CF_nCD,
0275     ASIC3_GPIOD11_nCIOIS16,
0276     ASIC3_GPIOD12_nCWAIT,
0277     ASIC3_GPIOD15_nPIOW,
0278 };
0279 
0280 static struct asic3_led asic3_leds[ASIC3_NUM_LEDS] = {
0281     [0] = {
0282         .name = "hx4700:amber",
0283         .default_trigger = "ds2760-battery.0-charging-blink-full-solid",
0284     },
0285     [1] = {
0286         .name = "hx4700:green",
0287         .default_trigger = "unused",
0288     },
0289     [2] = {
0290         .name = "hx4700:blue",
0291         .default_trigger = "hx4700-radio",
0292     },
0293 };
0294 
0295 static struct resource asic3_resources[] = {
0296     /* GPIO part */
0297     [0] = DEFINE_RES_MEM(ASIC3_PHYS, ASIC3_MAP_SIZE_16BIT),
0298     [1] = DEFINE_RES_IRQ(PXA_GPIO_TO_IRQ(GPIO12_HX4700_ASIC3_IRQ)),
0299     /* SD part */
0300     [2] = DEFINE_RES_MEM(ASIC3_SD_PHYS, ASIC3_MAP_SIZE_16BIT),
0301     [3] = DEFINE_RES_IRQ(PXA_GPIO_TO_IRQ(GPIO66_HX4700_ASIC3_nSDIO_IRQ)),
0302 };
0303 
0304 static struct asic3_platform_data asic3_platform_data = {
0305     .gpio_config     = asic3_gpio_config,
0306     .gpio_config_num = ARRAY_SIZE(asic3_gpio_config),
0307     .irq_base        = IRQ_BOARD_START,
0308     .gpio_base       = HX4700_ASIC3_GPIO_BASE,
0309     .clock_rate      = 4000000,
0310     .leds            = asic3_leds,
0311 };
0312 
0313 static struct platform_device asic3 = {
0314     .name          = "asic3",
0315     .id            = -1,
0316     .resource      = asic3_resources,
0317     .num_resources = ARRAY_SIZE(asic3_resources),
0318     .dev = {
0319         .platform_data = &asic3_platform_data,
0320     },
0321 };
0322 
0323 /*
0324  * EGPIO
0325  */
0326 
0327 static struct resource egpio_resources[] = {
0328     [0] = DEFINE_RES_MEM(PXA_CS5_PHYS, 0x4),
0329 };
0330 
0331 static struct htc_egpio_chip egpio_chips[] = {
0332     [0] = {
0333         .reg_start = 0,
0334         .gpio_base = HX4700_EGPIO_BASE,
0335         .num_gpios = 8,
0336         .direction = HTC_EGPIO_OUTPUT,
0337     },
0338 };
0339 
0340 static struct htc_egpio_platform_data egpio_info = {
0341     .reg_width = 16,
0342     .bus_width = 16,
0343     .chip      = egpio_chips,
0344     .num_chips = ARRAY_SIZE(egpio_chips),
0345 };
0346 
0347 static struct platform_device egpio = {
0348     .name          = "htc-egpio",
0349     .id            = -1,
0350     .resource      = egpio_resources,
0351     .num_resources = ARRAY_SIZE(egpio_resources),
0352     .dev = {
0353         .platform_data = &egpio_info,
0354     },
0355 };
0356 
0357 /*
0358  * LCD - Sony display connected to ATI Imageon w3220
0359  */
0360 
0361 static void sony_lcd_init(void)
0362 {
0363     gpio_set_value(GPIO84_HX4700_LCD_SQN, 1);
0364     gpio_set_value(GPIO110_HX4700_LCD_LVDD_3V3_ON, 0);
0365     gpio_set_value(GPIO111_HX4700_LCD_AVDD_3V3_ON, 0);
0366     gpio_set_value(GPIO70_HX4700_LCD_SLIN1, 0);
0367     gpio_set_value(GPIO62_HX4700_LCD_nRESET, 0);
0368     mdelay(10);
0369     gpio_set_value(GPIO59_HX4700_LCD_PC1, 0);
0370     gpio_set_value(GPIO110_HX4700_LCD_LVDD_3V3_ON, 0);
0371     mdelay(20);
0372 
0373     gpio_set_value(GPIO110_HX4700_LCD_LVDD_3V3_ON, 1);
0374     mdelay(5);
0375     gpio_set_value(GPIO111_HX4700_LCD_AVDD_3V3_ON, 1);
0376 
0377     /* FIXME: init w3220 registers here */
0378 
0379     mdelay(5);
0380     gpio_set_value(GPIO70_HX4700_LCD_SLIN1, 1);
0381     mdelay(10);
0382     gpio_set_value(GPIO62_HX4700_LCD_nRESET, 1);
0383     mdelay(10);
0384     gpio_set_value(GPIO59_HX4700_LCD_PC1, 1);
0385     mdelay(10);
0386     gpio_set_value(GPIO112_HX4700_LCD_N2V7_7V3_ON, 1);
0387 }
0388 
0389 static void sony_lcd_off(void)
0390 {
0391     gpio_set_value(GPIO59_HX4700_LCD_PC1, 0);
0392     gpio_set_value(GPIO62_HX4700_LCD_nRESET, 0);
0393     mdelay(10);
0394     gpio_set_value(GPIO112_HX4700_LCD_N2V7_7V3_ON, 0);
0395     mdelay(10);
0396     gpio_set_value(GPIO111_HX4700_LCD_AVDD_3V3_ON, 0);
0397     mdelay(10);
0398     gpio_set_value(GPIO110_HX4700_LCD_LVDD_3V3_ON, 0);
0399 }
0400 
0401 #ifdef CONFIG_PM
0402 static void w3220_lcd_suspend(struct w100fb_par *wfb)
0403 {
0404     sony_lcd_off();
0405 }
0406 
0407 static void w3220_lcd_resume(struct w100fb_par *wfb)
0408 {
0409     sony_lcd_init();
0410 }
0411 #else
0412 #define w3220_lcd_resume    NULL
0413 #define w3220_lcd_suspend   NULL
0414 #endif
0415 
0416 static struct w100_tg_info w3220_tg_info = {
0417     .suspend    = w3220_lcd_suspend,
0418     .resume     = w3220_lcd_resume,
0419 };
0420 
0421 /*                   W3220_VGA      QVGA */
0422 static struct w100_gen_regs w3220_regs = {
0423     .lcd_format =        0x00000003,
0424     .lcdd_cntl1 =        0x00000000,
0425     .lcdd_cntl2 =        0x0003ffff,
0426     .genlcd_cntl1 =      0x00abf003,    /* 0x00fff003 */
0427     .genlcd_cntl2 =      0x00000003,
0428     .genlcd_cntl3 =      0x000102aa,
0429 };
0430 
0431 static struct w100_mode w3220_modes[] = {
0432 {
0433     .xres       = 480,
0434     .yres       = 640,
0435     .left_margin    = 15,
0436     .right_margin   = 16,
0437     .upper_margin   = 8,
0438     .lower_margin   = 7,
0439     .crtc_ss    = 0x00000000,
0440     .crtc_ls    = 0xa1ff01f9,   /* 0x21ff01f9 */
0441     .crtc_gs    = 0xc0000000,   /* 0x40000000 */
0442     .crtc_vpos_gs   = 0x0000028f,
0443     .crtc_ps1_active = 0x00000000,  /* 0x41060010 */
0444     .crtc_rev   = 0,
0445     .crtc_dclk  = 0x80000000,
0446     .crtc_gclk  = 0x040a0104,
0447     .crtc_goe   = 0,
0448     .pll_freq   = 95,
0449     .pixclk_divider = 4,
0450     .pixclk_divider_rotated = 4,
0451     .pixclk_src     = CLK_SRC_PLL,
0452     .sysclk_divider = 0,
0453     .sysclk_src     = CLK_SRC_PLL,
0454 },
0455 {
0456     .xres       = 240,
0457     .yres       = 320,
0458     .left_margin    = 9,
0459     .right_margin   = 8,
0460     .upper_margin   = 5,
0461     .lower_margin   = 4,
0462     .crtc_ss    = 0x80150014,
0463     .crtc_ls        = 0xa0fb00f7,
0464     .crtc_gs    = 0xc0080007,
0465     .crtc_vpos_gs   = 0x00080007,
0466     .crtc_rev   = 0x0000000a,
0467     .crtc_dclk  = 0x81700030,
0468     .crtc_gclk  = 0x8015010f,
0469     .crtc_goe   = 0x00000000,
0470     .pll_freq   = 95,
0471     .pixclk_divider = 4,
0472     .pixclk_divider_rotated = 4,
0473     .pixclk_src     = CLK_SRC_PLL,
0474     .sysclk_divider = 0,
0475     .sysclk_src     = CLK_SRC_PLL,
0476 },
0477 };
0478 
0479 struct w100_mem_info w3220_mem_info = {
0480     .ext_cntl        = 0x09640011,
0481     .sdram_mode_reg  = 0x00600021,
0482     .ext_timing_cntl = 0x1a001545,  /* 0x15001545 */
0483     .io_cntl         = 0x7ddd7333,
0484     .size            = 0x1fffff,
0485 };
0486 
0487 struct w100_bm_mem_info w3220_bm_mem_info = {
0488     .ext_mem_bw = 0x50413e01,
0489     .offset = 0,
0490     .ext_timing_ctl = 0x00043f7f,
0491     .ext_cntl = 0x00000010,
0492     .mode_reg = 0x00250000,
0493     .io_cntl = 0x0fff0000,
0494     .config = 0x08301480,
0495 };
0496 
0497 static struct w100_gpio_regs w3220_gpio_info = {
0498     .init_data1 = 0xdfe00100,   /* GPIO_DATA */
0499     .gpio_dir1  = 0xffff0000,   /* GPIO_CNTL1 */
0500     .gpio_oe1   = 0x00000000,   /* GPIO_CNTL2 */
0501     .init_data2 = 0x00000000,   /* GPIO_DATA2 */
0502     .gpio_dir2  = 0x00000000,   /* GPIO_CNTL3 */
0503     .gpio_oe2   = 0x00000000,   /* GPIO_CNTL4 */
0504 };
0505 
0506 static struct w100fb_mach_info w3220_info = {
0507     .tg        = &w3220_tg_info,
0508     .mem       = &w3220_mem_info,
0509     .bm_mem    = &w3220_bm_mem_info,
0510     .gpio      = &w3220_gpio_info,
0511     .regs      = &w3220_regs,
0512     .modelist  = w3220_modes,
0513     .num_modes = 2,
0514     .xtal_freq = 16000000,
0515 };
0516 
0517 static struct resource w3220_resources[] = {
0518     [0] = DEFINE_RES_MEM(ATI_W3220_PHYS, SZ_16M),
0519 };
0520 
0521 static struct platform_device w3220 = {
0522     .name   = "w100fb",
0523     .id = -1,
0524     .dev    = {
0525         .platform_data = &w3220_info,
0526     },
0527     .num_resources = ARRAY_SIZE(w3220_resources),
0528     .resource      = w3220_resources,
0529 };
0530 
0531 static void hx4700_lcd_set_power(struct plat_lcd_data *pd, unsigned int power)
0532 {
0533     if (power)
0534         sony_lcd_init();
0535     else
0536         sony_lcd_off();
0537 }
0538 
0539 static struct plat_lcd_data hx4700_lcd_data = {
0540     .set_power = hx4700_lcd_set_power,
0541 };
0542 
0543 static struct platform_device hx4700_lcd = {
0544     .name = "platform-lcd",
0545     .id   = -1,
0546     .dev  = {
0547         .platform_data = &hx4700_lcd_data,
0548         .parent        = &w3220.dev,
0549     },
0550 };
0551 
0552 /*
0553  * Backlight
0554  */
0555 
0556 static struct platform_pwm_backlight_data backlight_data = {
0557     .max_brightness = 200,
0558     .dft_brightness = 100,
0559 };
0560 
0561 static struct platform_device backlight = {
0562     .name = "pwm-backlight",
0563     .id   = -1,
0564     .dev  = {
0565         .parent        = &pxa27x_device_pwm1.dev,
0566         .platform_data = &backlight_data,
0567     },
0568 };
0569 
0570 static struct pwm_lookup hx4700_pwm_lookup[] = {
0571     PWM_LOOKUP("pxa27x-pwm.1", 0, "pwm-backlight", NULL,
0572            30923, PWM_POLARITY_NORMAL),
0573 };
0574 
0575 /*
0576  * USB "Transceiver"
0577  */
0578 
0579 static struct gpiod_lookup_table gpio_vbus_gpiod_table = {
0580     .dev_id = "gpio-vbus",
0581     .table = {
0582         /* This GPIO is on ASIC3 */
0583         GPIO_LOOKUP("asic3",
0584                 /* Convert to a local offset on the ASIC3 */
0585                 GPIOD14_nUSBC_DETECT - HX4700_ASIC3_GPIO_BASE,
0586                 "vbus", GPIO_ACTIVE_LOW),
0587         /* This one is on the primary SOC GPIO */
0588         GPIO_LOOKUP("gpio-pxa", GPIO76_HX4700_USBC_PUEN,
0589                 "pullup", GPIO_ACTIVE_HIGH),
0590         { },
0591     },
0592 };
0593 
0594 static struct platform_device gpio_vbus = {
0595     .name          = "gpio-vbus",
0596     .id            = -1,
0597 };
0598 
0599 static struct pxa2xx_udc_mach_info hx4700_udc_info;
0600 
0601 /*
0602  * Touchscreen - TSC2046 connected to SSP2
0603  */
0604 
0605 static const struct ads7846_platform_data tsc2046_info = {
0606     .model            = 7846,
0607     .vref_delay_usecs = 100,
0608     .pressure_max     = 1024,
0609     .debounce_max     = 10,
0610     .debounce_tol     = 3,
0611     .debounce_rep     = 1,
0612     .gpio_pendown     = GPIO58_HX4700_TSC2046_nPENIRQ,
0613 };
0614 
0615 static struct pxa2xx_spi_chip tsc2046_chip = {
0616     .tx_threshold = 1,
0617     .rx_threshold = 2,
0618     .timeout      = 64,
0619 };
0620 
0621 static struct spi_board_info tsc2046_board_info[] __initdata = {
0622     {
0623         .modalias        = "ads7846",
0624         .bus_num         = 2,
0625         .max_speed_hz    = 2600000, /* 100 kHz sample rate */
0626         .irq             = PXA_GPIO_TO_IRQ(GPIO58_HX4700_TSC2046_nPENIRQ),
0627         .platform_data   = &tsc2046_info,
0628         .controller_data = &tsc2046_chip,
0629     },
0630 };
0631 
0632 static struct pxa2xx_spi_controller pxa_ssp2_master_info = {
0633     .num_chipselect = 1,
0634     .enable_dma     = 1,
0635 };
0636 
0637 static struct gpiod_lookup_table pxa_ssp2_gpio_table = {
0638     .dev_id = "spi2",
0639     .table = {
0640         GPIO_LOOKUP_IDX("gpio-pxa", GPIO88_HX4700_TSC2046_CS, "cs", 0, GPIO_ACTIVE_LOW),
0641         { },
0642     },
0643 };
0644 
0645 /*
0646  * External power
0647  */
0648 
0649 static int power_supply_init(struct device *dev)
0650 {
0651     return gpio_request(GPIOD9_nAC_IN, "AC charger detect");
0652 }
0653 
0654 static int hx4700_is_ac_online(void)
0655 {
0656     return !gpio_get_value(GPIOD9_nAC_IN);
0657 }
0658 
0659 static void power_supply_exit(struct device *dev)
0660 {
0661     gpio_free(GPIOD9_nAC_IN);
0662 }
0663 
0664 static char *hx4700_supplicants[] = {
0665     "ds2760-battery.0", "backup-battery"
0666 };
0667 
0668 static struct pda_power_pdata power_supply_info = {
0669     .init            = power_supply_init,
0670     .is_ac_online    = hx4700_is_ac_online,
0671     .exit            = power_supply_exit,
0672     .supplied_to     = hx4700_supplicants,
0673     .num_supplicants = ARRAY_SIZE(hx4700_supplicants),
0674 };
0675 
0676 static struct resource power_supply_resources[] = {
0677     [0] = DEFINE_RES_NAMED(PXA_GPIO_TO_IRQ(GPIOD9_nAC_IN), 1, "ac",
0678         IORESOURCE_IRQ |
0679         IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE),
0680     [1] = DEFINE_RES_NAMED(PXA_GPIO_TO_IRQ(GPIOD14_nUSBC_DETECT), 1, "usb",
0681         IORESOURCE_IRQ |
0682         IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE),
0683 };
0684 
0685 static struct platform_device power_supply = {
0686     .name = "pda-power",
0687     .id   = -1,
0688     .dev  = {
0689         .platform_data = &power_supply_info,
0690     },
0691     .resource      = power_supply_resources,
0692     .num_resources = ARRAY_SIZE(power_supply_resources),
0693 };
0694 
0695 /*
0696  * Battery charger
0697  */
0698 
0699 static struct regulator_consumer_supply bq24022_consumers[] = {
0700     REGULATOR_SUPPLY("vbus_draw", NULL),
0701     REGULATOR_SUPPLY("ac_draw", NULL),
0702 };
0703 
0704 static struct regulator_init_data bq24022_init_data = {
0705     .constraints = {
0706         .max_uA         = 500000,
0707         .valid_ops_mask = REGULATOR_CHANGE_CURRENT|REGULATOR_CHANGE_STATUS,
0708     },
0709     .num_consumer_supplies  = ARRAY_SIZE(bq24022_consumers),
0710     .consumer_supplies      = bq24022_consumers,
0711 };
0712 
0713 static enum gpiod_flags bq24022_gpiod_gflags[] = { GPIOD_OUT_LOW };
0714 
0715 static struct gpio_regulator_state bq24022_states[] = {
0716     { .value = 100000, .gpios = (0 << 0) },
0717     { .value = 500000, .gpios = (1 << 0) },
0718 };
0719 
0720 static struct gpio_regulator_config bq24022_info = {
0721     .supply_name = "bq24022",
0722 
0723     .enabled_at_boot = 0,
0724 
0725     .gflags = bq24022_gpiod_gflags,
0726     .ngpios = ARRAY_SIZE(bq24022_gpiod_gflags),
0727 
0728     .states = bq24022_states,
0729     .nr_states = ARRAY_SIZE(bq24022_states),
0730 
0731     .type = REGULATOR_CURRENT,
0732     .init_data = &bq24022_init_data,
0733 };
0734 
0735 static struct platform_device bq24022 = {
0736     .name = "gpio-regulator",
0737     .id   = -1,
0738     .dev  = {
0739         .platform_data = &bq24022_info,
0740     },
0741 };
0742 
0743 static struct gpiod_lookup_table bq24022_gpiod_table = {
0744     .dev_id = "gpio-regulator",
0745     .table = {
0746         GPIO_LOOKUP("gpio-pxa", GPIO96_HX4700_BQ24022_ISET2,
0747                 NULL, GPIO_ACTIVE_HIGH),
0748         GPIO_LOOKUP("gpio-pxa", GPIO72_HX4700_BQ24022_nCHARGE_EN,
0749                 "enable", GPIO_ACTIVE_LOW),
0750         { },
0751     },
0752 };
0753 
0754 /*
0755  * StrataFlash
0756  */
0757 
0758 static void hx4700_set_vpp(struct platform_device *pdev, int vpp)
0759 {
0760     gpio_set_value(GPIO91_HX4700_FLASH_VPEN, vpp);
0761 }
0762 
0763 static struct resource strataflash_resource[] = {
0764     [0] = DEFINE_RES_MEM(PXA_CS0_PHYS, SZ_64M),
0765     [1] = DEFINE_RES_MEM(PXA_CS0_PHYS + SZ_64M, SZ_64M),
0766 };
0767 
0768 static struct physmap_flash_data strataflash_data = {
0769     .width = 4,
0770     .set_vpp = hx4700_set_vpp,
0771 };
0772 
0773 static struct platform_device strataflash = {
0774     .name          = "physmap-flash",
0775     .id            = -1,
0776     .resource      = strataflash_resource,
0777     .num_resources = ARRAY_SIZE(strataflash_resource),
0778     .dev = {
0779         .platform_data = &strataflash_data,
0780     },
0781 };
0782 
0783 /*
0784  * Maxim MAX1587A on PI2C
0785  */
0786 
0787 static struct regulator_consumer_supply max1587a_consumer =
0788     REGULATOR_SUPPLY("vcc_core", NULL);
0789 
0790 static struct regulator_init_data max1587a_v3_info = {
0791     .constraints = {
0792         .name = "vcc_core range",
0793         .min_uV =  900000,
0794         .max_uV = 1705000,
0795         .always_on = 1,
0796         .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
0797     },
0798     .num_consumer_supplies = 1,
0799     .consumer_supplies     = &max1587a_consumer,
0800 };
0801 
0802 static struct max1586_subdev_data max1587a_subdev = {
0803     .name = "vcc_core",
0804     .id   = MAX1586_V3,
0805     .platform_data = &max1587a_v3_info,
0806 };
0807 
0808 static struct max1586_platform_data max1587a_info = {
0809     .num_subdevs = 1,
0810     .subdevs     = &max1587a_subdev,
0811     .v3_gain     = MAX1586_GAIN_R24_3k32, /* 730..1550 mV */
0812 };
0813 
0814 static struct i2c_board_info __initdata pi2c_board_info[] = {
0815     {
0816         I2C_BOARD_INFO("max1586", 0x14),
0817         .platform_data = &max1587a_info,
0818     },
0819 };
0820 
0821 /*
0822  * Asahi Kasei AK4641 on I2C
0823  */
0824 
0825 static struct ak4641_platform_data ak4641_info = {
0826     .gpio_power = GPIO27_HX4700_CODEC_ON,
0827     .gpio_npdn  = GPIO109_HX4700_CODEC_nPDN,
0828 };
0829 
0830 static struct i2c_board_info i2c_board_info[] __initdata = {
0831     {
0832         I2C_BOARD_INFO("ak4641", 0x12),
0833         .platform_data = &ak4641_info,
0834     },
0835 };
0836 
0837 static struct gpiod_lookup_table hx4700_audio_gpio_table = {
0838     .dev_id = "hx4700-audio",
0839     .table = {
0840         GPIO_LOOKUP("gpio-pxa", GPIO75_HX4700_EARPHONE_nDET,
0841                 "earphone-det", GPIO_ACTIVE_LOW),
0842         GPIO_LOOKUP("gpio-pxa", GPIO92_HX4700_HP_DRIVER,
0843                 "hp-driver", GPIO_ACTIVE_HIGH),
0844         GPIO_LOOKUP("gpio-pxa", GPIO107_HX4700_SPK_nSD,
0845                 "spk-sd", GPIO_ACTIVE_LOW),
0846         { },
0847     },
0848 };
0849 
0850 static struct platform_device audio = {
0851     .name   = "hx4700-audio",
0852     .id = -1,
0853 };
0854 
0855 
0856 /*
0857  * Platform devices
0858  */
0859 
0860 static struct platform_device *devices[] __initdata = {
0861     &asic3,
0862     &gpio_keys,
0863     &navpoint,
0864     &backlight,
0865     &w3220,
0866     &hx4700_lcd,
0867     &egpio,
0868     &bq24022,
0869     &gpio_vbus,
0870     &power_supply,
0871     &strataflash,
0872     &audio,
0873 };
0874 
0875 static struct gpio global_gpios[] = {
0876     { GPIO12_HX4700_ASIC3_IRQ, GPIOF_IN, "ASIC3_IRQ" },
0877     { GPIO13_HX4700_W3220_IRQ, GPIOF_IN, "W3220_IRQ" },
0878     { GPIO14_HX4700_nWLAN_IRQ, GPIOF_IN, "WLAN_IRQ" },
0879     { GPIO59_HX4700_LCD_PC1,          GPIOF_OUT_INIT_HIGH, "LCD_PC1" },
0880     { GPIO62_HX4700_LCD_nRESET,       GPIOF_OUT_INIT_HIGH, "LCD_RESET" },
0881     { GPIO70_HX4700_LCD_SLIN1,        GPIOF_OUT_INIT_HIGH, "LCD_SLIN1" },
0882     { GPIO84_HX4700_LCD_SQN,          GPIOF_OUT_INIT_HIGH, "LCD_SQN" },
0883     { GPIO110_HX4700_LCD_LVDD_3V3_ON, GPIOF_OUT_INIT_HIGH, "LCD_LVDD" },
0884     { GPIO111_HX4700_LCD_AVDD_3V3_ON, GPIOF_OUT_INIT_HIGH, "LCD_AVDD" },
0885     { GPIO32_HX4700_RS232_ON,         GPIOF_OUT_INIT_HIGH, "RS232_ON" },
0886     { GPIO61_HX4700_W3220_nRESET,     GPIOF_OUT_INIT_HIGH, "W3220_nRESET" },
0887     { GPIO71_HX4700_ASIC3_nRESET,     GPIOF_OUT_INIT_HIGH, "ASIC3_nRESET" },
0888     { GPIO81_HX4700_CPU_GP_nRESET,    GPIOF_OUT_INIT_HIGH, "CPU_GP_nRESET" },
0889     { GPIO82_HX4700_EUART_RESET,      GPIOF_OUT_INIT_HIGH, "EUART_RESET" },
0890     { GPIO116_HX4700_CPU_HW_nRESET,   GPIOF_OUT_INIT_HIGH, "CPU_HW_nRESET" },
0891 };
0892 
0893 static void __init hx4700_init(void)
0894 {
0895     int ret;
0896 
0897     PCFR = PCFR_GPR_EN | PCFR_OPDE;
0898 
0899     pxa2xx_mfp_config(ARRAY_AND_SIZE(hx4700_pin_config));
0900     gpio_set_wake(GPIO12_HX4700_ASIC3_IRQ, 1);
0901     ret = gpio_request_array(ARRAY_AND_SIZE(global_gpios));
0902     if (ret)
0903         pr_err ("hx4700: Failed to request GPIOs.\n");
0904 
0905     pxa_set_ffuart_info(NULL);
0906     pxa_set_btuart_info(NULL);
0907     pxa_set_stuart_info(NULL);
0908 
0909     gpiod_add_lookup_table(&bq24022_gpiod_table);
0910     gpiod_add_lookup_table(&gpio_vbus_gpiod_table);
0911     gpiod_add_lookup_table(&hx4700_audio_gpio_table);
0912     platform_add_devices(devices, ARRAY_SIZE(devices));
0913     pwm_add_table(hx4700_pwm_lookup, ARRAY_SIZE(hx4700_pwm_lookup));
0914 
0915     pxa_set_ficp_info(&ficp_info);
0916     pxa27x_set_i2c_power_info(NULL);
0917     pxa_set_i2c_info(NULL);
0918     i2c_register_board_info(0, ARRAY_AND_SIZE(i2c_board_info));
0919     i2c_register_board_info(1, ARRAY_AND_SIZE(pi2c_board_info));
0920     gpiod_add_lookup_table(&pxa_ssp2_gpio_table);
0921     pxa2xx_set_spi_info(2, &pxa_ssp2_master_info);
0922     spi_register_board_info(ARRAY_AND_SIZE(tsc2046_board_info));
0923 
0924     gpio_set_value(GPIO71_HX4700_ASIC3_nRESET, 0);
0925     mdelay(10);
0926     gpio_set_value(GPIO71_HX4700_ASIC3_nRESET, 1);
0927     mdelay(10);
0928 
0929     pxa_set_udc_info(&hx4700_udc_info);
0930     regulator_has_full_constraints();
0931 }
0932 
0933 MACHINE_START(H4700, "HP iPAQ HX4700")
0934     .atag_offset  = 0x100,
0935     .map_io       = pxa27x_map_io,
0936     .nr_irqs      = HX4700_NR_IRQS,
0937     .init_irq     = pxa27x_init_irq,
0938     .handle_irq     = pxa27x_handle_irq,
0939     .init_machine = hx4700_init,
0940     .init_time  = pxa_timer_init,
0941     .restart    = pxa_restart,
0942 MACHINE_END