Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | 9d6652c | 2016-09-17 03:33:09 +0900 | [diff] [blame] | 3 | * Copyright (C) 2013-2014 Panasonic Corporation |
| 4 | * Copyright (C) 2015-2016 Socionext Inc. |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Masahiro Yamada | e4e789d | 2017-01-21 18:05:24 +0900 | [diff] [blame] | 8 | #include <linux/errno.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 9 | #include <linux/io.h> |
Masahiro Yamada | efdf340 | 2016-01-09 01:51:13 +0900 | [diff] [blame] | 10 | |
| 11 | #include "../init.h" |
| 12 | #include "../sc-regs.h" |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 13 | |
| 14 | #undef DPLL_SSC_RATE_1PER |
| 15 | |
Masahiro Yamada | 9d6652c | 2016-09-17 03:33:09 +0900 | [diff] [blame] | 16 | int uniphier_ld4_dpll_init(const struct uniphier_board_data *bd) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 17 | { |
Masahiro Yamada | 9d6652c | 2016-09-17 03:33:09 +0900 | [diff] [blame] | 18 | unsigned int dram_freq = bd->dram_freq; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 19 | u32 tmp; |
| 20 | |
| 21 | /* |
| 22 | * Set Frequency |
| 23 | * Set 0xc(1600MHz)/0xd(1333MHz)/0xe(1066MHz) |
| 24 | * to FOUT (DPLLCTRL.bit[29:20]) |
| 25 | */ |
Masahiro Yamada | c84024c | 2019-07-10 20:07:41 +0900 | [diff] [blame] | 26 | tmp = readl(sc_base + SC_DPLLCTRL); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 27 | tmp &= ~0x000f0000; |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 28 | 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 Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 39 | |
| 40 | #if defined(DPLL_SSC_RATE_1PER) |
| 41 | tmp &= ~SC_DPLLCTRL_SSC_RATE; |
| 42 | #else |
| 43 | tmp |= SC_DPLLCTRL_SSC_RATE; |
| 44 | #endif |
Masahiro Yamada | c84024c | 2019-07-10 20:07:41 +0900 | [diff] [blame] | 45 | writel(tmp, sc_base + SC_DPLLCTRL); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 46 | |
Masahiro Yamada | c84024c | 2019-07-10 20:07:41 +0900 | [diff] [blame] | 47 | tmp = readl(sc_base + SC_DPLLCTRL2); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 48 | tmp |= SC_DPLLCTRL2_NRSTDS; |
Masahiro Yamada | c84024c | 2019-07-10 20:07:41 +0900 | [diff] [blame] | 49 | writel(tmp, sc_base + SC_DPLLCTRL2); |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 50 | |
Masahiro Yamada | 9d6652c | 2016-09-17 03:33:09 +0900 | [diff] [blame] | 51 | /* Wait 500 usec until dpll gets stable */ |
| 52 | udelay(500); |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 53 | |
| 54 | return 0; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 55 | } |