blob: a78bb025440aec946aff24a1b5332ac4a718b6e0 [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>
9#include <malloc.h>
Simon Glass32761632016-01-18 20:19:21 -070010#include <pch.h>
Simon Glassa75abeb2016-01-17 16:11:59 -070011#include <asm/cpu.h>
Simon Glassab39d332016-03-11 22:06:56 -070012#include <asm/intel_regs.h>
Simon Glass6c9e1d82016-01-17 16:11:53 -070013#include <asm/io.h>
Simon Glass17f1c402014-11-14 18:18:32 -070014#include <asm/lapic.h>
Simon Glass63e08a22016-03-11 22:06:57 -070015#include <asm/lpc_common.h>
Simon Glass17f1c402014-11-14 18:18:32 -070016#include <asm/pci.h>
Simon Glass17f1c402014-11-14 18:18:32 -070017#include <asm/arch/model_206ax.h>
18#include <asm/arch/pch.h>
19#include <asm/arch/sandybridge.h>
20
Simon Glassd87b0922017-01-16 07:03:37 -070021DECLARE_GLOBAL_DATA_PTR;
22
Bin Mengfd2afdf2016-02-01 01:40:44 -080023#define GPIO_BASE 0x48
Simon Glass32761632016-01-18 20:19:21 -070024#define BIOS_CTRL 0xdc
25
Bin Meng051f1752016-02-17 00:16:24 -080026#ifndef CONFIG_HAVE_FSP
Simon Glass6c9e1d82016-01-17 16:11:53 -070027static int pch_revision_id = -1;
28static int pch_type = -1;
29
30/**
31 * pch_silicon_revision() - Read silicon revision ID from the PCH
32 *
33 * @dev: PCH device
34 * @return silicon revision ID
35 */
36static int pch_silicon_revision(struct udevice *dev)
37{
38 u8 val;
39
40 if (pch_revision_id < 0) {
41 dm_pci_read_config8(dev, PCI_REVISION_ID, &val);
42 pch_revision_id = val;
43 }
44
45 return pch_revision_id;
46}
47
48int pch_silicon_type(struct udevice *dev)
49{
50 u8 val;
51
52 if (pch_type < 0) {
53 dm_pci_read_config8(dev, PCI_DEVICE_ID + 1, &val);
54 pch_type = val;
55 }
56
57 return pch_type;
58}
59
60/**
61 * pch_silicon_supported() - Check if a certain revision is supported
62 *
63 * @dev: PCH device
64 * @type: PCH type
65 * @rev: Minimum required resion
66 * @return 0 if not supported, 1 if supported
67 */
68static int pch_silicon_supported(struct udevice *dev, int type, int rev)
69{
70 int cur_type = pch_silicon_type(dev);
71 int cur_rev = pch_silicon_revision(dev);
72
73 switch (type) {
74 case PCH_TYPE_CPT:
75 /* CougarPoint minimum revision */
76 if (cur_type == PCH_TYPE_CPT && cur_rev >= rev)
77 return 1;
78 /* PantherPoint any revision */
79 if (cur_type == PCH_TYPE_PPT)
80 return 1;
81 break;
82
83 case PCH_TYPE_PPT:
84 /* PantherPoint minimum revision */
85 if (cur_type == PCH_TYPE_PPT && cur_rev >= rev)
86 return 1;
87 break;
88 }
89
90 return 0;
91}
92
93#define IOBP_RETRY 1000
94static inline int iobp_poll(void)
95{
96 unsigned try = IOBP_RETRY;
97 u32 data;
98
99 while (try--) {
100 data = readl(RCB_REG(IOBPS));
101 if ((data & 1) == 0)
102 return 1;
103 udelay(10);
104 }
105
106 printf("IOBP timeout\n");
107 return 0;
108}
109
110void pch_iobp_update(struct udevice *dev, u32 address, u32 andvalue,
111 u32 orvalue)
112{
113 u32 data;
114
115 /* Set the address */
116 writel(address, RCB_REG(IOBPIRI));
117
118 /* READ OPCODE */
119 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
120 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
121 else
122 writel(IOBPS_READ_AX, RCB_REG(IOBPS));
123 if (!iobp_poll())
124 return;
125
126 /* Read IOBP data */
127 data = readl(RCB_REG(IOBPD));
128 if (!iobp_poll())
129 return;
130
131 /* Check for successful transaction */
132 if ((readl(RCB_REG(IOBPS)) & 0x6) != 0) {
133 printf("IOBP read 0x%08x failed\n", address);
134 return;
135 }
136
137 /* Update the data */
138 data &= andvalue;
139 data |= orvalue;
140
141 /* WRITE OPCODE */
142 if (pch_silicon_supported(dev, PCH_TYPE_CPT, PCH_STEP_B0))
143 writel(IOBPS_RW_BX, RCB_REG(IOBPS));
144 else
145 writel(IOBPS_WRITE_AX, RCB_REG(IOBPS));
146 if (!iobp_poll())
147 return;
148
149 /* Write IOBP data */
150 writel(data, RCB_REG(IOBPD));
151 if (!iobp_poll())
152 return;
153}
154
Simon Glasse0e7b362015-03-05 12:25:33 -0700155static int bd82x6x_probe(struct udevice *dev)
Simon Glass17f1c402014-11-14 18:18:32 -0700156{
Simon Glass044f1a02016-01-17 16:11:10 -0700157 if (!(gd->flags & GD_FLG_RELOC))
158 return 0;
159
Simon Glass39f3f8c2016-01-17 16:11:37 -0700160 /* Cause the SATA device to do its init */
Simon Glass85ee1652016-05-01 11:35:52 -0600161 uclass_first_device(UCLASS_AHCI, &dev);
Simon Glass39f3f8c2016-01-17 16:11:37 -0700162
Simon Glass17f1c402014-11-14 18:18:32 -0700163 return 0;
164}
Bin Meng051f1752016-02-17 00:16:24 -0800165#endif /* CONFIG_HAVE_FSP */
Simon Glass17f1c402014-11-14 18:18:32 -0700166
Bin Meng06d66af2016-02-01 01:40:42 -0800167static int bd82x6x_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
Simon Glass32761632016-01-18 20:19:21 -0700168{
169 u32 rcba;
170
171 dm_pci_read_config32(dev, PCH_RCBA, &rcba);
172 /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
173 rcba = rcba & 0xffffc000;
174 *sbasep = rcba + 0x3800;
175
176 return 0;
177}
178
Simon Glass32761632016-01-18 20:19:21 -0700179static int bd82x6x_set_spi_protect(struct udevice *dev, bool protect)
180{
Simon Glass63e08a22016-03-11 22:06:57 -0700181 return lpc_set_spi_protect(dev, BIOS_CTRL, protect);
Simon Glass32761632016-01-18 20:19:21 -0700182}
183
Bin Mengfd2afdf2016-02-01 01:40:44 -0800184static int bd82x6x_get_gpio_base(struct udevice *dev, u32 *gbasep)
185{
186 u32 base;
187
188 /*
189 * GPIO_BASE moved to its current offset with ICH6, but prior to
190 * that it was unused (or undocumented). Check that it looks
191 * okay: not all ones or zeros.
192 *
193 * Note we don't need check bit0 here, because the Tunnel Creek
194 * GPIO base address register bit0 is reserved (read returns 0),
195 * while on the Ivybridge the bit0 is used to indicate it is an
196 * I/O space.
197 */
198 dm_pci_read_config32(dev, GPIO_BASE, &base);
199 if (base == 0x00000000 || base == 0xffffffff) {
200 debug("%s: unexpected BASE value\n", __func__);
201 return -ENODEV;
202 }
203
204 /*
205 * Okay, I guess we're looking at the right device. The actual
206 * GPIO registers are in the PCI device's I/O space, starting
207 * at the offset that we just read. Bit 0 indicates that it's
208 * an I/O address, not a memory address, so mask that off.
209 */
210 *gbasep = base & 1 ? base & ~3 : base & ~15;
211
212 return 0;
213}
214
Simon Glass32761632016-01-18 20:19:21 -0700215static const struct pch_ops bd82x6x_pch_ops = {
Bin Meng06d66af2016-02-01 01:40:42 -0800216 .get_spi_base = bd82x6x_pch_get_spi_base,
Simon Glass32761632016-01-18 20:19:21 -0700217 .set_spi_protect = bd82x6x_set_spi_protect,
Bin Mengfd2afdf2016-02-01 01:40:44 -0800218 .get_gpio_base = bd82x6x_get_gpio_base,
Simon Glass32761632016-01-18 20:19:21 -0700219};
220
Simon Glasse0e7b362015-03-05 12:25:33 -0700221static const struct udevice_id bd82x6x_ids[] = {
222 { .compatible = "intel,bd82x6x" },
223 { }
224};
225
226U_BOOT_DRIVER(bd82x6x_drv) = {
227 .name = "bd82x6x",
228 .id = UCLASS_PCH,
229 .of_match = bd82x6x_ids,
Bin Meng051f1752016-02-17 00:16:24 -0800230#ifndef CONFIG_HAVE_FSP
Simon Glasse0e7b362015-03-05 12:25:33 -0700231 .probe = bd82x6x_probe,
Bin Meng051f1752016-02-17 00:16:24 -0800232#endif
Simon Glass32761632016-01-18 20:19:21 -0700233 .ops = &bd82x6x_pch_ops,
Simon Glasse0e7b362015-03-05 12:25:33 -0700234};