linux/drivers/iio/adc/cpcap-adc.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) 2017 Tony Lindgren <[email protected]>
 *
 * Rewritten for Linux IIO framework with some code based on
 * earlier driver found in the Motorola Linux kernel:
 *
 * Copyright (C) 2009-2010 Motorola, Inc.
 */

#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/regmap.h>

#include <linux/iio/buffer.h>
#include <linux/iio/driver.h>
#include <linux/iio/iio.h>
#include <linux/iio/kfifo_buf.h>
#include <linux/mfd/motorola-cpcap.h>

/* Register CPCAP_REG_ADCC1 bits */
#define CPCAP_BIT_ADEN_AUTO_CLR
#define CPCAP_BIT_CAL_MODE
#define CPCAP_BIT_ADC_CLK_SEL1
#define CPCAP_BIT_ADC_CLK_SEL0
#define CPCAP_BIT_ATOX
#define CPCAP_BIT_ATO3
#define CPCAP_BIT_ATO2
#define CPCAP_BIT_ATO1
#define CPCAP_BIT_ATO0
#define CPCAP_BIT_ADA2
#define CPCAP_BIT_ADA1
#define CPCAP_BIT_ADA0
#define CPCAP_BIT_AD_SEL1
#define CPCAP_BIT_RAND1
#define CPCAP_BIT_RAND0
#define CPCAP_BIT_ADEN

#define CPCAP_REG_ADCC1_DEFAULTS

/* Register CPCAP_REG_ADCC2 bits */
#define CPCAP_BIT_CAL_FACTOR_ENABLE
#define CPCAP_BIT_BATDETB_EN
#define CPCAP_BIT_ADTRIG_ONESHOT
#define CPCAP_BIT_ASC
#define CPCAP_BIT_ATOX_PS_FACTOR
#define CPCAP_BIT_ADC_PS_FACTOR1
#define CPCAP_BIT_ADC_PS_FACTOR0
#define CPCAP_BIT_AD4_SELECT
#define CPCAP_BIT_ADC_BUSY
#define CPCAP_BIT_THERMBIAS_EN
#define CPCAP_BIT_ADTRIG_DIS
#define CPCAP_BIT_LIADC
#define CPCAP_BIT_TS_REFEN
#define CPCAP_BIT_TS_M2
#define CPCAP_BIT_TS_M1
#define CPCAP_BIT_TS_M0

#define CPCAP_REG_ADCC2_DEFAULTS

#define CPCAP_MAX_TEMP_LVL
#define CPCAP_FOUR_POINT_TWO_ADC
#define ST_ADC_CAL_CHRGI_HIGH_THRESHOLD
#define ST_ADC_CAL_CHRGI_LOW_THRESHOLD
#define ST_ADC_CAL_BATTI_HIGH_THRESHOLD
#define ST_ADC_CAL_BATTI_LOW_THRESHOLD
#define ST_ADC_CALIBRATE_DIFF_THRESHOLD

#define CPCAP_ADC_MAX_RETRIES

/*
 * struct cpcap_adc_ato - timing settings for cpcap adc
 *
 * Unfortunately no cpcap documentation available, please document when
 * using these.
 */
struct cpcap_adc_ato {};

/**
 * struct cpcap_adc - cpcap adc device driver data
 * @reg: cpcap regmap
 * @dev: struct device
 * @vendor: cpcap vendor
 * @irq: interrupt
 * @lock: mutex
 * @ato: request timings
 * @wq_data_avail: work queue
 * @done: work done
 */
struct cpcap_adc {};

/*
 * enum cpcap_adc_channel - cpcap adc channels
 */
enum cpcap_adc_channel {};

/*
 * enum cpcap_adc_timing - cpcap adc timing options
 *
 * CPCAP_ADC_TIMING_IMM seems to be immediate with no timings.
 * Please document when using.
 */
enum cpcap_adc_timing {};

