Skip to contentSkip to conversation

MIPS: ralink: add CPU clock detection and clock gate driver for MT7621

PATCH Superseded Sergio Paracuellos 3 participants 16 messages Nov 11, 2020 – Nov 17, 2020

Subsystems (7)

v1 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Sergio Paracuellos

author maintainer
#0 lore raw

cover MIPS: ralink: add CPU clock detection and clock gate driver for MT7621

This patchset ports CPU clock detection for MT7621 from OpenWrt and adds a complete clock plan for the mt7621 SOC.

The documentation for this SOC only talks about two registers regarding to the clocks:
* SYSC_REG_CPLL_CLKCFG0 - provides some information about boostrapped refclock. PLL and dividers used for CPU and some sort of BUS (AHB?).
* SYSC_REG_CPLL_CLKCFG1 - a banch of gates to enable/disable clocks for all or some ip cores.

No documentation about a probably existant set of dividers for each ip core is included in the datasheets. So we cannot make anything better, AFAICT.

Looking into driver code, there is another frequency which is used in some drivers (uart, sd...) which for any reason is always hardcoded to 50 MHz. Taking this into account this patchset provides three main fixed clocks to the SOC in 'mt7621-pll' which are:
- "cpu": with detected frequency (900 MHz in my board).
- "ahb": cpu / 4 = 225 Mhz.
- "apb": 50 Mhz.

PLL controller cannot be manipulatedbecause there is no info about how to do it. Because of this, there is nothing related with registers in the included binding.

It also provides a clock gate driver 'mt7621-clk' as a platform driver to allow to enable and disable some clocks in the different ip cores. The parent clocks for this clock gates have also set taking into account existant device tree and driver code resulting in the followings:
- "hsdma": "ahb"
- "fe": "ahb"
- "sp_divtx": "ahb"
- "timer": "cpu"
- "int": "cpu"
- "mc": "ahb"
- "pcm": "ahb"
- "pio": "ahb"
- "gdma": "ahb"
- "nand": "ahb"
- "i2c": "ahb"
- "i2s": "ahb"
- "spi": "ahb"
- "uart1": "apb"
- "uart2": "apb"
- "uart3": "apb"
- "eth": "ahb"
- "pcie0": "ahb"
- "pcie1": "ahb"
- "pcie2": "ahb"
- "crypto": "ahb"
- "shxc": "ahb"

There was a previous attempt of doing this here[0] but the author did not wanted to make assumptions of a clock plan for the platform.

I do really want this to be upstreamed so according to the comments in previous attempt[0] from Oleksij Rempel I have tried to do this by myself.

All of this patches have been tested in a GNUBee PC1 resulting in a working platform.

[0]: https://www.lkml.org/lkml/2019/7/23/1044

Sergio Paracuellos (7):
dt-bindings: clock: add dt binding header for mt7621 clocks
dt: bindings: add mt7621-pll device tree binding documentation
dt: bindings: add mt7621-clk device tree binding documentation
MIPS: ralink: add clock device providing cpu/ahb/apb clock for mt7621
clk: ralink: add clock gate driver for mt7621 SoC
staging: mt7621-dts: make use of new 'mt7621-pll' and 'mt7621-clk'
MAINTAINERS: add MT7621 CLOCK maintainer

 .../bindings/clock/mediatek,mt7621-clk.yaml   |  52 ++++
 .../bindings/clock/mediatek,mt7621-pll.yaml   |  51 ++++
 MAINTAINERS                                   |   8 +
 arch/mips/include/asm/mach-ralink/mt7621.h    |  20 ++
 arch/mips/ralink/mt7621.c                     |  87 ++++++
 drivers/clk/Kconfig                           |   1 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/ralink/Kconfig                    |  14 +
 drivers/clk/ralink/Makefile                   |   2 +
 drivers/clk/ralink/clk-mt7621.c               | 258 ++++++++++++++++++
 drivers/staging/mt7621-dts/gbpc1.dts          |  11 -
 drivers/staging/mt7621-dts/mt7621.dtsi        |  71 +++--
 include/dt-bindings/clock/mt7621-clk.h        |  39 +++
 13 files changed, 567 insertions(+), 48 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt7621-clk.yaml
 create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt7621-pll.yaml
 create mode 100644 drivers/clk/ralink/Kconfig
 create mode 100644 drivers/clk/ralink/Makefile
 create mode 100644 drivers/clk/ralink/clk-mt7621.c
 create mode 100644 include/dt-bindings/clock/mt7621-clk.h
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/7 dt-bindings: clock: add dt binding header for mt7621 clocks

