blob: c2da2b161996c31464e32b94eafd84ed7b4e3559 [file] [log] [blame]
Davide Rizzo06160322009-03-31 15:24:27 -07001/*
Davide Rizzo0f1deb42010-11-18 07:23:00 -08002 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com>
Davide Rizzo06160322009-03-31 15:24:27 -07003 *
Davide Rizzo0f1deb42010-11-18 07:23:00 -08004 * The LM95241 is a sensor chip made by National Semiconductors.
5 * It reports up to three temperatures (its own plus up to two external ones).
6 * Complete datasheet can be obtained from National's website at:
Davide Rizzo06160322009-03-31 15:24:27 -07007 * http://www.national.com/ds.cgi/LM/LM95241.pdf
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
Guenter Roeck4b2ea082016-07-04 06:48:18 -070024#include <linux/err.h>
Davide Rizzo06160322009-03-31 15:24:27 -070025#include <linux/i2c.h>
Guenter Roeck4b2ea082016-07-04 06:48:18 -070026#include <linux/init.h>
27#include <linux/jiffies.h>
Davide Rizzo06160322009-03-31 15:24:27 -070028#include <linux/hwmon.h>
29#include <linux/hwmon-sysfs.h>
Guenter Roeck4b2ea082016-07-04 06:48:18 -070030#include <linux/module.h>
Davide Rizzo06160322009-03-31 15:24:27 -070031#include <linux/mutex.h>
Guenter Roeck4b2ea082016-07-04 06:48:18 -070032#include <linux/slab.h>
Davide Rizzo06160322009-03-31 15:24:27 -070033#include <linux/sysfs.h>
34
Davide Rizzo0f1deb42010-11-18 07:23:00 -080035#define DEVNAME "lm95241"
36
Davide Rizzo06160322009-03-31 15:24:27 -070037static const unsigned short normal_i2c[] = {
Davide Rizzo0f1deb42010-11-18 07:23:00 -080038 0x19, 0x2a, 0x2b, I2C_CLIENT_END };
Davide Rizzo06160322009-03-31 15:24:27 -070039
Davide Rizzo06160322009-03-31 15:24:27 -070040/* LM95241 registers */
41#define LM95241_REG_R_MAN_ID 0xFE
42#define LM95241_REG_R_CHIP_ID 0xFF
43#define LM95241_REG_R_STATUS 0x02
44#define LM95241_REG_RW_CONFIG 0x03
45#define LM95241_REG_RW_REM_FILTER 0x06
46#define LM95241_REG_RW_TRUTHERM 0x07
Davide Rizzo0f1deb42010-11-18 07:23:00 -080047#define LM95241_REG_W_ONE_SHOT 0x0F
Davide Rizzo06160322009-03-31 15:24:27 -070048#define LM95241_REG_R_LOCAL_TEMPH 0x10
49#define LM95241_REG_R_REMOTE1_TEMPH 0x11
50#define LM95241_REG_R_REMOTE2_TEMPH 0x12
51#define LM95241_REG_R_LOCAL_TEMPL 0x20
52#define LM95241_REG_R_REMOTE1_TEMPL 0x21
53#define LM95241_REG_R_REMOTE2_TEMPL 0x22
54#define LM95241_REG_RW_REMOTE_MODEL 0x30
55
56/* LM95241 specific bitfields */
57#define CFG_STOP 0x40
58#define CFG_CR0076 0x00
59#define CFG_CR0182 0x10
60#define CFG_CR1000 0x20
61#define CFG_CR2700 0x30
Guenter Roeckf48ccb22016-07-03 21:46:05 -070062#define CFG_CRMASK 0x30
Davide Rizzo06160322009-03-31 15:24:27 -070063#define R1MS_SHIFT 0
64#define R2MS_SHIFT 2
65#define R1MS_MASK (0x01 << (R1MS_SHIFT))
66#define R2MS_MASK (0x01 << (R2MS_SHIFT))
67#define R1DF_SHIFT 1
68#define R2DF_SHIFT 2
69#define R1DF_MASK (0x01 << (R1DF_SHIFT))
70#define R2DF_MASK (0x01 << (R2DF_SHIFT))
71#define R1FE_MASK 0x01
72#define R2FE_MASK 0x05
Guenter Roeck090a7f82016-07-04 06:46:31 -070073#define R1DM 0x01
74#define R2DM 0x02
Davide Rizzo06160322009-03-31 15:24:27 -070075#define TT1_SHIFT 0
76#define TT2_SHIFT 4
77#define TT_OFF 0
78#define TT_ON 1
79#define TT_MASK 7
Guenter Roeck8c1d0412011-07-05 13:31:48 -070080#define NATSEMI_MAN_ID 0x01
81#define LM95231_CHIP_ID 0xA1
82#define LM95241_CHIP_ID 0xA4
Davide Rizzo06160322009-03-31 15:24:27 -070083
Davide Rizzo0f1deb42010-11-18 07:23:00 -080084static const u8 lm95241_reg_address[] = {
85 LM95241_REG_R_LOCAL_TEMPH,
86 LM95241_REG_R_LOCAL_TEMPL,
87 LM95241_REG_R_REMOTE1_TEMPH,
88 LM95241_REG_R_REMOTE1_TEMPL,
89 LM95241_REG_R_REMOTE2_TEMPH,
90 LM95241_REG_R_REMOTE2_TEMPL
91};
Davide Rizzo06160322009-03-31 15:24:27 -070092
Davide Rizzo06160322009-03-31 15:24:27 -070093/* Client data (each client gets its own) */
94struct lm95241_data {
Guenter Roeckf8096212014-01-20 09:25:50 -080095 struct i2c_client *client;
Davide Rizzo06160322009-03-31 15:24:27 -070096 struct mutex update_lock;
Guenter Roeckf48ccb22016-07-03 21:46:05 -070097 unsigned long last_updated; /* in jiffies */
98 unsigned long interval; /* in milli-seconds */
Davide Rizzo0f1deb42010-11-18 07:23:00 -080099 char valid; /* zero until following fields are valid */
Davide Rizzo06160322009-03-31 15:24:27 -0700100 /* registers values */
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800101 u8 temp[ARRAY_SIZE(lm95241_reg_address)];
Guenter Roeck090a7f82016-07-04 06:46:31 -0700102 u8 status, config, model, trutherm;
Davide Rizzo06160322009-03-31 15:24:27 -0700103};
104
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800105/* Conversions */
Guenter Roeck0c2a40e2011-06-30 02:09:37 -0700106static int temp_from_reg_signed(u8 val_h, u8 val_l)
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800107{
Guenter Roeck0c2a40e2011-06-30 02:09:37 -0700108 s16 val_hl = (val_h << 8) | val_l;
109 return val_hl * 1000 / 256;
110}
111
112static int temp_from_reg_unsigned(u8 val_h, u8 val_l)
113{
114 u16 val_hl = (val_h << 8) | val_l;
115 return val_hl * 1000 / 256;
Davide Rizzo06160322009-03-31 15:24:27 -0700116}
Davide Rizzo06160322009-03-31 15:24:27 -0700117
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800118static struct lm95241_data *lm95241_update_device(struct device *dev)
119{
Guenter Roeckf8096212014-01-20 09:25:50 -0800120 struct lm95241_data *data = dev_get_drvdata(dev);
121 struct i2c_client *client = data->client;
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800122
123 mutex_lock(&data->update_lock);
124
Guenter Roeckf48ccb22016-07-03 21:46:05 -0700125 if (time_after(jiffies, data->last_updated
126 + msecs_to_jiffies(data->interval)) ||
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800127 !data->valid) {
128 int i;
129
Guenter Roeckf8096212014-01-20 09:25:50 -0800130 dev_dbg(dev, "Updating lm95241 data.\n");
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800131 for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++)
132 data->temp[i]
133 = i2c_smbus_read_byte_data(client,
134 lm95241_reg_address[i]);
Guenter Roeck090a7f82016-07-04 06:46:31 -0700135
136 data->status = i2c_smbus_read_byte_data(client,
137 LM95241_REG_R_STATUS);
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800138 data->last_updated = jiffies;
139 data->valid = 1;
140 }
141
142 mutex_unlock(&data->update_lock);
143
144 return data;
145}
146
147/* Sysfs stuff */
148static ssize_t show_input(struct device *dev, struct device_attribute *attr,
149 char *buf)
Davide Rizzo06160322009-03-31 15:24:27 -0700150{
151 struct lm95241_data *data = lm95241_update_device(dev);
Guenter Roeck0c2a40e2011-06-30 02:09:37 -0700152 int index = to_sensor_dev_attr(attr)->index;
Davide Rizzo06160322009-03-31 15:24:27 -0700153
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800154 return snprintf(buf, PAGE_SIZE - 1, "%d\n",
Guenter Roeck0c2a40e2011-06-30 02:09:37 -0700155 index == 0 || (data->config & (1 << (index / 2))) ?
156 temp_from_reg_signed(data->temp[index], data->temp[index + 1]) :
157 temp_from_reg_unsigned(data->temp[index],
158 data->temp[index + 1]));
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800159}
160
161static ssize_t show_type(struct device *dev, struct device_attribute *attr,
162 char *buf)
163{
Guenter Roeckf8096212014-01-20 09:25:50 -0800164 struct lm95241_data *data = dev_get_drvdata(dev);
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800165
166 return snprintf(buf, PAGE_SIZE - 1,
167 data->model & to_sensor_dev_attr(attr)->index ? "1\n" : "2\n");
168}
169
170static ssize_t set_type(struct device *dev, struct device_attribute *attr,
171 const char *buf, size_t count)
172{
Guenter Roeckf8096212014-01-20 09:25:50 -0800173 struct lm95241_data *data = dev_get_drvdata(dev);
174 struct i2c_client *client = data->client;
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800175 unsigned long val;
176 int shift;
177 u8 mask = to_sensor_dev_attr(attr)->index;
178
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100179 if (kstrtoul(buf, 10, &val) < 0)
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800180 return -EINVAL;
181 if (val != 1 && val != 2)
182 return -EINVAL;
183
184 shift = mask == R1MS_MASK ? TT1_SHIFT : TT2_SHIFT;
185
186 mutex_lock(&data->update_lock);
187
188 data->trutherm &= ~(TT_MASK << shift);
189 if (val == 1) {
190 data->model |= mask;
191 data->trutherm |= (TT_ON << shift);
192 } else {
193 data->model &= ~mask;
194 data->trutherm |= (TT_OFF << shift);
195 }
196 data->valid = 0;
197
198 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL,
199 data->model);
200 i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM,
201 data->trutherm);
202
203 mutex_unlock(&data->update_lock);
204
205 return count;
206}
207
208static ssize_t show_min(struct device *dev, struct device_attribute *attr,
209 char *buf)
210{
Guenter Roeckf8096212014-01-20 09:25:50 -0800211 struct lm95241_data *data = dev_get_drvdata(dev);
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800212
213 return snprintf(buf, PAGE_SIZE - 1,
214 data->config & to_sensor_dev_attr(attr)->index ?
215 "-127000\n" : "0\n");
216}
217
218static ssize_t set_min(struct device *dev, struct device_attribute *attr,
219 const char *buf, size_t count)
220{
Guenter Roeckf8096212014-01-20 09:25:50 -0800221 struct lm95241_data *data = dev_get_drvdata(dev);
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800222 long val;
223
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100224 if (kstrtol(buf, 10, &val) < 0)
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800225 return -EINVAL;
226 if (val < -128000)
227 return -EINVAL;
228
229 mutex_lock(&data->update_lock);
230
231 if (val < 0)
232 data->config |= to_sensor_dev_attr(attr)->index;
233 else
234 data->config &= ~to_sensor_dev_attr(attr)->index;
235 data->valid = 0;
236
Guenter Roeckf8096212014-01-20 09:25:50 -0800237 i2c_smbus_write_byte_data(data->client, LM95241_REG_RW_CONFIG,
238 data->config);
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800239
240 mutex_unlock(&data->update_lock);
241
242 return count;
243}
244
245static ssize_t show_max(struct device *dev, struct device_attribute *attr,
246 char *buf)
247{
Guenter Roeckf8096212014-01-20 09:25:50 -0800248 struct lm95241_data *data = dev_get_drvdata(dev);
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800249
250 return snprintf(buf, PAGE_SIZE - 1,
251 data->config & to_sensor_dev_attr(attr)->index ?
252 "127000\n" : "255000\n");
253}
254
255static ssize_t set_max(struct device *dev, struct device_attribute *attr,
256 const char *buf, size_t count)
257{
Guenter Roeckf8096212014-01-20 09:25:50 -0800258 struct lm95241_data *data = dev_get_drvdata(dev);
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800259 long val;
260
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100261 if (kstrtol(buf, 10, &val) < 0)
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800262 return -EINVAL;
263 if (val >= 256000)
264 return -EINVAL;
265
266 mutex_lock(&data->update_lock);
267
268 if (val <= 127000)
269 data->config |= to_sensor_dev_attr(attr)->index;
270 else
271 data->config &= ~to_sensor_dev_attr(attr)->index;
272 data->valid = 0;
273
Guenter Roeckf8096212014-01-20 09:25:50 -0800274 i2c_smbus_write_byte_data(data->client, LM95241_REG_RW_CONFIG,
275 data->config);
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800276
277 mutex_unlock(&data->update_lock);
278
279 return count;
280}
281
Guenter Roeck090a7f82016-07-04 06:46:31 -0700282static ssize_t show_fault(struct device *dev, struct device_attribute *attr,
283 char *buf)
284{
285 struct lm95241_data *data = lm95241_update_device(dev);
286
287 return snprintf(buf, PAGE_SIZE - 1, "%d",
288 !!(data->status & to_sensor_dev_attr(attr)->index));
289}
290
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800291static ssize_t show_interval(struct device *dev, struct device_attribute *attr,
292 char *buf)
293{
294 struct lm95241_data *data = lm95241_update_device(dev);
295
Guenter Roeckf48ccb22016-07-03 21:46:05 -0700296 return snprintf(buf, PAGE_SIZE - 1, "%lu\n", data->interval);
Davide Rizzo06160322009-03-31 15:24:27 -0700297}
298
Guenter Roeckbc482bf2010-09-17 17:24:15 +0200299static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800300 const char *buf, size_t count)
Davide Rizzo06160322009-03-31 15:24:27 -0700301{
Guenter Roeckf8096212014-01-20 09:25:50 -0800302 struct lm95241_data *data = dev_get_drvdata(dev);
Jean Delvare61ec2da2010-11-15 21:38:56 +0100303 unsigned long val;
Guenter Roeckf48ccb22016-07-03 21:46:05 -0700304 int convrate;
305 u8 config;
Davide Rizzo06160322009-03-31 15:24:27 -0700306
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100307 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvare61ec2da2010-11-15 21:38:56 +0100308 return -EINVAL;
309
Guenter Roeckf48ccb22016-07-03 21:46:05 -0700310 mutex_lock(&data->update_lock);
311
312 config = data->config & ~CFG_CRMASK;
313
314 if (val < 130) {
315 convrate = 76;
316 config |= CFG_CR0076;
317 } else if (val < 590) {
318 convrate = 182;
319 config |= CFG_CR0182;
320 } else if (val < 1850) {
321 convrate = 1000;
322 config |= CFG_CR1000;
323 } else {
324 convrate = 2700;
325 config |= CFG_CR2700;
326 }
327
328 data->interval = convrate;
329 data->config = config;
330 i2c_smbus_write_byte_data(data->client, LM95241_REG_RW_CONFIG,
331 config);
332 mutex_unlock(&data->update_lock);
Davide Rizzo06160322009-03-31 15:24:27 -0700333
334 return count;
335}
336
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800337static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0);
338static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2);
339static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_input, NULL, 4);
340static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type,
341 R1MS_MASK);
342static SENSOR_DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type, set_type,
343 R2MS_MASK);
344static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min, set_min,
345 R1DF_MASK);
346static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min, set_min,
347 R2DF_MASK);
348static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max, set_max,
349 R1DF_MASK);
350static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max, set_max,
351 R2DF_MASK);
Guenter Roeck090a7f82016-07-04 06:46:31 -0700352static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_fault, NULL, R1DM);
353static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_fault, NULL, R2DM);
Guenter Roeckbc482bf2010-09-17 17:24:15 +0200354static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval,
355 set_interval);
Davide Rizzo06160322009-03-31 15:24:27 -0700356
Guenter Roeckf8096212014-01-20 09:25:50 -0800357static struct attribute *lm95241_attrs[] = {
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800358 &sensor_dev_attr_temp1_input.dev_attr.attr,
359 &sensor_dev_attr_temp2_input.dev_attr.attr,
360 &sensor_dev_attr_temp3_input.dev_attr.attr,
361 &sensor_dev_attr_temp2_type.dev_attr.attr,
362 &sensor_dev_attr_temp3_type.dev_attr.attr,
363 &sensor_dev_attr_temp2_min.dev_attr.attr,
364 &sensor_dev_attr_temp3_min.dev_attr.attr,
365 &sensor_dev_attr_temp2_max.dev_attr.attr,
366 &sensor_dev_attr_temp3_max.dev_attr.attr,
Guenter Roeck090a7f82016-07-04 06:46:31 -0700367 &sensor_dev_attr_temp2_fault.dev_attr.attr,
368 &sensor_dev_attr_temp3_fault.dev_attr.attr,
Guenter Roeckbc482bf2010-09-17 17:24:15 +0200369 &dev_attr_update_interval.attr,
Davide Rizzo06160322009-03-31 15:24:27 -0700370 NULL
371};
Guenter Roeckf8096212014-01-20 09:25:50 -0800372ATTRIBUTE_GROUPS(lm95241);
Davide Rizzo06160322009-03-31 15:24:27 -0700373
Jean Delvare797eaa42009-04-07 15:32:59 +0200374/* Return 0 if detection is successful, -ENODEV otherwise */
Jean Delvare310ec792009-12-14 21:17:23 +0100375static int lm95241_detect(struct i2c_client *new_client,
Jean Delvare797eaa42009-04-07 15:32:59 +0200376 struct i2c_board_info *info)
Davide Rizzo06160322009-03-31 15:24:27 -0700377{
Jean Delvare797eaa42009-04-07 15:32:59 +0200378 struct i2c_adapter *adapter = new_client->adapter;
Jean Delvare52df6442009-12-09 20:35:57 +0100379 const char *name;
Guenter Roeck8c1d0412011-07-05 13:31:48 -0700380 int mfg_id, chip_id;
Davide Rizzo06160322009-03-31 15:24:27 -0700381
382 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Jean Delvare797eaa42009-04-07 15:32:59 +0200383 return -ENODEV;
Davide Rizzo06160322009-03-31 15:24:27 -0700384
Guenter Roeck8c1d0412011-07-05 13:31:48 -0700385 mfg_id = i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID);
386 if (mfg_id != NATSEMI_MAN_ID)
387 return -ENODEV;
388
389 chip_id = i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID);
390 switch (chip_id) {
391 case LM95231_CHIP_ID:
392 name = "lm95231";
393 break;
394 case LM95241_CHIP_ID:
395 name = "lm95241";
396 break;
397 default:
Jean Delvare52df6442009-12-09 20:35:57 +0100398 return -ENODEV;
Davide Rizzo06160322009-03-31 15:24:27 -0700399 }
400
Jean Delvare797eaa42009-04-07 15:32:59 +0200401 /* Fill the i2c board info */
Jean Delvare797eaa42009-04-07 15:32:59 +0200402 strlcpy(info->type, name, I2C_NAME_SIZE);
403 return 0;
404}
Davide Rizzo06160322009-03-31 15:24:27 -0700405
Guenter Roeckf8096212014-01-20 09:25:50 -0800406static void lm95241_init_client(struct i2c_client *client,
407 struct lm95241_data *data)
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800408{
Guenter Roeckf48ccb22016-07-03 21:46:05 -0700409 data->interval = 1000;
410 data->config = CFG_CR1000;
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800411 data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT);
412
413 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config);
414 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER,
415 R1FE_MASK | R2FE_MASK);
416 i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM,
417 data->trutherm);
418 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL,
419 data->model);
420}
421
Guenter Roeckf8096212014-01-20 09:25:50 -0800422static int lm95241_probe(struct i2c_client *client,
Jean Delvare797eaa42009-04-07 15:32:59 +0200423 const struct i2c_device_id *id)
424{
Guenter Roeckf8096212014-01-20 09:25:50 -0800425 struct device *dev = &client->dev;
Jean Delvare797eaa42009-04-07 15:32:59 +0200426 struct lm95241_data *data;
Guenter Roeckf8096212014-01-20 09:25:50 -0800427 struct device *hwmon_dev;
Jean Delvare797eaa42009-04-07 15:32:59 +0200428
Guenter Roeckf8096212014-01-20 09:25:50 -0800429 data = devm_kzalloc(dev, sizeof(struct lm95241_data), GFP_KERNEL);
Guenter Roeck1487bf72012-06-02 09:58:11 -0700430 if (!data)
431 return -ENOMEM;
Jean Delvare797eaa42009-04-07 15:32:59 +0200432
Guenter Roeckf8096212014-01-20 09:25:50 -0800433 data->client = client;
Davide Rizzo06160322009-03-31 15:24:27 -0700434 mutex_init(&data->update_lock);
435
Davide Rizzo06160322009-03-31 15:24:27 -0700436 /* Initialize the LM95241 chip */
Guenter Roeckf8096212014-01-20 09:25:50 -0800437 lm95241_init_client(client, data);
Davide Rizzo06160322009-03-31 15:24:27 -0700438
Guenter Roeckf8096212014-01-20 09:25:50 -0800439 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
440 data,
441 lm95241_groups);
442 return PTR_ERR_OR_ZERO(hwmon_dev);
Davide Rizzo06160322009-03-31 15:24:27 -0700443}
444
Jean Delvare797eaa42009-04-07 15:32:59 +0200445/* Driver data (common to all clients) */
446static const struct i2c_device_id lm95241_id[] = {
Guenter Roeck8c1d0412011-07-05 13:31:48 -0700447 { "lm95231", 0 },
448 { "lm95241", 0 },
Jean Delvare797eaa42009-04-07 15:32:59 +0200449 { }
450};
451MODULE_DEVICE_TABLE(i2c, lm95241_id);
452
453static struct i2c_driver lm95241_driver = {
454 .class = I2C_CLASS_HWMON,
455 .driver = {
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800456 .name = DEVNAME,
Jean Delvare797eaa42009-04-07 15:32:59 +0200457 },
458 .probe = lm95241_probe,
Jean Delvare797eaa42009-04-07 15:32:59 +0200459 .id_table = lm95241_id,
460 .detect = lm95241_detect,
Jean Delvarec3813d62009-12-14 21:17:25 +0100461 .address_list = normal_i2c,
Jean Delvare797eaa42009-04-07 15:32:59 +0200462};
463
Axel Linf0967ee2012-01-20 15:38:18 +0800464module_i2c_driver(lm95241_driver);
Davide Rizzo06160322009-03-31 15:24:27 -0700465
Davide Rizzo0f1deb42010-11-18 07:23:00 -0800466MODULE_AUTHOR("Davide Rizzo <elpa.rizzo@gmail.com>");
Davide Rizzo06160322009-03-31 15:24:27 -0700467MODULE_DESCRIPTION("LM95241 sensor driver");
468MODULE_LICENSE("GPL");