blob: f02f07e3a869f23bd6c8bb90a05f80cfa93f86d6 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google, Inc.
Lee Leahy32471722015-04-20 15:20:28 -07005 * Copyright (C) 2015 Intel Corp.
Lee Leahy77ff0b12015-05-05 15:07:29 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
Marshall Dawsone8c527e2017-01-13 14:23:49 -070012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070015 */
16
Lee Leahy32471722015-04-20 15:20:28 -070017#ifndef _SOC_IOSF_H_
18#define _SOC_IOSF_H_
Lee Leahy77ff0b12015-05-05 15:07:29 -070019
20#include <stdint.h>
Lee Leahy32471722015-04-20 15:20:28 -070021#if ENV_RAMSTAGE
22#include <device/device.h>
23#include <reg_script.h>
24#endif /* ENV_RAMSTAGE */
Lee Leahy77ff0b12015-05-05 15:07:29 -070025#include <soc/pci_devs.h>
26
27/*
Lee Leahy32471722015-04-20 15:20:28 -070028 * The SoC has a message network called IOSF Sideband. The access
Lee Leahy77ff0b12015-05-05 15:07:29 -070029 * routines are through 3 registers in PCI config space of 00:00.0:
30 * MCR - control register
31 * MDR - data register
32 * MCRX - control register extension
Lee Leahy32471722015-04-20 15:20:28 -070033 * The extension register is only used for addresses that don't fit
34 * into the 8 bit register address.
Lee Leahy77ff0b12015-05-05 15:07:29 -070035 */
36
37#ifndef PCI_DEV
38#define PCI_DEV(SEGBUS, DEV, FN) ( \
Lee Leahy32471722015-04-20 15:20:28 -070039 (((SEGBUS) & 0xFFF) << 20) | \
40 (((DEV) & 0x1F) << 15) | \
41 (((FN) & 0x07) << 12))
Lee Leahy77ff0b12015-05-05 15:07:29 -070042#endif
Lee Leahy32471722015-04-20 15:20:28 -070043#define IOSF_PCI_DEV PCI_DEV(0, SOC_DEV, SOC_FUNC)
Lee Leahy77ff0b12015-05-05 15:07:29 -070044
45#define MCR_REG 0xd0
46#define IOSF_OPCODE(x) ((x) << 24)
47#define IOSF_PORT(x) ((0xff & (x)) << 16)
48#define IOSF_REG(x) ((0xff & (x)) << 8)
49#define IOSF_REG_UPPER(x) (((~0xff) & (x)))
50#define IOSF_BYTE_EN_0 0x10
51#define IOSF_BYTE_EN_1 0x20
52#define IOSF_BYTE_EN_2 0x40
53#define IOSF_BYTE_EN_3 0x80
54#define IOSF_BYTE_EN \
55 (IOSF_BYTE_EN_0 | IOSF_BYTE_EN_1 | IOSF_BYTE_EN_2 | IOSF_BYTE_EN_3)
56#define MDR_REG 0xd4
57#define MCRX_REG 0xd8
58
Lee Leahy77ff0b12015-05-05 15:07:29 -070059uint32_t iosf_bunit_read(int reg);
60void iosf_bunit_write(int reg, uint32_t val);
Lee Leahy77ff0b12015-05-05 15:07:29 -070061uint32_t iosf_punit_read(int reg);
62void iosf_punit_write(int reg, uint32_t val);
Lee Leahy77ff0b12015-05-05 15:07:29 -070063uint32_t iosf_score_read(int reg);
64void iosf_score_write(int reg, uint32_t val);
Lee Leahy32471722015-04-20 15:20:28 -070065uint32_t iosf_lpss_read(int reg);
66void iosf_lpss_write(int reg, uint32_t val);
67uint32_t iosf_port58_read(int reg);
68void iosf_port58_write(int reg, uint32_t val);
Lee Leahy77ff0b12015-05-05 15:07:29 -070069uint32_t iosf_scc_read(int reg);
70void iosf_scc_write(int reg, uint32_t val);
shkimcc728f02015-09-22 17:53:58 +090071uint32_t iosf_usbphy_read(int reg);
72void iosf_usbphy_write(int reg, uint32_t val);
Lee Leahy32471722015-04-20 15:20:28 -070073
74#if ENV_RAMSTAGE
75uint64_t reg_script_read_iosf(struct reg_script_context *ctx);
76void reg_script_write_iosf(struct reg_script_context *ctx);
77#endif /* ENV_RAMSTAGE */
Lee Leahy77ff0b12015-05-05 15:07:29 -070078
79/* IOSF ports. */
80#define IOSF_PORT_AUNIT 0x00 /* IO Arbiter unit */
Lee Leahy77ff0b12015-05-05 15:07:29 -070081#define IOSF_PORT_CPU_BUS 0x02 /* CPU Bus Interface Controller */
82#define IOSF_PORT_BUNIT 0x03 /* System Memory Arbiter/Bunit */
83#define IOSF_PORT_PMC 0x04 /* Power Management Controller */
Lee Leahy77ff0b12015-05-05 15:07:29 -070084#define IOSF_PORT_SEC 0x44 /* SEC */
85#define IOSF_PORT_0x45 0x45
86#define IOSF_PORT_0x46 0x46
87#define IOSF_PORT_0x47 0x47
88#define IOSF_PORT_SCORE 0x48 /* SCORE */
89#define IOSF_PORT_0x55 0x55
90#define IOSF_PORT_0x58 0x58
91#define IOSF_PORT_0x59 0x59
92#define IOSF_PORT_0x5a 0x5a
93#define IOSF_PORT_USHPHY 0x61 /* USB XHCI PHY */
94#define IOSF_PORT_SCC 0x63 /* Storage Control Cluster */
shkimcc728f02015-09-22 17:53:58 +090095#define IOSF_PORT_USBPHY 0x43 /* USB PHY */
Lee Leahy77ff0b12015-05-05 15:07:29 -070096#define IOSF_PORT_LPSS 0xa0 /* LPSS - Low Power Subsystem */
97#define IOSF_PORT_0xa2 0xa2
Lee Leahy77ff0b12015-05-05 15:07:29 -070098#define IOSF_PORT_SSUS 0xa8 /* SUS */
99#define IOSF_PORT_CCU 0xa9 /* Clock control unit. */
100
101/* Read and write opcodes differ per port. */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700102#define IOSF_OP_READ_BUNIT 0x10
103#define IOSF_OP_WRITE_BUNIT (IOSF_OP_READ_BUNIT | 1)
104#define IOSF_OP_READ_PMC 0x06
105#define IOSF_OP_WRITE_PMC (IOSF_OP_READ_PMC | 1)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700106#define IOSF_OP_READ_SCORE 0x06
107#define IOSF_OP_WRITE_SCORE (IOSF_OP_READ_SCORE | 1)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700108#define IOSF_OP_READ_LPSS 0x06
109#define IOSF_OP_WRITE_LPSS (IOSF_OP_READ_LPSS | 1)
Lee Leahy32471722015-04-20 15:20:28 -0700110#define IOSF_OP_READ_0x58 0x06
111#define IOSF_OP_WRITE_0x58 (IOSF_OP_READ_0x58 | 1)
112#define IOSF_OP_READ_SCC 0x06
113#define IOSF_OP_WRITE_SCC (IOSF_OP_READ_SCC | 1)
shkimcc728f02015-09-22 17:53:58 +0900114#define IOSF_OP_READ_USBPHY 0x06
115#define IOSF_OP_WRITE_USBPHY (IOSF_OP_READ_USBPHY | 1)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700116
117/*
118 * BUNIT Registers.
119 */
120
Lee Leahy77ff0b12015-05-05 15:07:29 -0700121/* BMBOUND has a 128MiB granularity. Highest address is 0xf8000000. */
122#define BUNIT_BMBOUND 0x25
Lee Leahy32471722015-04-20 15:20:28 -0700123/*
Elyes HAOUAS038e7242016-07-29 18:31:16 +0200124 * BMBOUND_HI describes the available RAM above 4GiB. It has a
Lee Leahy77ff0b12015-05-05 15:07:29 -0700125 * 256MiB granularity. Physical address bits 35:28 are compared with 31:24
126 * bits in the BMBOUND_HI register. Also note that since BMBOUND has 128MiB
127 * granularity care needs to be taken with the e820 map to account for a hole
Elyes HAOUAS038e7242016-07-29 18:31:16 +0200128 * in the RAM.
Lee Leahy32471722015-04-20 15:20:28 -0700129 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700130#define BUNIT_BMBOUND_HI 0x26
131#define BUNIT_MMCONF_REG 0x27
Lee Leahy32471722015-04-20 15:20:28 -0700132#define BUNIT_BMISC 0x28
Lee Leahy77ff0b12015-05-05 15:07:29 -0700133/* The SMMRR registers define the SMM region in MiB granularity. */
Chiranjeevi Rapolufd016a42015-08-11 14:09:46 -0700134#define BUNIT_SMRWAC 0x2d
Lee Leahy77ff0b12015-05-05 15:07:29 -0700135#define BUNIT_SMRRL 0x2e
136#define BUNIT_SMRRH 0x2f
Lee Leahy77ff0b12015-05-05 15:07:29 -0700137
Chiranjeevi Rapolufd016a42015-08-11 14:09:46 -0700138/* SA ID bits. */
139#define SAI_IA_UNTRUSTED (1 << 0)
140#define SAI_IA_SMM (1 << 2)
141#define SAI_IA_BOOT (1 << 4)
142
Lee Leahy77ff0b12015-05-05 15:07:29 -0700143/*
144 * LPSS Registers
145 */
146#define LPSS_SIO_DMA1_CTL 0x280
147#define LPSS_I2C1_CTL 0x288
148#define LPSS_I2C2_CTL 0x290
149#define LPSS_I2C3_CTL 0x298
150#define LPSS_I2C4_CTL 0x2a0
151#define LPSS_I2C5_CTL 0x2a8
152#define LPSS_I2C6_CTL 0x2b0
153#define LPSS_I2C7_CTL 0x2b8
154#define LPSS_SIO_DMA2_CTL 0x240
155#define LPSS_PWM1_CTL 0x248
156#define LPSS_PWM2_CTL 0x250
157#define LPSS_HSUART1_CTL 0x258
158#define LPSS_HSUART2_CTL 0x260
159#define LPSS_SPI_CTL 0x268
160# define LPSS_CTL_ACPI_INT_EN (1 << 21)
161# define LPSS_CTL_PCI_CFG_DIS (1 << 20)
162# define LPSS_CTL_SNOOP (1 << 18)
163# define LPSS_CTL_NOSNOOP (1 << 19)
164# define LPSS_CTL_PM_CAP_PRSNT (1 << 1)
165
166/*
167 * SCC Registers
168 */
169#define SCC_SD_CTL 0x504
170#define SCC_SDIO_CTL 0x508
Lee Leahy32471722015-04-20 15:20:28 -0700171#define SCC_MMC_CTL 0x500
Lee Leahy77ff0b12015-05-05 15:07:29 -0700172# define SCC_CTL_PCI_CFG_DIS (1 << 0)
173# define SCC_CTL_ACPI_INT_EN (1 << 1)
174
175/*
Lee Leahy77ff0b12015-05-05 15:07:29 -0700176 * LPE Registers
177 */
178#define LPE_PCICFGCTR1 0x0500
179# define LPE_PCICFGCTR1_PCI_CFG_DIS (1 << 0)
180# define LPE_PCICFGCTR1_ACPI_INT_EN (1 << 1)
181
Lee Leahy32471722015-04-20 15:20:28 -0700182/*
shkimcc728f02015-09-22 17:53:58 +0900183 * USBPHY Registers
184 */
185#define USBPHY_COMPBG 0x7f04
186
187/*
Lee Leahy32471722015-04-20 15:20:28 -0700188 * IO Sideband Function
189 */
190
191#if ENV_RAMSTAGE
192#define REG_SCRIPT_IOSF(cmd_, unit_, reg_, mask_, value_, timeout_) \
193 _REG_SCRIPT_ENCODE_RAW(REG_SCRIPT_COMMAND_##cmd_, \
194 REG_SCRIPT_TYPE_IOSF, \
195 REG_SCRIPT_SIZE_32, \
196 reg_, mask_, value_, timeout_, unit_)
197#define REG_IOSF_READ(unit_, reg_) \
198 REG_SCRIPT_IOSF(READ, unit_, reg_, 0, 0, 0)
199#define REG_IOSF_WRITE(unit_, reg_, value_) \
200 REG_SCRIPT_IOSF(WRITE, unit_, reg_, 0, value_, 0)
201#define REG_IOSF_RMW(unit_, reg_, mask_, value_) \
202 REG_SCRIPT_IOSF(RMW, unit_, reg_, mask_, value_, 0)
203#define REG_IOSF_OR(unit_, reg_, value_) \
204 REG_IOSF_RMW(unit_, reg_, 0xffffffff, value_)
205#define REG_IOSF_POLL(unit_, reg_, mask_, value_, timeout_) \
206 REG_SCRIPT_IOSF(POLL, unit_, reg_, mask_, value_, timeout_)
207#endif /* ENV_RAMSTAGE */
208
209#endif /* _SOC_IOSF_H_ */