summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-05-03 13:44:18 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-05-17 19:06:31 -0700
commit760c89fe3746278c9324c981d0adf6d3e79562d0 (patch)
tree1eb56808de7c8e49cb209d77366545de19ace955
parent120ce3eaa054bcdb3f2c33a0e11a6a821fea67ce (diff)
downloadchrome-ec-760c89fe3746278c9324c981d0adf6d3e79562d0.tar.gz
Fizz: Set up charge suppliers at boot
Fizz has two power sources: barrel jack and type-c port. It selects a power source at boot and does not dynamicall switch to the other ports after that. Fizz initializes all power suppliers of all ports to zero then initialize the source supplier (barrel jack or type-c port). When both sources are provided, it prefers a barrel jack. This detection is done by reading the voltage on PPVAR_PWR_IN. If barrel jack is detected as a sink, type-c port works as a source only. If type-c port is detected as a sink, type-c port works as a sink only. Fizz does not have a battery. So, battery module is removed. BUG=b:37573548,b:37316498 BRANCH=none TEST=Boot on both type-c & barrel jack. Change-Id: If4f5ff0c6019d06ac9dacb5dd365f5aa96bffef3 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/499547
-rw-r--r--board/fizz/battery.c134
-rw-r--r--board/fizz/board.c71
-rw-r--r--board/fizz/board.h27
-rw-r--r--board/fizz/build.mk1
-rw-r--r--board/fizz/ec.tasklist1
-rw-r--r--board/fizz/gpio.inc1
-rw-r--r--board/fizz/usb_pd_policy.c54
-rw-r--r--power/intel_x86.c6
8 files changed, 96 insertions, 199 deletions
diff --git a/board/fizz/battery.c b/board/fizz/battery.c
deleted file mode 100644
index 221814dba3..0000000000
--- a/board/fizz/battery.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/* Copyright 2017 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.
- *
- * Placeholder values for temporary battery pack.
- */
-
-#include "battery.h"
-#include "battery_smart.h"
-#include "charge_state.h"
-#include "console.h"
-#include "ec_commands.h"
-#include "extpower.h"
-#include "util.h"
-
-/* Shutdown mode parameter to write to manufacturer access register */
-#define SB_SHIP_MODE_REG 0x3a
-#define SB_SHUTDOWN_DATA 0xC574
-
-static const struct battery_info info = {
- .voltage_max = 13200,
- .voltage_normal = 11550,
- .voltage_min = 9100,
- /* Pre-charge values. */
- .precharge_current = 256, /* mA */
-
- .start_charging_min_c = 0,
- .start_charging_max_c = 50,
- .charging_min_c = 0,
- .charging_max_c = 60,
- .discharging_min_c = 0,
- .discharging_max_c = 60,
-};
-
-const struct battery_info *battery_get_info(void)
-{
- return &info;
-}
-
-int board_cut_off_battery(void)
-{
- int rv;
-
- /* Ship mode command must be sent twice to take effect */
- rv = sb_write(SB_SHIP_MODE_REG, SB_SHUTDOWN_DATA);
-
- if (rv != EC_SUCCESS)
- return rv;
-
- return sb_write(SB_SHIP_MODE_REG, SB_SHUTDOWN_DATA);
-}
-
-/* TODO(crosbug.com/p/61098): Verify that this applies with our battery pack */
-enum battery_disconnect_state battery_get_disconnect_state(void)
-{
- uint8_t data[6];
- int rv;
-
- /*
- * Take note if we find that the battery isn't in disconnect state,
- * and always return NOT_DISCONNECTED without probing the battery.
- * This assumes the battery will not go to disconnect state during
- * runtime.
- */
- static int not_disconnected;
-
- if (not_disconnected)
- return BATTERY_NOT_DISCONNECTED;
-
- if (extpower_is_present()) {
- /* Check if battery charging + discharging is disabled. */
- rv = sb_read_mfgacc(PARAM_OPERATION_STATUS,
- SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data));
- if (rv)
- return BATTERY_DISCONNECT_ERROR;
-
- if (~data[3] & (BATTERY_DISCHARGING_DISABLED |
- BATTERY_CHARGING_DISABLED)) {
- not_disconnected = 1;
- return BATTERY_NOT_DISCONNECTED;
- }
-
- /*
- * Battery is neither charging nor discharging. Verify that
- * we didn't enter this state due to a safety fault.
- */
- rv = sb_read_mfgacc(PARAM_SAFETY_STATUS,
- SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data));
- if (rv || data[2] || data[3] || data[4] || data[5])
- return BATTERY_DISCONNECT_ERROR;
-
- /*
- * Battery is present and also the status is initialized and
- * no safety fault, battery is disconnected.
- */
- if (battery_is_present() == BP_YES)
- return BATTERY_DISCONNECTED;
- }
- not_disconnected = 1;
- return BATTERY_NOT_DISCONNECTED;
-}
-
-int charger_profile_override(struct charge_state_data *curr)
-{
- const struct battery_info *batt_info;
- /* battery temp in 0.1 deg C */
- int bat_temp_c = curr->batt.temperature - 2731;
-
- batt_info = battery_get_info();
- /* Don't charge if outside of allowable temperature range */
- if (bat_temp_c >= batt_info->charging_max_c * 10 ||
- bat_temp_c < batt_info->charging_min_c * 10) {
- curr->requested_current = 0;
- curr->requested_voltage = 0;
- curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE;
- curr->state = ST_IDLE;
- }
- return 0;
-}
-
-/* Customs options controllable by host command. */
-#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0)
-
-enum ec_status charger_profile_override_get_param(uint32_t param,
- uint32_t *value)
-{
- return EC_RES_INVALID_PARAM;
-}
-
-enum ec_status charger_profile_override_set_param(uint32_t param,
- uint32_t value)
-{
- return EC_RES_INVALID_PARAM;
-}
diff --git a/board/fizz/board.c b/board/fizz/board.c
index 157b452e62..6f03aa19ea 100644
--- a/board/fizz/board.c
+++ b/board/fizz/board.c
@@ -8,6 +8,7 @@
#include "adc.h"
#include "adc_chip.h"
#include "als.h"
+#include "battery.h"
#include "bd99992gw.h"
#include "board_config.h"
#include "button.h"
@@ -90,10 +91,7 @@ const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins);
/* ADC channels */
const struct adc_t adc_channels[] = {
- /* Base detection */
- [ADC_BASE_DET] = {"BASE_DET", NPCX_ADC_CH0,
- ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
- /* Vbus sensing (10x voltage divider). */
+ /* Vbus sensing (1/10 voltage divider). */
[ADC_VBUS] = {"VBUS", NPCX_ADC_CH2, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0},
/*
* Adapter current output or battery charging/discharging current (uV)
@@ -195,8 +193,6 @@ uint16_t tcpc_get_alert_status(void)
* src/mainboard/google/${board}/acpi/dptf.asl
*/
const struct temp_sensor_t temp_sensors[] = {
- {"Battery", TEMP_SENSOR_TYPE_BATTERY, charge_get_battery_temp,
- 0, 4},
{"TMP432_Internal", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val,
TMP432_IDX_LOCAL, 4},
{"TMP432_Sensor_1", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val,
@@ -215,7 +211,6 @@ struct ec_thermal_config thermal_params[] = {
{{0, 0, 0}, C_TO_K(35), C_TO_K(68)}, /* TMP432_Internal */
{{0, 0, 0}, 0, 0}, /* TMP432_Sensor_1 */
{{0, 0, 0}, 0, 0}, /* TMP432_Sensor_2 */
- {{0, 0, 0}, 0, 0}, /* Battery */
};
BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT);
@@ -373,52 +368,42 @@ static void board_init(void)
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-/**
- * Set active charge port -- only one port can be active at a time.
- *
- * @param charge_port Charge port to enable.
- *
- * Returns EC_SUCCESS if charge port is accepted and made active,
- * EC_ERROR_* otherwise.
- */
int board_set_active_charge_port(int charge_port)
{
- /* charge port is a physical port */
- int is_real_port = (charge_port >= 0 &&
- charge_port < CONFIG_USB_PD_PORT_COUNT);
- /* check if we are source VBUS on the port */
- int source = gpio_get_level(GPIO_USB_C0_5V_EN);
-
- if (is_real_port && source) {
- CPRINTF("Skip enable p%d", charge_port);
+ const int active_port = charge_manager_get_active_charge_port();
+
+ if (charge_port < 0 || CHARGE_PORT_COUNT <= charge_port)
return EC_ERROR_INVAL;
- }
- CPRINTF("New chg p%d", charge_port);
+ if (charge_port == active_port)
+ return EC_SUCCESS;
- if (charge_port == CHARGE_PORT_NONE)
- /* Disable port */
- gpio_set_level(GPIO_USB_C0_CHARGE_L, 1);
- else
- /* Enable charging port */
+ /* Don't charge from a source port */
+ if (board_vbus_source_enabled(charge_port))
+ return EC_ERROR_INVAL;
+
+ CPRINTS("New charger p%d", charge_port);
+
+ switch (charge_port) {
+ case CHARGE_PORT_TYPEC0:
gpio_set_level(GPIO_USB_C0_CHARGE_L, 0);
+ gpio_set_level(GPIO_AC_JACK_CHARGE_L, 1);
+ break;
+ case CHARGE_PORT_BARRELJACK :
+ gpio_set_level(GPIO_AC_JACK_CHARGE_L, 0);
+ gpio_set_level(GPIO_USB_C0_CHARGE_L, 1);
+ break;
+ default:
+ return EC_ERROR_INVAL;
+ }
return EC_SUCCESS;
}
-/**
- * Set the charge limit based upon desired maximum.
- *
- * @param port Port number.
- * @param supplier Charge supplier type.
- * @param charge_ma Desired charge limit (mA).
- * @param charge_mv Negotiated charge voltage (mV).
- */
void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
- charge_set_input_current_limit(MAX(charge_ma,
- CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
+ charger_set_input_current(charge_ma);
}
/**
@@ -479,3 +464,9 @@ const struct button_config *recovery_buttons[] = {
&buttons[BUTTON_RECOVERY],
};
const int recovery_buttons_count = ARRAY_SIZE(recovery_buttons);
+
+enum battery_present battery_is_present(void)
+{
+ /* The GPIO is low when the battery is present */
+ return BP_NO;
+}
diff --git a/board/fizz/board.h b/board/fizz/board.h
index f723e89415..0848f35b89 100644
--- a/board/fizz/board.h
+++ b/board/fizz/board.h
@@ -55,27 +55,12 @@
#define CONFIG_ESPI_VW_SIGNALS
#define CONFIG_LPC
-/* Battery */
-#define CONFIG_BATTERY_CUT_OFF
-#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION"
-#define CONFIG_BATTERY_PRESENT_GPIO GPIO_BATTERY_PRESENT_L
-#define CONFIG_BATTERY_REVIVE_DISCONNECT
-#define CONFIG_BATTERY_SMART
-
/* Charger */
#define CONFIG_CHARGE_MANAGER
#define CONFIG_CHARGE_RAMP_HW /* This, or just RAMP? */
-#define CONFIG_CHARGER
-#define CONFIG_CHARGER_V2
#define CONFIG_CHARGER_ISL9238
-#define CONFIG_CHARGER_DISCHARGE_ON_AC
#define CONFIG_CHARGER_INPUT_CURRENT 512
-#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 15000
-#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 1
-#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1
-#define CONFIG_CHARGER_NARROW_VDC
-#define CONFIG_CHARGER_PROFILE_OVERRIDE
#define CONFIG_CHARGER_SENSE_RESISTOR 10
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20
#define CONFIG_CMD_CHARGER_ADC_AMON_BMON
@@ -119,6 +104,10 @@
#define CONFIG_USBC_VCONN
#define CONFIG_USBC_VCONN_SWAP
+/* Charge ports */
+#undef CONFIG_DEDICATED_CHARGE_PORT_COUNT
+#define CONFIG_DEDICATED_CHARGE_PORT_COUNT 1
+
/* USB-A config */
#define CONFIG_USB_PORT_POWER_DUMB
#define USB_PORT_COUNT 5
@@ -144,6 +133,11 @@
#include "gpio_signal.h"
#include "registers.h"
+enum charge_port {
+ CHARGE_PORT_TYPEC0,
+ CHARGE_PORT_BARRELJACK,
+};
+
enum power_signal {
X86_SLP_S0_DEASSERTED,
X86_SLP_S3_DEASSERTED,
@@ -155,7 +149,6 @@ enum power_signal {
};
enum temp_sensor_id {
- TEMP_SENSOR_BATTERY, /* BD99956GW TSENSE */
TEMP_SENSOR_CHARGER, /* BD99992GW SYSTHERM1 */
TEMP_SENSOR_DRAM, /* BD99992GW SYSTHERM2 */
TEMP_SENSOR_EMMC, /* BD99992GW SYSTHERM3 */
@@ -163,7 +156,6 @@ enum temp_sensor_id {
};
enum adc_channel {
- ADC_BASE_DET,
ADC_VBUS,
ADC_AMON_BMON,
ADC_CH_COUNT
@@ -195,6 +187,7 @@ enum button {
int board_get_version(void);
void board_reset_pd_mcu(void);
void board_set_tcpc_power_mode(int port, int mode);
+int board_get_battery_soc(void);
#endif /* !__ASSEMBLER__ */
diff --git a/board/fizz/build.mk b/board/fizz/build.mk
index 2ff420939e..74094ac834 100644
--- a/board/fizz/build.mk
+++ b/board/fizz/build.mk
@@ -10,6 +10,5 @@ CHIP:=npcx
CHIP_VARIANT:=npcx5m6g
board-y=board.o
-board-$(CONFIG_BATTERY_SMART)+=battery.o
board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
board-y+=led.o
diff --git a/board/fizz/ec.tasklist b/board/fizz/ec.tasklist
index 582d5ddee8..06c39984a3 100644
--- a/board/fizz/ec.tasklist
+++ b/board/fizz/ec.tasklist
@@ -22,7 +22,6 @@
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
- TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \
diff --git a/board/fizz/gpio.inc b/board/fizz/gpio.inc
index 92ee2b1798..a73f3745e1 100644
--- a/board/fizz/gpio.inc
+++ b/board/fizz/gpio.inc
@@ -73,6 +73,7 @@ GPIO(I2C3_SDA, PIN(D, 0), GPIO_INPUT) /* EC_THEM_SDA */
/* 5V enables: INPUT=1.5A, OUT_LOW=OFF, OUT_HIGH=3A */
GPIO(USB_C0_5V_EN, PIN(4, 2), GPIO_OUT_LOW | GPIO_PULL_UP) /* C0 5V Enable */
GPIO(USB_C0_CHARGE_L, PIN(C, 0), GPIO_OUT_LOW) /* C0 Charge enable */
+GPIO(AC_JACK_CHARGE_L, PIN(C, 3), GPIO_OUT_LOW) /* AC jack charge enable */
GPIO(USB_C0_PD_RST_ODL, PIN(0, 3), GPIO_OUT_LOW) /* C0 PD Reset */
GPIO(USB_C0_DP_HPD, PIN(9, 4), GPIO_INPUT) /* C0 DP Hotplug Detect */
GPIO(USB_C0_TCPC_PWR, PIN(8, 4), GPIO_OUT_LOW) /* Enable C0 TCPC Power */
diff --git a/board/fizz/usb_pd_policy.c b/board/fizz/usb_pd_policy.c
index 122c4d39ca..69ab2b379e 100644
--- a/board/fizz/usb_pd_policy.c
+++ b/board/fizz/usb_pd_policy.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include "adc.h"
#include "atomic.h"
#include "extpower.h"
#include "charge_manager.h"
@@ -55,18 +56,19 @@ void pd_transition_voltage(int idx)
/* No-operation: we are always 5V */
}
-static uint8_t vbus_en;
-
int board_vbus_source_enabled(int port)
{
- return vbus_en;
+ if (port != 0)
+ return 0;
+ return gpio_get_level(GPIO_USB_C0_5V_EN);
}
int pd_set_power_supply_ready(int port)
{
/* Disable charging */
gpio_set_level(GPIO_USB_C0_CHARGE_L, 1);
- /* Provide VBUS */
+
+ /* Enable VBUS source */
gpio_set_level(GPIO_USB_C0_5V_EN, 1);
/* notify host of power info change */
@@ -77,7 +79,7 @@ int pd_set_power_supply_ready(int port)
void pd_power_supply_reset(int port)
{
- /* Disable VBUS */
+ /* Disable VBUS source */
gpio_set_level(GPIO_USB_C0_5V_EN, 0);
/* notify host of power info change */
@@ -243,6 +245,48 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload,
return 0;
}
+static void board_charge_manager_init(void)
+{
+ int input_voltage;
+ int i, j;
+ struct charge_port_info cpi = {
+ .voltage = USB_CHARGER_VOLTAGE_MV,
+ .current = 0,
+ };
+
+ /* Initialize all charge suppliers to 0 */
+ for (i = 0; i < CHARGE_PORT_COUNT; i++) {
+ for (j = 0; j < CHARGE_SUPPLIER_COUNT; j++)
+ charge_manager_update_charge(j, i, &cpi);
+ }
+
+ input_voltage = adc_read_channel(ADC_VBUS);
+
+ /* Initialize the power source supplier */
+ if (input_voltage > 5500) {
+ /* Power source is barrel jack */
+ CPRINTF("Source: BJ (%dmV)\n", input_voltage);
+ cpi.voltage = input_voltage;
+ cpi.current = 3330; /* TODO: Set right value */
+ charge_manager_update_charge(CHARGE_SUPPLIER_PROPRIETARY, 1,
+ &cpi);
+ /* Source only. Disable PD negotiation as a sink */
+ } else {
+ /* Power source is usb-c */
+ CPRINTF("Source: C0 (%dmV)\n", input_voltage);
+ cpi.voltage = input_voltage;
+ cpi.current = 3000; /* TODO: Set right value */
+ charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, 0, &cpi);
+ /* Sink only. Disable PD negotiation as a source */
+ }
+}
+DECLARE_HOOK(HOOK_INIT, board_charge_manager_init, HOOK_PRIO_INIT_ADC + 1);
+
+int board_get_battery_soc(void)
+{
+ return 100;
+}
+
#ifdef CONFIG_USB_PD_ALT_MODE_DFP
static int dp_flags[CONFIG_USB_PD_PORT_COUNT];
static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT];
diff --git a/power/intel_x86.c b/power/intel_x86.c
index c9e28f3d6f..f4b5251d00 100644
--- a/power/intel_x86.c
+++ b/power/intel_x86.c
@@ -180,7 +180,6 @@ enum power_state power_chipset_init(void)
enum power_state common_intel_x86_power_handle_state(enum power_state state)
{
- int tries = 0;
switch (state) {
case POWER_G3:
@@ -241,6 +240,9 @@ enum power_state common_intel_x86_power_handle_state(enum power_state state)
#endif
case POWER_G3S5:
+#ifdef CONFIG_CHARGER
+ {
+ int tries = 0;
/*
* Allow charger to be initialized for upto defined tries,
* in case we're trying to boot the AP with no battery.
@@ -257,6 +259,8 @@ enum power_state common_intel_x86_power_handle_state(enum power_state state)
chipset_force_shutdown();
return POWER_G3;
}
+ }
+#endif
/* Call hooks to initialize PMIC */
hook_notify(HOOK_CHIPSET_PRE_INIT);