Unverified Commit 6c710c0c authored by Serge Semin's avatar Serge Semin Committed by Mark Brown
Browse files

spi: dw: Move Non-DMA code to the DW PCIe-SPI driver



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: default avatarGeorgy Vlasov <Georgy.Vlasov@baikalelectronics.ru>
Co-developed-by: default avatarRamil Zaripov <Ramil.Zaripov@baikalelectronics.ru>
Signed-off-by: default avatarGeorgy Vlasov <Georgy.Vlasov@baikalelectronics.ru>
Signed-off-by: default avatarRamil Zaripov <Ramil.Zaripov@baikalelectronics.ru>
Signed-off-by: default avatarSerge Semin <Sergey.Semin@baikalelectronics.ru>
Reviewed-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Alexey Malahov <Alexey.Malahov@baikalelectronics.ru>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Feng Tang <feng.tang@intel.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: linux-mips@vger.kernel.org
Cc: devicetree@vger.kernel.org
Link: https://lore.kernel.org/r/20200529131205.31838-11-Sergey.Semin@baikalelectronics.ru


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 77ccff80
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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
+9 −57
Original line number Diff line number Diff line
// 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 <linux/spi/spi.h>
#include <linux/types.h>

#include "spi-dw.h"

#ifdef CONFIG_SPI_DW_MID_DMA
#include <linux/completion.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
@@ -18,6 +12,10 @@
#include <linux/jiffies.h>
#include <linux/pci.h>
#include <linux/platform_data/dma-dw.h>
#include <linux/spi/spi.h>
#include <linux/types.h>

#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);
+47 −3
Original line number Diff line number Diff line
@@ -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,
+11 −3
Original line number Diff line number Diff line
@@ -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 */