1 /* linux/arch/arm/mach-s3c2410/mach-h1940.c
3 * Copyright (c) 2003-2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * http://www.handhelds.org/projects/h1940.html
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/interrupt.h>
17 #include <linux/list.h>
18 #include <linux/memblock.h>
19 #include <linux/timer.h>
20 #include <linux/init.h>
21 #include <linux/sysdev.h>
22 #include <linux/serial_core.h>
23 #include <linux/platform_device.h>
25 #include <linux/gpio.h>
26 #include <linux/input.h>
27 #include <linux/gpio_keys.h>
28 #include <linux/pwm_backlight.h>
29 #include <linux/i2c.h>
30 #include <linux/leds.h>
32 #include <video/platform_lcd.h>
34 #include <linux/mmc/host.h>
36 #include <asm/mach/arch.h>
37 #include <asm/mach/map.h>
38 #include <asm/mach/irq.h>
40 #include <mach/hardware.h>
42 #include <asm/mach-types.h>
44 #include <plat/regs-serial.h>
45 #include <mach/regs-lcd.h>
46 #include <mach/regs-clock.h>
48 #include <mach/regs-gpio.h>
49 #include <mach/gpio-fns.h>
50 #include <mach/gpio-nrs.h>
52 #include <mach/h1940.h>
53 #include <mach/h1940-latch.h>
58 #include <plat/gpio-cfg.h>
59 #include <plat/clock.h>
60 #include <plat/devs.h>
67 #include <sound/uda1380.h>
69 #define H1940_LATCH ((void __force __iomem *)0xF8000000)
71 #define H1940_PA_LATCH S3C2410_CS2
73 #define H1940_LATCH_BIT(x) (1 << ((x) + 16 - S3C_GPIO_END))
75 static struct map_desc h1940_iodesc[] __initdata = {
77 .virtual = (unsigned long)H1940_LATCH,
78 .pfn = __phys_to_pfn(H1940_PA_LATCH),
84 #define UCON S3C2410_UCON_DEFAULT | S3C2410_UCON_UCLK
85 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
86 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
88 static struct s3c2410_uartcfg h1940_uartcfgs[] __initdata = {
107 .uart_flags = UPF_CONS_FLOW,
114 /* Board control latch control */
116 static unsigned int latch_state;
118 static void h1940_latch_control(unsigned int clear, unsigned int set)
122 local_irq_save(flags);
124 latch_state &= ~clear;
127 __raw_writel(latch_state, H1940_LATCH);
129 local_irq_restore(flags);
132 static inline int h1940_gpiolib_to_latch(int offset)
134 return 1 << (offset + 16);
137 static void h1940_gpiolib_latch_set(struct gpio_chip *chip,
138 unsigned offset, int value)
140 int latch_bit = h1940_gpiolib_to_latch(offset);
142 h1940_latch_control(value ? 0 : latch_bit,
143 value ? latch_bit : 0);
146 static int h1940_gpiolib_latch_output(struct gpio_chip *chip,
147 unsigned offset, int value)
149 h1940_gpiolib_latch_set(chip, offset, value);
153 static int h1940_gpiolib_latch_get(struct gpio_chip *chip,
156 return (latch_state >> (offset + 16)) & 1;
159 struct gpio_chip h1940_latch_gpiochip = {
160 .base = H1940_LATCH_GPIO(0),
161 .owner = THIS_MODULE,
162 .label = "H1940_LATCH",
164 .direction_output = h1940_gpiolib_latch_output,
165 .set = h1940_gpiolib_latch_set,
166 .get = h1940_gpiolib_latch_get,
169 static struct s3c2410_udc_mach_info h1940_udc_cfg __initdata = {
170 .vbus_pin = S3C2410_GPG(5),
171 .vbus_pin_inverted = 1,
172 .pullup_pin = H1940_LATCH_USB_DP,
175 static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
178 .oversampling_shift = 2,
179 .cfg_gpio = s3c24xx_ts_cfg_gpio,
185 static struct s3c2410fb_display h1940_lcd __initdata = {
186 .lcdcon5= S3C2410_LCDCON5_FRM565 | \
187 S3C2410_LCDCON5_INVVLINE | \
188 S3C2410_LCDCON5_HWSWP,
190 .type = S3C2410_LCDCON1_TFT,
205 static struct s3c2410fb_mach_info h1940_fb_info __initdata = {
206 .displays = &h1940_lcd,
208 .default_display = 0,
212 .gpccon_mask= 0xffffffff,
214 .gpcup_mask= 0xffffffff,
216 .gpdcon_mask= 0xffffffff,
218 .gpdup_mask= 0xffffffff,
221 DEFINE_SPINLOCK(h1940_blink_spin);
223 int h1940_led_blink_set(unsigned gpio, int state,
224 unsigned long *delay_on, unsigned long *delay_off)
226 int blink_gpio, check_gpio1, check_gpio2;
229 case H1940_LATCH_LED_GREEN:
230 blink_gpio = S3C2410_GPA(7);
231 check_gpio1 = S3C2410_GPA(1);
232 check_gpio2 = S3C2410_GPA(3);
234 case H1940_LATCH_LED_RED:
235 blink_gpio = S3C2410_GPA(1);
236 check_gpio1 = S3C2410_GPA(7);
237 check_gpio2 = S3C2410_GPA(3);
240 blink_gpio = S3C2410_GPA(3);
241 check_gpio1 = S3C2410_GPA(1);
242 check_gpio1 = S3C2410_GPA(7);
246 if (delay_on && delay_off && !*delay_on && !*delay_off)
247 *delay_on = *delay_off = 500;
249 spin_lock(&h1940_blink_spin);
252 case GPIO_LED_NO_BLINK_LOW:
253 case GPIO_LED_NO_BLINK_HIGH:
254 if (!gpio_get_value(check_gpio1) &&
255 !gpio_get_value(check_gpio2))
256 gpio_set_value(H1940_LATCH_LED_FLASH, 0);
257 gpio_set_value(blink_gpio, 0);
258 if (gpio_is_valid(gpio))
259 gpio_set_value(gpio, state);
262 if (gpio_is_valid(gpio))
263 gpio_set_value(gpio, 0);
264 gpio_set_value(H1940_LATCH_LED_FLASH, 1);
265 gpio_set_value(blink_gpio, 1);
269 spin_unlock(&h1940_blink_spin);
273 EXPORT_SYMBOL(h1940_led_blink_set);
275 static struct gpio_led h1940_leds_desc[] = {
278 .default_trigger = "main-battery-charging-or-full",
279 .gpio = H1940_LATCH_LED_GREEN,
280 .retain_state_suspended = 1,
284 .default_trigger = "main-battery-full",
285 .gpio = H1940_LATCH_LED_RED,
286 .retain_state_suspended = 1,
290 static struct gpio_led_platform_data h1940_leds_pdata = {
291 .num_leds = ARRAY_SIZE(h1940_leds_desc),
292 .leds = h1940_leds_desc,
293 .gpio_blink_set = h1940_led_blink_set,
296 static struct platform_device h1940_device_leds = {
300 .platform_data = &h1940_leds_pdata,
304 static struct platform_device h1940_device_bluetooth = {
309 static void h1940_set_mmc_power(unsigned char power_mode, unsigned short vdd)
311 switch (power_mode) {
313 gpio_set_value(H1940_LATCH_SD_POWER, 0);
317 gpio_set_value(H1940_LATCH_SD_POWER, 1);
324 static struct s3c24xx_mci_pdata h1940_mmc_cfg __initdata = {
325 .gpio_detect = S3C2410_GPF(5),
326 .gpio_wprotect = S3C2410_GPH(8),
327 .set_power = h1940_set_mmc_power,
328 .ocr_avail = MMC_VDD_32_33,
331 static int h1940_backlight_init(struct device *dev)
333 gpio_request(S3C2410_GPB(0), "Backlight");
335 gpio_direction_output(S3C2410_GPB(0), 0);
336 s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
337 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
338 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
343 static int h1940_backlight_notify(struct device *dev, int brightness)
346 gpio_direction_output(S3C2410_GPB(0), 1);
347 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
349 gpio_direction_output(S3C2410_GPB(0), 0);
350 s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
351 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
352 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 1);
357 static void h1940_backlight_exit(struct device *dev)
359 gpio_direction_output(S3C2410_GPB(0), 1);
360 gpio_set_value(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
364 static struct platform_pwm_backlight_data backlight_data = {
366 .max_brightness = 100,
367 .dft_brightness = 50,
369 .pwm_period_ns = 36296,
370 .init = h1940_backlight_init,
371 .notify = h1940_backlight_notify,
372 .exit = h1940_backlight_exit,
375 static struct platform_device h1940_backlight = {
376 .name = "pwm-backlight",
378 .parent = &s3c_device_timer[0].dev,
379 .platform_data = &backlight_data,
384 static void h1940_lcd_power_set(struct plat_lcd_data *pd,
390 gpio_set_value(S3C2410_GPC(0), 0);
393 value = gpio_get_value(S3C2410_GPC(6));
396 gpio_set_value(H1940_LATCH_LCD_P2, 0);
397 gpio_set_value(H1940_LATCH_LCD_P3, 0);
398 gpio_set_value(H1940_LATCH_LCD_P4, 0);
400 gpio_direction_output(S3C2410_GPC(1), 0);
401 gpio_direction_output(S3C2410_GPC(4), 0);
403 gpio_set_value(H1940_LATCH_LCD_P1, 0);
404 gpio_set_value(H1940_LATCH_LCD_P0, 0);
406 gpio_set_value(S3C2410_GPC(5), 0);
409 gpio_set_value(H1940_LATCH_LCD_P0, 1);
410 gpio_set_value(H1940_LATCH_LCD_P1, 1);
412 s3c_gpio_cfgpin(S3C2410_GPC(1), S3C_GPIO_SFN(2));
413 s3c_gpio_cfgpin(S3C2410_GPC(4), S3C_GPIO_SFN(2));
415 gpio_set_value(S3C2410_GPC(5), 1);
416 gpio_set_value(S3C2410_GPC(0), 1);
418 gpio_set_value(H1940_LATCH_LCD_P3, 1);
419 gpio_set_value(H1940_LATCH_LCD_P2, 1);
420 gpio_set_value(H1940_LATCH_LCD_P4, 1);
424 static struct plat_lcd_data h1940_lcd_power_data = {
425 .set_power = h1940_lcd_power_set,
428 static struct platform_device h1940_lcd_powerdev = {
429 .name = "platform-lcd",
430 .dev.parent = &s3c_device_lcd.dev,
431 .dev.platform_data = &h1940_lcd_power_data,
434 static struct uda1380_platform_data uda1380_info = {
435 .gpio_power = H1940_LATCH_UDA_POWER,
436 .gpio_reset = S3C2410_GPA(12),
437 .dac_clk = UDA1380_DAC_CLK_SYSCLK,
440 static struct i2c_board_info h1940_i2c_devices[] = {
442 I2C_BOARD_INFO("uda1380", 0x1a),
443 .platform_data = &uda1380_info,
447 #define DECLARE_BUTTON(p, k, n, w) \
456 static struct gpio_keys_button h1940_buttons[] = {
457 DECLARE_BUTTON(S3C2410_GPF(0), KEY_POWER, "Power", 1),
458 DECLARE_BUTTON(S3C2410_GPF(6), KEY_ENTER, "Select", 1),
459 DECLARE_BUTTON(S3C2410_GPF(7), KEY_RECORD, "Record", 0),
460 DECLARE_BUTTON(S3C2410_GPG(0), KEY_F11, "Calendar", 0),
461 DECLARE_BUTTON(S3C2410_GPG(2), KEY_F12, "Contacts", 0),
462 DECLARE_BUTTON(S3C2410_GPG(3), KEY_MAIL, "Mail", 0),
463 DECLARE_BUTTON(S3C2410_GPG(6), KEY_LEFT, "Left_arrow", 0),
464 DECLARE_BUTTON(S3C2410_GPG(7), KEY_HOMEPAGE, "Home", 0),
465 DECLARE_BUTTON(S3C2410_GPG(8), KEY_RIGHT, "Right_arrow", 0),
466 DECLARE_BUTTON(S3C2410_GPG(9), KEY_UP, "Up_arrow", 0),
467 DECLARE_BUTTON(S3C2410_GPG(10), KEY_DOWN, "Down_arrow", 0),
470 static struct gpio_keys_platform_data h1940_buttons_data = {
471 .buttons = h1940_buttons,
472 .nbuttons = ARRAY_SIZE(h1940_buttons),
475 static struct platform_device h1940_dev_buttons = {
479 .platform_data = &h1940_buttons_data,
483 static struct platform_device *h1940_devices[] __initdata = {
491 &s3c_device_usbgadget,
493 &h1940_device_bluetooth,
496 &s3c_device_timer[0],
503 static void __init h1940_map_io(void)
505 s3c24xx_init_io(h1940_iodesc, ARRAY_SIZE(h1940_iodesc));
506 s3c24xx_init_clocks(0);
507 s3c24xx_init_uarts(h1940_uartcfgs, ARRAY_SIZE(h1940_uartcfgs));
511 #ifdef CONFIG_PM_H1940
512 memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 1024);
516 /* Add latch gpio chip, set latch initial value */
517 h1940_latch_control(0, 0);
518 WARN_ON(gpiochip_add(&h1940_latch_gpiochip));
521 /* H1940 and RX3715 need to reserve this for suspend */
522 static void __init h1940_reserve(void)
524 memblock_reserve(0x30003000, 0x1000);
525 memblock_reserve(0x30081000, 0x1000);
528 static void __init h1940_init_irq(void)
533 static void __init h1940_init(void)
537 s3c24xx_fb_set_platdata(&h1940_fb_info);
538 s3c24xx_mci_set_platdata(&h1940_mmc_cfg);
539 s3c24xx_udc_set_platdata(&h1940_udc_cfg);
540 s3c24xx_ts_set_platdata(&h1940_ts_cfg);
541 s3c_i2c0_set_platdata(NULL);
543 /* Turn off suspend on both USB ports, and switch the
544 * selectable USB port to USB device mode. */
546 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
547 S3C2410_MISCCR_USBSUSPND0 |
548 S3C2410_MISCCR_USBSUSPND1, 0x0);
550 tmp = (0x78 << S3C24XX_PLLCON_MDIVSHIFT)
551 | (0x02 << S3C24XX_PLLCON_PDIVSHIFT)
552 | (0x03 << S3C24XX_PLLCON_SDIVSHIFT);
553 writel(tmp, S3C2410_UPLLCON);
555 gpio_request(S3C2410_GPC(0), "LCD power");
556 gpio_request(S3C2410_GPC(1), "LCD power");
557 gpio_request(S3C2410_GPC(4), "LCD power");
558 gpio_request(S3C2410_GPC(5), "LCD power");
559 gpio_request(S3C2410_GPC(6), "LCD power");
560 gpio_request(H1940_LATCH_LCD_P0, "LCD power");
561 gpio_request(H1940_LATCH_LCD_P1, "LCD power");
562 gpio_request(H1940_LATCH_LCD_P2, "LCD power");
563 gpio_request(H1940_LATCH_LCD_P3, "LCD power");
564 gpio_request(H1940_LATCH_LCD_P4, "LCD power");
565 gpio_request(H1940_LATCH_MAX1698_nSHUTDOWN, "LCD power");
566 gpio_direction_output(S3C2410_GPC(0), 0);
567 gpio_direction_output(S3C2410_GPC(1), 0);
568 gpio_direction_output(S3C2410_GPC(4), 0);
569 gpio_direction_output(S3C2410_GPC(5), 0);
570 gpio_direction_input(S3C2410_GPC(6));
571 gpio_direction_output(H1940_LATCH_LCD_P0, 0);
572 gpio_direction_output(H1940_LATCH_LCD_P1, 0);
573 gpio_direction_output(H1940_LATCH_LCD_P2, 0);
574 gpio_direction_output(H1940_LATCH_LCD_P3, 0);
575 gpio_direction_output(H1940_LATCH_LCD_P4, 0);
576 gpio_direction_output(H1940_LATCH_MAX1698_nSHUTDOWN, 0);
578 gpio_request(H1940_LATCH_SD_POWER, "SD power");
579 gpio_direction_output(H1940_LATCH_SD_POWER, 0);
581 platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
583 gpio_request(S3C2410_GPA(1), "Red LED blink");
584 gpio_request(S3C2410_GPA(3), "Blue LED blink");
585 gpio_request(S3C2410_GPA(7), "Green LED blink");
586 gpio_request(H1940_LATCH_LED_FLASH, "LED blink");
587 gpio_direction_output(S3C2410_GPA(1), 0);
588 gpio_direction_output(S3C2410_GPA(3), 0);
589 gpio_direction_output(S3C2410_GPA(7), 0);
590 gpio_direction_output(H1940_LATCH_LED_FLASH, 0);
592 i2c_register_board_info(0, h1940_i2c_devices,
593 ARRAY_SIZE(h1940_i2c_devices));
596 MACHINE_START(H1940, "IPAQ-H1940")
597 /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
598 .boot_params = S3C2410_SDRAM_PA + 0x100,
599 .map_io = h1940_map_io,
600 .reserve = h1940_reserve,
601 .init_irq = h1940_init_irq,
602 .init_machine = h1940_init,
603 .timer = &s3c24xx_timer,