Skip to contentSkip to conversation

Add pin control driver for Sunplus SP7021 SoC

PATCH Superseded Wells Lu 6 participants 19 messages Oct 27, 2021 – Nov 18, 2021 1 message not in the archive

Subsystems (4)

v1 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Wells Lu

author maintainer
#0 lore raw

cover Add pin control driver for Sunplus SP7021 SoC

This is a patch series for pinctrl driver for Sunplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Wells Lu (3):
pinctrl: Add driver for Sunplus SP7021
dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021
devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

 .../bindings/pinctrl/sunplus,sp7021-pinctrl.yaml   | 277 ++++++++++
 MAINTAINERS                                        |  10 +
 drivers/pinctrl/Kconfig                            |   1 +
 drivers/pinctrl/Makefile                           |   1 +
 drivers/pinctrl/sunplus/Kconfig                    |  32 ++
 drivers/pinctrl/sunplus/Makefile                   |  11 +
 drivers/pinctrl/sunplus/gpio_inf_sp7021.c          |  48 ++
 drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c       | 501 +++++++++++++++++
 drivers/pinctrl/sunplus/sppctl.c                   | 359 +++++++++++++
 drivers/pinctrl/sunplus/sppctl.h                   | 181 +++++++
 drivers/pinctrl/sunplus/sppctl_gpio.c              | 136 +++++
 drivers/pinctrl/sunplus/sppctl_gpio.h              |  73 +++
 drivers/pinctrl/sunplus/sppctl_gpio_ops.c          | 288 ++++++++++
 drivers/pinctrl/sunplus/sppctl_gpio_ops.h          |  75 +++
 drivers/pinctrl/sunplus/sppctl_pinctrl.c           | 593 +++++++++++++++++++++
 drivers/pinctrl/sunplus/sppctl_pinctrl.h           |  33 ++
 drivers/pinctrl/sunplus/sppctl_sysfs.c             | 385 +++++++++++++
 drivers/pinctrl/sunplus/sppctl_sysfs.h             |  33 ++
 include/dt-bindings/pinctrl/sppctl-sp7021.h        | 136 +++++
 include/dt-bindings/pinctrl/sppctl.h               |  40 ++
 20 files changed, 3213 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml
 create mode 100644 drivers/pinctrl/sunplus/Kconfig
 create mode 100644 drivers/pinctrl/sunplus/Makefile
 create mode 100644 drivers/pinctrl/sunplus/gpio_inf_sp7021.c
 create mode 100644 drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio_ops.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio_ops.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_pinctrl.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_pinctrl.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_sysfs.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_sysfs.h
 create mode 100644 include/dt-bindings/pinctrl/sppctl-sp7021.h
 create mode 100644 include/dt-bindings/pinctrl/sppctl.h
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 1/3 pinctrl: Add driver for Sunplus SP7021

Add driver for Sunplus SP7021.

---
 MAINTAINERS                                  |   8 +
 drivers/pinctrl/Kconfig                      |   1 +
 drivers/pinctrl/Makefile                     |   1 +
 drivers/pinctrl/sunplus/Kconfig              |  32 ++
 drivers/pinctrl/sunplus/Makefile             |  11 +
 drivers/pinctrl/sunplus/gpio_inf_sp7021.c    |  48 +++
 drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c | 501 ++++++++++++++++++++++
 drivers/pinctrl/sunplus/sppctl.c             | 359 ++++++++++++++++
 drivers/pinctrl/sunplus/sppctl.h             | 181 ++++++++
 drivers/pinctrl/sunplus/sppctl_gpio.c        | 136 ++++++
 drivers/pinctrl/sunplus/sppctl_gpio.h        |  73 ++++
 drivers/pinctrl/sunplus/sppctl_gpio_ops.c    | 288 +++++++++++++
 drivers/pinctrl/sunplus/sppctl_gpio_ops.h    |  75 ++++
 drivers/pinctrl/sunplus/sppctl_pinctrl.c     | 593 +++++++++++++++++++++++++++
 drivers/pinctrl/sunplus/sppctl_pinctrl.h     |  33 ++
 drivers/pinctrl/sunplus/sppctl_sysfs.c       | 385 +++++++++++++++++
 drivers/pinctrl/sunplus/sppctl_sysfs.h       |  33 ++
 17 files changed, 2758 insertions(+)
 create mode 100644 drivers/pinctrl/sunplus/Kconfig
 create mode 100644 drivers/pinctrl/sunplus/Makefile
 create mode 100644 drivers/pinctrl/sunplus/gpio_inf_sp7021.c
 create mode 100644 drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio_ops.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio_ops.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_pinctrl.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_pinctrl.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_sysfs.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_sysfs.h
MAINTAINERS +8 -0
index f26920f..43d587c 100644
@@ -14866,6 +14866,14 @@ S:	Maintained
 W:	http://www.st.com/spear
 F:	drivers/pinctrl/spear/
 
+PIN CONTROLLER - SUNPLUS
+M:	Dvorkin Dmitry <[email protected]>
+M:	Wells Lu <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
+F:	drivers/pinctrl/sunplus/
+
 PKTCDVD DRIVER
 M:	[email protected]
 S:	Orphan
drivers/pinctrl/Kconfig +1 -0
index 3192110..5fe8e5d 100644
@@ -452,6 +452,7 @@ source "drivers/pinctrl/mediatek/Kconfig"
 source "drivers/pinctrl/meson/Kconfig"
 source "drivers/pinctrl/cirrus/Kconfig"
 source "drivers/pinctrl/visconti/Kconfig"
+source "drivers/pinctrl/sunplus/Kconfig"
 
 config PINCTRL_XWAY
 	bool
drivers/pinctrl/Makefile +1 -0
index 200073b..3721877 100644
@@ -66,6 +66,7 @@ obj-$(CONFIG_PINCTRL_SAMSUNG)	+= samsung/
 obj-$(CONFIG_PINCTRL_SPEAR)	+= spear/
 obj-y				+= sprd/
 obj-$(CONFIG_PINCTRL_STM32)	+= stm32/
+obj-y				+= sunplus/
 obj-$(CONFIG_PINCTRL_SUNXI)	+= sunxi/
 obj-y				+= ti/
 obj-$(CONFIG_PINCTRL_UNIPHIER)	+= uniphier/
drivers/pinctrl/sunplus/Kconfig new file +32 -0
new file mode 100644
index 0000000..93b5ccf
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Sunplus Pin control driver configuration
+#
+
+config PINCTRL_SPPCTL
+	bool "Sunplus SP7021 pinmux and gpio driver"
+	depends on SOC_SP7021
+	select PINMUX
+	select GENERIC_PINCTRL_GROUPS
+	select CONFIG_GENERIC_PINMUX_FUNCTIONS
+	select PINCONF
+	select GENERIC_PINCONF
+	select OF_GPIO
+	select GPIOLIB
+	select GPIO_SYSFS
+	select GENERIC_IRQ_CHIP
+	select GPIOLIB_IRQCHIP
+	help
+	  Say Y here to support Sunplus SP7021 pinmux controller.
+	  The driveer is selected automatically by platform.
+	  This driver requires the pinctrl framework.
+	  GPIO is provided by the same driver.
+
+config PINCTRL_SPPCTL_DEBUG
+	bool "Sunplus pinmux specific debug"
+	depends on SOC_SP7021 && DEBUG_PINCTRL
+	help
+	  Say Y if you need to debug Sunplus pinmux driver in-depth.
+	  Pin control driver will output more messages if you enable
+	  this item. This function is dependent on DEBUG_PINCTRL. It
+	  should be enabled first.
drivers/pinctrl/sunplus/Makefile new file +11 -0
new file mode 100644
index 0000000..a945653
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Sunplus Pin control drivers.
+#
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_pinctrl.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_sysfs.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_gpio_ops.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_gpio.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += pinctrl_inf_sp7021.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += gpio_inf_sp7021.o
drivers/pinctrl/sunplus/gpio_inf_sp7021.c new file +48 -0

48 lines not on this page · raw message

drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c new file +501 -0

501 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl.c new file +359 -0

359 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl.h new file +181 -0

181 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_gpio.c new file +136 -0

136 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_gpio.h new file +73 -0

73 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_gpio_ops.c new file +288 -0

288 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_gpio_ops.h new file +75 -0

75 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_pinctrl.c new file +593 -0

593 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_pinctrl.h new file +33 -0
new file mode 100644
index 0000000..a634c41
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SP7021 pinmux controller driver.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef SPPCTL_PINCTRL_H
+#define SPPCTL_PINCTRL_H
+
+#include "sppctl.h"
+
+
+int sppctl_pinctrl_init(struct platform_device *_pdev);
+void sppctl_pinctrl_clea(struct platform_device *_pdev);
+
+#define D(x, y) ((x)*8+(y))
+
+extern const struct pinctrl_pin_desc sppctlpins_all[];
+extern const size_t sppctlpins_allSZ;
+extern const unsigned int sppctlpins_G[];
+
+#endif // SPPCTL_PINCTRL_H
drivers/pinctrl/sunplus/sppctl_sysfs.c new file +385 -0

385 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_sysfs.h new file +33 -0
new file mode 100644
index 0000000..f37b8cf
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SP7021 pinmux controller driver.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef SPPCTL_SYSFS_H
+#define SPPCTL_SYSFS_H
+
+#include "sppctl.h"
+
+
+struct sppctl_sdata_t {
+	uint8_t i;
+	uint8_t ridx;
+	struct sppctl_pdata_t *pdata;
+};
+
+void sppctl_sysfs_init(struct platform_device *_pdev);
+void sppctl_sysfs_clean(struct platform_device *_pdev);
+
+#endif // SPPCTL_SYSFS_H
Signature · 1 line
2.7.4
author maintainer
#5 lore raw

PATCH 2/3 dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021

In reply to Wells Lu

Add dt-bindings header files for Sunplus SP7021 SoC.

---
 MAINTAINERS                                 |   1 +
 include/dt-bindings/pinctrl/sppctl-sp7021.h | 136 ++++++++++++++++++++++++++++
 include/dt-bindings/pinctrl/sppctl.h        |  40 ++++++++
 3 files changed, 177 insertions(+)
 create mode 100644 include/dt-bindings/pinctrl/sppctl-sp7021.h
 create mode 100644 include/dt-bindings/pinctrl/sppctl.h
MAINTAINERS +1 -0
index 43d587c..9cae8e7 100644
@@ -14873,6 +14873,7 @@ L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	drivers/pinctrl/sunplus/
+F:	include/dt-bindings/pinctrl/sppctl*
 
 PKTCDVD DRIVER
 M:	[email protected]
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +136 -0

136 lines not on this page · raw message

include/dt-bindings/pinctrl/sppctl.h new file +40 -0
new file mode 100644
index 0000000..3e82989
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SP7021 pinmux pinctrl bindings.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_PINCTRL_SPPCTL_H
+#define _DT_BINDINGS_PINCTRL_SPPCTL_H
+
+#define IOP_G_MASTE             (0x01<<0)
+#define IOP_G_FIRST             (0x01<<1)
+
+#define SPPCTL_PCTL_G_PMUX      (0x00|IOP_G_MASTE)
+#define SPPCTL_PCTL_G_GPIO      (IOP_G_FIRST|IOP_G_MASTE)
+#define SPPCTL_PCTL_G_IOPP      (IOP_G_FIRST|0x00)
+
+#define SPPCTL_PCTL_L_OUT       (0x01<<0)
+#define SPPCTL_PCTL_L_OU1       (0x01<<1)
+#define SPPCTL_PCTL_L_INV       (0x01<<2)
+#define SPPCTL_PCTL_L_ONV       (0x01<<3)
+#define SPPCTL_PCTL_L_ODR       (0x01<<4)
+
+#define SPPCTL_PCTLE_P(v)       ((v)<<24)
+#define SPPCTL_PCTLE_G(v)       ((v)<<16)
+#define SPPCTL_PCTLE_F(v)       ((v)<<8)
+#define SPPCTL_PCTLE_L(v)       ((v)<<0)
+
+#define SPPCTL_PCTLD_P(v)       (((v)>>24) & 0xFF)
+#define SPPCTL_PCTLD_G(v)       (((v)>>16) & 0xFF)
+#define SPPCTL_PCTLD_F(v)       (((v) >> 8) & 0xFF)
+#define SPPCTL_PCTLD_L(v)       (((v) >> 0) & 0xFF)
+
+/*
+ * pack into 32-bit value:
+ * pin#{8bit}, typ{8bit}, function{8bit}, flags{8bit}
+ */
+#define SPPCTL_IOPAD(pin, typ, fun, fls) (((pin)<<24)|((typ)<<16)|((fun)<<8)|(fls))
+
+#endif
Signature · 1 line
2.7.4
author maintainer
#6 lore raw

PATCH 3/3 devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

In reply to Wells Lu

Add bindings documentation for Sunplus SP7021.

---
 .../bindings/pinctrl/sunplus,sp7021-pinctrl.yaml   | 277 +++++++++++++++++++++
 MAINTAINERS                                        |   1 +
 2 files changed, 278 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +277 -0
