Skip to content

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

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

dylanHsieh4963
Copy link
Contributor

Add adc driver for Realtek rts5912.

@zephyrbot zephyrbot added platform: Realtek EC area: ADC Analog-to-Digital Converter (ADC) labels Mar 7, 2025
Copy link

github-actions bot commented Mar 7, 2025

Hello @dylanHsieh4963, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

Comment on lines 20 to 21
#define ADC_CTRL_EN_Pos (0U)
#define ADC_CTRL_EN_Msk BIT(ADC_CTRL_EN_Pos)
Copy link
Collaborator

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.

Suggested change
#define ADC_CTRL_EN_Pos (0U)
#define ADC_CTRL_EN_Msk BIT(ADC_CTRL_EN_Pos)
#define ADC_CTRL_EN BIT(0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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,
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Comment on lines 286 to 288
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)};
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

compatible = "realtek,rts5912-adc";
reg = <0x4000fe00 0x38>;
clocks = <&sccon RTS5912_SCCON_ADC ADC0_CLKPWR>;
clock-names = "adc";
Copy link
Collaborator

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,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

#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), \
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return ret;
}

#if defined(CONFIG_CLOCK_CONTROL)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(CONFIG_CLOCK_CONTROL)
#ifdef CONFIG_CLOCK_CONTROL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@keith-zephyr
Copy link
Collaborator

You also need to add the ADC driver to one of the board files so the driver gets compiled by the tests.

@dylanHsieh4963 dylanHsieh4963 force-pushed the rts5912_enable_adc branch 3 times, most recently from d8fbca5 to 94aff50 Compare March 14, 2025 07:51
#define RTS5912_ADC_ENABLE_TIMEOUT 100

struct adc_rts5912_config {
ADC_Type *regs;
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

#ifndef ZEPHYR_SOC_REALTEK_RTS5912_REG_ADC_H
#define ZEPHYR_SOC_REALTEK_RTS5912_REG_ADC_H

typedef struct {
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 21 to 22
#define ADC_CTRL_START_Pos (1U)
#define ADC_CTRL_START_Msk BIT(ADC_CTRL_START_Pos)
Copy link
Collaborator

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.

Suggested change
#define ADC_CTRL_START_Pos (1U)
#define ADC_CTRL_START_Msk BIT(ADC_CTRL_START_Pos)
#define ADC_CTRL_START BIT(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@dylanHsieh4963 dylanHsieh4963 force-pushed the rts5912_enable_adc branch 2 times, most recently from 5ef1685 to 035a300 Compare March 18, 2025 09:12
Comment on lines 11 to 16
uint32_t CTRL;
uint32_t CHCTRL;
uint32_t STS;
uint32_t CHDATA[12];
uint32_t COEFFA;
uint32_t COEFFB;
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@dylanHsieh4963 dylanHsieh4963 force-pushed the rts5912_enable_adc branch 3 times, most recently from d62da9d to 28d2933 Compare March 20, 2025 09:01
keith-zephyr
keith-zephyr previously approved these changes Mar 20, 2025
@keith-zephyr
Copy link
Collaborator

@anangl and @JasonLin-RealTek please give this a review.

anangl
anangl previously approved these changes Mar 27, 2025
@kartben
Copy link
Collaborator

kartben commented Apr 11, 2025

@dylanHsieh4963 this needs to be rebased

@JasonLin-RealTek
Copy link
Collaborator

Hi @kartben , we rebase the commit in here #88751, thanks!

@keith-zephyr
Copy link
Collaborator

Hi @kartben , we rebase the commit in here #88751, thanks!

Creating a new PR loses the comment history. Can you rebase this PR instead?

@JasonLin-RealTek
Copy link
Collaborator

Hi @keith-zephyr,
Here is the same situation with #87536
I will borrow his computer to rebase the commit as he back.

Add adc driver for Realtek rts5912.

Signed-off-by: Dylan Hsieh <[email protected]>
@kartben kartben dismissed stale reviews from anangl and keith-zephyr via 75ec1bf April 18, 2025 06:52
@kartben kartben force-pushed the rts5912_enable_adc branch from 28d2933 to 75ec1bf Compare April 18, 2025 06:52
@JasonLin-RealTek JasonLin-RealTek self-requested a review April 21, 2025 03:56
@kartben kartben merged commit f3bc550 into zephyrproject-rtos:main Apr 22, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ADC Analog-to-Digital Converter (ADC) platform: Realtek EC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants