summaryrefslogtreecommitdiffstats
path: root/src/drivers/asmedia/asm1061.c
blob: 29d2704f45c5f9cf6f39037c33d89f6621a14094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* SPDX-License-Identifier: GPL-2.0-only */

#include <console/console.h>
#include <device/device.h>
#include <device/pci.h>
#include <device/pci_ids.h>
#include <option.h>

#define ASM1061_CTRL_REG 0xec
#define ASM1061_PCI_CFG_UNLOCK (1 << 2)

static void asm1061_enable(struct device *const dev)
{
	printk(BIOS_INFO, "Disabling ASPM for %s [%04x/%04x]\n",
	       dev_path(dev), dev->vendor, dev->device);
	dev->disable_pcie_aspm = 1;

	u8 sata_mode = get_uint_option("sata_mode", 0);
	pci_or_config8(dev, ASM1061_CTRL_REG, ASM1061_PCI_CFG_UNLOCK);
	if (sata_mode == 0) {
		printk(BIOS_INFO, "Setting AHCI mode for %s [%04x/%04x]\n",
		       dev_path(dev), dev->vendor, dev->device);
		pci_write_config16(dev, PCI_CLASS_DEVICE, PCI_CLASS_STORAGE_SATA);
	} else {
		printk(BIOS_INFO, "Setting IDE mode for %s [%04x/%04x]\n",
		       dev_path(dev), dev->vendor, dev->device);
		pci_write_config16(dev, PCI_CLASS_DEVICE, PCI_CLASS_STORAGE_IDE);
	}
	pci_and_config8(dev, ASM1061_CTRL_REG, ~ASM1061_PCI_CFG_UNLOCK);
}

static struct device_operations asm1061_ops = {
	.read_resources		= pci_dev_read_resources,
	.set_resources		= pci_dev_set_resources,
	.enable_resources	= pci_dev_enable_resources,
	.enable			= asm1061_enable,
};

static const unsigned short pci_device_ids[] = {
	0x0611, /* ASM1061 SATA IDE Controller */
	0
};

static const struct pci_driver asmedia_asm1061 __pci_driver = {
	.ops		= &asm1061_ops,
	.vendor		= 0x1b21,
	.devices	= pci_device_ids,
};