Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2004 Ron G. Minnich |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
Stefan Reinauer | 138be83 | 2010-02-27 01:50:21 +0000 | [diff] [blame] | 19 | #include "i82801dx.h" |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 20 | |
Elyes HAOUAS | 66faf0c | 2018-05-13 13:32:56 +0200 | [diff] [blame] | 21 | void i82801dx_enable(struct device *dev) |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 22 | { |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 23 | unsigned int index = 0; |
| 24 | uint8_t bHasDisableBit = 0; |
| 25 | uint16_t cur_disable_mask, new_disable_mask; |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 26 | |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 27 | // all 82801dbm devices are in bus 0 |
| 28 | unsigned int devfn = PCI_DEVFN(0x1f, 0); // lpc |
Kyösti Mälkki | e737755 | 2018-06-21 16:20:55 +0300 | [diff] [blame^] | 29 | struct device *lpc_dev = pcidev_path_on_root(devfn); // 0 |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 30 | if (!lpc_dev) |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 31 | return; |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 32 | |
| 33 | // Calculate disable bit position for specified device:function |
| 34 | // NOTE: For ICH-4, only the following devices can be disabled: |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 35 | // D31: F0, F1, F3, F5, F6, |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 36 | // D29: F0, F1, F2, F7 |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 37 | |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 38 | if (PCI_SLOT(dev->path.pci.devfn) == 31) { |
| 39 | index = PCI_FUNC(dev->path.pci.devfn); |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 40 | |
| 41 | switch (index) { |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 42 | case 0: |
| 43 | case 1: |
| 44 | case 3: |
| 45 | case 5: |
| 46 | case 6: |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 47 | bHasDisableBit = 1; |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 48 | break; |
| 49 | |
| 50 | default: |
| 51 | break; |
| 52 | }; |
| 53 | |
| 54 | if (index == 0) |
| 55 | index = 14; // D31:F0 bit is an exception |
| 56 | |
| 57 | } else if (PCI_SLOT(dev->path.pci.devfn) == 29) { |
| 58 | index = 8 + PCI_FUNC(dev->path.pci.devfn); |
| 59 | |
| 60 | if ((PCI_FUNC(dev->path.pci.devfn) < 3) |
| 61 | || (PCI_FUNC(dev->path.pci.devfn) == 7)) |
| 62 | bHasDisableBit = 1; |
| 63 | } |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 64 | |
| 65 | if (bHasDisableBit) { |
| 66 | cur_disable_mask = pci_read_config16(lpc_dev, FUNC_DIS); |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 67 | new_disable_mask = cur_disable_mask & ~(1 << index); // enable it |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 68 | if (!dev->enabled) { |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 69 | new_disable_mask |= (1 << index); // disable it |
Steven J. Magnani | 7557331 | 2005-09-21 13:49:44 +0000 | [diff] [blame] | 70 | } |
| 71 | if (new_disable_mask != cur_disable_mask) { |
| 72 | pci_write_config16(lpc_dev, FUNC_DIS, new_disable_mask); |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Stefan Reinauer | 138be83 | 2010-02-27 01:50:21 +0000 | [diff] [blame] | 77 | struct chip_operations southbridge_intel_i82801dx_ops = { |
| 78 | CHIP_NAME("Intel ICH4/ICH4-M (82801Dx) Series Southbridge") |
Stefan Reinauer | 8702ab5 | 2010-03-14 17:01:08 +0000 | [diff] [blame] | 79 | .enable_dev = i82801dx_enable, |
Ronald G. Minnich | 182615d | 2004-08-24 16:20:46 +0000 | [diff] [blame] | 80 | }; |