Driver: ISL9237: Monitor system power consumption

Added code to enable the system power monitoring functionality to get the
details of the system power consumption.
And also added EC console command "psys" to get the system power consumption.

BUG=none
TEST=Manually tested on Kunimitsu.
     Power = Voltage * Current, reading is equal to the power readings
     from the psys command.
BRANCH=none

Change-Id: I62519ac96800363b67cab23cd9eb0dcac229cb47
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/302472
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Vijay Hiremath
2015-09-23 17:19:19 -07:00
committed by chrome-bot
parent 58540e90a5
commit 5cbd9fa7bb
5 changed files with 106 additions and 6 deletions

View File

@@ -102,8 +102,11 @@ const struct adc_t adc_channels[] = {
[ADC_VBUS] = {"VBUS", 33000, 1024, 0, 1},
/* Adapter current output or battery discharging current */
[ADC_AMON_BMON] = {"AMON_BMON", 1, 1, 0, 3},
/* System current consumption */
[ADC_PSYS] = {"PSYS", 1, 1, 0, 4},
/*
* System current consumption. Converted to mV,
* full ADC is equivalent to 100W
*/
[ADC_PSYS] = {"PSYS", 3000, 1024, 0, 4},
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);

View File

@@ -29,15 +29,30 @@
#define CONFIG_CHARGER_ISL9237
#define CONFIG_CHARGER_ILIM_PIN_DISABLED
#define CONFIG_CHARGER_INPUT_CURRENT 512
#ifndef KUNIMITSU_BOARD_V3
#ifndef BOARD_KUNIMITSU_V3
#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1
#endif
#define CONFIG_CHARGER_PSYS
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20
#ifndef KUNIMITSU_BOARD_V3
#ifndef BOARD_KUNIMITSU_V3
#define CONFIG_TRICKLE_CHARGING
#endif
#ifndef BOARD_KUNIMITSU_V3
/* PSYS register 8.25KOhm */
#define CHARGER_PSYS_REGISTER 8250
#else
/* PSYS register 8.6KOhm */
#define CHARGER_PSYS_REGISTER 8600
#endif
#define CONFIG_CMD_PSYS
/*
* PSYS gain = 1 / (PYSY register * (1.44 or 0.36) uA/W)
*/
#define ISL9237_C2_PSYS_GAIN_1_44 (100000000ul / (CHARGER_PSYS_REGISTER * 144))
#define ISL9237_C2_PSYS_GAIN_0_36 (100000000ul / (CHARGER_PSYS_REGISTER * 36))
#define CONFIG_CHIPSET_SKYLAKE
#define CONFIG_CLOCK_CRYSTAL
#undef CONFIG_DEBUG_ASSERT

View File

@@ -11,8 +11,10 @@
#include "charger.h"
#include "console.h"
#include "common.h"
#include "hooks.h"
#include "i2c.h"
#include "isl9237.h"
#include "timer.h"
#include "util.h"
#define DEFAULT_R_AC 20
@@ -243,6 +245,83 @@ int charger_discharge_on_ac(int enable)
return raw_write16(ISL9237_REG_CONTROL1, control1);
}
#ifdef CONFIG_CHARGER_PSYS
static void charger_enable_psys(void)
{
int val;
/*
* enable system power monitor PSYS function
*/
if (!raw_read16(ISL9237_REG_CONTROL1, &val)) {
val |= ISL9237_C1_ENABLE_PSYS;
raw_write16(ISL9237_REG_CONTROL1, val);
}
}
DECLARE_HOOK(HOOK_CHIPSET_STARTUP, charger_enable_psys, HOOK_PRIO_DEFAULT);
static void charger_disable_psys(void)
{
int val;
/*
* disable system power monitor PSYS function
*/
if (!raw_read16(ISL9237_REG_CONTROL1, &val)) {
val &= ~ISL9237_C1_ENABLE_PSYS;
raw_write16(ISL9237_REG_CONTROL1, val);
}
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, charger_disable_psys, HOOK_PRIO_DEFAULT);
#ifdef CONFIG_CMD_PSYS
#define PSYS_ADC_READ_COUNT 100
static int charger_get_system_power(void)
{
int adc = 0;
int i;
int ret;
int val;
ret = raw_read16(ISL9237_REG_CONTROL2, &val);
if (ret)
return ret;
/* Read ADC */
for (i = 0; i < PSYS_ADC_READ_COUNT; i++) {
adc += adc_read_channel(ADC_PSYS);
usleep(10);
}
/*
* Calculate the power in mW (Power = adc * gain)
*
* System power monitor PSYS output gain
* [0]: 0 = 1.44 uA/W
* 1 = 0.36 uA/W
*
* Do not divide the constants first to ensure precision is not lost.
*/
if (val & ISL9237_C2_PSYS_GAIN)
return ((adc * ISL9237_C2_PSYS_GAIN_0_36) /
PSYS_ADC_READ_COUNT);
else
return ((adc * ISL9237_C2_PSYS_GAIN_1_44) /
PSYS_ADC_READ_COUNT);
}
static int console_command_psys(int argc, char **argv)
{
CPRINTF("system power = %d mW\n", charger_get_system_power());
return 0;
}
DECLARE_CONSOLE_COMMAND(psys, console_command_psys,
NULL,
"Get the system power in mW",
NULL);
#endif /* CONFIG_CMD_PSYS */
#endif /* CONFIG_CHARGER_PSYS */
#ifdef CONFIG_CHARGER_ADC_AMON_BMON
/**
* Get charger AMON and BMON current.

View File

@@ -194,8 +194,7 @@
#define ISL9237_C2_WOC_OFF (1 << 1)
/* Control2: PSYS gain in uA/W */
#define ISL9237_C2_PSYS_GAIN_1_44 0
#define ISL9237_C2_PSYS_GAIN_0_36 1
#define ISL9237_C2_PSYS_GAIN (1 << 0)
/* OTG voltage limit in mV, current limit in mA */
#define ISL9237_OTG_VOLTAGE_MIN 4864

View File

@@ -341,6 +341,9 @@
*/
#undef CONFIG_CHARGER_CURRENT_LIMIT
/* Enable/disable system power monitor PSYS function */
#undef CONFIG_CHARGER_PSYS
/*
* Board specific charging current termination limit, in mA. If defined and
* charger supports setting termination current it should be set during charger
@@ -502,6 +505,7 @@
#define CONFIG_CMD_POWER_AP
#define CONFIG_CMD_POWERINDEBUG
#undef CONFIG_CMD_POWERLED
#undef CONFIG_CMD_PSYS
#undef CONFIG_CMD_RTC_ALARM
#undef CONFIG_CMD_SCRATCHPAD
#define CONFIG_CMD_SHMEM