Blame view

drivers/hwmon/lm92.c 12.1 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  /*
   * lm92 - Hardware monitoring driver
7c81c60f3   Jean Delvare   Update Jean Delva...
3
   * Copyright (C) 2005-2008  Jean Delvare <jdelvare@suse.de>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
   *
   * Based on the lm90 driver, with some ideas taken from the lm_sensors
   * lm92 driver as well.
   *
   * The LM92 is a sensor chip made by National Semiconductor. It reports
   * its own temperature with a 0.0625 deg resolution and a 0.33 deg
   * accuracy. Complete datasheet can be obtained from National's website
   * at:
   *   http://www.national.com/pf/LM/LM92.html
   *
   * This driver also supports the MAX6635 sensor chip made by Maxim.
   * This chip is compatible with the LM92, but has a lesser accuracy
   * (1.0 deg). Complete datasheet can be obtained from Maxim's website
   * at:
   *   http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3074
   *
   * Since the LM92 was the first chipset supported by this driver, most
   * comments will refer to this chipset, but are actually general and
   * concern all supported chipsets, unless mentioned otherwise.
   *
   * Support could easily be added for the National Semiconductor LM76
   * and Maxim MAX6633 and MAX6634 chips, which are mostly compatible
   * with the LM92.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
40
41
42
   */
  
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/slab.h>
  #include <linux/i2c.h>
943b0830c   Mark M. Hoffman   [PATCH] I2C hwmon...
43
  #include <linux/hwmon.h>
6cb59e915   Jean Delvare   hwmon: (lm92) Add...
44
  #include <linux/hwmon-sysfs.h>
943b0830c   Mark M. Hoffman   [PATCH] I2C hwmon...
45
  #include <linux/err.h>
9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
46
  #include <linux/mutex.h>
dcd8f3923   Jean Delvare   hwmon: Add missin...
47
  #include <linux/jiffies.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48

a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
49
50
51
52
  /*
   * The LM92 and MAX6635 have 2 two-state pins for address selection,
   * resulting in 4 possible addresses.
   */
25e9c86d5   Mark M. Hoffman   hwmon: normal_i2c...
53
54
  static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
  						I2C_CLIENT_END };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
