summaryrefslogtreecommitdiff
path: root/board/fizz
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-09-29 17:38:12 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-10-24 12:57:47 -0700
commit5fd1540e62be47747c4fe234a0b348e58e0cfd3f (patch)
tree88584ce0e03811d831f677097dbe0aaf572b7375 /board/fizz
parente3d15afa68d9e4c8866a0301b33ff6e6d78b1750 (diff)
downloadchrome-ec-5fd1540e62be47747c4fe234a0b348e58e0cfd3f.tar.gz
Fizz: Inform host of BJ plug/unplug event
This patch makes EC notify the host of BJ plug or unplug event by triggering EC_HOST_EVENT_PD_MCU. The host can then use EC_CMD_PD_HOST_EVENT_STATUS to get event details. BUG=b:67060237 BRANCH=none TEST=Boot Fizz on Type-C. Plug/unplug BJ adapter. Verify host event is set by hostevent. Verify available_charge is set by hacking chgsup command. Change-Id: I1831bec9715e0191cb9610e05d08bbc08347b513 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/692848 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'board/fizz')
-rw-r--r--board/fizz/board.c36
-rw-r--r--board/fizz/gpio.inc2
-rw-r--r--board/fizz/usb_pd_policy.c14
3 files changed, 39 insertions, 13 deletions
diff --git a/board/fizz/board.c b/board/fizz/board.c
index 3f2a55ad02..7d5a0d6228 100644
--- a/board/fizz/board.c
+++ b/board/fizz/board.c
@@ -64,10 +64,42 @@ static void tcpc_alert_event(enum gpio_signal signal)
#endif
}
-void adp_in(enum gpio_signal signal)
+#define ADP_DEBOUNCE_MS 1000 /* Debounce time for BJ plug/unplug */
+/*
+ * ADP_IN pin state. It's initialized to 1 (=unplugged) because the IRQ won't
+ * be triggered if BJ is the power source.
+ */
+static int adp_in_state = 1;
+
+static void adp_in_deferred(void)
{
/* TODO: Switch power source from USB-C to BJ only if we're in S5. */
- CPRINTS("BJ detected");
+ struct charge_port_info cpi;
+ int level = gpio_get_level(GPIO_ADP_IN_L);
+
+ /* Debounce */
+ if (level == adp_in_state)
+ return;
+ /* High = unplugged. Low = plugged. TODO: Set appropriate voltage. */
+ cpi.voltage = level ? 0 : 19000;
+ /* Set to 0 to ensure charge manager will ignore it. */
+ cpi.current = 0;
+ charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED, 1, &cpi);
+ /*
+ * Explicitly notifies the host that BJ is plugged or unplugged
+ * (when running on a type-c adapter).
+ */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
+ adp_in_state = level;
+}
+DECLARE_DEFERRED(adp_in_deferred);
+
+/* IRQ for BJ plug/unplug. It shouldn't be called if BJ is the power source. */
+void adp_in(enum gpio_signal signal)
+{
+ if (adp_in_state == gpio_get_level(GPIO_ADP_IN_L))
+ return;
+ hook_call_deferred(&adp_in_deferred_data, ADP_DEBOUNCE_MS * MSEC);
}
void vbus0_evt(enum gpio_signal signal)
diff --git a/board/fizz/gpio.inc b/board/fizz/gpio.inc
index b50212a17e..c1b3be59c7 100644
--- a/board/fizz/gpio.inc
+++ b/board/fizz/gpio.inc
@@ -22,7 +22,7 @@ GPIO_INT(PCH_SLP_SUS_L, PIN(6, 2), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(RSMRST_L_PGOOD, PIN(B, 0), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(PMIC_DPWROK, PIN(C, 7), GPIO_INT_BOTH, power_signal_interrupt)
GPIO_INT(WP_L, PIN(9, 3), GPIO_INT_BOTH, switch_interrupt)
-GPIO_INT(ADP_IN_L, PIN(C, 5), GPIO_INT_LOW | GPIO_PULL_UP, adp_in) /* Low: BJ detected */
+GPIO_INT(ADP_IN_L, PIN(C, 5), GPIO_INT_BOTH | GPIO_PULL_UP, adp_in) /* Low: BJ detected */
GPIO_INT(USB_C0_VBUS_WAKE_L, PIN(9, 7), GPIO_INT_BOTH | GPIO_PULL_UP, vbus0_evt)
GPIO_INT(RECOVERY_L, PIN(8, 2), GPIO_INT_BOTH, button_interrupt) /* Recovery button */
GPIO(PCH_RTCRST, PIN(E, 7), GPIO_OUT_LOW) /* RTCRST# to SOC */
diff --git a/board/fizz/usb_pd_policy.c b/board/fizz/usb_pd_policy.c
index 235ad92725..ee853f0ab6 100644
--- a/board/fizz/usb_pd_policy.c
+++ b/board/fizz/usb_pd_policy.c
@@ -224,10 +224,7 @@ static void board_charge_manager_init(void)
int input_voltage;
enum charge_port input_port;
int i, j;
- struct charge_port_info cpi = {
- .voltage = USB_CHARGER_VOLTAGE_MV,
- .current = 0,
- };
+ struct charge_port_info cpi = { 0 };
/* Initialize all charge suppliers to 0 */
for (i = 0; i < CHARGE_PORT_COUNT; i++) {
@@ -236,12 +233,7 @@ static void board_charge_manager_init(void)
}
input_voltage = adc_read_channel(ADC_VBUS);
- if (system_get_board_version() == 0)
- /* TODO(dnojiri): Remove this case after proto1 is deprecated */
- input_port = input_voltage > 5500 ?
- CHARGE_PORT_BARRELJACK : CHARGE_PORT_TYPEC0;
- else /* proto2 and onward */
- input_port = gpio_get_level(GPIO_ADP_IN_L) ?
+ input_port = gpio_get_level(GPIO_ADP_IN_L) ?
CHARGE_PORT_TYPEC0 : CHARGE_PORT_BARRELJACK;
CPRINTS("Power Source: p%d (%dmV)", input_port, input_voltage);
@@ -283,10 +275,12 @@ int board_set_active_charge_port(int port)
case CHARGE_PORT_TYPEC0:
gpio_set_level(GPIO_USB_C0_CHARGE_L, 0);
gpio_set_level(GPIO_AC_JACK_CHARGE_L, 1);
+ gpio_enable_interrupt(GPIO_ADP_IN_L);
break;
case CHARGE_PORT_BARRELJACK :
gpio_set_level(GPIO_AC_JACK_CHARGE_L, 0);
gpio_set_level(GPIO_USB_C0_CHARGE_L, 1);
+ gpio_disable_interrupt(GPIO_ADP_IN_L);
break;
default:
return EC_ERROR_INVAL;