blob: b2d2aca887721da5688a462f070501af86bb1562 [file] [log] [blame]
Patrick Georgi02363b52020-05-05 20:48:50 +02001/* This file is part of the coreboot project. */
Patrick Georgiac959032020-05-05 22:49:26 +02002/* SPDX-License-Identifier: GPL-2.0-or-later */
Uwe Hermann1410c2d2007-05-29 10:37:52 +00003
Uwe Hermann9da69f82007-11-30 02:08:26 +00004/* TODO: Check if this really works for all of the southbridges. */
5
6#include <stdint.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +00007#include <console/console.h>
8#include <device/device.h>
9#include <device/pci.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020010#include <device/pci_ops.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000011#include <device/pci_ids.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030012#include "chip.h"
Uwe Hermann1410c2d2007-05-29 10:37:52 +000013#include "i82371eb.h"
14
15/**
16 * Initialize the IDE controller.
17 *
18 * Depending on the configuration variables 'ide0_enable' and 'ide1_enable'
Uwe Hermann9da69f82007-11-30 02:08:26 +000019 * enable or disable the primary and secondary IDE interface, respectively.
20 *
21 * Depending on the configuration variable 'ide_legacy_enable' enable or
22 * disable access to the legacy IDE ports and the PCI Bus Master IDE I/O
23 * registers (this is required for e.g. FILO).
Uwe Hermann1410c2d2007-05-29 10:37:52 +000024 *
25 * @param dev The device to use.
26 */
Uwe Hermann9da69f82007-11-30 02:08:26 +000027static void ide_init_enable(struct device *dev)
Uwe Hermann1410c2d2007-05-29 10:37:52 +000028{
Uwe Hermann9da69f82007-11-30 02:08:26 +000029 u16 reg16;
Uwe Hermann56a91252007-06-03 16:57:27 +000030 struct southbridge_intel_i82371eb_config *conf = dev->chip_info;
Uwe Hermann1410c2d2007-05-29 10:37:52 +000031
32 /* Enable/disable the primary IDE interface. */
Uwe Hermann9da69f82007-11-30 02:08:26 +000033 reg16 = pci_read_config16(dev, IDETIM_PRI);
34 reg16 = ONOFF(conf->ide0_enable, reg16, IDE_DECODE_ENABLE);
35 pci_write_config16(dev, IDETIM_PRI, reg16);
Sylvain Hitier5b2fd1ea2010-10-11 23:22:24 +000036 printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Primary",
Uwe Hermann9da69f82007-11-30 02:08:26 +000037 conf->ide0_enable ? "on" : "off");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000038
39 /* Enable/disable the secondary IDE interface. */
Uwe Hermann9da69f82007-11-30 02:08:26 +000040 reg16 = pci_read_config16(dev, IDETIM_SEC);
41 reg16 = ONOFF(conf->ide1_enable, reg16, IDE_DECODE_ENABLE);
42 pci_write_config16(dev, IDETIM_SEC, reg16);
Sylvain Hitier5b2fd1ea2010-10-11 23:22:24 +000043 printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Secondary",
Uwe Hermann9da69f82007-11-30 02:08:26 +000044 conf->ide1_enable ? "on" : "off");
45
46 /* Enable access to the legacy IDE ports (both primary and secondary),
47 * and the PCI Bus Master IDE I/O registers.
48 * Only do this if at least one IDE interface is enabled.
49 */
50 if (conf->ide0_enable || conf->ide1_enable) {
51 reg16 = pci_read_config16(dev, PCI_COMMAND);
52 reg16 = ONOFF(conf->ide_legacy_enable, reg16,
53 (PCI_COMMAND_IO | PCI_COMMAND_MASTER));
54 pci_write_config16(dev, PCI_COMMAND, reg16);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000055 printk(BIOS_DEBUG, "IDE: Access to legacy IDE ports: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000056 conf->ide_legacy_enable ? "on" : "off");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000057 }
Uwe Hermann1410c2d2007-05-29 10:37:52 +000058}
59
Uwe Hermann9da69f82007-11-30 02:08:26 +000060/**
61 * Initialize the Ultra DMA/33 support of the IDE controller.
62 *
63 * Depending on the configuration variables 'ide0_drive0_udma33_enable',
64 * 'ide0_drive1_udma33_enable', 'ide1_drive0_udma33_enable', and
65 * 'ide1_drive1_udma33_enable' enable or disable Ultra DMA/33 support for
66 * the respective IDE controller and drive.
67 *
68 * Only do that if the respective controller is actually enabled, of course.
69 *
70 * @param dev The device to use.
71 */
72static void ide_init_udma33(struct device *dev)
73{
74 u8 reg8;
75 struct southbridge_intel_i82371eb_config *conf = dev->chip_info;
76
77 /* Enable/disable UDMA/33 operation (primary IDE interface). */
78 if (conf->ide0_enable) {
79 reg8 = pci_read_config8(dev, UDMACTL);
80 reg8 = ONOFF(conf->ide0_drive0_udma33_enable, reg8, PSDE0);
81 reg8 = ONOFF(conf->ide0_drive1_udma33_enable, reg8, PSDE1);
82 pci_write_config8(dev, UDMACTL, reg8);
83
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000084 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000085 "Primary IDE interface", 0,
86 conf->ide0_drive0_udma33_enable ? "on" : "off");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000087 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000088 "Primary IDE interface", 1,
89 conf->ide0_drive1_udma33_enable ? "on" : "off");
90 }
91
92 /* Enable/disable Ultra DMA/33 operation (secondary IDE interface). */
93 if (conf->ide1_enable) {
94 reg8 = pci_read_config8(dev, UDMACTL);
95 reg8 = ONOFF(conf->ide1_drive0_udma33_enable, reg8, SSDE0);
96 reg8 = ONOFF(conf->ide1_drive1_udma33_enable, reg8, SSDE1);
97 pci_write_config8(dev, UDMACTL, reg8);
98
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000099 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +0000100 "Secondary IDE interface", 0,
101 conf->ide1_drive0_udma33_enable ? "on" : "off");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000102 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +0000103 "Secondary IDE interface", 1,
104 conf->ide1_drive1_udma33_enable ? "on" : "off");
105 }
106}
107
108/**
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000109 * IDE init for the Intel 82371FB/SB IDE controller.
110 *
111 * These devices do not support UDMA/33, so don't attempt to enable it.
112 *
113 * @param dev The device to use.
114 */
115static void ide_init_i82371fb_sb(struct device *dev)
116{
117 ide_init_enable(dev);
118}
119
120/**
Uwe Hermann9da69f82007-11-30 02:08:26 +0000121 * IDE init for the Intel 82371AB/EB/MB IDE controller.
122 *
123 * @param dev The device to use.
124 */
125static void ide_init_i82371ab_eb_mb(struct device *dev)
126{
127 ide_init_enable(dev);
128 ide_init_udma33(dev);
129}
130
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000131/* Intel 82371FB/SB */
132static const struct device_operations ide_ops_fb_sb = {
133 .read_resources = pci_dev_read_resources,
134 .set_resources = pci_dev_set_resources,
135 .enable_resources = pci_dev_enable_resources,
136 .init = ide_init_i82371fb_sb,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000137 .ops_pci = 0, /* No subsystem IDs on 82371XX! */
138};
139
Uwe Hermann9da69f82007-11-30 02:08:26 +0000140/* Intel 82371AB/EB/MB */
Uwe Hermann312673c2009-10-27 21:49:33 +0000141static const struct device_operations ide_ops_ab_eb_mb = {
Uwe Hermann9da69f82007-11-30 02:08:26 +0000142 .read_resources = pci_dev_read_resources,
143 .set_resources = pci_dev_set_resources,
144 .enable_resources = pci_dev_enable_resources,
145 .init = ide_init_i82371ab_eb_mb,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000146 .ops_pci = 0, /* No subsystem IDs on 82371XX! */
147};
148
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000149/* Intel 82371FB (PIIX) */
150static const struct pci_driver ide_driver_fb __pci_driver = {
151 .ops = &ide_ops_fb_sb,
152 .vendor = PCI_VENDOR_ID_INTEL,
153 .device = PCI_DEVICE_ID_INTEL_82371FB_IDE,
154};
155
156/* Intel 82371SB (PIIX3) */
157static const struct pci_driver ide_driver_sb __pci_driver = {
158 .ops = &ide_ops_fb_sb,
159 .vendor = PCI_VENDOR_ID_INTEL,
160 .device = PCI_DEVICE_ID_INTEL_82371SB_IDE,
161};
162
163/* Intel 82371MX (MPIIX) */
164static const struct pci_driver ide_driver_mx __pci_driver = {
165 .ops = &ide_ops_fb_sb,
166 .vendor = PCI_VENDOR_ID_INTEL,
167 .device = PCI_DEVICE_ID_INTEL_82371MX_ISA_IDE,
168};
169
170/* Intel 82437MX (part of the 430MX chipset) */
171static const struct pci_driver ide_driver_82437mx __pci_driver = {
172 .ops = &ide_ops_fb_sb,
173 .vendor = PCI_VENDOR_ID_INTEL,
174 .device = PCI_DEVICE_ID_INTEL_82437MX_ISA_IDE,
175};
176
Uwe Hermann9da69f82007-11-30 02:08:26 +0000177/* Intel 82371AB/EB/MB */
178static const struct pci_driver ide_driver_ab_eb_mb __pci_driver = {
179 .ops = &ide_ops_ab_eb_mb,
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000180 .vendor = PCI_VENDOR_ID_INTEL,
181 .device = PCI_DEVICE_ID_INTEL_82371AB_IDE,
182};