blob: b137aaac21ddb01ea3fea9281470f7aac42d6322 [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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010019 * Foundation, Inc.
Sven Schnellee2ca71e2011-02-14 20:02:47 +000020 */
21
22#include <console/console.h>
23#include <device/device.h>
24#include <arch/io.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000025#include <delay.h>
Vladimir Serbinenko63acd222014-06-01 00:26:48 +020026#include <string.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000027#include <device/pci_def.h>
28#include <device/pci_ops.h>
Jonathan A. Kollasch25962832012-07-10 10:14:17 -050029#include <device/pci_ids.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000030#include <arch/io.h>
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020031#include <arch/interrupt.h>
Sven Schnellee2ca71e2011-02-14 20:02:47 +000032#include <ec/lenovo/pmh7/pmh7.h>
33#include <ec/acpi/ec.h>
Sven Schnelleffcd1432011-04-11 19:43:32 +000034#include <ec/lenovo/h8/h8.h>
Sven Schnelle8099cbf2011-04-04 10:57:17 +000035#include <northbridge/intel/i945/i945.h>
Sven Schnelled40d4f772011-06-12 15:08:58 +020036#include <pc80/mc146818rtc.h>
Sven Schnelle50270b82011-04-27 19:48:05 +000037#include "dock.h"
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020038#include <arch/x86/include/arch/acpigen.h>
Peter Stugeb6b3f792013-07-06 20:10:36 +020039#include <smbios.h>
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020040#include <drivers/intel/gma/int15.h>
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020041#include "drivers/lenovo/lenovo.h"
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020042
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020043#define PANEL INT15_5F35_CL_DISPLAY_DEFAULT
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020044
Stefan Reinauer4cc8c702012-04-27 21:34:16 +020045static acpi_cstate_t cst_entries[] = {
46 { 1, 1, 1000, { 0x7f, 1, 2, { 0 }, 1, 0 } },
47 { 2, 1, 500, { 0x01, 8, 0, { 0 }, DEFAULT_PMBASE + LV2, 0 } },
48 { 2, 17, 250, { 0x01, 8, 0, { 0 }, DEFAULT_PMBASE + LV3, 0 } },
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020049};
50
Stefan Reinauer4cc8c702012-04-27 21:34:16 +020051int get_cst_entries(acpi_cstate_t **entries)
Sven Schnelle6eb8bef2011-10-23 16:57:50 +020052{
53 *entries = cst_entries;
54 return ARRAY_SIZE(cst_entries);
55}
Sven Schnellee2ca71e2011-02-14 20:02:47 +000056
Peter Stugeeac99162013-07-06 20:05:13 +020057static void mainboard_init(device_t dev)
Sven Schnelleb31eb3e2011-04-05 13:00:14 +000058{
Jonathan A. Kollasch25962832012-07-10 10:14:17 -050059 device_t dev0, idedev, sdhci_dev;
Sven Schnelleb31eb3e2011-04-05 13:00:14 +000060
Sven Schnelle8d0b86c2011-07-11 18:36:16 +020061 ec_clr_bit(0x03, 2);
62
63 if (inb(0x164c) & 0x08) {
64 ec_set_bit(0x03, 2);
65 ec_write(0x0c, 0x88);
66 }
Denis 'GNUtoo' Carikli4062f172013-05-21 03:13:46 +020067
Vladimir Serbinenkoa2a906e2014-09-01 01:41:37 +020068 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 +020069
Sven Schnelle8099cbf2011-04-04 10:57:17 +000070 /* If we're resuming from suspend, blink suspend LED */
71 dev0 = dev_find_slot(0, PCI_DEVFN(0,0));
Sven Schnelled8c68a92011-06-15 09:26:34 +020072 if (dev0 && pci_read_config32(dev0, SKPAD) == SKPAD_ACPI_S3_MAGIC)
Sven Schnelle8099cbf2011-04-04 10:57:17 +000073 ec_write(0x0c, 0xc7);
Sven Schnelle50270b82011-04-27 19:48:05 +000074
75 idedev = dev_find_slot(0, PCI_DEVFN(0x1f,1));
76 if (idedev && idedev->chip_info && dock_ultrabay_device_present()) {
77 struct southbridge_intel_i82801gx_config *config = idedev->chip_info;
78 config->ide_enable_primary = 1;
79 /* enable Ultrabay power */
80 outb(inb(0x1628) | 0x01, 0x1628);
81 ec_write(0x0c, 0x84);
82 } else {
83 /* disable Ultrabay power */
84 outb(inb(0x1628) & ~0x01, 0x1628);
85 ec_write(0x0c, 0x04);
86 }
Sven Schnelled40d4f772011-06-12 15:08:58 +020087
Jonathan A. Kollasch25962832012-07-10 10:14:17 -050088 /* Set SDHCI write protect polarity "SDWPPol" */
89 sdhci_dev = dev_find_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C822, 0);
90 if (sdhci_dev) {
91 if (pci_read_config8(sdhci_dev, 0xfa) != 0x20) {
92 /* unlock */
93 pci_write_config8(sdhci_dev, 0xf9, 0xfc);
94 /* set SDWPPol, keep CLKRUNDis, SDPWRPol clear */
95 pci_write_config8(sdhci_dev, 0xfa, 0x20);
96 /* restore lock */
97 pci_write_config8(sdhci_dev, 0xf9, 0x00);
98 }
99 }
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000100}
101
Alexander Couzens5eea4582015-04-12 22:18:55 +0200102static void fill_ssdt(device_t device)
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200103{
104 drivers_lenovo_serial_ports_ssdt_generate("\\_SB.PCI0.LPCB", 1);
105}
106
Peter Stugeeac99162013-07-06 20:05:13 +0200107static void mainboard_enable(device_t dev)
108{
109 dev->ops->init = mainboard_init;
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200110 dev->ops->acpi_fill_ssdt_generator = fill_ssdt;
Peter Stugeeac99162013-07-06 20:05:13 +0200111}
112
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000113struct chip_operations mainboard_ops = {
Sven Schnellee2ca71e2011-02-14 20:02:47 +0000114 .enable_dev = mainboard_enable,
115};