]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-pxa/tosa.c
Merge tag 'pxa-for-4.2' of https://github.com/rjarzmik/linux into next/soc
[karo-tx-linux.git] / arch / arm / mach-pxa / tosa.c
1 /*
2  *  Support for Sharp SL-C6000x PDAs
3  *  Model: (Tosa)
4  *
5  *  Copyright (c) 2005 Dirk Opfer
6  *
7  *      Based on code written by Sharp/Lineo for 2.4 kernels
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License version 2 as
11  *  published by the Free Software Foundation.
12  *
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/major.h>
19 #include <linux/fs.h>
20 #include <linux/interrupt.h>
21 #include <linux/delay.h>
22 #include <linux/fb.h>
23 #include <linux/mmc/host.h>
24 #include <linux/mfd/tc6393xb.h>
25 #include <linux/mfd/tmio.h>
26 #include <linux/mtd/nand.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/mtd/physmap.h>
29 #include <linux/pm.h>
30 #include <linux/gpio_keys.h>
31 #include <linux/input.h>
32 #include <linux/gpio.h>
33 #include <linux/power/gpio-charger.h>
34 #include <linux/spi/spi.h>
35 #include <linux/spi/pxa2xx_spi.h>
36 #include <linux/input/matrix_keypad.h>
37 #include <linux/i2c/pxa-i2c.h>
38 #include <linux/usb/gpio_vbus.h>
39 #include <linux/reboot.h>
40 #include <linux/memblock.h>
41
42 #include <asm/setup.h>
43 #include <asm/mach-types.h>
44
45 #include <mach/pxa25x.h>
46 #include <mach/reset.h>
47 #include <linux/platform_data/irda-pxaficp.h>
48 #include <linux/platform_data/mmc-pxamci.h>
49 #include <mach/udc.h>
50 #include <mach/tosa_bt.h>
51 #include <mach/audio.h>
52 #include <mach/smemc.h>
53
54 #include <asm/mach/arch.h>
55 #include <mach/tosa.h>
56
57 #include <asm/hardware/scoop.h>
58 #include <asm/mach/sharpsl_param.h>
59
60 #include "generic.h"
61 #include "devices.h"
62
63 static unsigned long tosa_pin_config[] = {
64         GPIO78_nCS_2, /* Scoop */
65         GPIO80_nCS_4, /* tg6393xb */
66         GPIO33_nCS_5, /* Scoop */
67
68         // GPIO76 CARD_VCC_ON1
69
70         GPIO19_GPIO, /* Reset out */
71         GPIO1_RST | WAKEUP_ON_EDGE_FALL,
72
73         GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
74         GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
75         GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
76         GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
77         GPIO20_GPIO, /* EAR_IN */
78         GPIO22_GPIO, /* On */
79
80         GPIO5_GPIO, /* USB_IN */
81         GPIO32_GPIO, /* Pen IRQ */
82
83         GPIO7_GPIO, /* Jacket Detect */
84         GPIO14_GPIO, /* BAT0_CRG */
85         GPIO12_GPIO, /* BAT1_CRG */
86         GPIO17_GPIO, /* BAT0_LOW */
87         GPIO84_GPIO, /* BAT1_LOW */
88         GPIO38_GPIO, /* BAT_LOCK */
89
90         GPIO11_3_6MHz,
91         GPIO15_GPIO, /* TC6393XB IRQ */
92         GPIO18_RDY,
93         GPIO27_GPIO, /* LCD Sync */
94
95         /* MMC */
96         GPIO6_MMC_CLK,
97         GPIO8_MMC_CS0,
98         GPIO9_GPIO, /* Detect */
99         GPIO10_GPIO, /* nSD_INT */
100
101         /* CF */
102         GPIO13_GPIO, /* CD_IRQ */
103         GPIO21_GPIO, /* Main Slot IRQ */
104         GPIO36_GPIO, /* Jacket Slot IRQ */
105         GPIO48_nPOE,
106         GPIO49_nPWE,
107         GPIO50_nPIOR,
108         GPIO51_nPIOW,
109         GPIO52_nPCE_1,
110         GPIO53_nPCE_2,
111         GPIO54_nPSKTSEL,
112         GPIO55_nPREG,
113         GPIO56_nPWAIT,
114         GPIO57_nIOIS16,
115
116         /* AC97 */
117         GPIO31_AC97_SYNC,
118         GPIO30_AC97_SDATA_OUT,
119         GPIO28_AC97_BITCLK,
120         GPIO29_AC97_SDATA_IN_0,
121         // GPIO79 nAUD_IRQ
122
123         /* FFUART */
124         GPIO34_FFUART_RXD,
125         GPIO35_FFUART_CTS,
126         GPIO37_FFUART_DSR,
127         GPIO39_FFUART_TXD,
128         GPIO40_FFUART_DTR,
129         GPIO41_FFUART_RTS,
130
131         /* BTUART */
132         GPIO42_BTUART_RXD,
133         GPIO43_BTUART_TXD,
134         GPIO44_BTUART_CTS,
135         GPIO45_BTUART_RTS,
136
137         /* Keybd */
138         GPIO58_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 0 */
139         GPIO59_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 1 */
140         GPIO60_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 2 */
141         GPIO61_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 3 */
142         GPIO62_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 4 */
143         GPIO63_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 5 */
144         GPIO64_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 6 */
145         GPIO65_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 7 */
146         GPIO66_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 8 */
147         GPIO67_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 9 */
148         GPIO68_GPIO | MFP_LPM_DRIVE_LOW,        /* Column 10 */
149         GPIO69_GPIO | MFP_LPM_DRIVE_LOW,        /* Row 0 */
150         GPIO70_GPIO | MFP_LPM_DRIVE_LOW,        /* Row 1 */
151         GPIO71_GPIO | MFP_LPM_DRIVE_LOW,        /* Row 2 */
152         GPIO72_GPIO | MFP_LPM_DRIVE_LOW,        /* Row 3 */
153         GPIO73_GPIO | MFP_LPM_DRIVE_LOW,        /* Row 4 */
154         GPIO74_GPIO | MFP_LPM_DRIVE_LOW,        /* Row 5 */
155         GPIO75_GPIO | MFP_LPM_DRIVE_LOW,        /* Row 6 */
156
157         /* SPI */
158         GPIO81_SSP2_CLK_OUT,
159         GPIO82_SSP2_FRM_OUT,
160         GPIO83_SSP2_TXD,
161
162         /* IrDA is managed in other way */
163         GPIO46_GPIO,
164         GPIO47_GPIO,
165 };
166
167 /*
168  * SCOOP Device
169  */
170 static struct resource tosa_scoop_resources[] = {
171         [0] = {
172                 .start  = TOSA_CF_PHYS,
173                 .end    = TOSA_CF_PHYS + 0xfff,
174                 .flags  = IORESOURCE_MEM,
175         },
176 };
177
178 static struct scoop_config tosa_scoop_setup = {
179         .io_dir         = TOSA_SCOOP_IO_DIR,
180         .gpio_base      = TOSA_SCOOP_GPIO_BASE,
181 };
182
183 static struct platform_device tosascoop_device = {
184         .name           = "sharp-scoop",
185         .id             = 0,
186         .dev            = {
187                 .platform_data  = &tosa_scoop_setup,
188         },
189         .num_resources  = ARRAY_SIZE(tosa_scoop_resources),
190         .resource       = tosa_scoop_resources,
191 };
192
193
194 /*
195  * SCOOP Device Jacket
196  */
197 static struct resource tosa_scoop_jc_resources[] = {
198         [0] = {
199                 .start          = TOSA_SCOOP_PHYS + 0x40,
200                 .end            = TOSA_SCOOP_PHYS + 0xfff,
201                 .flags          = IORESOURCE_MEM,
202         },
203 };
204
205 static struct scoop_config tosa_scoop_jc_setup = {
206         .io_dir         = TOSA_SCOOP_JC_IO_DIR,
207         .gpio_base      = TOSA_SCOOP_JC_GPIO_BASE,
208 };
209
210 static struct platform_device tosascoop_jc_device = {
211         .name           = "sharp-scoop",
212         .id             = 1,
213         .dev            = {
214                 .platform_data  = &tosa_scoop_jc_setup,
215                 .parent         = &tosascoop_device.dev,
216         },
217         .num_resources  = ARRAY_SIZE(tosa_scoop_jc_resources),
218         .resource       = tosa_scoop_jc_resources,
219 };
220
221 /*
222  * PCMCIA
223  */
224 static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
225 {
226         .dev        = &tosascoop_device.dev,
227         .irq        = TOSA_IRQ_GPIO_CF_IRQ,
228         .cd_irq     = TOSA_IRQ_GPIO_CF_CD,
229         .cd_irq_str = "PCMCIA0 CD",
230 },{
231         .dev        = &tosascoop_jc_device.dev,
232         .irq        = TOSA_IRQ_GPIO_JC_CF_IRQ,
233         .cd_irq     = -1,
234 },
235 };
236
237 static struct scoop_pcmcia_config tosa_pcmcia_config = {
238         .devs         = &tosa_pcmcia_scoop[0],
239         .num_devs     = 2,
240 };
241
242 /*
243  * USB Device Controller
244  */
245 static struct gpio_vbus_mach_info tosa_udc_info = {
246         .gpio_pullup            = TOSA_GPIO_USB_PULLUP,
247         .gpio_vbus              = TOSA_GPIO_USB_IN,
248         .gpio_vbus_inverted     = 1,
249 };
250
251 static struct platform_device tosa_gpio_vbus = {
252         .name   = "gpio-vbus",
253         .id     = -1,
254         .dev    = {
255                 .platform_data  = &tosa_udc_info,
256         },
257 };
258
259 /*
260  * MMC/SD Device
261  */
262 static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
263 {
264         int err;
265
266         err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
267         if (err) {
268                 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
269                 goto err_gpio_int;
270         }
271         err = gpio_direction_input(TOSA_GPIO_nSD_INT);
272         if (err)
273                 goto err_gpio_int_dir;
274
275         return 0;
276
277 err_gpio_int_dir:
278         gpio_free(TOSA_GPIO_nSD_INT);
279 err_gpio_int:
280         return err;
281 }
282
283 static void tosa_mci_exit(struct device *dev, void *data)
284 {
285         gpio_free(TOSA_GPIO_nSD_INT);
286 }
287
288 static struct pxamci_platform_data tosa_mci_platform_data = {
289         .detect_delay_ms        = 250,
290         .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
291         .init                   = tosa_mci_init,
292         .exit                   = tosa_mci_exit,
293         .gpio_card_detect       = TOSA_GPIO_nSD_DETECT,
294         .gpio_card_ro           = TOSA_GPIO_SD_WP,
295         .gpio_power             = TOSA_GPIO_PWR_ON,
296 };
297
298 /*
299  * Irda
300  */
301 static void tosa_irda_transceiver_mode(struct device *dev, int mode)
302 {
303         if (mode & IR_OFF) {
304                 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
305                 pxa2xx_transceiver_mode(dev, mode);
306                 gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
307         } else {
308                 pxa2xx_transceiver_mode(dev, mode);
309                 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
310         }
311 }
312
313 static int tosa_irda_startup(struct device *dev)
314 {
315         int ret;
316
317         ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
318         if (ret)
319                 goto err_tx;
320         ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
321         if (ret)
322                 goto err_tx_dir;
323
324         ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
325         if (ret)
326                 goto err_pwr;
327
328         ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
329         if (ret)
330                 goto err_pwr_dir;
331
332         tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
333
334         return 0;
335
336 err_pwr_dir:
337         gpio_free(TOSA_GPIO_IR_POWERDWN);
338 err_pwr:
339 err_tx_dir:
340         gpio_free(TOSA_GPIO_IRDA_TX);
341 err_tx:
342         return ret;
343 }
344
345 static void tosa_irda_shutdown(struct device *dev)
346 {
347         tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
348         gpio_free(TOSA_GPIO_IR_POWERDWN);
349         gpio_free(TOSA_GPIO_IRDA_TX);
350 }
351
352 static struct pxaficp_platform_data tosa_ficp_platform_data = {
353         .gpio_pwdown            = -1,
354         .transceiver_cap        = IR_SIRMODE | IR_OFF,
355         .transceiver_mode       = tosa_irda_transceiver_mode,
356         .startup                = tosa_irda_startup,
357         .shutdown               = tosa_irda_shutdown,
358 };
359
360 /*
361  * Tosa AC IN
362  */
363 static char *tosa_ac_supplied_to[] = {
364         "main-battery",
365         "backup-battery",
366         "jacket-battery",
367 };
368
369 static struct gpio_charger_platform_data tosa_power_data = {
370         .name                   = "charger",
371         .type                   = POWER_SUPPLY_TYPE_MAINS,
372         .gpio                   = TOSA_GPIO_AC_IN,
373         .gpio_active_low        = 1,
374         .supplied_to            = tosa_ac_supplied_to,
375         .num_supplicants        = ARRAY_SIZE(tosa_ac_supplied_to),
376 };
377
378 static struct resource tosa_power_resource[] = {
379         {
380                 .name           = "ac",
381                 .start          = PXA_GPIO_TO_IRQ(TOSA_GPIO_AC_IN),
382                 .end            = PXA_GPIO_TO_IRQ(TOSA_GPIO_AC_IN),
383                 .flags          = IORESOURCE_IRQ |
384                                   IORESOURCE_IRQ_HIGHEDGE |
385                                   IORESOURCE_IRQ_LOWEDGE,
386         },
387 };
388
389 static struct platform_device tosa_power_device = {
390         .name                   = "gpio-charger",
391         .id                     = -1,
392         .dev.platform_data      = &tosa_power_data,
393         .resource               = tosa_power_resource,
394         .num_resources          = ARRAY_SIZE(tosa_power_resource),
395 };
396
397 /*
398  * Tosa Keyboard
399  */
400 static const uint32_t tosakbd_keymap[] = {
401         KEY(0, 1, KEY_W),
402         KEY(0, 5, KEY_K),
403         KEY(0, 6, KEY_BACKSPACE),
404         KEY(0, 7, KEY_P),
405         KEY(1, 0, KEY_Q),
406         KEY(1, 1, KEY_E),
407         KEY(1, 2, KEY_T),
408         KEY(1, 3, KEY_Y),
409         KEY(1, 5, KEY_O),
410         KEY(1, 6, KEY_I),
411         KEY(1, 7, KEY_COMMA),
412         KEY(2, 0, KEY_A),
413         KEY(2, 1, KEY_D),
414         KEY(2, 2, KEY_G),
415         KEY(2, 3, KEY_U),
416         KEY(2, 5, KEY_L),
417         KEY(2, 6, KEY_ENTER),
418         KEY(2, 7, KEY_DOT),
419         KEY(3, 0, KEY_Z),
420         KEY(3, 1, KEY_C),
421         KEY(3, 2, KEY_V),
422         KEY(3, 3, KEY_J),
423         KEY(3, 4, TOSA_KEY_ADDRESSBOOK),
424         KEY(3, 5, TOSA_KEY_CANCEL),
425         KEY(3, 6, TOSA_KEY_CENTER),
426         KEY(3, 7, TOSA_KEY_OK),
427         KEY(3, 8, KEY_LEFTSHIFT),
428         KEY(4, 0, KEY_S),
429         KEY(4, 1, KEY_R),
430         KEY(4, 2, KEY_B),
431         KEY(4, 3, KEY_N),
432         KEY(4, 4, TOSA_KEY_CALENDAR),
433         KEY(4, 5, TOSA_KEY_HOMEPAGE),
434         KEY(4, 6, KEY_LEFTCTRL),
435         KEY(4, 7, TOSA_KEY_LIGHT),
436         KEY(4, 9, KEY_RIGHTSHIFT),
437         KEY(5, 0, KEY_TAB),
438         KEY(5, 1, KEY_SLASH),
439         KEY(5, 2, KEY_H),
440         KEY(5, 3, KEY_M),
441         KEY(5, 4, TOSA_KEY_MENU),
442         KEY(5, 6, KEY_UP),
443         KEY(5, 10, TOSA_KEY_FN),
444         KEY(6, 0, KEY_X),
445         KEY(6, 1, KEY_F),
446         KEY(6, 2, KEY_SPACE),
447         KEY(6, 3, KEY_APOSTROPHE),
448         KEY(6, 4, TOSA_KEY_MAIL),
449         KEY(6, 5, KEY_LEFT),
450         KEY(6, 6, KEY_DOWN),
451         KEY(6, 7, KEY_RIGHT),
452 };
453
454 static struct matrix_keymap_data tosakbd_keymap_data = {
455         .keymap         = tosakbd_keymap,
456         .keymap_size    = ARRAY_SIZE(tosakbd_keymap),
457 };
458
459 static const int tosakbd_col_gpios[] =
460                         { 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68 };
461 static const int tosakbd_row_gpios[] =
462                         { 69, 70, 71, 72, 73, 74, 75 };
463
464 static struct matrix_keypad_platform_data tosakbd_pdata = {
465         .keymap_data            = &tosakbd_keymap_data,
466         .row_gpios              = tosakbd_row_gpios,
467         .col_gpios              = tosakbd_col_gpios,
468         .num_row_gpios          = ARRAY_SIZE(tosakbd_row_gpios),
469         .num_col_gpios          = ARRAY_SIZE(tosakbd_col_gpios),
470         .col_scan_delay_us      = 10,
471         .debounce_ms            = 10,
472         .wakeup                 = 1,
473 };
474
475 static struct platform_device tosakbd_device = {
476         .name           = "matrix-keypad",
477         .id             = -1,
478         .dev            = {
479                 .platform_data = &tosakbd_pdata,
480         },
481 };
482
483 static struct gpio_keys_button tosa_gpio_keys[] = {
484         /*
485          * Two following keys are directly tied to "ON" button of tosa. Why?
486          * The first one can be used as a wakeup source, the second can't;
487          * also the first one is OR of ac_powered and on_button.
488          */
489         {
490                 .type   = EV_PWR,
491                 .code   = KEY_RESERVED,
492                 .gpio   = TOSA_GPIO_POWERON,
493                 .desc   = "Poweron",
494                 .wakeup = 1,
495                 .active_low = 1,
496         },
497         {
498                 .type   = EV_PWR,
499                 .code   = KEY_SUSPEND,
500                 .gpio   = TOSA_GPIO_ON_KEY,
501                 .desc   = "On key",
502                 /*
503                  * can't be used as wakeup
504                  * .wakeup      = 1,
505                  */
506                 .active_low = 1,
507         },
508         {
509                 .type   = EV_KEY,
510                 .code   = TOSA_KEY_RECORD,
511                 .gpio   = TOSA_GPIO_RECORD_BTN,
512                 .desc   = "Record Button",
513                 .wakeup = 1,
514                 .active_low = 1,
515         },
516         {
517                 .type   = EV_KEY,
518                 .code   = TOSA_KEY_SYNC,
519                 .gpio   = TOSA_GPIO_SYNC,
520                 .desc   = "Sync Button",
521                 .wakeup = 1,
522                 .active_low = 1,
523         },
524         {
525                 .type   = EV_SW,
526                 .code   = SW_HEADPHONE_INSERT,
527                 .gpio   = TOSA_GPIO_EAR_IN,
528                 .desc   = "HeadPhone insert",
529                 .active_low = 1,
530                 .debounce_interval = 300,
531         },
532 };
533
534 static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
535         .buttons        = tosa_gpio_keys,
536         .nbuttons       = ARRAY_SIZE(tosa_gpio_keys),
537 };
538
539 static struct platform_device tosa_gpio_keys_device = {
540         .name   = "gpio-keys",
541         .id     = -1,
542         .dev    = {
543                 .platform_data  = &tosa_gpio_keys_platform_data,
544         },
545 };
546
547 /*
548  * Tosa LEDs
549  */
550 static struct gpio_led tosa_gpio_leds[] = {
551         {
552                 .name                   = "tosa:amber:charge",
553                 .default_trigger        = "main-battery-charging",
554                 .gpio                   = TOSA_GPIO_CHRG_ERR_LED,
555         },
556         {
557                 .name                   = "tosa:green:mail",
558                 .default_trigger        = "nand-disk",
559                 .gpio                   = TOSA_GPIO_NOTE_LED,
560         },
561         {
562                 .name                   = "tosa:dual:wlan",
563                 .default_trigger        = "none",
564                 .gpio                   = TOSA_GPIO_WLAN_LED,
565         },
566         {
567                 .name                   = "tosa:blue:bluetooth",
568                 .default_trigger        = "tosa-bt",
569                 .gpio                   = TOSA_GPIO_BT_LED,
570         },
571 };
572
573 static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
574         .leds           = tosa_gpio_leds,
575         .num_leds       = ARRAY_SIZE(tosa_gpio_leds),
576 };
577
578 static struct platform_device tosaled_device = {
579         .name   = "leds-gpio",
580         .id     = -1,
581         .dev    = {
582                 .platform_data  = &tosa_gpio_leds_platform_data,
583         },
584 };
585
586 /*
587  * Toshiba Mobile IO Controller
588  */
589 static struct resource tc6393xb_resources[] = {
590         [0] = {
591                 .start  = TOSA_LCDC_PHYS,
592                 .end    = TOSA_LCDC_PHYS + 0x3ffffff,
593                 .flags  = IORESOURCE_MEM,
594         },
595
596         [1] = {
597                 .start  = TOSA_IRQ_GPIO_TC6393XB_INT,
598                 .end    = TOSA_IRQ_GPIO_TC6393XB_INT,
599                 .flags  = IORESOURCE_IRQ,
600         },
601 };
602
603
604 static int tosa_tc6393xb_enable(struct platform_device *dev)
605 {
606         int rc;
607
608         rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
609         if (rc)
610                 goto err_req_pclr;
611         rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
612         if (rc)
613                 goto err_req_suspend;
614         rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "tc6393xb l3v");
615         if (rc)
616                 goto err_req_l3v;
617         rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
618         if (rc)
619                 goto err_dir_l3v;
620         rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
621         if (rc)
622                 goto err_dir_suspend;
623         rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
624         if (rc)
625                 goto err_dir_pclr;
626
627         mdelay(1);
628
629         gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
630
631         mdelay(10);
632
633         gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
634         gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
635
636         return 0;
637 err_dir_pclr:
638 err_dir_suspend:
639 err_dir_l3v:
640         gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
641 err_req_l3v:
642         gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
643 err_req_suspend:
644         gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
645 err_req_pclr:
646         return rc;
647 }
648
649 static int tosa_tc6393xb_disable(struct platform_device *dev)
650 {
651         gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
652         gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
653         gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
654
655         return 0;
656 }
657
658 static int tosa_tc6393xb_resume(struct platform_device *dev)
659 {
660         gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
661         mdelay(10);
662         gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
663         mdelay(10);
664
665         return 0;
666 }
667
668 static int tosa_tc6393xb_suspend(struct platform_device *dev)
669 {
670         gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
671         gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
672         return 0;
673 }
674
675 static struct mtd_partition tosa_nand_partition[] = {
676         {
677                 .name   = "smf",
678                 .offset = 0,
679                 .size   = 7 * 1024 * 1024,
680         },
681         {
682                 .name   = "root",
683                 .offset = MTDPART_OFS_APPEND,
684                 .size   = 28 * 1024 * 1024,
685         },
686         {
687                 .name   = "home",
688                 .offset = MTDPART_OFS_APPEND,
689                 .size   = MTDPART_SIZ_FULL,
690         },
691 };
692
693 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
694
695 static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
696         .options        = 0,
697         .offs           = 4,
698         .len            = 2,
699         .pattern        = scan_ff_pattern
700 };
701
702 static struct tmio_nand_data tosa_tc6393xb_nand_config = {
703         .num_partitions = ARRAY_SIZE(tosa_nand_partition),
704         .partition      = tosa_nand_partition,
705         .badblock_pattern = &tosa_tc6393xb_nand_bbt,
706 };
707
708 static int tosa_tc6393xb_setup(struct platform_device *dev)
709 {
710         int rc;
711
712         rc = gpio_request(TOSA_GPIO_CARD_VCC_ON, "CARD_VCC_ON");
713         if (rc)
714                 goto err_req;
715
716         rc = gpio_direction_output(TOSA_GPIO_CARD_VCC_ON, 1);
717         if (rc)
718                 goto err_dir;
719
720         return rc;
721
722 err_dir:
723         gpio_free(TOSA_GPIO_CARD_VCC_ON);
724 err_req:
725         return rc;
726 }
727
728 static void tosa_tc6393xb_teardown(struct platform_device *dev)
729 {
730         gpio_free(TOSA_GPIO_CARD_VCC_ON);
731 }
732
733 #ifdef CONFIG_MFD_TC6393XB
734 static struct fb_videomode tosa_tc6393xb_lcd_mode[] = {
735         {
736                 .xres = 480,
737                 .yres = 640,
738                 .pixclock = 0x002cdf00,/* PLL divisor */
739                 .left_margin = 0x004c,
740                 .right_margin = 0x005b,
741                 .upper_margin = 0x0001,
742                 .lower_margin = 0x000d,
743                 .hsync_len = 0x0002,
744                 .vsync_len = 0x0001,
745                 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
746                 .vmode = FB_VMODE_NONINTERLACED,
747         },{
748                 .xres = 240,
749                 .yres = 320,
750                 .pixclock = 0x00e7f203,/* PLL divisor */
751                 .left_margin = 0x0024,
752                 .right_margin = 0x002f,
753                 .upper_margin = 0x0001,
754                 .lower_margin = 0x000d,
755                 .hsync_len = 0x0002,
756                 .vsync_len = 0x0001,
757                 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
758                 .vmode = FB_VMODE_NONINTERLACED,
759         }
760 };
761
762 static struct tmio_fb_data tosa_tc6393xb_fb_config = {
763         .lcd_set_power  = tc6393xb_lcd_set_power,
764         .lcd_mode       = tc6393xb_lcd_mode,
765         .num_modes      = ARRAY_SIZE(tosa_tc6393xb_lcd_mode),
766         .modes          = &tosa_tc6393xb_lcd_mode[0],
767         .height         = 82,
768         .width          = 60,
769 };
770 #endif
771
772 static struct tc6393xb_platform_data tosa_tc6393xb_data = {
773         .scr_pll2cr     = 0x0cc1,
774         .scr_gper       = 0x3300,
775
776         .irq_base       = IRQ_BOARD_START,
777         .gpio_base      = TOSA_TC6393XB_GPIO_BASE,
778         .setup          = tosa_tc6393xb_setup,
779         .teardown       = tosa_tc6393xb_teardown,
780
781         .enable         = tosa_tc6393xb_enable,
782         .disable        = tosa_tc6393xb_disable,
783         .suspend        = tosa_tc6393xb_suspend,
784         .resume         = tosa_tc6393xb_resume,
785
786         .nand_data      = &tosa_tc6393xb_nand_config,
787 #ifdef CONFIG_MFD_TC6393XB
788         .fb_data        = &tosa_tc6393xb_fb_config,
789 #endif
790
791         .resume_restore = 1,
792 };
793
794
795 static struct platform_device tc6393xb_device = {
796         .name   = "tc6393xb",
797         .id     = -1,
798         .dev    = {
799                 .platform_data  = &tosa_tc6393xb_data,
800         },
801         .num_resources  = ARRAY_SIZE(tc6393xb_resources),
802         .resource       = tc6393xb_resources,
803 };
804
805 static struct tosa_bt_data tosa_bt_data = {
806         .gpio_pwr       = TOSA_GPIO_BT_PWR_EN,
807         .gpio_reset     = TOSA_GPIO_BT_RESET,
808 };
809
810 static struct platform_device tosa_bt_device = {
811         .name   = "tosa-bt",
812         .id     = -1,
813         .dev.platform_data = &tosa_bt_data,
814 };
815
816 static struct pxa2xx_spi_master pxa_ssp_master_info = {
817         .num_chipselect = 1,
818 };
819
820 static struct spi_board_info spi_board_info[] __initdata = {
821         {
822                 .modalias       = "tosa-lcd",
823                 // .platform_data
824                 .max_speed_hz   = 28750,
825                 .bus_num        = 2,
826                 .chip_select    = 0,
827                 .mode           = SPI_MODE_0,
828         },
829 };
830
831 static struct mtd_partition sharpsl_rom_parts[] = {
832         {
833                 .name   ="Boot PROM Filesystem",
834                 .offset = 0x00160000,
835                 .size   = MTDPART_SIZ_FULL,
836         },
837 };
838
839 static struct physmap_flash_data sharpsl_rom_data = {
840         .width          = 2,
841         .nr_parts       = ARRAY_SIZE(sharpsl_rom_parts),
842         .parts          = sharpsl_rom_parts,
843 };
844
845 static struct resource sharpsl_rom_resources[] = {
846         {
847                 .start  = 0x00000000,
848                 .end    = 0x007fffff,
849                 .flags  = IORESOURCE_MEM,
850         },
851 };
852
853 static struct platform_device sharpsl_rom_device = {
854         .name   = "physmap-flash",
855         .id     = -1,
856         .resource = sharpsl_rom_resources,
857         .num_resources = ARRAY_SIZE(sharpsl_rom_resources),
858         .dev.platform_data = &sharpsl_rom_data,
859 };
860
861 static struct platform_device wm9712_device = {
862         .name   = "wm9712-codec",
863         .id     = -1,
864 };
865
866 static struct platform_device tosa_audio_device = {
867         .name   = "tosa-audio",
868         .id     = -1,
869 };
870
871 static struct platform_device *devices[] __initdata = {
872         &tosascoop_device,
873         &tosascoop_jc_device,
874         &tc6393xb_device,
875         &tosa_power_device,
876         &tosakbd_device,
877         &tosa_gpio_keys_device,
878         &tosaled_device,
879         &tosa_bt_device,
880         &sharpsl_rom_device,
881         &wm9712_device,
882         &tosa_gpio_vbus,
883         &tosa_audio_device,
884 };
885
886 static void tosa_poweroff(void)
887 {
888         pxa_restart(REBOOT_GPIO, NULL);
889 }
890
891 static void tosa_restart(enum reboot_mode mode, const char *cmd)
892 {
893         uint32_t msc0 = __raw_readl(MSC0);
894
895         /* Bootloader magic for a reboot */
896         if((msc0 & 0xffff0000) == 0x7ff00000)
897                 __raw_writel((msc0 & 0xffff) | 0x7ee00000, MSC0);
898
899         tosa_poweroff();
900 }
901
902 static void __init tosa_init(void)
903 {
904         pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
905
906         pxa_set_ffuart_info(NULL);
907         pxa_set_btuart_info(NULL);
908         pxa_set_stuart_info(NULL);
909
910         gpio_set_wake(MFP_PIN_GPIO1, 1);
911         /* We can't pass to gpio-keys since it will drop the Reset altfunc */
912
913         init_gpio_reset(TOSA_GPIO_ON_RESET, 0, 0);
914
915         pm_power_off = tosa_poweroff;
916
917         PCFR |= PCFR_OPDE;
918
919         /* enable batt_fault */
920         PMCR = 0x01;
921
922         pxa_set_mci_info(&tosa_mci_platform_data);
923         pxa_set_ficp_info(&tosa_ficp_platform_data);
924         pxa_set_i2c_info(NULL);
925         pxa_set_ac97_info(NULL);
926         platform_scoop_config = &tosa_pcmcia_config;
927
928         pxa2xx_set_spi_info(2, &pxa_ssp_master_info);
929         spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
930
931         clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL);
932
933         platform_add_devices(devices, ARRAY_SIZE(devices));
934 }
935
936 static void __init fixup_tosa(struct tag *tags, char **cmdline)
937 {
938         sharpsl_save_param();
939         memblock_add(0xa0000000, SZ_64M);
940 }
941
942 MACHINE_START(TOSA, "SHARP Tosa")
943         .fixup          = fixup_tosa,
944         .map_io         = pxa25x_map_io,
945         .nr_irqs        = TOSA_NR_IRQS,
946         .init_irq       = pxa25x_init_irq,
947         .handle_irq       = pxa25x_handle_irq,
948         .init_machine   = tosa_init,
949         .init_time      = pxa_timer_init,
950         .restart        = tosa_restart,
951 MACHINE_END