Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Sven Schnelle <svens@stackframe.org> |
| 5 | * Copyright (C) 2013 Vladimir Serbinenko <phcoder@gmail.com> |
| 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 |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 20 | * MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | #define __SIMPLE_DEVICE__ |
| 24 | #include <console/console.h> |
| 25 | #include <arch/io.h> |
| 26 | #include <device/device.h> |
| 27 | #include <device/pci.h> |
| 28 | #include <delay.h> |
| 29 | #include "dock.h" |
| 30 | #include "southbridge/intel/ibexpeak/pch.h" |
| 31 | #include "ec/lenovo/h8/h8.h" |
| 32 | #include <ec/acpi/ec.h> |
| 33 | |
| 34 | void h8_mainboard_init_dock (void) |
| 35 | { |
| 36 | if (dock_present()) { |
| 37 | printk(BIOS_DEBUG, "dock is connected\n"); |
| 38 | dock_connect(); |
| 39 | } else |
| 40 | printk(BIOS_DEBUG, "dock is not connected\n"); |
| 41 | } |
| 42 | |
| 43 | void dock_connect(void) |
| 44 | { |
Vladimir Serbinenko | f319ae4 | 2014-08-19 00:48:39 +0200 | [diff] [blame] | 45 | u16 gpiobase = pci_read_config16(PCH_LPC_DEV, GPIO_BASE) & 0xfffc; |
| 46 | |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 47 | ec_set_bit(0x02, 0); |
| 48 | ec_set_bit(0x1a, 0); |
| 49 | ec_set_bit(0xfe, 4); |
Vladimir Serbinenko | f319ae4 | 2014-08-19 00:48:39 +0200 | [diff] [blame] | 50 | |
| 51 | outl(inl(gpiobase + 0x0c) | (1 << 28), gpiobase + 0x0c); |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void dock_disconnect(void) |
| 55 | { |
Vladimir Serbinenko | f319ae4 | 2014-08-19 00:48:39 +0200 | [diff] [blame] | 56 | u16 gpiobase = pci_read_config16(PCH_LPC_DEV, GPIO_BASE) & 0xfffc; |
| 57 | |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 58 | ec_clr_bit(0x02, 0); |
| 59 | ec_clr_bit(0x1a, 0); |
| 60 | ec_clr_bit(0xfe, 4); |
Vladimir Serbinenko | f319ae4 | 2014-08-19 00:48:39 +0200 | [diff] [blame] | 61 | |
| 62 | outl(inl(gpiobase + 0x0c) & ~(1 << 28), gpiobase + 0x0c); |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | int dock_present(void) |
| 66 | { |
| 67 | u16 gpiobase = pci_read_config16(PCH_LPC_DEV, GPIO_BASE) & 0xfffc; |
| 68 | u8 st = inb(gpiobase + 0x0c); |
| 69 | |
Vladimir Serbinenko | c5e040b | 2014-08-18 23:54:54 +0200 | [diff] [blame^] | 70 | return ((st >> 3) & 7) != 7; |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 71 | } |