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