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