2 * This file is part of the coreboot project.
4 * Copyright (C) 2012 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 "Platform.h" /* Platfrom Specific Definitions */
30 #include "sb700_cfg.h" /* sb700 Cimx configuration */
31 #include "chip.h" /* struct southbridge_amd_cimx_sb700_config */
34 /*implement in mainboard.c*/
35 void set_pcie_reset(void);
36 void set_pcie_dereset(void);
38 static AMDSBCFG sb_late_cfg; //global, init in sb700_cimx_config
39 static AMDSBCFG *sb_config = &sb_late_cfg;
43 * @brief Entry point of Southbridge CIMx callout
45 * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig)
47 * @param[in] func Southbridge CIMx Function ID.
48 * @param[in] data Southbridge Input Data.
49 * @param[in] sb_config Southbridge configuration structure pointer.
52 u32 sb700_callout_entry(u32 func, u32 data, void* config)
56 printk(BIOS_DEBUG, "SB700 - Late.c - sb700_callout_entry - Start.\n");
57 printk(BIOS_DEBUG, "SB700 - Late.c - sb700_callout_entry - End.\n");
62 static struct pci_operations lops_pci = {
63 .set_subsystem = pci_dev_set_subsystem,
66 static void lpc_enable_resources(device_t dev)
69 printk(BIOS_SPEW, "SB700 - Late.c - %s - Start.\n", __func__);
70 pci_dev_enable_resources(dev);
71 lpc_enable_childrens_resources(dev);
72 printk(BIOS_SPEW, "SB700 - Late.c - %s - End.\n", __func__);
75 static struct device_operations lpc_ops = {
76 .read_resources = lpc_read_resources,
77 .set_resources = lpc_set_resources,
78 .enable_resources = lpc_enable_resources,
80 .scan_bus = scan_static_bus,
84 static const struct pci_driver lpc_driver __pci_driver = {
86 .vendor = PCI_VENDOR_ID_ATI,
87 .device = PCI_DEVICE_ID_ATI_SB700_LPC,
91 static struct device_operations sata_ops = {
92 .read_resources = pci_dev_read_resources,
93 .set_resources = pci_dev_set_resources,
94 .enable_resources = pci_dev_enable_resources,
100 static const struct pci_driver sata_driver __pci_driver = {
102 .vendor = PCI_VENDOR_ID_ATI,
103 .device = PCI_DEVICE_ID_ATI_SB700_SATA, //SATA IDE Mode 4390
107 static void usb_set_resources(struct device *dev)
109 struct resource *res;
113 printk(BIOS_SPEW, "SB700 - Late.c - %s - Start.\n", __func__);
114 old_debug = get_ehci_debug();
117 pci_dev_set_resources(dev);
119 res = find_resource(dev, 0x10);
120 set_ehci_debug(old_debug);
125 report_resource_stored(dev, res, "");
126 printk(BIOS_SPEW, "SB700 - Late.c - %s - End.\n", __func__);
131 static struct device_operations usb_ops = {
132 .read_resources = pci_dev_read_resources,
134 .set_resources = usb_set_resources,
136 .set_resources = pci_dev_set_resources,
138 .enable_resources = pci_dev_enable_resources,
141 .ops_pci = &lops_pci,
145 * The pci id of usb ctrl 0 and 1 are the same.
147 static const struct pci_driver usb_ohci123_driver __pci_driver = {
149 .vendor = PCI_VENDOR_ID_ATI,
150 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
153 static const struct pci_driver usb_ohci3_driver __pci_driver = {
155 .vendor = PCI_VENDOR_ID_ATI,
156 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_1,
159 static const struct pci_driver usb_ehci123_driver __pci_driver = {
161 .vendor = PCI_VENDOR_ID_ATI,
162 .device = PCI_DEVICE_ID_ATI_SB700_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
165 static const struct pci_driver usb_ohci4_driver __pci_driver = {
167 .vendor = PCI_VENDOR_ID_ATI,
168 .device = PCI_DEVICE_ID_ATI_SB700_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_SB700_HDA,
187 static struct device_operations pci_ops = {
188 .read_resources = pci_bus_read_resources,
189 .set_resources = pci_dev_set_resources,
190 .enable_resources = pci_bus_enable_resources,
192 .scan_bus = pci_scan_bridge,
193 .reset_bus = pci_bus_reset,
194 .ops_pci = &lops_pci,
197 static const struct pci_driver pci_driver __pci_driver = {
199 .vendor = PCI_VENDOR_ID_ATI,
200 .device = PCI_DEVICE_ID_ATI_SB700_PCI,
204 static void sb700_enable(device_t dev)
206 struct southbridge_amd_cimx_sb700_config *sb_chip =
207 (struct southbridge_amd_cimx_sb700_config *)(dev->chip_info);
209 printk(BIOS_DEBUG, "sb700_enable() ");
210 switch (dev->path.pci.devfn) {
211 case (0x11 << 3) | 0: /* 0:11.0 SATA */
212 sb700_cimx_config(sb_config);
214 sb_config->SataController = CIMX_OPTION_ENABLED;
215 if (1 == sb_chip->boot_switch_sata_ide)
216 sb_config->SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
217 else if (0 == sb_chip->boot_switch_sata_ide)
218 sb_config->SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
220 sb_config->SataController = CIMX_OPTION_DISABLED;
224 case (0x12 << 3) | 0: /* 0:12:0 OHCI-USB1 */
225 case (0x12 << 3) | 2: /* 0:12:2 EHCI-USB1 */
226 case (0x13 << 3) | 0: /* 0:13:0 OHCI-USB2 */
227 case (0x13 << 3) | 2: /* 0:13:2 EHCI-USB2 */
230 case (0x14 << 3) | 0: /* 0:14:0 SMBUS */
234 printk(BIOS_DEBUG, "sm_init().\n");
235 ioapic_base = IO_APIC_ADDR;
236 clear_ioapic(ioapic_base);
237 /* I/O APIC IDs are normally limited to 4-bits. Enforce this limit. */
238 #if (CONFIG_APIC_ID_OFFSET == 0 && CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS >= 1)
239 /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
240 setup_ioapic(ioapic_base, CONFIG_MAX_CPUS * CONFIG_MAX_PHYSICAL_CPUS);
241 #elif (CONFIG_APIC_ID_OFFSET > 0)
242 /* Assign the ioapic ID the value 0. Processor APIC IDs follow. */
243 setup_ioapic(ioapic_base, 0);
245 #error "The processor APIC IDs must be lifted to make room for the I/O APIC ID"
251 case (0x14 << 3) | 1: /* 0:14:1 IDE */
254 case (0x14 << 3) | 2: /* 0:14:2 HDA */
256 if (AZALIA_DISABLE == sb_config->AzaliaController) {
257 sb_config->AzaliaController = AZALIA_AUTO;
259 printk(BIOS_DEBUG, "hda enabled\n");
261 sb_config->AzaliaController = AZALIA_DISABLE;
262 printk(BIOS_DEBUG, "hda disabled\n");
267 case (0x14 << 3) | 3: /* 0:14:3 LPC */
270 case (0x14 << 3) | 4: /* 0:14:4 PCI */
273 case (0x14 << 3) | 5: /* 0:14:5 OHCI-USB4 */
274 /* call CIMX entry after last device enable */
275 sb_Before_Pci_Init();
283 struct chip_operations southbridge_amd_cimx_sb700_ops = {
284 CHIP_NAME("ATI SB700")
285 .enable_dev = sb700_enable,
289 * @brief SB Cimx entry point sbBeforePciInit wrapper
291 void sb_Before_Pci_Init(void)
293 printk(BIOS_SPEW, "sb700 %s Start\n", __func__);
294 /* TODO: The sb700 cimx dispatcher not work yet, calling cimx API directly */
295 //sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
296 //AmdSbDispatcher(sb_config);
297 sbBeforePciInit(sb_config);
298 printk(BIOS_SPEW, "sb700 %s End\n", __func__);
301 void sb_After_Pci_Init(void)
303 printk(BIOS_SPEW, "sb700 %s Start\n", __func__);
304 /* TODO: The sb700 cimx dispatcher not work yet, calling cimx API directly */
305 //sb_config->StdHeader.Func = SB_AFTER_PCI_INIT;
306 //AmdSbDispatcher(sb_config);
307 sbAfterPciInit(sb_config);
308 printk(BIOS_SPEW, "sb700 %s End\n", __func__);
311 void sb_Late_Post(void)
313 printk(BIOS_SPEW, "sb700 %s Start\n", __func__);
314 /* TODO: The sb700 cimx dispatcher not work yet, calling cimx API directly */
315 //sb_config->StdHeader.Func = SB_LATE_POST_INIT;
316 //AmdSbDispatcher(sb_config);
317 sbLatePost(sb_config);
318 printk(BIOS_SPEW, "sb700 %s End\n", __func__);