blob: 6661a5f390c38f07e8a8883849cb58414f2a4cc2 [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
18#include <console/console.h>
19#include <device/device.h>
Kyösti Mälkki81830252016-06-25 11:40:00 +030020#include <arch/acpi.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000021#include <arch/io.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000022#include <delay.h>
Vladimir Serbinenko63acd222014-06-01 00:26:48 +020023#include <string.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000024#include <device/pci_def.h>
25#include <device/pci_ops.h>
Jonathan A. Kollasch25962832012-07-10 10:14:17 -050026#include <device/pci_ids.h>
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020027#include <arch/interrupt.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000028#include <ec/lenovo/pmh7/pmh7.h>
29#include <ec/acpi/ec.h>
Sven Schnelleffcd1432011-04-11 19:43:32 +000030#include <ec/lenovo/h8/h8.h>
Sven Schnelle8099cbf2011-04-04 10:57:17 +000031#include <northbridge/intel/i945/i945.h>
Sven Schnelled40d4f772011-06-12 15:08:58 +020032#include <pc80/mc146818rtc.h>
Sven Schnelle50270b82011-04-27 19:48:05 +000033#include "dock.h"
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020034#include <arch/x86/include/arch/acpigen.h>
Peter Stugeb6b3f792013-07-06 20:10:36 +020035#include <smbios.h>
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020036#include <drivers/intel/gma/int15.h>
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020037#include "drivers/lenovo/lenovo.h"
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020038
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020039#define PANEL INT15_5F35_CL_DISPLAY_DEFAULT
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020040
Arthur Heymanse1f0ac42016-05-19 16:02:38 +020041#define MWAIT_RES(state, sub_state) \
42 { \
43 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
44 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
45 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
46 { \
47 .resv = 0, \
48 }, \
49 .addrl = (((state) << 4) | (sub_state)), \
50 .addrh = 0, \
51 }
52
Stefan Reinauer4cc8c702012-04-27 21:34:16 +020053static acpi_cstate_t cst_entries[] = {
Arthur Heymanse1f0ac42016-05-19 16:02:38 +020054 {
55 .ctype = 1,
56 .latency = 1,
57 .power = 1000,
58 .resource = MWAIT_RES(0, 0),
59 },
60 {
61 .ctype = 2,
62 .latency = 1,
63 .power = 500,
64 .resource = MWAIT_RES(1, 0),
65 },
66 {
67 .ctype = 3,
68 .latency = 17,
69 .power = 250,
70 .resource = MWAIT_RES(2, 0),
71 },
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020072};
73
Stefan Reinauer4cc8c702012-04-27 21:34:16 +020074int get_cst_entries(acpi_cstate_t **entries)
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020075{
76 *entries = cst_entries;
77 return ARRAY_SIZE(cst_entries);
78}
Sven Schnellee2ca71e2011-02-14 20:02:47 +000079
Peter Stugeeac99162013-07-06 20:05:13 +020080static void mainboard_init(device_t dev)
Sven Schnelleb31eb3e2011-04-05 13:00:14 +000081{
Kyösti Mälkki81830252016-06-25 11:40:00 +030082 device_t idedev, sdhci_dev;
Sven Schnelleb31eb3e2011-04-05 13:00:14 +000083
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020084 ec_clr_bit(0x03, 2);
85
86 if (inb(0x164c) & 0x08) {
87 ec_set_bit(0x03, 2);
88 ec_write(0x0c, 0x88);
89 }
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020090
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020091 install_intel_vga_int15_handler(GMA_INT15_ACTIVE_LFP_INT_LVDS, GMA_INT15_PANEL_FIT_DEFAULT, PANEL, 3);
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020092
Sven Schnelle8099cbf2011-04-04 10:57:17 +000093 /* If we're resuming from suspend, blink suspend LED */
Kyösti Mälkki81830252016-06-25 11:40:00 +030094 if (acpi_is_wakeup_s3())
Sven Schnelle8099cbf2011-04-04 10:57:17 +000095 ec_write(0x0c, 0xc7);
Sven Schnelle50270b82011-04-27 19:48:05 +000096
97 idedev = dev_find_slot(0, PCI_DEVFN(0x1f,1));
98 if (idedev && idedev->chip_info && dock_ultrabay_device_present()) {
99 struct southbridge_intel_i82801gx_config *config = idedev->chip_info;
100 config->ide_enable_primary = 1;
101 /* enable Ultrabay power */
102 outb(inb(0x1628) | 0x01, 0x1628);
103 ec_write(0x0c, 0x84);
104 } else {
105 /* disable Ultrabay power */
106 outb(inb(0x1628) & ~0x01, 0x1628);
107 ec_write(0x0c, 0x04);
108 }
Sven Schnelled40d4f772011-06-12 15:08:58 +0200109
Jonathan A. Kollasch25962832012-07-10 10:14:17 -0500110 /* Set SDHCI write protect polarity "SDWPPol" */
111 sdhci_dev = dev_find_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C822, 0);
112 if (sdhci_dev) {
113 if (pci_read_config8(sdhci_dev, 0xfa) != 0x20) {
114 /* unlock */
115 pci_write_config8(sdhci_dev, 0xf9, 0xfc);
116 /* set SDWPPol, keep CLKRUNDis, SDPWRPol clear */
117 pci_write_config8(sdhci_dev, 0xfa, 0x20);
118 /* restore lock */
119 pci_write_config8(sdhci_dev, 0xf9, 0x00);
120 }
121 }
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000122}
123
Alexander Couzens5eea4582015-04-12 22:18:55 +0200124static void fill_ssdt(device_t device)
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200125{
126 drivers_lenovo_serial_ports_ssdt_generate("\\_SB.PCI0.LPCB", 1);
127}
128
Peter Stugeeac99162013-07-06 20:05:13 +0200129static void mainboard_enable(device_t dev)
130{
131 dev->ops->init = mainboard_init;
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200132 dev->ops->acpi_fill_ssdt_generator = fill_ssdt;
Peter Stugeeac99162013-07-06 20:05:13 +0200133}
134
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000135struct chip_operations mainboard_ops = {
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000136 .enable_dev = mainboard_enable,
137};