blob: 552d27d1f452d5f6eea8ed40d583eea65f741d22 [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Aaron Durbinc626b742013-11-12 16:40:33 -06003
4
Duncan Laurie430bf0d2013-12-10 14:37:42 -08005#include <cbmem.h>
Aaron Durbinc626b742013-11-12 16:40:33 -06006#include <console/console.h>
Duncan Laurie430bf0d2013-12-10 14:37:42 -08007#include <device/device.h>
8#include <device/pci.h>
Aaron Durbinc626b742013-11-12 16:40:33 -06009#include <reg_script.h>
10
Julius Werner18ea2d32014-10-07 16:42:17 -070011#include <soc/iosf.h>
12#include <soc/nvs.h>
13#include <soc/ramstage.h>
Aaron Durbinc626b742013-11-12 16:40:33 -060014
15static const struct reg_script scc_start_dll[] = {
16 /* Configure master DLL. */
17 REG_IOSF_WRITE(IOSF_PORT_SCORE, 0x4964, 0x00078000),
18 /* Configure Swing,FSM for Master DLL */
19 REG_IOSF_WRITE(IOSF_PORT_SCORE, 0x4970, 0x00000133),
20 /* Run+Local Reset on Master DLL */
21 REG_IOSF_WRITE(IOSF_PORT_SCORE, 0x4970, 0x00001933),
22 REG_SCRIPT_END,
23};
24
25static const struct reg_script scc_after_dll[] = {
26 /* Configure Write Path */
27 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x4954, ~0x7fff, 0x35ad),
28 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x4958, ~0x7fff, 0x35ad),
29 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x495c, ~0x7fff, 0x35ad),
30 /* Configure Read Path */
31 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x43e4, ~0x7fff, 0x35ad),
32 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x4324, ~0x7fff, 0x35ad),
33 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x42b4, ~0x7fff, 0x35ad),
34 /* eMMC 4.5 TX and RX DLL */
35 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x49a4, ~0x1f001f, 0xa000d),
36 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x49a8, ~0x1f001f, 0xd000d),
37 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x49ac, ~0x1f001f, 0xd000d),
38 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x49b0, ~0x1f001f, 0xd000d),
39 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x49b4, ~0x1f001f, 0xd000d),
40 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x49b8, ~0x1, 0x0),
41 /* cfio_regs_mmc1_ELECTRICAL.nslew/pslew */
42 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x48c0, ~0x3c, 0x0),
43 REG_IOSF_RMW(IOSF_PORT_SCORE, 0x48c4, ~0x3c, 0x0),
44 /*
45 * iosf2ocp_private.GENREGRW1.cr_clock_enable_clk_ocp = 01
46 * iosf2ocp_private.GENREGRW1.cr_clock_enable_clk_xin = 01
47 */
48 REG_IOSF_RMW(IOSF_PORT_SCC, 0x600, ~0xf, 0x5),
49 /* Enable IOSF Snoop */
50 REG_IOSF_OR(IOSF_PORT_SCC, 0x00, (1 << 7)),
51 /* SDIO 3V Support. */
52 REG_IOSF_RMW(IOSF_PORT_SCC, 0x600, ~0x30, 0x30),
53 REG_SCRIPT_END,
54};
55
56void baytrail_init_scc(void)
57{
58 uint32_t dll_values;
59
60 printk(BIOS_DEBUG, "Initializing sideband SCC registers.\n");
61
62 /* Common Sideband Initialization for SCC */
63 reg_script_run(scc_start_dll);
64
65 /* Override Slave Path - populate DLL settings. */
66 dll_values = iosf_score_read(0x496c) & 0x7ffff;
67 dll_values |= iosf_score_read(0x4950) & ~0xfffff;
68 iosf_score_write(0x4950, dll_values | (1 << 19));
69
70 reg_script_run(scc_after_dll);
71}
Duncan Laurie430bf0d2013-12-10 14:37:42 -080072
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020073void scc_enable_acpi_mode(struct device *dev, int iosf_reg, int nvs_index)
Duncan Laurie430bf0d2013-12-10 14:37:42 -080074{
75 struct reg_script ops[] = {
Duncan Laurie430bf0d2013-12-10 14:37:42 -080076 /* Disable PCI interrupt, enable Memory and Bus Master */
Elyes HAOUASd2bbc682020-04-29 10:12:33 +020077 REG_PCI_OR16(PCI_COMMAND,
Duncan Laurie430bf0d2013-12-10 14:37:42 -080078 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | (1<<10)),
79 /* Enable ACPI mode */
80 REG_IOSF_OR(IOSF_PORT_SCC, iosf_reg,
81 SCC_CTL_PCI_CFG_DIS | SCC_CTL_ACPI_INT_EN),
82 REG_SCRIPT_END
83 };
84 struct resource *bar;
85 global_nvs_t *gnvs;
86
87 /* Find ACPI NVS to update BARs */
88 gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS);
89 if (!gnvs) {
90 printk(BIOS_ERR, "Unable to locate Global NVS\n");
91 return;
92 }
93
94 /* Save BAR0 and BAR1 to ACPI NVS */
95 bar = find_resource(dev, PCI_BASE_ADDRESS_0);
96 if (bar)
97 gnvs->dev.scc_bar0[nvs_index] = (u32)bar->base;
98
99 bar = find_resource(dev, PCI_BASE_ADDRESS_1);
100 if (bar)
101 gnvs->dev.scc_bar1[nvs_index] = (u32)bar->base;
102
103 /* Device is enabled in ACPI mode */
104 gnvs->dev.scc_en[nvs_index] = 1;
105
106 /* Put device in ACPI mode */
Aaron Durbin616f3942013-12-10 17:12:44 -0800107 reg_script_run_on_dev(dev, ops);
Duncan Laurie430bf0d2013-12-10 14:37:42 -0800108}