From patchwork Tue Apr 9 04:59:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasanna Kumar X-Patchwork-Id: 2412901 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id BCBA73FC71 for ; Tue, 9 Apr 2013 04:52:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750740Ab3DIEwt (ORCPT ); Tue, 9 Apr 2013 00:52:49 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:41541 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750713Ab3DIEws (ORCPT ); Tue, 9 Apr 2013 00:52:48 -0400 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MKZ00DZN1J55A80@mailout4.samsung.com>; Tue, 09 Apr 2013 13:52:24 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.125]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id BB.F0.20872.78E93615; Tue, 09 Apr 2013 13:52:24 +0900 (KST) X-AuditID: cbfee68d-b7f786d000005188-37-51639e87cf0a Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 47.BE.17838.78E93615; Tue, 09 Apr 2013 13:52:23 +0900 (KST) Received: from user-ubuntu.sisodomain.com ([107.108.83.235]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MKZ00GV01J3AP90@mmp2.samsung.com>; Tue, 09 Apr 2013 13:52:23 +0900 (KST) From: Prasanna Kumar To: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org Cc: w.sang@pengutronix.de, khali@linux-fr.org, ben-linux@fluff.org, grant.likely@secretlab.ca, kgene.kim@samsung.com, jmin.yoo@samsung.com Subject: [PATCH RESEND] i2c: s3c2410: Add SMBus emulation for block read Date: Tue, 09 Apr 2013 10:29:18 +0530 Message-id: <1365483558-4054-1-git-send-email-prasanna.ps@samsung.com> X-Mailer: git-send-email 1.7.5.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRmVeSWpSXmKPExsWyRsSkVrdjXnKgwekuVotJ6w4wWbw6s5HN 4s7K7SwWvQuuslk0/o202PT4GqtFx98vjBYzzu9jstj3eiuzA6fH31UvmD2uNJxk89i8pN6j /6+BR9+WVYweP1/qeHzeJBfAHsVlk5Kak1mWWqRvl8CV0fPkFFPBNf6Kr3/7mRsYr/J0MXJy SAiYSMxcdo0NwhaTuHBvPZDNxSEksJRRYt2KdhaYorMzLrCC2EIC0xkleh9EQBR1M0nMXPSF ESTBJqAnMX/GcnYQW0QgQ+L9+vlgk5gFehgl7s3sBOsWFvCQmN7+mrmLkYODRUBV4sZtsCt4 Bdwkpr/vgLpCQeLXkVWsEPY8donv25NAbBYBAYlvkw+xgLRKCMhKbDrADFEiKXFwxQ2WCYyC CxgZVjGKphYkFxQnpRcZ6hUn5haX5qXrJefnbmIEBvXpf896dzDePmB9iDEZaNxEZinR5Hxg VOSVxBsamxlZmJqYGhuZW5qRJqwkzqvWYh0oJJCeWJKanZpakFoUX1Sak1p8iJGJg1OqgbH6 /7T/vgmnr1ZMfvslY27ou1gBOUbx5xGcdxzOHr571yFiZu63DO21VQl/PT+k+L89K71Y2p9n zY5rS+/e4QiYf+yWs/z2PZ+7nLZMefgof/+B5T9Wnj1z/edTQb5Xh//t5fDV3xxtdG+VluiU q13OW88UGakqbH6UX16+Q6Ns/s6ld8JTNXa3KrEUZyQaajEXFScCAOf8sQuAAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNIsWRmVeSWpSXmKPExsVy+t9jQd32ecmBBiu7zC0mrTvAZPHqzEY2 izsrt7NY9C64ymbR+DfSYtPja6wWHX+/MFrMOL+PyWLf663MDpwef1e9YPa40nCSzWPzknqP /r8GHn1bVjF6/Hyp4/F5k1wAe1QDo01GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5 kkJeYm6qrZKLT4CuW2YO0F1KCmWJOaVAoYDE4mIlfTtME0JD3HQtYBojdH1DguB6jAzQQMIa xoyeJ6eYCq7xV3z928/cwHiVp4uRk0NCwETi7IwLrBC2mMSFe+vZQGwhgemMEr0PIroYuYDs biaJmYu+MIIk2AT0JObPWM4OYosIZEi8Xz+fDaSIWaCHUeLezE6wScICHhLT218zdzFycLAI qErcuA22jFfATWL6+w42iGUKEr+OrGKdwMi9gJFhFaNoakFyQXFSeq6hXnFibnFpXrpecn7u JkZw1DyT2sG4ssHiEKMAB6MSD++FJ0mBQqyJZcWVuYcYJTiYlUR4uw2TA4V4UxIrq1KL8uOL SnNSiw8xJgMtn8gsJZqcD4zovJJ4Q2MTc1NjU0sTCxMzS9KElcR5D7RaBwoJpCeWpGanphak FsFsYeLglGpglI1NudF2W3dXCMuVzzG1rR/udV+x3RnmvjVf4uv1A0dyVZm2BZl5LxP8/LNd QMJp+ZmcYEEdJ2UFjmutJSXiTPMXlWk2iyzd+OrDgsr/u5a/3bvyW2BF8aafx2dv+Gvf+NhC 3nNCCF/zhdQW4y/H5mb3OBzXXLHK5U2SoKjULtPr59RTFZ9dU2Ipzkg01GIuKk4EALhQsC7e AgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org From: Jaemin Yoo SMBus read and write are supported by the emulation layer of i2c framework if the controller doesn't have SMBus features. I2C_M_RECV_LEN flag is used to let i2c drivers know rx length is not yet determined but will be read to the first byte in rx buffer. s3c2410 doesn't handle this flag. So only one byte is read from slave. There fore following two features are added to the driver code. 1. skip rx length check if I2C_M_RECV_LEN is set and the length is 1. 2. add actual bytes to the rx length after reading first bytes if I2C_M_RECV_LEN. I2C_M_RECV_LEN is only set for SMBus command. So this code does not affect legacy codes which only use i2c command for s3c2410. Signed-off-by: Jaemin Yoo Signed-off-by: Prasanna Kumar --- drivers/i2c/busses/i2c-s3c2410.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 17c5c37..e4ab9ea 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -309,6 +309,12 @@ static inline int is_lastmsg(struct s3c24xx_i2c *i2c) static inline int is_msglast(struct s3c24xx_i2c *i2c) { + /* msg->len is always 1 for the first byte of smbus block read. + * Actual length will be read from slave. More bytes will be + * read according to the length then. */ + if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1) + return 0; + return i2c->msg_ptr == i2c->msg->len-1; } @@ -448,6 +454,9 @@ static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) byte = readb(i2c->regs + S3C2410_IICDS); i2c->msg->buf[i2c->msg_ptr++] = byte; + /* Add actual length to read for smbus block read */ + if (i2c->msg->flags & I2C_M_RECV_LEN && i2c->msg->len == 1) + i2c->msg->len += byte; prepare_read: if (is_msglast(i2c)) { /* last byte of buffer */