/* Five minutes expressed in seconds */
#define FIVE_MINUTES_IN_SECONDS 300
-#define CHARGALG_CURR_STEP_LOW_UA 0
-#define CHARGALG_CURR_STEP_HIGH_UA 100000
-
/*
* This is the battery capacity limit that will trigger a new
* full charging cycle in the case where maintenance charging
bool usb_suspended;
};
-struct ab8500_chargalg_current_step_status {
- bool curr_step_change;
- int curr_step_ua;
-};
-
struct ab8500_chargalg_battery_data {
int temp;
int volt_uv;
* struct ab8500_charge_curr_maximization - Charger maximization parameters
* @original_iset_ua: the non optimized/maximised charger current
* @current_iset_ua: the charging current used at this moment
- * @test_delta_i_ua: the delta between the current we want to charge and the
- current that is really going into the battery
* @condition_cnt: number of iterations needed before a new charger current
is set
* @max_current_ua: maximum charger current
struct ab8500_charge_curr_maximization {
int original_iset_ua;
int current_iset_ua;
- int test_delta_i_ua;
int condition_cnt;
int max_current_ua;
int wait_cnt;
* @batt_data: data of the battery
* @susp_status: current charger suspension status
* @bm: Platform specific battery management information
- * @curr_status: Current step status for over-current protection
* @parent: pointer to the struct ab8500
* @chargalg_psy: structure that holds the battery properties exposed by
* the charging algorithm
struct ab8500_chargalg_battery_data batt_data;
struct ab8500_chargalg_suspension_status susp_status;
struct ab8500 *parent;
- struct ab8500_chargalg_current_step_status curr_status;
struct ab8500_bm_data *bm;
struct power_supply *chargalg_psy;
struct ux500_charger *ac_chg;
}
/**
- * ab8500_chargalg_check_current_step_status() - Check charging current
- * step status.
- * @di: pointer to the ab8500_chargalg structure
- *
- * This function will check if there is a change in the charging current step
- * and change charge state accordingly.
- */
-static void ab8500_chargalg_check_current_step_status
- (struct ab8500_chargalg *di)
-{
- if (di->curr_status.curr_step_change)
- ab8500_chargalg_state_to(di, STATE_NORMAL_INIT);
- di->curr_status.curr_step_change = false;
-}
-
-/**
* ab8500_chargalg_start_safety_timer() - Start charging safety timer
* @di: pointer to the ab8500_chargalg structure
*
di->ccm.original_iset_ua = bi->constant_charge_current_max_ua;
di->ccm.current_iset_ua = bi->constant_charge_current_max_ua;
- di->ccm.test_delta_i_ua = di->bm->maxi->charger_curr_step_ua;
di->ccm.max_current_ua = di->bm->maxi->chg_curr_ua;
di->ccm.condition_cnt = di->bm->maxi->wait_cycles;
di->ccm.level = 0;
dev_dbg(di->dev, "lowering current\n");
di->ccm.wait_cnt++;
di->ccm.condition_cnt = di->bm->maxi->wait_cycles;
- di->ccm.max_current_ua =
- di->ccm.current_iset_ua - di->ccm.test_delta_i_ua;
+ di->ccm.max_current_ua = di->ccm.current_iset_ua;
di->ccm.current_iset_ua = di->ccm.max_current_ua;
di->ccm.level--;
return MAXIM_RET_CHANGE;
return MAXIM_RET_IBAT_TOO_HIGH;
}
- if (delta_i_ua > di->ccm.test_delta_i_ua &&
- (di->ccm.current_iset_ua + di->ccm.test_delta_i_ua) <
- di->ccm.max_current_ua) {
- if (di->ccm.condition_cnt-- == 0) {
- /* Increse the iset with cco.test_delta_i */
- di->ccm.condition_cnt = di->bm->maxi->wait_cycles;
- di->ccm.current_iset_ua += di->ccm.test_delta_i_ua;
- di->ccm.level++;
- dev_dbg(di->dev, " Maximization needed, increase"
- " with %d uA to %duA (Optimal ibat: %d uA)"
- " Level %d\n",
- di->ccm.test_delta_i_ua,
- di->ccm.current_iset_ua,
- di->ccm.original_iset_ua,
- di->ccm.level);
- return MAXIM_RET_CHANGE;
- } else {
- return MAXIM_RET_NOACTION;
- }
- } else {
- di->ccm.condition_cnt = di->bm->maxi->wait_cycles;
- return MAXIM_RET_NOACTION;
- }
+ di->ccm.condition_cnt = di->bm->maxi->wait_cycles;
+ return MAXIM_RET_NOACTION;
}
static void handle_maxim_chg_curr(struct ab8500_chargalg *di)
struct power_supply_battery_info *bi = di->bm->bi;
int charger_status;
int ret;
- int curr_step_lvl_ua;
/* Collect data from all power_supply class devices */
class_for_each_device(power_supply_class, NULL,
ab8500_chargalg_check_charger_voltage(di);
charger_status = ab8500_chargalg_check_charger_connection(di);
- ab8500_chargalg_check_current_step_status(di);
if (is_ab8500(di->parent)) {
ret = ab8500_chargalg_check_charger_enable(di);
break;
case STATE_NORMAL_INIT:
- if (di->curr_status.curr_step_ua == CHARGALG_CURR_STEP_LOW_UA)
+ if (bi->constant_charge_current_max_ua == 0)
+ /* "charging" with 0 uA */
ab8500_chargalg_stop_charging(di);
else {
- curr_step_lvl_ua = bi->constant_charge_current_max_ua
- * di->curr_status.curr_step_ua
- / CHARGALG_CURR_STEP_HIGH_UA;
ab8500_chargalg_start_charging(di,
bi->constant_charge_voltage_max_uv,
- curr_step_lvl_ua);
+ bi->constant_charge_current_max_ua);
}
ab8500_chargalg_state_to(di, STATE_NORMAL);
/* Exposure to the sysfs interface */
-static ssize_t ab8500_chargalg_curr_step_show(struct ab8500_chargalg *di,
- char *buf)
-{
- return sprintf(buf, "%d\n", di->curr_status.curr_step_ua);
-}
-
-static ssize_t ab8500_chargalg_curr_step_store(struct ab8500_chargalg *di,
- const char *buf, size_t length)
-{
- long param;
- int ret;
-
- ret = kstrtol(buf, 10, ¶m);
- if (ret < 0)
- return ret;
-
- di->curr_status.curr_step_ua = param;
- if (di->curr_status.curr_step_ua >= CHARGALG_CURR_STEP_LOW_UA &&
- di->curr_status.curr_step_ua <= CHARGALG_CURR_STEP_HIGH_UA) {
- di->curr_status.curr_step_change = true;
- queue_work(di->chargalg_wq, &di->chargalg_work);
- } else
- dev_info(di->dev, "Wrong current step\n"
- "Enter 0. Disable AC/USB Charging\n"
- "1--100. Set AC/USB charging current step\n"
- "100. Enable AC/USB Charging\n");
-
- return strlen(buf);
-}
-
-
static ssize_t ab8500_chargalg_en_show(struct ab8500_chargalg *di,
char *buf)
{
__ATTR(chargalg, 0644, ab8500_chargalg_en_show,
ab8500_chargalg_en_store);
-static struct ab8500_chargalg_sysfs_entry ab8500_chargalg_curr_step =
- __ATTR(chargalg_curr_step, 0644, ab8500_chargalg_curr_step_show,
- ab8500_chargalg_curr_step_store);
-
static ssize_t ab8500_chargalg_sysfs_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{
static struct attribute *ab8500_chargalg_chg[] = {
&ab8500_chargalg_en_charger.attr,
- &ab8500_chargalg_curr_step.attr,
NULL,
};
dev_err(di->dev, "failed to create sysfs entry\n");
return ret;
}
- di->curr_status.curr_step_ua = CHARGALG_CURR_STEP_HIGH_UA;
dev_info(di->dev, "probe success\n");
return component_add(dev, &ab8500_chargalg_component_ops);