Adds dt binding header for 'mediatek,mt7621-pll' PLL controller and for 'mediatek,mt7621-clk' clock gates.

---
 include/dt-bindings/clock/mt7621-clk.h | 39 ++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 include/dt-bindings/clock/mt7621-clk.h
include/dt-bindings/clock/mt7621-clk.h new file +39 -0
new file mode 100644
index 000000000000..8fccfa514185
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Author: Sergio Paracuellos <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_CLK_MT7621_H
+#define _DT_BINDINGS_CLK_MT7621_H
+
+/* SYS CLOCKS */
+#define MT7621_CLK_CPU		0
+#define MT7621_CLK_AHB		1
+#define MT7621_CLK_APB		2
+#define MT7621_CLK_MAX		3
+
+/* CLOCK GATES */
+#define MT7621_CLK_HSDMA	0
+#define MT7621_CLK_FE		1
+#define MT7621_CLK_SP_DIVTX	2
+#define MT7621_CLK_TIMER	3
+#define MT7621_CLK_INT		4
+#define MT7621_CLK_MC		5
+#define MT7621_CLK_PCM		6
+#define MT7621_CLK_PIO		7
+#define MT7621_CLK_GDMA		8
+#define MT7621_CLK_NAND		9
+#define MT7621_CLK_I2C		10
+#define MT7621_CLK_I2S		11
+#define MT7621_CLK_SPI		12
+#define MT7621_CLK_UART1	13
+#define MT7621_CLK_UART2	14
+#define MT7621_CLK_UART3	15
+#define MT7621_CLK_ETH		16
+#define MT7621_CLK_PCIE0	17
+#define MT7621_CLK_PCIE1	18
+#define MT7621_CLK_PCIE2	19
+#define MT7621_CLK_CRYPTO	20
+#define MT7621_CLK_SHXC		21
+
+#endif /* _DT_BINDINGS_CLK_MT7621_H */
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

PATCH 2/7 dt: bindings: add mt7621-pll device tree binding documentation

In reply to Sergio Paracuellos

Adds device tree binding documentation for PLL controller in the MT7621 SOC.

---
 .../bindings/clock/mediatek,mt7621-pll.yaml   | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt7621-pll.yaml
Documentation/devicetree/bindings/clock/mediatek,mt7621-pll.yaml new file +51 -0
new file mode 100644
index 000000000000..ef58411065e4
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/mediatek,mt7621-pll.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MT7621 PLL Controller Device Tree Bindings
+
+maintainers:
+  - Sergio Paracuellos <[email protected]>
+
+
+description: |
+  The PLL Controller provides the cpu clock as well as derived
+  clock for the bus and the peripherals.
+
+  Each clock is assigned an identifier and client nodes use this identifier
+  to specify the clock which they consume.
+
+  All these identifiers could be found in:
+  [1]: <include/dt-bindings/clock/mt7621-clk.h>.
+
+properties:
+  compatible:
+    const: mediatek,mt7621-pll
+
+  "#clock-cells":
+    description:
+      The first cell indicates the clock number, see [1] for available
+      clocks.
+    const: 1
+
+  clock-output-names:
+    maxItems: 3
+
+required:
+  - compatible
+  - '#clock-cells'
+  - clock-output-names
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/mt7621-clk.h>
+
+    pll {
+      compatible = "mediatek,mt7621-pll";
+      #clock-cells = <1>;
+      clock-output-names = "cpu", "ahb", "apb";
+    };
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 2/7
#3 lore raw

Re: [PATCH 2/7] dt: bindings: add mt7621-pll device tree binding documentation

Quoted 9 lines · Sergio Paracuellos

Adds device tree binding documentation for PLL controller in the MT7621 SOC.

---
 .../bindings/clock/mediatek,mt7621-pll.yaml   | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt7621-pll.yaml
author maintainer
#4 lore raw

Re: [PATCH 2/7] dt: bindings: add mt7621-pll device tree binding documentation

Hi Rob,

Quoted 5 lines · Rob Herring
Quoted 3 lines · Sergio Paracuellos

Adds device tree binding documentation for PLL controller in the MT7621 SOC.

Quoted 8 lines
Quoted 6 lines
---
 .../bindings/clock/mediatek,mt7621-pll.yaml   | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt7621-pll.yaml

Thanks for the review. In that series there were two clock bindings relating the pll and gates, There were finally joined in only one binding and driver. This is done in the v3 of this series sent on friday. Thanks for your time in looking also into this new version,

Best regards,
Sergio Paracuellos

author maintainer
#5 lore raw

PATCH 3/7 dt: bindings: add mt7621-clk device tree binding documentation

In reply to Sergio Paracuellos

Adds device tree binding documentation for clock gates in the MT7621 SOC.

---
 .../bindings/clock/mediatek,mt7621-clk.yaml   | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt7621-clk.yaml
Documentation/devicetree/bindings/clock/mediatek,mt7621-clk.yaml new file +52 -0
new file mode 100644
index 000000000000..89886b066849
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/mediatek,mt7621-clk.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MT7621 Bus Gates Clock Device Tree Bindings
+
+maintainers:
+  - Sergio Paracuellos <[email protected]>
+
+description: |
+  The MT7621 can gate SoC device clocks.
+
+  Each clock gate is assigned an identifier and client nodes use this identifier
+  to specify the clock gate which they consume.
+
+  All these identifiers could be found in:
+  [1]: <include/dt-bindings/clock/mt7621-clk.h>.
+
+properties:
+  compatible:
+    const: mediatek,mt7621-clk
+
+  "#clock-cells":
+    description:
+      The first cell indicates the clock gate number, see [1] for available
+      clocks.
+    const: 1
+
+  ralink,sysctl:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to the syscon which is in the same address area with syscon
+      device.
+
+required:
+  - compatible
+  - '#clock-cells'
+  - ralink,sysctl
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/mt7621-clk.h>
+
+    clkctrl {
+      compatible = "mediatek,mt7621-clk";
+      #clock-cells = <1>;
+      ralink,sysctl = <&sysc>;
+    };
Signature · 1 line
2.25.1
author maintainer
#6 lore raw

PATCH 4/7 MIPS: ralink: add clock device providing cpu/ahb/apb clock for mt7621

In reply to Sergio Paracuellos

For a long time the mt7621 uses a fixed cpu clock which causes a problem if the cpu frequency is not 880MHz.
This patch adds cpu/ahb/apb clock calculation code and binds clocks to mt7621-pll node.

Adapted from OpenWrt:
c7ca224299 ramips: fix cpu clock of mt7621 and add dt clk devices

---
 arch/mips/include/asm/mach-ralink/mt7621.h | 20 +++++
 arch/mips/ralink/mt7621.c                  | 87 ++++++++++++++++++++++
 2 files changed, 107 insertions(+)
arch/mips/include/asm/mach-ralink/mt7621.h +20 -0
index e1af1ba50bd8..a9f3febddf1c 100644
@@ -17,6 +17,10 @@
 #define SYSC_REG_CHIP_REV		0x0c
 #define SYSC_REG_SYSTEM_CONFIG0		0x10
 #define SYSC_REG_SYSTEM_CONFIG1		0x14
