linux/drivers/power/supply/bq24190_charger.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Driver for the TI bq24190 battery charger.
 *
 * Author: Mark A. Greer <[email protected]>
 */

#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/pm_runtime.h>
#include <linux/power_supply.h>
#include <linux/power/bq24190_charger.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/workqueue.h>
#include <linux/i2c.h>
#include <linux/extcon-provider.h>

#define BQ24190_MANUFACTURER

#define BQ24190_REG_ISC
#define BQ24190_REG_ISC_EN_HIZ_MASK
#define BQ24190_REG_ISC_EN_HIZ_SHIFT
#define BQ24190_REG_ISC_VINDPM_MASK
#define BQ24190_REG_ISC_VINDPM_SHIFT
#define BQ24190_REG_ISC_IINLIM_MASK
#define BQ24190_REG_ISC_IINLIM_SHIFT

#define BQ24190_REG_POC
#define BQ24190_REG_POC_RESET_MASK
#define BQ24190_REG_POC_RESET_SHIFT
#define BQ24190_REG_POC_WDT_RESET_MASK
#define BQ24190_REG_POC_WDT_RESET_SHIFT
#define BQ24190_REG_POC_CHG_CONFIG_MASK
#define BQ24190_REG_POC_CHG_CONFIG_SHIFT
#define BQ24190_REG_POC_CHG_CONFIG_DISABLE
#define BQ24190_REG_POC_CHG_CONFIG_CHARGE
#define BQ24190_REG_POC_CHG_CONFIG_OTG
#define BQ24190_REG_POC_CHG_CONFIG_OTG_ALT
#define BQ24296_REG_POC_OTG_CONFIG_MASK
#define BQ24296_REG_POC_OTG_CONFIG_SHIFT
#define BQ24296_REG_POC_CHG_CONFIG_MASK
#define BQ24296_REG_POC_CHG_CONFIG_SHIFT
#define BQ24296_REG_POC_OTG_CONFIG_DISABLE
#define BQ24296_REG_POC_OTG_CONFIG_OTG
#define BQ24190_REG_POC_SYS_MIN_MASK
#define BQ24190_REG_POC_SYS_MIN_SHIFT
#define BQ24190_REG_POC_SYS_MIN_MIN
#define BQ24190_REG_POC_SYS_MIN_MAX
#define BQ24190_REG_POC_BOOST_LIM_MASK
#define BQ24190_REG_POC_BOOST_LIM_SHIFT

#define BQ24190_REG_CCC
#define BQ24190_REG_CCC_ICHG_MASK
#define BQ24190_REG_CCC_ICHG_SHIFT
#define BQ24190_REG_CCC_FORCE_20PCT_MASK
#define BQ24190_REG_CCC_FORCE_20PCT_SHIFT

#define BQ24190_REG_PCTCC
#define BQ24190_REG_PCTCC_IPRECHG_MASK
#define BQ24190_REG_PCTCC_IPRECHG_SHIFT
#define BQ24190_REG_PCTCC_IPRECHG_MIN
#define BQ24190_REG_PCTCC_IPRECHG_MAX
#define BQ24190_REG_PCTCC_ITERM_MASK
#define BQ24190_REG_PCTCC_ITERM_SHIFT
#define BQ24190_REG_PCTCC_ITERM_MIN
#define BQ24190_REG_PCTCC_ITERM_MAX

#define BQ24190_REG_CVC
#define BQ24190_REG_CVC_VREG_MASK
#define BQ24190_REG_CVC_VREG_SHIFT
#define BQ24190_REG_CVC_BATLOWV_MASK
#define BQ24190_REG_CVC_BATLOWV_SHIFT
#define BQ24190_REG_CVC_VRECHG_MASK
#define BQ24190_REG_CVC_VRECHG_SHIFT

#define BQ24190_REG_CTTC
#define BQ24190_REG_CTTC_EN_TERM_MASK
#define BQ24190_REG_CTTC_EN_TERM_SHIFT
#define BQ24190_REG_CTTC_TERM_STAT_MASK
#define BQ24190_REG_CTTC_TERM_STAT_SHIFT
#define BQ24190_REG_CTTC_WATCHDOG_MASK
#define BQ24190_REG_CTTC_WATCHDOG_SHIFT
#define BQ24190_REG_CTTC_EN_TIMER_MASK
#define BQ24190_REG_CTTC_EN_TIMER_SHIFT
#define BQ24190_REG_CTTC_CHG_TIMER_MASK
#define BQ24190_REG_CTTC_CHG_TIMER_SHIFT
#define BQ24190_REG_CTTC_JEITA_ISET_MASK
#define BQ24190_REG_CTTC_JEITA_ISET_SHIFT

