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