Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADIS16550 #2510

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions Documentation/devicetree/bindings/iio/imu/adi,adis16550.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/iio/imu/adi,adis16550.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Analog Devices ADIS16550 and similar IMUs

maintainers:
- Nuno Sa <[email protected]>
- Ramona Gradinariu <[email protected]>
- Antoniu Miclaus <[email protected]>

properties:
compatible:
enum:
- adi,adis16550
- adi,adis16550w

reg:
maxItems: 1

spi-cpha: true

spi-cpol: true

spi-max-frequency:
maximum: 15000000

vdd-supply: true

interrupts:
maxItems: 1

reset-gpios:
description:
Must be the device tree identifier of the RESET pin. If specified,
it will be asserted during driver probe. As the line is active low,
it should be marked GPIO_ACTIVE_LOW.
maxItems: 1

clocks:
maxItems: 1
description: If not provided, then the internal clock is used.

adi,sync-mode:
$ref: /schemas/types.yaml#/definitions/string
description: |
Configures the device SYNC pin.
enum:
- direct_sync
- scaled_sync

required:
- compatible
- reg
- interrupts
- spi-cpha
- spi-cpol
- spi-max-frequency
- vdd-supply

allOf:
- if:
properties:
adi,sync-mode:
enum: [direct_sync, scaled_sync]

then:
dependencies:
adi,sync-mode: [ clocks ]

- $ref: /schemas/spi/spi-peripheral-props.yaml#

additionalProperties: false

examples:
- |
#include <dt-bindings/interrupt-controller/irq.h>
spi {
#address-cells = <1>;
#size-cells = <0>;

imu@0 {
compatible = "adi,adis16550";
reg = <0>;
spi-max-frequency = <15000000>;
spi-cpol;
spi-cpha;
vdd-supply = <&vdd>;
interrupts = <4 IRQ_TYPE_EDGE_FALLING>;
interrupt-parent = <&gpio>;
};
};
...
389 changes: 389 additions & 0 deletions Documentation/iio/adis16550.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Documentation/iio/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Industrial I/O Kernel Drivers

adis16475
adis16480
adis16550
adxl380
bno055
ep93xx_adc
10 changes: 10 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,16 @@ S: Supported
F: drivers/iio/imu/adis16475.c
F: Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml

ANALOG DEVICES INC ADIS16550 DRIVER
M: Nuno Sa <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I'm here, I should likely be also in the bindings patch

M: Ramona Gradinariu <[email protected]>
M: Antoniu Miclaus <[email protected]>
L: [email protected]
S: Supported
W: https://ez.analog.com/linux-software-drivers
F: Documentation/devicetree/bindings/iio/imu/adi,adis16550.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is introduced in the bindings patch. Hence, the entry should be introduced in that patch...

F: drivers/iio/imu/adis16550.c

ANALOG DEVICES INC ADM1177 DRIVER
M: Michael Hennerich <[email protected]>
L: [email protected]
Expand Down
1 change: 1 addition & 0 deletions drivers/iio/Kconfig.adi
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ config IIO_ALL_ADI_DRIVERS
imply ADIS16460
imply ADIS16475
imply ADIS16480
imply ADIS16550
imply M2K_LOGIC_ANALYZER
imply AD5272
imply IIO_REGMAP_I2C
Expand Down
13 changes: 13 additions & 0 deletions drivers/iio/imu/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ config ADIS16480
Say yes here to build support for Analog Devices ADIS16375, ADIS16480,
ADIS16485, ADIS16488 inertial sensors.

config ADIS16550
tristate "Analog Devices ADIS16550 and similar IMU driver"
depends on SPI
select IIO_ADIS_LIB
select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
select CRC32
help
Say yes here to build support for Analog Devices ADIS16550 inertial
sensor.

To compile this driver as a module, choose M here: the module will be
called adis16550.

source "drivers/iio/imu/bmi160/Kconfig"
source "drivers/iio/imu/bno055/Kconfig"

