Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Support for Sharp SL-Cxx00 Series of PDAs
0004  * Models: SL-C3000 (Spitz), SL-C1000 (Akita) and SL-C3100 (Borzoi)
0005  *
0006  * Copyright (c) 2005 Richard Purdie
0007  *
0008  * Based on Sharp's 2.4 kernel patches/lubbock.c
0009  */
0010 
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>   /* symbol_get ; symbol_put */
0013 #include <linux/platform_device.h>
0014 #include <linux/delay.h>
0015 #include <linux/gpio_keys.h>
0016 #include <linux/gpio.h>
0017 #include <linux/gpio/machine.h>
0018 #include <linux/leds.h>
0019 #include <linux/i2c.h>
0020 #include <linux/platform_data/i2c-pxa.h>
0021 #include <linux/platform_data/pca953x.h>
0022 #include <linux/spi/spi.h>
0023 #include <linux/spi/ads7846.h>
0024 #include <linux/spi/corgi_lcd.h>
0025 #include <linux/spi/pxa2xx_spi.h>
0026 #include <linux/mtd/sharpsl.h>
0027 #include <linux/mtd/physmap.h>
0028 #include <linux/input/matrix_keypad.h>
0029 #include <linux/regulator/machine.h>
0030 #include <linux/io.h>
0031 #include <linux/reboot.h>
0032 #include <linux/memblock.h>
0033 
0034 #include <asm/setup.h>
0035 #include <asm/mach-types.h>
0036 #include <asm/mach/arch.h>
0037 #include <asm/mach/sharpsl_param.h>
0038 #include <asm/hardware/scoop.h>
0039 
0040 #include "pxa27x.h"
0041 #include "pxa27x-udc.h"
0042 #include "reset.h"
0043 #include <linux/platform_data/irda-pxaficp.h>
0044 #include <linux/platform_data/mmc-pxamci.h>
0045 #include <linux/platform_data/usb-ohci-pxa27x.h>
0046 #include <linux/platform_data/video-pxafb.h>
0047 #include "spitz.h"
0048 #include "sharpsl_pm.h"
0049 #include "smemc.h"
0050 
0051 #include "generic.h"
0052 #include "devices.h"
0053 
0054 /******************************************************************************
0055  * Pin configuration
0056  ******************************************************************************/
0057 static unsigned long spitz_pin_config[] __initdata = {
0058     /* Chip Selects */
0059     GPIO78_nCS_2,   /* SCOOP #2 */
0060     GPIO79_nCS_3,   /* NAND */
0061     GPIO80_nCS_4,   /* SCOOP #1 */
0062 
0063     /* LCD - 16bpp Active TFT */
0064     GPIOxx_LCD_TFT_16BPP,
0065 
0066     /* PC Card */
0067     GPIO48_nPOE,
0068     GPIO49_nPWE,
0069     GPIO50_nPIOR,
0070     GPIO51_nPIOW,
0071     GPIO85_nPCE_1,
0072     GPIO54_nPCE_2,
0073     GPIO55_nPREG,
0074     GPIO56_nPWAIT,
0075     GPIO57_nIOIS16,
0076     GPIO104_PSKTSEL,
0077 
0078     /* I2S */
0079     GPIO28_I2S_BITCLK_OUT,
0080     GPIO29_I2S_SDATA_IN,
0081     GPIO30_I2S_SDATA_OUT,
0082     GPIO31_I2S_SYNC,
0083 
0084     /* MMC */
0085     GPIO32_MMC_CLK,
0086     GPIO112_MMC_CMD,
0087     GPIO92_MMC_DAT_0,
0088     GPIO109_MMC_DAT_1,
0089     GPIO110_MMC_DAT_2,
0090     GPIO111_MMC_DAT_3,
0091 
0092     /* GPIOs */
0093     GPIO9_GPIO, /* SPITZ_GPIO_nSD_DETECT */
0094     GPIO16_GPIO,    /* SPITZ_GPIO_SYNC */
0095     GPIO81_GPIO,    /* SPITZ_GPIO_nSD_WP */
0096     GPIO41_GPIO,    /* SPITZ_GPIO_USB_CONNECT */
0097     GPIO37_GPIO,    /* SPITZ_GPIO_USB_HOST */
0098     GPIO35_GPIO,    /* SPITZ_GPIO_USB_DEVICE */
0099     GPIO22_GPIO,    /* SPITZ_GPIO_HSYNC */
0100     GPIO94_GPIO,    /* SPITZ_GPIO_CF_CD */
0101     GPIO105_GPIO,   /* SPITZ_GPIO_CF_IRQ */
0102     GPIO106_GPIO,   /* SPITZ_GPIO_CF2_IRQ */
0103 
0104     /* GPIO matrix keypad */
0105     GPIO88_GPIO,    /* column 0 */
0106     GPIO23_GPIO,    /* column 1 */
0107     GPIO24_GPIO,    /* column 2 */
0108     GPIO25_GPIO,    /* column 3 */
0109     GPIO26_GPIO,    /* column 4 */
0110     GPIO27_GPIO,    /* column 5 */
0111     GPIO52_GPIO,    /* column 6 */
0112     GPIO103_GPIO,   /* column 7 */
0113     GPIO107_GPIO,   /* column 8 */
0114     GPIO108_GPIO,   /* column 9 */
0115     GPIO114_GPIO,   /* column 10 */
0116     GPIO12_GPIO,    /* row 0 */
0117     GPIO17_GPIO,    /* row 1 */
0118     GPIO91_GPIO,    /* row 2 */
0119     GPIO34_GPIO,    /* row 3 */
0120     GPIO36_GPIO,    /* row 4 */
0121     GPIO38_GPIO,    /* row 5 */
0122     GPIO39_GPIO,    /* row 6 */
0123 
0124     /* I2C */
0125     GPIO117_I2C_SCL,
0126     GPIO118_I2C_SDA,
0127 
0128     GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,   /* SPITZ_GPIO_KEY_INT */
0129     GPIO1_GPIO | WAKEUP_ON_EDGE_FALL,   /* SPITZ_GPIO_RESET */
0130 };
0131 
0132 
0133 /******************************************************************************
0134  * Scoop GPIO expander
0135  ******************************************************************************/
0136 #if defined(CONFIG_SHARP_SCOOP) || defined(CONFIG_SHARP_SCOOP_MODULE)
0137 /* SCOOP Device #1 */
0138 static struct resource spitz_scoop_1_resources[] = {
0139     [0] = {
0140         .start      = 0x10800000,
0141         .end        = 0x10800fff,
0142         .flags      = IORESOURCE_MEM,
0143     },
0144 };
0145 
0146 static struct scoop_config spitz_scoop_1_setup = {
0147     .io_dir     = SPITZ_SCP_IO_DIR,
0148     .io_out     = SPITZ_SCP_IO_OUT,
0149     .suspend_clr    = SPITZ_SCP_SUS_CLR,
0150     .suspend_set    = SPITZ_SCP_SUS_SET,
0151     .gpio_base  = SPITZ_SCP_GPIO_BASE,
0152 };
0153 
0154 struct platform_device spitz_scoop_1_device = {
0155     .name       = "sharp-scoop",
0156     .id     = 0,
0157     .dev        = {
0158         .platform_data  = &spitz_scoop_1_setup,
0159     },
0160     .num_resources  = ARRAY_SIZE(spitz_scoop_1_resources),
0161     .resource   = spitz_scoop_1_resources,
0162 };
0163 
0164 /* SCOOP Device #2 */
0165 static struct resource spitz_scoop_2_resources[] = {
0166     [0] = {
0167         .start      = 0x08800040,
0168         .end        = 0x08800fff,
0169         .flags      = IORESOURCE_MEM,
0170     },
0171 };
0172 
0173 static struct scoop_config spitz_scoop_2_setup = {
0174     .io_dir     = SPITZ_SCP2_IO_DIR,
0175     .io_out     = SPITZ_SCP2_IO_OUT,
0176     .suspend_clr    = SPITZ_SCP2_SUS_CLR,
0177     .suspend_set    = SPITZ_SCP2_SUS_SET,
0178     .gpio_base  = SPITZ_SCP2_GPIO_BASE,
0179 };
0180 
0181 struct platform_device spitz_scoop_2_device = {
0182     .name       = "sharp-scoop",
0183     .id     = 1,
0184     .dev        = {
0185         .platform_data  = &spitz_scoop_2_setup,
0186     },
0187     .num_resources  = ARRAY_SIZE(spitz_scoop_2_resources),
0188     .resource   = spitz_scoop_2_resources,
0189 };
0190 
0191 static void __init spitz_scoop_init(void)
0192 {
0193     platform_device_register(&spitz_scoop_1_device);
0194 
0195     /* Akita doesn't have the second SCOOP chip */
0196     if (!machine_is_akita())
0197         platform_device_register(&spitz_scoop_2_device);
0198 }
0199 
0200 /* Power control is shared with between one of the CF slots and SD */
0201 static void __maybe_unused spitz_card_pwr_ctrl(uint8_t enable, uint8_t new_cpr)
0202 {
0203     unsigned short cpr;
0204     unsigned long flags;
0205 
0206     if (new_cpr & 0x7) {
0207         gpio_set_value(SPITZ_GPIO_CF_POWER, 1);
0208         mdelay(5);
0209     }
0210 
0211     local_irq_save(flags);
0212 
0213     cpr = read_scoop_reg(&spitz_scoop_1_device.dev, SCOOP_CPR);
0214 
0215     if (enable & new_cpr)
0216         cpr |= new_cpr;
0217     else
0218         cpr &= ~enable;
0219 
0220     write_scoop_reg(&spitz_scoop_1_device.dev, SCOOP_CPR, cpr);
0221 
0222     local_irq_restore(flags);
0223 
0224     if (!(cpr & 0x7)) {
0225         mdelay(1);
0226         gpio_set_value(SPITZ_GPIO_CF_POWER, 0);
0227     }
0228 }
0229 
0230 #else
0231 static inline void spitz_scoop_init(void) {}
0232 static inline void spitz_card_pwr_ctrl(uint8_t enable, uint8_t new_cpr) {}
0233 #endif
0234 
0235 /******************************************************************************
0236  * PCMCIA
0237  ******************************************************************************/
0238 #if defined(CONFIG_PCMCIA_PXA2XX) || defined(CONFIG_PCMCIA_PXA2XX_MODULE)
0239 static void spitz_pcmcia_pwr(struct device *scoop, uint16_t cpr, int nr)
0240 {
0241     /* Only need to override behaviour for slot 0 */
0242     if (nr == 0)
0243         spitz_card_pwr_ctrl(
0244             cpr & (SCOOP_CPR_CF_3V | SCOOP_CPR_CF_XV), cpr);
0245     else
0246         write_scoop_reg(scoop, SCOOP_CPR, cpr);
0247 }
0248 
0249 static struct scoop_pcmcia_dev spitz_pcmcia_scoop[] = {
0250     {
0251         .dev        = &spitz_scoop_1_device.dev,
0252         .irq        = SPITZ_IRQ_GPIO_CF_IRQ,
0253         .cd_irq     = SPITZ_IRQ_GPIO_CF_CD,
0254         .cd_irq_str = "PCMCIA0 CD",
0255     }, {
0256         .dev        = &spitz_scoop_2_device.dev,
0257         .irq        = SPITZ_IRQ_GPIO_CF2_IRQ,
0258         .cd_irq     = -1,
0259     },
0260 };
0261 
0262 static struct scoop_pcmcia_config spitz_pcmcia_config = {
0263     .devs       = &spitz_pcmcia_scoop[0],
0264     .num_devs   = 2,
0265     .power_ctrl = spitz_pcmcia_pwr,
0266 };
0267 
0268 static void __init spitz_pcmcia_init(void)
0269 {
0270     /* Akita has only one PCMCIA slot used */
0271     if (machine_is_akita())
0272         spitz_pcmcia_config.num_devs = 1;
0273 
0274     platform_scoop_config = &spitz_pcmcia_config;
0275 }
0276 #else
0277 static inline void spitz_pcmcia_init(void) {}
0278 #endif
0279 
0280 /******************************************************************************
0281  * GPIO keyboard
0282  ******************************************************************************/
0283 #if defined(CONFIG_KEYBOARD_MATRIX) || defined(CONFIG_KEYBOARD_MATRIX_MODULE)
0284 
0285 #define SPITZ_KEY_CALENDAR  KEY_F1
0286 #define SPITZ_KEY_ADDRESS   KEY_F2
0287 #define SPITZ_KEY_FN        KEY_F3
0288 #define SPITZ_KEY_CANCEL    KEY_F4
0289 #define SPITZ_KEY_EXOK      KEY_F5
0290 #define SPITZ_KEY_EXCANCEL  KEY_F6
0291 #define SPITZ_KEY_EXJOGDOWN KEY_F7
0292 #define SPITZ_KEY_EXJOGUP   KEY_F8
0293 #define SPITZ_KEY_JAP1      KEY_LEFTALT
0294 #define SPITZ_KEY_JAP2      KEY_RIGHTCTRL
0295 #define SPITZ_KEY_SYNC      KEY_F9
0296 #define SPITZ_KEY_MAIL      KEY_F10
0297 #define SPITZ_KEY_OK        KEY_F11
0298 #define SPITZ_KEY_MENU      KEY_F12
0299 
0300 static const uint32_t spitz_keymap[] = {
0301     KEY(0, 0, KEY_LEFTCTRL),
0302     KEY(0, 1, KEY_1),
0303     KEY(0, 2, KEY_3),
0304     KEY(0, 3, KEY_5),
0305     KEY(0, 4, KEY_6),
0306     KEY(0, 5, KEY_7),
0307     KEY(0, 6, KEY_9),
0308     KEY(0, 7, KEY_0),
0309     KEY(0, 8, KEY_BACKSPACE),
0310     KEY(0, 9, SPITZ_KEY_EXOK),  /* EXOK */
0311     KEY(0, 10, SPITZ_KEY_EXCANCEL), /* EXCANCEL */
0312     KEY(1, 1, KEY_2),
0313     KEY(1, 2, KEY_4),
0314     KEY(1, 3, KEY_R),
0315     KEY(1, 4, KEY_Y),
0316     KEY(1, 5, KEY_8),
0317     KEY(1, 6, KEY_I),
0318     KEY(1, 7, KEY_O),
0319     KEY(1, 8, KEY_P),
0320     KEY(1, 9, SPITZ_KEY_EXJOGDOWN), /* EXJOGDOWN */
0321     KEY(1, 10, SPITZ_KEY_EXJOGUP),  /* EXJOGUP */
0322     KEY(2, 0, KEY_TAB),
0323     KEY(2, 1, KEY_Q),
0324     KEY(2, 2, KEY_E),
0325     KEY(2, 3, KEY_T),
0326     KEY(2, 4, KEY_G),
0327     KEY(2, 5, KEY_U),
0328     KEY(2, 6, KEY_J),
0329     KEY(2, 7, KEY_K),
0330     KEY(3, 0, SPITZ_KEY_ADDRESS),   /* ADDRESS */
0331     KEY(3, 1, KEY_W),
0332     KEY(3, 2, KEY_S),
0333     KEY(3, 3, KEY_F),
0334     KEY(3, 4, KEY_V),
0335     KEY(3, 5, KEY_H),
0336     KEY(3, 6, KEY_M),
0337     KEY(3, 7, KEY_L),
0338     KEY(3, 9, KEY_RIGHTSHIFT),
0339     KEY(4, 0, SPITZ_KEY_CALENDAR),  /* CALENDAR */
0340     KEY(4, 1, KEY_A),
0341     KEY(4, 2, KEY_D),
0342     KEY(4, 3, KEY_C),
0343     KEY(4, 4, KEY_B),
0344     KEY(4, 5, KEY_N),
0345     KEY(4, 6, KEY_DOT),
0346     KEY(4, 8, KEY_ENTER),
0347     KEY(4, 9, KEY_LEFTSHIFT),
0348     KEY(5, 0, SPITZ_KEY_MAIL),  /* MAIL */
0349     KEY(5, 1, KEY_Z),
0350     KEY(5, 2, KEY_X),
0351     KEY(5, 3, KEY_MINUS),
0352     KEY(5, 4, KEY_SPACE),
0353     KEY(5, 5, KEY_COMMA),
0354     KEY(5, 7, KEY_UP),
0355     KEY(5, 10, SPITZ_KEY_FN),   /* FN */
0356     KEY(6, 0, KEY_SYSRQ),
0357     KEY(6, 1, SPITZ_KEY_JAP1),  /* JAP1 */
0358     KEY(6, 2, SPITZ_KEY_JAP2),  /* JAP2 */
0359     KEY(6, 3, SPITZ_KEY_CANCEL),    /* CANCEL */
0360     KEY(6, 4, SPITZ_KEY_OK),    /* OK */
0361     KEY(6, 5, SPITZ_KEY_MENU),  /* MENU */
0362     KEY(6, 6, KEY_LEFT),
0363     KEY(6, 7, KEY_DOWN),
0364     KEY(6, 8, KEY_RIGHT),
0365 };
0366 
0367 static const struct matrix_keymap_data spitz_keymap_data = {
0368     .keymap     = spitz_keymap,
0369     .keymap_size    = ARRAY_SIZE(spitz_keymap),
0370 };
0371 
0372 static const uint32_t spitz_row_gpios[] =
0373         { 12, 17, 91, 34, 36, 38, 39 };
0374 static const uint32_t spitz_col_gpios[] =
0375         { 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114 };
0376 
0377 static struct matrix_keypad_platform_data spitz_mkp_pdata = {
0378     .keymap_data        = &spitz_keymap_data,
0379     .row_gpios      = spitz_row_gpios,
0380     .col_gpios      = spitz_col_gpios,
0381     .num_row_gpios      = ARRAY_SIZE(spitz_row_gpios),
0382     .num_col_gpios      = ARRAY_SIZE(spitz_col_gpios),
0383     .col_scan_delay_us  = 10,
0384     .debounce_ms        = 10,
0385     .wakeup         = 1,
0386 };
0387 
0388 static struct platform_device spitz_mkp_device = {
0389     .name       = "matrix-keypad",
0390     .id     = -1,
0391     .dev        = {
0392         .platform_data  = &spitz_mkp_pdata,
0393     },
0394 };
0395 
0396 static void __init spitz_mkp_init(void)
0397 {
0398     platform_device_register(&spitz_mkp_device);
0399 }
0400 #else
0401 static inline void spitz_mkp_init(void) {}
0402 #endif
0403 
0404 /******************************************************************************
0405  * GPIO keys
0406  ******************************************************************************/
0407 #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
0408 static struct gpio_keys_button spitz_gpio_keys[] = {
0409     {
0410         .type   = EV_PWR,
0411         .code   = KEY_SUSPEND,
0412         .gpio   = SPITZ_GPIO_ON_KEY,
0413         .desc   = "On Off",
0414         .wakeup = 1,
0415     },
0416     /* Two buttons detecting the lid state */
0417     {
0418         .type   = EV_SW,
0419         .code   = 0,
0420         .gpio   = SPITZ_GPIO_SWA,
0421         .desc   = "Display Down",
0422     },
0423     {
0424         .type   = EV_SW,
0425         .code   = 1,
0426         .gpio   = SPITZ_GPIO_SWB,
0427         .desc   = "Lid Closed",
0428     },
0429 };
0430 
0431 static struct gpio_keys_platform_data spitz_gpio_keys_platform_data = {
0432     .buttons    = spitz_gpio_keys,
0433     .nbuttons   = ARRAY_SIZE(spitz_gpio_keys),
0434 };
0435 
0436 static struct platform_device spitz_gpio_keys_device = {
0437     .name   = "gpio-keys",
0438     .id = -1,
0439     .dev    = {
0440         .platform_data  = &spitz_gpio_keys_platform_data,
0441     },
0442 };
0443 
0444 static void __init spitz_keys_init(void)
0445 {
0446     platform_device_register(&spitz_gpio_keys_device);
0447 }
0448 #else
0449 static inline void spitz_keys_init(void) {}
0450 #endif
0451 
0452 /******************************************************************************
0453  * LEDs
0454  ******************************************************************************/
0455 #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
0456 static struct gpio_led spitz_gpio_leds[] = {
0457     {
0458         .name           = "spitz:amber:charge",
0459         .default_trigger    = "sharpsl-charge",
0460         .gpio           = SPITZ_GPIO_LED_ORANGE,
0461     },
0462     {
0463         .name           = "spitz:green:hddactivity",
0464         .default_trigger    = "disk-activity",
0465         .gpio           = SPITZ_GPIO_LED_GREEN,
0466     },
0467 };
0468 
0469 static struct gpio_led_platform_data spitz_gpio_leds_info = {
0470     .leds       = spitz_gpio_leds,
0471     .num_leds   = ARRAY_SIZE(spitz_gpio_leds),
0472 };
0473 
0474 static struct platform_device spitz_led_device = {
0475     .name       = "leds-gpio",
0476     .id     = -1,
0477     .dev        = {
0478         .platform_data  = &spitz_gpio_leds_info,
0479     },
0480 };
0481 
0482 static void __init spitz_leds_init(void)
0483 {
0484     platform_device_register(&spitz_led_device);
0485 }
0486 #else
0487 static inline void spitz_leds_init(void) {}
0488 #endif
0489 
0490 /******************************************************************************
0491  * SSP Devices
0492  ******************************************************************************/
0493 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
0494 static void spitz_ads7846_wait_for_hsync(void)
0495 {
0496     while (gpio_get_value(SPITZ_GPIO_HSYNC))
0497         cpu_relax();
0498 
0499     while (!gpio_get_value(SPITZ_GPIO_HSYNC))
0500         cpu_relax();
0501 }
0502 
0503 static struct ads7846_platform_data spitz_ads7846_info = {
0504     .model          = 7846,
0505     .vref_delay_usecs   = 100,
0506     .x_plate_ohms       = 419,
0507     .y_plate_ohms       = 486,
0508     .pressure_max       = 1024,
0509     .gpio_pendown       = SPITZ_GPIO_TP_INT,
0510     .wait_for_sync      = spitz_ads7846_wait_for_hsync,
0511 };
0512 
0513 static void spitz_bl_kick_battery(void)
0514 {
0515     void (*kick_batt)(void);
0516 
0517     kick_batt = symbol_get(sharpsl_battery_kick);
0518     if (kick_batt) {
0519         kick_batt();
0520         symbol_put(sharpsl_battery_kick);
0521     }
0522 }
0523 
0524 static struct gpiod_lookup_table spitz_lcdcon_gpio_table = {
0525     .dev_id = "spi2.1",
0526     .table = {
0527         GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_CONT,
0528                 "BL_CONT", GPIO_ACTIVE_LOW),
0529         GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_BACKLIGHT_ON,
0530                 "BL_ON", GPIO_ACTIVE_HIGH),
0531         { },
0532     },
0533 };
0534 
0535 static struct gpiod_lookup_table akita_lcdcon_gpio_table = {
0536     .dev_id = "spi2.1",
0537     .table = {
0538         GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_CONT,
0539                 "BL_CONT", GPIO_ACTIVE_LOW),
0540         GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_BACKLIGHT_ON,
0541                 "BL_ON", GPIO_ACTIVE_HIGH),
0542         { },
0543     },
0544 };
0545 
0546 static struct corgi_lcd_platform_data spitz_lcdcon_info = {
0547     .init_mode      = CORGI_LCD_MODE_VGA,
0548     .max_intensity      = 0x2f,
0549     .default_intensity  = 0x1f,
0550     .limit_mask     = 0x0b,
0551     .kick_battery       = spitz_bl_kick_battery,
0552 };
0553 
0554 static struct spi_board_info spitz_spi_devices[] = {
0555     {
0556         .modalias       = "ads7846",
0557         .max_speed_hz       = 1200000,
0558         .bus_num        = 2,
0559         .chip_select        = 0,
0560         .platform_data      = &spitz_ads7846_info,
0561         .irq            = PXA_GPIO_TO_IRQ(SPITZ_GPIO_TP_INT),
0562     }, {
0563         .modalias       = "corgi-lcd",
0564         .max_speed_hz       = 50000,
0565         .bus_num        = 2,
0566         .chip_select        = 1,
0567         .platform_data      = &spitz_lcdcon_info,
0568     }, {
0569         .modalias       = "max1111",
0570         .max_speed_hz       = 450000,
0571         .bus_num        = 2,
0572         .chip_select        = 2,
0573     },
0574 };
0575 
0576 static struct pxa2xx_spi_controller spitz_spi_info = {
0577     .num_chipselect = 3,
0578 };
0579 
0580 static struct gpiod_lookup_table spitz_spi_gpio_table = {
0581     .dev_id = "spi2",
0582     .table = {
0583         GPIO_LOOKUP_IDX("gpio-pxa", SPITZ_GPIO_ADS7846_CS, "cs", 0, GPIO_ACTIVE_LOW),
0584         GPIO_LOOKUP_IDX("gpio-pxa", SPITZ_GPIO_LCDCON_CS, "cs", 1, GPIO_ACTIVE_LOW),
0585         GPIO_LOOKUP_IDX("gpio-pxa", SPITZ_GPIO_MAX1111_CS, "cs", 2, GPIO_ACTIVE_LOW),
0586         { },
0587     },
0588 };
0589 
0590 static void __init spitz_spi_init(void)
0591 {
0592     if (machine_is_akita())
0593         gpiod_add_lookup_table(&akita_lcdcon_gpio_table);
0594     else
0595         gpiod_add_lookup_table(&spitz_lcdcon_gpio_table);
0596 
0597     gpiod_add_lookup_table(&spitz_spi_gpio_table);
0598     pxa2xx_set_spi_info(2, &spitz_spi_info);
0599     spi_register_board_info(ARRAY_AND_SIZE(spitz_spi_devices));
0600 }
0601 #else
0602 static inline void spitz_spi_init(void) {}
0603 #endif
0604 
0605 /******************************************************************************
0606  * SD/MMC card controller
0607  ******************************************************************************/
0608 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
0609 /*
0610  * NOTE: The card detect interrupt isn't debounced so we delay it by 250ms to
0611  * give the card a chance to fully insert/eject.
0612  */
0613 static int spitz_mci_setpower(struct device *dev, unsigned int vdd)
0614 {
0615     struct pxamci_platform_data* p_d = dev->platform_data;
0616 
0617     if ((1 << vdd) & p_d->ocr_mask)
0618         spitz_card_pwr_ctrl(SCOOP_CPR_SD_3V, SCOOP_CPR_SD_3V);
0619     else
0620         spitz_card_pwr_ctrl(SCOOP_CPR_SD_3V, 0x0);
0621 
0622     return 0;
0623 }
0624 
0625 static struct pxamci_platform_data spitz_mci_platform_data = {
0626     .detect_delay_ms    = 250,
0627     .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
0628     .setpower       = spitz_mci_setpower,
0629 };
0630 
0631 static struct gpiod_lookup_table spitz_mci_gpio_table = {
0632     .dev_id = "pxa2xx-mci.0",
0633     .table = {
0634         GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_nSD_DETECT,
0635                 "cd", GPIO_ACTIVE_LOW),
0636         GPIO_LOOKUP("gpio-pxa", SPITZ_GPIO_nSD_WP,
0637                 "wp", GPIO_ACTIVE_LOW),
0638         { },
0639     },
0640 };
0641 
0642 static void __init spitz_mmc_init(void)
0643 {
0644     gpiod_add_lookup_table(&spitz_mci_gpio_table);
0645     pxa_set_mci_info(&spitz_mci_platform_data);
0646 }
0647 #else
0648 static inline void spitz_mmc_init(void) {}
0649 #endif
0650 
0651 /******************************************************************************
0652  * USB Host
0653  ******************************************************************************/
0654 #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
0655 static int spitz_ohci_init(struct device *dev)
0656 {
0657     int err;
0658 
0659     err = gpio_request(SPITZ_GPIO_USB_HOST, "USB_HOST");
0660     if (err)
0661         return err;
0662 
0663     /* Only Port 2 is connected, setup USB Port 2 Output Control Register */
0664     UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
0665 
0666     return gpio_direction_output(SPITZ_GPIO_USB_HOST, 1);
0667 }
0668 
0669 static void spitz_ohci_exit(struct device *dev)
0670 {
0671     gpio_free(SPITZ_GPIO_USB_HOST);
0672 }
0673 
0674 static struct pxaohci_platform_data spitz_ohci_platform_data = {
0675     .port_mode  = PMM_NPS_MODE,
0676     .init       = spitz_ohci_init,
0677     .exit       = spitz_ohci_exit,
0678     .flags      = ENABLE_PORT_ALL | NO_OC_PROTECTION,
0679     .power_budget   = 150,
0680 };
0681 
0682 static void __init spitz_uhc_init(void)
0683 {
0684     pxa_set_ohci_info(&spitz_ohci_platform_data);
0685 }
0686 #else
0687 static inline void spitz_uhc_init(void) {}
0688 #endif
0689 
0690 /******************************************************************************
0691  * IrDA
0692  ******************************************************************************/
0693 #if defined(CONFIG_PXA_FICP) || defined(CONFIG_PXA_FICP_MODULE)
0694 static struct pxaficp_platform_data spitz_ficp_platform_data = {
0695     .transceiver_cap    = IR_SIRMODE | IR_OFF,
0696 };
0697 
0698 static void __init spitz_irda_init(void)
0699 {
0700     if (machine_is_akita())
0701         spitz_ficp_platform_data.gpio_pwdown = AKITA_GPIO_IR_ON;
0702     else
0703         spitz_ficp_platform_data.gpio_pwdown = SPITZ_GPIO_IR_ON;
0704 
0705     pxa_set_ficp_info(&spitz_ficp_platform_data);
0706 }
0707 #else
0708 static inline void spitz_irda_init(void) {}
0709 #endif
0710 
0711 /******************************************************************************
0712  * Framebuffer
0713  ******************************************************************************/
0714 #if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
0715 static struct pxafb_mode_info spitz_pxafb_modes[] = {
0716     {
0717         .pixclock       = 19231,
0718         .xres           = 480,
0719         .yres           = 640,
0720         .bpp            = 16,
0721         .hsync_len      = 40,
0722         .left_margin    = 46,
0723         .right_margin   = 125,
0724         .vsync_len      = 3,
0725         .upper_margin   = 1,
0726         .lower_margin   = 0,
0727         .sync           = 0,
0728     }, {
0729         .pixclock       = 134617,
0730         .xres           = 240,
0731         .yres           = 320,
0732         .bpp            = 16,
0733         .hsync_len      = 20,
0734         .left_margin    = 20,
0735         .right_margin   = 46,
0736         .vsync_len      = 2,
0737         .upper_margin   = 1,
0738         .lower_margin   = 0,
0739         .sync           = 0,
0740     },
0741 };
0742 
0743 static struct pxafb_mach_info spitz_pxafb_info = {
0744     .modes          = spitz_pxafb_modes,
0745     .num_modes      = ARRAY_SIZE(spitz_pxafb_modes),
0746     .fixed_modes    = 1,
0747     .lcd_conn   = LCD_COLOR_TFT_16BPP | LCD_ALTERNATE_MAPPING,
0748 };
0749 
0750 static void __init spitz_lcd_init(void)
0751 {
0752     pxa_set_fb_info(NULL, &spitz_pxafb_info);
0753 }
0754 #else
0755 static inline void spitz_lcd_init(void) {}
0756 #endif
0757 
0758 /******************************************************************************
0759  * NAND Flash
0760  ******************************************************************************/
0761 #if defined(CONFIG_MTD_NAND_SHARPSL) || defined(CONFIG_MTD_NAND_SHARPSL_MODULE)
0762 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
0763 
0764 static struct nand_bbt_descr spitz_nand_bbt = {
0765     .options    = 0,
0766     .offs       = 4,
0767     .len        = 2,
0768     .pattern    = scan_ff_pattern
0769 };
0770 
0771 static int akita_ooblayout_ecc(struct mtd_info *mtd, int section,
0772                    struct mtd_oob_region *oobregion)
0773 {
0774     if (section > 12)
0775         return -ERANGE;
0776 
0777     switch (section % 3) {
0778     case 0:
0779         oobregion->offset = 5;
0780         oobregion->length = 1;
0781         break;
0782 
0783     case 1:
0784         oobregion->offset = 1;
0785         oobregion->length = 3;
0786         break;
0787 
0788     case 2:
0789         oobregion->offset = 6;
0790         oobregion->length = 2;
0791         break;
0792     }
0793 
0794     oobregion->offset += (section / 3) * 0x10;
0795 
0796     return 0;
0797 }
0798 
0799 static int akita_ooblayout_free(struct mtd_info *mtd, int section,
0800                 struct mtd_oob_region *oobregion)
0801 {
0802     if (section)
0803         return -ERANGE;
0804 
0805     oobregion->offset = 8;
0806     oobregion->length = 9;
0807 
0808     return 0;
0809 }
0810 
0811 static const struct mtd_ooblayout_ops akita_ooblayout_ops = {
0812     .ecc = akita_ooblayout_ecc,
0813     .free = akita_ooblayout_free,
0814 };
0815 
0816 static const char * const probes[] = {
0817     "cmdlinepart",
0818     "ofpart",
0819     "sharpslpart",
0820     NULL,
0821 };
0822 
0823 static struct sharpsl_nand_platform_data spitz_nand_pdata = {
0824     .badblock_pattern   = &spitz_nand_bbt,
0825     .part_parsers       = probes,
0826 };
0827 
0828 static struct resource spitz_nand_resources[] = {
0829     {
0830         .start  = PXA_CS3_PHYS,
0831         .end    = PXA_CS3_PHYS + SZ_4K - 1,
0832         .flags  = IORESOURCE_MEM,
0833     },
0834 };
0835 
0836 static struct platform_device spitz_nand_device = {
0837     .name       = "sharpsl-nand",
0838     .id     = -1,
0839     .resource   = spitz_nand_resources,
0840     .num_resources  = ARRAY_SIZE(spitz_nand_resources),
0841     .dev        = {
0842         .platform_data  = &spitz_nand_pdata,
0843     }
0844 };
0845 
0846 static void __init spitz_nand_init(void)
0847 {
0848     if (machine_is_akita() || machine_is_borzoi()) {
0849         spitz_nand_bbt.len = 1;
0850         spitz_nand_pdata.ecc_layout = &akita_ooblayout_ops;
0851     }
0852 
0853     platform_device_register(&spitz_nand_device);
0854 }
0855 #else
0856 static inline void spitz_nand_init(void) {}
0857 #endif
0858 
0859 /******************************************************************************
0860  * NOR Flash
0861  ******************************************************************************/
0862 #if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
0863 static struct mtd_partition spitz_rom_parts[] = {
0864     {
0865         .name   ="Boot PROM Filesystem",
0866         .offset = 0x00140000,
0867         .size   = MTDPART_SIZ_FULL,
0868     },
0869 };
0870 
0871 static struct physmap_flash_data spitz_rom_data = {
0872     .width      = 2,
0873     .nr_parts   = ARRAY_SIZE(spitz_rom_parts),
0874     .parts      = spitz_rom_parts,
0875 };
0876 
0877 static struct resource spitz_rom_resources[] = {
0878     {
0879         .start  = PXA_CS0_PHYS,
0880         .end    = PXA_CS0_PHYS + SZ_8M - 1,
0881         .flags  = IORESOURCE_MEM,
0882     },
0883 };
0884 
0885 static struct platform_device spitz_rom_device = {
0886     .name       = "physmap-flash",
0887     .id     = -1,
0888     .resource   = spitz_rom_resources,
0889     .num_resources  = ARRAY_SIZE(spitz_rom_resources),
0890     .dev        = {
0891         .platform_data  = &spitz_rom_data,
0892     },
0893 };
0894 
0895 static void __init spitz_nor_init(void)
0896 {
0897     platform_device_register(&spitz_rom_device);
0898 }
0899 #else
0900 static inline void spitz_nor_init(void) {}
0901 #endif
0902 
0903 /******************************************************************************
0904  * I2C devices
0905  ******************************************************************************/
0906 #if defined(CONFIG_I2C_PXA) || defined(CONFIG_I2C_PXA_MODULE)
0907 static struct pca953x_platform_data akita_pca953x_pdata = {
0908     .gpio_base      = AKITA_IOEXP_GPIO_BASE,
0909 };
0910 
0911 static struct i2c_board_info spitz_i2c_devs[] = {
0912     {
0913         .type       = "wm8750",
0914         .addr       = 0x1b,
0915     }, {
0916         .type       = "max7310",
0917         .addr       = 0x18,
0918         .platform_data  = &akita_pca953x_pdata,
0919     },
0920 };
0921 
0922 static struct regulator_consumer_supply isl6271a_consumers[] = {
0923     REGULATOR_SUPPLY("vcc_core", NULL),
0924 };
0925 
0926 static struct regulator_init_data isl6271a_info[] = {
0927     {
0928         .constraints = {
0929             .name       = "vcc_core range",
0930             .min_uV     = 850000,
0931             .max_uV     = 1600000,
0932             .always_on  = 1,
0933             .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
0934         },
0935     .consumer_supplies  = isl6271a_consumers,
0936     .num_consumer_supplies  = ARRAY_SIZE(isl6271a_consumers),
0937     }
0938 };
0939 
0940 static struct i2c_board_info spitz_pi2c_devs[] = {
0941     {
0942         .type       = "isl6271a",
0943         .addr       = 0x0c,
0944         .platform_data  = &isl6271a_info,
0945     },
0946 };
0947 
0948 static void __init spitz_i2c_init(void)
0949 {
0950     int size = ARRAY_SIZE(spitz_i2c_devs);
0951 
0952     /* Only Akita has the max7310 chip */
0953     if (!machine_is_akita())
0954         size--;
0955 
0956     pxa_set_i2c_info(NULL);
0957     pxa27x_set_i2c_power_info(NULL);
0958     i2c_register_board_info(0, spitz_i2c_devs, size);
0959     i2c_register_board_info(1, ARRAY_AND_SIZE(spitz_pi2c_devs));
0960 }
0961 #else
0962 static inline void spitz_i2c_init(void) {}
0963 #endif
0964 
0965 static struct gpiod_lookup_table spitz_audio_gpio_table = {
0966     .dev_id = "spitz-audio",
0967     .table = {
0968         GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_L - SPITZ_SCP_GPIO_BASE,
0969                 "mute-l", GPIO_ACTIVE_HIGH),
0970         GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_R - SPITZ_SCP_GPIO_BASE,
0971                 "mute-r", GPIO_ACTIVE_HIGH),
0972         GPIO_LOOKUP("sharp-scoop.1", SPITZ_GPIO_MIC_BIAS - SPITZ_SCP2_GPIO_BASE,
0973                 "mic", GPIO_ACTIVE_HIGH),
0974         { },
0975     },
0976 };
0977 
0978 static struct gpiod_lookup_table akita_audio_gpio_table = {
0979     .dev_id = "spitz-audio",
0980     .table = {
0981         GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_L - SPITZ_SCP_GPIO_BASE,
0982                 "mute-l", GPIO_ACTIVE_HIGH),
0983         GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_R - SPITZ_SCP_GPIO_BASE,
0984                 "mute-r", GPIO_ACTIVE_HIGH),
0985         GPIO_LOOKUP("i2c-max7310", AKITA_GPIO_MIC_BIAS - AKITA_IOEXP_GPIO_BASE,
0986                 "mic", GPIO_ACTIVE_HIGH),
0987         { },
0988     },
0989 };
0990 
0991 /******************************************************************************
0992  * Audio devices
0993  ******************************************************************************/
0994 static inline void spitz_audio_init(void)
0995 {
0996     if (machine_is_akita())
0997         gpiod_add_lookup_table(&akita_audio_gpio_table);
0998     else
0999         gpiod_add_lookup_table(&spitz_audio_gpio_table);
1000 
1001     platform_device_register_simple("spitz-audio", -1, NULL, 0);
1002 }
1003 
1004 /******************************************************************************
1005  * Machine init
1006  ******************************************************************************/
1007 static void spitz_poweroff(void)
1008 {
1009     pxa_restart(REBOOT_GPIO, NULL);
1010 }
1011 
1012 static void spitz_restart(enum reboot_mode mode, const char *cmd)
1013 {
1014     uint32_t msc0 = __raw_readl(MSC0);
1015     /* Bootloader magic for a reboot */
1016     if ((msc0 & 0xffff0000) == 0x7ff00000)
1017         __raw_writel((msc0 & 0xffff) | 0x7ee00000, MSC0);
1018 
1019     spitz_poweroff();
1020 }
1021 
1022 static void __init spitz_init(void)
1023 {
1024     init_gpio_reset(SPITZ_GPIO_ON_RESET, 1, 0);
1025     pm_power_off = spitz_poweroff;
1026 
1027     PMCR = 0x00;
1028 
1029     /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
1030     PCFR |= PCFR_OPDE;
1031 
1032     pxa2xx_mfp_config(ARRAY_AND_SIZE(spitz_pin_config));
1033 
1034     pxa_set_ffuart_info(NULL);
1035     pxa_set_btuart_info(NULL);
1036     pxa_set_stuart_info(NULL);
1037 
1038     spitz_spi_init();
1039     spitz_scoop_init();
1040     spitz_mkp_init();
1041     spitz_keys_init();
1042     spitz_leds_init();
1043     spitz_mmc_init();
1044     spitz_pcmcia_init();
1045     spitz_irda_init();
1046     spitz_uhc_init();
1047     spitz_lcd_init();
1048     spitz_nor_init();
1049     spitz_nand_init();
1050     spitz_i2c_init();
1051     spitz_audio_init();
1052 
1053     regulator_has_full_constraints();
1054 }
1055 
1056 static void __init spitz_fixup(struct tag *tags, char **cmdline)
1057 {
1058     sharpsl_save_param();
1059     memblock_add(0xa0000000, SZ_64M);
1060 }
1061 
1062 #ifdef CONFIG_MACH_SPITZ
1063 MACHINE_START(SPITZ, "SHARP Spitz")
1064     .fixup      = spitz_fixup,
1065     .map_io     = pxa27x_map_io,
1066     .nr_irqs    = PXA_NR_IRQS,
1067     .init_irq   = pxa27x_init_irq,
1068     .handle_irq = pxa27x_handle_irq,
1069     .init_machine   = spitz_init,
1070     .init_time  = pxa_timer_init,
1071     .restart    = spitz_restart,
1072 MACHINE_END
1073 #endif
1074 
1075 #ifdef CONFIG_MACH_BORZOI
1076 MACHINE_START(BORZOI, "SHARP Borzoi")
1077     .fixup      = spitz_fixup,
1078     .map_io     = pxa27x_map_io,
1079     .nr_irqs    = PXA_NR_IRQS,
1080     .init_irq   = pxa27x_init_irq,
1081     .handle_irq = pxa27x_handle_irq,
1082     .init_machine   = spitz_init,
1083     .init_time  = pxa_timer_init,
1084     .restart    = spitz_restart,
1085 MACHINE_END
1086 #endif
1087 
1088 #ifdef CONFIG_MACH_AKITA
1089 MACHINE_START(AKITA, "SHARP Akita")
1090     .fixup      = spitz_fixup,
1091     .map_io     = pxa27x_map_io,
1092     .nr_irqs    = PXA_NR_IRQS,
1093     .init_irq   = pxa27x_init_irq,
1094     .handle_irq = pxa27x_handle_irq,
1095     .init_machine   = spitz_init,
1096     .init_time  = pxa_timer_init,
1097     .restart    = spitz_restart,
1098 MACHINE_END
1099 #endif