Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | 6a3e427 | 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 | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 7 | #include <linux/delay.h> |
Masahiro Yamada | 0f4ec05 | 2017-01-21 18:05:24 +0900 | [diff] [blame] | 8 | #include <linux/errno.h> |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 9 | #include <linux/io.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 10 | #include <linux/printk.h> |
Masahiro Yamada | 107b3fb | 2016-01-09 01:51:13 +0900 | [diff] [blame] | 11 | |
| 12 | #include "../init.h" |
| 13 | #include "../sc-regs.h" |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 14 | |
| 15 | #undef DPLL_SSC_RATE_1PER |
| 16 | |
Masahiro Yamada | 6a3e427 | 2016-09-17 03:33:09 +0900 | [diff] [blame] | 17 | int uniphier_pro4_dpll_init(const struct uniphier_board_data *bd) |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 18 | { |
Masahiro Yamada | 6a3e427 | 2016-09-17 03:33:09 +0900 | [diff] [blame] | 19 | unsigned int dram_freq = bd->dram_freq; |
Masahiro Yamada | 5894ca0 | 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 | */ |
Masahiro Yamada | 739ba41 | 2019-07-10 20:07:41 +0900 | [diff] [blame] | 27 | tmp = readl(sc_base + SC_DPLLCTRL); |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 28 | tmp &= ~(0x000f0000); |
Masahiro Yamada | 323d1f9 | 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 | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 40 | |
| 41 | /* |
| 42 | * Set Moduration rate |
| 43 | * Set 0x0(1%)/0x1(2%) to SSC_RATE(DPLLCTRL.bit[15]) |
| 44 | */ |
| 45 | #if defined(DPLL_SSC_RATE_1PER) |
| 46 | tmp &= ~0x00008000; |
| 47 | #else |
| 48 | tmp |= 0x00008000; |
| 49 | #endif |
Masahiro Yamada | 739ba41 | 2019-07-10 20:07:41 +0900 | [diff] [blame] | 50 | writel(tmp, sc_base + SC_DPLLCTRL); |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 51 | |
Masahiro Yamada | 739ba41 | 2019-07-10 20:07:41 +0900 | [diff] [blame] | 52 | tmp = readl(sc_base + SC_DPLLCTRL2); |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 53 | tmp |= SC_DPLLCTRL2_NRSTDS; |
Masahiro Yamada | 739ba41 | 2019-07-10 20:07:41 +0900 | [diff] [blame] | 54 | writel(tmp, sc_base + SC_DPLLCTRL2); |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 55 | |
Masahiro Yamada | 6a3e427 | 2016-09-17 03:33:09 +0900 | [diff] [blame] | 56 | /* Wait until dpll gets stable */ |
| 57 | udelay(500); |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 58 | |
| 59 | return 0; |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 60 | } |