1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-11-29 21:12:06 +00:00

Fixes to battery charger and fuel gauge ICs

This commit is contained in:
CTCaer 2020-04-30 03:45:19 +03:00
parent c2e8d51115
commit 2c4d6552e9
6 changed files with 26 additions and 0 deletions

View file

@ -31,6 +31,7 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value)
case BQ24193_InputVoltageLimit: // Input voltage limit (mV). case BQ24193_InputVoltageLimit: // Input voltage limit (mV).
data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_InputSource); data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_InputSource);
data = (data & BQ24193_INCONFIG_VINDPM_MASK) >> 3; data = (data & BQ24193_INCONFIG_VINDPM_MASK) >> 3;
*value = 0;
*value += ((data >> 0) & 1) ? 80 : 0; *value += ((data >> 0) & 1) ? 80 : 0;
*value += ((data >> 1) & 1) ? 160 : 0; *value += ((data >> 1) & 1) ? 160 : 0;
*value += ((data >> 2) & 1) ? 320 : 0; *value += ((data >> 2) & 1) ? 320 : 0;
@ -77,6 +78,7 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value)
case BQ24193_FastChargeCurrentLimit: // Fast charge current limit (mA). case BQ24193_FastChargeCurrentLimit: // Fast charge current limit (mA).
data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgCurr); data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgCurr);
data = (data & BQ24193_CHRGCURR_ICHG_MASK) >> 2; data = (data & BQ24193_CHRGCURR_ICHG_MASK) >> 2;
*value = 0;
*value += ((data >> 0) & 1) ? 64 : 0; *value += ((data >> 0) & 1) ? 64 : 0;
*value += ((data >> 1) & 1) ? 128 : 0; *value += ((data >> 1) & 1) ? 128 : 0;
*value += ((data >> 2) & 1) ? 256 : 0; *value += ((data >> 2) & 1) ? 256 : 0;
@ -92,6 +94,7 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value)
case BQ24193_ChargeVoltageLimit: // Charge voltage limit (mV). case BQ24193_ChargeVoltageLimit: // Charge voltage limit (mV).
data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgVolt); data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgVolt);
data = (data & BQ24193_CHRGVOLT_VREG) >> 2; data = (data & BQ24193_CHRGVOLT_VREG) >> 2;
*value = 0;
*value += ((data >> 0) & 1) ? 16 : 0; *value += ((data >> 0) & 1) ? 16 : 0;
*value += ((data >> 1) & 1) ? 32 : 0; *value += ((data >> 1) & 1) ? 32 : 0;
*value += ((data >> 2) & 1) ? 64 : 0; *value += ((data >> 2) & 1) ? 64 : 0;

View file

@ -46,6 +46,12 @@
#pragma GCC push_options #pragma GCC push_options
#pragma GCC optimize ("Os") #pragma GCC optimize ("Os")
static u32 battery_voltage = 0;
u32 max17050_get_cached_batt_volt()
{
return battery_voltage;
}
int max17050_get_property(enum MAX17050_reg reg, int *value) int max17050_get_property(enum MAX17050_reg reg, int *value)
{ {
u16 data; u16 data;
@ -74,6 +80,7 @@ int max17050_get_property(enum MAX17050_reg reg, int *value)
case MAX17050_VCELL: // Voltage now. case MAX17050_VCELL: // Voltage now.
i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_VCELL); i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_VCELL);
*value = data * 625 / 8 / 1000; *value = data * 625 / 8 / 1000;
battery_voltage = *value;
break; break;
case MAX17050_AvgVCELL: // Voltage avg. case MAX17050_AvgVCELL: // Voltage avg.
i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_AvgVCELL); i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_AvgVCELL);

View file

