blob: 9a267578f8ccb011b1a7a44b58d05780c2ad63ff [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,
Lee Leahy32471722015-04-20 15:20:28 -070012 * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty 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
17#include <arch/io.h>
Lee Leahy32471722015-04-20 15:20:28 -070018#include <console/console.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070019#include <soc/iosf.h>
20
Lee Leahy32471722015-04-20 15:20:28 -070021#if ENV_RAMSTAGE
Lee Leahy77ff0b12015-05-05 15:07:29 -070022#define IOSF_PCI_BASE (CONFIG_MMCONF_BASE_ADDRESS + (IOSF_PCI_DEV << 12))
23
24static inline void write_iosf_reg(int reg, uint32_t value)
25{
Lee Leahy32471722015-04-20 15:20:28 -070026 write32((void *)(IOSF_PCI_BASE + reg), value);
Lee Leahy77ff0b12015-05-05 15:07:29 -070027}
28static inline uint32_t read_iosf_reg(int reg)
29{
Lee Leahy32471722015-04-20 15:20:28 -070030 return read32((void *)(IOSF_PCI_BASE + reg));
Lee Leahy77ff0b12015-05-05 15:07:29 -070031}
32#else
33static inline void write_iosf_reg(int reg, uint32_t value)
34{
35 pci_write_config32(IOSF_PCI_DEV, reg, value);
36}
37static inline uint32_t read_iosf_reg(int reg)
38{
39 return pci_read_config32(IOSF_PCI_DEV, reg);
40}
Lee Leahy32471722015-04-20 15:20:28 -070041#endif /* ENV_RAMSTAGE */
Lee Leahy77ff0b12015-05-05 15:07:29 -070042
43/* Common sequences for all the port accesses. */
44static uint32_t iosf_read_port(uint32_t cr, int reg)
45{
46 cr |= IOSF_REG(reg) | IOSF_BYTE_EN;
47 write_iosf_reg(MCRX_REG, IOSF_REG_UPPER(reg));
48 write_iosf_reg(MCR_REG, cr);
49 return read_iosf_reg(MDR_REG);
50}
51
52static void iosf_write_port(uint32_t cr, int reg, uint32_t val)
53{
54 cr |= IOSF_REG(reg) | IOSF_BYTE_EN;
55 write_iosf_reg(MDR_REG, val);
56 write_iosf_reg(MCRX_REG, IOSF_REG_UPPER(reg));
57 write_iosf_reg(MCR_REG, cr);
58}
59
60#define IOSF_READ(port) \
Lee Leahy32471722015-04-20 15:20:28 -070061 (IOSF_OPCODE(IOSF_OP_READ_##port) | IOSF_PORT(IOSF_PORT_##port))
Lee Leahy77ff0b12015-05-05 15:07:29 -070062#define IOSF_WRITE(port) \
Lee Leahy32471722015-04-20 15:20:28 -070063 (IOSF_OPCODE(IOSF_OP_WRITE_##port) | IOSF_PORT(IOSF_PORT_##port))
Lee Leahy77ff0b12015-05-05 15:07:29 -070064
65uint32_t iosf_bunit_read(int reg)
66{
67 return iosf_read_port(IOSF_READ(BUNIT), reg);
68}
69
70void iosf_bunit_write(int reg, uint32_t val)
71{
72 iosf_write_port(IOSF_WRITE(BUNIT), reg, val);
73}
74
Lee Leahy77ff0b12015-05-05 15:07:29 -070075uint32_t iosf_punit_read(int reg)
76{
77 return iosf_read_port(IOSF_READ(PMC), reg);
78}
79
80void iosf_punit_write(int reg, uint32_t val)
81{
82 iosf_write_port(IOSF_WRITE(PMC), reg, val);
83}
84
Lee Leahy32471722015-04-20 15:20:28 -070085uint32_t iosf_score_read(int reg)
Lee Leahy77ff0b12015-05-05 15:07:29 -070086{
Lee Leahy32471722015-04-20 15:20:28 -070087 return iosf_read_port(IOSF_READ(SCORE), reg);
Lee Leahy77ff0b12015-05-05 15:07:29 -070088}
89
Lee Leahy32471722015-04-20 15:20:28 -070090void iosf_score_write(int reg, uint32_t val)
Lee Leahy77ff0b12015-05-05 15:07:29 -070091{
Lee Leahy32471722015-04-20 15:20:28 -070092 iosf_write_port(IOSF_WRITE(SCORE), reg, val);
Lee Leahy77ff0b12015-05-05 15:07:29 -070093}
94
95uint32_t iosf_lpss_read(int reg)
96{
97 return iosf_read_port(IOSF_READ(LPSS), reg);
98}
99
100void iosf_lpss_write(int reg, uint32_t val)
101{
Lee Leahy32471722015-04-20 15:20:28 -0700102 iosf_write_port(IOSF_WRITE(LPSS), reg, val);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700103}
104
Lee Leahy32471722015-04-20 15:20:28 -0700105uint32_t iosf_port58_read(int reg)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700106{
Lee Leahy32471722015-04-20 15:20:28 -0700107 return iosf_read_port(IOSF_READ(0x58), reg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700108}
109
Lee Leahy32471722015-04-20 15:20:28 -0700110void iosf_port58_write(int reg, uint32_t val)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700111{
Lee Leahy32471722015-04-20 15:20:28 -0700112 iosf_write_port(IOSF_WRITE(0x58), reg, val);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700113}
114
115uint32_t iosf_scc_read(int reg)
116{
117 return iosf_read_port(IOSF_READ(SCC), reg);
118}
119
120void iosf_scc_write(int reg, uint32_t val)
121{
122 return iosf_write_port(IOSF_WRITE(SCC), reg, val);
123}
124
shkimcc728f02015-09-22 17:53:58 +0900125uint32_t iosf_usbphy_read(int reg)
126{
127 return iosf_read_port(IOSF_READ(USBPHY), reg);
128}
129
130void iosf_usbphy_write(int reg, uint32_t val)
131{
132 return iosf_write_port(IOSF_WRITE(USBPHY), reg, val);
133}
Lee Leahy32471722015-04-20 15:20:28 -0700134
135#if ENV_RAMSTAGE
136uint64_t reg_script_read_iosf(struct reg_script_context *ctx)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700137{
Lee Leahy32471722015-04-20 15:20:28 -0700138 const struct reg_script *step = ctx->step;
139
140 /* Process the request */
141 switch (step->id) {
142 case IOSF_PORT_BUNIT:
143 return iosf_bunit_read(step->reg);
144 case IOSF_PORT_SCORE:
145 return iosf_score_read(step->reg);
146 case IOSF_PORT_LPSS:
147 return iosf_lpss_read(step->reg);
148 case IOSF_PORT_0x58:
149 return iosf_port58_read(step->reg);
150 case IOSF_PORT_SCC:
151 return iosf_scc_read(step->reg);
shkimcc728f02015-09-22 17:53:58 +0900152 case IOSF_PORT_USBPHY:
153 return iosf_usbphy_read(step->reg);
Lee Leahy32471722015-04-20 15:20:28 -0700154 default:
155 printk(BIOS_DEBUG, "No read support for IOSF port 0x%x.\n",
156 step->id);
157 break;
158 }
159 return 0;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700160}
161
Lee Leahy32471722015-04-20 15:20:28 -0700162void reg_script_write_iosf(struct reg_script_context *ctx)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700163{
Lee Leahy32471722015-04-20 15:20:28 -0700164 const struct reg_script *step = ctx->step;
165
166 /* Process the request */
167 switch (step->id) {
168 case IOSF_PORT_BUNIT:
169 iosf_bunit_write(step->reg, step->value);
170 break;
171 case IOSF_PORT_SCORE:
172 iosf_score_write(step->reg, step->value);
173 break;
174 case IOSF_PORT_LPSS:
175 iosf_lpss_write(step->reg, step->value);
176 break;
177 case IOSF_PORT_0x58:
178 iosf_port58_write(step->reg, step->value);
179 break;
180 case IOSF_PORT_SCC:
181 iosf_scc_write(step->reg, step->value);
182 break;
shkimcc728f02015-09-22 17:53:58 +0900183 case IOSF_PORT_USBPHY:
184 iosf_usbphy_write(step->reg, step->value);
185 break;
Lee Leahy32471722015-04-20 15:20:28 -0700186 default:
187 printk(BIOS_DEBUG, "No write support for IOSF port 0x%x.\n",
188 step->id);
189 break;
190 }
Lee Leahy77ff0b12015-05-05 15:07:29 -0700191}
192
Lee Leahyefcee9f2016-04-29 17:26:36 -0700193static const struct reg_script_bus_entry reg_script_bus_table = {
194 REG_SCRIPT_TYPE_IOSF, reg_script_read_iosf, reg_script_write_iosf
Lee Leahy32471722015-04-20 15:20:28 -0700195};
196
Lee Leahyefcee9f2016-04-29 17:26:36 -0700197REG_SCRIPT_BUS_ENTRY(reg_script_bus_table);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700198
Lee Leahy32471722015-04-20 15:20:28 -0700199#endif /* ENV_RAMSTAGE */