blob: b7dc3e261f81d14d19aacac4f499cc4e67a3eb98 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada9d6652c2016-09-17 03:33:09 +09002/*
3 * Copyright (C) 2013-2014 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
Masahiro Yamada9d6652c2016-09-17 03:33:09 +09005 */
6
Masahiro Yamadaeb6aeca2017-01-21 18:05:25 +09007#include <linux/delay.h>
Masahiro Yamada9d6652c2016-09-17 03:33:09 +09008#include <linux/io.h>
9
10#include "../init.h"
11#include "../sc-regs.h"
12#include "../sg-regs.h"
13#include "pll.h"
14
15static void vpll_init(void)
16{
17 u32 tmp, clk_mode_axosel;
18
19 /* Set VPLL27A & VPLL27B */
Masahiro Yamada76b31242019-07-10 20:07:40 +090020 tmp = readl(sg_base + SG_PINMON0);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090021 clk_mode_axosel = tmp & SG_PINMON0_CLK_MODE_AXOSEL_MASK;
22
23 /* 25MHz or 6.25MHz is default for Pro4R, no need to set VPLLA/B */
24 if (clk_mode_axosel == SG_PINMON0_CLK_MODE_AXOSEL_25000KHZ ||
25 clk_mode_axosel == SG_PINMON0_CLK_MODE_AXOSEL_6250KHZ)
26 return;
27
28 /* Disable write protect of VPLL27ACTRL[2-7]*, VPLL27BCTRL[2-8] */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090029 tmp = readl(sc_base + SC_VPLL27ACTRL);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090030 tmp |= 0x00000001;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090031 writel(tmp, sc_base + SC_VPLL27ACTRL);
32 tmp = readl(sc_base + SC_VPLL27BCTRL);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090033 tmp |= 0x00000001;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090034 writel(tmp, sc_base + SC_VPLL27BCTRL);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090035
36 /* Unset VPLA_K_LD and VPLB_K_LD bit */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090037 tmp = readl(sc_base + SC_VPLL27ACTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090038 tmp &= ~0x10000000;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090039 writel(tmp, sc_base + SC_VPLL27ACTRL3);
40 tmp = readl(sc_base + SC_VPLL27BCTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090041 tmp &= ~0x10000000;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090042 writel(tmp, sc_base + SC_VPLL27BCTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090043
44 /* Set VPLA_M and VPLB_M to 0x20 */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090045 tmp = readl(sc_base + SC_VPLL27ACTRL2);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090046 tmp &= ~0x0000007f;
47 tmp |= 0x00000020;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090048 writel(tmp, sc_base + SC_VPLL27ACTRL2);
49 tmp = readl(sc_base + SC_VPLL27BCTRL2);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090050 tmp &= ~0x0000007f;
51 tmp |= 0x00000020;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090052 writel(tmp, sc_base + SC_VPLL27BCTRL2);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090053
54 if (clk_mode_axosel == SG_PINMON0_CLK_MODE_AXOSEL_25000KHZ ||
55 clk_mode_axosel == SG_PINMON0_CLK_MODE_AXOSEL_6250KHZ) {
56 /* Set VPLA_K and VPLB_K for AXO: 25MHz */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090057 tmp = readl(sc_base + SC_VPLL27ACTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090058 tmp &= ~0x000fffff;
59 tmp |= 0x00066666;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090060 writel(tmp, sc_base + SC_VPLL27ACTRL3);
61 tmp = readl(sc_base + SC_VPLL27BCTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090062 tmp &= ~0x000fffff;
63 tmp |= 0x00066666;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090064 writel(tmp, sc_base + SC_VPLL27BCTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090065 } else {
66 /* Set VPLA_K and VPLB_K for AXO: 24.576 MHz */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090067 tmp = readl(sc_base + SC_VPLL27ACTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090068 tmp &= ~0x000fffff;
69 tmp |= 0x000f5800;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090070 writel(tmp, sc_base + SC_VPLL27ACTRL3);
71 tmp = readl(sc_base + SC_VPLL27BCTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090072 tmp &= ~0x000fffff;
73 tmp |= 0x000f5800;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090074 writel(tmp, sc_base + SC_VPLL27BCTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090075 }
76
77 /* wait 1 usec */
78 udelay(1);
79
80 /* Set VPLA_K_LD and VPLB_K_LD to load K parameters */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090081 tmp = readl(sc_base + SC_VPLL27ACTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090082 tmp |= 0x10000000;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090083 writel(tmp, sc_base + SC_VPLL27ACTRL3);
84 tmp = readl(sc_base + SC_VPLL27BCTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090085 tmp |= 0x10000000;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090086 writel(tmp, sc_base + SC_VPLL27BCTRL3);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090087
88 /* Unset VPLA_SNRST and VPLB_SNRST bit */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090089 tmp = readl(sc_base + SC_VPLL27ACTRL2);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090090 tmp |= 0x10000000;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090091 writel(tmp, sc_base + SC_VPLL27ACTRL2);
92 tmp = readl(sc_base + SC_VPLL27BCTRL2);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090093 tmp |= 0x10000000;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090094 writel(tmp, sc_base + SC_VPLL27BCTRL2);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090095
96 /* Enable write protect of VPLL27ACTRL[2-7]*, VPLL27BCTRL[2-8] */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090097 tmp = readl(sc_base + SC_VPLL27ACTRL);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090098 tmp &= ~0x00000001;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090099 writel(tmp, sc_base + SC_VPLL27ACTRL);
100 tmp = readl(sc_base + SC_VPLL27BCTRL);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +0900101 tmp &= ~0x00000001;
Masahiro Yamadac84024c2019-07-10 20:07:41 +0900102 writel(tmp, sc_base + SC_VPLL27BCTRL);
Masahiro Yamada9d6652c2016-09-17 03:33:09 +0900103}
104
105void uniphier_pro4_pll_init(void)
106{
107 vpll_init();
108 uniphier_ld4_dpll_ssc_en();
109}