Commit 0fe2f2b7 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron
Browse files

iio: tcs3414: fix iio_triggered_buffer_{pre,post}enable positions



The iio_triggered_buffer_{predisable,postenable} functions attach/detach
the poll functions.

For the predisable hook, the disable code should occur before detaching
the poll func, and for the postenable hook, the poll func should be
attached before the enable code.

The driver was slightly reworked. The preenable hook was moved to the
postenable, to add some symmetry to the postenable/predisable part.

Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 505ea3ad
Loading
Loading
Loading
Loading
+20 −10
Original line number Original line Diff line number Diff line
@@ -240,32 +240,42 @@ static const struct iio_info tcs3414_info = {
	.attrs = &tcs3414_attribute_group,
	.attrs = &tcs3414_attribute_group,
};
};


static int tcs3414_buffer_preenable(struct iio_dev *indio_dev)
static int tcs3414_buffer_postenable(struct iio_dev *indio_dev)
{
{
	struct tcs3414_data *data = iio_priv(indio_dev);
	struct tcs3414_data *data = iio_priv(indio_dev);
	int ret;

	ret = iio_triggered_buffer_postenable(indio_dev);
	if (ret)
		return ret;


	data->control |= TCS3414_CONTROL_ADC_EN;
	data->control |= TCS3414_CONTROL_ADC_EN;
	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
		data->control);
		data->control);
	if (ret)
		iio_triggered_buffer_predisable(indio_dev);

	return ret;
}
}


static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)
static int tcs3414_buffer_predisable(struct iio_dev *indio_dev)
{
{
	struct tcs3414_data *data = iio_priv(indio_dev);
	struct tcs3414_data *data = iio_priv(indio_dev);
	int ret;
	int ret, ret2;

	ret = iio_triggered_buffer_predisable(indio_dev);
	if (ret < 0)
		return ret;


	data->control &= ~TCS3414_CONTROL_ADC_EN;
	data->control &= ~TCS3414_CONTROL_ADC_EN;
	return i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
	ret = i2c_smbus_write_byte_data(data->client, TCS3414_CONTROL,
		data->control);
		data->control);

	ret2 = iio_triggered_buffer_predisable(indio_dev);
	if (!ret)
		ret = ret2;

	return ret;
}
}


static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = {
static const struct iio_buffer_setup_ops tcs3414_buffer_setup_ops = {
	.preenable = tcs3414_buffer_preenable,
	.postenable = tcs3414_buffer_postenable,
	.postenable = &iio_triggered_buffer_postenable,
	.predisable = tcs3414_buffer_predisable,
	.predisable = tcs3414_buffer_predisable,
};
};