Re: [PATCH v1 11/13] serial: 8250_exar: Use BIT() in exar_ee_read()

From: Andy Shevchenko
Date: Thu May 02 2024 - 13:20:15 EST


On Thu, May 02, 2024 at 07:08:21PM +0300, Ilpo Järvinen wrote:
> On Thu, 2 May 2024, Andy Shevchenko wrote:

..

> > // Send address to read from
> > - for (i = 1 << (UART_EXAR_REGB_EE_ADDR_SIZE - 1); i; i >>= 1)
> > - exar_ee_write_bit(priv, (ee_addr & i));
> > + for (i = UART_EXAR_REGB_EE_ADDR_SIZE - 1; i >= 0; i--)
> > + exar_ee_write_bit(priv, ee_addr & BIT(i));
> >
> > // Read data 1 bit at a time
> > for (i = 0; i <= UART_EXAR_REGB_EE_DATA_SIZE; i++) {
> > - data <<= 1;
> > - data |= exar_ee_read_bit(priv);
> > + if (exar_ee_read_bit(priv))
> > + data |= BIT(i);
>
> Does this end up reversing the order of bits? In the original, data was left
> shifted which moved the existing bits and added the lsb but the replacement
> adds highest bit on each iteration?

Oh, seems a good catch!

I was also wondering, but missed this somehow. Seems the EEPROM is in BE mode,
so two loops has to be aligned.

--
With Best Regards,
Andy Shevchenko