2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 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
21 #include <device/device.h> /* device_t */
22 #include <device/pci.h> /* device_operations */
23 #include <device/pci_ids.h>
24 #include <arch/ioapic.h>
25 #include <device/smbus.h> /* smbus_bus_operations */
26 #include <console/console.h> /* printk */
27 #include "lpc.h" /* lpc_read_resources */
28 #include "SBPLATFORM.h" /* Platfrom Specific Definitions */
29 #include "cfg.h" /* sb800 Cimx configuration */
30 #include "chip.h" /* struct southbridge_amd_cimx_sb800_config */
31 #include "sb_cimx.h" /* AMD CIMX wrapper entries */
34 /*implement in mainboard.c*/
35 void set_pcie_reset(void);
36 void set_pcie_dereset(void);
39 static AMDSBCFG sb_late_cfg; //global, init in sb800_cimx_config
40 static AMDSBCFG *sb_config = &sb_late_cfg;
44 * @brief Entry point of Southbridge CIMx callout
46 * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig)
48 * @param[in] func Southbridge CIMx Function ID.
49 * @param[in] data Southbridge Input Data.
50 * @param[in] sb_config Southbridge configuration structure pointer.
53 u32 sb800_callout_entry(u32 func, u32 data, void* config)
56 printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
58 case CB_SBGPP_RESET_ASSERT:
62 case CB_SBGPP_RESET_DEASSERT:
66 case IMC_FIRMWARE_FAIL:
73 printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
78 static struct pci_operations lops_pci = {
79 .set_subsystem = pci_dev_set_subsystem,
82 static struct device_operations lpc_ops = {
83 .read_resources = lpc_read_resources,
84 .set_resources = lpc_set_resources,
85 .enable_resources = pci_dev_enable_resources,
87 .scan_bus = scan_static_bus,
91 static const struct pci_driver lpc_driver __pci_driver = {
93 .vendor = PCI_VENDOR_ID_ATI,
94 .device = PCI_DEVICE_ID_ATI_SB800_LPC,
97 static struct device_operations sata_ops = {
98 .read_resources = pci_dev_read_resources,
99 .set_resources = pci_dev_set_resources,
100 .enable_resources = pci_dev_enable_resources,
103 .ops_pci = &lops_pci,
106 static const struct pci_driver sata_driver __pci_driver = {
108 .vendor = PCI_VENDOR_ID_ATI,
109 .device = PCI_DEVICE_ID_ATI_SB800_SATA_AHCI,
112 #if CONFIG_USBDEBUG == 1
113 static void usb_set_resources(struct device *dev)
115 struct resource *res;
119 printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
120 old_debug = get_ehci_debug();
123 pci_dev_set_resources(dev);
125 res = find_resource(dev, 0x10);
126 set_ehci_debug(old_debug);
131 report_resource_stored(dev, res, "");
132 printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
136 static struct device_operations usb_ops = {
137 .read_resources = pci_dev_read_resources,
139 .set_resources = usb_set_resources,
141 .set_resources = pci_dev_set_resources,
143 .enable_resources = pci_dev_enable_resources,
146 .ops_pci = &lops_pci,
150 * The pci id of usb ctrl 0 and 1 are the same.
152 static const struct pci_driver usb_ohci123_driver __pci_driver = {
154 .vendor = PCI_VENDOR_ID_ATI,
155 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
158 static const struct pci_driver usb_ehci123_driver __pci_driver = {
160 .vendor = PCI_VENDOR_ID_ATI,
161 .device = PCI_DEVICE_ID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
164 static const struct pci_driver usb_ohci4_driver __pci_driver = {
166 .vendor = PCI_VENDOR_ID_ATI,
167 .device = PCI_DEVICE_ID_ATI_SB800_USB_20_5, /* OHCI-USB4 */
171 static struct device_operations azalia_ops = {
172 .read_resources = pci_dev_read_resources,
173 .set_resources = pci_dev_set_resources,
174 .enable_resources = pci_dev_enable_resources,
177 .ops_pci = &lops_pci,
180 static const struct pci_driver azalia_driver __pci_driver = {
182 .vendor = PCI_VENDOR_ID_ATI,
183 .device = PCI_DEVICE_ID_ATI_SB800_HDA,
187 static struct device_operations gec_ops = {
188 .read_resources = pci_dev_read_resources,
189 .set_resources = pci_dev_set_resources,
190 .enable_resources = pci_dev_enable_resources,
193 .ops_pci = &lops_pci,
196 static const struct pci_driver gec_driver __pci_driver = {
198 .vendor = PCI_VENDOR_ID_ATI,
199 .device = PCI_DEVICE_ID_ATI_SB800_GEC,
203 * @brief Enable PCI Bridge
205 * PcibConfig [PM_Reg: EAh], PCIDisable [Bit0]
206 * 'PCIDisable' set to 0 to enable P2P bridge.
207 * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins
208 * to function as GPIO {GPIO 35:0}.
210 static void pci_init(device_t dev)
212 /* PCI Bridge SHOULD be enabled by default according to SB800 rrg,
213 * but actually was disabled in some platform, so I have to enabled it.
215 RWMEM(ACPI_MMIO_BASE + PMIO_BASE + SB_PMIOA_REGEA, AccWidthUint8, ~BIT0, 0);
219 static struct device_operations pci_ops = {
220 .read_resources = pci_bus_read_resources,
221 .set_resources = pci_dev_set_resources,
222 .enable_resources = pci_bus_enable_resources,
224 .scan_bus = pci_scan_bridge,
225 .reset_bus = pci_bus_reset,
226 .ops_pci = &lops_pci,
229 static const struct pci_driver pci_driver __pci_driver = {
231 .vendor = PCI_VENDOR_ID_ATI,
232 .device = PCI_DEVICE_ID_ATI_SB800_PCI,
236 struct device_operations bridge_ops = {
237 .read_resources = pci_bus_read_resources,
238 .set_resources = pci_dev_set_resources,
239 .enable_resources = pci_bus_enable_resources,
241 .scan_bus = pci_scan_bridge,
243 .reset_bus = pci_bus_reset,
244 .ops_pci = &lops_pci,
247 /* 0:15:0 PCIe PortA */
248 static const struct pci_driver PORTA_driver __pci_driver = {
250 .vendor = PCI_VENDOR_ID_ATI,
251 .device = PCI_DEVICE_ID_ATI_SB800_PCIEA,
254 /* 0:15:1 PCIe PortB */
255 static const struct pci_driver PORTB_driver __pci_driver = {
257 .vendor = PCI_VENDOR_ID_ATI,
258 .device = PCI_DEVICE_ID_ATI_SB800_PCIEB,
261 /* 0:15:2 PCIe PortC */
262 static const struct pci_driver PORTC_driver __pci_driver = {
264 .vendor = PCI_VENDOR_ID_ATI,
265 .device = PCI_DEVICE_ID_ATI_SB800_PCIEC,
268 /* 0:15:3 PCIe PortD */
269 static const struct pci_driver PORTD_driver __pci_driver = {
271 .vendor = PCI_VENDOR_ID_ATI,
272 .device = PCI_DEVICE_ID_ATI_SB800_PCIED,
277 * South Bridge CIMx ramstage entry point wrapper.
279 void sb_Before_Pci_Init(void)
281 sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
282 AmdSbDispatcher(sb_config);
285 void sb_After_Pci_Init(void)
287 sb_config->StdHeader.Func = SB_AFTER_PCI_INIT;
288 AmdSbDispatcher(sb_config);
291 void sb_Mid_Post_Init(void)
293 sb_config->StdHeader.Func = SB_MID_POST_INIT;
294 AmdSbDispatcher(sb_config);
297 void sb_Late_Post(void)
299 sb_config->StdHeader.Func = SB_LATE_POST_INIT;
300 AmdSbDispatcher(sb_config);
305 * @brief SB Cimx entry point sbBeforePciInit wrapper
307 static void sb800_enable(device_t dev)
309 struct southbridge_amd_cimx_sb800_config *sb_chip =
310 (struct southbridge_amd_cimx_sb800_config *)(dev->chip_info);
312 printk(BIOS_DEBUG, "sb800_enable() ");
314 switch (dev->path.pci.devfn) {
315 case (0x11 << 3) | 0: /* 0:11.0 SATA */
316 /* the first sb800 device */
317 sb800_cimx_config(sb_config);
320 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED;
321 if (1 == sb_chip->boot_switch_sata_ide)
322 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
323 else if (0 == sb_chip->boot_switch_sata_ide)
324 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
326 sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED;
330 case (0x14 << 3) | 0: /* 0:14:0 SMBUS */
331 printk(BIOS_INFO, "sm_init().\n");
332 clear_ioapic(IO_APIC_ADDR);
333 /* I/O APIC IDs are normally limited to 4-bits. Enforce this limit. */
334 #if (CONFIG_APIC_ID_OFFSET == 0 && CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS < 16)
335 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
336 setup_ioapic(IO_APIC_ADDR, CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS);
337 #elif (CONFIG_APIC_ID_OFFSET > 0)
338 /* Assign the ioapic ID the value 0. Processor APIC IDs follow. */
339 setup_ioapic(IO_APIC_ADDR, 0);
341 #error "The processor APIC IDs must be lifted to make room for the I/O APIC ID"
345 case (0x14 << 3) | 1: /* 0:14:1 IDE */
348 case (0x14 << 3) | 2: /* 0:14:2 HDA */
350 if (AZALIA_DISABLE == sb_config->AzaliaController) {
351 sb_config->AzaliaController = AZALIA_AUTO;
353 printk(BIOS_DEBUG, "hda enabled\n");
355 sb_config->AzaliaController = AZALIA_DISABLE;
356 printk(BIOS_DEBUG, "hda disabled\n");
361 case (0x14 << 3) | 3: /* 0:14:3 LPC */
364 case (0x14 << 3) | 4: /* 0:14:4 PCI */
367 case (0x14 << 3) | 6: /* 0:14:6 GEC */
369 sb_config->GecConfig = 0;
370 printk(BIOS_DEBUG, "gec enabled\n");
372 sb_config->GecConfig = 1;
373 printk(BIOS_DEBUG, "gec disabled\n");
377 case (0x15 << 3) | 0: /* 0:15:0 PCIe PortA */
380 for (device = dev; device; device = device->next) {
381 if (dev->path.type != DEVICE_PATH_PCI) continue;
382 if ((device->path.pci.devfn & ~7) != PCI_DEVFN(0x15,0)) break;
383 sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled;
387 * GPP_CFGMODE_X4000: PortA Lanes[3:0]
388 * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2]
389 * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3
390 * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3
392 sb_config->GppLinkConfig = sb_chip->gpp_configuration;
396 case (0x12 << 3) | 0: /* 0:12:0 OHCI-USB1 */
397 sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled;
399 case (0x12 << 3) | 2: /* 0:12:2 EHCI-USB1 */
400 sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled;
402 case (0x13 << 3) | 0: /* 0:13:0 OHCI-USB2 */
403 sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled;
405 case (0x13 << 3) | 2: /* 0:13:2 EHCI-USB2 */
406 sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled;
408 case (0x14 << 3) | 5: /* 0:14:5 OHCI-USB4 */
409 sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled;
411 case (0x16 << 3) | 0: /* 0:16:0 OHCI-USB3 */
412 sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled;
414 case (0x16 << 3) | 2: /* 0:16:2 EHCI-USB3 */
415 sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled;
417 /* call the CIMX entry at the last sb800 device,
418 * so make sure the mainboard devicetree is complete
420 sb_Before_Pci_Init();
428 struct chip_operations southbridge_amd_cimx_sb800_ops = {
429 CHIP_NAME("ATI SB800")
430 .enable_dev = sb800_enable,