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/device.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-lcd.h>
46 #include <mach/h1940.h>
49 #include <plat/clock.h>
50 #include <plat/regs-serial.h>
51 #include <plat/regs-iic.h>
52 #include <linux/platform_data/mmc-s3cmci.h>
53 #include <linux/platform_data/usb-s3c2410_udc.h>
54 #include <linux/platform_data/mtd-nand-s3c2410.h>
55 #include <linux/platform_data/i2c-s3c2410.h>
56 #include <plat/devs.h>
60 #include <linux/platform_data/touchscreen-s3c2410.h>
62 #include <sound/uda1380.h>
66 #define LCD_PWM_PERIOD 192960
67 #define LCD_PWM_DUTY 127353
69 static struct map_desc rx1950_iodesc
[] __initdata
= {
72 static struct s3c2410_uartcfg rx1950_uartcfgs
[] __initdata
= {
79 .clk_sel
= S3C2410_UCON_CLKSEL3
,
87 .clk_sel
= S3C2410_UCON_CLKSEL3
,
96 .clk_sel
= S3C2410_UCON_CLKSEL3
,
100 static struct s3c2410fb_display rx1950_display
= {
101 .type
= S3C2410_LCDCON1_TFT
,
116 .lcdcon5
= S3C2410_LCDCON5_FRM565
|
117 S3C2410_LCDCON5_INVVCLK
|
118 S3C2410_LCDCON5_INVVLINE
|
119 S3C2410_LCDCON5_INVVFRAME
|
120 S3C2410_LCDCON5_HWSWP
|
126 static int power_supply_init(struct device
*dev
)
128 return gpio_request(S3C2410_GPF(2), "cable plugged");
131 static int rx1950_is_ac_online(void)
133 return !gpio_get_value(S3C2410_GPF(2));
136 static void power_supply_exit(struct device
*dev
)
138 gpio_free(S3C2410_GPF(2));
141 static char *rx1950_supplicants
[] = {
145 static struct pda_power_pdata power_supply_info
= {
146 .init
= power_supply_init
,
147 .is_ac_online
= rx1950_is_ac_online
,
148 .exit
= power_supply_exit
,
149 .supplied_to
= rx1950_supplicants
,
150 .num_supplicants
= ARRAY_SIZE(rx1950_supplicants
),
153 static struct resource power_supply_resources
[] = {
154 [0] = DEFINE_RES_NAMED(IRQ_EINT2
, 1, "ac", IORESOURCE_IRQ \
155 | IORESOURCE_IRQ_LOWEDGE
| IORESOURCE_IRQ_HIGHEDGE
),
158 static struct platform_device power_supply
= {
165 .resource
= power_supply_resources
,
166 .num_resources
= ARRAY_SIZE(power_supply_resources
),
169 static const struct s3c_adc_bat_thresh bat_lut_noac
[] = {
170 { .volt
= 4100, .cur
= 156, .level
= 100},
171 { .volt
= 4050, .cur
= 156, .level
= 95},
172 { .volt
= 4025, .cur
= 141, .level
= 90},
173 { .volt
= 3995, .cur
= 144, .level
= 85},
174 { .volt
= 3957, .cur
= 162, .level
= 80},
175 { .volt
= 3931, .cur
= 147, .level
= 75},
176 { .volt
= 3902, .cur
= 147, .level
= 70},
177 { .volt
= 3863, .cur
= 153, .level
= 65},
178 { .volt
= 3838, .cur
= 150, .level
= 60},
179 { .volt
= 3800, .cur
= 153, .level
= 55},
180 { .volt
= 3765, .cur
= 153, .level
= 50},
181 { .volt
= 3748, .cur
= 172, .level
= 45},
182 { .volt
= 3740, .cur
= 153, .level
= 40},
183 { .volt
= 3714, .cur
= 175, .level
= 35},
184 { .volt
= 3710, .cur
= 156, .level
= 30},
185 { .volt
= 3963, .cur
= 156, .level
= 25},
186 { .volt
= 3672, .cur
= 178, .level
= 20},
187 { .volt
= 3651, .cur
= 178, .level
= 15},
188 { .volt
= 3629, .cur
= 178, .level
= 10},
189 { .volt
= 3612, .cur
= 162, .level
= 5},
190 { .volt
= 3605, .cur
= 162, .level
= 0},
193 static const struct s3c_adc_bat_thresh bat_lut_acin
[] = {
194 { .volt
= 4200, .cur
= 0, .level
= 100},
195 { .volt
= 4190, .cur
= 0, .level
= 99},
196 { .volt
= 4178, .cur
= 0, .level
= 95},
197 { .volt
= 4110, .cur
= 0, .level
= 70},
198 { .volt
= 4076, .cur
= 0, .level
= 65},
199 { .volt
= 4046, .cur
= 0, .level
= 60},
200 { .volt
= 4021, .cur
= 0, .level
= 55},
201 { .volt
= 3999, .cur
= 0, .level
= 50},
202 { .volt
= 3982, .cur
= 0, .level
= 45},
203 { .volt
= 3965, .cur
= 0, .level
= 40},
204 { .volt
= 3957, .cur
= 0, .level
= 35},
205 { .volt
= 3948, .cur
= 0, .level
= 30},
206 { .volt
= 3936, .cur
= 0, .level
= 25},
207 { .volt
= 3927, .cur
= 0, .level
= 20},
208 { .volt
= 3906, .cur
= 0, .level
= 15},
209 { .volt
= 3880, .cur
= 0, .level
= 10},
210 { .volt
= 3829, .cur
= 0, .level
= 5},
211 { .volt
= 3820, .cur
= 0, .level
= 0},
214 static int rx1950_bat_init(void)
218 ret
= gpio_request(S3C2410_GPJ(2), "rx1950-charger-enable-1");
221 ret
= gpio_request(S3C2410_GPJ(3), "rx1950-charger-enable-2");
228 gpio_free(S3C2410_GPJ(2));
233 static void rx1950_bat_exit(void)
235 gpio_free(S3C2410_GPJ(2));
236 gpio_free(S3C2410_GPJ(3));
239 static void rx1950_enable_charger(void)
241 gpio_direction_output(S3C2410_GPJ(2), 1);
242 gpio_direction_output(S3C2410_GPJ(3), 1);
245 static void rx1950_disable_charger(void)
247 gpio_direction_output(S3C2410_GPJ(2), 0);
248 gpio_direction_output(S3C2410_GPJ(3), 0);
251 static DEFINE_SPINLOCK(rx1950_blink_spin
);
253 static int rx1950_led_blink_set(unsigned gpio
, int state
,
254 unsigned long *delay_on
, unsigned long *delay_off
)
256 int blink_gpio
, check_gpio
;
260 blink_gpio
= S3C2410_GPA(4);
261 check_gpio
= S3C2410_GPA(3);
264 blink_gpio
= S3C2410_GPA(3);
265 check_gpio
= S3C2410_GPA(4);
272 if (delay_on
&& delay_off
&& !*delay_on
&& !*delay_off
)
273 *delay_on
= *delay_off
= 500;
275 spin_lock(&rx1950_blink_spin
);
278 case GPIO_LED_NO_BLINK_LOW
:
279 case GPIO_LED_NO_BLINK_HIGH
:
280 if (!gpio_get_value(check_gpio
))
281 gpio_set_value(S3C2410_GPJ(6), 0);
282 gpio_set_value(blink_gpio
, 0);
283 gpio_set_value(gpio
, state
);
286 gpio_set_value(gpio
, 0);
287 gpio_set_value(S3C2410_GPJ(6), 1);
288 gpio_set_value(blink_gpio
, 1);
292 spin_unlock(&rx1950_blink_spin
);
297 static struct gpio_led rx1950_leds_desc
[] = {
300 .default_trigger
= "main-battery-full",
301 .gpio
= S3C2410_GPA(6),
302 .retain_state_suspended
= 1,
307 = "main-battery-charging-blink-full-solid",
308 .gpio
= S3C2410_GPA(7),
309 .retain_state_suspended
= 1,
313 .default_trigger
= "rx1950-acx-mem",
314 .gpio
= S3C2410_GPA(11),
315 .retain_state_suspended
= 1,
319 static struct gpio_led_platform_data rx1950_leds_pdata
= {
320 .num_leds
= ARRAY_SIZE(rx1950_leds_desc
),
321 .leds
= rx1950_leds_desc
,
322 .gpio_blink_set
= rx1950_led_blink_set
,
325 static struct platform_device rx1950_leds
= {
329 .platform_data
= &rx1950_leds_pdata
,
333 static struct s3c_adc_bat_pdata rx1950_bat_cfg
= {
334 .init
= rx1950_bat_init
,
335 .exit
= rx1950_bat_exit
,
336 .enable_charger
= rx1950_enable_charger
,
337 .disable_charger
= rx1950_disable_charger
,
338 .gpio_charge_finished
= S3C2410_GPF(3),
339 .lut_noac
= bat_lut_noac
,
340 .lut_noac_cnt
= ARRAY_SIZE(bat_lut_noac
),
341 .lut_acin
= bat_lut_acin
,
342 .lut_acin_cnt
= ARRAY_SIZE(bat_lut_acin
),
344 .current_channel
= 1,
346 .current_mult
= 2900,
347 .internal_impedance
= 200,
350 static struct platform_device rx1950_battery
= {
351 .name
= "s3c-adc-battery",
354 .parent
= &s3c_device_adc
.dev
,
355 .platform_data
= &rx1950_bat_cfg
,
359 static struct s3c2410fb_mach_info rx1950_lcd_cfg
= {
360 .displays
= &rx1950_display
,
362 .default_display
= 0,
365 .gpccon
= 0xaa9556a9,
366 .gpccon_mask
= 0xffc003fc,
368 .gpcup_mask
= 0xffffffff,
370 .gpdcon
= 0xaa90aaa1,
371 .gpdcon_mask
= 0xffc0fff0,
373 .gpdup_mask
= 0xffffffff,
377 static struct pwm_device
*lcd_pwm
;
379 static void rx1950_lcd_power(int enable
)
383 if (enabled
== enable
)
387 /* GPC11-GPC15->OUTPUT */
388 for (i
= 11; i
< 16; i
++)
389 gpio_direction_output(S3C2410_GPC(i
), 1);
391 /* Wait a bit here... */
394 /* GPD2-GPD7->OUTPUT */
395 /* GPD11-GPD15->OUTPUT */
396 /* GPD2-GPD7->1, GPD11-GPD15->1 */
397 for (i
= 2; i
< 8; i
++)
398 gpio_direction_output(S3C2410_GPD(i
), 1);
399 for (i
= 11; i
< 16; i
++)
400 gpio_direction_output(S3C2410_GPD(i
), 1);
402 /* Wait a bit here...*/
405 /* GPB0->OUTPUT, GPB0->0 */
406 gpio_direction_output(S3C2410_GPB(0), 0);
408 /* GPC1-GPC4->OUTPUT, GPC1-4->0 */
409 for (i
= 1; i
< 5; i
++)
410 gpio_direction_output(S3C2410_GPC(i
), 0);
413 for (i
= 11; i
< 16; i
++)
414 gpio_direction_output(S3C2410_GPC(i
), 0);
416 /* GPD15-GPD11->0, GPD2->GPD7->0 */
417 for (i
= 11; i
< 16; i
++)
418 gpio_direction_output(S3C2410_GPD(i
), 0);
420 for (i
= 2; i
< 8; i
++)
421 gpio_direction_output(S3C2410_GPD(i
), 0);
423 /* GPC6->0, GPC7->0, GPC5->0 */
424 gpio_direction_output(S3C2410_GPC(6), 0);
425 gpio_direction_output(S3C2410_GPC(7), 0);
426 gpio_direction_output(S3C2410_GPC(5), 0);
428 /* GPB1->OUTPUT, GPB1->0 */
429 gpio_direction_output(S3C2410_GPB(1), 0);
430 pwm_config(lcd_pwm
, 0, LCD_PWM_PERIOD
);
431 pwm_disable(lcd_pwm
);
433 /* GPC0->0, GPC10->0 */
434 gpio_direction_output(S3C2410_GPC(0), 0);
435 gpio_direction_output(S3C2410_GPC(10), 0);
437 pwm_config(lcd_pwm
, LCD_PWM_DUTY
, LCD_PWM_PERIOD
);
440 gpio_direction_output(S3C2410_GPC(0), 1);
441 gpio_direction_output(S3C2410_GPC(5), 1);
443 s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1
);
444 gpio_direction_output(S3C2410_GPC(7), 1);
446 for (i
= 1; i
< 5; i
++)
447 s3c_gpio_cfgpin(S3C2410_GPC(i
), S3C_GPIO_SFN(2));
449 for (i
= 11; i
< 16; i
++)
450 s3c_gpio_cfgpin(S3C2410_GPC(i
), S3C_GPIO_SFN(2));
452 for (i
= 2; i
< 8; i
++)
453 s3c_gpio_cfgpin(S3C2410_GPD(i
), S3C_GPIO_SFN(2));
455 for (i
= 11; i
< 16; i
++)
456 s3c_gpio_cfgpin(S3C2410_GPD(i
), S3C_GPIO_SFN(2));
458 gpio_direction_output(S3C2410_GPC(10), 1);
459 gpio_direction_output(S3C2410_GPC(6), 1);
464 static void rx1950_bl_power(int enable
)
467 if (enabled
== enable
)
470 gpio_direction_output(S3C2410_GPB(0), 0);
472 /* LED driver need a "push" to power on */
473 gpio_direction_output(S3C2410_GPB(0), 1);
474 /* Warm up backlight for one period of PWM.
475 * Without this trick its almost impossible to
476 * enable backlight with low brightness value
479 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0
);
484 static int rx1950_backlight_init(struct device
*dev
)
486 WARN_ON(gpio_request(S3C2410_GPB(0), "Backlight"));
487 lcd_pwm
= pwm_request(1, "RX1950 LCD");
488 if (IS_ERR(lcd_pwm
)) {
489 dev_err(dev
, "Unable to request PWM for LCD power!\n");
490 return PTR_ERR(lcd_pwm
);
499 static void rx1950_backlight_exit(struct device
*dev
)
505 gpio_free(S3C2410_GPB(0));
509 static int rx1950_backlight_notify(struct device
*dev
, int brightness
)
521 static struct platform_pwm_backlight_data rx1950_backlight_data
= {
523 .max_brightness
= 24,
525 .pwm_period_ns
= 48000,
526 .init
= rx1950_backlight_init
,
527 .notify
= rx1950_backlight_notify
,
528 .exit
= rx1950_backlight_exit
,
531 static struct platform_device rx1950_backlight
= {
532 .name
= "pwm-backlight",
534 .parent
= &s3c_device_timer
[0].dev
,
535 .platform_data
= &rx1950_backlight_data
,
539 static void rx1950_set_mmc_power(unsigned char power_mode
, unsigned short vdd
)
541 switch (power_mode
) {
543 gpio_direction_output(S3C2410_GPJ(1), 0);
547 gpio_direction_output(S3C2410_GPJ(1), 1);
554 static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata
= {
555 .gpio_detect
= S3C2410_GPF(5),
556 .gpio_wprotect
= S3C2410_GPH(8),
557 .set_power
= rx1950_set_mmc_power
,
558 .ocr_avail
= MMC_VDD_32_33
,
561 static struct mtd_partition rx1950_nand_part
[] = {
566 .mask_flags
= MTD_WRITEABLE
,
570 .offset
= MTDPART_OFS_APPEND
,
572 .mask_flags
= MTD_WRITEABLE
,
576 .offset
= MTDPART_OFS_APPEND
,
581 .name
= "Filesystem",
582 .offset
= MTDPART_OFS_APPEND
,
583 .size
= MTDPART_SIZ_FULL
,
588 static struct s3c2410_nand_set rx1950_nand_sets
[] = {
592 .nr_partitions
= ARRAY_SIZE(rx1950_nand_part
),
593 .partitions
= rx1950_nand_part
,
597 static struct s3c2410_platform_nand rx1950_nand_info
= {
601 .nr_sets
= ARRAY_SIZE(rx1950_nand_sets
),
602 .sets
= rx1950_nand_sets
,
605 static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata
= {
606 .vbus_pin
= S3C2410_GPG(5),
607 .vbus_pin_inverted
= 1,
608 .pullup_pin
= S3C2410_GPJ(5),
611 static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata
= {
614 .oversampling_shift
= 3,
617 static struct gpio_keys_button rx1950_gpio_keys_table
[] = {
620 .gpio
= S3C2410_GPF(0),
622 .desc
= "Power button",
627 .gpio
= S3C2410_GPF(7),
629 .desc
= "Record button",
633 .gpio
= S3C2410_GPG(0),
635 .desc
= "Calendar button",
639 .gpio
= S3C2410_GPG(2),
641 .desc
= "Contacts button",
645 .gpio
= S3C2410_GPG(3),
647 .desc
= "Mail button",
651 .gpio
= S3C2410_GPG(7),
653 .desc
= "WLAN button",
657 .gpio
= S3C2410_GPG(10),
659 .desc
= "Left button",
663 .gpio
= S3C2410_GPG(11),
665 .desc
= "Right button",
669 .gpio
= S3C2410_GPG(4),
675 .gpio
= S3C2410_GPG(6),
677 .desc
= "Down button",
681 .gpio
= S3C2410_GPG(9),
687 static struct gpio_keys_platform_data rx1950_gpio_keys_data
= {
688 .buttons
= rx1950_gpio_keys_table
,
689 .nbuttons
= ARRAY_SIZE(rx1950_gpio_keys_table
),
692 static struct platform_device rx1950_device_gpiokeys
= {
694 .dev
.platform_data
= &rx1950_gpio_keys_data
,
697 static struct uda1380_platform_data uda1380_info
= {
698 .gpio_power
= S3C2410_GPJ(0),
699 .gpio_reset
= S3C2410_GPD(0),
700 .dac_clk
= UDA1380_DAC_CLK_SYSCLK
,
703 static struct i2c_board_info rx1950_i2c_devices
[] = {
705 I2C_BOARD_INFO("uda1380", 0x1a),
706 .platform_data
= &uda1380_info
,
710 static struct platform_device
*rx1950_devices
[] __initdata
= {
715 &s3c_device_usbgadget
,
721 &s3c_device_timer
[0],
722 &s3c_device_timer
[1],
724 &rx1950_device_gpiokeys
,
730 static struct clk
*rx1950_clocks
[] __initdata
= {
735 static void __init
rx1950_map_io(void)
737 s3c24xx_clkout0
.parent
= &clk_h
;
738 s3c24xx_clkout1
.parent
= &clk_f
;
740 s3c24xx_register_clocks(rx1950_clocks
, ARRAY_SIZE(rx1950_clocks
));
742 s3c24xx_init_io(rx1950_iodesc
, ARRAY_SIZE(rx1950_iodesc
));
743 s3c24xx_init_clocks(16934000);
744 s3c24xx_init_uarts(rx1950_uartcfgs
, ARRAY_SIZE(rx1950_uartcfgs
));
748 #ifdef CONFIG_PM_H1940
749 memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT
), h1940_pm_return
, 8);
755 static void __init
rx1950_init_machine(void)
759 s3c24xx_fb_set_platdata(&rx1950_lcd_cfg
);
760 s3c24xx_udc_set_platdata(&rx1950_udc_cfg
);
761 s3c24xx_ts_set_platdata(&rx1950_ts_cfg
);
762 s3c24xx_mci_set_platdata(&rx1950_mmc_cfg
);
763 s3c_i2c0_set_platdata(NULL
);
764 s3c_nand_set_platdata(&rx1950_nand_info
);
766 /* Turn off suspend on both USB ports, and switch the
767 * selectable USB port to USB device mode. */
768 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST
|
769 S3C2410_MISCCR_USBSUSPND0
|
770 S3C2410_MISCCR_USBSUSPND1
, 0x0);
772 /* mmc power is disabled by default */
773 WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power"));
774 gpio_direction_output(S3C2410_GPJ(1), 0);
776 for (i
= 0; i
< 8; i
++)
777 WARN_ON(gpio_request(S3C2410_GPC(i
), "LCD power"));
779 for (i
= 10; i
< 16; i
++)
780 WARN_ON(gpio_request(S3C2410_GPC(i
), "LCD power"));
782 for (i
= 2; i
< 8; i
++)
783 WARN_ON(gpio_request(S3C2410_GPD(i
), "LCD power"));
785 for (i
= 11; i
< 16; i
++)
786 WARN_ON(gpio_request(S3C2410_GPD(i
), "LCD power"));
788 WARN_ON(gpio_request(S3C2410_GPB(1), "LCD power"));
790 WARN_ON(gpio_request(S3C2410_GPA(3), "Red blink"));
791 WARN_ON(gpio_request(S3C2410_GPA(4), "Green blink"));
792 WARN_ON(gpio_request(S3C2410_GPJ(6), "LED blink"));
793 gpio_direction_output(S3C2410_GPA(3), 0);
794 gpio_direction_output(S3C2410_GPA(4), 0);
795 gpio_direction_output(S3C2410_GPJ(6), 0);
797 platform_add_devices(rx1950_devices
, ARRAY_SIZE(rx1950_devices
));
799 i2c_register_board_info(0, rx1950_i2c_devices
,
800 ARRAY_SIZE(rx1950_i2c_devices
));
803 /* H1940 and RX3715 need to reserve this for suspend */
804 static void __init
rx1950_reserve(void)
806 memblock_reserve(0x30003000, 0x1000);
807 memblock_reserve(0x30081000, 0x1000);
810 MACHINE_START(RX1950
, "HP iPAQ RX1950")
811 /* Maintainers: Vasily Khoruzhick */
812 .atag_offset
= 0x100,
813 .map_io
= rx1950_map_io
,
814 .reserve
= rx1950_reserve
,
815 .init_irq
= s3c24xx_init_irq
,
816 .init_machine
= rx1950_init_machine
,
817 .timer
= &s3c24xx_timer
,
818 .restart
= s3c244x_restart
,