blob: 786bb1bd3c8e585cf426a411c91a6329c64a60a8 (
plain)
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
|
/* 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/logging/log.h>
#include "battery.h"
#include "charger.h"
#include "console.h"
#include "driver/charger/sm5803.h"
#include "extpower.h"
#include "usb_pd.h"
#include "nissa_common.h"
LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL);
int extpower_is_present(void)
{
int port;
int rv;
bool acok;
for (port = 0; port < board_get_usb_pd_port_count(); port++) {
rv = sm5803_is_acok(port, &acok);
if ((rv == EC_SUCCESS) && acok)
return 1;
}
return 0;
}
/*
* Yaviks does not have a GPIO indicating whether extpower is present,
* so detect using the charger(s).
*/
__override void board_check_extpower(void)
{
static int last_extpower_present;
int extpower_present = extpower_is_present();
if (last_extpower_present ^ extpower_present)
extpower_handle_update(extpower_present);
last_extpower_present = extpower_present;
}
__override void board_hibernate(void)
{
/* Shut down the chargers */
if (board_get_usb_pd_port_count() == 2)
sm5803_hibernate(CHARGER_SECONDARY);
sm5803_hibernate(CHARGER_PRIMARY);
LOG_INF("Charger(s) hibernated");
cflush();
}
|