[PATCH v3 2/6] PCI: Add pci_clear_and_set_config_word()

From: Yazen Ghannam

Date: Fri Dec 04 2026 - 13:16:35 EST


A word register that shares its dword with RW1CS bits cannot use
pci_clear_and_set_config_dword(). Writing the dword back would clear any
status bits that are set.

Add the word-sized counterpart. Only the PCI core needs it, so declare it
in drivers/pci/pci.h and don't export it.

Suggested-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Signed-off-by: Yazen Ghannam <yazen.ghannam@xxxxxxx>
---
drivers/pci/access.c | 11 +++++++++++
drivers/pci/pci.h | 2 ++
2 files changed, 13 insertions(+)

diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index b123da16b63b..38619bc9c7f9 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -613,6 +613,17 @@ int pci_write_config_dword(const struct pci_dev *dev, int where,
}
EXPORT_SYMBOL(pci_write_config_dword);

+void pci_clear_and_set_config_word(const struct pci_dev *dev, int pos,
+ u16 clear, u16 set)
+{
+ u16 val;
+
+ pci_read_config_word(dev, pos, &val);
+ val &= ~clear;
+ val |= set;
+ pci_write_config_word(dev, pos, val);
+}
+
void pci_clear_and_set_config_dword(const struct pci_dev *dev, int pos,
u32 clear, u32 set)
{
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index aa392bb6a482..2f21246380dd 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -286,6 +286,8 @@ void pci_dev_adjust_pme(struct pci_dev *dev);
void pci_dev_complete_resume(struct pci_dev *pci_dev);
void pci_config_pm_runtime_get(struct pci_dev *dev);
void pci_config_pm_runtime_put(struct pci_dev *dev);
+void pci_clear_and_set_config_word(const struct pci_dev *dev, int pos,
+ u16 clear, u16 set);
void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev);
void pci_pm_init(struct pci_dev *dev);
void pci_ea_init(struct pci_dev *dev);
--
2.55.0