Skip to content

Commit 0899431

Browse files
passgatbebarino
authored andcommitted
clk: ti: add am33xx/am43xx spread spectrum clock support
The patch enables spread spectrum clocking (SSC) for MPU and LCD PLLs. As reported by the TI spruh73x/spruhl7x RM, SSC is only supported for the DISP/LCD and MPU PLLs on am33xx/am43xx. SSC is not supported for DDR, PER, and CORE PLLs. Calculating the required values and setting the registers accordingly was taken from the set_mpu_spreadspectrum routine contained in the arch/arm/mach-omap2/am33xx/clock_am33xx.c file of the u-boot project. In locked condition, DPLL output clock = CLKINP *[M/N]. In case of SSC enabled, the reference manual explains that there is a restriction of range of M values. Since the omap2_dpll_round_rate routine attempts to select the minimum possible N, the value of M obtained is not guaranteed to be within the range required. With the new "ti,min-div" parameter it is possible to increase N and consequently M to satisfy the constraint imposed by SSC. Signed-off-by: Dario Binacchi <[email protected]> Reviewed-by: Tero Kristo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 2fdf0b8 commit 0899431

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

drivers/clk/ti/dpll.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ static void __init of_ti_dpll_setup(struct device_node *node,
290290
struct clk_init_data *init = NULL;
291291
const char **parent_names = NULL;
292292
struct dpll_data *dd = NULL;
293+
int ssc_clk_index;
293294
u8 dpll_mode = 0;
295+
u32 min_div;
294296

295297
dd = kmemdup(ddt, sizeof(*dd), GFP_KERNEL);
296298
clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
@@ -345,6 +347,27 @@ static void __init of_ti_dpll_setup(struct device_node *node,
345347
if (dd->autoidle_mask) {
346348
if (ti_clk_get_reg_addr(node, 3, &dd->autoidle_reg))
347349
goto cleanup;
350+
351+
ssc_clk_index = 4;
352+
} else {
353+
ssc_clk_index = 3;
354+
}
355+
356+
if (dd->ssc_deltam_int_mask && dd->ssc_deltam_frac_mask &&
357+
dd->ssc_modfreq_mant_mask && dd->ssc_modfreq_exp_mask) {
358+
if (ti_clk_get_reg_addr(node, ssc_clk_index++,
359+
&dd->ssc_deltam_reg))
360+
goto cleanup;
361+
362+
if (ti_clk_get_reg_addr(node, ssc_clk_index++,
363+
&dd->ssc_modfreq_reg))
364+
goto cleanup;
365+
366+
of_property_read_u32(node, "ti,ssc-modfreq-hz",
367+
&dd->ssc_modfreq);
368+
of_property_read_u32(node, "ti,ssc-deltam", &dd->ssc_deltam);
369+
dd->ssc_downspread =
370+
of_property_read_bool(node, "ti,ssc-downspread");
348371
}
349372

350373
if (of_property_read_bool(node, "ti,low-power-stop"))
@@ -356,6 +379,10 @@ static void __init of_ti_dpll_setup(struct device_node *node,
356379
if (of_property_read_bool(node, "ti,lock"))
357380
dpll_mode |= 1 << DPLL_LOCKED;
358381

382+
if (!of_property_read_u32(node, "ti,min-div", &min_div) &&
383+
min_div > dd->min_divider)
384+
dd->min_divider = min_div;
385+
359386
if (dpll_mode)
360387
dd->modes = dpll_mode;
361388

@@ -585,8 +612,14 @@ static void __init of_ti_am3_no_gate_dpll_setup(struct device_node *node)
585612
const struct dpll_data dd = {
586613
.idlest_mask = 0x1,
587614
.enable_mask = 0x7,
615+
.ssc_enable_mask = 0x1 << 12,
616+
.ssc_downspread_mask = 0x1 << 14,
588617
.mult_mask = 0x7ff << 8,
589618
.div1_mask = 0x7f,
619+
.ssc_deltam_int_mask = 0x3 << 18,
620+
.ssc_deltam_frac_mask = 0x3ffff,
621+
.ssc_modfreq_mant_mask = 0x7f,
622+
.ssc_modfreq_exp_mask = 0x7 << 8,
590623
.max_multiplier = 2047,
591624
.max_divider = 128,
592625
.min_divider = 1,
@@ -645,8 +678,14 @@ static void __init of_ti_am3_dpll_setup(struct device_node *node)
645678
const struct dpll_data dd = {
646679
.idlest_mask = 0x1,
647680
.enable_mask = 0x7,
681+
.ssc_enable_mask = 0x1 << 12,
682+
.ssc_downspread_mask = 0x1 << 14,
648683
.mult_mask = 0x7ff << 8,
649684
.div1_mask = 0x7f,
685+
.ssc_deltam_int_mask = 0x3 << 18,
686+
.ssc_deltam_frac_mask = 0x3ffff,
687+
.ssc_modfreq_mant_mask = 0x7f,
688+
.ssc_modfreq_exp_mask = 0x7 << 8,
650689
.max_multiplier = 2047,
651690
.max_divider = 128,
652691
.min_divider = 1,

drivers/clk/ti/dpll3xxx.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,88 @@ static void _lookup_sddiv(struct clk_hw_omap *clk, u8 *sd_div, u16 m, u8 n)
291291
*sd_div = sd;
292292
}
293293

294+
/**
295+
* omap3_noncore_dpll_ssc_program - set spread-spectrum clocking registers
296+
* @clk: struct clk * of DPLL to set
297+
*
298+
* Enable the DPLL spread spectrum clocking if frequency modulation and
299+
* frequency spreading have been set, otherwise disable it.
300+
*/
301+
static void omap3_noncore_dpll_ssc_program(struct clk_hw_omap *clk)
302+
{
303+
struct dpll_data *dd = clk->dpll_data;
304+
unsigned long ref_rate;
305+
u32 v, ctrl, mod_freq_divider, exponent, mantissa;
306+
u32 deltam_step, deltam_ceil;
307+
308+
ctrl = ti_clk_ll_ops->clk_readl(&dd->control_reg);
309+
310+
if (dd->ssc_modfreq && dd->ssc_deltam) {
311+
ctrl |= dd->ssc_enable_mask;
312+
313+
if (dd->ssc_downspread)
314+
ctrl |= dd->ssc_downspread_mask;
315+
else
316+
ctrl &= ~dd->ssc_downspread_mask;
317+
318+
ref_rate = clk_hw_get_rate(dd->clk_ref);
319+
mod_freq_divider =
320+
(ref_rate / dd->last_rounded_n) / (4 * dd->ssc_modfreq);
321+
if (dd->ssc_modfreq > (ref_rate / 70))
322+
pr_warn("clock: SSC modulation frequency of DPLL %s greater than %ld\n",
323+
__clk_get_name(clk->hw.clk), ref_rate / 70);
324+
325+
exponent = 0;
326+
mantissa = mod_freq_divider;
327+
while ((mantissa > 127) && (exponent < 7)) {
328+
exponent++;
329+
mantissa /= 2;
330+
}
331+
if (mantissa > 127)
332+
mantissa = 127;
333+
334+
v = ti_clk_ll_ops->clk_readl(&dd->ssc_modfreq_reg);
335+
v &= ~(dd->ssc_modfreq_mant_mask | dd->ssc_modfreq_exp_mask);
336+
v |= mantissa << __ffs(dd->ssc_modfreq_mant_mask);
337+
v |= exponent << __ffs(dd->ssc_modfreq_exp_mask);
338+
ti_clk_ll_ops->clk_writel(v, &dd->ssc_modfreq_reg);
339+
340+
deltam_step = dd->last_rounded_m * dd->ssc_deltam;
341+
deltam_step /= 10;
342+
if (dd->ssc_downspread)
343+
deltam_step /= 2;
344+
345+
deltam_step <<= __ffs(dd->ssc_deltam_int_mask);
346+
deltam_step /= 100;
347+
deltam_step /= mod_freq_divider;
348+
if (deltam_step > 0xFFFFF)
349+
deltam_step = 0xFFFFF;
350+
351+
deltam_ceil = (deltam_step & dd->ssc_deltam_int_mask) >>
352+
__ffs(dd->ssc_deltam_int_mask);
353+
if (deltam_step & dd->ssc_deltam_frac_mask)
354+
deltam_ceil++;
355+
356+
if ((dd->ssc_downspread &&
357+
((dd->last_rounded_m - (2 * deltam_ceil)) < 20 ||
358+
dd->last_rounded_m > 2045)) ||
359+
((dd->last_rounded_m - deltam_ceil) < 20 ||
360+
(dd->last_rounded_m + deltam_ceil) > 2045))
361+
pr_warn("clock: SSC multiplier of DPLL %s is out of range\n",
362+
__clk_get_name(clk->hw.clk));
363+
364+
v = ti_clk_ll_ops->clk_readl(&dd->ssc_deltam_reg);
365+
v &= ~(dd->ssc_deltam_int_mask | dd->ssc_deltam_frac_mask);
366+
v |= deltam_step << __ffs(dd->ssc_deltam_int_mask |
367+
dd->ssc_deltam_frac_mask);
368+
ti_clk_ll_ops->clk_writel(v, &dd->ssc_deltam_reg);
369+
} else {
370+
ctrl &= ~dd->ssc_enable_mask;
371+
}
372+
373+
ti_clk_ll_ops->clk_writel(ctrl, &dd->control_reg);
374+
}
375+
294376
/**
295377
* omap3_noncore_dpll_program - set non-core DPLL M,N values directly
296378
* @clk: struct clk * of DPLL to set
@@ -390,6 +472,9 @@ static int omap3_noncore_dpll_program(struct clk_hw_omap *clk, u16 freqsel)
390472
ti_clk_ll_ops->clk_writel(v, &dd->control_reg);
391473
}
392474

475+
if (dd->ssc_enable_mask)
476+
omap3_noncore_dpll_ssc_program(clk);
477+
393478
/* We let the clock framework set the other output dividers later */
394479

395480
/* REVISIT: Set ramp-up delay? */

include/linux/clk/ti.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ struct clk_omap_reg {
6363
* @auto_recal_bit: bitshift of the driftguard enable bit in @control_reg
6464
* @recal_en_bit: bitshift of the PRM_IRQENABLE_* bit for recalibration IRQs
6565
* @recal_st_bit: bitshift of the PRM_IRQSTATUS_* bit for recalibration IRQs
66+
* @ssc_deltam_reg: register containing the DPLL SSC frequency spreading
67+
* @ssc_modfreq_reg: register containing the DPLL SSC modulation frequency
68+
* @ssc_modfreq_mant_mask: mask of the mantissa component in @ssc_modfreq_reg
69+
* @ssc_modfreq_exp_mask: mask of the exponent component in @ssc_modfreq_reg
70+
* @ssc_enable_mask: mask of the DPLL SSC enable bit in @control_reg
71+
* @ssc_downspread_mask: mask of the DPLL SSC low frequency only bit in
72+
* @control_reg
73+
* @ssc_modfreq: the DPLL SSC frequency modulation in kHz
74+
* @ssc_deltam: the DPLL SSC frequency spreading in permille (10th of percent)
75+
* @ssc_downspread: require the only low frequency spread of the DPLL in SSC
76+
* mode
6677
* @flags: DPLL type/features (see below)
6778
*
6879
* Possible values for @flags:
@@ -110,6 +121,17 @@ struct dpll_data {
110121
u8 auto_recal_bit;
111122
u8 recal_en_bit;
112123
u8 recal_st_bit;
124+
struct clk_omap_reg ssc_deltam_reg;
125+
struct clk_omap_reg ssc_modfreq_reg;
126+
u32 ssc_deltam_int_mask;
127+
u32 ssc_deltam_frac_mask;
128+
u32 ssc_modfreq_mant_mask;
129+
u32 ssc_modfreq_exp_mask;
130+
u32 ssc_enable_mask;
131+
u32 ssc_downspread_mask;
132+
u32 ssc_modfreq;
133+
u32 ssc_deltam;
134+
bool ssc_downspread;
113135
u8 flags;
114136
};
115137

0 commit comments

Comments
 (0)