summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2017-06-20 10:57:47 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-06-22 17:03:52 -0700
commitb0dd82b39c57eab3a30923eb4a755172b9852f7e (patch)
tree75a68eb0f62fe221690eafec5cf97e1e8c0767c4 /driver
parentb3a7ede47dcf8fb8302df9c3b76921066253d22f (diff)
downloadchrome-ec-b0dd82b39c57eab3a30923eb4a755172b9852f7e.tar.gz
cleanup: Remove big and pit boards
Remove big and pit boards along with several now-obsolete CONFIGs / source files. BUG=chromium:735109 TEST=`make buildall -j` BRANCH=None CQ-DEPEND=CL:544681 Change-Id: Ieb784bd36157fd1f6240cd19de6e6d12191a8097 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/540667 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/build.mk5
-rw-r--r--driver/pmu_tps65090.c743
-rw-r--r--driver/pmu_tps65090_charger.c556
-rw-r--r--driver/pmu_tps65090_powerinfo.c159
4 files changed, 0 insertions, 1463 deletions
diff --git a/driver/build.mk b/driver/build.mk
index c43db78ba4..8634aadf5b 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -57,11 +57,6 @@ driver-$(CONFIG_IO_EXPANDER_PCA9534)+=ioexpander_pca9534.o
# Current/Power monitor
driver-$(CONFIG_INA219)$(CONFIG_INA231)+=ina2xx.o
-# Power Management IC
-driver-$(CONFIG_PMU_TPS65090)+=pmu_tps65090.o
-driver-$(CONFIG_CHARGER_TPS65090)+=pmu_tps65090_charger.o
-driver-$(CONFIG_PMU_POWERINFO)+=pmu_tps65090_powerinfo.o
-
# LED drivers
driver-$(CONFIG_LED_DRIVER_DS2413)+=led/ds2413.o
driver-$(CONFIG_LED_DRIVER_LP5562)+=led/lp5562.o
diff --git a/driver/pmu_tps65090.c b/driver/pmu_tps65090.c
deleted file mode 100644
index 665801538a..0000000000
--- a/driver/pmu_tps65090.c
+++ /dev/null
@@ -1,743 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * TI TPS65090 PMU driver.
- */
-
-#include "clock.h"
-#include "console.h"
-#include "common.h"
-#include "extpower.h"
-#include "host_command.h"
-#include "hooks.h"
-#include "i2c.h"
-#include "pmu_tpschrome.h"
-#include "task.h"
-#include "timer.h"
-#include "util.h"
-
-#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-
-#define TPS65090_I2C_ADDR 0x90
-
-#define IRQ1_REG 0x00
-#define IRQ2_REG 0x01
-#define IRQ1MASK 0x02
-#define IRQ2MASK 0x03
-#define CG_CTRL0 0x04
-#define CG_CTRL1 0x05
-#define CG_CTRL2 0x06
-#define CG_CTRL3 0x07
-#define CG_CTRL4 0x08
-#define CG_CTRL5 0x09
-#define CG_STATUS1 0x0a
-#define CG_STATUS2 0x0b
-#define DCDC1_CTRL 0x0c
-#define DCDC2_CTRL 0x0d
-#define DCDC3_CTRL 0x0e
-#define FET1_CTRL 0x0f
-#define FET2_CTRL 0x10
-#define FET3_CTRL 0x11
-#define FET4_CTRL 0x12
-#define FET5_CTRL 0x13
-#define FET6_CTRL 0x14
-#define FET7_CTRL 0x15
-#define AD_CTRL 0x16
-#define AD_OUT1 0x17
-#define AD_OUT2 0x18
-#define TPSCHROME_VER 0x19
-
-/* Charger control */
-#define CG_EN (1 << 0)
-#define CG_EXT_EN (1 << 1)
-#define CG_FASTCHARGE_SHIFT 2
-#define CG_FASTCHARGE_MASK (7 << CG_FASTCHARGE_SHIFT)
-
-/* Charger termination voltage/current */
-#define CG_VSET_SHIFT 3
-#define CG_VSET_MASK (3 << CG_VSET_SHIFT)
-#define CG_ISET_SHIFT 0
-#define CG_ISET_MASK (7 << CG_ISET_SHIFT)
-#define CG_NOITERM (1 << 5)
-#define CG_TSET_SHIFT 5
-#define CG_TSET_MASK (7 << CG_TSET_SHIFT)
-
-/* A temperature threshold to force charger hardware error */
-#define CG_TEMP_THRESHOLD_ERROR 0
-
-/* Timeout indication */
-#define STATUS_TIMEOUT_MASK 0xc
-#define STATUS_PRECHARGE_TIMEOUT 0x4
-#define STATUS_FASTCHARGE_TIMEOUT 0x8
-
-/* IRQ events */
-#define EVENT_VACG (1 << 1) /* AC voltage good */
-#define EVENT_VSYSG (1 << 2) /* System voltage good */
-#define EVENT_VBATG (1 << 3) /* Battery voltage good */
-#define EVENT_CGACT (1 << 4) /* Charging status */
-#define EVENT_CGCPL (1 << 5) /* Charging complete */
-
-/* Charger alarm */
-#define CHARGER_ALARM 3
-
-/* FET control register bits */
-#define FET_CTRL_ENFET (1 << 0)
-#define FET_CTRL_ADENFET (1 << 1)
-#define FET_CTRL_WAIT (3 << 2) /* Overcurrent timeout max : 3200 us */
-#define FET_CTRL_PGFET (1 << 4)
-
-#define FET_CTRL_BASE (FET1_CTRL - 1)
-
-#define POWER_GOOD_DELAY_US 3500
-
-/* AD control register bits */
-#define AD_CTRL_ENADREF (1 << 4)
-#define AD_CTRL_ADEOC (1 << 5)
-#define AD_CTRL_ADSTART (1 << 6)
-
-#define HARD_RESET_TIMEOUT_MS 5
-
-/* Charger temperature threshold table */
-static const uint8_t const pmu_temp_threshold[] = {
- 1, /* 0b001, 0 degree C */
- 2, /* 0b010, 10 degree C */
- 5, /* 0b101, 45 degree C */
- 7, /* 0b111, 60 degree C */
-};
-
-#ifdef CONFIG_PMU_HARD_RESET
-/**
- * Force the pmic to reset completely.
- *
- * This forces an entire system reset, and therefore should never return. The
- * implementation is rather hacky; it simply shorts out the 3.3V rail to force
- * the PMIC to panic. We need this unfortunate hack because it's the only way
- * to reset the I2C engine inside the PMU.
- */
-static void pmu_hard_reset(void)
-{
- /* Short out the 3.3V rail to force a hard reset of tps Chrome */
- gpio_set_level(GPIO_PMIC_RESET, 1);
-
- /* Delay while the power is cut */
- udelay(HARD_RESET_TIMEOUT_MS * 1000);
-
- /* Shouldn't get here unless the board doesn't have this capability */
- panic_puts("pmu hard reset failed! (this board may not be capable)\n");
-}
-#else
-static void pmu_hard_reset(void)
-{
- panic_puts("pmu hard reset unsupported!\n");
-}
-#endif
-
-/* Read all tps65090 interrupt events */
-static int pmu_get_event(int *event)
-{
- static int prev_event;
- int rv;
- int irq1, irq2;
-
- pmu_clear_irq();
-
- rv = pmu_read(IRQ1_REG, &irq1);
- if (rv)
- return rv;
- rv = pmu_read(IRQ2_REG, &irq2);
- if (rv)
- return rv;
-
- *event = irq1 | (irq2 << 8);
-
- if (prev_event != *event) {
- CPRINTS("pmu event: %016b", *event);
- prev_event = *event;
- }
-
- return EC_SUCCESS;
-}
-
-/* Clear tps65090 irq */
-int pmu_clear_irq(void)
-{
- return pmu_write(IRQ1_REG, 0);
-}
-
-/* Read/write tps65090 register */
-int pmu_read(int reg, int *value)
-{
- return i2c_read8(I2C_PORT_CHARGER, TPS65090_I2C_ADDR, reg, value);
-}
-
-int pmu_write(int reg, int value)
-{
- return i2c_write8(I2C_PORT_CHARGER, TPS65090_I2C_ADDR, reg, value);
-}
-
-/**
- * Read tpschrome version
- *
- * @param version output value of tpschrome version
- */
-int pmu_version(int *version)
-{
- return pmu_read(TPSCHROME_VER, version);
-}
-
-int pmu_is_charger_alarm(void)
-{
- int status;
-
- /**
- * if the I2C access to the PMU fails, we consider the failure as
- * non-critical and wait for the next read without send the alert.
- */
- if (!pmu_read(CG_STATUS1, &status) && (status & CHARGER_ALARM))
- return 1;
- return 0;
-}
-
-int pmu_is_charge_timeout(void)
-{
- int status;
-
- if (pmu_read(CG_STATUS1, &status))
- return 0;
-
- status &= STATUS_TIMEOUT_MASK;
- return (status == STATUS_PRECHARGE_TIMEOUT) ||
- (status == STATUS_FASTCHARGE_TIMEOUT);
-}
-
-int pmu_get_power_source(int *ac_good, int *battery_good)
-{
- int rv, event = 0;
-
- rv = pmu_get_event(&event);
- if (rv)
- return rv;
-
- if (ac_good)
- *ac_good = event & EVENT_VACG;
- if (battery_good)
- *battery_good = event & EVENT_VBATG;
-
- return EC_SUCCESS;
-}
-
-/**
- * Enable charger's charging function
- *
- * When enable, charger ignores external control and charge the
- * battery directly. If EC wants to contorl charging, set the flag
- * to 0.
- */
-int pmu_enable_charger(int enable)
-{
- int rv;
- int reg;
-
- rv = pmu_read(CG_CTRL0, &reg);
- if (rv)
- return rv;
-
- if (enable)
- reg |= CG_EN;
- else
- reg &= ~CG_EN;
-
- return pmu_write(CG_CTRL0, reg);
-}
-
-/**
- * Set external charge enable pin
- *
- * @param enable boolean, set 1 to eanble external control
- */
-int pmu_enable_ext_control(int enable)
-{
- int rv;
- int reg;
-
- rv = pmu_read(CG_CTRL0, &reg);
- if (rv)
- return rv;
-
- if (enable)
- reg |= CG_EXT_EN;
- else
- reg &= ~CG_EXT_EN;
-
- return pmu_write(CG_CTRL0, reg);
-}
-
-/**
- * Set fast charge timeout
- *
- * @param timeout enum FASTCHARGE_TIMEOUT
- */
-int pmu_set_fastcharge(enum FASTCHARGE_TIMEOUT timeout)
-{
- int rv;
- int reg;
-
- rv = pmu_read(CG_CTRL0, &reg);
- if (rv)
- return rv;
-
- reg &= ~CG_FASTCHARGE_MASK;
- reg |= (timeout << CG_FASTCHARGE_SHIFT) & CG_FASTCHARGE_MASK;
-
- return pmu_write(CG_CTRL0, reg);
-}
-
-/**
- * Set termination current for temperature ranges
- *
- * @param range T01 T12 T23 T34 T40
- * @param current enum termination current, I0250 == 25.0%:
- * I0000 I0250 I0375 I0500 I0625 I0750 I0875 I1000
- */
-int pmu_set_term_current(enum TPS_TEMPERATURE_RANGE range,
- enum TPS_TERMINATION_CURRENT current)
-{
- int rv;
- int reg_val;
-
- rv = pmu_read(CG_CTRL1 + range, &reg_val);
- if (rv)
- return rv;
-
- reg_val &= ~CG_ISET_MASK;
- reg_val |= current << CG_ISET_SHIFT;
-
- return pmu_write(CG_CTRL1 + range, reg_val);
-}
-
-/**
- * Set termination voltage for temperature ranges
- *
- * @param range T01 T12 T23 T34 T40
- * @param voltage enum termination voltage, V2050 == 2.05V:
- * V2000 V2050 V2075 V2100
- */
-int pmu_set_term_voltage(enum TPS_TEMPERATURE_RANGE range,
- enum TPS_TERMINATION_VOLTAGE voltage)
-{
- int rv;
- int reg_val;
-
- rv = pmu_read(CG_CTRL1 + range, &reg_val);
- if (rv)
- return rv;
-
- reg_val &= ~CG_VSET_MASK;
- reg_val |= voltage << CG_VSET_SHIFT;
-
- return pmu_write(CG_CTRL1 + range, reg_val);
-}
-
-/**
- * Set temperature threshold
- *
- * @param temp_n TSET_T1 to TSET_T4
- * @param value 0b000 ~ 0b111, temperature threshold
- */
-int pmu_set_temp_threshold(enum TPS_TEMPERATURE temp_n, uint8_t value)
-{
- int rv;
- int reg_val;
-
- /*
- * Temperature threshold T1 to T4 are stored in TPSCHROME registers
- * CG_CTRL1 to CG_CTRL4.
- */
- rv = pmu_read(CG_CTRL1 + temp_n, &reg_val);
- if (rv)
- return rv;
-
- reg_val &= ~CG_TSET_MASK;
- reg_val |= (value << CG_TSET_SHIFT) & CG_TSET_MASK;
-
- return pmu_write(CG_CTRL1 + temp_n, reg_val);
-}
-
-/**
- * Force charger into error state, turn off charging and blinks charging LED
- *
- * @param enable true to turn off charging and blink LED
- * @return EC_SUCCESS for success
- */
-int pmu_blink_led(int enable)
-{
- int rv;
- enum TPS_TEMPERATURE t;
- uint8_t threshold;
-
- for (t = TSET_T1; t <= TSET_T4; t++) {
- if (enable)
- threshold = CG_TEMP_THRESHOLD_ERROR;
- else
- threshold = pmu_temp_threshold[t];
-
- rv = pmu_set_temp_threshold(t, threshold);
- if (rv) {
- /* Retry */
- rv = pmu_set_temp_threshold(t, threshold);
- if (rv)
- return rv;
- }
- }
-
- return EC_SUCCESS;
-}
-
-/**
- * Enable low current charging
- *
- * @param enable enable/disable low current charging
- */
-int pmu_low_current_charging(int enable)
-{
- int rv;
- int reg_val;
-
- rv = pmu_read(CG_CTRL5, &reg_val);
- if (rv)
- return rv;
-
- if (enable)
- reg_val |= CG_NOITERM;
- else
- reg_val &= ~CG_NOITERM;
-
- return pmu_write(CG_CTRL5, reg_val);
-}
-
-int pmu_enable_fet(int fet_id, int enable, int *power_good)
-{
- int rv, reg;
- int reg_offset;
-
- reg_offset = FET_CTRL_BASE + fet_id;
-
- rv = pmu_read(reg_offset, &reg);
- if (rv)
- return rv;
- reg |= FET_CTRL_ADENFET | FET_CTRL_WAIT;
- if (enable)
- reg |= FET_CTRL_ENFET;
- else
- reg &= ~FET_CTRL_ENFET;
-
- rv = pmu_write(reg_offset, reg);
- if (rv)
- return rv;
-
- if (power_good) {
- usleep(POWER_GOOD_DELAY_US);
- rv = pmu_read(reg_offset, &reg);
- if (rv)
- return rv;
- *power_good = reg & FET_CTRL_PGFET;
- }
-
- return EC_SUCCESS;
-}
-
-int pmu_adc_read(int adc_idx, int flags)
-{
- int ctrl;
- int val1, val2;
- int rv;
-
- rv = pmu_read(AD_CTRL, &ctrl);
- if (rv)
- return rv;
- if (!(ctrl & AD_CTRL_ENADREF)) {
- ctrl |= AD_CTRL_ENADREF;
- rv = pmu_write(AD_CTRL, ctrl);
- if (rv)
- return rv;
- /* wait for reference voltage stabilization */
- msleep(10);
- }
-
- ctrl = (ctrl & ~0xf) | adc_idx;
- rv = pmu_write(AD_CTRL, ctrl);
- if (rv)
- return rv;
- udelay(150);
-
- ctrl |= AD_CTRL_ADSTART;
- rv = pmu_write(AD_CTRL, ctrl);
- if (rv)
- return rv;
- udelay(200);
-
- do {
- rv = pmu_read(AD_CTRL, &ctrl);
- if (rv)
- return rv;
- } while (!(ctrl & AD_CTRL_ADEOC));
-
- rv = pmu_read(AD_OUT1, &val1) | pmu_read(AD_OUT2, &val2);
- if (rv)
- return rv;
-
- if (!(flags & ADC_FLAG_KEEP_ON))
- rv = pmu_write(AD_CTRL, ctrl & ~AD_CTRL_ENADREF);
-
- return (val2 << 8) | val1;
-}
-
-/**
- * Attempt shutdown.
- */
-static int pmu_try_shutdown(void)
-{
- int offset;
-
- /* Disable each of the DCDCs */
- for (offset = DCDC1_CTRL; offset <= DCDC3_CTRL; offset++) {
- if (pmu_write(offset, 0x0e))
- return EC_ERROR_UNKNOWN;
- }
- /* Disable each of the FETs */
- for (offset = FET1_CTRL; offset <= FET7_CTRL; offset++) {
- if (pmu_write(offset, 0x02))
- return EC_ERROR_UNKNOWN;
- }
-
- /* Clear AD controls/status */
- if (pmu_write(AD_CTRL, 0x00))
- return EC_ERROR_UNKNOWN;
-
- return EC_SUCCESS;
-}
-
-int pmu_shutdown(void)
-{
- int pmu_shutdown_retries = 3;
-
- /* Attempt shutdown */
- while (--pmu_shutdown_retries >= 0) {
- if (!pmu_try_shutdown())
- return EC_SUCCESS;
- }
-
-#ifdef CONFIG_PMU_HARD_RESET
- /* We ran out of tries, so reset the board */
- CPUTS("PMU shutdown failed. Hard-resetting.\n");
- cflush();
- pmu_hard_reset();
-#endif
-
- /* If we're still here, we couldn't shutdown OR reset */
- return EC_ERROR_UNKNOWN;
-}
-
-/*
- * Fill all of the pmu registers with known good values, this allows the
- * pmu to recover by rebooting the system if its registers were trashed.
- */
-static void pmu_init_registers(void)
-{
- const struct {
- uint8_t index;
- uint8_t value;
- } reg[] = {
- {IRQ1MASK, 0x00},
- {IRQ2MASK, 0x00},
- {CG_CTRL0, 0x02},
- {CG_CTRL1, 0x20},
- {CG_CTRL2, 0x4b},
- {CG_CTRL3, 0xbf},
- {CG_CTRL4, 0xf3},
- {CG_CTRL5, 0xc0},
- {DCDC1_CTRL, 0x0e},
- {DCDC2_CTRL, 0x0e},
- {DCDC3_CTRL, 0x0e},
- {FET1_CTRL, 0x02},
- {FET2_CTRL, 0x02},
- {FET3_CTRL, 0x02},
- {FET4_CTRL, 0x02},
- {FET5_CTRL, 0x02},
- {FET6_CTRL, 0x02},
- {FET7_CTRL, 0x02},
- {AD_CTRL, 0x00},
- {IRQ1_REG, 0x00}
- };
- uint8_t i;
-
- /*
- * Write all PMU registers. Ignore return value from pmu_write()
- * because there's nothing we can reasonably do if it fails.
- */
- for (i = 0; i < ARRAY_SIZE(reg); i++)
- pmu_write(reg[i].index, reg[i].value);
-}
-DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, pmu_init_registers, HOOK_PRIO_DEFAULT);
-
-void pmu_init(void)
-{
- int failure = 0, retries_remaining = 3;
-
- while (--retries_remaining >= 0) {
- failure = pmu_board_init();
-
- /* Enable interrupts */
- if (!failure) {
- failure = pmu_write(IRQ1MASK,
- EVENT_VACG | /* AC voltage good */
- EVENT_VSYSG | /* System voltage good */
- EVENT_VBATG | /* Battery voltage good */
- EVENT_CGACT | /* Charging status */
- EVENT_CGCPL); /* Charging complete */
- }
- if (!failure)
- failure = pmu_write(IRQ2MASK, 0);
- if (!failure)
- failure = pmu_clear_irq();
-
- /* Exit the retry loop if there was no failure */
- if (!failure)
- break;
- }
-
- if (failure) {
- CPUTS("Failed to initialize PMU. Hard-resetting.\n");
- cflush();
- pmu_hard_reset();
- }
-}
-
-/* Initializes PMU when power is turned on. This is necessary because the TPS'
- * 3.3V rail is not powered until the power is turned on. */
-static void pmu_chipset_startup(void)
-{
- pmu_init();
-
-#ifdef BOARD_PIT
- /* Enable FET4 by default which allows for SD Card booting */
- {
- int pgood;
- pmu_enable_fet(4, 1, &pgood);
- }
-#endif
-}
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, pmu_chipset_startup, HOOK_PRIO_DEFAULT);
-
-#ifdef CONFIG_CMD_PMU
-static int print_pmu_info(void)
-{
- int reg, ret;
- int value;
-
- ccprintf(" ");
- for (reg = 0; reg <= 0x18; reg++)
- ccprintf("%02x ", reg);
- ccprintf("\n");
-
- ccprintf("PMU: ");
- for (reg = 0; reg <= 0x18; reg++) {
- ret = pmu_read(reg, &value);
- if (ret)
- return ret;
- ccprintf("%02x ", value);
- }
- ccputs("\n");
-
- return 0;
-}
-
-static int command_pmu(int argc, char **argv)
-{
- int repeat = 1;
- int rv = 0;
- int loop;
- int value;
- char *e;
-
- if (argc > 1) {
- repeat = strtoi(argv[1], &e, 0);
- if (*e) {
- if (strlen(argv[1]) >= 1 && argv[1][0] == 'r') {
- pmu_hard_reset();
- /* If this returns, there was an error */
- return EC_ERROR_UNKNOWN;
- }
-
- ccputs("Invalid repeat count\n");
- return EC_ERROR_INVAL;
- }
- }
-
- for (loop = 0; loop < repeat; loop++) {
- rv = print_pmu_info();
- usleep(1000);
- }
-
- rv = pmu_read(IRQ1_REG, &value);
- if (rv)
- return rv;
- CPRINTS("pmu events b%08b", value);
- CPRINTS("ac gpio %d", extpower_is_present());
-
- if (rv)
- ccprintf("Failed - error %d\n", rv);
-
- return rv ? EC_ERROR_UNKNOWN : EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(pmu, command_pmu,
- "<repeat_count|reset>",
- "Print PMU info or force a hard reset");
-#endif
-
-/*****************************************************************************/
-/* TPSchrome LDO pass-through
- */
-#ifdef CONFIG_I2C_PASSTHROUGH
-static int host_command_ldo_get(struct host_cmd_handler_args *args)
-{
- int rv;
- int val;
- const struct ec_params_ldo_get *p = args->params;
- struct ec_response_ldo_get *r = args->response;
-
- /* is this an existing TPSchrome FET ? */
- if ((p->index < 1) || (p->index > 7))
- return EC_RES_ERROR;
-
- rv = pmu_read(FET_CTRL_BASE + p->index, &val);
- if (rv)
- return EC_RES_ERROR;
-
- r->state = !!(val & FET_CTRL_PGFET);
- args->response_size = sizeof(struct ec_response_ldo_get);
-
- return EC_RES_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_LDO_GET,
- host_command_ldo_get,
- EC_VER_MASK(0));
-
-static int host_command_ldo_set(struct host_cmd_handler_args *args)
-{
- int rv;
- const struct ec_params_ldo_set *p = args->params;
-
- /* is this an existing TPSchrome FET ? */
- if ((p->index < 1) || (p->index > 7))
- return EC_RES_ERROR;
- rv = pmu_enable_fet(p->index, p->state & EC_LDO_STATE_ON, NULL);
-
- return rv ? EC_RES_ERROR : EC_RES_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_LDO_SET,
- host_command_ldo_set,
- EC_VER_MASK(0));
-#endif
diff --git a/driver/pmu_tps65090_charger.c b/driver/pmu_tps65090_charger.c
deleted file mode 100644
index 695b8a4897..0000000000
--- a/driver/pmu_tps65090_charger.c
+++ /dev/null
@@ -1,556 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * TI TPS65090 PMU charging task.
- */
-
-#include "battery.h"
-#include "battery_smart.h"
-#include "clock.h"
-#include "chipset.h"
-#include "common.h"
-#include "console.h"
-#include "extpower.h"
-#include "hooks.h"
-#include "gpio.h"
-#include "pmu_tpschrome.h"
-#include "system.h"
-#include "task.h"
-#include "timer.h"
-#include "util.h"
-
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-
-/* Charging and discharging alarms */
-#define ALARM_DISCHARGING (ALARM_TERMINATE_DISCHARGE | ALARM_OVER_TEMP)
-#define ALARM_CHARGED (ALARM_OVER_CHARGED | ALARM_TERMINATE_CHARGE)
-
-/* Maximum time allowed to revive a extremely low charge battery */
-#define PRE_CHARGING_TIMEOUT (15 * SECOND)
-
-/*
- * Time delay in usec for idle, charging and discharging. Defined in battery
- * charging flow.
- */
-#define T1_OFF_USEC (60 * SECOND)
-#define T1_SUSPEND_USEC (60 * SECOND)
-#define T1_USEC (5 * SECOND)
-#define T2_USEC (10 * SECOND)
-#define T3_USEC (10 * SECOND)
-
-#ifndef BATTERY_AP_OFF_LEVEL
-#define BATTERY_AP_OFF_LEVEL 0
-#endif
-
-static const char * const state_list[] = CHARGE_STATE_NAME_TABLE;
-
-/* States for throttling PMU task */
-static timestamp_t last_waken; /* Initialized to 0 */
-static int has_pending_event;
-
-static enum charging_state current_state = ST_IDLE0;
-
-/* Cached version of battery parameter */
-static struct batt_params batt_params_copy;
-
-
-#ifdef CONFIG_PMU_TPS65090_CHARGING_LED
-static void update_battery_led(void)
-{
- int alarm;
- int led_on = 0;
- if(extpower_is_present()){
- battery_status(&alarm);
- if((alarm & ALARM_CHARGED) && !gpio_get_level(GPIO_CHARGER_EN))
- led_on = 1;
- }
-
- gpio_set_level(GPIO_CHARGING_LED, led_on);
-}
-#endif
-
-static void enable_charging(int enable)
-{
- enable = enable ? 1 : 0;
- if (gpio_get_level(GPIO_CHARGER_EN) != enable)
- gpio_set_level(GPIO_CHARGER_EN, enable);
-}
-
-static int battery_start_charging_range(int deci_k)
-{
- int8_t temp_c = DECI_KELVIN_TO_CELSIUS(deci_k);
- const struct battery_info *info = battery_get_info();
-
- return (temp_c >= info->start_charging_min_c &&
- temp_c < info->start_charging_max_c);
-}
-
-static int battery_charging_range(int deci_k)
-{
- int8_t temp_c = DECI_KELVIN_TO_CELSIUS(deci_k);
- const struct battery_info *info = battery_get_info();
-
- return (temp_c >= info->charging_min_c &&
- temp_c < info->charging_max_c);
-}
-
-static int battery_discharging_range(int deci_k)
-{
- int8_t temp_c = DECI_KELVIN_TO_CELSIUS(deci_k);
- const struct battery_info *info = battery_get_info();
-
- return (temp_c >= info->discharging_min_c &&
- temp_c < info->discharging_max_c);
-}
-
-/**
- * Turn off the AP
- */
-static int system_off(void)
-{
- if (chipset_in_state(CHIPSET_STATE_ON)) {
- CPRINTS("pmu turning system off");
- chipset_force_shutdown();
- }
-
- return ST_IDLE0;
-}
-
-/**
- * Notify the host when battery remaining charge is lower than 10%
- */
-static int notify_battery_low(void)
-{
- static timestamp_t last_notify_time;
- timestamp_t now;
-
- if (chipset_in_state(CHIPSET_STATE_ON)) {
- now = get_time();
- if (now.val - last_notify_time.val > MINUTE) {
- CPRINTS("pmu notify battery low (< 4%)");
- last_notify_time = now;
- /* TODO(crosbug.com/p/23814): Actually notify AP */
- }
- }
- return ST_DISCHARGING;
-}
-
-/*
- * Calculate relative state of charge moving average
- *
- * @param state_of_charge Current battery state of charge reading,
- * from 0 to 100. When state_of_charge < 0,
- * resets the moving average window
- * @return Average state of charge, rounded to nearest
- * integer.
- * -1 when window reset.
- *
- * The returned value will be rounded to the nearest integer, by set moving
- * average init value to (0.5 * window_size).
- *
- */
-static int rsoc_moving_average(int state_of_charge)
-{
- static uint8_t rsoc[4];
- static int8_t index = -1;
- int moving_average = ARRAY_SIZE(rsoc) / 2;
- int i;
-
- if (state_of_charge < 0) {
- index = -1;
- return -1;
- }
-
- if (index < 0) {
- for (i = 0; i < ARRAY_SIZE(rsoc); i++)
- rsoc[i] = (uint8_t)state_of_charge;
- index = 0;
- return state_of_charge;
- }
-
- rsoc[index] = (uint8_t)state_of_charge;
- index++;
- index %= sizeof(rsoc);
-
- for (i = 0; i < ARRAY_SIZE(rsoc); i++)
- moving_average += (int)rsoc[i];
- moving_average /= ARRAY_SIZE(rsoc);
-
- return moving_average;
-}
-
-/*
- * This saves battery parameters for charger_current_battery_params().
- */
-static void battery_get_params_and_save_a_copy(struct batt_params *batt)
-{
- battery_get_params(&batt_params_copy);
- memcpy(batt, &batt_params_copy, sizeof(*batt));
-}
-
-struct batt_params *charger_current_battery_params(void)
-{
- return &batt_params_copy;
-}
-
-static int calc_next_state(int state)
-{
- struct batt_params batt;
- int alarm;
-
- battery_get_params_and_save_a_copy(&batt);
-
- switch (state) {
- case ST_IDLE0:
- case ST_BAD_COND:
- case ST_IDLE:
- /* Check AC and chipset state */
- if (!extpower_is_present()) {
- if (chipset_in_state(CHIPSET_STATE_ON))
- return ST_DISCHARGING;
- return ST_IDLE;
- }
-
- /* Stay in idle mode if charger overtemp */
- if (pmu_is_charger_alarm())
- return ST_BAD_COND;
-
- /* Enable charging when battery doesn't respond */
- if (!(batt.flags & BATT_FLAG_RESPONSIVE))
- return ST_PRE_CHARGING;
-
- /* Turn off charger when battery temperature is out
- * of the start charging range.
- */
- if (!battery_start_charging_range(batt.temperature))
- return ST_BAD_COND;
-
- /* Turn off charger on battery over temperature alarm */
- if (battery_status(&alarm) || (alarm & ALARM_OVER_TEMP))
- return ST_BAD_COND;
-
- /* Stop charging if the battery says it's charged */
- if (alarm & ALARM_CHARGED)
- return ST_IDLE;
-
- /* Start charging only when battery charge lower than 100% */
- if (!(batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE)) {
- if (batt.state_of_charge < 100)
- return ST_CHARGING;
- }
-
- return ST_IDLE;
-
- case ST_PRE_CHARGING:
- if (!extpower_is_present())
- return ST_IDLE0;
-
- /*
- * If the battery goes online after enabling the charger, go
- * into charging state.
- */
- if (batt.flags & BATT_FLAG_RESPONSIVE) {
- if (!battery_start_charging_range(batt.temperature))
- return ST_IDLE0;
- if (!(batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE)) {
- if (batt.state_of_charge >= 100)
- return ST_IDLE0;
- }
- return ST_CHARGING;
- }
-
- return ST_PRE_CHARGING;
-
- case ST_CHARGING:
- /* Go back to idle state when AC is unplugged */
- if (!extpower_is_present())
- return ST_IDLE0;
-
- /*
- * Disable charging on battery access error, or charging
- * temperature out of range.
- */
- if (!(batt.flags & BATT_FLAG_RESPONSIVE)) {
- CPRINTS("pmu charging: unable to get battery "
- "temperature");
- return ST_IDLE0;
- } else if (!battery_charging_range(batt.temperature)) {
- CPRINTS("pmu charging: temperature out of range "
- "%dC",
- DECI_KELVIN_TO_CELSIUS(batt.temperature));
- return ST_CHARGING_ERROR;
- }
-
- /*
- * Disable charging on battery alarm events or access error:
- * - over temperature
- * - over current
- */
- if (battery_status(&alarm))
- return ST_IDLE0;
-
- if (alarm & ALARM_OVER_TEMP) {
- CPRINTS("pmu charging: battery over temp");
- return ST_CHARGING_ERROR;
- }
-
- /* Go to idle state if battery is fully charged */
- if (alarm & ALARM_CHARGED)
- return ST_IDLE;
-
- /*
- * Disable charging on charger alarm events:
- * - charger over current
- * - charger over temperature
- */
- if (pmu_is_charger_alarm()) {
- CPRINTS("pmu charging: charger alarm");
- return ST_IDLE0;
- }
-
- return ST_CHARGING;
-
- case ST_CHARGING_ERROR:
- /*
- * This state indicates AC is plugged but the battery is not
- * charging. The conditions to exit this state:
- * - battery detected
- * - battery temperature is in start charging range
- * - no battery alarm
- */
- if (extpower_is_present()) {
- if (battery_status(&alarm))
- return ST_CHARGING_ERROR;
-
- if (alarm & ALARM_OVER_TEMP)
- return ST_CHARGING_ERROR;
-
- if (!(batt.flags & BATT_FLAG_RESPONSIVE))
- return ST_CHARGING_ERROR;
-
- if (!battery_charging_range(batt.temperature))
- return ST_CHARGING_ERROR;
-
- return ST_CHARGING;
- }
-
- return ST_IDLE0;
-
-
- case ST_DISCHARGING:
- /* Go back to idle state when AC is plugged */
- if (extpower_is_present())
- return ST_IDLE0;
-
- /* Prepare EC sleep after system stopped discharging */
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
- return ST_IDLE0;
-
- /* Check battery discharging temperature range */
- if (batt.flags & BATT_FLAG_RESPONSIVE) {
- if (!battery_discharging_range(batt.temperature)) {
- CPRINTS("pmu discharging: temperature out of "
- "range %dC",
- DECI_KELVIN_TO_CELSIUS(
- batt.temperature));
- return system_off();
- }
- }
- /* Check discharging alarm */
- if (!battery_status(&alarm) && (alarm & ALARM_DISCHARGING)) {
- CPRINTS("pmu discharging: battery alarm %016b", alarm);
- return system_off();
- }
- /* Check remaining charge % */
- if (!(batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE)) {
- /*
- * Shutdown AP when state of charge < 1.5%.
- * Moving average is rounded to integer.
- */
- if (rsoc_moving_average(batt.state_of_charge) < 2)
- return system_off();
- else if (batt.state_of_charge < 4)
- notify_battery_low();
- }
-
- return ST_DISCHARGING;
- }
-
- return ST_IDLE0;
-}
-
-enum charging_state charge_get_state(void)
-{
- return current_state;
-}
-
-int charge_keep_power_off(void)
-{
- int charge;
-
- if (BATTERY_AP_OFF_LEVEL == 0)
- return 0;
-
- if (battery_remaining_capacity(&charge))
- return current_state != ST_CHARGING_ERROR;
-
- return charge <= BATTERY_AP_OFF_LEVEL;
-}
-
-void charger_task(void)
-{
- int next_state;
- int wait_time = T1_USEC;
- timestamp_t pre_chg_start = get_time();
-
- pmu_init();
-
- /* Enable low current charging */
- pmu_low_current_charging(1);
-
- /* Enable charger interrupt */
- gpio_enable_interrupt(GPIO_CHARGER_INT_L);
-
- /*
- * EC STOP mode support
- * The charging loop can be stopped in idle state with AC unplugged.
- * Charging loop will be resumed by TPSCHROME interrupt.
- */
- enable_charging(0);
- disable_sleep(SLEEP_MASK_CHARGING);
-
- while (1) {
- last_waken = get_time();
- pmu_clear_irq();
-
-#ifdef CONFIG_PMU_TPS65090_CHARGING_LED
- update_battery_led();
-#endif
- /*
- * When battery is extremely low, the internal voltage can not
- * power on its gas gauge IC. Charging loop will enable the
- * charger and turn on trickle charging. For safety reason,
- * charger should be disabled if the communication to battery
- * failed.
- */
- if (current_state == ST_PRE_CHARGING &&
- get_time().val - pre_chg_start.val >= PRE_CHARGING_TIMEOUT)
- next_state = ST_CHARGING_ERROR;
- else
- next_state = calc_next_state(current_state);
-
- if (next_state != current_state) {
- /* Reset state of charge moving average window */
- rsoc_moving_average(-1);
-
- CPRINTS("batt state %s -> %s",
- state_list[current_state],
- state_list[next_state]);
-
- current_state = next_state;
-
- switch (current_state) {
- case ST_PRE_CHARGING:
- pre_chg_start = get_time();
- /* Fall through */
- case ST_CHARGING:
- if (pmu_blink_led(0))
- next_state = ST_CHARGING_ERROR;
- else
- enable_charging(1);
- break;
- case ST_CHARGING_ERROR:
- /*
- * Enable hardware charging circuit after set
- * PMU to hardware error state.
- */
- if (pmu_blink_led(1))
- enable_charging(0);
- else
- enable_charging(1);
- break;
- case ST_IDLE:
- case ST_IDLE0:
- case ST_BAD_COND:
- case ST_DISCHARGING:
- enable_charging(0);
- /* Ignore charger error when discharging */
- pmu_blink_led(0);
- break;
- }
- }
-
- switch (current_state) {
- case ST_CHARGING:
- case ST_CHARGING_ERROR:
- wait_time = T2_USEC;
- break;
- case ST_DISCHARGING:
- wait_time = T3_USEC;
- break;
- case ST_PRE_CHARGING:
- wait_time = T1_USEC;
- if (get_time().val - pre_chg_start.val >=
- PRE_CHARGING_TIMEOUT)
- enable_charging(0);
- break;
- default:
- if (extpower_is_present()) {
- wait_time = T1_USEC;
- break;
- } else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
- wait_time = T1_OFF_USEC;
- enable_sleep(SLEEP_MASK_CHARGING);
- } else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) {
- wait_time = T1_SUSPEND_USEC;
- } else {
- wait_time = T1_USEC;
- }
- }
-
- if (!has_pending_event) {
- task_wait_event(wait_time);
- disable_sleep(SLEEP_MASK_CHARGING);
- } else {
- has_pending_event = 0;
- }
- }
-}
-
-void pmu_task_throttled_wake(void)
-{
- timestamp_t now = get_time();
- if (now.val - last_waken.val >= HOOK_TICK_INTERVAL) {
- has_pending_event = 0;
- task_wake(TASK_ID_CHARGER);
- } else {
- has_pending_event = 1;
- }
-}
-
-static void wake_pmu_task_if_necessary(void)
-{
- if (has_pending_event) {
- has_pending_event = 0;
- task_wake(TASK_ID_CHARGER);
- }
-}
-DECLARE_HOOK(HOOK_TICK, wake_pmu_task_if_necessary, HOOK_PRIO_DEFAULT);
-
-/* Wake charging task on chipset events */
-static void pmu_chipset_events(void)
-{
- pmu_task_throttled_wake();
-}
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, pmu_chipset_events, HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, pmu_chipset_events, HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, pmu_chipset_events, HOOK_PRIO_DEFAULT);
-DECLARE_HOOK(HOOK_CHIPSET_RESUME, pmu_chipset_events, HOOK_PRIO_DEFAULT);
-
-void pmu_irq_handler(enum gpio_signal signal)
-{
- pmu_task_throttled_wake();
- CPRINTS("Charger IRQ received");
-}
-
diff --git a/driver/pmu_tps65090_powerinfo.c b/driver/pmu_tps65090_powerinfo.c
deleted file mode 100644
index 3ab4fb26b3..0000000000
--- a/driver/pmu_tps65090_powerinfo.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * TPSChrome powerinfo commands.
- */
-
-#include "battery.h"
-#include "console.h"
-#include "extpower.h"
-#include "host_command.h"
-#include "pmu_tpschrome.h"
-#include "util.h"
-
-/*
- * All these constants are specific to the Pit board. If we reuse this command
- * on other boards, we'll need to move the table to board.c.
- */
-static const struct {
- const char *name;
- int voltage_mv;
- int current_range_ma;
-} pmu_fet[] = {
- {"backlight", 11400, 1100},
- {"video" , 5000, 220},
- {"wwan" , 3300, 3300},
- {"sdcard" , 3300, 1100},
- {"camera" , 3300, 1100},
- {"lcd" , 3300, 1100},
- {"video_add", 5000, 1100},
-}, pmu_dcdc[] = {
- {"p5000", 5050, 5000},
- {"p3300", 3333, 5000},
- {"p1350", 1350, 5000},
-};
-
-/* These constants may be Pit-specific as well. */
-static const int pmu_voltage_range_mv = 17000;
-static const int pmu_ac_sense_range_mv = 33;
-static const int pmu_bat_sense_range_mv = 40;
-static const int pmu_adc_resolution = 1024;
-static const int pmu_sense_resistor_bat = CONFIG_CHARGER_SENSE_RESISTOR;
-static const int pmu_sense_resistor_ac = CONFIG_CHARGER_SENSE_RESISTOR_AC;
-
-static inline int calc_voltage(int adc_value, int range_mv)
-{
- return adc_value * range_mv / pmu_adc_resolution;
-}
-
-static inline int calc_current(int adc_value, int range_ma)
-{
- return adc_value * range_ma / pmu_adc_resolution;
-}
-
-static inline int calc_current_sr(int adc_value, int sense_resistor_mohm,
- int range_mv)
-{
- return adc_value * range_mv * 1000 / sense_resistor_mohm /
- pmu_adc_resolution;
-}
-
-static int command_powerinfo(int argc, char **argv)
-{
- int voltage, current;
- int index;
-
- ccputs("[pmu powerinfo]\n");
- /* DC to DC converter */
- for (index = 0; index < ARRAY_SIZE(pmu_dcdc); index++) {
- current = calc_current(
- pmu_adc_read(ADC_IDCDC1 + index, ADC_FLAG_KEEP_ON),
- pmu_dcdc[index].current_range_ma);
- voltage = pmu_dcdc[index].voltage_mv;
- ccprintf("DCDC%d:%6d mV,%4d mA,%4d mW %s\n",
- index + 1, voltage, current, voltage * current / 1000,
- pmu_dcdc[index].name);
- }
-
- /* FET */
- for (index = 0; index < ARRAY_SIZE(pmu_fet); index++) {
- current = calc_current(
- pmu_adc_read(ADC_IFET1 + index, ADC_FLAG_KEEP_ON),
- pmu_fet[index].current_range_ma);
- voltage = pmu_fet[index].voltage_mv;
- ccprintf("FET%d :%6d mV,%4d mA,%4d mW %s\n",
- index + 1, voltage, current, voltage * current / 1000,
- pmu_fet[index].name);
- }
-
- /* Battery charging */
- voltage = calc_voltage(
- pmu_adc_read(ADC_VBAT, ADC_FLAG_KEEP_ON),
- pmu_voltage_range_mv);
- current = calc_current_sr(
- pmu_adc_read(ADC_IBAT, ADC_FLAG_KEEP_ON),
- pmu_sense_resistor_bat, pmu_bat_sense_range_mv);
- ccprintf("Chg :%6d mV,%4d mA,%4d mW\n", voltage, current,
- voltage * current / 1000);
-
- /* AC input */
- voltage = calc_voltage(
- pmu_adc_read(ADC_VAC, ADC_FLAG_KEEP_ON),
- pmu_voltage_range_mv);
- current = calc_current_sr(
- pmu_adc_read(ADC_IAC, 0),
- pmu_sense_resistor_ac, pmu_ac_sense_range_mv);
- ccprintf("AC :%6d mV,%4d mA,%4d mW\n", voltage, current,
- voltage * current / 1000);
-
-
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(powerinfo, command_powerinfo,
- NULL,
- "Show PMU power info");
-
-/**
- * Host command to get power info from PMU
- *
- * This reuses the same EC_CMD_POWER_INFO host command as Spring, but doesn't
- * provide the full set of information because Pit doesn't take power over USB.
- */
-static int power_command_info(struct host_cmd_handler_args *args)
-{
- struct ec_response_power_info *r = args->response;
-
- r->voltage_ac = calc_voltage(
- pmu_adc_read(ADC_VAC, ADC_FLAG_KEEP_ON),
- pmu_voltage_range_mv);
- if (extpower_is_present()) {
- /* Power source = AC */
- r->voltage_system = r->voltage_ac;
- r->current_system = calc_current_sr(
- pmu_adc_read(ADC_IAC, ADC_FLAG_KEEP_ON),
- pmu_sense_resistor_ac, pmu_ac_sense_range_mv);
- } else {
- /* Power source == battery */
- struct batt_params batt;
-
- r->voltage_system = calc_voltage(
- pmu_adc_read(ADC_VBAT, ADC_FLAG_KEEP_ON),
- pmu_voltage_range_mv);
- /*
- * PMU reads charging current. When battery is discharging, ADC
- * returns 0. Use battery gas gauge output instead.
- */
- battery_get_params(&batt);
- r->current_system = -batt.current;
- }
-
- /* Ignore USB powerinfo fields. */
- r->usb_dev_type = 0;
- r->usb_current_limit = 0;
-
- args->response_size = sizeof(*r);
-
- return EC_RES_SUCCESS;
-}
-DECLARE_HOST_COMMAND(EC_CMD_POWER_INFO, power_command_info, EC_VER_MASK(0));