blob: 9ea71dba71a853ba7fbffc04297adb6d6a33712e [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Uwe Hermann1410c2d2007-05-29 10:37:52 +00002
Uwe Hermann9da69f82007-11-30 02:08:26 +00003/* TODO: Check if this really works for all of the southbridges. */
4
5#include <stdint.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +00006#include <console/console.h>
7#include <device/device.h>
8#include <device/pci.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02009#include <device/pci_ops.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000010#include <device/pci_ids.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030011#include "chip.h"
Uwe Hermann1410c2d2007-05-29 10:37:52 +000012#include "i82371eb.h"
13
14/**
15 * Initialize the IDE controller.
16 *
17 * Depending on the configuration variables 'ide0_enable' and 'ide1_enable'
Uwe Hermann9da69f82007-11-30 02:08:26 +000018 * enable or disable the primary and secondary IDE interface, respectively.
19 *
20 * Depending on the configuration variable 'ide_legacy_enable' enable or
21 * disable access to the legacy IDE ports and the PCI Bus Master IDE I/O
22 * registers (this is required for e.g. FILO).
Uwe Hermann1410c2d2007-05-29 10:37:52 +000023 *
24 * @param dev The device to use.
25 */
Uwe Hermann9da69f82007-11-30 02:08:26 +000026static void ide_init_enable(struct device *dev)
Uwe Hermann1410c2d2007-05-29 10:37:52 +000027{
Uwe Hermann9da69f82007-11-30 02:08:26 +000028 u16 reg16;
Uwe Hermann56a91252007-06-03 16:57:27 +000029 struct southbridge_intel_i82371eb_config *conf = dev->chip_info;
Uwe Hermann1410c2d2007-05-29 10:37:52 +000030
31 /* Enable/disable the primary IDE interface. */
Uwe Hermann9da69f82007-11-30 02:08:26 +000032 reg16 = pci_read_config16(dev, IDETIM_PRI);
33 reg16 = ONOFF(conf->ide0_enable, reg16, IDE_DECODE_ENABLE);
34 pci_write_config16(dev, IDETIM_PRI, reg16);
Sylvain Hitier5b2fd1ea2010-10-11 23:22:24 +000035 printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Primary",
Uwe Hermann9da69f82007-11-30 02:08:26 +000036 conf->ide0_enable ? "on" : "off");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000037
38 /* Enable/disable the secondary IDE interface. */
Uwe Hermann9da69f82007-11-30 02:08:26 +000039 reg16 = pci_read_config16(dev, IDETIM_SEC);
40 reg16 = ONOFF(conf->ide1_enable, reg16, IDE_DECODE_ENABLE);
41 pci_write_config16(dev, IDETIM_SEC, reg16);
Sylvain Hitier5b2fd1ea2010-10-11 23:22:24 +000042 printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Secondary",
Uwe Hermann9da69f82007-11-30 02:08:26 +000043 conf->ide1_enable ? "on" : "off");
44
45 /* Enable access to the legacy IDE ports (both primary and secondary),
46 * and the PCI Bus Master IDE I/O registers.
47 * Only do this if at least one IDE interface is enabled.
48 */
49 if (conf->ide0_enable || conf->ide1_enable) {
50 reg16 = pci_read_config16(dev, PCI_COMMAND);
51 reg16 = ONOFF(conf->ide_legacy_enable, reg16,
52 (PCI_COMMAND_IO | PCI_COMMAND_MASTER));
53 pci_write_config16(dev, PCI_COMMAND, reg16);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000054 printk(BIOS_DEBUG, "IDE: Access to legacy IDE ports: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000055 conf->ide_legacy_enable ? "on" : "off");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000056 }
Uwe Hermann1410c2d2007-05-29 10:37:52 +000057}
58
Uwe Hermann9da69f82007-11-30 02:08:26 +000059/**
60 * Initialize the Ultra DMA/33 support of the IDE controller.
61 *
62 * Depending on the configuration variables 'ide0_drive0_udma33_enable',
63 * 'ide0_drive1_udma33_enable', 'ide1_drive0_udma33_enable', and
64 * 'ide1_drive1_udma33_enable' enable or disable Ultra DMA/33 support for
65 * the respective IDE controller and drive.
66 *
67 * Only do that if the respective controller is actually enabled, of course.
68 *
69 * @param dev The device to use.
70 */
71static void ide_init_udma33(struct device *dev)
72{
73 u8 reg8;
74 struct southbridge_intel_i82371eb_config *conf = dev->chip_info;
75
76 /* Enable/disable UDMA/33 operation (primary IDE interface). */
77 if (conf->ide0_enable) {
78 reg8 = pci_read_config8(dev, UDMACTL);
79 reg8 = ONOFF(conf->ide0_drive0_udma33_enable, reg8, PSDE0);
80 reg8 = ONOFF(conf->ide0_drive1_udma33_enable, reg8, PSDE1);
81 pci_write_config8(dev, UDMACTL, reg8);
82
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000083 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000084 "Primary IDE interface", 0,
85 conf->ide0_drive0_udma33_enable ? "on" : "off");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000086 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000087 "Primary IDE interface", 1,
88 conf->ide0_drive1_udma33_enable ? "on" : "off");
89 }
90
91 /* Enable/disable Ultra DMA/33 operation (secondary IDE interface). */
92 if (conf->ide1_enable) {
93 reg8 = pci_read_config8(dev, UDMACTL);
94 reg8 = ONOFF(conf->ide1_drive0_udma33_enable, reg8, SSDE0);
95 reg8 = ONOFF(conf->ide1_drive1_udma33_enable, reg8, SSDE1);
96 pci_write_config8(dev, UDMACTL, reg8);
97
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 "Secondary IDE interface", 0,
100 conf->ide1_drive0_udma33_enable ? "on" : "off");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000101 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +0000102 "Secondary IDE interface", 1,
103 conf->ide1_drive1_udma33_enable ? "on" : "off");
104 }
105}
106
107/**
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000108 * IDE init for the Intel 82371FB/SB IDE controller.
109 *
110 * These devices do not support UDMA/33, so don't attempt to enable it.
111 *
112 * @param dev The device to use.
113 */
114static void ide_init_i82371fb_sb(struct device *dev)
115{
116 ide_init_enable(dev);
117}
118
119/**
Uwe Hermann9da69f82007-11-30 02:08:26 +0000120 * IDE init for the Intel 82371AB/EB/MB IDE controller.
121 *
122 * @param dev The device to use.
123 */
124static void ide_init_i82371ab_eb_mb(struct device *dev)
125{
126 ide_init_enable(dev);
127 ide_init_udma33(dev);
128}
129
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000130/* Intel 82371FB/SB */
131static const struct device_operations ide_ops_fb_sb = {
132 .read_resources = pci_dev_read_resources,
133 .set_resources = pci_dev_set_resources,
134 .enable_resources = pci_dev_enable_resources,
135 .init = ide_init_i82371fb_sb,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000136 .ops_pci = 0, /* No subsystem IDs on 82371XX! */
137};
138
Uwe Hermann9da69f82007-11-30 02:08:26 +0000139/* Intel 82371AB/EB/MB */
Uwe Hermann312673c2009-10-27 21:49:33 +0000140static const struct device_operations ide_ops_ab_eb_mb = {
Uwe Hermann9da69f82007-11-30 02:08:26 +0000141 .read_resources = pci_dev_read_resources,
142 .set_resources = pci_dev_set_resources,
143 .enable_resources = pci_dev_enable_resources,
144 .init = ide_init_i82371ab_eb_mb,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000145 .ops_pci = 0, /* No subsystem IDs on 82371XX! */
146};
147
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000148/* Intel 82371FB (PIIX) */
149static const struct pci_driver ide_driver_fb __pci_driver = {
150 .ops = &ide_ops_fb_sb,
Felix Singer43b7f412022-03-07 04:34:52 +0100151 .vendor = PCI_VID_INTEL,
152 .device = PCI_DID_INTEL_82371FB_IDE,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000153};
154
155/* Intel 82371SB (PIIX3) */
156static const struct pci_driver ide_driver_sb __pci_driver = {
157 .ops = &ide_ops_fb_sb,
Felix Singer43b7f412022-03-07 04:34:52 +0100158 .vendor = PCI_VID_INTEL,
159 .device = PCI_DID_INTEL_82371SB_IDE,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000160};
161
162/* Intel 82371MX (MPIIX) */
163static const struct pci_driver ide_driver_mx __pci_driver = {
164 .ops = &ide_ops_fb_sb,
Felix Singer43b7f412022-03-07 04:34:52 +0100165 .vendor = PCI_VID_INTEL,
166 .device = PCI_DID_INTEL_82371MX_ISA_IDE,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000167};
168
169/* Intel 82437MX (part of the 430MX chipset) */
170static const struct pci_driver ide_driver_82437mx __pci_driver = {
171 .ops = &ide_ops_fb_sb,
Felix Singer43b7f412022-03-07 04:34:52 +0100172 .vendor = PCI_VID_INTEL,
173 .device = PCI_DID_INTEL_82437MX_ISA_IDE,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000174};
175
Uwe Hermann9da69f82007-11-30 02:08:26 +0000176/* Intel 82371AB/EB/MB */
177static const struct pci_driver ide_driver_ab_eb_mb __pci_driver = {
178 .ops = &ide_ops_ab_eb_mb,
Felix Singer43b7f412022-03-07 04:34:52 +0100179 .vendor = PCI_VID_INTEL,
180 .device = PCI_DID_INTEL_82371AB_IDE,
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000181};