Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 5 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 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. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame^] | 20 | #include <device/pci_ops.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 21 | #include <device/pci_ids.h> |
| 22 | #include "i82801gx.h" |
| 23 | |
| 24 | typedef struct southbridge_intel_i82801gx_config config_t; |
| 25 | |
| 26 | static void ide_init(struct device *dev) |
| 27 | { |
| 28 | u16 ideTimingConfig; |
| 29 | u32 reg32; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 30 | u32 enable_primary, enable_secondary; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 31 | |
| 32 | /* Get the chip configuration */ |
| 33 | config_t *config = dev->chip_info; |
| 34 | |
Paul Menzel | 7f1df8c | 2015-10-11 15:48:36 +0200 | [diff] [blame] | 35 | printk(BIOS_DEBUG, "i82801gx_ide: initializing..."); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 36 | if (config == NULL) { |
Uwe Hermann | 607614d | 2010-11-18 20:12:13 +0000 | [diff] [blame] | 37 | printk(BIOS_ERR, "\ni82801gx_ide: Not mentioned in devicetree.cb!\n"); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 38 | // Trying to set somewhat safe defaults instead of bailing out. |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 39 | enable_primary = enable_secondary = 1; |
| 40 | } else { |
| 41 | enable_primary = config->ide_enable_primary; |
| 42 | enable_secondary = config->ide_enable_secondary; |
| 43 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 44 | |
| 45 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 46 | pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_IO | PCI_COMMAND_MASTER); |
| 47 | |
| 48 | /* Native Capable, but not enabled. */ |
| 49 | pci_write_config8(dev, 0x09, 0x8a); |
| 50 | |
| 51 | ideTimingConfig = pci_read_config16(dev, IDE_TIM_PRI); |
| 52 | ideTimingConfig &= ~IDE_DECODE_ENABLE; |
| 53 | ideTimingConfig |= IDE_SITRE; |
| 54 | if (enable_primary) { |
| 55 | /* Enable primary IDE interface. */ |
| 56 | ideTimingConfig |= IDE_DECODE_ENABLE; |
| 57 | ideTimingConfig |= (2 << 12); // ISP = 3 clocks |
| 58 | ideTimingConfig |= (3 << 8); // RCT = 1 clock |
| 59 | ideTimingConfig |= (1 << 1); // IE0 |
| 60 | ideTimingConfig |= (1 << 0); // TIME0 |
Paul Menzel | 7f1df8c | 2015-10-11 15:48:36 +0200 | [diff] [blame] | 61 | printk(BIOS_DEBUG, " IDE0"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 62 | } |
| 63 | pci_write_config16(dev, IDE_TIM_PRI, ideTimingConfig); |
| 64 | |
| 65 | ideTimingConfig = pci_read_config16(dev, IDE_TIM_SEC); |
| 66 | ideTimingConfig &= ~IDE_DECODE_ENABLE; |
| 67 | ideTimingConfig |= IDE_SITRE; |
| 68 | if (enable_secondary) { |
| 69 | /* Enable secondary IDE interface. */ |
| 70 | ideTimingConfig |= IDE_DECODE_ENABLE; |
| 71 | ideTimingConfig |= (2 << 12); // ISP = 3 clocks |
| 72 | ideTimingConfig |= (3 << 8); // RCT = 1 clock |
| 73 | ideTimingConfig |= (1 << 1); // IE0 |
| 74 | ideTimingConfig |= (1 << 0); // TIME0 |
Paul Menzel | 7f1df8c | 2015-10-11 15:48:36 +0200 | [diff] [blame] | 75 | printk(BIOS_DEBUG, " IDE1"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 76 | } |
| 77 | pci_write_config16(dev, IDE_TIM_SEC, ideTimingConfig); |
| 78 | |
| 79 | /* Set IDE I/O Configuration */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 80 | reg32 = 0; |
| 81 | /* FIXME: only set FAST_* for ata/100, only ?CBx for ata/66 */ |
| 82 | if (enable_primary) |
| 83 | reg32 |= SIG_MODE_PRI_NORMAL | FAST_PCB0 | PCB0 | FAST_PCB1 | PCB1; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 84 | if (enable_secondary) |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 85 | reg32 |= SIG_MODE_SEC_NORMAL | FAST_SCB0 | SCB0 | FAST_SCB1 | SCB1; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 86 | pci_write_config32(dev, IDE_CONFIG, reg32); |
| 87 | |
| 88 | /* Set Interrupt Line */ |
| 89 | /* Interrupt Pin is set by D31IP.PIP */ |
| 90 | pci_write_config32(dev, INTR_LN, 0xff); /* Int 15 */ |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 91 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 92 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 95 | static void ide_set_subsystem(struct device *dev, unsigned int vendor, |
| 96 | unsigned int device) |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 97 | { |
| 98 | if (!vendor || !device) { |
| 99 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 100 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 101 | } else { |
| 102 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 103 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | static struct pci_operations ide_pci_ops = { |
| 108 | .set_subsystem = ide_set_subsystem, |
| 109 | }; |
| 110 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 111 | static struct device_operations ide_ops = { |
| 112 | .read_resources = pci_dev_read_resources, |
| 113 | .set_resources = pci_dev_set_resources, |
| 114 | .enable_resources = pci_dev_enable_resources, |
| 115 | .init = ide_init, |
| 116 | .scan_bus = 0, |
| 117 | .enable = i82801gx_enable, |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 118 | .ops_pci = &ide_pci_ops, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 121 | /* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 122 | static const struct pci_driver i82801gx_ide __pci_driver = { |
| 123 | .ops = &ide_ops, |
| 124 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 125 | .device = 0x27df, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 126 | }; |