0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/kernel.h>
0013 #include <linux/init.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/delay.h>
0016 #include <linux/gpio.h>
0017 #include <linux/gpio/machine.h>
0018 #include <linux/gpio_keys.h>
0019 #include <linux/input.h>
0020 #include <linux/mfd/htc-pasic3.h>
0021 #include <linux/mtd/physmap.h>
0022 #include <linux/pda_power.h>
0023 #include <linux/platform_data/gpio-htc-egpio.h>
0024 #include <linux/pwm.h>
0025 #include <linux/pwm_backlight.h>
0026 #include <linux/regulator/driver.h>
0027 #include <linux/regulator/fixed.h>
0028 #include <linux/regulator/gpio-regulator.h>
0029 #include <linux/regulator/machine.h>
0030 #include <linux/platform_data/i2c-pxa.h>
0031
0032 #include <asm/mach-types.h>
0033 #include <asm/mach/arch.h>
0034 #include <asm/system_info.h>
0035
0036 #include "pxa27x.h"
0037 #include "addr-map.h"
0038 #include "magician.h"
0039 #include <linux/platform_data/video-pxafb.h>
0040 #include <linux/platform_data/mmc-pxamci.h>
0041 #include <linux/platform_data/irda-pxaficp.h>
0042 #include <linux/platform_data/usb-ohci-pxa27x.h>
0043
0044 #include <linux/regulator/max1586.h>
0045
0046 #include <linux/platform_data/pxa2xx_udc.h>
0047
0048 #include "udc.h"
0049 #include "pxa27x-udc.h"
0050 #include "devices.h"
0051 #include "generic.h"
0052
0053 #include <linux/spi/spi.h>
0054 #include <linux/spi/pxa2xx_spi.h>
0055 #include <linux/spi/ads7846.h>
0056 #include <sound/uda1380.h>
0057
0058 static unsigned long magician_pin_config[] __initdata = {
0059
0060
0061 GPIO20_nSDCS_2,
0062 GPIO21_nSDCS_3,
0063 GPIO15_nCS_1,
0064 GPIO78_nCS_2,
0065 GPIO79_nCS_3,
0066 GPIO80_nCS_4,
0067 GPIO33_nCS_5,
0068
0069
0070 GPIO117_I2C_SCL,
0071 GPIO118_I2C_SDA,
0072
0073
0074 GPIO16_PWM0_OUT,
0075
0076
0077 GPIO28_I2S_BITCLK_OUT,
0078 GPIO29_I2S_SDATA_IN,
0079 GPIO31_I2S_SYNC,
0080 GPIO113_I2S_SYSCLK,
0081
0082
0083 GPIO23_SSP1_SCLK,
0084 GPIO24_SSP1_SFRM,
0085 GPIO25_SSP1_TXD,
0086
0087
0088 GPIO19_SSP2_SCLK,
0089 MFP_CFG_OUT(GPIO14, AF0, DRIVE_HIGH),
0090 GPIO89_SSP2_TXD,
0091 GPIO88_SSP2_RXD,
0092
0093
0094 GPIO32_MMC_CLK,
0095 GPIO92_MMC_DAT_0,
0096 GPIO109_MMC_DAT_1,
0097 GPIO110_MMC_DAT_2,
0098 GPIO111_MMC_DAT_3,
0099 GPIO112_MMC_CMD,
0100
0101
0102 GPIOxx_LCD_TFT_16BPP,
0103
0104
0105 GPIO12_CIF_DD_7,
0106 GPIO17_CIF_DD_6,
0107 GPIO50_CIF_DD_3,
0108 GPIO51_CIF_DD_2,
0109 GPIO52_CIF_DD_4,
0110 GPIO53_CIF_MCLK,
0111 GPIO54_CIF_PCLK,
0112 GPIO55_CIF_DD_1,
0113 GPIO81_CIF_DD_0,
0114 GPIO82_CIF_DD_5,
0115 GPIO84_CIF_FV,
0116 GPIO85_CIF_LV,
0117
0118
0119 GPIO9_GPIO,
0120 GPIO10_GPIO,
0121 GPIO13_GPIO,
0122 GPIO107_GPIO,
0123 GPIO108_GPIO,
0124 GPIO115_GPIO,
0125 };
0126
0127
0128
0129
0130
0131 static struct pxaficp_platform_data magician_ficp_info = {
0132 .gpio_pwdown = GPIO83_MAGICIAN_nIR_EN,
0133 .transceiver_cap = IR_SIRMODE | IR_OFF,
0134 .gpio_pwdown_inverted = 0,
0135 };
0136
0137
0138
0139
0140
0141 #define INIT_KEY(_code, _gpio, _desc) \
0142 { \
0143 .code = KEY_##_code, \
0144 .gpio = _gpio, \
0145 .desc = _desc, \
0146 .type = EV_KEY, \
0147 .wakeup = 1, \
0148 }
0149
0150 static struct gpio_keys_button magician_button_table[] = {
0151 INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"),
0152 INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"),
0153 INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"),
0154 INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"),
0155 INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"),
0156 INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"),
0157 INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"),
0158 INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"),
0159 INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"),
0160 INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"),
0161 INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"),
0162 INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"),
0163 INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
0164 INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"),
0165 INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"),
0166 };
0167
0168 static struct gpio_keys_platform_data gpio_keys_data = {
0169 .buttons = magician_button_table,
0170 .nbuttons = ARRAY_SIZE(magician_button_table),
0171 };
0172
0173 static struct platform_device gpio_keys = {
0174 .name = "gpio-keys",
0175 .dev = {
0176 .platform_data = &gpio_keys_data,
0177 },
0178 .id = -1,
0179 };
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189 static struct resource egpio_resources[] = {
0190 [0] = {
0191 .start = PXA_CS3_PHYS,
0192 .end = PXA_CS3_PHYS + 0x20 - 1,
0193 .flags = IORESOURCE_MEM,
0194 },
0195 [1] = {
0196 .start = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
0197 .end = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
0198 .flags = IORESOURCE_IRQ,
0199 },
0200 };
0201
0202 static struct htc_egpio_chip egpio_chips[] = {
0203 [0] = {
0204 .reg_start = 0,
0205 .gpio_base = MAGICIAN_EGPIO(0, 0),
0206 .num_gpios = 24,
0207 .direction = HTC_EGPIO_OUTPUT,
0208
0209
0210
0211 .initial_values = 0x40,
0212 },
0213 [1] = {
0214 .reg_start = 4,
0215 .gpio_base = MAGICIAN_EGPIO(4, 0),
0216 .num_gpios = 24,
0217 .direction = HTC_EGPIO_INPUT,
0218 },
0219 };
0220
0221 static struct htc_egpio_platform_data egpio_info = {
0222 .reg_width = 8,
0223 .bus_width = 32,
0224 .irq_base = IRQ_BOARD_START,
0225 .num_irqs = 4,
0226 .ack_register = 3,
0227 .chip = egpio_chips,
0228 .num_chips = ARRAY_SIZE(egpio_chips),
0229 };
0230
0231 static struct platform_device egpio = {
0232 .name = "htc-egpio",
0233 .id = -1,
0234 .resource = egpio_resources,
0235 .num_resources = ARRAY_SIZE(egpio_resources),
0236 .dev = {
0237 .platform_data = &egpio_info,
0238 },
0239 };
0240
0241
0242
0243
0244
0245 static struct pxafb_mode_info toppoly_modes[] = {
0246 {
0247 .pixclock = 96153,
0248 .bpp = 16,
0249 .xres = 240,
0250 .yres = 320,
0251 .hsync_len = 11,
0252 .vsync_len = 3,
0253 .left_margin = 19,
0254 .upper_margin = 2,
0255 .right_margin = 10,
0256 .lower_margin = 2,
0257 .sync = 0,
0258 },
0259 };
0260
0261 static struct pxafb_mode_info samsung_modes[] = {
0262 {
0263 .pixclock = 226469,
0264 .bpp = 16,
0265 .xres = 240,
0266 .yres = 320,
0267 .hsync_len = 8,
0268 .vsync_len = 4,
0269 .left_margin = 9,
0270 .upper_margin = 4,
0271 .right_margin = 9,
0272 .lower_margin = 4,
0273 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
0274 },
0275 };
0276
0277 static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
0278 {
0279 pr_debug("Toppoly LCD power: %s\n", on ? "on" : "off");
0280
0281 if (on) {
0282 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
0283 gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1);
0284 udelay(2000);
0285 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
0286 udelay(2000);
0287
0288 udelay(2000);
0289 gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1);
0290 udelay(2000);
0291 gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1);
0292 } else {
0293 msleep(15);
0294 gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0);
0295 udelay(500);
0296 gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0);
0297 udelay(1000);
0298 gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0);
0299 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
0300 }
0301 }
0302
0303 static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
0304 {
0305 pr_debug("Samsung LCD power: %s\n", on ? "on" : "off");
0306
0307 if (on) {
0308 if (system_rev < 3)
0309 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
0310 else
0311 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
0312 mdelay(6);
0313 gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1);
0314 mdelay(6);
0315 gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1);
0316 mdelay(16);
0317 gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1);
0318 } else {
0319 gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0);
0320 mdelay(16);
0321 gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0);
0322 mdelay(6);
0323 gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0);
0324 mdelay(6);
0325 if (system_rev < 3)
0326 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
0327 else
0328 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
0329 }
0330 }
0331
0332 static struct pxafb_mach_info toppoly_info = {
0333 .modes = toppoly_modes,
0334 .num_modes = 1,
0335 .fixed_modes = 1,
0336 .lcd_conn = LCD_COLOR_TFT_16BPP,
0337 .pxafb_lcd_power = toppoly_lcd_power,
0338 };
0339
0340 static struct pxafb_mach_info samsung_info = {
0341 .modes = samsung_modes,
0342 .num_modes = 1,
0343 .fixed_modes = 1,
0344 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
0345 LCD_ALTERNATE_MAPPING,
0346 .pxafb_lcd_power = samsung_lcd_power,
0347 };
0348
0349
0350
0351
0352
0353 static struct pwm_lookup magician_pwm_lookup[] = {
0354 PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight", NULL, 30923,
0355 PWM_POLARITY_NORMAL),
0356 };
0357
0358
0359
0360
0361
0362 static struct regulator_consumer_supply pwm_backlight_supply[] = {
0363 REGULATOR_SUPPLY("power", "pwm_backlight"),
0364 };
0365
0366
0367 static struct gpio magician_bl_gpios[] = {
0368 { EGPIO_MAGICIAN_BL_POWER, GPIOF_DIR_OUT, "Backlight power" },
0369 { EGPIO_MAGICIAN_BL_POWER2, GPIOF_DIR_OUT, "Backlight power 2" },
0370 };
0371
0372 static int magician_backlight_init(struct device *dev)
0373 {
0374 return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios));
0375 }
0376
0377 static int magician_backlight_notify(struct device *dev, int brightness)
0378 {
0379 pr_debug("Brightness = %i\n", brightness);
0380 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
0381 if (brightness >= 200) {
0382 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
0383 return brightness - 72;
0384 } else {
0385 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
0386 return brightness;
0387 }
0388 }
0389
0390 static void magician_backlight_exit(struct device *dev)
0391 {
0392 gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios));
0393 }
0394
0395
0396
0397
0398
0399
0400
0401
0402 static struct platform_pwm_backlight_data backlight_data = {
0403 .max_brightness = 272,
0404 .dft_brightness = 100,
0405 .init = magician_backlight_init,
0406 .notify = magician_backlight_notify,
0407 .exit = magician_backlight_exit,
0408 };
0409
0410 static struct platform_device backlight = {
0411 .name = "pwm-backlight",
0412 .id = -1,
0413 .dev = {
0414 .parent = &pxa27x_device_pwm0.dev,
0415 .platform_data = &backlight_data,
0416 },
0417 };
0418
0419
0420
0421
0422
0423 static struct gpio_led gpio_leds[] = {
0424 {
0425 .name = "magician::vibra",
0426 .default_trigger = "none",
0427 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
0428 },
0429 {
0430 .name = "magician::phone_bl",
0431 .default_trigger = "backlight",
0432 .gpio = GPIO103_MAGICIAN_LED_KP,
0433 },
0434 };
0435
0436 static struct gpio_led_platform_data gpio_led_info = {
0437 .leds = gpio_leds,
0438 .num_leds = ARRAY_SIZE(gpio_leds),
0439 };
0440
0441 static struct platform_device leds_gpio = {
0442 .name = "leds-gpio",
0443 .id = -1,
0444 .dev = {
0445 .platform_data = &gpio_led_info,
0446 },
0447 };
0448
0449
0450
0451
0452
0453 static struct resource pasic3_resources[] = {
0454 [0] = {
0455 .start = PXA_CS2_PHYS,
0456 .end = PXA_CS2_PHYS + 0x1b,
0457 .flags = IORESOURCE_MEM,
0458 },
0459
0460 [1] = {
0461 .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
0462 .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
0463 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
0464 }
0465 };
0466
0467 static struct pasic3_platform_data pasic3_platform_data = {
0468 .clock_rate = 4000000,
0469 };
0470
0471 static struct platform_device pasic3 = {
0472 .name = "pasic3",
0473 .id = -1,
0474 .num_resources = ARRAY_SIZE(pasic3_resources),
0475 .resource = pasic3_resources,
0476 .dev = {
0477 .platform_data = &pasic3_platform_data,
0478 },
0479 };
0480
0481
0482
0483
0484
0485 static void magician_udc_command(int cmd)
0486 {
0487 if (cmd == PXA2XX_UDC_CMD_CONNECT)
0488 UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
0489 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
0490 UP2OCR &= ~(UP2OCR_DPPUE | UP2OCR_DPPUBE);
0491 }
0492
0493 static struct pxa2xx_udc_mach_info magician_udc_info __initdata = {
0494 .udc_command = magician_udc_command,
0495 .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
0496 };
0497
0498
0499
0500
0501
0502 static struct resource gpio_vbus_resource = {
0503 .flags = IORESOURCE_IRQ,
0504 .start = IRQ_MAGICIAN_VBUS,
0505 .end = IRQ_MAGICIAN_VBUS,
0506 };
0507
0508 static struct gpiod_lookup_table gpio_vbus_gpiod_table = {
0509 .dev_id = "gpio-vbus",
0510 .table = {
0511
0512
0513
0514
0515
0516 GPIO_LOOKUP("htc-egpio-1", 1,
0517 "vbus", GPIO_ACTIVE_HIGH),
0518 GPIO_LOOKUP("gpio-pxa", GPIO27_MAGICIAN_USBC_PUEN,
0519 "pullup", GPIO_ACTIVE_HIGH),
0520 { },
0521 },
0522 };
0523
0524 static struct platform_device gpio_vbus = {
0525 .name = "gpio-vbus",
0526 .id = -1,
0527 .num_resources = 1,
0528 .resource = &gpio_vbus_resource,
0529 };
0530
0531
0532
0533
0534
0535 static int magician_supply_init(struct device *dev)
0536 {
0537 int ret = -1;
0538
0539 ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable is AC charger");
0540 if (ret) {
0541 pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret);
0542 goto err_ac;
0543 }
0544
0545 ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERTED, "Cable inserted");
0546 if (ret) {
0547 pr_err("Cannot request cable detection GPIO (%i)\n", ret);
0548 goto err_usb;
0549 }
0550
0551 return 0;
0552
0553 err_usb:
0554 gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
0555 err_ac:
0556 return ret;
0557 }
0558
0559 static void magician_set_charge(int flags)
0560 {
0561 if (flags & PDA_POWER_CHARGE_AC) {
0562 pr_debug("Charging from AC\n");
0563 gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
0564 } else if (flags & PDA_POWER_CHARGE_USB) {
0565 pr_debug("Charging from USB\n");
0566 gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
0567 } else {
0568 pr_debug("Charging disabled\n");
0569 gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 0);
0570 }
0571 }
0572
0573 static int magician_is_ac_online(void)
0574 {
0575 return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
0576 gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE);
0577 }
0578
0579 static int magician_is_usb_online(void)
0580 {
0581 return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
0582 (!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE));
0583 }
0584
0585 static void magician_supply_exit(struct device *dev)
0586 {
0587 gpio_free(EGPIO_MAGICIAN_CABLE_INSERTED);
0588 gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
0589 }
0590
0591 static char *magician_supplicants[] = {
0592 "ds2760-battery.0", "backup-battery"
0593 };
0594
0595 static struct pda_power_pdata power_supply_info = {
0596 .init = magician_supply_init,
0597 .exit = magician_supply_exit,
0598 .is_ac_online = magician_is_ac_online,
0599 .is_usb_online = magician_is_usb_online,
0600 .set_charge = magician_set_charge,
0601 .supplied_to = magician_supplicants,
0602 .num_supplicants = ARRAY_SIZE(magician_supplicants),
0603 };
0604
0605 static struct resource power_supply_resources[] = {
0606 [0] = {
0607 .name = "ac",
0608 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
0609 IORESOURCE_IRQ_LOWEDGE,
0610 .start = IRQ_MAGICIAN_VBUS,
0611 .end = IRQ_MAGICIAN_VBUS,
0612 },
0613 [1] = {
0614 .name = "usb",
0615 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
0616 IORESOURCE_IRQ_LOWEDGE,
0617 .start = IRQ_MAGICIAN_VBUS,
0618 .end = IRQ_MAGICIAN_VBUS,
0619 },
0620 };
0621
0622 static struct platform_device power_supply = {
0623 .name = "pda-power",
0624 .id = -1,
0625 .dev = {
0626 .platform_data = &power_supply_info,
0627 },
0628 .resource = power_supply_resources,
0629 .num_resources = ARRAY_SIZE(power_supply_resources),
0630 };
0631
0632
0633
0634
0635
0636 static struct regulator_consumer_supply bq24022_consumers[] = {
0637 REGULATOR_SUPPLY("vbus_draw", NULL),
0638 REGULATOR_SUPPLY("ac_draw", NULL),
0639 };
0640
0641 static struct regulator_init_data bq24022_init_data = {
0642 .constraints = {
0643 .max_uA = 500000,
0644 .valid_ops_mask = REGULATOR_CHANGE_CURRENT |
0645 REGULATOR_CHANGE_STATUS,
0646 },
0647 .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
0648 .consumer_supplies = bq24022_consumers,
0649 };
0650
0651
0652 static enum gpiod_flags bq24022_gpiod_gflags[] = { GPIOD_OUT_LOW };
0653
0654 static struct gpio_regulator_state bq24022_states[] = {
0655 { .value = 100000, .gpios = (0 << 0) },
0656 { .value = 500000, .gpios = (1 << 0) },
0657 };
0658
0659 static struct gpio_regulator_config bq24022_info = {
0660 .supply_name = "bq24022",
0661
0662 .enabled_at_boot = 1,
0663
0664 .gflags = bq24022_gpiod_gflags,
0665 .ngpios = ARRAY_SIZE(bq24022_gpiod_gflags),
0666
0667 .states = bq24022_states,
0668 .nr_states = ARRAY_SIZE(bq24022_states),
0669
0670 .type = REGULATOR_CURRENT,
0671 .init_data = &bq24022_init_data,
0672 };
0673
0674 static struct platform_device bq24022 = {
0675 .name = "gpio-regulator",
0676 .id = -1,
0677 .dev = {
0678 .platform_data = &bq24022_info,
0679 },
0680 };
0681
0682 static struct gpiod_lookup_table bq24022_gpiod_table = {
0683 .dev_id = "gpio-regulator",
0684 .table = {
0685 GPIO_LOOKUP("htc-egpio-0", EGPIO_MAGICIAN_BQ24022_ISET2 - MAGICIAN_EGPIO_BASE,
0686 NULL, GPIO_ACTIVE_HIGH),
0687 GPIO_LOOKUP("gpio-pxa", GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
0688 "enable", GPIO_ACTIVE_LOW),
0689 { },
0690 },
0691 };
0692
0693
0694
0695
0696
0697 static struct regulator_consumer_supply ads7846_supply =
0698 REGULATOR_SUPPLY("vcc", "spi2.0");
0699
0700 static struct regulator_init_data vads7846_regulator = {
0701 .constraints = {
0702 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
0703 },
0704 .num_consumer_supplies = 1,
0705 .consumer_supplies = &ads7846_supply,
0706 };
0707
0708 static struct fixed_voltage_config vads7846 = {
0709 .supply_name = "vads7846",
0710 .microvolts = 3300000,
0711 .startup_delay = 0,
0712 .init_data = &vads7846_regulator,
0713 };
0714
0715 static struct platform_device vads7846_device = {
0716 .name = "reg-fixed-voltage",
0717 .id = -1,
0718 .dev = {
0719 .platform_data = &vads7846,
0720 },
0721 };
0722
0723
0724
0725
0726
0727 static struct regulator_consumer_supply magician_max1587a_consumers[] = {
0728 REGULATOR_SUPPLY("vcc_core", NULL),
0729 };
0730
0731 static struct regulator_init_data magician_max1587a_v3_info = {
0732 .constraints = {
0733 .name = "vcc_core range",
0734 .min_uV = 700000,
0735 .max_uV = 1475000,
0736 .always_on = 1,
0737 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
0738 },
0739 .consumer_supplies = magician_max1587a_consumers,
0740 .num_consumer_supplies = ARRAY_SIZE(magician_max1587a_consumers),
0741 };
0742
0743 static struct max1586_subdev_data magician_max1587a_subdevs[] = {
0744 {
0745 .name = "vcc_core",
0746 .id = MAX1586_V3,
0747 .platform_data = &magician_max1587a_v3_info,
0748 }
0749 };
0750
0751 static struct max1586_platform_data magician_max1587a_info = {
0752 .subdevs = magician_max1587a_subdevs,
0753 .num_subdevs = ARRAY_SIZE(magician_max1587a_subdevs),
0754
0755
0756
0757
0758
0759 .v3_gain = MAX1586_GAIN_NO_R24,
0760 };
0761
0762 static struct i2c_board_info magician_pwr_i2c_board_info[] __initdata = {
0763 {
0764 I2C_BOARD_INFO("max1586", 0x14),
0765 .platform_data = &magician_max1587a_info,
0766 },
0767 };
0768
0769
0770
0771
0772
0773 static int magician_mci_init(struct device *dev,
0774 irq_handler_t detect_irq, void *data)
0775 {
0776 return request_irq(IRQ_MAGICIAN_SD, detect_irq, 0,
0777 "mmc card detect", data);
0778 }
0779
0780 static void magician_mci_exit(struct device *dev, void *data)
0781 {
0782 free_irq(IRQ_MAGICIAN_SD, data);
0783 }
0784
0785 static struct pxamci_platform_data magician_mci_info = {
0786 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
0787 .init = magician_mci_init,
0788 .exit = magician_mci_exit,
0789 .gpio_card_ro_invert = 1,
0790 };
0791
0792
0793
0794
0795
0796
0797 #define EGPIO_MAGICIAN_nSD_READONLY_OFFSET 12
0798
0799
0800
0801
0802 #define EGPIO_MAGICIAN_nSD_POWER_OFFSET 16
0803
0804 static struct gpiod_lookup_table magician_mci_gpio_table = {
0805 .dev_id = "pxa2xx-mci.0",
0806 .table = {
0807 GPIO_LOOKUP("htc-egpio-1", EGPIO_MAGICIAN_nSD_READONLY_OFFSET,
0808 "wp", GPIO_ACTIVE_HIGH),
0809 GPIO_LOOKUP("htc-egpio-0", EGPIO_MAGICIAN_nSD_POWER_OFFSET,
0810 "power", GPIO_ACTIVE_HIGH),
0811 { },
0812 },
0813 };
0814
0815
0816
0817
0818
0819 static struct pxaohci_platform_data magician_ohci_info = {
0820 .port_mode = PMM_PERPORT_MODE,
0821
0822 .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
0823 .power_budget = 0,
0824 .power_on_delay = 100,
0825 };
0826
0827
0828
0829
0830
0831 static int magician_flash_init(struct platform_device *pdev)
0832 {
0833 int ret = gpio_request(EGPIO_MAGICIAN_FLASH_VPP, "flash Vpp enable");
0834
0835 if (ret) {
0836 pr_err("Cannot request flash enable GPIO (%i)\n", ret);
0837 return ret;
0838 }
0839
0840 ret = gpio_direction_output(EGPIO_MAGICIAN_FLASH_VPP, 1);
0841 if (ret) {
0842 pr_err("Cannot set direction for flash enable (%i)\n", ret);
0843 gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
0844 }
0845
0846 return ret;
0847 }
0848
0849 static void magician_set_vpp(struct platform_device *pdev, int vpp)
0850 {
0851 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
0852 }
0853
0854 static void magician_flash_exit(struct platform_device *pdev)
0855 {
0856 gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
0857 }
0858
0859 static struct resource strataflash_resource = {
0860 .start = PXA_CS0_PHYS,
0861 .end = PXA_CS0_PHYS + SZ_64M - 1,
0862 .flags = IORESOURCE_MEM,
0863 };
0864
0865 static struct mtd_partition magician_flash_parts[] = {
0866 {
0867 .name = "Bootloader",
0868 .offset = 0x0,
0869 .size = 0x40000,
0870 .mask_flags = MTD_WRITEABLE,
0871 },
0872 {
0873 .name = "Linux Kernel",
0874 .offset = 0x40000,
0875 .size = MTDPART_SIZ_FULL,
0876 },
0877 };
0878
0879
0880
0881
0882
0883 static struct physmap_flash_data strataflash_data = {
0884 .width = 4,
0885 .init = magician_flash_init,
0886 .set_vpp = magician_set_vpp,
0887 .exit = magician_flash_exit,
0888 .parts = magician_flash_parts,
0889 .nr_parts = ARRAY_SIZE(magician_flash_parts),
0890 };
0891
0892 static struct platform_device strataflash = {
0893 .name = "physmap-flash",
0894 .id = -1,
0895 .resource = &strataflash_resource,
0896 .num_resources = 1,
0897 .dev = {
0898 .platform_data = &strataflash_data,
0899 },
0900 };
0901
0902
0903
0904
0905 static struct uda1380_platform_data uda1380_info = {
0906 .gpio_power = EGPIO_MAGICIAN_CODEC_POWER,
0907 .gpio_reset = EGPIO_MAGICIAN_CODEC_RESET,
0908 .dac_clk = UDA1380_DAC_CLK_WSPLL,
0909 };
0910
0911 static struct i2c_board_info magician_audio_i2c_board_info[] = {
0912 {
0913 I2C_BOARD_INFO("uda1380", 0x18),
0914 .platform_data = &uda1380_info,
0915 },
0916 };
0917
0918 static struct gpiod_lookup_table magician_audio_gpio_table = {
0919 .dev_id = "magician-audio",
0920 .table = {
0921 GPIO_LOOKUP("htc-egpio-0",
0922 EGPIO_MAGICIAN_SPK_POWER - MAGICIAN_EGPIO_BASE,
0923 "SPK_POWER", GPIO_ACTIVE_HIGH),
0924 GPIO_LOOKUP("htc-egpio-0",
0925 EGPIO_MAGICIAN_EP_POWER - MAGICIAN_EGPIO_BASE,
0926 "EP_POWER", GPIO_ACTIVE_HIGH),
0927 GPIO_LOOKUP("htc-egpio-0",
0928 EGPIO_MAGICIAN_MIC_POWER - MAGICIAN_EGPIO_BASE,
0929 "MIC_POWER", GPIO_ACTIVE_HIGH),
0930 GPIO_LOOKUP("htc-egpio-0",
0931 EGPIO_MAGICIAN_IN_SEL0 - MAGICIAN_EGPIO_BASE,
0932 "IN_SEL0", GPIO_ACTIVE_HIGH),
0933 GPIO_LOOKUP("htc-egpio-0",
0934 EGPIO_MAGICIAN_IN_SEL1 - MAGICIAN_EGPIO_BASE,
0935 "IN_SEL1", GPIO_ACTIVE_HIGH),
0936 { },
0937 },
0938 };
0939
0940 static void magician_audio_init(void)
0941 {
0942 i2c_register_board_info(0,
0943 ARRAY_AND_SIZE(magician_audio_i2c_board_info));
0944
0945 gpiod_add_lookup_table(&magician_audio_gpio_table);
0946 platform_device_register_simple("magician-audio", -1, NULL, 0);
0947 }
0948
0949
0950
0951
0952
0953 static struct i2c_pxa_platform_data i2c_info = {
0954
0955 .fast_mode = 0,
0956 };
0957
0958
0959
0960
0961
0962 static struct i2c_pxa_platform_data magician_i2c_power_info = {
0963 .fast_mode = 1,
0964 };
0965
0966
0967
0968
0969
0970 static struct ads7846_platform_data ads7846_pdata = {
0971 .model = 7846,
0972 .x_plate_ohms = 317,
0973 .y_plate_ohms = 500,
0974 .pressure_max = 1023,
0975 .debounce_max = 3,
0976 .debounce_tol = 30,
0977 .debounce_rep = 0,
0978 .gpio_pendown = GPIO115_MAGICIAN_nPEN_IRQ,
0979 .keep_vref_on = 1,
0980 .wakeup = true,
0981 .vref_delay_usecs = 100,
0982 .penirq_recheck_delay_usecs = 100,
0983 };
0984
0985 struct pxa2xx_spi_chip tsc2046_chip_info = {
0986 .tx_threshold = 1,
0987 .rx_threshold = 2,
0988 .timeout = 64,
0989 };
0990
0991 static struct pxa2xx_spi_controller magician_spi_info = {
0992 .num_chipselect = 1,
0993 .enable_dma = 1,
0994 };
0995
0996 static struct gpiod_lookup_table magician_spi_gpio_table = {
0997 .dev_id = "spi2",
0998 .table = {
0999
1000 GPIO_LOOKUP_IDX("gpio-pxa", GPIO14_MAGICIAN_TSC2046_CS, "cs", 0, GPIO_ACTIVE_LOW),
1001 { },
1002 },
1003 };
1004
1005 static struct spi_board_info ads7846_spi_board_info[] __initdata = {
1006 {
1007 .modalias = "ads7846",
1008 .bus_num = 2,
1009 .max_speed_hz = 2500000,
1010 .platform_data = &ads7846_pdata,
1011 .controller_data = &tsc2046_chip_info,
1012 .irq = PXA_GPIO_TO_IRQ(GPIO115_MAGICIAN_nPEN_IRQ),
1013 },
1014 };
1015
1016
1017
1018
1019
1020 static struct platform_device *devices[] __initdata = {
1021 &gpio_keys,
1022 &egpio,
1023 &backlight,
1024 &pasic3,
1025 &bq24022,
1026 &gpio_vbus,
1027 &power_supply,
1028 &strataflash,
1029 &leds_gpio,
1030 &vads7846_device,
1031 };
1032
1033 static struct gpio magician_global_gpios[] = {
1034 { GPIO13_MAGICIAN_CPLD_IRQ, GPIOF_IN, "CPLD_IRQ" },
1035 { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" },
1036
1037
1038 { GPIO106_MAGICIAN_LCD_DCDC_NRESET, GPIOF_OUT_INIT_LOW, "LCD DCDC nreset" },
1039 { GPIO104_MAGICIAN_LCD_VOFF_EN, GPIOF_OUT_INIT_LOW, "LCD VOFF enable" },
1040 { GPIO105_MAGICIAN_LCD_VON_EN, GPIOF_OUT_INIT_LOW, "LCD VON enable" },
1041 };
1042
1043 static void __init magician_init(void)
1044 {
1045 void __iomem *cpld;
1046 int lcd_select;
1047 int err;
1048
1049 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
1050 err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios));
1051 if (err)
1052 pr_err("magician: Failed to request global GPIOs: %d\n", err);
1053
1054 pxa_set_ffuart_info(NULL);
1055 pxa_set_btuart_info(NULL);
1056
1057 pwm_add_table(magician_pwm_lookup, ARRAY_SIZE(magician_pwm_lookup));
1058
1059 pxa_set_ficp_info(&magician_ficp_info);
1060 pxa27x_set_i2c_power_info(&magician_i2c_power_info);
1061 pxa_set_i2c_info(&i2c_info);
1062
1063 i2c_register_board_info(1,
1064 ARRAY_AND_SIZE(magician_pwr_i2c_board_info));
1065
1066 gpiod_add_lookup_table(&magician_mci_gpio_table);
1067 pxa_set_mci_info(&magician_mci_info);
1068 pxa_set_ohci_info(&magician_ohci_info);
1069 pxa_set_udc_info(&magician_udc_info);
1070
1071
1072 cpld = ioremap(PXA_CS3_PHYS, 0x1000);
1073 if (cpld) {
1074 u8 board_id = __raw_readb(cpld + 0x14);
1075
1076 iounmap(cpld);
1077 system_rev = board_id & 0x7;
1078 lcd_select = board_id & 0x8;
1079 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
1080 if (lcd_select && (system_rev < 3))
1081
1082 gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER,
1083 GPIOF_OUT_INIT_LOW, "Samsung LCD Power");
1084 pxa_set_fb_info(NULL,
1085 lcd_select ? &samsung_info : &toppoly_info);
1086 } else
1087 pr_err("LCD detection: CPLD mapping failed\n");
1088
1089 gpiod_add_lookup_table(&magician_spi_gpio_table);
1090 pxa2xx_set_spi_info(2, &magician_spi_info);
1091 spi_register_board_info(ARRAY_AND_SIZE(ads7846_spi_board_info));
1092
1093 regulator_register_always_on(0, "power", pwm_backlight_supply,
1094 ARRAY_SIZE(pwm_backlight_supply), 5000000);
1095
1096 gpiod_add_lookup_table(&bq24022_gpiod_table);
1097 gpiod_add_lookup_table(&gpio_vbus_gpiod_table);
1098 platform_add_devices(ARRAY_AND_SIZE(devices));
1099
1100 magician_audio_init();
1101 }
1102
1103 MACHINE_START(MAGICIAN, "HTC Magician")
1104 .atag_offset = 0x100,
1105 .map_io = pxa27x_map_io,
1106 .nr_irqs = MAGICIAN_NR_IRQS,
1107 .init_irq = pxa27x_init_irq,
1108 .handle_irq = pxa27x_handle_irq,
1109 .init_machine = magician_init,
1110 .init_time = pxa_timer_init,
1111 .restart = pxa_restart,
1112 MACHINE_END