static int max17048_get_property(struct power_supply *psy,
			    enum power_supply_property psp,
			    union power_supply_propval *val)
{
	struct max17048_chip *chip = container_of(psy,
				struct max17048_chip, batt_psy);

	switch (psp) {
	case POWER_SUPPLY_PROP_STATUS:
		val->intval = max17048_get_prop_status(chip);
		break;
	case POWER_SUPPLY_PROP_HEALTH:
		val->intval = max17048_get_prop_health(chip);
		break;
	case POWER_SUPPLY_PROP_PRESENT:
		val->intval = max17048_get_prop_present(chip);
		break;
	case POWER_SUPPLY_PROP_TECHNOLOGY:
		val->intval = chip->batt_tech;
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
		val->intval = chip->max_mvolt * 1000;
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
		val->intval = chip->min_mvolt * 1000;
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
		val->intval = max17048_get_prop_vbatt_uv(chip);
		break;
	case POWER_SUPPLY_PROP_TEMP:
		val->intval = max17048_get_prop_temp(chip);
		break;
	case POWER_SUPPLY_PROP_CAPACITY:
		val->intval = max17048_get_prop_capacity(chip);
		break;
	case POWER_SUPPLY_PROP_CURRENT_NOW:
		val->intval = max17048_get_prop_current(chip);
		break;
	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
		val->intval = chip->fcc_mah;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}
Пример #2
0
static void max17048_work(struct work_struct *work)
{
	struct max17048_chip *chip =
		container_of(work, struct max17048_chip, monitor_work.work);
	int ret = 0;
	int rechg_now;

	wake_lock(&chip->alert_lock);

	pr_debug("%s.\n", __func__);

	max17048_get_prop_temp(chip);
	max17048_get_prop_current(chip);

	ret = max17048_set_rcomp(chip);
	if (ret)
		pr_err("%s : failed to set rcomp\n", __func__);

	max17048_get_vcell(chip);
	max17048_get_soc(chip);
	complete_all(&monitor_work_done);

	if (chip->capacity_level != chip->lasttime_capacity_level ||
			chip->capacity_level == 0) {
		rechg_now = max17048_check_recharge(chip);
		chip->lasttime_capacity_level = chip->capacity_level;
		if (!rechg_now)
			power_supply_changed(&chip->batt_psy);
	}

	ret = max17048_clear_interrupt(chip);
	if (ret < 0)
		pr_err("%s : error clear alert irq register.\n", __func__);

	pr_info("%s: raw soc = 0x%04X raw vcell = 0x%04X\n",
			__func__, chip->soc, chip->vcell);
	pr_info("%s: SOC = %d vbatt_mv = %d\n",
			__func__, chip->capacity_level, chip->voltage);
	pr_info("%s: ibatt_ua = %d batt_temp = %d\n",
			__func__, chip->batt_current, chip->batt_temp);

	wake_unlock(&chip->alert_lock);
}