Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * linux/arch/arm/mach-omap1/board-ams-delta.c
0004  *
0005  * Modified from board-generic.c
0006  *
0007  * Board specific inits for the Amstrad E3 (codename Delta) videophone
0008  *
0009  * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
0010  */
0011 #include <linux/gpio/driver.h>
0012 #include <linux/gpio/machine.h>
0013 #include <linux/gpio/consumer.h>
0014 #include <linux/gpio.h>
0015 #include <linux/kernel.h>
0016 #include <linux/init.h>
0017 #include <linux/input.h>
0018 #include <linux/interrupt.h>
0019 #include <linux/leds.h>
0020 #include <linux/mtd/nand-gpio.h>
0021 #include <linux/mtd/partitions.h>
0022 #include <linux/platform_device.h>
0023 #include <linux/regulator/consumer.h>
0024 #include <linux/regulator/fixed.h>
0025 #include <linux/regulator/machine.h>
0026 #include <linux/serial_8250.h>
0027 #include <linux/export.h>
0028 #include <linux/omapfb.h>
0029 #include <linux/io.h>
0030 #include <linux/platform_data/gpio-omap.h>
0031 #include <linux/soc/ti/omap1-mux.h>
0032 
0033 #include <asm/serial.h>
0034 #include <asm/mach-types.h>
0035 #include <asm/mach/arch.h>
0036 #include <asm/mach/map.h>
0037 
0038 #include <linux/platform_data/keypad-omap.h>
0039 
0040 #include "hardware.h"
0041 #include "usb.h"
0042 #include "ams-delta-fiq.h"
0043 #include "board-ams-delta.h"
0044 #include "iomap.h"
0045 #include "common.h"
0046 
0047 static const unsigned int ams_delta_keymap[] = {
0048     KEY(0, 0, KEY_F1),      /* Advert    */
0049 
0050     KEY(0, 3, KEY_COFFEE),      /* Games     */
0051     KEY(0, 2, KEY_QUESTION),    /* Directory */
0052     KEY(2, 3, KEY_CONNECT),     /* Internet  */
0053     KEY(1, 2, KEY_SHOP),        /* Services  */
0054     KEY(1, 1, KEY_PHONE),       /* VoiceMail */
0055 
0056     KEY(0, 1, KEY_DELETE),      /* Delete    */
0057     KEY(2, 2, KEY_PLAY),        /* Play      */
0058     KEY(1, 0, KEY_PAGEUP),      /* Up        */
0059     KEY(1, 3, KEY_PAGEDOWN),    /* Down      */
0060     KEY(2, 0, KEY_EMAIL),       /* ReadEmail */
0061     KEY(2, 1, KEY_STOP),        /* Stop      */
0062 
0063     /* Numeric keypad portion */
0064     KEY(0, 7, KEY_KP1),
0065     KEY(0, 6, KEY_KP2),
0066     KEY(0, 5, KEY_KP3),
0067     KEY(1, 7, KEY_KP4),
0068     KEY(1, 6, KEY_KP5),
0069     KEY(1, 5, KEY_KP6),
0070     KEY(2, 7, KEY_KP7),
0071     KEY(2, 6, KEY_KP8),
0072     KEY(2, 5, KEY_KP9),
0073     KEY(3, 6, KEY_KP0),
0074     KEY(3, 7, KEY_KPASTERISK),
0075     KEY(3, 5, KEY_KPDOT),       /* # key     */
0076     KEY(7, 2, KEY_NUMLOCK),     /* Mute      */
0077     KEY(7, 1, KEY_KPMINUS),     /* Recall    */
0078     KEY(6, 1, KEY_KPPLUS),      /* Redial    */
0079     KEY(7, 6, KEY_KPSLASH),     /* Handsfree */
0080     KEY(6, 0, KEY_ENTER),       /* Video     */
0081 
0082     KEY(7, 4, KEY_CAMERA),      /* Photo     */
0083 
0084     KEY(0, 4, KEY_F2),      /* Home      */
0085     KEY(1, 4, KEY_F3),      /* Office    */
0086     KEY(2, 4, KEY_F4),      /* Mobile    */
0087     KEY(7, 7, KEY_F5),      /* SMS       */
0088     KEY(7, 5, KEY_F6),      /* Email     */
0089 
0090     /* QWERTY portion of keypad */
0091     KEY(3, 4, KEY_Q),
0092     KEY(3, 3, KEY_W),
0093     KEY(3, 2, KEY_E),
0094     KEY(3, 1, KEY_R),
0095     KEY(3, 0, KEY_T),
0096     KEY(4, 7, KEY_Y),
0097     KEY(4, 6, KEY_U),
0098     KEY(4, 5, KEY_I),
0099     KEY(4, 4, KEY_O),
0100     KEY(4, 3, KEY_P),
0101 
0102     KEY(4, 2, KEY_A),
0103     KEY(4, 1, KEY_S),
0104     KEY(4, 0, KEY_D),
0105     KEY(5, 7, KEY_F),
0106     KEY(5, 6, KEY_G),
0107     KEY(5, 5, KEY_H),
0108     KEY(5, 4, KEY_J),
0109     KEY(5, 3, KEY_K),
0110     KEY(5, 2, KEY_L),
0111 
0112     KEY(5, 1, KEY_Z),
0113     KEY(5, 0, KEY_X),
0114     KEY(6, 7, KEY_C),
0115     KEY(6, 6, KEY_V),
0116     KEY(6, 5, KEY_B),
0117     KEY(6, 4, KEY_N),
0118     KEY(6, 3, KEY_M),
0119     KEY(6, 2, KEY_SPACE),
0120 
0121     KEY(7, 0, KEY_LEFTSHIFT),   /* Vol up    */
0122     KEY(7, 3, KEY_LEFTCTRL),    /* Vol down  */
0123 };
0124 
0125 #define LATCH1_PHYS 0x01000000
0126 #define LATCH1_VIRT 0xEA000000
0127 #define MODEM_PHYS  0x04000000
0128 #define MODEM_VIRT  0xEB000000
0129 #define LATCH2_PHYS 0x08000000
0130 #define LATCH2_VIRT 0xEC000000
0131 
0132 static struct map_desc ams_delta_io_desc[] __initdata = {
0133     /* AMS_DELTA_LATCH1 */
0134     {
0135         .virtual    = LATCH1_VIRT,
0136         .pfn        = __phys_to_pfn(LATCH1_PHYS),
0137         .length     = 0x01000000,
0138         .type       = MT_DEVICE
0139     },
0140     /* AMS_DELTA_LATCH2 */
0141     {
0142         .virtual    = LATCH2_VIRT,
0143         .pfn        = __phys_to_pfn(LATCH2_PHYS),
0144         .length     = 0x01000000,
0145         .type       = MT_DEVICE
0146     },
0147     /* AMS_DELTA_MODEM */
0148     {
0149         .virtual    = MODEM_VIRT,
0150         .pfn        = __phys_to_pfn(MODEM_PHYS),
0151         .length     = 0x01000000,
0152         .type       = MT_DEVICE
0153     }
0154 };
0155 
0156 static const struct omap_lcd_config ams_delta_lcd_config __initconst = {
0157     .ctrl_name  = "internal",
0158 };
0159 
0160 static struct omap_usb_config ams_delta_usb_config __initdata = {
0161     .register_host  = 1,
0162     .hmc_mode   = 16,
0163     .pins[0]    = 2,
0164 };
0165 
0166 #define LATCH1_NGPIO        8
0167 
0168 static struct resource latch1_resources[] = {
0169     [0] = {
0170         .name   = "dat",
0171         .start  = LATCH1_PHYS,
0172         .end    = LATCH1_PHYS + (LATCH1_NGPIO - 1) / 8,
0173         .flags  = IORESOURCE_MEM,
0174     },
0175 };
0176 
0177 #define LATCH1_LABEL    "latch1"
0178 
0179 static struct bgpio_pdata latch1_pdata = {
0180     .label  = LATCH1_LABEL,
0181     .base   = -1,
0182     .ngpio  = LATCH1_NGPIO,
0183 };
0184 
0185 static struct platform_device latch1_gpio_device = {
0186     .name       = "basic-mmio-gpio",
0187     .id     = 0,
0188     .resource   = latch1_resources,
0189     .num_resources  = ARRAY_SIZE(latch1_resources),
0190     .dev        = {
0191         .platform_data  = &latch1_pdata,
0192     },
0193 };
0194 
0195 #define LATCH1_PIN_LED_CAMERA       0
0196 #define LATCH1_PIN_LED_ADVERT       1
0197 #define LATCH1_PIN_LED_MAIL     2
0198 #define LATCH1_PIN_LED_HANDSFREE    3
0199 #define LATCH1_PIN_LED_VOICEMAIL    4
0200 #define LATCH1_PIN_LED_VOICE        5
0201 #define LATCH1_PIN_DOCKIT1      6
0202 #define LATCH1_PIN_DOCKIT2      7
0203 
0204 #define LATCH2_NGPIO            16
0205 
0206 static struct resource latch2_resources[] = {
0207     [0] = {
0208         .name   = "dat",
0209         .start  = LATCH2_PHYS,
0210         .end    = LATCH2_PHYS + (LATCH2_NGPIO - 1) / 8,
0211         .flags  = IORESOURCE_MEM,
0212     },
0213 };
0214 
0215 #define LATCH2_LABEL    "latch2"
0216 
0217 static struct bgpio_pdata latch2_pdata = {
0218     .label  = LATCH2_LABEL,
0219     .base   = -1,
0220     .ngpio  = LATCH2_NGPIO,
0221 };
0222 
0223 static struct platform_device latch2_gpio_device = {
0224     .name       = "basic-mmio-gpio",
0225     .id     = 1,
0226     .resource   = latch2_resources,
0227     .num_resources  = ARRAY_SIZE(latch2_resources),
0228     .dev        = {
0229         .platform_data  = &latch2_pdata,
0230     },
0231 };
0232 
0233 #define LATCH2_PIN_LCD_VBLEN        0
0234 #define LATCH2_PIN_LCD_NDISP        1
0235 #define LATCH2_PIN_NAND_NCE     2
0236 #define LATCH2_PIN_NAND_NRE     3
0237 #define LATCH2_PIN_NAND_NWP     4
0238 #define LATCH2_PIN_NAND_NWE     5
0239 #define LATCH2_PIN_NAND_ALE     6
0240 #define LATCH2_PIN_NAND_CLE     7
0241 #define LATCH2_PIN_KEYBRD_PWR       8
0242 #define LATCH2_PIN_KEYBRD_DATAOUT   9
0243 #define LATCH2_PIN_SCARD_RSTIN      10
0244 #define LATCH2_PIN_SCARD_CMDVCC     11
0245 #define LATCH2_PIN_MODEM_NRESET     12
0246 #define LATCH2_PIN_MODEM_CODEC      13
0247 #define LATCH2_PIN_HANDSFREE_MUTE   14
0248 #define LATCH2_PIN_HANDSET_MUTE     15
0249 
0250 static struct regulator_consumer_supply modem_nreset_consumers[] = {
0251     REGULATOR_SUPPLY("RESET#", "serial8250.1"),
0252     REGULATOR_SUPPLY("POR", "cx20442-codec"),
0253 };
0254 
0255 static struct regulator_init_data modem_nreset_data = {
0256     .constraints        = {
0257         .valid_ops_mask     = REGULATOR_CHANGE_STATUS,
0258         .boot_on        = 1,
0259     },
0260     .num_consumer_supplies  = ARRAY_SIZE(modem_nreset_consumers),
0261     .consumer_supplies  = modem_nreset_consumers,
0262 };
0263 
0264 static struct fixed_voltage_config modem_nreset_config = {
0265     .supply_name        = "modem_nreset",
0266     .microvolts     = 3300000,
0267     .startup_delay      = 25000,
0268     .enabled_at_boot    = 1,
0269     .init_data      = &modem_nreset_data,
0270 };
0271 
0272 static struct platform_device modem_nreset_device = {
0273     .name   = "reg-fixed-voltage",
0274     .id = -1,
0275     .dev    = {
0276         .platform_data  = &modem_nreset_config,
0277     },
0278 };
0279 
0280 static struct gpiod_lookup_table ams_delta_nreset_gpiod_table = {
0281     .dev_id = "reg-fixed-voltage",
0282     .table = {
0283         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_MODEM_NRESET,
0284                 NULL, GPIO_ACTIVE_HIGH),
0285         { },
0286     },
0287 };
0288 
0289 struct modem_private_data {
0290     struct regulator *regulator;
0291 };
0292 
0293 static struct modem_private_data modem_priv;
0294 
0295 /*
0296  * Define partitions for flash device
0297  */
0298 
0299 static struct mtd_partition partition_info[] = {
0300     { .name     = "Kernel",
0301       .offset   = 0,
0302       .size     = 3 * SZ_1M + SZ_512K },
0303     { .name     = "u-boot",
0304       .offset   = 3 * SZ_1M + SZ_512K,
0305       .size     = SZ_256K },
0306     { .name     = "u-boot params",
0307       .offset   = 3 * SZ_1M + SZ_512K + SZ_256K,
0308       .size     = SZ_256K },
0309     { .name     = "Amstrad LDR",
0310       .offset   = 4 * SZ_1M,
0311       .size     = SZ_256K },
0312     { .name     = "File system",
0313       .offset   = 4 * SZ_1M + 1 * SZ_256K,
0314       .size     = 27 * SZ_1M },
0315     { .name     = "PBL reserved",
0316       .offset   = 32 * SZ_1M - 3 * SZ_256K,
0317       .size     =  3 * SZ_256K },
0318 };
0319 
0320 static struct gpio_nand_platdata nand_platdata = {
0321     .parts      = partition_info,
0322     .num_parts  = ARRAY_SIZE(partition_info),
0323 };
0324 
0325 static struct platform_device ams_delta_nand_device = {
0326     .name   = "ams-delta-nand",
0327     .id = -1,
0328     .dev    = {
0329         .platform_data = &nand_platdata,
0330     },
0331 };
0332 
0333 #define OMAP_GPIO_LABEL     "gpio-0-15"
0334 #define OMAP_MPUIO_LABEL    "mpuio"
0335 
0336 static struct gpiod_lookup_table ams_delta_nand_gpio_table = {
0337     .table = {
0338         GPIO_LOOKUP(OMAP_GPIO_LABEL, AMS_DELTA_GPIO_PIN_NAND_RB, "rdy",
0339                 0),
0340         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NCE, "nce",
0341                 GPIO_ACTIVE_LOW),
0342         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NRE, "nre",
0343                 GPIO_ACTIVE_LOW),
0344         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NWP, "nwp",
0345                 GPIO_ACTIVE_LOW),
0346         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_NWE, "nwe",
0347                 GPIO_ACTIVE_LOW),
0348         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_ALE, "ale", 0),
0349         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_NAND_CLE, "cle", 0),
0350         GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 0, "data", 0, 0),
0351         GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 1, "data", 1, 0),
0352         GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 2, "data", 2, 0),
0353         GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 3, "data", 3, 0),
0354         GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 4, "data", 4, 0),
0355         GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 5, "data", 5, 0),
0356         GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 6, "data", 6, 0),
0357         GPIO_LOOKUP_IDX(OMAP_MPUIO_LABEL, 7, "data", 7, 0),
0358         { },
0359     },
0360 };
0361 
0362 static struct resource ams_delta_kp_resources[] = {
0363     [0] = {
0364         .start  = INT_KEYBOARD,
0365         .end    = INT_KEYBOARD,
0366         .flags  = IORESOURCE_IRQ,
0367     },
0368 };
0369 
0370 static const struct matrix_keymap_data ams_delta_keymap_data = {
0371     .keymap     = ams_delta_keymap,
0372     .keymap_size    = ARRAY_SIZE(ams_delta_keymap),
0373 };
0374 
0375 static struct omap_kp_platform_data ams_delta_kp_data = {
0376     .rows       = 8,
0377     .cols       = 8,
0378     .keymap_data    = &ams_delta_keymap_data,
0379     .delay      = 9,
0380 };
0381 
0382 static struct platform_device ams_delta_kp_device = {
0383     .name       = "omap-keypad",
0384     .id     = -1,
0385     .dev        = {
0386         .platform_data = &ams_delta_kp_data,
0387     },
0388     .num_resources  = ARRAY_SIZE(ams_delta_kp_resources),
0389     .resource   = ams_delta_kp_resources,
0390 };
0391 
0392 static struct platform_device ams_delta_lcd_device = {
0393     .name   = "lcd_ams_delta",
0394     .id = -1,
0395 };
0396 
0397 static struct gpiod_lookup_table ams_delta_lcd_gpio_table = {
0398     .table = {
0399         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_LCD_VBLEN, "vblen", 0),
0400         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_LCD_NDISP, "ndisp", 0),
0401         { },
0402     },
0403 };
0404 
0405 static struct gpio_led gpio_leds[] __initdata = {
0406     [LATCH1_PIN_LED_CAMERA] = {
0407         .name        = "camera",
0408         .default_state   = LEDS_GPIO_DEFSTATE_OFF,
0409     },
0410     [LATCH1_PIN_LED_ADVERT] = {
0411         .name        = "advert",
0412         .default_state   = LEDS_GPIO_DEFSTATE_OFF,
0413     },
0414     [LATCH1_PIN_LED_MAIL] = {
0415         .name        = "email",
0416         .default_state   = LEDS_GPIO_DEFSTATE_OFF,
0417     },
0418     [LATCH1_PIN_LED_HANDSFREE] = {
0419         .name        = "handsfree",
0420         .default_state   = LEDS_GPIO_DEFSTATE_OFF,
0421     },
0422     [LATCH1_PIN_LED_VOICEMAIL] = {
0423         .name        = "voicemail",
0424         .default_state   = LEDS_GPIO_DEFSTATE_OFF,
0425     },
0426     [LATCH1_PIN_LED_VOICE] = {
0427         .name        = "voice",
0428         .default_state   = LEDS_GPIO_DEFSTATE_OFF,
0429     },
0430 };
0431 
0432 static const struct gpio_led_platform_data leds_pdata __initconst = {
0433     .leds       = gpio_leds,
0434     .num_leds   = ARRAY_SIZE(gpio_leds),
0435 };
0436 
0437 static struct gpiod_lookup_table leds_gpio_table = {
0438     .table = {
0439         GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_CAMERA, NULL,
0440                 LATCH1_PIN_LED_CAMERA, 0),
0441         GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_ADVERT, NULL,
0442                 LATCH1_PIN_LED_ADVERT, 0),
0443         GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_MAIL, NULL,
0444                 LATCH1_PIN_LED_MAIL, 0),
0445         GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_HANDSFREE, NULL,
0446                 LATCH1_PIN_LED_HANDSFREE, 0),
0447         GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_VOICEMAIL, NULL,
0448                 LATCH1_PIN_LED_VOICEMAIL, 0),
0449         GPIO_LOOKUP_IDX(LATCH1_LABEL, LATCH1_PIN_LED_VOICE, NULL,
0450                 LATCH1_PIN_LED_VOICE, 0),
0451         { },
0452     },
0453 };
0454 
0455 static struct platform_device ams_delta_audio_device = {
0456     .name   = "ams-delta-audio",
0457     .id     = -1,
0458 };
0459 
0460 static struct gpiod_lookup_table ams_delta_audio_gpio_table = {
0461     .table = {
0462         GPIO_LOOKUP(OMAP_GPIO_LABEL, AMS_DELTA_GPIO_PIN_HOOK_SWITCH,
0463                 "hook_switch", 0),
0464         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_MODEM_CODEC,
0465                 "modem_codec", 0),
0466         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_HANDSFREE_MUTE,
0467                 "handsfree_mute", 0),
0468         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_HANDSET_MUTE,
0469                 "handset_mute", 0),
0470         { },
0471     },
0472 };
0473 
0474 static struct platform_device cx20442_codec_device = {
0475     .name   = "cx20442-codec",
0476     .id     = -1,
0477 };
0478 
0479 static struct resource ams_delta_serio_resources[] = {
0480     {
0481         .flags  = IORESOURCE_IRQ,
0482         /*
0483          * Initialize IRQ resource with invalid IRQ number.
0484          * It will be replaced with dynamically allocated GPIO IRQ
0485          * obtained from GPIO chip as soon as the chip is available.
0486          */
0487         .start  = -EINVAL,
0488         .end    = -EINVAL,
0489     },
0490 };
0491 
0492 static struct platform_device ams_delta_serio_device = {
0493     .name       = "ams-delta-serio",
0494     .id     = PLATFORM_DEVID_NONE,
0495     .dev        = {
0496         /*
0497          * Initialize .platform_data explicitly with NULL to
0498          * indicate it is going to be used.  It will be replaced
0499          * with FIQ buffer address as soon as FIQ is initialized.
0500          */
0501         .platform_data = NULL,
0502     },
0503     .num_resources  = ARRAY_SIZE(ams_delta_serio_resources),
0504     .resource   = ams_delta_serio_resources,
0505 };
0506 
0507 static struct regulator_consumer_supply keybrd_pwr_consumers[] = {
0508     /*
0509      * Initialize supply .dev_name with NULL.  It will be replaced
0510      * with serio dev_name() as soon as the serio device is registered.
0511      */
0512     REGULATOR_SUPPLY("vcc", NULL),
0513 };
0514 
0515 static struct regulator_init_data keybrd_pwr_initdata = {
0516     .constraints        = {
0517         .valid_ops_mask     = REGULATOR_CHANGE_STATUS,
0518     },
0519     .num_consumer_supplies  = ARRAY_SIZE(keybrd_pwr_consumers),
0520     .consumer_supplies  = keybrd_pwr_consumers,
0521 };
0522 
0523 static struct fixed_voltage_config keybrd_pwr_config = {
0524     .supply_name        = "keybrd_pwr",
0525     .microvolts     = 5000000,
0526     .init_data      = &keybrd_pwr_initdata,
0527 };
0528 
0529 static struct platform_device keybrd_pwr_device = {
0530     .name   = "reg-fixed-voltage",
0531     .id = PLATFORM_DEVID_AUTO,
0532     .dev    = {
0533         .platform_data  = &keybrd_pwr_config,
0534     },
0535 };
0536 
0537 static struct gpiod_lookup_table keybrd_pwr_gpio_table = {
0538     .table = {
0539         GPIO_LOOKUP(LATCH2_LABEL, LATCH2_PIN_KEYBRD_PWR, NULL,
0540                 GPIO_ACTIVE_HIGH),
0541         { },
0542     },
0543 };
0544 
0545 static struct platform_device *ams_delta_devices[] __initdata = {
0546     &latch1_gpio_device,
0547     &latch2_gpio_device,
0548     &ams_delta_kp_device,
0549     &ams_delta_audio_device,
0550     &ams_delta_serio_device,
0551     &ams_delta_nand_device,
0552     &ams_delta_lcd_device,
0553     &cx20442_codec_device,
0554 };
0555 
0556 static struct gpiod_lookup_table *ams_delta_gpio_tables[] __initdata = {
0557     &ams_delta_nreset_gpiod_table,
0558     &ams_delta_audio_gpio_table,
0559     &keybrd_pwr_gpio_table,
0560     &ams_delta_lcd_gpio_table,
0561     &ams_delta_nand_gpio_table,
0562 };
0563 
0564 /*
0565  * Some drivers may not use GPIO lookup tables but need to be provided
0566  * with GPIO numbers.  The same applies to GPIO based IRQ lines - some
0567  * drivers may even not use GPIO layer but expect just IRQ numbers.
0568  * We could either define GPIO lookup tables then use them on behalf
0569  * of those devices, or we can use GPIO driver level methods for
0570  * identification of GPIO and IRQ numbers. For the purpose of the latter,
0571  * defina a helper function which identifies GPIO chips by their labels.
0572  */
0573 static int gpiochip_match_by_label(struct gpio_chip *chip, void *data)
0574 {
0575     char *label = data;
0576 
0577     return !strcmp(label, chip->label);
0578 }
0579 
0580 static struct gpiod_hog ams_delta_gpio_hogs[] = {
0581     GPIO_HOG(LATCH2_LABEL, LATCH2_PIN_KEYBRD_DATAOUT, "keybrd_dataout",
0582          GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW),
0583     {},
0584 };
0585 
0586 static struct plat_serial8250_port ams_delta_modem_ports[];
0587 
0588 /*
0589  * Obtain MODEM IRQ GPIO descriptor using its hardware pin
0590  * number and assign related IRQ number to the MODEM port.
0591  * Keep the GPIO descriptor open so nobody steps in.
0592  */
0593 static void __init modem_assign_irq(struct gpio_chip *chip)
0594 {
0595     struct gpio_desc *gpiod;
0596 
0597     gpiod = gpiochip_request_own_desc(chip, AMS_DELTA_GPIO_PIN_MODEM_IRQ,
0598                       "modem_irq", GPIO_ACTIVE_HIGH,
0599                       GPIOD_IN);
0600     if (IS_ERR(gpiod)) {
0601         pr_err("%s: modem IRQ GPIO request failed (%ld)\n", __func__,
0602                PTR_ERR(gpiod));
0603     } else {
0604         ams_delta_modem_ports[0].irq = gpiod_to_irq(gpiod);
0605     }
0606 }
0607 
0608 /*
0609  * The purpose of this function is to take care of proper initialization of
0610  * devices and data structures which depend on GPIO lines provided by OMAP GPIO
0611  * banks but their drivers don't use GPIO lookup tables or GPIO layer at all.
0612  * The function may be called as soon as OMAP GPIO devices are probed.
0613  * Since that happens at postcore_initcall, it can be called successfully
0614  * from init_machine or later.
0615  * Dependent devices may be registered from within this function or later.
0616  */
0617 static void __init omap_gpio_deps_init(void)
0618 {
0619     struct gpio_chip *chip;
0620 
0621     chip = gpiochip_find(OMAP_GPIO_LABEL, gpiochip_match_by_label);
0622     if (!chip) {
0623         pr_err("%s: OMAP GPIO chip not found\n", __func__);
0624         return;
0625     }
0626 
0627     /*
0628      * Start with FIQ initialization as it may have to request
0629      * and release successfully each OMAP GPIO pin in turn.
0630      */
0631     ams_delta_init_fiq(chip, &ams_delta_serio_device);
0632 
0633     modem_assign_irq(chip);
0634 }
0635 
0636 /*
0637  * Initialize latch2 pins with values which are safe for dependent on-board
0638  * devices or useful for their successull initialization even before GPIO
0639  * driver takes control over the latch pins:
0640  * - LATCH2_PIN_LCD_VBLEN   = 0
0641  * - LATCH2_PIN_LCD_NDISP   = 0 Keep LCD device powered off before its
0642  *                  driver takes control over it.
0643  * - LATCH2_PIN_NAND_NCE    = 0
0644  * - LATCH2_PIN_NAND_NWP    = 0 Keep NAND device down and write-
0645  *                  protected before its driver takes
0646  *                  control over it.
0647  * - LATCH2_PIN_KEYBRD_PWR  = 0 Keep keyboard powered off before serio
0648  *                  driver takes control over it.
0649  * - LATCH2_PIN_KEYBRD_DATAOUT  = 0 Keep low to avoid corruption of first
0650  *                  byte of data received from attached
0651  *                  keyboard when serio device is probed;
0652  *                  the pin is also hogged low by the latch2
0653  *                  GPIO driver as soon as it is ready.
0654  * - LATCH2_PIN_MODEM_NRESET    = 1 Enable voice MODEM device, allowing for
0655  *                  its successful probe even before a
0656  *                  regulator it depends on, which in turn
0657  *                  takes control over the pin, is set up.
0658  * - LATCH2_PIN_MODEM_CODEC = 1 Attach voice MODEM CODEC data port
0659  *                  to the MODEM so the CODEC is under
0660  *                  control even if audio driver doesn't
0661  *                  take it over.
0662  */
0663 static void __init ams_delta_latch2_init(void)
0664 {
0665     u16 latch2 = 1 << LATCH2_PIN_MODEM_NRESET | 1 << LATCH2_PIN_MODEM_CODEC;
0666 
0667     __raw_writew(latch2, IOMEM(LATCH2_VIRT));
0668 }
0669 
0670 static void __init ams_delta_init(void)
0671 {
0672     struct platform_device *leds_pdev;
0673 
0674     /* mux pins for uarts */
0675     omap_cfg_reg(UART1_TX);
0676     omap_cfg_reg(UART1_RTS);
0677 
0678     /* parallel camera interface */
0679     omap_cfg_reg(H19_1610_CAM_EXCLK);
0680     omap_cfg_reg(J15_1610_CAM_LCLK);
0681     omap_cfg_reg(L18_1610_CAM_VS);
0682     omap_cfg_reg(L15_1610_CAM_HS);
0683     omap_cfg_reg(L19_1610_CAM_D0);
0684     omap_cfg_reg(K14_1610_CAM_D1);
0685     omap_cfg_reg(K15_1610_CAM_D2);
0686     omap_cfg_reg(K19_1610_CAM_D3);
0687     omap_cfg_reg(K18_1610_CAM_D4);
0688     omap_cfg_reg(J14_1610_CAM_D5);
0689     omap_cfg_reg(J19_1610_CAM_D6);
0690     omap_cfg_reg(J18_1610_CAM_D7);
0691 
0692     omap_gpio_deps_init();
0693     ams_delta_latch2_init();
0694     gpiod_add_hogs(ams_delta_gpio_hogs);
0695 
0696     omap_serial_init();
0697     omap_register_i2c_bus(1, 100, NULL, 0);
0698 
0699     omap1_usb_init(&ams_delta_usb_config);
0700     platform_add_devices(ams_delta_devices, ARRAY_SIZE(ams_delta_devices));
0701 
0702     /*
0703      * As soon as regulator consumers have been registered, assign their
0704      * dev_names to consumer supply entries of respective regulators.
0705      */
0706     keybrd_pwr_consumers[0].dev_name =
0707             dev_name(&ams_delta_serio_device.dev);
0708 
0709     /*
0710      * Once consumer supply entries are populated with dev_names,
0711      * register regulator devices.  At this stage only the keyboard
0712      * power regulator has its consumer supply table fully populated.
0713      */
0714     platform_device_register(&keybrd_pwr_device);
0715 
0716     /*
0717      * As soon as GPIO consumers have been registered, assign
0718      * their dev_names to respective GPIO lookup tables.
0719      */
0720     ams_delta_audio_gpio_table.dev_id =
0721             dev_name(&ams_delta_audio_device.dev);
0722     keybrd_pwr_gpio_table.dev_id = dev_name(&keybrd_pwr_device.dev);
0723     ams_delta_nand_gpio_table.dev_id = dev_name(&ams_delta_nand_device.dev);
0724     ams_delta_lcd_gpio_table.dev_id = dev_name(&ams_delta_lcd_device.dev);
0725 
0726     /*
0727      * Once GPIO lookup tables are populated with dev_names, register them.
0728      */
0729     gpiod_add_lookup_tables(ams_delta_gpio_tables,
0730                 ARRAY_SIZE(ams_delta_gpio_tables));
0731 
0732     leds_pdev = gpio_led_register_device(PLATFORM_DEVID_NONE, &leds_pdata);
0733     if (!IS_ERR_OR_NULL(leds_pdev)) {
0734         leds_gpio_table.dev_id = dev_name(&leds_pdev->dev);
0735         gpiod_add_lookup_table(&leds_gpio_table);
0736     }
0737 
0738     omap_writew(omap_readw(ARM_RSTCT1) | 0x0004, ARM_RSTCT1);
0739 
0740     omapfb_set_lcd_config(&ams_delta_lcd_config);
0741 }
0742 
0743 static void modem_pm(struct uart_port *port, unsigned int state, unsigned old)
0744 {
0745     struct modem_private_data *priv = port->private_data;
0746     int ret;
0747 
0748     if (!priv)
0749         return;
0750 
0751     if (IS_ERR(priv->regulator))
0752         return;
0753 
0754     if (state == old)
0755         return;
0756 
0757     if (state == 0)
0758         ret = regulator_enable(priv->regulator);
0759     else if (old == 0)
0760         ret = regulator_disable(priv->regulator);
0761     else
0762         ret = 0;
0763 
0764     if (ret)
0765         dev_warn(port->dev,
0766              "ams_delta modem_pm: failed to %sable regulator: %d\n",
0767              state ? "dis" : "en", ret);
0768 }
0769 
0770 static struct plat_serial8250_port ams_delta_modem_ports[] = {
0771     {
0772         .membase    = IOMEM(MODEM_VIRT),
0773         .mapbase    = MODEM_PHYS,
0774         .irq        = IRQ_NOTCONNECTED, /* changed later */
0775         .flags      = UPF_BOOT_AUTOCONF,
0776         .irqflags   = IRQF_TRIGGER_RISING,
0777         .iotype     = UPIO_MEM,
0778         .regshift   = 1,
0779         .uartclk    = BASE_BAUD * 16,
0780         .pm     = modem_pm,
0781         .private_data   = &modem_priv,
0782     },
0783     { },
0784 };
0785 
0786 static struct platform_device ams_delta_modem_device = {
0787     .name   = "serial8250",
0788     .id = PLAT8250_DEV_PLATFORM1,
0789     .dev        = {
0790         .platform_data = ams_delta_modem_ports,
0791     },
0792 };
0793 
0794 static int __init modem_nreset_init(void)
0795 {
0796     int err;
0797 
0798     err = platform_device_register(&modem_nreset_device);
0799     if (err)
0800         pr_err("Couldn't register the modem regulator device\n");
0801 
0802     return err;
0803 }
0804 
0805 
0806 /*
0807  * This function expects MODEM IRQ number already assigned to the port.
0808  * The MODEM device requires its RESET# pin kept high during probe.
0809  * That requirement can be fulfilled in several ways:
0810  * - with a descriptor of already functional modem_nreset regulator
0811  *   assigned to the MODEM private data,
0812  * - with the regulator not yet controlled by modem_pm function but
0813  *   already enabled by default on probe,
0814  * - before the modem_nreset regulator is probed, with the pin already
0815  *   set high explicitly.
0816  * The last one is already guaranteed by ams_delta_latch2_init() called
0817  * from machine_init.
0818  * In order to avoid taking over ttyS0 device slot, the MODEM device
0819  * should be registered after OMAP serial ports.  Since those ports
0820  * are registered at arch_initcall, this function can be called safely
0821  * at arch_initcall_sync earliest.
0822  */
0823 static int __init ams_delta_modem_init(void)
0824 {
0825     int err;
0826 
0827     if (!machine_is_ams_delta())
0828         return -ENODEV;
0829 
0830     omap_cfg_reg(M14_1510_GPIO2);
0831 
0832     /* Initialize the modem_nreset regulator consumer before use */
0833     modem_priv.regulator = ERR_PTR(-ENODEV);
0834 
0835     err = platform_device_register(&ams_delta_modem_device);
0836 
0837     return err;
0838 }
0839 arch_initcall_sync(ams_delta_modem_init);
0840 
0841 static int __init late_init(void)
0842 {
0843     int err;
0844 
0845     err = modem_nreset_init();
0846     if (err)
0847         return err;
0848 
0849     /*
0850      * Once the modem device is registered, the modem_nreset
0851      * regulator can be requested on behalf of that device.
0852      */
0853     modem_priv.regulator = regulator_get(&ams_delta_modem_device.dev,
0854             "RESET#");
0855     if (IS_ERR(modem_priv.regulator)) {
0856         err = PTR_ERR(modem_priv.regulator);
0857         goto unregister;
0858     }
0859     return 0;
0860 
0861 unregister:
0862     platform_device_unregister(&ams_delta_modem_device);
0863     return err;
0864 }
0865 
0866 static void __init ams_delta_init_late(void)
0867 {
0868     omap1_init_late();
0869     late_init();
0870 }
0871 
0872 static void __init ams_delta_map_io(void)
0873 {
0874     omap15xx_map_io();
0875     iotable_init(ams_delta_io_desc, ARRAY_SIZE(ams_delta_io_desc));
0876 }
0877 
0878 MACHINE_START(AMS_DELTA, "Amstrad E3 (Delta)")
0879     /* Maintainer: Jonathan McDowell <noodles@earth.li> */
0880     .atag_offset    = 0x100,
0881     .map_io     = ams_delta_map_io,
0882     .init_early = omap1_init_early,
0883     .init_irq   = omap1_init_irq,
0884     .handle_irq = omap1_handle_irq,
0885     .init_machine   = ams_delta_init,
0886     .init_late  = ams_delta_init_late,
0887     .init_time  = omap1_timer_init,
0888     .restart    = omap1_restart,
0889 MACHINE_END