Skip to content

Commit 3a7f08f

Browse files
Natália Salvino Andréjic23
authored andcommitted
iio: gyro: HID: hid-sensor-gyro-3d: Refactor channel initialization
Replace the local gyro_3d_adjust_channel_bit_mask() function with a compound literal for scan_type initialization to improve code readability. Additionaly, clean up the channel initialization loop by iterating directly over the channel scan indices. 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 ab568cb commit 3a7f08f

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

drivers/iio/gyro/hid-sensor-gyro-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>
@@ -82,17 +83,6 @@ static const struct iio_chan_spec gyro_3d_channels[] = {
8283
IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP)
8384
};
8485

85-
/* Adjust channel real bits based on report descriptor */
86-
static void gyro_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
87-
int channel, int size)
88-
{
89-
channels[channel].scan_type.sign = 's';
90-
/* Real storage bits will change based on the report desc. */
91-
channels[channel].scan_type.realbits = size * 8;
92-
/* Maximum size of a sample to capture is u32 */
93-
channels[channel].scan_type.storagebits = sizeof(u32) * 8;
94-
}
95-
9686
/* Channel read_raw handler */
9787
static int gyro_3d_read_raw(struct iio_dev *indio_dev,
9888
struct iio_chan_spec const *chan,
@@ -248,19 +238,20 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
248238
struct gyro_3d_state *st)
249239
{
250240
int ret;
251-
int i;
252241

253-
for (i = 0; i <= CHANNEL_SCAN_INDEX_Z; ++i) {
242+
for (unsigned int ch = CHANNEL_SCAN_INDEX_X; ch <= CHANNEL_SCAN_INDEX_Z; ch++) {
254243
ret = sensor_hub_input_get_attribute_info(hsdev,
255244
HID_INPUT_REPORT,
256245
usage_id,
257-
HID_USAGE_SENSOR_ANGL_VELOCITY_X_AXIS + i,
258-
&st->gyro[CHANNEL_SCAN_INDEX_X + i]);
246+
HID_USAGE_SENSOR_ANGL_VELOCITY_X_AXIS + ch,
247+
&st->gyro[ch]);
259248
if (ret < 0)
260249
break;
261-
gyro_3d_adjust_channel_bit_mask(channels,
262-
CHANNEL_SCAN_INDEX_X + i,
263-
st->gyro[CHANNEL_SCAN_INDEX_X + i].size);
250+
channels[ch].scan_type = (struct iio_scan_type) {
251+
.format = 's',
252+
.realbits = BYTES_TO_BITS(st->gyro[ch].size),
253+
.storagebits = BITS_PER_TYPE(u32),
254+
};
264255
}
265256
dev_dbg(&pdev->dev, "gyro_3d %x:%x, %x:%x, %x:%x\n",
266257
st->gyro[0].index,

0 commit comments

Comments
 (0)