From patchwork Tue Jan 19 17:09:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 59996 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2727494lbb; Tue, 19 Jan 2016 10:10:30 -0800 (PST) X-Received: by 10.98.87.196 with SMTP id i65mr45794644pfj.72.1453227024137; Tue, 19 Jan 2016 10:10:24 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p13si48990938pfi.234.2016.01.19.10.10.23; Tue, 19 Jan 2016 10:10:24 -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 S932960AbcASSKT (ORCPT + 1 other); Tue, 19 Jan 2016 13:10:19 -0500 Received: from vms173019pub.verizon.net ([206.46.173.19]:53555 "EHLO vms173019pub.verizon.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932558AbcASSKN (ORCPT ); Tue, 19 Jan 2016 13:10:13 -0500 X-Greylist: delayed 3608 seconds by postgrey-1.27 at vger.kernel.org; Tue, 19 Jan 2016 13:10:13 EST Received: from serve.minyard.net ([173.57.176.17]) by vms173019.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0O1700JBHMC44Z80@vms173019.mailsrvcs.net> for linux-i2c@vger.kernel.org; Tue, 19 Jan 2016 11:09:45 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=Nc0brD34 c=1 sm=1 tr=0 a=bXmWQgKa9n63w7XTPFb8JQ==:117 a=N54-gffFAAAA:8 a=HL3alpDKAAAA:8 a=oR5dmqMzAAAA:8 a=7aQ_Q-yQQ-AA:10 a=fk1lIlRQAAAA:8 a=nDuVJYjCUDgrT7UzJD4A:9 Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 6110A3267; Tue, 19 Jan 2016 11:09:40 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 4FA1C300770; 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 4/5] i2c-i801: clean up block transaction Date: Tue, 19 Jan 2016 11:09:36 -0600 Message-id: <1453223377-20608-5-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 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 --- drivers/i2c/busses/i2c-i801.c | 54 +++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 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 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)