#define BQ24190_REG_ICTRC
#define BQ24190_REG_ICTRC_BAT_COMP_MASK
#define BQ24190_REG_ICTRC_BAT_COMP_SHIFT
#define BQ24190_REG_ICTRC_VCLAMP_MASK
#define BQ24190_REG_ICTRC_VCLAMP_SHIFT
#define BQ24190_REG_ICTRC_TREG_MASK
#define BQ24190_REG_ICTRC_TREG_SHIFT

#define BQ24190_REG_MOC
#define BQ24190_REG_MOC_DPDM_EN_MASK
#define BQ24190_REG_MOC_DPDM_EN_SHIFT
#define BQ24190_REG_MOC_TMR2X_EN_MASK
#define BQ24190_REG_MOC_TMR2X_EN_SHIFT
#define BQ24190_REG_MOC_BATFET_DISABLE_MASK
#define BQ24190_REG_MOC_BATFET_DISABLE_SHIFT
#define BQ24190_REG_MOC_JEITA_VSET_MASK
#define BQ24190_REG_MOC_JEITA_VSET_SHIFT
#define BQ24190_REG_MOC_INT_MASK_MASK
#define BQ24190_REG_MOC_INT_MASK_SHIFT

#define BQ24190_REG_SS
#define BQ24190_REG_SS_VBUS_STAT_MASK
#define BQ24190_REG_SS_VBUS_STAT_SHIFT
#define BQ24190_REG_SS_CHRG_STAT_MASK
#define BQ24190_REG_SS_CHRG_STAT_SHIFT
#define BQ24190_REG_SS_DPM_STAT_MASK
#define BQ24190_REG_SS_DPM_STAT_SHIFT
#define BQ24190_REG_SS_PG_STAT_MASK
#define BQ24190_REG_SS_PG_STAT_SHIFT
#define BQ24190_REG_SS_THERM_STAT_MASK
#define BQ24190_REG_SS_THERM_STAT_SHIFT
#define BQ24190_REG_SS_VSYS_STAT_MASK
#define BQ24190_REG_SS_VSYS_STAT_SHIFT

#define BQ24190_REG_F
#define BQ24190_REG_F_WATCHDOG_FAULT_MASK
#define BQ24190_REG_F_WATCHDOG_FAULT_SHIFT
#define BQ24190_REG_F_BOOST_FAULT_MASK
#define BQ24190_REG_F_BOOST_FAULT_SHIFT
#define BQ24190_REG_F_CHRG_FAULT_MASK
#define BQ24190_REG_F_CHRG_FAULT_SHIFT
#define BQ24190_REG_F_BAT_FAULT_MASK
#define BQ24190_REG_F_BAT_FAULT_SHIFT
#define BQ24190_REG_F_NTC_FAULT_MASK
#define BQ24190_REG_F_NTC_FAULT_SHIFT
#define BQ24296_REG_F_NTC_FAULT_MASK
#define BQ24296_REG_F_NTC_FAULT_SHIFT

#define BQ24190_REG_VPRS
#define BQ24190_REG_VPRS_PN_MASK
#define BQ24190_REG_VPRS_PN_SHIFT
#define BQ24190_REG_VPRS_PN_24190
#define BQ24190_REG_VPRS_PN_24192
#define BQ24190_REG_VPRS_PN_24192I
#define BQ24296_REG_VPRS_PN_MASK
#define BQ24296_REG_VPRS_PN_SHIFT
#define BQ24296_REG_VPRS_PN_24296
#define BQ24190_REG_VPRS_TS_PROFILE_MASK
#define BQ24190_REG_VPRS_TS_PROFILE_SHIFT
#define BQ24190_REG_VPRS_DEV_REG_MASK
#define BQ24190_REG_VPRS_DEV_REG_SHIFT

/*
 * The tables below provide a 2-way mapping for the value that goes in
 * the register field and the real-world value that it represents.
 * The index of the array is the value that goes in the register; the
 * number at that index in the array is the real-world value that it
 * represents.
 */

/* REG00[2:0] (IINLIM) in uAh */
static const int bq24190_isc_iinlim_values[] =;

/* REG02[7:2] (ICHG) in uAh */
static const int bq24190_ccc_ichg_values[] =;

/* ICHG higher than 3008mA is not supported in BQ24296 */
#define BQ24296_CCC_ICHG_VALUES_LEN

/* REG04[7:2] (VREG) in uV */
static const int bq24190_cvc_vreg_values[] =;

