iio: st_sensors: Call st_sensors_power_enable() from bus drivers

[ Upstream commit 7db4f2cacbede1c6d95552c0d10e77398665a733 ]

In case we would initialize two IIO devices from one physical device,
we shouldn't have a clash on regulators. That's why move
st_sensors_power_enable() call from core to bus drivers.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20210414195454.84183-4-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Andy Shevchenko 2021-04-14 22:54:51 +03:00 committed by Greg Kroah-Hartman
parent f84c7a03d1
commit bfedc81776
12 changed files with 138 additions and 74 deletions

View File

@ -1255,13 +1255,9 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &accel_info;
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_sensors_verify_id(indio_dev);
if (err < 0)
goto st_accel_power_off;
return err;
adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS;
indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
@ -1270,10 +1266,8 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
channels = devm_kmemdup(&indio_dev->dev,
adata->sensor_settings->ch,
channels_size, GFP_KERNEL);
if (!channels) {
err = -ENOMEM;
goto st_accel_power_off;
}
if (!channels)
return -ENOMEM;
if (apply_acpi_orientation(indio_dev, channels))
dev_warn(&indio_dev->dev,
@ -1288,11 +1282,11 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
err = st_sensors_init_sensor(indio_dev, pdata);
if (err < 0)
goto st_accel_power_off;
return err;
err = st_accel_allocate_ring(indio_dev);
if (err < 0)
goto st_accel_power_off;
return err;
if (adata->irq > 0) {
err = st_sensors_allocate_trigger(indio_dev,
@ -1315,9 +1309,6 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
st_sensors_deallocate_trigger(indio_dev);
st_accel_probe_trigger_error:
st_accel_deallocate_ring(indio_dev);
st_accel_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
EXPORT_SYMBOL(st_accel_common_probe);
@ -1326,8 +1317,6 @@ void st_accel_common_remove(struct iio_dev *indio_dev)
{
struct st_sensor_data *adata = iio_priv(indio_dev);
st_sensors_power_disable(indio_dev);
iio_device_unregister(indio_dev);
if (adata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);

View File

@ -174,16 +174,29 @@ static int st_accel_i2c_probe(struct i2c_client *client)
if (ret < 0)
return ret;
ret = st_accel_common_probe(indio_dev);
if (ret < 0)
ret = st_sensors_power_enable(indio_dev);
if (ret)
return ret;
ret = st_accel_common_probe(indio_dev);
if (ret < 0)
goto st_accel_power_off;
return 0;
st_accel_power_off:
st_sensors_power_disable(indio_dev);
return ret;
}
static int st_accel_i2c_remove(struct i2c_client *client)
{
st_accel_common_remove(i2c_get_clientdata(client));
struct iio_dev *indio_dev = i2c_get_clientdata(client);
st_sensors_power_disable(indio_dev);
st_accel_common_remove(indio_dev);
return 0;
}

View File

@ -123,16 +123,29 @@ static int st_accel_spi_probe(struct spi_device *spi)
if (err < 0)
return err;
err = st_accel_common_probe(indio_dev);
if (err < 0)
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_accel_common_probe(indio_dev);
if (err < 0)
goto st_accel_power_off;
return 0;
st_accel_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
static int st_accel_spi_remove(struct spi_device *spi)
{
st_accel_common_remove(spi_get_drvdata(spi));
struct iio_dev *indio_dev = spi_get_drvdata(spi);
st_sensors_power_disable(indio_dev);
st_accel_common_remove(indio_dev);
return 0;
}

View File

@ -466,13 +466,9 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &gyro_info;
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_sensors_verify_id(indio_dev);
if (err < 0)
goto st_gyro_power_off;
return err;
gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS;
indio_dev->channels = gdata->sensor_settings->ch;
@ -485,11 +481,11 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
err = st_sensors_init_sensor(indio_dev, pdata);
if (err < 0)
goto st_gyro_power_off;
return err;
err = st_gyro_allocate_ring(indio_dev);
if (err < 0)
goto st_gyro_power_off;
return err;
if (gdata->irq > 0) {
err = st_sensors_allocate_trigger(indio_dev,
@ -512,9 +508,6 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
st_sensors_deallocate_trigger(indio_dev);
st_gyro_probe_trigger_error:
st_gyro_deallocate_ring(indio_dev);
st_gyro_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
EXPORT_SYMBOL(st_gyro_common_probe);
@ -523,8 +516,6 @@ void st_gyro_common_remove(struct iio_dev *indio_dev)
{
struct st_sensor_data *gdata = iio_priv(indio_dev);
st_sensors_power_disable(indio_dev);
iio_device_unregister(indio_dev);
if (gdata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);

View File

@ -86,16 +86,29 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
if (err < 0)
return err;
err = st_gyro_common_probe(indio_dev);
if (err < 0)
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_gyro_common_probe(indio_dev);
if (err < 0)
goto st_gyro_power_off;
return 0;
st_gyro_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
static int st_gyro_i2c_remove(struct i2c_client *client)
{
st_gyro_common_remove(i2c_get_clientdata(client));
struct iio_dev *indio_dev = i2c_get_clientdata(client);
st_sensors_power_disable(indio_dev);
st_gyro_common_remove(indio_dev);
return 0;
}

View File

@ -90,16 +90,29 @@ static int st_gyro_spi_probe(struct spi_device *spi)
if (err < 0)
return err;
err = st_gyro_common_probe(indio_dev);
if (err < 0)
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_gyro_common_probe(indio_dev);
if (err < 0)
goto st_gyro_power_off;
return 0;
st_gyro_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
static int st_gyro_spi_remove(struct spi_device *spi)
{
st_gyro_common_remove(spi_get_drvdata(spi));
struct iio_dev *indio_dev = spi_get_drvdata(spi);
st_sensors_power_disable(indio_dev);
st_gyro_common_remove(indio_dev);
return 0;
}

View File

@ -494,13 +494,9 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &magn_info;
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_sensors_verify_id(indio_dev);
if (err < 0)
goto st_magn_power_off;
return err;
mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS;
indio_dev->channels = mdata->sensor_settings->ch;
@ -511,11 +507,11 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
err = st_sensors_init_sensor(indio_dev, NULL);
if (err < 0)
goto st_magn_power_off;
return err;
err = st_magn_allocate_ring(indio_dev);
if (err < 0)
goto st_magn_power_off;
return err;
if (mdata->irq > 0) {
err = st_sensors_allocate_trigger(indio_dev,
@ -538,9 +534,6 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
st_sensors_deallocate_trigger(indio_dev);
st_magn_probe_trigger_error:
st_magn_deallocate_ring(indio_dev);
st_magn_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
EXPORT_SYMBOL(st_magn_common_probe);
@ -549,8 +542,6 @@ void st_magn_common_remove(struct iio_dev *indio_dev)
{
struct st_sensor_data *mdata = iio_priv(indio_dev);
st_sensors_power_disable(indio_dev);
iio_device_unregister(indio_dev);
if (mdata->irq > 0)
st_sensors_deallocate_trigger(indio_dev);

View File

@ -78,16 +78,28 @@ static int st_magn_i2c_probe(struct i2c_client *client,
if (err < 0)
return err;
err = st_magn_common_probe(indio_dev);
if (err < 0)
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_magn_common_probe(indio_dev);
if (err < 0)
goto st_magn_power_off;
return 0;
st_magn_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
static int st_magn_i2c_remove(struct i2c_client *client)
{
struct iio_dev *indio_dev = i2c_get_clientdata(client);
st_sensors_power_disable(indio_dev);
st_magn_common_remove(indio_dev);
return 0;

View File

@ -72,16 +72,28 @@ static int st_magn_spi_probe(struct spi_device *spi)
if (err < 0)
return err;
err = st_magn_common_probe(indio_dev);
if (err < 0)
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_magn_common_probe(indio_dev);
if (err < 0)
goto st_magn_power_off;
return 0;
st_magn_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
static int st_magn_spi_remove(struct spi_device *spi)
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
st_sensors_power_disable(indio_dev);
st_magn_common_remove(indio_dev);
return 0;

View File

@ -689,13 +689,9 @@ int st_press_common_probe(struct iio_dev *indio_dev)
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &press_info;
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_sensors_verify_id(indio_dev);
if (err < 0)
goto st_press_power_off;
return err;
/*
* Skip timestamping channel while declaring available channels to
@ -718,11 +714,11 @@ int st_press_common_probe(struct iio_dev *indio_dev)
err = st_sensors_init_sensor(indio_dev, pdata);
if (err < 0)
goto st_press_power_off;
return err;
err = st_press_allocate_ring(indio_dev);
if (err < 0)
goto st_press_power_off;
return err;
if (press_data->irq > 0) {
err = st_sensors_allocate_trigger(indio_dev,
@ -745,9 +741,6 @@ int st_press_common_probe(struct iio_dev *indio_dev)
st_sensors_deallocate_trigger(indio_dev);
st_press_probe_trigger_error:
st_press_deallocate_ring(indio_dev);
st_press_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
EXPORT_SYMBOL(st_press_common_probe);
@ -756,8 +749,6 @@ void st_press_common_remove(struct iio_dev *indio_dev)
{
struct st_sensor_data *press_data = iio_priv(indio_dev);
st_sensors_power_disable(indio_dev);
iio_device_unregister(indio_dev);
if (press_data->irq > 0)
st_sensors_deallocate_trigger(indio_dev);

View File

@ -98,16 +98,29 @@ static int st_press_i2c_probe(struct i2c_client *client,
if (ret < 0)
return ret;
ret = st_press_common_probe(indio_dev);
if (ret < 0)
ret = st_sensors_power_enable(indio_dev);
if (ret)
return ret;
ret = st_press_common_probe(indio_dev);
if (ret < 0)
goto st_press_power_off;
return 0;
st_press_power_off:
st_sensors_power_disable(indio_dev);
return ret;
}
static int st_press_i2c_remove(struct i2c_client *client)
{
st_press_common_remove(i2c_get_clientdata(client));
struct iio_dev *indio_dev = i2c_get_clientdata(client);
st_sensors_power_disable(indio_dev);
st_press_common_remove(indio_dev);
return 0;
}

View File

@ -82,16 +82,29 @@ static int st_press_spi_probe(struct spi_device *spi)
if (err < 0)
return err;
err = st_press_common_probe(indio_dev);
if (err < 0)
err = st_sensors_power_enable(indio_dev);
if (err)
return err;
err = st_press_common_probe(indio_dev);
if (err < 0)
goto st_press_power_off;
return 0;
st_press_power_off:
st_sensors_power_disable(indio_dev);
return err;
}
static int st_press_spi_remove(struct spi_device *spi)
{
st_press_common_remove(spi_get_drvdata(spi));
struct iio_dev *indio_dev = spi_get_drvdata(spi);
st_sensors_power_disable(indio_dev);
st_press_common_remove(indio_dev);
return 0;
}