blob: d3f0122f22cef2315c3b73d17f67788a1c75e7d9 [file] [log] [blame]
Arthur Heymans7b9c1392017-04-09 20:40:39 +02001/*
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älkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Arthur Heymans7b9c1392017-04-09 20:40:39 +020020#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23
Arthur Heymans349e0852017-04-09 20:48:37 +020024#include "i82801jx.h"
Arthur Heymans7b9c1392017-04-09 20:40:39 +020025
26static void thermal_init(struct device *dev)
27{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030028 if (LPC_IS_MOBILE(pcidev_on_root(0x1f, 0)))
Arthur Heymans7b9c1392017-04-09 20:40:39 +020029 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 HAOUAS1a8c1df2018-05-13 13:36:44 +020054static void thermal_set_subsystem(struct device *dev, unsigned vendor,
55 unsigned device)
Arthur Heymans7b9c1392017-04-09 20:40:39 +020056{
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
66static struct pci_operations thermal_pci_ops = {
67 .set_subsystem = thermal_set_subsystem,
68};
69
70static 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 Heymans349e0852017-04-09 20:48:37 +020079static const unsigned short pci_device_ids[] = {
80 0x3a32,
81 0x3a62,
82 0
83};
84
85static const struct pci_driver ich10_thermal __pci_driver = {
Arthur Heymans7b9c1392017-04-09 20:40:39 +020086 .ops = &device_ops,
87 .vendor = PCI_VENDOR_ID_INTEL,
Arthur Heymans349e0852017-04-09 20:48:37 +020088 .devices = pci_device_ids,
Arthur Heymans7b9c1392017-04-09 20:40:39 +020089};