• Hugo Villeneuve's avatar
    serial: sc16is7xx: fix unconditional activation of THRI interrupt · 99157530
    Hugo Villeneuve authored
    Commit cc4c1d05 ("sc16is7xx: Properly resume TX after stop") changed
    behavior to unconditionnaly set the THRI interrupt in sc16is7xx_tx_proc().
    
    For example when sending a 65 bytes message, and assuming the Tx FIFO is
    initially empty, sc16is7xx_handle_tx() will write the first 64 bytes of the
    message to the FIFO and sc16is7xx_tx_proc() will then activate THRI. When
    the THRI IRQ is fired, the driver will write the remaining byte of the
    message to the FIFO, and disable THRI by calling sc16is7xx_stop_tx().
    
    When sending a 2 bytes message, sc16is7xx_handle_tx() will write the 2
    bytes of the message to the FIFO and call sc16is7xx_stop_tx(), disabling
    THRI. After sc16is7xx_handle_tx() exits, control returns to
    sc16is7xx_tx_proc() which will unconditionally set THRI. When the THRI IRQ
    is fired, the driver simply acknowledges the interrupt and does nothing
    more, since all the data has already been written to the FIFO. This results
    in 2 register writes and 4 register reads all for nothing and taking
    precious cycles from the I2C/SPI bus.
    
    Fix this by enabling the THRI interrupt only when we fill the Tx FIFO to
    its maximum capacity and there are remaining bytes to send in the message.
    
    Fixes: cc4c1d05 ("sc16is7xx: Properly resume TX after stop")
    Cc:  <stable@vger.kernel.org>
    Signed-off-by: default avatarHugo Villeneuve <hvilleneuve@dimonoff.com>
    Link: https://lore.kernel.org/r/20231211171353.2901416-7-hugo@hugovil.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    99157530
sc16is7xx.c 53.5 KB