Skip to contentSkip to conversation

clk: npcm750: Add NPCM7XX Clock driver and binding

PATCH Superseded [email protected] 2 participants 5 messages Mar 20, 2018 – Mar 23, 2018

Subsystems (3)

v11 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v11 cover clk: npcm750: Add NPCM7XX Clock driver and binding

From: Tali Perry <[email protected]>

Nuvoton NPCM7XX Clock Controller

Nuvoton Poleg BMC NPCM7XX contains an integrated clock controller, which generates and supplies clocks to all modules within the BMC.

---

10 ==> 11
update documentation. "eth" replaced with "ethernet" in use case eaxample.

2 ==> 10
update documentation. add external clocks as inputs to clk driver. fix SPDX comment.

1 ==> 2
This patch includes fix request described here:
https://patchwork.kernel.org/patch/10200033/
(move fixed clocks to DT)

Tali Perry (2):
clk: npcm750: Add binding for Nuvoton NPCM7XX clock Controller
clk: npcm7xx: Add Nuvoton NPCM7XX Clock Controller driver

 .../bindings/clock/nuvoton,npcm750-clk.txt         | 100 +++
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-npcm7xx.c                          | 757 +++++++++++++++++++++
 include/dt-bindings/clock/nuvoton,npcm7xx-clock.h  |  44 ++
 4 files changed, 902 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,npcm750-clk.txt
 create mode 100644 drivers/clk/clk-npcm7xx.c
 create mode 100644 include/dt-bindings/clock/nuvoton,npcm7xx-clock.h
Signature · 1 line
2.14.1
author maintainer
#1 lore raw

PATCH v11 1/2 dt-binding: clk: npcm750: Add binding for Nuvoton NPCM7XX Clock

From: Tali Perry <[email protected]>

* Nuvoton NPCM7XX Clock Controller

Nuvoton Poleg BMC NPCM7XX contains an integrated clock controller, which generates and supplies clocks to all modules within the BMC.

---

10 ==> 11
update documentation. "eth" replaced with "ethernet" in use case eaxample.

2 ==> 10
update documentation. add external clocks as inputs to clk driver. fix SPDX comment.

1 ==> 2
This patch includes fix request described here:
https://patchwork.kernel.org/patch/10200033/
(move fixed clocks to DT)

 .../bindings/clock/nuvoton,npcm750-clk.txt         | 100 +++++++++++++++++++++
 include/dt-bindings/clock/nuvoton,npcm7xx-clock.h  |  44 +++++++++
 2 files changed, 144 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/nuvoton,npcm750-clk.txt
 create mode 100644 include/dt-bindings/clock/nuvoton,npcm7xx-clock.h
