Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 secunet Security Networks AG |
| 5 | * (Written by Nico Huber <nico.huber@secunet.com> for secunet) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; version 2 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 19 | #include <device/pci_ops.h> |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 20 | #include <device/device.h> |
| 21 | #include <device/pci.h> |
| 22 | #include <device/pci_ids.h> |
| 23 | |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 24 | #include "i82801jx.h" |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 25 | |
| 26 | static void thermal_init(struct device *dev) |
| 27 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 28 | if (LPC_IS_MOBILE(pcidev_on_root(0x1f, 0))) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 29 | return; |
| 30 | |
| 31 | u8 reg8; |
| 32 | u32 reg32; |
| 33 | |
| 34 | pci_write_config32(dev, 0x10, (uintptr_t)DEFAULT_TBAR); |
| 35 | reg32 = pci_read_config32(dev, 0x04); |
| 36 | pci_write_config32(dev, 0x04, reg32 | (1 << 1)); |
| 37 | |
| 38 | write32(DEFAULT_TBAR + 0x04, 0); /* Clear thermal trip points. */ |
| 39 | write32(DEFAULT_TBAR + 0x44, 0); |
| 40 | |
| 41 | write8(DEFAULT_TBAR + 0x01, 0xba); /* Enable sensor 0 + 1. */ |
| 42 | write8(DEFAULT_TBAR + 0x41, 0xba); |
| 43 | |
| 44 | reg8 = read8(DEFAULT_TBAR + 0x08); /* Lock thermal registers. */ |
| 45 | write8(DEFAULT_TBAR + 0x08, reg8 | (1 << 7)); |
| 46 | reg8 = read8(DEFAULT_TBAR + 0x48); |
| 47 | write8(DEFAULT_TBAR + 0x48, reg8 | (1 << 7)); |
| 48 | |
| 49 | reg32 = pci_read_config32(dev, 0x04); |
| 50 | pci_write_config32(dev, 0x04, reg32 & ~(1 << 1)); |
| 51 | pci_write_config32(dev, 0x10, 0); |
| 52 | } |
| 53 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 54 | static void thermal_set_subsystem(struct device *dev, unsigned vendor, |
| 55 | unsigned device) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 56 | { |
| 57 | if (!vendor || !device) { |
| 58 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 59 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 60 | } else { |
| 61 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 62 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | static struct pci_operations thermal_pci_ops = { |
| 67 | .set_subsystem = thermal_set_subsystem, |
| 68 | }; |
| 69 | |
| 70 | static struct device_operations device_ops = { |
| 71 | .read_resources = pci_dev_read_resources, |
| 72 | .set_resources = pci_dev_set_resources, |
| 73 | .enable_resources = pci_dev_enable_resources, |
| 74 | .init = thermal_init, |
| 75 | .scan_bus = 0, |
| 76 | .ops_pci = &thermal_pci_ops, |
| 77 | }; |
| 78 | |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 79 | static const unsigned short pci_device_ids[] = { |
| 80 | 0x3a32, |
| 81 | 0x3a62, |
| 82 | 0 |
| 83 | }; |
| 84 | |
| 85 | static const struct pci_driver ich10_thermal __pci_driver = { |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 86 | .ops = &device_ops, |
| 87 | .vendor = PCI_VENDOR_ID_INTEL, |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 88 | .devices = pci_device_ids, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 89 | }; |