1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/* 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.
*/
/* DragonEgg board-specific configuration */
#include "common.h"
#include "charger.h"
#include "console.h"
#include "driver/ppc/sn5s330.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "intc.h"
#include "lid_switch.h"
#include "power.h"
#include "power_button.h"
#include "pwm_chip.h"
#include "spi.h"
#include "switch.h"
#include "system.h"
#include "uart.h"
#include "util.h"
static void ppc_interrupt(enum gpio_signal signal)
{
if (signal == GPIO_USB_C0_TCPPC_INT_L)
sn5s330_interrupt(0);
}
#include "gpio_list.h" /* Must come after other header files. */
/******************************************************************************/
/* SPI devices */
/* TODO(b/110880394): Fill out correctly (SPI FLASH) */
const struct spi_device_t spi_devices[] = {
};
const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices);
/******************************************************************************/
/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */
const struct pwm_t pwm_channels[] = {
[PWM_CH_KBLIGHT] = { .channel = 0, .flags = 0, .freq_hz = 100 },
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
/* GPIO to enable/disable the USB Type-A port. */
const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
GPIO_EN_USB_A_5V,
};
void board_overcurrent_event(int port)
{
if (port == 0) {
/* TODO(b/111281797): When does this get set high again? */
gpio_set_level(GPIO_USB_OC_ODL, 0);
cprints(CC_USBPD, "p%d: overcurrent!", port);
}
}
static void board_disable_learn_mode(void)
{
/* Disable learn mode after checking to make sure AC is still present */
if (extpower_is_present())
charger_discharge_on_ac(0);
}
DECLARE_DEFERRED(board_disable_learn_mode);
static void board_extpower(void)
{
/*
* For the bq25710 charger, we need the switching converter to remain
* disabled until ~130 msec from when VBUS present to allow the
* converter to be biased properly. Otherwise, there will be a reverse
* buck/boost until the converter is biased. The recommendation is to
* exit learn mode 200 msec after external charger is connected.
*
* TODO(b/112372451): When there are updated versions of the bq25710,
* this set of changes can be removed.
*/
if (extpower_is_present()) {
hook_call_deferred(&board_disable_learn_mode_data, 200 * MSEC);
} else {
/* Enable charger learn mode */
charger_discharge_on_ac(1);
/* Cancel any pending call to disable learn mode */
hook_call_deferred(&board_disable_learn_mode_data, -1);
}
}
DECLARE_HOOK(HOOK_AC_CHANGE, board_extpower, HOOK_PRIO_DEFAULT);
/* Initialize board. */
static void board_init(void)
{
/*
* On EC reboot, need to always set battery learn mode to the correct
* state based on presence of AC.
*/
board_extpower();
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
|