linux/drivers/power/supply/sc27xx_fuel_gauge.c

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

#include <linux/gpio/consumer.h>
#include <linux/iio/consumer.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/math64.h>
#include <linux/module.h>
#include <linux/nvmem-consumer.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/regmap.h>
#include <linux/slab.h>

/* PMIC global control registers definition */
#define SC27XX_MODULE_EN0
#define SC27XX_CLK_EN0
#define SC27XX_FGU_EN
#define SC27XX_FGU_RTC_EN

/* FGU registers definition */
#define SC27XX_FGU_START
#define SC27XX_FGU_CONFIG
#define SC27XX_FGU_ADC_CONFIG
#define SC27XX_FGU_STATUS
#define SC27XX_FGU_INT_EN
#define SC27XX_FGU_INT_CLR
#define SC27XX_FGU_INT_STS
#define SC27XX_FGU_VOLTAGE
#define SC27XX_FGU_OCV
#define SC27XX_FGU_POCV
#define SC27XX_FGU_CURRENT
#define SC27XX_FGU_LOW_OVERLOAD
#define SC27XX_FGU_CLBCNT_SETH
#define SC27XX_FGU_CLBCNT_SETL
#define SC27XX_FGU_CLBCNT_DELTH
#define SC27XX_FGU_CLBCNT_DELTL
#define SC27XX_FGU_CLBCNT_VALH
#define SC27XX_FGU_CLBCNT_VALL
#define SC27XX_FGU_CLBCNT_QMAXL
#define SC27XX_FGU_USER_AREA_SET
#define SC27XX_FGU_USER_AREA_CLEAR
#define SC27XX_FGU_USER_AREA_STATUS
#define SC27XX_FGU_VOLTAGE_BUF
#define SC27XX_FGU_CURRENT_BUF

#define SC27XX_WRITE_SELCLB_EN
#define SC27XX_FGU_CLBCNT_MASK
#define SC27XX_FGU_CLBCNT_SHIFT
#define SC27XX_FGU_LOW_OVERLOAD_MASK

#define SC27XX_FGU_INT_MASK
#define SC27XX_FGU_LOW_OVERLOAD_INT
#define SC27XX_FGU_CLBCNT_DELTA_INT

#define SC27XX_FGU_MODE_AREA_MASK
#define SC27XX_FGU_CAP_AREA_MASK
#define SC27XX_FGU_MODE_AREA_SHIFT

#define SC27XX_FGU_FIRST_POWERTON
#define SC27XX_FGU_DEFAULT_CAP
#define SC27XX_FGU_NORMAIL_POWERTON

#define SC27XX_FGU_CUR_BASIC_ADC
#define SC27XX_FGU_SAMPLE_HZ
/* micro Ohms */
#define SC27XX_FGU_IDEAL_RESISTANCE

/*
 * struct sc27xx_fgu_data: describe the FGU device
 * @regmap: regmap for register access
 * @dev: platform device
 * @battery: battery power supply
 * @base: the base offset for the controller
 * @lock: protect the structure
 * @gpiod: GPIO for battery detection
 * @channel: IIO channel to get battery temperature
 * @charge_chan: IIO channel to get charge voltage
 * @internal_resist: the battery internal resistance in mOhm
 * @total_cap: the total capacity of the battery in mAh
 * @init_cap: the initial capacity of the battery in mAh
 * @alarm_cap: the alarm capacity
 * @init_clbcnt: the initial coulomb counter
 * @max_volt: the maximum constant input voltage in millivolt
 * @min_volt: the minimum drained battery voltage in microvolt
 * @boot_volt: the voltage measured during boot in microvolt
 * @table_len: the capacity table length
 * @resist_table_len: the resistance table length
 * @cur_1000ma_adc: ADC value corresponding to 1000 mA
 * @vol_1000mv_adc: ADC value corresponding to 1000 mV
 * @calib_resist: the real resistance of coulomb counter chip in uOhm
 * @cap_table: capacity table with corresponding ocv
 * @resist_table: resistance percent table with corresponding temperature
 */
