blob: 381904ce55769c138a00aa3e77416e028936ce77 [file] [log] [blame]
Patrick Georgi02363b52020-05-05 20:48:50 +02001/* This file is part of the coreboot project. */
Patrick Georgiac959032020-05-05 22:49:26 +02002/* SPDX-License-Identifier: GPL-2.0-or-later */
Richard Smithcb8eab42006-07-24 04:25:47 +00003
Tobias Diedriche87c38e2010-11-27 09:40:16 +00004#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Tobias Diedriche87c38e2010-11-27 09:40:16 +00006#include <console/console.h>
Uwe Hermann9da69f82007-11-30 02:08:26 +00007#include <stdint.h>
Richard Smithcb8eab42006-07-24 04:25:47 +00008#include <device/device.h>
9#include <device/pci.h>
10#include <device/pci_ids.h>
Richard Smithcb8eab42006-07-24 04:25:47 +000011#include <device/smbus.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030012#include "chip.h"
Stefan Reinauera14b4682006-08-04 07:50:59 +000013#include "i82371eb.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000014
Tobias Diedriche87c38e2010-11-27 09:40:16 +000015static void pwrmgt_enable(struct device *dev)
16{
17 struct southbridge_intel_i82371eb_config *sb = dev->chip_info;
18 u32 reg, gpo = sb->gpo;
19
20 /* Sets the base address of power management ports. */
21 pci_write_config16(dev, PMBA, DEFAULT_PMBASE | 1);
22
23 /* Set Power Management IO Space Enable bit */
24 u8 val = pci_read_config8(dev, PMREGMISC);
25 pci_write_config8(dev, PMREGMISC, val | 1);
26
27 /* set global control:
28 * bit25 (lid_pol): 1=invert lid polarity
29 * bit24 (sm_freeze): 1=freeze idle and standby timers
30 * bit16 (end of smi): 0=disable smi assertion (cleared by hw)
31 * bits8-15,26: global standby timer inital count 127 * 4minutes
32 * bit2 (thrm_pol): 1=active low THRM#
33 * bit0 (smi_en): 1=disable smi generation upon smi event
34 */
35 reg = (sb->lid_polarity<<25)|
36 (1<<24)|
37 (0xff<<8)|
38 (sb->thrm_polarity<<2);
39 outl(reg, DEFAULT_PMBASE + GLBCTL);
40
41 /* set processor control:
42 * bit12 (stpclk_en): 1=enable stopping of host clk on lvl3
43 * bit11 (sleep_en): 1=enable slp# assertion on lvl3
44 * bit9 (cc_en): 1=enable clk control with lvl2 and lvl3 regs
45 */
46 outl(0, DEFAULT_PMBASE + PCNTRL);
47
48 /* disable smi event enables */
49 outw(0, DEFAULT_PMBASE + GLBEN);
50 outl(0, DEFAULT_PMBASE + DEVCTL);
51
52 /* set default gpo value.
53 * power-on default is 0x7fffbfffh */
54 if (gpo) {
55 /* only 8bit access allowed */
Elyes HAOUASa342f392018-10-17 10:56:26 +020056 outb(gpo & 0xff, DEFAULT_PMBASE + GPO0);
Tobias Diedriche87c38e2010-11-27 09:40:16 +000057 outb((gpo >> 8) & 0xff, DEFAULT_PMBASE + GPO1);
58 outb((gpo >> 16) & 0xff, DEFAULT_PMBASE + GPO2);
59 outb((gpo >> 24) & 0xff, DEFAULT_PMBASE + GPO3);
60 } else {
61 printk(BIOS_SPEW,
62 "%s: gpo default missing in devicetree.cb!\n", __func__);
63 }
64
65 /* Clear status events. */
66 outw(0xffff, DEFAULT_PMBASE + PMSTS);
67 outw(0xffff, DEFAULT_PMBASE + GPSTS);
68 outw(0xffff, DEFAULT_PMBASE + GLBSTS);
69 outl(0xffffffff, DEFAULT_PMBASE + DEVSTS);
70
Tobias Diedrich4e22a3b2010-12-13 22:39:46 +010071 /* set PMCNTRL default */
Tobias Diedriche87c38e2010-11-27 09:40:16 +000072 outw(SUS_TYP_S0|SCI_EN, DEFAULT_PMBASE + PMCNTRL);
73}
74
75static void pwrmgt_read_resources(struct device *dev)
76{
77 struct resource *res;
78
79 pci_dev_read_resources(dev);
80
81 res = new_resource(dev, 1);
82 res->base = DEFAULT_PMBASE;
83 res->size = 0x0040;
84 res->limit = 0xffff;
85 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
86 IORESOURCE_RESERVE;
87
88 res = new_resource(dev, 2);
89 res->base = SMBUS_IO_BASE;
90 res->size = 0x0010;
91 res->limit = 0xffff;
92 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
93 IORESOURCE_RESERVE;
94}
95
96
Uwe Hermann9da69f82007-11-30 02:08:26 +000097static const struct smbus_bus_operations lops_smbus_bus = {
Richard Smithcb8eab42006-07-24 04:25:47 +000098};
99
Uwe Hermann9da69f82007-11-30 02:08:26 +0000100static const struct device_operations smbus_ops = {
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000101 .read_resources = pwrmgt_read_resources,
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000102 .set_resources = pci_dev_set_resources,
103 .enable_resources = pci_dev_enable_resources,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200104 .scan_bus = scan_smbus,
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000105 .enable = pwrmgt_enable,
Uwe Hermann56a91252007-06-03 16:57:27 +0000106 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000107 .ops_smbus_bus = &lops_smbus_bus,
Richard Smithcb8eab42006-07-24 04:25:47 +0000108};
109
Uwe Hermann9da69f82007-11-30 02:08:26 +0000110/* Note: There's no SMBus on 82371FB/SB/MX and 82437MX. */
111
112/* Intel 82371AB/EB/MB */
Stefan Reinauerf1cf1f72007-10-24 09:08:58 +0000113static const struct pci_driver smbus_driver __pci_driver = {
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000114 .ops = &smbus_ops,
115 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann447aafe2007-11-29 01:44:43 +0000116 .device = PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI,
Richard Smithcb8eab42006-07-24 04:25:47 +0000117};