Skip to content

Commit 9d9cc58

Browse files
XBurstbebarino
authored andcommitted
clk: Ingenic: Adjust cgu code to make it compatible with X1830.
The PLL of X1830 Soc from Ingenic has been greatly changed, the bypass control is placed in another register, so now two registers may needed to control the PLL. To this end, a new "bypass_reg" was introduced. In addition, when calculating rate, the PLL of X1830 introduced an extra 2x multiplier, so a new "rate_multiplier" was introduced. And adjust the code in jz47xx-cgu.c and x1000-cgu.c, make it to be compatible with the new cgu code. Signed-off-by: 周琰杰 (Zhou Yanjie) <[email protected]> Reviewed-by: Paul Cercueil <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 15e3ae3 commit 9d9cc58

File tree

7 files changed

+41
-4
lines changed

7 files changed

+41
-4
lines changed

drivers/clk/ingenic/cgu.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ ingenic_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
9090
n += pll_info->n_offset;
9191
od_enc = ctl >> pll_info->od_shift;
9292
od_enc &= GENMASK(pll_info->od_bits - 1, 0);
93+
94+
ctl = readl(cgu->base + pll_info->bypass_reg);
95+
9396
bypass = !pll_info->no_bypass_bit &&
9497
!!(ctl & BIT(pll_info->bypass_bit));
9598

@@ -103,7 +106,8 @@ ingenic_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
103106
BUG_ON(od == pll_info->od_max);
104107
od++;
105108

106-
return div_u64((u64)parent_rate * m, n * od);
109+
return div_u64((u64)parent_rate * m * pll_info->rate_multiplier,
110+
n * od);
107111
}
108112

109113
static unsigned long
@@ -136,7 +140,8 @@ ingenic_pll_calc(const struct ingenic_cgu_clk_info *clk_info,
136140
if (pod)
137141
*pod = od;
138142

139-
return div_u64((u64)parent_rate * m, n * od);
143+
return div_u64((u64)parent_rate * m * pll_info->rate_multiplier,
144+
n * od);
140145
}
141146