struct sc27xx_fgu_data {};

static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity);
static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data,
					    int cap, bool int_mode);
static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap);
static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp);

static const char * const sc27xx_charger_supply_name[] =;

static int sc27xx_fgu_adc_to_current(struct sc27xx_fgu_data *data, s64 adc)
{}

static int sc27xx_fgu_adc_to_voltage(struct sc27xx_fgu_data *data, s64 adc)
{}

static int sc27xx_fgu_voltage_to_adc(struct sc27xx_fgu_data *data, int vol)
{}

static bool sc27xx_fgu_is_first_poweron(struct sc27xx_fgu_data *data)
{}

static int sc27xx_fgu_save_boot_mode(struct sc27xx_fgu_data *data,
				     int boot_mode)
{}

static int sc27xx_fgu_save_last_cap(struct sc27xx_fgu_data *data, int cap)
{}

static int sc27xx_fgu_read_last_cap(struct sc27xx_fgu_data *data, int *cap)
{}

/*
 * When system boots on, we can not read battery capacity from coulomb
 * registers, since now the coulomb registers are invalid. So we should
 * calculate the battery open circuit voltage, and get current battery
 * capacity according to the capacity table.
 */
static int sc27xx_fgu_get_boot_capacity(struct sc27xx_fgu_data *data, int *cap)
{}

static int sc27xx_fgu_set_clbcnt(struct sc27xx_fgu_data *data, int clbcnt)
{}

static int sc27xx_fgu_get_clbcnt(struct sc27xx_fgu_data *data, int *clb_cnt)
{}

static int sc27xx_fgu_get_vol_now(struct sc27xx_fgu_data *data, int *val)
{}

static int sc27xx_fgu_get_cur_now(struct sc27xx_fgu_data *data, int *val)
{}

static int sc27xx_fgu_get_capacity(struct sc27xx_fgu_data *data, int *cap)
{}

static int sc27xx_fgu_get_vbat_vol(struct sc27xx_fgu_data *data, int *val)
{}

static int sc27xx_fgu_get_current(struct sc27xx_fgu_data *data, int *val)
{}

static int sc27xx_fgu_get_vbat_ocv(struct sc27xx_fgu_data *data, int *val)
{}

static int sc27xx_fgu_get_charge_vol(struct sc27xx_fgu_data *data, int *val)
{}

static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp)
{}

static int sc27xx_fgu_get_health(struct sc27xx_fgu_data *data, int *health)
{}

static int sc27xx_fgu_get_status(struct sc27xx_fgu_data *data, int *status)
{}

static int sc27xx_fgu_get_property(struct power_supply *psy,
				   enum power_supply_property psp,
				   union power_supply_propval *val)
{}

static int sc27xx_fgu_set_property(struct power_supply *psy,
				   enum power_supply_property psp,
				   const union power_supply_propval *val)
{}

static int sc27xx_fgu_property_is_writeable(struct power_supply *psy,
					    enum power_supply_property psp)
{}

static enum power_supply_property sc27xx_fgu_props[] =;

static const struct power_supply_desc sc27xx_fgu_desc =;

static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap)
{}

static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data,
					    int cap, bool int_mode)
{}

static irqreturn_t sc27xx_fgu_interrupt(int irq, void *dev_id)
{}

static irqreturn_t sc27xx_fgu_bat_detection(int irq, void *dev_id)
{}

static void sc27xx_fgu_disable(void *_data)
{}

static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity)
{}

static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data)
{}

static int sc27xx_fgu_hw_init(struct sc27xx_fgu_data *data)
{}

static int sc27xx_fgu_probe(struct platform_device *pdev)
{}

#ifdef CONFIG_PM_SLEEP
static int sc27xx_fgu_resume(struct device *dev)
{}

static int sc27xx_fgu_suspend(struct device *dev)
{}
#endif

static const struct dev_pm_ops sc27xx_fgu_pm_ops =;

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

static struct platform_driver sc27xx_fgu_driver =;

module_platform_driver();

MODULE_DESCRIPTION();
MODULE_LICENSE();