summaryrefslogtreecommitdiff
path: root/zephyr/program/skyrim/crystaldrift/src/alt_charger.c
blob: 83e827ca5f6b57dd971a7ef63f2f7fa0fdc13772 (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
/* 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 "charger_chips.h"
#include "common.h"
#include "cros_board_info.h"
#include "cros_cbi.h"
#include "hooks.h"

#include <zephyr/devicetree.h>
#include <zephyr/logging/log.h>

#ifdef CONFIG_ZTEST
#undef CHG_ENABLE_ALTERNATE
void chg_enable_alternate_test(int port);
#define CHG_ENABLE_ALTERNATE(x) chg_enable_alternate_test(x)
#endif /* CONFIG_ZTEST */

LOG_MODULE_DECLARE(crystaldrift, CONFIG_SKYRIM_LOG_LEVEL);

test_export_static void alt_charger_init(void)
{
	int ret;
	uint32_t val;

	ret = cros_cbi_get_fw_config(FW_CHARGER, &val);
	if (ret != 0) {
		LOG_ERR("Error retrieving CBI FW_CONFIG field %d", FW_CHARGER);
		return;
	}

	if (val == FW_CHARGER_ISL9538)
		CHG_ENABLE_ALTERNATE(0);
}
DECLARE_HOOK(HOOK_INIT, alt_charger_init, HOOK_PRIO_POST_FIRST);