Message ID | 20231002084211.1108940-1-alain.volmat@foss.st.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1280888vqb; Mon, 2 Oct 2023 01:44:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4xy8tJCj+H2esvjB/DVi6SsloFrVBTNeK2IESlKH5xE06Fq3DrMM76tISylR6j7niWfYn X-Received: by 2002:a05:6a20:158e:b0:159:b4ba:a5bf with SMTP id h14-20020a056a20158e00b00159b4baa5bfmr10625162pzj.13.1696236288668; Mon, 02 Oct 2023 01:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696236288; cv=none; d=google.com; s=arc-20160816; b=PTTQkZw2bb6MLxsJ9yISTtET0cmh44QSjuXqMU0lw03XlTgAiDiPFDTH/VtC6ePGjC pBAHl25c/vjAKUObD0gdK5dMQ+tH67hl6FrKoOYQILNdlghyw54U/XNM0wBpu+LsxkFw MfqALKsZatHcxAlwNnDqH4NnlYA+ZiW2uvab5tikSHqqQxCsJDvCWmIE6ARQ4ioJP6dc 1g4v+X9rXon2cniXvdAhYofiyNxp0BDIDxEoQRwfkRrRVIE7haz9UYDwipvKuFifqrFr tD8RjdVftQh6gy03XxO0c6IdAmQsEVzvjkXQROgMZFr+UPyjRppMDJjIY58M39lNAbYD SmYA== 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.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id r1-20020a170902c60100b001c6223663b2si16325735plr.339.2023.10.02.01.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 01:44:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; 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.35 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 groat.vger.email (Postfix) with ESMTP id 717FA806D7D3; Mon, 2 Oct 2023 01:43:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229981AbjJBImr (ORCPT <rfc822;pwkd43@gmail.com> + 17 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <alain.volmat@foss.st.com> To: Pierre-Yves MORDRET <pierre-yves.mordret@foss.st.com>, Alain Volmat <alain.volmat@foss.st.com>, Andi Shyti <andi.shyti@kernel.org>, "Maxime Coquelin" <mcoquelin.stm32@gmail.com>, Alexandre Torgue <alexandre.torgue@foss.st.com>, M'boumba Cedric Madianga <cedric.madianga@gmail.com>, Wolfram Sang <wsa@kernel.org> CC: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>, <linux-i2c@vger.kernel.org>, <linux-stm32@st-md-mailman.stormreply.com>, <linux-arm-kernel@lists.infradead.org>, <linux-kernel@vger.kernel.org> 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=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 02 Oct 2023 01:43:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778632662489770872 X-GMAIL-MSGID: 1778632662489770872 |
Series |
i2c: stm32f7: Fix PEC handling in case of SMBUS transfers
|
|
Commit Message
Alain Volmat
Oct. 2, 2023, 8:42 a.m. UTC
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 <alain.volmat@foss.st.com>
---
drivers/i2c/busses/i2c-stm32f7.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
Comments
Hi Alain, Sounds good to me Reviewed-by: Pierre-Yves MORDRET <pierre-yves.mordret@foss.st.com> Regards On 10/2/23 10:42, Alain Volmat wrote: > 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 <alain.volmat@foss.st.com> > --- > 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);
Hi Alain, On Mon, Oct 02, 2023 at 10:42:10AM +0200, Alain Volmat wrote: > 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. What is this patch fixing? Can you please point this detail in the documentation, I haven't found it[*] > Fixes: 9e48155f6bfe ("i2c: i2c-stm32f7: Add initial SMBus protocols support") > > Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> please, don't leave blank lines between tags. Thanks, Andi [*] Hope this is the correct one: https://www.st.com/resource/en/reference_manual/rm0385-stm32f75xxx-and-stm32f74xxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf > --- > 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 >
Hi Andi, Thanks for the review. On Tue, Oct 03, 2023 at 07:42:46PM +0200, Andi Shyti wrote: > Hi Alain, > > On Mon, Oct 02, 2023 at 10:42:10AM +0200, Alain Volmat wrote: > > 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. > > What is this patch fixing? > > Can you please point this detail in the documentation, I haven't > found it[*] This is about the handling of the PECBYTE bit of the I2C_CR2 register (cf page 1010 of the spec you pointed). There were no issue in case of performing SMBUS write (with PEC), however read was not working. PECBYTE was set from the very beginning of the transaction, but since SMBUS read is first made of a write transfer, followed by a read transfer, the PECBYTE was appended to the end of the write transfer (instead of the read transfer), leading to lose of the last byte of the write transfer. (in addition to the fact that the PEC byte should NOT be placed at the end of the write transfer). (cf Figure 30 of SMBUS specification [1]). I could add more information within the commit log if you prefer. [1] http://www.smbus.org/specs/SMBus_3_2_20220112.pdf > > > Fixes: 9e48155f6bfe ("i2c: i2c-stm32f7: Add initial SMBus protocols support") > > > > Signed-off-by: Alain Volmat <alain.volmat@foss.st.com> > > please, don't leave blank lines between tags. Ok, will remove this blank line within a v2. Thanks, Alain > > Thanks, > Andi > > [*] Hope this is the correct one: > https://www.st.com/resource/en/reference_manual/rm0385-stm32f75xxx-and-stm32f74xxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf > > > --- > > 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 > >
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);