Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de> |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 5 | * 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 Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 8 | * |
| 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. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 21 | * Foundation, Inc. |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 22 | */ |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 23 | |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 24 | #include <arch/io.h> |
| 25 | #include <console/console.h> |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 26 | #include <stdint.h> |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 27 | #include <device/device.h> |
| 28 | #include <device/pci.h> |
| 29 | #include <device/pci_ids.h> |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 30 | #include <device/smbus.h> |
Stefan Reinauer | a14b468 | 2006-08-04 07:50:59 +0000 | [diff] [blame] | 31 | #include "i82371eb.h" |
stepan | 836ae29 | 2010-12-08 05:42:47 +0000 | [diff] [blame] | 32 | #include "smbus.h" |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 33 | |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 34 | static void pwrmgt_enable(struct device *dev) |
| 35 | { |
| 36 | struct southbridge_intel_i82371eb_config *sb = dev->chip_info; |
| 37 | u32 reg, gpo = sb->gpo; |
| 38 | |
| 39 | /* Sets the base address of power management ports. */ |
| 40 | pci_write_config16(dev, PMBA, DEFAULT_PMBASE | 1); |
| 41 | |
| 42 | /* Set Power Management IO Space Enable bit */ |
| 43 | u8 val = pci_read_config8(dev, PMREGMISC); |
| 44 | pci_write_config8(dev, PMREGMISC, val | 1); |
| 45 | |
| 46 | /* set global control: |
| 47 | * bit25 (lid_pol): 1=invert lid polarity |
| 48 | * bit24 (sm_freeze): 1=freeze idle and standby timers |
| 49 | * bit16 (end of smi): 0=disable smi assertion (cleared by hw) |
| 50 | * bits8-15,26: global standby timer inital count 127 * 4minutes |
| 51 | * bit2 (thrm_pol): 1=active low THRM# |
| 52 | * bit0 (smi_en): 1=disable smi generation upon smi event |
| 53 | */ |
| 54 | reg = (sb->lid_polarity<<25)| |
| 55 | (1<<24)| |
| 56 | (0xff<<8)| |
| 57 | (sb->thrm_polarity<<2); |
| 58 | outl(reg, DEFAULT_PMBASE + GLBCTL); |
| 59 | |
| 60 | /* set processor control: |
| 61 | * bit12 (stpclk_en): 1=enable stopping of host clk on lvl3 |
| 62 | * bit11 (sleep_en): 1=enable slp# assertion on lvl3 |
| 63 | * bit9 (cc_en): 1=enable clk control with lvl2 and lvl3 regs |
| 64 | */ |
| 65 | outl(0, DEFAULT_PMBASE + PCNTRL); |
| 66 | |
| 67 | /* disable smi event enables */ |
| 68 | outw(0, DEFAULT_PMBASE + GLBEN); |
| 69 | outl(0, DEFAULT_PMBASE + DEVCTL); |
| 70 | |
| 71 | /* set default gpo value. |
| 72 | * power-on default is 0x7fffbfffh */ |
| 73 | if (gpo) { |
| 74 | /* only 8bit access allowed */ |
| 75 | outb( gpo & 0xff, DEFAULT_PMBASE + GPO0); |
| 76 | outb((gpo >> 8) & 0xff, DEFAULT_PMBASE + GPO1); |
| 77 | outb((gpo >> 16) & 0xff, DEFAULT_PMBASE + GPO2); |
| 78 | outb((gpo >> 24) & 0xff, DEFAULT_PMBASE + GPO3); |
| 79 | } else { |
| 80 | printk(BIOS_SPEW, |
| 81 | "%s: gpo default missing in devicetree.cb!\n", __func__); |
| 82 | } |
| 83 | |
| 84 | /* Clear status events. */ |
| 85 | outw(0xffff, DEFAULT_PMBASE + PMSTS); |
| 86 | outw(0xffff, DEFAULT_PMBASE + GPSTS); |
| 87 | outw(0xffff, DEFAULT_PMBASE + GLBSTS); |
| 88 | outl(0xffffffff, DEFAULT_PMBASE + DEVSTS); |
| 89 | |
Tobias Diedrich | 4e22a3b | 2010-12-13 22:39:46 +0100 | [diff] [blame] | 90 | /* set PMCNTRL default */ |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 91 | outw(SUS_TYP_S0|SCI_EN, DEFAULT_PMBASE + PMCNTRL); |
| 92 | } |
| 93 | |
| 94 | static void pwrmgt_read_resources(struct device *dev) |
| 95 | { |
| 96 | struct resource *res; |
| 97 | |
| 98 | pci_dev_read_resources(dev); |
| 99 | |
| 100 | res = new_resource(dev, 1); |
| 101 | res->base = DEFAULT_PMBASE; |
| 102 | res->size = 0x0040; |
| 103 | res->limit = 0xffff; |
| 104 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED | |
| 105 | IORESOURCE_RESERVE; |
| 106 | |
| 107 | res = new_resource(dev, 2); |
| 108 | res->base = SMBUS_IO_BASE; |
| 109 | res->size = 0x0010; |
| 110 | res->limit = 0xffff; |
| 111 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED | |
| 112 | IORESOURCE_RESERVE; |
| 113 | } |
| 114 | |
| 115 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 116 | static const struct smbus_bus_operations lops_smbus_bus = { |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 119 | static const struct device_operations smbus_ops = { |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 120 | .read_resources = pwrmgt_read_resources, |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 121 | .set_resources = pci_dev_set_resources, |
| 122 | .enable_resources = pci_dev_enable_resources, |
| 123 | .init = 0, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame^] | 124 | .scan_bus = scan_smbus, |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 125 | .enable = pwrmgt_enable, |
Uwe Hermann | 56a9125 | 2007-06-03 16:57:27 +0000 | [diff] [blame] | 126 | .ops_pci = 0, /* No subsystem IDs on 82371EB! */ |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 127 | .ops_smbus_bus = &lops_smbus_bus, |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 130 | /* Note: There's no SMBus on 82371FB/SB/MX and 82437MX. */ |
| 131 | |
| 132 | /* Intel 82371AB/EB/MB */ |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 133 | static const struct pci_driver smbus_driver __pci_driver = { |
Uwe Hermann | 1410c2d | 2007-05-29 10:37:52 +0000 | [diff] [blame] | 134 | .ops = &smbus_ops, |
| 135 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 447aafe | 2007-11-29 01:44:43 +0000 | [diff] [blame] | 136 | .device = PCI_DEVICE_ID_INTEL_82371AB_SMB_ACPI, |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 137 | }; |