new file mode 100644
index 0000000..7cfa0ce
@@ -0,0 +1,277 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/sunplus,sp7021-pinctrl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 Pin Controller Device Tree Bindings
+
+maintainers:
+  - Dvorkin Dmitry <[email protected]>
+  - Wells Lu <[email protected]>
+
+description: |
+  The Sunplus SP7021 pin controller is used to control SoC pins. Please
+  refer to pinctrl-bindings.txt in this directory for details of the common
+  pinctrl bindings used by client devices.
+
+  Refer to https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/pages/
+  1443495991/How+to+setup+pins+of+SP7021+in+device-tree+source
+
+  The device node of pin controller of Sunplus SP7021 has following
+  properties.
+
+properties:
+  compatible:
+    const: sunplus,sp7021-pctl
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+  reg:
+    items:
+      - description: Base address and length of the MOON2 registers.
+      - description: Base address and length of the GPIOXT registers.
+      - description: Base address and length of the GPIOXT2 registers.
+      - description: Base address and length of the FIRST registers.
+      - description: Base address and length of the MOON1 registers.
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+patternProperties:
+  '^.*$':
+    if:
+      type: object
+    then:
+      description: |
+        A pinctrl node should contain at least one subnodes representing the
+        pins or function-pins group available on the machine. Each subnode
+        will list the pins it needs, and how they should be configured.
+
+        Pinctrl node's client devices use subnodes for desired pin
+        configuration. Client device subnodes use below standard properties.
+
+      properties:
+        pins:
+          description: |
+            Define pins which are used by pinctrl node's client device.
+
+            It consists of one or more integers which represents the config
+            setting for corresponding pin. Please use macro SPPCTL_IOPAD to
+            define the integers for pins.
+
+            The first argument of the macro is pin number, the second is pin
+            type, the third is type of GPIO, the last is default output state
+            of GPIO.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+        function:
+          description: |
+            Define pin-function which is used by pinctrl node's client device.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH, SPI_FLASH_4BIT, SPI_NAND, CARD0_EMMC, SD_CARD,
+                  UA0, FPGA_IFX, HDMI_TX, LCDIF, USB0_OTG, USB1_OTG ]
+
+        groups:
+          description: |
+            Define pin-group in a specified pin-function.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH1, SPI_FLASH2, SPI_FLASH_4BIT1, SPI_FLASH_4BIT2,
+                  SPI_NAND, CARD0_EMMC, SD_CARD, UA0, FPGA_IFX, HDMI_TX1,
+                  HDMI_TX2, HDMI_TX3, LCDIF, USB0_OTG, USB1_OTG ]
+
+        zero_func:
+          description: |
+            Disabled pins which are not used by pinctrl node's client device.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+      additionalProperties: false
+
+      allOf:
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH1
+                  - SPI_FLASH2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH_4BIT
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH_4BIT1
+                  - SPI_FLASH_4BIT2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_NAND
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_NAND
+        - if:
+            properties:
+              function:
+                enum:
+                  - CARD0_EMMC
+          then:
+            properties:
+              groups:
+                enum:
+                  - CARD0_EMMC
+        - if:
+            properties:
+              function:
+                enum:
+                  - SD_CARD
+          then:
+            properties:
+              groups:
+                enum:
+                  - SD_CARD
+        - if:
+            properties:
+              function:
+                enum:
+                  - UA0
+          then:
+            properties:
+              groups:
+                enum:
+                  - UA0
+        - if:
+            properties:
+              function:
+                enum:
+                  - FPGA_IFX
+          then:
+            properties:
+              groups:
+                enum:
+                  - FPGA_IFX
+        - if:
+            properties:
+              function:
+                enum:
+                  - HDMI_TX
+          then:
+            properties:
+              groups:
+                enum:
+                  - HDMI_TX1
+                  - HDMI_TX2
+                  - HDMI_TX3
+        - if:
+            properties:
+              function:
+                enum:
+                  - LCDIF
+          then:
+            properties:
+              groups:
+                enum:
+                  - LCDIF
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB0_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB0_OTG
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB1_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB1_OTG
+
+required:
+  - compatible
+  - reg
+  - "#gpio-cells"
+  - gpio-controller
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sp-sp7021.h>
+    #include <dt-bindings/reset/sp-sp7021.h>
+    #include <dt-bindings/pinctrl/sppctl-sp7021.h>
+
+    pctl: pctl@9C000100 {
+        compatible = "sunplus,sp7021-pctl";
+        reg = <0x9C000100 0x100>, <0x9C000300 0x80>, <0x9C000380 0x80>,
+              <0x9C0032e4 0x1C>, <0x9C000080 0x20>;
+        gpio-controller;
+        #gpio-cells = <2>;
+        clocks = <&clkc GPIO>;
+        resets = <&rstc RST_GPIO>;
+
+        pins_uart0: pins_uart0 {
+            function = "UA0";
+            groups = "UA0";
+        };
+
+        pins_uart1: pins_uart1 {
+            pins = <
+                SPPCTL_IOPAD(11,SPPCTL_PCTL_G_PMUX,MUXF_UA1_TX,0)
+                SPPCTL_IOPAD(10,SPPCTL_PCTL_G_PMUX,MUXF_UA1_RX,0)
+                SPPCTL_IOPAD(7,SPPCTL_PCTL_G_GPIO,0,SPPCTL_PCTL_L_OUT)
+            >;
+        };
+
+        emmc_mux: emmc_mux {
+            function = "CARD0_EMMC";
+            groups = "CARD0_EMMC";
+        };
+
+        mmc1_mux: mmc1_mux {
+            function = "SD_CARD";
+            groups = "SD_CARD";
+            pins = < SPPCTL_IOPAD(91,SPPCTL_PCTL_G_GPIO,0,0) >;
+        };
+
+        hdmi_A_tx1: hdmi_A_tx1_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX1";
+        };
+        hdmi_A_tx2: hdmi_A_tx2_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX2";
+        };
+        hdmi_A_tx3: hdmi_A_tx3_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX3";
+        };
+    };
+...
MAINTAINERS +1 -0
index 9cae8e7..fe3f359 100644
@@ -14872,6 +14872,7 @@ M:	Wells Lu <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
+F:	Documentation/devicetree/bindings/pinctrl/sunplus,*
 F:	drivers/pinctrl/sunplus/
 F:	include/dt-bindings/pinctrl/sppctl*
 
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/3] pinctrl: Add driver for Sunplus SP7021

In reply to Wells Lu

Hi--

drivers/pinctrl/sunplus/Kconfig line 7

Quoted 13 lines · Wells Lu
drivers/pinctrl/sunplus/Kconfig new file +7 -0
new file mode 100644
index 0000000..93b5ccf
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Sunplus Pin control driver configuration
+#
+
+config PINCTRL_SPPCTL
+	bool "Sunplus SP7021 pinmux and gpio driver"

Preferably GPIO

drivers/pinctrl/sunplus/Kconfig line 11

Quoted 4 lines
drivers/pinctrl/sunplus/Kconfig new file +4 -0
+	depends on SOC_SP7021
+	select PINMUX
+	select GENERIC_PINCTRL_GROUPS
+	select CONFIG_GENERIC_PINMUX_FUNCTIONS

Drop CONFIG_

drivers/pinctrl/sunplus/Kconfig line 14

Quoted 3 lines
drivers/pinctrl/sunplus/Kconfig new file +3 -0
+	select PINCONF
+	select GENERIC_PINCONF
+	select OF_GPIO

Probably

	depends on OF && HAS_IOMEM

Otherwise how do you know that it's safe to do
select OF_GPIO
?

drivers/pinctrl/sunplus/Kconfig line 21

Quoted 7 lines
drivers/pinctrl/sunplus/Kconfig new file +7 -0
+	select GPIOLIB
+	select GPIO_SYSFS
+	select GENERIC_IRQ_CHIP
+	select GPIOLIB_IRQCHIP
+	help
+	  Say Y here to support Sunplus SP7021 pinmux controller.
+	  The driveer is selected automatically by platform.

driver

drivers/pinctrl/sunplus/Kconfig line 32

Quoted 11 lines
drivers/pinctrl/sunplus/Kconfig new file +11 -0
+	  This driver requires the pinctrl framework.
+	  GPIO is provided by the same driver.
+
+config PINCTRL_SPPCTL_DEBUG
+	bool "Sunplus pinmux specific debug"
+	depends on SOC_SP7021 && DEBUG_PINCTRL
+	help
+	  Say Y if you need to debug Sunplus pinmux driver in-depth.
+	  Pin control driver will output more messages if you enable
+	  this item. This function is dependent on DEBUG_PINCTRL. It
+	  should be enabled first.

thanks.

Signature · 1 line
~Randy
#3 lore raw

RE: [PATCH 1/3] pinctrl: Add driver for Sunplus SP7021

Hi Sir,

Thank you for your review.

I modified errors in Kconfig you pointed out.

Could you please teach me what is the next step I need to do (This is my first submission to Linux kernel main-line)?

1. Should I make a patch [PATHC 1/3 v2] for Kconfig and submit again?
2. Or wait for other files of the patch [PATCH 1/3] being reviewed and then submit patch again.
3. At first patch, I used 'git send-email' command to send a patch series. The command is:
git send-email \
--to [email protected] \
--to [email protected] \
--to [email protected] \
--to [email protected] \
--to [email protected] \
--cc [email protected] \
--cc [email protected] \
--thread 000*.patch
Please teach me what command options of 'git send-email' I should use to send the version 2 patch.
4. If this is not a correct way to reply your email, please teach me how to reply maintainers' email.

Best regards,

Wells Lu

#4 lore raw

Re: [PATCH 1/3] pinctrl: Add driver for Sunplus SP7021

Quoted 8 lines · Wells Lu 呂芳騰

Hi Sir,

Thank you for your review.

I modified errors in Kconfig you pointed out.

Could you please teach me what is the next step I need to do (This is my first submission to Linux kernel main-line)?

Hi,

I would wait another day or two to see if there are any other comments or reviews of the patch series, then send a v2 of the entire series.

Quoted 6 lines

1. Should I make a patch [PATHC 1/3 v2] for Kconfig and submit again?
2. Or wait for other files of the patch [PATCH 1/3] being reviewed and then submit patch again.
3. At first patch, I used 'git send-email' command to send a patch series. The command is:

Quoted 11 lines
   git send-email \
   --to [email protected] \
   --to [email protected] \
   --to [email protected] \
   --to [email protected] \
   --to [email protected] \
   --cc [email protected] \
   --cc [email protected] \
   --thread 000*.patch
   Please teach me what command options of 'git send-email'
   I should use to send the version 2 patch.

I suppose that you are using git to create patches.
I don't create patches with git, so I don't know what it takes to create and send v2 of a patch series.

If you are not using git to create patches, you can just modify the Subject: line in each email to include the "v2" string.

In either case, but sure to describe the changes from v1 to v2. This description goes after (below) the "---" line. I put it before the diffstat output with a blank line separating them.

Quoted 2 lines

4. If this is not a correct way to reply your email, please teach me how to reply maintainers' email.

This is fine.

thanks.

Signature · 1 line
~Randy
author maintainer
#10 lore raw

v2 cover This is a patch series for pinctrl driver for Sunplus SP7021 SoC.

In reply to Wells Lu

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Changes in v2:
- Addressed all comments from Mr. Randy Dunlap.
- Added more 'defines' in dt-bindings header files (forgot to add in v1).
- Modified vendor name in MAINTAINERS file.

Wells Lu (3):
pinctrl: Add driver for Sunplus SP7021
dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021
devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

 .../bindings/pinctrl/sunplus,sp7021-pinctrl.yaml   | 277 ++++++++++
 MAINTAINERS                                        |  10 +
 drivers/pinctrl/Kconfig                            |   1 +
 drivers/pinctrl/Makefile                           |   1 +
 drivers/pinctrl/sunplus/Kconfig                    |  33 ++
 drivers/pinctrl/sunplus/Makefile                   |  11 +
 drivers/pinctrl/sunplus/gpio_inf_sp7021.c          |  48 ++
 drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c       | 501 +++++++++++++++++
 drivers/pinctrl/sunplus/sppctl.c                   | 359 +++++++++++++
 drivers/pinctrl/sunplus/sppctl.h                   | 181 +++++++
 drivers/pinctrl/sunplus/sppctl_gpio.c              | 136 +++++
 drivers/pinctrl/sunplus/sppctl_gpio.h              |  73 +++
 drivers/pinctrl/sunplus/sppctl_gpio_ops.c          | 288 ++++++++++
 drivers/pinctrl/sunplus/sppctl_gpio_ops.h          |  75 +++
 drivers/pinctrl/sunplus/sppctl_pinctrl.c           | 593 +++++++++++++++++++++
 drivers/pinctrl/sunplus/sppctl_pinctrl.h           |  33 ++
 drivers/pinctrl/sunplus/sppctl_sysfs.c             | 385 +++++++++++++
 drivers/pinctrl/sunplus/sppctl_sysfs.h             |  33 ++
 include/dt-bindings/pinctrl/sppctl-sp7021.h        | 171 ++++++
 include/dt-bindings/pinctrl/sppctl.h               |  40 ++
 20 files changed, 3249 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml
 create mode 100644 drivers/pinctrl/sunplus/Kconfig
 create mode 100644 drivers/pinctrl/sunplus/Makefile
 create mode 100644 drivers/pinctrl/sunplus/gpio_inf_sp7021.c
 create mode 100644 drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio_ops.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio_ops.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_pinctrl.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_pinctrl.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_sysfs.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_sysfs.h
 create mode 100644 include/dt-bindings/pinctrl/sppctl-sp7021.h
 create mode 100644 include/dt-bindings/pinctrl/sppctl.h
Signature · 1 line
2.7.4
author maintainer
#11 lore raw

PATCH v2 1/3 pinctrl: Add driver for Sunplus SP7021

Add driver for Sunplus SP7021.

---
Changes in v2:
- Addressed all comments from Mr. Randy Dunlap.
- Modified vendor name in MAINTAINERS file.

 MAINTAINERS                                  |   8 +
 drivers/pinctrl/Kconfig                      |   1 +
 drivers/pinctrl/Makefile                     |   1 +
 drivers/pinctrl/sunplus/Kconfig              |  33 ++
 drivers/pinctrl/sunplus/Makefile             |  11 +
 drivers/pinctrl/sunplus/gpio_inf_sp7021.c    |  48 +++
 drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c | 501 ++++++++++++++++++++++
 drivers/pinctrl/sunplus/sppctl.c             | 359 ++++++++++++++++
 drivers/pinctrl/sunplus/sppctl.h             | 181 ++++++++
 drivers/pinctrl/sunplus/sppctl_gpio.c        | 136 ++++++
 drivers/pinctrl/sunplus/sppctl_gpio.h        |  73 ++++
 drivers/pinctrl/sunplus/sppctl_gpio_ops.c    | 288 +++++++++++++
 drivers/pinctrl/sunplus/sppctl_gpio_ops.h    |  75 ++++
 drivers/pinctrl/sunplus/sppctl_pinctrl.c     | 593 +++++++++++++++++++++++++++
 drivers/pinctrl/sunplus/sppctl_pinctrl.h     |  33 ++
 drivers/pinctrl/sunplus/sppctl_sysfs.c       | 385 +++++++++++++++++
 drivers/pinctrl/sunplus/sppctl_sysfs.h       |  33 ++
 17 files changed, 2759 insertions(+)
 create mode 100644 drivers/pinctrl/sunplus/Kconfig
 create mode 100644 drivers/pinctrl/sunplus/Makefile
 create mode 100644 drivers/pinctrl/sunplus/gpio_inf_sp7021.c
 create mode 100644 drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio_ops.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_gpio_ops.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_pinctrl.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_pinctrl.h
 create mode 100644 drivers/pinctrl/sunplus/sppctl_sysfs.c
 create mode 100644 drivers/pinctrl/sunplus/sppctl_sysfs.h
MAINTAINERS +8 -0
index f26920f..fd82c77 100644
@@ -14866,6 +14866,14 @@ S:	Maintained
 W:	http://www.st.com/spear
 F:	drivers/pinctrl/spear/
 
+PIN CONTROLLER - SUNPLUS / TIBBO
+M:	Dvorkin Dmitry <[email protected]>
+M:	Wells Lu <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+S:	Maintained
+W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
+F:	drivers/pinctrl/sunplus/
+
 PKTCDVD DRIVER
 M:	[email protected]
 S:	Orphan
drivers/pinctrl/Kconfig +1 -0
index 3192110..5fe8e5d 100644
@@ -452,6 +452,7 @@ source "drivers/pinctrl/mediatek/Kconfig"
 source "drivers/pinctrl/meson/Kconfig"
 source "drivers/pinctrl/cirrus/Kconfig"
 source "drivers/pinctrl/visconti/Kconfig"
+source "drivers/pinctrl/sunplus/Kconfig"
 
 config PINCTRL_XWAY
 	bool
drivers/pinctrl/Makefile +1 -0
index 200073b..3721877 100644
@@ -66,6 +66,7 @@ obj-$(CONFIG_PINCTRL_SAMSUNG)	+= samsung/
 obj-$(CONFIG_PINCTRL_SPEAR)	+= spear/
 obj-y				+= sprd/
 obj-$(CONFIG_PINCTRL_STM32)	+= stm32/
+obj-y				+= sunplus/
 obj-$(CONFIG_PINCTRL_SUNXI)	+= sunxi/
 obj-y				+= ti/
 obj-$(CONFIG_PINCTRL_UNIPHIER)	+= uniphier/
drivers/pinctrl/sunplus/Kconfig new file +33 -0
new file mode 100644
index 0000000..502a8fa
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Sunplus Pin control driver configuration
+#
+
+config PINCTRL_SPPCTL
+	bool "Sunplus SP7021 pinmux and GPIO driver"
+	depends on SOC_SP7021
+	depends on OF && HAS_IOMEM
+	select PINMUX
+	select GENERIC_PINCTRL_GROUPS
+	select GENERIC_PINMUX_FUNCTIONS
+	select PINCONF
+	select GENERIC_PINCONF
+	select OF_GPIO
+	select GPIOLIB
+	select GPIO_SYSFS
+	select GENERIC_IRQ_CHIP
+	select GPIOLIB_IRQCHIP
+	help
+	  Say Y here to support Sunplus SP7021 pinmux controller.
+	  The driver is selected automatically by platform.
+	  This driver requires the pinctrl framework.
+	  GPIO is provided by the same driver.
+
+config PINCTRL_SPPCTL_DEBUG
+	bool "Sunplus pinmux specific debug"
+	depends on SOC_SP7021 && DEBUG_PINCTRL
+	help
+	  Say Y if you need to debug Sunplus pinmux driver in-depth.
+	  Pin control driver will output more messages if you enable
+	  this item. This function is dependent on DEBUG_PINCTRL. It
+	  should be enabled first.
drivers/pinctrl/sunplus/Makefile new file +11 -0
new file mode 100644
index 0000000..a945653
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Sunplus Pin control drivers.
+#
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_pinctrl.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_sysfs.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_gpio_ops.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_gpio.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += pinctrl_inf_sp7021.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += gpio_inf_sp7021.o
drivers/pinctrl/sunplus/gpio_inf_sp7021.c new file +48 -0

48 lines not on this page · raw message

drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c new file +501 -0

501 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl.c new file +359 -0

359 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl.h new file +181 -0

181 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_gpio.c new file +136 -0

136 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_gpio.h new file +73 -0

73 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_gpio_ops.c new file +288 -0

288 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_gpio_ops.h new file +75 -0

75 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_pinctrl.c new file +593 -0

593 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_pinctrl.h new file +33 -0
new file mode 100644
index 0000000..a634c41
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SP7021 pinmux controller driver.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef SPPCTL_PINCTRL_H
+#define SPPCTL_PINCTRL_H
+
+#include "sppctl.h"
+
+
+int sppctl_pinctrl_init(struct platform_device *_pdev);
+void sppctl_pinctrl_clea(struct platform_device *_pdev);
+
+#define D(x, y) ((x)*8+(y))
+
+extern const struct pinctrl_pin_desc sppctlpins_all[];
+extern const size_t sppctlpins_allSZ;
+extern const unsigned int sppctlpins_G[];
+
+#endif // SPPCTL_PINCTRL_H
drivers/pinctrl/sunplus/sppctl_sysfs.c new file +385 -0

385 lines not on this page · raw message

drivers/pinctrl/sunplus/sppctl_sysfs.h new file +33 -0
new file mode 100644
index 0000000..f37b8cf
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SP7021 pinmux controller driver.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef SPPCTL_SYSFS_H
+#define SPPCTL_SYSFS_H
+
+#include "sppctl.h"
+
+
+struct sppctl_sdata_t {
+	uint8_t i;
+	uint8_t ridx;
+	struct sppctl_pdata_t *pdata;
+};
+
+void sppctl_sysfs_init(struct platform_device *_pdev);
+void sppctl_sysfs_clean(struct platform_device *_pdev);
+
+#endif // SPPCTL_SYSFS_H
Signature · 1 line
2.7.4
author maintainer
#14 lore raw

PATCH v2 2/3 dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021

In reply to Wells Lu

Add dt-bindings header files for Sunplus SP7021 SoC.

---
Changes in v2:
- Added more 'defines' in dt-bindings header files (forgot to add in v1).

 MAINTAINERS                                 |   1 +
 include/dt-bindings/pinctrl/sppctl-sp7021.h | 171 ++++++++++++++++++++++++++++
 include/dt-bindings/pinctrl/sppctl.h        |  40 +++++++
 3 files changed, 212 insertions(+)
 create mode 100644 include/dt-bindings/pinctrl/sppctl-sp7021.h
 create mode 100644 include/dt-bindings/pinctrl/sppctl.h
MAINTAINERS +1 -0
index fd82c77..da6378f 100644
@@ -14873,6 +14873,7 @@ L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	drivers/pinctrl/sunplus/
+F:	include/dt-bindings/pinctrl/sppctl*
 
 PKTCDVD DRIVER
 M:	[email protected]
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +171 -0

171 lines not on this page · raw message

include/dt-bindings/pinctrl/sppctl.h new file +40 -0
new file mode 100644
index 0000000..3e82989
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SP7021 pinmux pinctrl bindings.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_PINCTRL_SPPCTL_H
+#define _DT_BINDINGS_PINCTRL_SPPCTL_H
+
+#define IOP_G_MASTE             (0x01<<0)
+#define IOP_G_FIRST             (0x01<<1)
+
+#define SPPCTL_PCTL_G_PMUX      (0x00|IOP_G_MASTE)
+#define SPPCTL_PCTL_G_GPIO      (IOP_G_FIRST|IOP_G_MASTE)
+#define SPPCTL_PCTL_G_IOPP      (IOP_G_FIRST|0x00)
+
+#define SPPCTL_PCTL_L_OUT       (0x01<<0)
+#define SPPCTL_PCTL_L_OU1       (0x01<<1)
+#define SPPCTL_PCTL_L_INV       (0x01<<2)
+#define SPPCTL_PCTL_L_ONV       (0x01<<3)
+#define SPPCTL_PCTL_L_ODR       (0x01<<4)
+
+#define SPPCTL_PCTLE_P(v)       ((v)<<24)
+#define SPPCTL_PCTLE_G(v)       ((v)<<16)
+#define SPPCTL_PCTLE_F(v)       ((v)<<8)
+#define SPPCTL_PCTLE_L(v)       ((v)<<0)
+
+#define SPPCTL_PCTLD_P(v)       (((v)>>24) & 0xFF)
+#define SPPCTL_PCTLD_G(v)       (((v)>>16) & 0xFF)
+#define SPPCTL_PCTLD_F(v)       (((v) >> 8) & 0xFF)
+#define SPPCTL_PCTLD_L(v)       (((v) >> 0) & 0xFF)
+
+/*
+ * pack into 32-bit value:
+ * pin#{8bit}, typ{8bit}, function{8bit}, flags{8bit}
+ */
+#define SPPCTL_IOPAD(pin, typ, fun, fls) (((pin)<<24)|((typ)<<16)|((fun)<<8)|(fls))
+
+#endif
Signature · 1 line
2.7.4
author maintainer
#17 lore raw

PATCH v2 3/3 devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

In reply to Wells Lu

Add bindings documentation for Sunplus SP7021.

---
Changes in v2:
- None

 .../bindings/pinctrl/sunplus,sp7021-pinctrl.yaml   | 277 +++++++++++++++++++++
 MAINTAINERS                                        |   1 +
 2 files changed, 278 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +277 -0
new file mode 100644
index 0000000..7cfa0ce
@@ -0,0 +1,277 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/sunplus,sp7021-pinctrl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 Pin Controller Device Tree Bindings
+
+maintainers:
+  - Dvorkin Dmitry <[email protected]>
+  - Wells Lu <[email protected]>
+
+description: |
+  The Sunplus SP7021 pin controller is used to control SoC pins. Please
+  refer to pinctrl-bindings.txt in this directory for details of the common
+  pinctrl bindings used by client devices.
+
+  Refer to https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/pages/
+  1443495991/How+to+setup+pins+of+SP7021+in+device-tree+source
+
+  The device node of pin controller of Sunplus SP7021 has following
+  properties.
+
+properties:
+  compatible:
+    const: sunplus,sp7021-pctl
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+  reg:
+    items:
+      - description: Base address and length of the MOON2 registers.
+      - description: Base address and length of the GPIOXT registers.
+      - description: Base address and length of the GPIOXT2 registers.
+      - description: Base address and length of the FIRST registers.
+      - description: Base address and length of the MOON1 registers.
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+patternProperties:
+  '^.*$':
+    if:
+      type: object
+    then:
+      description: |
+        A pinctrl node should contain at least one subnodes representing the
+        pins or function-pins group available on the machine. Each subnode
+        will list the pins it needs, and how they should be configured.
+
+        Pinctrl node's client devices use subnodes for desired pin
+        configuration. Client device subnodes use below standard properties.
+
+      properties:
+        pins:
+          description: |
+            Define pins which are used by pinctrl node's client device.
+
+            It consists of one or more integers which represents the config
+            setting for corresponding pin. Please use macro SPPCTL_IOPAD to
+            define the integers for pins.
+
+            The first argument of the macro is pin number, the second is pin
+            type, the third is type of GPIO, the last is default output state
+            of GPIO.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+        function:
+          description: |
+            Define pin-function which is used by pinctrl node's client device.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH, SPI_FLASH_4BIT, SPI_NAND, CARD0_EMMC, SD_CARD,
+                  UA0, FPGA_IFX, HDMI_TX, LCDIF, USB0_OTG, USB1_OTG ]
+
+        groups:
+          description: |
+            Define pin-group in a specified pin-function.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH1, SPI_FLASH2, SPI_FLASH_4BIT1, SPI_FLASH_4BIT2,
+                  SPI_NAND, CARD0_EMMC, SD_CARD, UA0, FPGA_IFX, HDMI_TX1,
+                  HDMI_TX2, HDMI_TX3, LCDIF, USB0_OTG, USB1_OTG ]
+
+        zero_func:
+          description: |
+            Disabled pins which are not used by pinctrl node's client device.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+      additionalProperties: false
+
+      allOf:
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH1
+                  - SPI_FLASH2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH_4BIT
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH_4BIT1
+                  - SPI_FLASH_4BIT2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_NAND
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_NAND
+        - if:
+            properties:
+              function:
+                enum:
+                  - CARD0_EMMC
+          then:
+            properties:
+              groups:
+                enum:
+                  - CARD0_EMMC
+        - if:
+            properties:
+              function:
+                enum:
+                  - SD_CARD
+          then:
+            properties:
+              groups:
+                enum:
+                  - SD_CARD
+        - if:
+            properties:
+              function:
+                enum:
+                  - UA0
+          then:
+            properties:
+              groups:
+                enum:
+                  - UA0
+        - if:
+            properties:
+              function:
+                enum:
+                  - FPGA_IFX
+          then:
+            properties:
+              groups:
+                enum:
+                  - FPGA_IFX
+        - if:
+            properties:
+              function:
+                enum:
+                  - HDMI_TX
+          then:
+            properties:
+              groups:
+                enum:
+                  - HDMI_TX1
+                  - HDMI_TX2
+                  - HDMI_TX3
+        - if:
+            properties:
+              function:
+                enum:
+                  - LCDIF
+          then:
+            properties:
+              groups:
+                enum:
+                  - LCDIF
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB0_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB0_OTG
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB1_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB1_OTG
+
+required:
+  - compatible
+  - reg
+  - "#gpio-cells"
+  - gpio-controller
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sp-sp7021.h>
+    #include <dt-bindings/reset/sp-sp7021.h>
+    #include <dt-bindings/pinctrl/sppctl-sp7021.h>
+
+    pctl: pctl@9C000100 {
+        compatible = "sunplus,sp7021-pctl";
+        reg = <0x9C000100 0x100>, <0x9C000300 0x80>, <0x9C000380 0x80>,
+              <0x9C0032e4 0x1C>, <0x9C000080 0x20>;
+        gpio-controller;
+        #gpio-cells = <2>;
+        clocks = <&clkc GPIO>;
+        resets = <&rstc RST_GPIO>;
+
+        pins_uart0: pins_uart0 {
+            function = "UA0";
+            groups = "UA0";
+        };
+
+        pins_uart1: pins_uart1 {
+            pins = <
+                SPPCTL_IOPAD(11,SPPCTL_PCTL_G_PMUX,MUXF_UA1_TX,0)
+                SPPCTL_IOPAD(10,SPPCTL_PCTL_G_PMUX,MUXF_UA1_RX,0)
+                SPPCTL_IOPAD(7,SPPCTL_PCTL_G_GPIO,0,SPPCTL_PCTL_L_OUT)
+            >;
+        };
+
+        emmc_mux: emmc_mux {
+            function = "CARD0_EMMC";
+            groups = "CARD0_EMMC";
+        };
+
+        mmc1_mux: mmc1_mux {
+            function = "SD_CARD";
+            groups = "SD_CARD";
+            pins = < SPPCTL_IOPAD(91,SPPCTL_PCTL_G_GPIO,0,0) >;
+        };
+
+        hdmi_A_tx1: hdmi_A_tx1_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX1";
+        };
+        hdmi_A_tx2: hdmi_A_tx2_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX2";
+        };
+        hdmi_A_tx3: hdmi_A_tx3_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX3";
+        };
+    };
+...
MAINTAINERS +1 -0
index da6378f..11835e7 100644
@@ -14872,6 +14872,7 @@ M:	Wells Lu <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
+F:	Documentation/devicetree/bindings/pinctrl/sunplus,*
 F:	drivers/pinctrl/sunplus/
 F:	include/dt-bindings/pinctrl/sppctl*
 
Signature · 1 line
2.7.4
#7 lore raw

Re: [PATCH 3/3] devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

In reply to Wells Lu

Hi Wells Lu,

thanks for your patch!

Quoted 20 lines · Wells Lu
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +20 -0
+      properties:
+        pins:
+          description: |
+            Define pins which are used by pinctrl node's client device.
+
+            It consists of one or more integers which represents the config
+            setting for corresponding pin. Please use macro SPPCTL_IOPAD to
+            define the integers for pins.
+
+            The first argument of the macro is pin number, the second is pin
+            type, the third is type of GPIO, the last is default output state
+            of GPIO.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+        function:
+          description: |
+            Define pin-function which is used by pinctrl node's client device.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH, SPI_FLASH_4BIT, SPI_NAND, CARD0_EMMC, SD_CARD,

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 90

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +10 -0
+                  UA0, FPGA_IFX, HDMI_TX, LCDIF, USB0_OTG, USB1_OTG ]
+
+        groups:
+          description: |
+            Define pin-group in a specified pin-function.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH1, SPI_FLASH2, SPI_FLASH_4BIT1, SPI_FLASH_4BIT2,
+                  SPI_NAND, CARD0_EMMC, SD_CARD, UA0, FPGA_IFX, HDMI_TX1,
+                  HDMI_TX2, HDMI_TX3, LCDIF, USB0_OTG, USB1_OTG ]

Is it possible to use Documentation/devicetree/bindings/pinctrl/pinmux-node.yaml for this like other drivers do?

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 95

Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +4 -0
+        zero_func:
+          description: |
+            Disabled pins which are not used by pinctrl node's client device.
+          $ref: /schemas/types.yaml#/definitions/uint32-array

I have never seen this before. Can't you just use pin control hogs for this so the pin controller just take care of these pins?

Quoted 105 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +105 -0
+      allOf:
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH1
+                  - SPI_FLASH2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH_4BIT
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH_4BIT1
+                  - SPI_FLASH_4BIT2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_NAND
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_NAND
+        - if:
+            properties:
+              function:
+                enum:
+                  - CARD0_EMMC
+          then:
+            properties:
+              groups:
+                enum:
+                  - CARD0_EMMC
+        - if:
+            properties:
+              function:
+                enum:
+                  - SD_CARD
+          then:
+            properties:
+              groups:
+                enum:
+                  - SD_CARD
+        - if:
+            properties:
+              function:
+                enum:
+                  - UA0
+          then:
+            properties:
+              groups:
+                enum:
+                  - UA0
+        - if:
+            properties:
+              function:
+                enum:
+                  - FPGA_IFX
+          then:
+            properties:
+              groups:
+                enum:
+                  - FPGA_IFX
+        - if:
+            properties:
+              function:
+                enum:
+                  - HDMI_TX
+          then:
+            properties:
+              groups:
+                enum:
+                  - HDMI_TX1
+                  - HDMI_TX2
+                  - HDMI_TX3
+        - if:
+            properties:
+              function:
+                enum:
+                  - LCDIF
+          then:
+            properties:
+              groups:
+                enum:
+                  - LCDIF
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB0_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB0_OTG

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 213

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +10 -0
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB1_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB1_OTG

This looks complex to me, I need feedback from bindings people on this.

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 251

Quoted 12 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +12 -0
+        pins_uart0: pins_uart0 {
+            function = "UA0";
+            groups = "UA0";
+        };
+
+        pins_uart1: pins_uart1 {
+            pins = <
+                SPPCTL_IOPAD(11,SPPCTL_PCTL_G_PMUX,MUXF_UA1_TX,0)
+                SPPCTL_IOPAD(10,SPPCTL_PCTL_G_PMUX,MUXF_UA1_RX,0)
+                SPPCTL_IOPAD(7,SPPCTL_PCTL_G_GPIO,0,SPPCTL_PCTL_L_OUT)
+            >;
+        };

This first looks like two ways to do the same thing? UART0 uses strings for group + function and uart1 control individual pins.

Is it possible to just do it one way?

I think the pins = <...> scheme includes also multiplexing settings and then it should be named pinmux = <...>:

Please read Documentation/devicetree/bindings/pinctrl/pinmux-node.yaml closely.

Yours,
Linus Walleij

#12 lore raw

Re: [PATCH v2 1/3] pinctrl: Add driver for Sunplus SP7021

In reply to Wells Lu

Hi Wells Lu,

thanks for your patch!

This driver needs a bit of work, I will point out some things and I think it will be quite different if we also change the bindings.

drivers/pinctrl/sunplus/Kconfig line 17

Quoted 12 lines · Wells Lu
drivers/pinctrl/sunplus/Kconfig new file +12 -0
+config PINCTRL_SPPCTL
+       bool "Sunplus SP7021 pinmux and GPIO driver"
+       depends on SOC_SP7021
+       depends on OF && HAS_IOMEM
+       select PINMUX
+       select GENERIC_PINCTRL_GROUPS
+       select GENERIC_PINMUX_FUNCTIONS
+       select PINCONF
+       select GENERIC_PINCONF
+       select OF_GPIO
+       select GPIOLIB
+       select GPIO_SYSFS

Don't do this, sysfs is deprecated.

drivers/pinctrl/sunplus/Makefile line 11

Quoted 7 lines
drivers/pinctrl/sunplus/Makefile new file +7 -0
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_pinctrl.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_sysfs.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_gpio_ops.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_gpio.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += pinctrl_inf_sp7021.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += gpio_inf_sp7021.o

This multitide of files makes this a bit hard to read and review, usually pin controllers are in one-two files for a single SoC.

Quoted 9 lines

+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.

Drop this boilerplate on all files and just use the SPDX tag.

Quoted 1 line

+const size_t GPIS_listSZ = sizeof(sppctlgpio_list_s)/sizeof(*(sppctlgpio_list_s));

Use only lowercase in variable names.
This looks like a reimplementation of ARRAY_SIZE(), replace with that if this is the case.

Quoted 1 line

+const size_t sppctlpins_allSZ = ARRAY_SIZE(sppctlpins_all);

Instead of defining consts for random sizes like this, just inline ARRAY_SIZE() where you use it.

drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c line 80

Quoted 2 lines
drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c new file +2 -0
+// gpio: is defined in gpio_inf_sp7021.c
+const size_t PMUX_listSZ = sizeof(sppctlpmux_list_s)/sizeof(*(sppctlpmux_list_s));

Same comment as above. Etc.

drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c line 152

Quoted 4 lines
drivers/pinctrl/sunplus/pinctrl_inf_sp7021.c new file +4 -0
+/* CEC pin is not used. Release it for others. */
+//static const unsigned int pins_hdmi1[] = { D(10, 6), D(10, 7), D(12, 2), D(12, 1) };
+//static const unsigned int pins_hdmi2[] = { D(8, 3), D(8, 4), D(8, 5), D(8, 6) };
+//static const unsigned int pins_hdmi3[] = { D(7, 4), D(7, 5), D(7, 6), D(7, 7) };

Don't leave commented-out code in the driver. Delete all this stuff.

Quoted 19 lines
drivers/pinctrl/sunplus/sppctl.c new file +19 -0
+void print_device_tree_node(struct device_node *node, int depth)
+{
+       int i = 0;
+       struct device_node *child;
+       struct property    *properties;
+       char                indent[255] = "";
+
+       for (i = 0; i < depth * 3; i++)
+               indent[i] = ' ';
+       indent[i] = '\0';
+
+       ++depth;
+       if (depth == 1) {
+               pr_info("%s{ name = %s\n", indent, node->name);
+               for (properties = node->properties; properties != NULL;
+                       properties = properties->next)
+                       pr_info("%s  %s (%d)\n", indent, properties->name, properties->length);
+               pr_info("%s}\n", indent);
+       }

drivers/pinctrl/sunplus/sppctl.c line 55

Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.c new file +10 -0
+
+       for_each_child_of_node(node, child) {
+               pr_info("%s{ name = %s\n", indent, child->name);
+               for (properties = child->properties; properties != NULL;
+                       properties = properties->next)
+                       pr_info("%s  %s (%d)\n", indent, properties->name, properties->length);
+               print_device_tree_node(child, depth);
+               pr_info("%s}\n", indent);
+       }
+}

This kind of debugging code should be deleted or use what is in the device tree core.

drivers/pinctrl/sunplus/sppctl.c line 60

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.c new file +4 -0
+void sppctl_gmx_set(struct sppctl_pdata_t *_p, uint8_t _roff, uint8_t _boff, uint8_t _bsiz,
+                   uint8_t _rval)
+{
+       uint32_t *r;

Don't use uint8_t or uint16_t or uint32_t, use the kernel short forms u8, u16 or u32, simply.

Don't start any variable names with _underscore, it i a big confusion for the head because it has ambigous semantics.

Try to find concise descriptive variable names.

drivers/pinctrl/sunplus/sppctl.c line 66

Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6 -0
+       struct sppctl_reg_t x = { .m = (~(~0 << _bsiz)) << _boff,
+                                 .v = ((uint16_t)_rval) << _boff };
+
+       if (_p->debug > 1)
+               KDBG(_p->pcdp->dev, "%s(x%X,x%X,x%X,x%X) m:x%X v:x%X\n",
+                    __func__, _roff, _boff, _bsiz, _rval, x.m, x.v);

Do not reinvent kernel debugging use the dev_dbg() macro.

Quoted 1 line

+ r = (uint32_t *)&x;

Try to avoid casting like this. It is usually a sign that something is wrong.

drivers/pinctrl/sunplus/sppctl.c line 98

Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6 -0
+       if (_fun % 2 == 0)
+               ;
+       else {
+               x.v <<= 8;
+               x.m <<= 8;
+       }

This is code that is incredibly terse and deviant from the kernels general style. Please read a few other pin control drivers and familiarize with how these drivers usually look.

drivers/pinctrl/sunplus/sppctl.c line 111

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.c new file +4 -0
+uint8_t sppctl_fun_get(struct sppctl_pdata_t *_p,  uint8_t _fun)
+{
+       uint8_t pin = 0x00;
+       uint8_t func = (_fun >> 1) << 2;

This looks like shting to get rid of bit 0.
Just use bitwise logic instead.

drivers/pinctrl/sunplus/sppctl.c line 165

Quoted 2 lines
drivers/pinctrl/sunplus/sppctl.c new file +2 -0
+       ret = request_firmware_nowait(THIS_MODULE, true, _fwname, _dev, GFP_KERNEL, p,
+                                     sppctl_fwload_cb);

So this pin controller needs a firmware? That is the first time I have ever seen that. Please add comments describing what this firmware is and what it does, also explain it in the commit message.

drivers/pinctrl/sunplus/sppctl.c line 180

Quoted 11 lines
drivers/pinctrl/sunplus/sppctl.c new file +11 -0
+int sppctl_pctl_resmap(struct platform_device *_pd, struct sppctl_pdata_t *_pc)
+{
+       struct resource *rp;
+
+       // resF
+       rp = platform_get_resource(_pd, IORESOURCE_MEM, 0);
+       if (IS_ERR(rp)) {
+               KERR(&(_pd->dev), "%s get res#F ERR\n", __func__);
+               return PTR_ERR(rp);
+       }
+       KDBG(&(_pd->dev), "mres #F:%p\n", rp);

Thes resF etc are very terse and hard to understand. It seems written by someone who knows everything of what they are doing but with very little interest to explain it to others. Code readability is important.

drivers/pinctrl/sunplus/sppctl.c line 336

Quoted 3 lines
drivers/pinctrl/sunplus/sppctl.c new file +3 -0
+static struct platform_driver sppctl_driver = {
+       .driver = {
+               .name           = MNAME,

Don't abbreviate so compulsively.
SP7021_MODULE_NAME is fine.

drivers/pinctrl/sunplus/sppctl.c line 348

Quoted 5 lines
drivers/pinctrl/sunplus/sppctl.c new file +5 -0
+static int __init sppctl_drv_reg(void)
+{
+       return platform_driver_register(&sppctl_driver);
+}
+postcore_initcall(sppctl_drv_reg);

Why do you need a postcore_initcall()?

drivers/pinctrl/sunplus/sppctl.c line 359

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.c new file +4 -0
+MODULE_AUTHOR(M_AUT1);
+MODULE_AUTHOR(M_AUT2);
+MODULE_DESCRIPTION(M_NAM);
+MODULE_LICENSE(M_LIC);

Just inline the strings, all other drivers do.

drivers/pinctrl/sunplus/sppctl.h line 27

Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.h new file +7 -0
+#define MNAME "sppctl"
+#define M_LIC "GPL v2"
+#define M_AUT1 "Dvorkin Dmitry <[email protected]>"
+#define M_AUT2 "Wells Lu <[email protected]>"
+#define M_NAM "SP7021 PinCtl"
+#define M_ORG "Sunplus/Tibbo Tech."
+#define M_CPR "(C) 2020"

This is too much and too abbreviated names, just use the strings directly in the macros.

Quoted 1 line

+#include <linux/version.h>

Why?

Quoted 1 line

+#include <linux/of_gpio.h>

Never use this include in new code. It is legacy.

Quoted 18 lines
drivers/pinctrl/sunplus/sppctl.h new file +18 -0
+#define SPPCTL_MAX_NAM 64
+#define SPPCTL_MAX_BUF PAGE_SIZE
+
+#define KINF(pd, fmt, args...) \
+       do { \
+               if ((pd) != NULL) \
+                       dev_info((pd), fmt, ##args); \
+               else \
+                       pr_info(MNAME ": " fmt, ##args); \
+       } while (0)
+#define KERR(pd, fmt, args...) \
+       do { \
+               if ((pd) != NULL) \
+                       dev_info((pd), fmt, ##args); \
+               else \
+                       pr_err(MNAME ": " fmt, ##args); \
+       } while (0)
+#ifdef CONFIG_PINCTRL_SPPCTL_DEBUG

drivers/pinctrl/sunplus/sppctl.h line 79

Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.h new file +10 -0
+#define KDBG(pd, fmt, args...) \
+       do { \
+               if ((pd) != NULL) \
+                       dev_info((pd), fmt, ##args); \
+               else \
+                       pr_debug(MNAME ": " fmt, ##args); \
+       } while (0)
+#else
+#define KDBG(pd, fmt, args...)
+#endif

Don't reimplement kernel debugging use dev_dbg(), dev_info() dev_err() etc directly. I don't see why you need CONFIG_PINCTRL_SPPCTL_DEBUG at all, if you absolutely want to control debugging for these files only just use this in your Makefile

subdir-ccflags-$(CONFIG_PINCTRL_SPPCTL_DEBUG) := -DDEBUG

This will turn on/off the output from dev_dbg().

drivers/pinctrl/sunplus/sppctl.h line 85

Quoted 3 lines
drivers/pinctrl/sunplus/sppctl.h new file +3 -0
+struct sppctl_pdata_t {
+       char name[SPPCTL_MAX_NAM];
+       uint8_t debug;

Don't use u8 for things like this use bool.

drivers/pinctrl/sunplus/sppctl.h line 97

Quoted 12 lines
drivers/pinctrl/sunplus/sppctl.h new file +12 -0
+       char fwname[SPPCTL_MAX_NAM];
+       void *sysfs_sdp;
+       void __iomem *baseF;    // functions
+       void __iomem *base0;    // MASTER , OE , OUT , IN
+       void __iomem *base1;    // I_INV , O_INV , OD
+       void __iomem *base2;    // GPIO_FIRST
+       void __iomem *baseI;    // IOP
+       // pinctrl-related
+       struct pinctrl_desc pdesc;
+       struct pinctrl_dev *pcdp;
+       struct pinctrl_gpio_range gpio_range;
+       struct sppctlgpio_chip_t *gpiod;

*gpiod is a bad name because we use it quite a lot in the kernel for GPIO descriptors.

drivers/pinctrl/sunplus/sppctl.h line 103

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.h new file +4 -0
+struct sppctl_reg_t {
+       uint16_t v;     // value part
+       uint16_t m;     // mask part
+};

These are not types (no typedef) so don't add *_t
suffixes, just drop those everywhere.

drivers/pinctrl/sunplus/sppctl.h line 127

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.h new file +4 -0
+       const char * const name;
+       const uint8_t gval;             // value for register
+       const unsigned * const pins;    // list of pins
+       const unsigned int pnum;        // number of pins

Use kerneldoc to document struct members.

There will be many more comments but work on these things to begin with!

Yours,
Linus Walleij

maintainer
#15 lore raw

Re: [PATCH v2 2/3] dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021

In reply to Wells Lu
Quoted 32 lines · Wells Lu

Add dt-bindings header files for Sunplus SP7021 SoC.

---
Changes in v2:
- Added more 'defines' in dt-bindings header files (forgot to add in v1).

 MAINTAINERS                                 |   1 +
 include/dt-bindings/pinctrl/sppctl-sp7021.h | 171 ++++++++++++++++++++++++++++
 include/dt-bindings/pinctrl/sppctl.h        |  40 +++++++
 3 files changed, 212 insertions(+)
 create mode 100644 include/dt-bindings/pinctrl/sppctl-sp7021.h
 create mode 100644 include/dt-bindings/pinctrl/sppctl.h
MAINTAINERS +1 -0
index fd82c77..da6378f 100644
@@ -14873,6 +14873,7 @@ L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	drivers/pinctrl/sunplus/
+F:	include/dt-bindings/pinctrl/sppctl*
 
 PKTCDVD DRIVER
 M:	[email protected]
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +0 -0
new file mode 100644
index 0000000..4e07d03

include/dt-bindings/pinctrl/sppctl-sp7021.h line 1

Quoted 1 line
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +1 -0
@@ -0,0 +1,171 @@
+/* SPDX-License-Identifier: GPL-2.0 */

Care about OS other than Linux? Should be dual licensed.

include/dt-bindings/pinctrl/sppctl-sp7021.h line 13

Quoted 12 lines
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +12 -0
+/*
+ * SP7021 pinmux pinctrl bindings.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_PINCTRL_SPPCTL_SP7021_H
+#define _DT_BINDINGS_PINCTRL_SPPCTL_SP7021_H
+
+#include <dt-bindings/pinctrl/sppctl.h>
+
+#define MUXF_GPIO                       0

Where do these numbers come from? Hopefully they correspond to register offsets and aren't made up. A comment either way here would help.

Quoted 208 lines
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +158 -0
+#define MUXF_IOP                        1
+#define MUXF_L2SW_CLK_OUT               2
+#define MUXF_L2SW_MAC_SMI_MDC           3
+#define MUXF_L2SW_LED_FLASH0            4
+#define MUXF_L2SW_LED_FLASH1            5
+#define MUXF_L2SW_LED_ON0               6
+#define MUXF_L2SW_LED_ON1               7
+#define MUXF_L2SW_MAC_SMI_MDIO          8
+#define MUXF_L2SW_P0_MAC_RMII_TXEN      9
+#define MUXF_L2SW_P0_MAC_RMII_TXD0      10
+#define MUXF_L2SW_P0_MAC_RMII_TXD1      11
+#define MUXF_L2SW_P0_MAC_RMII_CRSDV     12
+#define MUXF_L2SW_P0_MAC_RMII_RXD0      13
+#define MUXF_L2SW_P0_MAC_RMII_RXD1      14
+#define MUXF_L2SW_P0_MAC_RMII_RXER      15
+#define MUXF_L2SW_P1_MAC_RMII_TXEN      16
+#define MUXF_L2SW_P1_MAC_RMII_TXD0      17
+#define MUXF_L2SW_P1_MAC_RMII_TXD1      18
+#define MUXF_L2SW_P1_MAC_RMII_CRSDV     19
+#define MUXF_L2SW_P1_MAC_RMII_RXD0      20
+#define MUXF_L2SW_P1_MAC_RMII_RXD1      21
+#define MUXF_L2SW_P1_MAC_RMII_RXER      22
+#define MUXF_DAISY_MODE                 23
+#define MUXF_SDIO_CLK                   24
+#define MUXF_SDIO_CMD                   25
+#define MUXF_SDIO_D0                    26
+#define MUXF_SDIO_D1                    27
+#define MUXF_SDIO_D2                    28
+#define MUXF_SDIO_D3                    29
+#define MUXF_PWM0                       30
+#define MUXF_PWM1                       31
+#define MUXF_PWM2                       32
+#define MUXF_PWM3                       33
+#define MUXF_PWM4                       34
+#define MUXF_PWM5                       35
+#define MUXF_PWM6                       36
+#define MUXF_PWM7                       37
+#define MUXF_ICM0_D                     38
+#define MUXF_ICM1_D                     39
+#define MUXF_ICM2_D                     40
+#define MUXF_ICM3_D                     41
+#define MUXF_ICM0_CLK                   42
+#define MUXF_ICM1_CLK                   43
+#define MUXF_ICM2_CLK                   44
+#define MUXF_ICM3_CLK                   45
+#define MUXF_SPIM0_INT                  46
+#define MUXF_SPIM0_CLK                  47
+#define MUXF_SPIM0_EN                   48
+#define MUXF_SPIM0_DO                   49
+#define MUXF_SPIM0_DI                   50
+#define MUXF_SPIM1_INT                  51
+#define MUXF_SPIM1_CLK                  52
+#define MUXF_SPIM1_EN                   53
+#define MUXF_SPIM1_DO                   54
+#define MUXF_SPIM1_DI                   55
+#define MUXF_SPIM2_INT                  56
+#define MUXF_SPIM2_CLK                  57
+#define MUXF_SPIM2_EN                   58
+#define MUXF_SPIM2_DO                   59
+#define MUXF_SPIM2_DI                   60
+#define MUXF_SPIM3_INT                  61
+#define MUXF_SPIM3_CLK                  62
+#define MUXF_SPIM3_EN                   63
+#define MUXF_SPIM3_DO                   64
+#define MUXF_SPIM3_DI                   65
+#define MUXF_SPI0S_INT                  66
+#define MUXF_SPI0S_CLK                  67
+#define MUXF_SPI0S_EN                   68
+#define MUXF_SPI0S_DO                   69
+#define MUXF_SPI0S_DI                   70
+#define MUXF_SPI1S_INT                  71
+#define MUXF_SPI1S_CLK                  72
+#define MUXF_SPI1S_EN                   73
+#define MUXF_SPI1S_DO                   74
+#define MUXF_SPI1S_DI                   75
+#define MUXF_SPI2S_INT                  76
+#define MUXF_SPI2S_CLK                  77
+#define MUXF_SPI2S_EN                   78
+#define MUXF_SPI2S_DO                   79
+#define MUXF_SPI2S_DI                   80
+#define MUXF_SPI3S_INT                  81
+#define MUXF_SPI3S_CLK                  82
+#define MUXF_SPI3S_EN                   83
+#define MUXF_SPI3S_DO                   84
+#define MUXF_SPI3S_DI                   85
+#define MUXF_I2CM0_CLK                  86
+#define MUXF_I2CM0_DAT                  87
+#define MUXF_I2CM1_CLK                  88
+#define MUXF_I2CM1_DAT                  89
+#define MUXF_I2CM2_CLK                  90
+#define MUXF_I2CM2_DAT                  91
+#define MUXF_I2CM3_CLK                  92
+#define MUXF_I2CM3_DAT                  93
+#define MUXF_UA1_TX                     94
+#define MUXF_UA1_RX                     95
+#define MUXF_UA1_CTS                    96
+#define MUXF_UA1_RTS                    97
+#define MUXF_UA2_TX                     98
+#define MUXF_UA2_RX                     99
+#define MUXF_UA2_CTS                    100
+#define MUXF_UA2_RTS                    101
+#define MUXF_UA3_TX                     102
+#define MUXF_UA3_RX                     103
+#define MUXF_UA3_CTS                    104
+#define MUXF_UA3_RTS                    105
+#define MUXF_UA4_TX                     106
+#define MUXF_UA4_RX                     107
+#define MUXF_UA4_CTS                    108
+#define MUXF_UA4_RTS                    109
+#define MUXF_TIMER0_INT                 110
+#define MUXF_TIMER1_INT                 111
+#define MUXF_TIMER2_INT                 112
+#define MUXF_TIMER3_INT                 113
+#define MUXF_GPIO_INT0                  114
+#define MUXF_GPIO_INT1                  115
+#define MUXF_GPIO_INT2                  116
+#define MUXF_GPIO_INT3                  117
+#define MUXF_GPIO_INT4                  118
+#define MUXF_GPIO_INT5                  119
+#define MUXF_GPIO_INT6                  120
+#define MUXF_GPIO_INT7                  121
+
+#define GROP_SPI_FLASH                  122
+#define GROP_SPI_FLASH_4BIT             123
+#define GROP_SPI_NAND                   124
+#define GROP_CARD0_EMMC                 125
+#define GROP_SD_CARD                    126
+#define GROP_UA0                        127
+#define GROP_ACHIP_DEBUG                128
+#define GROP_ACHIP_UA2AXI               129
+#define GROP_FPGA_IFX                   130
+#define GROP_HDMI_TX                    131
+#define GROP_AUD_EXT_ADC_IFX0           132
+#define GROP_AUD_EXT_DAC_IFX0           133
+#define GROP_SPDIF_RX                   134
+#define GROP_SPDIF_TX                   135
+#define GROP_TDMTX_IFX0                 136
+#define GROP_TDMRX_IFX0                 137
+#define GROP_PDMRX_IFX0                 138
+#define GROP_PCM_IEC_TX                 139
+#define GROP_LCDIF                      140
+#define GROP_DVD_DSP_DEBUG              141
+#define GROP_I2C_DEBUG                  142
+#define GROP_I2C_SLAVE                  143
+#define GROP_WAKEUP                     144
+#define GROP_UART2AXI                   145
+#define GROP_USB0_I2C                   146
+#define GROP_USB1_I2C                   147
+#define GROP_USB0_OTG                   148
+#define GROP_USB1_OTG                   149
+#define GROP_UPHY0_DEBUG                150
+#define GROP_UPHY1_DEBUG                151
+#define GROP_UPHY0_EXT                  152
+#define GROP_PROBE_PORT                 153
+#define GROP_ANA_I2C_IF                 154
+#define GROP_ANA_TEST_IF                155
+
+#endif
include/dt-bindings/pinctrl/sppctl.h new file +40 -0
new file mode 100644
index 0000000..3e82989
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SP7021 pinmux pinctrl bindings.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_PINCTRL_SPPCTL_H
+#define _DT_BINDINGS_PINCTRL_SPPCTL_H
+
+#define IOP_G_MASTE             (0x01<<0)
+#define IOP_G_FIRST             (0x01<<1)
+
+#define SPPCTL_PCTL_G_PMUX      (0x00|IOP_G_MASTE)
+#define SPPCTL_PCTL_G_GPIO      (IOP_G_FIRST|IOP_G_MASTE)
+#define SPPCTL_PCTL_G_IOPP      (IOP_G_FIRST|0x00)
+
+#define SPPCTL_PCTL_L_OUT       (0x01<<0)
+#define SPPCTL_PCTL_L_OU1       (0x01<<1)
+#define SPPCTL_PCTL_L_INV       (0x01<<2)
+#define SPPCTL_PCTL_L_ONV       (0x01<<3)
+#define SPPCTL_PCTL_L_ODR       (0x01<<4)
+
+#define SPPCTL_PCTLE_P(v)       ((v)<<24)
+#define SPPCTL_PCTLE_G(v)       ((v)<<16)
+#define SPPCTL_PCTLE_F(v)       ((v)<<8)
+#define SPPCTL_PCTLE_L(v)       ((v)<<0)
+
+#define SPPCTL_PCTLD_P(v)       (((v)>>24) & 0xFF)
+#define SPPCTL_PCTLD_G(v)       (((v)>>16) & 0xFF)
+#define SPPCTL_PCTLD_F(v)       (((v) >> 8) & 0xFF)
+#define SPPCTL_PCTLD_L(v)       (((v) >> 0) & 0xFF)
+
+/*
+ * pack into 32-bit value:
+ * pin#{8bit}, typ{8bit}, function{8bit}, flags{8bit}
+ */
+#define SPPCTL_IOPAD(pin, typ, fun, fls) (((pin)<<24)|((typ)<<16)|((fun)<<8)|(fls))
+
+#endif
Signature · 1 line
2.7.4
maintainer
#18 lore raw

Re: [PATCH v2 3/3] devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

In reply to Wells Lu
Quoted 1 line · Wells Lu

Add bindings documentation for Sunplus SP7021.

Patch 2 and 3 can be combined. Use consistent subjects. Patch 2 is good. This one is not.

Quoted 59 lines

---
Changes in v2:
- None

 .../bindings/pinctrl/sunplus,sp7021-pinctrl.yaml   | 277 +++++++++++++++++++++
 MAINTAINERS                                        |   1 +
 2 files changed, 278 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +42 -0
new file mode 100644
index 0000000..7cfa0ce
@@ -0,0 +1,277 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pinctrl/sunplus,sp7021-pinctrl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 Pin Controller Device Tree Bindings
+
+maintainers:
+  - Dvorkin Dmitry <[email protected]>
+  - Wells Lu <[email protected]>
+
+description: |
+  The Sunplus SP7021 pin controller is used to control SoC pins. Please
+  refer to pinctrl-bindings.txt in this directory for details of the common
+  pinctrl bindings used by client devices.
+
+  Refer to https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/pages/
+  1443495991/How+to+setup+pins+of+SP7021+in+device-tree+source
+
+  The device node of pin controller of Sunplus SP7021 has following
+  properties.
+
+properties:
+  compatible:
+    const: sunplus,sp7021-pctl
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+  reg:
+    items:
+      - description: Base address and length of the MOON2 registers.
+      - description: Base address and length of the GPIOXT registers.
+      - description: Base address and length of the GPIOXT2 registers.
+      - description: Base address and length of the FIRST registers.
+      - description: Base address and length of the MOON1 registers.
+
+  clocks:

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 52

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +10 -0
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+patternProperties:
+  '^.*$':
+    if:
+      type: object
+    then:

For new bindings, don't use this hack. Make the node name something you can match on (e.g. '-pins$').

Quoted 169 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +169 -0
+      description: |
+        A pinctrl node should contain at least one subnodes representing the
+        pins or function-pins group available on the machine. Each subnode
+        will list the pins it needs, and how they should be configured.
+
+        Pinctrl node's client devices use subnodes for desired pin
+        configuration. Client device subnodes use below standard properties.
+
+      properties:
+        pins:
+          description: |
+            Define pins which are used by pinctrl node's client device.
+
+            It consists of one or more integers which represents the config
+            setting for corresponding pin. Please use macro SPPCTL_IOPAD to
+            define the integers for pins.
+
+            The first argument of the macro is pin number, the second is pin
+            type, the third is type of GPIO, the last is default output state
+            of GPIO.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+        function:
+          description: |
+            Define pin-function which is used by pinctrl node's client device.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH, SPI_FLASH_4BIT, SPI_NAND, CARD0_EMMC, SD_CARD,
+                  UA0, FPGA_IFX, HDMI_TX, LCDIF, USB0_OTG, USB1_OTG ]
+
+        groups:
+          description: |
+            Define pin-group in a specified pin-function.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH1, SPI_FLASH2, SPI_FLASH_4BIT1, SPI_FLASH_4BIT2,
+                  SPI_NAND, CARD0_EMMC, SD_CARD, UA0, FPGA_IFX, HDMI_TX1,
+                  HDMI_TX2, HDMI_TX3, LCDIF, USB0_OTG, USB1_OTG ]
+
+        zero_func:
+          description: |
+            Disabled pins which are not used by pinctrl node's client device.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+      additionalProperties: false
+
+      allOf:
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH1
+                  - SPI_FLASH2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH_4BIT
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH_4BIT1
+                  - SPI_FLASH_4BIT2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_NAND
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_NAND
+        - if:
+            properties:
+              function:
+                enum:
+                  - CARD0_EMMC
+          then:
+            properties:
+              groups:
+                enum:
+                  - CARD0_EMMC
+        - if:
+            properties:
+              function:
+                enum:
+                  - SD_CARD
+          then:
+            properties:
+              groups:
+                enum:
+                  - SD_CARD
+        - if:
+            properties:
+              function:
+                enum:
+                  - UA0
+          then:
+            properties:
+              groups:
+                enum:
+                  - UA0
+        - if:
+            properties:
+              function:
+                enum:
+                  - FPGA_IFX
+          then:
+            properties:
+              groups:
+                enum:
+                  - FPGA_IFX
+        - if:
+            properties:
+              function:
+                enum:
+                  - HDMI_TX
+          then:
+            properties:
+              groups:
+                enum:
+                  - HDMI_TX1
+                  - HDMI_TX2
+                  - HDMI_TX3
+        - if:
+            properties:
+              function:
+                enum:
+                  - LCDIF
+          then:
+            properties:
+              groups:
+                enum:
+                  - LCDIF
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB0_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB0_OTG
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB1_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB1_OTG
+
+required:
+  - compatible
+  - reg
+  - "#gpio-cells"
+  - gpio-controller
+  - clocks
+  - resets

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 231

Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +10 -0
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sp-sp7021.h>
+    #include <dt-bindings/reset/sp-sp7021.h>
+    #include <dt-bindings/pinctrl/sppctl-sp7021.h>
+
+    pctl: pctl@9C000100 {

pinctl@9c000100

Quoted 62 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +46 -0
+        compatible = "sunplus,sp7021-pctl";
+        reg = <0x9C000100 0x100>, <0x9C000300 0x80>, <0x9C000380 0x80>,
+              <0x9C0032e4 0x1C>, <0x9C000080 0x20>;
+        gpio-controller;
+        #gpio-cells = <2>;
+        clocks = <&clkc GPIO>;
+        resets = <&rstc RST_GPIO>;
+
+        pins_uart0: pins_uart0 {
+            function = "UA0";
+            groups = "UA0";
+        };
+
+        pins_uart1: pins_uart1 {
+            pins = <
+                SPPCTL_IOPAD(11,SPPCTL_PCTL_G_PMUX,MUXF_UA1_TX,0)
+                SPPCTL_IOPAD(10,SPPCTL_PCTL_G_PMUX,MUXF_UA1_RX,0)
+                SPPCTL_IOPAD(7,SPPCTL_PCTL_G_GPIO,0,SPPCTL_PCTL_L_OUT)
+            >;
+        };
+
+        emmc_mux: emmc_mux {
+            function = "CARD0_EMMC";
+            groups = "CARD0_EMMC";
+        };
+
+        mmc1_mux: mmc1_mux {
+            function = "SD_CARD";
+            groups = "SD_CARD";
+            pins = < SPPCTL_IOPAD(91,SPPCTL_PCTL_G_GPIO,0,0) >;
+        };
+
+        hdmi_A_tx1: hdmi_A_tx1_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX1";
+        };
+        hdmi_A_tx2: hdmi_A_tx2_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX2";
+        };
+        hdmi_A_tx3: hdmi_A_tx3_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX3";
+        };
+    };
+...
MAINTAINERS +1 -0
index da6378f..11835e7 100644
@@ -14872,6 +14872,7 @@ M:	Wells Lu <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
+F:	Documentation/devicetree/bindings/pinctrl/sunplus,*
 F:	drivers/pinctrl/sunplus/
 F:	include/dt-bindings/pinctrl/sppctl*
 
Signature · 1 line
2.7.4
#13 lore raw

RE: [PATCH v2 1/3] pinctrl: Add driver for Sunplus SP7021

In reply to Linus Walleij

Hi Linus,

Thanks for review and sorry for late reply.

Quoted 22 lines

Hi Wells Lu,

thanks for your patch!

This driver needs a bit of work, I will point out some things and I think it will be quite different if we also change the bindings.

drivers/pinctrl/sunplus/Kconfig line 17

Quoted 12 lines · Wells Lu
drivers/pinctrl/sunplus/Kconfig new file +12 -0
+config PINCTRL_SPPCTL
+       bool "Sunplus SP7021 pinmux and GPIO driver"
+       depends on SOC_SP7021
+       depends on OF && HAS_IOMEM
+       select PINMUX
+       select GENERIC_PINCTRL_GROUPS
+       select GENERIC_PINMUX_FUNCTIONS
+       select PINCONF
+       select GENERIC_PINCONF
+       select OF_GPIO
+       select GPIOLIB
+       select GPIO_SYSFS
Quoted 1 line

Don't do this, sysfs is deprecated.

Yes, I'll remove 'select GPIO_SYSFS' in next patch.

Quoted 10 lines

drivers/pinctrl/sunplus/Makefile line 11

Quoted 7 lines
drivers/pinctrl/sunplus/Makefile new file +7 -0
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_pinctrl.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_sysfs.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_gpio_ops.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl_gpio.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += pinctrl_inf_sp7021.o
+obj-$(CONFIG_PINCTRL_SPPCTL) += gpio_inf_sp7021.o

This multitide of files makes this a bit hard to read and review, usually pin controllers are in one-two files for a single SoC.

Yes, I'll re-arrange files into two files in next patch.

sppctl.c sppctl.h -- for SoC-irrelevant code.
sppctl_sp7021.c -- for SoC-relevant code.

Is this arrangement ok?

Quoted 12 lines
Quoted 11 lines

+ * This program is free software; you can redistribute it and/or
+ modify
+ * it under the terms of the GNU General Public License as published
+ by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.

Quoted 1 line

Drop this boilerplate on all files and just use the SPDX tag.

Yes, I'll remove them in next patch.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+const size_t GPIS_listSZ =
+sizeof(sppctlgpio_list_s)/sizeof(*(sppctlgpio_list_s));

Use only lowercase in variable names.

Yes, I'll check and use lowercase for all variable names in next patch.

Quoted 1 line

This looks like a reimplementation of ARRAY_SIZE(), replace with that if this is the case.

Yes, I'll replace the statement with using ARRAY_SIZE() in next patch.

Quoted 4 lines
Quoted 1 line

+const size_t sppctlpins_allSZ = ARRAY_SIZE(sppctlpins_all);

Instead of defining consts for random sizes like this, just inline ARRAY_SIZE() where you use it.

The array 'sppctlpins_all' is defined without explicit size. ARRAY_SIZE won't work if it is not placed with define (within the same file).

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+// gpio: is defined in gpio_inf_sp7021.c const size_t PMUX_listSZ =
+sizeof(sppctlpmux_list_s)/sizeof(*(sppctlpmux_list_s));

Same comment as above. Etc.

Yes, I'll replace the statement with using ARRAY_SIZE() in next patch.

Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* CEC pin is not used. Release it for others. */ //static const
+unsigned int pins_hdmi1[] = { D(10, 6), D(10, 7), D(12, 2), D(12, 1)
+}; //static const unsigned int pins_hdmi2[] = { D(8, 3), D(8, 4),
+D(8, 5), D(8, 6) }; //static const unsigned int pins_hdmi3[] = { D(7,
+4), D(7, 5), D(7, 6), D(7, 7) };

Don't leave commented-out code in the driver. Delete all this stuff.

Yes, I'll remove them in next patch.

Quoted 25 lines
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6 -0
+void print_device_tree_node(struct device_node *node, int depth) {
+       int i = 0;
+       struct device_node *child;
+       struct property    *properties;
+       char                indent[255] = "";
+

drivers/pinctrl/sunplus/sppctl.c

Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.c new file +10 -0
+       for (i = 0; i < depth * 3; i++)
+               indent[i] = ' ';
+       indent[i] = '\0';
+
+       ++depth;
+       if (depth == 1) {
+               pr_info("%s{ name = %s\n", indent, node->name);
+               for (properties = node->properties; properties != NULL;
+                       properties = properties->next)
+                       pr_info("%s  %s (%d)\n", indent, properties->name,

properties->length);

drivers/pinctrl/sunplus/sppctl.c

Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c new file +8 -0
+               pr_info("%s}\n", indent);
+       }
+
+       for_each_child_of_node(node, child) {
+               pr_info("%s{ name = %s\n", indent, child->name);
+               for (properties = child->properties; properties != NULL;
+                       properties = properties->next)
+                       pr_info("%s  %s (%d)\n", indent, properties->name,
Quoted 7 lines

properties->length);

drivers/pinctrl/sunplus/sppctl.c line 55

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.c new file +4 -0
+               print_device_tree_node(child, depth);
+               pr_info("%s}\n", indent);
+       }
+}

This kind of debugging code should be deleted or use what is in the device tree core.

Yes, I'll remove them in next patch.
Could you please teach me which function I can use to print dt-node in core?

Quoted 7 lines
Quoted 1 line

+void sppctl_gmx_set(struct sppctl_pdata_t *_p, uint8_t _roff, uint8_t _boff, uint8_t

_bsiz,

drivers/pinctrl/sunplus/sppctl.c line 60

Quoted 3 lines
drivers/pinctrl/sunplus/sppctl.c new file +3 -0
+                   uint8_t _rval)
+{
+       uint32_t *r;

Don't use uint8_t or uint16_t or uint32_t, use the kernel short forms u8, u16 or u32, simply.

Yes, I'll replace them with kernel short forms u8, u16, u32 in next patch.

Quoted 4 lines

Don't start any variable names with _underscore, it i a big confusion for the head because it has ambigous semantics.

Try to find concise descriptive variable names.

Yes, I'll review variables name with underscore prefix and give proper name in next patch

Quoted 8 lines

drivers/pinctrl/sunplus/sppctl.c line 66

Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6 -0
+       struct sppctl_reg_t x = { .m = (~(~0 << _bsiz)) << _boff,
+                                 .v = ((uint16_t)_rval) << _boff };
+
+       if (_p->debug > 1)
+               KDBG(_p->pcdp->dev, "%s(x%X,x%X,x%X,x%X) m:x%X v:x%X\n",
+                    __func__, _roff, _boff, _bsiz, _rval, x.m, x.v);

Do not reinvent kernel debugging use the dev_dbg() macro.

Yes, I'll replace KDBG with dev_dbg() in next patch.

Quoted 3 lines
Quoted 1 line

+ r = (uint32_t *)&x;

Try to avoid casting like this. It is usually a sign that something is wrong.

Yes, I'll review and remove the casting in next patch.

Quoted 10 lines

drivers/pinctrl/sunplus/sppctl.c line 98

Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.c new file +6 -0
+       if (_fun % 2 == 0)
+               ;
+       else {
+               x.v <<= 8;
+               x.m <<= 8;
+       }

This is code that is incredibly terse and deviant from the kernels general style. Please read a few other pin control drivers and familiarize with how these drivers usually look.

Yes, I'll study other drivers and modify them.

Quoted 6 lines

drivers/pinctrl/sunplus/sppctl.c line 111

Quoted 3 lines
drivers/pinctrl/sunplus/sppctl.c new file +3 -0
+uint8_t sppctl_fun_get(struct sppctl_pdata_t *_p,  uint8_t _fun) {
+       uint8_t pin = 0x00;
+       uint8_t func = (_fun >> 1) << 2;

This looks like shifting to get rid of bit 0.
Just use bitwise logic instead.

Yes, I'll replace 'shift' with bitwise logic operation in next patch.

Quoted 6 lines

drivers/pinctrl/sunplus/sppctl.c line 165

Quoted 2 lines
drivers/pinctrl/sunplus/sppctl.c new file +2 -0
+       ret = request_firmware_nowait(THIS_MODULE, true, _fwname, _dev, GFP_KERNEL, p,
+                                     sppctl_fwload_cb);

So this pin controller needs a firmware? That is the first time I have ever seen that. Please add comments describing what this firmware is and what it does, also explain it in the commit message.

No, it restores pins settings from a file.
The driver supports saving pin-settings to a file and restoring pin-settings from a file.

Quoted 7 lines
Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.c new file +7 -0
+int sppctl_pctl_resmap(struct platform_device *_pd, struct
+sppctl_pdata_t *_pc) {
+       struct resource *rp;
+
+       // resF
+       rp = platform_get_resource(_pd, IORESOURCE_MEM, 0);
+       if (IS_ERR(rp)) {
Quoted 8 lines

drivers/pinctrl/sunplus/sppctl.c line 180

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.c new file +4 -0
+               KERR(&(_pd->dev), "%s get res#F ERR\n", __func__);
+               return PTR_ERR(rp);
+       }
+       KDBG(&(_pd->dev), "mres #F:%p\n", rp);

Thes resF etc are very terse and hard to understand. It seems written by someone who knows everything of what they are doing but with very little interest to explain it to others. Code readability is important.

Yes, I'll rename the variable name to improve code readability in next patch.

Quoted 6 lines

drivers/pinctrl/sunplus/sppctl.c line 336

Quoted 3 lines
drivers/pinctrl/sunplus/sppctl.c new file +3 -0
+static struct platform_driver sppctl_driver = {
+       .driver = {
+               .name           = MNAME,

Don't abbreviate so compulsively.
SP7021_MODULE_NAME is fine.

Yes, I'll rename the defines to SPPCTL_MODULE_NAME in next patch.

Quoted 7 lines

drivers/pinctrl/sunplus/sppctl.c line 348

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.c new file +4 -0
+static int __init sppctl_drv_reg(void) {
+       return platform_driver_register(&sppctl_driver);
+}
+postcore_initcall(sppctl_drv_reg);

Why do you need a postcore_initcall()?

postcore_initcall() is added here to make sure pinctrl driver will be loaded before other drivers which need pin settings. With moving pinctrl driver earlier, HDMI-TX driver will be loaded earlier.

Quoted 6 lines

drivers/pinctrl/sunplus/sppctl.c line 359

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.c new file +4 -0
+MODULE_AUTHOR(M_AUT1);
+MODULE_AUTHOR(M_AUT2);
+MODULE_DESCRIPTION(M_NAM);
+MODULE_LICENSE(M_LIC);

Just inline the strings, all other drivers do.

Yes, I'll use fixed string directly here in next patch.

Quoted 9 lines

drivers/pinctrl/sunplus/sppctl.h line 27

Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.h new file +7 -0
+#define MNAME "sppctl"
+#define M_LIC "GPL v2"
+#define M_AUT1 "Dvorkin Dmitry <[email protected]>"
+#define M_AUT2 "Wells Lu <[email protected]>"
+#define M_NAM "SP7021 PinCtl"
+#define M_ORG "Sunplus/Tibbo Tech."
+#define M_CPR "(C) 2020"

This is too much and too abbreviated names, just use the strings directly in the macros.

Yes, I'll do it in next patch.

Quoted 3 lines
Quoted 1 line

+#include <linux/version.h>

Why?

I'll remove the inclusion in next patch.
It is indeed not necessary.

Quoted 3 lines
Quoted 1 line

+#include <linux/of_gpio.h>

Never use this include in new code. It is legacy.

I'll remove the inclusion in next patch.

Quoted 33 lines
Quoted 18 lines
drivers/pinctrl/sunplus/sppctl.h new file +18 -0
+#define SPPCTL_MAX_NAM 64
+#define SPPCTL_MAX_BUF PAGE_SIZE
+
+#define KINF(pd, fmt, args...) \
+       do { \
+               if ((pd) != NULL) \
+                       dev_info((pd), fmt, ##args); \
+               else \
+                       pr_info(MNAME ": " fmt, ##args); \
+       } while (0)
+#define KERR(pd, fmt, args...) \
+       do { \
+               if ((pd) != NULL) \
+                       dev_info((pd), fmt, ##args); \
+               else \
+                       pr_err(MNAME ": " fmt, ##args); \
+       } while (0)
+#ifdef CONFIG_PINCTRL_SPPCTL_DEBUG

drivers/pinctrl/sunplus/sppctl.h line 79

Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.h new file +10 -0
+#define KDBG(pd, fmt, args...) \
+       do { \
+               if ((pd) != NULL) \
+                       dev_info((pd), fmt, ##args); \
+               else \
+                       pr_debug(MNAME ": " fmt, ##args); \
+       } while (0)
+#else
+#define KDBG(pd, fmt, args...)
+#endif

Don't reimplement kernel debugging use dev_dbg(), dev_info()
dev_err() etc directly. I don't see why you need CONFIG_PINCTRL_SPPCTL_DEBUG at all, if you absolutely want to control debugging for these files only just use this in your Makefile

Quoted 3 lines

subdir-ccflags-$(CONFIG_PINCTRL_SPPCTL_DEBUG) := -DDEBUG

This will turn on/off the output from dev_dbg().

Yes, I'll remove KINF, KERR, KDB macros and use kernel debugging functions dev_info(), dev_err(), dev_info() in next patch.

Quoted 5 lines

drivers/pinctrl/sunplus/sppctl.h line 85

Quoted 3 lines
drivers/pinctrl/sunplus/sppctl.h new file +3 -0
+struct sppctl_pdata_t {
+       char name[SPPCTL_MAX_NAM];
+       uint8_t debug;

Don't use u8 for things like this use bool.

Yes, I'll remove 'debug' member and customized debug function will be removed.

Quoted 13 lines

drivers/pinctrl/sunplus/sppctl.h line 97

Quoted 12 lines
drivers/pinctrl/sunplus/sppctl.h new file +12 -0
+       char fwname[SPPCTL_MAX_NAM];
+       void *sysfs_sdp;
+       void __iomem *baseF;    // functions
+       void __iomem *base0;    // MASTER , OE , OUT , IN
+       void __iomem *base1;    // I_INV , O_INV , OD
+       void __iomem *base2;    // GPIO_FIRST
+       void __iomem *baseI;    // IOP
+       // pinctrl-related
+       struct pinctrl_desc pdesc;
+       struct pinctrl_dev *pcdp;
+       struct pinctrl_gpio_range gpio_range;
+       struct sppctlgpio_chip_t *gpiod;
Quoted 1 line

*gpiod is a bad name because we use it quite a lot in the kernel for GPIO descriptors.

Yes, I'll rename 'gpiod' with '' in next patch.

Quoted 6 lines

drivers/pinctrl/sunplus/sppctl.h line 103

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.h new file +4 -0
+struct sppctl_reg_t {
+       uint16_t v;     // value part
+       uint16_t m;     // mask part
+};

These are not types (no typedef) so don't add *_t suffixes, just drop those everywhere.

Yes, I'll remove all _t suffixes in next patch.

Quoted 8 lines

drivers/pinctrl/sunplus/sppctl.h line 127

Quoted 4 lines
drivers/pinctrl/sunplus/sppctl.h new file +4 -0
+       const char * const name;
+       const uint8_t gval;             // value for register
+       const unsigned * const pins;    // list of pins
+       const unsigned int pnum;        // number of pins

Use kerneldoc to document struct members.

There will be many more comments but work on these things to begin with!

I never use kerneldoc. Where should I put my vendor-specified kernel doc?

Quoted 3 lines

Yours,
Linus Walleij

Thank you very much for your review.

Best regards,
Wells

#16 lore raw

RE: [PATCH v2 2/3] dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021

In reply to Rob Herring

Hi,

Thank you for your review.

Quoted 25 lines · Wells Lu

MAINTAINERS L: [email protected] (moderated for

Quoted 18 lines

Add dt-bindings header files for Sunplus SP7021 SoC.

---
Changes in v2:
- Added more 'defines' in dt-bindings header files (forgot to add in v1).

 MAINTAINERS                                 |   1 +
 include/dt-bindings/pinctrl/sppctl-sp7021.h | 171 ++++++++++++++++++++++++++++
 include/dt-bindings/pinctrl/sppctl.h        |  40 +++++++
 3 files changed, 212 insertions(+)
 create mode 100644 include/dt-bindings/pinctrl/sppctl-sp7021.h
 create mode 100644 include/dt-bindings/pinctrl/sppctl.h
MAINTAINERS +0 -0
@@ -14873,6 +14873,7 @@ L:	[email protected] (moderated for

non-subscribers)

Quoted 5 lines
MAINTAINERS +1 -0
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
 F:	drivers/pinctrl/sunplus/
+F:	include/dt-bindings/pinctrl/sppctl*
 
Quoted 12 lines

include/dt-bindings/pinctrl/sppctl-sp7021.h line 1

Quoted 10 lines
MAINTAINERS +0 -0
 PKTCDVD DRIVER
 M:	[email protected]
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +1 -0
new file mode 100644
index 0000000..4e07d03
@@ -0,0 +1,171 @@
+/* SPDX-License-Identifier: GPL-2.0 */

Care about OS other than Linux? Should be dual licensed.

Yes, I'll add dual license for dt-binding header file.

Quoted 6 lines
Quoted 6 lines
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +6 -0
+/*
+ * SP7021 pinmux pinctrl bindings.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>  */
+
+#ifndef _DT_BINDINGS_PINCTRL_SPPCTL_SP7021_H
Quoted 8 lines

include/dt-bindings/pinctrl/sppctl-sp7021.h line 13

Quoted 5 lines
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +5 -0
+#define _DT_BINDINGS_PINCTRL_SPPCTL_SP7021_H
+
+#include <dt-bindings/pinctrl/sppctl.h>
+
+#define MUXF_GPIO                       0

Where do these numbers come from? Hopefully they correspond to register offsets and aren't made up. A comment either way here would help.

The numbers are based on define of hardware. SP7021 supports so-called 'fully pin-mux' function. GPIO8 ~ GPIO71 are 'fully pin-mux' pins

For example,
If I set pin-mux register of GPIO8 to 1, GPIO8 will output L2SW_CLK_OUT signal.

If I set pin-mux register of GPIO8 to 2, GPIO8 will output L2SW_MAC_SMI_MDC signal.

If I set pin-mux register of GPIO8 to 7, GPIO8 will output L2SW_MAC_SMI_DMIO signal.

In fact, all signals from number 2 to 121, can be selected to output to any fully pin-mux pins (GPIO8 ~ GPIO71).

Numbers 121 to 155 are also based on define of hardware. It is used to turn off specific pin-function. With the number, drivers can calculate the control-bit easily.

Quoted 208 lines
Quoted 208 lines
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +158 -0
+#define MUXF_IOP                        1
+#define MUXF_L2SW_CLK_OUT               2
+#define MUXF_L2SW_MAC_SMI_MDC           3
+#define MUXF_L2SW_LED_FLASH0            4
+#define MUXF_L2SW_LED_FLASH1            5
+#define MUXF_L2SW_LED_ON0               6
+#define MUXF_L2SW_LED_ON1               7
+#define MUXF_L2SW_MAC_SMI_MDIO          8
+#define MUXF_L2SW_P0_MAC_RMII_TXEN      9
+#define MUXF_L2SW_P0_MAC_RMII_TXD0      10
+#define MUXF_L2SW_P0_MAC_RMII_TXD1      11
+#define MUXF_L2SW_P0_MAC_RMII_CRSDV     12
+#define MUXF_L2SW_P0_MAC_RMII_RXD0      13
+#define MUXF_L2SW_P0_MAC_RMII_RXD1      14
+#define MUXF_L2SW_P0_MAC_RMII_RXER      15
+#define MUXF_L2SW_P1_MAC_RMII_TXEN      16
+#define MUXF_L2SW_P1_MAC_RMII_TXD0      17
+#define MUXF_L2SW_P1_MAC_RMII_TXD1      18
+#define MUXF_L2SW_P1_MAC_RMII_CRSDV     19
+#define MUXF_L2SW_P1_MAC_RMII_RXD0      20
+#define MUXF_L2SW_P1_MAC_RMII_RXD1      21
+#define MUXF_L2SW_P1_MAC_RMII_RXER      22
+#define MUXF_DAISY_MODE                 23
+#define MUXF_SDIO_CLK                   24
+#define MUXF_SDIO_CMD                   25
+#define MUXF_SDIO_D0                    26
+#define MUXF_SDIO_D1                    27
+#define MUXF_SDIO_D2                    28
+#define MUXF_SDIO_D3                    29
+#define MUXF_PWM0                       30
+#define MUXF_PWM1                       31
+#define MUXF_PWM2                       32
+#define MUXF_PWM3                       33
+#define MUXF_PWM4                       34
+#define MUXF_PWM5                       35
+#define MUXF_PWM6                       36
+#define MUXF_PWM7                       37
+#define MUXF_ICM0_D                     38
+#define MUXF_ICM1_D                     39
+#define MUXF_ICM2_D                     40
+#define MUXF_ICM3_D                     41
+#define MUXF_ICM0_CLK                   42
+#define MUXF_ICM1_CLK                   43
+#define MUXF_ICM2_CLK                   44
+#define MUXF_ICM3_CLK                   45
+#define MUXF_SPIM0_INT                  46
+#define MUXF_SPIM0_CLK                  47
+#define MUXF_SPIM0_EN                   48
+#define MUXF_SPIM0_DO                   49
+#define MUXF_SPIM0_DI                   50
+#define MUXF_SPIM1_INT                  51
+#define MUXF_SPIM1_CLK                  52
+#define MUXF_SPIM1_EN                   53
+#define MUXF_SPIM1_DO                   54
+#define MUXF_SPIM1_DI                   55
+#define MUXF_SPIM2_INT                  56
+#define MUXF_SPIM2_CLK                  57
+#define MUXF_SPIM2_EN                   58
+#define MUXF_SPIM2_DO                   59
+#define MUXF_SPIM2_DI                   60
+#define MUXF_SPIM3_INT                  61
+#define MUXF_SPIM3_CLK                  62
+#define MUXF_SPIM3_EN                   63
+#define MUXF_SPIM3_DO                   64
+#define MUXF_SPIM3_DI                   65
+#define MUXF_SPI0S_INT                  66
+#define MUXF_SPI0S_CLK                  67
+#define MUXF_SPI0S_EN                   68
+#define MUXF_SPI0S_DO                   69
+#define MUXF_SPI0S_DI                   70
+#define MUXF_SPI1S_INT                  71
+#define MUXF_SPI1S_CLK                  72
+#define MUXF_SPI1S_EN                   73
+#define MUXF_SPI1S_DO                   74
+#define MUXF_SPI1S_DI                   75
+#define MUXF_SPI2S_INT                  76
+#define MUXF_SPI2S_CLK                  77
+#define MUXF_SPI2S_EN                   78
+#define MUXF_SPI2S_DO                   79
+#define MUXF_SPI2S_DI                   80
+#define MUXF_SPI3S_INT                  81
+#define MUXF_SPI3S_CLK                  82
+#define MUXF_SPI3S_EN                   83
+#define MUXF_SPI3S_DO                   84
+#define MUXF_SPI3S_DI                   85
+#define MUXF_I2CM0_CLK                  86
+#define MUXF_I2CM0_DAT                  87
+#define MUXF_I2CM1_CLK                  88
+#define MUXF_I2CM1_DAT                  89
+#define MUXF_I2CM2_CLK                  90
+#define MUXF_I2CM2_DAT                  91
+#define MUXF_I2CM3_CLK                  92
+#define MUXF_I2CM3_DAT                  93
+#define MUXF_UA1_TX                     94
+#define MUXF_UA1_RX                     95
+#define MUXF_UA1_CTS                    96
+#define MUXF_UA1_RTS                    97
+#define MUXF_UA2_TX                     98
+#define MUXF_UA2_RX                     99
+#define MUXF_UA2_CTS                    100
+#define MUXF_UA2_RTS                    101
+#define MUXF_UA3_TX                     102
+#define MUXF_UA3_RX                     103
+#define MUXF_UA3_CTS                    104
+#define MUXF_UA3_RTS                    105
+#define MUXF_UA4_TX                     106
+#define MUXF_UA4_RX                     107
+#define MUXF_UA4_CTS                    108
+#define MUXF_UA4_RTS                    109
+#define MUXF_TIMER0_INT                 110
+#define MUXF_TIMER1_INT                 111
+#define MUXF_TIMER2_INT                 112
+#define MUXF_TIMER3_INT                 113
+#define MUXF_GPIO_INT0                  114
+#define MUXF_GPIO_INT1                  115
+#define MUXF_GPIO_INT2                  116
+#define MUXF_GPIO_INT3                  117
+#define MUXF_GPIO_INT4                  118
+#define MUXF_GPIO_INT5                  119
+#define MUXF_GPIO_INT6                  120
+#define MUXF_GPIO_INT7                  121
+
+#define GROP_SPI_FLASH                  122
+#define GROP_SPI_FLASH_4BIT             123
+#define GROP_SPI_NAND                   124
+#define GROP_CARD0_EMMC                 125
+#define GROP_SD_CARD                    126
+#define GROP_UA0                        127
+#define GROP_ACHIP_DEBUG                128
+#define GROP_ACHIP_UA2AXI               129
+#define GROP_FPGA_IFX                   130
+#define GROP_HDMI_TX                    131
+#define GROP_AUD_EXT_ADC_IFX0           132
+#define GROP_AUD_EXT_DAC_IFX0           133
+#define GROP_SPDIF_RX                   134
+#define GROP_SPDIF_TX                   135
+#define GROP_TDMTX_IFX0                 136
+#define GROP_TDMRX_IFX0                 137
+#define GROP_PDMRX_IFX0                 138
+#define GROP_PCM_IEC_TX                 139
+#define GROP_LCDIF                      140
+#define GROP_DVD_DSP_DEBUG              141
+#define GROP_I2C_DEBUG                  142
+#define GROP_I2C_SLAVE                  143
+#define GROP_WAKEUP                     144
+#define GROP_UART2AXI                   145
+#define GROP_USB0_I2C                   146
+#define GROP_USB1_I2C                   147
+#define GROP_USB0_OTG                   148
+#define GROP_USB1_OTG                   149
+#define GROP_UPHY0_DEBUG                150
+#define GROP_UPHY1_DEBUG                151
+#define GROP_UPHY0_EXT                  152
+#define GROP_PROBE_PORT                 153
+#define GROP_ANA_I2C_IF                 154
+#define GROP_ANA_TEST_IF                155
+
+#endif
include/dt-bindings/pinctrl/sppctl.h new file +39 -1
new file mode 100644
index 0000000..3e82989
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * SP7021 pinmux pinctrl bindings.
+ * Copyright (C) Sunplus Tech/Tibbo Tech. 2020
+ * Author: Dvorkin Dmitry <[email protected]>  */
+
+#ifndef _DT_BINDINGS_PINCTRL_SPPCTL_H #define
+_DT_BINDINGS_PINCTRL_SPPCTL_H
+
+#define IOP_G_MASTE             (0x01<<0)
+#define IOP_G_FIRST             (0x01<<1)
+
+#define SPPCTL_PCTL_G_PMUX      (0x00|IOP_G_MASTE)
+#define SPPCTL_PCTL_G_GPIO      (IOP_G_FIRST|IOP_G_MASTE)
+#define SPPCTL_PCTL_G_IOPP      (IOP_G_FIRST|0x00)
+
+#define SPPCTL_PCTL_L_OUT       (0x01<<0)
+#define SPPCTL_PCTL_L_OU1       (0x01<<1)
+#define SPPCTL_PCTL_L_INV       (0x01<<2)
+#define SPPCTL_PCTL_L_ONV       (0x01<<3)
+#define SPPCTL_PCTL_L_ODR       (0x01<<4)
+
+#define SPPCTL_PCTLE_P(v)       ((v)<<24)
+#define SPPCTL_PCTLE_G(v)       ((v)<<16)
+#define SPPCTL_PCTLE_F(v)       ((v)<<8)
+#define SPPCTL_PCTLE_L(v)       ((v)<<0)
+
+#define SPPCTL_PCTLD_P(v)       (((v)>>24) & 0xFF)
+#define SPPCTL_PCTLD_G(v)       (((v)>>16) & 0xFF)
+#define SPPCTL_PCTLD_F(v)       (((v) >> 8) & 0xFF)
+#define SPPCTL_PCTLD_L(v)       (((v) >> 0) & 0xFF)
+
+/*
+ * pack into 32-bit value:
+ * pin#{8bit}, typ{8bit}, function{8bit}, flags{8bit}  */ #define
+SPPCTL_IOPAD(pin, typ, fun, fls)
+(((pin)<<24)|((typ)<<16)|((fun)<<8)|(fls))
+
+#endif
--

2.7.4

#19 lore raw

RE: [PATCH v2 3/3] devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

In reply to Rob Herring

Hi,

Thanks for your review.

Quoted 5 lines · Wells Lu
Quoted 1 line

Add bindings documentation for Sunplus SP7021.

Patch 2 and 3 can be combined. Use consistent subjects. Patch 2 is good. This one is not.

Yes, I'll combine patch 2 and 3 into a single patch in next patch series.

Quoted 72 lines
Quoted 72 lines

---
Changes in v2:
- None

 .../bindings/pinctrl/sunplus,sp7021-pinctrl.yaml   | 277 +++++++++++++++++++++
 MAINTAINERS                                        |   1 +
 2 files changed, 278 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml

diff --git a/Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yam l b/Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yam l
new file mode 100644
index 0000000..7cfa0ce

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl new file +50 -0
+++ .yaml
@@ -0,0 +1,277 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) # Copyright
+(C) Sunplus Co., Ltd. 2021 %YAML 1.2
+---
+$id:
+http://devicetree.org/schemas/pinctrl/sunplus,sp7021-pinctrl.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus SP7021 Pin Controller Device Tree Bindings
+
+maintainers:
+  - Dvorkin Dmitry <[email protected]>
+  - Wells Lu <[email protected]>
+
+description: |
+  The Sunplus SP7021 pin controller is used to control SoC pins.
+Please
+  refer to pinctrl-bindings.txt in this directory for details of the
+common
+  pinctrl bindings used by client devices.
+
+  Refer to https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/pages/
+  1443495991/How+to+setup+pins+of+SP7021+in+device-tree+source
+
+  The device node of pin controller of Sunplus SP7021 has following
+ properties.
+
+properties:
+  compatible:
+    const: sunplus,sp7021-pctl
+
+  gpio-controller: true
+
+  '#gpio-cells':
+    const: 2
+
+  reg:
+    items:
+      - description: Base address and length of the MOON2 registers.
+      - description: Base address and length of the GPIOXT registers.
+      - description: Base address and length of the GPIOXT2 registers.
+      - description: Base address and length of the FIRST registers.
+      - description: Base address and length of the MOON1 registers.
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
Quoted 8 lines

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl line 54

Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl new file +5 -0
+patternProperties:
+  '^.*$':
+    if:
+      type: object
+    then:

For new bindings, don't use this hack. Make the node name something you can match on (e.g. '-pins$').

Yes, I'll modify the regular expression to '-pins$' in next patch. Sub-nodes of pinctrl node will look like:

	uart0-pins {
		...
	};

	emmc-pins {
		...
	};
Quoted 173 lines
Quoted 173 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl new file +173 -0
+      description: |
+        A pinctrl node should contain at least one subnodes representing the
+        pins or function-pins group available on the machine. Each subnode
+        will list the pins it needs, and how they should be configured.
+
+        Pinctrl node's client devices use subnodes for desired pin
+        configuration. Client device subnodes use below standard properties.
+
+      properties:
+        pins:
+          description: |
+            Define pins which are used by pinctrl node's client device.
+
+            It consists of one or more integers which represents the config
+            setting for corresponding pin. Please use macro SPPCTL_IOPAD to
+            define the integers for pins.
+
+            The first argument of the macro is pin number, the second is pin
+            type, the third is type of GPIO, the last is default output state
+            of GPIO.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+        function:
+          description: |
+            Define pin-function which is used by pinctrl node's client device.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH, SPI_FLASH_4BIT, SPI_NAND, CARD0_EMMC, SD_CARD,
+                  UA0, FPGA_IFX, HDMI_TX, LCDIF, USB0_OTG, USB1_OTG ]
+
+        groups:
+          description: |
+            Define pin-group in a specified pin-function.
+            The name should be one of string in the following enumeration.
+          $ref: "/schemas/types.yaml#/definitions/string"
+          enum: [ SPI_FLASH1, SPI_FLASH2, SPI_FLASH_4BIT1, SPI_FLASH_4BIT2,
+                  SPI_NAND, CARD0_EMMC, SD_CARD, UA0, FPGA_IFX, HDMI_TX1,
+                  HDMI_TX2, HDMI_TX3, LCDIF, USB0_OTG, USB1_OTG ]
+
+        zero_func:
+          description: |
+            Disabled pins which are not used by pinctrl node's client device.
+          $ref: /schemas/types.yaml#/definitions/uint32-array
+
+      additionalProperties: false
+
+      allOf:
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH1
+                  - SPI_FLASH2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH_4BIT
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH_4BIT1
+                  - SPI_FLASH_4BIT2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_NAND
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_NAND
+        - if:
+            properties:
+              function:
+                enum:
+                  - CARD0_EMMC
+          then:
+            properties:
+              groups:
+                enum:
+                  - CARD0_EMMC
+        - if:
+            properties:
+              function:
+                enum:
+                  - SD_CARD
+          then:
+            properties:
+              groups:
+                enum:
+                  - SD_CARD
+        - if:
+            properties:
+              function:
+                enum:
+                  - UA0
+          then:
+            properties:
+              groups:
+                enum:
+                  - UA0
+        - if:
+            properties:
+              function:
+                enum:
+                  - FPGA_IFX
+          then:
+            properties:
+              groups:
+                enum:
+                  - FPGA_IFX
+        - if:
+            properties:
+              function:
+                enum:
+                  - HDMI_TX
+          then:
+            properties:
+              groups:
+                enum:
+                  - HDMI_TX1
+                  - HDMI_TX2
+                  - HDMI_TX3
+        - if:
+            properties:
+              function:
+                enum:
+                  - LCDIF
+          then:
+            properties:
+              groups:
+                enum:
+                  - LCDIF
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB0_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB0_OTG
+        - if:
+            properties:
+              function:
+                enum:
+                  - USB1_OTG
+          then:
+            properties:
+              groups:
+                enum:
+                  - USB1_OTG
+
+required:
+  - compatible
+  - reg
+  - "#gpio-cells"
+  - gpio-controller
+  - clocks
+  - resets
+
+additionalProperties: false
+
+examples:
Quoted 8 lines

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl line 233

Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl new file +6 -0
+  - |
+    #include <dt-bindings/clock/sp-sp7021.h>
+    #include <dt-bindings/reset/sp-sp7021.h>
+    #include <dt-bindings/pinctrl/sppctl-sp7021.h>
+
+    pctl: pctl@9C000100 {

pinctl@9c000100

Yes, I'll modify node name of pin-ctrl to 'pinctl@9c000100' in next patch.

Quoted 61 lines
Quoted 61 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl new file +46 -0
+        compatible = "sunplus,sp7021-pctl";
+        reg = <0x9C000100 0x100>, <0x9C000300 0x80>, <0x9C000380 0x80>,
+              <0x9C0032e4 0x1C>, <0x9C000080 0x20>;
+        gpio-controller;
+        #gpio-cells = <2>;
+        clocks = <&clkc GPIO>;
+        resets = <&rstc RST_GPIO>;
+
+        pins_uart0: pins_uart0 {
+            function = "UA0";
+            groups = "UA0";
+        };
+
+        pins_uart1: pins_uart1 {
+            pins = <
+                SPPCTL_IOPAD(11,SPPCTL_PCTL_G_PMUX,MUXF_UA1_TX,0)
+                SPPCTL_IOPAD(10,SPPCTL_PCTL_G_PMUX,MUXF_UA1_RX,0)
+                SPPCTL_IOPAD(7,SPPCTL_PCTL_G_GPIO,0,SPPCTL_PCTL_L_OUT)
+            >;
+        };
+
+        emmc_mux: emmc_mux {
+            function = "CARD0_EMMC";
+            groups = "CARD0_EMMC";
+        };
+
+        mmc1_mux: mmc1_mux {
+            function = "SD_CARD";
+            groups = "SD_CARD";
+            pins = < SPPCTL_IOPAD(91,SPPCTL_PCTL_G_GPIO,0,0) >;
+        };
+
+        hdmi_A_tx1: hdmi_A_tx1_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX1";
+        };
+        hdmi_A_tx2: hdmi_A_tx2_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX2";
+        };
+        hdmi_A_tx3: hdmi_A_tx3_pins {
+            function = "HDMI_TX";
+            groups = "HDMI_TX3";
+        };
+    };
+...
MAINTAINERS +1 -1
@@ -14872,6 +14872,7 @@ M:	Wells Lu <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
 W:	https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
+F:	Documentation/devicetree/bindings/pinctrl/sunplus,*
 F:	drivers/pinctrl/sunplus/
 F:	include/dt-bindings/pinctrl/sppctl*
 
--

2.7.4

maintainer
#9 lore raw

Re: [PATCH 3/3] devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

In reply to a message not in the archive

Dear Linus!

I am the person who wrote this driver. Let me answer to your questions...

-----Original Message-----

Quoted 10 lines
Quoted 10 lines

From: Linus Walleij <[email protected]>
Sent: Tuesday, November 9, 2021 12:00 PM
To: Wells Lu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wells Lu 呂芳騰 <[email protected]>
Subject: Re: [PATCH 3/3] devicetree: bindings: pinctrl: Add bindings doc for Sunplus SP7021.

Quoted 7 lines
Quoted 7 lines

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml

Quoted 3 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +3 -0
+        zero_func:
+          description: |
+            Disabled pins which are not used by pinctrl node's client

device.

Quoted 1 line

+ $ref: /schemas/types.yaml#/definitions/uint32-array

I have never seen this before. Can't you just use pin control hogs for this so the pin controller just take care of these pins?

zero_func is required.

The bootloader may have different device tree (I am using general sp7021 DTS in my u-boot setup, for example), while the kernel DTS may be changed between boots and specifies it more precisely - it is configured by user. So u-boot DTB and kernel DTB may be different -> result is that some pins may be muxed wrongly after u-boot starts kernel. Or even in pre-u-boot stage (we have the bootloader that starts u-boot, called XBoot). This XBoot also do some muxing. So we need this feature to get rid of possible unneded muxes done before kernel has been started.

There is the "group of pins" functions and individual pins that may intersect.

You may have "group of pins", say, emmc preconfigured before kernel started (in general DTS for u-boot) and you may want to have the pin from emmc group to be muxed as, say, SD card detect. You mux it in kernel DTS as GPIO, it will be in correct GPIO state, configured correctly, but while emmc group is enabled (nobody disabled it in kernel DTS!) the pin will belong to emmc function (preset group) and will not be functional.

I invented zero_func while has been debugging the problem like "why my Eth is not working when all pins are configured correctly and muxed to Eth". I spend some time to find that the pin I muxed to Eth has been muxed to SPI_FLASH GROUP in very early stage (in ROM boot). And I have no way to cleanup this mux group easily.

zero_func is the way to easily guarantee that you will successfully and correctly mux some pins / functions on kernel load even if somebody muxed other pins to this functions before kernel.

If I'd implement "automatic" mux cleanup before muxing some pin, the code would be more complex. I would like to keep code as simple as I can and give better control to user.

Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +45 -0
+      allOf:
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH1
+                  - SPI_FLASH2
+        - if:
+            properties:
+              function:
+                enum:
+                  - SPI_FLASH_4BIT
+          then:
+            properties:
+              groups:
+                enum:
+                  - SPI_FLASH_4BIT1
+                  - SPI_FLASH_4BIT2
+        - if:
+            properties:
+              function:
+                enum:
+                  - HDMI_TX
+          then:
+            properties:
+              groups:
+                enum:
+                  - HDMI_TX1
+                  - HDMI_TX2
+                  - HDMI_TX3
+        - if:
+            properties:
+              function:
+                enum:
+                  - LCDIF
+          then:
+            properties:
+              groups:
+                enum:
+                  - LCDIF
Quoted 1 line
Quoted 1 line
Quoted 1 line

This looks complex to me, I need feedback from bindings people on this.

sp7021 supports two types of muxes:

1) group muxing (1-N sets of predefined pins for some function)

2) individual pin muxing

Some functions may be muxed only in group, like SPI_FLASH or HDMI.

That's why we have

pins = <...>;

and

function = <funcname>;

group = <funcsubname-group>;

second case could be cuted to

function = <funcsubname-group> only;

But I think, the syntax of a pair {function,group} fits SoC logic better. Especially if customer is reading possible muxes table for the chip.

Quoted 16 lines
Quoted 16 lines

Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 252

Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +8 -0
+        pins_uart0: pins_uart0 {
+            function = "UA0";
+            groups = "UA0";
+        };
+
+        pins_uart1: pins_uart1 {
+            pins = <
+

SPPCTL_IOPAD(11,SPPCTL_PCTL_G_PMUX,MUXF_UA1_TX,0)

Quoted 1 line

+

SPPCTL_IOPAD(10,SPPCTL_PCTL_G_PMUX,MUXF_UA1_RX,0)

Quoted 1 line

+

SPPCTL_IOPAD(7,SPPCTL_PCTL_G_GPIO,0,SPPCTL_PCTL_L_OUT)

Quoted 2 lines
(quoted diff) +2 -0
+            >;
+        };
Quoted 7 lines
Quoted 7 lines

This first looks like two ways to do the same thing?
UART0 uses strings for group + function and uart1 control individual pins.

Is it possible to just do it one way?

I think the pins = <...> scheme includes also multiplexing settings and then it should be named pinmux = <...>:

No. Sorry. It is two different way of supported two different types of muxing, described above.

Quoted 7 lines
Quoted 7 lines

Please read Documentation/devicetree/bindings/pinctrl/pinmux-node.yaml closely.

Yours,
Linus Walleij

BEGIN:VCARD
VERSION:4.0
EMAIL;PREF=1:[email protected]
EMAIL:[email protected]
FN:Dmitry Dvorkin
NICKNAME:dv
ORG:Tibbo Technology Inc.;
TITLE:Embedded Linux Architect
N:Dvorkin;Dmitry;;;
ADR:;;9F-3\, No.31, Lane 169, Kang-Ning St., Hsi-Chih;New Taipei City;;2218
0;Taiwan
TEL;VALUE=TEXT:+79190546388
URL;VALUE=URL:https://tibbo.com/ UID:1c58210f-ac8c-4337-b391-0bde146d2d83
END:VCARD