Blame view

drivers/hwmon/ds1621.c 11.1 KB
74ba9207e   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
  /*
19f2c0596   Guenter Roeck   hwmon: (ds1621) F...
3
4
5
6
7
   * ds1621.c - Part of lm_sensors, Linux kernel modules for hardware
   *	      monitoring
   * Christian W. Zuckschwerdt  <zany@triq.net>  2000-11-23
   * based on lm75.c by Frodo Looijaard <frodol@dds.nl>
   * Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
7c81c60f3   Jean Delvare   Update Jean Delva...
8
   * the help of Jean Delvare <jdelvare@suse.de>
19f2c0596   Guenter Roeck   hwmon: (ds1621) F...
9
   *
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
10
11
12
13
   * The DS1621 device is a digital temperature/thermometer with 9-bit
   * resolution, a thermal alarm output (Tout), and user-defined minimum
   * and maximum temperature thresholds (TH and TL).
   *
260f81ffc   Robert Coulson   hwmon: (ds1621) A...
14
15
   * The DS1625, DS1631, DS1721, and DS1731 are pin compatible with the DS1621
   * and similar in operation, with slight variations as noted in the device
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
16
17
18
19
20
21
   * datasheets (please refer to www.maximintegrated.com for specific
   * device information).
   *
   * Since the DS1621 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.
19f2c0596   Guenter Roeck   hwmon: (ds1621) F...
22
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
26
27
28
  
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/slab.h>
  #include <linux/jiffies.h>
  #include <linux/i2c.h>
943b0830c   Mark M. Hoffman   [PATCH] I2C hwmon...
29
  #include <linux/hwmon.h>
46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
30
  #include <linux/hwmon-sysfs.h>
943b0830c   Mark M. Hoffman   [PATCH] I2C hwmon...
31
  #include <linux/err.h>
9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
32
  #include <linux/mutex.h>
a5ebe668a   Jean Delvare   hwmon: Fix unchec...
33
  #include <linux/sysfs.h>
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
34
  #include <linux/kernel.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35

cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
36
  /* Supported devices */
260f81ffc   Robert Coulson   hwmon: (ds1621) A...
37
  enum chips { ds1621, ds1625, ds1631, ds1721, ds1731 };
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
38

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
  /* Insmod parameters */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
  static int polarity = -1;
  module_param(polarity, int, 0);
  MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low");
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
43
44
45
46
47
48
49
50
51
52
53
  /*
   * The Configuration/Status register
   *
   * - DS1621:
   *   7    6    5    4    3    2    1    0
   * |Done|THF |TLF |NVB | X  | X  |POL |1SHOT|
   *
   * - DS1625:
   *   7    6    5    4    3    2    1    0
   * |Done|THF |TLF |NVB | 1  | 0  |POL |1SHOT|
   *
260f81ffc   Robert Coulson   hwmon: (ds1621) A...
54
   * - DS1631, DS1731:
79c1cc1c9   Robert Coulson   hwmon: (ds1621) A...
55
56
57
   *   7    6    5    4    3    2    1    0
   * |Done|THF |TLF |NVB | R1 | R0 |POL |1SHOT|
   *
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
58
59
60
61
62
63
64
65
   * - DS1721:
   *   7    6    5    4    3    2    1    0
   * |Done| X  | X  | U  | R1 | R0 |POL |1SHOT|
   *
   * Where:
   * - 'X' is Reserved
   * - 'U' is Undefined
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
  #define DS1621_REG_CONFIG_NVB		0x10
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
67
  #define DS1621_REG_CONFIG_RESOL		0x0C
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
69
70
  #define DS1621_REG_CONFIG_POLARITY	0x02
  #define DS1621_REG_CONFIG_1SHOT		0x01
  #define DS1621_REG_CONFIG_DONE		0x80
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  #define DS1621_REG_CONFIG_RESOL_SHIFT	2
  
  /* ds1721 conversion rates: {C/LSB, time(ms), resolution bit setting} */
  static const unsigned short ds1721_convrates[] = {
  	94,	/*  9-bits (0.5,  93.75, RES[0..1] = 0 */
  	188,	/* 10-bits (0.25, 187.5, RES[0..1] = 1 */
  	375,	/* 11-bits (0.125,  375, RES[0..1] = 2 */
  	750,	/* 12-bits (0.0625, 750, RES[0..1] = 3 */
  };
  
  #define DS1621_CONVERSION_MAX	750
  #define DS1625_CONVERSION_MAX	500
  
  #define DS1621_TEMP_MAX	125000
  #define DS1621_TEMP_MIN	(-55000)
  
  /* The DS1621 temperature registers */
