clk: meson: use regmap in clock controllers
Jerome Brunet
maintainerv2 cover 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. As explained by Martin, the old cpu_clk would hang quite often when changing the rate of the cpu clock. Surprisingly, the new implementation improved the situation a bit, but still hangs from time to time. As this is not acceptable, the cpu clk subtree as been switched to a read-only mode, preventing any change of the cpu rate, until an acceptable solution is found.
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]
Changes since v1 [3]:
* Fixed a few typos in patches descriptions
* Fixed cpu clock names on meson8b, as suggested by Martin
* Switched cpu clock subtree to reead-only mode
* Fix clk_regmap mux documentation, as reported by Yixun
[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.17/meson/clk-regmap
[1]: https://lkml.kernel.org/r/20180131180945.18025-1-jbrunet at baylibre.com
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 | 1402 ++++++++++++++++++--------------- drivers/clk/meson/gxbb.h | 5 +- drivers/clk/meson/meson8b.c | 588 ++++++++------ drivers/clk/meson/meson8b.h | 11 +- 18 files changed, 1978 insertions(+), 1833 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 v2 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 v2 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 v2 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 v2 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 v2 5/19 clk: meson: add regmap clocks
In reply to Jerome BrunetMeson clock controllers need 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 v2 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 v2 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 v2 8/19 clk: meson: add regmap to the clock controllers
In reply to Jerome BrunetThis change registers 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.
This is needed because other drivers, such as the HDMI driver, need to access the HHI register region
--- 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 v2 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 | 266 +++++++++++++++++++++++--------------------- drivers/clk/meson/meson8b.c | 39 +++---- 5 files changed, 206 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 +137 -129
429 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 v2 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 v2 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 | 310 +++++++++++++++++++++----------------------- drivers/clk/meson/meson8b.c | 27 ++-- 3 files changed, 184 insertions(+), 213 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 -160
504 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 v2 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 fields with regmap helps to 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 v2 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 v2 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 v2 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 was 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 =16 , - .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 =16 , + .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 v2 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 the generic gate ops.
This change removes the gate ops from the mpll driver and inserts 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 | 78 ++++++++++++++++++++++++--------- drivers/clk/meson/gxbb.h | 5 ++- drivers/clk/meson/meson8b.c | 75 +++++++++++++++++++++++--------- drivers/clk/meson/meson8b.h | 6 ++- 8 files changed, 197 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 +57 -21
150 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 v2 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 cpu_clk was not working correctly to enable dvfs on meson8b. It hangs quite often when changing the cpu clock rate. This new implementation, based on simple elements improves the situation but the platform will still hang from time to time. This is not acceptable so, until we can make the mechanism around the cpu clock stable, the cpu clock subtree has been put in read-only mode, preventing any change of the cpu clock
The notifier and read-write operation will be added back when we have a solution to the problem.
--- drivers/clk/meson/meson8b.c | 173 +++++++++++++++++++++++++++++--------------- drivers/clk/meson/meson8b.h | 7 +- 2 files changed, 119 insertions(+), 61 deletions(-)
drivers/clk/meson/meson8b.c +113 -60
@@ -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 ){
@@ -227,7 +213,7 @@ static struct clk_regmap meson8b_sys_pll = { }, .hw.init = &(struct clk_init_data){ .name ="sys_pll" , - .ops = &meson_clk_pll_ops, + .ops = &meson_clk_pll_ro_ops, .parent_names = (const char *[]){"xtal" }, .num_parents =1 , .flags =CLK_GET_RATE_NOCACHE ,
@@ -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,108 @@ 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_ro_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_scale_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_scale_div = { + .data = &(struct clk_regmap_div_data ){ + .offset =HHI_SYS_CPU_CLK_CNTL1 , + .shift =20 , + .width =9 , + .table = cpu_scale_table, + .flags =CLK_DIVIDER_ALLOW_ZERO , + }, + .hw.init = &(struct clk_init_data ){ + .name ="cpu_scale_div" , + .ops = &clk_regmap_divider_ro_ops, + .parent_names = (const char *[]){"cpu_in_sel" }, + .num_parents =1 , + .flags =CLK_SET_RATE_PARENT , + }, +}; + +struct clk_regmap meson8b_cpu_scale_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_scale_out_sel" , + .ops = &clk_regmap_mux_ro_ops, + .parent_names = (const char *[]) {"cpu_in_sel" , +"cpu_div2" , +"cpu_div3" , +"cpu_scale_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_ro_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 +741,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_SCALE_DIV] = &meson8b_cpu_scale_div.hw, + [CLKID_CPU_SCALE_OUT_SEL] = &meson8b_cpu_scale_out_sel.hw, [CLK_NR_CLKS ] =NULL , }, .num = CLK_NR_CLKS,
@@ -765,6 +841,10 @@ static struct clk_regmap *const meson8b_clk_regmaps[] = { &meson8b_fixed_pll, &meson8b_vid_pll, &meson8b_sys_pll, + &meson8b_cpu_in_sel, + &meson8b_cpu_scale_div, + &meson8b_cpu_scale_out_sel, + &meson8b_cpu_clk, }; static const struct meson8b_clk_reset_line {
@@ -875,8 +955,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 +966,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;
@@ -908,29 +984,6 @@ static int meson8b_clkc_probe(struct platform_device *pdev)return ret; } -/* -* Register CPU 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 -* by the forthcoming coordinated clock rates mechanism once that -* feature is released. -* -* Furthermore, looking up the parent 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); -if (ret) { -pr_err ("%s: failed to register clock notifier for cpu_clk\n" , - __func__); -return ret; - } -return devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, &meson8b_hw_onecell_data); }
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_SCALE_DIV 102 +#define CLKID_CPU_SCALE_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
Re: [PATCH v2 17/19] clk: meson: rework meson8b cpu clock
Quoted 14 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.The
cpu_clkwas not working correctly to enable dvfs on meson8b. It hangs quite often when changing the cpu clock rate. This new implementation, based on simple elements improves the situation but the platform will still hang from time to time. This is not acceptable so, until we can make the mechanism around the cpu clock stable, the cpu clock subtree has been put in read-only mode, preventing any change of the cpu clock
Quoted 5 lines
The notifier and read-write operation will be added back when we have a solution to the problem.
Cc Martin Blumenstingl <[email protected]>Signed-off-by Jerome Brunet <[email protected]>
thank you Jerome!
Jerome Brunet
maintainerPATCH v2 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 v2 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>
@@ -2045,19 +2046,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
Neil Armstrong
AppliedQuoted 93 lines · Jerome Brunet
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_clkof meson8b.The new code around the cpu clk of the meson8b is just re-implementation, using simple elements, of the old
cpu_clk. As explained by Martin, the oldcpu_clkwould hang quite often when changing the rate of the cpu clock. Surprisingly, the new implementation improved the situation a bit, but still hangs from time to time. As this is not acceptable, the cpu clk subtree as been switched to a read-only mode, preventing any change of the cpu rate, until an acceptable solution is found.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]
Changes since v1 [3]:
* Fixed a few typos in patches descriptions
* Fixed cpu clock names on meson8b, as suggested by Martin
* Switched cpu clock subtree to reead-only mode
* Fixclk_regmapmux documentation, as reported by Yixun[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.17/meson/clk-regmap
[1]: https://lkml.kernel.org/r/20180131180945.18025-1-jbrunet at baylibre.comJerome Brunet (19):
clk: meson: use dev pointer where possible
clk: meson: usedevm_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 gxbbao_clktoclk_regmap
clk: meson: remove supersededaoclk_gate_regmap
clk: meson: add regmap to the clock controllers
clk: meson: migrate gates toclk_regmap
clk: meson: migrate dividers toclk_regmap
clk: meson: migrate muxes toclk_regmap
clk: meson: add regmap helpers for parm
clk: meson: migrate mplls clocks toclk_regmap
clk: meson: migrate the audio divider clock toclk_regmap
clk: meson: migrate plls clocks toclk_regmap
clk: meson: split divider and gate part of mpll
clk: meson: rework meson8b cpu clock
clk: meson: remove obsoletecpu_clk
clk: meson: use hhi syscon if availabledrivers/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 | 1402 ++++++++++++++++++---------------
Quoted 9 lines
drivers/clk/meson/gxbb.h | 5 +- drivers/clk/meson/meson8b.c | 588 ++++++++------ drivers/clk/meson/meson8b.h | 11 +- 18 files changed, 1978 insertions(+), 1833 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
Tested on Odroid-C2 & LibreTech-CC,
Applied to meson's next/drivers tree after merge of clk-next to satisfy the dependencies.
Neil
Bonjour Jerome,
Excerpts from Jerome Brunet's message of February 12, 2018 6:58 am:
Quoted 37 lines
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_clkof meson8b.The new code around the cpu clk of the meson8b is just re-implementation, using simple elements, of the old
cpu_clk. As explained by Martin, the oldcpu_clkwould hang quite often when changing the rate of the cpu clock. Surprisingly, the new implementation improved the situation a bit, but still hangs from time to time. As this is not acceptable, the cpu clk subtree as been switched to a read-only mode, preventing any change of the cpu rate, until an acceptable solution is found.
Quoted 5 lines
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.
Looks OK to me. As we discussed off-list, can you send this (and the other meson patches) as a PR based on top of the clk-helpers branch in the clk git tree? That should satisfy the dependencies (I hope).
Best regards,
Mike
Quoted 64 lines
Based on this changeset, more patches are coming. For those interested, the WIP is available here [2]
Changes since v1 [3]:
* Fixed a few typos in patches descriptions
* Fixed cpu clock names on meson8b, as suggested by Martin
* Switched cpu clock subtree to reead-only mode
* Fixclk_regmapmux documentation, as reported by Yixun[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.17/meson/clk-regmap
[1]: https://lkml.kernel.org/r/20180131180945.18025-1-jbrunet at baylibre.comJerome Brunet (19):
clk: meson: use dev pointer where possible
clk: meson: usedevm_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 gxbbao_clktoclk_regmap
clk: meson: remove supersededaoclk_gate_regmap
clk: meson: add regmap to the clock controllers
clk: meson: migrate gates toclk_regmap
clk: meson: migrate dividers toclk_regmap
clk: meson: migrate muxes toclk_regmap
clk: meson: add regmap helpers for parm
clk: meson: migrate mplls clocks toclk_regmap
clk: meson: migrate the audio divider clock toclk_regmap
clk: meson: migrate plls clocks toclk_regmap
clk: meson: split divider and gate part of mpll
clk: meson: rework meson8b cpu clock
clk: meson: remove obsoletecpu_clk
clk: meson: use hhi syscon if availabledrivers/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 | 1402 ++++++++++++++++++--------------- drivers/clk/meson/gxbb.h | 5 +- drivers/clk/meson/meson8b.c | 588 ++++++++------ drivers/clk/meson/meson8b.h | 11 +- 18 files changed, 1978 insertions(+), 1833 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.cSignature · 1 line
2.14.3