blob: 97c93a7a285c12b70a7249c25cd9f47ee1b2f493 [file] [log] [blame]
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +01001/*
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>
Robert Jarzmik4aa89f92008-11-15 16:09:59 +010037#include <linux/wm97xx_batt.h>
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +010038#include <linux/mtd/physmap.h>
Robert Jarzmik689b4fe2009-01-30 20:48:24 +010039#include <linux/usb/gpio_vbus.h>
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +010040
41#include <asm/mach-types.h>
42#include <asm/mach/arch.h>
Eric Miao51c62982009-01-02 23:17:22 +080043
44#include <mach/pxa27x.h>
Eric Miao5bf3df32009-01-20 11:04:16 +080045#include <mach/regs-rtc.h>
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +010046#include <mach/pxa27x_keypad.h>
47#include <mach/pxafb.h>
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +010048#include <mach/mmc.h>
49#include <mach/udc.h>
50#include <mach/pxa27x-udc.h>
Robert Jarzmik8e7ccdd2008-11-15 16:09:54 +010051#include <mach/i2c.h>
52#include <mach/camera.h>
53#include <media/soc_camera.h>
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +010054
55#include <mach/mioa701.h>
56
57#include "generic.h"
58#include "devices.h"
59
60static unsigned long mioa701_pin_config[] = {
61 /* Mio global */
Robert Jarzmikc96763d2008-11-18 20:23:32 +010062 MIO_CFG_OUT(GPIO9_CHARGE_EN, AF0, DRIVE_LOW),
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +010063 MIO_CFG_OUT(GPIO18_POWEROFF, AF0, DRIVE_LOW),
64 MFP_CFG_OUT(GPIO3, AF0, DRIVE_HIGH),
65 MFP_CFG_OUT(GPIO4, AF0, DRIVE_HIGH),
Robert Jarzmikc96763d2008-11-18 20:23:32 +010066 MIO_CFG_IN(GPIO80_MAYBE_CHARGE_VDROP, AF0),
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +010067
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 */
Robert Jarzmikc96763d2008-11-18 20:23:32 +010083 MIO_CFG_IN(GPIO13_nUSB_DETECT, AF0),
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +010084 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
Robert Jarzmik8e7ccdd2008-11-15 16:09:54 +0100107 /* 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
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100121 /* Bluetooth */
Robert Jarzmikc96763d2008-11-18 20:23:32 +0100122 MIO_CFG_IN(GPIO14_BT_nACTIVITY, AF0),
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100123 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),
Robert Jarzmikc96763d2008-11-18 20:23:32 +0100128 MIO_CFG_OUT(GPIO77_BT_UNKNOWN1, AF0, DRIVE_HIGH),
129 MIO_CFG_OUT(GPIO86_BT_MAYBE_nRESET, AF0, DRIVE_HIGH),
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100130
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
Robert Jarzmik8e7ccdd2008-11-15 16:09:54 +0100177 /* I2C */
178 GPIO117_I2C_SCL,
179 GPIO118_I2C_SDA,
180
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100181 /* Unknown */
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100182 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),
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100187 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 */
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100416static int is_usb_connected(void)
417{
Robert Jarzmikc96763d2008-11-18 20:23:32 +0100418 return !gpio_get_value(GPIO13_nUSB_DETECT);
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100419}
420
421static struct pxa2xx_udc_mach_info mioa701_udc_info = {
422 .udc_is_connected = is_usb_connected,
Robert Jarzmikcefdb2a2009-01-31 21:07:09 +0100423 .gpio_pullup = GPIO22_USB_ENABLE,
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100424};
425
Robert Jarzmik689b4fe2009-01-30 20:48:24 +0100426struct gpio_vbus_mach_info gpio_vbus_data = {
427 .gpio_vbus = GPIO13_nUSB_DETECT,
428 .gpio_vbus_inverted = 1,
429 .gpio_pullup = -1,
430};
431
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100432/*
433 * SDIO/MMC Card controller
434 */
435static void mci_setpower(struct device *dev, unsigned int vdd)
436{
437 struct pxamci_platform_data *p_d = dev->platform_data;
438
439 if ((1 << vdd) & p_d->ocr_mask)
440 gpio_set_value(GPIO91_SDIO_EN, 1); /* enable SDIO power */
441 else
442 gpio_set_value(GPIO91_SDIO_EN, 0); /* disable SDIO power */
443}
444
445static int mci_get_ro(struct device *dev)
446{
447 return gpio_get_value(GPIO78_SDIO_RO);
448}
449
450struct gpio_ress mci_gpios[] = {
451 MIO_GPIO_IN(GPIO78_SDIO_RO, "SDIO readonly detect"),
452 MIO_GPIO_IN(GPIO15_SDIO_INSERT, "SDIO insertion detect"),
453 MIO_GPIO_OUT(GPIO91_SDIO_EN, 0, "SDIO power enable")
454};
455
456static void mci_exit(struct device *dev, void *data)
457{
458 mio_gpio_free(ARRAY_AND_SIZE(mci_gpios));
459 free_irq(gpio_to_irq(GPIO15_SDIO_INSERT), data);
460}
461
462static struct pxamci_platform_data mioa701_mci_info;
463
464/**
465 * The card detect interrupt isn't debounced so we delay it by 250ms
466 * to give the card a chance to fully insert/eject.
467 */
468static int mci_init(struct device *dev, irq_handler_t detect_int, void *data)
469{
470 int rc;
471 int irq = gpio_to_irq(GPIO15_SDIO_INSERT);
472
473 rc = mio_gpio_request(ARRAY_AND_SIZE(mci_gpios));
474 if (rc)
475 goto err_gpio;
476 /* enable RE/FE interrupt on card insertion and removal */
477 rc = request_irq(irq, detect_int,
478 IRQF_DISABLED | IRQF_TRIGGER_RISING |
479 IRQF_TRIGGER_FALLING,
480 "MMC card detect", data);
481 if (rc)
482 goto err_irq;
483
484 mioa701_mci_info.detect_delay = msecs_to_jiffies(250);
485 return 0;
486
487err_irq:
488 dev_err(dev, "mioa701_mci_init: MMC/SD:"
489 " can't request MMC card detect IRQ\n");
490 mio_gpio_free(ARRAY_AND_SIZE(mci_gpios));
491err_gpio:
492 return rc;
493}
494
495static struct pxamci_platform_data mioa701_mci_info = {
496 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
497 .init = mci_init,
498 .get_ro = mci_get_ro,
499 .setpower = mci_setpower,
500 .exit = mci_exit,
501};
502
503/* FlashRAM */
504static struct resource strataflash_resource = {
505 .start = PXA_CS0_PHYS,
506 .end = PXA_CS0_PHYS + SZ_64M - 1,
507 .flags = IORESOURCE_MEM,
508};
509
510static struct physmap_flash_data strataflash_data = {
511 .width = 2,
512 /* .set_vpp = mioa701_set_vpp, */
513};
514
515static struct platform_device strataflash = {
516 .name = "physmap-flash",
517 .id = -1,
518 .resource = &strataflash_resource,
519 .num_resources = 1,
520 .dev = {
521 .platform_data = &strataflash_data,
522 },
523};
524
525/*
526 * Suspend/Resume bootstrap management
527 *
528 * MIO A701 reboot sequence is highly ROM dependant. From the one dissassembled,
529 * this sequence is as follows :
530 * - disables interrupts
531 * - initialize SDRAM (self refresh RAM into active RAM)
532 * - initialize GPIOs (depends on value at 0xa020b020)
533 * - initialize coprossessors
534 * - if edge detect on PWR_SCL(GPIO3), then proceed to cold start
535 * - or if value at 0xa020b000 not equal to 0x0f0f0f0f, proceed to cold start
536 * - else do a resume, ie. jump to addr 0xa0100000
537 */
538#define RESUME_ENABLE_ADDR 0xa020b000
539#define RESUME_ENABLE_VAL 0x0f0f0f0f
540#define RESUME_BT_ADDR 0xa020b020
541#define RESUME_UNKNOWN_ADDR 0xa020b024
542#define RESUME_VECTOR_ADDR 0xa0100000
543#define BOOTSTRAP_WORDS mioa701_bootstrap_lg/4
544
545static u32 *save_buffer;
546
547static void install_bootstrap(void)
548{
549 int i;
550 u32 *rom_bootstrap = phys_to_virt(RESUME_VECTOR_ADDR);
551 u32 *src = &mioa701_bootstrap;
552
553 for (i = 0; i < BOOTSTRAP_WORDS; i++)
554 rom_bootstrap[i] = src[i];
555}
556
557
558static int mioa701_sys_suspend(struct sys_device *sysdev, pm_message_t state)
559{
560 int i = 0, is_bt_on;
561 u32 *mem_resume_vector = phys_to_virt(RESUME_VECTOR_ADDR);
562 u32 *mem_resume_enabler = phys_to_virt(RESUME_ENABLE_ADDR);
563 u32 *mem_resume_bt = phys_to_virt(RESUME_BT_ADDR);
564 u32 *mem_resume_unknown = phys_to_virt(RESUME_UNKNOWN_ADDR);
565
566 /* Devices prepare suspend */
Robert Jarzmik844c6f62008-11-17 20:29:04 +0100567 is_bt_on = !!gpio_get_value(GPIO83_BT_ON);
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100568 pxa2xx_mfp_set_lpm(GPIO83_BT_ON,
569 is_bt_on ? MFP_LPM_DRIVE_HIGH : MFP_LPM_DRIVE_LOW);
570
571 for (i = 0; i < BOOTSTRAP_WORDS; i++)
572 save_buffer[i] = mem_resume_vector[i];
573 save_buffer[i++] = *mem_resume_enabler;
574 save_buffer[i++] = *mem_resume_bt;
575 save_buffer[i++] = *mem_resume_unknown;
576
577 *mem_resume_enabler = RESUME_ENABLE_VAL;
578 *mem_resume_bt = is_bt_on;
579
580 install_bootstrap();
581 return 0;
582}
583
584static int mioa701_sys_resume(struct sys_device *sysdev)
585{
586 int i = 0;
587 u32 *mem_resume_vector = phys_to_virt(RESUME_VECTOR_ADDR);
588 u32 *mem_resume_enabler = phys_to_virt(RESUME_ENABLE_ADDR);
589 u32 *mem_resume_bt = phys_to_virt(RESUME_BT_ADDR);
590 u32 *mem_resume_unknown = phys_to_virt(RESUME_UNKNOWN_ADDR);
591
592 for (i = 0; i < BOOTSTRAP_WORDS; i++)
593 mem_resume_vector[i] = save_buffer[i];
594 *mem_resume_enabler = save_buffer[i++];
595 *mem_resume_bt = save_buffer[i++];
596 *mem_resume_unknown = save_buffer[i++];
597
598 return 0;
599}
600
601static struct sysdev_class mioa701_sysclass = {
602 .name = "mioa701",
603};
604
605static struct sys_device sysdev_bootstrap = {
606 .cls = &mioa701_sysclass,
607};
608
609static struct sysdev_driver driver_bootstrap = {
610 .suspend = &mioa701_sys_suspend,
611 .resume = &mioa701_sys_resume,
612};
613
614static int __init bootstrap_init(void)
615{
616 int rc;
617 int save_size = mioa701_bootstrap_lg + (sizeof(u32) * 3);
618
619 rc = sysdev_class_register(&mioa701_sysclass);
620 if (rc) {
621 printk(KERN_ERR "Failed registering mioa701 sys class\n");
622 return -ENODEV;
623 }
624 rc = sysdev_register(&sysdev_bootstrap);
625 if (rc) {
626 printk(KERN_ERR "Failed registering mioa701 sys device\n");
627 return -ENODEV;
628 }
629 rc = sysdev_driver_register(&mioa701_sysclass, &driver_bootstrap);
630 if (rc) {
631 printk(KERN_ERR "Failed registering PMU sys driver\n");
632 return -ENODEV;
633 }
634
635 save_buffer = kmalloc(save_size, GFP_KERNEL);
636 if (!save_buffer)
637 return -ENOMEM;
638 printk(KERN_INFO "MioA701: allocated %d bytes for bootstrap\n",
639 save_size);
640 return 0;
641}
642
643static void bootstrap_exit(void)
644{
645 kfree(save_buffer);
646 sysdev_driver_unregister(&mioa701_sysclass, &driver_bootstrap);
647 sysdev_unregister(&sysdev_bootstrap);
648 sysdev_class_unregister(&mioa701_sysclass);
649
650 printk(KERN_CRIT "Unregistering mioa701 suspend will hang next"
651 "resume !!!\n");
652}
653
654/*
655 * Power Supply
656 */
657static char *supplicants[] = {
658 "mioa701_battery"
659};
660
Robert Jarzmik4aa89f92008-11-15 16:09:59 +0100661static int is_ac_connected(void)
662{
663 return gpio_get_value(GPIO96_AC_DETECT);
664}
665
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100666static void mioa701_set_charge(int flags)
667{
Robert Jarzmikc96763d2008-11-18 20:23:32 +0100668 gpio_set_value(GPIO9_CHARGE_EN, (flags == PDA_POWER_CHARGE_USB));
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100669}
670
671static struct pda_power_pdata power_pdata = {
Robert Jarzmik4aa89f92008-11-15 16:09:59 +0100672 .is_ac_online = is_ac_connected,
673 .is_usb_online = is_usb_connected,
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100674 .set_charge = mioa701_set_charge,
675 .supplied_to = supplicants,
676 .num_supplicants = ARRAY_SIZE(supplicants),
677};
678
679static struct resource power_resources[] = {
680 [0] = {
681 .name = "ac",
Robert Jarzmik4aa89f92008-11-15 16:09:59 +0100682 .start = gpio_to_irq(GPIO96_AC_DETECT),
683 .end = gpio_to_irq(GPIO96_AC_DETECT),
684 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
685 IORESOURCE_IRQ_LOWEDGE,
686 },
687 [1] = {
688 .name = "usb",
Robert Jarzmikc96763d2008-11-18 20:23:32 +0100689 .start = gpio_to_irq(GPIO13_nUSB_DETECT),
690 .end = gpio_to_irq(GPIO13_nUSB_DETECT),
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100691 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE |
692 IORESOURCE_IRQ_LOWEDGE,
693 },
694};
695
696static struct platform_device power_dev = {
697 .name = "pda-power",
698 .id = -1,
699 .resource = power_resources,
700 .num_resources = ARRAY_SIZE(power_resources),
701 .dev = {
702 .platform_data = &power_pdata,
703 },
704};
705
Robert Jarzmik4aa89f92008-11-15 16:09:59 +0100706static struct wm97xx_batt_info mioa701_battery_data = {
707 .batt_aux = WM97XX_AUX_ID1,
708 .temp_aux = -1,
709 .charge_gpio = -1,
710 .min_voltage = 0xc00,
711 .max_voltage = 0xfc0,
712 .batt_tech = POWER_SUPPLY_TECHNOLOGY_LION,
713 .batt_div = 1,
714 .batt_mult = 1,
715 .batt_name = "mioa701_battery",
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100716};
717
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100718/*
Robert Jarzmik8e7ccdd2008-11-15 16:09:54 +0100719 * Camera interface
720 */
721struct pxacamera_platform_data mioa701_pxacamera_platform_data = {
722 .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 |
723 PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
724 .mclk_10khz = 5000,
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100725};
726
Robert Jarzmik8e7ccdd2008-11-15 16:09:54 +0100727static struct soc_camera_link iclink = {
728 .bus_id = 0, /* Must match id in pxa27x_device_camera in device.c */
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100729};
730
Robert Jarzmik8e7ccdd2008-11-15 16:09:54 +0100731/* Board I2C devices. */
732static struct i2c_board_info __initdata mioa701_i2c_devices[] = {
733 {
734 /* Must initialize before the camera(s) */
735 I2C_BOARD_INFO("mt9m111", 0x5d),
736 .platform_data = &iclink,
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100737 },
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100738};
739
Robert Jarzmik8e7ccdd2008-11-15 16:09:54 +0100740struct i2c_pxa_platform_data i2c_pdata = {
741 .fast_mode = 1,
742};
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100743
744/*
745 * Mio global
746 */
747
748/* Devices */
749#define MIO_PARENT_DEV(var, strname, tparent, pdata) \
750static struct platform_device var = { \
751 .name = strname, \
752 .id = -1, \
753 .dev = { \
754 .platform_data = pdata, \
755 .parent = tparent, \
756 }, \
757};
758#define MIO_SIMPLE_DEV(var, strname, pdata) \
759 MIO_PARENT_DEV(var, strname, NULL, pdata)
760
761MIO_SIMPLE_DEV(mioa701_gpio_keys, "gpio-keys", &mioa701_gpio_keys_data)
762MIO_PARENT_DEV(mioa701_backlight, "pwm-backlight", &pxa27x_device_pwm0.dev,
763 &mioa701_backlight_data);
764MIO_SIMPLE_DEV(mioa701_led, "leds-gpio", &gpio_led_info)
765MIO_SIMPLE_DEV(pxa2xx_pcm, "pxa2xx-pcm", NULL)
766MIO_SIMPLE_DEV(pxa2xx_ac97, "pxa2xx-ac97", NULL)
767MIO_PARENT_DEV(mio_wm9713_codec, "wm9713-codec", &pxa2xx_ac97.dev, NULL)
768MIO_SIMPLE_DEV(mioa701_sound, "mioa701-wm9713", NULL)
769MIO_SIMPLE_DEV(mioa701_board, "mioa701-board", NULL)
Robert Jarzmik689b4fe2009-01-30 20:48:24 +0100770MIO_SIMPLE_DEV(gpio_vbus, "gpio-vbus", &gpio_vbus_data);
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100771
772static struct platform_device *devices[] __initdata = {
773 &mioa701_gpio_keys,
774 &mioa701_backlight,
775 &mioa701_led,
776 &pxa2xx_pcm,
777 &pxa2xx_ac97,
778 &mio_wm9713_codec,
779 &mioa701_sound,
780 &power_dev,
781 &strataflash,
Robert Jarzmik689b4fe2009-01-30 20:48:24 +0100782 &gpio_vbus,
783 &mioa701_board,
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100784};
785
786static void mioa701_machine_exit(void);
787
788static void mioa701_poweroff(void)
789{
790 mioa701_machine_exit();
Russell Kingbe093be2009-03-19 16:20:24 +0000791 arm_machine_restart('s', NULL);
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100792}
793
Russell Kingbe093be2009-03-19 16:20:24 +0000794static void mioa701_restart(char c, const char *cmd)
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100795{
796 mioa701_machine_exit();
Russell Kingbe093be2009-03-19 16:20:24 +0000797 arm_machine_restart('s', cmd);
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100798}
799
800struct gpio_ress global_gpios[] = {
Robert Jarzmikc96763d2008-11-18 20:23:32 +0100801 MIO_GPIO_OUT(GPIO9_CHARGE_EN, 1, "Charger enable"),
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100802 MIO_GPIO_OUT(GPIO18_POWEROFF, 0, "Power Off"),
803 MIO_GPIO_OUT(GPIO87_LCD_POWER, 0, "LCD Power")
804};
805
806static void __init mioa701_machine_init(void)
807{
808 PSLR = 0xff100000; /* SYSDEL=125ms, PWRDEL=125ms, PSLR_SL_ROD=1 */
809 PCFR = PCFR_DC_EN | PCFR_GPR_EN | PCFR_OPDE;
810 RTTR = 32768 - 1; /* Reset crazy WinCE value */
811 UP2OCR = UP2OCR_HXOE;
812
813 pxa2xx_mfp_config(ARRAY_AND_SIZE(mioa701_pin_config));
814 mio_gpio_request(ARRAY_AND_SIZE(global_gpios));
815 bootstrap_init();
816 set_pxa_fb_info(&mioa701_pxafb_info);
817 pxa_set_mci_info(&mioa701_mci_info);
818 pxa_set_keypad_info(&mioa701_keypad_info);
Robert Jarzmik4aa89f92008-11-15 16:09:59 +0100819 wm97xx_bat_set_pdata(&mioa701_battery_data);
Robert Jarzmikcefdb2a2009-01-31 21:07:09 +0100820 pxa_set_udc_info(&mioa701_udc_info);
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100821 pm_power_off = mioa701_poweroff;
822 arm_pm_restart = mioa701_restart;
823 platform_add_devices(devices, ARRAY_SIZE(devices));
824 gsm_init();
Robert Jarzmik8e7ccdd2008-11-15 16:09:54 +0100825
826 pxa_set_i2c_info(&i2c_pdata);
827 pxa_set_camera_info(&mioa701_pxacamera_platform_data);
828 i2c_register_board_info(0, ARRAY_AND_SIZE(mioa701_i2c_devices));
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100829}
830
831static void mioa701_machine_exit(void)
832{
Robert Jarzmikeda6f6e2008-08-17 09:34:30 +0100833 bootstrap_exit();
834 gsm_exit();
835}
836
837MACHINE_START(MIOA701, "MIO A701")
838 .phys_io = 0x40000000,
839 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
840 .boot_params = 0xa0000100,
841 .map_io = &pxa_map_io,
842 .init_irq = &pxa27x_init_irq,
843 .init_machine = mioa701_machine_init,
844 .timer = &pxa_timer,
845MACHINE_END