Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 16 | #include <boardid.h> |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 17 | #include <cbfs.h> |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 18 | #include <console/console.h> |
| 19 | #include <gpio.h> |
| 20 | #include <soc/sdram.h> |
| 21 | #include <string.h> |
| 22 | #include <types.h> |
| 23 | |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 24 | static const char *sdram_configs[] = { |
Lin Huang | 2bd52ff | 2017-12-01 16:32:34 +0800 | [diff] [blame] | 25 | |
| 26 | /* Samsung K4E6E304EB-EGCE */ |
| 27 | [0] = "sdram-lpddr3-generic-4GB", |
| 28 | |
| 29 | /* Hynix H9CCNNNBJTALAR */ |
| 30 | [1] = "sdram-lpddr3-generic-4GB", |
| 31 | |
| 32 | /* Samsung K4E8E324EB-EGCF */ |
| 33 | [3] = "sdram-lpddr3-generic-2GB", |
| 34 | |
| 35 | /* Micron MT52L256M32D1PF */ |
| 36 | [4] = "sdram-lpddr3-generic-2GB", |
| 37 | |
| 38 | /* Samsung K4E6E304EB-EGCE, duplicate to 0 */ |
| 39 | [5] = "sdram-lpddr3-generic-4GB", |
| 40 | |
| 41 | /* Micron MT52L512M32D2PF */ |
| 42 | [6] = "sdram-lpddr3-generic-4GB", |
Lin Huang | 627c27b | 2016-06-16 10:44:30 +0800 | [diff] [blame] | 43 | }; |
| 44 | |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 45 | static struct rk3399_sdram_params params; |
| 46 | |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 47 | enum dram_speeds { |
| 48 | dram_800MHz = 800, |
| 49 | dram_928MHz = 928, |
| 50 | }; |
| 51 | |
| 52 | static enum dram_speeds get_sdram_target_mhz(void) |
| 53 | { |
| 54 | if (IS_ENABLED(CONFIG_BOARD_GOOGLE_BOB) && board_id() < 4) |
| 55 | return dram_800MHz; |
| 56 | |
| 57 | return dram_928MHz; |
| 58 | } |
| 59 | |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 60 | const struct rk3399_sdram_params *get_sdram_config() |
| 61 | { |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 62 | char config_file[64]; |
Shasha Zhao | c99526c | 2016-11-17 12:42:51 +0800 | [diff] [blame] | 63 | uint32_t ramcode; |
Shasha Zhao | 6bd75ec | 2016-11-14 20:10:55 +0800 | [diff] [blame] | 64 | |
Shasha Zhao | c99526c | 2016-11-17 12:42:51 +0800 | [diff] [blame] | 65 | ramcode = ram_code(); |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 66 | if (ramcode >= ARRAY_SIZE(sdram_configs) || |
| 67 | !snprintf(config_file, sizeof(config_file), "%s-%d", |
| 68 | sdram_configs[ramcode], get_sdram_target_mhz()) || |
T Michael Turney | 809fa7b | 2018-04-12 13:36:40 -0700 | [diff] [blame] | 69 | (cbfs_boot_load_file(config_file, ¶ms, sizeof(params), |
| 70 | CBFS_TYPE_STRUCT) != sizeof(params))) |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 71 | die("Cannot load SDRAM parameter file!"); |
Caesar Wang | 6c4e574 | 2017-05-05 17:37:42 +0800 | [diff] [blame] | 72 | |
Julius Werner | 329031f | 2016-08-19 16:35:22 -0700 | [diff] [blame] | 73 | return ¶ms; |
Lin Huang | c4cbf48 | 2016-03-17 15:28:33 +0800 | [diff] [blame] | 74 | } |