linux/drivers/iio/adc/ad7280a.c

// SPDX-License-Identifier: GPL-2.0
/*
 * AD7280A Lithium Ion Battery Monitoring System
 *
 * Copyright 2011 Analog Devices Inc.
 */

#include <linux/bitfield.h>
#include <linux/bits.h>
#include <linux/cleanup.h>
#include <linux/crc8.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/spi/spi.h>

#include <linux/iio/events.h>
#include <linux/iio/iio.h>

/* Registers */

#define AD7280A_CELL_VOLTAGE_1_REG
#define AD7280A_CELL_VOLTAGE_2_REG
#define AD7280A_CELL_VOLTAGE_3_REG
#define AD7280A_CELL_VOLTAGE_4_REG
#define AD7280A_CELL_VOLTAGE_5_REG
#define AD7280A_CELL_VOLTAGE_6_REG
#define AD7280A_AUX_ADC_1_REG
#define AD7280A_AUX_ADC_2_REG
#define AD7280A_AUX_ADC_3_REG
#define AD7280A_AUX_ADC_4_REG
#define AD7280A_AUX_ADC_5_REG
#define AD7280A_AUX_ADC_6_REG
#define AD7280A_SELF_TEST_REG

#define AD7280A_CTRL_HB_REG
#define AD7280A_CTRL_HB_CONV_INPUT_MSK
#define AD7280A_CTRL_HB_CONV_INPUT_ALL
#define AD7280A_CTRL_HB_CONV_INPUT_6CELL_AUX1_3_5
#define AD7280A_CTRL_HB_CONV_INPUT_6CELL
#define AD7280A_CTRL_HB_CONV_INPUT_SELF_TEST
#define AD7280A_CTRL_HB_CONV_RREAD_MSK
#define AD7280A_CTRL_HB_CONV_RREAD_ALL
#define AD7280A_CTRL_HB_CONV_RREAD_6CELL_AUX1_3_5
#define AD7280A_CTRL_HB_CONV_RREAD_6CELL
#define AD7280A_CTRL_HB_CONV_RREAD_NO
#define AD7280A_CTRL_HB_CONV_START_MSK
#define AD7280A_CTRL_HB_CONV_START_CNVST
#define AD7280A_CTRL_HB_CONV_START_CS
#define AD7280A_CTRL_HB_CONV_AVG_MSK
#define AD7280A_CTRL_HB_CONV_AVG_DIS
#define AD7280A_CTRL_HB_CONV_AVG_2
#define AD7280A_CTRL_HB_CONV_AVG_4
#define AD7280A_CTRL_HB_CONV_AVG_8
#define AD7280A_CTRL_HB_PWRDN_SW

#define AD7280A_CTRL_LB_REG
#define AD7280A_CTRL_LB_SWRST_MSK
#define AD7280A_CTRL_LB_ACQ_TIME_MSK
#define AD7280A_CTRL_LB_ACQ_TIME_400ns
#define AD7280A_CTRL_LB_ACQ_TIME_800ns
#define AD7280A_CTRL_LB_ACQ_TIME_1200ns
#define AD7280A_CTRL_LB_ACQ_TIME_1600ns
#define AD7280A_CTRL_LB_MUST_SET
#define AD7280A_CTRL_LB_THERMISTOR_MSK
#define AD7280A_CTRL_LB_LOCK_DEV_ADDR_MSK
#define AD7280A_CTRL_LB_INC_DEV_ADDR_MSK
#define AD7280A_CTRL_LB_DAISY_CHAIN_RB_MSK

#define AD7280A_CELL_OVERVOLTAGE_REG
#define AD7280A_CELL_UNDERVOLTAGE_REG
#define AD7280A_AUX_ADC_OVERVOLTAGE_REG
#define AD7280A_AUX_ADC_UNDERVOLTAGE_REG

#define AD7280A_ALERT_REG
#define AD7280A_ALERT_REMOVE_MSK
#define AD7280A_ALERT_REMOVE_AUX5
#define AD7280A_ALERT_REMOVE_AUX3_AUX5
#define AD7280A_ALERT_REMOVE_VIN5
#define AD7280A_ALERT_REMOVE_VIN4_VIN5
#define AD7280A_ALERT_GEN_STATIC_HIGH
#define AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN

#define AD7280A_CELL_BALANCE_REG
#define AD7280A_CELL_BALANCE_CHAN_BITMAP_MSK
#define AD7280A_CB1_TIMER_REG
#define AD7280A_CB_TIMER_VAL_MSK
#define AD7280A_CB2_TIMER_REG
#define AD7280A_CB3_TIMER_REG
#define AD7280A_CB4_TIMER_REG
#define AD7280A_CB5_TIMER_REG
#define AD7280A_CB6_TIMER_REG
#define AD7280A_PD_TIMER_REG
#define AD7280A_READ_REG
#define AD7280A_READ_ADDR_MSK
#define AD7280A_CNVST_CTRL_REG

/* Transfer fields */
#define AD7280A_TRANS_WRITE_DEVADDR_MSK
#define AD7280A_TRANS_WRITE_ADDR_MSK
#define AD7280A_TRANS_WRITE_VAL_MSK
#define AD7280A_TRANS_WRITE_ALL_MSK
#define AD7280A_TRANS_WRITE_CRC_MSK
#define AD7280A_TRANS_WRITE_RES_PATTERN

