From patchwork Mon Oct 2 08:42:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alain Volmat X-Patchwork-Id: 13405642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 561E4E784A4 for ; Mon, 2 Oct 2023 08:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=y2y42NHc3sUBUkAgafoOlSen2kiT/tm+BMbS9ZsJghY=; b=4Ug+N84iRaYqKV g9ac2jc3uiu/cwaDKow6u1ycXVYpIN+Jm8OanMHg1pwCgnQDtQ2o/JlGOAO1hLJZoHxH21gSbfLGa bH9wUH67B4VQI7Sn0VuofykfOXoo4qHGORQ26TxHTDvyXAtfqwyALwGZkoMR3G/TPhjUU+TUtb/DY ajBXWgifl67i4089+67NYtFDu/PTWBdrgInhtaO+J9mW9o6yOZZPWGple85ytcrW+YfePf7p+HHO5 4Amvq52SvhFYNZx8Yj7PKjaAjbi3Q6vTW3xLLhQrKJTGpPp6laGH3QfxRix6coSktRsMLIeTU/iCa rdkg7BZMktq9xFefOIzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qnEVl-00C9AD-2g; Mon, 02 Oct 2023 08:42:41 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qnEVh-00C99p-24 for linux-arm-kernel@lists.infradead.org; Mon, 02 Oct 2023 08:42:40 +0000 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3928U3U6019923; Mon, 2 Oct 2023 10:42:16 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=selector1; bh=ST/+Jyc 5mLphX8HujPhPASxpDHMbj5k1JIST9D3Y+J0=; b=e7MCGpg1xbM8W063320H0Km +c9mxJVe+yYjekAoCqVa/0yo1GP22pICas5bVIRYpLY4/C35a82Qs03levH3k9CB Ki3aAftI1Y7RohsjoWfq+a4RvYj0u2YXi3/fQkqQVC6YBXSDS8M99KRRHetJ3SKV OF4iTu1TyYklmUBcAvSKVhyxyMip23v/JkUgjUgavTC6U2+GEuiI++xCwW8+ZA5R wHdenECB6AbDg+PdDtnF3gZxKlyR0OH+gMx+y4Xu2WLcbQk4dqaImnupObBIIVWR teraMW0BxZ2QH51iIvHyS81UXe/aMmK1f+oJ3KFJBV+SLvJgNLRu5X42FFxSC4w= = Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3te8t4pbnw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 02 Oct 2023 10:42:16 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2196A100059; Mon, 2 Oct 2023 10:42:16 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 196D420F55A; Mon, 2 Oct 2023 10:42:16 +0200 (CEST) Received: from localhost (10.129.178.213) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 2 Oct 2023 10:42:15 +0200 From: Alain Volmat To: Pierre-Yves MORDRET , Alain Volmat , Andi Shyti , "Maxime Coquelin" , Alexandre Torgue , M'boumba Cedric Madianga , Wolfram Sang CC: Pierre-Yves MORDRET , , , , Subject: [PATCH] i2c: stm32f7: Fix PEC handling in case of SMBUS transfers Date: Mon, 2 Oct 2023 10:42:10 +0200 Message-ID: <20231002084211.1108940-1-alain.volmat@foss.st.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.129.178.213] X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-02_03,2023-09-28_03,2023-05-22_02 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231002_014238_215868_9DADB0EF X-CRM114-Status: GOOD ( 14.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The PECBYTE bit allows to generate (in case of write) or compute/compare the PEC byte (in case of read). In case of reading a value (performed by first sending a write command, then followed by a read command) the PECBYTE should only be set before starting the read command and not before the first write command. Fixes: 9e48155f6bfe ("i2c: i2c-stm32f7: Add initial SMBus protocols support") Signed-off-by: Alain Volmat Reviewed-by: Pierre-Yves MORDRET --- drivers/i2c/busses/i2c-stm32f7.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c index 579b30581725..0d3c9a041b56 100644 --- a/drivers/i2c/busses/i2c-stm32f7.c +++ b/drivers/i2c/busses/i2c-stm32f7.c @@ -1059,9 +1059,10 @@ static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev, /* Configure PEC */ if ((flags & I2C_CLIENT_PEC) && f7_msg->size != I2C_SMBUS_QUICK) { cr1 |= STM32F7_I2C_CR1_PECEN; - cr2 |= STM32F7_I2C_CR2_PECBYTE; - if (!f7_msg->read_write) + if (!f7_msg->read_write) { + cr2 |= STM32F7_I2C_CR2_PECBYTE; f7_msg->count++; + } } else { cr1 &= ~STM32F7_I2C_CR1_PECEN; cr2 &= ~STM32F7_I2C_CR2_PECBYTE; @@ -1149,8 +1150,10 @@ static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev) f7_msg->stop = true; /* Add one byte for PEC if needed */ - if (cr1 & STM32F7_I2C_CR1_PECEN) + if (cr1 & STM32F7_I2C_CR1_PECEN) { + cr2 |= STM32F7_I2C_CR2_PECBYTE; f7_msg->count++; + } /* Set number of bytes to be transferred */ cr2 &= ~(STM32F7_I2C_CR2_NBYTES_MASK);