blob: 11c44d038736a5220b9dd9712e8e6c019c8eab7c [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy77ff0b12015-05-05 15:07:29 -07002
Kyösti Mälkkie459a892019-03-04 07:22:56 +02003#include <stdint.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Lee Leahy32471722015-04-20 15:20:28 -07005#include <console/console.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07006#include <soc/iosf.h>
7
Kyösti Mälkkie459a892019-03-04 07:22:56 +02008static inline void write_iosf_reg(int reg, uint32_t value)
9{
10 pci_s_write_config32(IOSF_PCI_DEV, reg, value);
11}
Lee Leahy77ff0b12015-05-05 15:07:29 -070012
Lee Leahy77ff0b12015-05-05 15:07:29 -070013static inline uint32_t read_iosf_reg(int reg)
14{
Kyösti Mälkkie459a892019-03-04 07:22:56 +020015 return pci_s_read_config32(IOSF_PCI_DEV, reg);
Lee Leahy77ff0b12015-05-05 15:07:29 -070016}
Lee Leahy77ff0b12015-05-05 15:07:29 -070017
18/* Common sequences for all the port accesses. */
19static uint32_t iosf_read_port(uint32_t cr, int reg)
20{
21 cr |= IOSF_REG(reg) | IOSF_BYTE_EN;
22 write_iosf_reg(MCRX_REG, IOSF_REG_UPPER(reg));
23 write_iosf_reg(MCR_REG, cr);
24 return read_iosf_reg(MDR_REG);
25}
26
27static void iosf_write_port(uint32_t cr, int reg, uint32_t val)
28{
29 cr |= IOSF_REG(reg) | IOSF_BYTE_EN;
30 write_iosf_reg(MDR_REG, val);
31 write_iosf_reg(MCRX_REG, IOSF_REG_UPPER(reg));
32 write_iosf_reg(MCR_REG, cr);
33}
34
35#define IOSF_READ(port) \
Lee Leahy32471722015-04-20 15:20:28 -070036 (IOSF_OPCODE(IOSF_OP_READ_##port) | IOSF_PORT(IOSF_PORT_##port))
Lee Leahy77ff0b12015-05-05 15:07:29 -070037#define IOSF_WRITE(port) \
Lee Leahy32471722015-04-20 15:20:28 -070038 (IOSF_OPCODE(IOSF_OP_WRITE_##port) | IOSF_PORT(IOSF_PORT_##port))
Lee Leahy77ff0b12015-05-05 15:07:29 -070039
40uint32_t iosf_bunit_read(int reg)
41{
42 return iosf_read_port(IOSF_READ(BUNIT), reg);
43}
44
45void iosf_bunit_write(int reg, uint32_t val)
46{
47 iosf_write_port(IOSF_WRITE(BUNIT), reg, val);
48}
49
Lee Leahy77ff0b12015-05-05 15:07:29 -070050uint32_t iosf_punit_read(int reg)
51{
52 return iosf_read_port(IOSF_READ(PMC), reg);
53}
54
55void iosf_punit_write(int reg, uint32_t val)
56{
57 iosf_write_port(IOSF_WRITE(PMC), reg, val);
58}
59
Lee Leahy32471722015-04-20 15:20:28 -070060uint32_t iosf_score_read(int reg)
Lee Leahy77ff0b12015-05-05 15:07:29 -070061{
Lee Leahy32471722015-04-20 15:20:28 -070062 return iosf_read_port(IOSF_READ(SCORE), reg);
Lee Leahy77ff0b12015-05-05 15:07:29 -070063}
64
Lee Leahy32471722015-04-20 15:20:28 -070065void iosf_score_write(int reg, uint32_t val)
Lee Leahy77ff0b12015-05-05 15:07:29 -070066{
Lee Leahy32471722015-04-20 15:20:28 -070067 iosf_write_port(IOSF_WRITE(SCORE), reg, val);
Lee Leahy77ff0b12015-05-05 15:07:29 -070068}
69
70uint32_t iosf_lpss_read(int reg)
71{
72 return iosf_read_port(IOSF_READ(LPSS), reg);
73}
74
75void iosf_lpss_write(int reg, uint32_t val)
76{
Lee Leahy32471722015-04-20 15:20:28 -070077 iosf_write_port(IOSF_WRITE(LPSS), reg, val);
Lee Leahy77ff0b12015-05-05 15:07:29 -070078}
79
Lee Leahy32471722015-04-20 15:20:28 -070080uint32_t iosf_port58_read(int reg)
Lee Leahy77ff0b12015-05-05 15:07:29 -070081{
Lee Leahy32471722015-04-20 15:20:28 -070082 return iosf_read_port(IOSF_READ(0x58), reg);
Lee Leahy77ff0b12015-05-05 15:07:29 -070083}
84
Lee Leahy32471722015-04-20 15:20:28 -070085void iosf_port58_write(int reg, uint32_t val)
Lee Leahy77ff0b12015-05-05 15:07:29 -070086{
Lee Leahy32471722015-04-20 15:20:28 -070087 iosf_write_port(IOSF_WRITE(0x58), reg, val);
Lee Leahy77ff0b12015-05-05 15:07:29 -070088}
89
90uint32_t iosf_scc_read(int reg)
91{
92 return iosf_read_port(IOSF_READ(SCC), reg);
93}
94
95void iosf_scc_write(int reg, uint32_t val)
96{
Angel Ponsa81c8ee2020-07-07 17:46:49 +020097 iosf_write_port(IOSF_WRITE(SCC), reg, val);
Lee Leahy77ff0b12015-05-05 15:07:29 -070098}
99
shkimcc728f02015-09-22 17:53:58 +0900100uint32_t iosf_usbphy_read(int reg)
101{
102 return iosf_read_port(IOSF_READ(USBPHY), reg);
103}
104
105void iosf_usbphy_write(int reg, uint32_t val)
106{
Angel Ponsa81c8ee2020-07-07 17:46:49 +0200107 iosf_write_port(IOSF_WRITE(USBPHY), reg, val);
shkimcc728f02015-09-22 17:53:58 +0900108}
Lee Leahy32471722015-04-20 15:20:28 -0700109
110#if ENV_RAMSTAGE
111uint64_t reg_script_read_iosf(struct reg_script_context *ctx)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700112{
Lee Leahy32471722015-04-20 15:20:28 -0700113 const struct reg_script *step = ctx->step;
114
115 /* Process the request */
116 switch (step->id) {
117 case IOSF_PORT_BUNIT:
118 return iosf_bunit_read(step->reg);
119 case IOSF_PORT_SCORE:
120 return iosf_score_read(step->reg);
121 case IOSF_PORT_LPSS:
122 return iosf_lpss_read(step->reg);
123 case IOSF_PORT_0x58:
124 return iosf_port58_read(step->reg);
125 case IOSF_PORT_SCC:
126 return iosf_scc_read(step->reg);
shkimcc728f02015-09-22 17:53:58 +0900127 case IOSF_PORT_USBPHY:
128 return iosf_usbphy_read(step->reg);
Lee Leahy32471722015-04-20 15:20:28 -0700129 default:
130 printk(BIOS_DEBUG, "No read support for IOSF port 0x%x.\n",
131 step->id);
132 break;
133 }
134 return 0;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700135}
136
Lee Leahy32471722015-04-20 15:20:28 -0700137void reg_script_write_iosf(struct reg_script_context *ctx)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700138{
Lee Leahy32471722015-04-20 15:20:28 -0700139 const struct reg_script *step = ctx->step;
140
141 /* Process the request */
142 switch (step->id) {
143 case IOSF_PORT_BUNIT:
144 iosf_bunit_write(step->reg, step->value);
145 break;
146 case IOSF_PORT_SCORE:
147 iosf_score_write(step->reg, step->value);
148 break;
149 case IOSF_PORT_LPSS:
150 iosf_lpss_write(step->reg, step->value);
151 break;
152 case IOSF_PORT_0x58:
153 iosf_port58_write(step->reg, step->value);
154 break;
155 case IOSF_PORT_SCC:
156 iosf_scc_write(step->reg, step->value);
157 break;
shkimcc728f02015-09-22 17:53:58 +0900158 case IOSF_PORT_USBPHY:
159 iosf_usbphy_write(step->reg, step->value);
160 break;
Lee Leahy32471722015-04-20 15:20:28 -0700161 default:
162 printk(BIOS_DEBUG, "No write support for IOSF port 0x%x.\n",
163 step->id);
164 break;
165 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700166}
167
Lee Leahyefcee9f2016-04-29 17:26:36 -0700168static const struct reg_script_bus_entry reg_script_bus_table = {
169 REG_SCRIPT_TYPE_IOSF, reg_script_read_iosf, reg_script_write_iosf
Lee Leahy32471722015-04-20 15:20:28 -0700170};
171
Lee Leahyefcee9f2016-04-29 17:26:36 -0700172REG_SCRIPT_BUS_ENTRY(reg_script_bus_table);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700173
Lee Leahy32471722015-04-20 15:20:28 -0700174#endif /* ENV_RAMSTAGE */