/* * Max charging current read to/written from hardware register. * Note how highest value corresponding to 0x7 is the lowest * current, this is per the datasheet.
*/ enum rk817_chg_cur {
CHG_1A,
CHG_1_5A,
CHG_2A,
CHG_2_5A,
CHG_2_75A,
CHG_3A,
CHG_3_5A,
CHG_0_5A,
};
/* * voltage_k and voltage_b values are used to calibrate the ADC * voltage readings. While they are documented in the BSP kernel and * datasheet as voltage_k and voltage_b, there is no further * information explaining them in more detail.
*/
uint32_t voltage_k;
uint32_t voltage_b;
/* * soc - state of charge - like the BSP this is stored as a percentage, * to the thousandth. BSP has a display state of charge (dsoc) and a * remaining state of charge (rsoc). This value will be used for both * purposes here so we don't do any fancy math to try and "smooth" the * charge and just report it as it is. Note for example an soc of 100 * is stored as 100000, an soc of 50 is stored as 50000, etc.
*/ int soc;
/* * Capacity of battery when fully charged, equal or less than design * capacity depending upon wear. BSP kernel saves to nvram in mAh, * so this value is in mAh not the standard uAh.
*/ int fcc_mah;
/* * Calibrate the SOC on a fully charged battery, this way we can use * the calibrated SOC value to correct for columb counter drift.
*/ bool soc_cal;
/* Implementation specific immutable properties from device tree */ int res_div; int sleep_enter_current_ua; int sleep_filter_current_ua; int bat_charge_full_design_uah; int bat_voltage_min_design_uv; int bat_voltage_max_design_uv;
/* Values updated periodically by driver for display. */ int charge_now_uah; int volt_avg_uv; int cur_avg_ua; int max_chg_cur_ua; int max_chg_volt_uv; int charge_status; int charger_input_volt_avg_uv;
/* Work queue to periodically update values. */ struct delayed_work work;
};
/* * note that only the fcc_mah is really used by this driver, the other values * are to ensure we can remain backwards compatible with the BSP kernel.
*/ staticint rk817_record_battery_nvram_values(struct rk817_charger *charger)
{
u8 bulk_reg[3]; int ret, rsoc;
/* * write the soc value to the nvram location used by the BSP kernel * for the dsoc value.
*/
put_unaligned_le24(charger->soc, bulk_reg);
ret = regmap_bulk_write(charger->rk808->regmap, RK817_GAS_GAUGE_BAT_R1,
bulk_reg, 3); if (ret < 0) return ret; /* * write the remaining capacity in mah to the nvram location used by * the BSP kernel for the rsoc value.
*/
rsoc = (charger->soc * charger->fcc_mah) / 100000;
put_unaligned_le24(rsoc, bulk_reg);
ret = regmap_bulk_write(charger->rk808->regmap, RK817_GAS_GAUGE_DATA0,
bulk_reg, 3); if (ret < 0) return ret; /* write the fcc_mah in mAh, just as the BSP kernel does. */
put_unaligned_le24(charger->fcc_mah, bulk_reg);
ret = regmap_bulk_write(charger->rk808->regmap, RK817_GAS_GAUGE_DATA3,
bulk_reg, 3); if (ret < 0) return ret;
/* Don't do anything if there's no battery. */ if (!charger->battery_present) return 0;
/* * When resuming from suspend, sometimes the voltage value would be * incorrect. BSP would simply wait two seconds and try reading the * values again. Do not do any sort of calibration activity when the * reported value is incorrect. The next scheduled update of battery * vaules should then return valid data and the driver can continue. * Use 2.7v as the sanity value because per the datasheet the PMIC * can in no way support a battery voltage lower than this. BSP only * checked for values too low, but I'm adding in a check for values * too high just in case; again the PMIC can in no way support * voltages above 4.45v, so this seems like a good value.
*/ if ((charger->volt_avg_uv < 2700000) || (charger->volt_avg_uv > 4450000)) {
dev_dbg(charger->dev, "Battery voltage of %d is invalid, ignoring.\n",
charger->volt_avg_uv); return -EINVAL;
}
/* Calibrate the soc and fcc on a fully charged battery */
if (charger->charge_status == CHARGE_FINISH && (!charger->soc_cal)) { /* * soc should be 100000 and columb counter should show the full * charge capacity. Note that if the device is unplugged for a * period of several days the columb counter will have a large * margin of error, so setting it back to the full charge on * a completed charge cycle should correct this (my device was * showing 33% battery after 3 days unplugged when it should * have been closer to 95% based on voltage and charge * current).
*/
charger->soc_cal = 1;
dev_dbg(charger->dev, "Fully charged. SOC is %d, full capacity is %d\n",
charger->soc, charger->fcc_mah * 1000);
}
/* * The columb counter can drift up slightly, so we should correct for * it. But don't correct it until we're at 100% soc.
*/ if (charger->charge_status == CHARGE_FINISH && charger->soc_cal) {
regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3,
bulk_reg, 4);
charge_now_adc = get_unaligned_be32(bulk_reg); if (charge_now_adc < 0) return charge_now_adc;
charge_now = ADC_TO_CHARGE_UAH(charge_now_adc,
charger->res_div);
/* * Re-init columb counter with updated values to correct drift.
*/ if (charge_now / 1000 > charger->fcc_mah) {
dev_dbg(charger->dev, "Recalibrating columb counter to %d uah\n",
charge_now); /* * Order of operations matters here to ensure we keep * enough precision until the last step to keep from * making needless updates to columb counter.
*/
charge_now_adc = CHARGE_TO_ADC(charger->fcc_mah,
charger->res_div);
put_unaligned_be32(charge_now_adc, bulk_reg);
regmap_bulk_write(rk808->regmap,
RK817_GAS_GAUGE_Q_INIT_H3,
bulk_reg, 4);
}
}
rk817_record_battery_nvram_values(charger);
return 0;
}
staticvoid rk817_read_props(struct rk817_charger *charger)
{ int tmp, reg;
u8 bulk_reg[4];
/* * Recalibrate voltage and current readings if we need to BSP does both * on CUR_CALIB_UPD, ignoring VOL_CALIB_UPD. Curiously enough, both * documentation and the BSP show that you perform an update if bit 7 * is 1, but you clear the status by writing a 1 to bit 7.
*/
regmap_read(charger->rk808->regmap, RK817_GAS_GAUGE_ADC_CONFIG1, ®); if (reg & RK817_VOL_CUR_CALIB_UPD) {
rk817_bat_calib_cur(charger);
rk817_bat_calib_vol(charger);
regmap_write_bits(charger->rk808->regmap,
RK817_GAS_GAUGE_ADC_CONFIG1,
RK817_VOL_CUR_CALIB_UPD,
RK817_VOL_CUR_CALIB_UPD);
}
/* * Update reported current. Note value from registers is a signed 16 * bit int.
*/
regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_BAT_CUR_H,
bulk_reg, 2);
tmp = (shortint)get_unaligned_be16(bulk_reg);
charger->cur_avg_ua = ADC_TO_CURRENT(tmp, charger->res_div);
/* * Update the max charge current. This value shouldn't change, but we * can read it to report what the PMIC says it is instead of simply * returning the default value.
*/
regmap_read(charger->rk808->regmap, RK817_PMIC_CHRG_OUT, ®);
charger->max_chg_cur_ua =
rk817_chg_cur_from_reg(reg & RK817_CHRG_CUR_SEL);
/* * Update max charge voltage. Like the max charge current this value * shouldn't change, but we can report what the PMIC says.
*/
regmap_read(charger->rk808->regmap, RK817_PMIC_CHRG_OUT, ®);
charger->max_chg_volt_uv = ((((reg & RK817_CHRG_VOL_SEL) >> 4) *
50000) + 4100000);
/* Check if battery still present. */
regmap_read(charger->rk808->regmap, RK817_PMIC_CHRG_STS, ®);
charger->battery_present = (reg & RK817_BAT_EXS);
/* Get which type of charge we are using (if any). */
regmap_read(charger->rk808->regmap, RK817_PMIC_CHRG_STS, ®);
charger->charge_status = (reg >> 4) & 0x07;
/* * Get charger input voltage. Note that on my example hardware (an * Odroid Go Advance) the voltage of the power connector is measured * on the register labelled USB in the datasheet; I don't know if this * is how it is designed or just a quirk of the implementation. I * believe this will also measure the voltage of the USB output when in * OTG mode, if that is the case we may need to change this in the * future to return 0 if the power supply status is offline (I can't * test this with my current implementation. Also, when the voltage * should be zero sometimes the ADC still shows a single bit (which * would register as 20000uv). When this happens set it to 0.
*/
regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_USB_VOL_H,
bulk_reg, 2);
reg = get_unaligned_be16(bulk_reg); if (reg > 1) {
tmp = ((charger->voltage_k * reg / 1000 + charger->voltage_b) *
60 / 46);
charger->charger_input_volt_avg_uv = tmp * 1000;
} else {
charger->charger_input_volt_avg_uv = 0;
}
/* Calibrate battery capacity and soc. */
rk817_bat_calib_cap(charger);
}
switch (prop) { case POWER_SUPPLY_PROP_PRESENT:
val->intval = charger->battery_present; break; case POWER_SUPPLY_PROP_STATUS: if (charger->cur_avg_ua < 0) {
val->intval = POWER_SUPPLY_STATUS_DISCHARGING; break;
} switch (charger->charge_status) { case CHRG_OFF:
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; break; /* * Dead charge is documented, but not explained. I never * observed it but assume it's a pre-charge for a dead * battery.
*/ case DEAD_CHRG: case TRICKLE_CHRG: case CC_OR_CV_CHRG:
val->intval = POWER_SUPPLY_STATUS_CHARGING; break; case CHARGE_FINISH:
val->intval = POWER_SUPPLY_STATUS_FULL; break; default:
val->intval = POWER_SUPPLY_STATUS_UNKNOWN; return -EINVAL;
} break; case POWER_SUPPLY_PROP_CHARGE_TYPE: switch (charger->charge_status) { case CHRG_OFF: case CHARGE_FINISH:
val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; break; case TRICKLE_CHRG:
val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; break; case DEAD_CHRG: case CC_OR_CV_CHRG:
val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; break; default:
val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; break;
} break; case POWER_SUPPLY_PROP_CHARGE_FULL:
val->intval = charger->fcc_mah * 1000; break; case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
val->intval = charger->bat_charge_full_design_uah; break; case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
val->intval = 0; break; case POWER_SUPPLY_PROP_CHARGE_NOW:
val->intval = charger->charge_now_uah; break; case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
val->intval = charger->bat_voltage_min_design_uv; break; case POWER_SUPPLY_PROP_CAPACITY: /* Add 500 so that values like 99999 are 100% not 99%. */
val->intval = (charger->soc + 500) / 1000; if (val->intval > 100)
val->intval = 100; if (val->intval < 0)
val->intval = 0; break; case POWER_SUPPLY_PROP_VOLTAGE_AVG:
val->intval = charger->volt_avg_uv; break; case POWER_SUPPLY_PROP_CURRENT_AVG:
val->intval = charger->cur_avg_ua; break; case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
val->intval = charger->max_chg_cur_ua; break; case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
val->intval = charger->max_chg_volt_uv; break; case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
val->intval = charger->bat_voltage_max_design_uv; break; default: return -EINVAL;
} return 0;
}
switch (prop) { case POWER_SUPPLY_PROP_ONLINE:
val->intval = charger->plugged_in; break; case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: /* max voltage from datasheet at 5.5v (default 5.0v) */
val->intval = 5500000; break; case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: /* min voltage from datasheet at 3.8v (default 5.0v) */
val->intval = 3800000; break; case POWER_SUPPLY_PROP_VOLTAGE_AVG:
val->intval = charger->charger_input_volt_avg_uv; break; /* * While it's possible that other implementations could use different * USB types, the current implementation for this PMIC (the Odroid Go * Advance) only uses a dedicated charging port with no rx/tx lines.
*/ case POWER_SUPPLY_PROP_USB_TYPE:
val->intval = POWER_SUPPLY_USB_TYPE_DCP; break; default: return -EINVAL;
} return 0;
charger = (struct rk817_charger *)cg;
charger->plugged_in = 1;
power_supply_changed(charger->chg_ps);
power_supply_changed(charger->bat_ps); /* try to recalibrate capacity if we hit full charge. */
charger->soc_cal = 0;
/* * For some reason the bits of RK817_PMIC_CHRG_IN reset whenever the * power cord is unplugged. This was not documented in the BSP kernel * or the datasheet and only discovered by trial and error. Set minimum * USB input voltage to 4.5v and enable USB voltage input limit.
*/
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN,
RK817_USB_VLIM_SEL, (0x05 << 4));
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, RK817_USB_VLIM_EN,
(0x01 << 7));
/* * Set average USB input current limit to 1.5A and enable USB current * input limit.
*/
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN,
RK817_USB_ILIM_SEL, 0x03);
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, RK817_USB_ILIM_EN,
(0x01 << 3));
staticint rk817_read_battery_nvram_values(struct rk817_charger *charger)
{
u8 bulk_reg[3]; int ret;
/* Read the nvram data for full charge capacity. */
ret = regmap_bulk_read(charger->rk808->regmap,
RK817_GAS_GAUGE_DATA3, bulk_reg, 3); if (ret < 0) return ret;
charger->fcc_mah = get_unaligned_le24(bulk_reg);
/* * Sanity checking for values equal to zero or less than would be * practical for this device (BSP Kernel assumes 500mAH or less) for * practicality purposes. Also check if the value is too large and * correct it.
*/ if ((charger->fcc_mah < 500) ||
((charger->fcc_mah * 1000) > charger->bat_charge_full_design_uah)) {
dev_info(charger->dev, "Invalid NVRAM max charge, setting to %u uAH\n",
charger->bat_charge_full_design_uah);
charger->fcc_mah = charger->bat_charge_full_design_uah / 1000;
}
/* * Read the nvram for state of charge. Sanity check for values greater * than 100 (10000) or less than 0, because other things (BSP kernels, * U-Boot, or even i2cset) can write to this register. If the value is * off it should get corrected automatically when the voltage drops to * the min (soc is 0) or when the battery is full (soc is 100).
*/
ret = regmap_bulk_read(charger->rk808->regmap,
RK817_GAS_GAUGE_BAT_R1, bulk_reg, 3); if (ret < 0) return ret;
charger->soc = get_unaligned_le24(bulk_reg); if (charger->soc > 10000)
charger->soc = 10000; if (charger->soc < 0)
charger->soc = 0;
/* * Check if the battery is uninitalized. If it is, the columb counter * needs to be set up.
*/
ret = regmap_read(rk808->regmap, RK817_GAS_GAUGE_GG_STS, ®); if (ret < 0) return ret;
first_boot = reg & RK817_BAT_CON; /* * If the battery is uninitialized, use the poweron voltage and an ocv * lookup to guess our charge. The number won't be very accurate until * we hit either our minimum voltage (0%) or full charge (100%).
*/ if (first_boot) {
regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_PWRON_VOL_H,
bulk_reg, 2);
tmp = get_unaligned_be16(bulk_reg);
boot_voltage = (charger->voltage_k * tmp) +
1000 * charger->voltage_b; /* * Since only implementation has no working thermistor, assume * 20C for OCV lookup. If lookup fails, report error with OCV * table.
*/
charger->soc = power_supply_batinfo_ocv2cap(bat_info,
boot_voltage,
20) * 1000; if (charger->soc < 0)
charger->soc = 0;
/* Guess that full charge capacity is the design capacity */
charger->fcc_mah = charger->bat_charge_full_design_uah / 1000; /* * Set battery as "set up". BSP driver uses this value even * though datasheet claims it's a read-only value.
*/
regmap_write_bits(rk808->regmap, RK817_GAS_GAUGE_GG_STS,
RK817_BAT_CON, 0); /* Save nvram values */
ret = rk817_record_battery_nvram_values(charger); if (ret < 0) return ret;
} else {
ret = rk817_read_battery_nvram_values(charger); if (ret < 0) return ret;
regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3,
bulk_reg, 4);
tmp = get_unaligned_be32(bulk_reg); if (tmp < 0)
tmp = 0;
boot_charge_mah = ADC_TO_CHARGE_UAH(tmp,
charger->res_div) / 1000; /* * Check if the columb counter has been off for more than 30 * minutes as it tends to drift downward. If so, re-init soc * with the boot voltage instead. Note the unit values for the * OFF_CNT register appear to be in decaminutes and stops * counting at 2550 (0xFF) minutes. BSP kernel used OCV, but * for me occasionally that would show invalid values. Boot * voltage is only accurate for me on first poweron (not * reboots), but we shouldn't ever encounter an OFF_CNT more * than 0 on a reboot anyway.
*/
regmap_read(rk808->regmap, RK817_GAS_GAUGE_OFF_CNT, &off_time); if (off_time >= 3) {
regmap_bulk_read(rk808->regmap,
RK817_GAS_GAUGE_PWRON_VOL_H,
bulk_reg, 2);
tmp = get_unaligned_be16(bulk_reg);
boot_voltage = (charger->voltage_k * tmp) +
1000 * charger->voltage_b;
charger->soc =
power_supply_batinfo_ocv2cap(bat_info,
boot_voltage,
20) * 1000;
} else {
charger->soc = (boot_charge_mah * 1000 * 100 /
charger->fcc_mah);
}
}
/* * Now we have our full charge capacity and soc, init the columb * counter.
*/
boot_charge_mah = charger->soc * charger->fcc_mah / 100 / 1000; if (boot_charge_mah > charger->fcc_mah)
boot_charge_mah = charger->fcc_mah;
tmp = CHARGE_TO_ADC(boot_charge_mah, charger->res_div);
put_unaligned_be32(tmp, bulk_reg);
ret = regmap_bulk_write(rk808->regmap, RK817_GAS_GAUGE_Q_INIT_H3,
bulk_reg, 4); if (ret < 0) return ret;
/* Set QMAX value to max design capacity. */
tmp = CHARGE_TO_ADC((charger->bat_charge_full_design_uah / 1000),
charger->res_div);
put_unaligned_be32(tmp, bulk_reg);
ret = regmap_bulk_write(rk808->regmap, RK817_GAS_GAUGE_Q_MAX_H3,
bulk_reg, 4); if (ret < 0) return ret;
/* Get initial plug state */
regmap_read(rk808->regmap, RK817_SYS_STS, &tmp);
charger->plugged_in = (tmp & RK817_PLUG_IN_STS);
/* * Turn on all ADC functions to measure battery, USB, and sys voltage, * as well as batt temp. Note only tested implementation so far does * not use a battery with a thermistor.
*/
regmap_write(rk808->regmap, RK817_GAS_GAUGE_ADC_CONFIG0, 0xfc);
/* * Set relax mode voltage sampling interval and ADC offset calibration * interval to 8 minutes to mirror BSP kernel. Set voltage and current * modes to average to mirror BSP kernel.
*/
regmap_write(rk808->regmap, RK817_GAS_GAUGE_GG_CON, 0x04);
/* Calibrate voltage like the BSP does here. */
rk817_bat_calib_vol(charger);
/* Write relax threshold, derived from sleep enter current. */
tmp = CURRENT_TO_ADC(charger->sleep_enter_current_ua,
charger->res_div);
put_unaligned_be16(tmp, bulk_reg);
regmap_bulk_write(rk808->regmap, RK817_GAS_GAUGE_RELAX_THRE_H,
bulk_reg, 2);
/* * Set OCV Threshold Voltage to 127.5mV. This was hard coded like this * in the BSP.
*/
regmap_write(rk808->regmap, RK817_GAS_GAUGE_OCV_THRE_VOL, 0xff);
/* * Set maximum charging voltage to battery max voltage. Trying to be * incredibly safe with these value, as setting them wrong could * overcharge the battery, which would be very bad.
*/
max_chg_vol_mv = bat_info->constant_charge_voltage_max_uv / 1000;
max_chg_cur_ma = bat_info->constant_charge_current_max_ua / 1000;
if (max_chg_vol_mv < 4100) { return dev_err_probe(charger->dev, -EINVAL, "invalid max charger voltage, value %u unsupported\n",
max_chg_vol_mv * 1000);
} if (max_chg_vol_mv > 4450) {
dev_info(charger->dev, "Setting max charge voltage to 4450000uv\n");
max_chg_vol_mv = 4450;
}
if (max_chg_cur_ma < 500) { return dev_err_probe(charger->dev, -EINVAL, "invalid max charger current, value %u unsupported\n",
max_chg_cur_ma * 1000);
} if (max_chg_cur_ma > 3500)
dev_info(charger->dev, "Setting max charge current to 3500000ua\n");
/* * Now that the values are sanity checked, if we subtract 4100 from the * max voltage and divide by 50, we conviently get the exact value for * the registers, which are 4.1v, 4.15v, 4.2v, 4.25v, 4.3v, 4.35v, * 4.4v, and 4.45v; these correspond to values 0x00 through 0x07.
*/
max_chg_vol_reg = (max_chg_vol_mv - 4100) / 50;
if (max_chg_vol_reg < 0 || max_chg_vol_reg > 7) { return dev_err_probe(charger->dev, -EINVAL, "invalid max charger voltage, value %u unsupported\n",
max_chg_vol_mv * 1000);
} if (max_chg_cur_reg < 0 || max_chg_cur_reg > 7) { return dev_err_probe(charger->dev, -EINVAL, "invalid max charger current, value %u unsupported\n",
max_chg_cur_ma * 1000);
}
/* * Write the values to the registers, and deliver an emergency warning * in the event they are not written correctly.
*/
ret = regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_OUT,
RK817_CHRG_VOL_SEL, (max_chg_vol_reg << 4)); if (ret) {
dev_emerg(charger->dev, "Danger, unable to set max charger voltage: %u\n",
ret);
}
ret = regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_OUT,
RK817_CHRG_CUR_SEL, max_chg_cur_reg); if (ret) {
dev_emerg(charger->dev, "Danger, unable to set max charger current: %u\n",
ret);
}
/* Set charge finishing mode to analog */
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_TERM,
RK817_CHRG_TERM_ANA_DIG, (0x0 << 2));
/* * Set charge finish current, warn if value not in range and keep * default.
*/
chg_term_ma = bat_info->charge_term_current_ua / 1000; if (chg_term_ma < 150 || chg_term_ma > 400) {
dev_warn(charger->dev, "Invalid charge termination %u, keeping default\n",
chg_term_ma * 1000);
chg_term_ma = 200;
}
/* * Values of 150ma, 200ma, 300ma, and 400ma correspond to 00, 01, 10, * and 11.
*/
chg_term_i_reg = (chg_term_ma - 100) / 100;
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_TERM,
RK817_CHRG_TERM_ANA_SEL, chg_term_i_reg);
ret = rk817_read_or_set_full_charge_on_boot(charger, bat_info); if (ret < 0) return ret;
/* * Set minimum USB input voltage to 4.5v and enable USB voltage input * limit.
*/
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN,
RK817_USB_VLIM_SEL, (0x05 << 4));
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, RK817_USB_VLIM_EN,
(0x01 << 7));
/* * Set average USB input current limit to 1.5A and enable USB current * input limit.
*/
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN,
RK817_USB_ILIM_SEL, 0x03);
regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, RK817_USB_ILIM_EN,
(0x01 << 3));
/* * Get sample resistor value. Note only values of 10000 or 20000 * microohms are allowed. Schematic for my test implementation (an * Odroid Go Advance) shows a 10 milliohm resistor for reference.
*/
ret = of_property_read_u32(node, "rockchip,resistor-sense-micro-ohms",
&of_value); if (ret < 0) { return dev_err_probe(dev, ret, "Error reading sample resistor value\n");
} /* * Store as a 1 or a 2, since all we really use the value for is as a * divisor in some calculations.
*/
charger->res_div = (of_value == 20000) ? 2 : 1;
/* * Get sleep enter current value. Not sure what this value is for * other than to help calibrate the relax threshold.
*/
ret = of_property_read_u32(node, "rockchip,sleep-enter-current-microamp",
&of_value); if (ret < 0) { return dev_err_probe(dev, ret, "Error reading sleep enter cur value\n");
}
charger->sleep_enter_current_ua = of_value;
/* Get sleep filter current value */
ret = of_property_read_u32(node, "rockchip,sleep-filter-current-microamp",
&of_value); if (ret < 0) { return dev_err_probe(dev, ret, "Error reading sleep filter cur value\n");
}
charger->sleep_filter_current_ua = of_value;
charger->bat_ps = devm_power_supply_register(&pdev->dev,
&rk817_bat_desc, &pscfg); if (IS_ERR(charger->bat_ps)) return dev_err_probe(dev, -EINVAL, "Battery failed to probe\n");
charger->chg_ps = devm_power_supply_register(&pdev->dev,
&rk817_chg_desc, &pscfg); if (IS_ERR(charger->chg_ps)) return dev_err_probe(dev, -EINVAL, "Charger failed to probe\n");
ret = power_supply_get_battery_info(charger->bat_ps,
&bat_info); if (ret) { return dev_err_probe(dev, ret, "Unable to get battery info\n");
}
if ((bat_info->charge_full_design_uah <= 0) ||
(bat_info->voltage_min_design_uv <= 0) ||
(bat_info->voltage_max_design_uv <= 0) ||
(bat_info->constant_charge_voltage_max_uv <= 0) ||
(bat_info->constant_charge_current_max_ua <= 0) ||
(bat_info->charge_term_current_ua <= 0)) { return dev_err_probe(dev, -EINVAL, "Required bat info missing or invalid\n");
}
/* * Has to run after power_supply_get_battery_info as it depends on some * values discovered from that routine.
*/
ret = rk817_battery_init(charger, bat_info); if (ret) return ret;
MODULE_DESCRIPTION("Battery power supply driver for RK817 PMIC");
MODULE_AUTHOR("Maya Matuszczyk ");
MODULE_AUTHOR("Chris Morgan ");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:rk817-charger");
Messung V0.5
¤ Dauer der Verarbeitung: 0.5 Sekunden
(vorverarbeitet)
¤
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.