[ARM] pxa/MioA701: add gpio_vbus driver
[deliverable/linux.git] / arch / arm / mach-pxa / mioa701.c
CommitLineData
eda6f6ec
RJ
1/*
2 * Handles the Mitac Mio A701 Board
3 *
4 * Copyright (C) 2008 Robert Jarzmik
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/platform_device.h>
25#include <linux/sysdev.h>
26#include <linux/input.h>
27#include <linux/delay.h>
28#include <linux/gpio_keys.h>
29#include <linux/pwm_backlight.h>
30#include <linux/rtc.h>
31#include <linux/leds.h>
32#include <linux/gpio.h>
33#include <linux/interrupt.h>
34#include <linux/irq.h>
35#include <linux/pda_power.h>
36#include <linux/power_supply.h>
4aa89f97 37#include <linux/wm97xx_batt.h>
eda6f6ec 38#include <linux/mtd/physmap.h>
689b4feb 39#include <linux/usb/gpio_vbus.h>
eda6f6ec
RJ
40
41#include <asm/mach-types.h>
42#include <asm/mach/arch.h>
51c62982
EM
43
44#include <mach/pxa27x.h>
5bf3df3f 45#include <mach/regs-rtc.h>
eda6f6ec
RJ
46#include <mach/pxa27x_keypad.h>
47#include <mach/pxafb.h>
eda6f6ec
RJ
48#include <mach/mmc.h>
49#include <mach/udc.h>
50#include <mach/pxa27x-udc.h>
8e7ccddf
RJ
51#include <mach/i2c.h>
52#include <mach/camera.h>
53#include <media/soc_camera.h>
eda6f6ec
RJ
54
55#include <mach/mioa701.h>
56
57#include "generic.h"
58#include "devices.h"
59
60static unsigned long mioa701_pin_config[] = {
61 /* Mio global */
c96763d4 62 MIO_CFG_OUT(GPIO9_CHARGE_EN, AF0, DRIVE_LOW),
eda6f6ec
RJ
63 MIO_CFG_OUT(GPIO18_POWEROFF, AF0, DRIVE_LOW),
64 MFP_CFG_OUT(GPIO3, AF0, DRIVE_HIGH),
65 MFP_CFG_OUT(GPIO4, AF0, DRIVE_HIGH),
c96763d4 66 MIO_CFG_IN(GPIO80_MAYBE_CHARGE_VDROP, AF0),
eda6f6ec
RJ
67
68 /* Backlight PWM 0 */
69 GPIO16_PWM0_OUT,
70
71 /* MMC */
72 GPIO32_MMC_CLK,
73 GPIO92_MMC_DAT_0,
74 GPIO109_MMC_DAT_1,
75 GPIO110_MMC_DAT_2,
76 GPIO111_MMC_DAT_3,
77 GPIO112_MMC_CMD,
78 MIO_CFG_IN(GPIO78_SDIO_RO, AF0),
79 MIO_CFG_IN(GPIO15_SDIO_INSERT, AF0),
80 MIO_CFG_OUT(GPIO91_SDIO_EN, AF0, DRIVE_LOW),
81
82 /* USB */
c96763d4 83 MIO_CFG_IN(GPIO13_nUSB_DETECT, AF0),
eda6f6ec
RJ
84 MIO_CFG_OUT(GPIO22_USB_ENABLE, AF0, DRIVE_LOW),
85
86 /* LCD */
87 GPIO58_LCD_LDD_0,
88 GPIO59_LCD_LDD_1,
89 GPIO60_LCD_LDD_2,
90 GPIO61_LCD_LDD_3,
91 GPIO62_LCD_LDD_4,
92 GPIO63_LCD_LDD_5,
93 GPIO64_LCD_LDD_6,
94 GPIO65_LCD_LDD_7,
95 GPIO66_LCD_LDD_8,
96 GPIO67_LCD_LDD_9,
97 GPIO68_LCD_LDD_10,
98 GPIO69_LCD_LDD_11,
99 GPIO70_LCD_LDD_12,
100 GPIO71_LCD_LDD_13,
101 GPIO72_LCD_LDD_14,
102 GPIO73_LCD_LDD_15,
103 GPIO74_LCD_FCLK,
104 GPIO75_LCD_LCLK,
105 GPIO76_LCD_PCLK,
106
8e7ccddf
RJ
107 /* QCI */
108 GPIO12_CIF_DD_7,
109 GPIO17_CIF_DD_6,
110 GPIO50_CIF_DD_3,
111 GPIO51_CIF_DD_2,
112 GPIO52_CIF_DD_4,
113 GPIO53_CIF_MCLK,
114 GPIO54_CIF_PCLK,
115 GPIO55_CIF_DD_1,
116 GPIO81_CIF_DD_0,
117 GPIO82_CIF_DD_5,
118 GPIO84_CIF_FV,
119 GPIO85_CIF_LV,
120
eda6f6ec 121 /* Bluetooth */
c96763d4 122 MIO_CFG_IN(GPIO14_BT_nACTIVITY, AF0),
eda6f6ec
RJ
123 GPIO44_BTUART_CTS,
124 GPIO42_BTUART_RXD,
125 GPIO45_BTUART_RTS,
126 GPIO43_BTUART_TXD,
127 MIO_CFG_OUT(GPIO83_BT_ON, AF0, DRIVE_LOW),
c96763d4
RJ
128 MIO_CFG_OUT(GPIO77_BT_UNKNOWN1, AF0, DRIVE_HIGH),
129 MIO_CFG_OUT(GPIO86_BT_MAYBE_nRESET, AF0, DRIVE_HIGH),
eda6f6ec
RJ
130
131 /* GPS */
132 MIO_CFG_OUT(GPIO23_GPS_UNKNOWN1, AF0, DRIVE_LOW),
133 MIO_CFG_OUT(GPIO26_GPS_ON, AF0, DRIVE_LOW),
134 MIO_CFG_OUT(GPIO27_GPS_RESET, AF0, DRIVE_LOW),
135 MIO_CFG_OUT(GPIO106_GPS_UNKNOWN2, AF0, DRIVE_LOW),
136 MIO_CFG_OUT(GPIO107_GPS_UNKNOWN3, AF0, DRIVE_LOW),
137 GPIO46_STUART_RXD,
138 GPIO47_STUART_TXD,
139
140 /* GSM */
141 MIO_CFG_OUT(GPIO24_GSM_MOD_RESET_CMD, AF0, DRIVE_LOW),
142 MIO_CFG_OUT(GPIO88_GSM_nMOD_ON_CMD, AF0, DRIVE_HIGH),
143 MIO_CFG_OUT(GPIO90_GSM_nMOD_OFF_CMD, AF0, DRIVE_HIGH),
144 MIO_CFG_OUT(GPIO114_GSM_nMOD_DTE_UART_STATE, AF0, DRIVE_HIGH),
145 MIO_CFG_IN(GPIO25_GSM_MOD_ON_STATE, AF0),
146 MIO_CFG_IN(GPIO113_GSM_EVENT, AF0) | WAKEUP_ON_EDGE_BOTH,
147 GPIO34_FFUART_RXD,
148 GPIO35_FFUART_CTS,
149 GPIO36_FFUART_DCD,
150 GPIO37_FFUART_DSR,
151 GPIO39_FFUART_TXD,
152 GPIO40_FFUART_DTR,
153 GPIO41_FFUART_RTS,
154
155 /* Sound */
156 GPIO89_AC97_SYSCLK,
157 MIO_CFG_IN(GPIO12_HPJACK_INSERT, AF0),
158
159 /* Leds */
160 MIO_CFG_OUT(GPIO10_LED_nCharging, AF0, DRIVE_HIGH),
161 MIO_CFG_OUT(GPIO97_LED_nBlue, AF0, DRIVE_HIGH),
162 MIO_CFG_OUT(GPIO98_LED_nOrange, AF0, DRIVE_HIGH),
163 MIO_CFG_OUT(GPIO82_LED_nVibra, AF0, DRIVE_HIGH),
164 MIO_CFG_OUT(GPIO115_LED_nKeyboard, AF0, DRIVE_HIGH),
165
166 /* Keyboard */
167 MIO_CFG_IN(GPIO0_KEY_POWER, AF0) | WAKEUP_ON_EDGE_BOTH,
168 MIO_CFG_IN(GPIO93_KEY_VOLUME_UP, AF0),
169 MIO_CFG_IN(GPIO94_KEY_VOLUME_DOWN, AF0),
170 GPIO100_KP_MKIN_0,
171 GPIO101_KP_MKIN_1,
172 GPIO102_KP_MKIN_2,
173 GPIO103_KP_MKOUT_0,
174 GPIO104_KP_MKOUT_1,
175 GPIO105_KP_MKOUT_2,
176
8e7ccddf
RJ
177 /* I2C */
178 GPIO117_I2C_SCL,
179 GPIO118_I2C_SDA,
180
eda6f6ec 181 /* Unknown */
eda6f6ec
RJ
182 MFP_CFG_IN(GPIO20, AF0),
183 MFP_CFG_IN(GPIO21, AF0),
184 MFP_CFG_IN(GPIO33, AF0),
185 MFP_CFG_OUT(GPIO49, AF0, DRIVE_HIGH),
186 MFP_CFG_OUT(GPIO57, AF0, DRIVE_HIGH),
eda6f6ec
RJ
187 MFP_CFG_IN(GPIO96, AF0),
188 MFP_CFG_OUT(GPIO116, AF0, DRIVE_HIGH),
189};
190
191#define MIO_GPIO_IN(num, _desc) \
192 { .gpio = (num), .dir = 0, .desc = (_desc) }
193#define MIO_GPIO_OUT(num, _init, _desc) \
194 { .gpio = (num), .dir = 1, .init = (_init), .desc = (_desc) }
195struct gpio_ress {
196 unsigned gpio : 8;
197 unsigned dir : 1;
198 unsigned init : 1;
199 char *desc;
200};
201
202static int mio_gpio_request(struct gpio_ress *gpios, int size)
203{
204 int i, rc = 0;
205 int gpio;
206 int dir;
207
208 for (i = 0; (!rc) && (i < size); i++) {
209 gpio = gpios[i].gpio;
210 dir = gpios[i].dir;
211 rc = gpio_request(gpio, gpios[i].desc);
212 if (rc) {
213 printk(KERN_ERR "Error requesting GPIO %d(%s) : %d\n",
214 gpio, gpios[i].desc, rc);
215 continue;
216 }
217 if (dir)
218 gpio_direction_output(gpio, gpios[i].init);
219 else
220 gpio_direction_input(gpio);
221 }
222 while ((rc) && (--i >= 0))
223 gpio_free(gpios[i].gpio);
224 return rc;
225}
226
227static void mio_gpio_free(struct gpio_ress *gpios, int size)
228{
229 int i;
230
231 for (i = 0; i < size; i++)
232 gpio_free(gpios[i].gpio);
233}
234
235/* LCD Screen and Backlight */
236static struct platform_pwm_backlight_data mioa701_backlight_data = {
237 .pwm_id = 0,
238 .max_brightness = 100,
239 .dft_brightness = 50,
240 .pwm_period_ns = 4000 * 1024, /* Fl = 250kHz */
241};
242
243/*
244 * LTM0305A776C LCD panel timings
245 *
246 * see:
247 * - the LTM0305A776C datasheet,
248 * - and the PXA27x Programmers' manual
249 */
250static struct pxafb_mode_info mioa701_ltm0305a776c = {
251 .pixclock = 220000, /* CLK=4.545 MHz */
252 .xres = 240,
253 .yres = 320,
254 .bpp = 16,
255 .hsync_len = 4,
256 .vsync_len = 2,
257 .left_margin = 6,
258 .right_margin = 4,
259 .upper_margin = 5,
260 .lower_margin = 3,
261};
262
263static void mioa701_lcd_power(int on, struct fb_var_screeninfo *si)
264{
265 gpio_set_value(GPIO87_LCD_POWER, on);
266}
267
268static struct pxafb_mach_info mioa701_pxafb_info = {
269 .modes = &mioa701_ltm0305a776c,
270 .num_modes = 1,
271 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
272 .pxafb_lcd_power = mioa701_lcd_power,
273};
274
275/*
276 * Keyboard configuration
277 */
278static unsigned int mioa701_matrix_keys[] = {
279 KEY(0, 0, KEY_UP),
280 KEY(0, 1, KEY_RIGHT),
281 KEY(0, 2, KEY_MEDIA),
282 KEY(1, 0, KEY_DOWN),
283 KEY(1, 1, KEY_ENTER),
284 KEY(1, 2, KEY_CONNECT), /* GPS key */
285 KEY(2, 0, KEY_LEFT),
286 KEY(2, 1, KEY_PHONE), /* Phone Green key */
287 KEY(2, 2, KEY_CAMERA) /* Camera key */
288};
289static struct pxa27x_keypad_platform_data mioa701_keypad_info = {
290 .matrix_key_rows = 3,
291 .matrix_key_cols = 3,
292 .matrix_key_map = mioa701_matrix_keys,
293 .matrix_key_map_size = ARRAY_SIZE(mioa701_matrix_keys),
294};
295
296/*
297 * GPIO Key Configuration
298 */
299#define MIO_KEY(key, _gpio, _desc, _wakeup) \
300 { .code = (key), .gpio = (_gpio), .active_low = 0, \
301 .desc = (_desc), .type = EV_KEY, .wakeup = (_wakeup) }
302static struct gpio_keys_button mioa701_button_table[] = {
303 MIO_KEY(KEY_EXIT, GPIO0_KEY_POWER, "Power button", 1),
304 MIO_KEY(KEY_VOLUMEUP, GPIO93_KEY_VOLUME_UP, "Volume up", 0),
305 MIO_KEY(KEY_VOLUMEDOWN, GPIO94_KEY_VOLUME_DOWN, "Volume down", 0),
306 MIO_KEY(KEY_HP, GPIO12_HPJACK_INSERT, "HP jack detect", 0)
307};
308
309static struct gpio_keys_platform_data mioa701_gpio_keys_data = {
310 .buttons = mioa701_button_table,
311 .nbuttons = ARRAY_SIZE(mioa701_button_table),
312};
313
314/*
315 * Leds and vibrator
316 */
317#define ONE_LED(_gpio, _name) \
318{ .gpio = (_gpio), .name = (_name), .active_low = true }
319static struct gpio_led gpio_leds[] = {
320 ONE_LED(GPIO10_LED_nCharging, "mioa701:charging"),
321 ONE_LED(GPIO97_LED_nBlue, "mioa701:blue"),
322 ONE_LED(GPIO98_LED_nOrange, "mioa701:orange"),
323 ONE_LED(GPIO82_LED_nVibra, "mioa701:vibra"),
324 ONE_LED(GPIO115_LED_nKeyboard, "mioa701:keyboard")
325};
326
327static struct gpio_led_platform_data gpio_led_info = {
328 .leds = gpio_leds,
329 .num_leds = ARRAY_SIZE(gpio_leds),
330};
331
332/*
333 * GSM Sagem XS200 chip
334 *
335 * GSM handling was purged from kernel. For history, this is the way to go :
336 * - init : GPIO24_GSM_MOD_RESET_CMD = 0, GPIO114_GSM_nMOD_DTE_UART_STATE = 1
337 * GPIO88_GSM_nMOD_ON_CMD = 1, GPIO90_GSM_nMOD_OFF_CMD = 1
338 * - reset : GPIO24_GSM_MOD_RESET_CMD = 1, msleep(100),
339 * GPIO24_GSM_MOD_RESET_CMD = 0
340 * - turn on : GPIO88_GSM_nMOD_ON_CMD = 0, msleep(1000),
341 * GPIO88_GSM_nMOD_ON_CMD = 1
342 * - turn off : GPIO90_GSM_nMOD_OFF_CMD = 0, msleep(1000),
343 * GPIO90_GSM_nMOD_OFF_CMD = 1
344 */
345static int is_gsm_on(void)
346{
347 int is_on;
348
349 is_on = !!gpio_get_value(GPIO25_GSM_MOD_ON_STATE);
350 return is_on;
351}
352
353irqreturn_t gsm_on_irq(int irq, void *p)
354{
355 printk(KERN_DEBUG "Mioa701: GSM status changed to %s\n",
356 is_gsm_on() ? "on" : "off");
357 return IRQ_HANDLED;
358}
359
360struct gpio_ress gsm_gpios[] = {
361 MIO_GPIO_IN(GPIO25_GSM_MOD_ON_STATE, "GSM state"),
362 MIO_GPIO_IN(GPIO113_GSM_EVENT, "GSM event"),
363};
364
365static int __init gsm_init(void)
366{
367 int rc;
368
369 rc = mio_gpio_request(ARRAY_AND_SIZE(gsm_gpios));
370 if (rc)
371 goto err_gpio;
372 rc = request_irq(gpio_to_irq(GPIO25_GSM_MOD_ON_STATE), gsm_on_irq,
373 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
374 "GSM XS200 Power Irq", NULL);
375 if (rc)
376 goto err_irq;
377
378 gpio_set_wake(GPIO113_GSM_EVENT, 1);
379 return 0;
380
381err_irq:
382 printk(KERN_ERR "Mioa701: Can't request GSM_ON irq\n");
383 mio_gpio_free(ARRAY_AND_SIZE(gsm_gpios));
384err_gpio:
385 printk(KERN_ERR "Mioa701: gsm not available\n");
386 return rc;
387}
388
389static void gsm_exit(void)
390{
391 free_irq(gpio_to_irq(GPIO25_GSM_MOD_ON_STATE), NULL);
392 mio_gpio_free(ARRAY_AND_SIZE(gsm_gpios));
393}
394
395/*
396 * Bluetooth BRF6150 chip
397 *
398 * BT handling was purged from kernel. For history, this is the way to go :
399 * - turn on : GPIO83_BT_ON = 1
400 * - turn off : GPIO83_BT_ON = 0
401 */
402
403/*
404 * GPS Sirf Star III chip
405 *
406 * GPS handling was purged from kernel. For history, this is the way to go :
407 * - init : GPIO23_GPS_UNKNOWN1 = 1, GPIO26_GPS_ON = 0, GPIO27_GPS_RESET = 0
408 * GPIO106_GPS_UNKNOWN2 = 0, GPIO107_GPS_UNKNOWN3 = 0
409 * - turn on : GPIO27_GPS_RESET = 1, GPIO26_GPS_ON = 1
410 * - turn off : GPIO26_GPS_ON = 0, GPIO27_GPS_RESET = 0
411 */
412
413/*
414 * USB UDC
415 */
416static void udc_power_command(int cmd)
417{
418 switch (cmd) {
419 case PXA2XX_UDC_CMD_DISCONNECT:
420 gpio_set_value(GPIO22_USB_ENABLE, 0);
421 break;
422 case PXA2XX_UDC_CMD_CONNECT:
423 gpio_set_value(GPIO22_USB_ENABLE, 1);
424 break;
425 default:
426 printk(KERN_INFO "udc_control: unknown command (0x%x)!\n", cmd);
427 break;
428 }
429}
430
431static int is_usb_connected(void)
432{
c96763d4 433 return !gpio_get_value(GPIO13_nUSB_DETECT);
eda6f6ec
RJ
434}
435
436static struct pxa2xx_udc_mach_info mioa701_udc_info = {
437 .udc_is_connected = is_usb_connected,
438 .udc_command = udc_power_command,
439};
440
441struct gpio_ress udc_gpios[] = {
442 MIO_GPIO_OUT(GPIO22_USB_ENABLE, 0, "USB Vbus enable")
443};
444
445static int __init udc_init(void)
446{
447 pxa_set_udc_info(&mioa701_udc_info);
448 return mio_gpio_request(ARRAY_AND_SIZE(udc_gpios));
449}
450
451static void udc_exit(void)
452{
453 mio_gpio_free(ARRAY_AND_SIZE(udc_gpios));
454}
455
689b4feb
RJ
456struct gpio_vbus_mach_info gpio_vbus_data = {
457 .gpio_vbus = GPIO13_nUSB_DETECT,
458 .gpio_vbus_inverted = 1,
459 .gpio_pullup = -1,
460};
461
eda6f6ec
RJ
462/*
463 * SDIO/MMC Card controller
464 */
465static void mci_setpower(struct device *dev, unsigned int vdd)
466{
467 struct pxamci_platform_data *p_d = dev->platform_data;
468
469 if ((1 << vdd) & p_d->ocr_mask)
470 gpio_set_value(GPIO91_SDIO_EN, 1); /* enable SDIO power */
471 else
472 gpio_set_value(GPIO91_SDIO_EN, 0); /* disable SDIO power */
473}
474
475static int mci_get_ro(struct device *dev)
476{
477 return gpio_get_value(GPIO78_SDIO_RO);
478}
479
480struct gpio_ress mci_gpios[] = {
481 MIO_GPIO_IN(GPIO78_SDIO_RO, "SDIO readonly detect"),
482 MIO_GPIO_IN(GPIO15_SDIO_INSERT, "SDIO insertion detect"),
483 MIO_GPIO_OUT(GPIO91_SDIO_EN, 0, "SDIO power enable")
484};
485
486static void mci_exit(struct device *dev, void *data)
487{
488 mio_gpio_free(ARRAY_AND_SIZE(mci_gpios));
489 free_irq(gpio_to_irq(GPIO15_SDIO_INSERT), data);
490}
491
492static struct pxamci_platform_data mioa701_mci_info;
493
494/**
495 * The card detect interrupt isn't debounced so we delay it by 250ms
496 * to give the card a chance to fully insert/eject.
497 */
498static int mci_init(struct device *dev, irq_handler_t detect_int, void *data)
499{
500 int rc;
501 int irq = gpio_to_irq(GPIO15_SDIO_INSERT);
502
503 rc = mio_gpio_request(ARRAY_AND_SIZE(mci_gpios));
504 if (rc)
505 goto err_gpio;
506 /* enable RE/FE interrupt on card insertion and removal */
507 rc = request_irq(irq, detect_int,
508 IRQF_DISABLED | IRQF_TRIGGER_RISING |
509 IRQF_TRIGGER_FALLING,
510 "MMC card detect", data);
511 if (rc)
512 goto err_irq;
513
514 mioa701_mci_info.detect_delay = msecs_to_jiffies(250);
515 return 0;
516
517err_irq:
518 dev_err(dev, "mioa701_mci_init: MMC/SD:"
519 " can't request MMC card detect IRQ\n");
520 mio_gpio_free(ARRAY_AND_SIZE(mci_gpios));
521err_gpio:
522 return rc;
523}
524
525static struct pxamci_platform_data mioa701_mci_info = {
526 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
527 .init = mci_init,
528 .get_ro = mci_get_ro,
529 .setpower = mci_setpower,
530 .exit = mci_exit,
531};
532
533/* FlashRAM */
534static struct resource strataflash_resource = {
535 .start = PXA_CS0_PHYS,
536 .end = PXA_CS0_PHYS + SZ_64M - 1,
537 .flags = IORESOURCE_MEM,
538};
539
540static struct physmap_flash_data strataflash_data = {
541 .width = 2,
542 /* .set_vpp = mioa701_set_vpp, */
543};
544
545static struct platform_device strataflash = {
546 .name = "physmap-flash",
547 .id = -1,
548 .resource = &strataflash_resource,
549 .num_resources = 1,
550 .dev = {
551 .platform_data = &strataflash_data,
552 },
553};
554
555/*
556 * Suspend/Resume bootstrap management
557 *
558 * MIO A701 reboot sequence is highly ROM dependant. From the one dissassembled,
559 * this sequence is as follows :
560 * - disables interrupts
561 * - initialize SDRAM (self refresh RAM into active RAM)
562 * - initialize GPIOs (depends on value at 0xa020b020)
563 * - initialize coprossessors
564 * - if edge detect on PWR_SCL(GPIO3), then proceed to cold start
565 * - or if value at 0xa020b000 not equal to 0x0f0f0f0f, proceed to cold start
566 * - else do a resume, ie. jump to addr 0xa0100000
567 */
568#define RESUME_ENABLE_ADDR 0xa020b000
569#define RESUME_ENABLE_VAL 0x0f0f0f0f
570#define RESUME_BT_ADDR 0xa020b020
571#define RESUME_UNKNOWN_ADDR 0xa020b024
572#define RESUME_VECTOR_ADDR 0xa0100000
573#define BOOTSTRAP_WORDS mioa701_bootstrap_lg/4
574
575static u32 *save_buffer;
576
577static void install_bootstrap(void)
578{
579 int i;
580 u32 *rom_bootstrap = phys_to_virt(RESUME_VECTOR_ADDR);
581 u32 *src = &mioa701_bootstrap;
582
583 for (i = 0; i < BOOTSTRAP_WORDS; i++)
584 rom_bootstrap[i] = src[i];
585}
586
587
588static int mioa701_sys_suspend(struct sys_device *sysdev, pm_message_t state)
589{
590 int i = 0, is_bt_on;
591 u32 *mem_resume_vector = phys_to_virt(RESUME_VECTOR_ADDR);
592 u32 *mem_resume_enabler = phys_to_virt(RESUME_ENABLE_ADDR);
593 u32 *mem_resume_bt = phys_to_virt(RESUME_BT_ADDR);
594 u32 *mem_resume_unknown = phys_to_virt(RESUME_UNKNOWN_ADDR);
595
596 /* Devices prepare suspend */
844c6f6a 597 is_bt_on = !!gpio_get_value(GPIO83_BT_ON);
eda6f6ec
RJ
598 pxa2xx_mfp_set_lpm(GPIO83_BT_ON,
599 is_bt_on ? MFP_LPM_DRIVE_HIGH : MFP_LPM_DRIVE_LOW);
600
601 for (i = 0; i < BOOTSTRAP_WORDS; i++)
602 save_buffer[i] = mem_resume_vector[i];
603 save_buffer[i++] = *mem_resume_enabler;
604 save_buffer[i++] = *mem_resume_bt;
605 save_buffer[i++] = *mem_resume_unknown;
606
607 *mem_resume_enabler = RESUME_ENABLE_VAL;
608 *mem_resume_bt = is_bt_on;
609
610 install_bootstrap();
611 return 0;
612}
613
614static int mioa701_sys_resume(struct sys_device *sysdev)
615{
616 int i = 0;
617 u32 *mem_resume_vector = phys_to_virt(RESUME_VECTOR_ADDR);
618 u32 *mem_resume_enabler = phys_to_virt(RESUME_ENABLE_ADDR);
619 u32 *mem_resume_bt = phys_to_virt(RESUME_BT_ADDR);
620 u32 *mem_resume_unknown = phys_to_virt(RESUME_UNKNOWN_ADDR);
621
622 for (i = 0; i < BOOTSTRAP_WORDS; i++)
623 mem_resume_vector[i] = save_buffer[i];
624 *mem_resume_enabler = save_buffer[i++];
625 *mem_resume_bt = save_buffer[i++];
626 *mem_resume_unknown = save_buffer[i++];
627
628 return 0;
629}
630
631static struct sysdev_class mioa701_sysclass = {
632 .name = "mioa701",
633};
634
635static struct sys_device sysdev_bootstrap = {
636 .cls = &mioa701_sysclass,
637};
638
639static struct sysdev_driver driver_bootstrap = {
640 .suspend = &mioa701_sys_suspend,
641 .resume = &mioa701_sys_resume,
642};
643
644static int __init bootstrap_init(void)
645{
646 int rc;
647 int save_size = mioa701_bootstrap_lg + (sizeof(u32) * 3);
648
649 rc = sysdev_class_register(&mioa701_sysclass);
650 if (rc) {
651 printk(KERN_ERR "Failed registering mioa701 sys class\n");
652 return -ENODEV;
653 }
654 rc = sysdev_register(&sysdev_bootstrap);
655 if (rc) {
656 printk(KERN_ERR "Failed registering mioa701 sys device\n");
657 return -ENODEV;
658 }
659 rc = sysdev_driver_register(&mioa701_sysclass, &driver_bootstrap);
660 if (rc) {
661 printk(KERN_ERR "Failed registering PMU sys driver\n");
662 return -ENODEV;
663 }
664
665 save_buffer = kmalloc(save_size, GFP_KERNEL);
666 if (!save_buffer)
667 return -ENOMEM;
668 printk(KERN_INFO "MioA701: allocated %d bytes for bootstrap\n",
669 save_size);
670 return 0;
671}
672
673static void bootstrap_exit(void)
674{
675 kfree(save_buffer);
676 sysdev_driver_unregister(&mioa701_sysclass, &driver_bootstrap);
677 sysdev_unregister(&sysdev_bootstrap);
678 sysdev_class_unregister(&mioa701_sysclass);
679
680 printk(KERN_CRIT "Unregistering mioa701 suspend will hang next"
681 "resume !!!\n");
682}
683
684/*
685 * Power Supply
686 */
687static char *supplicants[] = {
688 "mioa701_battery"
689};
690
4aa89f97
RJ
691static int is_ac_connected(void)
692{
693 return gpio_get_value(GPIO96_AC_DETECT);
694}
695
eda6f6ec
RJ
696static void mioa701_set_charge(int flags)
697{
c96763d4 698 gpio_set_value(GPIO9_CHARGE_EN, (flags == PDA_POWER_CHARGE_USB));
eda6f6ec
RJ
699}
700
701static struct pda_power_pdata power_pdata = {
4aa89f97
RJ
702 .is_ac_online = is_ac_connected,
703 .is_usb_online = is_usb_connected,
eda6f6ec
RJ
704 .set_charge = mioa701_set_charge,
705 .supplied_to = supplicants,
706 .num_supplicants = ARRAY_SIZE(supplicants),
707};
708
709static struct resource power_resources[] = {
710 [0] = {
711 .name = "ac",
4aa89f97
RJ
712 .start = gpio_to_irq(GPIO96_AC_DETECT),
713 .end = gpio_to_irq(GPIO96_AC_DETECT),
714 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
715 IORESOURCE_IRQ_LOWEDGE,
716 },
717 [1] = {
718 .name = "usb",
c96763d4
RJ
719 .start = gpio_to_irq(GPIO13_nUSB_DETECT),
720 .end = gpio_to_irq(GPIO13_nUSB_DETECT),
eda6f6ec
RJ
721 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
722 IORESOURCE_IRQ_LOWEDGE,
723 },
724};
725
726static struct platform_device power_dev = {
727 .name = "pda-power",
728 .id = -1,
729 .resource = power_resources,
730 .num_resources = ARRAY_SIZE(power_resources),
731 .dev = {
732 .platform_data = &power_pdata,
733 },
734};
735
4aa89f97
RJ
736static struct wm97xx_batt_info mioa701_battery_data = {
737 .batt_aux = WM97XX_AUX_ID1,
738 .temp_aux = -1,
739 .charge_gpio = -1,
740 .min_voltage = 0xc00,
741 .max_voltage = 0xfc0,
742 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LION,
743 .batt_div = 1,
744 .batt_mult = 1,
745 .batt_name = "mioa701_battery",
eda6f6ec
RJ
746};
747
8e7ccddf
RJ
748/*
749 * Camera interface
750 */
751struct pxacamera_platform_data mioa701_pxacamera_platform_data = {
752 .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
753 PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
754 .mclk_10khz = 5000,
eda6f6ec
RJ
755};
756
8e7ccddf
RJ
757static struct soc_camera_link iclink = {
758 .bus_id = 0, /* Must match id in pxa27x_device_camera in device.c */
eda6f6ec
RJ
759};
760
8e7ccddf
RJ
761/* Board I2C devices. */
762static struct i2c_board_info __initdata mioa701_i2c_devices[] = {
763 {
764 /* Must initialize before the camera(s) */
765 I2C_BOARD_INFO("mt9m111", 0x5d),
766 .platform_data = &iclink,
eda6f6ec 767 },
eda6f6ec
RJ
768};
769
8e7ccddf
RJ
770struct i2c_pxa_platform_data i2c_pdata = {
771 .fast_mode = 1,
772};
eda6f6ec
RJ
773
774/*
775 * Mio global
776 */
777
778/* Devices */
779#define MIO_PARENT_DEV(var, strname, tparent, pdata) \
780static struct platform_device var = { \
781 .name = strname, \
782 .id = -1, \
783 .dev = { \
784 .platform_data = pdata, \
785 .parent = tparent, \
786 }, \
787};
788#define MIO_SIMPLE_DEV(var, strname, pdata) \
789 MIO_PARENT_DEV(var, strname, NULL, pdata)
790
791MIO_SIMPLE_DEV(mioa701_gpio_keys, "gpio-keys", &mioa701_gpio_keys_data)
792MIO_PARENT_DEV(mioa701_backlight, "pwm-backlight", &pxa27x_device_pwm0.dev,
793 &mioa701_backlight_data);
794MIO_SIMPLE_DEV(mioa701_led, "leds-gpio", &gpio_led_info)
795MIO_SIMPLE_DEV(pxa2xx_pcm, "pxa2xx-pcm", NULL)
796MIO_SIMPLE_DEV(pxa2xx_ac97, "pxa2xx-ac97", NULL)
797MIO_PARENT_DEV(mio_wm9713_codec, "wm9713-codec", &pxa2xx_ac97.dev, NULL)
798MIO_SIMPLE_DEV(mioa701_sound, "mioa701-wm9713", NULL)
799MIO_SIMPLE_DEV(mioa701_board, "mioa701-board", NULL)
689b4feb 800MIO_SIMPLE_DEV(gpio_vbus, "gpio-vbus", &gpio_vbus_data);
eda6f6ec
RJ
801
802static struct platform_device *devices[] __initdata = {
803 &mioa701_gpio_keys,
804 &mioa701_backlight,
805 &mioa701_led,
806 &pxa2xx_pcm,
807 &pxa2xx_ac97,
808 &mio_wm9713_codec,
809 &mioa701_sound,
810 &power_dev,
811 &strataflash,
689b4feb
RJ
812 &gpio_vbus,
813 &mioa701_board,
eda6f6ec
RJ
814};
815
816static void mioa701_machine_exit(void);
817
818static void mioa701_poweroff(void)
819{
820 mioa701_machine_exit();
a0361a8a 821 arm_machine_restart('s');
eda6f6ec
RJ
822}
823
824static void mioa701_restart(char c)
825{
826 mioa701_machine_exit();
a0361a8a 827 arm_machine_restart('s');
eda6f6ec
RJ
828}
829
830struct gpio_ress global_gpios[] = {
c96763d4 831 MIO_GPIO_OUT(GPIO9_CHARGE_EN, 1, "Charger enable"),
eda6f6ec
RJ
832 MIO_GPIO_OUT(GPIO18_POWEROFF, 0, "Power Off"),
833 MIO_GPIO_OUT(GPIO87_LCD_POWER, 0, "LCD Power")
834};
835
836static void __init mioa701_machine_init(void)
837{
838 PSLR = 0xff100000; /* SYSDEL=125ms, PWRDEL=125ms, PSLR_SL_ROD=1 */
839 PCFR = PCFR_DC_EN | PCFR_GPR_EN | PCFR_OPDE;
840 RTTR = 32768 - 1; /* Reset crazy WinCE value */
841 UP2OCR = UP2OCR_HXOE;
842
843 pxa2xx_mfp_config(ARRAY_AND_SIZE(mioa701_pin_config));
844 mio_gpio_request(ARRAY_AND_SIZE(global_gpios));
845 bootstrap_init();
846 set_pxa_fb_info(&mioa701_pxafb_info);
847 pxa_set_mci_info(&mioa701_mci_info);
848 pxa_set_keypad_info(&mioa701_keypad_info);
4aa89f97 849 wm97xx_bat_set_pdata(&mioa701_battery_data);
eda6f6ec
RJ
850 udc_init();
851 pm_power_off = mioa701_poweroff;
852 arm_pm_restart = mioa701_restart;
853 platform_add_devices(devices, ARRAY_SIZE(devices));
854 gsm_init();
8e7ccddf
RJ
855
856 pxa_set_i2c_info(&i2c_pdata);
857 pxa_set_camera_info(&mioa701_pxacamera_platform_data);
858 i2c_register_board_info(0, ARRAY_AND_SIZE(mioa701_i2c_devices));
eda6f6ec
RJ
859}
860
861static void mioa701_machine_exit(void)
862{
863 udc_exit();
864 bootstrap_exit();
865 gsm_exit();
866}
867
868MACHINE_START(MIOA701, "MIO A701")
869 .phys_io = 0x40000000,
870 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
871 .boot_params = 0xa0000100,
872 .map_io = &pxa_map_io,
873 .init_irq = &pxa27x_init_irq,
874 .init_machine = mioa701_machine_init,
875 .timer = &pxa_timer,
876MACHINE_END
This page took 0.08811 seconds and 5 git commands to generate.