summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-01-09 18:57:12 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-01-09 19:58:35 +0000
commiteee8243102460986ba1733222ebdbe9ac3200d77 (patch)
treea6fb7e2abadedb5c5cf6ff9125b80365cb0733ce
parenteaee5e7339aec46b4b67f06b139b8708810a4c2e (diff)
downloadrockbox-eee8243102.tar.gz
rockbox-eee8243102.tar.bz2
rockbox-eee8243102.zip
axp-pmu: clean up charge current setting
Change-Id: Ifac30f728887c376a83052c826b4bb6a98bbd27a
-rw-r--r--firmware/drivers/axp-pmu.c43
-rw-r--r--firmware/export/axp-pmu.h2
2 files changed, 14 insertions, 31 deletions
diff --git a/firmware/drivers/axp-pmu.c b/firmware/drivers/axp-pmu.c
index fd1126dbbf..e9af3c0b05 100644
--- a/firmware/drivers/axp-pmu.c
+++ b/firmware/drivers/axp-pmu.c
@@ -128,7 +128,6 @@ static const struct axp_supply_info axp_supply_info[AXP_NUM_SUPPLIES] = {
static struct axp_driver {
int adc_enable;
- int chargecurrent_setting;
int chip_id;
} axp;
@@ -173,10 +172,6 @@ void axp_init(void)
int bits = axp.adc_enable;
bits |= (1 << ADC_DISCHARGE_CURRENT);
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)
@@ -468,38 +463,26 @@ static const int chargecurrent_tbl[] = {
1080, 1160, 1240, 1320,
};
-static const int chargecurrent_tblsz = sizeof(chargecurrent_tbl)/sizeof(int);
-
-void axp_set_charge_current(int maxcurrent)
+void axp_set_charge_current(int current_mA)
{
- /* Find the charge current just higher than maxcurrent */
- int value = 0;
- while(value < chargecurrent_tblsz &&
- chargecurrent_tbl[value] <= maxcurrent)
- ++value;
-
- /* 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;
+ /* find greatest charging current not exceeding requested current */
+ unsigned int index = 0;
+ while(index < ARRAYLEN(chargecurrent_tbl)-1 &&
+ chargecurrent_tbl[index+1] <= current_mA)
+ ++index;
- /* Update register */
i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
- AXP_REG_CHARGECONTROL1, 0x0f, value, NULL);
- axp.chargecurrent_setting = value;
+ AXP_REG_CHARGECONTROL1, 0x0f, index, NULL);
}
int axp_get_charge_current(void)
{
- if(axp.chargecurrent_setting < 0)
- return chargecurrent_tbl[0];
- else
- return chargecurrent_tbl[axp.chargecurrent_setting];
+ int ret = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_CHARGECONTROL1);
+ if(ret < 0)
+ ret = 0;
+
+ return chargecurrent_tbl[ret & 0x0f];
}
void axp_power_off(void)
diff --git a/firmware/export/axp-pmu.h b/firmware/export/axp-pmu.h
index 457f746e8c..553410ced8 100644
--- a/firmware/export/axp-pmu.h
+++ b/firmware/export/axp-pmu.h
@@ -139,7 +139,7 @@ extern void axp_cc_enable(bool en);
extern bool axp_cc_is_enabled(void);
/* 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);
/* Set the shutdown bit */