/**
 * struct cpcap_adc_phasing_tbl - cpcap phasing table
 * @offset: offset in the phasing table
 * @multiplier: multiplier in the phasing table
 * @divider: divider in the phasing table
 * @min: minimum value
 * @max: maximum value
 */
struct cpcap_adc_phasing_tbl {};

/**
 * struct cpcap_adc_conversion_tbl - cpcap conversion table
 * @conv_type: conversion type
 * @align_offset: align offset
 * @conv_offset: conversion offset
 * @cal_offset: calibration offset
 * @multiplier: conversion multiplier
 * @divider: conversion divider
 */
struct cpcap_adc_conversion_tbl {};

/**
 * struct cpcap_adc_request - cpcap adc request
 * @channel: request channel
 * @phase_tbl: channel phasing table
 * @conv_tbl: channel conversion table
 * @bank_index: channel index within the bank
 * @timing: timing settings
 * @result: result
 */
struct cpcap_adc_request {};

/* Phasing table for channels. Note that channels 16 & 17 use BATTP and BATTI */
static const struct cpcap_adc_phasing_tbl bank_phasing[] =;

/*
 * Conversion table for channels. Updated during init based on calibration.
 * Here too channels 16 & 17 use BATTP and BATTI.
 */
static struct cpcap_adc_conversion_tbl bank_conversion[] =;

/*
 * Temperature lookup table of register values to milliCelcius.
 * REVISIT: Check the duplicate 0x3ff entry in a freezer
 */
static const int temp_map[CPCAP_MAX_TEMP_LVL][2] =;

#define CPCAP_CHAN(_type, _index, _address, _datasheet_name)

/*
 * The datasheet names are from Motorola mapphone Linux kernel except
 * for the last two which might be uncalibrated charge voltage and
 * current.
 */
static const struct iio_chan_spec cpcap_adc_channels[] =;

static irqreturn_t cpcap_adc_irq_thread(int irq, void *data)
{}

/* ADC calibration functions */
static void cpcap_adc_setup_calibrate(struct cpcap_adc *ddata,
				      enum cpcap_adc_channel chan)
{}

static int cpcap_adc_calibrate_one(struct cpcap_adc *ddata,
				   int channel,
				   u16 calibration_register,
				   int lower_threshold,
				   int upper_threshold)
{}

static int cpcap_adc_calibrate(struct cpcap_adc *ddata)
{}

/* ADC setup, read and scale functions */
static void cpcap_adc_setup_bank(struct cpcap_adc *ddata,
				 struct cpcap_adc_request *req)
{}

static int cpcap_adc_start_bank(struct cpcap_adc *ddata,
				struct cpcap_adc_request *req)
{}

static int cpcap_adc_stop_bank(struct cpcap_adc *ddata)
{}

static void cpcap_adc_phase(struct cpcap_adc_request *req)
{}

/* Looks up temperatures in a table and calculates averages if needed */
static int cpcap_adc_table_to_millicelcius(unsigned short value)
{}

static void cpcap_adc_convert(struct cpcap_adc_request *req)
{}

/*
 * REVISIT: Check if timed sampling can use multiple channels at the
 * same time. If not, replace channel_mask with just channel.
 */
static int cpcap_adc_read_bank_scaled(struct cpcap_adc *ddata,
				      struct cpcap_adc_request *req)
{}

static int cpcap_adc_init_request(struct cpcap_adc_request *req,
				  int channel)
{}

static int cpcap_adc_read_st_die_temp(struct cpcap_adc *ddata,
				      int addr, int *val)
{}

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

static const struct iio_info cpcap_adc_info =;

/*
 * Configuration for Motorola mapphone series such as droid 4.
 * Copied from the Motorola mapphone kernel tree.
 */
static const struct cpcap_adc_ato mapphone_adc =;

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

static int cpcap_adc_probe(struct platform_device *pdev)
{}

static struct platform_driver cpcap_adc_driver =;

module_platform_driver();

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