[x86] add rootwait option to the kernel command line (#6209)
[openwrt.git] / target / linux / s3c24xx / files-2.6.31 / drivers / leds / leds-gta02-vibrator.c
1 /*
2 * LED driver for the vibrator of the Openmoko GTA01/GTA02 GSM Phones
3 *
4 * (C) 2006-2008 by Openmoko, Inc.
5 * Author: Harald Welte <laforge@openmoko.org>
6 * All rights reserved.
7 *
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.
11 *
12 * Javi Roman <javiroman@kernel-labs.org>:
13 * Implement PWM support for GTA01Bv4 and later
14 */
15
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>
22 #include <plat/pwm.h>
23 #include <mach/regs-gpio.h>
24 #include <mach/gpio-fns.h>
25 #include <plat/regs-timer.h>
26 #include <linux/gta02-vibrator.h>
27
28 #define COUNTER 64
29
30 static struct gta02_vib_priv {
31 struct led_classdev cdev;
32 unsigned int gpio;
33 spinlock_t lock;
34 unsigned int has_pwm;
35 struct s3c2410_pwm pwm;
36
37 unsigned long vib_gpio_pin; /* which pin to meddle with */
38 u8 vib_pwm; /* 0 = OFF -- will ensure GPIO deasserted and stop FIQ */
39 u8 vib_pwm_latched;
40 u32 fiq_count;
41
42 struct gta02_vib_platform_data *pdata;
43 } gta02_vib_priv;
44
45 int gta02_vibrator_fiq_handler(void)
46 {
47 gta02_vib_priv.fiq_count++;
48
49 if (!gta02_vib_priv.vib_pwm_latched && !gta02_vib_priv.vib_pwm)
50 /* idle */
51 return 0;
52
53 if ((u8)gta02_vib_priv.fiq_count == gta02_vib_priv.vib_pwm_latched)
54 s3c2410_gpio_setpin(gta02_vib_priv.vib_gpio_pin, 0);
55
56 if ((u8)gta02_vib_priv.fiq_count)
57 return 1;
58
59 gta02_vib_priv.vib_pwm_latched = gta02_vib_priv.vib_pwm;
60 if (gta02_vib_priv.vib_pwm_latched)
61 s3c2410_gpio_setpin(gta02_vib_priv.vib_gpio_pin, 1);
62
63 return 1;
64 }
65
66 static void gta02_vib_vib_set(struct led_classdev *led_cdev,
67 enum led_brightness value)
68 {
69 gta02_vib_priv.vib_pwm = value; /* set it for FIQ */
70 gta02_vib_priv.pdata->kick_fiq(); /* start up FIQs if not already going */
71 }
72
73 static struct gta02_vib_priv gta02_vib_led = {
74 .cdev = {
75 .name = "gta02:vibrator",
76 .brightness_set = gta02_vib_vib_set,
77 },
78 };
79
80 static int gta02_vib_init_hw(struct gta02_vib_priv *vp)
81 {
82 int rc;
83
84 rc = s3c2410_pwm_init(&vp->pwm);
85 if (rc)
86 return rc;
87
88 vp->pwm.timerid = PWM3;
89 /* use same prescaler as arch/arm/plat-s3c24xx/time.c */
90 vp->pwm.prescaler = (6 - 1) / 2;
91 vp->pwm.divider = S3C2410_TCFG1_MUX3_DIV2;
92 vp->pwm.counter = COUNTER;
93 vp->pwm.comparer = COUNTER;
94
95 rc = s3c2410_pwm_enable(&vp->pwm);
96 if (rc)
97 return rc;
98
99 s3c2410_pwm_start(&vp->pwm);
100
101 return 0;
102 }
103
104 #ifdef CONFIG_PM
105 static int gta02_vib_suspend(struct platform_device *dev, pm_message_t state)
106 {
107 led_classdev_suspend(&gta02_vib_led.cdev);
108 if (gta02_vib_priv.pdata)
109 gta02_vib_priv.pdata->disable_fiq();
110 return 0;
111 }
112
113 static int gta02_vib_resume(struct platform_device *dev)
114 {
115 struct gta02_vib_priv *vp = platform_get_drvdata(dev);
116
117 if (vp->has_pwm)
118 gta02_vib_init_hw(vp);
119
120 led_classdev_resume(&gta02_vib_led.cdev);
121 if (gta02_vib_priv.pdata)
122 gta02_vib_priv.pdata->enable_fiq();
123
124 return 0;
125 }
126 #endif /* CONFIG_PM */
127
128 static int __init gta02_vib_probe(struct platform_device *pdev)
129 {
130 struct resource *r;
131
132 r = platform_get_resource(pdev, 0, 0);
133 if (!r || !r->start)
134 return -EIO;
135
136 gta02_vib_led.gpio = r->start;
137
138 gta02_vib_priv.pdata = pdev->dev.platform_data;
139 platform_set_drvdata(pdev, &gta02_vib_led);
140
141 s3c2410_gpio_setpin(gta02_vib_led.gpio, 0); /* off */
142 s3c2410_gpio_cfgpin(gta02_vib_led.gpio, S3C2410_GPIO_OUTPUT);
143 /* safe, kmalloc'd copy needed for FIQ ISR */
144 gta02_vib_priv.vib_gpio_pin = gta02_vib_led.gpio;
145 gta02_vib_priv.vib_pwm = 0; /* off */
146 spin_lock_init(&gta02_vib_led.lock);
147
148 return led_classdev_register(&pdev->dev, &gta02_vib_led.cdev);
149 }
150
151 static int gta02_vib_remove(struct platform_device *pdev)
152 {
153 gta02_vib_priv.vib_pwm = 0; /* off */
154 /* would only need kick if already off so no kick needed */
155
156 if (gta02_vib_led.has_pwm)
157 s3c2410_pwm_disable(&gta02_vib_led.pwm);
158
159 led_classdev_unregister(&gta02_vib_led.cdev);
160
161 return 0;
162 }
163
164 static struct platform_driver gta02_vib_driver = {
165 .probe = gta02_vib_probe,
166 .remove = gta02_vib_remove,
167 #ifdef CONFIG_PM
168 .suspend = gta02_vib_suspend,
169 .resume = gta02_vib_resume,
170 #endif
171 .driver = {
172 .name = "gta02-vibrator",
173 },
174 };
175
176 static int __init gta02_vib_init(void)
177 {
178 return platform_driver_register(&gta02_vib_driver);
179 }
180
181 static void __exit gta02_vib_exit(void)
182 {
183 platform_driver_unregister(&gta02_vib_driver);
184 }
185
186 module_init(gta02_vib_init);
187 module_exit(gta02_vib_exit);
188
189 MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
190 MODULE_DESCRIPTION("Openmoko Freerunner vibrator driver");
191 MODULE_LICENSE("GPL");
This page took 0.061445 seconds and 5 git commands to generate.