initialize the url field for packages
[openwrt.git] / target / linux / s3c24xx / patches-2.6.24 / 1310--lis302dl-wakeup-configuration.patch.patch
1 From 933f18caaf8f96d1094f064312d416a2fe0b4337 Mon Sep 17 00:00:00 2001
2 From: Simon Kagstrom <simon.kagstrom@gmail.com>
3 Date: Thu, 16 Oct 2008 01:19:56 +0100
4 Subject: [PATCH] : lis302dl-wakeup-configuration.patch
5
6 Setup accelerometer interrupt to wake the device up
7
8 From: Simon Kagstrom <simon.kagstrom@gmail.com>
9
10 The threshold implementation recently broke this functionality. This
11 patch reinstates it again and simplifies the code a bit. It only
12 supports one of the two lis302dl interrupt sources now (which is the
13 only connected one on the openmoko). If you need to configure both, buy
14 an Iphone!
15
16 (Or flame this patch)
17
18
19 Note that, as before, the device immediately wakes up when put to sleep
20 with the wakeup configured. The interface is therefore not currently
21 very useful, but to use it do e.g.,
22
23 echo 1 1 1 180 0 1 > wakeup
24
25 The value is of the form
26
27 X Y Z THRESHOLD DURATION SPEC
28
29 X, Y and Z are threshold values, given as a value > 0, < 0 or 0 to
30 specify if an interrupt should be generated for high or low thresholds
31 or neither (off). THRESHOLD specifies the threshold that must be
32 exceeded, in mg. DURATION specifies the time in milliseconds for which
33 the acceleration should be measured. SPEC is either '1' or '0' and
34 specifies if the thresholds should be taken all together or one at a
35 time ('and' or 'or' mode).
36
37 Echoing '0' to the file turns off the interrupts.
38
39 Signed-off-by: Simon Kagstrom <simon.kagstrom@gmail.com>
40 ---
41 drivers/input/misc/lis302dl.c | 204 ++++++++++++-----------------------------
42 include/linux/lis302dl.h | 6 +
43 2 files changed, 63 insertions(+), 147 deletions(-)
44
45 diff --git a/drivers/input/misc/lis302dl.c b/drivers/input/misc/lis302dl.c
46 index e404a45..f743a24 100644
47 --- a/drivers/input/misc/lis302dl.c
48 +++ b/drivers/input/misc/lis302dl.c
49 @@ -133,6 +133,23 @@ static void __lis302dl_int_mode(struct device *dev, int int_pin,
50 }
51 }
52
53 +static void __enable_wakeup(struct lis302dl_info *lis)
54 +{
55 + /* First zero to get to a known state */
56 + __reg_write(lis, LIS302DL_REG_FF_WU_CFG_1,
57 + lis->wakeup.cfg);
58 + __reg_write(lis, LIS302DL_REG_FF_WU_THS_1,
59 + lis->wakeup.threshold);
60 + __reg_write(lis, LIS302DL_REG_FF_WU_DURATION_1,
61 + lis->wakeup.duration);
62 +
63 + /* Route the interrupt for wakeup */
64 + __lis302dl_int_mode(lis->dev, 1,
65 + LIS302DL_INTMODE_FF_WU_1);
66 +
67 + __reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD);
68 +}
69 +
70 static void __enable_data_collection(struct lis302dl_info *lis)
71 {
72 u_int8_t ctrl1 = LIS302DL_CTRL1_PD | LIS302DL_CTRL1_Xen |
73 @@ -395,73 +412,33 @@ static ssize_t lis302dl_dump(struct device *dev, struct device_attribute *attr,
74 static DEVICE_ATTR(dump, S_IRUGO, lis302dl_dump, NULL);
75
76 /* Configure freefall/wakeup interrupts */
77 -static ssize_t set_freefall_common(int which, struct device *dev,
78 - struct device_attribute *attr, const char *buf, size_t count)
79 +static ssize_t set_wakeup(struct device *dev, struct device_attribute *attr,
80 + const char *buf, size_t count)
81 {
82 struct lis302dl_info *lis = dev_get_drvdata(dev);
83 u_int8_t x_lo, y_lo, z_lo;
84 u_int8_t x_hi, y_hi, z_hi;
85 - int duration;
86 - int threshold;
87 - int and_events;
88 - int r_ths = LIS302DL_REG_FF_WU_THS_1; /* registers, assume first pin */
89 - int r_duration = LIS302DL_REG_FF_WU_DURATION_1;
90 - int r_cfg = LIS302DL_REG_FF_WU_CFG_1;
91 - int flag_mask = LIS302DL_F_WUP_FF_1;
92 - int intmode = LIS302DL_INTMODE_FF_WU_1;
93 + int duration, threshold, and_events;
94 int x, y, z;
95 - int ms;
96 - unsigned long flags;
97 -
98 - /* Configure for second freefall/wakeup pin */
99 - if (which == 2) {
100 - r_ths = LIS302DL_REG_FF_WU_THS_2;
101 - r_duration = LIS302DL_REG_FF_WU_DURATION_2;
102 - r_cfg = LIS302DL_REG_FF_WU_CFG_2;
103 - flag_mask = LIS302DL_F_WUP_FF_2;
104 - intmode = LIS302DL_INTMODE_FF_WU_2;
105
106 - printk(KERN_WARNING
107 - "Configuring second freefall / wakeup interrupt\n");
108 - }
109 -
110 - /* Parse the input */
111 + /* Zero turns the feature off */
112 if (strcmp(buf, "0\n") == 0) {
113 - /* Turn off the interrupt */
114 - local_irq_save(flags);
115 - if (lis->flags & LIS302DL_F_IRQ_WAKE)
116 - disable_irq_wake(lis->pdata->interrupt);
117 - __lis302dl_int_mode(lis->dev, which,
118 - LIS302DL_INTMODE_DATA_READY);
119 - lis->flags &= ~(flag_mask | LIS302DL_F_IRQ_WAKE);
120 -
121 - __reg_write(lis, r_cfg, 0);
122 - __reg_write(lis, r_ths, 0);
123 - __reg_write(lis, r_duration, 0);
124 + lis->wakeup.active = 0;
125
126 - /* Power off unless the input subsystem is using the device */
127 - if (!(lis->flags & LIS302DL_F_INPUT_OPEN))
128 - __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1,
129 - LIS302DL_CTRL1_PD, 0);
130 -
131 - local_irq_restore(flags);
132 + if (lis->flags & LIS302DL_F_IRQ_WAKE) {
133 + disable_irq_wake(lis->pdata->interrupt);
134 + lis->flags &= ~LIS302DL_F_IRQ_WAKE;
135 + }
136
137 return count;
138 }
139
140 - if (sscanf(buf, "%d %d %d %d %d %d", &x, &y, &z, &threshold, &ms,
141 - &and_events) != 6)
142 + if (sscanf(buf, "%d %d %d %d %d %d", &x, &y, &z, &threshold, &duration,
143 + &and_events) != 6)
144 return -EINVAL;
145
146 - local_irq_save(flags);
147 - duration = __ms_to_duration(lis, ms);
148 - local_irq_save(flags);
149 -
150 - if (duration < 0)
151 - return -ERANGE;
152 -
153 - /* 7 bits */
154 - if (threshold < 0 || threshold > 127)
155 + if (duration < 0 || duration > 2550 ||
156 + threshold < 0 || threshold > 8000)
157 return -ERANGE;
158
159 /* Interrupt flags */
160 @@ -472,91 +449,38 @@ static ssize_t set_freefall_common(int which, struct device *dev,
161 y_hi = y > 0 ? LIS302DL_FFWUCFG_YHIE : 0;
162 z_hi = z > 0 ? LIS302DL_FFWUCFG_ZHIE : 0;
163
164 - /* Setup the configuration registers */
165 - local_irq_save(flags);
166 - /* First zero to get to a known state */
167 - __reg_write(lis, r_cfg, 0);
168 - __reg_write(lis, r_cfg,
169 - (and_events ? LIS302DL_FFWUCFG_AOI : 0) |
170 - x_lo | x_hi | y_lo | y_hi | z_lo | z_hi);
171 - __reg_write(lis, r_ths, threshold & ~LIS302DL_FFWUTHS_DCRM);
172 - __reg_write(lis, r_duration, duration);
173 + lis->wakeup.duration = __ms_to_duration(lis, duration);
174 + lis->wakeup.threshold = __mg_to_threshold(lis, threshold);
175 + lis->wakeup.cfg = (and_events ? LIS302DL_FFWUCFG_AOI : 0) |
176 + x_lo | x_hi | y_lo | y_hi | z_lo | z_hi;
177
178 - /* Route the interrupt for wakeup */
179 - __lis302dl_int_mode(lis->dev, which, intmode);
180 -
181 - /* Power up the device and note that we want to wake up from
182 - * this interrupt */
183 - if (!(lis->flags & LIS302DL_F_IRQ_WAKE))
184 + if (!(lis->flags & LIS302DL_F_IRQ_WAKE)) {
185 enable_irq_wake(lis->pdata->interrupt);
186 -
187 - lis->flags |= flag_mask | LIS302DL_F_IRQ_WAKE;
188 - __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD,
189 - LIS302DL_CTRL1_PD);
190 - local_irq_restore(flags);
191 + lis->flags |= LIS302DL_F_IRQ_WAKE;
192 + }
193 + lis->wakeup.active = 1;
194
195 return count;
196 }
197
198 -static ssize_t set_freefall_1(struct device *dev, struct device_attribute *attr,
199 - const char *buf, size_t count)
200 -{
201 - return set_freefall_common(1, dev, attr, buf, count);
202 -}
203 -static ssize_t set_freefall_2(struct device *dev, struct device_attribute *attr,
204 - const char *buf, size_t count)
205 -{
206 - return set_freefall_common(2, dev, attr, buf, count);
207 -}
208 -
209 -
210 -static ssize_t show_freefall_common(int which, struct device *dev,
211 +static ssize_t show_wakeup(struct device *dev,
212 struct device_attribute *attr, char *buf)
213 {
214 struct lis302dl_info *lis = dev_get_drvdata(dev);
215 - u_int8_t duration;
216 - u_int8_t threshold;
217 - u_int8_t config;
218 - u_int8_t r4;
219 - u_int8_t r5;
220 - int r_ths = LIS302DL_REG_FF_WU_THS_1; /* registers, assume first pin */
221 - int r_duration = LIS302DL_REG_FF_WU_DURATION_1;
222 - int r_cfg = LIS302DL_REG_FF_WU_CFG_1;
223 - int r_src = LIS302DL_REG_FF_WU_SRC_1;
224 - unsigned long flags;
225 - int ms;
226 -
227 - /* Configure second freefall/wakeup pin */
228 - if (which == 2) {
229 - r_ths = LIS302DL_REG_FF_WU_THS_2;
230 - r_duration = LIS302DL_REG_FF_WU_DURATION_2;
231 - r_cfg = LIS302DL_REG_FF_WU_CFG_2;
232 - r_src = LIS302DL_REG_FF_WU_SRC_2;
233 - }
234 -
235 - local_irq_save(flags);
236 - config = __reg_read(lis, r_cfg);
237 - threshold = __reg_read(lis, r_ths);
238 - duration = __reg_read(lis, r_duration);
239 - r4 = __reg_read(lis, r_src);
240 - r5 = __reg_read(lis, LIS302DL_REG_CTRL3);
241 - ms = __duration_to_ms(lis, duration);
242 - local_irq_restore(flags);
243 + u8 config;
244
245 /* All events off? */
246 - if ((config & (LIS302DL_FFWUCFG_XLIE | LIS302DL_FFWUCFG_XHIE |
247 - LIS302DL_FFWUCFG_YLIE | LIS302DL_FFWUCFG_YHIE |
248 - LIS302DL_FFWUCFG_ZLIE | LIS302DL_FFWUCFG_ZHIE)) == 0)
249 + if (!lis->wakeup.active)
250 return sprintf(buf, "off\n");
251
252 + config = lis->wakeup.cfg;
253
254 return sprintf(buf,
255 - "%s events, %s interrupt, duration %d, threshold %d, "
256 + "%s events, duration %d, threshold %d, "
257 "enabled: %s %s %s %s %s %s\n",
258 (config & LIS302DL_FFWUCFG_AOI) == 0 ? "or" : "and",
259 - (config & LIS302DL_FFWUCFG_LIR) == 0 ?
260 - "don't latch" : "latch",
261 - ms, threshold,
262 + __duration_to_ms(lis, lis->wakeup.duration),
263 + __threshold_to_mg(lis, lis->wakeup.threshold),
264 (config & LIS302DL_FFWUCFG_XLIE) == 0 ? "---" : "xlo",
265 (config & LIS302DL_FFWUCFG_XHIE) == 0 ? "---" : "xhi",
266 (config & LIS302DL_FFWUCFG_YLIE) == 0 ? "---" : "ylo",
267 @@ -565,22 +489,7 @@ static ssize_t show_freefall_common(int which, struct device *dev,
268 (config & LIS302DL_FFWUCFG_ZHIE) == 0 ? "---" : "zhi");
269 }
270
271 -static ssize_t show_freefall_1(struct device *dev,
272 - struct device_attribute *attr, char *buf)
273 -{
274 - return show_freefall_common(1, dev, attr, buf);
275 -}
276 -
277 -static ssize_t show_freefall_2(struct device *dev,
278 - struct device_attribute *attr, char *buf)
279 -{
280 - return show_freefall_common(2, dev, attr, buf);
281 -}
282 -
283 -static DEVICE_ATTR(freefall_wakeup_1, S_IRUGO | S_IWUSR, show_freefall_1,
284 - set_freefall_1);
285 -static DEVICE_ATTR(freefall_wakeup_2, S_IRUGO | S_IWUSR, show_freefall_2,
286 - set_freefall_2);
287 +static DEVICE_ATTR(wakeup, S_IRUGO | S_IWUSR, show_wakeup, set_wakeup);
288
289 static struct attribute *lis302dl_sysfs_entries[] = {
290 &dev_attr_sample_rate.attr,
291 @@ -588,8 +497,7 @@ static struct attribute *lis302dl_sysfs_entries[] = {
292 &dev_attr_threshold.attr,
293 &dev_attr_duration.attr,
294 &dev_attr_dump.attr,
295 - &dev_attr_freefall_wakeup_1.attr,
296 - &dev_attr_freefall_wakeup_2.attr,
297 + &dev_attr_wakeup.attr,
298 NULL
299 };
300
301 @@ -715,6 +623,7 @@ static int __devinit lis302dl_probe(struct platform_device *pdev)
302 */
303 lis->threshold = 1;
304 lis->duration = 0;
305 + memset(&lis->wakeup, 0, sizeof(lis->wakeup));
306
307 lis->input_dev->private = lis;
308 lis->input_dev->name = pdata->name;
309 @@ -845,8 +754,7 @@ static int lis302dl_suspend(struct platform_device *pdev, pm_message_t state)
310 int n;
311
312 /* determine if we want to wake up from the accel. */
313 - if (lis->flags & LIS302DL_F_WUP_FF ||
314 - lis->flags & LIS302DL_F_WUP_CLICK)
315 + if (lis->flags & LIS302DL_F_WUP_CLICK)
316 return 0;
317
318 disable_irq(lis->pdata->interrupt);
319 @@ -866,10 +774,13 @@ static int lis302dl_suspend(struct platform_device *pdev, pm_message_t state)
320 lis->regs[regs_to_save[n]] =
321 __reg_read(lis, regs_to_save[n]);
322
323 - /* power down */
324 - tmp = __reg_read(lis, LIS302DL_REG_CTRL1);
325 - tmp &= ~LIS302DL_CTRL1_PD;
326 - __reg_write(lis, LIS302DL_REG_CTRL1, tmp);
327 + /* power down or enable wakeup */
328 + if (!lis->wakeup.active) {
329 + tmp = __reg_read(lis, LIS302DL_REG_CTRL1);
330 + tmp &= ~LIS302DL_CTRL1_PD;
331 + __reg_write(lis, LIS302DL_REG_CTRL1, tmp);
332 + } else
333 + __enable_wakeup(lis);
334
335 /* place our IO to the device in sleep-compatible states */
336 (lis->pdata->lis302dl_suspend_io)(lis, 0);
337 @@ -885,8 +796,7 @@ static int lis302dl_resume(struct platform_device *pdev)
338 unsigned long flags;
339 int n;
340
341 - if (lis->flags & LIS302DL_F_WUP_FF ||
342 - lis->flags & LIS302DL_F_WUP_CLICK)
343 + if (lis->flags & LIS302DL_F_WUP_CLICK)
344 return 0;
345
346 local_irq_save(flags);
347 diff --git a/include/linux/lis302dl.h b/include/linux/lis302dl.h
348 index f7aa956..f4121d9 100644
349 --- a/include/linux/lis302dl.h
350 +++ b/include/linux/lis302dl.h
351 @@ -31,6 +31,12 @@ struct lis302dl_info {
352 unsigned int flags;
353 unsigned int threshold;
354 unsigned int duration;
355 + struct {
356 + u8 cfg;
357 + u8 threshold;
358 + u8 duration;
359 + int active;
360 + } wakeup;
361 u_int8_t regs[0x40];
362 };
363
364 --
365 1.5.6.5
366
This page took 0.070526 seconds and 5 git commands to generate.