1 From ca57dbb5effd245e2619f4b730f8247f7279f954 Mon Sep 17 00:00:00 2001
2 From: Simon Kagstrom <simon.kagstrom@gmail.com>
3 Date: Thu, 16 Oct 2008 01:19:47 +0100
4 Subject: [PATCH] : lis302dl-open-floodgates-on-zero-threshold.patch
6 Generate data ready interrupts if threshold is zero
8 From: Simon Kagstrom <simon.kagstrom@gmail.com>
10 If the threshold is set to zero, enable the data ready interrupt
11 (generated one interrupt per datum). Otherwise use the freefall
14 Signed-off-by: Simon Kagstrom <simon.kagstrom@gmail.com>
16 drivers/input/misc/lis302dl.c | 64 +++++++++++++++++++++++++++-------------
17 1 files changed, 43 insertions(+), 21 deletions(-)
19 diff --git a/drivers/input/misc/lis302dl.c b/drivers/input/misc/lis302dl.c
20 index d738199..e404a45 100644
21 --- a/drivers/input/misc/lis302dl.c
22 +++ b/drivers/input/misc/lis302dl.c
24 #include <linux/lis302dl.h>
26 /* Utility functions */
28 static u8 __reg_read(struct lis302dl_info *lis, u8 reg)
30 return (lis->pdata->lis302dl_bitbang_reg_read)(lis, reg);
31 @@ -132,6 +133,36 @@ static void __lis302dl_int_mode(struct device *dev, int int_pin,
35 +static void __enable_data_collection(struct lis302dl_info *lis)
37 + u_int8_t ctrl1 = LIS302DL_CTRL1_PD | LIS302DL_CTRL1_Xen |
38 + LIS302DL_CTRL1_Yen | LIS302DL_CTRL1_Zen;
40 + /* make sure we're powered up and generate data ready */
41 + __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, ctrl1);
43 + /* If the threshold is zero, let the device generated an interrupt
45 + if (lis->threshold == 0) {
46 + __reg_write(lis, LIS302DL_REG_CTRL2, 0);
47 + __lis302dl_int_mode(lis->dev, 1, LIS302DL_INTMODE_DATA_READY);
48 + __lis302dl_int_mode(lis->dev, 2, LIS302DL_INTMODE_DATA_READY);
50 + __reg_write(lis, LIS302DL_REG_CTRL2,
51 + LIS302DL_CTRL2_HPFF1);
52 + __reg_write(lis, LIS302DL_REG_FF_WU_THS_1, lis->threshold);
53 + __reg_write(lis, LIS302DL_REG_FF_WU_DURATION_1, lis->duration);
55 + /* Clear the HP filter "starting point" */
56 + __reg_read(lis, LIS302DL_REG_HP_FILTER_RESET);
57 + __reg_write(lis, LIS302DL_REG_FF_WU_CFG_1,
58 + LIS302DL_FFWUCFG_XHIE | LIS302DL_FFWUCFG_YHIE |
59 + LIS302DL_FFWUCFG_ZHIE);
60 + __lis302dl_int_mode(lis->dev, 1, LIS302DL_INTMODE_FF_WU_12);
61 + __lis302dl_int_mode(lis->dev, 2, LIS302DL_INTMODE_FF_WU_12);
66 static void _report_btn_single(struct input_dev *inp, int btn)
68 @@ -263,7 +294,7 @@ static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
69 /* Adjust the threshold */
70 lis->threshold = __mg_to_threshold(lis, threshold_mg);
71 if (lis->flags & LIS302DL_F_INPUT_OPEN)
72 - __reg_write(lis, LIS302DL_REG_FF_WU_THS_1, lis->threshold);
73 + __enable_data_collection(lis);
75 local_irq_restore(flags);
77 @@ -294,8 +325,14 @@ static ssize_t set_threshold(struct device *dev, struct device_attribute *attr,
79 /* Set the threshold and write it out if the device is used */
80 lis->threshold = __mg_to_threshold(lis, val);
81 - if (lis->flags & LIS302DL_F_INPUT_OPEN)
82 - __reg_write(lis, LIS302DL_REG_FF_WU_THS_1, lis->threshold);
84 + if (lis->flags & LIS302DL_F_INPUT_OPEN) {
85 + unsigned long flags;
87 + local_irq_save(flags);
88 + __enable_data_collection(lis);
89 + local_irq_restore(flags);
94 @@ -562,29 +599,14 @@ static struct attribute_group lis302dl_attr_group = {
97 /* input device handling and driver core interaction */
99 static int lis302dl_input_open(struct input_dev *inp)
101 struct lis302dl_info *lis = inp->private;
102 - u_int8_t ctrl1 = LIS302DL_CTRL1_PD | LIS302DL_CTRL1_Xen |
103 - LIS302DL_CTRL1_Yen | LIS302DL_CTRL1_Zen;
104 - u_int8_t ctrl2 = LIS302DL_CTRL2_HPFF1;
107 local_irq_save(flags);
108 - /* make sure we're powered up and generate data ready */
109 - __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, ctrl1, ctrl1);
111 - __reg_write(lis, LIS302DL_REG_CTRL2,
113 - __reg_write(lis, LIS302DL_REG_FF_WU_THS_1, lis->threshold);
114 - __reg_write(lis, LIS302DL_REG_FF_WU_DURATION_1, lis->duration);
116 - /* Clear the HP filter "starting point" */
117 - __reg_read(lis, LIS302DL_REG_HP_FILTER_RESET);
118 - __reg_write(lis, LIS302DL_REG_FF_WU_CFG_1, LIS302DL_FFWUCFG_XHIE |
119 - LIS302DL_FFWUCFG_YHIE | LIS302DL_FFWUCFG_ZHIE);
121 + __enable_data_collection(lis);
122 lis->flags |= LIS302DL_F_INPUT_OPEN;
124 /* kick it off -- since we are edge triggered, if we missed the edge
125 @@ -736,8 +758,8 @@ static int __devinit lis302dl_probe(struct platform_device *pdev)
126 /* push-pull, active-low */
127 __reg_write(lis, LIS302DL_REG_CTRL3, LIS302DL_CTRL3_IHL);
129 - __lis302dl_int_mode(lis->dev, 1, LIS302DL_INTMODE_FF_WU_12);
130 - __lis302dl_int_mode(lis->dev, 2, LIS302DL_INTMODE_FF_WU_12);
131 + __lis302dl_int_mode(lis->dev, 1, LIS302DL_INTMODE_GND);
132 + __lis302dl_int_mode(lis->dev, 2, LIS302DL_INTMODE_GND);
134 __reg_read(lis, LIS302DL_REG_STATUS);
135 __reg_read(lis, LIS302DL_REG_FF_WU_SRC_1);