drivers/power/supply/bq24190_charger.c

Source file repositories/reference/linux-study-clean/drivers/power/supply/bq24190_charger.c

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/bq24190_charger.c
Extension
.c
Size
64563 bytes
Lines
2350
Domain
Driver Families
Bucket
drivers/power
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct bq24190_dev_info {
	struct i2c_client		*client;
	struct device			*dev;
	struct extcon_dev		*edev;
	struct power_supply		*charger;
	struct power_supply		*battery;
	struct delayed_work		input_current_limit_work;
	char				model_name[I2C_NAME_SIZE];
	bool				initialized;
	bool				irq_event;
	bool				otg_vbus_enabled;
	int				charge_type;
	u16				sys_min;
	u16				iprechg;
	u16				iterm;
	u32				ichg;
	u32				ichg_max;
	u32				vreg;
	u32				vreg_max;
	struct mutex			f_reg_lock;
	u8				f_reg;
	u8				ss_reg;
	u8				watchdog;
	const struct bq24190_chip_info	*info;
};

struct bq24190_chip_info {
	int ichg_array_size;
#ifdef CONFIG_REGULATOR
	const struct regulator_desc *vbus_desc;
#endif
	int (*check_chip)(struct bq24190_dev_info *bdi);
	int (*set_chg_config)(struct bq24190_dev_info *bdi, const u8 chg_config);
	int (*set_otg_vbus)(struct bq24190_dev_info *bdi, bool enable);
	u8 ntc_fault_mask;
	int (*get_ntc_status)(const u8 value);
};

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[] = {
	EXTCON_USB,
	EXTCON_NONE,
};


/*
 * 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)
{
	int i;

	for (i = 1; i < tbl_size; i++)
		if (v < tbl[i])
			break;

	return i - 1;
}

/* Basic driver I/O routines */

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

	ret = i2c_smbus_read_byte_data(bdi->client, reg);
	if (ret < 0)
		return ret;

	*data = ret;
	return 0;
}

static int bq24190_write(struct bq24190_dev_info *bdi, u8 reg, u8 data)
{
	return i2c_smbus_write_byte_data(bdi->client, reg, data);
}

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

	ret = bq24190_read(bdi, reg, &v);

Annotation

Implementation Notes