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
|
/* 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/drivers/emul.h>
#include <zephyr/fff.h>
#include <zephyr/ztest.h>
#include "charger.h"
#include "driver/charger/rt9490.h"
#include "emul/emul_rt9490.h"
#include "hooks.h"
#include "i2c.h"
#include "system.h"
FAKE_VALUE_FUNC(int, board_get_version);
const struct emul *emul = EMUL_DT_GET(DT_NODELABEL(charger));
static bool ibus_adc_workaround_called(void)
{
return rt9490_emul_peek_reg(emul, 0x52) == 0xC4;
}
static bool i2c_speed_workaround_called(void)
{
return rt9490_emul_peek_reg(emul, 0x71) == 0x22;
}
static bool eoc_deglitch_workaround_called(void)
{
return !(rt9490_emul_peek_reg(emul, RT9490_REG_ADD_CTRL0) &
RT9490_TD_EOC);
}
static bool disable_safety_timer_called(void)
{
return rt9490_emul_peek_reg(emul, RT9490_REG_SAFETY_TMR_CTRL) ==
(RT9490_EN_TRICHG_TMR | RT9490_EN_PRECHG_TMR |
RT9490_EN_FASTCHG_TMR);
}
ZTEST(charger_workaround, test_board_version_0)
{
board_get_version_fake.return_val = 0;
hook_notify(HOOK_INIT);
zassert_true(ibus_adc_workaround_called(), NULL);
zassert_true(i2c_speed_workaround_called(), NULL);
zassert_false(eoc_deglitch_workaround_called(), NULL);
zassert_true(disable_safety_timer_called(), NULL);
}
ZTEST(charger_workaround, test_board_version_1)
{
board_get_version_fake.return_val = 1;
hook_notify(HOOK_INIT);
zassert_false(ibus_adc_workaround_called(), NULL);
zassert_true(i2c_speed_workaround_called(), NULL);
zassert_true(eoc_deglitch_workaround_called(), NULL);
zassert_true(disable_safety_timer_called(), NULL);
}
ZTEST(charger_workaround, test_board_version_2)
{
board_get_version_fake.return_val = 2;
hook_notify(HOOK_INIT);
zassert_false(ibus_adc_workaround_called(), NULL);
zassert_true(i2c_speed_workaround_called(), NULL);
zassert_false(eoc_deglitch_workaround_called(), NULL);
zassert_false(disable_safety_timer_called(), NULL);
}
ZTEST(charger_workaround, test_board_version_3)
{
board_get_version_fake.return_val = 3;
hook_notify(HOOK_INIT);
zassert_false(ibus_adc_workaround_called(), NULL);
zassert_false(i2c_speed_workaround_called(), NULL);
zassert_false(eoc_deglitch_workaround_called(), NULL);
zassert_false(disable_safety_timer_called(), NULL);
}
static void charge_workaround_before(void *fixture)
{
RESET_FAKE(board_get_version);
rt9490_emul_reset_regs(emul);
}
ZTEST_SUITE(charger_workaround, NULL, NULL, charge_workaround_before, NULL,
NULL);
|