linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: minyard@acm.org
To: Jean Delvare <jdelvare@suse.com>, linux-i2c@vger.kernel.org
Cc: Corey Minyard <cminyard@mvista.com>
Subject: [PATCH 3/5] i2c-i801: Move PEC handling into i2c_block_transaction()
Date: Tue, 19 Jan 2016 11:09:35 -0600	[thread overview]
Message-ID: <1453223377-20608-4-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>

PEC is only used on real block transactions, moving it into the block
transaction code allows removal of some if statements and the proper
setting of SMBAUXCTL.  PEC was being set in the byte-by-byte block
transaction, though it wasn't valid in that situation.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
 drivers/i2c/busses/i2c-i801.c | 52 ++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 9143fcf..7567a96 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -669,14 +669,31 @@ static int i801_block_transaction(struct i801_priv *priv,
 	if ((priv->features & FEATURE_BLOCK_BUFFER)
 	 && command != I2C_SMBUS_I2C_BLOCK_DATA
 	 && i801_set_block_buffer_mode(priv) == 0) {
-		if (hwpec)
+		if (hwpec) {	/* enable/disable hardware PEC */
+			outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC,
+			       SMBAUXCTL(priv));
 			priv->xact_extra |= SMBHSTCNT_PEC_EN;
+		} else
+			outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
+			       SMBAUXCTL(priv));
+
 		result = i801_block_transaction_by_block(priv, data,
 							 read_write);
-	} else
+	} else {
+		outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
+		       SMBAUXCTL(priv));
 		result = i801_block_transaction_byte_by_byte(priv, data,
 							     read_write,
 							     command);
+	}
+
+	/*
+	 * Some BIOSes don't like it when PEC is enabled at reboot or resume
+	 * time, so we forcibly disable it after every transaction. Turn off
+	 * E32B for the same reason.
+	 */
+	outb_p(inb_p(SMBAUXCTL(priv)) &
+	       ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
 
 	return result;
 }
@@ -686,17 +703,12 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 		       unsigned short flags, char read_write, u8 command,
 		       int size, union i2c_smbus_data *data)
 {
-	int hwpec;
 	int block = 0;
 	int ret, xact = 0;
 	struct i801_priv *priv = i2c_get_adapdata(adap);
 	int result;
 	int hostc = -1;
 
-	hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
-		&& size != I2C_SMBUS_QUICK
-		&& size != I2C_SMBUS_I2C_BLOCK_DATA;
-
 	switch (size) {
 	case I2C_SMBUS_QUICK:
 		outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
@@ -766,26 +778,20 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 	if (result < 0)
 		return result;
 
-	if (hwpec) {	/* enable/disable hardware PEC */
-		outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
-	} else {
-		outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
-		       SMBAUXCTL(priv));
-		priv->xact_extra &= ~SMBHSTCNT_PEC_EN;
-	}
+	priv->xact_extra &= ~SMBHSTCNT_PEC_EN;
+	if (block) {
+		int hwpec = (priv->features & FEATURE_SMBUS_PEC) &&
+			(flags & I2C_CLIENT_PEC)
+			&& size != I2C_SMBUS_QUICK
+			&& size != I2C_SMBUS_I2C_BLOCK_DATA;
 
-	if (block)
 		ret = i801_block_transaction(priv, data, read_write, size,
 					     hwpec);
-	else
+	} else {
+		outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
+		       SMBAUXCTL(priv));
 		ret = i801_transaction(priv, xact);
-
-	/* Some BIOSes don't like it when PEC is enabled at reboot or resume
-	   time, so we forcibly disable it after every transaction. Turn off
-	   E32B for the same reason. */
-	if (hwpec || block)
-		outb_p(inb_p(SMBAUXCTL(priv)) &
-		       ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B), SMBAUXCTL(priv));
+	}
 
 	if (hostc >= 0)
 		pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hostc);
-- 
2.5.0

  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 ` minyard [this message]
2016-05-25 12:00   ` [PATCH 3/5] i2c-i801: Move PEC handling into i2c_block_transaction() Jean Delvare
2016-01-19 17:09 ` [PATCH 4/5] i2c-i801: clean up block transaction minyard
2016-05-25 12:31   ` 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-4-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).