Add pinctrl support for S32 SoC family
Subsystems (5)
v4 cover Add pinctrl support for S32 SoC family
Hello,
Here I want to introduce a new patch series, which aims to support IOMUX functions provided by SIUL2 [System Integration Unit Lite2] on S32 SoCs, such as S32G2. This series is originally from NXP's implementation on nxp-auto-linux repo[1] and it will be required by upstream kernel for supporting a variety of devices on S32 SoCs which need to config PINMUXs, such as PHYs and MAC controllers.
Thanks,
Chester
Changes in v4:
- dt-bindings:
- Change the representation of available slew-rate DT values from register values to real frequencies.
- driver:
- Add a mapping table for converting the slew rates to register settings.
- Move driver files into an independent folder drivers/pinctrl/nxp
- Add a MAINTAINER patch.
Changes in v3:
- dt-bindings:
- Remove the minItems from reg because there's no optional item for
s32g2.
- List supported properties of pinmux-node and pincfg-node and add more descriptions.
- Adjust the location of "required:".
- Fix descriptions and wordings.
- Rename the yaml file to nxp,s32g2-siul2-pinctrl.yaml.
- Rename pinctrl-s32g.c to pinctrl-s32g2.c
- Adjust Kconfig options [menu-invisible] and names [S32G -> S32G2].
- Add .suppress_bind_attrs
- Drop the .remove callback and replace the module_platform_driver() call with builtin_platform_driver()
Changes in v2:
- Move the "nxp,pins" ID range information from DT to the driver.
- dt-bindings:
- Fix schema issues.
- Add descriptions for reg entries.
- Revise the example.
- Refine the compatible name from "nxp,s32g-..." to "nxp,s32g2-...".
- Fix the copyright format suggested by NXP.
[1] https://github.com/nxp-auto-linux/linux/tree/bsp35.0-5.15.73-rt
Chester Lin (3):
dt-bindings: pinctrl: add schema for NXP S32 SoCs
pinctrl: add NXP S32 SoC family support
MAINTAINERS: Add NXP S32 pinctrl maintainer and reviewer
.../pinctrl/nxp,s32g2-siul2-pinctrl.yaml | 123 ++ MAINTAINERS | 8 + drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/nxp/Kconfig | 14 + drivers/pinctrl/nxp/Makefile | 4 + drivers/pinctrl/nxp/pinctrl-s32.h | 76 ++ drivers/pinctrl/nxp/pinctrl-s32cc.c | 1004 +++++++++++++++++ drivers/pinctrl/nxp/pinctrl-s32g2.c | 773 +++++++++++++ 9 files changed, 2004 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/nxp,s32g2-siul2-pinctrl.yaml create mode 100644 drivers/pinctrl/nxp/Kconfig create mode 100644 drivers/pinctrl/nxp/Makefile create mode 100644 drivers/pinctrl/nxp/pinctrl-s32.h create mode 100644 drivers/pinctrl/nxp/pinctrl-s32cc.c create mode 100644 drivers/pinctrl/nxp/pinctrl-s32g2.c
Signature · 7 lines
2.37.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v4 1/3 dt-bindings: pinctrl: add schema for NXP S32 SoCs
Add DT schema for the pinctrl driver of NXP S32 SoC family.
---
Changes in v4:
- Change the representation of available slew-rate DT values from register values to real frequencies.
.../pinctrl/nxp,s32g2-siul2-pinctrl.yaml | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/nxp,s32g2-siul2-pinctrl.yaml
Documentation/devicetree/bindings/pinctrl/nxp,s32g2-siul2-pinctrl.yaml new file +123 -0
@@ -0,0 +1,123 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2022 NXP +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/nxp,s32g2-siul2-pinctrl.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP S32G2 pin controller + +maintainers: + - Ghennadi Procopciuc <[email protected]> + - Chester Lin <[email protected]> + +description: | + S32G2 pinmux is implemented in SIUL2 (System Integration Unit Lite2), + whose memory map is split into two regions: + SIUL2_0 @ 0x4009c000 + SIUL2_1 @ 0x44010000 + + Every SIUL2 region has multiple register types, and here only MSCR and + IMCR registers need to be revealed for kernel to configure pinmux. + + Please note that some register indexes are reserved in S32G2, such as + MSCR102-MSCR111, MSCR123-MSCR143, IMCR84-IMCR118 and IMCR398-IMCR429. + +properties: + compatible: + enum: + - nxp,s32g2-siul2-pinctrl + + reg: + description: | + A list of MSCR/IMCR register regions to be reserved. + - MSCR (Multiplexed Signal Configuration Register) + An MSCR register can configure the associated pin as either a GPIO pin + or a function output pin depends on the selected signal source. + - IMCR (Input Multiplexed Signal Configuration Register) + An IMCR register can configure the associated pin as function input + pin depends on the selected signal source. + items: + - description: MSCR registers group 0 in SIUL2_0 + - description: MSCR registers group 1 in SIUL2_1 + - description: MSCR registers group 2 in SIUL2_1 + - description: IMCR registers group 0 in SIUL2_0 + - description: IMCR registers group 1 in SIUL2_1 + - description: IMCR registers group 2 in SIUL2_1 + +patternProperties: + '-pins$': + type: object + additionalProperties: false + + patternProperties: + '-grp[0-9]$': + type: object + allOf: + - $ref: pinmux-node.yaml# + - $ref: pincfg-node.yaml# + description: | + Pinctrl node's client devices specify pin muxes using subnodes, + which in turn use the standard properties below. + + properties: + bias-disable: true + bias-high-impedance: true + bias-pull-up: true + bias-pull-down: true + drive-open-drain: true + input-enable: true + output-enable: true + + pinmux: + description: | + An integer array for representing pinmux configurations of + a device. Each integer consists of a PIN_ID and a 4-bit + selected signal source(SSS) as IOMUX setting, which is + calculated as: pinmux = (PIN_ID << 4 | SSS) + + slew-rate: + description: Supported slew rate based on Fmax values (MHz) + enum: [83, 133, 150, 166, 208] + + additionalProperties: false + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + pinctrl@4009c240 { + compatible = "nxp,s32g2-siul2-pinctrl"; + + /* MSCR0-MSCR101 registers on siul2_0 */ + reg = <0x4009c240 0x198>, + /* MSCR112-MSCR122 registers on siul2_1 */ + <0x44010400 0x2c>, + /* MSCR144-MSCR190 registers on siul2_1 */ + <0x44010480 0xbc>, + /* IMCR0-IMCR83 registers on siul2_0 */ + <0x4009ca40 0x150>, + /* IMCR119-IMCR397 registers on siul2_1 */ + <0x44010c1c 0x45c>, + /* IMCR430-IMCR495 registers on siul2_1 */ + <0x440110f8 0x108>; + + llce-can0-pins { + llce-can0-grp0 { + pinmux = <0x2b0>; + input-enable; + slew-rate = <208>; + }; + + llce-can0-grp1 { + pinmux = <0x2c2>; + output-enable; + slew-rate = <208>; + }; + }; + }; +...
Signature · 7 lines
2.37.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v4 1/3] dt-bindings: pinctrl: add schema for NXP S32 SoCs
Quoted 7 lines · Chester Lin
Add DT schema for the pinctrl driver of NXP S32 SoC family.
Signed-off-by Larisa Grigore <[email protected]>Signed-off-by Ghennadi Procopciuc <[email protected]>Signed-off-by Chester Lin <[email protected]>---
Quoted 8 lines
Changes in v4:
- Change the representation of available slew-rate DT values from register values to real frequencies..../pinctrl/nxp,s32g2-siul2-pinctrl.yaml | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/nxp,s32g2-siul2-pinctrl.yaml
PATCH v4 2/3 pinctrl: add NXP S32 SoC family support
In reply to Chester LinAdd the pinctrl driver for NXP S32 SoC family. This driver is mainly based on NXP's downstream implementation on nxp-auto-linux repo[1].
[1] https://github.com/nxp-auto-linux/linux/tree/bsp35.0-5.15.73-rt/drivers/pinctrl/freescale
---
Changes in v4:
- Add a mapping table for converting the slew rates to register settings.
- Move driver files into an independent folder drivers/pinctrl/nxp
drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/nxp/Kconfig | 14 + drivers/pinctrl/nxp/Makefile | 4 + drivers/pinctrl/nxp/pinctrl-s32.h | 76 ++ drivers/pinctrl/nxp/pinctrl-s32cc.c | 1004 +++++++++++++++++++++++++++ drivers/pinctrl/nxp/pinctrl-s32g2.c | 773 +++++++++++++++++++++ 7 files changed, 1873 insertions(+) create mode 100644 drivers/pinctrl/nxp/Kconfig create mode 100644 drivers/pinctrl/nxp/Makefile create mode 100644 drivers/pinctrl/nxp/pinctrl-s32.h create mode 100644 drivers/pinctrl/nxp/pinctrl-s32cc.c create mode 100644 drivers/pinctrl/nxp/pinctrl-s32g2.c
drivers/pinctrl/Kconfig +1 -0
@@ -535,6 +535,7 @@ source "drivers/pinctrl/meson/Kconfig" source "drivers/pinctrl/mvebu/Kconfig" source "drivers/pinctrl/nomadik/Kconfig" source "drivers/pinctrl/nuvoton/Kconfig" +source "drivers/pinctrl/nxp/Kconfig" source "drivers/pinctrl/pxa/Kconfig" source "drivers/pinctrl/qcom/Kconfig" source "drivers/pinctrl/ralink/Kconfig"
drivers/pinctrl/Makefile +1 -0
@@ -64,6 +64,7 @@ obj-$(CONFIG_PINCTRL_MESON) += meson/ obj-y += mvebu/ obj-y += nomadik/ obj-y += nuvoton/ +obj-y += nxp/ obj-$(CONFIG_PINCTRL_PXA) += pxa/ obj-$(CONFIG_ARCH_QCOM) += qcom/ obj-$(CONFIG_PINCTRL_RALINK) += ralink/
drivers/pinctrl/nxp/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +config PINCTRL_S32CC + bool + depends on ARCH_S32 && OF + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF + +config PINCTRL_S32G2 + depends on ARCH_S32 && OF + bool "NXP S32G2 pinctrl driver" + select PINCTRL_S32CC + help + Say Y here to enable the pinctrl driver for NXP S32G2 family SoCs
drivers/pinctrl/nxp/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +# NXP pin control +obj-$(CONFIG_PINCTRL_S32CC) += pinctrl-s32cc.o +obj-$(CONFIG_PINCTRL_S32G2) += pinctrl-s32g2.o
drivers/pinctrl/nxp/pinctrl-s32.h new file +76 -0
76 lines not on this page · raw message
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +1004 -0
1,004 lines not on this page · raw message
drivers/pinctrl/nxp/pinctrl-s32g2.c new file +773 -0
773 lines not on this page · raw message
Signature · 7 lines
2.37.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v4 2/3] pinctrl: add NXP S32 SoC family support
Hi Chester!
thanks for your patch!
This looks much better and the DT bindings are finished which is nice. As the driver is pretty big I need to find time to do review and look closer.
Here follows some concerns:
Quoted 13 lines · Chester Lin
Add the pinctrl driver for NXP S32 SoC family. This driver is mainly based on NXP's downstream implementation on nxp-auto-linux repo[1].
[1] https://github.com/nxp-auto-linux/linux/tree/bsp35.0-5.15.73-rt/drivers/pinctrl/freescale
Signed-off-by Matthew Nunez <[email protected]>Signed-off-by Phu Luu An <[email protected]>Signed-off-by Stefan-Gabriel Mirea <[email protected]>Signed-off-by Larisa Grigore <[email protected]>Signed-off-by Ghennadi Procopciuc <[email protected]>Signed-off-by Andrei Stefanescu <[email protected]>Signed-off-by Radu Pirea <[email protected]>Signed-off-by Chester Lin <[email protected]>
(...)
drivers/pinctrl/nxp/Kconfig line 7
Quoted 9 lines
+++ b/drivers/pinctrl/nxp/Kconfig
drivers/pinctrl/nxp/Kconfig new file +7
-0@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +config PINCTRL_S32CC + bool + depends on ARCH_S32 && OF + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF
Maybe select REGMAP_MMIO
Maybe select GPIO_GENERIC or GPIO_REGMAP
see further below.
drivers/pinctrl/nxp/pinctrl-s32.h line 75
Quoted 4 lines
drivers/pinctrl/nxp/pinctrl-s32.h new file +4
-0+#ifdef CONFIG_PM_SLEEP +int s32_pinctrl_resume (struct device *dev); +int s32_pinctrl_suspend (struct device *dev); +#endif
I think these are usually handled by tagging the functions with __maybe_unused.
drivers/pinctrl/nxp/pinctrl-s32cc.c line 41
Quoted 3 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +3
-0+static u32 get_pin_no (u32 pinmux) +{ +return pinmux >>S32CC_PIN_NO_SHIFT ;
Maybe add a mask too so it is clear that you just rely on bits being shifted out to the righy.
Quoted 56 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +56
-0+static inline int s32_pinctrl_readl_nolock (struct pinctrl_dev *pctldev, +unsigned int pin, +unsigned long *config) +{ +struct s32_pinctrl_mem_region *region; +unsigned int offset; + + region =s32_get_region (pctldev, pin); +if (!region) +return -EINVAL ; + + offset = pin - region->pin_range->start; + + *config =readl (region->base +S32_PAD_CONFIG (offset)); + +return 0 ; +} + +static inline int s32_pinctrl_readl (struct pinctrl_dev *pctldev, +unsigned int pin, +unsigned long *config) +{ +struct s32_pinctrl *ipctl =pinctrl_dev_get_drvdata (pctldev); +unsigned long flags; +int ret; + +spin_lock_irqsave (&ipctl->reg_lock, flags); + ret =s32_pinctrl_readl_nolock (pctldev, pin, config); +spin_unlock_irqrestore (&ipctl->reg_lock, flags); + +return ret; +} + +static inline int s32_pinctrl_writel_nolock (struct pinctrl_dev *pctldev, +unsigned int pin, +unsigned long config) +{ +struct s32_pinctrl_mem_region *region; +unsigned int offset; + + region =s32_get_region (pctldev, pin); +if (!region) +return -EINVAL ; + + offset = pin - region->pin_range->start; + +writel (config, region->base +S32_PAD_CONFIG (offset)); + +return 0 ; + +} + +static inline int s32_pinctrl_writel (unsigned long config, +struct pinctrl_dev *pctldev, +unsigned int pin) +{
drivers/pinctrl/nxp/pinctrl-s32cc.c line 184
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +10
-0+struct s32_pinctrl *ipctl =pinctrl_dev_get_drvdata (pctldev); +unsigned long flags; +int ret; + +spin_lock_irqsave (&ipctl->reg_lock, flags); + ret =s32_pinctrl_writel_nolock (pctldev, pin, config); +spin_unlock_irqrestore (&ipctl->reg_lock, flags); + +return ret; +}
If you turn this around, *first* get the offset and *then* issye the read/write to respective registers, you will find that you have re-implemented regmap_mmio, which will take care of serializing your writes so that you do not need a lock either. At least consider it.
Quoted 9 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +9
-0+static int s32_update_pin_mscr (struct pinctrl_dev *pctldev,unsigned int pin, +unsigned long mask,unsigned long new_mask) +{ +struct s32_pinctrl *ipctl =pinctrl_dev_get_drvdata (pctldev); +unsigned long config, flags; +int ret; + +spin_lock_irqsave (&ipctl->reg_lock, flags); +
drivers/pinctrl/nxp/pinctrl-s32cc.c line 330
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +10
-0+ ret =s32_pinctrl_readl_nolock (pctldev, pin, &config); +if (ret) + goto unlock; + + config &= ~mask; + config |= new_mask; + + ret =s32_pinctrl_writel_nolock (pctldev, pin, config); +if (ret) + goto unlock;
And after having pointed out how regmap MMIO was reimplemented, here you re-implement regmap_update_bits() which performs mask and set.
drivers/pinctrl/nxp/pinctrl-s32cc.c line 510
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +10
-0+static int s32_pinconf_get (struct pinctrl_dev *pctldev, +unsigned int pin_id, +unsigned long *config) +{ +int ret =s32_pinctrl_readl (pctldev, pin_id, config); + +if (ret) +return -EINVAL ; + +return 0 ;
This looks like unnecessary indirection since every call site has to check the return code anyway, can't you just inline the s32_pinctrl_readl() calls?
(...)
Quoted 1 line
+#ifdef
CONFIG_PM_SLEEP
Use __maybe_unused and compile in unconditionally.
Quoted 8 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +8
-0+static void s32_pinctrl_parse_groups (struct device_node *np, +struct s32_pin_group *grp, +struct s32_pinctrl_soc_info *info) +{ +const __be32 *p; +struct device *dev; +struct property *prop; +int i, npins;
drivers/pinctrl/nxp/pinctrl-s32cc.c line 799
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +10
-0+u32 pinmux; + + dev = info->dev; + +dev_dbg (dev,"group: %s\n" , np->name); + +/* Initialise group */ + grp->name = np->name; + + npins =of_property_count_elems_of_size (np,"pinmux" ,sizeof (u32));
There is a lot of code here for handling the funky pinmux stuff. Don't we have generic helpers for this? Well maybe not :/
Quoted 20 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +20
-0+static void s32_pinctrl_parse_functions (struct device_node *np, +struct s32_pinctrl_soc_info *info, +u32 index) +{ +struct device_node *child; +struct s32_pmx_func *func; +struct s32_pin_group *grp; +u32 i =0 ; + +dev_dbg (info->dev,"parse function(%d): %s\n" , index, np->name); + + func = &info->functions[index]; + +/* Initialise function */ + func->name = np->name; + func->num_groups =of_get_child_count (np); +if (func->num_groups ==0 ) { +dev_err (info->dev,"no groups defined in %s\n" , np->full_name); +return ; + }
drivers/pinctrl/nxp/pinctrl-s32cc.c line 864
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +10
-0+ func->groups =devm_kzalloc (info->dev, + func->num_groups *sizeof (char *),GFP_KERNEL ); + +for_each_child_of_node (np, child) { + func->groups[i] = child->name; + grp = &info->groups[info->grp_index++]; +s32_pinctrl_parse_groups (child, grp, info); + i++; + } +}
This also looks like helpers we should already have, can you look around
a bit in other recently merged drivers?
Yours,
Linus Walleij
Re: [PATCH v4 2/3] pinctrl: add NXP S32 SoC family support
Hi Linus,
Sorry for the late reply and thank you for reviewing this patch!
Quoted 42 lines · Linus Walleij
Hi Chester!
thanks for your patch!
This looks much better and the DT bindings are finished which is nice. As the driver is pretty big I need to find time to do review and look closer.
Here follows some concerns:
Quoted 13 lines · Chester Lin
Add the pinctrl driver for NXP S32 SoC family. This driver is mainly based on NXP's downstream implementation on nxp-auto-linux repo[1].
[1] https://github.com/nxp-auto-linux/linux/tree/bsp35.0-5.15.73-rt/drivers/pinctrl/freescale
Signed-off-by Matthew Nunez <[email protected]>Signed-off-by Phu Luu An <[email protected]>Signed-off-by Stefan-Gabriel Mirea <[email protected]>Signed-off-by Larisa Grigore <[email protected]>Signed-off-by Ghennadi Procopciuc <[email protected]>Signed-off-by Andrei Stefanescu <[email protected]>Signed-off-by Radu Pirea <[email protected]>Signed-off-by Chester Lin <[email protected]>(...)
drivers/pinctrl/nxp/Kconfig line 7
Quoted 9 lines
+++ b/drivers/pinctrl/nxp/Kconfig
drivers/pinctrl/nxp/Kconfig new file +7
-0@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +config PINCTRL_S32CC + bool + depends on ARCH_S32 && OF + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONFMaybe select
REGMAP_MMIO
Maybe selectGPIO_GENERICorGPIO_REGMAP
see further below.
Quoted 7 lines
drivers/pinctrl/nxp/pinctrl-s32.h line 75
Quoted 4 lines
drivers/pinctrl/nxp/pinctrl-s32.h new file +4
-0+#ifdef CONFIG_PM_SLEEP +int s32_pinctrl_resume (struct device *dev); +int s32_pinctrl_suspend (struct device *dev); +#endif I think these are usually handled by tagging the functions with
__maybe_unused.
Will fix it.
Quoted 7 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c line 41
Quoted 3 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +3
-0+static u32 get_pin_no (u32 pinmux) +{ +return pinmux >>S32CC_PIN_NO_SHIFT ;Maybe add a mask too so it is clear that you just rely on bits being shifted out to the righy.
Will do.
Quoted 87 lines
Quoted 56 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +56
-0+static inline int s32_pinctrl_readl_nolock (struct pinctrl_dev *pctldev, +unsigned int pin, +unsigned long *config) +{ +struct s32_pinctrl_mem_region *region; +unsigned int offset; + + region =s32_get_region (pctldev, pin); +if (!region) +return -EINVAL ; + + offset = pin - region->pin_range->start; + + *config =readl (region->base +S32_PAD_CONFIG (offset)); + +return 0 ; +} + +static inline int s32_pinctrl_readl (struct pinctrl_dev *pctldev, +unsigned int pin, +unsigned long *config) +{ +struct s32_pinctrl *ipctl =pinctrl_dev_get_drvdata (pctldev); +unsigned long flags; +int ret; + +spin_lock_irqsave (&ipctl->reg_lock, flags); + ret =s32_pinctrl_readl_nolock (pctldev, pin, config); +spin_unlock_irqrestore (&ipctl->reg_lock, flags); + +return ret; +} + +static inline int s32_pinctrl_writel_nolock (struct pinctrl_dev *pctldev, +unsigned int pin, +unsigned long config) +{ +struct s32_pinctrl_mem_region *region; +unsigned int offset; + + region =s32_get_region (pctldev, pin); +if (!region) +return -EINVAL ; + + offset = pin - region->pin_range->start; + +writel (config, region->base +S32_PAD_CONFIG (offset)); + +return 0 ; + +} + +static inline int s32_pinctrl_writel (unsigned long config, +struct pinctrl_dev *pctldev, +unsigned int pin) +{drivers/pinctrl/nxp/pinctrl-s32cc.c line 184
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +10
-0+struct s32_pinctrl *ipctl =pinctrl_dev_get_drvdata (pctldev); +unsigned long flags; +int ret; + +spin_lock_irqsave (&ipctl->reg_lock, flags); + ret =s32_pinctrl_writel_nolock (pctldev, pin, config); +spin_unlock_irqrestore (&ipctl->reg_lock, flags); + +return ret; +}If you turn this around, *first* get the offset and *then* issye the read/write to respective registers, you will find that you have re-implemented
regmap_mmio, which will take care of serializing your writes so that you do not need a lock either. At least consider it.Quoted 15 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +15
-0+static int s32_update_pin_mscr (struct pinctrl_dev *pctldev,unsigned int pin, +unsigned long mask,unsigned long new_mask) +{ +struct s32_pinctrl *ipctl =pinctrl_dev_get_drvdata (pctldev); +unsigned long config, flags; +int ret; + +spin_lock_irqsave (&ipctl->reg_lock, flags); + + ret =s32_pinctrl_readl_nolock (pctldev, pin, &config); +if (ret) + goto unlock; + + config &= ~mask; + config |= new_mask;
Quoted 9 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c line 330
Quoted 4 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +4
-0+ + ret =s32_pinctrl_writel_nolock (pctldev, pin, config); +if (ret) + goto unlock;And after having pointed out how regmap MMIO was reimplemented, here you re-implement
regmap_update_bits()which performs mask and set.
Thanks for your suggestion.
IIUC, that means I should use devm_regmap_init_mmio() to acquire a regmap and then use regmap APIs to access registers, such as regmap_read(), regmap_write() or regmap_update_bits(). My main concern is that this driver would need a regmap array to map all register base addresses since they are scattered based on the memory map of S32G2 SoC.
Quoted 6 lines
Quoted 6 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +6
-0+static int s32_pinconf_get (struct pinctrl_dev *pctldev, +unsigned int pin_id, +unsigned long *config) +{ +int ret =s32_pinctrl_readl (pctldev, pin_id, config); +
Quoted 9 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c line 400
Quoted 4 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +4
-0+if (ret) +return -EINVAL ; + +return 0 ;This looks like unnecessary indirection since every call site has to check the return code anyway, can't you just inline the
s32_pinctrl_readl()calls?
Will fix it, thanks!
Quoted 5 lines
(...)
Quoted 1 line
+#ifdef
CONFIG_PM_SLEEPUse
__maybe_unusedand compile in unconditionally.
Will do.
Quoted 47 lines
Quoted 8 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +8
-0+static void s32_pinctrl_parse_groups (struct device_node *np, +struct s32_pin_group *grp, +struct s32_pinctrl_soc_info *info) +{ +const __be32 *p; +struct device *dev; +struct property *prop; +int i, npins;drivers/pinctrl/nxp/pinctrl-s32cc.c line 799
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +10
-0+u32 pinmux; + + dev = info->dev; + +dev_dbg (dev,"group: %s\n" , np->name); + +/* Initialise group */ + grp->name = np->name; + + npins =of_property_count_elems_of_size (np,"pinmux" ,sizeof (u32));There is a lot of code here for handling the funky pinmux stuff. Don't we have generic helpers for this? Well maybe not :/
Quoted 25 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +25
-0+static void s32_pinctrl_parse_functions (struct device_node *np, +struct s32_pinctrl_soc_info *info, +u32 index) +{ +struct device_node *child; +struct s32_pmx_func *func; +struct s32_pin_group *grp; +u32 i =0 ; + +dev_dbg (info->dev,"parse function(%d): %s\n" , index, np->name); + + func = &info->functions[index]; + +/* Initialise function */ + func->name = np->name; + func->num_groups =of_get_child_count (np); +if (func->num_groups ==0 ) { +dev_err (info->dev,"no groups defined in %s\n" , np->full_name); +return ; + } + func->groups =devm_kzalloc (info->dev, + func->num_groups *sizeof (char *),GFP_KERNEL ); + +for_each_child_of_node (np, child) { + func->groups[i] = child->name;
Quoted 8 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c line 864
Quoted 5 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c new file +5
-0+ grp = &info->groups[info->grp_index++]; +s32_pinctrl_parse_groups (child, grp, info); + i++; + } +}This also looks like helpers we should already have, can you look around
a bit in other recently merged drivers?
You probably mean these two helpers in pinconf-generic.c:
pinconf_generic_dt_node_to_map()
pinconf_generic_dt_subnode_to_map()
Since we use specific pinmux format [as described in dt-bindings] to represent pin ID and mux settings, to my understanding, calling generic helpers would get nothing due to lack of generic properties, such as 'pins', 'groups' and 'function'.
Please feel free to correct me if anything wrong.
Thanks,
Chester
Quoted 3 lines
Yours,
Linus Walleij
PATCH v4 3/3 MAINTAINERS: Add NXP S32 pinctrl maintainer and reviewer
In reply to Chester LinAdd myself as a maintainer and add NXP S32 Linux Team as a review group for S32 pinctrl patches.
---
Changes in v4:
- The initial version in this series.
MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -16551,6 +16551,14 @@ S: Supported F: drivers/gpio/gpio-sama5d2-piobu.c F: drivers/pinctrl/pinctrl-at91* +PIN CONTROLLER - NXP S32 +M: Chester Lin <[email protected]> +R: NXP S32 Linux Team <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/pinctrl/nxp,s32* +F: drivers/pinctrl/nxp/ + PIN CONTROLLER - QUALCOMM M: Bjorn Andersson <[email protected]> L: [email protected]
Signature · 7 lines
2.37.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel