linux/drivers/power/supply/bq2415x_charger.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * bq2415x charger driver
 *
 * Copyright (C) 2011-2013  Pali Rohár <[email protected]>
 *
 * Datasheets:
 * https://www.ti.com/product/bq24150
 * https://www.ti.com/product/bq24150a
 * https://www.ti.com/product/bq24152
 * https://www.ti.com/product/bq24153
 * https://www.ti.com/product/bq24153a
 * https://www.ti.com/product/bq24155
 * https://www.ti.com/product/bq24157s
 * https://www.ti.com/product/bq24158
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/param.h>
#include <linux/err.h>
#include <linux/workqueue.h>
#include <linux/sysfs.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/idr.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/acpi.h>

#include <linux/power/bq2415x_charger.h>

/* timeout for resetting chip timer */
#define BQ2415X_TIMER_TIMEOUT

#define BQ2415X_REG_STATUS
#define BQ2415X_REG_CONTROL
#define BQ2415X_REG_VOLTAGE
#define BQ2415X_REG_VENDER
#define BQ2415X_REG_CURRENT

/* reset state for all registers */
#define BQ2415X_RESET_STATUS
#define BQ2415X_RESET_CONTROL
#define BQ2415X_RESET_VOLTAGE
#define BQ2415X_RESET_CURRENT

/* status register */
#define BQ2415X_BIT_TMR_RST
#define BQ2415X_BIT_OTG
#define BQ2415X_BIT_EN_STAT
#define BQ2415X_MASK_STAT
#define BQ2415X_SHIFT_STAT
#define BQ2415X_BIT_BOOST
#define BQ2415X_MASK_FAULT
#define BQ2415X_SHIFT_FAULT

/* control register */
#define BQ2415X_MASK_LIMIT
#define BQ2415X_SHIFT_LIMIT
#define BQ2415X_MASK_VLOWV
#define BQ2415X_SHIFT_VLOWV
#define BQ2415X_BIT_TE
#define BQ2415X_BIT_CE
#define BQ2415X_BIT_HZ_MODE
#define BQ2415X_BIT_OPA_MODE

/* voltage register */
#define BQ2415X_MASK_VO
#define BQ2415X_SHIFT_VO
#define BQ2415X_BIT_OTG_PL
#define BQ2415X_BIT_OTG_EN

/* vender register */
#define BQ2415X_MASK_VENDER
#define BQ2415X_SHIFT_VENDER
#define BQ2415X_MASK_PN
#define BQ2415X_SHIFT_PN
#define BQ2415X_MASK_REVISION
#define BQ2415X_SHIFT_REVISION

/* current register */
#define BQ2415X_MASK_RESET
#define BQ2415X_MASK_VI_CHRG
#define BQ2415X_SHIFT_VI_CHRG
/* N/A					BIT(3) */
#define BQ2415X_MASK_VI_TERM
#define BQ2415X_SHIFT_VI_TERM


enum bq2415x_command {};

enum bq2415x_chip {};

static char *bq2415x_chip_name[] =;

struct bq2415x_device {};

/* each registered chip must have unique id */
static DEFINE_IDR(bq2415x_id);

static DEFINE_MUTEX(bq2415x_id_mutex);
static DEFINE_MUTEX(bq2415x_timer_mutex);
static DEFINE_MUTEX(bq2415x_i2c_mutex);

/**** i2c read functions ****/

/* read value from register */
static int bq2415x_i2c_read(struct bq2415x_device *bq, u8 reg)
{}

/* read value from register, apply mask and right shift it */
static int bq2415x_i2c_read_mask(struct bq2415x_device *bq, u8 reg,
				 u8 mask, u8 shift)
{}

/* read value from register and return one specified bit */
static int bq2415x_i2c_read_bit(struct bq2415x_device *bq, u8 reg, u8 bit)
{}

/**** i2c write functions ****/

/* write value to register */
static int bq2415x_i2c_write(struct bq2415x_device *bq, u8 reg, u8 val)
{}

/* read value from register, change it with mask left shifted and write back */
static int bq2415x_i2c_write_mask(struct bq2415x_device *bq, u8 reg, u8 val,
				  u8 mask, u8 shift)
{}

