2 * Copyright (c) 2006-2009 Victor Chukhantsev, Denis Grigoriev,
3 * Copyright (c) 2007-2010 Vasily Khoruzhick
5 * based on smdk2440 written by Ben Dooks
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/interrupt.h>
16 #include <linux/list.h>
17 #include <linux/memblock.h>
18 #include <linux/delay.h>
19 #include <linux/timer.h>
20 #include <linux/init.h>
21 #include <linux/gpio.h>
22 #include <linux/platform_device.h>
23 #include <linux/serial_core.h>
24 #include <linux/input.h>
25 #include <linux/gpio_keys.h>
26 #include <linux/device.h>
27 #include <linux/pda_power.h>
28 #include <linux/pwm_backlight.h>
29 #include <linux/pwm.h>
30 #include <linux/s3c_adc_battery.h>
31 #include <linux/leds.h>
32 #include <linux/i2c.h>
34 #include <linux/mtd/mtd.h>
35 #include <linux/mtd/partitions.h>
37 #include <linux/mmc/host.h>
39 #include <asm/mach-types.h>
40 #include <asm/mach/arch.h>
41 #include <asm/mach/map.h>
43 #include <linux/platform_data/i2c-s3c2410.h>
44 #include <linux/platform_data/mmc-s3cmci.h>
45 #include <linux/platform_data/mtd-nand-s3c2410.h>
46 #include <linux/platform_data/touchscreen-s3c2410.h>
47 #include <linux/platform_data/usb-s3c2410_udc.h>
49 #include <sound/uda1380.h>
52 #include <mach/regs-gpio.h>
53 #include <mach/regs-lcd.h>
55 #include <plat/clock.h>
57 #include <plat/devs.h>
59 #include <plat/regs-serial.h>
64 #define LCD_PWM_PERIOD 192960
65 #define LCD_PWM_DUTY 127353
67 static struct map_desc rx1950_iodesc[] __initdata = {
70 static struct s3c2410_uartcfg rx1950_uartcfgs[] __initdata = {
77 .clk_sel = S3C2410_UCON_CLKSEL3,
85 .clk_sel = S3C2410_UCON_CLKSEL3,
94 .clk_sel = S3C2410_UCON_CLKSEL3,
98 static struct s3c2410fb_display rx1950_display = {
99 .type = S3C2410_LCDCON1_TFT,
114 .lcdcon5 = S3C2410_LCDCON5_FRM565 |
115 S3C2410_LCDCON5_INVVCLK |
116 S3C2410_LCDCON5_INVVLINE |
117 S3C2410_LCDCON5_INVVFRAME |
118 S3C2410_LCDCON5_HWSWP |
124 static int power_supply_init(struct device *dev)
126 return gpio_request(S3C2410_GPF(2), "cable plugged");
129 static int rx1950_is_ac_online(void)
131 return !gpio_get_value(S3C2410_GPF(2));
134 static void power_supply_exit(struct device *dev)
136 gpio_free(S3C2410_GPF(2));
139 static char *rx1950_supplicants[] = {
143 static struct pda_power_pdata power_supply_info = {
144 .init = power_supply_init,
145 .is_ac_online = rx1950_is_ac_online,
146 .exit = power_supply_exit,
147 .supplied_to = rx1950_supplicants,
148 .num_supplicants = ARRAY_SIZE(rx1950_supplicants),
151 static struct resource power_supply_resources[] = {
152 [0] = DEFINE_RES_NAMED(IRQ_EINT2, 1, "ac", IORESOURCE_IRQ \
153 | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE),
156 static struct platform_device power_supply = {
163 .resource = power_supply_resources,
164 .num_resources = ARRAY_SIZE(power_supply_resources),
167 static const struct s3c_adc_bat_thresh bat_lut_noac[] = {
168 { .volt = 4100, .cur = 156, .level = 100},
169 { .volt = 4050, .cur = 156, .level = 95},
170 { .volt = 4025, .cur = 141, .level = 90},
171 { .volt = 3995, .cur = 144, .level = 85},
172 { .volt = 3957, .cur = 162, .level = 80},
173 { .volt = 3931, .cur = 147, .level = 75},
174 { .volt = 3902, .cur = 147, .level = 70},
175 { .volt = 3863, .cur = 153, .level = 65},
176 { .volt = 3838, .cur = 150, .level = 60},
177 { .volt = 3800, .cur = 153, .level = 55},
178 { .volt = 3765, .cur = 153, .level = 50},
179 { .volt = 3748, .cur = 172, .level = 45},
180 { .volt = 3740, .cur = 153, .level = 40},
181 { .volt = 3714, .cur = 175, .level = 35},
182 { .volt = 3710, .cur = 156, .level = 30},
183 { .volt = 3963, .cur = 156, .level = 25},
184 { .volt = 3672, .cur = 178, .level = 20},
185 { .volt = 3651, .cur = 178, .level = 15},
186 { .volt = 3629, .cur = 178, .level = 10},
187 { .volt = 3612, .cur = 162, .level = 5},
188 { .volt = 3605, .cur = 162, .level = 0},
191 static const struct s3c_adc_bat_thresh bat_lut_acin[] = {
192 { .volt = 4200, .cur = 0, .level = 100},
193 { .volt = 4190, .cur = 0, .level = 99},
194 { .volt = 4178, .cur = 0, .level = 95},
195 { .volt = 4110, .cur = 0, .level = 70},
196 { .volt = 4076, .cur = 0, .level = 65},
197 { .volt = 4046, .cur = 0, .level = 60},
198 { .volt = 4021, .cur = 0, .level = 55},
199 { .volt = 3999, .cur = 0, .level = 50},
200 { .volt = 3982, .cur = 0, .level = 45},
201 { .volt = 3965, .cur = 0, .level = 40},
202 { .volt = 3957, .cur = 0, .level = 35},
203 { .volt = 3948, .cur = 0, .level = 30},
204 { .volt = 3936, .cur = 0, .level = 25},
205 { .volt = 3927, .cur = 0, .level = 20},
206 { .volt = 3906, .cur = 0, .level = 15},
207 { .volt = 3880, .cur = 0, .level = 10},
208 { .volt = 3829, .cur = 0, .level = 5},
209 { .volt = 3820, .cur = 0, .level = 0},
212 static int rx1950_bat_init(void)
216 ret = gpio_request(S3C2410_GPJ(2), "rx1950-charger-enable-1");
219 ret = gpio_request(S3C2410_GPJ(3), "rx1950-charger-enable-2");
226 gpio_free(S3C2410_GPJ(2));
231 static void rx1950_bat_exit(void)
233 gpio_free(S3C2410_GPJ(2));
234 gpio_free(S3C2410_GPJ(3));
237 static void rx1950_enable_charger(void)
239 gpio_direction_output(S3C2410_GPJ(2), 1);
240 gpio_direction_output(S3C2410_GPJ(3), 1);
243 static void rx1950_disable_charger(void)
245 gpio_direction_output(S3C2410_GPJ(2), 0);
246 gpio_direction_output(S3C2410_GPJ(3), 0);
249 static DEFINE_SPINLOCK(rx1950_blink_spin);
251 static int rx1950_led_blink_set(unsigned gpio, int state,
252 unsigned long *delay_on, unsigned long *delay_off)
254 int blink_gpio, check_gpio;
258 blink_gpio = S3C2410_GPA(4);
259 check_gpio = S3C2410_GPA(3);
262 blink_gpio = S3C2410_GPA(3);
263 check_gpio = S3C2410_GPA(4);
270 if (delay_on && delay_off && !*delay_on && !*delay_off)
271 *delay_on = *delay_off = 500;
273 spin_lock(&rx1950_blink_spin);
276 case GPIO_LED_NO_BLINK_LOW:
277 case GPIO_LED_NO_BLINK_HIGH:
278 if (!gpio_get_value(check_gpio))
279 gpio_set_value(S3C2410_GPJ(6), 0);
280 gpio_set_value(blink_gpio, 0);
281 gpio_set_value(gpio, state);
284 gpio_set_value(gpio, 0);
285 gpio_set_value(S3C2410_GPJ(6), 1);
286 gpio_set_value(blink_gpio, 1);
290 spin_unlock(&rx1950_blink_spin);
295 static struct gpio_led rx1950_leds_desc[] = {
298 .default_trigger = "main-battery-full",
299 .gpio = S3C2410_GPA(6),
300 .retain_state_suspended = 1,
305 = "main-battery-charging-blink-full-solid",
306 .gpio = S3C2410_GPA(7),
307 .retain_state_suspended = 1,
311 .default_trigger = "rx1950-acx-mem",
312 .gpio = S3C2410_GPA(11),
313 .retain_state_suspended = 1,
317 static struct gpio_led_platform_data rx1950_leds_pdata = {
318 .num_leds = ARRAY_SIZE(rx1950_leds_desc),
319 .leds = rx1950_leds_desc,
320 .gpio_blink_set = rx1950_led_blink_set,
323 static struct platform_device rx1950_leds = {
327 .platform_data = &rx1950_leds_pdata,
331 static struct s3c_adc_bat_pdata rx1950_bat_cfg = {
332 .init = rx1950_bat_init,
333 .exit = rx1950_bat_exit,
334 .enable_charger = rx1950_enable_charger,
335 .disable_charger = rx1950_disable_charger,
336 .gpio_charge_finished = S3C2410_GPF(3),
337 .lut_noac = bat_lut_noac,
338 .lut_noac_cnt = ARRAY_SIZE(bat_lut_noac),
339 .lut_acin = bat_lut_acin,
340 .lut_acin_cnt = ARRAY_SIZE(bat_lut_acin),
342 .current_channel = 1,
344 .current_mult = 2900,
345 .internal_impedance = 200,
348 static struct platform_device rx1950_battery = {
349 .name = "s3c-adc-battery",
352 .parent = &s3c_device_adc.dev,
353 .platform_data = &rx1950_bat_cfg,
357 static struct s3c2410fb_mach_info rx1950_lcd_cfg = {
358 .displays = &rx1950_display,
360 .default_display = 0,
363 .gpccon = 0xaa9556a9,
364 .gpccon_mask = 0xffc003fc,
366 .gpcup_mask = 0xffffffff,
368 .gpdcon = 0xaa90aaa1,
369 .gpdcon_mask = 0xffc0fff0,
371 .gpdup_mask = 0xffffffff,
375 static struct pwm_device *lcd_pwm;
377 static void rx1950_lcd_power(int enable)
381 if (enabled == enable)
385 /* GPC11-GPC15->OUTPUT */
386 for (i = 11; i < 16; i++)
387 gpio_direction_output(S3C2410_GPC(i), 1);
389 /* Wait a bit here... */
392 /* GPD2-GPD7->OUTPUT */
393 /* GPD11-GPD15->OUTPUT */
394 /* GPD2-GPD7->1, GPD11-GPD15->1 */
395 for (i = 2; i < 8; i++)
396 gpio_direction_output(S3C2410_GPD(i), 1);
397 for (i = 11; i < 16; i++)
398 gpio_direction_output(S3C2410_GPD(i), 1);
400 /* Wait a bit here...*/
403 /* GPB0->OUTPUT, GPB0->0 */
404 gpio_direction_output(S3C2410_GPB(0), 0);
406 /* GPC1-GPC4->OUTPUT, GPC1-4->0 */
407 for (i = 1; i < 5; i++)
408 gpio_direction_output(S3C2410_GPC(i), 0);
411 for (i = 11; i < 16; i++)
412 gpio_direction_output(S3C2410_GPC(i), 0);
414 /* GPD15-GPD11->0, GPD2->GPD7->0 */
415 for (i = 11; i < 16; i++)
416 gpio_direction_output(S3C2410_GPD(i), 0);
418 for (i = 2; i < 8; i++)
419 gpio_direction_output(S3C2410_GPD(i), 0);
421 /* GPC6->0, GPC7->0, GPC5->0 */
422 gpio_direction_output(S3C2410_GPC(6), 0);
423 gpio_direction_output(S3C2410_GPC(7), 0);
424 gpio_direction_output(S3C2410_GPC(5), 0);
426 /* GPB1->OUTPUT, GPB1->0 */
427 gpio_direction_output(S3C2410_GPB(1), 0);
428 pwm_config(lcd_pwm, 0, LCD_PWM_PERIOD);
429 pwm_disable(lcd_pwm);
431 /* GPC0->0, GPC10->0 */
432 gpio_direction_output(S3C2410_GPC(0), 0);
433 gpio_direction_output(S3C2410_GPC(10), 0);
435 pwm_config(lcd_pwm, LCD_PWM_DUTY, LCD_PWM_PERIOD);
438 gpio_direction_output(S3C2410_GPC(0), 1);
439 gpio_direction_output(S3C2410_GPC(5), 1);
441 s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1);
442 gpio_direction_output(S3C2410_GPC(7), 1);
444 for (i = 1; i < 5; i++)
445 s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2));
447 for (i = 11; i < 16; i++)
448 s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2));
450 for (i = 2; i < 8; i++)
451 s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2));
453 for (i = 11; i < 16; i++)
454 s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2));
456 gpio_direction_output(S3C2410_GPC(10), 1);
457 gpio_direction_output(S3C2410_GPC(6), 1);
462 static void rx1950_bl_power(int enable)
465 if (enabled == enable)
468 gpio_direction_output(S3C2410_GPB(0), 0);
470 /* LED driver need a "push" to power on */
471 gpio_direction_output(S3C2410_GPB(0), 1);
472 /* Warm up backlight for one period of PWM.
473 * Without this trick its almost impossible to
474 * enable backlight with low brightness value
477 s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
482 static int rx1950_backlight_init(struct device *dev)
484 WARN_ON(gpio_request(S3C2410_GPB(0), "Backlight"));
485 lcd_pwm = pwm_request(1, "RX1950 LCD");
486 if (IS_ERR(lcd_pwm)) {
487 dev_err(dev, "Unable to request PWM for LCD power!\n");
488 return PTR_ERR(lcd_pwm);
497 static void rx1950_backlight_exit(struct device *dev)
503 gpio_free(S3C2410_GPB(0));
507 static int rx1950_backlight_notify(struct device *dev, int brightness)
519 static struct platform_pwm_backlight_data rx1950_backlight_data = {
521 .max_brightness = 24,
523 .pwm_period_ns = 48000,
524 .init = rx1950_backlight_init,
525 .notify = rx1950_backlight_notify,
526 .exit = rx1950_backlight_exit,
529 static struct platform_device rx1950_backlight = {
530 .name = "pwm-backlight",
532 .parent = &s3c_device_timer[0].dev,
533 .platform_data = &rx1950_backlight_data,
537 static void rx1950_set_mmc_power(unsigned char power_mode, unsigned short vdd)
539 switch (power_mode) {
541 gpio_direction_output(S3C2410_GPJ(1), 0);
545 gpio_direction_output(S3C2410_GPJ(1), 1);
552 static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata = {
553 .gpio_detect = S3C2410_GPF(5),
554 .gpio_wprotect = S3C2410_GPH(8),
555 .set_power = rx1950_set_mmc_power,
556 .ocr_avail = MMC_VDD_32_33,
559 static struct mtd_partition rx1950_nand_part[] = {
564 .mask_flags = MTD_WRITEABLE,
568 .offset = MTDPART_OFS_APPEND,
570 .mask_flags = MTD_WRITEABLE,
574 .offset = MTDPART_OFS_APPEND,
579 .name = "Filesystem",
580 .offset = MTDPART_OFS_APPEND,
581 .size = MTDPART_SIZ_FULL,
586 static struct s3c2410_nand_set rx1950_nand_sets[] = {
590 .nr_partitions = ARRAY_SIZE(rx1950_nand_part),
591 .partitions = rx1950_nand_part,
595 static struct s3c2410_platform_nand rx1950_nand_info = {
599 .nr_sets = ARRAY_SIZE(rx1950_nand_sets),
600 .sets = rx1950_nand_sets,
603 static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = {
604 .vbus_pin = S3C2410_GPG(5),
605 .vbus_pin_inverted = 1,
606 .pullup_pin = S3C2410_GPJ(5),
609 static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata = {
612 .oversampling_shift = 3,
615 static struct gpio_keys_button rx1950_gpio_keys_table[] = {
618 .gpio = S3C2410_GPF(0),
620 .desc = "Power button",
625 .gpio = S3C2410_GPF(7),
627 .desc = "Record button",
631 .gpio = S3C2410_GPG(0),
633 .desc = "Calendar button",
637 .gpio = S3C2410_GPG(2),
639 .desc = "Contacts button",
643 .gpio = S3C2410_GPG(3),
645 .desc = "Mail button",
649 .gpio = S3C2410_GPG(7),
651 .desc = "WLAN button",
655 .gpio = S3C2410_GPG(10),
657 .desc = "Left button",
661 .gpio = S3C2410_GPG(11),
663 .desc = "Right button",
667 .gpio = S3C2410_GPG(4),
673 .gpio = S3C2410_GPG(6),
675 .desc = "Down button",
679 .gpio = S3C2410_GPG(9),
685 static struct gpio_keys_platform_data rx1950_gpio_keys_data = {
686 .buttons = rx1950_gpio_keys_table,
687 .nbuttons = ARRAY_SIZE(rx1950_gpio_keys_table),
690 static struct platform_device rx1950_device_gpiokeys = {
692 .dev.platform_data = &rx1950_gpio_keys_data,
695 static struct uda1380_platform_data uda1380_info = {
696 .gpio_power = S3C2410_GPJ(0),
697 .gpio_reset = S3C2410_GPD(0),
698 .dac_clk = UDA1380_DAC_CLK_SYSCLK,
701 static struct i2c_board_info rx1950_i2c_devices[] = {
703 I2C_BOARD_INFO("uda1380", 0x1a),
704 .platform_data = &uda1380_info,
708 static struct platform_device *rx1950_devices[] __initdata = {
713 &s3c_device_usbgadget,
719 &s3c_device_timer[0],
720 &s3c_device_timer[1],
722 &rx1950_device_gpiokeys,
728 static struct clk *rx1950_clocks[] __initdata = {
733 static void __init rx1950_map_io(void)
735 s3c24xx_clkout0.parent = &clk_h;
736 s3c24xx_clkout1.parent = &clk_f;
738 s3c24xx_register_clocks(rx1950_clocks, ARRAY_SIZE(rx1950_clocks));
740 s3c24xx_init_io(rx1950_iodesc, ARRAY_SIZE(rx1950_iodesc));
741 s3c24xx_init_clocks(16934000);
742 s3c24xx_init_uarts(rx1950_uartcfgs, ARRAY_SIZE(rx1950_uartcfgs));
746 #ifdef CONFIG_PM_H1940
747 memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 8);
753 static void __init rx1950_init_machine(void)
757 s3c24xx_fb_set_platdata(&rx1950_lcd_cfg);
758 s3c24xx_udc_set_platdata(&rx1950_udc_cfg);
759 s3c24xx_ts_set_platdata(&rx1950_ts_cfg);
760 s3c24xx_mci_set_platdata(&rx1950_mmc_cfg);
761 s3c_i2c0_set_platdata(NULL);
762 s3c_nand_set_platdata(&rx1950_nand_info);
764 /* Turn off suspend on both USB ports, and switch the
765 * selectable USB port to USB device mode. */
766 s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
767 S3C2410_MISCCR_USBSUSPND0 |
768 S3C2410_MISCCR_USBSUSPND1, 0x0);
770 /* mmc power is disabled by default */
771 WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power"));
772 gpio_direction_output(S3C2410_GPJ(1), 0);
774 for (i = 0; i < 8; i++)
775 WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power"));
777 for (i = 10; i < 16; i++)
778 WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power"));
780 for (i = 2; i < 8; i++)
781 WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power"));
783 for (i = 11; i < 16; i++)
784 WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power"));
786 WARN_ON(gpio_request(S3C2410_GPB(1), "LCD power"));
788 WARN_ON(gpio_request(S3C2410_GPA(3), "Red blink"));
789 WARN_ON(gpio_request(S3C2410_GPA(4), "Green blink"));
790 WARN_ON(gpio_request(S3C2410_GPJ(6), "LED blink"));
791 gpio_direction_output(S3C2410_GPA(3), 0);
792 gpio_direction_output(S3C2410_GPA(4), 0);
793 gpio_direction_output(S3C2410_GPJ(6), 0);
795 platform_add_devices(rx1950_devices, ARRAY_SIZE(rx1950_devices));
797 i2c_register_board_info(0, rx1950_i2c_devices,
798 ARRAY_SIZE(rx1950_i2c_devices));
801 /* H1940 and RX3715 need to reserve this for suspend */
802 static void __init rx1950_reserve(void)
804 memblock_reserve(0x30003000, 0x1000);
805 memblock_reserve(0x30081000, 0x1000);
808 MACHINE_START(RX1950, "HP iPAQ RX1950")
809 /* Maintainers: Vasily Khoruzhick */
810 .atag_offset = 0x100,
811 .map_io = rx1950_map_io,
812 .reserve = rx1950_reserve,
813 .init_irq = s3c24xx_init_irq,
814 .init_machine = rx1950_init_machine,
815 .init_time = s3c24xx_timer_init,
816 .restart = s3c244x_restart,