Skip to contentSkip to conversation

clk: add driver for the SiFive FU740

PATCH Superseded Zong Li 5 participants 17 messages Oct 16, 2020 – Nov 5, 2020

Subsystems (4)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Zong Li

author
#0 lore raw

cover clk: add driver for the SiFive FU740

Add a driver for the SiFive FU740 PRCI IP block, which handles more clocks than FU540. These patches also refactor the original implementation by spliting the dependent-code of fu540 and fu740 respectively.

Zong Li (4):
clk: sifive: Extract prci core to common base
clk: sifive: Use common name for prci configuration
clk: sifive: Add a driver for the SiFive FU740 PRCI IP block
clk: sifive: Refactor __prci_clock array by using macro

 arch/riscv/Kconfig.socs                       |   2 +-
 drivers/clk/sifive/Kconfig                    |   8 +-
 drivers/clk/sifive/Makefile                   |   5 +-
 drivers/clk/sifive/fu540-prci.c               | 618 +-----------------
 drivers/clk/sifive/fu540-prci.h               |  21 +
 drivers/clk/sifive/fu740-prci.c               | 102 +++
 drivers/clk/sifive/fu740-prci.h               |  21 +
 drivers/clk/sifive/sifive-prci.c              | 529 +++++++++++++++
 drivers/clk/sifive/sifive-prci.h              | 297 +++++++++
 include/dt-bindings/clock/sifive-fu740-prci.h |  23 +
 10 files changed, 1032 insertions(+), 594 deletions(-)
 create mode 100644 drivers/clk/sifive/fu540-prci.h
 create mode 100644 drivers/clk/sifive/fu740-prci.c
 create mode 100644 drivers/clk/sifive/fu740-prci.h
 create mode 100644 drivers/clk/sifive/sifive-prci.c
 create mode 100644 drivers/clk/sifive/sifive-prci.h
 create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h
Signature · 1 line
2.28.0
author
#1 lore raw

PATCH 1/4 clk: sifive: Extract prci core to common base

Extract common core of prci driver to an independent file, it could allow other chips to reuse it. Separate SoCs-dependent code 'fu540' from prci core, then we can easily add 'fu740' later.

---
 drivers/clk/sifive/Makefile      |   2 +
 drivers/clk/sifive/fu540-prci.c  | 586 +------------------------------
 drivers/clk/sifive/fu540-prci.h  |  21 ++
 drivers/clk/sifive/sifive-prci.c | 409 +++++++++++++++++++++
 drivers/clk/sifive/sifive-prci.h | 201 +++++++++++
 5 files changed, 652 insertions(+), 567 deletions(-)
 create mode 100644 drivers/clk/sifive/fu540-prci.h
 create mode 100644 drivers/clk/sifive/sifive-prci.c
 create mode 100644 drivers/clk/sifive/sifive-prci.h
drivers/clk/sifive/Makefile +2 -0
index 0797f14fef6b..627effe2ece1 100644
@@ -1,2 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
+obj-y += sifive-prci.o
+
 obj-$(CONFIG_CLK_SIFIVE_FU540_PRCI)	+= fu540-prci.o
drivers/clk/sifive/fu540-prci.c +19 -567

625 lines not on this page · raw message

drivers/clk/sifive/fu540-prci.h new file +21 -0
new file mode 100644
index 000000000000..c8271efa7bdc
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 SiFive, Inc.
+ * Zong Li
+ */
+
+#ifndef __SIFIVE_CLK_FU540_PRCI_H
+#define __SIFIVE_CLK_FU540_PRCI_H
+
+#include "sifive-prci.h"
+
+#define NUM_CLOCK_FU540	4
+
+extern struct __prci_clock __prci_init_clocks_fu540[NUM_CLOCK_FU540];
+
+static const struct prci_clk_desc prci_clk_fu540 = {
+	.clks = __prci_init_clocks_fu540,
+	.num_clks = ARRAY_SIZE(__prci_init_clocks_fu540),
+};
+
+#endif /* __SIFIVE_CLK_FU540_PRCI_H */
drivers/clk/sifive/sifive-prci.c new file +409 -0

409 lines not on this page · raw message

drivers/clk/sifive/sifive-prci.h new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
2.28.0
author
#6 lore raw

PATCH 2/4 clk: sifive: Use common name for prci configuration

In reply to Zong Li

Use generic name CLK_SIFIVE_PRCI instead of CLK_SIFIVE_FU540_PRCI. This patch is prepared for fu740 support.

---
 arch/riscv/Kconfig.socs     | 2 +-
 drivers/clk/sifive/Kconfig  | 6 +++---
 drivers/clk/sifive/Makefile | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/Kconfig.socs +1 -1
index 8a55f6156661..3284d5c291be 100644
@@ -5,7 +5,7 @@ config SOC_SIFIVE
 	select SERIAL_SIFIVE if TTY
 	select SERIAL_SIFIVE_CONSOLE if TTY
 	select CLK_SIFIVE
-	select CLK_SIFIVE_FU540_PRCI
+	select CLK_SIFIVE_PRCI
 	select SIFIVE_PLIC
 	help
 	  This enables support for SiFive SoC platform hardware.
drivers/clk/sifive/Kconfig +3 -3
index f3b4eb9cb0f5..ab48cf7e0105 100644
@@ -8,12 +8,12 @@ menuconfig CLK_SIFIVE
 
 if CLK_SIFIVE
 
-config CLK_SIFIVE_FU540_PRCI
-	bool "PRCI driver for SiFive FU540 SoCs"
+config CLK_SIFIVE_PRCI
+	bool "PRCI driver for SiFive SoCs"
 	select CLK_ANALOGBITS_WRPLL_CLN28HPC
 	help
 	  Supports the Power Reset Clock interface (PRCI) IP block found in
-	  FU540 SoCs.  If this kernel is meant to run on a SiFive FU540 SoC,
+	  FU540 SoCs. If this kernel is meant to run on a SiFive FU540 SoC,
 	  enable this driver.
 
 endif
drivers/clk/sifive/Makefile +1 -1
index 627effe2ece1..fe3e2cb4c4d8 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-y += sifive-prci.o
 
-obj-$(CONFIG_CLK_SIFIVE_FU540_PRCI)	+= fu540-prci.o
+obj-$(CONFIG_CLK_SIFIVE_PRCI)	+= fu540-prci.o
Signature · 1 line
2.28.0
author
#10 lore raw

PATCH 3/4 clk: sifive: Add a driver for the SiFive FU740 PRCI IP block

In reply to Zong Li

Add driver code for the SiFive FU740 PRCI IP block. This IP block handles reset and clock control for the SiFive FU740 device and implements SoC-level clock tree controls and dividers.

