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);
70 tmp = readl(base); /* SSCPLLCTRL */
71 tmp |= SC_PLLCTRL_SSC_EN;
79 int uniphier_ld20_vpll27_init(unsigned long reg_base)
84 base = ioremap(reg_base, SZ_16);
88 tmp = readl(base); /* VPLL27CTRL */
89 tmp |= SC_VPLL27CTRL_WP; /* write protect off */
92 tmp = readl(base + 8); /* VPLL27CTRL3 */
93 tmp |= SC_VPLL27CTRL3_K_LD;
94 writel(tmp, base + 8);
96 tmp = readl(base); /* VPLL27CTRL */
97 tmp &= ~SC_VPLL27CTRL_WP; /* write protect on */
105 int uniphier_ld20_dspll_init(unsigned long reg_base)
110 base = ioremap(reg_base, SZ_16);
114 tmp = readl(base + 8); /* DSPLLCTRL2 */
115 tmp |= SC_DSPLLCTRL2_K_LD;
116 writel(tmp, base + 8);