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 <device/smbus.h> /* smbus_bus_operations */
25 #include <console/console.h> /* printk */
26 #include "lpc.h" /* lpc_read_resources */
27 #include "SbPlatform.h" /* Platfrom Specific Definitions */
28 #include "cfg.h" /* sb900 Cimx configuration */
29 #include "chip.h" /* struct southbridge_amd_cimx_sb900_config */
32 /*implement in mainboard.c*/
33 //void set_pcie_assert(void);
34 //void set_pcie_deassert(void);
35 void set_pcie_reset(void);
36 void set_pcie_dereset(void);
42 static AMDSBCFG sb_late_cfg; //global, init in sb900_cimx_config
43 static AMDSBCFG *sb_config = &sb_late_cfg;
47 * @brief Entry point of Southbridge CIMx callout
49 * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig)
51 * @param[in] func Southbridge CIMx Function ID.
52 * @param[in] data Southbridge Input Data.
53 * @param[in] sb_config Southbridge configuration structure pointer.
56 u32 sb900_callout_entry(u32 func, u32 data, void* config)
60 printk(BIOS_DEBUG, "SB900 - Late.c - sb900_callout_entry - Start.\n");
62 case CB_SBGPP_RESET_ASSERT:
67 case CB_SBGPP_RESET_DEASSERT:
68 //set_pcie_deassert();
69 //- set_pcie_dereset();
72 //- case IMC_FIRMWARE_FAIL:
79 printk(BIOS_DEBUG, "SB900 - Late.c - sb900_callout_entry - End.\n");
84 static struct pci_operations lops_pci = {
88 static void lpc_enable_resources(device_t dev)
91 printk(BIOS_DEBUG, "SB900 - Late.c - lpc_enable_resources - Start.\n");
92 pci_dev_enable_resources(dev);
93 //lpc_enable_childrens_resources(dev);
94 printk(BIOS_DEBUG, "SB900 - Late.c - lpc_enable_resources - End.\n");
97 static void lpc_init(device_t dev)
99 printk(BIOS_DEBUG, "SB900 - Late.c - lpc_init - Start.\n");
100 /* SB Configure HPET base and enable bit */
101 //- hpetInit(sb_config, &(sb_config->BuildParameters));
102 printk(BIOS_DEBUG, "SB900 - Late.c - lpc_init - End.\n");
105 static struct device_operations lpc_ops = {
106 .read_resources = lpc_read_resources,
107 .set_resources = lpc_set_resources,
108 .enable_resources = lpc_enable_resources,
110 .scan_bus = scan_static_bus,
111 .ops_pci = &lops_pci,
114 static const struct pci_driver lpc_driver __pci_driver = {
116 .vendor = PCI_VENDOR_ID_AMD,
117 .device = PCI_DEVICE_ID_ATI_SB900_LPC,
121 static void sata_enable_resources(struct device *dev)
123 printk(BIOS_DEBUG, "SB900 - Late.c - sata_enable_resources - Start.\n");
124 //- sataInitAfterPciEnum(sb_config);
125 pci_dev_enable_resources(dev);
126 printk(BIOS_DEBUG, "SB900 - Late.c - sata_enable_resources - End.\n");
129 static void sata_init(struct device *dev)
131 printk(BIOS_DEBUG, "SB900 - Late.c - sata_init - Start.\n");
132 sb_config->StdHeader.Func = SB_MID_POST_INIT;
133 //- AmdSbDispatcher(sb_config); //sataInitMidPost only
134 //- commonInitLateBoot(sb_config);
135 //- sataInitLatePost(sb_config);
136 printk(BIOS_DEBUG, "SB900 - Late.c - sata_init - End.\n");
139 static struct device_operations sata_ops = {
140 .read_resources = pci_dev_read_resources,
141 .set_resources = pci_dev_set_resources,
142 .enable_resources = sata_enable_resources, //pci_dev_enable_resources,
145 .ops_pci = &lops_pci,
148 static const struct pci_driver sata_driver __pci_driver = {
150 .vendor = PCI_VENDOR_ID_AMD,
151 #if (CONFIG_SATA_CONTROLLER_MODE == 0x0 || CONFIG_SATA_CONTROLLER_MODE == 0x3)
152 .device = PCI_DEVICE_ID_ATI_SB900_SATA, //SATA IDE Mode
154 #if (CONFIG_SATA_CONTROLLER_MODE == 0x2 || CONFIG_SATA_CONTROLLER_MODE == 0x4)
155 .device = PCI_DEVICE_ID_ATI_SB900_SATA_AHCI, //SATA AHCI Mode
157 #if (CONFIG_SATA_CONTROLLER_MODE == 0x5 || CONFIG_SATA_CONTROLLER_MODE == 0x6)
158 .device = PCI_DEVICE_ID_ATI_SB900_SATA_AMDAHCI, //SATA AMDAHCI Mode
160 #if (CONFIG_SATA_CONTROLLER_MODE == 0x1 && INCHIP_SATA_FORCE_RAID5 == 0x0)
161 .device = PCI_DEVICE_ID_ATI_SB900_SATA_RAID5, //SATA RAID5 Mode
163 #if (CONFIG_SATA_CONTROLLER_MODE == 0x1 && INCHIP_SATA_FORCE_RAID5 == 0x1)
164 .device = PCI_DEVICE_ID_ATI_SB900_SATA_RAID, //SATA RAID Mode
170 static void usb_set_resources(struct device *dev)
172 struct resource *res;
176 printk(BIOS_DEBUG, "SB900 - Late.c - usb_set_resources - Start.\n");
177 old_debug = get_ehci_debug();
180 pci_dev_set_resources(dev);
182 res = find_resource(dev, 0x10);
183 set_ehci_debug(old_debug);
188 report_resource_stored(dev, res, "");
189 printk(BIOS_DEBUG, "SB900 - Late.c - usb_set_resources - End.\n");
193 static void usb_init(struct device *dev)
195 printk(BIOS_DEBUG, "SB900 - Late.c - usb_init - Start.\n");
196 //- usbInitAfterPciInit(sb_config);
197 //- commonInitLateBoot(sb_config);
198 printk(BIOS_DEBUG, "SB900 - Late.c - usb_init - End.\n");
201 static struct device_operations usb_ops = {
202 .read_resources = pci_dev_read_resources,
204 .set_resources = usb_set_resources,
206 .set_resources = pci_dev_set_resources,
208 .enable_resources = pci_dev_enable_resources,
211 .ops_pci = &lops_pci,
215 * The pci id of usb ctrl 0 and 1 are the same.
217 static const struct pci_driver usb_xhci123_driver __pci_driver = {
219 .vendor = PCI_VENDOR_ID_AMD,
220 .device = PCI_DEVICE_ID_ATI_SB900_USB_16_0, /* XHCI-USB1, XHCI-USB2 */
223 static const struct pci_driver usb_ohci123_driver __pci_driver = {
225 .vendor = PCI_VENDOR_ID_AMD,
226 .device = PCI_DEVICE_ID_ATI_SB900_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
229 static const struct pci_driver usb_ehci123_driver __pci_driver = {
231 .vendor = PCI_VENDOR_ID_AMD,
232 .device = PCI_DEVICE_ID_ATI_SB900_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
235 static const struct pci_driver usb_ohci4_driver __pci_driver = {
237 .vendor = PCI_VENDOR_ID_AMD,
238 .device = PCI_DEVICE_ID_ATI_SB900_USB_20_5, /* OHCI-USB4 */
242 static void azalia_init(struct device *dev)
244 printk(BIOS_DEBUG, "SB900 - Late.c - azalia_init - Start.\n");
245 //- azaliaInitAfterPciEnum(sb_config); //Detect and configure High Definition Audio
246 printk(BIOS_DEBUG, "SB900 - Late.c - azalia_init - End.\n");
249 static struct device_operations azalia_ops = {
250 .read_resources = pci_dev_read_resources,
251 .set_resources = pci_dev_set_resources,
252 .enable_resources = pci_dev_enable_resources,
255 .ops_pci = &lops_pci,
258 static const struct pci_driver azalia_driver __pci_driver = {
260 .vendor = PCI_VENDOR_ID_AMD,
261 .device = PCI_DEVICE_ID_ATI_SB900_HDA,
265 static void gec_init(struct device *dev)
267 printk(BIOS_DEBUG, "SB900 - Late.c - gec_init - Start.\n");
268 //- gecInitAfterPciEnum(sb_config);
269 //- gecInitLatePost(sb_config);
270 printk(BIOS_DEBUG, "SB900 - Late.c - gec_init - End.\n");
273 static struct device_operations gec_ops = {
274 .read_resources = pci_dev_read_resources,
275 .set_resources = pci_dev_set_resources,
276 .enable_resources = pci_dev_enable_resources,
279 .ops_pci = &lops_pci,
282 static const struct pci_driver gec_driver __pci_driver = {
284 .vendor = PCI_VENDOR_ID_AMD,
285 .device = PCI_DEVICE_ID_ATI_SB900_GEC,
289 static void pcie_init(device_t dev)
291 printk(BIOS_DEBUG, "SB900 - Late.c - pcie_init - Start.\n");
292 //- sbPcieGppLateInit(sb_config);
293 printk(BIOS_DEBUG, "SB900 - Late.c - pcie_init - End.\n");
296 static struct device_operations pci_ops = {
297 .read_resources = pci_bus_read_resources,
298 .set_resources = pci_dev_set_resources,
299 .enable_resources = pci_bus_enable_resources,
301 .scan_bus = pci_scan_bridge,
302 .reset_bus = pci_bus_reset,
303 .ops_pci = &lops_pci,
306 static const struct pci_driver pci_driver __pci_driver = {
308 .vendor = PCI_VENDOR_ID_AMD,
309 .device = PCI_DEVICE_ID_ATI_SB900_PCI,
313 struct device_operations bridge_ops = {
314 .read_resources = pci_bus_read_resources,
315 .set_resources = pci_dev_set_resources,
316 .enable_resources = pci_bus_enable_resources,
318 .scan_bus = pci_scan_bridge,
320 .reset_bus = pci_bus_reset,
321 .ops_pci = &lops_pci,
324 /* 0:15:0 PCIe PortA */
325 static const struct pci_driver PORTA_driver __pci_driver = {
327 .vendor = PCI_VENDOR_ID_AMD,
328 .device = PCI_DEVICE_ID_ATI_SB900_PCIEA,
331 /* 0:15:1 PCIe PortB */
332 static const struct pci_driver PORTB_driver __pci_driver = {
334 .vendor = PCI_VENDOR_ID_AMD,
335 .device = PCI_DEVICE_ID_ATI_SB900_PCIEB,
338 /* 0:15:2 PCIe PortC */
339 static const struct pci_driver PORTC_driver __pci_driver = {
341 .vendor = PCI_VENDOR_ID_AMD,
342 .device = PCI_DEVICE_ID_ATI_SB900_PCIEC,
345 /* 0:15:3 PCIe PortD */
346 static const struct pci_driver PORTD_driver __pci_driver = {
348 .vendor = PCI_VENDOR_ID_AMD,
349 .device = PCI_DEVICE_ID_ATI_SB900_PCIED,
354 * @brief SB Cimx entry point sbBeforePciInit wrapper
356 static void sb900_enable(device_t dev)
359 struct southbridge_amd_cimx_sb900_config *sb_chip =
360 (struct southbridge_amd_cimx_sb900_config *)(dev->chip_info);
362 sb900_cimx_config(sb_config);
363 printk(BIOS_DEBUG, "sb900_enable() ");
365 /* Config SouthBridge SMBUS/ACPI/IDE/LPC/PCIB.*/
366 //- commonInitEarlyBoot(sb_config);
367 //- commonInitEarlyPost(sb_config);
369 switch (dev->path.pci.devfn) {
370 case (0x10 << 3) | 0: /* 0:10:0 XHCI-USB */
371 //- usbInitBeforePciEnum(sb_config); // USB POST TIME Only
374 case (0x11 << 3) | 0: /* 0:11.0 SATA */
376 sb_config->SATAMODE.SataMode.SataController = ENABLED;
377 if (1 == sb_chip->boot_switch_sata_ide)
378 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
379 else if (0 == sb_chip->boot_switch_sata_ide)
380 sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
382 sb_config->SATAMODE.SataMode.SataController = DISABLED;
385 //- sataInitBeforePciEnum(sb_config); // Init SATA class code and PHY
388 case (0x12 << 3) | 0: /* 0:12:0 OHCI-USB1 */
389 case (0x12 << 3) | 2: /* 0:12:2 EHCI-USB1 */
390 case (0x13 << 3) | 0: /* 0:13:0 OHCI-USB2 */
391 case (0x13 << 3) | 2: /* 0:13:2 EHCI-USB2 */
392 case (0x14 << 3) | 5: /* 0:14:5 OHCI-USB4 */
393 //- usbInitBeforePciEnum(sb_config); // USB POST TIME Only
396 case (0x14 << 3) | 0: /* 0:14:0 SMBUS */
399 case (0x14 << 3) | 1: /* 0:14:1 IDE */
401 sb_config->SATAMODE.SataMode.SataIdeCombinedMode = ENABLED;
403 sb_config->SATAMODE.SataMode.SataIdeCombinedMode = DISABLED;
405 //- sataInitBeforePciEnum(sb_config); // Init SATA class code and PHY
408 case (0x14 << 3) | 2: /* 0:14:2 HDA */
410 if (AZALIA_DISABLE == sb_config->AzaliaController) {
411 sb_config->AzaliaController = AZALIA_AUTO;
413 printk(BIOS_DEBUG, "hda enabled\n");
415 sb_config->AzaliaController = AZALIA_DISABLE;
416 printk(BIOS_DEBUG, "hda disabled\n");
418 //- azaliaInitBeforePciEnum(sb_config); // Detect and configure High Definition Audio
422 case (0x14 << 3) | 3: /* 0:14:3 LPC */
425 case (0x14 << 3) | 4: /* 0:14:4 PCI */
428 case (0x14 << 3) | 6: /* 0:14:6 GEC */
430 sb_config->GecConfig = 0;
431 printk(BIOS_DEBUG, "gec enabled\n");
433 sb_config->GecConfig = 1;
434 printk(BIOS_DEBUG, "gec disabled\n");
436 //- gecInitBeforePciEnum(sb_config); // Init GEC
439 case (0x15 << 3) | 0: /* 0:15:0 PCIe PortA */
440 case (0x15 << 3) | 1: /* 0:15:1 PCIe PortB */
441 case (0x15 << 3) | 2: /* 0:15:2 PCIe PortC */
442 case (0x15 << 3) | 3: /* 0:15:3 PCIe PortD */
443 gpp_port = (dev->path.pci.devfn) & 0x03;
445 sb_config->PORTCONFIG[gpp_port].PortCfg.PortPresent = ENABLED;
447 sb_config->PORTCONFIG[gpp_port].PortCfg.PortPresent = DISABLED;
451 * GPP_CFGMODE_X4000: PortA Lanes[3:0]
452 * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2]
453 * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3
454 * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3
456 if (sb_config->GppLinkConfig != sb_chip->gpp_configuration) {
457 sb_config->GppLinkConfig = sb_chip->gpp_configuration;
460 //- sbPcieGppEarlyInit(sb_config);
467 /* Special setting ABCFG registers before PCI emulation. */
468 //- abSpecialSetBeforePciEnum(sb_config);
469 //- usbDesertPll(sb_config);
470 //sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
471 //AmdSbDispatcher(sb_config);
474 struct chip_operations southbridge_amd_cimx_sb900_ops = {
475 CHIP_NAME("ATI SB900")
476 .enable_dev = sb900_enable,