clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-01-16 02:47:25 +08:00
|
|
|
/*
|
2018-03-08 15:18:12 +08:00
|
|
|
* Copyright (c) 2013, 2018, The Linux Foundation. All rights reserved.
|
2014-01-16 02:47:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/bug.h>
|
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/delay.h>
|
2019-08-01 02:27:12 +08:00
|
|
|
#include <linux/rational.h>
|
2014-01-16 02:47:25 +08:00
|
|
|
#include <linux/regmap.h>
|
2014-05-17 07:07:11 +08:00
|
|
|
#include <linux/math64.h>
|
2022-06-12 22:59:53 +08:00
|
|
|
#include <linux/minmax.h>
|
2018-08-11 09:53:55 +08:00
|
|
|
#include <linux/slab.h>
|
2014-01-16 02:47:25 +08:00
|
|
|
|
|
|
|
#include <asm/div64.h>
|
|
|
|
|
|
|
|
#include "clk-rcg.h"
|
2014-09-05 04:21:50 +08:00
|
|
|
#include "common.h"
|
2014-01-16 02:47:25 +08:00
|
|
|
|
|
|
|
#define CMD_REG 0x0
|
|
|
|
#define CMD_UPDATE BIT(0)
|
|
|
|
#define CMD_ROOT_EN BIT(1)
|
|
|
|
#define CMD_DIRTY_CFG BIT(4)
|
|
|
|
#define CMD_DIRTY_N BIT(5)
|
|
|
|
#define CMD_DIRTY_M BIT(6)
|
|
|
|
#define CMD_DIRTY_D BIT(7)
|
|
|
|
#define CMD_ROOT_OFF BIT(31)
|
|
|
|
|
|
|
|
#define CFG_REG 0x4
|
|
|
|
#define CFG_SRC_DIV_SHIFT 0
|
|
|
|
#define CFG_SRC_SEL_SHIFT 8
|
|
|
|
#define CFG_SRC_SEL_MASK (0x7 << CFG_SRC_SEL_SHIFT)
|
|
|
|
#define CFG_MODE_SHIFT 12
|
|
|
|
#define CFG_MODE_MASK (0x3 << CFG_MODE_SHIFT)
|
|
|
|
#define CFG_MODE_DUAL_EDGE (0x2 << CFG_MODE_SHIFT)
|
2018-03-08 15:18:12 +08:00
|
|
|
#define CFG_HW_CLK_CTRL_MASK BIT(20)
|
2014-01-16 02:47:25 +08:00
|
|
|
|
|
|
|
#define M_REG 0x8
|
|
|
|
#define N_REG 0xc
|
|
|
|
#define D_REG 0x10
|
|
|
|
|
2019-02-11 15:39:27 +08:00
|
|
|
#define RCG_CFG_OFFSET(rcg) ((rcg)->cmd_rcgr + (rcg)->cfg_off + CFG_REG)
|
|
|
|
#define RCG_M_OFFSET(rcg) ((rcg)->cmd_rcgr + (rcg)->cfg_off + M_REG)
|
|
|
|
#define RCG_N_OFFSET(rcg) ((rcg)->cmd_rcgr + (rcg)->cfg_off + N_REG)
|
|
|
|
#define RCG_D_OFFSET(rcg) ((rcg)->cmd_rcgr + (rcg)->cfg_off + D_REG)
|
|
|
|
|
2018-08-11 09:53:55 +08:00
|
|
|
/* Dynamic Frequency Scaling */
|
|
|
|
#define MAX_PERF_LEVEL 8
|
|
|
|
#define SE_CMD_DFSR_OFFSET 0x14
|
|
|
|
#define SE_CMD_DFS_EN BIT(0)
|
|
|
|
#define SE_PERF_DFSR(level) (0x1c + 0x4 * (level))
|
|
|
|
#define SE_PERF_M_DFSR(level) (0x5c + 0x4 * (level))
|
|
|
|
#define SE_PERF_N_DFSR(level) (0x9c + 0x4 * (level))
|
|
|
|
|
2016-11-21 14:37:11 +08:00
|
|
|
enum freq_policy {
|
|
|
|
FLOOR,
|
|
|
|
CEIL,
|
|
|
|
};
|
|
|
|
|
2014-01-16 02:47:25 +08:00
|
|
|
static int clk_rcg2_is_enabled(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
u32 cmd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG, &cmd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-05-17 07:07:08 +08:00
|
|
|
return (cmd & CMD_ROOT_OFF) == 0;
|
2014-01-16 02:47:25 +08:00
|
|
|
}
|
|
|
|
|
2022-04-27 05:21:36 +08:00
|
|
|
static u8 __clk_rcg2_get_parent(struct clk_hw *hw, u32 cfg)
|
2014-01-16 02:47:25 +08:00
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
2015-06-26 07:53:23 +08:00
|
|
|
int num_parents = clk_hw_get_num_parents(hw);
|
2022-04-27 05:21:36 +08:00
|
|
|
int i;
|
2014-01-16 02:47:25 +08:00
|
|
|
|
|
|
|
cfg &= CFG_SRC_SEL_MASK;
|
|
|
|
cfg >>= CFG_SRC_SEL_SHIFT;
|
|
|
|
|
|
|
|
for (i = 0; i < num_parents; i++)
|
2015-03-21 00:30:26 +08:00
|
|
|
if (cfg == rcg->parent_map[i].cfg)
|
2014-01-16 02:47:25 +08:00
|
|
|
return i;
|
|
|
|
|
2015-03-21 00:30:24 +08:00
|
|
|
pr_debug("%s: Clock %s has invalid parent, using default.\n",
|
2015-07-31 08:20:57 +08:00
|
|
|
__func__, clk_hw_get_name(hw));
|
2015-03-21 00:30:24 +08:00
|
|
|
return 0;
|
2014-01-16 02:47:25 +08:00
|
|
|
}
|
|
|
|
|
2022-04-27 05:21:36 +08:00
|
|
|
static u8 clk_rcg2_get_parent(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
u32 cfg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = regmap_read(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), &cfg);
|
|
|
|
if (ret) {
|
|
|
|
pr_debug("%s: Unable to read CFG register for %s\n",
|
|
|
|
__func__, clk_hw_get_name(hw));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return __clk_rcg2_get_parent(hw, cfg);
|
|
|
|
}
|
|
|
|
|
2014-01-16 02:47:25 +08:00
|
|
|
static int update_config(struct clk_rcg2 *rcg)
|
|
|
|
{
|
|
|
|
int count, ret;
|
|
|
|
u32 cmd;
|
|
|
|
struct clk_hw *hw = &rcg->clkr.hw;
|
2015-07-31 08:20:57 +08:00
|
|
|
const char *name = clk_hw_get_name(hw);
|
2014-01-16 02:47:25 +08:00
|
|
|
|
|
|
|
ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
|
|
|
|
CMD_UPDATE, CMD_UPDATE);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Wait for update to take effect */
|
|
|
|
for (count = 500; count > 0; count--) {
|
|
|
|
ret = regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG, &cmd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
if (!(cmd & CMD_UPDATE))
|
|
|
|
return 0;
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN(1, "%s: rcg didn't update its configuration.", name);
|
2019-05-09 02:24:53 +08:00
|
|
|
return -EBUSY;
|
2014-01-16 02:47:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_set_parent(struct clk_hw *hw, u8 index)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
int ret;
|
2015-03-21 00:30:26 +08:00
|
|
|
u32 cfg = rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
|
2014-01-16 02:47:25 +08:00
|
|
|
|
2019-02-11 15:39:27 +08:00
|
|
|
ret = regmap_update_bits(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg),
|
2015-03-21 00:30:26 +08:00
|
|
|
CFG_SRC_SEL_MASK, cfg);
|
2014-01-16 02:47:25 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return update_config(rcg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate m/n:d rate
|
|
|
|
*
|
|
|
|
* parent_rate m
|
|
|
|
* rate = ----------- x ---
|
|
|
|
* hid_div n
|
|
|
|
*/
|
|
|
|
static unsigned long
|
|
|
|
calc_rate(unsigned long rate, u32 m, u32 n, u32 mode, u32 hid_div)
|
|
|
|
{
|
|
|
|
if (hid_div) {
|
|
|
|
rate *= 2;
|
|
|
|
rate /= hid_div + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode) {
|
|
|
|
u64 tmp = rate;
|
|
|
|
tmp *= m;
|
|
|
|
do_div(tmp, n);
|
|
|
|
rate = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
2022-04-27 05:21:36 +08:00
|
|
|
__clk_rcg2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate, u32 cfg)
|
2014-01-16 02:47:25 +08:00
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
2022-04-27 05:21:36 +08:00
|
|
|
u32 hid_div, m = 0, n = 0, mode = 0, mask;
|
2014-01-16 02:47:25 +08:00
|
|
|
|
|
|
|
if (rcg->mnd_width) {
|
|
|
|
mask = BIT(rcg->mnd_width) - 1;
|
2019-02-11 15:39:27 +08:00
|
|
|
regmap_read(rcg->clkr.regmap, RCG_M_OFFSET(rcg), &m);
|
2014-01-16 02:47:25 +08:00
|
|
|
m &= mask;
|
2019-02-11 15:39:27 +08:00
|
|
|
regmap_read(rcg->clkr.regmap, RCG_N_OFFSET(rcg), &n);
|
2014-01-16 02:47:25 +08:00
|
|
|
n = ~n;
|
|
|
|
n &= mask;
|
|
|
|
n += m;
|
|
|
|
mode = cfg & CFG_MODE_MASK;
|
|
|
|
mode >>= CFG_MODE_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = BIT(rcg->hid_width) - 1;
|
|
|
|
hid_div = cfg >> CFG_SRC_DIV_SHIFT;
|
|
|
|
hid_div &= mask;
|
|
|
|
|
|
|
|
return calc_rate(parent_rate, m, n, mode, hid_div);
|
|
|
|
}
|
|
|
|
|
2022-04-27 05:21:36 +08:00
|
|
|
static unsigned long
|
|
|
|
clk_rcg2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
u32 cfg;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), &cfg);
|
|
|
|
|
|
|
|
return __clk_rcg2_recalc_rate(hw, parent_rate, cfg);
|
|
|
|
}
|
|
|
|
|
2016-11-21 14:37:11 +08:00
|
|
|
static int _freq_tbl_determine_rate(struct clk_hw *hw, const struct freq_tbl *f,
|
|
|
|
struct clk_rate_request *req,
|
|
|
|
enum freq_policy policy)
|
2014-01-16 02:47:25 +08:00
|
|
|
{
|
2015-07-08 02:48:08 +08:00
|
|
|
unsigned long clk_flags, rate = req->rate;
|
2015-07-31 08:20:57 +08:00
|
|
|
struct clk_hw *p;
|
2015-04-07 22:14:51 +08:00
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
int index;
|
2014-01-16 02:47:25 +08:00
|
|
|
|
2016-11-21 14:37:11 +08:00
|
|
|
switch (policy) {
|
|
|
|
case FLOOR:
|
|
|
|
f = qcom_find_freq_floor(f, rate);
|
|
|
|
break;
|
|
|
|
case CEIL:
|
|
|
|
f = qcom_find_freq(f, rate);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2019-10-25 17:33:32 +08:00
|
|
|
}
|
2016-11-21 14:37:11 +08:00
|
|
|
|
2014-01-16 02:47:25 +08:00
|
|
|
if (!f)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-04-07 22:14:51 +08:00
|
|
|
index = qcom_find_src_index(hw, rcg->parent_map, f->src);
|
|
|
|
if (index < 0)
|
|
|
|
return index;
|
|
|
|
|
2015-06-30 07:56:30 +08:00
|
|
|
clk_flags = clk_hw_get_flags(hw);
|
2015-07-31 08:20:57 +08:00
|
|
|
p = clk_hw_get_parent_by_index(hw, index);
|
2020-02-04 02:31:34 +08:00
|
|
|
if (!p)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-01-16 02:47:25 +08:00
|
|
|
if (clk_flags & CLK_SET_RATE_PARENT) {
|
2018-04-14 04:33:36 +08:00
|
|
|
rate = f->freq;
|
2014-01-16 02:47:25 +08:00
|
|
|
if (f->pre_div) {
|
2019-11-01 02:57:15 +08:00
|
|
|
if (!rate)
|
|
|
|
rate = req->rate;
|
2014-01-16 02:47:25 +08:00
|
|
|
rate /= 2;
|
|
|
|
rate *= f->pre_div + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f->n) {
|
|
|
|
u64 tmp = rate;
|
|
|
|
tmp = tmp * f->n;
|
|
|
|
do_div(tmp, f->m);
|
|
|
|
rate = tmp;
|
|
|
|
}
|
|
|
|
} else {
|
2015-07-31 08:20:57 +08:00
|
|
|
rate = clk_hw_get_rate(p);
|
2014-01-16 02:47:25 +08:00
|
|
|
}
|
2015-07-31 08:20:57 +08:00
|
|
|
req->best_parent_hw = p;
|
2015-07-08 02:48:08 +08:00
|
|
|
req->best_parent_rate = rate;
|
|
|
|
req->rate = f->freq;
|
2014-01-16 02:47:25 +08:00
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
return 0;
|
2014-01-16 02:47:25 +08:00
|
|
|
}
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
static int clk_rcg2_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
2014-01-16 02:47:25 +08:00
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
|
2016-11-21 14:37:11 +08:00
|
|
|
return _freq_tbl_determine_rate(hw, rcg->freq_tbl, req, CEIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_determine_floor_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
|
|
|
|
return _freq_tbl_determine_rate(hw, rcg->freq_tbl, req, FLOOR);
|
2014-01-16 02:47:25 +08:00
|
|
|
}
|
|
|
|
|
2022-04-27 05:21:36 +08:00
|
|
|
static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f,
|
|
|
|
u32 *_cfg)
|
2014-01-16 02:47:25 +08:00
|
|
|
{
|
2022-02-28 01:55:35 +08:00
|
|
|
u32 cfg, mask, d_val, not2d_val, n_minus_m;
|
2015-03-21 00:30:26 +08:00
|
|
|
struct clk_hw *hw = &rcg->clkr.hw;
|
|
|
|
int ret, index = qcom_find_src_index(hw, rcg->parent_map, f->src);
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
return index;
|
2014-01-16 02:47:25 +08:00
|
|
|
|
|
|
|
if (rcg->mnd_width && f->n) {
|
|
|
|
mask = BIT(rcg->mnd_width) - 1;
|
2014-05-17 07:07:11 +08:00
|
|
|
ret = regmap_update_bits(rcg->clkr.regmap,
|
2019-02-11 15:39:27 +08:00
|
|
|
RCG_M_OFFSET(rcg), mask, f->m);
|
2014-01-16 02:47:25 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-05-17 07:07:11 +08:00
|
|
|
ret = regmap_update_bits(rcg->clkr.regmap,
|
2019-02-11 15:39:27 +08:00
|
|
|
RCG_N_OFFSET(rcg), mask, ~(f->n - f->m));
|
2014-01-16 02:47:25 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-02-28 01:55:35 +08:00
|
|
|
/* Calculate 2d value */
|
|
|
|
d_val = f->n;
|
|
|
|
|
|
|
|
n_minus_m = f->n - f->m;
|
|
|
|
n_minus_m *= 2;
|
|
|
|
|
|
|
|
d_val = clamp_t(u32, d_val, f->m, n_minus_m);
|
|
|
|
not2d_val = ~d_val & mask;
|
|
|
|
|
2014-05-17 07:07:11 +08:00
|
|
|
ret = regmap_update_bits(rcg->clkr.regmap,
|
2022-02-28 01:55:35 +08:00
|
|
|
RCG_D_OFFSET(rcg), mask, not2d_val);
|
2014-01-16 02:47:25 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = BIT(rcg->hid_width) - 1;
|
2018-03-08 15:18:12 +08:00
|
|
|
mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
|
2014-01-16 02:47:25 +08:00
|
|
|
cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
|
2015-03-21 00:30:26 +08:00
|
|
|
cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
|
2015-03-04 17:49:35 +08:00
|
|
|
if (rcg->mnd_width && f->n && (f->m != f->n))
|
2014-01-16 02:47:25 +08:00
|
|
|
cfg |= CFG_MODE_DUAL_EDGE;
|
2022-04-27 05:21:36 +08:00
|
|
|
|
|
|
|
*_cfg &= ~mask;
|
|
|
|
*_cfg |= cfg;
|
|
|
|
|
|
|
|
return 0;
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
|
|
|
|
{
|
2022-04-27 05:21:36 +08:00
|
|
|
u32 cfg;
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
int ret;
|
|
|
|
|
2022-04-27 05:21:36 +08:00
|
|
|
ret = regmap_read(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), &cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = __clk_rcg2_configure(rcg, f, &cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = regmap_write(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), cfg);
|
2014-01-16 02:47:25 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return update_config(rcg);
|
|
|
|
}
|
|
|
|
|
2016-11-21 14:37:11 +08:00
|
|
|
static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
enum freq_policy policy)
|
2014-05-17 07:07:11 +08:00
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
const struct freq_tbl *f;
|
|
|
|
|
2016-11-21 14:37:11 +08:00
|
|
|
switch (policy) {
|
|
|
|
case FLOOR:
|
|
|
|
f = qcom_find_freq_floor(rcg->freq_tbl, rate);
|
|
|
|
break;
|
|
|
|
case CEIL:
|
|
|
|
f = qcom_find_freq(rcg->freq_tbl, rate);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2019-10-25 17:33:32 +08:00
|
|
|
}
|
2016-11-21 14:37:11 +08:00
|
|
|
|
2014-05-17 07:07:11 +08:00
|
|
|
if (!f)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return clk_rcg2_configure(rcg, f);
|
|
|
|
}
|
|
|
|
|
2014-01-16 02:47:25 +08:00
|
|
|
static int clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
2016-11-21 14:37:11 +08:00
|
|
|
return __clk_rcg2_set_rate(hw, rate, CEIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_set_floor_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
return __clk_rcg2_set_rate(hw, rate, FLOOR);
|
2014-01-16 02:47:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_set_rate_and_parent(struct clk_hw *hw,
|
|
|
|
unsigned long rate, unsigned long parent_rate, u8 index)
|
|
|
|
{
|
2016-11-21 14:37:11 +08:00
|
|
|
return __clk_rcg2_set_rate(hw, rate, CEIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_set_floor_rate_and_parent(struct clk_hw *hw,
|
|
|
|
unsigned long rate, unsigned long parent_rate, u8 index)
|
|
|
|
{
|
|
|
|
return __clk_rcg2_set_rate(hw, rate, FLOOR);
|
2014-01-16 02:47:25 +08:00
|
|
|
}
|
|
|
|
|
2021-04-25 15:08:22 +08:00
|
|
|
static int clk_rcg2_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
u32 notn_m, n, m, d, not2d, mask;
|
|
|
|
|
|
|
|
if (!rcg->mnd_width) {
|
|
|
|
/* 50 % duty-cycle for Non-MND RCGs */
|
|
|
|
duty->num = 1;
|
|
|
|
duty->den = 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, RCG_D_OFFSET(rcg), ¬2d);
|
|
|
|
regmap_read(rcg->clkr.regmap, RCG_M_OFFSET(rcg), &m);
|
|
|
|
regmap_read(rcg->clkr.regmap, RCG_N_OFFSET(rcg), ¬n_m);
|
|
|
|
|
|
|
|
if (!not2d && !m && !notn_m) {
|
|
|
|
/* 50 % duty-cycle always */
|
|
|
|
duty->num = 1;
|
|
|
|
duty->den = 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = BIT(rcg->mnd_width) - 1;
|
|
|
|
|
|
|
|
d = ~(not2d) & mask;
|
|
|
|
d = DIV_ROUND_CLOSEST(d, 2);
|
|
|
|
|
|
|
|
n = (~(notn_m) + m) & mask;
|
|
|
|
|
|
|
|
duty->num = d;
|
|
|
|
duty->den = n;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
2022-06-12 22:59:52 +08:00
|
|
|
u32 notn_m, n, m, d, not2d, mask, duty_per, cfg;
|
2021-04-25 15:08:22 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Duty-cycle cannot be modified for non-MND RCGs */
|
|
|
|
if (!rcg->mnd_width)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
mask = BIT(rcg->mnd_width) - 1;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, RCG_N_OFFSET(rcg), ¬n_m);
|
|
|
|
regmap_read(rcg->clkr.regmap, RCG_M_OFFSET(rcg), &m);
|
2022-06-12 22:59:52 +08:00
|
|
|
regmap_read(rcg->clkr.regmap, RCG_CFG_OFFSET(rcg), &cfg);
|
|
|
|
|
|
|
|
/* Duty-cycle cannot be modified if MND divider is in bypass mode. */
|
|
|
|
if (!(cfg & CFG_MODE_MASK))
|
|
|
|
return -EINVAL;
|
2021-04-25 15:08:22 +08:00
|
|
|
|
|
|
|
n = (~(notn_m) + m) & mask;
|
|
|
|
|
|
|
|
duty_per = (duty->num * 100) / duty->den;
|
|
|
|
|
|
|
|
/* Calculate 2d value */
|
|
|
|
d = DIV_ROUND_CLOSEST(n * duty_per * 2, 100);
|
|
|
|
|
2022-06-12 22:59:53 +08:00
|
|
|
/*
|
|
|
|
* Check bit widths of 2d. If D is too big reduce duty cycle.
|
|
|
|
* Also make sure it is never zero.
|
|
|
|
*/
|
|
|
|
d = clamp_val(d, 1, mask);
|
2021-04-25 15:08:22 +08:00
|
|
|
|
|
|
|
if ((d / 2) > (n - m))
|
|
|
|
d = (n - m) * 2;
|
|
|
|
else if ((d / 2) < (m / 2))
|
|
|
|
d = m;
|
|
|
|
|
|
|
|
not2d = ~d & mask;
|
|
|
|
|
|
|
|
ret = regmap_update_bits(rcg->clkr.regmap, RCG_D_OFFSET(rcg), mask,
|
|
|
|
not2d);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return update_config(rcg);
|
|
|
|
}
|
|
|
|
|
2014-01-16 02:47:25 +08:00
|
|
|
const struct clk_ops clk_rcg2_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_recalc_rate,
|
|
|
|
.determine_rate = clk_rcg2_determine_rate,
|
|
|
|
.set_rate = clk_rcg2_set_rate,
|
|
|
|
.set_rate_and_parent = clk_rcg2_set_rate_and_parent,
|
2021-04-25 15:08:22 +08:00
|
|
|
.get_duty_cycle = clk_rcg2_get_duty_cycle,
|
|
|
|
.set_duty_cycle = clk_rcg2_set_duty_cycle,
|
2014-01-16 02:47:25 +08:00
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_rcg2_ops);
|
2014-05-17 07:07:11 +08:00
|
|
|
|
2016-11-21 14:37:11 +08:00
|
|
|
const struct clk_ops clk_rcg2_floor_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_recalc_rate,
|
|
|
|
.determine_rate = clk_rcg2_determine_floor_rate,
|
|
|
|
.set_rate = clk_rcg2_set_floor_rate,
|
|
|
|
.set_rate_and_parent = clk_rcg2_set_floor_rate_and_parent,
|
2021-04-25 15:08:22 +08:00
|
|
|
.get_duty_cycle = clk_rcg2_get_duty_cycle,
|
|
|
|
.set_duty_cycle = clk_rcg2_set_duty_cycle,
|
2016-11-21 14:37:11 +08:00
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_rcg2_floor_ops);
|
|
|
|
|
2022-08-19 06:06:20 +08:00
|
|
|
const struct clk_ops clk_rcg2_mux_closest_ops = {
|
|
|
|
.determine_rate = __clk_mux_determine_rate_closest,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_rcg2_mux_closest_ops);
|
|
|
|
|
2014-05-17 07:07:11 +08:00
|
|
|
struct frac_entry {
|
|
|
|
int num;
|
|
|
|
int den;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct frac_entry frac_table_675m[] = { /* link rate of 270M */
|
|
|
|
{ 52, 295 }, /* 119 M */
|
|
|
|
{ 11, 57 }, /* 130.25 M */
|
|
|
|
{ 63, 307 }, /* 138.50 M */
|
|
|
|
{ 11, 50 }, /* 148.50 M */
|
|
|
|
{ 47, 206 }, /* 154 M */
|
|
|
|
{ 31, 100 }, /* 205.25 M */
|
|
|
|
{ 107, 269 }, /* 268.50 M */
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct frac_entry frac_table_810m[] = { /* Link rate of 162M */
|
|
|
|
{ 31, 211 }, /* 119 M */
|
|
|
|
{ 32, 199 }, /* 130.25 M */
|
|
|
|
{ 63, 307 }, /* 138.50 M */
|
|
|
|
{ 11, 60 }, /* 148.50 M */
|
|
|
|
{ 50, 263 }, /* 154 M */
|
|
|
|
{ 31, 120 }, /* 205.25 M */
|
|
|
|
{ 119, 359 }, /* 268.50 M */
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int clk_edp_pixel_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
struct freq_tbl f = *rcg->freq_tbl;
|
|
|
|
const struct frac_entry *frac;
|
|
|
|
int delta = 100000;
|
|
|
|
s64 src_rate = parent_rate;
|
|
|
|
s64 request;
|
|
|
|
u32 mask = BIT(rcg->hid_width) - 1;
|
|
|
|
u32 hid_div;
|
|
|
|
|
|
|
|
if (src_rate == 810000000)
|
|
|
|
frac = frac_table_810m;
|
|
|
|
else
|
|
|
|
frac = frac_table_675m;
|
|
|
|
|
|
|
|
for (; frac->num; frac++) {
|
|
|
|
request = rate;
|
|
|
|
request *= frac->den;
|
|
|
|
request = div_s64(request, frac->num);
|
|
|
|
if ((src_rate < (request - delta)) ||
|
|
|
|
(src_rate > (request + delta)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
|
|
|
|
&hid_div);
|
|
|
|
f.pre_div = hid_div;
|
|
|
|
f.pre_div >>= CFG_SRC_DIV_SHIFT;
|
|
|
|
f.pre_div &= mask;
|
|
|
|
f.m = frac->num;
|
|
|
|
f.n = frac->den;
|
|
|
|
|
|
|
|
return clk_rcg2_configure(rcg, &f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_edp_pixel_set_rate_and_parent(struct clk_hw *hw,
|
|
|
|
unsigned long rate, unsigned long parent_rate, u8 index)
|
|
|
|
{
|
|
|
|
/* Parent index is set statically in frequency table */
|
|
|
|
return clk_edp_pixel_set_rate(hw, rate, parent_rate);
|
|
|
|
}
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
static int clk_edp_pixel_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
2014-05-17 07:07:11 +08:00
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
const struct freq_tbl *f = rcg->freq_tbl;
|
|
|
|
const struct frac_entry *frac;
|
|
|
|
int delta = 100000;
|
|
|
|
s64 request;
|
|
|
|
u32 mask = BIT(rcg->hid_width) - 1;
|
|
|
|
u32 hid_div;
|
2015-04-07 22:14:51 +08:00
|
|
|
int index = qcom_find_src_index(hw, rcg->parent_map, f->src);
|
2014-05-17 07:07:11 +08:00
|
|
|
|
|
|
|
/* Force the correct parent */
|
2015-07-31 08:20:57 +08:00
|
|
|
req->best_parent_hw = clk_hw_get_parent_by_index(hw, index);
|
|
|
|
req->best_parent_rate = clk_hw_get_rate(req->best_parent_hw);
|
2014-05-17 07:07:11 +08:00
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
if (req->best_parent_rate == 810000000)
|
2014-05-17 07:07:11 +08:00
|
|
|
frac = frac_table_810m;
|
|
|
|
else
|
|
|
|
frac = frac_table_675m;
|
|
|
|
|
|
|
|
for (; frac->num; frac++) {
|
2015-07-08 02:48:08 +08:00
|
|
|
request = req->rate;
|
2014-05-17 07:07:11 +08:00
|
|
|
request *= frac->den;
|
|
|
|
request = div_s64(request, frac->num);
|
2015-07-08 02:48:08 +08:00
|
|
|
if ((req->best_parent_rate < (request - delta)) ||
|
|
|
|
(req->best_parent_rate > (request + delta)))
|
2014-05-17 07:07:11 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
|
|
|
|
&hid_div);
|
|
|
|
hid_div >>= CFG_SRC_DIV_SHIFT;
|
|
|
|
hid_div &= mask;
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
req->rate = calc_rate(req->best_parent_rate,
|
|
|
|
frac->num, frac->den,
|
|
|
|
!!frac->den, hid_div);
|
|
|
|
return 0;
|
2014-05-17 07:07:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct clk_ops clk_edp_pixel_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_recalc_rate,
|
|
|
|
.set_rate = clk_edp_pixel_set_rate,
|
|
|
|
.set_rate_and_parent = clk_edp_pixel_set_rate_and_parent,
|
|
|
|
.determine_rate = clk_edp_pixel_determine_rate,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_edp_pixel_ops);
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
static int clk_byte_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
2014-05-17 07:07:11 +08:00
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
const struct freq_tbl *f = rcg->freq_tbl;
|
2015-04-07 22:14:51 +08:00
|
|
|
int index = qcom_find_src_index(hw, rcg->parent_map, f->src);
|
2014-05-17 07:07:11 +08:00
|
|
|
unsigned long parent_rate, div;
|
|
|
|
u32 mask = BIT(rcg->hid_width) - 1;
|
2015-07-31 08:20:57 +08:00
|
|
|
struct clk_hw *p;
|
2014-05-17 07:07:11 +08:00
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
if (req->rate == 0)
|
2014-05-17 07:07:11 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2015-07-31 08:20:57 +08:00
|
|
|
req->best_parent_hw = p = clk_hw_get_parent_by_index(hw, index);
|
|
|
|
req->best_parent_rate = parent_rate = clk_hw_round_rate(p, req->rate);
|
2014-05-17 07:07:11 +08:00
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
div = DIV_ROUND_UP((2 * parent_rate), req->rate) - 1;
|
2014-05-17 07:07:11 +08:00
|
|
|
div = min_t(u32, div, mask);
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
req->rate = calc_rate(parent_rate, 0, 0, 0, div);
|
|
|
|
|
|
|
|
return 0;
|
2014-05-17 07:07:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_byte_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
struct freq_tbl f = *rcg->freq_tbl;
|
|
|
|
unsigned long div;
|
|
|
|
u32 mask = BIT(rcg->hid_width) - 1;
|
|
|
|
|
|
|
|
div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
|
|
|
|
div = min_t(u32, div, mask);
|
|
|
|
|
|
|
|
f.pre_div = div;
|
|
|
|
|
|
|
|
return clk_rcg2_configure(rcg, &f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_byte_set_rate_and_parent(struct clk_hw *hw,
|
|
|
|
unsigned long rate, unsigned long parent_rate, u8 index)
|
|
|
|
{
|
|
|
|
/* Parent index is set statically in frequency table */
|
|
|
|
return clk_byte_set_rate(hw, rate, parent_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct clk_ops clk_byte_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_recalc_rate,
|
|
|
|
.set_rate = clk_byte_set_rate,
|
|
|
|
.set_rate_and_parent = clk_byte_set_rate_and_parent,
|
|
|
|
.determine_rate = clk_byte_determine_rate,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_byte_ops);
|
|
|
|
|
2015-04-10 14:02:02 +08:00
|
|
|
static int clk_byte2_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
unsigned long parent_rate, div;
|
|
|
|
u32 mask = BIT(rcg->hid_width) - 1;
|
|
|
|
struct clk_hw *p;
|
|
|
|
unsigned long rate = req->rate;
|
|
|
|
|
|
|
|
if (rate == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
p = req->best_parent_hw;
|
|
|
|
req->best_parent_rate = parent_rate = clk_hw_round_rate(p, rate);
|
|
|
|
|
|
|
|
div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
|
|
|
|
div = min_t(u32, div, mask);
|
|
|
|
|
|
|
|
req->rate = calc_rate(parent_rate, 0, 0, 0, div);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_byte2_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
struct freq_tbl f = { 0 };
|
|
|
|
unsigned long div;
|
|
|
|
int i, num_parents = clk_hw_get_num_parents(hw);
|
|
|
|
u32 mask = BIT(rcg->hid_width) - 1;
|
|
|
|
u32 cfg;
|
|
|
|
|
|
|
|
div = DIV_ROUND_UP((2 * parent_rate), rate) - 1;
|
|
|
|
div = min_t(u32, div, mask);
|
|
|
|
|
|
|
|
f.pre_div = div;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
|
|
|
|
cfg &= CFG_SRC_SEL_MASK;
|
|
|
|
cfg >>= CFG_SRC_SEL_SHIFT;
|
|
|
|
|
|
|
|
for (i = 0; i < num_parents; i++) {
|
|
|
|
if (cfg == rcg->parent_map[i].cfg) {
|
|
|
|
f.src = rcg->parent_map[i].src;
|
|
|
|
return clk_rcg2_configure(rcg, &f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_byte2_set_rate_and_parent(struct clk_hw *hw,
|
|
|
|
unsigned long rate, unsigned long parent_rate, u8 index)
|
|
|
|
{
|
|
|
|
/* Read the hardware to determine parent during set_rate */
|
|
|
|
return clk_byte2_set_rate(hw, rate, parent_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct clk_ops clk_byte2_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_recalc_rate,
|
|
|
|
.set_rate = clk_byte2_set_rate,
|
|
|
|
.set_rate_and_parent = clk_byte2_set_rate_and_parent,
|
|
|
|
.determine_rate = clk_byte2_determine_rate,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_byte2_ops);
|
|
|
|
|
2014-05-17 07:07:11 +08:00
|
|
|
static const struct frac_entry frac_table_pixel[] = {
|
|
|
|
{ 3, 8 },
|
|
|
|
{ 2, 9 },
|
|
|
|
{ 4, 9 },
|
|
|
|
{ 1, 1 },
|
2022-02-28 01:55:36 +08:00
|
|
|
{ 2, 3 },
|
2014-05-17 07:07:11 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
static int clk_pixel_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
2014-05-17 07:07:11 +08:00
|
|
|
{
|
|
|
|
unsigned long request, src_rate;
|
|
|
|
int delta = 100000;
|
|
|
|
const struct frac_entry *frac = frac_table_pixel;
|
|
|
|
|
|
|
|
for (; frac->num; frac++) {
|
2015-07-08 02:48:08 +08:00
|
|
|
request = (req->rate * frac->den) / frac->num;
|
2014-05-17 07:07:11 +08:00
|
|
|
|
2015-07-31 08:20:57 +08:00
|
|
|
src_rate = clk_hw_round_rate(req->best_parent_hw, request);
|
2014-05-17 07:07:11 +08:00
|
|
|
if ((src_rate < (request - delta)) ||
|
|
|
|
(src_rate > (request + delta)))
|
|
|
|
continue;
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
req->best_parent_rate = src_rate;
|
|
|
|
req->rate = (src_rate * frac->num) / frac->den;
|
|
|
|
return 0;
|
2014-05-17 07:07:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_pixel_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
2015-04-10 14:02:02 +08:00
|
|
|
struct freq_tbl f = { 0 };
|
2014-05-17 07:07:11 +08:00
|
|
|
const struct frac_entry *frac = frac_table_pixel;
|
2015-06-26 06:35:33 +08:00
|
|
|
unsigned long request;
|
2014-05-17 07:07:11 +08:00
|
|
|
int delta = 100000;
|
|
|
|
u32 mask = BIT(rcg->hid_width) - 1;
|
2015-04-10 14:02:02 +08:00
|
|
|
u32 hid_div, cfg;
|
|
|
|
int i, num_parents = clk_hw_get_num_parents(hw);
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
|
|
|
|
cfg &= CFG_SRC_SEL_MASK;
|
|
|
|
cfg >>= CFG_SRC_SEL_SHIFT;
|
|
|
|
|
|
|
|
for (i = 0; i < num_parents; i++)
|
|
|
|
if (cfg == rcg->parent_map[i].cfg) {
|
|
|
|
f.src = rcg->parent_map[i].src;
|
|
|
|
break;
|
|
|
|
}
|
2014-05-17 07:07:11 +08:00
|
|
|
|
|
|
|
for (; frac->num; frac++) {
|
|
|
|
request = (rate * frac->den) / frac->num;
|
|
|
|
|
2015-06-26 06:35:33 +08:00
|
|
|
if ((parent_rate < (request - delta)) ||
|
|
|
|
(parent_rate > (request + delta)))
|
2014-05-17 07:07:11 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
|
|
|
|
&hid_div);
|
|
|
|
f.pre_div = hid_div;
|
|
|
|
f.pre_div >>= CFG_SRC_DIV_SHIFT;
|
|
|
|
f.pre_div &= mask;
|
|
|
|
f.m = frac->num;
|
|
|
|
f.n = frac->den;
|
|
|
|
|
|
|
|
return clk_rcg2_configure(rcg, &f);
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_pixel_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate, u8 index)
|
|
|
|
{
|
|
|
|
return clk_pixel_set_rate(hw, rate, parent_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct clk_ops clk_pixel_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_recalc_rate,
|
|
|
|
.set_rate = clk_pixel_set_rate,
|
|
|
|
.set_rate_and_parent = clk_pixel_set_rate_and_parent,
|
|
|
|
.determine_rate = clk_pixel_determine_rate,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_pixel_ops);
|
2015-12-01 09:31:41 +08:00
|
|
|
|
|
|
|
static int clk_gfx3d_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
|
|
|
{
|
2022-04-20 07:54:47 +08:00
|
|
|
struct clk_rate_request parent_req = { .min_rate = 0, .max_rate = ULONG_MAX };
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
struct clk_rcg2_gfx3d *cgfx = to_clk_rcg2_gfx3d(hw);
|
|
|
|
struct clk_hw *xo, *p0, *p1, *p2;
|
2021-03-03 07:41:06 +08:00
|
|
|
unsigned long p0_rate;
|
|
|
|
u8 mux_div = cgfx->div;
|
2015-12-01 09:31:41 +08:00
|
|
|
int ret;
|
|
|
|
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
p0 = cgfx->hws[0];
|
|
|
|
p1 = cgfx->hws[1];
|
|
|
|
p2 = cgfx->hws[2];
|
|
|
|
/*
|
|
|
|
* This function does ping-pong the RCG between PLLs: if we don't
|
|
|
|
* have at least one fixed PLL and two variable ones,
|
|
|
|
* then it's not going to work correctly.
|
|
|
|
*/
|
|
|
|
if (WARN_ON(!p0 || !p1 || !p2))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-12-01 09:31:41 +08:00
|
|
|
xo = clk_hw_get_parent_by_index(hw, 0);
|
|
|
|
if (req->rate == clk_hw_get_rate(xo)) {
|
|
|
|
req->best_parent_hw = xo;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-03 07:41:06 +08:00
|
|
|
if (mux_div == 0)
|
|
|
|
mux_div = 1;
|
|
|
|
|
|
|
|
parent_req.rate = req->rate * mux_div;
|
2015-12-01 09:31:41 +08:00
|
|
|
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
/* This has to be a fixed rate PLL */
|
|
|
|
p0_rate = clk_hw_get_rate(p0);
|
2015-12-01 09:31:41 +08:00
|
|
|
|
2021-03-03 07:41:06 +08:00
|
|
|
if (parent_req.rate == p0_rate) {
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
req->rate = req->best_parent_rate = p0_rate;
|
|
|
|
req->best_parent_hw = p0;
|
2015-12-01 09:31:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
if (req->best_parent_hw == p0) {
|
2015-12-01 09:31:41 +08:00
|
|
|
/* Are we going back to a previously used rate? */
|
2021-03-03 07:41:06 +08:00
|
|
|
if (clk_hw_get_rate(p2) == parent_req.rate)
|
2015-12-01 09:31:41 +08:00
|
|
|
req->best_parent_hw = p2;
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
else
|
|
|
|
req->best_parent_hw = p1;
|
|
|
|
} else if (req->best_parent_hw == p2) {
|
|
|
|
req->best_parent_hw = p1;
|
2015-12-01 09:31:41 +08:00
|
|
|
} else {
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
req->best_parent_hw = p2;
|
2015-12-01 09:31:41 +08:00
|
|
|
}
|
|
|
|
|
2022-08-16 19:25:29 +08:00
|
|
|
clk_hw_get_rate_range(req->best_parent_hw,
|
|
|
|
&parent_req.min_rate, &parent_req.max_rate);
|
|
|
|
|
|
|
|
if (req->min_rate > parent_req.min_rate)
|
|
|
|
parent_req.min_rate = req->min_rate;
|
|
|
|
|
|
|
|
if (req->max_rate < parent_req.max_rate)
|
|
|
|
parent_req.max_rate = req->max_rate;
|
|
|
|
|
2015-12-01 09:31:41 +08:00
|
|
|
ret = __clk_determine_rate(req->best_parent_hw, &parent_req);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
req->rate = req->best_parent_rate = parent_req.rate;
|
2021-03-03 07:41:06 +08:00
|
|
|
req->rate /= mux_div;
|
2015-12-01 09:31:41 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_gfx3d_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate, u8 index)
|
|
|
|
{
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
struct clk_rcg2_gfx3d *cgfx = to_clk_rcg2_gfx3d(hw);
|
|
|
|
struct clk_rcg2 *rcg = &cgfx->rcg;
|
2015-12-01 09:31:41 +08:00
|
|
|
u32 cfg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
cfg = rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
|
clk: qcom: rcg2: Stop hardcoding gfx3d pingpong parent numbers
The function clk_gfx3d_determine_rate is selecting different PLLs
to manage the GFX3D clock source in a special way: this one needs
to be ping-pong'ed on different PLLs to ensure stability during
frequency switching (set a PLL rate, let it stabilize, switch the
RCG to the new PLL) and fast frequency transitions.
This technique is currently being used in the MSM8996 SoC and the
function was assuming that the parents were always at a specific
index in the parents list, which is TRUE, if we use this only on
the MSM8996 MMCC.
Unfortunately, MSM8996 is not the only SoC that needs to ping-pong
the graphics RCG, so choices are:
1. Make new special ops just to hardcode *again* other indexes,
creating code duplication for (imo) no reason; or
2. Generalize this function, so that it becomes usable for a range
of SoCs with slightly different ping-pong configuration.
In this commit, the second road was taken: define a new "special"
struct clk_rcg2_gfx3d, containing the ordered list of parents to
ping-pong the graphics clock on, and the "regular" rcg2 clock
structure in order to generalize the clk_gfx3d_determine_rate
function and make it working for other SoCs.
As for the function itself it is left with the assumption that we
need to ping-pong over three parents. The reasons for this are:
1. The initial model was MSM8996, which has 3 parents for the
graphics clock pingpong;
2. The other example that was taken into consideration is the
SDM630/636/660 SoC gpu clock controller, which is ping-ponging
over two dynamic clocked and one fixed clock PLL.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@somainline.org>
Link: https://lore.kernel.org/r/20210113183817.447866-6-angelogioacchino.delregno@somainline.org
[sboyd@kernel.org: Grow some local variables, drop do_div() usage in
favor of plain division, we're not dealing with a u64 here]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2021-01-14 02:38:13 +08:00
|
|
|
/* On some targets, the GFX3D RCG may need to divide PLL frequency */
|
|
|
|
if (cgfx->div > 1)
|
|
|
|
cfg |= ((2 * cgfx->div) - 1) << CFG_SRC_DIV_SHIFT;
|
|
|
|
|
2015-12-01 09:31:41 +08:00
|
|
|
ret = regmap_write(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return update_config(rcg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We should never get here; clk_gfx3d_determine_rate() should always
|
|
|
|
* make us use a different parent than what we're currently using, so
|
|
|
|
* clk_gfx3d_set_rate_and_parent() should always be called.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct clk_ops clk_gfx3d_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_recalc_rate,
|
|
|
|
.set_rate = clk_gfx3d_set_rate,
|
|
|
|
.set_rate_and_parent = clk_gfx3d_set_rate_and_parent,
|
|
|
|
.determine_rate = clk_gfx3d_determine_rate,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_gfx3d_ops);
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
|
|
|
|
static int clk_rcg2_set_force_enable(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
const char *name = clk_hw_get_name(hw);
|
|
|
|
int ret, count;
|
|
|
|
|
|
|
|
ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
|
|
|
|
CMD_ROOT_EN, CMD_ROOT_EN);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* wait for RCG to turn ON */
|
|
|
|
for (count = 500; count > 0; count--) {
|
|
|
|
if (clk_rcg2_is_enabled(hw))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_err("%s: RCG did not turn on\n", name);
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_clear_force_enable(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
|
|
|
|
return regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
|
|
|
|
CMD_ROOT_EN, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
clk_rcg2_shared_force_enable_clear(struct clk_hw *hw, const struct freq_tbl *f)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_rcg2_set_force_enable(hw);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_rcg2_configure(rcg, f);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return clk_rcg2_clear_force_enable(hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
const struct freq_tbl *f;
|
|
|
|
|
|
|
|
f = qcom_find_freq(rcg->freq_tbl, rate);
|
|
|
|
if (!f)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
2022-04-27 05:21:36 +08:00
|
|
|
* In case clock is disabled, update the M, N and D registers, cache
|
|
|
|
* the CFG value in parked_cfg and don't hit the update bit of CMD
|
|
|
|
* register.
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
*/
|
2022-04-27 05:21:36 +08:00
|
|
|
if (!clk_hw_is_enabled(hw))
|
|
|
|
return __clk_rcg2_configure(rcg, f, &rcg->parked_cfg);
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
|
|
|
|
return clk_rcg2_shared_force_enable_clear(hw, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_shared_set_rate_and_parent(struct clk_hw *hw,
|
|
|
|
unsigned long rate, unsigned long parent_rate, u8 index)
|
|
|
|
{
|
|
|
|
return clk_rcg2_shared_set_rate(hw, rate, parent_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_shared_enable(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the update bit because required configuration has already
|
|
|
|
* been written in clk_rcg2_shared_set_rate()
|
|
|
|
*/
|
|
|
|
ret = clk_rcg2_set_force_enable(hw);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-04-27 05:21:36 +08:00
|
|
|
/* Write back the stored configuration corresponding to current rate */
|
|
|
|
ret = regmap_write(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, rcg->parked_cfg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
ret = update_config(rcg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return clk_rcg2_clear_force_enable(hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clk_rcg2_shared_disable(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store current configuration as switching to safe source would clear
|
|
|
|
* the SRC and DIV of CFG register
|
|
|
|
*/
|
2022-04-27 05:21:36 +08:00
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &rcg->parked_cfg);
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Park the RCG at a safe configuration - sourced off of safe source.
|
|
|
|
* Force enable and disable the RCG while configuring it to safeguard
|
|
|
|
* against any update signal coming from the downstream clock.
|
|
|
|
* The current parent is still prepared and enabled at this point, and
|
|
|
|
* the safe source is always on while application processor subsystem
|
|
|
|
* is online. Therefore, the RCG can safely switch its parent.
|
|
|
|
*/
|
|
|
|
clk_rcg2_set_force_enable(hw);
|
|
|
|
|
|
|
|
regmap_write(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG,
|
|
|
|
rcg->safe_src_index << CFG_SRC_SEL_SHIFT);
|
|
|
|
|
|
|
|
update_config(rcg);
|
|
|
|
|
|
|
|
clk_rcg2_clear_force_enable(hw);
|
2022-04-27 05:21:36 +08:00
|
|
|
}
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
|
2022-04-27 05:21:36 +08:00
|
|
|
static u8 clk_rcg2_shared_get_parent(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
|
|
|
|
/* If the shared rcg is parked use the cached cfg instead */
|
|
|
|
if (!clk_hw_is_enabled(hw))
|
|
|
|
return __clk_rcg2_get_parent(hw, rcg->parked_cfg);
|
|
|
|
|
|
|
|
return clk_rcg2_get_parent(hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_shared_set_parent(struct clk_hw *hw, u8 index)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
|
|
|
|
/* If the shared rcg is parked only update the cached cfg */
|
|
|
|
if (!clk_hw_is_enabled(hw)) {
|
|
|
|
rcg->parked_cfg &= ~CFG_SRC_SEL_MASK;
|
|
|
|
rcg->parked_cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return clk_rcg2_set_parent(hw, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
clk_rcg2_shared_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
|
|
|
|
/* If the shared rcg is parked use the cached cfg instead */
|
|
|
|
if (!clk_hw_is_enabled(hw))
|
|
|
|
return __clk_rcg2_recalc_rate(hw, parent_rate, rcg->parked_cfg);
|
|
|
|
|
|
|
|
return clk_rcg2_recalc_rate(hw, parent_rate);
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct clk_ops clk_rcg2_shared_ops = {
|
|
|
|
.enable = clk_rcg2_shared_enable,
|
|
|
|
.disable = clk_rcg2_shared_disable,
|
2022-04-27 05:21:36 +08:00
|
|
|
.get_parent = clk_rcg2_shared_get_parent,
|
|
|
|
.set_parent = clk_rcg2_shared_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_shared_recalc_rate,
|
clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of
its downstream clocks are disabled and RCG is in disabled state but in
reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in reality
RCG is on and it expects its new source to already be in enable state but
in reality new source is off. In order to avoid having the RCG to go into
an invalid state, add support to update the CFG, M, N and D registers
during set_rate() without configuration update and defer the actual RCG
configuration update to be done during clk_enable() as at this point of
time, both its new parent and safe source will be already enabled and RCG
can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its
parents, safe source and current parent will be enabled and RCG can
safely execute a switch.
Signed-off-by: Taniya Das <tdas@codeaurora.org>
Signed-off-by: Amit Nischal <anischal@codeaurora.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
2018-05-07 18:50:18 +08:00
|
|
|
.determine_rate = clk_rcg2_determine_rate,
|
|
|
|
.set_rate = clk_rcg2_shared_set_rate,
|
|
|
|
.set_rate_and_parent = clk_rcg2_shared_set_rate_and_parent,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_rcg2_shared_ops);
|
2018-08-11 09:53:55 +08:00
|
|
|
|
|
|
|
/* Common APIs to be used for DFS based RCGR */
|
|
|
|
static void clk_rcg2_dfs_populate_freq(struct clk_hw *hw, unsigned int l,
|
|
|
|
struct freq_tbl *f)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
struct clk_hw *p;
|
|
|
|
unsigned long prate = 0;
|
2020-01-29 03:33:29 +08:00
|
|
|
u32 val, mask, cfg, mode, src;
|
2018-08-11 09:53:55 +08:00
|
|
|
int i, num_parents;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + SE_PERF_DFSR(l), &cfg);
|
|
|
|
|
|
|
|
mask = BIT(rcg->hid_width) - 1;
|
|
|
|
f->pre_div = 1;
|
|
|
|
if (cfg & mask)
|
|
|
|
f->pre_div = cfg & mask;
|
|
|
|
|
2020-01-29 03:33:29 +08:00
|
|
|
src = cfg & CFG_SRC_SEL_MASK;
|
|
|
|
src >>= CFG_SRC_SEL_SHIFT;
|
2018-08-11 09:53:55 +08:00
|
|
|
|
|
|
|
num_parents = clk_hw_get_num_parents(hw);
|
|
|
|
for (i = 0; i < num_parents; i++) {
|
2020-01-29 03:33:29 +08:00
|
|
|
if (src == rcg->parent_map[i].cfg) {
|
2018-08-11 09:53:55 +08:00
|
|
|
f->src = rcg->parent_map[i].src;
|
|
|
|
p = clk_hw_get_parent_by_index(&rcg->clkr.hw, i);
|
|
|
|
prate = clk_hw_get_rate(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = cfg & CFG_MODE_MASK;
|
|
|
|
mode >>= CFG_MODE_SHIFT;
|
|
|
|
if (mode) {
|
|
|
|
mask = BIT(rcg->mnd_width) - 1;
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + SE_PERF_M_DFSR(l),
|
|
|
|
&val);
|
|
|
|
val &= mask;
|
|
|
|
f->m = val;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + SE_PERF_N_DFSR(l),
|
|
|
|
&val);
|
|
|
|
val = ~val;
|
|
|
|
val &= mask;
|
|
|
|
val += f->m;
|
|
|
|
f->n = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
f->freq = calc_rate(prate, f->m, f->n, mode, f->pre_div);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_dfs_populate_freq_table(struct clk_rcg2 *rcg)
|
|
|
|
{
|
|
|
|
struct freq_tbl *freq_tbl;
|
|
|
|
int i;
|
|
|
|
|
2018-08-31 01:34:37 +08:00
|
|
|
/* Allocate space for 1 extra since table is NULL terminated */
|
|
|
|
freq_tbl = kcalloc(MAX_PERF_LEVEL + 1, sizeof(*freq_tbl), GFP_KERNEL);
|
2018-08-11 09:53:55 +08:00
|
|
|
if (!freq_tbl)
|
|
|
|
return -ENOMEM;
|
|
|
|
rcg->freq_tbl = freq_tbl;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PERF_LEVEL; i++)
|
|
|
|
clk_rcg2_dfs_populate_freq(&rcg->clkr.hw, i, freq_tbl + i);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_dfs_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!rcg->freq_tbl) {
|
|
|
|
ret = clk_rcg2_dfs_populate_freq_table(rcg);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("Failed to update DFS tables for %s\n",
|
|
|
|
clk_hw_get_name(hw));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return clk_rcg2_determine_rate(hw, req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
clk_rcg2_dfs_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
u32 level, mask, cfg, m = 0, n = 0, mode, pre_div;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap,
|
|
|
|
rcg->cmd_rcgr + SE_CMD_DFSR_OFFSET, &level);
|
|
|
|
level &= GENMASK(4, 1);
|
|
|
|
level >>= 1;
|
|
|
|
|
|
|
|
if (rcg->freq_tbl)
|
|
|
|
return rcg->freq_tbl[level].freq;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assume that parent_rate is actually the parent because
|
|
|
|
* we can't do any better at figuring it out when the table
|
|
|
|
* hasn't been populated yet. We only populate the table
|
|
|
|
* in determine_rate because we can't guarantee the parents
|
|
|
|
* will be registered with the framework until then.
|
|
|
|
*/
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + SE_PERF_DFSR(level),
|
|
|
|
&cfg);
|
|
|
|
|
|
|
|
mask = BIT(rcg->hid_width) - 1;
|
|
|
|
pre_div = 1;
|
|
|
|
if (cfg & mask)
|
|
|
|
pre_div = cfg & mask;
|
|
|
|
|
|
|
|
mode = cfg & CFG_MODE_MASK;
|
|
|
|
mode >>= CFG_MODE_SHIFT;
|
|
|
|
if (mode) {
|
|
|
|
mask = BIT(rcg->mnd_width) - 1;
|
|
|
|
regmap_read(rcg->clkr.regmap,
|
|
|
|
rcg->cmd_rcgr + SE_PERF_M_DFSR(level), &m);
|
|
|
|
m &= mask;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap,
|
|
|
|
rcg->cmd_rcgr + SE_PERF_N_DFSR(level), &n);
|
|
|
|
n = ~n;
|
|
|
|
n &= mask;
|
|
|
|
n += m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return calc_rate(parent_rate, m, n, mode, pre_div);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clk_ops clk_rcg2_dfs_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.determine_rate = clk_rcg2_dfs_determine_rate,
|
|
|
|
.recalc_rate = clk_rcg2_dfs_recalc_rate,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int clk_rcg2_enable_dfs(const struct clk_rcg_dfs_data *data,
|
|
|
|
struct regmap *regmap)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = data->rcg;
|
|
|
|
struct clk_init_data *init = data->init;
|
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = regmap_read(regmap, rcg->cmd_rcgr + SE_CMD_DFSR_OFFSET, &val);
|
|
|
|
if (ret)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!(val & SE_CMD_DFS_EN))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rate changes with consumer writing a register in
|
|
|
|
* their own I/O region
|
|
|
|
*/
|
|
|
|
init->flags |= CLK_GET_RATE_NOCACHE;
|
|
|
|
init->ops = &clk_rcg2_dfs_ops;
|
|
|
|
|
|
|
|
rcg->freq_tbl = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qcom_cc_register_rcg_dfs(struct regmap *regmap,
|
|
|
|
const struct clk_rcg_dfs_data *rcgs, size_t len)
|
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
ret = clk_rcg2_enable_dfs(&rcgs[i], regmap);
|
2019-08-16 00:00:20 +08:00
|
|
|
if (ret)
|
2018-08-11 09:53:55 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_cc_register_rcg_dfs);
|
2019-08-01 02:27:12 +08:00
|
|
|
|
|
|
|
static int clk_rcg2_dp_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
struct freq_tbl f = { 0 };
|
|
|
|
u32 mask = BIT(rcg->hid_width) - 1;
|
|
|
|
u32 hid_div, cfg;
|
|
|
|
int i, num_parents = clk_hw_get_num_parents(hw);
|
|
|
|
unsigned long num, den;
|
|
|
|
|
|
|
|
rational_best_approximation(parent_rate, rate,
|
|
|
|
GENMASK(rcg->mnd_width - 1, 0),
|
|
|
|
GENMASK(rcg->mnd_width - 1, 0), &den, &num);
|
|
|
|
|
|
|
|
if (!num || !den)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
regmap_read(rcg->clkr.regmap, rcg->cmd_rcgr + CFG_REG, &cfg);
|
|
|
|
hid_div = cfg;
|
|
|
|
cfg &= CFG_SRC_SEL_MASK;
|
|
|
|
cfg >>= CFG_SRC_SEL_SHIFT;
|
|
|
|
|
|
|
|
for (i = 0; i < num_parents; i++) {
|
|
|
|
if (cfg == rcg->parent_map[i].cfg) {
|
|
|
|
f.src = rcg->parent_map[i].src;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f.pre_div = hid_div;
|
|
|
|
f.pre_div >>= CFG_SRC_DIV_SHIFT;
|
|
|
|
f.pre_div &= mask;
|
|
|
|
|
|
|
|
if (num != den) {
|
|
|
|
f.m = num;
|
|
|
|
f.n = den;
|
|
|
|
} else {
|
|
|
|
f.m = 0;
|
|
|
|
f.n = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return clk_rcg2_configure(rcg, &f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_dp_set_rate_and_parent(struct clk_hw *hw,
|
|
|
|
unsigned long rate, unsigned long parent_rate, u8 index)
|
|
|
|
{
|
|
|
|
return clk_rcg2_dp_set_rate(hw, rate, parent_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_rcg2_dp_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
|
|
|
{
|
2020-09-17 07:12:01 +08:00
|
|
|
struct clk_rcg2 *rcg = to_clk_rcg2(hw);
|
|
|
|
unsigned long num, den;
|
|
|
|
u64 tmp;
|
2019-08-01 02:27:12 +08:00
|
|
|
|
2020-09-17 07:12:01 +08:00
|
|
|
/* Parent rate is a fixed phy link rate */
|
|
|
|
rational_best_approximation(req->best_parent_rate, req->rate,
|
|
|
|
GENMASK(rcg->mnd_width - 1, 0),
|
|
|
|
GENMASK(rcg->mnd_width - 1, 0), &den, &num);
|
|
|
|
|
|
|
|
if (!num || !den)
|
|
|
|
return -EINVAL;
|
2019-08-01 02:27:12 +08:00
|
|
|
|
2020-09-17 07:12:01 +08:00
|
|
|
tmp = req->best_parent_rate * num;
|
|
|
|
do_div(tmp, den);
|
|
|
|
req->rate = tmp;
|
2019-08-01 02:27:12 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct clk_ops clk_dp_ops = {
|
|
|
|
.is_enabled = clk_rcg2_is_enabled,
|
|
|
|
.get_parent = clk_rcg2_get_parent,
|
|
|
|
.set_parent = clk_rcg2_set_parent,
|
|
|
|
.recalc_rate = clk_rcg2_recalc_rate,
|
|
|
|
.set_rate = clk_rcg2_dp_set_rate,
|
|
|
|
.set_rate_and_parent = clk_rcg2_dp_set_rate_and_parent,
|
|
|
|
.determine_rate = clk_rcg2_dp_determine_rate,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(clk_dp_ops);
|