+#define SYSC_REG_CLKCFG0		0x2c
+#define SYSC_REG_CUR_CLK_STS		0x44
+
+#define MEMC_REG_CPU_PLL		0x648
 
 #define CHIP_REV_PKG_MASK		0x1
 #define CHIP_REV_PKG_SHIFT		16
@@ -24,6 +28,22 @@
 #define CHIP_REV_VER_SHIFT		8
 #define CHIP_REV_ECO_MASK		0xf
 
+#define XTAL_MODE_SEL_MASK		0x7
+#define XTAL_MODE_SEL_SHIFT		6
+
+#define CPU_CLK_SEL_MASK		0x3
+#define CPU_CLK_SEL_SHIFT		30
+
+#define CUR_CPU_FDIV_MASK		0x1f
+#define CUR_CPU_FDIV_SHIFT		8
+#define CUR_CPU_FFRAC_MASK		0x1f
+#define CUR_CPU_FFRAC_SHIFT		0
+
+#define CPU_PLL_PREDIV_MASK		0x3
+#define CPU_PLL_PREDIV_SHIFT		12
+#define CPU_PLL_FBDIV_MASK		0x7f
+#define CPU_PLL_FBDIV_SHIFT		4
+
 #define MT7621_DRAM_BASE                0x0
 #define MT7621_DDR2_SIZE_MIN		32
 #define MT7621_DDR2_SIZE_MAX		256
arch/mips/ralink/mt7621.c +87 -0

110 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#7 lore raw

PATCH 5/7 clk: ralink: add clock gate driver for mt7621 SoC

In reply to Sergio Paracuellos

In mt7621 SoC register 'SYSC_REG_CPLL_CLKCFG1' allows to handle a bunch of gates to enable/disable clocks for all or some ip cores. Add a driver to properly handle them. Parent clocks for this gates are not documented at all in the SoC documentation so all of them have been assumed looking into the clock frequencies used in its related driver code. There are three main clocks which are "cpu", "ahb" and "apb" from the 'mt7621-pll'.

The following parents are set to each GATE:
* "hsdma": "ahb"
* "fe": "ahb"
* "sp_divtx": "ahb"
* "timer": "cpu"
* "int": "cpu"
* "mc": "ahb"
* "pcm": "ahb"
* "pio": "ahb"
* "gdma": "ahb"
* "nand": "ahb"
* "i2c": "ahb"
* "i2s": "ahb"
* "spi": "ahb"
* "uart1": "apb"
* "uart2": "apb"
* "uart3": "apb"
* "eth": "ahb"
* "pcie0": "ahb"
* "pcie1": "ahb"
* "pcie2": "ahb"
* "crypto": "ahb"
* "shxc": "ahb"

With this information the clk driver will provide gate functionality from a a set of hardcoded clocks allowing to define a nice device tree without fixed clocks.

---
 drivers/clk/Kconfig             |   1 +
 drivers/clk/Makefile            |   1 +
 drivers/clk/ralink/Kconfig      |  14 ++
 drivers/clk/ralink/Makefile     |   2 +
 drivers/clk/ralink/clk-mt7621.c | 258 ++++++++++++++++++++++++++++++++
 5 files changed, 276 insertions(+)
 create mode 100644 drivers/clk/ralink/Kconfig
 create mode 100644 drivers/clk/ralink/Makefile
 create mode 100644 drivers/clk/ralink/clk-mt7621.c
drivers/clk/Kconfig +1 -0
index c715d4681a0b..5f94c4329033 100644
@@ -372,6 +372,7 @@ source "drivers/clk/mediatek/Kconfig"
 source "drivers/clk/meson/Kconfig"
 source "drivers/clk/mvebu/Kconfig"
 source "drivers/clk/qcom/Kconfig"
