summaryrefslogtreecommitdiffstats
path: root/target/linux/s3c24xx/patches-2.6.24/1211-fix-lis302dl-resume-and-init-reload-boot-coefficient.patch
blob: bbc4190d526ada02cc64d9f385b08038e12d13b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
From b70bd0433a197f93f927f7b5720efe889aa4b430 Mon Sep 17 00:00:00 2001
From: Andy Green <andy@openmoko.com>
Date: Wed, 2 Jul 2008 22:43:45 +0100
Subject: [PATCH] fix-lis302dl-resume-and-init-reload-boot-coefficients.patch
 Reported-by: John Lee <john_lee@openmoko.com>

We don't reset the devices either at init or resume, where init
means use the BOOT bit to reload device calibration coefficients
from internal EEPROM.  John Lee saw brain-damaged behaviour after
resume and sometimes after boot (since it may not have lost power
to force a BOOT itself that makes sense).

This patch

 - adds a diagnostic dump feature down /sys
 - forces BOOT action on init and resume, and waits for
   completion
 - makes sure XYZ capture is enabled on resume
 - adds some constants in the .h and removes some magic numbers
   in the code by using them

Signed-off-by: Andy Green <andy@openmoko.com>
---
 drivers/input/misc/lis302dl.c |   78 +++++++++++++++++++++++++++++++++++++++--
 include/linux/lis302dl.h      |    9 +++++
 2 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/drivers/input/misc/lis302dl.c b/drivers/input/misc/lis302dl.c
index 6067dba..de8478d 100644
--- a/drivers/input/misc/lis302dl.c
+++ b/drivers/input/misc/lis302dl.c
@@ -221,9 +221,37 @@ static ssize_t set_scale(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(full_scale, S_IRUGO | S_IWUSR, show_scale, set_scale);
 
+static ssize_t lis302dl_dump(struct device *dev, struct device_attribute *attr,
+			  char *buf)
+{
+	struct lis302dl_info *lis = dev_get_drvdata(dev);
+	int n = 0;
+	u8 reg[0x40];
+	char *end = buf;
+	unsigned long flags;
+
+	local_save_flags(flags);
+
+	for (n = 0; n < sizeof(reg); n++)
+		reg[n] = reg_read(lis, n);
+
+	local_irq_restore(flags);
+
+	for (n = 0; n < sizeof(reg); n += 16) {
+		hex_dump_to_buffer(reg + n, 16, 16, 1, end, 128, 0);
+		end += strlen(end);
+		*end++ = '\n';
+		*end++ = '\0';
+	}
+
+	return end - buf;
+}
+static DEVICE_ATTR(dump, S_IRUGO, lis302dl_dump, NULL);
+
 static struct attribute *lis302dl_sysfs_entries[] = {
 	&dev_attr_sample_rate.attr,
 	&dev_attr_full_scale.attr,
+	&dev_attr_dump.attr,
 	NULL
 };
 
@@ -276,6 +304,24 @@ static void lis302dl_input_close(struct input_dev *inp)
 	local_irq_restore(flags);
 }
 
+/* get the device to reload its coefficients from EEPROM and wait for it
+ * to complete
+ */
+
+static int __lis302dl_reset_device(struct lis302dl_info *lis)
+{
+	int timeout = 10;
+
+	reg_write(lis, LIS302DL_REG_CTRL2, LIS302DL_CTRL2_BOOT |
+							    LIS302DL_CTRL2_FDS);
+
+	while ((reg_read(lis, LIS302DL_REG_CTRL2) & LIS302DL_CTRL2_BOOT) &&
+								    (timeout--))
+		mdelay(1);
+
+	return !!(timeout < 0);
+}
+
 static int __devinit lis302dl_probe(struct spi_device *spi)
 {
 	int rc;
@@ -347,12 +393,24 @@ static int __devinit lis302dl_probe(struct spi_device *spi)
 		goto bail_inp_dev;
 	}
 
