-
Notifications
You must be signed in to change notification settings - Fork 8.2k
pinctrl: add NPCX implementation. #43638
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
Conversation
|
Hi all, this PR has been verified on all devices on my side and marked as ready. Any comments are highly appreciated. |
9b02862 to
37a003d
Compare
|
Some general comments: Does this pinctrl driver provide any mechanism for setting the pullup/pulldown, and open drain properties? I believe these are set using the GPIO module in the NPCX, while the alternate function support is set through the system configuration It might be useful to add an NPCX specific pinctrl state called "locked". This state would be used set the corresponding Right now, as gerard notes, you have setup the default pinctrl for each driver. The I2C ports support is currently modeled as an I2C port/I2C controller pair. With the pinctrl support, this could be refactored so that the board uses the pinctrl-0 property to select the correct I2C port. For example, boards using I2C controller 4, port 1, are configured with the current implementation like this: This could be refactored as: |
|
Thanks for your comments. Please see my reply below.
Not only NPCX, the other soc series also use
Indeed, it is a good idea. I will add a new pinctrl state,
Here is the chart which demonstrates npcx I2C port and controller pair. If users use both i2c6_0 and i2c6_1 ports for the application, all relevant selection bits in DEVALTn must be set, and switch pin-mux from GPIO to I2C. By setting the i2c-port DT node's status to In my opinion, I still think putting |
This was my thought as well. This will also simplify the devicetree for the user. Today the user needs to enable both the I2C port (&i2c0_0) and the I2C controller (&i2c_ctrl0). |
8cfaae0 to
f3d43ac
Compare
gmarull
left a comment
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.
lgtm, a couple of minor issues
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 property should be part of the pwm6_gpc0 node
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. Setting bit 7 in PWMCTLEX selects the type of the PWM_n output buffer to push-pull or open-drain. I don't know it's a good idea to move it to pinctrl_npcx.c. Hence, I still keep it in the pwm driver.
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 review the latest PR.
drivers/pwm/pwm_npcx.c
Outdated
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 needs to be handled by a pin control driver, not like this. If some pin properties are handled directly by certain IP blocks (like e.g. Nordic), you can either encode address/bit in the state node or make use of the PINCTRL_STORE_REG, so that you also get the peripheral address when being called.
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.
Got it. Will modify it for code review later.
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. The latest PR has moved sources that configure drive-open-drain from pwm_npcx.c to pinctrl_npcx.c. In order to make sure static casting of reg is reliable, a new property, drive-supported, is introduced in pwm pinctrl rebuild nodes.
gmarull
left a comment
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 for the continued effort
Thanks for the detailed explanation. It helps a lot. Hi @keith-zephyr, do you have any comments for the latest version? |
I have been on vacation. But I will review this tomorrow (May 11). |
|
In order to resolve the conflicts, I rebase the branch onto ToT. Sorry for dismissing @gmarull's approval. Could you review it again? |
drivers/pinctrl/Kconfig.npcx
Outdated
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 - this adds 4 bytes to every pinctrl node correct? But this is only needed by the PWM nodes.
If you can repack the bitfields of npcx_periph to use 3 bits to store the PWM instance number. You could then store the PWM base addresses into npcx_pinctrl_cfg similar to the base_scfg field.
Using PINCTRL_STORE_REG is a cleaner approach, so you would need to evaluate how much flash space is saved by encoding the PWM instance in place of using reg.
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 - this adds 4 bytes to every pinctrl node correct? But this is only needed by the PWM nodes.
ML> If you mean each given device that applies pinctrl mechanism will increase 4 bytes, yes, you're correct.
If you can repack the bitfields of
npcx_periphto use 3 bits to store the PWM instance number. You could then store the PWM base addresses intonpcx_pinctrl_cfgsimilar to thebase_scfgfield.
Using PINCTRL_STORE_REG is a cleaner approach, so you would need to evaluate how much flash space is saved by encoding the PWM instance in place of usingreg.
ML> I have thought about that before. But if we have a chance to add drive mode support for the other peripheral devices, PINCTRL_STORE_REG is a clearer way to maintain pinctrl mechanism. As I mentioned above, the flash space increases by 4 bytes for every device using pinctl-names and proctrl-0/1/2 properties for pinctrl mechanism. If we need to save flash spaces in the furture, I prefer to create the other PR that includes:
- Restore device's label name in
npcx_periph - Use
device_get_bindingto get the correct register address.
But the cost is the latency of selecting drive mode is longer.
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.
Note that device_get_binding is rarely needed these days, DEVICE_DT_GET can be used for most situations. It is sometimes not necessary to store a device pointer either, see e.g. how GD32 pinctrl driver handles selected port.
This CL is the initial version for npcx pinctrl driver and introduces pinctrl nodes for both IO-pads and peripheral devices for each npcx series. Users can set pin configuration via these nodes in the board layout DT file. It also wraps all configurations related to pin-muxing in pinctrl_soc.h. Regarding the other pin properties, we will implement them later. Signed-off-by: Mulin Chao <[email protected]>
Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in uart driver. Signed-off-by: Mulin Chao <[email protected]>
Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in i2c driver. Signed-off-by: Mulin Chao <[email protected]>
Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in pwm driver. Signed-off-by: Mulin Chao <[email protected]>
Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in ps2 driver. Signed-off-by: Mulin Chao <[email protected]>
Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in npcx tachometer driver. Signed-off-by: Mulin Chao <[email protected]>
Replace soc-specific pin functions with Zephyr pinctrl api functions for
pin-mux configuration in npcx adc driver. Please notice users need to
configure the corresponding pinctrl nodes in 'pinctrl-0' property in the
adc0 DT node. For example, if ADC0 and ADC2 channels are selected for
the application, please add the follwoings in your board DT layout file.
&adc0 {
status = "okay";
/* Use adc0 channel 0 and 2 for 'adc_api' driver tests */
pinctrl-0 = <&adc0_chan0_gp45
&adc0_chan2_gp43>;
pinctrl-names = "default";
};
Signed-off-by: Mulin Chao <[email protected]>
Replace soc-specific pin functions with Zephyr pinctrl api functions for pin-mux configuration in npcx eSPI and host_subs driver. Signed-off-by: Mulin Chao <[email protected]>
|
Hi @gmarull & @keith-zephyr, sorry for the noise. The latest changes only rename variables for the recent comments. Please review it and give your comment freely. |
This pull request contains the following changes:
Add pinctrl implementation in pinctrl_npcx.c.
Merge npcx pinctrl configuration into pinctrl_soc_pin_t structure in soc/arm/nuvoton_npcx/common/pinctrl_soc.h
Keep part of the existing but non-generic NPCX soc pinctrl utilities still. (Will remove them in the following PRs.)
Inherit pinctrl-device in peripheral drivers' yaml files
Add required 'pinctrl-names' properties on related peripheral device-tree nodes.
Replace npcx utilities with pinctrl APIs for generic pinctrl functionalities in the driver.
Verified devices: (ongoing,)
npcx7m6fb_evb, npcx9m6f_evb, and volteer/lazer chromebooks.
Since Nuvton ec has been applied on notebooks for decades, the needs such as firmware backward compatibility are to be considered. Hence, there are three consideration factors during pinctrl driver refactoring.
This PR is the first attempt for npcx pinctrl driver and adds pinctrl nodes for each npcx series. According to the above points, it introduces pinctrl nodes for peripheral devices. And wraps all configurations no matter general pin-muxing or soc-specific features such as
pinmux-lockedin pinctrl_soc.h. Users set pin configuration via these nodes in the board layout DT file by the following ways:Regarding gpio and psl pads configurations via pinctrl driver, they will be introduced in the following PR.