blob: 4c1594b4ffa0a869b692dd8d12e3771f665a0c8a [file] [log] [blame]
Patrick Georgi02363b52020-05-05 20:48:50 +02001/* This file is part of the coreboot project. */
Richard Smithcb8eab42006-07-24 04:25:47 +00002/*
Uwe Hermann1410c2d2007-05-29 10:37:52 +00003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Uwe Hermann1410c2d2007-05-29 10:37:52 +000013 */
Richard Smithcb8eab42006-07-24 04:25:47 +000014
Tobias Diedriche87c38e2010-11-27 09:40:16 +000015#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020016#include <device/pci_ops.h>
Tobias Diedriche87c38e2010-11-27 09:40:16 +000017#include <console/console.h>
Uwe Hermann9da69f82007-11-30 02:08:26 +000018#include <stdint.h>
Richard Smithcb8eab42006-07-24 04:25:47 +000019#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
Richard Smithcb8eab42006-07-24 04:25:47 +000022#include <device/smbus.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030023#include "chip.h"
Stefan Reinauera14b4682006-08-04 07:50:59 +000024#include "i82371eb.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000025
Tobias Diedriche87c38e2010-11-27 09:40:16 +000026static void pwrmgt_enable(struct device *dev)
27{
28 struct southbridge_intel_i82371eb_config *sb = dev->chip_info;
29 u32 reg, gpo = sb->gpo;
30
31 /* Sets the base address of power management ports. */
32 pci_write_config16(dev, PMBA, DEFAULT_PMBASE | 1);
33
34 /* Set Power Management IO Space Enable bit */
35 u8 val = pci_read_config8(dev, PMREGMISC);
36 pci_write_config8(dev, PMREGMISC, val | 1);
37
38 /* set global control:
39 * bit25 (lid_pol): 1=invert lid polarity
40 * bit24 (sm_freeze): 1=freeze idle and standby timers
41 * bit16 (end of smi): 0=disable smi assertion (cleared by hw)
42 * bits8-15,26: global standby timer inital count 127 * 4minutes
43 * bit2 (thrm_pol): 1=active low THRM#
44 * bit0 (smi_en): 1=disable smi generation upon smi event
45 */
46 reg = (sb->lid_polarity<<25)|
47 (1<<24)|
48 (0xff<<8)|
49 (sb->thrm_polarity<<2);
50 outl(reg, DEFAULT_PMBASE + GLBCTL);
51
52 /* set processor control:
53 * bit12 (stpclk_en): 1=enable stopping of host clk on lvl3
54 * bit11 (sleep_en): 1=enable slp# assertion on lvl3
55 * bit9 (cc_en): 1=enable clk control with lvl2 and lvl3 regs
56 */
57 outl(0, DEFAULT_PMBASE + PCNTRL);
58
59 /* disable smi event enables */
60 outw(0, DEFAULT_PMBASE + GLBEN);
61 outl(0, DEFAULT_PMBASE + DEVCTL);
62
63 /* set default gpo value.
64 * power-on default is 0x7fffbfffh */
65 if (gpo) {
66 /* only 8bit access allowed */
Elyes HAOUASa342f392018-10-17 10:56:26 +020067 outb(gpo & 0xff, DEFAULT_PMBASE + GPO0);
Tobias Diedriche87c38e2010-11-27 09:40:16 +000068 outb((gpo >> 8) & 0xff, DEFAULT_PMBASE + GPO1);
69 outb((gpo >> 16) & 0xff, DEFAULT_PMBASE + GPO2);
70 outb((gpo >> 24) & 0xff, DEFAULT_PMBASE + GPO3);
71 } else {
72 printk(BIOS_SPEW,
73 "%s: gpo default missing in devicetree.cb!\n", __func__);
74 }
75
76 /* Clear status events. */
77 outw(0xffff, DEFAULT_PMBASE + PMSTS);
78 outw(0xffff, DEFAULT_PMBASE + GPSTS);
79 outw(0xffff, DEFAULT_PMBASE + GLBSTS);
80 outl(0xffffffff, DEFAULT_PMBASE + DEVSTS);
81
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +010082 /* set PMCNTRL default */
Tobias Diedriche87c38e2010-11-27 09:40:16 +000083 outw(SUS_TYP_S0|SCI_EN, DEFAULT_PMBASE + PMCNTRL);
84}
85
86static void pwrmgt_read_resources(struct device *dev)
87{
88 struct resource *res;
89
90 pci_dev_read_resources(dev);
91
92 res = new_resource(dev, 1);
93 res->base = DEFAULT_PMBASE;
94 res->size = 0x0040;
95 res->limit = 0xffff;
96 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
97 IORESOURCE_RESERVE;
98
99 res = new_resource(dev, 2);
100 res->base = SMBUS_IO_BASE;
101 res->size = 0x0010;
102 res->limit = 0xffff;
103 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
104 IORESOURCE_RESERVE;
105}
106
107
Uwe Hermann9da69f82007-11-30 02:08:26 +0000108static const struct smbus_bus_operations lops_smbus_bus = {
Richard Smithcb8eab42006-07-24 04:25:47 +0000109};
110
Uwe Hermann9da69f82007-11-30 02:08:26 +0000111static const struct device_operations smbus_ops = {
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000112 .read_resources = pwrmgt_read_resources,
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000113 .set_resources = pci_dev_set_resources,
114 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200115 .scan_bus = scan_smbus,
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000116 .enable = pwrmgt_enable,
Uwe Hermann56a91252007-06-03 16:57:27 +0000117 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000118 .ops_smbus_bus = &lops_smbus_bus,
Richard Smithcb8eab42006-07-24 04:25:47 +0000119};
120
Uwe Hermann9da69f82007-11-30 02:08:26 +0000121/* Note: There's no SMBus on 82371FB/SB/MX and 82437MX. */
122
123/* Intel 82371AB/EB/MB */
Stefan Reinauerf1cf1f72007-10-24 09:08:58 +0000124static const struct pci_driver smbus_driver __pci_driver = {
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000125 .ops = &smbus_ops,
126 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann447aafe2007-11-29 01:44:43 +0000127 .device = PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI,
Richard Smithcb8eab42006-07-24 04:25:47 +0000128};