From patchwork Thu May 1 18:49:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 4099961 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3AB9D9F271 for ; Thu, 1 May 2014 18:50:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E31C2034F for ; Thu, 1 May 2014 18:50:06 +0000 (UTC) Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1E5872034C for ; Thu, 1 May 2014 18:50:05 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s41Io3Va031606 for ; Thu, 1 May 2014 13:50:04 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s41Io3RW027617 for ; Thu, 1 May 2014 13:50:03 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Thu, 1 May 2014 13:50:03 -0500 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s41Io3QR032212 for ; Thu, 1 May 2014 13:50:03 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 4140C8062D for ; Thu, 1 May 2014 13:50:03 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dlelxv90.itg.ti.com (dlelxv90.itg.ti.com [172.17.2.17]) by linux.omap.com (Postfix) with ESMTP id BFBFB80626 for ; Thu, 1 May 2014 13:49:50 -0500 (CDT) Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s41InoAV027310; Thu, 1 May 2014 13:49:50 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Thu, 1 May 2014 13:49:49 -0500 Received: from ares-ubuntu.am.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s41Inn6w000327; Thu, 1 May 2014 13:49:50 -0500 Received: from a0868495 by ares-ubuntu.am.dhcp.ti.com with local (Exim 4.76) (envelope-from ) id 1Wfw3J-0003BP-Fn; Thu, 01 May 2014 14:49:49 -0400 From: Murali Karicheri To: , , Subject: [PATCH] i2c: davinci: Add block read functionality for IPMI Date: Thu, 1 May 2014 14:49:46 -0400 Message-ID: <1398970186-12204-1-git-send-email-m-karicheri2@ti.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 CC: Wolfram Sang , Kevin Hilman , Santosh Shilimkar , Garrett Ding X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: Errors-To: davinci-linux-open-source-bounces+patchwork-davinci=patchwork.kernel.org@linux.davincidsp.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Intelligent Plaform Management Interface (IPMI) requires I2C driver to support block read, where the first byte received from slave is the length of following data:- Added length check if the read type is block read (I2C_M_RECV_LEN) Send NACK/STOP bits before last byte is received Signed-off-by: Garrett Ding Signed-off-by: Murali Karicheri Tested-by: Garrett Ding CC: Sekhar Nori CC: Kevin Hilman CC: Wolfram Sang CC: Santosh Shilimkar Tested-by: Sekhar Nori --- Tested on a customer board based on K2HK SoC drivers/i2c/busses/i2c-davinci.c | 42 +++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 389bc68..cd97920 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c @@ -97,6 +97,10 @@ #define DAVINCI_I2C_IMR_NACK BIT(1) #define DAVINCI_I2C_IMR_AL BIT(0) +/* capabilities */ +#define I2C_CAPABILITIES (I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | \ + I2C_FUNC_SMBUS_READ_BLOCK_DATA) + struct davinci_i2c_dev { struct device *dev; void __iomem *base; @@ -318,7 +322,13 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) davinci_i2c_write_reg(dev, DAVINCI_I2C_SAR_REG, msg->addr); dev->buf = msg->buf; - dev->buf_len = msg->len; + + /* if first received byte is length, set buf_len = 0xffff as flag */ + if (msg->flags & I2C_M_RECV_LEN) + dev->buf_len = 0xffff; + else + dev->buf_len = msg->len; + dev->stop = stop; davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len); @@ -456,7 +466,7 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) static u32 i2c_davinci_func(struct i2c_adapter *adap) { - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; + return I2C_CAPABILITIES; } static void terminate_read(struct davinci_i2c_dev *dev) @@ -528,10 +538,32 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id) case DAVINCI_I2C_IVR_RDR: if (dev->buf_len) { - *dev->buf++ = - davinci_i2c_read_reg(dev, - DAVINCI_I2C_DRR_REG); + *dev->buf++ = davinci_i2c_read_reg(dev, + DAVINCI_I2C_DRR_REG); + /* + * check if the first received byte is message + * length, i.e, I2C_M_RECV_LEN + */ + if (dev->buf_len == 0xffff) + dev->buf_len = *(dev->buf - 1) + 1; + dev->buf_len--; + /* + * send NACK/STOP bits BEFORE last byte is + * received + */ + if (dev->buf_len == 1) { + w = davinci_i2c_read_reg(dev, + DAVINCI_I2C_MDR_REG); + w |= DAVINCI_I2C_MDR_NACK; + davinci_i2c_write_reg(dev, + DAVINCI_I2C_MDR_REG, w); + + w |= DAVINCI_I2C_MDR_STP; + davinci_i2c_write_reg(dev, + DAVINCI_I2C_MDR_REG, w); + } + if (dev->buf_len) continue;