blob: 62594954848cdde3c8b29ad36dc8451d08e0c3e1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada5894ca02014-10-03 19:21:06 +09002/*
Masahiro Yamada6a3e4272016-09-17 03:33:09 +09003 * Copyright (C) 2013-2014 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
Masahiro Yamada5894ca02014-10-03 19:21:06 +09005 */
6
7#include <common.h>
Masahiro Yamada0f4ec052017-01-21 18:05:24 +09008#include <linux/errno.h>
Masahiro Yamadaf6e7f072015-05-29 17:30:00 +09009#include <linux/io.h>
Masahiro Yamada107b3fb2016-01-09 01:51:13 +090010
11#include "../init.h"
12#include "../sc-regs.h"
Masahiro Yamada5894ca02014-10-03 19:21:06 +090013
14#undef DPLL_SSC_RATE_1PER
15
Masahiro Yamada6a3e4272016-09-17 03:33:09 +090016int uniphier_pro4_dpll_init(const struct uniphier_board_data *bd)
Masahiro Yamada5894ca02014-10-03 19:21:06 +090017{
Masahiro Yamada6a3e4272016-09-17 03:33:09 +090018 unsigned int dram_freq = bd->dram_freq;
Masahiro Yamada5894ca02014-10-03 19:21:06 +090019 u32 tmp;
20
21 /*
22 * Set Frequency
23 * Set 0xc(1600MHz)/0xd(1333MHz)/0xe(1066MHz)
24 * to FOUT ( DPLLCTRL.bit[29:20] )
25 */
Masahiro Yamada739ba412019-07-10 20:07:41 +090026 tmp = readl(sc_base + SC_DPLLCTRL);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090027 tmp &= ~(0x000f0000);
Masahiro Yamada323d1f92015-09-22 00:27:39 +090028 switch (dram_freq) {
29 case 1333:
30 tmp |= 0x000d0000;
31 break;
32 case 1600:
33 tmp |= 0x000c0000;
34 break;
35 default:
36 pr_err("Unsupported frequency");
37 return -EINVAL;
38 }
Masahiro Yamada5894ca02014-10-03 19:21:06 +090039
40 /*
41 * Set Moduration rate
42 * Set 0x0(1%)/0x1(2%) to SSC_RATE(DPLLCTRL.bit[15])
43 */
44#if defined(DPLL_SSC_RATE_1PER)
45 tmp &= ~0x00008000;
46#else
47 tmp |= 0x00008000;
48#endif
Masahiro Yamada739ba412019-07-10 20:07:41 +090049 writel(tmp, sc_base + SC_DPLLCTRL);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090050
Masahiro Yamada739ba412019-07-10 20:07:41 +090051 tmp = readl(sc_base + SC_DPLLCTRL2);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090052 tmp |= SC_DPLLCTRL2_NRSTDS;
Masahiro Yamada739ba412019-07-10 20:07:41 +090053 writel(tmp, sc_base + SC_DPLLCTRL2);
Masahiro Yamada323d1f92015-09-22 00:27:39 +090054
Masahiro Yamada6a3e4272016-09-17 03:33:09 +090055 /* Wait until dpll gets stable */
56 udelay(500);
Masahiro Yamada323d1f92015-09-22 00:27:39 +090057
58 return 0;
Masahiro Yamada5894ca02014-10-03 19:21:06 +090059}