mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-07 16:11:43 +00:00
This enables forwarding of the local PD/EC console over debug USB. It gates the console functionality based on the CCD mode that is set. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Enable partial CCD mode on ryu and verify that it is enumerated by the host correctly, but doesn't respond to console input, and doesn't generate output. Enable full CCD mode on ryu and verify that it is enumerated and that the console works as expected. Verify that the console still works by default on the discovery-stm32f072 board. Change-Id: I0325ce9689486c41387d6075330be1d7d42f1d42 Reviewed-on: https://chromium-review.googlesource.com/229342 Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org>
201 lines
5.4 KiB
C
201 lines
5.4 KiB
C
/* Copyright (c) 2014 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.
|
|
*/
|
|
/* ryu board configuration */
|
|
|
|
#include "adc.h"
|
|
#include "adc_chip.h"
|
|
#include "battery.h"
|
|
#include "case_closed_debug.h"
|
|
#include "charger.h"
|
|
#include "common.h"
|
|
#include "console.h"
|
|
#include "ec_version.h"
|
|
#include "gpio.h"
|
|
#include "hooks.h"
|
|
#include "host_command.h"
|
|
#include "i2c.h"
|
|
#include "inductive_charging.h"
|
|
#include "lid_switch.h"
|
|
#include "power.h"
|
|
#include "power_button.h"
|
|
#include "registers.h"
|
|
#include "task.h"
|
|
#include "usb.h"
|
|
#include "usb_pd.h"
|
|
#include "usb_pd_config.h"
|
|
#include "usb-stm32f3.h"
|
|
#include "util.h"
|
|
#include "pi3usb9281.h"
|
|
|
|
void vbus_evt(enum gpio_signal signal)
|
|
{
|
|
ccprintf("VBUS %d, %d!\n", signal, gpio_get_level(signal));
|
|
task_wake(TASK_ID_PD);
|
|
}
|
|
|
|
void unhandled_evt(enum gpio_signal signal)
|
|
{
|
|
ccprintf("Unhandled INT %d,%d!\n", signal, gpio_get_level(signal));
|
|
}
|
|
|
|
#include "gpio_list.h"
|
|
|
|
const void *const usb_strings[] = {
|
|
[USB_STR_DESC] = usb_string_desc,
|
|
[USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
|
|
[USB_STR_PRODUCT] = USB_STRING_DESC("Ryu debug"),
|
|
[USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
|
|
[USB_STR_CONSOLE_NAME] = USB_STRING_DESC("EC_PD"),
|
|
};
|
|
|
|
BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
|
|
|
|
/* Initialize board. */
|
|
static void board_init(void)
|
|
{
|
|
/*
|
|
* Determine recovery mode is requested by the power, volup, and
|
|
* voldown buttons being pressed.
|
|
*/
|
|
if (power_button_signal_asserted() &&
|
|
!gpio_get_level(GPIO_BTN_VOLD_L) &&
|
|
!gpio_get_level(GPIO_BTN_VOLU_L))
|
|
host_set_single_event(EC_HOST_EVENT_KEYBOARD_RECOVERY);
|
|
|
|
/*
|
|
* Enable CC lines after all GPIO have been initialized. Note, it is
|
|
* important that this is enabled after the CC_DEVICE_ODL lines are
|
|
* set low to specify device mode.
|
|
*/
|
|
gpio_set_level(GPIO_USBC_CC_EN, 1);
|
|
|
|
/* Enable interrupts on VBUS transitions. */
|
|
gpio_enable_interrupt(GPIO_CHGR_ACOK);
|
|
}
|
|
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
|
|
|
|
/* power signal list. Must match order of enum power_signal. */
|
|
const struct power_signal_info power_signal_list[] = {
|
|
{GPIO_AP_HOLD, 1, "AP_HOLD"},
|
|
{GPIO_AP_IN_SUSPEND, 1, "SUSPEND_ASSERTED"},
|
|
};
|
|
BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
|
|
|
|
/* ADC channels */
|
|
const struct adc_t adc_channels[] = {
|
|
/* Vbus sensing. Converted to mV, /10 voltage divider. */
|
|
[ADC_VBUS] = {"VBUS", 30000, 4096, 0, STM32_AIN(0)},
|
|
/* USB PD CC lines sensing. Converted to mV (3000mV/4096). */
|
|
[ADC_CC1_PD] = {"CC1_PD", 3000, 4096, 0, STM32_AIN(1)},
|
|
[ADC_CC2_PD] = {"CC2_PD", 3000, 4096, 0, STM32_AIN(3)},
|
|
/* Charger current sensing. Converted to mA. */
|
|
[ADC_IADP] = {"IADP", 7500, 4096, 0, STM32_AIN(8)},
|
|
[ADC_IBAT] = {"IBAT", 37500, 4096, 0, STM32_AIN(13)},
|
|
};
|
|
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
|
|
|
|
/* I2C ports */
|
|
const struct i2c_port_t i2c_ports[] = {
|
|
{"master", I2C_PORT_MASTER, 100,
|
|
GPIO_MASTER_I2C_SCL, GPIO_MASTER_I2C_SDA},
|
|
{"slave", I2C_PORT_SLAVE, 100,
|
|
GPIO_SLAVE_I2C_SCL, GPIO_SLAVE_I2C_SDA},
|
|
};
|
|
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
|
|
|
|
void board_set_usb_mux(int port, enum typec_mux mux, int polarity)
|
|
{
|
|
/* reset everything */
|
|
gpio_set_level(GPIO_USBC_SS_EN_L, 1);
|
|
gpio_set_level(GPIO_USBC_DP_MODE_L, 1);
|
|
gpio_set_level(GPIO_USBC_DP_POLARITY, 1);
|
|
gpio_set_level(GPIO_USBC_SS1_USB_MODE_L, 1);
|
|
gpio_set_level(GPIO_USBC_SS2_USB_MODE_L, 1);
|
|
|
|
if (mux == TYPEC_MUX_NONE)
|
|
/* everything is already disabled, we can return */
|
|
return;
|
|
|
|
if (mux == TYPEC_MUX_USB || mux == TYPEC_MUX_DOCK) {
|
|
/* USB 3.0 uses 2 superspeed lanes */
|
|
gpio_set_level(polarity ? GPIO_USBC_SS2_USB_MODE_L :
|
|
GPIO_USBC_SS1_USB_MODE_L, 0);
|
|
}
|
|
|
|
if (mux == TYPEC_MUX_DP || mux == TYPEC_MUX_DOCK) {
|
|
/* DP uses available superspeed lanes (x2 or x4) */
|
|
gpio_set_level(GPIO_USBC_DP_POLARITY, polarity);
|
|
gpio_set_level(GPIO_USBC_DP_MODE_L, 0);
|
|
}
|
|
/* switch on superspeed lanes */
|
|
gpio_set_level(GPIO_USBC_SS_EN_L, 0);
|
|
}
|
|
|
|
int board_get_usb_mux(int port, const char **dp_str, const char **usb_str)
|
|
{
|
|
int has_ss = !gpio_get_level(GPIO_USBC_SS_EN_L);
|
|
int has_usb = !gpio_get_level(GPIO_USBC_SS1_USB_MODE_L) ||
|
|
!gpio_get_level(GPIO_USBC_SS2_USB_MODE_L);
|
|
int has_dp = !gpio_get_level(GPIO_USBC_DP_MODE_L);
|
|
|
|
if (has_dp)
|
|
*dp_str = gpio_get_level(GPIO_USBC_DP_POLARITY) ? "DP2" : "DP1";
|
|
else
|
|
*dp_str = NULL;
|
|
|
|
if (has_usb)
|
|
*usb_str = gpio_get_level(GPIO_USBC_SS1_USB_MODE_L) ?
|
|
"USB2" : "USB1";
|
|
else
|
|
*usb_str = NULL;
|
|
|
|
return has_ss;
|
|
}
|
|
|
|
/**
|
|
* Discharge battery when on AC power for factory test.
|
|
*/
|
|
int board_discharge_on_ac(int enable)
|
|
{
|
|
return charger_discharge_on_ac(enable);
|
|
}
|
|
|
|
int extpower_is_present(void)
|
|
{
|
|
return gpio_get_level(GPIO_CHGR_ACOK);
|
|
}
|
|
|
|
/*
|
|
* Disconnect the USB lines from the AP, this enables manual control of the
|
|
* Pericom polarity switch and disconnects the USB 2.0 lines
|
|
*/
|
|
void ccd_board_connect(void)
|
|
{
|
|
pi3usb9281_set_pins(0, 0x00);
|
|
pi3usb9281_set_switch_manual(0, 0);
|
|
}
|
|
|
|
/*
|
|
* Reconnect the USB lines to the AP re-enabling automatic switching
|
|
*/
|
|
void ccd_board_disconnect(void)
|
|
{
|
|
pi3usb9281_set_switch_manual(0, 1);
|
|
}
|
|
|
|
void usb_board_connect(void)
|
|
{
|
|
/*
|
|
* TODO(robotboy): Enable DP pullup for Proto 3, Proto 2 doesn't have
|
|
* the DP pullup, so case closed debug will only work on a Proto 2 if
|
|
* the board is reworked, and this function is updated.
|
|
*/
|
|
}
|
|
|
|
void usb_board_disconnect(void)
|
|
{
|
|
/* TODO(robotboy): Disable DP pullup for Proto 3 */
|
|
}
|