/* * This is invoked when the charge is complete. The conarge complete condition * is configurable, and can be set to be an input from a charger or, the gauge * itself can detect charge complete condition. * On charge complete, if charge cycle is qualified, the gauge learns a * capacity. * This is can be invoked from either foreground, or background context. */ static void fg_charge_complete(struct cell_state *cell) { dev_dbg(cell->dev, "CHG: Charge Complete Detected!\n"); /* Set Charge Complete Flag and Toggle a CC Pin, if configured to */ cell->cc = true; cell->calibrate = true; /* Check if we can Learn capacity on Charge */ if (cell->vcq) { dev_dbg(cell->dev, "LRN: Learned Capacity = %d + %d + %d mAh\n", cell->learn_q, cell->learn_offset, -cell->ocv_total_q); fg_learn_capacity(cell, cell->learn_q + cell->learn_offset - cell->ocv_total_q); } dev_dbg(cell->dev, "CHG: Setting RM to FCC\n"); /* Set Remaining Capacities to Full */ cell->nac = cell->fcc; /* Capacity learning complete */ cell->vcq = false; }
/* * EDV algorithm, should be called on discharge, adjusts NAC, based * on the discharge conditions. Also set EDV2, 1, 0 flags if needed */ void fg_edv(struct cell_state *cell) { /* Check if EDV condition reached and we are above EDV0*/ if (!cell->edv0 && fg_look_for_edv(cell)) { /* EDV2 point reached */ if (!cell->edv2) { /* todo : recalibrate? */ cell->edv2 = true; if (cell->vdq) { dev_dbg(cell->dev, "LRN: Learned Capacity ="\ " %d + %d + %d + %d mAh\n", -cell->learn_q, cell->ocv_total_q, cell->learn_offset, cell->nac); fg_learn_capacity(cell, -cell->learn_q + cell->ocv_total_q + cell->learn_offset + cell->nac); } cell->vdq = false; fg_init_edv(cell, &cell->config->edv->edv[1]); } else if (!cell->edv1) { /* EDV1 point reached */ cell->edv1 = true; fg_init_edv(cell, &cell->config->edv->edv[0]); } else { /* EDV0 point reached */ cell->edv0 = true; } } }