linux/drivers/iio/adc/sc27xx_adc.c

// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2018 Spreadtrum Communications Inc.

#include <linux/hwspinlock.h>
#include <linux/iio/iio.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/nvmem-consumer.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>

/* PMIC global registers definition */
#define SC2730_MODULE_EN
#define SC2731_MODULE_EN
#define SC27XX_MODULE_ADC_EN
#define SC2721_ARM_CLK_EN
#define SC2730_ARM_CLK_EN
#define SC2731_ARM_CLK_EN
#define SC27XX_CLK_ADC_EN
#define SC27XX_CLK_ADC_CLK_EN

/* ADC controller registers definition */
#define SC27XX_ADC_CTL
#define SC27XX_ADC_CH_CFG
#define SC27XX_ADC_DATA
#define SC27XX_ADC_INT_EN
#define SC27XX_ADC_INT_CLR
#define SC27XX_ADC_INT_STS
#define SC27XX_ADC_INT_RAW

/* Bits and mask definition for SC27XX_ADC_CTL register */
#define SC27XX_ADC_EN
#define SC27XX_ADC_CHN_RUN
#define SC27XX_ADC_12BIT_MODE
#define SC27XX_ADC_RUN_NUM_MASK
#define SC27XX_ADC_RUN_NUM_SHIFT

/* Bits and mask definition for SC27XX_ADC_CH_CFG register */
#define SC27XX_ADC_CHN_ID_MASK
#define SC27XX_ADC_SCALE_MASK
#define SC2721_ADC_SCALE_MASK
#define SC27XX_ADC_SCALE_SHIFT
#define SC2721_ADC_SCALE_SHIFT

/* Bits definitions for SC27XX_ADC_INT_EN registers */
#define SC27XX_ADC_IRQ_EN

/* Bits definitions for SC27XX_ADC_INT_CLR registers */
#define SC27XX_ADC_IRQ_CLR

/* Bits definitions for SC27XX_ADC_INT_RAW registers */
#define SC27XX_ADC_IRQ_RAW

/* Mask definition for SC27XX_ADC_DATA register */
#define SC27XX_ADC_DATA_MASK

/* Timeout (ms) for the trylock of hardware spinlocks */
#define SC27XX_ADC_HWLOCK_TIMEOUT

/* Timeout (us) for ADC data conversion according to ADC datasheet */
#define SC27XX_ADC_RDY_TIMEOUT
#define SC27XX_ADC_POLL_RAW_STATUS

/* Maximum ADC channel number */
#define SC27XX_ADC_CHANNEL_MAX

/* ADC voltage ratio definition */
#define SC27XX_VOLT_RATIO(n, d)
#define SC27XX_RATIO_NUMERATOR_OFFSET
#define SC27XX_RATIO_DENOMINATOR_MASK

/* ADC specific channel reference voltage 3.5V */
#define SC27XX_ADC_REFVOL_VDD35

/* ADC default channel reference voltage is 2.8V */
#define SC27XX_ADC_REFVOL_VDD28

struct sc27xx_adc_data {};

/*
 * Since different PMICs of SC27xx series can have different
 * address and ratio, we should save ratio config and base
 * in the device data structure.
 */
struct sc27xx_adc_variant_data {};

struct sc27xx_adc_linear_graph {};

/*
 * According to the datasheet, we can convert one ADC value to one voltage value
 * through 2 points in the linear graph. If the voltage is less than 1.2v, we
 * should use the small-scale graph, and if more than 1.2v, we should use the
 * big-scale graph.
 */
static struct sc27xx_adc_linear_graph big_scale_graph =;

static struct sc27xx_adc_linear_graph small_scale_graph =;

static const struct sc27xx_adc_linear_graph sc2731_big_scale_graph_calib =;

static const struct sc27xx_adc_linear_graph sc2731_small_scale_graph_calib =;

static const struct sc27xx_adc_linear_graph big_scale_graph_calib =;

static const struct sc27xx_adc_linear_graph small_scale_graph_calib =;

static int sc27xx_adc_get_calib_data(u32 calib_data, int calib_adc)
{}

/* get the adc nvmem cell calibration data */
static int adc_nvmem_cell_calib_data(struct sc27xx_adc_data *data, const char *cell_name)
{}

static int sc27xx_adc_scale_calibration(struct sc27xx_adc_data *data,
					bool big_scale)
{}

static int sc2720_adc_get_ratio(int channel, int scale)
{}

static int sc2721_adc_get_ratio(int channel, int scale)
{}

static int sc2730_adc_get_ratio(int channel, int scale)
{}

static int sc2731_adc_get_ratio(int channel, int scale)
{}

/*
 * According to the datasheet set specific value on some channel.
 */
static void sc2720_adc_scale_init(struct sc27xx_adc_data *data)
{}

static void sc2730_adc_scale_init(struct sc27xx_adc_data *data)
{}

static void sc2731_adc_scale_init(struct sc27xx_adc_data *data)
{}

static int sc27xx_adc_read(struct sc27xx_adc_data *data, int channel,
			   int scale, int *val)
{}

static void sc27xx_adc_volt_ratio(struct sc27xx_adc_data *data, int channel, int scale,
				  struct u32_fract *fract)
{}

static int adc_to_volt(struct sc27xx_adc_linear_graph *graph,
			      int raw_adc)
{}

static int sc27xx_adc_to_volt(struct sc27xx_adc_linear_graph *graph,
			      int raw_adc)
{}

static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
				   int scale, int raw_adc)
{}

static int sc27xx_adc_read_processed(struct sc27xx_adc_data *data,
				     int channel, int scale, int *val)
{}

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

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

static const struct iio_info sc27xx_info =;

#define SC27XX_ADC_CHANNEL(index, mask)

static const struct iio_chan_spec sc27xx_channels[] =;

static int sc27xx_adc_enable(struct sc27xx_adc_data *data)
{}

static void sc27xx_adc_disable(void *_data)
{}

static const struct sc27xx_adc_variant_data sc2731_data =;

static const struct sc27xx_adc_variant_data sc2730_data =;

static const struct sc27xx_adc_variant_data sc2721_data =;

static const struct sc27xx_adc_variant_data sc2720_data =;

static int sc27xx_adc_probe(struct platform_device *pdev)
{}

static const struct of_device_id sc27xx_adc_of_match[] =;
MODULE_DEVICE_TABLE(of, sc27xx_adc_of_match);

static struct platform_driver sc27xx_adc_driver =;

module_platform_driver();

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