Loading...
1/*
2 * Support for HTC Magician PDA phones:
3 * i-mate JAM, O2 Xda mini, Orange SPV M500, Qtek s100, Qtek s110
4 * and T-Mobile MDA Compact.
5 *
6 * Copyright (c) 2006-2007 Philipp Zabel
7 *
8 * Based on hx4700.c, spitz.c and others.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/platform_device.h>
19#include <linux/delay.h>
20#include <linux/gpio.h>
21#include <linux/gpio_keys.h>
22#include <linux/input.h>
23#include <linux/mfd/htc-egpio.h>
24#include <linux/mfd/htc-pasic3.h>
25#include <linux/mtd/physmap.h>
26#include <linux/pda_power.h>
27#include <linux/pwm_backlight.h>
28#include <linux/regulator/driver.h>
29#include <linux/regulator/gpio-regulator.h>
30#include <linux/regulator/machine.h>
31#include <linux/usb/gpio_vbus.h>
32#include <linux/i2c/pxa-i2c.h>
33
34#include <mach/hardware.h>
35#include <asm/mach-types.h>
36#include <asm/mach/arch.h>
37#include <asm/system_info.h>
38
39#include <mach/pxa27x.h>
40#include <mach/magician.h>
41#include <linux/platform_data/video-pxafb.h>
42#include <linux/platform_data/mmc-pxamci.h>
43#include <linux/platform_data/irda-pxaficp.h>
44#include <linux/platform_data/usb-ohci-pxa27x.h>
45
46#include "devices.h"
47#include "generic.h"
48
49static unsigned long magician_pin_config[] __initdata = {
50
51 /* SDRAM and Static Memory I/O Signals */
52 GPIO20_nSDCS_2,
53 GPIO21_nSDCS_3,
54 GPIO15_nCS_1,
55 GPIO78_nCS_2, /* PASIC3 */
56 GPIO79_nCS_3, /* EGPIO CPLD */
57 GPIO80_nCS_4,
58 GPIO33_nCS_5,
59
60 /* I2C */
61 GPIO117_I2C_SCL,
62 GPIO118_I2C_SDA,
63
64 /* PWM 0 */
65 GPIO16_PWM0_OUT,
66
67 /* I2S */
68 GPIO28_I2S_BITCLK_OUT,
69 GPIO29_I2S_SDATA_IN,
70 GPIO31_I2S_SYNC,
71 GPIO113_I2S_SYSCLK,
72
73 /* SSP 1 */
74 GPIO23_SSP1_SCLK,
75 GPIO24_SSP1_SFRM,
76 GPIO25_SSP1_TXD,
77
78 /* SSP 2 */
79 GPIO19_SSP2_SCLK,
80 GPIO14_SSP2_SFRM,
81 GPIO89_SSP2_TXD,
82 GPIO88_SSP2_RXD,
83
84 /* MMC */
85 GPIO32_MMC_CLK,
86 GPIO92_MMC_DAT_0,
87 GPIO109_MMC_DAT_1,
88 GPIO110_MMC_DAT_2,
89 GPIO111_MMC_DAT_3,
90 GPIO112_MMC_CMD,
91
92 /* LCD */
93 GPIOxx_LCD_TFT_16BPP,
94
95 /* QCI */
96 GPIO12_CIF_DD_7,
97 GPIO17_CIF_DD_6,
98 GPIO50_CIF_DD_3,
99 GPIO51_CIF_DD_2,
100 GPIO52_CIF_DD_4,
101 GPIO53_CIF_MCLK,
102 GPIO54_CIF_PCLK,
103 GPIO55_CIF_DD_1,
104 GPIO81_CIF_DD_0,
105 GPIO82_CIF_DD_5,
106 GPIO84_CIF_FV,
107 GPIO85_CIF_LV,
108
109 /* Magician specific input GPIOs */
110 GPIO9_GPIO, /* unknown */
111 GPIO10_GPIO, /* GSM_IRQ */
112 GPIO13_GPIO, /* CPLD_IRQ */
113 GPIO107_GPIO, /* DS1WM_IRQ */
114 GPIO108_GPIO, /* GSM_READY */
115 GPIO115_GPIO, /* nPEN_IRQ */
116
117 /* I2C */
118 GPIO117_I2C_SCL,
119 GPIO118_I2C_SDA,
120};
121
122/*
123 * IRDA
124 */
125
126static struct pxaficp_platform_data magician_ficp_info = {
127 .gpio_pwdown = GPIO83_MAGICIAN_nIR_EN,
128 .transceiver_cap = IR_SIRMODE | IR_OFF,
129};
130
131/*
132 * GPIO Keys
133 */
134
135#define INIT_KEY(_code, _gpio, _desc) \
136 { \
137 .code = KEY_##_code, \
138 .gpio = _gpio, \
139 .desc = _desc, \
140 .type = EV_KEY, \
141 .wakeup = 1, \
142 }
143
144static struct gpio_keys_button magician_button_table[] = {
145 INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"),
146 INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"),
147 INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"),
148 INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"),
149 INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"),
150 INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"),
151 INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"),
152 INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"),
153 INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"),
154 INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"),
155 INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"),
156 INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"),
157 INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
158 INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"),
159 INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"),
160};
161
162static struct gpio_keys_platform_data gpio_keys_data = {
163 .buttons = magician_button_table,
164 .nbuttons = ARRAY_SIZE(magician_button_table),
165};
166
167static struct platform_device gpio_keys = {
168 .name = "gpio-keys",
169 .dev = {
170 .platform_data = &gpio_keys_data,
171 },
172 .id = -1,
173};
174
175
176/*
177 * EGPIO (Xilinx CPLD)
178 *
179 * 7 32-bit aligned 8-bit registers: 3x output, 1x irq, 3x input
180 */
181
182static struct resource egpio_resources[] = {
183 [0] = {
184 .start = PXA_CS3_PHYS,
185 .end = PXA_CS3_PHYS + 0x20 - 1,
186 .flags = IORESOURCE_MEM,
187 },
188 [1] = {
189 .start = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
190 .end = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
191 .flags = IORESOURCE_IRQ,
192 },
193};
194
195static struct htc_egpio_chip egpio_chips[] = {
196 [0] = {
197 .reg_start = 0,
198 .gpio_base = MAGICIAN_EGPIO(0, 0),
199 .num_gpios = 24,
200 .direction = HTC_EGPIO_OUTPUT,
201 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
202 },
203 [1] = {
204 .reg_start = 4,
205 .gpio_base = MAGICIAN_EGPIO(4, 0),
206 .num_gpios = 24,
207 .direction = HTC_EGPIO_INPUT,
208 },
209};
210
211static struct htc_egpio_platform_data egpio_info = {
212 .reg_width = 8,
213 .bus_width = 32,
214 .irq_base = IRQ_BOARD_START,
215 .num_irqs = 4,
216 .ack_register = 3,
217 .chip = egpio_chips,
218 .num_chips = ARRAY_SIZE(egpio_chips),
219};
220
221static struct platform_device egpio = {
222 .name = "htc-egpio",
223 .id = -1,
224 .resource = egpio_resources,
225 .num_resources = ARRAY_SIZE(egpio_resources),
226 .dev = {
227 .platform_data = &egpio_info,
228 },
229};
230
231/*
232 * LCD - Toppoly TD028STEB1 or Samsung LTP280QV
233 */
234
235static struct pxafb_mode_info toppoly_modes[] = {
236 {
237 .pixclock = 96153,
238 .bpp = 16,
239 .xres = 240,
240 .yres = 320,
241 .hsync_len = 11,
242 .vsync_len = 3,
243 .left_margin = 19,
244 .upper_margin = 2,
245 .right_margin = 10,
246 .lower_margin = 2,
247 .sync = 0,
248 },
249};
250
251static struct pxafb_mode_info samsung_modes[] = {
252 {
253 .pixclock = 96153,
254 .bpp = 16,
255 .xres = 240,
256 .yres = 320,
257 .hsync_len = 8,
258 .vsync_len = 4,
259 .left_margin = 9,
260 .upper_margin = 4,
261 .right_margin = 9,
262 .lower_margin = 4,
263 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
264 },
265};
266
267static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
268{
269 pr_debug("Toppoly LCD power\n");
270
271 if (on) {
272 pr_debug("on\n");
273 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
274 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
275 udelay(2000);
276 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
277 udelay(2000);
278 /* FIXME: enable LCDC here */
279 udelay(2000);
280 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
281 udelay(2000);
282 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
283 } else {
284 pr_debug("off\n");
285 msleep(15);
286 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
287 udelay(500);
288 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
289 udelay(1000);
290 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
291 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
292 }
293}
294
295static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
296{
297 pr_debug("Samsung LCD power\n");
298
299 if (on) {
300 pr_debug("on\n");
301 if (system_rev < 3)
302 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
303 else
304 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
305 mdelay(10);
306 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 1);
307 mdelay(10);
308 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 1);
309 mdelay(30);
310 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 1);
311 mdelay(10);
312 } else {
313 pr_debug("off\n");
314 mdelay(10);
315 gpio_set_value(GPIO105_MAGICIAN_LCD_POWER_2, 0);
316 mdelay(30);
317 gpio_set_value(GPIO104_MAGICIAN_LCD_POWER_1, 0);
318 mdelay(10);
319 gpio_set_value(GPIO106_MAGICIAN_LCD_POWER_3, 0);
320 mdelay(10);
321 if (system_rev < 3)
322 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
323 else
324 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
325 }
326}
327
328static struct pxafb_mach_info toppoly_info = {
329 .modes = toppoly_modes,
330 .num_modes = 1,
331 .fixed_modes = 1,
332 .lcd_conn = LCD_COLOR_TFT_16BPP,
333 .pxafb_lcd_power = toppoly_lcd_power,
334};
335
336static struct pxafb_mach_info samsung_info = {
337 .modes = samsung_modes,
338 .num_modes = 1,
339 .fixed_modes = 1,
340 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |\
341 LCD_ALTERNATE_MAPPING,
342 .pxafb_lcd_power = samsung_lcd_power,
343};
344
345/*
346 * Backlight
347 */
348
349static struct gpio magician_bl_gpios[] = {
350 { EGPIO_MAGICIAN_BL_POWER, GPIOF_DIR_OUT, "Backlight power" },
351 { EGPIO_MAGICIAN_BL_POWER2, GPIOF_DIR_OUT, "Backlight power 2" },
352};
353
354static int magician_backlight_init(struct device *dev)
355{
356 return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios));
357}
358
359static int magician_backlight_notify(struct device *dev, int brightness)
360{
361 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
362 if (brightness >= 200) {
363 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
364 return brightness - 72;
365 } else {
366 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
367 return brightness;
368 }
369}
370
371static void magician_backlight_exit(struct device *dev)
372{
373 gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios));
374}
375
376static struct platform_pwm_backlight_data backlight_data = {
377 .pwm_id = 0,
378 .max_brightness = 272,
379 .dft_brightness = 100,
380 .pwm_period_ns = 30923,
381 .enable_gpio = -1,
382 .init = magician_backlight_init,
383 .notify = magician_backlight_notify,
384 .exit = magician_backlight_exit,
385};
386
387static struct platform_device backlight = {
388 .name = "pwm-backlight",
389 .id = -1,
390 .dev = {
391 .parent = &pxa27x_device_pwm0.dev,
392 .platform_data = &backlight_data,
393 },
394};
395
396/*
397 * LEDs
398 */
399
400static struct gpio_led gpio_leds[] = {
401 {
402 .name = "magician::vibra",
403 .default_trigger = "none",
404 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
405 },
406 {
407 .name = "magician::phone_bl",
408 .default_trigger = "backlight",
409 .gpio = GPIO103_MAGICIAN_LED_KP,
410 },
411};
412
413static struct gpio_led_platform_data gpio_led_info = {
414 .leds = gpio_leds,
415 .num_leds = ARRAY_SIZE(gpio_leds),
416};
417
418static struct platform_device leds_gpio = {
419 .name = "leds-gpio",
420 .id = -1,
421 .dev = {
422 .platform_data = &gpio_led_info,
423 },
424};
425
426static struct pasic3_led pasic3_leds[] = {
427 {
428 .led = {
429 .name = "magician:red",
430 .default_trigger = "ds2760-battery.0-charging",
431 },
432 .hw_num = 0,
433 .bit2 = PASIC3_BIT2_LED0,
434 .mask = PASIC3_MASK_LED0,
435 },
436 {
437 .led = {
438 .name = "magician:green",
439 .default_trigger = "ds2760-battery.0-charging-or-full",
440 },
441 .hw_num = 1,
442 .bit2 = PASIC3_BIT2_LED1,
443 .mask = PASIC3_MASK_LED1,
444 },
445 {
446 .led = {
447 .name = "magician:blue",
448 .default_trigger = "bluetooth",
449 },
450 .hw_num = 2,
451 .bit2 = PASIC3_BIT2_LED2,
452 .mask = PASIC3_MASK_LED2,
453 },
454};
455
456static struct pasic3_leds_machinfo pasic3_leds_info = {
457 .num_leds = ARRAY_SIZE(pasic3_leds),
458 .power_gpio = EGPIO_MAGICIAN_LED_POWER,
459 .leds = pasic3_leds,
460};
461
462/*
463 * PASIC3 with DS1WM
464 */
465
466static struct resource pasic3_resources[] = {
467 [0] = {
468 .start = PXA_CS2_PHYS,
469 .end = PXA_CS2_PHYS + 0x1b,
470 .flags = IORESOURCE_MEM,
471 },
472 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
473 [1] = {
474 .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
475 .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
476 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
477 }
478};
479
480static struct pasic3_platform_data pasic3_platform_data = {
481 .led_pdata = &pasic3_leds_info,
482 .clock_rate = 4000000,
483};
484
485static struct platform_device pasic3 = {
486 .name = "pasic3",
487 .id = -1,
488 .num_resources = ARRAY_SIZE(pasic3_resources),
489 .resource = pasic3_resources,
490 .dev = {
491 .platform_data = &pasic3_platform_data,
492 },
493};
494
495/*
496 * USB "Transceiver"
497 */
498
499static struct resource gpio_vbus_resource = {
500 .flags = IORESOURCE_IRQ,
501 .start = IRQ_MAGICIAN_VBUS,
502 .end = IRQ_MAGICIAN_VBUS,
503};
504
505static struct gpio_vbus_mach_info gpio_vbus_info = {
506 .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
507 .gpio_vbus = EGPIO_MAGICIAN_CABLE_STATE_USB,
508};
509
510static struct platform_device gpio_vbus = {
511 .name = "gpio-vbus",
512 .id = -1,
513 .num_resources = 1,
514 .resource = &gpio_vbus_resource,
515 .dev = {
516 .platform_data = &gpio_vbus_info,
517 },
518};
519
520/*
521 * External power
522 */
523
524static int power_supply_init(struct device *dev)
525{
526 return gpio_request(EGPIO_MAGICIAN_CABLE_STATE_AC, "CABLE_STATE_AC");
527}
528
529static int magician_is_ac_online(void)
530{
531 return gpio_get_value(EGPIO_MAGICIAN_CABLE_STATE_AC);
532}
533
534static void power_supply_exit(struct device *dev)
535{
536 gpio_free(EGPIO_MAGICIAN_CABLE_STATE_AC);
537}
538
539static char *magician_supplicants[] = {
540 "ds2760-battery.0", "backup-battery"
541};
542
543static struct pda_power_pdata power_supply_info = {
544 .init = power_supply_init,
545 .is_ac_online = magician_is_ac_online,
546 .exit = power_supply_exit,
547 .supplied_to = magician_supplicants,
548 .num_supplicants = ARRAY_SIZE(magician_supplicants),
549};
550
551static struct resource power_supply_resources[] = {
552 [0] = {
553 .name = "ac",
554 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
555 IORESOURCE_IRQ_LOWEDGE,
556 .start = IRQ_MAGICIAN_VBUS,
557 .end = IRQ_MAGICIAN_VBUS,
558 },
559 [1] = {
560 .name = "usb",
561 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
562 IORESOURCE_IRQ_LOWEDGE,
563 .start = IRQ_MAGICIAN_VBUS,
564 .end = IRQ_MAGICIAN_VBUS,
565 },
566};
567
568static struct platform_device power_supply = {
569 .name = "pda-power",
570 .id = -1,
571 .dev = {
572 .platform_data = &power_supply_info,
573 },
574 .resource = power_supply_resources,
575 .num_resources = ARRAY_SIZE(power_supply_resources),
576};
577
578/*
579 * Battery charger
580 */
581
582static struct regulator_consumer_supply bq24022_consumers[] = {
583 REGULATOR_SUPPLY("vbus_draw", NULL),
584 REGULATOR_SUPPLY("ac_draw", NULL),
585};
586
587static struct regulator_init_data bq24022_init_data = {
588 .constraints = {
589 .max_uA = 500000,
590 .valid_ops_mask = REGULATOR_CHANGE_CURRENT | REGULATOR_CHANGE_STATUS,
591 },
592 .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
593 .consumer_supplies = bq24022_consumers,
594};
595
596static struct gpio bq24022_gpios[] = {
597 { EGPIO_MAGICIAN_BQ24022_ISET2, GPIOF_OUT_INIT_LOW, "bq24022_iset2" },
598};
599
600static struct gpio_regulator_state bq24022_states[] = {
601 { .value = 100000, .gpios = (0 << 0) },
602 { .value = 500000, .gpios = (1 << 0) },
603};
604
605static struct gpio_regulator_config bq24022_info = {
606 .supply_name = "bq24022",
607
608 .enable_gpio = GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
609 .enable_high = 0,
610 .enabled_at_boot = 0,
611
612 .gpios = bq24022_gpios,
613 .nr_gpios = ARRAY_SIZE(bq24022_gpios),
614
615 .states = bq24022_states,
616 .nr_states = ARRAY_SIZE(bq24022_states),
617
618 .type = REGULATOR_CURRENT,
619 .init_data = &bq24022_init_data,
620};
621
622static struct platform_device bq24022 = {
623 .name = "gpio-regulator",
624 .id = -1,
625 .dev = {
626 .platform_data = &bq24022_info,
627 },
628};
629
630/*
631 * MMC/SD
632 */
633
634static int magician_mci_init(struct device *dev,
635 irq_handler_t detect_irq, void *data)
636{
637 return request_irq(IRQ_MAGICIAN_SD, detect_irq, 0,
638 "mmc card detect", data);
639}
640
641static void magician_mci_exit(struct device *dev, void *data)
642{
643 free_irq(IRQ_MAGICIAN_SD, data);
644}
645
646static struct pxamci_platform_data magician_mci_info = {
647 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
648 .init = magician_mci_init,
649 .exit = magician_mci_exit,
650 .gpio_card_detect = -1,
651 .gpio_card_ro = EGPIO_MAGICIAN_nSD_READONLY,
652 .gpio_card_ro_invert = 1,
653 .gpio_power = EGPIO_MAGICIAN_SD_POWER,
654};
655
656
657/*
658 * USB OHCI
659 */
660
661static struct pxaohci_platform_data magician_ohci_info = {
662 .port_mode = PMM_PERPORT_MODE,
663 .flags = ENABLE_PORT1 | ENABLE_PORT3 | POWER_CONTROL_LOW,
664 .power_budget = 0,
665};
666
667
668/*
669 * StrataFlash
670 */
671
672static void magician_set_vpp(struct platform_device *pdev, int vpp)
673{
674 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
675}
676
677static struct resource strataflash_resource = {
678 .start = PXA_CS0_PHYS,
679 .end = PXA_CS0_PHYS + SZ_64M - 1,
680 .flags = IORESOURCE_MEM,
681};
682
683static struct physmap_flash_data strataflash_data = {
684 .width = 4,
685 .set_vpp = magician_set_vpp,
686};
687
688static struct platform_device strataflash = {
689 .name = "physmap-flash",
690 .id = -1,
691 .resource = &strataflash_resource,
692 .num_resources = 1,
693 .dev = {
694 .platform_data = &strataflash_data,
695 },
696};
697
698/*
699 * I2C
700 */
701
702static struct i2c_pxa_platform_data i2c_info = {
703 .fast_mode = 1,
704};
705
706/*
707 * Platform devices
708 */
709
710static struct platform_device *devices[] __initdata = {
711 &gpio_keys,
712 &egpio,
713 &backlight,
714 &pasic3,
715 &bq24022,
716 &gpio_vbus,
717 &power_supply,
718 &strataflash,
719 &leds_gpio,
720};
721
722static struct gpio magician_global_gpios[] = {
723 { GPIO13_MAGICIAN_CPLD_IRQ, GPIOF_IN, "CPLD_IRQ" },
724 { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" },
725 { GPIO104_MAGICIAN_LCD_POWER_1, GPIOF_OUT_INIT_LOW, "LCD power 1" },
726 { GPIO105_MAGICIAN_LCD_POWER_2, GPIOF_OUT_INIT_LOW, "LCD power 2" },
727 { GPIO106_MAGICIAN_LCD_POWER_3, GPIOF_OUT_INIT_LOW, "LCD power 3" },
728 { GPIO83_MAGICIAN_nIR_EN, GPIOF_OUT_INIT_HIGH, "nIR_EN" },
729};
730
731static void __init magician_init(void)
732{
733 void __iomem *cpld;
734 int lcd_select;
735 int err;
736
737 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
738 err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios));
739 if (err)
740 pr_err("magician: Failed to request GPIOs: %d\n", err);
741
742 pxa_set_ffuart_info(NULL);
743 pxa_set_btuart_info(NULL);
744 pxa_set_stuart_info(NULL);
745
746 platform_add_devices(ARRAY_AND_SIZE(devices));
747
748 pxa_set_ficp_info(&magician_ficp_info);
749 pxa27x_set_i2c_power_info(NULL);
750 pxa_set_i2c_info(&i2c_info);
751 pxa_set_mci_info(&magician_mci_info);
752 pxa_set_ohci_info(&magician_ohci_info);
753
754 /* Check LCD type we have */
755 cpld = ioremap_nocache(PXA_CS3_PHYS, 0x1000);
756 if (cpld) {
757 u8 board_id = __raw_readb(cpld+0x14);
758 iounmap(cpld);
759 system_rev = board_id & 0x7;
760 lcd_select = board_id & 0x8;
761 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
762 if (lcd_select && (system_rev < 3))
763 gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER,
764 GPIOF_OUT_INIT_LOW, "SAMSUNG_POWER");
765 pxa_set_fb_info(NULL, lcd_select ? &samsung_info : &toppoly_info);
766 } else
767 pr_err("LCD detection: CPLD mapping failed\n");
768}
769
770
771MACHINE_START(MAGICIAN, "HTC Magician")
772 .atag_offset = 0x100,
773 .map_io = pxa27x_map_io,
774 .nr_irqs = MAGICIAN_NR_IRQS,
775 .init_irq = pxa27x_init_irq,
776 .handle_irq = pxa27x_handle_irq,
777 .init_machine = magician_init,
778 .init_time = pxa_timer_init,
779 .restart = pxa_restart,
780MACHINE_END
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Support for HTC Magician PDA phones:
4 * i-mate JAM, O2 Xda mini, Orange SPV M500, Qtek s100, Qtek s110
5 * and T-Mobile MDA Compact.
6 *
7 * Copyright (c) 2006-2007 Philipp Zabel
8 *
9 * Based on hx4700.c, spitz.c and others.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/delay.h>
16#include <linux/gpio.h>
17#include <linux/gpio/machine.h>
18#include <linux/gpio_keys.h>
19#include <linux/input.h>
20#include <linux/mfd/htc-pasic3.h>
21#include <linux/mtd/physmap.h>
22#include <linux/pda_power.h>
23#include <linux/platform_data/gpio-htc-egpio.h>
24#include <linux/pwm.h>
25#include <linux/pwm_backlight.h>
26#include <linux/regulator/driver.h>
27#include <linux/regulator/fixed.h>
28#include <linux/regulator/gpio-regulator.h>
29#include <linux/regulator/machine.h>
30#include <linux/platform_data/i2c-pxa.h>
31
32#include <mach/hardware.h>
33#include <asm/mach-types.h>
34#include <asm/mach/arch.h>
35#include <asm/system_info.h>
36
37#include "pxa27x.h"
38#include <mach/magician.h>
39#include <linux/platform_data/video-pxafb.h>
40#include <linux/platform_data/mmc-pxamci.h>
41#include <linux/platform_data/irda-pxaficp.h>
42#include <linux/platform_data/usb-ohci-pxa27x.h>
43
44#include <linux/regulator/max1586.h>
45
46#include <linux/platform_data/pxa2xx_udc.h>
47
48#include "udc.h"
49#include "pxa27x-udc.h"
50#include "devices.h"
51#include "generic.h"
52
53#include <linux/spi/spi.h>
54#include <linux/spi/pxa2xx_spi.h>
55#include <linux/spi/ads7846.h>
56
57static unsigned long magician_pin_config[] __initdata = {
58
59 /* SDRAM and Static Memory I/O Signals */
60 GPIO20_nSDCS_2,
61 GPIO21_nSDCS_3,
62 GPIO15_nCS_1,
63 GPIO78_nCS_2, /* PASIC3 */
64 GPIO79_nCS_3, /* EGPIO CPLD */
65 GPIO80_nCS_4,
66 GPIO33_nCS_5,
67
68 /* I2C UDA1380 + OV9640 */
69 GPIO117_I2C_SCL,
70 GPIO118_I2C_SDA,
71
72 /* PWM 0 - LCD backlight */
73 GPIO16_PWM0_OUT,
74
75 /* I2S UDA1380 capture */
76 GPIO28_I2S_BITCLK_OUT,
77 GPIO29_I2S_SDATA_IN,
78 GPIO31_I2S_SYNC,
79 GPIO113_I2S_SYSCLK,
80
81 /* SSP 1 UDA1380 playback */
82 GPIO23_SSP1_SCLK,
83 GPIO24_SSP1_SFRM,
84 GPIO25_SSP1_TXD,
85
86 /* SSP 2 TSC2046 touchscreen */
87 GPIO19_SSP2_SCLK,
88 MFP_CFG_OUT(GPIO14, AF0, DRIVE_HIGH), /* frame as GPIO */
89 GPIO89_SSP2_TXD,
90 GPIO88_SSP2_RXD,
91
92 /* MMC/SD/SDHC slot */
93 GPIO32_MMC_CLK,
94 GPIO92_MMC_DAT_0,
95 GPIO109_MMC_DAT_1,
96 GPIO110_MMC_DAT_2,
97 GPIO111_MMC_DAT_3,
98 GPIO112_MMC_CMD,
99
100 /* LCD */
101 GPIOxx_LCD_TFT_16BPP,
102
103 /* QCI camera interface */
104 GPIO12_CIF_DD_7,
105 GPIO17_CIF_DD_6,
106 GPIO50_CIF_DD_3,
107 GPIO51_CIF_DD_2,
108 GPIO52_CIF_DD_4,
109 GPIO53_CIF_MCLK,
110 GPIO54_CIF_PCLK,
111 GPIO55_CIF_DD_1,
112 GPIO81_CIF_DD_0,
113 GPIO82_CIF_DD_5,
114 GPIO84_CIF_FV,
115 GPIO85_CIF_LV,
116
117 /* Magician specific input GPIOs */
118 GPIO9_GPIO, /* unknown */
119 GPIO10_GPIO, /* GSM_IRQ */
120 GPIO13_GPIO, /* CPLD_IRQ */
121 GPIO107_GPIO, /* DS1WM_IRQ */
122 GPIO108_GPIO, /* GSM_READY */
123 GPIO115_GPIO, /* nPEN_IRQ */
124};
125
126/*
127 * IrDA
128 */
129
130static struct pxaficp_platform_data magician_ficp_info = {
131 .gpio_pwdown = GPIO83_MAGICIAN_nIR_EN,
132 .transceiver_cap = IR_SIRMODE | IR_OFF,
133 .gpio_pwdown_inverted = 0,
134};
135
136/*
137 * GPIO Keys
138 */
139
140#define INIT_KEY(_code, _gpio, _desc) \
141 { \
142 .code = KEY_##_code, \
143 .gpio = _gpio, \
144 .desc = _desc, \
145 .type = EV_KEY, \
146 .wakeup = 1, \
147 }
148
149static struct gpio_keys_button magician_button_table[] = {
150 INIT_KEY(POWER, GPIO0_MAGICIAN_KEY_POWER, "Power button"),
151 INIT_KEY(ESC, GPIO37_MAGICIAN_KEY_HANGUP, "Hangup button"),
152 INIT_KEY(F10, GPIO38_MAGICIAN_KEY_CONTACTS, "Contacts button"),
153 INIT_KEY(CALENDAR, GPIO90_MAGICIAN_KEY_CALENDAR, "Calendar button"),
154 INIT_KEY(CAMERA, GPIO91_MAGICIAN_KEY_CAMERA, "Camera button"),
155 INIT_KEY(UP, GPIO93_MAGICIAN_KEY_UP, "Up button"),
156 INIT_KEY(DOWN, GPIO94_MAGICIAN_KEY_DOWN, "Down button"),
157 INIT_KEY(LEFT, GPIO95_MAGICIAN_KEY_LEFT, "Left button"),
158 INIT_KEY(RIGHT, GPIO96_MAGICIAN_KEY_RIGHT, "Right button"),
159 INIT_KEY(KPENTER, GPIO97_MAGICIAN_KEY_ENTER, "Action button"),
160 INIT_KEY(RECORD, GPIO98_MAGICIAN_KEY_RECORD, "Record button"),
161 INIT_KEY(VOLUMEUP, GPIO100_MAGICIAN_KEY_VOL_UP, "Volume up"),
162 INIT_KEY(VOLUMEDOWN, GPIO101_MAGICIAN_KEY_VOL_DOWN, "Volume down"),
163 INIT_KEY(PHONE, GPIO102_MAGICIAN_KEY_PHONE, "Phone button"),
164 INIT_KEY(PLAY, GPIO99_MAGICIAN_HEADPHONE_IN, "Headset button"),
165};
166
167static struct gpio_keys_platform_data gpio_keys_data = {
168 .buttons = magician_button_table,
169 .nbuttons = ARRAY_SIZE(magician_button_table),
170};
171
172static struct platform_device gpio_keys = {
173 .name = "gpio-keys",
174 .dev = {
175 .platform_data = &gpio_keys_data,
176 },
177 .id = -1,
178};
179
180/*
181 * EGPIO (Xilinx CPLD)
182 *
183 * 32-bit aligned 8-bit registers
184 * 16 possible registers (reg windows size), only 7 used:
185 * 3x output, 1x irq, 3x input
186 */
187
188static struct resource egpio_resources[] = {
189 [0] = {
190 .start = PXA_CS3_PHYS,
191 .end = PXA_CS3_PHYS + 0x20 - 1,
192 .flags = IORESOURCE_MEM,
193 },
194 [1] = {
195 .start = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
196 .end = PXA_GPIO_TO_IRQ(GPIO13_MAGICIAN_CPLD_IRQ),
197 .flags = IORESOURCE_IRQ,
198 },
199};
200
201static struct htc_egpio_chip egpio_chips[] = {
202 [0] = {
203 .reg_start = 0,
204 .gpio_base = MAGICIAN_EGPIO(0, 0),
205 .num_gpios = 24,
206 .direction = HTC_EGPIO_OUTPUT,
207 /*
208 * Depends on modules configuration
209 */
210 .initial_values = 0x40, /* EGPIO_MAGICIAN_GSM_RESET */
211 },
212 [1] = {
213 .reg_start = 4,
214 .gpio_base = MAGICIAN_EGPIO(4, 0),
215 .num_gpios = 24,
216 .direction = HTC_EGPIO_INPUT,
217 },
218};
219
220static struct htc_egpio_platform_data egpio_info = {
221 .reg_width = 8,
222 .bus_width = 32,
223 .irq_base = IRQ_BOARD_START,
224 .num_irqs = 4,
225 .ack_register = 3,
226 .chip = egpio_chips,
227 .num_chips = ARRAY_SIZE(egpio_chips),
228};
229
230static struct platform_device egpio = {
231 .name = "htc-egpio",
232 .id = -1,
233 .resource = egpio_resources,
234 .num_resources = ARRAY_SIZE(egpio_resources),
235 .dev = {
236 .platform_data = &egpio_info,
237 },
238};
239
240/*
241 * PXAFB LCD - Toppoly TD028STEB1 or Samsung LTP280QV
242 */
243
244static struct pxafb_mode_info toppoly_modes[] = {
245 {
246 .pixclock = 96153,
247 .bpp = 16,
248 .xres = 240,
249 .yres = 320,
250 .hsync_len = 11,
251 .vsync_len = 3,
252 .left_margin = 19,
253 .upper_margin = 2,
254 .right_margin = 10,
255 .lower_margin = 2,
256 .sync = 0,
257 },
258};
259
260static struct pxafb_mode_info samsung_modes[] = {
261 {
262 .pixclock = 226469,
263 .bpp = 16,
264 .xres = 240,
265 .yres = 320,
266 .hsync_len = 8,
267 .vsync_len = 4,
268 .left_margin = 9,
269 .upper_margin = 4,
270 .right_margin = 9,
271 .lower_margin = 4,
272 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
273 },
274};
275
276static void toppoly_lcd_power(int on, struct fb_var_screeninfo *si)
277{
278 pr_debug("Toppoly LCD power: %s\n", on ? "on" : "off");
279
280 if (on) {
281 gpio_set_value(EGPIO_MAGICIAN_TOPPOLY_POWER, 1);
282 gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1);
283 udelay(2000);
284 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
285 udelay(2000);
286 /* FIXME: enable LCDC here */
287 udelay(2000);
288 gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1);
289 udelay(2000);
290 gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1);
291 } else {
292 msleep(15);
293 gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0);
294 udelay(500);
295 gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0);
296 udelay(1000);
297 gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0);
298 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
299 }
300}
301
302static void samsung_lcd_power(int on, struct fb_var_screeninfo *si)
303{
304 pr_debug("Samsung LCD power: %s\n", on ? "on" : "off");
305
306 if (on) {
307 if (system_rev < 3)
308 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 1);
309 else
310 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 1);
311 mdelay(6);
312 gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 1);
313 mdelay(6); /* Avdd -> Voff >5ms */
314 gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 1);
315 mdelay(16); /* Voff -> Von >(5+10)ms */
316 gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 1);
317 } else {
318 gpio_set_value(GPIO105_MAGICIAN_LCD_VON_EN, 0);
319 mdelay(16);
320 gpio_set_value(GPIO104_MAGICIAN_LCD_VOFF_EN, 0);
321 mdelay(6);
322 gpio_set_value(GPIO106_MAGICIAN_LCD_DCDC_NRESET, 0);
323 mdelay(6);
324 if (system_rev < 3)
325 gpio_set_value(GPIO75_MAGICIAN_SAMSUNG_POWER, 0);
326 else
327 gpio_set_value(EGPIO_MAGICIAN_LCD_POWER, 0);
328 }
329}
330
331static struct pxafb_mach_info toppoly_info = {
332 .modes = toppoly_modes,
333 .num_modes = 1,
334 .fixed_modes = 1,
335 .lcd_conn = LCD_COLOR_TFT_16BPP,
336 .pxafb_lcd_power = toppoly_lcd_power,
337};
338
339static struct pxafb_mach_info samsung_info = {
340 .modes = samsung_modes,
341 .num_modes = 1,
342 .fixed_modes = 1,
343 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL |
344 LCD_ALTERNATE_MAPPING,
345 .pxafb_lcd_power = samsung_lcd_power,
346};
347
348/*
349 * Backlight
350 */
351
352static struct pwm_lookup magician_pwm_lookup[] = {
353 PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight", NULL, 30923,
354 PWM_POLARITY_NORMAL),
355};
356
357 /*
358 * fixed regulator for pwm_backlight
359 */
360
361static struct regulator_consumer_supply pwm_backlight_supply[] = {
362 REGULATOR_SUPPLY("power", "pwm_backlight"),
363};
364
365
366static struct gpio magician_bl_gpios[] = {
367 { EGPIO_MAGICIAN_BL_POWER, GPIOF_DIR_OUT, "Backlight power" },
368 { EGPIO_MAGICIAN_BL_POWER2, GPIOF_DIR_OUT, "Backlight power 2" },
369};
370
371static int magician_backlight_init(struct device *dev)
372{
373 return gpio_request_array(ARRAY_AND_SIZE(magician_bl_gpios));
374}
375
376static int magician_backlight_notify(struct device *dev, int brightness)
377{
378 pr_debug("Brightness = %i\n", brightness);
379 gpio_set_value(EGPIO_MAGICIAN_BL_POWER, brightness);
380 if (brightness >= 200) {
381 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 1);
382 return brightness - 72;
383 } else {
384 gpio_set_value(EGPIO_MAGICIAN_BL_POWER2, 0);
385 return brightness;
386 }
387}
388
389static void magician_backlight_exit(struct device *dev)
390{
391 gpio_free_array(ARRAY_AND_SIZE(magician_bl_gpios));
392}
393
394/*
395 * LCD PWM backlight (main)
396 *
397 * MP1521 frequency should be:
398 * 100-400 Hz = 2 .5*10^6 - 10 *10^6 ns
399 */
400
401static struct platform_pwm_backlight_data backlight_data = {
402 .max_brightness = 272,
403 .dft_brightness = 100,
404 .init = magician_backlight_init,
405 .notify = magician_backlight_notify,
406 .exit = magician_backlight_exit,
407};
408
409static struct platform_device backlight = {
410 .name = "pwm-backlight",
411 .id = -1,
412 .dev = {
413 .parent = &pxa27x_device_pwm0.dev,
414 .platform_data = &backlight_data,
415 },
416};
417
418/*
419 * GPIO LEDs, Phone keys backlight, vibra
420 */
421
422static struct gpio_led gpio_leds[] = {
423 {
424 .name = "magician::vibra",
425 .default_trigger = "none",
426 .gpio = GPIO22_MAGICIAN_VIBRA_EN,
427 },
428 {
429 .name = "magician::phone_bl",
430 .default_trigger = "backlight",
431 .gpio = GPIO103_MAGICIAN_LED_KP,
432 },
433};
434
435static struct gpio_led_platform_data gpio_led_info = {
436 .leds = gpio_leds,
437 .num_leds = ARRAY_SIZE(gpio_leds),
438};
439
440static struct platform_device leds_gpio = {
441 .name = "leds-gpio",
442 .id = -1,
443 .dev = {
444 .platform_data = &gpio_led_info,
445 },
446};
447
448/*
449 * PASIC3 with DS1WM
450 */
451
452static struct resource pasic3_resources[] = {
453 [0] = {
454 .start = PXA_CS2_PHYS,
455 .end = PXA_CS2_PHYS + 0x1b,
456 .flags = IORESOURCE_MEM,
457 },
458 /* No IRQ handler in the PASIC3, DS1WM needs an external IRQ */
459 [1] = {
460 .start = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
461 .end = PXA_GPIO_TO_IRQ(GPIO107_MAGICIAN_DS1WM_IRQ),
462 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
463 }
464};
465
466static struct pasic3_platform_data pasic3_platform_data = {
467 .clock_rate = 4000000,
468};
469
470static struct platform_device pasic3 = {
471 .name = "pasic3",
472 .id = -1,
473 .num_resources = ARRAY_SIZE(pasic3_resources),
474 .resource = pasic3_resources,
475 .dev = {
476 .platform_data = &pasic3_platform_data,
477 },
478};
479
480/*
481 * PXA UDC
482 */
483
484static void magician_udc_command(int cmd)
485{
486 if (cmd == PXA2XX_UDC_CMD_CONNECT)
487 UP2OCR |= UP2OCR_DPPUE | UP2OCR_DPPUBE;
488 else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
489 UP2OCR &= ~(UP2OCR_DPPUE | UP2OCR_DPPUBE);
490}
491
492static struct pxa2xx_udc_mach_info magician_udc_info __initdata = {
493 .udc_command = magician_udc_command,
494 .gpio_pullup = GPIO27_MAGICIAN_USBC_PUEN,
495};
496
497/*
498 * USB device VBus detection
499 */
500
501static struct resource gpio_vbus_resource = {
502 .flags = IORESOURCE_IRQ,
503 .start = IRQ_MAGICIAN_VBUS,
504 .end = IRQ_MAGICIAN_VBUS,
505};
506
507static struct gpiod_lookup_table gpio_vbus_gpiod_table = {
508 .dev_id = "gpio-vbus",
509 .table = {
510 /*
511 * EGPIO on register 4 index 1, the second EGPIO chip
512 * starts at register 4 so this will be at index 1 on that
513 * chip.
514 */
515 GPIO_LOOKUP("htc-egpio-1", 1,
516 "vbus", GPIO_ACTIVE_HIGH),
517 GPIO_LOOKUP("gpio-pxa", GPIO27_MAGICIAN_USBC_PUEN,
518 "pullup", GPIO_ACTIVE_HIGH),
519 { },
520 },
521};
522
523static struct platform_device gpio_vbus = {
524 .name = "gpio-vbus",
525 .id = -1,
526 .num_resources = 1,
527 .resource = &gpio_vbus_resource,
528};
529
530/*
531 * External power
532 */
533
534static int magician_supply_init(struct device *dev)
535{
536 int ret = -1;
537
538 ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable is AC charger");
539 if (ret) {
540 pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret);
541 goto err_ac;
542 }
543
544 ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERTED, "Cable inserted");
545 if (ret) {
546 pr_err("Cannot request cable detection GPIO (%i)\n", ret);
547 goto err_usb;
548 }
549
550 return 0;
551
552err_usb:
553 gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
554err_ac:
555 return ret;
556}
557
558static void magician_set_charge(int flags)
559{
560 if (flags & PDA_POWER_CHARGE_AC) {
561 pr_debug("Charging from AC\n");
562 gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
563 } else if (flags & PDA_POWER_CHARGE_USB) {
564 pr_debug("Charging from USB\n");
565 gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
566 } else {
567 pr_debug("Charging disabled\n");
568 gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 0);
569 }
570}
571
572static int magician_is_ac_online(void)
573{
574 return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
575 gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE); /* AC=1 */
576}
577
578static int magician_is_usb_online(void)
579{
580 return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
581 (!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE)); /* USB=0 */
582}
583
584static void magician_supply_exit(struct device *dev)
585{
586 gpio_free(EGPIO_MAGICIAN_CABLE_INSERTED);
587 gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
588}
589
590static char *magician_supplicants[] = {
591 "ds2760-battery.0", "backup-battery"
592};
593
594static struct pda_power_pdata power_supply_info = {
595 .init = magician_supply_init,
596 .exit = magician_supply_exit,
597 .is_ac_online = magician_is_ac_online,
598 .is_usb_online = magician_is_usb_online,
599 .set_charge = magician_set_charge,
600 .supplied_to = magician_supplicants,
601 .num_supplicants = ARRAY_SIZE(magician_supplicants),
602};
603
604static struct resource power_supply_resources[] = {
605 [0] = {
606 .name = "ac",
607 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
608 IORESOURCE_IRQ_LOWEDGE,
609 .start = IRQ_MAGICIAN_VBUS,
610 .end = IRQ_MAGICIAN_VBUS,
611 },
612 [1] = {
613 .name = "usb",
614 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
615 IORESOURCE_IRQ_LOWEDGE,
616 .start = IRQ_MAGICIAN_VBUS,
617 .end = IRQ_MAGICIAN_VBUS,
618 },
619};
620
621static struct platform_device power_supply = {
622 .name = "pda-power",
623 .id = -1,
624 .dev = {
625 .platform_data = &power_supply_info,
626 },
627 .resource = power_supply_resources,
628 .num_resources = ARRAY_SIZE(power_supply_resources),
629};
630
631/*
632 * Battery charger
633 */
634
635static struct regulator_consumer_supply bq24022_consumers[] = {
636 REGULATOR_SUPPLY("vbus_draw", NULL),
637 REGULATOR_SUPPLY("ac_draw", NULL),
638};
639
640static struct regulator_init_data bq24022_init_data = {
641 .constraints = {
642 .max_uA = 500000,
643 .valid_ops_mask = REGULATOR_CHANGE_CURRENT |
644 REGULATOR_CHANGE_STATUS,
645 },
646 .num_consumer_supplies = ARRAY_SIZE(bq24022_consumers),
647 .consumer_supplies = bq24022_consumers,
648};
649
650
651static enum gpiod_flags bq24022_gpiod_gflags[] = { GPIOD_OUT_LOW };
652
653static struct gpio_regulator_state bq24022_states[] = {
654 { .value = 100000, .gpios = (0 << 0) },
655 { .value = 500000, .gpios = (1 << 0) },
656};
657
658static struct gpio_regulator_config bq24022_info = {
659 .supply_name = "bq24022",
660
661 .enabled_at_boot = 1,
662
663 .gflags = bq24022_gpiod_gflags,
664 .ngpios = ARRAY_SIZE(bq24022_gpiod_gflags),
665
666 .states = bq24022_states,
667 .nr_states = ARRAY_SIZE(bq24022_states),
668
669 .type = REGULATOR_CURRENT,
670 .init_data = &bq24022_init_data,
671};
672
673static struct platform_device bq24022 = {
674 .name = "gpio-regulator",
675 .id = -1,
676 .dev = {
677 .platform_data = &bq24022_info,
678 },
679};
680
681static struct gpiod_lookup_table bq24022_gpiod_table = {
682 .dev_id = "gpio-regulator",
683 .table = {
684 GPIO_LOOKUP("gpio-pxa", EGPIO_MAGICIAN_BQ24022_ISET2,
685 NULL, GPIO_ACTIVE_HIGH),
686 GPIO_LOOKUP("gpio-pxa", GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
687 "enable", GPIO_ACTIVE_LOW),
688 { },
689 },
690};
691
692/*
693 * fixed regulator for ads7846
694 */
695
696static struct regulator_consumer_supply ads7846_supply =
697 REGULATOR_SUPPLY("vcc", "spi2.0");
698
699static struct regulator_init_data vads7846_regulator = {
700 .constraints = {
701 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
702 },
703 .num_consumer_supplies = 1,
704 .consumer_supplies = &ads7846_supply,
705};
706
707static struct fixed_voltage_config vads7846 = {
708 .supply_name = "vads7846",
709 .microvolts = 3300000, /* probably */
710 .startup_delay = 0,
711 .init_data = &vads7846_regulator,
712};
713
714static struct platform_device vads7846_device = {
715 .name = "reg-fixed-voltage",
716 .id = -1,
717 .dev = {
718 .platform_data = &vads7846,
719 },
720};
721
722/*
723 * Vcore regulator MAX1587A
724 */
725
726static struct regulator_consumer_supply magician_max1587a_consumers[] = {
727 REGULATOR_SUPPLY("vcc_core", NULL),
728};
729
730static struct regulator_init_data magician_max1587a_v3_info = {
731 .constraints = {
732 .name = "vcc_core range",
733 .min_uV = 700000,
734 .max_uV = 1475000,
735 .always_on = 1,
736 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
737 },
738 .consumer_supplies = magician_max1587a_consumers,
739 .num_consumer_supplies = ARRAY_SIZE(magician_max1587a_consumers),
740};
741
742static struct max1586_subdev_data magician_max1587a_subdevs[] = {
743 {
744 .name = "vcc_core",
745 .id = MAX1586_V3,
746 .platform_data = &magician_max1587a_v3_info,
747 }
748};
749
750static struct max1586_platform_data magician_max1587a_info = {
751 .subdevs = magician_max1587a_subdevs,
752 .num_subdevs = ARRAY_SIZE(magician_max1587a_subdevs),
753 /*
754 * NOTICE measured directly on the PCB (board_id == 0x3a), but
755 * if R24 is present, it will boost the voltage
756 * (write 1.475V, get 1.645V and smoke)
757 */
758 .v3_gain = MAX1586_GAIN_NO_R24,
759};
760
761static struct i2c_board_info magician_pwr_i2c_board_info[] __initdata = {
762 {
763 I2C_BOARD_INFO("max1586", 0x14),
764 .platform_data = &magician_max1587a_info,
765 },
766};
767
768/*
769 * MMC/SD
770 */
771
772static int magician_mci_init(struct device *dev,
773 irq_handler_t detect_irq, void *data)
774{
775 return request_irq(IRQ_MAGICIAN_SD, detect_irq, 0,
776 "mmc card detect", data);
777}
778
779static void magician_mci_exit(struct device *dev, void *data)
780{
781 free_irq(IRQ_MAGICIAN_SD, data);
782}
783
784static struct pxamci_platform_data magician_mci_info = {
785 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
786 .init = magician_mci_init,
787 .exit = magician_mci_exit,
788 .gpio_card_ro_invert = 1,
789};
790
791/*
792 * Write protect on EGPIO register 5 index 4, this is on the second HTC
793 * EGPIO chip which starts at register 4, so we need offset 8+4=12 on that
794 * particular chip.
795 */
796#define EGPIO_MAGICIAN_nSD_READONLY_OFFSET 12
797/*
798 * Power on EGPIO register 2 index 0, so this is on the first HTC EGPIO chip
799 * starting at register 0 so we need offset 2*8+0 = 16 on that chip.
800 */
801#define EGPIO_MAGICIAN_nSD_POWER_OFFSET 16
802
803static struct gpiod_lookup_table magician_mci_gpio_table = {
804 .dev_id = "pxa2xx-mci.0",
805 .table = {
806 GPIO_LOOKUP("htc-egpio-1", EGPIO_MAGICIAN_nSD_READONLY_OFFSET,
807 "wp", GPIO_ACTIVE_HIGH),
808 GPIO_LOOKUP("htc-egpio-0", EGPIO_MAGICIAN_nSD_POWER_OFFSET,
809 "power", GPIO_ACTIVE_HIGH),
810 { },
811 },
812};
813
814/*
815 * USB OHCI
816 */
817
818static struct pxaohci_platform_data magician_ohci_info = {
819 .port_mode = PMM_PERPORT_MODE,
820 /* port1: CSR Bluetooth, port2: OTG with UDC */
821 .flags = ENABLE_PORT1 | ENABLE_PORT2 | POWER_CONTROL_LOW,
822 .power_budget = 0,
823 .power_on_delay = 100,
824};
825
826/*
827 * StrataFlash
828 */
829
830static int magician_flash_init(struct platform_device *pdev)
831{
832 int ret = gpio_request(EGPIO_MAGICIAN_FLASH_VPP, "flash Vpp enable");
833
834 if (ret) {
835 pr_err("Cannot request flash enable GPIO (%i)\n", ret);
836 return ret;
837 }
838
839 ret = gpio_direction_output(EGPIO_MAGICIAN_FLASH_VPP, 1);
840 if (ret) {
841 pr_err("Cannot set direction for flash enable (%i)\n", ret);
842 gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
843 }
844
845 return ret;
846}
847
848static void magician_set_vpp(struct platform_device *pdev, int vpp)
849{
850 gpio_set_value(EGPIO_MAGICIAN_FLASH_VPP, vpp);
851}
852
853static void magician_flash_exit(struct platform_device *pdev)
854{
855 gpio_free(EGPIO_MAGICIAN_FLASH_VPP);
856}
857
858static struct resource strataflash_resource = {
859 .start = PXA_CS0_PHYS,
860 .end = PXA_CS0_PHYS + SZ_64M - 1,
861 .flags = IORESOURCE_MEM,
862};
863
864static struct mtd_partition magician_flash_parts[] = {
865 {
866 .name = "Bootloader",
867 .offset = 0x0,
868 .size = 0x40000,
869 .mask_flags = MTD_WRITEABLE, /* EXPERIMENTAL */
870 },
871 {
872 .name = "Linux Kernel",
873 .offset = 0x40000,
874 .size = MTDPART_SIZ_FULL,
875 },
876};
877
878/*
879 * physmap-flash driver
880 */
881
882static struct physmap_flash_data strataflash_data = {
883 .width = 4,
884 .init = magician_flash_init,
885 .set_vpp = magician_set_vpp,
886 .exit = magician_flash_exit,
887 .parts = magician_flash_parts,
888 .nr_parts = ARRAY_SIZE(magician_flash_parts),
889};
890
891static struct platform_device strataflash = {
892 .name = "physmap-flash",
893 .id = -1,
894 .resource = &strataflash_resource,
895 .num_resources = 1,
896 .dev = {
897 .platform_data = &strataflash_data,
898 },
899};
900
901/*
902 * PXA I2C main controller
903 */
904
905static struct i2c_pxa_platform_data i2c_info = {
906 /* OV9640 I2C device doesn't support fast mode */
907 .fast_mode = 0,
908};
909
910/*
911 * PXA I2C power controller
912 */
913
914static struct i2c_pxa_platform_data magician_i2c_power_info = {
915 .fast_mode = 1,
916};
917
918/*
919 * Touchscreen
920 */
921
922static struct ads7846_platform_data ads7846_pdata = {
923 .model = 7846,
924 .x_plate_ohms = 317,
925 .y_plate_ohms = 500,
926 .pressure_max = 1023, /* with x plate ohms it will overflow 255 */
927 .debounce_max = 3, /* first readout is always bad */
928 .debounce_tol = 30,
929 .debounce_rep = 0,
930 .gpio_pendown = GPIO115_MAGICIAN_nPEN_IRQ,
931 .keep_vref_on = 1,
932 .wakeup = true,
933 .vref_delay_usecs = 100,
934 .penirq_recheck_delay_usecs = 100,
935};
936
937struct pxa2xx_spi_chip tsc2046_chip_info = {
938 .tx_threshold = 1,
939 .rx_threshold = 2,
940 .timeout = 64,
941 /* NOTICE must be GPIO, incompatibility with hw PXA SPI framing */
942 .gpio_cs = GPIO14_MAGICIAN_TSC2046_CS,
943};
944
945static struct pxa2xx_spi_controller magician_spi_info = {
946 .num_chipselect = 1,
947 .enable_dma = 1,
948};
949
950static struct spi_board_info ads7846_spi_board_info[] __initdata = {
951 {
952 .modalias = "ads7846",
953 .bus_num = 2,
954 .max_speed_hz = 2500000,
955 .platform_data = &ads7846_pdata,
956 .controller_data = &tsc2046_chip_info,
957 .irq = PXA_GPIO_TO_IRQ(GPIO115_MAGICIAN_nPEN_IRQ),
958 },
959};
960
961/*
962 * Platform devices
963 */
964
965static struct platform_device *devices[] __initdata = {
966 &gpio_keys,
967 &egpio,
968 &backlight,
969 &pasic3,
970 &bq24022,
971 &gpio_vbus,
972 &power_supply,
973 &strataflash,
974 &leds_gpio,
975 &vads7846_device,
976};
977
978static struct gpio magician_global_gpios[] = {
979 { GPIO13_MAGICIAN_CPLD_IRQ, GPIOF_IN, "CPLD_IRQ" },
980 { GPIO107_MAGICIAN_DS1WM_IRQ, GPIOF_IN, "DS1WM_IRQ" },
981
982 /* NOTICE valid LCD init sequence */
983 { GPIO106_MAGICIAN_LCD_DCDC_NRESET, GPIOF_OUT_INIT_LOW, "LCD DCDC nreset" },
984 { GPIO104_MAGICIAN_LCD_VOFF_EN, GPIOF_OUT_INIT_LOW, "LCD VOFF enable" },
985 { GPIO105_MAGICIAN_LCD_VON_EN, GPIOF_OUT_INIT_LOW, "LCD VON enable" },
986};
987
988static void __init magician_init(void)
989{
990 void __iomem *cpld;
991 int lcd_select;
992 int err;
993
994 pxa2xx_mfp_config(ARRAY_AND_SIZE(magician_pin_config));
995 err = gpio_request_array(ARRAY_AND_SIZE(magician_global_gpios));
996 if (err)
997 pr_err("magician: Failed to request global GPIOs: %d\n", err);
998
999 pxa_set_ffuart_info(NULL);
1000 pxa_set_btuart_info(NULL);
1001
1002 pwm_add_table(magician_pwm_lookup, ARRAY_SIZE(magician_pwm_lookup));
1003
1004 pxa_set_ficp_info(&magician_ficp_info);
1005 pxa27x_set_i2c_power_info(&magician_i2c_power_info);
1006 pxa_set_i2c_info(&i2c_info);
1007
1008 i2c_register_board_info(1,
1009 ARRAY_AND_SIZE(magician_pwr_i2c_board_info));
1010
1011 gpiod_add_lookup_table(&magician_mci_gpio_table);
1012 pxa_set_mci_info(&magician_mci_info);
1013 pxa_set_ohci_info(&magician_ohci_info);
1014 pxa_set_udc_info(&magician_udc_info);
1015
1016 /* Check LCD type we have */
1017 cpld = ioremap(PXA_CS3_PHYS, 0x1000);
1018 if (cpld) {
1019 u8 board_id = __raw_readb(cpld + 0x14);
1020
1021 iounmap(cpld);
1022 system_rev = board_id & 0x7;
1023 lcd_select = board_id & 0x8;
1024 pr_info("LCD type: %s\n", lcd_select ? "Samsung" : "Toppoly");
1025 if (lcd_select && (system_rev < 3))
1026 /* NOTICE valid LCD init sequence */
1027 gpio_request_one(GPIO75_MAGICIAN_SAMSUNG_POWER,
1028 GPIOF_OUT_INIT_LOW, "Samsung LCD Power");
1029 pxa_set_fb_info(NULL,
1030 lcd_select ? &samsung_info : &toppoly_info);
1031 } else
1032 pr_err("LCD detection: CPLD mapping failed\n");
1033
1034 pxa2xx_set_spi_info(2, &magician_spi_info);
1035 spi_register_board_info(ARRAY_AND_SIZE(ads7846_spi_board_info));
1036
1037 regulator_register_always_on(0, "power", pwm_backlight_supply,
1038 ARRAY_SIZE(pwm_backlight_supply), 5000000);
1039
1040 gpiod_add_lookup_table(&bq24022_gpiod_table);
1041 gpiod_add_lookup_table(&gpio_vbus_gpiod_table);
1042 platform_add_devices(ARRAY_AND_SIZE(devices));
1043}
1044
1045MACHINE_START(MAGICIAN, "HTC Magician")
1046 .atag_offset = 0x100,
1047 .map_io = pxa27x_map_io,
1048 .nr_irqs = MAGICIAN_NR_IRQS,
1049 .init_irq = pxa27x_init_irq,
1050 .handle_irq = pxa27x_handle_irq,
1051 .init_machine = magician_init,
1052 .init_time = pxa_timer_init,
1053 .restart = pxa_restart,
1054MACHINE_END