diff mbox series

[v2,06/11] iio:accel: device settings are set immediately during probe

Message ID 20190718225353.2078-7-denis.ciocca@st.com (mailing list archive)
State New, archived
Headers show
Series iio:st_sensors: make use of regmap API | expand

Commit Message

Denis CIOCCA July 18, 2019, 10:53 p.m. UTC
This patch set accel settings right after probe start. This is
done in preparation of regmap that needs different configuration
based on multiread bit value.

Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
---
Changes in v2:
 not there in v1.

 drivers/iio/accel/st_accel_i2c.c | 19 ++++++++++++++-----
 drivers/iio/accel/st_accel_spi.c | 16 +++++++++++++---
 2 files changed, 27 insertions(+), 8 deletions(-)

Comments

Jonathan Cameron July 21, 2019, 5:54 p.m. UTC | #1
On Thu, 18 Jul 2019 15:53:48 -0700
Denis Ciocca <denis.ciocca@st.com> wrote:

> This patch set accel settings right after probe start. This is
> done in preparation of regmap that needs different configuration
> based on multiread bit value.
> 
> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
Applied,

Thanks,

Jonathan

> ---
> Changes in v2:
>  not there in v1.
> 
>  drivers/iio/accel/st_accel_i2c.c | 19 ++++++++++++++-----
>  drivers/iio/accel/st_accel_spi.c | 16 +++++++++++++---
>  2 files changed, 27 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
> index c3c8f2e73c2a..a92cf776031e 100644
> --- a/drivers/iio/accel/st_accel_i2c.c
> +++ b/drivers/iio/accel/st_accel_i2c.c
> @@ -150,20 +150,29 @@ MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
>  
>  static int st_accel_i2c_probe(struct i2c_client *client)
>  {
> -	struct iio_dev *indio_dev;
> +	const struct st_sensor_settings *settings;
>  	struct st_sensor_data *adata;
> +	struct iio_dev *indio_dev;
>  	const char *match;
>  	int ret;
>  
> +	match = device_get_match_data(&client->dev);
> +	if (match)
> +		strlcpy(client->name, match, sizeof(client->name));
> +
> +	settings = st_accel_get_settings(client->name);
> +	if (!settings) {
> +		dev_err(&client->dev, "device name %s not recognized.\n",
> +			client->name);
> +		return -ENODEV;
> +	}
> +
>  	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
>  	if (!indio_dev)
>  		return -ENOMEM;
>  
>  	adata = iio_priv(indio_dev);
> -
> -	match = device_get_match_data(&client->dev);
> -	if (match)
> -		strlcpy(client->name, match, sizeof(client->name));
> +	adata->sensor_settings = (struct st_sensor_settings *)settings;
>  
>  	st_sensors_i2c_configure(indio_dev, client, adata);
>  
> diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
> index 474742e35d92..c0556db9d60a 100644
> --- a/drivers/iio/accel/st_accel_spi.c
> +++ b/drivers/iio/accel/st_accel_spi.c
> @@ -102,18 +102,28 @@ MODULE_DEVICE_TABLE(of, st_accel_of_match);
>  
>  static int st_accel_spi_probe(struct spi_device *spi)
>  {
> -	struct iio_dev *indio_dev;
> +	const struct st_sensor_settings *settings;
>  	struct st_sensor_data *adata;
> +	struct iio_dev *indio_dev;
>  	int err;
>  
> +	st_sensors_of_name_probe(&spi->dev, st_accel_of_match,
> +				 spi->modalias, sizeof(spi->modalias));
> +
> +	settings = st_accel_get_settings(spi->modalias);
> +	if (!settings) {
> +		dev_err(&spi->dev, "device name %s not recognized.\n",
> +			spi->modalias);
> +		return -ENODEV;
> +	}
> +
>  	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adata));
>  	if (!indio_dev)
>  		return -ENOMEM;
>  
>  	adata = iio_priv(indio_dev);
> +	adata->sensor_settings = (struct st_sensor_settings *)settings;
>  
> -	st_sensors_of_name_probe(&spi->dev, st_accel_of_match,
> -				 spi->modalias, sizeof(spi->modalias));
>  	st_sensors_spi_configure(indio_dev, spi, adata);
>  
>  	err = st_accel_common_probe(indio_dev);
diff mbox series

Patch

diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index c3c8f2e73c2a..a92cf776031e 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -150,20 +150,29 @@  MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
 
 static int st_accel_i2c_probe(struct i2c_client *client)
 {
-	struct iio_dev *indio_dev;
+	const struct st_sensor_settings *settings;
 	struct st_sensor_data *adata;
+	struct iio_dev *indio_dev;
 	const char *match;
 	int ret;
 
+	match = device_get_match_data(&client->dev);
+	if (match)
+		strlcpy(client->name, match, sizeof(client->name));
+
+	settings = st_accel_get_settings(client->name);
+	if (!settings) {
+		dev_err(&client->dev, "device name %s not recognized.\n",
+			client->name);
+		return -ENODEV;
+	}
+
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
 	if (!indio_dev)
 		return -ENOMEM;
 
 	adata = iio_priv(indio_dev);
-
-	match = device_get_match_data(&client->dev);
-	if (match)
-		strlcpy(client->name, match, sizeof(client->name));
+	adata->sensor_settings = (struct st_sensor_settings *)settings;
 
 	st_sensors_i2c_configure(indio_dev, client, adata);
 
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index 474742e35d92..c0556db9d60a 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -102,18 +102,28 @@  MODULE_DEVICE_TABLE(of, st_accel_of_match);
 
 static int st_accel_spi_probe(struct spi_device *spi)
 {
-	struct iio_dev *indio_dev;
+	const struct st_sensor_settings *settings;
 	struct st_sensor_data *adata;
+	struct iio_dev *indio_dev;
 	int err;
 
+	st_sensors_of_name_probe(&spi->dev, st_accel_of_match,
+				 spi->modalias, sizeof(spi->modalias));
+
+	settings = st_accel_get_settings(spi->modalias);
+	if (!settings) {
+		dev_err(&spi->dev, "device name %s not recognized.\n",
+			spi->modalias);
+		return -ENODEV;
+	}
+
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adata));
 	if (!indio_dev)
 		return -ENOMEM;
 
 	adata = iio_priv(indio_dev);
+	adata->sensor_settings = (struct st_sensor_settings *)settings;
 
-	st_sensors_of_name_probe(&spi->dev, st_accel_of_match,
-				 spi->modalias, sizeof(spi->modalias));
 	st_sensors_spi_configure(indio_dev, spi, adata);
 
 	err = st_accel_common_probe(indio_dev);