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