blob: e4ed6f37d53c92d20c1d58d45d9108e3b5f06330 [file] [log] [blame]
Duncan Lauriee3f75f82013-10-28 15:49:34 -07001/*
2 * This file is part of the coreboot project.
3 *
Duncan Lauriee3f75f82013-10-28 15:49:34 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Duncan Lauriee3f75f82013-10-28 15:49:34 -070013 */
14
Kyösti Mälkki13f66502019-03-03 08:01:05 +020015#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020016#include <device/pci_ops.h>
Duncan Lauriee3f75f82013-10-28 15:49:34 -070017#include <console/console.h>
Duncan Lauriee3f75f82013-10-28 15:49:34 -070018#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
Matt DeVillierbe33a672018-03-11 22:44:41 -050021#include <drivers/intel/gma/opregion.h>
Duncan Laurie223d4a4f2013-10-31 08:27:29 -070022#include <reg_script.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070023#include <soc/gfx.h>
24#include <soc/iosf.h>
Matt DeVillierbe33a672018-03-11 22:44:41 -050025#include <soc/nvs.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070026#include <soc/pci_devs.h>
27#include <soc/ramstage.h>
Matt DeVillierbe33a672018-03-11 22:44:41 -050028#include <cbmem.h>
Elyes HAOUAS27d02d82019-05-15 21:11:39 +020029#include <types.h>
Duncan Lauriee3f75f82013-10-28 15:49:34 -070030
Duncan Laurieb40e4442013-12-09 14:38:57 -080031#include "chip.h"
32
Duncan Laurie223d4a4f2013-10-31 08:27:29 -070033#define GFX_TIMEOUT 100000 /* 100ms */
Duncan Lauriee3f75f82013-10-28 15:49:34 -070034
35/*
36 * Lock Power Context Base Register to point to a 24KB block
37 * of memory in GSM. Power context save data is stored here.
38 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020039static void gfx_lock_pcbase(struct device *dev)
Duncan Lauriee3f75f82013-10-28 15:49:34 -070040{
Duncan Laurie223d4a4f2013-10-31 08:27:29 -070041 struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0);
Duncan Lauriee3f75f82013-10-28 15:49:34 -070042 const u16 gms_size_map[17] = { 0,32,64,96,128,160,192,224,256,
43 288,320,352,384,416,448,480,512 };
44 u32 pcsize = 24 << 10; /* 24KB */
45 u32 wopcmsz = 0x100000; /* PAVP offset */
46 u32 gms, gmsize, pcbase;
47
48 gms = pci_read_config32(dev, GGC) & GGC_GSM_SIZE_MASK;
49 gms >>= 3;
Jacob Garber0decccb2019-03-29 18:33:32 -060050 if (gms >= ARRAY_SIZE(gms_size_map))
Duncan Lauriee3f75f82013-10-28 15:49:34 -070051 return;
52 gmsize = gms_size_map[gms];
53
54 /* PcBase = BDSM + GMS Size - WOPCMSZ - PowerContextSize */
55 pcbase = pci_read_config32(dev, GSM_BASE) & 0xfff00000;
56 pcbase += (gmsize-1) * wopcmsz - pcsize;
57 pcbase |= 1; /* Lock */
58
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080059 write32((u32 *)(uintptr_t)(res->base + 0x182120), pcbase);
Duncan Laurie223d4a4f2013-10-31 08:27:29 -070060}
61
62static const struct reg_script gfx_init_script[] = {
63 /* Allow-Wake render/media wells */
64 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x130090, ~1, 1),
65 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x130094, 1, 1, GFX_TIMEOUT),
66 /* Render Force-Wake */
67 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1300b0, 0x80008000),
68 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x1300b4, 0x8000, 0x8000,
69 GFX_TIMEOUT),
70 /* Media Force-Wake */
71 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1300b8, 0x80008000),
72 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x1300bc, 0x8000, 0x8000,
73 GFX_TIMEOUT),
74 /* Workaround - X0:261954/A0:261955 */
75 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x182060, ~0xf, 1),
76
77 /*
78 * PowerMeter Weights
79 */
80
81 /* SET1 */
82 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA800, 0x00000000),
83 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA804, 0x00000000),
84 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA808, 0x0000ff0A),
85 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA80C, 0x1D000000),
86 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA810, 0xAC004900),
87 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA814, 0x000F0000),
88 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA818, 0x5A000000),
89 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA81C, 0x2600001F),
90 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA820, 0x00090000),
91 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA824, 0x2000ff00),
92 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA828, 0xff090016),
93 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA82C, 0x00000000),
94 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA830, 0x00000100),
95 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA834, 0x00A00F51),
96 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA838, 0x000B0000),
97 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA83C, 0xcb7D3307),
98 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA840, 0x003C0000),
99 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA844, 0xFFFF0000),
100 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA848, 0x00220000),
101 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA84c, 0x43000000),
102 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA850, 0x00000800),
103 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA854, 0x00000F00),
104 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA858, 0x00000021),
105 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA85c, 0x00000000),
106 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA860, 0x00190000),
107 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xAA80, 0x00FF00FF),
108 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xAA84, 0x00000000),
109 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x1300A4, 0x00000000),
110 /* SET2 */
111 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA900, 0x00000000),
112 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA904, 0x00000000),
113 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA908, 0x00000000),
114 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa90c, 0x1D000000),
115 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa910, 0xAC005000),
116 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa914, 0x000F0000),
117 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa918, 0x5A000000),
118 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa91c, 0x2600001F),
119 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa920, 0x00090000),
120 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa924, 0x2000ff00),
121 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa928, 0xff090016),
122 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa92c, 0x00000000),
123 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa930, 0x00000100),
124 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa934, 0x00A00F51),
125 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xa938, 0x000B0000),
126 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA93C, 0xcb7D3307),
127 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA940, 0x003C0000),
128 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA944, 0xFFFF0000),
129 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA948, 0x00220000),
130 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA94C, 0x43000000),
131 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA950, 0x00000800),
132 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA954, 0x00000000),
133 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA960, 0x00000000),
134 /* SET3 */
135 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xaa3c, 0x00000000),
136 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xaa54, 0x00000000),
137 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xaa60, 0x00000000),
138 /* Enable PowerMeter Counters */
139 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA248, 0x00000058),
140
141 /* Program PUNIT_GPU_EC_VIRUS based on DPTF SDP */
142 /* SDP Profile 4 == 0x11940, others 0xcf08 */
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800143 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_GPU_EC_VIRUS, 0xcf08),
Duncan Laurie223d4a4f2013-10-31 08:27:29 -0700144
145 /* GfxPause */
146 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa000, 0x00071388),
147
148 /* Dynamic EU Control Settings */
149 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa080, 0x00000004),
150
151 /* Lock ECO Bit Settings */
152 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa180, 0x80000000),
153
154 /* DOP Clock Gating */
155 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9424, 0x00000001),
156
157 /* MBCunit will send the VCR (Fuse) writes as NP-W */
158 REG_RES_RMW32(PCI_BASE_ADDRESS_0, 0x907c, 0xfffeffff, 0x00010000),
159
160 /*
161 * RC6 Settings
162 */
163 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA090, 0x00000000),
164 /* RC1e - RC6/6p - RC6pp Wake Rate Limits */
165 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA09C, 0x00280000),
166 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA0A8, 0x0001E848),
167 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA0AC, 0x00000019),
168 /* RC Sleep / RCx Thresholds */
169 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA0B0, 0x00000000),
170 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA0B8, 0x00000557),
171
172 /*
173 * Turbo Settings
174 */
175
176 /* Render/Video/Blitter Idle Max Count */
177 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x2054, 0x0000000A),
178 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x12054, 0x0000000A),
179 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0x22054, 0x0000000A),
180 /* RP Down Timeout */
181 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA010, 0x000F4240),
182
183 /*
184 * Turbo Control Settings
185 */
186
187 /* RP Up/Down Threshold */
188 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA02C, 0x0000E8E8),
189 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA030, 0x0003BD08),
190 /* RP Up/Down EI */
191 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA068, 0x000101D0),
192 REG_RES_OR32(PCI_BASE_ADDRESS_0, 0xA06C, 0x00055730),
193
194 /* RP Idle Hysteresis */
195 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa070, 0x0000000a),
196
197 /* HW RC6 Control Settings */
198 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa090, 0x11000000),
199
200 /* RP Control */
201 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa024, 0x00000592),
202
203 /* Enable PM Interrupts */
204 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x44024, 0x03000000),
205 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x4402c, 0x03000076),
206 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0xa168, 0x0000007e),
207
208 /* Aggressive Clock Gating */
209 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9400, 0),
210 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9404, 0),
211 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x9408, 0),
212 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x940c, 0),
Aaron Durbin35494622014-01-15 11:59:10 -0600213
214 /* Enable Gfx Turbo. */
215 REG_IOSF_RMW(IOSF_PORT_PMC, SB_BIOS_CONFIG,
216 ~SB_BIOS_CONFIG_GFX_TURBO_DIS, 0),
Duncan Laurie223d4a4f2013-10-31 08:27:29 -0700217 REG_SCRIPT_END
218};
219
220static const struct reg_script gpu_pre_vbios_script[] = {
221 /* Make sure GFX is bus master with MMIO access */
222 REG_PCI_OR32(PCI_COMMAND, PCI_COMMAND_MASTER|PCI_COMMAND_MEMORY),
223 /* Display */
224 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xc0),
225 REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xc0, 0xc0,
226 GFX_TIMEOUT),
227 /* Tx/Rx Lanes */
228 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xfff0c0),
229 REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xfff0c0, 0xfff0c0,
230 GFX_TIMEOUT),
231 /* Common Lane */
232 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xfffcc0),
233 REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xfffcc0, 0xfffcc0,
234 GFX_TIMEOUT),
235 /* Ungating Tx only */
236 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xf00cc0),
237 REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xfffcc0, 0xf00cc0,
238 GFX_TIMEOUT),
239 /* Ungating Common Lane only */
240 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xf000c0),
241 REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xffffc0, 0xf000c0,
242 GFX_TIMEOUT),
243 /* Ungating Display */
244 REG_IOSF_WRITE(IOSF_PORT_PMC, PUNIT_PWRGT_CONTROL, 0xf00000),
245 REG_IOSF_POLL(IOSF_PORT_PMC, PUNIT_PWRGT_STATUS, 0xfffff0, 0xf00000,
246 GFX_TIMEOUT),
247 REG_SCRIPT_END
248};
249
250static const struct reg_script gfx_post_vbios_script[] = {
251 /* Deassert Render Force-Wake */
252 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1300b0, 0x80000000),
253 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x1300b4, 0x8000, 0, GFX_TIMEOUT),
254 /* Deassert Media Force-Wake */
255 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x1300b8, 0x80000000),
256 REG_RES_POLL32(PCI_BASE_ADDRESS_0, 0x1300bc, 0x8000, 0, GFX_TIMEOUT),
257 /* Set Lock bits */
258 REG_PCI_RMW32(GGC, 0xffffffff, 1),
259 REG_PCI_RMW32(GSM_BASE, 0xffffffff, 1),
260 REG_PCI_RMW32(GTT_BASE, 0xffffffff, 1),
261 REG_SCRIPT_END
262};
263
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200264static inline void gfx_run_script(struct device *dev,
265 const struct reg_script *ops)
Duncan Laurie223d4a4f2013-10-31 08:27:29 -0700266{
Aaron Durbin616f3942013-12-10 17:12:44 -0800267 reg_script_run_on_dev(dev, ops);
Duncan Laurie223d4a4f2013-10-31 08:27:29 -0700268}
269
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200270static void gfx_pre_vbios_init(struct device *dev)
Duncan Laurie223d4a4f2013-10-31 08:27:29 -0700271{
272 printk(BIOS_INFO, "GFX: Pre VBIOS Init\n");
273 gfx_run_script(dev, gpu_pre_vbios_script);
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700274}
275
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200276static void gfx_pm_init(struct device *dev)
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700277{
278 printk(BIOS_INFO, "GFX: Power Management Init\n");
Duncan Laurie223d4a4f2013-10-31 08:27:29 -0700279 gfx_run_script(dev, gfx_init_script);
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700280
281 /* Lock power context base */
282 gfx_lock_pcbase(dev);
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700283}
284
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200285static void gfx_post_vbios_init(struct device *dev)
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700286{
Duncan Laurie223d4a4f2013-10-31 08:27:29 -0700287 printk(BIOS_INFO, "GFX: Post VBIOS Init\n");
288 gfx_run_script(dev, gfx_post_vbios_script);
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700289}
290
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200291static void set_backlight_pwm(struct device *dev, uint32_t bklt_reg, int req_hz)
Aaron Durbin59e209a2014-04-24 11:35:28 -0500292{
293 int divider;
294 struct resource *res;
295
296 res = find_resource(dev, PCI_BASE_ADDRESS_0);
297
298 if (res == NULL)
299 return;
300
301 /* Default to 200 Hz if nothing is set. */
302 if (req_hz == 0)
303 req_hz = 200;
304
305 /* Base clock is 25MHz */
306 divider = 25 * 1000 * 1000 / (16 * req_hz);
307
308 /* Do not set duty cycle (lower 16 bits). Just set the divider. */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800309 write32((u32 *)(uintptr_t)(res->base + bklt_reg), divider << 16);
Aaron Durbin59e209a2014-04-24 11:35:28 -0500310}
311
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200312static void gfx_panel_setup(struct device *dev)
Duncan Laurieb40e4442013-12-09 14:38:57 -0800313{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300314 struct soc_intel_baytrail_config *config = config_of(dev);
Duncan Laurieb40e4442013-12-09 14:38:57 -0800315 struct reg_script gfx_pipea_init[] = {
Duncan Laurieb40e4442013-12-09 14:38:57 -0800316 /* CONTROL */
317 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEA_REG(PP_CONTROL),
318 PP_CONTROL_UNLOCK | PP_CONTROL_EDP_FORCE_VDD),
Duncan Laurieb40e4442013-12-09 14:38:57 -0800319 /* POWER ON */
320 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEA_REG(PP_ON_DELAYS),
Jacob Garber767c4b22019-07-22 13:31:38 -0600321 ((u32)config->gpu_pipea_port_select << 30 |
322 (u32)config->gpu_pipea_power_on_delay << 16 |
323 (u32)config->gpu_pipea_light_on_delay)),
Duncan Laurieb40e4442013-12-09 14:38:57 -0800324 /* POWER OFF */
325 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEA_REG(PP_OFF_DELAYS),
Jacob Garber767c4b22019-07-22 13:31:38 -0600326 ((u32)config->gpu_pipea_power_off_delay << 16 |
327 (u32)config->gpu_pipea_light_off_delay)),
Duncan Laurieb40e4442013-12-09 14:38:57 -0800328 /* DIVISOR */
329 REG_RES_RMW32(PCI_BASE_ADDRESS_0, PIPEA_REG(PP_DIVISOR),
330 ~0x1f, config->gpu_pipea_power_cycle_delay),
Duncan Laurieb40e4442013-12-09 14:38:57 -0800331 REG_SCRIPT_END
332 };
333 struct reg_script gfx_pipeb_init[] = {
Duncan Laurieb40e4442013-12-09 14:38:57 -0800334 /* CONTROL */
335 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEB_REG(PP_CONTROL),
336 PP_CONTROL_UNLOCK | PP_CONTROL_EDP_FORCE_VDD),
Duncan Laurieb40e4442013-12-09 14:38:57 -0800337 /* POWER ON */
338 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEB_REG(PP_ON_DELAYS),
Jacob Garber767c4b22019-07-22 13:31:38 -0600339 ((u32)config->gpu_pipeb_port_select << 30 |
340 (u32)config->gpu_pipeb_power_on_delay << 16 |
341 (u32)config->gpu_pipeb_light_on_delay)),
Duncan Laurieb40e4442013-12-09 14:38:57 -0800342 /* POWER OFF */
343 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, PIPEB_REG(PP_OFF_DELAYS),
Jacob Garber767c4b22019-07-22 13:31:38 -0600344 ((u32)config->gpu_pipeb_power_off_delay << 16 |
345 (u32)config->gpu_pipeb_light_off_delay)),
Duncan Laurieb40e4442013-12-09 14:38:57 -0800346 /* DIVISOR */
347 REG_RES_RMW32(PCI_BASE_ADDRESS_0, PIPEB_REG(PP_DIVISOR),
348 ~0x1f, config->gpu_pipeb_power_cycle_delay),
Duncan Laurieb40e4442013-12-09 14:38:57 -0800349 REG_SCRIPT_END
350 };
351
352 if (config->gpu_pipea_port_select) {
353 printk(BIOS_INFO, "GFX: Initialize PIPEA\n");
Aaron Durbin616f3942013-12-10 17:12:44 -0800354 reg_script_run_on_dev(dev, gfx_pipea_init);
Aaron Durbin59e209a2014-04-24 11:35:28 -0500355 set_backlight_pwm(dev, PIPEA_REG(BACKLIGHT_CTL),
356 config->gpu_pipea_pwm_freq_hz);
Duncan Laurieb40e4442013-12-09 14:38:57 -0800357 }
358
359 if (config->gpu_pipeb_port_select) {
360 printk(BIOS_INFO, "GFX: Initialize PIPEB\n");
Aaron Durbin616f3942013-12-10 17:12:44 -0800361 reg_script_run_on_dev(dev, gfx_pipeb_init);
Aaron Durbin59e209a2014-04-24 11:35:28 -0500362 set_backlight_pwm(dev, PIPEB_REG(BACKLIGHT_CTL),
363 config->gpu_pipeb_pwm_freq_hz);
Duncan Laurieb40e4442013-12-09 14:38:57 -0800364 }
365}
366
Matt DeVillierbe33a672018-03-11 22:44:41 -0500367uintptr_t gma_get_gnvs_aslb(const void *gnvs)
368{
369 const global_nvs_t *gnvs_ptr = gnvs;
370 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
371}
372
373void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
374{
375 global_nvs_t *gnvs_ptr = gnvs;
376 if (gnvs_ptr)
377 gnvs_ptr->aslb = aslb;
378}
379
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200380static void gfx_init(struct device *dev)
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700381{
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700382 /* Pre VBIOS Init */
383 gfx_pre_vbios_init(dev);
Duncan Laurie223d4a4f2013-10-31 08:27:29 -0700384
385 /* Power Management Init */
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700386 gfx_pm_init(dev);
387
Duncan Laurieb40e4442013-12-09 14:38:57 -0800388 gfx_panel_setup(dev);
389
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700390 /* Run VBIOS */
391 pci_dev_init(dev);
392
393 /* Post VBIOS Init */
394 gfx_post_vbios_init(dev);
Matt DeVillierbe33a672018-03-11 22:44:41 -0500395
396 /* Restore opregion on S3 resume */
397 intel_gma_restore_opregion();
398}
399
Matt DeVillierc72f5f72018-01-28 18:42:10 -0600400static void gma_generate_ssdt(struct device *dev)
401{
402 const struct soc_intel_baytrail_config *chip = dev->chip_info;
403
404 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
405}
406
Matt DeVillierbe33a672018-03-11 22:44:41 -0500407static unsigned long
408gma_write_acpi_tables(struct device *const dev,
409 unsigned long current,
410 struct acpi_rsdp *const rsdp)
411{
412 igd_opregion_t *opregion = (igd_opregion_t *)current;
413 global_nvs_t *gnvs;
414
415 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
416 return current;
417
418 current += sizeof(igd_opregion_t);
419
420 /* GNVS has been already set up */
421 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
422 if (gnvs) {
423 /* IGD OpRegion Base Address */
424 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
425 } else {
426 printk(BIOS_ERR, "Error: GNVS table not found.\n");
427 }
428
429 current = acpi_align_current(current);
430 return current;
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700431}
432
433static struct device_operations gfx_device_ops = {
434 .read_resources = pci_dev_read_resources,
435 .set_resources = pci_dev_set_resources,
436 .enable_resources = pci_dev_enable_resources,
437 .init = gfx_init,
438 .ops_pci = &soc_pci_ops,
Matt DeVillierbe33a672018-03-11 22:44:41 -0500439 .write_acpi_tables = gma_write_acpi_tables,
Matt DeVillierc72f5f72018-01-28 18:42:10 -0600440 .acpi_fill_ssdt = gma_generate_ssdt,
Duncan Lauriee3f75f82013-10-28 15:49:34 -0700441};
442
443static const struct pci_driver gfx_driver __pci_driver = {
444 .ops = &gfx_device_ops,
445 .vendor = PCI_VENDOR_ID_INTEL,
446 .device = GFX_DEVID,
447};