Skip to contentSkip to conversation

Add pinctrl support for sky1

PATCH Superseded Gary Yang 3 participants 17 messages Sep 12, 2025 – Oct 9, 2025

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Gary Yang

author maintainer
#0 lore raw

v2 cover Add pinctrl support for sky1

Patch 1: add Cix pinctrl driver to support pinmux and pinconfigs Patch 2: add Cix pinctrl nodes and header file
Patch 3: add yaml doc

Changes for v2:
- restructure the pinctrl driver to support pinmux=<..>
- redefine pinmux macros
- move header file from dt-bindings to dts
- fix the code-style issues

Gary Yang (3):
pinctrl: cix: Add pin-controller support for sky1
dt-bindings: pinctrl: Add cix,sky1-pinctrl
arm64: dts: cix: Add pinctrl nodes for sky1

 .../bindings/pinctrl/cix,sky1-pinctrl.yaml    |   85 +
 arch/arm64/boot/dts/cix/sky1-orion-o6.dts     |   32 +
 arch/arm64/boot/dts/cix/sky1-pinfunc.h        |  417 +++++
 arch/arm64/boot/dts/cix/sky1.dtsi             |   10 +
 drivers/pinctrl/Kconfig                       |    1 +
 drivers/pinctrl/Makefile                      |    1 +
 drivers/pinctrl/cix/Kconfig                   |   14 +
 drivers/pinctrl/cix/Makefile                  |    4 +
 drivers/pinctrl/cix/pinctrl-sky1-base.c       |  581 +++++++
 drivers/pinctrl/cix/pinctrl-sky1.c            | 1435 +++++++++++++++++
 drivers/pinctrl/cix/pinctrl-sky1.h            |   46 +
 11 files changed, 2626 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml
 create mode 100644 arch/arm64/boot/dts/cix/sky1-pinfunc.h
 create mode 100644 drivers/pinctrl/cix/Kconfig
 create mode 100644 drivers/pinctrl/cix/Makefile
 create mode 100644 drivers/pinctrl/cix/pinctrl-sky1-base.c
 create mode 100644 drivers/pinctrl/cix/pinctrl-sky1.c
 create mode 100644 drivers/pinctrl/cix/pinctrl-sky1.h
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH v2 1/3 pinctrl: cix: Add pin-controller support for sky1

Add the pin-controller driver for Sky1 platform

---
 drivers/pinctrl/Kconfig                 |    1 +
 drivers/pinctrl/Makefile                |    1 +
 drivers/pinctrl/cix/Kconfig             |   14 +
 drivers/pinctrl/cix/Makefile            |    4 +
 drivers/pinctrl/cix/pinctrl-sky1-base.c |  581 +++++++++
 drivers/pinctrl/cix/pinctrl-sky1.c      | 1435 +++++++++++++++++++++++
 drivers/pinctrl/cix/pinctrl-sky1.h      |   46 +
 7 files changed, 2082 insertions(+)
 create mode 100644 drivers/pinctrl/cix/Kconfig
 create mode 100644 drivers/pinctrl/cix/Makefile
 create mode 100644 drivers/pinctrl/cix/pinctrl-sky1-base.c
 create mode 100644 drivers/pinctrl/cix/pinctrl-sky1.c
 create mode 100644 drivers/pinctrl/cix/pinctrl-sky1.h
drivers/pinctrl/Kconfig +1 -0
index ddd11668457c..a5b7177be115 100644
@@ -653,6 +653,7 @@ source "drivers/pinctrl/aspeed/Kconfig"
 source "drivers/pinctrl/bcm/Kconfig"
 source "drivers/pinctrl/berlin/Kconfig"
 source "drivers/pinctrl/cirrus/Kconfig"
+source "drivers/pinctrl/cix/Kconfig"
 source "drivers/pinctrl/freescale/Kconfig"
 source "drivers/pinctrl/intel/Kconfig"
 source "drivers/pinctrl/mediatek/Kconfig"
drivers/pinctrl/Makefile +1 -0
index 909ab89a56d2..8f353fc38e0e 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_ARCH_ASPEED)	+= aspeed/
 obj-y				+= bcm/
 obj-$(CONFIG_PINCTRL_BERLIN)	+= berlin/
 obj-y				+= cirrus/
+obj-y				+= cix/
 obj-y				+= freescale/
 obj-$(CONFIG_X86)		+= intel/
 obj-y				+= mediatek/
drivers/pinctrl/cix/Kconfig new file +14 -0
new file mode 100644
index 000000000000..42e064b6e7a2
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config PINCTRL_SKY1_BASE
+	tristate
+	select GENERIC_PINCTRL_GROUPS
+	select GENERIC_PINMUX_FUNCTIONS
+	select GENERIC_PINCONF
+	select REGMAP
+
+config PINCTRL_SKY1
+	tristate "Cix Sky1 pinctrl driver"
+	depends on ARCH_CIX
+	select PINCTRL_SKY1_BASE
+	help
+	  Say Y here to enable the sky1 pinctrl driver
drivers/pinctrl/cix/Makefile new file +4 -0
new file mode 100644
index 000000000000..22685d6a107b
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+# Cix Sky1 pin control drivers
+obj-$(CONFIG_PINCTRL_SKY1_BASE)	+= pinctrl-sky1-base.o
+obj-$(CONFIG_PINCTRL_SKY1)	+= pinctrl-sky1.o
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +581 -0

581 lines not on this page · raw message

drivers/pinctrl/cix/pinctrl-sky1.c new file +1435 -0

1,435 lines not on this page · raw message

drivers/pinctrl/cix/pinctrl-sky1.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.49.0
#2 lore raw

Re: [v2 1/3] pinctrl: cix: Add pin-controller support for sky1

Hi Gary,

thanks for your patch!

Quoted 2 lines · Gary Yang

Add the pin-controller driver for Sky1 platform

Add some more description of the pin control on the SoC here please.

Quoted 1 line

(...)

Config structure in Kconfig looks good!

Quoted 21 lines

+++ b/drivers/pinctrl/cix/pinctrl-sky1-base.c

drivers/pinctrl/cix/pinctrl-sky1-base.c new file +19 -0
@@ -0,0 +1,581 @@
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Author: Jerry Zhu <[email protected]>
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_address.h>
+#include <linux/pinctrl/machine.h>
+#include <linux/pinctrl/pinconf.h>
+#include <linux/pinctrl/pinconf-generic.h>
+#include <linux/pinctrl/pinctrl.h>
+#include <linux/pinctrl/pinmux.h>
+#include <linux/platform_device.h>
+#include <linux/seq_file.h>

drivers/pinctrl/cix/pinctrl-sky1-base.c line 29

Quoted 10 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +10 -0
+#include <linux/slab.h>
+
+#include "../core.h"
+#include "../pinconf.h"
+#include "../pinctrl-utils.h"
+#include "../pinmux.h"
+#include "pinctrl-sky1.h"
+
+#define SKY1_PIN_SIZE          (0x4)
+#define SKY1_MUX_MASK          (0x180)

For masks do this:

#include <linux/bits.h>

#define SKY1_MUX_MASK GENMASK(8, 7)

GENMASK generates a bitmask from bit 7 to 8, 0x180.

If its a 32bit register you can use GENMASK_U32() to be even clearer, etc.

drivers/pinctrl/cix/pinctrl-sky1-base.c line 31

Quoted 2 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +2 -0
+#define SKY1_MUX_SHIFT         (0x7)
+#define SKY1_PULLCONF_MASK     (0x60)

Same idea here.

drivers/pinctrl/cix/pinctrl-sky1-base.c line 33

Quoted 2 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +2 -0
+#define SKY1_PULLUP_SHIFT      (0x6)
+#define SKY1_PULLDN_SHIFT      (0x5)

I would probably do this:

#include <linus/bits.h>

#define SKY1_PULLDN BIT(5)
#define SKY1_PULLUP BIT(6)

Using simple bit references to define what each bit is for.

drivers/pinctrl/cix/pinctrl-sky1-base.c line 34

Quoted 1 line
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +1 -0
+#define SKY1_DS_MASK           (0x0f)

Use GENMASK()

drivers/pinctrl/cix/pinctrl-sky1-base.c line 37