-	reg_write(lis, LIS302DL_REG_CTRL1, 0x47);
-	reg_write(lis, LIS302DL_REG_CTRL3, 0xc0);
+	if (__lis302dl_reset_device(lis))
+		dev_err(&spi->dev, "device BOOT reload failed\n");
+
+	/* force us powered */
+	reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD |
+					   LIS302DL_CTRL1_Xen |
+					   LIS302DL_CTRL1_Yen |
+					   LIS302DL_CTRL1_Zen);
+	mdelay(1);
+
+	reg_write(lis, LIS302DL_REG_CTRL2, 0);
+	reg_write(lis, LIS302DL_REG_CTRL3, LIS302DL_CTRL3_PP_OD |
+							    LIS302DL_CTRL3_IHL);
 	reg_write(lis, LIS302DL_REG_FF_WU_THS_1, 0x14);
 	reg_write(lis, LIS302DL_REG_FF_WU_DURATION_1, 0x00);
 	reg_write(lis, LIS302DL_REG_FF_WU_CFG_1, 0x95);
 
+	/* start off in powered down mode; we power up when someone opens us */
 	reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_Xen |
 					   LIS302DL_CTRL1_Yen |
 			 		   LIS302DL_CTRL1_Zen);
@@ -494,8 +552,22 @@ static int lis302dl_resume(struct spi_device *spi)
 	/* get our IO to the device back in operational states */
 	(lis->pdata->lis302dl_suspend_io)(lis, 1);
 
+	/* resume from powerdown first! */
+	reg_write(lis, LIS302DL_REG_CTRL1, LIS302DL_CTRL1_PD |
+					   LIS302DL_CTRL1_Xen |
+					   LIS302DL_CTRL1_Yen |
+					   LIS302DL_CTRL1_Zen);
+	mdelay(1);
+
+	if (__lis302dl_reset_device(lis))
+		dev_err(&spi->dev, "device BOOT reload failed\n");
+
 	/* restore registers after resume */
-	reg_write(lis, LIS302DL_REG_CTRL1, lis->regs[LIS302DL_REG_CTRL1]);
+	reg_write(lis, LIS302DL_REG_CTRL1, lis->regs[LIS302DL_REG_CTRL1] |
+						LIS302DL_CTRL1_PD |
+						LIS302DL_CTRL1_Xen |
+						LIS302DL_CTRL1_Yen |
+						LIS302DL_CTRL1_Zen);
 	reg_write(lis, LIS302DL_REG_CTRL2, lis->regs[LIS302DL_REG_CTRL2]);
 	reg_write(lis, LIS302DL_REG_CTRL3, lis->regs[LIS302DL_REG_CTRL3]);
 	reg_write(lis, LIS302DL_REG_FF_WU_CFG_1,
diff --git a/include/linux/lis302dl.h b/include/linux/lis302dl.h
index 0d6b4c4..4d8ded9 100644
--- a/include/linux/lis302dl.h
+++ b/include/linux/lis302dl.h
@@ -66,6 +66,15 @@ enum lis302dl_reg_ctrl1 {
 	LIS302DL_CTRL1_DR		= 0x80,
 };
 
+enum lis302dl_reg_ctrl2 {
+	LIS302DL_CTRL2_HPC1		= 0x01,
+	LIS302DL_CTRL2_HPC2		= 0x02,
+	LIS302DL_CTRL2_HPFF1		= 0x04,
+	LIS302DL_CTRL2_HPFF2		= 0x08,
+	LIS302DL_CTRL2_FDS		= 0x10,
+	LIS302DL_CTRL2_BOOT		= 0x40,
+	LIS302DL_CTRL2_SIM		= 0x80,
+};
 enum lis302dl_reg_ctrl3 {
 	LIS302DL_CTRL3_PP_OD		= 0x40,
 	LIS302DL_CTRL3_IHL		= 0x80,
-- 
1.5.6.5