Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6319beb authored by Xiaozhe Shi's avatar Xiaozhe Shi Committed by Abhijeet Dharmapurikar
Browse files

power: qpnp-fg: add device tree support for batt-therm coefficients



The fuel gauge uses some coefficients to do battery thermistor
conversions. These values can vary depending on the thermistor and board
characteristics.

Add support for a device tree property qcom,thermal-coefficients to the
fuel gauge driver to allow users to configure these values.

CRs-Fixed: 713392
Change-Id: Ief2f75cbd5df28245baccdde9960f30d197d413c
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent aa4cb467
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -35,6 +35,10 @@ Parent node optional properties:
- qcom,cold-bat-decidegc:		Cold battery temperature in decidegC.
- qcom,ext-sense-type:			Current sense channel used by the FG.
					Set this to use external rsense.
- qcom,thermal-coefficients:		Byte array of thermal coefficients for
					reading battery thermistor. This should
					be exactly 6 bytes in length.
					Example: [01 02 03 04 05 06]
- qcom,use-otp-profile:			Specify this flag to avoid RAM loading
					any battery profile.

+24 −4
Original line number Diff line number Diff line
@@ -208,6 +208,7 @@ enum fg_mem_if_irq {
	FG_MEM_IF_IRQ_COUNT,
};

#define THERMAL_COEFF_N_BYTES		6
struct fg_chip {
	struct device		*dev;
	struct spmi_device	*spmi;
@@ -235,6 +236,8 @@ struct fg_chip {
	struct delayed_work	update_jeita_setting;
	struct delayed_work	update_sram_data;
	char			*batt_profile;
	u8			thermal_coefficients[THERMAL_COEFF_N_BYTES];
	bool			use_thermal_coefficients;
	unsigned int		batt_profile_len;
	const char		*batt_type;
	unsigned long		last_sram_update_time;
@@ -1637,12 +1640,19 @@ static void batt_profile_init(struct work_struct *work)

static int fg_of_init(struct fg_chip *chip)
{
	int rc = 0, sense_type;
	int rc = 0, sense_type, len = 0;
	const char *data;

	OF_READ_SETTING(FG_MEM_SOFT_HOT, "warm-bat-decidegc", rc, 1);
	OF_READ_SETTING(FG_MEM_SOFT_COLD, "cool-bat-decidegc", rc, 1);
	OF_READ_SETTING(FG_MEM_HARD_HOT, "hot-bat-decidegc", rc, 1);
	OF_READ_SETTING(FG_MEM_HARD_COLD, "cold-bat-decidegc", rc, 1);
	data = of_get_property(chip->spmi->dev.of_node,
			"qcom,thermal-coefficients", &len);
	if (data && len == THERMAL_COEFF_N_BYTES) {
		memcpy(chip->thermal_coefficients, data, len);
		chip->use_thermal_coefficients = true;
	}

	/* Get the use-otp-profile property */
	chip->use_otp_profile = of_property_read_bool(
@@ -2255,6 +2265,8 @@ static int soc_to_setpoint(int soc)
#define BATT_TEMP_CNTRL_MASK	0x0F
#define BATT_TEMP_ON		0x0E
#define BATT_TEMP_OFF		0x01
#define THERMAL_COEFF_ADDR	0x444
#define THERMAL_COEFF_OFFSET	0x2
static int fg_hw_init(struct fg_chip *chip)
{
	int rc = 0;
@@ -2286,6 +2298,14 @@ static int fg_hw_init(struct fg_chip *chip)
		return rc;
	}

	if (chip->use_thermal_coefficients) {
		fg_mem_write(chip, chip->thermal_coefficients,
			THERMAL_COEFF_ADDR, 2,
			THERMAL_COEFF_OFFSET, 0);
		fg_mem_write(chip, chip->thermal_coefficients + 2,
			THERMAL_COEFF_ADDR + 4, 4, 0, 0);
	}

	return 0;
}

@@ -2435,15 +2455,15 @@ static int fg_probe(struct spmi_device *spmi)
	if (chip->last_sram_update_time == 0)
		update_sram_data(&chip->update_sram_data.work);

	/* release memory access if necessary */
	fg_release_access_if_necessary(chip);

	rc = fg_hw_init(chip);
	if (rc) {
		pr_err("failed to hw init rc = %d\n", rc);
		goto cancel_jeita_work;
	}

	/* release memory access if necessary */
	fg_release_access_if_necessary(chip);

	if (!chip->use_otp_profile)
		schedule_work(&chip->batt_profile_init);