57
58
59
60
61
62
63
  /* The LM92 registers */
  #define LM92_REG_CONFIG			0x01 /* 8-bit, RW */
  #define LM92_REG_TEMP			0x00 /* 16-bit, RO */
  #define LM92_REG_TEMP_HYST		0x02 /* 16-bit, RW */
  #define LM92_REG_TEMP_CRIT		0x03 /* 16-bit, RW */
  #define LM92_REG_TEMP_LOW		0x04 /* 16-bit, RW */
  #define LM92_REG_TEMP_HIGH		0x05 /* 16-bit, RW */
  #define LM92_REG_MAN_ID			0x07 /* 16-bit, RO, LM92 only */
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
64
65
66
67
68
69
70
  /*
   * The LM92 uses signed 13-bit values with LSB = 0.0625 degree Celsius,
   * left-justified in 16-bit registers. No rounding is done, with such
   * a resolution it's just not worth it. Note that the MAX6635 doesn't
   * make use of the 4 lower bits for limits (i.e. effective resolution
   * for limits is 1 degree Celsius).
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
73
74
  static inline int TEMP_FROM_REG(s16 reg)
  {
  	return reg / 8 * 625 / 10;
  }
5b9630891   Axel Lin   hwmon: (lm92) Pre...
75
  static inline s16 TEMP_TO_REG(long val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  {
5b9630891   Axel Lin   hwmon: (lm92) Pre...
77
  	val = clamp_val(val, -60000, 160000);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
82
83
84
85
  	return val * 10 / 625 * 8;
  }
  
  /* Alarm flags are stored in the 3 LSB of the temperature register */
  static inline u8 ALARMS_FROM_REG(s16 reg)
  {
  	return reg & 0x0007;
  }
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  enum temp_index {
  	t_input,
  	t_crit,
  	t_min,
  	t_max,
  	t_hyst,
  	t_num_regs
  };
  
  static const u8 regs[t_num_regs] = {
  	[t_input] = LM92_REG_TEMP,
  	[t_crit] = LM92_REG_TEMP_CRIT,
  	[t_min] = LM92_REG_TEMP_LOW,
  	[t_max] = LM92_REG_TEMP_HIGH,
  	[t_hyst] = LM92_REG_TEMP_HYST,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
103
  /* Client data (each client gets its own) */
  struct lm92_data {
030004b1e   Guenter Roeck   hwmon: (lm92) Con...
104
  	struct i2c_client *client;
9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
105
  	struct mutex update_lock;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
106
107
108
109
  	char valid; /* zero until following fields are valid */
  	unsigned long last_updated; /* in jiffies */
  
  	/* registers values */
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
110
  	s16 temp[t_num_regs];	/* index with enum temp_index */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
113
114
115
116
117
  /*
   * Sysfs attributes and callback functions
   */
  
  static struct lm92_data *lm92_update_device(struct device *dev)
  {
030004b1e   Guenter Roeck   hwmon: (lm92) Con...
118
119
  	struct lm92_data *data = dev_get_drvdata(dev);
  	struct i2c_client *client = data->client;
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
120
  	int i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121

9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
122
  	mutex_lock(&data->update_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
124
125
126
127
  
  	if (time_after(jiffies, data->last_updated + HZ)
  	 || !data->valid) {
  		dev_dbg(&client->dev, "Updating lm92 data
  ");
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
128
129
130
131
  		for (i = 0; i < t_num_regs; i++) {
  			data->temp[i] =
  				i2c_smbus_read_word_swapped(client, regs[i]);
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
132
133
134
  		data->last_updated = jiffies;
  		data->valid = 1;
  	}
9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
135
  	mutex_unlock(&data->update_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
137
138
  
  	return data;
  }
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
139
140
141
142
143
144
145
146
  static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
  			 char *buf)
  {
  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
  	struct lm92_data *data = lm92_update_device(dev);
  
  	return sprintf(buf, "%d
  ", TEMP_FROM_REG(data->temp[attr->index]));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
147
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148

b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
149
150
  static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
  			   const char *buf, size_t count)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
151
  {
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
152
  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
030004b1e   Guenter Roeck   hwmon: (lm92) Con...
153
154
  	struct lm92_data *data = dev_get_drvdata(dev);
  	struct i2c_client *client = data->client;
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
155
156
157
158
159
160
161
162
163
164
165
166
167
  	int nr = attr->index;
  	long val;
  	int err;
  	
  	err = kstrtol(buf, 10, &val);
  	if (err)
  		return err;
  
  	mutex_lock(&data->update_lock);
  	data->temp[nr] = TEMP_TO_REG(val);
  	i2c_smbus_write_word_swapped(client, regs[nr], data->temp[nr]);
  	mutex_unlock(&data->update_lock);
  	return count;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168
  }
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
169
170
171
  
  static ssize_t show_temp_hyst(struct device *dev,
  			      struct device_attribute *devattr, char *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
172
  {
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
173
  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
174
  	struct lm92_data *data = lm92_update_device(dev);
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
175
176
177
  	return sprintf(buf, "%d
  ", TEMP_FROM_REG(data->temp[attr->index])
  		       - TEMP_FROM_REG(data->temp[t_hyst]));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
  }
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
179
180
181
  
  static ssize_t show_temp_min_hyst(struct device *dev,
  				  struct device_attribute *attr, char *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182
183
  {
  	struct lm92_data *data = lm92_update_device(dev);
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
184
185
186
  	return sprintf(buf, "%d
  ", TEMP_FROM_REG(data->temp[t_min])
  		       + TEMP_FROM_REG(data->temp[t_hyst]));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
  }
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
188
189
190
  static ssize_t set_temp_hyst(struct device *dev,
  			     struct device_attribute *devattr,
  			     const char *buf, size_t count)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
191
  {
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
192
  	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
030004b1e   Guenter Roeck   hwmon: (lm92) Con...
193
194
  	struct lm92_data *data = dev_get_drvdata(dev);
  	struct i2c_client *client = data->client;
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
195
196
197
198
199
200
  	long val;
  	int err;
  
  	err = kstrtol(buf, 10, &val);
  	if (err)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201

5b9630891   Axel Lin   hwmon: (lm92) Pre...
202
  	val = clamp_val(val, -120000, 220000);
9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
203
  	mutex_lock(&data->update_lock);
5b9630891   Axel Lin   hwmon: (lm92) Pre...
204
205
  	 data->temp[t_hyst] =
  		TEMP_TO_REG(TEMP_FROM_REG(data->temp[attr->index]) - val);
90f4102ce   Jean Delvare   hwmon: Use i2c_sm...
206
  	i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST,
5b9630891   Axel Lin   hwmon: (lm92) Pre...
207
  				     data->temp[t_hyst]);
9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
208
  	mutex_unlock(&data->update_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
210
  	return count;
  }
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
211
212
  static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
  			   char *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
213
214
  {
  	struct lm92_data *data = lm92_update_device(dev);
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
215
216
  	return sprintf(buf, "%d
  ", ALARMS_FROM_REG(data->temp[t_input]));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
  }
6cb59e915   Jean Delvare   hwmon: (lm92) Add...
218
219
220
221
222
  static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
  			  char *buf)
  {
  	int bitnr = to_sensor_dev_attr(attr)->index;
  	struct lm92_data *data = lm92_update_device(dev);
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
223
224
  	return sprintf(buf, "%d
  ", (data->temp[t_input] >> bitnr) & 1);
6cb59e915   Jean Delvare   hwmon: (lm92) Add...
225
  }
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
226
227
228
229
230
231
232
233
234
235
236
  static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, t_input);
  static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp, set_temp,
  			  t_crit);
  static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst,
  			  set_temp_hyst, t_crit);
  static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp,
  			  t_min);
  static DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_temp_min_hyst, NULL);
  static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp,
  			  t_max);
  static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp_hyst, NULL, t_max);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
  static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
6cb59e915   Jean Delvare   hwmon: (lm92) Add...
238
239
240
  static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2);
  static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
  static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
243
244
245
246
247
248
249
250
251
252
253
254
255
  /*
   * Detection and registration
   */
  
  static void lm92_init_client(struct i2c_client *client)
  {
  	u8 config;
  
  	/* Start the conversions if needed */
  	config = i2c_smbus_read_byte_data(client, LM92_REG_CONFIG);
  	if (config & 0x01)
  		i2c_smbus_write_byte_data(client, LM92_REG_CONFIG,
  					  config & 0xFE);
  }
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
256
257
258
259
260
261
262
  /*
   * The MAX6635 has no identification register, so we have to use tricks
   * to identify it reliably. This is somewhat slow.
   * Note that we do NOT rely on the 2 MSB of the configuration register
   * always reading 0, as suggested by the datasheet, because it was once
   * reported not to be true.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
263
264
265
266
267
  static int max6635_check(struct i2c_client *client)
  {
  	u16 temp_low, temp_high, temp_hyst, temp_crit;
  	u8 conf;
  	int i;
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
268
269
270
271
  	/*
  	 * No manufacturer ID register, so a read from this address will
  	 * always return the last read value.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272
273
274
275
276
277
  	temp_low = i2c_smbus_read_word_data(client, LM92_REG_TEMP_LOW);
  	if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_low)
  		return 0;
  	temp_high = i2c_smbus_read_word_data(client, LM92_REG_TEMP_HIGH);
  	if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_high)
  		return 0;
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
278

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279
280
281
282
283
284
285
  	/* Limits are stored as integer values (signed, 9-bit). */
  	if ((temp_low & 0x7f00) || (temp_high & 0x7f00))
  		return 0;
  	temp_hyst = i2c_smbus_read_word_data(client, LM92_REG_TEMP_HYST);
  	temp_crit = i2c_smbus_read_word_data(client, LM92_REG_TEMP_CRIT);
  	if ((temp_hyst & 0x7f00) || (temp_crit & 0x7f00))
  		return 0;
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
286
287
288
289
290
291
  	/*
  	 * Registers addresses were found to cycle over 16-byte boundaries.
  	 * We don't test all registers with all offsets so as to save some
  	 * reads and time, but this should still be sufficient to dismiss
  	 * non-MAX6635 chips.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
  	conf = i2c_smbus_read_byte_data(client, LM92_REG_CONFIG);
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
293
  	for (i = 16; i < 96; i *= 2) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
294
  		if (temp_hyst != i2c_smbus_read_word_data(client,
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
295
  				 LM92_REG_TEMP_HYST + i - 16)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296
  		 || temp_crit != i2c_smbus_read_word_data(client,
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
297
  				 LM92_REG_TEMP_CRIT + i)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
300
  		 || temp_low != i2c_smbus_read_word_data(client,
  				LM92_REG_TEMP_LOW + i + 16)
  		 || temp_high != i2c_smbus_read_word_data(client,
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
301
  				 LM92_REG_TEMP_HIGH + i + 32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302
  		 || conf != i2c_smbus_read_byte_data(client,
a318afd89   Guenter Roeck   hwmon: (lm92) Fix...
303
  			    LM92_REG_CONFIG + i))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
305
306
307
308
  			return 0;
  	}
  
  	return 1;
  }
030004b1e   Guenter Roeck   hwmon: (lm92) Con...
309
  static struct attribute *lm92_attrs[] = {
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
310
311
312
313
  	&sensor_dev_attr_temp1_input.dev_attr.attr,
  	&sensor_dev_attr_temp1_crit.dev_attr.attr,
  	&sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
  	&sensor_dev_attr_temp1_min.dev_attr.attr,
0501a3816   Mark M. Hoffman   hwmon: Fix unchec...
314
  	&dev_attr_temp1_min_hyst.attr,
b8fe58e95   Guenter Roeck   hwmon: (lm92) Dro...
315
316
  	&sensor_dev_attr_temp1_max.dev_attr.attr,
  	&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
0501a3816   Mark M. Hoffman   hwmon: Fix unchec...
317
  	&dev_attr_alarms.attr,
6cb59e915   Jean Delvare   hwmon: (lm92) Add...
318
319
320
  	&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
  	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
  	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
0501a3816   Mark M. Hoffman   hwmon: Fix unchec...
321
322
  	NULL
  };
030004b1e   Guenter Roeck   hwmon: (lm92) Con...
323
  ATTRIBUTE_GROUPS(lm92);
0501a3816   Mark M. Hoffman   hwmon: Fix unchec...
324

910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
325
  /* Return 0 if detection is successful, -ENODEV otherwise */
310ec7921   Jean Delvare   i2c: Drop the kin...
326
  static int lm92_detect(struct i2c_client *new_client,
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
327
  		       struct i2c_board_info *info)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
  {
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
329
  	struct i2c_adapter *adapter = new_client->adapter;
52df6440a   Jean Delvare   hwmon: Clean up d...
330
331
  	u8 config;
  	u16 man_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
332
333
334
  
  	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
  					    | I2C_FUNC_SMBUS_WORD_DATA))
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
335
  		return -ENODEV;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336

