Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756635AbeAJOdt (ORCPT + 1 other); Wed, 10 Jan 2018 09:33:49 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:38956 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752743AbeAJOdr (ORCPT ); Wed, 10 Jan 2018 09:33:47 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180110143344euoutp024bacd3bf7bf687c16cf93f2115b3b6a1~IeXadRCX91176811768euoutp02Z X-AuditID: cbfec7f4-f790c6d0000075d3-9f-5a562447d93b MIME-version: 1.0 Content-type: text/plain; charset="utf-8" Subject: Re: [PATCH v2 2/2] drm/bridge/synopsys: dsi: handle endianness correctly in dw_mipi_dsi_write() To: Brian Norris , Archit Taneja , Laurent Pinchart Cc: David Airlie , Yannick Fertre , Philippe Cornu , 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: <199f9097-736e-afe8-2093-bb28fba8b308@samsung.com> Date: Wed, 10 Jan 2018 15:33:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 In-reply-to: <20180109203248.139249-2-briannorris@chromium.org> Content-transfer-encoding: 8bit Content-language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa0hTYRju2zlnO1sujmvTjy4G6wLdVobBh6VlBp3+RARJ7U+tOupKp2wu VAhnedts5o2yM8PKC12ozIXLgVRmzUxT0UTFy0zULqSlpYZT23YU/Pe87/O+3/O8Dx+JSb4R a0i1JoHRalQxcr4Ir37/r2XnkU0Ryt332oOR+dMHHrqa9ZNAVb/HCdTxd5yPZiobMTTlyiSQ Ma9MgNrtxX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fe5k9Pm+SC+CK4rJJSc3JLEst0rdL4MrYNaeLuWCVaMXzr7MZ GxhXCnYxcnJICJhILD3wnQnCFpO4cG89WxcjF4eQwBJGiW8/TjODJHgFBCV+TL7H0sXIwcEs oC4xZUouRM0zRomNl+6BNQsLZEm0bD7PApIQEehllHj18QeYwyywk1lizdE1jBAtxxklXjY1 soG0sAloSvzdfJMNYoWdxNPGbWDrWARUJW7tOssCYosKREg0zZzLCmJzCthLfHt0nB3EZhaQ lzh45TkLhC0u0dx6k2UCo+AsJNfOQrh2FpKOWUg6FjCyrGIUSS0tzk3PLTbSK07MLS7NS9dL zs/dxAiM1W3Hfm7Zwdj1LvgQowAHoxIPb4RoWJQQa2JZcWXuIUYJDmYlEd53j0OjhHhTEiur Uovy44tKc1KLDzFKc7AoifP27lkdKSSQnliSmp2aWpBaBJNl4uCUamDc6/U3ZpLVBkNniR9h nwXtS2dt37/Ga9nq5L3RXst/VAvsOfKsZX7Jom+t7zxmhxwvmP0/pVpGysTkGENsy6YYsRfv nzkFLO7PCuLTMN5mybvrjnlB6d7Qjuzsu1EZE5faPetvjJ8jlhmQPO/p0Q5fpYU/uN/9OCjz +l3n7ZiNDlmNvxK3vrBTYinOSDTUYi4qTgQA3P7I7NECAAA= X-CMS-MailID: 20180110143343eucas1p2a9b7f8993b1b6ef44ce268b80230d74c X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180109203308epcas1p17226c8b3b3a0474adcd51b87b70084bf X-RootMTR: 20180109203308epcas1p17226c8b3b3a0474adcd51b87b70084bf References: <20180109203248.139249-1-briannorris@chromium.org> <20180109203248.139249-2-briannorris@chromium.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 09.01.2018 21:32, Brian Norris wrote: > We're filling the "remainder" word with little-endian data, then writing > it out to IO registers with endian-correcting writel(). That probably > won't work on big-endian systems. > > Let's mark the "remainder" variable as LE32 (since we fill it with > memcpy()) and do the swapping explicitly. > > Some of this function could be done more easily without memcpy(), but > the unaligned "remainder" case is a little hard to do without > potentially overrunning 'tx_buf', so I just applied the same solution in > all cases (memcpy() + le32_to_cpu()). > > Tested only on a little-endian system. > > Signed-off-by: Brian Norris > --- > drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c > index ed91e32ee43a..90f13df6f106 100644 > --- a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c > +++ b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c > @@ -360,18 +360,18 @@ static int dw_mipi_dsi_write(struct dw_mipi_dsi *dsi, > { > const u8 *tx_buf = packet->payload; > int len = packet->payload_length, pld_data_bytes = sizeof(u32), ret; > - u32 remainder; > + __le32 word; > u32 val; > > while (len) { > if (len < pld_data_bytes) { > - remainder = 0; > - memcpy(&remainder, tx_buf, len); > - dsi_write(dsi, DSI_GEN_PLD_DATA, remainder); > + word = 0; > + memcpy(&word, tx_buf, len); > + dsi_write(dsi, DSI_GEN_PLD_DATA, le32_to_cpu(word)); > len = 0; > } else { > - memcpy(&remainder, tx_buf, pld_data_bytes); > - dsi_write(dsi, DSI_GEN_PLD_DATA, remainder); > + memcpy(&word, tx_buf, pld_data_bytes); > + dsi_write(dsi, DSI_GEN_PLD_DATA, le32_to_cpu(word)); > tx_buf += pld_data_bytes; > len -= pld_data_bytes; > } > @@ -386,9 +386,9 @@ static int dw_mipi_dsi_write(struct dw_mipi_dsi *dsi, > } > } > > - remainder = 0; > - memcpy(&remainder, packet->header, sizeof(packet->header)); > - return dw_mipi_dsi_gen_pkt_hdr_write(dsi, remainder); > + word = 0; > + memcpy(&word, packet->header, sizeof(packet->header)); > + return dw_mipi_dsi_gen_pkt_hdr_write(dsi, le32_to_cpu(word)); You could create and use appropriate helper, lets say: u32 le_to_cpup(const u8 *p, int count) {     __le32 r = 0;     memcpy(&r, p, count);     return le32_to_cpu(r); } With or without this change: Reviewed-by: Andrzej Hajda  -- Regards Andrzej > } > > static ssize_t dw_mipi_dsi_host_transfer(struct mipi_dsi_host *host,