2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-09-16 18:33:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Socionext Inc.
|
|
|
|
* Author: Masahiro Yamada <yamada.masahiro@socionext.com>
|
|
|
|
*/
|
|
|
|
|
2017-12-06 05:16:34 +00:00
|
|
|
#include <linux/bitfield.h>
|
2016-09-16 18:33:11 +00:00
|
|
|
#include <linux/bitops.h>
|
2017-01-21 09:05:25 +00:00
|
|
|
#include <linux/delay.h>
|
2017-12-06 05:16:33 +00:00
|
|
|
#include <linux/kernel.h>
|
2017-01-21 09:05:25 +00:00
|
|
|
#include <linux/errno.h>
|
2016-09-16 18:33:11 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/sizes.h>
|
|
|
|
|
2019-07-10 11:07:41 +00:00
|
|
|
#include "../sc64-regs.h"
|
2016-09-16 18:33:11 +00:00
|
|
|
#include "pll.h"
|
|
|
|
|
|
|
|
/* PLL type: SSC */
|
|
|
|
#define SC_PLLCTRL_SSC_DK_MASK GENMASK(14, 0)
|
|
|
|
#define SC_PLLCTRL_SSC_EN BIT(31)
|
|
|
|
#define SC_PLLCTRL2_NRSTDS BIT(28)
|
|
|
|
#define SC_PLLCTRL2_SSC_JK_MASK GENMASK(26, 0)
|
2017-02-21 14:00:35 +00:00
|
|
|
#define SC_PLLCTRL3_REGI_MASK GENMASK(19, 16)
|
2016-09-16 18:33:11 +00:00
|
|
|
|
|
|
|
/* PLL type: VPLL27 */
|
|
|
|
#define SC_VPLL27CTRL_WP BIT(0)
|
|
|
|
#define SC_VPLL27CTRL3_K_LD BIT(28)
|
|
|
|
|
|
|
|
/* PLL type: DSPLL */
|
|
|
|
#define SC_DSPLLCTRL2_K_LD BIT(28)
|
|
|
|
|
|
|
|
int uniphier_ld20_sscpll_init(unsigned long reg_base, unsigned int freq,
|
|
|
|
unsigned int ssc_rate, unsigned int divn)
|
|
|
|
{
|
2019-07-10 11:07:41 +00:00
|
|
|
void __iomem *base = sc_base + reg_base;
|
2016-09-16 18:33:11 +00:00
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
if (freq != UNIPHIER_PLL_FREQ_DEFAULT) {
|
|
|
|
tmp = readl(base); /* SSCPLLCTRL */
|
|
|
|
tmp &= ~SC_PLLCTRL_SSC_DK_MASK;
|
2017-12-06 05:16:34 +00:00
|
|
|
tmp |= FIELD_PREP(SC_PLLCTRL_SSC_DK_MASK,
|
|
|
|
DIV_ROUND_CLOSEST(487UL * freq * ssc_rate,
|
|
|
|
divn * 512));
|
2016-09-16 18:33:11 +00:00
|
|
|
writel(tmp, base);
|
|
|
|
|
|
|
|
tmp = readl(base + 4);
|
|
|
|
tmp &= ~SC_PLLCTRL2_SSC_JK_MASK;
|
2017-12-06 05:16:34 +00:00
|
|
|
tmp |= FIELD_PREP(SC_PLLCTRL2_SSC_JK_MASK,
|
|
|
|
DIV_ROUND_CLOSEST(21431887UL * freq,
|
|
|
|
divn * 512));
|
2017-12-06 05:16:32 +00:00
|
|
|
writel(tmp, base + 4);
|
2016-09-16 18:33:11 +00:00
|
|
|
|
|
|
|
udelay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = readl(base + 4); /* SSCPLLCTRL2 */
|
|
|
|
tmp |= SC_PLLCTRL2_NRSTDS;
|
|
|
|
writel(tmp, base + 4);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uniphier_ld20_sscpll_ssc_en(unsigned long reg_base)
|
|
|
|
{
|
2019-07-10 11:07:41 +00:00
|
|
|
void __iomem *base = sc_base + reg_base;
|
2016-09-16 18:33:11 +00:00
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
tmp = readl(base); /* SSCPLLCTRL */
|
|
|
|
tmp |= SC_PLLCTRL_SSC_EN;
|
|
|
|
writel(tmp, base);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-21 14:00:35 +00:00
|
|
|
int uniphier_ld20_sscpll_set_regi(unsigned long reg_base, unsigned regi)
|
|
|
|
{
|
2019-07-10 11:07:41 +00:00
|
|
|
void __iomem *base = sc_base + reg_base;
|
2017-02-21 14:00:35 +00:00
|
|
|
u32 tmp;
|
|
|
|
|
2017-08-28 12:57:15 +00:00
|
|
|
tmp = readl(base + 8); /* SSCPLLCTRL3 */
|
2017-02-21 14:00:35 +00:00
|
|
|
tmp &= ~SC_PLLCTRL3_REGI_MASK;
|
2017-12-06 05:16:34 +00:00
|
|
|
tmp |= FIELD_PREP(SC_PLLCTRL3_REGI_MASK, regi);
|
2017-02-21 14:00:35 +00:00
|
|
|
writel(tmp, base + 8);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-16 18:33:11 +00:00
|
|
|
int uniphier_ld20_vpll27_init(unsigned long reg_base)
|
|
|
|
{
|
2019-07-10 11:07:41 +00:00
|
|
|
void __iomem *base = sc_base + reg_base;
|
2016-09-16 18:33:11 +00:00
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
tmp = readl(base); /* VPLL27CTRL */
|
|
|
|
tmp |= SC_VPLL27CTRL_WP; /* write protect off */
|
|
|
|
writel(tmp, base);
|
|
|
|
|
|
|
|
tmp = readl(base + 8); /* VPLL27CTRL3 */
|
|
|
|
tmp |= SC_VPLL27CTRL3_K_LD;
|
|
|
|
writel(tmp, base + 8);
|
|
|
|
|
|
|
|
tmp = readl(base); /* VPLL27CTRL */
|
|
|
|
tmp &= ~SC_VPLL27CTRL_WP; /* write protect on */
|
|
|
|
writel(tmp, base);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uniphier_ld20_dspll_init(unsigned long reg_base)
|
|
|
|
{
|
2019-07-10 11:07:41 +00:00
|
|
|
void __iomem *base = sc_base + reg_base;
|
2016-09-16 18:33:11 +00:00
|
|
|
u32 tmp;
|
|
|
|
|
2017-08-28 12:57:15 +00:00
|
|
|
tmp = readl(base + 4); /* DSPLLCTRL2 */
|
2016-09-16 18:33:11 +00:00
|
|
|
tmp |= SC_DSPLLCTRL2_K_LD;
|
2017-08-28 12:57:15 +00:00
|
|
|
writel(tmp, base + 4);
|
2016-09-16 18:33:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|