@ -24,6 +24,8 @@
#ifndef __MAX17050_H_ #ifndef __MAX17050_H_
#define __MAX17050_H_ #define __MAX17050_H_
#include "../utils/types.h"
#define MAX17050_STATUS_BattAbsent (1 << 3) #define MAX17050_STATUS_BattAbsent (1 << 3)
#define MAX17050_DEFAULT_SNS_RESISTOR 10000 #define MAX17050_DEFAULT_SNS_RESISTOR 10000
@ -128,5 +130,6 @@ enum MAX17050_reg {
int max17050_get_property(enum MAX17050_reg reg, int *value); int max17050_get_property(enum MAX17050_reg reg, int *value);
int max17050_fix_configuration(); int max17050_fix_configuration();
u32 max17050_get_cached_batt_volt();
#endif /* __MAX17050_H_ */ #endif /* __MAX17050_H_ */

View file

@ -28,6 +28,7 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value)
case BQ24193_InputVoltageLimit: // Input voltage limit (mV). case BQ24193_InputVoltageLimit: // Input voltage limit (mV).
data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_InputSource); data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_InputSource);
data = (data & BQ24193_INCONFIG_VINDPM_MASK) >> 3; data = (data & BQ24193_INCONFIG_VINDPM_MASK) >> 3;
*value = 0;
*value += ((data >> 0) & 1) ? 80 : 0; *value += ((data >> 0) & 1) ? 80 : 0;
*value += ((data >> 1) & 1) ? 160 : 0; *value += ((data >> 1) & 1) ? 160 : 0;
*value += ((data >> 2) & 1) ? 320 : 0; *value += ((data >> 2) & 1) ? 320 : 0;
@ -74,6 +75,7 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value)
case BQ24193_FastChargeCurrentLimit: // Fast charge current limit (mA). case BQ24193_FastChargeCurrentLimit: // Fast charge current limit (mA).
data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgCurr); data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgCurr);
data = (data & BQ24193_CHRGCURR_ICHG_MASK) >> 2; data = (data & BQ24193_CHRGCURR_ICHG_MASK) >> 2;
*value = 0;
*value += ((data >> 0) & 1) ? 64 : 0; *value += ((data >> 0) & 1) ? 64 : 0;
*value += ((data >> 1) & 1) ? 128 : 0; *value += ((data >> 1) & 1) ? 128 : 0;
*value += ((data >> 2) & 1) ? 256 : 0; *value += ((data >> 2) & 1) ? 256 : 0;
@ -89,6 +91,7 @@ int bq24193_get_property(enum BQ24193_reg_prop prop, int *value)
case BQ24193_ChargeVoltageLimit: // Charge voltage limit (mV). case BQ24193_ChargeVoltageLimit: // Charge voltage limit (mV).
data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgVolt); data = i2c_recv_byte(I2C_1, BQ24193_I2C_ADDR, BQ24193_ChrgVolt);
data = (data & BQ24193_CHRGVOLT_VREG) >> 2; data = (data & BQ24193_CHRGVOLT_VREG) >> 2;
*value = 0;
*value += ((data >> 0) & 1) ? 16 : 0; *value += ((data >> 0) & 1) ? 16 : 0;
*value += ((data >> 1) & 1) ? 32 : 0; *value += ((data >> 1) & 1) ? 32 : 0;
*value += ((data >> 2) & 1) ? 64 : 0; *value += ((data >> 2) & 1) ? 64 : 0;

View file

@ -43,6 +43,12 @@
#define MAX17050_VMAX_TOLERANCE 50 /* 50 mV */ #define MAX17050_VMAX_TOLERANCE 50 /* 50 mV */
static u32 battery_voltage = 0;
u32 max17050_get_cached_batt_volt()
{
return battery_voltage;
}
int max17050_get_property(enum MAX17050_reg reg, int *value) int max17050_get_property(enum MAX17050_reg reg, int *value)
{ {
u16 data; u16 data;
@ -71,6 +77,7 @@ int max17050_get_property(enum MAX17050_reg reg, int *value)
case MAX17050_VCELL: // Voltage now. case MAX17050_VCELL: // Voltage now.
i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_VCELL); i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_VCELL);
*value = data * 625 / 8 / 1000; *value = data * 625 / 8 / 1000;
battery_voltage = *value;
break; break;
case MAX17050_AvgVCELL: // Voltage avg. case MAX17050_AvgVCELL: // Voltage avg.
i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_AvgVCELL); i2c_recv_buf_small((u8 *)&data, 2, I2C_1, MAXIM17050_I2C_ADDR, MAX17050_AvgVCELL);

View file

@ -24,6 +24,8 @@
#ifndef __MAX17050_H_ #ifndef __MAX17050_H_
#define __MAX17050_H_ #define __MAX17050_H_
#include "../utils/types.h"
#define MAX17050_STATUS_BattAbsent (1 << 3) #define MAX17050_STATUS_BattAbsent (1 << 3)
#define MAX17050_DEFAULT_SNS_RESISTOR 10000 #define MAX17050_DEFAULT_SNS_RESISTOR 10000
@ -128,5 +130,6 @@ enum MAX17050_reg {
int max17050_get_property(enum MAX17050_reg reg, int *value); int max17050_get_property(enum MAX17050_reg reg, int *value);
int max17050_fix_configuration(); int max17050_fix_configuration();
u32 max17050_get_cached_batt_volt();
#endif /* __MAX17050_H_ */ #endif /* __MAX17050_H_ */