From: minyard@acm.org
To: Jean Delvare <jdelvare@suse.com>, linux-i2c@vger.kernel.org
Cc: Corey Minyard <cminyard@mvista.com>
Subject: [PATCH 4/5] i2c-i801: clean up block transaction
Date: Tue, 19 Jan 2016 11:09:36 -0600 [thread overview]
Message-ID: <1453223377-20608-5-git-send-email-minyard@acm.org> (raw)
In-Reply-To: <1453223377-20608-1-git-send-email-minyard@acm.org>
From: Corey Minyard <cminyard@mvista.com>
The block transaction code looked a little messy, pull out the
code to copy to/from the buffer into separate functions to make
it a little neater.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
drivers/i2c/busses/i2c-i801.c | 54 +++++++++++++++++++++++++++----------------
1 file changed, 34 insertions(+), 20 deletions(-)
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 7567a96..840656c 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -425,37 +425,51 @@ static int i801_transaction(struct i801_priv *priv, int xact)
return i801_check_post(priv, status);
}
+static void i801_write_block(struct i801_priv *priv, union i2c_smbus_data *data)
+{
+ int i, len;
+
+ len = data->block[0];
+ outb_p(len, SMBHSTDAT0(priv));
+ for (i = 0; i < len; i++)
+ outb_p(data->block[i+1], SMBBLKDAT(priv));
+}
+
+static int i801_read_block(struct i801_priv *priv, union i2c_smbus_data *data)
+{
+ int i, len;
+
+ len = inb_p(SMBHSTDAT0(priv));
+ if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
+ return -EPROTO;
+
+ data->block[0] = len;
+ for (i = 0; i < len; i++)
+ data->block[i + 1] = inb_p(SMBBLKDAT(priv));
+
+ return 0;
+}
+
static int i801_block_transaction_by_block(struct i801_priv *priv,
union i2c_smbus_data *data,
char read_write)
{
- int i, len;
- int status;
+ int result;
inb_p(SMBHSTCNT(priv)); /* reset the data buffer index */
/* Use 32-byte buffer to process this transaction */
- if (read_write == I2C_SMBUS_WRITE) {
- len = data->block[0];
- outb_p(len, SMBHSTDAT0(priv));
- for (i = 0; i < len; i++)
- outb_p(data->block[i+1], SMBBLKDAT(priv));
- }
+ if (read_write == I2C_SMBUS_WRITE)
+ i801_write_block(priv, data);
- status = i801_transaction(priv, I801_BLOCK_DATA);
- if (status)
- return status;
+ result = i801_transaction(priv, I801_BLOCK_DATA);
+ if (result)
+ return result;
- if (read_write == I2C_SMBUS_READ) {
- len = inb_p(SMBHSTDAT0(priv));
- if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
- return -EPROTO;
+ if (read_write == I2C_SMBUS_READ)
+ result = i801_read_block(priv, data);
- data->block[0] = len;
- for (i = 0; i < len; i++)
- data->block[i + 1] = inb_p(SMBBLKDAT(priv));
- }
- return 0;
+ return result;
}
static void i801_isr_byte_done(struct i801_priv *priv)
--
2.5.0
next prev parent reply other threads:[~2016-01-19 18:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-19 17:09 [PATCH 0/5] minyard
2016-01-19 17:09 ` [PATCH 1/5] i2c-i801: hwpec and check_pre cleanups minyard
2016-05-25 9:30 ` Jean Delvare
2016-05-25 11:04 ` Jean Delvare
2016-01-19 17:09 ` [PATCH 2/5] i2c-i801: Move hostcfg set/reset to i801_access() minyard
2016-05-25 11:42 ` Jean Delvare
2016-01-19 17:09 ` [PATCH 3/5] i2c-i801: Move PEC handling into i2c_block_transaction() minyard
2016-05-25 12:00 ` Jean Delvare
2016-01-19 17:09 ` minyard [this message]
2016-05-25 12:31 ` [PATCH 4/5] i2c-i801: clean up block transaction Jean Delvare
2016-01-19 17:09 ` [PATCH 5/5] i2c-i801: Remove redundant code and event-drive minyard
2016-05-25 12:52 ` Jean Delvare
2016-05-25 16:58 ` Corey Minyard
2016-05-26 7:17 ` Jean Delvare
2016-05-26 12:15 ` Corey Minyard
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=1453223377-20608-5-git-send-email-minyard@acm.org \
--to=minyard@acm.org \
--cc=cminyard@mvista.com \
--cc=jdelvare@suse.com \
--cc=linux-i2c@vger.kernel.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).