This driver contains bug fixes and contributions from Henry Styles <[email protected]> and Erik Danie <[email protected]>.

Cc Henry Styles <[email protected]>
Cc Erik Danie <[email protected]>
---
 drivers/clk/sifive/Kconfig                    |   4 +-
 drivers/clk/sifive/Makefile                   |   1 +
 drivers/clk/sifive/fu740-prci.c               | 122 ++++++++++++++++++
 drivers/clk/sifive/fu740-prci.h               |  21 +++
 drivers/clk/sifive/sifive-prci.c              | 120 +++++++++++++++++
 drivers/clk/sifive/sifive-prci.h              |  88 +++++++++++++
 include/dt-bindings/clock/sifive-fu740-prci.h |  23 ++++
 7 files changed, 377 insertions(+), 2 deletions(-)
 create mode 100644 drivers/clk/sifive/fu740-prci.c
 create mode 100644 drivers/clk/sifive/fu740-prci.h
 create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h
drivers/clk/sifive/Kconfig +2 -2
index ab48cf7e0105..1c14eb20c066 100644
@@ -13,7 +13,7 @@ config CLK_SIFIVE_PRCI
 	select CLK_ANALOGBITS_WRPLL_CLN28HPC
 	help
 	  Supports the Power Reset Clock interface (PRCI) IP block found in
-	  FU540 SoCs. If this kernel is meant to run on a SiFive FU540 SoC,
-	  enable this driver.
+	  FU540/FU740 SoCs. If this kernel is meant to run on a SiFive FU540/
+	  FU740 SoCs, enable this driver.
 
 endif
drivers/clk/sifive/Makefile +1 -0
index fe3e2cb4c4d8..2c05798e4ba4 100644
@@ -2,3 +2,4 @@
 obj-y += sifive-prci.o
 
 obj-$(CONFIG_CLK_SIFIVE_PRCI)	+= fu540-prci.o
+obj-$(CONFIG_CLK_SIFIVE_PRCI)	+= fu740-prci.o
drivers/clk/sifive/fu740-prci.c new file +122 -0

122 lines not on this page · raw message

drivers/clk/sifive/fu740-prci.h new file +21 -0
new file mode 100644
index 000000000000..13ef971f7764
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 SiFive, Inc.
+ * Zong Li
+ */
+
+#ifndef __SIFIVE_CLK_FU740_PRCI_H
+#define __SIFIVE_CLK_FU740_PRCI_H
+
+#include "sifive-prci.h"
+
+#define NUM_CLOCK_FU740	8
+
+extern struct __prci_clock __prci_init_clocks_fu740[NUM_CLOCK_FU740];
+
+static const struct prci_clk_desc prci_clk_fu740 = {
+	.clks = __prci_init_clocks_fu740,
+	.num_clks = ARRAY_SIZE(__prci_init_clocks_fu740),
+};
+
+#endif /* __SIFIVE_CLK_FU740_PRCI_H */
drivers/clk/sifive/sifive-prci.c +120 -0

144 lines not on this page · raw message

drivers/clk/sifive/sifive-prci.h +88 -0

105 lines not on this page · raw message

include/dt-bindings/clock/sifive-fu740-prci.h new file +23 -0
new file mode 100644
index 000000000000..cd7706ea5677
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
+/*
+ * Copyright (C) 2019 SiFive, Inc.
+ * Wesley Terpstra
+ * Paul Walmsley
+ * Zong Li
+ */
+
+#ifndef __DT_BINDINGS_CLOCK_SIFIVE_FU740_PRCI_H
+#define __DT_BINDINGS_CLOCK_SIFIVE_FU740_PRCI_H
+
+/* Clock indexes for use by Device Tree data and the PRCI driver */
+
+#define PRCI_CLK_COREPLL	       0
+#define PRCI_CLK_DDRPLL		       1
+#define PRCI_CLK_GEMGXLPLL	       2
+#define PRCI_CLK_DVFSCOREPLL	       3
+#define PRCI_CLK_HFPCLKPLL	       4
+#define PRCI_CLK_CLTXPLL	       5
+#define PRCI_CLK_TLCLK		       6
+#define PRCI_CLK_PCLK		       7
+
+#endif	/* __DT_BINDINGS_CLOCK_SIFIVE_FU740_PRCI_H */
Signature · 1 line
2.28.0
author
#11 lore raw

PATCH 4/4 clk: sifive: Refactor __prci_clock array by using macro

In reply to Zong Li

Refactor code by using DEFINE_PRCI_CLOCK to define each clock and reduce duplicate code.

---
 drivers/clk/sifive/fu540-prci.c  | 38 ++++++----------
 drivers/clk/sifive/fu540-prci.h  |  2 +-
 drivers/clk/sifive/fu740-prci.c  | 74 ++++++++++++--------------------
 drivers/clk/sifive/fu740-prci.h  |  2 +-
 drivers/clk/sifive/sifive-prci.c |  2 +-
 drivers/clk/sifive/sifive-prci.h | 10 ++++-
 6 files changed, 53 insertions(+), 75 deletions(-)
drivers/clk/sifive/fu540-prci.c +14 -24
index 840b97bfff85..d43b9a9984f6 100644
@@ -54,29 +54,19 @@ static const struct clk_ops sifive_fu540_prci_tlclksel_clk_ops = {
 	.recalc_rate = sifive_prci_tlclksel_recalc_rate,
 };
 
+DEFINE_PRCI_CLOCK(fu540, corepll, hfclk,
+		  &sifive_fu540_prci_wrpll_clk_ops, &__prci_corepll_data);
+DEFINE_PRCI_CLOCK(fu540, ddrpll, hfclk,
+		  &sifive_fu540_prci_wrpll_ro_clk_ops, &__prci_ddrpll_data);
+DEFINE_PRCI_CLOCK(fu540, gemgxlpll, hfclk,
+		  &sifive_fu540_prci_wrpll_clk_ops, &__prci_gemgxlpll_data);
+DEFINE_PRCI_CLOCK(fu540, tlclk, corepll,
+		  &sifive_fu540_prci_tlclksel_clk_ops, NULL);
+
 /* List of clock controls provided by the PRCI */