/* Layouts differ for channel vs other registers */
#define AD7280A_TRANS_READ_DEVADDR_MSK
#define AD7280A_TRANS_READ_CONV_CHANADDR_MSK
#define AD7280A_TRANS_READ_CONV_DATA_MSK
#define AD7280A_TRANS_READ_REG_REGADDR_MSK
#define AD7280A_TRANS_READ_REG_DATA_MSK
#define AD7280A_TRANS_READ_WRITE_ACK_MSK
#define AD7280A_TRANS_READ_CRC_MSK

/* Magic value used to indicate this special case */
#define AD7280A_ALL_CELLS

#define AD7280A_MAX_SPI_CLK_HZ
#define AD7280A_MAX_CHAIN
#define AD7280A_CELLS_PER_DEV
#define AD7280A_BITS
#define AD7280A_NUM_CH

#define AD7280A_CALC_VOLTAGE_CHAN_NUM(d, c)
#define AD7280A_CALC_TEMP_CHAN_NUM(d, c)

#define AD7280A_DEVADDR_MASTER
#define AD7280A_DEVADDR_ALL

static const unsigned short ad7280a_n_avg[4] =;
static const unsigned short ad7280a_t_acq_ns[4] =;

/* 5-bit device address is sent LSB first */
static unsigned int ad7280a_devaddr(unsigned int addr)
{}

/*
 * During a read a valid write is mandatory.
 * So writing to the highest available address (Address 0x1F) and setting the
 * address all parts bit to 0 is recommended.
 * So the TXVAL is AD7280A_DEVADDR_ALL + CRC
 */
#define AD7280A_READ_TXVAL

/*
 * AD7280 CRC
 *
 * P(x) = x^8 + x^5 + x^3 + x^2 + x^1 + x^0 = 0b100101111 => 0x2F
 */
#define POLYNOM

struct ad7280_state {};

static unsigned char ad7280_calc_crc8(unsigned char *crc_tab, unsigned int val)
{}

static int ad7280_check_crc(struct ad7280_state *st, unsigned int val)
{}

/*
 * After initiating a conversion sequence we need to wait until the conversion
 * is done. The delay is typically in the range of 15..30us however depending on
 * the number of devices in the daisy chain, the number of averages taken,
 * conversion delays and acquisition time options it may take up to 250us, in
 * this case we better sleep instead of busy wait.
 */

static void ad7280_delay(struct ad7280_state *st)
{}

static int __ad7280_read32(struct ad7280_state *st, unsigned int *val)
{}

static int ad7280_write(struct ad7280_state *st, unsigned int devaddr,
			unsigned int addr, bool all, unsigned int val)
{}

static int ad7280_read_reg(struct ad7280_state *st, unsigned int devaddr,
			   unsigned int addr)
{}

static int ad7280_read_channel(struct ad7280_state *st, unsigned int devaddr,
			       unsigned int addr)
{}

static int ad7280_read_all_channels(struct ad7280_state *st, unsigned int cnt,
				    unsigned int *array)
{}

static void ad7280_sw_power_down(void *data)
{}

static int ad7280_chain_setup(struct ad7280_state *st)
{}

static ssize_t ad7280_show_balance_sw(struct iio_dev *indio_dev,
				      uintptr_t private,
				      const struct iio_chan_spec *chan, char *buf)
{}

static ssize_t ad7280_store_balance_sw(struct iio_dev *indio_dev,
				       uintptr_t private,
				       const struct iio_chan_spec *chan,
				       const char *buf, size_t len)
{}

static ssize_t ad7280_show_balance_timer(struct iio_dev *indio_dev,
					 uintptr_t private,
					 const struct iio_chan_spec *chan,
					 char *buf)
{}

static ssize_t ad7280_store_balance_timer(struct iio_dev *indio_dev,
					  uintptr_t private,
					  const struct iio_chan_spec *chan,
					  const char *buf, size_t len)
{}

static const struct iio_chan_spec_ext_info ad7280_cell_ext_info[] =;

static const struct iio_event_spec ad7280_events[] =;

static void ad7280_voltage_channel_init(struct iio_chan_spec *chan, int i,
					bool irq_present)
{}

static void ad7280_temp_channel_init(struct iio_chan_spec *chan, int i,
				     bool irq_present)
{}

static void ad7280_common_fields_init(struct iio_chan_spec *chan, int addr,
				      int cnt)
{}

static void ad7280_total_voltage_channel_init(struct iio_chan_spec *chan,
					      int cnt, int dev)
{}

static void ad7280_init_dev_channels(struct ad7280_state *st, int dev, int *cnt,
				     bool irq_present)
{}

static int ad7280_channel_init(struct ad7280_state *st, bool irq_present)
{}

static int ad7280a_read_thresh(struct iio_dev *indio_dev,
			       const struct iio_chan_spec *chan,
			       enum iio_event_type type,
			       enum iio_event_direction dir,
			       enum iio_event_info info, int *val, int *val2)
{}

static int ad7280a_write_thresh(struct iio_dev *indio_dev,
				const struct iio_chan_spec *chan,
				enum iio_event_type type,
				enum iio_event_direction dir,
				enum iio_event_info info,
				int val, int val2)
{}

static irqreturn_t ad7280_event_handler(int irq, void *private)
{}

static void ad7280_update_delay(struct ad7280_state *st)
{}

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

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

static const struct iio_info ad7280_info =;

static const struct iio_info ad7280_info_no_irq =;

static int ad7280_probe(struct spi_device *spi)
{}

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

static struct spi_driver ad7280_driver =;
module_spi_driver();

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