From patchwork Tue Oct 10 06:27:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamlakant Patel X-Patchwork-Id: 9995083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B80D1603B5 for ; Tue, 10 Oct 2017 06:27:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A93F627CAF for ; Tue, 10 Oct 2017 06:27:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E27B27D0C; Tue, 10 Oct 2017 06:27:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24F7327CAF for ; Tue, 10 Oct 2017 06:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752372AbdJJG1w (ORCPT ); Tue, 10 Oct 2017 02:27:52 -0400 Received: from mail-sn1nam02on0069.outbound.protection.outlook.com ([104.47.36.69]:21556 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754108AbdJJG1q (ORCPT ); Tue, 10 Oct 2017 02:27:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5IaXxBKhVhHdRjEH9CKC3efAsf/1c760oW0X1vkH9fk=; b=KcG12lWnk+lo8/h8Z5BEIZ7KwaQhqn4fLRVrDGqdg2DKHn/He4UjG7O7WEiRLGivS58kAh/F+pOoGTQSCpfAHepbCbNlFO0eN7IUytI2QUmfaB+LX9B/BkSTE8HoSTwvubcaRoGirPeZjuQDk0hQr438gIM4g+JTRe3n8BmwNks= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Kamlakant.Patel@cavium.com; Received: from localhost.localdomain (111.93.218.67) by SN1PR07MB2142.namprd07.prod.outlook.com (10.164.47.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Tue, 10 Oct 2017 06:27:40 +0000 From: Kamlakant Patel To: linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Kamlakant Patel , Wolfram Sang , Mika Westerberg , "Rafael J. Wysocki" , Jayachandran C Subject: [PATCH v2 3/3] i2c: xlp9xx: Handle I2C_M_RECV_LEN in msg->flags Date: Tue, 10 Oct 2017 11:57:56 +0530 Message-Id: <1507616876-17189-4-git-send-email-kamlakant.patel@cavium.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507616876-17189-1-git-send-email-kamlakant.patel@cavium.com> References: <1507616876-17189-1-git-send-email-kamlakant.patel@cavium.com> MIME-Version: 1.0 X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: PN1PR01CA0102.INDPRD01.PROD.OUTLOOK.COM (10.174.144.18) To SN1PR07MB2142.namprd07.prod.outlook.com (10.164.47.12) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c590f0da-6874-4993-188b-08d50fa803e1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:SN1PR07MB2142; X-Microsoft-Exchange-Diagnostics: 1; SN1PR07MB2142; 3:5Adi/kWxNDSOsAxsT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yw8y6u0bJZHyduan0uKuY69eEacZEqvdsH+wYTQn7TxjxF9rDU/GOmzCWa6tguZzyFHHQ3IOWBE8tMu/DElV29IdefezPLfPKIBXq1WLlgME5K7cCcmrvOGwPKejm4AT4AW3sAqf/oqgqKVDKizZvNi5ThJREkH4dm/u33HNzVkeihojRgiZT1HZMhkvXmd9TdAZ1jL9thiaFcDmWhtwzNTNugRlEnsQeAqrnIcAhSj2Qfs+obNYoHshpYKLMUHii9QXI+vMA8m8/UkHxpT3zzPtnRcaIA4wJSeVeAUxcMcHVIJJyFVN2cZo74cFpARxG9ke; 4:vUfVehk/SeKZ/nFNbsAkP9uXwfDayEFS0+EoxeVfsk0nCsfEGX1QcSgpCiv/ObEOpDkz4FyDdtZz0UUUUkR88KzOXoNOSMuwQLx3AdGXzhRdqv2A5/sk/itoaaU1Sumi6uX/ccFlnYTYYu/DTGxjaK/HP2D0IukcBfzPMqRhaBTcPbO93qcVSsnZdciReceIiJaII9jvccPAoQlLqv+CEhUhQHVHJx1PXYUYI7f45282vUt2oJsAejUMPU87nzxBRVjljxPmRqiR/gOrlhE7IB2MxRpmpTF4SB+KMzispNM= X-Exchange-Antispam-Report-Test: UriScan:(228905959029699); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(100000703101)(100105400095)(6041248)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123562025)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:SN1PR07MB2142; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:SN1PR07MB2142; X-Forefront-PRVS: 04569283F9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(6009001)(376002)(346002)(189002)(199003)(68736007)(54906003)(48376002)(316002)(551934003)(5003940100001)(5660300001)(16586007)(2906002)(97736004)(478600001)(33646002)(2950100002)(50226002)(50986999)(7736002)(72206003)(66066001)(8676002)(189998001)(8936002)(6116002)(76176999)(53936002)(3846002)(105586002)(5009440100003)(36756003)(106356001)(575784001)(6666003)(86362001)(50466002)(81166006)(4326008)(25786009)(305945005)(81156014)(107886003)(101416001)(6512007)(16526018)(6506006)(6486002)(47776003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR07MB2142; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR07MB2142; 23:jb42UZFJdByRMne0WCQXTyS5bzHlwWGe7S1Sx2MGo?= =?us-ascii?Q?dOLfm/+Yh6Xtok5FzbGm5ilyEcfFWoBhVNhHCQjR7Spy0/dSgr4JyIC863Z5?= =?us-ascii?Q?6SUD0xhNw5p8glBewIgW4UeDjX2f4n3WJViHfSmNUoherHekPSqMQ/UcP2II?= =?us-ascii?Q?JHxHmvB4FsLmgHVI4FY3rMBaXfdJeoquB4000XssEGMsf0VKZtA50+jX4j73?= =?us-ascii?Q?XQtRDxjZ6JZ2M6hw4K9yZAdcOMZRo4ofFOlmzGmPLPRaIM9/O1dPSpjScEYV?= =?us-ascii?Q?Of9UtpAu2EOjVEtMnF8ljalVHAaAgvKYiCtTVEfS1IoMgpg/jMuDnR7QYITd?= =?us-ascii?Q?YujDGeuTN4UgeUNGlGBZK7JyHTfLAvl4+wNbwh9PUfFyyDa4sSk59GKIAXrT?= =?us-ascii?Q?Emw4FSW2ku9cNRN02x9setD+44a+nMJb4BxYe6xdrSU4iEguq/D6lNgyYTBy?= =?us-ascii?Q?hniNiAy+M/EbfdsodkNLjIzo4xl30kZC8KRc2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7ysWWfDzcHRv8LBUllIMiDQjX6JZbY8t/YlFmQxkVRfzI9Jgrjpw8k7+6X9UEtymoT/Hcsy21nPqshksVbagnhiKlltnPMEWESzzE4NajqB4gfjFQbEGZSe7WLz7JBj4k+pNAElqQH1d7n1QVEh+DQYenKwS+f0gtzYsms+x7b4dW5s3s5E7DadQ==; 5:tL8TBx/KUxC2ANCbM1nIr/seVKq6FQLpTJS4EpEVYhh7moEsbzR/yfimGdV3pJrw1ylMpLY829bmDDG0udSX9gvcd+9irZJ8WxFIpGJGHxx81RRCqD1NI+W46IqlYwRdGBWJ+yiuowPSHkXe1bT7zA==; 24:ue/pSCfNmEqQONi+ezvO+lA5nZlIKaVkR0B2yCdjDpekKYHa8UupV27HmzVanXddLNAq6hlsVrXRKVObTBiH6rkHPVBhkKB3fmIBDjHAL0c=; 7:JgFfzuu2ejvPmqfRbHcatctXH0bX6xasvCgEClzaSkiW4nzdrIE0RdG5e5+zT54J3XOWmoZVrEwXX5a8iAukKBe4icexc5CtaFPlGj/Gcf9QdCJWalfX8sMN/3m3GYQWP5Oep0HqYvPG9CYljpABOg8JT/ahZCmIHYJZACUD+UA4PTpHGp/KdLKFH9XxkqBiX14UpCiS69FzOLeSgjWEbg111+Ir1HegYgNhhhoWolA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2017 06:27:40.9142 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB2142 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver needs to handle the flag I2C_M_RECV_LEN during receive to support SMBus emulation. Update receive logic to handle the case where the length is received as the first byte of a transaction. Also update the code to handle I2C_CLIENT_PEC, which is set when the client sends a packet error checking code byte. Signed-off-by: Jayachandran C Signed-off-by: Kamlakant Patel Reviewed-by: Mika Westerberg --- drivers/i2c/busses/i2c-xlp9xx.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c index f0bef2d..b970bf8 100644 --- a/drivers/i2c/busses/i2c-xlp9xx.c +++ b/drivers/i2c/busses/i2c-xlp9xx.c @@ -82,6 +82,8 @@ struct xlp9xx_i2c_dev { struct completion msg_complete; int irq; bool msg_read; + bool len_recv; + bool client_pec; u32 __iomem *base; u32 msg_buf_remaining; u32 msg_len; @@ -143,10 +145,25 @@ static void xlp9xx_i2c_fill_tx_fifo(struct xlp9xx_i2c_dev *priv) static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv) { u32 len, i; - u8 *buf = priv->msg_buf; + u8 rlen, *buf = priv->msg_buf; len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) & XLP9XX_I2C_FIFO_WCNT_MASK; + if (!len) + return; + if (priv->len_recv) { + /* read length byte */ + rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); + *buf++ = rlen; + len--; + if (priv->client_pec) + ++rlen; + /* update remaining bytes and message length */ + priv->msg_buf_remaining = rlen; + priv->msg_len = rlen + 1; + priv->len_recv = false; + } + len = min(priv->msg_buf_remaining, len); for (i = 0; i < len; i++, buf++) *buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO); @@ -230,7 +247,7 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg, int last_msg) { unsigned long timeleft; - u32 intr_mask, cmd, val; + u32 intr_mask, cmd, val, len; priv->msg_buf = msg->buf; priv->msg_buf_remaining = priv->msg_len = msg->len; @@ -263,9 +280,13 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg, else val &= ~XLP9XX_I2C_CTRL_ADDMODE; + priv->len_recv = msg->flags & I2C_M_RECV_LEN; + len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len; + priv->client_pec = msg->flags & I2C_CLIENT_PEC; + /* set data length to be transferred */ val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) | - (msg->len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); + (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT); xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val); /* fill fifo during tx */ @@ -312,6 +333,9 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg, return -ETIMEDOUT; } + /* update msg->len with actual received length */ + if (msg->flags & I2C_M_RECV_LEN) + msg->len = priv->msg_len; return 0; }