drivers/power/supply/smb347-charger.c

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

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/smb347-charger.c
Extension
.c
Size
43836 bytes
Lines
1643
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 smb347_charger {
	struct device		*dev;
	struct regmap		*regmap;
	struct power_supply	*mains;
	struct power_supply	*usb;
	struct regulator_dev	*usb_rdev;
	unsigned int		id;
	bool			mains_online;
	bool			usb_online;
	bool			irq_unsupported;
	bool			usb_vbus_enabled;

	unsigned int		max_charge_current;
	unsigned int		max_charge_voltage;
	unsigned int		pre_charge_current;
	unsigned int		termination_current;
	unsigned int		pre_to_fast_voltage;
	unsigned int		mains_current_limit;
	unsigned int		usb_hc_current_limit;
	unsigned int		chip_temp_threshold;
	int			soft_cold_temp_limit;
	int			soft_hot_temp_limit;
	int			hard_cold_temp_limit;
	int			hard_hot_temp_limit;
	bool			suspend_on_hard_temp_limit;
	unsigned int		soft_temp_limit_compensation;
	unsigned int		charge_current_compensation;
	bool			use_mains;
	bool			use_usb;
	bool			use_usb_otg;
	unsigned int		enable_control;
	unsigned int		inok_polarity;
};

enum smb_charger_chipid {
	SMB345,
	SMB347,
	SMB358,
	NUM_CHIP_TYPES,
};

/* Fast charge current in uA */
static const unsigned int fcc_tbl[NUM_CHIP_TYPES][8] = {
	[SMB345] = {  200000,  450000,  600000,  900000,
		     1300000, 1500000, 1800000, 2000000 },
	[SMB347] = {  700000,  900000, 1200000, 1500000,
		     1800000, 2000000, 2200000, 2500000 },
	[SMB358] = {  200000,  450000,  600000,  900000,
		     1300000, 1500000, 1800000, 2000000 },
};
/* Pre-charge current in uA */
static const unsigned int pcc_tbl[NUM_CHIP_TYPES][4] = {
	[SMB345] = { 150000, 250000, 350000, 450000 },
	[SMB347] = { 100000, 150000, 200000, 250000 },
	[SMB358] = { 150000, 250000, 350000, 450000 },
};

/* Termination current in uA */
static const unsigned int tc_tbl[NUM_CHIP_TYPES][8] = {
	[SMB345] = {  30000,  40000,  60000,  80000,
		     100000, 125000, 150000, 200000 },
	[SMB347] = {  37500,  50000, 100000, 150000,
		     200000, 250000, 500000, 600000 },
	[SMB358] = {  30000,  40000,  60000,  80000,
		     100000, 125000, 150000, 200000 },
};

/* Input current limit in uA */
static const unsigned int icl_tbl[NUM_CHIP_TYPES][10] = {
	[SMB345] = {  300000,  500000,  700000, 1000000, 1500000,
		     1800000, 2000000, 2000000, 2000000, 2000000 },
	[SMB347] = {  300000,  500000,  700000,  900000, 1200000,
		     1500000, 1800000, 2000000, 2200000, 2500000 },
	[SMB358] = {  300000,  500000,  700000, 1000000, 1500000,
		     1800000, 2000000, 2000000, 2000000, 2000000 },
};

/* Charge current compensation in uA */
static const unsigned int ccc_tbl[NUM_CHIP_TYPES][4] = {
	[SMB345] = {  200000,  450000,  600000,  900000 },
	[SMB347] = {  250000,  700000,  900000, 1200000 },
	[SMB358] = {  200000,  450000,  600000,  900000 },
};

/* Convert register value to current using lookup table */
static int hw_to_current(const unsigned int *tbl, size_t size, unsigned int val)
{
	if (val >= size)
		return -EINVAL;
	return tbl[val];

Annotation

Implementation Notes