2 * LED driver for the vibrator of the Openmoko GTA01/GTA02 GSM Phones
4 * (C) 2006-2008 by Openmoko, Inc.
5 * Author: Harald Welte <laforge@openmoko.org>
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.
12 * Javi Roman <javiroman@kernel-labs.org>:
13 * Implement PWM support for GTA01Bv4 and later
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/leds.h>
20 #include <mach/hardware.h>
21 #include <asm/mach-types.h>
23 #include <mach/regs-gpio.h>
24 #include <plat/regs-timer.h>
25 #include <linux/gta02-vibrator.h>
29 static struct gta02_vib_priv
{
30 struct led_classdev cdev
;
34 struct s3c2410_pwm pwm
;
36 unsigned long vib_gpio_pin
; /* which pin to meddle with */
37 u8 vib_pwm
; /* 0 = OFF -- will ensure GPIO deasserted and stop FIQ */
41 struct gta02_vib_platform_data
*pdata
;
44 int gta02_vibrator_fiq_handler(void)
46 gta02_vib_priv
.fiq_count
++;
48 if (!gta02_vib_priv
.vib_pwm_latched
&& !gta02_vib_priv
.vib_pwm
)
52 if ((u8
)gta02_vib_priv
.fiq_count
== gta02_vib_priv
.vib_pwm_latched
)
53 s3c2410_gpio_setpin(gta02_vib_priv
.vib_gpio_pin
, 0);
55 if ((u8
)gta02_vib_priv
.fiq_count
)
58 gta02_vib_priv
.vib_pwm_latched
= gta02_vib_priv
.vib_pwm
;
59 if (gta02_vib_priv
.vib_pwm_latched
)
60 s3c2410_gpio_setpin(gta02_vib_priv
.vib_gpio_pin
, 1);
65 static void gta02_vib_vib_set(struct led_classdev
*led_cdev
,
66 enum led_brightness value
)
68 gta02_vib_priv
.vib_pwm
= value
; /* set it for FIQ */
69 gta02_vib_priv
.pdata
->kick_fiq(); /* start up FIQs if not already going */
72 static struct gta02_vib_priv gta02_vib_led
= {
74 .name
= "gta02:vibrator",
75 .brightness_set
= gta02_vib_vib_set
,
79 static int gta02_vib_init_hw(struct gta02_vib_priv
*vp
)
83 rc
= s3c2410_pwm_init(&vp
->pwm
);
87 vp
->pwm
.timerid
= PWM3
;
88 /* use same prescaler as arch/arm/plat-s3c24xx/time.c */
89 vp
->pwm
.prescaler
= (6 - 1) / 2;
90 vp
->pwm
.divider
= S3C2410_TCFG1_MUX3_DIV2
;
91 vp
->pwm
.counter
= COUNTER
;
92 vp
->pwm
.comparer
= COUNTER
;
94 rc
= s3c2410_pwm_enable(&vp
->pwm
);
98 s3c2410_pwm_start(&vp
->pwm
);
104 static int gta02_vib_suspend(struct platform_device
*dev
, pm_message_t state
)
106 led_classdev_suspend(>a02_vib_led
.cdev
);
107 if (gta02_vib_priv
.pdata
)
108 gta02_vib_priv
.pdata
->disable_fiq();
112 static int gta02_vib_resume(struct platform_device
*dev
)
114 struct gta02_vib_priv
*vp
= platform_get_drvdata(dev
);
117 gta02_vib_init_hw(vp
);
119 led_classdev_resume(>a02_vib_led
.cdev
);
120 if (gta02_vib_priv
.pdata
)
121 gta02_vib_priv
.pdata
->enable_fiq();
125 #endif /* CONFIG_PM */
127 static int __init
gta02_vib_probe(struct platform_device
*pdev
)
131 r
= platform_get_resource(pdev
, 0, 0);
135 gta02_vib_led
.gpio
= r
->start
;
137 gta02_vib_priv
.pdata
= pdev
->dev
.platform_data
;
138 platform_set_drvdata(pdev
, >a02_vib_led
);
140 s3c2410_gpio_setpin(gta02_vib_led
.gpio
, 0); /* off */
141 s3c2410_gpio_cfgpin(gta02_vib_led
.gpio
, S3C2410_GPIO_OUTPUT
);
142 /* safe, kmalloc'd copy needed for FIQ ISR */
143 gta02_vib_priv
.vib_gpio_pin
= gta02_vib_led
.gpio
;
144 gta02_vib_priv
.vib_pwm
= 0; /* off */
145 spin_lock_init(>a02_vib_led
.lock
);
147 return led_classdev_register(&pdev
->dev
, >a02_vib_led
.cdev
);
150 static int gta02_vib_remove(struct platform_device
*pdev
)
152 gta02_vib_priv
.vib_pwm
= 0; /* off */
153 /* would only need kick if already off so no kick needed */
155 if (gta02_vib_led
.has_pwm
)
156 s3c2410_pwm_disable(>a02_vib_led
.pwm
);
158 led_classdev_unregister(>a02_vib_led
.cdev
);
163 static struct platform_driver gta02_vib_driver
= {
164 .probe
= gta02_vib_probe
,
165 .remove
= gta02_vib_remove
,
167 .suspend
= gta02_vib_suspend
,
168 .resume
= gta02_vib_resume
,
171 .name
= "gta02-vibrator",
175 static int __init
gta02_vib_init(void)
177 return platform_driver_register(>a02_vib_driver
);
180 static void __exit
gta02_vib_exit(void)
182 platform_driver_unregister(>a02_vib_driver
);
185 module_init(gta02_vib_init
);
186 module_exit(gta02_vib_exit
);
188 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
189 MODULE_DESCRIPTION("Openmoko Freerunner vibrator driver");
190 MODULE_LICENSE("GPL");