+source "drivers/clk/ralink/Kconfig"
 source "drivers/clk/renesas/Kconfig"
 source "drivers/clk/rockchip/Kconfig"
 source "drivers/clk/samsung/Kconfig"
drivers/clk/Makefile +1 -0
index da8fcf147eb1..6578e167b047 100644
@@ -100,6 +100,7 @@ obj-$(CONFIG_COMMON_CLK_NXP)		+= nxp/
 obj-$(CONFIG_MACH_PISTACHIO)		+= pistachio/
 obj-$(CONFIG_COMMON_CLK_PXA)		+= pxa/
 obj-$(CONFIG_COMMON_CLK_QCOM)		+= qcom/
+obj-y					+= ralink/
 obj-y					+= renesas/
 obj-$(CONFIG_ARCH_ROCKCHIP)		+= rockchip/
 obj-$(CONFIG_COMMON_CLK_SAMSUNG)	+= samsung/
drivers/clk/ralink/Kconfig new file +14 -0
new file mode 100644
index 000000000000..7e8697327e0c
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# MediaTek Mt7621 Clock Driver
+#
+menu "Clock driver for mediatek mt7621 SoC"
+	depends on SOC_MT7621 || COMPILE_TEST
+
+config CLK_MT7621
+	bool "Clock driver for MediaTek MT7621"
+	depends on SOC_MT7621 || COMPILE_TEST
+	default SOC_MT7621
+	help
+	  This driver supports MediaTek MT7621 basic clocks.
+endmenu
drivers/clk/ralink/Makefile new file +2 -0
new file mode 100644
index 000000000000..cf6f9216379d
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_CLK_MT7621) += clk-mt7621.o
drivers/clk/ralink/clk-mt7621.c new file +258 -0

258 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#8 lore raw

PATCH 6/7 staging: mt7621-dts: make use of new 'mt7621-pll' and 'mt7621-clk'

In reply to Sergio Paracuellos

Clocks for SoC mt7621 have been properly integrated so there is no need to declare fixed clocks at all in the device tree. Remove all of them, add new device tree nodes for new mt7621-pll and mt7621-clk and update the rest of the nodes to use them.

---
 drivers/staging/mt7621-dts/gbpc1.dts   | 11 ----
 drivers/staging/mt7621-dts/mt7621.dtsi | 71 ++++++++++++--------------
 2 files changed, 34 insertions(+), 48 deletions(-)
drivers/staging/mt7621-dts/gbpc1.dts +0 -11
index a7c0d3115d72..7716d0efe524 100644
@@ -100,17 +100,6 @@ partition@50000 {
 	};
 };
 
