2 * This file is part of the coreboot project.
4 * Copyright 2014 Rockchip Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <device/mmio.h>
17 #include <soc/addressmap.h>
21 #include <soc/clock.h>
32 struct pwm_ctl pwm
[4];
36 check_member(rk_pwm_regs
, int_en
, 0x44);
38 #define RK_PWM_DISABLE (0 << 0)
39 #define RK_PWM_ENABLE (1 << 0)
42 #define PWM_ONE_SHOT (0 << 1)
43 #define PWM_CONTINUOUS (1 << 1)
44 #define RK_PWM_CAPTURE (1 << 2)
46 #define PWM_DUTY_POSTIVE (1 << 3)
47 #define PWM_DUTY_NEGATIVE (0 << 3)
49 #define PWM_INACTIVE_POSTIVE (1 << 4)
50 #define PWM_INACTIVE_NEGATIVE (0 << 4)
52 #define PWM_OUTPUT_LEFT (0 << 5)
53 #define PWM_OUTPUT_CENTER (1 << 5)
55 #define PWM_LP_ENABLE (1 << 8)
56 #define PWM_LP_DISABLE (0 << 8)
58 #define PWM_SEL_SCALE_CLK (1 << 9)
59 #define PWM_SEL_SRC_CLK (0 << 9)
61 struct rk_pwm_regs
*rk_pwm
= (void *)RK_PWM_BASE
;
63 void pwm_init(u32 id
, u32 period_ns
, u32 duty_ns
)
65 unsigned long period
, duty
;
67 #if CONFIG(SOC_ROCKCHIP_RK3288)
69 write32(&rk3288_grf
->soc_con2
, RK_SETBITS(1 << 0));
72 write32(&rk_pwm
->pwm
[id
].pwm_ctrl
, PWM_SEL_SRC_CLK
|
73 PWM_OUTPUT_LEFT
| PWM_LP_DISABLE
| PWM_CONTINUOUS
|
74 PWM_DUTY_POSTIVE
| PWM_INACTIVE_POSTIVE
| RK_PWM_DISABLE
);
76 period
= (PWM_CLOCK_HZ
/ 1000) * period_ns
/ USECS_PER_SEC
;
77 duty
= (PWM_CLOCK_HZ
/ 1000) * duty_ns
/ USECS_PER_SEC
;
79 write32(&rk_pwm
->pwm
[id
].pwm_period_hpr
, period
);
80 write32(&rk_pwm
->pwm
[id
].pwm_duty_lpr
, duty
);
81 setbits32(&rk_pwm
->pwm
[id
].pwm_ctrl
, RK_PWM_ENABLE
);