Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 2 | |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 3 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 5 | #include <console/console.h> |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 6 | #include <stdint.h> |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
| 9 | #include <device/pci_ids.h> |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 10 | #include <device/smbus.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 11 | #include "chip.h" |
Stefan Reinauer | a14b468 | 2006-08-04 07:50:59 +0000 | [diff] [blame] | 12 | #include "i82371eb.h" |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 13 | |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 14 | static 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 Roth | 26f97f9 | 2021-10-01 14:53:22 -0600 | [diff] [blame] | 30 | * bits8-15,26: global standby timer initial count 127 * 4minutes |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 31 | * 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 HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 55 | outb(gpo & 0xff, DEFAULT_PMBASE + GPO0); |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 56 | 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 Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 70 | /* set PMCNTRL default */ |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 71 | outw(SUS_TYP_S0|SCI_EN, DEFAULT_PMBASE + PMCNTRL); |
| 72 | } |
| 73 | |
| 74 | static 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 Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 95 | static const struct smbus_bus_operations lops_smbus_bus = { |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 98 | static const struct device_operations smbus_ops = { |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 99 | .read_resources = pwrmgt_read_resources, |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 100 | .set_resources = pci_dev_set_resources, |
| 101 | .enable_resources = pci_dev_enable_resources, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 102 | .scan_bus = scan_smbus, |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 103 | .enable = pwrmgt_enable, |
Uwe Hermann | 56a9125 | 2007-06-03 16:57:27 +0000 | [diff] [blame] | 104 | .ops_pci = 0, /* No subsystem IDs on 82371EB! */ |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 105 | .ops_smbus_bus = &lops_smbus_bus, |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 108 | /* Note: There's no SMBus on 82371FB/SB/MX and 82437MX. */ |
| 109 | |
| 110 | /* Intel 82371AB/EB/MB */ |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 111 | static const struct pci_driver smbus_driver __pci_driver = { |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 112 | .ops = &smbus_ops, |
| 113 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 447aafe | 2007-11-29 01:44:43 +0000 | [diff] [blame] | 114 | .device = PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI, |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 115 | }; |