Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 7 | #include <device/pci_ids.h> |
Arthur Heymans | 742df5a | 2019-06-03 16:24:41 +0200 | [diff] [blame] | 8 | #include "chip.h" |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 9 | #include "i82801gx.h" |
| 10 | |
| 11 | typedef struct southbridge_intel_i82801gx_config config_t; |
| 12 | |
| 13 | static void ide_init(struct device *dev) |
| 14 | { |
| 15 | u16 ideTimingConfig; |
| 16 | u32 reg32; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 17 | u32 enable_primary, enable_secondary; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 18 | |
| 19 | /* Get the chip configuration */ |
| 20 | config_t *config = dev->chip_info; |
| 21 | |
Paul Menzel | 7f1df8c | 2015-10-11 15:48:36 +0200 | [diff] [blame] | 22 | printk(BIOS_DEBUG, "i82801gx_ide: initializing..."); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 23 | if (config == NULL) { |
Uwe Hermann | 607614d | 2010-11-18 20:12:13 +0000 | [diff] [blame] | 24 | printk(BIOS_ERR, "\ni82801gx_ide: Not mentioned in devicetree.cb!\n"); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 25 | // Trying to set somewhat safe defaults instead of bailing out. |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 26 | enable_primary = enable_secondary = 1; |
| 27 | } else { |
| 28 | enable_primary = config->ide_enable_primary; |
| 29 | enable_secondary = config->ide_enable_secondary; |
| 30 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 31 | |
Elyes HAOUAS | 1234925 | 2020-04-27 05:08:26 +0200 | [diff] [blame] | 32 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MASTER); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 33 | |
| 34 | /* Native Capable, but not enabled. */ |
| 35 | pci_write_config8(dev, 0x09, 0x8a); |
| 36 | |
| 37 | ideTimingConfig = pci_read_config16(dev, IDE_TIM_PRI); |
| 38 | ideTimingConfig &= ~IDE_DECODE_ENABLE; |
| 39 | ideTimingConfig |= IDE_SITRE; |
| 40 | if (enable_primary) { |
| 41 | /* Enable primary IDE interface. */ |
| 42 | ideTimingConfig |= IDE_DECODE_ENABLE; |
Elyes HAOUAS | ae22fe2 | 2020-05-21 09:04:16 +0200 | [diff] [blame] | 43 | ideTimingConfig |= IDE_ISP_3_CLOCKS; |
| 44 | ideTimingConfig |= IDE_RCT_1_CLOCKS; |
| 45 | ideTimingConfig |= IDE_IE0; |
| 46 | ideTimingConfig |= IDE_TIME0; // TIME0 |
Paul Menzel | 7f1df8c | 2015-10-11 15:48:36 +0200 | [diff] [blame] | 47 | printk(BIOS_DEBUG, " IDE0"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 48 | } |
| 49 | pci_write_config16(dev, IDE_TIM_PRI, ideTimingConfig); |
| 50 | |
| 51 | ideTimingConfig = pci_read_config16(dev, IDE_TIM_SEC); |
| 52 | ideTimingConfig &= ~IDE_DECODE_ENABLE; |
| 53 | ideTimingConfig |= IDE_SITRE; |
| 54 | if (enable_secondary) { |
| 55 | /* Enable secondary IDE interface. */ |
| 56 | ideTimingConfig |= IDE_DECODE_ENABLE; |
Elyes HAOUAS | ae22fe2 | 2020-05-21 09:04:16 +0200 | [diff] [blame] | 57 | ideTimingConfig |= IDE_ISP_3_CLOCKS; |
| 58 | ideTimingConfig |= IDE_RCT_1_CLOCKS; |
| 59 | ideTimingConfig |= IDE_IE0; |
| 60 | ideTimingConfig |= IDE_TIME0; |
Paul Menzel | 7f1df8c | 2015-10-11 15:48:36 +0200 | [diff] [blame] | 61 | printk(BIOS_DEBUG, " IDE1"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 62 | } |
| 63 | pci_write_config16(dev, IDE_TIM_SEC, ideTimingConfig); |
| 64 | |
| 65 | /* Set IDE I/O Configuration */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 66 | reg32 = 0; |
| 67 | /* FIXME: only set FAST_* for ata/100, only ?CBx for ata/66 */ |
| 68 | if (enable_primary) |
| 69 | reg32 |= SIG_MODE_PRI_NORMAL | FAST_PCB0 | PCB0 | FAST_PCB1 | PCB1; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 70 | if (enable_secondary) |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 71 | reg32 |= SIG_MODE_SEC_NORMAL | FAST_SCB0 | SCB0 | FAST_SCB1 | SCB1; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 72 | pci_write_config32(dev, IDE_CONFIG, reg32); |
| 73 | |
| 74 | /* Set Interrupt Line */ |
| 75 | /* Interrupt Pin is set by D31IP.PIP */ |
| 76 | pci_write_config32(dev, INTR_LN, 0xff); /* Int 15 */ |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 77 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 78 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 81 | static struct pci_operations ide_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 82 | .set_subsystem = pci_dev_set_subsystem, |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 85 | static struct device_operations ide_ops = { |
| 86 | .read_resources = pci_dev_read_resources, |
| 87 | .set_resources = pci_dev_set_resources, |
| 88 | .enable_resources = pci_dev_enable_resources, |
| 89 | .init = ide_init, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 90 | .enable = i82801gx_enable, |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 91 | .ops_pci = &ide_pci_ops, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 94 | /* 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] | 95 | static const struct pci_driver i82801gx_ide __pci_driver = { |
| 96 | .ops = &ide_ops, |
| 97 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 98 | .device = 0x27df, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 99 | }; |