| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * AFE4403 Heart Rate Monitors and Low-Cost Pulse Oximeters |
|---|
| 3 | 4 | * |
|---|
| 4 | | - * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/ |
|---|
| 5 | + * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/ |
|---|
| 5 | 6 | * 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. |
|---|
| 15 | 7 | */ |
|---|
| 16 | 8 | |
|---|
| 17 | 9 | #include <linux/device.h> |
|---|
| .. | .. |
|---|
| 30 | 22 | #include <linux/iio/trigger.h> |
|---|
| 31 | 23 | #include <linux/iio/triggered_buffer.h> |
|---|
| 32 | 24 | #include <linux/iio/trigger_consumer.h> |
|---|
| 25 | + |
|---|
| 26 | +#include <asm/unaligned.h> |
|---|
| 33 | 27 | |
|---|
| 34 | 28 | #include "afe440x.h" |
|---|
| 35 | 29 | |
|---|
| .. | .. |
|---|
| 231 | 225 | if (ret) |
|---|
| 232 | 226 | return ret; |
|---|
| 233 | 227 | |
|---|
| 234 | | - ret = spi_write_then_read(afe->spi, ®, 1, rx, 3); |
|---|
| 228 | + ret = spi_write_then_read(afe->spi, ®, 1, rx, sizeof(rx)); |
|---|
| 235 | 229 | if (ret) |
|---|
| 236 | 230 | return ret; |
|---|
| 237 | 231 | |
|---|
| 238 | | - *val = (rx[0] << 16) | |
|---|
| 239 | | - (rx[1] << 8) | |
|---|
| 240 | | - (rx[2]); |
|---|
| 232 | + *val = get_unaligned_be24(&rx[0]); |
|---|
| 241 | 233 | |
|---|
| 242 | 234 | /* Disable reading from the device */ |
|---|
| 243 | 235 | tx[3] = AFE440X_CONTROL0_WRITE; |
|---|
| .. | .. |
|---|
| 253 | 245 | int *val, int *val2, long mask) |
|---|
| 254 | 246 | { |
|---|
| 255 | 247 | 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; |
|---|
| 258 | 249 | int ret; |
|---|
| 259 | 250 | |
|---|
| 260 | 251 | switch (chan->type) { |
|---|
| 261 | 252 | case IIO_INTENSITY: |
|---|
| 262 | 253 | switch (mask) { |
|---|
| 263 | 254 | case IIO_CHAN_INFO_RAW: |
|---|
| 255 | + reg = afe4403_channel_values[chan->address]; |
|---|
| 264 | 256 | ret = afe4403_read(afe, reg, val); |
|---|
| 265 | 257 | if (ret) |
|---|
| 266 | 258 | return ret; |
|---|
| .. | .. |
|---|
| 270 | 262 | case IIO_CURRENT: |
|---|
| 271 | 263 | switch (mask) { |
|---|
| 272 | 264 | case IIO_CHAN_INFO_RAW: |
|---|
| 265 | + field = afe4403_channel_leds[chan->address]; |
|---|
| 273 | 266 | ret = regmap_field_read(afe->fields[field], val); |
|---|
| 274 | 267 | if (ret) |
|---|
| 275 | 268 | return ret; |
|---|
| .. | .. |
|---|
| 332 | 325 | indio_dev->masklength) { |
|---|
| 333 | 326 | ret = spi_write_then_read(afe->spi, |
|---|
| 334 | 327 | &afe4403_channel_values[bit], 1, |
|---|
| 335 | | - rx, 3); |
|---|
| 328 | + rx, sizeof(rx)); |
|---|
| 336 | 329 | if (ret) |
|---|
| 337 | 330 | goto err; |
|---|
| 338 | 331 | |
|---|
| 339 | | - afe->buffer[i++] = (rx[0] << 16) | |
|---|
| 340 | | - (rx[1] << 8) | |
|---|
| 341 | | - (rx[2]); |
|---|
| 332 | + afe->buffer[i++] = get_unaligned_be24(&rx[0]); |
|---|
| 342 | 333 | } |
|---|
| 343 | 334 | |
|---|
| 344 | 335 | /* Disable reading from the device */ |
|---|
| .. | .. |
|---|
| 522 | 513 | } |
|---|
| 523 | 514 | |
|---|
| 524 | 515 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 525 | | - indio_dev->dev.parent = afe->dev; |
|---|
| 526 | 516 | indio_dev->channels = afe4403_channels; |
|---|
| 527 | 517 | indio_dev->num_channels = ARRAY_SIZE(afe4403_channels); |
|---|
| 528 | 518 | indio_dev->name = AFE4403_DRIVER_NAME; |
|---|