summaryrefslogtreecommitdiff
path: root/board/poppy/base_detect_lux.c
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-11-04 12:11:58 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-05 04:22:34 +0000
commit252457d4b21f46889eebad61d4c0a65331919cec (patch)
tree01856c4d31d710b20e85a74c8d7b5836e35c3b98 /board/poppy/base_detect_lux.c
parent08f5a1e6fc2c9467230444ac9b582dcf4d9f0068 (diff)
downloadchrome-ec-firmware-brya-14505.B-ish.tar.gz
In the interest of making long-term branch maintenance incur as little technical debt on us as possible, we should not maintain any files on the branch we are not actually using. This has the added effect of making it extremely clear when merging CLs from the main branch when changes have the possibility to affect us. The follow-on CL adds a convenience script to actually pull updates from the main branch and generate a CL for the update. BUG=b:204206272 BRANCH=ish TEST=make BOARD=arcada_ish && make BOARD=drallion_ish Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I17e4694c38219b5a0823e0a3e55a28d1348f4b18 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3262038 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'board/poppy/base_detect_lux.c')
-rw-r--r--board/poppy/base_detect_lux.c237
1 files changed, 0 insertions, 237 deletions
diff --git a/board/poppy/base_detect_lux.c b/board/poppy/base_detect_lux.c
deleted file mode 100644
index c348eb681d..0000000000
--- a/board/poppy/base_detect_lux.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/* Copyright 2018 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.
- */
-
-/* Lux base detection code */
-
-#include "adc.h"
-#include "board.h"
-#include "chipset.h"
-#include "common.h"
-#include "console.h"
-#include "extpower.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "host_command.h"
-#include "system.h"
-#include "tablet_mode.h"
-#include "task.h"
-#include "timer.h"
-#include "util.h"
-
-#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
-
-/* Base detection and debouncing */
-#define BASE_DETECT_DEBOUNCE_US (20 * MSEC)
-
-/*
- * If the base status is unclear (i.e. not within expected ranges, read
- * the ADC value again every 500ms.
- */
-#define BASE_DETECT_RETRY_US (500 * MSEC)
-
-/*
- * When base is disconnected, and gets connected:
- * Lid has 1M pull-up, base has 200K pull-down, so the ADC
- * value should be around 200/(200+1000)*3300 = 550.
- *
- * Idle value should be ~3300: lid has 1M pull-up, and nothing else (i.e. ADC
- * maxing out at 2813).
- */
-#define BASE_DISCONNECTED_CONNECT_MIN_MV 450
-#define BASE_DISCONNECTED_CONNECT_MAX_MV 600
-
-#define BASE_DISCONNECTED_MIN_MV 2800
-#define BASE_DISCONNECTED_MAX_MV (ADC_MAX_VOLT+1)
-
-/*
- * When base is connected, then gets disconnected:
- * Lid has 1M pull-up, lid has 10.0K pull-down, so the ADC
- * value should be around 10.0/(10.0+1000)*3300 = 33.
- *
- * Idle level when connected should be:
- * Lid has 10K pull-down, base has 5.1K pull-up, so the ADC value should be
- * around 10.0/(10.0+5.1)*3300 = 2185 (actual value is 2153 as there is still
- * a 1M pull-up on lid, and 200K pull-down on base).
- */
-#define BASE_CONNECTED_DISCONNECT_MIN_MV 20
-#define BASE_CONNECTED_DISCONNECT_MAX_MV 40
-
-#define BASE_CONNECTED_MIN_MV 2050
-#define BASE_CONNECTED_MAX_MV 2300
-
-static uint64_t base_detect_debounce_time;
-
-static void base_detect_deferred(void);
-DECLARE_DEFERRED(base_detect_deferred);
-
-enum base_status {
- BASE_UNKNOWN = 0,
- BASE_DISCONNECTED = 1,
- BASE_CONNECTED = 2,
-};
-
-static enum base_status current_base_status;
-
-/**
- * Board-specific routine to indicate if the base is connected.
- */
-int board_is_base_connected(void)
-{
- return current_base_status == BASE_CONNECTED;
-}
-
-/**
- * Board-specific routine to enable power distribution between lid and base
- * (current can flow both ways).
- *
- * We only allow the base power to be enabled if the detection code knows that
- * the base is connected.
- */
-void board_enable_base_power(int enable)
-{
- gpio_set_level(GPIO_PPVAR_VAR_BASE,
- enable && current_base_status == BASE_CONNECTED);
-}
-
-/*
- * This function is called whenever there is a change in the base detect
- * status. Actions taken include:
- * 1. Enable/disable pull-down on half-duplex UART line
- * 2. Disable power transfer between lid and base when unplugged.
- * 3. Indicate mode change to host.
- * 4. Indicate tablet mode to host. Current assumption is that if base is
- * disconnected then the system is in tablet mode, else if the base is
- * connected, then the system is not in tablet mode.
- */
-static void base_detect_change(enum base_status status)
-{
- int connected = (status == BASE_CONNECTED);
-
- if (current_base_status == status)
- return;
-
- current_base_status = status;
-
- /* Enable pull-down if connected. */
- gpio_set_level(GPIO_EC_COMM_PD, !connected);
- /* Disable power to/from base as quickly as possible. */
- if (!connected)
- board_enable_base_power(0);
-
- /*
- * Wake the charger task (it is responsible for enabling power to the
- * base, and providing OTG power to the base if required).
- */
- task_wake(TASK_ID_CHARGER);
-
- tablet_set_mode(!connected, TABLET_TRIGGER_BASE);
-}
-
-static void print_base_detect_value(const char *str, int v)
-{
- CPRINTS("Base %s. ADC: %d", str, v);
-}
-
-static void base_detect_deferred(void)
-{
- uint64_t time_now = get_time().val;
- int v;
-
- if (base_detect_debounce_time > time_now) {
- hook_call_deferred(&base_detect_deferred_data,
- base_detect_debounce_time - time_now);
- return;
- }
-
- v = adc_read_channel(ADC_BASE_DET);
- if (v == ADC_READ_ERROR)
- goto retry;
-
- if (current_base_status == BASE_CONNECTED) {
- if (v >= BASE_CONNECTED_DISCONNECT_MIN_MV &&
- v <= BASE_CONNECTED_DISCONNECT_MAX_MV) {
- print_base_detect_value("disconnected", v);
- base_detect_change(BASE_DISCONNECTED);
- return;
- } else if (v >= BASE_CONNECTED_MIN_MV &&
- v <= BASE_CONNECTED_MAX_MV) {
- /* Still connected. */
- return;
- }
- } else { /* Disconnected or unknown. */
- if (v >= BASE_DISCONNECTED_CONNECT_MIN_MV &&
- v <= BASE_DISCONNECTED_CONNECT_MAX_MV) {
- print_base_detect_value("connected", v);
- base_detect_change(BASE_CONNECTED);
- return;
- } else if (v >= BASE_DISCONNECTED_MIN_MV &&
- v <= BASE_DISCONNECTED_MAX_MV) {
- if (current_base_status == BASE_UNKNOWN) {
- print_base_detect_value("disconnected", v);
- base_detect_change(BASE_DISCONNECTED);
- }
- /* Still disconnected. */
- return;
- }
- }
-
-retry:
- print_base_detect_value("status unclear", v);
- /* Unclear base status, schedule again in a while. */
- hook_call_deferred(&base_detect_deferred_data,
- BASE_DETECT_RETRY_US);
-}
-
-void base_detect_interrupt(enum gpio_signal signal)
-{
- uint64_t time_now = get_time().val;
-
- if (base_detect_debounce_time <= time_now)
- hook_call_deferred(&base_detect_deferred_data,
- BASE_DETECT_DEBOUNCE_US);
-
- base_detect_debounce_time = time_now + BASE_DETECT_DEBOUNCE_US;
-}
-
-void board_base_reset(void)
-{
- CPRINTS("Resetting base.");
- base_detect_change(BASE_UNKNOWN);
- hook_call_deferred(&base_detect_deferred_data, BASE_DETECT_RETRY_US);
-}
-
-static void base_init(void)
-{
- /*
- * Make sure base power and pull-down are off. This will reset the base
- * if it is already connected.
- */
- board_enable_base_power(0);
- gpio_set_level(GPIO_EC_COMM_PD, 1);
-
- /* Enable base detection interrupt. */
- hook_call_deferred(&base_detect_deferred_data, BASE_DETECT_DEBOUNCE_US);
- gpio_enable_interrupt(GPIO_BASE_DET_A);
-}
-DECLARE_HOOK(HOOK_INIT, base_init, HOOK_PRIO_DEFAULT+1);
-
-void base_force_state(enum ec_set_base_state_cmd state)
-{
- if (state == EC_SET_BASE_STATE_ATTACH) {
- gpio_disable_interrupt(GPIO_BASE_DET_A);
- base_detect_change(BASE_CONNECTED);
- CPRINTS("BD forced connected");
- } else if (state == EC_SET_BASE_STATE_DETACH) {
- gpio_disable_interrupt(GPIO_BASE_DET_A);
- base_detect_change(BASE_DISCONNECTED);
- CPRINTS("BD forced disconnected");
- } else {
- hook_call_deferred(&base_detect_deferred_data,
- BASE_DETECT_DEBOUNCE_US);
- gpio_enable_interrupt(GPIO_BASE_DET_A);
- CPRINTS("BD forced reset");
- }
-}