Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.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; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 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. |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 17 | /* TODO: Check if this really works for all of the southbridges. */ |
| 18 | |
| 19 | #include <stdint.h> |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 23 | #include <device/pci_ops.h> |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 24 | #include <device/pci_ids.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame^] | 25 | #include "chip.h" |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 26 | #include "i82371eb.h" |
| 27 | |
| 28 | /** |
| 29 | * Initialize the IDE controller. |
| 30 | * |
| 31 | * Depending on the configuration variables 'ide0_enable' and 'ide1_enable' |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 32 | * enable or disable the primary and secondary IDE interface, respectively. |
| 33 | * |
| 34 | * Depending on the configuration variable 'ide_legacy_enable' enable or |
| 35 | * disable access to the legacy IDE ports and the PCI Bus Master IDE I/O |
| 36 | * registers (this is required for e.g. FILO). |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 37 | * |
| 38 | * @param dev The device to use. |
| 39 | */ |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 40 | static void ide_init_enable(struct device *dev) |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 41 | { |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 42 | u16 reg16; |
Uwe Hermann | 56a9125 | 2007-06-03 16:57:27 +0000 | [diff] [blame] | 43 | struct southbridge_intel_i82371eb_config *conf = dev->chip_info; |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 44 | |
| 45 | /* Enable/disable the primary IDE interface. */ |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 46 | reg16 = pci_read_config16(dev, IDETIM_PRI); |
| 47 | reg16 = ONOFF(conf->ide0_enable, reg16, IDE_DECODE_ENABLE); |
| 48 | pci_write_config16(dev, IDETIM_PRI, reg16); |
Sylvain Hitier | 5b2fd1ea | 2010-10-11 23:22:24 +0000 | [diff] [blame] | 49 | printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Primary", |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 50 | conf->ide0_enable ? "on" : "off"); |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 51 | |
| 52 | /* Enable/disable the secondary IDE interface. */ |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 53 | reg16 = pci_read_config16(dev, IDETIM_SEC); |
| 54 | reg16 = ONOFF(conf->ide1_enable, reg16, IDE_DECODE_ENABLE); |
| 55 | pci_write_config16(dev, IDETIM_SEC, reg16); |
Sylvain Hitier | 5b2fd1ea | 2010-10-11 23:22:24 +0000 | [diff] [blame] | 56 | printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Secondary", |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 57 | conf->ide1_enable ? "on" : "off"); |
| 58 | |
| 59 | /* Enable access to the legacy IDE ports (both primary and secondary), |
| 60 | * and the PCI Bus Master IDE I/O registers. |
| 61 | * Only do this if at least one IDE interface is enabled. |
| 62 | */ |
| 63 | if (conf->ide0_enable || conf->ide1_enable) { |
| 64 | reg16 = pci_read_config16(dev, PCI_COMMAND); |
| 65 | reg16 = ONOFF(conf->ide_legacy_enable, reg16, |
| 66 | (PCI_COMMAND_IO | PCI_COMMAND_MASTER)); |
| 67 | pci_write_config16(dev, PCI_COMMAND, reg16); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 68 | printk(BIOS_DEBUG, "IDE: Access to legacy IDE ports: %s\n", |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 69 | conf->ide_legacy_enable ? "on" : "off"); |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 70 | } |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 73 | /** |
| 74 | * Initialize the Ultra DMA/33 support of the IDE controller. |
| 75 | * |
| 76 | * Depending on the configuration variables 'ide0_drive0_udma33_enable', |
| 77 | * 'ide0_drive1_udma33_enable', 'ide1_drive0_udma33_enable', and |
| 78 | * 'ide1_drive1_udma33_enable' enable or disable Ultra DMA/33 support for |
| 79 | * the respective IDE controller and drive. |
| 80 | * |
| 81 | * Only do that if the respective controller is actually enabled, of course. |
| 82 | * |
| 83 | * @param dev The device to use. |
| 84 | */ |
| 85 | static void ide_init_udma33(struct device *dev) |
| 86 | { |
| 87 | u8 reg8; |
| 88 | struct southbridge_intel_i82371eb_config *conf = dev->chip_info; |
| 89 | |
| 90 | /* Enable/disable UDMA/33 operation (primary IDE interface). */ |
| 91 | if (conf->ide0_enable) { |
| 92 | reg8 = pci_read_config8(dev, UDMACTL); |
| 93 | reg8 = ONOFF(conf->ide0_drive0_udma33_enable, reg8, PSDE0); |
| 94 | reg8 = ONOFF(conf->ide0_drive1_udma33_enable, reg8, PSDE1); |
| 95 | pci_write_config8(dev, UDMACTL, reg8); |
| 96 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 97 | printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n", |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 98 | "Primary IDE interface", 0, |
| 99 | conf->ide0_drive0_udma33_enable ? "on" : "off"); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 100 | printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n", |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 101 | "Primary IDE interface", 1, |
| 102 | conf->ide0_drive1_udma33_enable ? "on" : "off"); |
| 103 | } |
| 104 | |
| 105 | /* Enable/disable Ultra DMA/33 operation (secondary IDE interface). */ |
| 106 | if (conf->ide1_enable) { |
| 107 | reg8 = pci_read_config8(dev, UDMACTL); |
| 108 | reg8 = ONOFF(conf->ide1_drive0_udma33_enable, reg8, SSDE0); |
| 109 | reg8 = ONOFF(conf->ide1_drive1_udma33_enable, reg8, SSDE1); |
| 110 | pci_write_config8(dev, UDMACTL, reg8); |
| 111 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 112 | printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n", |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 113 | "Secondary IDE interface", 0, |
| 114 | conf->ide1_drive0_udma33_enable ? "on" : "off"); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 115 | printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n", |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 116 | "Secondary IDE interface", 1, |
| 117 | conf->ide1_drive1_udma33_enable ? "on" : "off"); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * IDE init for the Intel 82371FB/SB IDE controller. |
| 123 | * |
| 124 | * These devices do not support UDMA/33, so don't attempt to enable it. |
| 125 | * |
| 126 | * @param dev The device to use. |
| 127 | */ |
| 128 | static void ide_init_i82371fb_sb(struct device *dev) |
| 129 | { |
| 130 | ide_init_enable(dev); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * IDE init for the Intel 82371AB/EB/MB IDE controller. |
| 135 | * |
| 136 | * @param dev The device to use. |
| 137 | */ |
| 138 | static void ide_init_i82371ab_eb_mb(struct device *dev) |
| 139 | { |
| 140 | ide_init_enable(dev); |
| 141 | ide_init_udma33(dev); |
| 142 | } |
| 143 | |
| 144 | /* Intel 82371FB/SB */ |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 145 | static const struct device_operations ide_ops_fb_sb = { |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 146 | .read_resources = pci_dev_read_resources, |
| 147 | .set_resources = pci_dev_set_resources, |
| 148 | .enable_resources = pci_dev_enable_resources, |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 149 | .init = ide_init_i82371fb_sb, |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 150 | .scan_bus = 0, |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 151 | .enable = 0, |
| 152 | .ops_pci = 0, /* No subsystem IDs on 82371XX! */ |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 155 | /* Intel 82371AB/EB/MB */ |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 156 | static const struct device_operations ide_ops_ab_eb_mb = { |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 157 | .read_resources = pci_dev_read_resources, |
| 158 | .set_resources = pci_dev_set_resources, |
| 159 | .enable_resources = pci_dev_enable_resources, |
| 160 | .init = ide_init_i82371ab_eb_mb, |
| 161 | .scan_bus = 0, |
| 162 | .enable = 0, |
| 163 | .ops_pci = 0, /* No subsystem IDs on 82371XX! */ |
| 164 | }; |
| 165 | |
| 166 | /* Intel 82371FB (PIIX) */ |
| 167 | static const struct pci_driver ide_driver_fb __pci_driver = { |
| 168 | .ops = &ide_ops_fb_sb, |
| 169 | .vendor = PCI_VENDOR_ID_INTEL, |
| 170 | .device = PCI_DEVICE_ID_INTEL_82371FB_IDE, |
| 171 | }; |
| 172 | |
| 173 | /* Intel 82371SB (PIIX3) */ |
| 174 | static const struct pci_driver ide_driver_sb __pci_driver = { |
| 175 | .ops = &ide_ops_fb_sb, |
| 176 | .vendor = PCI_VENDOR_ID_INTEL, |
| 177 | .device = PCI_DEVICE_ID_INTEL_82371SB_IDE, |
| 178 | }; |
| 179 | |
| 180 | /* Intel 82371MX (MPIIX) */ |
| 181 | static const struct pci_driver ide_driver_mx __pci_driver = { |
| 182 | .ops = &ide_ops_fb_sb, |
| 183 | .vendor = PCI_VENDOR_ID_INTEL, |
| 184 | .device = PCI_DEVICE_ID_INTEL_82371MX_ISA_IDE, |
| 185 | }; |
| 186 | |
| 187 | /* Intel 82437MX (part of the 430MX chipset) */ |
| 188 | static const struct pci_driver ide_driver_82437mx __pci_driver = { |
| 189 | .ops = &ide_ops_fb_sb, |
| 190 | .vendor = PCI_VENDOR_ID_INTEL, |
| 191 | .device = PCI_DEVICE_ID_INTEL_82437MX_ISA_IDE, |
| 192 | }; |
| 193 | |
| 194 | /* Intel 82371AB/EB/MB */ |
| 195 | static const struct pci_driver ide_driver_ab_eb_mb __pci_driver = { |
| 196 | .ops = &ide_ops_ab_eb_mb, |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 197 | .vendor = PCI_VENDOR_ID_INTEL, |
| 198 | .device = PCI_DEVICE_ID_INTEL_82371AB_IDE, |
| 199 | }; |