summaryrefslogtreecommitdiff
path: root/arch/arm/mach-uniphier/clk/pll-base-ld20.c
blob: caa631d9f766ebb243d249078c3ec642b916dbde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (C) 2016 Socionext Inc.
 *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <linux/bitops.h>
#include <linux/io.h>
#include <linux/sizes.h>

#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)

/* 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)
{
	void __iomem *base;
	u32 tmp;

	base = ioremap(reg_base, SZ_16);
	if (!base)
		return -ENOMEM;

	if (freq != UNIPHIER_PLL_FREQ_DEFAULT) {
		tmp = readl(base);	/* SSCPLLCTRL */
		tmp &= ~SC_PLLCTRL_SSC_DK_MASK;
		tmp |= (487 * freq * ssc_rate / divn / 512) &
							SC_PLLCTRL_SSC_DK_MASK;
		writel(tmp, base);

		tmp = readl(base + 4);
		tmp &= ~SC_PLLCTRL2_SSC_JK_MASK;
		tmp |= (41859 * freq / divn) & SC_PLLCTRL2_SSC_JK_MASK;

		udelay(50);
	}

	tmp = readl(base + 4);		/* SSCPLLCTRL2 */
	tmp |= SC_PLLCTRL2_NRSTDS;
	writel(tmp, base + 4);

	iounmap(base);

	return 0;
}

int uniphier_ld20_sscpll_ssc_en(unsigned long reg_base)
{
	void __iomem *base;
	u32 tmp;

	base = ioremap(reg_base, SZ_16);
	if (!base)
		return -ENOMEM;

	tmp = readl(base);	/* SSCPLLCTRL */
	tmp |= SC_PLLCTRL_SSC_EN;
	writel(tmp, base);

	iounmap(base);

	return 0;
}

int uniphier_ld20_vpll27_init(unsigned long reg_base)
{
	void __iomem *base;
	u32 tmp;

	base = ioremap(reg_base, SZ_16);
	if (!base)
		return -ENOMEM;

	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);

	iounmap(base);

	return 0;
}

int uniphier_ld20_dspll_init(unsigned long reg_base)
{
	void __iomem *base;
	u32 tmp;

	base = ioremap(reg_base, SZ_16);
	if (!base)
		return -ENOMEM;

	tmp = readl(base + 8);		/* DSPLLCTRL2 */
	tmp |= SC_DSPLLCTRL2_K_LD;
	writel(tmp, base + 8);

	iounmap(base);

	return 0;
}