From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754211AbeALHKd (ORCPT + 1 other); Fri, 12 Jan 2018 02:10:33 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:41353 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbeALHKb (ORCPT ); Fri, 12 Jan 2018 02:10:31 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180112071027euoutp010925ccc91ba7133240a5f58c2e9bab10~I-m7-lODw0615006150euoutp01m X-AuditID: cbfec7f4-f790c6d0000075d3-40-5a585f624029 Subject: Re: [PATCH v2 1/2] drm/bridge/synopsys: dsi: use common mipi_dsi_create_packet() To: Philippe CORNU , Brian Norris , Archit Taneja , Laurent Pinchart Cc: David Airlie , Yannick FERTRE , Vincent ABRIOU , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , Sean Paul , Nickey Yang , "hl@rock-chips.com" , "linux-rockchip@lists.infradead.org" , "mka@chromium.org" , "hoegsberg@gmail.com" , "zyw@rock-chips.com" , "xbl@rock-chips.com" From: Andrzej Hajda Message-id: <8e02092c-7627-5c66-5443-af4adaeafe44@samsung.com> Date: Fri, 12 Jan 2018 08:10:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-version: 1.0 In-reply-to: Content-type: text/plain; charset="utf-8" Content-transfer-encoding: 7bit Content-language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA02SfUhTURjGObv3btfl4rpZvmQljCLsQ42iDlpSEHUpiKAwW1EuvejMqe2q aP2RVJpO7GNK6UyyWmHRx9L8aCTFJGdpozJNC20ZiiQ628oMs7V5Dfbf7znv8573PC+HJuSj 1CJak57F6dLVaUqxlGxs+21fc/RIvCrq188gXGp/KcKni8YoXPfdSeH3P51iPGV+ReDJP+co XHzJJMFdl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9/g7az+Lx9Mfe5k9Pm+SC+CK4rJJSc3JLEst0rdL4Mr4ueQHa8Ee84pz77ez NjBO1+li5OSQEDCR+HDmOxuELSZx4d56IJuLQ0hgCaPE1sN7WSCcZ4wSE79sYe9i5OAQFoiW WDItCiQuIrCdUaJh6X4mEIdZ4BuLxM2/nxghOg4xSqz8fYIdZC6bgKbE3803wXbwCthJHJ4y mRnEZhFQlXh4fRmYLSoQIdE0cy4rRI2gxI/J91hAbE4BK4kZMw+xgWxmFlCXmDIlFyTMLCAv sXnNW2YIW1yiufUmywRGwVlIumchdMxC0jELSccCRpZVjCKppcW56bnFRnrFibnFpXnpesn5 uZsYgZG67djPLTsYu94FH2IU4GBU4uG1KAiPEmJNLCuuzAV6j4NZSYR3hntElBBvSmJlVWpR fnxRaU5q8SFGaQ4WJXHe3j2rI4UE0hNLUrNTUwtSi2CyTBycUg2MnPe4HbtNdFRyHXdv5uG8 9UpZbvbBf3OlGrabnquWfc7Q2mJR+v+/8eOt5TNtGdev2DLp8lxtQXuLmd76Qvzr1Pc0Xmro UxJ+pvJmqR3/bqdH3/99FN9ktTTgcIl59G8707dv/maULH3yfUdASHPnE63MD3N+n7u58//N 3jixSRN2zOJb6+fWqsRSnJFoqMVcVJwIAG+wxTXQAgAA X-CMS-MailID: 20180112071025eucas1p175b83d133de57e6ef475e4de5758de4c X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180111135206epcas1p15bf907fd4e30948e22a28c4f6f023f91 X-RootMTR: 20180111135206epcas1p15bf907fd4e30948e22a28c4f6f023f91 References: <20180109203248.139249-1-briannorris@chromium.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 11.01.2018 14:51, Philippe CORNU wrote: > Hi Brian & All *DSI DRM experts*, > > 1) Re-reading this patch, I realize that the returned value of > dw_mipi_dsi_host_transfer() is not correct: we should return the number > of transfered/received bytes... > > so I think there are two solutions: fix this in this serie or add a TODO > for later (both solutions are fine to me :-) > > > 2) Digging more into the drm code, the function > mipi_dsi_device_transfer() in drm_mipi_dsi.c is called in the same file > by the 3 following functions: mipi_dsi_shutdown_peripheral(), > mipi_dsi_turn_on_peripheral() & > mipi_dsi_set_maximum_return_packet_size(). All these 3 functions are > expecting "Return: 0 on success or a negative error code on failure." > that is not in line with the transfer function. > > So then, we can change the documentation in this file and have instead > "* Return: The number of bytes transmitted on success or a negative > error code on failure." as for mipi_dsi_generic_write()... > Or we can change the source code of these 3 functions to match with the > documentation "Return: 0 on success...". > > note: Hopefully, "users" of these 3 functions test the sign of the > return value (or do not use it). > > Does anyone have a preferred solutions? All three functions performs single operation which can succeed only in one way, nobody is interested in the number of bytes send to achieve the result. So IMO the result should be 0 or error. And mipi_dsi_device_transfer() is a different beast, it returns number of written/read bytes, which can vary (more specifically, only number of read bytes can vary :) ). Regards Andrzej > > Many thanks > Philippe :-) > > On 01/09/2018 09:32 PM, Brian Norris wrote: >> 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 = {