2 * Copyright (C) 2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <linux/bitops.h>
11 #include <linux/sizes.h>
16 #define SC_PLLCTRL_SSC_DK_MASK GENMASK(14, 0)
17 #define SC_PLLCTRL_SSC_EN BIT(31)
18 #define SC_PLLCTRL2_NRSTDS BIT(28)
19 #define SC_PLLCTRL2_SSC_JK_MASK GENMASK(26, 0)
21 /* PLL type: VPLL27 */
22 #define SC_VPLL27CTRL_WP BIT(0)
23 #define SC_VPLL27CTRL3_K_LD BIT(28)
26 #define SC_DSPLLCTRL2_K_LD BIT(28)
28 int uniphier_ld20_sscpll_init(unsigned long reg_base, unsigned int freq,
29 unsigned int ssc_rate, unsigned int divn)
34 base = ioremap(reg_base, SZ_16);
38 if (freq != UNIPHIER_PLL_FREQ_DEFAULT) {
39 tmp = readl(base); /* SSCPLLCTRL */
40 tmp &= ~SC_PLLCTRL_SSC_DK_MASK;
41 tmp |= (487 * freq * ssc_rate / divn / 512) &
42 SC_PLLCTRL_SSC_DK_MASK;
45 tmp = readl(base + 4);
46 tmp &= ~SC_PLLCTRL2_SSC_JK_MASK;
47 tmp |= (41859 * freq / divn) & SC_PLLCTRL2_SSC_JK_MASK;
52 tmp = readl(base + 4); /* SSCPLLCTRL2 */
53 tmp |= SC_PLLCTRL2_NRSTDS;
54 writel(tmp, base + 4);
61 int uniphier_ld20_sscpll_ssc_en(unsigned long reg_base)
66 base = ioremap(reg_base, SZ_16);
72 tmp = readl(base); /* SSCPLLCTRL */
73 tmp |= SC_PLLCTRL_SSC_EN;
81 int uniphier_ld20_vpll27_init(unsigned long reg_base)
86 base = ioremap(reg_base, SZ_16);
90 tmp = readl(base); /* VPLL27CTRL */
91 tmp |= SC_VPLL27CTRL_WP; /* write protect off */
94 tmp = readl(base + 8); /* VPLL27CTRL3 */
95 tmp |= SC_VPLL27CTRL3_K_LD;
96 writel(tmp, base + 8);
98 tmp = readl(base); /* VPLL27CTRL */
99 tmp &= ~SC_VPLL27CTRL_WP; /* write protect on */
107 int uniphier_ld20_dspll_init(unsigned long reg_base)
112 base = ioremap(reg_base, SZ_16);
116 tmp = readl(base + 8); /* DSPLLCTRL2 */
117 tmp |= SC_DSPLLCTRL2_K_LD;
118 writel(tmp, base + 8);