46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
88
89
90
91
92
  static const u8 DS1621_REG_TEMP[3] = {
  	0xAA,		/* input, word, RO */
  	0xA2,		/* min, word, RW */
  	0xA1,		/* max, word, RW */
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
94
  #define DS1621_REG_CONF			0xAC /* byte, RW */
  #define DS1621_COM_START		0xEE /* no data */
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
95
  #define DS1721_COM_START		0x51 /* no data */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
98
99
100
  #define DS1621_COM_STOP			0x22 /* no data */
  
  /* The DS1621 configuration register */
  #define DS1621_ALARM_TEMP_HIGH		0x40
  #define DS1621_ALARM_TEMP_LOW		0x20
75819f01a   Jean Delvare   hwmon/ds1621: Min...
101
  /* Conversions */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
  #define ALARMS_FROM_REG(val) ((val) & \
19f2c0596   Guenter Roeck   hwmon: (ds1621) F...
103
  			(DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
106
  
  /* Each client has this additional data */
  struct ds1621_data {
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
107
  	struct i2c_client *client;
9a61bf630   Ingo Molnar   [PATCH] hwmon: Se...
108
  	struct mutex update_lock;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
110
  	char valid;			/* !=0 if following fields are valid */
  	unsigned long last_updated;	/* In jiffies */
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
111
  	enum chips kind;		/* device type */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112

46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
113
  	u16 temp[3];			/* Register values, word */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
  	u8 conf;			/* Register encoding, combined */
a50d9a4d9   Guenter Roeck   hwmon: (ds1621) F...
115
116
  	u8 zbits;			/* Resolution encoded as number of
  					 * zero bits */
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
117
  	u16 update_interval;		/* Conversion rate in milliseconds */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
  };
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
119
120
121
122
123
124
125
126
  static inline int DS1621_TEMP_FROM_REG(u16 reg)
  {
  	return DIV_ROUND_CLOSEST(((s16)reg / 16) * 625, 10);
  }
  
  /*
   * TEMP: 0.001C/bit (-55C to +125C)
   * REG:
a50d9a4d9   Guenter Roeck   hwmon: (ds1621) F...
127
128
   *  - 1621, 1625: 0.5C/bit, 7 zero-bits
   *  - 1631, 1721, 1731: 0.0625C/bit, 4 zero-bits
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
129
   */
a50d9a4d9   Guenter Roeck   hwmon: (ds1621) F...
130
  static inline u16 DS1621_TEMP_TO_REG(long temp, u8 zbits)
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
131
  {
a50d9a4d9   Guenter Roeck   hwmon: (ds1621) F...
132
133
134
  	temp = clamp_val(temp, DS1621_TEMP_MIN, DS1621_TEMP_MAX);
  	temp = DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits;
  	return temp;
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
135
  }
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
136
137
  static void ds1621_init_client(struct ds1621_data *data,
  			       struct i2c_client *client)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
  {
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
139
  	u8 conf, new_conf, sreg, resol;
e4879e28a   Jean Delvare   hwmon: (ds1621) A...
140
141
  
  	new_conf = conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
44bbe87e9   Steven Cole   [PATCH] Spelling ...
142
  	/* switch to continuous conversion mode */
e4879e28a   Jean Delvare   hwmon: (ds1621) A...
143
  	new_conf &= ~DS1621_REG_CONFIG_1SHOT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
144
145
146
  
  	/* setup output polarity */
  	if (polarity == 0)
e4879e28a   Jean Delvare   hwmon: (ds1621) A...
147
  		new_conf &= ~DS1621_REG_CONFIG_POLARITY;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
  	else if (polarity == 1)
e4879e28a   Jean Delvare   hwmon: (ds1621) A...
149
  		new_conf |= DS1621_REG_CONFIG_POLARITY;
19f2c0596   Guenter Roeck   hwmon: (ds1621) F...
150

e4879e28a   Jean Delvare   hwmon: (ds1621) A...
151
152
  	if (conf != new_conf)
  		i2c_smbus_write_byte_data(client, DS1621_REG_CONF, new_conf);
19f2c0596   Guenter Roeck   hwmon: (ds1621) F...
153

cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
154
155
156
  	switch (data->kind) {
  	case ds1625:
  		data->update_interval = DS1625_CONVERSION_MAX;
a50d9a4d9   Guenter Roeck   hwmon: (ds1621) F...
157
  		data->zbits = 7;
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
158
159
  		sreg = DS1621_COM_START;
  		break;
79c1cc1c9   Robert Coulson   hwmon: (ds1621) A...
160
  	case ds1631:
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
161
  	case ds1721:
260f81ffc   Robert Coulson   hwmon: (ds1621) A...
162
  	case ds1731:
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
163
164
165
  		resol = (new_conf & DS1621_REG_CONFIG_RESOL) >>
  			 DS1621_REG_CONFIG_RESOL_SHIFT;
  		data->update_interval = ds1721_convrates[resol];
a50d9a4d9   Guenter Roeck   hwmon: (ds1621) F...
166
  		data->zbits = 7 - resol;
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
167
168
169
170
  		sreg = DS1721_COM_START;
  		break;
  	default:
  		data->update_interval = DS1621_CONVERSION_MAX;
a50d9a4d9   Guenter Roeck   hwmon: (ds1621) F...
171
  		data->zbits = 7;
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
172
173
174
  		sreg = DS1621_COM_START;
  		break;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
  	/* start conversion */
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
176
  	i2c_smbus_write_byte(client, sreg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
  }
9202add67   Jean Delvare   hwmon: (ds1621) R...
178
179
  static struct ds1621_data *ds1621_update_client(struct device *dev)
  {
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
180
181
  	struct ds1621_data *data = dev_get_drvdata(dev);
  	struct i2c_client *client = data->client;
9202add67   Jean Delvare   hwmon: (ds1621) R...
182
183
184
  	u8 new_conf;
  
  	mutex_lock(&data->update_lock);
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
185
186
  	if (time_after(jiffies, data->last_updated + data->update_interval) ||
  	    !data->valid) {
9202add67   Jean Delvare   hwmon: (ds1621) R...
187
188
189
190
  		int i;
  
  		dev_dbg(&client->dev, "Starting ds1621 update
  ");
594592dc6   Jean Delvare   hwmon: (ds1621) C...
191
  		data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
9202add67   Jean Delvare   hwmon: (ds1621) R...
192
193
  
  		for (i = 0; i < ARRAY_SIZE(data->temp); i++)
90f4102ce   Jean Delvare   hwmon: Use i2c_sm...
194
  			data->temp[i] = i2c_smbus_read_word_swapped(client,
594592dc6   Jean Delvare   hwmon: (ds1621) C...
195
  							 DS1621_REG_TEMP[i]);
9202add67   Jean Delvare   hwmon: (ds1621) R...
196
197
198
199
200
201
202
203
  
  		/* reset alarms if necessary */
  		new_conf = data->conf;
  		if (data->temp[0] > data->temp[1])	/* input > min */
  			new_conf &= ~DS1621_ALARM_TEMP_LOW;
  		if (data->temp[0] < data->temp[2])	/* input < max */
  			new_conf &= ~DS1621_ALARM_TEMP_HIGH;
  		if (data->conf != new_conf)
594592dc6   Jean Delvare   hwmon: (ds1621) C...
204
205
  			i2c_smbus_write_byte_data(client, DS1621_REG_CONF,
  						  new_conf);
9202add67   Jean Delvare   hwmon: (ds1621) R...
206
207
208
209
210
211
212
213
214
  
  		data->last_updated = jiffies;
  		data->valid = 1;
  	}
  
  	mutex_unlock(&data->update_lock);
  
  	return data;
  }
0ad85c07a   Guenter Roeck   hwmon: (ds1621) U...
215
  static ssize_t temp_show(struct device *dev, struct device_attribute *da,
46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
216
217
218
219
220
221
  			 char *buf)
  {
  	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
  	struct ds1621_data *data = ds1621_update_client(dev);
  	return sprintf(buf, "%d
  ",
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
222
  		       DS1621_TEMP_FROM_REG(data->temp[attr->index]));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
  }
0ad85c07a   Guenter Roeck   hwmon: (ds1621) U...
224
225
  static ssize_t temp_store(struct device *dev, struct device_attribute *da,
  			  const char *buf, size_t count)
46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
226
227
  {
  	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
228
  	struct ds1621_data *data = dev_get_drvdata(dev);
19f2c0596   Guenter Roeck   hwmon: (ds1621) F...
229
230
231
232
233
234
  	long val;
  	int err;
  
  	err = kstrtol(buf, 10, &val);
  	if (err)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235

46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
236
  	mutex_lock(&data->update_lock);
a50d9a4d9   Guenter Roeck   hwmon: (ds1621) F...
237
  	data->temp[attr->index] = DS1621_TEMP_TO_REG(val, data->zbits);
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
238
  	i2c_smbus_write_word_swapped(data->client, DS1621_REG_TEMP[attr->index],
90f4102ce   Jean Delvare   hwmon: Use i2c_sm...
239
  				     data->temp[attr->index]);
46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
240
241
242
  	mutex_unlock(&data->update_lock);
  	return count;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
243

345d52fa3   Julia Lawall   hwmon: (ds1621) u...
244
  static ssize_t alarms_show(struct device *dev, struct device_attribute *da,
46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
245
  			   char *buf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246
247
248
249
250
  {
  	struct ds1621_data *data = ds1621_update_client(dev);
  	return sprintf(buf, "%d
  ", ALARMS_FROM_REG(data->conf));
  }
0ad85c07a   Guenter Roeck   hwmon: (ds1621) U...
251
  static ssize_t alarm_show(struct device *dev, struct device_attribute *da,
87f0f31ba   Jean Delvare   hwmon/ds1621: Cre...
252
253
254
255
256
257
258
  			  char *buf)
  {
  	struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
  	struct ds1621_data *data = ds1621_update_client(dev);
  	return sprintf(buf, "%d
  ", !!(data->conf & attr->index));
  }
345d52fa3   Julia Lawall   hwmon: (ds1621) u...
259
260
  static ssize_t update_interval_show(struct device *dev,
  				    struct device_attribute *da, char *buf)
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
261
  {
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
262
  	struct ds1621_data *data = dev_get_drvdata(dev);
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
263
264
265
  	return scnprintf(buf, PAGE_SIZE, "%hu
  ", data->update_interval);
  }
345d52fa3   Julia Lawall   hwmon: (ds1621) u...
266
267
268
  static ssize_t update_interval_store(struct device *dev,
  				     struct device_attribute *da,
  				     const char *buf, size_t count)
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
269
  {
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
270
271
  	struct ds1621_data *data = dev_get_drvdata(dev);
  	struct i2c_client *client = data->client;
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
  	unsigned long convrate;
  	s32 err;
  	int resol = 0;
  
  	err = kstrtoul(buf, 10, &convrate);
  	if (err)
  		return err;
  
  	/* Convert rate into resolution bits */
  	while (resol < (ARRAY_SIZE(ds1721_convrates) - 1) &&
  	       convrate > ds1721_convrates[resol])
  		resol++;
  
  	mutex_lock(&data->update_lock);
  	data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
  	data->conf &= ~DS1621_REG_CONFIG_RESOL;
  	data->conf |= (resol << DS1621_REG_CONFIG_RESOL_SHIFT);
  	i2c_smbus_write_byte_data(client, DS1621_REG_CONF, data->conf);
  	data->update_interval = ds1721_convrates[resol];
39c627a08   Robert Coulson   hwmon: (ds1621) U...
291
  	data->zbits = 7 - resol;
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
292
293
294
295
  	mutex_unlock(&data->update_lock);
  
  	return count;
  }
345d52fa3   Julia Lawall   hwmon: (ds1621) u...
296
297
  static DEVICE_ATTR_RO(alarms);
  static DEVICE_ATTR_RW(update_interval);
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
298

0ad85c07a   Guenter Roeck   hwmon: (ds1621) U...
299
300
301
302
303
  static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0);
  static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, 1);
  static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, 2);
  static SENSOR_DEVICE_ATTR_RO(temp1_min_alarm, alarm, DS1621_ALARM_TEMP_LOW);
  static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, DS1621_ALARM_TEMP_HIGH);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304

a5ebe668a   Jean Delvare   hwmon: Fix unchec...
305
  static struct attribute *ds1621_attributes[] = {
46a2e71ce   Jean Delvare   hwmon/ds1621: Use...
306
307
308
  	&sensor_dev_attr_temp1_input.dev_attr.attr,
  	&sensor_dev_attr_temp1_min.dev_attr.attr,
  	&sensor_dev_attr_temp1_max.dev_attr.attr,
87f0f31ba   Jean Delvare   hwmon/ds1621: Cre...
309
310
  	&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
  	&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
a5ebe668a   Jean Delvare   hwmon: Fix unchec...
311
  	&dev_attr_alarms.attr,
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
312
  	&dev_attr_update_interval.attr,
a5ebe668a   Jean Delvare   hwmon: Fix unchec...
313
314
  	NULL
  };
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
315
316
317
318
  static umode_t ds1621_attribute_visible(struct kobject *kobj,
  					struct attribute *attr, int index)
  {
  	struct device *dev = container_of(kobj, struct device, kobj);
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
319
  	struct ds1621_data *data = dev_get_drvdata(dev);
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
320
321
  
  	if (attr == &dev_attr_update_interval.attr)
79c1cc1c9   Robert Coulson   hwmon: (ds1621) A...
322
  		if (data->kind == ds1621 || data->kind == ds1625)
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
323
324
325
326
  			/* shhh, we're hiding update_interval */
  			return 0;
  	return attr->mode;
  }
a5ebe668a   Jean Delvare   hwmon: Fix unchec...
327
328
  static const struct attribute_group ds1621_group = {
  	.attrs = ds1621_attributes,
3a8fe3315   Robert Coulson   hwmon: (ds1621) A...
329
  	.is_visible = ds1621_attribute_visible
a5ebe668a   Jean Delvare   hwmon: Fix unchec...
330
  };
0d36dce0f   Guenter Roeck   hwmon: (ds1621) C...
331
  __ATTRIBUTE_GROUPS(ds1621);
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
332

674870385   Stephen Kitt   hwmon: use simple...
333
334
335
  static const struct i2c_device_id ds1621_id[];
  
  static int ds1621_probe(struct i2c_client *client)
70313eabf   Jean Delvare   hwmon: (ds1621) C...
336
337
  {
  	struct ds1621_data *data;
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
338
  	struct device *hwmon_dev;
70313eabf   Jean Delvare   hwmon: (ds1621) C...
339

e20b4b38c   Guenter Roeck   hwmon: (ds1621) C...
340
341
342
343
  	data = devm_kzalloc(&client->dev, sizeof(struct ds1621_data),
  			    GFP_KERNEL);
  	if (!data)
  		return -ENOMEM;
70313eabf   Jean Delvare   hwmon: (ds1621) C...
344

70313eabf   Jean Delvare   hwmon: (ds1621) C...
345
  	mutex_init(&data->update_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
346

674870385   Stephen Kitt   hwmon: use simple...
347
  	data->kind = i2c_match_id(ds1621_id, client)->driver_data;
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
348
  	data->client = client;
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
349

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350
  	/* Initialize the DS1621 chip */
8269b75ae   Guenter Roeck   hwmon: (ds1621) C...
351
  	ds1621_init_client(data, client);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
352

0d36dce0f   Guenter Roeck   hwmon: (ds1621) C...
353
354
355
  	hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
  							   client->name, data,
  							   ds1621_groups);
31ab1ad70   Fengguang Wu   hwmon: (ds1621) f...
356
  	return PTR_ERR_OR_ZERO(hwmon_dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
357
  }
9202add67   Jean Delvare   hwmon: (ds1621) R...
358
  static const struct i2c_device_id ds1621_id[] = {
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
359
360
  	{ "ds1621", ds1621 },
  	{ "ds1625", ds1625 },
79c1cc1c9   Robert Coulson   hwmon: (ds1621) A...
361
  	{ "ds1631", ds1631 },
cd6c8a429   Robert Coulson   hwmon: (ds1621) A...
362
  	{ "ds1721", ds1721 },
260f81ffc   Robert Coulson   hwmon: (ds1621) A...
363
  	{ "ds1731", ds1731 },
9202add67   Jean Delvare   hwmon: (ds1621) R...
364
365
366
  	{ }
  };
  MODULE_DEVICE_TABLE(i2c, ds1621_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
367

9202add67   Jean Delvare   hwmon: (ds1621) R...
368
369
370
371
372
373
  /* This is the driver that will be inserted */
  static struct i2c_driver ds1621_driver = {
  	.class		= I2C_CLASS_HWMON,
  	.driver = {
  		.name	= "ds1621",
  	},
674870385   Stephen Kitt   hwmon: use simple...
374
  	.probe_new	= ds1621_probe,
9202add67   Jean Delvare   hwmon: (ds1621) R...
375
  	.id_table	= ds1621_id,
9202add67   Jean Delvare   hwmon: (ds1621) R...
376
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
377

f0967eea8   Axel Lin   hwmon: convert dr...
378
  module_i2c_driver(ds1621_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
379
380
381
382
  
  MODULE_AUTHOR("Christian W. Zuckschwerdt <zany@triq.net>");
  MODULE_DESCRIPTION("DS1621 driver");
  MODULE_LICENSE("GPL");