summaryrefslogtreecommitdiffstats
path: root/meta/recipes-kernel/linux/linux-netbook-2.6.33.2/linux-2.6.34-moorestown-thermal-emc1403-driver.patch
blob: 667db0207687326f549d4ab2066046ddd2da6fb6 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
From e11104658a3b8eabbb4eb74b38645a4f114b745d Mon Sep 17 00:00:00 2001
From: Kalhan Trisal <kalhan.trisal@intel.com>
Date: Fri, 4 Sep 2009 18:10:52 -0400
Subject: [PATCH 075/104] Thermal patch for emc1403 driver

Thermal driver will handle event generation even if alert handler is called multiple time due to GPE->GPIO changes. The IRQ has become now shared and the handler will be called on every event as shared with other devices also.

Signed-off-by: Kalhan Trisal <kalhan.trisal@intel.com>
---
 drivers/hwmon/Kconfig   |    2 +-
 drivers/hwmon/emc1403.c |  128 +++++++++++++++++++++--------------------------
 2 files changed, 58 insertions(+), 72 deletions(-)

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 55637c3..c8fefbc 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -55,7 +55,7 @@ config SENSORS_LIS331DL
 
 config SENSORS_EMC1403
 	tristate "SMSC EMC1403 Thermal"
-	depends on I2C_MRST && GPE && GPIO_MAX7315 && MSTWN_POWER_MGMT
+	depends on I2C
 	help
 	  If you say yes here you get support for the SMSC Devices
 	  EMC1403 temperature monitoring chip.
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index 45cf5d0..75e3b15 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -44,8 +44,7 @@ MODULE_LICENSE("GPL v2");
 /* To support the interrupt mechanism for moorestown interrupt flag is added
  * If the flag is not enabled it support generic emc1403 chip */
 
-#if defined(CONFIG_GPIO_LNWPMIC) && defined(CONFIG_GPIO_MAX7315) \
-			&& defined(CONFIG_MSTWN_POWER_MGMT)
+#if defined(CONFIG_GPIO_LANGWELL_PMIC) && defined(CONFIG_MSTWN_POWER_MGMT)
 #define MOORESTOWN_INTERRUPT_ENABLE
 #endif
 
@@ -335,40 +334,6 @@ static ssize_t store_power_state(struct device *dev,
 	return count;
 }
 
-static ssize_t show_mode(struct device *dev,
-			struct device_attribute *attr, char *buf)
-{
-	struct i2c_client *client = to_i2c_client(dev);
-	int ret_val;
-
-	ret_val = i2c_read_current_data(client, 0x03);
-	ret_val = ret_val & 0x80;
-	if (ret_val == 0x80)
-		ret_val = 1;
-	return sprintf(buf, "%x", ret_val);
-}
-
-static ssize_t store_mode(struct device *dev,
-		struct device_attribute *attr, const char *buf, size_t count)
-{
-	struct i2c_client *client = to_i2c_client(dev);
-	unsigned long val = 0;
-	char curr_val;
-
-	if (strict_strtoul(buf, 10, &val))
-		return -EINVAL;
-
-	curr_val = i2c_read_current_data(client, 0x03);
-	if (val == INTERRUPT_MODE_ENABLE)
-		curr_val = curr_val & 0x7F;
-	else if (val == INTERRUPT_MODE_DISABLE)
-		curr_val = curr_val | 0x80;
-	else
-		return -EINVAL;
-	i2c_write_current_data(client, 0x03, curr_val);
-	return count;
-}
-
 static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR,
 	show_temp_auto_offset, store_temp_auto_offset, 0, 1);
 static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR,
@@ -398,7 +363,6 @@ static DEVICE_ATTR(status, S_IRUGO, show_status_reg, NULL);
 
 static DEVICE_ATTR(power_state, S_IRUGO | S_IWUSR,
 	show_power_state, store_power_state);
-static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, show_mode, store_mode);
 
 static struct attribute *mid_att_thermal[] = {
 	&sensor_dev_attr_temp1_min.dev_attr.attr,
@@ -416,7 +380,6 @@ static struct attribute *mid_att_thermal[] = {
 	&dev_attr_hyster.attr,
 	&dev_attr_status.attr,
 	&dev_attr_power_state.attr,
-	&dev_attr_mode.attr,
 	NULL
 };
 
@@ -449,102 +412,124 @@ static irqreturn_t alert_interrupt_handler(int id, void *dev)
 	return IRQ_HANDLED;
 }
 
