-
Notifications
You must be signed in to change notification settings - Fork 7.3k
driver: adc: add adc driver for rts5912 #86753
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
driver: adc: add adc driver for rts5912 #86753
Conversation
Hello @dylanHsieh4963, and thank you very much for your first pull request to the Zephyr project! |
soc/realtek/ec/rts5912/reg/reg_adc.h
Outdated
#define ADC_CTRL_EN_Pos (0U) | ||
#define ADC_CTRL_EN_Msk BIT(ADC_CTRL_EN_Pos) |
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.
The _Msk
suffix implies that this field is multiple bits. You can simplify by dropping the _Msk
suffix. The _Pos
helper macro makes this harder to read so I recommend deleting it. Do this for all the macros define for the ADC.
#define ADC_CTRL_EN_Pos (0U) | |
#define ADC_CTRL_EN_Msk BIT(ADC_CTRL_EN_Pos) | |
#define ADC_CTRL_EN BIT(0) |
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.
Fixed
drivers/adc/adc_realtek_rts5912.c
Outdated
ADC_CONTEXT_INIT_SYNC(adc_rts5912_dev_data_0, ctx), | ||
}; | ||
|
||
DEVICE_DT_INST_DEFINE(0, adc_rts5912_init, NULL, &adc_rts5912_dev_data_0, &adc_rts5912_dev_cfg_0, |
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.
Device drivers should generally support multiple instances. If the driver is limited to a single instance, it needs a BUILD_ASSERT() to verify only one instance is enabled.
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.
Modify to support multiple instances, thanks
drivers/adc/adc_realtek_rts5912.c
Outdated
static struct adc_rts5912_config adc_rts5912_dev_cfg_0 = {.regs = (ADC_Type *)(DT_INST_REG_ADDR(0)), | ||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0), | ||
DEV_CONFIG_CLK_DEV_INIT(0)}; |
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.
The doesn't match the coding-style use for braces. Please run clang-format on the file.
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.
Fixed.
dts/arm/realtek/ec/rts5912.dtsi
Outdated
compatible = "realtek,rts5912-adc"; | ||
reg = <0x4000fe00 0x38>; | ||
clocks = <&sccon RTS5912_SCCON_ADC ADC0_CLKPWR>; | ||
clock-names = "adc"; |
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 there is only one clock, you can delete the clock-names
property,
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.
Fixed.
drivers/adc/adc_realtek_rts5912.c
Outdated
#define DEV_CONFIG_CLK_DEV_INIT(n) \ | ||
.clk_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \ | ||
.sccon_cfg = { \ | ||
.clk_grp = DT_INST_CLOCKS_CELL_BY_NAME(n, adc, clk_grp), \ |
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 can use DT_INST_CLOCKS_CELL()
here instead. It's not needed to use the clocks-name
property when there is only one clock.
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.
Fixed.
drivers/adc/adc_realtek_rts5912.c
Outdated
return ret; | ||
} | ||
|
||
#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.
Fixed.
You also need to add the ADC driver to one of the board files so the driver gets compiled by the tests. |
d8fbca5
to
94aff50
Compare
drivers/adc/adc_realtek_rts5912.c
Outdated
#define RTS5912_ADC_ENABLE_TIMEOUT 100 | ||
|
||
struct adc_rts5912_config { | ||
ADC_Type *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.
Your register definitions need to be volatile.
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.
Fixed
soc/realtek/ec/rts5912/reg/reg_adc.h
Outdated
#ifndef ZEPHYR_SOC_REALTEK_RTS5912_REG_ADC_H | ||
#define ZEPHYR_SOC_REALTEK_RTS5912_REG_ADC_H | ||
|
||
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 use typedefs. Use struct adc_regs
instead. Also, declare the whole structure as volatile, not just the individual fields.
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.
Fixed
soc/realtek/ec/rts5912/reg/reg_adc.h
Outdated
#define ADC_CTRL_START_Pos (1U) | ||
#define ADC_CTRL_START_Msk BIT(ADC_CTRL_START_Pos) |
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.
Simplify all the single-bit definitions.
#define ADC_CTRL_START_Pos (1U) | |
#define ADC_CTRL_START_Msk BIT(ADC_CTRL_START_Pos) | |
#define ADC_CTRL_START BIT(1) |
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.
Fixed
5ef1685
to
035a300
Compare
soc/realtek/ec/rts5912/reg/reg_adc.h
Outdated
uint32_t CTRL; | ||
uint32_t CHCTRL; | ||
uint32_t STS; | ||
uint32_t CHDATA[12]; | ||
uint32_t COEFFA; | ||
uint32_t COEFFB; |
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 for code and variables, so all these should be lowercase.
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.
Fixed
d62da9d
to
28d2933
Compare
@anangl and @JasonLin-RealTek please give this a review. |
@dylanHsieh4963 this needs to be rebased |
Hi @keith-zephyr, |
Add adc driver for Realtek rts5912. Signed-off-by: Dylan Hsieh <[email protected]>
28d2933
to
75ec1bf
Compare
Add adc driver for Realtek rts5912.