linux/drivers/iio/adc/twl6030-gpadc.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * TWL6030 GPADC module driver
 *
 * Copyright (C) 2009-2013 Texas Instruments Inc.
 * Nishant Kamat <[email protected]>
 * Balaji T K <[email protected]>
 * Graeme Gregory <[email protected]>
 * Girish S Ghongdemath <[email protected]>
 * Ambresh K <[email protected]>
 * Oleksandr Kozaruk <[email protected]
 *
 * Based on twl4030-madc.c
 * Copyright (C) 2008 Nokia Corporation
 * Mikko Ylinen <[email protected]>
 */
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/mfd/twl.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>

#define DRIVER_NAME

/*
 * twl6030 per TRM has 17 channels, and twl6032 has 19 channels
 * 2 test network channels are not used,
 * 2 die temperature channels are not used either, as it is not
 * defined how to convert ADC value to temperature
 */
#define TWL6030_GPADC_USED_CHANNELS
#define TWL6030_GPADC_MAX_CHANNELS
#define TWL6032_GPADC_USED_CHANNELS
#define TWL6032_GPADC_MAX_CHANNELS
#define TWL6030_GPADC_NUM_TRIM_REGS

#define TWL6030_GPADC_CTRL_P1

#define TWL6032_GPADC_GPSELECT_ISB
#define TWL6032_GPADC_CTRL_P1

#define TWL6032_GPADC_GPCH0_LSB
#define TWL6032_GPADC_GPCH0_MSB

#define TWL6030_GPADC_CTRL_P1_SP1

#define TWL6030_GPADC_GPCH0_LSB

#define TWL6030_GPADC_RT_SW1_EOC_MASK

#define TWL6030_GPADC_TRIM1

#define TWL6030_REG_TOGGLE1
#define TWL6030_GPADCS
#define TWL6030_GPADCR

#define USB_VBUS_CTRL_SET
#define USB_ID_CTRL_SET

#define TWL6030_MISC1
#define VBUS_MEAS
#define ID_MEAS

#define VAC_MEAS
#define VBAT_MEAS
#define BB_MEAS


/**
 * struct twl6030_chnl_calib - channel calibration
 * @gain:		slope coefficient for ideal curve
 * @gain_error:		gain error
 * @offset_error:	offset of the real curve
 */
struct twl6030_chnl_calib {};

/**
 * struct twl6030_ideal_code - GPADC calibration parameters
 * GPADC is calibrated in two points: close to the beginning and
 * to the and of the measurable input range
 *
 * @channel:	channel number
 * @code1:	ideal code for the input at the beginning
 * @code2:	ideal code for at the end of the range
 * @volt1:	voltage input at the beginning(low voltage)
 * @volt2:	voltage input at the end(high voltage)
 */
struct twl6030_ideal_code {};

struct twl6030_gpadc_data;

/**
 * struct twl6030_gpadc_platform_data - platform specific data
 * @nchannels:		number of GPADC channels
 * @iio_channels:	iio channels
 * @ideal:		pointer to calibration parameters
 * @start_conversion:	pointer to ADC start conversion function
 * @channel_to_reg:	pointer to ADC function to convert channel to
 *			register address for reading conversion result
 * @calibrate:		pointer to calibration function
 */
struct twl6030_gpadc_platform_data {};

/**
 * struct twl6030_gpadc_data - GPADC data
 * @dev:		device pointer
 * @lock:		mutual exclusion lock for the structure
 * @irq_complete:	completion to signal end of conversion
 * @twl6030_cal_tbl:	pointer to calibration data for each
 *			channel with gain error and offset
 * @pdata:		pointer to device specific data
 */
struct twl6030_gpadc_data {};

/*
 * channels 11, 12, 13, 15 and 16 have no calibration data
 * calibration offset is same for channels 1, 3, 4, 5
 *
 * The data is taken from GPADC_TRIM registers description.
 * GPADC_TRIM registers keep difference between the code measured
 * at volt1 and volt2 input voltages and corresponding code1 and code2
 */
