-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcp.c
67 lines (51 loc) · 1.37 KB
/
cp.c
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
// SPDX-License-Identifier: BSD-2-Clause
/*
* Copyright (c) 2025 Kontron Europe GmbH
*
* The charge pump uses TIMG0 with a frequency of 100kHz and a duty cycle of 50%.
*/
#include "cp.h"
#include "misc.h"
#define TIMG0_BASE 0x40084000
#define TIM_PWREN (TIMG0_BASE + 0x0800)
#define PWREN_KEY 0x26000000
#define PWREN_ENABLE BIT(0)
#define TIM_CLKSEL (TIMG0_BASE + 0x1008)
#define CLKSEL_MFCLK BIT(2)
#define TIM_CCPD (TIMG0_BASE + 0x1100)
#define CCPD_C0CCP0_OUTPUT BIT(0)
#define TIM_CTRCTL (TIMG0_BASE + 0x1804)
#define CTRCTL_EN BIT(0)
#define CTRCTL_REPEAT (1 << 1)
#define TIM_LOAD (TIMG0_BASE + 0x1808)
#define MCLK_FREQ 4000000
#ifndef CFG_CP_FREQ
#define CFG_CP_FREQ 100000
#endif
#define TIM_CCACT0 (TIMG0_BASE + 0x1870)
#define CCACT_ZACT_TOGGLE (3 << 0)
void cp_init(void)
{
iow(TIM_PWREN, PWREN_KEY | PWREN_ENABLE);
/* use 4 MHz mid frequency clock */
iow(TIM_CLKSEL, CLKSEL_MFCLK);
/*
* set frequency, because we just toggle the output on zero condition we
* have to be twice as fast as the configured frequency
*/
iow(TIM_LOAD, MCLK_FREQ / CFG_CP_FREQ / 2);
/* toggle output on zero */
iow(TIM_CCACT0, CCACT_ZACT_TOGGLE);
/* enable timer */
iow(TIM_CTRCTL, CTRCTL_REPEAT | CTRCTL_EN);
}
void cp_enable(void)
{
/* enable output */
iow(TIM_CCPD, CCPD_C0CCP0_OUTPUT);
}
void cp_disable(void)
{
/* disable output */
iow(TIM_CCPD, 0);
}