drivers/power/supply/ucs1002_power.c

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

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/ucs1002_power.c
Extension
.c
Size
17988 bytes
Lines
689
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 ucs1002_info {
	struct power_supply *charger;
	struct i2c_client *client;
	struct regmap *regmap;
	struct regulator_desc *regulator_descriptor;
	struct regulator_dev *rdev;
	bool present;
	bool output_disable;
	struct delayed_work health_poll;
	int health;

};

static enum power_supply_property ucs1002_props[] = {
	POWER_SUPPLY_PROP_ONLINE,
	POWER_SUPPLY_PROP_CHARGE_NOW,
	POWER_SUPPLY_PROP_CURRENT_NOW,
	POWER_SUPPLY_PROP_CURRENT_MAX,
	POWER_SUPPLY_PROP_PRESENT, /* the presence of PED */
	POWER_SUPPLY_PROP_MANUFACTURER,
	POWER_SUPPLY_PROP_USB_TYPE,
	POWER_SUPPLY_PROP_HEALTH,
};

static int ucs1002_get_online(struct ucs1002_info *info,
			      union power_supply_propval *val)
{
	unsigned int reg;
	int ret;

	ret = regmap_read(info->regmap, UCS1002_REG_OTHER_STATUS, &reg);
	if (ret)
		return ret;

	val->intval = !!(reg & F_CHG_ACT);

	return 0;
}

static int ucs1002_get_charge(struct ucs1002_info *info,
			      union power_supply_propval *val)
{
	/*
	 * To fit within 32 bits some values are rounded (uA/h)
	 *
	 * For Total Accumulated Charge Middle Low Byte register, addr
	 * 03h, byte 2
	 *
	 *   B0: 0.01084 mA/h rounded to 11 uA/h
	 *   B1: 0.02169 mA/h rounded to 22 uA/h
	 *   B2: 0.04340 mA/h rounded to 43 uA/h
	 *   B3: 0.08676 mA/h rounded to 87 uA/h
	 *   B4: 0.17350 mA/h rounded to 173 uÁ/h
	 *
	 * For Total Accumulated Charge Low Byte register, addr 04h,
	 * byte 3
	 *
	 *   B6: 0.00271 mA/h rounded to 3 uA/h
	 *   B7: 0.005422 mA/h rounded to 5 uA/h
	 */
	static const int bit_weights_uAh[BITS_PER_TYPE(u32)] = {
		/*
		 * Bit corresponding to low byte (offset 0x04)
		 * B0 B1 B2 B3 B4 B5 B6 B7
		 */
		0, 0, 0, 0, 0, 0, 3, 5,
		/*
		 * Bit corresponding to middle low byte (offset 0x03)
		 * B0 B1 B2 B3 B4 B5 B6 B7
		 */
		11, 22, 43, 87, 173, 347, 694, 1388,
		/*
		 * Bit corresponding to middle high byte (offset 0x02)
		 * B0 B1 B2 B3 B4 B5 B6 B7
		 */
		2776, 5552, 11105, 22210, 44420, 88840, 177700, 355400,
		/*
		 * Bit corresponding to high byte (offset 0x01)
		 * B0 B1 B2 B3 B4 B5 B6 B7
		 */
		710700, 1421000, 2843000, 5685000, 11371000, 22742000,
		45484000, 90968000,
	};
	unsigned long total_acc_charger;
	unsigned int reg;
	int i, ret;

	ret = regmap_bulk_read(info->regmap, UCS1002_REG_TOTAL_ACC_CHARGE,
			       &reg, sizeof(u32));
	if (ret)

Annotation

Implementation Notes