Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp358252lqd; Wed, 24 Apr 2024 04:52:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/uEz7IpNM0Sw0uyHp3Dqyxxp5+Rzr1ks0kBXp6WXAr0nowx4lQzC8Baz4nLLBKEtQKoIUNB1ZgtzPfk/Sly3AI7rphOFz9Er5l8NTCw== X-Google-Smtp-Source: AGHT+IHjItGw6V3f9f6jaxi0+tUlCxtIOfvEn6TPHX7q7ijCiNd6s8f7w4qPW0wcjQYhyCt2sJGs X-Received: by 2002:a50:d6d2:0:b0:572:2264:76ec with SMTP id l18-20020a50d6d2000000b00572226476ecmr1651189edj.2.1713959529927; Wed, 24 Apr 2024 04:52:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713959529; cv=pass; d=google.com; s=arc-20160816; b=WsTz60cTJTpGLtNN7UKEe5zGVazWJDVFlWpdMKPaAGaQpAX8V0v+/lK5I/vHaqICb1 mSgV/rilKJt4tA1XMrjlcrjLZDE2rXVwnPinep8dr7s3NOnKEsYCCW135dqacRc8Qsse ErfmLVn36oeDjpoEudy5OYPi1uCpD9j58H5CXdyQoY0dBsEdNQMCDBABvQ9ZWl5ZHe1W 8X5r5+jUwOks074ysIiKNJFRNGk5KQ2ADho7GyAsWWUV1THMg3k22df7PF6LX6tyS57Z 9Go/w+ArZs28uhFJPOlVxLepF6f37fH4SU47/AUIfDCnwI05yzuNma5YpTXhgWKIyxF0 FY3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=xOm5T/4jY89PI4SRr+AkkxFY12h8SZd9qq4A5/+qf7Q=; fh=t/Rlprtb5kVZgOj4jZz3MBiSXVd5jcjJfSKVyh9eDy8=; b=d/RT84aULN/TT6hLjseSZTQBTXLl51YOztVoIHgph+i7935H/eYIvZTM42cghLp5pa U1ov0HpbhLk+kmdJ34CZZwrPP+0KhZJ0VGVy8Eo8Gk7kNQLxj/VjGy6yr+KQMOgBQACw LLRdc0cTWg/ND+PHpXp3aIQ0OmSIhf6MOgl732s4+pYX4xaOuSwRtizPxyVddzCGlm3B YbAKbWVXmydhqhUEgGDS8mJb/JbH2QbJYITpN9pA4RVP+qRUa9Xk+HMuuNw926frbdPf RMB3NhSLdH24fBiinEx5vV2vJlByKRIZc4TTgfOvgo0wAeCA4aeUSDh4VwmlRszI4XWx d1WQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-156819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156819-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i19-20020a50fc13000000b0056c25c52559si8668750edr.77.2024.04.24.04.52.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 04:52:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-156819-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156819-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 336171F2444D for ; Wed, 24 Apr 2024 11:52:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BCFEB15AACF; Wed, 24 Apr 2024 11:52:02 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9062315A4AF for ; Wed, 24 Apr 2024 11:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713959522; cv=none; b=kF9jewgRVlmvsYLVz3wt56isSuU05JPli4xmtRe1Qec/YGRcEJkBh8pZKBguNhiezb6hCs9lb2kVahMo23nX1YNJCXHUfLMHkJjl5joQOLrn/Jadt3HGMXffpZdOciwxbiNJlJ2+BfhY1auXVdcvYxT8RYUjYuUaZfN98QVX9sg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713959522; c=relaxed/simple; bh=4LHwUL/GiaGN8UBv9G2UKP4Pgmi5yTLpk/Z5kdqHPnU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AaO6nIsNHEhASw+WG0Gs34EezPY3mqsm2adls4X8J52qDSlWlg1g+Gi6ftByxCQVCnulMAiugam8uecw/S4GndZ8nXazay3zDWRSVyShow1mTOQJGPVNweNdJ8KqxD+ucKuMKeR3RWshKURgKVD0eABUw6JvULTBzk/+FjegvXI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rzbA4-0000pN-S2; Wed, 24 Apr 2024 13:51:40 +0200 Received: from [2a0a:edc0:0:b01:1d::7b] (helo=bjornoya.blackshift.org) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rzbA2-00E4RF-Q0; Wed, 24 Apr 2024 13:51:38 +0200 Received: from pengutronix.de (unknown [172.20.34.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 5D2892BEDF1; Wed, 24 Apr 2024 11:51:38 +0000 (UTC) Date: Wed, 24 Apr 2024 13:51:37 +0200 From: Marc Kleine-Budde To: Gregor Herburger Cc: Manivannan Sadhasivam , Thomas Kopp , Vincent Mailhol , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux@ew.tq-group.com, alexander.stein@ew.tq-group.com Subject: Re: [PATCH 2/4] can: mcp251xfd: mcp251xfd_regmap_crc_write(): workaround for errata 5 Message-ID: <20240424-worm-of-massive-triumph-2eaf27-mkl@pengutronix.de> References: <20240417-mcp251xfd-gpio-feature-v1-0-bc0c61fd0c80@ew.tq-group.com> <20240417-mcp251xfd-gpio-feature-v1-2-bc0c61fd0c80@ew.tq-group.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="xye5fqb7pzx6nlyi" Content-Disposition: inline In-Reply-To: <20240417-mcp251xfd-gpio-feature-v1-2-bc0c61fd0c80@ew.tq-group.com> X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org --xye5fqb7pzx6nlyi Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 17.04.2024 15:43:55, Gregor Herburger wrote: > According to Errata DS80000789E 5 writing IOCON register using one SPI > write command clears LAT0/LAT1. >=20 > Errata Fix/Work Around suggests to write registers with single byte write > instructions. However, it seems that every write to the second byte > causes the overrite of LAT0/LAT1. This change doesn't use single byte write instructions. > Never write byte 2 of IOCON register to avoid clearing of LAT0/LAT1. I discovered that erratum, it's described in mcp251xfd_chip_rx_int_enable(): /* Configure GPIOs: * - PIN0: GPIO Input * - PIN1: GPIO Input/RX Interrupt * * PIN1 must be Input, otherwise there is a glitch on the * rx-INT line. It happens between setting the PIN as output * (in the first byte of the SPI transfer) and configuring the * PIN as interrupt (in the last byte of the SPI transfer). */ The problem is that the SPI writes 1 byte at a time, starting at the lower address. The chip updates the GPIO pin's status after each written byte. This may leads to a glitch if you have an external pull up. The power on default auf the chip is GPIO/input, the GPIO line is not driven by the chip and with the external pull up this will result in a high level. If you configure the GPIO as an output/high, the driver first writes bits 0...7, which results in the GPIO line being configured as an output; the subsequent bits 8...15 configure the level of the GPIO line. This change doesn't take care of this. I'm not sure, if it's better to have 2 dedicated writes to IOCON in the driver or try to hide it here in the regmap. > Signed-off-by: Gregor Herburger > --- > drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c | 35 ++++++++++++++++++= +++++- > 1 file changed, 34 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c b/drivers/n= et/can/spi/mcp251xfd/mcp251xfd-regmap.c > index 92b7bc7f14b9..ab4e372baffb 100644 > --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c > +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c > @@ -229,14 +229,47 @@ mcp251xfd_regmap_crc_gather_write(void *context, > return spi_sync_transfer(spi, xfer, ARRAY_SIZE(xfer)); > } > =20 > +static int > +mcp251xfd_regmap_crc_write_iocon(void *context, const void *data, size_t= count) > +{ > + const size_t data_offset =3D sizeof(__be16) + > + mcp251xfd_regmap_crc.pad_bits / BITS_PER_BYTE; > + u16 reg =3D *(u16 *)data; > + > + /* Never write to bits 16..23 of IOCON register to avoid clearing of LA= T0/LAT1 > + * > + * According to Errata DS80000789E 5 writing IOCON register using one > + * SPI write command clears LAT0/LAT1. > + * > + * Errata Fix/Work Around suggests to write registers with single byte > + * write instructions. However, it seems that the byte at 0xe06(IOCON[2= 3:16]) > + * is for read-only access and writing to it causes the cleraing of LAT= 0/LAT1. > + */ > + > + /* Write IOCON[15:0] */ > + mcp251xfd_regmap_crc_gather_write(context, ®, 1, > + data + data_offset, 2); You write 15:0 in 1 go here. > + reg +=3D 3; > + /* Write IOCON[31:24] */ > + mcp251xfd_regmap_crc_gather_write(context, ®, 1, > + data + data_offset + 3, 1); > + > + return 0; > +} > + > static int > mcp251xfd_regmap_crc_write(void *context, > const void *data, size_t count) > { > const size_t data_offset =3D sizeof(__be16) + > mcp251xfd_regmap_crc.pad_bits / BITS_PER_BYTE; > + u16 reg =3D *(u16 *)data; > =20 > - return mcp251xfd_regmap_crc_gather_write(context, > + if (reg =3D=3D MCP251XFD_REG_IOCON) > + return mcp251xfd_regmap_crc_write_iocon(context, > + data, count); > + else > + return mcp251xfd_regmap_crc_gather_write(context, > data, data_offset, > data + data_offset, > count - data_offset); Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung N=C3=BCrnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 | --xye5fqb7pzx6nlyi Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEUEC6huC2BN0pvD5fKDiiPnotvG8FAmYo8kYACgkQKDiiPnot vG9t/gf9H+/WdOg2eiOSM5KODtdgigCiOuzFEj5izdhPZ3+561zJqSlT/jAnq6uk 1hsJrhI72Un3frNW977QH36dWk2xkUb06ByGaTMcGrN5NrKLjhCRQSCVWxcSLECe lAFQiiCrJC+zqIxST0daQaOxqtXlM5bNynWO21OwLgtkt1sFd3TWvLjp6hdFjn7R uSAzYi7CkDyKU0YoCTUgpJSV+di0tbxKO99Q/jl6OKY6X7ceullmFVKa2QhCZ7Hc gQpWwoYBEJ0zuCbkA9sA2+eTOtS6lbcfssloNpfxTnOwV6zkVVC/GVIlN9J0HGuj sWTg+tmk5kUwdVFwNTBfKNFBTYr+BA== =X001 -----END PGP SIGNATURE----- --xye5fqb7pzx6nlyi--