int charger_get_current(int *current) { int rv; int reg; rv = sbc_read(SB_CHARGING_CURRENT, ®); if (rv) return rv; *current = REG_TO_CURRENT(reg, R_SNS); return EC_SUCCESS; }
int charger_get_input_current(int *input_current) { int rv; int reg; rv = sbc_read(BQ24735_INPUT_CURRENT, ®); if (rv) return rv; *input_current = REG_TO_CURRENT(reg, R_AC); return EC_SUCCESS; }
int charger_get_current(int *current) { int rv; int reg; rv = i2c_read16(I2C_PORT_CHARGER, BQ24773_ADDR, BQ24773_CHARGE_CURRENT, ®); if (rv) return rv; *current = REG_TO_CURRENT(reg, R_SNS); return EC_SUCCESS; }
int charger_get_input_current(int *input_current) { int rv; int reg; #ifdef CONFIG_CHARGER_BQ24770 rv = raw_read16(REG_INPUT_CURRENT, ®); #elif defined(CONFIG_CHARGER_BQ24773) rv = raw_read8(REG_INPUT_CURRENT, ®); #endif if (rv) return rv; #ifdef CONFIG_CHARGER_BQ24770 *input_current = REG_TO_CURRENT(reg, R_AC); #elif defined(CONFIG_CHARGER_BQ24773) *input_current = REG8_TO_CURRENT(reg, R_AC); #endif return EC_SUCCESS; }
#define R_SNS CONFIG_CHARGER_SENSE_RESISTOR #define R_AC CONFIG_CHARGER_SENSE_RESISTOR_AC #define REG_TO_CURRENT(REG, RS) ((REG) * DEFAULT_SENSE_RESISTOR / (RS)) #define CURRENT_TO_REG(CUR, RS) ((CUR) * (RS) / DEFAULT_SENSE_RESISTOR) /* Charger information * charge voltage bitmask: 0111 1111 1111 0000 * charge current bitmask: 0001 1111 1000 0000 * input current bitmask : 0000 0000 1000 0000 */ static const struct charger_info bq24735_charger_info = { .name = "bq24735", .voltage_max = 19200, .voltage_min = 1024, .voltage_step = 16, .current_max = REG_TO_CURRENT(8128, R_SNS), .current_min = REG_TO_CURRENT(128, R_SNS), .current_step = REG_TO_CURRENT(128, R_SNS), .input_current_max = REG_TO_CURRENT(8064, R_AC), .input_current_min = REG_TO_CURRENT(128, R_AC), .input_current_step = REG_TO_CURRENT(128, R_AC), }; /* bq24735 specific interfaces */ static inline int sbc_read(int cmd, int *param) { return i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param); } static inline int sbc_write(int cmd, int param)
/* Sense resistor configurations and macros */ #define DEFAULT_SENSE_RESISTOR 10 #define R_SNS CONFIG_CHARGER_SENSE_RESISTOR #define R_AC CONFIG_CHARGER_SENSE_RESISTOR_AC #define REG_TO_CURRENT(REG, RS) ((REG) * DEFAULT_SENSE_RESISTOR / (RS)) #define CURRENT_TO_REG(CUR, RS) ((CUR) * (RS) / DEFAULT_SENSE_RESISTOR) /* Note: it is assumed that the sense resistors are 10mOhm. */ static const struct charger_info bq24725_charger_info = { .name = "bq24715", .voltage_max = CHARGE_V_MAX, .voltage_min = CHARGE_V_MIN, .voltage_step = CHARGE_V_STEP, .current_max = REG_TO_CURRENT(CHARGE_I_MAX, R_SNS), .current_min = REG_TO_CURRENT(CHARGE_I_MIN, R_SNS), .current_step = REG_TO_CURRENT(CHARGE_I_STEP, R_SNS), .input_current_max = REG_TO_CURRENT(INPUT_I_MAX, R_AC), .input_current_min = REG_TO_CURRENT(INPUT_I_MIN, R_AC), .input_current_step = REG_TO_CURRENT(INPUT_I_STEP, R_AC), }; static inline int sbc_read(int cmd, int *param) { return i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param); } static inline int sbc_write(int cmd, int param) { return i2c_write16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param);