On Thu, 2026-11-12 at 14:17 +0800, Yidi Lin wrote:
> mtk_dp_aux_wait_for_completion() returns for a read as soon as the RX
> FIFO write pointer is non-zero, i.e. when the first byte of the reply
> has arrived. The rest of the reply is still on the AUX line, so
> mtk_dp_aux_read_rx_fifo() sleeps 500-1000 us before reading each byte
> of an I2C-over-AUX reply and 100-200 us before each byte of a native
> reply. The FIFO is drained this way even for DEFER replies, which carry
> no data.
> 
> A 16-byte EDID read therefore takes about 16 ms, although the reply is
> complete within about 300 us of the request.
> 
> Wait for the AUX receive-complete (or 400 us timeout) interrupt status
> instead, which the write path already relies on, and drain the RX FIFO
> without delays. Poll every 20 us instead of every 100-500 us.
> 
> Reading the 256-byte EDID through the DP AUX DDC adapter drops from 266
> to 6.5 ms on an MT8189 Chromebook, and from 547 to 23 ms on an MT8196
> Chromebook whose panel defers every 16-byte read once. A 16-byte DPCD
> read drops from about 4.7 to 0.5 ms.
> 
> Signed-off-by: Yidi Lin <[email protected]>
> ---
>  drivers/gpu/drm/mediatek/mtk_dp.c | 64 ++++++++++++-------------------
>  1 file changed, 25 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c 
> b/drivers/gpu/drm/mediatek/mtk_dp.c
> index f656b85b84212..b2f7f42cbe715 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dp.c
> @@ -45,7 +45,8 @@
>  #define MTK_DP_4P1T 4
>  #define MTK_DP_HDE 2
>  #define MTK_DP_PIX_PER_ADDR 2
> -#define MTK_DP_AUX_WAIT_REPLY_COUNT 20
> +#define MTK_DP_AUX_POLL_US 20
> +#define MTK_DP_AUX_TIMEOUT_US 10000
>  #define MTK_DP_TBC_BUF_READ_START_ADDR 0x8
>  #define MTK_DP_TRAIN_VOLTAGE_LEVEL_RETRY 5
>  #define MTK_DP_TRAIN_DOWNSCALE_RETRY 10
> @@ -825,20 +826,18 @@ static void mtk_dp_aux_fill_write_fifo(struct mtk_dp 
> *mtk_dp, u8 *buf,
>  }
>  
>  static void mtk_dp_aux_read_rx_fifo(struct mtk_dp *mtk_dp, u8 *buf,
> -                                 size_t length, int read_delay)
> +                                 size_t length)
>  {
>       int read_pos;
>  
>       mtk_dp_update_bits(mtk_dp, MTK_DP_AUX_P0_3620,
>                          0, AUX_RD_MODE_AUX_TX_P0_MASK);
>  
> +     /* The complete reply is in the RX FIFO, so read it without delays. */
>       for (read_pos = 0; read_pos < length; read_pos++) {
>               mtk_dp_update_bits(mtk_dp, MTK_DP_AUX_P0_3620,
>                                  AUX_RX_FIFO_READ_PULSE_TX_P0,
>                                  AUX_RX_FIFO_READ_PULSE_TX_P0);
> -
> -             /* Hardware needs time to update the data */

We assume the delay is just for AUX_RX_AUX_RECV_COMPLETE_IRQ_AUX_TX_P0 and no 
the other hardware delay.
It seems this assumption is right, so

Reviewed-by: CK Hu <[email protected]>

> -             usleep_range(read_delay, read_delay * 2);
>               buf[read_pos] = (u8)(mtk_dp_read(mtk_dp, MTK_DP_AUX_P0_3620) &
>                                    AUX_RX_FIFO_READ_DATA_AUX_TX_P0_MASK);
>       }
> @@ -864,33 +863,28 @@ static void mtk_dp_aux_set_length(struct mtk_dp 
> *mtk_dp, size_t length)
>       }
>  }
>  
> -static int mtk_dp_aux_wait_for_completion(struct mtk_dp *mtk_dp, bool 
> is_read)
> +static int mtk_dp_aux_wait_for_completion(struct mtk_dp *mtk_dp)
>  {
> -     int wait_reply = MTK_DP_AUX_WAIT_REPLY_COUNT;
> -
> -     while (--wait_reply) {
> -             u32 aux_irq_status;
> -
> -             if (is_read) {
> -                     u32 fifo_status = mtk_dp_read(mtk_dp, 
> MTK_DP_AUX_P0_3618);
> -
> -                     if (fifo_status &
> -                         (AUX_RX_FIFO_WRITE_POINTER_AUX_TX_P0_MASK |
> -                          AUX_RX_FIFO_FULL_AUX_TX_P0_MASK)) {
> -                             return 0;
> -                     }
> -             }
> -
> -             aux_irq_status = mtk_dp_read(mtk_dp, MTK_DP_AUX_P0_3640);
> -             if (aux_irq_status & AUX_RX_AUX_RECV_COMPLETE_IRQ_AUX_TX_P0)
> -                     return 0;
> +     u32 aux_irq_status;
> +     int ret;
>  
> -             if (aux_irq_status & AUX_400US_TIMEOUT_IRQ_AUX_TX_P0)
> -                     return -ETIMEDOUT;
> +     /*
> +      * Wait until the whole reply has been received. The RX FIFO write
> +      * pointer becomes non-zero as soon as the first byte of the reply
> +      * arrives, while the rest of the reply is still on the AUX line, so
> +      * it cannot be used to tell that the reply is complete.
> +      */
> +     ret = regmap_read_poll_timeout(mtk_dp->regs, MTK_DP_AUX_P0_3640,
> +                                    aux_irq_status,
> +                                    aux_irq_status &
> +                                    (AUX_RX_AUX_RECV_COMPLETE_IRQ_AUX_TX_P0 |
> +                                     AUX_400US_TIMEOUT_IRQ_AUX_TX_P0),
> +                                    MTK_DP_AUX_POLL_US, 
> MTK_DP_AUX_TIMEOUT_US);
> +     if (ret)
> +             return ret;
>  
> -             /* Give the hardware a chance to reach completion before 
> retrying */
> -             usleep_range(100, 500);
> -     }
> +     if (aux_irq_status & AUX_RX_AUX_RECV_COMPLETE_IRQ_AUX_TX_P0)
> +             return 0;
>  
>       return -ETIMEDOUT;
>  }
> @@ -928,7 +922,7 @@ static int mtk_dp_aux_do_transfer(struct mtk_dp *mtk_dp, 
> bool is_read, u8 cmd,
>       mtk_dp_aux_request_ready(mtk_dp);
>  
>       /* Wait for feedback from sink device. */
> -     ret = mtk_dp_aux_wait_for_completion(mtk_dp, is_read);
> +     ret = mtk_dp_aux_wait_for_completion(mtk_dp);
>  
>       *reply_cmd = mtk_dp_read(mtk_dp, MTK_DP_AUX_P0_3624) &
>                    AUX_RX_REPLY_COMMAND_AUX_TX_P0_MASK;
> @@ -952,15 +946,7 @@ static int mtk_dp_aux_do_transfer(struct mtk_dp *mtk_dp, 
> bool is_read, u8 cmd,
>                                  AUX_TX_AUXTX_OV_EN_AUX_TX_P0_MASK |
>                                  AUX_RESERVED_RW_0_AUX_TX_P0_MASK);
>       } else if (is_read) {
> -             int read_delay;
> -
> -             if (cmd == (DP_AUX_I2C_READ | DP_AUX_I2C_MOT) ||
> -                 cmd == DP_AUX_I2C_READ)
> -                     read_delay = 500;
> -             else
> -                     read_delay = 100;
> -
> -             mtk_dp_aux_read_rx_fifo(mtk_dp, buf, length, read_delay);
> +             mtk_dp_aux_read_rx_fifo(mtk_dp, buf, length);
>       }
>  
>       return 0;

Reply via email to