#include <linux/module.h>
#include <linux/delay.h>
#include <linux/of.h>
#include <linux/pm_runtime.h>
#include <linux/power_supply.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#define LTC4162L_EN_LIMIT_ALERTS_REG …
#define LTC4162L_EN_CHARGER_STATE_ALERTS_REG …
#define LTC4162L_EN_CHARGE_STATUS_ALERTS_REG …
#define LTC4162L_CONFIG_BITS_REG …
#define LTC4162L_IIN_LIMIT_TARGET …
#define LTC4162L_ARM_SHIP_MODE …
#define LTC4162L_CHARGE_CURRENT_SETTING …
#define LTC4162L_VCHARGE_SETTING …
#define LTC4162L_C_OVER_X_THRESHOLD …
#define LTC4162L_MAX_CV_TIME …
#define LTC4162L_MAX_CHARGE_TIME …
#define LTC4162L_CHARGER_CONFIG_BITS …
#define LTC4162L_CHARGER_STATE …
#define LTC4162L_CHARGE_STATUS …
#define LTC4162L_LIMIT_ALERTS_REG …
#define LTC4162L_CHARGER_STATE_ALERTS_REG …
#define LTC4162L_CHARGE_STATUS_ALERTS_REG …
#define LTC4162L_SYSTEM_STATUS_REG …
#define LTC4162L_VBAT …
#define LTC4162L_VIN …
#define LTC4162L_VOUT …
#define LTC4162L_IBAT …
#define LTC4162L_IIN …
#define LTC4162L_DIE_TEMPERATURE …
#define LTC4162L_THERMISTOR_VOLTAGE …
#define LTC4162L_BSR …
#define LTC4162L_JEITA_REGION …
#define LTC4162L_CHEM_CELLS_REG …
#define LTC4162L_ICHARGE_DAC …
#define LTC4162L_VCHARGE_DAC …
#define LTC4162L_IIN_LIMIT_DAC …
#define LTC4162L_VBAT_FILT …
#define LTC4162L_INPUT_UNDERVOLTAGE_DAC …
enum ltc4162l_state { … };
enum ltc4162l_charge_status { … };
#define LTC4162L_ARM_SHIP_MODE_MAGIC …
struct ltc4162l_info { … };
static u8 ltc4162l_get_cell_count(struct ltc4162l_info *info)
{
int ret;
unsigned int val;
if (info->cell_count)
return info->cell_count;
ret = regmap_read(info->regmap, LTC4162L_CHEM_CELLS_REG, &val);
if (ret)
return 0;
val &= 0x0f;
if (!val)
return 0;
info->cell_count = val;
return val;
};
static int ltc4162l_state_decode(enum ltc4162l_state value)
{
switch (value) {
case precharge:
case cc_cv_charge:
return POWER_SUPPLY_STATUS_CHARGING;
case c_over_x_term:
return POWER_SUPPLY_STATUS_FULL;
case bat_missing_fault:
case bat_short_fault:
return POWER_SUPPLY_STATUS_UNKNOWN;
default:
return POWER_SUPPLY_STATUS_NOT_CHARGING;
}
};
static int ltc4162l_get_status(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_charge_status_decode(enum ltc4162l_charge_status value)
{ … }
static int ltc4162l_get_charge_type(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_state_to_health(enum ltc4162l_state value)
{ … }
static int ltc4162l_get_health(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_get_online(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_get_vbat(struct ltc4162l_info *info,
unsigned int reg,
union power_supply_propval *val)
{ … }
static int ltc4162l_get_ibat(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_get_input_voltage(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_get_input_current(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_get_icharge(struct ltc4162l_info *info,
unsigned int reg,
union power_supply_propval *val)
{ … }
static int ltc4162l_set_icharge(struct ltc4162l_info *info,
unsigned int reg,
unsigned int value)
{ … }
static int ltc4162l_get_vcharge(struct ltc4162l_info *info,
unsigned int reg,
union power_supply_propval *val)
{ … }
static int ltc4162l_set_vcharge(struct ltc4162l_info *info,
unsigned int reg,
unsigned int value)
{ … }
static int ltc4162l_get_iin_limit_dac(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_set_iin_limit(struct ltc4162l_info *info,
unsigned int value)
{ … }
static int ltc4162l_get_die_temp(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_get_term_current(struct ltc4162l_info *info,
union power_supply_propval *val)
{ … }
static int ltc4162l_set_term_current(struct ltc4162l_info *info,
unsigned int value)
{ … }
static const char * const ltc4162l_charge_status_name[] = …;
static ssize_t charge_status_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RO(charge_status);
static ssize_t vbat_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RO(vbat);
static ssize_t vbat_avg_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RO(vbat_avg);
static ssize_t ibat_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static DEVICE_ATTR_RO(ibat);
static ssize_t force_telemetry_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t force_telemetry_store(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t count)
{ … }
static DEVICE_ATTR_RW(force_telemetry);
static ssize_t arm_ship_mode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t arm_ship_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t count)
{ … }
static DEVICE_ATTR_RW(arm_ship_mode);
static struct attribute *ltc4162l_sysfs_entries[] = …;
static const struct attribute_group ltc4162l_attr_group = …;
static const struct attribute_group *ltc4162l_attr_groups[] = …;
static int ltc4162l_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{ … }
static int ltc4162l_set_property(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *val)
{ … }
static int ltc4162l_property_is_writeable(struct power_supply *psy,
enum power_supply_property psp)
{ … }
static enum power_supply_property ltc4162l_properties[] = …;
static const struct power_supply_desc ltc4162l_desc = …;
static bool ltc4162l_is_writeable_reg(struct device *dev, unsigned int reg)
{ … }
static bool ltc4162l_is_volatile_reg(struct device *dev, unsigned int reg)
{ … }
static const struct regmap_config ltc4162l_regmap_config = …;
static void ltc4162l_clear_interrupts(struct ltc4162l_info *info)
{ … }
static int ltc4162l_probe(struct i2c_client *client)
{ … }
static void ltc4162l_alert(struct i2c_client *client,
enum i2c_alert_protocol type, unsigned int flag)
{ … }
static const struct i2c_device_id ltc4162l_i2c_id_table[] = …;
MODULE_DEVICE_TABLE(i2c, ltc4162l_i2c_id_table);
static const struct of_device_id ltc4162l_of_match[] __maybe_unused = …;
MODULE_DEVICE_TABLE(of, ltc4162l_of_match);
static struct i2c_driver ltc4162l_driver = …;
module_i2c_driver(…) …;
MODULE_LICENSE(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;