linux/drivers/iio/adc/ad7380.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Analog Devices AD738x Simultaneous Sampling SAR ADCs
 *
 * Copyright 2017 Analog Devices Inc.
 * Copyright 2024 BayLibre, SAS
 *
 * Datasheets of supported parts:
 * ad7380/1 : https://www.analog.com/media/en/technical-documentation/data-sheets/AD7380-7381.pdf
 * ad7383/4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-7384.pdf
 * ad7380-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7380-4.pdf
 * ad7381-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7381-4.pdf
 * ad7383/4-4 : https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-4-ad7384-4.pdf
 */

#include <linux/align.h>
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/cleanup.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/spi/spi.h>

#include <linux/iio/buffer.h>
#include <linux/iio/iio.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>

#define MAX_NUM_CHANNELS
/* 2.5V internal reference voltage */
#define AD7380_INTERNAL_REF_MV

/* reading and writing registers is more reliable at lower than max speed */
#define AD7380_REG_WR_SPEED_HZ

#define AD7380_REG_WR
#define AD7380_REG_REGADDR
#define AD7380_REG_DATA

#define AD7380_REG_ADDR_NOP
#define AD7380_REG_ADDR_CONFIG1
#define AD7380_REG_ADDR_CONFIG2
#define AD7380_REG_ADDR_ALERT
#define AD7380_REG_ADDR_ALERT_LOW_TH
#define AD7380_REG_ADDR_ALERT_HIGH_TH

#define AD7380_CONFIG1_OS_MODE
#define AD7380_CONFIG1_OSR
#define AD7380_CONFIG1_CRC_W
#define AD7380_CONFIG1_CRC_R
#define AD7380_CONFIG1_ALERTEN
#define AD7380_CONFIG1_RES
#define AD7380_CONFIG1_REFSEL
#define AD7380_CONFIG1_PMODE

#define AD7380_CONFIG2_SDO2
#define AD7380_CONFIG2_SDO
#define AD7380_CONFIG2_RESET

#define AD7380_CONFIG2_RESET_SOFT
#define AD7380_CONFIG2_RESET_HARD

#define AD7380_ALERT_LOW_TH
#define AD7380_ALERT_HIGH_TH

#define T_CONVERT_NS
#define T_CONVERT_0_NS
#define T_CONVERT_X_NS

struct ad7380_timing_specs {};

struct ad7380_chip_info {};

enum {};

/* Extended scan types for 14-bit chips. */
static const struct iio_scan_type ad7380_scan_type_14[] =;

/* Extended scan types for 16-bit chips. */
static const struct iio_scan_type ad7380_scan_type_16[] =;

#define AD7380_CHANNEL(index, bits, diff)

#define DEFINE_AD7380_2_CHANNEL(name, bits, diff)

#define DEFINE_AD7380_4_CHANNEL(name, bits, diff)

/* fully differential */
DEFINE_AD7380_2_CHANNEL();
DEFINE_AD7380_2_CHANNEL();
DEFINE_AD7380_4_CHANNEL();
DEFINE_AD7380_4_CHANNEL();
/* pseudo differential */
DEFINE_AD7380_2_CHANNEL();
DEFINE_AD7380_2_CHANNEL();
DEFINE_AD7380_4_CHANNEL();
DEFINE_AD7380_4_CHANNEL();

static const char * const ad7380_2_channel_vcm_supplies[] =;

static const char * const ad7380_4_channel_vcm_supplies[] =;

/* Since this is simultaneous sampling, we don't allow individual channels. */
static const unsigned long ad7380_2_channel_scan_masks[] =;

static const unsigned long ad7380_4_channel_scan_masks[] =;

static const struct ad7380_timing_specs ad7380_timing =;

static const struct ad7380_timing_specs ad7380_4_timing =;

/*
 * Available oversampling ratios. The indices correspond with the bit value
 * expected by the chip.  The available ratios depend on the averaging mode,
 * only normal averaging is supported for now.
 */
static const int ad7380_oversampling_ratios[] =;

static const struct ad7380_chip_info ad7380_chip_info =;

static const struct ad7380_chip_info ad7381_chip_info =;

static const struct ad7380_chip_info ad7383_chip_info =;

static const struct ad7380_chip_info ad7384_chip_info =;

static const struct ad7380_chip_info ad7380_4_chip_info =;

static const struct ad7380_chip_info ad7381_4_chip_info =;

static const struct ad7380_chip_info ad7383_4_chip_info =;

static const struct ad7380_chip_info ad7384_4_chip_info =;

struct ad7380_state {};

static int ad7380_regmap_reg_write(void *context, unsigned int reg,
				   unsigned int val)
{}

static int ad7380_regmap_reg_read(void *context, unsigned int reg,
				  unsigned int *val)
{}

static const struct regmap_config ad7380_regmap_config =;

static int ad7380_debugfs_reg_access(struct iio_dev *indio_dev, u32 reg,
				     u32 writeval, u32 *readval)
{}

/**
 * ad7380_update_xfers - update the SPI transfers base on the current scan type
 * @st:		device instance specific state
 * @scan_type:	current scan type
 */
static void ad7380_update_xfers(struct ad7380_state *st,
				const struct iio_scan_type *scan_type)
{}

static int ad7380_triggered_buffer_preenable(struct iio_dev *indio_dev)
{}

static int ad7380_triggered_buffer_postdisable(struct iio_dev *indio_dev)
{}

static const struct iio_buffer_setup_ops ad7380_buffer_setup_ops =;

static irqreturn_t ad7380_trigger_handler(int irq, void *p)
{}

static int ad7380_read_direct(struct ad7380_state *st, unsigned int scan_index,
			      const struct iio_scan_type *scan_type, int *val)
{}

static int ad7380_read_raw(struct iio_dev *indio_dev,
			   struct iio_chan_spec const *chan,
			   int *val, int *val2, long info)
{}

static int ad7380_read_avail(struct iio_dev *indio_dev,
			     struct iio_chan_spec const *chan,
			     const int **vals, int *type, int *length,
			     long mask)
{}

/**
 * ad7380_osr_to_regval - convert ratio to OSR register value
 * @ratio: ratio to check
 *
 * Check if ratio is present in the list of available ratios and return the
 * corresponding value that needs to be written to the register to select that
 * ratio.
 *
 * Returns: register value (0 to 7) or -EINVAL if there is not an exact match
 */
static int ad7380_osr_to_regval(int ratio)
{}

static int ad7380_write_raw(struct iio_dev *indio_dev,
			    struct iio_chan_spec const *chan, int val,
			    int val2, long mask)
{}

static int ad7380_get_current_scan_type(const struct iio_dev *indio_dev,
					const struct iio_chan_spec *chan)
{}

static const struct iio_info ad7380_info =;

static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
{}

static void ad7380_regulator_disable(void *p)
{}

static int ad7380_probe(struct spi_device *spi)
{}

static const struct of_device_id ad7380_of_match_table[] =;

static const struct spi_device_id ad7380_id_table[] =;
MODULE_DEVICE_TABLE(spi, ad7380_id_table);

static struct spi_driver ad7380_driver =;
module_spi_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();