-&sysclock {
-			compatible = "fixed-clock";
-			/* This is normally 1/4 of cpuclock */
-			clock-frequency = <225000000>;
-};
-
-&cpuclock {
-			compatible = "fixed-clock";
-			clock-frequency = <900000000>;
-};
-
 &pcie {
 	pinctrl-names = "default";
 	pinctrl-0 = <&pcie_pins>;
drivers/staging/mt7621-dts/mt7621.dtsi +34 -37

168 lines not on this page · raw message

Signature · 1 line
2.25.1
author maintainer
#9 lore raw

PATCH 7/7 MAINTAINERS: add MT7621 CLOCK maintainer

In reply to Sergio Paracuellos

Adding myself as maintainer for mt7621 clock driver.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index f1f088a29bc2..c34c12d62355 100644
@@ -11142,6 +11142,14 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/wireless/mediatek/mt7601u/
 
+MEDIATEK MT7621 CLOCK DRIVER
+M:	Sergio Paracuellos <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/clock/mediatek,mt7621-clk.yaml
+F:	Documentation/devicetree/bindings/clock/mediatek,mt7621-pll.yaml
+F:	arch/mips/ralink/mt7621.c
+F:	drivers/clk/ralink/clk-mt7621.c
+
 MEDIATEK MT7621/28/88 I2C DRIVER
 M:	Stefan Roese <[email protected]>
 L:	[email protected]
Signature · 1 line
2.25.1
#10 lore raw
In reply to Sergio Paracuellos

Hi!

Quoted 54 lines · Sergio Paracuellos

This patchset ports CPU clock detection for MT7621 from OpenWrt and adds a complete clock plan for the mt7621 SOC.

The documentation for this SOC only talks about two registers regarding to the clocks:
* SYSC_REG_CPLL_CLKCFG0 - provides some information about boostrapped refclock. PLL and dividers used for CPU and some sort of BUS (AHB?).
* SYSC_REG_CPLL_CLKCFG1 - a banch of gates to enable/disable clocks for all or some ip cores.

No documentation about a probably existant set of dividers for each ip core is included in the datasheets. So we cannot make anything better, AFAICT.

Looking into driver code, there is another frequency which is used in some drivers (uart, sd...) which for any reason is always hardcoded to 50 MHz. Taking this into account this patchset provides three main fixed clocks to the SOC in 'mt7621-pll' which are:
- "cpu": with detected frequency (900 MHz in my board).
- "ahb": cpu / 4 = 225 Mhz.
- "apb": 50 Mhz.

PLL controller cannot be manipulatedbecause there is no info about how to do it. Because of this, there is nothing related with registers in the included binding.

It also provides a clock gate driver 'mt7621-clk' as a platform driver to allow to enable and disable some clocks in the different ip cores. The parent clocks for this clock gates have also set taking into account existant device tree and driver code resulting in the followings:
- "hsdma": "ahb"
- "fe": "ahb"
- "sp_divtx": "ahb"
- "timer": "cpu"
- "int": "cpu"
- "mc": "ahb"
- "pcm": "ahb"
- "pio": "ahb"
- "gdma": "ahb"
- "nand": "ahb"
- "i2c": "ahb"
- "i2s": "ahb"
- "spi": "ahb"
- "uart1": "apb"
- "uart2": "apb"
- "uart3": "apb"
- "eth": "ahb"
- "pcie0": "ahb"
- "pcie1": "ahb"
- "pcie2": "ahb"
- "crypto": "ahb"
- "shxc": "ahb"

Quoted 2 lines

There was a previous attempt of doing this here[0] but the author did not wanted to make assumptions of a clock plan for the platform.

I've already said in previous threads that clock assignment in current linux kernel is not trustworthy.
I've got the clock plan for mt7621 now. (Can't share it, sorry.) Most of your clock assumptions above are incorrect. I've made a clock driver with gate support a few months ago.[0] but I don't have much time to really finish it.
Maybe you could rework your clock gate driver based on it.

[0] https://github.com/981213/linux/commit/2eca1f045e4c3db18c941135464c0d7422ad8133

Signature · 2 lines
Regards,
Chuanhong Guo
#11 lore raw
Quoted 10 lines · Chuanhong Guo

I've already said in previous threads that clock assignment in current linux kernel is not trustworthy.
I've got the clock plan for mt7621 now. (Can't share it, sorry.) Most of your clock assumptions above are incorrect. I've made a clock driver with gate support a few months ago.[0] but I don't have much time to really finish it.
Maybe you could rework your clock gate driver based on it.

[0] https://github.com/981213/linux/commit/2eca1f045e4c3db18c941135464c0d7422ad8133

hsdma/eth/pio clocks are still missing in mediatek doc and I just made them up in the driver. Correct clock frequency for them aren't really important for them to work though. And another part I didn't finish is checking clock support for every drivers mt7621 used. Many drivers don't explicitly enable the clock and may be problematic when kernel gates unused clocks.

Signature · 2 lines
Regards,
Chuanhong Guo
author maintainer
#12 lore raw

Hi,

Quoted 13 lines · Chuanhong Guo
Quoted 10 lines · Chuanhong Guo