/* REG06[1:0] (TREG) in tenths of degrees Celsius */
static const int bq24190_ictrc_treg_values[] =;

enum bq24190_chip {};

/*
 * The FAULT register is latched by the bq24190 (except for NTC_FAULT)
 * so the first read after a fault returns the latched value and subsequent
 * reads return the current value.  In order to return the fault status
 * to the user, have the interrupt handler save the reg's value and retrieve
 * it in the appropriate health/status routine.
 */
struct bq24190_dev_info {};

struct bq24190_chip_info {};

static int bq24190_charger_set_charge_type(struct bq24190_dev_info *bdi,
					   const union power_supply_propval *val);

static const unsigned int bq24190_usb_extcon_cable[] =;


/*
 * Return the index in 'tbl' of greatest value that is less than or equal to
 * 'val'.  The index range returned is 0 to 'tbl_size' - 1.  Assumes that
 * the values in 'tbl' are sorted from smallest to largest and 'tbl_size'
 * is less than 2^8.
 */
static u8 bq24190_find_idx(const int tbl[], int tbl_size, int v)
{}

/* Basic driver I/O routines */

static int bq24190_read(struct bq24190_dev_info *bdi, u8 reg, u8 *data)
{}

static int bq24190_write(struct bq24190_dev_info *bdi, u8 reg, u8 data)
{}

static int bq24190_read_mask(struct bq24190_dev_info *bdi, u8 reg,
		u8 mask, u8 shift, u8 *data)
{}

static int bq24190_write_mask(struct bq24190_dev_info *bdi, u8 reg,
		u8 mask, u8 shift, u8 data)
{}

static int bq24190_get_field_val(struct bq24190_dev_info *bdi,
		u8 reg, u8 mask, u8 shift,
		const int tbl[], int tbl_size,
		int *val)
{}

static int bq24190_set_field_val(struct bq24190_dev_info *bdi,
		u8 reg, u8 mask, u8 shift,
		const int tbl[], int tbl_size,
		int val)
{}

#ifdef CONFIG_SYSFS
/*
 * There are a numerous options that are configurable on the bq24190
 * that go well beyond what the power_supply properties provide access to.
 * Provide sysfs access to them so they can be examined and possibly modified
 * on the fly.  They will be provided for the charger power_supply object only
 * and will be prefixed by 'f_' to make them easier to recognize.
 */

#define BQ24190_SYSFS_FIELD(_name, r, f, m, store)

#define BQ24190_SYSFS_FIELD_RW(_name, r, f)

#define BQ24190_SYSFS_FIELD_RO(_name, r, f)

static ssize_t bq24190_sysfs_show(struct device *dev,
		struct device_attribute *attr, char *buf);
static ssize_t bq24190_sysfs_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count);

struct bq24190_sysfs_field_info {};

/* On i386 ptrace-abi.h defines SS that breaks the macro calls below. */
#undef SS

static struct bq24190_sysfs_field_info bq24190_sysfs_field_tbl[] =;

static struct attribute *
	bq24190_sysfs_attrs[ARRAY_SIZE(bq24190_sysfs_field_tbl) + 1];

ATTRIBUTE_GROUPS();

static void bq24190_sysfs_init_attrs(void)
{}

static struct bq24190_sysfs_field_info *bq24190_sysfs_field_lookup(
		const char *name)
{}

static ssize_t bq24190_sysfs_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{}

static ssize_t bq24190_sysfs_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{}
#endif

static int bq24190_set_otg_vbus(struct bq24190_dev_info *bdi, bool enable)
{}

static int bq24296_set_otg_vbus(struct bq24190_dev_info *bdi, bool enable)
{}

#ifdef CONFIG_REGULATOR
static int bq24190_vbus_enable(struct regulator_dev *dev)
{}

static int bq24190_vbus_disable(struct regulator_dev *dev)
{}

static int bq24190_vbus_is_enabled(struct regulator_dev *dev)
{}

static int bq24296_vbus_enable(struct regulator_dev *dev)
{}

static int bq24296_vbus_disable(struct regulator_dev *dev)
{}

static int bq24296_vbus_is_enabled(struct regulator_dev *dev)
{}

static const struct regulator_ops bq24190_vbus_ops =;

static const struct regulator_desc bq24190_vbus_desc =;

static const struct regulator_ops bq24296_vbus_ops =;

static const struct regulator_desc bq24296_vbus_desc =;

static const struct regulator_init_data bq24190_vbus_init_data =;

static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi)
{}
#else
static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi)
{
	return 0;
}
#endif

static int bq24190_set_config(struct bq24190_dev_info *bdi)
{}

static int bq24190_register_reset(struct bq24190_dev_info *bdi)
{}

