2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <device/pci_ops.h>
30 static device_t find_sm_dev(device_t dev, u32 devfn)
34 sm_dev = dev_find_slot(dev->bus->secondary, devfn);
38 if ((sm_dev->vendor != PCI_VENDOR_ID_ATI) ||
39 ((sm_dev->device != PCI_DEVICE_ID_ATI_SB700_SM))) {
41 id = pci_read_config32(sm_dev, PCI_VENDOR_ID);
43 (PCI_VENDOR_ID_ATI | (PCI_DEVICE_ID_ATI_SB700_SM << 16))))
52 void set_sm_enable_bits(device_t sm_dev, u32 reg_pos, u32 mask, u32 val)
55 reg = reg_old = pci_read_config32(sm_dev, reg_pos);
59 pci_write_config32(sm_dev, reg_pos, reg);
63 static void pmio_write_index(u16 port_base, u8 reg, u8 value)
66 outb(value, port_base + 1);
69 static u8 pmio_read_index(u16 port_base, u8 reg)
72 return inb(port_base + 1);
75 void pm_iowrite(u8 reg, u8 value)
77 pmio_write_index(PM_INDEX, reg, value);
82 return pmio_read_index(PM_INDEX, reg);
85 void pm2_iowrite(u8 reg, u8 value)
87 pmio_write_index(PM2_INDEX, reg, value);
92 return pmio_read_index(PM2_INDEX, reg);
95 static void set_pmio_enable_bits(device_t sm_dev, u32 reg_pos,
99 reg = reg_old = pm_ioread(reg_pos);
102 if (reg != reg_old) {
103 pm_iowrite(reg_pos, reg);
107 void sb700_enable(device_t dev)
110 device_t bus_dev = 0;
115 /* struct southbridge_ati_sb700_config *conf; */
116 /* conf = dev->chip_info; */
121 printk(BIOS_DEBUG, "sb700_enable()\n");
124 * 0:11.0 SATA bit 8 of sm_dev 0xac : 1 - enable, default + 32 * 3
125 * 0:12.0 OHCI0-USB1 bit 0 of sm_dev 0x68
126 * 0:12.1 OHCI1-USB1 bit 1 of sm_dev 0x68
127 * 0:12.2 EHCI-USB1 bit 2 of sm_dev 0x68
128 * 0:13.0 OHCI0-USB2 bit 4 of sm_dev 0x68
129 * 0:13.1 OHCI1-USB2 bit 5 of sm_dev 0x68
130 * 0:13.2 EHCI-USB2 bit 6 of sm_dev 0x68
131 * 0:14.5 OHCI0-USB3 bit 7 of sm_dev 0x68
134 * 0:14.2 HDA bit 3 of pm_io 0x59 : 1 - enable, default + 32 * 4
135 * 0:14.3 LPC bit 20 of sm_dev 0x64 : 0 - disable, default + 32 * 1
138 if (dev->device == 0x0000) {
139 vendorid = pci_read_config32(dev, PCI_VENDOR_ID);
140 deviceid = (vendorid >> 16) & 0xffff;
143 vendorid = dev->vendor;
144 deviceid = dev->device;
146 bus_dev = dev->bus->dev;
147 if ((bus_dev->vendor == PCI_VENDOR_ID_ATI) &&
148 (bus_dev->device == PCI_DEVICE_ID_ATI_SB700_PCI)) {
149 devfn = (bus_dev->path.pci.devfn) & ~7;
150 sm_dev = find_sm_dev(bus_dev, devfn);
154 /* something under 00:01.0 */
155 switch (dev->path.pci.devfn) {
163 i = (dev->path.pci.devfn) & ~7;
165 for (devfn = (0x14 << 3); devfn <= i; devfn += (1 << 3)) {
166 sm_dev = find_sm_dev(dev, devfn);
173 switch (dev->path.pci.devfn - (devfn - (0x14 << 3))) {
174 case (0x11 << 3) | 0:
176 set_sm_enable_bits(sm_dev, 0xac, 1 << index,
177 (dev->enabled ? 1 : 0) << index);
180 case (0x12 << 3) | 0:
181 case (0x12 << 3) | 1:
182 case (0x12 << 3) | 2:
183 index = dev->path.pci.devfn & 3;
184 set_sm_enable_bits(sm_dev, 0x68, 1 << index,
185 (dev->enabled ? 1 : 0) << index);
188 case (0x13 << 3) | 0:
189 case (0x13 << 3) | 1:
190 case (0x13 << 3) | 2:
191 index = (dev->path.pci.devfn & 3) + 4;
192 set_sm_enable_bits(sm_dev, 0x68, 1 << index,
193 (dev->enabled ? 1 : 0) << index);
196 case (0x14 << 3) | 5:
198 set_sm_enable_bits(sm_dev, 0x68, 1 << index,
199 (dev->enabled ? 1 : 0) << index);
202 case (0x14 << 3) | 0:
205 case (0x14 << 3) | 1:
208 case (0x14 << 3) | 2:
210 set_pmio_enable_bits(sm_dev, 0x59, 1 << index,
211 (dev->enabled ? 1 : 0) << index);
214 case (0x14 << 3) | 3:
216 set_sm_enable_bits(sm_dev, 0x64, 1 << index,
217 (dev->enabled ? 1 : 0) << index);
220 case (0x14 << 3) | 4:
224 printk(BIOS_DEBUG, "unknown dev: %s deviceid=%4x\n", dev_path(dev),
229 struct chip_operations southbridge_amd_sb700_ops = {
230 CHIP_NAME("ATI SB700")
231 .enable_dev = sb700_enable,