Basic StarFive JH7100 RISC-V SoC support
Subsystems (16)
Emil Renner Berthing
maintainercover Basic StarFive JH7100 RISC-V SoC support
This series adds support for the StarFive JH7100 RISC-V SoC. The SoC has many devices that needs non-coherent dma operations to work which isn't upstream yet[1], so this just adds basic support to boot up, get a serial console, blink an LED and reboot itself. Unlike the Allwinner D1 this chip doesn't use any extra pagetable bits, but instead the DDR RAM appears twice in the memory map, with and without the cache.
The JH7100 is a test chip for the upcoming JH7110 and about 300 BeagleV Starlight Beta boards were sent out with them as part of a now cancelled BeagleBoard.org project. However StarFive has produced more of the JH7100s and more boards will be available[2] to buy. Hopefully before the end of the year.
This series is also available at
https://github.com/esmil/linux/commits/starlight-minimal
..but a more complete kernel including non-coherent dma operations can be found at
https://github.com/starfive-tech/linux/tree/starlight
/Emil
[1]: https://lore.kernel.org/linux-riscv/[email protected]/
[2]: https://www.linkedin.com/pulse/starfive-release-open-source-single-board-platform-q3-2021-starfive/
Emil Renner Berthing (12):
RISC-V: Add StarFive SoC Kconfig option
dt-bindings: timer: Add StarFive JH7100 clint
dt-bindings: interrupt-controller: Add StarFive JH7100 plic
dt-bindings: reset: Add Starfive JH7100 reset bindings
reset: starfive-jh7100: Add StarFive JH7100 reset driver
dt-bindings: pinctrl: Add StarFive pinctrl definitions
dt-bindings: pinctrl: Add StarFive JH7100 bindings
pinctrl: starfive: Add pinctrl driver for StarFive SoCs
dt-bindings: serial: snps-dw-apb-uart: Add JH7100 uarts
serial: 8250_dw: Add skip_clk_set_rate quirk
RISC-V: Add initial StarFive JH7100 device tree
RISC-V: Add BeagleV Starlight Beta device tree
Geert Uytterhoeven (4):
dt-bindings: clock: starfive: Add JH7100 clock definitions
dt-bindings: clock: starfive: Add JH7100 bindings
clk: starfive: Add JH7100 clock generator driver
dt-bindings: reset: Add StarFive JH7100 reset definitions
.../clock/starfive,jh7100-clkgen.yaml | 56 + .../sifive,plic-1.0.0.yaml | 1 + .../pinctrl/starfive,jh7100-pinctrl.yaml | 274 ++++ .../bindings/reset/starfive,jh7100-reset.yaml | 38 + .../bindings/serial/snps-dw-apb-uart.yaml | 5 + .../bindings/timer/sifive,clint.yaml | 1 + MAINTAINERS | 22 + arch/riscv/Kconfig.socs | 8 + arch/riscv/boot/dts/Makefile | 1 + arch/riscv/boot/dts/starfive/Makefile | 2 + .../dts/starfive/jh7100-beaglev-starlight.dts | 162 ++ arch/riscv/boot/dts/starfive/jh7100.dtsi | 228 +++ drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/starfive/Kconfig | 10 + drivers/clk/starfive/Makefile | 3 + drivers/clk/starfive/clk-starfive-jh7100.c | 769 +++++++++ drivers/pinctrl/Kconfig | 17 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-starfive.c | 1439 +++++++++++++++++ drivers/reset/Kconfig | 8 + drivers/reset/Makefile | 1 + drivers/reset/reset-starfive-jh7100.c | 164 ++ drivers/tty/serial/8250/8250_dw.c | 32 +- include/dt-bindings/clock/starfive-jh7100.h | 202 +++ .../dt-bindings/pinctrl/pinctrl-starfive.h | 274 ++++ include/dt-bindings/reset/starfive-jh7100.h | 126 ++ 27 files changed, 3833 insertions(+), 13 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/starfive,jh7100-clkgen.yaml create mode 100644 Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml create mode 100644 Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml create mode 100644 arch/riscv/boot/dts/starfive/Makefile create mode 100644 arch/riscv/boot/dts/starfive/jh7100-beaglev-starlight.dts create mode 100644 arch/riscv/boot/dts/starfive/jh7100.dtsi create mode 100644 drivers/clk/starfive/Kconfig create mode 100644 drivers/clk/starfive/Makefile create mode 100644 drivers/clk/starfive/clk-starfive-jh7100.c create mode 100644 drivers/pinctrl/pinctrl-starfive.c create mode 100644 drivers/reset/reset-starfive-jh7100.c create mode 100644 include/dt-bindings/clock/starfive-jh7100.h create mode 100644 include/dt-bindings/pinctrl/pinctrl-starfive.h create mode 100644 include/dt-bindings/reset/starfive-jh7100.h
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 1/16 RISC-V: Add StarFive SoC Kconfig option
Add StarFive Kconfig option to select SoC specific and common drivers required for these SoCs.
--- arch/riscv/Kconfig.socs | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/riscv/Kconfig.socs +8 -0
@@ -19,6 +19,14 @@ config SOC_SIFIVE help This enables support for SiFive SoC platform hardware. +config SOC_STARFIVE + bool "StarFive SoCs" + select SERIAL_8250_DW + select SIFIVE_PLIC + select PINCTRL + help + This enables support for StarFive SoC platform hardware. + config SOC_VIRT bool "QEMU Virt Machine" select CLINT_TIMER if RISCV_M_MODE
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 2/16 dt-bindings: timer: Add StarFive JH7100 clint
In reply to Emil Renner BerthingAdd compatible string for the StarFive JH7100 clint.
--- Documentation/devicetree/bindings/timer/sifive,clint.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/timer/sifive,clint.yaml +1 -0
@@ -25,6 +25,7 @@ properties: items: - enum: - sifive,fu540-c000-clint + - starfive,jh7100-clint - canaan,k210-clint - const: sifive,clint0
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 3/16 dt-bindings: interrupt-controller: Add StarFive JH7100 plic
In reply to Emil Renner BerthingAdd compatible string for StarFive JH7100 plic.
--- .../bindings/interrupt-controller/sifive,plic-1.0.0.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml +1 -0
@@ -45,6 +45,7 @@ properties: items: - enum: - sifive,fu540-c000-plic + - starfive,jh7100-plic - canaan,k210-plic - const: sifive,plic-1.0.0
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 4/16 dt-bindings: clock: starfive: Add JH7100 clock definitions
In reply to Emil Renner BerthingFrom: Geert Uytterhoeven <[email protected]>
Add all clock outputs for the StarFive JH7100 clock generator.
Based on work by Ahmad Fatoum for Barebox, with "JH7100_" prefixes added to all definitions.
--- include/dt-bindings/clock/starfive-jh7100.h | 202 ++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 include/dt-bindings/clock/starfive-jh7100.h
include/dt-bindings/clock/starfive-jh7100.h new file +202 -0
@@ -0,0 +1,202 @@ +/* SPDX-License-Identifier: GPL-2.0 OR X11 */ +/* +* Copyright (C) 2021 Ahmad Fatoum, Pengutronix +*/ + +#ifndef __DT_BINDINGS_CLOCK_STARFIVE_JH7100_H__ +#define __DT_BINDINGS_CLOCK_STARFIVE_JH7100_H__ + +#define JH7100_CLK_CPUNDBUS_ROOT 0 +#define JH7100_CLK_DLA_ROOT 1 +#define JH7100_CLK_DSP_ROOT 2 +#define JH7100_CLK_GMACUSB_ROOT 3 +#define JH7100_CLK_PERH0_ROOT 4 +#define JH7100_CLK_PERH1_ROOT 5 +#define JH7100_CLK_VIN_ROOT 6 +#define JH7100_CLK_VOUT_ROOT 7 +#define JH7100_CLK_AUDIO_ROOT 8 +#define JH7100_CLK_CDECHIFI4_ROOT 9 +#define JH7100_CLK_CDEC_ROOT 10 +#define JH7100_CLK_VOUTBUS_ROOT 11 +#define JH7100_CLK_CPUNBUS_ROOT_DIV 12 +#define JH7100_CLK_DSP_ROOT_DIV 13 +#define JH7100_CLK_PERH0_SRC 14 +#define JH7100_CLK_PERH1_SRC 15 +#define JH7100_CLK_PLL0_TESTOUT 16 +#define JH7100_CLK_PLL1_TESTOUT 17 +#define JH7100_CLK_PLL2_TESTOUT 18 +#define JH7100_CLK_PLL2_REF 19 +#define JH7100_CLK_CPU_CORE 20 +#define JH7100_CLK_CPU_AXI 21 +#define JH7100_CLK_AHB_BUS 22 +#define JH7100_CLK_APB1_BUS 23 +#define JH7100_CLK_APB2_BUS 24 +#define JH7100_CLK_DOM3AHB_BUS 25 +#define JH7100_CLK_DOM7AHB_BUS 26 +#define JH7100_CLK_U74_CORE0 27 +#define JH7100_CLK_U74_CORE1 28 +#define JH7100_CLK_U74_AXI 29 +#define JH7100_CLK_U74RTC_TOGGLE 30 +#define JH7100_CLK_SGDMA2P_AXI 31 +#define JH7100_CLK_DMA2PNOC_AXI 32 +#define JH7100_CLK_SGDMA2P_AHB 33 +#define JH7100_CLK_DLA_BUS 34 +#define JH7100_CLK_DLA_AXI 35 +#define JH7100_CLK_DLANOC_AXI 36 +#define JH7100_CLK_DLA_APB 37 +#define JH7100_CLK_VP6_CORE 38 +#define JH7100_CLK_VP6BUS_SRC 39 +#define JH7100_CLK_VP6_AXI 40 +#define JH7100_CLK_VCDECBUS_SRC 41 +#define JH7100_CLK_VDEC_BUS 42 +#define JH7100_CLK_VDEC_AXI 43 +#define JH7100_CLK_VDECBRG_MAIN 44 +#define JH7100_CLK_VDEC_BCLK 45 +#define JH7100_CLK_VDEC_CCLK 46 +#define JH7100_CLK_VDEC_APB 47 +#define JH7100_CLK_JPEG_AXI 48 +#define JH7100_CLK_JPEG_CCLK 49 +#define JH7100_CLK_JPEG_APB 50 +#define JH7100_CLK_GC300_2X 51 +#define JH7100_CLK_GC300_AHB 52 +#define JH7100_CLK_JPCGC300_AXIBUS 53 +#define JH7100_CLK_GC300_AXI 54 +#define JH7100_CLK_JPCGC300_MAIN 55 +#define JH7100_CLK_VENC_BUS 56 +#define JH7100_CLK_VENC_AXI 57 +#define JH7100_CLK_VENCBRG_MAIN 58 +#define JH7100_CLK_VENC_BCLK 59 +#define JH7100_CLK_VENC_CCLK 60 +#define JH7100_CLK_VENC_APB 61 +#define JH7100_CLK_DDRPLL_DIV2 62 +#define JH7100_CLK_DDRPLL_DIV4 63 +#define JH7100_CLK_DDRPLL_DIV8 64 +#define JH7100_CLK_DDROSC_DIV2 65 +#define JH7100_CLK_DDRC0 66 +#define JH7100_CLK_DDRC1 67 +#define JH7100_CLK_DDRPHY_APB 68 +#define JH7100_CLK_NOC_ROB 69 +#define JH7100_CLK_NOC_COG 70 +#define JH7100_CLK_NNE_AHB 71 +#define JH7100_CLK_NNEBUS_SRC1 72 +#define JH7100_CLK_NNE_BUS 73 +#define JH7100_CLK_NNE_AXI 74 +#define JH7100_CLK_NNENOC_AXI 75 +#define JH7100_CLK_DLASLV_AXI 76 +#define JH7100_CLK_DSPX2C_AXI 77 +#define JH7100_CLK_HIFI4_SRC 78 +#define JH7100_CLK_HIFI4_COREFREE 79 +#define JH7100_CLK_HIFI4_CORE 80 +#define JH7100_CLK_HIFI4_BUS 81 +#define JH7100_CLK_HIFI4_AXI 82 +#define JH7100_CLK_HIFI4NOC_AXI 83 +#define JH7100_CLK_SGDMA1P_BUS 84 +#define JH7100_CLK_SGDMA1P_AXI 85 +#define JH7100_CLK_DMA1P_AXI 86 +#define JH7100_CLK_X2C_AXI 87 +#define JH7100_CLK_USB_BUS 88 +#define JH7100_CLK_USB_AXI 89 +#define JH7100_CLK_USBNOC_AXI 90 +#define JH7100_CLK_USBPHY_ROOTDIV 91 +#define JH7100_CLK_USBPHY_125M 92 +#define JH7100_CLK_USBPHY_PLLDIV25M 93 +#define JH7100_CLK_USBPHY_25M 94 +#define JH7100_CLK_AUDIO_DIV 95 +#define JH7100_CLK_AUDIO_SRC 96 +#define JH7100_CLK_AUDIO_12288 97 +#define JH7100_CLK_VIN_SRC 98 +#define JH7100_CLK_ISP0_BUS 99 +#define JH7100_CLK_ISP0_AXI 100 +#define JH7100_CLK_ISP0NOC_AXI 101 +#define JH7100_CLK_ISPSLV_AXI 102 +#define JH7100_CLK_ISP1_BUS 103 +#define JH7100_CLK_ISP1_AXI 104 +#define JH7100_CLK_ISP1NOC_AXI 105 +#define JH7100_CLK_VIN_BUS 106 +#define JH7100_CLK_VIN_AXI 107 +#define JH7100_CLK_VINNOC_AXI 108 +#define JH7100_CLK_VOUT_SRC 109 +#define JH7100_CLK_DISPBUS_SRC 110 +#define JH7100_CLK_DISP_BUS 111 +#define JH7100_CLK_DISP_AXI 112 +#define JH7100_CLK_DISPNOC_AXI 113 +#define JH7100_CLK_SDIO0_AHB 114 +#define JH7100_CLK_SDIO0_CCLKINT 115 +#define JH7100_CLK_SDIO0_CCLKINT_INV 116 +#define JH7100_CLK_SDIO1_AHB 117 +#define JH7100_CLK_SDIO1_CCLKINT 118 +#define JH7100_CLK_SDIO1_CCLKINT_INV 119 +#define JH7100_CLK_GMAC_AHB 120 +#define JH7100_CLK_GMAC_ROOT_DIV 121 +#define JH7100_CLK_GMAC_PTP_REF 122 +#define JH7100_CLK_GMAC_GTX 123 +#define JH7100_CLK_GMAC_RMII_TX 124 +#define JH7100_CLK_GMAC_RMII_RX 125 +#define JH7100_CLK_GMAC_TX 126 +#define JH7100_CLK_GMAC_TX_INV 127 +#define JH7100_CLK_GMAC_RX_PRE 128 +#define JH7100_CLK_GMAC_RX_INV 129 +#define JH7100_CLK_GMAC_RMII 130 +#define JH7100_CLK_GMAC_TOPHYREF 131 +#define JH7100_CLK_SPI2AHB_AHB 132 +#define JH7100_CLK_SPI2AHB_CORE 133 +#define JH7100_CLK_EZMASTER_AHB 134 +#define JH7100_CLK_E24_AHB 135 +#define JH7100_CLK_E24RTC_TOGGLE 136 +#define JH7100_CLK_QSPI_AHB 137 +#define JH7100_CLK_QSPI_APB 138 +#define JH7100_CLK_QSPI_REF 139 +#define JH7100_CLK_SEC_AHB 140 +#define JH7100_CLK_AES 141 +#define JH7100_CLK_SHA 142 +#define JH7100_CLK_PKA 143 +#define JH7100_CLK_TRNG_APB 144 +#define JH7100_CLK_OTP_APB 145 +#define JH7100_CLK_UART0_APB 146 +#define JH7100_CLK_UART0_CORE 147 +#define JH7100_CLK_UART1_APB 148 +#define JH7100_CLK_UART1_CORE 149 +#define JH7100_CLK_SPI0_APB 150 +#define JH7100_CLK_SPI0_CORE 151 +#define JH7100_CLK_SPI1_APB 152 +#define JH7100_CLK_SPI1_CORE 153 +#define JH7100_CLK_I2C0_APB 154 +#define JH7100_CLK_I2C0_CORE 155 +#define JH7100_CLK_I2C1_APB 156 +#define JH7100_CLK_I2C1_CORE 157 +#define JH7100_CLK_GPIO_APB 158 +#define JH7100_CLK_UART2_APB 159 +#define JH7100_CLK_UART2_CORE 160 +#define JH7100_CLK_UART3_APB 161 +#define JH7100_CLK_UART3_CORE 162 +#define JH7100_CLK_SPI2_APB 163 +#define JH7100_CLK_SPI2_CORE 164 +#define JH7100_CLK_SPI3_APB 165 +#define JH7100_CLK_SPI3_CORE 166 +#define JH7100_CLK_I2C2_APB 167 +#define JH7100_CLK_I2C2_CORE 168 +#define JH7100_CLK_I2C3_APB 169 +#define JH7100_CLK_I2C3_CORE 170 +#define JH7100_CLK_WDTIMER_APB 171 +#define JH7100_CLK_WDT_CORE 172 +#define JH7100_CLK_TIMER0_CORE 173 +#define JH7100_CLK_TIMER1_CORE 174 +#define JH7100_CLK_TIMER2_CORE 175 +#define JH7100_CLK_TIMER3_CORE 176 +#define JH7100_CLK_TIMER4_CORE 177 +#define JH7100_CLK_TIMER5_CORE 178 +#define JH7100_CLK_TIMER6_CORE 179 +#define JH7100_CLK_VP6INTC_APB 180 +#define JH7100_CLK_PWM_APB 181 +#define JH7100_CLK_MSI_APB 182 +#define JH7100_CLK_TEMP_APB 183 +#define JH7100_CLK_TEMP_SENSE 184 +#define JH7100_CLK_SYSERR_APB 185 + +#define JH7100_CLK_PLL0_OUT 186 +#define JH7100_CLK_PLL1_OUT 187 +#define JH7100_CLK_PLL2_OUT 188 + +#define JH7100_CLK_END 189 + +#endif /* __DT_BINDINGS_CLOCK_STARFIVE_JH7100_H__ */
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 5/16 dt-bindings: clock: starfive: Add JH7100 bindings
In reply to Emil Renner BerthingFrom: Geert Uytterhoeven <[email protected]>
Add device tree bindings for the StarFive JH7100 clock generator.
--- .../clock/starfive,jh7100-clkgen.yaml | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/starfive,jh7100-clkgen.yaml
Documentation/devicetree/bindings/clock/starfive,jh7100-clkgen.yaml new file +56 -0
@@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/starfive,jh7100-clkgen.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive JH7100 Clock Generator + +maintainers: + - Geert Uytterhoeven <[email protected]> + - Emil Renner Berthing <[email protected]> + +properties: + compatible: + const: starfive,jh7100-clkgen + + reg: + maxItems: 1 + + clocks: + items: + - description: Main clock source (25 MHz) + - description: Application-specific clock source (12-27 MHz) + - description: RMII reference clock (50 MHz) + - description: RGMII RX clock (125 MHz) + + clock-names: + items: + - const: osc_sys + - const: osc_aud + - const: gmac_rmii_ref + - const: gmac_gr_mii_rxclk + + '#clock-cells': + const: 1 + description: + See <dt-bindings/clock/starfive-jh7100.h> for valid indices. + +required: + - compatible + - reg + - clocks + - clock-names + - '#clock-cells' + +additionalProperties: false + +examples: + - | + clkgen: clock-controller@11800000 { + compatible = "starfive,jh7100-clkgen"; + reg = <0x11800000 0x10000>; + clocks = <&osc_sys>, <&osc_aud>, <&gmac_rmii_ref>, <&gmac_gr_mii_rxclk>; + clock-names = "osc_sys", "osc_aud", "gmac_rmii_ref", "gmac_gr_mii_rxclk"; + #clock-cells = <1>; + };
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 6/16 clk: starfive: Add JH7100 clock generator driver
In reply to Emil Renner BerthingFrom: Geert Uytterhoeven <[email protected]>
Add a driver for the StarFive JH7100 clock generator.
--- MAINTAINERS | 7 + drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/starfive/Kconfig | 10 + drivers/clk/starfive/Makefile | 3 + drivers/clk/starfive/clk-starfive-jh7100.c | 769 +++++++++++++++++++++ 6 files changed, 791 insertions(+) create mode 100644 drivers/clk/starfive/Kconfig create mode 100644 drivers/clk/starfive/Makefile create mode 100644 drivers/clk/starfive/clk-starfive-jh7100.c
MAINTAINERS +7 -0
@@ -17847,6 +17847,13 @@ M: Ion Badulescu <[email protected]> S: Odd Fixes F: drivers/net/ethernet/adaptec/starfire* +STARFIVE JH7100 CLOCK DRIVER +M: Emil Renner Berthing <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/clock/starfive,jh7100-clkgen.yaml +F: drivers/clk/starfive/clk-starfive-jh7100.c +F: include/dt-bindings/clock/starfive-jh7100.h + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>
drivers/clk/Kconfig +1 -0
@@ -412,6 +412,7 @@ source "drivers/clk/samsung/Kconfig" source "drivers/clk/sifive/Kconfig" source "drivers/clk/socfpga/Kconfig" source "drivers/clk/sprd/Kconfig" +source "drivers/clk/starfive/Kconfig" source "drivers/clk/sunxi/Kconfig" source "drivers/clk/sunxi-ng/Kconfig" source "drivers/clk/tegra/Kconfig"
drivers/clk/Makefile +1 -0
@@ -109,6 +109,7 @@ obj-y += socfpga/ obj-$(CONFIG_PLAT_SPEAR) += spear/ obj-y += sprd/ obj-$(CONFIG_ARCH_STI) += st/ +obj-$(CONFIG_SOC_STARFIVE) += starfive/ obj-$(CONFIG_ARCH_SUNXI) += sunxi/ obj-$(CONFIG_SUNXI_CCU) += sunxi-ng/ obj-$(CONFIG_ARCH_TEGRA) += tegra/
drivers/clk/starfive/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +config CLK_STARFIVE_JH7100 + bool "StarFive JH7100 clock support" + depends on SOC_STARFIVE || COMPILE_TEST + depends on OF + default SOC_STARFIVE + help + Say yes here to support the clock controller on the StarFive JH7100 + SoC.
drivers/clk/starfive/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +# StarFive Clock +obj-$(CONFIG_CLK_STARFIVE_JH7100) += clk-starfive-jh7100.o
drivers/clk/starfive/clk-starfive-jh7100.c new file +769 -0
769 lines not on this page · raw message
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 7/16 dt-bindings: reset: Add StarFive JH7100 reset definitions
In reply to Emil Renner BerthingFrom: Geert Uytterhoeven <[email protected]>
Add all resets for the StarFive JH7100 reset controller.
Based on work by Ahmad Fatoum for Barebox, with "JH7100_" prefixes added to all definitions.
--- include/dt-bindings/reset/starfive-jh7100.h | 126 ++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 include/dt-bindings/reset/starfive-jh7100.h
include/dt-bindings/reset/starfive-jh7100.h new file +126 -0
@@ -0,0 +1,126 @@ +/* SPDX-License-Identifier: GPL-2.0 OR X11 */ +/* +* Copyright (c) 2021 Ahmad Fatoum, Pengutronix +*/ + +#ifndef __DT_BINDINGS_RESET_STARFIVE_JH7100_H__ +#define __DT_BINDINGS_RESET_STARFIVE_JH7100_H__ + +#define JH7100_RSTN_DOM3AHB_BUS 0 +#define JH7100_RSTN_DOM7AHB_BUS 1 +#define JH7100_RST_U74 2 +#define JH7100_RSTN_U74_AXI 3 +#define JH7100_RSTN_SGDMA2P_AHB 4 +#define JH7100_RSTN_SGDMA2P_AXI 5 +#define JH7100_RSTN_DMA2PNOC_AXI 6 +#define JH7100_RSTN_DLA_AXI 7 +#define JH7100_RSTN_DLANOC_AXI 8 +#define JH7100_RSTN_DLA_APB 9 +#define JH7100_RST_VP6_DRESET 10 +#define JH7100_RST_VP6_BRESET 11 +#define JH7100_RSTN_VP6_AXI 12 +#define JH7100_RSTN_VDECBRG_MAIN 13 +#define JH7100_RSTN_VDEC_AXI 14 +#define JH7100_RSTN_VDEC_BCLK 15 +#define JH7100_RSTN_VDEC_CCLK 16 +#define JH7100_RSTN_VDEC_APB 17 +#define JH7100_RSTN_JPEG_AXI 18 +#define JH7100_RSTN_JPEG_CCLK 19 +#define JH7100_RSTN_JPEG_APB 20 +#define JH7100_RSTN_JPCGC300_MAIN 21 +#define JH7100_RSTN_GC300_2X 22 +#define JH7100_RSTN_GC300_AXI 23 +#define JH7100_RSTN_GC300_AHB 24 +#define JH7100_RSTN_VENC_AXI 25 +#define JH7100_RSTN_VENCBRG_MAIN 26 +#define JH7100_RSTN_VENC_BCLK 27 +#define JH7100_RSTN_VENC_CCLK 28 +#define JH7100_RSTN_VENC_APB 29 +#define JH7100_RSTN_DDRPHY_APB 30 +#define JH7100_RSTN_NOC_ROB 31 +#define JH7100_RSTN_NOC_COG 32 +#define JH7100_RSTN_HIFI4_AXI 33 +#define JH7100_RSTN_HIFI4NOC_AXI 34 +#define JH7100_RST_HIFI4_DRESET 35 +#define JH7100_RST_HIFI4_BRESET 36 +#define JH7100_RSTN_USB_AXI 37 +#define JH7100_RSTN_USBNOC_AXI 38 +#define JH7100_RSTN_SGDMA1P_AXI 39 +#define JH7100_RSTN_DMA1P_AXI 40 +#define JH7100_RSTN_X2C_AXI 41 +#define JH7100_RSTN_NNE_AHB 42 +#define JH7100_RSTN_NNE_AXI 43 +#define JH7100_RSTN_NNENOC_AXI 44 +#define JH7100_RSTN_DLASLV_AXI 45 +#define JH7100_RSTN_DSPX2C_AXI 46 +#define JH7100_RSTN_VIN_SRC 47 +#define JH7100_RSTN_ISPSLV_AXI 48 +#define JH7100_RSTN_VIN_AXI 49 +#define JH7100_RSTN_VINNOC_AXI 50 +#define JH7100_RSTN_ISP0_AXI 51 +#define JH7100_RSTN_ISP0NOC_AXI 52 +#define JH7100_RSTN_ISP1_AXI 53 +#define JH7100_RSTN_ISP1NOC_AXI 54 +#define JH7100_RSTN_VOUT_SRC 55 +#define JH7100_RSTN_DISP_AXI 56 +#define JH7100_RSTN_DISPNOC_AXI 57 +#define JH7100_RSTN_SDIO0_AHB 58 +#define JH7100_RSTN_SDIO1_AHB 59 +#define JH7100_RSTN_GMAC_AHB 60 +#define JH7100_RSTN_SPI2AHB_AHB 61 +#define JH7100_RSTN_SPI2AHB_CORE 62 +#define JH7100_RSTN_EZMASTER_AHB 63 +#define JH7100_RST_E24 64 +#define JH7100_RSTN_QSPI_AHB 65 +#define JH7100_RSTN_QSPI_CORE 66 +#define JH7100_RSTN_QSPI_APB 67 +#define JH7100_RSTN_SEC_AHB 68 +#define JH7100_RSTN_AES 69 +#define JH7100_RSTN_PKA 70 +#define JH7100_RSTN_SHA 71 +#define JH7100_RSTN_TRNG_APB 72 +#define JH7100_RSTN_OTP_APB 73 +#define JH7100_RSTN_UART0_APB 74 +#define JH7100_RSTN_UART0_CORE 75 +#define JH7100_RSTN_UART1_APB 76 +#define JH7100_RSTN_UART1_CORE 77 +#define JH7100_RSTN_SPI0_APB 78 +#define JH7100_RSTN_SPI0_CORE 79 +#define JH7100_RSTN_SPI1_APB 80 +#define JH7100_RSTN_SPI1_CORE 81 +#define JH7100_RSTN_I2C0_APB 82 +#define JH7100_RSTN_I2C0_CORE 83 +#define JH7100_RSTN_I2C1_APB 84 +#define JH7100_RSTN_I2C1_CORE 85 +#define JH7100_RSTN_GPIO_APB 86 +#define JH7100_RSTN_UART2_APB 87 +#define JH7100_RSTN_UART2_CORE 88 +#define JH7100_RSTN_UART3_APB 89 +#define JH7100_RSTN_UART3_CORE 90 +#define JH7100_RSTN_SPI2_APB 91 +#define JH7100_RSTN_SPI2_CORE 92 +#define JH7100_RSTN_SPI3_APB 93 +#define JH7100_RSTN_SPI3_CORE 94 +#define JH7100_RSTN_I2C2_APB 95 +#define JH7100_RSTN_I2C2_CORE 96 +#define JH7100_RSTN_I2C3_APB 97 +#define JH7100_RSTN_I2C3_CORE 98 +#define JH7100_RSTN_WDTIMER_APB 99 +#define JH7100_RSTN_WDT 100 +#define JH7100_RSTN_TIMER0 101 +#define JH7100_RSTN_TIMER1 102 +#define JH7100_RSTN_TIMER2 103 +#define JH7100_RSTN_TIMER3 104 +#define JH7100_RSTN_TIMER4 105 +#define JH7100_RSTN_TIMER5 106 +#define JH7100_RSTN_TIMER6 107 +#define JH7100_RSTN_VP6INTC_APB 108 +#define JH7100_RSTN_PWM_APB 109 +#define JH7100_RSTN_MSI_APB 110 +#define JH7100_RSTN_TEMP_APB 111 +#define JH7100_RSTN_TEMP_SENSE 112 +#define JH7100_RSTN_SYSERR_APB 113 + +#define JH7100_RSTN_END 114 + +#endif /* __DT_BINDINGS_RESET_STARFIVE_JH7100_H__ */
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 8/16 dt-bindings: reset: Add Starfive JH7100 reset bindings
In reply to Emil Renner BerthingAdd device tree bindings for the StarFive JH7100 reset controller.
--- .../bindings/reset/starfive,jh7100-reset.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml
Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml new file +38 -0
@@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/reset/starfive,jh7100-reset.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive JH7100 SoC Reset Controller Device Tree Bindings + +maintainers: + - Emil Renner Berthing <[email protected]> + +properties: + compatible: + enum: + - starfive,jh7100-reset + + reg: + maxItems: 1 + + "#reset-cells": + const: 1 + +required: + - compatible + - reg + - "#reset-cells" + +additionalProperties: false + +examples: + - | + rstgen: reset@11840000 { + compatible = "starfive,jh7100-reset"; + reg = <0x11840000 0x10000>; + #reset-cells = <1>; + }; + +...
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 9/16 reset: starfive-jh7100: Add StarFive JH7100 reset driver
In reply to Emil Renner BerthingAdd a driver for the StarFive JH7100 reset controller.
--- MAINTAINERS | 7 ++ drivers/reset/Kconfig | 8 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-starfive-jh7100.c | 164 ++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/reset/reset-starfive-jh7100.c
MAINTAINERS +7 -0
@@ -17854,6 +17854,13 @@ F: Documentation/devicetree/bindings/clock/starfive,jh7100-clkgen.yaml F: drivers/clk/starfive/clk-starfive-jh7100.c F: include/dt-bindings/clock/starfive-jh7100.h +STARFIVE JH7100 RESET CONTROLLER DRIVER +M: Emil Renner Berthing <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml +F: drivers/reset/reset-starfive-jh7100.c +F: include/dt-bindings/reset/starfive-jh7100.h + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>
drivers/reset/Kconfig +8 -0
@@ -92,6 +92,14 @@ config RESET_INTEL_GW Say Y to control the reset signals provided by reset controller. Otherwise, say N. +config RESET_STARFIVE_JH7100 + bool "StarFive JH7100 Reset Driver" + depends on SOC_STARFIVE || COMPILE_TEST + depends on OF + default SOC_STARFIVE + help + This enables the reset controller driver for the StarFive JH7100 SoC. + config RESET_K210 bool "Reset controller driver for Canaan Kendryte K210 SoC" depends on (SOC_CANAAN || COMPILE_TEST) && OF
drivers/reset/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_RESET_BRCMSTB_RESCAL) += reset-brcmstb-rescal.o obj-$(CONFIG_RESET_HSDK) += reset-hsdk.o obj-$(CONFIG_RESET_IMX7) += reset-imx7.o obj-$(CONFIG_RESET_INTEL_GW) += reset-intel-gw.o +obj-$(CONFIG_RESET_STARFIVE_JH7100) += reset-starfive-jh7100.o obj-$(CONFIG_RESET_K210) += reset-k210.o obj-$(CONFIG_RESET_LANTIQ) += reset-lantiq.o obj-$(CONFIG_RESET_LPC18XX) += reset-lpc18xx.o
drivers/reset/reset-starfive-jh7100.c new file +164 -0
164 lines not on this page · raw message
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 10/16 dt-bindings: pinctrl: Add StarFive pinctrl definitions
In reply to Emil Renner BerthingAdd definitons for pins and gpio input, output and output enable signals on the StarFive JH7100 SoC.
--- .../dt-bindings/pinctrl/pinctrl-starfive.h | 274 ++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 include/dt-bindings/pinctrl/pinctrl-starfive.h
include/dt-bindings/pinctrl/pinctrl-starfive.h new file +274 -0
@@ -0,0 +1,274 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2021 Emil Renner Berthing <[email protected]> +*/ +#ifndef _DT_BINDINGS_PINCTRL_STARFIVE_H +#define _DT_BINDINGS_PINCTRL_STARFIVE_H + +#define PAD_GPIO_OFFSET 0 +#define PAD_FUNC_SHARE_OFFSET 64 +#define PAD_GPIO (x) (PAD_GPIO_OFFSET + (x)) +#define PAD_FUNC_SHARE (x) (PAD_FUNC_SHARE_OFFSET + (x)) + +/* +* GPIOMUX bits: +* | 31 - 24 | 23 - 16 | 15 - 8 | 7 | 6 | 5 - 0 | +* | dout | doen | din | dout rev | doen rev | gpio nr | +* +* dout: output signal +* doen: output enable signal +* din: optional input signal, 0xff = none +* dout rev: output signal reverse bit +* doen rev: output enable signal reverse bit +* gpio nr: gpio number, 0 - 63 +*/ +#define GPIOMUX (n, dout, doen, din) ( \ + (((dout) & 0x80000000) >> (31 - 7)) | (((dout) & 0xff) << 24) | \ + (((doen) & 0x80000000) >> (31 - 6)) | (((doen) & 0xff) << 16) | \ + (((din) & 0xff) << 8) | \ + ((n) & 0x3f)) + +#define GPO_REVERSE 0x80000000 + +#define GPO_LOW 0 +#define GPO_HIGH 1 +#define GPO_ENABLE 0 +#define GPO_DISABLE 1 +#define GPO_CLK_GMAC_PAPHYREF 2 +#define GPO_JTAG_TDO 3 +#define GPO_JTAG_TDO_OEN 4 +#define GPO_DMIC_CLK_OUT 5 +#define GPO_DSP_JTDOEN_PAD 6 +#define GPO_DSP_JTDO_PAD 7 +#define GPO_I2C0_PAD_SCK_OE 8 +#define GPO_I2C0_PAD_SCK_OEN (GPO_I2C0_PAD_SCK_OE | GPO_REVERSE) +#define GPO_I2C0_PAD_SDA_OE 9 +#define GPO_I2C0_PAD_SDA_OEN (GPO_I2C0_PAD_SDA_OE | GPO_REVERSE) +#define GPO_I2C1_PAD_SCK_OE 10 +#define GPO_I2C1_PAD_SCK_OEN (GPO_I2C1_PAD_SCK_OE | GPO_REVERSE) +#define GPO_I2C1_PAD_SDA_OE 11 +#define GPO_I2C1_PAD_SDA_OEN (GPO_I2C1_PAD_SDA_OE | GPO_REVERSE) +#define GPO_I2C2_PAD_SCK_OE 12 +#define GPO_I2C2_PAD_SCK_OEN (GPO_I2C2_PAD_SCK_OE | GPO_REVERSE) +#define GPO_I2C2_PAD_SDA_OE 13 +#define GPO_I2C2_PAD_SDA_OEN (GPO_I2C2_PAD_SDA_OE | GPO_REVERSE) +#define GPO_I2C3_PAD_SCK_OE 14 +#define GPO_I2C3_PAD_SCK_OEN (GPO_I2C3_PAD_SCK_OE | GPO_REVERSE) +#define GPO_I2C3_PAD_SDA_OE 15 +#define GPO_I2C3_PAD_SDA_OEN (GPO_I2C3_PAD_SDA_OE | GPO_REVERSE) +#define GPO_I2SRX_BCLK_OUT 16 +#define GPO_I2SRX_BCLK_OUT_OEN 17 +#define GPO_I2SRX_LRCK_OUT 18 +#define GPO_I2SRX_LRCK_OUT_OEN 19 +#define GPO_I2SRX_MCLK_OUT 20 +#define GPO_I2STX_BCLK_OUT 21 +#define GPO_I2STX_BCLK_OUT_OEN 22 +#define GPO_I2STX_LRCK_OUT 23 +#define GPO_I2STX_LRCK_OUT_OEN 24 +#define GPO_I2STX_MCLK_OUT 25 +#define GPO_I2STX_SDOUT0 26 +#define GPO_I2STX_SDOUT1 27 +#define GPO_LCD_PAD_CSM_N 28 +#define GPO_PWM_PAD_OE_N_BIT0 29 +#define GPO_PWM_PAD_OE_N_BIT1 30 +#define GPO_PWM_PAD_OE_N_BIT2 31 +#define GPO_PWM_PAD_OE_N_BIT3 32 +#define GPO_PWM_PAD_OE_N_BIT4 33 +#define GPO_PWM_PAD_OE_N_BIT5 34 +#define GPO_PWM_PAD_OE_N_BIT6 35 +#define GPO_PWM_PAD_OE_N_BIT7 36 +#define GPO_PWM_PAD_OUT_BIT0 37 +#define GPO_PWM_PAD_OUT_BIT1 38 +#define GPO_PWM_PAD_OUT_BIT2 39 +#define GPO_PWM_PAD_OUT_BIT3 40 +#define GPO_PWM_PAD_OUT_BIT4 41 +#define GPO_PWM_PAD_OUT_BIT5 42 +#define GPO_PWM_PAD_OUT_BIT6 43 +#define GPO_PWM_PAD_OUT_BIT7 44 +#define GPO_PWMDAC_LEFT_OUT 45 +#define GPO_PWMDAC_RIGHT_OUT 46 +#define GPO_QSPI_CSN1_OUT 47 +#define GPO_QSPI_CSN2_OUT 48 +#define GPO_QSPI_CSN3_OUT 49 +#define GPO_REGISTER23_SCFG_CMSENSOR_RST0 50 +#define GPO_REGISTER23_SCFG_CMSENSOR_RST1 51 +#define GPO_REGISTER32_SCFG_GMAC_PHY_RSTN 52 +#define GPO_SDIO0_PAD_CARD_POWER_EN 53 +#define GPO_SDIO0_PAD_CCLK_OUT 54 +#define GPO_SDIO0_PAD_CCMD_OE 55 +#define GPO_SDIO0_PAD_CCMD_OEN (GPO_SDIO0_PAD_CCMD_OE | GPO_REVERSE) +#define GPO_SDIO0_PAD_CCMD_OUT 56 +#define GPO_SDIO0_PAD_CDATA_OE_BIT0 57 +#define GPO_SDIO0_PAD_CDATA_OEN_BIT0 (GPO_SDIO0_PAD_CDATA_OE_BIT0 | GPO_REVERSE) +#define GPO_SDIO0_PAD_CDATA_OE_BIT1 58 +#define GPO_SDIO0_PAD_CDATA_OEN_BIT1 (GPO_SDIO0_PAD_CDATA_OE_BIT1 | GPO_REVERSE) +#define GPO_SDIO0_PAD_CDATA_OE_BIT2 59 +#define GPO_SDIO0_PAD_CDATA_OEN_BIT2 (GPO_SDIO0_PAD_CDATA_OE_BIT2 | GPO_REVERSE) +#define GPO_SDIO0_PAD_CDATA_OE_BIT3 60 +#define GPO_SDIO0_PAD_CDATA_OEN_BIT3 (GPO_SDIO0_PAD_CDATA_OE_BIT3 | GPO_REVERSE) +#define GPO_SDIO0_PAD_CDATA_OE_BIT4 61 +#define GPO_SDIO0_PAD_CDATA_OEN_BIT4 (GPO_SDIO0_PAD_CDATA_OE_BIT4 | GPO_REVERSE) +#define GPO_SDIO0_PAD_CDATA_OE_BIT5 62 +#define GPO_SDIO0_PAD_CDATA_OEN_BIT5 (GPO_SDIO0_PAD_CDATA_OE_BIT5 | GPO_REVERSE) +#define GPO_SDIO0_PAD_CDATA_OE_BIT6 63 +#define GPO_SDIO0_PAD_CDATA_OEN_BIT6 (GPO_SDIO0_PAD_CDATA_OE_BIT6 | GPO_REVERSE) +#define GPO_SDIO0_PAD_CDATA_OE_BIT7 64 +#define GPO_SDIO0_PAD_CDATA_OEN_BIT7 (GPO_SDIO0_PAD_CDATA_OE_BIT7 | GPO_REVERSE) +#define GPO_SDIO0_PAD_CDATA_OUT_BIT0 65 +#define GPO_SDIO0_PAD_CDATA_OUT_BIT1 66 +#define GPO_SDIO0_PAD_CDATA_OUT_BIT2 67 +#define GPO_SDIO0_PAD_CDATA_OUT_BIT3 68 +#define GPO_SDIO0_PAD_CDATA_OUT_BIT4 69 +#define GPO_SDIO0_PAD_CDATA_OUT_BIT5 70 +#define GPO_SDIO0_PAD_CDATA_OUT_BIT6 71 +#define GPO_SDIO0_PAD_CDATA_OUT_BIT7 72 +#define GPO_SDIO0_PAD_RST_N 73 +#define GPO_SDIO1_PAD_CARD_POWER_EN 74 +#define GPO_SDIO1_PAD_CCLK_OUT 75 +#define GPO_SDIO1_PAD_CCMD_OE 76 +#define GPO_SDIO1_PAD_CCMD_OEN (GPO_SDIO1_PAD_CCMD_OE | GPO_REVERSE) +#define GPO_SDIO1_PAD_CCMD_OUT 77 +#define GPO_SDIO1_PAD_CDATA_OE_BIT0 78 +#define GPO_SDIO1_PAD_CDATA_OEN_BIT0 (GPO_SDIO1_PAD_CDATA_OE_BIT0 | GPO_REVERSE) +#define GPO_SDIO1_PAD_CDATA_OE_BIT1 79 +#define GPO_SDIO1_PAD_CDATA_OEN_BIT1 (GPO_SDIO1_PAD_CDATA_OE_BIT1 | GPO_REVERSE) +#define GPO_SDIO1_PAD_CDATA_OE_BIT2 80 +#define GPO_SDIO1_PAD_CDATA_OEN_BIT2 (GPO_SDIO1_PAD_CDATA_OE_BIT2 | GPO_REVERSE) +#define GPO_SDIO1_PAD_CDATA_OE_BIT3 81 +#define GPO_SDIO1_PAD_CDATA_OEN_BIT3 (GPO_SDIO1_PAD_CDATA_OE_BIT3 | GPO_REVERSE) +#define GPO_SDIO1_PAD_CDATA_OE_BIT4 82 +#define GPO_SDIO1_PAD_CDATA_OEN_BIT4 (GPO_SDIO1_PAD_CDATA_OE_BIT4 | GPO_REVERSE) +#define GPO_SDIO1_PAD_CDATA_OE_BIT5 83 +#define GPO_SDIO1_PAD_CDATA_OEN_BIT5 (GPO_SDIO1_PAD_CDATA_OE_BIT5 | GPO_REVERSE) +#define GPO_SDIO1_PAD_CDATA_OE_BIT6 84 +#define GPO_SDIO1_PAD_CDATA_OEN_BIT6 (GPO_SDIO1_PAD_CDATA_OE_BIT6 | GPO_REVERSE) +#define GPO_SDIO1_PAD_CDATA_OE_BIT7 85 +#define GPO_SDIO1_PAD_CDATA_OEN_BIT7 (GPO_SDIO1_PAD_CDATA_OE_BIT7 | GPO_REVERSE) +#define GPO_SDIO1_PAD_CDATA_OUT_BIT0 86 +#define GPO_SDIO1_PAD_CDATA_OUT_BIT1 87 +#define GPO_SDIO1_PAD_CDATA_OUT_BIT2 88 +#define GPO_SDIO1_PAD_CDATA_OUT_BIT3 89 +#define GPO_SDIO1_PAD_CDATA_OUT_BIT4 90 +#define GPO_SDIO1_PAD_CDATA_OUT_BIT5 91 +#define GPO_SDIO1_PAD_CDATA_OUT_BIT6 92 +#define GPO_SDIO1_PAD_CDATA_OUT_BIT7 93 +#define GPO_SDIO1_PAD_RST_N 94 +#define GPO_SPDIF_TX_SDOUT 95 +#define GPO_SPDIF_TX_SDOUT_OEN 96 +#define GPO_SPI0_PAD_OE_N 97 +#define GPO_SPI0_PAD_SCK_OUT 98 +#define GPO_SPI0_PAD_SS_0_N 99 +#define GPO_SPI0_PAD_SS_1_N 100 +#define GPO_SPI0_PAD_TXD 101 +#define GPO_SPI1_PAD_OE_N 102 +#define GPO_SPI1_PAD_SCK_OUT 103 +#define GPO_SPI1_PAD_SS_0_N 104 +#define GPO_SPI1_PAD_SS_1_N 105 +#define GPO_SPI1_PAD_TXD 106 +#define GPO_SPI2_PAD_OE_N 107 +#define GPO_SPI2_PAD_SCK_OUT 108 +#define GPO_SPI2_PAD_SS_0_N 109 +#define GPO_SPI2_PAD_SS_1_N 110 +#define GPO_SPI2_PAD_TXD 111 +#define GPO_SPI2AHB_PAD_OE_N_BIT0 112 +#define GPO_SPI2AHB_PAD_OE_N_BIT1 113 +#define GPO_SPI2AHB_PAD_OE_N_BIT2 114 +#define GPO_SPI2AHB_PAD_OE_N_BIT3 115 +#define GPO_SPI2AHB_PAD_TXD_BIT0 116 +#define GPO_SPI2AHB_PAD_TXD_BIT1 117 +#define GPO_SPI2AHB_PAD_TXD_BIT2 118 +#define GPO_SPI2AHB_PAD_TXD_BIT3 119 +#define GPO_SPI3_PAD_OE_N 120 +#define GPO_SPI3_PAD_SCK_OUT 121 +#define GPO_SPI3_PAD_SS_0_N 122 +#define GPO_SPI3_PAD_SS_1_N 123 +#define GPO_SPI3_PAD_TXD 124 +#define GPO_UART0_PAD_DTRN 125 +#define GPO_UART0_PAD_RTSN 126 +#define GPO_UART0_PAD_SOUT 127 +#define GPO_UART1_PAD_SOUT 128 +#define GPO_UART2_PAD_DTR_N 129 +#define GPO_UART2_PAD_RTS_N 130 +#define GPO_UART2_PAD_SOUT 131 +#define GPO_UART3_PAD_SOUT 132 +#define GPO_USB_DRV_BUS 133 + +#define GPI_NONE 0xffffffff + +#define GPI_CPU_JTAG_TCK 0 +#define GPI_CPU_JTAG_TDI 1 +#define GPI_CPU_JTAG_TMS 2 +#define GPI_CPU_JTAG_TRST 3 +#define GPI_DMIC_SDIN_BIT0 4 +#define GPI_DMIC_SDIN_BIT1 5 +#define GPI_DSP_JTCK_PAD 6 +#define GPI_DSP_JTDI_PAD 7 +#define GPI_DSP_JTMS_PAD 8 +#define GPI_DSP_TRST_PAD 9 +#define GPI_I2C0_PAD_SCK_IN 10 +#define GPI_I2C0_PAD_SDA_IN 11 +#define GPI_I2C1_PAD_SCK_IN 12 +#define GPI_I2C1_PAD_SDA_IN 13 +#define GPI_I2C2_PAD_SCK_IN 14 +#define GPI_I2C2_PAD_SDA_IN 15 +#define GPI_I2C3_PAD_SCK_IN 16 +#define GPI_I2C3_PAD_SDA_IN 17 +#define GPI_I2SRX_BCLK_IN 18 +#define GPI_I2SRX_LRCK_IN 19 +#define GPI_I2SRX_SDIN_BIT0 20 +#define GPI_I2SRX_SDIN_BIT1 21 +#define GPI_I2SRX_SDIN_BIT2 22 +#define GPI_I2STX_BCLK_IN 23 +#define GPI_I2STX_LRCK_IN 24 +#define GPI_SDIO0_PAD_CARD_DETECT_N 25 +#define GPI_SDIO0_PAD_CARD_WRITE_PRT 26 +#define GPI_SDIO0_PAD_CCMD_IN 27 +#define GPI_SDIO0_PAD_CDATA_IN_BIT0 28 +#define GPI_SDIO0_PAD_CDATA_IN_BIT1 29 +#define GPI_SDIO0_PAD_CDATA_IN_BIT2 30 +#define GPI_SDIO0_PAD_CDATA_IN_BIT3 31 +#define GPI_SDIO0_PAD_CDATA_IN_BIT4 32 +#define GPI_SDIO0_PAD_CDATA_IN_BIT5 33 +#define GPI_SDIO0_PAD_CDATA_IN_BIT6 34 +#define GPI_SDIO0_PAD_CDATA_IN_BIT7 35 +#define GPI_SDIO1_PAD_CARD_DETECT_N 36 +#define GPI_SDIO1_PAD_CARD_WRITE_PRT 37 +#define GPI_SDIO1_PAD_CCMD_IN 38 +#define GPI_SDIO1_PAD_CDATA_IN_BIT0 39 +#define GPI_SDIO1_PAD_CDATA_IN_BIT1 40 +#define GPI_SDIO1_PAD_CDATA_IN_BIT2 41 +#define GPI_SDIO1_PAD_CDATA_IN_BIT3 42 +#define GPI_SDIO1_PAD_CDATA_IN_BIT4 43 +#define GPI_SDIO1_PAD_CDATA_IN_BIT5 44 +#define GPI_SDIO1_PAD_CDATA_IN_BIT6 45 +#define GPI_SDIO1_PAD_CDATA_IN_BIT7 46 +#define GPI_SPDIF_RX_SDIN 47 +#define GPI_SPI0_PAD_RXD 48 +#define GPI_SPI0_PAD_SS_IN_N 49 +#define GPI_SPI1_PAD_RXD 50 +#define GPI_SPI1_PAD_SS_IN_N 51 +#define GPI_SPI2_PAD_RXD 52 +#define GPI_SPI2_PAD_SS_IN_N 53 +#define GPI_SPI2AHB_PAD_RXD_BIT0 54 +#define GPI_SPI2AHB_PAD_RXD_BIT1 55 +#define GPI_SPI2AHB_PAD_RXD_BIT2 56 +#define GPI_SPI2AHB_PAD_RXD_BIT3 57 +#define GPI_SPI2AHB_PAD_SS_N 58 +#define GPI_SPI2AHB_SLV_SCLKIN 59 +#define GPI_SPI3_PAD_RXD 60 +#define GPI_SPI3_PAD_SS_IN_N 61 +#define GPI_UART0_PAD_CTSN 62 +#define GPI_UART0_PAD_DCDN 63 +#define GPI_UART0_PAD_DSRN 64 +#define GPI_UART0_PAD_RIN 65 +#define GPI_UART0_PAD_SIN 66 +#define GPI_UART1_PAD_SIN 67 +#define GPI_UART2_PAD_CTS_N 68 +#define GPI_UART2_PAD_DCD_N 69 +#define GPI_UART2_PAD_DSR_N 70 +#define GPI_UART2_PAD_RI_N 71 +#define GPI_UART2_PAD_SIN 72 +#define GPI_UART3_PAD_SIN 73 +#define GPI_USB_OVER_CURRENT 74 + +#endif
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 11/16 dt-bindings: pinctrl: Add StarFive JH7100 bindings
In reply to Emil Renner BerthingAdd bindings for the StarFive JH7100 gpio/pin controller.
--- .../pinctrl/starfive,jh7100-pinctrl.yaml | 274 ++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml
Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml new file +274 -0
@@ -0,0 +1,274 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/starfive,jh7100-pinctrl.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive JH7100 Pin Controller Device Tree Bindings + +maintainers: + - Emil Renner Berthing <[email protected]> + - Drew Fustini <[email protected]> + +properties: + compatible: + const: starfive,jh7100-pinctrl + + reg: + minItems: 2 + maxItems: 2 + + reg-names: + items: + - const: "gpio" + - const: "padctl" + + clocks: + maxItems: 1 + + resets: + maxItems: 1 + + gpio-controller: true + + "#gpio-cells": + const: 2 + description: | + Number of cells in GPIO specifier. Since the generic GPIO + binding is used, the amount of cells must be specified as 2. + + interrupts: + maxItems: 1 + description: The GPIO parent interrupt. + + interrupt-controller: true + + "#interrupt-cells": + const: 2 + + starfive,signal-group: + description: | + The SoC has a global setting selecting one of 7 different pinmux + configurations of the pads named GPIO[0:63] and FUNC_SHARE[0:141]. After + this global setting is chosen only the 64 "GPIO" pins can be further + muxed by configuring them to be controlled by certain peripherals rather + than software. + Note that in configuration 0 none of GPIOs are routed to pads, and only + in configuration 1 are the GPIOs routed to the pads named GPIO[0:63]. + If this property is not set it defaults to the configuration already + chosen by the earlier boot stages. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3, 4, 5, 6] + +required: + - compatible + - reg + - reg-names + - clocks + - gpio-controller + - "#gpio-cells" + - interrupts + - interrupt-controller + - "#interrupt-cells" + +patternProperties: + '-[0-9]*$': + type: object + patternProperties: + '-pins*$': + type: object + description: | + A pinctrl node should contain at least one subnode representing the + pinctrl groups available on the machine. Each subnode will list the + pins it needs, and how they should be configured, with regard to + muxer configuration, bias, input enable/disable, input schmitt + trigger enable/disable, slew-rate and drive strength. + $ref: "/schemas/pinctrl/pincfg-node.yaml" + + properties: + pins: + description: | + The list of pin identifiers that properties in the node apply to. + This should be set using either the PAD_GPIO or PAD_FUNC_SHARE + macro. Either this or "pinmux" has to be specified. + + pinmux: + description: | + The list of GPIO identifiers and their mux settings that + properties in the node apply to. This should be set using the + GPIOMUX macro. Either this or "pins" has to be specified. + + bias-disable: true + + bias-pull-up: + type: boolean + + bias-pull-down: + type: boolean + + drive-strength: + enum: [ 14, 21, 28, 35, 42, 49, 56, 63 ] + + input-enable: true + + input-disable: true + + input-schmitt-enable: true + + input-schmitt-disable: true + + slew-rate: + maximum: 7 + + starfive,strong-pull-up: + description: enable strong pull-up. + type: boolean + + additionalProperties: false + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/starfive-jh7100.h> + #include <dt-bindings/reset/starfive-jh7100.h> + #include <dt-bindings/pinctrl/pinctrl-starfive.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + gpio: pinctrl@11910000 { + compatible = "starfive,jh7100-pinctrl"; + reg = <0x0 0x11910000 0x0 0x10000>, + <0x0 0x11858000 0x0 0x1000>; + reg-names = "gpio", "padctl"; + clocks = <&clkgen JH7100_CLK_GPIO_APB>; + resets = <&clkgen JH7100_RSTN_GPIO_APB>; + interrupts = <32>; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + starfive,signal-group = <6>; + + gmac_pins_default: gmac-0 { + gtxclk-pins { + pins = <PAD_FUNC_SHARE(115)>; + bias-pull-up; + drive-strength = <35>; + input-enable; + input-schmitt-enable; + slew-rate = <0>; + }; + miitxclk-pins { + pins = <PAD_FUNC_SHARE(116)>; + bias-pull-up; + drive-strength = <14>; + input-enable; + input-schmitt-disable; + slew-rate = <0>; + }; + tx-pins { + pins = <PAD_FUNC_SHARE(117)>, + <PAD_FUNC_SHARE(119)>, + <PAD_FUNC_SHARE(120)>, + <PAD_FUNC_SHARE(121)>, + <PAD_FUNC_SHARE(122)>, + <PAD_FUNC_SHARE(123)>, + <PAD_FUNC_SHARE(124)>, + <PAD_FUNC_SHARE(125)>, + <PAD_FUNC_SHARE(126)>; + bias-disable; + drive-strength = <35>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + rxclk-pins { + pins = <PAD_FUNC_SHARE(127)>; + bias-pull-up; + drive-strength = <14>; + input-enable; + input-schmitt-disable; + slew-rate = <6>; + }; + rxer-pins { + pins = <PAD_FUNC_SHARE(129)>; + bias-pull-up; + drive-strength = <14>; + input-enable; + input-schmitt-disable; + slew-rate = <0>; + }; + rx-pins { + pins = <PAD_FUNC_SHARE(128)>, + <PAD_FUNC_SHARE(130)>, + <PAD_FUNC_SHARE(131)>, + <PAD_FUNC_SHARE(132)>, + <PAD_FUNC_SHARE(133)>, + <PAD_FUNC_SHARE(134)>, + <PAD_FUNC_SHARE(135)>, + <PAD_FUNC_SHARE(136)>, + <PAD_FUNC_SHARE(137)>, + <PAD_FUNC_SHARE(138)>, + <PAD_FUNC_SHARE(139)>, + <PAD_FUNC_SHARE(140)>, + <PAD_FUNC_SHARE(141)>; + bias-pull-up; + drive-strength = <14>; + input-enable; + input-schmitt-enable; + slew-rate = <0>; + }; + }; + + i2c0_pins_default: i2c0-0 { + i2c-pins { + pinmux = <GPIOMUX(62, GPO_LOW, + GPO_I2C0_PAD_SCK_OEN, + GPI_I2C0_PAD_SCK_IN)>, + <GPIOMUX(61, GPO_LOW, + GPO_I2C0_PAD_SDA_OEN, + GPI_I2C0_PAD_SDA_IN)>; + bias-disable; /* external pull-up */ + input-enable; + input-schmitt-enable; + }; + }; + + uart3_pins_default: uart3-0 { + rx-pin { + pinmux = <GPIOMUX(13, GPO_LOW, GPO_DISABLE, + GPI_UART3_PAD_SIN)>; + bias-pull-up; + input-enable; + input-schmitt-enable; + }; + tx-pin { + pinmux = <GPIOMUX(14, GPO_UART3_PAD_SOUT, + GPO_ENABLE, GPI_NONE)>; + bias-disable; + input-disable; + input-schmitt-disable; + }; + }; + }; + + gmac { + pinctrl-0 = <&gmac_pins_default>; + pinctrl-names = "default"; + }; + + i2c0 { + pinctrl-0 = <&i2c0_pins_default>; + pinctrl-names = "default"; + }; + + uart3 { + pinctrl-0 = <&uart3_pins_default>; + pinctrl-names = "default"; + }; + }; + +...
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 13/16 dt-bindings: serial: snps-dw-apb-uart: Add JH7100 uarts
In reply to Emil Renner BerthingAdd compatibles for the StarFive JH7100 uarts.
--- .../devicetree/bindings/serial/snps-dw-apb-uart.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml +5 -0
@@ -40,6 +40,11 @@ properties: - brcm,bcm11351-dw-apb-uart - brcm,bcm21664-dw-apb-uart - const: snps,dw-apb-uart + - items: + - enum: + - starfive,jh7100-hsuart + - starfive,jh7100-uart + - const: snps,dw-apb-uart - const: snps,dw-apb-uart reg:
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 14/16 serial: 8250_dw: Add skip_clk_set_rate quirk
In reply to Emil Renner BerthingOn the StarFive JH7100 SoC the uart core clocks can't be set to exactly 16 * 115200Hz and many other common bitrates. Trying this will only result in a higher input clock, but low enough that the uart's internal divisor can't come close enough to the baud rate target. So rather than try to set the input clock it's better to rely solely on the uart's internal divisor.
--- drivers/tty/serial/8250/8250_dw.c | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
drivers/tty/serial/8250/8250_dw.c +19 -13
@@ -51,6 +51,7 @@ struct dw8250_data { unsigned int skip_autocfg:1; unsigned int uart_16550_compatible:1; + unsigned int skip_clk_set_rate:1; };static inline struct dw8250_data *to_dw8250_data (struct dw8250_port_data *data)
@@ -334,21 +335,23 @@ static void dw8250_set_termios(struct uart_port *p, struct ktermios *termios,long rate;int ret; -clk_disable_unprepare (d->clk); - rate =clk_round_rate (d->clk, newrate); -if (rate >0 ) { -/* -* Premilinary set the uartclk to the new clock rate so the -* clock update event handler caused by the clk_set_rate() -* calling wouldn't actually update the UART divisor since -* we about to do this anyway. -*/ -swap (p->uartclk, rate); - ret =clk_set_rate (d->clk, newrate); -if (ret) +if (!d->skip_clk_set_rate) { +clk_disable_unprepare (d->clk); + rate =clk_round_rate (d->clk, newrate); +if (rate >0 ) { +/* +* Premilinary set the uartclk to the new clock rate so +* the clock update event handler caused by the +* clk_set_rate() calling wouldn't actually update the +* UART divisor since we about to do this anyway. +*/ swap (p->uartclk, rate); + ret =clk_set_rate (d->clk, newrate); +if (ret) +swap (p->uartclk, rate); + } +clk_prepare_enable (d->clk); } -clk_prepare_enable (d->clk); p->status &= ~UPSTAT_AUTOCTS ;if (termios->c_cflag &CRTSCTS )
@@ -418,6 +421,8 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data) }if (of_device_is_compatible (np,"marvell,armada-38x-uart" )) p->serial_out = dw8250_serial_out38x; +if (of_device_is_compatible (np,"starfive,jh7100-uart" )) + data->skip_clk_set_rate = true; }else if (acpi_dev_present ("APMC0D08" ,NULL ,-1 )) { p->iotype =UPIO_MEM32 ;
@@ -700,6 +705,7 @@ static const struct of_device_id dw8250_of_match[] = { { .compatible = "cavium,octeon-3860-uart" }, { .compatible = "marvell,armada-38x-uart" }, { .compatible = "renesas,rzn1-uart" }, + { .compatible = "starfive,jh7100-uart" }, {/* Sentinel */ } };MODULE_DEVICE_TABLE (of, dw8250_of_match);
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 12/16 pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Emil Renner BerthingAdd a combined pinctrl and gpio driver for the StarFive JH7100 SoC.
For each "GPIO" there are two registers for configuring the output and output enable signals which may come from other peripherals. Among these are two special signals that are constant 0 and constant 1 respectively. Controlling the GPIOs from software is done by choosing one of these signals. In other words the same registers are used for both pinmuxing and controlling the GPIOs, which makes it easier to combine the pinctrl and gpio driver in one.
I wrote the pinconf and pinmux parts, but the gpio part of the code is based on the gpio driver in the vendor tree written by Huan Feng with cleanups and fixes by Drew and me.
--- MAINTAINERS | 8 + drivers/pinctrl/Kconfig | 17 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-starfive.c | 1439 ++++++++++++++++++++++++++++ 4 files changed, 1465 insertions(+) create mode 100644 drivers/pinctrl/pinctrl-starfive.c
MAINTAINERS +8 -0
@@ -17854,6 +17854,14 @@ F: Documentation/devicetree/bindings/clock/starfive,jh7100-clkgen.yaml F: drivers/clk/starfive/clk-starfive-jh7100.c F: include/dt-bindings/clock/starfive-jh7100.h +STARFIVE JH7100 PINCTRL DRIVER +M: Emil Renner Berthing <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml +F: drivers/pinctrl/pinctrl-starfive.c +F: include/dt-bindings/pinctrl/pinctrl-starfive.h + STARFIVE JH7100 RESET CONTROLLER DRIVER M: Emil Renner Berthing <[email protected]> S: Maintained
drivers/pinctrl/Kconfig +17 -0
@@ -265,6 +265,23 @@ config PINCTRL_ST select PINCONF select GPIOLIB_IRQCHIP +config PINCTRL_STARFIVE + bool "Pinctrl and GPIO driver for the StarFive JH7100 SoC" + depends on SOC_STARFIVE || COMPILE_TEST + depends on OF + default SOC_STARFIVE + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF + select GPIOLIB + select GPIOLIB_IRQCHIP + select OF_GPIO + help + Say yes here to support pin control on the StarFive JH7100 SoC. + This also provides an interface to the GPIO pins not used by other + peripherals supporting inputs, outputs, configuring pull-up/pull-down + and interrupts on input changes. + config PINCTRL_STMFX tristate "STMicroelectronics STMFX GPIO expander pinctrl driver" depends on I2C
drivers/pinctrl/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_PINCTRL_LANTIQ) += pinctrl-lantiq.o obj-$(CONFIG_PINCTRL_LPC18XX) += pinctrl-lpc18xx.o obj-$(CONFIG_PINCTRL_TB10X) += pinctrl-tb10x.o obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o +obj-$(CONFIG_PINCTRL_STARFIVE) += pinctrl-starfive.o obj-$(CONFIG_PINCTRL_STMFX) += pinctrl-stmfx.o obj-$(CONFIG_PINCTRL_ZYNQ) += pinctrl-zynq.o obj-$(CONFIG_PINCTRL_ZYNQMP) += pinctrl-zynqmp.o
drivers/pinctrl/pinctrl-starfive.c new file +1439 -0
1,439 lines not on this page · raw message
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 16/16 RISC-V: Add BeagleV Starlight Beta device tree
In reply to Emil Renner BerthingAdd initial device tree for the BeagleV Starlight Beta board. About 300 of these boards were sent out as part of a now cancelled BeagleBoard.org project.
I2C timing data is based on the device tree in the vendor u-boot port. Heartbeat LED added by Geert.
--- arch/riscv/boot/dts/Makefile | 1 + arch/riscv/boot/dts/starfive/Makefile | 2 + .../dts/starfive/jh7100-beaglev-starlight.dts | 162 ++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 arch/riscv/boot/dts/starfive/Makefile create mode 100644 arch/riscv/boot/dts/starfive/jh7100-beaglev-starlight.dts
arch/riscv/boot/dts/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 subdir-y += sifive +subdir-y += starfive subdir-$(CONFIG_SOC_CANAAN_K210_DTB_BUILTIN) += canaan subdir-y += microchip
arch/riscv/boot/dts/starfive/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +dtb-$(CONFIG_SOC_STARFIVE) += jh7100-beaglev-starlight.dtb
arch/riscv/boot/dts/starfive/jh7100-beaglev-starlight.dts new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.33.0
Emil Renner Berthing
maintainerPATCH 15/16 RISC-V: Add initial StarFive JH7100 device tree
In reply to Emil Renner BerthingAdd initial device tree for the StarFive JH7100 SoC.
The CPU and cache data is based on the device tree in the vendor u-boot port.
--- arch/riscv/boot/dts/starfive/jh7100.dtsi | 228 +++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 arch/riscv/boot/dts/starfive/jh7100.dtsi
arch/riscv/boot/dts/starfive/jh7100.dtsi new file +228 -0
@@ -0,0 +1,228 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* Copyright (c) 2021 StarFive Technology Co., Ltd. */ +/* Copyright (c) 2021 Emil Renner Berthing <[email protected]> */ + +/dts-v1/; +#include <dt-bindings/clock/starfive-jh7100.h> +#include <dt-bindings/reset/starfive-jh7100.h> + +/ { + compatible = "starfive,jh7100"; + #address-cells = <2>; + #size-cells = <2>; + + cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + compatible = "sifive,u74-mc", "riscv"; + reg = <0>; + d-cache-block-size = <64>; + d-cache-sets = <64>; + d-cache-size = <32768>; + d-tlb-sets = <1>; + d-tlb-size = <32>; + device_type = "cpu"; + i-cache-block-size = <64>; + i-cache-sets = <64>; + i-cache-size = <32768>; + i-tlb-sets = <1>; + i-tlb-size = <32>; + mmu-type = "riscv,sv39"; + riscv,isa = "rv64imafdc"; + tlb-split; + + cpu0_intc: interrupt-controller { + compatible = "riscv,cpu-intc"; + interrupt-controller; + #interrupt-cells = <1>; + }; + }; + + cpu@1 { + compatible = "sifive,u74-mc", "riscv"; + reg = <1>; + d-cache-block-size = <64>; + d-cache-sets = <64>; + d-cache-size = <32768>; + d-tlb-sets = <1>; + d-tlb-size = <32>; + device_type = "cpu"; + i-cache-block-size = <64>; + i-cache-sets = <64>; + i-cache-size = <32768>; + i-tlb-sets = <1>; + i-tlb-size = <32>; + mmu-type = "riscv,sv39"; + riscv,isa = "rv64imafdc"; + tlb-split; + + cpu1_intc: interrupt-controller { + compatible = "riscv,cpu-intc"; + interrupt-controller; + #interrupt-cells = <1>; + }; + }; + }; + + osc_sys: osc_sys { + compatible = "fixed-clock"; + #clock-cells = <0>; + /* This value must be overridden by the board */ + clock-frequency = <0>; + }; + + osc_aud: osc_aud { + compatible = "fixed-clock"; + #clock-cells = <0>; + /* This value must be overridden by the board */ + clock-frequency = <0>; + }; + + gmac_rmii_ref: gmac_rmii_ref { + compatible = "fixed-clock"; + #clock-cells = <0>; + /* Should be overridden by the board when needed */ + clock-frequency = <0>; + }; + + gmac_gr_mii_rxclk: gmac_gr_mii_rxclk { + compatible = "fixed-clock"; + #clock-cells = <0>; + /* Should be overridden by the board when needed */ + clock-frequency = <0>; + }; + + soc { + compatible = "simple-bus"; + interrupt-parent = <&plic>; + #address-cells = <2>; + #size-cells = <2>; + ranges; + + clint: clint@2000000 { + compatible = "starfive,jh7100-clint", "sifive,clint0"; + reg = <0x0 0x2000000 0x0 0x10000>; + interrupts-extended = <&cpu0_intc 3 &cpu0_intc 7 + &cpu1_intc 3 &cpu1_intc 7>; + }; + + plic: interrupt-controller@c000000 { + compatible = "starfive,jh7100-plic", "sifive,plic-1.0.0"; + reg = <0x0 0xc000000 0x0 0x4000000>; + interrupts-extended = <&cpu0_intc 11 &cpu0_intc 9 + &cpu1_intc 11 &cpu1_intc 9>; + interrupt-controller; + #address-cells = <0>; + #interrupt-cells = <1>; + riscv,ndev = <127>; + }; + + clkgen: clock-controller@11800000 { + compatible = "starfive,jh7100-clkgen"; + reg = <0x0 0x11800000 0x0 0x10000>; + clocks = <&osc_sys>, <&osc_aud>, <&gmac_rmii_ref>, <&gmac_gr_mii_rxclk>; + clock-names = "osc_sys", "osc_aud", "gmac_rmii_ref", "gmac_gr_mii_rxclk"; + #clock-cells = <1>; + }; + + rstgen: reset@11840000 { + compatible = "starfive,jh7100-reset"; + reg = <0x0 0x11840000 0x0 0x10000>; + #reset-cells = <1>; + }; + + i2c0: i2c@118b0000 { + compatible = "snps,designware-i2c"; + reg = <0x0 0x118b0000 0x0 0x10000>; + clocks = <&clkgen JH7100_CLK_I2C0_CORE>, + <&clkgen JH7100_CLK_I2C0_APB>; + clock-names = "ref", "pclk"; + resets = <&rstgen JH7100_RSTN_I2C0_APB>; + interrupts = <96>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + i2c1: i2c@118c0000 { + compatible = "snps,designware-i2c"; + reg = <0x0 0x118c0000 0x0 0x10000>; + clocks = <&clkgen JH7100_CLK_I2C1_CORE>, + <&clkgen JH7100_CLK_I2C1_APB>; + clock-names = "ref", "pclk"; + resets = <&rstgen JH7100_RSTN_I2C1_APB>; + interrupts = <97>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + gpio: pinctrl@11910000 { + compatible = "starfive,jh7100-pinctrl"; + reg = <0x0 0x11910000 0x0 0x10000>, + <0x0 0x11858000 0x0 0x1000>; + reg-names = "gpio", "padctl"; + clocks = <&clkgen JH7100_CLK_GPIO_APB>; + resets = <&rstgen JH7100_RSTN_GPIO_APB>; + interrupts = <32>; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + uart2: serial@12430000 { + compatible = "starfive,jh7100-uart", "snps,dw-apb-uart"; + reg = <0x0 0x12430000 0x0 0x10000>; + clocks = <&clkgen JH7100_CLK_UART2_CORE>, + <&clkgen JH7100_CLK_UART2_APB>; + clock-names = "baudclk", "apb_pclk"; + resets = <&rstgen JH7100_RSTN_UART2_APB>; + interrupts = <72>; + reg-io-width = <4>; + reg-shift = <2>; + status = "disabled"; + }; + + uart3: serial@12440000 { + compatible = "starfive,jh7100-uart", "snps,dw-apb-uart"; + reg = <0x0 0x12440000 0x0 0x10000>; + clocks = <&clkgen JH7100_CLK_UART3_CORE>, + <&clkgen JH7100_CLK_UART3_APB>; + clock-names = "baudclk", "apb_pclk"; + resets = <&rstgen JH7100_RSTN_UART3_APB>; + interrupts = <73>; + reg-io-width = <4>; + reg-shift = <2>; + status = "disabled"; + }; + + i2c2: i2c@12450000 { + compatible = "snps,designware-i2c"; + reg = <0x0 0x12450000 0x0 0x10000>; + clocks = <&clkgen JH7100_CLK_I2C2_CORE>, + <&clkgen JH7100_CLK_I2C2_APB>; + clock-names = "ref", "pclk"; + resets = <&rstgen JH7100_RSTN_I2C2_APB>; + interrupts = <74>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + + i2c3: i2c@12460000 { + compatible = "snps,designware-i2c"; + reg = <0x0 0x12460000 0x0 0x10000>; + clocks = <&clkgen JH7100_CLK_I2C3_CORE>, + <&clkgen JH7100_CLK_I2C3_APB>; + clock-names = "ref", "pclk"; + resets = <&rstgen JH7100_RSTN_I2C3_APB>; + interrupts = <75>; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + }; +};
Signature · 1 line
2.33.0
Philipp Zabel
maintainerRe: [PATCH v1 09/16] reset: starfive-jh7100: Add StarFive JH7100 reset driver
In reply to Emil Renner BerthingHi Emil,
Quoted 35 lines · Emil Renner Berthing
Add a driver for the StarFive JH7100 reset controller.
Signed-off-by Emil Renner Berthing <[email protected]>--- MAINTAINERS | 7 ++ drivers/reset/Kconfig | 8 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-starfive-jh7100.c | 164 ++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/reset/reset-starfive-jh7100.cMAINTAINERS +7
-0@@ -17854,6 +17854,13 @@ F: Documentation/devicetree/bindings/clock/starfive,jh7100-clkgen.yaml F: drivers/clk/starfive/clk-starfive-jh7100.c F: include/dt-bindings/clock/starfive-jh7100.h +STARFIVE JH7100 RESET CONTROLLER DRIVER +M: Emil Renner Berthing <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml +F: drivers/reset/reset-starfive-jh7100.c +F: include/dt-bindings/reset/starfive-jh7100.h + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>drivers/reset/Kconfig +0
-0@@ -92,6 +92,14 @@ config RESET_INTEL_GW Say Y to control the reset signals provided by reset controller.
drivers/reset/Kconfig config RESET_INTEL_GW · line 102
Quoted 10 lines
drivers/reset/Kconfig +8
-0Otherwise, say N. +config RESET_STARFIVE_JH7100 + bool "StarFive JH7100 Reset Driver" + depends on SOC_STARFIVE || COMPILE_TEST + depends on OF + default SOC_STARFIVE + help + This enables the reset controller driver for the StarFive JH7100 SoC. +
Please keep these in alphabetical (config symbol name) order.
regards
Philipp
Emil Renner Berthing
maintainerRe: [PATCH v1 09/16] reset: starfive-jh7100: Add StarFive JH7100 reset driver
Quoted 41 lines · Philipp Zabel
Hi Emil,
Quoted 37 lines · Emil Renner Berthing
Add a driver for the StarFive JH7100 reset controller.
Signed-off-by Emil Renner Berthing <[email protected]>--- MAINTAINERS | 7 ++ drivers/reset/Kconfig | 8 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-starfive-jh7100.c | 164 ++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/reset/reset-starfive-jh7100.cMAINTAINERS +7
-0@@ -17854,6 +17854,13 @@ F: Documentation/devicetree/bindings/clock/starfive,jh7100-clkgen.yaml F: drivers/clk/starfive/clk-starfive-jh7100.c F: include/dt-bindings/clock/starfive-jh7100.h +STARFIVE JH7100 RESET CONTROLLER DRIVER +M: Emil Renner Berthing <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml +F: drivers/reset/reset-starfive-jh7100.c +F: include/dt-bindings/reset/starfive-jh7100.h + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>drivers/reset/Kconfig +0
-0@@ -92,6 +92,14 @@ config RESET_INTEL_GW Say Y to control the reset signals provided by reset controller. Otherwise, say N.
Quoted 10 lines
drivers/reset/Kconfig config RESET_INTEL_GW · line 102
Quoted 8 lines
drivers/reset/Kconfig +8
-0+config RESET_STARFIVE_JH7100 + bool "StarFive JH7100 Reset Driver" + depends on SOC_STARFIVE || COMPILE_TEST + depends on OF + default SOC_STARFIVE + help + This enables the reset controller driver for the StarFive JH7100 SoC. +Please keep these in alphabetical (config symbol name) order.
Argh, sorry. I injected the _STARFIVE_ late and forgot about ordering. Will fix, thanks!
Quoted 2 lines
regards
Philipp
Philipp Zabel
maintainerRe: [PATCH v1 08/16] dt-bindings: reset: Add Starfive JH7100 reset bindings
In reply to Emil Renner BerthingQuoted 36 lines · Emil Renner Berthing
Add device tree bindings for the StarFive JH7100 reset controller.
Signed-off-by Emil Renner Berthing <[email protected]>--- .../bindings/reset/starfive,jh7100-reset.yaml | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yamlDocumentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml new file +22
-0@@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/reset/starfive,jh7100-reset.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive JH7100 SoC Reset Controller Device Tree Bindings + +maintainers: + - Emil Renner Berthing <[email protected]> + +properties: + compatible: + enum: + - starfive,jh7100-reset + + reg: + maxItems: 1 + + "#reset-cells": + const: 1 +
Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml line 32
Quoted 10 lines
Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml new file +10
-0+required: + - compatible + - reg + - "#reset-cells" + +additionalProperties: false + +examples: + - | + rstgen: reset@11840000 {
Better call this reset-controller@11840000, same in the .dtsi.
regards
Philipp
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Philipp Zabel
maintainerRe: [PATCH v1 09/16] reset: starfive-jh7100: Add StarFive JH7100 reset driver
In reply to Emil Renner BerthingQuoted 11 lines · Emil Renner Berthing
Add a driver for the StarFive JH7100 reset controller.
Signed-off-by Emil Renner Berthing <[email protected]>--- MAINTAINERS | 7 ++ drivers/reset/Kconfig | 8 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-starfive-jh7100.c | 164 ++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/reset/reset-starfive-jh7100.c
[...]
Quoted 6 lines
drivers/reset/reset-starfive-jh7100.c new file +0
-0@@ -0,0 +1,164 @@
[...]
Quoted 17 lines
drivers/reset/reset-starfive-jh7100.c new file +17
-0+static int jh7100_reset_update (struct reset_controller_dev *rcdev, +unsigned long id,bool assert) +{ +struct jh7100_reset *data =jh7100_reset_from (rcdev); +unsigned long offset = id /32 ; +void __iomem *reg_assert = data->base +JH7100_RESET_ASSERT0 +4 * offset; +void __iomem *reg_status = data->base +JH7100_RESET_STATUS0 +4 * offset; +u32 mask =BIT (id %32 ); +u32 done = jh7100_reset_asserted[offset] & mask; +unsigned long flags; +u32 value; + +if (!assert) + done ^= mask; + +spin_lock_irqsave (&data->lock, flags); +
drivers/reset/reset-starfive-jh7100.c line 77
Quoted 10 lines
drivers/reset/reset-starfive-jh7100.c new file +10
-0+ value =readl (reg_assert); +if (assert) + value |= mask; +else + value &= ~mask; +writel (value, reg_assert); + +do { + value =readl (reg_status) & mask; + }while (value != done);
Looking at the barebox driver, this could loop indefinitely if the caller forgets to enable the corresponding peripheral clock. Maybe use readl_poll_timeout() as a safety net.
regards
Philipp
Emil Renner Berthing
maintainerRe: [PATCH v1 09/16] reset: starfive-jh7100: Add StarFive JH7100 reset driver
Quoted 44 lines · Philipp Zabel
Quoted 11 lines · Emil Renner Berthing
Add a driver for the StarFive JH7100 reset controller.
Signed-off-by Emil Renner Berthing <[email protected]>--- MAINTAINERS | 7 ++ drivers/reset/Kconfig | 8 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-starfive-jh7100.c | 164 ++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 drivers/reset/reset-starfive-jh7100.c[...]
Quoted 6 lines
drivers/reset/reset-starfive-jh7100.c new file +0
-0@@ -0,0 +1,164 @@[...]
Quoted 23 lines
drivers/reset/reset-starfive-jh7100.c new file +23
-0+static int jh7100_reset_update (struct reset_controller_dev *rcdev, +unsigned long id,bool assert) +{ +struct jh7100_reset *data =jh7100_reset_from (rcdev); +unsigned long offset = id /32 ; +void __iomem *reg_assert = data->base +JH7100_RESET_ASSERT0 +4 * offset; +void __iomem *reg_status = data->base +JH7100_RESET_STATUS0 +4 * offset; +u32 mask =BIT (id %32 ); +u32 done = jh7100_reset_asserted[offset] & mask; +unsigned long flags; +u32 value; + +if (!assert) + done ^= mask; + +spin_lock_irqsave (&data->lock, flags); + + value =readl (reg_assert); +if (assert) + value |= mask; +else + value &= ~mask; +writel (value, reg_assert);
Quoted 8 lines
drivers/reset/reset-starfive-jh7100.c line 77
Quoted 4 lines
drivers/reset/reset-starfive-jh7100.c new file +4
-0+ +do { + value =readl (reg_status) & mask; + }while (value != done);Looking at the barebox driver, this could loop indefinitely if the caller forgets to enable the corresponding peripheral clock. Maybe use
readl_poll_timeout()as a safety net.
You're right. Asserting without the clock enabled is fine, but deasserting will hang forever. At least for the temperature sensor clock/resets I tried it with. I'll add the timeout, thanks!
/Emil
Re: [PATCH v1 01/16] RISC-V: Add StarFive SoC Kconfig option
In reply to Emil Renner BerthingQuoted 3 lines · Emil Renner Berthing
Add StarFive
Kconfigoption to select SoC specific and common drivers required for these SoCs.
...
Quoted 1 line
+ select
SERIAL_8250_DW
Is it critical for boot? Why?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 06/16] clk: starfive: Add JH7100 clock generator driver
In reply to Emil Renner BerthingQuoted 4 lines · Emil Renner Berthing
From: Geert Uytterhoeven <[email protected]>
Add a driver for the StarFive JH7100 clock generator.
...
drivers/clk/starfive/Kconfig line 6
Quoted 5 lines
drivers/clk/starfive/Kconfig new file +4
-0+config CLK_STARFIVE_JH7100 + bool "StarFive JH7100 clock support" + depends on SOC_STARFIVE || COMPILE_TEST + depends on OF
Why? I haven't found a compile dependency, so you reduce the test scope (when COMPILE_TEST=y).
...
You are usingbits.hmod_devicetable.h
which are not here
Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +10
-0+#include <linux/clk.h> +#include <linux/clk-provider.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/overflow.h> +#include <linux/platform_device.h>
...
Quoted 1 line
+ value |=
readl_relaxed(reg)& ~mask;
value is not masked, is it okay?
Usual pattern for this kind of operations is
value = (current & ~mask) | (value & mask);
Quoted 1 line
+
writel_relaxed(value, reg);
...
drivers/clk/starfive/clk-starfive-jh7100.c line 241
Quoted 4 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +4
-0+if (div > max) + div = max; + +return div;
return min(div, max); ?
...
drivers/clk/starfive/clk-starfive-jh7100.c line 256
Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +5
-0+ rate = parent / div; +if (rate < req->min_rate && div >1 ) { + div -=1 ; + rate = parent / div; + }
Seems like homegrown DIV_ROUND_UP() or so. Who will guarantee that decreasing div by 1 will satisfy the conditional again?
...
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FS
Perhaps __maybe_unused?
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +3
-0+#else +#define jh7100_clk_debug_init NULL +#endif
...
drivers/clk/starfive/clk-starfive-jh7100.c line 670
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +2
-0+if (idx >=JH7100_CLK_END ) { +dev_err (priv->dev,"%s: invalid index %u\n" , __func__, idx);
__func__ means that the message has no value on its own. Make it unique without using __func__, or drop completely.
Quoted 2 lines
(quoted diff) +2
-0+ return ERR_PTR(-EINVAL); + }
...
drivers/clk/starfive/clk-starfive-jh7100.c line 716
Quoted 7 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +6
-0+for (idx =0 ; idx <JH7100_CLK_PLL0_OUT ; idx++) { +struct clk_init_data init = { + .name = jh7100_clk_data[idx].name, + .ops = jh7100_clk_data[idx].ops, + .num_parents = ((jh7100_clk_data[idx].max &JH7100_CLK_MUX_MASK ) + >>JH7100_CLK_MUX_SHIFT ) +1 ,
With temporary variable this can be better written, or consider something like this
.num_parents =
((jh7100_clk_data[idx].max &JH7100_CLK_MUX_MASK) >> JH7100_CLK_MUX_SHIFT) + 1,
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +3
-0+ .flags = jh7100_clk_data[idx].flags, + }; +struct jh7100_clk *clk = &priv->reg[idx];
...
drivers/clk/starfive/clk-starfive-jh7100.c line 742
Quoted 2 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +2
-0+while (idx >0 ) +clk_hw_unregister (&priv->reg[--idx].hw);
The
while (idx--)
clk_hw_unregister(&priv->reg[idx].hw);is slightly better to read.
Quoted 2 lines
(quoted diff) +2
-0+ return ret; +}
...
drivers/clk/starfive/clk-starfive-jh7100.c line 763
Quoted 7 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +6
-0+static int __init clk_starfive_jh7100_init (void ) +{ +return platform_driver_probe (&clk_starfive_jh7100_driver, + clk_starfive_jh7100_probe); +} +
No need to have this blank line.
Quoted 1 line
+subsys_initcall(clk_starfive_jh7100_init);
Any explanation why subsys_initcall() is in use?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Emil Renner BerthingQuoted 11 lines · Emil Renner Berthing
Add a combined pinctrl and gpio driver for the StarFive JH7100 SoC.
For each "GPIO" there are two registers for configuring the output and output enable signals which may come from other peripherals. Among these are two special signals that are constant 0 and constant 1 respectively. Controlling the GPIOs from software is done by choosing one of these signals. In other words the same registers are used for both pinmuxing and controlling the GPIOs, which makes it easier to combine the pinctrl and gpio driver in one.
Quoted 3 lines
I wrote the pinconf and pinmux parts, but the gpio part of the code is based on the gpio driver in the vendor tree written by Huan Feng with cleanups and fixes by Drew and me.
s/gpio/GPIO/g
...
drivers/pinctrl/Kconfig config PINCTRL_ST · line 269
Quoted 3 lines
drivers/pinctrl/Kconfig +2
-0+config PINCTRL_STARFIVE + bool "Pinctrl and GPIO driver for the StarFive JH7100 SoC"
Why not module?
drivers/pinctrl/Kconfig config PINCTRL_ST · line 271
Quoted 3 lines
drivers/pinctrl/Kconfig +2
-0+ depends on SOC_STARFIVE || COMPILE_TEST + depends on OF
Do you really need this taking into account...
drivers/pinctrl/Kconfig config PINCTRL_ST · line 278
Quoted 8 lines
drivers/pinctrl/Kconfig +7
-0+ default SOC_STARFIVE + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF + select GPIOLIB + select GPIOLIB_IRQCHIP + select OF_GPIO
...this one?
...
bits.h ?
drivers/pinctrl/pinctrl-starfive.c line 12
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+#include <linux/clk.h> +#include <linux/gpio/driver.h> +#include <linux/io.h> +#include <linux/module.h>
mod_devicetable.h ?
drivers/pinctrl/pinctrl-starfive.c line 15
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+#include <linux/pinctrl/pinctrl.h> +#include <linux/pinctrl/pinmux.h>
Can you move these as a group after generic linux/* ones?
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#include <linux/platform_device.h> +#include <linux/reset.h> +#include <linux/spinlock.h>
...
Quoted 2 lines
+/*
+ * refer to Section 12. GPIO Registers in JH7100 datasheet:
Be consistent in your style, here for example missed capitalization.
Quoted 1 line
Is it possible to have the datasheet to be provided as Datasheet: tag in the commit message?
Quoted 1 line
+ */
...
drivers/pinctrl/pinctrl-starfive.c line 39
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+/* +* Global enable for GPIO interrupts, offset: 0x0, field: GPIOEN +* set to 1 if GPIO interrupts are enabled, set to 0 to disable +*/ +#define IRQ_GLOBAL_EN 0x0
s/0x0/0x00/g
...
drivers/pinctrl/pinctrl-starfive.c line 50
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+/* +* Interrupt Type for GPIO[31:0], offset: 0x10, field: GPIOS_0 +* set to 1 if edge-triggered, set to 0 for level-triggered +*/ +#define IRQ_TYPE_LOW 0x10 + +/* +* Interrupt Type for GPIO[63:32], offset: 0x14, field: GPIOS_1 +*/ +#define IRQ_TYPE_HIGH 0x14
As I reviewed below, the IRQ is represented by a few registers in a row, no need to define low and high separately. Ditto for the rest register pairs.
...
Quoted 4 lines
+/*
+ * Interrupt Status after Masking GPIO[31:0], offset:0x40, field:GPIOMIS_0
+ * status of edge-triggered or level-triggered after masking
+ * value of 1 means edge or level was detected, value of 0 menas not detected
menas?!
Quoted 1 line
+ */
...
Quoted 2 lines
+/*
+ * Data Value of GPIO for GPIO[31:0], offest:0x48, field:GPIODIN_0
offest?!
Quoted 2 lines
+ * dynamically reflects value on the GPIO pin
+ */
Please, run a spellchecker.
...
Quoted 1 line
+#define
IO_PADSHARE_SEL0x1a0
Okay, make all registers to be fixed width, i.e. 0x000 for IRQ global enabling and so on.
...
Quoted 1 line
+#define
PAD_SLEW_RATE_MASK0xe00U
GENMASK()
drivers/pinctrl/pinctrl-starfive.c line 168
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+#define PAD_BIAS_STRONG_PULL_UP 0x100U +#define PAD_INPUT_ENABLE 0x080U +#define PAD_INPUT_SCHMITT_ENABLE 0x040U +#define PAD_BIAS_DISABLE 0x020U +#define PAD_BIAS_PULL_DOWN 0x010U
All above seems like BIT(_something_).
drivers/pinctrl/pinctrl-starfive.c line 170
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+#define PAD_BIAS_MASK 0x130U +#define PAD_DRIVE_STRENGTH_MASK 0x007U
GENMASK()
...
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FS
__maybe_unused ?
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#else +#define starfive_pin_dbg_show NULL +#endif
...
Quoted 1 line
+ dout =
readl_relaxed(reg);
readl_relaxed(reg + 0x00)
drivers/pinctrl/pinctrl-starfive.c line 439
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ reg +=4 ; + doen =readl_relaxed (reg);
readl_relaxed(reg + 0x04);
...
drivers/pinctrl/pinctrl-starfive.c line 443
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+seq_printf (s,"dout=%u%s doen=%u%s" , + dout &0xffU , (dout &0x80000000U ) ?"r" :"" , + doen &0xffU , (doen &0x80000000U ) ?"r" :"" );
GENMASK()BIT()
...
Quoted 17 lines
drivers/pinctrl/pinctrl-starfive.c new file +17
-0+for_each_child_of_node (np, child) { +const __be32 *pinmux_list; +const __be32 *pins_list; +int pinmux_size; +int pins_size; + + pinmux_list =of_get_property (child,"pinmux" , &pinmux_size); + pins_list =of_get_property (child,"pins" , &pins_size); +if (pinmux_list && pins_list) { +dev_err (dev,"invalid pinctrl group %pOFn.%pOFn: %s\n" , + np, child,"both pinmux and pins set" ); +of_node_put (child); +return -EINVAL ; + } + +if (pinmux_list && pinmux_size >0 ) { + nmaps +=2 ;
drivers/pinctrl/pinctrl-starfive.c line 494
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+ }else if (pins_list && pins_size >0 ) { + nmaps +=1 ; + }else { +dev_err (dev,"invalid pinctrl group %pOFn.%pOFn: %s\n" , + np, child,"neither pinmux nor pins set" ); +of_node_put (child); +return -EINVAL ; + } + ngroups +=1 ; + }
This entire loop seems like
1) it should be based on something from pin control core;
2) it's using some low level APIs instead of better ones like of_property_read_uXX();
3) smells like unoptimized NIH.
...
Quoted 1 line
+ if ((list =
of_get_property(child, "pinmux", &npins))) {
Why not of_property_read_...() ?
...
Quoted 1 line
+ u32 v =
be32_to_cpu(*list++);
My gosh!
...
drivers/pinctrl/pinctrl-starfive.c line 551
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+for (i =0 ; i < npins; i++) + pins[i] =be32_to_cpu (*list++);
Ditto.
Even for this we have something in byteorder headers.
Summary, make sure you use much better _existing_ APIs instead of the above crap.
...
drivers/pinctrl/pinctrl-starfive.c line 597
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c new file +6
-0+free_pinmux: +devm_kfree (dev, pinmux); +free_pins: +devm_kfree (dev, pins); +free_grpname: +devm_kfree (dev, grpname);
What the heck?!
drivers/pinctrl/pinctrl-starfive.c line 603
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+free_pgnames: +devm_kfree (dev, pgnames);
Ditto.
...
Quoted 1 line
+out:
Useless label.
Quoted 1 line
+ return ret;
...
drivers/pinctrl/pinctrl-starfive.c line 639
Quoted 9 lines
drivers/pinctrl/pinctrl-starfive.c new file +8
-0+for (i =0 ; i < group->num_pins; i++) { +unsigned int gpio =starfive_pin_to_gpio (sfp, group->pins[i]); +void __iomem *reg_dout; +void __iomem *reg_doen; +void __iomem *reg_din; +u32 v, dout, doen, din; +unsigned long flags; + if (dev_WARN_ONCE(dev, gpio >= MAX_GPIO,
What?!
drivers/pinctrl/pinctrl-starfive.c line 646
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c new file +7
-0+ "%s: invalid gpiomux pin", group->name)) +continue ; + + v = pinmux[i]; + dout = ((v &BIT (7 )) << (31 -7 )) | ((v >>24 ) &0xffU ); + doen = ((v &BIT (6 )) << (31 -6 )) | ((v >>16 ) &0xffU ); + din = (v >>8 ) &0xffU ;
What is this voodoo for?
drivers/pinctrl/pinctrl-starfive.c line 656
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+if (din !=0xff ) + reg_din = sfp->base +GPIO_IN_OFFSET +4 * din; +else + reg_din =NULL ;
This looks like you maybe use gpio-regmap instead?
...
drivers/pinctrl/pinctrl-starfive.c line 685
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c new file +6
-0+void __iomem *reg = sfp->padctl +4 * (pin /2 ); +u32 value =readl_relaxed (reg); + +if (pin &1U ) + value >>=16 ; +return value;
u8 shift = 16 * (pin % 2);
return readl_relaxed() >> shift;
?
Something similar for below code.
...
drivers/pinctrl/pinctrl-starfive.c line 719
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#ifdef CONFIG_DEBUG_FS +static const struct pin_config_item +starfive_pinconf_custom_conf_items[ARRAY_SIZE(starfive_pinconf_custom_params)] = {
Instead of using ARAY_SIZE() here, use static_assert().
__maybe_unused?
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+ PCONFDUMP(PIN_CONFIG_STARFIVE_STRONG_PULL_UP, "input bias strong pull-up", NULL, false), +}; +#else +#define starfive_pinconf_custom_conf_items NULL +#endif
...
drivers/pinctrl/pinctrl-starfive.c line 727
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+static const unsigned char starfive_drive_strength[] = { +14 ,21 ,28 ,35 ,42 ,49 ,56 ,63 ,
Why table? Can you simply use the formula?!
Quoted 1 line
+};
...
Quoted 1 line
+ if (unlikely(!group))
Why unlikely() Must be justified here and everywhere where you are using it.
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+return -EINVAL ; + +return starfive_pinconf_get (pctldev, group->pins[0 ], config); +}
...
drivers/pinctrl/pinctrl-starfive.c line 815
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+case PIN_CONFIG_BIAS_DISABLE : + mask |=PAD_BIAS_MASK ;
Use it...
Quoted 1 line
+ value = (value & ~PAD_BIAS_MASK) |
PAD_BIAS_DISABLE;
...here. Ditto for the similar cases in this function and elsewhere.
After done this, you will see how you can simplify and deduplicate the switch-cases.
...
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FS
__maybe_unused ?
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#else +#define starfive_pinconf_dbg_show NULL +#endif
...
drivers/pinctrl/pinctrl-starfive.c line 986
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+if (gpio <32 ) { + value =readl_relaxed (sfp->base +GPIO_DIN_LOW ); + value = (value >> gpio) &1U ;
Drop
drivers/pinctrl/pinctrl-starfive.c line 989
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ }else { + value =readl_relaxed (sfp->base +GPIO_DIN_HIGH ); + value = (value >> (gpio -32 )) &1U ;
Drop
drivers/pinctrl/pinctrl-starfive.c line 685
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ } +return value;
return !!(value & BIT(gpio % 32));
...
drivers/pinctrl/pinctrl-starfive.c line 820
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+if (arg ==0 ) +return -ENOTSUPP ;
Shouldn't we return something else and pin control core will change it to something else if needed?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (arg == 0) + return -ENOTSUPP;
Ditto.
Quoted 2 lines
(quoted diff) +2
-0+ default: + return -ENOTSUPP;
...
drivers/pinctrl/pinctrl-starfive.c line 1109
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+if (gpio <0 || gpio >=MAX_GPIO ) +return ; + +if (gpio <32 ) { + ie = sfp->base +IRQ_ENABLE_LOW ; + mask =BIT (gpio); + }else { + ie = sfp->base +IRQ_ENABLE_HIGH ; + mask =BIT (gpio -32 ); + }
See below. And update all occurrences of these lines accordingly and everywhere. Also for IRQ may use helper functions if needed (but I don't believe the high and low register have stride more than 4).
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (gpio < 0 || gpio >= MAX_GPIO) + return -EINVAL;
How is it possible to be ever triggered?
...
drivers/pinctrl/pinctrl-starfive.c line 1191
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c new file +7
-0+if (gpio <32 ) { + base = sfp->base; + mask =BIT (gpio); + }else { + base = sfp->base +4 ; + mask =BIT (gpio -32 ); + }
base = sfp_base + 4 * (gpio / 32);
mask = BIT(gpio % 32);
...
drivers/pinctrl/pinctrl-starfive.c line 1201
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+irq_set_handler_locked (d, handle_edge_irq); +irq_set_handler_locked (d, handle_edge_irq);
Dup.
...
drivers/pinctrl/pinctrl-starfive.c line 1219
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+irq_set_handler_locked (d, handle_edge_irq); +irq_set_handler_locked (d, handle_level_irq); +irq_set_handler_locked (d, handle_level_irq);
Ditto.
...
Quoted 1 line
+
irq_set_handler_locked(d, handle_bad_irq);
Why is this here? Move it to ->probe().
...
drivers/pinctrl/pinctrl-starfive.c line 1308
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ clk =devm_clk_get (dev,NULL ); +if (IS_ERR (clk)) { + ret =PTR_ERR (clk); +dev_err (dev,"could not get clock: %d\n" , ret);
Thank you for spamming logs with this noise.
Quoted 1 line
+ return ret;
Hint: return dev_err_probe(). Ditto for the rest in this function.
Quoted 1 line
+ }
...
drivers/pinctrl/pinctrl-starfive.c line 1327
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) { +reset_control_deassert (rst);
Use devm_add_action_or_reset().
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+dev_err (dev,"could not enable clock: %d\n" , ret); +return ret; + }
...
Quoted 1 line
+ if (!of_property_read_u32(dev->of_node, "starfive,signal-group", &value)) {
Can be refactored without conditional. Also, why not to use device_property_read_u32()?
drivers/pinctrl/pinctrl-starfive.c line 1352
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+if (value <=6 ) +writel (value, sfp->padctl +IO_PADSHARE_SEL ); +else +dev_err (dev,"invalid signal group %u\n" , value);
Why _err if you not bail out here?
Quoted 1 line
+ }
...
drivers/pinctrl/pinctrl-starfive.c line 1358
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ value =readl (sfp->padctl +IO_PADSHARE_SEL ); +switch (value) { +case 0 : + sfp->gpios.pin_base =0x10000 ;
Magic number!
Quoted 17 lines
drivers/pinctrl/pinctrl-starfive.c new file +17
-0+ goto done; +case 1 : + sfp->gpios.pin_base =PAD_GPIO (0 ); +break ; +case 2 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (72 ); +break ; +case 3 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (70 ); +break ; +case 4 :case 5 :case 6 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (0 ); +break ; +default : +dev_err (dev,"invalid signal group %u\n" , value); +return -EINVAL ; + }
...
Quoted 1 line
+
sfp->gc.of_node=dev->of_node;
Isn't GPIO library do this for you?
...
Quoted 1 line
+ starfive_irq_chip.parent_device = dev;
Ditto?
...
drivers/pinctrl/pinctrl-starfive.c line 1398
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ sfp->gc.irq.parents = +devm_kcalloc (dev,1 ,sizeof (*sfp->gc.irq.parents),GFP_KERNEL );
1 -> sfp->gc.irq.num_parents
And hence move below line up.
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+if (!sfp->gc.irq.parents) +return -ENOMEM ; + sfp->gc.irq.num_parents =1 ;
...
Quoted 1 line
+
dev_info(dev, "StarFive GPIO chip registered %d GPIOs\n", sfp->gc.ngpio);
Redundant noise.
...
drivers/pinctrl/pinctrl-starfive.c line 1424
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+static const struct of_device_id starfive_of_match[] = { + { .compatible ="starfive,jh7100-pinctrl" }, + {/* sentinel */ },
No comma needed for terminator entry.
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 14/16] serial: 8250_dw: Add skip_clk_set_rate quirk
In reply to Emil Renner BerthingQuoted 7 lines · Emil Renner Berthing
On the StarFive JH7100 SoC the uart core clocks can't be set to exactly 16 * 115200Hz and many other common bitrates. Trying this will only result in a higher input clock, but low enough that the uart's internal divisor can't come close enough to the baud rate target. So rather than try to set the input clock it's better to rely solely on the uart's internal divisor.
s/uart/UART/g
...
Quoted 3 lines
unsigned int skip_autocfg:1;
unsigned int uart_16550_compatible:1;
+ unsigned int skip_clk_set_rate:1;Keep skip_* bitfields grouped.
...
Quoted 1 line
+ if (!d->skip_clk_set_rate) {
I believe you have to rebase this patch on top of tty/tty-next. Besides that, please, avoid indentation changes, i.e. refactor your patch accordgingly.
Quoted 1 line
}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Emil Renner Berthing
maintainerRe: [PATCH v1 06/16] clk: starfive: Add JH7100 clock generator driver
In reply to Andy ShevchenkoQuoted 9 lines · Andy Shevchenko
Quoted 4 lines · Emil Renner Berthing
From: Geert Uytterhoeven <[email protected]>
Add a driver for the StarFive JH7100 clock generator.
...
Quoted 8 lines
drivers/clk/starfive/Kconfig line 6
Quoted 5 lines
drivers/clk/starfive/Kconfig new file +4
-0+config CLK_STARFIVE_JH7100 + bool "StarFive JH7100 clock support" + depends on SOC_STARFIVE || COMPILE_TEST + depends on OFWhy? I haven't found a compile dependency, so you reduce the test scope (when COMPILE_TEST=y).
My thinking was that it can't ever be loaded on a !OF system, but you're right it'll just restrict compile testing. I'll remove, thanks.
Quoted 20 lines
...
You are using
bits.hmod_devicetable.h
which are not hereQuoted 10 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +10
-0+#include <linux/clk.h> +#include <linux/clk-provider.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/overflow.h> +#include <linux/platform_device.h> ...
Quoted 7 lines
Quoted 1 line
+ value |=
readl_relaxed(reg)& ~mask;value is not masked, is it okay?
Usual pattern for this kind of operations is
value = (current & ~mask) | (value & mask);
This function is only ever called with constants, already masked values or the parent number from the clk framework, so it should be ok.
Quoted 13 lines
Quoted 1 line
+
writel_relaxed(value, reg);...
drivers/clk/starfive/clk-starfive-jh7100.c line 241
Quoted 4 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +4
-0+if (div > max) + div = max; + +return div;return
min(div, max); ?...
Quoted 8 lines
drivers/clk/starfive/clk-starfive-jh7100.c line 256
Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +5
-0+ rate = parent / div; +if (rate < req->min_rate && div >1 ) { + div -=1 ; + rate = parent / div; + }Seems like homegrown
DIV_ROUND_UP()or so. Who will guarantee that decreasing div by 1 will satisfy the conditional again?
Maths unless I'm mistaken: div = DIV_ROUND_UP(parent, target), so in rational numbers
div - 1 < parent / target
But the target is clamped by min_rate and max_rate, so
min_rate <= target < parent / (div - 1) = rate
Sorry, re-using the rate varable for both the target and result is confusing. I'll fix that.
Quoted 5 lines
...
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FSPerhaps
__maybe_unused?
I can definitely use __maybe_unused for the function declaration, but then I'll need a conditional every time clk_ops.debug_init needs to be initialized to either the function or NULL depending on CONFIG_DEBUG_FS below. Is that better?
Quoted 42 lines
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +3
-0+#else +#define jh7100_clk_debug_init NULL +#endif ...
drivers/clk/starfive/clk-starfive-jh7100.c line 670
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +2
-0+if (idx >=JH7100_CLK_END ) { +dev_err (priv->dev,"%s: invalid index %u\n" , __func__, idx);
__func__means that the message has no value on its own. Make it unique without using__func__, or drop completely.Quoted 2 lines
(quoted diff) +2
-0+ return ERR_PTR(-EINVAL); + }...
drivers/clk/starfive/clk-starfive-jh7100.c line 716
Quoted 7 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +6
-0+for (idx =0 ; idx <JH7100_CLK_PLL0_OUT ; idx++) { +struct clk_init_data init = { + .name = jh7100_clk_data[idx].name, + .ops = jh7100_clk_data[idx].ops, + .num_parents = ((jh7100_clk_data[idx].max &JH7100_CLK_MUX_MASK ) + >>JH7100_CLK_MUX_SHIFT ) +1 ,With temporary variable this can be better written, or consider something like this
.num_parents = ((jh7100_clk_data[idx].max &
JH7100_CLK_MUX_MASK) >>JH7100_CLK_MUX_SHIFT) + 1,Quoted 3 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +3
-0+ .flags = jh7100_clk_data[idx].flags, + }; +struct jh7100_clk *clk = &priv->reg[idx];...
drivers/clk/starfive/clk-starfive-jh7100.c line 742
Quoted 2 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +2
-0+while (idx >0 ) +clk_hw_unregister (&priv->reg[--idx].hw);
Quoted 6 lines
The
while (idx--) clk_hw_unregister(&priv->reg[idx].hw);is slightly better to read.
It's not something I'll insist hard on, but I must admit I disagree. To me the above looks like cartoon characters running off a cliff and back. As a middle ground could we maybe do this?
while (idx)
clk_hw_unregister(&priv->reg[--idx].hw);Quoted 11 lines
Quoted 2 lines
(quoted diff) +2
-0+ return ret; +}...
Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +5
-0+static int __init clk_starfive_jh7100_init (void ) +{ +return platform_driver_probe (&clk_starfive_jh7100_driver, + clk_starfive_jh7100_probe); +}
Quoted 6 lines
Quoted 1 line
+
No need to have this blank line.
Quoted 1 line
+subsys_initcall(clk_starfive_jh7100_init);
Any explanation why
subsys_initcall()is in use?
TBH I just inherited that from Geert's first mock driver and never thought to question it. What would be a better alternative to try?
Thanks!
/Emil
Re: [PATCH v1 06/16] clk: starfive: Add JH7100 clock generator driver
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:42 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
+ value |=
readl_relaxed(reg)& ~mask;value is not masked, is it okay?
Usual pattern for this kind of operations is
value = (current & ~mask) | (value & mask);
This function is only ever called with constants, already masked values or the parent number from the clk framework, so it should be ok.
Up to you, but I think it's better to have a usual pattern.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
writel_relaxed(value, reg);
...
Quoted 9 lines
Quoted 8 lines
drivers/clk/starfive/clk-starfive-jh7100.c line 256
Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +5
-0+ rate = parent / div; +if (rate < req->min_rate && div >1 ) { + div -=1 ; + rate = parent / div; + }Seems like homegrown
DIV_ROUND_UP()or so. Who will guarantee that decreasing div by 1 will satisfy the conditional again?
Quoted 8 lines
Maths unless I'm mistaken: div =
DIV_ROUND_UP(parent, target), so in rational numbers
div - 1 < parent / target
But the target is clamped bymin_rateandmax_rate, so
min_rate<= target < parent / (div - 1) = rateSorry, re-using the rate varable for both the target and result is confusing. I'll fix that.
Also needs a comment, I believe.
...
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FSPerhaps
__maybe_unused?I can definitely use
__maybe_unusedfor the function declaration, but then I'll need a conditional every time clk_ops.debug_init needs to be initialized to either the function or NULL depending onCONFIG_DEBUG_FSbelow. Is that better?
Actually, why can't you always initialize the field? Shouldn't CLK core take care about this conditional?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +3
-0+#else +#define jh7100_clk_debug_init NULL +#endif
...
Quoted 8 lines
Quoted 8 lines
drivers/clk/starfive/clk-starfive-jh7100.c line 742
Quoted 2 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +2
-0+while (idx >0 ) +clk_hw_unregister (&priv->reg[--idx].hw);The
while (idx--) clk_hw_unregister(&priv->reg[idx].hw);
Quoted 8 lines
Quoted 1 line
is slightly better to read.
It's not something I'll insist hard on, but I must admit I disagree. To me the above looks like cartoon characters running off a cliff and back. As a middle ground could we maybe do this?
while (idx) clk_hw_unregister(&priv->reg[--idx].hw);
My point is exactly in having the common pattern for error paths, i.e.
while (counter--)
...bla-bla-bla...
Your second approach is better, but I think that proposed by me is even better.
...
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+subsys_initcall(clk_starfive_jh7100_init);
Any explanation why
subsys_initcall()is in use?TBH I just inherited that from Geert's first mock driver and never thought to question it. What would be a better alternative to try?
At least add a comment to explain the choice.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Emil Renner Berthing
maintainerRe: [PATCH v1 06/16] clk: starfive: Add JH7100 clock generator driver
Quoted 40 lines · Andy Shevchenko
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:42 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
+ value |=
readl_relaxed(reg)& ~mask;value is not masked, is it okay?
Usual pattern for this kind of operations is
value = (current & ~mask) | (value & mask);
This function is only ever called with constants, already masked values or the parent number from the clk framework, so it should be ok.
Up to you, but I think it's better to have a usual pattern.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
writel_relaxed(value, reg);...
Quoted 15 lines
Quoted 8 lines
drivers/clk/starfive/clk-starfive-jh7100.c line 256
Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +5
-0+ rate = parent / div; +if (rate < req->min_rate && div >1 ) { + div -=1 ; + rate = parent / div; + }Seems like homegrown
DIV_ROUND_UP()or so. Who will guarantee that decreasing div by 1 will satisfy the conditional again?Maths unless I'm mistaken: div =
DIV_ROUND_UP(parent, target), so in rational numbers
div - 1 < parent / target
But the target is clamped bymin_rateandmax_rate, so
min_rate<= target < parent / (div - 1) = rate
Quoted 4 lines
Quoted 2 lines
Sorry, re-using the rate varable for both the target and result is confusing. I'll fix that.
Also needs a comment, I believe.
Will add.
Quoted 6 lines
...
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FSPerhaps
__maybe_unused?
Quoted 7 lines
Quoted 4 lines
I can definitely use
__maybe_unusedfor the function declaration, but then I'll need a conditional every time clk_ops.debug_init needs to be initialized to either the function or NULL depending onCONFIG_DEBUG_FSbelow. Is that better?Actually, why can't you always initialize the field? Shouldn't CLK core take care about this conditional?
It could, but I see other drivers avoiding the code bloat when debugfs is not enabled, so I thought I'd copy that.
Quoted 44 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +3
-0+#else +#define jh7100_clk_debug_init NULL +#endif ...
Quoted 8 lines
Quoted 8 lines
drivers/clk/starfive/clk-starfive-jh7100.c line 742
Quoted 2 lines
drivers/clk/starfive/clk-starfive-jh7100.c new file +2
-0+while (idx >0 ) +clk_hw_unregister (&priv->reg[--idx].hw);The
while (idx--) clk_hw_unregister(&priv->reg[idx].hw);Quoted 8 lines
Quoted 1 line
is slightly better to read.
It's not something I'll insist hard on, but I must admit I disagree. To me the above looks like cartoon characters running off a cliff and back. As a middle ground could we maybe do this?
while (idx) clk_hw_unregister(&priv->reg[--idx].hw);My point is exactly in having the common pattern for error paths, i.e.
while (counter--)
...bla-bla-bla...Your second approach is better, but I think that proposed by me is even better.
...
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+subsys_initcall(clk_starfive_jh7100_init);
Any explanation why
subsys_initcall()is in use?TBH I just inherited that from Geert's first mock driver and never thought to question it. What would be a better alternative to try?
At least add a comment to explain the choice.
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v1 02/16] dt-bindings: timer: Add StarFive JH7100 clint
In reply to Emil Renner BerthingQuoted 3 lines · Emil Renner Berthing
Add compatible string for the StarFive JH7100 clint.
Signed-off-by Emil Renner Berthing <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v1 03/16] dt-bindings: interrupt-controller: Add StarFive JH7100 plic
In reply to Emil Renner BerthingQuoted 3 lines · Emil Renner Berthing
Add compatible string for StarFive JH7100 plic.
Signed-off-by Emil Renner Berthing <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v1 13/16] dt-bindings: serial: snps-dw-apb-uart: Add JH7100 uarts
In reply to Emil Renner BerthingQuoted 3 lines · Emil Renner Berthing
Add compatibles for the StarFive JH7100 uarts.
Signed-off-by Emil Renner Berthing <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Emil Renner Berthing
maintainerRe: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Andy ShevchenkoQuoted 69 lines · Andy Shevchenko
Quoted 11 lines · Emil Renner Berthing
Add a combined pinctrl and gpio driver for the StarFive JH7100 SoC.
For each "GPIO" there are two registers for configuring the output and output enable signals which may come from other peripherals. Among these are two special signals that are constant 0 and constant 1 respectively. Controlling the GPIOs from software is done by choosing one of these signals. In other words the same registers are used for both pinmuxing and controlling the GPIOs, which makes it easier to combine the pinctrl and gpio driver in one.
Quoted 3 lines
I wrote the pinconf and pinmux parts, but the gpio part of the code is based on the gpio driver in the vendor tree written by Huan Feng with cleanups and fixes by Drew and me.
s/gpio/GPIO/g
...
drivers/pinctrl/Kconfig config PINCTRL_ST · line 269
Quoted 3 lines
drivers/pinctrl/Kconfig +2
-0+config PINCTRL_STARFIVE + bool "Pinctrl and GPIO driver for the StarFive JH7100 SoC"Why not module?
drivers/pinctrl/Kconfig config PINCTRL_ST · line 271
Quoted 3 lines
drivers/pinctrl/Kconfig +2
-0+ depends on SOC_STARFIVE || COMPILE_TEST + depends on OFDo you really need this taking into account...
drivers/pinctrl/Kconfig config PINCTRL_ST · line 278
Quoted 8 lines
drivers/pinctrl/Kconfig +7
-0+ default SOC_STARFIVE + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF + select GPIOLIB + select GPIOLIB_IRQCHIP + select OF_GPIO...this one?
...
bits.h?drivers/pinctrl/pinctrl-starfive.c line 12
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+#include <linux/clk.h> +#include <linux/gpio/driver.h> +#include <linux/io.h> +#include <linux/module.h>
mod_devicetable.h?drivers/pinctrl/pinctrl-starfive.c line 15
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+#include <linux/pinctrl/pinctrl.h> +#include <linux/pinctrl/pinmux.h> Can you move these as a group after generic linux/* ones?
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#include <linux/platform_device.h> +#include <linux/reset.h> +#include <linux/spinlock.h> ...
Quoted 2 lines
+/*
+ * refer to Section 12. GPIO Registers in JH7100 datasheet:
Quoted 6 lines
Be consistent in your style, here for example missed capitalization.
Quoted 1 line
Is it possible to have the datasheet to be provided as Datasheet: tag in the commit message?
Oh neat. Didn't know about that. I'll also check with StarFive if this is the best address for it.
Quoted 78 lines
Quoted 1 line
+ */
...
drivers/pinctrl/pinctrl-starfive.c line 39
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+/* +* Global enable for GPIO interrupts, offset: 0x0, field: GPIOEN +* set to 1 if GPIO interrupts are enabled, set to 0 to disable +*/ +#define IRQ_GLOBAL_EN 0x0s/0x0/0x00/g
...
drivers/pinctrl/pinctrl-starfive.c line 50
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+/* +* Interrupt Type for GPIO[31:0], offset: 0x10, field: GPIOS_0 +* set to 1 if edge-triggered, set to 0 for level-triggered +*/ +#define IRQ_TYPE_LOW 0x10 + +/* +* Interrupt Type for GPIO[63:32], offset: 0x14, field: GPIOS_1 +*/ +#define IRQ_TYPE_HIGH 0x14As I reviewed below, the IRQ is represented by a few registers in a row, no need to define low and high separately. Ditto for the rest register pairs.
...
Quoted 4 lines
+/*
+ * Interrupt Status after Masking GPIO[31:0], offset:0x40, field:GPIOMIS_0
+ * status of edge-triggered or level-triggered after masking
+ * value of 1 means edge or level was detected, value of 0 menas not detectedmenas?!
Quoted 1 line
+ */
...
Quoted 2 lines
+/*
+ * Data Value of GPIO for GPIO[31:0], offest:0x48, field:GPIODIN_0offest?!
Quoted 2 lines
+ * dynamically reflects value on the GPIO pin
+ */Please, run a spellchecker.
...
Quoted 1 line
+#define
IO_PADSHARE_SEL0x1a0Okay, make all registers to be fixed width, i.e.
0x000for IRQ global enabling and so on....
Quoted 1 line
+#define
PAD_SLEW_RATE_MASK0xe00U
GENMASK()drivers/pinctrl/pinctrl-starfive.c line 168
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+#define PAD_BIAS_STRONG_PULL_UP 0x100U +#define PAD_INPUT_ENABLE 0x080U +#define PAD_INPUT_SCHMITT_ENABLE 0x040U +#define PAD_BIAS_DISABLE 0x020U +#define PAD_BIAS_PULL_DOWN 0x010UAll above seems like
BIT(_something_).drivers/pinctrl/pinctrl-starfive.c line 170
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+#define PAD_BIAS_MASK 0x130U +#define PAD_DRIVE_STRENGTH_MASK 0x007U
GENMASK()
Quoted 5 lines
...
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FS
__maybe_unused?
This is the same as the clock driver. If we don't have the ifdef here we'll need it when populating the ops structure later or live with the code bloat when debugfs is not enabled. Other driver don't seem to do that.
Quoted 86 lines
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#else +#define starfive_pin_dbg_show NULL +#endif ...
Quoted 1 line
+ dout =
readl_relaxed(reg);
readl_relaxed(reg + 0x00)drivers/pinctrl/pinctrl-starfive.c line 439
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ reg +=4 ; + doen =readl_relaxed (reg);
readl_relaxed(reg + 0x04);...
drivers/pinctrl/pinctrl-starfive.c line 443
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+seq_printf (s,"dout=%u%s doen=%u%s" , + dout &0xffU , (dout &0x80000000U ) ?"r" :"" , + doen &0xffU , (doen &0x80000000U ) ?"r" :"" );
GENMASK()BIT()...
Quoted 17 lines
drivers/pinctrl/pinctrl-starfive.c new file +17
-0+for_each_child_of_node (np, child) { +const __be32 *pinmux_list; +const __be32 *pins_list; +int pinmux_size; +int pins_size; + + pinmux_list =of_get_property (child,"pinmux" , &pinmux_size); + pins_list =of_get_property (child,"pins" , &pins_size); +if (pinmux_list && pins_list) { +dev_err (dev,"invalid pinctrl group %pOFn.%pOFn: %s\n" , + np, child,"both pinmux and pins set" ); +of_node_put (child); +return -EINVAL ; + } + +if (pinmux_list && pinmux_size >0 ) { + nmaps +=2 ;drivers/pinctrl/pinctrl-starfive.c line 494
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+ }else if (pins_list && pins_size >0 ) { + nmaps +=1 ; + }else { +dev_err (dev,"invalid pinctrl group %pOFn.%pOFn: %s\n" , + np, child,"neither pinmux nor pins set" ); +of_node_put (child); +return -EINVAL ; + } + ngroups +=1 ; + }This entire loop seems like
1) it should be based on something from pin control core;
2) it's using some low level APIs instead of better ones likeof_property_read_uXX();
3) smells like unoptimized NIH....
Quoted 1 line
+ if ((list =
of_get_property(child, "pinmux", &npins))) {Why not of_property_read_...() ?
...
Quoted 1 line
+ u32 v =
be32_to_cpu(*list++);My gosh!
...
drivers/pinctrl/pinctrl-starfive.c line 551
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+for (i =0 ; i < npins; i++) + pins[i] =be32_to_cpu (*list++);Ditto.
Even for this we have something in byteorder headers.Summary, make sure you use much better _existing_ APIs instead of the above crap.
...
Quoted 8 lines
drivers/pinctrl/pinctrl-starfive.c line 597
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c new file +6
-0+free_pinmux: +devm_kfree (dev, pinmux); +free_pins: +devm_kfree (dev, pins); +free_grpname: +devm_kfree (dev, grpname);What the heck?!
Just to be clear. You mean we don't need to explicitly free them because they're tied to the device right? I don't think the device will go away just because a single device tree entry can't be parsed, so on such errors this garbage would be left behind. You can still argue we shouldn't optimize for broken device trees, I just want to make it at conscious decision.
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c line 603
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+free_pgnames: +devm_kfree (dev, pgnames);Ditto.
...
Quoted 1 line
+out:
Useless label.
Hmm.. my compiler disagrees.
Quoted 24 lines
Quoted 1 line
+ return ret;
...
drivers/pinctrl/pinctrl-starfive.c line 639
Quoted 9 lines
drivers/pinctrl/pinctrl-starfive.c new file +8
-0+for (i =0 ; i < group->num_pins; i++) { +unsigned int gpio =starfive_pin_to_gpio (sfp, group->pins[i]); +void __iomem *reg_dout; +void __iomem *reg_doen; +void __iomem *reg_din; +u32 v, dout, doen, din; +unsigned long flags; + if (dev_WARN_ONCE(dev, gpio >= MAX_GPIO,What?!
drivers/pinctrl/pinctrl-starfive.c line 646
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c new file +7
-0+ "%s: invalid gpiomux pin", group->name)) +continue ; + + v = pinmux[i]; + dout = ((v &BIT (7 )) << (31 -7 )) | ((v >>24 ) &0xffU ); + doen = ((v &BIT (6 )) << (31 -6 )) | ((v >>16 ) &0xffU ); + din = (v >>8 ) &0xffU ;
Quoted 1 line
What is this voodoo for?
In order to do pinmux we need the following pieces of information from the device tree for each pin ("GPIO" they call it):
output signal: 0-133 + 1bit reverse flag
output enable signal: 0-133 + 1bit reverse flag optional input signal: 0-74 + special "none" value, right now 0xff gpio number: 0-63
As the code is now all that info is packed into a u32 for each pin using the GPIOMUX macro defined in the dt-binding header added in patch 10. There is also a diagram for how this packing is done. The above voodoo is for unpacking that.
I'd very much like to hear if you have a better solution for how to convey that information from the device tree to here.
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 656
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+if (din !=0xff ) + reg_din = sfp->base +GPIO_IN_OFFSET +4 * din; +else + reg_din =NULL ;This looks like you maybe use gpio-regmap instead?
This was discussed at length when Drew sent in the GPIO part of this code:
https://lore.kernel.org/linux-riscv/[email protected]/
The conclusion was that because pinmux and controlling the pins from software in GPIO mode uses the same registers it is better to do a combined driver like this that can share the lock among other things.
Quoted 19 lines
...
drivers/pinctrl/pinctrl-starfive.c line 685
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c new file +6
-0+void __iomem *reg = sfp->padctl +4 * (pin /2 ); +u32 value =readl_relaxed (reg); + +if (pin &1U ) + value >>=16 ; +return value;u8 shift = 16 * (pin % 2);
return
readl_relaxed()>> shift;?
Something similar for below code.
...
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c line 719
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#ifdef CONFIG_DEBUG_FS +static const struct pin_config_item +starfive_pinconf_custom_conf_items[ARRAY_SIZE(starfive_pinconf_custom_params)] = {Instead of using
ARAY_SIZE()here, usestatic_assert().
__maybe_unused?
As above.
Quoted 8 lines
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+ PCONFDUMP(PIN_CONFIG_STARFIVE_STRONG_PULL_UP, "input bias strong pull-up", NULL, false), +}; +#else +#define starfive_pinconf_custom_conf_items NULL +#endif ...
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c line 727
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+static const unsigned char starfive_drive_strength[] = { +14 ,21 ,28 ,35 ,42 ,49 ,56 ,63 ,Why table? Can you simply use the formula?!
Heh, yeah. So these are rounded values from a table and I never noticed that after rounding they follow a nice arithmetic progression. It'll probably still be nice to have an explanation in the comments about the formula then.
Quoted 60 lines
Quoted 1 line
+};
...
Quoted 1 line
+ if (unlikely(!group))
Why
unlikely()Must be justified here and everywhere where you are using it.Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+return -EINVAL ; + +return starfive_pinconf_get (pctldev, group->pins[0 ], config); +}...
drivers/pinctrl/pinctrl-starfive.c line 815
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+case PIN_CONFIG_BIAS_DISABLE : + mask |=PAD_BIAS_MASK ;Use it...
Quoted 1 line
+ value = (value & ~PAD_BIAS_MASK) |
PAD_BIAS_DISABLE;...here. Ditto for the similar cases in this function and elsewhere.
After done this, you will see how you can simplify and deduplicate the switch-cases.
...
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FS
__maybe_unused?Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#else +#define starfive_pinconf_dbg_show NULL +#endif ...
drivers/pinctrl/pinctrl-starfive.c line 986
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+if (gpio <32 ) { + value =readl_relaxed (sfp->base +GPIO_DIN_LOW ); + value = (value >> gpio) &1U ;Drop
drivers/pinctrl/pinctrl-starfive.c line 989
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ }else { + value =readl_relaxed (sfp->base +GPIO_DIN_HIGH ); + value = (value >> (gpio -32 )) &1U ;Drop
drivers/pinctrl/pinctrl-starfive.c line 685
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ } +return value;return !!(value & BIT(gpio % 32));
Quoted 8 lines
...
drivers/pinctrl/pinctrl-starfive.c line 820
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+if (arg ==0 ) +return -ENOTSUPP ;Shouldn't we return something else and pin control core will change it to something else if needed?
The documentation include/linux/pinctrl/pinconf.h has rules for when to return -ENOTSUPP and -EINVAL.
Quoted 61 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (arg == 0) + return -ENOTSUPP;Ditto.
Quoted 2 lines
(quoted diff) +2
-0+ default: + return -ENOTSUPP;...
drivers/pinctrl/pinctrl-starfive.c line 1109
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+if (gpio <0 || gpio >=MAX_GPIO ) +return ; + +if (gpio <32 ) { + ie = sfp->base +IRQ_ENABLE_LOW ; + mask =BIT (gpio); + }else { + ie = sfp->base +IRQ_ENABLE_HIGH ; + mask =BIT (gpio -32 ); + }See below. And update all occurrences of these lines accordingly and everywhere. Also for IRQ may use helper functions if needed (but I don't believe the high and low register have stride more than 4).
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (gpio < 0 || gpio >= MAX_GPIO) + return -EINVAL;How is it possible to be ever triggered?
...
drivers/pinctrl/pinctrl-starfive.c line 1191
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c new file +7
-0+if (gpio <32 ) { + base = sfp->base; + mask =BIT (gpio); + }else { + base = sfp->base +4 ; + mask =BIT (gpio -32 ); + }base =
sfp_base+ 4 * (gpio / 32);
mask = BIT(gpio % 32);...
drivers/pinctrl/pinctrl-starfive.c line 1201
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+irq_set_handler_locked (d, handle_edge_irq); +irq_set_handler_locked (d, handle_edge_irq);Dup.
...
drivers/pinctrl/pinctrl-starfive.c line 1219
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+irq_set_handler_locked (d, handle_edge_irq); +irq_set_handler_locked (d, handle_level_irq); +irq_set_handler_locked (d, handle_level_irq);
Quoted 7 lines
Ditto.
...
Quoted 1 line
+
irq_set_handler_locked(d, handle_bad_irq);Why is this here? Move it to ->probe().
My thinking was that if something tries to set a an unsupported irq type, we should make sure the caller doesn't get spurious interrupts because we left the handler at its old value.
Quoted 36 lines
...
drivers/pinctrl/pinctrl-starfive.c line 1308
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ clk =devm_clk_get (dev,NULL ); +if (IS_ERR (clk)) { + ret =PTR_ERR (clk); +dev_err (dev,"could not get clock: %d\n" , ret);Thank you for spamming logs with this noise.
Quoted 1 line
+ return ret;
Hint: return
dev_err_probe(). Ditto for the rest in this function.Quoted 1 line
+ }
...
drivers/pinctrl/pinctrl-starfive.c line 1327
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) { +reset_control_deassert (rst);Use
devm_add_action_or_reset().Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+dev_err (dev,"could not enable clock: %d\n" , ret); +return ret; + }...
Quoted 1 line
+ if (!of_property_read_u32(dev->of_node, "starfive,signal-group", &value)) {
Can be refactored without conditional. Also, why not to use
device_property_read_u32()?
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c line 1352
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+if (value <=6 ) +writel (value, sfp->padctl +IO_PADSHARE_SEL ); +else +dev_err (dev,"invalid signal group %u\n" , value);Why
_errif you not bail out here?
My thinking was that if the device tree specifies an invalid signal group we should just leave the setting alone and not break booting, but still be loud about it. Maybe that's too lenient and it's better to crash and burn immediately if someone does that.
Quoted 74 lines
Quoted 1 line
+ }
...
drivers/pinctrl/pinctrl-starfive.c line 1358
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ value =readl (sfp->padctl +IO_PADSHARE_SEL ); +switch (value) { +case 0 : + sfp->gpios.pin_base =0x10000 ;Magic number!
Quoted 17 lines
drivers/pinctrl/pinctrl-starfive.c new file +17
-0+ goto done; +case 1 : + sfp->gpios.pin_base =PAD_GPIO (0 ); +break ; +case 2 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (72 ); +break ; +case 3 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (70 ); +break ; +case 4 :case 5 :case 6 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (0 ); +break ; +default : +dev_err (dev,"invalid signal group %u\n" , value); +return -EINVAL ; + }...
Quoted 1 line
+
sfp->gc.of_node=dev->of_node;Isn't GPIO library do this for you?
...
Quoted 1 line
+ starfive_irq_chip.parent_device = dev;
Ditto?
...
drivers/pinctrl/pinctrl-starfive.c line 1398
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ sfp->gc.irq.parents = +devm_kcalloc (dev,1 ,sizeof (*sfp->gc.irq.parents),GFP_KERNEL );1 ->
sfp->gc.irq.num_parents
And hence move below line up.Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+if (!sfp->gc.irq.parents) +return -ENOMEM ; + sfp->gc.irq.num_parents =1 ;...
Quoted 1 line
+
dev_info(dev, "StarFive GPIO chip registered %d GPIOs\n", sfp->gc.ngpio);Redundant noise.
...
drivers/pinctrl/pinctrl-starfive.c line 1424
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+static const struct of_device_id starfive_of_match[] = { + { .compatible ="starfive,jh7100-pinctrl" }, + {/* sentinel */ },No comma needed for terminator entry.
Quoted 1 line
+};
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 9 lines
Quoted 8 lines
drivers/pinctrl/pinctrl-starfive.c line 597
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c new file +6
-0+free_pinmux: +devm_kfree (dev, pinmux); +free_pins: +devm_kfree (dev, pins); +free_grpname: +devm_kfree (dev, grpname);What the heck?!
Quoted 6 lines
Just to be clear. You mean we don't need to explicitly free them because they're tied to the device right? I don't think the device will go away just because a single device tree entry can't be parsed, so on such errors this garbage would be left behind. You can still argue we shouldn't optimize for broken device trees, I just want to make it at conscious decision.
If you are using devm_kfree() it is quite likely shows either of the following issues:
* you mustn't use devm_*() in the first place due to object lifetime;
* you shouldn't use devm_kfree() since this is the whole point of devm.
Quoted 4 lines
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c line 603
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+free_pgnames: +devm_kfree (dev, pgnames);Ditto.
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+out:
Useless label.
Hmm.. my compiler disagrees.
The comment implies that you return directly instead of using goto out;.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ return ret;
...
Quoted 15 lines
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 646
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ v = pinmux[i]; + dout = ((v &BIT (7 )) << (31 -7 )) | ((v >>24 ) &0xffU ); + doen = ((v &BIT (6 )) << (31 -6 )) | ((v >>16 ) &0xffU ); + din = (v >>8 ) &0xffU ;What is this voodoo for?
In order to do pinmux we need the following pieces of information from the device tree for each pin ("GPIO" they call it):
output signal: 0-133 + 1bit reverse flag
output enable signal: 0-133 + 1bit reverse flag optional input signal: 0-74 + special "none" value, right now0xffgpio number: 0-63
Quoted 7 lines
As the code is now all that info is packed into a u32 for each pin using the GPIOMUX macro defined in the dt-binding header added in patch 10. There is also a diagram for how this packing is done. The above voodoo is for unpacking that.
I'd very much like to hear if you have a better solution for how to convey that information from the device tree to here.
At very least this code should have something like above in the comment.
...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+if (din !=0xff ) + reg_din = sfp->base +GPIO_IN_OFFSET +4 * din; +else + reg_din =NULL ;
Quoted 7 lines
Quoted 1 line
This looks like you maybe use gpio-regmap instead?
This was discussed at length when Drew sent in the GPIO part of this code:
https://lore.kernel.org/linux-riscv/[email protected]/
The conclusion was that because pinmux and controlling the pins from software in GPIO mode uses the same registers it is better to do a combined driver like this that can share the lock among other things.
And what does prevent exactly to base the GPIO part on gpio-regmap?
...
Quoted 9 lines
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c line 727
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+static const unsigned char starfive_drive_strength[] = { +14 ,21 ,28 ,35 ,42 ,49 ,56 ,63 ,Why table? Can you simply use the formula?!
Heh, yeah. So these are rounded values from a table and I never noticed that after rounding they follow a nice arithmetic progression. It'll probably still be nice to have an explanation in the comments about the formula then.
Yup!
Quoted 1 line
Quoted 1 line
Quoted 1 line
+};
...
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+
irq_set_handler_locked(d, handle_bad_irq);Why is this here? Move it to ->probe().
My thinking was that if something tries to set a an unsupported irq type, we should make sure the caller doesn't get spurious interrupts because we left the handler at its old value.
You already assigned to this handler in the ->probe(), what's this then?
...
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+if (value <=6 ) +writel (value, sfp->padctl +IO_PADSHARE_SEL ); +else
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+
dev_err(dev, "invalid signal group %u\n", value);Why
_errif you not bail out here?My thinking was that if the device tree specifies an invalid signal group we should just leave the setting alone and not break booting, but still be loud about it. Maybe that's too lenient and it's better to crash and burn immediately if someone does that.
Here is inconsistency between level of the message and following action. There are (rare!) cases when it's justified, but I believe it's not the case here. You have two choices or justify why you have to use error level without stopping process.
...
All uncommented stuff you agreed on, correct?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Emil Renner Berthing
maintainerRe: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
Quoted 22 lines · Andy Shevchenko
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 9 lines
Quoted 8 lines
drivers/pinctrl/pinctrl-starfive.c line 597
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c new file +6
-0+free_pinmux: +devm_kfree (dev, pinmux); +free_pins: +devm_kfree (dev, pins); +free_grpname: +devm_kfree (dev, grpname);What the heck?!
Quoted 6 lines
Just to be clear. You mean we don't need to explicitly free them because they're tied to the device right? I don't think the device will go away just because a single device tree entry can't be parsed, so on such errors this garbage would be left behind. You can still argue we shouldn't optimize for broken device trees, I just want to make it at conscious decision.
Quoted 5 lines
If you are using
devm_kfree()it is quite likely shows either of the following issues:* you mustn't use devm_*() in the first place due to object lifetime;
* you shouldn't usedevm_kfree()since this is the whole point of devm.
Hmm.. it seems like other drivers that dynamically builds the groups and functions either also uses devm_kcalloc/devm_kfree like fx. pinctrl-single or implements their own code to clean up groups and functions when unloaded. There are no group destroy or function destroy callbacks. I like devm_kcalloc/devm_kfree version better since it's less code to write.
Quoted 39 lines
Quoted 4 lines
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c line 603
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+free_pgnames: +devm_kfree (dev, pgnames);Ditto.
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+out:
Useless label.
Hmm.. my compiler disagrees.
The comment implies that you return directly instead of using
goto out;.Quoted 1 line
Quoted 1 line
Quoted 1 line
+ return ret;
...
Quoted 20 lines
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 646
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ v = pinmux[i]; + dout = ((v &BIT (7 )) << (31 -7 )) | ((v >>24 ) &0xffU ); + doen = ((v &BIT (6 )) << (31 -6 )) | ((v >>16 ) &0xffU ); + din = (v >>8 ) &0xffU ;What is this voodoo for?
In order to do pinmux we need the following pieces of information from the device tree for each pin ("GPIO" they call it):
output signal: 0-133 + 1bit reverse flag
output enable signal: 0-133 + 1bit reverse flag optional input signal: 0-74 + special "none" value, right now0xffgpio number: 0-63As the code is now all that info is packed into a u32 for each pin using the GPIOMUX macro defined in the dt-binding header added in patch 10. There is also a diagram for how this packing is done. The above voodoo is for unpacking that.
Quoted 4 lines
Quoted 2 lines
I'd very much like to hear if you have a better solution for how to convey that information from the device tree to here.
At very least this code should have something like above in the comment.
Will add!
Quoted 9 lines
...
Quoted 7 lines
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 656
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+if (din !=0xff ) + reg_din = sfp->base +GPIO_IN_OFFSET +4 * din; +else + reg_din =NULL ;This looks like you maybe use gpio-regmap instead?
Quoted 7 lines
Quoted 5 lines
This was discussed at length when Drew sent in the GPIO part of this code:
https://lore.kernel.org/linux-riscv/[email protected]/
The conclusion was that because pinmux and controlling the pins from software in GPIO mode uses the same registers it is better to do a combined driver like this that can share the lock among other things.And what does prevent exactly to base the GPIO part on gpio-regmap?
Other reasons are that gpio-regmap doesn't implement the .set_config and .add_pin_ranges callbacks. add_pin_ranges is needed because the 64 GPIOs map to different pin numbers depending on the chosen "signal group".
Quoted 20 lines
...
Quoted 9 lines
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c line 727
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+static const unsigned char starfive_drive_strength[] = { +14 ,21 ,28 ,35 ,42 ,49 ,56 ,63 ,Why table? Can you simply use the formula?!
Heh, yeah. So these are rounded values from a table and I never noticed that after rounding they follow a nice arithmetic progression. It'll probably still be nice to have an explanation in the comments about the formula then.
Yup!
Quoted 1 line
Quoted 1 line
Quoted 1 line
+};
...
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
+
irq_set_handler_locked(d, handle_bad_irq);
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Why is this here? Move it to ->probe().
My thinking was that if something tries to set a an unsupported irq type, we should make sure the caller doesn't get spurious interrupts because we left the handler at its old value.
You already assigned to this handler in the ->probe(), what's this then?
But userspace could fx. first request IRQ_TYPE_EDGE_BOTH through the gpio api and later load a driver that might request an unsupported irq type right? Or am I missing something.
Quoted 15 lines
...
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+if (value <=6 ) +writel (value, sfp->padctl +IO_PADSHARE_SEL ); +else Quoted 8 lines
Quoted 3 lines
Quoted 1 line
+
dev_err(dev, "invalid signal group %u\n", value);Why
_errif you not bail out here?My thinking was that if the device tree specifies an invalid signal group we should just leave the setting alone and not break booting, but still be loud about it. Maybe that's too lenient and it's better to crash and burn immediately if someone does that.
Quoted 8 lines
Here is inconsistency between level of the message and following action. There are (rare!) cases when it's justified, but I believe it's not the case here. You have two choices or justify why you have to use error level without stopping process.
...
All uncommented stuff you agreed on, correct?
Yes, thank you! (.. or at least I'll get back to you if something comes up ;)
Quoted 11 lines
--
With Best Regards,
Andy Shevchenko_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Andy ShevchenkoQuoted 24 lines · Andy Shevchenko
Quoted 23 lines · Emil Renner Berthing
Quoted 8 lines · Andy Shevchenko
drivers/pinctrl/pinctrl-starfive.c line 646
Quoted 4 lines · Emil Renner Berthing
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ v = pinmux[i]; + dout = ((v &BIT (7 )) << (31 -7 )) | ((v >>24 ) &0xffU ); + doen = ((v &BIT (6 )) << (31 -6 )) | ((v >>16 ) &0xffU ); + din = (v >>8 ) &0xffU ;What is this voodoo for?
In order to do pinmux we need the following pieces of information from the device tree for each pin ("GPIO" they call it):
output signal: 0-133 + 1bit reverse flag
output enable signal: 0-133 + 1bit reverse flag optional input signal: 0-74 + special "none" value, right now0xffgpio number: 0-63As the code is now all that info is packed into a u32 for each pin using the GPIOMUX macro defined in the dt-binding header added in patch 10. There is also a diagram for how this packing is done. The above voodoo is for unpacking that.
Quoted 4 lines
Quoted 2 lines
I'd very much like to hear if you have a better solution for how to convey that information from the device tree to here.
At very least this code should have something like above in the comment.
And perhaps introduce some helper macros to access the fields?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Stephen Boyd
maintainerRe: [PATCH v1 04/16] dt-bindings: clock: starfive: Add JH7100 clock definitions
In reply to Emil Renner BerthingQuoting Emil Renner Berthing (2021-10-12 06:40:15)
Quoted 8 lines
From: Geert Uytterhoeven <[email protected]>
Add all clock outputs for the StarFive JH7100 clock generator.
Based on work by Ahmad Fatoum for Barebox, with "
JH7100_" prefixes added to all definitions.Signed-off-by Geert Uytterhoeven <[email protected]>
You need to add your Signed-off-by here.
kernel test robot
build botRe: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Emil Renner BerthingI love your patch! Perhaps something to improve:
Hi Emil,
I love your patch! Perhaps something to improve:
[auto build test WARNING on robh/for-next]
[also build test WARNING on clk/clk-next pza/reset/next linus/master v5.15-rc5 next-20211013] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Emil-Renner-Berthing/Basic-StarFive-JH7100-RISC-V-SoC-support/20211012-220348 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: microblaze-randconfig-r033-20211013 (attached as .config) compiler: microblaze-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/39e70136443b16615b0b83a448d6c5106d68cef7
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Emil-Renner-Berthing/Basic-StarFive-JH7100-RISC-V-SoC-support/20211012-220348 git checkout 39e70136443b16615b0b83a448d6c5106d68cef7
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=microblaze SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux.o(.data+0x8a2c8): Section mismatch in reference from the variable starfive_pinctrl_driver to the function .init.text:starfive_probe()
The variable starfive_pinctrl_driver references
the function __init starfive_probe()
If the reference is valid then annotate the
variable with or __refdata (see linux/init.h) or name the variable:
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 3 lines · Emil Renner Berthing
dt-bindings: pinctrl: Add StarFive pinctrl definitions
dt-bindings: pinctrl: Add StarFive JH7100 bindings
pinctrl: starfive: Add pinctrl driver for StarFive SoCs
I'd be happy to apply these to the pinctrl tree if everybody is happy.
If you prefer some other merge path:
Yours,
Linus Walleij
Emil Renner Berthing
maintainerQuoted 10 lines · Linus Walleij
Quoted 3 lines · Emil Renner Berthing
dt-bindings: pinctrl: Add StarFive pinctrl definitions
dt-bindings: pinctrl: Add StarFive JH7100 bindings
pinctrl: starfive: Add pinctrl driver for StarFive SoCsI'd be happy to apply these to the pinctrl tree if everybody is happy.
If you prefer some other merge path:Acked-by Linus Walleij <[email protected]>
Thank you, that sounds great to me. Let me post v2 to address Andy and Geerts comments though.
/Emil
Emil Renner Berthing
maintainerRe: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Andy ShevchenkoQuoted 355 lines · Andy Shevchenko
Quoted 10 lines · Emil Renner Berthing
Add a combined pinctrl and gpio driver for the StarFive JH7100 SoC.
For each "GPIO" there are two registers for configuring the output and output enable signals which may come from other peripherals. Among these are two special signals that are constant 0 and constant 1 respectively. Controlling the GPIOs from software is done by choosing one of these signals. In other words the same registers are used for both pinmuxing and controlling the GPIOs, which makes it easier to combine the pinctrl and gpio driver in one.
Quoted 3 lines
I wrote the pinconf and pinmux parts, but the gpio part of the code is based on the gpio driver in the vendor tree written by Huan Feng with cleanups and fixes by Drew and me.
s/gpio/GPIO/g
...
drivers/pinctrl/Kconfig config PINCTRL_ST · line 269
Quoted 3 lines
drivers/pinctrl/Kconfig +2
-0+config PINCTRL_STARFIVE + bool "Pinctrl and GPIO driver for the StarFive JH7100 SoC"Why not module?
drivers/pinctrl/Kconfig config PINCTRL_ST · line 271
Quoted 3 lines
drivers/pinctrl/Kconfig +2
-0+ depends on SOC_STARFIVE || COMPILE_TEST + depends on OFDo you really need this taking into account...
drivers/pinctrl/Kconfig config PINCTRL_ST · line 278
Quoted 8 lines
drivers/pinctrl/Kconfig +7
-0+ default SOC_STARFIVE + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF + select GPIOLIB + select GPIOLIB_IRQCHIP + select OF_GPIO...this one?
...
bits.h?drivers/pinctrl/pinctrl-starfive.c line 12
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+#include <linux/clk.h> +#include <linux/gpio/driver.h> +#include <linux/io.h> +#include <linux/module.h>
mod_devicetable.h?drivers/pinctrl/pinctrl-starfive.c line 15
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+#include <linux/pinctrl/pinctrl.h> +#include <linux/pinctrl/pinmux.h> Can you move these as a group after generic linux/* ones?
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#include <linux/platform_device.h> +#include <linux/reset.h> +#include <linux/spinlock.h> ...
Quoted 2 lines
+/*
+ * refer to Section 12. GPIO Registers in JH7100 datasheet:Be consistent in your style, here for example missed capitalization.
Quoted 1 line
Is it possible to have the datasheet to be provided as Datasheet: tag in the commit message?
Quoted 1 line
+ */
...
drivers/pinctrl/pinctrl-starfive.c line 39
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+/* +* Global enable for GPIO interrupts, offset: 0x0, field: GPIOEN +* set to 1 if GPIO interrupts are enabled, set to 0 to disable +*/ +#define IRQ_GLOBAL_EN 0x0s/0x0/0x00/g
...
drivers/pinctrl/pinctrl-starfive.c line 50
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+/* +* Interrupt Type for GPIO[31:0], offset: 0x10, field: GPIOS_0 +* set to 1 if edge-triggered, set to 0 for level-triggered +*/ +#define IRQ_TYPE_LOW 0x10 + +/* +* Interrupt Type for GPIO[63:32], offset: 0x14, field: GPIOS_1 +*/ +#define IRQ_TYPE_HIGH 0x14As I reviewed below, the IRQ is represented by a few registers in a row, no need to define low and high separately. Ditto for the rest register pairs.
...
Quoted 4 lines
+/*
+ * Interrupt Status after Masking GPIO[31:0], offset:0x40, field:GPIOMIS_0
+ * status of edge-triggered or level-triggered after masking
+ * value of 1 means edge or level was detected, value of 0 menas not detectedmenas?!
Quoted 1 line
+ */
...
Quoted 2 lines
+/*
+ * Data Value of GPIO for GPIO[31:0], offest:0x48, field:GPIODIN_0offest?!
Quoted 2 lines
+ * dynamically reflects value on the GPIO pin
+ */Please, run a spellchecker.
...
Quoted 1 line
+#define
IO_PADSHARE_SEL0x1a0Okay, make all registers to be fixed width, i.e.
0x000for IRQ global enabling and so on....
Quoted 1 line
+#define
PAD_SLEW_RATE_MASK0xe00U
GENMASK()drivers/pinctrl/pinctrl-starfive.c line 168
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+#define PAD_BIAS_STRONG_PULL_UP 0x100U +#define PAD_INPUT_ENABLE 0x080U +#define PAD_INPUT_SCHMITT_ENABLE 0x040U +#define PAD_BIAS_DISABLE 0x020U +#define PAD_BIAS_PULL_DOWN 0x010UAll above seems like
BIT(_something_).drivers/pinctrl/pinctrl-starfive.c line 170
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+#define PAD_BIAS_MASK 0x130U +#define PAD_DRIVE_STRENGTH_MASK 0x007U
GENMASK()...
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FS
__maybe_unused?Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#else +#define starfive_pin_dbg_show NULL +#endif ...
Quoted 1 line
+ dout =
readl_relaxed(reg);
readl_relaxed(reg + 0x00)drivers/pinctrl/pinctrl-starfive.c line 439
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ reg +=4 ; + doen =readl_relaxed (reg);
readl_relaxed(reg + 0x04);...
drivers/pinctrl/pinctrl-starfive.c line 443
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+seq_printf (s,"dout=%u%s doen=%u%s" , + dout &0xffU , (dout &0x80000000U ) ?"r" :"" , + doen &0xffU , (doen &0x80000000U ) ?"r" :"" );
GENMASK()BIT()...
Quoted 17 lines
drivers/pinctrl/pinctrl-starfive.c new file +17
-0+for_each_child_of_node (np, child) { +const __be32 *pinmux_list; +const __be32 *pins_list; +int pinmux_size; +int pins_size; + + pinmux_list =of_get_property (child,"pinmux" , &pinmux_size); + pins_list =of_get_property (child,"pins" , &pins_size); +if (pinmux_list && pins_list) { +dev_err (dev,"invalid pinctrl group %pOFn.%pOFn: %s\n" , + np, child,"both pinmux and pins set" ); +of_node_put (child); +return -EINVAL ; + } + +if (pinmux_list && pinmux_size >0 ) { + nmaps +=2 ;drivers/pinctrl/pinctrl-starfive.c line 494
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+ }else if (pins_list && pins_size >0 ) { + nmaps +=1 ; + }else { +dev_err (dev,"invalid pinctrl group %pOFn.%pOFn: %s\n" , + np, child,"neither pinmux nor pins set" ); +of_node_put (child); +return -EINVAL ; + } + ngroups +=1 ; + }This entire loop seems like
1) it should be based on something from pin control core;
2) it's using some low level APIs instead of better ones likeof_property_read_uXX();
3) smells like unoptimized NIH....
Quoted 1 line
+ if ((list =
of_get_property(child, "pinmux", &npins))) {Why not of_property_read_...() ?
...
Quoted 1 line
+ u32 v =
be32_to_cpu(*list++);My gosh!
...
drivers/pinctrl/pinctrl-starfive.c line 551
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+for (i =0 ; i < npins; i++) + pins[i] =be32_to_cpu (*list++);Ditto.
Even for this we have something in byteorder headers.Summary, make sure you use much better _existing_ APIs instead of the above crap.
...
drivers/pinctrl/pinctrl-starfive.c line 597
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c new file +6
-0+free_pinmux: +devm_kfree (dev, pinmux); +free_pins: +devm_kfree (dev, pins); +free_grpname: +devm_kfree (dev, grpname);What the heck?!
drivers/pinctrl/pinctrl-starfive.c line 603
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+free_pgnames: +devm_kfree (dev, pgnames);Ditto.
...
Quoted 1 line
+out:
Useless label.
Quoted 1 line
+ return ret;
...
drivers/pinctrl/pinctrl-starfive.c line 639
Quoted 9 lines
drivers/pinctrl/pinctrl-starfive.c new file +8
-0+for (i =0 ; i < group->num_pins; i++) { +unsigned int gpio =starfive_pin_to_gpio (sfp, group->pins[i]); +void __iomem *reg_dout; +void __iomem *reg_doen; +void __iomem *reg_din; +u32 v, dout, doen, din; +unsigned long flags; + if (dev_WARN_ONCE(dev, gpio >= MAX_GPIO,What?!
drivers/pinctrl/pinctrl-starfive.c line 646
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c new file +7
-0+ "%s: invalid gpiomux pin", group->name)) +continue ; + + v = pinmux[i]; + dout = ((v &BIT (7 )) << (31 -7 )) | ((v >>24 ) &0xffU ); + doen = ((v &BIT (6 )) << (31 -6 )) | ((v >>16 ) &0xffU ); + din = (v >>8 ) &0xffU ;What is this voodoo for?
drivers/pinctrl/pinctrl-starfive.c line 656
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+if (din !=0xff ) + reg_din = sfp->base +GPIO_IN_OFFSET +4 * din; +else + reg_din =NULL ;This looks like you maybe use gpio-regmap instead?
...
drivers/pinctrl/pinctrl-starfive.c line 685
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c new file +6
-0+void __iomem *reg = sfp->padctl +4 * (pin /2 ); +u32 value =readl_relaxed (reg); + +if (pin &1U ) + value >>=16 ; +return value;u8 shift = 16 * (pin % 2);
return
readl_relaxed()>> shift;?
Something similar for below code.
...
drivers/pinctrl/pinctrl-starfive.c line 719
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#ifdef CONFIG_DEBUG_FS +static const struct pin_config_item +starfive_pinconf_custom_conf_items[ARRAY_SIZE(starfive_pinconf_custom_params)] = {Instead of using
ARAY_SIZE()here, usestatic_assert().
__maybe_unused?Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +5
-0+ PCONFDUMP(PIN_CONFIG_STARFIVE_STRONG_PULL_UP, "input bias strong pull-up", NULL, false), +}; +#else +#define starfive_pinconf_custom_conf_items NULL +#endif ...
drivers/pinctrl/pinctrl-starfive.c line 727
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+static const unsigned char starfive_drive_strength[] = { +14 ,21 ,28 ,35 ,42 ,49 ,56 ,63 ,Why table? Can you simply use the formula?!
Quoted 1 line
+};
...
Quoted 1 line
+ if (unlikely(!group))
Why
unlikely()Must be justified here and everywhere where you are using it.Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+return -EINVAL ; + +return starfive_pinconf_get (pctldev, group->pins[0 ], config); +}...
Quoted 1 line
+ case
PIN_CONFIG_BIAS_DISABLE:
Quoted 7 lines
Quoted 1 line
+ mask |=
PAD_BIAS_MASK;Use it...
Quoted 1 line
+ value = (value & ~PAD_BIAS_MASK) |
PAD_BIAS_DISABLE;...here. Ditto for the similar cases in this function and elsewhere.
I don't follow. How do you want me to use mask? If I did value = (value & ~mask) | PAD_BIAS_DISABLE; then I'd wipe the previous configuration. Eg. suppose the first config is the drive strength and second disables bias. Then on the 2nd loop mask = PAD_DRIVE_STRENGTH_MASK | PAD_BIAS_MASK and the drive strength value would be wiped.
Quoted 129 lines
After done this, you will see how you can simplify and deduplicate the switch-cases.
...
Quoted 1 line
+#ifdef
CONFIG_DEBUG_FS
__maybe_unused?Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+#else +#define starfive_pinconf_dbg_show NULL +#endif ...
drivers/pinctrl/pinctrl-starfive.c line 986
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+if (gpio <32 ) { + value =readl_relaxed (sfp->base +GPIO_DIN_LOW ); + value = (value >> gpio) &1U ;Drop
drivers/pinctrl/pinctrl-starfive.c line 989
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ }else { + value =readl_relaxed (sfp->base +GPIO_DIN_HIGH ); + value = (value >> (gpio -32 )) &1U ;Drop
drivers/pinctrl/pinctrl-starfive.c line 685
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ } +return value;return !!(value & BIT(gpio % 32));
...
drivers/pinctrl/pinctrl-starfive.c line 820
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+if (arg ==0 ) +return -ENOTSUPP ;Shouldn't we return something else and pin control core will change it to something else if needed?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (arg == 0) + return -ENOTSUPP;Ditto.
Quoted 2 lines
(quoted diff) +2
-0+ default: + return -ENOTSUPP;...
drivers/pinctrl/pinctrl-starfive.c line 1109
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+if (gpio <0 || gpio >=MAX_GPIO ) +return ; + +if (gpio <32 ) { + ie = sfp->base +IRQ_ENABLE_LOW ; + mask =BIT (gpio); + }else { + ie = sfp->base +IRQ_ENABLE_HIGH ; + mask =BIT (gpio -32 ); + }See below. And update all occurrences of these lines accordingly and everywhere. Also for IRQ may use helper functions if needed (but I don't believe the high and low register have stride more than 4).
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (gpio < 0 || gpio >= MAX_GPIO) + return -EINVAL;How is it possible to be ever triggered?
...
drivers/pinctrl/pinctrl-starfive.c line 1191
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c new file +7
-0+if (gpio <32 ) { + base = sfp->base; + mask =BIT (gpio); + }else { + base = sfp->base +4 ; + mask =BIT (gpio -32 ); + }base =
sfp_base+ 4 * (gpio / 32);
mask = BIT(gpio % 32);...
drivers/pinctrl/pinctrl-starfive.c line 1201
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+irq_set_handler_locked (d, handle_edge_irq); +irq_set_handler_locked (d, handle_edge_irq);Dup.
...
drivers/pinctrl/pinctrl-starfive.c line 1219
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+irq_set_handler_locked (d, handle_edge_irq); +irq_set_handler_locked (d, handle_level_irq); +irq_set_handler_locked (d, handle_level_irq);Ditto.
...
Quoted 1 line
+
irq_set_handler_locked(d, handle_bad_irq);Why is this here? Move it to ->probe().
...
drivers/pinctrl/pinctrl-starfive.c line 1308
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ clk =devm_clk_get (dev,NULL ); +if (IS_ERR (clk)) { + ret =PTR_ERR (clk); +dev_err (dev,"could not get clock: %d\n" , ret);Thank you for spamming logs with this noise.
Quoted 1 line
+ return ret;
Hint: return
dev_err_probe(). Ditto for the rest in this function.Quoted 1 line
+ }
Quoted 8 lines
...
drivers/pinctrl/pinctrl-starfive.c line 1327
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) { +reset_control_deassert (rst);Use
devm_add_action_or_reset().
I don't see how that is better. Then I'd first need to call that and check for errors, but just on the line below enabling the clock the reset line is deasserted anyway, so then the action isn't needed any longer. So that 3 lines of code for devm_add_action_or_reset + lingering unneeded action or code to remove it again vs. just the line above.
Quoted 48 lines
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+dev_err (dev,"could not enable clock: %d\n" , ret); +return ret; + }...
Quoted 1 line
+ if (!of_property_read_u32(dev->of_node, "starfive,signal-group", &value)) {
Can be refactored without conditional. Also, why not to use
device_property_read_u32()?drivers/pinctrl/pinctrl-starfive.c line 1352
Quoted 5 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+if (value <=6 ) +writel (value, sfp->padctl +IO_PADSHARE_SEL ); +else +dev_err (dev,"invalid signal group %u\n" , value);Why
_errif you not bail out here?Quoted 1 line
+ }
...
drivers/pinctrl/pinctrl-starfive.c line 1358
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +4
-0+ value =readl (sfp->padctl +IO_PADSHARE_SEL ); +switch (value) { +case 0 : + sfp->gpios.pin_base =0x10000 ;Magic number!
Quoted 7 lines
drivers/pinctrl/pinctrl-starfive.c new file +7
-0+ goto done; +case 1 : + sfp->gpios.pin_base =PAD_GPIO (0 ); +break ; +case 2 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (72 ); +break ;drivers/pinctrl/pinctrl-starfive.c line 1375
Quoted 10 lines
drivers/pinctrl/pinctrl-starfive.c new file +10
-0+case 3 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (70 ); +break ; +case 4 :case 5 :case 6 : + sfp->gpios.pin_base =PAD_FUNC_SHARE (0 ); +break ; +default : +dev_err (dev,"invalid signal group %u\n" , value); +return -EINVAL ; + }
Quoted 5 lines
...
Quoted 1 line
+
sfp->gc.of_node=dev->of_node;Isn't GPIO library do this for you?
If it does I can't find it.
Quoted 40 lines
...
Quoted 1 line
+ starfive_irq_chip.parent_device = dev;
Ditto?
...
drivers/pinctrl/pinctrl-starfive.c line 1398
Quoted 2 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+ sfp->gc.irq.parents = +devm_kcalloc (dev,1 ,sizeof (*sfp->gc.irq.parents),GFP_KERNEL );1 ->
sfp->gc.irq.num_parents
And hence move below line up.Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+if (!sfp->gc.irq.parents) +return -ENOMEM ; + sfp->gc.irq.num_parents =1 ;...
Quoted 1 line
+
dev_info(dev, "StarFive GPIO chip registered %d GPIOs\n", sfp->gc.ngpio);Redundant noise.
...
drivers/pinctrl/pinctrl-starfive.c line 1424
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+static const struct of_device_id starfive_of_match[] = { + { .compatible ="starfive,jh7100-pinctrl" }, + {/* sentinel */ },No comma needed for terminator entry.
Quoted 1 line
+};
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
When answering, cut down your message to the point, please! It's a bit annoying to remove overquoting...
...
Quoted 8 lines
Quoted 8 lines
drivers/pinctrl/pinctrl-starfive.c line 815
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+case PIN_CONFIG_BIAS_DISABLE : + mask |=PAD_BIAS_MASK ;Use it...
Quoted 1 line
+ value = (value & ~PAD_BIAS_MASK) |
PAD_BIAS_DISABLE;
Quoted 8 lines
Quoted 1 line
...here. Ditto for the similar cases in this function and elsewhere.
I don't follow. How do you want me to use mask? If I did value = (value & ~mask) |
PAD_BIAS_DISABLE; then I'd wipe the previous configuration. Eg. suppose the first config is the drive strength and second disables bias. Then on the 2nd loop mask =PAD_DRIVE_STRENGTH_MASK|PAD_BIAS_MASKand the drive strength value would be wiped.
Collect masks and new values in temporary variables and apply them once after the loop is done, no?
...
Quoted 8 lines
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 1327
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) { +reset_control_deassert (rst);Use
devm_add_action_or_reset().I don't see how that is better.
Pity. The rule of thumb is to either try to use devm_*() everywhere in the probe, or don't use it at all. Above is the more-or-less standard pattern where devn_add_action_or_reset() is being used in the entire kernel.
Quoted 6 lines
Then I'd first need to call that and
check for errors, but just on the line below enabling the clock the reset line is deasserted anyway, so then the action isn't needed any longer. So that 3 lines of code fordevm_add_action_or_reset+ lingering unneeded action or code to remove it again vs. just the line above.
Then don't use devm_*() at all. What's the point?
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+
sfp->gc.of_node=dev->of_node;Isn't GPIO library do this for you?
If it does I can't find it.
Heh... man git grep
Hint: git grep -n 'of_node = .*of_node' -- drivers/gpio/gpiolib*
Signature · 2 lines
With Best Regards, Andy Shevchenko
Emil Renner Berthing
maintainerRe: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
Quoted 26 lines · Andy Shevchenko
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
When answering, cut down your message to the point, please! It's a bit annoying to remove overquoting...
...
Quoted 8 lines
Quoted 8 lines
drivers/pinctrl/pinctrl-starfive.c line 815
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+case PIN_CONFIG_BIAS_DISABLE : + mask |=PAD_BIAS_MASK ;Use it...
Quoted 1 line
+ value = (value & ~PAD_BIAS_MASK) |
PAD_BIAS_DISABLE;Quoted 8 lines
Quoted 1 line
...here. Ditto for the similar cases in this function and elsewhere.
I don't follow. How do you want me to use mask? If I did value = (value & ~mask) |
PAD_BIAS_DISABLE; then I'd wipe the previous configuration. Eg. suppose the first config is the drive strength and second disables bias. Then on the 2nd loop mask =PAD_DRIVE_STRENGTH_MASK|PAD_BIAS_MASKand the drive strength value would be wiped.
Quoted 2 lines
Collect masks and new values in temporary variables and apply them once after the loop is done, no?
But that's exactly what the code does. It merges all the config options into a single mask and value so we only need to do rmw on the register once.
Quoted 16 lines
...
Quoted 8 lines
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 1327
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) { +reset_control_deassert (rst);Use
devm_add_action_or_reset().I don't see how that is better.
Pity. The rule of thumb is to either try to use devm_*() everywhere in the probe, or don't use it at all. Above is the more-or-less standard pattern where
devn_add_action_or_reset()is being used in the entire kernel.
Quoted 8 lines
Quoted 6 lines
Then I'd first need to call that and
check for errors, but just on the line below enabling the clock the reset line is deasserted anyway, so then the action isn't needed any longer. So that 3 lines of code fordevm_add_action_or_reset+ lingering unneeded action or code to remove it again vs. just the line above.Then don't use devm_*() at all. What's the point?
I'm confused. So you wan't an unneeded action to linger because the probe function temporarily asserts reset for 3 lines of code?
Quoted 10 lines
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+
sfp->gc.of_node=dev->of_node;Isn't GPIO library do this for you?
If it does I can't find it.
Heh...
man git grep
Hint:git grep -n 'of_node = .*of_node' -- drivers/gpio/gpiolib*
That's exactly what I did.
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko
Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
Quoted 4 lines · Emil Renner Berthing
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 9 lines
drivers/pinctrl/pinctrl-starfive.c line 815
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+case PIN_CONFIG_BIAS_DISABLE : + mask |=PAD_BIAS_MASK ;Use it...
Quoted 1 line
+ value = (value & ~PAD_BIAS_MASK) |
PAD_BIAS_DISABLE;...here. Ditto for the similar cases in this function and elsewhere.
I don't follow. How do you want me to use mask? If I did value = (value & ~mask) |
PAD_BIAS_DISABLE; then I'd wipe the previous configuration. Eg. suppose the first config is the drive strength and second disables bias. Then on the 2nd loop mask =PAD_DRIVE_STRENGTH_MASK|PAD_BIAS_MASKand the drive strength value would be wiped.
Quoted 6 lines
Quoted 2 lines
Collect masks and new values in temporary variables and apply them once after the loop is done, no?
But that's exactly what the code does. It merges all the config options into a single mask and value so we only need to do rmw on the register once.
Then masking the value makes no sense.
What you should have is simply as
mask |= FOO; value |= BAR;
...
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 1327
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) { +reset_control_deassert (rst);Use
devm_add_action_or_reset().I don't see how that is better.
Pity. The rule of thumb is to either try to use devm_*() everywhere in the probe, or don't use it at all. Above is the more-or-less standard pattern where
devn_add_action_or_reset()is being used in the entire kernel.Quoted 6 lines
Then I'd first need to call that and
check for errors, but just on the line below enabling the clock the reset line is deasserted anyway, so then the action isn't needed any longer. So that 3 lines of code fordevm_add_action_or_reset+ lingering unneeded action or code to remove it again vs. just the line above.
Quoted 4 lines
Quoted 1 line
Then don't use devm_*() at all. What's the point?
I'm confused. So you wan't an unneeded action to linger because the probe function temporarily asserts reset for 3 lines of code?
I;m talking about clk_prepare_enable().
...
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+
sfp->gc.of_node=dev->of_node;Isn't GPIO library do this for you?
If it does I can't find it.
Heh...
man git grep
Hint:git grep -n 'of_node = .*of_node' -- drivers/gpio/gpiolib*That's exactly what I did.
Now look at the result and find the correct place where it's done. Btw, all hits are in the very same function.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Emil Renner Berthing
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 1327
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) { +reset_control_deassert (rst);Use
devm_add_action_or_reset().I don't see how that is better.
Pity. The rule of thumb is to either try to use devm_*() everywhere in the probe, or don't use it at all. Above is the more-or-less standard pattern where
devn_add_action_or_reset()is being used in the entire kernel.Quoted 6 lines
Then I'd first need to call that and
check for errors, but just on the line below enabling the clock the reset line is deasserted anyway, so then the action isn't needed any longer. So that 3 lines of code fordevm_add_action_or_reset+ lingering unneeded action or code to remove it again vs. just the line above.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Then don't use devm_*() at all. What's the point?
I'm confused. So you wan't an unneeded action to linger because the probe function temporarily asserts reset for 3 lines of code?
I;m talking about
clk_prepare_enable().
Having a second look I found even problematic error paths because of mixing devm_*() with non-devm_*() calls, which only assures me that your ->probe() error path is broken and should be revisited.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Emil Renner Berthing
maintainerRe: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Andy ShevchenkoQuoted 32 lines · Andy Shevchenko
Quoted 4 lines · Emil Renner Berthing
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 9 lines
drivers/pinctrl/pinctrl-starfive.c line 815
Quoted 3 lines
drivers/pinctrl/pinctrl-starfive.c new file +2
-0+case PIN_CONFIG_BIAS_DISABLE : + mask |=PAD_BIAS_MASK ;Use it...
Quoted 1 line
+ value = (value & ~PAD_BIAS_MASK) |
PAD_BIAS_DISABLE;...here. Ditto for the similar cases in this function and elsewhere.
I don't follow. How do you want me to use mask? If I did value = (value & ~mask) |
PAD_BIAS_DISABLE; then I'd wipe the previous configuration. Eg. suppose the first config is the drive strength and second disables bias. Then on the 2nd loop mask =PAD_DRIVE_STRENGTH_MASK|PAD_BIAS_MASKand the drive strength value would be wiped.Quoted 6 lines
Quoted 2 lines
Collect masks and new values in temporary variables and apply them once after the loop is done, no?
But that's exactly what the code does. It merges all the config options into a single mask and value so we only need to do rmw on the register once.
Quoted 5 lines
Then masking the value makes no sense.
What you should have is simply asmask |= FOO; value |= BAR;
Yeah, but then we could get into weird states if the device tree specifies both bias-disable and bias-pull-up by mistake. This code is written so that only the last valid state is chosen.
Quoted 23 lines
...
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
Quoted 6 lines
drivers/pinctrl/pinctrl-starfive.c line 1327
Quoted 4 lines
drivers/pinctrl/pinctrl-starfive.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) { +reset_control_deassert (rst);Use
devm_add_action_or_reset().I don't see how that is better.
Pity. The rule of thumb is to either try to use devm_*() everywhere in the probe, or don't use it at all. Above is the more-or-less standard pattern where
devn_add_action_or_reset()is being used in the entire kernel.Quoted 6 lines
Then I'd first need to call that and
check for errors, but just on the line below enabling the clock the reset line is deasserted anyway, so then the action isn't needed any longer. So that 3 lines of code fordevm_add_action_or_reset+ lingering unneeded action or code to remove it again vs. just the line above.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Then don't use devm_*() at all. What's the point?
I'm confused. So you wan't an unneeded action to linger because the probe function temporarily asserts reset for 3 lines of code?
I;m talking about
clk_prepare_enable().
Ok, you wrote your comment under the reset_control_deassert call. How would devm_add_action_or_reset for clk_prepare_enable work?
Quoted 19 lines
...
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+
sfp->gc.of_node=dev->of_node;Isn't GPIO library do this for you?
If it does I can't find it.
Heh...
man git grep
Hint:git grep -n 'of_node = .*of_node' -- drivers/gpio/gpiolib*That's exactly what I did.
Now look at the result and find the correct place where it's done. Btw, all hits are in the very same function.
--
With Best Regards,
Andy Shevchenko
Emil Renner Berthing
maintainerRe: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Andy ShevchenkoQuoted 33 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Emil Renner Berthing
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 8 lines
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ ret = clk_prepare_enable(clk); + if (ret) { + reset_control_deassert(rst);Use
devm_add_action_or_reset().I don't see how that is better.
Pity. The rule of thumb is to either try to use devm_*() everywhere in the probe, or don't use it at all. Above is the more-or-less standard pattern where
devn_add_action_or_reset()is being used in the entire kernel.Quoted 6 lines
Then I'd first need to call that and
check for errors, but just on the line below enabling the clock the reset line is deasserted anyway, so then the action isn't needed any longer. So that 3 lines of code fordevm_add_action_or_reset+ lingering unneeded action or code to remove it again vs. just the line above.Then don't use devm_*() at all. What's the point?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I'm confused. So you wan't an unneeded action to linger because the probe function temporarily asserts reset for 3 lines of code?
I;m talking about
clk_prepare_enable().Having a second look I found even problematic error paths because of mixing devm_*() with non-devm_*() calls, which only assures me that your ->probe() error path is broken and should be revisited.
So do you want to expand on that now or should I send v2 first?
Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Emil Renner BerthingQuoted 6 lines · Emil Renner Berthing
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Emil Renner Berthing
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Emil Renner Berthing
Quoted 1 line · Andy Shevchenko
On Tue, Oct 12, 2021 at 4:43 PM Emil Renner Berthing <[email protected]> wrote:
...
Quoted 27 lines
Quoted 27 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ case PIN_CONFIG_BIAS_DISABLE: + mask |= PAD_BIAS_MASK;Use it...
Quoted 1 line
+ value = (value & ~PAD_BIAS_MASK) |
PAD_BIAS_DISABLE;...here. Ditto for the similar cases in this function and elsewhere.
I don't follow. How do you want me to use mask? If I did value = (value & ~mask) |
PAD_BIAS_DISABLE; then I'd wipe the previous configuration. Eg. suppose the first config is the drive strength and second disables bias. Then on the 2nd loop mask =PAD_DRIVE_STRENGTH_MASK|PAD_BIAS_MASKand the drive strength value would be wiped.Quoted 6 lines
Quoted 2 lines
Collect masks and new values in temporary variables and apply them once after the loop is done, no?
But that's exactly what the code does. It merges all the config options into a single mask and value so we only need to do rmw on the register once.
Then masking the value makes no sense.
What you should have is simply as
Quoted 6 lines
Quoted 2 lines
mask |= FOO; value |= BAR;Yeah, but then we could get into weird states if the device tree specifies both bias-disable and bias-pull-up by mistake. This code is written so that only the last valid state is chosen.
But shouldn't it be disallowed by:
1) DTC validator (Rob?)
2) GPIO / pin control (Linus, Bart?)
?
...
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 8 lines
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ ret = clk_prepare_enable(clk); + if (ret) { + reset_control_deassert(rst);Use
devm_add_action_or_reset().I don't see how that is better.
Pity. The rule of thumb is to either try to use devm_*() everywhere in the probe, or don't use it at all. Above is the more-or-less standard pattern where
devn_add_action_or_reset()is being used in the entire kernel.Quoted 6 lines
Then I'd first need to call that and
check for errors, but just on the line below enabling the clock the reset line is deasserted anyway, so then the action isn't needed any longer. So that 3 lines of code fordevm_add_action_or_reset+ lingering unneeded action or code to remove it again vs. just the line above.Then don't use devm_*() at all. What's the point?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I'm confused. So you wan't an unneeded action to linger because the probe function temporarily asserts reset for 3 lines of code?
I;m talking about
clk_prepare_enable().Ok, you wrote your comment under the
reset_control_deassertcall. How woulddevm_add_action_or_resetforclk_prepare_enablework?
It seems both are needed to be converted, otherwise _everything_ after reset_assert() should not be devm_*().
TL;DR: the rule is
Allowed: devm_*() followed by non-devm_*()
NOT allowed: devm_*() followed by non-devm_*() followed by devm_*()
Of course, you may try to work the latter one, but it diminishes the whole idea behind it, that's why I told that may be not using devm_*() is the correct approach here and that what you meant (?).
The example how to use above mentioned API, just grep for it.
# See [1] for the sources of the used script
$ gl4func.sh devm_add_action_or_reset clk_prepare_enable | wc -l 101
[1]: https://github.com/andy-shev/home-bin-tools/blob/master/gl4func.sh
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs
In reply to Emil Renner BerthingQuoted 3 lines · Emil Renner Berthing
Quoted 2 lines · Andy Shevchenko
On Mon, Oct 18, 2021 at 7:23 PM Andy Shevchenko
<[email protected]> wrote:
...
Quoted 5 lines
Quoted 3 lines
Having a second look I found even problematic error paths because of mixing devm_*() with non-devm_*() calls, which only assures me that your ->probe() error path is broken and should be revisited.
So do you want to expand on that now or should I send v2 first?
Here is not enough context anymore to point out. I expect one to have done their homework anyway.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 02/16] dt-bindings: timer: Add StarFive JH7100 clint
In reply to Emil Renner BerthingQuoted 7 lines · Emil Renner Berthing
Add compatible string for the StarFive JH7100 clint.
Signed-off-by Emil Renner Berthing <[email protected]>--- Documentation/devicetree/bindings/timer/sifive,clint.yaml | 1 + 1 file changed, 1 insertion(+)