staticint adp5061_set_input_current_limit(struct adp5061_state *st, int val)
{ int index;
/* Convert from uA to mA */
val /= 1000;
index = adp5061_get_array_index(adp5061_in_current_lim,
ARRAY_SIZE(adp5061_in_current_lim),
val); if (index < 0) return index;
staticint adp5061_set_const_chg_vmax(struct adp5061_state *st, int val)
{ int index;
/* Convert from uV to mV */
val /= 1000;
index = adp5061_get_array_index(adp5061_const_chg_vmax,
ARRAY_SIZE(adp5061_const_chg_vmax),
val); if (index < 0) return index;
staticint adp5061_set_prechg_current(struct adp5061_state *st, int val)
{ int index;
/* Convert from uA to mA */
val /= 1000;
index = adp5061_get_array_index(adp5061_prechg_current,
ARRAY_SIZE(adp5061_prechg_current),
val); if (index < 0) return index;
staticint adp5061_set_vweak_th(struct adp5061_state *st, int val)
{ int index;
/* Convert from uV to mV */
val /= 1000;
index = adp5061_get_array_index(adp5061_vweak_th,
ARRAY_SIZE(adp5061_vweak_th),
val); if (index < 0) return index;
staticint adp5061_get_charger_status(struct adp5061_state *st, union power_supply_propval *val)
{
u8 status1, status2; int ret;
ret = adp5061_get_status(st, &status1, &status2); if (ret < 0) return ret;
switch (ADP5061_CHG_STATUS_1_CHG_STATUS(status1)) { case ADP5061_CHG_OFF:
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; break; case ADP5061_CHG_TRICKLE: case ADP5061_CHG_FAST_CC: case ADP5061_CHG_FAST_CV:
val->intval = POWER_SUPPLY_STATUS_CHARGING; break; case ADP5061_CHG_COMPLETE:
val->intval = POWER_SUPPLY_STATUS_FULL; break; case ADP5061_CHG_TIMER_EXP: /* The battery must be discharging if there is a charge fault */
val->intval = POWER_SUPPLY_STATUS_DISCHARGING; break; default:
val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
}
return ret;
}
staticint adp5061_get_battery_status(struct adp5061_state *st, union power_supply_propval *val)
{
u8 status1, status2; int ret;
ret = adp5061_get_status(st, &status1, &status2); if (ret < 0) return ret;
switch (ADP5061_CHG_STATUS_2_BAT_STATUS(status2)) { case 0x0: /* Battery monitor off */ case 0x1: /* No battery */
val->intval = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; break; case 0x2: /* VBAT < VTRK */
val->intval = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; break; case 0x3: /* VTRK < VBAT_SNS < VWEAK */
val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW; break; case 0x4: /* VBAT_SNS > VWEAK */
val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; break; default:
val->intval = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; break;
}
return ret;
}
staticint adp5061_get_termination_current(struct adp5061_state *st, union power_supply_propval *val)
{ unsignedint regval; int ret;
ret = regmap_read(st->regmap, ADP5061_IEND, ®val); if (ret < 0) return ret;
switch (psp) { case POWER_SUPPLY_PROP_PRESENT:
ret = adp5061_get_status(st, &status1, &status2); if (ret < 0) return ret;
mode = ADP5061_CHG_STATUS_2_BAT_STATUS(status2); if (mode == ADP5061_NO_BATTERY)
val->intval = 0; else
val->intval = 1; break; case POWER_SUPPLY_PROP_CHARGE_TYPE: return adp5061_get_chg_type(st, val); case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: /* This property is used to indicate the input current * limit into VINx (ILIM)
*/ return adp5061_get_input_current_limit(st, val); case POWER_SUPPLY_PROP_VOLTAGE_MAX: /* This property is used to indicate the termination * voltage (VTRM)
*/ return adp5061_get_max_voltage(st, val); case POWER_SUPPLY_PROP_VOLTAGE_MIN: /* * This property is used to indicate the trickle to fast * charge threshold (VTRK_DEAD)
*/ return adp5061_get_min_voltage(st, val); case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: /* This property is used to indicate the charging * voltage limit (CHG_VLIM)
*/ return adp5061_get_chg_volt_lim(st, val); case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: /* * This property is used to indicate the value of the constant * current charge (ICHG)
*/ return adp5061_get_const_chg_current(st, val); case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: /* * This property is used to indicate the value of the trickle * and weak charge currents (ITRK_DEAD)
*/ return adp5061_get_prechg_current(st, val); case POWER_SUPPLY_PROP_VOLTAGE_AVG: /* * This property is used to set the VWEAK threshold * below this value, weak charge mode is entered * above this value, fast chargerge mode is entered
*/ return adp5061_get_vweak_th(st, val); case POWER_SUPPLY_PROP_STATUS: /* * Indicate the charger status in relation to power * supply status property
*/ return adp5061_get_charger_status(st, val); case POWER_SUPPLY_PROP_CAPACITY_LEVEL: /* * Indicate the battery status in relation to power * supply capacity level property
*/ return adp5061_get_battery_status(st, val); case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: /* Indicate the values of the termination current */ return adp5061_get_termination_current(st, val); default: return -EINVAL;
}
switch (psp) { case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: return adp5061_set_input_current_limit(st, val->intval); case POWER_SUPPLY_PROP_VOLTAGE_MAX: return adp5061_set_max_voltage(st, val->intval); case POWER_SUPPLY_PROP_VOLTAGE_MIN: return adp5061_set_min_voltage(st, val->intval); case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: return adp5061_set_const_chg_vmax(st, val->intval); case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: return adp5061_set_const_chg_current(st, val->intval); case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: return adp5061_set_prechg_current(st, val->intval); case POWER_SUPPLY_PROP_VOLTAGE_AVG: return adp5061_set_vweak_th(st, val->intval); case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: return adp5061_set_termination_current(st, val->intval); default: return -EINVAL;
}
return 0;
}
staticint adp5061_prop_writeable(struct power_supply *psy, enum power_supply_property psp)
{ switch (psp) { case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: case POWER_SUPPLY_PROP_VOLTAGE_MAX: case POWER_SUPPLY_PROP_VOLTAGE_MIN: case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: case POWER_SUPPLY_PROP_PRECHARGE_CURRENT: case POWER_SUPPLY_PROP_VOLTAGE_AVG: case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT: return 1; default: return 0;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.