Florian Zumbiehl | 2138556 | 2011-11-01 20:19:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz> |
Florian Zumbiehl | 6cdf5a9 | 2011-11-01 20:19:41 +0100 | [diff] [blame] | 5 | * Copyright (C) 2010 Tobias Diedrich <ranma+coreboot@tdiedrich.de> |
Florian Zumbiehl | 2138556 | 2011-11-01 20:19:40 +0100 | [diff] [blame] | 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. |
Florian Zumbiehl | 2138556 | 2011-11-01 20:19:40 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
Florian Zumbiehl | 6cdf5a9 | 2011-11-01 20:19:41 +0100 | [diff] [blame] | 21 | #include <arch/io.h> |
| 22 | #include "southbridge/via/vt8237r/vt8237r.h" |
Florian Zumbiehl | 2138556 | 2011-11-01 20:19:40 +0100 | [diff] [blame] | 23 | |
Florian Zumbiehl | 6cdf5a9 | 2011-11-01 20:19:41 +0100 | [diff] [blame] | 24 | u32 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 HAOUAS | 6350a2e | 2016-09-16 20:49:38 +0200 | [diff] [blame] | 45 | res = gpio_in & (1 << 29) ? 0 : VT8237R_IDE0_80PIN_CABLE; |
Florian Zumbiehl | 6cdf5a9 | 2011-11-01 20:19:41 +0100 | [diff] [blame] | 46 | /* bit 8 for secondary port, clear if unconnected or 80-pin cable */ |
Elyes HAOUAS | 6350a2e | 2016-09-16 20:49:38 +0200 | [diff] [blame] | 47 | res |= gpio_in & (1 << 8) ? 0 : VT8237R_IDE1_80PIN_CABLE; |
Florian Zumbiehl | 6cdf5a9 | 2011-11-01 20:19:41 +0100 | [diff] [blame] | 48 | |
| 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 | } |