it6505_audio_input() saves REG_RESET_CTRL, pulses AUDIO_RESET and
writes the saved value back. it6505_read() returns a negative errno on
i2c failure, which regmap truncates to eight bits on the way out:
-EIO turns into 0xfb, asserting ALL_LOGIC_RESET, VIDEO_RESET,
AUX_RESET and HDCP_RESET. A failed REG_AUDIO_INPUT_FREQ read is just
as wrong, as any negative value passes the != 0xFF test and reports an
audio clock that was never sampled. Bail out before touching the
register and only report audio input for a usable readback.

Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver")
Signed-off-by: Daniel Golle <[email protected]>
---
v6: new patch

 drivers/gpu/drm/bridge/ite-it6505.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/ite-it6505.c 
b/drivers/gpu/drm/bridge/ite-it6505.c
index 1678ec5b3ba7..aeaa7b5ecf5a 100644
--- a/drivers/gpu/drm/bridge/ite-it6505.c
+++ b/drivers/gpu/drm/bridge/ite-it6505.c
@@ -1516,12 +1516,15 @@ static bool it6505_audio_input(struct it6505 *it6505)
        int reg05, regbe;
 
        reg05 = it6505_read(it6505, REG_RESET_CTRL);
+       if (reg05 < 0)
+               return false;
+
        it6505_set_bits(it6505, REG_RESET_CTRL, AUDIO_RESET, 0x00);
        usleep_range(3000, 4000);
        regbe = it6505_read(it6505, REG_AUDIO_INPUT_FREQ);
        it6505_write(it6505, REG_RESET_CTRL, reg05);
 
-       return regbe != 0xFF;
+       return regbe > 0 && regbe != 0xFF;
 }
 
 static void it6505_setup_audio_channel_status(struct it6505 *it6505)
-- 
2.55.0

Reply via email to