Skip to content

Commit 70da641

Browse files
commodojic23
authored andcommitted
iio: temperature: tmp007: use device-managed functions in probe
This change converts the driver to use device-managed functions in the probe function. The power-down call is handled now via a devm_add_action_or_reset() hook, and then devm_iio_device_register() can be used to register the IIO device. The final aim here would be for IIO to export only the device-managed functions of it's API. That's a long way to go and this a small step in that direction. Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com> Link: https://lore.kernel.org/r/20210310093800.45822-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 218bc53 commit 70da641

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

drivers/iio/temperature/tmp007.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ static bool tmp007_identify(struct i2c_client *client)
439439
return (manf_id == TMP007_MANUFACTURER_MAGIC && dev_id == TMP007_DEVICE_MAGIC);
440440
}
441441

442+
static void tmp007_powerdown_action_cb(void *priv)
443+
{
444+
struct tmp007_data *data = priv;
445+
446+
tmp007_powerdown(data);
447+
}
448+
442449
static int tmp007_probe(struct i2c_client *client,
443450
const struct i2c_device_id *tmp007_id)
444451
{
@@ -489,6 +496,10 @@ static int tmp007_probe(struct i2c_client *client,
489496
if (ret < 0)
490497
return ret;
491498

499+
ret = devm_add_action_or_reset(&client->dev, tmp007_powerdown_action_cb, data);
500+
if (ret)
501+
return ret;
502+
492503
/*
493504
* Only the following flags can activate ALERT pin. Data conversion/validity flags
494505
* flags can still be polled for getting temperature data
@@ -502,15 +513,15 @@ static int tmp007_probe(struct i2c_client *client,
502513

503514
ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK);
504515
if (ret < 0)
505-
goto error_powerdown;
516+
return ret;
506517

507518
data->status_mask = ret;
508519
data->status_mask |= (TMP007_STATUS_OHF | TMP007_STATUS_OLF
509520
| TMP007_STATUS_LHF | TMP007_STATUS_LLF);
510521

511522
ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, data->status_mask);
512523
if (ret < 0)
513-
goto error_powerdown;
524+
return ret;
514525

515526
if (client->irq) {
516527
ret = devm_request_threaded_irq(&client->dev, client->irq,
@@ -519,27 +530,11 @@ static int tmp007_probe(struct i2c_client *client,
519530
tmp007_id->name, indio_dev);
520531
if (ret) {
521532
dev_err(&client->dev, "irq request error %d\n", -ret);
522-
goto error_powerdown;
533+
return ret;
523534
}
524535
}
525536

526-
return iio_device_register(indio_dev);
527-
528-
error_powerdown:
529-
tmp007_powerdown(data);
530-
531-
return ret;
532-
}
533-
534-
static int tmp007_remove(struct i2c_client *client)
535-
{
536-
struct iio_dev *indio_dev = i2c_get_clientdata(client);
537-
struct tmp007_data *data = iio_priv(indio_dev);
538-
539-
iio_device_unregister(indio_dev);
540-
tmp007_powerdown(data);
541-
542-
return 0;
537+
return devm_iio_device_register(&client->dev, indio_dev);
543538
}
544539

545540
#ifdef CONFIG_PM_SLEEP
@@ -582,7 +577,6 @@ static struct i2c_driver tmp007_driver = {
582577
.pm = &tmp007_pm_ops,
583578
},
584579
.probe = tmp007_probe,
585-
.remove = tmp007_remove,
586580
.id_table = tmp007_id,
587581
};
588582
module_i2c_driver(tmp007_driver);

0 commit comments

Comments
 (0)