blob: ca836212ddf80b4b07b014cdc8448ba8024a6946 [file] [log] [blame]
Tobias Diedrich4e6305f2010-11-07 20:08:45 +00001/*
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.
Tobias Diedrich4e6305f2010-11-07 20:08:45 +000014 */
15
Tobias Diedrich5d72eb52010-11-14 14:17:29 +000016#include <arch/io.h>
Tobias Diedrich4e6305f2010-11-07 20:08:45 +000017#include <device/device.h>
Tobias Diedrich5d72eb52010-11-14 14:17:29 +000018#include <device/pci.h>
19#include <device/pci_ids.h>
20#include <console/console.h>
21#include "southbridge/via/vt8237r/vt8237r.h"
Tobias Diedrich4e6305f2010-11-07 20:08:45 +000022
Tobias Diedrich5d72eb52010-11-14 14:17:29 +000023u32 vt8237_ide_80pin_detect(struct device *dev)
24{
25 device_t lpc_dev;
26 u16 acpi_io_base;
27 u32 gpio_in;
28 u32 res;
29
30 lpc_dev = dev_find_device(PCI_VENDOR_ID_VIA,
31 PCI_DEVICE_ID_VIA_VT8237A_LPC, 0);
32 if (!lpc_dev)
Rudolf Marek727edb02010-11-14 14:39:29 +000033 return 0;
Tobias Diedrich5d72eb52010-11-14 14:17:29 +000034
Florian Zumbiehlf8ed9032011-11-01 20:17:13 +010035 acpi_io_base = pci_read_config16(lpc_dev, 0x88) & ~1;
36 if (!acpi_io_base)
Rudolf Marek727edb02010-11-14 14:39:29 +000037 return 0;
Tobias Diedrich5d72eb52010-11-14 14:17:29 +000038
39 gpio_in = inl(acpi_io_base + 0x48);
40 /* bit 9 for primary port, clear if unconnected or 80-pin cable */
41 res = gpio_in & (1<<9) ? 0 : VT8237R_IDE0_80PIN_CABLE;
42 /* bit 4 for secondary port, clear if unconnected or 80-pin cable */
43 res |= gpio_in & (1<<4) ? 0 : VT8237R_IDE1_80PIN_CABLE;
44
45 printk(BIOS_INFO, "Cable on %s PATA port: %d pin\n", "primary",
Florian Zumbiehlf8ed9032011-11-01 20:17:13 +010046 res & VT8237R_IDE0_80PIN_CABLE ? 80 : 40);
Tobias Diedrich5d72eb52010-11-14 14:17:29 +000047 printk(BIOS_INFO, "Cable on %s PATA port: %d pin\n", "secondary",
Florian Zumbiehlf8ed9032011-11-01 20:17:13 +010048 res & VT8237R_IDE1_80PIN_CABLE ? 80 : 40);
Tobias Diedrich5d72eb52010-11-14 14:17:29 +000049
50 return res;
51}