Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp214665ybm; Thu, 28 May 2020 21:04:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwv5RdySMLb+t/0DkKROa9Dm5kmD3u3rqp9ueIqkf5WKYg/DnBz82vplfhDPLI88NPyn0NI X-Received: by 2002:a17:906:17d1:: with SMTP id u17mr5823749eje.242.1590725083566; Thu, 28 May 2020 21:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590725083; cv=none; d=google.com; s=arc-20160816; b=up2x/wBVkifBuTP3i4ekB56e/TIgcamyBCLvPxXJuULJIXV7ISBeFT7b3aqFaqDQzL XW2Uhk1mDhGAQ8Vo4G092L1bSyV2iDwFlBRrDOw6u6j7Zyvr9jQ0TsqhUfb6w5L03Jjf Ky26wsI9+L+ifHt9T2JoO6LSI+DuMJBmKcaX1dGU2NaVtdvdJHmvi+IIVjOaSU3W3NvH y6DUPG44KRJjYzA1ge7N5NNmOCbA/C1dtiUplRkboCt5mhQ8/ZF94iL4/m9kzhXvfRk6 UXQ6mBfTQ70ZDXymehAClAy1yWaOaj20ylPMywX4QNTUlDRhcJH6Fy6aGmhRaFWmqyOE WKCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Oce6nirb2tX3SMEk258vfybzmUXNod3ZRWDGNyAQPws=; b=Plr9UDcMMwcqMI5ab/c5jKFmdtHfg+YDLR4Tsl8j7AKSCoRja2jdIUSKzswAGPKjLu O7tP+7JC5yIELh6XBJvW5jwbH314zZvYwVG1+nmshZRGPa9mcD4Ve5Dssx6GmMg8ioWx nhG6bjAp2HHBDMaO1isbqoy8GYrRuF8Di7irKiARmVcrYi1bK2S8tKcHq4EayN/+FTlV SKsjLkfgJUaNUyAuVp9wWyTa2RmRBVgHIWTHYvm1CEhMRz8zUWCKIy5a7fdgr+v8rfwb ty6tTXyAgsWsJJnKw+o2kADKNV0HJnelA/hb+eH1rgYrWIlzbJAfJizD+i2ZUn71EcAO LShg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s17si5112480edi.175.2020.05.28.21.04.21; Thu, 28 May 2020 21:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391512AbgE2EAy (ORCPT + 99 others); Fri, 29 May 2020 00:00:54 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:45412 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389387AbgE2D7l (ORCPT ); Thu, 28 May 2020 23:59:41 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id E75D9803078F; Fri, 29 May 2020 03:59:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at baikalelectronics.ru Received: from mail.baikalelectronics.ru ([127.0.0.1]) by localhost (mail.baikalelectronics.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gB-UnZMQ5-tN; Fri, 29 May 2020 06:59:38 +0300 (MSK) From: Serge Semin To: Mark Brown CC: Serge Semin , Serge Semin , Georgy Vlasov , Ramil Zaripov , Andy Shevchenko , Alexey Malahov , Thomas Bogendoerfer , Arnd Bergmann , Feng Tang , Rob Herring , , , , Subject: [PATCH v5 10/16] spi: dw: Move Non-DMA code to the DW PCIe-SPI driver Date: Fri, 29 May 2020 06:59:08 +0300 Message-ID: <20200529035915.20790-11-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20200529035915.20790-1-Sergey.Semin@baikalelectronics.ru> References: <20200529035915.20790-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a preparation patch before adding the DW DMA support into the DW SPI MMIO driver. We need to unpin the Non-DMA-specific code from the intended to be generic DW APB SSI DMA code. This isn't that hard, since the most part of the spi-dw-mid.c driver in fact implements a generic DMA interface for the DW SPI controller driver. The only Intel MID specifics concern getting the max frequency from the MRST Clock Control Unit and fetching the DMA controller channels from corresponding PCIe DMA controller. Since first one is related with the SPI interface configuration we moved it' implementation into the DW PCIe-SPI driver module. After that former spi-dw-mid.c file can be just renamed to be the DW SPI DMA module optionally compiled in to the DW APB SSI core driver. Co-developed-by: Georgy Vlasov Signed-off-by: Georgy Vlasov Co-developed-by: Ramil Zaripov Signed-off-by: Ramil Zaripov Signed-off-by: Serge Semin Reviewed-by: Andy Shevchenko Cc: Alexey Malahov Cc: Thomas Bogendoerfer Cc: Arnd Bergmann Cc: Feng Tang Cc: Rob Herring Cc: linux-mips@vger.kernel.org Cc: devicetree@vger.kernel.org --- Changelog v2: - Compile the DW SPI DMA module into the DW APB SSI core instead of being a separate driver. --- drivers/spi/Kconfig | 8 +-- drivers/spi/Makefile | 4 +- drivers/spi/{spi-dw-mid.c => spi-dw-dma.c} | 66 +++------------------- drivers/spi/spi-dw-pci.c | 50 +++++++++++++++- drivers/spi/spi-dw.h | 14 ++++- 5 files changed, 73 insertions(+), 69 deletions(-) rename drivers/spi/{spi-dw-mid.c => spi-dw-dma.c} (88%) diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 741b9140992a..03b061975f70 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -226,14 +226,14 @@ config SPI_DESIGNWARE help general driver for SPI controller core from DesignWare +config SPI_DW_DMA + bool "DMA support for DW SPI controller" + depends on SPI_DESIGNWARE && DW_DMAC_PCI + config SPI_DW_PCI tristate "PCI interface driver for DW SPI core" depends on SPI_DESIGNWARE && PCI -config SPI_DW_MID_DMA - bool "DMA support for DW SPI controller on Intel MID platform" - depends on SPI_DW_PCI && DW_DMAC_PCI - config SPI_DW_MMIO tristate "Memory-mapped io interface driver for DW SPI core" depends on SPI_DESIGNWARE diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 70ebc2a62e5f..c4aa80085257 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -37,9 +37,9 @@ obj-$(CONFIG_SPI_DAVINCI) += spi-davinci.o obj-$(CONFIG_SPI_DLN2) += spi-dln2.o obj-$(CONFIG_SPI_DESIGNWARE) += spi-dw.o spi-dw-y := spi-dw-core.o +spi-dw-$(CONFIG_SPI_DW_DMA) += spi-dw-dma.o obj-$(CONFIG_SPI_DW_MMIO) += spi-dw-mmio.o -obj-$(CONFIG_SPI_DW_PCI) += spi-dw-midpci.o -spi-dw-midpci-objs := spi-dw-pci.o spi-dw-mid.o +obj-$(CONFIG_SPI_DW_PCI) += spi-dw-pci.o obj-$(CONFIG_SPI_EFM32) += spi-efm32.o obj-$(CONFIG_SPI_EP93XX) += spi-ep93xx.o obj-$(CONFIG_SPI_FALCON) += spi-falcon.o diff --git a/drivers/spi/spi-dw-mid.c b/drivers/spi/spi-dw-dma.c similarity index 88% rename from drivers/spi/spi-dw-mid.c rename to drivers/spi/spi-dw-dma.c index ff79b4239d68..30bd9800f2df 100644 --- a/drivers/spi/spi-dw-mid.c +++ b/drivers/spi/spi-dw-dma.c @@ -1,16 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Special handling for DW core on Intel MID platform + * Special handling for DW DMA core * * Copyright (c) 2009, 2014 Intel Corporation. */ -#include -#include - -#include "spi-dw.h" - -#ifdef CONFIG_SPI_DW_MID_DMA #include #include #include @@ -18,6 +12,10 @@ #include #include #include +#include +#include + +#include "spi-dw.h" #define WAIT_RETRIES 5 #define RX_BUSY 0 @@ -461,10 +459,11 @@ static const struct dw_spi_dma_ops mfld_dma_ops = { .dma_stop = mid_spi_dma_stop, }; -static void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws) +void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws) { dws->dma_ops = &mfld_dma_ops; } +EXPORT_SYMBOL_GPL(dw_spi_mid_setup_dma_mfld); static const struct dw_spi_dma_ops generic_dma_ops = { .dma_init = mid_spi_dma_init_generic, @@ -475,55 +474,8 @@ static const struct dw_spi_dma_ops generic_dma_ops = { .dma_stop = mid_spi_dma_stop, }; -static void dw_spi_mid_setup_dma_generic(struct dw_spi *dws) +void dw_spi_mid_setup_dma_generic(struct dw_spi *dws) { dws->dma_ops = &generic_dma_ops; } -#else /* CONFIG_SPI_DW_MID_DMA */ -static inline void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws) {} -static inline void dw_spi_mid_setup_dma_generic(struct dw_spi *dws) {} -#endif - -/* Some specific info for SPI0 controller on Intel MID */ - -/* HW info for MRST Clk Control Unit, 32b reg per controller */ -#define MRST_SPI_CLK_BASE 100000000 /* 100m */ -#define MRST_CLK_SPI_REG 0xff11d86c -#define CLK_SPI_BDIV_OFFSET 0 -#define CLK_SPI_BDIV_MASK 0x00000007 -#define CLK_SPI_CDIV_OFFSET 9 -#define CLK_SPI_CDIV_MASK 0x00000e00 -#define CLK_SPI_DISABLE_OFFSET 8 - -int dw_spi_mid_init_mfld(struct dw_spi *dws) -{ - void __iomem *clk_reg; - u32 clk_cdiv; - - clk_reg = ioremap(MRST_CLK_SPI_REG, 16); - if (!clk_reg) - return -ENOMEM; - - /* Get SPI controller operating freq info */ - clk_cdiv = readl(clk_reg + dws->bus_num * sizeof(u32)); - clk_cdiv &= CLK_SPI_CDIV_MASK; - clk_cdiv >>= CLK_SPI_CDIV_OFFSET; - dws->max_freq = MRST_SPI_CLK_BASE / (clk_cdiv + 1); - - iounmap(clk_reg); - - /* Register hook to configure CTRLR0 */ - dws->update_cr0 = dw_spi_update_cr0; - - dw_spi_mid_setup_dma_mfld(dws); - return 0; -} - -int dw_spi_mid_init_generic(struct dw_spi *dws) -{ - /* Register hook to configure CTRLR0 */ - dws->update_cr0 = dw_spi_update_cr0; - - dw_spi_mid_setup_dma_generic(dws); - return 0; -} +EXPORT_SYMBOL_GPL(dw_spi_mid_setup_dma_generic); diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c index dde54a918b5d..c13707b8493e 100644 --- a/drivers/spi/spi-dw-pci.c +++ b/drivers/spi/spi-dw-pci.c @@ -15,6 +15,15 @@ #define DRIVER_NAME "dw_spi_pci" +/* HW info for MRST Clk Control Unit, 32b reg per controller */ +#define MRST_SPI_CLK_BASE 100000000 /* 100m */ +#define MRST_CLK_SPI_REG 0xff11d86c +#define CLK_SPI_BDIV_OFFSET 0 +#define CLK_SPI_BDIV_MASK 0x00000007 +#define CLK_SPI_CDIV_OFFSET 9 +#define CLK_SPI_CDIV_MASK 0x00000e00 +#define CLK_SPI_DISABLE_OFFSET 8 + struct spi_pci_desc { int (*setup)(struct dw_spi *); u16 num_cs; @@ -22,20 +31,55 @@ struct spi_pci_desc { u32 max_freq; }; +static int spi_mid_init(struct dw_spi *dws) +{ + void __iomem *clk_reg; + u32 clk_cdiv; + + clk_reg = ioremap(MRST_CLK_SPI_REG, 16); + if (!clk_reg) + return -ENOMEM; + + /* Get SPI controller operating freq info */ + clk_cdiv = readl(clk_reg + dws->bus_num * sizeof(u32)); + clk_cdiv &= CLK_SPI_CDIV_MASK; + clk_cdiv >>= CLK_SPI_CDIV_OFFSET; + dws->max_freq = MRST_SPI_CLK_BASE / (clk_cdiv + 1); + + iounmap(clk_reg); + + /* Register hook to configure CTRLR0 */ + dws->update_cr0 = dw_spi_update_cr0; + + dw_spi_mid_setup_dma_mfld(dws); + + return 0; +} + +static int spi_generic_init(struct dw_spi *dws) +{ + /* Register hook to configure CTRLR0 */ + dws->update_cr0 = dw_spi_update_cr0; + + dw_spi_mid_setup_dma_generic(dws); + + return 0; +} + static struct spi_pci_desc spi_pci_mid_desc_1 = { - .setup = dw_spi_mid_init_mfld, + .setup = spi_mid_init, .num_cs = 5, .bus_num = 0, }; static struct spi_pci_desc spi_pci_mid_desc_2 = { - .setup = dw_spi_mid_init_mfld, + .setup = spi_mid_init, .num_cs = 2, .bus_num = 1, }; static struct spi_pci_desc spi_pci_ehl_desc = { - .setup = dw_spi_mid_init_generic, + .setup = spi_generic_init, .num_cs = 2, .bus_num = -1, .max_freq = 100000000, diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h index 9247670fcdfb..91608cf12636 100644 --- a/drivers/spi/spi-dw.h +++ b/drivers/spi/spi-dw.h @@ -257,8 +257,16 @@ extern u32 dw_spi_update_cr0_v1_01a(struct spi_controller *master, struct spi_device *spi, struct spi_transfer *transfer); -/* platform related setup */ -extern int dw_spi_mid_init_mfld(struct dw_spi *dws); -extern int dw_spi_mid_init_generic(struct dw_spi *dws); +#ifdef CONFIG_SPI_DW_DMA + +extern void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws); +extern void dw_spi_mid_setup_dma_generic(struct dw_spi *dws); + +#else + +static inline void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws) {} +static inline void dw_spi_mid_setup_dma_generic(struct dw_spi *dws) {} + +#endif /* !CONFIG_SPI_DW_DMA */ #endif /* DW_SPI_HEADER_H */ -- 2.26.2