Angel Pons | 16c851f | 2020-04-05 13:21:38 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 2 | |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 3 | #include <boardid.h> |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 4 | #include <cbfs.h> |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <gpio.h> |
| 7 | #include <soc/sdram.h> |
Elyes Haouas | bdd03c2 | 2024-05-27 11:20:07 +0200 | [diff] [blame] | 8 | #include <stdio.h> |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 9 | #include <types.h> |
| 10 | |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 11 | static const char *sdram_configs[] = { |
Lin Huang | 2bd52ff | 2017-12-01 16:32:34 +0800 | [diff] [blame] | 12 | /* Samsung K4E6E304EB-EGCE */ |
| 13 | [0] = "sdram-lpddr3-generic-4GB", |
| 14 | |
| 15 | /* Hynix H9CCNNNBJTALAR */ |
| 16 | [1] = "sdram-lpddr3-generic-4GB", |
| 17 | |
| 18 | /* Samsung K4E8E324EB-EGCF */ |
| 19 | [3] = "sdram-lpddr3-generic-2GB", |
| 20 | |
| 21 | /* Micron MT52L256M32D1PF */ |
| 22 | [4] = "sdram-lpddr3-generic-2GB", |
| 23 | |
| 24 | /* Samsung K4E6E304EB-EGCE, duplicate to 0 */ |
| 25 | [5] = "sdram-lpddr3-generic-4GB", |
| 26 | |
| 27 | /* Micron MT52L512M32D2PF */ |
| 28 | [6] = "sdram-lpddr3-generic-4GB", |
Lin Huang | 627c27b | 2016-06-16 10:44:30 +0800 | [diff] [blame] | 29 | }; |
| 30 | |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 31 | static struct rk3399_sdram_params params; |
| 32 | |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 33 | enum dram_speeds { |
| 34 | dram_800MHz = 800, |
| 35 | dram_928MHz = 928, |
| 36 | }; |
| 37 | |
| 38 | static enum dram_speeds get_sdram_target_mhz(void) |
| 39 | { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 40 | if (CONFIG(BOARD_GOOGLE_BOB) && board_id() < 4) |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 41 | return dram_800MHz; |
| 42 | |
| 43 | return dram_928MHz; |
| 44 | } |
| 45 | |
Arthur Heymans | 71e4078 | 2022-11-17 12:47:09 +0100 | [diff] [blame] | 46 | const struct rk3399_sdram_params *get_sdram_config(void) |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 47 | { |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 48 | char config_file[64]; |
Shasha Zhao | c99526c | 2016-11-17 12:42:51 +0800 | [diff] [blame] | 49 | uint32_t ramcode; |
Shasha Zhao | 6bd75ec | 2016-11-14 20:10:55 +0800 | [diff] [blame] | 50 | |
Shasha Zhao | c99526c | 2016-11-17 12:42:51 +0800 | [diff] [blame] | 51 | ramcode = ram_code(); |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 52 | if (ramcode >= ARRAY_SIZE(sdram_configs) || |
| 53 | !snprintf(config_file, sizeof(config_file), "%s-%d", |
| 54 | sdram_configs[ramcode], get_sdram_target_mhz()) || |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 55 | (cbfs_load(config_file, ¶ms, sizeof(params)) != sizeof(params))) |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 56 | die("Cannot load SDRAM parameter file!"); |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 57 | |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 58 | return ¶ms; |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 59 | } |