From patchwork Fri Aug 30 13:06:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 172698 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp601271ily; Fri, 30 Aug 2019 06:06:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIKo1/mb/bNOvjbFNsAGb/hlRa6nF3m/vz7aaObXU33yacZJZsVqNEWOROOMALgGjII9f+ X-Received: by 2002:a17:90b:8c5:: with SMTP id ds5mr15762101pjb.142.1567170394508; Fri, 30 Aug 2019 06:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567170394; cv=none; d=google.com; s=arc-20160816; b=rY00oBC4nWC8R03BON6CkrIR4nVfWF1wclDWzXP5JvJ1I9135an/jnMzP7/kx23/jf LQuU2DvnGwSj9BtanHOAATLPjnvnewY86Puwx8y7GsKZH7d/l6A3PTEIjZuxHVUDCjj2 X/lWk/7PP+VBUvS/wz+nMRlWgU/gu3Enk4Me5bMu2zcb2YwNsgorCxuipmaUgGVTsULK oOTe1YjYk3hjbDsnX61OyoeEUFo5LWJq47OhljrmuWDgRsjODMOrVr0gneLRh4iECEVU jXmWtV4b9lRvNqWkwM/Z4Km3nkJRNVZLNQv19SfIehMIldcD2z3WSqZ9v68N/9k3suNa eTnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :delivered-to; bh=wvLLcFqCfEet9bnzf9V8xgL4bgp3oqx76Amk765AFUU=; b=gL/Ii9uOpZkPZea2vxpeh2h4Li/cnEhb+sb2ihKlu8fNPLqk/jJEfOgv8bBOrvIXhh /lwlLfksC3LkVGdHP7kZbP55f79JMcrVBkdY8k0iWCqN4OSfF/1SD1g1h+CFZGPjiUxH Sifed+aCUJ9TKn2YQjx7IsBtesIWwmzSzhYGmZIDazdf6m09Q4inAnzVybNt15D728PM Er7DGtJ8tYT0a8SXtE25Nr7RS6f3sknUctMzXS9DvzpxMj1vdzptW0f86FsXaB8NCVd1 mfOuUaWMLn42UIquxB0KyUkkb2lo/lL4RnFZirzYDhr/5uPG2B6bMmnAepQyT9kK8bE0 UQnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id w188si5725677pfb.175.2019.08.30.06.06.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Aug 2019 06:06:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DCF356E331; Fri, 30 Aug 2019 13:06:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by gabe.freedesktop.org (Postfix) with ESMTPS id E00C36E331 for ; Fri, 30 Aug 2019 13:06:30 +0000 (UTC) Received: by mail-lf1-x144.google.com with SMTP id q27so5289579lfo.10 for ; Fri, 30 Aug 2019 06:06:30 -0700 (PDT) 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=CEB5ZvNjUPElBE9umR+JJZU4wgevrWXUj1n2n10MLZs=; b=fK3yq7YNiMGS6v5KCEAm3fvx0UN546gkBl95ayUhZdGt193aYvHp+o8vOvdqodG2lr ySKiXrA2cTasiiKzCMPz2uqFLSDtc6ROVUg5VNgr/KvfMIDmeTMD6BR3WmIssnGWgX2a KlRmpavQVnodkswTuGuRub045trmTSwpdidi9gTyXbJTE8zZLIukOI9Hl2Cp8Lar5bTO mdM7Wr0BCgkkrrs5on0FPstktKon7Xg1hLhYVGlnRZ+lM0DIpaiG3ZrbfULXpv4COReX 4KuVld3g/y//w4Zsgw1OCSJmIaEPSu9bFPjLUNhCn7kTdqbQMo0dqnFt9keKVM7IOcZf vBpQ== X-Gm-Message-State: APjAAAWxfHGoq1VXwoOYXueoNR939rqwD2cPzwNS2B3TG4zuGukCm+KJ Os2BQg0no32I+c6ePorbOyVcIlxcpgQ= X-Received: by 2002:a19:e04f:: with SMTP id g15mr9011216lfj.46.1567170388587; Fri, 30 Aug 2019 06:06:28 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y20sm833319ljy.55.2019.08.30.06.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2019 06:06:27 -0700 (PDT) From: Linus Walleij To: dri-devel@lists.freedesktop.org, Maarten Lankhorst , Maxime Ripard , Sean Paul Subject: [PATCH] drm/mcde: Fix DSI transfers Date: Fri, 30 Aug 2019 15:06:23 +0200 Message-Id: <20190830130623.19116-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-Mailman-Original-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=CEB5ZvNjUPElBE9umR+JJZU4wgevrWXUj1n2n10MLZs=; b=uwd8wpGvjkNaubjt9cnpM6036yUIA8iJpAkMfwRTyg+jknhyyGowZf1ko4n3IvSm2n oAZBqNTS6R+q3h3OKpKow1Rq5OLDKixQjYHQeQp1skVm1KqbhfqLn9z6jr5DtjHpmp0Y Ps7O6kMaTplrkMiCpbf+rGxQuGARV94LgzQeEdjtpycJUjqurOhctuIYkY5o5wxQ+SGL rbWATECNrvU8qWlsZVcGobN/lZUGTtpPujqpTgqHRAR1eKhQbTLqG6Ls4WKfWZABMbnx 2/hOUzJcoJglMPbDpA+4SAegV9rREWDaaNLoqJsVJoPZGS51C1G9iYEM9qWP5iV9KE04 aE9g== 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: Stephan Gerhold , linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There were bugs in the DSI transfer (read and write) function as it was only tested with displays ever needing a single byte to be written. Fixed it up and tested so we can now write messages of up to 16 bytes and read up to 4 bytes from the display. Tested with a Sony ACX424AKP display: this display now self- identifies and can control backlight in command mode. Cc: Stephan Gerhold Fixes: 5fc537bfd000 ("drm/mcde: Add new driver for ST-Ericsson MCDE") Signed-off-by: Linus Walleij --- drivers/gpu/drm/mcde/mcde_dsi.c | 70 ++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/mcde/mcde_dsi.c b/drivers/gpu/drm/mcde/mcde_dsi.c index 07f7090d08b3..ad76a36e7bc1 100644 --- a/drivers/gpu/drm/mcde/mcde_dsi.c +++ b/drivers/gpu/drm/mcde/mcde_dsi.c @@ -178,22 +178,26 @@ static ssize_t mcde_dsi_host_transfer(struct mipi_dsi_host *host, const u32 loop_delay_us = 10; /* us */ const u8 *tx = msg->tx_buf; u32 loop_counter; - size_t txlen; + size_t txlen = msg->tx_len; + size_t rxlen = msg->rx_len; u32 val; int ret; int i; - txlen = msg->tx_len; - if (txlen > 12) { + if (txlen > 16) { dev_err(d->dev, - "dunno how to write more than 12 bytes yet\n"); + "dunno how to write more than 16 bytes yet\n"); + return -EIO; + } + if (rxlen > 4) { + dev_err(d->dev, + "dunno how to read more than 4 bytes yet\n"); return -EIO; } dev_dbg(d->dev, - "message to channel %d, %zd bytes", - msg->channel, - txlen); + "message to channel %d, write %zd bytes read %zd bytes\n", + msg->channel, txlen, rxlen); /* Command "nature" */ if (MCDE_DSI_HOST_IS_READ(msg->type)) @@ -210,9 +214,7 @@ static ssize_t mcde_dsi_host_transfer(struct mipi_dsi_host *host, if (mipi_dsi_packet_format_is_long(msg->type)) val |= DSI_DIRECT_CMD_MAIN_SETTINGS_CMD_LONGNOTSHORT; val |= 0 << DSI_DIRECT_CMD_MAIN_SETTINGS_CMD_ID_SHIFT; - /* Add one to the length for the MIPI DCS command */ - val |= txlen - << DSI_DIRECT_CMD_MAIN_SETTINGS_CMD_SIZE_SHIFT; + val |= txlen << DSI_DIRECT_CMD_MAIN_SETTINGS_CMD_SIZE_SHIFT; val |= DSI_DIRECT_CMD_MAIN_SETTINGS_CMD_LP_EN; val |= msg->type << DSI_DIRECT_CMD_MAIN_SETTINGS_CMD_HEAD_SHIFT; writel(val, d->regs + DSI_DIRECT_CMD_MAIN_SETTINGS); @@ -249,17 +251,36 @@ static ssize_t mcde_dsi_host_transfer(struct mipi_dsi_host *host, writel(1, d->regs + DSI_DIRECT_CMD_SEND); loop_counter = 1000 * 1000 / loop_delay_us; - while (!(readl(d->regs + DSI_DIRECT_CMD_STS) & - DSI_DIRECT_CMD_STS_WRITE_COMPLETED) - && --loop_counter) - usleep_range(loop_delay_us, (loop_delay_us * 3) / 2); - - if (!loop_counter) { - dev_err(d->dev, "DSI write timeout!\n"); - return -ETIME; + if (MCDE_DSI_HOST_IS_READ(msg->type)) { + /* Read command */ + while (!(readl(d->regs + DSI_DIRECT_CMD_STS) & + (DSI_DIRECT_CMD_STS_READ_COMPLETED | + DSI_DIRECT_CMD_STS_READ_COMPLETED_WITH_ERR)) + && --loop_counter) + usleep_range(loop_delay_us, (loop_delay_us * 3) / 2); + if (!loop_counter) { + dev_err(d->dev, "DSI write timeout!\n"); + return -ETIME; + } + } else { + /* Writing only */ + while (!(readl(d->regs + DSI_DIRECT_CMD_STS) & + DSI_DIRECT_CMD_STS_WRITE_COMPLETED) + && --loop_counter) + usleep_range(loop_delay_us, (loop_delay_us * 3) / 2); + + if (!loop_counter) { + dev_err(d->dev, "DSI write timeout!\n"); + return -ETIME; + } } val = readl(d->regs + DSI_DIRECT_CMD_STS); + if (val & DSI_DIRECT_CMD_STS_READ_COMPLETED_WITH_ERR) { + dev_err(d->dev, "read completed with error\n"); + writel(1, d->regs + DSI_DIRECT_CMD_RD_INIT); + return -EIO; + } if (val & DSI_DIRECT_CMD_STS_ACKNOWLEDGE_WITH_ERR_RECEIVED) { val >>= DSI_DIRECT_CMD_STS_ACK_VAL_SHIFT; dev_err(d->dev, "error during transmission: %04x\n", @@ -269,10 +290,7 @@ static ssize_t mcde_dsi_host_transfer(struct mipi_dsi_host *host, if (!MCDE_DSI_HOST_IS_READ(msg->type)) { /* Return number of bytes written */ - if (mipi_dsi_packet_format_is_long(msg->type)) - ret = 4 + txlen; - else - ret = 4; + ret = txlen; } else { /* OK this is a read command, get the response */ u32 rdsz; @@ -282,7 +300,13 @@ static ssize_t mcde_dsi_host_transfer(struct mipi_dsi_host *host, rdsz = readl(d->regs + DSI_DIRECT_CMD_RD_PROPERTY); rdsz &= DSI_DIRECT_CMD_RD_PROPERTY_RD_SIZE_MASK; rddat = readl(d->regs + DSI_DIRECT_CMD_RDDAT); - for (i = 0; i < 4 && i < rdsz; i++) + if (rdsz < rxlen) { + dev_err(d->dev, "read error, requested %d got %d\n", + msg->rx_len, rdsz); + return -EIO; + } + /* FIXME: read more than 4 bytes */ + for (i = 0; i < 4 && i < rxlen; i++) rx[i] = (rddat >> (i * 8)) & 0xff; ret = rdsz; }