From patchwork Fri Apr 12 09:41:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10897723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 206D517E1 for ; Fri, 12 Apr 2019 09:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0190528E18 for ; Fri, 12 Apr 2019 09:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9B0E28E71; Fri, 12 Apr 2019 09:41:43 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B355428E18 for ; Fri, 12 Apr 2019 09:41:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726708AbfDLJlm (ORCPT ); Fri, 12 Apr 2019 05:41:42 -0400 Received: from smtp.domeneshop.no ([194.63.252.55]:43336 "EHLO smtp.domeneshop.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbfDLJll (ORCPT ); Fri, 12 Apr 2019 05:41:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject:Cc:To:From; bh=KGZJ3WnM21zM7Ne/S58ozyw6djuLtV+7nKa/hI+MU9c=; b=A+g/Tikuw0O/4G/yu+qoW6GZQ7o5uwBgGP4uEDz5OF5F1wRJel9zLjEWJCAxYug2JIFPiZrO87pV3a7IisxLmxyHQ1FkjVj+jG815qLmCIea9OwWHfw5Mrm17cDwYTSAGCfRvL0nOmm1ZDdD/qS2kPJ/UWK85t+E45Et3c5gt03tMzpJJgKT6OA4daIv+74epvE5O44RhFMLmhzlMci1B9CGTGmWhDc++oZ9b0C8J2gsdsgYr1Hak7oRHzCEdSHAok+W79/HhREZW9++rYteUrbLD5MkV8MeW1besAkDdbK/vpKYPNJds9u87Of3pE7Upatnb2maOQ0LWuA4VryQcg==; Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:49906 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1hEsgl-0007Xy-EJ; Fri, 12 Apr 2019 11:41:39 +0200 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: linux-spi@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: broonie@kernel.org, =?utf-8?q?Noralf_Tr=C3=B8nnes?= Subject: [PATCH 1/2] spi: Add spi_is_bpw_supported() Date: Fri, 12 Apr 2019 11:41:30 +0200 Message-Id: <20190412094131.25616-1-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This let SPI clients check if the controller supports a particular word width. drivers/gpu/drm/tinydrm/mipi-dbi.c will use this to determine if the controller supports 16-bit for RGB565 pixels. If it doesn't it will swap the bytes before transfer on little endian machines. Signed-off-by: Noralf Trønnes --- include/linux/spi/spi.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 662b336aa2e4..b30e3d13a5ac 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -983,6 +983,26 @@ spi_max_transfer_size(struct spi_device *spi) return min(tr_max, msg_max); } +/** + * spi_is_bpw_supported - Check if bits per word is supported + * @spi: SPI device + * @bpw: Bits per word + * + * This function checks to see if the SPI controller supports @bpw. + * + * Returns: + * True if @bpw is supported, false otherwise. + */ +static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw) +{ + u32 bpw_mask = spi->master->bits_per_word_mask; + + if (bpw == 8 || (bpw <= 32 && bpw_mask & SPI_BPW_MASK(bpw))) + return true; + + return false; +} + /*---------------------------------------------------------------------------*/ /* SPI transfer replacement methods which make use of spi_res */ From patchwork Fri Apr 12 09:41:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10897725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 715201800 for ; Fri, 12 Apr 2019 09:41:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54BBA28E20 for ; Fri, 12 Apr 2019 09:41:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48B1728E71; Fri, 12 Apr 2019 09:41:45 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D418B28E24 for ; Fri, 12 Apr 2019 09:41:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726327AbfDLJlm (ORCPT ); Fri, 12 Apr 2019 05:41:42 -0400 Received: from smtp.domeneshop.no ([194.63.252.55]:44684 "EHLO smtp.domeneshop.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726706AbfDLJll (ORCPT ); Fri, 12 Apr 2019 05:41:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=IpldDZy5VVQUoPIoyYo2tvopGHdJYbn7KvyOuoec1Nw=; b=swrlfKiBVmdNkU6Uk4rwgY14r3TSnLZ4dHpMSRFP6ZtL7mmhMqCQLFKeNcZMLmxjsJTs97FdO6BWpNsN8UB9OSu0le4VE62hxOujefBNO1A7v40AW/JPtcbccBAw/Sr9pSDx0OXCIwdHzSRhWvRX7EfnZUlU8HUYU0YugRrFq9AIxxnFHwA4mEJ3x8fWPqHe6ZNum27/Ku50QRA+9sy/0no5W5P3lwW5LL9ghOrRnZhI0fTlGgVnjGoJcEpQ93DFYGyr1Dla/OqyzL+EVbGDDW/+zxm6CNimEqi/4jcvSlvzlzBw1+9jdBEV0URjR17zoxL6ya8dBMgxSnzR4DgoDw==; Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:49906 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1hEsgl-0007Xy-Id; Fri, 12 Apr 2019 11:41:39 +0200 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: linux-spi@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: broonie@kernel.org, =?utf-8?q?Noralf_Tr=C3=B8nnes?= Subject: [PATCH 2/2] drm/tinydrm: Use spi_is_bpw_supported() Date: Fri, 12 Apr 2019 11:41:31 +0200 Message-Id: <20190412094131.25616-2-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190412094131.25616-1-noralf@tronnes.org> References: <20190412094131.25616-1-noralf@tronnes.org> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This means that tinydrm_spi_bpw_supported() can be removed. Signed-off-by: Noralf Trønnes --- .../gpu/drm/tinydrm/core/tinydrm-helpers.c | 32 +------------------ drivers/gpu/drm/tinydrm/mipi-dbi.c | 5 ++- include/drm/tinydrm/tinydrm-helpers.h | 1 - 3 files changed, 3 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c index 6d540d93758f..a2b24b5680ba 100644 --- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c @@ -57,36 +57,6 @@ size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len) } EXPORT_SYMBOL(tinydrm_spi_max_transfer_size); -/** - * tinydrm_spi_bpw_supported - Check if bits per word is supported - * @spi: SPI device - * @bpw: Bits per word - * - * This function checks to see if the SPI master driver supports @bpw. - * - * Returns: - * True if @bpw is supported, false otherwise. - */ -bool tinydrm_spi_bpw_supported(struct spi_device *spi, u8 bpw) -{ - u32 bpw_mask = spi->master->bits_per_word_mask; - - if (bpw == 8) - return true; - - if (!bpw_mask) { - dev_warn_once(&spi->dev, - "bits_per_word_mask not set, assume 8-bit only\n"); - return false; - } - - if (bpw_mask & SPI_BPW_MASK(bpw)) - return true; - - return false; -} -EXPORT_SYMBOL(tinydrm_spi_bpw_supported); - static void tinydrm_dbg_spi_print(struct spi_device *spi, struct spi_transfer *tr, const void *buf, int idx, bool tx) @@ -163,7 +133,7 @@ int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz, pr_debug("[drm:%s] bpw=%u, max_chunk=%zu, transfers:\n", __func__, bpw, max_chunk); - if (bpw == 16 && !tinydrm_spi_bpw_supported(spi, 16)) { + if (bpw == 16 && !spi_is_bpw_supported(spi, 16)) { tr.bits_per_word = 8; if (tinydrm_machine_little_endian()) { swap_buf = kmalloc(min(len, max_chunk), GFP_KERNEL); diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c index 85761b4abb83..534b16926bee 100644 --- a/drivers/gpu/drm/tinydrm/mipi-dbi.c +++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c @@ -787,7 +787,7 @@ static int mipi_dbi_spi1_transfer(struct mipi_dbi *mipi, int dc, u16 *dst16; int ret; - if (!tinydrm_spi_bpw_supported(spi, 9)) + if (!spi_is_bpw_supported(spi, 9)) return mipi_dbi_spi1e_transfer(mipi, dc, buf, len, bpw); tr.speed_hz = mipi_dbi_spi_cmd_max_speed(spi, len); @@ -1008,8 +1008,7 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi, if (dc) { mipi->command = mipi_dbi_typec3_command; mipi->dc = dc; - if (tinydrm_machine_little_endian() && - !tinydrm_spi_bpw_supported(spi, 16)) + if (tinydrm_machine_little_endian() && !spi_is_bpw_supported(spi, 16)) mipi->swap_bytes = true; } else { mipi->command = mipi_dbi_typec1_command; diff --git a/include/drm/tinydrm/tinydrm-helpers.h b/include/drm/tinydrm/tinydrm-helpers.h index 7d259acb8826..a35a78e7b109 100644 --- a/include/drm/tinydrm/tinydrm-helpers.h +++ b/include/drm/tinydrm/tinydrm-helpers.h @@ -47,7 +47,6 @@ int tinydrm_display_pipe_init(struct drm_device *drm, unsigned int rotation); size_t tinydrm_spi_max_transfer_size(struct spi_device *spi, size_t max_len); -bool tinydrm_spi_bpw_supported(struct spi_device *spi, u8 bpw); int tinydrm_spi_transfer(struct spi_device *spi, u32 speed_hz, struct spi_transfer *header, u8 bpw, const void *buf, size_t len);