coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
pwm.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <soc/addressmap.h>
5 #include <soc/grf.h>
6 #include <soc/soc.h>
7 #include <soc/pwm.h>
8 #include <soc/clock.h>
9 #include <timer.h>
10 
11 struct pwm_ctl {
16 };
17 
18 struct rk_pwm_regs {
19  struct pwm_ctl pwm[4];
22 };
23 check_member(rk_pwm_regs, int_en, 0x44);
24 
25 #define RK_PWM_DISABLE (0 << 0)
26 #define RK_PWM_ENABLE (1 << 0)
27 
28 #define PWM_ONE_SHOT (0 << 1)
29 #define PWM_CONTINUOUS (1 << 1)
30 #define RK_PWM_CAPTURE (1 << 2)
31 
32 #define PWM_DUTY_POSTIVE (1 << 3)
33 #define PWM_DUTY_NEGATIVE (0 << 3)
34 
35 #define PWM_INACTIVE_POSTIVE (1 << 4)
36 #define PWM_INACTIVE_NEGATIVE (0 << 4)
37 
38 #define PWM_OUTPUT_LEFT (0 << 5)
39 #define PWM_OUTPUT_CENTER (1 << 5)
40 
41 #define PWM_LP_ENABLE (1 << 8)
42 #define PWM_LP_DISABLE (0 << 8)
43 
44 #define PWM_SEL_SCALE_CLK (1 << 9)
45 #define PWM_SEL_SRC_CLK (0 << 9)
46 
47 struct rk_pwm_regs *rk_pwm = (void *)RK_PWM_BASE;
48 
49 void pwm_init(u32 id, u32 period_ns, u32 duty_ns)
50 {
51  unsigned long period, duty;
52 
53 #if CONFIG(SOC_ROCKCHIP_RK3288)
54  /*use rk pwm*/
56 #endif
57 
61 
62  period = (PWM_CLOCK_HZ / 1000) * period_ns / USECS_PER_SEC;
63  duty = (PWM_CLOCK_HZ / 1000) * duty_ns / USECS_PER_SEC;
64 
65  write32(&rk_pwm->pwm[id].pwm_period_hpr, period);
66  write32(&rk_pwm->pwm[id].pwm_duty_lpr, duty);
68 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
#define setbits32(addr, set)
Definition: mmio.h:21
#define USECS_PER_SEC
Definition: timer.h:8
#define PWM_CONTINUOUS
Definition: pwm.c:29
#define PWM_OUTPUT_LEFT
Definition: pwm.c:38
check_member(rk_pwm_regs, int_en, 0x44)
#define RK_PWM_DISABLE
Definition: pwm.c:25
#define RK_PWM_ENABLE
Definition: pwm.c:26
#define PWM_DUTY_POSTIVE
Definition: pwm.c:32
#define PWM_INACTIVE_POSTIVE
Definition: pwm.c:35
#define PWM_SEL_SRC_CLK
Definition: pwm.c:45
struct rk_pwm_regs * rk_pwm
Definition: pwm.c:47
#define PWM_LP_DISABLE
Definition: pwm.c:42
void pwm_init(u32 id, u32 period_ns, u32 duty_ns)
Definition: pwm.c:49
static struct rk3288_grf_regs *const rk3288_grf
Definition: grf.h:181
#define RK_SETBITS(set)
Definition: soc.h:9
#define RK_PWM_BASE
Definition: addressmap.h:44
#define PWM_CLOCK_HZ
Definition: clock.h:30
uint32_t u32
Definition: stdint.h:51
Definition: pwm.c:11
u32 pwm_ctrl
Definition: pwm.c:15
u32 pwm_duty_lpr
Definition: pwm.c:14
u32 pwm_period_hpr
Definition: pwm.c:13
u32 pwm_cnt
Definition: pwm.c:12
u32 soc_con2
Definition: grf.h:106
struct pwm_ctl pwm[4]
Definition: pwm.c:19
u32 intsts
Definition: pwm.c:20
u32 int_en
Definition: pwm.c:21