Skip to content

Commit 78ea722

Browse files
committed
i2c: i801: Add helper i801_check_and_clear_pec_error
JIRA: https://issues.redhat.com/browse/RHEL-47426 commit 03f9863 Author: Heiner Kallweit <hkallweit1@gmail.com> Date: Fri Feb 2 08:02:19 2024 +0100 i2c: i801: Add helper i801_check_and_clear_pec_error Avoid code duplication and factor out checking and clearing PEC error bit to new helper i801_check_and_clear_pec_error(). Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent 8e3a1bc commit 78ea722

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

drivers/i2c/busses/i2c-i801.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,27 @@ MODULE_PARM_DESC(disable_features, "Disable selected driver features:\n"
330330
"\t\t 0x10 don't use interrupts\n"
331331
"\t\t 0x20 disable SMBus Host Notify ");
332332

333+
static int i801_check_and_clear_pec_error(struct i801_priv *priv)
334+
{
335+
u8 status;
336+
337+
if (!(priv->features & FEATURE_SMBUS_PEC))
338+
return 0;
339+
340+
status = inb_p(SMBAUXSTS(priv)) & SMBAUXSTS_CRCE;
341+
if (status) {
342+
outb_p(status, SMBAUXSTS(priv));
343+
return -EBADMSG;
344+
}
345+
346+
return 0;
347+
}
348+
333349
/* Make sure the SMBus host is ready to start transmitting.
334350
Return 0 if it is, -EBUSY if it is not. */
335351
static int i801_check_pre(struct i801_priv *priv)
336352
{
337-
int status;
353+
int status, result;
338354

339355
status = inb_p(SMBHSTSTS(priv));
340356
if (status & SMBHSTSTS_HOST_BUSY) {
@@ -355,13 +371,9 @@ static int i801_check_pre(struct i801_priv *priv)
355371
* the hardware was already in this state when the driver
356372
* started.
357373
*/
358-
if (priv->features & FEATURE_SMBUS_PEC) {
359-
status = inb_p(SMBAUXSTS(priv)) & SMBAUXSTS_CRCE;
360-
if (status) {
361-
pci_dbg(priv->pci_dev, "Clearing aux status flags (%02x)\n", status);
362-
outb_p(status, SMBAUXSTS(priv));
363-
}
364-
}
374+
result = i801_check_and_clear_pec_error(priv);
375+
if (result)
376+
pci_dbg(priv->pci_dev, "Clearing aux status flag CRCE\n");
365377

366378
return 0;
367379
}
@@ -410,14 +422,12 @@ static int i801_check_post(struct i801_priv *priv, int status)
410422
* bit is harmless as long as it's cleared before
411423
* the next operation.
412424
*/
413-
if ((priv->features & FEATURE_SMBUS_PEC) &&
414-
(inb_p(SMBAUXSTS(priv)) & SMBAUXSTS_CRCE)) {
415-
outb_p(SMBAUXSTS_CRCE, SMBAUXSTS(priv));
416-
result = -EBADMSG;
417-
dev_dbg(&priv->pci_dev->dev, "PEC error\n");
425+
result = i801_check_and_clear_pec_error(priv);
426+
if (result) {
427+
pci_dbg(priv->pci_dev, "PEC error\n");
418428
} else {
419429
result = -ENXIO;
420-
dev_dbg(&priv->pci_dev->dev, "No response\n");
430+
pci_dbg(priv->pci_dev, "No response\n");
421431
}
422432
}
423433
if (status & SMBHSTSTS_BUS_ERR) {

0 commit comments

Comments
 (0)