From patchwork Mon Aug 1 06:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Birger Koblitz X-Patchwork-Id: 594827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EB0EC00144 for ; Mon, 1 Aug 2022 06:17:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239069AbiHAGRO (ORCPT ); Mon, 1 Aug 2022 02:17:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbiHAGRM (ORCPT ); Mon, 1 Aug 2022 02:17:12 -0400 Received: from wp175.webpack.hosteurope.de (wp175.webpack.hosteurope.de [IPv6:2a01:488:42:1000:50ed:84b6::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B153BF7E; Sun, 31 Jul 2022 23:17:11 -0700 (PDT) Received: from p54bc6cd6.dip0.t-ipconnect.de ([84.188.108.214] helo=[192.168.1.113]); authenticated by wp175.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1oIOjl-0003nO-Py; Mon, 01 Aug 2022 08:17:09 +0200 Message-ID: Date: Mon, 1 Aug 2022 08:17:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Martin Blumenstingl Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, bert@biot.com, Sander Vanheule From: Birger Koblitz Subject: [PATCH 1/7] spi: realteak-rtl: Add support for RTL93xx SoCs X-bounce-key: webpack.hosteurope.de; mail@birger-koblitz.de; 1659334631; 3eec86fb; X-HE-SMSGID: 1oIOjl-0003nO-Py Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The Realtek RTL930x and RTL931x SoCs are new generations of the RTL838x and RTL839x Ethernet Router SoCs, providing only 2 instead of 4 CS lines for SPI, however with quad IO capabilities instead of merely dual IO. We introduce device capability flags for the various SoCs stating their number of CS lines and their multi-IO capabilities and add compatibles for the RTL9300 and RTL9310 SoC families. Signed-off-by: Birger Koblitz --- drivers/spi/spi-realtek-rtl.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-realtek-rtl.c b/drivers/spi/spi-realtek-rtl.c index 866b0477dbd7..927bd44744a8 100644 --- a/drivers/spi/spi-realtek-rtl.c +++ b/drivers/spi/spi-realtek-rtl.c @@ -29,6 +29,9 @@ struct rtspi { #define REG(x) (rtspi->base + x) +/* SoC-specific features */ +#define SPI_CSMAX_3 0x1 +#define SPI_QUAD_SUPPORTED 0x2 static void rt_set_cs(struct spi_device *spi, bool active) { @@ -185,13 +188,16 @@ static int realtek_rtl_spi_probe(struct platform_device *pdev) static const struct of_device_id realtek_rtl_spi_of_ids[] = { - { .compatible = "realtek,rtl8380-spi" }, - { .compatible = "realtek,rtl8382-spi" }, - { .compatible = "realtek,rtl8391-spi" }, - { .compatible = "realtek,rtl8392-spi" }, - { .compatible = "realtek,rtl8393-spi" }, + { .compatible = "realtek,rtl8380-spi", .data = (void *)SPI_CSMAX_3, }, + { .compatible = "realtek,rtl8382-spi", .data = (void *)SPI_CSMAX_3, }, + { .compatible = "realtek,rtl8391-spi", .data = (void *)SPI_CSMAX_3, }, + { .compatible = "realtek,rtl8392-spi", .data = (void *)SPI_CSMAX_3, }, + { .compatible = "realtek,rtl8393-spi", .data = (void *)SPI_CSMAX_3, }, + { .compatible = "realtek,rtl9300-spi", .data = (void *)SPI_QUAD_SUPPORTED, }, + { .compatible = "realtek,rtl9310-spi", .data = (void *)SPI_QUAD_SUPPORTED, }, { /* sentinel */ } }; + MODULE_DEVICE_TABLE(of, realtek_rtl_spi_of_ids); static struct platform_driver realtek_rtl_spi_driver = { From patchwork Mon Aug 1 06:18:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Birger Koblitz X-Patchwork-Id: 595302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F11CC00144 for ; Mon, 1 Aug 2022 06:18:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239605AbiHAGSO (ORCPT ); Mon, 1 Aug 2022 02:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbiHAGSN (ORCPT ); Mon, 1 Aug 2022 02:18:13 -0400 Received: from wp175.webpack.hosteurope.de (wp175.webpack.hosteurope.de [IPv6:2a01:488:42:1000:50ed:84b6::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EB9FBF7E; Sun, 31 Jul 2022 23:18:11 -0700 (PDT) Received: from p54bc6cd6.dip0.t-ipconnect.de ([84.188.108.214] helo=[192.168.1.113]); authenticated by wp175.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1oIOkk-0004BO-46; Mon, 01 Aug 2022 08:18:10 +0200 Message-ID: <4d10e375-7342-6c1b-9886-e49974b1620b@birger-koblitz.de> Date: Mon, 1 Aug 2022 08:18:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Martin Blumenstingl Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, bert@biot.com, sander@svanheule.net From: Birger Koblitz Subject: [PATCH 2/7] spi: realtek-rtl: set device capability flags X-bounce-key: webpack.hosteurope.de; mail@birger-koblitz.de; 1659334692; cb8995e6; X-HE-SMSGID: 1oIOkk-0004BO-46 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Read out the number of chip selects supported by the SoC and whether the device supports Quad-IO and set the spi_controller flags accordingly. Signed-off-by: Birger Koblitz --- drivers/spi/spi-realtek-rtl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/spi/spi-realtek-rtl.c b/drivers/spi/spi-realtek-rtl.c index 927bd44744a8..287ecc34e1cc 100644 --- a/drivers/spi/spi-realtek-rtl.c +++ b/drivers/spi/spi-realtek-rtl.c @@ -4,9 +4,11 @@ #include #include #include +#include struct rtspi { void __iomem *base; + u32 dev_flags; }; /* SPI Flash Configuration Register */ @@ -163,6 +165,7 @@ static int realtek_rtl_spi_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, ctrl); rtspi = spi_controller_get_devdata(ctrl); + rtspi->dev_flags = (u32) device_get_match_data(&pdev->dev); rtspi->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); if (IS_ERR(rtspi->base)) { @@ -174,8 +177,12 @@ static int realtek_rtl_spi_probe(struct platform_device *pdev) ctrl->dev.of_node = pdev->dev.of_node; ctrl->flags = SPI_CONTROLLER_HALF_DUPLEX; + ctrl->flags |= SPI_TX_DUAL | SPI_RX_DUAL; + if (rtspi->dev_flags & SPI_QUAD_SUPPORTED) + ctrl->flags |= SPI_TX_QUAD | SPI_RX_QUAD; ctrl->set_cs = rt_set_cs; ctrl->transfer_one = transfer_one; + ctrl->num_chipselect = rtspi->dev_flags & SPI_CSMAX_3?4:2; err = devm_spi_register_controller(&pdev->dev, ctrl); if (err) { From patchwork Mon Aug 1 06:32:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Birger Koblitz X-Patchwork-Id: 595299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28399C00144 for ; Mon, 1 Aug 2022 06:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbiHAGc3 (ORCPT ); Mon, 1 Aug 2022 02:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbiHAGc2 (ORCPT ); Mon, 1 Aug 2022 02:32:28 -0400 Received: from wp175.webpack.hosteurope.de (wp175.webpack.hosteurope.de [IPv6:2a01:488:42:1000:50ed:84b6::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7649CE017; Sun, 31 Jul 2022 23:32:27 -0700 (PDT) Received: from p54bc6cd6.dip0.t-ipconnect.de ([84.188.108.214] helo=[192.168.1.113]); authenticated by wp175.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1oIOyX-0003Ki-WD; Mon, 01 Aug 2022 08:32:26 +0200 Message-ID: Date: Mon, 1 Aug 2022 08:32:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Martin Blumenstingl Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, bert@biot.com, sander@svanheule.net From: Birger Koblitz Subject: [PATCH 3/7] spi: realtek-rtl: allow use of chip-select other than CS0 X-bounce-key: webpack.hosteurope.de; mail@birger-koblitz.de; 1659335547; 5dadb7f0; X-HE-SMSGID: 1oIOyX-0003Ki-WD Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The RTL838x and RTL839x SoCs have 4 chip selects, the RTL93xx SoCs 2. Configure the CS for a given transfer. The logic of the RTL_SPI_SFCSR_CSBx bits is that if the value of the bit is 0, then the corresponding CS line is pulled low, which activates/selects the chip. Signed-off-by: Birger Koblitz --- drivers/spi/spi-realtek-rtl.c | 39 ++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/spi/spi-realtek-rtl.c b/drivers/spi/spi-realtek-rtl.c index 287ecc34e1cc..5979233522f4 100644 --- a/drivers/spi/spi-realtek-rtl.c +++ b/drivers/spi/spi-realtek-rtl.c @@ -9,6 +9,7 @@ struct rtspi { void __iomem *base; u32 dev_flags; + u32 cs_all; }; /* SPI Flash Configuration Register */ @@ -20,6 +21,8 @@ struct rtspi { #define RTL_SPI_SFCSR 0x08 #define RTL_SPI_SFCSR_CSB0 BIT(31) #define RTL_SPI_SFCSR_CSB1 BIT(30) +#define RTL_SPI_SFCSR_CSB2 BIT(15) +#define RTL_SPI_SFCSR_CSB3 BIT(14) #define RTL_SPI_SFCSR_RDY BIT(27) #define RTL_SPI_SFCSR_CS BIT(24) #define RTL_SPI_SFCSR_LEN_MASK ~(0x03 << 28) @@ -38,14 +41,34 @@ struct rtspi { static void rt_set_cs(struct spi_device *spi, bool active) { struct rtspi *rtspi = spi_controller_get_devdata(spi->controller); + int cs = spi->chip_select; u32 value; + u32 cs_mask; - /* CS0 bit is active low */ value = readl(REG(RTL_SPI_SFCSR)); + value |= rtspi->cs_all | RTL_SPI_SFCSR_CS; + + switch (cs) { + case 0: + cs_mask = RTL_SPI_SFCSR_CSB0; + break; + case 1: + cs_mask = RTL_SPI_SFCSR_CSB1; + break; + case 2: + cs_mask = RTL_SPI_SFCSR_CSB2; + break; + case 3: + cs_mask = RTL_SPI_SFCSR_CSB3; + break; + } + + /* CS bits are active low */ if (active) - value |= RTL_SPI_SFCSR_CSB0; + value |= cs_mask; else - value &= ~RTL_SPI_SFCSR_CSB0; + value &= ~cs_mask; + writel(value, REG(RTL_SPI_SFCSR)); } @@ -144,11 +167,8 @@ static void init_hw(struct rtspi *rtspi) value |= RTL_SPI_SFCR_RBO | RTL_SPI_SFCR_WBO; writel(value, REG(RTL_SPI_SFCR)); - value = readl(REG(RTL_SPI_SFCSR)); - /* Permanently disable CS1, since it's never used */ - value |= RTL_SPI_SFCSR_CSB1; - /* Select CS0 for use */ - value &= RTL_SPI_SFCSR_CS; + /* Disable CS0-CS3, enable CS */ + value = rtspi->cs_all | RTL_SPI_SFCSR_CS; writel(value, REG(RTL_SPI_SFCSR)); } @@ -183,6 +203,9 @@ static int realtek_rtl_spi_probe(struct platform_device *pdev) ctrl->set_cs = rt_set_cs; ctrl->transfer_one = transfer_one; ctrl->num_chipselect = rtspi->dev_flags & SPI_CSMAX_3?4:2; + rtspi->cs_all = RTL_SPI_SFCSR_CSB0 | RTL_SPI_SFCSR_CSB1; + if (rtspi->dev_flags & SPI_CSMAX_3) + rtspi->cs_all |= RTL_SPI_SFCSR_CSB2 | RTL_SPI_SFCSR_CSB3; err = devm_spi_register_controller(&pdev->dev, ctrl); if (err) { From patchwork Mon Aug 1 06:19:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Birger Koblitz X-Patchwork-Id: 595301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C89C3C00144 for ; Mon, 1 Aug 2022 06:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbiHAGUD (ORCPT ); Mon, 1 Aug 2022 02:20:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239069AbiHAGUC (ORCPT ); Mon, 1 Aug 2022 02:20:02 -0400 Received: from wp175.webpack.hosteurope.de (wp175.webpack.hosteurope.de [IPv6:2a01:488:42:1000:50ed:84b6::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3CA513FA8; Sun, 31 Jul 2022 23:19:59 -0700 (PDT) Received: from p54bc6cd6.dip0.t-ipconnect.de ([84.188.108.214] helo=[192.168.1.113]); authenticated by wp175.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1oIOmU-00051u-26; Mon, 01 Aug 2022 08:19:58 +0200 Message-ID: Date: Mon, 1 Aug 2022 08:19:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Martin Blumenstingl Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, bert@biot.com, sander@svanheule.net From: Birger Koblitz Subject: [PATCH 4/7] spi: realtek-rtl: add parallel IO suppport X-bounce-key: webpack.hosteurope.de; mail@birger-koblitz.de; 1659334800; 60fd91a7; X-HE-SMSGID: 1oIOmU-00051u-26 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The Realtek SoCs are capable of dual and/or quad IO. Add a function to enable this functionality. Signed-off-by: Birger Koblitz --- drivers/spi/spi-realtek-rtl.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/spi/spi-realtek-rtl.c b/drivers/spi/spi-realtek-rtl.c index 5979233522f4..25a90493bf6e 100644 --- a/drivers/spi/spi-realtek-rtl.c +++ b/drivers/spi/spi-realtek-rtl.c @@ -25,6 +25,9 @@ struct rtspi { #define RTL_SPI_SFCSR_CSB3 BIT(14) #define RTL_SPI_SFCSR_RDY BIT(27) #define RTL_SPI_SFCSR_CS BIT(24) +#define RTL_SPI_SFCSR_WIDTH_MASK ~(0x03 << 25) +#define RTL_SPI_SFCSR_WIDTH_DUAL (0x01 << 25) +#define RTL_SPI_SFCSR_WIDTH_QUAD (0x02 << 25) #define RTL_SPI_SFCSR_LEN_MASK ~(0x03 << 28) #define RTL_SPI_SFCSR_LEN1 (0x00 << 28) #define RTL_SPI_SFCSR_LEN4 (0x03 << 28) @@ -118,6 +121,25 @@ static void rcv1(struct rtspi *rtspi, u8 *buf) *buf = readl(REG(RTL_SPI_SFDR)) >> 24; } +static void set_mode(struct rtspi *rtspi, unsigned int mode) +{ + u32 value; + + value = readl(REG(RTL_SPI_SFCSR)); + value &= RTL_SPI_SFCSR_WIDTH_MASK; + switch (mode) { + case SPI_NBITS_QUAD: + value |= RTL_SPI_SFCSR_WIDTH_QUAD; + break; + case SPI_NBITS_DUAL: + value |= RTL_SPI_SFCSR_WIDTH_DUAL; + break; + default: + break; + } + writel(value, REG(RTL_SPI_SFCSR)); +} + static int transfer_one(struct spi_controller *ctrl, struct spi_device *spi, struct spi_transfer *xfer) { From patchwork Mon Aug 1 06:21:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Birger Koblitz X-Patchwork-Id: 594825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A5FEC00144 for ; Mon, 1 Aug 2022 06:21:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239723AbiHAGVE (ORCPT ); Mon, 1 Aug 2022 02:21:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiHAGVD (ORCPT ); Mon, 1 Aug 2022 02:21:03 -0400 Received: from wp175.webpack.hosteurope.de (wp175.webpack.hosteurope.de [IPv6:2a01:488:42:1000:50ed:84b6::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 347351F3; Sun, 31 Jul 2022 23:21:02 -0700 (PDT) Received: from p54bc6cd6.dip0.t-ipconnect.de ([84.188.108.214] helo=[192.168.1.113]); authenticated by wp175.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1oIOnU-0005Ym-Qa; Mon, 01 Aug 2022 08:21:00 +0200 Message-ID: Date: Mon, 1 Aug 2022 08:21:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Martin Blumenstingl Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, bert@biot.com, sander@svanheule.net From: Birger Koblitz Subject: [PATCH 5/7] spi: realtek-rtl: set transfer mode in, transfer_one_message() X-bounce-key: webpack.hosteurope.de; mail@birger-koblitz.de; 1659334862; a63f4424; X-HE-SMSGID: 1oIOnU-0005Ym-Qa Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Refactor the SPI transfer function to allow support for parallel IO. Use transfer_one_message() instead of the generic transfer_one() for the necessary HW control for the transfer. Signed-off-by: Birger Koblitz --- drivers/spi/spi-realtek-rtl.c | 84 ++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/drivers/spi/spi-realtek-rtl.c b/drivers/spi/spi-realtek-rtl.c index 25a90493bf6e..21c0dc16c8cc 100644 --- a/drivers/spi/spi-realtek-rtl.c +++ b/drivers/spi/spi-realtek-rtl.c @@ -140,42 +140,66 @@ static void set_mode(struct rtspi *rtspi, unsigned int mode) writel(value, REG(RTL_SPI_SFCSR)); } -static int transfer_one(struct spi_controller *ctrl, struct spi_device *spi, - struct spi_transfer *xfer) +static void raw_write(struct rtspi *rtspi, const void *tx_buf, int cnt) +{ + while (cnt >= 4) { + send4(rtspi, tx_buf); + tx_buf += 4; + cnt -= 4; + } + while (cnt) { + send1(rtspi, tx_buf); + tx_buf++; + cnt--; + } +} + +static void raw_read(struct rtspi *rtspi, void *rx_buf, int cnt) +{ + while (cnt >= 4) { + rcv4(rtspi, rx_buf); + rx_buf += 4; + cnt -= 4; + } + while (cnt) { + rcv1(rtspi, rx_buf); + rx_buf++; + cnt--; + } +} + +static int transfer_one_message(struct spi_controller *ctrl, struct spi_message *m) { struct rtspi *rtspi = spi_controller_get_devdata(ctrl); - void *rx_buf; - const void *tx_buf; + struct spi_device *spi = m->spi; + struct spi_transfer *xfer = NULL; + int status = 0; int cnt; - tx_buf = xfer->tx_buf; - rx_buf = xfer->rx_buf; - cnt = xfer->len; - if (tx_buf) { - while (cnt >= 4) { - send4(rtspi, tx_buf); - tx_buf += 4; - cnt -= 4; - } - while (cnt) { - send1(rtspi, tx_buf); - tx_buf++; - cnt--; - } - } else if (rx_buf) { - while (cnt >= 4) { - rcv4(rtspi, rx_buf); - rx_buf += 4; - cnt -= 4; - } - while (cnt) { - rcv1(rtspi, rx_buf); - rx_buf++; - cnt--; + wait_ready(rtspi); + + /* Assert CS */ + rt_set_cs(spi, false); + + m->actual_length = 0; + list_for_each_entry(xfer, &m->transfers, transfer_list) { + cnt = xfer->len; + if (xfer->rx_buf) { + set_mode(rtspi, xfer->rx_nbits); + raw_read(rtspi, xfer->rx_buf, cnt); + } else if (xfer->tx_buf) { + set_mode(rtspi, xfer->tx_nbits); + raw_write(rtspi, xfer->tx_buf, cnt); } + m->actual_length += xfer->len; } - spi_finalize_current_transfer(ctrl); + /* Wait until transfer finished and de-assert CS */ + wait_ready(rtspi); + rt_set_cs(spi, true); + + m->status = status; + spi_finalize_current_message(ctrl); return 0; } @@ -223,7 +247,7 @@ static int realtek_rtl_spi_probe(struct platform_device *pdev) if (rtspi->dev_flags & SPI_QUAD_SUPPORTED) ctrl->flags |= SPI_TX_QUAD | SPI_RX_QUAD; ctrl->set_cs = rt_set_cs; - ctrl->transfer_one = transfer_one; + ctrl->transfer_one_message = transfer_one_message; ctrl->num_chipselect = rtspi->dev_flags & SPI_CSMAX_3?4:2; rtspi->cs_all = RTL_SPI_SFCSR_CSB0 | RTL_SPI_SFCSR_CSB1; if (rtspi->dev_flags & SPI_CSMAX_3) From patchwork Mon Aug 1 06:21:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Birger Koblitz X-Patchwork-Id: 595300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61B40C00144 for ; Mon, 1 Aug 2022 06:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238779AbiHAGVv (ORCPT ); Mon, 1 Aug 2022 02:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiHAGVv (ORCPT ); Mon, 1 Aug 2022 02:21:51 -0400 Received: from wp175.webpack.hosteurope.de (wp175.webpack.hosteurope.de [IPv6:2a01:488:42:1000:50ed:84b6::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6813A13FB4; Sun, 31 Jul 2022 23:21:50 -0700 (PDT) Received: from p54bc6cd6.dip0.t-ipconnect.de ([84.188.108.214] helo=[192.168.1.113]); authenticated by wp175.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1oIOoH-0006Bs-11; Mon, 01 Aug 2022 08:21:49 +0200 Message-ID: Date: Mon, 1 Aug 2022 08:21:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Martin Blumenstingl Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, bert@biot.com, sander@svanheule.net From: Birger Koblitz Subject: [PATCH 6/7] spi: realtek-rtl: add support to configure bus speed X-bounce-key: webpack.hosteurope.de; mail@birger-koblitz.de; 1659334910; 3afd5195; X-HE-SMSGID: 1oIOoH-0006Bs-11 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org The available datasheets for the RTL8381M and RTL9301 state that the SPI frequency is 50MHz. Set this maximum spi frequency unless specified otherwise in the device node. The SPI device on the RTL83xx and RTL93xx SoCs is also accessed independently by dedicated SPI-NOR (RTL83xx/RTL93xx) and SPI-NAND (RTL93xx) hardware, which can perform DMA transfers via the SPI device. While these devices can set chip selects, they cannot configure the SPI frequency for a transfer. The clock divider is therefore configured once during device probe and not changed for individual transfers as the SPI frequency is a bus property on this platform. The clock divider setting can take values 0-7, the actual divider then is: clock_divider = 2 * (divider_setting + 1) allowing for clock dividers with values 2-16. The clock used to derive the SPI clock on the Realtek SoCs is the Lexra bus clock. When a clock is provided in the SPI device node, we set a clock divider corresponding to the maximum spi frequency. Signed-off-by: Birger Koblitz --- drivers/spi/spi-realtek-rtl.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-realtek-rtl.c b/drivers/spi/spi-realtek-rtl.c index 21c0dc16c8cc..91aa7a0348a2 100644 --- a/drivers/spi/spi-realtek-rtl.c +++ b/drivers/spi/spi-realtek-rtl.c @@ -5,15 +5,21 @@ #include #include #include +#include +#include struct rtspi { void __iomem *base; u32 dev_flags; u32 cs_all; + struct clk *clk; + int frequency_div; }; /* SPI Flash Configuration Register */ #define RTL_SPI_SFCR 0x00 +#define RTL_SPI_SFCR_CLK_DIV_BIT 29 +#define RTL_SPI_SFCR_CLK_DIV_MASK ~(0x7 << RTL_SPI_SFCR_CLK_DIV_BIT) #define RTL_SPI_SFCR_RBO BIT(28) #define RTL_SPI_SFCR_WBO BIT(27) @@ -208,9 +214,14 @@ static void init_hw(struct rtspi *rtspi) { u32 value; - /* Turn on big-endian byte ordering */ + /* Turn on big-endian byte ordering and set clock divider */ value = readl(REG(RTL_SPI_SFCR)); value |= RTL_SPI_SFCR_RBO | RTL_SPI_SFCR_WBO; + if (rtspi->frequency_div >= 0) { + value &= RTL_SPI_SFCR_CLK_DIV_MASK; + value |= rtspi->frequency_div << RTL_SPI_SFCR_CLK_DIV_BIT; + } + writel(value, REG(RTL_SPI_SFCR)); /* Disable CS0-CS3, enable CS */ @@ -222,6 +233,7 @@ static int realtek_rtl_spi_probe(struct platform_device *pdev) { struct spi_controller *ctrl; struct rtspi *rtspi; + u32 spi_clk; int err; ctrl = devm_spi_alloc_master(&pdev->dev, sizeof(*rtspi)); @@ -239,6 +251,20 @@ static int realtek_rtl_spi_probe(struct platform_device *pdev) return -ENOMEM; } + if (of_property_read_u32(pdev->dev.of_node, "spi-max-frequency", + &ctrl->max_speed_hz)) + ctrl->max_speed_hz = 50000000; /* 50MHz */ + + rtspi->frequency_div = -1; + rtspi->clk = devm_clk_get(&pdev->dev, NULL); + if (!IS_ERR(rtspi->clk)) { + spi_clk = clk_get_rate(rtspi->clk); + rtspi->frequency_div = DIV_ROUND_UP(spi_clk, ctrl->max_speed_hz); + rtspi->frequency_div = (rtspi->frequency_div / 2) - 1; + if (rtspi->frequency_div > 0x7) + rtspi->frequency_div = 0x7; + } + init_hw(rtspi); ctrl->dev.of_node = pdev->dev.of_node; From patchwork Mon Aug 1 06:22:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Birger Koblitz X-Patchwork-Id: 594824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57563C00144 for ; Mon, 1 Aug 2022 06:22:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232878AbiHAGWt (ORCPT ); Mon, 1 Aug 2022 02:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiHAGWs (ORCPT ); Mon, 1 Aug 2022 02:22:48 -0400 Received: from wp175.webpack.hosteurope.de (wp175.webpack.hosteurope.de [IPv6:2a01:488:42:1000:50ed:84b6::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5CD13FB4; Sun, 31 Jul 2022 23:22:47 -0700 (PDT) Received: from p54bc6cd6.dip0.t-ipconnect.de ([84.188.108.214] helo=[192.168.1.113]); authenticated by wp175.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1oIOpB-0006YE-Mj; Mon, 01 Aug 2022 08:22:45 +0200 Message-ID: Date: Mon, 1 Aug 2022 08:22:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Martin Blumenstingl Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, bert@biot.com, sander@svanheule.net From: Birger Koblitz Subject: [PATCH 7/7] spi: realtek-rtl: update devicetree documentation X-bounce-key: webpack.hosteurope.de; mail@birger-koblitz.de; 1659334967; 7b32f370; X-HE-SMSGID: 1oIOpB-0006YE-Mj Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Update documentation to include the optional clocks and spi-max-frequency properties in the devicetree node. Signed-off-by: Birger Koblitz --- .../devicetree/bindings/spi/realtek,rtl-spi.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/realtek,rtl-spi.yaml b/Documentation/devicetree/bindings/spi/realtek,rtl-spi.yaml index 2f938c293f70..e790a85067d3 100644 --- a/Documentation/devicetree/bindings/spi/realtek,rtl-spi.yaml +++ b/Documentation/devicetree/bindings/spi/realtek,rtl-spi.yaml @@ -21,9 +21,17 @@ properties: - realtek,rtl8391-spi - realtek,rtl8392-spi - realtek,rtl8393-spi + - realtek,rtl9300-spi + - realtek,rtl9310-spi reg: maxItems: 1 + + clocks: + maxItems: 1 + + spi-max-frequency: 1 + maxItems: 1 required: - compatible @@ -36,6 +44,8 @@ examples: spi: spi@1200 { compatible = "realtek,rtl8382-spi"; reg = <0x1200 0x100>; + clocks = <&lx_clk> + spi-max-requency = <25000000>; #address-cells = <1>; #size-cells = <0>; };