1 // SPDX-License-Identifier: ISC
3 * Copyright (C) 2019 Lorenzo Bianconi <lorenzo@kernel.org>
9 void mt76_pci_disable_aspm(struct pci_dev
*pdev
)
11 struct pci_dev
*parent
= pdev
->bus
->self
;
12 u16 aspm_conf
, parent_aspm_conf
= 0;
14 pcie_capability_read_word(pdev
, PCI_EXP_LNKCTL
, &aspm_conf
);
15 aspm_conf
&= PCI_EXP_LNKCTL_ASPMC
;
17 pcie_capability_read_word(parent
, PCI_EXP_LNKCTL
,
19 parent_aspm_conf
&= PCI_EXP_LNKCTL_ASPMC
;
22 if (!aspm_conf
&& (!parent
|| !parent_aspm_conf
)) {
23 /* aspm already disabled */
27 dev_info(&pdev
->dev
, "disabling ASPM %s %s\n",
28 (aspm_conf
& PCI_EXP_LNKCTL_ASPM_L0S
) ? "L0s" : "",
29 (aspm_conf
& PCI_EXP_LNKCTL_ASPM_L1
) ? "L1" : "");
31 if (IS_ENABLED(CONFIG_PCIEASPM
)) {
34 err
= pci_disable_link_state(pdev
, aspm_conf
);
39 /* both device and parent should have the same ASPM setting.
40 * disable ASPM in downstream component first and then upstream.
42 pcie_capability_clear_word(pdev
, PCI_EXP_LNKCTL
, aspm_conf
);
44 pcie_capability_clear_word(parent
, PCI_EXP_LNKCTL
,
47 EXPORT_SYMBOL_GPL(mt76_pci_disable_aspm
);