Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 //
0003 // S3C2442 Machine Support for Openmoko GTA02 / FreeRunner.
0004 //
0005 // Copyright (C) 2006-2009 by Openmoko, Inc.
0006 // Authors: Harald Welte <laforge@openmoko.org>
0007 //          Andy Green <andy@openmoko.org>
0008 //          Werner Almesberger <werner@openmoko.org>
0009 // All rights reserved.
0010 
0011 #include <linux/kernel.h>
0012 #include <linux/types.h>
0013 #include <linux/interrupt.h>
0014 #include <linux/list.h>
0015 #include <linux/delay.h>
0016 #include <linux/timer.h>
0017 #include <linux/init.h>
0018 #include <linux/gpio/machine.h>
0019 #include <linux/gpio.h>
0020 #include <linux/gpio_keys.h>
0021 #include <linux/workqueue.h>
0022 #include <linux/platform_device.h>
0023 #include <linux/serial_core.h>
0024 #include <linux/serial_s3c.h>
0025 #include <linux/input.h>
0026 #include <linux/io.h>
0027 #include <linux/i2c.h>
0028 
0029 #include <linux/mmc/host.h>
0030 
0031 #include <linux/mfd/pcf50633/adc.h>
0032 #include <linux/mfd/pcf50633/backlight.h>
0033 #include <linux/mfd/pcf50633/core.h>
0034 #include <linux/mfd/pcf50633/gpio.h>
0035 #include <linux/mfd/pcf50633/mbc.h>
0036 #include <linux/mfd/pcf50633/pmic.h>
0037 
0038 #include <linux/mtd/mtd.h>
0039 #include <linux/mtd/rawnand.h>
0040 #include <linux/mtd/nand-ecc-sw-hamming.h>
0041 #include <linux/mtd/partitions.h>
0042 #include <linux/mtd/physmap.h>
0043 
0044 #include <linux/regulator/machine.h>
0045 
0046 #include <linux/spi/spi.h>
0047 #include <linux/spi/s3c24xx.h>
0048 
0049 #include <asm/irq.h>
0050 #include <asm/mach-types.h>
0051 #include <asm/mach/arch.h>
0052 #include <asm/mach/map.h>
0053 #include <asm/mach/irq.h>
0054 
0055 #include <linux/platform_data/i2c-s3c2410.h>
0056 #include <linux/platform_data/mtd-nand-s3c2410.h>
0057 #include <linux/platform_data/touchscreen-s3c2410.h>
0058 #include <linux/platform_data/usb-ohci-s3c2410.h>
0059 #include <linux/platform_data/usb-s3c2410_udc.h>
0060 #include <linux/platform_data/fb-s3c2410.h>
0061 
0062 #include "regs-gpio.h"
0063 #include "regs-irq.h"
0064 #include "gpio-samsung.h"
0065 
0066 #include "cpu.h"
0067 #include "devs.h"
0068 #include "gpio-cfg.h"
0069 #include "pm.h"
0070 
0071 #include "s3c24xx.h"
0072 #include "gta02.h"
0073 
0074 static struct pcf50633 *gta02_pcf;
0075 
0076 /*
0077  * This gets called frequently when we paniced.
0078  */
0079 
0080 static long gta02_panic_blink(int state)
0081 {
0082     char led;
0083 
0084     led = (state) ? 1 : 0;
0085     gpio_direction_output(GTA02_GPIO_AUX_LED, led);
0086 
0087     return 0;
0088 }
0089 
0090 
0091 static struct map_desc gta02_iodesc[] __initdata = {
0092     {
0093         .virtual    = 0xe0000000,
0094         .pfn        = __phys_to_pfn(S3C2410_CS3 + 0x01000000),
0095         .length     = SZ_1M,
0096         .type       = MT_DEVICE
0097     },
0098 };
0099 
0100 #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
0101 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
0102 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
0103 
0104 static struct s3c2410_uartcfg gta02_uartcfgs[] = {
0105     [0] = {
0106         .hwport     = 0,
0107         .flags      = 0,
0108         .ucon       = UCON,
0109         .ulcon      = ULCON,
0110         .ufcon      = UFCON,
0111     },
0112     [1] = {
0113         .hwport     = 1,
0114         .flags      = 0,
0115         .ucon       = UCON,
0116         .ulcon      = ULCON,
0117         .ufcon      = UFCON,
0118     },
0119     [2] = {
0120         .hwport     = 2,
0121         .flags      = 0,
0122         .ucon       = UCON,
0123         .ulcon      = ULCON,
0124         .ufcon      = UFCON,
0125     },
0126 };
0127 
0128 #ifdef CONFIG_CHARGER_PCF50633
0129 /*
0130  * On GTA02 the 1A charger features a 48K resistor to 0V on the ID pin.
0131  * We use this to recognize that we can pull 1A from the USB socket.
0132  *
0133  * These constants are the measured pcf50633 ADC levels with the 1A
0134  * charger / 48K resistor, and with no pulldown resistor.
0135  */
0136 
0137 #define ADC_NOM_CHG_DETECT_1A 6
0138 #define ADC_NOM_CHG_DETECT_USB 43
0139 
0140 #ifdef CONFIG_PCF50633_ADC
0141 static void
0142 gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
0143 {
0144     int  ma;
0145 
0146     /* Interpret charger type */
0147     if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2)) {
0148 
0149         /*
0150          * Sanity - stop GPO driving out now that we have a 1A charger
0151          * GPO controls USB Host power generation on GTA02
0152          */
0153         pcf50633_gpio_set(pcf, PCF50633_GPO, 0);
0154 
0155         ma = 1000;
0156     } else
0157         ma = 100;
0158 
0159     pcf50633_mbc_usb_curlim_set(pcf, ma);
0160 }
0161 #endif
0162 
0163 static struct delayed_work gta02_charger_work;
0164 static int gta02_usb_vbus_draw;
0165 
0166 static void gta02_charger_worker(struct work_struct *work)
0167 {
0168     if (gta02_usb_vbus_draw) {
0169         pcf50633_mbc_usb_curlim_set(gta02_pcf, gta02_usb_vbus_draw);
0170         return;
0171     }
0172 
0173 #ifdef CONFIG_PCF50633_ADC
0174     pcf50633_adc_async_read(gta02_pcf,
0175                 PCF50633_ADCC1_MUX_ADCIN1,
0176                 PCF50633_ADCC1_AVERAGE_16,
0177                 gta02_configure_pmu_for_charger,
0178                 NULL);
0179 #else
0180     /*
0181      * If the PCF50633 ADC is disabled we fallback to a
0182      * 100mA limit for safety.
0183      */
0184     pcf50633_mbc_usb_curlim_set(gta02_pcf, 100);
0185 #endif
0186 }
0187 
0188 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
0189 
0190 static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
0191 {
0192     if (irq == PCF50633_IRQ_USBINS) {
0193         schedule_delayed_work(&gta02_charger_work,
0194                       GTA02_CHARGER_CONFIGURE_TIMEOUT);
0195 
0196         return;
0197     }
0198 
0199     if (irq == PCF50633_IRQ_USBREM) {
0200         cancel_delayed_work_sync(&gta02_charger_work);
0201         gta02_usb_vbus_draw = 0;
0202     }
0203 }
0204 
0205 static void gta02_udc_vbus_draw(unsigned int ma)
0206 {
0207     if (!gta02_pcf)
0208         return;
0209 
0210     gta02_usb_vbus_draw = ma;
0211 
0212     schedule_delayed_work(&gta02_charger_work,
0213                   GTA02_CHARGER_CONFIGURE_TIMEOUT);
0214 }
0215 #else /* !CONFIG_CHARGER_PCF50633 */
0216 #define gta02_pmu_event_callback    NULL
0217 #define gta02_udc_vbus_draw     NULL
0218 #endif
0219 
0220 static char *gta02_batteries[] = {
0221     "battery",
0222 };
0223 
0224 static struct pcf50633_bl_platform_data gta02_backlight_data = {
0225     .default_brightness = 0x3f,
0226     .default_brightness_limit = 0,
0227     .ramp_time = 5,
0228 };
0229 
0230 static struct pcf50633_platform_data gta02_pcf_pdata = {
0231     .resumers = {
0232         [0] =   PCF50633_INT1_USBINS |
0233             PCF50633_INT1_USBREM |
0234             PCF50633_INT1_ALARM,
0235         [1] =   PCF50633_INT2_ONKEYF,
0236         [2] =   PCF50633_INT3_ONKEY1S,
0237         [3] =   PCF50633_INT4_LOWSYS |
0238             PCF50633_INT4_LOWBAT |
0239             PCF50633_INT4_HIGHTMP,
0240     },
0241 
0242     .batteries = gta02_batteries,
0243     .num_batteries = ARRAY_SIZE(gta02_batteries),
0244 
0245     .charger_reference_current_ma = 1000,
0246 
0247     .backlight_data = &gta02_backlight_data,
0248 
0249     .reg_init_data = {
0250         [PCF50633_REGULATOR_AUTO] = {
0251             .constraints = {
0252                 .min_uV = 3300000,
0253                 .max_uV = 3300000,
0254                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0255                 .always_on = 1,
0256                 .apply_uV = 1,
0257             },
0258         },
0259         [PCF50633_REGULATOR_DOWN1] = {
0260             .constraints = {
0261                 .min_uV = 1300000,
0262                 .max_uV = 1600000,
0263                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0264                 .always_on = 1,
0265                 .apply_uV = 1,
0266             },
0267         },
0268         [PCF50633_REGULATOR_DOWN2] = {
0269             .constraints = {
0270                 .min_uV = 1800000,
0271                 .max_uV = 1800000,
0272                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0273                 .apply_uV = 1,
0274                 .always_on = 1,
0275             },
0276         },
0277         [PCF50633_REGULATOR_HCLDO] = {
0278             .constraints = {
0279                 .min_uV = 2000000,
0280                 .max_uV = 3300000,
0281                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0282                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
0283                         REGULATOR_CHANGE_STATUS,
0284             },
0285         },
0286         [PCF50633_REGULATOR_LDO1] = {
0287             .constraints = {
0288                 .min_uV = 3300000,
0289                 .max_uV = 3300000,
0290                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0291                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
0292                 .apply_uV = 1,
0293             },
0294         },
0295         [PCF50633_REGULATOR_LDO2] = {
0296             .constraints = {
0297                 .min_uV = 3300000,
0298                 .max_uV = 3300000,
0299                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0300                 .apply_uV = 1,
0301             },
0302         },
0303         [PCF50633_REGULATOR_LDO3] = {
0304             .constraints = {
0305                 .min_uV = 3000000,
0306                 .max_uV = 3000000,
0307                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0308                 .apply_uV = 1,
0309             },
0310         },
0311         [PCF50633_REGULATOR_LDO4] = {
0312             .constraints = {
0313                 .min_uV = 3200000,
0314                 .max_uV = 3200000,
0315                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0316                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
0317                 .apply_uV = 1,
0318             },
0319         },
0320         [PCF50633_REGULATOR_LDO5] = {
0321             .constraints = {
0322                 .min_uV = 3000000,
0323                 .max_uV = 3000000,
0324                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0325                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
0326                 .apply_uV = 1,
0327             },
0328         },
0329         [PCF50633_REGULATOR_LDO6] = {
0330             .constraints = {
0331                 .min_uV = 3000000,
0332                 .max_uV = 3000000,
0333                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0334             },
0335         },
0336         [PCF50633_REGULATOR_MEMLDO] = {
0337             .constraints = {
0338                 .min_uV = 1800000,
0339                 .max_uV = 1800000,
0340                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
0341             },
0342         },
0343 
0344     },
0345     .mbc_event_callback = gta02_pmu_event_callback,
0346 };
0347 
0348 
0349 /* NOR Flash. */
0350 
0351 #define GTA02_FLASH_BASE    0x18000000 /* GCS3 */
0352 #define GTA02_FLASH_SIZE    0x200000 /* 2MBytes */
0353 
0354 static struct physmap_flash_data gta02_nor_flash_data = {
0355     .width      = 2,
0356 };
0357 
0358 static struct resource gta02_nor_flash_resource =
0359     DEFINE_RES_MEM(GTA02_FLASH_BASE, GTA02_FLASH_SIZE);
0360 
0361 static struct platform_device gta02_nor_flash = {
0362     .name       = "physmap-flash",
0363     .id     = 0,
0364     .dev        = {
0365         .platform_data  = &gta02_nor_flash_data,
0366     },
0367     .resource   = &gta02_nor_flash_resource,
0368     .num_resources  = 1,
0369 };
0370 
0371 
0372 static struct platform_device s3c24xx_pwm_device = {
0373     .name       = "s3c24xx_pwm",
0374     .num_resources  = 0,
0375 };
0376 
0377 static struct platform_device gta02_dfbmcs320_device = {
0378     .name = "dfbmcs320",
0379 };
0380 
0381 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
0382     {
0383         I2C_BOARD_INFO("pcf50633", 0x73),
0384         .irq = GTA02_IRQ_PCF50633,
0385         .platform_data = &gta02_pcf_pdata,
0386     },
0387     {
0388         I2C_BOARD_INFO("wm8753", 0x1a),
0389     },
0390 };
0391 
0392 static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
0393     [0] = {
0394         /*
0395          * This name is also hard-coded in the boot loaders, so
0396          * changing it would would require all users to upgrade
0397          * their boot loaders, some of which are stored in a NOR
0398          * that is considered to be immutable.
0399          */
0400         .name       = "neo1973-nand",
0401         .nr_chips   = 1,
0402         .flash_bbt  = 1,
0403     },
0404 };
0405 
0406 /*
0407  * Choose a set of timings derived from S3C@2442B MCP54
0408  * data sheet (K5D2G13ACM-D075 MCP Memory).
0409  */
0410 
0411 static struct s3c2410_platform_nand __initdata gta02_nand_info = {
0412     .tacls      = 0,
0413     .twrph0     = 25,
0414     .twrph1     = 15,
0415     .nr_sets    = ARRAY_SIZE(gta02_nand_sets),
0416     .sets       = gta02_nand_sets,
0417     .engine_type    = NAND_ECC_ENGINE_TYPE_SOFT,
0418 };
0419 
0420 
0421 /* Get PMU to set USB current limit accordingly. */
0422 static struct s3c2410_udc_mach_info gta02_udc_cfg __initdata = {
0423     .vbus_draw  = gta02_udc_vbus_draw,
0424     .pullup_pin = GTA02_GPIO_USB_PULLUP,
0425 };
0426 
0427 /* USB */
0428 static struct s3c2410_hcd_info gta02_usb_info __initdata = {
0429     .port[0]    = {
0430         .flags  = S3C_HCDFLG_USED,
0431     },
0432     .port[1]    = {
0433         .flags  = 0,
0434     },
0435 };
0436 
0437 /* Touchscreen */
0438 static struct s3c2410_ts_mach_info gta02_ts_info = {
0439     .delay          = 10000,
0440     .presc          = 0xff, /* slow as we can go */
0441     .oversampling_shift = 2,
0442 };
0443 
0444 /* Buttons */
0445 static struct gpio_keys_button gta02_buttons[] = {
0446     {
0447         .gpio = GTA02_GPIO_AUX_KEY,
0448         .code = KEY_PHONE,
0449         .desc = "Aux",
0450         .type = EV_KEY,
0451         .debounce_interval = 100,
0452     },
0453     {
0454         .gpio = GTA02_GPIO_HOLD_KEY,
0455         .code = KEY_PAUSE,
0456         .desc = "Hold",
0457         .type = EV_KEY,
0458         .debounce_interval = 100,
0459     },
0460 };
0461 
0462 static struct gpio_keys_platform_data gta02_buttons_pdata = {
0463     .buttons = gta02_buttons,
0464     .nbuttons = ARRAY_SIZE(gta02_buttons),
0465 };
0466 
0467 static struct platform_device gta02_buttons_device = {
0468     .name = "gpio-keys",
0469     .id = -1,
0470     .dev = {
0471         .platform_data = &gta02_buttons_pdata,
0472     },
0473 };
0474 
0475 static struct gpiod_lookup_table gta02_audio_gpio_table = {
0476     .dev_id = "neo1973-audio",
0477     .table = {
0478         GPIO_LOOKUP("GPIOJ", 2, "amp-shut", GPIO_ACTIVE_HIGH),
0479         GPIO_LOOKUP("GPIOJ", 1, "hp", GPIO_ACTIVE_HIGH),
0480         { },
0481     },
0482 };
0483 
0484 static struct platform_device gta02_audio = {
0485     .name = "neo1973-audio",
0486     .id = -1,
0487 };
0488 
0489 static struct gpiod_lookup_table gta02_mmc_gpio_table = {
0490     .dev_id = "s3c2410-sdi",
0491     .table = {
0492         /* bus pins */
0493         GPIO_LOOKUP_IDX("GPIOE",  5, "bus", 0, GPIO_ACTIVE_HIGH),
0494         GPIO_LOOKUP_IDX("GPIOE",  6, "bus", 1, GPIO_ACTIVE_HIGH),
0495         GPIO_LOOKUP_IDX("GPIOE",  7, "bus", 2, GPIO_ACTIVE_HIGH),
0496         GPIO_LOOKUP_IDX("GPIOE",  8, "bus", 3, GPIO_ACTIVE_HIGH),
0497         GPIO_LOOKUP_IDX("GPIOE",  9, "bus", 4, GPIO_ACTIVE_HIGH),
0498         GPIO_LOOKUP_IDX("GPIOE", 10, "bus", 5, GPIO_ACTIVE_HIGH),
0499         { },
0500     },
0501 };
0502 
0503 static void __init gta02_map_io(void)
0504 {
0505     s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
0506     s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
0507     s3c24xx_set_timer_source(S3C24XX_PWM3, S3C24XX_PWM4);
0508 }
0509 
0510 
0511 /* These are the guys that don't need to be children of PMU. */
0512 
0513 static struct platform_device *gta02_devices[] __initdata = {
0514     &s3c_device_ohci,
0515     &s3c_device_wdt,
0516     &s3c_device_sdi,
0517     &s3c_device_usbgadget,
0518     &s3c_device_nand,
0519     &gta02_nor_flash,
0520     &s3c24xx_pwm_device,
0521     &s3c_device_iis,
0522     &s3c_device_i2c0,
0523     &gta02_dfbmcs320_device,
0524     &gta02_buttons_device,
0525     &s3c_device_adc,
0526     &s3c_device_ts,
0527     &gta02_audio,
0528 };
0529 
0530 static void gta02_poweroff(void)
0531 {
0532     pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
0533 }
0534 
0535 static void __init gta02_machine_init(void)
0536 {
0537     /* Set the panic callback to turn AUX LED on or off. */
0538     panic_blink = gta02_panic_blink;
0539 
0540     s3c_pm_init();
0541 
0542 #ifdef CONFIG_CHARGER_PCF50633
0543     INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
0544 #endif
0545 
0546     s3c24xx_udc_set_platdata(&gta02_udc_cfg);
0547     s3c24xx_ts_set_platdata(&gta02_ts_info);
0548     s3c_ohci_set_platdata(&gta02_usb_info);
0549     s3c_nand_set_platdata(&gta02_nand_info);
0550     s3c_i2c0_set_platdata(NULL);
0551 
0552     i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
0553 
0554     /* Configure the I2S pins (GPE0...GPE4) in correct mode */
0555     s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
0556                   S3C_GPIO_PULL_NONE);
0557 
0558     gpiod_add_lookup_table(&gta02_audio_gpio_table);
0559     gpiod_add_lookup_table(&gta02_mmc_gpio_table);
0560     platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
0561     pm_power_off = gta02_poweroff;
0562 
0563     regulator_has_full_constraints();
0564 }
0565 
0566 static void __init gta02_init_time(void)
0567 {
0568     s3c2442_init_clocks(12000000);
0569     s3c24xx_timer_init();
0570 }
0571 
0572 MACHINE_START(NEO1973_GTA02, "GTA02")
0573     /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
0574     .atag_offset    = 0x100,
0575     .nr_irqs    = NR_IRQS_S3C2442,
0576     .map_io     = gta02_map_io,
0577     .init_irq   = s3c2442_init_irq,
0578     .init_machine   = gta02_machine_init,
0579     .init_time  = gta02_init_time,
0580 MACHINE_END