clk: meson: use regmap in clock controllers
Jerome Brunet
maintainercover clk: meson: use regmap in clock controllers
This changeset is a rework of meson's clock controllers to use regmap instead of directly using io memory. It based clk-meson next/drivers and depends on few core clock patches, mainly to export generic clocks
helpers: [0],[1]. The line count is pretty high but the changes are actually fairly simple and repetitive.
This work has been triggered by the fact that the HHI register space on gxbb and axg provides more than just clocks. The display driver already uses a syscon for HHI on gxbb. This is why gxbb did not use devm_ioremap_resource() to map the registers, since it would have reserved the memory region, preventing another driver from re-mapping it. The cleaner solution is, of course, to use syscon to handle. The purpose of this changeset is to allow it. Even if meson8b does not need this ATM, there is real reason to leave it behind. It is actually easier to migrate it as well, so all meson clock drivers may support regmap only.
The rework starts with a few easy clean-ups. The real deal starts with patch 5, which adds meson's clk_regmap. This will be used as common structure to implement all the controller clocks. Having this replaces the gxbb AO controller specific regmap gate. This structure will also be re-used in upcoming controllers, such as the axg's AO and audio controllers. Each clock type is then migrated, one at a time, to this new structure.
While at it, the meson clock drivers have been cleaned-up a bit, removing the gate embedded in the mpll driver, simplifying the pll driver and removing the legacy cpu_clk of meson8b The new code around the cpu clk of the meson8b is just re-implementation, using simple elements, of the old cpu_clk. What was failing before is still expected to fail now. Apparently this clock will need a bit more love to enable dvfs on meson8b. BTW, thanks a lot to Martin for trying this rework as early as he did !!
With this series applied, the clock controllers of the gxbb, gxl and axg SoC will try get regmap from their parent DT node. If this fails, they will fallback to mapping the register themselves. This fallback will be kept until platform DTs have changed so clock controllers is a child of the HHI system controller.
Based on this changeset, more patches are coming. For those interested, the WIP is available here [2]
[0]: https://lkml.kernel.org/r/20180118110144.30619-1-jbrunet at baylibre.com [1]: https://lkml.kernel.org/r/20180122105759.12206-1-jbrunet at baylibre.com [2]: https://github.com/jeromebrunet/linux/tree/v4.16/meson/clk-regmap
Jerome Brunet (19):
clk: meson: use dev pointer where possible
clk: meson: use devm_of_clk_add_hw_provider
clk: meson: only one loop index is necessary in probe
clk: meson: remove obsolete comments
clk: meson: add regmap clocks
clk: meson: switch gxbb ao_clk to clk_regmap
clk: meson: remove superseded aoclk_gate_regmap
clk: meson: add regmap to the clock controllers
clk: meson: migrate gates to clk_regmap
clk: meson: migrate dividers to clk_regmap
clk: meson: migrate muxes to clk_regmap
clk: meson: add regmap helpers for parm
clk: meson: migrate mplls clocks to clk_regmap
clk: meson: migrate the audio divider clock to clk_regmap
clk: meson: migrate plls clocks to clk_regmap
clk: meson: split divider and gate part of mpll
clk: meson: rework meson8b cpu clock
clk: meson: remove obsolete cpu_clk
clk: meson: use hhi syscon if available
drivers/clk/meson/Kconfig | 9 + drivers/clk/meson/Makefile | 5 +- drivers/clk/meson/axg.c | 722 +++++++++-------- drivers/clk/meson/axg.h | 6 +- drivers/clk/meson/clk-audio-divider.c | 63 +- drivers/clk/meson/clk-cpu.c | 178 ----- drivers/clk/meson/clk-mpll.c | 132 +--- drivers/clk/meson/clk-pll.c | 243 +++--- drivers/clk/meson/clk-regmap.c | 166 ++++ drivers/clk/meson/clk-regmap.h | 111 +++ drivers/clk/meson/clkc.h | 93 +-- drivers/clk/meson/gxbb-aoclk-regmap.c | 46 -- drivers/clk/meson/gxbb-aoclk.c | 20 +- drivers/clk/meson/gxbb-aoclk.h | 11 - drivers/clk/meson/gxbb.c | 1399 ++++++++++++++++++--------------- drivers/clk/meson/gxbb.h | 5 +- drivers/clk/meson/meson8b.c | 612 ++++++++------ drivers/clk/meson/meson8b.h | 11 +- 18 files changed, 2016 insertions(+), 1816 deletions(-) delete mode 100644 drivers/clk/meson/clk-cpu.c create mode 100644 drivers/clk/meson/clk-regmap.c create mode 100644 drivers/clk/meson/clk-regmap.h delete mode 100644 drivers/clk/meson/gxbb-aoclk-regmap.c
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 1/19 clk: meson: use dev pointer where possible
The 'dev' pointer is directly available in gxbb and axg clock controller, so consistently use it instead of going the through the 'pdev' pointer once in while
--- drivers/clk/meson/axg.c | 8 ++++---- drivers/clk/meson/gxbb.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/clk/meson/axg.c +4 -4
@@ -804,7 +804,7 @@ static int axg_clkc_probe(struct platform_device *pdev)void __iomem *clk_base;int ret, clkid, i; - clkc_data =of_device_get_match_data (&pdev->dev); + clkc_data =of_device_get_match_data (dev);if (!clkc_data)return -EINVAL ;
@@ -812,9 +812,9 @@ static int axg_clkc_probe(struct platform_device *pdev) res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res)return -EINVAL ; - clk_base =devm_ioremap (&pdev->dev, res->start,resource_size (res)); + clk_base =devm_ioremap (dev, res->start,resource_size (res));if (!clk_base) { -dev_err (&pdev->dev,"Unable to map clk base\n" ); +dev_err (dev,"Unable to map clk base\n" );return -ENXIO ; }
@@ -849,7 +849,7 @@ static int axg_clkc_probe(struct platform_device *pdev) ret =devm_clk_hw_register (dev, clkc_data->hw_onecell_data->hws[clkid]);if (ret) { -dev_err (&pdev->dev,"Clock registration failed\n" ); +dev_err (dev,"Clock registration failed\n" );return ret; } }
drivers/clk/meson/gxbb.c +1 -1
@@ -1950,7 +1950,7 @@ static int gxbb_clkc_probe(struct platform_device *pdev)int ret, clkid, i;struct device *dev = &pdev->dev; - clkc_data =of_device_get_match_data (&pdev->dev); + clkc_data =of_device_get_match_data (dev);if (!clkc_data)return -EINVAL ;
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 2/19 clk: meson: use devm_of_clk_add_hw_provider
In reply to Jerome BrunetThere is no remove callbacks in meson's clock controllers and of_clk_del_provider is never called if of_clk_add_hw_provider has been executed, introducing a potential memory leak.
Fixing this by the using the devm variant.
In reality, the leak would never happen since these controllers are never unloaded once in use ... still, this is worth cleaning.
--- drivers/clk/meson/axg.c | 4 ++-- drivers/clk/meson/gxbb.c | 5 +++-- drivers/clk/meson/meson8b.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-)
drivers/clk/meson/axg.c +2 -2
@@ -854,8 +854,8 @@ static int axg_clkc_probe(struct platform_device *pdev) } } -return of_clk_add_hw_provider (dev->of_node, of_clk_hw_onecell_get, - clkc_data->hw_onecell_data); +return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, + clkc_data->hw_onecell_data); }static struct platform_driver axg_driver = {
drivers/clk/meson/gxbb.c +3 -2
@@ -2002,8 +2002,9 @@ static int gxbb_clkc_probe(struct platform_device *pdev) goto iounmap; } -return of_clk_add_hw_provider (dev->of_node, of_clk_hw_onecell_get, - clkc_data->hw_onecell_data); + +return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, + clkc_data->hw_onecell_data); iounmap:iounmap (clk_base);
drivers/clk/meson/meson8b.c +2 -2
@@ -878,8 +878,8 @@ static int meson8b_clkc_probe(struct platform_device *pdev)return ret; } -return of_clk_add_hw_provider (dev->of_node, of_clk_hw_onecell_get, - &meson8b_hw_onecell_data); +return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, + &meson8b_hw_onecell_data); }static const struct of_device_id meson8b_clkc_match_table[] = {
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 3/19 clk: meson: only one loop index is necessary in probe
In reply to Jerome BrunetWe don't need several loop index variables in the probe function This is far from being critical but since we are doing a vast rework of meson clock controllers, now is the time to lower the entropy a bit
--- drivers/clk/meson/axg.c | 8 ++++---- drivers/clk/meson/gxbb.c | 13 ++++++------- drivers/clk/meson/meson8b.c | 8 ++++---- 3 files changed, 14 insertions(+), 15 deletions(-)
drivers/clk/meson/axg.c +4 -4
@@ -802,7 +802,7 @@ static int axg_clkc_probe(struct platform_device *pdev)const struct clkc_data *clkc_data;struct resource *res;void __iomem *clk_base; -int ret, clkid, i; +int ret, i; clkc_data =of_device_get_match_data (dev);if (!clkc_data)
@@ -841,13 +841,13 @@ static int axg_clkc_probe(struct platform_device *pdev) clkc_data->clk_dividers[i]->reg = clk_base + (u64 )clkc_data->clk_dividers[i]->reg; -for (clkid =0 ; clkid < clkc_data->hw_onecell_data->num; clkid++) { +for (i =0 ; i < clkc_data->hw_onecell_data->num; i++) {/* array might be sparse */ -if (!clkc_data->hw_onecell_data->hws[clkid]) +if (!clkc_data->hw_onecell_data->hws[i])continue ; ret =devm_clk_hw_register (dev, - clkc_data->hw_onecell_data->hws[clkid]); + clkc_data->hw_onecell_data->hws[i]);if (ret) {dev_err (dev,"Clock registration failed\n" );return ret;
drivers/clk/meson/gxbb.c +6 -7
@@ -1947,7 +1947,7 @@ static int gxbb_clkc_probe(struct platform_device *pdev) {const struct clkc_data *clkc_data;void __iomem *clk_base; -int ret, clkid, i; +int ret, i;struct device *dev = &pdev->dev; clkc_data =of_device_get_match_data (dev);
@@ -1988,16 +1988,15 @@ static int gxbb_clkc_probe(struct platform_device *pdev)for (i =0 ; i < clkc_data->clk_audio_dividers_count; i++) clkc_data->clk_audio_dividers[i]->base = clk_base; -/* -* register all clks -*/ -for (clkid =0 ; clkid < clkc_data->hw_onecell_data->num; clkid++) { + +/* Register all clks */ +for (i =0 ; i < clkc_data->hw_onecell_data->num; i++) {/* array might be sparse */ -if (!clkc_data->hw_onecell_data->hws[clkid]) +if (!clkc_data->hw_onecell_data->hws[i])continue ; ret =devm_clk_hw_register (dev, - clkc_data->hw_onecell_data->hws[clkid]); + clkc_data->hw_onecell_data->hws[i]);if (ret) goto iounmap; }
drivers/clk/meson/meson8b.c +4 -4
@@ -806,7 +806,7 @@ static const struct reset_control_ops meson8b_clk_reset_ops = {static int meson8b_clkc_probe (struct platform_device *pdev) { -int ret, clkid, i; +int ret, i;struct clk_hw *parent_hw;struct clk *parent_clk;struct device *dev = &pdev->dev;
@@ -844,13 +844,13 @@ static int meson8b_clkc_probe(struct platform_device *pdev)* register all clks * CLKID_UNUSED = 0, so skip it and start with CLKID_XTAL = 1 */ -for (clkid =CLKID_XTAL ; clkid <CLK_NR_CLKS ; clkid++) { +for (i =CLKID_XTAL ; i <CLK_NR_CLKS ; i++) {/* array might be sparse */ -if (!meson8b_hw_onecell_data.hws[clkid]) +if (!meson8b_hw_onecell_data.hws[i])continue ;/* FIXME convert to devm_clk_register */ - ret =devm_clk_hw_register (dev, meson8b_hw_onecell_data.hws[clkid]); + ret =devm_clk_hw_register (dev, meson8b_hw_onecell_data.hws[i]);if (ret)return ret; }
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 4/19 clk: meson: remove obsolete comments
In reply to Jerome BrunetOver time things changes in CCF and issues have been fixed in meson controllers.
Now, clk81 is decently modeled by read-only PLLs, a mux, a divider and a gate. We can remove the FIXME comments related to clk81. Also remove the comment about devm_clk_hw_register, as there is apparently nothing wrong with it.
--- drivers/clk/meson/axg.c | 5 ----- drivers/clk/meson/gxbb.c | 6 ------ drivers/clk/meson/meson8b.c | 1 - 3 files changed, 12 deletions(-)
drivers/clk/meson/axg.c +0 -5
@@ -411,11 +411,6 @@ static struct meson_clk_mpll axg_mpll3 = { }, }; -/* -* FIXME The legacy composite clocks (e.g. clk81) are both PLL post-dividers -* and should be modeled with their respective PLLs via the forthcoming -* coordinated clock rates feature -*/ static u32 mux_table_clk81[] = {0 ,2 ,3 ,4 ,5 ,6 ,7 };static const char *const clk81_parent_names[] = {"xtal" ,"fclk_div7" ,"mpll1" ,"mpll2" ,"fclk_div4" ,
drivers/clk/meson/gxbb.c +0 -6
@@ -575,12 +575,6 @@ static struct meson_clk_mpll gxbb_mpll2 = { }, }; -/* -* FIXME The legacy composite clocks (e.g. clk81) are both PLL post-dividers -* and should be modeled with their respective PLLs via the forthcoming -* coordinated clock rates feature -*/ -static u32 mux_table_clk81[] = {0 ,2 ,3 ,4 ,5 ,6 ,7 };static const char *const clk81_parent_names[] = {"xtal" ,"fclk_div7" ,"mpll1" ,"mpll2" ,"fclk_div4" ,
drivers/clk/meson/meson8b.c +0 -1
@@ -849,7 +849,6 @@ static int meson8b_clkc_probe(struct platform_device *pdev)if (!meson8b_hw_onecell_data.hws[i])continue ; -/* FIXME convert to devm_clk_register */ ret =devm_clk_hw_register (dev, meson8b_hw_onecell_data.hws[i]);if (ret)return ret;
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 5/19 clk: meson: add regmap clocks
In reply to Jerome BrunetMeson clock controllers needs to move the classical iomem registers to regmap. This is triggered because the HHI controllers found on the GXBB and GXL host more than just clocks. To properly handle this, we would like to migrate HHI to syscon. Also GXBB AO clock controller already use regmap, AXG AO and Audio clock controllers will as well.
The purpose of this change is to provide a common structure to these meson controllers (and possibly others) for regmap based clocks.
This change provides the basic gate, mux and divider, based on the helpers provided by the related generic clocks
--- drivers/clk/meson/Kconfig | 4 + drivers/clk/meson/Makefile | 1 + drivers/clk/meson/clk-regmap.c | 166 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/meson/clk-regmap.h | 111 +++++++++++++++++++++++++++ 4 files changed, 282 insertions(+) create mode 100644 drivers/clk/meson/clk-regmap.c create mode 100644 drivers/clk/meson/clk-regmap.h
drivers/clk/meson/Kconfig +4 -0
@@ -3,6 +3,10 @@ config COMMON_CLK_AMLOGIC depends on OF depends on ARCH_MESON || COMPILE_TEST +config COMMON_CLK_REGMAP_MESON + bool + select REGMAP + config COMMON_CLK_MESON8B bool depends on COMMON_CLK_AMLOGIC
drivers/clk/meson/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-cpu.o clk-mpll.o clk-audio-div obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o obj-$(CONFIG_COMMON_CLK_GXBB) += gxbb.o gxbb-aoclk.o gxbb-aoclk-regmap.o gxbb-aoclk-32k.o obj-$(CONFIG_COMMON_CLK_AXG) += axg.o +obj-$(CONFIG_COMMON_CLK_REGMAP_MESON) += clk-regmap.o
drivers/clk/meson/clk-regmap.c new file +166 -0
166 lines not on this page · raw message
drivers/clk/meson/clk-regmap.h new file +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 6/19 clk: meson: switch gxbb ao_clk to clk_regmap
In reply to Jerome BrunetDrop the gxbb ao specific regmap based clock and use the meson clk_regmap based clock instead.
--- drivers/clk/meson/Kconfig | 1 + drivers/clk/meson/Makefile | 2 +- drivers/clk/meson/gxbb-aoclk.c | 20 ++++++++++---------- drivers/clk/meson/gxbb-aoclk.h | 1 - 4 files changed, 12 insertions(+), 12 deletions(-)
drivers/clk/meson/Kconfig +1 -0
@@ -20,6 +20,7 @@ config COMMON_CLK_GXBB bool depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER + select COMMON_CLK_REGMAP_MESON help Support for the clock controller on AmLogic S905 devices, aka gxbb. Say Y if you want peripherals and CPU frequency scaling to work.
drivers/clk/meson/Makefile +1 -1
@@ -4,6 +4,6 @@ obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-cpu.o clk-mpll.o clk-audio-divider.o obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o -obj-$(CONFIG_COMMON_CLK_GXBB) += gxbb.o gxbb-aoclk.o gxbb-aoclk-regmap.o gxbb-aoclk-32k.o +obj-$(CONFIG_COMMON_CLK_GXBB) += gxbb.o gxbb-aoclk.o gxbb-aoclk-32k.o obj-$(CONFIG_COMMON_CLK_AXG) += axg.o obj-$(CONFIG_COMMON_CLK_REGMAP_MESON) += clk-regmap.o
drivers/clk/meson/gxbb-aoclk.c +10 -10
@@ -62,10 +62,9 @@#include <linux/delay.h> #include <dt-bindings/clock/gxbb-aoclkc.h> #include <dt-bindings/reset/gxbb-aoclkc.h> +#include "clk-regmap.h" #include "gxbb-aoclk.h" -static DEFINE_SPINLOCK (gxbb_aoclk_lock); -struct gxbb_aoclk_reset_controller {struct reset_controller_dev reset;unsigned int *data;
@@ -87,12 +86,14 @@ static const struct reset_control_ops gxbb_aoclk_reset_ops = { };#define GXBB_AO_GATE (_name, _bit) \ -static struct aoclk_gate_regmap _name##_ao = { \ - .bit_idx = (_bit), \ - .lock = &gxbb_aoclk_lock, \ +static struct clk_regmap _name##_ao = { \ + .data = &(struct clk_regmap_gate_data) { \ + .offset = AO_RTI_GEN_CNTL_REG0, \ + .bit_idx = (_bit), \ + }, \ .hw.init = &(struct clk_init_data) { \ .name = #_name "_ao", \ - .ops = &meson_aoclk_gate_regmap_ops, \ + .ops = &clk_regmap_gate_ops, \ .parent_names = (const char *[]){ "clk81" }, \ .num_parents = 1, \ .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \
@@ -107,7 +108,6 @@ GXBB_AO_GATE(uart2, 5);GXBB_AO_GATE (ir_blaster,6 );static struct aoclk_cec_32k cec_32k_ao = { - .lock = &gxbb_aoclk_lock, .hw.init = &(struct clk_init_data ) { .name ="cec_32k_ao" , .ops = &meson_aoclk_cec_32k_ops,
@@ -126,7 +126,7 @@ static unsigned int gxbb_aoclk_reset[] = { [RESET_AO_IR_BLASTER] = 23, }; -static struct aoclk_gate_regmap *gxbb_aoclk_gate[] = { +static struct clk_regmap *gxbb_aoclk_gate[] = { [CLKID_AO_REMOTE ] = &remote_ao, [CLKID_AO_I2C_MASTER ] = &i2c_master_ao, [CLKID_AO_I2C_SLAVE ] = &i2c_slave_ao,
@@ -177,10 +177,10 @@ static int gxbb_aoclkc_probe(struct platform_device *pdev)* Populate regmap and register all clks */ for (clkid =0 ; clkid <ARRAY_SIZE (gxbb_aoclk_gate); clkid++) { - gxbb_aoclk_gate[clkid]->regmap = regmap; + gxbb_aoclk_gate[clkid]->map = regmap; ret =devm_clk_hw_register (dev, - gxbb_aoclk_onecell_data.hws[clkid]); + gxbb_aoclk_onecell_data.hws[clkid]);if (ret)return ret; }
drivers/clk/meson/gxbb-aoclk.h +0 -1
@@ -32,7 +32,6 @@ extern const struct clk_ops meson_aoclk_gate_regmap_ops;struct aoclk_cec_32k {struct clk_hw hw;struct regmap *regmap; -spinlock_t *lock; };#define to_aoclk_cec_32k (_hw) container_of(_hw, struct aoclk_cec_32k, hw)
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 7/19 clk: meson: remove superseded aoclk_gate_regmap
In reply to Jerome Brunetaoclk_gate_regmap has been replaced by meson's clk_regmap. It is no longer necessary so, remove it
--- drivers/clk/meson/gxbb-aoclk-regmap.c | 46 ----------------------------------- drivers/clk/meson/gxbb-aoclk.h | 10 -------- 2 files changed, 56 deletions(-) delete mode 100644 drivers/clk/meson/gxbb-aoclk-regmap.c
drivers/clk/meson/gxbb-aoclk-regmap.c deleted +0 -46
@@ -1,46 +0,0 @@ -/* -* Copyright (c) 2017 BayLibre, SAS. -* Author: Neil Armstrong <[email protected]> -* -* SPDX-License-Identifier: GPL-2.0+ -*/ - -#include <linux/clk-provider.h> -#include <linux/bitfield.h> -#include <linux/regmap.h> -#include "gxbb-aoclk.h" - -static int aoclk_gate_regmap_enable (struct clk_hw *hw) -{ -struct aoclk_gate_regmap *gate =to_aoclk_gate_regmap (hw); - -return regmap_update_bits (gate->regmap,AO_RTI_GEN_CNTL_REG0 , -BIT (gate->bit_idx),BIT (gate->bit_idx)); -} - -static void aoclk_gate_regmap_disable (struct clk_hw *hw) -{ -struct aoclk_gate_regmap *gate =to_aoclk_gate_regmap (hw); - -regmap_update_bits (gate->regmap,AO_RTI_GEN_CNTL_REG0 , -BIT (gate->bit_idx),0 ); -} - -static int aoclk_gate_regmap_is_enabled (struct clk_hw *hw) -{ -struct aoclk_gate_regmap *gate =to_aoclk_gate_regmap (hw); -unsigned int val; -int ret; - - ret =regmap_read (gate->regmap,AO_RTI_GEN_CNTL_REG0 , &val); -if (ret) -return ret; - -return (val &BIT (gate->bit_idx)) !=0 ; -} - -const struct clk_ops meson_aoclk_gate_regmap_ops = { - .enable = aoclk_gate_regmap_enable, - .disable = aoclk_gate_regmap_disable, - .is_enabled = aoclk_gate_regmap_is_enabled, -};
drivers/clk/meson/gxbb-aoclk.h +0 -10
@@ -17,16 +17,6 @@#define AO_RTC_ALT_CLK_CNTL0 0x94#define AO_RTC_ALT_CLK_CNTL1 0x98 -struct aoclk_gate_regmap { -struct clk_hw hw; -unsigned bit_idx; -struct regmap *regmap; -spinlock_t *lock; -}; - -#define to_aoclk_gate_regmap (_hw) \ - container_of(_hw, struct aoclk_gate_regmap, hw) -extern const struct clk_ops meson_aoclk_gate_regmap_ops;struct aoclk_cec_32k {
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 8/19 clk: meson: add regmap to the clock controllers
In reply to Jerome BrunetThis change register a regmap in meson8b, gxbb and axg controllers. The clock are still accessing their registers directly through iomem. Once all clocks handled by these controllers have been move to regmap, the regmap register will be removed and replaced with a syscon request.
--- drivers/clk/meson/Kconfig | 2 ++ drivers/clk/meson/axg.c | 15 ++++++++++++++- drivers/clk/meson/gxbb.c | 33 +++++++++++++++++++++++---------- drivers/clk/meson/meson8b.c | 14 +++++++++++++- 4 files changed, 52 insertions(+), 12 deletions(-)
drivers/clk/meson/Kconfig +2 -0
@@ -11,6 +11,7 @@ config COMMON_CLK_MESON8B bool depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER + select REGMAP help Support for the clock controller on AmLogic S802 (Meson8), S805 (Meson8b) and S812 (Meson8m2) devices. Say Y if you
@@ -29,6 +30,7 @@ config COMMON_CLK_AXG bool depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER + select REGMAP help Support for the clock controller on AmLogic A113D devices, aka axg. Say Y if you want peripherals and CPU frequency scaling to work.
drivers/clk/meson/axg.c +14 -1
@@ -11,10 +11,11 @@#include <linux/clk.h> #include <linux/clk-provider.h> +#include <linux/init.h> #include <linux/of_address.h> #include <linux/of_device.h> #include <linux/platform_device.h> -#include <linux/init.h> +#include <linux/regmap.h> #include "clkc.h" #include "axg.h"
@@ -791,12 +792,19 @@ static const struct of_device_id clkc_match_table[] = { {} }; +static const struct regmap_config clkc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; +static int axg_clkc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;const struct clkc_data *clkc_data;struct resource *res;void __iomem *clk_base; +struct regmap *map;int ret, i; clkc_data =of_device_get_match_data (dev);
@@ -807,12 +815,17 @@ static int axg_clkc_probe(struct platform_device *pdev) res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res)return -EINVAL ; + clk_base =devm_ioremap (dev, res->start,resource_size (res));if (!clk_base) {dev_err (dev,"Unable to map clk base\n" );return -ENXIO ; } + map =devm_regmap_init_mmio (dev, clk_base, &clkc_regmap_config); +if (IS_ERR (map)) +return PTR_ERR (map); +/* Populate base address for PLLs */ for (i =0 ; i < clkc_data->clk_plls_count; i++) clkc_data->clk_plls[i]->base = clk_base;
drivers/clk/meson/gxbb.c +23 -10
@@ -19,10 +19,11 @@#include <linux/clk.h> #include <linux/clk-provider.h> +#include <linux/init.h> #include <linux/of_address.h> #include <linux/of_device.h> #include <linux/platform_device.h> -#include <linux/init.h> +#include <linux/regmap.h> #include "clkc.h" #include "gxbb.h"
@@ -1937,10 +1938,18 @@ static const struct of_device_id clkc_match_table[] = { {}, }; +static const struct regmap_config clkc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; +static int gxbb_clkc_probe (struct platform_device *pdev) {const struct clkc_data *clkc_data; +struct resource *res;void __iomem *clk_base; +struct regmap *map;int ret, i;struct device *dev = &pdev->dev;
@@ -1948,13 +1957,20 @@ static int gxbb_clkc_probe(struct platform_device *pdev)if (!clkc_data)return -EINVAL ; -/* Generic clocks and PLLs */ - clk_base =of_iomap (dev->of_node,0 ); + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + + clk_base =devm_ioremap (dev, res->start,resource_size (res));if (!clk_base) {pr_err ("%s: Unable to map clk base\n" , __func__);return -ENXIO ; } + map =devm_regmap_init_mmio (dev, clk_base, &clkc_regmap_config); +if (IS_ERR (map)) +return PTR_ERR (map); +/* Populate base address for PLLs */ for (i =0 ; i < clkc_data->clk_plls_count; i++) clkc_data->clk_plls[i]->base = clk_base;
@@ -1991,17 +2007,14 @@ static int gxbb_clkc_probe(struct platform_device *pdev) ret =devm_clk_hw_register (dev, clkc_data->hw_onecell_data->hws[i]); -if (ret) - goto iounmap; +if (ret) { +dev_err (dev,"Clock registration failed\n" ); +return ret; + } } -return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, clkc_data->hw_onecell_data); - -iounmap: -iounmap (clk_base); -return ret; }static struct platform_driver gxbb_driver = {
drivers/clk/meson/meson8b.c +13 -1
@@ -23,11 +23,12 @@#include <linux/clk.h> #include <linux/clk-provider.h> +#include <linux/init.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/reset-controller.h> #include <linux/slab.h> -#include <linux/init.h> +#include <linux/regmap.h> #include "clkc.h" #include "meson8b.h"
@@ -804,16 +805,27 @@ static const struct reset_control_ops meson8b_clk_reset_ops = { .deassert = meson8b_clk_reset_deassert, }; +static const struct regmap_config clkc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; +static int meson8b_clkc_probe (struct platform_device *pdev) {int ret, i;struct clk_hw *parent_hw;struct clk *parent_clk;struct device *dev = &pdev->dev; +struct regmap *map;if (!clk_base)return -ENXIO ; + map =devm_regmap_init_mmio (dev, clk_base, &clkc_regmap_config); +if (IS_ERR (map)) +return PTR_ERR (map); +/* Populate base address for PLLs */ for (i =0 ; i <ARRAY_SIZE (meson8b_clk_plls); i++) meson8b_clk_plls[i]->base = clk_base;
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 9/19 clk: meson: migrate gates to clk_regmap
In reply to Jerome BrunetMove meson8b, gxbb and axg clocks using clk_gate to clk_regmap
--- drivers/clk/meson/Kconfig | 4 +- drivers/clk/meson/axg.c | 72 ++++++------ drivers/clk/meson/clkc.h | 20 ++-- drivers/clk/meson/gxbb.c | 268 +++++++++++++++++++++++--------------------- drivers/clk/meson/meson8b.c | 39 +++---- 5 files changed, 208 insertions(+), 195 deletions(-)
drivers/clk/meson/Kconfig +2 -2
@@ -11,7 +11,7 @@ config COMMON_CLK_MESON8B bool depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER - select REGMAP + select COMMON_CLK_REGMAP_MESON help Support for the clock controller on AmLogic S802 (Meson8), S805 (Meson8b) and S812 (Meson8m2) devices. Say Y if you
@@ -30,7 +30,7 @@ config COMMON_CLK_AXG bool depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER - select REGMAP + select COMMON_CLK_REGMAP_MESON help Support for the clock controller on AmLogic A113D devices, aka axg. Say Y if you want peripherals and CPU frequency scaling to work.
drivers/clk/meson/axg.c +35 -37
127 lines not on this page · raw message
drivers/clk/meson/clkc.h +12 -8
@@ -18,6 +18,9 @@#ifndef __CLKC_H#define __CLKC_H +#include <linux/clk-provider.h> +#include "clk-regmap.h" +#define PMASK (width) GENMASK(width - 1, 0)#define SETPMASK (width, shift) GENMASK(shift + width - 1, shift)#define CLRPMASK (width, shift) (~SETPMASK(width, shift))
@@ -134,16 +137,17 @@ struct meson_clk_audio_divider { };#define MESON_GATE (_name, _reg, _bit) \ -struct clk_gate _name = { \ - .reg = (void __iomem *) _reg, \ - .bit_idx = (_bit), \ - .lock = &meson_clk_lock, \ - .hw.init = &(struct clk_init_data) { \ - .name = #_name, \ - .ops = &clk_gate_ops, \ +struct clk_regmap _name = { \ + .data = &(struct clk_regmap_gate_data){ \ + .offset = (_reg), \ + .bit_idx = (_bit), \ + }, \ + .hw.init = &(struct clk_init_data) { \ + .name = #_name, \ + .ops = &clk_regmap_gate_ops, \ .parent_names = (const char *[]){ "clk81" }, \ .num_parents = 1, \ - .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \ + .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED), \ }, \ };
drivers/clk/meson/gxbb.c +139 -129
435 lines not on this page · raw message
drivers/clk/meson/meson8b.c +20 -19
@@ -32,6 +32,7 @@#include "clkc.h" #include "meson8b.h" +#include "clk-regmap.h" static DEFINE_SPINLOCK (meson_clk_lock);
@@ -406,13 +407,14 @@ struct clk_divider meson8b_mpeg_clk_div = { }, }; -struct clk_gate meson8b_clk81 = { - .reg = (void *)HHI_MPEG_CLK_CNTL , - .bit_idx =7 , - .lock = &meson_clk_lock, +struct clk_regmap meson8b_clk81 = { + .data = &(struct clk_regmap_gate_data ){ + .offset =HHI_MPEG_CLK_CNTL , + .bit_idx =7 , + }, .hw.init = &(struct clk_init_data ){ .name ="clk81" , - .ops = &clk_gate_ops, + .ops = &clk_regmap_gate_ops, .parent_names = (const char *[]){"mpeg_clk_div" }, .num_parents =1 , .flags = (CLK_SET_RATE_PARENT |CLK_IS_CRITICAL ),
@@ -617,7 +619,15 @@ static struct meson_clk_mpll *const meson8b_clk_mplls[] = { &meson8b_mpll2, }; -static struct clk_gate *const meson8b_clk_gates[] = { +static struct clk_mux *const meson8b_clk_muxes[] = { + &meson8b_mpeg_clk_sel, +}; + +static struct clk_divider *const meson8b_clk_dividers[] = { + &meson8b_mpeg_clk_div, +}; + +static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_clk81, &meson8b_ddr, &meson8b_dos,
@@ -698,14 +708,6 @@ static struct clk_gate *const meson8b_clk_gates[] = { &meson8b_ao_iface, }; -static struct clk_mux *const meson8b_clk_muxes[] = { - &meson8b_mpeg_clk_sel, -}; - -static struct clk_divider *const meson8b_clk_dividers[] = { - &meson8b_mpeg_clk_div, -}; - static const struct meson8b_clk_reset_line { u32 reg; u8 bit_idx;
@@ -837,11 +839,6 @@ static int meson8b_clkc_probe(struct platform_device *pdev)/* Populate the base address for CPU clk */ meson8b_cpu_clk.base = clk_base; -/* Populate base address for gates */ -for (i =0 ; i <ARRAY_SIZE (meson8b_clk_gates); i++) - meson8b_clk_gates[i]->reg = clk_base + - (u32 )meson8b_clk_gates[i]->reg; -/* Populate base address for muxes */ for (i =0 ; i <ARRAY_SIZE (meson8b_clk_muxes); i++) meson8b_clk_muxes[i]->reg = clk_base +
@@ -852,6 +849,10 @@ static int meson8b_clkc_probe(struct platform_device *pdev) meson8b_clk_dividers[i]->reg = clk_base + (u32 )meson8b_clk_dividers[i]->reg; +/* Populate regmap for the regmap backed clocks */ +for (i =0 ; i <ARRAY_SIZE (meson8b_clk_regmaps); i++) + meson8b_clk_regmaps[i]->map = map; +/* * register all clks * CLKID_UNUSED = 0, so skip it and start with CLKID_XTAL = 1
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 10/19 clk: meson: migrate dividers to clk_regmap
In reply to Jerome BrunetMove meson8b, gxbb and axg clocks using clk_divider to clk_regmap
--- drivers/clk/meson/axg.c | 61 ++++++------- drivers/clk/meson/gxbb.c | 217 ++++++++++++++++++++++---------------------- drivers/clk/meson/meson8b.c | 23 ++--- 3 files changed, 142 insertions(+), 159 deletions(-)
drivers/clk/meson/axg.c +26 -35
@@ -433,14 +433,15 @@ static struct clk_mux axg_mpeg_clk_sel = { }, }; -static struct clk_divider axg_mpeg_clk_div = { - .reg = (void *)HHI_MPEG_CLK_CNTL , - .shift =0 , - .width =7 , - .lock = &meson_clk_lock, +static struct clk_regmap axg_mpeg_clk_div = { + .data = &(struct clk_regmap_div_data ){ + .offset =HHI_MPEG_CLK_CNTL , + .shift =0 , + .width =7 , + }, .hw.init = &(struct clk_init_data ){ .name ="mpeg_clk_div" , - .ops = &clk_divider_ops, + .ops = &clk_regmap_divider_ops, .parent_names = (const char *[]){"mpeg_clk_sel" }, .num_parents =1 , .flags =CLK_SET_RATE_PARENT ,
@@ -487,15 +488,16 @@ static struct clk_mux axg_sd_emmc_b_clk0_sel = { }, }; -static struct clk_divider axg_sd_emmc_b_clk0_div = { - .reg = (void *)HHI_SD_EMMC_CLK_CNTL , - .shift =16 , - .width =7 , - .lock = &meson_clk_lock, - .flags =CLK_DIVIDER_ROUND_CLOSEST , +static struct clk_regmap axg_sd_emmc_b_clk0_div = { + .data = &(struct clk_regmap_div_data ){ + .offset =HHI_SD_EMMC_CLK_CNTL , + .shift =16 , + .width =7 , + .flags =CLK_DIVIDER_ROUND_CLOSEST , + }, .hw.init = &(struct clk_init_data ) { .name ="sd_emmc_b_clk0_div" , - .ops = &clk_divider_ops, + .ops = &clk_regmap_divider_ops, .parent_names = (const char *[]){"sd_emmc_b_clk0_sel" }, .num_parents =1 , .flags =CLK_SET_RATE_PARENT ,
@@ -531,15 +533,16 @@ static struct clk_mux axg_sd_emmc_c_clk0_sel = { }, }; -static struct clk_divider axg_sd_emmc_c_clk0_div = { - .reg = (void *)HHI_NAND_CLK_CNTL , - .shift =0 , - .width =7 , - .lock = &meson_clk_lock, - .flags =CLK_DIVIDER_ROUND_CLOSEST , +static struct clk_regmap axg_sd_emmc_c_clk0_div = { + .data = &(struct clk_regmap_div_data ){ + .offset =HHI_NAND_CLK_CNTL , + .shift =0 , + .width =7 , + .flags =CLK_DIVIDER_ROUND_CLOSEST , + }, .hw.init = &(struct clk_init_data ) { .name ="sd_emmc_c_clk0_div" , - .ops = &clk_divider_ops, + .ops = &clk_regmap_divider_ops, .parent_names = (const char *[]){"sd_emmc_c_clk0_sel" }, .num_parents =1 , .flags =CLK_SET_RATE_PARENT ,
@@ -706,12 +709,6 @@ static struct clk_mux *const axg_clk_muxes[] = { &axg_sd_emmc_c_clk0_sel, }; -static struct clk_divider *const axg_clk_dividers[] = { - &axg_mpeg_clk_div, - &axg_sd_emmc_b_clk0_div, - &axg_sd_emmc_c_clk0_div, -}; -static struct clk_regmap *const axg_clk_regmaps[] = { &axg_clk81, &axg_ddr,
@@ -760,6 +757,9 @@ static struct clk_regmap *const axg_clk_regmaps[] = { &axg_ao_i2c, &axg_sd_emmc_b_clk0, &axg_sd_emmc_c_clk0, + &axg_mpeg_clk_div, + &axg_sd_emmc_b_clk0_div, + &axg_sd_emmc_c_clk0_div, }; struct clkc_data {
@@ -769,8 +769,6 @@ struct clkc_data {unsigned int clk_plls_count;struct clk_mux *const *clk_muxes;unsigned int clk_muxes_count; -struct clk_divider *const *clk_dividers; -unsigned int clk_dividers_count;struct clk_hw_onecell_data *hw_onecell_data; };
@@ -781,8 +779,6 @@ static const struct clkc_data axg_clkc_data = { .clk_plls_count = ARRAY_SIZE(axg_clk_plls), .clk_muxes = axg_clk_muxes, .clk_muxes_count = ARRAY_SIZE(axg_clk_muxes), - .clk_dividers = axg_clk_dividers, - .clk_dividers_count = ARRAY_SIZE(axg_clk_dividers), .hw_onecell_data = &axg_hw_onecell_data, };
@@ -838,11 +834,6 @@ static int axg_clkc_probe(struct platform_device *pdev) clkc_data->clk_muxes[i]->reg = clk_base + (u64 )clkc_data->clk_muxes[i]->reg; -/* Populate base address for dividers */ -for (i =0 ; i < clkc_data->clk_dividers_count; i++) - clkc_data->clk_dividers[i]->reg = clk_base + - (u64 )clkc_data->clk_dividers[i]->reg; -/* Populate regmap for the regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (axg_clk_regmaps); i++) axg_clk_regmaps[i]->map = map;
drivers/clk/meson/gxbb.c +108 -109
357 lines not on this page · raw message
drivers/clk/meson/meson8b.c +8 -15
@@ -393,14 +393,15 @@ struct clk_mux meson8b_mpeg_clk_sel = { }, }; -struct clk_divider meson8b_mpeg_clk_div = { - .reg = (void *)HHI_MPEG_CLK_CNTL , - .shift =0 , - .width =7 , - .lock = &meson_clk_lock, +struct clk_regmap meson8b_mpeg_clk_div = { + .data = &(struct clk_regmap_div_data ){ + .offset =HHI_MPEG_CLK_CNTL , + .shift =0 , + .width =7 , + }, .hw.init = &(struct clk_init_data ){ .name ="mpeg_clk_div" , - .ops = &clk_divider_ops, + .ops = &clk_regmap_divider_ops, .parent_names = (const char *[]){"mpeg_clk_sel" }, .num_parents =1 , .flags = (CLK_SET_RATE_PARENT |CLK_IGNORE_UNUSED ),
@@ -623,10 +624,6 @@ static struct clk_mux *const meson8b_clk_muxes[] = { &meson8b_mpeg_clk_sel, }; -static struct clk_divider *const meson8b_clk_dividers[] = { - &meson8b_mpeg_clk_div, -}; -static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_clk81, &meson8b_ddr,
@@ -706,6 +703,7 @@ static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_ao_ahb_sram, &meson8b_ao_ahb_bus, &meson8b_ao_iface, + &meson8b_mpeg_clk_div, }; static const struct meson8b_clk_reset_line {
@@ -844,11 +842,6 @@ static int meson8b_clkc_probe(struct platform_device *pdev) meson8b_clk_muxes[i]->reg = clk_base + (u32 )meson8b_clk_muxes[i]->reg; -/* Populate base address for dividers */ -for (i =0 ; i <ARRAY_SIZE (meson8b_clk_dividers); i++) - meson8b_clk_dividers[i]->reg = clk_base + - (u32 )meson8b_clk_dividers[i]->reg; -/* Populate regmap for the regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (meson8b_clk_regmaps); i++) meson8b_clk_regmaps[i]->map = map;
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 11/19 clk: meson: migrate muxes to clk_regmap
In reply to Jerome BrunetMove meson8b, gxbb and axg clocks using clk_mux to clk_regmap Also remove a few useless tables in the process
--- drivers/clk/meson/axg.c | 60 ++++----- drivers/clk/meson/gxbb.c | 312 +++++++++++++++++++++----------------------- drivers/clk/meson/meson8b.c | 27 ++-- 3 files changed, 184 insertions(+), 215 deletions(-)
drivers/clk/meson/axg.c +25 -35
@@ -418,16 +418,16 @@ static const char * const clk81_parent_names[] = {"fclk_div3" ,"fclk_div5" }; -static struct clk_mux axg_mpeg_clk_sel = { - .reg = (void *)HHI_MPEG_CLK_CNTL , - .mask =0x7 , - .shift =12 , - .flags =CLK_MUX_READ_ONLY , - .table = mux_table_clk81, - .lock = &meson_clk_lock, +static struct clk_regmap axg_mpeg_clk_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_MPEG_CLK_CNTL , + .mask =0x7 , + .shift =12 , + .table = mux_table_clk81, + }, .hw.init = &(struct clk_init_data ){ .name ="mpeg_clk_sel" , - .ops = &clk_mux_ro_ops, + .ops = &clk_regmap_mux_ro_ops, .parent_names = clk81_parent_names, .num_parents =ARRAY_SIZE (clk81_parent_names), },
@@ -474,14 +474,15 @@ static const char * const axg_sd_emmc_clk0_parent_names[] = { };/* SDcard clock */ -static struct clk_mux axg_sd_emmc_b_clk0_sel = { - .reg = (void *)HHI_SD_EMMC_CLK_CNTL , - .mask =0x7 , - .shift =25 , - .lock = &meson_clk_lock, +static struct clk_regmap axg_sd_emmc_b_clk0_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_SD_EMMC_CLK_CNTL , + .mask =0x7 , + .shift =25 , + }, .hw.init = &(struct clk_init_data ) { .name ="sd_emmc_b_clk0_sel" , - .ops = &clk_mux_ops, + .ops = &clk_regmap_mux_ops, .parent_names = axg_sd_emmc_clk0_parent_names, .num_parents =ARRAY_SIZE (axg_sd_emmc_clk0_parent_names), .flags =CLK_SET_RATE_PARENT ,
@@ -519,14 +520,15 @@ static struct clk_regmap axg_sd_emmc_b_clk0 = { };/* EMMC/NAND clock */ -static struct clk_mux axg_sd_emmc_c_clk0_sel = { - .reg = (void *)HHI_NAND_CLK_CNTL , - .mask =0x7 , - .shift =9 , - .lock = &meson_clk_lock, +static struct clk_regmap axg_sd_emmc_c_clk0_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_NAND_CLK_CNTL , + .mask =0x7 , + .shift =9 , + }, .hw.init = &(struct clk_init_data ) { .name ="sd_emmc_c_clk0_sel" , - .ops = &clk_mux_ops, + .ops = &clk_regmap_mux_ops, .parent_names = axg_sd_emmc_clk0_parent_names, .num_parents =ARRAY_SIZE (axg_sd_emmc_clk0_parent_names), .flags =CLK_SET_RATE_PARENT ,
@@ -703,12 +705,6 @@ static struct meson_clk_mpll *const axg_clk_mplls[] = { &axg_mpll3, }; -static struct clk_mux *const axg_clk_muxes[] = { - &axg_mpeg_clk_sel, - &axg_sd_emmc_b_clk0_sel, - &axg_sd_emmc_c_clk0_sel, -}; -static struct clk_regmap *const axg_clk_regmaps[] = { &axg_clk81, &axg_ddr,
@@ -760,6 +756,9 @@ static struct clk_regmap *const axg_clk_regmaps[] = { &axg_mpeg_clk_div, &axg_sd_emmc_b_clk0_div, &axg_sd_emmc_c_clk0_div, + &axg_mpeg_clk_sel, + &axg_sd_emmc_b_clk0_sel, + &axg_sd_emmc_c_clk0_sel, }; struct clkc_data {
@@ -767,8 +766,6 @@ struct clkc_data {unsigned int clk_mplls_count;struct meson_clk_pll *const *clk_plls;unsigned int clk_plls_count; -struct clk_mux *const *clk_muxes; -unsigned int clk_muxes_count;struct clk_hw_onecell_data *hw_onecell_data; };
@@ -777,8 +774,6 @@ static const struct clkc_data axg_clkc_data = { .clk_mplls_count = ARRAY_SIZE(axg_clk_mplls), .clk_plls = axg_clk_plls, .clk_plls_count = ARRAY_SIZE(axg_clk_plls), - .clk_muxes = axg_clk_muxes, - .clk_muxes_count = ARRAY_SIZE(axg_clk_muxes), .hw_onecell_data = &axg_hw_onecell_data, };
@@ -829,11 +824,6 @@ static int axg_clkc_probe(struct platform_device *pdev)for (i =0 ; i < clkc_data->clk_mplls_count; i++) clkc_data->clk_mplls[i]->base = clk_base; -/* Populate base address for muxes */ -for (i =0 ; i < clkc_data->clk_muxes_count; i++) - clkc_data->clk_muxes[i]->reg = clk_base + - (u64 )clkc_data->clk_muxes[i]->reg; -/* Populate regmap for the regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (axg_clk_regmaps); i++) axg_clk_regmaps[i]->map = map;
drivers/clk/meson/gxbb.c +150 -162
508 lines not on this page · raw message
drivers/clk/meson/meson8b.c +9 -18
@@ -370,17 +370,16 @@ static struct meson_clk_cpu meson8b_cpu_clk = { };static u32 mux_table_clk81[] = {6 ,5 ,7 }; - -struct clk_mux meson8b_mpeg_clk_sel = { - .reg = (void *)HHI_MPEG_CLK_CNTL , - .mask =0x7 , - .shift =12 , - .flags =CLK_MUX_READ_ONLY , - .table = mux_table_clk81, - .lock = &meson_clk_lock, +static struct clk_regmap meson8b_mpeg_clk_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_MPEG_CLK_CNTL , + .mask =0x7 , + .shift =12 , + .table = mux_table_clk81, + }, .hw.init = &(struct clk_init_data ){ .name ="mpeg_clk_sel" , - .ops = &clk_mux_ro_ops, + .ops = &clk_regmap_mux_ro_ops,/* * FIXME bits 14:12 selects from 8 possible parents: * xtal, 1'b0 (wtf), fclk_div7, mpll_clkout1, mpll_clkout2,
@@ -620,10 +619,6 @@ static struct meson_clk_mpll *const meson8b_clk_mplls[] = { &meson8b_mpll2, }; -static struct clk_mux *const meson8b_clk_muxes[] = { - &meson8b_mpeg_clk_sel, -}; -static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_clk81, &meson8b_ddr,
@@ -704,6 +699,7 @@ static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_ao_ahb_bus, &meson8b_ao_iface, &meson8b_mpeg_clk_div, + &meson8b_mpeg_clk_sel, }; static const struct meson8b_clk_reset_line {
@@ -837,11 +833,6 @@ static int meson8b_clkc_probe(struct platform_device *pdev)/* Populate the base address for CPU clk */ meson8b_cpu_clk.base = clk_base; -/* Populate base address for muxes */ -for (i =0 ; i <ARRAY_SIZE (meson8b_clk_muxes); i++) - meson8b_clk_muxes[i]->reg = clk_base + - (u32 )meson8b_clk_muxes[i]->reg; -/* Populate regmap for the regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (meson8b_clk_regmaps); i++) meson8b_clk_regmaps[i]->map = map;
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 12/19 clk: meson: add regmap helpers for parm
In reply to Jerome BrunetMeson clock drivers are using struct parm to describe each field of the clock provider. Providing helpers to access these field with regmap helps keep drivers readable
--- drivers/clk/meson/clkc.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/clk/meson/clkc.h +16 -0
@@ -38,6 +38,22 @@ struct parm {u8 width; }; +static inline unsigned int meson_parm_read (struct regmap *map,struct parm *p) +{ +unsigned int val; + +regmap_read (map, p->reg_off, &val); +return PARM_GET (p->width, p->shift, val); +} + +static inline void meson_parm_write (struct regmap *map,struct parm *p, +unsigned int val) +{ +regmap_update_bits (map, p->reg_off,SETPMASK (p->width, p->shift), + val << p->shift); +} + +struct pll_rate_table {unsigned long rate;u16 m;
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 13/19 clk: meson: migrate mplls clocks to clk_regmap
In reply to Jerome BrunetRework meson mpll driver to use clk_regmap and move meson8b, gxbb and axg clocks using meson_clk_mpll to clk_regmap
--- drivers/clk/meson/axg.c | 245 +++++++++++++++++++++---------------------- drivers/clk/meson/clk-mpll.c | 102 +++++++----------- drivers/clk/meson/clkc.h | 4 +- drivers/clk/meson/gxbb.c | 161 ++++++++++++++-------------- drivers/clk/meson/meson8b.c | 155 ++++++++++++++------------- 5 files changed, 313 insertions(+), 354 deletions(-)
drivers/clk/meson/axg.c +121 -124
@@ -267,38 +267,40 @@ static struct clk_fixed_factor axg_fclk_div7 = { }, }; -static struct meson_clk_mpll axg_mpll0 = { - .sdm = { - .reg_off =HHI_MPLL_CNTL7 , - .shift =0 , - .width =14 , - }, - .sdm_en = { - .reg_off =HHI_MPLL_CNTL7 , - .shift =15 , - .width =1 , - }, - .n2 = { - .reg_off =HHI_MPLL_CNTL7 , - .shift =16 , - .width =9 , - }, - .en = { - .reg_off =HHI_MPLL_CNTL7 , - .shift =14 , - .width =1 , +static struct clk_regmap axg_mpll0 = { + .data = &(struct meson_clk_mpll_data ){ + .sdm = { + .reg_off =HHI_MPLL_CNTL7 , + .shift =0 , + .width =14 , + }, + .sdm_en = { + .reg_off =HHI_MPLL_CNTL7 , + .shift =15 , + .width =1 , + }, + .n2 = { + .reg_off =HHI_MPLL_CNTL7 , + .shift =16 , + .width =9 , + }, + .en = { + .reg_off =HHI_MPLL_CNTL7 , + .shift =14 , + .width =1 , + }, + .ssen = { + .reg_off =HHI_MPLL_CNTL , + .shift =25 , + .width =1 , + }, + .misc = { + .reg_off =HHI_PLL_TOP_MISC , + .shift =0 , + .width =1 , + }, + .lock = &meson_clk_lock, }, - .ssen = { - .reg_off =HHI_MPLL_CNTL , - .shift =25 , - .width =1 , - }, - .misc = { - .reg_off =HHI_PLL_TOP_MISC , - .shift =0 , - .width =1 , - }, - .lock = &meson_clk_lock, .hw.init = &(struct clk_init_data ){ .name ="mpll0" , .ops = &meson_clk_mpll_ops,
@@ -307,33 +309,35 @@ static struct meson_clk_mpll axg_mpll0 = { }, }; -static struct meson_clk_mpll axg_mpll1 = { - .sdm = { - .reg_off =HHI_MPLL_CNTL8 , - .shift =0 , - .width =14 , +static struct clk_regmap axg_mpll1 = { + .data = &(struct meson_clk_mpll_data ){ + .sdm = { + .reg_off =HHI_MPLL_CNTL8 , + .shift =0 , + .width =14 , + }, + .sdm_en = { + .reg_off =HHI_MPLL_CNTL8 , + .shift =15 , + .width =1 , + }, + .n2 = { + .reg_off =HHI_MPLL_CNTL8 , + .shift =16 , + .width =9 , + }, + .en = { + .reg_off =HHI_MPLL_CNTL8 , + .shift =14 , + .width =1 , + }, + .misc = { + .reg_off =HHI_PLL_TOP_MISC , + .shift =1 , + .width =1 , + }, + .lock = &meson_clk_lock, }, - .sdm_en = { - .reg_off =HHI_MPLL_CNTL8 , - .shift =15 , - .width =1 , - }, - .n2 = { - .reg_off =HHI_MPLL_CNTL8 , - .shift =16 , - .width =9 , - }, - .en = { - .reg_off =HHI_MPLL_CNTL8 , - .shift =14 , - .width =1 , - }, - .misc = { - .reg_off =HHI_PLL_TOP_MISC , - .shift =1 , - .width =1 , - }, - .lock = &meson_clk_lock, .hw.init = &(struct clk_init_data ){ .name ="mpll1" , .ops = &meson_clk_mpll_ops,
@@ -342,33 +346,35 @@ static struct meson_clk_mpll axg_mpll1 = { }, }; -static struct meson_clk_mpll axg_mpll2 = { - .sdm = { - .reg_off =HHI_MPLL_CNTL9 , - .shift =0 , - .width =14 , - }, - .sdm_en = { - .reg_off =HHI_MPLL_CNTL9 , - .shift =15 , - .width =1 , +static struct clk_regmap axg_mpll2 = { + .data = &(struct meson_clk_mpll_data ){ + .sdm = { + .reg_off =HHI_MPLL_CNTL9 , + .shift =0 , + .width =14 , + }, + .sdm_en = { + .reg_off =HHI_MPLL_CNTL9 , + .shift =15 , + .width =1 , + }, + .n2 = { + .reg_off =HHI_MPLL_CNTL9 , + .shift =16 , + .width =9 , + }, + .en = { + .reg_off =HHI_MPLL_CNTL9 , + .shift =14 , + .width =1 , + }, + .misc = { + .reg_off =HHI_PLL_TOP_MISC , + .shift =2 , + .width =1 , + }, + .lock = &meson_clk_lock, }, - .n2 = { - .reg_off =HHI_MPLL_CNTL9 , - .shift =16 , - .width =9 , - }, - .en = { - .reg_off =HHI_MPLL_CNTL9 , - .shift =14 , - .width =1 , - }, - .misc = { - .reg_off =HHI_PLL_TOP_MISC , - .shift =2 , - .width =1 , - }, - .lock = &meson_clk_lock, .hw.init = &(struct clk_init_data ){ .name ="mpll2" , .ops = &meson_clk_mpll_ops,
@@ -377,33 +383,35 @@ static struct meson_clk_mpll axg_mpll2 = { }, }; -static struct meson_clk_mpll axg_mpll3 = { - .sdm = { - .reg_off =HHI_MPLL3_CNTL0 , - .shift =12 , - .width =14 , - }, - .sdm_en = { - .reg_off =HHI_MPLL3_CNTL0 , - .shift =11 , - .width =1 , +static struct clk_regmap axg_mpll3 = { + .data = &(struct meson_clk_mpll_data ){ + .sdm = { + .reg_off =HHI_MPLL3_CNTL0 , + .shift =12 , + .width =14 , + }, + .sdm_en = { + .reg_off =HHI_MPLL3_CNTL0 , + .shift =11 , + .width =1 , + }, + .n2 = { + .reg_off =HHI_MPLL3_CNTL0 , + .shift =2 , + .width =9 , + }, + .en = { + .reg_off =HHI_MPLL3_CNTL0 , + .shift =0 , + .width =1 , + }, + .misc = { + .reg_off =HHI_PLL_TOP_MISC , + .shift =3 , + .width =1 , + }, + .lock = &meson_clk_lock, }, - .n2 = { - .reg_off =HHI_MPLL3_CNTL0 , - .shift =2 , - .width =9 , - }, - .en = { - .reg_off =HHI_MPLL3_CNTL0 , - .shift =0 , - .width =1 , - }, - .misc = { - .reg_off =HHI_PLL_TOP_MISC , - .shift =3 , - .width =1 , - }, - .lock = &meson_clk_lock, .hw.init = &(struct clk_init_data ){ .name ="mpll3" , .ops = &meson_clk_mpll_ops,
@@ -698,13 +706,6 @@ static struct meson_clk_pll *const axg_clk_plls[] = { &axg_gp0_pll, }; -static struct meson_clk_mpll *const axg_clk_mplls[] = { - &axg_mpll0, - &axg_mpll1, - &axg_mpll2, - &axg_mpll3, -}; -static struct clk_regmap *const axg_clk_regmaps[] = { &axg_clk81, &axg_ddr,
@@ -759,19 +760,19 @@ static struct clk_regmap *const axg_clk_regmaps[] = { &axg_mpeg_clk_sel, &axg_sd_emmc_b_clk0_sel, &axg_sd_emmc_c_clk0_sel, + &axg_mpll0, + &axg_mpll1, + &axg_mpll2, + &axg_mpll3, };struct clkc_data { -struct meson_clk_mpll *const *clk_mplls; -unsigned int clk_mplls_count;struct meson_clk_pll *const *clk_plls;unsigned int clk_plls_count;struct clk_hw_onecell_data *hw_onecell_data; };static const struct clkc_data axg_clkc_data = { - .clk_mplls = axg_clk_mplls, - .clk_mplls_count =ARRAY_SIZE (axg_clk_mplls), .clk_plls = axg_clk_plls, .clk_plls_count =ARRAY_SIZE (axg_clk_plls), .hw_onecell_data = &axg_hw_onecell_data,
@@ -820,10 +821,6 @@ static int axg_clkc_probe(struct platform_device *pdev)for (i =0 ; i < clkc_data->clk_plls_count; i++) clkc_data->clk_plls[i]->base = clk_base; -/* Populate base address for MPLLs */ -for (i =0 ; i < clkc_data->clk_mplls_count; i++) - clkc_data->clk_mplls[i]->base = clk_base; -/* Populate regmap for the regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (axg_clk_regmaps); i++) axg_clk_regmaps[i]->map = map;
drivers/clk/meson/clk-mpll.c +37 -65
165 lines not on this page · raw message
drivers/clk/meson/clkc.h +1 -3
@@ -132,9 +132,7 @@ struct meson_clk_cpu {int meson_clk_cpu_notifier_cb (struct notifier_block *nb,unsigned long event,void *data); -struct meson_clk_mpll { -struct clk_hw hw; -void __iomem *base; +struct meson_clk_mpll_data {struct parm sdm;struct parm sdm_en;struct parm n2;
drivers/clk/meson/gxbb.c +77 -84
215 lines not on this page · raw message
drivers/clk/meson/meson8b.c +77 -78
194 lines not on this page · raw message
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 14/19 clk: meson: migrate the audio divider clock to clk_regmap
In reply to Jerome BrunetRework meson audio divider driver to use clk_regmap and move gxbb clock using meson_clk_audio_divider to clk_regmap.
--- drivers/clk/meson/clk-audio-divider.c | 63 +++++++++++------------------------ drivers/clk/meson/clkc.h | 5 +-- drivers/clk/meson/gxbb.c | 30 +++++------------ 3 files changed, 30 insertions(+), 68 deletions(-)
drivers/clk/meson/clk-audio-divider.c +20 -43
@@ -28,8 +28,11 @@#include <linux/clk-provider.h> #include "clkc.h" -#define to_meson_clk_audio_divider (_hw) container_of(_hw, \ - struct meson_clk_audio_divider, hw) +static inline struct meson_clk_audio_div_data * +meson_clk_audio_div_data (struct clk_regmap *clk) +{ +return (struct meson_clk_audio_div_data *)clk->data; +}static int _div_round (unsigned long parent_rate,unsigned long rate,unsigned long flags)
@@ -45,15 +48,9 @@ static int _get_val(unsigned long parent_rate, unsigned long rate)return DIV_ROUND_UP_ULL ((u64 )parent_rate, rate) -1 ; } -static int _valid_divider (struct clk_hw *hw,int divider) +static int _valid_divider (unsigned int width,int divider) { -struct meson_clk_audio_divider *adiv = -to_meson_clk_audio_divider (hw); -int max_divider; -u8 width; - - width = adiv->div.width; - max_divider =1 << width; +int max_divider =1 << width;return clamp (divider,1 , max_divider); }
@@ -61,14 +58,11 @@ static int _valid_divider(struct clk_hw *hw, int divider)static unsigned long audio_divider_recalc_rate (struct clk_hw *hw,unsigned long parent_rate) { -struct meson_clk_audio_divider *adiv = -to_meson_clk_audio_divider (hw); -struct parm *p; -unsigned long reg, divider; +struct clk_regmap *clk =to_clk_regmap (hw); +struct meson_clk_audio_div_data *adiv =meson_clk_audio_div_data (clk); +unsigned long divider; - p = &adiv->div; - reg =readl (adiv->base + p->reg_off); - divider =PARM_GET (p->width, p->shift, reg) +1 ; + divider =meson_parm_read (clk->map, &adiv->div);return DIV_ROUND_UP_ULL ((u64 )parent_rate, divider); }
@@ -77,14 +71,14 @@ static long audio_divider_round_rate(struct clk_hw *hw,unsigned long rate, unsigned long *parent_rate) { - struct meson_clk_audio_divider *adiv = -to_meson_clk_audio_divider (hw); + struct clk_regmap *clk = to_clk_regmap(hw); +struct meson_clk_audio_div_data *adiv =meson_clk_audio_div_data (clk);unsigned long max_prate;int divider;if (!(clk_hw_get_flags (hw) &CLK_SET_RATE_PARENT )) { divider =_div_round (*parent_rate, rate, adiv->flags); - divider =_valid_divider (hw, divider); + divider =_valid_divider (adiv->div.width, divider);return DIV_ROUND_UP_ULL ((u64)*parent_rate, divider); }
@@ -93,7 +87,7 @@ static long audio_divider_round_rate(struct clk_hw *hw,/* Get the corresponding rounded down divider */ divider = max_prate / rate; - divider =_valid_divider (hw, divider); + divider =_valid_divider (adiv->div.width, divider);/* Get actual rate of the parent */ *parent_rate = clk_hw_round_rate(clk_hw_get_parent(hw),
@@ -106,28 +100,11 @@ static int audio_divider_set_rate(struct clk_hw *hw,unsigned long rate, unsigned long parent_rate) { - struct meson_clk_audio_divider *adiv = -to_meson_clk_audio_divider (hw); -struct parm *p; -unsigned long reg, flags =0 ; -int val; - - val =_get_val (parent_rate, rate); - -if (adiv->lock) -spin_lock_irqsave (adiv->lock, flags); -else -__acquire (adiv->lock); - - p = &adiv->div; - reg =readl (adiv->base + p->reg_off); - reg =PARM_SET (p->width, p->shift, reg, val); -writel (reg, adiv->base + p->reg_off); - -if (adiv->lock) -spin_unlock_irqrestore (adiv->lock, flags); -else -__release (adiv->lock); + struct clk_regmap *clk = to_clk_regmap(hw); +struct meson_clk_audio_div_data *adiv =meson_clk_audio_div_data (clk); +int val =_get_val (parent_rate, rate); + +meson_parm_write (clk->map, &adiv->div, val);return 0 ; }
drivers/clk/meson/clkc.h +1 -4
@@ -142,12 +142,9 @@ struct meson_clk_mpll_data {spinlock_t *lock; }; -struct meson_clk_audio_divider { -struct clk_hw hw; -void __iomem *base; +struct meson_clk_audio_div_data {struct parm div;u8 flags; -spinlock_t *lock; };#define MESON_GATE (_name, _reg, _bit) \
drivers/clk/meson/gxbb.c +9 -21
@@ -826,14 +826,15 @@ static struct clk_regmap gxbb_cts_amclk_sel = { }, }; -static struct meson_clk_audio_divider gxbb_cts_amclk_div = { - .div = { - .reg_off =HHI_AUD_CLK_CNTL , - .shift =0 , - .width =8 , +static struct clk_regmap gxbb_cts_amclk_div = { + .data = &(struct meson_clk_audio_div_data ){ + .div = { + .reg_off =HHI_AUD_CLK_CNTL , + .shift =0 , + .width =8 , + }, + .flags =CLK_DIVIDER_ROUND_CLOSEST , }, - .flags =CLK_DIVIDER_ROUND_CLOSEST , - .lock = &meson_clk_lock, .hw.init = &(struct clk_init_data ){ .name ="cts_amclk_div" , .ops = &meson_clk_audio_divider_ops,
@@ -1777,10 +1778,6 @@ static struct meson_clk_pll *const gxl_clk_plls[] = { &gxl_gp0_pll, }; -static struct meson_clk_audio_divider *const gxbb_audio_dividers[] = { - &gxbb_cts_amclk_div, -}; -static struct clk_regmap *const gx_clk_regmaps[] = { &gxbb_clk81, &gxbb_ddr,
@@ -1912,29 +1909,24 @@ static struct clk_regmap *const gx_clk_regmaps[] = { &gxbb_mpll0, &gxbb_mpll1, &gxbb_mpll2, + &gxbb_cts_amclk_div, };struct clkc_data {struct meson_clk_pll *const *clk_plls;unsigned int clk_plls_count; -struct meson_clk_audio_divider *const *clk_audio_dividers; -unsigned int clk_audio_dividers_count;struct clk_hw_onecell_data *hw_onecell_data; };static const struct clkc_data gxbb_clkc_data = { .clk_plls = gxbb_clk_plls, .clk_plls_count =ARRAY_SIZE (gxbb_clk_plls), - .clk_audio_dividers = gxbb_audio_dividers, - .clk_audio_dividers_count =ARRAY_SIZE (gxbb_audio_dividers), .hw_onecell_data = &gxbb_hw_onecell_data, };static const struct clkc_data gxl_clkc_data = { .clk_plls = gxl_clk_plls, .clk_plls_count =ARRAY_SIZE (gxl_clk_plls), - .clk_audio_dividers = gxbb_audio_dividers, - .clk_audio_dividers_count =ARRAY_SIZE (gxbb_audio_dividers), .hw_onecell_data = &gxl_hw_onecell_data, };
@@ -1981,10 +1973,6 @@ static int gxbb_clkc_probe(struct platform_device *pdev)for (i =0 ; i < clkc_data->clk_plls_count; i++) clkc_data->clk_plls[i]->base = clk_base; -/* Populate base address for the audio dividers */ -for (i =0 ; i < clkc_data->clk_audio_dividers_count; i++) - clkc_data->clk_audio_dividers[i]->base = clk_base; -/* Populate regmap for the common regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (gx_clk_regmaps); i++) gx_clk_regmaps[i]->map = map;
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 15/19 clk: meson: migrate plls clocks to clk_regmap
In reply to Jerome BrunetRework meson pll driver to use clk_regmap and move meson8b, gxbb and axg's clock using meson_clk_pll to clk_regmap.
This rework is not just about clk_regmap, there a serious clean-up of the driver code:
* Add lock and reset field: Previously inferred from the n field.
* Simplify the reset logic: Code seemed to apply reset differently but in fact it always the same -> assert reset, apply params, de-assert reset. The 2 lock checking loops have been kept for now, as they seem to be necessary.
* Do the sequence of init register pokes only at .init() instead of in .set_rate(). Redoing the init on every set_rate() is not necessary
--- drivers/clk/meson/axg.c | 213 +++++++++++----------- drivers/clk/meson/clk-pll.c | 243 ++++++++++--------------- drivers/clk/meson/clkc.h | 36 +--- drivers/clk/meson/gxbb.c | 424 +++++++++++++++++++++++++------------------- drivers/clk/meson/meson8b.c | 149 +++++++++------- 5 files changed, 535 insertions(+), 530 deletions(-)
drivers/clk/meson/axg.c +108 -105
@@ -22,28 +22,39 @@static DEFINE_SPINLOCK (meson_clk_lock); -static struct meson_clk_pll axg_fixed_pll = { - .m = { - .reg_off =HHI_MPLL_CNTL , - .shift =0 , - .width =9 , - }, - .n = { - .reg_off =HHI_MPLL_CNTL , - .shift =9 , - .width =5 , - }, - .od = { - .reg_off =HHI_MPLL_CNTL , - .shift =16 , - .width =2 , - }, - .frac = { - .reg_off =HHI_MPLL_CNTL2 , - .shift =0 , - .width =12 , - }, - .lock = &meson_clk_lock, +static struct clk_regmap axg_fixed_pll = { + .data = &(struct meson_clk_pll_data ){ + .m = { + .reg_off =HHI_MPLL_CNTL , + .shift =0 , + .width =9 , + }, + .n = { + .reg_off =HHI_MPLL_CNTL , + .shift =9 , + .width =5 , + }, + .od = { + .reg_off =HHI_MPLL_CNTL , + .shift =16 , + .width =2 , + }, + .frac = { + .reg_off =HHI_MPLL_CNTL2 , + .shift =0 , + .width =12 , + }, + .l = { + .reg_off =HHI_MPLL_CNTL , + .shift =31 , + .width =1 , + }, + .rst = { + .reg_off =HHI_MPLL_CNTL , + .shift =29 , + .width =1 , + }, + }, .hw.init = &(struct clk_init_data ){ .name ="fixed_pll" , .ops = &meson_clk_pll_ro_ops,
@@ -52,23 +63,34 @@ static struct meson_clk_pll axg_fixed_pll = { }, }; -static struct meson_clk_pll axg_sys_pll = { - .m = { - .reg_off =HHI_SYS_PLL_CNTL , - .shift =0 , - .width =9 , - }, - .n = { - .reg_off =HHI_SYS_PLL_CNTL , - .shift =9 , - .width =5 , - }, - .od = { - .reg_off =HHI_SYS_PLL_CNTL , - .shift =10 , - .width =2 , +static struct clk_regmap axg_sys_pll = { + .data = &(struct meson_clk_pll_data ){ + .m = { + .reg_off =HHI_SYS_PLL_CNTL , + .shift =0 , + .width =9 , + }, + .n = { + .reg_off =HHI_SYS_PLL_CNTL , + .shift =9 , + .width =5 , + }, + .od = { + .reg_off =HHI_SYS_PLL_CNTL , + .shift =10 , + .width =2 , + }, + .l = { + .reg_off =HHI_SYS_PLL_CNTL , + .shift =31 , + .width =1 , + }, + .rst = { + .reg_off =HHI_SYS_PLL_CNTL , + .shift =29 , + .width =1 , + }, }, - .lock = &meson_clk_lock, .hw.init = &(struct clk_init_data ){ .name ="sys_pll" , .ops = &meson_clk_pll_ro_ops,
@@ -169,40 +191,47 @@ static const struct pll_rate_table axg_gp0_pll_rate_table[] = { { /* sentinel */ }, }; -static struct pll_params_table axg_gp0_params_table[] = { -PLL_PARAM (HHI_GP0_PLL_CNTL ,0x40010250 ), -PLL_PARAM (HHI_GP0_PLL_CNTL1 ,0xc084a000 ), -PLL_PARAM (HHI_GP0_PLL_CNTL2 ,0xb75020be ), -PLL_PARAM (HHI_GP0_PLL_CNTL3 ,0x0a59a288 ), -PLL_PARAM (HHI_GP0_PLL_CNTL4 ,0xc000004d ), -PLL_PARAM (HHI_GP0_PLL_CNTL5 ,0x00078000 ), +const struct reg_sequence axg_gp0_init_regs[] = { + { .reg =HHI_GP0_PLL_CNTL , .def =0x40010250 }, + { .reg =HHI_GP0_PLL_CNTL1 , .def =0xc084a000 }, + { .reg =HHI_GP0_PLL_CNTL2 , .def =0xb75020be }, + { .reg =HHI_GP0_PLL_CNTL3 , .def =0x0a59a288 }, + { .reg =HHI_GP0_PLL_CNTL4 , .def =0xc000004d }, + { .reg =HHI_GP0_PLL_CNTL5 , .def =0x00078000 }, }; -static struct meson_clk_pll axg_gp0_pll = { - .m = { - .reg_off =HHI_GP0_PLL_CNTL , - .shift =0 , - .width =9 , - }, - .n = { - .reg_off =HHI_GP0_PLL_CNTL , - .shift =9 , - .width =5 , - }, - .od = { - .reg_off =HHI_GP0_PLL_CNTL , - .shift =16 , - .width =2 , - }, - .params = { - .params_table = axg_gp0_params_table, - .params_count =ARRAY_SIZE (axg_gp0_params_table), - .no_init_reset = true, - .reset_lock_loop = true, - }, - .rate_table = axg_gp0_pll_rate_table, - .rate_count =ARRAY_SIZE (axg_gp0_pll_rate_table), - .lock = &meson_clk_lock, +static struct clk_regmap axg_gp0_pll = { + .data = &(struct meson_clk_pll_data ){ + .m = { + .reg_off =HHI_GP0_PLL_CNTL , + .shift =0 , + .width =9 , + }, + .n = { + .reg_off =HHI_GP0_PLL_CNTL , + .shift =9 , + .width =5 , + }, + .od = { + .reg_off =HHI_GP0_PLL_CNTL , + .shift =16 , + .width =2 , + }, + .l = { + .reg_off =HHI_GP0_PLL_CNTL , + .shift =31 , + .width =1 , + }, + .rst = { + .reg_off =HHI_GP0_PLL_CNTL , + .shift =29 , + .width =1 , + }, + .table = axg_gp0_pll_rate_table, + .init_regs = axg_gp0_init_regs, + .init_count =ARRAY_SIZE (axg_gp0_init_regs), + .flags =CLK_MESON_PLL_LOCK_LOOP_RST , + }, .hw.init = &(struct clk_init_data ){ .name ="gp0_pll" , .ops = &meson_clk_pll_ops,
@@ -698,14 +727,7 @@ static struct clk_hw_onecell_data axg_hw_onecell_data = { .num = NR_CLKS, }; -/* Convenience tables to populate base addresses in .probe */ - -static struct meson_clk_pll *const axg_clk_plls[] = { - &axg_fixed_pll, - &axg_sys_pll, - &axg_gp0_pll, -}; - +/* Convenience table to populate regmap in .probe */ static struct clk_regmap *const axg_clk_regmaps[] = { &axg_clk81, &axg_ddr,
@@ -764,22 +786,13 @@ static struct clk_regmap *const axg_clk_regmaps[] = { &axg_mpll1, &axg_mpll2, &axg_mpll3, -}; - -struct clkc_data { -struct meson_clk_pll *const *clk_plls; -unsigned int clk_plls_count; -struct clk_hw_onecell_data *hw_onecell_data; -}; - -static const struct clkc_data axg_clkc_data = { - .clk_plls = axg_clk_plls, - .clk_plls_count =ARRAY_SIZE (axg_clk_plls), - .hw_onecell_data = &axg_hw_onecell_data, + &axg_fixed_pll, + &axg_sys_pll, + &axg_gp0_pll, };static const struct of_device_id clkc_match_table[] = { - { .compatible ="amlogic,axg-clkc" , .data = &axg_clkc_data }, + { .compatible ="amlogic,axg-clkc" }, {} };
@@ -792,16 +805,11 @@ static const struct regmap_config clkc_regmap_config = {static int axg_clkc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -const struct clkc_data *clkc_data;struct resource *res;void __iomem *clk_base;struct regmap *map;int ret, i; - clkc_data =of_device_get_match_data (dev); -if (!clkc_data) -return -EINVAL ; -/* Generic clocks and PLLs */ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res)
@@ -817,21 +825,16 @@ static int axg_clkc_probe(struct platform_device *pdev)if (IS_ERR (map))return PTR_ERR (map); -/* Populate base address for PLLs */ -for (i =0 ; i < clkc_data->clk_plls_count; i++) - clkc_data->clk_plls[i]->base = clk_base; -/* Populate regmap for the regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (axg_clk_regmaps); i++) axg_clk_regmaps[i]->map = map; -for (i =0 ; i < clkc_data->hw_onecell_data->num; i++) { +for (i =0 ; i < axg_hw_onecell_data.num; i++) {/* array might be sparse */ -if (!clkc_data->hw_onecell_data->hws[i]) +if (!axg_hw_onecell_data.hws[i])continue ; - ret =devm_clk_hw_register (dev, - clkc_data->hw_onecell_data->hws[i]); + ret =devm_clk_hw_register (dev, axg_hw_onecell_data.hws[i]);if (ret) {dev_err (dev,"Clock registration failed\n" );return ret;
@@ -839,7 +842,7 @@ static int axg_clkc_probe(struct platform_device *pdev) }return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, - clkc_data->hw_onecell_data); + &axg_hw_onecell_data); }static struct platform_driver axg_driver = {
drivers/clk/meson/clk-pll.c +93 -150
322 lines not on this page · raw message
drivers/clk/meson/clkc.h +8 -28
@@ -82,41 +82,21 @@ struct pll_rate_table { .frac = (_frac), \ } \ -struct pll_params_table { -unsigned int reg_off; -unsigned int value; -}; - -#define PLL_PARAM (_reg, _val) \ - { \ - .reg_off = (_reg), \ - .value = (_val), \ - } - -struct pll_setup_params { -struct pll_params_table *params_table; -unsigned int params_count; -/* Workaround for GP0, do not reset before configuring */ -bool no_init_reset; -/* Workaround for GP0, unreset right before checking for lock */ -bool clear_reset_for_lock; -/* Workaround for GXL GP0, reset in the lock checking loop */ -bool reset_lock_loop; -}; +#define CLK_MESON_PLL_LOCK_LOOP_RST BIT(0) -struct meson_clk_pll { -struct clk_hw hw; -void __iomem *base; +struct meson_clk_pll_data {struct parm m;struct parm n;struct parm frac;struct parm od;struct parm od2;struct parm od3; -const struct pll_setup_params params; -const struct pll_rate_table *rate_table; -unsigned int rate_count; -spinlock_t *lock; +struct parm l; +struct parm rst; +const struct reg_sequence *init_regs; +unsigned int init_count; +const struct pll_rate_table *table; +u8 flags; };#define to_meson_clk_pll (_hw) container_of(_hw, struct meson_clk_pll, hw)
drivers/clk/meson/gxbb.c +239 -185
506 lines not on this page · raw message
drivers/clk/meson/meson8b.c +87 -62
186 lines not on this page · raw message
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 16/19 clk: meson: split divider and gate part of mpll
In reply to Jerome BrunetThe mpll clock is a kind of fractional divider which can gate. When the RW operation have been added, enable/disable ops have been mistakenly inserted in this driver. These ops are essentially a poor copy/paste of generic gate ops.
This change remove the gate ops from the mpll driver and insert a generic gate clock on each mpll divider, simplifying the mpll driver and reducing code duplication.
--- drivers/clk/meson/axg.c | 100 +++++++++++++++++++++++++++++++------------ drivers/clk/meson/axg.h | 6 ++- drivers/clk/meson/clk-mpll.c | 44 ------------------- drivers/clk/meson/clkc.h | 1 - drivers/clk/meson/gxbb.c | 75 +++++++++++++++++++++++--------- drivers/clk/meson/gxbb.h | 5 ++- drivers/clk/meson/meson8b.c | 75 +++++++++++++++++++++++--------- drivers/clk/meson/meson8b.h | 6 ++- 8 files changed, 194 insertions(+), 118 deletions(-)
drivers/clk/meson/axg.c +72 -28
@@ -296,7 +296,7 @@ static struct clk_fixed_factor axg_fclk_div7 = { }, }; -static struct clk_regmap axg_mpll0 = { +static struct clk_regmap axg_mpll0_div = { .data = &(struct meson_clk_mpll_data ){ .sdm = { .reg_off =HHI_MPLL_CNTL7 ,
@@ -313,11 +313,6 @@ static struct clk_regmap axg_mpll0 = { .shift = 16, .width = 9, }, - .en = { - .reg_off = HHI_MPLL_CNTL7, - .shift = 14, - .width = 1, - }, .ssen = { .reg_off = HHI_MPLL_CNTL, .shift = 25,
@@ -331,14 +326,28 @@ static struct clk_regmap axg_mpll0 = { .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data ){ - .name ="mpll0" , + .name ="mpll0_div" , .ops = &meson_clk_mpll_ops, .parent_names = (const char *[]){"fixed_pll" }, .num_parents =1 , }, }; -static struct clk_regmap axg_mpll1 = { +static struct clk_regmap axg_mpll0 = { + .data = &(struct clk_regmap_gate_data ){ + .offset =HHI_MPLL_CNTL7 , + .bit_idx =14 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="mpll0" , + .ops = &clk_regmap_gate_ops, + .parent_names = (const char *[]){"mpll0_div" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +static struct clk_regmap axg_mpll1_div = { .data = &(struct meson_clk_mpll_data ){ .sdm = { .reg_off =HHI_MPLL_CNTL8 ,
@@ -355,11 +364,6 @@ static struct clk_regmap axg_mpll1 = { .shift = 16, .width = 9, }, - .en = { - .reg_off = HHI_MPLL_CNTL8, - .shift = 14, - .width = 1, - }, .misc = { .reg_off = HHI_PLL_TOP_MISC, .shift = 1,
@@ -368,14 +372,28 @@ static struct clk_regmap axg_mpll1 = { .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data ){ - .name ="mpll1" , + .name ="mpll1_div" , .ops = &meson_clk_mpll_ops, .parent_names = (const char *[]){"fixed_pll" }, .num_parents =1 , }, }; -static struct clk_regmap axg_mpll2 = { +static struct clk_regmap axg_mpll1 = { + .data = &(struct clk_regmap_gate_data ){ + .offset =HHI_MPLL_CNTL8 , + .bit_idx =14 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="mpll1" , + .ops = &clk_regmap_gate_ops, + .parent_names = (const char *[]){"mpll1_div" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +static struct clk_regmap axg_mpll2_div = { .data = &(struct meson_clk_mpll_data ){ .sdm = { .reg_off =HHI_MPLL_CNTL9 ,
@@ -392,11 +410,6 @@ static struct clk_regmap axg_mpll2 = { .shift = 16, .width = 9, }, - .en = { - .reg_off = HHI_MPLL_CNTL9, - .shift = 14, - .width = 1, - }, .misc = { .reg_off = HHI_PLL_TOP_MISC, .shift = 2,
@@ -405,14 +418,28 @@ static struct clk_regmap axg_mpll2 = { .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data ){ - .name ="mpll2" , + .name ="mpll2_div" , .ops = &meson_clk_mpll_ops, .parent_names = (const char *[]){"fixed_pll" }, .num_parents =1 , }, }; -static struct clk_regmap axg_mpll3 = { +static struct clk_regmap axg_mpll2 = { + .data = &(struct clk_regmap_gate_data ){ + .offset =HHI_MPLL_CNTL9 , + .bit_idx =14 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="mpll2" , + .ops = &clk_regmap_gate_ops, + .parent_names = (const char *[]){"mpll2_div" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +static struct clk_regmap axg_mpll3_div = { .data = &(struct meson_clk_mpll_data ){ .sdm = { .reg_off =HHI_MPLL3_CNTL0 ,
@@ -429,11 +456,6 @@ static struct clk_regmap axg_mpll3 = { .shift = 2, .width = 9, }, - .en = { - .reg_off = HHI_MPLL3_CNTL0, - .shift = 0, - .width = 1, - }, .misc = { .reg_off = HHI_PLL_TOP_MISC, .shift = 3,
@@ -442,13 +464,27 @@ static struct clk_regmap axg_mpll3 = { .lock = &meson_clk_lock, }, .hw.init = &(struct clk_init_data ){ - .name ="mpll3" , + .name ="mpll3_div" , .ops = &meson_clk_mpll_ops, .parent_names = (const char *[]){"fixed_pll" }, .num_parents =1 , }, }; +static struct clk_regmap axg_mpll3 = { + .data = &(struct clk_regmap_gate_data ){ + .offset =HHI_MPLL3_CNTL0 , + .bit_idx =0 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="mpll3" , + .ops = &clk_regmap_gate_ops, + .parent_names = (const char *[]){"mpll3_div" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; +static u32 mux_table_clk81[] = {0 ,2 ,3 ,4 ,5 ,6 ,7 };static const char *const clk81_parent_names[] = {"xtal" ,"fclk_div7" ,"mpll1" ,"mpll2" ,"fclk_div4" ,
@@ -722,6 +758,10 @@ static struct clk_hw_onecell_data axg_hw_onecell_data = { [CLKID_SD_EMMC_C_CLK0_SEL] = &axg_sd_emmc_c_clk0_sel.hw, [CLKID_SD_EMMC_C_CLK0_DIV] = &axg_sd_emmc_c_clk0_div.hw, [CLKID_SD_EMMC_C_CLK0] = &axg_sd_emmc_c_clk0.hw, + [CLKID_MPLL0_DIV] = &axg_mpll0_div.hw, + [CLKID_MPLL1_DIV] = &axg_mpll1_div.hw, + [CLKID_MPLL2_DIV] = &axg_mpll2_div.hw, + [CLKID_MPLL3_DIV] = &axg_mpll3_div.hw, [NR_CLKS ] =NULL , }, .num = NR_CLKS,
@@ -786,6 +826,10 @@ static struct clk_regmap *const axg_clk_regmaps[] = { &axg_mpll1, &axg_mpll2, &axg_mpll3, + &axg_mpll0_div, + &axg_mpll1_div, + &axg_mpll2_div, + &axg_mpll3_div, &axg_fixed_pll, &axg_sys_pll, &axg_gp0_pll,
drivers/clk/meson/axg.h +5 -1
@@ -117,8 +117,12 @@#define CLKID_SD_EMMC_B_CLK0_DIV 62#define CLKID_SD_EMMC_C_CLK0_SEL 63#define CLKID_SD_EMMC_C_CLK0_DIV 64 +#define CLKID_MPLL0_DIV 65 +#define CLKID_MPLL1_DIV 66 +#define CLKID_MPLL2_DIV 67 +#define CLKID_MPLL3_DIV 68 -#define NR_CLKS 65 +#define NR_CLKS 69/* include the CLKIDs that have been made part of the DT binding */ #include <dt-bindings/clock/axg-clkc.h>
drivers/clk/meson/clk-mpll.c +0 -44
57 lines not on this page · raw message
drivers/clk/meson/clkc.h +0 -1
@@ -116,7 +116,6 @@ struct meson_clk_mpll_data {struct parm sdm;struct parm sdm_en;struct parm n2; -struct parm en;struct parm ssen;struct parm misc;spinlock_t *lock;
drivers/clk/meson/gxbb.c +54 -21
141 lines not on this page · raw message
drivers/clk/meson/gxbb.h +4 -1
@@ -195,8 +195,11 @@#define CLKID_VAPB_0_DIV 134#define CLKID_VAPB_1_DIV 137#define CLKID_HDMI_PLL_PRE_MULT 141 +#define CLKID_MPLL0_DIV 142 +#define CLKID_MPLL1_DIV 143 +#define CLKID_MPLL2_DIV 144 -#define NR_CLKS 142 +#define NR_CLKS 145/* include the CLKIDs that have been made part of the DT binding */ #include <dt-bindings/clock/gxbb-clkc.h>
drivers/clk/meson/meson8b.c +54 -21
141 lines not on this page · raw message
drivers/clk/meson/meson8b.h +5 -1
@@ -69,7 +69,11 @@* will remain defined here. */ -#define CLK_NR_CLKS 96 +#define CLKID_MPLL0_DIV 96 +#define CLKID_MPLL1_DIV 97 +#define CLKID_MPLL2_DIV 98 + +#define CLK_NR_CLKS 99/* * include the CLKID and RESETID that have
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 17/19 clk: meson: rework meson8b cpu clock
In reply to Jerome BrunetInstead of migrating meson cpu_clk to clk_regmap, like the other meson clock drivers, we take advantage of the massive rework to get rid of it completely, and solve (the first part) of the related FIXME notice.
As pointed out in the code comments, the cpu_clk should be modeled with dividers and muxes it is made of, instead of one big composite clock.
The other issue pointed out in the FIXME note, around cpu notifier, remains unsolved, until CCR comes up.
AFAIK, the cpu_clk was not working correctly to enable dvfs on meson8b. This change being just a re-implementation, hopefully cleaner, of the cpu_clk, the problem remains unsolved as well.
--- drivers/clk/meson/meson8b.c | 203 ++++++++++++++++++++++++++++++++++---------- drivers/clk/meson/meson8b.h | 7 +- 2 files changed, 163 insertions(+), 47 deletions(-)
drivers/clk/meson/meson8b.c +157 -46
@@ -99,20 +99,6 @@ static const struct pll_rate_table sys_pll_rate_table[] = { { /* sentinel */ }, }; -static const struct clk_div_table cpu_div_table[] = { - { .val =1 , .div =1 }, - { .val =2 , .div =2 }, - { .val =3 , .div =3 }, - { .val =2 , .div =4 }, - { .val =3 , .div =6 }, - { .val =4 , .div =8 }, - { .val =5 , .div =10 }, - { .val =6 , .div =12 }, - { .val =7 , .div =14 }, - { .val =8 , .div =16 }, - {/* sentinel */ }, -}; -static struct clk_fixed_rate meson8b_xtal = { .fixed_rate =24000000 , .hw.init = &(struct clk_init_data ){
@@ -417,23 +403,6 @@ static struct clk_regmap meson8b_mpll2 = { }, }; -/* -* FIXME cpu clocks and the legacy composite clocks (e.g. clk81) are both PLL -* post-dividers and should be modeled with their respective PLLs via the -* forthcoming coordinated clock rates feature -*/ -static struct meson_clk_cpu meson8b_cpu_clk = { - .reg_off =HHI_SYS_CPU_CLK_CNTL1 , - .div_table = cpu_div_table, - .clk_nb.notifier_call = meson_clk_cpu_notifier_cb, - .hw.init = &(struct clk_init_data ){ - .name ="cpu_clk" , - .ops = &meson_clk_cpu_ops, - .parent_names = (const char *[]){"sys_pll" }, - .num_parents =1 , - }, -}; -static u32 mux_table_clk81[] = {6 ,5 ,7 };static struct clk_regmap meson8b_mpeg_clk_sel = { .data = &(struct clk_regmap_mux_data ){
@@ -486,6 +455,106 @@ struct clk_regmap meson8b_clk81 = { }, }; +struct clk_regmap meson8b_cpu_in_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL0 , + .mask =0x1 , + .shift =0 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_in_sel" , + .ops = &clk_regmap_mux_ops, + .parent_names = (const char *[]){"xtal" ,"sys_pll" }, + .num_parents =2 , + .flags = (CLK_SET_RATE_PARENT | +CLK_SET_RATE_NO_REPARENT ), + }, +}; + +static struct clk_fixed_factor meson8b_cpu_div2 = { + .mult =1 , + .div =2 , + .hw.init = &(struct clk_init_data ){ + .name ="cpu_div2" , + .ops = &clk_fixed_factor_ops, + .parent_names = (const char *[]){"cpu_in_sel" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +static struct clk_fixed_factor meson8b_cpu_div3 = { + .mult =1 , + .div =3 , + .hw.init = &(struct clk_init_data ){ + .name ="cpu_div3" , + .ops = &clk_fixed_factor_ops, + .parent_names = (const char *[]){"cpu_in_sel" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +static const struct clk_div_table cpu_div_table[] = { + { .val =2 , .div =4 }, + { .val =3 , .div =6 }, + { .val =4 , .div =8 }, + { .val =5 , .div =10 }, + { .val =6 , .div =12 }, + { .val =7 , .div =14 }, + { .val =8 , .div =16 }, + {/* sentinel */ }, +}; + +struct clk_regmap meson8b_cpu_div = { + .data = &(struct clk_regmap_div_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL1 , + .shift =20 , + .width =9 , + .table = cpu_div_table, + .flags =CLK_DIVIDER_ALLOW_ZERO , + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_div" , + .ops = &clk_regmap_divider_ops, + .parent_names = (const char *[]){"cpu_in_sel" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +struct clk_regmap meson8b_cpu_out_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL0 , + .mask =0x3 , + .shift =2 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_out_sel" , + .ops = &clk_regmap_mux_ops, + .parent_names = (const char *[]) {"cpu_in_sel" ,"cpu_div2" , +"cpu_div3" ,"cpu_div" }, + .num_parents =4 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +struct clk_regmap meson8b_cpu_clk = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL0 , + .mask =0x1 , + .shift =7 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_clk" , + .ops = &clk_regmap_mux_ops, + .parent_names = (const char *[]){"xtal" ,"cpu_out_sel" }, + .num_parents =2 , + .flags = (CLK_SET_RATE_PARENT | +CLK_SET_RATE_NO_REPARENT ), + }, +}; +/* Everything Else (EE) domain gates */ static MESON_GATE(meson8b_ddr, HHI_GCLK_MPEG0, 0);
@@ -670,6 +739,11 @@ static struct clk_hw_onecell_data meson8b_hw_onecell_data = { [CLKID_MPLL0_DIV] = &meson8b_mpll0_div.hw, [CLKID_MPLL1_DIV] = &meson8b_mpll1_div.hw, [CLKID_MPLL2_DIV] = &meson8b_mpll2_div.hw, + [CLKID_CPU_IN_SEL] = &meson8b_cpu_in_sel.hw, + [CLKID_CPU_DIV2] = &meson8b_cpu_div2.hw, + [CLKID_CPU_DIV3] = &meson8b_cpu_div3.hw, + [CLKID_CPU_DIV] = &meson8b_cpu_div.hw, + [CLKID_CPU_OUT_SEL] = &meson8b_cpu_out_sel.hw, [CLK_NR_CLKS ] =NULL , }, .num = CLK_NR_CLKS,
@@ -765,6 +839,49 @@ static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_fixed_pll, &meson8b_vid_pll, &meson8b_sys_pll, + &meson8b_cpu_in_sel, + &meson8b_cpu_div, + &meson8b_cpu_out_sel, + &meson8b_cpu_clk, +}; + +struct meson8b_nb_data { +struct notifier_block nb; +struct clk_hw_onecell_data *onecell_data; +}; + +int meson8b_clk_cpu_notifier_cb (struct notifier_block *nb, +unsigned long event,void *data) +{ +struct meson8b_nb_data *nb_data = + container_of(nb, struct meson8b_nb_data, nb); +struct clk_hw **hws = nb_data->onecell_data->hws; + +switch (event) { +case PRE_RATE_CHANGE : +clk_hw_reparent (hws[CLKID_CPUCLK ], + hws[CLKID_XTAL ]); +udelay (100 ); +clk_hw_reparent (hws[CLKID_CPU_IN_SEL ], + hws[CLKID_PLL_SYS ]); +break ; + +case POST_RATE_CHANGE : +clk_hw_reparent (hws[CLKID_CPUCLK ], + hws[CLKID_CPU_OUT_SEL ]); +udelay (100 ); +break ; + +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +static struct meson8b_nb_data cpu_nb_data = { + .nb.notifier_call = meson8b_clk_cpu_notifier_cb, + .onecell_data = &meson8b_hw_onecell_data, }; static const struct meson8b_clk_reset_line {
@@ -875,8 +992,7 @@ static const struct regmap_config clkc_regmap_config = {static int meson8b_clkc_probe (struct platform_device *pdev) {int ret, i; -struct clk_hw *parent_hw; -struct clk *parent_clk; +struct clk *clk;struct device *dev = &pdev->dev;struct regmap *map;
@@ -887,9 +1003,6 @@ static int meson8b_clkc_probe(struct platform_device *pdev)if (IS_ERR (map))return PTR_ERR (map); -/* Populate the base address for CPU clk */ - meson8b_cpu_clk.base = clk_base; -/* Populate regmap for the regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (meson8b_clk_regmaps); i++) meson8b_clk_regmaps[i]->map = map;
@@ -909,25 +1022,23 @@ static int meson8b_clkc_probe(struct platform_device *pdev) }/* -* Register CPU clk notifier +* Register sys clk notifier * -* FIXME this is wrong for a lot of reasons. First, the muxes should be -* struct clk_hw objects. Second, we shouldn't program the muxes in -* notifier handlers. The tricky programming sequence will be handled +* FIXME this is wrong, we shouldn't program the muxes in notifier +* handlers. The tricky programming sequence will be handled * by the forthcoming coordinated clock rates mechanism once that * feature is released. * -* Furthermore, looking up the parent this way is terrible. At some +* Furthermore, looking up the clk this way is terrible. At some * point we will stop allocating a default struct clk when registering * a new clk_hw, and this hack will no longer work. Releasing the ccr * feature before that time solves the problem :-) */ - parent_hw =clk_hw_get_parent (&meson8b_cpu_clk.hw); - parent_clk = parent_hw->clk; - ret =clk_notifier_register (parent_clk, &meson8b_cpu_clk.clk_nb); + clk = meson8b_hw_onecell_data.hws[CLKID_PLL_SYS ]->clk; + ret =clk_notifier_register (clk, &cpu_nb_data.nb);if (ret) { -pr_err ("%s: failed to register clock notifier for cpu_clk\n" , - __func__); +dev_err (dev, +"failed to register clock notifier for cpu clock\n" );return ret; }
drivers/clk/meson/meson8b.h +6 -1
@@ -72,8 +72,13 @@#define CLKID_MPLL0_DIV 96#define CLKID_MPLL1_DIV 97#define CLKID_MPLL2_DIV 98 +#define CLKID_CPU_IN_SEL 99 +#define CLKID_CPU_DIV2 100 +#define CLKID_CPU_DIV3 101 +#define CLKID_CPU_DIV 102 +#define CLKID_CPU_OUT_SEL 103 -#define CLK_NR_CLKS 99 +#define CLK_NR_CLKS 104/* * include the CLKID and RESETID that have
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 18/19 clk: meson: remove obsolete cpu_clk
In reply to Jerome Brunetmeson8b cpu_clk has been replaced by a set of divider and mux clocks. meson_cpu_clk is no longer used and can be removed
--- drivers/clk/meson/Makefile | 2 +- drivers/clk/meson/clk-cpu.c | 178 -------------------------------------------- drivers/clk/meson/clkc.h | 11 --- 3 files changed, 1 insertion(+), 190 deletions(-) delete mode 100644 drivers/clk/meson/clk-cpu.c
drivers/clk/meson/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for Meson specific clk # -obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-cpu.o clk-mpll.o clk-audio-divider.o +obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-mpll.o clk-audio-divider.o obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o obj-$(CONFIG_COMMON_CLK_GXBB) += gxbb.o gxbb-aoclk.o gxbb-aoclk-32k.o obj-$(CONFIG_COMMON_CLK_AXG) += axg.o
drivers/clk/meson/clk-cpu.c deleted +0 -178
178 lines not on this page · raw message
drivers/clk/meson/clkc.h +0 -11
@@ -101,17 +101,6 @@ struct meson_clk_pll_data {#define to_meson_clk_pll (_hw) container_of(_hw, struct meson_clk_pll, hw) -struct meson_clk_cpu { -struct clk_hw hw; -void __iomem *base; -u16 reg_off; -struct notifier_block clk_nb; -const struct clk_div_table *div_table; -}; - -int meson_clk_cpu_notifier_cb (struct notifier_block *nb,unsigned long event, -void *data); -struct meson_clk_mpll_data {struct parm sdm;struct parm sdm_en;
Signature · 1 line
2.14.3
Jerome Brunet
maintainerPATCH 19/19 clk: meson: use hhi syscon if available
In reply to Jerome BrunetOn gxbb and axg, try to get the hhi regmap from the parent DT node, which should be the HHI system controller once the necessary changes have been made in amlogic's DTs
Until then, if getting regmap through the system controller fails, the clock controller will fall back to the old way, requesting memory region directly and then registering the regmap itself.
This should allow a smooth transition to syscon
--- drivers/clk/meson/Kconfig | 2 ++ drivers/clk/meson/axg.c | 43 ++++++++++++++++++++++++++++++------------- drivers/clk/meson/gxbb.c | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 60 insertions(+), 24 deletions(-)
drivers/clk/meson/Kconfig +2 -0
@@ -22,6 +22,7 @@ config COMMON_CLK_GXBB depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER select COMMON_CLK_REGMAP_MESON + select MFD_SYSCON help Support for the clock controller on AmLogic S905 devices, aka gxbb. Say Y if you want peripherals and CPU frequency scaling to work.
@@ -31,6 +32,7 @@ config COMMON_CLK_AXG depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER select COMMON_CLK_REGMAP_MESON + select MFD_SYSCON help Support for the clock controller on AmLogic A113D devices, aka axg. Say Y if you want peripherals and CPU frequency scaling to work.
drivers/clk/meson/axg.c +30 -13
61 lines not on this page · raw message
drivers/clk/meson/gxbb.c +28 -11
@@ -22,6 +22,7 @@#include <linux/init.h> #include <linux/of_address.h> #include <linux/of_device.h> +#include <linux/mfd/syscon.h> #include <linux/platform_device.h> #include <linux/regmap.h>
@@ -2042,19 +2043,35 @@ static int gxbb_clkc_probe(struct platform_device *pdev)if (!clkc_data)return -EINVAL ; - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -if (!res) -return -EINVAL ; +/* Get the hhi system controller node if available */ + map =syscon_node_to_regmap (of_get_parent (dev->of_node)); +if (IS_ERR (map)) { +dev_err (dev, +"failed to get HHI regmap - Trying obsolete regs\n" ); - clk_base =devm_ioremap (dev, res->start,resource_size (res)); -if (!clk_base) { -pr_err ("%s: Unable to map clk base\n" , __func__); -return -ENXIO ; - } +/* +* FIXME: HHI registers should be accessed through +* the appropriate system controller. This is required because +* there is more than just clocks in this register space +* +* This fallback method is only provided temporarily until +* all the platform DTs are properly using the syscon node +*/ + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + + clk_base =devm_ioremap (dev, res->start,resource_size (res)); +if (!clk_base) { +dev_err (dev,"Unable to map clk base\n" ); +return -ENXIO ; + } - map =devm_regmap_init_mmio (dev, clk_base, &clkc_regmap_config); -if (IS_ERR (map)) -return PTR_ERR (map); + map =devm_regmap_init_mmio (dev, clk_base, + &clkc_regmap_config); +if (IS_ERR (map)) +return PTR_ERR (map); + }/* Populate regmap for the common regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (gx_clk_regmaps); i++)
Signature · 1 line
2.14.3
Re: [PATCH 17/19] clk: meson: rework meson8b cpu clock
In reply to Jerome BrunetHi Jerome,
Quoted 7 lines · Jerome Brunet
Instead of migrating meson
cpu_clktoclk_regmap, like the other meson clock drivers, we take advantage of the massive rework to get rid of it completely, and solve (the first part) of the related FIXME notice.As pointed out in the code comments, the
cpu_clkshould be modeled with dividers and muxes it is made of, instead of one big composite clock.
Quoted 6 lines
The other issue pointed out in the FIXME note, around cpu notifier, remains unsolved, until CCR comes up.
AFAIK, the
cpu_clkwas not working correctly to enable dvfs on meson8b. This change being just a re-implementation, hopefully cleaner, of thecpu_clk, the problem remains unsolved as well.
I can confirm that I have seen system lock-ups when using the cpu_clk implementation
your patch doesn't fully solve this (I still get some lock-ups), but I still think it's a step forward!
Quoted 1 line
Signed-off-by Jerome Brunet <[email protected]>
I have some minor comments below, with these addressed:
Quoted 106 lines
--- drivers/clk/meson/meson8b.c | 203 ++++++++++++++++++++++++++++++++++---------- drivers/clk/meson/meson8b.h | 7 +- 2 files changed, 163 insertions(+), 47 deletions(-)drivers/clk/meson/meson8b.c +48
-31@@ -99,20 +99,6 @@ static const struct pll_rate_table sys_pll_rate_table[] = { { /* sentinel */ }, }; -static const struct clk_div_table cpu_div_table[] = { - { .val =1 , .div =1 }, - { .val =2 , .div =2 }, - { .val =3 , .div =3 }, - { .val =2 , .div =4 }, - { .val =3 , .div =6 }, - { .val =4 , .div =8 }, - { .val =5 , .div =10 }, - { .val =6 , .div =12 }, - { .val =7 , .div =14 }, - { .val =8 , .div =16 }, - {/* sentinel */ }, -}; -static struct clk_fixed_rate meson8b_xtal = { .fixed_rate =24000000 , .hw.init = &(struct clk_init_data ){@@ -417,23 +403,6 @@ static struct clk_regmap meson8b_mpll2 = { }, }; -/* -* FIXME cpu clocks and the legacy composite clocks (e.g. clk81) are both PLL -* post-dividers and should be modeled with their respective PLLs via the -* forthcoming coordinated clock rates feature -*/ -static struct meson_clk_cpu meson8b_cpu_clk = { - .reg_off =HHI_SYS_CPU_CLK_CNTL1 , - .div_table = cpu_div_table, - .clk_nb.notifier_call = meson_clk_cpu_notifier_cb, - .hw.init = &(struct clk_init_data ){ - .name ="cpu_clk" , - .ops = &meson_clk_cpu_ops, - .parent_names = (const char *[]){"sys_pll" }, - .num_parents =1 , - }, -}; -static u32 mux_table_clk81[] = {6 ,5 ,7 };static struct clk_regmap meson8b_mpeg_clk_sel = { .data = &(struct clk_regmap_mux_data ){@@ -486,6 +455,106 @@ struct clk_regmap meson8b_clk81 = { }, }; +struct clk_regmap meson8b_cpu_in_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL0 , + .mask =0x1 , + .shift =0 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_in_sel" , + .ops = &clk_regmap_mux_ops, + .parent_names = (const char *[]){"xtal" ,"sys_pll" }, + .num_parents =2 , + .flags = (CLK_SET_RATE_PARENT | +CLK_SET_RATE_NO_REPARENT ), + }, +}; + +static struct clk_fixed_factor meson8b_cpu_div2 = { + .mult =1 , + .div =2 , + .hw.init = &(struct clk_init_data ){ + .name ="cpu_div2" , + .ops = &clk_fixed_factor_ops, + .parent_names = (const char *[]){"cpu_in_sel" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +static struct clk_fixed_factor meson8b_cpu_div3 = { + .mult =1 , + .div =3 , + .hw.init = &(struct clk_init_data ){ + .name ="cpu_div3" , + .ops = &clk_fixed_factor_ops, + .parent_names = (const char *[]){"cpu_in_sel" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +static const struct clk_div_table cpu_div_table[] = { + { .val =2 , .div =4 }, + { .val =3 , .div =6 }, + { .val =4 , .div =8 }, + { .val =5 , .div =10 }, + { .val =6 , .div =12 }, + { .val =7 , .div =14 }, + { .val =8 , .div =16 },
drivers/clk/meson/meson8b.c struct clk_regmap meson8b_clk81 = { · line 515
Quoted 10 lines
drivers/clk/meson/meson8b.c +10
-0+ { /* sentinel */ }, +}; + +struct clk_regmap meson8b_cpu_div = { + .data = &(struct clk_regmap_div_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL1 , + .shift =20 , + .width =9 , + .table = cpu_div_table, + .flags =CLK_DIVIDER_ALLOW_ZERO ,
looking at the Amlogic GPL kernel sources: [0]
they allow programming this divider with 0, however it seems that it's not allowed to select this in the mux below
during my tests this seems to have worked fine because the first parent of the mux below is cpu_in - which has the same rate as this divider with register value 0. in this scenario the common clock framework chooses the parent it finds first (cpu_in in this case - which is fine)
drivers/clk/meson/meson8b.c struct clk_regmap meson8b_clk81 = { · line 518
Quoted 3 lines
drivers/clk/meson/meson8b.c +3
-0+ }, + .hw.init = &(struct clk_init_data){ + .name ="cpu_div" ,
I suggest to call this "cpu_scale_div", so it matches the value we find in the public S805 datasheet on page 31: [1] (the same goes for the variable name above and the CLKID #define)
Quoted 5 lines
drivers/clk/meson/meson8b.c +5
-0+ .ops = &clk_regmap_divider_ops, + .parent_names = (const char *[]){ "cpu_in_sel" }, + .num_parents = 1, + .flags = CLK_SET_RATE_PARENT, + },
drivers/clk/meson/meson8b.c struct clk_regmap meson8b_clk81 = { · line 533
Quoted 10 lines
drivers/clk/meson/meson8b.c +10
-0+}; + +struct clk_regmap meson8b_cpu_out_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL0 , + .mask =0x3 , + .shift =2 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_out_sel" ,
I suggest to call this "cpu_scale_out_sel", so it matches the value we find in the public S805 datasheet on page 34: [1] (the same goes for the variable name above and the CLKID #define)
Quoted 166 lines
drivers/clk/meson/meson8b.c +81
-15+ .ops = &clk_regmap_mux_ops, + .parent_names = (const char *[]) { "cpu_in_sel", "cpu_div2", + "cpu_div3", "cpu_div" }, + .num_parents = 4, + .flags = CLK_SET_RATE_PARENT, + }, +}; + +struct clk_regmap meson8b_cpu_clk = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL0 , + .mask =0x1 , + .shift =7 , + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_clk" , + .ops = &clk_regmap_mux_ops, + .parent_names = (const char *[]){"xtal" ,"cpu_out_sel" }, + .num_parents =2 , + .flags = (CLK_SET_RATE_PARENT | +CLK_SET_RATE_NO_REPARENT ), + }, +}; +/* Everything Else (EE) domain gates */ static MESON_GATE(meson8b_ddr, HHI_GCLK_MPEG0, 0);@@ -670,6 +739,11 @@ static struct clk_hw_onecell_data meson8b_hw_onecell_data = { [CLKID_MPLL0_DIV] = &meson8b_mpll0_div.hw, [CLKID_MPLL1_DIV] = &meson8b_mpll1_div.hw, [CLKID_MPLL2_DIV] = &meson8b_mpll2_div.hw, + [CLKID_CPU_IN_SEL] = &meson8b_cpu_in_sel.hw, + [CLKID_CPU_DIV2] = &meson8b_cpu_div2.hw, + [CLKID_CPU_DIV3] = &meson8b_cpu_div3.hw, + [CLKID_CPU_DIV] = &meson8b_cpu_div.hw, + [CLKID_CPU_OUT_SEL] = &meson8b_cpu_out_sel.hw, [CLK_NR_CLKS ] =NULL , }, .num = CLK_NR_CLKS,@@ -765,6 +839,49 @@ static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_fixed_pll, &meson8b_vid_pll, &meson8b_sys_pll, + &meson8b_cpu_in_sel, + &meson8b_cpu_div, + &meson8b_cpu_out_sel, + &meson8b_cpu_clk, +}; + +struct meson8b_nb_data { +struct notifier_block nb; +struct clk_hw_onecell_data *onecell_data; +}; + +int meson8b_clk_cpu_notifier_cb (struct notifier_block *nb, +unsigned long event,void *data) +{ +struct meson8b_nb_data *nb_data = + container_of(nb, struct meson8b_nb_data, nb); +struct clk_hw **hws = nb_data->onecell_data->hws; + +switch (event) { +case PRE_RATE_CHANGE : +clk_hw_reparent (hws[CLKID_CPUCLK ], + hws[CLKID_XTAL ]); +udelay (100 ); +clk_hw_reparent (hws[CLKID_CPU_IN_SEL ], + hws[CLKID_PLL_SYS ]); +break ; + +case POST_RATE_CHANGE : +clk_hw_reparent (hws[CLKID_CPUCLK ], + hws[CLKID_CPU_OUT_SEL ]); +udelay (100 ); +break ; + +default : +return NOTIFY_DONE ; + } + +return NOTIFY_OK ; +} + +static struct meson8b_nb_data cpu_nb_data = { + .nb.notifier_call = meson8b_clk_cpu_notifier_cb, + .onecell_data = &meson8b_hw_onecell_data, }; static const struct meson8b_clk_reset_line {@@ -875,8 +992,7 @@ static const struct regmap_config clkc_regmap_config = {static int meson8b_clkc_probe (struct platform_device *pdev) {int ret, i; -struct clk_hw *parent_hw; -struct clk *parent_clk; +struct clk *clk;struct device *dev = &pdev->dev;struct regmap *map;@@ -887,9 +1003,6 @@ static int meson8b_clkc_probe(struct platform_device *pdev)if (IS_ERR (map))return PTR_ERR (map); -/* Populate the base address for CPU clk */ - meson8b_cpu_clk.base = clk_base; -/* Populate regmap for the regmap backed clocks */ for (i =0 ; i <ARRAY_SIZE (meson8b_clk_regmaps); i++) meson8b_clk_regmaps[i]->map = map;@@ -909,25 +1022,23 @@ static int meson8b_clkc_probe(struct platform_device *pdev) }/* -* Register CPU clk notifier +* Register sys clk notifier * -* FIXME this is wrong for a lot of reasons. First, the muxes should be -* struct clk_hw objects. Second, we shouldn't program the muxes in -* notifier handlers. The tricky programming sequence will be handled +* FIXME this is wrong, we shouldn't program the muxes in notifier +* handlers. The tricky programming sequence will be handled * by the forthcoming coordinated clock rates mechanism once that * feature is released. * -* Furthermore, looking up the parent this way is terrible. At some +* Furthermore, looking up the clk this way is terrible. At some * point we will stop allocating a default struct clk when registering * a new clk_hw, and this hack will no longer work. Releasing the ccr * feature before that time solves the problem :-) */ - parent_hw =clk_hw_get_parent (&meson8b_cpu_clk.hw); - parent_clk = parent_hw->clk; - ret =clk_notifier_register (parent_clk, &meson8b_cpu_clk.clk_nb); + clk = meson8b_hw_onecell_data.hws[CLKID_PLL_SYS ]->clk; + ret =clk_notifier_register (clk, &cpu_nb_data.nb);if (ret) { -pr_err ("%s: failed to register clock notifier for cpu_clk\n" , - __func__); +dev_err (dev, +"failed to register clock notifier for cpu clock\n" );return ret; }drivers/clk/meson/meson8b.h +6
-2@@ -72,8 +72,13 @@#define CLKID_MPLL0_DIV 96#define CLKID_MPLL1_DIV 97#define CLKID_MPLL2_DIV 98 +#define CLKID_CPU_IN_SEL 99 +#define CLKID_CPU_DIV2 100 +#define CLKID_CPU_DIV3 101 +#define CLKID_CPU_DIV 102 +#define CLKID_CPU_OUT_SEL 103 -#define CLK_NR_CLKS 99 +#define CLK_NR_CLKS 104/* * include the CLKID and RESETID that have -- 2.14.3
Quoted 4 lines
_______________________________________________
linux-amlogic mailing list
linux-amlogic at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
[0] https://github.com/endlessm/linux-meson/blob/03393bb8e8478626e03ee93b0a2a225d6de242b5/arch/arm/mach-meson8b/clock.c#L1349
[1] https://dn.odroid.com/S805/Datasheet/S805_Datasheet%20V0.8%2020150126.pdf
Re: [PATCH 18/19] clk: meson: remove obsolete cpu_clk
In reply to Jerome BrunetQuoted 2 lines · Jerome Brunet
meson8b
cpu_clkhas been replaced by a set of divider and mux clocks.meson_cpu_clkis no longer used and can be removed
as I mentioned in the other series: I've seen the system lock up with the "old" clk-cpu implementation.
the new code still seem to lock up in some cases, but now always (so I call it an improvement)
Quoted 1 line
Signed-off-by Jerome Brunet <[email protected]>
Quoted 234 lines
--- drivers/clk/meson/Makefile | 2 +- drivers/clk/meson/clk-cpu.c | 178 -------------------------------------------- drivers/clk/meson/clkc.h | 11 --- 3 files changed, 1 insertion(+), 190 deletions(-) delete mode 100644 drivers/clk/meson/clk-cpu.cdrivers/clk/meson/Makefile +1
-1@@ -2,7 +2,7 @@ # Makefile for Meson specific clk # -obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-cpu.o clk-mpll.o clk-audio-divider.o +obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-mpll.o clk-audio-divider.o obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o obj-$(CONFIG_COMMON_CLK_GXBB) += gxbb.o gxbb-aoclk.o gxbb-aoclk-32k.o obj-$(CONFIG_COMMON_CLK_AXG) += axg.odrivers/clk/meson/clk-cpu.c deleted +0
-178@@ -1,178 +0,0 @@ -/* -* Copyright (c) 2015 Endless Mobile, Inc. -* Author: Carlo Caione <[email protected]> -* -* This program is free software; you can redistribute it and/or modify it -* under the terms and conditions of the GNU General Public License, -* version 2, as published by the Free Software Foundation. -* -* This program is distributed in the hope it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. -* -* You should have received a copy of the GNU General Public License along with -* this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -/* -* CPU clock path: -* -* +-[/N]-----|3| -* MUX2 +--[/3]-+----------|2| MUX1 -* [sys_pll]---|1| |--[/2]------------|1|-|1| -* | |---+------------------|0| | |----- [a5_clk] -* +--|0| | | -* [xtal]---+-------------------------------|0| -* -* -* -*/ - -#include <linux/delay.h> -#include <linux/err.h> -#include <linux/io.h> -#include <linux/module.h> -#include <linux/of_address.h> -#include <linux/slab.h> -#include <linux/clk.h> -#include <linux/clk-provider.h> - -#define MESON_CPU_CLK_CNTL1 0x00 -#define MESON_CPU_CLK_CNTL 0x40 - -#define MESON_CPU_CLK_MUX1 BIT(7) -#define MESON_CPU_CLK_MUX2 BIT(0) - -#define MESON_N_WIDTH 9 -#define MESON_N_SHIFT 20 -#define MESON_SEL_WIDTH 2 -#define MESON_SEL_SHIFT 2 - -#include "clkc.h" - -#define to_meson_clk_cpu_hw (_hw) container_of(_hw, struct meson_clk_cpu, hw) -#define to_meson_clk_cpu_nb (_nb) container_of(_nb, struct meson_clk_cpu, clk_nb) - -static long meson_clk_cpu_round_rate (struct clk_hw *hw,unsigned long rate, -unsigned long *prate) -{ -struct meson_clk_cpu *clk_cpu =to_meson_clk_cpu_hw (hw); - -return divider_round_rate (hw, rate, prate, clk_cpu->div_table, -MESON_N_WIDTH ,CLK_DIVIDER_ROUND_CLOSEST ); -} - -static int meson_clk_cpu_set_rate (struct clk_hw *hw,unsigned long rate, -unsigned long parent_rate) -{ -struct meson_clk_cpu *clk_cpu =to_meson_clk_cpu_hw (hw); -unsigned int div, sel,N =0 ; -u32 reg; - - div =DIV_ROUND_UP (parent_rate, rate); - -if (div <=3 ) { - sel = div -1 ; - }else { - sel =3 ; -N = div /2 ; - } - - reg =readl (clk_cpu->base + clk_cpu->reg_off +MESON_CPU_CLK_CNTL1 ); - reg =PARM_SET (MESON_N_WIDTH ,MESON_N_SHIFT , reg,N ); -writel (reg, clk_cpu->base + clk_cpu->reg_off +MESON_CPU_CLK_CNTL1 ); - - reg =readl (clk_cpu->base + clk_cpu->reg_off +MESON_CPU_CLK_CNTL ); - reg =PARM_SET (MESON_SEL_WIDTH ,MESON_SEL_SHIFT , reg, sel); -writel (reg, clk_cpu->base + clk_cpu->reg_off +MESON_CPU_CLK_CNTL ); - -return 0 ; -} - -static unsigned long meson_clk_cpu_recalc_rate (struct clk_hw *hw, -unsigned long parent_rate) -{ -struct meson_clk_cpu *clk_cpu =to_meson_clk_cpu_hw (hw); -unsigned int N , sel; -unsigned int div =1 ; -u32 reg; - - reg =readl (clk_cpu->base + clk_cpu->reg_off +MESON_CPU_CLK_CNTL1 ); -N =PARM_GET (MESON_N_WIDTH ,MESON_N_SHIFT , reg); - - reg =readl (clk_cpu->base + clk_cpu->reg_off +MESON_CPU_CLK_CNTL ); - sel =PARM_GET (MESON_SEL_WIDTH ,MESON_SEL_SHIFT , reg); - -if (sel <3 ) - div = sel +1 ; -else - div =2 *N ; - -return parent_rate / div; -} - -/* FIXME MUX1 & MUX2 should be struct clk_hw objects */ -static int meson_clk_cpu_pre_rate_change (struct meson_clk_cpu *clk_cpu, -struct clk_notifier_data *ndata) -{ -u32 cpu_clk_cntl; - -/* switch MUX1 to xtal */ - cpu_clk_cntl =readl (clk_cpu->base + clk_cpu->reg_off - +MESON_CPU_CLK_CNTL ); - cpu_clk_cntl &= ~MESON_CPU_CLK_MUX1 ; -writel (cpu_clk_cntl, clk_cpu->base + clk_cpu->reg_off - +MESON_CPU_CLK_CNTL ); -udelay (100 ); - -/* switch MUX2 to sys-pll */ - cpu_clk_cntl |=MESON_CPU_CLK_MUX2 ; -writel (cpu_clk_cntl, clk_cpu->base + clk_cpu->reg_off - +MESON_CPU_CLK_CNTL ); - -return 0 ; -} - -/* FIXME MUX1 & MUX2 should be struct clk_hw objects */ -static int meson_clk_cpu_post_rate_change (struct meson_clk_cpu *clk_cpu, -struct clk_notifier_data *ndata) -{ -u32 cpu_clk_cntl; - -/* switch MUX1 to divisors' output */ - cpu_clk_cntl =readl (clk_cpu->base + clk_cpu->reg_off - +MESON_CPU_CLK_CNTL ); - cpu_clk_cntl |=MESON_CPU_CLK_MUX1 ; -writel (cpu_clk_cntl, clk_cpu->base + clk_cpu->reg_off - +MESON_CPU_CLK_CNTL ); -udelay (100 ); - -return 0 ; -} - -/* -* This clock notifier is called when the frequency of the of the parent -* PLL clock is to be changed. We use the xtal input as temporary parent -* while the PLL frequency is stabilized. -*/ -int meson_clk_cpu_notifier_cb (struct notifier_block *nb, -unsigned long event,void *data) -{ -struct clk_notifier_data *ndata = data; -struct meson_clk_cpu *clk_cpu =to_meson_clk_cpu_nb (nb); -int ret =0 ; - -if (event ==PRE_RATE_CHANGE ) - ret =meson_clk_cpu_pre_rate_change (clk_cpu, ndata); -else if (event ==POST_RATE_CHANGE ) - ret =meson_clk_cpu_post_rate_change (clk_cpu, ndata); - -return notifier_from_errno (ret); -} - -const struct clk_ops meson_clk_cpu_ops = { - .recalc_rate = meson_clk_cpu_recalc_rate, - .round_rate = meson_clk_cpu_round_rate, - .set_rate = meson_clk_cpu_set_rate, -};drivers/clk/meson/clkc.h +0
-12@@ -101,17 +101,6 @@ struct meson_clk_pll_data {#define to_meson_clk_pll (_hw) container_of(_hw, struct meson_clk_pll, hw) -struct meson_clk_cpu { -struct clk_hw hw; -void __iomem *base; -u16 reg_off; -struct notifier_block clk_nb; -const struct clk_div_table *div_table; -}; - -int meson_clk_cpu_notifier_cb (struct notifier_block *nb,unsigned long event, -void *data); -struct meson_clk_mpll_data {struct parm sdm;struct parm sdm_en; --2.14.3
_______________________________________________
linux-amlogic mailing list
linux-amlogic at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Re: [PATCH 08/19] clk: meson: add regmap to the clock controllers
In reply to Jerome BrunetQuoted 4 lines · Jerome Brunet
This change register a regmap in meson8b, gxbb and axg controllers. The clock are still accessing their registers directly through iomem. Once all clocks handled by these controllers have been move to regmap, the regmap register will be removed and replaced with a syscon request.
maybe you can add a comment that some of the registers from this area need to be accessed outside the clock driver (by the HDMI driver for example - which is the case on GX and Meson8/8b IIRC) if you have to re-spin this series
Quoted 1 line
Signed-off-by Jerome Brunet <[email protected]>
Quoted 217 lines
--- drivers/clk/meson/Kconfig | 2 ++ drivers/clk/meson/axg.c | 15 ++++++++++++++- drivers/clk/meson/gxbb.c | 33 +++++++++++++++++++++++---------- drivers/clk/meson/meson8b.c | 14 +++++++++++++- 4 files changed, 52 insertions(+), 12 deletions(-)drivers/clk/meson/Kconfig +2
-0@@ -11,6 +11,7 @@ config COMMON_CLK_MESON8B bool depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER + select REGMAP help Support for the clock controller on AmLogic S802 (Meson8), S805 (Meson8b) and S812 (Meson8m2) devices. Say Y if you@@ -29,6 +30,7 @@ config COMMON_CLK_AXG bool depends on COMMON_CLK_AMLOGIC select RESET_CONTROLLER + select REGMAP help Support for the clock controller on AmLogic A113D devices, aka axg. Say Y if you want peripherals and CPU frequency scaling to work.drivers/clk/meson/axg.c +14
-1@@ -11,10 +11,11 @@#include <linux/clk.h> #include <linux/clk-provider.h> +#include <linux/init.h> #include <linux/of_address.h> #include <linux/of_device.h> #include <linux/platform_device.h> -#include <linux/init.h> +#include <linux/regmap.h> #include "clkc.h" #include "axg.h" @@ -791,12 +792,19 @@ static const struct of_device_id clkc_match_table[] = { {} }; +static const struct regmap_config clkc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; +static int axg_clkc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;const struct clkc_data *clkc_data;struct resource *res;void __iomem *clk_base; +struct regmap *map;int ret, i; clkc_data =of_device_get_match_data (dev);@@ -807,12 +815,17 @@ static int axg_clkc_probe(struct platform_device *pdev) res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res)return -EINVAL ; + clk_base =devm_ioremap (dev, res->start,resource_size (res));if (!clk_base) {dev_err (dev,"Unable to map clk base\n" );return -ENXIO ; } + map =devm_regmap_init_mmio (dev, clk_base, &clkc_regmap_config); +if (IS_ERR (map)) +return PTR_ERR (map); +/* Populate base address for PLLs */ for (i =0 ; i < clkc_data->clk_plls_count; i++) clkc_data->clk_plls[i]->base = clk_base;drivers/clk/meson/gxbb.c +23
-10@@ -19,10 +19,11 @@#include <linux/clk.h> #include <linux/clk-provider.h> +#include <linux/init.h> #include <linux/of_address.h> #include <linux/of_device.h> #include <linux/platform_device.h> -#include <linux/init.h> +#include <linux/regmap.h> #include "clkc.h" #include "gxbb.h" @@ -1937,10 +1938,18 @@ static const struct of_device_id clkc_match_table[] = { {}, }; +static const struct regmap_config clkc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; +static int gxbb_clkc_probe (struct platform_device *pdev) {const struct clkc_data *clkc_data; +struct resource *res;void __iomem *clk_base; +struct regmap *map;int ret, i;struct device *dev = &pdev->dev;@@ -1948,13 +1957,20 @@ static int gxbb_clkc_probe(struct platform_device *pdev)if (!clkc_data)return -EINVAL ; -/* Generic clocks and PLLs */ - clk_base =of_iomap (dev->of_node,0 ); + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + + clk_base =devm_ioremap (dev, res->start,resource_size (res));if (!clk_base) {pr_err ("%s: Unable to map clk base\n" , __func__);return -ENXIO ; } + map =devm_regmap_init_mmio (dev, clk_base, &clkc_regmap_config); +if (IS_ERR (map)) +return PTR_ERR (map); +/* Populate base address for PLLs */ for (i =0 ; i < clkc_data->clk_plls_count; i++) clkc_data->clk_plls[i]->base = clk_base;@@ -1991,17 +2007,14 @@ static int gxbb_clkc_probe(struct platform_device *pdev) ret =devm_clk_hw_register (dev, clkc_data->hw_onecell_data->hws[i]); -if (ret) - goto iounmap; +if (ret) { +dev_err (dev,"Clock registration failed\n" ); +return ret; + } } -return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, clkc_data->hw_onecell_data); - -iounmap: -iounmap (clk_base); -return ret; }static struct platform_driver gxbb_driver = {drivers/clk/meson/meson8b.c +13
-2@@ -23,11 +23,12 @@#include <linux/clk.h> #include <linux/clk-provider.h> +#include <linux/init.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/reset-controller.h> #include <linux/slab.h> -#include <linux/init.h> +#include <linux/regmap.h> #include "clkc.h" #include "meson8b.h" @@ -804,16 +805,27 @@ static const struct reset_control_ops meson8b_clk_reset_ops = { .deassert = meson8b_clk_reset_deassert, }; +static const struct regmap_config clkc_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; +static int meson8b_clkc_probe (struct platform_device *pdev) {int ret, i;struct clk_hw *parent_hw;struct clk *parent_clk;struct device *dev = &pdev->dev; +struct regmap *map;if (!clk_base)return -ENXIO ; + map =devm_regmap_init_mmio (dev, clk_base, &clkc_regmap_config); +if (IS_ERR (map)) +return PTR_ERR (map); +/* Populate base address for PLLs */ for (i =0 ; i <ARRAY_SIZE (meson8b_clk_plls); i++) meson8b_clk_plls[i]->base = clk_base; --2.14.3
_______________________________________________
linux-amlogic mailing list
linux-amlogic at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Jerome Brunet
maintainerRe: [PATCH 17/19] clk: meson: rework meson8b cpu clock
In reply to Martin BlumenstinglQuoted 22 lines · Martin Blumenstingl
Hi Jerome,
Quoted 7 lines · Jerome Brunet
Instead of migrating meson
cpu_clktoclk_regmap, like the other meson clock drivers, we take advantage of the massive rework to get rid of it completely, and solve (the first part) of the related FIXME notice.As pointed out in the code comments, the
cpu_clkshould be modeled with dividers and muxes it is made of, instead of one big composite clock.Quoted 6 lines
The other issue pointed out in the FIXME note, around cpu notifier, remains unsolved, until CCR comes up.
AFAIK, the
cpu_clkwas not working correctly to enable dvfs on meson8b. This change being just a re-implementation, hopefully cleaner, of thecpu_clk, the problem remains unsolved as well.I can confirm that I have seen system lock-ups when using the
cpu_clkimplementation
your patch doesn't fully solve this (I still get some lock-ups), but I still think it's a step forward!
Quoted 4 lines
Quoted 1 line
Signed-off-by Jerome Brunet <[email protected]>I have some minor comments below, with these addressed:
Reviewed-by Martin Blumenstingl <[email protected]>
Thanks for reviewing this Martin.
I happy that changing the implementation of the cpu clock improve the situation. However, thinking about it, I'm not really confortable upstreaming something that we know is not stable yet, especially when it comes to the cpu clock.
To start, and until when get a stable solution, I would prefer to put the whole thing in read-only mode, and removing the notifier. The RW WIP is available here on the ML, so nothing is lost.
As a second step to progress on getting this clock stable, we could try to keep in the PLL Read-Only, but have the dividers in RW w/o a notifier : The goal would be to determine if we need to park the clock on xtal while changing the dividers. If we do, the notifier should probably be on SCALE_OUT_SEL instead of SYS_PLL.
This should already allow to adjust the clock quite lot, maybe it would be an interesting first step for a working dvfs on meson8.
Once we get this stable, we'll be able to throw the sys_pll in the mix.
Would you agree with this approach Martin ?
Quoted 1 line
[...]
Quoted 8 lines
drivers/clk/meson/meson8b.c struct clk_regmap meson8b_clk81 = { · line 515
Quoted 7 lines
drivers/clk/meson/meson8b.c +7
-0+struct clk_regmap meson8b_cpu_div = { + .data = &(struct clk_regmap_div_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL1 , + .shift =20 , + .width =9 , + .table = cpu_div_table, + .flags =CLK_DIVIDER_ALLOW_ZERO ,
Quoted 8 lines
looking at the Amlogic GPL kernel sources: [0]
they allow programming this divider with 0, however it seems that it's not allowed to select this in the mux below
during my tests this seems to have worked fine because the first parent of the mux below iscpu_in- which has the same rate as this divider with register value 0. in this scenario the common clock framework chooses the parent it finds first (cpu_inin this case - which is fine)
(It was a while ago but I think) I put this flag to avoid warning on boot because the register value could be 0 by default, when the clock is not used.
When the clock is set by the CCF, it won't ever put 0 because zero is not part of the divider table provided with this clock. So, as soon as a set_rate() call reaches this clock, the zero value will go away and won't ever come back.
Quoted 8 lines
drivers/clk/meson/meson8b.c struct clk_regmap meson8b_clk81 = { · line 518
Quoted 4 lines
drivers/clk/meson/meson8b.c +3
-0+ }, + .hw.init = &(struct clk_init_data){ + .name ="cpu_div" ,I suggest to call this "
cpu_scale_div", so it matches the value we find in the public S805 datasheet on page 31: [1] (the same goes for the variable name above and the CLKID #define)
No problem, will do.
Quoted 12 lines
Quoted 12 lines
drivers/clk/meson/meson8b.c +11
-0+ .ops = &clk_regmap_divider_ops, + .parent_names = (const char *[]){ "cpu_in_sel" }, + .num_parents = 1, + .flags = CLK_SET_RATE_PARENT, + }, +}; + +struct clk_regmap meson8b_cpu_out_sel = { + .data = &(struct clk_regmap_mux_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL0 , + .mask =0x3 ,
Quoted 8 lines
drivers/clk/meson/meson8b.c struct clk_regmap meson8b_clk81 = { · line 533
Quoted 4 lines
drivers/clk/meson/meson8b.c +4
-0+ .shift = 2, + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_out_sel" ,I suggest to call this "
cpu_scale_out_sel", so it matches the value we find in the public S805 datasheet on page 34: [1] (the same goes for the variable name above and the CLKID #define)
Sure.
Jerome Brunet
maintainerRe: [PATCH 08/19] clk: meson: add regmap to the clock controllers
In reply to Martin BlumenstinglQuoted 10 lines · Martin Blumenstingl
Quoted 4 lines · Jerome Brunet
This change register a regmap in meson8b, gxbb and axg controllers. The clock are still accessing their registers directly through iomem. Once all clocks handled by these controllers have been move to regmap, the regmap register will be removed and replaced with a syscon request.
maybe you can add a comment that some of the registers from this area need to be accessed outside the clock driver (by the HDMI driver for example - which is the case on GX and Meson8/8b IIRC) if you have to re-spin this series
I think it was mentioned in the cover letter, but you are right, I should mention it here as well.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Jerome Brunet <[email protected]>
Re: [PATCH 05/19] clk: meson: add regmap clocks
In reply to Jerome BrunetHI Jerome:
Quoted 302 lines · Jerome Brunet
Meson clock controllers needs to move the classical iomem registers to regmap. This is triggered because the HHI controllers found on the GXBB and GXL host more than just clocks. To properly handle this, we would like to migrate HHI to syscon. Also GXBB AO clock controller already use regmap, AXG AO and Audio clock controllers will as well.
The purpose of this change is to provide a common structure to these meson controllers (and possibly others) for regmap based clocks.
This change provides the basic gate, mux and divider, based on the helpers provided by the related generic clocks
Signed-off-by Jerome Brunet <[email protected]>--- drivers/clk/meson/Kconfig | 4 + drivers/clk/meson/Makefile | 1 + drivers/clk/meson/clk-regmap.c | 166 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/meson/clk-regmap.h | 111 +++++++++++++++++++++++++++ 4 files changed, 282 insertions(+) create mode 100644 drivers/clk/meson/clk-regmap.c create mode 100644 drivers/clk/meson/clk-regmap.hdrivers/clk/meson/Kconfig +4
-0@@ -3,6 +3,10 @@ config COMMON_CLK_AMLOGIC depends on OF depends on ARCH_MESON || COMPILE_TEST +config COMMON_CLK_REGMAP_MESON + bool + select REGMAP + config COMMON_CLK_MESON8B bool depends on COMMON_CLK_AMLOGICdrivers/clk/meson/Makefile +1
-0@@ -6,3 +6,4 @@ obj-$(CONFIG_COMMON_CLK_AMLOGIC) += clk-pll.o clk-cpu.o clk-mpll.o clk-audio-div obj-$(CONFIG_COMMON_CLK_MESON8B) += meson8b.o obj-$(CONFIG_COMMON_CLK_GXBB) += gxbb.o gxbb-aoclk.o gxbb-aoclk-regmap.o gxbb-aoclk-32k.o obj-$(CONFIG_COMMON_CLK_AXG) += axg.o +obj-$(CONFIG_COMMON_CLK_REGMAP_MESON) += clk-regmap.odrivers/clk/meson/clk-regmap.c new file +166
-0@@ -0,0 +1,166 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2018 BayLibre, SAS. +// Author: Jerome Brunet <[email protected]> + +#include "clk-regmap.h" + +static int clk_regmap_gate_endisable (struct clk_hw *hw,int enable) +{ +struct clk_regmap *clk =to_clk_regmap (hw); +struct clk_regmap_gate_data *gate =clk_get_regmap_gate_data (clk); +int set = gate->flags &CLK_GATE_SET_TO_DISABLE ?1 :0 ; + + set ^= enable; + +return regmap_update_bits (clk->map, gate->offset,BIT (gate->bit_idx), + set ?BIT (gate->bit_idx) :0 ); +} + +static int clk_regmap_gate_enable (struct clk_hw *hw) +{ +return clk_regmap_gate_endisable (hw,1 ); +} + +static void clk_regmap_gate_disable (struct clk_hw *hw) +{ +clk_regmap_gate_endisable (hw,0 ); +} + +static int clk_regmap_gate_is_enabled (struct clk_hw *hw) +{ +struct clk_regmap *clk =to_clk_regmap (hw); +struct clk_regmap_gate_data *gate =clk_get_regmap_gate_data (clk); +unsigned int val; + +regmap_read (clk->map, gate->offset, &val); +if (gate->flags &CLK_GATE_SET_TO_DISABLE ) + val ^=BIT (gate->bit_idx); + + val &=BIT (gate->bit_idx); + +return val ?1 :0 ; +} + +const struct clk_ops clk_regmap_gate_ops = { + .enable = clk_regmap_gate_enable, + .disable = clk_regmap_gate_disable, + .is_enabled = clk_regmap_gate_is_enabled, +}; +EXPORT_SYMBOL_GPL (clk_regmap_gate_ops); + +static unsigned long clk_regmap_div_recalc_rate (struct clk_hw *hw, +unsigned long prate) +{ +struct clk_regmap *clk =to_clk_regmap (hw); +struct clk_regmap_div_data *div =clk_get_regmap_div_data (clk); +unsigned int val; +int ret; + + ret =regmap_read (clk->map, div->offset, &val); +if (ret) +/* Gives a hint that something is wrong */ +return 0 ; + + val >>= div->shift; + val &=clk_div_mask (div->width); +return divider_recalc_rate (hw, prate, val, div->table, div->flags, + div->width); +} + +static long clk_regmap_div_round_rate (struct clk_hw *hw,unsigned long rate, +unsigned long *prate) +{ +struct clk_regmap *clk =to_clk_regmap (hw); +struct clk_regmap_div_data *div =clk_get_regmap_div_data (clk); +unsigned int val; +int ret; + +/* if read only, just return current value */ +if (div->flags &CLK_DIVIDER_READ_ONLY ) { + ret =regmap_read (clk->map, div->offset, &val); +if (ret) +/* Gives a hint that something is wrong */ +return 0 ; + + val >>= div->shift; + val &=clk_div_mask (div->width); + +return divider_ro_round_rate (hw, rate, prate, div->table, + div->width, div->flags, val); + } + +return divider_round_rate (hw, rate, prate, div->table, div->width, + div->flags); +} + +static int clk_regmap_div_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +struct clk_regmap *clk =to_clk_regmap (hw); +struct clk_regmap_div_data *div =clk_get_regmap_div_data (clk); +unsigned int val; +int ret; + + ret =divider_get_val (rate, parent_rate, div->table, div->width, + div->flags); +if (ret <0 ) +return ret; + + val = (unsigned int )ret << div->shift; +return regmap_update_bits (clk->map, div->offset, +clk_div_mask (div->width) << div->shift, val); +}; + +/* Would prefer clk_regmap_div_ro_ops but clashes with qcom */ + +const struct clk_ops clk_regmap_divider_ops = { + .recalc_rate = clk_regmap_div_recalc_rate, + .round_rate = clk_regmap_div_round_rate, + .set_rate = clk_regmap_div_set_rate, +}; +EXPORT_SYMBOL_GPL (clk_regmap_divider_ops); + +const struct clk_ops clk_regmap_divider_ro_ops = { + .recalc_rate = clk_regmap_div_recalc_rate, + .round_rate = clk_regmap_div_round_rate, +}; +EXPORT_SYMBOL_GPL (clk_regmap_divider_ro_ops); + +static u8 clk_regmap_mux_get_parent (struct clk_hw *hw) +{ +struct clk_regmap *clk =to_clk_regmap (hw); +struct clk_regmap_mux_data *mux =clk_get_regmap_mux_data (clk); +unsigned int val; +int ret; + + ret =regmap_read (clk->map, mux->offset, &val); +if (ret) +return ret; + + val >>= mux->shift; + val &= mux->mask; +return clk_mux_val_to_index (hw, mux->table, mux->flags, val); +} + +static int clk_regmap_mux_set_parent (struct clk_hw *hw,u8 index) +{ +struct clk_regmap *clk =to_clk_regmap (hw); +struct clk_regmap_mux_data *mux =clk_get_regmap_mux_data (clk); +unsigned int val =clk_mux_index_to_val (mux->table, mux->flags, index); + +return regmap_update_bits (clk->map, mux->offset, + mux->mask << mux->shift, + val << mux->shift); +} + +const struct clk_ops clk_regmap_mux_ops = { + .get_parent = clk_regmap_mux_get_parent, + .set_parent = clk_regmap_mux_set_parent, + .determine_rate = __clk_mux_determine_rate, +}; +EXPORT_SYMBOL_GPL (clk_regmap_mux_ops); + +const struct clk_ops clk_regmap_mux_ro_ops = { + .get_parent = clk_regmap_mux_get_parent, +}; +EXPORT_SYMBOL_GPL (clk_regmap_mux_ro_ops);drivers/clk/meson/clk-regmap.h new file +78
-0@@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2018 BayLibre, SAS. +// Author: Jerome Brunet <[email protected]> + +#ifndef __CLK_REGMAP_H +#define __CLK_REGMAP_H + +#include <linux/clk-provider.h> +#include <linux/regmap.h> + +/** +* struct clk_regmap - regmap backed clock +* +* @hw: handle between common and hardware-specific interfaces +* @map: pointer to the regmap structure controlling the clock +* @data: data specific to the clock type +* +* Clock which is controlled by regmap backed registers. The actual type of +* of the clock is controlled by the clock_ops and data. +*/ +struct clk_regmap { +struct clk_hw hw; +struct regmap *map; +void *data; +}; + +#define to_clk_regmap (_hw) container_of(_hw, struct clk_regmap, hw) + +/** +* struct clk_regmap_gate_data - regmap backed gate specific data +* +* @offset: offset of the register controlling gate +* @bit_idx: single bit controlling gate +* @flags: hardware-specific flags +* +* Flags: +* Same as clk_gate except CLK_GATE_HIWORD_MASK which is ignored +*/ +struct clk_regmap_gate_data { +unsigned int offset; +u8 bit_idx; +u8 flags; +}; + +static inline struct clk_regmap_gate_data * +clk_get_regmap_gate_data (struct clk_regmap *clk) +{ +return (struct clk_regmap_gate_data *)clk->data; +} + +extern const struct clk_ops clk_regmap_gate_ops; + +/** +* struct clk_regmap_div_data - regmap backed adjustable divider specific data +* +* @offset: offset of the register controlling the divider +* @shift: shift to the divider bit field +* @width: width of the divider bit field +* @table: array of value/divider pairs, last entry should have div = 0 +* +* Flags: +* Same as clk_divider except CLK_DIVIDER_HIWORD_MASK which is ignored +*/ +struct clk_regmap_div_data { +unsigned int offset; +u8 shift; +u8 width; +u8 flags; +const struct clk_div_table *table; +}; + +static inline struct clk_regmap_div_data * +clk_get_regmap_div_data (struct clk_regmap *clk) +{ +return (struct clk_regmap_div_data *)clk->data; +} + +extern const struct clk_ops clk_regmap_divider_ops;
drivers/clk/meson/clk-regmap.h line 88
Quoted 10 lines
drivers/clk/meson/clk-regmap.h new file +10
-0+extern const struct clk_ops clk_regmap_divider_ro_ops; + +/** +* struct clk_regmap_mux_data - regmap backed multiplexer clock specific data +* +* @hw: handle between common and hardware-specific interfaces +* @offset: offset of theregister controlling multiplexer +* @table: array of parent indexed register values +* @shift: shift to multiplexer bit field +* @width: width of mutliplexer bit field
~~~~~~ this is wrong, please update to keep it sync with the
struct definition
drivers/clk/meson/clk-regmap.h line 97
Quoted 9 lines
drivers/clk/meson/clk-regmap.h new file +9
-0+* @flags: hardware-specific flags +* +* Flags: +* Same as clk_divider except CLK_MUX_HIWORD_MASK which is ignored +*/ +struct clk_regmap_mux_data { +unsigned int offset; +u32 *table; +u32 mask;
~~~~~ here
Quoted 15 lines
drivers/clk/meson/clk-regmap.h new file +14
-0+u8 shift; + u8 flags; +}; + +static inline struct clk_regmap_mux_data * +clk_get_regmap_mux_data (struct clk_regmap *clk) +{ +return (struct clk_regmap_mux_data *)clk->data; +} + +extern const struct clk_ops clk_regmap_mux_ops; +extern const struct clk_ops clk_regmap_mux_ro_ops; + +#endif /* __CLK_REGMAP_H */
Jerome Brunet
maintainerRe: [PATCH 05/19] clk: meson: add regmap clocks
Quoted 11 lines · Yixun Lan
Quoted 8 lines
+/**
+ * structclk_regmap_mux_data- regmap backed multiplexer clock specific data
+ *
+ * @hw: handle between common and hardware-specific interfaces+ * @offset: offset of theregister controlling multiplexer + * @table: array of parent indexed register values + * @shift: shift to multiplexer bit field + * @width: width of mutliplexer bit field~~~~~~ this is wrong, please update to keep it sync with the
struct definition
Indeed, it is.
This is just a copy/paste of the mux documentation provided in include/linux/clk-provider.h ... which is also inaccurate.
Thanks for pointing it out
Quoted 16 lines
drivers/clk/meson/clk-regmap.h line 97
Quoted 10 lines
+ * @flags: hardware-specific flags
+ *
+ * Flags:
+ * Same asclk_dividerexceptCLK_MUX_HIWORD_MASKwhich is ignored
+ */drivers/clk/meson/clk-regmap.h new file +4
-0+struct clk_regmap_mux_data { +unsigned int offset; +u32 *table; +u32 mask;~~~~~ hereQuoted 4 lines
drivers/clk/meson/clk-regmap.h new file +4
-0+u8 shift; +u8 flags; +}; +