Skip to content

Commit 8ff69ee

Browse files
Jean DelvareJean Delvare
authored andcommitted
hwmon: (lm75) Drop legacy i2c driver
Drop the legacy lm75 driver, and add a detect callback to the new-style driver to achieve the same functionality. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: David Brownell <david-b@pacbell.net>
1 parent 2ce5b34 commit 8ff69ee

File tree

1 file changed

+22
-92
lines changed

1 file changed

+22
-92
lines changed

drivers/hwmon/lm75.c

Lines changed: 22 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ enum lm75_type { /* keep sorted in alphabetical order */
5454
tmp75,
5555
};
5656

57-
/* Addresses scanned by legacy style driver binding */
57+
/* Addresses scanned */
5858
static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
5959
0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
6060

61-
/* Insmod parameters (only for legacy style driver binding) */
61+
/* Insmod parameters */
6262
I2C_CLIENT_INSMOD_1(lm75);
6363

6464

@@ -72,7 +72,6 @@ static const u8 LM75_REG_TEMP[3] = {
7272

7373
/* Each client has this additional data */
7474
struct lm75_data {
75-
struct i2c_client *client;
7675
struct device *hwmon_dev;
7776
struct mutex update_lock;
7877
u8 orig_conf;
@@ -138,7 +137,7 @@ static const struct attribute_group lm75_group = {
138137

139138
/*-----------------------------------------------------------------------*/
140139

141-
/* "New style" I2C driver binding -- following the driver model */
140+
/* device probe and removal */
142141

143142
static int
144143
lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
@@ -157,8 +156,6 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
157156
return -ENOMEM;
158157

159158
i2c_set_clientdata(client, data);
160-
161-
data->client = client;
162159
mutex_init(&data->update_lock);
163160

164161
/* Set to LM75 resolution (9 bits, 1/2 degree C) and range.
@@ -236,45 +233,16 @@ static const struct i2c_device_id lm75_ids[] = {
236233
};
237234
MODULE_DEVICE_TABLE(i2c, lm75_ids);
238235

239-
static struct i2c_driver lm75_driver = {
240-
.driver = {
241-
.name = "lm75",
242-
},
243-
.probe = lm75_probe,
244-
.remove = lm75_remove,
245-
.id_table = lm75_ids,
246-
};
247-
248-
/*-----------------------------------------------------------------------*/
249-
250-
/* "Legacy" I2C driver binding */
251-
252-
static struct i2c_driver lm75_legacy_driver;
253-
254-
/* This function is called by i2c_probe */
255-
static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
236+
/* Return 0 if detection is successful, -ENODEV otherwise */
237+
static int lm75_detect(struct i2c_client *new_client, int kind,
238+
struct i2c_board_info *info)
256239
{
240+
struct i2c_adapter *adapter = new_client->adapter;
257241
int i;
258-
struct i2c_client *new_client;
259-
int err = 0;
260242

261243
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
262244
I2C_FUNC_SMBUS_WORD_DATA))
263-
goto exit;
264-
265-
/* OK. For now, we presume we have a valid address. We create the
266-
client structure, even though there may be no sensor present.
267-
But it allows us to use i2c_smbus_read_*_data() calls. */
268-
new_client = kzalloc(sizeof *new_client, GFP_KERNEL);
269-
if (!new_client) {
270-
err = -ENOMEM;
271-
goto exit;
272-
}
273-
274-
new_client->addr = address;
275-
new_client->adapter = adapter;
276-
new_client->driver = &lm75_legacy_driver;
277-
new_client->flags = 0;
245+
return -ENODEV;
278246

279247
/* Now, we do the remaining detection. There is no identification-
280248
dedicated register so we have to rely on several tricks:
@@ -294,71 +262,44 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
294262
|| i2c_smbus_read_word_data(new_client, 5) != hyst
295263
|| i2c_smbus_read_word_data(new_client, 6) != hyst
296264
|| i2c_smbus_read_word_data(new_client, 7) != hyst)
297-
goto exit_free;
265+
return -ENODEV;
298266
os = i2c_smbus_read_word_data(new_client, 3);
299267
if (i2c_smbus_read_word_data(new_client, 4) != os
300268
|| i2c_smbus_read_word_data(new_client, 5) != os
301269
|| i2c_smbus_read_word_data(new_client, 6) != os
302270
|| i2c_smbus_read_word_data(new_client, 7) != os)
303-
goto exit_free;
271+
return -ENODEV;
304272

305273
/* Unused bits */
306274
if (conf & 0xe0)
307-
goto exit_free;
275+
return -ENODEV;
308276

309277
/* Addresses cycling */
310278
for (i = 8; i < 0xff; i += 8)
311279
if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
312280
|| i2c_smbus_read_word_data(new_client, i + 2) != hyst
313281
|| i2c_smbus_read_word_data(new_client, i + 3) != os)
314-
goto exit_free;
282+
return -ENODEV;
315283
}
316284

317285
/* NOTE: we treat "force=..." and "force_lm75=..." the same.
318286
* Only new-style driver binding distinguishes chip types.
319287
*/
320-
strlcpy(new_client->name, "lm75", I2C_NAME_SIZE);
321-
322-
/* Tell the I2C layer a new client has arrived */
323-
err = i2c_attach_client(new_client);
324-
if (err)
325-
goto exit_free;
326-
327-
err = lm75_probe(new_client, NULL);
328-
if (err < 0)
329-
goto exit_detach;
288+
strlcpy(info->type, "lm75", I2C_NAME_SIZE);
330289

331290
return 0;
332-
333-
exit_detach:
334-
i2c_detach_client(new_client);
335-
exit_free:
336-
kfree(new_client);
337-
exit:
338-
return err;
339-
}
340-
341-
static int lm75_attach_adapter(struct i2c_adapter *adapter)
342-
{
343-
if (!(adapter->class & I2C_CLASS_HWMON))
344-
return 0;
345-
return i2c_probe(adapter, &addr_data, lm75_detect);
346291
}
347292

348-
static int lm75_detach_client(struct i2c_client *client)
349-
{
350-
lm75_remove(client);
351-
i2c_detach_client(client);
352-
kfree(client);
353-
return 0;
354-
}
355-
356-
static struct i2c_driver lm75_legacy_driver = {
293+
static struct i2c_driver lm75_driver = {
294+
.class = I2C_CLASS_HWMON,
357295
.driver = {
358-
.name = "lm75_legacy",
296+
.name = "lm75",
359297
},
360-
.attach_adapter = lm75_attach_adapter,
361-
.detach_client = lm75_detach_client,
298+
.probe = lm75_probe,
299+
.remove = lm75_remove,
300+
.id_table = lm75_ids,
301+
.detect = lm75_detect,
302+
.address_data = &addr_data,
362303
};
363304

364305
/*-----------------------------------------------------------------------*/
@@ -424,22 +365,11 @@ static struct lm75_data *lm75_update_device(struct device *dev)
424365

425366
static int __init sensors_lm75_init(void)
426367
{
427-
int status;
428-
429-
status = i2c_add_driver(&lm75_driver);
430-
if (status < 0)
431-
return status;
432-
433-
status = i2c_add_driver(&lm75_legacy_driver);
434-
if (status < 0)
435-
i2c_del_driver(&lm75_driver);
436-
437-
return status;
368+
return i2c_add_driver(&lm75_driver);
438369
}
439370

440371
static void __exit sensors_lm75_exit(void)
441372
{
442-
i2c_del_driver(&lm75_legacy_driver);
443373
i2c_del_driver(&lm75_driver);
444374
}
445375

0 commit comments

Comments
 (0)