axp-pmu: clean up charge current setting
Change-Id: Ifac30f728887c376a83052c826b4bb6a98bbd27a
This commit is contained in:
parent
eaee5e7339
commit
eee8243102
2 changed files with 14 additions and 31 deletions
|
@ -128,7 +128,6 @@ static const struct axp_supply_info axp_supply_info[AXP_NUM_SUPPLIES] = {
|
||||||
|
|
||||||
static struct axp_driver {
|
static struct axp_driver {
|
||||||
int adc_enable;
|
int adc_enable;
|
||||||
int chargecurrent_setting;
|
|
||||||
int chip_id;
|
int chip_id;
|
||||||
} axp;
|
} axp;
|
||||||
|
|
||||||
|
@ -173,10 +172,6 @@ void axp_init(void)
|
||||||
int bits = axp.adc_enable;
|
int bits = axp.adc_enable;
|
||||||
bits |= (1 << ADC_DISCHARGE_CURRENT);
|
bits |= (1 << ADC_DISCHARGE_CURRENT);
|
||||||
axp_adc_set_enabled(bits);
|
axp_adc_set_enabled(bits);
|
||||||
|
|
||||||
/* Read the maximum charging current */
|
|
||||||
int value = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_CHARGECONTROL1);
|
|
||||||
axp.chargecurrent_setting = (value < 0) ? -1 : (value & 0xf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void axp_supply_set_voltage(int supply, int voltage)
|
void axp_supply_set_voltage(int supply, int voltage)
|
||||||
|
@ -468,38 +463,26 @@ static const int chargecurrent_tbl[] = {
|
||||||
1080, 1160, 1240, 1320,
|
1080, 1160, 1240, 1320,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int chargecurrent_tblsz = sizeof(chargecurrent_tbl)/sizeof(int);
|
void axp_set_charge_current(int current_mA)
|
||||||
|
|
||||||
void axp_set_charge_current(int maxcurrent)
|
|
||||||
{
|
{
|
||||||
/* Find the charge current just higher than maxcurrent */
|
/* find greatest charging current not exceeding requested current */
|
||||||
int value = 0;
|
unsigned int index = 0;
|
||||||
while(value < chargecurrent_tblsz &&
|
while(index < ARRAYLEN(chargecurrent_tbl)-1 &&
|
||||||
chargecurrent_tbl[value] <= maxcurrent)
|
chargecurrent_tbl[index+1] <= current_mA)
|
||||||
++value;
|
++index;
|
||||||
|
|
||||||
/* Select the next lower current, the greatest current <= maxcurrent */
|
|
||||||
if(value >= chargecurrent_tblsz)
|
|
||||||
value = chargecurrent_tblsz - 1;
|
|
||||||
else if(value > 0)
|
|
||||||
--value;
|
|
||||||
|
|
||||||
/* Don't issue i2c write if desired setting is already in use */
|
|
||||||
if(value == axp.chargecurrent_setting)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Update register */
|
|
||||||
i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
|
i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
|
||||||
AXP_REG_CHARGECONTROL1, 0x0f, value, NULL);
|
AXP_REG_CHARGECONTROL1, 0x0f, index, NULL);
|
||||||
axp.chargecurrent_setting = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int axp_get_charge_current(void)
|
int axp_get_charge_current(void)
|
||||||
{
|
{
|
||||||
if(axp.chargecurrent_setting < 0)
|
int ret = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR,
|
||||||
return chargecurrent_tbl[0];
|
AXP_REG_CHARGECONTROL1);
|
||||||
else
|
if(ret < 0)
|
||||||
return chargecurrent_tbl[axp.chargecurrent_setting];
|
ret = 0;
|
||||||
|
|
||||||
|
return chargecurrent_tbl[ret & 0x0f];
|
||||||
}
|
}
|
||||||
|
|
||||||
void axp_power_off(void)
|
void axp_power_off(void)
|
||||||
|
|
|
@ -139,7 +139,7 @@ extern void axp_cc_enable(bool en);
|
||||||
extern bool axp_cc_is_enabled(void);
|
extern bool axp_cc_is_enabled(void);
|
||||||
|
|
||||||
/* Set/get maximum charging current in milliamps */
|
/* Set/get maximum charging current in milliamps */
|
||||||
extern void axp_set_charge_current(int maxcurrent);
|
extern void axp_set_charge_current(int current_mA);
|
||||||
extern int axp_get_charge_current(void);
|
extern int axp_get_charge_current(void);
|
||||||
|
|
||||||
/* Set the shutdown bit */
|
/* Set the shutdown bit */
|
||||||
|
|
Loading…
Reference in a new issue