I've already said in previous threads that clock assignment in current linux kernel is not trustworthy.
I've got the clock plan for mt7621 now. (Can't share it, sorry.) Most of your clock assumptions above are incorrect. I've made a clock driver with gate support a few months ago.[0] but I don't have much time to really finish it.
Maybe you could rework your clock gate driver based on it.

[0] https://github.com/981213/linux/commit/2eca1f045e4c3db18c941135464c0d7422ad8133

Quoted 8 lines

hsdma/eth/pio clocks are still missing in mediatek doc and I just made them up in the driver. Correct clock frequency for them aren't really important for them to work though. And another part I didn't finish is checking clock support for every drivers mt7621 used. Many drivers don't explicitly enable the clock and may be problematic when kernel gates unused clocks.

Well, I think they are not important either. Also, by default gate register has all the gate bits enabled. When a gate driver is added, the kernel by default will try to disable those clocks that haven't been requested. To avoid weird behaviour because of some drivers are not using properly clocks we have the CLK_IGNORED_UNUSED, which as you can see is currently being used in my code. Using that all seems to work as expected as it is now.

Quoted 3 lines

--
Regards,
Chuanhong Guo

Best regards,
Sergio Paracuellos

#13 lore raw
Quoted 5 lines · Sergio Paracuellos

To avoid weird behaviour because of some drivers are
not using properly clocks we have the CLK_IGNORED_UNUSED, which as you can see is currently being used in my code. Using that all seems to work as expected as it is now.

The whole point of having a clock gate driver is to gate unused clocks to save (maybe a tiny bit of) power. It's other peripheral drivers' fault that it doesn't enable clocks properly and we shouldn't just work-around the problem in the clock driver by disallowing auto clock gating.

Signature · 2 lines
Regards,
Chuanhong Guo
author maintainer
#14 lore raw
Quoted 9 lines · Chuanhong Guo
Quoted 5 lines · Sergio Paracuellos

To avoid weird behaviour because of some drivers are
not using properly clocks we have the CLK_IGNORED_UNUSED, which as you can see is currently being used in my code. Using that all seems to work as expected as it is now.

Quoted 6 lines

The whole point of having a clock gate driver is to gate unused clocks to save (maybe a tiny bit of) power. It's other peripheral drivers' fault that it doesn't enable clocks properly and we shouldn't just work-around the problem in the clock driver by disallowing auto clock gating.

Totally agreed with what you are saying here but I don't really think using the flag is a workaround. It is just a way to ensure no regressions occurred until all drivers are adapted and also having all of them enabled is the behaviour. For me adapt the rest of driver code
should be a different patch set after this driver is properly
finished and mainlined.

Quoted 3 lines

--
Regards,
Chuanhong Guo

Best regards,
Sergio Paracuellos

author maintainer
#15 lore raw
In reply to Chuanhong Guo

Hi Chuanhong,

On Thu, Nov 12, 2020 at 2:26 AM Chuanhong Guo <[email protected]> wrote:
[snip]

Quoted 5 lines

I've already said in previous threads that clock assignment in current linux kernel is not trustworthy.
I've got the clock plan for mt7621 now. (Can't share it, sorry.) Most of your clock assumptions above are incorrect.

Well, that was of course expected, without a real clock plan this driver was only taking into account Oleksij Rempel suggestions to try to make a driver good enough to properly be maintained :).

Quoted 5 lines

I've made a clock driver with gate support a few months ago.[0] but I don't have much time to really finish it.
Maybe you could rework your clock gate driver based on it.

[0] https://github.com/981213/linux/commit/2eca1f045e4c3db18c941135464c0d7422ad8133

Thanks for the link, I see there are three more clocks there with frequencies of 125, 250 and 270 Mhz. all of them having main xtal as parent. Ok, I will take this real information into account and will send v2 after a bit of more feedback comes.

Quoted 3 lines

--
Regards,
Chuanhong Guo

Best regards,
Sergio Paracuellos