blob: 5448f064fcbf0761da5ba445b396c6d7baaf68bb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass17f1c402014-11-14 18:18:32 -07002/*
3 * Copyright (C) 2014 Google, Inc
Simon Glass17f1c402014-11-14 18:18:32 -07004 */
Simon Glass17f1c402014-11-14 18:18:32 -07005#include <common.h>
Simon Glasse0e7b362015-03-05 12:25:33 -07006#include <dm.h>
Simon Glass17f1c402014-11-14 18:18:32 -07007#include <errno.h>
8#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Simon Glass17f1c402014-11-14 18:18:32 -070010#include <malloc.h>
Simon Glass32761632016-01-18 20:19:21 -070011#include <pch.h>
Simon Glassa75abeb2016-01-17 16:11:59 -070012#include <asm/cpu.h>
Simon Glassab39d332016-03-11 22:06:56 -070013#include <asm/intel_regs.h>
Simon Glass6c9e1d82016-01-17 16:11:53 -070014#include <asm/io.h>
Simon Glass17f1c402014-11-14 18:18:32 -070015#include <asm/lapic.h>
Simon Glass63e08a22016-03-11 22:06:57 -070016#include <asm/lpc_common.h>
Simon Glass17f1c402014-11-14 18:18:32 -070017#include <asm/pci.h>
Simon Glass17f1c402014-11-14 18:18:32 -070018#include <asm/arch/model_206ax.h>
19#include <asm/arch/pch.h>
20#include <asm/arch/sandybridge.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060021#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060022#include <linux/delay.h>
Simon Glass17f1c402014-11-14 18:18:32 -070023
Simon Glassd87b0922017-01-16 07:03:37 -070024DECLARE_GLOBAL_DATA_PTR;
25
Simon Glass1a9360d2019-02-16 20:24:52 -070026#define GPIO_BASE 0x48
27#define BIOS_CTRL 0xdc
28
29#define RCBA_AUDIO_CONFIG 0x2030
30#define RCBA_AUDIO_CONFIG_HDA BIT(31)
31#define RCBA_AUDIO_CONFIG_MASK 0xfe
Simon Glass32761632016-01-18 20:19:21 -070032
Bin Meng051f1752016-02-17 00:16:24 -080033#ifndef CONFIG_HAVE_FSP
Simon Glass6c9e1d82016-01-17 16:11:53 -070034static int pch_revision_id = -1;
35static int pch_type = -1;
36
37/**
38 * pch_silicon_revision() - Read silicon revision ID from the PCH
39 *
40 * @dev: PCH device
41 * @return silicon revision ID
42 */
43static int pch_silicon_revision(struct udevice *dev)
44{
45 u8 val;
46
47 if (pch_revision_id < 0) {
48 dm_pci_read_config8(dev, PCI_REVISION_ID, &val);
49 pch_revision_id = val;
50 }
51
52 return pch_revision_id;
53}
54
55int pch_silicon_type(struct udevice *dev)
56{
57 u8 val;
58
59 if (pch_type < 0) {
60 dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val);
61 pch_type = val;
62 }
63
64 return pch_type;
65}
66
67/**
68 * pch_silicon_supported() - Check if a certain revision is supported
69 *
70 * @dev: PCH device
71 * @type: PCH type
72 * @rev: Minimum required resion
73 * @return 0 if not supported, 1 if supported
74 */
75static int pch_silicon_supported(struct udevice *dev, int type, int rev)
76{
77 int cur_type = pch_silicon_type(dev);
78 int cur_rev = pch_silicon_revision(dev);
79
80 switch (type) {
81 case PCH_TYPE_CPT:
82 /* CougarPoint minimum revision */
83 if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
84 return 1;
85 /* PantherPoint any revision */
86 if (cur_type == PCH_TYPE_PPT)
87 return 1;
88 break;
89
90 case PCH_TYPE_PPT:
91 /* PantherPoint minimum revision */
92 if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
93 return 1;
94 break;
95 }
96
97 return 0;
98}
99
100#define IOBP_RETRY 1000
101static inline int iobp_poll(void)
102{
103 unsigned try = IOBP_RETRY;
104 u32 data;
105
106 while (try--) {
107 data = readl(RCB_REG(IOBPS));
108 if ((data & 1) == 0)
109 return 1;
110 udelay(10);
111 }
112
113 printf("IOBP timeout\n");
114 return 0;
115}
116
117void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
118 u32 orvalue)
119{
120 u32 data;
121
122 /* Set the address */
123 writel(address, RCB_REG(IOBPIRI));
124
125 /* READ OPCODE */
126 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
127 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
128 else
129 writel(IOBPS_READ_AX, RCB_REG(IOBPS));
130 if (!iobp_poll())
131 return;
132
133 /* Read IOBP data */
134 data = readl(RCB_REG(IOBPD));
135 if (!iobp_poll())
136 return;
137
138 /* Check for successful transaction */
139 if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
140 printf("IOBP read 0x%08x failed\n", address);
141 return;
142 }
143
144 /* Update the data */
145 data &= andvalue;
146 data |= orvalue;
147
148 /* WRITE OPCODE */
149 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
150 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
151 else
152 writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
153 if (!iobp_poll())
154 return;
155
156 /* Write IOBP data */
157 writel(data, RCB_REG(IOBPD));
158 if (!iobp_poll())
159 return;
160}
161
Simon Glasse0e7b362015-03-05 12:25:33 -0700162static int bd82x6x_probe(struct udevice *dev)
Simon Glass17f1c402014-11-14 18:18:32 -0700163{
Simon Glass044f1a02016-01-17 16:11:10 -0700164 if (!(gd->flags & GD_FLG_RELOC))
165 return 0;
166
Simon Glass39f3f8c2016-01-17 16:11:37 -0700167 /* Cause the SATA device to do its init */
Simon Glass85ee1652016-05-01 11:35:52 -0600168 uclass_first_device(UCLASS_AHCI, &dev);
Simon Glass39f3f8c2016-01-17 16:11:37 -0700169
Simon Glass17f1c402014-11-14 18:18:32 -0700170 return 0;
171}
Bin Meng051f1752016-02-17 00:16:24 -0800172#endif /* CONFIG_HAVE_FSP */
Simon Glass17f1c402014-11-14 18:18:32 -0700173
Bin Meng06d66af2016-02-01 01:40:42 -0800174static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
Simon Glass32761632016-01-18 20:19:21 -0700175{
176 u32 rcba;
177
178 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
179 /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
180 rcba = rcba & 0xffffc000;
181 *sbasep = rcba + 0x3800;
182
183 return 0;
184}
185
Simon Glass32761632016-01-18 20:19:21 -0700186static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
187{
Simon Glass63e08a22016-03-11 22:06:57 -0700188 return lpc_set_spi_protect(dev, BIOS_CTRL, protect);
Simon Glass32761632016-01-18 20:19:21 -0700189}
190
Bin Mengfd2afdf2016-02-01 01:40:44 -0800191static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
192{
193 u32 base;
194
195 /*
196 * GPIO_BASE moved to its current offset with ICH6, but prior to
197 * that it was unused (or undocumented). Check that it looks
198 * okay: not all ones or zeros.
199 *
200 * Note we don't need check bit0 here, because the Tunnel Creek
201 * GPIO base address register bit0 is reserved (read returns 0),
202 * while on the Ivybridge the bit0 is used to indicate it is an
203 * I/O space.
204 */
205 dm_pci_read_config32(dev, GPIO_BASE, &base);
206 if (base == 0x00000000 || base == 0xffffffff) {
207 debug("%s: unexpected BASE value\n", __func__);
208 return -ENODEV;
209 }
210
211 /*
212 * Okay, I guess we're looking at the right device. The actual
213 * GPIO registers are in the PCI device's I/O space, starting
214 * at the offset that we just read. Bit 0 indicates that it's
215 * an I/O address, not a memory address, so mask that off.
216 */
217 *gbasep = base & 1 ? base & ~3 : base & ~15;
218
219 return 0;
220}
221
Simon Glass1a9360d2019-02-16 20:24:52 -0700222static int bd82x6x_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
223 int size)
224{
225 u32 rcba, val;
226
227 switch (req) {
228 case PCH_REQ_HDA_CONFIG:
229 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
230 val = readl(rcba + RCBA_AUDIO_CONFIG);
231 if (!(val & RCBA_AUDIO_CONFIG_HDA))
232 return -ENOENT;
233
234 return val & RCBA_AUDIO_CONFIG_MASK;
Simon Glass027f8372019-04-25 21:59:02 -0600235 case PCH_REQ_PMBASE_INFO: {
236 struct pch_pmbase_info *pm = data;
237 int ret;
238
239 /* Find the base address of the powermanagement registers */
240 ret = dm_pci_read_config16(dev, 0x40, &pm->base);
241 if (ret)
242 return ret;
243 pm->base &= 0xfffe;
244 pm->gpio0_en_ofs = GPE0_EN;
245 pm->pm1_sts_ofs = PM1_STS;
246 pm->pm1_cnt_ofs = PM1_CNT;
247
248 return 0;
249 }
Simon Glass1a9360d2019-02-16 20:24:52 -0700250 default:
251 return -ENOSYS;
252 }
253}
254
Simon Glass32761632016-01-18 20:19:21 -0700255static const struct pch_ops bd82x6x_pch_ops = {
Bin Meng06d66af2016-02-01 01:40:42 -0800256 .get_spi_base = bd82x6x_pch_get_spi_base,
Simon Glass32761632016-01-18 20:19:21 -0700257 .set_spi_protect = bd82x6x_set_spi_protect,
Bin Mengfd2afdf2016-02-01 01:40:44 -0800258 .get_gpio_base = bd82x6x_get_gpio_base,
Simon Glass1a9360d2019-02-16 20:24:52 -0700259 .ioctl = bd82x6x_ioctl,
Simon Glass32761632016-01-18 20:19:21 -0700260};
261
Simon Glasse0e7b362015-03-05 12:25:33 -0700262static const struct udevice_id bd82x6x_ids[] = {
263 { .compatible = "intel,bd82x6x" },
264 { }
265};
266
267U_BOOT_DRIVER(bd82x6x_drv) = {
268 .name = "bd82x6x",
269 .id = UCLASS_PCH,
270 .of_match = bd82x6x_ids,
Bin Meng051f1752016-02-17 00:16:24 -0800271#ifndef CONFIG_HAVE_FSP
Simon Glasse0e7b362015-03-05 12:25:33 -0700272 .probe = bd82x6x_probe,
Bin Meng051f1752016-02-17 00:16:24 -0800273#endif
Simon Glass32761632016-01-18 20:19:21 -0700274 .ops = &bd82x6x_pch_ops,
Simon Glasse0e7b362015-03-05 12:25:33 -0700275};