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: 29527 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f70.google.com (mail-yh0-f70.google.com [209.85.213.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4D72F20675 for ; Thu, 1 May 2014 18:49:57 +0000 (UTC) Received: by mail-yh0-f70.google.com with SMTP id a41sf3977045yho.1 for ; Thu, 01 May 2014 11:49:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type; bh=ALXNRTrCs4Oop28mF6/cYM1/s5gKvutVZ+brrb0COMw=; b=Ur+LwipTrjy2VCiXRvVmq4lEGixUl+/ogyne+lN7oH7+Rr+kaDACg+hNk6FuXFymKV qKpHWMA6ancgA0sDEpVaVl62VD96Mz2wOxLF+hkaMaOZs5wIGJTFiV18VPg4ut1rnLXk /GeYp5ImAyzFKVkoFCuXtgNj17eiwZgdPyVWHLUyP5wPrqPTg5zSlrRkKYbYT9Jp25PB P9bxmeY+L+GmRUTaAUk8Gw5tnr5xbqW+8YN2hHJ86hu8MgMl+E0UP9IZ4MlRdqQgqwK3 cYlE3GlMDR8E0IbaBwUUUNKq5Igp5m6mBYMooAivMKk7Hw6/Fj3NG0OBIJQc6ZCWEeaB 3W3w== X-Gm-Message-State: ALoCoQl5n2N0lRbFcpJkUOsRyZeRljvJdJ42ownuYMQwIIKpZ8YZacOH1w3DoQXVT+Nbpj5QHrYR X-Received: by 10.236.1.198 with SMTP id 46mr5298206yhd.16.1398970197608; Thu, 01 May 2014 11:49:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.22.6 with SMTP id 6ls1211376qgm.50.gmail; Thu, 01 May 2014 11:49:57 -0700 (PDT) X-Received: by 10.220.81.194 with SMTP id y2mr2072085vck.29.1398970197494; Thu, 01 May 2014 11:49:57 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id sq9si6196374vdc.35.2014.05.01.11.49.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 11:49:57 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hr9so4404581vcb.29 for ; Thu, 01 May 2014 11:49:57 -0700 (PDT) X-Received: by 10.58.22.38 with SMTP id a6mr843899vef.58.1398970197402; Thu, 01 May 2014 11:49:57 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp46075vcb; Thu, 1 May 2014 11:49:56 -0700 (PDT) X-Received: by 10.66.218.193 with SMTP id pi1mr24448262pac.20.1398970196597; Thu, 01 May 2014 11:49:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yd10si21553798pab.248.2014.05.01.11.49.56; Thu, 01 May 2014 11:49:56 -0700 (PDT) Received-SPF: none (google.com: linux-i2c-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750818AbaEAStz (ORCPT + 2 others); Thu, 1 May 2014 14:49:55 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:51446 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750806AbaEASty (ORCPT ); Thu, 1 May 2014 14:49:54 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s41InoLo000554; Thu, 1 May 2014 13:49:50 -0500 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: , , CC: Murali Karicheri , Garrett Ding , Sekhar Nori , Kevin Hilman , Wolfram Sang , Santosh Shilimkar 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 Sender: linux-i2c-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-i2c@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m-karicheri2@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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;