pinctrl: stm32: add irq affinity, RIF, module support
Subsystems (5)
Antonio Borneo
maintainerv2 cover pinctrl: stm32: add irq affinity, RIF, module support
This v2 is a subset of the v1, split-out to simplify the review.
This subset:
- adds support for irq affinity,
- adds support for Resource Isolation Framework (RIF),
- allows compile the driver as module,
- adds entry in MAINTAINERS for STM32 pinctrl,
- minor cleanups.
Please notice that the entry in MAINTAINERS already excludes the pinctrl driver HDP that has a different maintainer but it's still under review in
https://lore.kernel.org/lkml/[email protected]/
Changes v1 -> v2 subset:
- rebased on v6.16-rc1,
- added include export.h required by v6.16-rc1,
- change in Kconfig to avoid default build on COMPILE_TEST,
- added entry in MAINTAINERS,
- Link to v1: https://lore.kernel.org/lkml/[email protected]/
Antonio Borneo (3):
pinctrl: stm32: Declare stm32_pmx_get_mode() as static
pinctrl: stm32: Add RIF support for stm32mp257
MAINTAINERS: Add entry for STM32 pinctrl drivers and documentation
Cheick Traore (1):
pinctrl: stm32: Manage irq affinity settings
Stephane Danieau (1):
pinctrl: stm32: Allow compile as module for stm32mp257
MAINTAINERS | 8 ++ arch/arm64/Kconfig.platforms | 1 - drivers/pinctrl/stm32/Kconfig | 6 +- drivers/pinctrl/stm32/pinctrl-stm32.c | 135 ++++++++++++++++++++- drivers/pinctrl/stm32/pinctrl-stm32.h | 19 ++- drivers/pinctrl/stm32/pinctrl-stm32mp257.c | 15 ++- 6 files changed, 168 insertions(+), 16 deletions(-)
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
Signature · 1 line
2.34.1
Antonio Borneo
maintainerPATCH v2 1/5 pinctrl: stm32: Declare stm32_pmx_get_mode() as static
The commit acaa037970f6 ("pinctrl: stm32: Implement .get_direction gpio_chip callback") exported the function stm32_pmx_get_mode() and the struct stm32_gpio_bank, but these were never used outside the file that defines them.
Declare the function as static, drop it from the include file and drop also the struct, not anymore visible outside the file.
--- drivers/pinctrl/stm32/pinctrl-stm32.c | 5 +++-- drivers/pinctrl/stm32/pinctrl-stm32.h | 4 ---- 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/pinctrl/stm32/pinctrl-stm32.c +3 -2
@@ -122,6 +122,8 @@ struct stm32_pinctrl {spinlock_t irqmux_lock; }; +static void stm32_pmx_get_mode (struct stm32_gpio_bank *bank,int pin,u32 *mode,u32 *alt); +static inline int stm32_gpio_pin (int gpio) {return gpio %STM32_GPIO_PINS_PER_BANK ;
@@ -798,8 +800,7 @@ static int stm32_pmx_set_mode(struct stm32_gpio_bank *bank,return err; } -void stm32_pmx_get_mode (struct stm32_gpio_bank *bank,int pin,u32 *mode, -u32 *alt) +static void stm32_pmx_get_mode (struct stm32_gpio_bank *bank,int pin,u32 *mode,u32 *alt) {u32 val;int alt_shift = (pin %8 ) *4 ;
drivers/pinctrl/stm32/pinctrl-stm32.h +0 -4
@@ -65,11 +65,7 @@ struct stm32_pinctrl_match_data {bool secure_control; }; -struct stm32_gpio_bank ; -int stm32_pctl_probe (struct platform_device *pdev); -void stm32_pmx_get_mode (struct stm32_gpio_bank *bank, -int pin,u32 *mode,u32 *alt);int stm32_pinctrl_suspend (struct device *dev);int stm32_pinctrl_resume (struct device *dev);
Signature · 1 line
2.34.1
Antonio Borneo
maintainerPATCH v2 2/5 pinctrl: stm32: Manage irq affinity settings
In reply to Antonio BorneoFrom: Cheick Traore <[email protected]>
Trying to set the affinity of the interrupts associated to stm32 pinctrl results in a write error.
Fill struct irq_chip::irq_set_affinity to use the default helper function.
--- drivers/pinctrl/stm32/pinctrl-stm32.c | 1 + 1 file changed, 1 insertion(+)
drivers/pinctrl/stm32/pinctrl-stm32.c +1 -0
@@ -413,6 +413,7 @@ static struct irq_chip stm32_gpio_irq_chip = { .irq_set_wake = irq_chip_set_wake_parent, .irq_request_resources = stm32_gpio_irq_request_resources, .irq_release_resources = stm32_gpio_irq_release_resources, + .irq_set_affinity = IS_ENABLED(CONFIG_SMP) ? irq_chip_set_affinity_parent : NULL, }; static int stm32_gpio_domain_translate(struct irq_domain *d,
Signature · 1 line
2.34.1
Antonio Borneo
maintainerPATCH v2 3/5 pinctrl: stm32: Add RIF support for stm32mp257
In reply to Antonio BorneoOn SoC stm32mp257, GPIO supports security and isolation compliant with the Resource Isolation Framework (RIF). Each GPIO line can be assigned to different security and compartment domains.
Add the generic code to handle the RIF configuration set by the secure world and initialize the GPIO valid mask accordingly.
Enable the RIF support for stm32mp257.
--- drivers/pinctrl/stm32/pinctrl-stm32.c | 121 ++++++++++++++++++++- drivers/pinctrl/stm32/pinctrl-stm32.h | 1 + drivers/pinctrl/stm32/pinctrl-stm32mp257.c | 4 + 3 files changed, 125 insertions(+), 1 deletion(-)
drivers/pinctrl/stm32/pinctrl-stm32.c +120 -1
@@ -6,6 +6,7 @@* * Heavily based on Mediatek's pinctrl driver */ +#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/gpio/driver.h> #include <linux/hwspinlock.h>
@@ -36,6 +37,8 @@#include "../pinctrl-utils.h" #include "pinctrl-stm32.h" +#define STM32_GPIO_CID1 1 +#define STM32_GPIO_MODER 0x00#define STM32_GPIO_TYPER 0x04#define STM32_GPIO_SPEEDR 0x08
@@ -47,6 +50,8 @@#define STM32_GPIO_AFRL 0x20#define STM32_GPIO_AFRH 0x24#define STM32_GPIO_SECCFGR 0x30 +#define STM32_GPIO_CIDCFGR (x) (0x50 + (0x8 * (x))) +#define STM32_GPIO_SEMCR (x) (0x54 + (0x8 * (x)))/* custom bitfield to backup pin status */ #define STM32_GPIO_BKP_MODE_SHIFT 0
@@ -60,6 +65,14 @@#define STM32_GPIO_BKP_TYPE 10#define STM32_GPIO_BKP_VAL 11 +#define STM32_GPIO_CIDCFGR_CFEN BIT(0) +#define STM32_GPIO_CIDCFGR_SEMEN BIT(1) +#define STM32_GPIO_CIDCFGR_SCID_MASK GENMASK(5, 4) +#define STM32_GPIO_CIDCFGR_SEMWL_CID1 BIT(16 + STM32_GPIO_CID1) + +#define STM32_GPIO_SEMCR_SEM_MUTEX BIT(0) +#define STM32_GPIO_SEMCR_SEMCID_MASK GENMASK(5, 4) +#define STM32_GPIO_PINS_PER_BANK 16#define STM32_GPIO_IRQ_LINE 16
@@ -98,6 +111,7 @@ struct stm32_gpio_bank {u32 pin_backup[STM32_GPIO_PINS_PER_BANK ];u8 irq_type[STM32_GPIO_PINS_PER_BANK ];bool secure_control; +bool rif_control; };struct stm32_pinctrl {
@@ -194,6 +208,80 @@ static void stm32_gpio_backup_bias(struct stm32_gpio_bank *bank, u32 offset, bank->pin_backup[offset] |= bias <<STM32_GPIO_BKP_PUPD_SHIFT ; } +/* RIF functions */ + +static bool stm32_gpio_rif_valid (struct stm32_gpio_bank *bank,unsigned int gpio_nr) +{ +u32 cid; + + cid =readl_relaxed (bank->base +STM32_GPIO_CIDCFGR (gpio_nr)); + +if (!(cid &STM32_GPIO_CIDCFGR_CFEN )) +return true; + +if (!(cid &STM32_GPIO_CIDCFGR_SEMEN )) { +if (FIELD_GET (STM32_GPIO_CIDCFGR_SCID_MASK , cid) ==STM32_GPIO_CID1 ) +return true; + +return false; + } + +if (cid &STM32_GPIO_CIDCFGR_SEMWL_CID1 ) +return true; + +return false; +} + +static bool stm32_gpio_rif_acquire_semaphore (struct stm32_gpio_bank *bank,unsigned int gpio_nr) +{ +u32 cid, sem; + + cid =readl_relaxed (bank->base +STM32_GPIO_CIDCFGR (gpio_nr)); + +if (!(cid &STM32_GPIO_CIDCFGR_CFEN )) +return true; + +if (!(cid &STM32_GPIO_CIDCFGR_SEMEN )) { +if (FIELD_GET (STM32_GPIO_CIDCFGR_SCID_MASK , cid) ==STM32_GPIO_CID1 ) +return true; + +return false; + } + +if (!(cid &STM32_GPIO_CIDCFGR_SEMWL_CID1 )) +return false; + + sem =readl_relaxed (bank->base +STM32_GPIO_SEMCR (gpio_nr)); +if (sem &STM32_GPIO_SEMCR_SEM_MUTEX ) { +if (FIELD_GET (STM32_GPIO_SEMCR_SEMCID_MASK , sem) ==STM32_GPIO_CID1 ) +return true; + +return false; + } + +writel_relaxed (STM32_GPIO_SEMCR_SEM_MUTEX , bank->base +STM32_GPIO_SEMCR (gpio_nr)); + + sem =readl_relaxed (bank->base +STM32_GPIO_SEMCR (gpio_nr)); +if (sem &STM32_GPIO_SEMCR_SEM_MUTEX && +FIELD_GET (STM32_GPIO_SEMCR_SEMCID_MASK , sem) ==STM32_GPIO_CID1 ) +return true; + +return false; +} + +static void stm32_gpio_rif_release_semaphore (struct stm32_gpio_bank *bank,unsigned int gpio_nr) +{ +u32 cid; + + cid =readl_relaxed (bank->base +STM32_GPIO_CIDCFGR (gpio_nr)); + +if (!(cid &STM32_GPIO_CIDCFGR_CFEN )) +return ; + +if (cid &STM32_GPIO_CIDCFGR_SEMEN ) +writel_relaxed (0 , bank->base +STM32_GPIO_SEMCR (gpio_nr)); +} +/* GPIO functions */ static inline void __stm32_gpio_set(struct stm32_gpio_bank *bank,
@@ -220,9 +308,26 @@ static int stm32_gpio_request(struct gpio_chip *chip, unsigned offset)return -EINVAL ; } +if (bank->rif_control) { +if (!stm32_gpio_rif_acquire_semaphore (bank, offset)) { +dev_err (pctl->dev,"pin %d not available.\n" , pin); +return -EINVAL ; + } + } +return pinctrl_gpio_request (chip, offset); } +static void stm32_gpio_free (struct gpio_chip *chip,unsigned int offset) +{ +struct stm32_gpio_bank *bank =gpiochip_get_data (chip); + +pinctrl_gpio_free (chip, offset); + +if (bank->rif_control) +stm32_gpio_rif_release_semaphore (bank, offset); +} +static int stm32_gpio_get (struct gpio_chip *chip,unsigned offset) {struct stm32_gpio_bank *bank =gpiochip_get_data (chip);
@@ -306,12 +411,25 @@ static int stm32_gpio_init_valid_mask(struct gpio_chip *chip, } } +if (bank->rif_control) { +for (i =0 ; i < ngpios; i++) { +if (!test_bit (i, valid_mask)) +continue ; + +if (stm32_gpio_rif_valid (bank, i)) +continue ; + +dev_dbg (pctl->dev,"RIF semaphore ownership conflict, GPIO %u" , i); +clear_bit (i, valid_mask); + } + } +return 0 ; }static const struct gpio_chip stm32_gpio_template = { .request = stm32_gpio_request, - .free = pinctrl_gpio_free, + .free = stm32_gpio_free, .get = stm32_gpio_get, .set_rv = stm32_gpio_set, .direction_input = pinctrl_gpio_direction_input,
@@ -1350,6 +1468,7 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode bank->bank_nr = bank_nr; bank->bank_ioport_nr = bank_ioport_nr; bank->secure_control = pctl->match_data->secure_control; + bank->rif_control = pctl->match_data->rif_control;spin_lock_init (&bank->lock);if (pctl->domain) {
drivers/pinctrl/stm32/pinctrl-stm32.h +1 -0
@@ -63,6 +63,7 @@ struct stm32_pinctrl_match_data {const struct stm32_desc_pin *pins;const unsigned int npins;bool secure_control; +bool rif_control; };int stm32_pctl_probe (struct platform_device *pdev);
drivers/pinctrl/stm32/pinctrl-stm32mp257.c +4 -0
@@ -2542,11 +2542,15 @@ static const struct stm32_desc_pin stm32mp257_z_pins[] = {static struct stm32_pinctrl_match_data stm32mp257_match_data = { .pins = stm32mp257_pins, .npins =ARRAY_SIZE (stm32mp257_pins), + .secure_control = true, + .rif_control = true, };static struct stm32_pinctrl_match_data stm32mp257_z_match_data = { .pins = stm32mp257_z_pins, .npins =ARRAY_SIZE (stm32mp257_z_pins), + .secure_control = true, + .rif_control = true, };static const struct of_device_id stm32mp257_pctrl_match[] = {
Signature · 1 line
2.34.1
Antonio Borneo
maintainerPATCH v2 4/5 pinctrl: stm32: Allow compile as module for stm32mp257
In reply to Antonio BorneoFrom: Stephane Danieau <[email protected]>
Add ability to build pinctrl for stm32mp257 as a kernel module. Add kernel-doc to the exported symbols.
--- arch/arm64/Kconfig.platforms | 1 - drivers/pinctrl/stm32/Kconfig | 6 +++--- drivers/pinctrl/stm32/pinctrl-stm32.c | 8 ++++++++ drivers/pinctrl/stm32/pinctrl-stm32.h | 14 ++++++++++++++ drivers/pinctrl/stm32/pinctrl-stm32mp257.c | 11 ++++++----- 5 files changed, 31 insertions(+), 9 deletions(-)
arch/arm64/Kconfig.platforms +0 -1
@@ -311,7 +311,6 @@ config ARCH_STM32 bool "STMicroelectronics STM32 SoC Family" select GPIOLIB select PINCTRL - select PINCTRL_STM32MP257 select ARM_SMC_MBOX select ARM_SCMI_PROTOCOL select REGULATOR
drivers/pinctrl/stm32/Kconfig +3 -3
@@ -2,7 +2,7 @@ if ARCH_STM32 || COMPILE_TEST config PINCTRL_STM32 - bool + tristate depends on OF select PINMUX select GENERIC_PINCONF
@@ -53,8 +53,8 @@ config PINCTRL_STM32MP157 select PINCTRL_STM32 config PINCTRL_STM32MP257 - bool "STMicroelectronics STM32MP257 pin control" if COMPILE_TEST && !MACH_STM32MP25 + tristate "STMicroelectronics STM32MP257 pin control" depends on OF && HAS_IOMEM - default MACH_STM32MP25 + default MACH_STM32MP25 || (ARCH_STM32 && ARM64) select PINCTRL_STM32 endif
drivers/pinctrl/stm32/pinctrl-stm32.c +8 -0
@@ -8,6 +8,7 @@*/ #include <linux/bitfield.h> #include <linux/clk.h> +#include <linux/export.h> #include <linux/gpio/driver.h> #include <linux/hwspinlock.h> #include <linux/io.h>
@@ -1785,6 +1786,7 @@ int stm32_pctl_probe(struct platform_device *pdev)clk_bulk_disable_unprepare (banks, pctl->clks);return ret; } +EXPORT_SYMBOL (stm32_pctl_probe);static int __maybe_unused stm32_pinctrl_restore_gpio_regs (struct stm32_pinctrl *pctl,u32 pin)
@@ -1857,6 +1859,7 @@ int __maybe_unused stm32_pinctrl_suspend(struct device *dev)return 0 ; } +EXPORT_SYMBOL (stm32_pinctrl_suspend);int __maybe_unused stm32_pinctrl_resume (struct device *dev) {
@@ -1873,3 +1876,8 @@ int __maybe_unused stm32_pinctrl_resume(struct device *dev)return 0 ; } +EXPORT_SYMBOL (stm32_pinctrl_resume); + +MODULE_AUTHOR ("Alexandre Torgue <[email protected]>" ); +MODULE_DESCRIPTION ("STM32 core pinctrl driver" ); +MODULE_LICENSE ("GPL" );
drivers/pinctrl/stm32/pinctrl-stm32.h +14 -0
@@ -66,8 +66,22 @@ struct stm32_pinctrl_match_data { bool rif_control; }; +/** +* stm32_pctl_probe() - Common probe for stm32 pinctrl drivers. +* @pdev: Pinctrl platform device. +*/ int stm32_pctl_probe (struct platform_device *pdev); + +/** +* stm32_pinctrl_suspend() - Common suspend for stm32 pinctrl drivers. +* @dev: Pinctrl device. +*/ int stm32_pinctrl_suspend (struct device *dev); + +/** +* stm32_pinctrl_resume() - Common resume for stm32 pinctrl drivers. +* @dev: Pinctrl device. +*/ int stm32_pinctrl_resume (struct device *dev);#endif /* __PINCTRL_STM32_H */
drivers/pinctrl/stm32/pinctrl-stm32mp257.c +6 -5
@@ -4,6 +4,7 @@* Author: Alexandre Torgue <[email protected]> for STMicroelectronics. */ #include <linux/init.h> +#include <linux/module.h> #include <linux/of.h> #include <linux/platform_device.h>
@@ -2564,6 +2565,7 @@ static const struct of_device_id stm32mp257_pctrl_match[] = { }, { } }; +MODULE_DEVICE_TABLE (of, stm32mp257_pctrl_match);static const struct dev_pm_ops stm32_pinctrl_dev_pm_ops = {SET_LATE_SYSTEM_SLEEP_PM_OPS (stm32_pinctrl_suspend, stm32_pinctrl_resume)
@@ -2577,9 +2579,8 @@ static struct platform_driver stm32mp257_pinctrl_driver = { .pm = &stm32_pinctrl_dev_pm_ops, }, }; +module_platform_driver (stm32mp257_pinctrl_driver); -static int __init stm32mp257_pinctrl_init (void ) -{ -return platform_driver_register (&stm32mp257_pinctrl_driver); -} -arch_initcall (stm32mp257_pinctrl_init); +MODULE_AUTHOR ("Alexandre Torgue <[email protected]>" ); +MODULE_DESCRIPTION ("STM32MP257 pinctrl driver" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
2.34.1
Antonio Borneo
maintainerPATCH v2 5/5 MAINTAINERS: Add entry for STM32 pinctrl drivers and documentation
In reply to Antonio BorneoAdd an entry to make myself a maintainer of STM32 pinctrl drivers and documentation.
Exclude the HDP driver, already covered by another maintainer.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -23471,6 +23471,14 @@ S: Maintained F: Documentation/devicetree/bindings/memory-controllers/st,stm32mp25-omm.yaml F: drivers/memory/stm32_omm.c +ST STM32 PINCTRL DRIVER +M: Antonio Borneo <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/pinctrl/st,stm32-pinctrl.yaml +F: drivers/pinctrl/stm32/ +F: include/dt-bindings/pinctrl/stm32-pinfunc.h +X: drivers/pinctrl/stm32/pinctrl-stm32-hdp.c + ST STM32 SPI DRIVER M: Alain Volmat <[email protected]> L: [email protected]
Signature · 1 line
2.34.1
Quoted 1 line · Antonio Borneo
This v2 is a subset of the v1, split-out to simplify the review.
Patches applied!
Yours,
Linus Walleij