2 * linux/arch/arm/mach-s3c2442/mach-gta02.c
4 * S3C2442 Machine Support for Openmoko GTA02 / FreeRunner.
6 * Copyright (C) 2006-2009 by Openmoko, Inc.
7 * Authors: Harald Welte <laforge@openmoko.org>
8 * Andy Green <andy@openmoko.org>
9 * Werner Almesberger <werner@openmoko.org>
10 * All rights reserved.
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/interrupt.h>
32 #include <linux/list.h>
33 #include <linux/delay.h>
34 #include <linux/timer.h>
35 #include <linux/init.h>
36 #include <linux/gpio.h>
37 #include <linux/workqueue.h>
38 #include <linux/platform_device.h>
39 #include <linux/serial_core.h>
40 #include <linux/spi/spi.h>
42 #include <linux/mmc/host.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>
51 #include <linux/i2c.h>
52 #include <linux/backlight.h>
53 #include <linux/regulator/machine.h>
55 #include <linux/mfd/pcf50633/core.h>
56 #include <linux/mfd/pcf50633/mbc.h>
57 #include <linux/mfd/pcf50633/adc.h>
58 #include <linux/mfd/pcf50633/gpio.h>
59 #include <linux/mfd/pcf50633/pmic.h>
61 #include <asm/mach/arch.h>
62 #include <asm/mach/map.h>
63 #include <asm/mach/irq.h>
66 #include <asm/mach-types.h>
68 #include <mach/regs-irq.h>
69 #include <mach/regs-gpio.h>
70 #include <mach/regs-gpioj.h>
74 #include <mach/spi-gpio.h>
75 #include <plat/usb-control.h>
76 #include <mach/regs-mem.h>
77 #include <mach/hardware.h>
79 #include <mach/gta02.h>
81 #include <plat/regs-serial.h>
82 #include <plat/nand.h>
83 #include <plat/devs.h>
87 #include <plat/gpio-cfg.h>
90 static struct pcf50633
*gta02_pcf
;
93 * This gets called every 1ms when we paniced.
96 static long gta02_panic_blink(long count
)
99 static long last_blink
;
102 /* Fast blink: 200ms period. */
103 if (count
- last_blink
< 100)
107 gpio_direction_output(GTA02_GPIO_AUX_LED
, led
);
115 static struct map_desc gta02_iodesc
[] __initdata
= {
117 .virtual = 0xe0000000,
118 .pfn
= __phys_to_pfn(S3C2410_CS3
+ 0x01000000),
124 #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
125 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
126 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
128 static struct s3c2410_uartcfg gta02_uartcfgs
[] = {
152 #ifdef CONFIG_CHARGER_PCF50633
154 * On GTA02 the 1A charger features a 48K resistor to 0V on the ID pin.
155 * We use this to recognize that we can pull 1A from the USB socket.
157 * These constants are the measured pcf50633 ADC levels with the 1A
158 * charger / 48K resistor, and with no pulldown resistor.
161 #define ADC_NOM_CHG_DETECT_1A 6
162 #define ADC_NOM_CHG_DETECT_USB 43
165 gta02_configure_pmu_for_charger(struct pcf50633
*pcf
, void *unused
, int res
)
169 /* Interpret charger type */
170 if (res
< ((ADC_NOM_CHG_DETECT_USB
+ ADC_NOM_CHG_DETECT_1A
) / 2)) {
173 * Sanity - stop GPO driving out now that we have a 1A charger
174 * GPO controls USB Host power generation on GTA02
176 pcf50633_gpio_set(pcf
, PCF50633_GPO
, 0);
182 pcf50633_mbc_usb_curlim_set(pcf
, ma
);
185 static struct delayed_work gta02_charger_work
;
186 static int gta02_usb_vbus_draw
;
188 static void gta02_charger_worker(struct work_struct
*work
)
190 if (gta02_usb_vbus_draw
) {
191 pcf50633_mbc_usb_curlim_set(gta02_pcf
, gta02_usb_vbus_draw
);
195 #ifdef CONFIG_PCF50633_ADC
196 pcf50633_adc_async_read(gta02_pcf
,
197 PCF50633_ADCC1_MUX_ADCIN1
,
198 PCF50633_ADCC1_AVERAGE_16
,
199 gta02_configure_pmu_for_charger
,
203 * If the PCF50633 ADC is disabled we fallback to a
204 * 100mA limit for safety.
206 pcf50633_mbc_usb_curlim_set(pcf
, 100);
210 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
212 static void gta02_pmu_event_callback(struct pcf50633
*pcf
, int irq
)
214 if (irq
== PCF50633_IRQ_USBINS
) {
215 schedule_delayed_work(>a02_charger_work
,
216 GTA02_CHARGER_CONFIGURE_TIMEOUT
);
221 if (irq
== PCF50633_IRQ_USBREM
) {
222 cancel_delayed_work_sync(>a02_charger_work
);
223 gta02_usb_vbus_draw
= 0;
227 static void gta02_udc_vbus_draw(unsigned int ma
)
232 gta02_usb_vbus_draw
= ma
;
234 schedule_delayed_work(>a02_charger_work
,
235 GTA02_CHARGER_CONFIGURE_TIMEOUT
);
237 #else /* !CONFIG_CHARGER_PCF50633 */
238 #define gta02_pmu_event_callback NULL
239 #define gta02_udc_vbus_draw NULL
243 * This is called when pc50633 is probed, unfortunately quite late in the
244 * day since it is an I2C bus device. Here we can belatedly define some
245 * platform devices with the advantage that we can mark the pcf50633 as the
246 * parent. This makes them get suspended and resumed with their parent
247 * the pcf50633 still around.
250 static void gta02_pmu_attach_child_devices(struct pcf50633
*pcf
);
253 static char *gta02_batteries
[] = {
257 struct pcf50633_platform_data gta02_pcf_pdata
= {
259 [0] = PCF50633_INT1_USBINS
|
260 PCF50633_INT1_USBREM
|
262 [1] = PCF50633_INT2_ONKEYF
,
263 [2] = PCF50633_INT3_ONKEY1S
,
264 [3] = PCF50633_INT4_LOWSYS
|
265 PCF50633_INT4_LOWBAT
|
266 PCF50633_INT4_HIGHTMP
,
269 .batteries
= gta02_batteries
,
270 .num_batteries
= ARRAY_SIZE(gta02_batteries
),
272 [PCF50633_REGULATOR_AUTO
] = {
276 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
284 [PCF50633_REGULATOR_DOWN1
] = {
288 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
293 [PCF50633_REGULATOR_DOWN2
] = {
297 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
305 [PCF50633_REGULATOR_HCLDO
] = {
309 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
310 .valid_ops_mask
= REGULATOR_CHANGE_VOLTAGE
,
314 [PCF50633_REGULATOR_LDO1
] = {
318 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
325 [PCF50633_REGULATOR_LDO2
] = {
329 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
333 [PCF50633_REGULATOR_LDO3
] = {
337 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
341 [PCF50633_REGULATOR_LDO4
] = {
345 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
349 [PCF50633_REGULATOR_LDO5
] = {
353 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
360 [PCF50633_REGULATOR_LDO6
] = {
364 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
367 [PCF50633_REGULATOR_MEMLDO
] = {
371 .valid_modes_mask
= REGULATOR_MODE_NORMAL
,
379 .probe_done
= gta02_pmu_attach_child_devices
,
380 .mbc_event_callback
= gta02_pmu_event_callback
,
386 #define GTA02_FLASH_BASE 0x18000000 /* GCS3 */
387 #define GTA02_FLASH_SIZE 0x200000 /* 2MBytes */
389 static struct physmap_flash_data gta02_nor_flash_data
= {
393 static struct resource gta02_nor_flash_resource
= {
394 .start
= GTA02_FLASH_BASE
,
395 .end
= GTA02_FLASH_BASE
+ GTA02_FLASH_SIZE
- 1,
396 .flags
= IORESOURCE_MEM
,
399 static struct platform_device gta02_nor_flash
= {
400 .name
= "physmap-flash",
403 .platform_data
= >a02_nor_flash_data
,
405 .resource
= >a02_nor_flash_resource
,
410 struct platform_device s3c24xx_pwm_device
= {
411 .name
= "s3c24xx_pwm",
415 static struct i2c_board_info gta02_i2c_devs
[] __initdata
= {
417 I2C_BOARD_INFO("pcf50633", 0x73),
418 .irq
= GTA02_IRQ_PCF50633
,
419 .platform_data
= >a02_pcf_pdata
,
422 I2C_BOARD_INFO("wm8753", 0x1a),
426 static struct s3c2410_nand_set gta02_nand_sets
[] = {
429 * This name is also hard-coded in the boot loaders, so
430 * changing it would would require all users to upgrade
431 * their boot loaders, some of which are stored in a NOR
432 * that is considered to be immutable.
434 .name
= "neo1973-nand",
441 * Choose a set of timings derived from S3C@2442B MCP54
442 * data sheet (K5D2G13ACM-D075 MCP Memory).
445 static struct s3c2410_platform_nand gta02_nand_info
= {
449 .nr_sets
= ARRAY_SIZE(gta02_nand_sets
),
450 .sets
= gta02_nand_sets
,
454 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd
)
457 case S3C2410_UDC_P_ENABLE
:
458 pr_debug("%s S3C2410_UDC_P_ENABLE\n", __func__
);
459 gpio_direction_output(GTA02_GPIO_USB_PULLUP
, 1);
461 case S3C2410_UDC_P_DISABLE
:
462 pr_debug("%s S3C2410_UDC_P_DISABLE\n", __func__
);
463 gpio_direction_output(GTA02_GPIO_USB_PULLUP
, 0);
465 case S3C2410_UDC_P_RESET
:
466 pr_debug("%s S3C2410_UDC_P_RESET\n", __func__
);
467 /* FIXME: Do something here. */
471 /* Get PMU to set USB current limit accordingly. */
472 static struct s3c2410_udc_mach_info gta02_udc_cfg
= {
473 .vbus_draw
= gta02_udc_vbus_draw
,
474 .udc_command
= gta02_udc_command
,
480 static void gta02_bl_set_intensity(int intensity
)
482 struct pcf50633
*pcf
= gta02_pcf
;
483 int old_intensity
= pcf50633_reg_read(pcf
, PCF50633_REG_LEDOUT
);
485 /* We map 8-bit intensity to 6-bit intensity in hardware. */
489 * This can happen during, eg, print of panic on blanked console,
490 * but we can't service i2c without interrupts active, so abort.
493 printk(KERN_ERR
"gta02_bl_set_intensity called while atomic\n");
497 old_intensity
= pcf50633_reg_read(pcf
, PCF50633_REG_LEDOUT
);
498 if (intensity
== old_intensity
)
501 /* We can't do this anywhere else. */
502 pcf50633_reg_write(pcf
, PCF50633_REG_LEDDIM
, 5);
504 if (!(pcf50633_reg_read(pcf
, PCF50633_REG_LEDENA
) & 3))
508 * The PCF50633 cannot handle LEDOUT = 0 (datasheet p60)
509 * if seen, you have to re-enable the LED unit.
511 if (!intensity
|| !old_intensity
)
512 pcf50633_reg_write(pcf
, PCF50633_REG_LEDENA
, 0);
514 /* Illegal to set LEDOUT to 0. */
516 pcf50633_reg_set_bit_mask(pcf
, PCF50633_REG_LEDOUT
, 0x3f, 2);
518 pcf50633_reg_set_bit_mask(pcf
, PCF50633_REG_LEDOUT
, 0x3f,
522 pcf50633_reg_write(pcf
, PCF50633_REG_LEDENA
, 2);
526 static struct generic_bl_info gta02_bl_info
= {
528 .max_intensity
= 0xff,
529 .default_intensity
= 0xff,
530 .set_bl_intensity
= gta02_bl_set_intensity
,
533 static struct platform_device gta02_bl_dev
= {
534 .name
= "generic-bl",
537 .platform_data
= >a02_bl_info
,
544 static struct s3c2410_hcd_info gta02_usb_info
= {
546 .flags
= S3C_HCDFLG_USED
,
554 static void __init
gta02_map_io(void)
556 s3c24xx_init_io(gta02_iodesc
, ARRAY_SIZE(gta02_iodesc
));
557 s3c24xx_init_clocks(12000000);
558 s3c24xx_init_uarts(gta02_uartcfgs
, ARRAY_SIZE(gta02_uartcfgs
));
562 /* These are the guys that don't need to be children of PMU. */
564 static struct platform_device
*gta02_devices
[] __initdata
= {
568 &s3c_device_usbgadget
,
576 /* These guys DO need to be children of PMU. */
578 static struct platform_device
*gta02_devices_pmu_children
[] = {
584 * This is called when pc50633 is probed, quite late in the day since it is an
585 * I2C bus device. Here we can define platform devices with the advantage that
586 * we can mark the pcf50633 as the parent. This makes them get suspended and
587 * resumed with their parent the pcf50633 still around. All devices whose
588 * operation depends on something from pcf50633 must have this relationship
589 * made explicit like this, or suspend and resume will become an unreliable
593 static void gta02_pmu_attach_child_devices(struct pcf50633
*pcf
)
597 /* Grab a copy of the now probed PMU pointer. */
600 for (n
= 0; n
< ARRAY_SIZE(gta02_devices_pmu_children
); n
++)
601 gta02_devices_pmu_children
[n
]->dev
.parent
= pcf
->dev
;
603 platform_add_devices(gta02_devices_pmu_children
,
604 ARRAY_SIZE(gta02_devices_pmu_children
));
607 static void gta02_poweroff(void)
609 pcf50633_reg_set_bit_mask(gta02_pcf
, PCF50633_REG_OOCSHDWN
, 1, 1);
612 static void __init
gta02_machine_init(void)
614 /* Set the panic callback to make AUX LED blink at ~5Hz. */
615 panic_blink
= gta02_panic_blink
;
619 #ifdef CONFIG_CHARGER_PCF50633
620 INIT_DELAYED_WORK(>a02_charger_work
, gta02_charger_worker
);
623 s3c_device_usb
.dev
.platform_data
= >a02_usb_info
;
624 s3c_device_nand
.dev
.platform_data
= >a02_nand_info
;
626 s3c24xx_udc_set_platdata(>a02_udc_cfg
);
627 s3c_i2c0_set_platdata(NULL
);
629 i2c_register_board_info(0, gta02_i2c_devs
, ARRAY_SIZE(gta02_i2c_devs
));
631 platform_add_devices(gta02_devices
, ARRAY_SIZE(gta02_devices
));
632 pm_power_off
= gta02_poweroff
;
636 MACHINE_START(NEO1973_GTA02
, "GTA02")
637 /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
638 .phys_io
= S3C2410_PA_UART
,
639 .io_pg_offst
= (((u32
)S3C24XX_VA_UART
) >> 18) & 0xfffc,
640 .boot_params
= S3C2410_SDRAM_PA
+ 0x100,
641 .map_io
= gta02_map_io
,
642 .init_irq
= s3c24xx_init_irq
,
643 .init_machine
= gta02_machine_init
,
644 .timer
= &s3c24xx_timer
,