Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1476335rdb; Mon, 2 Oct 2023 10:35:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFeE33TaXl/YWyYwHuGYkI613jqzeE8SSwv9k1qVijsKtnnkBpzvDlLvibLfuurZ2s8Beg X-Received: by 2002:a17:90b:fc7:b0:274:735c:e2d3 with SMTP id gd7-20020a17090b0fc700b00274735ce2d3mr10166938pjb.8.1696268111107; Mon, 02 Oct 2023 10:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696268111; cv=none; d=google.com; s=arc-20160816; b=M59Xmeqt5PmpWnKTx16M9EicfPa+WbIxqjT90PvFcDnP8ZySkZDWwKPVv48ouFv+/L PD/yd0ILY8MU+EY1Gcsa1D7uQg2cxioc5xrcKkyT5qFD4Nl/GLg2vcmug1YERLLtBcQh E+BEWbIlVeJFUi8R/XdCxDetcnky2bI3BtzvcUsRRNV76IMtsMkVQ0gNhAY/saFZwp9B Qg1MhUW/BiIJyMwLmGjRsl7eKeukEP65hFScocUyzoJwNVRzslC5EdtTzOljXevM+uyf +9mbOclsu8jcN5hTz6of8tuBUJsOOTtGuodUTZiWztRB87iSnjyzTaOfBGTbEY6uaYoU 0Qtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ST/+Jyc5mLphX8HujPhPASxpDHMbj5k1JIST9D3Y+J0=; fh=HrP3yWlgIBe+CU3Vl0qOE4Me+RgFIDeZQyM6K800zkI=; b=Ygx3T210GLWQw3JmYpqMxtpDkWYkizzhngMVw1hsJZgED0uD+RushlF2aV69FY0b9K jZONVv5+esxeumwInSj2mhTsI7bGIkO7XWJnGG1Se0n6uv1OEr3DnibeNEj0rEuJkwcV JdIcoedh8zaepFM4E7X0031f/J9zG70Xit//bMKgPg+9iwojBGw1jGzsjyKXKinPCTTG fTZO/bzcO7FqhF//LSYwl31409CzAIRWNLQp48NFzqZPj6S47gkAooAgnH/T0H9NtodA J6nSf1gn4VW37lgMdsYOT2n1wEK5Ign4JTUS9yXP4OvWm7TAL0Sv9CesFN1Ltc8ITc7g 5KLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=e7MCGpg1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a1-20020a17090a854100b0026b698fdda6si7530172pjw.98.2023.10.02.10.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 10:35:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=e7MCGpg1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id BBA5A80F4E16; Mon, 2 Oct 2023 01:42:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235864AbjJBImr (ORCPT + 99 others); Mon, 2 Oct 2023 04:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235856AbjJBImq (ORCPT ); Mon, 2 Oct 2023 04:42:46 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11062A6; Mon, 2 Oct 2023 01:42:42 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 02 Oct 2023 01:42:53 -0700 (PDT) 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 --- 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); -- 2.25.1