Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'spi-v4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi

Pull spi updates from Mark Brown:
"Quite an active release for the SPI subsystem, lots of small updates
and fixes scattered about with highlights including:

- 3-wire support in the GPIO driver.

- support for setting a custom memory name in the memory mapped flash
drivers.

- support for extended mode in the Freescale DSPI controller.

- support for the non-standard integration with the Microsemi Ocelot
platform in the DesignWare driver.

- new driver for the SocioNext UniPhier"

* tag 'spi-v4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (47 commits)
spi: davinci: fix a NULL pointer dereference
spi: spi-mem: Constify spi_mem->name
mtd: m25p80: Call spi_mem_get_name() to let controller set a custom name
spi: spi-mem: Extend the SPI mem interface to set a custom memory name
spi: spi-mem: Fix a typo in the documentation of struct spi_mem
spi: uniphier: remove unnecessary include headers
spi: spi-gpio: add SPI_3WIRE support
spi: add flags parameter to txrx_word function pointers
spi: add SPI controller driver for UniPhier SoC
spi: add DT bindings for UniPhier SPI controller
spi: dw: document Microsemi integration
spi: img-spfi: Set device select bits for SPFI port state
spi: omap2-mcspi: remove several redundant variables
spi: dw-mmio: add MSCC Ocelot support
spi: dw: export dw_spi_set_cs
spi: spi-fsl-espi: Log fifo counters on error
spi: imx: Use the longuest possible burst size when in dynamic_burst
spi: imx: remove unnecessary check in spi_imx_can_dma
spi: imx: Use correct number of bytes per words
spi: imx: Use dynamic bursts only when bits_per_word is 8, 16 or 32
...

+1258 -679
+4 -2
Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.txt
··· 1 1 Synopsys DesignWare AMBA 2.0 Synchronous Serial Interface. 2 2 3 3 Required properties: 4 - - compatible : "snps,dw-apb-ssi" 5 - - reg : The register base for the controller. 4 + - compatible : "snps,dw-apb-ssi" or "mscc,<soc>-spi", where soc is "ocelot" or 5 + "jaguar2" 6 + - reg : The register base for the controller. For "mscc,<soc>-spi", a second 7 + register set is required (named ICPU_CFG:SPI_MST) 6 8 - interrupts : One interrupt, used by the controller. 7 9 - #address-cells : <1>, as required by generic SPI binding. 8 10 - #size-cells : <0>, also as required by generic SPI binding.
+1
Documentation/devicetree/bindings/spi/spi-rockchip.txt
··· 7 7 8 8 - compatible: should be one of the following. 9 9 "rockchip,rv1108-spi" for rv1108 SoCs. 10 + "rockchip,px30-spi", "rockchip,rk3066-spi" for px30 SoCs. 10 11 "rockchip,rk3036-spi" for rk3036 SoCS. 11 12 "rockchip,rk3066-spi" for rk3066 SoCs. 12 13 "rockchip,rk3188-spi" for rk3188 SoCs.
+22
Documentation/devicetree/bindings/spi/spi-uniphier.txt
··· 1 + Socionext UniPhier SPI controller driver 2 + 3 + UniPhier SoCs have SCSSI which supports SPI single channel. 4 + 5 + Required properties: 6 + - compatible: should be "socionext,uniphier-scssi" 7 + - reg: address and length of the spi master registers 8 + - #address-cells: must be <1>, see spi-bus.txt 9 + - #size-cells: must be <0>, see spi-bus.txt 10 + - clocks: A phandle to the clock for the device. 11 + - resets: A phandle to the reset control for the device. 12 + 13 + Example: 14 + 15 + spi0: spi@54006000 { 16 + compatible = "socionext,uniphier-scssi"; 17 + reg = <0x54006000 0x100>; 18 + #address-cells = <1>; 19 + #size-cells = <0>; 20 + clocks = <&peri_clk 11>; 21 + resets = <&peri_rst 11>; 22 + };
+3
drivers/mtd/devices/m25p80.c
··· 199 199 if (data && data->name) 200 200 nor->mtd.name = data->name; 201 201 202 + if (!nor->mtd.name) 203 + nor->mtd.name = spi_mem_get_name(spimem); 204 + 202 205 /* For some (historical?) reason many platforms provide two different 203 206 * names in flash_platform_data: "name" and "type". Quite often name is 204 207 * set to "m25p80" and then "type" provides a real chip name.
+13
drivers/spi/Kconfig
··· 688 688 help 689 689 SPI driver for Toshiba TXx9 MIPS SoCs 690 690 691 + config SPI_UNIPHIER 692 + tristate "Socionext UniPhier SPI Controller" 693 + depends on (ARCH_UNIPHIER || COMPILE_TEST) && OF 694 + help 695 + This enables a driver for the Socionext UniPhier SoC SCSSI SPI controller. 696 + 697 + UniPhier SoCs have SCSSI and MCSSI SPI controllers. 698 + Every UniPhier SoC has SCSSI which supports single channel. 699 + Older UniPhier Pro4/Pro5 also has MCSSI which support multiple channels. 700 + This driver supports SCSSI only. 701 + 702 + If your SoC supports SCSSI, say Y here. 703 + 691 704 config SPI_XCOMM 692 705 tristate "Analog Devices AD-FMCOMMS1-EBZ SPI-I2C-bridge driver" 693 706 depends on I2C
+1
drivers/spi/Makefile
··· 101 101 obj-$(CONFIG_SPI_THUNDERX) += spi-thunderx.o 102 102 obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi-topcliff-pch.o 103 103 obj-$(CONFIG_SPI_TXX9) += spi-txx9.o 104 + obj-$(CONFIG_SPI_UNIPHIER) += spi-uniphier.o 104 105 obj-$(CONFIG_SPI_XCOMM) += spi-xcomm.o 105 106 obj-$(CONFIG_SPI_XILINX) += spi-xilinx.o 106 107 obj-$(CONFIG_SPI_XLP) += spi-xlp.o
+1 -1
drivers/spi/spi-ath79.c
··· 176 176 } 177 177 178 178 static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned int nsecs, 179 - u32 word, u8 bits) 179 + u32 word, u8 bits, unsigned flags) 180 180 { 181 181 struct ath79_spi *sp = ath79_spidev_to_sp(spi); 182 182 u32 ioc = sp->ioc_base;
+37 -13
drivers/spi/spi-bitbang.c
··· 49 49 struct spi_bitbang_cs { 50 50 unsigned nsecs; /* (clock cycle time)/2 */ 51 51 u32 (*txrx_word)(struct spi_device *spi, unsigned nsecs, 52 - u32 word, u8 bits); 52 + u32 word, u8 bits, unsigned flags); 53 53 unsigned (*txrx_bufs)(struct spi_device *, 54 54 u32 (*txrx_word)( 55 55 struct spi_device *spi, 56 56 unsigned nsecs, 57 - u32 word, u8 bits), 58 - unsigned, struct spi_transfer *); 57 + u32 word, u8 bits, 58 + unsigned flags), 59 + unsigned, struct spi_transfer *, 60 + unsigned); 59 61 }; 60 62 61 63 static unsigned bitbang_txrx_8( 62 64 struct spi_device *spi, 63 65 u32 (*txrx_word)(struct spi_device *spi, 64 66 unsigned nsecs, 65 - u32 word, u8 bits), 67 + u32 word, u8 bits, 68 + unsigned flags), 66 69 unsigned ns, 67 - struct spi_transfer *t 70 + struct spi_transfer *t, 71 + unsigned flags 68 72 ) { 69 73 unsigned bits = t->bits_per_word; 70 74 unsigned count = t->len; ··· 80 76 81 77 if (tx) 82 78 word = *tx++; 83 - word = txrx_word(spi, ns, word, bits); 79 + word = txrx_word(spi, ns, word, bits, flags); 84 80 if (rx) 85 81 *rx++ = word; 86 82 count -= 1; ··· 92 88 struct spi_device *spi, 93 89 u32 (*txrx_word)(struct spi_device *spi, 94 90 unsigned nsecs, 95 - u32 word, u8 bits), 91 + u32 word, u8 bits, 92 + unsigned flags), 96 93 unsigned ns, 97 - struct spi_transfer *t 94 + struct spi_transfer *t, 95 + unsigned flags 98 96 ) { 99 97 unsigned bits = t->bits_per_word; 100 98 unsigned count = t->len; ··· 108 102 109 103 if (tx) 110 104 word = *tx++; 111 - word = txrx_word(spi, ns, word, bits); 105 + word = txrx_word(spi, ns, word, bits, flags); 112 106 if (rx) 113 107 *rx++ = word; 114 108 count -= 2; ··· 120 114 struct spi_device *spi, 121 115 u32 (*txrx_word)(struct spi_device *spi, 122 116 unsigned nsecs, 123 - u32 word, u8 bits), 117 + u32 word, u8 bits, 118 + unsigned flags), 124 119 unsigned ns, 125 - struct spi_transfer *t 120 + struct spi_transfer *t, 121 + unsigned flags 126 122 ) { 127 123 unsigned bits = t->bits_per_word; 128 124 unsigned count = t->len; ··· 136 128 137 129 if (tx) 138 130 word = *tx++; 139 - word = txrx_word(spi, ns, word, bits); 131 + word = txrx_word(spi, ns, word, bits, flags); 140 132 if (rx) 141 133 *rx++ = word; 142 134 count -= 4; ··· 243 235 { 244 236 struct spi_bitbang_cs *cs = spi->controller_state; 245 237 unsigned nsecs = cs->nsecs; 238 + struct spi_bitbang *bitbang; 246 239 247 - return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t); 240 + bitbang = spi_master_get_devdata(spi->master); 241 + if (bitbang->set_line_direction) { 242 + int err; 243 + 244 + err = bitbang->set_line_direction(spi, !!(t->tx_buf)); 245 + if (err < 0) 246 + return err; 247 + } 248 + 249 + if (spi->mode & SPI_3WIRE) { 250 + unsigned flags; 251 + 252 + flags = t->tx_buf ? SPI_MASTER_NO_RX : SPI_MASTER_NO_TX; 253 + return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t, flags); 254 + } 255 + return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t, 0); 248 256 } 249 257 250 258 /*----------------------------------------------------------------------*/
+2 -2
drivers/spi/spi-butterfly.c
··· 144 144 145 145 static u32 146 146 butterfly_txrx_word_mode0(struct spi_device *spi, unsigned nsecs, u32 word, 147 - u8 bits) 147 + u8 bits, unsigned flags) 148 148 { 149 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); 149 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); 150 150 } 151 151 152 152 /*----------------------------------------------------------------------*/
+2 -2
drivers/spi/spi-cadence.c
··· 319 319 */ 320 320 if (cdns_spi_read(xspi, CDNS_SPI_ISR) & 321 321 CDNS_SPI_IXR_TXFULL) 322 - usleep_range(10, 20); 322 + udelay(10); 323 323 324 324 if (xspi->txbuf) 325 325 cdns_spi_write(xspi, CDNS_SPI_TXD, *xspi->txbuf++); ··· 739 739 ret = clk_prepare_enable(xspi->ref_clk); 740 740 if (ret) { 741 741 dev_err(dev, "Cannot enable device clock.\n"); 742 - clk_disable(xspi->pclk); 742 + clk_disable_unprepare(xspi->pclk); 743 743 return ret; 744 744 } 745 745 return 0;
+1 -1
drivers/spi/spi-davinci.c
··· 217 217 pdata = &dspi->pdata; 218 218 219 219 /* program delay transfers if tx_delay is non zero */ 220 - if (spicfg->wdelay) 220 + if (spicfg && spicfg->wdelay) 221 221 spidat1 |= SPIDAT1_WDEL; 222 222 223 223 /*
+90
drivers/spi/spi-dw-mmio.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/spi/spi.h> 17 17 #include <linux/scatterlist.h> 18 + #include <linux/mfd/syscon.h> 18 19 #include <linux/module.h> 19 20 #include <linux/of.h> 20 21 #include <linux/of_gpio.h> 21 22 #include <linux/of_platform.h> 22 23 #include <linux/property.h> 24 + #include <linux/regmap.h> 23 25 24 26 #include "spi-dw.h" 25 27 ··· 30 28 struct dw_spi_mmio { 31 29 struct dw_spi dws; 32 30 struct clk *clk; 31 + void *priv; 33 32 }; 33 + 34 + #define MSCC_CPU_SYSTEM_CTRL_GENERAL_CTRL 0x24 35 + #define OCELOT_IF_SI_OWNER_MASK GENMASK(5, 4) 36 + #define OCELOT_IF_SI_OWNER_OFFSET 4 37 + #define MSCC_IF_SI_OWNER_SISL 0 38 + #define MSCC_IF_SI_OWNER_SIBM 1 39 + #define MSCC_IF_SI_OWNER_SIMC 2 40 + 41 + #define MSCC_SPI_MST_SW_MODE 0x14 42 + #define MSCC_SPI_MST_SW_MODE_SW_PIN_CTRL_MODE BIT(13) 43 + #define MSCC_SPI_MST_SW_MODE_SW_SPI_CS(x) (x << 5) 44 + 45 + struct dw_spi_mscc { 46 + struct regmap *syscon; 47 + void __iomem *spi_mst; 48 + }; 49 + 50 + /* 51 + * The Designware SPI controller (referred to as master in the documentation) 52 + * automatically deasserts chip select when the tx fifo is empty. The chip 53 + * selects then needs to be either driven as GPIOs or, for the first 4 using the 54 + * the SPI boot controller registers. the final chip select is an OR gate 55 + * between the Designware SPI controller and the SPI boot controller. 56 + */ 57 + static void dw_spi_mscc_set_cs(struct spi_device *spi, bool enable) 58 + { 59 + struct dw_spi *dws = spi_master_get_devdata(spi->master); 60 + struct dw_spi_mmio *dwsmmio = container_of(dws, struct dw_spi_mmio, dws); 61 + struct dw_spi_mscc *dwsmscc = dwsmmio->priv; 62 + u32 cs = spi->chip_select; 63 + 64 + if (cs < 4) { 65 + u32 sw_mode = MSCC_SPI_MST_SW_MODE_SW_PIN_CTRL_MODE; 66 + 67 + if (!enable) 68 + sw_mode |= MSCC_SPI_MST_SW_MODE_SW_SPI_CS(BIT(cs)); 69 + 70 + writel(sw_mode, dwsmscc->spi_mst + MSCC_SPI_MST_SW_MODE); 71 + } 72 + 73 + dw_spi_set_cs(spi, enable); 74 + } 75 + 76 + static int dw_spi_mscc_init(struct platform_device *pdev, 77 + struct dw_spi_mmio *dwsmmio) 78 + { 79 + struct dw_spi_mscc *dwsmscc; 80 + struct resource *res; 81 + 82 + dwsmscc = devm_kzalloc(&pdev->dev, sizeof(*dwsmscc), GFP_KERNEL); 83 + if (!dwsmscc) 84 + return -ENOMEM; 85 + 86 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 87 + dwsmscc->spi_mst = devm_ioremap_resource(&pdev->dev, res); 88 + if (IS_ERR(dwsmscc->spi_mst)) { 89 + dev_err(&pdev->dev, "SPI_MST region map failed\n"); 90 + return PTR_ERR(dwsmscc->spi_mst); 91 + } 92 + 93 + dwsmscc->syscon = syscon_regmap_lookup_by_compatible("mscc,ocelot-cpu-syscon"); 94 + if (IS_ERR(dwsmscc->syscon)) 95 + return PTR_ERR(dwsmscc->syscon); 96 + 97 + /* Deassert all CS */ 98 + writel(0, dwsmscc->spi_mst + MSCC_SPI_MST_SW_MODE); 99 + 100 + /* Select the owner of the SI interface */ 101 + regmap_update_bits(dwsmscc->syscon, MSCC_CPU_SYSTEM_CTRL_GENERAL_CTRL, 102 + OCELOT_IF_SI_OWNER_MASK, 103 + MSCC_IF_SI_OWNER_SIMC << OCELOT_IF_SI_OWNER_OFFSET); 104 + 105 + dwsmmio->dws.set_cs = dw_spi_mscc_set_cs; 106 + dwsmmio->priv = dwsmscc; 107 + 108 + return 0; 109 + } 34 110 35 111 static int dw_spi_mmio_probe(struct platform_device *pdev) 36 112 { 113 + int (*init_func)(struct platform_device *pdev, 114 + struct dw_spi_mmio *dwsmmio); 37 115 struct dw_spi_mmio *dwsmmio; 38 116 struct dw_spi *dws; 39 117 struct resource *mem; ··· 181 99 } 182 100 } 183 101 102 + init_func = device_get_match_data(&pdev->dev); 103 + if (init_func) { 104 + ret = init_func(pdev, dwsmmio); 105 + if (ret) 106 + goto out; 107 + } 108 + 184 109 ret = dw_spi_add_host(&pdev->dev, dws); 185 110 if (ret) 186 111 goto out; ··· 212 123 213 124 static const struct of_device_id dw_spi_mmio_of_match[] = { 214 125 { .compatible = "snps,dw-apb-ssi", }, 126 + { .compatible = "mscc,ocelot-spi", .data = dw_spi_mscc_init}, 215 127 { /* end of table */} 216 128 }; 217 129 MODULE_DEVICE_TABLE(of, dw_spi_mmio_of_match);
+7 -2
drivers/spi/spi-dw.c
··· 133 133 } 134 134 #endif /* CONFIG_DEBUG_FS */ 135 135 136 - static void dw_spi_set_cs(struct spi_device *spi, bool enable) 136 + void dw_spi_set_cs(struct spi_device *spi, bool enable) 137 137 { 138 138 struct dw_spi *dws = spi_controller_get_devdata(spi->controller); 139 139 struct chip_data *chip = spi_get_ctldata(spi); ··· 145 145 if (!enable) 146 146 dw_writel(dws, DW_SPI_SER, BIT(spi->chip_select)); 147 147 } 148 + EXPORT_SYMBOL_GPL(dw_spi_set_cs); 148 149 149 150 /* Return the max entries we can fill into tx fifo */ 150 151 static inline u32 tx_max(struct dw_spi *dws) ··· 486 485 dws->dma_inited = 0; 487 486 dws->dma_addr = (dma_addr_t)(dws->paddr + DW_SPI_DR); 488 487 488 + spi_controller_set_devdata(master, dws); 489 + 489 490 ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED, dev_name(dev), 490 491 master); 491 492 if (ret < 0) { ··· 508 505 master->dev.of_node = dev->of_node; 509 506 master->flags = SPI_MASTER_GPIO_SS; 510 507 508 + if (dws->set_cs) 509 + master->set_cs = dws->set_cs; 510 + 511 511 /* Basic HW init */ 512 512 spi_hw_init(dev, dws); 513 513 ··· 524 518 } 525 519 } 526 520 527 - spi_controller_set_devdata(master, dws); 528 521 ret = devm_spi_register_controller(dev, master); 529 522 if (ret) { 530 523 dev_err(&master->dev, "problem registering spi master\n");
+2
drivers/spi/spi-dw.h
··· 112 112 u32 reg_io_width; /* DR I/O width in bytes */ 113 113 u16 bus_num; 114 114 u16 num_cs; /* supported slave numbers */ 115 + void (*set_cs)(struct spi_device *spi, bool enable); 115 116 116 117 /* Current message transfer state info */ 117 118 size_t len; ··· 245 244 void (*cs_control)(u32 command); 246 245 }; 247 246 247 + extern void dw_spi_set_cs(struct spi_device *spi, bool enable); 248 248 extern int dw_spi_add_host(struct device *dev, struct dw_spi *dws); 249 249 extern void dw_spi_remove_host(struct dw_spi *dws); 250 250 extern int dw_spi_suspend_host(struct dw_spi *dws);
+276 -239
drivers/spi/spi-fsl-dspi.c
··· 1 - /* 2 - * drivers/spi/spi-fsl-dspi.c 3 - * 4 - * Copyright 2013 Freescale Semiconductor, Inc. 5 - * 6 - * Freescale DSPI driver 7 - * This file contains a driver for the Freescale DSPI 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License as published by 11 - * the Free Software Foundation; either version 2 of the License, or 12 - * (at your option) any later version. 13 - * 14 - */ 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + // 3 + // Copyright 2013 Freescale Semiconductor, Inc. 4 + // 5 + // Freescale DSPI driver 6 + // This file contains a driver for the Freescale DSPI 15 7 16 8 #include <linux/clk.h> 17 9 #include <linux/delay.h> ··· 30 38 31 39 #define DRIVER_NAME "fsl-dspi" 32 40 33 - #define TRAN_STATE_RX_VOID 0x01 34 - #define TRAN_STATE_TX_VOID 0x02 35 - #define TRAN_STATE_WORD_ODD_NUM 0x04 36 - 37 41 #define DSPI_FIFO_SIZE 4 38 42 #define DSPI_DMA_BUFSIZE (DSPI_FIFO_SIZE * 1024) 39 43 ··· 38 50 #define SPI_MCR_PCSIS (0x3F << 16) 39 51 #define SPI_MCR_CLR_TXF (1 << 11) 40 52 #define SPI_MCR_CLR_RXF (1 << 10) 53 + #define SPI_MCR_XSPI (1 << 3) 41 54 42 55 #define SPI_TCR 0x08 43 56 #define SPI_TCR_GET_TCNT(x) (((x) & 0xffff0000) >> 16) ··· 75 86 #define SPI_RSER_TCFQE 0x80000000 76 87 77 88 #define SPI_PUSHR 0x34 78 - #define SPI_PUSHR_CONT (1 << 31) 79 - #define SPI_PUSHR_CTAS(x) (((x) & 0x00000003) << 28) 80 - #define SPI_PUSHR_EOQ (1 << 27) 81 - #define SPI_PUSHR_CTCNT (1 << 26) 82 - #define SPI_PUSHR_PCS(x) (((1 << x) & 0x0000003f) << 16) 89 + #define SPI_PUSHR_CMD_CONT (1 << 15) 90 + #define SPI_PUSHR_CONT (SPI_PUSHR_CMD_CONT << 16) 91 + #define SPI_PUSHR_CMD_CTAS(x) (((x) & 0x0003) << 12) 92 + #define SPI_PUSHR_CTAS(x) (SPI_PUSHR_CMD_CTAS(x) << 16) 93 + #define SPI_PUSHR_CMD_EOQ (1 << 11) 94 + #define SPI_PUSHR_EOQ (SPI_PUSHR_CMD_EOQ << 16) 95 + #define SPI_PUSHR_CMD_CTCNT (1 << 10) 96 + #define SPI_PUSHR_CTCNT (SPI_PUSHR_CMD_CTCNT << 16) 97 + #define SPI_PUSHR_CMD_PCS(x) ((1 << x) & 0x003f) 98 + #define SPI_PUSHR_PCS(x) (SPI_PUSHR_CMD_PCS(x) << 16) 83 99 #define SPI_PUSHR_TXDATA(x) ((x) & 0x0000ffff) 84 100 85 101 #define SPI_PUSHR_SLAVE 0x34 ··· 101 107 #define SPI_RXFR2 0x84 102 108 #define SPI_RXFR3 0x88 103 109 110 + #define SPI_CTARE(x) (0x11c + (((x) & 0x3) * 4)) 111 + #define SPI_CTARE_FMSZE(x) (((x) & 0x1) << 16) 112 + #define SPI_CTARE_DTCP(x) ((x) & 0x7ff) 113 + 114 + #define SPI_SREX 0x13c 115 + 104 116 #define SPI_FRAME_BITS(bits) SPI_CTAR_FMSZ((bits) - 1) 105 117 #define SPI_FRAME_BITS_MASK SPI_CTAR_FMSZ(0xf) 106 118 #define SPI_FRAME_BITS_16 SPI_CTAR_FMSZ(0xf) 107 119 #define SPI_FRAME_BITS_8 SPI_CTAR_FMSZ(0x7) 108 120 121 + #define SPI_FRAME_EBITS(bits) SPI_CTARE_FMSZE(((bits) - 1) >> 4) 122 + #define SPI_FRAME_EBITS_MASK SPI_CTARE_FMSZE(1) 123 + 124 + /* Register offsets for regmap_pushr */ 125 + #define PUSHR_CMD 0x0 126 + #define PUSHR_TX 0x2 127 + 109 128 #define SPI_CS_INIT 0x01 110 129 #define SPI_CS_ASSERT 0x02 111 130 #define SPI_CS_DROP 0x04 112 131 113 - #define SPI_TCR_TCNT_MAX 0x10000 114 - 115 132 #define DMA_COMPLETION_TIMEOUT msecs_to_jiffies(3000) 116 133 117 134 struct chip_data { 118 - u32 mcr_val; 119 135 u32 ctar_val; 120 136 u16 void_write_data; 121 137 }; ··· 139 135 struct fsl_dspi_devtype_data { 140 136 enum dspi_trans_mode trans_mode; 141 137 u8 max_clock_factor; 138 + bool xspi_mode; 142 139 }; 143 140 144 141 static const struct fsl_dspi_devtype_data vf610_data = { ··· 150 145 static const struct fsl_dspi_devtype_data ls1021a_v1_data = { 151 146 .trans_mode = DSPI_TCFQ_MODE, 152 147 .max_clock_factor = 8, 148 + .xspi_mode = true, 153 149 }; 154 150 155 151 static const struct fsl_dspi_devtype_data ls2085a_data = { ··· 185 179 struct platform_device *pdev; 186 180 187 181 struct regmap *regmap; 182 + struct regmap *regmap_pushr; 188 183 int irq; 189 184 struct clk *clk; 190 185 ··· 193 186 struct spi_message *cur_msg; 194 187 struct chip_data *cur_chip; 195 188 size_t len; 196 - void *tx; 197 - void *tx_end; 189 + const void *tx; 198 190 void *rx; 199 191 void *rx_end; 200 - char dataflags; 201 - u8 cs; 202 192 u16 void_write_data; 203 - u32 cs_change; 193 + u16 tx_cmd; 194 + u8 bits_per_word; 195 + u8 bytes_per_word; 204 196 const struct fsl_dspi_devtype_data *devtype_data; 205 197 206 198 wait_queue_head_t waitq; 207 199 u32 waitflags; 208 200 209 - u32 spi_tcnt; 210 201 struct fsl_dspi_dma *dma; 211 202 }; 212 203 213 - static u32 dspi_data_to_pushr(struct fsl_dspi *dspi, int tx_word); 214 - 215 - static inline int is_double_byte_mode(struct fsl_dspi *dspi) 204 + static u32 dspi_pop_tx(struct fsl_dspi *dspi) 216 205 { 217 - unsigned int val; 206 + u32 txdata = 0; 218 207 219 - regmap_read(dspi->regmap, SPI_CTAR(0), &val); 208 + if (dspi->tx) { 209 + if (dspi->bytes_per_word == 1) 210 + txdata = *(u8 *)dspi->tx; 211 + else if (dspi->bytes_per_word == 2) 212 + txdata = *(u16 *)dspi->tx; 213 + else /* dspi->bytes_per_word == 4 */ 214 + txdata = *(u32 *)dspi->tx; 215 + dspi->tx += dspi->bytes_per_word; 216 + } 217 + dspi->len -= dspi->bytes_per_word; 218 + return txdata; 219 + } 220 220 221 - return ((val & SPI_FRAME_BITS_MASK) == SPI_FRAME_BITS(8)) ? 0 : 1; 221 + static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) 222 + { 223 + u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi); 224 + 225 + if (dspi->len > 0) 226 + cmd |= SPI_PUSHR_CMD_CONT; 227 + return cmd << 16 | data; 228 + } 229 + 230 + static void dspi_push_rx(struct fsl_dspi *dspi, u32 rxdata) 231 + { 232 + if (!dspi->rx) 233 + return; 234 + 235 + /* Mask of undefined bits */ 236 + rxdata &= (1 << dspi->bits_per_word) - 1; 237 + 238 + if (dspi->bytes_per_word == 1) 239 + *(u8 *)dspi->rx = rxdata; 240 + else if (dspi->bytes_per_word == 2) 241 + *(u16 *)dspi->rx = rxdata; 242 + else /* dspi->bytes_per_word == 4 */ 243 + *(u32 *)dspi->rx = rxdata; 244 + dspi->rx += dspi->bytes_per_word; 222 245 } 223 246 224 247 static void dspi_tx_dma_callback(void *arg) ··· 263 226 { 264 227 struct fsl_dspi *dspi = arg; 265 228 struct fsl_dspi_dma *dma = dspi->dma; 266 - int rx_word; 267 229 int i; 268 - u16 d; 269 230 270 - rx_word = is_double_byte_mode(dspi); 271 - 272 - if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) { 273 - for (i = 0; i < dma->curr_xfer_len; i++) { 274 - d = dspi->dma->rx_dma_buf[i]; 275 - rx_word ? (*(u16 *)dspi->rx = d) : 276 - (*(u8 *)dspi->rx = d); 277 - dspi->rx += rx_word + 1; 278 - } 231 + if (dspi->rx) { 232 + for (i = 0; i < dma->curr_xfer_len; i++) 233 + dspi_push_rx(dspi, dspi->dma->rx_dma_buf[i]); 279 234 } 280 235 281 236 complete(&dma->cmd_rx_complete); ··· 278 249 struct fsl_dspi_dma *dma = dspi->dma; 279 250 struct device *dev = &dspi->pdev->dev; 280 251 int time_left; 281 - int tx_word; 282 252 int i; 283 253 284 - tx_word = is_double_byte_mode(dspi); 285 - 286 - for (i = 0; i < dma->curr_xfer_len; i++) { 287 - dspi->dma->tx_dma_buf[i] = dspi_data_to_pushr(dspi, tx_word); 288 - if ((dspi->cs_change) && (!dspi->len)) 289 - dspi->dma->tx_dma_buf[i] &= ~SPI_PUSHR_CONT; 290 - } 254 + for (i = 0; i < dma->curr_xfer_len; i++) 255 + dspi->dma->tx_dma_buf[i] = dspi_pop_tx_pushr(dspi); 291 256 292 257 dma->tx_desc = dmaengine_prep_slave_single(dma->chan_tx, 293 258 dma->tx_dma_phys, ··· 350 327 { 351 328 struct fsl_dspi_dma *dma = dspi->dma; 352 329 struct device *dev = &dspi->pdev->dev; 330 + struct spi_message *message = dspi->cur_msg; 353 331 int curr_remaining_bytes; 354 332 int bytes_per_buffer; 355 - int word = 1; 356 333 int ret = 0; 357 334 358 - if (is_double_byte_mode(dspi)) 359 - word = 2; 360 335 curr_remaining_bytes = dspi->len; 361 336 bytes_per_buffer = DSPI_DMA_BUFSIZE / DSPI_FIFO_SIZE; 362 337 while (curr_remaining_bytes) { 363 338 /* Check if current transfer fits the DMA buffer */ 364 - dma->curr_xfer_len = curr_remaining_bytes / word; 339 + dma->curr_xfer_len = curr_remaining_bytes 340 + / dspi->bytes_per_word; 365 341 if (dma->curr_xfer_len > bytes_per_buffer) 366 342 dma->curr_xfer_len = bytes_per_buffer; 367 343 ··· 370 348 goto exit; 371 349 372 350 } else { 373 - curr_remaining_bytes -= dma->curr_xfer_len * word; 351 + const int len = 352 + dma->curr_xfer_len * dspi->bytes_per_word; 353 + curr_remaining_bytes -= len; 354 + message->actual_length += len; 374 355 if (curr_remaining_bytes < 0) 375 356 curr_remaining_bytes = 0; 376 357 } ··· 559 534 } 560 535 } 561 536 562 - static u32 dspi_data_to_pushr(struct fsl_dspi *dspi, int tx_word) 537 + static void fifo_write(struct fsl_dspi *dspi) 563 538 { 564 - u16 d16; 565 - 566 - if (!(dspi->dataflags & TRAN_STATE_TX_VOID)) 567 - d16 = tx_word ? *(u16 *)dspi->tx : *(u8 *)dspi->tx; 568 - else 569 - d16 = dspi->void_write_data; 570 - 571 - dspi->tx += tx_word + 1; 572 - dspi->len -= tx_word + 1; 573 - 574 - return SPI_PUSHR_TXDATA(d16) | 575 - SPI_PUSHR_PCS(dspi->cs) | 576 - SPI_PUSHR_CTAS(0) | 577 - SPI_PUSHR_CONT; 539 + regmap_write(dspi->regmap, SPI_PUSHR, dspi_pop_tx_pushr(dspi)); 578 540 } 579 541 580 - static void dspi_data_from_popr(struct fsl_dspi *dspi, int rx_word) 542 + static void cmd_fifo_write(struct fsl_dspi *dspi) 581 543 { 582 - u16 d; 583 - unsigned int val; 544 + u16 cmd = dspi->tx_cmd; 584 545 585 - regmap_read(dspi->regmap, SPI_POPR, &val); 586 - d = SPI_POPR_RXDATA(val); 587 - 588 - if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) 589 - rx_word ? (*(u16 *)dspi->rx = d) : (*(u8 *)dspi->rx = d); 590 - 591 - dspi->rx += rx_word + 1; 546 + if (dspi->len > 0) 547 + cmd |= SPI_PUSHR_CMD_CONT; 548 + regmap_write(dspi->regmap_pushr, PUSHR_CMD, cmd); 592 549 } 593 550 594 - static int dspi_eoq_write(struct fsl_dspi *dspi) 551 + static void tx_fifo_write(struct fsl_dspi *dspi, u16 txdata) 595 552 { 596 - int tx_count = 0; 597 - int tx_word; 598 - u32 dspi_pushr = 0; 553 + regmap_write(dspi->regmap_pushr, PUSHR_TX, txdata); 554 + } 599 555 600 - tx_word = is_double_byte_mode(dspi); 556 + static void dspi_tcfq_write(struct fsl_dspi *dspi) 557 + { 558 + /* Clear transfer count */ 559 + dspi->tx_cmd |= SPI_PUSHR_CMD_CTCNT; 601 560 602 - while (dspi->len && (tx_count < DSPI_FIFO_SIZE)) { 603 - /* If we are in word mode, only have a single byte to transfer 604 - * switch to byte mode temporarily. Will switch back at the 605 - * end of the transfer. 561 + if (dspi->devtype_data->xspi_mode && dspi->bits_per_word > 16) { 562 + /* Write two TX FIFO entries first, and then the corresponding 563 + * CMD FIFO entry. 606 564 */ 607 - if (tx_word && (dspi->len == 1)) { 608 - dspi->dataflags |= TRAN_STATE_WORD_ODD_NUM; 609 - regmap_update_bits(dspi->regmap, SPI_CTAR(0), 610 - SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(8)); 611 - tx_word = 0; 565 + u32 data = dspi_pop_tx(dspi); 566 + 567 + if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE(1)) { 568 + /* LSB */ 569 + tx_fifo_write(dspi, data & 0xFFFF); 570 + tx_fifo_write(dspi, data >> 16); 571 + } else { 572 + /* MSB */ 573 + tx_fifo_write(dspi, data >> 16); 574 + tx_fifo_write(dspi, data & 0xFFFF); 612 575 } 613 - 614 - dspi_pushr = dspi_data_to_pushr(dspi, tx_word); 615 - 616 - if (dspi->len == 0 || tx_count == DSPI_FIFO_SIZE - 1) { 617 - /* last transfer in the transfer */ 618 - dspi_pushr |= SPI_PUSHR_EOQ; 619 - if ((dspi->cs_change) && (!dspi->len)) 620 - dspi_pushr &= ~SPI_PUSHR_CONT; 621 - } else if (tx_word && (dspi->len == 1)) 622 - dspi_pushr |= SPI_PUSHR_EOQ; 623 - 624 - regmap_write(dspi->regmap, SPI_PUSHR, dspi_pushr); 625 - 626 - tx_count++; 576 + cmd_fifo_write(dspi); 577 + } else { 578 + /* Write one entry to both TX FIFO and CMD FIFO 579 + * simultaneously. 580 + */ 581 + fifo_write(dspi); 627 582 } 628 - 629 - return tx_count * (tx_word + 1); 630 583 } 631 584 632 - static int dspi_eoq_read(struct fsl_dspi *dspi) 585 + static u32 fifo_read(struct fsl_dspi *dspi) 633 586 { 634 - int rx_count = 0; 635 - int rx_word = is_double_byte_mode(dspi); 587 + u32 rxdata = 0; 636 588 637 - while ((dspi->rx < dspi->rx_end) 638 - && (rx_count < DSPI_FIFO_SIZE)) { 639 - if (rx_word && (dspi->rx_end - dspi->rx) == 1) 640 - rx_word = 0; 641 - 642 - dspi_data_from_popr(dspi, rx_word); 643 - rx_count++; 644 - } 645 - 646 - return rx_count; 647 - } 648 - 649 - static int dspi_tcfq_write(struct fsl_dspi *dspi) 650 - { 651 - int tx_word; 652 - u32 dspi_pushr = 0; 653 - 654 - tx_word = is_double_byte_mode(dspi); 655 - 656 - if (tx_word && (dspi->len == 1)) { 657 - dspi->dataflags |= TRAN_STATE_WORD_ODD_NUM; 658 - regmap_update_bits(dspi->regmap, SPI_CTAR(0), 659 - SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(8)); 660 - tx_word = 0; 661 - } 662 - 663 - dspi_pushr = dspi_data_to_pushr(dspi, tx_word); 664 - 665 - if ((dspi->cs_change) && (!dspi->len)) 666 - dspi_pushr &= ~SPI_PUSHR_CONT; 667 - 668 - regmap_write(dspi->regmap, SPI_PUSHR, dspi_pushr); 669 - 670 - return tx_word + 1; 589 + regmap_read(dspi->regmap, SPI_POPR, &rxdata); 590 + return rxdata; 671 591 } 672 592 673 593 static void dspi_tcfq_read(struct fsl_dspi *dspi) 674 594 { 675 - int rx_word = is_double_byte_mode(dspi); 595 + dspi_push_rx(dspi, fifo_read(dspi)); 596 + } 676 597 677 - if (rx_word && (dspi->rx_end - dspi->rx) == 1) 678 - rx_word = 0; 598 + static void dspi_eoq_write(struct fsl_dspi *dspi) 599 + { 600 + int fifo_size = DSPI_FIFO_SIZE; 679 601 680 - dspi_data_from_popr(dspi, rx_word); 602 + /* Fill TX FIFO with as many transfers as possible */ 603 + while (dspi->len && fifo_size--) { 604 + /* Request EOQF for last transfer in FIFO */ 605 + if (dspi->len == dspi->bytes_per_word || fifo_size == 0) 606 + dspi->tx_cmd |= SPI_PUSHR_CMD_EOQ; 607 + /* Clear transfer count for first transfer in FIFO */ 608 + if (fifo_size == (DSPI_FIFO_SIZE - 1)) 609 + dspi->tx_cmd |= SPI_PUSHR_CMD_CTCNT; 610 + /* Write combined TX FIFO and CMD FIFO entry */ 611 + fifo_write(dspi); 612 + } 613 + } 614 + 615 + static void dspi_eoq_read(struct fsl_dspi *dspi) 616 + { 617 + int fifo_size = DSPI_FIFO_SIZE; 618 + 619 + /* Read one FIFO entry at and push to rx buffer */ 620 + while ((dspi->rx < dspi->rx_end) && fifo_size--) 621 + dspi_push_rx(dspi, fifo_read(dspi)); 681 622 } 682 623 683 624 static int dspi_transfer_one_message(struct spi_master *master, ··· 654 663 struct spi_transfer *transfer; 655 664 int status = 0; 656 665 enum dspi_trans_mode trans_mode; 657 - u32 spi_tcr; 658 - 659 - regmap_read(dspi->regmap, SPI_TCR, &spi_tcr); 660 - dspi->spi_tcnt = SPI_TCR_GET_TCNT(spi_tcr); 661 666 662 667 message->actual_length = 0; 663 668 ··· 661 674 dspi->cur_transfer = transfer; 662 675 dspi->cur_msg = message; 663 676 dspi->cur_chip = spi_get_ctldata(spi); 664 - dspi->cs = spi->chip_select; 665 - dspi->cs_change = 0; 677 + /* Prepare command word for CMD FIFO */ 678 + dspi->tx_cmd = SPI_PUSHR_CMD_CTAS(0) | 679 + SPI_PUSHR_CMD_PCS(spi->chip_select); 666 680 if (list_is_last(&dspi->cur_transfer->transfer_list, 667 - &dspi->cur_msg->transfers) || transfer->cs_change) 668 - dspi->cs_change = 1; 681 + &dspi->cur_msg->transfers)) { 682 + /* Leave PCS activated after last transfer when 683 + * cs_change is set. 684 + */ 685 + if (transfer->cs_change) 686 + dspi->tx_cmd |= SPI_PUSHR_CMD_CONT; 687 + } else { 688 + /* Keep PCS active between transfers in same message 689 + * when cs_change is not set, and de-activate PCS 690 + * between transfers in the same message when 691 + * cs_change is set. 692 + */ 693 + if (!transfer->cs_change) 694 + dspi->tx_cmd |= SPI_PUSHR_CMD_CONT; 695 + } 696 + 669 697 dspi->void_write_data = dspi->cur_chip->void_write_data; 670 698 671 - dspi->dataflags = 0; 672 - dspi->tx = (void *)transfer->tx_buf; 673 - dspi->tx_end = dspi->tx + transfer->len; 699 + dspi->tx = transfer->tx_buf; 674 700 dspi->rx = transfer->rx_buf; 675 701 dspi->rx_end = dspi->rx + transfer->len; 676 702 dspi->len = transfer->len; 703 + /* Validated transfer specific frame size (defaults applied) */ 704 + dspi->bits_per_word = transfer->bits_per_word; 705 + if (transfer->bits_per_word <= 8) 706 + dspi->bytes_per_word = 1; 707 + else if (transfer->bits_per_word <= 16) 708 + dspi->bytes_per_word = 2; 709 + else 710 + dspi->bytes_per_word = 4; 677 711 678 - if (!dspi->rx) 679 - dspi->dataflags |= TRAN_STATE_RX_VOID; 680 - 681 - if (!dspi->tx) 682 - dspi->dataflags |= TRAN_STATE_TX_VOID; 683 - 684 - regmap_write(dspi->regmap, SPI_MCR, dspi->cur_chip->mcr_val); 685 712 regmap_update_bits(dspi->regmap, SPI_MCR, 686 - SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF, 687 - SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF); 713 + SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF, 714 + SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF); 688 715 regmap_write(dspi->regmap, SPI_CTAR(0), 689 - dspi->cur_chip->ctar_val); 716 + dspi->cur_chip->ctar_val | 717 + SPI_FRAME_BITS(transfer->bits_per_word)); 718 + if (dspi->devtype_data->xspi_mode) 719 + regmap_write(dspi->regmap, SPI_CTARE(0), 720 + SPI_FRAME_EBITS(transfer->bits_per_word) 721 + | SPI_CTARE_DTCP(1)); 690 722 691 723 trans_mode = dspi->devtype_data->trans_mode; 692 724 switch (trans_mode) { ··· 756 750 struct fsl_dspi_platform_data *pdata; 757 751 u32 cs_sck_delay = 0, sck_cs_delay = 0; 758 752 unsigned char br = 0, pbr = 0, pcssck = 0, cssck = 0; 759 - unsigned char pasc = 0, asc = 0, fmsz = 0; 753 + unsigned char pasc = 0, asc = 0; 760 754 unsigned long clkrate; 761 - 762 - if ((spi->bits_per_word >= 4) && (spi->bits_per_word <= 16)) { 763 - fmsz = spi->bits_per_word - 1; 764 - } else { 765 - pr_err("Invalid wordsize\n"); 766 - return -ENODEV; 767 - } 768 755 769 756 /* Only alloc on first setup */ 770 757 chip = spi_get_ctldata(spi); ··· 780 781 sck_cs_delay = pdata->sck_cs_delay; 781 782 } 782 783 783 - chip->mcr_val = SPI_MCR_MASTER | SPI_MCR_PCSIS | 784 - SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF; 785 - 786 784 chip->void_write_data = 0; 787 785 788 786 clkrate = clk_get_rate(dspi->clk); ··· 791 795 /* Set After SCK delay scale values */ 792 796 ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate); 793 797 794 - chip->ctar_val = SPI_CTAR_FMSZ(fmsz) 795 - | SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0) 798 + chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0) 796 799 | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0) 797 800 | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0) 798 801 | SPI_CTAR_PCSSCK(pcssck) ··· 822 827 struct spi_message *msg = dspi->cur_msg; 823 828 enum dspi_trans_mode trans_mode; 824 829 u32 spi_sr, spi_tcr; 825 - u32 spi_tcnt, tcnt_diff; 826 - int tx_word; 830 + u16 spi_tcnt; 827 831 828 832 regmap_read(dspi->regmap, SPI_SR, &spi_sr); 829 833 regmap_write(dspi->regmap, SPI_SR, spi_sr); 830 834 831 835 832 836 if (spi_sr & (SPI_SR_EOQF | SPI_SR_TCFQF)) { 833 - tx_word = is_double_byte_mode(dspi); 834 - 837 + /* Get transfer counter (in number of SPI transfers). It was 838 + * reset to 0 when transfer(s) were started. 839 + */ 835 840 regmap_read(dspi->regmap, SPI_TCR, &spi_tcr); 836 841 spi_tcnt = SPI_TCR_GET_TCNT(spi_tcr); 837 - /* 838 - * The width of SPI Transfer Counter in SPI_TCR is 16bits, 839 - * so the max couner is 65535. When the counter reach 65535, 840 - * it will wrap around, counter reset to zero. 841 - * spi_tcnt my be less than dspi->spi_tcnt, it means the 842 - * counter already wrapped around. 843 - * SPI Transfer Counter is a counter of transmitted frames. 844 - * The size of frame maybe two bytes. 845 - */ 846 - tcnt_diff = ((spi_tcnt + SPI_TCR_TCNT_MAX) - dspi->spi_tcnt) 847 - % SPI_TCR_TCNT_MAX; 848 - tcnt_diff *= (tx_word + 1); 849 - if (dspi->dataflags & TRAN_STATE_WORD_ODD_NUM) 850 - tcnt_diff--; 851 - 852 - msg->actual_length += tcnt_diff; 853 - 854 - dspi->spi_tcnt = spi_tcnt; 842 + /* Update total number of bytes that were transferred */ 843 + msg->actual_length += spi_tcnt * dspi->bytes_per_word; 855 844 856 845 trans_mode = dspi->devtype_data->trans_mode; 857 846 switch (trans_mode) { ··· 852 873 } 853 874 854 875 if (!dspi->len) { 855 - if (dspi->dataflags & TRAN_STATE_WORD_ODD_NUM) { 856 - regmap_update_bits(dspi->regmap, 857 - SPI_CTAR(0), 858 - SPI_FRAME_BITS_MASK, 859 - SPI_FRAME_BITS(16)); 860 - dspi->dataflags &= ~TRAN_STATE_WORD_ODD_NUM; 861 - } 862 - 863 876 dspi->waitflags = 1; 864 877 wake_up_interruptible(&dspi->waitq); 865 878 } else { ··· 914 943 915 944 static SIMPLE_DEV_PM_OPS(dspi_pm, dspi_suspend, dspi_resume); 916 945 946 + static const struct regmap_range dspi_volatile_ranges[] = { 947 + regmap_reg_range(SPI_MCR, SPI_TCR), 948 + regmap_reg_range(SPI_SR, SPI_SR), 949 + regmap_reg_range(SPI_PUSHR, SPI_RXFR3), 950 + }; 951 + 952 + static const struct regmap_access_table dspi_volatile_table = { 953 + .yes_ranges = dspi_volatile_ranges, 954 + .n_yes_ranges = ARRAY_SIZE(dspi_volatile_ranges), 955 + }; 956 + 917 957 static const struct regmap_config dspi_regmap_config = { 918 958 .reg_bits = 32, 919 959 .val_bits = 32, 920 960 .reg_stride = 4, 921 961 .max_register = 0x88, 962 + .volatile_table = &dspi_volatile_table, 963 + }; 964 + 965 + static const struct regmap_range dspi_xspi_volatile_ranges[] = { 966 + regmap_reg_range(SPI_MCR, SPI_TCR), 967 + regmap_reg_range(SPI_SR, SPI_SR), 968 + regmap_reg_range(SPI_PUSHR, SPI_RXFR3), 969 + regmap_reg_range(SPI_SREX, SPI_SREX), 970 + }; 971 + 972 + static const struct regmap_access_table dspi_xspi_volatile_table = { 973 + .yes_ranges = dspi_xspi_volatile_ranges, 974 + .n_yes_ranges = ARRAY_SIZE(dspi_xspi_volatile_ranges), 975 + }; 976 + 977 + static const struct regmap_config dspi_xspi_regmap_config[] = { 978 + { 979 + .reg_bits = 32, 980 + .val_bits = 32, 981 + .reg_stride = 4, 982 + .max_register = 0x13c, 983 + .volatile_table = &dspi_xspi_volatile_table, 984 + }, 985 + { 986 + .name = "pushr", 987 + .reg_bits = 16, 988 + .val_bits = 16, 989 + .reg_stride = 2, 990 + .max_register = 0x2, 991 + }, 922 992 }; 923 993 924 994 static void dspi_init(struct fsl_dspi *dspi) 925 995 { 996 + regmap_write(dspi->regmap, SPI_MCR, SPI_MCR_MASTER | SPI_MCR_PCSIS | 997 + (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0)); 926 998 regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR); 999 + if (dspi->devtype_data->xspi_mode) 1000 + regmap_write(dspi->regmap, SPI_CTARE(0), 1001 + SPI_CTARE_FMSZE(0) | SPI_CTARE_DTCP(1)); 927 1002 } 928 1003 929 1004 static int dspi_probe(struct platform_device *pdev) ··· 978 961 struct spi_master *master; 979 962 struct fsl_dspi *dspi; 980 963 struct resource *res; 964 + const struct regmap_config *regmap_config; 981 965 void __iomem *base; 982 966 struct fsl_dspi_platform_data *pdata; 983 967 int ret = 0, cs_num, bus_num; ··· 998 980 999 981 master->cleanup = dspi_cleanup; 1000 982 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; 1001 - master->bits_per_word_mask = SPI_BPW_MASK(4) | SPI_BPW_MASK(8) | 1002 - SPI_BPW_MASK(16); 1003 983 1004 984 pdata = dev_get_platdata(&pdev->dev); 1005 985 if (pdata) { ··· 1029 1013 } 1030 1014 } 1031 1015 1016 + if (dspi->devtype_data->xspi_mode) 1017 + master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); 1018 + else 1019 + master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); 1020 + 1032 1021 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1033 1022 base = devm_ioremap_resource(&pdev->dev, res); 1034 1023 if (IS_ERR(base)) { ··· 1041 1020 goto out_master_put; 1042 1021 } 1043 1022 1044 - dspi->regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base, 1045 - &dspi_regmap_config); 1023 + if (dspi->devtype_data->xspi_mode) 1024 + regmap_config = &dspi_xspi_regmap_config[0]; 1025 + else 1026 + regmap_config = &dspi_regmap_config; 1027 + dspi->regmap = devm_regmap_init_mmio(&pdev->dev, base, regmap_config); 1046 1028 if (IS_ERR(dspi->regmap)) { 1047 1029 dev_err(&pdev->dev, "failed to init regmap: %ld\n", 1048 1030 PTR_ERR(dspi->regmap)); ··· 1053 1029 goto out_master_put; 1054 1030 } 1055 1031 1056 - dspi_init(dspi); 1057 - dspi->irq = platform_get_irq(pdev, 0); 1058 - if (dspi->irq < 0) { 1059 - dev_err(&pdev->dev, "can't get platform irq\n"); 1060 - ret = dspi->irq; 1061 - goto out_master_put; 1062 - } 1063 - 1064 - ret = devm_request_irq(&pdev->dev, dspi->irq, dspi_interrupt, 0, 1065 - pdev->name, dspi); 1066 - if (ret < 0) { 1067 - dev_err(&pdev->dev, "Unable to attach DSPI interrupt\n"); 1068 - goto out_master_put; 1032 + if (dspi->devtype_data->xspi_mode) { 1033 + dspi->regmap_pushr = devm_regmap_init_mmio( 1034 + &pdev->dev, base + SPI_PUSHR, 1035 + &dspi_xspi_regmap_config[1]); 1036 + if (IS_ERR(dspi->regmap_pushr)) { 1037 + dev_err(&pdev->dev, 1038 + "failed to init pushr regmap: %ld\n", 1039 + PTR_ERR(dspi->regmap_pushr)); 1040 + ret = PTR_ERR(dspi->regmap_pushr); 1041 + goto out_master_put; 1042 + } 1069 1043 } 1070 1044 1071 1045 dspi->clk = devm_clk_get(&pdev->dev, "dspi"); ··· 1075 1053 ret = clk_prepare_enable(dspi->clk); 1076 1054 if (ret) 1077 1055 goto out_master_put; 1056 + 1057 + dspi_init(dspi); 1058 + dspi->irq = platform_get_irq(pdev, 0); 1059 + if (dspi->irq < 0) { 1060 + dev_err(&pdev->dev, "can't get platform irq\n"); 1061 + ret = dspi->irq; 1062 + goto out_clk_put; 1063 + } 1064 + 1065 + ret = devm_request_irq(&pdev->dev, dspi->irq, dspi_interrupt, 0, 1066 + pdev->name, dspi); 1067 + if (ret < 0) { 1068 + dev_err(&pdev->dev, "Unable to attach DSPI interrupt\n"); 1069 + goto out_clk_put; 1070 + } 1078 1071 1079 1072 if (dspi->devtype_data->trans_mode == DSPI_DMA_MODE) { 1080 1073 ret = dspi_request_dma(dspi, res->start);
+4 -1
drivers/spi/spi-fsl-espi.c
··· 547 547 dev_err(espi->dev, 548 548 "Transfer done but SPIE_DON isn't set!\n"); 549 549 550 - if (SPIE_RXCNT(events) || SPIE_TXCNT(events) != FSL_ESPI_FIFO_SIZE) 550 + if (SPIE_RXCNT(events) || SPIE_TXCNT(events) != FSL_ESPI_FIFO_SIZE) { 551 551 dev_err(espi->dev, "Transfer done but rx/tx fifo's aren't empty!\n"); 552 + dev_err(espi->dev, "SPIE_RXCNT = %d, SPIE_TXCNT = %d\n", 553 + SPIE_RXCNT(events), SPIE_TXCNT(events)); 554 + } 552 555 553 556 complete(&espi->done); 554 557 }
+32 -17
drivers/spi/spi-gpio.c
··· 121 121 { 122 122 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 123 123 124 - return !!gpiod_get_value_cansleep(spi_gpio->miso); 124 + if (spi->mode & SPI_3WIRE) 125 + return !!gpiod_get_value_cansleep(spi_gpio->mosi); 126 + else 127 + return !!gpiod_get_value_cansleep(spi_gpio->miso); 125 128 } 126 129 127 130 /* ··· 152 149 */ 153 150 154 151 static u32 spi_gpio_txrx_word_mode0(struct spi_device *spi, 155 - unsigned nsecs, u32 word, u8 bits) 152 + unsigned nsecs, u32 word, u8 bits, unsigned flags) 156 153 { 157 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); 154 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); 158 155 } 159 156 160 157 static u32 spi_gpio_txrx_word_mode1(struct spi_device *spi, 161 - unsigned nsecs, u32 word, u8 bits) 158 + unsigned nsecs, u32 word, u8 bits, unsigned flags) 162 159 { 163 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); 160 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); 164 161 } 165 162 166 163 static u32 spi_gpio_txrx_word_mode2(struct spi_device *spi, 167 - unsigned nsecs, u32 word, u8 bits) 164 + unsigned nsecs, u32 word, u8 bits, unsigned flags) 168 165 { 169 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); 166 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); 170 167 } 171 168 172 169 static u32 spi_gpio_txrx_word_mode3(struct spi_device *spi, 173 - unsigned nsecs, u32 word, u8 bits) 170 + unsigned nsecs, u32 word, u8 bits, unsigned flags) 174 171 { 175 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); 172 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); 176 173 } 177 174 178 175 /* ··· 186 183 */ 187 184 188 185 static u32 spi_gpio_spec_txrx_word_mode0(struct spi_device *spi, 189 - unsigned nsecs, u32 word, u8 bits) 186 + unsigned nsecs, u32 word, u8 bits, unsigned flags) 190 187 { 191 - unsigned flags = spi->master->flags; 188 + flags = spi->master->flags; 192 189 return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); 193 190 } 194 191 195 192 static u32 spi_gpio_spec_txrx_word_mode1(struct spi_device *spi, 196 - unsigned nsecs, u32 word, u8 bits) 193 + unsigned nsecs, u32 word, u8 bits, unsigned flags) 197 194 { 198 - unsigned flags = spi->master->flags; 195 + flags = spi->master->flags; 199 196 return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); 200 197 } 201 198 202 199 static u32 spi_gpio_spec_txrx_word_mode2(struct spi_device *spi, 203 - unsigned nsecs, u32 word, u8 bits) 200 + unsigned nsecs, u32 word, u8 bits, unsigned flags) 204 201 { 205 - unsigned flags = spi->master->flags; 202 + flags = spi->master->flags; 206 203 return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); 207 204 } 208 205 209 206 static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, 210 - unsigned nsecs, u32 word, u8 bits) 207 + unsigned nsecs, u32 word, u8 bits, unsigned flags) 211 208 { 212 - unsigned flags = spi->master->flags; 209 + flags = spi->master->flags; 213 210 return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); 214 211 } 215 212 ··· 251 248 status = spi_bitbang_setup(spi); 252 249 253 250 return status; 251 + } 252 + 253 + static int spi_gpio_set_direction(struct spi_device *spi, bool output) 254 + { 255 + struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 256 + 257 + if (output) 258 + return gpiod_direction_output(spi_gpio->mosi, 1); 259 + else 260 + return gpiod_direction_input(spi_gpio->mosi); 254 261 } 255 262 256 263 static void spi_gpio_cleanup(struct spi_device *spi) ··· 408 395 return status; 409 396 410 397 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); 398 + master->mode_bits = SPI_3WIRE | SPI_CPHA | SPI_CPOL; 411 399 master->flags = master_flags; 412 400 master->bus_num = pdev->id; 413 401 /* The master needs to think there is a chipselect even if not connected */ ··· 421 407 422 408 spi_gpio->bitbang.master = master; 423 409 spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 410 + spi_gpio->bitbang.set_line_direction = spi_gpio_set_direction; 424 411 425 412 if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) { 426 413 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0;
+3
drivers/spi/spi-img-spfi.c
··· 419 419 u32 val; 420 420 421 421 val = spfi_readl(spfi, SPFI_PORT_STATE); 422 + val &= ~(SPFI_PORT_STATE_DEV_SEL_MASK << 423 + SPFI_PORT_STATE_DEV_SEL_SHIFT); 424 + val |= msg->spi->chip_select << SPFI_PORT_STATE_DEV_SEL_SHIFT; 422 425 if (msg->spi->mode & SPI_CPHA) 423 426 val |= SPFI_PORT_STATE_CK_PHASE(msg->spi->chip_select); 424 427 else
+101 -61
drivers/spi/spi-imx.c
··· 94 94 void *rx_buf; 95 95 const void *tx_buf; 96 96 unsigned int txfifo; /* number of words pushed in tx FIFO */ 97 - unsigned int dynamic_burst, read_u32; 98 - unsigned int word_mask; 97 + unsigned int dynamic_burst; 99 98 100 99 /* Slave mode */ 101 100 bool slave_mode; ··· 139 140 *(type *)spi_imx->rx_buf = val; \ 140 141 spi_imx->rx_buf += sizeof(type); \ 141 142 } \ 143 + \ 144 + spi_imx->remainder -= sizeof(type); \ 142 145 } 143 146 144 147 #define MXC_SPI_BUF_TX(type) \ ··· 204 203 205 204 static int spi_imx_bytes_per_word(const int bits_per_word) 206 205 { 207 - return DIV_ROUND_UP(bits_per_word, BITS_PER_BYTE); 206 + if (bits_per_word <= 8) 207 + return 1; 208 + else if (bits_per_word <= 16) 209 + return 2; 210 + else 211 + return 4; 208 212 } 209 213 210 214 static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi, ··· 226 220 227 221 bytes_per_word = spi_imx_bytes_per_word(transfer->bits_per_word); 228 222 229 - if (bytes_per_word != 1 && bytes_per_word != 2 && bytes_per_word != 4) 230 - return false; 231 - 232 223 for (i = spi_imx->devtype_data->fifo_size / 2; i > 0; i--) { 233 224 if (!(transfer->len % (i * bytes_per_word))) 234 225 break; 235 226 } 236 - 237 - if (i == 0) 238 - return false; 239 227 240 228 spi_imx->wml = i; 241 229 spi_imx->dynamic_burst = 0; ··· 291 291 else if (bytes_per_word == 2) 292 292 val = (val << 16) | (val >> 16); 293 293 #endif 294 - val &= spi_imx->word_mask; 295 294 *(u32 *)spi_imx->rx_buf = val; 296 295 spi_imx->rx_buf += sizeof(u32); 297 296 } 297 + 298 + spi_imx->remainder -= sizeof(u32); 298 299 } 299 300 300 301 static void spi_imx_buf_rx_swap(struct spi_imx_data *spi_imx) 301 302 { 302 - unsigned int bytes_per_word; 303 + int unaligned; 304 + u32 val; 303 305 304 - bytes_per_word = spi_imx_bytes_per_word(spi_imx->bits_per_word); 305 - if (spi_imx->read_u32) { 306 + unaligned = spi_imx->remainder % 4; 307 + 308 + if (!unaligned) { 306 309 spi_imx_buf_rx_swap_u32(spi_imx); 307 310 return; 308 311 } 309 312 310 - if (bytes_per_word == 1) 311 - spi_imx_buf_rx_u8(spi_imx); 312 - else if (bytes_per_word == 2) 313 + if (spi_imx_bytes_per_word(spi_imx->bits_per_word) == 2) { 313 314 spi_imx_buf_rx_u16(spi_imx); 315 + return; 316 + } 317 + 318 + val = readl(spi_imx->base + MXC_CSPIRXDATA); 319 + 320 + while (unaligned--) { 321 + if (spi_imx->rx_buf) { 322 + *(u8 *)spi_imx->rx_buf = (val >> (8 * unaligned)) & 0xff; 323 + spi_imx->rx_buf++; 324 + } 325 + spi_imx->remainder--; 326 + } 314 327 } 315 328 316 329 static void spi_imx_buf_tx_swap_u32(struct spi_imx_data *spi_imx) ··· 335 322 336 323 if (spi_imx->tx_buf) { 337 324 val = *(u32 *)spi_imx->tx_buf; 338 - val &= spi_imx->word_mask; 339 325 spi_imx->tx_buf += sizeof(u32); 340 326 } 341 327 ··· 352 340 353 341 static void spi_imx_buf_tx_swap(struct spi_imx_data *spi_imx) 354 342 { 355 - u32 ctrl, val; 356 - unsigned int bytes_per_word; 343 + int unaligned; 344 + u32 val = 0; 357 345 358 - if (spi_imx->count == spi_imx->remainder) { 359 - ctrl = readl(spi_imx->base + MX51_ECSPI_CTRL); 360 - ctrl &= ~MX51_ECSPI_CTRL_BL_MASK; 361 - if (spi_imx->count > MX51_ECSPI_CTRL_MAX_BURST) { 362 - spi_imx->remainder = spi_imx->count % 363 - MX51_ECSPI_CTRL_MAX_BURST; 364 - val = MX51_ECSPI_CTRL_MAX_BURST * 8 - 1; 365 - } else if (spi_imx->count >= sizeof(u32)) { 366 - spi_imx->remainder = spi_imx->count % sizeof(u32); 367 - val = (spi_imx->count - spi_imx->remainder) * 8 - 1; 368 - } else { 369 - spi_imx->remainder = 0; 370 - val = spi_imx->bits_per_word - 1; 371 - spi_imx->read_u32 = 0; 372 - } 346 + unaligned = spi_imx->count % 4; 373 347 374 - ctrl |= (val << MX51_ECSPI_CTRL_BL_OFFSET); 375 - writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL); 376 - } 377 - 378 - if (spi_imx->count >= sizeof(u32)) { 348 + if (!unaligned) { 379 349 spi_imx_buf_tx_swap_u32(spi_imx); 380 350 return; 381 351 } 382 352 383 - bytes_per_word = spi_imx_bytes_per_word(spi_imx->bits_per_word); 384 - 385 - if (bytes_per_word == 1) 386 - spi_imx_buf_tx_u8(spi_imx); 387 - else if (bytes_per_word == 2) 353 + if (spi_imx_bytes_per_word(spi_imx->bits_per_word) == 2) { 388 354 spi_imx_buf_tx_u16(spi_imx); 355 + return; 356 + } 357 + 358 + while (unaligned--) { 359 + if (spi_imx->tx_buf) { 360 + val |= *(u8 *)spi_imx->tx_buf << (8 * unaligned); 361 + spi_imx->tx_buf++; 362 + } 363 + spi_imx->count--; 364 + } 365 + 366 + writel(val, spi_imx->base + MXC_CSPITXDATA); 389 367 } 390 368 391 369 static void mx53_ecspi_rx_slave(struct spi_imx_data *spi_imx) ··· 394 392 spi_imx->rx_buf += n_bytes; 395 393 spi_imx->slave_burst -= n_bytes; 396 394 } 395 + 396 + spi_imx->remainder -= sizeof(u32); 397 397 } 398 398 399 399 static void mx53_ecspi_tx_slave(struct spi_imx_data *spi_imx) ··· 1005 1001 gpio_set_value(spi->cs_gpio, dev_is_lowactive ^ active); 1006 1002 } 1007 1003 1004 + static void spi_imx_set_burst_len(struct spi_imx_data *spi_imx, int n_bits) 1005 + { 1006 + u32 ctrl; 1007 + 1008 + ctrl = readl(spi_imx->base + MX51_ECSPI_CTRL); 1009 + ctrl &= ~MX51_ECSPI_CTRL_BL_MASK; 1010 + ctrl |= ((n_bits - 1) << MX51_ECSPI_CTRL_BL_OFFSET); 1011 + writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL); 1012 + } 1013 + 1008 1014 static void spi_imx_push(struct spi_imx_data *spi_imx) 1009 1015 { 1016 + unsigned int burst_len, fifo_words; 1017 + 1018 + if (spi_imx->dynamic_burst) 1019 + fifo_words = 4; 1020 + else 1021 + fifo_words = spi_imx_bytes_per_word(spi_imx->bits_per_word); 1022 + /* 1023 + * Reload the FIFO when the remaining bytes to be transferred in the 1024 + * current burst is 0. This only applies when bits_per_word is a 1025 + * multiple of 8. 1026 + */ 1027 + if (!spi_imx->remainder) { 1028 + if (spi_imx->dynamic_burst) { 1029 + 1030 + /* We need to deal unaligned data first */ 1031 + burst_len = spi_imx->count % MX51_ECSPI_CTRL_MAX_BURST; 1032 + 1033 + if (!burst_len) 1034 + burst_len = MX51_ECSPI_CTRL_MAX_BURST; 1035 + 1036 + spi_imx_set_burst_len(spi_imx, burst_len * 8); 1037 + 1038 + spi_imx->remainder = burst_len; 1039 + } else { 1040 + spi_imx->remainder = fifo_words; 1041 + } 1042 + } 1043 + 1010 1044 while (spi_imx->txfifo < spi_imx->devtype_data->fifo_size) { 1011 1045 if (!spi_imx->count) 1012 1046 break; 1013 - if (spi_imx->txfifo && (spi_imx->count == spi_imx->remainder)) 1047 + if (spi_imx->dynamic_burst && 1048 + spi_imx->txfifo >= DIV_ROUND_UP(spi_imx->remainder, 1049 + fifo_words)) 1014 1050 break; 1015 1051 spi_imx->tx(spi_imx); 1016 1052 spi_imx->txfifo++; ··· 1146 1102 spi_imx->bits_per_word = t->bits_per_word; 1147 1103 spi_imx->speed_hz = t->speed_hz; 1148 1104 1149 - /* Initialize the functions for transfer */ 1150 - if (spi_imx->devtype_data->dynamic_burst && !spi_imx->slave_mode) { 1151 - u32 mask; 1105 + /* 1106 + * Initialize the functions for transfer. To transfer non byte-aligned 1107 + * words, we have to use multiple word-size bursts, we can't use 1108 + * dynamic_burst in that case. 1109 + */ 1110 + if (spi_imx->devtype_data->dynamic_burst && !spi_imx->slave_mode && 1111 + (spi_imx->bits_per_word == 8 || 1112 + spi_imx->bits_per_word == 16 || 1113 + spi_imx->bits_per_word == 32)) { 1152 1114 1153 - spi_imx->dynamic_burst = 0; 1154 - spi_imx->remainder = 0; 1155 - spi_imx->read_u32 = 1; 1156 - 1157 - mask = (1 << spi_imx->bits_per_word) - 1; 1158 1115 spi_imx->rx = spi_imx_buf_rx_swap; 1159 1116 spi_imx->tx = spi_imx_buf_tx_swap; 1160 1117 spi_imx->dynamic_burst = 1; 1161 - spi_imx->remainder = t->len; 1162 1118 1163 - if (spi_imx->bits_per_word <= 8) 1164 - spi_imx->word_mask = mask << 24 | mask << 16 1165 - | mask << 8 | mask; 1166 - else if (spi_imx->bits_per_word <= 16) 1167 - spi_imx->word_mask = mask << 16 | mask; 1168 - else 1169 - spi_imx->word_mask = mask; 1170 1119 } else { 1171 1120 if (spi_imx->bits_per_word <= 8) { 1172 1121 spi_imx->rx = spi_imx_buf_rx_u8; ··· 1171 1134 spi_imx->rx = spi_imx_buf_rx_u32; 1172 1135 spi_imx->tx = spi_imx_buf_tx_u32; 1173 1136 } 1137 + spi_imx->dynamic_burst = 0; 1174 1138 } 1175 1139 1176 1140 if (spi_imx_can_dma(spi_imx->bitbang.master, spi, t)) ··· 1355 1317 spi_imx->rx_buf = transfer->rx_buf; 1356 1318 spi_imx->count = transfer->len; 1357 1319 spi_imx->txfifo = 0; 1320 + spi_imx->remainder = 0; 1358 1321 1359 1322 reinit_completion(&spi_imx->xfer_done); 1360 1323 ··· 1393 1354 spi_imx->rx_buf = transfer->rx_buf; 1394 1355 spi_imx->count = transfer->len; 1395 1356 spi_imx->txfifo = 0; 1357 + spi_imx->remainder = 0; 1396 1358 1397 1359 reinit_completion(&spi_imx->xfer_done); 1398 1360 spi_imx->slave_aborted = false;
+3 -2
drivers/spi/spi-lm70llp.c
··· 188 188 /* 189 189 * Our actual bitbanger routine. 190 190 */ 191 - static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits) 191 + static u32 lm70_txrx(struct spi_device *spi, unsigned nsecs, u32 word, u8 bits, 192 + unsigned flags) 192 193 { 193 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); 194 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); 194 195 } 195 196 196 197 static void spi_lm70llp_attach(struct parport *p)
+28
drivers/spi/spi-mem.c
··· 311 311 EXPORT_SYMBOL_GPL(spi_mem_exec_op); 312 312 313 313 /** 314 + * spi_mem_get_name() - Return the SPI mem device name to be used by the 315 + * upper layer if necessary 316 + * @mem: the SPI memory 317 + * 318 + * This function allows SPI mem users to retrieve the SPI mem device name. 319 + * It is useful if the upper layer needs to expose a custom name for 320 + * compatibility reasons. 321 + * 322 + * Return: a string containing the name of the memory device to be used 323 + * by the SPI mem user 324 + */ 325 + const char *spi_mem_get_name(struct spi_mem *mem) 326 + { 327 + return mem->name; 328 + } 329 + EXPORT_SYMBOL_GPL(spi_mem_get_name); 330 + 331 + /** 314 332 * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to 315 333 * match controller limitations 316 334 * @mem: the SPI memory ··· 362 344 static int spi_mem_probe(struct spi_device *spi) 363 345 { 364 346 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); 347 + struct spi_controller *ctlr = spi->controller; 365 348 struct spi_mem *mem; 366 349 367 350 mem = devm_kzalloc(&spi->dev, sizeof(*mem), GFP_KERNEL); ··· 370 351 return -ENOMEM; 371 352 372 353 mem->spi = spi; 354 + 355 + if (ctlr->mem_ops && ctlr->mem_ops->get_name) 356 + mem->name = ctlr->mem_ops->get_name(mem); 357 + else 358 + mem->name = dev_name(&spi->dev); 359 + 360 + if (IS_ERR_OR_NULL(mem->name)) 361 + return PTR_ERR(mem->name); 362 + 373 363 spi_set_drvdata(spi, mem); 374 364 375 365 return memdrv->probe(mem);
-9
drivers/spi/spi-omap2-mcspi.c
··· 398 398 { 399 399 struct omap2_mcspi *mcspi; 400 400 struct omap2_mcspi_dma *mcspi_dma; 401 - unsigned int count; 402 401 403 402 mcspi = spi_master_get_devdata(spi->master); 404 403 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 405 - count = xfer->len; 406 404 407 405 if (mcspi_dma->dma_tx) { 408 406 struct dma_async_tx_descriptor *tx; ··· 580 582 struct omap2_mcspi_cs *cs = spi->controller_state; 581 583 struct omap2_mcspi_dma *mcspi_dma; 582 584 unsigned int count; 583 - u32 l; 584 585 u8 *rx; 585 586 const u8 *tx; 586 587 struct dma_slave_config cfg; ··· 592 595 593 596 mcspi = spi_master_get_devdata(spi->master); 594 597 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 595 - l = mcspi_cached_chconf0(spi); 596 - 597 598 598 599 if (cs->word_len <= 8) { 599 600 width = DMA_SLAVE_BUSWIDTH_1_BYTE; ··· 671 676 static unsigned 672 677 omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer) 673 678 { 674 - struct omap2_mcspi *mcspi; 675 679 struct omap2_mcspi_cs *cs = spi->controller_state; 676 680 unsigned int count, c; 677 681 u32 l; ··· 680 686 void __iomem *chstat_reg; 681 687 int word_len; 682 688 683 - mcspi = spi_master_get_devdata(spi->master); 684 689 count = xfer->len; 685 690 c = count; 686 691 word_len = cs->word_len; ··· 876 883 { 877 884 struct omap2_mcspi_cs *cs = spi->controller_state; 878 885 struct omap2_mcspi *mcspi; 879 - struct spi_master *spi_cntrl; 880 886 u32 l = 0, clkd = 0, div, extclk = 0, clkg = 0; 881 887 u8 word_len = spi->bits_per_word; 882 888 u32 speed_hz = spi->max_speed_hz; 883 889 884 890 mcspi = spi_master_get_devdata(spi->master); 885 - spi_cntrl = mcspi->master; 886 891 887 892 if (t != NULL && t->bits_per_word) 888 893 word_len = t->bits_per_word;
+40 -37
drivers/spi/spi-orion.c
··· 20 20 #include <linux/of.h> 21 21 #include <linux/of_address.h> 22 22 #include <linux/of_device.h> 23 + #include <linux/of_gpio.h> 23 24 #include <linux/clk.h> 24 25 #include <linux/sizes.h> 25 26 #include <linux/gpio.h> ··· 682 681 goto out_rel_axi_clk; 683 682 } 684 683 685 - /* Scan all SPI devices of this controller for direct mapped devices */ 686 684 for_each_available_child_of_node(pdev->dev.of_node, np) { 687 685 u32 cs; 686 + int cs_gpio; 688 687 689 688 /* Get chip-select number from the "reg" property */ 690 689 status = of_property_read_u32(np, "reg", &cs); ··· 693 692 "%pOF has no valid 'reg' property (%d)\n", 694 693 np, status); 695 694 continue; 695 + } 696 + 697 + /* 698 + * Initialize the CS GPIO: 699 + * - properly request the actual GPIO signal 700 + * - de-assert the logical signal so that all GPIO CS lines 701 + * are inactive when probing for slaves 702 + * - find an unused physical CS which will be driven for any 703 + * slave which uses a CS GPIO 704 + */ 705 + cs_gpio = of_get_named_gpio(pdev->dev.of_node, "cs-gpios", cs); 706 + if (cs_gpio > 0) { 707 + char *gpio_name; 708 + int cs_flags; 709 + 710 + if (spi->unused_hw_gpio == -1) { 711 + dev_info(&pdev->dev, 712 + "Selected unused HW CS#%d for any GPIO CSes\n", 713 + cs); 714 + spi->unused_hw_gpio = cs; 715 + } 716 + 717 + gpio_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, 718 + "%s-CS%d", dev_name(&pdev->dev), cs); 719 + if (!gpio_name) { 720 + status = -ENOMEM; 721 + goto out_rel_axi_clk; 722 + } 723 + 724 + cs_flags = of_property_read_bool(np, "spi-cs-high") ? 725 + GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH; 726 + status = devm_gpio_request_one(&pdev->dev, cs_gpio, 727 + cs_flags, gpio_name); 728 + if (status) { 729 + dev_err(&pdev->dev, 730 + "Can't request GPIO for CS %d\n", cs); 731 + goto out_rel_axi_clk; 732 + } 696 733 } 697 734 698 735 /* ··· 779 740 if (status < 0) 780 741 goto out_rel_pm; 781 742 782 - if (master->cs_gpios) { 783 - int i; 784 - for (i = 0; i < master->num_chipselect; ++i) { 785 - char *gpio_name; 786 - 787 - if (!gpio_is_valid(master->cs_gpios[i])) { 788 - continue; 789 - } 790 - 791 - gpio_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, 792 - "%s-CS%d", dev_name(&pdev->dev), i); 793 - if (!gpio_name) { 794 - status = -ENOMEM; 795 - goto out_rel_master; 796 - } 797 - 798 - status = devm_gpio_request(&pdev->dev, 799 - master->cs_gpios[i], gpio_name); 800 - if (status) { 801 - dev_err(&pdev->dev, 802 - "Can't request GPIO for CS %d\n", 803 - master->cs_gpios[i]); 804 - goto out_rel_master; 805 - } 806 - if (spi->unused_hw_gpio == -1) { 807 - dev_info(&pdev->dev, 808 - "Selected unused HW CS#%d for any GPIO CSes\n", 809 - i); 810 - spi->unused_hw_gpio = i; 811 - } 812 - } 813 - } 814 - 815 - 816 743 return status; 817 744 818 - out_rel_master: 819 - spi_unregister_master(master); 820 745 out_rel_pm: 821 746 pm_runtime_disable(&pdev->dev); 822 747 out_rel_axi_clk:
+4
drivers/spi/spi-pxa2xx.c
··· 1391 1391 { PCI_VDEVICE(INTEL, 0x31c2), LPSS_BXT_SSP }, 1392 1392 { PCI_VDEVICE(INTEL, 0x31c4), LPSS_BXT_SSP }, 1393 1393 { PCI_VDEVICE(INTEL, 0x31c6), LPSS_BXT_SSP }, 1394 + /* ICL-LP */ 1395 + { PCI_VDEVICE(INTEL, 0x34aa), LPSS_CNL_SSP }, 1396 + { PCI_VDEVICE(INTEL, 0x34ab), LPSS_CNL_SSP }, 1397 + { PCI_VDEVICE(INTEL, 0x34fb), LPSS_CNL_SSP }, 1394 1398 /* APL */ 1395 1399 { PCI_VDEVICE(INTEL, 0x5ac2), LPSS_BXT_SSP }, 1396 1400 { PCI_VDEVICE(INTEL, 0x5ac4), LPSS_BXT_SSP },
+29 -24
drivers/spi/spi-sh-msiof.c
··· 49 49 struct platform_device *pdev; 50 50 struct sh_msiof_spi_info *info; 51 51 struct completion done; 52 + struct completion done_txdma; 52 53 unsigned int tx_fifo_size; 53 54 unsigned int rx_fifo_size; 54 55 unsigned int min_div_pow; ··· 650 649 651 650 p->slave_aborted = true; 652 651 complete(&p->done); 652 + complete(&p->done_txdma); 653 653 return 0; 654 654 } 655 655 656 - static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p) 656 + static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p, 657 + struct completion *x) 657 658 { 658 659 if (spi_controller_is_slave(p->master)) { 659 - if (wait_for_completion_interruptible(&p->done) || 660 + if (wait_for_completion_interruptible(x) || 660 661 p->slave_aborted) { 661 662 dev_dbg(&p->pdev->dev, "interrupted\n"); 662 663 return -EINTR; 663 664 } 664 665 } else { 665 - if (!wait_for_completion_timeout(&p->done, HZ)) { 666 + if (!wait_for_completion_timeout(x, HZ)) { 666 667 dev_err(&p->pdev->dev, "timeout\n"); 667 668 return -ETIMEDOUT; 668 669 } ··· 714 711 } 715 712 716 713 /* wait for tx fifo to be emptied / rx fifo to be filled */ 717 - ret = sh_msiof_wait_for_completion(p); 714 + ret = sh_msiof_wait_for_completion(p, &p->done); 718 715 if (ret) 719 716 goto stop_reset; 720 717 ··· 743 740 744 741 static void sh_msiof_dma_complete(void *arg) 745 742 { 746 - struct sh_msiof_spi_priv *p = arg; 747 - 748 - sh_msiof_write(p, IER, 0); 749 - complete(&p->done); 743 + complete(arg); 750 744 } 751 745 752 746 static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, ··· 764 764 return -EAGAIN; 765 765 766 766 desc_rx->callback = sh_msiof_dma_complete; 767 - desc_rx->callback_param = p; 767 + desc_rx->callback_param = &p->done; 768 768 cookie = dmaengine_submit(desc_rx); 769 769 if (dma_submit_error(cookie)) 770 770 return cookie; ··· 782 782 goto no_dma_tx; 783 783 } 784 784 785 - if (rx) { 786 - /* No callback */ 787 - desc_tx->callback = NULL; 788 - } else { 789 - desc_tx->callback = sh_msiof_dma_complete; 790 - desc_tx->callback_param = p; 791 - } 785 + desc_tx->callback = sh_msiof_dma_complete; 786 + desc_tx->callback_param = &p->done_txdma; 792 787 cookie = dmaengine_submit(desc_tx); 793 788 if (dma_submit_error(cookie)) { 794 789 ret = cookie; ··· 800 805 sh_msiof_write(p, IER, ier_bits); 801 806 802 807 reinit_completion(&p->done); 808 + if (tx) 809 + reinit_completion(&p->done_txdma); 803 810 p->slave_aborted = false; 804 811 805 812 /* Now start DMA */ ··· 816 819 goto stop_dma; 817 820 } 818 821 819 - /* wait for tx/rx DMA completion */ 820 - ret = sh_msiof_wait_for_completion(p); 821 - if (ret) 822 - goto stop_reset; 822 + if (tx) { 823 + /* wait for tx DMA completion */ 824 + ret = sh_msiof_wait_for_completion(p, &p->done_txdma); 825 + if (ret) 826 + goto stop_reset; 827 + } 823 828 824 - if (!rx) { 825 - reinit_completion(&p->done); 826 - sh_msiof_write(p, IER, IER_TEOFE); 829 + if (rx) { 830 + /* wait for rx DMA completion */ 831 + ret = sh_msiof_wait_for_completion(p, &p->done); 832 + if (ret) 833 + goto stop_reset; 827 834 835 + sh_msiof_write(p, IER, 0); 836 + } else { 828 837 /* wait for tx fifo to be emptied */ 829 - ret = sh_msiof_wait_for_completion(p); 838 + sh_msiof_write(p, IER, IER_TEOFE); 839 + ret = sh_msiof_wait_for_completion(p, &p->done); 830 840 if (ret) 831 841 goto stop_reset; 832 842 } ··· 1331 1327 p->min_div_pow = chipdata->min_div_pow; 1332 1328 1333 1329 init_completion(&p->done); 1330 + init_completion(&p->done_txdma); 1334 1331 1335 1332 p->clk = devm_clk_get(&pdev->dev, NULL); 1336 1333 if (IS_ERR(p->clk)) {
+12 -8
drivers/spi/spi-sh-sci.c
··· 80 80 #include "spi-bitbang-txrx.h" 81 81 82 82 static u32 sh_sci_spi_txrx_mode0(struct spi_device *spi, 83 - unsigned nsecs, u32 word, u8 bits) 83 + unsigned nsecs, u32 word, u8 bits, 84 + unsigned flags) 84 85 { 85 - return bitbang_txrx_be_cpha0(spi, nsecs, 0, 0, word, bits); 86 + return bitbang_txrx_be_cpha0(spi, nsecs, 0, flags, word, bits); 86 87 } 87 88 88 89 static u32 sh_sci_spi_txrx_mode1(struct spi_device *spi, 89 - unsigned nsecs, u32 word, u8 bits) 90 + unsigned nsecs, u32 word, u8 bits, 91 + unsigned flags) 90 92 { 91 - return bitbang_txrx_be_cpha1(spi, nsecs, 0, 0, word, bits); 93 + return bitbang_txrx_be_cpha1(spi, nsecs, 0, flags, word, bits); 92 94 } 93 95 94 96 static u32 sh_sci_spi_txrx_mode2(struct spi_device *spi, 95 - unsigned nsecs, u32 word, u8 bits) 97 + unsigned nsecs, u32 word, u8 bits, 98 + unsigned flags) 96 99 { 97 - return bitbang_txrx_be_cpha0(spi, nsecs, 1, 0, word, bits); 100 + return bitbang_txrx_be_cpha0(spi, nsecs, 1, flags, word, bits); 98 101 } 99 102 100 103 static u32 sh_sci_spi_txrx_mode3(struct spi_device *spi, 101 - unsigned nsecs, u32 word, u8 bits) 104 + unsigned nsecs, u32 word, u8 bits, 105 + unsigned flags) 102 106 { 103 - return bitbang_txrx_be_cpha1(spi, nsecs, 1, 0, word, bits); 107 + return bitbang_txrx_be_cpha1(spi, nsecs, 1, flags, word, bits); 104 108 } 105 109 106 110 static void sh_sci_spi_chipselect(struct spi_device *dev, int value)
+523
drivers/spi/spi-uniphier.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // spi-uniphier.c - Socionext UniPhier SPI controller driver 3 + // Copyright 2012 Panasonic Corporation 4 + // Copyright 2016-2018 Socionext Inc. 5 + 6 + #include <linux/kernel.h> 7 + #include <linux/bitfield.h> 8 + #include <linux/bitops.h> 9 + #include <linux/clk.h> 10 + #include <linux/interrupt.h> 11 + #include <linux/io.h> 12 + #include <linux/module.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/spi/spi.h> 15 + 16 + #include <asm/unaligned.h> 17 + 18 + #define SSI_TIMEOUT_MS 2000 19 + #define SSI_MAX_CLK_DIVIDER 254 20 + #define SSI_MIN_CLK_DIVIDER 4 21 + 22 + struct uniphier_spi_priv { 23 + void __iomem *base; 24 + struct clk *clk; 25 + struct spi_master *master; 26 + struct completion xfer_done; 27 + 28 + int error; 29 + unsigned int tx_bytes; 30 + unsigned int rx_bytes; 31 + const u8 *tx_buf; 32 + u8 *rx_buf; 33 + 34 + bool is_save_param; 35 + u8 bits_per_word; 36 + u16 mode; 37 + u32 speed_hz; 38 + }; 39 + 40 + #define SSI_CTL 0x00 41 + #define SSI_CTL_EN BIT(0) 42 + 43 + #define SSI_CKS 0x04 44 + #define SSI_CKS_CKRAT_MASK GENMASK(7, 0) 45 + #define SSI_CKS_CKPHS BIT(14) 46 + #define SSI_CKS_CKINIT BIT(13) 47 + #define SSI_CKS_CKDLY BIT(12) 48 + 49 + #define SSI_TXWDS 0x08 50 + #define SSI_TXWDS_WDLEN_MASK GENMASK(13, 8) 51 + #define SSI_TXWDS_TDTF_MASK GENMASK(7, 6) 52 + #define SSI_TXWDS_DTLEN_MASK GENMASK(5, 0) 53 + 54 + #define SSI_RXWDS 0x0c 55 + #define SSI_RXWDS_DTLEN_MASK GENMASK(5, 0) 56 + 57 + #define SSI_FPS 0x10 58 + #define SSI_FPS_FSPOL BIT(15) 59 + #define SSI_FPS_FSTRT BIT(14) 60 + 61 + #define SSI_SR 0x14 62 + #define SSI_SR_RNE BIT(0) 63 + 64 + #define SSI_IE 0x18 65 + #define SSI_IE_RCIE BIT(3) 66 + #define SSI_IE_RORIE BIT(0) 67 + 68 + #define SSI_IS 0x1c 69 + #define SSI_IS_RXRS BIT(9) 70 + #define SSI_IS_RCID BIT(3) 71 + #define SSI_IS_RORID BIT(0) 72 + 73 + #define SSI_IC 0x1c 74 + #define SSI_IC_TCIC BIT(4) 75 + #define SSI_IC_RCIC BIT(3) 76 + #define SSI_IC_RORIC BIT(0) 77 + 78 + #define SSI_FC 0x20 79 + #define SSI_FC_TXFFL BIT(12) 80 + #define SSI_FC_TXFTH_MASK GENMASK(11, 8) 81 + #define SSI_FC_RXFFL BIT(4) 82 + #define SSI_FC_RXFTH_MASK GENMASK(3, 0) 83 + 84 + #define SSI_TXDR 0x24 85 + #define SSI_RXDR 0x24 86 + 87 + #define SSI_FIFO_DEPTH 8U 88 + 89 + static inline unsigned int bytes_per_word(unsigned int bits) 90 + { 91 + return bits <= 8 ? 1 : (bits <= 16 ? 2 : 4); 92 + } 93 + 94 + static inline void uniphier_spi_irq_enable(struct spi_device *spi, u32 mask) 95 + { 96 + struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master); 97 + u32 val; 98 + 99 + val = readl(priv->base + SSI_IE); 100 + val |= mask; 101 + writel(val, priv->base + SSI_IE); 102 + } 103 + 104 + static inline void uniphier_spi_irq_disable(struct spi_device *spi, u32 mask) 105 + { 106 + struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master); 107 + u32 val; 108 + 109 + val = readl(priv->base + SSI_IE); 110 + val &= ~mask; 111 + writel(val, priv->base + SSI_IE); 112 + } 113 + 114 + static void uniphier_spi_set_mode(struct spi_device *spi) 115 + { 116 + struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master); 117 + u32 val1, val2; 118 + 119 + /* 120 + * clock setting 121 + * CKPHS capture timing. 0:rising edge, 1:falling edge 122 + * CKINIT clock initial level. 0:low, 1:high 123 + * CKDLY clock delay. 0:no delay, 1:delay depending on FSTRT 124 + * (FSTRT=0: 1 clock, FSTRT=1: 0.5 clock) 125 + * 126 + * frame setting 127 + * FSPOL frame signal porarity. 0: low, 1: high 128 + * FSTRT start frame timing 129 + * 0: rising edge of clock, 1: falling edge of clock 130 + */ 131 + switch (spi->mode & (SPI_CPOL | SPI_CPHA)) { 132 + case SPI_MODE_0: 133 + /* CKPHS=1, CKINIT=0, CKDLY=1, FSTRT=0 */ 134 + val1 = SSI_CKS_CKPHS | SSI_CKS_CKDLY; 135 + val2 = 0; 136 + break; 137 + case SPI_MODE_1: 138 + /* CKPHS=0, CKINIT=0, CKDLY=0, FSTRT=1 */ 139 + val1 = 0; 140 + val2 = SSI_FPS_FSTRT; 141 + break; 142 + case SPI_MODE_2: 143 + /* CKPHS=0, CKINIT=1, CKDLY=1, FSTRT=1 */ 144 + val1 = SSI_CKS_CKINIT | SSI_CKS_CKDLY; 145 + val2 = SSI_FPS_FSTRT; 146 + break; 147 + case SPI_MODE_3: 148 + /* CKPHS=1, CKINIT=1, CKDLY=0, FSTRT=0 */ 149 + val1 = SSI_CKS_CKPHS | SSI_CKS_CKINIT; 150 + val2 = 0; 151 + break; 152 + } 153 + 154 + if (!(spi->mode & SPI_CS_HIGH)) 155 + val2 |= SSI_FPS_FSPOL; 156 + 157 + writel(val1, priv->base + SSI_CKS); 158 + writel(val2, priv->base + SSI_FPS); 159 + 160 + val1 = 0; 161 + if (spi->mode & SPI_LSB_FIRST) 162 + val1 |= FIELD_PREP(SSI_TXWDS_TDTF_MASK, 1); 163 + writel(val1, priv->base + SSI_TXWDS); 164 + writel(val1, priv->base + SSI_RXWDS); 165 + } 166 + 167 + static void uniphier_spi_set_transfer_size(struct spi_device *spi, int size) 168 + { 169 + struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master); 170 + u32 val; 171 + 172 + val = readl(priv->base + SSI_TXWDS); 173 + val &= ~(SSI_TXWDS_WDLEN_MASK | SSI_TXWDS_DTLEN_MASK); 174 + val |= FIELD_PREP(SSI_TXWDS_WDLEN_MASK, size); 175 + val |= FIELD_PREP(SSI_TXWDS_DTLEN_MASK, size); 176 + writel(val, priv->base + SSI_TXWDS); 177 + 178 + val = readl(priv->base + SSI_RXWDS); 179 + val &= ~SSI_RXWDS_DTLEN_MASK; 180 + val |= FIELD_PREP(SSI_RXWDS_DTLEN_MASK, size); 181 + writel(val, priv->base + SSI_RXWDS); 182 + } 183 + 184 + static void uniphier_spi_set_baudrate(struct spi_device *spi, 185 + unsigned int speed) 186 + { 187 + struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master); 188 + u32 val, ckdiv; 189 + 190 + /* 191 + * the supported rates are even numbers from 4 to 254. (4,6,8...254) 192 + * round up as we look for equal or less speed 193 + */ 194 + ckdiv = DIV_ROUND_UP(clk_get_rate(priv->clk), speed); 195 + ckdiv = round_up(ckdiv, 2); 196 + 197 + val = readl(priv->base + SSI_CKS); 198 + val &= ~SSI_CKS_CKRAT_MASK; 199 + val |= ckdiv & SSI_CKS_CKRAT_MASK; 200 + writel(val, priv->base + SSI_CKS); 201 + } 202 + 203 + static void uniphier_spi_setup_transfer(struct spi_device *spi, 204 + struct spi_transfer *t) 205 + { 206 + struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master); 207 + u32 val; 208 + 209 + priv->error = 0; 210 + priv->tx_buf = t->tx_buf; 211 + priv->rx_buf = t->rx_buf; 212 + priv->tx_bytes = priv->rx_bytes = t->len; 213 + 214 + if (!priv->is_save_param || priv->mode != spi->mode) { 215 + uniphier_spi_set_mode(spi); 216 + priv->mode = spi->mode; 217 + } 218 + 219 + if (!priv->is_save_param || priv->bits_per_word != t->bits_per_word) { 220 + uniphier_spi_set_transfer_size(spi, t->bits_per_word); 221 + priv->bits_per_word = t->bits_per_word; 222 + } 223 + 224 + if (!priv->is_save_param || priv->speed_hz != t->speed_hz) { 225 + uniphier_spi_set_baudrate(spi, t->speed_hz); 226 + priv->speed_hz = t->speed_hz; 227 + } 228 + 229 + if (!priv->is_save_param) 230 + priv->is_save_param = true; 231 + 232 + /* reset FIFOs */ 233 + val = SSI_FC_TXFFL | SSI_FC_RXFFL; 234 + writel(val, priv->base + SSI_FC); 235 + } 236 + 237 + static void uniphier_spi_send(struct uniphier_spi_priv *priv) 238 + { 239 + int wsize; 240 + u32 val = 0; 241 + 242 + wsize = min(bytes_per_word(priv->bits_per_word), priv->tx_bytes); 243 + priv->tx_bytes -= wsize; 244 + 245 + if (priv->tx_buf) { 246 + switch (wsize) { 247 + case 1: 248 + val = *priv->tx_buf; 249 + break; 250 + case 2: 251 + val = get_unaligned_le16(priv->tx_buf); 252 + break; 253 + case 4: 254 + val = get_unaligned_le32(priv->tx_buf); 255 + break; 256 + } 257 + 258 + priv->tx_buf += wsize; 259 + } 260 + 261 + writel(val, priv->base + SSI_TXDR); 262 + } 263 + 264 + static void uniphier_spi_recv(struct uniphier_spi_priv *priv) 265 + { 266 + int rsize; 267 + u32 val; 268 + 269 + rsize = min(bytes_per_word(priv->bits_per_word), priv->rx_bytes); 270 + priv->rx_bytes -= rsize; 271 + 272 + val = readl(priv->base + SSI_RXDR); 273 + 274 + if (priv->rx_buf) { 275 + switch (rsize) { 276 + case 1: 277 + *priv->rx_buf = val; 278 + break; 279 + case 2: 280 + put_unaligned_le16(val, priv->rx_buf); 281 + break; 282 + case 4: 283 + put_unaligned_le32(val, priv->rx_buf); 284 + break; 285 + } 286 + 287 + priv->rx_buf += rsize; 288 + } 289 + } 290 + 291 + static void uniphier_spi_fill_tx_fifo(struct uniphier_spi_priv *priv) 292 + { 293 + unsigned int tx_count; 294 + u32 val; 295 + 296 + tx_count = DIV_ROUND_UP(priv->tx_bytes, 297 + bytes_per_word(priv->bits_per_word)); 298 + tx_count = min(tx_count, SSI_FIFO_DEPTH); 299 + 300 + /* set fifo threshold */ 301 + val = readl(priv->base + SSI_FC); 302 + val &= ~(SSI_FC_TXFTH_MASK | SSI_FC_RXFTH_MASK); 303 + val |= FIELD_PREP(SSI_FC_TXFTH_MASK, tx_count); 304 + val |= FIELD_PREP(SSI_FC_RXFTH_MASK, tx_count); 305 + writel(val, priv->base + SSI_FC); 306 + 307 + while (tx_count--) 308 + uniphier_spi_send(priv); 309 + } 310 + 311 + static void uniphier_spi_set_cs(struct spi_device *spi, bool enable) 312 + { 313 + struct uniphier_spi_priv *priv = spi_master_get_devdata(spi->master); 314 + u32 val; 315 + 316 + val = readl(priv->base + SSI_FPS); 317 + 318 + if (enable) 319 + val |= SSI_FPS_FSPOL; 320 + else 321 + val &= ~SSI_FPS_FSPOL; 322 + 323 + writel(val, priv->base + SSI_FPS); 324 + } 325 + 326 + static int uniphier_spi_transfer_one(struct spi_master *master, 327 + struct spi_device *spi, 328 + struct spi_transfer *t) 329 + { 330 + struct uniphier_spi_priv *priv = spi_master_get_devdata(master); 331 + int status; 332 + 333 + uniphier_spi_setup_transfer(spi, t); 334 + 335 + reinit_completion(&priv->xfer_done); 336 + 337 + uniphier_spi_fill_tx_fifo(priv); 338 + 339 + uniphier_spi_irq_enable(spi, SSI_IE_RCIE | SSI_IE_RORIE); 340 + 341 + status = wait_for_completion_timeout(&priv->xfer_done, 342 + msecs_to_jiffies(SSI_TIMEOUT_MS)); 343 + 344 + uniphier_spi_irq_disable(spi, SSI_IE_RCIE | SSI_IE_RORIE); 345 + 346 + if (status < 0) 347 + return status; 348 + 349 + return priv->error; 350 + } 351 + 352 + static int uniphier_spi_prepare_transfer_hardware(struct spi_master *master) 353 + { 354 + struct uniphier_spi_priv *priv = spi_master_get_devdata(master); 355 + 356 + writel(SSI_CTL_EN, priv->base + SSI_CTL); 357 + 358 + return 0; 359 + } 360 + 361 + static int uniphier_spi_unprepare_transfer_hardware(struct spi_master *master) 362 + { 363 + struct uniphier_spi_priv *priv = spi_master_get_devdata(master); 364 + 365 + writel(0, priv->base + SSI_CTL); 366 + 367 + return 0; 368 + } 369 + 370 + static irqreturn_t uniphier_spi_handler(int irq, void *dev_id) 371 + { 372 + struct uniphier_spi_priv *priv = dev_id; 373 + u32 val, stat; 374 + 375 + stat = readl(priv->base + SSI_IS); 376 + val = SSI_IC_TCIC | SSI_IC_RCIC | SSI_IC_RORIC; 377 + writel(val, priv->base + SSI_IC); 378 + 379 + /* rx fifo overrun */ 380 + if (stat & SSI_IS_RORID) { 381 + priv->error = -EIO; 382 + goto done; 383 + } 384 + 385 + /* rx complete */ 386 + if ((stat & SSI_IS_RCID) && (stat & SSI_IS_RXRS)) { 387 + while ((readl(priv->base + SSI_SR) & SSI_SR_RNE) && 388 + (priv->rx_bytes - priv->tx_bytes) > 0) 389 + uniphier_spi_recv(priv); 390 + 391 + if ((readl(priv->base + SSI_SR) & SSI_SR_RNE) || 392 + (priv->rx_bytes != priv->tx_bytes)) { 393 + priv->error = -EIO; 394 + goto done; 395 + } else if (priv->rx_bytes == 0) 396 + goto done; 397 + 398 + /* next tx transfer */ 399 + uniphier_spi_fill_tx_fifo(priv); 400 + 401 + return IRQ_HANDLED; 402 + } 403 + 404 + return IRQ_NONE; 405 + 406 + done: 407 + complete(&priv->xfer_done); 408 + return IRQ_HANDLED; 409 + } 410 + 411 + static int uniphier_spi_probe(struct platform_device *pdev) 412 + { 413 + struct uniphier_spi_priv *priv; 414 + struct spi_master *master; 415 + struct resource *res; 416 + unsigned long clk_rate; 417 + int irq; 418 + int ret; 419 + 420 + master = spi_alloc_master(&pdev->dev, sizeof(*priv)); 421 + if (!master) 422 + return -ENOMEM; 423 + 424 + platform_set_drvdata(pdev, master); 425 + 426 + priv = spi_master_get_devdata(master); 427 + priv->master = master; 428 + priv->is_save_param = false; 429 + 430 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 431 + priv->base = devm_ioremap_resource(&pdev->dev, res); 432 + if (IS_ERR(priv->base)) { 433 + ret = PTR_ERR(priv->base); 434 + goto out_master_put; 435 + } 436 + 437 + priv->clk = devm_clk_get(&pdev->dev, NULL); 438 + if (IS_ERR(priv->clk)) { 439 + dev_err(&pdev->dev, "failed to get clock\n"); 440 + ret = PTR_ERR(priv->clk); 441 + goto out_master_put; 442 + } 443 + 444 + ret = clk_prepare_enable(priv->clk); 445 + if (ret) 446 + goto out_master_put; 447 + 448 + irq = platform_get_irq(pdev, 0); 449 + if (irq < 0) { 450 + dev_err(&pdev->dev, "failed to get IRQ\n"); 451 + ret = irq; 452 + goto out_disable_clk; 453 + } 454 + 455 + ret = devm_request_irq(&pdev->dev, irq, uniphier_spi_handler, 456 + 0, "uniphier-spi", priv); 457 + if (ret) { 458 + dev_err(&pdev->dev, "failed to request IRQ\n"); 459 + goto out_disable_clk; 460 + } 461 + 462 + init_completion(&priv->xfer_done); 463 + 464 + clk_rate = clk_get_rate(priv->clk); 465 + 466 + master->max_speed_hz = DIV_ROUND_UP(clk_rate, SSI_MIN_CLK_DIVIDER); 467 + master->min_speed_hz = DIV_ROUND_UP(clk_rate, SSI_MAX_CLK_DIVIDER); 468 + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST; 469 + master->dev.of_node = pdev->dev.of_node; 470 + master->bus_num = pdev->id; 471 + master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); 472 + 473 + master->set_cs = uniphier_spi_set_cs; 474 + master->transfer_one = uniphier_spi_transfer_one; 475 + master->prepare_transfer_hardware 476 + = uniphier_spi_prepare_transfer_hardware; 477 + master->unprepare_transfer_hardware 478 + = uniphier_spi_unprepare_transfer_hardware; 479 + master->num_chipselect = 1; 480 + 481 + ret = devm_spi_register_master(&pdev->dev, master); 482 + if (ret) 483 + goto out_disable_clk; 484 + 485 + return 0; 486 + 487 + out_disable_clk: 488 + clk_disable_unprepare(priv->clk); 489 + 490 + out_master_put: 491 + spi_master_put(master); 492 + return ret; 493 + } 494 + 495 + static int uniphier_spi_remove(struct platform_device *pdev) 496 + { 497 + struct uniphier_spi_priv *priv = platform_get_drvdata(pdev); 498 + 499 + clk_disable_unprepare(priv->clk); 500 + 501 + return 0; 502 + } 503 + 504 + static const struct of_device_id uniphier_spi_match[] = { 505 + { .compatible = "socionext,uniphier-scssi" }, 506 + { /* sentinel */ } 507 + }; 508 + MODULE_DEVICE_TABLE(of, uniphier_spi_match); 509 + 510 + static struct platform_driver uniphier_spi_driver = { 511 + .probe = uniphier_spi_probe, 512 + .remove = uniphier_spi_remove, 513 + .driver = { 514 + .name = "uniphier-spi", 515 + .of_match_table = uniphier_spi_match, 516 + }, 517 + }; 518 + module_platform_driver(uniphier_spi_driver); 519 + 520 + MODULE_AUTHOR("Kunihiko Hayashi <hayashi.kunihiko@socionext.com>"); 521 + MODULE_AUTHOR("Keiji Hayashibara <hayashibara.keiji@socionext.com>"); 522 + MODULE_DESCRIPTION("Socionext UniPhier SPI controller driver"); 523 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/spi/spi-xtensa-xtfpga.c
··· 54 54 } 55 55 56 56 static u32 xtfpga_spi_txrx_word(struct spi_device *spi, unsigned nsecs, 57 - u32 v, u8 bits) 57 + u32 v, u8 bits, unsigned flags) 58 58 { 59 59 struct xtfpga_spi *xspi = spi_master_get_devdata(spi->master); 60 60
-254
include/linux/spi/adi_spi3.h
··· 1 - /* 2 - * Analog Devices SPI3 controller driver 3 - * 4 - * Copyright (c) 2014 Analog Devices Inc. 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License version 2 as 8 - * published by the Free Software Foundation. 9 - * 10 - * This program is distributed in the hope that it will be useful, 11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 - * GNU General Public License for more details. 14 - */ 15 - 16 - #ifndef _ADI_SPI3_H_ 17 - #define _ADI_SPI3_H_ 18 - 19 - #include <linux/types.h> 20 - 21 - /* SPI_CONTROL */ 22 - #define SPI_CTL_EN 0x00000001 /* Enable */ 23 - #define SPI_CTL_MSTR 0x00000002 /* Master/Slave */ 24 - #define SPI_CTL_PSSE 0x00000004 /* controls modf error in master mode */ 25 - #define SPI_CTL_ODM 0x00000008 /* Open Drain Mode */ 26 - #define SPI_CTL_CPHA 0x00000010 /* Clock Phase */ 27 - #define SPI_CTL_CPOL 0x00000020 /* Clock Polarity */ 28 - #define SPI_CTL_ASSEL 0x00000040 /* Slave Select Pin Control */ 29 - #define SPI_CTL_SELST 0x00000080 /* Slave Select Polarity in-between transfers */ 30 - #define SPI_CTL_EMISO 0x00000100 /* Enable MISO */ 31 - #define SPI_CTL_SIZE 0x00000600 /* Word Transfer Size */ 32 - #define SPI_CTL_SIZE08 0x00000000 /* SIZE: 8 bits */ 33 - #define SPI_CTL_SIZE16 0x00000200 /* SIZE: 16 bits */ 34 - #define SPI_CTL_SIZE32 0x00000400 /* SIZE: 32 bits */ 35 - #define SPI_CTL_LSBF 0x00001000 /* LSB First */ 36 - #define SPI_CTL_FCEN 0x00002000 /* Flow-Control Enable */ 37 - #define SPI_CTL_FCCH 0x00004000 /* Flow-Control Channel Selection */ 38 - #define SPI_CTL_FCPL 0x00008000 /* Flow-Control Polarity */ 39 - #define SPI_CTL_FCWM 0x00030000 /* Flow-Control Water-Mark */ 40 - #define SPI_CTL_FIFO0 0x00000000 /* FCWM: TFIFO empty or RFIFO Full */ 41 - #define SPI_CTL_FIFO1 0x00010000 /* FCWM: TFIFO 75% or more empty or RFIFO 75% or more full */ 42 - #define SPI_CTL_FIFO2 0x00020000 /* FCWM: TFIFO 50% or more empty or RFIFO 50% or more full */ 43 - #define SPI_CTL_FMODE 0x00040000 /* Fast-mode Enable */ 44 - #define SPI_CTL_MIOM 0x00300000 /* Multiple I/O Mode */ 45 - #define SPI_CTL_MIO_DIS 0x00000000 /* MIOM: Disable */ 46 - #define SPI_CTL_MIO_DUAL 0x00100000 /* MIOM: Enable DIOM (Dual I/O Mode) */ 47 - #define SPI_CTL_MIO_QUAD 0x00200000 /* MIOM: Enable QUAD (Quad SPI Mode) */ 48 - #define SPI_CTL_SOSI 0x00400000 /* Start on MOSI */ 49 - /* SPI_RX_CONTROL */ 50 - #define SPI_RXCTL_REN 0x00000001 /* Receive Channel Enable */ 51 - #define SPI_RXCTL_RTI 0x00000004 /* Receive Transfer Initiate */ 52 - #define SPI_RXCTL_RWCEN 0x00000008 /* Receive Word Counter Enable */ 53 - #define SPI_RXCTL_RDR 0x00000070 /* Receive Data Request */ 54 - #define SPI_RXCTL_RDR_DIS 0x00000000 /* RDR: Disabled */ 55 - #define SPI_RXCTL_RDR_NE 0x00000010 /* RDR: RFIFO not empty */ 56 - #define SPI_RXCTL_RDR_25 0x00000020 /* RDR: RFIFO 25% full */ 57 - #define SPI_RXCTL_RDR_50 0x00000030 /* RDR: RFIFO 50% full */ 58 - #define SPI_RXCTL_RDR_75 0x00000040 /* RDR: RFIFO 75% full */ 59 - #define SPI_RXCTL_RDR_FULL 0x00000050 /* RDR: RFIFO full */ 60 - #define SPI_RXCTL_RDO 0x00000100 /* Receive Data Over-Run */ 61 - #define SPI_RXCTL_RRWM 0x00003000 /* FIFO Regular Water-Mark */ 62 - #define SPI_RXCTL_RWM_0 0x00000000 /* RRWM: RFIFO Empty */ 63 - #define SPI_RXCTL_RWM_25 0x00001000 /* RRWM: RFIFO 25% full */ 64 - #define SPI_RXCTL_RWM_50 0x00002000 /* RRWM: RFIFO 50% full */ 65 - #define SPI_RXCTL_RWM_75 0x00003000 /* RRWM: RFIFO 75% full */ 66 - #define SPI_RXCTL_RUWM 0x00070000 /* FIFO Urgent Water-Mark */ 67 - #define SPI_RXCTL_UWM_DIS 0x00000000 /* RUWM: Disabled */ 68 - #define SPI_RXCTL_UWM_25 0x00010000 /* RUWM: RFIFO 25% full */ 69 - #define SPI_RXCTL_UWM_50 0x00020000 /* RUWM: RFIFO 50% full */ 70 - #define SPI_RXCTL_UWM_75 0x00030000 /* RUWM: RFIFO 75% full */ 71 - #define SPI_RXCTL_UWM_FULL 0x00040000 /* RUWM: RFIFO full */ 72 - /* SPI_TX_CONTROL */ 73 - #define SPI_TXCTL_TEN 0x00000001 /* Transmit Channel Enable */ 74 - #define SPI_TXCTL_TTI 0x00000004 /* Transmit Transfer Initiate */ 75 - #define SPI_TXCTL_TWCEN 0x00000008 /* Transmit Word Counter Enable */ 76 - #define SPI_TXCTL_TDR 0x00000070 /* Transmit Data Request */ 77 - #define SPI_TXCTL_TDR_DIS 0x00000000 /* TDR: Disabled */ 78 - #define SPI_TXCTL_TDR_NF 0x00000010 /* TDR: TFIFO not full */ 79 - #define SPI_TXCTL_TDR_25 0x00000020 /* TDR: TFIFO 25% empty */ 80 - #define SPI_TXCTL_TDR_50 0x00000030 /* TDR: TFIFO 50% empty */ 81 - #define SPI_TXCTL_TDR_75 0x00000040 /* TDR: TFIFO 75% empty */ 82 - #define SPI_TXCTL_TDR_EMPTY 0x00000050 /* TDR: TFIFO empty */ 83 - #define SPI_TXCTL_TDU 0x00000100 /* Transmit Data Under-Run */ 84 - #define SPI_TXCTL_TRWM 0x00003000 /* FIFO Regular Water-Mark */ 85 - #define SPI_TXCTL_RWM_FULL 0x00000000 /* TRWM: TFIFO full */ 86 - #define SPI_TXCTL_RWM_25 0x00001000 /* TRWM: TFIFO 25% empty */ 87 - #define SPI_TXCTL_RWM_50 0x00002000 /* TRWM: TFIFO 50% empty */ 88 - #define SPI_TXCTL_RWM_75 0x00003000 /* TRWM: TFIFO 75% empty */ 89 - #define SPI_TXCTL_TUWM 0x00070000 /* FIFO Urgent Water-Mark */ 90 - #define SPI_TXCTL_UWM_DIS 0x00000000 /* TUWM: Disabled */ 91 - #define SPI_TXCTL_UWM_25 0x00010000 /* TUWM: TFIFO 25% empty */ 92 - #define SPI_TXCTL_UWM_50 0x00020000 /* TUWM: TFIFO 50% empty */ 93 - #define SPI_TXCTL_UWM_75 0x00030000 /* TUWM: TFIFO 75% empty */ 94 - #define SPI_TXCTL_UWM_EMPTY 0x00040000 /* TUWM: TFIFO empty */ 95 - /* SPI_CLOCK */ 96 - #define SPI_CLK_BAUD 0x0000FFFF /* Baud Rate */ 97 - /* SPI_DELAY */ 98 - #define SPI_DLY_STOP 0x000000FF /* Transfer delay time in multiples of SCK period */ 99 - #define SPI_DLY_LEADX 0x00000100 /* Extended (1 SCK) LEAD Control */ 100 - #define SPI_DLY_LAGX 0x00000200 /* Extended (1 SCK) LAG control */ 101 - /* SPI_SSEL */ 102 - #define SPI_SLVSEL_SSE1 0x00000002 /* SPISSEL1 Enable */ 103 - #define SPI_SLVSEL_SSE2 0x00000004 /* SPISSEL2 Enable */ 104 - #define SPI_SLVSEL_SSE3 0x00000008 /* SPISSEL3 Enable */ 105 - #define SPI_SLVSEL_SSE4 0x00000010 /* SPISSEL4 Enable */ 106 - #define SPI_SLVSEL_SSE5 0x00000020 /* SPISSEL5 Enable */ 107 - #define SPI_SLVSEL_SSE6 0x00000040 /* SPISSEL6 Enable */ 108 - #define SPI_SLVSEL_SSE7 0x00000080 /* SPISSEL7 Enable */ 109 - #define SPI_SLVSEL_SSEL1 0x00000200 /* SPISSEL1 Value */ 110 - #define SPI_SLVSEL_SSEL2 0x00000400 /* SPISSEL2 Value */ 111 - #define SPI_SLVSEL_SSEL3 0x00000800 /* SPISSEL3 Value */ 112 - #define SPI_SLVSEL_SSEL4 0x00001000 /* SPISSEL4 Value */ 113 - #define SPI_SLVSEL_SSEL5 0x00002000 /* SPISSEL5 Value */ 114 - #define SPI_SLVSEL_SSEL6 0x00004000 /* SPISSEL6 Value */ 115 - #define SPI_SLVSEL_SSEL7 0x00008000 /* SPISSEL7 Value */ 116 - /* SPI_RWC */ 117 - #define SPI_RWC_VALUE 0x0000FFFF /* Received Word-Count */ 118 - /* SPI_RWCR */ 119 - #define SPI_RWCR_VALUE 0x0000FFFF /* Received Word-Count Reload */ 120 - /* SPI_TWC */ 121 - #define SPI_TWC_VALUE 0x0000FFFF /* Transmitted Word-Count */ 122 - /* SPI_TWCR */ 123 - #define SPI_TWCR_VALUE 0x0000FFFF /* Transmitted Word-Count Reload */ 124 - /* SPI_IMASK */ 125 - #define SPI_IMSK_RUWM 0x00000002 /* Receive Urgent Water-Mark Interrupt Mask */ 126 - #define SPI_IMSK_TUWM 0x00000004 /* Transmit Urgent Water-Mark Interrupt Mask */ 127 - #define SPI_IMSK_ROM 0x00000010 /* Receive Over-Run Error Interrupt Mask */ 128 - #define SPI_IMSK_TUM 0x00000020 /* Transmit Under-Run Error Interrupt Mask */ 129 - #define SPI_IMSK_TCM 0x00000040 /* Transmit Collision Error Interrupt Mask */ 130 - #define SPI_IMSK_MFM 0x00000080 /* Mode Fault Error Interrupt Mask */ 131 - #define SPI_IMSK_RSM 0x00000100 /* Receive Start Interrupt Mask */ 132 - #define SPI_IMSK_TSM 0x00000200 /* Transmit Start Interrupt Mask */ 133 - #define SPI_IMSK_RFM 0x00000400 /* Receive Finish Interrupt Mask */ 134 - #define SPI_IMSK_TFM 0x00000800 /* Transmit Finish Interrupt Mask */ 135 - /* SPI_IMASKCL */ 136 - #define SPI_IMSK_CLR_RUW 0x00000002 /* Receive Urgent Water-Mark Interrupt Mask */ 137 - #define SPI_IMSK_CLR_TUWM 0x00000004 /* Transmit Urgent Water-Mark Interrupt Mask */ 138 - #define SPI_IMSK_CLR_ROM 0x00000010 /* Receive Over-Run Error Interrupt Mask */ 139 - #define SPI_IMSK_CLR_TUM 0x00000020 /* Transmit Under-Run Error Interrupt Mask */ 140 - #define SPI_IMSK_CLR_TCM 0x00000040 /* Transmit Collision Error Interrupt Mask */ 141 - #define SPI_IMSK_CLR_MFM 0x00000080 /* Mode Fault Error Interrupt Mask */ 142 - #define SPI_IMSK_CLR_RSM 0x00000100 /* Receive Start Interrupt Mask */ 143 - #define SPI_IMSK_CLR_TSM 0x00000200 /* Transmit Start Interrupt Mask */ 144 - #define SPI_IMSK_CLR_RFM 0x00000400 /* Receive Finish Interrupt Mask */ 145 - #define SPI_IMSK_CLR_TFM 0x00000800 /* Transmit Finish Interrupt Mask */ 146 - /* SPI_IMASKST */ 147 - #define SPI_IMSK_SET_RUWM 0x00000002 /* Receive Urgent Water-Mark Interrupt Mask */ 148 - #define SPI_IMSK_SET_TUWM 0x00000004 /* Transmit Urgent Water-Mark Interrupt Mask */ 149 - #define SPI_IMSK_SET_ROM 0x00000010 /* Receive Over-Run Error Interrupt Mask */ 150 - #define SPI_IMSK_SET_TUM 0x00000020 /* Transmit Under-Run Error Interrupt Mask */ 151 - #define SPI_IMSK_SET_TCM 0x00000040 /* Transmit Collision Error Interrupt Mask */ 152 - #define SPI_IMSK_SET_MFM 0x00000080 /* Mode Fault Error Interrupt Mask */ 153 - #define SPI_IMSK_SET_RSM 0x00000100 /* Receive Start Interrupt Mask */ 154 - #define SPI_IMSK_SET_TSM 0x00000200 /* Transmit Start Interrupt Mask */ 155 - #define SPI_IMSK_SET_RFM 0x00000400 /* Receive Finish Interrupt Mask */ 156 - #define SPI_IMSK_SET_TFM 0x00000800 /* Transmit Finish Interrupt Mask */ 157 - /* SPI_STATUS */ 158 - #define SPI_STAT_SPIF 0x00000001 /* SPI Finished */ 159 - #define SPI_STAT_RUWM 0x00000002 /* Receive Urgent Water-Mark Breached */ 160 - #define SPI_STAT_TUWM 0x00000004 /* Transmit Urgent Water-Mark Breached */ 161 - #define SPI_STAT_ROE 0x00000010 /* Receive Over-Run Error Indication */ 162 - #define SPI_STAT_TUE 0x00000020 /* Transmit Under-Run Error Indication */ 163 - #define SPI_STAT_TCE 0x00000040 /* Transmit Collision Error Indication */ 164 - #define SPI_STAT_MODF 0x00000080 /* Mode Fault Error Indication */ 165 - #define SPI_STAT_RS 0x00000100 /* Receive Start Indication */ 166 - #define SPI_STAT_TS 0x00000200 /* Transmit Start Indication */ 167 - #define SPI_STAT_RF 0x00000400 /* Receive Finish Indication */ 168 - #define SPI_STAT_TF 0x00000800 /* Transmit Finish Indication */ 169 - #define SPI_STAT_RFS 0x00007000 /* SPI_RFIFO status */ 170 - #define SPI_STAT_RFIFO_EMPTY 0x00000000 /* RFS: RFIFO Empty */ 171 - #define SPI_STAT_RFIFO_25 0x00001000 /* RFS: RFIFO 25% Full */ 172 - #define SPI_STAT_RFIFO_50 0x00002000 /* RFS: RFIFO 50% Full */ 173 - #define SPI_STAT_RFIFO_75 0x00003000 /* RFS: RFIFO 75% Full */ 174 - #define SPI_STAT_RFIFO_FULL 0x00004000 /* RFS: RFIFO Full */ 175 - #define SPI_STAT_TFS 0x00070000 /* SPI_TFIFO status */ 176 - #define SPI_STAT_TFIFO_FULL 0x00000000 /* TFS: TFIFO full */ 177 - #define SPI_STAT_TFIFO_25 0x00010000 /* TFS: TFIFO 25% empty */ 178 - #define SPI_STAT_TFIFO_50 0x00020000 /* TFS: TFIFO 50% empty */ 179 - #define SPI_STAT_TFIFO_75 0x00030000 /* TFS: TFIFO 75% empty */ 180 - #define SPI_STAT_TFIFO_EMPTY 0x00040000 /* TFS: TFIFO empty */ 181 - #define SPI_STAT_FCS 0x00100000 /* Flow-Control Stall Indication */ 182 - #define SPI_STAT_RFE 0x00400000 /* SPI_RFIFO Empty */ 183 - #define SPI_STAT_TFF 0x00800000 /* SPI_TFIFO Full */ 184 - /* SPI_ILAT */ 185 - #define SPI_ILAT_RUWMI 0x00000002 /* Receive Urgent Water Mark Interrupt */ 186 - #define SPI_ILAT_TUWMI 0x00000004 /* Transmit Urgent Water Mark Interrupt */ 187 - #define SPI_ILAT_ROI 0x00000010 /* Receive Over-Run Error Indication */ 188 - #define SPI_ILAT_TUI 0x00000020 /* Transmit Under-Run Error Indication */ 189 - #define SPI_ILAT_TCI 0x00000040 /* Transmit Collision Error Indication */ 190 - #define SPI_ILAT_MFI 0x00000080 /* Mode Fault Error Indication */ 191 - #define SPI_ILAT_RSI 0x00000100 /* Receive Start Indication */ 192 - #define SPI_ILAT_TSI 0x00000200 /* Transmit Start Indication */ 193 - #define SPI_ILAT_RFI 0x00000400 /* Receive Finish Indication */ 194 - #define SPI_ILAT_TFI 0x00000800 /* Transmit Finish Indication */ 195 - /* SPI_ILATCL */ 196 - #define SPI_ILAT_CLR_RUWMI 0x00000002 /* Receive Urgent Water Mark Interrupt */ 197 - #define SPI_ILAT_CLR_TUWMI 0x00000004 /* Transmit Urgent Water Mark Interrupt */ 198 - #define SPI_ILAT_CLR_ROI 0x00000010 /* Receive Over-Run Error Indication */ 199 - #define SPI_ILAT_CLR_TUI 0x00000020 /* Transmit Under-Run Error Indication */ 200 - #define SPI_ILAT_CLR_TCI 0x00000040 /* Transmit Collision Error Indication */ 201 - #define SPI_ILAT_CLR_MFI 0x00000080 /* Mode Fault Error Indication */ 202 - #define SPI_ILAT_CLR_RSI 0x00000100 /* Receive Start Indication */ 203 - #define SPI_ILAT_CLR_TSI 0x00000200 /* Transmit Start Indication */ 204 - #define SPI_ILAT_CLR_RFI 0x00000400 /* Receive Finish Indication */ 205 - #define SPI_ILAT_CLR_TFI 0x00000800 /* Transmit Finish Indication */ 206 - 207 - /* 208 - * adi spi3 registers layout 209 - */ 210 - struct adi_spi_regs { 211 - u32 revid; 212 - u32 control; 213 - u32 rx_control; 214 - u32 tx_control; 215 - u32 clock; 216 - u32 delay; 217 - u32 ssel; 218 - u32 rwc; 219 - u32 rwcr; 220 - u32 twc; 221 - u32 twcr; 222 - u32 reserved0; 223 - u32 emask; 224 - u32 emaskcl; 225 - u32 emaskst; 226 - u32 reserved1; 227 - u32 status; 228 - u32 elat; 229 - u32 elatcl; 230 - u32 reserved2; 231 - u32 rfifo; 232 - u32 reserved3; 233 - u32 tfifo; 234 - }; 235 - 236 - #define MAX_CTRL_CS 8 /* cs in spi controller */ 237 - 238 - /* device.platform_data for SSP controller devices */ 239 - struct adi_spi3_master { 240 - u16 num_chipselect; 241 - u16 pin_req[7]; 242 - }; 243 - 244 - /* spi_board_info.controller_data for SPI slave devices, 245 - * copied to spi_device.platform_data ... mostly for dma tuning 246 - */ 247 - struct adi_spi3_chip { 248 - u32 control; 249 - u16 cs_chg_udelay; /* Some devices require 16-bit delays */ 250 - u32 tx_dummy_val; /* tx value for rx only transfer */ 251 - bool enable_dma; 252 - }; 253 - 254 - #endif /* _ADI_SPI3_H_ */
+13 -1
include/linux/spi/spi-mem.h
··· 124 124 /** 125 125 * struct spi_mem - describes a SPI memory device 126 126 * @spi: the underlying SPI device 127 - * @drvpriv: spi_mem_drviver private data 127 + * @drvpriv: spi_mem_driver private data 128 + * @name: name of the SPI memory device 128 129 * 129 130 * Extra information that describe the SPI memory device and may be needed by 130 131 * the controller to properly handle this device should be placed here. ··· 136 135 struct spi_mem { 137 136 struct spi_device *spi; 138 137 void *drvpriv; 138 + const char *name; 139 139 }; 140 140 141 141 /** ··· 169 167 * limitations) 170 168 * @supports_op: check if an operation is supported by the controller 171 169 * @exec_op: execute a SPI memory operation 170 + * @get_name: get a custom name for the SPI mem device from the controller. 171 + * This might be needed if the controller driver has been ported 172 + * to use the SPI mem layer and a custom name is used to keep 173 + * mtdparts compatible. 174 + * Note that if the implementation of this function allocates memory 175 + * dynamically, then it should do so with devm_xxx(), as we don't 176 + * have a ->free_name() function. 172 177 * 173 178 * This interface should be implemented by SPI controllers providing an 174 179 * high-level interface to execute SPI memory operation, which is usually the ··· 187 178 const struct spi_mem_op *op); 188 179 int (*exec_op)(struct spi_mem *mem, 189 180 const struct spi_mem_op *op); 181 + const char *(*get_name)(struct spi_mem *mem); 190 182 }; 191 183 192 184 /** ··· 245 235 246 236 int spi_mem_exec_op(struct spi_mem *mem, 247 237 const struct spi_mem_op *op); 238 + 239 + const char *spi_mem_get_name(struct spi_mem *mem); 248 240 249 241 int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv, 250 242 struct module *owner);
+3 -2
include/linux/spi/spi_bitbang.h
··· 8 8 struct mutex lock; 9 9 u8 busy; 10 10 u8 use_dma; 11 - u8 flags; /* extra spi->mode support */ 11 + u16 flags; /* extra spi->mode support */ 12 12 13 13 struct spi_master *master; 14 14 ··· 30 30 /* txrx_word[SPI_MODE_*]() just looks like a shift register */ 31 31 u32 (*txrx_word[4])(struct spi_device *spi, 32 32 unsigned nsecs, 33 - u32 word, u8 bits); 33 + u32 word, u8 bits, unsigned flags); 34 + int (*set_line_direction)(struct spi_device *spi, bool output); 34 35 }; 35 36 36 37 /* you can call these default bitbang->master methods from your custom