142147
static inline const struct ingenic_cgu_clk_info *to_clk_info(
@@ -209,9 +214,14 @@ static int ingenic_pll_enable(struct clk_hw *hw)
209214
u32 ctl;
210215

211216
spin_lock_irqsave(&cgu->lock, flags);
212-
ctl = readl(cgu->base + pll_info->reg);
217+
ctl = readl(cgu->base + pll_info->bypass_reg);
213218

214219
ctl &= ~BIT(pll_info->bypass_bit);
220+
221+
writel(ctl, cgu->base + pll_info->bypass_reg);
222+
223+
ctl = readl(cgu->base + pll_info->reg);
224+
215225
ctl |= BIT(pll_info->enable_bit);
216226

217227
writel(ctl, cgu->base + pll_info->reg);

drivers/clk/ingenic/cgu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/**
1818
* struct ingenic_cgu_pll_info - information about a PLL
1919
* @reg: the offset of the PLL's control register within the CGU
20+
* @rate_multiplier: the multiplier needed by pll rate calculation
2021
* @m_shift: the number of bits to shift the multiplier value by (ie. the
2122
* index of the lowest bit of the multiplier value in the PLL's
2223
* control register)
@@ -37,17 +38,20 @@
3738
* @od_encoding: a pointer to an array mapping post-VCO divider values to
3839
* their encoded values in the PLL control register, or -1 for
3940
* unsupported values
41+
* @bypass_reg: the offset of the bypass control register within the CGU
4042
* @bypass_bit: the index of the bypass bit in the PLL control register
4143
* @enable_bit: the index of the enable bit in the PLL control register
4244
* @stable_bit: the index of the stable bit in the PLL control register
4345
* @no_bypass_bit: if set, the PLL has no bypass functionality
4446
*/
4547
struct ingenic_cgu_pll_info {
4648
unsigned reg;
49+
unsigned rate_multiplier;
4750
const s8 *od_encoding;
4851
u8 m_shift, m_bits, m_offset;
4952
u8 n_shift, n_bits, n_offset;
5053
u8 od_shift, od_bits, od_max;
54+
unsigned bypass_reg;
5155
u8 bypass_bit;
5256
u8 enable_bit;
5357
u8 stable_bit;

drivers/clk/ingenic/jz4725b-cgu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <linux/clk-provider.h>
1010
#include <linux/delay.h>
1111
#include <linux/of.h>
12+
1213
#include <dt-bindings/clock/jz4725b-cgu.h>
14+
1315
#include "cgu.h"
1416
#include "pm.h"
1517

@@ -54,6 +56,7 @@ static const struct ingenic_cgu_clk_info jz4725b_cgu_clocks[] = {
5456
.parents = { JZ4725B_CLK_EXT, -1, -1, -1 },
5557
.pll = {
5658
.reg = CGU_REG_CPPCR,
59+
.rate_multiplier = 1,
5760
.m_shift = 23,
5861
.m_bits = 9,
5962
.m_offset = 2,
@@ -65,6 +68,7 @@ static const struct ingenic_cgu_clk_info jz4725b_cgu_clocks[] = {
6568
.od_max = 4,
6669
.od_encoding = pll_od_encoding,
6770
.stable_bit = 10,
71+
.bypass_reg = CGU_REG_CPPCR,
6872
.bypass_bit = 9,
6973
.enable_bit = 8,
7074
},

drivers/clk/ingenic/jz4740-cgu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include <linux/delay.h>
1111
#include <linux/io.h>
1212
#include <linux/of.h>
13+
1314
#include <dt-bindings/clock/jz4740-cgu.h>
15+
1416
#include "cgu.h"
1517
#include "pm.h"
1618

@@ -69,6 +71,7 @@ static const struct ingenic_cgu_clk_info jz4740_cgu_clocks[] = {
6971
.parents = { JZ4740_CLK_EXT, -1, -1, -1 },
7072
.pll = {
7173
.reg = CGU_REG_CPPCR,
74+
.rate_multiplier = 1,
7275
.m_shift = 23,
7376
.m_bits = 9,
7477
.m_offset = 2,
@@ -80,6 +83,7 @@ static const struct ingenic_cgu_clk_info jz4740_cgu_clocks[] = {
8083
.od_max = 4,
8184
.od_encoding = pll_od_encoding,
8285
.stable_bit = 10,
86+
.bypass_reg = CGU_REG_CPPCR,
8387
.bypass_bit = 9,
8488
.enable_bit = 8,
8589
},

drivers/clk/ingenic/jz4770-cgu.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <linux/delay.h>
1010
#include <linux/io.h>
1111
#include <linux/of.h>
12+
1213
#include <dt-bindings/clock/jz4770-cgu.h>
14+
1315
#include "cgu.h"
1416
#include "pm.h"
1517

@@ -102,6 +104,7 @@ static const struct ingenic_cgu_clk_info jz4770_cgu_clocks[] = {
102104
.parents = { JZ4770_CLK_EXT },
103105
.pll = {
104106
.reg = CGU_REG_CPPCR0,
107+
.rate_multiplier = 1,
105108
.m_shift = 24,
106109
.m_bits = 7,
107110
.m_offset = 1,
@@ -112,6 +115,7 @@ static const struct ingenic_cgu_clk_info jz4770_cgu_clocks[] = {
112115
.od_bits = 2,
113116
.od_max = 8,
114117
.od_encoding = pll_od_encoding,
118+
.bypass_reg = CGU_REG_CPPCR0,
115119
.bypass_bit = 9,
116120
.enable_bit = 8,
117121
.stable_bit = 10,
@@ -124,6 +128,7 @@ static const struct ingenic_cgu_clk_info jz4770_cgu_clocks[] = {
124128
.parents = { JZ4770_CLK_EXT },
125129
.pll = {
126130
.reg = CGU_REG_CPPCR1,
131+
.rate_multiplier = 1,
127132
.m_shift = 24,
128133
.m_bits = 7,
129134
.m_offset = 1,
@@ -134,9 +139,10 @@ static const struct ingenic_cgu_clk_info jz4770_cgu_clocks[] = {
134139
.od_bits = 2,
135140
.od_max = 8,
136141
.od_encoding = pll_od_encoding,
142+
.bypass_reg = CGU_REG_CPPCR1,
143+
.no_bypass_bit = true,
137144
.enable_bit = 7,
138145
.stable_bit = 6,
139-
.no_bypass_bit = true,
140146
},
141147
},
142148

drivers/clk/ingenic/jz4780-cgu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/of.h>
1414

1515
#include <dt-bindings/clock/jz4780-cgu.h>
16+
1617
#include "cgu.h"
1718
#include "pm.h"
1819

@@ -266,6 +267,7 @@ static const struct ingenic_cgu_clk_info jz4780_cgu_clocks[] = {
266267

267268
#define DEF_PLL(name) { \
268269
.reg = CGU_REG_ ## name, \
270+
.rate_multiplier = 1, \
269271
.m_shift = 19, \
270272
.m_bits = 13, \
271273
.m_offset = 1, \
@@ -277,6 +279,7 @@ static const struct ingenic_cgu_clk_info jz4780_cgu_clocks[] = {
277279
.od_max = 16, \
278280
.od_encoding = pll_od_encoding, \
279281
.stable_bit = 6, \
282+
.bypass_reg = CGU_REG_ ## name, \
280283
.bypass_bit = 1, \
281284
.enable_bit = 0, \
282285
}

drivers/clk/ingenic/x1000-cgu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include <linux/clk-provider.h>
88
#include <linux/delay.h>
99
#include <linux/of.h>
10+
1011
#include <dt-bindings/clock/x1000-cgu.h>
12+
1113
#include "cgu.h"
1214
#include "pm.h"
1315

@@ -58,6 +60,7 @@ static const struct ingenic_cgu_clk_info x1000_cgu_clocks[] = {
5860
.parents = { X1000_CLK_EXCLK, -1, -1, -1 },
5961
.pll = {
6062
.reg = CGU_REG_APLL,
63+
.rate_multiplier = 1,
6164
.m_shift = 24,
6265
.m_bits = 7,
6366
.m_offset = 1,
@@ -68,6 +71,7 @@ static const struct ingenic_cgu_clk_info x1000_cgu_clocks[] = {
6871
.od_bits = 2,
6972
.od_max = 8,
7073
.od_encoding = pll_od_encoding,
74+
.bypass_reg = CGU_REG_APLL,
7175
.bypass_bit = 9,
7276
.enable_bit = 8,
7377
.stable_bit = 10,
@@ -79,6 +83,7 @@ static const struct ingenic_cgu_clk_info x1000_cgu_clocks[] = {
7983
.parents = { X1000_CLK_EXCLK, -1, -1, -1 },
8084
.pll = {
8185
.reg = CGU_REG_MPLL,
86+
.rate_multiplier = 1,
8287
.m_shift = 24,
8388
.m_bits = 7,
8489
.m_offset = 1,
@@ -89,6 +94,7 @@ static const struct ingenic_cgu_clk_info x1000_cgu_clocks[] = {
8994
.od_bits = 2,
9095
.od_max = 8,
9196
.od_encoding = pll_od_encoding,
97+
.bypass_reg = CGU_REG_MPLL,
9298
.bypass_bit = 6,
9399
.enable_bit = 7,
94100
.stable_bit = 0,

0 commit comments

Comments
 (0)