aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Ciocca <denis.ciocca@st.com>2019-08-05 14:57:11 -0400
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2019-08-11 04:26:04 -0400
commite031d5f558f1535968df1ecae8d734b84c17f78d (patch)
tree663fb1b5ab579c6486d387e5dabe3ab747535e86
parent854da7511a05c9a05a4f28fb2225349380520b96 (diff)
iio:st_sensors: remove buffer allocation at each buffer enable
This patch is removing the buffer allocation at each buffer enable. We just allocate enough memory in the main structure during probe to cover maximum size needed (that anyway is pretty small) [16bytes]. Signed-off-by: Denis Ciocca <denis.ciocca@st.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r--drivers/iio/accel/st_accel_buffer.c12
-rw-r--r--drivers/iio/gyro/st_gyro_buffer.c12
-rw-r--r--drivers/iio/magnetometer/st_magn_buffer.c12
-rw-r--r--drivers/iio/pressure/st_pressure_buffer.c12
-rw-r--r--include/linux/iio/common/st_sensors.h14
5 files changed, 13 insertions, 49 deletions
diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
index 59dcef02ec19..9f2b40474b8e 100644
--- a/drivers/iio/accel/st_accel_buffer.c
+++ b/drivers/iio/accel/st_accel_buffer.c
@@ -31,17 +31,11 @@ int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
31 31
32static int st_accel_buffer_postenable(struct iio_dev *indio_dev) 32static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
33{ 33{
34 struct st_sensor_data *adata = iio_priv(indio_dev);
35 int err; 34 int err;
36 35
37 adata->buffer_data = kmalloc(indio_dev->scan_bytes,
38 GFP_DMA | GFP_KERNEL);
39 if (!adata->buffer_data)
40 return -ENOMEM;
41
42 err = iio_triggered_buffer_postenable(indio_dev); 36 err = iio_triggered_buffer_postenable(indio_dev);
43 if (err < 0) 37 if (err < 0)
44 goto st_accel_free_buffer; 38 return err;
45 39
46 err = st_sensors_set_axis_enable(indio_dev, 40 err = st_sensors_set_axis_enable(indio_dev,
47 (u8)indio_dev->active_scan_mask[0]); 41 (u8)indio_dev->active_scan_mask[0]);
@@ -58,14 +52,11 @@ st_accel_buffer_enable_all_axis:
58 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); 52 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
59st_accel_buffer_predisable: 53st_accel_buffer_predisable:
60 iio_triggered_buffer_predisable(indio_dev); 54 iio_triggered_buffer_predisable(indio_dev);
61st_accel_free_buffer:
62 kfree(adata->buffer_data);
63 return err; 55 return err;
64} 56}
65 57
66static int st_accel_buffer_predisable(struct iio_dev *indio_dev) 58static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
67{ 59{
68 struct st_sensor_data *adata = iio_priv(indio_dev);
69 int err, err2; 60 int err, err2;
70 61
71 err = st_sensors_set_enable(indio_dev, false); 62 err = st_sensors_set_enable(indio_dev, false);
@@ -79,7 +70,6 @@ st_accel_buffer_predisable:
79 if (!err) 70 if (!err)
80 err = err2; 71 err = err2;
81 72
82 kfree(adata->buffer_data);
83 return err; 73 return err;
84} 74}
85 75
diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
index c6ddfecc1fc3..7465ad62391c 100644
--- a/drivers/iio/gyro/st_gyro_buffer.c
+++ b/drivers/iio/gyro/st_gyro_buffer.c
@@ -31,17 +31,11 @@ int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
31 31
32static int st_gyro_buffer_postenable(struct iio_dev *indio_dev) 32static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
33{ 33{
34 struct st_sensor_data *gdata = iio_priv(indio_dev);
35 int err; 34 int err;
36 35
37 gdata->buffer_data = kmalloc(indio_dev->scan_bytes,
38 GFP_DMA | GFP_KERNEL);
39 if (!gdata->buffer_data)
40 return -ENOMEM;
41
42 err = iio_triggered_buffer_postenable(indio_dev); 36 err = iio_triggered_buffer_postenable(indio_dev);
43 if (err < 0) 37 if (err < 0)
44 goto st_gyro_free_buffer; 38 return err;
45 39
46 err = st_sensors_set_axis_enable(indio_dev, 40 err = st_sensors_set_axis_enable(indio_dev,
47 (u8)indio_dev->active_scan_mask[0]); 41 (u8)indio_dev->active_scan_mask[0]);
@@ -58,15 +52,12 @@ st_gyro_buffer_enable_all_axis:
58 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS); 52 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
59st_gyro_buffer_predisable: 53st_gyro_buffer_predisable:
60 iio_triggered_buffer_predisable(indio_dev); 54 iio_triggered_buffer_predisable(indio_dev);
61st_gyro_free_buffer:
62 kfree(gdata->buffer_data);
63 return err; 55 return err;
64} 56}
65 57
66static int st_gyro_buffer_predisable(struct iio_dev *indio_dev) 58static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
67{ 59{
68 int err, err2; 60 int err, err2;
69 struct st_sensor_data *gdata = iio_priv(indio_dev);
70 61
71 err = st_sensors_set_enable(indio_dev, false); 62 err = st_sensors_set_enable(indio_dev, false);
72 if (err < 0) 63 if (err < 0)
@@ -79,7 +70,6 @@ st_gyro_buffer_predisable:
79 if (!err) 70 if (!err)
80 err = err2; 71 err = err2;
81 72
82 kfree(gdata->buffer_data);
83 return err; 73 return err;
84} 74}
85 75
diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
index 658d627dad8e..bb425c167a96 100644
--- a/drivers/iio/magnetometer/st_magn_buffer.c
+++ b/drivers/iio/magnetometer/st_magn_buffer.c
@@ -31,17 +31,11 @@ int st_magn_trig_set_state(struct iio_trigger *trig, bool state)
31 31
32static int st_magn_buffer_postenable(struct iio_dev *indio_dev) 32static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
33{ 33{
34 struct st_sensor_data *mdata = iio_priv(indio_dev);
35 int err; 34 int err;
36 35
37 mdata->buffer_data = kmalloc(indio_dev->scan_bytes,
38 GFP_DMA | GFP_KERNEL);
39 if (!mdata->buffer_data)
40 return -ENOMEM;
41
42 err = iio_triggered_buffer_postenable(indio_dev); 36 err = iio_triggered_buffer_postenable(indio_dev);
43 if (err < 0) 37 if (err < 0)
44 goto st_magn_free_buffer; 38 return err;
45 39
46 err = st_sensors_set_enable(indio_dev, true); 40 err = st_sensors_set_enable(indio_dev, true);
47 if (err < 0) 41 if (err < 0)
@@ -51,14 +45,11 @@ static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
51 45
52st_magn_buffer_predisable: 46st_magn_buffer_predisable:
53 iio_triggered_buffer_predisable(indio_dev); 47 iio_triggered_buffer_predisable(indio_dev);
54st_magn_free_buffer:
55 kfree(mdata->buffer_data);
56 return err; 48 return err;
57} 49}
58 50
59static int st_magn_buffer_predisable(struct iio_dev *indio_dev) 51static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
60{ 52{
61 struct st_sensor_data *mdata = iio_priv(indio_dev);
62 int err, err2; 53 int err, err2;
63 54
64 err = st_sensors_set_enable(indio_dev, false); 55 err = st_sensors_set_enable(indio_dev, false);
@@ -67,7 +58,6 @@ static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
67 if (!err) 58 if (!err)
68 err = err2; 59 err = err2;
69 60
70 kfree(mdata->buffer_data);
71 return err; 61 return err;
72} 62}
73 63
diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c
index 77cb2d862f19..418dbf9e6e1e 100644
--- a/drivers/iio/pressure/st_pressure_buffer.c
+++ b/drivers/iio/pressure/st_pressure_buffer.c
@@ -31,17 +31,11 @@ int st_press_trig_set_state(struct iio_trigger *trig, bool state)
31 31
32static int st_press_buffer_postenable(struct iio_dev *indio_dev) 32static int st_press_buffer_postenable(struct iio_dev *indio_dev)
33{ 33{
34 struct st_sensor_data *press_data = iio_priv(indio_dev);
35 int err; 34 int err;
36 35
37 press_data->buffer_data = kmalloc(indio_dev->scan_bytes,
38 GFP_DMA | GFP_KERNEL);
39 if (!press_data->buffer_data)
40 return -ENOMEM;
41
42 err = iio_triggered_buffer_postenable(indio_dev); 36 err = iio_triggered_buffer_postenable(indio_dev);
43 if (err < 0) 37 if (err < 0)
44 goto st_press_free_buffer; 38 return err;
45 39
46 err = st_sensors_set_enable(indio_dev, true); 40 err = st_sensors_set_enable(indio_dev, true);
47 if (err < 0) 41 if (err < 0)
@@ -51,14 +45,11 @@ static int st_press_buffer_postenable(struct iio_dev *indio_dev)
51 45
52st_press_buffer_predisable: 46st_press_buffer_predisable:
53 iio_triggered_buffer_predisable(indio_dev); 47 iio_triggered_buffer_predisable(indio_dev);
54st_press_free_buffer:
55 kfree(press_data->buffer_data);
56 return err; 48 return err;
57} 49}
58 50
59static int st_press_buffer_predisable(struct iio_dev *indio_dev) 51static int st_press_buffer_predisable(struct iio_dev *indio_dev)
60{ 52{
61 struct st_sensor_data *press_data = iio_priv(indio_dev);
62 int err, err2; 53 int err, err2;
63 54
64 err = st_sensors_set_enable(indio_dev, false); 55 err = st_sensors_set_enable(indio_dev, false);
@@ -67,7 +58,6 @@ static int st_press_buffer_predisable(struct iio_dev *indio_dev)
67 if (!err) 58 if (!err)
68 err = err2; 59 err = err2;
69 60
70 kfree(press_data->buffer_data);
71 return err; 61 return err;
72} 62}
73 63
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 4d0889bf1c6c..686be532f4cb 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -20,8 +20,12 @@
20 20
21#include <linux/platform_data/st_sensors_pdata.h> 21#include <linux/platform_data/st_sensors_pdata.h>
22 22
23#define ST_SENSORS_TX_MAX_LENGTH 2 23/*
24#define ST_SENSORS_RX_MAX_LENGTH 6 24 * Buffer size max case: 2bytes per channel, 3 channels in total +
25 * 8bytes timestamp channel (s64)
26 */
27#define ST_SENSORS_MAX_BUFFER_SIZE (ALIGN(2 * 3, sizeof(s64)) + \
28 sizeof(s64))
25 29
26#define ST_SENSORS_ODR_LIST_MAX 10 30#define ST_SENSORS_ODR_LIST_MAX 10
27#define ST_SENSORS_FULLSCALE_AVL_MAX 10 31#define ST_SENSORS_FULLSCALE_AVL_MAX 10
@@ -215,7 +219,6 @@ struct st_sensor_settings {
215 * @vdd_io: Pointer to sensor's Vdd-IO power supply 219 * @vdd_io: Pointer to sensor's Vdd-IO power supply
216 * @regmap: Pointer to specific sensor regmap configuration. 220 * @regmap: Pointer to specific sensor regmap configuration.
217 * @enabled: Status of the sensor (false->off, true->on). 221 * @enabled: Status of the sensor (false->off, true->on).
218 * @buffer_data: Data used by buffer part.
219 * @odr: Output data rate of the sensor [Hz]. 222 * @odr: Output data rate of the sensor [Hz].
220 * num_data_channels: Number of data channels used in buffer. 223 * num_data_channels: Number of data channels used in buffer.
221 * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2). 224 * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2).
@@ -224,6 +227,7 @@ struct st_sensor_settings {
224 * @edge_irq: the IRQ triggers on edges and need special handling. 227 * @edge_irq: the IRQ triggers on edges and need special handling.
225 * @hw_irq_trigger: if we're using the hardware interrupt on the sensor. 228 * @hw_irq_trigger: if we're using the hardware interrupt on the sensor.
226 * @hw_timestamp: Latest timestamp from the interrupt handler, when in use. 229 * @hw_timestamp: Latest timestamp from the interrupt handler, when in use.
230 * @buffer_data: Data used by buffer part.
227 */ 231 */
228struct st_sensor_data { 232struct st_sensor_data {
229 struct device *dev; 233 struct device *dev;
@@ -237,8 +241,6 @@ struct st_sensor_data {
237 241
238 bool enabled; 242 bool enabled;
239 243
240 char *buffer_data;
241
242 unsigned int odr; 244 unsigned int odr;
243 unsigned int num_data_channels; 245 unsigned int num_data_channels;
244 246
@@ -249,6 +251,8 @@ struct st_sensor_data {
249 bool edge_irq; 251 bool edge_irq;
250 bool hw_irq_trigger; 252 bool hw_irq_trigger;
251 s64 hw_timestamp; 253 s64 hw_timestamp;
254
255 char buffer_data[ST_SENSORS_MAX_BUFFER_SIZE] ____cacheline_aligned;
252}; 256};
253 257
254#ifdef CONFIG_IIO_BUFFER 258#ifdef CONFIG_IIO_BUFFER