static const struct twl6030_ideal_code
	twl6030_ideal[TWL6030_GPADC_USED_CHANNELS] =;

static const struct twl6030_ideal_code
			twl6032_ideal[TWL6032_GPADC_USED_CHANNELS] =;

static inline int twl6030_gpadc_write(u8 reg, u8 val)
{}

static inline int twl6030_gpadc_read(u8 reg, u8 *val)
{}

static int twl6030_gpadc_enable_irq(u8 mask)
{}

static void twl6030_gpadc_disable_irq(u8 mask)
{}

static irqreturn_t twl6030_gpadc_irq_handler(int irq, void *indio_dev)
{}

static int twl6030_start_conversion(int channel)
{}

static int twl6032_start_conversion(int channel)
{}

static u8 twl6030_channel_to_reg(int channel)
{}

static u8 twl6032_channel_to_reg(int channel)
{}

static int twl6030_gpadc_lookup(const struct twl6030_ideal_code *ideal,
		int channel, int size)
{}

static int twl6030_channel_calibrated(const struct twl6030_gpadc_platform_data
		*pdata, int channel)
{}

static int twl6030_gpadc_make_correction(struct twl6030_gpadc_data *gpadc,
		int channel, int raw_code)
{}

static int twl6030_gpadc_get_raw(struct twl6030_gpadc_data *gpadc,
		int channel, int *res)
{}

static int twl6030_gpadc_get_processed(struct twl6030_gpadc_data *gpadc,
		int channel, int *val)
{}

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

/*
 * The GPADC channels are calibrated using a two point calibration method.
 * The channels measured with two known values: volt1 and volt2, and
 * ideal corresponding output codes are known: code1, code2.
 * The difference(d1, d2) between ideal and measured codes stored in trim
 * registers.
 * The goal is to find offset and gain of the real curve for each calibrated
 * channel.
 * gain: k = 1 + ((d2 - d1) / (x2 - x1))
 * offset: b = d1 + (k - 1) * x1
 */
static void twl6030_calibrate_channel(struct twl6030_gpadc_data *gpadc,
		int channel, int d1, int d2)
{}

static inline int twl6030_gpadc_get_trim_offset(s8 d)
{}

static int twl6030_calibration(struct twl6030_gpadc_data *gpadc)
{}

static int twl6032_get_trim_value(u8 *trim_regs, unsigned int reg0,
		unsigned int reg1, unsigned int mask0, unsigned int mask1,
		unsigned int shift0)
{}

static int twl6032_calibration(struct twl6030_gpadc_data *gpadc)
{}

#define TWL6030_GPADC_CHAN(chn, _type, chan_info)

static const struct iio_chan_spec twl6030_gpadc_iio_channels[] =;

static const struct iio_chan_spec twl6032_gpadc_iio_channels[] =;

static const struct iio_info twl6030_gpadc_iio_info =;

static const struct twl6030_gpadc_platform_data twl6030_pdata =;

static const struct twl6030_gpadc_platform_data twl6032_pdata =;

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

static int twl6030_gpadc_probe(struct platform_device *pdev)
{}

static void twl6030_gpadc_remove(struct platform_device *pdev)
{}

static int twl6030_gpadc_suspend(struct device *pdev)
{
	int ret;

	ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, TWL6030_GPADCR,
				TWL6030_REG_TOGGLE1);
	if (ret)
		dev_err(pdev, "error resetting GPADC (%d)!\n", ret);

	return 0;
};

static int twl6030_gpadc_resume(struct device *pdev)
{
	int ret;

	ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, TWL6030_GPADCS,
				TWL6030_REG_TOGGLE1);
	if (ret)
		dev_err(pdev, "error setting GPADC (%d)!\n", ret);

	return 0;
};

static DEFINE_SIMPLE_DEV_PM_OPS(twl6030_gpadc_pm_ops, twl6030_gpadc_suspend,
				twl6030_gpadc_resume);

static struct platform_driver twl6030_gpadc_driver =;

module_platform_driver();

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