-struct __prci_clock __prci_init_clocks_fu540[] = {
-	[PRCI_CLK_COREPLL] = {
-		.name = "corepll",
-		.parent_name = "hfclk",
-		.ops = &sifive_fu540_prci_wrpll_clk_ops,
-		.pwd = &__prci_corepll_data,
-	},
-	[PRCI_CLK_DDRPLL] = {
-		.name = "ddrpll",
-		.parent_name = "hfclk",
-		.ops = &sifive_fu540_prci_wrpll_ro_clk_ops,
-		.pwd = &__prci_ddrpll_data,
-	},
-	[PRCI_CLK_GEMGXLPLL] = {
-		.name = "gemgxlpll",
-		.parent_name = "hfclk",
-		.ops = &sifive_fu540_prci_wrpll_clk_ops,
-		.pwd = &__prci_gemgxlpll_data,
-	},
-	[PRCI_CLK_TLCLK] = {
-		.name = "tlclk",
-		.parent_name = "corepll",
-		.ops = &sifive_fu540_prci_tlclksel_clk_ops,
-	},
+struct __prci_clock *__prci_init_clocks_fu540[] = {
+	[PRCI_CLK_COREPLL]	= &fu540_corepll,
+	[PRCI_CLK_DDRPLL]	= &fu540_ddrpll,
+	[PRCI_CLK_GEMGXLPLL]	= &fu540_gemgxlpll,
+	[PRCI_CLK_TLCLK]	= &fu540_tlclk,
 };
drivers/clk/sifive/fu540-prci.h +1 -1
index c8271efa7bdc..281200cd8848 100644
@@ -11,7 +11,7 @@
 
 #define NUM_CLOCK_FU540	4
 
-extern struct __prci_clock __prci_init_clocks_fu540[NUM_CLOCK_FU540];
+extern struct __prci_clock *__prci_init_clocks_fu540[NUM_CLOCK_FU540];
 
 static const struct prci_clk_desc prci_clk_fu540 = {
 	.clks = __prci_init_clocks_fu540,
drivers/clk/sifive/fu740-prci.c +27 -47

79 lines not on this page · raw message

drivers/clk/sifive/fu740-prci.h +1 -1
index 13ef971f7764..3f03295f719a 100644
@@ -11,7 +11,7 @@
 
 #define NUM_CLOCK_FU740	8
 
-extern struct __prci_clock __prci_init_clocks_fu740[NUM_CLOCK_FU740];
+extern struct __prci_clock *__prci_init_clocks_fu740[NUM_CLOCK_FU740];
 
 static const struct prci_clk_desc prci_clk_fu740 = {
 	.clks = __prci_init_clocks_fu740,
drivers/clk/sifive/sifive-prci.c +1 -1
index 4098dbc5881a..2ef3f9f91b33 100644
@@ -431,7 +431,7 @@ static int __prci_register_clocks(struct device *dev, struct __prci_data *pd,
 
 	/* Register PLLs */
 	for (i = 0; i < desc->num_clks; ++i) {
-		pic = &(desc->clks[i]);
+		pic = desc->clks[i];
 
 		init.name = pic->name;
 		init.parent_names = &pic->parent_name;
drivers/clk/sifive/sifive-prci.h +9 -1
index bc0646bc9c3e..e6c9f72e20de 100644
@@ -253,6 +253,14 @@ struct __prci_clock {
 	struct __prci_data *pd;
 };
 
+#define DEFINE_PRCI_CLOCK(_platform, _name, _parent, _ops, _pwd)	\
+	static struct __prci_clock _platform##_##_name = {		\
+		.name = #_name,						\
+		.parent_name = #_parent,				\
+		.ops = _ops,						\
+		.pwd = _pwd,						\
+	}								\
+
 #define clk_hw_to_prci_clock(pwd) container_of(pwd, struct __prci_clock, hw)
 
 /*
@@ -261,7 +269,7 @@ struct __prci_clock {
  * @num_clks: the number of element of clks
  */
 struct prci_clk_desc {
-	struct __prci_clock *clks;
+	struct __prci_clock **clks;
 	size_t num_clks;
 };
 
Signature · 1 line
2.28.0
#14 lore raw
In reply to Zong Li
Quoted 7 lines · Zong Li

Add a driver for the SiFive FU740 PRCI IP block, which handles more clocks than FU540. These patches also refactor the original implementation by spliting the dependent-code of fu540 and fu740 respectively.

Zong Li (4):
clk: sifive: Extract prci core to common base

I don't see this patch, and it isn't listed on the web archive. Was it not CC'd to this list?

	--Sean
Quoted 22 lines

clk: sifive: Use common name for prci configuration
clk: sifive: Add a driver for the SiFive FU740 PRCI IP block
clk: sifive: Refactor __prci_clock array by using macro

 arch/riscv/Kconfig.socs                       |   2 +-
 drivers/clk/sifive/Kconfig                    |   8 +-
 drivers/clk/sifive/Makefile                   |   5 +-
 drivers/clk/sifive/fu540-prci.c               | 618 +-----------------
 drivers/clk/sifive/fu540-prci.h               |  21 +
 drivers/clk/sifive/fu740-prci.c               | 102 +++
 drivers/clk/sifive/fu740-prci.h               |  21 +
 drivers/clk/sifive/sifive-prci.c              | 529 +++++++++++++++
 drivers/clk/sifive/sifive-prci.h              | 297 +++++++++
 include/dt-bindings/clock/sifive-fu740-prci.h |  23 +
 10 files changed, 1032 insertions(+), 594 deletions(-)
 create mode 100644 drivers/clk/sifive/fu540-prci.h
 create mode 100644 drivers/clk/sifive/fu740-prci.c
 create mode 100644 drivers/clk/sifive/fu740-prci.h
 create mode 100644 drivers/clk/sifive/sifive-prci.c
 create mode 100644 drivers/clk/sifive/sifive-prci.h
 create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h
author
#15 lore raw
Quoted 7 lines · Sean Anderson
Quoted 5 lines · Zong Li

Add a driver for the SiFive FU740 PRCI IP block, which handles more clocks than FU540. These patches also refactor the original implementation by spliting the dependent-code of fu540 and fu740 respectively.

Quoted 8 lines
Quoted 2 lines

Zong Li (4):
clk: sifive: Extract prci core to common base

I don't see this patch, and it isn't listed on the web archive. Was it not CC'd to this list?

        --Sean

There is a problem on linux-riscv mailing list for the first one patch, the size of it is too big, it needs to be approved and posted on the list by moderator.

This patch set is also sent to clk mailing list, and I can see it on that:
https://patchwork.kernel.org/project/linux-clk/patch/b10784643665ad56ca41ea6754c7f28f8be1c7ca.1602838910.git.zong.li@sifive.com/

Quoted 23 lines
Quoted 22 lines

clk: sifive: Use common name for prci configuration
clk: sifive: Add a driver for the SiFive FU740 PRCI IP block
clk: sifive: Refactor __prci_clock array by using macro

 arch/riscv/Kconfig.socs                       |   2 +-
 drivers/clk/sifive/Kconfig                    |   8 +-
 drivers/clk/sifive/Makefile                   |   5 +-
 drivers/clk/sifive/fu540-prci.c               | 618 +-----------------
 drivers/clk/sifive/fu540-prci.h               |  21 +
 drivers/clk/sifive/fu740-prci.c               | 102 +++
 drivers/clk/sifive/fu740-prci.h               |  21 +
 drivers/clk/sifive/sifive-prci.c              | 529 +++++++++++++++
 drivers/clk/sifive/sifive-prci.h              | 297 +++++++++
 include/dt-bindings/clock/sifive-fu740-prci.h |  23 +
 10 files changed, 1032 insertions(+), 594 deletions(-)
 create mode 100644 drivers/clk/sifive/fu540-prci.h
 create mode 100644 drivers/clk/sifive/fu740-prci.c
 create mode 100644 drivers/clk/sifive/fu740-prci.h
 create mode 100644 drivers/clk/sifive/sifive-prci.c
 create mode 100644 drivers/clk/sifive/sifive-prci.h
 create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h
author
#16 lore raw
Quoted 18 lines · Zong Li
Quoted 7 lines · Sean Anderson
Quoted 5 lines · Zong Li

Add a driver for the SiFive FU740 PRCI IP block, which handles more clocks than FU540. These patches also refactor the original implementation by spliting the dependent-code of fu540 and fu740 respectively.

Quoted 8 lines
Quoted 2 lines

Zong Li (4):
clk: sifive: Extract prci core to common base

I don't see this patch, and it isn't listed on the web archive. Was it not CC'd to this list?

        --Sean
Quoted 33 lines

There is a problem on linux-riscv mailing list for the first one patch, the size of it is too big, it needs to be approved and posted on the list by moderator.

This patch set is also sent to clk mailing list, and I can see it on that:
https://patchwork.kernel.org/project/linux-clk/patch/b10784643665ad56ca41ea6754c7f28f8be1c7ca.1602838910.git.zong.li@sifive.com/

Quoted 23 lines
Quoted 22 lines

clk: sifive: Use common name for prci configuration
clk: sifive: Add a driver for the SiFive FU740 PRCI IP block
clk: sifive: Refactor __prci_clock array by using macro

 arch/riscv/Kconfig.socs                       |   2 +-
 drivers/clk/sifive/Kconfig                    |   8 +-
 drivers/clk/sifive/Makefile                   |   5 +-
 drivers/clk/sifive/fu540-prci.c               | 618 +-----------------
 drivers/clk/sifive/fu540-prci.h               |  21 +
 drivers/clk/sifive/fu740-prci.c               | 102 +++
 drivers/clk/sifive/fu740-prci.h               |  21 +
 drivers/clk/sifive/sifive-prci.c              | 529 +++++++++++++++
 drivers/clk/sifive/sifive-prci.h              | 297 +++++++++
 include/dt-bindings/clock/sifive-fu740-prci.h |  23 +
 10 files changed, 1032 insertions(+), 594 deletions(-)
 create mode 100644 drivers/clk/sifive/fu540-prci.h
 create mode 100644 drivers/clk/sifive/fu740-prci.c
 create mode 100644 drivers/clk/sifive/fu740-prci.h
 create mode 100644 drivers/clk/sifive/sifive-prci.c
 create mode 100644 drivers/clk/sifive/sifive-prci.h
 create mode 100644 include/dt-bindings/clock/sifive-fu740-prci.h

ping

maintainer
#2 lore raw

Re: [PATCH 1/4] clk: sifive: Extract prci core to common base

In reply to Zong Li

Quoting Zong Li (2020-10-16 02:18:23)

Quoted 3 lines

Extract common core of prci driver to an independent file, it could allow other chips to reuse it. Separate SoCs-dependent code 'fu540' from prci core, then we can easily add 'fu740' later.

Please indicate if there are any functional changes or this is just code movement.

Quoted 8 lines
---
 drivers/clk/sifive/Makefile      |   2 +
 drivers/clk/sifive/fu540-prci.c  | 586 +------------------------------
 drivers/clk/sifive/fu540-prci.h  |  21 ++
 drivers/clk/sifive/sifive-prci.c | 409 +++++++++++++++++++++
 drivers/clk/sifive/sifive-prci.h | 201 +++++++++++

How much of this is a copy/pastes? Can you generate patches with format-patch -M -C to try to find copies and renames?

Quoted 5 lines
 5 files changed, 652 insertions(+), 567 deletions(-)
 create mode 100644 drivers/clk/sifive/fu540-prci.h
 create mode 100644 drivers/clk/sifive/sifive-prci.c
 create mode 100644 drivers/clk/sifive/sifive-prci.h
maintainer
#7 lore raw

Re: [PATCH 2/4] clk: sifive: Use common name for prci configuration

In reply to Zong Li

Quoting Zong Li (2020-10-16 02:18:24)

Quoted 5 lines

Use generic name CLK_SIFIVE_PRCI instead of CLK_SIFIVE_FU540_PRCI. This patch is prepared for fu740 support.

---

Looks ok but needs an ack from riscv maintainers to go through clk tree. I was worried it would break defconfigs but it seems that the arch selects the config so this should be OK, right?

Quoted 18 lines
 arch/riscv/Kconfig.socs     | 2 +-
 drivers/clk/sifive/Kconfig  | 6 +++---
 drivers/clk/sifive/Makefile | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/Kconfig.socs +1 -1
index 8a55f6156661..3284d5c291be 100644
@@ -5,7 +5,7 @@ config SOC_SIFIVE
        select SERIAL_SIFIVE if TTY
        select SERIAL_SIFIVE_CONSOLE if TTY
        select CLK_SIFIVE
-       select CLK_SIFIVE_FU540_PRCI
+       select CLK_SIFIVE_PRCI
        select SIFIVE_PLIC
        help
          This enables support for SiFive SoC platform hardware.
maintainer
#12 lore raw

Re: [PATCH 4/4] clk: sifive: Refactor __prci_clock array by using macro

In reply to Zong Li

Quoting Zong Li (2020-10-16 02:18:26)

Quoted 2 lines

Refactor code by using DEFINE_PRCI_CLOCK to define each clock and reduce duplicate code.

What is duplicate?

Quoted 17 lines
---
 drivers/clk/sifive/fu540-prci.c  | 38 ++++++----------
 drivers/clk/sifive/fu540-prci.h  |  2 +-
 drivers/clk/sifive/fu740-prci.c  | 74 ++++++++++++--------------------
 drivers/clk/sifive/fu740-prci.h  |  2 +-
 drivers/clk/sifive/sifive-prci.c |  2 +-
 drivers/clk/sifive/sifive-prci.h | 10 ++++-
 6 files changed, 53 insertions(+), 75 deletions(-)
drivers/clk/sifive/fu540-prci.c +0 -0
index 840b97bfff85..d43b9a9984f6 100644
@@ -54,29 +54,19 @@ static const struct clk_ops sifive_fu540_prci_tlclksel_clk_ops = {
        .recalc_rate = sifive_prci_tlclksel_recalc_rate,

drivers/clk/sifive/fu540-prci.c static const struct clk_ops sifive_fu540_prci_tlclksel_clk_ops = { · line 64

Quoted 10 lines
drivers/clk/sifive/fu540-prci.c +8 -0
 };
 
+DEFINE_PRCI_CLOCK(fu540, corepll, hfclk,
+                 &sifive_fu540_prci_wrpll_clk_ops, &__prci_corepll_data);
+DEFINE_PRCI_CLOCK(fu540, ddrpll, hfclk,
+                 &sifive_fu540_prci_wrpll_ro_clk_ops, &__prci_ddrpll_data);
+DEFINE_PRCI_CLOCK(fu540, gemgxlpll, hfclk,
+                 &sifive_fu540_prci_wrpll_clk_ops, &__prci_gemgxlpll_data);
+DEFINE_PRCI_CLOCK(fu540, tlclk, corepll,
+                 &sifive_fu540_prci_tlclksel_clk_ops, NULL);

Readability looks to decrease with this change. Why should all us code reviewers suffer because the code author wants to type a few less characters? Named initializers are useful so we don't have to hold each macro argument in our head and map it to the struct member that is being initialized.

Quoted 119 lines
drivers/clk/sifive/fu540-prci.c +6 -24
+
 /* List of clock controls provided by the PRCI */
-struct __prci_clock __prci_init_clocks_fu540[] = {
-       [PRCI_CLK_COREPLL] = {
-               .name = "corepll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu540_prci_wrpll_clk_ops,
-               .pwd = &__prci_corepll_data,
-       },
-       [PRCI_CLK_DDRPLL] = {
-               .name = "ddrpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu540_prci_wrpll_ro_clk_ops,
-               .pwd = &__prci_ddrpll_data,
-       },
-       [PRCI_CLK_GEMGXLPLL] = {
-               .name = "gemgxlpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu540_prci_wrpll_clk_ops,
-               .pwd = &__prci_gemgxlpll_data,
-       },
-       [PRCI_CLK_TLCLK] = {
-               .name = "tlclk",
-               .parent_name = "corepll",
-               .ops = &sifive_fu540_prci_tlclksel_clk_ops,
-       },
+struct __prci_clock *__prci_init_clocks_fu540[] = {
+       [PRCI_CLK_COREPLL]      = &fu540_corepll,
+       [PRCI_CLK_DDRPLL]       = &fu540_ddrpll,
+       [PRCI_CLK_GEMGXLPLL]    = &fu540_gemgxlpll,
+       [PRCI_CLK_TLCLK]        = &fu540_tlclk,
 };
drivers/clk/sifive/fu540-prci.h +1 -1
index c8271efa7bdc..281200cd8848 100644
@@ -11,7 +11,7 @@
 
 #define NUM_CLOCK_FU540        4
 
-extern struct __prci_clock __prci_init_clocks_fu540[NUM_CLOCK_FU540];
+extern struct __prci_clock *__prci_init_clocks_fu540[NUM_CLOCK_FU540];
 
 static const struct prci_clk_desc prci_clk_fu540 = {
        .clks = __prci_init_clocks_fu540,
drivers/clk/sifive/fu740-prci.c +18 -47
index 3b87e273c3eb..676cad2c3886 100644
@@ -71,52 +71,32 @@ static const struct clk_ops sifive_fu740_prci_hfpclkplldiv_clk_ops = {
        .recalc_rate = sifive_prci_hfpclkplldiv_recalc_rate,
 };
 
+
+DEFINE_PRCI_CLOCK(fu740, corepll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_corepll_data);
+DEFINE_PRCI_CLOCK(fu740, ddrpll, hfclk,
+                 &sifive_fu740_prci_wrpll_ro_clk_ops, &__prci_ddrpll_data);
+DEFINE_PRCI_CLOCK(fu740, gemgxlpll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_gemgxlpll_data);
+DEFINE_PRCI_CLOCK(fu740, dvfscorepll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_dvfscorepll_data);
+DEFINE_PRCI_CLOCK(fu740, hfpclkpll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_hfpclkpll_data);
+DEFINE_PRCI_CLOCK(fu740, cltxpll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_cltxpll_data);
+DEFINE_PRCI_CLOCK(fu740, tlclk, corepll,
+                 &sifive_fu740_prci_tlclksel_clk_ops, NULL);
+DEFINE_PRCI_CLOCK(fu740, pclk, hfpclkpll,
+                 &sifive_fu740_prci_hfpclkplldiv_clk_ops, NULL);
+
 /* List of clock controls provided by the PRCI */
-struct __prci_clock __prci_init_clocks_fu740[] = {
-       [PRCI_CLK_COREPLL] = {
-               .name = "corepll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_corepll_data,
-       },
-       [PRCI_CLK_DDRPLL] = {
-               .name = "ddrpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_ro_clk_ops,
-               .pwd = &__prci_ddrpll_data,
-       },
-       [PRCI_CLK_GEMGXLPLL] = {
-               .name = "gemgxlpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_gemgxlpll_data,
-       },
-       [PRCI_CLK_DVFSCOREPLL] = {
-               .name = "dvfscorepll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_dvfscorepll_data,
-       },
-       [PRCI_CLK_HFPCLKPLL] = {
-               .name = "hfpclkpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_hfpclkpll_data,
-       },
-       [PRCI_CLK_CLTXPLL] = {
-               .name = "cltxpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_cltxpll_data,
-       },
-       [PRCI_CLK_TLCLK] = {
-               .name = "tlclk",
-               .parent_name = "corepll",
-               .ops = &sifive_fu740_prci_tlclksel_clk_ops,
-       },
-       [PRCI_CLK_PCLK] = {
-               .name = "pclk",
-               .parent_name = "hfpclkpll",
-               .ops = &sifive_fu740_prci_hfpclkplldiv_clk_ops,
-       },

drivers/clk/sifive/fu740-prci.c static const struct clk_ops sifive_fu740_prci_hfpclkplldiv_clk_ops = { · line 102

Quoted 10 lines
drivers/clk/sifive/fu740-prci.c +9 -0
+struct __prci_clock *__prci_init_clocks_fu740[] = {
+       [PRCI_CLK_COREPLL]      = &fu740_corepll,
+       [PRCI_CLK_DDRPLL]       = &fu740_ddrpll,
+       [PRCI_CLK_GEMGXLPLL]    = &fu740_gemgxlpll,
+       [PRCI_CLK_DVFSCOREPLL]  = &fu740_dvfscorepll,
+       [PRCI_CLK_HFPCLKPLL]    = &fu740_hfpclkpll,
+       [PRCI_CLK_CLTXPLL]      = &fu740_cltxpll,
+       [PRCI_CLK_TLCLK]        = &fu740_tlclk,
+       [PRCI_CLK_PCLK]         = &fu740_pclk,
 };

I suppose this is fine and then non-macro structs above this array of pointers.

Quoted 18 lines
drivers/clk/sifive/fu740-prci.h +1 -1
index 13ef971f7764..3f03295f719a 100644
@@ -11,7 +11,7 @@
 
 #define NUM_CLOCK_FU740        8
 
-extern struct __prci_clock __prci_init_clocks_fu740[NUM_CLOCK_FU740];
+extern struct __prci_clock *__prci_init_clocks_fu740[NUM_CLOCK_FU740];
 
 static const struct prci_clk_desc prci_clk_fu740 = {
        .clks = __prci_init_clocks_fu740,
drivers/clk/sifive/sifive-prci.c +0 -0
index 4098dbc5881a..2ef3f9f91b33 100644

drivers/clk/sifive/sifive-prci.c static int __prci_register_clocks(struct device *dev, struct __prci_data *pd, · line 434

Quoted 5 lines
drivers/clk/sifive/sifive-prci.c +1 -1
@@ -431,7 +431,7 @@ static int __prci_register_clocks(struct device *dev, struct __prci_data *pd,
 
        /* Register PLLs */
        for (i = 0; i < desc->num_clks; ++i) {
-               pic = &(desc->clks[i]);
+               pic = desc->clks[i];

This is related how?

Quoted 23 lines
drivers/clk/sifive/sifive-prci.c +0 -0
                init.name = pic->name;
                init.parent_names = &pic->parent_name;
drivers/clk/sifive/sifive-prci.h +8 -0
index bc0646bc9c3e..e6c9f72e20de 100644
@@ -253,6 +253,14 @@ struct __prci_clock {
        struct __prci_data *pd;
 };
 
+#define DEFINE_PRCI_CLOCK(_platform, _name, _parent, _ops, _pwd)       \
+       static struct __prci_clock _platform##_##_name = {              \
+               .name = #_name,                                         \
+               .parent_name = #_parent,                                \
+               .ops = _ops,                                            \
+               .pwd = _pwd,                                            \
+       }                                                               \
+
 #define clk_hw_to_prci_clock(pwd) container_of(pwd, struct __prci_clock, hw)
 
 /*

drivers/clk/sifive/sifive-prci.h struct __prci_clock { · line 272

Quoted 5 lines
drivers/clk/sifive/sifive-prci.h +1 -1
@@ -261,7 +269,7 @@ struct __prci_clock {
  * @num_clks: the number of element of clks
  */
 struct prci_clk_desc {
-       struct __prci_clock *clks;
+       struct __prci_clock **clks;

Huh? Nothing in the commit text mentions this.

Quoted 2 lines
drivers/clk/sifive/sifive-prci.h +0 -0
        size_t num_clks;
 };
author
#8 lore raw

Re: [PATCH 2/4] clk: sifive: Use common name for prci configuration

In reply to Stephen Boyd
Quoted 11 lines · Stephen Boyd

Quoting Zong Li (2020-10-16 02:18:24)

Quoted 5 lines

Use generic name CLK_SIFIVE_PRCI instead of CLK_SIFIVE_FU540_PRCI. This patch is prepared for fu740 support.

---

Looks ok but needs an ack from riscv maintainers to go through clk tree. I was worried it would break defconfigs but it seems that the arch selects the config so this should be OK, right?

Yes, this config is selected by arch, the defconfig won't be impacted.

Quoted 19 lines
Quoted 19 lines
 arch/riscv/Kconfig.socs     | 2 +-
 drivers/clk/sifive/Kconfig  | 6 +++---
 drivers/clk/sifive/Makefile | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/Kconfig.socs +1 -1
index 8a55f6156661..3284d5c291be 100644
@@ -5,7 +5,7 @@ config SOC_SIFIVE
        select SERIAL_SIFIVE if TTY
        select SERIAL_SIFIVE_CONSOLE if TTY
        select CLK_SIFIVE
-       select CLK_SIFIVE_FU540_PRCI
+       select CLK_SIFIVE_PRCI
        select SIFIVE_PLIC
        help
          This enables support for SiFive SoC platform hardware.
author
#13 lore raw

Re: [PATCH 4/4] clk: sifive: Refactor __prci_clock array by using macro

In reply to Stephen Boyd
Quoted 6 lines · Stephen Boyd

Quoting Zong Li (2020-10-16 02:18:26)

Quoted 2 lines

Refactor code by using DEFINE_PRCI_CLOCK to define each clock and reduce duplicate code.

What is duplicate?

Sorry for unclear description, actually, I want to say that we can remove the repeating code about initializing the data member of structure.

Quoted 20 lines
Quoted 20 lines
---
 drivers/clk/sifive/fu540-prci.c  | 38 ++++++----------
 drivers/clk/sifive/fu540-prci.h  |  2 +-
 drivers/clk/sifive/fu740-prci.c  | 74 ++++++++++++--------------------
 drivers/clk/sifive/fu740-prci.h  |  2 +-
 drivers/clk/sifive/sifive-prci.c |  2 +-
 drivers/clk/sifive/sifive-prci.h | 10 ++++-
 6 files changed, 53 insertions(+), 75 deletions(-)
drivers/clk/sifive/fu540-prci.c +0 -0
index 840b97bfff85..d43b9a9984f6 100644
@@ -54,29 +54,19 @@ static const struct clk_ops sifive_fu540_prci_tlclksel_clk_ops = {
        .recalc_rate = sifive_prci_tlclksel_recalc_rate,
 };
 
Quoted 14 lines

drivers/clk/sifive/fu540-prci.c static const struct clk_ops sifive_fu540_prci_tlclksel_clk_ops = { · line 64

Quoted 8 lines
drivers/clk/sifive/fu540-prci.c +8 -0
+DEFINE_PRCI_CLOCK(fu540, corepll, hfclk,
+                 &sifive_fu540_prci_wrpll_clk_ops, &__prci_corepll_data);
+DEFINE_PRCI_CLOCK(fu540, ddrpll, hfclk,
+                 &sifive_fu540_prci_wrpll_ro_clk_ops, &__prci_ddrpll_data);
+DEFINE_PRCI_CLOCK(fu540, gemgxlpll, hfclk,
+                 &sifive_fu540_prci_wrpll_clk_ops, &__prci_gemgxlpll_data);
+DEFINE_PRCI_CLOCK(fu540, tlclk, corepll,
+                 &sifive_fu540_prci_tlclksel_clk_ops, NULL);

Readability looks to decrease with this change. Why should all us code reviewers suffer because the code author wants to type a few less characters? Named initializers are useful so we don't have to hold each macro argument in our head and map it to the struct member that is being initialized.

Ok, as you mentioned, macro reduce the readability, let me remove this change in the next version.

Quoted 181 lines
Quoted 120 lines
drivers/clk/sifive/fu540-prci.c +6 -24
+
 /* List of clock controls provided by the PRCI */
-struct __prci_clock __prci_init_clocks_fu540[] = {
-       [PRCI_CLK_COREPLL] = {
-               .name = "corepll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu540_prci_wrpll_clk_ops,
-               .pwd = &__prci_corepll_data,
-       },
-       [PRCI_CLK_DDRPLL] = {
-               .name = "ddrpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu540_prci_wrpll_ro_clk_ops,
-               .pwd = &__prci_ddrpll_data,
-       },
-       [PRCI_CLK_GEMGXLPLL] = {
-               .name = "gemgxlpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu540_prci_wrpll_clk_ops,
-               .pwd = &__prci_gemgxlpll_data,
-       },
-       [PRCI_CLK_TLCLK] = {
-               .name = "tlclk",
-               .parent_name = "corepll",
-               .ops = &sifive_fu540_prci_tlclksel_clk_ops,
-       },
+struct __prci_clock *__prci_init_clocks_fu540[] = {
+       [PRCI_CLK_COREPLL]      = &fu540_corepll,
+       [PRCI_CLK_DDRPLL]       = &fu540_ddrpll,
+       [PRCI_CLK_GEMGXLPLL]    = &fu540_gemgxlpll,
+       [PRCI_CLK_TLCLK]        = &fu540_tlclk,
 };
drivers/clk/sifive/fu540-prci.h +1 -1
index c8271efa7bdc..281200cd8848 100644
@@ -11,7 +11,7 @@
 
 #define NUM_CLOCK_FU540        4
 
-extern struct __prci_clock __prci_init_clocks_fu540[NUM_CLOCK_FU540];
+extern struct __prci_clock *__prci_init_clocks_fu540[NUM_CLOCK_FU540];
 
 static const struct prci_clk_desc prci_clk_fu540 = {
        .clks = __prci_init_clocks_fu540,
drivers/clk/sifive/fu740-prci.c +18 -47
index 3b87e273c3eb..676cad2c3886 100644
@@ -71,52 +71,32 @@ static const struct clk_ops sifive_fu740_prci_hfpclkplldiv_clk_ops = {
        .recalc_rate = sifive_prci_hfpclkplldiv_recalc_rate,
 };
 
+
+DEFINE_PRCI_CLOCK(fu740, corepll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_corepll_data);
+DEFINE_PRCI_CLOCK(fu740, ddrpll, hfclk,
+                 &sifive_fu740_prci_wrpll_ro_clk_ops, &__prci_ddrpll_data);
+DEFINE_PRCI_CLOCK(fu740, gemgxlpll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_gemgxlpll_data);
+DEFINE_PRCI_CLOCK(fu740, dvfscorepll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_dvfscorepll_data);
+DEFINE_PRCI_CLOCK(fu740, hfpclkpll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_hfpclkpll_data);
+DEFINE_PRCI_CLOCK(fu740, cltxpll, hfclk,
+                 &sifive_fu740_prci_wrpll_clk_ops, &__prci_cltxpll_data);
+DEFINE_PRCI_CLOCK(fu740, tlclk, corepll,
+                 &sifive_fu740_prci_tlclksel_clk_ops, NULL);
+DEFINE_PRCI_CLOCK(fu740, pclk, hfpclkpll,
+                 &sifive_fu740_prci_hfpclkplldiv_clk_ops, NULL);
+
 /* List of clock controls provided by the PRCI */
-struct __prci_clock __prci_init_clocks_fu740[] = {
-       [PRCI_CLK_COREPLL] = {
-               .name = "corepll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_corepll_data,
-       },
-       [PRCI_CLK_DDRPLL] = {
-               .name = "ddrpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_ro_clk_ops,
-               .pwd = &__prci_ddrpll_data,
-       },
-       [PRCI_CLK_GEMGXLPLL] = {
-               .name = "gemgxlpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_gemgxlpll_data,
-       },
-       [PRCI_CLK_DVFSCOREPLL] = {
-               .name = "dvfscorepll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_dvfscorepll_data,
-       },
-       [PRCI_CLK_HFPCLKPLL] = {
-               .name = "hfpclkpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_hfpclkpll_data,
-       },
-       [PRCI_CLK_CLTXPLL] = {
-               .name = "cltxpll",
-               .parent_name = "hfclk",
-               .ops = &sifive_fu740_prci_wrpll_clk_ops,
-               .pwd = &__prci_cltxpll_data,
-       },
-       [PRCI_CLK_TLCLK] = {
-               .name = "tlclk",
-               .parent_name = "corepll",
-               .ops = &sifive_fu740_prci_tlclksel_clk_ops,
-       },
-       [PRCI_CLK_PCLK] = {
-               .name = "pclk",
-               .parent_name = "hfpclkpll",
-               .ops = &sifive_fu740_prci_hfpclkplldiv_clk_ops,
-       },

drivers/clk/sifive/fu740-prci.c static const struct clk_ops sifive_fu740_prci_hfpclkplldiv_clk_ops = { · line 102

Quoted 10 lines
drivers/clk/sifive/fu740-prci.c +9 -0
+struct __prci_clock *__prci_init_clocks_fu740[] = {
+       [PRCI_CLK_COREPLL]      = &fu740_corepll,
+       [PRCI_CLK_DDRPLL]       = &fu740_ddrpll,
+       [PRCI_CLK_GEMGXLPLL]    = &fu740_gemgxlpll,
+       [PRCI_CLK_DVFSCOREPLL]  = &fu740_dvfscorepll,
+       [PRCI_CLK_HFPCLKPLL]    = &fu740_hfpclkpll,
+       [PRCI_CLK_CLTXPLL]      = &fu740_cltxpll,
+       [PRCI_CLK_TLCLK]        = &fu740_tlclk,
+       [PRCI_CLK_PCLK]         = &fu740_pclk,
 };

I suppose this is fine and then non-macro structs above this array of pointers.

Quoted 18 lines
drivers/clk/sifive/fu740-prci.h +1 -1
index 13ef971f7764..3f03295f719a 100644
@@ -11,7 +11,7 @@
 
 #define NUM_CLOCK_FU740        8
 
-extern struct __prci_clock __prci_init_clocks_fu740[NUM_CLOCK_FU740];
+extern struct __prci_clock *__prci_init_clocks_fu740[NUM_CLOCK_FU740];
 
 static const struct prci_clk_desc prci_clk_fu740 = {
        .clks = __prci_init_clocks_fu740,
drivers/clk/sifive/sifive-prci.c +0 -0
index 4098dbc5881a..2ef3f9f91b33 100644

drivers/clk/sifive/sifive-prci.c static int __prci_register_clocks(struct device *dev, struct __prci_data *pd, · line 434

Quoted 5 lines
drivers/clk/sifive/sifive-prci.c +1 -1
@@ -431,7 +431,7 @@ static int __prci_register_clocks(struct device *dev, struct __prci_data *pd,
 
        /* Register PLLs */
        for (i = 0; i < desc->num_clks; ++i) {
-               pic = &(desc->clks[i]);
+               pic = desc->clks[i];

This is related how?

Quoted 21 lines
drivers/clk/sifive/sifive-prci.c +0 -0
                init.name = pic->name;
                init.parent_names = &pic->parent_name;
drivers/clk/sifive/sifive-prci.h +8 -0
index bc0646bc9c3e..e6c9f72e20de 100644
@@ -253,6 +253,14 @@ struct __prci_clock {
        struct __prci_data *pd;
 };
 
+#define DEFINE_PRCI_CLOCK(_platform, _name, _parent, _ops, _pwd)       \
+       static struct __prci_clock _platform##_##_name = {              \
+               .name = #_name,                                         \
+               .parent_name = #_parent,                                \
+               .ops = _ops,                                            \
+               .pwd = _pwd,                                            \
+       }                                                               \
+
 #define clk_hw_to_prci_clock(pwd) container_of(pwd, struct __prci_clock, hw)
 
Quoted 10 lines

drivers/clk/sifive/sifive-prci.h struct __prci_clock { · line 272

Quoted 7 lines
drivers/clk/sifive/sifive-prci.h +1 -1
 /*
@@ -261,7 +269,7 @@ struct __prci_clock {
  * @num_clks: the number of element of clks
  */
 struct prci_clk_desc {
-       struct __prci_clock *clks;
+       struct __prci_clock **clks;

Huh? Nothing in the commit text mentions this.

Because I introduce the macro in this patch, so the type of array __prci_init_clocks_fuXXX are changed to pointer which point to __prci_clock, the related use need to be changed as well. It would be recover due to discarding this patch.

Quoted 2 lines
Quoted 2 lines
drivers/clk/sifive/sifive-prci.h +0 -0
        size_t num_clks;
 };
author
#3 lore raw

Re: [PATCH 1/4] clk: sifive: Extract prci core to common base

In reply to Stephen Boyd
Quoted 8 lines · Stephen Boyd

Quoting Zong Li (2020-10-16 02:18:23)

Quoted 3 lines

Extract common core of prci driver to an independent file, it could allow other chips to reuse it. Separate SoCs-dependent code 'fu540' from prci core, then we can easily add 'fu740' later.

Please indicate if there are any functional changes or this is just code movement.

There are some changes for common use, not just code movement or copies, I would figure out the changes in the commit message in the next version.

Quoted 10 lines
Quoted 9 lines
---
 drivers/clk/sifive/Makefile      |   2 +
 drivers/clk/sifive/fu540-prci.c  | 586 +------------------------------
 drivers/clk/sifive/fu540-prci.h  |  21 ++
 drivers/clk/sifive/sifive-prci.c | 409 +++++++++++++++++++++
 drivers/clk/sifive/sifive-prci.h | 201 +++++++++++
Quoted 2 lines

How much of this is a copy/pastes? Can you generate patches with format-patch -M -C to try to find copies and renames?

I tried to add -M and -C option to find renames and copies, but it doesn't detect anything here.

Quoted 6 lines
Quoted 6 lines
 5 files changed, 652 insertions(+), 567 deletions(-)
 create mode 100644 drivers/clk/sifive/fu540-prci.h
 create mode 100644 drivers/clk/sifive/sifive-prci.c
 create mode 100644 drivers/clk/sifive/sifive-prci.h
#4 lore raw

Re: [PATCH 1/4] clk: sifive: Extract prci core to common base

Quoted 2 lines · Zong Li

I tried to add -M and -C option to find renames and copies, but it doesn't detect anything here.

-C40 finds a copy drivers/clk/sifive/{fu540-prci.c => sifive-prci.c}.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
author
#5 lore raw

Re: [PATCH 1/4] clk: sifive: Extract prci core to common base

Quoted 7 lines · Andreas Schwab
Quoted 2 lines · Zong Li

I tried to add -M and -C option to find renames and copies, but it doesn't detect anything here.

-C40 finds a copy drivers/clk/sifive/{fu540-prci.c => sifive-prci.c}.

Thanks! I used the default value of these options, I would create the patch with -C40 in the next version.

Quoted 7 lines

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."

maintainer Reviewed-by Acked-by
#9 lore raw

Re: [PATCH 2/4] clk: sifive: Use common name for prci configuration

In reply to Stephen Boyd
Quoted 10 lines · On Wed, 04 Nov 2020 18:46:56 PST (-0800), [email protected] wrote:

Quoting Zong Li (2020-10-16 02:18:24)

Quoted 5 lines

Use generic name CLK_SIFIVE_PRCI instead of CLK_SIFIVE_FU540_PRCI. This patch is prepared for fu740 support.

---

Looks ok but needs an ack from riscv maintainers to go through clk tree. I was worried it would break defconfigs but it seems that the arch selects the config so this should be OK, right?

Ya, looks fine. TBH the whole Kconfig.socs thing was probably a mistake, but at least in this case it makes things easy.

I was going to suggest spliting the Kconfigs out so there's a _FU540_PRCI and an _FU740_PRCI, but looking at the code it doesn't really seem to buy us much -- just that one offset table we could toss.

Quoted 18 lines
Quoted 18 lines
 arch/riscv/Kconfig.socs     | 2 +-
 drivers/clk/sifive/Kconfig  | 6 +++---
 drivers/clk/sifive/Makefile | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/Kconfig.socs +1 -1
index 8a55f6156661..3284d5c291be 100644
@@ -5,7 +5,7 @@ config SOC_SIFIVE
        select SERIAL_SIFIVE if TTY
        select SERIAL_SIFIVE_CONSOLE if TTY
        select CLK_SIFIVE
-       select CLK_SIFIVE_FU540_PRCI
+       select CLK_SIFIVE_PRCI
        select SIFIVE_PLIC
        help
          This enables support for SiFive SoC platform hardware.