Commit 179c8fb3 authored by Linus Walleij's avatar Linus Walleij

clk: versatile-icst: convert to use regmap

Instead of passing around register bases, pass around a regmap
in this driver. This refactoring make things so much easier when
we later want to manage an ICST that is part of a syscon.

Cc: Michael Turquette <mturquette@baylibre.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: linux-clk@vger.kernel.org
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 2b749cb3
config COMMON_CLK_VERSATILE config COMMON_CLK_VERSATILE
bool "Clock driver for ARM Reference designs" bool "Clock driver for ARM Reference designs"
depends on ARCH_INTEGRATOR || ARCH_REALVIEW || ARCH_VEXPRESS || ARM64 || COMPILE_TEST depends on ARCH_INTEGRATOR || ARCH_REALVIEW || ARCH_VEXPRESS || ARM64 || COMPILE_TEST
select REGMAP_MMIO
---help--- ---help---
Supports clocking on ARM Reference designs: Supports clocking on ARM Reference designs:
- Integrator/AP and Integrator/CP - Integrator/AP and Integrator/CP
......
...@@ -19,9 +19,13 @@ ...@@ -19,9 +19,13 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/clk-provider.h> #include <linux/clk-provider.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/regmap.h>
#include "clk-icst.h" #include "clk-icst.h"
/* Magic unlocking token used on all Versatile boards */
#define VERSATILE_LOCK_VAL 0xA05F
/** /**
* struct clk_icst - ICST VCO clock wrapper * struct clk_icst - ICST VCO clock wrapper
* @hw: corresponding clock hardware entry * @hw: corresponding clock hardware entry
...@@ -32,8 +36,9 @@ ...@@ -32,8 +36,9 @@
*/ */
struct clk_icst { struct clk_icst {
struct clk_hw hw; struct clk_hw hw;
void __iomem *vcoreg; struct regmap *map;
void __iomem *lockreg; u32 vcoreg_off;
u32 lockreg_off;
struct icst_params *params; struct icst_params *params;
unsigned long rate; unsigned long rate;
}; };
...@@ -41,53 +46,67 @@ struct clk_icst { ...@@ -41,53 +46,67 @@ struct clk_icst {
#define to_icst(_hw) container_of(_hw, struct clk_icst, hw) #define to_icst(_hw) container_of(_hw, struct clk_icst, hw)
/** /**
* vco_get() - get ICST VCO settings from a certain register * vco_get() - get ICST VCO settings from a certain ICST
* @vcoreg: register containing the VCO settings * @icst: the ICST clock to get
* @vco: the VCO struct to return the value in
*/ */
static struct icst_vco vco_get(void __iomem *vcoreg) static int vco_get(struct clk_icst *icst, struct icst_vco *vco)
{ {
u32 val; u32 val;
struct icst_vco vco; int ret;
val = readl(vcoreg); ret = regmap_read(icst->map, icst->vcoreg_off, &val);
vco.v = val & 0x1ff; if (ret)
vco.r = (val >> 9) & 0x7f; return ret;
vco.s = (val >> 16) & 03; vco->v = val & 0x1ff;
return vco; vco->r = (val >> 9) & 0x7f;
vco->s = (val >> 16) & 03;
return 0;
} }
/** /**
* vco_set() - commit changes to an ICST VCO * vco_set() - commit changes to an ICST VCO
* @locreg: register to poke to unlock the VCO for writing * @icst: the ICST clock to set
* @vcoreg: register containing the VCO settings * @vco: the VCO struct to set the changes from
* @vco: ICST VCO parameters to commit
*/ */
static void vco_set(void __iomem *lockreg, static int vco_set(struct clk_icst *icst, struct icst_vco vco)
void __iomem *vcoreg,
struct icst_vco vco)
{ {
u32 val; u32 val;
int ret;
val = readl(vcoreg) & ~0x7ffff; ret = regmap_read(icst->map, icst->vcoreg_off, &val);
if (ret)
return ret;
val |= vco.v | (vco.r << 9) | (vco.s << 16); val |= vco.v | (vco.r << 9) | (vco.s << 16);
/* This magic unlocks the VCO so it can be controlled */ /* This magic unlocks the VCO so it can be controlled */
writel(0xa05f, lockreg); ret = regmap_write(icst->map, icst->lockreg_off, VERSATILE_LOCK_VAL);
writel(val, vcoreg); if (ret)
return ret;
ret = regmap_write(icst->map, icst->vcoreg_off, val);
if (ret)
return ret;
/* This locks the VCO again */ /* This locks the VCO again */
writel(0, lockreg); ret = regmap_write(icst->map, icst->lockreg_off, 0);
if (ret)
return ret;
return 0;
} }
static unsigned long icst_recalc_rate(struct clk_hw *hw, static unsigned long icst_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate) unsigned long parent_rate)
{ {
struct clk_icst *icst = to_icst(hw); struct clk_icst *icst = to_icst(hw);
struct icst_vco vco; struct icst_vco vco;
int ret;
if (parent_rate) if (parent_rate)
icst->params->ref = parent_rate; icst->params->ref = parent_rate;
vco = vco_get(icst->vcoreg); ret = vco_get(icst, &vco);
if (ret) {
pr_err("ICST: could not get VCO setting\n");
return 0;
}
icst->rate = icst_hz(icst->params, vco); icst->rate = icst_hz(icst->params, vco);
return icst->rate; return icst->rate;
} }
...@@ -112,8 +131,7 @@ static int icst_set_rate(struct clk_hw *hw, unsigned long rate, ...@@ -112,8 +131,7 @@ static int icst_set_rate(struct clk_hw *hw, unsigned long rate,
icst->params->ref = parent_rate; icst->params->ref = parent_rate;
vco = icst_hz_to_vco(icst->params, rate); vco = icst_hz_to_vco(icst->params, rate);
icst->rate = icst_hz(icst->params, vco); icst->rate = icst_hz(icst->params, vco);
vco_set(icst->lockreg, icst->vcoreg, vco); return vco_set(icst, vco);
return 0;
} }
static const struct clk_ops icst_ops = { static const struct clk_ops icst_ops = {
...@@ -132,6 +150,11 @@ struct clk *icst_clk_register(struct device *dev, ...@@ -132,6 +150,11 @@ struct clk *icst_clk_register(struct device *dev,
struct clk_icst *icst; struct clk_icst *icst;
struct clk_init_data init; struct clk_init_data init;
struct icst_params *pclone; struct icst_params *pclone;
struct regmap_config icst_regmap_conf = {
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
};
icst = kzalloc(sizeof(struct clk_icst), GFP_KERNEL); icst = kzalloc(sizeof(struct clk_icst), GFP_KERNEL);
if (!icst) { if (!icst) {
...@@ -151,10 +174,19 @@ struct clk *icst_clk_register(struct device *dev, ...@@ -151,10 +174,19 @@ struct clk *icst_clk_register(struct device *dev,
init.flags = CLK_IS_ROOT; init.flags = CLK_IS_ROOT;
init.parent_names = (parent_name ? &parent_name : NULL); init.parent_names = (parent_name ? &parent_name : NULL);
init.num_parents = (parent_name ? 1 : 0); init.num_parents = (parent_name ? 1 : 0);
icst->map = regmap_init_mmio(dev, base, &icst_regmap_conf);
if (IS_ERR(icst->map)) {
int ret;
pr_err("could not initialize ICST regmap\n");
ret = PTR_ERR(icst->map);
kfree(icst);
return ERR_PTR(ret);
}
icst->hw.init = &init; icst->hw.init = &init;
icst->params = pclone; icst->params = pclone;
icst->vcoreg = base + desc->vco_offset; icst->vcoreg_off = desc->vco_offset;
icst->lockreg = base + desc->lock_offset; icst->lockreg_off = desc->lock_offset;
clk = clk_register(dev, &icst->hw); clk = clk_register(dev, &icst->hw);
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment