coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
refcode_native.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <console/console.h>
5 #include <cpu/x86/tsc.h>
6 #include <device/pci.h>
7 #include <delay.h>
8 #include <soc/pci_devs.h>
9 #include <soc/lpc.h>
10 #include <soc/iosf.h>
11 #include <soc/iomap.h>
12 #include <soc/ramstage.h>
13 #include <soc/modphy_table.h>
14 
15 #define IOSF_READ(op_read, port) \
16  (IOSF_OPCODE(op_read) | IOSF_PORT(port))
17 #define IOSF_WRITE(op_write, port) \
18  (IOSF_OPCODE(op_write) | IOSF_PORT(port))
19 
20 static void program_modphy_table(struct modphy_entry *table)
21 {
22  u32 tmp;
23 
24  for (; table->port; ++table) {
25  tmp = iosf_read_port(IOSF_READ(table->op_read, table->port), table->reg);
26  iosf_write_port(IOSF_WRITE(table->op_write, table->port), table->reg,
27  (tmp & table->mask) | table->value);
28  }
29 }
30 
31 static void gpio_sc_sdcard_workaround(void)
32 {
33  setbits32((char *) IO_BASE_ADDRESS + 0x698, (1 << 0));
34  setbits32((char *) IO_BASE_ADDRESS + 0x698, (1 << 2));
35  clrbits32((char *) IO_BASE_ADDRESS + 0x698, (1 << 1));
36  clrbits32((char *) IO_BASE_ADDRESS + 0x690, (1 << 3));
37  udelay(100);
38  clrbits32((char *) IO_BASE_ADDRESS + 0x698, (1 << 0));
39  udelay(100);
40  write32((char *) IO_BASE_ADDRESS + 0x830, 0x78480);
41  udelay(40);
42  write32((char *) IO_BASE_ADDRESS + 0x830, 0x78080);
43  setbits32((char *) IO_BASE_ADDRESS + 0x698, (1 << 0));
44  udelay(100);
45  setbits32((char *) IO_BASE_ADDRESS + 0x698, (1 << 1));
46  clrbits32((char *) IO_BASE_ADDRESS + 0x698, (1 << 2));
47  clrsetbits32((char *) IO_BASE_ADDRESS + 0x690, 7, (1 << 0));
48 }
49 
50 #define BUNIT_BALIMIT0 0x0b
51 #define AUNIT_AVCCTL 0x21
52 #define AUNIT_ACFCACV 0x60
53 #define CUNIT_ACCESS_CTRL_VIOL 0x41
54 #define CUINT_SSA_REGIONAL_TRUNKGATE_CTL 0x43
55 #define TUNIT_CTL 0x03
56 #define TUNIT_MISC_CTL 0x04
57 
58 static void ssa_safe_config(void)
59 {
60  u32 tmp;
61 
63  iosf_bunit_write(BUNIT_BALIMIT0, (tmp & 0xC0D0D0D0) | 0x1F2F2F2F);
64 
66  iosf_aunit_write(AUNIT_AVCCTL, tmp | 0x80000100);
67 
69  iosf_aunit_write(AUNIT_ACFCACV, tmp & 0x7FFFFFFF);
70 
72  iosf_cunit_write(CUNIT_ACCESS_CTRL_VIOL, tmp & 0x7FFFFFFF);
73 
75 
77  iosf_cpu_bus_write(TUNIT_CTL, tmp | 0x110430);
78 
80  iosf_cpu_bus_write(TUNIT_MISC_CTL, tmp | 0x40010);
81 }
82 
83 #define R_PCH_PMC_MTPMC1 0xb0
84 
85 /*
86  * Replacement for refcode.elf
87  */
89 {
90  u32 tmp;
91  size_t pollcnt;
92 
93  printk(BIOS_DEBUG, "ModPHY init entry\n");
94 
96  printk(BIOS_DEBUG, "SOC A0/A1 ModPhy Table programming\n");
98  } else {
99  printk(BIOS_DEBUG, "SOC B0 and later ModPhy Table programming\n");
101  }
102 
104 
105  for (pollcnt = 0; pollcnt < 10; ++pollcnt) {
106  tmp = read32((char *) PMC_BASE_ADDRESS + R_PCH_PMC_MTPMC1);
107  printk(BIOS_DEBUG, "Polling bit3 of R_PCH_PMC_MTPMC1 = %x\n", tmp);
108  if (!(tmp & 8))
109  break;
110  }
111 
113  ssa_safe_config();
114 
115  printk(BIOS_DEBUG, "ModPHY init done\n");
116 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
void iosf_aunit_write(int reg, uint32_t val)
Definition: iosf.c:156
void iosf_write_port(uint32_t cr, int reg, uint32_t val)
Definition: iosf.c:26
uint32_t iosf_read_port(uint32_t cr, int reg)
Definition: iosf.c:18
uint32_t iosf_cpu_bus_read(int reg)
Definition: iosf.c:161
void iosf_cpu_bus_write(int reg, uint32_t val)
Definition: iosf.c:166
void iosf_cunit_write(int reg, uint32_t val)
Definition: iosf.c:76
uint32_t iosf_bunit_read(int reg)
Definition: iosf.c:39
uint32_t iosf_aunit_read(int reg)
Definition: iosf.c:151
void iosf_bunit_write(int reg, uint32_t val)
Definition: iosf.c:44
uint32_t iosf_cunit_read(int reg)
Definition: iosf.c:71
#define printk(level,...)
Definition: stdlib.h:16
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
#define setbits32(addr, set)
Definition: mmio.h:21
#define clrsetbits32(addr, clear, set)
Definition: mmio.h:16
#define clrbits32(addr, clear)
Definition: mmio.h:26
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
#define IO_BASE_ADDRESS
Definition: iomap.h:19
#define PMC_BASE_ADDRESS
Definition: iomap.h:15
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
struct modphy_entry revb0_modphy_table[]
Definition: modphy_table.c:228
struct modphy_entry reva0_modphy_table[]
Definition: modphy_table.c:5
#define LPC_DEV
Definition: romstage.c:15
#define R_PCH_PMC_MTPMC1
#define AUNIT_ACFCACV
#define IOSF_WRITE(op_write, port)
#define TUNIT_CTL
#define TUNIT_MISC_CTL
#define CUINT_SSA_REGIONAL_TRUNKGATE_CTL
#define IOSF_READ(op_read, port)
#define AUNIT_AVCCTL
static void gpio_sc_sdcard_workaround(void)
static void program_modphy_table(struct modphy_entry *table)
static void ssa_safe_config(void)
#define CUNIT_ACCESS_CTRL_VIOL
#define BUNIT_BALIMIT0
void baytrail_run_reference_code(void)
#define LPC_FUNC
Definition: pci_devs.h:122
#define RID_B_STEPPING_START
Definition: lpc.h:20
#define REVID
Definition: lpc.h:7
uint32_t u32
Definition: stdint.h:51
Definition: modphy_table.h:8
u32 mask
Definition: modphy_table.h:11
u8 op_write
Definition: modphy_table.h:14
u8 op_read
Definition: modphy_table.h:13
u32 reg
Definition: modphy_table.h:10
u32 value
Definition: modphy_table.h:12
u8 port
Definition: modphy_table.h:9
void udelay(uint32_t us)
Definition: udelay.c:15