blob: 839fdabd72c4192e5d8af3df63be21768f5074e0 [file] [log] [blame]
Sven Schnellee2ca71e2011-02-14 20:02:47 +00001/*
2 * This file is part of the coreboot project.
3 *
Sven Schnellee2ca71e2011-02-14 20:02:47 +00004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
8 * the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Sven Schnellee2ca71e2011-02-14 20:02:47 +000014 */
15
Sven Schnellee2ca71e2011-02-14 20:02:47 +000016#include <device/pci_def.h>
Jonathan A. Kollasch25962832012-07-10 10:14:17 -050017#include <device/pci_ids.h>
Patrick Rudolphc670a412017-04-28 17:28:32 +020018#include <device/device.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020019#include <device/pci_ops.h>
Patrick Rudolphc670a412017-04-28 17:28:32 +020020#include <arch/io.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000021#include <ec/acpi/ec.h>
Sven Schnelle8099cbf2011-04-04 10:57:17 +000022#include <northbridge/intel/i945/i945.h>
Arthur Heymans742df5a2019-06-03 16:24:41 +020023#include <southbridge/intel/i82801gx/chip.h>
Sven Schnelle50270b82011-04-27 19:48:05 +000024#include "dock.h"
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020025#include <drivers/intel/gma/int15.h>
Patrick Rudolphc670a412017-04-28 17:28:32 +020026#include <drivers/lenovo/lenovo.h>
27#include <arch/acpigen.h>
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020028
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020029#define PANEL INT15_5F35_CL_DISPLAY_DEFAULT
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020030
Arthur Heymanse1f0ac42016-05-19 16:02:38 +020031#define MWAIT_RES(state, sub_state) \
32 { \
33 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
34 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
35 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +010036 .access_size = 0, \
Arthur Heymanse1f0ac42016-05-19 16:02:38 +020037 .addrl = (((state) << 4) | (sub_state)), \
38 .addrh = 0, \
39 }
40
Stefan Reinauer4cc8c702012-04-27 21:34:16 +020041static acpi_cstate_t cst_entries[] = {
Arthur Heymanse1f0ac42016-05-19 16:02:38 +020042 {
43 .ctype = 1,
44 .latency = 1,
45 .power = 1000,
46 .resource = MWAIT_RES(0, 0),
47 },
48 {
49 .ctype = 2,
50 .latency = 1,
51 .power = 500,
52 .resource = MWAIT_RES(1, 0),
53 },
54 {
55 .ctype = 3,
56 .latency = 17,
57 .power = 250,
58 .resource = MWAIT_RES(2, 0),
59 },
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020060};
61
Stefan Reinauer4cc8c702012-04-27 21:34:16 +020062int get_cst_entries(acpi_cstate_t **entries)
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020063{
64 *entries = cst_entries;
65 return ARRAY_SIZE(cst_entries);
66}
Sven Schnellee2ca71e2011-02-14 20:02:47 +000067
Elyes HAOUAS64b759e2018-05-05 09:11:32 +020068static void mainboard_init(struct device *dev)
Sven Schnelleb31eb3e2011-04-05 13:00:14 +000069{
Elyes HAOUAS64b759e2018-05-05 09:11:32 +020070 struct device *idedev, *sdhci_dev;
Sven Schnelleb31eb3e2011-04-05 13:00:14 +000071
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020072 ec_clr_bit(0x03, 2);
73
74 if (inb(0x164c) & 0x08) {
75 ec_set_bit(0x03, 2);
76 ec_write(0x0c, 0x88);
77 }
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020078
Patrick Rudolphc670a412017-04-28 17:28:32 +020079 install_intel_vga_int15_handler(GMA_INT15_ACTIVE_LFP_INT_LVDS,
80 GMA_INT15_PANEL_FIT_DEFAULT,
81 PANEL, 3);
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020082
Sven Schnelle8099cbf2011-04-04 10:57:17 +000083 /* If we're resuming from suspend, blink suspend LED */
Kyösti Mälkki81830252016-06-25 11:40:00 +030084 if (acpi_is_wakeup_s3())
Sven Schnelle8099cbf2011-04-04 10:57:17 +000085 ec_write(0x0c, 0xc7);
Sven Schnelle50270b82011-04-27 19:48:05 +000086
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030087 idedev = pcidev_on_root(0x1f, 1);
Sven Schnelle50270b82011-04-27 19:48:05 +000088 if (idedev && idedev->chip_info && dock_ultrabay_device_present()) {
89 struct southbridge_intel_i82801gx_config *config = idedev->chip_info;
90 config->ide_enable_primary = 1;
91 /* enable Ultrabay power */
92 outb(inb(0x1628) | 0x01, 0x1628);
93 ec_write(0x0c, 0x84);
94 } else {
95 /* disable Ultrabay power */
96 outb(inb(0x1628) & ~0x01, 0x1628);
97 ec_write(0x0c, 0x04);
98 }
Sven Schnelled40d4f772011-06-12 15:08:58 +020099
Jonathan A. Kollasch25962832012-07-10 10:14:17 -0500100 /* Set SDHCI write protect polarity "SDWPPol" */
101 sdhci_dev = dev_find_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C822, 0);
102 if (sdhci_dev) {
103 if (pci_read_config8(sdhci_dev, 0xfa) != 0x20) {
104 /* unlock */
105 pci_write_config8(sdhci_dev, 0xf9, 0xfc);
106 /* set SDWPPol, keep CLKRUNDis, SDPWRPol clear */
107 pci_write_config8(sdhci_dev, 0xfa, 0x20);
108 /* restore lock */
109 pci_write_config8(sdhci_dev, 0xf9, 0x00);
110 }
111 }
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000112}
113
Elyes HAOUAS64b759e2018-05-05 09:11:32 +0200114static void fill_ssdt(struct device *device)
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200115{
116 drivers_lenovo_serial_ports_ssdt_generate("\\_SB.PCI0.LPCB", 1);
117}
118
Elyes HAOUAS64b759e2018-05-05 09:11:32 +0200119static void mainboard_enable(struct device *dev)
Peter Stugeeac99162013-07-06 20:05:13 +0200120{
121 dev->ops->init = mainboard_init;
Nico Huber68680dd2020-03-31 17:34:52 +0200122 dev->ops->acpi_fill_ssdt = fill_ssdt;
Peter Stugeeac99162013-07-06 20:05:13 +0200123}
124
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000125struct chip_operations mainboard_ops = {
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000126 .enable_dev = mainboard_enable,
127};