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. |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #define __SIMPLE_DEVICE__ |
| 19 | #include <console/console.h> |
| 20 | #include <arch/io.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <delay.h> |
| 24 | #include "dock.h" |
| 25 | #include "southbridge/intel/ibexpeak/pch.h" |
| 26 | #include "ec/lenovo/h8/h8.h" |
| 27 | #include <ec/acpi/ec.h> |
| 28 | |
| 29 | void h8_mainboard_init_dock (void) |
| 30 | { |
| 31 | if (dock_present()) { |
| 32 | printk(BIOS_DEBUG, "dock is connected\n"); |
| 33 | dock_connect(); |
| 34 | } else |
| 35 | printk(BIOS_DEBUG, "dock is not connected\n"); |
| 36 | } |
| 37 | |
| 38 | void dock_connect(void) |
| 39 | { |
Vladimir Serbinenko | f319ae4 | 2014-08-19 00:48:39 +0200 | [diff] [blame] | 40 | u16 gpiobase = pci_read_config16(PCH_LPC_DEV, GPIO_BASE) & 0xfffc; |
| 41 | |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 42 | ec_set_bit(0x02, 0); |
| 43 | ec_set_bit(0x1a, 0); |
| 44 | ec_set_bit(0xfe, 4); |
Vladimir Serbinenko | f319ae4 | 2014-08-19 00:48:39 +0200 | [diff] [blame] | 45 | |
| 46 | outl(inl(gpiobase + 0x0c) | (1 << 28), gpiobase + 0x0c); |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void dock_disconnect(void) |
| 50 | { |
Vladimir Serbinenko | f319ae4 | 2014-08-19 00:48:39 +0200 | [diff] [blame] | 51 | u16 gpiobase = pci_read_config16(PCH_LPC_DEV, GPIO_BASE) & 0xfffc; |
| 52 | |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 53 | ec_clr_bit(0x02, 0); |
| 54 | ec_clr_bit(0x1a, 0); |
| 55 | ec_clr_bit(0xfe, 4); |
Vladimir Serbinenko | f319ae4 | 2014-08-19 00:48:39 +0200 | [diff] [blame] | 56 | |
| 57 | outl(inl(gpiobase + 0x0c) & ~(1 << 28), gpiobase + 0x0c); |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | int dock_present(void) |
| 61 | { |
| 62 | u16 gpiobase = pci_read_config16(PCH_LPC_DEV, GPIO_BASE) & 0xfffc; |
| 63 | u8 st = inb(gpiobase + 0x0c); |
| 64 | |
Vladimir Serbinenko | c5e040b | 2014-08-18 23:54:54 +0200 | [diff] [blame] | 65 | return ((st >> 3) & 7) != 7; |
Vladimir Serbinenko | 9bf05de | 2013-11-14 19:11:19 +0100 | [diff] [blame] | 66 | } |