Documentation/devicetree/bindings/clock/nuvoton,npcm750-clk.txt new file +100 -0
new file mode 100644
index 000000000000..f82064546d11
@@ -0,0 +1,100 @@
+* Nuvoton NPCM7XX Clock Controller
+
+Nuvoton Poleg BMC NPCM7XX contains an integrated clock controller, which
+generates and supplies clocks to all modules within the BMC.
+
+External clocks:
+
+There are six fixed clocks that are generated outside the BMC. All clocks are of
+a known fixed value that cannot be changed. clk_refclk, clk_mcbypck and
+clk_sysbypck are inputs to the clock controller.
+clk_rg1refck, clk_rg2refck and clk_xin are external clocks suppling the
+network. They are set on the device tree, but not used by the clock module. The
+network devices use them directly.
+Example can be found below.
+
+All available clocks are defined as preprocessor macros in:
+dt-bindings/clock/nuvoton,npcm7xx-clock.h
+and can be reused as DT sources.
+
+Required Properties of clock controller:
+
+	- compatible: "nuvoton,npcm750-clk" : for clock controller of Nuvoton
+		  Poleg BMC NPCM750
+
+	- reg: physical base address of the clock controller and length of
+		memory mapped region.
+
+	- #clock-cells: should be 1.
+
+Example: Clock controller node:
+
+	clk: clock-controller at f0801000 {
+		compatible = "nuvoton,npcm750-clk";
+		#clock-cells = <1>;
+		reg = <0xf0801000 0x1000>;
+		clock-names = "refclk", "sysbypck", "mcbypck";
+		clocks = <&clk_refclk>, <&clk_sysbypck>, <&clk_mcbypck>;
+	};
+
+Example: Required external clocks for network:
+
+	/* external reference clock */
+	clk_refclk: clk-refclk {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <25000000>;
+		clock-output-names = "refclk";
+	};
+
+	/* external reference clock for cpu. float in normal operation */
+	clk_sysbypck: clk-sysbypck {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <800000000>;
+		clock-output-names = "sysbypck";
+	};
+
+	/* external reference clock for MC. float in normal operation */
+	clk_mcbypck: clk-mcbypck {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <800000000>;
+		clock-output-names = "mcbypck";
+	};
+
+	 /* external clock signal rg1refck, supplied by the phy */
+	clk_rg1refck: clk-rg1refck {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <125000000>;
+		clock-output-names = "clk_rg1refck";
+	};
+
+	 /* external clock signal rg2refck, supplied by the phy */
+	clk_rg2refck: clk-rg2refck {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <125000000>;
+		clock-output-names = "clk_rg2refck";
+	};
+
+	clk_xin: clk-xin {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <50000000>;
+		clock-output-names = "clk_xin";
+	};
+
+
+Example: GMAC controller node that consumes two clocks: a generated clk by the
+clock controller and a fixed clock from DT (clk_rg1refck).
+
+	ethernet0: ethernet at f0802000 {
+		compatible = "snps,dwmac";
+		reg = <0xf0802000 0x2000>;
+		interrupts = <0 14 4>;
+		interrupt-names = "macirq";
+		clocks	= <&clk_rg1refck>, <&clk NPCM7XX_CLK_AHB>;
+		clock-names = "stmmaceth", "clk_gmac";
+	};
include/dt-bindings/clock/nuvoton,npcm7xx-clock.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.14.1
author maintainer
#3 lore raw

PATCH v11 2/2 clk: npcm7xx: Nuvoton NPCM7XX Clock Controller driver

In reply to [email protected]

From: Tali Perry <[email protected]>

* Nuvoton NPCM7XX Clock Controller

Nuvoton Poleg BMC NPCM7XX contains an integrated clock controller, which generates and supplies clocks to all modules within the BMC.

---

10 ==> 11
update documentation. "eth" replaced with "ethernet" in use case eaxample.

2 ==> 10
update documentation. add external clocks as inputs to clk driver. fix SPDX comment.

1 ==> 2
This patch includes fix request described here:
https://patchwork.kernel.org/patch/10200033/
(move fixed clocks to DT)

 drivers/clk/Makefile      |   1 +
 drivers/clk/clk-npcm7xx.c | 757 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 758 insertions(+)
 create mode 100644 drivers/clk/clk-npcm7xx.c
drivers/clk/Makefile +1 -0
index 71ec41e6364f..353e94f2c25a 100644
@@ -21,6 +21,7 @@ endif
 obj-$(CONFIG_MACH_ASM9260)		+= clk-asm9260.o
 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)	+= clk-axi-clkgen.o
 obj-$(CONFIG_ARCH_AXXIA)		+= clk-axm5516.o
+obj-$(CONFIG_ARCH_NPCM7XX)	    	+= clk-npcm7xx.o
 obj-$(CONFIG_COMMON_CLK_CDCE706)	+= clk-cdce706.o
 obj-$(CONFIG_COMMON_CLK_CDCE925)	+= clk-cdce925.o
 obj-$(CONFIG_ARCH_CLPS711X)		+= clk-clps711x.o
drivers/clk/clk-npcm7xx.c new file +757 -0

757 lines not on this page · raw message

Signature · 1 line
2.14.1
maintainer
#2 lore raw

Re: [PATCH v11 1/2] dt-binding: clk: npcm750: Add binding for Nuvoton NPCM7XX Clock

In reply to [email protected]