/* Charger power supply property routines */

static int bq24190_charger_get_charge_type(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_battery_set_chg_config(struct bq24190_dev_info *bdi,
		const u8 chg_config)
{}

static int bq24296_battery_set_chg_config(struct bq24190_dev_info *bdi,
		const u8 chg_config)
{}

static int bq24190_charger_set_charge_type(struct bq24190_dev_info *bdi,
		const union power_supply_propval *val)
{}

static int bq24190_charger_get_ntc_status(u8 value)
{}

static int bq24296_charger_get_ntc_status(u8 value)
{}

static int bq24190_charger_get_health(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_charger_get_online(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_battery_set_online(struct bq24190_dev_info *bdi,
				      const union power_supply_propval *val);
static int bq24190_battery_get_status(struct bq24190_dev_info *bdi,
				      union power_supply_propval *val);
static int bq24190_battery_get_temp_alert_max(struct bq24190_dev_info *bdi,
					      union power_supply_propval *val);
static int bq24190_battery_set_temp_alert_max(struct bq24190_dev_info *bdi,
					      const union power_supply_propval *val);

static int bq24190_charger_set_online(struct bq24190_dev_info *bdi,
				      const union power_supply_propval *val)
{}

static int bq24190_charger_get_status(struct bq24190_dev_info *bdi,
				      union power_supply_propval *val)
{}

static int bq24190_charger_get_temp_alert_max(struct bq24190_dev_info *bdi,
					      union power_supply_propval *val)
{}

static int bq24190_charger_set_temp_alert_max(struct bq24190_dev_info *bdi,
					      const union power_supply_propval *val)
{}

static int bq24190_charger_get_precharge(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_charger_get_charge_term(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_charger_get_current(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_charger_set_current(struct bq24190_dev_info *bdi,
		const union power_supply_propval *val)
{}

static int bq24190_charger_get_voltage(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_charger_set_voltage(struct bq24190_dev_info *bdi,
		const union power_supply_propval *val)
{}

static int bq24190_charger_get_iinlimit(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_charger_set_iinlimit(struct bq24190_dev_info *bdi,
		const union power_supply_propval *val)
{}

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

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

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

static void bq24190_input_current_limit_work(struct work_struct *work)
{}

/* Sync the input-current-limit with our parent supply (if we have one) */
static void bq24190_charger_external_power_changed(struct power_supply *psy)
{}

static enum power_supply_property bq24190_charger_properties[] =;

static char *bq24190_charger_supplied_to[] =;

static const struct power_supply_desc bq24190_charger_desc =;

/* Battery power supply property routines */

static int bq24190_battery_get_status(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_battery_get_health(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_battery_get_online(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_battery_set_online(struct bq24190_dev_info *bdi,
		const union power_supply_propval *val)
{}

static int bq24190_battery_get_temp_alert_max(struct bq24190_dev_info *bdi,
		union power_supply_propval *val)
{}

static int bq24190_battery_set_temp_alert_max(struct bq24190_dev_info *bdi,
		const union power_supply_propval *val)
{}

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

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

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

static enum power_supply_property bq24190_battery_properties[] =;

static const struct power_supply_desc bq24190_battery_desc =;

static int bq24190_configure_usb_otg(struct bq24190_dev_info *bdi, u8 ss_reg)
{}

static void bq24190_check_status(struct bq24190_dev_info *bdi)
{}

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

static int bq24190_check_chip(struct bq24190_dev_info *bdi)
{}

static int bq24296_check_chip(struct bq24190_dev_info *bdi)
{}

static int bq24190_hw_init(struct bq24190_dev_info *bdi)
{}

static int bq24190_get_config(struct bq24190_dev_info *bdi)
{}

static const struct bq24190_chip_info bq24190_chip_info_tbl[] =;

static int bq24190_probe(struct i2c_client *client)
{}

static void bq24190_remove(struct i2c_client *client)
{}

static void bq24190_shutdown(struct i2c_client *client)
{}

static __maybe_unused int bq24190_runtime_suspend(struct device *dev)
{}

static __maybe_unused int bq24190_runtime_resume(struct device *dev)
{}

static __maybe_unused int bq24190_pm_suspend(struct device *dev)
{}

static __maybe_unused int bq24190_pm_resume(struct device *dev)
{}

static const struct dev_pm_ops bq24190_pm_ops =;

static const struct i2c_device_id bq24190_i2c_ids[] =;
MODULE_DEVICE_TABLE(i2c, bq24190_i2c_ids);

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

static struct i2c_driver bq24190_driver =;
module_i2c_driver();

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