/* change only one bit in register */
static int bq2415x_i2c_write_bit(struct bq2415x_device *bq, u8 reg,
				 bool val, u8 bit)
{}

/**** global functions ****/

/* exec command function */
static int bq2415x_exec_command(struct bq2415x_device *bq,
				enum bq2415x_command command)
{}

/* detect chip type */
static enum bq2415x_chip bq2415x_detect_chip(struct bq2415x_device *bq)
{}

/* detect chip revision */
static int bq2415x_detect_revision(struct bq2415x_device *bq)
{}

/* return chip vender code */
static int bq2415x_get_vender_code(struct bq2415x_device *bq)
{}

/* reset all chip registers to default state */
static void bq2415x_reset_chip(struct bq2415x_device *bq)
{}

/**** properties functions ****/

/* set current limit in mA */
static int bq2415x_set_current_limit(struct bq2415x_device *bq, int mA)
{}

/* get current limit in mA */
static int bq2415x_get_current_limit(struct bq2415x_device *bq)
{}

/* set weak battery voltage in mV */
static int bq2415x_set_weak_battery_voltage(struct bq2415x_device *bq, int mV)
{}

/* get weak battery voltage in mV */
static int bq2415x_get_weak_battery_voltage(struct bq2415x_device *bq)
{}

/* set battery regulation voltage in mV */
static int bq2415x_set_battery_regulation_voltage(struct bq2415x_device *bq,
						  int mV)
{}

/* get battery regulation voltage in mV */
static int bq2415x_get_battery_regulation_voltage(struct bq2415x_device *bq)
{}

/* set charge current in mA (platform data must provide resistor sense) */
static int bq2415x_set_charge_current(struct bq2415x_device *bq, int mA)
{}

/* get charge current in mA (platform data must provide resistor sense) */
static int bq2415x_get_charge_current(struct bq2415x_device *bq)
{}

/* set termination current in mA (platform data must provide resistor sense) */
static int bq2415x_set_termination_current(struct bq2415x_device *bq, int mA)
{}

/* get termination current in mA (platform data must provide resistor sense) */
static int bq2415x_get_termination_current(struct bq2415x_device *bq)
{}

/* set default value of property */
#define bq2415x_set_default_value(bq, prop)

/* set default values of all properties */
static int bq2415x_set_defaults(struct bq2415x_device *bq)
{}

/**** charger mode functions ****/

/* set charger mode */
static int bq2415x_set_mode(struct bq2415x_device *bq, enum bq2415x_mode mode)
{}

static bool bq2415x_update_reported_mode(struct bq2415x_device *bq, int mA)
{}

static int bq2415x_notifier_call(struct notifier_block *nb,
		unsigned long val, void *v)
{}

/**** timer functions ****/

/* enable/disable auto resetting chip timer */
static void bq2415x_set_autotimer(struct bq2415x_device *bq, int state)
{}

/* called by bq2415x_timer_work on timer error */
static void bq2415x_timer_error(struct bq2415x_device *bq, const char *msg)
{}

/* delayed work function for auto resetting chip timer */
static void bq2415x_timer_work(struct work_struct *work)
{}

/**** power supply interface code ****/

static enum power_supply_property bq2415x_power_supply_props[] =;

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

static void bq2415x_power_supply_exit(struct bq2415x_device *bq)
{}

/**** additional sysfs entries for power supply interface ****/

/* show *_status entries */
static ssize_t bq2415x_sysfs_show_status(struct device *dev,
					 struct device_attribute *attr,
					 char *buf)
{}

/*
 * set timer entry:
 *    auto - enable auto mode
 *    off - disable auto mode
 *    (other values) - reset chip timer
 */
static ssize_t bq2415x_sysfs_set_timer(struct device *dev,
				       struct device_attribute *attr,
				       const char *buf,
				       size_t count)
{}

