2 * linux/arch/arm/mach-s3c2442/mach-gta02.c
4 * S3C2442 Machine Support for the Openmoko Freerunner (GTA02)
6 * Copyright (C) 2006-2007 by Openmoko, Inc.
7 * Author: Harald Welte <laforge@openmoko.org>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/interrupt.h>
30 #include <linux/list.h>
31 #include <linux/delay.h>
32 #include <linux/timer.h>
33 #include <linux/init.h>
34 #include <linux/workqueue.h>
35 #include <linux/platform_device.h>
36 #include <linux/serial_core.h>
37 #include <linux/spi/spi.h>
38 #include <linux/spi/spi_gpio.h>
39 #include <linux/spi/spi_bitbang.h>
40 #include <linux/mmc/host.h>
41 #include <linux/leds.h>
42 #include <linux/gpio_keys.h>
44 #include <linux/mtd/mtd.h>
45 #include <linux/mtd/nand.h>
46 #include <linux/mtd/nand_ecc.h>
47 #include <linux/mtd/partitions.h>
48 #include <linux/mtd/physmap.h>
50 #include <linux/i2c.h>
51 #include <linux/backlight.h>
52 #include <linux/regulator/machine.h>
54 #include <linux/mfd/pcf50633/core.h>
55 #include <linux/mfd/pcf50633/mbc.h>
56 #include <linux/mfd/pcf50633/adc.h>
57 #include <linux/mfd/pcf50633/gpio.h>
58 #include <linux/mfd/pcf50633/pmic.h>
60 #include <linux/lis302dl.h>
62 #include <asm/mach/arch.h>
63 #include <asm/mach/map.h>
64 #include <asm/mach/irq.h>
66 #include <mach/hardware.h>
69 #include <asm/mach-types.h>
71 #include <mach/regs-irq.h>
72 #include <mach/regs-gpio.h>
73 #include <mach/regs-gpioj.h>
78 #include <mach/spi-gpio.h>
79 #include <mach/regs-mem.h>
83 #include <mach/gta02.h>
85 #include <plat/regs-serial.h>
86 #include <plat/nand.h>
87 #include <plat/devs.h>
92 #include <plat/usb-control.h>
93 #include <plat/regs-timer.h>
94 #include <plat/gpio-core.h>
96 #include <mach/gta02-pm-gsm.h>
97 #include <mach/gta02-pm-gps.h>
98 #include <mach/gta02-pm-wlan.h>
100 #include <linux/jbt6k74.h>
101 #include <linux/glamofb.h>
102 #include <linux/mfd/glamo.h>
104 #include <linux/hdq.h>
105 #include <linux/bq27000_battery.h>
107 #include <linux/touchscreen/ts_filter_chain.h>
108 #ifdef CONFIG_TOUCHSCREEN_FILTER
109 #include <linux/touchscreen/ts_filter_linear.h>
110 #include <linux/touchscreen/ts_filter_mean.h>
111 #include <linux/touchscreen/ts_filter_median.h>
112 #include <linux/touchscreen/ts_filter_group.h>
117 #include <linux/gta02-vibrator.h>
119 /* -------------------------------------------------------------------------------
122 * Calls into vibrator and hdq and based on the return values
123 * determines if we the FIQ source be kept alive
126 #define DIVISOR_FROM_US(x) ((x) << 3)
128 #ifdef CONFIG_HDQ_GPIO_BITBANG
129 #define FIQ_DIVISOR_HDQ DIVISOR_FROM_US(HDQ_SAMPLE_PERIOD_US)
130 extern int hdq_fiq_handler(void);
133 #ifdef CONFIG_LEDS_GTA02_VIBRATOR
134 #define FIQ_DIVISOR_VIBRATOR DIVISOR_FROM_US(100)
135 extern int gta02_vibrator_fiq_handler(void);
138 #if defined(CONFIG_LEDS_GTA02_VIBRATOR) || defined(CONFIG_HDQ_GPIO_BITBANG)
140 /* Global data related to our fiq source */
141 static u32 gta02_fiq_ack_mask;
142 static struct s3c2410_pwm gta02_fiq_pwm_timer;
143 static u16 gta02_fiq_timer_index;
144 static int gta02_fiq_irq;
146 static void gta02_fiq_handler(void)
148 u16 divisor = 0xffff;
150 /* Vibrator servicing */
152 /* disable further timer interrupts if nobody has any work
153 * or adjust rate according to who still has work
155 * CAUTION: it means forground code must disable FIQ around
156 * its own non-atomic S3C2410_INTMSK changes... not common
157 * thankfully and taken care of by the fiq-basis patch
160 #ifdef CONFIG_LEDS_GTA02_VIBRATOR
161 if (gta02_vibrator_fiq_handler())
162 divisor = FIQ_DIVISOR_VIBRATOR;
165 #ifdef CONFIG_HDQ_GPIO_BITBANG
166 if (hdq_fiq_handler())
167 divisor = FIQ_DIVISOR_HDQ;
170 if (divisor == 0xffff) /* mask the fiq irq source */
171 __raw_writel(__raw_readl(S3C2410_INTMSK) | gta02_fiq_ack_mask,
173 else /* still working, maybe at a different rate */
174 __raw_writel(divisor, S3C2410_TCNTB(gta02_fiq_timer_index));
176 __raw_writel(gta02_fiq_ack_mask, S3C2410_SRCPND);
179 static void gta02_fiq_kick(void)
184 /* we have to take care about FIQ because this modification is
185 * non-atomic, FIQ could come in after the read and before the
186 * writeback and its changes to the register would be lost
187 * (platform INTMSK mod code is taken care of already)
189 local_save_flags(flags);
191 /* allow FIQs to resume */
192 __raw_writel(__raw_readl(S3C2410_INTMSK) &
193 ~(1 << (gta02_fiq_irq - S3C2410_CPUIRQ_OFFSET)),
195 tcon = __raw_readl(S3C2410_TCON) & ~S3C2410_TCON_T3START;
196 /* fake the timer to a count of 1 */
197 __raw_writel(1, S3C2410_TCNTB(gta02_fiq_timer_index));
198 __raw_writel(tcon | S3C2410_TCON_T3MANUALUPD, S3C2410_TCON);
199 __raw_writel(tcon | S3C2410_TCON_T3MANUALUPD | S3C2410_TCON_T3START,
201 __raw_writel(tcon | S3C2410_TCON_T3START, S3C2410_TCON);
202 local_irq_restore(flags);
205 static int gta02_fiq_enable(void)
207 int irq_index_fiq = IRQ_TIMER3;
212 gta02_fiq_irq = irq_index_fiq;
213 gta02_fiq_ack_mask = 1 << (irq_index_fiq - S3C2410_CPUIRQ_OFFSET);
214 gta02_fiq_timer_index = (irq_index_fiq - IRQ_TIMER0);
216 /* set up the timer to operate as a pwm device */
218 rc = s3c2410_pwm_init(>a02_fiq_pwm_timer);
222 gta02_fiq_pwm_timer.timerid = PWM0 + gta02_fiq_timer_index;
223 gta02_fiq_pwm_timer.prescaler = (6 - 1) / 2;
224 gta02_fiq_pwm_timer.divider = S3C2410_TCFG1_MUX3_DIV2;
225 /* default rate == ~32us */
226 gta02_fiq_pwm_timer.counter = gta02_fiq_pwm_timer.comparer = 3000;
228 rc = s3c2410_pwm_enable(>a02_fiq_pwm_timer);
232 s3c2410_pwm_start(>a02_fiq_pwm_timer);
234 /* let our selected interrupt be a magic FIQ interrupt */
235 __raw_writel(gta02_fiq_ack_mask, S3C2410_INTMOD);
237 /* it's ready to go as soon as we unmask the source in S3C2410_INTMSK */
240 set_fiq_c_handler(gta02_fiq_handler);
245 printk(KERN_ERR "Could not initialize FIQ for GTA02: %d\n", rc);
250 static void gta02_fiq_disable(void)
252 __raw_writel(0, S3C2410_INTMOD);
254 gta02_fiq_irq = 0; /* no active source interrupt now either */
257 /* -------------------- /GTA02 FIQ Handler ------------------------------------- */
262 * this gets called every 1ms when we paniced.
265 static long gta02_panic_blink(long count)
268 static long last_blink;
271 if (count - last_blink < 100) /* 200ms period, fast blink */
275 s3c2410_gpio_cfgpin(GTA02_GPIO_AUX_LED, S3C2410_GPIO_OUTPUT);
276 s3c2410_gpio_setpin(GTA02_GPIO_AUX_LED, led);
284 * returns PCB revision information in b9,b8 and b2,b1,b0
285 * Pre-GTA02 A6 returns 0x000
286 * GTA02 A6 returns 0x101
290 int gta02_get_pcb_revision(void)
294 static unsigned long pinlist[] = {
301 static int pin_offset[] = {
305 for (n = 0 ; n < ARRAY_SIZE(pinlist); n++) {
307 * set the PCB version GPIO to be pulled-down input
308 * force low briefly first
310 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_OUTPUT);
311 s3c2410_gpio_setpin(pinlist[n], 0);
312 /* misnomer: it is a pullDOWN in 2442 */
313 s3c2410_gpio_pullup(pinlist[n], 1);
314 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_INPUT);
318 if (s3c2410_gpio_getpin(pinlist[n]))
319 u |= 1 << pin_offset[n];
322 * when not being interrogated, all of the revision GPIO
323 * are set to output HIGH without pulldown so no current flows
324 * if they are NC or pulled up.
326 s3c2410_gpio_setpin(pinlist[n], 1);
327 s3c2410_gpio_cfgpin(pinlist[n], S3C2410_GPIO_OUTPUT);
328 /* misnomer: it is a pullDOWN in 2442 */
329 s3c2410_gpio_pullup(pinlist[n], 0);
335 struct platform_device gta02_resume_reason_device = {
336 .name = "gta02-resume",
340 static struct map_desc gta02_iodesc[] __initdata = {
342 .virtual = 0xe0000000,
343 .pfn = __phys_to_pfn(S3C2410_CS3+0x01000000),
349 #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
350 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
351 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
353 static struct s3c2410_uartcfg gta02_uartcfgs[] = {
378 struct pcf50633 *gta02_pcf;
380 #ifdef CONFIG_CHARGER_PCF50633
381 #ifdef CONFIG_HDQ_GPIO_BITBANG
382 static int gta02_get_charger_online_status(void)
384 struct pcf50633 *pcf = gta02_pcf;
386 return pcf50633_mbc_get_status(pcf) & PCF50633_MBC_USB_ONLINE;
389 static int gta02_get_charger_active_status(void)
391 struct pcf50633 *pcf = gta02_pcf;
393 return pcf50633_mbc_get_status(pcf) & PCF50633_MBC_USB_ACTIVE;
397 #define ADC_NOM_CHG_DETECT_1A 6
398 #define ADC_NOM_CHG_DETECT_USB 43
401 gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
405 /* Interpret charger type */
406 if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2)) {
408 /* Stop GPO driving out now that we have a IA charger */
409 pcf50633_gpio_set(pcf, PCF50633_GPO, 0);
415 pcf50633_mbc_usb_curlim_set(pcf, ma);
418 static struct delayed_work gta02_charger_work;
419 static int gta02_usb_vbus_draw;
421 static void gta02_charger_worker(struct work_struct *work)
423 struct pcf50633 *pcf = gta02_pcf;
425 if (gta02_usb_vbus_draw) {
426 pcf50633_mbc_usb_curlim_set(pcf, gta02_usb_vbus_draw);
429 #ifdef CONFIG_PCF50633_ADC
430 pcf50633_adc_async_read(pcf,
431 PCF50633_ADCC1_MUX_ADCIN1,
432 PCF50633_ADCC1_AVERAGE_16,
433 gta02_configure_pmu_for_charger, NULL);
435 /* If the PCF50633 ADC is disabled we fallback to a 100mA limit for safety. */
436 pcf50633_mbc_usb_curlim_set(pcf, 100);
442 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
443 static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
445 if (irq == PCF50633_IRQ_USBINS) {
446 schedule_delayed_work(>a02_charger_work,
447 GTA02_CHARGER_CONFIGURE_TIMEOUT);
449 } else if (irq == PCF50633_IRQ_USBREM) {
450 cancel_delayed_work_sync(>a02_charger_work);
451 gta02_usb_vbus_draw = 0;
455 static void gta02_pmu_force_shutdown(struct pcf50633 *pcf)
457 pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_OOCSHDWN,
458 PCF50633_OOCSHDWN_GOSTDBY, PCF50633_OOCSHDWN_GOSTDBY);
462 static void gta02_udc_vbus_draw(unsigned int ma)
467 gta02_usb_vbus_draw = ma;
469 schedule_delayed_work(>a02_charger_work,
470 GTA02_CHARGER_CONFIGURE_TIMEOUT);
473 static int gta02_udc_vbus_status(void)
475 struct pcf50633 *pcf = gta02_pcf;
479 return !!(pcf50633_mbc_get_status(pcf) & PCF50633_MBC_USB_ONLINE);
482 #else /* !CONFIG_CHARGER_PCF50633 */
483 #ifdef CONFIG_HDQ_GPIO_BITBANG
484 #define gta02_get_charger_online_status NULL
485 #define gta02_get_charger_active_status NULL
487 #define gta02_pmu_event_callback NULL
488 #define gta02_udc_vbus_draw NULL
489 #define gta02_udc_vbus_status NULL
493 static struct platform_device gta02_pm_gps_dev = {
494 .name = "gta02-pm-gps",
497 static struct platform_device gta02_pm_bt_dev = {
498 .name = "gta02-pm-bt",
501 static struct platform_device gta02_pm_gsm_dev = {
502 .name = "gta02-pm-gsm",
505 static struct platform_device gta02_pm_wlan_dev = {
506 .name = "gta02-pm-wlan",
509 /* this is called when pc50633 is probed, unfortunately quite late in the
510 * day since it is an I2C bus device. Here we can belatedly define some
511 * platform devices with the advantage that we can mark the pcf50633 as the
512 * parent. This makes them get suspended and resumed with their parent
513 * the pcf50633 still around.
516 static struct platform_device gta02_glamo_dev;
518 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf);
519 static void gta02_pmu_regulator_registered(struct pcf50633 *pcf, int id);
521 static struct regulator_consumer_supply ldo4_consumers[] = {
523 .dev = >a02_pm_bt_dev.dev,
528 static struct regulator_consumer_supply ldo5_consumers[] = {
530 .dev = >a02_pm_gps_dev.dev,
535 static struct regulator_consumer_supply hcldo_consumers[] = {
537 .dev = >a02_glamo_dev.dev,
542 static struct regulator_consumer_supply ldo6_consumers[] = {
544 { .supply = "VDDIO" },
547 static char *gta02_batteries[] = {
551 #ifdef CONFIG_CHARGER_PCF50633
553 struct pcf50633_platform_data gta02_pcf_pdata = {
555 [0] = PCF50633_INT1_USBINS |
556 PCF50633_INT1_USBREM |
558 [1] = PCF50633_INT2_ONKEYF,
559 [2] = PCF50633_INT3_ONKEY1S,
560 [3] = PCF50633_INT4_LOWSYS |
561 PCF50633_INT4_LOWBAT |
562 PCF50633_INT4_HIGHTMP,
565 .batteries = gta02_batteries,
566 .num_batteries = ARRAY_SIZE(gta02_batteries),
567 .charging_restart_interval = (900 * HZ),
568 .chg_ref_current_ma = 1000,
571 [PCF50633_REGULATOR_AUTO] = {
576 .valid_modes_mask = REGULATOR_MODE_NORMAL,
584 .num_consumer_supplies = 0,
586 [PCF50633_REGULATOR_DOWN1] = {
591 .valid_modes_mask = REGULATOR_MODE_NORMAL,
596 .num_consumer_supplies = 0,
598 [PCF50633_REGULATOR_DOWN2] = {
603 .valid_modes_mask = REGULATOR_MODE_NORMAL,
611 .num_consumer_supplies = 0,
613 [PCF50633_REGULATOR_HCLDO] = {
618 .valid_modes_mask = REGULATOR_MODE_NORMAL,
619 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
622 .num_consumer_supplies = ARRAY_SIZE(hcldo_consumers),
623 .consumer_supplies = hcldo_consumers,
625 [PCF50633_REGULATOR_LDO1] = {
627 .name = "GSENSOR_3V3",
630 .valid_modes_mask = REGULATOR_MODE_NORMAL,
634 .num_consumer_supplies = 0,
636 [PCF50633_REGULATOR_LDO2] = {
641 .valid_modes_mask = REGULATOR_MODE_NORMAL,
645 .num_consumer_supplies = 0,
647 [PCF50633_REGULATOR_LDO3] = {
651 .valid_modes_mask = REGULATOR_MODE_NORMAL,
655 .num_consumer_supplies = 0,
657 [PCF50633_REGULATOR_LDO4] = {
662 .valid_modes_mask = REGULATOR_MODE_NORMAL,
666 .num_consumer_supplies = ARRAY_SIZE(ldo4_consumers),
667 .consumer_supplies = ldo4_consumers,
669 [PCF50633_REGULATOR_LDO5] = {
674 .valid_modes_mask = REGULATOR_MODE_NORMAL,
680 .num_consumer_supplies = ARRAY_SIZE(ldo5_consumers),
681 .consumer_supplies = ldo5_consumers,
683 [PCF50633_REGULATOR_LDO6] = {
689 .valid_modes_mask = REGULATOR_MODE_NORMAL,
692 .num_consumer_supplies = ARRAY_SIZE(ldo6_consumers),
693 .consumer_supplies = ldo6_consumers,
696 .probe_done = gta02_pmu_attach_child_devices,
697 .regulator_registered = gta02_pmu_regulator_registered,
698 .mbc_event_callback = gta02_pmu_event_callback,
699 .force_shutdown = gta02_pmu_force_shutdown,
704 #ifdef CONFIG_HDQ_GPIO_BITBANG
705 /* BQ27000 Battery */
707 struct bq27000_platform_data bq27000_pdata = {
710 .hdq_read = hdq_read,
711 .hdq_write = hdq_write,
712 .hdq_initialized = hdq_initialized,
713 .get_charger_online_status = gta02_get_charger_online_status,
714 .get_charger_active_status = gta02_get_charger_active_status
717 struct platform_device bq27000_battery_device = {
718 .name = "bq27000-battery",
720 .platform_data = &bq27000_pdata,
726 static void gta02_hdq_attach_child_devices(struct device *parent_device)
728 switch (S3C_SYSTEM_REV_ATAG) {
729 case GTA02v5_SYSTEM_REV:
730 case GTA02v6_SYSTEM_REV:
731 bq27000_battery_device.dev.parent = parent_device;
732 platform_device_register(&bq27000_battery_device);
739 static void gta02_hdq_gpio_direction_out(void)
741 s3c2410_gpio_cfgpin(GTA02v5_GPIO_HDQ, S3C2410_GPIO_OUTPUT);
744 static void gta02_hdq_gpio_direction_in(void)
746 s3c2410_gpio_cfgpin(GTA02v5_GPIO_HDQ, S3C2410_GPIO_INPUT);
749 static void gta02_hdq_gpio_set_value(int val)
752 s3c2410_gpio_setpin(GTA02v5_GPIO_HDQ, val);
755 static int gta02_hdq_gpio_get_value(void)
757 return s3c2410_gpio_getpin(GTA02v5_GPIO_HDQ);
760 static struct resource gta02_hdq_resources[] = {
762 .start = GTA02v5_GPIO_HDQ,
763 .end = GTA02v5_GPIO_HDQ,
767 struct hdq_platform_data gta02_hdq_platform_data = {
768 .attach_child_devices = gta02_hdq_attach_child_devices,
769 .gpio_dir_out = gta02_hdq_gpio_direction_out,
770 .gpio_dir_in = gta02_hdq_gpio_direction_in,
771 .gpio_set = gta02_hdq_gpio_set_value,
772 .gpio_get = gta02_hdq_gpio_get_value,
774 .enable_fiq = gta02_fiq_enable,
775 .disable_fiq = gta02_fiq_disable,
776 .kick_fiq = gta02_fiq_kick,
780 struct platform_device gta02_hdq_device = {
783 .resource = gta02_hdq_resources,
785 .platform_data = >a02_hdq_platform_data,
791 /* vibrator (child of FIQ) */
793 static struct resource gta02_vibrator_resources[] = {
795 .start = GTA02_GPIO_VIBRATOR_ON,
796 .end = GTA02_GPIO_VIBRATOR_ON,
799 struct gta02_vib_platform_data gta02_vib_pdata = {
800 .enable_fiq = gta02_fiq_enable,
801 .disable_fiq = gta02_fiq_disable,
802 .kick_fiq = gta02_fiq_kick,
805 static struct platform_device gta02_vibrator_dev = {
806 .name = "gta02-vibrator",
807 .num_resources = ARRAY_SIZE(gta02_vibrator_resources),
808 .resource = gta02_vibrator_resources,
810 .platform_data = >a02_vib_pdata,
816 #define GTA02_FLASH_BASE S3C2410_CS3 /* GCS3 */
817 #define GTA02_FLASH_SIZE 0x200000 /* 2MBytes */
819 static struct physmap_flash_data gta02_nor_flash_data = {
823 static struct resource gta02_nor_flash_resource = {
824 .start = GTA02_FLASH_BASE,
825 .end = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
826 .flags = IORESOURCE_MEM,
829 static struct platform_device gta02_nor_flash = {
830 .name = "physmap-flash",
833 .platform_data = >a02_nor_flash_data,
835 .resource = >a02_nor_flash_resource,
840 struct platform_device s3c24xx_pwm_device = {
841 .name = "s3c24xx_pwm",
845 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
847 I2C_BOARD_INFO("pcf50633", 0x73),
848 .irq = GTA02_IRQ_PCF50633,
849 .platform_data = >a02_pcf_pdata,
852 I2C_BOARD_INFO("wm8753", 0x1a),
856 static struct s3c2410_nand_set gta02_nand_sets[] = {
858 .name = "neo1973-nand",
860 .flags = S3C2410_NAND_BBT,
864 /* choose a set of timings derived from S3C@2442B MCP54
865 * data sheet (K5D2G13ACM-D075 MCP Memory)
868 static struct s3c2410_platform_nand gta02_nand_info = {
872 .nr_sets = ARRAY_SIZE(gta02_nand_sets),
873 .sets = gta02_nand_sets,
878 static void gta02_s3c_mmc_set_power(unsigned char power_mode,
881 static int is_on = -1;
884 on = power_mode == MMC_POWER_ON || power_mode == MMC_POWER_UP;
886 gta02_wlan_reset(!on);
891 static struct s3c24xx_mci_pdata gta02_s3c_mmc_cfg = {
892 .set_power = gta02_s3c_mmc_set_power,
895 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
898 case S3C2410_UDC_P_ENABLE:
899 printk(KERN_DEBUG "%s S3C2410_UDC_P_ENABLE\n", __func__);
900 s3c2410_gpio_setpin(GTA02_GPIO_USB_PULLUP, 1);
902 case S3C2410_UDC_P_DISABLE:
903 printk(KERN_DEBUG "%s S3C2410_UDC_P_DISABLE\n", __func__);
904 s3c2410_gpio_setpin(GTA02_GPIO_USB_PULLUP, 0);
906 case S3C2410_UDC_P_RESET:
907 printk(KERN_DEBUG "%s S3C2410_UDC_P_RESET\n", __func__);
915 /* get PMU to set USB current limit accordingly */
917 static struct s3c2410_udc_mach_info gta02_udc_cfg = {
918 .vbus_draw = gta02_udc_vbus_draw,
919 .udc_command = gta02_udc_command,
920 /* .get_vbus_status = gta02_udc_vbus_status,*/
924 /* Touchscreen configuration. */
926 #ifdef CONFIG_TOUCHSCREEN_FILTER
927 const static struct ts_filter_group_configuration gta02_ts_group = {
930 .threshold = 6, /* At least half of the points in a group. */
934 const static struct ts_filter_median_configuration gta02_ts_median = {
936 .decimation_below = 3,
937 .decimation_threshold = 8 * 3,
938 .decimation_above = 4,
941 const static struct ts_filter_mean_configuration gta02_ts_mean = {
945 const static struct ts_filter_linear_configuration gta02_ts_linear = {
946 .constants = {1, 0, 0, 0, 1, 0, 1}, /* Don't modify coords. */
952 const static struct ts_filter_chain_configuration gta02_filter_configuration[] =
954 #ifdef CONFIG_TOUCHSCREEN_FILTER
955 {&ts_filter_group_api, >a02_ts_group.config},
956 {&ts_filter_median_api, >a02_ts_median.config},
957 {&ts_filter_mean_api, >a02_ts_mean.config},
958 {&ts_filter_linear_api, >a02_ts_linear.config},
963 const static struct s3c2410_ts_mach_info gta02_ts_cfg = {
965 .presc = 0xff, /* slow as we can go */
966 .filter_config = gta02_filter_configuration,
971 static void gta02_bl_set_intensity(int intensity)
973 struct pcf50633 *pcf = gta02_pcf;
974 int old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT);
978 * One code path that leads here is from a kernel panic. Trying to turn
979 * the backlight on just gives us a nearly endless stream of complaints
980 * and accomplishes nothing. We can't win. Just give up.
982 * In the unlikely event that there's another path leading here while
983 * we're atomic, we print at least a warning.
987 "gta02_bl_set_intensity called while atomic\n");
991 if (!(pcf50633_reg_read(pcf, PCF50633_REG_LEDENA) & 3))
994 old_intensity = pcf50633_reg_read(pcf, PCF50633_REG_LEDOUT);
996 if (intensity == old_intensity)
999 /* We can't do this anywhere else */
1000 pcf50633_reg_write(pcf, PCF50633_REG_LEDDIM, 5);
1003 * The PCF50633 cannot handle LEDOUT = 0 (datasheet p60)
1004 * if seen, you have to re-enable the LED unit
1006 if (!intensity || !old_intensity)
1007 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0);
1009 if (!intensity) /* illegal to set LEDOUT to 0 */
1010 ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f,
1013 ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_LEDOUT, 0x3f,
1017 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 2);
1021 static struct generic_bl_info gta02_bl_info = {
1023 .max_intensity = 0x3f,
1024 .default_intensity = 0x3f,
1025 .set_bl_intensity = gta02_bl_set_intensity,
1028 static struct platform_device gta02_bl_dev = {
1029 .name = "generic-bl",
1032 .platform_data = >a02_bl_info,
1036 /* SPI: LCM control interface attached to Glamo3362 */
1038 static void gta02_jbt6k74_reset(int devidx, int level)
1040 gpio_set_value(GTA02_GPIO_GLAMO(4), level);
1043 static int jbt_probed = 0;
1045 static void gta02_jbt6k74_probe_completed(struct device *dev)
1047 struct pcf50633 *pcf = gta02_pcf;
1049 /* Switch on backlight. Qi does not do it for us */
1050 pcf50633_reg_write(pcf, PCF50633_REG_LEDOUT, 0x01);
1051 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0x00);
1052 pcf50633_reg_write(pcf, PCF50633_REG_LEDDIM, 0x01);
1053 pcf50633_reg_write(pcf, PCF50633_REG_LEDENA, 0x01);
1055 gta02_bl_dev.dev.parent = dev;
1056 platform_device_register(>a02_bl_dev);
1061 const struct jbt6k74_platform_data jbt6k74_pdata = {
1062 .reset = gta02_jbt6k74_reset,
1063 .probe_completed = gta02_jbt6k74_probe_completed,
1066 /*----------- SPI: Accelerometers attached to SPI of s3c244x ----------------- */
1068 void gta02_lis302dl_suspend_io(struct lis302dl_info *lis, int resume)
1070 struct lis302dl_platform_data *pdata = lis->pdata;
1074 * we don't want to power them with a high level
1075 * because GSENSOR_3V3 is not up during suspend
1077 s3c2410_gpio_setpin(pdata->pin_chip_select, 0);
1078 s3c2410_gpio_setpin(pdata->pin_clk, 0);
1079 s3c2410_gpio_setpin(pdata->pin_mosi, 0);
1080 /* misnomer: it is a pullDOWN in 2442 */
1081 s3c2410_gpio_pullup(pdata->pin_miso, 1);
1085 /* back to normal */
1086 s3c2410_gpio_setpin(pdata->pin_chip_select, 1);
1087 s3c2410_gpio_setpin(pdata->pin_clk, 1);
1088 /* misnomer: it is a pullDOWN in 2442 */
1089 s3c2410_gpio_pullup(pdata->pin_miso, 0);
1091 s3c2410_gpio_cfgpin(pdata->pin_chip_select, S3C2410_GPIO_OUTPUT);
1092 s3c2410_gpio_cfgpin(pdata->pin_clk, S3C2410_GPIO_OUTPUT);
1093 s3c2410_gpio_cfgpin(pdata->pin_mosi, S3C2410_GPIO_OUTPUT);
1094 s3c2410_gpio_cfgpin(pdata->pin_miso, S3C2410_GPIO_INPUT);
1098 struct lis302dl_platform_data lis302_pdata_top = {
1099 .name = "lis302-1 (top)",
1100 .pin_chip_select= S3C2410_GPD(12),
1101 .pin_clk = S3C2410_GPG(7),
1102 .pin_mosi = S3C2410_GPG(6),
1103 .pin_miso = S3C2410_GPG(5),
1104 .interrupt = GTA02_IRQ_GSENSOR_1,
1105 .open_drain = 1, /* altered at runtime by PCB rev */
1106 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
1109 struct lis302dl_platform_data lis302_pdata_bottom = {
1110 .name = "lis302-2 (bottom)",
1111 .pin_chip_select= S3C2410_GPD(13),
1112 .pin_clk = S3C2410_GPG(7),
1113 .pin_mosi = S3C2410_GPG(6),
1114 .pin_miso = S3C2410_GPG(5),
1115 .interrupt = GTA02_IRQ_GSENSOR_2,
1116 .open_drain = 1, /* altered at runtime by PCB rev */
1117 .lis302dl_suspend_io = gta02_lis302dl_suspend_io,
1120 static struct spi_board_info gta02_spi_board_info[] = {
1122 .modalias = "jbt6k74",
1123 .platform_data = &jbt6k74_pdata,
1124 .controller_data = (void*)GTA02_GPIO_GLAMO(12),
1126 .max_speed_hz = 100 * 1000,
1131 .modalias = "lis302dl",
1133 .platform_data = &lis302_pdata_top,
1134 /* controller_data */
1136 .max_speed_hz = 100 * 1000,
1142 .modalias = "lis302dl",
1144 .platform_data = &lis302_pdata_bottom,
1145 /* controller_data */
1147 .max_speed_hz = 100 * 1000,
1154 static void gta02_lis302_chip_select(struct s3c2410_spigpio_info *info, int csid, int cs)
1158 * Huh... "quirk"... CS on this device is not really "CS" like you can
1161 * When it is 0 it selects SPI interface mode.
1162 * When it is 1 it selects I2C interface mode.
1164 * Because we have 2 devices on one interface we have to make sure
1165 * that the "disabled" device (actually in I2C mode) don't think we're
1168 * When we talk to the "enabled" device, the "disabled" device sees
1169 * the clocks as I2C clocks, creating havoc.
1171 * I2C sees MOSI going LOW while CLK HIGH as a START action, thus we
1172 * must ensure this is never issued.
1175 int cs_gpio, other_cs_gpio;
1177 cs_gpio = csid ? S3C2410_GPD(13) : S3C2410_GPD(12);
1178 other_cs_gpio = csid ? S3C2410_GPD(12) : S3C2410_GPD(13);
1181 if (cs == BITBANG_CS_ACTIVE) {
1182 s3c2410_gpio_setpin(other_cs_gpio, 1);
1183 s3c2410_gpio_setpin(cs_gpio, 1);
1184 s3c2410_gpio_setpin(info->pin_clk, 1);
1185 s3c2410_gpio_setpin(cs_gpio, 0);
1187 s3c2410_gpio_setpin(cs_gpio, 1);
1188 s3c2410_gpio_setpin(other_cs_gpio, 1);
1192 static struct s3c2410_spigpio_info gta02_spigpio_cfg = {
1193 .pin_clk = S3C2410_GPG(7),
1194 .pin_mosi = S3C2410_GPG(6),
1195 .pin_miso = S3C2410_GPG(5),
1197 .num_chipselect = 2,
1198 .chip_select = gta02_lis302_chip_select,
1201 static struct platform_device gta02_spi_gpio_dev = {
1202 .name = "spi_s3c24xx_gpio",
1204 .platform_data = >a02_spigpio_cfg,
1208 /*----------- / SPI: Accelerometers attached to SPI of s3c244x ----------------- */
1210 static struct gpio_led gta02_gpio_leds[] = {
1212 .name = "gta02-power:orange",
1213 .gpio = GTA02_GPIO_PWR_LED1,
1215 .name = "gta02-power:blue",
1216 .gpio = GTA02_GPIO_PWR_LED2,
1218 .name = "gta02-aux:red",
1219 .gpio = GTA02_GPIO_AUX_LED,
1223 static struct gpio_led_platform_data gta02_gpio_leds_pdata = {
1224 .leds = gta02_gpio_leds,
1225 .num_leds = ARRAY_SIZE(gta02_gpio_leds),
1228 struct platform_device gta02_led_dev = {
1229 .name = "leds-gpio",
1232 .platform_data = >a02_gpio_leds_pdata,
1236 static struct gpio_keys_button gta02_buttons[] = {
1238 .gpio = GTA02_GPIO_AUX_KEY,
1242 .debounce_interval = 100,
1245 .gpio = GTA02_GPIO_HOLD_KEY,
1249 .debounce_interval = 100,
1253 static struct gpio_keys_platform_data gta02_buttons_pdata = {
1254 .buttons = gta02_buttons,
1255 .nbuttons = ARRAY_SIZE(gta02_buttons),
1258 static struct platform_device gta02_button_dev = {
1259 .name = "gpio-keys",
1262 .platform_data = >a02_buttons_pdata,
1266 static struct platform_device gta02_pm_usbhost_dev = {
1267 .name = "gta02-pm-host",
1271 static struct s3c2410_hcd_info gta02_usb_info = {
1273 .flags = S3C_HCDFLG_USED,
1281 * we crank down SD Card clock dynamically when GPS is powered
1284 static int gta02_glamo_mci_use_slow(void)
1286 return gta02_pm_gps_is_on();
1289 static void gta02_glamo_external_reset(int level)
1291 s3c2410_gpio_setpin(GTA02_GPIO_3D_RESET, level);
1292 s3c2410_gpio_cfgpin(GTA02_GPIO_3D_RESET, S3C2410_GPIO_OUTPUT);
1296 static struct fb_videomode gta02_glamo_modes[] = {
1308 .vmode = FB_VMODE_NONINTERLACED,
1320 .vmode = FB_VMODE_NONINTERLACED,
1324 struct spi_gpio_platform_data spigpio_platform_data = {
1325 .sck = GTA02_GPIO_GLAMO(10),
1326 .mosi = GTA02_GPIO_GLAMO(11),
1327 .miso = GTA02_GPIO_GLAMO(5),
1328 .num_chipselect = 1,
1331 static struct platform_device spigpio_device = {
1335 .platform_data = &spigpio_platform_data,
1339 static void gta02_glamo_registered(struct device *dev)
1341 if (gpio_request(GTA02_GPIO_GLAMO(4), "jbt6k74 reset"))
1342 printk("gta02: Failed to request jbt6k74 reset pin\n");
1343 if (gpio_direction_output(GTA02_GPIO_GLAMO(4), 1))
1344 printk("gta02: Failed to configure jbt6k74 reset pin\n");
1345 spigpio_device.dev.parent = dev;
1346 platform_device_register(&spigpio_device);
1349 static struct fb_videomode gta02_glamo_modes[] = {
1361 .vmode = FB_VMODE_NONINTERLACED,
1373 .vmode = FB_VMODE_NONINTERLACED,
1378 static struct glamo_fb_platform_data gta02_glamo_fb_pdata = {
1382 .num_modes = ARRAY_SIZE(gta02_glamo_modes),
1383 .modes = gta02_glamo_modes,
1386 static struct glamo_mmc_platform_data gta02_glamo_mmc_pdata = {
1387 .glamo_mmc_use_slow = gta02_glamo_mci_use_slow,
1390 static struct glamo_platform_data gta02_glamo_pdata = {
1391 .fb_data = >a02_glamo_fb_pdata,
1392 .mmc_data = >a02_glamo_mmc_pdata,
1393 .gpio_base = GTA02_GPIO_GLAMO_BASE,
1395 .osci_clock_rate = 32768,
1397 .glamo_external_reset = gta02_glamo_external_reset,
1398 .registered = gta02_glamo_registered,
1401 static struct resource gta02_glamo_resources[] = {
1403 .start = S3C2410_CS1,
1404 .end = S3C2410_CS1 + 0x1000000 - 1,
1405 .flags = IORESOURCE_MEM,
1408 .start = GTA02_IRQ_3D,
1409 .end = GTA02_IRQ_3D,
1410 .flags = IORESOURCE_IRQ,
1413 .start = GTA02_GPIO_3D_RESET,
1414 .end = GTA02_GPIO_3D_RESET,
1418 static struct platform_device gta02_glamo_dev = {
1419 .name = "glamo3362",
1420 .num_resources = ARRAY_SIZE(gta02_glamo_resources),
1421 .resource = gta02_glamo_resources,
1423 .platform_data = >a02_glamo_pdata,
1427 static void __init gta02_map_io(void)
1429 s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
1430 s3c24xx_init_clocks(12000000);
1431 s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
1434 static irqreturn_t gta02_modem_irq(int irq, void *param)
1436 /* printk(KERN_DEBUG "modem wakeup interrupt\n");*/
1437 gta_gsm_interrupts++;
1441 static irqreturn_t ar6000_wow_irq(int irq, void *param)
1443 /* printk(KERN_DEBUG "ar6000_wow interrupt\n");*/
1450 static char hardware_ecc_str[4] __initdata = "";
1452 static int __init hardware_ecc_setup(char *str)
1455 strlcpy(hardware_ecc_str, str, sizeof(hardware_ecc_str));
1459 __setup("hardware_ecc=", hardware_ecc_setup);
1461 /* these are the guys that don't need to be children of PMU */
1463 static struct platform_device *gta02_devices[] __initdata = {
1468 &s3c_device_usbgadget,
1472 &s3c24xx_pwm_device,
1474 >a02_pm_wlan_dev, /* not dependent on PMU */
1478 /* these guys DO need to be children of PMU */
1480 static struct platform_device *gta02_devices_pmu_children[] = {
1481 &s3c_device_ts, /* input 1 */
1483 >a02_pm_usbhost_dev,
1484 >a02_spi_gpio_dev, /* input 2 and 3 */
1485 >a02_button_dev, /* input 4 */
1486 >a02_resume_reason_device,
1489 static void gta02_register_glamo(void)
1491 platform_device_register(>a02_glamo_dev);
1494 static void gta02_pmu_regulator_registered(struct pcf50633 *pcf, int id)
1496 struct platform_device *regulator, *pdev;
1500 regulator = pcf->regulator_pdev[id];
1503 case PCF50633_REGULATOR_LDO4:
1504 pdev = >a02_pm_bt_dev;
1506 case PCF50633_REGULATOR_LDO5:
1507 pdev = >a02_pm_gps_dev;
1509 case PCF50633_REGULATOR_HCLDO:
1510 gta02_register_glamo();
1516 pdev->dev.parent = ®ulator->dev;
1517 platform_device_register(pdev);
1520 /* this is called when pc50633 is probed, unfortunately quite late in the
1521 * day since it is an I2C bus device. Here we can belatedly define some
1522 * platform devices with the advantage that we can mark the pcf50633 as the
1523 * parent. This makes them get suspended and resumed with their parent
1524 * the pcf50633 still around.
1527 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
1531 for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
1532 gta02_devices_pmu_children[n]->dev.parent = pcf->dev;
1534 platform_add_devices(gta02_devices_pmu_children,
1535 ARRAY_SIZE(gta02_devices_pmu_children));
1537 regulator_has_full_constraints();
1540 static void gta02_poweroff(void)
1542 pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN,
1543 PCF50633_OOCSHDWN_GOSTDBY, PCF50633_OOCSHDWN_GOSTDBY);
1547 /* On hardware rev 5 and earlier the leds are missing a resistor and reading
1548 * from their gpio pins will always return 0, so we have to shadow the
1549 * led states software */
1550 static unsigned long gpb_shadow;
1551 extern struct s3c_gpio_chip s3c24xx_gpios[];
1553 static void gta02_gpb_set(struct gpio_chip *chip,
1554 unsigned offset, int value)
1556 void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
1557 unsigned long flags;
1560 local_irq_save(flags);
1562 dat = __raw_readl(base + 0x04) | gpb_shadow;
1563 dat &= ~(1 << offset);
1564 gpb_shadow &= ~(1 << offset);
1569 gpb_shadow |= 1 << offset;
1575 __raw_writel(dat, base + 0x04);
1577 local_irq_restore(flags);
1580 static int gta02_gpb_get(struct gpio_chip *chip, unsigned offset)
1582 void __iomem *base = S3C24XX_GPIO_BASE(S3C2410_GPB(0));
1585 val = __raw_readl(base + 0x04) | gpb_shadow;
1592 static void gta02_hijack_gpb(void) {
1593 s3c24xx_gpios[1].chip.set = gta02_gpb_set;
1594 s3c24xx_gpios[1].chip.get = gta02_gpb_get;
1597 static void __init gta02_machine_init(void)
1601 /* set the panic callback to make AUX blink fast */
1602 panic_blink = gta02_panic_blink;
1604 switch (S3C_SYSTEM_REV_ATAG) {
1605 case GTA02v6_SYSTEM_REV:
1606 /* we need push-pull interrupt from motion sensors */
1607 lis302_pdata_top.open_drain = 0;
1608 lis302_pdata_bottom.open_drain = 0;
1613 if (S3C_SYSTEM_REV_ATAG <= GTA02v5_SYSTEM_REV)
1616 #ifdef CONFIG_CHARGER_PCF50633
1617 INIT_DELAYED_WORK(>a02_charger_work, gta02_charger_worker);
1620 /* Glamo chip select optimization */
1621 /* *((u32 *)(S3C2410_MEMREG(((1 + 1) << 2)))) = 0x1280; */
1623 /* do not force soft ecc if we are asked to use hardware_ecc */
1624 if (hardware_ecc_str[0] == '1')
1625 gta02_nand_info.software_ecc = 0;
1627 s3c_device_usb.dev.platform_data = >a02_usb_info;
1628 s3c_device_nand.dev.platform_data = >a02_nand_info;
1629 s3c_device_sdi.dev.platform_data = >a02_s3c_mmc_cfg;
1631 /* acc sensor chip selects */
1632 s3c2410_gpio_setpin(S3C2410_GPD(12), 1);
1633 s3c2410_gpio_cfgpin(S3C2410_GPD(12), S3C2410_GPIO_OUTPUT);
1634 s3c2410_gpio_setpin(S3C2410_GPD(13), 1);
1635 s3c2410_gpio_cfgpin(S3C2410_GPD(13), S3C2410_GPIO_OUTPUT);
1638 s3c24xx_udc_set_platdata(>a02_udc_cfg);
1639 s3c_i2c0_set_platdata(NULL);
1640 set_s3c2410ts_info(>a02_ts_cfg);
1642 i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
1643 spi_register_board_info(gta02_spi_board_info,
1644 ARRAY_SIZE(gta02_spi_board_info));
1646 platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
1650 /* Make sure the modem can wake us up */
1651 set_irq_type(GTA02_IRQ_MODEM, IRQ_TYPE_EDGE_RISING);
1652 rc = request_irq(GTA02_IRQ_MODEM, gta02_modem_irq, IRQF_DISABLED,
1655 printk(KERN_ERR "GTA02: can't request GSM modem wakeup IRQ\n");
1656 enable_irq_wake(GTA02_IRQ_MODEM);
1658 /* Make sure the wifi module can wake us up*/
1659 set_irq_type(GTA02_IRQ_WLAN_GPIO1, IRQ_TYPE_EDGE_RISING);
1660 rc = request_irq(GTA02_IRQ_WLAN_GPIO1, ar6000_wow_irq, IRQF_DISABLED,
1664 printk(KERN_ERR "GTA02: can't request ar6k wakeup IRQ\n");
1665 enable_irq_wake(GTA02_IRQ_WLAN_GPIO1);
1667 pm_power_off = gta02_poweroff;
1669 /* Register the HDQ and vibrator as children of pwm device */
1670 #ifdef CONFIG_HDQ_GPIO_BITBANG
1671 gta02_hdq_device.dev.parent = &s3c24xx_pwm_device.dev;
1672 platform_device_register(>a02_hdq_device);
1674 gta02_vibrator_dev.dev.parent = &s3c24xx_pwm_device.dev;
1675 platform_device_register(>a02_vibrator_dev);
1678 MACHINE_START(NEO1973_GTA02, "GTA02")
1679 .phys_io = S3C2410_PA_UART,
1680 .io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
1681 .boot_params = S3C2410_SDRAM_PA + 0x100,
1682 .map_io = gta02_map_io,
1683 .init_irq = s3c24xx_init_irq,
1684 .init_machine = gta02_machine_init,
1685 .timer = &s3c24xx_timer,