clk: hisilicon: support stub clock
Subsystems (2)
cover clk: hisilicon: support stub clock
This series adds support for hisilicon stub clock driver. On hi6220, the bootloader needs load the firmware image and set info for OPPs; after run into kernel, the stub clock driver is used to communicate w/t firmware for cpu dynamic frequency scaling. So finally s/w will simply write request in sram and send ipc to power controller.
These patches have been tested on 96board hikey and will be used by cpufreq driver.
Leo Yan (4):
clk: hisi: add API for allocation clk data struct
dt-bindings: clk: hisilicon: Document stub clock driver
clk: hisi: add stub clk driver
clk: hisi: add stub clock register function
.../devicetree/bindings/clock/hisi,stub-clock.txt | 38 +++ drivers/clk/hisilicon/Makefile | 2 +- drivers/clk/hisilicon/clk-stub.c | 284 +++++++++++++++++++++ drivers/clk/hisilicon/clk.c | 71 ++++-- drivers/clk/hisilicon/clk.h | 17 ++ include/dt-bindings/clock/hisi,stub-clock.h | 26 ++ 6 files changed, 422 insertions(+), 16 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/hisi,stub-clock.txt create mode 100644 drivers/clk/hisilicon/clk-stub.c create mode 100644 include/dt-bindings/clock/hisi,stub-clock.h
Signature · 1 line
1.9.1
PATCH 1/4 clk: hisi: add API for allocation clk data struct
In the old clk init function, it will read the register base address from dts and allocate the clk data structures. But for the some cases, the clock driver don't need init the reg's base address, which will directly access mmio region with syscon.
So for clock's initialization, this patch adds one more API which is only for allocating clock data structure.
--- drivers/clk/hisilicon/clk.c | 42 +++++++++++++++++++++++++++--------------- drivers/clk/hisilicon/clk.h | 2 ++ 2 files changed, 29 insertions(+), 15 deletions(-)
drivers/clk/hisilicon/clk.c +27 -15
@@ -38,30 +38,17 @@static DEFINE_SPINLOCK (hisi_clk_lock); -struct hisi_clock_data __init *hisi_clk_init (struct device_node *np, -int nr_clks) +struct hisi_clock_data __init *hisi_clk_alloc_data (struct device_node *np, +int nr_clks) {struct hisi_clock_data *clk_data;struct clk **clk_table; -void __iomem *base; - -if (np) { - base =of_iomap (np,0 ); -if (!base) { -pr_err ("failed to map Hisilicon clock registers\n" ); - goto err; - } - }else { -pr_err ("failed to find Hisilicon clock node in DTS\n" ); - goto err; - } clk_data =kzalloc (sizeof (*clk_data),GFP_KERNEL );if (!clk_data) {pr_err ("%s: could not allocate clock data\n" , __func__); goto err; } - clk_data->base = base; clk_table =kzalloc (sizeof (struct clk *) * nr_clks,GFP_KERNEL );if (!clk_table) {
@@ -72,12 +59,37 @@ struct hisi_clock_data __init *hisi_clk_init(struct device_node *np, clk_data->clk_data.clk_num = nr_clks;of_clk_add_provider (np, of_clk_src_onecell_get, &clk_data->clk_data);return clk_data; + err_data:kfree (clk_data); err:return NULL ; } +struct hisi_clock_data __init *hisi_clk_init (struct device_node *np, +int nr_clks) +{ +struct hisi_clock_data *clk_data; +void __iomem *base; + +if (np) { + base =of_iomap (np,0 ); +if (!base) { +pr_err ("failed to map Hisilicon clock registers\n" ); +return NULL ; + } +printk ("%s: base %p\n" , __func__, base); + }else { +pr_err ("failed to find Hisilicon clock node in DTS\n" ); +return NULL ; + } + + clk_data =hisi_clk_alloc_data (np, nr_clks); +if (clk_data) + clk_data->base = base; +return clk_data; +} +void __init hisi_clk_register_fixed_rate (struct hisi_fixed_rate_clock *clks,int nums,struct hisi_clock_data *data) {
drivers/clk/hisilicon/clk.h +2 -0
@@ -96,6 +96,8 @@ struct clk *hisi_register_clkgate_sep(struct device *, const char *, u8, spinlock_t *);struct hisi_clock_data __init *hisi_clk_init (struct device_node *,int ); +struct hisi_clock_data __init *hisi_clk_alloc_data (struct device_node *np, +int nr_clks);void __init hisi_clk_register_fixed_rate (struct hisi_fixed_rate_clock *,int ,struct hisi_clock_data *); void __init hisi_clk_register_fixed_factor(struct hisi_fixed_factor_clock *,
Signature · 1 line
1.9.1
PATCH 1/4 clk: hisi: add API for allocation clk data struct
drivers/clk/hisilicon/clk.c struct hisi_clock_data __init *hisi_clk_init(struct device_node *np, · line 81
Quoted 13 lines · Leo Yan
drivers/clk/hisilicon/clk.c +13
-0+struct hisi_clock_data __init *hisi_clk_init (struct device_node *np, +int nr_clks) +{ +struct hisi_clock_data *clk_data; +void __iomem *base; + +if (np) { + base =of_iomap (np,0 ); +if (!base) { +pr_err ("failed to map Hisilicon clock registers\n" ); +return NULL ; + } +printk ("%s: base %p\n" , __func__, base);
Did you leave your debugging in?
drivers/clk/hisilicon/clk.c struct hisi_clock_data __init *hisi_clk_init(struct device_node *np, · line 85
Quoted 4 lines
drivers/clk/hisilicon/clk.c +4
-0+ }else { +pr_err ("failed to find Hisilicon clock node in DTS\n" ); +return NULL ; + }
I know you're mostly only moving this code, but it would be far better if it were written:
if (!np) {
pr_err("failed to find Hisilicon clock node in DTS\n");
return NULL;
}
base = of_iomap(np, 0);
if (!base) {
pr_err("failed to map Hisilicon clock registers\n");
return NULL;
}Possibly do this first as a separate patch, and then move the code.
Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up according to speedtest.net.
PATCH 1/4 clk: hisi: add API for allocation clk data struct
hi Russell,
Quoted 16 lines · Russell King - ARM Linux
drivers/clk/hisilicon/clk.c struct hisi_clock_data __init *hisi_clk_init(struct device_node *np, · line 81
Quoted 13 lines · Leo Yan
drivers/clk/hisilicon/clk.c +13
-0+struct hisi_clock_data __init *hisi_clk_init (struct device_node *np, +int nr_clks) +{ +struct hisi_clock_data *clk_data; +void __iomem *base; + +if (np) { + base =of_iomap (np,0 ); +if (!base) { +pr_err ("failed to map Hisilicon clock registers\n" ); +return NULL ; + } +printk ("%s: base %p\n" , __func__, base);Did you leave your debugging in?
Sorry, will remove it.
Quoted 19 lines
drivers/clk/hisilicon/clk.c struct hisi_clock_data __init *hisi_clk_init(struct device_node *np, · line 85
Quoted 4 lines
drivers/clk/hisilicon/clk.c +4
-0+ }else { +pr_err ("failed to find Hisilicon clock node in DTS\n" ); +return NULL ; + }I know you're mostly only moving this code, but it would be far better if it were written:
if (!np) { pr_err("failed to find Hisilicon clock node in DTS\n"); return NULL; } base = of_iomap(np, 0); if (!base) { pr_err("failed to map Hisilicon clock registers\n"); return NULL; }
Quoted 1 line
Possibly do this first as a separate patch, and then move the code.
Will do this.
Quoted 3 lines
Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up according to speedtest.net.
PATCH 2/4 dt-bindings: clk: hisilicon: Document stub clock driver
In reply to Leo YanDocument the new compatible for stub clock driver which is used for CPU and DDR's dynamic frequency scaling.
--- .../devicetree/bindings/clock/hisi,stub-clock.txt | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/hisi,stub-clock.txt
Documentation/devicetree/bindings/clock/hisi,stub-clock.txt new file +38 -0
@@ -0,0 +1,38 @@ +* Clock bindings for Hisilicon Stub Clock Driver + +The Hisilicon stub clock will directly send dynamic frequency scaling request +to power controller, then the power controller will handle the request for +cpu and ddr's frequency change. + +Required properties: +- compatible: must be "hisilicon,hisi-clock-stub" +- hisilicon,clk-stub-sram: phandle to the syscon managing the SoC internal sram; + the driver need use the sram to pass parameters for frequency change. +- hisilicon,clk-stub-mc: phandle to the syscon managing the multi-cores' + communication; need set related register to trigger the dynamic frequency + scaling. +- #clock-cells: should be <1> + +Each clock is assigned an identifier and client nodes use this identifier +to specify the clock which they consume. + +All these identifier could be found in <dt-bindings/clock/hisi,stub-clock.h>. + +Example: + + sram: sram { + compatible = "hisilicon,sram", "syscon"; + reg = <0x0 0xFFF80000 0x0 0x12000>; + }; + + ipc_s: ipc_s { + compatible = "hisilicon,ipc-s", "syscon"; + reg = <0x0 0xF7510000 0x0 0x1000>; + }; + + clock_stub: clock_stub { + compatible = "hisilicon,hisi-clock-stub"; + hisilicon,clk-stub-sram = <&sram>; + hisilicon,clk-stub-mc = <&ipc_s>; + #clock-cells = <1>; + };
Signature · 1 line
1.9.1
PATCH 3/4 clk: hisi: add stub clk driver
In reply to Leo YanOn hisilicon platform, there have some clocks which can directly send messages to power controller to change frequency; this includes cpu and ddr's clocks.
For dynamic frequency scaling, firstly need write the frequency value to sram region, and then write the communication register to trigger power controller to run the state machine. These two part's addresses are different and will be shared w/t other module; so use syscon APIs to pass these two memory region and accessing related registers.
This init driver will support cpu frequency change firstly.
--- drivers/clk/hisilicon/Makefile | 2 +- drivers/clk/hisilicon/clk-stub.c | 284 ++++++++++++++++++++++++++++ drivers/clk/hisilicon/clk.h | 3 + include/dt-bindings/clock/hisi,stub-clock.h | 26 +++ 4 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/hisilicon/clk-stub.c create mode 100644 include/dt-bindings/clock/hisi,stub-clock.h
drivers/clk/hisilicon/Makefile +1 -1
@@ -2,7 +2,7 @@ # Hisilicon Clock specific Makefile # -obj-y += clk.o clkgate-separated.o +obj-y += clk.o clkgate-separated.o clk-stub.o obj-$(CONFIG_ARCH_HI3xxx) += clk-hi3620.o obj-$(CONFIG_ARCH_HIP04) += clk-hip04.o
drivers/clk/hisilicon/clk-stub.c new file +284 -0
284 lines not on this page · raw message
drivers/clk/hisilicon/clk.h +3 -0
@@ -94,6 +94,9 @@ struct clk *hisi_register_clkgate_sep(struct device *, const char *, const char *, unsigned long, void __iomem *, u8, u8, spinlock_t *); +struct clk *hisi_register_stub_clk (struct device_node *np, +unsigned int id,const char *name,const char *parent_name, +unsigned long flags,spinlock_t *lock);struct hisi_clock_data __init *hisi_clk_init (struct device_node *,int ); struct hisi_clock_data __init *hisi_clk_alloc_data(struct device_node *np,
include/dt-bindings/clock/hisi,stub-clock.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* This header provides constants for Hisilicon stub clock driver. +* +* Copyright (c) 2015 Hisilicon Limited. +* Copyright (c) 2015 Linaro Limited. +* +* Author: Leo Yan <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef _DT_BINDINGS_HISI_STUB_CLOCK_H +#define _DT_BINDINGS_HISI_STUB_CLOCK_H + +/* Stub Clocks */ +#define HISI_STUB_ACPU0 0 +#define HISI_STUB_ACPU1 1 +#define HISI_STUB_GPU 2 +#define HISI_STUB_DDR_MIN 3 +#define HISI_STUB_DDR_MAX 4 +#define HISI_STUB_DDR 5 +#define HISI_STUB_NR_CLKS 6 + +#endif /* _DT_BINDINGS_HISI_STUB_CLOCK_H */
Signature · 1 line
1.9.1
PATCH 3/4 clk: hisi: add stub clk driver
Quoted 3 lines · Leo Yan
drivers/clk/hisilicon/clk-stub.c new file +3
-0+static unsigned long hisi_stub_clk_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{
...
Quoted 1 line
(quoted diff) +1
-0+ BUG_ON(!stub_clk->lock);
...
Quoted 3 lines
drivers/clk/hisilicon/clk-stub.c new file +3
-0+static int hisi_stub_clk_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{
...
Quoted 1 line
(quoted diff) +1
-0+ BUG_ON(!stub_clk->lock);
...
Quoted 3 lines
drivers/clk/hisilicon/clk-stub.c new file +3
-0+static long hisi_stub_clk_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{
...
Quoted 1 line
(quoted diff) +1
-0+ BUG_ON(!stub_clk->lock);
...
Quoted 5 lines
drivers/clk/hisilicon/clk-stub.c new file +5
-0+static struct clk_ops hisi_stub_clk_ops = { + .recalc_rate = hisi_stub_clk_recalc_rate, + .round_rate = hisi_stub_clk_round_rate, + .set_rate = hisi_stub_clk_set_rate, +};
...
Quoted 13 lines
drivers/clk/hisilicon/clk-stub.c new file +13
-0+static struct clk *_register_stub_clk (struct device *dev,unsigned int id, +const char *name,const char *parent_name,unsigned long flags, +spinlock_t *lock) +{ +struct hisi_stub_clk *stub_clk; +struct clk *clk; +struct clk_init_data init; + + stub_clk =kzalloc (sizeof (*stub_clk),GFP_KERNEL ); +if (!stub_clk) { +pr_err ("%s: fail to alloc stub clk!\n" , __func__); +return ERR_PTR (-ENOMEM ); + }
drivers/clk/hisilicon/clk-stub.c line 254
Quoted 10 lines
drivers/clk/hisilicon/clk-stub.c new file +10
-0+ + init.name = name; + init.ops = &hisi_stub_clk_ops; + init.parent_names = parent_name ? &parent_name :NULL ; + init.num_parents = parent_name ?1 :0 ; + init.flags = flags; + + stub_clk->hw.init = &init; + stub_clk->id = id; + stub_clk->lock = lock;
Under what scenario is it safe to call _register_stub_clk() with a NULL lock argument?
If lock is NULL, then every function callable via the ops structure will bug.
Rather than doing a test in each method function, do it in _register_stub_clk() - this means we aren't waiting for a NULL pointer deref when one of these method functions gets called.
Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up according to speedtest.net.
PATCH 3/4 clk: hisi: add stub clk driver
Quoted 55 lines · Russell King - ARM Linux
Quoted 3 lines · Leo Yan
drivers/clk/hisilicon/clk-stub.c new file +3
-0+static unsigned long hisi_stub_clk_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{...
Quoted 1 line
(quoted diff) +1
-0+ BUG_ON(!stub_clk->lock);...
Quoted 3 lines
drivers/clk/hisilicon/clk-stub.c new file +3
-0+static int hisi_stub_clk_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{...
Quoted 1 line
(quoted diff) +1
-0+ BUG_ON(!stub_clk->lock);...
Quoted 3 lines
drivers/clk/hisilicon/clk-stub.c new file +3
-0+static long hisi_stub_clk_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *parent_rate) +{...
Quoted 1 line
(quoted diff) +1
-0+ BUG_ON(!stub_clk->lock);...
Quoted 5 lines
drivers/clk/hisilicon/clk-stub.c new file +5
-0+static struct clk_ops hisi_stub_clk_ops = { + .recalc_rate = hisi_stub_clk_recalc_rate, + .round_rate = hisi_stub_clk_round_rate, + .set_rate = hisi_stub_clk_set_rate, +};...
Quoted 13 lines
drivers/clk/hisilicon/clk-stub.c new file +13
-0+static struct clk *_register_stub_clk (struct device *dev,unsigned int id, +const char *name,const char *parent_name,unsigned long flags, +spinlock_t *lock) +{ +struct hisi_stub_clk *stub_clk; +struct clk *clk; +struct clk_init_data init; + + stub_clk =kzalloc (sizeof (*stub_clk),GFP_KERNEL ); +if (!stub_clk) { +pr_err ("%s: fail to alloc stub clk!\n" , __func__); +return ERR_PTR (-ENOMEM ); + }drivers/clk/hisilicon/clk-stub.c line 254
Quoted 10 lines
drivers/clk/hisilicon/clk-stub.c new file +10
-0+ + init.name = name; + init.ops = &hisi_stub_clk_ops; + init.parent_names = parent_name ? &parent_name :NULL ; + init.num_parents = parent_name ?1 :0 ; + init.flags = flags; + + stub_clk->hw.init = &init; + stub_clk->id = id; + stub_clk->lock = lock;Under what scenario is it safe to call
_register_stub_clk()with a NULL lock argument?
Quoted 6 lines
If lock is NULL, then every function callable via the ops structure will bug.
Rather than doing a test in each method function, do it in
_register_stub_clk()- this means we aren't waiting for a NULL pointer deref when one of these method functions gets called.
Will fix to check lock pointer in the function _register_stub_clk().
Thanks,
Leo Yan
PATCH 4/4 clk: hisi: add stub clock register function
In reply to Leo YanAdd stub clock register function, so can easily enable stub clock for platforms.
--- drivers/clk/hisilicon/clk.c | 29 +++++++++++++++++++++++++++++ drivers/clk/hisilicon/clk.h | 12 ++++++++++++ 2 files changed, 41 insertions(+)
drivers/clk/hisilicon/clk.c +29 -0
@@ -244,3 +244,32 @@ void __init hisi_clk_register_gate_sep(struct hisi_gate_clock *clks, data->clk_data.clks[clks[i].id] = clk; } } + +void __init hisi_clk_register_stub (struct hisi_stub_clock *clks,int nums, +struct hisi_clock_data *data, +struct device_node *np) +{ +struct clk *clk; +int i; + +for (i =0 ; i < nums; i++) { + clk =hisi_register_stub_clk (np, + clks[i].id, + clks[i].name, + clks[i].parent_name, + clks[i].flags, + &hisi_clk_lock); +if (IS_ERR (clk)) { +pr_err ("%s: failed to register clock %s\n" , + __func__, clks[i].name); +continue ; + } + +if (clks[i].alias) +clk_register_clkdev (clk, clks[i].name,NULL ); + + data->clk_data.clks[clks[i].id] = clk; + } + +return ; +}
drivers/clk/hisilicon/clk.h +12 -0
@@ -90,6 +90,14 @@ struct hisi_gate_clock {const char *alias; }; +struct hisi_stub_clock { +unsigned int id; +char *name; +const char *parent_name; +unsigned long flags; +const char *alias; +}; + struct clk *hisi_register_clkgate_sep(struct device *, const char *, const char *, unsigned long, void __iomem *, u8,
@@ -113,4 +121,8 @@ void __init hisi_clk_register_gate(struct hisi_gate_clock *, int, struct hisi_clock_data *);void __init hisi_clk_register_gate_sep (struct hisi_gate_clock *,int ,struct hisi_clock_data *); +void __init hisi_clk_register_stub (struct hisi_stub_clock *clks,int nums, +struct hisi_clock_data *data, +struct device_node *np); +#endif /* __HISI_CLK_H */
Signature · 1 line
1.9.1