// SPDX-License-Identifier: GPL-2.0-or-later /* * Common library for ADIS16XXX devices * * Copyright 2012 Analog Devices Inc. * Author: Lars-Peter Clausen <[email protected]> */ #include <linux/delay.h> #include <linux/gpio/consumer.h> #include <linux/mutex.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/spi/spi.h> #include <linux/module.h> #include <linux/unaligned.h> #include <linux/iio/iio.h> #include <linux/iio/imu/adis.h> #define ADIS_MSC_CTRL_DATA_RDY_EN … #define ADIS_MSC_CTRL_DATA_RDY_POL_HIGH … #define ADIS_MSC_CTRL_DATA_RDY_DIO2 … #define ADIS_GLOB_CMD_SW_RESET … /** * __adis_write_reg() - write N bytes to register (unlocked version) * @adis: The adis device * @reg: The address of the lower of the two registers * @value: The value to write to device (up to 4 bytes) * @size: The size of the @value (in bytes) */ int __adis_write_reg(struct adis *adis, unsigned int reg, unsigned int value, unsigned int size) { … } EXPORT_SYMBOL_NS_GPL(…); /** * __adis_read_reg() - read N bytes from register (unlocked version) * @adis: The adis device * @reg: The address of the lower of the two registers * @val: The value read back from the device * @size: The size of the @val buffer */ int __adis_read_reg(struct adis *adis, unsigned int reg, unsigned int *val, unsigned int size) { … } EXPORT_SYMBOL_NS_GPL(…); /** * __adis_update_bits_base() - ADIS Update bits function - Unlocked version * @adis: The adis device * @reg: The address of the lower of the two registers * @mask: Bitmask to change * @val: Value to be written * @size: Size of the register to update * * Updates the desired bits of @reg in accordance with @mask and @val. */ int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask, const u32 val, u8 size) { … } EXPORT_SYMBOL_NS_GPL(…); #ifdef CONFIG_DEBUG_FS int adis_debugfs_reg_access(struct iio_dev *indio_dev, unsigned int reg, unsigned int writeval, unsigned int *readval) { … } EXPORT_SYMBOL_NS(…); #endif /** * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked) * @adis: The adis device * @enable: Whether to enable the IRQ * * Returns 0 on success, negative error code otherwise */ int __adis_enable_irq(struct adis *adis, bool enable) { … } EXPORT_SYMBOL_NS(…); /** * __adis_check_status() - Check the device for error conditions (unlocked) * @adis: The adis device * * Returns 0 on success, a negative error code otherwise */ int __adis_check_status(struct adis *adis) { … } EXPORT_SYMBOL_NS_GPL(…); /** * __adis_reset() - Reset the device (unlocked version) * @adis: The adis device * * Returns 0 on success, a negative error code otherwise */ int __adis_reset(struct adis *adis) { … } EXPORT_SYMBOL_NS_GPL(…); static int adis_self_test(struct adis *adis) { … } /** * __adis_initial_startup() - Device initial setup * @adis: The adis device * * The function performs a HW reset via a reset pin that should be specified * via GPIOLIB. If no pin is configured a SW reset will be performed. * The RST pin for the ADIS devices should be configured as ACTIVE_LOW. * * After the self-test operation is performed, the function will also check * that the product ID is as expected. This assumes that drivers providing * 'prod_id_reg' will also provide the 'prod_id'. * * Returns 0 if the device is operational, a negative error code otherwise. * * This function should be called early on in the device initialization sequence * to ensure that the device is in a sane and known state and that it is usable. */ int __adis_initial_startup(struct adis *adis) { … } EXPORT_SYMBOL_NS_GPL(…); /** * adis_single_conversion() - Performs a single sample conversion * @indio_dev: The IIO device * @chan: The IIO channel * @error_mask: Mask for the error bit * @val: Result of the conversion * * Returns IIO_VAL_INT on success, a negative error code otherwise. * * The function performs a single conversion on a given channel and post * processes the value accordingly to the channel spec. If a error_mask is given * the function will check if the mask is set in the returned raw value. If it * is set the function will perform a self-check. If the device does not report * a error bit in the channels raw value set error_mask to 0. */ int adis_single_conversion(struct iio_dev *indio_dev, const struct iio_chan_spec *chan, unsigned int error_mask, int *val) { … } EXPORT_SYMBOL_NS_GPL(…); /** * adis_init() - Initialize adis device structure * @adis: The adis device * @indio_dev: The iio device * @spi: The spi device * @data: Chip specific data * * Returns 0 on success, a negative error code otherwise. * * This function must be called, before any other adis helper function may be * called. */ int adis_init(struct adis *adis, struct iio_dev *indio_dev, struct spi_device *spi, const struct adis_data *data) { … } EXPORT_SYMBOL_NS_GPL(…); MODULE_LICENSE(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …;