This is a patch series for pinctrl driver of Sunplus SP7021 SoC.
Subsystems (4)
Wells Lu
maintainerv3 cover This is a patch series for pinctrl driver of 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 applications.
Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html
Wells Lu (2):
dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021
pinctrl: Add driver for Sunplus SP7021
.../bindings/pinctrl/sunplus,sp7021-pinctrl.yaml | 293 ++++++ MAINTAINERS | 10 + drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/sunplus/Kconfig | 21 + drivers/pinctrl/sunplus/Makefile | 5 + drivers/pinctrl/sunplus/sppctl.c | 1074 ++++++++++++++++++++ drivers/pinctrl/sunplus/sppctl.h | 154 +++ drivers/pinctrl/sunplus/sppctl_sp7021.c | 536 ++++++++++ include/dt-bindings/pinctrl/sppctl-sp7021.h | 173 ++++ include/dt-bindings/pinctrl/sppctl.h | 40 + 11 files changed, 2308 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/sppctl.c create mode 100644 drivers/pinctrl/sunplus/sppctl.h create mode 100644 drivers/pinctrl/sunplus/sppctl_sp7021.c 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
Wells Lu
maintainerPATCH v3 1/2 dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021
Add dt-bindings header files and documentation for Sunplus SP7021 SoC.
---
Changes in V3
- Addressed comments of Mr. Rob Herring.
.../bindings/pinctrl/sunplus,sp7021-pinctrl.yaml | 293 +++++++++++++++++++++ MAINTAINERS | 9 + include/dt-bindings/pinctrl/sppctl-sp7021.h | 173 ++++++++++++ include/dt-bindings/pinctrl/sppctl.h | 40 +++ 4 files changed, 515 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml create mode 100644 include/dt-bindings/pinctrl/sppctl-sp7021.h create mode 100644 include/dt-bindings/pinctrl/sppctl.h
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +293 -0
@@ -0,0 +1,293 @@ +# 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. + + 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: the MOON2 registers + - description: the GPIOXT registers + - description: the GPIOXT2 registers + - description: the FIRST registers + - description: the MOON1 registers + + reg-names: + items: + - const: moon2 + - const: gpioxt + - const: gpioxt2 + - const: first + - const: moon1 + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + +patternProperties: + '-pins$': + 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/pinctrl/sppctl-sp7021.h> + + pinctl@9c000100 { + compatible = "sunplus,sp7021-pctl"; + reg = <0x9c000100 0x100>, <0x9c000300 0x80>, <0x9c000380 0x80>, + <0x9c0032e4 0x1c>, <0x9c000080 0x20>; + gpio-controller; + #gpio-cells = <2>; + clocks = <&clkc 0x83>; + resets = <&rstc 0x73>; + + uart0-pins { + function = "UA0"; + groups = "UA0"; + }; + + spinand0-pins { + function = "SPI_NAND"; + groups = "SPI_NAND"; + }; + + uart1-pins { + pins = < + SPPCTL_IOPAD(11, SPPCTL_PCTL_G_PMUX, MUXF_UA1_TX, 0) + SPPCTL_IOPAD(10, SPPCTL_PCTL_G_PMUX, MUXF_UA1_RX, 0) + >; + }; + + uart2-pins { + pins = < + SPPCTL_IOPAD(20, SPPCTL_PCTL_G_PMUX, MUXF_UA1_TX, 0) + SPPCTL_IOPAD(21, SPPCTL_PCTL_G_PMUX, MUXF_UA1_RX, 0) + SPPCTL_IOPAD(22, SPPCTL_PCTL_G_PMUX, MUXF_UA1_RTS, 0) + SPPCTL_IOPAD(23, SPPCTL_PCTL_G_PMUX, MUXF_UA1_CTS, 0) + >; + }; + + emmc-pins { + function = "CARD0_EMMC"; + groups = "CARD0_EMMC"; + }; + + sdcard-pins { + function = "SD_CARD"; + groups = "SD_CARD"; + pins = < SPPCTL_IOPAD(91, SPPCTL_PCTL_G_GPIO, 0, 0) >; + }; + + hdmi_A_tx1-pins { + function = "HDMI_TX"; + groups = "HDMI_TX1"; + }; + hdmi_A_tx2-pins { + function = "HDMI_TX"; + groups = "HDMI_TX2"; + }; + hdmi_A_tx3-pins { + function = "HDMI_TX"; + groups = "HDMI_TX3"; + }; + }; +...
MAINTAINERS +9 -0
@@ -15128,6 +15128,15 @@ L: [email protected] S: Maintained F: drivers/pinctrl/pinctrl-single.c +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: Documentation/devicetree/bindings/pinctrl/sunplus,* +F: include/dt-bindings/pinctrl/sppctl* + PKTCDVD DRIVER M: [email protected] S: Orphan
include/dt-bindings/pinctrl/sppctl-sp7021.h new file +173 -0
173 lines not on this page · raw message
include/dt-bindings/pinctrl/sppctl.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +/* Sunplus dt-bindings Pinctrl header file +* 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)/* Output LOW */ +#define SPPCTL_PCTL_L_OU1 (0x01 << 1)/* Output HIGH */ +#define SPPCTL_PCTL_L_INV (0x01 << 2)/* Input Invert */ +#define SPPCTL_PCTL_L_ONV (0x01 << 3)/* Output Invert */ +#define SPPCTL_PCTL_L_ODR (0x01 << 4)/* Output Open Drain */ + +#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), flag(8bit) +*/ +#define SPPCTL_IOPAD (pin, typ, fun, flg) (((pin) << 24) | ((typ) << 16) | \ + ((fun) << 8) | (flg)) + +#endif
Signature · 1 line
2.7.4
Re: [PATCH v3 1/2] dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021
Quoted 6 lines · Wells Lu
Add dt-bindings header files and documentation for Sunplus SP7021 SoC.
Signed-off-by Wells Lu <[email protected]>Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +2
-0+patternProperties: + '-pins$':
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 64
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +10
-0+ 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.
I don't understand this if type object stuff here, Rob, help...
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +4
-0+ properties: + pins: + description: | + Define pins which are used by pinctrl node's client device.
(...)
Quoted 1 line
+ $ref: /schemas/types.yaml#/definitions/uint32-array
Why can this not $ref the standard binings in Documentation/devicetree/bindings/pinctrl/pinmux-node.yaml
See for example Documentation/devicetree/bindings/pinctrl/actions,s500-pinctrl.yaml for a nice example of how to use this.
Yours,
Linus Walleij
呂芳騰
maintainerRe: [PATCH v3 1/2] dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021
Re-send this email because it was rejected due to the wrong email format!
Hi Linus,
Thank you very much for your review!
Please see my answers below:
Quoted 4 lines
Quoted 3 lines
Add dt-bindings header files and documentation for Sunplus SP7021 SoC.
Signed-off-by Wells Lu <[email protected]>
Quoted 14 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml line 64
Quoted 12 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +12
-0+patternProperties: + '-pins$': + 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.I don't understand this if type object stuff here, Rob, help...
I'll remove "if type object" stuff next patch since pinctrl node has no properties with "-pins" suffix. except sub nodes.
Quoted 7 lines
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +4
-0+ properties: + pins: + description: | + Define pins which are used by pinctrl node's client device.(...)
Quoted 1 line
+ $ref: /schemas/types.yaml#/definitions/uint32-array
Quoted 8 lines
Why can this not $ref the standard binings in
Documentation/devicetree/bindings/pinctrl/pinmux-node.yamlSee for example
Documentation/devicetree/bindings/pinctrl/actions,s500-pinctrl.yamlfor a nice example of how to use this.
Yours,
Linus Walleij
The pins' types and control of SP7021 are a bit complex. Let me explain:
SP7021 has 99 digital GPIO pins which are numbered from GPIO 0 to 98. All are multiplexed with some special function pins. There are 3 types special function pins:
(1) function-pins:
For example, if control-field SPI_FLASH_SEL is set to 1, GPIO 83, 84, 86 and 87 will be pins of SPI-NOR flash. If it is set to 2, GPIO 76, 78, 79 and 81 will be pins of SPI-NOR flash.
For example 2, if control-bit UA0_SEL is set to 1, GPIO 88 and 89 will be TX and RX pins of UART_0 (UART channel 0).
For example 3, if control-bit EMMC_SEL is set to 1, GPIO 72, 73, 74, 75, 76, 77, 78, 79, 80, 81 will be pins of an eMMC device.
The driver defines properties "function" and "groups" to select this kind of pins-function.
(2) fully pin-mux pins:
GPIO 8 to 71 are 'fully pin-mux' pins.
Pins of peripherals of SP7021 (ex: UART_1, UART_2, UART_3, UART_4, I2C_0, I2C_1, ..., SPI_0, SPI_1, ... GPIO_INT0, GPIO_INT1, .., RMII_of_Ethernet, and etc.) can be set to any pins of fully pin-mux pins.
EX1 (UART channel 1):
If control-field UA1_TX_SEL is set to 3, TX pin of UART_1 will be routed to GPIO 10 (3 - 1 + 8 = 10) If control-field UA1_RX_SEL is set to 4, RX pin of UART_1 will be routed to GPIO 11 (4 - 1 + 8 = 11) If control-field UA1_RTS_SEL is set to 5, RTS pin of UART_1 will be routed to GPIO 12 (5 - 1 + 8 = 12) If control-field UA1_CTS_SEL is set to 6, CTS pin of UART_1 will be routed to GPIO 13 (6 - 1 + 8 = 13)
EX2 (I2C channel 0):
If control-field I2C0_CLK_SEL is set to 20, CLK pin of I2C_0 will be routed to GPIO 27 (20 - 1 + 8 = 27) If control-field I2C0_DATA_SEL is set to 21, DATA pin of I2C_0 will be routed to GPIO 28 (21 - 1 + 9 = 28)
Totally, SP7021 has 120 peripheral pins. The peripheral pins can be routed to any of 64 'fully
pin-mux' pins. So total combinations are:
120 x 64 = 7680
This is why we cannot enumerate all combinations.
(3) I/O processor pins
SP7021 has a built-in I/O processor.
Any GPIO pins (GPIO 0 to 98) can be set to pins of I/O processor.
Property 'pins' is defined as uint32 array. Each item defines a pin as below:
Bit 32~24 defines GPIO number. Its range is 0 ~ 98.
Bit 23~16 defines types: digital GPIO pins (3), IO processor pins (2) or fully pin-mux pins (1)
Bit 15~8 defines pins of peripherals which are defined in 'include/dt-binging/pinctrl/sppctl.h'.
Bit 7~0 defines types or initial-state of digital GPIO pins.
Best regards,
Wells
A message that is not in the archive (sent off-list or not yet received): CAFnkrskBVLk0q77Xkk=E07gxmWSNfRtwznz9yv1fd07u0P2HgQ@mail.gmail.com
Re: [PATCH v3 1/2] dt-bindings: pinctrl: Add dt-bindings for Sunplus SP7021
Quoted 44 lines · 呂芳騰
SP7021 has 99 digital GPIO pins which are numbered from GPIO 0 to 98. All are multiplexed with some special function pins. There are 3 types special function pins:
(1) function-pins:
For example, if control-fieldSPI_FLASH_SELis set to 1, GPIO 83, 84, 86 and 87 will be pins of SPI-NOR flash. If it is set to 2, GPIO 76, 78, 79 and 81 will be pins of SPI-NOR flash.For example 2, if control-bit
UA0_SELis set to 1, GPIO 88 and 89 will be TX and RX pins ofUART_0(UART channel 0).For example 3, if control-bit
EMMC_SELis set to 1, GPIO 72, 73, 74, 75, 76, 77, 78, 79, 80, 81 will be pins of an eMMC device.The driver defines properties "function" and "groups" to select this kind of pins-function.
(2) fully pin-mux pins:
GPIO 8 to 71 are 'fully pin-mux' pins.
Pins of peripherals of SP7021 (ex:UART_1,UART_2,UART_3,UART_4,I2C_0,I2C_1, ...,SPI_0,SPI_1, ...GPIO_INT0,GPIO_INT1, ..,RMII_of_Ethernet, and etc.) can be set to any pins of fully pin-mux pins.EX1 (UART channel 1):
If control-fieldUA1_TX_SELis set to 3, TX pin ofUART_1will be routed to GPIO 10 (3 - 1 + 8 = 10) If control-fieldUA1_RX_SELis set to 4, RX pin ofUART_1will be routed to GPIO 11 (4 - 1 + 8 = 11) If control-fieldUA1_RTS_SELis set to 5, RTS pin ofUART_1will be routed to GPIO 12 (5 - 1 + 8 = 12) If control-fieldUA1_CTS_SELis set to 6, CTS pin ofUART_1will be routed to GPIO 13 (6 - 1 + 8 = 13)EX2 (I2C channel 0):
If control-fieldI2C0_CLK_SELis set to 20, CLK pin ofI2C_0will be routed to GPIO 27 (20 - 1 + 8 = 27) If control-fieldI2C0_DATA_SELis set to 21, DATA pin ofI2C_0will be routed to GPIO 28 (21 - 1 + 9 = 28)
Quoted 5 lines
Totally, SP7021 has 120 peripheral pins. The peripheral pins can be routed to any of 64 'fully
pin-mux' pins. So total combinations are:
120 x 64 = 7680
This is why we cannot enumerate all combinations.
Please copy some version of the above into the top level description in the bindings. People writing DTS files need to know what they are doing and why this looks so funny and if the explanation is right there in the bindings document, that is helpful.
This is pretty cool. It is what is called a "phone exchange mux", (anyone can call any number) which is a type that the pin control subsystem simply assumed did not exist because it would take up a lot of silicon space. But here it is.
So:
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/sunplus,sp7021-pinctrl.yaml new file +4
-0+ properties: + pins: + description: | + Define pins which are used by pinctrl node's client device.(...)
Quoted 1 line
+ $ref: /schemas/types.yaml#/definitions/uint32-array
Why can this not $ref the standard binings in
Documentation/devicetree/bindings/pinctrl/pinmux-node.yaml
If this does not conform with the standard definition of pins from pinmux-node.yaml then you need to vendor prefix them, this will then be something like sunplus,pins.
Yours,
Linus Walleij
Wells Lu
maintainerPATCH v3 2/2 pinctrl: Add driver for Sunplus SP7021
In reply to Wells LuAdd driver for Sunplus SP7021.
---
Changes in V3
- Addressed comments of Mr. Linus Walleij.
- Remove sysfs functions.
- Cleaned up code.
MAINTAINERS | 1 + drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/sunplus/Kconfig | 21 + drivers/pinctrl/sunplus/Makefile | 5 + drivers/pinctrl/sunplus/sppctl.c | 1074 +++++++++++++++++++++++++++++++ drivers/pinctrl/sunplus/sppctl.h | 154 +++++ drivers/pinctrl/sunplus/sppctl_sp7021.c | 536 +++++++++++++++ 8 files changed, 1793 insertions(+) create mode 100644 drivers/pinctrl/sunplus/Kconfig create mode 100644 drivers/pinctrl/sunplus/Makefile create mode 100644 drivers/pinctrl/sunplus/sppctl.c create mode 100644 drivers/pinctrl/sunplus/sppctl.h create mode 100644 drivers/pinctrl/sunplus/sppctl_sp7021.c
MAINTAINERS +1 -0
@@ -15135,6 +15135,7 @@ 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* PKTCDVD DRIVER
drivers/pinctrl/Kconfig +1 -0
@@ -459,6 +459,7 @@ source "drivers/pinctrl/samsung/Kconfig" source "drivers/pinctrl/spear/Kconfig" source "drivers/pinctrl/sprd/Kconfig" source "drivers/pinctrl/stm32/Kconfig" +source "drivers/pinctrl/sunplus/Kconfig" source "drivers/pinctrl/sunxi/Kconfig" source "drivers/pinctrl/tegra/Kconfig" source "drivers/pinctrl/ti/Kconfig"
drivers/pinctrl/Makefile +1 -0
@@ -67,6 +67,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 +21 -0
@@ -0,0 +1,21 @@ +# 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 GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF + select PINCONF + select PINMUX + select GPIOLIB + select OF_GPIO + 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.
drivers/pinctrl/sunplus/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the Sunplus Pin control drivers. +# +obj-$(CONFIG_PINCTRL_SPPCTL) += sppctl.o sppctl_sp7021.o
drivers/pinctrl/sunplus/sppctl.c new file +1074 -0
1,074 lines not on this page · raw message
drivers/pinctrl/sunplus/sppctl.h new file +154 -0
154 lines not on this page · raw message
drivers/pinctrl/sunplus/sppctl_sp7021.c new file +536 -0
536 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v3 2/2] pinctrl: Add driver for Sunplus SP7021
Hi Wells,
this is improving! Keep working on this driver. I now naturally have more comments :)
drivers/pinctrl/sunplus/sppctl.c line 24
Quoted 9 lines · Wells Lu
drivers/pinctrl/sunplus/sppctl.c new file +9
-0+static void sppctl_func_set (struct sppctl_pdata *pctl,u8 func,u8 val) +{ +u32 reg, offset; + +/* Note that upper 16-bit word is mask +* and lower 16-bit word is value. +* Enable mask before write. +*/ + reg =0x007f0000 | val;/* Set value and enable mask. */
Define these types of masks and use them like this:
#include <linux/bits.h>
#define SPPCTL_FUNC_MASK GENMASK(22, 16)
Also switch the order with the mask to the right please:
reg = val & SPPCTL_FUNC_MASK;
Quoted 1 line
+ if (func & 1)
I would write
#define SSPCTL_FUNC_FLAG BIT(0)
if (func & SSPCTL_FUNC_FLAG)
Use the name that bit has in your documentation for the define so we know what is going on.
Quoted 1 line
+ reg <<= 8;
Likewise
#define SSPCTL_FUNC_UPPER_SHIFT 8
reg <<= SSPCTL_FUNC_UPPER_SHIFT;
Can also be a comment. The general idea is to break out as many of these magic numbers as possible to #defines and give them some names from the reference manual, so we understand them instead of the numbers being magic.
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* Convert function # to register offset. */ + offset = func & ~1;
Step 1 write:
offset = func & GENMASK(31, 1);
Quoted 1 line
+ offset <<= 1;
I would write:
offset *= 2;
because we are dealing with an offset and not an arithmetic operation. It will be the same to the compiler.
But the best is to just merge all this and write (if I'm not wrong):
#include <linux/bitfield.h>
/*
* Bit 1 .. 31 gives the function, index this into a 32-bit offset by
* multiplying by four to find the register.
*/
offset = FIELD_GET(GENMASK(31, 1), func);
offset *= 4;
This gets pretty clear. We see that we remove BIT(0) and use the rest as offset index and there are four bytes per register.
(Beware of bugs in my pseudocode, check it!)
drivers/pinctrl/sunplus/sppctl.c line 45
Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c new file +8
-0+static u8 sppctl_func_get (struct sppctl_pdata *pctl,u8 func) +{ +u32 reg, offset; +u8 val; + +/* Convert function # to register offset. */ + offset = func & ~1 ; + offset <<=1 ;
Same comments.
drivers/pinctrl/sunplus/sppctl.c line 52
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6
-0+ reg =readl (pctl->moon2_base + offset); +if (func &1 ) + val = reg >>8 ; +else + val = reg; + val &=0x7f ;
#define SSPCTL_*_MASK for this 0x7f so we understand it.
drivers/pinctrl/sunplus/sppctl.c line 71
Quoted 12 lines
drivers/pinctrl/sunplus/sppctl.c new file +12
-0+static void sppctl_gmx_set (struct sppctl_pdata *pctl,u8 reg_off,u8 bit_off,u8 bit_sz, +u8 val) +{ +u32 mask, reg; + +/* Note that upper 16-bit word is mask +* and lower 16-bit word is value. +* Enable mask before write. +*/ + mask = ~(~0 << bit_sz); + reg = (mask <<16 ) | (val & mask); + reg <<= bit_off;
Please familiarize yourself with <linux/bitfield.h> and use things like FIELD_PREP() for this (I think, atleast).
drivers/pinctrl/sunplus/sppctl.c line 83
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6
-0+static int sppctl_first_get (struct gpio_chip *chip,unsigned int offset) +{ +struct sppctl_gpio_chip *spp_gchip =gpiochip_get_data (chip); +u32 reg; + + reg =readl (spp_gchip->first_base +SPPCTL_GPIO_OFF_FIRST +R32_ROF (offset));
So R32_ROF() is register offset.
drivers/pinctrl/sunplus/sppctl.c line 89
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6
-0+ +dev_dbg (chip->parent,"%s(%u): addr = %p, reg = %08x, val = %d\n" , + __func__, offset, spp_gchip->first_base +SPPCTL_GPIO_OFF_FIRST + +R32_ROF (offset), reg, (int )R32_VAL (reg,R32_BOF (offset))); + +return R32_VAL (reg,R32_BOF (offset));
And R32_BOF is register bit offset.
I think these macros just make it hard to read because the reader has to go to another file and look it up and then figure out what does ROF and BOF actually mean (no explanation given).
I would just inline the stuff.
u32 reg = (offset / 32) * 4;
u32 bit = offset % 32;
reg = readl(spp_gchip->first_base + SPPCTL_GPIO_OFF_FIRST + reg);
// Some debug code
return !!(reg & BIT(bit));
drivers/pinctrl/sunplus/sppctl.c line 158
Quoted 9 lines
drivers/pinctrl/sunplus/sppctl.c new file +9
-0+static void sppctl_gpio_output_inv_set (struct gpio_chip *chip,unsigned int offset) +{ +struct sppctl_gpio_chip *spp_gchip =gpiochip_get_data (chip); +u32 reg; + +/* Upper 16-bit word is mask. Lower 16-bit word is value. */ + reg = (BIT (R16_BOF (offset)) <<16 ) |BIT (R16_BOF (offset)); +writel (reg, spp_gchip->gpioxt2_base +SPPCTL_GPIO_OFF_OINV +R16_ROF (offset)); +}
Same comments about the BOF and ROF.
This layout with "mask and value" in registers needs to be explained somewhere it looks complex. I don't understand why a machine register contains a mask for example.
drivers/pinctrl/sunplus/sppctl.c line 555
Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.c new file +7
-0+static int stpctl_set_mux (struct pinctrl_dev *pctldev,unsigned int func_selector, +unsigned int group_selector) +{ +const struct sppctl_func *f = &sppctl_list_funcs[func_selector]; +struct sppctl_pdata *pctl =pinctrl_dev_get_drvdata (pctldev); +struct grp2fp_map g2fpm = pctl->g2fp_maps[group_selector]; +int i =-1 , j =-1 ;
Please do not initialize loop variable i to -1, just declare it.
drivers/pinctrl/sunplus/sppctl.c line 565
Quoted 9 lines
drivers/pinctrl/sunplus/sppctl.c new file +9
-0+dev_dbg (pctldev->dev,"%s(func: %d, grp: %d)\n" , __func__, + func_selector, group_selector); + +switch (f->freg) { +case f_off_0:/* GPIO. detouch from all funcs - ? */ +for (i =0 ; i < sppctl_list_funcs_sz; i++) { +if (sppctl_list_funcs[i].freg != f_off_m) +continue ; + j++;
Insert a comment that j is set to -1 so this will be zero here after the first iteration.
drivers/pinctrl/sunplus/sppctl.c line 576
Quoted 11 lines
drivers/pinctrl/sunplus/sppctl.c new file +11
-0+if (sppctl_func_get (pctl, j) != group_selector) +continue ; +sppctl_func_set (pctl, j,0 ); + } +break ; + +case f_off_m:/* Mux */ +sppctl_first_master_set (&pctl->spp_gchip->chip, group_selector, + mux_f_mux, mux_m_keep); +sppctl_func_set (pctl, func_selector -2 , (group_selector ==0 ) ? + group_selector : group_selector -7 );
-2 and -7? Why? Add some comments or maybe #define these constants?
Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.c new file +7
-0+static int stpctl_gpio_request_enable (struct pinctrl_dev *pctldev, +struct pinctrl_gpio_range *range,unsigned int offset) +{ +struct sppctl_pdata *pctl =pinctrl_dev_get_drvdata (pctldev); +struct pin_desc *pdesc; +int g_f, g_m; +
drivers/pinctrl/sunplus/sppctl.c line 617
Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.c new file +10
-0+dev_dbg (pctldev->dev,"%s(%d)\n" , __func__, offset); + + g_f =sppctl_first_get (&pctl->spp_gchip->chip, offset); + g_m =sppctl_master_get (&pctl->spp_gchip->chip, offset); +if (g_f == mux_f_gpio && g_m == mux_m_gpio) +return 0 ; + + pdesc =pin_desc_get (pctldev, offset); +if (pdesc->mux_owner) +return -EACCES ;
Do not reimplement the pinmux core please.
What you want to achieve here is "strict pinmux", i.e. setting the field "strict" in struct pinmux_ops to true. Then you can just delete this check.
drivers/pinctrl/sunplus/sppctl.c line 639
Quoted 3 lines
drivers/pinctrl/sunplus/sppctl.c new file +3
-0+static const struct pinmux_ops sppctl_pinmux_ops = { + .request = stpctl_request, + .free = stpctl_free,
These are just set to empty functions. Delete these entries and the empty functions.
drivers/pinctrl/sunplus/sppctl.c line 647
Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c new file +8
-0+ .get_functions_count = stpctl_get_functions_count, + .get_function_name = stpctl_get_function_name, + .get_function_groups = stpctl_get_function_groups, + .set_mux = stpctl_set_mux, + .gpio_request_enable = stpctl_gpio_request_enable, + .gpio_disable_free = stpctl_gpio_disable_free, + .gpio_set_direction = stpctl_gpio_set_direction, + .strict = 1
Use "true" rather than 1. (And do not reimplement the check.)
drivers/pinctrl/sunplus/sppctl.c line 1051
Quoted 5 lines
drivers/pinctrl/sunplus/sppctl.c new file +5
-0+static int sppctl_remove (struct platform_device *pdev) +{ +struct sppctl_pdata *sppctl = pdev->dev.platform_data; + +devm_pinctrl_unregister (&pdev->dev, sppctl->pctl_dev);
This defies the idea with devm_* calls. Drop remove() entirely because devm_ allocated resources go away by themselves.
Quoted 1 line
+++
b/drivers/pinctrl/sunplus/sppctl.h
(...)
drivers/pinctrl/sunplus/sppctl.h line 27
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.h new file +6
-0+/* (/16)*4 */ +#define R16_ROF (r) (((r) >> 4) << 2) +#define R16_BOF (r) ((r) % 16) +/* (/32)*4 */ +#define R32_ROF (r) (((r) >> 5) << 2) +#define R32_BOF (r) ((r) % 32)
As mentioned I prefer explicit inlined code for these. The bit shifting here makes it really hard to know what is going on, the compiler will get it right if you use the right types and just write (n / 32) * 4. Please do not try to help the compiler optimizing it just leads to code that is hard to read.
Quoted 1 line
+#define
R32_VAL(r, boff)(((r) >> (boff)) & BIT(0))
To check the value of a certain bit use this pattern:
if (val & BIT(n))
To return a boolean clamped bit (return 0/1) do this idiom:
return !!(val & BIT(n));
Other than these things I didn't notice anything more this time, but I might find even more stuff, but hey it's getting there!
Yours,
Linus Walleij
呂芳騰
maintainerRe: [PATCH v3 2/2] pinctrl: Add driver for Sunplus SP7021
Resend the email because it was rejected due to wrong format!
Hi Linus,
Thank you very much for your review.
Please see my answers below:
Quoted 19 lines
Hi Wells,
this is improving! Keep working on this driver. I now naturally have more comments :)
drivers/pinctrl/sunplus/sppctl.c line 24
Quoted 9 lines · Wells Lu
drivers/pinctrl/sunplus/sppctl.c new file +9
-0+static void sppctl_func_set (struct sppctl_pdata *pctl,u8 func,u8 val) +{ +u32 reg, offset; + +/* Note that upper 16-bit word is mask +* and lower 16-bit word is value. +* Enable mask before write. +*/ + reg =0x007f0000 | val;/* Set value and enable mask. */ Define these types of masks and use them like this:
Quoted 7 lines
#include <
linux/bits.h>#define
SPPCTL_FUNC_MASKGENMASK(22, 16)Also switch the order with the mask to the right please:
reg = val &
SPPCTL_FUNC_MASK;
Yes, I'll modify code next patch.
Quoted 10 lines
Quoted 1 line
+ if (func & 1)
I would write
#define
SSPCTL_FUNC_FLAGBIT(0)if (func &
SSPCTL_FUNC_FLAG)Use the name that bit has in your documentation for the define so we know what is going on.
Actually, 'if (func & 1)' is not used to test bit 0, but test 'func' is an odd number or not.
If 'func' is even number, control-field is at bit 6 ~ 0. Its corresponding mask-field is at bit 22 ~ 16. If 'func' is odd number, control-field is at bit 14 ~ 8. Its corresponding mask-field is at bit 30 ~ 24.
Control and mask fields of 'func' are arranged as shown below:
func # | register control-field mask-field
-------+------------------------------------
0 | reg[0] ( 6:0) (22 : 6) 1 | reg[0] (14:8) (30 : 24) 2 | reg[1] ( 6:0) (22 : 6) 3 | reg[1] (14:8) (30 : 24)
Quoted 11 lines
Quoted 1 line
+ reg <<= 8;
Likewise
#define
SSPCTL_FUNC_UPPER_SHIFT8reg <<=
SSPCTL_FUNC_UPPER_SHIFT;
Can also be a comment. The general idea is to break out as many of these magic numbers as possible to #defines and give them some names from the reference manual, so we understand them instead of the numbers being magic.
Yes, I'll modify codes, add defines and more comments next patch.
Quoted 24 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* Convert function # to register offset. */ + offset = func & ~1;Step 1 write:
offset = func &GENMASK(31, 1);Quoted 1 line
+ offset <<= 1;
I would write:
offset *= 2;
because we are dealing with an offset and not an arithmetic operation. It will be the same to the compiler.But the best is to just merge all this and write (if I'm not wrong):
#include <
linux/bitfield.h>/*
* Bit 1 .. 31 gives the function, index this into a 32-bit offset by
* multiplying by four to find the register.
*/
offset =FIELD_GET(GENMASK(31, 1), func);
offset *= 4;
Quoted 4 lines
This gets pretty clear. We see that we remove BIT(0) and use the rest as offset index and there are four bytes per register.
(Beware of bugs in my pseudo code, check it!)
Thank you for example code!
Yes, I will use BIT, GENMASK, FIELD_GET, and FIELD_PREP macros next patch.
Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.c line 45
Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c new file +8
-0+static u8 sppctl_func_get (struct sppctl_pdata *pctl,u8 func) +{ +u32 reg, offset; +u8 val; + +/* Convert function # to register offset. */ + offset = func & ~1 ; + offset <<=1 ;Same comments.
Yes, I got it. I'll modify codes next patch.
Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c line 52
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6
-0+ reg =readl (pctl->moon2_base + offset); +if (func &1 ) + val = reg >>8 ; +else + val = reg; + val &=0x7f ;#define SSPCTL_*_MASK for this
0x7fso we understand it.
Yes, I'll do it next patch.
Quoted 7 lines
Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.c new file +7
-0+static void sppctl_gmx_set (struct sppctl_pdata *pctl,u8 reg_off,u8 bit_off,u8 bit_sz, +u8 val) +{ +u32 mask, reg; + +/* Note that upper 16-bit word is mask +* and lower 16-bit word is value.
Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c line 71
Quoted 5 lines
drivers/pinctrl/sunplus/sppctl.c new file +5
-0+* Enable mask before write. +*/ + mask = ~(~0 << bit_sz); + reg = (mask <<16 ) | (val & mask); + reg <<= bit_off;Please familiarize yourself with <
linux/bitfield.h> and use things likeFIELD_PREP()for this (I think, at least).
Yes, I will use BIT, GENMASK, FIELD_GET, and FIELD_PREP macros next patch.
Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c line 83
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6
-0+static int sppctl_first_get (struct gpio_chip *chip,unsigned int offset) +{ +struct sppctl_gpio_chip *spp_gchip =gpiochip_get_data (chip); +u32 reg; + + reg =readl (spp_gchip->first_base +SPPCTL_GPIO_OFF_FIRST +R32_ROF (offset));So
R32_ROF()is register offset.
Yes, it converts 'offset' to register offset (w.r.t. base register)
R32_ROF() is for 32-bit width registersR16_ROF() is for 16-bit width registers (higher 16-bit of the register is mask).
Quoted 15 lines
drivers/pinctrl/sunplus/sppctl.c line 89
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c new file +6
-0+ +dev_dbg (chip->parent,"%s(%u): addr = %p, reg = %08x, val = %d\n" , + __func__, offset, spp_gchip->first_base +SPPCTL_GPIO_OFF_FIRST + +R32_ROF (offset), reg, (int )R32_VAL (reg,R32_BOF (offset))); + +return R32_VAL (reg,R32_BOF (offset));And
R32_BOFis register bit offset.I think these macros just make it hard to read because the reader has to go to another file and look it up and then figure out what does ROF and BOF actually mean (no explanation given).
I would just inline the stuff.
Quoted 8 lines
u32 reg = (offset / 32) * 4;
u32 bit = offset % 32;reg =
readl(spp_gchip->first_base + SPPCTL_GPIO_OFF_FIRST + reg);// Some debug code
return !!(reg & BIT(bit));
Yes, I'll modify codes to follow your suggestions next patch.
Quoted 12 lines
drivers/pinctrl/sunplus/sppctl.c line 158
Quoted 9 lines
drivers/pinctrl/sunplus/sppctl.c new file +9
-0+static void sppctl_gpio_output_inv_set (struct gpio_chip *chip,unsigned int offset) +{ +struct sppctl_gpio_chip *spp_gchip =gpiochip_get_data (chip); +u32 reg; + +/* Upper 16-bit word is mask. Lower 16-bit word is value. */ + reg = (BIT (R16_BOF (offset)) <<16 ) |BIT (R16_BOF (offset)); +writel (reg, spp_gchip->gpioxt2_base +SPPCTL_GPIO_OFF_OINV +R16_ROF (offset)); +}Same comments about the BOF and ROF.
Quoted 3 lines
This layout with "mask and value" in registers needs to be explained somewhere it looks complex. I don't understand why a machine register contains a mask for example.
This is a hardware mechanism for protecting some important registers from being overwritten accidentally. The corresponding mask bit should be set first and then the control-bits or fields can be written. The design is originally requested from car makers.
Quoted 9 lines
drivers/pinctrl/sunplus/sppctl.c line 555
Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.c new file +7
-0+static int stpctl_set_mux (struct pinctrl_dev *pctldev,unsigned int func_selector, +unsigned int group_selector) +{ +const struct sppctl_func *f = &sppctl_list_funcs[func_selector]; +struct sppctl_pdata *pctl =pinctrl_dev_get_drvdata (pctldev); +struct grp2fp_map g2fpm = pctl->g2fp_maps[group_selector]; +int i =-1 , j =-1 ;Please do not initialize loop variable i to -1, just declare it.
Yes, I'll remove the initialization for loop variables next patch
Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.c line 565
Quoted 9 lines
drivers/pinctrl/sunplus/sppctl.c new file +9
-0+dev_dbg (pctldev->dev,"%s(func: %d, grp: %d)\n" , __func__, + func_selector, group_selector); + +switch (f->freg) { +case f_off_0:/* GPIO. detouch from all funcs - ? */ +for (i =0 ; i < sppctl_list_funcs_sz; i++) { +if (sppctl_list_funcs[i].freg != f_off_m) +continue ; + j++;
Quoted 2 lines
Insert a comment that j is set to -1 so this will be zero here after the first iteration.
Yes, I'll add comments next patch.
Quoted 12 lines
drivers/pinctrl/sunplus/sppctl.c line 576
Quoted 11 lines
drivers/pinctrl/sunplus/sppctl.c new file +11
-0+if (sppctl_func_get (pctl, j) != group_selector) +continue ; +sppctl_func_set (pctl, j,0 ); + } +break ; + +case f_off_m:/* Mux */ +sppctl_first_master_set (&pctl->spp_gchip->chip, group_selector, + mux_f_mux, mux_m_keep); +sppctl_func_set (pctl, func_selector -2 , (group_selector ==0 ) ? + group_selector : group_selector -7 );
Quoted 2 lines
-2 and -7? Why? Add some comments or maybe #define these constants?
Yes, I'll defines and add some comments for the magic numbers next patch.
Quoted 20 lines
Quoted 7 lines
drivers/pinctrl/sunplus/sppctl.c new file +7
-0+static int stpctl_gpio_request_enable (struct pinctrl_dev *pctldev, +struct pinctrl_gpio_range *range,unsigned int offset) +{ +struct sppctl_pdata *pctl =pinctrl_dev_get_drvdata (pctldev); +struct pin_desc *pdesc; +int g_f, g_m; +drivers/pinctrl/sunplus/sppctl.c line 617
Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.c new file +10
-0+dev_dbg (pctldev->dev,"%s(%d)\n" , __func__, offset); + + g_f =sppctl_first_get (&pctl->spp_gchip->chip, offset); + g_m =sppctl_master_get (&pctl->spp_gchip->chip, offset); +if (g_f == mux_f_gpio && g_m == mux_m_gpio) +return 0 ; + + pdesc =pin_desc_get (pctldev, offset); +if (pdesc->mux_owner) +return -EACCES ;Do not reimplement the pinmux core please.
Quoted 3 lines
What you want to achieve here is "strict pinmux", i.e. setting the field "strict" in struct
pinmux_opsto true. Then you can just delete this check.
Yes, I'll remove the if-statement next patch.
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.c line 639
Quoted 3 lines
drivers/pinctrl/sunplus/sppctl.c new file +3
-0+static const struct pinmux_ops sppctl_pinmux_ops = { + .request = stpctl_request, + .free = stpctl_free,These are just set to empty functions. Delete these entries and the empty functions.
Yes, I'll remove all 'empty' functions next patch.
Quoted 10 lines
drivers/pinctrl/sunplus/sppctl.c line 647
Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c new file +8
-0+ .get_functions_count = stpctl_get_functions_count, + .get_function_name = stpctl_get_function_name, + .get_function_groups = stpctl_get_function_groups, + .set_mux = stpctl_set_mux, + .gpio_request_enable = stpctl_gpio_request_enable, + .gpio_disable_free = stpctl_gpio_disable_free, + .gpio_set_direction = stpctl_gpio_set_direction, + .strict = 1Use "true" rather than 1. (And do not reimplement the check.)
Yes, I'll do it next patch.
Quoted 8 lines
drivers/pinctrl/sunplus/sppctl.c line 1051
Quoted 5 lines
drivers/pinctrl/sunplus/sppctl.c new file +5
-0+static int sppctl_remove (struct platform_device *pdev) +{ +struct sppctl_pdata *sppctl = pdev->dev.platform_data; + +devm_pinctrl_unregister (&pdev->dev, sppctl->pctl_dev);This defies the idea with devm_* calls. Drop
remove()entirely becausedevm_allocated resources go away by themselves.
Yes, I'll remove devm_pinctrl_unregister() next patch. Sorry for buggy code. Fortunately, pinctrl driver will never be removed.
Quoted 17 lines
Quoted 1 line
+++
b/drivers/pinctrl/sunplus/sppctl.h(...)
drivers/pinctrl/sunplus/sppctl.h line 27
Quoted 6 lines
drivers/pinctrl/sunplus/sppctl.h new file +6
-0+/* (/16)*4 */ +#define R16_ROF (r) (((r) >> 4) << 2) +#define R16_BOF (r) ((r) % 16) +/* (/32)*4 */ +#define R32_ROF (r) (((r) >> 5) << 2) +#define R32_BOF (r) ((r) % 32)As mentioned I prefer explicit inlined code for these. The bit shifting here makes it really hard to know what is going on, the compiler will get it right if you use the right types and just write (n / 32) * 4. Please do not try to help the compiler optimizing it just leads to code that is hard to read.
Quoted 1 line
+#define
R32_VAL(r, boff)(((r) >> (boff)) & BIT(0))
Quoted 7 lines
To check the value of a certain bit use this pattern:
if (val & BIT(n))
To return a boolean clamped bit (return 0/1) do this idiom:
return !!(val & BIT(n));
Yes, I'll remove the four macros.
Write explicit inline code.
Quoted 4 lines
Other than these things I didn't notice anything more this time, but I might find even more stuff, but hey it's getting there! Yours,
Linus Walleij
Thanks, I'll review the whole code again and fix
the similar improper coding you pointed out.
Best regards,
Wells Lu
A message that is not in the archive (sent off-list or not yet received): CAFnkrsnY=-9VuN5ek9e-wyU+udrc6zsm_ttupe0mkEkcDK5j5A@mail.gmail.com
Re: [PATCH v3 2/2] pinctrl: Add driver for Sunplus SP7021
Hi Wells,
I understand things better now!
Quoted 7 lines · 呂芳騰
Quoted 6 lines
#define
SSPCTL_FUNC_FLAGBIT(0)if (func &
SSPCTL_FUNC_FLAG)Use the name that bit has in your documentation for the define so we know what is going on.
Quoted 6 lines
Actually, 'if (func & 1)' is not used to test bit 0, but test 'func' is an odd number or not.
If 'func' is even number, control-field is at bit 6 ~ 0. Its corresponding mask-field is at bit 22 ~ 16. If 'func' is odd number, control-field is at bit 14 ~ 8. Its corresponding mask-field is at bit 30 ~ 24.
Aha! That makes sense. Just put in exactly that comment in a block comment in the code so people maintaining this can see what is going on here and why you are checking for an odd/even number.
Quoted 9 lines
Control and mask fields of 'func' are arranged as shown below:
func # | register control-field mask-field
-------+------------------------------------0 | reg[0] ( 6:0) (22 : 6) 1 | reg[0] (14:8) (30 : 24) 2 | reg[1] ( 6:0) (22 : 6) 3 | reg[1] (14:8) (30 : 24)
This is also nice to actually have in the code. Be generous with comments I like that.
Quoted 8 lines
Quoted 3 lines
This layout with "mask and value" in registers needs to be explained somewhere it looks complex. I don't understand why a machine register contains a mask for example.
This is a hardware mechanism for protecting some important registers from being overwritten accidentally. The corresponding mask bit should be set first and then the control-bits or fields can be written. The design is originally requested from car makers.
Wow that is very very interesting! So the feature is there to stop a program that goes astray and just write random numbers all over the memory from doing something harmful.
Insert some comments about this at the top of the file or at the first time you use a mask.
Thanks for keeping fixing this up despite my sometimes confused comments. Most of my comment is about making the code easy to read by people that will maintain it, so my rule of thumb is if I have a hard time to understand it then others may have a hard time with it too.
Yours,
Linus Walleij