blob: 18348e367e8781806ffffb6c201045650e05eab4 [file] [log] [blame]
Alexandru Gagniucc3640192015-12-15 16:06:15 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015-2016 Intel Corp.
5 * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.)
6 *
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; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
Andrey Petrov868679f2016-05-12 19:11:48 -070018#include <arch/acpi.h>
19#include <arch/acpigen.h>
Alexandru Gagniucc3640192015-12-15 16:06:15 -080020#include <console/console.h>
21#include <fsp/util.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
Naresh G Solanki16e9d452016-09-08 22:27:04 +053025#include <soc/pci_devs.h>
Alexandru Gagniucc3640192015-12-15 16:06:15 -080026#include <soc/pci_ids.h>
Andrey Petrov868679f2016-05-12 19:11:48 -070027#include <soc/intel/common/opregion.h>
Alexandru Gagniucc3640192015-12-15 16:06:15 -080028
Naresh G Solanki16e9d452016-09-08 22:27:04 +053029uintptr_t fsp_soc_get_igd_bar(void)
Alexandru Gagniucc3640192015-12-15 16:06:15 -080030{
Naresh G Solanki16e9d452016-09-08 22:27:04 +053031 return find_resource(IGD_DEV, PCI_BASE_ADDRESS_2)->base;
Alexandru Gagniucc3640192015-12-15 16:06:15 -080032}
33
34static void igd_set_resources(struct device *dev)
35{
Alexandru Gagniucc3640192015-12-15 16:06:15 -080036 pci_dev_set_resources(dev);
37}
38
Andrey Petrov868679f2016-05-12 19:11:48 -070039static unsigned long igd_write_opregion(device_t dev, unsigned long current,
40 struct acpi_rsdp *rsdp)
41{
42 igd_opregion_t *opregion;
43 uint16_t reg16;
44
45 printk(BIOS_DEBUG, "ACPI: * IGD OpRegion\n");
46 opregion = (igd_opregion_t *)current;
47
48 if (!init_igd_opregion(opregion))
49 return current;
50
51 current += sizeof(igd_opregion_t);
52
53 /* TODO Initialize Mailbox 3 */
54 opregion->mailbox3.bclp = IGD_BACKLIGHT_BRIGHTNESS;
55 opregion->mailbox3.pfit = IGD_FIELD_VALID | IGD_PFIT_STRETCH;
56 opregion->mailbox3.pcft = 0; /* should be (IMON << 1) & 0x3e */
57 opregion->mailbox3.cblv = IGD_FIELD_VALID | IGD_INITIAL_BRIGHTNESS;
58 opregion->mailbox3.bclm[0] = IGD_WORD_FIELD_VALID + 0x0000;
59 opregion->mailbox3.bclm[1] = IGD_WORD_FIELD_VALID + 0x0a19;
60 opregion->mailbox3.bclm[2] = IGD_WORD_FIELD_VALID + 0x1433;
61 opregion->mailbox3.bclm[3] = IGD_WORD_FIELD_VALID + 0x1e4c;
62 opregion->mailbox3.bclm[4] = IGD_WORD_FIELD_VALID + 0x2866;
63 opregion->mailbox3.bclm[5] = IGD_WORD_FIELD_VALID + 0x327f;
64 opregion->mailbox3.bclm[6] = IGD_WORD_FIELD_VALID + 0x3c99;
65 opregion->mailbox3.bclm[7] = IGD_WORD_FIELD_VALID + 0x46b2;
66 opregion->mailbox3.bclm[8] = IGD_WORD_FIELD_VALID + 0x50cc;
67 opregion->mailbox3.bclm[9] = IGD_WORD_FIELD_VALID + 0x5ae5;
68 opregion->mailbox3.bclm[10] = IGD_WORD_FIELD_VALID + 0x64ff;
69
70 /*
71 * TODO This needs to happen in S3 resume, too.
72 * Maybe it should move to the finalize handler.
73 */
74
75 pci_write_config32(dev, ASLS, (uintptr_t)opregion);
76 reg16 = pci_read_config16(dev, SWSCI);
77 reg16 &= ~(1 << 0);
78 reg16 |= (1 << 15);
79 pci_write_config16(dev, SWSCI, reg16);
80
81 return acpi_align_current(current);
82}
83
Alexandru Gagniucc3640192015-12-15 16:06:15 -080084static const struct device_operations igd_ops = {
85 .read_resources = pci_dev_read_resources,
86 .set_resources = igd_set_resources,
87 .enable_resources = pci_dev_enable_resources,
88 .init = pci_dev_init,
Andrey Petrov868679f2016-05-12 19:11:48 -070089 .write_acpi_tables = igd_write_opregion,
Alexandru Gagniucc3640192015-12-15 16:06:15 -080090 .enable = DEVICE_NOOP
91};
92
Abhay Kumar67870f52016-07-20 17:48:55 -070093static const unsigned short pci_device_ids[] = {
94 PCI_DEVICE_ID_APOLLOLAKE_IGD_HD_505,
95 PCI_DEVICE_ID_APOLLOLAKE_IGD_HD_500,
96 0,
97};
98
Alexandru Gagniucc3640192015-12-15 16:06:15 -080099static const struct pci_driver integrated_graphics_driver __pci_driver = {
Lee Leahy320b7ca2017-03-09 09:42:48 -0800100 .ops = &igd_ops,
101 .vendor = PCI_VENDOR_ID_INTEL,
102 .devices = pci_device_ids,
Alexandru Gagniucc3640192015-12-15 16:06:15 -0800103};