Skip to content

Commit ab568cb

Browse files
Natália Salvino Andréjic23
authored andcommitted
iio: accel: HID: hid-sensor-accel-3d: Refactor channel initialization
Clean up the channel initialization loop and replace the local accel_3d_adjust_channel_bit_mask() function with a compound literal to improve code readability. Signed-off-by: Natália Salvino André <natalia.andre@ime.usp.br> Co-developed-by: Pietro Di Consolo Gregorio <pietro.gregorio@usp.br> Signed-off-by: Pietro Di Consolo Gregorio <pietro.gregorio@usp.br> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent 94574df commit ab568cb

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

drivers/iio/accel/hid-sensor-accel-3d.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* HID Sensors Driver
44
* Copyright (c) 2012, Intel Corporation.
55
*/
6+
#include <linux/bitops.h>
67
#include <linux/device.h>
78
#include <linux/platform_device.h>
89
#include <linux/module.h>
@@ -119,17 +120,6 @@ static const struct iio_chan_spec gravity_channels[] = {
119120
IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP),
120121
};
121122

122-
/* Adjust channel real bits based on report descriptor */
123-
static void accel_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
124-
int channel, int size)
125-
{
126-
channels[channel].scan_type.sign = 's';
127-
/* Real storage bits will change based on the report desc. */
128-
channels[channel].scan_type.realbits = size * 8;
129-
/* Maximum size of a sample to capture is u32 */
130-
channels[channel].scan_type.storagebits = sizeof(u32) * 8;
131-
}
132-
133123
/* Channel read_raw handler */
134124
static int accel_3d_read_raw(struct iio_dev *indio_dev,
135125
struct iio_chan_spec const *chan,
@@ -297,19 +287,20 @@ static int accel_3d_parse_report(struct platform_device *pdev,
297287
struct accel_3d_state *st)
298288
{
299289
int ret;
300-
int i;
301290

302-
for (i = 0; i <= CHANNEL_SCAN_INDEX_Z; ++i) {
291+
for (unsigned int ch = CHANNEL_SCAN_INDEX_X; ch <= CHANNEL_SCAN_INDEX_Z; ch++) {
303292
ret = sensor_hub_input_get_attribute_info(hsdev,
304293
HID_INPUT_REPORT,
305294
usage_id,
306-
HID_USAGE_SENSOR_ACCEL_X_AXIS + i,
307-
&st->accel[CHANNEL_SCAN_INDEX_X + i]);
295+
HID_USAGE_SENSOR_ACCEL_X_AXIS + ch,
296+
&st->accel[ch]);
308297
if (ret < 0)
309298
break;
310-
accel_3d_adjust_channel_bit_mask(channels,
311-
CHANNEL_SCAN_INDEX_X + i,
312-
st->accel[CHANNEL_SCAN_INDEX_X + i].size);
299+
channels[ch].scan_type = (struct iio_scan_type) {
300+
.format = 's',
301+
.realbits = BYTES_TO_BITS(st->accel[ch].size),
302+
.storagebits = BITS_PER_TYPE(u32),
303+
};
313304
}
314305
dev_dbg(&pdev->dev, "accel_3d %x:%x, %x:%x, %x:%x\n",
315306
st->accel[0].index,

0 commit comments

Comments
 (0)