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

Merge tag 'spi-v3.16' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi into next

Pull spi updates from Mark Brown:
"For this release SPI has been exceptionally quiet, all the work has
been on improving drivers (including taking advantage of some of the
recent framework updates):

- DMA support for the rspi driver providing a nice performance boost
- performance improvement for the SIRF controller in PIO mode
- new support for the Cadence SPI IP and for pxa2xx on BayTrail"

* tag 'spi-v3.16' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (59 commits)
spi: rspi: Extract rspi_common_transfer()
spi: rspi: Add DMA support for RSPI on RZ/A1H
spi: rspi: Add DMA support for QSPI on R-Car Gen2
spi: rspi: Absorb rspi_rz_transfer_out_in() into rspi_rz_transfer_one()
spi: rspi: Merge rspi_*_dma() into rspi_dma_transfer()
spi: rspi: Pass sg_tables instead of spi_tranfer to rspi_*_dma()
spi: rspi: Move RSPI-specific setup out of DMA routines
spi: rspi: Use SPI core DMA mapping framework
spi: rspi: SPI DMA core needs both RX and TX DMA to function
spi: rspi: Remove unneeded resource test in DMA setup
spi: rspi: Extract rspi_request_dma_chan()
spi: rspi: Don't consider DMA configuration failures fatal
spi: rspi: Extract rspi_pio_transfer()
spi: rspi: Use core SPI_MASTER_MUST_[RT]X handling
spi: rspi: Remove unused 16-bit DMA support
spi: rspi: Do not call rspi_receive_init() for TX-only
spi: rspi: Extract rspi_wait_for_{tx_empty,rx_full}()
spi/pxa2xx: fix runtime PM enabling order
spi/fsl-espi: fix rx_buf in fsl_espi_cmd_trans()/fsl_espi_rw_trans()
spi: core: Ignore unsupported spi-[tr]x-bus-width property values
...

