blob: e67f0ec2f7e86e6809fa458b4a59f6951cfde8ca [file] [log] [blame]
Lin Huangc4cbf482016-03-17 15:28:33 +08001/*
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 Huangc4cbf482016-03-17 15:28:33 +080016#include <boardid.h>
Julius Werner329031f2016-08-19 16:35:22 -070017#include <cbfs.h>
Lin Huangc4cbf482016-03-17 15:28:33 +080018#include <console/console.h>
19#include <gpio.h>
20#include <soc/sdram.h>
21#include <string.h>
22#include <types.h>
23
Julius Werner329031f2016-08-19 16:35:22 -070024static const char *sdram_configs[] = {
Lin Huang2bd52ff2017-12-01 16:32:34 +080025
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 Huang627c27b2016-06-16 10:44:30 +080043};
44
Julius Werner329031f2016-08-19 16:35:22 -070045static struct rk3399_sdram_params params;
46
Caesar Wang6c4e5742017-05-05 17:37:42 +080047enum dram_speeds {
48 dram_800MHz = 800,
49 dram_928MHz = 928,
50};
51
52static 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 Huangc4cbf482016-03-17 15:28:33 +080060const struct rk3399_sdram_params *get_sdram_config()
61{
Caesar Wang6c4e5742017-05-05 17:37:42 +080062 char config_file[64];
Shasha Zhaoc99526c2016-11-17 12:42:51 +080063 uint32_t ramcode;
Shasha Zhao6bd75ec2016-11-14 20:10:55 +080064
Shasha Zhaoc99526c2016-11-17 12:42:51 +080065 ramcode = ram_code();
Caesar Wang6c4e5742017-05-05 17:37:42 +080066 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 Turney809fa7b2018-04-12 13:36:40 -070069 (cbfs_boot_load_file(config_file, &params, sizeof(params),
70 CBFS_TYPE_STRUCT) != sizeof(params)))
Julius Werner329031f2016-08-19 16:35:22 -070071 die("Cannot load SDRAM parameter file!");
Caesar Wang6c4e5742017-05-05 17:37:42 +080072
Julius Werner329031f2016-08-19 16:35:22 -070073 return &params;
Lin Huangc4cbf482016-03-17 15:28:33 +080074}