+
 /* when the device raise the interrupt we mask the interrupt
  * bit for that device as the status register is R-C
  * so that till thermal governor doesnot take action  we need
  * not to send continuous events */
 
 static int interrupt_status(struct i2c_client *client, u8 diode_reg_val,
-				u8 *status, u8 event)
+				u8 *mask_status, u8 event, u8 *status)
 {
-	u8 crit_st = 0, set_mask = 0;
+	u8 crit_st = 0, set_mask = 0, event_status = 0;
 
 	set_mask = i2c_read_current_data(client, 0x1F);
 	if (diode_reg_val & THM_CHAN_TEMP[3]) {
-		set_mask = (set_mask | 0x02);
-		crit_st = (crit_st  | 2);
+		if (set_mask & TEMP2)
+			event_status = event_status | TEMP2;
+		else
+			set_mask = set_mask | 0x02;
+		crit_st = crit_st  | 2;
 	}
 	if (diode_reg_val & THM_CHAN_TEMP[2]) {
-		set_mask = (set_mask | 0x04);
-		crit_st = (crit_st  | 4);
+		if (set_mask & TEMP3)
+			event_status = event_status | TEMP3;
+		else
+			set_mask = set_mask | 0x04;
+		crit_st = crit_st  | 4;
 	}
 	if (diode_reg_val & THM_CHAN_TEMP[4]) {
-		set_mask = (set_mask | 0x01);
-		crit_st = (crit_st  | 1);
+		if (set_mask & TEMP1)
+			event_status = event_status | TEMP1;
+		else
+			set_mask = set_mask | 0x01;
+		crit_st = crit_st  | 1;
 	}
 	if (event == ALERT_EVENT)
-		i2c_smbus_write_byte_data(client, 0x1F, set_mask);
-	*status = crit_st;
+		i2c_smbus_write_byte_data(client, 0x1f, set_mask);
+	*mask_status = crit_st;
+	*status = event_status;
 	return 0;
 }
 
 static void ospm_event(int event_id, int sensor_id, int curr_temp)
 {
 	if (event_id == THERM_EVENT) {
-		printk(KERN_ALERT "emc1403: Sensor Id = %d crit event \
+		printk(KERN_ALERT "emc1403: sensor id = %d crit event \
 					temp = %d \n", sensor_id, curr_temp);
 		ospm_generate_netlink_event(sensor_id,
 					OSPM_EVENT_THERMAL_CRITICAL);
 	}
 	if (event_id == HIGH_EVENT) {
-		printk(KERN_ALERT "emc1403: Sensor Id = %d AUX1 event \
+		printk(KERN_ALERT "emc1403: sensor id = %d aux1 event \
 					temp = %d \n", sensor_id, curr_temp);
 		ospm_generate_netlink_event(sensor_id,
 					OSPM_EVENT_THERMAL_AUX1);
 	}
 	if (event_id == LOW_EVENT) {
-		printk(KERN_ALERT "emc1403: Sensor Id = %d AUX0 event \
+		printk(KERN_ALERT "emc1403: sensor id = %d aux0 event \
 					temp = %d \n", sensor_id, curr_temp);
 	ospm_generate_netlink_event(sensor_id,
 					OSPM_EVENT_THERMAL_AUX0);
 	}
 	if (event_id == FAULT_EVENT) {
-		printk(KERN_ALERT "emc1403: Sensor Id  = %d Fault event \
+		printk(KERN_ALERT "emc1403: sensor id  = %d fault event \
 					temp = %d \n", sensor_id, curr_temp);
 		ospm_generate_netlink_event(sensor_id,
 					OSPM_EVENT_THERMAL_DEV_FAULT);
 	}
 }
 
-static void send_event(struct i2c_client *client, int status, int event_id)
+static void send_event(struct i2c_client *client, int status, u8 mask_event,
+			int event_id)
 {
 	int ret_val;
 
 	if (status & TEMP1) {
-		ret_val = i2c_read_current_data(client, THM_REG_CURR_TEMP[0]);
-		ospm_event(event_id, TEMP_DEV_ID1, ret_val);
+		if (!(TEMP1 & mask_event)) {
+			ret_val = i2c_read_current_data(client,
+							THM_REG_CURR_TEMP[0]);
+			ospm_event(event_id, TEMP_DEV_ID1, ret_val);
+		}
 	}
 	if (status & TEMP2) {
-		ret_val = i2c_read_current_data(client, THM_REG_CURR_TEMP[1]);
-		ospm_event(event_id, TEMP_DEV_ID2, ret_val);
+		if (!(TEMP2 & mask_event)) {
+			ret_val = i2c_read_current_data(client,
+							THM_REG_CURR_TEMP[1]);
+			ospm_event(event_id, TEMP_DEV_ID2, ret_val);
+		}
 	}
 	if (status & TEMP3) {
-		ret_val = i2c_read_current_data(client, THM_REG_CURR_TEMP[2]);
-		ospm_event(event_id, TEMP_DEV_ID3, ret_val);
+		if (!(TEMP3 & mask_event)) {
+			ret_val = i2c_read_current_data(client,
+							THM_REG_CURR_TEMP[2]);
+			ospm_event(event_id, TEMP_DEV_ID3, ret_val);
+		}
 	}
 }
 
 static void therm_handle_intrpt(struct work_struct *work)
 {
-	u8 status, reg_val;
+	u8 status, reg_val, mask_status;
 	struct thermal_data *data = container_of(work,
 					struct thermal_data, therm_handler);
 
 	/* check if therm_module_info is initialized */
 	if (!data)
 		return;
-	/* Which DIODE has raised the interrupt 0x1B
-		internal/External1/External2 */
+	/* which diode has raised the interrupt 0x1b
+		internal/external1/external2 */
 	reg_val = i2c_smbus_read_byte_data(data->client,
 						THM_STAT_REG_TEMP[0]);
-	interrupt_status(data->client, reg_val, &status, THERM_EVENT);
-	send_event(data->client, status, THERM_EVENT);
+	interrupt_status(data->client, reg_val, &status, THERM_EVENT,
+			&mask_status);
+	send_event(data->client, status, 0, THERM_EVENT);
 }
 
 static void alert_handle_intrpt(struct work_struct *work)
 {
 	int sta_reg_val, reg_val;
-	u8 status;
+	u8 status, mask_status;
 	struct thermal_data *data = container_of(work,
 					struct thermal_data, alert_handler);
 	if (!data)
@@ -557,25 +542,26 @@ static void alert_handle_intrpt(struct work_struct *work)
 		internal/External1/External2 */
 		sta_reg_val = i2c_smbus_read_byte_data(data->client,
 					THM_STAT_REG_TEMP[1]);
+	/*chek if the mask is already enabled then donot send the event again*/
 		interrupt_status(data->client, sta_reg_val, &status,
-					ALERT_EVENT);
-		send_event(data->client, status, HIGH_EVENT);
+					ALERT_EVENT, &mask_status);
+		send_event(data->client, status, mask_status, HIGH_EVENT);
 	}
 	/* Low status bit is set */
 	if (reg_val & THM_CHAN_TEMP[1]) {
 		sta_reg_val = i2c_smbus_read_byte_data(data->client,
 					THM_STAT_REG_TEMP[2]);
 		interrupt_status(data->client, sta_reg_val, &status,
-					ALERT_EVENT);
-		send_event(data->client, status, LOW_EVENT);
+					ALERT_EVENT, &mask_status);
+		send_event(data->client, status, mask_status, LOW_EVENT);
 	}
 	/* Fault status bit is set */
 	if (reg_val & THM_CHAN_TEMP[2]) {
 		sta_reg_val = i2c_smbus_read_byte_data(data->client,
 					THM_STAT_REG_TEMP[3]);
 		interrupt_status(data->client, sta_reg_val, &status,
-					ALERT_EVENT);
-		send_event(data->client, status, FAULT_EVENT);
+					ALERT_EVENT, &mask_status);
+		send_event(data->client, status, mask_status, FAULT_EVENT);
 	}
 }
 #endif
-- 
1.6.2.5