iio: st_sensors: remove st_sensors_deallocate_trigger() function
This change converts the st_sensors_allocate_trigger() to use device-managed functions. The parent device of the IIO device object is used. This is based on the assumption that all other devm_ calls in the ST sensors use this reference. That makes the st_sensors_deallocate_trigger() function un-needed, so it can be removed. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20210823112204.243255-3-aardelean@deviqon.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
9f0b3e0cc0
commit
82bcb7fb64
|
@ -1380,29 +1380,13 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
|
|||
return err;
|
||||
}
|
||||
|
||||
err = iio_device_register(indio_dev);
|
||||
if (err)
|
||||
goto st_accel_device_register_error;
|
||||
|
||||
dev_info(&indio_dev->dev, "registered accelerometer %s\n",
|
||||
indio_dev->name);
|
||||
|
||||
return 0;
|
||||
|
||||
st_accel_device_register_error:
|
||||
if (adata->irq > 0)
|
||||
st_sensors_deallocate_trigger(indio_dev);
|
||||
return err;
|
||||
return iio_device_register(indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL(st_accel_common_probe);
|
||||
|
||||
void st_accel_common_remove(struct iio_dev *indio_dev)
|
||||
{
|
||||
struct st_sensor_data *adata = iio_priv(indio_dev);
|
||||
|
||||
iio_device_unregister(indio_dev);
|
||||
if (adata->irq > 0)
|
||||
st_sensors_deallocate_trigger(indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL(st_accel_common_remove);
|
||||
|
||||
|
|
|
@ -119,11 +119,12 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
const struct iio_trigger_ops *trigger_ops)
|
||||
{
|
||||
struct st_sensor_data *sdata = iio_priv(indio_dev);
|
||||
struct device *parent = indio_dev->dev.parent;
|
||||
unsigned long irq_trig;
|
||||
int err;
|
||||
|
||||
sdata->trig = iio_trigger_alloc(sdata->dev, "%s-trigger",
|
||||
indio_dev->name);
|
||||
sdata->trig = devm_iio_trigger_alloc(parent, "%s-trigger",
|
||||
indio_dev->name);
|
||||
if (sdata->trig == NULL) {
|
||||
dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n");
|
||||
return -ENOMEM;
|
||||
|
@ -153,7 +154,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
sdata->sensor_settings->drdy_irq.addr_ihl,
|
||||
sdata->sensor_settings->drdy_irq.mask_ihl, 1);
|
||||
if (err < 0)
|
||||
goto iio_trigger_free;
|
||||
return err;
|
||||
dev_info(&indio_dev->dev,
|
||||
"interrupts on the falling edge or active low level\n");
|
||||
}
|
||||
|
@ -179,8 +180,7 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
if (!sdata->sensor_settings->drdy_irq.stat_drdy.addr) {
|
||||
dev_err(&indio_dev->dev,
|
||||
"edge IRQ not supported w/o stat register.\n");
|
||||
err = -EOPNOTSUPP;
|
||||
goto iio_trigger_free;
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
sdata->edge_irq = true;
|
||||
} else {
|
||||
|
@ -205,44 +205,29 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
sdata->sensor_settings->drdy_irq.stat_drdy.addr)
|
||||
irq_trig |= IRQF_SHARED;
|
||||
|
||||
err = request_threaded_irq(sdata->irq,
|
||||
st_sensors_irq_handler,
|
||||
st_sensors_irq_thread,
|
||||
irq_trig,
|
||||
sdata->trig->name,
|
||||
sdata->trig);
|
||||
err = devm_request_threaded_irq(parent,
|
||||
sdata->irq,
|
||||
st_sensors_irq_handler,
|
||||
st_sensors_irq_thread,
|
||||
irq_trig,
|
||||
sdata->trig->name,
|
||||
sdata->trig);
|
||||
if (err) {
|
||||
dev_err(&indio_dev->dev, "failed to request trigger IRQ.\n");
|
||||
goto iio_trigger_free;
|
||||
return err;
|
||||
}
|
||||
|
||||
err = iio_trigger_register(sdata->trig);
|
||||
err = devm_iio_trigger_register(parent, sdata->trig);
|
||||
if (err < 0) {
|
||||
dev_err(&indio_dev->dev, "failed to register iio trigger.\n");
|
||||
goto iio_trigger_register_error;
|
||||
return err;
|
||||
}
|
||||
indio_dev->trig = iio_trigger_get(sdata->trig);
|
||||
|
||||
return 0;
|
||||
|
||||
iio_trigger_register_error:
|
||||
free_irq(sdata->irq, sdata->trig);
|
||||
iio_trigger_free:
|
||||
iio_trigger_free(sdata->trig);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL(st_sensors_allocate_trigger);
|
||||
|
||||
void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
|
||||
{
|
||||
struct st_sensor_data *sdata = iio_priv(indio_dev);
|
||||
|
||||
iio_trigger_unregister(sdata->trig);
|
||||
free_irq(sdata->irq, sdata->trig);
|
||||
iio_trigger_free(sdata->trig);
|
||||
}
|
||||
EXPORT_SYMBOL(st_sensors_deallocate_trigger);
|
||||
|
||||
int st_sensors_validate_device(struct iio_trigger *trig,
|
||||
struct iio_dev *indio_dev)
|
||||
{
|
||||
|
|
|
@ -515,29 +515,13 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
|
|||
return err;
|
||||
}
|
||||
|
||||
err = iio_device_register(indio_dev);
|
||||
if (err)
|
||||
goto st_gyro_device_register_error;
|
||||
|
||||
dev_info(&indio_dev->dev, "registered gyroscope %s\n",
|
||||
indio_dev->name);
|
||||
|
||||
return 0;
|
||||
|
||||
st_gyro_device_register_error:
|
||||
if (gdata->irq > 0)
|
||||
st_sensors_deallocate_trigger(indio_dev);
|
||||
return err;
|
||||
return iio_device_register(indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL(st_gyro_common_probe);
|
||||
|
||||
void st_gyro_common_remove(struct iio_dev *indio_dev)
|
||||
{
|
||||
struct st_sensor_data *gdata = iio_priv(indio_dev);
|
||||
|
||||
iio_device_unregister(indio_dev);
|
||||
if (gdata->irq > 0)
|
||||
st_sensors_deallocate_trigger(indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL(st_gyro_common_remove);
|
||||
|
||||
|
|
|
@ -650,29 +650,13 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
|
|||
return err;
|
||||
}
|
||||
|
||||
err = iio_device_register(indio_dev);
|
||||
if (err)
|
||||
goto st_magn_device_register_error;
|
||||
|
||||
dev_info(&indio_dev->dev, "registered magnetometer %s\n",
|
||||
indio_dev->name);
|
||||
|
||||
return 0;
|
||||
|
||||
st_magn_device_register_error:
|
||||
if (mdata->irq > 0)
|
||||
st_sensors_deallocate_trigger(indio_dev);
|
||||
return err;
|
||||
return iio_device_register(indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL(st_magn_common_probe);
|
||||
|
||||
void st_magn_common_remove(struct iio_dev *indio_dev)
|
||||
{
|
||||
struct st_sensor_data *mdata = iio_priv(indio_dev);
|
||||
|
||||
iio_device_unregister(indio_dev);
|
||||
if (mdata->irq > 0)
|
||||
st_sensors_deallocate_trigger(indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL(st_magn_common_remove);
|
||||
|
||||
|
|
|
@ -721,29 +721,13 @@ int st_press_common_probe(struct iio_dev *indio_dev)
|
|||
return err;
|
||||
}
|
||||
|
||||
err = iio_device_register(indio_dev);
|
||||
if (err)
|
||||
goto st_press_device_register_error;
|
||||
|
||||
dev_info(&indio_dev->dev, "registered pressure sensor %s\n",
|
||||
indio_dev->name);
|
||||
|
||||
return err;
|
||||
|
||||
st_press_device_register_error:
|
||||
if (press_data->irq > 0)
|
||||
st_sensors_deallocate_trigger(indio_dev);
|
||||
return err;
|
||||
return iio_device_register(indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL(st_press_common_probe);
|
||||
|
||||
void st_press_common_remove(struct iio_dev *indio_dev)
|
||||
{
|
||||
struct st_sensor_data *press_data = iio_priv(indio_dev);
|
||||
|
||||
iio_device_unregister(indio_dev);
|
||||
if (press_data->irq > 0)
|
||||
st_sensors_deallocate_trigger(indio_dev);
|
||||
}
|
||||
EXPORT_SYMBOL(st_press_common_remove);
|
||||
|
||||
|
|
|
@ -273,7 +273,6 @@ irqreturn_t st_sensors_trigger_handler(int irq, void *p);
|
|||
int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
||||
const struct iio_trigger_ops *trigger_ops);
|
||||
|
||||
void st_sensors_deallocate_trigger(struct iio_dev *indio_dev);
|
||||
int st_sensors_validate_device(struct iio_trigger *trig,
|
||||
struct iio_dev *indio_dev);
|
||||
#else
|
||||
|
@ -282,10 +281,6 @@ static inline int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
static inline void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#define st_sensors_validate_device NULL
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue