Skip to content

Commit 6c710c0

Browse files
fancerbroonie
authored andcommitted
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: Georgy Vlasov <[email protected]> Co-developed-by: Ramil Zaripov <[email protected]> Signed-off-by: Georgy Vlasov <[email protected]> Signed-off-by: Ramil Zaripov <[email protected]> Signed-off-by: Serge Semin <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Cc: Alexey Malahov <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Feng Tang <[email protected]> Cc: Rob Herring <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 77ccff8 commit 6c710c0

File tree

5 files changed

+73
-69
lines changed

5 files changed

+73
-69
lines changed

drivers/spi/Kconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ config SPI_DESIGNWARE
226226
help
227227
general driver for SPI controller core from DesignWare
228228

229+
config SPI_DW_DMA
230+
bool "DMA support for DW SPI controller"
231+
depends on SPI_DESIGNWARE && DW_DMAC_PCI
232+
229233
config SPI_DW_PCI
230234
tristate "PCI interface driver for DW SPI core"
231235
depends on SPI_DESIGNWARE && PCI
232236

233-
config SPI_DW_MID_DMA
234-
bool "DMA support for DW SPI controller on Intel MID platform"
235-
depends on SPI_DW_PCI && DW_DMAC_PCI
236-
237237
config SPI_DW_MMIO
238238
tristate "Memory-mapped io interface driver for DW SPI core"
239239
depends on SPI_DESIGNWARE

drivers/spi/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ obj-$(CONFIG_SPI_DAVINCI) += spi-davinci.o
3737
obj-$(CONFIG_SPI_DLN2) += spi-dln2.o
3838
obj-$(CONFIG_SPI_DESIGNWARE) += spi-dw.o
3939
spi-dw-y := spi-dw-core.o
40+
spi-dw-$(CONFIG_SPI_DW_DMA) += spi-dw-dma.o
4041
obj-$(CONFIG_SPI_DW_MMIO) += spi-dw-mmio.o
41-
obj-$(CONFIG_SPI_DW_PCI) += spi-dw-midpci.o
42-
spi-dw-midpci-objs := spi-dw-pci.o spi-dw-mid.o
42+
obj-$(CONFIG_SPI_DW_PCI) += spi-dw-pci.o
4343
obj-$(CONFIG_SPI_EFM32) += spi-efm32.o
4444
obj-$(CONFIG_SPI_EP93XX) += spi-ep93xx.o
4545
obj-$(CONFIG_SPI_FALCON) += spi-falcon.o

drivers/spi/spi-dw-mid.c renamed to drivers/spi/spi-dw-dma.c

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
3-
* Special handling for DW core on Intel MID platform
3+
* Special handling for DW DMA core
44
*
55
* Copyright (c) 2009, 2014 Intel Corporation.
66
*/
77

8-
#include <linux/spi/spi.h>
9-
#include <linux/types.h>
10-
11-
#include "spi-dw.h"
12-
13-
#ifdef CONFIG_SPI_DW_MID_DMA
148
#include <linux/completion.h>
159
#include <linux/dma-mapping.h>
1610
#include <linux/dmaengine.h>
1711
#include <linux/irqreturn.h>
1812
#include <linux/jiffies.h>
1913
#include <linux/pci.h>
2014
#include <linux/platform_data/dma-dw.h>
15+
#include <linux/spi/spi.h>
16+
#include <linux/types.h>
17+
18+
#include "spi-dw.h"
2119

2220
#define WAIT_RETRIES 5
2321
#define RX_BUSY 0
@@ -461,10 +459,11 @@ static const struct dw_spi_dma_ops mfld_dma_ops = {
461459
.dma_stop = mid_spi_dma_stop,
462460
};
463461

464-
static void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws)
462+
void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws)
465463
{
466464
dws->dma_ops = &mfld_dma_ops;
467465
}
466+
EXPORT_SYMBOL_GPL(dw_spi_mid_setup_dma_mfld);
468467

469468
static const struct dw_spi_dma_ops generic_dma_ops = {
470469
.dma_init = mid_spi_dma_init_generic,
@@ -475,55 +474,8 @@ static const struct dw_spi_dma_ops generic_dma_ops = {
475474
.dma_stop = mid_spi_dma_stop,
476475
};
477476

478-
static void dw_spi_mid_setup_dma_generic(struct dw_spi *dws)
477+
void dw_spi_mid_setup_dma_generic(struct dw_spi *dws)
479478
{
480479
dws->dma_ops = &generic_dma_ops;
481480
}
482-
#else /* CONFIG_SPI_DW_MID_DMA */
483-
static inline void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws) {}
484-
static inline void dw_spi_mid_setup_dma_generic(struct dw_spi *dws) {}
485-
#endif
486-
487-
/* Some specific info for SPI0 controller on Intel MID */
488-
489-
/* HW info for MRST Clk Control Unit, 32b reg per controller */
490-
#define MRST_SPI_CLK_BASE 100000000 /* 100m */
491-
#define MRST_CLK_SPI_REG 0xff11d86c
492-
#define CLK_SPI_BDIV_OFFSET 0
493-
#define CLK_SPI_BDIV_MASK 0x00000007
494-
#define CLK_SPI_CDIV_OFFSET 9
495-
#define CLK_SPI_CDIV_MASK 0x00000e00
496-
#define CLK_SPI_DISABLE_OFFSET 8
497-
498-
int dw_spi_mid_init_mfld(struct dw_spi *dws)
499-
{
500-
void __iomem *clk_reg;
501-
u32 clk_cdiv;
502-
503-
clk_reg = ioremap(MRST_CLK_SPI_REG, 16);
504-
if (!clk_reg)
505-
return -ENOMEM;
506-
507-
/* Get SPI controller operating freq info */
508-
clk_cdiv = readl(clk_reg + dws->bus_num * sizeof(u32));
509-
clk_cdiv &= CLK_SPI_CDIV_MASK;
510-
clk_cdiv >>= CLK_SPI_CDIV_OFFSET;
511-
dws->max_freq = MRST_SPI_CLK_BASE / (clk_cdiv + 1);
512-
513-
iounmap(clk_reg);
514-
515-
/* Register hook to configure CTRLR0 */
516-
dws->update_cr0 = dw_spi_update_cr0;
517-
518-
dw_spi_mid_setup_dma_mfld(dws);
519-
return 0;
520-
}
521-
522-
int dw_spi_mid_init_generic(struct dw_spi *dws)
523-
{
524-
/* Register hook to configure CTRLR0 */
525-
dws->update_cr0 = dw_spi_update_cr0;
526-
527-
dw_spi_mid_setup_dma_generic(dws);
528-
return 0;
529-
}
481+
EXPORT_SYMBOL_GPL(dw_spi_mid_setup_dma_generic);

drivers/spi/spi-dw-pci.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,71 @@
1515

1616
#define DRIVER_NAME "dw_spi_pci"
1717

18+
/* HW info for MRST Clk Control Unit, 32b reg per controller */
19+
#define MRST_SPI_CLK_BASE 100000000 /* 100m */
20+
#define MRST_CLK_SPI_REG 0xff11d86c
21+
#define CLK_SPI_BDIV_OFFSET 0
22+
#define CLK_SPI_BDIV_MASK 0x00000007
23+
#define CLK_SPI_CDIV_OFFSET 9
24+
#define CLK_SPI_CDIV_MASK 0x00000e00
25+
#define CLK_SPI_DISABLE_OFFSET 8
26+
1827
struct spi_pci_desc {
1928
int (*setup)(struct dw_spi *);
2029
u16 num_cs;
2130
u16 bus_num;
2231
u32 max_freq;
2332
};
2433

34+
static int spi_mid_init(struct dw_spi *dws)
35+
{
36+
void __iomem *clk_reg;
37+
u32 clk_cdiv;
38+
39+
clk_reg = ioremap(MRST_CLK_SPI_REG, 16);
40+
if (!clk_reg)
41+
return -ENOMEM;
42+
43+
/* Get SPI controller operating freq info */
44+
clk_cdiv = readl(clk_reg + dws->bus_num * sizeof(u32));
45+
clk_cdiv &= CLK_SPI_CDIV_MASK;
46+
clk_cdiv >>= CLK_SPI_CDIV_OFFSET;
47+
dws->max_freq = MRST_SPI_CLK_BASE / (clk_cdiv + 1);
48+
49+
iounmap(clk_reg);
50+
51+
/* Register hook to configure CTRLR0 */
52+
dws->update_cr0 = dw_spi_update_cr0;
53+
54+
dw_spi_mid_setup_dma_mfld(dws);
55+
56+
return 0;
57+
}
58+
59+
static int spi_generic_init(struct dw_spi *dws)
60+
{
61+
/* Register hook to configure CTRLR0 */
62+
dws->update_cr0 = dw_spi_update_cr0;
63+
64+
dw_spi_mid_setup_dma_generic(dws);
65+
66+
return 0;
67+
}
68+
2569
static struct spi_pci_desc spi_pci_mid_desc_1 = {
26-
.setup = dw_spi_mid_init_mfld,
70+
.setup = spi_mid_init,
2771
.num_cs = 5,
2872
.bus_num = 0,
2973
};
3074

3175
static struct spi_pci_desc spi_pci_mid_desc_2 = {
32-
.setup = dw_spi_mid_init_mfld,
76+
.setup = spi_mid_init,
3377
.num_cs = 2,
3478
.bus_num = 1,
3579
};
3680

3781
static struct spi_pci_desc spi_pci_ehl_desc = {
38-
.setup = dw_spi_mid_init_generic,
82+
.setup = spi_generic_init,
3983
.num_cs = 2,
4084
.bus_num = -1,
4185
.max_freq = 100000000,

drivers/spi/spi-dw.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,16 @@ extern u32 dw_spi_update_cr0_v1_01a(struct spi_controller *master,
257257
struct spi_device *spi,
258258
struct spi_transfer *transfer);
259259

260-
/* platform related setup */
261-
extern int dw_spi_mid_init_mfld(struct dw_spi *dws);
262-
extern int dw_spi_mid_init_generic(struct dw_spi *dws);
260+
#ifdef CONFIG_SPI_DW_DMA
261+
262+
extern void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws);
263+
extern void dw_spi_mid_setup_dma_generic(struct dw_spi *dws);
264+
265+
#else
266+
267+
static inline void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws) {}
268+
static inline void dw_spi_mid_setup_dma_generic(struct dw_spi *dws) {}
269+
270+
#endif /* !CONFIG_SPI_DW_DMA */
263271

264272
#endif /* DW_SPI_HEADER_H */

0 commit comments

Comments
 (0)