Quoting tali.perry1 at gmail.com (2018-03-20 06:40:48)

Quoted 16 lines

From: Tali Perry <[email protected]>

* Nuvoton NPCM7XX Clock Controller

Nuvoton Poleg BMC NPCM7XX contains an integrated clock controller, which generates and supplies clocks to all modules within the BMC.

---

10 ==> 11
update documentation. "eth" replaced with "ethernet" in use case eaxample.

2 ==> 10
update documentation. add external clocks as inputs to clk driver. fix SPDX comment.

Quoted 7 lines

1 ==> 2
This patch includes fix request described here:
https://patchwork.kernel.org/patch/10200033/
(move fixed clocks to DT)

But this part goes before the triple dash. I'll apply it and fix it up on clk-next.

maintainer
#4 lore raw

Re: [PATCH v11 2/2] clk: npcm7xx: Nuvoton NPCM7XX Clock Controller driver

In reply to [email protected]

Quoting tali.perry1 at gmail.com (2018-03-20 06:40:49)

drivers/clk/Makefile endif · line 24

Quoted 9 lines
drivers/clk/Makefile +1 -0
index 71ec41e6364f..353e94f2c25a 100644
@@ -21,6 +21,7 @@ endif
 obj-$(CONFIG_MACH_ASM9260)             += clk-asm9260.o
 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)    += clk-axi-clkgen.o
 obj-$(CONFIG_ARCH_AXXIA)               += clk-axm5516.o
+obj-$(CONFIG_ARCH_NPCM7XX)             += clk-npcm7xx.o

Please sort this by filename, not config name.

Quoted 12 lines
drivers/clk/Makefile +0 -0
 obj-$(CONFIG_COMMON_CLK_CDCE706)       += clk-cdce706.o
 obj-$(CONFIG_COMMON_CLK_CDCE925)       += clk-cdce925.o
 obj-$(CONFIG_ARCH_CLPS711X)            += clk-clps711x.o
drivers/clk/clk-npcm7xx.c new file +3 -0
new file mode 100644
index 000000000000..0d373f8f114b
@@ -0,0 +1,757 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Nuvoton NPCM7xx Clock Generator

[..]

drivers/clk/clk-npcm7xx.c line 562

Quoted 4 lines
drivers/clk/clk-npcm7xx.c new file +4 -0
+
+
+static struct clk_hw_onecell_data *npcm7xx_clk_data;
+static void __iomem *clk_base;

Please remove static singletons and allocate them during init.

Quoted 1 line

+static DEFINE_SPINLOCK(lock);

Please give 'lock' a better name so that lockdep reports are meaningful.

drivers/clk/clk-npcm7xx.c line 571

Quoted 8 lines
drivers/clk/clk-npcm7xx.c new file +8 -0
+
+
+static const struct of_device_id npcm7xx_clk_match_table[] = {
+                               { .compatible = "nuvoton,npcm750-clk"},
+                               {},
+};
+
+MODULE_DEVICE_TABLE(of, npcm7xx_clk_match_table);

Is this used?

