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/h1940.h>
49 #include <plat/clock.h>
50 #include <plat/regs-serial.h>
51 #include <plat/regs-iic.h>
54 #include <plat/nand.h>
56 #include <plat/devs.h>
62 #include <sound/uda1380.h>
64 #define LCD_PWM_PERIOD 192960
65 #define LCD_PWM_DUTY 127353
67 static struct map_desc rx1950_iodesc
[] __initdata
= {
70 static struct s3c24xx_uart_clksrc rx1950_serial_clocks
[] = {
79 static struct s3c2410_uartcfg rx1950_uartcfgs
[] __initdata
= {
86 .clocks
= rx1950_serial_clocks
,
87 .clocks_size
= ARRAY_SIZE(rx1950_serial_clocks
),
95 .clocks
= rx1950_serial_clocks
,
96 .clocks_size
= ARRAY_SIZE(rx1950_serial_clocks
),
105 .clocks
= rx1950_serial_clocks
,
106 .clocks_size
= ARRAY_SIZE(rx1950_serial_clocks
),
110 static struct s3c2410fb_display rx1950_display
= {
111 .type
= S3C2410_LCDCON1_TFT
,
126 .lcdcon5
= S3C2410_LCDCON5_FRM565
|
127 S3C2410_LCDCON5_INVVCLK
|
128 S3C2410_LCDCON5_INVVLINE
|
129 S3C2410_LCDCON5_INVVFRAME
|
130 S3C2410_LCDCON5_HWSWP
|
136 static int power_supply_init(struct device
*dev
)
138 return gpio_request(S3C2410_GPF(2), "cable plugged");
141 static int rx1950_is_ac_online(void)
143 return !gpio_get_value(S3C2410_GPF(2));
146 static void power_supply_exit(struct device
*dev
)
148 gpio_free(S3C2410_GPF(2));
151 static char *rx1950_supplicants
[] = {
155 static struct pda_power_pdata power_supply_info
= {
156 .init
= power_supply_init
,
157 .is_ac_online
= rx1950_is_ac_online
,
158 .exit
= power_supply_exit
,
159 .supplied_to
= rx1950_supplicants
,
160 .num_supplicants
= ARRAY_SIZE(rx1950_supplicants
),
163 static struct resource power_supply_resources
[] = {
166 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_LOWEDGE
|
167 IORESOURCE_IRQ_HIGHEDGE
,
173 static struct platform_device power_supply
= {
180 .resource
= power_supply_resources
,
181 .num_resources
= ARRAY_SIZE(power_supply_resources
),
184 static const struct s3c_adc_bat_thresh bat_lut_noac
[] = {
185 { .volt
= 4100, .cur
= 156, .level
= 100},
186 { .volt
= 4050, .cur
= 156, .level
= 95},
187 { .volt
= 4025, .cur
= 141, .level
= 90},
188 { .volt
= 3995, .cur
= 144, .level
= 85},
189 { .volt
= 3957, .cur
= 162, .level
= 80},
190 { .volt
= 3931, .cur
= 147, .level
= 75},
191 { .volt
= 3902, .cur
= 147, .level
= 70},
192 { .volt
= 3863, .cur
= 153, .level
= 65},
193 { .volt
= 3838, .cur
= 150, .level
= 60},
194 { .volt
= 3800, .cur
= 153, .level
= 55},
195 { .volt
= 3765, .cur
= 153, .level
= 50},
196 { .volt
= 3748, .cur
= 172, .level
= 45},
197 { .volt
= 3740, .cur
= 153, .level
= 40},
198 { .volt
= 3714, .cur
= 175, .level
= 35},
199 { .volt
= 3710, .cur
= 156, .level
= 30},
200 { .volt
= 3963, .cur
= 156, .level
= 25},
201 { .volt
= 3672, .cur
= 178, .level
= 20},
202 { .volt
= 3651, .cur
= 178, .level
= 15},
203 { .volt
= 3629, .cur
= 178, .level
= 10},
204 { .volt
= 3612, .cur
= 162, .level
= 5},
205 { .volt
= 3605, .cur
= 162, .level
= 0},
208 static const struct s3c_adc_bat_thresh bat_lut_acin
[] = {
209 { .volt
= 4200, .cur
= 0, .level
= 100},
210 { .volt
= 4190, .cur
= 0, .level
= 99},
211 { .volt
= 4178, .cur
= 0, .level
= 95},
212 { .volt
= 4110, .cur
= 0, .level
= 70},
213 { .volt
= 4076, .cur
= 0, .level
= 65},
214 { .volt
= 4046, .cur
= 0, .level
= 60},
215 { .volt
= 4021, .cur
= 0, .level
= 55},
216 { .volt
= 3999, .cur
= 0, .level
= 50},
217 { .volt
= 3982, .cur
= 0, .level
= 45},
218 { .volt
= 3965, .cur
= 0, .level
= 40},
219 { .volt
= 3957, .cur
= 0, .level
= 35},
220 { .volt
= 3948, .cur
= 0, .level
= 30},
221 { .volt
= 3936, .cur
= 0, .level
= 25},
222 { .volt
= 3927, .cur
= 0, .level
= 20},
223 { .volt
= 3906, .cur
= 0, .level
= 15},
224 { .volt
= 3880, .cur
= 0, .level
= 10},
225 { .volt
= 3829, .cur
= 0, .level
= 5},
226 { .volt
= 3820, .cur
= 0, .level
= 0},
229 int rx1950_bat_init(void)
233 ret
= gpio_request(S3C2410_GPJ(2), "rx1950-charger-enable-1");
236 ret
= gpio_request(S3C2410_GPJ(3), "rx1950-charger-enable-2");
243 gpio_free(S3C2410_GPJ(2));
248 void rx1950_bat_exit(void)
250 gpio_free(S3C2410_GPJ(2));
251 gpio_free(S3C2410_GPJ(3));
254 void rx1950_enable_charger(void)
256 gpio_direction_output(S3C2410_GPJ(2), 1);
257 gpio_direction_output(S3C2410_GPJ(3), 1);
260 void rx1950_disable_charger(void)
262 gpio_direction_output(S3C2410_GPJ(2), 0);
263 gpio_direction_output(S3C2410_GPJ(3), 0);
266 static struct gpio_led rx1950_leds_desc
[] = {
269 .default_trigger
= "main-battery-charging-or-full",
270 .gpio
= S3C2410_GPA(6),
274 .default_trigger
= "main-battery-full",
275 .gpio
= S3C2410_GPA(7),
279 .default_trigger
= "rx1950-acx-mem",
280 .gpio
= S3C2410_GPA(11),
284 static struct gpio_led_platform_data rx1950_leds_pdata
= {
285 .num_leds
= ARRAY_SIZE(rx1950_leds_desc
),
286 .leds
= rx1950_leds_desc
,
289 static struct platform_device rx1950_leds
= {
293 .platform_data
= &rx1950_leds_pdata
,
297 static struct s3c_adc_bat_pdata rx1950_bat_cfg
= {
298 .init
= rx1950_bat_init
,
299 .exit
= rx1950_bat_exit
,
300 .enable_charger
= rx1950_enable_charger
,
301 .disable_charger
= rx1950_disable_charger
,
302 .gpio_charge_finished
= S3C2410_GPF(3),
303 .lut_noac
= bat_lut_noac
,
304 .lut_noac_cnt
= ARRAY_SIZE(bat_lut_noac
),
305 .lut_acin
= bat_lut_acin
,
306 .lut_acin_cnt
= ARRAY_SIZE(bat_lut_acin
),
308 .current_channel
= 1,
310 .current_mult
= 2900,
311 .internal_impedance
= 200,
314 static struct platform_device rx1950_battery
= {
315 .name
= "s3c-adc-battery",
318 .parent
= &s3c_device_adc
.dev
,
319 .platform_data
= &rx1950_bat_cfg
,
323 static struct s3c2410fb_mach_info rx1950_lcd_cfg
= {
324 .displays
= &rx1950_display
,
326 .default_display
= 0,
329 .gpccon
= 0xaa9556a9,
330 .gpccon_mask
= 0xffc003fc,
332 .gpcup_mask
= 0xffffffff,
334 .gpdcon
= 0xaa90aaa1,
335 .gpdcon_mask
= 0xffc0fff0,
337 .gpdup_mask
= 0xffffffff,
341 static struct pwm_device
*lcd_pwm
;
343 void rx1950_lcd_power(int enable
)
347 if (enabled
== enable
)
351 /* GPC11-GPC15->OUTPUT */
352 for (i
= 11; i
< 16; i
++)
353 gpio_direction_output(S3C2410_GPC(i
), 1);
355 /* Wait a bit here... */
358 /* GPD2-GPD7->OUTPUT */
359 /* GPD11-GPD15->OUTPUT */
360 /* GPD2-GPD7->1, GPD11-GPD15->1 */
361 for (i
= 2; i
< 8; i
++)
362 gpio_direction_output(S3C2410_GPD(i
), 1);
363 for (i
= 11; i
< 16; i
++)
364 gpio_direction_output(S3C2410_GPD(i
), 1);
366 /* Wait a bit here...*/
369 /* GPB0->OUTPUT, GPB0->0 */
370 gpio_direction_output(S3C2410_GPB(0), 0);
372 /* GPC1-GPC4->OUTPUT, GPC1-4->0 */
373 for (i
= 1; i
< 5; i
++)
374 gpio_direction_output(S3C2410_GPC(i
), 0);
377 for (i
= 11; i
< 16; i
++)
378 gpio_direction_output(S3C2410_GPC(i
), 0);
380 /* GPD15-GPD11->0, GPD2->GPD7->0 */
381 for (i
= 11; i
< 16; i
++)
382 gpio_direction_output(S3C2410_GPD(i
), 0);
384 for (i
= 2; i
< 8; i
++)
385 gpio_direction_output(S3C2410_GPD(i
), 0);
387 /* GPC6->0, GPC7->0, GPC5->0 */
388 gpio_direction_output(S3C2410_GPC(6), 0);
389 gpio_direction_output(S3C2410_GPC(7), 0);
390 gpio_direction_output(S3C2410_GPC(5), 0);
392 /* GPB1->OUTPUT, GPB1->0 */
393 gpio_direction_output(S3C2410_GPB(1), 0);
394 pwm_config(lcd_pwm
, 0, LCD_PWM_PERIOD
);
395 pwm_disable(lcd_pwm
);
397 /* GPC0->0, GPC10->0 */
398 gpio_direction_output(S3C2410_GPC(0), 0);
399 gpio_direction_output(S3C2410_GPC(10), 0);
401 pwm_config(lcd_pwm
, LCD_PWM_DUTY
, LCD_PWM_PERIOD
);
404 gpio_direction_output(S3C2410_GPC(0), 1);
405 gpio_direction_output(S3C2410_GPC(5), 1);
407 s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1
);
408 gpio_direction_output(S3C2410_GPC(7), 1);
410 for (i
= 1; i
< 5; i
++)
411 s3c_gpio_cfgpin(S3C2410_GPC(i
), S3C_GPIO_SFN(2));
413 for (i
= 11; i
< 16; i
++)
414 s3c_gpio_cfgpin(S3C2410_GPC(i
), S3C_GPIO_SFN(2));
416 for (i
= 2; i
< 8; i
++)
417 s3c_gpio_cfgpin(S3C2410_GPD(i
), S3C_GPIO_SFN(2));
419 for (i
= 11; i
< 16; i
++)
420 s3c_gpio_cfgpin(S3C2410_GPD(i
), S3C_GPIO_SFN(2));
422 gpio_direction_output(S3C2410_GPC(10), 1);
423 gpio_direction_output(S3C2410_GPC(6), 1);
428 static void rx1950_bl_power(int enable
)
431 if (enabled
== enable
)
434 gpio_direction_output(S3C2410_GPB(0), 0);
436 /* LED driver need a "push" to power on */
437 gpio_direction_output(S3C2410_GPB(0), 1);
438 /* Warm up backlight for one period of PWM.
439 * Without this trick its almost impossible to
440 * enable backlight with low brightness value
443 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0
);
448 static int rx1950_backlight_init(struct device
*dev
)
450 WARN_ON(gpio_request(S3C2410_GPB(0), "Backlight"));
451 lcd_pwm
= pwm_request(1, "RX1950 LCD");
452 if (IS_ERR(lcd_pwm
)) {
453 dev_err(dev
, "Unable to request PWM for LCD power!\n");
454 return PTR_ERR(lcd_pwm
);
463 static void rx1950_backlight_exit(struct device
*dev
)
469 gpio_free(S3C2410_GPB(0));
473 static int rx1950_backlight_notify(struct device
*dev
, int brightness
)
485 static struct platform_pwm_backlight_data rx1950_backlight_data
= {
487 .max_brightness
= 24,
489 .pwm_period_ns
= 48000,
490 .init
= rx1950_backlight_init
,
491 .notify
= rx1950_backlight_notify
,
492 .exit
= rx1950_backlight_exit
,
495 static struct platform_device rx1950_backlight
= {
496 .name
= "pwm-backlight",
498 .parent
= &s3c_device_timer
[0].dev
,
499 .platform_data
= &rx1950_backlight_data
,
503 static void rx1950_set_mmc_power(unsigned char power_mode
, unsigned short vdd
)
505 switch (power_mode
) {
507 gpio_direction_output(S3C2410_GPJ(1), 0);
511 gpio_direction_output(S3C2410_GPJ(1), 1);
518 static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata
= {
519 .gpio_detect
= S3C2410_GPF(5),
520 .gpio_wprotect
= S3C2410_GPH(8),
521 .set_power
= rx1950_set_mmc_power
,
522 .ocr_avail
= MMC_VDD_32_33
,
525 static struct mtd_partition rx1950_nand_part
[] = {
530 .mask_flags
= MTD_WRITEABLE
,
534 .offset
= MTDPART_OFS_APPEND
,
536 .mask_flags
= MTD_WRITEABLE
,
540 .offset
= MTDPART_OFS_APPEND
,
545 .name
= "Filesystem",
546 .offset
= MTDPART_OFS_APPEND
,
547 .size
= MTDPART_SIZ_FULL
,
552 static struct s3c2410_nand_set rx1950_nand_sets
[] = {
556 .nr_partitions
= ARRAY_SIZE(rx1950_nand_part
),
557 .partitions
= rx1950_nand_part
,
561 static struct s3c2410_platform_nand rx1950_nand_info
= {
565 .nr_sets
= ARRAY_SIZE(rx1950_nand_sets
),
566 .sets
= rx1950_nand_sets
,
569 static void rx1950_udc_pullup(enum s3c2410_udc_cmd_e cmd
)
572 case S3C2410_UDC_P_ENABLE
:
573 gpio_direction_output(S3C2410_GPJ(5), 1);
575 case S3C2410_UDC_P_DISABLE
:
576 gpio_direction_output(S3C2410_GPJ(5), 0);
578 case S3C2410_UDC_P_RESET
:
585 static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata
= {
586 .udc_command
= rx1950_udc_pullup
,
587 .vbus_pin
= S3C2410_GPG(5),
588 .vbus_pin_inverted
= 1,
591 static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata
= {
594 .oversampling_shift
= 3,
597 static struct gpio_keys_button rx1950_gpio_keys_table
[] = {
600 .gpio
= S3C2410_GPF(0),
602 .desc
= "Power button",
607 .gpio
= S3C2410_GPF(7),
609 .desc
= "Record button",
613 .gpio
= S3C2410_GPG(0),
615 .desc
= "Calendar button",
619 .gpio
= S3C2410_GPG(2),
621 .desc
= "Contacts button",
625 .gpio
= S3C2410_GPG(3),
627 .desc
= "Mail button",
631 .gpio
= S3C2410_GPG(7),
633 .desc
= "WLAN button",
637 .gpio
= S3C2410_GPG(10),
639 .desc
= "Left button",
643 .gpio
= S3C2410_GPG(11),
645 .desc
= "Right button",
649 .gpio
= S3C2410_GPG(4),
655 .gpio
= S3C2410_GPG(6),
657 .desc
= "Down button",
661 .gpio
= S3C2410_GPG(9),
667 static struct gpio_keys_platform_data rx1950_gpio_keys_data
= {
668 .buttons
= rx1950_gpio_keys_table
,
669 .nbuttons
= ARRAY_SIZE(rx1950_gpio_keys_table
),
672 static struct platform_device rx1950_device_gpiokeys
= {
674 .dev
.platform_data
= &rx1950_gpio_keys_data
,
677 static struct uda1380_platform_data uda1380_info
= {
678 .gpio_power
= S3C2410_GPJ(0),
679 .gpio_reset
= S3C2410_GPD(0),
680 .dac_clk
= UDA1380_DAC_CLK_SYSCLK
,
683 static struct i2c_board_info rx1950_i2c_devices
[] = {
685 I2C_BOARD_INFO("uda1380", 0x1a),
686 .platform_data
= &uda1380_info
,
690 static struct platform_device
*rx1950_devices
[] __initdata
= {
696 &s3c_device_usbgadget
,
702 &s3c_device_timer
[0],
703 &s3c_device_timer
[1],
705 &rx1950_device_gpiokeys
,
711 static struct clk
*rx1950_clocks
[] __initdata
= {
716 static void __init
rx1950_map_io(void)
718 s3c24xx_clkout0
.parent
= &clk_h
;
719 s3c24xx_clkout1
.parent
= &clk_f
;
721 s3c24xx_register_clocks(rx1950_clocks
, ARRAY_SIZE(rx1950_clocks
));
723 s3c24xx_init_io(rx1950_iodesc
, ARRAY_SIZE(rx1950_iodesc
));
724 s3c24xx_init_clocks(16934000);
725 s3c24xx_init_uarts(rx1950_uartcfgs
, ARRAY_SIZE(rx1950_uartcfgs
));
729 #ifdef CONFIG_PM_H1940
730 memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT
), h1940_pm_return
, 8);
736 static void __init
rx1950_init_machine(void)
740 s3c24xx_fb_set_platdata(&rx1950_lcd_cfg
);
741 s3c24xx_udc_set_platdata(&rx1950_udc_cfg
);
742 s3c24xx_ts_set_platdata(&rx1950_ts_cfg
);
743 s3c24xx_mci_set_platdata(&rx1950_mmc_cfg
);
744 s3c_i2c0_set_platdata(NULL
);
745 s3c_nand_set_platdata(&rx1950_nand_info
);
747 /* Turn off suspend on both USB ports, and switch the
748 * selectable USB port to USB device mode. */
749 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST
|
750 S3C2410_MISCCR_USBSUSPND0
|
751 S3C2410_MISCCR_USBSUSPND1
, 0x0);
753 WARN_ON(gpio_request(S3C2410_GPJ(5), "UDC pullup"));
754 gpio_direction_output(S3C2410_GPJ(5), 0);
756 /* mmc power is disabled by default */
757 WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power"));
758 gpio_direction_output(S3C2410_GPJ(1), 0);
760 for (i
= 0; i
< 8; i
++)
761 WARN_ON(gpio_request(S3C2410_GPC(i
), "LCD power"));
763 for (i
= 10; i
< 16; i
++)
764 WARN_ON(gpio_request(S3C2410_GPC(i
), "LCD power"));
766 for (i
= 2; i
< 8; i
++)
767 WARN_ON(gpio_request(S3C2410_GPD(i
), "LCD power"));
769 for (i
= 11; i
< 16; i
++)
770 WARN_ON(gpio_request(S3C2410_GPD(i
), "LCD power"));
772 WARN_ON(gpio_request(S3C2410_GPB(1), "LCD power"));
774 platform_add_devices(rx1950_devices
, ARRAY_SIZE(rx1950_devices
));
776 i2c_register_board_info(0, rx1950_i2c_devices
,
777 ARRAY_SIZE(rx1950_i2c_devices
));
780 /* H1940 and RX3715 need to reserve this for suspend */
781 static void __init
rx1950_reserve(void)
783 memblock_reserve(0x30003000, 0x1000);
784 memblock_reserve(0x30081000, 0x1000);
787 MACHINE_START(RX1950
, "HP iPAQ RX1950")
788 /* Maintainers: Vasily Khoruzhick */
789 .boot_params
= S3C2410_SDRAM_PA
+ 0x100,
790 .map_io
= rx1950_map_io
,
791 .reserve
= rx1950_reserve
,
792 .init_irq
= s3c24xx_init_irq
,
793 .init_machine
= rx1950_init_machine
,
794 .timer
= &s3c24xx_timer
,