Quoted 2 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +2 -0
+#define CIX_GET_PIN_NO(x) ((x) >> 8)
+#define CIX_GET_PIN_FUNC(x) ((x) & 0xf)

Maybe define 8 and 0xf as shifts?

drivers/pinctrl/cix/pinctrl-sky1-base.c line 53

Quoted 11 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +11 -0
+static const struct sky1_function_desc *sky1_pctrl_find_function_by_pin(
+               struct sky1_pinctrl *spctl, u32 pin_num, u32 fnum)
+{
+       const struct sky1_pin_desc *pin = spctl->info->pins + pin_num;
+       const struct sky1_function_desc *func = pin->functions;
+
+       while (func && func->name) {
+               if (func->muxval == fnum)
+                       return func;
+               func++;
+       }

Using a NULL func->name to terminate the array looks a bit dangerous.

What about adding:

drivers/pinctrl/cix/pinctrl-sky1.h line 11

Quoted 3 lines
drivers/pinctrl/cix/pinctrl-sky1.h new file +3 -0
+struct sky1_function_desc {
+       unsigned char muxval;
+       const char *name;

const char * const *functions;
size_t nfuncs;

Review line 51

Quoted 1 line
(quoted diff) +1 -0
+};

Then you can use nfuncs to iterate over the array of function names, and define a macro like this:

#define SKY_PINFUNCTION(_muxval, _functions, _nfunctions) \

(struct sky1_function_desc) {                                  \
                .muxval = (muxval),                        \
                .functions = (_functions),                    \
                .nfuncs = (_nfunctions),                  \
        }

And then this:

+static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {

drivers/pinctrl/cix/pinctrl-sky1.c line 28

Quoted 13 lines
drivers/pinctrl/cix/pinctrl-sky1.c new file +12 -0
+       {
+               .pin = PINCTRL_PIN(0, "GPIO1"),
+               .functions = {
+                       [0] = {0, "GPIO1"},
+               },
+       },
+       {
+               .pin = PINCTRL_PIN(1, "GPIO2"),
+               .functions = {
+                       [0] = {0, "GPIO2"},
+               },
 
+       },

becomes

static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
    SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"),  "GPIO1", 1),
    SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"),  "GPIO2", 1),

I don't know about using the PINCTRL_PIN() macro here though, can't you just put in 0, 1...?

Anyway I think you get the idea.

drivers/pinctrl/cix/pinctrl-sky1-base.c line 70

Quoted 13 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +13 -0
+static bool sky1_pctrl_is_function_valid(struct sky1_pinctrl *spctl,
+               u32 pin_num, u32 fnum)
+{
+       int i;
+
+       for (i = 0; i < spctl->info->npins; i++) {
+               const struct sky1_pin_desc *pin = spctl->info->pins + i;
+
+               if (pin->pin.number == pin_num) {
+                       const struct sky1_function_desc *func =
+                                       pin->functions;
+
+                       while (func && func->name) {

So here you could just for (i = 0; i++; i < func->nfuncs)

(etc everywhere)

Quoted 31 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +31 -0
+static int sky1_pctrl_dt_node_to_map_func(struct sky1_pinctrl *spctl,
+               u32 pin, u32 fnum, struct sky1_pinctrl_group *grp,
+               struct pinctrl_map **map, unsigned int *reserved_maps,
+               unsigned int *num_maps)
+{
+       bool ret;
+
+       if (*num_maps == *reserved_maps)
+               return -ENOSPC;
+
+       (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
+       (*map)[*num_maps].data.mux.group = grp->name;
+
+       ret = sky1_pctrl_is_function_valid(spctl, pin, fnum);
+       if (!ret) {
+               dev_err(spctl->dev, "invalid function %d on pin %d .\n",
+                               fnum, pin);
+               return -EINVAL;
+       }
+
+       (*map)[*num_maps].data.mux.function = sky1_gpio_functions[fnum];
+       (*num_maps)++;
+
+       return 0;
+}
+
+static struct sky1_pinctrl_group *
+sky1_pctrl_find_group_by_pin(struct sky1_pinctrl *spctl, u32 pin)
+{
+       int i;
+

drivers/pinctrl/cix/pinctrl-sky1-base.c line 123

Quoted 10 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +10 -0
+       for (i = 0; i < spctl->info->npins; i++) {
+               struct sky1_pinctrl_group *grp =
+                       (struct sky1_pinctrl_group *)spctl->groups + i;
+
+               if (grp->pin == pin)
+                       return grp;
+       }
+
+       return NULL;
+}

And this:

drivers/pinctrl/cix/pinctrl-sky1.h line 18

Quoted 5 lines
drivers/pinctrl/cix/pinctrl-sky1.h new file +5 -0
+struct sky1_pinctrl_group {
+       const char *name;
+       unsigned long config;
+       unsigned int pin;
+};

it's a bit conceptually weird.

Usually a pin can be member of many groups.

The only time this works is when the pin controller is of the type where every pin is placed in a single group with only that pin in it.

And that seems to be the case, because:

drivers/pinctrl/cix/pinctrl-sky1-base.c line 259

Quoted 6 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +6 -0
+static int sky1_pctrl_get_groups_count(struct pinctrl_dev *pctldev)
+{
+       struct sky1_pinctrl *spctl = pinctrl_dev_get_drvdata(pctldev);
+
+       return spctl->info->npins;
+}

If this is the implied pattern for this driver, write as a comment to the above function that this pin controller place all pins into a single group with one pin and that this is why this works.

The normal (as can be seen from the pin control documentation
https://docs.kernel.org/driver-api/pin-control.html ) is to group pins, so e.g.

uart0_rx_tx_grp = { pin1, pin2 };
i2c0_sda_scl_grp = { pin1, pin2 };

Then this is combined with functions such as uart0 and i2c0:

function, group
("uart0", uart0_rx_tx_grp)
("i2c0", i2c0_sda_scl_grp)

Here you see the two pins are used for uart in the first case and for i2c in the second case, it's the same pins, but members of two different groups, and these groups are then used with a function.

The possible functions for a group are then defined somewhere so these settings can be applied.

Maybe this pattern is something you have in your driver because the code was copied from some other driver which use one group per pin, it's not certain that this is the best layout for the cix SoC so look it over!

The pinconf part of the driver looks very good to me.

Look over these things, and keep posting updates!

Yours,
Linus Walleij

author maintainer
#3 lore raw

回复: [v2 1/3] pinctrl: cix: Add pin-controller support for sky1

Hi Linus

Thanks for your review and suggestions below

Quoted 4 lines

EXTERNAL EMAIL

Hi Gary,

Quoted 9 lines

thanks for your patch!

Quoted 2 lines · Gary Yang

Add the pin-controller driver for Sky1 platform

Add some more description of the pin control on the SoC here please.

OK, we will add more description as following, How about it?

The pin-controller is used to control Soc pins. It contains two parts: pinmux and pinconfig. Pinmux is used to select pin function and pinconfig is used to configure pin. It includes Pull-up,pull-down,and drive strength. There are two pin-controllers on Cix Sky1 platform. one is used under S0 state, the other one is used under S0 and S5 state.

Quoted 37 lines
Quoted 1 line

(...)

Config structure in Kconfig looks good!

Quoted 19 lines

+++ b/drivers/pinctrl/cix/pinctrl-sky1-base.c

drivers/pinctrl/cix/pinctrl-sky1-base.c new file +17 -0
@@ -0,0 +1,581 @@
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Author: Jerry Zhu <[email protected]>
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_address.h>
+#include <linux/pinctrl/machine.h>
+#include <linux/pinctrl/pinconf.h>
+#include <linux/pinctrl/pinconf-generic.h> #include
+<linux/pinctrl/pinctrl.h> #include <linux/pinctrl/pinmux.h> #include
+<linux/platform_device.h> #include <linux/seq_file.h> #include

drivers/pinctrl/cix/pinctrl-sky1-base.c line 27

Quoted 10 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +10 -0
+<linux/slab.h>
+
+#include "../core.h"
+#include "../pinconf.h"
+#include "../pinctrl-utils.h"
+#include "../pinmux.h"
+#include "pinctrl-sky1.h"
+
+#define SKY1_PIN_SIZE          (0x4)
+#define SKY1_MUX_MASK          (0x180)

For masks do this:

Quoted 7 lines

#include <linux/bits.h>

#define SKY1_MUX_MASK GENMASK(8, 7)

GENMASK generates a bitmask from bit 7 to 8, 0x180.

If its a 32bit register you can use GENMASK_U32() to be even clearer, etc.

Yes, it looks better. I agree this change

Quoted 5 lines

drivers/pinctrl/cix/pinctrl-sky1-base.c line 31

Quoted 3 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +2 -0
+#define SKY1_MUX_SHIFT         (0x7)
+#define SKY1_PULLCONF_MASK     (0x60)

Same idea here.

Same things

Quoted 6 lines

drivers/pinctrl/cix/pinctrl-sky1-base.c line 33

Quoted 3 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +2 -0
+#define SKY1_PULLUP_SHIFT      (0x6)
+#define SKY1_PULLDN_SHIFT      (0x5)

I would probably do this:

Quoted 7 lines

#include <linus/bits.h>

#define SKY1_PULLDN BIT(5)
#define SKY1_PULLUP BIT(6)

Using simple bit references to define what each bit is for.

Same things

Quoted 4 lines

drivers/pinctrl/cix/pinctrl-sky1-base.c line 34

Quoted 1 line
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +1 -0
+#define SKY1_DS_MASK           (0x0f)

Use GENMASK()

Same things

Quoted 5 lines

drivers/pinctrl/cix/pinctrl-sky1-base.c line 37

Quoted 2 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +2 -0
+#define CIX_GET_PIN_NO(x) ((x) >> 8)
+#define CIX_GET_PIN_FUNC(x) ((x) & 0xf)

Maybe define 8 and 0xf as shifts?

Same things

Quoted 13 lines

drivers/pinctrl/cix/pinctrl-sky1-base.c line 53

Quoted 10 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +10 -0
+static const struct sky1_function_desc *sky1_pctrl_find_function_by_pin(
+               struct sky1_pinctrl *spctl, u32 pin_num, u32 fnum) {
+       const struct sky1_pin_desc *pin = spctl->info->pins + pin_num;
+       const struct sky1_function_desc *func = pin->functions;
+
+       while (func && func->name) {
+               if (func->muxval == fnum)
+                       return func;
+               func++;
+       }

Using a NULL func->name to terminate the array looks a bit dangerous.

Quoted 10 lines

What about adding:

drivers/pinctrl/cix/pinctrl-sky1.h line 11

Quoted 3 lines
drivers/pinctrl/cix/pinctrl-sky1.h new file +3 -0
+struct sky1_function_desc {
+       unsigned char muxval;
+       const char *name;

const char * const *functions;
size_t nfuncs;

Quoted 1 line
(quoted diff) +1 -0
+};

First, I understand your thinkings. please pay some attention to the type of func->name, it's a pointer,

Checking whether this pointer is a null pointer is generally acceptable. A name maps to a mux value.

I think that it is safe. Of course, your suggestion is also a good idea. If you think this is not safe, we will

change codes as your suggestions.

Quoted 30 lines

Then you can use nfuncs to iterate over the array of function names, and define a macro like this:

#define SKY_PINFUNCTION(_muxval, _functions, _nfunctions) \

(struct sky1_function_desc) {                                  \
                .muxval = (muxval),                        \
                .functions = (_functions),                    \
                .nfuncs = (_nfunctions),                  \
        }

And then this:

+static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {

drivers/pinctrl/cix/pinctrl-sky1.c line 28

Quoted 13 lines
drivers/pinctrl/cix/pinctrl-sky1.c new file +12 -0
+       {
+               .pin = PINCTRL_PIN(0, "GPIO1"),
+               .functions = {
+                       [0] = {0, "GPIO1"},
+               },
+       },
+       {
+               .pin = PINCTRL_PIN(1, "GPIO2"),
+               .functions = {
+                       [0] = {0, "GPIO2"},
+               },
 
+       },

becomes

Quoted 9 lines
static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
    SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"),  "GPIO1", 1),
    SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"),  "GPIO2", 1),

I don't know about using the PINCTRL_PIN() macro here though, can't you just put in 0, 1...?

Anyway I think you get the idea.

First, let us review the struct sky1_pin_desc, it contains two members, one is the struct pinctrl_pin_desc.

struct pinctrl_pin_desc {
        unsigned int number;
        const char *name;
        void *drv_data;
};

PINCTRL_PIN is used to initialize this struct in kernel. It locates in include/linux/pinctrl/pinctrl.h

#define PINCTRL_PIN(a, b) { .number = a, .name = b }

PINCTRL_PIN(0, "GPIO1") defines a pin, its number is 0, its name is "GPIO1".

Second, I ever think that use SKY_PINFUNCTION macro to define pins, when a pin has serval functions,

more than one function, we need define a function array for the pin and then pass the array to

SKY_PINFUNCTION. Maybe it doesn't save anything, it takes more time in reading these codes to understand.

What's your opinion?

Quoted 103 lines

drivers/pinctrl/cix/pinctrl-sky1-base.c line 70

Quoted 13 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +13 -0
+static bool sky1_pctrl_is_function_valid(struct sky1_pinctrl *spctl,
+               u32 pin_num, u32 fnum) {
+       int i;
+
+       for (i = 0; i < spctl->info->npins; i++) {
+               const struct sky1_pin_desc *pin = spctl->info->pins +
+ i;
+
+               if (pin->pin.number == pin_num) {
+                       const struct sky1_function_desc *func =
+                                       pin->functions;
+
+                       while (func && func->name) {

So here you could just for (i = 0; i++; i < func->nfuncs)

(etc everywhere)

Quoted 10 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +10 -0
+static int sky1_pctrl_dt_node_to_map_func(struct sky1_pinctrl *spctl,
+               u32 pin, u32 fnum, struct sky1_pinctrl_group *grp,
+               struct pinctrl_map **map, unsigned int *reserved_maps,
+               unsigned int *num_maps) {
+       bool ret;
+
+       if (*num_maps == *reserved_maps)
+               return -ENOSPC;
+
+       (*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;

drivers/pinctrl/cix/pinctrl-sky1-base.c

Quoted 10 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +10 -0
+       (*map)[*num_maps].data.mux.group = grp->name;
+
+       ret = sky1_pctrl_is_function_valid(spctl, pin, fnum);
+       if (!ret) {
+               dev_err(spctl->dev, "invalid function %d on pin %d .\n",
+                               fnum, pin);
+               return -EINVAL;
+       }
+
+       (*map)[*num_maps].data.mux.function =

sky1_gpio_functions[fnum];

Quoted 10 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +10 -0
+       (*num_maps)++;
+
+       return 0;
+}
+
+static struct sky1_pinctrl_group *
+sky1_pctrl_find_group_by_pin(struct sky1_pinctrl *spctl, u32 pin) {
+       int i;
+
+       for (i = 0; i < spctl->info->npins; i++) {

drivers/pinctrl/cix/pinctrl-sky1-base.c line 123

Quoted 10 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +10 -0
+               struct sky1_pinctrl_group *grp =
+                       (struct sky1_pinctrl_group *)spctl->groups +
+ i;
+
+               if (grp->pin == pin)
+                       return grp;
+       }
+
+       return NULL;
+}

And this:

drivers/pinctrl/cix/pinctrl-sky1.h line 18

Quoted 5 lines
drivers/pinctrl/cix/pinctrl-sky1.h new file +5 -0
+struct sky1_pinctrl_group {
+       const char *name;
+       unsigned long config;
+       unsigned int pin;
+};

it's a bit conceptually weird.

Usually a pin can be member of many groups.

The only time this works is when the pin controller is of the type where every pin is placed in a single group with only that pin in it.

And that seems to be the case, because:

drivers/pinctrl/cix/pinctrl-sky1-base.c line 259

Quoted 5 lines
drivers/pinctrl/cix/pinctrl-sky1-base.c new file +5 -0
+static int sky1_pctrl_get_groups_count(struct pinctrl_dev *pctldev) {
+       struct sky1_pinctrl *spctl = pinctrl_dev_get_drvdata(pctldev);
+
+       return spctl->info->npins;
+}

If this is the implied pattern for this driver, write as a comment to the above function that this pin controller place all pins into a single group with one pin and that this is why this works.

The normal (as can be seen from the pin control documentation
https://docs.kernel.org/driver-api/pin-control.html ) is to group pins, so e.g.

uart0_rx_tx_grp = { pin1, pin2 };
i2c0_sda_scl_grp = { pin1, pin2 };

Then this is combined with functions such as uart0 and i2c0:

function, group
("uart0", uart0_rx_tx_grp)
("i2c0", i2c0_sda_scl_grp)

Here you see the two pins are used for uart in the first case and for i2c in the second case, it's the same pins, but members of two different groups, and these groups are then used with a function.

Quoted 7 lines

The possible functions for a group are then defined somewhere so these settings can be applied.

Maybe this pattern is something you have in your driver because the code was copied from some other driver which use one group per pin, it's not certain that this is the best layout for the cix SoC so look it over!

First maybe you ignore that fact the struct sky1_pinctrl_group is different from

the struct group_desc. It only saves the config of a pin from dts. it doesn't include

pin function part. As we know, a pin only has a config at the same time. One group map to a pin.

The pin function part is included in the struct sky1_function_desc. One pin can map

serval functions. There are four functions on sky1. We define the sky1_gpio_functions array.

It is used to select the pin functions.

Second, you are right. the pinctrl driver support new scheme is seldom in kernel. You take mt723 as

an example before. Some codes come from the pinctrl driver on MTK. We modify them to adopt our platform.

If I misunderstand or miss anything, please let me know.

Quoted 6 lines

The pinconf part of the driver looks very good to me.

Look over these things, and keep posting updates!

Yours,
Linus Walleij

Best wishes
Gary

#4 lore raw

Re: [v2 1/3] pinctrl: cix: Add pin-controller support for sky1

Quoted 5 lines · Gary Yang
Quoted 1 line

Using a NULL func->name to terminate the array looks a bit dangerous.

Checking whether this pointer is a null pointer is generally acceptable. A name maps to a mux value. I think that it is safe. Of course, your suggestion is also a good idea. If you think this is not safe, we will change codes as your suggestions.

It's OK just a suggestion. There are many ways to do this, first fix other problems.

There are things in the language and the kernel that can help you to check boundaries of arrays such as these functions so you can't write code that index out of range, e.g.

+struct sky1_pin_desc {
+ const struct pinctrl_pin_desc pin;
+ const struct sky1_function_desc functions[4];
+};
+
+struct sky1_pinctrl_soc_info {
+ const struct sky1_pin_desc *pins;
+ unsigned int npins;
+};

It is possible to use a flexible array with the intrinsic __counted by() here, e.g. instead of:

struct sky1_pin_desc {
     const struct pinctrl_pin_desc pin;
     const struct sky1_function_desc functions[4];

You can use:

+ size_t nfunctions;
+ const struct sky1_function_desc functions[] __counted_by(nfunctions);

If you grep counted_by in the kernel you find many other examples of how we use this.

But flexible arrays is a bit complicated and dangerous so maybe you want to avoid it altogether. Also I'm not sure it works when you put things containing a flexible array into another array... I never tried it.

Quoted 47 lines
Quoted 29 lines

Then you can use nfuncs to iterate over the array of function names, and define a macro like this:

#define SKY_PINFUNCTION(_muxval, _functions, _nfunctions) \

(struct sky1_function_desc) {                                  \
                .muxval = (muxval),                        \
                .functions = (_functions),                    \
                .nfuncs = (_nfunctions),                  \
        }

And then this:

+static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {

drivers/pinctrl/cix/pinctrl-sky1.c line 28

Quoted 13 lines
drivers/pinctrl/cix/pinctrl-sky1.c new file +12 -0
+       {
+               .pin = PINCTRL_PIN(0, "GPIO1"),
+               .functions = {
+                       [0] = {0, "GPIO1"},
+               },
+       },
+       {
+               .pin = PINCTRL_PIN(1, "GPIO2"),
+               .functions = {
+                       [0] = {0, "GPIO2"},
+               },
 
+       },

becomes

Quoted 9 lines
static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
    SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"),  "GPIO1", 1),
    SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"),  "GPIO2", 1),

I don't know about using the PINCTRL_PIN() macro here though, can't you just put in 0, 1...?

Anyway I think you get the idea.

First, let us review the struct sky1_pin_desc, it contains two members, one is the struct pinctrl_pin_desc.

struct pinctrl_pin_desc {
        unsigned int number;
        const char *name;
        void *drv_data;
};
Quoted 5 lines

PINCTRL_PIN is used to initialize this struct in kernel. It locates in include/linux/pinctrl/pinctrl.h

#define PINCTRL_PIN(a, b) { .number = a, .name = b }

PINCTRL_PIN(0, "GPIO1") defines a pin, its number is 0, its name is "GPIO1".

Ah I saw it wrong, sorry :(

You're right about this of course.

But I think you can still use a macro to define the long pin tables? Albeit macros with flexible arguments is a bit hard to write. Save it until everything else is working.

Quoted 34 lines
Quoted 20 lines

If this is the implied pattern for this driver, write as a comment to the above function that this pin controller place all pins into a single group with one pin and that this is why this works.

The normal (as can be seen from the pin control documentation
https://docs.kernel.org/driver-api/pin-control.html ) is to group pins, so e.g.

uart0_rx_tx_grp = { pin1, pin2 };
i2c0_sda_scl_grp = { pin1, pin2 };

Then this is combined with functions such as uart0 and i2c0:

function, group
("uart0", uart0_rx_tx_grp)
("i2c0", i2c0_sda_scl_grp)

Here you see the two pins are used for uart in the first case and for i2c in the second case, it's the same pins, but members of two different groups, and these groups are then used with a function.

Quoted 6 lines

The possible functions for a group are then defined somewhere so these settings can be applied.

Maybe this pattern is something you have in your driver because the code was copied from some other driver which use one group per pin, it's not certain that this is the best layout for the cix SoC so look it over!

First maybe you ignore that fact the struct sky1_pinctrl_group is different from the struct group_desc. It only saves the config of a pin from dts. it doesn't include pin function part. As we know, a pin only has a config at the same time. One group map to a pin. The pin function part is included in the struct sky1_function_desc. One pin can map serval functions. There are four functions on sky1. We define the sky1_gpio_functions array. It is used to select the pin functions.

Quoted 3 lines

Second, you are right. the pinctrl driver support new scheme is seldom in kernel. You take mt723 as an example before. Some codes come from the pinctrl driver on MTK. We modify them to adopt our platform. If I misunderstand or miss anything, please let me know.

Yes I can see that the driver is based on the MTK driver, my point is that make sure you are not following it too closely, because what is good for the mtk chips is not necessarily good for the cix chips.

But if you feel convenient with one group per pin and you are convinced this is the best for your driver, go ahead with this scheme!

Yours,
Linus Walleij

author maintainer
#5 lore raw

回复: [v2 1/3] pinctrl: cix: Add pin-controller support for sky1

Hi Linus,

Thanks for your kind comments

Sorry for delay reply

Quoted 39 lines

EXTERNAL EMAIL

Quoted 3 lines · Gary Yang
Quoted 1 line

Using a NULL func->name to terminate the array looks a bit dangerous.

Checking whether this pointer is a null pointer is generally acceptable. A

name maps to a mux value.

Quoted 2 lines

I think that it is safe. Of course, your suggestion is also a good idea. If you think this is not safe, we will change codes as your suggestions.

It's OK just a suggestion. There are many ways to do this, first fix other problems.

There are things in the language and the kernel that can help you to check boundaries of arrays such as these functions so you can't write code that index out of range, e.g.

drivers/pinctrl/cix/pinctrl-sky1.h new file +8 -0
+struct sky1_pin_desc {
+       const struct pinctrl_pin_desc pin;
+       const struct sky1_function_desc functions[4]; };
+
+struct sky1_pinctrl_soc_info {
+       const struct sky1_pin_desc *pins;
+       unsigned int npins;
+};

It is possible to use a flexible array with the intrinsic __counted by() here, e.g. instead of:

struct sky1_pin_desc {
     const struct pinctrl_pin_desc pin;
     const struct sky1_function_desc functions[4];

You can use:

+ size_t nfunctions;
+ const struct sky1_function_desc functions[] __counted_by(nfunctions);

Quoted 7 lines

If you grep counted_by in the kernel you find many other examples of how we use this.

But flexible arrays is a bit complicated and dangerous so maybe you want to avoid it altogether. Also I'm not sure it works when you put things containing a flexible array into another array... I never tried it.

Thanks for your good idea. We will have a try. Only need take some time to debug it.

Quoted 102 lines
Quoted 33 lines
Quoted 33 lines

Then you can use nfuncs to iterate over the array of function names, and define a macro like this:

#define SKY_PINFUNCTION(_muxval, _functions, _nfunctions) \

(struct sky1_function_desc) {                                  \
                .muxval = (muxval),                        \
                .functions = (_functions),                    \
                .nfuncs = (_nfunctions),                  \
        }

And then this:

+static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {

drivers/pinctrl/cix/pinctrl-sky1.c line 28

Quoted 13 lines
drivers/pinctrl/cix/pinctrl-sky1.c new file +12 -0
+       {
+               .pin = PINCTRL_PIN(0, "GPIO1"),
+               .functions = {
+                       [0] = {0, "GPIO1"},
+               },
+       },
+       {
+               .pin = PINCTRL_PIN(1, "GPIO2"),
+               .functions = {
+                       [0] = {0, "GPIO2"},
+               },
 
+       },

becomes

static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
    SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"),  "GPIO1", 1),
    SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"),  "GPIO2", 1),
Quoted 7 lines
Quoted 5 lines

I don't know about using the PINCTRL_PIN() macro here though, can't you just put in 0, 1...?

Anyway I think you get the idea.

First, let us review the struct sky1_pin_desc, it contains two members, one is

the struct pinctrl_pin_desc.

Quoted 7 lines
struct pinctrl_pin_desc {
        unsigned int number;
        const char *name;
        void *drv_data;
};
Quoted 6 lines

PINCTRL_PIN is used to initialize this struct in kernel. It locates in include/linux/pinctrl/pinctrl.h

#define PINCTRL_PIN(a, b) { .number = a, .name = b }

PINCTRL_PIN(0, "GPIO1") defines a pin, its number is 0, its name is "GPIO1".

Ah I saw it wrong, sorry :(

You're right about this of course.

But I think you can still use a macro to define the long pin tables? Albeit macros with flexible arguments is a bit hard to write. Save it until everything else is working.

Quoted 23 lines
Quoted 23 lines

If this is the implied pattern for this driver, write as a comment to the above function that this pin controller place all pins into a single group with one pin and that this is why this works.

The normal (as can be seen from the pin control documentation
https://docs.kernel.org/driver-api/pin-control.html ) is to group pins, so e.g.

uart0_rx_tx_grp = { pin1, pin2 };
i2c0_sda_scl_grp = { pin1, pin2 };

Then this is combined with functions such as uart0 and i2c0:

function, group
("uart0", uart0_rx_tx_grp)
("i2c0", i2c0_sda_scl_grp)

Here you see the two pins are used for uart in the first case and for i2c in the second case, it's the same pins, but members of two different groups, and these groups are then used with a function.

The possible functions for a group are then defined somewhere so these settings can be applied.

Quoted 7 lines
Quoted 3 lines

Maybe this pattern is something you have in your driver because the code was copied from some other driver which use one group per pin, it's not certain that this is the best layout for the cix SoC so look it over!

First maybe you ignore that fact the struct sky1_pinctrl_group is different from the struct group_desc. It only saves the config of a pin from dts. it doesn't include pin function part. As we know, a pin only has

a config at the same time. One group map to a pin.

Quoted 2 lines

The pin function part is included in the struct sky1_function_desc. One pin can map serval functions. There are four functions on sky1. We

define the sky1_gpio_functions array.

Quoted 4 lines

It is used to select the pin functions.

Second, you are right. the pinctrl driver support new scheme is seldom in kernel. You take mt723 as an example before. Some codes come from the

pinctrl driver on MTK. We modify them to adopt our platform.

Quoted 9 lines
Quoted 1 line

If I misunderstand or miss anything, please let me know.

Yes I can see that the driver is based on the MTK driver, my point is that make sure you are not following it too closely, because what is good for the mtk chips is not necessarily good for the cix chips.

But if you feel convenient with one group per pin and you are convinced this is the best for your driver, go ahead with this scheme!

First thanks for your understanding. If I misunderstand anything, please kindly remind me.

I think the pinmux=<> scheme is different from sky1,pin=<> scheme.

In sky1,pin=<> scheme,It first parse the config in DTS in probe() and then create three radix trees. They are function tree, group tree, and pin tree. When apply setting, it finds the right group and right function via the name of dts node, and get the total pin number from group, and create map array, the first element maps to function. From second element, one element maps to a pinconfig. one pin only has one config at the same time.

In pinmux=<> scheme, the pdata Info includes all the pins and the valid functions. It doesn't need to parse the pin config in probe(). only when apply setting, it parses the pinconfig in DTS. It also creates map array, it gets the right function via func in DTS and the right pinconfig via API. So it also works ok.

Second, We will try to use macros to define our pins. Just need some time to verify it. Thanks

Quoted 2 lines

Yours,
Linus Walleij

Best wishes
Gary

author maintainer
#6 lore raw

回复: [v2 1/3] pinctrl: cix: Add pin-controller support for sky1

In reply to Linus Walleij

Hi Linus,

New scheme with macros has verified ok. I just want to confirm with you before submit codes

Quoted 101 lines

EXTERNAL EMAIL

Quoted 3 lines · Gary Yang
Quoted 1 line

Using a NULL func->name to terminate the array looks a bit dangerous.

Checking whether this pointer is a null pointer is generally acceptable. A

name maps to a mux value.

Quoted 2 lines

I think that it is safe. Of course, your suggestion is also a good idea. If you think this is not safe, we will change codes as your suggestions.

It's OK just a suggestion. There are many ways to do this, first fix other problems.

There are things in the language and the kernel that can help you to check boundaries of arrays such as these functions so you can't write code that index out of range, e.g.

drivers/pinctrl/cix/pinctrl-sky1.h new file +8 -0
+struct sky1_pin_desc {
+       const struct pinctrl_pin_desc pin;
+       const struct sky1_function_desc functions[4]; };
+
+struct sky1_pinctrl_soc_info {
+       const struct sky1_pin_desc *pins;
+       unsigned int npins;
+};

It is possible to use a flexible array with the intrinsic __counted by() here, e.g. instead of:

struct sky1_pin_desc {
     const struct pinctrl_pin_desc pin;
     const struct sky1_function_desc functions[4];

You can use:

+ size_t nfunctions;
+ const struct sky1_function_desc functions[] __counted_by(nfunctions);

If you grep counted_by in the kernel you find many other examples of how we use this.

But flexible arrays is a bit complicated and dangerous so maybe you want to avoid it altogether. Also I'm not sure it works when you put things containing a flexible array into another array... I never tried it.

Quoted 33 lines
Quoted 33 lines

Then you can use nfuncs to iterate over the array of function names, and define a macro like this:

#define SKY_PINFUNCTION(_muxval, _functions, _nfunctions) \

(struct sky1_function_desc) {                                  \
                .muxval = (muxval),                        \
                .functions = (_functions),                    \
                .nfuncs = (_nfunctions),                  \
        }

And then this:

+static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {

drivers/pinctrl/cix/pinctrl-sky1.c line 28

Quoted 13 lines
drivers/pinctrl/cix/pinctrl-sky1.c new file +12 -0
+       {
+               .pin = PINCTRL_PIN(0, "GPIO1"),
+               .functions = {
+                       [0] = {0, "GPIO1"},
+               },
+       },
+       {
+               .pin = PINCTRL_PIN(1, "GPIO2"),
+               .functions = {
+                       [0] = {0, "GPIO2"},
+               },
 
+       },

becomes

static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
    SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"),  "GPIO1", 1),
    SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"),  "GPIO2", 1),
Quoted 7 lines
Quoted 5 lines

I don't know about using the PINCTRL_PIN() macro here though, can't you just put in 0, 1...?

Anyway I think you get the idea.

First, let us review the struct sky1_pin_desc, it contains two members, one is

the struct pinctrl_pin_desc.

Quoted 7 lines
struct pinctrl_pin_desc {
        unsigned int number;
        const char *name;
        void *drv_data;
};
Quoted 6 lines

PINCTRL_PIN is used to initialize this struct in kernel. It locates in include/linux/pinctrl/pinctrl.h

#define PINCTRL_PIN(a, b) { .number = a, .name = b }

PINCTRL_PIN(0, "GPIO1") defines a pin, its number is 0, its name is "GPIO1".

Quoted 8 lines

Ah I saw it wrong, sorry :(

You're right about this of course.

But I think you can still use a macro to define the long pin tables? Albeit macros with flexible arguments is a bit hard to write. Save it until everything else is working.

In header file:

struct sky1_pin_desc {
        const struct pinctrl_pin_desc pin;
        const char **func_group;
        unsigned int nfunc;
};

#define SKY_PINFUNCTION(_pin, _func) \

 (struct sky1_pin_desc) {                                        \
                 .pin = _pin,                                    \
                 .func_group = _func##_group,                    \
                 .nfunc = ARRAY_SIZE(_func##_group),             \
         }

In C file:

static const char *gpio1_group[] = {"GPIO1"};
static const char *gpio2_group[] = {"GPIO2"};

static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
        SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"), gpio1),
        SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"), gpio2),
		.......
};

What's your suggestion? Thanks

Quoted 3 lines

Yours,
Linus Walleij

Best wishes
Gary

author maintainer
#7 lore raw

回复: [v2 1/3] pinctrl: cix: Add pin-controller support for sky1

Hi Linus,

Quoted 138 lines

New scheme with macros has verified ok. I just want to confirm with you before submit codes

Quoted 3 lines

EXTERNAL EMAIL

On Mon, Sep 15, 2025 at 9:09 AM Gary Yang <[email protected]>

Quoted 81 lines · wrote:
Quoted 5 lines
Quoted 2 lines

Using a NULL func->name to terminate the array looks a bit dangerous.

Checking whether this pointer is a null pointer is generally acceptable. A

name maps to a mux value.

Quoted 2 lines

I think that it is safe. Of course, your suggestion is also a good idea. If you think this is not safe, we will change codes as your suggestions.

It's OK just a suggestion. There are many ways to do this, first fix other problems.

There are things in the language and the kernel that can help you to check boundaries of arrays such as these functions so you can't write code that index out of range, e.g.

drivers/pinctrl/cix/pinctrl-sky1.h new file +8 -0
+struct sky1_pin_desc {
+       const struct pinctrl_pin_desc pin;
+       const struct sky1_function_desc functions[4]; };
+
+struct sky1_pinctrl_soc_info {
+       const struct sky1_pin_desc *pins;
+       unsigned int npins;
+};

It is possible to use a flexible array with the intrinsic __counted by() here, e.g. instead of:

struct sky1_pin_desc {
     const struct pinctrl_pin_desc pin;
     const struct sky1_function_desc functions[4];

You can use:

+ size_t nfunctions;
+ const struct sky1_function_desc functions[]
+ __counted_by(nfunctions);

If you grep counted_by in the kernel you find many other examples of how we use this.

But flexible arrays is a bit complicated and dangerous so maybe you want to avoid it altogether. Also I'm not sure it works when you put things containing a flexible array into another array... I never tried it.

Quoted 36 lines
Quoted 36 lines

Then you can use nfuncs to iterate over the array of function names, and define a macro like this:

#define SKY_PINFUNCTION(_muxval, _functions, _nfunctions) \

(struct sky1_function_desc) {                                  \
                .muxval = (muxval),                        \
                .functions = (_functions),                    \
                .nfuncs = (_nfunctions),                  \
        }

And then this:

+static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {

drivers/pinctrl/cix/pinctrl-sky1.c line 28

Quoted 13 lines
drivers/pinctrl/cix/pinctrl-sky1.c new file +12 -0
+       {
+               .pin = PINCTRL_PIN(0, "GPIO1"),
+               .functions = {
+                       [0] = {0, "GPIO1"},
+               },
+       },
+       {
+               .pin = PINCTRL_PIN(1, "GPIO2"),
+               .functions = {
+                       [0] = {0, "GPIO2"},
+               },
 
+       },

becomes

static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
    SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"),  "GPIO1", 1),
    SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"),  "GPIO2", 1),

I don't know about using the PINCTRL_PIN() macro here though, can't you just put in 0, 1...?

Quoted 19 lines
Quoted 5 lines
Quoted 2 lines

Anyway I think you get the idea.

First, let us review the struct sky1_pin_desc, it contains two members, one is

the struct pinctrl_pin_desc.

Quoted 13 lines
struct pinctrl_pin_desc {
        unsigned int number;
        const char *name;
        void *drv_data;
};

PINCTRL_PIN is used to initialize this struct in kernel. It locates in include/linux/pinctrl/pinctrl.h

#define PINCTRL_PIN(a, b) { .number = a, .name = b }

PINCTRL_PIN(0, "GPIO1") defines a pin, its number is 0, its name is

"GPIO1".

Quoted 9 lines

Ah I saw it wrong, sorry :(

You're right about this of course.

But I think you can still use a macro to define the long pin tables? Albeit macros with flexible arguments is a bit hard to write. Save it until everything else is working.

In header file:

struct sky1_pin_desc {
        const struct pinctrl_pin_desc pin;
        const char **func_group;
        unsigned int nfunc;
};

#define SKY_PINFUNCTION(_pin, _func) \

 (struct sky1_pin_desc) {                                        \
                 .pin = _pin,                                    \
                 .func_group = _func##_group,                    \
                 .nfunc = ARRAY_SIZE(_func##_group),             \
         }

In C file:

static const char *gpio1_group[] = {"GPIO1"}; static const char *gpio2_group[] = {"GPIO2"};

Quoted 8 lines
static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
        SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"), gpio1),
        SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"), gpio2),
		.......
};

What's your suggestion? Thanks

Ping....

Quoted 4 lines
Quoted 3 lines

Yours,
Linus Walleij

Best wishes
Gary

#8 lore raw

Re: [v2 1/3] pinctrl: cix: Add pin-controller support for sky1

In reply to Gary Yang

Hi Gary,

thanks for your efforts!

Sorry for taking so much time to respond. I was coding.

Quoted 1 line · Gary Yang

New scheme with macros has verified ok. I just want to confirm with you before submit codes

No need to confirm with me just post it!
Better one post too much than one too little.

Quoted 24 lines
Quoted 4 lines

But I think you can still use a macro to define the long pin tables? Albeit macros with flexible arguments is a bit hard to write. Save it until everything else is working.

In header file:

struct sky1_pin_desc {
        const struct pinctrl_pin_desc pin;
        const char **func_group;
        unsigned int nfunc;
};

#define SKY_PINFUNCTION(_pin, _func) \

 (struct sky1_pin_desc) {                                        \
                 .pin = _pin,                                    \
                 .func_group = _func##_group,                    \
                 .nfunc = ARRAY_SIZE(_func##_group),             \
         }

In C file:

static const char *gpio1_group[] = {"GPIO1"};
static const char *gpio2_group[] = {"GPIO2"};

Quoted 7 lines
static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
        SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"), gpio1),
        SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"), gpio2),
                .......
};

What's your suggestion? Thanks

It's OK as-is if this is how you want to structure things!

Yours,
Linus Walleij

author maintainer
#9 lore raw

回复: [v2 1/3] pinctrl: cix: Add pin-controller support for sky1

Hi Linus:

I'm glad to receive your reply.

Quoted 8 lines

EXTERNAL EMAIL

Hi Gary,

thanks for your efforts!

Sorry for taking so much time to respond. I was coding.

Quoted 8 lines
Quoted 2 lines · Gary Yang

New scheme with macros has verified ok. I just want to confirm with you before submit codes

No need to confirm with me just post it!
Better one post too much than one too little.

Ok, We will post the next version as soon as possible.

Quoted 30 lines
Quoted 30 lines
Quoted 4 lines

But I think you can still use a macro to define the long pin tables? Albeit macros with flexible arguments is a bit hard to write. Save it until everything else is working.

In header file:

struct sky1_pin_desc {
        const struct pinctrl_pin_desc pin;
        const char **func_group;
        unsigned int nfunc;
};

#define SKY_PINFUNCTION(_pin, _func) \

 (struct sky1_pin_desc) {                                        \
                 .pin = _pin,                                    \
                 .func_group = _func##_group,                    \
                 .nfunc = ARRAY_SIZE(_func##_group),             \
         }

In C file:

static const char *gpio1_group[] = {"GPIO1"}; static const char *gpio2_group[] = {"GPIO2"};

static const struct sky1_pin_desc sky1_pinctrl_s5_pads[] = {
        SKY_PINFUNCTION(PINCTRL_PIN(0, "GPIO1"), gpio1),
        SKY_PINFUNCTION(PINCTRL_PIN(1, "GPIO2"), gpio2),
                .......
};
Quoted 4 lines
Quoted 1 line

What's your suggestion? Thanks

It's OK as-is if this is how you want to structure things!

Thanks for your understanding. We will adopt this scheme in next version.

Quoted 2 lines

Yours,
Linus Walleij

Best wishes
Gary

author maintainer
#10 lore raw

PATCH v2 2/3 dt-bindings: pinctrl: Add cix,sky1-pinctrl

In reply to Gary Yang

The pin-controller is used to control the Soc pins. There are two pin-controllers on Cix Sky1 platform. One is used under S0 state, the other is used under S5 state.

---
 .../bindings/pinctrl/cix,sky1-pinctrl.yaml    | 85 +++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +85 -0
new file mode 100644
index 000000000000..c4a127fd8330
@@ -0,0 +1,85 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/cix,sky1-pinctrl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cix Sky1 Pin Controller
+
+maintainers:
+  - Gary Yang <[email protected]>
+
+description:
+  The pin-controller is used to control Soc pins. There are two pin-controllers
+  on Cix Sky1 platform. one is used under S0 state, the other one is used under
+  S5 state.
+
+properties:
+  compatible:
+    enum:
+      - cix,sky1-iomuxc
+      - cix,sky1-iomuxc-s5
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+# Client device subnode's properties
+patternProperties:
+  'pins$':
+    type: object
+    additionalProperties: false
+    patternProperties:
+      '(^pins|pins?$)':
+        type: object
+        additionalProperties: false
+        description:
+          A pinctrl node should contain at least one subnodes representing the
+          pinctrl groups available on the machine. Each subnode will list the
+          pins it needs, and how they should be configured, with regard to muxer
+          configuration, pullups, and drive strength.
+        $ref: /schemas/pinctrl/pincfg-node.yaml
+
+        properties:
+          pinmux:
+            description:
+              Integer array, represents gpio pin number and mux setting.
+              Supported pin number and mux varies for different SoCs, and are
+              defined as macros in arch/arm64/boot/dts/cix/sky1-pinfunc.h directly.
+
+          bias-disable: true
+
+          bias-pull-up: true
+
+          bias-pull-down: true
+
+          drive-strength:
+            description:
+              Can support 15 levels, from DS_LEVEL1 to DS_LEVEL15.
+              See arch/arm64/boot/dts/cix/sky1-pinfunc.h for valid arguments.
+
+        required:
+          - pinmux
+
+additionalProperties: false
+
+examples:
+  # Pinmux controller node
+  - |
+    #define CIX_PAD_GPIO012_FUNC_GPIO012 (11 << 8 | 0x0)
+    #define DS_LEVEL4 (4)
+    iomuxc: pinctrl@4170000 {
+        compatible = "cix,sky1-iomuxc";
+        reg = <0x4170000 0x1000>;
+
+        wifi_vbat_gpio: wifi-vbat-gpio-pins {
+            pins-wifi-vbat-gpio {
+                pinmux = <CIX_PAD_GPIO012_FUNC_GPIO012>;
+                bias-pull-up;
+                drive-strength = <DS_LEVEL4>;
+           };
+        };
+    };
Signature · 1 line
2.49.0
#11 lore raw

Re: [v2 2/3] dt-bindings: pinctrl: Add cix,sky1-pinctrl

Hi Gary,

thanks for your patch!

Overall this is starting to look good.

Please make the bindings patch 1/3 because we usually put the bindings first.

Some comments below!

Quoted 6 lines · Gary Yang

The pin-controller is used to control the Soc pins. There are two pin-controllers on Cix Sky1 platform. One is used under S0 state, the other is used under S5 state.

(...)

Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +4 -0
+# Client device subnode's properties
+patternProperties:
+  'pins$':
+    type: object

Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml line 43

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +10 -0
+    additionalProperties: false
+    patternProperties:
+      '(^pins|pins?$)':
+        type: object
+        additionalProperties: false
+        description:
+          A pinctrl node should contain at least one subnodes representing the
+          pinctrl groups available on the machine. Each subnode will list the
+          pins it needs, and how they should be configured, with regard to muxer
+          configuration, pullups, and drive strength.

I'm not sure the binding maintainers want this info here, if the same is inside pincfg-node.yaml, I would just skip it.

Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml line 51

Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +8 -0
+        $ref: /schemas/pinctrl/pincfg-node.yaml
+
+        properties:
+          pinmux:
+            description:
+              Integer array, represents gpio pin number and mux setting.
+              Supported pin number and mux varies for different SoCs, and are
+              defined as macros in arch/arm64/boot/dts/cix/sky1-pinfunc.h directly.

No reference to arch/arm64 in the bindings please. Just drop this.

The bindings are used by U-Boot and FreeBSD as well so these developers will be confused by any Linux-specific references.

Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml line 62

Quoted 11 lines
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +11 -0
+
+          bias-disable: true
+
+          bias-pull-up: true
+
+          bias-pull-down: true
+
+          drive-strength:
+            description:
+              Can support 15 levels, from DS_LEVEL1 to DS_LEVEL15.
+              See arch/arm64/boot/dts/cix/sky1-pinfunc.h for valid arguments.

Same thing.

Quoted 13 lines
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +13 -0
+
+        required:
+          - pinmux
+
+additionalProperties: false
+
+examples:
+  # Pinmux controller node
+  - |
+    #define CIX_PAD_GPIO012_FUNC_GPIO012 (11 << 8 | 0x0)
+    #define DS_LEVEL4 (4)
+    iomuxc: pinctrl@4170000 {
+        compatible = "cix,sky1-iomuxc";

Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml line 85

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +10 -0
+        reg = <0x4170000 0x1000>;
+
+        wifi_vbat_gpio: wifi-vbat-gpio-pins {
+            pins-wifi-vbat-gpio {
+                pinmux = <CIX_PAD_GPIO012_FUNC_GPIO012>;
+                bias-pull-up;
+                drive-strength = <DS_LEVEL4>;
+           };
+        };
+    };

This looks good to me, I don't know if the bindings maintainers have opinions on the placement of defines in examples.

Yours,
Linus Walleij

maintainer
#12 lore raw

Re: [v2 2/3] dt-bindings: pinctrl: Add cix,sky1-pinctrl

In reply to Gary Yang
Quoted 4 lines · Gary Yang

The pin-controller is used to control the Soc pins. There are two pin-controllers on Cix Sky1 platform. One is used under S0 state, the other is used under S5 state.

Wrap lines at 72 chars.

Quoted 65 lines
---
 .../bindings/pinctrl/cix,sky1-pinctrl.yaml    | 85 +++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +52 -0
new file mode 100644
index 000000000000..c4a127fd8330
@@ -0,0 +1,85 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/cix,sky1-pinctrl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cix Sky1 Pin Controller
+
+maintainers:
+  - Gary Yang <[email protected]>
+
+description:
+  The pin-controller is used to control Soc pins. There are two pin-controllers
+  on Cix Sky1 platform. one is used under S0 state, the other one is used under
+  S5 state.
+
+properties:
+  compatible:
+    enum:
+      - cix,sky1-iomuxc
+      - cix,sky1-iomuxc-s5
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+# Client device subnode's properties
+patternProperties:
+  'pins$':
+    type: object
+    additionalProperties: false
+    patternProperties:
+      '(^pins|pins?$)':
+        type: object
+        additionalProperties: false
+        description:
+          A pinctrl node should contain at least one subnodes representing the
+          pinctrl groups available on the machine. Each subnode will list the
+          pins it needs, and how they should be configured, with regard to muxer
+          configuration, pullups, and drive strength.
+        $ref: /schemas/pinctrl/pincfg-node.yaml
+
+        properties:
+          pinmux:
+            description:
+              Integer array, represents gpio pin number and mux setting.
+              Supported pin number and mux varies for different SoCs, and are
+              defined as macros in arch/arm64/boot/dts/cix/sky1-pinfunc.h directly.
+

Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml line 62

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +10 -0
+          bias-disable: true
+
+          bias-pull-up: true
+
+          bias-pull-down: true
+
+          drive-strength:
+            description:
+              Can support 15 levels, from DS_LEVEL1 to DS_LEVEL15.
+              See arch/arm64/boot/dts/cix/sky1-pinfunc.h for valid arguments.

Constraints on the values?

Quoted 26 lines
Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml new file +23 -0
+
+        required:
+          - pinmux
+
+additionalProperties: false
+
+examples:
+  # Pinmux controller node
+  - |
+    #define CIX_PAD_GPIO012_FUNC_GPIO012 (11 << 8 | 0x0)
+    #define DS_LEVEL4 (4)
+    iomuxc: pinctrl@4170000 {
+        compatible = "cix,sky1-iomuxc";
+        reg = <0x4170000 0x1000>;
+
+        wifi_vbat_gpio: wifi-vbat-gpio-pins {
+            pins-wifi-vbat-gpio {
+                pinmux = <CIX_PAD_GPIO012_FUNC_GPIO012>;
+                bias-pull-up;
+                drive-strength = <DS_LEVEL4>;
+           };
+        };
+    };
Signature · 1 line
2.49.0
#13 lore raw

Re: [v2 2/3] dt-bindings: pinctrl: Add cix,sky1-pinctrl

In reply to Gary Yang
Quoted 11 lines · Gary Yang

The pin-controller is used to control the Soc pins. There are two pin-controllers on Cix Sky1 platform. One is used under S0 state, the other is used under S5 state.

---
 .../bindings/pinctrl/cix,sky1-pinctrl.yaml    | 85 +++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.example.dtb: wifi-vbat-gpio-pins: pins-wifi-vbat-gpio: {'pinmux': [2816], 'bias-pull-up': True, 'drive-strength': 4} is not of type 'array'
from schema $id: http://devicetree.org/schemas/gpio/gpio-consumer.yaml#

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

author maintainer
#14 lore raw

回复: [v2 2/3] dt-bindings: pinctrl: Add cix,sky1-pinctrl

Hi Rob,

Thanks for your comments

Quoted 39 lines · Gary Yang
Quoted 5 lines

The pin-controller is used to control the Soc pins. There are two pin-controllers on Cix Sky1 platform. One is used under S0 state, the other is used under S5 state.

Quoted 7 lines
---
 .../bindings/pinctrl/cix,sky1-pinctrl.yaml    | 85 +++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.yaml

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/pi nctrl/cix,sky1-pinctrl.example.dtb: wifi-vbat-gpio-pins: pins-wifi-vbat-gpio:
{'pinmux': [2816], 'bias-pull-up': True, 'drive-strength': 4} is not of type 'array'
from schema $id:
http://devicetree.org/schemas/gpio/gpio-consumer.yaml#

doc reference errors (make refcheckdocs):

See
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/2025091206
[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

Quoted 5 lines

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

As we know, must execute three commands before submit patches:
1) make O=$OUTKNL dt_binding_check DT_SCHEMA_FILES=pinctrl/cix,sky1-pinctrl.yaml
2) make CHECK_DTBS=y W=1 cix/sky1-orion-o6.dtb
3) ./scripts/checkpatch.pl 000*.patch
We don't submit any patch until no error or unexpected warning when execute three commands above.

As your suggestion, execute first command again after upgrade dtschema. But I don't see any error. See more details as following:

gary@gary-System-Product-Name:~/workspace/upstream/kernel_upstream$ make O=$OUTKNL dt_binding_check DT_SCHEMA_FILES=pinctrl/cix,sky1-pinctrl.yaml
  SCHEMA  Documentation/devicetree/bindings/processed-schema.json
  CHKDT   ./Documentation/devicetree/bindings
  LINT    ./Documentation/devicetree/bindings
  DTEX    Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.example.dts
  DTC [C] Documentation/devicetree/bindings/pinctrl/cix,sky1-pinctrl.example.dtb

If I misunderstand or miss any information, please kindly remind me. Thanks

Best wishes
Gary

author maintainer
#15 lore raw

PATCH v2 3/3 arm64: dts: cix: Add pinctrl nodes for sky1

In reply to Gary Yang

Add the pin-controller nodes for Sky1 platform.

---
 arch/arm64/boot/dts/cix/sky1-orion-o6.dts |  32 ++
 arch/arm64/boot/dts/cix/sky1-pinfunc.h    | 417 ++++++++++++++++++++++
 arch/arm64/boot/dts/cix/sky1.dtsi         |  10 +
 3 files changed, 459 insertions(+)
 create mode 100644 arch/arm64/boot/dts/cix/sky1-pinfunc.h
arch/arm64/boot/dts/cix/sky1-orion-o6.dts +32 -0
index d74964d53c3b..52e5e35d3db2 100644
@@ -7,6 +7,8 @@
 /dts-v1/;
 
 #include "sky1.dtsi"
+#include "sky1-pinfunc.h"
+
 / {
 	model = "Radxa Orion O6";
 	compatible = "radxa,orion-o6", "cix,sky1";
@@ -34,6 +36,36 @@ linux,cma {
 
 };
 
+&iomuxc {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_hog>;
+
+	pinctrl_hog: hog-pins {
+		pins-hog {
+			pinmux = <CIX_PAD_GPIO144_FUNC_GPIO144>,
+				<CIX_PAD_GPIO145_FUNC_GPIO145>,
+				<CIX_PAD_GPIO146_FUNC_GPIO146>,
+				<CIX_PAD_GPIO147_FUNC_GPIO147>;
+			bias-pull-down;
+			drive-strength = <DS_LEVEL4>;
+		};
+	};
+};
+
+&iomuxc_s5 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_hog_s5>;
+
+	pinctrl_hog_s5: hog-s5-pins {
+		pins-hog-s5 {
+			pinmux = <CIX_PAD_GPIO014_FUNC_GPIO014>;
+			bias-pull-up;
+			drive-strength = <DS_LEVEL4>;
+
+		};
+	};
+};
+
 &uart2 {
 	status = "okay";
 };
arch/arm64/boot/dts/cix/sky1-pinfunc.h new file +417 -0

417 lines not on this page · raw message

arch/arm64/boot/dts/cix/sky1.dtsi +10 -0
index 7dfe7677e649..4c6f25fe797c 100644
@@ -228,6 +228,11 @@ uart3: serial@40e0000 {
 			status = "disabled";
 		};
 
+		iomuxc: pinctrl@4170000 {
+			compatible = "cix,sky1-iomuxc";
+			reg = <0x0 0x04170000 0x0 0x1000>;
+		};
+
 		mbox_ap2se: mailbox@5060000 {
 			compatible = "cix,sky1-mbox";
 			reg = <0x0 0x05060000 0x0 0x10000>;
@@ -316,6 +321,11 @@ ppi_partition1: interrupt-partition-1 {
 				};
 			};
 		};
+
+		iomuxc_s5: pinctrl@16007000 {
+			compatible = "cix,sky1-iomuxc-s5";
+			reg = <0x0 0x16007000 0x0 0x1000>;
+		};
 	};
 
 	timer {
Signature · 1 line
2.49.0
#16 lore raw
In reply to Gary Yang

Hi Gary,

Quoted 9 lines · Gary Yang

Patch 1: add Cix pinctrl driver to support pinmux and pinconfigs Patch 2: add Cix pinctrl nodes and header file
Patch 3: add yaml doc

Changes for v2:
- restructure the pinctrl driver to support pinmux=<..>
- redefine pinmux macros
- move header file from dt-bindings to dts
- fix the code-style issues

If you want help for managing the different revisions of a patch series, you can use the "b4" tool, here is a tutorial:

https://people.kernel.org/monsieuricon/sending-a-kernel-patch-with-b4-part-1

[Konstantin: the doc link on the bottom of the article is wrong and needs to be augmented to point to latest!]

It's a bit tricky to switch to v3 since you already started without it, but it can be done with

b4 prep --force-revision 3
(see full docs https://b4.docs.kernel.org/en/latest/ )

Yours,
Linus Walleij