wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 2 | * (C) Copyright 2001-2004 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * David Mueller, ELSOFT AG, d.mueller@elsoft.ch |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* This code should work for both the S3C2400 and the S3C2410 |
| 12 | * as they seem to have the same PLL and clock machinery inside. |
| 13 | * The different address mapping is handled by the s3c24xx.h files below. |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
kevin.morfitt@fearnside-systems.co.uk | e0d8131 | 2009-11-17 18:30:34 +0900 | [diff] [blame] | 17 | #ifdef CONFIG_S3C24X0 |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 18 | |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 19 | #include <asm/io.h> |
kevin.morfitt@fearnside-systems.co.uk | e0d8131 | 2009-11-17 18:30:34 +0900 | [diff] [blame] | 20 | #include <asm/arch/s3c24x0_cpu.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 21 | |
| 22 | #define MPLL 0 |
| 23 | #define UPLL 1 |
| 24 | |
| 25 | /* ------------------------------------------------------------------------- */ |
| 26 | /* NOTE: This describes the proper use of this file. |
| 27 | * |
wdenk | 1272e23 | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 28 | * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | * |
| 30 | * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of |
| 31 | * the specified bus in HZ. |
| 32 | */ |
| 33 | /* ------------------------------------------------------------------------- */ |
| 34 | |
| 35 | static ulong get_PLLCLK(int pllreg) |
| 36 | { |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 37 | struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power(); |
| 38 | ulong r, m, p, s; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 39 | |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 40 | if (pllreg == MPLL) |
C Nauman | 383c43e | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 41 | r = readl(&clk_power->mpllcon); |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 42 | else if (pllreg == UPLL) |
C Nauman | 383c43e | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 43 | r = readl(&clk_power->upllcon); |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 44 | else |
| 45 | hang(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 46 | |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 47 | m = ((r & 0xFF000) >> 12) + 8; |
| 48 | p = ((r & 0x003F0) >> 4) + 2; |
| 49 | s = r & 0x3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 50 | |
C Nauman | 383c43e | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 51 | #if defined(CONFIG_S3C2440) |
| 52 | if (pllreg == MPLL) |
| 53 | return 2 * m * (CONFIG_SYS_CLK_FREQ / (p << s)); |
| 54 | #endif |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 55 | return (CONFIG_SYS_CLK_FREQ * m) / (p << s); |
C Nauman | 383c43e | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 56 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /* return FCLK frequency */ |
| 60 | ulong get_FCLK(void) |
| 61 | { |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 62 | return get_PLLCLK(MPLL); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* return HCLK frequency */ |
| 66 | ulong get_HCLK(void) |
| 67 | { |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 68 | struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power(); |
C Nauman | 383c43e | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 69 | #ifdef CONFIG_S3C2440 |
| 70 | switch (readl(&clk_power->clkdivn) & 0x6) { |
| 71 | default: |
| 72 | case 0: |
| 73 | return get_FCLK(); |
| 74 | case 2: |
| 75 | return get_FCLK() / 2; |
| 76 | case 4: |
| 77 | return (readl(&clk_power->camdivn) & (1 << 9)) ? |
| 78 | get_FCLK() / 8 : get_FCLK() / 4; |
| 79 | case 6: |
| 80 | return (readl(&clk_power->camdivn) & (1 << 8)) ? |
| 81 | get_FCLK() / 6 : get_FCLK() / 3; |
| 82 | } |
| 83 | #else |
| 84 | return (readl(&clk_power->clkdivn) & 2) ? get_FCLK() / 2 : get_FCLK(); |
| 85 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* return PCLK frequency */ |
| 89 | ulong get_PCLK(void) |
| 90 | { |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 91 | struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 92 | |
C Nauman | 383c43e | 2010-10-26 23:04:31 +0900 | [diff] [blame] | 93 | return (readl(&clk_power->clkdivn) & 1) ? get_HCLK() / 2 : get_HCLK(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* return UCLK frequency */ |
| 97 | ulong get_UCLK(void) |
| 98 | { |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 99 | return get_PLLCLK(UPLL); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 100 | } |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 101 | |
kevin.morfitt@fearnside-systems.co.uk | e0d8131 | 2009-11-17 18:30:34 +0900 | [diff] [blame] | 102 | #endif /* CONFIG_S3C24X0 */ |