[ar71xx] preliminary support for the Ubiquiti RouterStation Pro
[openwrt.git] / target / linux / s3c24xx / patches-2.6.24 / 1307--lis302dl-threshold-configuration-in-mg.patch.patch
1 From 5e2b5ddaf95985744e0e0c28ba6dac83c093fd15 Mon Sep 17 00:00:00 2001
2 From: Simon Kagstrom <simon.kagstrom@gmail.com>
3 Date: Thu, 16 Oct 2008 01:19:29 +0100
4 Subject: [PATCH] : lis302dl-threshold-configuration-in-mg.patch
5
6 Change the threshold configuration to be set in mg instead
7
8 From: Simon Kagstrom <simon.kagstrom@gmail.com>
9
10 This patch changes the threshold sysfs file to handle values in mg
11 instead of the device-values. Overrun values have also been corrected
12 and the sampler function now honors the FS bit.
13
14 Signed-off-by: Simon Kagstrom <simon.kagstrom@gmail.com>
15 ---
16 drivers/input/misc/lis302dl.c | 49 ++++++++++++++++++++++++++++++++--------
17 1 files changed, 39 insertions(+), 10 deletions(-)
18
19 diff --git a/drivers/input/misc/lis302dl.c b/drivers/input/misc/lis302dl.c
20 index 300918d..c1b1d67 100644
21 --- a/drivers/input/misc/lis302dl.c
22 +++ b/drivers/input/misc/lis302dl.c
23 @@ -97,6 +97,24 @@ static int __duration_to_ms(struct lis302dl_info *lis, int duration)
24 return duration * 10;
25 }
26
27 +static u8 __mg_to_threshold(struct lis302dl_info *lis, int mg)
28 +{
29 + /* If FS is set each bit is 71mg, otherwise 18mg. The THS register
30 + * has 7 bits for the threshold value */
31 + if (lis->flags & LIS302DL_F_FS)
32 + return min(mg / 71, 127);
33 +
34 + return min(mg / 18, 127);
35 +}
36 +
37 +static int __threshold_to_mg(struct lis302dl_info *lis, u8 threshold)
38 +{
39 + if (lis->flags & LIS302DL_F_FS)
40 + return threshold * 71;
41 +
42 + return threshold * 18;
43 +}
44 +
45 /* interrupt handling related */
46
47 enum lis302dl_intmode {
48 @@ -146,23 +164,24 @@ static void _report_btn_double(struct input_dev *inp, int btn)
49 }
50 #endif
51
52 -#define MG_PER_SAMPLE 18
53
54 static void lis302dl_bitbang_read_sample(struct lis302dl_info *lis)
55 {
56 u8 data = 0xc0 | LIS302DL_REG_OUT_X; /* read, autoincrement */
57 u8 read[5];
58 unsigned long flags;
59 + int mg_per_sample;
60
61 local_irq_save(flags);
62 + mg_per_sample = __threshold_to_mg(lis, 1);
63
64 (lis->pdata->lis302dl_bitbang)(lis, &data, 1, &read[0], 5);
65
66 local_irq_restore(flags);
67
68 - input_report_rel(lis->input_dev, REL_X, MG_PER_SAMPLE * (s8)read[0]);
69 - input_report_rel(lis->input_dev, REL_Y, MG_PER_SAMPLE * (s8)read[2]);
70 - input_report_rel(lis->input_dev, REL_Z, MG_PER_SAMPLE * (s8)read[4]);
71 + input_report_rel(lis->input_dev, REL_X, mg_per_sample * (s8)read[0]);
72 + input_report_rel(lis->input_dev, REL_Y, mg_per_sample * (s8)read[2]);
73 + input_report_rel(lis->input_dev, REL_Z, mg_per_sample * (s8)read[4]);
74
75 input_sync(lis->input_dev);
76
77 @@ -234,15 +253,24 @@ static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
78 {
79 struct lis302dl_info *lis = dev_get_drvdata(dev);
80 unsigned long flags;
81 + int threshold_mg = __threshold_to_mg(lis, lis->threshold);
82
83 local_irq_save(flags);
84
85 - if (!strcmp(buf, "9.2\n"))
86 + if (!strcmp(buf, "9.2\n")) {
87 __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS,
88 LIS302DL_CTRL1_FS);
89 - else
90 + lis->flags |= LIS302DL_F_FS;
91 + } else {
92 __reg_set_bit_mask(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_FS,
93 - 0);
94 + 0);
95 + lis->flags &= ~LIS302DL_F_FS;
96 + }
97 +
98 + /* Adjust the threshold */
99 + lis->threshold = __mg_to_threshold(lis, threshold_mg);
100 + if (lis->flags & LIS302DL_F_INPUT_OPEN)
101 + __reg_write(lis, LIS302DL_REG_FF_WU_THS_1, lis->threshold);
102
103 local_irq_restore(flags);
104
105 @@ -256,7 +284,7 @@ static ssize_t show_threshold(struct device *dev, struct device_attribute *attr,
106 {
107 struct lis302dl_info *lis = dev_get_drvdata(dev);
108
109 - return sprintf(buf, "%d\n", lis->threshold);
110 + return sprintf(buf, "%d\n", __threshold_to_mg(lis, lis->threshold));
111 }
112
113 static ssize_t set_threshold(struct device *dev, struct device_attribute *attr,
114 @@ -267,11 +295,12 @@ static ssize_t set_threshold(struct device *dev, struct device_attribute *attr,
115
116 if (sscanf(buf, "%d\n", &val) != 1)
117 return -EINVAL;
118 - if (val < 0 || val > 255)
119 + /* 8g is the maximum if FS is 1 */
120 + if (val < 0 || val > 8000)
121 return -ERANGE;
122
123 /* Set the threshold and write it out if the device is used */
124 - lis->threshold = val;
125 + lis->threshold = __mg_to_threshold(lis, val);
126 if (lis->flags & LIS302DL_F_INPUT_OPEN)
127 __reg_write(lis, LIS302DL_REG_FF_WU_THS_1, lis->threshold);
128
129 --
130 1.5.6.5
131
This page took 0.049023 seconds and 5 git commands to generate.