From patchwork Tue Jan 19 17:09:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 59993 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2727314lbb; Tue, 19 Jan 2016 10:10:12 -0800 (PST) X-Received: by 10.98.13.197 with SMTP id 66mr45598268pfn.125.1453227012565; Tue, 19 Jan 2016 10:10:12 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si48928117pfk.172.2016.01.19.10.10.12; Tue, 19 Jan 2016 10:10:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932591AbcASSKB (ORCPT + 1 other); Tue, 19 Jan 2016 13:10:01 -0500 Received: from vms173025pub.verizon.net ([206.46.173.25]:62032 "EHLO vms173025pub.verizon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932933AbcASSJ6 (ORCPT ); Tue, 19 Jan 2016 13:09:58 -0500 X-Greylist: delayed 3600 seconds by postgrey-1.27 at vger.kernel.org; Tue, 19 Jan 2016 13:09:57 EST Received: from serve.minyard.net ([173.57.176.17]) by vms173025.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0O1700LX5MC4TW30@vms173025.mailsrvcs.net> for linux-i2c@vger.kernel.org; Tue, 19 Jan 2016 11:09:41 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=WpDWSorv c=1 sm=1 tr=0 a=bXmWQgKa9n63w7XTPFb8JQ==:117 a=N54-gffFAAAA:8 a=HL3alpDKAAAA:8 a=oR5dmqMzAAAA:8 a=xqWC_Br6kY4A:10 a=7aQ_Q-yQQ-AA:10 a=fk1lIlRQAAAA:8 a=c4kJbCyHevqSCC69RtYA:9 Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:8d:b94b:720b:cc15]) by serve.minyard.net (Postfix) with ESMTPA id 96E49326E; Tue, 19 Jan 2016 11:09:40 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 122B6300740; Tue, 19 Jan 2016 11:09:39 -0600 (CST) From: minyard@acm.org To: Jean Delvare , linux-i2c@vger.kernel.org Cc: Corey Minyard Subject: [PATCH 1/5] i2c-i801: hwpec and check_pre cleanups Date: Tue, 19 Jan 2016 11:09:33 -0600 Message-id: <1453223377-20608-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.5.0 In-reply-to: <1453223377-20608-1-git-send-email-minyard@acm.org> References: <1453223377-20608-1-git-send-email-minyard@acm.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Corey Minyard Add an "xact_extra" variable and use it to carry the PEC enable and interrupt flags . Also move i801_check_pre() to i801_access() That consolidates it to one call, and there's no point in doing all the work if the hardware isn't ready. Signed-off-by: Corey Minyard --- drivers/i2c/busses/i2c-i801.c | 51 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 25 deletions(-) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index f62d697..62cf1e5 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c @@ -230,6 +230,7 @@ struct i801_priv { /* isr processing */ wait_queue_head_t waitq; u8 status; + u8 xact_extra; /* Used to set INTREN if irqs enabled, and HWPEC */ /* Command state used by isr for byte-by-byte block transactions */ u8 cmd; @@ -401,13 +402,13 @@ static int i801_transaction(struct i801_priv *priv, int xact) int result; const struct i2c_adapter *adap = &priv->adapter; - result = i801_check_pre(priv); - if (result < 0) - return result; + /* + * the current contents of SMBHSTCNT can be overwritten, since PEC, + * SMBSCMD are passed in xact + */ + outb_p(xact | priv->xact_extra | SMBHSTCNT_START, SMBHSTCNT(priv)); if (priv->features & FEATURE_IRQ) { - outb_p(xact | SMBHSTCNT_INTREN | SMBHSTCNT_START, - SMBHSTCNT(priv)); result = wait_event_timeout(priv->waitq, (status = priv->status), adap->timeout); @@ -420,17 +421,13 @@ static int i801_transaction(struct i801_priv *priv, int xact) return i801_check_post(priv, status); } - /* the current contents of SMBHSTCNT can be overwritten, since PEC, - * SMBSCMD are passed in xact */ - outb_p(xact | SMBHSTCNT_START, SMBHSTCNT(priv)); - status = i801_wait_intr(priv); return i801_check_post(priv, status); } static int i801_block_transaction_by_block(struct i801_priv *priv, union i2c_smbus_data *data, - char read_write, int hwpec) + char read_write) { int i, len; int status; @@ -445,8 +442,7 @@ static int i801_block_transaction_by_block(struct i801_priv *priv, outb_p(data->block[i+1], SMBBLKDAT(priv)); } - status = i801_transaction(priv, I801_BLOCK_DATA | - (hwpec ? SMBHSTCNT_PEC_EN : 0)); + status = i801_transaction(priv, I801_BLOCK_DATA); if (status) return status; @@ -553,8 +549,7 @@ static irqreturn_t i801_isr(int irq, void *dev_id) */ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, union i2c_smbus_data *data, - char read_write, int command, - int hwpec) + char read_write, int command) { int i, len; int smbcmd; @@ -562,10 +557,6 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, int result; const struct i2c_adapter *adap = &priv->adapter; - result = i801_check_pre(priv); - if (result < 0) - return result; - len = data->block[0]; if (read_write == I2C_SMBUS_WRITE) { @@ -583,7 +574,7 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv, priv->is_read = (read_write == I2C_SMBUS_READ); if (len == 1 && priv->is_read) smbcmd |= SMBHSTCNT_LAST_BYTE; - priv->cmd = smbcmd | SMBHSTCNT_INTREN; + priv->cmd = smbcmd | priv->xact_extra; priv->len = len; priv->count = 0; priv->data = &data->block[1]; @@ -691,13 +682,15 @@ static int i801_block_transaction(struct i801_priv *priv, doesn't mention this limitation. */ if ((priv->features & FEATURE_BLOCK_BUFFER) && command != I2C_SMBUS_I2C_BLOCK_DATA - && i801_set_block_buffer_mode(priv) == 0) + && i801_set_block_buffer_mode(priv) == 0) { + if (hwpec) + priv->xact_extra |= SMBHSTCNT_PEC_EN; result = i801_block_transaction_by_block(priv, data, - read_write, hwpec); - else + read_write); + } else result = i801_block_transaction_byte_by_byte(priv, data, read_write, - command, hwpec); + command); if (command == I2C_SMBUS_I2C_BLOCK_DATA && read_write == I2C_SMBUS_WRITE) { @@ -716,6 +709,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, int block = 0; int ret, xact = 0; struct i801_priv *priv = i2c_get_adapdata(adap); + int result; hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK @@ -776,11 +770,17 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, return -EOPNOTSUPP; } - if (hwpec) /* enable/disable hardware PEC */ + result = i801_check_pre(priv); + if (result < 0) + return result; + + if (hwpec) { /* enable/disable hardware PEC */ outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv)); - else + } else { outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC), SMBAUXCTL(priv)); + priv->xact_extra &= ~SMBHSTCNT_PEC_EN; + } if (block) ret = i801_block_transaction(priv, data, read_write, size, @@ -1381,6 +1381,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id) } if (priv->features & FEATURE_IRQ) { + priv->xact_extra |= SMBHSTCNT_INTREN; init_waitqueue_head(&priv->waitq); err = devm_request_irq(&dev->dev, dev->irq, i801_isr,