Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 2 | /* |
3 | * Copyright 2008 Extreme Engineering Solutions, Inc. | ||||
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 4 | */ |
5 | |||||
6 | #include <common.h> | ||||
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 7 | #include <clock_legacy.h> |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 8 | #include <asm/io.h> |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 9 | |
10 | /* | ||||
11 | * Return SYSCLK input frequency - 50 MHz or 66 MHz depending on POR config | ||||
12 | */ | ||||
Tom Rini | aea2a99 | 2021-12-14 13:36:39 -0500 | [diff] [blame] | 13 | unsigned long get_board_sys_clk(void) |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 14 | { |
Peter Tyser | 281e41d | 2009-05-22 10:26:37 -0500 | [diff] [blame] | 15 | #if defined(CONFIG_MPC85xx) |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 16 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Peter Tyser | 281e41d | 2009-05-22 10:26:37 -0500 | [diff] [blame] | 17 | #elif defined(CONFIG_MPC86xx) |
18 | immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; | ||||
19 | volatile ccsr_gur_t *gur = &immap->im_gur; | ||||
20 | #endif | ||||
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 21 | |
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 22 | if (in_be32(&gur->gpporcr) & 0x10000) |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 23 | return 66666666; |
24 | else | ||||
York Sun | 4b08dd7 | 2016-11-18 11:08:43 -0800 | [diff] [blame] | 25 | #ifdef CONFIG_ARCH_P2020 |
John Schmoller | 9a0709d | 2010-10-22 00:20:34 -0500 | [diff] [blame] | 26 | return 100000000; |
27 | #else | ||||
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 28 | return 50000000; |
John Schmoller | 9a0709d | 2010-10-22 00:20:34 -0500 | [diff] [blame] | 29 | #endif |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 30 | } |
31 | |||||
Peter Tyser | 281e41d | 2009-05-22 10:26:37 -0500 | [diff] [blame] | 32 | #ifdef CONFIG_MPC85xx |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 33 | /* |
34 | * Return DDR input clock - synchronous with SYSCLK or 66 MHz | ||||
Peter Tyser | 281e41d | 2009-05-22 10:26:37 -0500 | [diff] [blame] | 35 | * Note: 86xx doesn't support asynchronous DDR clk |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 36 | */ |
Tom Rini | aea2a99 | 2021-12-14 13:36:39 -0500 | [diff] [blame] | 37 | unsigned long get_board_ddr_clk(void) |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 38 | { |
39 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); | ||||
Peter Tyser | 2b1a48d | 2009-08-07 13:16:34 -0500 | [diff] [blame] | 40 | u32 ddr_ratio = (in_be32(&gur->porpllsr) & 0x00003e00) >> 9; |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 41 | |
42 | if (ddr_ratio == 0x7) | ||||
Tom Rini | aea2a99 | 2021-12-14 13:36:39 -0500 | [diff] [blame] | 43 | return get_board_sys_clk(); |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 44 | |
York Sun | 4b08dd7 | 2016-11-18 11:08:43 -0800 | [diff] [blame] | 45 | #ifdef CONFIG_ARCH_P2020 |
John Schmoller | 9a0709d | 2010-10-22 00:20:34 -0500 | [diff] [blame] | 46 | if (in_be32(&gur->gpporcr) & 0x20000) |
47 | return 66666666; | ||||
48 | else | ||||
49 | return 100000000; | ||||
50 | #else | ||||
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 51 | return 66666666; |
John Schmoller | 9a0709d | 2010-10-22 00:20:34 -0500 | [diff] [blame] | 52 | #endif |
Peter Tyser | 1c2b329 | 2008-12-17 16:36:23 -0600 | [diff] [blame] | 53 | } |
Peter Tyser | 281e41d | 2009-05-22 10:26:37 -0500 | [diff] [blame] | 54 | #endif |