forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/iio/health/afe4403.c
....@@ -1,17 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AFE4403 Heart Rate Monitors and Low-Cost Pulse Oximeters
34 *
4
- * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
5
+ * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
56 * Andrew F. Davis <afd@ti.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful, but
12
- * WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * General Public License for more details.
157 */
168
179 #include <linux/device.h>
....@@ -30,6 +22,8 @@
3022 #include <linux/iio/trigger.h>
3123 #include <linux/iio/triggered_buffer.h>
3224 #include <linux/iio/trigger_consumer.h>
25
+
26
+#include <asm/unaligned.h>
3327
3428 #include "afe440x.h"
3529
....@@ -231,13 +225,11 @@
231225 if (ret)
232226 return ret;
233227
234
- ret = spi_write_then_read(afe->spi, &reg, 1, rx, 3);
228
+ ret = spi_write_then_read(afe->spi, &reg, 1, rx, sizeof(rx));
235229 if (ret)
236230 return ret;
237231
238
- *val = (rx[0] << 16) |
239
- (rx[1] << 8) |
240
- (rx[2]);
232
+ *val = get_unaligned_be24(&rx[0]);
241233
242234 /* Disable reading from the device */
243235 tx[3] = AFE440X_CONTROL0_WRITE;
....@@ -253,14 +245,14 @@
253245 int *val, int *val2, long mask)
254246 {
255247 struct afe4403_data *afe = iio_priv(indio_dev);
256
- unsigned int reg = afe4403_channel_values[chan->address];
257
- unsigned int field = afe4403_channel_leds[chan->address];
248
+ unsigned int reg, field;
258249 int ret;
259250
260251 switch (chan->type) {
261252 case IIO_INTENSITY:
262253 switch (mask) {
263254 case IIO_CHAN_INFO_RAW:
255
+ reg = afe4403_channel_values[chan->address];
264256 ret = afe4403_read(afe, reg, val);
265257 if (ret)
266258 return ret;
....@@ -270,6 +262,7 @@
270262 case IIO_CURRENT:
271263 switch (mask) {
272264 case IIO_CHAN_INFO_RAW:
265
+ field = afe4403_channel_leds[chan->address];
273266 ret = regmap_field_read(afe->fields[field], val);
274267 if (ret)
275268 return ret;
....@@ -332,13 +325,11 @@
332325 indio_dev->masklength) {
333326 ret = spi_write_then_read(afe->spi,
334327 &afe4403_channel_values[bit], 1,
335
- rx, 3);
328
+ rx, sizeof(rx));
336329 if (ret)
337330 goto err;
338331
339
- afe->buffer[i++] = (rx[0] << 16) |
340
- (rx[1] << 8) |
341
- (rx[2]);
332
+ afe->buffer[i++] = get_unaligned_be24(&rx[0]);
342333 }
343334
344335 /* Disable reading from the device */
....@@ -522,7 +513,6 @@
522513 }
523514
524515 indio_dev->modes = INDIO_DIRECT_MODE;
525
- indio_dev->dev.parent = afe->dev;
526516 indio_dev->channels = afe4403_channels;
527517 indio_dev->num_channels = ARRAY_SIZE(afe4403_channels);
528518 indio_dev->name = AFE4403_DRIVER_NAME;