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