iio: gyro: bmg160: decouple buffer and triggers

Make it possible to use buffering with an external trigger, such as one
based on sysfs or hrtimer.

Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
Vlad Dogaru 2015-05-13 16:30:09 +03:00 коммит произвёл Jonathan Cameron
Родитель eb2191017e
Коммит 00e0c8e8e8
1 изменённых файлов: 32 добавлений и 24 удалений

Просмотреть файл

@ -737,17 +737,6 @@ static int bmg160_write_event_config(struct iio_dev *indio_dev,
return 0; return 0;
} }
static int bmg160_validate_trigger(struct iio_dev *indio_dev,
struct iio_trigger *trig)
{
struct bmg160_data *data = iio_priv(indio_dev);
if (data->dready_trig != trig && data->motion_trig != trig)
return -EINVAL;
return 0;
}
static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("100 200 400 1000 2000"); static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("100 200 400 1000 2000");
static IIO_CONST_ATTR(in_anglvel_scale_available, static IIO_CONST_ATTR(in_anglvel_scale_available,
@ -809,7 +798,6 @@ static const struct iio_info bmg160_info = {
.write_event_value = bmg160_write_event, .write_event_value = bmg160_write_event,
.write_event_config = bmg160_write_event_config, .write_event_config = bmg160_write_event_config,
.read_event_config = bmg160_read_event_config, .read_event_config = bmg160_read_event_config,
.validate_trigger = bmg160_validate_trigger,
.driver_module = THIS_MODULE, .driver_module = THIS_MODULE,
}; };
@ -984,6 +972,27 @@ static irqreturn_t bmg160_data_rdy_trig_poll(int irq, void *private)
} }
static int bmg160_buffer_preenable(struct iio_dev *indio_dev)
{
struct bmg160_data *data = iio_priv(indio_dev);
return bmg160_set_power_state(data, true);
}
static int bmg160_buffer_postdisable(struct iio_dev *indio_dev)
{
struct bmg160_data *data = iio_priv(indio_dev);
return bmg160_set_power_state(data, false);
}
static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {
.preenable = bmg160_buffer_preenable,
.postenable = iio_triggered_buffer_postenable,
.predisable = iio_triggered_buffer_predisable,
.postdisable = bmg160_buffer_postdisable,
};
static int bmg160_gpio_probe(struct i2c_client *client, static int bmg160_gpio_probe(struct i2c_client *client,
struct bmg160_data *data) struct bmg160_data *data)
@ -1100,17 +1109,17 @@ static int bmg160_probe(struct i2c_client *client,
data->motion_trig = NULL; data->motion_trig = NULL;
goto err_trigger_unregister; goto err_trigger_unregister;
} }
}
ret = iio_triggered_buffer_setup(indio_dev, ret = iio_triggered_buffer_setup(indio_dev,
iio_pollfunc_store_time, iio_pollfunc_store_time,
bmg160_trigger_handler, bmg160_trigger_handler,
NULL); &bmg160_buffer_setup_ops);
if (ret < 0) { if (ret < 0) {
dev_err(&client->dev, dev_err(&client->dev,
"iio triggered buffer setup failed\n"); "iio triggered buffer setup failed\n");
goto err_trigger_unregister; goto err_trigger_unregister;
} }
}
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret < 0) { if (ret < 0) {
@ -1132,7 +1141,6 @@ static int bmg160_probe(struct i2c_client *client,
err_iio_unregister: err_iio_unregister:
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
err_buffer_cleanup: err_buffer_cleanup:
if (data->dready_trig)
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
err_trigger_unregister: err_trigger_unregister:
if (data->dready_trig) if (data->dready_trig)
@ -1153,9 +1161,9 @@ static int bmg160_remove(struct i2c_client *client)
pm_runtime_put_noidle(&client->dev); pm_runtime_put_noidle(&client->dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
if (data->dready_trig) { if (data->dready_trig) {
iio_triggered_buffer_cleanup(indio_dev);
iio_trigger_unregister(data->dready_trig); iio_trigger_unregister(data->dready_trig);
iio_trigger_unregister(data->motion_trig); iio_trigger_unregister(data->motion_trig);
} }