Skip to content

Commit

Permalink
Merge pull request #46 from 916BGAI/main
Browse files Browse the repository at this point in the history
Optimize AXP2101 PMU
  • Loading branch information
Z2Z-GuGu authored Sep 6, 2024
2 parents 752683e + d116757 commit 40170c1
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 111 deletions.
31 changes: 31 additions & 0 deletions buildroot/board/cvitek/SG200X/overlay/etc/init.d/S00pmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

if ! command -v i2cget &> /dev/null
then
echo "i2cdetect not find, please install i2c-tools"
exit 1
fi

pmu_version=$(i2cget -y 4 0x34 0x03)
pmu_version=$((pmu_version & 0xCF))

chip_id_1=$(printf "%d" 0x47)
chip_id_2=$(printf "%d" 0x4a)

if [ "$pmu_version" -eq "$chip_id_1" ] || [ "$pmu_version" -eq "$chip_id_2" ]; then
case "$1" in
start)
exec /usr/bin/axp2101
echo "Starting PMU: OK\n"
;;
stop)
runlevel=$(cat /run/runlevel | awk '{ print $1 }')
if [ "$runlevel" = "0" ]; then
printf "Stopping PMU\n"
value=$(i2cget -y 4 0x34 0x10)
value=$((value | 0x01))
i2cset -y 4 0x34 0x10 $value
fi
;;
esac
fi
13 changes: 0 additions & 13 deletions buildroot/board/cvitek/SG200X/overlay/etc/init.d/S99pmu

This file was deleted.

22 changes: 11 additions & 11 deletions buildroot/package/axp2101/src/XPowersLib/XPowersAXP2101.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ public:
return getRegisterBit(XPOWERS_AXP2101_STATUS2, 3) == 0 && isVbusGood();
}

xpowers_chg_status_t getChargerStatus(void)
uint8_t getChargerStatus(void)
{
int val = readRegister(XPOWERS_AXP2101_STATUS2);
if (val == -1)return XPOWERS_AXP2101_CHG_STOP_STATE;
val &= 0x07;
return (xpowers_chg_status_t)val;
return (uint8_t)val;
}

/*
Expand Down Expand Up @@ -472,12 +472,12 @@ public:
}

// Linear Charger Vsys voltage dpm
void setLinearChargerVsysDpm(xpower_chg_dpm_t opt)
void setLinearChargerVsysDpm(uint8_t opt)
{
int val = readRegister(XPOWERS_AXP2101_MIN_SYS_VOL_CTRL);
if (val == -1)return;
val &= 0x8F;
writeRegister(XPOWERS_AXP2101_MIN_SYS_VOL_CTRL, val | (opt << 4));
writeRegister(XPOWERS_AXP2101_MIN_SYS_VOL_CTRL, opt);
}

uint8_t getLinearChargerVsysDpm(void)
Expand All @@ -490,12 +490,12 @@ public:

// Set the minimum common working voltage of the PMU VBUS input,
// below this value will turn off the PMU
void setVbusVoltageLimit(xpower_vbus_vol_limit_t opt)
bool setVbusVoltageLimit(uint8_t opt)
{
int val = readRegister(XPOWERS_AXP2101_INPUT_VOL_LIMIT_CTRL);
if (val == -1)return;
if (val == -1)return false;
val &= 0xF0;
writeRegister(XPOWERS_AXP2101_INPUT_VOL_LIMIT_CTRL, val | (opt & 0x0F));
return 0 == writeRegister(XPOWERS_AXP2101_INPUT_VOL_LIMIT_CTRL, val | (opt & 0x0F));
}

uint8_t getVbusVoltageLimit(void)
Expand Down Expand Up @@ -2357,8 +2357,8 @@ public:
int val;
switch (mode) {
case XPOWERS_CHG_LED_OFF:
// clrRegisterBit(XPOWERS_AXP2101_CHGLED_SET_CTRL, 0);
// break;
clrRegisterBit(XPOWERS_AXP2101_CHGLED_SET_CTRL, 0);
break;
case XPOWERS_CHG_LED_BLINK_1HZ:
case XPOWERS_CHG_LED_BLINK_4HZ:
case XPOWERS_CHG_LED_ON:
Expand Down Expand Up @@ -2399,7 +2399,7 @@ public:
* @param opt: 25 * opt
* @retval None
*/
void setPrechargeCurr(xpowers_prechg_t opt)
void setPrechargeCurr(uint8_t opt)
{
int val = readRegister(XPOWERS_AXP2101_IPRECHG_SET);
if (val == -1)return;
Expand Down Expand Up @@ -2443,7 +2443,7 @@ public:
* @note Charging termination of current limit
* @retval
*/
void setChargerTerminationCurr(xpowers_axp2101_chg_iterm_t opt)
void setChargerTerminationCurr(uint8_t opt)
{
int val = readRegister(XPOWERS_AXP2101_ITERM_CHG_SET_CTRL);
if (val == -1)return;
Expand Down
23 changes: 20 additions & 3 deletions buildroot/package/axp2101/src/XPowersLib/XPowersLibInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,23 @@ class XPowersLibInterface : public HasBatteryLevel
*/
virtual bool isChannelAvailable(uint8_t channel);

virtual void setPrechargeCurr(uint8_t opt) = 0;
virtual void disableChargerTerminationLimit(void) = 0;

virtual bool setVbusVoltageLimit(uint8_t opt) = 0;
virtual uint8_t getVbusVoltageLimit(void) = 0;

virtual bool isStandby(void) = 0;
virtual bool isVbusGood(void) = 0;
virtual uint8_t getChargerStatus(void) = 0;
virtual void enableCellbatteryCharge(void) = 0;
virtual void enableGauge(void) = 0;
virtual void disableGauge(void) = 0;
virtual void setLinearChargerVsysDpm(uint8_t opt) = 0;
virtual void disablePwronShutPMIC(void) = 0;

virtual void fuelGaugeControl(bool writeROM, bool enable) = 0;
virtual void printIntRegister() = 0;

//battery
/**
Expand Down Expand Up @@ -421,7 +438,6 @@ class XPowersLibInterface : public HasBatteryLevel
*/
virtual uint64_t getIrqStatus() = 0;


/**
* @brief Clear interrupt controller state.
*/
Expand Down Expand Up @@ -597,8 +613,9 @@ class XPowersLibInterface : public HasBatteryLevel
* parameters in "XPowersParams.hpp"
*/
virtual void setChargingLedMode(uint8_t mode) = 0;


virtual void setChargerTerminationCurr(uint8_t opt) = 0;
virtual void disableDieOverTempDetect(void) = 0;
virtual void resetGauge(void) = 0;

// PMU PEKEY settings
/**
Expand Down
Loading

0 comments on commit 40170c1

Please sign in to comment.