All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: temperature: tmp007: use device-managed functions in probe
@ 2021-03-10  9:38 Alexandru Ardelean
  2021-03-13 18:49 ` Jonathan Cameron
  2021-03-15  4:23 ` Manivannan Sadhasivam
  0 siblings, 2 replies; 3+ messages in thread
From: Alexandru Ardelean @ 2021-03-10  9:38 UTC (permalink / raw)
  To: linux-kernel, linux-iio; +Cc: jic23, manivannanece23, linux, Alexandru Ardelean

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>
---
 drivers/iio/temperature/tmp007.c | 36 +++++++++++++-------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/drivers/iio/temperature/tmp007.c b/drivers/iio/temperature/tmp007.c
index ad2b35c65548..b422371a4674 100644
--- a/drivers/iio/temperature/tmp007.c
+++ b/drivers/iio/temperature/tmp007.c
@@ -439,6 +439,13 @@ static bool tmp007_identify(struct i2c_client *client)
 	return (manf_id == TMP007_MANUFACTURER_MAGIC && dev_id == TMP007_DEVICE_MAGIC);
 }
 
+static void tmp007_powerdown_action_cb(void *priv)
+{
+	struct tmp007_data *data = priv;
+
+	tmp007_powerdown(data);
+}
+
 static int tmp007_probe(struct i2c_client *client,
 			const struct i2c_device_id *tmp007_id)
 {
@@ -489,6 +496,10 @@ static int tmp007_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
+	ret = devm_add_action_or_reset(&client->dev, tmp007_powerdown_action_cb, data);
+	if (ret)
+		return ret;
+
 	/*
 	 * Only the following flags can activate ALERT pin. Data conversion/validity flags
 	 * flags can still be polled for getting temperature data
@@ -502,7 +513,7 @@ static int tmp007_probe(struct i2c_client *client,
 
 	ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK);
 	if (ret < 0)
-		goto error_powerdown;
+		return ret;
 
 	data->status_mask = ret;
 	data->status_mask |= (TMP007_STATUS_OHF | TMP007_STATUS_OLF
@@ -510,7 +521,7 @@ static int tmp007_probe(struct i2c_client *client,
 
 	ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, data->status_mask);
 	if (ret < 0)
-		goto error_powerdown;
+		return ret;
 
 	if (client->irq) {
 		ret = devm_request_threaded_irq(&client->dev, client->irq,
@@ -519,27 +530,11 @@ static int tmp007_probe(struct i2c_client *client,
 				tmp007_id->name, indio_dev);
 		if (ret) {
 			dev_err(&client->dev, "irq request error %d\n", -ret);
-			goto error_powerdown;
+			return ret;
 		}
 	}
 
-	return iio_device_register(indio_dev);
-
-error_powerdown:
-	tmp007_powerdown(data);
-
-	return ret;
-}
-
-static int tmp007_remove(struct i2c_client *client)
-{
-	struct iio_dev *indio_dev = i2c_get_clientdata(client);
-	struct tmp007_data *data = iio_priv(indio_dev);
-
-	iio_device_unregister(indio_dev);
-	tmp007_powerdown(data);
-
-	return 0;
+	return devm_iio_device_register(&client->dev, indio_dev);
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -582,7 +577,6 @@ static struct i2c_driver tmp007_driver = {
 		.pm	= &tmp007_pm_ops,
 	},
 	.probe		= tmp007_probe,
-	.remove		= tmp007_remove,
 	.id_table	= tmp007_id,
 };
 module_i2c_driver(tmp007_driver);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: temperature: tmp007: use device-managed functions in probe
  2021-03-10  9:38 [PATCH] iio: temperature: tmp007: use device-managed functions in probe Alexandru Ardelean
@ 2021-03-13 18:49 ` Jonathan Cameron
  2021-03-15  4:23 ` Manivannan Sadhasivam
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2021-03-13 18:49 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-kernel, linux-iio, manivannanece23, linux

On Wed, 10 Mar 2021 11:38:00 +0200
Alexandru Ardelean <aardelean@deviqon.com> wrote:

> 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.
I'm not sure it makes sense in all cases!  However this particular one
is clear cut.

Applied to the togreg branch of iio.git and pushed out as testing.
Manivannan, I won't be pushing this out as a non rebasing tree for
a few days if you want to take a look.

thanks,

Jonathan

> 
> Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
> ---
>  drivers/iio/temperature/tmp007.c | 36 +++++++++++++-------------------
>  1 file changed, 15 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/iio/temperature/tmp007.c b/drivers/iio/temperature/tmp007.c
> index ad2b35c65548..b422371a4674 100644
> --- a/drivers/iio/temperature/tmp007.c
> +++ b/drivers/iio/temperature/tmp007.c
> @@ -439,6 +439,13 @@ static bool tmp007_identify(struct i2c_client *client)
>  	return (manf_id == TMP007_MANUFACTURER_MAGIC && dev_id == TMP007_DEVICE_MAGIC);
>  }
>  
> +static void tmp007_powerdown_action_cb(void *priv)
> +{
> +	struct tmp007_data *data = priv;
> +
> +	tmp007_powerdown(data);
> +}
> +
>  static int tmp007_probe(struct i2c_client *client,
>  			const struct i2c_device_id *tmp007_id)
>  {
> @@ -489,6 +496,10 @@ static int tmp007_probe(struct i2c_client *client,
>  	if (ret < 0)
>  		return ret;
>  
> +	ret = devm_add_action_or_reset(&client->dev, tmp007_powerdown_action_cb, data);
> +	if (ret)
> +		return ret;
> +
>  	/*
>  	 * Only the following flags can activate ALERT pin. Data conversion/validity flags
>  	 * flags can still be polled for getting temperature data
> @@ -502,7 +513,7 @@ static int tmp007_probe(struct i2c_client *client,
>  
>  	ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK);
>  	if (ret < 0)
> -		goto error_powerdown;
> +		return ret;
>  
>  	data->status_mask = ret;
>  	data->status_mask |= (TMP007_STATUS_OHF | TMP007_STATUS_OLF
> @@ -510,7 +521,7 @@ static int tmp007_probe(struct i2c_client *client,
>  
>  	ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, data->status_mask);
>  	if (ret < 0)
> -		goto error_powerdown;
> +		return ret;
>  
>  	if (client->irq) {
>  		ret = devm_request_threaded_irq(&client->dev, client->irq,
> @@ -519,27 +530,11 @@ static int tmp007_probe(struct i2c_client *client,
>  				tmp007_id->name, indio_dev);
>  		if (ret) {
>  			dev_err(&client->dev, "irq request error %d\n", -ret);
> -			goto error_powerdown;
> +			return ret;
>  		}
>  	}
>  
> -	return iio_device_register(indio_dev);
> -
> -error_powerdown:
> -	tmp007_powerdown(data);
> -
> -	return ret;
> -}
> -
> -static int tmp007_remove(struct i2c_client *client)
> -{
> -	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> -	struct tmp007_data *data = iio_priv(indio_dev);
> -
> -	iio_device_unregister(indio_dev);
> -	tmp007_powerdown(data);
> -
> -	return 0;
> +	return devm_iio_device_register(&client->dev, indio_dev);
>  }
>  
>  #ifdef CONFIG_PM_SLEEP
> @@ -582,7 +577,6 @@ static struct i2c_driver tmp007_driver = {
>  		.pm	= &tmp007_pm_ops,
>  	},
>  	.probe		= tmp007_probe,
> -	.remove		= tmp007_remove,
>  	.id_table	= tmp007_id,
>  };
>  module_i2c_driver(tmp007_driver);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: temperature: tmp007: use device-managed functions in probe
  2021-03-10  9:38 [PATCH] iio: temperature: tmp007: use device-managed functions in probe Alexandru Ardelean
  2021-03-13 18:49 ` Jonathan Cameron
@ 2021-03-15  4:23 ` Manivannan Sadhasivam
  1 sibling, 0 replies; 3+ messages in thread
From: Manivannan Sadhasivam @ 2021-03-15  4:23 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-kernel, linux-iio, jic23, linux

On Wed, Mar 10, 2021 at 11:38:00AM +0200, Alexandru Ardelean wrote:
> 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>

Reviewed-by: Manivannan Sadhasivam <manivannanece23@gmail.com>

Thanks,
Mani

> ---
>  drivers/iio/temperature/tmp007.c | 36 +++++++++++++-------------------
>  1 file changed, 15 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/iio/temperature/tmp007.c b/drivers/iio/temperature/tmp007.c
> index ad2b35c65548..b422371a4674 100644
> --- a/drivers/iio/temperature/tmp007.c
> +++ b/drivers/iio/temperature/tmp007.c
> @@ -439,6 +439,13 @@ static bool tmp007_identify(struct i2c_client *client)
>  	return (manf_id == TMP007_MANUFACTURER_MAGIC && dev_id == TMP007_DEVICE_MAGIC);
>  }
>  
> +static void tmp007_powerdown_action_cb(void *priv)
> +{
> +	struct tmp007_data *data = priv;
> +
> +	tmp007_powerdown(data);
> +}
> +
>  static int tmp007_probe(struct i2c_client *client,
>  			const struct i2c_device_id *tmp007_id)
>  {
> @@ -489,6 +496,10 @@ static int tmp007_probe(struct i2c_client *client,
>  	if (ret < 0)
>  		return ret;
>  
> +	ret = devm_add_action_or_reset(&client->dev, tmp007_powerdown_action_cb, data);
> +	if (ret)
> +		return ret;
> +
>  	/*
>  	 * Only the following flags can activate ALERT pin. Data conversion/validity flags
>  	 * flags can still be polled for getting temperature data
> @@ -502,7 +513,7 @@ static int tmp007_probe(struct i2c_client *client,
>  
>  	ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK);
>  	if (ret < 0)
> -		goto error_powerdown;
> +		return ret;
>  
>  	data->status_mask = ret;
>  	data->status_mask |= (TMP007_STATUS_OHF | TMP007_STATUS_OLF
> @@ -510,7 +521,7 @@ static int tmp007_probe(struct i2c_client *client,
>  
>  	ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, data->status_mask);
>  	if (ret < 0)
> -		goto error_powerdown;
> +		return ret;
>  
>  	if (client->irq) {
>  		ret = devm_request_threaded_irq(&client->dev, client->irq,
> @@ -519,27 +530,11 @@ static int tmp007_probe(struct i2c_client *client,
>  				tmp007_id->name, indio_dev);
>  		if (ret) {
>  			dev_err(&client->dev, "irq request error %d\n", -ret);
> -			goto error_powerdown;
> +			return ret;
>  		}
>  	}
>  
> -	return iio_device_register(indio_dev);
> -
> -error_powerdown:
> -	tmp007_powerdown(data);
> -
> -	return ret;
> -}
> -
> -static int tmp007_remove(struct i2c_client *client)
> -{
> -	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> -	struct tmp007_data *data = iio_priv(indio_dev);
> -
> -	iio_device_unregister(indio_dev);
> -	tmp007_powerdown(data);
> -
> -	return 0;
> +	return devm_iio_device_register(&client->dev, indio_dev);
>  }
>  
>  #ifdef CONFIG_PM_SLEEP
> @@ -582,7 +577,6 @@ static struct i2c_driver tmp007_driver = {
>  		.pm	= &tmp007_pm_ops,
>  	},
>  	.probe		= tmp007_probe,
> -	.remove		= tmp007_remove,
>  	.id_table	= tmp007_id,
>  };
>  module_i2c_driver(tmp007_driver);
> -- 
> 2.29.2
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-15  4:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10  9:38 [PATCH] iio: temperature: tmp007: use device-managed functions in probe Alexandru Ardelean
2021-03-13 18:49 ` Jonathan Cameron
2021-03-15  4:23 ` Manivannan Sadhasivam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.