mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 01:21:49 +00:00
Previously the version string was special cased in the USB stack because the build system prevented the inclusion of ec_version.h in any file other than common/version.c. This lead to common/version.c being the only place that the USB version string could be computed and thus the special case of filling in the version string descriptor at run time. This made the USB stack more complex, and lead to the common/version.c file including usb.h, which is actually STM32 specific. Now, the portion of ec_version.h that is deterministic is only updated when something in the tree actually changes (by way of a conditional in the makefile), and ec_version.h no longer has to depend on all object files (other than the special version.o). This allows anyone to include ec_version.h as needed. In particular, each board that wants to define a USB version string can directly include ec_version.h and do so. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j touch files and verify rebuilds happen correctly Change-Id: Ic84d0b9da90f82ebb4630fb550ec841071e25a49 Reviewed-on: https://chromium-review.googlesource.com/227211 Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
185 lines
5.2 KiB
C
185 lines
5.2 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.
|
|
*/
|
|
/* Dingdong dongle configuration */
|
|
|
|
#include "adc.h"
|
|
#include "adc_chip.h"
|
|
#include "common.h"
|
|
#include "ec_version.h"
|
|
#include "gpio.h"
|
|
#include "hooks.h"
|
|
#include "registers.h"
|
|
#include "usb.h"
|
|
#include "usb_bb.h"
|
|
#include "usb_pd.h"
|
|
#include "task.h"
|
|
#include "timer.h"
|
|
#include "util.h"
|
|
|
|
static volatile uint64_t hpd_prev_ts;
|
|
static volatile int hpd_prev_level;
|
|
|
|
void hpd_event(enum gpio_signal signal);
|
|
#include "gpio_list.h"
|
|
|
|
/**
|
|
* Hotplug detect deferred task
|
|
*
|
|
* Called after level change on hpd GPIO to evaluate (and debounce) what event
|
|
* has occurred. There are 3 events that occur on HPD:
|
|
* 1. low : downstream display sink is deattached
|
|
* 2. high : downstream display sink is attached
|
|
* 3. irq : downstream display sink signalling an interrupt.
|
|
*
|
|
* The debounce times for these various events are:
|
|
* 100MSEC : min pulse width of level value.
|
|
* 2MSEC : min pulse width of IRQ low pulse. Max is level debounce min.
|
|
*
|
|
* lvl(n-2) lvl(n-1) lvl prev_delta now_delta event
|
|
* ----------------------------------------------------
|
|
* 1 0 1 <2ms n/a low glitch (ignore)
|
|
* 1 0 1 >2ms <100ms irq
|
|
* x 0 1 n/a >100ms high
|
|
* 0 1 0 <100ms n/a high glitch (ignore)
|
|
* x 1 0 n/a >100ms low
|
|
*/
|
|
|
|
void hpd_irq_deferred(void)
|
|
{
|
|
pd_send_hpd(0, hpd_irq);
|
|
}
|
|
DECLARE_DEFERRED(hpd_irq_deferred);
|
|
|
|
void hpd_lvl_deferred(void)
|
|
{
|
|
int level = gpio_get_level(GPIO_DP_HPD);
|
|
|
|
if (level != hpd_prev_level)
|
|
/* It's a glitch while in deferred or canceled action */
|
|
return;
|
|
|
|
pd_send_hpd(0, (level) ? hpd_high : hpd_low);
|
|
}
|
|
DECLARE_DEFERRED(hpd_lvl_deferred);
|
|
|
|
void hpd_event(enum gpio_signal signal)
|
|
{
|
|
timestamp_t now = get_time();
|
|
int level = gpio_get_level(signal);
|
|
uint64_t cur_delta = now.val - hpd_prev_ts;
|
|
|
|
/* store current time */
|
|
hpd_prev_ts = now.val;
|
|
|
|
/* All previous hpd level events need to be re-triggered */
|
|
hook_call_deferred(hpd_lvl_deferred, -1);
|
|
|
|
/* It's a glitch. Previous time moves but level is the same. */
|
|
if (cur_delta < HPD_DEBOUNCE_IRQ)
|
|
return;
|
|
|
|
if ((!hpd_prev_level && level) && (cur_delta < HPD_DEBOUNCE_LVL))
|
|
/* It's an irq */
|
|
hook_call_deferred(hpd_irq_deferred, 0);
|
|
else if (cur_delta >= HPD_DEBOUNCE_LVL)
|
|
hook_call_deferred(hpd_lvl_deferred, HPD_DEBOUNCE_LVL);
|
|
|
|
hpd_prev_level = level;
|
|
}
|
|
|
|
/* Initialize board. */
|
|
void board_config_pre_init(void)
|
|
{
|
|
/* enable SYSCFG clock */
|
|
STM32_RCC_APB2ENR |= 1 << 0;
|
|
/* Remap USART DMA to match the USART driver */
|
|
STM32_SYSCFG_CFGR1 |= (1 << 9) | (1 << 10);/* Remap USART1 RX/TX DMA */
|
|
}
|
|
|
|
/* Initialize board. */
|
|
static void board_init(void)
|
|
{
|
|
timestamp_t now = get_time();
|
|
hpd_prev_level = gpio_get_level(GPIO_DP_HPD);
|
|
hpd_prev_ts = now.val;
|
|
gpio_enable_interrupt(GPIO_DP_HPD);
|
|
}
|
|
|
|
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
|
|
|
|
/* ADC channels */
|
|
const struct adc_t adc_channels[] = {
|
|
/* USB PD CC lines sensing. Converted to mV (3300mV/4096). */
|
|
[ADC_CH_CC1_PD] = {"USB_C_CC1_PD", 3300, 4096, 0, STM32_AIN(1)},
|
|
};
|
|
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
|
|
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("Dingdong"),
|
|
[USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
|
|
[USB_STR_BB_URL] = USB_STRING_DESC(USB_GOOGLE_TYPEC_URL),
|
|
};
|
|
BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
|
|
|
|
/**
|
|
* USB configuration
|
|
* Any type-C device with alternate mode capabilities must have the following
|
|
* set of descriptors.
|
|
*
|
|
* 1. Standard Device
|
|
* 2. BOS
|
|
* 2a. Container ID
|
|
* 2b. Billboard Caps
|
|
*/
|
|
struct my_bos {
|
|
struct usb_bos_hdr_descriptor bos;
|
|
struct usb_contid_caps_descriptor contid_caps;
|
|
struct usb_bb_caps_base_descriptor bb_caps;
|
|
struct usb_bb_caps_svid_descriptor bb_caps_svids[1];
|
|
};
|
|
|
|
static struct my_bos bos_desc = {
|
|
.bos = {
|
|
.bLength = USB_DT_BOS_SIZE,
|
|
.bDescriptorType = USB_DT_BOS,
|
|
.wTotalLength = (USB_DT_BOS_SIZE + USB_DT_CONTID_SIZE +
|
|
USB_BB_CAPS_BASE_SIZE +
|
|
USB_BB_CAPS_SVID_SIZE * 1),
|
|
.bNumDeviceCaps = 2, /* contid + bb_caps */
|
|
},
|
|
.contid_caps = {
|
|
.bLength = USB_DT_CONTID_SIZE,
|
|
.bDescriptorType = USB_DT_DEVICE_CAPABILITY,
|
|
.bDevCapabilityType = USB_DC_DTYPE_CONTID,
|
|
.bReserved = 0,
|
|
.ContainerID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
},
|
|
.bb_caps = {
|
|
.bLength = (USB_BB_CAPS_BASE_SIZE + USB_BB_CAPS_SVID_SIZE * 1),
|
|
.bDescriptorType = USB_DT_DEVICE_CAPABILITY,
|
|
.bDevCapabilityType = USB_DC_DTYPE_BILLBOARD,
|
|
.iAdditionalInfoURL = USB_STR_BB_URL,
|
|
.bNumberOfAlternateModes = 1,
|
|
.bPreferredAlternateMode = 1,
|
|
.VconnPower = 0,
|
|
.bmConfigured = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
|
.bReserved = 0,
|
|
},
|
|
.bb_caps_svids = {
|
|
{
|
|
.wSVID = USB_SID_DISPLAYPORT,
|
|
.bAlternateMode = 1,
|
|
.iAlternateModeString = USB_STR_BB_URL, /* TODO(crosbug.com/p/32687) */
|
|
},
|
|
},
|
|
};
|
|
|
|
const struct bos_context bos_ctx = {
|
|
.descp = (void *)&bos_desc,
|
|
.size = sizeof(struct my_bos),
|
|
};
|