mirror of
https://github.com/CTCaer/hekate.git
synced 2024-11-26 03:32:17 +00:00
reg5V: Manage battery source based on charger status
This commit is contained in:
parent
74b91b0085
commit
c6c396ce2a
7 changed files with 33 additions and 14 deletions
|
@ -808,10 +808,10 @@ void jc_power_supply(u8 uart, bool enable)
|
||||||
{
|
{
|
||||||
if (enable)
|
if (enable)
|
||||||
{
|
{
|
||||||
if (regulator_get_5v_dev_enabled(1 << uart))
|
if (regulator_5v_get_dev_enabled(1 << uart))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
regulator_enable_5v(1 << uart);
|
regulator_5v_enable(1 << uart);
|
||||||
|
|
||||||
if (jc_init_done)
|
if (jc_init_done)
|
||||||
{
|
{
|
||||||
|
@ -841,10 +841,10 @@ void jc_power_supply(u8 uart, bool enable)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!regulator_get_5v_dev_enabled(1 << uart))
|
if (!regulator_5v_get_dev_enabled(1 << uart))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
regulator_disable_5v(1 << uart);
|
regulator_5v_disable(1 << uart);
|
||||||
|
|
||||||
if (uart == UART_C)
|
if (uart == UART_C)
|
||||||
gpio_write(GPIO_PORT_CC, GPIO_PIN_3, GPIO_LOW);
|
gpio_write(GPIO_PORT_CC, GPIO_PIN_3, GPIO_LOW);
|
||||||
|
|
|
@ -21,8 +21,9 @@
|
||||||
#include <utils/types.h>
|
#include <utils/types.h>
|
||||||
|
|
||||||
static u8 reg_5v_dev = 0;
|
static u8 reg_5v_dev = 0;
|
||||||
|
static bool batt_src = false;
|
||||||
|
|
||||||
void regulator_enable_5v(u8 dev)
|
void regulator_5v_enable(u8 dev)
|
||||||
{
|
{
|
||||||
// The power supply selection from battery or USB is automatic.
|
// The power supply selection from battery or USB is automatic.
|
||||||
if (!reg_5v_dev)
|
if (!reg_5v_dev)
|
||||||
|
@ -32,6 +33,7 @@ void regulator_enable_5v(u8 dev)
|
||||||
gpio_config(GPIO_PORT_A, GPIO_PIN_5, GPIO_MODE_GPIO);
|
gpio_config(GPIO_PORT_A, GPIO_PIN_5, GPIO_MODE_GPIO);
|
||||||
gpio_output_enable(GPIO_PORT_A, GPIO_PIN_5, GPIO_OUTPUT_ENABLE);
|
gpio_output_enable(GPIO_PORT_A, GPIO_PIN_5, GPIO_OUTPUT_ENABLE);
|
||||||
gpio_write(GPIO_PORT_A, GPIO_PIN_5, GPIO_HIGH);
|
gpio_write(GPIO_PORT_A, GPIO_PIN_5, GPIO_HIGH);
|
||||||
|
batt_src = true;
|
||||||
|
|
||||||
// Fan and Rail power from USB 5V VDD.
|
// Fan and Rail power from USB 5V VDD.
|
||||||
PINMUX_AUX(PINMUX_AUX_USB_VBUS_EN0) = PINMUX_LPDR | 1;
|
PINMUX_AUX(PINMUX_AUX_USB_VBUS_EN0) = PINMUX_LPDR | 1;
|
||||||
|
@ -47,7 +49,7 @@ void regulator_enable_5v(u8 dev)
|
||||||
reg_5v_dev |= dev;
|
reg_5v_dev |= dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
void regulator_disable_5v(u8 dev)
|
void regulator_5v_disable(u8 dev)
|
||||||
{
|
{
|
||||||
reg_5v_dev &= ~dev;
|
reg_5v_dev &= ~dev;
|
||||||
|
|
||||||
|
@ -58,6 +60,7 @@ void regulator_disable_5v(u8 dev)
|
||||||
gpio_output_enable(GPIO_PORT_A, GPIO_PIN_5, GPIO_OUTPUT_DISABLE);
|
gpio_output_enable(GPIO_PORT_A, GPIO_PIN_5, GPIO_OUTPUT_DISABLE);
|
||||||
gpio_config(GPIO_PORT_A, GPIO_PIN_5, GPIO_MODE_SPIO);
|
gpio_config(GPIO_PORT_A, GPIO_PIN_5, GPIO_MODE_SPIO);
|
||||||
PINMUX_AUX(PINMUX_AUX_SATA_LED_ACTIVE) = PINMUX_PARKED | PINMUX_INPUT_ENABLE;
|
PINMUX_AUX(PINMUX_AUX_SATA_LED_ACTIVE) = PINMUX_PARKED | PINMUX_INPUT_ENABLE;
|
||||||
|
batt_src = false;
|
||||||
|
|
||||||
// Rail power from USB 5V VDD.
|
// Rail power from USB 5V VDD.
|
||||||
gpio_write(GPIO_PORT_CC, GPIO_PIN_4, GPIO_LOW);
|
gpio_write(GPIO_PORT_CC, GPIO_PIN_4, GPIO_LOW);
|
||||||
|
@ -70,7 +73,15 @@ void regulator_disable_5v(u8 dev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool regulator_get_5v_dev_enabled(u8 dev)
|
bool regulator_5v_get_dev_enabled(u8 dev)
|
||||||
{
|
{
|
||||||
return (reg_5v_dev & dev);
|
return (reg_5v_dev & dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void regulator_5v_batt_src_enable(bool enable)
|
||||||
|
{
|
||||||
|
if (enable && !batt_src)
|
||||||
|
gpio_write(GPIO_PORT_A, GPIO_PIN_5, GPIO_HIGH);
|
||||||
|
else if (!enable && batt_src)
|
||||||
|
gpio_write(GPIO_PORT_A, GPIO_PIN_5, GPIO_LOW);
|
||||||
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@ enum
|
||||||
REGULATOR_5V_ALL = 0xFF
|
REGULATOR_5V_ALL = 0xFF
|
||||||
};
|
};
|
||||||
|
|
||||||
void regulator_enable_5v(u8 dev);
|
void regulator_5v_enable(u8 dev);
|
||||||
void regulator_disable_5v(u8 dev);
|
void regulator_5v_disable(u8 dev);
|
||||||
bool regulator_get_5v_dev_enabled(u8 dev);
|
bool regulator_5v_get_dev_enabled(u8 dev);
|
||||||
|
void regulator_5v_batt_src_enable(bool enable);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -429,7 +429,7 @@ void hw_reinit_workaround(bool coreboot, u32 magic)
|
||||||
touch_power_off();
|
touch_power_off();
|
||||||
set_fan_duty(0);
|
set_fan_duty(0);
|
||||||
jc_deinit();
|
jc_deinit();
|
||||||
regulator_disable_5v(REGULATOR_5V_ALL);
|
regulator_5v_disable(REGULATOR_5V_ALL);
|
||||||
clock_disable_uart(UART_B);
|
clock_disable_uart(UART_B);
|
||||||
clock_disable_uart(UART_C);
|
clock_disable_uart(UART_C);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,7 +56,7 @@ void set_fan_duty(u32 duty)
|
||||||
if (inv_duty == 236)
|
if (inv_duty == 236)
|
||||||
{
|
{
|
||||||
PWM(PWM_CONTROLLER_PWM_CSR_1) = PWM_CSR_EN | (0x100 << 16); // Bit 24 is absolute 0%.
|
PWM(PWM_CONTROLLER_PWM_CSR_1) = PWM_CSR_EN | (0x100 << 16); // Bit 24 is absolute 0%.
|
||||||
regulator_disable_5v(REGULATOR_5V_FAN);
|
regulator_5v_disable(REGULATOR_5V_FAN);
|
||||||
|
|
||||||
// Disable fan.
|
// Disable fan.
|
||||||
PINMUX_AUX(PINMUX_AUX_LCD_GPIO2) =
|
PINMUX_AUX(PINMUX_AUX_LCD_GPIO2) =
|
||||||
|
@ -65,7 +65,7 @@ void set_fan_duty(u32 duty)
|
||||||
else // Set PWM duty.
|
else // Set PWM duty.
|
||||||
{
|
{
|
||||||
// Fan power supply.
|
// Fan power supply.
|
||||||
regulator_enable_5v(REGULATOR_5V_FAN);
|
regulator_5v_enable(REGULATOR_5V_FAN);
|
||||||
PWM(PWM_CONTROLLER_PWM_CSR_1) = PWM_CSR_EN | (inv_duty << 16);
|
PWM(PWM_CONTROLLER_PWM_CSR_1) = PWM_CSR_EN | (inv_duty << 16);
|
||||||
|
|
||||||
// Enable fan.
|
// Enable fan.
|
||||||
|
|
|
@ -29,7 +29,7 @@ u8 btn_read()
|
||||||
res |= BTN_VOL_DOWN;
|
res |= BTN_VOL_DOWN;
|
||||||
if (!gpio_read(GPIO_PORT_X, GPIO_PIN_6))
|
if (!gpio_read(GPIO_PORT_X, GPIO_PIN_6))
|
||||||
res |= BTN_VOL_UP;
|
res |= BTN_VOL_UP;
|
||||||
if (i2c_recv_byte(4, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFSTAT) & MAX77620_ONOFFSTAT_EN0)
|
if (i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFSTAT) & MAX77620_ONOFFSTAT_EN0)
|
||||||
res |= BTN_POWER;
|
res |= BTN_POWER;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include <mem/minerva.h>
|
#include <mem/minerva.h>
|
||||||
#include <power/bq24193.h>
|
#include <power/bq24193.h>
|
||||||
#include <power/max17050.h>
|
#include <power/max17050.h>
|
||||||
|
#include <power/regulator_5v.h>
|
||||||
#include <rtc/max77620-rtc.h>
|
#include <rtc/max77620-rtc.h>
|
||||||
#include <soc/bpmp.h>
|
#include <soc/bpmp.h>
|
||||||
#include <soc/fuse.h>
|
#include <soc/fuse.h>
|
||||||
|
@ -1263,8 +1264,14 @@ static void _update_status_bar(void *params)
|
||||||
else
|
else
|
||||||
strcat(label, "#FF3C28 "SYMBOL_BATTERY_EMPTY"#");
|
strcat(label, "#FF3C28 "SYMBOL_BATTERY_EMPTY"#");
|
||||||
|
|
||||||
|
// Set charging symbol and regulator 5V source based on USB state.
|
||||||
if (charge_status)
|
if (charge_status)
|
||||||
|
{
|
||||||
strcat(label, " #FFDD00 "SYMBOL_CHARGE"#");
|
strcat(label, " #FFDD00 "SYMBOL_CHARGE"#");
|
||||||
|
regulator_5v_batt_src_enable(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
regulator_5v_batt_src_enable(true);
|
||||||
|
|
||||||
lv_label_set_text(status_bar.battery, label);
|
lv_label_set_text(status_bar.battery, label);
|
||||||
lv_obj_realign(status_bar.battery);
|
lv_obj_realign(status_bar.battery);
|
||||||
|
|
Loading…
Reference in a new issue