1 /* linux/arch/arm/mach-s3c2440/mach-rx1950.c
3 * Copyright (c) 2006-2009 Victor Chukhantsev, Denis Grigoriev,
4 * Copyright (c) 2007-2010 Vasily Khoruzhick
6 * based on smdk2440 written by Ben Dooks
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/delay.h>
20 #include <linux/timer.h>
21 #include <linux/init.h>
22 #include <linux/gpio.h>
23 #include <linux/platform_device.h>
24 #include <linux/serial_core.h>
25 #include <linux/input.h>
26 #include <linux/gpio_keys.h>
27 #include <linux/sysdev.h>
28 #include <linux/pda_power.h>
29 #include <linux/pwm_backlight.h>
30 #include <linux/pwm.h>
31 #include <linux/s3c_adc_battery.h>
32 #include <linux/leds.h>
33 #include <linux/i2c.h>
35 #include <linux/mtd/mtd.h>
36 #include <linux/mtd/partitions.h>
38 #include <linux/mmc/host.h>
40 #include <asm/mach/arch.h>
41 #include <asm/mach/map.h>
42 #include <asm/mach-types.h>
44 #include <mach/regs-gpio.h>
45 #include <mach/regs-gpioj.h>
46 #include <mach/regs-lcd.h>
47 #include <mach/h1940.h>
50 #include <plat/clock.h>
51 #include <plat/regs-serial.h>
52 #include <plat/regs-iic.h>
55 #include <plat/nand.h>
57 #include <plat/devs.h>
63 #include <sound/uda1380.h>
67 #define LCD_PWM_PERIOD 192960
68 #define LCD_PWM_DUTY 127353
70 static struct map_desc rx1950_iodesc[] __initdata = {
73 static struct s3c24xx_uart_clksrc rx1950_serial_clocks[] = {
82 static struct s3c2410_uartcfg rx1950_uartcfgs[] __initdata = {
89 .clocks = rx1950_serial_clocks,
90 .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
98 .clocks = rx1950_serial_clocks,
99 .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
108 .clocks = rx1950_serial_clocks,
109 .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
113 static struct s3c2410fb_display rx1950_display = {
114 .type = S3C2410_LCDCON1_TFT,
129 .lcdcon5 = S3C2410_LCDCON5_FRM565 |
130 S3C2410_LCDCON5_INVVCLK |
131 S3C2410_LCDCON5_INVVLINE |
132 S3C2410_LCDCON5_INVVFRAME |
133 S3C2410_LCDCON5_HWSWP |
139 static int power_supply_init(struct device *dev)
141 return gpio_request(S3C2410_GPF(2), "cable plugged");
144 static int rx1950_is_ac_online(void)
146 return !gpio_get_value(S3C2410_GPF(2));
149 static void power_supply_exit(struct device *dev)
151 gpio_free(S3C2410_GPF(2));
154 static char *rx1950_supplicants[] = {
158 static struct pda_power_pdata power_supply_info = {
159 .init = power_supply_init,
160 .is_ac_online = rx1950_is_ac_online,
161 .exit = power_supply_exit,
162 .supplied_to = rx1950_supplicants,
163 .num_supplicants = ARRAY_SIZE(rx1950_supplicants),
166 static struct resource power_supply_resources[] = {
169 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWEDGE |
170 IORESOURCE_IRQ_HIGHEDGE,
176 static struct platform_device power_supply = {
183 .resource = power_supply_resources,
184 .num_resources = ARRAY_SIZE(power_supply_resources),
187 static const struct s3c_adc_bat_thresh bat_lut_noac[] = {
188 { .volt = 4100, .cur = 156, .level = 100},
189 { .volt = 4050, .cur = 156, .level = 95},
190 { .volt = 4025, .cur = 141, .level = 90},
191 { .volt = 3995, .cur = 144, .level = 85},
192 { .volt = 3957, .cur = 162, .level = 80},
193 { .volt = 3931, .cur = 147, .level = 75},
194 { .volt = 3902, .cur = 147, .level = 70},
195 { .volt = 3863, .cur = 153, .level = 65},
196 { .volt = 3838, .cur = 150, .level = 60},
197 { .volt = 3800, .cur = 153, .level = 55},
198 { .volt = 3765, .cur = 153, .level = 50},
199 { .volt = 3748, .cur = 172, .level = 45},
200 { .volt = 3740, .cur = 153, .level = 40},
201 { .volt = 3714, .cur = 175, .level = 35},
202 { .volt = 3710, .cur = 156, .level = 30},
203 { .volt = 3963, .cur = 156, .level = 25},
204 { .volt = 3672, .cur = 178, .level = 20},
205 { .volt = 3651, .cur = 178, .level = 15},
206 { .volt = 3629, .cur = 178, .level = 10},
207 { .volt = 3612, .cur = 162, .level = 5},
208 { .volt = 3605, .cur = 162, .level = 0},
211 static const struct s3c_adc_bat_thresh bat_lut_acin[] = {
212 { .volt = 4200, .cur = 0, .level = 100},
213 { .volt = 4190, .cur = 0, .level = 99},
214 { .volt = 4178, .cur = 0, .level = 95},
215 { .volt = 4110, .cur = 0, .level = 70},
216 { .volt = 4076, .cur = 0, .level = 65},
217 { .volt = 4046, .cur = 0, .level = 60},
218 { .volt = 4021, .cur = 0, .level = 55},
219 { .volt = 3999, .cur = 0, .level = 50},
220 { .volt = 3982, .cur = 0, .level = 45},
221 { .volt = 3965, .cur = 0, .level = 40},
222 { .volt = 3957, .cur = 0, .level = 35},
223 { .volt = 3948, .cur = 0, .level = 30},
224 { .volt = 3936, .cur = 0, .level = 25},
225 { .volt = 3927, .cur = 0, .level = 20},
226 { .volt = 3906, .cur = 0, .level = 15},
227 { .volt = 3880, .cur = 0, .level = 10},
228 { .volt = 3829, .cur = 0, .level = 5},
229 { .volt = 3820, .cur = 0, .level = 0},
232 int rx1950_bat_init(void)
236 ret = gpio_request(S3C2410_GPJ(2), "rx1950-charger-enable-1");
239 ret = gpio_request(S3C2410_GPJ(3), "rx1950-charger-enable-2");
246 gpio_free(S3C2410_GPJ(2));
251 void rx1950_bat_exit(void)
253 gpio_free(S3C2410_GPJ(2));
254 gpio_free(S3C2410_GPJ(3));
257 void rx1950_enable_charger(void)
259 gpio_direction_output(S3C2410_GPJ(2), 1);
260 gpio_direction_output(S3C2410_GPJ(3), 1);
263 void rx1950_disable_charger(void)
265 gpio_direction_output(S3C2410_GPJ(2), 0);
266 gpio_direction_output(S3C2410_GPJ(3), 0);
269 DEFINE_SPINLOCK(rx1950_blink_spin);
271 static int rx1950_led_blink_set(unsigned gpio, int state,
272 unsigned long *delay_on, unsigned long *delay_off)
274 int blink_gpio, check_gpio;
278 blink_gpio = S3C2410_GPA(4);
279 check_gpio = S3C2410_GPA(3);
282 blink_gpio = S3C2410_GPA(3);
283 check_gpio = S3C2410_GPA(4);
290 if (delay_on && delay_off && !*delay_on && !*delay_off)
291 *delay_on = *delay_off = 500;
293 spin_lock(&rx1950_blink_spin);
296 case GPIO_LED_NO_BLINK_LOW:
297 case GPIO_LED_NO_BLINK_HIGH:
298 if (!gpio_get_value(check_gpio))
299 gpio_set_value(S3C2410_GPJ(6), 0);
300 gpio_set_value(blink_gpio, 0);
301 gpio_set_value(gpio, state);
304 gpio_set_value(gpio, 0);
305 gpio_set_value(S3C2410_GPJ(6), 1);
306 gpio_set_value(blink_gpio, 1);
310 spin_unlock(&rx1950_blink_spin);
315 static struct gpio_led rx1950_leds_desc[] = {
318 .default_trigger = "main-battery-full",
319 .gpio = S3C2410_GPA(6),
320 .retain_state_suspended = 1,
325 = "main-battery-charging-blink-full-solid",
326 .gpio = S3C2410_GPA(7),
327 .retain_state_suspended = 1,
331 .default_trigger = "rx1950-acx-mem",
332 .gpio = S3C2410_GPA(11),
333 .retain_state_suspended = 1,
337 static struct gpio_led_platform_data rx1950_leds_pdata = {
338 .num_leds = ARRAY_SIZE(rx1950_leds_desc),
339 .leds = rx1950_leds_desc,
340 .gpio_blink_set = rx1950_led_blink_set,
343 static struct platform_device rx1950_leds = {
347 .platform_data = &rx1950_leds_pdata,
351 static struct s3c_adc_bat_pdata rx1950_bat_cfg = {
352 .init = rx1950_bat_init,
353 .exit = rx1950_bat_exit,
354 .enable_charger = rx1950_enable_charger,
355 .disable_charger = rx1950_disable_charger,
356 .gpio_charge_finished = S3C2410_GPF(3),
357 .lut_noac = bat_lut_noac,
358 .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
359 .lut_acin = bat_lut_acin,
360 .lut_acin_cnt = ARRAY_SIZE(bat_lut_acin),
362 .current_channel = 1,
364 .current_mult = 2900,
365 .internal_impedance = 200,
368 static struct platform_device rx1950_battery = {
369 .name = "s3c-adc-battery",
372 .parent = &s3c_device_adc.dev,
373 .platform_data = &rx1950_bat_cfg,
377 static struct s3c2410fb_mach_info rx1950_lcd_cfg = {
378 .displays = &rx1950_display,
380 .default_display = 0,
383 .gpccon = 0xaa9556a9,
384 .gpccon_mask = 0xffc003fc,
386 .gpcup_mask = 0xffffffff,
388 .gpdcon = 0xaa90aaa1,
389 .gpdcon_mask = 0xffc0fff0,
391 .gpdup_mask = 0xffffffff,
395 static struct pwm_device *lcd_pwm;
397 void rx1950_lcd_power(int enable)
401 if (enabled == enable)
405 /* GPC11-GPC15->OUTPUT */
406 for (i = 11; i < 16; i++)
407 gpio_direction_output(S3C2410_GPC(i), 1);
409 /* Wait a bit here... */
412 /* GPD2-GPD7->OUTPUT */
413 /* GPD11-GPD15->OUTPUT */
414 /* GPD2-GPD7->1, GPD11-GPD15->1 */
415 for (i = 2; i < 8; i++)
416 gpio_direction_output(S3C2410_GPD(i), 1);
417 for (i = 11; i < 16; i++)
418 gpio_direction_output(S3C2410_GPD(i), 1);
420 /* Wait a bit here...*/
423 /* GPB0->OUTPUT, GPB0->0 */
424 gpio_direction_output(S3C2410_GPB(0), 0);
426 /* GPC1-GPC4->OUTPUT, GPC1-4->0 */
427 for (i = 1; i < 5; i++)
428 gpio_direction_output(S3C2410_GPC(i), 0);
431 for (i = 11; i < 16; i++)
432 gpio_direction_output(S3C2410_GPC(i), 0);
434 /* GPD15-GPD11->0, GPD2->GPD7->0 */
435 for (i = 11; i < 16; i++)
436 gpio_direction_output(S3C2410_GPD(i), 0);
438 for (i = 2; i < 8; i++)
439 gpio_direction_output(S3C2410_GPD(i), 0);
441 /* GPC6->0, GPC7->0, GPC5->0 */
442 gpio_direction_output(S3C2410_GPC(6), 0);
443 gpio_direction_output(S3C2410_GPC(7), 0);
444 gpio_direction_output(S3C2410_GPC(5), 0);
446 /* GPB1->OUTPUT, GPB1->0 */
447 gpio_direction_output(S3C2410_GPB(1), 0);
448 pwm_config(lcd_pwm, 0, LCD_PWM_PERIOD);
449 pwm_disable(lcd_pwm);
451 /* GPC0->0, GPC10->0 */
452 gpio_direction_output(S3C2410_GPC(0), 0);
453 gpio_direction_output(S3C2410_GPC(10), 0);
455 pwm_config(lcd_pwm, LCD_PWM_DUTY, LCD_PWM_PERIOD);
458 gpio_direction_output(S3C2410_GPC(0), 1);
459 gpio_direction_output(S3C2410_GPC(5), 1);
461 s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1);
462 gpio_direction_output(S3C2410_GPC(7), 1);
464 for (i = 1; i < 5; i++)
465 s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2));
467 for (i = 11; i < 16; i++)
468 s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2));
470 for (i = 2; i < 8; i++)
471 s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2));
473 for (i = 11; i < 16; i++)
474 s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2));
476 gpio_direction_output(S3C2410_GPC(10), 1);
477 gpio_direction_output(S3C2410_GPC(6), 1);
482 static void rx1950_bl_power(int enable)
485 if (enabled == enable)
488 gpio_direction_output(S3C2410_GPB(0), 0);
490 /* LED driver need a "push" to power on */
491 gpio_direction_output(S3C2410_GPB(0), 1);
492 /* Warm up backlight for one period of PWM.
493 * Without this trick its almost impossible to
494 * enable backlight with low brightness value
497 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
502 static int rx1950_backlight_init(struct device *dev)
504 WARN_ON(gpio_request(S3C2410_GPB(0), "Backlight"));
505 lcd_pwm = pwm_request(1, "RX1950 LCD");
506 if (IS_ERR(lcd_pwm)) {
507 dev_err(dev, "Unable to request PWM for LCD power!\n");
508 return PTR_ERR(lcd_pwm);
517 static void rx1950_backlight_exit(struct device *dev)
523 gpio_free(S3C2410_GPB(0));
527 static int rx1950_backlight_notify(struct device *dev, int brightness)
539 static struct platform_pwm_backlight_data rx1950_backlight_data = {
541 .max_brightness = 24,
543 .pwm_period_ns = 48000,
544 .init = rx1950_backlight_init,
545 .notify = rx1950_backlight_notify,
546 .exit = rx1950_backlight_exit,
549 static struct platform_device rx1950_backlight = {
550 .name = "pwm-backlight",
552 .parent = &s3c_device_timer[0].dev,
553 .platform_data = &rx1950_backlight_data,
557 static void rx1950_set_mmc_power(unsigned char power_mode, unsigned short vdd)
559 switch (power_mode) {
561 gpio_direction_output(S3C2410_GPJ(1), 0);
565 gpio_direction_output(S3C2410_GPJ(1), 1);
572 static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata = {
573 .gpio_detect = S3C2410_GPF(5),
574 .gpio_wprotect = S3C2410_GPH(8),
575 .set_power = rx1950_set_mmc_power,
576 .ocr_avail = MMC_VDD_32_33,
579 static struct mtd_partition rx1950_nand_part[] = {
584 .mask_flags = MTD_WRITEABLE,
588 .offset = MTDPART_OFS_APPEND,
590 .mask_flags = MTD_WRITEABLE,
594 .offset = MTDPART_OFS_APPEND,
599 .name = "Filesystem",
600 .offset = MTDPART_OFS_APPEND,
601 .size = MTDPART_SIZ_FULL,
606 static struct s3c2410_nand_set rx1950_nand_sets[] = {
610 .nr_partitions = ARRAY_SIZE(rx1950_nand_part),
611 .partitions = rx1950_nand_part,
615 static struct s3c2410_platform_nand rx1950_nand_info = {
619 .nr_sets = ARRAY_SIZE(rx1950_nand_sets),
620 .sets = rx1950_nand_sets,
623 static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = {
624 .vbus_pin = S3C2410_GPG(5),
625 .vbus_pin_inverted = 1,
626 .pullup_pin = S3C2410_GPJ(5),
629 static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata = {
632 .oversampling_shift = 3,
635 static struct gpio_keys_button rx1950_gpio_keys_table[] = {
638 .gpio = S3C2410_GPF(0),
640 .desc = "Power button",
645 .gpio = S3C2410_GPF(7),
647 .desc = "Record button",
651 .gpio = S3C2410_GPG(0),
653 .desc = "Calendar button",
657 .gpio = S3C2410_GPG(2),
659 .desc = "Contacts button",
663 .gpio = S3C2410_GPG(3),
665 .desc = "Mail button",
669 .gpio = S3C2410_GPG(7),
671 .desc = "WLAN button",
675 .gpio = S3C2410_GPG(10),
677 .desc = "Left button",
681 .gpio = S3C2410_GPG(11),
683 .desc = "Right button",
687 .gpio = S3C2410_GPG(4),
693 .gpio = S3C2410_GPG(6),
695 .desc = "Down button",
699 .gpio = S3C2410_GPG(9),
705 static struct gpio_keys_platform_data rx1950_gpio_keys_data = {
706 .buttons = rx1950_gpio_keys_table,
707 .nbuttons = ARRAY_SIZE(rx1950_gpio_keys_table),
710 static struct platform_device rx1950_device_gpiokeys = {
712 .dev.platform_data = &rx1950_gpio_keys_data,
715 static struct uda1380_platform_data uda1380_info = {
716 .gpio_power = S3C2410_GPJ(0),
717 .gpio_reset = S3C2410_GPD(0),
718 .dac_clk = UDA1380_DAC_CLK_SYSCLK,
721 static struct i2c_board_info rx1950_i2c_devices[] = {
723 I2C_BOARD_INFO("uda1380", 0x1a),
724 .platform_data = &uda1380_info,
728 static struct platform_device *rx1950_devices[] __initdata = {
734 &s3c_device_usbgadget,
740 &s3c_device_timer[0],
741 &s3c_device_timer[1],
743 &rx1950_device_gpiokeys,
749 static struct clk *rx1950_clocks[] __initdata = {
754 static void __init rx1950_map_io(void)
756 s3c24xx_clkout0.parent = &clk_h;
757 s3c24xx_clkout1.parent = &clk_f;
759 s3c24xx_register_clocks(rx1950_clocks, ARRAY_SIZE(rx1950_clocks));
761 s3c24xx_init_io(rx1950_iodesc, ARRAY_SIZE(rx1950_iodesc));
762 s3c24xx_init_clocks(16934000);
763 s3c24xx_init_uarts(rx1950_uartcfgs, ARRAY_SIZE(rx1950_uartcfgs));
767 #ifdef CONFIG_PM_H1940
768 memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 8);
774 static void __init rx1950_init_machine(void)
778 s3c24xx_fb_set_platdata(&rx1950_lcd_cfg);
779 s3c24xx_udc_set_platdata(&rx1950_udc_cfg);
780 s3c24xx_ts_set_platdata(&rx1950_ts_cfg);
781 s3c24xx_mci_set_platdata(&rx1950_mmc_cfg);
782 s3c_i2c0_set_platdata(NULL);
783 s3c_nand_set_platdata(&rx1950_nand_info);
785 /* Turn off suspend on both USB ports, and switch the
786 * selectable USB port to USB device mode. */
787 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
788 S3C2410_MISCCR_USBSUSPND0 |
789 S3C2410_MISCCR_USBSUSPND1, 0x0);
791 /* mmc power is disabled by default */
792 WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power"));
793 gpio_direction_output(S3C2410_GPJ(1), 0);
795 for (i = 0; i < 8; i++)
796 WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power"));
798 for (i = 10; i < 16; i++)
799 WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power"));
801 for (i = 2; i < 8; i++)
802 WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power"));
804 for (i = 11; i < 16; i++)
805 WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power"));
807 WARN_ON(gpio_request(S3C2410_GPB(1), "LCD power"));
809 WARN_ON(gpio_request(S3C2410_GPA(3), "Red blink"));
810 WARN_ON(gpio_request(S3C2410_GPA(4), "Green blink"));
811 WARN_ON(gpio_request(S3C2410_GPJ(6), "LED blink"));
812 gpio_direction_output(S3C2410_GPA(3), 0);
813 gpio_direction_output(S3C2410_GPA(4), 0);
814 gpio_direction_output(S3C2410_GPJ(6), 0);
816 platform_add_devices(rx1950_devices, ARRAY_SIZE(rx1950_devices));
818 i2c_register_board_info(0, rx1950_i2c_devices,
819 ARRAY_SIZE(rx1950_i2c_devices));
822 /* H1940 and RX3715 need to reserve this for suspend */
823 static void __init rx1950_reserve(void)
825 memblock_reserve(0x30003000, 0x1000);
826 memblock_reserve(0x30081000, 0x1000);
829 MACHINE_START(RX1950, "HP iPAQ RX1950")
830 /* Maintainers: Vasily Khoruzhick */
831 .atag_offset = 0x100,
832 .map_io = rx1950_map_io,
833 .reserve = rx1950_reserve,
834 .init_irq = s3c24xx_init_irq,
835 .init_machine = rx1950_init_machine,
836 .timer = &s3c24xx_timer,
837 .restart = s3c2440_restart,