+1579 -1049
+6
Documentation/devicetree/bindings/spi/fsl-spi.txt
··· 42 42 - interrupts : should contain eSPI interrupt, the device has one interrupt. 43 43 - fsl,espi-num-chipselects : the number of the chipselect signals. 44 44 45 + Optional properties: 46 + - fsl,csbef: chip select assertion time in bits before frame starts 47 + - fsl,csaft: chip select negation time in bits after frame ends 48 + 45 49 Example: 46 50 spi@110000 { 47 51 #address-cells = <1>; ··· 55 51 interrupts = <53 0x2>; 56 52 interrupt-parent = <&mpic>; 57 53 fsl,espi-num-chipselects = <4>; 54 + fsl,csbef = <1>; 55 + fsl,csaft = <1>; 58 56 };
+2
Documentation/devicetree/bindings/spi/spi-bus.txt
··· 55 55 chip select active high 56 56 - spi-3wire - (optional) Empty property indicating device requires 57 57 3-wire mode. 58 + - spi-lsb-first - (optional) Empty property indicating device requires 59 + LSB first mode. 58 60 - spi-tx-bus-width - (optional) The bus width(number of data wires) that 59 61 used for MOSI. Defaults to 1 if not present. 60 62 - spi-rx-bus-width - (optional) The bus width(number of data wires) that
+31
Documentation/devicetree/bindings/spi/spi-cadence.txt
··· 1 + Cadence SPI controller Device Tree Bindings 2 + ------------------------------------------- 3 + 4 + Required properties: 5 + - compatible : Should be "cdns,spi-r1p6" or "xlnx,zynq-spi-r1p6". 6 + - reg : Physical base address and size of SPI registers map. 7 + - interrupts : Property with a value describing the interrupt 8 + number. 9 + - interrupt-parent : Must be core interrupt controller 10 + - clock-names : List of input clock names - "ref_clk", "pclk" 11 + (See clock bindings for details). 12 + - clocks : Clock phandles (see clock bindings for details). 13 + 14 + Optional properties: 15 + - num-cs : Number of chip selects used. 16 + If a decoder is used, this will be the number of 17 + chip selects after the decoder. 18 + - is-decoded-cs : Flag to indicate whether decoder is used or not. 19 + 20 + Example: 21 + 22 + spi@e0007000 { 23 + compatible = "xlnx,zynq-spi-r1p6"; 24 + clock-names = "ref_clk", "pclk"; 25 + clocks = <&clkc 26>, <&clkc 35>; 26 + interrupt-parent = <&intc>; 27 + interrupts = <0 49 4>; 28 + num-cs = <4>; 29 + is-decoded-cs = <0>; 30 + reg = <0xe0007000 0x1000>; 31 + } ;
+24
Documentation/devicetree/bindings/spi/spi-dw.txt
··· 1 + Synopsys DesignWare SPI master 2 + 3 + Required properties: 4 + - compatible: should be "snps,designware-spi" 5 + - #address-cells: see spi-bus.txt 6 + - #size-cells: see spi-bus.txt 7 + - reg: address and length of the spi master registers 8 + - interrupts: should contain one interrupt 9 + - clocks: spi clock phandle 10 + - num-cs: see spi-bus.txt 11 + 12 + Optional properties: 13 + - cs-gpios: see spi-bus.txt 14 + 15 + Example: 16 + 17 + spi: spi@4020a000 { 18 + compatible = "snps,designware-spi"; 19 + interrupts = <11 1>; 20 + reg = <0x4020a000 0x1000>; 21 + clocks = <&pclk>; 22 + num-cs = <2>; 23 + cs-gpios = <&banka 0 0>; 24 + };
+8 -12
arch/blackfin/include/asm/bfin_spi3.h include/linux/spi/adi_spi3.h
··· 1 1 /* 2 2 * Analog Devices SPI3 controller driver 3 3 * 4 - * Copyright (c) 2011 Analog Devices Inc. 4 + * Copyright (c) 2014 Analog Devices Inc. 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify 7 7 * it under the terms of the GNU General Public License version 2 as ··· 11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 13 * GNU General Public License for more details. 14 - * 15 - * You should have received a copy of the GNU General Public License 16 - * along with this program; if not, write to the Free Software 17 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 14 */ 19 15 20 - #ifndef _SPI_CHANNEL_H_ 21 - #define _SPI_CHANNEL_H_ 16 + #ifndef _ADI_SPI3_H_ 17 + #define _ADI_SPI3_H_ 22 18 23 19 #include <linux/types.h> 24 20 ··· 205 209 #define SPI_ILAT_CLR_TFI 0x00000800 /* Transmit Finish Indication */ 206 210 207 211 /* 208 - * bfin spi3 registers layout 212 + * adi spi3 registers layout 209 213 */ 210 - struct bfin_spi_regs { 214 + struct adi_spi_regs { 211 215 u32 revid; 212 216 u32 control; 213 217 u32 rx_control; ··· 236 240 #define MAX_CTRL_CS 8 /* cs in spi controller */ 237 241 238 242 /* device.platform_data for SSP controller devices */ 239 - struct bfin_spi3_master { 243 + struct adi_spi3_master { 240 244 u16 num_chipselect; 241 245 u16 pin_req[7]; 242 246 }; ··· 244 248 /* spi_board_info.controller_data for SPI slave devices, 245 249 * copied to spi_device.platform_data ... mostly for dma tuning 246 250 */ 247 - struct bfin_spi3_chip { 251 + struct adi_spi3_chip { 248 252 u32 control; 249 253 u16 cs_chg_udelay; /* Some devices require 16-bit delays */ 250 254 u32 tx_dummy_val; /* tx value for rx only transfer */ 251 255 bool enable_dma; 252 256 }; 253 257 254 - #endif /* _SPI_CHANNEL_H_ */ 258 + #endif /* _ADI_SPI3_H_ */
+11 -11
arch/blackfin/mach-bf609/boards/ezkit.c
··· 20 20 #include <linux/pinctrl/machine.h> 21 21 #include <linux/pinctrl/pinconf-generic.h> 22 22 #include <linux/platform_data/pinctrl-adi2.h> 23 - #include <asm/bfin_spi3.h> 23 + #include <linux/spi/adi_spi3.h> 24 24 #include <asm/dma.h> 25 25 #include <asm/gpio.h> 26 26 #include <asm/nand.h> ··· 767 767 .type = "w25q32", 768 768 }; 769 769 770 - static struct bfin_spi3_chip spi_flash_chip_info = { 770 + static struct adi_spi3_chip spi_flash_chip_info = { 771 771 .enable_dma = true, /* use dma transfer with this chip*/ 772 772 }; 773 773 #endif 774 774 775 775 #if IS_ENABLED(CONFIG_SPI_SPIDEV) 776 - static struct bfin_spi3_chip spidev_chip_info = { 776 + static struct adi_spi3_chip spidev_chip_info = { 777 777 .enable_dma = true, 778 778 }; 779 779 #endif ··· 1736 1736 }, 1737 1737 #endif 1738 1738 }; 1739 - #if IS_ENABLED(CONFIG_SPI_BFIN_V3) 1739 + #if IS_ENABLED(CONFIG_SPI_ADI_V3) 1740 1740 /* SPI (0) */ 1741 1741 static struct resource bfin_spi0_resource[] = { 1742 1742 { ··· 1777 1777 }; 1778 1778 1779 1779 /* SPI controller data */ 1780 - static struct bfin_spi3_master bf60x_spi_master_info0 = { 1780 + static struct adi_spi3_master bf60x_spi_master_info0 = { 1781 1781 .num_chipselect = MAX_CTRL_CS + MAX_BLACKFIN_GPIOS, 1782 1782 .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0}, 1783 1783 }; 1784 1784 1785 1785 static struct platform_device bf60x_spi_master0 = { 1786 - .name = "bfin-spi3", 1786 + .name = "adi-spi3", 1787 1787 .id = 0, /* Bus number */ 1788 1788 .num_resources = ARRAY_SIZE(bfin_spi0_resource), 1789 1789 .resource = bfin_spi0_resource, ··· 1792 1792 }, 1793 1793 }; 1794 1794 1795 - static struct bfin_spi3_master bf60x_spi_master_info1 = { 1795 + static struct adi_spi3_master bf60x_spi_master_info1 = { 1796 1796 .num_chipselect = MAX_CTRL_CS + MAX_BLACKFIN_GPIOS, 1797 1797 .pin_req = {P_SPI1_SCK, P_SPI1_MISO, P_SPI1_MOSI, 0}, 1798 1798 }; 1799 1799 1800 1800 static struct platform_device bf60x_spi_master1 = { 1801 - .name = "bfin-spi3", 1801 + .name = "adi-spi3", 1802 1802 .id = 1, /* Bus number */ 1803 1803 .num_resources = ARRAY_SIZE(bfin_spi1_resource), 1804 1804 .resource = bfin_spi1_resource, ··· 1990 1990 &bfin_sdh_device, 1991 1991 #endif 1992 1992 1993 - #if IS_ENABLED(CONFIG_SPI_BFIN_V3) 1993 + #if IS_ENABLED(CONFIG_SPI_ADI_V3) 1994 1994 &bf60x_spi_master0, 1995 1995 &bf60x_spi_master1, 1996 1996 #endif ··· 2051 2051 PIN_MAP_MUX_GROUP_DEFAULT("bfin_sir.1", "pinctrl-adi2.0", NULL, "uart1"), 2052 2052 PIN_MAP_MUX_GROUP_DEFAULT("bfin-sdh.0", "pinctrl-adi2.0", NULL, "rsi0"), 2053 2053 PIN_MAP_MUX_GROUP_DEFAULT("stmmaceth.0", "pinctrl-adi2.0", NULL, "eth0"), 2054 - PIN_MAP_MUX_GROUP_DEFAULT("bfin-spi3.0", "pinctrl-adi2.0", NULL, "spi0"), 2055 - PIN_MAP_MUX_GROUP_DEFAULT("bfin-spi3.1", "pinctrl-adi2.0", NULL, "spi1"), 2054 + PIN_MAP_MUX_GROUP_DEFAULT("adi-spi3.0", "pinctrl-adi2.0", NULL, "spi0"), 2055 + PIN_MAP_MUX_GROUP_DEFAULT("adi-spi3.1", "pinctrl-adi2.0", NULL, "spi1"), 2056 2056 PIN_MAP_MUX_GROUP_DEFAULT("i2c-bfin-twi.0", "pinctrl-adi2.0", NULL, "twi0"), 2057 2057 PIN_MAP_MUX_GROUP_DEFAULT("i2c-bfin-twi.1", "pinctrl-adi2.0", NULL, "twi1"), 2058 2058 PIN_MAP_MUX_GROUP_DEFAULT("bfin-rotary", "pinctrl-adi2.0", NULL, "rotary"),
+7
arch/blackfin/mach-bf609/clock.c
··· 363 363 .ops = &dummy_clk_ops, 364 364 }; 365 365 366 + static struct clk spiclk = { 367 + .name = "spi", 368 + .parent = &sclk1, 369 + .ops = &dummy_clk_ops, 370 + }; 371 + 366 372 static struct clk_lookup bf609_clks[] = { 367 373 CLK(sys_clkin, NULL, "SYS_CLKIN"), 368 374 CLK(pll_clk, NULL, "PLLCLK"), ··· 381 375 CLK(dclk, NULL, "DCLK"), 382 376 CLK(oclk, NULL, "OCLK"), 383 377 CLK(ethclk, NULL, "stmmaceth"), 378 + CLK(spiclk, NULL, "spi"), 384 379 }; 385 380 386 381 int __init clk_init(void)
+10 -3
drivers/spi/Kconfig
··· 91 91 help 92 92 This is the SPI controller master driver for Blackfin 5xx processor. 93 93 94 - config SPI_BFIN_V3 95 - tristate "SPI controller v3 for Blackfin" 94 + config SPI_ADI_V3 95 + tristate "SPI controller v3 for ADI" 96 96 depends on BF60x 97 97 help 98 98 This is the SPI controller v3 master driver ··· 147 147 Butterfly <http://www.atmel.com/products/avr/butterfly>, an 148 148 inexpensive battery powered microcontroller evaluation board. 149 149 This same cable can be used to flash new firmware. 150 + 151 + config SPI_CADENCE 152 + tristate "Cadence SPI controller" 153 + depends on ARM 154 + help 155 + This selects the Cadence SPI controller master driver 156 + used by Xilinx Zynq. 150 157 151 158 config SPI_CLPS711X 152 159 tristate "CLPS711X host SPI controller" ··· 512 505 513 506 config SPI_TOPCLIFF_PCH 514 507 tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) SPI" 515 - depends on PCI 508 + depends on PCI && (X86_32 || COMPILE_TEST) 516 509 help 517 510 SPI driver for the Topcliff PCH (Platform Controller Hub) SPI bus 518 511 used in some x86 embedded processors.
+2 -1
drivers/spi/Makefile
··· 18 18 obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o 19 19 obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o 20 20 obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o 21 - obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o 21 + obj-$(CONFIG_SPI_ADI_V3) += spi-adi-v3.o 22 22 obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o 23 23 obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o 24 24 obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o 25 + obj-$(CONFIG_SPI_CADENCE) += spi-cadence.o 25 26 obj-$(CONFIG_SPI_CLPS711X) += spi-clps711x.o 26 27 obj-$(CONFIG_SPI_COLDFIRE_QSPI) += spi-coldfire-qspi.o 27 28 obj-$(CONFIG_SPI_DAVINCI) += spi-davinci.o
-1
drivers/spi/spi-ath79.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/delay.h> 18 18 #include <linux/spinlock.h> 19 - #include <linux/workqueue.h> 20 19 #include <linux/platform_device.h> 21 20 #include <linux/io.h> 22 21 #include <linux/spi/spi.h>
+6 -3
drivers/spi/spi-atmel.c
··· 224 224 struct platform_device *pdev; 225 225 226 226 struct spi_transfer *current_transfer; 227 - unsigned long current_remaining_bytes; 227 + int current_remaining_bytes; 228 228 int done_status; 229 229 230 230 struct completion xfer_completion; ··· 874 874 spi_readl(as, RDR); 875 875 } 876 876 if (xfer->bits_per_word > 8) { 877 - as->current_remaining_bytes -= 2; 878 - if (as->current_remaining_bytes < 0) 877 + if (as->current_remaining_bytes > 2) 878 + as->current_remaining_bytes -= 2; 879 + else 879 880 as->current_remaining_bytes = 0; 880 881 } else { 881 882 as->current_remaining_bytes--; ··· 1111 1110 atmel_spi_next_xfer_pio(master, xfer); 1112 1111 } else { 1113 1112 as->current_remaining_bytes -= len; 1113 + if (as->current_remaining_bytes < 0) 1114 + as->current_remaining_bytes = 0; 1114 1115 } 1115 1116 } else { 1116 1117 atmel_spi_next_xfer_pio(master, xfer);
-1
drivers/spi/spi-bcm63xx-hsspi.c
··· 18 18 #include <linux/err.h> 19 19 #include <linux/interrupt.h> 20 20 #include <linux/spi/spi.h> 21 - #include <linux/workqueue.h> 22 21 #include <linux/mutex.h> 23 22 24 23 #define HSSPI_GLOBAL_CTRL_REG 0x0
-1
drivers/spi/spi-bcm63xx.c
··· 29 29 #include <linux/spi/spi.h> 30 30 #include <linux/completion.h> 31 31 #include <linux/err.h> 32 - #include <linux/workqueue.h> 33 32 #include <linux/pm_runtime.h> 34 33 35 34 #include <bcm63xx_dev_spi.h>
+227 -206
drivers/spi/spi-bfin-v3.c drivers/spi/spi-adi-v3.c
··· 1 1 /* 2 2 * Analog Devices SPI3 controller driver 3 3 * 4 - * Copyright (c) 2013 Analog Devices Inc. 4 + * Copyright (c) 2014 Analog Devices Inc. 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify 7 7 * it under the terms of the GNU General Public License version 2 as ··· 13 13 * GNU General Public License for more details. 14 14 */ 15 15 16 + #include <linux/clk.h> 16 17 #include <linux/delay.h> 17 18 #include <linux/device.h> 18 19 #include <linux/dma-mapping.h> ··· 27 26 #include <linux/platform_device.h> 28 27 #include <linux/slab.h> 29 28 #include <linux/spi/spi.h> 29 + #include <linux/spi/adi_spi3.h> 30 30 #include <linux/types.h> 31 31 32 - #include <asm/bfin_spi3.h> 33 - #include <asm/cacheflush.h> 34 32 #include <asm/dma.h> 35 33 #include <asm/portmux.h> 36 34 37 - enum bfin_spi_state { 35 + enum adi_spi_state { 38 36 START_STATE, 39 37 RUNNING_STATE, 40 38 DONE_STATE, 41 39 ERROR_STATE 42 40 }; 43 41 44 - struct bfin_spi_master; 42 + struct adi_spi_master; 45 43 46 - struct bfin_spi_transfer_ops { 47 - void (*write) (struct bfin_spi_master *); 48 - void (*read) (struct bfin_spi_master *); 49 - void (*duplex) (struct bfin_spi_master *); 44 + struct adi_spi_transfer_ops { 45 + void (*write) (struct adi_spi_master *); 46 + void (*read) (struct adi_spi_master *); 47 + void (*duplex) (struct adi_spi_master *); 50 48 }; 51 49 52 50 /* runtime info for spi master */ 53 - struct bfin_spi_master { 51 + struct adi_spi_master { 54 52 /* SPI framework hookup */ 55 53 struct spi_master *master; 56 54 57 55 /* Regs base of SPI controller */ 58 - struct bfin_spi_regs __iomem *regs; 56 + struct adi_spi_regs __iomem *regs; 59 57 60 58 /* Pin request list */ 61 59 u16 *pin_req; ··· 65 65 /* Current message transfer state info */ 66 66 struct spi_message *cur_msg; 67 67 struct spi_transfer *cur_transfer; 68 - struct bfin_spi_device *cur_chip; 68 + struct adi_spi_device *cur_chip; 69 69 unsigned transfer_len; 70 70 71 71 /* transfer buffer */ ··· 90 90 u32 ssel; 91 91 92 92 unsigned long sclk; 93 - enum bfin_spi_state state; 93 + enum adi_spi_state state; 94 94 95 - const struct bfin_spi_transfer_ops *ops; 95 + const struct adi_spi_transfer_ops *ops; 96 96 }; 97 97 98 - struct bfin_spi_device { 98 + struct adi_spi_device { 99 99 u32 control; 100 100 u32 clock; 101 101 u32 ssel; ··· 105 105 u32 cs_gpio; 106 106 u32 tx_dummy_val; /* tx value for rx only transfer */ 107 107 bool enable_dma; 108 - const struct bfin_spi_transfer_ops *ops; 108 + const struct adi_spi_transfer_ops *ops; 109 109 }; 110 110 111 - static void bfin_spi_enable(struct bfin_spi_master *drv_data) 111 + static void adi_spi_enable(struct adi_spi_master *drv_data) 112 112 { 113 - bfin_write_or(&drv_data->regs->control, SPI_CTL_EN); 113 + u32 ctl; 114 + 115 + ctl = ioread32(&drv_data->regs->control); 116 + ctl |= SPI_CTL_EN; 117 + iowrite32(ctl, &drv_data->regs->control); 114 118 } 115 119 116 - static void bfin_spi_disable(struct bfin_spi_master *drv_data) 120 + static void adi_spi_disable(struct adi_spi_master *drv_data) 117 121 { 118 - bfin_write_and(&drv_data->regs->control, ~SPI_CTL_EN); 122 + u32 ctl; 123 + 124 + ctl = ioread32(&drv_data->regs->control); 125 + ctl &= ~SPI_CTL_EN; 126 + iowrite32(ctl, &drv_data->regs->control); 119 127 } 120 128 121 129 /* Caculate the SPI_CLOCK register value based on input HZ */ ··· 136 128 return spi_clock; 137 129 } 138 130 139 - static int bfin_spi_flush(struct bfin_spi_master *drv_data) 131 + static int adi_spi_flush(struct adi_spi_master *drv_data) 140 132 { 141 133 unsigned long limit = loops_per_jiffy << 1; 142 134 143 135 /* wait for stop and clear stat */ 144 - while (!(bfin_read(&drv_data->regs->status) & SPI_STAT_SPIF) && --limit) 136 + while (!(ioread32(&drv_data->regs->status) & SPI_STAT_SPIF) && --limit) 145 137 cpu_relax(); 146 138 147 - bfin_write(&drv_data->regs->status, 0xFFFFFFFF); 139 + iowrite32(0xFFFFFFFF, &drv_data->regs->status); 148 140 149 141 return limit; 150 142 } 151 143 152 144 /* Chip select operation functions for cs_change flag */ 153 - static void bfin_spi_cs_active(struct bfin_spi_master *drv_data, struct bfin_spi_device *chip) 145 + static void adi_spi_cs_active(struct adi_spi_master *drv_data, struct adi_spi_device *chip) 154 146 { 155 - if (likely(chip->cs < MAX_CTRL_CS)) 156 - bfin_write_and(&drv_data->regs->ssel, ~chip->ssel); 157 - else 147 + if (likely(chip->cs < MAX_CTRL_CS)) { 148 + u32 reg; 149 + reg = ioread32(&drv_data->regs->ssel); 150 + reg &= ~chip->ssel; 151 + iowrite32(reg, &drv_data->regs->ssel); 152 + } else { 158 153 gpio_set_value(chip->cs_gpio, 0); 154 + } 159 155 } 160 156 161 - static void bfin_spi_cs_deactive(struct bfin_spi_master *drv_data, 162 - struct bfin_spi_device *chip) 157 + static void adi_spi_cs_deactive(struct adi_spi_master *drv_data, 158 + struct adi_spi_device *chip) 163 159 { 164 - if (likely(chip->cs < MAX_CTRL_CS)) 165 - bfin_write_or(&drv_data->regs->ssel, chip->ssel); 166 - else 160 + if (likely(chip->cs < MAX_CTRL_CS)) { 161 + u32 reg; 162 + reg = ioread32(&drv_data->regs->ssel); 163 + reg |= chip->ssel; 164 + iowrite32(reg, &drv_data->regs->ssel); 165 + } else { 167 166 gpio_set_value(chip->cs_gpio, 1); 167 + } 168 168 169 169 /* Move delay here for consistency */ 170 170 if (chip->cs_chg_udelay) ··· 180 164 } 181 165 182 166 /* enable or disable the pin muxed by GPIO and SPI CS to work as SPI CS */ 183 - static inline void bfin_spi_cs_enable(struct bfin_spi_master *drv_data, 184 - struct bfin_spi_device *chip) 167 + static inline void adi_spi_cs_enable(struct adi_spi_master *drv_data, 168 + struct adi_spi_device *chip) 185 169 { 186 - if (chip->cs < MAX_CTRL_CS) 187 - bfin_write_or(&drv_data->regs->ssel, chip->ssel >> 8); 170 + if (chip->cs < MAX_CTRL_CS) { 171 + u32 reg; 172 + reg = ioread32(&drv_data->regs->ssel); 173 + reg |= chip->ssel >> 8; 174 + iowrite32(reg, &drv_data->regs->ssel); 175 + } 188 176 } 189 177 190 - static inline void bfin_spi_cs_disable(struct bfin_spi_master *drv_data, 191 - struct bfin_spi_device *chip) 178 + static inline void adi_spi_cs_disable(struct adi_spi_master *drv_data, 179 + struct adi_spi_device *chip) 192 180 { 193 - if (chip->cs < MAX_CTRL_CS) 194 - bfin_write_and(&drv_data->regs->ssel, ~(chip->ssel >> 8)); 181 + if (chip->cs < MAX_CTRL_CS) { 182 + u32 reg; 183 + reg = ioread32(&drv_data->regs->ssel); 184 + reg &= ~(chip->ssel >> 8); 185 + iowrite32(reg, &drv_data->regs->ssel); 186 + } 195 187 } 196 188 197 189 /* stop controller and re-config current chip*/ 198 - static void bfin_spi_restore_state(struct bfin_spi_master *drv_data) 190 + static void adi_spi_restore_state(struct adi_spi_master *drv_data) 199 191 { 200 - struct bfin_spi_device *chip = drv_data->cur_chip; 192 + struct adi_spi_device *chip = drv_data->cur_chip; 201 193 202 194 /* Clear status and disable clock */ 203 - bfin_write(&drv_data->regs->status, 0xFFFFFFFF); 204 - bfin_write(&drv_data->regs->rx_control, 0x0); 205 - bfin_write(&drv_data->regs->tx_control, 0x0); 206 - bfin_spi_disable(drv_data); 207 - 208 - SSYNC(); 195 + iowrite32(0xFFFFFFFF, &drv_data->regs->status); 196 + iowrite32(0x0, &drv_data->regs->rx_control); 197 + iowrite32(0x0, &drv_data->regs->tx_control); 198 + adi_spi_disable(drv_data); 209 199 210 200 /* Load the registers */ 211 - bfin_write(&drv_data->regs->control, chip->control); 212 - bfin_write(&drv_data->regs->clock, chip->clock); 201 + iowrite32(chip->control, &drv_data->regs->control); 202 + iowrite32(chip->clock, &drv_data->regs->clock); 213 203 214 - bfin_spi_enable(drv_data); 204 + adi_spi_enable(drv_data); 215 205 drv_data->tx_num = drv_data->rx_num = 0; 216 206 /* we always choose tx transfer initiate */ 217 - bfin_write(&drv_data->regs->rx_control, SPI_RXCTL_REN); 218 - bfin_write(&drv_data->regs->tx_control, 219 - SPI_TXCTL_TEN | SPI_TXCTL_TTI); 220 - bfin_spi_cs_active(drv_data, chip); 207 + iowrite32(SPI_RXCTL_REN, &drv_data->regs->rx_control); 208 + iowrite32(SPI_TXCTL_TEN | SPI_TXCTL_TTI, &drv_data->regs->tx_control); 209 + adi_spi_cs_active(drv_data, chip); 221 210 } 222 211 223 212 /* discard invalid rx data and empty rfifo */ 224 - static inline void dummy_read(struct bfin_spi_master *drv_data) 213 + static inline void dummy_read(struct adi_spi_master *drv_data) 225 214 { 226 - while (!(bfin_read(&drv_data->regs->status) & SPI_STAT_RFE)) 227 - bfin_read(&drv_data->regs->rfifo); 215 + while (!(ioread32(&drv_data->regs->status) & SPI_STAT_RFE)) 216 + ioread32(&drv_data->regs->rfifo); 228 217 } 229 218 230 - static void bfin_spi_u8_write(struct bfin_spi_master *drv_data) 219 + static void adi_spi_u8_write(struct adi_spi_master *drv_data) 231 220 { 232 221 dummy_read(drv_data); 233 222 while (drv_data->tx < drv_data->tx_end) { 234 - bfin_write(&drv_data->regs->tfifo, (*(u8 *)(drv_data->tx++))); 235 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 223 + iowrite32(*(u8 *)(drv_data->tx++), &drv_data->regs->tfifo); 224 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 236 225 cpu_relax(); 237 - bfin_read(&drv_data->regs->rfifo); 226 + ioread32(&drv_data->regs->rfifo); 238 227 } 239 228 } 240 229 241 - static void bfin_spi_u8_read(struct bfin_spi_master *drv_data) 230 + static void adi_spi_u8_read(struct adi_spi_master *drv_data) 242 231 { 243 232 u32 tx_val = drv_data->cur_chip->tx_dummy_val; 244 233 245 234 dummy_read(drv_data); 246 235 while (drv_data->rx < drv_data->rx_end) { 247 - bfin_write(&drv_data->regs->tfifo, tx_val); 248 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 236 + iowrite32(tx_val, &drv_data->regs->tfifo); 237 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 249 238 cpu_relax(); 250 - *(u8 *)(drv_data->rx++) = bfin_read(&drv_data->regs->rfifo); 239 + *(u8 *)(drv_data->rx++) = ioread32(&drv_data->regs->rfifo); 251 240 } 252 241 } 253 242 254 - static void bfin_spi_u8_duplex(struct bfin_spi_master *drv_data) 243 + static void adi_spi_u8_duplex(struct adi_spi_master *drv_data) 255 244 { 256 245 dummy_read(drv_data); 257 246 while (drv_data->rx < drv_data->rx_end) { 258 - bfin_write(&drv_data->regs->tfifo, (*(u8 *)(drv_data->tx++))); 259 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 247 + iowrite32(*(u8 *)(drv_data->tx++), &drv_data->regs->tfifo); 248 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 260 249 cpu_relax(); 261 - *(u8 *)(drv_data->rx++) = bfin_read(&drv_data->regs->rfifo); 250 + *(u8 *)(drv_data->rx++) = ioread32(&drv_data->regs->rfifo); 262 251 } 263 252 } 264 253 265 - static const struct bfin_spi_transfer_ops bfin_bfin_spi_transfer_ops_u8 = { 266 - .write = bfin_spi_u8_write, 267 - .read = bfin_spi_u8_read, 268 - .duplex = bfin_spi_u8_duplex, 254 + static const struct adi_spi_transfer_ops adi_spi_transfer_ops_u8 = { 255 + .write = adi_spi_u8_write, 256 + .read = adi_spi_u8_read, 257 + .duplex = adi_spi_u8_duplex, 269 258 }; 270 259 271 - static void bfin_spi_u16_write(struct bfin_spi_master *drv_data) 260 + static void adi_spi_u16_write(struct adi_spi_master *drv_data) 272 261 { 273 262 dummy_read(drv_data); 274 263 while (drv_data->tx < drv_data->tx_end) { 275 - bfin_write(&drv_data->regs->tfifo, (*(u16 *)drv_data->tx)); 264 + iowrite32(*(u16 *)drv_data->tx, &drv_data->regs->tfifo); 276 265 drv_data->tx += 2; 277 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 266 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 278 267 cpu_relax(); 279 - bfin_read(&drv_data->regs->rfifo); 268 + ioread32(&drv_data->regs->rfifo); 280 269 } 281 270 } 282 271 283 - static void bfin_spi_u16_read(struct bfin_spi_master *drv_data) 272 + static void adi_spi_u16_read(struct adi_spi_master *drv_data) 284 273 { 285 274 u32 tx_val = drv_data->cur_chip->tx_dummy_val; 286 275 287 276 dummy_read(drv_data); 288 277 while (drv_data->rx < drv_data->rx_end) { 289 - bfin_write(&drv_data->regs->tfifo, tx_val); 290 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 278 + iowrite32(tx_val, &drv_data->regs->tfifo); 279 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 291 280 cpu_relax(); 292 - *(u16 *)drv_data->rx = bfin_read(&drv_data->regs->rfifo); 281 + *(u16 *)drv_data->rx = ioread32(&drv_data->regs->rfifo); 293 282 drv_data->rx += 2; 294 283 } 295 284 } 296 285 297 - static void bfin_spi_u16_duplex(struct bfin_spi_master *drv_data) 286 + static void adi_spi_u16_duplex(struct adi_spi_master *drv_data) 298 287 { 299 288 dummy_read(drv_data); 300 289 while (drv_data->rx < drv_data->rx_end) { 301 - bfin_write(&drv_data->regs->tfifo, (*(u16 *)drv_data->tx)); 290 + iowrite32(*(u16 *)drv_data->tx, &drv_data->regs->tfifo); 302 291 drv_data->tx += 2; 303 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 292 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 304 293 cpu_relax(); 305 - *(u16 *)drv_data->rx = bfin_read(&drv_data->regs->rfifo); 294 + *(u16 *)drv_data->rx = ioread32(&drv_data->regs->rfifo); 306 295 drv_data->rx += 2; 307 296 } 308 297 } 309 298 310 - static const struct bfin_spi_transfer_ops bfin_bfin_spi_transfer_ops_u16 = { 311 - .write = bfin_spi_u16_write, 312 - .read = bfin_spi_u16_read, 313 - .duplex = bfin_spi_u16_duplex, 299 + static const struct adi_spi_transfer_ops adi_spi_transfer_ops_u16 = { 300 + .write = adi_spi_u16_write, 301 + .read = adi_spi_u16_read, 302 + .duplex = adi_spi_u16_duplex, 314 303 }; 315 304 316 - static void bfin_spi_u32_write(struct bfin_spi_master *drv_data) 305 + static void adi_spi_u32_write(struct adi_spi_master *drv_data) 317 306 { 318 307 dummy_read(drv_data); 319 308 while (drv_data->tx < drv_data->tx_end) { 320 - bfin_write(&drv_data->regs->tfifo, (*(u32 *)drv_data->tx)); 309 + iowrite32(*(u32 *)drv_data->tx, &drv_data->regs->tfifo); 321 310 drv_data->tx += 4; 322 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 311 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 323 312 cpu_relax(); 324 - bfin_read(&drv_data->regs->rfifo); 313 + ioread32(&drv_data->regs->rfifo); 325 314 } 326 315 } 327 316 328 - static void bfin_spi_u32_read(struct bfin_spi_master *drv_data) 317 + static void adi_spi_u32_read(struct adi_spi_master *drv_data) 329 318 { 330 319 u32 tx_val = drv_data->cur_chip->tx_dummy_val; 331 320 332 321 dummy_read(drv_data); 333 322 while (drv_data->rx < drv_data->rx_end) { 334 - bfin_write(&drv_data->regs->tfifo, tx_val); 335 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 323 + iowrite32(tx_val, &drv_data->regs->tfifo); 324 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 336 325 cpu_relax(); 337 - *(u32 *)drv_data->rx = bfin_read(&drv_data->regs->rfifo); 326 + *(u32 *)drv_data->rx = ioread32(&drv_data->regs->rfifo); 338 327 drv_data->rx += 4; 339 328 } 340 329 } 341 330 342 - static void bfin_spi_u32_duplex(struct bfin_spi_master *drv_data) 331 + static void adi_spi_u32_duplex(struct adi_spi_master *drv_data) 343 332 { 344 333 dummy_read(drv_data); 345 334 while (drv_data->rx < drv_data->rx_end) { 346 - bfin_write(&drv_data->regs->tfifo, (*(u32 *)drv_data->tx)); 335 + iowrite32(*(u32 *)drv_data->tx, &drv_data->regs->tfifo); 347 336 drv_data->tx += 4; 348 - while (bfin_read(&drv_data->regs->status) & SPI_STAT_RFE) 337 + while (ioread32(&drv_data->regs->status) & SPI_STAT_RFE) 349 338 cpu_relax(); 350 - *(u32 *)drv_data->rx = bfin_read(&drv_data->regs->rfifo); 339 + *(u32 *)drv_data->rx = ioread32(&drv_data->regs->rfifo); 351 340 drv_data->rx += 4; 352 341 } 353 342 } 354 343 355 - static const struct bfin_spi_transfer_ops bfin_bfin_spi_transfer_ops_u32 = { 356 - .write = bfin_spi_u32_write, 357 - .read = bfin_spi_u32_read, 358 - .duplex = bfin_spi_u32_duplex, 344 + static const struct adi_spi_transfer_ops adi_spi_transfer_ops_u32 = { 345 + .write = adi_spi_u32_write, 346 + .read = adi_spi_u32_read, 347 + .duplex = adi_spi_u32_duplex, 359 348 }; 360 349 361 350 362 351 /* test if there is more transfer to be done */ 363 - static void bfin_spi_next_transfer(struct bfin_spi_master *drv) 352 + static void adi_spi_next_transfer(struct adi_spi_master *drv) 364 353 { 365 354 struct spi_message *msg = drv->cur_msg; 366 355 struct spi_transfer *t = drv->cur_transfer; ··· 381 360 } 382 361 } 383 362 384 - static void bfin_spi_giveback(struct bfin_spi_master *drv_data) 363 + static void adi_spi_giveback(struct adi_spi_master *drv_data) 385 364 { 386 - struct bfin_spi_device *chip = drv_data->cur_chip; 365 + struct adi_spi_device *chip = drv_data->cur_chip; 387 366 388 - bfin_spi_cs_deactive(drv_data, chip); 367 + adi_spi_cs_deactive(drv_data, chip); 389 368 spi_finalize_current_message(drv_data->master); 390 369 } 391 370 392 - static int bfin_spi_setup_transfer(struct bfin_spi_master *drv) 371 + static int adi_spi_setup_transfer(struct adi_spi_master *drv) 393 372 { 394 373 struct spi_transfer *t = drv->cur_transfer; 395 374 u32 cr, cr_width; ··· 414 393 switch (t->bits_per_word) { 415 394 case 8: 416 395 cr_width = SPI_CTL_SIZE08; 417 - drv->ops = &bfin_bfin_spi_transfer_ops_u8; 396 + drv->ops = &adi_spi_transfer_ops_u8; 418 397 break; 419 398 case 16: 420 399 cr_width = SPI_CTL_SIZE16; 421 - drv->ops = &bfin_bfin_spi_transfer_ops_u16; 400 + drv->ops = &adi_spi_transfer_ops_u16; 422 401 break; 423 402 case 32: 424 403 cr_width = SPI_CTL_SIZE32; 425 - drv->ops = &bfin_bfin_spi_transfer_ops_u32; 404 + drv->ops = &adi_spi_transfer_ops_u32; 426 405 break; 427 406 default: 428 407 return -EINVAL; 429 408 } 430 - cr = bfin_read(&drv->regs->control) & ~SPI_CTL_SIZE; 409 + cr = ioread32(&drv->regs->control) & ~SPI_CTL_SIZE; 431 410 cr |= cr_width; 432 - bfin_write(&drv->regs->control, cr); 411 + iowrite32(cr, &drv->regs->control); 433 412 434 413 /* speed setup */ 435 - bfin_write(&drv->regs->clock, 436 - hz_to_spi_clock(drv->sclk, t->speed_hz)); 414 + iowrite32(hz_to_spi_clock(drv->sclk, t->speed_hz), &drv->regs->clock); 437 415 return 0; 438 416 } 439 417 440 - static int bfin_spi_dma_xfer(struct bfin_spi_master *drv_data) 418 + static int adi_spi_dma_xfer(struct adi_spi_master *drv_data) 441 419 { 442 420 struct spi_transfer *t = drv_data->cur_transfer; 443 421 struct spi_message *msg = drv_data->cur_msg; 444 - struct bfin_spi_device *chip = drv_data->cur_chip; 422 + struct adi_spi_device *chip = drv_data->cur_chip; 445 423 u32 dma_config; 446 424 unsigned long word_count, word_size; 447 425 void *tx_buf, *rx_buf; ··· 518 498 set_dma_config(drv_data->rx_dma, dma_config | WNR); 519 499 enable_dma(drv_data->tx_dma); 520 500 enable_dma(drv_data->rx_dma); 521 - SSYNC(); 522 501 523 - bfin_write(&drv_data->regs->rx_control, SPI_RXCTL_REN | SPI_RXCTL_RDR_NE); 524 - SSYNC(); 525 - bfin_write(&drv_data->regs->tx_control, 526 - SPI_TXCTL_TEN | SPI_TXCTL_TTI | SPI_TXCTL_TDR_NF); 502 + iowrite32(SPI_RXCTL_REN | SPI_RXCTL_RDR_NE, 503 + &drv_data->regs->rx_control); 504 + iowrite32(SPI_TXCTL_TEN | SPI_TXCTL_TTI | SPI_TXCTL_TDR_NF, 505 + &drv_data->regs->tx_control); 527 506 528 507 return 0; 529 508 } 530 509 531 - static int bfin_spi_pio_xfer(struct bfin_spi_master *drv_data) 510 + static int adi_spi_pio_xfer(struct adi_spi_master *drv_data) 532 511 { 533 512 struct spi_message *msg = drv_data->cur_msg; 534 513 ··· 548 529 return -EIO; 549 530 } 550 531 551 - if (!bfin_spi_flush(drv_data)) 532 + if (!adi_spi_flush(drv_data)) 552 533 return -EIO; 553 534 msg->actual_length += drv_data->transfer_len; 554 535 tasklet_schedule(&drv_data->pump_transfers); 555 536 return 0; 556 537 } 557 538 558 - static void bfin_spi_pump_transfers(unsigned long data) 539 + static void adi_spi_pump_transfers(unsigned long data) 559 540 { 560 - struct bfin_spi_master *drv_data = (struct bfin_spi_master *)data; 541 + struct adi_spi_master *drv_data = (struct adi_spi_master *)data; 561 542 struct spi_message *msg = NULL; 562 543 struct spi_transfer *t = NULL; 563 - struct bfin_spi_device *chip = NULL; 544 + struct adi_spi_device *chip = NULL; 564 545 int ret; 565 546 566 547 /* Get current state information */ ··· 571 552 /* Handle for abort */ 572 553 if (drv_data->state == ERROR_STATE) { 573 554 msg->status = -EIO; 574 - bfin_spi_giveback(drv_data); 555 + adi_spi_giveback(drv_data); 575 556 return; 576 557 } 577 558 ··· 579 560 if (t->delay_usecs) 580 561 udelay(t->delay_usecs); 581 562 if (t->cs_change) 582 - bfin_spi_cs_deactive(drv_data, chip); 583 - bfin_spi_next_transfer(drv_data); 563 + adi_spi_cs_deactive(drv_data, chip); 564 + adi_spi_next_transfer(drv_data); 584 565 t = drv_data->cur_transfer; 585 566 } 586 567 /* Handle end of message */ 587 568 if (drv_data->state == DONE_STATE) { 588 569 msg->status = 0; 589 - bfin_spi_giveback(drv_data); 570 + adi_spi_giveback(drv_data); 590 571 return; 591 572 } 592 573 ··· 596 577 return; 597 578 } 598 579 599 - ret = bfin_spi_setup_transfer(drv_data); 580 + ret = adi_spi_setup_transfer(drv_data); 600 581 if (ret) { 601 582 msg->status = ret; 602 - bfin_spi_giveback(drv_data); 583 + adi_spi_giveback(drv_data); 603 584 } 604 585 605 - bfin_write(&drv_data->regs->status, 0xFFFFFFFF); 606 - bfin_spi_cs_active(drv_data, chip); 586 + iowrite32(0xFFFFFFFF, &drv_data->regs->status); 587 + adi_spi_cs_active(drv_data, chip); 607 588 drv_data->state = RUNNING_STATE; 608 589 609 590 if (chip->enable_dma) 610 - ret = bfin_spi_dma_xfer(drv_data); 591 + ret = adi_spi_dma_xfer(drv_data); 611 592 else 612 - ret = bfin_spi_pio_xfer(drv_data); 593 + ret = adi_spi_pio_xfer(drv_data); 613 594 if (ret) { 614 595 msg->status = ret; 615 - bfin_spi_giveback(drv_data); 596 + adi_spi_giveback(drv_data); 616 597 } 617 598 } 618 599 619 - static int bfin_spi_transfer_one_message(struct spi_master *master, 600 + static int adi_spi_transfer_one_message(struct spi_master *master, 620 601 struct spi_message *m) 621 602 { 622 - struct bfin_spi_master *drv_data = spi_master_get_devdata(master); 603 + struct adi_spi_master *drv_data = spi_master_get_devdata(master); 623 604 624 605 drv_data->cur_msg = m; 625 606 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi); 626 - bfin_spi_restore_state(drv_data); 607 + adi_spi_restore_state(drv_data); 627 608 628 609 drv_data->state = START_STATE; 629 610 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next, ··· 649 630 P_SPI2_SSEL6, P_SPI2_SSEL7}, 650 631 }; 651 632 652 - static int bfin_spi_setup(struct spi_device *spi) 633 + static int adi_spi_setup(struct spi_device *spi) 653 634 { 654 - struct bfin_spi_master *drv_data = spi_master_get_devdata(spi->master); 655 - struct bfin_spi_device *chip = spi_get_ctldata(spi); 656 - u32 bfin_ctl_reg = SPI_CTL_ODM | SPI_CTL_PSSE; 635 + struct adi_spi_master *drv_data = spi_master_get_devdata(spi->master); 636 + struct adi_spi_device *chip = spi_get_ctldata(spi); 637 + u32 ctl_reg = SPI_CTL_ODM | SPI_CTL_PSSE; 657 638 int ret = -EINVAL; 658 639 659 640 if (!chip) { 660 - struct bfin_spi3_chip *chip_info = spi->controller_data; 641 + struct adi_spi3_chip *chip_info = spi->controller_data; 661 642 662 643 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 663 644 if (!chip) { ··· 665 646 return -ENOMEM; 666 647 } 667 648 if (chip_info) { 668 - if (chip_info->control & ~bfin_ctl_reg) { 649 + if (chip_info->control & ~ctl_reg) { 669 650 dev_err(&spi->dev, 670 651 "do not set bits that the SPI framework manages\n"); 671 652 goto error; ··· 676 657 chip->enable_dma = chip_info->enable_dma; 677 658 } 678 659 chip->cs = spi->chip_select; 660 + 679 661 if (chip->cs < MAX_CTRL_CS) { 680 662 chip->ssel = (1 << chip->cs) << 8; 681 663 ret = peripheral_request(ssel[spi->master->bus_num] ··· 698 678 } 699 679 700 680 /* force a default base state */ 701 - chip->control &= bfin_ctl_reg; 681 + chip->control &= ctl_reg; 702 682 703 683 if (spi->mode & SPI_CPOL) 704 684 chip->control |= SPI_CTL_CPOL; ··· 712 692 713 693 chip->clock = hz_to_spi_clock(drv_data->sclk, spi->max_speed_hz); 714 694 715 - bfin_spi_cs_enable(drv_data, chip); 716 - bfin_spi_cs_deactive(drv_data, chip); 695 + adi_spi_cs_enable(drv_data, chip); 696 + adi_spi_cs_deactive(drv_data, chip); 717 697 718 698 return 0; 719 699 error: ··· 725 705 return ret; 726 706 } 727 707 728 - static void bfin_spi_cleanup(struct spi_device *spi) 708 + static void adi_spi_cleanup(struct spi_device *spi) 729 709 { 730 - struct bfin_spi_device *chip = spi_get_ctldata(spi); 731 - struct bfin_spi_master *drv_data = spi_master_get_devdata(spi->master); 710 + struct adi_spi_device *chip = spi_get_ctldata(spi); 711 + struct adi_spi_master *drv_data = spi_master_get_devdata(spi->master); 732 712 733 713 if (!chip) 734 714 return; ··· 736 716 if (chip->cs < MAX_CTRL_CS) { 737 717 peripheral_free(ssel[spi->master->bus_num] 738 718 [chip->cs-1]); 739 - bfin_spi_cs_disable(drv_data, chip); 719 + adi_spi_cs_disable(drv_data, chip); 740 720 } else { 741 721 gpio_free(chip->cs_gpio); 742 722 } ··· 745 725 spi_set_ctldata(spi, NULL); 746 726 } 747 727 748 - static irqreturn_t bfin_spi_tx_dma_isr(int irq, void *dev_id) 728 + static irqreturn_t adi_spi_tx_dma_isr(int irq, void *dev_id) 749 729 { 750 - struct bfin_spi_master *drv_data = dev_id; 730 + struct adi_spi_master *drv_data = dev_id; 751 731 u32 dma_stat = get_dma_curr_irqstat(drv_data->tx_dma); 732 + u32 tx_ctl; 752 733 753 734 clear_dma_irqstat(drv_data->tx_dma); 754 735 if (dma_stat & DMA_DONE) { ··· 760 739 if (drv_data->tx) 761 740 drv_data->state = ERROR_STATE; 762 741 } 763 - bfin_write_and(&drv_data->regs->tx_control, ~SPI_TXCTL_TDR_NF); 742 + tx_ctl = ioread32(&drv_data->regs->tx_control); 743 + tx_ctl &= ~SPI_TXCTL_TDR_NF; 744 + iowrite32(tx_ctl, &drv_data->regs->tx_control); 764 745 return IRQ_HANDLED; 765 746 } 766 747 767 - static irqreturn_t bfin_spi_rx_dma_isr(int irq, void *dev_id) 748 + static irqreturn_t adi_spi_rx_dma_isr(int irq, void *dev_id) 768 749 { 769 - struct bfin_spi_master *drv_data = dev_id; 750 + struct adi_spi_master *drv_data = dev_id; 770 751 struct spi_message *msg = drv_data->cur_msg; 771 752 u32 dma_stat = get_dma_curr_irqstat(drv_data->rx_dma); 772 753 ··· 783 760 dev_err(&drv_data->master->dev, 784 761 "spi rx dma error: %d\n", dma_stat); 785 762 } 786 - bfin_write(&drv_data->regs->tx_control, 0); 787 - bfin_write(&drv_data->regs->rx_control, 0); 763 + iowrite32(0, &drv_data->regs->tx_control); 764 + iowrite32(0, &drv_data->regs->rx_control); 788 765 if (drv_data->rx_num != drv_data->tx_num) 789 766 dev_dbg(&drv_data->master->dev, 790 767 "dma interrupt missing: tx=%d,rx=%d\n", ··· 793 770 return IRQ_HANDLED; 794 771 } 795 772 796 - static int bfin_spi_probe(struct platform_device *pdev) 773 + static int adi_spi_probe(struct platform_device *pdev) 797 774 { 798 775 struct device *dev = &pdev->dev; 799 - struct bfin_spi3_master *info = dev_get_platdata(dev); 776 + struct adi_spi3_master *info = dev_get_platdata(dev); 800 777 struct spi_master *master; 801 - struct bfin_spi_master *drv_data; 778 + struct adi_spi_master *drv_data; 802 779 struct resource *mem, *res; 803 780 unsigned int tx_dma, rx_dma; 804 - unsigned long sclk; 781 + struct clk *sclk; 805 782 int ret; 806 783 807 784 if (!info) { ··· 809 786 return -ENODEV; 810 787 } 811 788 812 - sclk = get_sclk1(); 813 - if (!sclk) { 814 - dev_err(dev, "can not get sclk1\n"); 815 - return -ENXIO; 789 + sclk = devm_clk_get(dev, "spi"); 790 + if (IS_ERR(sclk)) { 791 + dev_err(dev, "can not get spi clock\n"); 792 + return PTR_ERR(sclk); 816 793 } 817 794 818 795 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); ··· 842 819 843 820 master->bus_num = pdev->id; 844 821 master->num_chipselect = info->num_chipselect; 845 - master->cleanup = bfin_spi_cleanup; 846 - master->setup = bfin_spi_setup; 847 - master->transfer_one_message = bfin_spi_transfer_one_message; 822 + master->cleanup = adi_spi_cleanup; 823 + master->setup = adi_spi_setup; 824 + master->transfer_one_message = adi_spi_transfer_one_message; 848 825 master->bits_per_word_mask = SPI_BPW_MASK(32) | SPI_BPW_MASK(16) | 849 826 SPI_BPW_MASK(8); 850 827 ··· 853 830 drv_data->tx_dma = tx_dma; 854 831 drv_data->rx_dma = rx_dma; 855 832 drv_data->pin_req = info->pin_req; 856 - drv_data->sclk = sclk; 833 + drv_data->sclk = clk_get_rate(sclk); 857 834 858 835 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 859 836 drv_data->regs = devm_ioremap_resource(dev, mem); ··· 868 845 dev_err(dev, "can not request SPI TX DMA channel\n"); 869 846 goto err_put_master; 870 847 } 871 - set_dma_callback(tx_dma, bfin_spi_tx_dma_isr, drv_data); 848 + set_dma_callback(tx_dma, adi_spi_tx_dma_isr, drv_data); 872 849 873 850 ret = request_dma(rx_dma, "SPI_RX_DMA"); 874 851 if (ret) { 875 852 dev_err(dev, "can not request SPI RX DMA channel\n"); 876 853 goto err_free_tx_dma; 877 854 } 878 - set_dma_callback(drv_data->rx_dma, bfin_spi_rx_dma_isr, drv_data); 855 + set_dma_callback(drv_data->rx_dma, adi_spi_rx_dma_isr, drv_data); 879 856 880 857 /* request CLK, MOSI and MISO */ 881 - ret = peripheral_request_list(drv_data->pin_req, "bfin-spi3"); 858 + ret = peripheral_request_list(drv_data->pin_req, "adi-spi3"); 882 859 if (ret < 0) { 883 860 dev_err(dev, "can not request spi pins\n"); 884 861 goto err_free_rx_dma; 885 862 } 886 863 887 - bfin_write(&drv_data->regs->control, SPI_CTL_MSTR | SPI_CTL_CPHA); 888 - bfin_write(&drv_data->regs->ssel, 0x0000FE00); 889 - bfin_write(&drv_data->regs->delay, 0x0); 864 + iowrite32(SPI_CTL_MSTR | SPI_CTL_CPHA, &drv_data->regs->control); 865 + iowrite32(0x0000FE00, &drv_data->regs->ssel); 866 + iowrite32(0x0, &drv_data->regs->delay); 890 867 891 868 tasklet_init(&drv_data->pump_transfers, 892 - bfin_spi_pump_transfers, (unsigned long)drv_data); 869 + adi_spi_pump_transfers, (unsigned long)drv_data); 893 870 /* register with the SPI framework */ 894 871 ret = devm_spi_register_master(dev, master); 895 872 if (ret) { ··· 911 888 return ret; 912 889 } 913 890 914 - static int bfin_spi_remove(struct platform_device *pdev) 891 + static int adi_spi_remove(struct platform_device *pdev) 915 892 { 916 893 struct spi_master *master = platform_get_drvdata(pdev); 917 - struct bfin_spi_master *drv_data = spi_master_get_devdata(master); 894 + struct adi_spi_master *drv_data = spi_master_get_devdata(master); 918 895 919 - bfin_spi_disable(drv_data); 920 - 896 + adi_spi_disable(drv_data); 921 897 peripheral_free_list(drv_data->pin_req); 922 898 free_dma(drv_data->rx_dma); 923 899 free_dma(drv_data->tx_dma); 924 - 925 900 return 0; 926 901 } 927 902 928 903 #ifdef CONFIG_PM 929 - static int bfin_spi_suspend(struct device *dev) 904 + static int adi_spi_suspend(struct device *dev) 930 905 { 931 906 struct spi_master *master = dev_get_drvdata(dev); 932 - struct bfin_spi_master *drv_data = spi_master_get_devdata(master); 907 + struct adi_spi_master *drv_data = spi_master_get_devdata(master); 933 908 934 909 spi_master_suspend(master); 935 910 936 - drv_data->control = bfin_read(&drv_data->regs->control); 937 - drv_data->ssel = bfin_read(&drv_data->regs->ssel); 911 + drv_data->control = ioread32(&drv_data->regs->control); 912 + drv_data->ssel = ioread32(&drv_data->regs->ssel); 938 913 939 - bfin_write(&drv_data->regs->control, SPI_CTL_MSTR | SPI_CTL_CPHA); 940 - bfin_write(&drv_data->regs->ssel, 0x0000FE00); 914 + iowrite32(SPI_CTL_MSTR | SPI_CTL_CPHA, &drv_data->regs->control); 915 + iowrite32(0x0000FE00, &drv_data->regs->ssel); 941 916 dma_disable_irq(drv_data->rx_dma); 942 917 dma_disable_irq(drv_data->tx_dma); 943 918 944 919 return 0; 945 920 } 946 921 947 - static int bfin_spi_resume(struct device *dev) 922 + static int adi_spi_resume(struct device *dev) 948 923 { 949 924 struct spi_master *master = dev_get_drvdata(dev); 950 - struct bfin_spi_master *drv_data = spi_master_get_devdata(master); 925 + struct adi_spi_master *drv_data = spi_master_get_devdata(master); 951 926 int ret = 0; 952 927 953 928 /* bootrom may modify spi and dma status when resume in spi boot mode */ ··· 953 932 954 933 dma_enable_irq(drv_data->rx_dma); 955 934 dma_enable_irq(drv_data->tx_dma); 956 - bfin_write(&drv_data->regs->control, drv_data->control); 957 - bfin_write(&drv_data->regs->ssel, drv_data->ssel); 935 + iowrite32(drv_data->control, &drv_data->regs->control); 936 + iowrite32(drv_data->ssel, &drv_data->regs->ssel); 958 937 959 938 ret = spi_master_resume(master); 960 939 if (ret) { ··· 965 944 return ret; 966 945 } 967 946 #endif 968 - static const struct dev_pm_ops bfin_spi_pm_ops = { 969 - SET_SYSTEM_SLEEP_PM_OPS(bfin_spi_suspend, bfin_spi_resume) 947 + static const struct dev_pm_ops adi_spi_pm_ops = { 948 + SET_SYSTEM_SLEEP_PM_OPS(adi_spi_suspend, adi_spi_resume) 970 949 }; 971 950 972 - MODULE_ALIAS("platform:bfin-spi3"); 973 - static struct platform_driver bfin_spi_driver = { 951 + MODULE_ALIAS("platform:adi-spi3"); 952 + static struct platform_driver adi_spi_driver = { 974 953 .driver = { 975 - .name = "bfin-spi3", 954 + .name = "adi-spi3", 976 955 .owner = THIS_MODULE, 977 - .pm = &bfin_spi_pm_ops, 956 + .pm = &adi_spi_pm_ops, 978 957 }, 979 - .remove = bfin_spi_remove, 958 + .remove = adi_spi_remove, 980 959 }; 981 960 982 - module_platform_driver_probe(bfin_spi_driver, bfin_spi_probe); 961 + module_platform_driver_probe(adi_spi_driver, adi_spi_probe); 983 962 984 963 MODULE_DESCRIPTION("Analog Devices SPI3 controller driver"); 985 964 MODULE_AUTHOR("Scott Jiang <Scott.Jiang.Linux@gmail.com>");
+673
drivers/spi/spi-cadence.c
··· 1 + /* 2 + * Cadence SPI controller driver (master mode only) 3 + * 4 + * Copyright (C) 2008 - 2014 Xilinx, Inc. 5 + * 6 + * based on Blackfin On-Chip SPI Driver (spi_bfin5xx.c) 7 + * 8 + * This program is free software; you can redistribute it and/or modify it under 9 + * the terms of the GNU General Public License version 2 as published by the 10 + * Free Software Foundation; either version 2 of the License, or (at your 11 + * option) any later version. 12 + */ 13 + 14 + #include <linux/clk.h> 15 + #include <linux/delay.h> 16 + #include <linux/interrupt.h> 17 + #include <linux/io.h> 18 + #include <linux/module.h> 19 + #include <linux/of_irq.h> 20 + #include <linux/of_address.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/spi/spi.h> 23 + 24 + /* Name of this driver */ 25 + #define CDNS_SPI_NAME "cdns-spi" 26 + 27 + /* Register offset definitions */ 28 + #define CDNS_SPI_CR_OFFSET 0x00 /* Configuration Register, RW */ 29 + #define CDNS_SPI_ISR_OFFSET 0x04 /* Interrupt Status Register, RO */ 30 + #define CDNS_SPI_IER_OFFSET 0x08 /* Interrupt Enable Register, WO */ 31 + #define CDNS_SPI_IDR_OFFSET 0x0c /* Interrupt Disable Register, WO */ 32 + #define CDNS_SPI_IMR_OFFSET 0x10 /* Interrupt Enabled Mask Register, RO */ 33 + #define CDNS_SPI_ER_OFFSET 0x14 /* Enable/Disable Register, RW */ 34 + #define CDNS_SPI_DR_OFFSET 0x18 /* Delay Register, RW */ 35 + #define CDNS_SPI_TXD_OFFSET 0x1C /* Data Transmit Register, WO */ 36 + #define CDNS_SPI_RXD_OFFSET 0x20 /* Data Receive Register, RO */ 37 + #define CDNS_SPI_SICR_OFFSET 0x24 /* Slave Idle Count Register, RW */ 38 + #define CDNS_SPI_THLD_OFFSET 0x28 /* Transmit FIFO Watermark Register,RW */ 39 + 40 + /* 41 + * SPI Configuration Register bit Masks 42 + * 43 + * This register contains various control bits that affect the operation 44 + * of the SPI controller 45 + */ 46 + #define CDNS_SPI_CR_MANSTRT_MASK 0x00010000 /* Manual TX Start */ 47 + #define CDNS_SPI_CR_CPHA_MASK 0x00000004 /* Clock Phase Control */ 48 + #define CDNS_SPI_CR_CPOL_MASK 0x00000002 /* Clock Polarity Control */ 49 + #define CDNS_SPI_CR_SSCTRL_MASK 0x00003C00 /* Slave Select Mask */ 50 + #define CDNS_SPI_CR_BAUD_DIV_MASK 0x00000038 /* Baud Rate Divisor Mask */ 51 + #define CDNS_SPI_CR_MSTREN_MASK 0x00000001 /* Master Enable Mask */ 52 + #define CDNS_SPI_CR_MANSTRTEN_MASK 0x00008000 /* Manual TX Enable Mask */ 53 + #define CDNS_SPI_CR_SSFORCE_MASK 0x00004000 /* Manual SS Enable Mask */ 54 + #define CDNS_SPI_CR_BAUD_DIV_4_MASK 0x00000008 /* Default Baud Div Mask */ 55 + #define CDNS_SPI_CR_DEFAULT_MASK (CDNS_SPI_CR_MSTREN_MASK | \ 56 + CDNS_SPI_CR_SSCTRL_MASK | \ 57 + CDNS_SPI_CR_SSFORCE_MASK | \ 58 + CDNS_SPI_CR_BAUD_DIV_4_MASK) 59 + 60 + /* 61 + * SPI Configuration Register - Baud rate and slave select 62 + * 63 + * These are the values used in the calculation of baud rate divisor and 64 + * setting the slave select. 65 + */ 66 + 67 + #define CDNS_SPI_BAUD_DIV_MAX 7 /* Baud rate divisor maximum */ 68 + #define CDNS_SPI_BAUD_DIV_MIN 1 /* Baud rate divisor minimum */ 69 + #define CDNS_SPI_BAUD_DIV_SHIFT 3 /* Baud rate divisor shift in CR */ 70 + #define CDNS_SPI_SS_SHIFT 10 /* Slave Select field shift in CR */ 71 + #define CDNS_SPI_SS0 0x1 /* Slave Select zero */ 72 + 73 + /* 74 + * SPI Interrupt Registers bit Masks 75 + * 76 + * All the four interrupt registers (Status/Mask/Enable/Disable) have the same 77 + * bit definitions. 78 + */ 79 + #define CDNS_SPI_IXR_TXOW_MASK 0x00000004 /* SPI TX FIFO Overwater */ 80 + #define CDNS_SPI_IXR_MODF_MASK 0x00000002 /* SPI Mode Fault */ 81 + #define CDNS_SPI_IXR_RXNEMTY_MASK 0x00000010 /* SPI RX FIFO Not Empty */ 82 + #define CDNS_SPI_IXR_DEFAULT_MASK (CDNS_SPI_IXR_TXOW_MASK | \ 83 + CDNS_SPI_IXR_MODF_MASK) 84 + #define CDNS_SPI_IXR_TXFULL_MASK 0x00000008 /* SPI TX Full */ 85 + #define CDNS_SPI_IXR_ALL_MASK 0x0000007F /* SPI all interrupts */ 86 + 87 + /* 88 + * SPI Enable Register bit Masks 89 + * 90 + * This register is used to enable or disable the SPI controller 91 + */ 92 + #define CDNS_SPI_ER_ENABLE_MASK 0x00000001 /* SPI Enable Bit Mask */ 93 + #define CDNS_SPI_ER_DISABLE_MASK 0x0 /* SPI Disable Bit Mask */ 94 + 95 + /* SPI FIFO depth in bytes */ 96 + #define CDNS_SPI_FIFO_DEPTH 128 97 + 98 + /* Default number of chip select lines */ 99 + #define CDNS_SPI_DEFAULT_NUM_CS 4 100 + 101 + /** 102 + * struct cdns_spi - This definition defines spi driver instance 103 + * @regs: Virtual address of the SPI controller registers 104 + * @ref_clk: Pointer to the peripheral clock 105 + * @pclk: Pointer to the APB clock 106 + * @speed_hz: Current SPI bus clock speed in Hz 107 + * @txbuf: Pointer to the TX buffer 108 + * @rxbuf: Pointer to the RX buffer 109 + * @tx_bytes: Number of bytes left to transfer 110 + * @rx_bytes: Number of bytes requested 111 + * @dev_busy: Device busy flag 112 + * @is_decoded_cs: Flag for decoder property set or not 113 + */ 114 + struct cdns_spi { 115 + void __iomem *regs; 116 + struct clk *ref_clk; 117 + struct clk *pclk; 118 + u32 speed_hz; 119 + const u8 *txbuf; 120 + u8 *rxbuf; 121 + int tx_bytes; 122 + int rx_bytes; 123 + u8 dev_busy; 124 + u32 is_decoded_cs; 125 + }; 126 + 127 + /* Macros for the SPI controller read/write */ 128 + static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset) 129 + { 130 + return readl_relaxed(xspi->regs + offset); 131 + } 132 + 133 + static inline void cdns_spi_write(struct cdns_spi *xspi, u32 offset, u32 val) 134 + { 135 + writel_relaxed(val, xspi->regs + offset); 136 + } 137 + 138 + /** 139 + * cdns_spi_init_hw - Initialize the hardware and configure the SPI controller 140 + * @xspi: Pointer to the cdns_spi structure 141 + * 142 + * On reset the SPI controller is configured to be in master mode, baud rate 143 + * divisor is set to 4, threshold value for TX FIFO not full interrupt is set 144 + * to 1 and size of the word to be transferred as 8 bit. 145 + * This function initializes the SPI controller to disable and clear all the 146 + * interrupts, enable manual slave select and manual start, deselect all the 147 + * chip select lines, and enable the SPI controller. 148 + */ 149 + static void cdns_spi_init_hw(struct cdns_spi *xspi) 150 + { 151 + cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET, 152 + CDNS_SPI_ER_DISABLE_MASK); 153 + cdns_spi_write(xspi, CDNS_SPI_IDR_OFFSET, 154 + CDNS_SPI_IXR_ALL_MASK); 155 + 156 + /* Clear the RX FIFO */ 157 + while (cdns_spi_read(xspi, CDNS_SPI_ISR_OFFSET) & 158 + CDNS_SPI_IXR_RXNEMTY_MASK) 159 + cdns_spi_read(xspi, CDNS_SPI_RXD_OFFSET); 160 + 161 + cdns_spi_write(xspi, CDNS_SPI_ISR_OFFSET, 162 + CDNS_SPI_IXR_ALL_MASK); 163 + cdns_spi_write(xspi, CDNS_SPI_CR_OFFSET, 164 + CDNS_SPI_CR_DEFAULT_MASK); 165 + cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET, 166 + CDNS_SPI_ER_ENABLE_MASK); 167 + } 168 + 169 + /** 170 + * cdns_spi_chipselect - Select or deselect the chip select line 171 + * @spi: Pointer to the spi_device structure 172 + * @is_on: Select(0) or deselect (1) the chip select line 173 + */ 174 + static void cdns_spi_chipselect(struct spi_device *spi, bool is_high) 175 + { 176 + struct cdns_spi *xspi = spi_master_get_devdata(spi->master); 177 + u32 ctrl_reg; 178 + 179 + ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR_OFFSET); 180 + 181 + if (is_high) { 182 + /* Deselect the slave */ 183 + ctrl_reg |= CDNS_SPI_CR_SSCTRL_MASK; 184 + } else { 185 + /* Select the slave */ 186 + ctrl_reg &= ~CDNS_SPI_CR_SSCTRL_MASK; 187 + if (!(xspi->is_decoded_cs)) 188 + ctrl_reg |= ((~(CDNS_SPI_SS0 << spi->chip_select)) << 189 + CDNS_SPI_SS_SHIFT) & 190 + CDNS_SPI_CR_SSCTRL_MASK; 191 + else 192 + ctrl_reg |= (spi->chip_select << CDNS_SPI_SS_SHIFT) & 193 + CDNS_SPI_CR_SSCTRL_MASK; 194 + } 195 + 196 + cdns_spi_write(xspi, CDNS_SPI_CR_OFFSET, ctrl_reg); 197 + } 198 + 199 + /** 200 + * cdns_spi_config_clock_mode - Sets clock polarity and phase 201 + * @spi: Pointer to the spi_device structure 202 + * 203 + * Sets the requested clock polarity and phase. 204 + */ 205 + static void cdns_spi_config_clock_mode(struct spi_device *spi) 206 + { 207 + struct cdns_spi *xspi = spi_master_get_devdata(spi->master); 208 + u32 ctrl_reg; 209 + 210 + ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR_OFFSET); 211 + 212 + /* Set the SPI clock phase and clock polarity */ 213 + ctrl_reg &= ~(CDNS_SPI_CR_CPHA_MASK | CDNS_SPI_CR_CPOL_MASK); 214 + if (spi->mode & SPI_CPHA) 215 + ctrl_reg |= CDNS_SPI_CR_CPHA_MASK; 216 + if (spi->mode & SPI_CPOL) 217 + ctrl_reg |= CDNS_SPI_CR_CPOL_MASK; 218 + 219 + cdns_spi_write(xspi, CDNS_SPI_CR_OFFSET, ctrl_reg); 220 + } 221 + 222 + /** 223 + * cdns_spi_config_clock_freq - Sets clock frequency 224 + * @spi: Pointer to the spi_device structure 225 + * @transfer: Pointer to the spi_transfer structure which provides 226 + * information about next transfer setup parameters 227 + * 228 + * Sets the requested clock frequency. 229 + * Note: If the requested frequency is not an exact match with what can be 230 + * obtained using the prescalar value the driver sets the clock frequency which 231 + * is lower than the requested frequency (maximum lower) for the transfer. If 232 + * the requested frequency is higher or lower than that is supported by the SPI 233 + * controller the driver will set the highest or lowest frequency supported by 234 + * controller. 235 + */ 236 + static void cdns_spi_config_clock_freq(struct spi_device *spi, 237 + struct spi_transfer *transfer) 238 + { 239 + struct cdns_spi *xspi = spi_master_get_devdata(spi->master); 240 + u32 ctrl_reg, baud_rate_val; 241 + unsigned long frequency; 242 + 243 + frequency = clk_get_rate(xspi->ref_clk); 244 + 245 + ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR_OFFSET); 246 + 247 + /* Set the clock frequency */ 248 + if (xspi->speed_hz != transfer->speed_hz) { 249 + /* first valid value is 1 */ 250 + baud_rate_val = CDNS_SPI_BAUD_DIV_MIN; 251 + while ((baud_rate_val < CDNS_SPI_BAUD_DIV_MAX) && 252 + (frequency / (2 << baud_rate_val)) > transfer->speed_hz) 253 + baud_rate_val++; 254 + 255 + ctrl_reg &= ~CDNS_SPI_CR_BAUD_DIV_MASK; 256 + ctrl_reg |= baud_rate_val << CDNS_SPI_BAUD_DIV_SHIFT; 257 + 258 + xspi->speed_hz = frequency / (2 << baud_rate_val); 259 + } 260 + cdns_spi_write(xspi, CDNS_SPI_CR_OFFSET, ctrl_reg); 261 + } 262 + 263 + /** 264 + * cdns_spi_setup_transfer - Configure SPI controller for specified transfer 265 + * @spi: Pointer to the spi_device structure 266 + * @transfer: Pointer to the spi_transfer structure which provides 267 + * information about next transfer setup parameters 268 + * 269 + * Sets the operational mode of SPI controller for the next SPI transfer and 270 + * sets the requested clock frequency. 271 + * 272 + * Return: Always 0 273 + */ 274 + static int cdns_spi_setup_transfer(struct spi_device *spi, 275 + struct spi_transfer *transfer) 276 + { 277 + struct cdns_spi *xspi = spi_master_get_devdata(spi->master); 278 + 279 + cdns_spi_config_clock_freq(spi, transfer); 280 + 281 + dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u clock speed\n", 282 + __func__, spi->mode, spi->bits_per_word, 283 + xspi->speed_hz); 284 + 285 + return 0; 286 + } 287 + 288 + /** 289 + * cdns_spi_fill_tx_fifo - Fills the TX FIFO with as many bytes as possible 290 + * @xspi: Pointer to the cdns_spi structure 291 + */ 292 + static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi) 293 + { 294 + unsigned long trans_cnt = 0; 295 + 296 + while ((trans_cnt < CDNS_SPI_FIFO_DEPTH) && 297 + (xspi->tx_bytes > 0)) { 298 + if (xspi->txbuf) 299 + cdns_spi_write(xspi, CDNS_SPI_TXD_OFFSET, 300 + *xspi->txbuf++); 301 + else 302 + cdns_spi_write(xspi, CDNS_SPI_TXD_OFFSET, 0); 303 + 304 + xspi->tx_bytes--; 305 + trans_cnt++; 306 + } 307 + } 308 + 309 + /** 310 + * cdns_spi_irq - Interrupt service routine of the SPI controller 311 + * @irq: IRQ number 312 + * @dev_id: Pointer to the xspi structure 313 + * 314 + * This function handles TX empty and Mode Fault interrupts only. 315 + * On TX empty interrupt this function reads the received data from RX FIFO and 316 + * fills the TX FIFO if there is any data remaining to be transferred. 317 + * On Mode Fault interrupt this function indicates that transfer is completed, 318 + * the SPI subsystem will identify the error as the remaining bytes to be 319 + * transferred is non-zero. 320 + * 321 + * Return: IRQ_HANDLED when handled; IRQ_NONE otherwise. 322 + */ 323 + static irqreturn_t cdns_spi_irq(int irq, void *dev_id) 324 + { 325 + struct spi_master *master = dev_id; 326 + struct cdns_spi *xspi = spi_master_get_devdata(master); 327 + u32 intr_status, status; 328 + 329 + status = IRQ_NONE; 330 + intr_status = cdns_spi_read(xspi, CDNS_SPI_ISR_OFFSET); 331 + cdns_spi_write(xspi, CDNS_SPI_ISR_OFFSET, intr_status); 332 + 333 + if (intr_status & CDNS_SPI_IXR_MODF_MASK) { 334 + /* Indicate that transfer is completed, the SPI subsystem will 335 + * identify the error as the remaining bytes to be 336 + * transferred is non-zero 337 + */ 338 + cdns_spi_write(xspi, CDNS_SPI_IDR_OFFSET, 339 + CDNS_SPI_IXR_DEFAULT_MASK); 340 + spi_finalize_current_transfer(master); 341 + status = IRQ_HANDLED; 342 + } else if (intr_status & CDNS_SPI_IXR_TXOW_MASK) { 343 + unsigned long trans_cnt; 344 + 345 + trans_cnt = xspi->rx_bytes - xspi->tx_bytes; 346 + 347 + /* Read out the data from the RX FIFO */ 348 + while (trans_cnt) { 349 + u8 data; 350 + 351 + data = cdns_spi_read(xspi, CDNS_SPI_RXD_OFFSET); 352 + if (xspi->rxbuf) 353 + *xspi->rxbuf++ = data; 354 + 355 + xspi->rx_bytes--; 356 + trans_cnt--; 357 + } 358 + 359 + if (xspi->tx_bytes) { 360 + /* There is more data to send */ 361 + cdns_spi_fill_tx_fifo(xspi); 362 + } else { 363 + /* Transfer is completed */ 364 + cdns_spi_write(xspi, CDNS_SPI_IDR_OFFSET, 365 + CDNS_SPI_IXR_DEFAULT_MASK); 366 + spi_finalize_current_transfer(master); 367 + } 368 + status = IRQ_HANDLED; 369 + } 370 + 371 + return status; 372 + } 373 + 374 + /** 375 + * cdns_transfer_one - Initiates the SPI transfer 376 + * @master: Pointer to spi_master structure 377 + * @spi: Pointer to the spi_device structure 378 + * @transfer: Pointer to the spi_transfer structure which provides 379 + * information about next transfer parameters 380 + * 381 + * This function fills the TX FIFO, starts the SPI transfer and 382 + * returns a positive transfer count so that core will wait for completion. 383 + * 384 + * Return: Number of bytes transferred in the last transfer 385 + */ 386 + static int cdns_transfer_one(struct spi_master *master, 387 + struct spi_device *spi, 388 + struct spi_transfer *transfer) 389 + { 390 + struct cdns_spi *xspi = spi_master_get_devdata(master); 391 + 392 + xspi->txbuf = transfer->tx_buf; 393 + xspi->rxbuf = transfer->rx_buf; 394 + xspi->tx_bytes = transfer->len; 395 + xspi->rx_bytes = transfer->len; 396 + 397 + cdns_spi_setup_transfer(spi, transfer); 398 + 399 + cdns_spi_fill_tx_fifo(xspi); 400 + 401 + cdns_spi_write(xspi, CDNS_SPI_IER_OFFSET, 402 + CDNS_SPI_IXR_DEFAULT_MASK); 403 + return transfer->len; 404 + } 405 + 406 + /** 407 + * cdns_prepare_transfer_hardware - Prepares hardware for transfer. 408 + * @master: Pointer to the spi_master structure which provides 409 + * information about the controller. 410 + * 411 + * This function enables SPI master controller. 412 + * 413 + * Return: 0 always 414 + */ 415 + static int cdns_prepare_transfer_hardware(struct spi_master *master) 416 + { 417 + struct cdns_spi *xspi = spi_master_get_devdata(master); 418 + 419 + cdns_spi_config_clock_mode(master->cur_msg->spi); 420 + 421 + cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET, 422 + CDNS_SPI_ER_ENABLE_MASK); 423 + 424 + return 0; 425 + } 426 + 427 + /** 428 + * cdns_unprepare_transfer_hardware - Relaxes hardware after transfer 429 + * @master: Pointer to the spi_master structure which provides 430 + * information about the controller. 431 + * 432 + * This function disables the SPI master controller. 433 + * 434 + * Return: 0 always 435 + */ 436 + static int cdns_unprepare_transfer_hardware(struct spi_master *master) 437 + { 438 + struct cdns_spi *xspi = spi_master_get_devdata(master); 439 + 440 + cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET, 441 + CDNS_SPI_ER_DISABLE_MASK); 442 + 443 + return 0; 444 + } 445 + 446 + /** 447 + * cdns_spi_probe - Probe method for the SPI driver 448 + * @pdev: Pointer to the platform_device structure 449 + * 450 + * This function initializes the driver data structures and the hardware. 451 + * 452 + * Return: 0 on success and error value on error 453 + */ 454 + static int cdns_spi_probe(struct platform_device *pdev) 455 + { 456 + int ret = 0, irq; 457 + struct spi_master *master; 458 + struct cdns_spi *xspi; 459 + struct resource *res; 460 + u32 num_cs; 461 + 462 + master = spi_alloc_master(&pdev->dev, sizeof(*xspi)); 463 + if (master == NULL) 464 + return -ENOMEM; 465 + 466 + xspi = spi_master_get_devdata(master); 467 + master->dev.of_node = pdev->dev.of_node; 468 + platform_set_drvdata(pdev, master); 469 + 470 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 471 + xspi->regs = devm_ioremap_resource(&pdev->dev, res); 472 + if (IS_ERR(xspi->regs)) { 473 + ret = PTR_ERR(xspi->regs); 474 + goto remove_master; 475 + } 476 + 477 + xspi->pclk = devm_clk_get(&pdev->dev, "pclk"); 478 + if (IS_ERR(xspi->pclk)) { 479 + dev_err(&pdev->dev, "pclk clock not found.\n"); 480 + ret = PTR_ERR(xspi->pclk); 481 + goto remove_master; 482 + } 483 + 484 + xspi->ref_clk = devm_clk_get(&pdev->dev, "ref_clk"); 485 + if (IS_ERR(xspi->ref_clk)) { 486 + dev_err(&pdev->dev, "ref_clk clock not found.\n"); 487 + ret = PTR_ERR(xspi->ref_clk); 488 + goto remove_master; 489 + } 490 + 491 + ret = clk_prepare_enable(xspi->pclk); 492 + if (ret) { 493 + dev_err(&pdev->dev, "Unable to enable APB clock.\n"); 494 + goto remove_master; 495 + } 496 + 497 + ret = clk_prepare_enable(xspi->ref_clk); 498 + if (ret) { 499 + dev_err(&pdev->dev, "Unable to enable device clock.\n"); 500 + goto clk_dis_apb; 501 + } 502 + 503 + /* SPI controller initializations */ 504 + cdns_spi_init_hw(xspi); 505 + 506 + irq = platform_get_irq(pdev, 0); 507 + if (irq <= 0) { 508 + ret = -ENXIO; 509 + dev_err(&pdev->dev, "irq number is invalid\n"); 510 + goto remove_master; 511 + } 512 + 513 + ret = devm_request_irq(&pdev->dev, irq, cdns_spi_irq, 514 + 0, pdev->name, master); 515 + if (ret != 0) { 516 + ret = -ENXIO; 517 + dev_err(&pdev->dev, "request_irq failed\n"); 518 + goto remove_master; 519 + } 520 + 521 + ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs); 522 + 523 + if (ret < 0) 524 + master->num_chipselect = CDNS_SPI_DEFAULT_NUM_CS; 525 + else 526 + master->num_chipselect = num_cs; 527 + 528 + ret = of_property_read_u32(pdev->dev.of_node, "is-decoded-cs", 529 + &xspi->is_decoded_cs); 530 + 531 + if (ret < 0) 532 + xspi->is_decoded_cs = 0; 533 + 534 + master->prepare_transfer_hardware = cdns_prepare_transfer_hardware; 535 + master->transfer_one = cdns_transfer_one; 536 + master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware; 537 + master->set_cs = cdns_spi_chipselect; 538 + master->mode_bits = SPI_CPOL | SPI_CPHA; 539 + 540 + /* Set to default valid value */ 541 + master->max_speed_hz = clk_get_rate(xspi->ref_clk) / 4; 542 + xspi->speed_hz = master->max_speed_hz; 543 + 544 + master->bits_per_word_mask = SPI_BPW_MASK(8); 545 + 546 + ret = spi_register_master(master); 547 + if (ret) { 548 + dev_err(&pdev->dev, "spi_register_master failed\n"); 549 + goto clk_dis_all; 550 + } 551 + 552 + return ret; 553 + 554 + clk_dis_all: 555 + clk_disable_unprepare(xspi->ref_clk); 556 + clk_dis_apb: 557 + clk_disable_unprepare(xspi->pclk); 558 + remove_master: 559 + spi_master_put(master); 560 + return ret; 561 + } 562 + 563 + /** 564 + * cdns_spi_remove - Remove method for the SPI driver 565 + * @pdev: Pointer to the platform_device structure 566 + * 567 + * This function is called if a device is physically removed from the system or 568 + * if the driver module is being unloaded. It frees all resources allocated to 569 + * the device. 570 + * 571 + * Return: 0 on success and error value on error 572 + */ 573 + static int cdns_spi_remove(struct platform_device *pdev) 574 + { 575 + struct spi_master *master = platform_get_drvdata(pdev); 576 + struct cdns_spi *xspi = spi_master_get_devdata(master); 577 + 578 + cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET, 579 + CDNS_SPI_ER_DISABLE_MASK); 580 + 581 + clk_disable_unprepare(xspi->ref_clk); 582 + clk_disable_unprepare(xspi->pclk); 583 + 584 + spi_unregister_master(master); 585 + 586 + return 0; 587 + } 588 + 589 + /** 590 + * cdns_spi_suspend - Suspend method for the SPI driver 591 + * @dev: Address of the platform_device structure 592 + * 593 + * This function disables the SPI controller and 594 + * changes the driver state to "suspend" 595 + * 596 + * Return: Always 0 597 + */ 598 + static int __maybe_unused cdns_spi_suspend(struct device *dev) 599 + { 600 + struct platform_device *pdev = container_of(dev, 601 + struct platform_device, dev); 602 + struct spi_master *master = platform_get_drvdata(pdev); 603 + struct cdns_spi *xspi = spi_master_get_devdata(master); 604 + 605 + spi_master_suspend(master); 606 + 607 + clk_disable_unprepare(xspi->ref_clk); 608 + 609 + clk_disable_unprepare(xspi->pclk); 610 + 611 + return 0; 612 + } 613 + 614 + /** 615 + * cdns_spi_resume - Resume method for the SPI driver 616 + * @dev: Address of the platform_device structure 617 + * 618 + * This function changes the driver state to "ready" 619 + * 620 + * Return: 0 on success and error value on error 621 + */ 622 + static int __maybe_unused cdns_spi_resume(struct device *dev) 623 + { 624 + struct platform_device *pdev = container_of(dev, 625 + struct platform_device, dev); 626 + struct spi_master *master = platform_get_drvdata(pdev); 627 + struct cdns_spi *xspi = spi_master_get_devdata(master); 628 + int ret = 0; 629 + 630 + ret = clk_prepare_enable(xspi->pclk); 631 + if (ret) { 632 + dev_err(dev, "Cannot enable APB clock.\n"); 633 + return ret; 634 + } 635 + 636 + ret = clk_prepare_enable(xspi->ref_clk); 637 + if (ret) { 638 + dev_err(dev, "Cannot enable device clock.\n"); 639 + clk_disable(xspi->pclk); 640 + return ret; 641 + } 642 + spi_master_resume(master); 643 + 644 + return 0; 645 + } 646 + 647 + static SIMPLE_DEV_PM_OPS(cdns_spi_dev_pm_ops, cdns_spi_suspend, 648 + cdns_spi_resume); 649 + 650 + static struct of_device_id cdns_spi_of_match[] = { 651 + { .compatible = "xlnx,zynq-spi-r1p6" }, 652 + { .compatible = "cdns,spi-r1p6" }, 653 + { /* end of table */ } 654 + }; 655 + MODULE_DEVICE_TABLE(of, cdns_spi_of_match); 656 + 657 + /* cdns_spi_driver - This structure defines the SPI subsystem platform driver */ 658 + static struct platform_driver cdns_spi_driver = { 659 + .probe = cdns_spi_probe, 660 + .remove = cdns_spi_remove, 661 + .driver = { 662 + .name = CDNS_SPI_NAME, 663 + .owner = THIS_MODULE, 664 + .of_match_table = cdns_spi_of_match, 665 + .pm = &cdns_spi_dev_pm_ops, 666 + }, 667 + }; 668 + 669 + module_platform_driver(cdns_spi_driver); 670 + 671 + MODULE_AUTHOR("Xilinx, Inc."); 672 + MODULE_DESCRIPTION("Cadence SPI driver"); 673 + MODULE_LICENSE("GPL");
+22
drivers/spi/spi-dw-mmio.c
··· 16 16 #include <linux/spi/spi.h> 17 17 #include <linux/scatterlist.h> 18 18 #include <linux/module.h> 19 + #include <linux/of_gpio.h> 19 20 20 21 #include "spi-dw.h" 21 22 ··· 70 69 dws->bus_num = pdev->id; 71 70 dws->num_cs = 4; 72 71 dws->max_freq = clk_get_rate(dwsmmio->clk); 72 + 73 + if (pdev->dev.of_node) { 74 + int i; 75 + 76 + for (i = 0; i < dws->num_cs; i++) { 77 + int cs_gpio = of_get_named_gpio(pdev->dev.of_node, 78 + "cs-gpios", i); 79 + 80 + if (cs_gpio == -EPROBE_DEFER) { 81 + ret = cs_gpio; 82 + goto out; 83 + } 84 + 85 + if (gpio_is_valid(cs_gpio)) { 86 + ret = devm_gpio_request(&pdev->dev, cs_gpio, 87 + dev_name(&pdev->dev)); 88 + if (ret) 89 + goto out; 90 + } 91 + } 92 + } 73 93 74 94 ret = dw_spi_add_host(&pdev->dev, dws); 75 95 if (ret)
+22 -175
drivers/spi/spi-dw.c
··· 24 24 #include <linux/delay.h> 25 25 #include <linux/slab.h> 26 26 #include <linux/spi/spi.h> 27 + #include <linux/gpio.h> 27 28 28 29 #include "spi-dw.h" 29 30 ··· 36 35 #define RUNNING_STATE ((void *)1) 37 36 #define DONE_STATE ((void *)2) 38 37 #define ERROR_STATE ((void *)-1) 39 - 40 - #define QUEUE_RUNNING 0 41 - #define QUEUE_STOPPED 1 42 - 43 - #define MRST_SPI_DEASSERT 0 44 - #define MRST_SPI_ASSERT 1 45 38 46 39 /* Slave spi_dev related */ 47 40 struct chip_data { ··· 258 263 static void giveback(struct dw_spi *dws) 259 264 { 260 265 struct spi_transfer *last_transfer; 261 - unsigned long flags; 262 266 struct spi_message *msg; 263 267 264 - spin_lock_irqsave(&dws->lock, flags); 265 268 msg = dws->cur_msg; 266 269 dws->cur_msg = NULL; 267 270 dws->cur_transfer = NULL; 268 271 dws->prev_chip = dws->cur_chip; 269 272 dws->cur_chip = NULL; 270 273 dws->dma_mapped = 0; 271 - queue_work(dws->workqueue, &dws->pump_messages); 272 - spin_unlock_irqrestore(&dws->lock, flags); 273 274 274 275 last_transfer = list_last_entry(&msg->transfers, struct spi_transfer, 275 276 transfer_list); 276 277 277 - if (!last_transfer->cs_change && dws->cs_control) 278 - dws->cs_control(MRST_SPI_DEASSERT); 278 + if (!last_transfer->cs_change) 279 + spi_chip_sel(dws, dws->cur_msg->spi, 0); 279 280 280 - msg->state = NULL; 281 - if (msg->complete) 282 - msg->complete(msg->context); 281 + spi_finalize_current_message(dws->master); 283 282 } 284 283 285 284 static void int_error_stop(struct dw_spi *dws, const char *msg) ··· 491 502 dw_writew(dws, DW_SPI_CTRL0, cr0); 492 503 493 504 spi_set_clk(dws, clk_div ? clk_div : chip->clk_div); 494 - spi_chip_sel(dws, spi->chip_select); 505 + spi_chip_sel(dws, spi, 1); 495 506 496 507 /* Set the interrupt mask, for poll mode just disable all int */ 497 508 spi_mask_intr(dws, 0xff); ··· 518 529 return; 519 530 } 520 531 521 - static void pump_messages(struct work_struct *work) 532 + static int dw_spi_transfer_one_message(struct spi_master *master, 533 + struct spi_message *msg) 522 534 { 523 - struct dw_spi *dws = 524 - container_of(work, struct dw_spi, pump_messages); 525 - unsigned long flags; 535 + struct dw_spi *dws = spi_master_get_devdata(master); 526 536 527 - /* Lock queue and check for queue work */ 528 - spin_lock_irqsave(&dws->lock, flags); 529 - if (list_empty(&dws->queue) || dws->run == QUEUE_STOPPED) { 530 - dws->busy = 0; 531 - spin_unlock_irqrestore(&dws->lock, flags); 532 - return; 533 - } 534 - 535 - /* Make sure we are not already running a message */ 536 - if (dws->cur_msg) { 537 - spin_unlock_irqrestore(&dws->lock, flags); 538 - return; 539 - } 540 - 541 - /* Extract head of queue */ 542 - dws->cur_msg = list_entry(dws->queue.next, struct spi_message, queue); 543 - list_del_init(&dws->cur_msg->queue); 544 - 537 + dws->cur_msg = msg; 545 538 /* Initial message state*/ 546 539 dws->cur_msg->state = START_STATE; 547 540 dws->cur_transfer = list_entry(dws->cur_msg->transfers.next, ··· 531 560 transfer_list); 532 561 dws->cur_chip = spi_get_ctldata(dws->cur_msg->spi); 533 562 534 - /* Mark as busy and launch transfers */ 563 + /* Launch transfers */ 535 564 tasklet_schedule(&dws->pump_transfers); 536 565 537 - dws->busy = 1; 538 - spin_unlock_irqrestore(&dws->lock, flags); 539 - } 540 - 541 - /* spi_device use this to queue in their spi_msg */ 542 - static int dw_spi_transfer(struct spi_device *spi, struct spi_message *msg) 543 - { 544 - struct dw_spi *dws = spi_master_get_devdata(spi->master); 545 - unsigned long flags; 546 - 547 - spin_lock_irqsave(&dws->lock, flags); 548 - 549 - if (dws->run == QUEUE_STOPPED) { 550 - spin_unlock_irqrestore(&dws->lock, flags); 551 - return -ESHUTDOWN; 552 - } 553 - 554 - msg->actual_length = 0; 555 - msg->status = -EINPROGRESS; 556 - msg->state = START_STATE; 557 - 558 - list_add_tail(&msg->queue, &dws->queue); 559 - 560 - if (dws->run == QUEUE_RUNNING && !dws->busy) { 561 - 562 - if (dws->cur_transfer || dws->cur_msg) 563 - queue_work(dws->workqueue, 564 - &dws->pump_messages); 565 - else { 566 - /* If no other data transaction in air, just go */ 567 - spin_unlock_irqrestore(&dws->lock, flags); 568 - pump_messages(&dws->pump_messages); 569 - return 0; 570 - } 571 - } 572 - 573 - spin_unlock_irqrestore(&dws->lock, flags); 574 566 return 0; 575 567 } 576 568 ··· 542 608 { 543 609 struct dw_spi_chip *chip_info = NULL; 544 610 struct chip_data *chip; 611 + int ret; 545 612 546 613 /* Only alloc on first setup */ 547 614 chip = spi_get_ctldata(spi); ··· 596 661 | (spi->mode << SPI_MODE_OFFSET) 597 662 | (chip->tmode << SPI_TMOD_OFFSET); 598 663 599 - return 0; 600 - } 601 - 602 - static int init_queue(struct dw_spi *dws) 603 - { 604 - INIT_LIST_HEAD(&dws->queue); 605 - spin_lock_init(&dws->lock); 606 - 607 - dws->run = QUEUE_STOPPED; 608 - dws->busy = 0; 609 - 610 - tasklet_init(&dws->pump_transfers, 611 - pump_transfers, (unsigned long)dws); 612 - 613 - INIT_WORK(&dws->pump_messages, pump_messages); 614 - dws->workqueue = create_singlethread_workqueue( 615 - dev_name(dws->master->dev.parent)); 616 - if (dws->workqueue == NULL) 617 - return -EBUSY; 618 - 619 - return 0; 620 - } 621 - 622 - static int start_queue(struct dw_spi *dws) 623 - { 624 - unsigned long flags; 625 - 626 - spin_lock_irqsave(&dws->lock, flags); 627 - 628 - if (dws->run == QUEUE_RUNNING || dws->busy) { 629 - spin_unlock_irqrestore(&dws->lock, flags); 630 - return -EBUSY; 664 + if (gpio_is_valid(spi->cs_gpio)) { 665 + ret = gpio_direction_output(spi->cs_gpio, 666 + !(spi->mode & SPI_CS_HIGH)); 667 + if (ret) 668 + return ret; 631 669 } 632 670 633 - dws->run = QUEUE_RUNNING; 634 - dws->cur_msg = NULL; 635 - dws->cur_transfer = NULL; 636 - dws->cur_chip = NULL; 637 - dws->prev_chip = NULL; 638 - spin_unlock_irqrestore(&dws->lock, flags); 639 - 640 - queue_work(dws->workqueue, &dws->pump_messages); 641 - 642 - return 0; 643 - } 644 - 645 - static int stop_queue(struct dw_spi *dws) 646 - { 647 - unsigned long flags; 648 - unsigned limit = 50; 649 - int status = 0; 650 - 651 - spin_lock_irqsave(&dws->lock, flags); 652 - dws->run = QUEUE_STOPPED; 653 - while ((!list_empty(&dws->queue) || dws->busy) && limit--) { 654 - spin_unlock_irqrestore(&dws->lock, flags); 655 - msleep(10); 656 - spin_lock_irqsave(&dws->lock, flags); 657 - } 658 - 659 - if (!list_empty(&dws->queue) || dws->busy) 660 - status = -EBUSY; 661 - spin_unlock_irqrestore(&dws->lock, flags); 662 - 663 - return status; 664 - } 665 - 666 - static int destroy_queue(struct dw_spi *dws) 667 - { 668 - int status; 669 - 670 - status = stop_queue(dws); 671 - if (status != 0) 672 - return status; 673 - destroy_workqueue(dws->workqueue); 674 671 return 0; 675 672 } 676 673 ··· 661 794 master->bus_num = dws->bus_num; 662 795 master->num_chipselect = dws->num_cs; 663 796 master->setup = dw_spi_setup; 664 - master->transfer = dw_spi_transfer; 797 + master->transfer_one_message = dw_spi_transfer_one_message; 665 798 master->max_speed_hz = dws->max_freq; 666 799 667 800 /* Basic HW init */ ··· 675 808 } 676 809 } 677 810 678 - /* Initial and start queue */ 679 - ret = init_queue(dws); 680 - if (ret) { 681 - dev_err(&master->dev, "problem initializing queue\n"); 682 - goto err_diable_hw; 683 - } 684 - ret = start_queue(dws); 685 - if (ret) { 686 - dev_err(&master->dev, "problem starting queue\n"); 687 - goto err_diable_hw; 688 - } 811 + tasklet_init(&dws->pump_transfers, pump_transfers, (unsigned long)dws); 689 812 690 813 spi_master_set_devdata(master, dws); 691 814 ret = devm_spi_register_master(dev, master); 692 815 if (ret) { 693 816 dev_err(&master->dev, "problem registering spi master\n"); 694 - goto err_queue_alloc; 817 + goto err_dma_exit; 695 818 } 696 819 697 820 mrst_spi_debugfs_init(dws); 698 821 return 0; 699 822 700 - err_queue_alloc: 701 - destroy_queue(dws); 823 + err_dma_exit: 702 824 if (dws->dma_ops && dws->dma_ops->dma_exit) 703 825 dws->dma_ops->dma_exit(dws); 704 - err_diable_hw: 705 826 spi_enable_chip(dws, 0); 706 827 err_free_master: 707 828 spi_master_put(master); ··· 699 844 700 845 void dw_spi_remove_host(struct dw_spi *dws) 701 846 { 702 - int status = 0; 703 - 704 847 if (!dws) 705 848 return; 706 849 mrst_spi_debugfs_remove(dws); 707 - 708 - /* Remove the queue */ 709 - status = destroy_queue(dws); 710 - if (status != 0) 711 - dev_err(&dws->master->dev, 712 - "dw_spi_remove: workqueue will not complete, message memory not freed\n"); 713 850 714 851 if (dws->dma_ops && dws->dma_ops->dma_exit) 715 852 dws->dma_ops->dma_exit(dws); ··· 715 868 { 716 869 int ret = 0; 717 870 718 - ret = stop_queue(dws); 871 + ret = spi_master_suspend(dws->master); 719 872 if (ret) 720 873 return ret; 721 874 spi_enable_chip(dws, 0); ··· 729 882 int ret; 730 883 731 884 spi_hw_init(dws); 732 - ret = start_queue(dws); 885 + ret = spi_master_resume(dws->master); 733 886 if (ret) 734 887 dev_err(&dws->master->dev, "fail to start queue (%d)\n", ret); 735 888 return ret;
+11 -13
drivers/spi/spi-dw.h
··· 3 3 4 4 #include <linux/io.h> 5 5 #include <linux/scatterlist.h> 6 + #include <linux/gpio.h> 6 7 7 8 /* Register offsets */ 8 9 #define DW_SPI_CTRL0 0x00 ··· 105 104 u16 bus_num; 106 105 u16 num_cs; /* supported slave numbers */ 107 106 108 - /* Driver message queue */ 109 - struct workqueue_struct *workqueue; 110 - struct work_struct pump_messages; 111 - spinlock_t lock; 112 - struct list_head queue; 113 - int busy; 114 - int run; 115 - 116 107 /* Message Transfer pump */ 117 108 struct tasklet_struct pump_transfers; 118 109 ··· 179 186 dw_writel(dws, DW_SPI_BAUDR, div); 180 187 } 181 188 182 - static inline void spi_chip_sel(struct dw_spi *dws, u16 cs) 189 + static inline void spi_chip_sel(struct dw_spi *dws, struct spi_device *spi, 190 + int active) 183 191 { 184 - if (cs > dws->num_cs) 185 - return; 192 + u16 cs = spi->chip_select; 193 + int gpio_val = active ? (spi->mode & SPI_CS_HIGH) : 194 + !(spi->mode & SPI_CS_HIGH); 186 195 187 196 if (dws->cs_control) 188 - dws->cs_control(1); 197 + dws->cs_control(active); 198 + if (gpio_is_valid(spi->cs_gpio)) 199 + gpio_set_value(spi->cs_gpio, gpio_val); 189 200 190 - dw_writel(dws, DW_SPI_SER, 1 << cs); 201 + if (active) 202 + dw_writel(dws, DW_SPI_SER, 1 << cs); 191 203 } 192 204 193 205 /* Disable IRQ bits */
-1
drivers/spi/spi-falcon.c
··· 11 11 #include <linux/platform_device.h> 12 12 #include <linux/spi/spi.h> 13 13 #include <linux/delay.h> 14 - #include <linux/workqueue.h> 15 14 #include <linux/of.h> 16 15 #include <linux/of_platform.h> 17 16
+1 -1
drivers/spi/spi-fsl-dspi.c
··· 406 406 return IRQ_HANDLED; 407 407 } 408 408 409 - static struct of_device_id fsl_dspi_dt_ids[] = { 409 + static const struct of_device_id fsl_dspi_dt_ids[] = { 410 410 { .compatible = "fsl,vf610-dspi", .data = NULL, }, 411 411 { /* sentinel */ } 412 412 };
+33 -7
drivers/spi/spi-fsl-espi.c
··· 348 348 } 349 349 350 350 espi_trans->tx_buf = local_buf; 351 - espi_trans->rx_buf = local_buf + espi_trans->n_tx; 351 + espi_trans->rx_buf = local_buf; 352 352 fsl_espi_do_trans(m, espi_trans); 353 353 354 354 espi_trans->actual_length = espi_trans->len; ··· 397 397 espi_trans->n_rx = trans_len; 398 398 espi_trans->len = trans_len + n_tx; 399 399 espi_trans->tx_buf = local_buf; 400 - espi_trans->rx_buf = local_buf + n_tx; 400 + espi_trans->rx_buf = local_buf; 401 401 fsl_espi_do_trans(m, espi_trans); 402 402 403 403 memcpy(rx_buf + pos, espi_trans->rx_buf + n_tx, trans_len); ··· 458 458 return -EINVAL; 459 459 460 460 if (!cs) { 461 - cs = kzalloc(sizeof *cs, GFP_KERNEL); 461 + cs = devm_kzalloc(&spi->dev, sizeof(*cs), GFP_KERNEL); 462 462 if (!cs) 463 463 return -ENOMEM; 464 464 spi->controller_state = cs; ··· 586 586 struct spi_master *master; 587 587 struct mpc8xxx_spi *mpc8xxx_spi; 588 588 struct fsl_espi_reg *reg_base; 589 - u32 regval; 590 - int i, ret = 0; 589 + struct device_node *nc; 590 + const __be32 *prop; 591 + u32 regval, csmode; 592 + int i, len, ret = 0; 591 593 592 594 master = spi_alloc_master(dev, sizeof(struct mpc8xxx_spi)); 593 595 if (!master) { ··· 636 634 mpc8xxx_spi_write_reg(&reg_base->event, 0xffffffff); 637 635 638 636 /* Init eSPI CS mode register */ 639 - for (i = 0; i < pdata->max_chipselect; i++) 640 - mpc8xxx_spi_write_reg(&reg_base->csmode[i], CSMODE_INIT_VAL); 637 + for_each_available_child_of_node(master->dev.of_node, nc) { 638 + /* get chip select */ 639 + prop = of_get_property(nc, "reg", &len); 640 + if (!prop || len < sizeof(*prop)) 641 + continue; 642 + i = be32_to_cpup(prop); 643 + if (i < 0 || i >= pdata->max_chipselect) 644 + continue; 645 + 646 + csmode = CSMODE_INIT_VAL; 647 + /* check if CSBEF is set in device tree */ 648 + prop = of_get_property(nc, "fsl,csbef", &len); 649 + if (prop && len >= sizeof(*prop)) { 650 + csmode &= ~(CSMODE_BEF(0xf)); 651 + csmode |= CSMODE_BEF(be32_to_cpup(prop)); 652 + } 653 + /* check if CSAFT is set in device tree */ 654 + prop = of_get_property(nc, "fsl,csaft", &len); 655 + if (prop && len >= sizeof(*prop)) { 656 + csmode &= ~(CSMODE_AFT(0xf)); 657 + csmode |= CSMODE_AFT(be32_to_cpup(prop)); 658 + } 659 + mpc8xxx_spi_write_reg(&reg_base->csmode[i], csmode); 660 + 661 + dev_info(dev, "cs=%d, init_csmode=0x%x\n", i, csmode); 662 + } 641 663 642 664 /* Enable SPI interface */ 643 665 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE;
-6
drivers/spi/spi-fsl-lib.c
··· 99 99 return 0; 100 100 } 101 101 102 - void mpc8xxx_spi_cleanup(struct spi_device *spi) 103 - { 104 - kfree(spi->controller_state); 105 - } 106 - 107 102 const char *mpc8xxx_spi_strmode(unsigned int flags) 108 103 { 109 104 if (flags & SPI_QE_CPU_MODE) { ··· 129 134 | SPI_LSB_FIRST | SPI_LOOP; 130 135 131 136 master->transfer = mpc8xxx_spi_transfer; 132 - master->cleanup = mpc8xxx_spi_cleanup; 133 137 master->dev.of_node = dev->of_node; 134 138 135 139 mpc8xxx_spi = spi_master_get_devdata(master);
-1
drivers/spi/spi-fsl-lib.h
··· 124 124 extern int mpc8xxx_spi_bufs(struct mpc8xxx_spi *mspi, 125 125 struct spi_transfer *t, unsigned int len); 126 126 extern int mpc8xxx_spi_transfer(struct spi_device *spi, struct spi_message *m); 127 - extern void mpc8xxx_spi_cleanup(struct spi_device *spi); 128 127 extern const char *mpc8xxx_spi_strmode(unsigned int flags); 129 128 extern int mpc8xxx_spi_probe(struct device *dev, struct resource *mem, 130 129 unsigned int irq);
+1 -1
drivers/spi/spi-fsl-spi.c
··· 431 431 return -EINVAL; 432 432 433 433 if (!cs) { 434 - cs = kzalloc(sizeof *cs, GFP_KERNEL); 434 + cs = devm_kzalloc(&spi->dev, sizeof(*cs), GFP_KERNEL); 435 435 if (!cs) 436 436 return -ENOMEM; 437 437 spi->controller_state = cs;
+1 -1
drivers/spi/spi-gpio.c
··· 340 340 } 341 341 342 342 #ifdef CONFIG_OF 343 - static struct of_device_id spi_gpio_dt_ids[] = { 343 + static const struct of_device_id spi_gpio_dt_ids[] = { 344 344 { .compatible = "spi-gpio" }, 345 345 {} 346 346 };
-1
drivers/spi/spi-nuc900.c
··· 10 10 11 11 #include <linux/module.h> 12 12 #include <linux/spinlock.h> 13 - #include <linux/workqueue.h> 14 13 #include <linux/interrupt.h> 15 14 #include <linux/delay.h> 16 15 #include <linux/errno.h>
-1
drivers/spi/spi-omap-uwire.c
··· 37 37 #include <linux/init.h> 38 38 #include <linux/delay.h> 39 39 #include <linux/platform_device.h> 40 - #include <linux/workqueue.h> 41 40 #include <linux/interrupt.h> 42 41 #include <linux/err.h> 43 42 #include <linux/clk.h>
+3 -10
drivers/spi/spi-pl022.c
··· 1111 1111 } 1112 1112 1113 1113 pl022->dummypage = kmalloc(PAGE_SIZE, GFP_KERNEL); 1114 - if (!pl022->dummypage) { 1115 - dev_dbg(&pl022->adev->dev, "no DMA dummypage!\n"); 1114 + if (!pl022->dummypage) 1116 1115 goto err_no_dummypage; 1117 - } 1118 1116 1119 1117 dev_info(&pl022->adev->dev, "setup for DMA on RX %s, TX %s\n", 1120 1118 dma_chan_name(pl022->dma_rx_channel), ··· 1807 1809 1808 1810 if (chip == NULL) { 1809 1811 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); 1810 - if (!chip) { 1811 - dev_err(&spi->dev, 1812 - "cannot allocate controller state\n"); 1812 + if (!chip) 1813 1813 return -ENOMEM; 1814 - } 1815 1814 dev_dbg(&spi->dev, 1816 1815 "allocated memory for controller's runtime state\n"); 1817 1816 } ··· 2045 2050 } 2046 2051 2047 2052 pd = devm_kzalloc(dev, sizeof(struct pl022_ssp_controller), GFP_KERNEL); 2048 - if (!pd) { 2049 - dev_err(dev, "cannot allocate platform data memory\n"); 2053 + if (!pd) 2050 2054 return NULL; 2051 - } 2052 2055 2053 2056 pd->bus_id = -1; 2054 2057 pd->enable_dma = 1;
+61 -15
drivers/spi/spi-pxa2xx-pci.c
··· 8 8 #include <linux/module.h> 9 9 #include <linux/spi/pxa2xx_spi.h> 10 10 11 - static int ce4100_spi_probe(struct pci_dev *dev, 11 + enum { 12 + PORT_CE4100, 13 + PORT_BYT, 14 + }; 15 + 16 + struct pxa_spi_info { 17 + enum pxa_ssp_type type; 18 + int port_id; 19 + int num_chipselect; 20 + int tx_slave_id; 21 + int tx_chan_id; 22 + int rx_slave_id; 23 + int rx_chan_id; 24 + }; 25 + 26 + static struct pxa_spi_info spi_info_configs[] = { 27 + [PORT_CE4100] = { 28 + .type = PXA25x_SSP, 29 + .port_id = -1, 30 + .num_chipselect = -1, 31 + .tx_slave_id = -1, 32 + .tx_chan_id = -1, 33 + .rx_slave_id = -1, 34 + .rx_chan_id = -1, 35 + }, 36 + [PORT_BYT] = { 37 + .type = LPSS_SSP, 38 + .port_id = 0, 39 + .num_chipselect = 1, 40 + .tx_slave_id = 0, 41 + .tx_chan_id = 0, 42 + .rx_slave_id = 1, 43 + .rx_chan_id = 1, 44 + }, 45 + }; 46 + 47 + static int pxa2xx_spi_pci_probe(struct pci_dev *dev, 12 48 const struct pci_device_id *ent) 13 49 { 14 50 struct platform_device_info pi; ··· 52 16 struct platform_device *pdev; 53 17 struct pxa2xx_spi_master spi_pdata; 54 18 struct ssp_device *ssp; 19 + struct pxa_spi_info *c; 55 20 56 21 ret = pcim_enable_device(dev); 57 22 if (ret) ··· 62 25 if (ret) 63 26 return ret; 64 27 28 + c = &spi_info_configs[ent->driver_data]; 29 + 65 30 memset(&spi_pdata, 0, sizeof(spi_pdata)); 66 - spi_pdata.num_chipselect = dev->devfn; 31 + spi_pdata.num_chipselect = (c->num_chipselect > 0) ? 32 + c->num_chipselect : dev->devfn; 33 + spi_pdata.tx_slave_id = c->tx_slave_id; 34 + spi_pdata.tx_chan_id = c->tx_chan_id; 35 + spi_pdata.rx_slave_id = c->rx_slave_id; 36 + spi_pdata.rx_chan_id = c->rx_chan_id; 37 + spi_pdata.enable_dma = c->rx_slave_id >= 0 && c->tx_slave_id >= 0; 67 38 68 39 ssp = &spi_pdata.ssp; 69 40 ssp->phys_base = pci_resource_start(dev, 0); ··· 81 36 return -EIO; 82 37 } 83 38 ssp->irq = dev->irq; 84 - ssp->port_id = dev->devfn; 85 - ssp->type = PXA25x_SSP; 39 + ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn; 40 + ssp->type = c->type; 86 41 87 42 memset(&pi, 0, sizeof(pi)); 88 43 pi.parent = &dev->dev; ··· 100 55 return 0; 101 56 } 102 57 103 - static void ce4100_spi_remove(struct pci_dev *dev) 58 + static void pxa2xx_spi_pci_remove(struct pci_dev *dev) 104 59 { 105 60 struct platform_device *pdev = pci_get_drvdata(dev); 106 61 107 62 platform_device_unregister(pdev); 108 63 } 109 64 110 - static const struct pci_device_id ce4100_spi_devices[] = { 111 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2e6a) }, 65 + static const struct pci_device_id pxa2xx_spi_pci_devices[] = { 66 + { PCI_VDEVICE(INTEL, 0x2e6a), PORT_CE4100 }, 67 + { PCI_VDEVICE(INTEL, 0x0f0e), PORT_BYT }, 112 68 { }, 113 69 }; 114 - MODULE_DEVICE_TABLE(pci, ce4100_spi_devices); 70 + MODULE_DEVICE_TABLE(pci, pxa2xx_spi_pci_devices); 115 71 116 - static struct pci_driver ce4100_spi_driver = { 117 - .name = "ce4100_spi", 118 - .id_table = ce4100_spi_devices, 119 - .probe = ce4100_spi_probe, 120 - .remove = ce4100_spi_remove, 72 + static struct pci_driver pxa2xx_spi_pci_driver = { 73 + .name = "pxa2xx_spi_pci", 74 + .id_table = pxa2xx_spi_pci_devices, 75 + .probe = pxa2xx_spi_pci_probe, 76 + .remove = pxa2xx_spi_pci_remove, 121 77 }; 122 78 123 - module_pci_driver(ce4100_spi_driver); 79 + module_pci_driver(pxa2xx_spi_pci_driver); 124 80 125 - MODULE_DESCRIPTION("CE4100 PCI-SPI glue code for PXA's driver"); 81 + MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver"); 126 82 MODULE_LICENSE("GPL v2"); 127 83 MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");
+7 -14
drivers/spi/spi-pxa2xx.c
··· 27 27 #include <linux/platform_device.h> 28 28 #include <linux/spi/pxa2xx_spi.h> 29 29 #include <linux/spi/spi.h> 30 - #include <linux/workqueue.h> 31 30 #include <linux/delay.h> 32 31 #include <linux/gpio.h> 33 32 #include <linux/slab.h> ··· 885 886 chip = spi_get_ctldata(spi); 886 887 if (!chip) { 887 888 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); 888 - if (!chip) { 889 - dev_err(&spi->dev, 890 - "failed setup: can't allocate chip data\n"); 889 + if (!chip) 891 890 return -ENOMEM; 892 - } 893 891 894 892 if (drv_data->ssp_type == CE4100_SSP) { 895 893 if (spi->chip_select > 4) { ··· 1033 1037 return NULL; 1034 1038 1035 1039 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 1036 - if (!pdata) { 1037 - dev_err(&pdev->dev, 1038 - "failed to allocate memory for platform data\n"); 1040 + if (!pdata) 1039 1041 return NULL; 1040 - } 1041 1042 1042 1043 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1043 1044 if (!res) ··· 1195 1202 tasklet_init(&drv_data->pump_transfers, pump_transfers, 1196 1203 (unsigned long)drv_data); 1197 1204 1205 + pm_runtime_set_autosuspend_delay(&pdev->dev, 50); 1206 + pm_runtime_use_autosuspend(&pdev->dev); 1207 + pm_runtime_set_active(&pdev->dev); 1208 + pm_runtime_enable(&pdev->dev); 1209 + 1198 1210 /* Register with the SPI framework */ 1199 1211 platform_set_drvdata(pdev, drv_data); 1200 1212 status = devm_spi_register_master(&pdev->dev, master); ··· 1207 1209 dev_err(&pdev->dev, "problem registering spi master\n"); 1208 1210 goto out_error_clock_enabled; 1209 1211 } 1210 - 1211 - pm_runtime_set_autosuspend_delay(&pdev->dev, 50); 1212 - pm_runtime_use_autosuspend(&pdev->dev); 1213 - pm_runtime_set_active(&pdev->dev); 1214 - pm_runtime_enable(&pdev->dev); 1215 1212 1216 1213 return status; 1217 1214
+3 -3
drivers/spi/spi-qup.c
··· 287 287 writel_relaxed(opflags, controller->base + QUP_OPERATIONAL); 288 288 289 289 if (!xfer) { 290 - dev_err_ratelimited(controller->dev, "unexpected irq %x08 %x08 %x08\n", 290 + dev_err_ratelimited(controller->dev, "unexpected irq %08x %08x %08x\n", 291 291 qup_err, spi_err, opflags); 292 292 return IRQ_HANDLED; 293 293 } ··· 366 366 n_words = xfer->len / w_size; 367 367 controller->w_size = w_size; 368 368 369 - if (n_words <= controller->in_fifo_sz) { 369 + if (n_words <= (controller->in_fifo_sz / sizeof(u32))) { 370 370 mode = QUP_IO_M_MODE_FIFO; 371 371 writel_relaxed(n_words, controller->base + QUP_MX_READ_CNT); 372 372 writel_relaxed(n_words, controller->base + QUP_MX_WRITE_CNT); ··· 749 749 return 0; 750 750 } 751 751 752 - static struct of_device_id spi_qup_dt_match[] = { 752 + static const struct of_device_id spi_qup_dt_match[] = { 753 753 { .compatible = "qcom,spi-qup-v2.1.1", }, 754 754 { .compatible = "qcom,spi-qup-v2.2.1", }, 755 755 { }
+215 -382
drivers/spi/spi-rspi.c
··· 183 183 #define SPBFCR_TXTRG_MASK 0x30 /* Transmit Buffer Data Triggering Number */ 184 184 #define SPBFCR_RXTRG_MASK 0x07 /* Receive Buffer Data Triggering Number */ 185 185 186 - #define DUMMY_DATA 0x00 187 - 188 186 struct rspi_data { 189 187 void __iomem *addr; 190 188 u32 max_speed_hz; ··· 195 197 int rx_irq, tx_irq; 196 198 const struct spi_ops *ops; 197 199 198 - /* for dmaengine */ 199 - struct dma_chan *chan_tx; 200 - struct dma_chan *chan_rx; 201 - 202 - unsigned dma_width_16bit:1; 203 200 unsigned dma_callbacked:1; 204 201 unsigned byte_access:1; 205 202 }; ··· 246 253 int (*transfer_one)(struct spi_master *master, struct spi_device *spi, 247 254 struct spi_transfer *xfer); 248 255 u16 mode_bits; 256 + u16 flags; 257 + u16 fifo_size; 249 258 }; 250 259 251 260 /* ··· 261 266 rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR); 262 267 263 268 /* Sets transfer bit rate */ 264 - spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1; 269 + spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk), 270 + 2 * rspi->max_speed_hz) - 1; 265 271 rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR); 266 272 267 273 /* Disable dummy transmission, set 16-bit word access, 1 frame */ ··· 298 302 rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR); 299 303 300 304 /* Sets transfer bit rate */ 301 - spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz) - 1; 305 + spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk), 306 + 2 * rspi->max_speed_hz) - 1; 302 307 rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR); 303 308 304 309 /* Disable dummy transmission, set byte access */ ··· 332 335 rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR); 333 336 334 337 /* Sets transfer bit rate */ 335 - spbr = clk_get_rate(rspi->clk) / (2 * rspi->max_speed_hz); 338 + spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk), 2 * rspi->max_speed_hz); 336 339 rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR); 337 340 338 341 /* Disable dummy transmission, set byte access */ ··· 400 403 return 0; 401 404 } 402 405 406 + static inline int rspi_wait_for_tx_empty(struct rspi_data *rspi) 407 + { 408 + return rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); 409 + } 410 + 411 + static inline int rspi_wait_for_rx_full(struct rspi_data *rspi) 412 + { 413 + return rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE); 414 + } 415 + 403 416 static int rspi_data_out(struct rspi_data *rspi, u8 data) 404 417 { 405 - if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { 418 + int error = rspi_wait_for_tx_empty(rspi); 419 + if (error < 0) { 406 420 dev_err(&rspi->master->dev, "transmit timeout\n"); 407 - return -ETIMEDOUT; 421 + return error; 408 422 } 409 423 rspi_write_data(rspi, data); 410 424 return 0; ··· 423 415 424 416 static int rspi_data_in(struct rspi_data *rspi) 425 417 { 418 + int error; 426 419 u8 data; 427 420 428 - if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) { 421 + error = rspi_wait_for_rx_full(rspi); 422 + if (error < 0) { 429 423 dev_err(&rspi->master->dev, "receive timeout\n"); 430 - return -ETIMEDOUT; 424 + return error; 431 425 } 432 426 data = rspi_read_data(rspi); 433 427 return data; 434 428 } 435 429 436 - static int rspi_data_out_in(struct rspi_data *rspi, u8 data) 430 + static int rspi_pio_transfer(struct rspi_data *rspi, const u8 *tx, u8 *rx, 431 + unsigned int n) 437 432 { 438 - int ret; 433 + while (n-- > 0) { 434 + if (tx) { 435 + int ret = rspi_data_out(rspi, *tx++); 436 + if (ret < 0) 437 + return ret; 438 + } 439 + if (rx) { 440 + int ret = rspi_data_in(rspi); 441 + if (ret < 0) 442 + return ret; 443 + *rx++ = ret; 444 + } 445 + } 439 446 440 - ret = rspi_data_out(rspi, data); 441 - if (ret < 0) 442 - return ret; 443 - 444 - return rspi_data_in(rspi); 447 + return 0; 445 448 } 446 449 447 450 static void rspi_dma_complete(void *arg) ··· 463 444 wake_up_interruptible(&rspi->wait); 464 445 } 465 446 466 - static int rspi_dma_map_sg(struct scatterlist *sg, const void *buf, 467 - unsigned len, struct dma_chan *chan, 468 - enum dma_transfer_direction dir) 447 + static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, 448 + struct sg_table *rx) 469 449 { 470 - sg_init_table(sg, 1); 471 - sg_set_buf(sg, buf, len); 472 - sg_dma_len(sg) = len; 473 - return dma_map_sg(chan->device->dev, sg, 1, dir); 474 - } 450 + struct dma_async_tx_descriptor *desc_tx = NULL, *desc_rx = NULL; 451 + u8 irq_mask = 0; 452 + unsigned int other_irq = 0; 453 + dma_cookie_t cookie; 454 + int ret; 475 455 476 - static void rspi_dma_unmap_sg(struct scatterlist *sg, struct dma_chan *chan, 477 - enum dma_transfer_direction dir) 478 - { 479 - dma_unmap_sg(chan->device->dev, sg, 1, dir); 480 - } 456 + if (tx) { 457 + desc_tx = dmaengine_prep_slave_sg(rspi->master->dma_tx, 458 + tx->sgl, tx->nents, DMA_TO_DEVICE, 459 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 460 + if (!desc_tx) 461 + return -EIO; 481 462 482 - static void rspi_memory_to_8bit(void *buf, const void *data, unsigned len) 483 - { 484 - u16 *dst = buf; 485 - const u8 *src = data; 486 - 487 - while (len) { 488 - *dst++ = (u16)(*src++); 489 - len--; 463 + irq_mask |= SPCR_SPTIE; 490 464 } 491 - } 465 + if (rx) { 466 + desc_rx = dmaengine_prep_slave_sg(rspi->master->dma_rx, 467 + rx->sgl, rx->nents, DMA_FROM_DEVICE, 468 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 469 + if (!desc_rx) 470 + return -EIO; 492 471 493 - static void rspi_memory_from_8bit(void *buf, const void *data, unsigned len) 494 - { 495 - u8 *dst = buf; 496 - const u16 *src = data; 497 - 498 - while (len) { 499 - *dst++ = (u8)*src++; 500 - len--; 501 - } 502 - } 503 - 504 - static int rspi_send_dma(struct rspi_data *rspi, struct spi_transfer *t) 505 - { 506 - struct scatterlist sg; 507 - const void *buf = NULL; 508 - struct dma_async_tx_descriptor *desc; 509 - unsigned int len; 510 - int ret = 0; 511 - 512 - if (rspi->dma_width_16bit) { 513 - void *tmp; 514 - /* 515 - * If DMAC bus width is 16-bit, the driver allocates a dummy 516 - * buffer. And, the driver converts original data into the 517 - * DMAC data as the following format: 518 - * original data: 1st byte, 2nd byte ... 519 - * DMAC data: 1st byte, dummy, 2nd byte, dummy ... 520 - */ 521 - len = t->len * 2; 522 - tmp = kmalloc(len, GFP_KERNEL); 523 - if (!tmp) 524 - return -ENOMEM; 525 - rspi_memory_to_8bit(tmp, t->tx_buf, t->len); 526 - buf = tmp; 527 - } else { 528 - len = t->len; 529 - buf = t->tx_buf; 530 - } 531 - 532 - if (!rspi_dma_map_sg(&sg, buf, len, rspi->chan_tx, DMA_TO_DEVICE)) { 533 - ret = -EFAULT; 534 - goto end_nomap; 535 - } 536 - desc = dmaengine_prep_slave_sg(rspi->chan_tx, &sg, 1, DMA_TO_DEVICE, 537 - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 538 - if (!desc) { 539 - ret = -EIO; 540 - goto end; 472 + irq_mask |= SPCR_SPRIE; 541 473 } 542 474 543 475 /* 544 - * DMAC needs SPTIE, but if SPTIE is set, this IRQ routine will be 476 + * DMAC needs SPxIE, but if SPxIE is set, the IRQ routine will be 545 477 * called. So, this driver disables the IRQ while DMA transfer. 546 478 */ 547 - disable_irq(rspi->tx_irq); 479 + if (tx) 480 + disable_irq(other_irq = rspi->tx_irq); 481 + if (rx && rspi->rx_irq != other_irq) 482 + disable_irq(rspi->rx_irq); 548 483 549 - rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD, RSPI_SPCR); 550 - rspi_enable_irq(rspi, SPCR_SPTIE); 484 + rspi_enable_irq(rspi, irq_mask); 551 485 rspi->dma_callbacked = 0; 552 486 553 - desc->callback = rspi_dma_complete; 554 - desc->callback_param = rspi; 555 - dmaengine_submit(desc); 556 - dma_async_issue_pending(rspi->chan_tx); 487 + if (rx) { 488 + desc_rx->callback = rspi_dma_complete; 489 + desc_rx->callback_param = rspi; 490 + cookie = dmaengine_submit(desc_rx); 491 + if (dma_submit_error(cookie)) 492 + return cookie; 493 + dma_async_issue_pending(rspi->master->dma_rx); 494 + } 495 + if (tx) { 496 + if (rx) { 497 + /* No callback */ 498 + desc_tx->callback = NULL; 499 + } else { 500 + desc_tx->callback = rspi_dma_complete; 501 + desc_tx->callback_param = rspi; 502 + } 503 + cookie = dmaengine_submit(desc_tx); 504 + if (dma_submit_error(cookie)) 505 + return cookie; 506 + dma_async_issue_pending(rspi->master->dma_tx); 507 + } 557 508 558 509 ret = wait_event_interruptible_timeout(rspi->wait, 559 510 rspi->dma_callbacked, HZ); ··· 531 542 ret = 0; 532 543 else if (!ret) 533 544 ret = -ETIMEDOUT; 534 - rspi_disable_irq(rspi, SPCR_SPTIE); 535 545 536 - enable_irq(rspi->tx_irq); 546 + rspi_disable_irq(rspi, irq_mask); 537 547 538 - end: 539 - rspi_dma_unmap_sg(&sg, rspi->chan_tx, DMA_TO_DEVICE); 540 - end_nomap: 541 - if (rspi->dma_width_16bit) 542 - kfree(buf); 548 + if (tx) 549 + enable_irq(rspi->tx_irq); 550 + if (rx && rspi->rx_irq != other_irq) 551 + enable_irq(rspi->rx_irq); 543 552 544 553 return ret; 545 554 } ··· 572 585 rspi_write8(rspi, 0, QSPI_SPBFCR); 573 586 } 574 587 575 - static int rspi_receive_dma(struct rspi_data *rspi, struct spi_transfer *t) 588 + static bool __rspi_can_dma(const struct rspi_data *rspi, 589 + const struct spi_transfer *xfer) 576 590 { 577 - struct scatterlist sg, sg_dummy; 578 - void *dummy = NULL, *rx_buf = NULL; 579 - struct dma_async_tx_descriptor *desc, *desc_dummy; 580 - unsigned int len; 581 - int ret = 0; 582 - 583 - if (rspi->dma_width_16bit) { 584 - /* 585 - * If DMAC bus width is 16-bit, the driver allocates a dummy 586 - * buffer. And, finally the driver converts the DMAC data into 587 - * actual data as the following format: 588 - * DMAC data: 1st byte, dummy, 2nd byte, dummy ... 589 - * actual data: 1st byte, 2nd byte ... 590 - */ 591 - len = t->len * 2; 592 - rx_buf = kmalloc(len, GFP_KERNEL); 593 - if (!rx_buf) 594 - return -ENOMEM; 595 - } else { 596 - len = t->len; 597 - rx_buf = t->rx_buf; 598 - } 599 - 600 - /* prepare dummy transfer to generate SPI clocks */ 601 - dummy = kzalloc(len, GFP_KERNEL); 602 - if (!dummy) { 603 - ret = -ENOMEM; 604 - goto end_nomap; 605 - } 606 - if (!rspi_dma_map_sg(&sg_dummy, dummy, len, rspi->chan_tx, 607 - DMA_TO_DEVICE)) { 608 - ret = -EFAULT; 609 - goto end_nomap; 610 - } 611 - desc_dummy = dmaengine_prep_slave_sg(rspi->chan_tx, &sg_dummy, 1, 612 - DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 613 - if (!desc_dummy) { 614 - ret = -EIO; 615 - goto end_dummy_mapped; 616 - } 617 - 618 - /* prepare receive transfer */ 619 - if (!rspi_dma_map_sg(&sg, rx_buf, len, rspi->chan_rx, 620 - DMA_FROM_DEVICE)) { 621 - ret = -EFAULT; 622 - goto end_dummy_mapped; 623 - 624 - } 625 - desc = dmaengine_prep_slave_sg(rspi->chan_rx, &sg, 1, DMA_FROM_DEVICE, 626 - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 627 - if (!desc) { 628 - ret = -EIO; 629 - goto end; 630 - } 631 - 632 - rspi_receive_init(rspi); 633 - 634 - /* 635 - * DMAC needs SPTIE, but if SPTIE is set, this IRQ routine will be 636 - * called. So, this driver disables the IRQ while DMA transfer. 637 - */ 638 - disable_irq(rspi->tx_irq); 639 - if (rspi->rx_irq != rspi->tx_irq) 640 - disable_irq(rspi->rx_irq); 641 - 642 - rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_TXMD, RSPI_SPCR); 643 - rspi_enable_irq(rspi, SPCR_SPTIE | SPCR_SPRIE); 644 - rspi->dma_callbacked = 0; 645 - 646 - desc->callback = rspi_dma_complete; 647 - desc->callback_param = rspi; 648 - dmaengine_submit(desc); 649 - dma_async_issue_pending(rspi->chan_rx); 650 - 651 - desc_dummy->callback = NULL; /* No callback */ 652 - dmaengine_submit(desc_dummy); 653 - dma_async_issue_pending(rspi->chan_tx); 654 - 655 - ret = wait_event_interruptible_timeout(rspi->wait, 656 - rspi->dma_callbacked, HZ); 657 - if (ret > 0 && rspi->dma_callbacked) 658 - ret = 0; 659 - else if (!ret) 660 - ret = -ETIMEDOUT; 661 - rspi_disable_irq(rspi, SPCR_SPTIE | SPCR_SPRIE); 662 - 663 - enable_irq(rspi->tx_irq); 664 - if (rspi->rx_irq != rspi->tx_irq) 665 - enable_irq(rspi->rx_irq); 666 - 667 - end: 668 - rspi_dma_unmap_sg(&sg, rspi->chan_rx, DMA_FROM_DEVICE); 669 - end_dummy_mapped: 670 - rspi_dma_unmap_sg(&sg_dummy, rspi->chan_tx, DMA_TO_DEVICE); 671 - end_nomap: 672 - if (rspi->dma_width_16bit) { 673 - if (!ret) 674 - rspi_memory_from_8bit(t->rx_buf, rx_buf, t->len); 675 - kfree(rx_buf); 676 - } 677 - kfree(dummy); 678 - 679 - return ret; 591 + return xfer->len > rspi->ops->fifo_size; 680 592 } 681 593 682 - static int rspi_is_dma(const struct rspi_data *rspi, struct spi_transfer *t) 594 + static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi, 595 + struct spi_transfer *xfer) 683 596 { 684 - if (t->tx_buf && rspi->chan_tx) 685 - return 1; 686 - /* If the module receives data by DMAC, it also needs TX DMAC */ 687 - if (t->rx_buf && rspi->chan_tx && rspi->chan_rx) 688 - return 1; 597 + struct rspi_data *rspi = spi_master_get_devdata(master); 689 598 690 - return 0; 599 + return __rspi_can_dma(rspi, xfer); 691 600 } 692 601 693 - static int rspi_transfer_out_in(struct rspi_data *rspi, 602 + static int rspi_common_transfer(struct rspi_data *rspi, 694 603 struct spi_transfer *xfer) 695 604 { 696 - int remain = xfer->len, ret; 697 - const u8 *tx_buf = xfer->tx_buf; 698 - u8 *rx_buf = xfer->rx_buf; 699 - u8 spcr, data; 605 + int ret; 700 606 701 - rspi_receive_init(rspi); 702 - 703 - spcr = rspi_read8(rspi, RSPI_SPCR); 704 - if (rx_buf) 705 - spcr &= ~SPCR_TXMD; 706 - else 707 - spcr |= SPCR_TXMD; 708 - rspi_write8(rspi, spcr, RSPI_SPCR); 709 - 710 - while (remain > 0) { 711 - data = tx_buf ? *tx_buf++ : DUMMY_DATA; 712 - ret = rspi_data_out(rspi, data); 713 - if (ret < 0) 714 - return ret; 715 - if (rx_buf) { 716 - ret = rspi_data_in(rspi); 717 - if (ret < 0) 718 - return ret; 719 - *rx_buf++ = ret; 720 - } 721 - remain--; 607 + if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) { 608 + /* rx_buf can be NULL on RSPI on SH in TX-only Mode */ 609 + return rspi_dma_transfer(rspi, &xfer->tx_sg, 610 + xfer->rx_buf ? &xfer->rx_sg : NULL); 722 611 } 723 612 613 + ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len); 614 + if (ret < 0) 615 + return ret; 616 + 724 617 /* Wait for the last transmission */ 725 - rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); 618 + rspi_wait_for_tx_empty(rspi); 726 619 727 620 return 0; 728 621 } ··· 611 744 struct spi_transfer *xfer) 612 745 { 613 746 struct rspi_data *rspi = spi_master_get_devdata(master); 614 - int ret; 747 + u8 spcr; 615 748 616 - if (!rspi_is_dma(rspi, xfer)) 617 - return rspi_transfer_out_in(rspi, xfer); 618 - 619 - if (xfer->tx_buf) { 620 - ret = rspi_send_dma(rspi, xfer); 621 - if (ret < 0) 622 - return ret; 749 + spcr = rspi_read8(rspi, RSPI_SPCR); 750 + if (xfer->rx_buf) { 751 + rspi_receive_init(rspi); 752 + spcr &= ~SPCR_TXMD; 753 + } else { 754 + spcr |= SPCR_TXMD; 623 755 } 624 - if (xfer->rx_buf) 625 - return rspi_receive_dma(rspi, xfer); 756 + rspi_write8(rspi, spcr, RSPI_SPCR); 626 757 627 - return 0; 628 - } 629 - 630 - static int rspi_rz_transfer_out_in(struct rspi_data *rspi, 631 - struct spi_transfer *xfer) 632 - { 633 - int remain = xfer->len, ret; 634 - const u8 *tx_buf = xfer->tx_buf; 635 - u8 *rx_buf = xfer->rx_buf; 636 - u8 data; 637 - 638 - rspi_rz_receive_init(rspi); 639 - 640 - while (remain > 0) { 641 - data = tx_buf ? *tx_buf++ : DUMMY_DATA; 642 - ret = rspi_data_out_in(rspi, data); 643 - if (ret < 0) 644 - return ret; 645 - if (rx_buf) 646 - *rx_buf++ = ret; 647 - remain--; 648 - } 649 - 650 - /* Wait for the last transmission */ 651 - rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); 652 - 653 - return 0; 758 + return rspi_common_transfer(rspi, xfer); 654 759 } 655 760 656 761 static int rspi_rz_transfer_one(struct spi_master *master, ··· 630 791 struct spi_transfer *xfer) 631 792 { 632 793 struct rspi_data *rspi = spi_master_get_devdata(master); 794 + int ret; 633 795 634 - return rspi_rz_transfer_out_in(rspi, xfer); 796 + rspi_rz_receive_init(rspi); 797 + 798 + return rspi_common_transfer(rspi, xfer); 635 799 } 636 800 637 801 static int qspi_transfer_out_in(struct rspi_data *rspi, 638 802 struct spi_transfer *xfer) 639 803 { 640 - int remain = xfer->len, ret; 641 - const u8 *tx_buf = xfer->tx_buf; 642 - u8 *rx_buf = xfer->rx_buf; 643 - u8 data; 644 - 645 804 qspi_receive_init(rspi); 646 805 647 - while (remain > 0) { 648 - data = tx_buf ? *tx_buf++ : DUMMY_DATA; 649 - ret = rspi_data_out_in(rspi, data); 650 - if (ret < 0) 651 - return ret; 652 - if (rx_buf) 653 - *rx_buf++ = ret; 654 - remain--; 655 - } 656 - 657 - /* Wait for the last transmission */ 658 - rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); 659 - 660 - return 0; 806 + return rspi_common_transfer(rspi, xfer); 661 807 } 662 808 663 809 static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) 664 810 { 665 - const u8 *buf = xfer->tx_buf; 666 - unsigned int i; 667 811 int ret; 668 812 669 - for (i = 0; i < xfer->len; i++) { 670 - ret = rspi_data_out(rspi, *buf++); 671 - if (ret < 0) 672 - return ret; 673 - } 813 + if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) 814 + return rspi_dma_transfer(rspi, &xfer->tx_sg, NULL); 815 + 816 + ret = rspi_pio_transfer(rspi, xfer->tx_buf, NULL, xfer->len); 817 + if (ret < 0) 818 + return ret; 674 819 675 820 /* Wait for the last transmission */ 676 - rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); 821 + rspi_wait_for_tx_empty(rspi); 677 822 678 823 return 0; 679 824 } 680 825 681 826 static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer) 682 827 { 683 - u8 *buf = xfer->rx_buf; 684 - unsigned int i; 685 - int ret; 828 + if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) 829 + return rspi_dma_transfer(rspi, NULL, &xfer->rx_sg); 686 830 687 - for (i = 0; i < xfer->len; i++) { 688 - ret = rspi_data_in(rspi); 689 - if (ret < 0) 690 - return ret; 691 - *buf++ = ret; 692 - } 693 - 694 - return 0; 831 + return rspi_pio_transfer(rspi, NULL, xfer->rx_buf, xfer->len); 695 832 } 696 833 697 834 static int qspi_transfer_one(struct spi_master *master, struct spi_device *spi, ··· 677 862 678 863 if (spi->mode & SPI_LOOP) { 679 864 return qspi_transfer_out_in(rspi, xfer); 680 - } else if (xfer->tx_buf && xfer->tx_nbits > SPI_NBITS_SINGLE) { 865 + } else if (xfer->tx_nbits > SPI_NBITS_SINGLE) { 681 866 /* Quad or Dual SPI Write */ 682 867 return qspi_transfer_out(rspi, xfer); 683 - } else if (xfer->rx_buf && xfer->rx_nbits > SPI_NBITS_SINGLE) { 868 + } else if (xfer->rx_nbits > SPI_NBITS_SINGLE) { 684 869 /* Quad or Dual SPI Read */ 685 870 return qspi_transfer_in(rspi, xfer); 686 871 } else { ··· 861 1046 return 0; 862 1047 } 863 1048 864 - static int rspi_request_dma(struct rspi_data *rspi, 865 - struct platform_device *pdev) 1049 + static struct dma_chan *rspi_request_dma_chan(struct device *dev, 1050 + enum dma_transfer_direction dir, 1051 + unsigned int id, 1052 + dma_addr_t port_addr) 866 1053 { 867 - const struct rspi_plat_data *rspi_pd = dev_get_platdata(&pdev->dev); 868 - struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 869 1054 dma_cap_mask_t mask; 1055 + struct dma_chan *chan; 870 1056 struct dma_slave_config cfg; 871 1057 int ret; 872 1058 873 - if (!res || !rspi_pd) 1059 + dma_cap_zero(mask); 1060 + dma_cap_set(DMA_SLAVE, mask); 1061 + 1062 + chan = dma_request_channel(mask, shdma_chan_filter, 1063 + (void *)(unsigned long)id); 1064 + if (!chan) { 1065 + dev_warn(dev, "dma_request_channel failed\n"); 1066 + return NULL; 1067 + } 1068 + 1069 + memset(&cfg, 0, sizeof(cfg)); 1070 + cfg.slave_id = id; 1071 + cfg.direction = dir; 1072 + if (dir == DMA_MEM_TO_DEV) 1073 + cfg.dst_addr = port_addr; 1074 + else 1075 + cfg.src_addr = port_addr; 1076 + 1077 + ret = dmaengine_slave_config(chan, &cfg); 1078 + if (ret) { 1079 + dev_warn(dev, "dmaengine_slave_config failed %d\n", ret); 1080 + dma_release_channel(chan); 1081 + return NULL; 1082 + } 1083 + 1084 + return chan; 1085 + } 1086 + 1087 + static int rspi_request_dma(struct device *dev, struct spi_master *master, 1088 + const struct resource *res) 1089 + { 1090 + const struct rspi_plat_data *rspi_pd = dev_get_platdata(dev); 1091 + 1092 + if (!rspi_pd || !rspi_pd->dma_rx_id || !rspi_pd->dma_tx_id) 874 1093 return 0; /* The driver assumes no error. */ 875 1094 876 - rspi->dma_width_16bit = rspi_pd->dma_width_16bit; 1095 + master->dma_rx = rspi_request_dma_chan(dev, DMA_DEV_TO_MEM, 1096 + rspi_pd->dma_rx_id, 1097 + res->start + RSPI_SPDR); 1098 + if (!master->dma_rx) 1099 + return -ENODEV; 877 1100 878 - /* If the module receives data by DMAC, it also needs TX DMAC */ 879 - if (rspi_pd->dma_rx_id && rspi_pd->dma_tx_id) { 880 - dma_cap_zero(mask); 881 - dma_cap_set(DMA_SLAVE, mask); 882 - rspi->chan_rx = dma_request_channel(mask, shdma_chan_filter, 883 - (void *)rspi_pd->dma_rx_id); 884 - if (rspi->chan_rx) { 885 - cfg.slave_id = rspi_pd->dma_rx_id; 886 - cfg.direction = DMA_DEV_TO_MEM; 887 - cfg.dst_addr = 0; 888 - cfg.src_addr = res->start + RSPI_SPDR; 889 - ret = dmaengine_slave_config(rspi->chan_rx, &cfg); 890 - if (!ret) 891 - dev_info(&pdev->dev, "Use DMA when rx.\n"); 892 - else 893 - return ret; 894 - } 895 - } 896 - if (rspi_pd->dma_tx_id) { 897 - dma_cap_zero(mask); 898 - dma_cap_set(DMA_SLAVE, mask); 899 - rspi->chan_tx = dma_request_channel(mask, shdma_chan_filter, 900 - (void *)rspi_pd->dma_tx_id); 901 - if (rspi->chan_tx) { 902 - cfg.slave_id = rspi_pd->dma_tx_id; 903 - cfg.direction = DMA_MEM_TO_DEV; 904 - cfg.dst_addr = res->start + RSPI_SPDR; 905 - cfg.src_addr = 0; 906 - ret = dmaengine_slave_config(rspi->chan_tx, &cfg); 907 - if (!ret) 908 - dev_info(&pdev->dev, "Use DMA when tx\n"); 909 - else 910 - return ret; 911 - } 1101 + master->dma_tx = rspi_request_dma_chan(dev, DMA_MEM_TO_DEV, 1102 + rspi_pd->dma_tx_id, 1103 + res->start + RSPI_SPDR); 1104 + if (!master->dma_tx) { 1105 + dma_release_channel(master->dma_rx); 1106 + master->dma_rx = NULL; 1107 + return -ENODEV; 912 1108 } 913 1109 1110 + master->can_dma = rspi_can_dma; 1111 + dev_info(dev, "DMA available"); 914 1112 return 0; 915 1113 } 916 1114 917 1115 static void rspi_release_dma(struct rspi_data *rspi) 918 1116 { 919 - if (rspi->chan_tx) 920 - dma_release_channel(rspi->chan_tx); 921 - if (rspi->chan_rx) 922 - dma_release_channel(rspi->chan_rx); 1117 + if (rspi->master->dma_tx) 1118 + dma_release_channel(rspi->master->dma_tx); 1119 + if (rspi->master->dma_rx) 1120 + dma_release_channel(rspi->master->dma_rx); 923 1121 } 924 1122 925 1123 static int rspi_remove(struct platform_device *pdev) ··· 946 1118 } 947 1119 948 1120 static const struct spi_ops rspi_ops = { 949 - .set_config_register = rspi_set_config_register, 950 - .transfer_one = rspi_transfer_one, 951 - .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP, 1121 + .set_config_register = rspi_set_config_register, 1122 + .transfer_one = rspi_transfer_one, 1123 + .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP, 1124 + .flags = SPI_MASTER_MUST_TX, 1125 + .fifo_size = 8, 952 1126 }; 953 1127 954 1128 static const struct spi_ops rspi_rz_ops = { 955 - .set_config_register = rspi_rz_set_config_register, 956 - .transfer_one = rspi_rz_transfer_one, 957 - .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP, 1129 + .set_config_register = rspi_rz_set_config_register, 1130 + .transfer_one = rspi_rz_transfer_one, 1131 + .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP, 1132 + .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX, 1133 + .fifo_size = 8, /* 8 for TX, 32 for RX */ 958 1134 }; 959 1135 960 1136 static const struct spi_ops qspi_ops = { 961 - .set_config_register = qspi_set_config_register, 962 - .transfer_one = qspi_transfer_one, 963 - .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP | 964 - SPI_TX_DUAL | SPI_TX_QUAD | 965 - SPI_RX_DUAL | SPI_RX_QUAD, 1137 + .set_config_register = qspi_set_config_register, 1138 + .transfer_one = qspi_transfer_one, 1139 + .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP | 1140 + SPI_TX_DUAL | SPI_TX_QUAD | 1141 + SPI_RX_DUAL | SPI_RX_QUAD, 1142 + .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX, 1143 + .fifo_size = 32, 966 1144 }; 967 1145 968 1146 #ifdef CONFIG_OF ··· 1088 1254 master->prepare_message = rspi_prepare_message; 1089 1255 master->unprepare_message = rspi_unprepare_message; 1090 1256 master->mode_bits = ops->mode_bits; 1257 + master->flags = ops->flags; 1091 1258 master->dev.of_node = pdev->dev.of_node; 1092 1259 1093 1260 ret = platform_get_irq_byname(pdev, "rx"); ··· 1126 1291 goto error2; 1127 1292 } 1128 1293 1129 - ret = rspi_request_dma(rspi, pdev); 1130 - if (ret < 0) { 1131 - dev_err(&pdev->dev, "rspi_request_dma failed.\n"); 1132 - goto error3; 1133 - } 1294 + ret = rspi_request_dma(&pdev->dev, master, res); 1295 + if (ret < 0) 1296 + dev_warn(&pdev->dev, "DMA not available, using PIO\n"); 1134 1297 1135 1298 ret = devm_spi_register_master(&pdev->dev, master); 1136 1299 if (ret < 0) {
+4 -11
drivers/spi/spi-s3c24xx.c
··· 10 10 */ 11 11 12 12 #include <linux/spinlock.h> 13 - #include <linux/workqueue.h> 14 13 #include <linux/interrupt.h> 15 14 #include <linux/delay.h> 16 15 #include <linux/errno.h> ··· 182 183 183 184 /* allocate settings on the first call */ 184 185 if (!cs) { 185 - cs = kzalloc(sizeof(struct s3c24xx_spi_devstate), GFP_KERNEL); 186 - if (!cs) { 187 - dev_err(&spi->dev, "no memory for controller state\n"); 186 + cs = devm_kzalloc(&spi->dev, 187 + sizeof(struct s3c24xx_spi_devstate), 188 + GFP_KERNEL); 189 + if (!cs) 188 190 return -ENOMEM; 189 - } 190 191 191 192 cs->spcon = SPCON_DEFAULT; 192 193 cs->hz = -1; ··· 206 207 spin_unlock(&hw->bitbang.lock); 207 208 208 209 return 0; 209 - } 210 - 211 - static void s3c24xx_spi_cleanup(struct spi_device *spi) 212 - { 213 - kfree(spi->controller_state); 214 210 } 215 211 216 212 static inline unsigned int hw_txbyte(struct s3c24xx_spi *hw, int count) ··· 537 543 hw->bitbang.txrx_bufs = s3c24xx_spi_txrx; 538 544 539 545 hw->master->setup = s3c24xx_spi_setup; 540 - hw->master->cleanup = s3c24xx_spi_cleanup; 541 546 542 547 dev_dbg(hw->dev, "bitbang at %p\n", &hw->bitbang); 543 548
+1 -5
drivers/spi/spi-s3c64xx.c
··· 19 19 20 20 #include <linux/init.h> 21 21 #include <linux/module.h> 22 - #include <linux/workqueue.h> 23 22 #include <linux/interrupt.h> 24 23 #include <linux/delay.h> 25 24 #include <linux/clk.h> ··· 772 773 773 774 cs = kzalloc(sizeof(*cs), GFP_KERNEL); 774 775 if (!cs) { 775 - dev_err(&spi->dev, "could not allocate memory for controller data\n"); 776 776 of_node_put(data_np); 777 777 return ERR_PTR(-ENOMEM); 778 778 } ··· 985 987 u32 temp; 986 988 987 989 sci = devm_kzalloc(dev, sizeof(*sci), GFP_KERNEL); 988 - if (!sci) { 989 - dev_err(dev, "memory allocation for spi_info failed\n"); 990 + if (!sci) 990 991 return ERR_PTR(-ENOMEM); 991 - } 992 992 993 993 if (of_property_read_u32(dev->of_node, "samsung,spi-src-clk", &temp)) { 994 994 dev_warn(dev, "spi bus clock parent not specified, using clock at index 0 as parent\n");
+1 -3
drivers/spi/spi-sh-msiof.c
··· 642 642 u32 num_cs = 1; 643 643 644 644 info = devm_kzalloc(dev, sizeof(struct sh_msiof_spi_info), GFP_KERNEL); 645 - if (!info) { 646 - dev_err(dev, "failed to allocate setup data\n"); 645 + if (!info) 647 646 return NULL; 648 - } 649 647 650 648 /* Parse the MSIOF properties */ 651 649 of_property_read_u32(np, "num-cs", &num_cs);
-1
drivers/spi/spi-sh-sci.c
··· 16 16 #include <linux/kernel.h> 17 17 #include <linux/delay.h> 18 18 #include <linux/spinlock.h> 19 - #include <linux/workqueue.h> 20 19 #include <linux/platform_device.h> 21 20 22 21 #include <linux/spi/spi.h>
+170 -133
drivers/spi/spi-sirf.c
··· 10 10 #include <linux/kernel.h> 11 11 #include <linux/slab.h> 12 12 #include <linux/clk.h> 13 + #include <linux/completion.h> 13 14 #include <linux/interrupt.h> 14 15 #include <linux/io.h> 15 16 #include <linux/of.h> ··· 86 85 #define SIRFSOC_SPI_TX_DONE BIT(1) 87 86 #define SIRFSOC_SPI_RX_OFLOW BIT(2) 88 87 #define SIRFSOC_SPI_TX_UFLOW BIT(3) 88 + #define SIRFSOC_SPI_RX_IO_DMA BIT(4) 89 89 #define SIRFSOC_SPI_RX_FIFO_FULL BIT(6) 90 90 #define SIRFSOC_SPI_TXFIFO_EMPTY BIT(7) 91 91 #define SIRFSOC_SPI_RXFIFO_THD_REACH BIT(8) ··· 266 264 { 267 265 struct sirfsoc_spi *sspi = dev_id; 268 266 u32 spi_stat = readl(sspi->base + SIRFSOC_SPI_INT_STATUS); 269 - 270 - writel(spi_stat, sspi->base + SIRFSOC_SPI_INT_STATUS); 271 - 272 267 if (sspi->tx_by_cmd && (spi_stat & SIRFSOC_SPI_FRM_END)) { 273 268 complete(&sspi->tx_done); 274 269 writel(0x0, sspi->base + SIRFSOC_SPI_INT_EN); 270 + writel(SIRFSOC_SPI_INT_MASK_ALL, 271 + sspi->base + SIRFSOC_SPI_INT_STATUS); 275 272 return IRQ_HANDLED; 276 273 } 277 274 278 275 /* Error Conditions */ 279 276 if (spi_stat & SIRFSOC_SPI_RX_OFLOW || 280 277 spi_stat & SIRFSOC_SPI_TX_UFLOW) { 278 + complete(&sspi->tx_done); 281 279 complete(&sspi->rx_done); 282 280 writel(0x0, sspi->base + SIRFSOC_SPI_INT_EN); 281 + writel(SIRFSOC_SPI_INT_MASK_ALL, 282 + sspi->base + SIRFSOC_SPI_INT_STATUS); 283 + return IRQ_HANDLED; 283 284 } 285 + if (spi_stat & SIRFSOC_SPI_TXFIFO_EMPTY) 286 + complete(&sspi->tx_done); 287 + while (!(readl(sspi->base + SIRFSOC_SPI_INT_STATUS) & 288 + SIRFSOC_SPI_RX_IO_DMA)) 289 + cpu_relax(); 290 + complete(&sspi->rx_done); 291 + writel(0x0, sspi->base + SIRFSOC_SPI_INT_EN); 292 + writel(SIRFSOC_SPI_INT_MASK_ALL, 293 + sspi->base + SIRFSOC_SPI_INT_STATUS); 284 294 285 - if (spi_stat & (SIRFSOC_SPI_FRM_END 286 - | SIRFSOC_SPI_RXFIFO_THD_REACH)) 287 - while (!((readl(sspi->base + SIRFSOC_SPI_RXFIFO_STATUS) 288 - & SIRFSOC_SPI_FIFO_EMPTY)) && 289 - sspi->left_rx_word) 290 - sspi->rx_word(sspi); 291 - 292 - if (spi_stat & (SIRFSOC_SPI_TXFIFO_EMPTY | 293 - SIRFSOC_SPI_TXFIFO_THD_REACH)) 294 - while (!((readl(sspi->base + SIRFSOC_SPI_TXFIFO_STATUS) 295 - & SIRFSOC_SPI_FIFO_FULL)) && 296 - sspi->left_tx_word) 297 - sspi->tx_word(sspi); 298 - 299 - /* Received all words */ 300 - if ((sspi->left_rx_word == 0) && (sspi->left_tx_word == 0)) { 301 - complete(&sspi->rx_done); 302 - writel(0x0, sspi->base + SIRFSOC_SPI_INT_EN); 303 - } 304 295 return IRQ_HANDLED; 305 296 } 306 297 ··· 304 309 complete(dma_complete); 305 310 } 306 311 307 - static int spi_sirfsoc_transfer(struct spi_device *spi, struct spi_transfer *t) 312 + static int spi_sirfsoc_cmd_transfer(struct spi_device *spi, 313 + struct spi_transfer *t) 308 314 { 309 315 struct sirfsoc_spi *sspi; 310 316 int timeout = t->len * 10; 317 + u32 cmd; 318 + 311 319 sspi = spi_master_get_devdata(spi->master); 312 - 313 - sspi->tx = t->tx_buf ? t->tx_buf : sspi->dummypage; 314 - sspi->rx = t->rx_buf ? t->rx_buf : sspi->dummypage; 315 - sspi->left_tx_word = sspi->left_rx_word = t->len / sspi->word_width; 316 - reinit_completion(&sspi->rx_done); 317 - reinit_completion(&sspi->tx_done); 318 - 319 - writel(SIRFSOC_SPI_INT_MASK_ALL, sspi->base + SIRFSOC_SPI_INT_STATUS); 320 - 321 - /* 322 - * fill tx_buf into command register and wait for its completion 323 - */ 324 - if (sspi->tx_by_cmd) { 325 - u32 cmd; 326 - memcpy(&cmd, sspi->tx, t->len); 327 - 328 - if (sspi->word_width == 1 && !(spi->mode & SPI_LSB_FIRST)) 329 - cmd = cpu_to_be32(cmd) >> 330 - ((SIRFSOC_MAX_CMD_BYTES - t->len) * 8); 331 - if (sspi->word_width == 2 && t->len == 4 && 332 - (!(spi->mode & SPI_LSB_FIRST))) 333 - cmd = ((cmd & 0xffff) << 16) | (cmd >> 16); 334 - 335 - writel(cmd, sspi->base + SIRFSOC_SPI_CMD); 336 - writel(SIRFSOC_SPI_FRM_END_INT_EN, 337 - sspi->base + SIRFSOC_SPI_INT_EN); 338 - writel(SIRFSOC_SPI_CMD_TX_EN, 339 - sspi->base + SIRFSOC_SPI_TX_RX_EN); 340 - 341 - if (wait_for_completion_timeout(&sspi->tx_done, timeout) == 0) { 342 - dev_err(&spi->dev, "transfer timeout\n"); 343 - return 0; 344 - } 345 - 346 - return t->len; 320 + memcpy(&cmd, sspi->tx, t->len); 321 + if (sspi->word_width == 1 && !(spi->mode & SPI_LSB_FIRST)) 322 + cmd = cpu_to_be32(cmd) >> 323 + ((SIRFSOC_MAX_CMD_BYTES - t->len) * 8); 324 + if (sspi->word_width == 2 && t->len == 4 && 325 + (!(spi->mode & SPI_LSB_FIRST))) 326 + cmd = ((cmd & 0xffff) << 16) | (cmd >> 16); 327 + writel(cmd, sspi->base + SIRFSOC_SPI_CMD); 328 + writel(SIRFSOC_SPI_FRM_END_INT_EN, 329 + sspi->base + SIRFSOC_SPI_INT_EN); 330 + writel(SIRFSOC_SPI_CMD_TX_EN, 331 + sspi->base + SIRFSOC_SPI_TX_RX_EN); 332 + if (wait_for_completion_timeout(&sspi->tx_done, timeout) == 0) { 333 + dev_err(&spi->dev, "cmd transfer timeout\n"); 334 + return 0; 347 335 } 348 336 349 - if (sspi->left_tx_word == 1) { 337 + return t->len; 338 + } 339 + 340 + static void spi_sirfsoc_dma_transfer(struct spi_device *spi, 341 + struct spi_transfer *t) 342 + { 343 + struct sirfsoc_spi *sspi; 344 + struct dma_async_tx_descriptor *rx_desc, *tx_desc; 345 + int timeout = t->len * 10; 346 + 347 + sspi = spi_master_get_devdata(spi->master); 348 + writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + SIRFSOC_SPI_RXFIFO_OP); 349 + writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + SIRFSOC_SPI_TXFIFO_OP); 350 + writel(SIRFSOC_SPI_FIFO_START, sspi->base + SIRFSOC_SPI_RXFIFO_OP); 351 + writel(SIRFSOC_SPI_FIFO_START, sspi->base + SIRFSOC_SPI_TXFIFO_OP); 352 + writel(0, sspi->base + SIRFSOC_SPI_INT_EN); 353 + writel(SIRFSOC_SPI_INT_MASK_ALL, sspi->base + SIRFSOC_SPI_INT_STATUS); 354 + if (sspi->left_tx_word < SIRFSOC_SPI_DAT_FRM_LEN_MAX) { 350 355 writel(readl(sspi->base + SIRFSOC_SPI_CTRL) | 351 - SIRFSOC_SPI_ENA_AUTO_CLR, 352 - sspi->base + SIRFSOC_SPI_CTRL); 353 - writel(0, sspi->base + SIRFSOC_SPI_TX_DMA_IO_LEN); 354 - writel(0, sspi->base + SIRFSOC_SPI_RX_DMA_IO_LEN); 355 - } else if ((sspi->left_tx_word > 1) && (sspi->left_tx_word < 356 - SIRFSOC_SPI_DAT_FRM_LEN_MAX)) { 357 - writel(readl(sspi->base + SIRFSOC_SPI_CTRL) | 358 - SIRFSOC_SPI_MUL_DAT_MODE | 359 - SIRFSOC_SPI_ENA_AUTO_CLR, 356 + SIRFSOC_SPI_ENA_AUTO_CLR | SIRFSOC_SPI_MUL_DAT_MODE, 360 357 sspi->base + SIRFSOC_SPI_CTRL); 361 358 writel(sspi->left_tx_word - 1, 362 359 sspi->base + SIRFSOC_SPI_TX_DMA_IO_LEN); ··· 360 373 writel(0, sspi->base + SIRFSOC_SPI_TX_DMA_IO_LEN); 361 374 writel(0, sspi->base + SIRFSOC_SPI_RX_DMA_IO_LEN); 362 375 } 376 + sspi->dst_start = dma_map_single(&spi->dev, sspi->rx, t->len, 377 + (t->tx_buf != t->rx_buf) ? 378 + DMA_FROM_DEVICE : DMA_BIDIRECTIONAL); 379 + rx_desc = dmaengine_prep_slave_single(sspi->rx_chan, 380 + sspi->dst_start, t->len, DMA_DEV_TO_MEM, 381 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 382 + rx_desc->callback = spi_sirfsoc_dma_fini_callback; 383 + rx_desc->callback_param = &sspi->rx_done; 363 384 364 - writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + SIRFSOC_SPI_RXFIFO_OP); 365 - writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + SIRFSOC_SPI_TXFIFO_OP); 366 - writel(SIRFSOC_SPI_FIFO_START, sspi->base + SIRFSOC_SPI_RXFIFO_OP); 367 - writel(SIRFSOC_SPI_FIFO_START, sspi->base + SIRFSOC_SPI_TXFIFO_OP); 385 + sspi->src_start = dma_map_single(&spi->dev, (void *)sspi->tx, t->len, 386 + (t->tx_buf != t->rx_buf) ? 387 + DMA_TO_DEVICE : DMA_BIDIRECTIONAL); 388 + tx_desc = dmaengine_prep_slave_single(sspi->tx_chan, 389 + sspi->src_start, t->len, DMA_MEM_TO_DEV, 390 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 391 + tx_desc->callback = spi_sirfsoc_dma_fini_callback; 392 + tx_desc->callback_param = &sspi->tx_done; 368 393 369 - if (IS_DMA_VALID(t)) { 370 - struct dma_async_tx_descriptor *rx_desc, *tx_desc; 371 - 372 - sspi->dst_start = dma_map_single(&spi->dev, sspi->rx, t->len, DMA_FROM_DEVICE); 373 - rx_desc = dmaengine_prep_slave_single(sspi->rx_chan, 374 - sspi->dst_start, t->len, DMA_DEV_TO_MEM, 375 - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 376 - rx_desc->callback = spi_sirfsoc_dma_fini_callback; 377 - rx_desc->callback_param = &sspi->rx_done; 378 - 379 - sspi->src_start = dma_map_single(&spi->dev, (void *)sspi->tx, t->len, DMA_TO_DEVICE); 380 - tx_desc = dmaengine_prep_slave_single(sspi->tx_chan, 381 - sspi->src_start, t->len, DMA_MEM_TO_DEV, 382 - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 383 - tx_desc->callback = spi_sirfsoc_dma_fini_callback; 384 - tx_desc->callback_param = &sspi->tx_done; 385 - 386 - dmaengine_submit(tx_desc); 387 - dmaengine_submit(rx_desc); 388 - dma_async_issue_pending(sspi->tx_chan); 389 - dma_async_issue_pending(sspi->rx_chan); 390 - } else { 391 - /* Send the first word to trigger the whole tx/rx process */ 392 - sspi->tx_word(sspi); 393 - 394 - writel(SIRFSOC_SPI_RX_OFLOW_INT_EN | SIRFSOC_SPI_TX_UFLOW_INT_EN | 395 - SIRFSOC_SPI_RXFIFO_THD_INT_EN | SIRFSOC_SPI_TXFIFO_THD_INT_EN | 396 - SIRFSOC_SPI_FRM_END_INT_EN | SIRFSOC_SPI_RXFIFO_FULL_INT_EN | 397 - SIRFSOC_SPI_TXFIFO_EMPTY_INT_EN, sspi->base + SIRFSOC_SPI_INT_EN); 398 - } 399 - 400 - writel(SIRFSOC_SPI_RX_EN | SIRFSOC_SPI_TX_EN, sspi->base + SIRFSOC_SPI_TX_RX_EN); 401 - 402 - if (!IS_DMA_VALID(t)) { /* for PIO */ 403 - if (wait_for_completion_timeout(&sspi->rx_done, timeout) == 0) 404 - dev_err(&spi->dev, "transfer timeout\n"); 405 - } else if (wait_for_completion_timeout(&sspi->rx_done, timeout) == 0) { 394 + dmaengine_submit(tx_desc); 395 + dmaengine_submit(rx_desc); 396 + dma_async_issue_pending(sspi->tx_chan); 397 + dma_async_issue_pending(sspi->rx_chan); 398 + writel(SIRFSOC_SPI_RX_EN | SIRFSOC_SPI_TX_EN, 399 + sspi->base + SIRFSOC_SPI_TX_RX_EN); 400 + if (wait_for_completion_timeout(&sspi->rx_done, timeout) == 0) { 406 401 dev_err(&spi->dev, "transfer timeout\n"); 407 402 dmaengine_terminate_all(sspi->rx_chan); 408 403 } else 409 404 sspi->left_rx_word = 0; 410 - 411 405 /* 412 406 * we only wait tx-done event if transferring by DMA. for PIO, 413 407 * we get rx data by writing tx data, so if rx is done, tx has 414 408 * done earlier 415 409 */ 416 - if (IS_DMA_VALID(t)) { 417 - if (wait_for_completion_timeout(&sspi->tx_done, timeout) == 0) { 418 - dev_err(&spi->dev, "transfer timeout\n"); 419 - dmaengine_terminate_all(sspi->tx_chan); 420 - } 410 + if (wait_for_completion_timeout(&sspi->tx_done, timeout) == 0) { 411 + dev_err(&spi->dev, "transfer timeout\n"); 412 + dmaengine_terminate_all(sspi->tx_chan); 421 413 } 422 - 423 - if (IS_DMA_VALID(t)) { 424 - dma_unmap_single(&spi->dev, sspi->src_start, t->len, DMA_TO_DEVICE); 425 - dma_unmap_single(&spi->dev, sspi->dst_start, t->len, DMA_FROM_DEVICE); 426 - } 427 - 414 + dma_unmap_single(&spi->dev, sspi->src_start, t->len, DMA_TO_DEVICE); 415 + dma_unmap_single(&spi->dev, sspi->dst_start, t->len, DMA_FROM_DEVICE); 428 416 /* TX, RX FIFO stop */ 429 417 writel(0, sspi->base + SIRFSOC_SPI_RXFIFO_OP); 430 418 writel(0, sspi->base + SIRFSOC_SPI_TXFIFO_OP); 431 - writel(0, sspi->base + SIRFSOC_SPI_TX_RX_EN); 432 - writel(0, sspi->base + SIRFSOC_SPI_INT_EN); 419 + if (sspi->left_tx_word >= SIRFSOC_SPI_DAT_FRM_LEN_MAX) 420 + writel(0, sspi->base + SIRFSOC_SPI_TX_RX_EN); 421 + } 422 + 423 + static void spi_sirfsoc_pio_transfer(struct spi_device *spi, 424 + struct spi_transfer *t) 425 + { 426 + struct sirfsoc_spi *sspi; 427 + int timeout = t->len * 10; 428 + 429 + sspi = spi_master_get_devdata(spi->master); 430 + do { 431 + writel(SIRFSOC_SPI_FIFO_RESET, 432 + sspi->base + SIRFSOC_SPI_RXFIFO_OP); 433 + writel(SIRFSOC_SPI_FIFO_RESET, 434 + sspi->base + SIRFSOC_SPI_TXFIFO_OP); 435 + writel(SIRFSOC_SPI_FIFO_START, 436 + sspi->base + SIRFSOC_SPI_RXFIFO_OP); 437 + writel(SIRFSOC_SPI_FIFO_START, 438 + sspi->base + SIRFSOC_SPI_TXFIFO_OP); 439 + writel(0, sspi->base + SIRFSOC_SPI_INT_EN); 440 + writel(SIRFSOC_SPI_INT_MASK_ALL, 441 + sspi->base + SIRFSOC_SPI_INT_STATUS); 442 + writel(readl(sspi->base + SIRFSOC_SPI_CTRL) | 443 + SIRFSOC_SPI_MUL_DAT_MODE | SIRFSOC_SPI_ENA_AUTO_CLR, 444 + sspi->base + SIRFSOC_SPI_CTRL); 445 + writel(min(sspi->left_tx_word, (u32)(256 / sspi->word_width)) 446 + - 1, sspi->base + SIRFSOC_SPI_TX_DMA_IO_LEN); 447 + writel(min(sspi->left_rx_word, (u32)(256 / sspi->word_width)) 448 + - 1, sspi->base + SIRFSOC_SPI_RX_DMA_IO_LEN); 449 + while (!((readl(sspi->base + SIRFSOC_SPI_TXFIFO_STATUS) 450 + & SIRFSOC_SPI_FIFO_FULL)) && sspi->left_tx_word) 451 + sspi->tx_word(sspi); 452 + writel(SIRFSOC_SPI_TXFIFO_EMPTY_INT_EN | 453 + SIRFSOC_SPI_TX_UFLOW_INT_EN | 454 + SIRFSOC_SPI_RX_OFLOW_INT_EN, 455 + sspi->base + SIRFSOC_SPI_INT_EN); 456 + writel(SIRFSOC_SPI_RX_EN | SIRFSOC_SPI_TX_EN, 457 + sspi->base + SIRFSOC_SPI_TX_RX_EN); 458 + if (!wait_for_completion_timeout(&sspi->tx_done, timeout) || 459 + !wait_for_completion_timeout(&sspi->rx_done, timeout)) { 460 + dev_err(&spi->dev, "transfer timeout\n"); 461 + break; 462 + } 463 + while (!((readl(sspi->base + SIRFSOC_SPI_RXFIFO_STATUS) 464 + & SIRFSOC_SPI_FIFO_EMPTY)) && sspi->left_rx_word) 465 + sspi->rx_word(sspi); 466 + writel(0, sspi->base + SIRFSOC_SPI_RXFIFO_OP); 467 + writel(0, sspi->base + SIRFSOC_SPI_TXFIFO_OP); 468 + } while (sspi->left_tx_word != 0 || sspi->left_rx_word != 0); 469 + } 470 + 471 + static int spi_sirfsoc_transfer(struct spi_device *spi, struct spi_transfer *t) 472 + { 473 + struct sirfsoc_spi *sspi; 474 + sspi = spi_master_get_devdata(spi->master); 475 + 476 + sspi->tx = t->tx_buf ? t->tx_buf : sspi->dummypage; 477 + sspi->rx = t->rx_buf ? t->rx_buf : sspi->dummypage; 478 + sspi->left_tx_word = sspi->left_rx_word = t->len / sspi->word_width; 479 + reinit_completion(&sspi->rx_done); 480 + reinit_completion(&sspi->tx_done); 481 + /* 482 + * in the transfer, if transfer data using command register with rx_buf 483 + * null, just fill command data into command register and wait for its 484 + * completion. 485 + */ 486 + if (sspi->tx_by_cmd) 487 + spi_sirfsoc_cmd_transfer(spi, t); 488 + else if (IS_DMA_VALID(t)) 489 + spi_sirfsoc_dma_transfer(spi, t); 490 + else 491 + spi_sirfsoc_pio_transfer(spi, t); 433 492 434 493 return t->len - sspi->left_rx_word * sspi->word_width; 435 494 } ··· 545 512 break; 546 513 case 12: 547 514 case 16: 548 - regval |= (bits_per_word == 12) ? SIRFSOC_SPI_TRAN_DAT_FORMAT_12 : 515 + regval |= (bits_per_word == 12) ? 516 + SIRFSOC_SPI_TRAN_DAT_FORMAT_12 : 549 517 SIRFSOC_SPI_TRAN_DAT_FORMAT_16; 550 518 sspi->rx_word = spi_sirfsoc_rx_word_u16; 551 519 sspi->tx_word = spi_sirfsoc_tx_word_u16; ··· 574 540 regval |= SIRFSOC_SPI_CLK_IDLE_STAT; 575 541 576 542 /* 577 - * Data should be driven at least 1/2 cycle before the fetch edge to make 578 - * sure that data gets stable at the fetch edge. 543 + * Data should be driven at least 1/2 cycle before the fetch edge 544 + * to make sure that data gets stable at the fetch edge. 579 545 */ 580 546 if (((spi->mode & SPI_CPOL) && (spi->mode & SPI_CPHA)) || 581 547 (!(spi->mode & SPI_CPOL) && !(spi->mode & SPI_CPHA))) ··· 612 578 if (IS_DMA_VALID(t)) { 613 579 /* Enable DMA mode for RX, TX */ 614 580 writel(0, sspi->base + SIRFSOC_SPI_TX_DMA_IO_CTRL); 615 - writel(SIRFSOC_SPI_RX_DMA_FLUSH, sspi->base + SIRFSOC_SPI_RX_DMA_IO_CTRL); 581 + writel(SIRFSOC_SPI_RX_DMA_FLUSH, 582 + sspi->base + SIRFSOC_SPI_RX_DMA_IO_CTRL); 616 583 } else { 617 584 /* Enable IO mode for RX, TX */ 618 - writel(SIRFSOC_SPI_IO_MODE_SEL, sspi->base + SIRFSOC_SPI_TX_DMA_IO_CTRL); 619 - writel(SIRFSOC_SPI_IO_MODE_SEL, sspi->base + SIRFSOC_SPI_RX_DMA_IO_CTRL); 585 + writel(SIRFSOC_SPI_IO_MODE_SEL, 586 + sspi->base + SIRFSOC_SPI_TX_DMA_IO_CTRL); 587 + writel(SIRFSOC_SPI_IO_MODE_SEL, 588 + sspi->base + SIRFSOC_SPI_RX_DMA_IO_CTRL); 620 589 } 621 590 622 591 return 0; ··· 649 612 goto err_cs; 650 613 } 651 614 652 - master = spi_alloc_master(&pdev->dev, sizeof(*sspi) + sizeof(int) * num_cs); 615 + master = spi_alloc_master(&pdev->dev, 616 + sizeof(*sspi) + sizeof(int) * num_cs); 653 617 if (!master) { 654 618 dev_err(&pdev->dev, "Unable to allocate SPI master\n"); 655 619 return -ENOMEM; ··· 846 808 .remove = spi_sirfsoc_remove, 847 809 }; 848 810 module_platform_driver(spi_sirfsoc_driver); 849 - 850 811 MODULE_DESCRIPTION("SiRF SoC SPI master driver"); 851 - MODULE_AUTHOR("Zhiwu Song <Zhiwu.Song@csr.com>, " 852 - "Barry Song <Baohua.Song@csr.com>"); 812 + MODULE_AUTHOR("Zhiwu Song <Zhiwu.Song@csr.com>"); 813 + MODULE_AUTHOR("Barry Song <Baohua.Song@csr.com>"); 853 814 MODULE_LICENSE("GPL v2");
-1
drivers/spi/spi-sun4i.c
··· 19 19 #include <linux/module.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/pm_runtime.h> 22 - #include <linux/workqueue.h> 23 22 24 23 #include <linux/spi/spi.h> 25 24
-1
drivers/spi/spi-sun6i.c
··· 20 20 #include <linux/platform_device.h> 21 21 #include <linux/pm_runtime.h> 22 22 #include <linux/reset.h> 23 - #include <linux/workqueue.h> 24 23 25 24 #include <linux/spi/spi.h> 26 25
+1 -1
drivers/spi/spi-tegra114.c
··· 1012 1012 return IRQ_WAKE_THREAD; 1013 1013 } 1014 1014 1015 - static struct of_device_id tegra_spi_of_match[] = { 1015 + static const struct of_device_id tegra_spi_of_match[] = { 1016 1016 { .compatible = "nvidia,tegra114-spi", }, 1017 1017 {} 1018 1018 };
+1 -1
drivers/spi/spi-tegra20-sflash.c
··· 419 419 return handle_cpu_based_xfer(tsd); 420 420 } 421 421 422 - static struct of_device_id tegra_sflash_of_match[] = { 422 + static const struct of_device_id tegra_sflash_of_match[] = { 423 423 { .compatible = "nvidia,tegra20-sflash", }, 424 424 {} 425 425 };
+1 -1
drivers/spi/spi-tegra20-slink.c
··· 1001 1001 .cs_hold_time = false, 1002 1002 }; 1003 1003 1004 - static struct of_device_id tegra_slink_of_match[] = { 1004 + static const struct of_device_id tegra_slink_of_match[] = { 1005 1005 { .compatible = "nvidia,tegra30-slink", .data = &tegra30_spi_cdata, }, 1006 1006 { .compatible = "nvidia,tegra20-slink", .data = &tegra20_spi_cdata, }, 1007 1007 {}
+1 -3
drivers/spi/spi-tle62x0.c
··· 253 253 } 254 254 255 255 st = kzalloc(sizeof(struct tle62x0_state), GFP_KERNEL); 256 - if (st == NULL) { 257 - dev_err(&spi->dev, "no memory for device state\n"); 256 + if (st == NULL) 258 257 return -ENOMEM; 259 - } 260 258 261 259 st->us = spi; 262 260 st->nr_gpio = pdata->gpio_count;
+1 -4
drivers/spi/spi-topcliff-pch.c
··· 1578 1578 struct pch_pd_dev_save *pd_dev_save; 1579 1579 1580 1580 pd_dev_save = kzalloc(sizeof(struct pch_pd_dev_save), GFP_KERNEL); 1581 - if (!pd_dev_save) { 1582 - dev_err(&pdev->dev, "%s Can't allocate pd_dev_sav\n", __func__); 1581 + if (!pd_dev_save) 1583 1582 return -ENOMEM; 1584 - } 1585 1583 1586 1584 board_dat = kzalloc(sizeof(struct pch_spi_board_data), GFP_KERNEL); 1587 1585 if (!board_dat) { 1588 - dev_err(&pdev->dev, "%s Can't allocate board_dat\n", __func__); 1589 1586 retval = -ENOMEM; 1590 1587 goto err_no_mem; 1591 1588 }
+11 -11
drivers/spi/spi.c
··· 796 796 if (ret > 0) { 797 797 ret = 0; 798 798 ms = xfer->len * 8 * 1000 / xfer->speed_hz; 799 - ms += 10; /* some tolerance */ 799 + ms += ms + 100; /* some tolerance */ 800 800 801 801 ms = wait_for_completion_timeout(&master->xfer_completion, 802 802 msecs_to_jiffies(ms)); ··· 1255 1255 spi->mode |= SPI_CS_HIGH; 1256 1256 if (of_find_property(nc, "spi-3wire", NULL)) 1257 1257 spi->mode |= SPI_3WIRE; 1258 + if (of_find_property(nc, "spi-lsb-first", NULL)) 1259 + spi->mode |= SPI_LSB_FIRST; 1258 1260 1259 1261 /* Device DUAL/QUAD mode */ 1260 1262 if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) { ··· 1270 1268 spi->mode |= SPI_TX_QUAD; 1271 1269 break; 1272 1270 default: 1273 - dev_err(&master->dev, 1274 - "spi-tx-bus-width %d not supported\n", 1275 - value); 1276 - spi_dev_put(spi); 1277 - continue; 1271 + dev_warn(&master->dev, 1272 + "spi-tx-bus-width %d not supported\n", 1273 + value); 1274 + break; 1278 1275 } 1279 1276 } 1280 1277 ··· 1288 1287 spi->mode |= SPI_RX_QUAD; 1289 1288 break; 1290 1289 default: 1291 - dev_err(&master->dev, 1292 - "spi-rx-bus-width %d not supported\n", 1293 - value); 1294 - spi_dev_put(spi); 1295 - continue; 1290 + dev_warn(&master->dev, 1291 + "spi-rx-bus-width %d not supported\n", 1292 + value); 1293 + break; 1296 1294 } 1297 1295 } 1298 1296
-2
include/linux/spi/rspi.h
··· 25 25 unsigned int dma_tx_id; 26 26 unsigned int dma_rx_id; 27 27 28 - unsigned dma_width_16bit:1; /* DMAC read/write width = 16-bit */ 29 - 30 28 u16 num_chipselect; 31 29 }; 32 30