blob: ab5b2c40bf2b8d3214b277967ebb2070b56b9c9a [file] [log] [blame]
Florian Zumbiehl21385562011-11-01 20:19:40 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
Florian Zumbiehl6cdf5a92011-11-01 20:19:41 +01005 * Copyright (C) 2010 Tobias Diedrich <ranma+coreboot@tdiedrich.de>
Florian Zumbiehl21385562011-11-01 20:19:40 +01006 *
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.
Florian Zumbiehl21385562011-11-01 20:19:40 +010015 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
Florian Zumbiehl6cdf5a92011-11-01 20:19:41 +010021#include <arch/io.h>
22#include "southbridge/via/vt8237r/vt8237r.h"
Florian Zumbiehl21385562011-11-01 20:19:40 +010023
Florian Zumbiehl6cdf5a92011-11-01 20:19:41 +010024u32 vt8237_ide_80pin_detect(struct device *dev)
25{
26 device_t lpc_dev;
27 u16 acpi_io_base;
28 u32 gpio_in;
29 u32 res;
30
31 lpc_dev = dev_find_device(PCI_VENDOR_ID_VIA,
32 PCI_DEVICE_ID_VIA_VT8237R_LPC, 0);
33 if (!lpc_dev)
34 return 0;
35
36 acpi_io_base = pci_read_config16(lpc_dev, 0x88) & ~1;
37 if (!acpi_io_base)
38 return 0;
39
40 /* select function GPIO29 for pin AB9 */
41 pci_write_config8(lpc_dev, 0xe5, pci_read_config8(lpc_dev, 0xe5) | 0x08);
42
43 gpio_in = inl(acpi_io_base + 0x48);
44 /* bit 29 for primary port, clear if unconnected or 80-pin cable */
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +020045 res = gpio_in & (1 << 29) ? 0 : VT8237R_IDE0_80PIN_CABLE;
Florian Zumbiehl6cdf5a92011-11-01 20:19:41 +010046 /* bit 8 for secondary port, clear if unconnected or 80-pin cable */
Elyes HAOUAS6350a2e2016-09-16 20:49:38 +020047 res |= gpio_in & (1 << 8) ? 0 : VT8237R_IDE1_80PIN_CABLE;
Florian Zumbiehl6cdf5a92011-11-01 20:19:41 +010048
49 printk(BIOS_INFO, "Cable on %s PATA port: %d pin\n", "primary",
50 res & VT8237R_IDE0_80PIN_CABLE ? 80 : 40);
51 printk(BIOS_INFO, "Cable on %s PATA port: %d pin\n", "secondary",
52 res & VT8237R_IDE1_80PIN_CABLE ? 80 : 40);
53
54 return res;
55}