From: Daniel Kurtz <djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org,
ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org,
seth.heasley-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
ben-/+tVBieCtBitmTQ+vhA3Yw@public.gmane.org,
David.Woodhouse-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: olofj-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org,
bleung-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org,
Daniel Kurtz <djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Subject: [PATCH 3/3 v2] i2c: i801: enable irq for byte_by_byte transactions
Date: Fri, 6 Jan 2012 18:58:22 +0800 [thread overview]
Message-ID: <1325847502-17841-4-git-send-email-djkurtz@chromium.org> (raw)
In-Reply-To: <1325847502-17841-1-git-send-email-djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Byte-by-byte transactions are used primarily for accessing i2c devices
with an smbus controller. For these transactions, for each byte that is
read or written, the SMBus controller generates a BYTE_DONE irq. The isr
reads/writes the next byte, and clears the irq flag to start the next byte.
On the penultimate irq, the isr also sets the LAST_BYTE flag.
There is no locking around the cmd/len/count/data variables, since the
i2c adapter lock ensures there is never multiple simultaneous transactions
for the same device, and the driver thread never accesses these variables
while interrupts might be occurring.
The end result is a dramatic speed up in emulated i2c-over smbus block
read and write transactions.
Note: This patch has only been tested and verified by doing i2c read and
write block transfers on Cougar Point 6 Series PCH.
Signed-off-by: Daniel Kurtz <djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
drivers/i2c/busses/i2c-i801.c | 51 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 50 insertions(+), 1 deletions(-)
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index b123133..f957eca 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -168,6 +168,13 @@ struct i801_priv {
wait_queue_head_t waitq;
spinlock_t lock;
u8 status;
+
+ /* Command state used during by isr */
+ u8 cmd;
+ bool is_read;
+ int count;
+ int len;
+ u8 *data;
};
static struct pci_driver i801_driver;
@@ -368,18 +375,24 @@ static int i801_block_transaction_by_block(struct i801_priv *priv,
}
/*
- * i801 signals transaction completion with one of these interrupts:
+ * There are two kinds of interrupts:
+ *
+ * (1) i801 signals transaction completion with one of these interrupts:
* INTR - Success
* DEV_ERR - Invalid command, NAK or communication timeout
* BUS_ERR - SMI# transaction collision
* FAILED - transaction was canceled due to a KILL request
* When any of these occur, update ->status and wake up the waitq.
* ->status must be cleared before kicking off the next transaction.
+ *
+* (2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
+* occurs for each byte of a byte-by-byte to prepare the next byte.
*/
static irqreturn_t i801_isr(int irq, void *dev_id)
{
struct i801_priv *priv = dev_id;
u8 pcists, hststs;
+ u8 cmd;
/* Confirm this is our interrupt */
pci_read_config_byte(priv->pci_dev, SMBPCISTS, &pcists);
@@ -391,6 +404,27 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
hststs = inb(SMBHSTSTS(priv));
dev_dbg(&priv->pci_dev->dev, "irq: hststs = %02x\n", hststs);
+ if (hststs & SMBHSTSTS_BYTE_DONE) {
+ if (priv->is_read) {
+ priv->data[priv->count++] = inb(SMBBLKDAT(priv));
+
+ /* Set LAST_BYTE for last byte of read transaction */
+ cmd = priv->cmd;
+ if (priv->count == priv->len - 1)
+ cmd |= I801_LAST_BYTE;
+ outb_p(cmd | I801_START, SMBHSTCNT(priv));
+ } else if (priv->count < priv->len - 1) {
+ outb(priv->data[++priv->count], SMBBLKDAT(priv));
+ outb_p(priv->cmd | I801_START, SMBHSTCNT(priv));
+ }
+
+ /* Clear BYTE_DONE to start next transaction. */
+ outb(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
+
+ /* Clear BYTE_DONE so it does not wake_up waitq */
+ hststs &= ~SMBHSTSTS_BYTE_DONE;
+ }
+
/*
* Clear irq sources and report transaction result.
* ->status must be cleared before the next transaction is started.
@@ -437,6 +471,21 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
else
smbcmd = I801_BLOCK_DATA;
+ if (priv->features & FEATURE_IRQ) {
+ priv->is_read = (read_write == I2C_SMBUS_READ);
+ if (len == 1 && priv->is_read)
+ smbcmd |= I801_LAST_BYTE;
+ priv->cmd = smbcmd | I801_INTREN;
+ priv->len = len;
+ priv->count = 0;
+ priv->data = &data->block[1];
+
+ outb(priv->cmd | I801_START, SMBHSTCNT(priv));
+ wait_event(priv->waitq, (status = priv->status));
+ priv->status = 0;
+ return i801_check_post(priv, status, 0);
+ }
+
for (i = 1; i <= len; i++) {
if (i == len && read_write == I2C_SMBUS_READ)
smbcmd |= I801_LAST_BYTE;
--
1.7.3.1
next prev parent reply other threads:[~2012-01-06 10:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-06 10:58 [PATCH 0/3 v2] i2c: i801: enable irq Daniel Kurtz
2012-01-06 10:58 ` [PATCH 1/3] i2c: i801: refactor i801_block_transaction_byte_by_byte Daniel Kurtz
[not found] ` <1325847502-17841-2-git-send-email-djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-06-19 14:42 ` Jean Delvare
[not found] ` <1325847502-17841-1-git-send-email-djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-01-06 10:58 ` [PATCH 2/3 v2] i2c: i801: enable irq for i801 smbus transactions Daniel Kurtz
[not found] ` <1325847502-17841-3-git-send-email-djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-06-19 18:47 ` Jean Delvare
[not found] ` <20120619204704.69454016-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-06-20 8:58 ` Jean Delvare
[not found] ` <20120620105847.65cf37f2-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-06-20 10:21 ` Daniel Kurtz
[not found] ` <CAGS+omDLYvqM69MFbU-pE6mAKT3tQnRw08aqbK73-hUBjOmZ0w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-06-20 10:51 ` Jean Delvare
2012-06-20 7:42 ` Jean Delvare
2012-01-06 10:58 ` Daniel Kurtz [this message]
2012-06-20 13:34 ` [PATCH 3/3 v2] i2c: i801: enable irq for byte_by_byte transactions Jean Delvare
[not found] ` <20120620153449.5cee35fa-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-06-26 16:24 ` Jean Delvare
2012-01-06 11:35 ` [PATCH 0/3 v2] i2c: i801: enable irq Jean Delvare
[not found] ` <20120106123531.3b5ca7db-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-02-20 11:23 ` Daniel Kurtz
[not found] ` <CAGS+omBvULkWsowprvVWkodBxT=diui7g5GtKZ0mb=Uy7DZKtg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-05-09 6:36 ` Daniel Kurtz
2012-06-27 9:24 ` Jean Delvare
[not found] ` <20120627112402.26576746-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-06-27 13:56 ` Daniel Kurtz
[not found] ` <CAGS+omDYaPBQiKBiVewbwZR2Vnjv+NfqbZxc+fknpCBNvRFRKw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-06-27 14:01 ` Jean Delvare
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1325847502-17841-4-git-send-email-djkurtz@chromium.org \
--to=djkurtz-f7+t8e8rja9g9huczpvpmw@public.gmane.org \
--cc=David.Woodhouse-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=ben-/+tVBieCtBitmTQ+vhA3Yw@public.gmane.org \
--cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
--cc=bleung-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=olofj-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=seth.heasley-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).