Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 3 | |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 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 | 138be83 | 2010-02-27 01:50:21 +0000 | [diff] [blame] | 7 | #include "i82801dx.h" |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 8 | |
Elyes HAOUAS | 66faf0c | 2018-05-13 13:32:56 +0200 | [diff] [blame] | 9 | void i82801dx_enable(struct device *dev) |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 10 | { |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 11 | unsigned int index = 0; |
| 12 | uint8_t bHasDisableBit = 0; |
| 13 | uint16_t cur_disable_mask, new_disable_mask; |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 14 | |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 15 | // all 82801dbm devices are in bus 0 |
| 16 | unsigned int devfn = PCI_DEVFN(0x1f, 0); // lpc |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame] | 17 | struct device *lpc_dev = pcidev_path_on_root(devfn); // 0 |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 18 | if (!lpc_dev) |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 19 | return; |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 20 | |
| 21 | // Calculate disable bit position for specified device:function |
| 22 | // NOTE: For ICH-4, only the following devices can be disabled: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 23 | // D31: F0, F1, F3, F5, F6, |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 24 | // D29: F0, F1, F2, F7 |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 25 | |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 26 | if (PCI_SLOT(dev->path.pci.devfn) == 31) { |
| 27 | index = PCI_FUNC(dev->path.pci.devfn); |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 28 | |
| 29 | switch (index) { |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 30 | case 0: |
| 31 | case 1: |
| 32 | case 3: |
| 33 | case 5: |
| 34 | case 6: |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 35 | bHasDisableBit = 1; |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 36 | break; |
| 37 | |
| 38 | default: |
| 39 | break; |
| 40 | }; |
| 41 | |
| 42 | if (index == 0) |
| 43 | index = 14; // D31:F0 bit is an exception |
| 44 | |
| 45 | } else if (PCI_SLOT(dev->path.pci.devfn) == 29) { |
| 46 | index = 8 + PCI_FUNC(dev->path.pci.devfn); |
| 47 | |
| 48 | if ((PCI_FUNC(dev->path.pci.devfn) < 3) |
| 49 | || (PCI_FUNC(dev->path.pci.devfn) == 7)) |
| 50 | bHasDisableBit = 1; |
| 51 | } |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 52 | |
| 53 | if (bHasDisableBit) { |
| 54 | cur_disable_mask = pci_read_config16(lpc_dev, FUNC_DIS); |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 55 | new_disable_mask = cur_disable_mask & ~(1 << index); // enable it |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 56 | if (!dev->enabled) { |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 57 | new_disable_mask |= (1 << index); // disable it |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 58 | } |
| 59 | if (new_disable_mask != cur_disable_mask) { |
| 60 | pci_write_config16(lpc_dev, FUNC_DIS, new_disable_mask); |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Stefan Reinauer | 138be83 | 2010-02-27 01:50:21 +0000 | [diff] [blame] | 65 | struct chip_operations southbridge_intel_i82801dx_ops = { |
| 66 | CHIP_NAME("Intel ICH4/ICH4-M (82801Dx) Series Southbridge") |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 67 | .enable_dev = i82801dx_enable, |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 68 | }; |