From patchwork Tue Jan 9 20:32:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 10153261 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 64899601A1 for ; Tue, 9 Jan 2018 20:33:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60462201A4 for ; Tue, 9 Jan 2018 20:33:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54BE620415; Tue, 9 Jan 2018 20:33:23 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable 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 126F420499 for ; Tue, 9 Jan 2018 20:33:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=d+mUjN/SjoQDM1ZR8OygFPc3aJ8eYybLf31qiGrORAE=; b=HMS BvqudFWLmT2WvNidblKqTxxB+ZMFU9YIr/aJcGL6fkJpyAaoAsmdMZgrF6XBSOdWTV4UTRhkOy9Bk aNi64dEFj+gTNafCHyo1UZ8K3duKdTOT2rg3wQHYb6hLuH2zSGDP7wLsRosvX9oeHrWOK16Jwh9BI 0sWGcthGVmd/YXG0G1V3eCn0fH+CSRTziN6GU/rm4K/d99rLopPIrmN4mZaKGKtLpiw59rZ9nBbwS ZCE0/2uqMwLBUMnDcWZZ57/gmny9jPRuFrRN+/siQl0q/LyQLmrAO2/ZUW+O9UJ1NUS4t9ijeGw71 sPrf9HWbKjow4H5wxYbkCyK0dFnct8g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eZ0aF-0000UD-5R; Tue, 09 Jan 2018 20:33:19 +0000 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZ0aB-00006s-GS for linux-rockchip@lists.infradead.org; Tue, 09 Jan 2018 20:33:17 +0000 Received: by mail-pg0-x244.google.com with SMTP id z17so2837474pgc.4 for ; Tue, 09 Jan 2018 12:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=MuEqMK4H/yvI/6nHveXuXw8kV13JkoAiVwpaVaxure0=; b=Ldg+lK57K6DCWK9zOPv0KFlfLRdhHVrX8EoExeNj2JfseCqasWbqdljA0N5WBkZx6e EpN8X4WXDz4BFYDp179b8mQOXa3Vs2SzgpgoO6ie9/RASG7cmLGgd7fjbW8BVB7sH/op oooawR3U38ywxsSLdRlEshrBNoaT7PJPhe+bY= 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; bh=MuEqMK4H/yvI/6nHveXuXw8kV13JkoAiVwpaVaxure0=; b=b3yZMguFaMixXLrZHu306NsSIHtmYUeWG04s2KMpt8whJc3dzAsArsfI9yD+acyBm9 O5ISMyFNsab1UCa6SjzDqH46DY+zhsn23f3opX4Cg5IPpYWlaafczItXe4mY7NWii/mM LZEMGf6Gosb8D8jbWY86mHUDXAoGu9TP8N9irq+HcXS17HbHxNweeeCmGbps5CGuQVX+ 2CtGE+ytm9ZIGtA0fW1c1aP17JYVC74WjyboIqod1+vBrmk67IUYuZcODOBDDSX3mXuJ gjTM23UY46bP+5XaBmPIQZNu+PFvNjcAcoY4teg8em9XX+Owql3Vo1AAn196brvgu6h5 7SIw== X-Gm-Message-State: AKGB3mKrF3nN622bKU1zG1ADry+AFfpLrt125vAo17hT71Kg+UJ2dozF QTnAL4NWr1pLNuB1C0Vb36lPrQ== X-Google-Smtp-Source: ACJfBovHEbkWNVVJkOBR7bXBdqZj1DuZm7bBK0ZFg6uVtYogy8q/6qXKta+kmj59FbmlxqYh5XWyyQ== X-Received: by 10.99.184.17 with SMTP id p17mr13217346pge.357.1515529984550; Tue, 09 Jan 2018 12:33:04 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.113.17]) by smtp.gmail.com with ESMTPSA id v25sm16248084pfg.132.2018.01.09.12.33.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Jan 2018 12:33:03 -0800 (PST) From: Brian Norris To: Archit Taneja , Andrzej Hajda , Laurent Pinchart Subject: [PATCH v2 1/2] drm/bridge/synopsys: dsi: use common mipi_dsi_create_packet() Date: Tue, 9 Jan 2018 12:32:47 -0800 Message-Id: <20180109203248.139249-1-briannorris@chromium.org> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180109_123315_551819_AAB6CBBE X-CRM114-Status: GOOD ( 15.36 ) 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: hl@rock-chips.com, David Airlie , Brian Norris , hoegsberg@gmail.com, Philippe Cornu , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Yannick Fertre , linux-rockchip@lists.infradead.org, Nickey Yang , mka@chromium.org, Sean Paul , zyw@rock-chips.com, xbl@rock-chips.com, Vincent Abriou 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 This takes care of 2 TODOs in this driver, by using the common DSI packet-marshalling code instead of our custom short/long write code. This both saves us some duplicated code and gets us free support for command types that weren't already part of our switch block (e.g., MIPI_DSI_GENERIC_LONG_WRITE). The code logic stays mostly intact, except that it becomes unnecessary to split the short/long write functions, and we have to copy data a bit more. Along the way, I noticed that loop bounds were a little odd: while (DIV_ROUND_UP(len, pld_data_bytes)) This really was just supposed to be 'len != 0', so I made that more clear. Tested on RK3399 with some pending refactoring patches by Nickey Yang, to make the Rockchip DSI driver wrap this common driver. Signed-off-by: Brian Norris Reviewed-by: Philippe Cornu Tested-by: Philippe Cornu --- v2: * remove "dcs" naming, since these commands handle generic DSI too, not just DCS (thanks Philippe) * add Philippe's {Tested,Reviewed}-by --- drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 78 ++++++--------------------- 1 file changed, 16 insertions(+), 62 deletions(-) diff --git a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c index d9cca4fd66ec..ed91e32ee43a 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c @@ -136,10 +136,6 @@ GEN_SW_0P_TX_LP) #define DSI_GEN_HDR 0x6c -/* TODO These 2 defines will be reworked thanks to mipi_dsi_create_packet() */ -#define GEN_HDATA(data) (((data) & 0xffff) << 8) -#define GEN_HTYPE(type) (((type) & 0xff) << 0) - #define DSI_GEN_PLD_DATA 0x70 #define DSI_CMD_PKT_STATUS 0x74 @@ -359,44 +355,15 @@ static int dw_mipi_dsi_gen_pkt_hdr_write(struct dw_mipi_dsi *dsi, u32 hdr_val) return 0; } -static int dw_mipi_dsi_dcs_short_write(struct dw_mipi_dsi *dsi, - const struct mipi_dsi_msg *msg) -{ - const u8 *tx_buf = msg->tx_buf; - u16 data = 0; - u32 val; - - if (msg->tx_len > 0) - data |= tx_buf[0]; - if (msg->tx_len > 1) - data |= tx_buf[1] << 8; - - if (msg->tx_len > 2) { - dev_err(dsi->dev, "too long tx buf length %zu for short write\n", - msg->tx_len); - return -EINVAL; - } - - val = GEN_HDATA(data) | GEN_HTYPE(msg->type); - return dw_mipi_dsi_gen_pkt_hdr_write(dsi, val); -} - -static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi, - const struct mipi_dsi_msg *msg) +static int dw_mipi_dsi_write(struct dw_mipi_dsi *dsi, + const struct mipi_dsi_packet *packet) { - const u8 *tx_buf = msg->tx_buf; - int len = msg->tx_len, pld_data_bytes = sizeof(u32), ret; - u32 hdr_val = GEN_HDATA(msg->tx_len) | GEN_HTYPE(msg->type); + const u8 *tx_buf = packet->payload; + int len = packet->payload_length, pld_data_bytes = sizeof(u32), ret; u32 remainder; u32 val; - if (msg->tx_len < 3) { - dev_err(dsi->dev, "wrong tx buf length %zu for long write\n", - msg->tx_len); - return -EINVAL; - } - - while (DIV_ROUND_UP(len, pld_data_bytes)) { + while (len) { if (len < pld_data_bytes) { remainder = 0; memcpy(&remainder, tx_buf, len); @@ -419,40 +386,27 @@ static int dw_mipi_dsi_dcs_long_write(struct dw_mipi_dsi *dsi, } } - return dw_mipi_dsi_gen_pkt_hdr_write(dsi, hdr_val); + remainder = 0; + memcpy(&remainder, packet->header, sizeof(packet->header)); + return dw_mipi_dsi_gen_pkt_hdr_write(dsi, remainder); } static ssize_t dw_mipi_dsi_host_transfer(struct mipi_dsi_host *host, const struct mipi_dsi_msg *msg) { struct dw_mipi_dsi *dsi = host_to_dsi(host); + struct mipi_dsi_packet packet; int ret; - /* - * TODO dw drv improvements - * use mipi_dsi_create_packet() instead of all following - * functions and code (no switch cases, no - * dw_mipi_dsi_dcs_short_write(), only the loop in long_write...) - * and use packet.header... - */ - dw_mipi_message_config(dsi, msg); - - switch (msg->type) { - case MIPI_DSI_DCS_SHORT_WRITE: - case MIPI_DSI_DCS_SHORT_WRITE_PARAM: - case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE: - ret = dw_mipi_dsi_dcs_short_write(dsi, msg); - break; - case MIPI_DSI_DCS_LONG_WRITE: - ret = dw_mipi_dsi_dcs_long_write(dsi, msg); - break; - default: - dev_err(dsi->dev, "unsupported message type 0x%02x\n", - msg->type); - ret = -EINVAL; + ret = mipi_dsi_create_packet(&packet, msg); + if (ret) { + dev_err(dsi->dev, "failed to create packet: %d\n", ret); + return ret; } - return ret; + dw_mipi_message_config(dsi, msg); + + return dw_mipi_dsi_write(dsi, &packet); } static const struct mipi_dsi_host_ops dw_mipi_dsi_host_ops = {