-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Introduce new pinctrl API (variant b) #35847
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_sources_ifdef(CONFIG_USERSPACE pinctrl_handlers.c) | ||
|
|
||
| zephyr_sources_ifdef(CONFIG_PINCTRL_STM32 pinctrl_stm32.c) | ||
| zephyr_sources_ifdef(CONFIG_PINCTRL_SAM pinctrl_sam.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # HW Info driver configuration options | ||
|
|
||
| # Copyright (c) 2021 Piotr Mienkowski | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| menuconfig PINCTRL | ||
| bool "Pin Controller driver" | ||
| help | ||
| Enable pinctrl driver. | ||
|
|
||
| if PINCTRL | ||
|
|
||
| config PINCTRL_STM32 | ||
| bool "STM32 pinctrl" | ||
| default y | ||
| depends on SOC_FAMILY_STM32 | ||
| help | ||
| Enable STM32 pinctrl driver. | ||
|
|
||
| config PINCTRL_SAM | ||
| bool "Atmel SAM device ID" | ||
| default y | ||
| depends on SOC_FAMILY_SAM | ||
| help | ||
| Enable Atmel SAM pinctrl driver. | ||
|
|
||
| endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright (c) 2021 Piotr Mienkowski | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <syscall_handler.h> | ||
| #include <drivers/pinctrl.h> | ||
|
|
||
| int z_vrfy_pinctrl_pin_configure(const pinctrl_dt_pin_spec_t *pin_spec) | ||
| { | ||
| Z_SYSCALL_MEMORY_READ(pin_spec, sizeof(pinctrl_dt_pin_spec_t)); | ||
|
|
||
| return z_impl_pinctrl_pin_configure((const struct pinctrl_dt_pin_spec *)pin_spec); | ||
| } | ||
| #include <syscalls/pinctrl_pin_configure_mrsh.c> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright (c) 2021 Piotr Mienkowski | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <drivers/pinctrl.h> | ||
| #include <soc.h> | ||
|
|
||
| int z_impl_pinctrl_pin_configure(const pinctrl_dt_pin_spec_t *pin_spec) | ||
| { | ||
| soc_gpio_configure((const struct soc_gpio_pin *)pin_spec); | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * Copyright (c) 2021 Piotr Mienkowski | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * @file | ||
| * @brief Public APIs for PINCTRL drivers | ||
| */ | ||
|
|
||
| #ifndef ZEPHYR_INCLUDE_DRIVERS_PINCTRL_H_ | ||
| #define ZEPHYR_INCLUDE_DRIVERS_PINCTRL_H_ | ||
|
|
||
| #include <zephyr/types.h> | ||
| #include <toolchain.h> | ||
| #include <soc_pinctrl.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @brief PINCTRL Driver APIs | ||
| * @defgroup pinctrl_interface PINCTRL Driver APIs | ||
| * @ingroup io_interfaces | ||
| * @{ | ||
| */ | ||
|
|
||
| /** | ||
| * @typedef pinctrl_dt_pin_spec_t | ||
| * | ||
| * @brief Provides a type to hold PINCTRL information specified in devicetree | ||
| * | ||
| * This type is sufficient to hold a PINCTRL device pointer, pin number, | ||
| * and the subset of the flags used to control PINCTRL configuration | ||
| * which may be given in devicetree. | ||
| */ | ||
|
|
||
| /** | ||
| * @def PINCTRL_DT_SPEC_GET(node_id, n) | ||
| * | ||
| * @brief Static initializer for a @p pinctrl_dt_pin_spec | ||
| * | ||
| * This returns a static initializer for a @p pinctrl_dt_pin_spec structure | ||
| * given a devicetree node identifier and a state ID. | ||
| * | ||
| * Example devicetree fragment: | ||
| * | ||
| * nodelabel: node { | ||
| * pinctrl-0 = <&pincfg_a>, <&pincfg_b>, <&pincfg_c>; | ||
| * pinctrl-1 = <&pincfg_ax>, <&pincfg_bx>; | ||
| * } | ||
| * | ||
| * Example usage: | ||
| * | ||
| * const pinctrl_dt_pin_spec_t spec[] = | ||
| * PINCTRL_DT_SPEC_GET(DT_NODELABEL(nodelabel), 0); | ||
| * | ||
| * It is an error to use this macro unless the node exists, has the given | ||
| * property, and that property specifies a list of valid phandles to pin | ||
| * configuration node. | ||
| * | ||
| * @param node_id devicetree node identifier | ||
| * @param n an integer id that corresponds to pinctrl-n property. | ||
| * @return static initializer for an array of `pinctrl_dt_pin_spec_t` | ||
| */ | ||
|
|
||
| /** | ||
| * @brief Configure a single pin from a @p pinctrl_dt_pin_spec. | ||
| * | ||
| * @param pin_spec Pin configuration obtained from the device tree. | ||
| * | ||
| * @retval 0 If successful. | ||
| */ | ||
| __syscall int pinctrl_pin_configure(const pinctrl_dt_pin_spec_t *pin_spec); | ||
|
|
||
| int z_impl_pinctrl_pin_configure(const pinctrl_dt_pin_spec_t *pin_spec); | ||
|
|
||
| /** | ||
| * @brief Configure pin list from a @p pinctrl_dt_pin_spec array. | ||
| * | ||
| * @param pin_spec An array of pin spec elements obtained from the device tree. | ||
| * @param pin_spec_length number of elements in pin_spec array. | ||
| * | ||
| * @retval 0 If successful. | ||
| */ | ||
| static inline int pinctrl_pin_list_configure( | ||
| const pinctrl_dt_pin_spec_t pin_spec[], | ||
| unsigned int pin_spec_length) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
| int ret = 0; | ||
|
|
||
| for (int i = 0; i < pin_spec_length; i++) { | ||
| ret = pinctrl_pin_configure(&pin_spec[i]); | ||
| if (ret != 0) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| /** | ||
| * @} | ||
| */ | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #include <syscalls/pinctrl.h> | ||
|
|
||
| #endif /* ZEPHYR_INCLUDE_DRIVERS_PINCTRL_H_ */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I wonder if there is any utility in passing a device pointer in here.
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.
Passing device pointer as the first argument of the function?
For the
pinctrl_pin_list_configurefunction that would not be practical since everypinctrl_dt_pin_spec_titem from the list may be associated with a different device. But it probably makes sense to do it forpinctrl_pin_configurefunction. The function will becomeThe current
pinctrl_pin_configure,pinctrl_pin_list_configurefunctions will preserve their arguments but be renamed topinctrl_pin_configure_dt,pinctrl_pin_list_configure_dt. After the change we will break one less convention and the implementation will be better aligned with the GPIO driver.