From patchwork Sat Jan 21 16:31:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Keeping X-Patchwork-Id: 9530409 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 B75B66020B for ; Sat, 21 Jan 2017 16:33:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A957528119 for ; Sat, 21 Jan 2017 16:33:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E6E82842E; Sat, 21 Jan 2017 16:33:47 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 65C4128119 for ; Sat, 21 Jan 2017 16:33:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cUybq-0007qI-VF; Sat, 21 Jan 2017 16:33:46 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cUyab-0005gJ-Ae; Sat, 21 Jan 2017 16:32:29 +0000 Received: from dougal.metanate.com ([90.155.101.14] helo=metanate.com) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cUyaX-0004O4-05; Sat, 21 Jan 2017 16:32:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=simple/simple; d=metanate.com; s=stronger; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=uIqTYBqYOdtROdVbQFTEzeh8J+Gj5kskZ4bsR6+G3U4=; b=gqYvU43NENGTQSTmqAHMchS/EKOS5Q3QH3Z6S9OxXjTWjPv64K3WHZHieQqJ0o1QUtr6bVAlPTuhqS2Iuabuk3yvylmxkJHfocsVWnsyFmECjMQtQFHgLLuBPTV1hcTJk4WmraBnZjTGyyrDb00YkG6BdXxGgRIrEeH36vpp8YjX3FfFAaDzrAfo+mEbg7E64PudGT+aCmO44PuN1TrW5/4waa4eSLEWOTo5xwRCh4SPgtFMBs52iJ/FymIXYw/2VDMI0pcfrdcD+imU8uVlop9O/eN0eKIMhhoD2EErpmCKya6H1mWICnENCpdBHD1yXTQMNM6K88RkX2AK4NRP+Q==; Received: from johnkeeping.plus.com ([81.174.171.191] helo=localhost.localdomain) by shrek.metanate.com with esmtpsa (TLSv1.2:DHE-RSA-AES128-GCM-SHA256:128) (Exim 4.83_RC2) (envelope-from ) id 1cUya8-0004rJ-Mi; Sat, 21 Jan 2017 16:32:00 +0000 From: John Keeping To: Mark Yao Subject: [PATCH v2 26/26] drm/rockchip: dw-mipi-dsi: support read commands Date: Sat, 21 Jan 2017 16:31:28 +0000 Message-Id: <20170121163128.22240-27-john@metanate.com> X-Mailer: git-send-email 2.11.0.197.gb556de5.dirty In-Reply-To: <20170121163128.22240-1-john@metanate.com> References: <20170121163128.22240-1-john@metanate.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170121_163225_107958_E237EDF9 X-CRM114-Status: GOOD ( 14.24 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org, John Keeping , Chris Zhong , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP I haven't found any method for getting the length of a response, so this just uses the requested rx_len Signed-off-by: John Keeping --- Unchanged in v2 --- drivers/gpu/drm/rockchip/dw-mipi-dsi.c | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c index f780401e8b5e..f0cb005c6d76 100644 --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c @@ -675,6 +675,54 @@ static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi, return dw_mipi_dsi_gen_pkt_hdr_write(dsi, hdr_val); } +static int dw_mipi_dsi_dcs_read(struct dw_mipi_dsi *dsi, + const struct mipi_dsi_msg *msg) +{ + const u8 *tx_buf = msg->tx_buf; + u8 *rx_buf = msg->rx_buf; + size_t i; + int ret, val; + + dsi_write(dsi, DSI_PCKHDL_CFG, EN_CRC_RX | EN_ECC_RX | EN_BTA); + dsi_write(dsi, DSI_GEN_HDR, GEN_HDATA(tx_buf[0]) | GEN_HTYPE(msg->type)); + + ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, + val, !(val & GEN_RD_CMD_BUSY), 1000, + CMD_PKT_STATUS_TIMEOUT_US); + if (ret < 0) { + dev_err(dsi->dev, "failed to read command response\n"); + return ret; + } + + for (i = 0; i < msg->rx_len;) { + u32 pld = dsi_read(dsi, DSI_GEN_PLD_DATA); + while (i < msg->rx_len) { + rx_buf[i] = pld & 0xff; + pld >>= 8; + i++; + } + } + + return msg->rx_len; +} + +static int dw_mipi_dsi_set_max_return_packet_size(struct dw_mipi_dsi *dsi, + size_t len) +{ + u8 val[] = { len & 0xff, (len >> 8) & 0xff }; + struct mipi_dsi_msg msg = { + .channel = dsi->channel, + .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, + .tx_buf = val, + .tx_len = 2, + }; + + if (len > 0xffff) + return -EINVAL; + + return dw_mipi_dsi_dcs_short_write(dsi, &msg); +} + static ssize_t dw_mipi_dsi_host_transfer(struct mipi_dsi_host *host, const struct mipi_dsi_msg *msg) { @@ -692,6 +740,12 @@ static ssize_t dw_mipi_dsi_host_transfer(struct mipi_dsi_host *host, case MIPI_DSI_DCS_LONG_WRITE: ret = dw_mipi_dsi_dcs_long_write(dsi, msg); break; + case MIPI_DSI_DCS_READ: + ret = dw_mipi_dsi_set_max_return_packet_size(dsi, msg->rx_len); + if (ret < 0) + return ret; + ret = dw_mipi_dsi_dcs_read(dsi, msg); + break; default: dev_err(dsi->dev, "unsupported message type 0x%02x\n", msg->type);