Commit 2427a7e9 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Jonathan Cameron

iio: light: adjd_s311: move buffer on adjd_s311_data object

This change moves the entire buffer on the private adjd_s311_data type.
Since the device has 4 channels, it's not a big waste to just allocate the
maximum possible buffer and use only what's needed.

This is in contrast with free-ing and re-allocating the buffer on the
update_scan_mode hook.

Since the driver pushes buffer data with
iio_push_to_buffers_with_timestamp(), the buffer must also include a
64-bit buffer for the timestamp, for each sample-set.

With this change, the adjd_s311_update_scan_mode() is no longer needed.
Signed-off-by: default avatarAlexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210705071456.649659-1-aardelean@deviqon.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 7786da3b
...@@ -54,7 +54,10 @@ ...@@ -54,7 +54,10 @@
struct adjd_s311_data { struct adjd_s311_data {
struct i2c_client *client; struct i2c_client *client;
u16 *buffer; struct {
s16 chans[4];
s64 ts __aligned(8);
} scan;
}; };
enum adjd_s311_channel_idx { enum adjd_s311_channel_idx {
...@@ -129,10 +132,10 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p) ...@@ -129,10 +132,10 @@ static irqreturn_t adjd_s311_trigger_handler(int irq, void *p)
if (ret < 0) if (ret < 0)
goto done; goto done;
data->buffer[j++] = ret & ADJD_S311_DATA_MASK; data->scan.chans[j++] = ret & ADJD_S311_DATA_MASK;
} }
iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns); iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns);
done: done:
iio_trigger_notify_done(indio_dev->trig); iio_trigger_notify_done(indio_dev->trig);
...@@ -225,23 +228,9 @@ static int adjd_s311_write_raw(struct iio_dev *indio_dev, ...@@ -225,23 +228,9 @@ static int adjd_s311_write_raw(struct iio_dev *indio_dev,
return -EINVAL; return -EINVAL;
} }
static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *scan_mask)
{
struct adjd_s311_data *data = iio_priv(indio_dev);
kfree(data->buffer);
data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
if (data->buffer == NULL)
return -ENOMEM;
return 0;
}
static const struct iio_info adjd_s311_info = { static const struct iio_info adjd_s311_info = {
.read_raw = adjd_s311_read_raw, .read_raw = adjd_s311_read_raw,
.write_raw = adjd_s311_write_raw, .write_raw = adjd_s311_write_raw,
.update_scan_mode = adjd_s311_update_scan_mode,
}; };
static int adjd_s311_probe(struct i2c_client *client, static int adjd_s311_probe(struct i2c_client *client,
...@@ -286,11 +275,9 @@ static int adjd_s311_probe(struct i2c_client *client, ...@@ -286,11 +275,9 @@ static int adjd_s311_probe(struct i2c_client *client,
static int adjd_s311_remove(struct i2c_client *client) static int adjd_s311_remove(struct i2c_client *client)
{ {
struct iio_dev *indio_dev = i2c_get_clientdata(client); struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct adjd_s311_data *data = iio_priv(indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
kfree(data->buffer);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment