pinctrl: tegra: Add descriptions for SoC data fields
Subsystems (3)
PATCH 1/2 pinctrl: tegra: Add descriptions for SoC data fields
Add detailed descriptions for the remaining fields in the tegra_pinctrl_soc_data structure. This improves code documentation and clarifies the purpose of each field, particularly for the pin-specific configuration options.
--- drivers/pinctrl/tegra/pinctrl-tegra.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/pinctrl/tegra/pinctrl-tegra.h +16 -10
@@ -176,16 +176,22 @@ struct tegra_pingroup {/** * struct tegra_pinctrl_soc_data - Tegra pin controller driver configuration -* @ngpios: The number of GPIO pins the pin controller HW affects. -* @pins: An array describing all pins the pin controller affects. -* All pins which are also GPIOs must be listed first within the -* array, and be numbered identically to the GPIO controller's -* numbering. -* @npins: The numbmer of entries in @pins. -* @functions: An array describing all mux functions the SoC supports. -* @nfunctions: The numbmer of entries in @functions. -* @groups: An array describing all pin groups the pin SoC supports. -* @ngroups: The numbmer of entries in @groups. +* @ngpios: The number of GPIO pins the pin controller HW affects. +* @gpio_compatible: Device-tree GPIO compatible string. +* @pins: An array describing all pins the pin controller affects. +* All pins which are also GPIOs must be listed first within the +* array, and be numbered identically to the GPIO controller's +* numbering. +* @npins: The number of entries in @pins. +* @functions: An array describing all mux functions the SoC supports. +* @nfunctions: The number of entries in @functions. +* @groups: An array describing all pin groups the pin SoC supports. +* @ngroups: The number of entries in @groups. +* @hsm_in_mux: High-speed mode field. Only applicable to devices with one pin per group. +* @schmitt_in_mux: Schmitt trigger field. Only applicable to devices with one pin per group. +* @drvtype_in_mux: Drivetype field. Only applicable to devices with one pin per group. +* @sfsel_in_mux: Special function selection field. +* Only applicable to devices with one pin per group. */ struct tegra_pinctrl_soc_data {unsigned ngpios;
Signature · 1 line
2.17.1
PATCH 2/2 pinctrl-tegra: Restore SFSEL bit when freeing pins
Each pin can be configured as a Special Function IO (SFIO) or GPIO, where the SFIO enables the pin to operate in alternative modes such as I2C, SPI, etc.
The current implementation sets all the pins back to SFIO mode even if they were initially in GPIO mode. This can cause glitches on the pins when pinctrl_gpio_free() is called.
Avoid these undesired glitches by storing the pin's SFIO/GPIO state on GPIO request and restoring it on GPIO free.
--- drivers/pinctrl/tegra/pinctrl-tegra.c | 59 +++++++++++++++++++++++---- drivers/pinctrl/tegra/pinctrl-tegra.h | 6 +++ 2 files changed, 57 insertions(+), 8 deletions(-)
drivers/pinctrl/tegra/pinctrl-tegra.c +51 -8
@@ -275,8 +275,8 @@ static int tegra_pinctrl_set_mux(struct pinctrl_dev *pctldev,return 0 ; } -static const struct tegra_pingroup *tegra_pinctrl_get_group (struct pinctrl_dev *pctldev, -unsigned int offset) +static int tegra_pinctrl_get_group_index (struct pinctrl_dev *pctldev, +unsigned int offset) {struct tegra_pmx *pmx =pinctrl_dev_get_drvdata (pctldev);unsigned int group, num_pins, j;
@@ -289,12 +289,35 @@ static const struct tegra_pingroup *tegra_pinctrl_get_group(struct pinctrl_dev *continue ;for (j =0 ; j < num_pins; j++) {if (offset == pins[j]) -return &pmx->soc->groups[group]; +return group; } } -dev_err (pctldev->dev,"Pingroup not found for pin %u\n" , offset); -return NULL ; +return -EINVAL ; +} + +static const struct tegra_pingroup *tegra_pinctrl_get_group (struct pinctrl_dev *pctldev, +unsigned int offset, +int group_index) +{ +struct tegra_pmx *pmx =pinctrl_dev_get_drvdata (pctldev); + +if (group_index <0 || group_index > pmx->soc->ngroups) +return NULL ; + +return &pmx->soc->groups[group_index]; +} + +static struct tegra_pingroup_config *tegra_pinctrl_get_group_config (struct pinctrl_dev *pctldev, +unsigned int offset, +int group_index) +{ +struct tegra_pmx *pmx =pinctrl_dev_get_drvdata (pctldev); + +if (group_index <0 ) +return NULL ; + +return &pmx->pingroup_configs[group_index]; } static int tegra_pinctrl_gpio_request_enable(struct pinctrl_dev *pctldev,
@@ -303,12 +326,15 @@ static int tegra_pinctrl_gpio_request_enable(struct pinctrl_dev *pctldev, {struct tegra_pmx *pmx =pinctrl_dev_get_drvdata (pctldev);const struct tegra_pingroup *group; +struct tegra_pingroup_config *config; +int group_index;u32 value;if (!pmx->soc->sfsel_in_mux)return 0 ; - group =tegra_pinctrl_get_group (pctldev, offset); + group_index =tegra_pinctrl_get_group_index (pctldev, offset); + group =tegra_pinctrl_get_group (pctldev, offset, group_index);if (!group)return -EINVAL ;
@@ -316,7 +342,11 @@ static int tegra_pinctrl_gpio_request_enable(struct pinctrl_dev *pctldev,if (group->mux_reg <0 || group->sfsel_bit <0 )return -EINVAL ; + config =tegra_pinctrl_get_group_config (pctldev, offset, group_index); +if (!config) +return -EINVAL ; value =pmx_readl (pmx, group->mux_bank, group->mux_reg); + config->is_sfsel = (value &BIT (group->sfsel_bit)) !=0 ; value &= ~BIT (group->sfsel_bit);pmx_writel (pmx, value, group->mux_bank, group->mux_reg);
@@ -329,12 +359,15 @@ static void tegra_pinctrl_gpio_disable_free(struct pinctrl_dev *pctldev, {struct tegra_pmx *pmx =pinctrl_dev_get_drvdata (pctldev);const struct tegra_pingroup *group; +struct tegra_pingroup_config *config; +int group_index;u32 value;if (!pmx->soc->sfsel_in_mux)return ; - group =tegra_pinctrl_get_group (pctldev, offset); + group_index =tegra_pinctrl_get_group_index (pctldev, offset); + group =tegra_pinctrl_get_group (pctldev, offset, group_index);if (!group)return ;
@@ -342,8 +375,12 @@ static void tegra_pinctrl_gpio_disable_free(struct pinctrl_dev *pctldev,if (group->mux_reg <0 || group->sfsel_bit <0 )return ; + config =tegra_pinctrl_get_group_config (pctldev, offset, group_index); +if (!config) +return ; value =pmx_readl (pmx, group->mux_bank, group->mux_reg); - value |=BIT (group->sfsel_bit); +if (config->is_sfsel) + value |=BIT (group->sfsel_bit);pmx_writel (pmx, value, group->mux_bank, group->mux_reg); }
@@ -788,6 +825,12 @@ int tegra_pinctrl_probe(struct platform_device *pdev, pmx->dev = &pdev->dev; pmx->soc = soc_data; + pmx->pingroup_configs =devm_kcalloc (&pdev->dev, + pmx->soc->ngroups,sizeof (*pmx->pingroup_configs), +GFP_KERNEL ); +if (!pmx->pingroup_configs) +return -ENOMEM ; +/* * Each mux group will appear in 4 functions' list of groups. * This over-allocates slightly, since not all groups are mux groups.
drivers/pinctrl/tegra/pinctrl-tegra.h +6 -0
@@ -8,6 +8,10 @@ #ifndef __PINMUX_TEGRA_H__ #define __PINMUX_TEGRA_H__ +struct tegra_pingroup_config { + bool is_sfsel; +}; + struct tegra_pmx { struct device *dev; struct pinctrl_dev *pctl;
@@ -21,6 +25,8 @@ struct tegra_pmx {int nbanks;void __iomem **regs;u32 *backup_regs; +/* Array of size soc->ngroups */ +struct tegra_pingroup_config *pingroup_configs; };enum tegra_pinconf_param {
Signature · 1 line
2.17.1
Quoted 6 lines · Prathamesh Shete
Add detailed descriptions for the remaining fields in the
tegra_pinctrl_soc_datastructure. This improves code documentation and clarifies the purpose of each field, particularly for the pin-specific configuration options.Signed-off-by Prathamesh Shete <[email protected]>
Both patches applied!
Yours,
Linus Walleij