Quoted 27 lines
drivers/clk/clk-npcm7xx.c new file +27 -0
+
+
+static void __init npcm7xx_clk_init(struct device_node *clk_np)
+{
+
+       struct resource res;
+       struct clk_hw *hw;
+       struct clk *clk;
+       int ret;
+       int i;
+
+       pr_debug("NPCM750: clock init: ");
+
+       clk_base = NULL;
+
+       ret = of_address_to_resource(clk_np, 0, &res);
+       if (ret) {
+               pr_err("\t%s: failed to get resource, ret %d\n", clk_np->name,
+                       ret);
+               return;
+       }
+
+
+       clk_base = ioremap(res.start, resource_size(&res));
+       if (IS_ERR(clk_base)) {
+               pr_err("\tnpcm7xx_clk_init: resource error\n");
+               goto npcm7xx_init_error;

drivers/clk/clk-npcm7xx.c line 608

Quoted 10 lines
drivers/clk/clk-npcm7xx.c new file +10 -0
+       }
+
+
+       npcm7xx_clk_data = kzalloc(sizeof(*npcm7xx_clk_data->hws) *
+               NPCM7XX_NUM_CLOCKS + sizeof(npcm7xx_clk_data), GFP_KERNEL);
+
+       npcm7xx_clk_data->num = 0;
+
+       if (!npcm7xx_clk_data->hws) {
+               pr_err("Can't alloc npcm7xx_clk_data\n");

We don't need allocation error messages, kmalloc already prints a bunch of info.

drivers/clk/clk-npcm7xx.c line 616

Quoted 8 lines
drivers/clk/clk-npcm7xx.c new file +8 -0
+               goto npcm7xx_init_np_err;
+       }
+
+       npcm7xx_clk_data->num = NPCM7XX_NUM_CLOCKS;
+
+
+       /*
+        * This way all clock fetched before the platform device probes,

What platform device?

Quoted 88 lines
drivers/clk/clk-npcm7xx.c new file +88 -0
+        * except those we assign here for early use, will be deferred.
+        */
+       pr_debug("\tclk init hws\n");
+       for (i = 0; i < NPCM7XX_NUM_CLOCKS; i++)
+               npcm7xx_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
+
+       /* Read fixed clocks. These 3 clocks must be defined in DT */
+       clk = of_clk_get_by_name(clk_np, NPCM7XX_CLK_S_REFCLK);
+       if (!IS_ERR(clk)) {
+               pr_err("failed to find external REFCLK: %ld\n",
+                       PTR_ERR(clk));
+               clk_put(clk);
+       }
+
+       clk = of_clk_get_by_name(clk_np, NPCM7XX_CLK_S_SYSBYPCK);
+       if (!IS_ERR(clk)) {
+               pr_err("failed to find external SYSBYPCK: %ld\n",
+                       PTR_ERR(clk));
+               clk_put(clk);
+       }
+
+       clk = of_clk_get_by_name(clk_np, NPCM7XX_CLK_S_MCBYPCK);
+       if (!IS_ERR(clk)) {
+               pr_err("failed to find external MCBYPCK: %ld\n",
+                       PTR_ERR(clk));
+               clk_put(clk);
+       }
+
+       /* Register plls */
+       pr_debug("\tclk register pll\n");
+       for (i = 0; i < ARRAY_SIZE(npcm7xx_plls); i++) {
+               const struct npcm7xx_clk_pll_data *pll_data = &npcm7xx_plls[i];
+
+               pr_debug("\tclk reg pll%d, reg=0x%x, name=%s, p=%s\n", i,
+               (unsigned int)pll_data->reg, pll_data->name,
+               pll_data->parent_name);
+
+               hw = npcm7xx_clk_register_pll(clk_base + pll_data->reg,
+                       pll_data->name, pll_data->parent_name, pll_data->flags);
+               if (IS_ERR(hw)) {
+                       pr_err("npcm7xx_clk: Can't register pll\n");
+                       goto npcm7xx_init_fail;
+               }
+
+               if (pll_data->onecell_idx >= 0)
+                       npcm7xx_clk_data->hws[pll_data->onecell_idx] = hw;
+       }
+
+       /* Register fixed dividers */
+       pr_debug("\tclk register fixed divs\n");
+       clk = clk_register_fixed_factor(NULL, NPCM7XX_CLK_S_PLL1_DIV2,
+                       NPCM7XX_CLK_S_PLL1, 0, 1, 2);
+       if (IS_ERR(clk)) {
+               pr_err("npcm7xx_clk: Can't register fixed div\n");
+               goto npcm7xx_init_fail;
+       }
+
+
+       clk = clk_register_fixed_factor(NULL, NPCM7XX_CLK_S_PLL2_DIV2,
+                       NPCM7XX_CLK_S_PLL2, 0, 1, 2);
+
+       if (IS_ERR(clk)) {
+               pr_err("npcm7xx_clk: Can't register div2\n");
+               goto npcm7xx_init_fail;
+       }
+
+       /* Register muxes */
+       for (i = 0; i < ARRAY_SIZE(npcm7xx_muxes); i++) {
+               const struct npcm7xx_clk_mux_data *mux_data = &npcm7xx_muxes[i];
+
+               pr_debug("\tadd mux%d reg=0x%x name=%s p=%s num_p=%d\n",
+                   i, ((u32)clk_base + (u32)NPCM7XX_CLKSEL), mux_data->name,
+                       mux_data->parent_names[0], mux_data->num_parents);
+
+               hw = clk_hw_register_mux_table(NULL,
+                       mux_data->name,
+                       mux_data->parent_names, mux_data->num_parents,
+                       mux_data->flags, clk_base + NPCM7XX_CLKSEL,
+                       mux_data->shift, mux_data->mask, 0,
+                       mux_data->table, &lock);
+
+               if (IS_ERR(hw)) {
+                       pr_err("npcm7xx_clk: Can't register mux\n");
+                       goto npcm7xx_init_fail;
+               }
+
+               if (mux_data->onecell_idx >= 0)
+                       npcm7xx_clk_data->hws[mux_data->onecell_idx] = hw;

drivers/clk/clk-npcm7xx.c line 714

Quoted 10 lines
drivers/clk/clk-npcm7xx.c new file +10 -0
+       }
+
+       /* Register clock dividers specified in npcm7xx_divs. */
+       pr_debug("\tclk register divs\n");
+       for (i = 0; i < ARRAY_SIZE(npcm7xx_divs); i++) {
+               const struct npcm7xx_clk_div_data *div_data = &npcm7xx_divs[i];
+
+               pr_debug("\tadd div%d reg=0x%x name=%s, parent=%s\n",
+                               i, (unsigned int)div_data->reg,
+                               div_data->name, div_data->parent_name);

Please remove all these debug prints.

Quoted 14 lines
drivers/clk/clk-npcm7xx.c new file +14 -0
+
+               hw = clk_hw_register_divider(NULL, div_data->name,
+                               div_data->parent_name,
+                               div_data->flags,
+                               clk_base + div_data->reg,
+                               div_data->shift, div_data->width,
+                               div_data->clk_divider_flags, &lock);
+               if (IS_ERR(hw)) {
+                       pr_err("npcm7xx_clk: Can't register div table\n");
+                       goto npcm7xx_init_fail;
+               }
+
+               if (div_data->onecell_idx >= 0)
+                       npcm7xx_clk_data->hws[div_data->onecell_idx] = hw;

drivers/clk/clk-npcm7xx.c line 738

Quoted 10 lines
drivers/clk/clk-npcm7xx.c new file +10 -0
+       }
+
+       ret = of_clk_add_hw_provider(clk_np, of_clk_hw_onecell_get,
+                                       npcm7xx_clk_data);
+       if (ret)
+               pr_err("failed to add DT provider: %d\n", ret);
+
+       pr_info("npcm7xx clk: %d dividers, %d muxes and %d plls registered.\n",
+               ARRAY_SIZE(npcm7xx_divs), ARRAY_SIZE(npcm7xx_muxes),
+               ARRAY_SIZE(npcm7xx_plls));

Please remove this "I'm alive!" message.

drivers/clk/clk-npcm7xx.c line 745

Quoted 7 lines
drivers/clk/clk-npcm7xx.c new file +7 -0
+
+       of_node_put(clk_np);
+
+       return;
+
+npcm7xx_init_fail:
+       pr_debug("\tclk setup fail\n");

Please don't put tabs at the beginning of printks.

drivers/clk/clk-npcm7xx.c line 755

Quoted 10 lines
drivers/clk/clk-npcm7xx.c new file +10 -0
+       if (npcm7xx_clk_data->num)
+               kfree(npcm7xx_clk_data->hws);
+npcm7xx_init_np_err:
+       if (clk_base != NULL)
+               iounmap(clk_base);
+npcm7xx_init_error:
+       of_node_put(clk_np);
+}
+
+CLK_OF_DECLARE(npcm7xx_clk_init, "nuvoton,npcm750-clk", npcm7xx_clk_init);

Any reason this can't be a platform driver?