blob: 602a0f0b0de8baae095a6c21cefad245fe869e58 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor
3 * with integrated fan control
Jean Delvared5957be2008-07-16 19:30:13 +02004 * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Based on the lm90 driver.
6 *
7 * The LM63 is a sensor chip made by National Semiconductor. It measures
8 * two temperatures (its own and one external one) and the speed of one
9 * fan, those speed it can additionally control. Complete datasheet can be
10 * obtained from National's website at:
11 * http://www.national.com/pf/LM/LM63.html
12 *
13 * The LM63 is basically an LM86 with fan speed monitoring and control
14 * capabilities added. It misses some of the LM86 features though:
15 * - No low limit for local temperature.
16 * - No critical limit for local temperature.
17 * - Critical limit for remote temperature can be changed only once. We
18 * will consider that the critical limit is read-only.
19 *
20 * The datasheet isn't very clear about what the tachometer reading is.
21 * I had a explanation from National Semiconductor though. The two lower
22 * bits of the read value have to be masked out. The value is still 16 bit
23 * in width.
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38 */
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/module.h>
41#include <linux/init.h>
42#include <linux/slab.h>
43#include <linux/jiffies.h>
44#include <linux/i2c.h>
Jean Delvare10c08f82005-06-06 19:34:45 +020045#include <linux/hwmon-sysfs.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040046#include <linux/hwmon.h>
47#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010048#include <linux/mutex.h>
Jean Delvare0e39e012006-09-24 21:16:40 +020049#include <linux/sysfs.h>
Guenter Roeck210961c2012-01-16 22:51:45 +010050#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/*
53 * Addresses to scan
Jean Delvared93ab782012-01-16 22:51:47 +010054 * Address is fully defined internally and cannot be changed except for
55 * LM64 which has one pin dedicated to address selection.
56 * LM63 and LM96163 have address 0x4c.
57 * LM64 can have address 0x18 or 0x4e.
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 */
59
Matthew Garrett10f2ed32010-05-27 19:58:38 +020060static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END };
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * The LM63 registers
64 */
65
66#define LM63_REG_CONFIG1 0x03
Guenter Roeck04738b22012-01-16 22:51:46 +010067#define LM63_REG_CONVRATE 0x04
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define LM63_REG_CONFIG2 0xBF
69#define LM63_REG_CONFIG_FAN 0x4A
70
71#define LM63_REG_TACH_COUNT_MSB 0x47
72#define LM63_REG_TACH_COUNT_LSB 0x46
73#define LM63_REG_TACH_LIMIT_MSB 0x49
74#define LM63_REG_TACH_LIMIT_LSB 0x48
75
76#define LM63_REG_PWM_VALUE 0x4C
77#define LM63_REG_PWM_FREQ 0x4D
Jean Delvared216f682012-01-16 22:51:47 +010078#define LM63_REG_LUT_TEMP_HYST 0x4F
79#define LM63_REG_LUT_TEMP(nr) (0x50 + 2 * (nr))
80#define LM63_REG_LUT_PWM(nr) (0x51 + 2 * (nr))
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82#define LM63_REG_LOCAL_TEMP 0x00
83#define LM63_REG_LOCAL_HIGH 0x05
84
85#define LM63_REG_REMOTE_TEMP_MSB 0x01
86#define LM63_REG_REMOTE_TEMP_LSB 0x10
87#define LM63_REG_REMOTE_OFFSET_MSB 0x11
88#define LM63_REG_REMOTE_OFFSET_LSB 0x12
89#define LM63_REG_REMOTE_HIGH_MSB 0x07
90#define LM63_REG_REMOTE_HIGH_LSB 0x13
91#define LM63_REG_REMOTE_LOW_MSB 0x08
92#define LM63_REG_REMOTE_LOW_LSB 0x14
93#define LM63_REG_REMOTE_TCRIT 0x19
94#define LM63_REG_REMOTE_TCRIT_HYST 0x21
95
96#define LM63_REG_ALERT_STATUS 0x02
97#define LM63_REG_ALERT_MASK 0x16
98
99#define LM63_REG_MAN_ID 0xFE
100#define LM63_REG_CHIP_ID 0xFF
101
Guenter Roeckf496b2d2012-01-16 22:51:46 +0100102#define LM96163_REG_TRUTHERM 0x30
Guenter Roecke872c912012-01-16 22:51:46 +0100103#define LM96163_REG_REMOTE_TEMP_U_MSB 0x31
104#define LM96163_REG_REMOTE_TEMP_U_LSB 0x32
Guenter Roeck210961c2012-01-16 22:51:45 +0100105#define LM96163_REG_CONFIG_ENHANCED 0x45
106
Guenter Roeck04738b22012-01-16 22:51:46 +0100107#define LM63_MAX_CONVRATE 9
108
109#define LM63_MAX_CONVRATE_HZ 32
110#define LM96163_MAX_CONVRATE_HZ 26
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/*
113 * Conversions and various macros
114 * For tachometer counts, the LM63 uses 16-bit values.
115 * For local temperature and high limit, remote critical limit and hysteresis
Steven Cole44bbe872005-05-03 18:21:25 -0600116 * value, it uses signed 8-bit values with LSB = 1 degree Celsius.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 * For remote temperature, low and high limits, it uses signed 11-bit values
Steven Cole44bbe872005-05-03 18:21:25 -0600118 * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers.
Dirk Eibach2778fb12011-02-09 04:51:34 -0500119 * For LM64 the actual remote diode temperature is 16 degree Celsius higher
120 * than the register reading. Remote temperature setpoints have to be
121 * adapted accordingly.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 */
123
124#define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \
125 5400000 / (reg))
126#define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \
127 (5400000 / (val)) & 0xFFFC)
128#define TEMP8_FROM_REG(reg) ((reg) * 1000)
129#define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \
130 (val) >= 127000 ? 127 : \
131 (val) < 0 ? ((val) - 500) / 1000 : \
132 ((val) + 500) / 1000)
Guenter Roeck94e55df2012-01-16 22:51:46 +0100133#define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \
134 (val) >= 255000 ? 255 : \
135 ((val) + 500) / 1000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
137#define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
138 (val) >= 127875 ? 0x7FE0 : \
139 (val) < 0 ? ((val) - 62) / 125 * 32 : \
140 ((val) + 62) / 125 * 32)
Guenter Roecke872c912012-01-16 22:51:46 +0100141#define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \
142 (val) >= 255875 ? 0xFFE0 : \
143 ((val) + 62) / 125 * 32)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#define HYST_TO_REG(val) ((val) <= 0 ? 0 : \
145 (val) >= 127000 ? 127 : \
146 ((val) + 500) / 1000)
147
Guenter Roeck04738b22012-01-16 22:51:46 +0100148#define UPDATE_INTERVAL(max, rate) \
149 ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max))
150
Guenter Roeck210961c2012-01-16 22:51:45 +0100151enum chips { lm63, lm64, lm96163 };
Matthew Garrett10f2ed32010-05-27 19:58:38 +0200152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 * Client data (each client gets its own)
155 */
156
157struct lm63_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700158 struct device *hwmon_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100159 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 char valid; /* zero until following fields are valid */
Jean Delvared216f682012-01-16 22:51:47 +0100161 char lut_valid; /* zero until lut fields are valid */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 unsigned long last_updated; /* in jiffies */
Jean Delvared216f682012-01-16 22:51:47 +0100163 unsigned long lut_last_updated; /* in jiffies */
Guenter Roeck04738b22012-01-16 22:51:46 +0100164 enum chips kind;
Dirk Eibach2778fb12011-02-09 04:51:34 -0500165 int temp2_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Guenter Roeck04738b22012-01-16 22:51:46 +0100167 int update_interval; /* in milliseconds */
168 int max_convrate_hz;
Jean Delvare2fe28ab2012-01-16 22:51:47 +0100169 int lut_size; /* 8 or 12 */
Guenter Roeck04738b22012-01-16 22:51:46 +0100170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 /* registers values */
172 u8 config, config_fan;
Jean Delvarebc51ae12005-06-05 20:32:27 +0200173 u16 fan[2]; /* 0: input
174 1: low limit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 u8 pwm1_freq;
Jean Delvare2fe28ab2012-01-16 22:51:47 +0100176 u8 pwm1[13]; /* 0: current output
177 1-12: lookup table */
178 s8 temp8[15]; /* 0: local input
Jean Delvarebc51ae12005-06-05 20:32:27 +0200179 1: local high limit
Jean Delvared216f682012-01-16 22:51:47 +0100180 2: remote critical limit
Jean Delvare2fe28ab2012-01-16 22:51:47 +0100181 3-14: lookup table */
Guenter Roeck786375f2012-01-16 22:51:45 +0100182 s16 temp11[4]; /* 0: remote input
Jean Delvarebc51ae12005-06-05 20:32:27 +0200183 1: remote low limit
Guenter Roeck786375f2012-01-16 22:51:45 +0100184 2: remote high limit
185 3: remote offset */
Guenter Roecke872c912012-01-16 22:51:46 +0100186 u16 temp11u; /* remote input (unsigned) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 u8 temp2_crit_hyst;
Jean Delvared216f682012-01-16 22:51:47 +0100188 u8 lut_temp_hyst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 u8 alarms;
Guenter Roeck210961c2012-01-16 22:51:45 +0100190 bool pwm_highres;
Jean Delvared216f682012-01-16 22:51:47 +0100191 bool lut_temp_highres;
Guenter Roecke872c912012-01-16 22:51:46 +0100192 bool remote_unsigned; /* true if unsigned remote upper limits */
Guenter Roeckf496b2d2012-01-16 22:51:46 +0100193 bool trutherm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194};
195
Guenter Roecke872c912012-01-16 22:51:46 +0100196static inline int temp8_from_reg(struct lm63_data *data, int nr)
197{
198 if (data->remote_unsigned)
199 return TEMP8_FROM_REG((u8)data->temp8[nr]);
200 return TEMP8_FROM_REG(data->temp8[nr]);
201}
202
Jean Delvared216f682012-01-16 22:51:47 +0100203static inline int lut_temp_from_reg(struct lm63_data *data, int nr)
204{
205 return data->temp8[nr] * (data->lut_temp_highres ? 500 : 1000);
206}
207
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100208static inline int lut_temp_to_reg(struct lm63_data *data, long val)
209{
210 val -= data->temp2_offset;
211 if (data->lut_temp_highres)
212 return DIV_ROUND_CLOSEST(SENSORS_LIMIT(val, 0, 127500), 500);
213 else
214 return DIV_ROUND_CLOSEST(SENSORS_LIMIT(val, 0, 127000), 1000);
215}
216
Jean Delvare817c6cc2012-03-23 10:02:19 +0100217/*
218 * Update the lookup table register cache.
219 * client->update_lock must be held when calling this function.
220 */
221static void lm63_update_lut(struct i2c_client *client)
222{
223 struct lm63_data *data = i2c_get_clientdata(client);
224 int i;
225
226 if (time_after(jiffies, data->lut_last_updated + 5 * HZ) ||
227 !data->lut_valid) {
228 for (i = 0; i < data->lut_size; i++) {
229 data->pwm1[1 + i] = i2c_smbus_read_byte_data(client,
230 LM63_REG_LUT_PWM(i));
231 data->temp8[3 + i] = i2c_smbus_read_byte_data(client,
232 LM63_REG_LUT_TEMP(i));
233 }
234 data->lut_temp_hyst = i2c_smbus_read_byte_data(client,
235 LM63_REG_LUT_TEMP_HYST);
236
237 data->lut_last_updated = jiffies;
238 data->lut_valid = 1;
239 }
240}
241
Jean Delvaredac27dc2012-03-23 10:02:18 +0100242static struct lm63_data *lm63_update_device(struct device *dev)
243{
244 struct i2c_client *client = to_i2c_client(dev);
245 struct lm63_data *data = i2c_get_clientdata(client);
246 unsigned long next_update;
Jean Delvaredac27dc2012-03-23 10:02:18 +0100247
248 mutex_lock(&data->update_lock);
249
250 next_update = data->last_updated
251 + msecs_to_jiffies(data->update_interval) + 1;
252
253 if (time_after(jiffies, next_update) || !data->valid) {
254 if (data->config & 0x04) { /* tachometer enabled */
255 /* order matters for fan1_input */
256 data->fan[0] = i2c_smbus_read_byte_data(client,
257 LM63_REG_TACH_COUNT_LSB) & 0xFC;
258 data->fan[0] |= i2c_smbus_read_byte_data(client,
259 LM63_REG_TACH_COUNT_MSB) << 8;
260 data->fan[1] = (i2c_smbus_read_byte_data(client,
261 LM63_REG_TACH_LIMIT_LSB) & 0xFC)
262 | (i2c_smbus_read_byte_data(client,
263 LM63_REG_TACH_LIMIT_MSB) << 8);
264 }
265
266 data->pwm1_freq = i2c_smbus_read_byte_data(client,
267 LM63_REG_PWM_FREQ);
268 if (data->pwm1_freq == 0)
269 data->pwm1_freq = 1;
270 data->pwm1[0] = i2c_smbus_read_byte_data(client,
271 LM63_REG_PWM_VALUE);
272
273 data->temp8[0] = i2c_smbus_read_byte_data(client,
274 LM63_REG_LOCAL_TEMP);
275 data->temp8[1] = i2c_smbus_read_byte_data(client,
276 LM63_REG_LOCAL_HIGH);
277
278 /* order matters for temp2_input */
279 data->temp11[0] = i2c_smbus_read_byte_data(client,
280 LM63_REG_REMOTE_TEMP_MSB) << 8;
281 data->temp11[0] |= i2c_smbus_read_byte_data(client,
282 LM63_REG_REMOTE_TEMP_LSB);
283 data->temp11[1] = (i2c_smbus_read_byte_data(client,
284 LM63_REG_REMOTE_LOW_MSB) << 8)
285 | i2c_smbus_read_byte_data(client,
286 LM63_REG_REMOTE_LOW_LSB);
287 data->temp11[2] = (i2c_smbus_read_byte_data(client,
288 LM63_REG_REMOTE_HIGH_MSB) << 8)
289 | i2c_smbus_read_byte_data(client,
290 LM63_REG_REMOTE_HIGH_LSB);
291 data->temp11[3] = (i2c_smbus_read_byte_data(client,
292 LM63_REG_REMOTE_OFFSET_MSB) << 8)
293 | i2c_smbus_read_byte_data(client,
294 LM63_REG_REMOTE_OFFSET_LSB);
295
296 if (data->kind == lm96163)
297 data->temp11u = (i2c_smbus_read_byte_data(client,
298 LM96163_REG_REMOTE_TEMP_U_MSB) << 8)
299 | i2c_smbus_read_byte_data(client,
300 LM96163_REG_REMOTE_TEMP_U_LSB);
301
302 data->temp8[2] = i2c_smbus_read_byte_data(client,
303 LM63_REG_REMOTE_TCRIT);
304 data->temp2_crit_hyst = i2c_smbus_read_byte_data(client,
305 LM63_REG_REMOTE_TCRIT_HYST);
306
307 data->alarms = i2c_smbus_read_byte_data(client,
308 LM63_REG_ALERT_STATUS) & 0x7F;
309
310 data->last_updated = jiffies;
311 data->valid = 1;
312 }
313
Jean Delvare817c6cc2012-03-23 10:02:19 +0100314 lm63_update_lut(client);
Jean Delvaredac27dc2012-03-23 10:02:18 +0100315
316 mutex_unlock(&data->update_lock);
317
318 return data;
319}
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321/*
Jean Delvare817c6cc2012-03-23 10:02:19 +0100322 * Trip points in the lookup table should be in ascending order for both
323 * temperatures and PWM output values.
324 */
325static int lm63_lut_looks_bad(struct i2c_client *client)
326{
327 struct lm63_data *data = i2c_get_clientdata(client);
328 int i;
329
330 mutex_lock(&data->update_lock);
331 lm63_update_lut(client);
332
333 for (i = 1; i < data->lut_size; i++) {
334 if (data->pwm1[1 + i - 1] > data->pwm1[1 + i]
335 || data->temp8[3 + i - 1] > data->temp8[3 + i]) {
336 dev_warn(&client->dev,
337 "Lookup table doesn't look sane (check entries %d and %d)\n",
338 i, i + 1);
339 break;
340 }
341 }
342 mutex_unlock(&data->update_lock);
343
344 return i == data->lut_size ? 0 : 1;
345}
346
347/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 * Sysfs callback functions and files
349 */
350
Jean Delvarebc51ae12005-06-05 20:32:27 +0200351static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
352 char *buf)
353{
354 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
355 struct lm63_data *data = lm63_update_device(dev);
356 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Jean Delvarebc51ae12005-06-05 20:32:27 +0200359static ssize_t set_fan(struct device *dev, struct device_attribute *dummy,
360 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
362 struct i2c_client *client = to_i2c_client(dev);
363 struct lm63_data *data = i2c_get_clientdata(client);
Guenter Roeck662bda22012-01-16 22:51:45 +0100364 unsigned long val;
365 int err;
366
367 err = kstrtoul(buf, 10, &val);
368 if (err)
369 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100371 mutex_lock(&data->update_lock);
Jean Delvarebc51ae12005-06-05 20:32:27 +0200372 data->fan[1] = FAN_TO_REG(val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB,
Jean Delvarebc51ae12005-06-05 20:32:27 +0200374 data->fan[1] & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB,
Jean Delvarebc51ae12005-06-05 20:32:27 +0200376 data->fan[1] >> 8);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100377 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return count;
379}
380
Jean Delvared216f682012-01-16 22:51:47 +0100381static ssize_t show_pwm1(struct device *dev, struct device_attribute *devattr,
Jean Delvarebc51ae12005-06-05 20:32:27 +0200382 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Jean Delvared216f682012-01-16 22:51:47 +0100384 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 struct lm63_data *data = lm63_update_device(dev);
Jean Delvared216f682012-01-16 22:51:47 +0100386 int nr = attr->index;
Guenter Roeck210961c2012-01-16 22:51:45 +0100387 int pwm;
388
389 if (data->pwm_highres)
Jean Delvared216f682012-01-16 22:51:47 +0100390 pwm = data->pwm1[nr];
Guenter Roeck210961c2012-01-16 22:51:45 +0100391 else
Jean Delvared216f682012-01-16 22:51:47 +0100392 pwm = data->pwm1[nr] >= 2 * data->pwm1_freq ?
393 255 : (data->pwm1[nr] * 255 + data->pwm1_freq) /
Guenter Roeck210961c2012-01-16 22:51:45 +0100394 (2 * data->pwm1_freq);
395
396 return sprintf(buf, "%d\n", pwm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100399static ssize_t set_pwm1(struct device *dev, struct device_attribute *devattr,
Jean Delvarebc51ae12005-06-05 20:32:27 +0200400 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100402 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 struct i2c_client *client = to_i2c_client(dev);
404 struct lm63_data *data = i2c_get_clientdata(client);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100405 int nr = attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 unsigned long val;
Guenter Roeck662bda22012-01-16 22:51:45 +0100407 int err;
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100408 u8 reg;
Guenter Roeck662bda22012-01-16 22:51:45 +0100409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (!(data->config_fan & 0x20)) /* register is read-only */
411 return -EPERM;
412
Guenter Roeck662bda22012-01-16 22:51:45 +0100413 err = kstrtoul(buf, 10, &val);
414 if (err)
415 return err;
416
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100417 reg = nr ? LM63_REG_LUT_PWM(nr - 1) : LM63_REG_PWM_VALUE;
Guenter Roeck210961c2012-01-16 22:51:45 +0100418 val = SENSORS_LIMIT(val, 0, 255);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100419
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100420 mutex_lock(&data->update_lock);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100421 data->pwm1[nr] = data->pwm_highres ? val :
Jean Delvared216f682012-01-16 22:51:47 +0100422 (val * data->pwm1_freq * 2 + 127) / 255;
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100423 i2c_smbus_write_byte_data(client, reg, data->pwm1[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100424 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return count;
426}
427
Guenter Roeck662bda22012-01-16 22:51:45 +0100428static ssize_t show_pwm1_enable(struct device *dev,
429 struct device_attribute *dummy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
431 struct lm63_data *data = lm63_update_device(dev);
432 return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2);
433}
434
Jean Delvare817c6cc2012-03-23 10:02:19 +0100435static ssize_t set_pwm1_enable(struct device *dev,
436 struct device_attribute *dummy,
437 const char *buf, size_t count)
438{
439 struct i2c_client *client = to_i2c_client(dev);
440 struct lm63_data *data = i2c_get_clientdata(client);
441 unsigned long val;
442 int err;
443
444 err = kstrtoul(buf, 10, &val);
445 if (err)
446 return err;
447 if (val < 1 || val > 2)
448 return -EINVAL;
449
450 /*
451 * Only let the user switch to automatic mode if the lookup table
452 * looks sane.
453 */
454 if (val == 2 && lm63_lut_looks_bad(client))
455 return -EPERM;
456
457 mutex_lock(&data->update_lock);
458 data->config_fan = i2c_smbus_read_byte_data(client,
459 LM63_REG_CONFIG_FAN);
460 if (val == 1)
461 data->config_fan |= 0x20;
462 else
463 data->config_fan &= ~0x20;
464 i2c_smbus_write_byte_data(client, LM63_REG_CONFIG_FAN,
465 data->config_fan);
466 mutex_unlock(&data->update_lock);
467 return count;
468}
469
Dirk Eibach2778fb12011-02-09 04:51:34 -0500470/*
471 * There are 8bit registers for both local(temp1) and remote(temp2) sensor.
472 * For remote sensor registers temp2_offset has to be considered,
473 * for local sensor it must not.
474 * So we need separate 8bit accessors for local and remote sensor.
475 */
476static ssize_t show_local_temp8(struct device *dev,
477 struct device_attribute *devattr,
478 char *buf)
Jean Delvarebc51ae12005-06-05 20:32:27 +0200479{
480 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
481 struct lm63_data *data = lm63_update_device(dev);
482 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Dirk Eibach2778fb12011-02-09 04:51:34 -0500485static ssize_t show_remote_temp8(struct device *dev,
486 struct device_attribute *devattr,
487 char *buf)
488{
489 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
490 struct lm63_data *data = lm63_update_device(dev);
Guenter Roecke872c912012-01-16 22:51:46 +0100491 return sprintf(buf, "%d\n", temp8_from_reg(data, attr->index)
Dirk Eibach2778fb12011-02-09 04:51:34 -0500492 + data->temp2_offset);
493}
494
Jean Delvared216f682012-01-16 22:51:47 +0100495static ssize_t show_lut_temp(struct device *dev,
496 struct device_attribute *devattr,
497 char *buf)
498{
499 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
500 struct lm63_data *data = lm63_update_device(dev);
501 return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index)
502 + data->temp2_offset);
503}
504
Guenter Roeck94e55df2012-01-16 22:51:46 +0100505static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
506 const char *buf, size_t count)
Jean Delvarebc51ae12005-06-05 20:32:27 +0200507{
Guenter Roeck94e55df2012-01-16 22:51:46 +0100508 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvarebc51ae12005-06-05 20:32:27 +0200509 struct i2c_client *client = to_i2c_client(dev);
510 struct lm63_data *data = i2c_get_clientdata(client);
Guenter Roeck94e55df2012-01-16 22:51:46 +0100511 int nr = attr->index;
Guenter Roeck662bda22012-01-16 22:51:45 +0100512 long val;
513 int err;
Guenter Roeck94e55df2012-01-16 22:51:46 +0100514 int temp;
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100515 u8 reg;
Guenter Roeck662bda22012-01-16 22:51:45 +0100516
517 err = kstrtol(buf, 10, &val);
518 if (err)
519 return err;
Jean Delvarebc51ae12005-06-05 20:32:27 +0200520
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100521 mutex_lock(&data->update_lock);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100522 switch (nr) {
523 case 2:
524 reg = LM63_REG_REMOTE_TCRIT;
Guenter Roeck94e55df2012-01-16 22:51:46 +0100525 if (data->remote_unsigned)
526 temp = TEMP8U_TO_REG(val - data->temp2_offset);
527 else
528 temp = TEMP8_TO_REG(val - data->temp2_offset);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100529 break;
530 case 1:
531 reg = LM63_REG_LOCAL_HIGH;
Guenter Roeck94e55df2012-01-16 22:51:46 +0100532 temp = TEMP8_TO_REG(val);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100533 break;
534 default: /* lookup table */
535 reg = LM63_REG_LUT_TEMP(nr - 3);
536 temp = lut_temp_to_reg(data, val);
Guenter Roeck94e55df2012-01-16 22:51:46 +0100537 }
538 data->temp8[nr] = temp;
539 i2c_smbus_write_byte_data(client, reg, temp);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100540 mutex_unlock(&data->update_lock);
Jean Delvarebc51ae12005-06-05 20:32:27 +0200541 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542}
Jean Delvarebc51ae12005-06-05 20:32:27 +0200543
544static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
545 char *buf)
546{
547 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
548 struct lm63_data *data = lm63_update_device(dev);
Guenter Roecke872c912012-01-16 22:51:46 +0100549 int nr = attr->index;
550 int temp;
551
552 if (!nr) {
553 /*
554 * Use unsigned temperature unless its value is zero.
555 * If it is zero, use signed temperature.
556 */
557 if (data->temp11u)
558 temp = TEMP11_FROM_REG(data->temp11u);
559 else
560 temp = TEMP11_FROM_REG(data->temp11[nr]);
561 } else {
562 if (data->remote_unsigned && nr == 2)
563 temp = TEMP11_FROM_REG((u16)data->temp11[nr]);
564 else
565 temp = TEMP11_FROM_REG(data->temp11[nr]);
566 }
567 return sprintf(buf, "%d\n", temp + data->temp2_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
Jean Delvarebc51ae12005-06-05 20:32:27 +0200569
570static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
571 const char *buf, size_t count)
572{
Guenter Roeck786375f2012-01-16 22:51:45 +0100573 static const u8 reg[6] = {
Jean Delvarebc51ae12005-06-05 20:32:27 +0200574 LM63_REG_REMOTE_LOW_MSB,
575 LM63_REG_REMOTE_LOW_LSB,
576 LM63_REG_REMOTE_HIGH_MSB,
577 LM63_REG_REMOTE_HIGH_LSB,
Guenter Roeck786375f2012-01-16 22:51:45 +0100578 LM63_REG_REMOTE_OFFSET_MSB,
579 LM63_REG_REMOTE_OFFSET_LSB,
Jean Delvarebc51ae12005-06-05 20:32:27 +0200580 };
581
582 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
583 struct i2c_client *client = to_i2c_client(dev);
584 struct lm63_data *data = i2c_get_clientdata(client);
Guenter Roeck662bda22012-01-16 22:51:45 +0100585 long val;
586 int err;
Jean Delvarebc51ae12005-06-05 20:32:27 +0200587 int nr = attr->index;
588
Guenter Roeck662bda22012-01-16 22:51:45 +0100589 err = kstrtol(buf, 10, &val);
590 if (err)
591 return err;
592
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100593 mutex_lock(&data->update_lock);
Guenter Roecke872c912012-01-16 22:51:46 +0100594 if (data->remote_unsigned && nr == 2)
595 data->temp11[nr] = TEMP11U_TO_REG(val - data->temp2_offset);
596 else
597 data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset);
598
Jean Delvarebc51ae12005-06-05 20:32:27 +0200599 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
600 data->temp11[nr] >> 8);
601 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
602 data->temp11[nr] & 0xff);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100603 mutex_unlock(&data->update_lock);
Jean Delvarebc51ae12005-06-05 20:32:27 +0200604 return count;
605}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Guenter Roeck662bda22012-01-16 22:51:45 +0100607/*
608 * Hysteresis register holds a relative value, while we want to present
609 * an absolute to user-space
610 */
611static ssize_t show_temp2_crit_hyst(struct device *dev,
612 struct device_attribute *dummy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
614 struct lm63_data *data = lm63_update_device(dev);
Guenter Roecke872c912012-01-16 22:51:46 +0100615 return sprintf(buf, "%d\n", temp8_from_reg(data, 2)
Dirk Eibach2778fb12011-02-09 04:51:34 -0500616 + data->temp2_offset
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 - TEMP8_FROM_REG(data->temp2_crit_hyst));
618}
619
Jean Delvared216f682012-01-16 22:51:47 +0100620static ssize_t show_lut_temp_hyst(struct device *dev,
621 struct device_attribute *devattr, char *buf)
622{
623 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
624 struct lm63_data *data = lm63_update_device(dev);
625
626 return sprintf(buf, "%d\n", lut_temp_from_reg(data, attr->index)
627 + data->temp2_offset
628 - TEMP8_FROM_REG(data->lut_temp_hyst));
629}
630
Guenter Roeck662bda22012-01-16 22:51:45 +0100631/*
632 * And now the other way around, user-space provides an absolute
633 * hysteresis value and we have to store a relative one
634 */
635static ssize_t set_temp2_crit_hyst(struct device *dev,
636 struct device_attribute *dummy,
Jean Delvarebc51ae12005-06-05 20:32:27 +0200637 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
639 struct i2c_client *client = to_i2c_client(dev);
640 struct lm63_data *data = i2c_get_clientdata(client);
Guenter Roeck662bda22012-01-16 22:51:45 +0100641 long val;
642 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 long hyst;
644
Guenter Roeck662bda22012-01-16 22:51:45 +0100645 err = kstrtol(buf, 10, &val);
646 if (err)
647 return err;
648
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100649 mutex_lock(&data->update_lock);
Guenter Roecke872c912012-01-16 22:51:46 +0100650 hyst = temp8_from_reg(data, 2) + data->temp2_offset - val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST,
652 HYST_TO_REG(hyst));
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100653 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return count;
655}
656
Guenter Roeck04738b22012-01-16 22:51:46 +0100657/*
658 * Set conversion rate.
659 * client->update_lock must be held when calling this function.
660 */
661static void lm63_set_convrate(struct i2c_client *client, struct lm63_data *data,
662 unsigned int interval)
663{
664 int i;
665 unsigned int update_interval;
666
667 /* Shift calculations to avoid rounding errors */
668 interval <<= 6;
669
670 /* find the nearest update rate */
671 update_interval = (1 << (LM63_MAX_CONVRATE + 6)) * 1000
672 / data->max_convrate_hz;
673 for (i = 0; i < LM63_MAX_CONVRATE; i++, update_interval >>= 1)
674 if (interval >= update_interval * 3 / 4)
675 break;
676
677 i2c_smbus_write_byte_data(client, LM63_REG_CONVRATE, i);
678 data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, i);
679}
680
681static ssize_t show_update_interval(struct device *dev,
682 struct device_attribute *attr, char *buf)
683{
684 struct lm63_data *data = dev_get_drvdata(dev);
685
686 return sprintf(buf, "%u\n", data->update_interval);
687}
688
689static ssize_t set_update_interval(struct device *dev,
690 struct device_attribute *attr,
691 const char *buf, size_t count)
692{
693 struct i2c_client *client = to_i2c_client(dev);
694 struct lm63_data *data = i2c_get_clientdata(client);
695 unsigned long val;
696 int err;
697
698 err = kstrtoul(buf, 10, &val);
699 if (err)
700 return err;
701
702 mutex_lock(&data->update_lock);
703 lm63_set_convrate(client, data, SENSORS_LIMIT(val, 0, 100000));
704 mutex_unlock(&data->update_lock);
705
706 return count;
707}
708
Guenter Roeckf496b2d2012-01-16 22:51:46 +0100709static ssize_t show_type(struct device *dev, struct device_attribute *attr,
710 char *buf)
711{
712 struct i2c_client *client = to_i2c_client(dev);
713 struct lm63_data *data = i2c_get_clientdata(client);
714
715 return sprintf(buf, data->trutherm ? "1\n" : "2\n");
716}
717
718static ssize_t set_type(struct device *dev, struct device_attribute *attr,
719 const char *buf, size_t count)
720{
721 struct i2c_client *client = to_i2c_client(dev);
722 struct lm63_data *data = i2c_get_clientdata(client);
723 unsigned long val;
724 int ret;
725 u8 reg;
726
727 ret = kstrtoul(buf, 10, &val);
728 if (ret < 0)
729 return ret;
730 if (val != 1 && val != 2)
731 return -EINVAL;
732
733 mutex_lock(&data->update_lock);
734 data->trutherm = val == 1;
735 reg = i2c_smbus_read_byte_data(client, LM96163_REG_TRUTHERM) & ~0x02;
736 i2c_smbus_write_byte_data(client, LM96163_REG_TRUTHERM,
737 reg | (data->trutherm ? 0x02 : 0x00));
738 data->valid = 0;
739 mutex_unlock(&data->update_lock);
740
741 return count;
742}
743
Jean Delvarebc51ae12005-06-05 20:32:27 +0200744static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
745 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
747 struct lm63_data *data = lm63_update_device(dev);
748 return sprintf(buf, "%u\n", data->alarms);
749}
750
Jean Delvare2d457712006-09-24 20:52:15 +0200751static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr,
752 char *buf)
753{
754 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
755 struct lm63_data *data = lm63_update_device(dev);
756 int bitnr = attr->index;
757
758 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
759}
760
Jean Delvarebc51ae12005-06-05 20:32:27 +0200761static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
762static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan,
763 set_fan, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Jean Delvared216f682012-01-16 22:51:47 +0100765static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1, 0);
Jean Delvare817c6cc2012-03-23 10:02:19 +0100766static DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
767 show_pwm1_enable, set_pwm1_enable);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100768static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO,
769 show_pwm1, set_pwm1, 1);
770static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IWUSR | S_IRUGO,
771 show_lut_temp, set_temp8, 3);
Jean Delvared216f682012-01-16 22:51:47 +0100772static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp_hyst, S_IRUGO,
773 show_lut_temp_hyst, NULL, 3);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100774static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
775 show_pwm1, set_pwm1, 2);
776static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IWUSR | S_IRUGO,
777 show_lut_temp, set_temp8, 4);
Jean Delvared216f682012-01-16 22:51:47 +0100778static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp_hyst, S_IRUGO,
779 show_lut_temp_hyst, NULL, 4);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100780static SENSOR_DEVICE_ATTR(pwm1_auto_point3_pwm, S_IWUSR | S_IRUGO,
781 show_pwm1, set_pwm1, 3);
782static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp, S_IWUSR | S_IRUGO,
783 show_lut_temp, set_temp8, 5);
Jean Delvared216f682012-01-16 22:51:47 +0100784static SENSOR_DEVICE_ATTR(pwm1_auto_point3_temp_hyst, S_IRUGO,
785 show_lut_temp_hyst, NULL, 5);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100786static SENSOR_DEVICE_ATTR(pwm1_auto_point4_pwm, S_IWUSR | S_IRUGO,
787 show_pwm1, set_pwm1, 4);
788static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp, S_IWUSR | S_IRUGO,
789 show_lut_temp, set_temp8, 6);
Jean Delvared216f682012-01-16 22:51:47 +0100790static SENSOR_DEVICE_ATTR(pwm1_auto_point4_temp_hyst, S_IRUGO,
791 show_lut_temp_hyst, NULL, 6);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100792static SENSOR_DEVICE_ATTR(pwm1_auto_point5_pwm, S_IWUSR | S_IRUGO,
793 show_pwm1, set_pwm1, 5);
794static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp, S_IWUSR | S_IRUGO,
795 show_lut_temp, set_temp8, 7);
Jean Delvared216f682012-01-16 22:51:47 +0100796static SENSOR_DEVICE_ATTR(pwm1_auto_point5_temp_hyst, S_IRUGO,
797 show_lut_temp_hyst, NULL, 7);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100798static SENSOR_DEVICE_ATTR(pwm1_auto_point6_pwm, S_IWUSR | S_IRUGO,
799 show_pwm1, set_pwm1, 6);
800static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp, S_IWUSR | S_IRUGO,
801 show_lut_temp, set_temp8, 8);
Jean Delvared216f682012-01-16 22:51:47 +0100802static SENSOR_DEVICE_ATTR(pwm1_auto_point6_temp_hyst, S_IRUGO,
803 show_lut_temp_hyst, NULL, 8);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100804static SENSOR_DEVICE_ATTR(pwm1_auto_point7_pwm, S_IWUSR | S_IRUGO,
805 show_pwm1, set_pwm1, 7);
806static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp, S_IWUSR | S_IRUGO,
807 show_lut_temp, set_temp8, 9);
Jean Delvared216f682012-01-16 22:51:47 +0100808static SENSOR_DEVICE_ATTR(pwm1_auto_point7_temp_hyst, S_IRUGO,
809 show_lut_temp_hyst, NULL, 9);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100810static SENSOR_DEVICE_ATTR(pwm1_auto_point8_pwm, S_IWUSR | S_IRUGO,
811 show_pwm1, set_pwm1, 8);
812static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp, S_IWUSR | S_IRUGO,
813 show_lut_temp, set_temp8, 10);
Jean Delvared216f682012-01-16 22:51:47 +0100814static SENSOR_DEVICE_ATTR(pwm1_auto_point8_temp_hyst, S_IRUGO,
815 show_lut_temp_hyst, NULL, 10);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100816static SENSOR_DEVICE_ATTR(pwm1_auto_point9_pwm, S_IWUSR | S_IRUGO,
817 show_pwm1, set_pwm1, 9);
818static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp, S_IWUSR | S_IRUGO,
819 show_lut_temp, set_temp8, 11);
Jean Delvare2fe28ab2012-01-16 22:51:47 +0100820static SENSOR_DEVICE_ATTR(pwm1_auto_point9_temp_hyst, S_IRUGO,
821 show_lut_temp_hyst, NULL, 11);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100822static SENSOR_DEVICE_ATTR(pwm1_auto_point10_pwm, S_IWUSR | S_IRUGO,
823 show_pwm1, set_pwm1, 10);
824static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp, S_IWUSR | S_IRUGO,
825 show_lut_temp, set_temp8, 12);
Jean Delvare2fe28ab2012-01-16 22:51:47 +0100826static SENSOR_DEVICE_ATTR(pwm1_auto_point10_temp_hyst, S_IRUGO,
827 show_lut_temp_hyst, NULL, 12);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100828static SENSOR_DEVICE_ATTR(pwm1_auto_point11_pwm, S_IWUSR | S_IRUGO,
829 show_pwm1, set_pwm1, 11);
830static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp, S_IWUSR | S_IRUGO,
831 show_lut_temp, set_temp8, 13);
Jean Delvare2fe28ab2012-01-16 22:51:47 +0100832static SENSOR_DEVICE_ATTR(pwm1_auto_point11_temp_hyst, S_IRUGO,
833 show_lut_temp_hyst, NULL, 13);
Jean Delvareaf2ef4f2012-03-23 10:02:19 +0100834static SENSOR_DEVICE_ATTR(pwm1_auto_point12_pwm, S_IWUSR | S_IRUGO,
835 show_pwm1, set_pwm1, 12);
836static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp, S_IWUSR | S_IRUGO,
837 show_lut_temp, set_temp8, 14);
Jean Delvare2fe28ab2012-01-16 22:51:47 +0100838static SENSOR_DEVICE_ATTR(pwm1_auto_point12_temp_hyst, S_IRUGO,
839 show_lut_temp_hyst, NULL, 14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Dirk Eibach2778fb12011-02-09 04:51:34 -0500841static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0);
842static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8,
Guenter Roeck94e55df2012-01-16 22:51:46 +0100843 set_temp8, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Jean Delvarebc51ae12005-06-05 20:32:27 +0200845static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
846static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
847 set_temp11, 1);
848static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
849 set_temp11, 2);
Guenter Roeck786375f2012-01-16 22:51:45 +0100850static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
851 set_temp11, 3);
Dirk Eibach2778fb12011-02-09 04:51:34 -0500852static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8,
Guenter Roeck94e55df2012-01-16 22:51:46 +0100853 set_temp8, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
855 set_temp2_crit_hyst);
856
Guenter Roeckf496b2d2012-01-16 22:51:46 +0100857static DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type);
858
Jean Delvare2d457712006-09-24 20:52:15 +0200859/* Individual alarm files */
860static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
861static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
Jean Delvare7817a392007-06-09 10:11:16 -0400862static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2);
Jean Delvare2d457712006-09-24 20:52:15 +0200863static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
864static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
865static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
866/* Raw alarm file for compatibility */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
868
Guenter Roeck04738b22012-01-16 22:51:46 +0100869static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval,
870 set_update_interval);
871
Jean Delvare0e39e012006-09-24 21:16:40 +0200872static struct attribute *lm63_attributes[] = {
Jean Delvared216f682012-01-16 22:51:47 +0100873 &sensor_dev_attr_pwm1.dev_attr.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +0200874 &dev_attr_pwm1_enable.attr,
Jean Delvared216f682012-01-16 22:51:47 +0100875 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
876 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
877 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
878 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
879 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
880 &sensor_dev_attr_pwm1_auto_point2_temp_hyst.dev_attr.attr,
881 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
882 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
883 &sensor_dev_attr_pwm1_auto_point3_temp_hyst.dev_attr.attr,
884 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
885 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
886 &sensor_dev_attr_pwm1_auto_point4_temp_hyst.dev_attr.attr,
887 &sensor_dev_attr_pwm1_auto_point5_pwm.dev_attr.attr,
888 &sensor_dev_attr_pwm1_auto_point5_temp.dev_attr.attr,
889 &sensor_dev_attr_pwm1_auto_point5_temp_hyst.dev_attr.attr,
890 &sensor_dev_attr_pwm1_auto_point6_pwm.dev_attr.attr,
891 &sensor_dev_attr_pwm1_auto_point6_temp.dev_attr.attr,
892 &sensor_dev_attr_pwm1_auto_point6_temp_hyst.dev_attr.attr,
893 &sensor_dev_attr_pwm1_auto_point7_pwm.dev_attr.attr,
894 &sensor_dev_attr_pwm1_auto_point7_temp.dev_attr.attr,
895 &sensor_dev_attr_pwm1_auto_point7_temp_hyst.dev_attr.attr,
896 &sensor_dev_attr_pwm1_auto_point8_pwm.dev_attr.attr,
897 &sensor_dev_attr_pwm1_auto_point8_temp.dev_attr.attr,
898 &sensor_dev_attr_pwm1_auto_point8_temp_hyst.dev_attr.attr,
899
Jean Delvare0e39e012006-09-24 21:16:40 +0200900 &sensor_dev_attr_temp1_input.dev_attr.attr,
901 &sensor_dev_attr_temp2_input.dev_attr.attr,
902 &sensor_dev_attr_temp2_min.dev_attr.attr,
903 &sensor_dev_attr_temp1_max.dev_attr.attr,
904 &sensor_dev_attr_temp2_max.dev_attr.attr,
Guenter Roeck786375f2012-01-16 22:51:45 +0100905 &sensor_dev_attr_temp2_offset.dev_attr.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +0200906 &sensor_dev_attr_temp2_crit.dev_attr.attr,
907 &dev_attr_temp2_crit_hyst.attr,
908
909 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
Jean Delvare7817a392007-06-09 10:11:16 -0400910 &sensor_dev_attr_temp2_fault.dev_attr.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +0200911 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
912 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
913 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
914 &dev_attr_alarms.attr,
Guenter Roeck04738b22012-01-16 22:51:46 +0100915 &dev_attr_update_interval.attr,
Jean Delvare0e39e012006-09-24 21:16:40 +0200916 NULL
917};
918
Jean Delvare2fe28ab2012-01-16 22:51:47 +0100919static struct attribute *lm63_attributes_extra_lut[] = {
920 &sensor_dev_attr_pwm1_auto_point9_pwm.dev_attr.attr,
921 &sensor_dev_attr_pwm1_auto_point9_temp.dev_attr.attr,
922 &sensor_dev_attr_pwm1_auto_point9_temp_hyst.dev_attr.attr,
923 &sensor_dev_attr_pwm1_auto_point10_pwm.dev_attr.attr,
924 &sensor_dev_attr_pwm1_auto_point10_temp.dev_attr.attr,
925 &sensor_dev_attr_pwm1_auto_point10_temp_hyst.dev_attr.attr,
926 &sensor_dev_attr_pwm1_auto_point11_pwm.dev_attr.attr,
927 &sensor_dev_attr_pwm1_auto_point11_temp.dev_attr.attr,
928 &sensor_dev_attr_pwm1_auto_point11_temp_hyst.dev_attr.attr,
929 &sensor_dev_attr_pwm1_auto_point12_pwm.dev_attr.attr,
930 &sensor_dev_attr_pwm1_auto_point12_temp.dev_attr.attr,
931 &sensor_dev_attr_pwm1_auto_point12_temp_hyst.dev_attr.attr,
932 NULL
933};
934
935static const struct attribute_group lm63_group_extra_lut = {
936 .attrs = lm63_attributes_extra_lut,
937};
938
Guenter Roeck94e55df2012-01-16 22:51:46 +0100939/*
940 * On LM63, temp2_crit can be set only once, which should be job
941 * of the bootloader.
942 * On LM64, temp2_crit can always be set.
943 * On LM96163, temp2_crit can be set if bit 1 of the configuration
944 * register is true.
945 */
946static umode_t lm63_attribute_mode(struct kobject *kobj,
947 struct attribute *attr, int index)
948{
949 struct device *dev = container_of(kobj, struct device, kobj);
950 struct i2c_client *client = to_i2c_client(dev);
951 struct lm63_data *data = i2c_get_clientdata(client);
952
953 if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr
954 && (data->kind == lm64 ||
955 (data->kind == lm96163 && (data->config & 0x02))))
956 return attr->mode | S_IWUSR;
957
958 return attr->mode;
959}
960
Jean Delvare0e39e012006-09-24 21:16:40 +0200961static const struct attribute_group lm63_group = {
Guenter Roeck94e55df2012-01-16 22:51:46 +0100962 .is_visible = lm63_attribute_mode,
Jean Delvare0e39e012006-09-24 21:16:40 +0200963 .attrs = lm63_attributes,
964};
965
966static struct attribute *lm63_attributes_fan1[] = {
967 &sensor_dev_attr_fan1_input.dev_attr.attr,
968 &sensor_dev_attr_fan1_min.dev_attr.attr,
969
970 &sensor_dev_attr_fan1_min_alarm.dev_attr.attr,
971 NULL
972};
973
974static const struct attribute_group lm63_group_fan1 = {
975 .attrs = lm63_attributes_fan1,
976};
977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978/*
979 * Real code
980 */
981
Jean Delvared5957be2008-07-16 19:30:13 +0200982/* Return 0 if detection is successful, -ENODEV otherwise */
Jean Delvaredac27dc2012-03-23 10:02:18 +0100983static int lm63_detect(struct i2c_client *client,
Jean Delvared5957be2008-07-16 19:30:13 +0200984 struct i2c_board_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985{
Jean Delvaredac27dc2012-03-23 10:02:18 +0100986 struct i2c_adapter *adapter = client->adapter;
Jean Delvare52df6442009-12-09 20:35:57 +0100987 u8 man_id, chip_id, reg_config1, reg_config2;
988 u8 reg_alert_status, reg_alert_mask;
Jean Delvaredac27dc2012-03-23 10:02:18 +0100989 int address = client->addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Jean Delvared5957be2008-07-16 19:30:13 +0200992 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Jean Delvaredac27dc2012-03-23 10:02:18 +0100994 man_id = i2c_smbus_read_byte_data(client, LM63_REG_MAN_ID);
995 chip_id = i2c_smbus_read_byte_data(client, LM63_REG_CHIP_ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Jean Delvaredac27dc2012-03-23 10:02:18 +0100997 reg_config1 = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1);
998 reg_config2 = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG2);
999 reg_alert_status = i2c_smbus_read_byte_data(client,
Jean Delvare52df6442009-12-09 20:35:57 +01001000 LM63_REG_ALERT_STATUS);
Jean Delvaredac27dc2012-03-23 10:02:18 +01001001 reg_alert_mask = i2c_smbus_read_byte_data(client, LM63_REG_ALERT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Jean Delvare52df6442009-12-09 20:35:57 +01001003 if (man_id != 0x01 /* National Semiconductor */
Jean Delvare52df6442009-12-09 20:35:57 +01001004 || (reg_config1 & 0x18) != 0x00
1005 || (reg_config2 & 0xF8) != 0x00
1006 || (reg_alert_status & 0x20) != 0x00
1007 || (reg_alert_mask & 0xA4) != 0xA4) {
1008 dev_dbg(&adapter->dev,
1009 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
1010 man_id, chip_id);
1011 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
1013
Matthew Garrett10f2ed32010-05-27 19:58:38 +02001014 if (chip_id == 0x41 && address == 0x4c)
1015 strlcpy(info->type, "lm63", I2C_NAME_SIZE);
1016 else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e))
1017 strlcpy(info->type, "lm64", I2C_NAME_SIZE);
Guenter Roeck210961c2012-01-16 22:51:45 +01001018 else if (chip_id == 0x49 && address == 0x4c)
1019 strlcpy(info->type, "lm96163", I2C_NAME_SIZE);
Matthew Garrett10f2ed32010-05-27 19:58:38 +02001020 else
1021 return -ENODEV;
Jean Delvared5957be2008-07-16 19:30:13 +02001022
1023 return 0;
1024}
1025
Guenter Roeck662bda22012-01-16 22:51:45 +01001026/*
1027 * Ideally we shouldn't have to initialize anything, since the BIOS
1028 * should have taken care of everything
1029 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030static void lm63_init_client(struct i2c_client *client)
1031{
1032 struct lm63_data *data = i2c_get_clientdata(client);
Guenter Roeck04738b22012-01-16 22:51:46 +01001033 u8 convrate;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
1035 data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1);
1036 data->config_fan = i2c_smbus_read_byte_data(client,
1037 LM63_REG_CONFIG_FAN);
1038
1039 /* Start converting if needed */
1040 if (data->config & 0x40) { /* standby */
Joe Perches898eb712007-10-18 03:06:30 -07001041 dev_dbg(&client->dev, "Switching to operational mode\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 data->config &= 0xA7;
1043 i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1,
1044 data->config);
1045 }
Jean Delvare409c0b52012-01-16 22:51:46 +01001046 /* Tachometer is always enabled on LM64 */
1047 if (data->kind == lm64)
1048 data->config |= 0x04;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 /* We may need pwm1_freq before ever updating the client data */
1051 data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ);
1052 if (data->pwm1_freq == 0)
1053 data->pwm1_freq = 1;
1054
Guenter Roeck04738b22012-01-16 22:51:46 +01001055 switch (data->kind) {
1056 case lm63:
1057 case lm64:
1058 data->max_convrate_hz = LM63_MAX_CONVRATE_HZ;
Jean Delvare2fe28ab2012-01-16 22:51:47 +01001059 data->lut_size = 8;
Guenter Roeck04738b22012-01-16 22:51:46 +01001060 break;
1061 case lm96163:
1062 data->max_convrate_hz = LM96163_MAX_CONVRATE_HZ;
Jean Delvare2fe28ab2012-01-16 22:51:47 +01001063 data->lut_size = 12;
Guenter Roeckf496b2d2012-01-16 22:51:46 +01001064 data->trutherm
1065 = i2c_smbus_read_byte_data(client,
1066 LM96163_REG_TRUTHERM) & 0x02;
Guenter Roeck04738b22012-01-16 22:51:46 +01001067 break;
1068 }
1069 convrate = i2c_smbus_read_byte_data(client, LM63_REG_CONVRATE);
1070 if (unlikely(convrate > LM63_MAX_CONVRATE))
1071 convrate = LM63_MAX_CONVRATE;
1072 data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz,
1073 convrate);
1074
Guenter Roeck210961c2012-01-16 22:51:45 +01001075 /*
Guenter Roecke872c912012-01-16 22:51:46 +01001076 * For LM96163, check if high resolution PWM
1077 * and unsigned temperature format is enabled.
Guenter Roeck210961c2012-01-16 22:51:45 +01001078 */
1079 if (data->kind == lm96163) {
1080 u8 config_enhanced
1081 = i2c_smbus_read_byte_data(client,
1082 LM96163_REG_CONFIG_ENHANCED);
Jean Delvared216f682012-01-16 22:51:47 +01001083 if (config_enhanced & 0x20)
1084 data->lut_temp_highres = true;
Guenter Roeck210961c2012-01-16 22:51:45 +01001085 if ((config_enhanced & 0x10)
1086 && !(data->config_fan & 0x08) && data->pwm1_freq == 8)
1087 data->pwm_highres = true;
1088 if (config_enhanced & 0x08)
Guenter Roecke872c912012-01-16 22:51:46 +01001089 data->remote_unsigned = true;
Guenter Roeck210961c2012-01-16 22:51:45 +01001090 }
1091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 /* Show some debug info about the LM63 configuration */
Jean Delvare409c0b52012-01-16 22:51:46 +01001093 if (data->kind == lm63)
1094 dev_dbg(&client->dev, "Alert/tach pin configured for %s\n",
1095 (data->config & 0x04) ? "tachometer input" :
1096 "alert output");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n",
1098 (data->config_fan & 0x08) ? "1.4" : "360",
1099 ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq);
1100 dev_dbg(&client->dev, "PWM output active %s, %s mode\n",
1101 (data->config_fan & 0x10) ? "low" : "high",
1102 (data->config_fan & 0x20) ? "manual" : "auto");
1103}
1104
Jean Delvaredac27dc2012-03-23 10:02:18 +01001105static int lm63_probe(struct i2c_client *client,
1106 const struct i2c_device_id *id)
1107{
1108 struct lm63_data *data;
1109 int err;
1110
1111 data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL);
1112 if (!data) {
1113 err = -ENOMEM;
1114 goto exit;
1115 }
1116
1117 i2c_set_clientdata(client, data);
1118 data->valid = 0;
1119 mutex_init(&data->update_lock);
1120
1121 /* Set the device type */
1122 data->kind = id->driver_data;
1123 if (data->kind == lm64)
1124 data->temp2_offset = 16000;
1125
1126 /* Initialize chip */
1127 lm63_init_client(client);
1128
1129 /* Register sysfs hooks */
1130 err = sysfs_create_group(&client->dev.kobj, &lm63_group);
1131 if (err)
1132 goto exit_free;
1133 if (data->config & 0x04) { /* tachometer enabled */
1134 err = sysfs_create_group(&client->dev.kobj, &lm63_group_fan1);
1135 if (err)
1136 goto exit_remove_files;
1137 }
1138 if (data->kind == lm96163) {
1139 err = device_create_file(&client->dev, &dev_attr_temp2_type);
1140 if (err)
1141 goto exit_remove_files;
1142
1143 err = sysfs_create_group(&client->dev.kobj,
1144 &lm63_group_extra_lut);
1145 if (err)
1146 goto exit_remove_files;
1147 }
1148
1149 data->hwmon_dev = hwmon_device_register(&client->dev);
1150 if (IS_ERR(data->hwmon_dev)) {
1151 err = PTR_ERR(data->hwmon_dev);
1152 goto exit_remove_files;
1153 }
1154
1155 return 0;
1156
1157exit_remove_files:
1158 sysfs_remove_group(&client->dev.kobj, &lm63_group);
1159 sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1);
1160 if (data->kind == lm96163) {
1161 device_remove_file(&client->dev, &dev_attr_temp2_type);
1162 sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut);
1163 }
1164exit_free:
1165 kfree(data);
1166exit:
1167 return err;
1168}
1169
Jean Delvared5957be2008-07-16 19:30:13 +02001170static int lm63_remove(struct i2c_client *client)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001172 struct lm63_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Tony Jones1beeffe2007-08-20 13:46:20 -07001174 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare0e39e012006-09-24 21:16:40 +02001175 sysfs_remove_group(&client->dev.kobj, &lm63_group);
1176 sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1);
Jean Delvare2fe28ab2012-01-16 22:51:47 +01001177 if (data->kind == lm96163) {
1178 device_remove_file(&client->dev, &dev_attr_temp2_type);
1179 sysfs_remove_group(&client->dev.kobj, &lm63_group_extra_lut);
1180 }
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001181
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001182 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 return 0;
1184}
1185
Jean Delvaredac27dc2012-03-23 10:02:18 +01001186/*
1187 * Driver data (common to all clients)
1188 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Jean Delvaredac27dc2012-03-23 10:02:18 +01001190static const struct i2c_device_id lm63_id[] = {
1191 { "lm63", lm63 },
1192 { "lm64", lm64 },
1193 { "lm96163", lm96163 },
1194 { }
1195};
1196MODULE_DEVICE_TABLE(i2c, lm63_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Jean Delvaredac27dc2012-03-23 10:02:18 +01001198static struct i2c_driver lm63_driver = {
1199 .class = I2C_CLASS_HWMON,
1200 .driver = {
1201 .name = "lm63",
1202 },
1203 .probe = lm63_probe,
1204 .remove = lm63_remove,
1205 .id_table = lm63_id,
1206 .detect = lm63_detect,
1207 .address_list = normal_i2c,
1208};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Axel Linf0967ee2012-01-20 15:38:18 +08001210module_i2c_driver(lm63_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1213MODULE_DESCRIPTION("LM63 driver");
1214MODULE_LICENSE("GPL");