/* show timer entry (auto or off) */
static ssize_t bq2415x_sysfs_show_timer(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{}

/*
 * set mode entry:
 *    auto - if automode is supported, enable it and set mode to reported
 *    none - disable charger and boost mode
 *    host - charging mode for host/hub chargers (current limit 500mA)
 *    dedicated - charging mode for dedicated chargers (unlimited current limit)
 *    boost - disable charger and enable boost mode
 */
static ssize_t bq2415x_sysfs_set_mode(struct device *dev,
				      struct device_attribute *attr,
				      const char *buf,
				      size_t count)
{}

/* show mode entry (auto, none, host, dedicated or boost) */
static ssize_t bq2415x_sysfs_show_mode(struct device *dev,
				       struct device_attribute *attr,
				       char *buf)
{}

/* show reported_mode entry (none, host, dedicated or boost) */
static ssize_t bq2415x_sysfs_show_reported_mode(struct device *dev,
						struct device_attribute *attr,
						char *buf)
{}

/* directly set raw value to chip register, format: 'register value' */
static ssize_t bq2415x_sysfs_set_registers(struct device *dev,
					   struct device_attribute *attr,
					   const char *buf,
					   size_t count)
{}

/* print value of chip register, format: 'register=value' */
static ssize_t bq2415x_sysfs_print_reg(struct bq2415x_device *bq,
				       u8 reg,
				       char *buf)
{}

/* show all raw values of chip register, format per line: 'register=value' */
static ssize_t bq2415x_sysfs_show_registers(struct device *dev,
					    struct device_attribute *attr,
					    char *buf)
{}

/* set current and voltage limit entries (in mA or mV) */
static ssize_t bq2415x_sysfs_set_limit(struct device *dev,
				       struct device_attribute *attr,
				       const char *buf,
				       size_t count)
{}

/* show current and voltage limit entries (in mA or mV) */
static ssize_t bq2415x_sysfs_show_limit(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{}

/* set *_enable entries */
static ssize_t bq2415x_sysfs_set_enable(struct device *dev,
					struct device_attribute *attr,
					const char *buf,
					size_t count)
{}

/* show *_enable entries */
static ssize_t bq2415x_sysfs_show_enable(struct device *dev,
					 struct device_attribute *attr,
					 char *buf)
{}

static DEVICE_ATTR(current_limit, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit);
static DEVICE_ATTR(weak_battery_voltage, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit);
static DEVICE_ATTR(battery_regulation_voltage, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit);
static DEVICE_ATTR(charge_current, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit);
static DEVICE_ATTR(termination_current, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit);

static DEVICE_ATTR(charge_termination_enable, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_enable, bq2415x_sysfs_set_enable);
static DEVICE_ATTR(high_impedance_enable, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_enable, bq2415x_sysfs_set_enable);
static DEVICE_ATTR(otg_pin_enable, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_enable, bq2415x_sysfs_set_enable);
static DEVICE_ATTR(stat_pin_enable, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_enable, bq2415x_sysfs_set_enable);

static DEVICE_ATTR(reported_mode, S_IRUGO,
		bq2415x_sysfs_show_reported_mode, NULL);
static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_mode, bq2415x_sysfs_set_mode);
static DEVICE_ATTR(timer, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_timer, bq2415x_sysfs_set_timer);

static DEVICE_ATTR(registers, S_IWUSR | S_IRUGO,
		bq2415x_sysfs_show_registers, bq2415x_sysfs_set_registers);

static DEVICE_ATTR(otg_status, S_IRUGO, bq2415x_sysfs_show_status, NULL);
static DEVICE_ATTR(charge_status, S_IRUGO, bq2415x_sysfs_show_status, NULL);
static DEVICE_ATTR(boost_status, S_IRUGO, bq2415x_sysfs_show_status, NULL);
static DEVICE_ATTR(fault_status, S_IRUGO, bq2415x_sysfs_show_status, NULL);

static struct attribute *bq2415x_sysfs_attrs[] =;

ATTRIBUTE_GROUPS();

static int bq2415x_power_supply_init(struct bq2415x_device *bq)
{}

/* main bq2415x probe function */
static int bq2415x_probe(struct i2c_client *client)
{}

/* main bq2415x remove function */

static void bq2415x_remove(struct i2c_client *client)
{}

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

#ifdef CONFIG_ACPI
static const struct acpi_device_id bq2415x_i2c_acpi_match[] =;
MODULE_DEVICE_TABLE(acpi, bq2415x_i2c_acpi_match);
#endif

#ifdef CONFIG_OF
static const struct of_device_id bq2415x_of_match_table[] =;
MODULE_DEVICE_TABLE(of, bq2415x_of_match_table);
#endif

static struct i2c_driver bq2415x_driver =;
module_i2c_driver();

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