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