i2c: i801: Replace waitqueue with completion API

Using the completion API is more intuitive and it allows to simplify
the code. Note that we don't have to set priv->status = 0 any longer
with the completion API.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
Tested-by: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
This commit is contained in:
Heiner Kallweit 2021-05-22 00:02:43 +02:00 committed by Wolfram Sang
parent 78f420acc4
commit 1de93d5d52

View file

@ -103,7 +103,7 @@
#include <linux/dmi.h> #include <linux/dmi.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/wait.h> #include <linux/completion.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/platform_data/itco_wdt.h> #include <linux/platform_data/itco_wdt.h>
@ -270,7 +270,7 @@ struct i801_priv {
unsigned int features; unsigned int features;
/* isr processing */ /* isr processing */
wait_queue_head_t waitq; struct completion done;
u8 status; u8 status;
/* Command state used by isr for byte-by-byte block transactions */ /* Command state used by isr for byte-by-byte block transactions */
@ -496,24 +496,19 @@ static int i801_wait_byte_done(struct i801_priv *priv)
static int i801_transaction(struct i801_priv *priv, int xact) static int i801_transaction(struct i801_priv *priv, int xact)
{ {
int status; int status;
int result; unsigned long result;
const struct i2c_adapter *adap = &priv->adapter; const struct i2c_adapter *adap = &priv->adapter;
result = i801_check_pre(priv); status = i801_check_pre(priv);
if (result < 0) if (status < 0)
return result; return status;
if (priv->features & FEATURE_IRQ) { if (priv->features & FEATURE_IRQ) {
reinit_completion(&priv->done);
outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START, outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START,
SMBHSTCNT(priv)); SMBHSTCNT(priv));
result = wait_event_timeout(priv->waitq, result = wait_for_completion_timeout(&priv->done, adap->timeout);
(status = priv->status), return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
adap->timeout);
if (!result)
status = -ETIMEDOUT;
priv->status = 0;
return i801_check_post(priv, status);
} }
/* the current contents of SMBHSTCNT can be overwritten, since PEC, /* the current contents of SMBHSTCNT can be overwritten, since PEC,
@ -638,7 +633,7 @@ static irqreturn_t i801_host_notify_isr(struct i801_priv *priv)
* DEV_ERR - Invalid command, NAK or communication timeout * DEV_ERR - Invalid command, NAK or communication timeout
* BUS_ERR - SMI# transaction collision * BUS_ERR - SMI# transaction collision
* FAILED - transaction was canceled due to a KILL request * FAILED - transaction was canceled due to a KILL request
* When any of these occur, update ->status and wake up the waitq. * When any of these occur, update ->status and signal completion.
* ->status must be cleared before kicking off the next transaction. * ->status must be cleared before kicking off the next transaction.
* *
* 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
@ -675,7 +670,7 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
if (status) { if (status) {
outb_p(status, SMBHSTSTS(priv)); outb_p(status, SMBHSTSTS(priv));
priv->status = status; priv->status = status;
wake_up(&priv->waitq); complete(&priv->done);
} }
return IRQ_HANDLED; return IRQ_HANDLED;
@ -694,15 +689,15 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
int i, len; int i, len;
int smbcmd; int smbcmd;
int status; int status;
int result; unsigned long result;
const struct i2c_adapter *adap = &priv->adapter; const struct i2c_adapter *adap = &priv->adapter;
if (command == I2C_SMBUS_BLOCK_PROC_CALL) if (command == I2C_SMBUS_BLOCK_PROC_CALL)
return -EOPNOTSUPP; return -EOPNOTSUPP;
result = i801_check_pre(priv); status = i801_check_pre(priv);
if (result < 0) if (status < 0)
return result; return status;
len = data->block[0]; len = data->block[0];
@ -726,15 +721,10 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
priv->count = 0; priv->count = 0;
priv->data = &data->block[1]; priv->data = &data->block[1];
reinit_completion(&priv->done);
outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv)); outb_p(priv->cmd | SMBHSTCNT_START, SMBHSTCNT(priv));
result = wait_event_timeout(priv->waitq, result = wait_for_completion_timeout(&priv->done, adap->timeout);
(status = priv->status), return i801_check_post(priv, result ? priv->status : -ETIMEDOUT);
adap->timeout);
if (!result)
status = -ETIMEDOUT;
priv->status = 0;
return i801_check_post(priv, status);
} }
for (i = 1; i <= len; i++) { for (i = 1; i <= len; i++) {
@ -1889,7 +1879,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
} }
if (priv->features & FEATURE_IRQ) { if (priv->features & FEATURE_IRQ) {
init_waitqueue_head(&priv->waitq); init_completion(&priv->done);
err = devm_request_irq(&dev->dev, dev->irq, i801_isr, err = devm_request_irq(&dev->dev, dev->irq, i801_isr,
IRQF_SHARED, IRQF_SHARED,