blob: beeb96dc8db36090a39722020d7843aecd96fb78 [file] [log] [blame]
Tobias Diedrichcee930a2017-02-12 14:09:06 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2017 Tobias Diedrich <ranma+coreboot@tdiedrich.de>
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
16#include <stdint.h>
17#include <string.h>
18#include <cbfs.h>
Tobias Diedrichcee930a2017-02-12 14:09:06 +010019#include <arch/byteorder.h>
20#include <arch/io.h>
21#include <device/pci_def.h>
Tobias Diedrichcee930a2017-02-12 14:09:06 +010022#include <console/console.h>
Elyes HAOUAS4ad14462018-06-16 18:29:33 +020023#include <northbridge/intel/sandybridge/sandybridge.h>
24#include <northbridge/intel/sandybridge/raminit_native.h>
25#include <southbridge/intel/bd82x6x/pch.h>
Tobias Diedrichcee930a2017-02-12 14:09:06 +010026#include <southbridge/intel/common/gpio.h>
Tobias Diedrichcee930a2017-02-12 14:09:06 +010027#include "ec.h"
28
29#define SPD_LEN 256
30
31void pch_enable_lpc(void)
32{
Peter Lemenkov9b7ae2f2018-10-09 13:09:07 +020033 pci_write_config16(PCH_LPC_DEV, LPC_EN, MC_LPC_EN | KBC_LPC_EN);
34 pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, 0xc0701);
35 pci_write_config32(PCH_LPC_DEV, LPC_GEN3_DEC, 0xc0069);
36 pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, 0xc06a1);
37 pci_write_config32(PCH_LPC_DEV, ETR3, 0x10000);
Tobias Diedrichcee930a2017-02-12 14:09:06 +010038
39 /* Memory map KB9012 EC registers */
40 pci_write_config32(
Peter Lemenkov9b7ae2f2018-10-09 13:09:07 +020041 PCH_LPC_DEV, LGMR,
Tobias Diedrichcee930a2017-02-12 14:09:06 +010042 CONFIG_EC_BASE_ADDRESS | 1);
Peter Lemenkov9b7ae2f2018-10-09 13:09:07 +020043 pci_write_config16(PCH_LPC_DEV, BIOS_DEC_EN1, 0xffc0);
Tobias Diedrichcee930a2017-02-12 14:09:06 +010044
Tobias Diedrichcee930a2017-02-12 14:09:06 +010045 /* Enable external USB port power. */
Martin Roth5ef5c002017-03-24 11:08:32 -060046 if (IS_ENABLED(CONFIG_USBDEBUG))
47 ec_mm_set_bit(0x3b, 4);
Tobias Diedrichcee930a2017-02-12 14:09:06 +010048}
49
Nico Huberff4025c2018-01-14 12:34:43 +010050void mainboard_rcba_config(void)
Tobias Diedrichcee930a2017-02-12 14:09:06 +010051{
52 /* Disable devices. */
Peter Lemenkov9b7ae2f2018-10-09 13:09:07 +020053 RCBA32(BUC) = 0x00000020;
Tobias Diedrichcee930a2017-02-12 14:09:06 +010054}
55const struct southbridge_usb_port mainboard_usb_ports[] = {
56 { 1, 1, 0 },
57 { 1, 0, 0 },
58 { 1, 1, 1 },
59 { 1, 0, 1 },
60 { 1, 1, 2 },
61 { 1, 0, 2 },
62 { 0, 0, 3 },
63 { 0, 1, 3 },
64 { 1, 0, 4 },
65 { 1, 1, 4 },
66 { 1, 1, 5 },
67 { 1, 1, 5 },
68 { 1, 1, 6 },
69 { 1, 1, 6 },
70};
71
72void mainboard_early_init(int s3resume)
73{
74}
75
76void mainboard_config_superio(void)
77{
78}
79
80static const char *mainboard_spd_names[9] = {
81 "ELPIDA 4GB",
82 "SAMSUNG 4GB",
83 "HYNIX 4GB",
84 "ELPIDA 8GB",
85 "SAMSUNG 8GB",
86 "HYNIX 8GB",
87 "ELPIDA 2GB",
88 "SAMSUNG 2GB",
89 "HYNIX 2GB",
90};
91
92void mainboard_get_spd(spd_raw_data *spd, bool id_only)
93{
94 void *spd_file;
95 size_t spd_file_len = 0;
96 const int spd_gpios[] = {71, 70, 16, 48, -1};
97
98 u32 spd_index = get_gpios(spd_gpios);
99 if (spd_index >= ARRAY_SIZE(mainboard_spd_names)) {
100 /* Fallback to pessimistic 2GB image (ELPIDA 2GB) */
101 spd_index = 6;
102 }
103
104 printk(BIOS_INFO, "SPD index %d (%s)\n",
105 spd_index, mainboard_spd_names[spd_index]);
106
107 /* C0S0 is a soldered RAM with no real SPD. Use stored SPD. */
108 spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
109 &spd_file_len);
110
111 if (!spd_file || spd_file_len < SPD_LEN * spd_index + SPD_LEN)
112 die("SPD data not found.");
113
114 memcpy(spd, spd_file + SPD_LEN * spd_index, SPD_LEN);
115}