blob: f24a0eb0b82741bfebae121c6ca3240967b1f2c3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09002/*
Masahiro Yamada9d6652c2016-09-17 03:33:09 +09003 * Copyright (C) 2013-2014 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09005 */
6
Simon Glassdbd79542020-05-10 11:40:11 -06007#include <linux/delay.h>
Masahiro Yamadae4e789d2017-01-21 18:05:24 +09008#include <linux/errno.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +09009#include <linux/io.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060010#include <linux/printk.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090011
12#include "../init.h"
13#include "../sc-regs.h"
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090014
15#undef DPLL_SSC_RATE_1PER
16
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090017int uniphier_ld4_dpll_init(const struct uniphier_board_data *bd)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090018{
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090019 unsigned int dram_freq = bd->dram_freq;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090020 u32 tmp;
21
22 /*
23 * Set Frequency
24 * Set 0xc(1600MHz)/0xd(1333MHz)/0xe(1066MHz)
25 * to FOUT (DPLLCTRL.bit[29:20])
26 */
Masahiro Yamadac84024c2019-07-10 20:07:41 +090027 tmp = readl(sc_base + SC_DPLLCTRL);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090028 tmp &= ~0x000f0000;
Masahiro Yamada75f16f82015-09-22 00:27:39 +090029 switch (dram_freq) {
30 case 1333:
31 tmp |= 0x000d0000;
32 break;
33 case 1600:
34 tmp |= 0x000c0000;
35 break;
36 default:
37 pr_err("Unsupported frequency");
38 return -EINVAL;
39 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090040
41#if defined(DPLL_SSC_RATE_1PER)
42 tmp &= ~SC_DPLLCTRL_SSC_RATE;
43#else
44 tmp |= SC_DPLLCTRL_SSC_RATE;
45#endif
Masahiro Yamadac84024c2019-07-10 20:07:41 +090046 writel(tmp, sc_base + SC_DPLLCTRL);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090047
Masahiro Yamadac84024c2019-07-10 20:07:41 +090048 tmp = readl(sc_base + SC_DPLLCTRL2);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090049 tmp |= SC_DPLLCTRL2_NRSTDS;
Masahiro Yamadac84024c2019-07-10 20:07:41 +090050 writel(tmp, sc_base + SC_DPLLCTRL2);
Masahiro Yamada75f16f82015-09-22 00:27:39 +090051
Masahiro Yamada9d6652c2016-09-17 03:33:09 +090052 /* Wait 500 usec until dpll gets stable */
53 udelay(500);
Masahiro Yamada75f16f82015-09-22 00:27:39 +090054
55 return 0;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090056}