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