blob: 81175ec39b9a0b316cc12870e65d657ad7697c32 [file] [log] [blame]
Sven Schnellee2ca71e2011-02-14 20:02:47 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
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.
Sven Schnellee2ca71e2011-02-14 20:02:47 +000016 */
17
Sven Schnellee2ca71e2011-02-14 20:02:47 +000018#include <device/pci_def.h>
Jonathan A. Kollasch25962832012-07-10 10:14:17 -050019#include <device/pci_ids.h>
Patrick Rudolphc670a412017-04-28 17:28:32 +020020#include <device/device.h>
21#include <arch/io.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000022#include <ec/acpi/ec.h>
Sven Schnelle8099cbf2011-04-04 10:57:17 +000023#include <northbridge/intel/i945/i945.h>
Sven Schnelled40d4f772011-06-12 15:08:58 +020024#include <pc80/mc146818rtc.h>
Sven Schnelle50270b82011-04-27 19:48:05 +000025#include "dock.h"
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020026#include <drivers/intel/gma/int15.h>
Patrick Rudolphc670a412017-04-28 17:28:32 +020027#include <drivers/lenovo/lenovo.h>
28#include <arch/acpigen.h>
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020029
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020030#define PANEL INT15_5F35_CL_DISPLAY_DEFAULT
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020031
Arthur Heymanse1f0ac42016-05-19 16:02:38 +020032#define MWAIT_RES(state, sub_state) \
33 { \
34 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
35 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
36 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
37 { \
38 .resv = 0, \
39 }, \
40 .addrl = (((state) << 4) | (sub_state)), \
41 .addrh = 0, \
42 }
43
Stefan Reinauer4cc8c702012-04-27 21:34:16 +020044static acpi_cstate_t cst_entries[] = {
Arthur Heymanse1f0ac42016-05-19 16:02:38 +020045 {
46 .ctype = 1,
47 .latency = 1,
48 .power = 1000,
49 .resource = MWAIT_RES(0, 0),
50 },
51 {
52 .ctype = 2,
53 .latency = 1,
54 .power = 500,
55 .resource = MWAIT_RES(1, 0),
56 },
57 {
58 .ctype = 3,
59 .latency = 17,
60 .power = 250,
61 .resource = MWAIT_RES(2, 0),
62 },
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020063};
64
Stefan Reinauer4cc8c702012-04-27 21:34:16 +020065int get_cst_entries(acpi_cstate_t **entries)
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020066{
67 *entries = cst_entries;
68 return ARRAY_SIZE(cst_entries);
69}
Sven Schnellee2ca71e2011-02-14 20:02:47 +000070
Peter Stugeeac99162013-07-06 20:05:13 +020071static void mainboard_init(device_t dev)
Sven Schnelleb31eb3e2011-04-05 13:00:14 +000072{
Kyösti Mälkki81830252016-06-25 11:40:00 +030073 device_t idedev, sdhci_dev;
Sven Schnelleb31eb3e2011-04-05 13:00:14 +000074
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020075 ec_clr_bit(0x03, 2);
76
77 if (inb(0x164c) & 0x08) {
78 ec_set_bit(0x03, 2);
79 ec_write(0x0c, 0x88);
80 }
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020081
Patrick Rudolphc670a412017-04-28 17:28:32 +020082 install_intel_vga_int15_handler(GMA_INT15_ACTIVE_LFP_INT_LVDS,
83 GMA_INT15_PANEL_FIT_DEFAULT,
84 PANEL, 3);
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020085
Sven Schnelle8099cbf2011-04-04 10:57:17 +000086 /* If we're resuming from suspend, blink suspend LED */
Kyösti Mälkki81830252016-06-25 11:40:00 +030087 if (acpi_is_wakeup_s3())
Sven Schnelle8099cbf2011-04-04 10:57:17 +000088 ec_write(0x0c, 0xc7);
Sven Schnelle50270b82011-04-27 19:48:05 +000089
90 idedev = dev_find_slot(0, PCI_DEVFN(0x1f,1));
91 if (idedev && idedev->chip_info && dock_ultrabay_device_present()) {
92 struct southbridge_intel_i82801gx_config *config = idedev->chip_info;
93 config->ide_enable_primary = 1;
94 /* enable Ultrabay power */
95 outb(inb(0x1628) | 0x01, 0x1628);
96 ec_write(0x0c, 0x84);
97 } else {
98 /* disable Ultrabay power */
99 outb(inb(0x1628) & ~0x01, 0x1628);
100 ec_write(0x0c, 0x04);
101 }
Sven Schnelled40d4f772011-06-12 15:08:58 +0200102
Jonathan A. Kollasch25962832012-07-10 10:14:17 -0500103 /* Set SDHCI write protect polarity "SDWPPol" */
104 sdhci_dev = dev_find_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C822, 0);
105 if (sdhci_dev) {
106 if (pci_read_config8(sdhci_dev, 0xfa) != 0x20) {
107 /* unlock */
108 pci_write_config8(sdhci_dev, 0xf9, 0xfc);
109 /* set SDWPPol, keep CLKRUNDis, SDPWRPol clear */
110 pci_write_config8(sdhci_dev, 0xfa, 0x20);
111 /* restore lock */
112 pci_write_config8(sdhci_dev, 0xf9, 0x00);
113 }
114 }
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000115}
116
Alexander Couzens5eea4582015-04-12 22:18:55 +0200117static void fill_ssdt(device_t device)
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200118{
119 drivers_lenovo_serial_ports_ssdt_generate("\\_SB.PCI0.LPCB", 1);
120}
121
Peter Stugeeac99162013-07-06 20:05:13 +0200122static void mainboard_enable(device_t dev)
123{
124 dev->ops->init = mainboard_init;
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200125 dev->ops->acpi_fill_ssdt_generator = fill_ssdt;
Peter Stugeeac99162013-07-06 20:05:13 +0200126}
127
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000128struct chip_operations mainboard_ops = {
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000129 .enable_dev = mainboard_enable,
130};