-
Notifications
You must be signed in to change notification settings - Fork 7.3k
drivers: pwm: rts5912: port pwm driver on Zephyr #86275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
drivers: pwm: rts5912: port pwm driver on Zephyr #86275
Conversation
3aaba9f
to
f3cc34c
Compare
dts/arm/realtek/ec/rts5912.dtsi
Outdated
pwm0: pwm@4000f000 { | ||
compatible = "realtek,rts5912-pwm"; | ||
clocks = <&sccon RTS5912_SCCON_PERIPH_GRP0 PERIPH_GRP0_PWM0_CLKPWR>; | ||
clock-names = "pwm"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking comment: you only have one clock specifier, so you don't need to assign a clock-names
property. You can use DT_INST_CLOCKS_CELL
as a shorthand for DT_INST_CLOCKS_CELL_BY_IDX(inst, 0, cell)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done.
soc/realtek/ec/rts5912/reg/reg_pwm.h
Outdated
struct { | ||
uint32_t: 28; | ||
volatile uint32_t CLKSRC: 1; | ||
volatile uint32_t INVT: 1; | ||
volatile uint32_t RST: 1; | ||
volatile uint32_t EN: 1; | ||
} CTRL_b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have also defined macros to access these bits below. You should pick one style here - bit fields or macros.
For single bits, I find C macros for the bit names easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done.
soc/realtek/ec/rts5912/reg/reg_pwm.h
Outdated
#define PWM_CTRL_CLKSRC_Pos (28UL) | ||
#define PWM_CTRL_CLKSRC_Msk BIT(28) | ||
#define PWM_CTRL_INVT_Pos (29UL) | ||
#define PWM_CTRL_INVT_Msk BIT(29) | ||
#define PWM_CTRL_RST_Pos (30UL) | ||
#define PWM_CTRL_RST_Msk BIT(30) | ||
#define PWM_CTRL_EN_Pos (31UL) | ||
#define PWM_CTRL_EN_Msk BIT(31) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you keep these macros - delete the _Pos
macros as they aren't used. You can also drop the _Msk'
suffix for single-bit fields.
#define PWM_CTRL_CLKSRC_Pos (28UL) | |
#define PWM_CTRL_CLKSRC_Msk BIT(28) | |
#define PWM_CTRL_INVT_Pos (29UL) | |
#define PWM_CTRL_INVT_Msk BIT(29) | |
#define PWM_CTRL_RST_Pos (30UL) | |
#define PWM_CTRL_RST_Msk BIT(30) | |
#define PWM_CTRL_EN_Pos (31UL) | |
#define PWM_CTRL_EN_Msk BIT(31) | |
#define PWM_CTRL_CLKSR BIT(28) | |
#define PWM_CTRL_INVT BIT(29) | |
#define PWM_CTRL_RST BIT(30) | |
#define PWM_CTRL_EN BIT(31) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done.
f3cc34c
to
7d94728
Compare
drivers/pwm/pwm_realtek_rts5912.c
Outdated
struct rts5912_sccon_subsys sccon; | ||
|
||
int rc = 0; | ||
#if defined(CONFIG_PINCTRL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use #ifdef CONFIG_PINCTRL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done.
drivers/pwm/pwm_realtek_rts5912.c
Outdated
return rc; | ||
} | ||
#endif | ||
#if defined(CONFIG_CLOCK_CONTROL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if defined(CONFIG_CLOCK_CONTROL) | |
#ifdef CONFIG_CLOCK_CONTROL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done.
drivers/pwm/pwm_realtek_rts5912.c
Outdated
.pwm_clk_grp = DT_INST_CLOCKS_CELL(inst, 0, clk_grp), \ | ||
.pwm_clk_idx = DT_INST_CLOCKS_CELL(inst, 0, clk_idx), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.pwm_clk_grp = DT_INST_CLOCKS_CELL(inst, 0, clk_grp), \ | |
.pwm_clk_idx = DT_INST_CLOCKS_CELL(inst, 0, clk_idx), \ | |
.pwm_clk_grp = DT_INST_CLOCKS_CELL(inst, clk_grp), \ | |
.pwm_clk_idx = DT_INST_CLOCKS_CELL(inst, clk_idx), \ |
Wrong number of arguments passed to DT_INST_CLOCKS_CELL
. Does the rts5912 EVB support PWM? Can you add a commit to the PR to enable PWM on the EVB? That will help catch compile errors like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done.
54ba42a
to
5d04790
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to this to the pwm_api test by adding an entry for your board.
soc/realtek/ec/rts5912/reg/reg_pwm.h
Outdated
* @brief PWM Controller (PWM) | ||
*/ | ||
|
||
typedef struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't declare new typedefs. https://www.kernel.org/doc/html/v4.10/process/coding-style.html#typedefs
Use struct pwm
or struct pwm_regs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
drivers/pwm/pwm_realtek_rts5912.c
Outdated
#define PWM_CYCLE_PER_SEC MHZ(50) | ||
|
||
struct pwm_rts5912_config { | ||
uint32_t pwm_base; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the struct pwm_regs
type directly to avoid casting every time you use this. This also needs to be declared volatile to prevent compiler reorderng.
uint32_t pwm_base; | |
volatile struct pwm_regs *pwm_regs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
a63db21
to
8fea7df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add this to the tests/drivers/build_all/pwm
test. You can add a rts5912_evb_defconfig.overlay
file to the board directory and enable one of the "pwm" drivers.
soc/realtek/ec/rts5912/reg/reg_pwm.h
Outdated
uint32_t DUTY; | ||
uint32_t DIV; | ||
uint32_t CTRL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use snake case C code. https://docs.zephyrproject.org/latest/contribute/style/code.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
d2a3734
to
d372d12
Compare
}; | ||
}; | ||
|
||
&pwm0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should be called rts5912_evb.overlay
- drop the the "defconfig" portion of the name.
You also need to add a testcase entry for the RTS5912 so that the rts5912_evb board and PWM driver are built.
You can verify this locally using ./scripts/twister -ivc -T tests/drivers/build_all/pwm/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
4fc4d5c
to
42cfb15
Compare
@anangl please take a look. |
#include <zephyr/drivers/pinctrl.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zephyr/drivers/clock_control.h> | ||
#include <zephyr/drivers/clock_control/clock_control_rts5912.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
Add PWM driver support for Realtek RTS5912 Signed-off-by: Titan Chen <[email protected]>
42cfb15
to
81f731b
Compare
Add PWM driver support for Realtek RTS5912