Skip to content

Commit 406cc9c

Browse files
Thomas Koppmarckleinebudde
authored andcommitted
can: mcp251xfd: mcp251xfd_regmap_crc_read(): improve workaround handling for mcp2517fd
The mcp251xfd compatible chips have an erratum ([1], [2]), where the received CRC doesn't match the calculated CRC. In commit c7eb923 ("can: mcp251xfd: mcp251xfd_regmap_crc_read(): work around broken CRC on TBC register") the following workaround was implementierend. - If a CRC read error on the TBC register is detected and the first byte is 0x00 or 0x80, the most significant bit of the first byte is flipped and the CRC is calculated again. - If the CRC now matches, the _original_ data is passed to the reader. For now we assume transferred data was OK. Measurements on the mcp2517fd show that the workaround is applicable not only of the lowest byte is 0x00 or 0x80, but also if 3 least significant bits are set. Update check on 1st data byte and workaround description accordingly. [1] mcp2517fd: DS80000792C: "Incorrect CRC for certain READ_CRC commands" [2] mcp2518fd: DS80000789C: "Incorrect CRC for certain READ_CRC commands" Link: https://lore.kernel.org/all/DM4PR11MB53901D49578FE265B239E55AFB7C9@DM4PR11MB5390.namprd11.prod.outlook.com Fixes: c7eb923 ("can: mcp251xfd: mcp251xfd_regmap_crc_read(): work around broken CRC on TBC register") Cc: [email protected] Reported-by: Pavel Modilaynen <[email protected]> Signed-off-by: Thomas Kopp <[email protected]> [mkl: split into 2 patches, update patch description and documentation] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent b3b6df2 commit 406cc9c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/net/can/spi/mcp251xfd/mcp251xfd-regmap.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,12 @@ mcp251xfd_regmap_crc_read(void *context,
334334
* register. It increments once per SYS clock tick,
335335
* which is 20 or 40 MHz.
336336
*
337-
* Observation shows that if the lowest byte (which is
338-
* transferred first on the SPI bus) of that register
339-
* is 0x00 or 0x80 the calculated CRC doesn't always
340-
* match the transferred one.
337+
* Observation on the mcp2518fd shows that if the
338+
* lowest byte (which is transferred first on the SPI
339+
* bus) of that register is 0x00 or 0x80 the
340+
* calculated CRC doesn't always match the transferred
341+
* one. On the mcp2517fd this problem is not limited
342+
* to the first byte being 0x00 or 0x80.
341343
*
342344
* If the highest bit in the lowest byte is flipped
343345
* the transferred CRC matches the calculated one. We
@@ -346,7 +348,8 @@ mcp251xfd_regmap_crc_read(void *context,
346348
* correct.
347349
*/
348350
if (reg == MCP251XFD_REG_TBC &&
349-
(buf_rx->data[0] == 0x0 || buf_rx->data[0] == 0x80)) {
351+
((buf_rx->data[0] & 0xf8) == 0x0 ||
352+
(buf_rx->data[0] & 0xf8) == 0x80)) {
350353
/* Flip highest bit in lowest byte of le32 */
351354
buf_rx->data[0] ^= 0x80;
352355

0 commit comments

Comments
 (0)