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