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

Commit e0d7b451 authored by st-sw's avatar st-sw Committed by Ashay Jaiswal
Browse files

power: Add STC3117 Fuel Gauge driver

Linux driver for STC3117 battery monitoring IC from
STMicroelectronics.

Git-commit:	47b14a831a4e89b6ef62bffd95f26d7d8fbeea1d
Git-repo: https://github.com/st-sw/STGasGaugeLinuxDrivers


[aghayal@codeaurora.org: Fixed trivial merge conflicts,
compilation errors and updated the commit text]

Change-Id: I4fcbd2fb06f2869253bd5aa500d5fb6a42caf31b
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
Signed-off-by: default avatarAshay Jaiswal <ashayj@codeaurora.org>
parent a660e4d0
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -495,6 +495,16 @@ config QPNP_SMBCHARGER
	  The driver also offers relevant information to userspace via the
	  power supply framework.

config FUELGAUGE_STC3117
	tristate "STC3117 fuel gauge driver"
	default n
	depends on I2C
	help
	  Say Y to include support
	  for STC3117 fuel gauge driver for batteries.
	  This driver source code implemented
	  all functions for STC3117 fuel gauge.

config QPNP_FG
	tristate "QPNP fuel gauge driver"
	depends on SPMI || MSM_SPMI
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o
obj-$(CONFIG_CHARGER_BQ2415X)	+= bq2415x_charger.o
obj-$(CONFIG_CHARGER_BQ24190)	+= bq24190_charger.o
obj-$(CONFIG_CHARGER_BQ24735)	+= bq24735-charger.o
obj-$(CONFIG_FUELGAUGE_STC3117)	+= stc3117_battery.o
obj-$(CONFIG_POWER_AVS)		+= avs/
obj-$(CONFIG_CHARGER_SMB347)	+= smb347-charger.o
obj-$(CONFIG_SMB349_USB_CHARGER)   += smb349-charger.o
+2142 −0

File added.

Preview size limit exceeded, changes collapsed.

+75 −0
Original line number Diff line number Diff line

#if CONFIG_BATTERY_STC3117

int null_fn(void)
{
	return 0;                // for discharging status
}

int Temperature_fn(void)
{
	return (25);
}

static struct stc311x_platform_data stc3117_data = {
	.battery_online = NULL,
	.charger_online = null_fn, 		// used in stc311x_get_status()
	.charger_enable = null_fn,		// used in stc311x_get_status()
	.power_supply_register = NULL,
	.power_supply_unregister = NULL,

	.Vmode= 0,       /*REG_MODE, BIT_VMODE 1=Voltage mode, 0=mixed mode */
	.Alm_SOC = 10,      /* SOC alm level %*/
	.Alm_Vbat = 3600,   /* Vbat alm level mV*/
	.CC_cnf = 525,      /* nominal CC_cnf, coming from battery characterisation*/
	.VM_cnf = 558,      /* nominal VM cnf , coming from battery characterisation*/
	.Rint = 200,			/* nominal internal impedance*/
	.Cnom = 2600,       /* nominal capacity in mAh, coming from battery characterisation*/
	.Rsense = 10,       /* sense resistor mOhms*/
	.RelaxCurrent = 150, /* current for relaxation in mA (< C/20) */
	.Adaptive = 1,     /* 1=Adaptive mode enabled, 0=Adaptive mode disabled */

	/* Elentec Co Ltd Battery pack - 80 means 8% */
	.CapDerating[6] = 71,   /* capacity derating in 0.1%, for temp = -20C */
	.CapDerating[5] = 42,   /* capacity derating in 0.1%, for temp = -10C */
	.CapDerating[4] = 13,   /* capacity derating in 0.1%, for temp = 0C */
	.CapDerating[3] = 5,   /* capacity derating in 0.1%, for temp = 10C */
	.CapDerating[2] = 0,   /* capacity derating in 0.1%, for temp = 25C */
	.CapDerating[1] = 0,   /* capacity derating in 0.1%, for temp = 40C */
	.CapDerating[0] = 0,   /* capacity derating in 0.1%, for temp = 60C */

	.OCVValue[15] = 0,   /* OCV curve adjustment */
	.OCVValue[14] = 0,   /* OCV curve adjustment */
	.OCVValue[13] = 0,   /* OCV curve adjustment */
	.OCVValue[12] = 0,   /* OCV curve adjustment */
	.OCVValue[11] = 0,   /* OCV curve adjustment */
	.OCVValue[10] = 0,   /* OCV curve adjustment */
	.OCVValue[9] = 0,    /* OCV curve adjustment */
	.OCVValue[8] = 0,    /* OCV curve adjustment */
	.OCVValue[7] = 0,    /* OCV curve adjustment */
	.OCVValue[6] = 0,    /* OCV curve adjustment */
	.OCVValue[5] = 0,    /* OCV curve adjustment */
	.OCVValue[4] = 0,    /* OCV curve adjustment */
	.OCVValue[3] = 0,    /* OCV curve adjustment */
	.OCVValue[2] = 0,    /* OCV curve adjustment */
	.OCVValue[1] = 0,    /* OCV curve adjustment */
	.OCVValue[0] = 0,    /* OCV curve adjustment */

	/*if the application temperature data is preferred than the STC3117 temperature*/
	.ExternalTemperature = Temperature_fn, /*External temperature fonction, return C*/
	.ForceExternalTemperature = 0, /* 1=External temperature, 0=STC3117 temperature */

};
#endif


static struct i2c_board_info __initdata beagle_i2c2_boardinfo[] = {

#if CONFIG_BATTERY_STC3117
	{
		I2C_BOARD_INFO("stc3117", 0x70),
			.platform_data = &stc3117_data,
	},
#endif

};
+40 −0
Original line number Diff line number Diff line
/*
 * STC3117 fuel gauge - Platform Device Driver
 *
 *  Copyright (C) 2011 STMicroelectronics.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef __STC3117_BATTERY_H_
#define __STC3117_BATTERY_H_

struct stc311x_platform_data {
	int (*battery_online)(void);
	int (*charger_online)(void);
	int (*charger_enable)(void);
	int (*power_supply_register)(struct device *parent, struct power_supply *psy);
	void (*power_supply_unregister)(struct power_supply *psy);

	int Vmode;       /* 1=Voltage mode, 0=mixed mode */
  	int Alm_SOC;     /* SOC alm level %*/
  	int Alm_Vbat;    /* Vbat alm level mV*/
  	int CC_cnf;      /* nominal CC_cnf */
  	int VM_cnf;      /* nominal VM cnf */
	int Rint;		 /*nominal Rint*/
  	int Cnom;        /* nominal capacity in mAh */
  	int Rsense;      /* sense resistor mOhms*/
  	int RelaxCurrent; /* current for relaxation in mA (< C/20) */
  	int Adaptive;     /* 1=Adaptive mode enabled, 0=Adaptive mode disabled */
  	int CapDerating[7];   /* capacity derating in 0.1%, for temp = 60, 40, 25, 10,   0, -10 C,-20C */
  	int OCVValue[16];    /* OCV curve adjustment */
  	int (*ExternalTemperature) (void); /*External temperature fonction, return C*/
  	int ForceExternalTemperature; /* 1=External temperature, 0=STC3115 temperature */
};

#endif