From nobody Tue Dec 16 16:37:11 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEB2CC28B2B for ; Fri, 19 Aug 2022 16:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351959AbiHSQSe (ORCPT ); Fri, 19 Aug 2022 12:18:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352006AbiHSQPD (ORCPT ); Fri, 19 Aug 2022 12:15:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62E857D7A6; Fri, 19 Aug 2022 08:58:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EF2FBB8281C; Fri, 19 Aug 2022 15:58:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 474F9C433C1; Fri, 19 Aug 2022 15:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924698; bh=5SQM0Vcn03jW8y+vL8vt3RbTBT1shOLYASI0Ea1720w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gUfkMbfw5lCP+6h4DQ7mZP1Z+ytcdeKSNXuAXWvCFVJBnbkEYFt3LTLxA2s9bzb82 W7Sg38KvcXIeMg+KIR+RnHTqccDLO7FkI01qEOR4Xgs/ZScM4ZOFNckV8XTA1xHks3 jJhEbNzHqyy04PpS0wrqr2tR4GsC49M0857qzMNs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Shubhrajyoti Datta , Wolfram Sang , Sasha Levin Subject: [PATCH 5.10 246/545] i2c: cadence: Support PEC for SMBus block read Date: Fri, 19 Aug 2022 17:40:16 +0200 Message-Id: <20220819153840.354957807@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lars-Peter Clausen [ Upstream commit 9fdf6d97f03035ad5298e2d1635036c74c2090ed ] SMBus packet error checking (PEC) is implemented by appending one additional byte of checksum data at the end of the message. This provides additional protection and allows to detect data corruption on the I2C bus. SMBus block reads support variable length reads. The first byte in the read message is the number of available data bytes. The combination of PEC and block read is currently not supported by the Cadence I2C driver. * When PEC is enabled the maximum transfer length for block reads increases from 33 to 34 bytes. * The I2C core smbus emulation layer relies on the driver updating the `i2c_msg` `len` field with the number of received bytes. The updated length is used when checking the PEC. Add support to the Cadence I2C driver for handling SMBus block reads with PEC. To determine the maximum transfer length uses the initial `len` value of the `i2c_msg`. When PEC is enabled this will be 2, when it is disabled it will be 1. Once a read transfer is done also increment the `len` field by the amount of received data bytes. This change has been tested with a UCM90320 PMBus power monitor, which requires block reads to access certain data fields, but also has PEC enabled by default. Fixes: df8eb5691c48 ("i2c: Add driver for Cadence I2C controller") Signed-off-by: Lars-Peter Clausen Tested-by: Shubhrajyoti Datta Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-cadence.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cade= nce.c index 0abce487ead7..50928216b3f2 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -566,8 +566,13 @@ static void cdns_i2c_mrecv(struct cdns_i2c *id) ctrl_reg =3D cdns_i2c_readreg(CDNS_I2C_CR_OFFSET); ctrl_reg |=3D CDNS_I2C_CR_RW | CDNS_I2C_CR_CLR_FIFO; =20 + /* + * Receive up to I2C_SMBUS_BLOCK_MAX data bytes, plus one message length + * byte, plus one checksum byte if PEC is enabled. p_msg->len will be 2 if + * PEC is enabled, otherwise 1. + */ if (id->p_msg->flags & I2C_M_RECV_LEN) - id->recv_count =3D I2C_SMBUS_BLOCK_MAX + 1; + id->recv_count =3D I2C_SMBUS_BLOCK_MAX + id->p_msg->len; =20 id->curr_recv_count =3D id->recv_count; =20 @@ -753,6 +758,9 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, st= ruct i2c_msg *msg, if (id->err_status & CDNS_I2C_IXR_ARB_LOST) return -EAGAIN; =20 + if (msg->flags & I2C_M_RECV_LEN) + msg->len +=3D min_t(unsigned int, msg->buf[0], I2C_SMBUS_BLOCK_MAX); + return 0; } =20 --=20 2.35.1