adding support for the Asus K8V-X
[coreboot.git] / src / mainboard / asus / k8v-x / mainboard.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
5  * Copyright (C) 2010 Tobias Diedrich <ranma+coreboot@tdiedrich.de>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <console/console.h>
22 #include <device/device.h>
23 #include <device/pci.h>
24 #include <device/pci_ids.h>
25 #include <arch/io.h>
26 #include "southbridge/via/vt8237r/vt8237r.h"
27 #include "chip.h"
28
29 u32 vt8237_ide_80pin_detect(struct device *dev)
30 {
31         device_t lpc_dev;
32         u16 acpi_io_base;
33         u32 gpio_in;
34         u32 res;
35
36         lpc_dev = dev_find_device(PCI_VENDOR_ID_VIA,
37                                 PCI_DEVICE_ID_VIA_VT8237R_LPC, 0);
38         if (!lpc_dev)
39                 return 0;
40
41         acpi_io_base = pci_read_config16(lpc_dev, 0x88) & ~1;
42         if (!acpi_io_base)
43                 return 0;
44
45         /* select function GPIO29 for pin AB9 */
46         pci_write_config8(lpc_dev, 0xe5, pci_read_config8(lpc_dev, 0xe5) | 0x08);
47
48         gpio_in = inl(acpi_io_base + 0x48);
49         /* bit 29 for primary port, clear if unconnected or 80-pin cable */
50         res  = gpio_in & (1<<29) ? 0 : VT8237R_IDE0_80PIN_CABLE;
51         /* bit 8 for secondary port, clear if unconnected or 80-pin cable */
52         res |= gpio_in & (1<<8) ? 0 : VT8237R_IDE1_80PIN_CABLE;
53
54         printk(BIOS_INFO, "Cable on %s PATA port: %d pin\n", "primary",
55                 res & VT8237R_IDE0_80PIN_CABLE ? 80 : 40);
56         printk(BIOS_INFO, "Cable on %s PATA port: %d pin\n", "secondary",
57                 res & VT8237R_IDE1_80PIN_CABLE ? 80 : 40);
58
59         return res;
60 }
61
62 struct chip_operations mainboard_ops = {
63         CHIP_NAME("ASUS K8V-X Mainboard")
64 };