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
|
/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <zephyr/devicetree.h>
#include <zephyr/logging/log.h>
#include <ap_power/ap_power.h>
#include <chipset.h>
#include <soc_espi.h>
LOG_MODULE_REGISTER(ec_chip_it8xxx2_espi, CONFIG_ESPI_LOG_LEVEL);
/*
* When eSPI CS# is held low, it prevents IT8xxx2 from entering deep doze.
* To allow deep doze and save power, disable the eSPI inputs while the AP is
* in G3.
*/
static const struct device *const espi_device =
DEVICE_DT_GET(DT_NODELABEL(espi0));
static void espi_enable_callback(struct ap_power_ev_callback *cb,
struct ap_power_ev_data data)
{
switch (data.event) {
case AP_POWER_INITIALIZED:
/* When AP power state becomes known, sync eSPI enable */
if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) {
LOG_DBG("AP off; disabling eSPI");
espi_it8xxx2_enable_pad_ctrl(espi_device, false);
}
break;
case AP_POWER_PRE_INIT:
case AP_POWER_HARD_OFF: {
bool enable = data.event == AP_POWER_PRE_INIT;
LOG_DBG("%sabling eSPI in response to AP power event",
enable ? "en" : "dis");
espi_it8xxx2_enable_pad_ctrl(espi_device, enable);
break;
}
default:
__ASSERT(false, "%s: unhandled event: %d", __func__,
data.event);
break;
}
}
static int init_espi_enable_callback(void)
{
static struct ap_power_ev_callback cb;
if (!device_is_ready(espi_device))
k_oops();
ap_power_ev_init_callback(&cb, espi_enable_callback,
AP_POWER_INITIALIZED | AP_POWER_PRE_INIT |
AP_POWER_HARD_OFF);
ap_power_ev_add_callback(&cb);
return 0;
}
/* Should run before power sequencing init so INITIALIZED callback can fire */
SYS_INIT(init_espi_enable_callback, APPLICATION, 0);
|