blob: d2e8614c5598992c5bf2885d6b7612ba36cac32e [file] [log] [blame]
Patrick Georgi02363b52020-05-05 20:48:50 +02001/* This file is part of the coreboot project. */
Uwe Hermann1410c2d2007-05-29 10:37:52 +00002/*
Uwe Hermann1410c2d2007-05-29 10:37:52 +00003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Uwe Hermann1410c2d2007-05-29 10:37:52 +000013 */
14
Uwe Hermann9da69f82007-11-30 02:08:26 +000015/* TODO: Check if this really works for all of the southbridges. */
16
17#include <stdint.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000018#include <console/console.h>
19#include <device/device.h>
20#include <device/pci.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000022#include <device/pci_ids.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030023#include "chip.h"
Uwe Hermann1410c2d2007-05-29 10:37:52 +000024#include "i82371eb.h"
25
26/**
27 * Initialize the IDE controller.
28 *
29 * Depending on the configuration variables 'ide0_enable' and 'ide1_enable'
Uwe Hermann9da69f82007-11-30 02:08:26 +000030 * enable or disable the primary and secondary IDE interface, respectively.
31 *
32 * Depending on the configuration variable 'ide_legacy_enable' enable or
33 * disable access to the legacy IDE ports and the PCI Bus Master IDE I/O
34 * registers (this is required for e.g. FILO).
Uwe Hermann1410c2d2007-05-29 10:37:52 +000035 *
36 * @param dev The device to use.
37 */
Uwe Hermann9da69f82007-11-30 02:08:26 +000038static void ide_init_enable(struct device *dev)
Uwe Hermann1410c2d2007-05-29 10:37:52 +000039{
Uwe Hermann9da69f82007-11-30 02:08:26 +000040 u16 reg16;
Uwe Hermann56a91252007-06-03 16:57:27 +000041 struct southbridge_intel_i82371eb_config *conf = dev->chip_info;
Uwe Hermann1410c2d2007-05-29 10:37:52 +000042
43 /* Enable/disable the primary IDE interface. */
Uwe Hermann9da69f82007-11-30 02:08:26 +000044 reg16 = pci_read_config16(dev, IDETIM_PRI);
45 reg16 = ONOFF(conf->ide0_enable, reg16, IDE_DECODE_ENABLE);
46 pci_write_config16(dev, IDETIM_PRI, reg16);
Sylvain Hitier5b2fd1ea2010-10-11 23:22:24 +000047 printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Primary",
Uwe Hermann9da69f82007-11-30 02:08:26 +000048 conf->ide0_enable ? "on" : "off");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000049
50 /* Enable/disable the secondary IDE interface. */
Uwe Hermann9da69f82007-11-30 02:08:26 +000051 reg16 = pci_read_config16(dev, IDETIM_SEC);
52 reg16 = ONOFF(conf->ide1_enable, reg16, IDE_DECODE_ENABLE);
53 pci_write_config16(dev, IDETIM_SEC, reg16);
Sylvain Hitier5b2fd1ea2010-10-11 23:22:24 +000054 printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Secondary",
Uwe Hermann9da69f82007-11-30 02:08:26 +000055 conf->ide1_enable ? "on" : "off");
56
57 /* Enable access to the legacy IDE ports (both primary and secondary),
58 * and the PCI Bus Master IDE I/O registers.
59 * Only do this if at least one IDE interface is enabled.
60 */
61 if (conf->ide0_enable || conf->ide1_enable) {
62 reg16 = pci_read_config16(dev, PCI_COMMAND);
63 reg16 = ONOFF(conf->ide_legacy_enable, reg16,
64 (PCI_COMMAND_IO | PCI_COMMAND_MASTER));
65 pci_write_config16(dev, PCI_COMMAND, reg16);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000066 printk(BIOS_DEBUG, "IDE: Access to legacy IDE ports: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000067 conf->ide_legacy_enable ? "on" : "off");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000068 }
Uwe Hermann1410c2d2007-05-29 10:37:52 +000069}
70
Uwe Hermann9da69f82007-11-30 02:08:26 +000071/**
72 * Initialize the Ultra DMA/33 support of the IDE controller.
73 *
74 * Depending on the configuration variables 'ide0_drive0_udma33_enable',
75 * 'ide0_drive1_udma33_enable', 'ide1_drive0_udma33_enable', and
76 * 'ide1_drive1_udma33_enable' enable or disable Ultra DMA/33 support for
77 * the respective IDE controller and drive.
78 *
79 * Only do that if the respective controller is actually enabled, of course.
80 *
81 * @param dev The device to use.
82 */
83static void ide_init_udma33(struct device *dev)
84{
85 u8 reg8;
86 struct southbridge_intel_i82371eb_config *conf = dev->chip_info;
87
88 /* Enable/disable UDMA/33 operation (primary IDE interface). */
89 if (conf->ide0_enable) {
90 reg8 = pci_read_config8(dev, UDMACTL);
91 reg8 = ONOFF(conf->ide0_drive0_udma33_enable, reg8, PSDE0);
92 reg8 = ONOFF(conf->ide0_drive1_udma33_enable, reg8, PSDE1);
93 pci_write_config8(dev, UDMACTL, reg8);
94
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000095 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000096 "Primary IDE interface", 0,
97 conf->ide0_drive0_udma33_enable ? "on" : "off");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000098 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000099 "Primary IDE interface", 1,
100 conf->ide0_drive1_udma33_enable ? "on" : "off");
101 }
102
103 /* Enable/disable Ultra DMA/33 operation (secondary IDE interface). */
104 if (conf->ide1_enable) {
105 reg8 = pci_read_config8(dev, UDMACTL);
106 reg8 = ONOFF(conf->ide1_drive0_udma33_enable, reg8, SSDE0);
107 reg8 = ONOFF(conf->ide1_drive1_udma33_enable, reg8, SSDE1);
108 pci_write_config8(dev, UDMACTL, reg8);
109
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000110 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +0000111 "Secondary IDE interface", 0,
112 conf->ide1_drive0_udma33_enable ? "on" : "off");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000113 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +0000114 "Secondary IDE interface", 1,
115 conf->ide1_drive1_udma33_enable ? "on" : "off");
116 }
117}
118
119/**
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000120 * IDE init for the Intel 82371FB/SB IDE controller.
121 *
122 * These devices do not support UDMA/33, so don't attempt to enable it.
123 *
124 * @param dev The device to use.
125 */
126static void ide_init_i82371fb_sb(struct device *dev)
127{
128 ide_init_enable(dev);
129}
130
131/**
Uwe Hermann9da69f82007-11-30 02:08:26 +0000132 * IDE init for the Intel 82371AB/EB/MB IDE controller.
133 *
134 * @param dev The device to use.
135 */
136static void ide_init_i82371ab_eb_mb(struct device *dev)
137{
138 ide_init_enable(dev);
139 ide_init_udma33(dev);
140}
141
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000142/* Intel 82371FB/SB */
143static const struct device_operations ide_ops_fb_sb = {
144 .read_resources = pci_dev_read_resources,
145 .set_resources = pci_dev_set_resources,
146 .enable_resources = pci_dev_enable_resources,
147 .init = ide_init_i82371fb_sb,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000148 .ops_pci = 0, /* No subsystem IDs on 82371XX! */
149};
150
Uwe Hermann9da69f82007-11-30 02:08:26 +0000151/* Intel 82371AB/EB/MB */
Uwe Hermann312673c2009-10-27 21:49:33 +0000152static const struct device_operations ide_ops_ab_eb_mb = {
Uwe Hermann9da69f82007-11-30 02:08:26 +0000153 .read_resources = pci_dev_read_resources,
154 .set_resources = pci_dev_set_resources,
155 .enable_resources = pci_dev_enable_resources,
156 .init = ide_init_i82371ab_eb_mb,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000157 .ops_pci = 0, /* No subsystem IDs on 82371XX! */
158};
159
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000160/* Intel 82371FB (PIIX) */
161static const struct pci_driver ide_driver_fb __pci_driver = {
162 .ops = &ide_ops_fb_sb,
163 .vendor = PCI_VENDOR_ID_INTEL,
164 .device = PCI_DEVICE_ID_INTEL_82371FB_IDE,
165};
166
167/* Intel 82371SB (PIIX3) */
168static const struct pci_driver ide_driver_sb __pci_driver = {
169 .ops = &ide_ops_fb_sb,
170 .vendor = PCI_VENDOR_ID_INTEL,
171 .device = PCI_DEVICE_ID_INTEL_82371SB_IDE,
172};
173
174/* Intel 82371MX (MPIIX) */
175static const struct pci_driver ide_driver_mx __pci_driver = {
176 .ops = &ide_ops_fb_sb,
177 .vendor = PCI_VENDOR_ID_INTEL,
178 .device = PCI_DEVICE_ID_INTEL_82371MX_ISA_IDE,
179};
180
181/* Intel 82437MX (part of the 430MX chipset) */
182static const struct pci_driver ide_driver_82437mx __pci_driver = {
183 .ops = &ide_ops_fb_sb,
184 .vendor = PCI_VENDOR_ID_INTEL,
185 .device = PCI_DEVICE_ID_INTEL_82437MX_ISA_IDE,
186};
187
Uwe Hermann9da69f82007-11-30 02:08:26 +0000188/* Intel 82371AB/EB/MB */
189static const struct pci_driver ide_driver_ab_eb_mb __pci_driver = {
190 .ops = &ide_ops_ab_eb_mb,
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000191 .vendor = PCI_VENDOR_ID_INTEL,
192 .device = PCI_DEVICE_ID_INTEL_82371AB_IDE,
193};