Ejemplo n.º 1
0
static int cn_get_property(struct power_supply *psy,
		enum power_supply_property psp,
		union power_supply_propval *val)
{
	int16_t reg;
	uint result_uv;
	struct cn_chip *chip = container_of(psy, struct cn_chip, cn_psy);

	switch (psp) {
	case POWER_SUPPLY_PROP_CURRENT_NOW:
		cn_read_wrapper(chip, (u8 *)&reg,
				BMS1_VSENSE_AVG_DATA0, 2);
		result_uv = convert_vsense_to_uv(chip, reg);
		val->intval = (int)result_uv;
		break;
	case POWER_SUPPLY_PROP_PRESENT:
		cn_read_wrapper(chip, (u8 *)&reg, BMS_EN_CTL, 1);
		val->intval = !!(reg | BMS_EN_MASK);
		break;
	default:
		return -EINVAL;
	}
	return 0;
}
Ejemplo n.º 2
0
static int cn_masked_write_base(struct cn_chip *chip, u16 addr,
							u8 mask, u8 val)
{
	int rc;
	u8 reg;

	rc = cn_read_wrapper(chip, &reg, addr, 1);
	if (rc) {
		pr_err("read failed addr = %03X, rc = %d\n", addr, rc);
		return rc;
	}
	reg &= ~mask;
	reg |= val & mask;
	rc = cn_write_wrapper(chip, &reg, addr, 1);
	if (rc) {
		pr_err("write failed addr = %03X, val = %02x,\
				mask = %02x, reg = %02x, rc = %d\n",
				addr, val, mask, reg, rc);
		return rc;
	}
	return 0;
}
Ejemplo n.º 3
0
static int cn_get_property(struct power_supply *psy,
		enum power_supply_property psp,
		union power_supply_propval *val)
{
	int16_t reg;
	uint result_uv;
	struct cn_chip *chip = container_of(psy, struct cn_chip, cn_psy);

	switch (psp) {
	case POWER_SUPPLY_PROP_VIRT_CURRENT_NOW:
		cn_read_wrapper(chip, (u8 *)&reg,
				BMS1_VSENSE_AVG_DATA0, 2);
		result_uv = convert_vsense_to_uv(chip, reg);
		val->intval = (int)(result_uv * RATIO_TO_MICRO_A);
		break;
	case POWER_SUPPLY_PROP_VIRT_ENABLE_BMS:
		val->intval = chip->bms_enabled;
		break;
	default:
		return -EINVAL;
	}
	return 0;
}