Skip to content

drivers: gpio: gpio_dw: add optional API to set data and control source #85438

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xodus7
Copy link
Contributor

@xodus7 xodus7 commented Feb 8, 2025

If supported, the data and control source for a signal can come from either software or hardware. This change adds a driver specific API to set this for a specific pin.

*
* @retval 0 If successful.
*/
int gpio_dw_set_hw_mode(const struct device *port, gpio_pin_t pin, bool hw_mode);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this be called once per pin? or the mode can be changed many times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, once per pin, it's basically a binary pinmux and either SW (GPIO) or HW controlled.

If supported, the data and control source for a signal can come from
either software or hardware. This change adds a driver specific API
to set this for a specific pin.

Signed-off-by: Corey Wharton <[email protected]>
This variable should be const and inside the driver config struct.

Signed-off-by: Corey Wharton <[email protected]>
@kartben kartben added this to the v4.2.0 milestone Feb 18, 2025
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Apr 19, 2025
@xodus7
Copy link
Contributor Author

xodus7 commented Apr 24, 2025

Ping @kartben @JarmouniA

@kartben kartben requested a review from Copilot April 24, 2025 01:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an optional API for the DW GPIO driver to set the data/control source for a pin, allowing it to be controlled by hardware if supported. It also updates various driver functions to consistently retrieve the base address from the configuration structure and removes the redundant base_addr field from the runtime structure.

  • Added a new API function (gpio_dw_set_hw_mode) in the header and its implementation in the driver.
  • Updated internal functions to use config->base_addr rather than runtime->base_addr.
  • Removed duplication in the runtime structure by eliminating an unnecessary base_addr field.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
include/zephyr/drivers/gpio/gpio_dw.h Added the new API declaration and documentation for setting hardware control mode
drivers/gpio/gpio_dw.h Added a base_addr field in the configuration structure and removed base_addr from runtime
drivers/gpio/gpio_dw.c Updated multiple functions to use config->base_addr and implemented the gpio_dw_set_hw_mode API
Comments suppressed due to low confidence (1)

drivers/gpio/gpio_dw.c:408

  • [nitpick] Consider enhancing the assert message to include the pin number (e.g., 'Unsupported pin %d') to provide clearer debugging information.
__ASSERT((config->common.port_pin_mask & (gpio_port_pins_t)BIT(pin)) != 0U, "Unsupported pin");

Copy link
Member

@henrikbrixandersen henrikbrixandersen left a comment

Choose a reason for hiding this comment

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

Why not use custom GPIO flags for this?

@github-actions github-actions bot removed the Stale label Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants