23
23
24
24
#include "lm75.h"
25
25
26
- #define DRV_VERSION "0.3 "
26
+ #define DRV_VERSION "0.4 "
27
27
28
- /* Addresses to scan */
29
- static const unsigned short normal_i2c [] = { 0x28 , I2C_CLIENT_END };
30
- /* Insmod parameters */
31
- I2C_CLIENT_INSMOD_3 (ad7416 , ad7417 , ad7418 );
28
+ enum chips { ad7416 , ad7417 , ad7418 };
32
29
33
30
/* AD7418 registers */
34
31
#define AD7418_REG_TEMP_IN 0x00
@@ -46,7 +43,6 @@ static const u8 AD7418_REG_TEMP[] = { AD7418_REG_TEMP_IN,
46
43
AD7418_REG_TEMP_OS };
47
44
48
45
struct ad7418_data {
49
- struct i2c_client client ;
50
46
struct device * hwmon_dev ;
51
47
struct attribute_group attrs ;
52
48
enum chips type ;
@@ -58,16 +54,25 @@ struct ad7418_data {
58
54
u16 in [4 ];
59
55
};
60
56
61
- static int ad7418_attach_adapter (struct i2c_adapter * adapter );
62
- static int ad7418_detect (struct i2c_adapter * adapter , int address , int kind );
63
- static int ad7418_detach_client (struct i2c_client * client );
57
+ static int ad7418_probe (struct i2c_client * client ,
58
+ const struct i2c_device_id * id );
59
+ static int ad7418_remove (struct i2c_client * client );
60
+
61
+ static const struct i2c_device_id ad7418_id [] = {
62
+ { "ad7416" , ad7416 },
63
+ { "ad7417" , ad7417 },
64
+ { "ad7418" , ad7418 },
65
+ { }
66
+ };
67
+ MODULE_DEVICE_TABLE (i2c , ad7418_id );
64
68
65
69
static struct i2c_driver ad7418_driver = {
66
70
.driver = {
67
71
.name = "ad7418" ,
68
72
},
69
- .attach_adapter = ad7418_attach_adapter ,
70
- .detach_client = ad7418_detach_client ,
73
+ .probe = ad7418_probe ,
74
+ .remove = ad7418_remove ,
75
+ .id_table = ad7418_id ,
71
76
};
72
77
73
78
/* All registers are word-sized, except for the configuration registers.
@@ -192,13 +197,6 @@ static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_adc, NULL, 1);
192
197
static SENSOR_DEVICE_ATTR (in3_input , S_IRUGO , show_adc , NULL, 2 ) ;
193
198
static SENSOR_DEVICE_ATTR (in4_input , S_IRUGO , show_adc , NULL, 3 ) ;
194
199
195
- static int ad7418_attach_adapter (struct i2c_adapter * adapter )
196
- {
197
- if (!(adapter -> class & I2C_CLASS_HWMON ))
198
- return 0 ;
199
- return i2c_probe (adapter , & addr_data , ad7418_detect );
200
- }
201
-
202
200
static struct attribute * ad7416_attributes [] = {
203
201
& sensor_dev_attr_temp1_max .dev_attr .attr ,
204
202
& sensor_dev_attr_temp1_max_hyst .dev_attr .attr ,
@@ -225,106 +223,54 @@ static struct attribute *ad7418_attributes[] = {
225
223
NULL
226
224
};
227
225
228
- static int ad7418_detect (struct i2c_adapter * adapter , int address , int kind )
226
+ static int ad7418_probe (struct i2c_client * client ,
227
+ const struct i2c_device_id * id )
229
228
{
230
- struct i2c_client * client ;
229
+ struct i2c_adapter * adapter = client -> adapter ;
231
230
struct ad7418_data * data ;
232
- int err = 0 ;
231
+ int err ;
233
232
234
233
if (!i2c_check_functionality (adapter , I2C_FUNC_SMBUS_BYTE_DATA |
235
- I2C_FUNC_SMBUS_WORD_DATA ))
234
+ I2C_FUNC_SMBUS_WORD_DATA )) {
235
+ err = - EOPNOTSUPP ;
236
236
goto exit ;
237
+ }
237
238
238
239
if (!(data = kzalloc (sizeof (struct ad7418_data ), GFP_KERNEL ))) {
239
240
err = - ENOMEM ;
240
241
goto exit ;
241
242
}
242
243
243
- client = & data -> client ;
244
- client -> addr = address ;
245
- client -> adapter = adapter ;
246
- client -> driver = & ad7418_driver ;
247
-
248
244
i2c_set_clientdata (client , data );
249
245
250
246
mutex_init (& data -> lock );
251
-
252
- /* AD7418 has a curious behaviour on registers 6 and 7. They
253
- * both always read 0xC071 and are not documented on the datasheet.
254
- * We use them to detect the chip.
255
- */
256
- if (kind <= 0 ) {
257
- int reg , reg6 , reg7 ;
258
-
259
- /* the AD7416 lies within this address range, but I have
260
- * no means to check.
261
- */
262
- if (address >= 0x48 && address <= 0x4f ) {
263
- /* XXX add tests for AD7416 here */
264
- /* data->type = ad7416; */
265
- }
266
- /* here we might have AD7417 or AD7418 */
267
- else if (address >= 0x28 && address <= 0x2f ) {
268
- reg6 = i2c_smbus_read_word_data (client , 0x06 );
269
- reg7 = i2c_smbus_read_word_data (client , 0x07 );
270
-
271
- if (address == 0x28 && reg6 == 0xC071 && reg7 == 0xC071 )
272
- data -> type = ad7418 ;
273
-
274
- /* XXX add tests for AD7417 here */
275
-
276
-
277
- /* both AD7417 and AD7418 have bits 0-5 of
278
- * the CONF2 register at 0
279
- */
280
- reg = i2c_smbus_read_byte_data (client ,
281
- AD7418_REG_CONF2 );
282
- if (reg & 0x3F )
283
- data -> type = any_chip ; /* detection failed */
284
- }
285
- } else {
286
- dev_dbg (& adapter -> dev , "detection forced\n" );
287
- }
288
-
289
- if (kind > 0 )
290
- data -> type = kind ;
291
- else if (kind < 0 && data -> type == any_chip ) {
292
- err = - ENODEV ;
293
- goto exit_free ;
294
- }
247
+ data -> type = id -> driver_data ;
295
248
296
249
switch (data -> type ) {
297
- case any_chip :
298
250
case ad7416 :
299
251
data -> adc_max = 0 ;
300
252
data -> attrs .attrs = ad7416_attributes ;
301
- strlcpy (client -> name , "ad7416" , I2C_NAME_SIZE );
302
253
break ;
303
254
304
255
case ad7417 :
305
256
data -> adc_max = 4 ;
306
257
data -> attrs .attrs = ad7417_attributes ;
307
- strlcpy (client -> name , "ad7417" , I2C_NAME_SIZE );
308
258
break ;
309
259
310
260
case ad7418 :
311
261
data -> adc_max = 1 ;
312
262
data -> attrs .attrs = ad7418_attributes ;
313
- strlcpy (client -> name , "ad7418" , I2C_NAME_SIZE );
314
263
break ;
315
264
}
316
265
317
- if ((err = i2c_attach_client (client )))
318
- goto exit_free ;
319
-
320
266
dev_info (& client -> dev , "%s chip found\n" , client -> name );
321
267
322
268
/* Initialize the AD7418 chip */
323
269
ad7418_init_client (client );
324
270
325
271
/* Register sysfs hooks */
326
272
if ((err = sysfs_create_group (& client -> dev .kobj , & data -> attrs )))
327
- goto exit_detach ;
273
+ goto exit_free ;
328
274
329
275
data -> hwmon_dev = hwmon_device_register (& client -> dev );
330
276
if (IS_ERR (data -> hwmon_dev )) {
@@ -336,20 +282,17 @@ static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind)
336
282
337
283
exit_remove :
338
284
sysfs_remove_group (& client -> dev .kobj , & data -> attrs );
339
- exit_detach :
340
- i2c_detach_client (client );
341
285
exit_free :
342
286
kfree (data );
343
287
exit :
344
288
return err ;
345
289
}
346
290
347
- static int ad7418_detach_client (struct i2c_client * client )
291
+ static int ad7418_remove (struct i2c_client * client )
348
292
{
349
293
struct ad7418_data * data = i2c_get_clientdata (client );
350
294
hwmon_device_unregister (data -> hwmon_dev );
351
295
sysfs_remove_group (& client -> dev .kobj , & data -> attrs );
352
- i2c_detach_client (client );
353
296
kfree (data );
354
297
return 0 ;
355
298
}
0 commit comments