52df6440a   Jean Delvare   hwmon: Clean up d...
337
338
339
340
341
342
343
344
345
346
347
  	config = i2c_smbus_read_byte_data(new_client, LM92_REG_CONFIG);
  	man_id = i2c_smbus_read_word_data(new_client, LM92_REG_MAN_ID);
  
  	if ((config & 0xe0) == 0x00 && man_id == 0x0180)
  		pr_info("lm92: Found National Semiconductor LM92 chip
  ");
  	else if (max6635_check(new_client))
  		pr_info("lm92: Found Maxim MAX6635 chip
  ");
  	else
  		return -ENODEV;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348

910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
349
350
351
352
353
354
355
356
  	strlcpy(info->type, "lm92", I2C_NAME_SIZE);
  
  	return 0;
  }
  
  static int lm92_probe(struct i2c_client *new_client,
  		      const struct i2c_device_id *id)
  {
030004b1e   Guenter Roeck   hwmon: (lm92) Con...
357
  	struct device *hwmon_dev;
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
358
  	struct lm92_data *data;
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
359

705375cc4   Guenter Roeck   hwmon: (lm92) Con...
360
361
362
363
  	data = devm_kzalloc(&new_client->dev, sizeof(struct lm92_data),
  			    GFP_KERNEL);
  	if (!data)
  		return -ENOMEM;
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
364

030004b1e   Guenter Roeck   hwmon: (lm92) Con...
365
  	data->client = new_client;
9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
366
  	mutex_init(&data->update_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
367

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
369
  	/* Initialize the chipset */
  	lm92_init_client(new_client);
030004b1e   Guenter Roeck   hwmon: (lm92) Con...
370
371
372
373
  	hwmon_dev = devm_hwmon_device_register_with_groups(&new_client->dev,
  							   new_client->name,
  							   data, lm92_groups);
  	return PTR_ERR_OR_ZERO(hwmon_dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
374
375
376
377
378
379
  }
  
  
  /*
   * Module and driver stuff
   */
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
380
  static const struct i2c_device_id lm92_id[] = {
1f86df49d   Jean Delvare   i2c: Drop I2C_CLI...
381
  	{ "lm92", 0 },
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
382
383
384
385
  	/* max6635 could be added here */
  	{ }
  };
  MODULE_DEVICE_TABLE(i2c, lm92_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
  static struct i2c_driver lm92_driver = {
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
387
  	.class		= I2C_CLASS_HWMON,
cdaf79349   Laurent Riffard   [PATCH] i2c: Drop...
388
  	.driver = {
cdaf79349   Laurent Riffard   [PATCH] i2c: Drop...
389
390
  		.name	= "lm92",
  	},
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
391
  	.probe		= lm92_probe,
910e8dcf1   Jean Delvare   hwmon: (lm92) Con...
392
393
  	.id_table	= lm92_id,
  	.detect		= lm92_detect,
c3813d6af   Jean Delvare   i2c: Get rid of s...
394
  	.address_list	= normal_i2c,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
395
  };
f0967eea8   Axel Lin   hwmon: convert dr...
396
  module_i2c_driver(lm92_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397

7c81c60f3   Jean Delvare   Update Jean Delva...
398
  MODULE_AUTHOR("Jean Delvare <jdelvare@suse.de>");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
399
400
  MODULE_DESCRIPTION("LM92/MAX6635 driver");
  MODULE_LICENSE("GPL");