Skip to content

Commit 3c089d7

Browse files
andy-shevgregkh
authored andcommitted
serial: 8250_exar: Use BIT() in exar_ee_read()
Use BIT() in exar_ee_read() like other functions do. While at it, explain the EEPROM type and the dummy bit requirement. Signed-off-by: Andy Shevchenko <[email protected]> Tested-by: Parker Newman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d72c301 commit 3c089d7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

drivers/tty/serial/8250/8250_exar.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ static inline u8 exar_ee_read_bit(struct exar8250 *priv)
324324
* @ee_addr: Offset of EEPROM to read word from
325325
*
326326
* Read a single 16bit word from an Exar UART's EEPROM.
327+
* The type of the EEPROM is AT93C46D.
327328
*
328329
* Return: EEPROM word
329330
*/
@@ -340,13 +341,13 @@ static u16 exar_ee_read(struct exar8250 *priv, u8 ee_addr)
340341
exar_ee_write_bit(priv, 0);
341342

342343
// Send address to read from
343-
for (i = 1 << (UART_EXAR_REGB_EE_ADDR_SIZE - 1); i; i >>= 1)
344-
exar_ee_write_bit(priv, (ee_addr & i));
344+
for (i = UART_EXAR_REGB_EE_ADDR_SIZE - 1; i >= 0; i--)
345+
exar_ee_write_bit(priv, ee_addr & BIT(i));
345346

346-
// Read data 1 bit at a time
347-
for (i = 0; i <= UART_EXAR_REGB_EE_DATA_SIZE; i++) {
348-
data <<= 1;
349-
data |= exar_ee_read_bit(priv);
347+
// Read data 1 bit at a time starting with a dummy bit
348+
for (i = UART_EXAR_REGB_EE_DATA_SIZE; i >= 0; i--) {
349+
if (exar_ee_read_bit(priv))
350+
data |= BIT(i);
350351
}
351352

352353
exar_ee_deselect(priv);

0 commit comments

Comments
 (0)