Expand Down
1 change: 1 addition & 0 deletions drivers/iio/imu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ obj-$(CONFIG_ADIS16400) += adis16400.o
obj-$(CONFIG_ADIS16460) += adis16460.o
obj-$(CONFIG_ADIS16475) += adis16475.o
obj-$(CONFIG_ADIS16480) += adis16480.o
obj-$(CONFIG_ADIS16550) += adis16550.o

adis_lib-y += adis.o
adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o
Expand Down
33 changes: 25 additions & 8 deletions drivers/iio/imu/adis.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask,
int ret;
u32 __val;

ret = __adis_read_reg(adis, reg, &__val, size);
ret = adis->ops->read(adis, reg, &__val, size);
if (ret)
return ret;

__val = (__val & ~mask) | (val & mask);

return __adis_write_reg(adis, reg, __val, size);
return adis->ops->write(adis, reg, __val, size);
}
EXPORT_SYMBOL_NS_GPL(__adis_update_bits_base, IIO_ADISLIB);

Expand Down Expand Up @@ -304,11 +304,17 @@ EXPORT_SYMBOL_NS(__adis_enable_irq, IIO_ADISLIB);
*/
int __adis_check_status(struct adis *adis)
{
u16 status;
unsigned int status = 0;
int ret;
int i;
/* default to 2 bytes */
unsigned int reg_size = 2;

ret = __adis_read_reg_16(adis, adis->data->diag_stat_reg, &status);
if (adis->data->diag_stat_size)
reg_size = adis->data->diag_stat_size;

ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status,
reg_size);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the above call should likely be in patch 1?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in patch 1 there is already an update of __adis_read_reg_16 using the ops structure (adis->ops->write(adis, reg, val, 2);). This call was added like this ret = adis->ops->read(adis, adis->data->diag_stat_reg, &status, reg_size); only because the reg_size is variable now.

if (ret)
return ret;

Expand All @@ -317,7 +323,7 @@ int __adis_check_status(struct adis *adis)
if (status == 0)
return 0;

for (i = 0; i < 16; ++i) {
for (i = 0; i < (reg_size * 8); ++i) {
if (status & BIT(i)) {
dev_err(&adis->spi->dev, "%s.\n",
adis->data->status_error_msgs[i]);
Expand All @@ -339,8 +345,11 @@ int __adis_reset(struct adis *adis)
int ret;
const struct adis_timeout *timeouts = adis->data->timeouts;

ret = __adis_write_reg_8(adis, adis->data->glob_cmd_reg,
ADIS_GLOB_CMD_SW_RESET);
if (adis->ops->reset)
ret = adis->ops->reset(adis);
else
ret = __adis_write_reg_8(adis, adis->data->glob_cmd_reg,
ADIS_GLOB_CMD_SW_RESET);
if (ret) {
dev_err(&adis->spi->dev, "Failed to reset device: %d\n", ret);
return ret;
Expand Down Expand Up @@ -468,7 +477,7 @@ int adis_single_conversion(struct iio_dev *indio_dev,

mutex_lock(&adis->state_lock);

ret = __adis_read_reg(adis, chan->address, &uval,
ret = adis->ops->read(adis, chan->address, &uval,
chan->scan_type.storagebits / 8);
if (ret)
goto err_unlock;
Expand All @@ -491,6 +500,11 @@ int adis_single_conversion(struct iio_dev *indio_dev,
}
EXPORT_SYMBOL_NS_GPL(adis_single_conversion, IIO_ADISLIB);

static const struct adis_ops adis_default_ops = {
.read = __adis_read_reg,
.write = __adis_write_reg,
};

/**
* adis_init() - Initialize adis device structure
* @adis: The adis device
Expand Down Expand Up @@ -520,6 +534,9 @@ int adis_init(struct adis *adis, struct iio_dev *indio_dev,

adis->spi = spi;
adis->data = data;
if (!adis->ops->write || !adis->ops->read)
adis->ops = &adis_default_ops;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are assuming we always have write() and read() we should sanity check it here (for ops given by drivers).


iio_device_set_drvdata(indio_dev, adis);

if (data->has_paging) {
Expand Down
Loading