From patchwork Mon Mar 5 10:17:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10258577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 406E560365 for ; Mon, 5 Mar 2018 10:17:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30EBB289CE for ; Mon, 5 Mar 2018 10:17:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25F35289D0; Mon, 5 Mar 2018 10:17:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B497289CE for ; Mon, 5 Mar 2018 10:17:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 509CF89DFE; Mon, 5 Mar 2018 10:17:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-x241.google.com (mail-lf0-x241.google.com [IPv6:2a00:1450:4010:c07::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id F24A489DFE for ; Mon, 5 Mar 2018 10:17:07 +0000 (UTC) Received: by mail-lf0-x241.google.com with SMTP id h127so21235304lfg.12 for ; Mon, 05 Mar 2018 02:17:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ytxJqlLdm6gJQ/vvGOytFWFrXlKD3coh8fL+60F8NQo=; b=iB0VcUUio4l5KbwDREB9Z1aV1SK915QpaDJAsXQ20Sxz2nifTcZB4VCZcg+JZ/ia0X UzWMoG52JFINMaY60UF2FM74a9EK89sY4RRZ+yhpVwMhZ7FRAFa8Ju/Lg5e/i2RBMe8d oWAG9ViCELOJ+Fn8jwaub422vfSvsnpmudbFo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ytxJqlLdm6gJQ/vvGOytFWFrXlKD3coh8fL+60F8NQo=; b=OcacAJZ+GTtlO4kwkxB7zYHjJgK5HxfU01HyErwUzXWYClFpPnCexdgcvGn7AInpMN I4Zb+eeiaaruk8FJWbChksfz/nTU8QkfrB37oeES3ldL3ZNdEPbDIiGuWLrwxFhXB2wb AIcHJIH8mpNRCZt8/78uXrMifyNo1RS0hDWu2+ig1zW23SYjUKHiwlMnXiia68+tBQye m1SFxvyVLPmTJff44yaaHt8VGCDVCdKV6AHDbso4FnIQz0mEPE1cvG14nsjQ3wNvC5e8 H32BzCMqEHDQU/xs7lnOhiEsl9wWf2lvnQa/qwRGMMtAdpULuTl63XdWN+NpQEHhwgXu /eUQ== X-Gm-Message-State: AElRT7EXpZVw0v7He2nvz2Zo/VOGVd30xVh1+iagabFKXcpZPbhrK5Ao 79Rto7W6qzHaP62OEJZJBHf/aA== X-Google-Smtp-Source: AG47ELuR5UuP8B8KJu4f6sdtaoD+/uL1uyqdYgN04TCP7O32yYF2LnrkkaTT93L/EyiXAdcU9f0mOQ== X-Received: by 10.46.92.7 with SMTP id q7mr9459791ljb.21.1520245026306; Mon, 05 Mar 2018 02:17:06 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id 4sm2627742lje.38.2018.03.05.02.17.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Mar 2018 02:17:05 -0800 (PST) From: Linus Walleij To: Archit Taneja , Andrzej Hajda , Laurent Pinchart Subject: [PATCH] drm/bridge: sii902x: Retry status read after DDI I2C Date: Mon, 5 Mar 2018 11:17:02 +0100 Message-Id: <20180305101702.13441-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liviu Dudau , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The following happens when connection a DVI output driven from the SiI9022 using a DVI-to-VGA adapter plug: i2c i2c-0: sendbytes: NAK bailout. i2c i2c-0: sendbytes: NAK bailout. Then no picture. Apparently the I2C engine inside the SiI9022 is not smart enough to try to fall back to DDC I2C. Or the vendor have not integrated the electronics properly. I don't know which one it is. After this, the I2C bus seems stalled and the first attempt to read the status register fails, and the code returns with negative return value, and the display fails to initialized. Instead, retry status readout five times and continue even if this fails. Tested on the ARM Versatile Express with a DVI-to-VGA connector, it now gives picture. Introduce a helper struct device *dev variable to make the code more readable. Cc: Ville Syrjälä Cc: Liviu Dudau Signed-off-by: Linus Walleij Reviewed-by: Liviu Dudau --- ChangeLog v1->v2: - Found the real problem instead of trying to explicitly shoehorn EDID modes into the error path. --- drivers/gpu/drm/bridge/sii902x.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/sii902x.c b/drivers/gpu/drm/bridge/sii902x.c index b1ab4ab09532..60373d7eb220 100644 --- a/drivers/gpu/drm/bridge/sii902x.c +++ b/drivers/gpu/drm/bridge/sii902x.c @@ -137,7 +137,9 @@ static int sii902x_get_modes(struct drm_connector *connector) struct sii902x *sii902x = connector_to_sii902x(connector); struct regmap *regmap = sii902x->regmap; u32 bus_format = MEDIA_BUS_FMT_RGB888_1X24; + struct device *dev = &sii902x->i2c->dev; unsigned long timeout; + unsigned int retries; unsigned int status; struct edid *edid; int num = 0; @@ -159,7 +161,7 @@ static int sii902x_get_modes(struct drm_connector *connector) time_before(jiffies, timeout)); if (!(status & SII902X_SYS_CTRL_DDC_BUS_GRTD)) { - dev_err(&sii902x->i2c->dev, "failed to acquire the i2c bus\n"); + dev_err(dev, "failed to acquire the i2c bus\n"); return -ETIMEDOUT; } @@ -179,9 +181,19 @@ static int sii902x_get_modes(struct drm_connector *connector) if (ret) return ret; - ret = regmap_read(regmap, SII902X_SYS_CTRL_DATA, &status); + /* + * Sometimes the I2C bus can stall after failure to use the + * EDID channel. Retry a few times to see if things clear + * up, else continue anyway. + */ + retries = 5; + do { + ret = regmap_read(regmap, SII902X_SYS_CTRL_DATA, + &status); + retries--; + } while (ret && retries); if (ret) - return ret; + dev_err(dev, "failed to read status (%d)\n", ret); ret = regmap_update_bits(regmap, SII902X_SYS_CTRL_DATA, SII902X_SYS_CTRL_DDC_BUS_REQ | @@ -201,7 +213,7 @@ static int sii902x_get_modes(struct drm_connector *connector) if (status & (SII902X_SYS_CTRL_DDC_BUS_REQ | SII902X_SYS_CTRL_DDC_BUS_GRTD)) { - dev_err(&sii902x->i2c->dev, "failed to release the i2c bus\n"); + dev_err(dev, "failed to release the i2c bus\n"); return -ETIMEDOUT; }