i2c: i801: Use MMIO if available
authorHeiner Kallweit <hkallweit1@gmail.com>
Wed, 12 Mar 2025 19:08:18 +0000 (20:08 +0100)
committerAndi Shyti <andi.shyti@kernel.org>
Thu, 20 Mar 2025 21:31:31 +0000 (22:31 +0100)
Newer versions of supported chips support MMIO in addition to legacy
PMIO register access. Probe the MMIO PCI BAR and use faster MMIO
register access if available.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/b4748b7a-aac5-445c-b813-20c4d2c23ec3@gmail.com
drivers/i2c/busses/i2c-i801.c

index bf5702ccb93abe153318d99e7d28573823efa16a..48e1af544b75a3ff62b9bed4c525486d8a5fd2e3 100644 (file)
 #define SMBNTFDADD(p)  (20 + (p)->smba)        /* ICH3 and later */
 
 /* PCI Address Constants */
+#define SMBBAR_MMIO    0
 #define SMBBAR         4
 #define SMBHSTCFG      0x040
 #define TCOBASE                0x050
@@ -1522,7 +1523,7 @@ static void i801_restore_regs(struct i801_priv *priv)
 
 static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
-       int err, i;
+       int err, i, bar = SMBBAR;
        struct i801_priv *priv;
 
        priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
@@ -1570,10 +1571,13 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
        if (i801_acpi_probe(priv))
                return -ENODEV;
 
-       priv->smba = pcim_iomap_region(dev, SMBBAR, DRV_NAME);
+       if (pci_resource_flags(dev, SMBBAR_MMIO) & IORESOURCE_MEM)
+               bar = SMBBAR_MMIO;
+
+       priv->smba = pcim_iomap_region(dev, bar, DRV_NAME);
        if (IS_ERR(priv->smba)) {
                pci_err(dev, "Failed to request SMBus region %pr\n",
-                       pci_resource_n(dev, SMBBAR));
+                       pci_resource_n(dev, bar));
                i801_acpi_remove(priv);
                return PTR_ERR(priv->smba);
        }