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.
16 #include <console/console.h>
17 #include <device/device.h>
19 #include <device/pci.h>
20 #include <device/pci_ids.h>
21 #include <device/pci_ops.h>
26 static void sata_init(struct device
*dev
)
28 #if IS_ENABLED(CONFIG_SOUTHBRIDGE_AMD_PI_AVALON) || IS_ENABLED(CONFIG_SOUTHBRIDGE_AMD_PI_KERN)
29 /**************************************
30 * Configure the SATA port multiplier *
31 **************************************/
32 #define BYTE_TO_DWORD_OFFSET(x) (x/4)
33 #define AHCI_BASE_ADDRESS_REG 0x24
34 #define MISC_CONTROL_REG 0x40
35 #define UNLOCK_BIT (1<<0)
36 #define SATA_CAPABILITIES_REG 0xFC
37 #define CFG_CAP_SPM (1<<12)
39 volatile u32
*ahci_ptr
=
40 (u32
*)(pci_read_config32(dev
, AHCI_BASE_ADDRESS_REG
) & 0xFFFFFF00);
43 /* unlock the write-protect */
44 temp
= pci_read_config32(dev
, MISC_CONTROL_REG
);
46 pci_write_config32(dev
, MISC_CONTROL_REG
, temp
);
48 /* set the SATA AHCI mode to allow port expanders */
49 *(ahci_ptr
+ BYTE_TO_DWORD_OFFSET(SATA_CAPABILITIES_REG
)) |= CFG_CAP_SPM
;
51 /* lock the write-protect */
52 temp
= pci_read_config32(dev
, MISC_CONTROL_REG
);
54 pci_write_config32(dev
, MISC_CONTROL_REG
, temp
);
58 static struct pci_operations lops_pci
= {
59 /* .set_subsystem = pci_dev_set_subsystem, */
62 static struct device_operations sata_ops
= {
63 .read_resources
= pci_dev_read_resources
,
64 .set_resources
= pci_dev_set_resources
,
65 .enable_resources
= pci_dev_enable_resources
,
71 static const unsigned short pci_device_ids
[] = {
72 PCI_DEVICE_ID_ATI_SB900_SATA
,
73 PCI_DEVICE_ID_ATI_SB900_SATA_AHCI
,
74 PCI_DEVICE_ID_AMD_CZ_SATA
,
75 PCI_DEVICE_ID_AMD_CZ_SATA_AHCI
,
79 static const struct pci_driver sata0_driver __pci_driver
= {
81 .vendor
= PCI_VENDOR_ID_AMD
,
82 .devices
= pci_device_ids
,