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

Merge remote-tracking branches 'spi/topic/octeon', 'spi/topic/omap2-mcspi', 'spi/topic/orion', 'spi/topic/pic32' and 'spi/topic/pic32-sqi' into spi-next

+499 -366
+48 -1
Documentation/devicetree/bindings/spi/spi-orion.txt
··· 8 8 - "marvell,armada-380-spi", for the Armada 38x SoCs 9 9 - "marvell,armada-390-spi", for the Armada 39x SoCs 10 10 - "marvell,armada-xp-spi", for the Armada XP SoCs 11 - - reg : offset and length of the register set for the device 11 + - reg : offset and length of the register set for the device. 12 + This property can optionally have additional entries to configure 13 + the SPI direct access mode that some of the Marvell SoCs support 14 + additionally to the normal indirect access (PIO) mode. The values 15 + for the MBus "target" and "attribute" are defined in the Marvell 16 + SoC "Functional Specifications" Manual in the chapter "Marvell 17 + Core Processor Address Decoding". 18 + The eight register sets following the control registers refer to 19 + chip-select lines 0 through 7 respectively. 12 20 - cell-index : Which of multiple SPI controllers is this. 13 21 Optional properties: 14 22 - interrupts : Is currently not used. ··· 31 23 interrupts = <23>; 32 24 status = "disabled"; 33 25 }; 26 + 27 + Example with SPI direct mode support (optionally): 28 + spi0: spi@10600 { 29 + compatible = "marvell,orion-spi"; 30 + #address-cells = <1>; 31 + #size-cells = <0>; 32 + cell-index = <0>; 33 + reg = <MBUS_ID(0xf0, 0x01) 0x10600 0x28>, /* control */ 34 + <MBUS_ID(0x01, 0x1e) 0 0xffffffff>, /* CS0 */ 35 + <MBUS_ID(0x01, 0x5e) 0 0xffffffff>, /* CS1 */ 36 + <MBUS_ID(0x01, 0x9e) 0 0xffffffff>, /* CS2 */ 37 + <MBUS_ID(0x01, 0xde) 0 0xffffffff>, /* CS3 */ 38 + <MBUS_ID(0x01, 0x1f) 0 0xffffffff>, /* CS4 */ 39 + <MBUS_ID(0x01, 0x5f) 0 0xffffffff>, /* CS5 */ 40 + <MBUS_ID(0x01, 0x9f) 0 0xffffffff>, /* CS6 */ 41 + <MBUS_ID(0x01, 0xdf) 0 0xffffffff>; /* CS7 */ 42 + interrupts = <23>; 43 + status = "disabled"; 44 + }; 45 + 46 + To enable the direct mode, the board specific 'ranges' property in the 47 + 'soc' node needs to add the entries for the desired SPI controllers 48 + and its chip-selects that are used in the direct mode instead of PIO 49 + mode. Here an example for this (SPI controller 0, device 1 and SPI 50 + controller 1, device 2 are used in direct mode. All other SPI device 51 + are used in the default indirect (PIO) mode): 52 + soc { 53 + /* 54 + * Enable the SPI direct access by configuring an entry 55 + * here in the board-specific ranges property 56 + */ 57 + ranges = <MBUS_ID(0xf0, 0x01) 0 0 0xf1000000 0x100000>, /* internal regs */ 58 + <MBUS_ID(0x01, 0x1d) 0 0 0xfff00000 0x100000>, /* BootROM */ 59 + <MBUS_ID(0x01, 0x5e) 0 0 0xf1100000 0x10000>, /* SPI0-DEV1 */ 60 + <MBUS_ID(0x01, 0x9a) 0 0 0xf1110000 0x10000>; /* SPI1-DEV2 */ 61 + 62 + For further information on the MBus bindings, please see the MBus 63 + DT documentation: 64 + Documentation/devicetree/bindings/bus/mvebu-mbus.txt
+30 -29
arch/mips/include/asm/octeon/cvmx-mpi-defs.h drivers/spi/spi-cavium.h
··· 1 - /***********************license start*************** 2 - * Author: Cavium Networks 3 - * 4 - * Contact: support@caviumnetworks.com 5 - * This file is part of the OCTEON SDK 6 - * 7 - * Copyright (c) 2003-2012 Cavium Networks 8 - * 9 - * This file is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License, Version 2, as 11 - * published by the Free Software Foundation. 12 - * 13 - * This file is distributed in the hope that it will be useful, but 14 - * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 15 - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 16 - * NONINFRINGEMENT. See the GNU General Public License for more 17 - * details. 18 - * 19 - * You should have received a copy of the GNU General Public License 20 - * along with this file; if not, write to the Free Software 21 - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 - * or visit http://www.gnu.org/licenses/. 23 - * 24 - * This file may also be available under a different license from Cavium. 25 - * Contact Cavium Networks for more information 26 - ***********************license end**************************************/ 1 + #ifndef __SPI_CAVIUM_H 2 + #define __SPI_CAVIUM_H 27 3 28 - #ifndef __CVMX_MPI_DEFS_H__ 29 - #define __CVMX_MPI_DEFS_H__ 4 + #define OCTEON_SPI_MAX_BYTES 9 5 + #define OCTEON_SPI_MAX_CLOCK_HZ 16000000 6 + 7 + struct octeon_spi_regs { 8 + int config; 9 + int status; 10 + int tx; 11 + int data; 12 + }; 13 + 14 + struct octeon_spi { 15 + void __iomem *register_base; 16 + u64 last_cfg; 17 + u64 cs_enax; 18 + int sys_freq; 19 + struct octeon_spi_regs regs; 20 + }; 21 + 22 + #define OCTEON_SPI_CFG(x) (x->regs.config) 23 + #define OCTEON_SPI_STS(x) (x->regs.status) 24 + #define OCTEON_SPI_TX(x) (x->regs.tx) 25 + #define OCTEON_SPI_DAT0(x) (x->regs.data) 26 + 27 + int octeon_spi_transfer_one_message(struct spi_master *master, 28 + struct spi_message *msg); 29 + 30 + /* MPI register descriptions */ 30 31 31 32 #define CVMX_MPI_CFG (CVMX_ADD_IO_SEG(0x0001070000001000ull)) 32 33 #define CVMX_MPI_DATX(offset) (CVMX_ADD_IO_SEG(0x0001070000001080ull) + ((offset) & 15) * 8) ··· 326 325 struct cvmx_mpi_tx_cn61xx cnf71xx; 327 326 }; 328 327 329 - #endif 328 + #endif /* __SPI_CAVIUM_H */
+1
drivers/spi/Kconfig
··· 411 411 tristate "McSPI driver for OMAP" 412 412 depends on HAS_DMA 413 413 depends on ARCH_OMAP2PLUS || COMPILE_TEST 414 + select SG_SPLIT 414 415 help 415 416 SPI master controller for OMAP24XX and later Multichannel SPI 416 417 (McSPI) modules.
+1
drivers/spi/Makefile
··· 56 56 obj-$(CONFIG_SPI_MXS) += spi-mxs.o 57 57 obj-$(CONFIG_SPI_NUC900) += spi-nuc900.o 58 58 obj-$(CONFIG_SPI_OC_TINY) += spi-oc-tiny.o 59 + spi-octeon-objs := spi-cavium.o spi-cavium-octeon.o 59 60 obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o 60 61 obj-$(CONFIG_SPI_OMAP_UWIRE) += spi-omap-uwire.o 61 62 obj-$(CONFIG_SPI_OMAP_100K) += spi-omap-100k.o
+104
drivers/spi/spi-cavium-octeon.c
··· 1 + /* 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * Copyright (C) 2011, 2012 Cavium, Inc. 7 + */ 8 + 9 + #include <linux/platform_device.h> 10 + #include <linux/spi/spi.h> 11 + #include <linux/module.h> 12 + #include <linux/io.h> 13 + #include <linux/of.h> 14 + 15 + #include <asm/octeon/octeon.h> 16 + 17 + #include "spi-cavium.h" 18 + 19 + static int octeon_spi_probe(struct platform_device *pdev) 20 + { 21 + struct resource *res_mem; 22 + void __iomem *reg_base; 23 + struct spi_master *master; 24 + struct octeon_spi *p; 25 + int err = -ENOENT; 26 + 27 + master = spi_alloc_master(&pdev->dev, sizeof(struct octeon_spi)); 28 + if (!master) 29 + return -ENOMEM; 30 + p = spi_master_get_devdata(master); 31 + platform_set_drvdata(pdev, master); 32 + 33 + res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 34 + reg_base = devm_ioremap_resource(&pdev->dev, res_mem); 35 + if (IS_ERR(reg_base)) { 36 + err = PTR_ERR(reg_base); 37 + goto fail; 38 + } 39 + 40 + p->register_base = reg_base; 41 + p->sys_freq = octeon_get_io_clock_rate(); 42 + 43 + p->regs.config = 0; 44 + p->regs.status = 0x08; 45 + p->regs.tx = 0x10; 46 + p->regs.data = 0x80; 47 + 48 + master->num_chipselect = 4; 49 + master->mode_bits = SPI_CPHA | 50 + SPI_CPOL | 51 + SPI_CS_HIGH | 52 + SPI_LSB_FIRST | 53 + SPI_3WIRE; 54 + 55 + master->transfer_one_message = octeon_spi_transfer_one_message; 56 + master->bits_per_word_mask = SPI_BPW_MASK(8); 57 + master->max_speed_hz = OCTEON_SPI_MAX_CLOCK_HZ; 58 + 59 + master->dev.of_node = pdev->dev.of_node; 60 + err = devm_spi_register_master(&pdev->dev, master); 61 + if (err) { 62 + dev_err(&pdev->dev, "register master failed: %d\n", err); 63 + goto fail; 64 + } 65 + 66 + dev_info(&pdev->dev, "OCTEON SPI bus driver\n"); 67 + 68 + return 0; 69 + fail: 70 + spi_master_put(master); 71 + return err; 72 + } 73 + 74 + static int octeon_spi_remove(struct platform_device *pdev) 75 + { 76 + struct spi_master *master = platform_get_drvdata(pdev); 77 + struct octeon_spi *p = spi_master_get_devdata(master); 78 + 79 + /* Clear the CSENA* and put everything in a known state. */ 80 + writeq(0, p->register_base + OCTEON_SPI_CFG(p)); 81 + 82 + return 0; 83 + } 84 + 85 + static const struct of_device_id octeon_spi_match[] = { 86 + { .compatible = "cavium,octeon-3010-spi", }, 87 + {}, 88 + }; 89 + MODULE_DEVICE_TABLE(of, octeon_spi_match); 90 + 91 + static struct platform_driver octeon_spi_driver = { 92 + .driver = { 93 + .name = "spi-octeon", 94 + .of_match_table = octeon_spi_match, 95 + }, 96 + .probe = octeon_spi_probe, 97 + .remove = octeon_spi_remove, 98 + }; 99 + 100 + module_platform_driver(octeon_spi_driver); 101 + 102 + MODULE_DESCRIPTION("Cavium, Inc. OCTEON SPI bus driver"); 103 + MODULE_AUTHOR("David Daney"); 104 + MODULE_LICENSE("GPL");
+151
drivers/spi/spi-cavium.c
··· 1 + /* 2 + * This file is subject to the terms and conditions of the GNU General Public 3 + * License. See the file "COPYING" in the main directory of this archive 4 + * for more details. 5 + * 6 + * Copyright (C) 2011, 2012 Cavium, Inc. 7 + */ 8 + 9 + #include <linux/spi/spi.h> 10 + #include <linux/module.h> 11 + #include <linux/delay.h> 12 + #include <linux/io.h> 13 + 14 + #include "spi-cavium.h" 15 + 16 + static void octeon_spi_wait_ready(struct octeon_spi *p) 17 + { 18 + union cvmx_mpi_sts mpi_sts; 19 + unsigned int loops = 0; 20 + 21 + do { 22 + if (loops++) 23 + __delay(500); 24 + mpi_sts.u64 = readq(p->register_base + OCTEON_SPI_STS(p)); 25 + } while (mpi_sts.s.busy); 26 + } 27 + 28 + static int octeon_spi_do_transfer(struct octeon_spi *p, 29 + struct spi_message *msg, 30 + struct spi_transfer *xfer, 31 + bool last_xfer) 32 + { 33 + struct spi_device *spi = msg->spi; 34 + union cvmx_mpi_cfg mpi_cfg; 35 + union cvmx_mpi_tx mpi_tx; 36 + unsigned int clkdiv; 37 + int mode; 38 + bool cpha, cpol; 39 + const u8 *tx_buf; 40 + u8 *rx_buf; 41 + int len; 42 + int i; 43 + 44 + mode = spi->mode; 45 + cpha = mode & SPI_CPHA; 46 + cpol = mode & SPI_CPOL; 47 + 48 + clkdiv = p->sys_freq / (2 * xfer->speed_hz); 49 + 50 + mpi_cfg.u64 = 0; 51 + 52 + mpi_cfg.s.clkdiv = clkdiv; 53 + mpi_cfg.s.cshi = (mode & SPI_CS_HIGH) ? 1 : 0; 54 + mpi_cfg.s.lsbfirst = (mode & SPI_LSB_FIRST) ? 1 : 0; 55 + mpi_cfg.s.wireor = (mode & SPI_3WIRE) ? 1 : 0; 56 + mpi_cfg.s.idlelo = cpha != cpol; 57 + mpi_cfg.s.cslate = cpha ? 1 : 0; 58 + mpi_cfg.s.enable = 1; 59 + 60 + if (spi->chip_select < 4) 61 + p->cs_enax |= 1ull << (12 + spi->chip_select); 62 + mpi_cfg.u64 |= p->cs_enax; 63 + 64 + if (mpi_cfg.u64 != p->last_cfg) { 65 + p->last_cfg = mpi_cfg.u64; 66 + writeq(mpi_cfg.u64, p->register_base + OCTEON_SPI_CFG(p)); 67 + } 68 + tx_buf = xfer->tx_buf; 69 + rx_buf = xfer->rx_buf; 70 + len = xfer->len; 71 + while (len > OCTEON_SPI_MAX_BYTES) { 72 + for (i = 0; i < OCTEON_SPI_MAX_BYTES; i++) { 73 + u8 d; 74 + if (tx_buf) 75 + d = *tx_buf++; 76 + else 77 + d = 0; 78 + writeq(d, p->register_base + OCTEON_SPI_DAT0(p) + (8 * i)); 79 + } 80 + mpi_tx.u64 = 0; 81 + mpi_tx.s.csid = spi->chip_select; 82 + mpi_tx.s.leavecs = 1; 83 + mpi_tx.s.txnum = tx_buf ? OCTEON_SPI_MAX_BYTES : 0; 84 + mpi_tx.s.totnum = OCTEON_SPI_MAX_BYTES; 85 + writeq(mpi_tx.u64, p->register_base + OCTEON_SPI_TX(p)); 86 + 87 + octeon_spi_wait_ready(p); 88 + if (rx_buf) 89 + for (i = 0; i < OCTEON_SPI_MAX_BYTES; i++) { 90 + u64 v = readq(p->register_base + OCTEON_SPI_DAT0(p) + (8 * i)); 91 + *rx_buf++ = (u8)v; 92 + } 93 + len -= OCTEON_SPI_MAX_BYTES; 94 + } 95 + 96 + for (i = 0; i < len; i++) { 97 + u8 d; 98 + if (tx_buf) 99 + d = *tx_buf++; 100 + else 101 + d = 0; 102 + writeq(d, p->register_base + OCTEON_SPI_DAT0(p) + (8 * i)); 103 + } 104 + 105 + mpi_tx.u64 = 0; 106 + mpi_tx.s.csid = spi->chip_select; 107 + if (last_xfer) 108 + mpi_tx.s.leavecs = xfer->cs_change; 109 + else 110 + mpi_tx.s.leavecs = !xfer->cs_change; 111 + mpi_tx.s.txnum = tx_buf ? len : 0; 112 + mpi_tx.s.totnum = len; 113 + writeq(mpi_tx.u64, p->register_base + OCTEON_SPI_TX(p)); 114 + 115 + octeon_spi_wait_ready(p); 116 + if (rx_buf) 117 + for (i = 0; i < len; i++) { 118 + u64 v = readq(p->register_base + OCTEON_SPI_DAT0(p) + (8 * i)); 119 + *rx_buf++ = (u8)v; 120 + } 121 + 122 + if (xfer->delay_usecs) 123 + udelay(xfer->delay_usecs); 124 + 125 + return xfer->len; 126 + } 127 + 128 + int octeon_spi_transfer_one_message(struct spi_master *master, 129 + struct spi_message *msg) 130 + { 131 + struct octeon_spi *p = spi_master_get_devdata(master); 132 + unsigned int total_len = 0; 133 + int status = 0; 134 + struct spi_transfer *xfer; 135 + 136 + list_for_each_entry(xfer, &msg->transfers, transfer_list) { 137 + bool last_xfer = list_is_last(&xfer->transfer_list, 138 + &msg->transfers); 139 + int r = octeon_spi_do_transfer(p, msg, xfer, last_xfer); 140 + if (r < 0) { 141 + status = r; 142 + goto err; 143 + } 144 + total_len += r; 145 + } 146 + err: 147 + msg->status = status; 148 + msg->actual_length = total_len; 149 + spi_finalize_current_message(master); 150 + return status; 151 + }
-255
drivers/spi/spi-octeon.c
··· 1 - /* 2 - * This file is subject to the terms and conditions of the GNU General Public 3 - * License. See the file "COPYING" in the main directory of this archive 4 - * for more details. 5 - * 6 - * Copyright (C) 2011, 2012 Cavium, Inc. 7 - */ 8 - 9 - #include <linux/platform_device.h> 10 - #include <linux/interrupt.h> 11 - #include <linux/spi/spi.h> 12 - #include <linux/module.h> 13 - #include <linux/delay.h> 14 - #include <linux/io.h> 15 - #include <linux/of.h> 16 - 17 - #include <asm/octeon/octeon.h> 18 - #include <asm/octeon/cvmx-mpi-defs.h> 19 - 20 - #define OCTEON_SPI_CFG 0 21 - #define OCTEON_SPI_STS 0x08 22 - #define OCTEON_SPI_TX 0x10 23 - #define OCTEON_SPI_DAT0 0x80 24 - 25 - #define OCTEON_SPI_MAX_BYTES 9 26 - 27 - #define OCTEON_SPI_MAX_CLOCK_HZ 16000000 28 - 29 - struct octeon_spi { 30 - u64 register_base; 31 - u64 last_cfg; 32 - u64 cs_enax; 33 - }; 34 - 35 - static void octeon_spi_wait_ready(struct octeon_spi *p) 36 - { 37 - union cvmx_mpi_sts mpi_sts; 38 - unsigned int loops = 0; 39 - 40 - do { 41 - if (loops++) 42 - __delay(500); 43 - mpi_sts.u64 = cvmx_read_csr(p->register_base + OCTEON_SPI_STS); 44 - } while (mpi_sts.s.busy); 45 - } 46 - 47 - static int octeon_spi_do_transfer(struct octeon_spi *p, 48 - struct spi_message *msg, 49 - struct spi_transfer *xfer, 50 - bool last_xfer) 51 - { 52 - struct spi_device *spi = msg->spi; 53 - union cvmx_mpi_cfg mpi_cfg; 54 - union cvmx_mpi_tx mpi_tx; 55 - unsigned int clkdiv; 56 - unsigned int speed_hz; 57 - int mode; 58 - bool cpha, cpol; 59 - const u8 *tx_buf; 60 - u8 *rx_buf; 61 - int len; 62 - int i; 63 - 64 - mode = spi->mode; 65 - cpha = mode & SPI_CPHA; 66 - cpol = mode & SPI_CPOL; 67 - 68 - speed_hz = xfer->speed_hz; 69 - 70 - clkdiv = octeon_get_io_clock_rate() / (2 * speed_hz); 71 - 72 - mpi_cfg.u64 = 0; 73 - 74 - mpi_cfg.s.clkdiv = clkdiv; 75 - mpi_cfg.s.cshi = (mode & SPI_CS_HIGH) ? 1 : 0; 76 - mpi_cfg.s.lsbfirst = (mode & SPI_LSB_FIRST) ? 1 : 0; 77 - mpi_cfg.s.wireor = (mode & SPI_3WIRE) ? 1 : 0; 78 - mpi_cfg.s.idlelo = cpha != cpol; 79 - mpi_cfg.s.cslate = cpha ? 1 : 0; 80 - mpi_cfg.s.enable = 1; 81 - 82 - if (spi->chip_select < 4) 83 - p->cs_enax |= 1ull << (12 + spi->chip_select); 84 - mpi_cfg.u64 |= p->cs_enax; 85 - 86 - if (mpi_cfg.u64 != p->last_cfg) { 87 - p->last_cfg = mpi_cfg.u64; 88 - cvmx_write_csr(p->register_base + OCTEON_SPI_CFG, mpi_cfg.u64); 89 - } 90 - tx_buf = xfer->tx_buf; 91 - rx_buf = xfer->rx_buf; 92 - len = xfer->len; 93 - while (len > OCTEON_SPI_MAX_BYTES) { 94 - for (i = 0; i < OCTEON_SPI_MAX_BYTES; i++) { 95 - u8 d; 96 - if (tx_buf) 97 - d = *tx_buf++; 98 - else 99 - d = 0; 100 - cvmx_write_csr(p->register_base + OCTEON_SPI_DAT0 + (8 * i), d); 101 - } 102 - mpi_tx.u64 = 0; 103 - mpi_tx.s.csid = spi->chip_select; 104 - mpi_tx.s.leavecs = 1; 105 - mpi_tx.s.txnum = tx_buf ? OCTEON_SPI_MAX_BYTES : 0; 106 - mpi_tx.s.totnum = OCTEON_SPI_MAX_BYTES; 107 - cvmx_write_csr(p->register_base + OCTEON_SPI_TX, mpi_tx.u64); 108 - 109 - octeon_spi_wait_ready(p); 110 - if (rx_buf) 111 - for (i = 0; i < OCTEON_SPI_MAX_BYTES; i++) { 112 - u64 v = cvmx_read_csr(p->register_base + OCTEON_SPI_DAT0 + (8 * i)); 113 - *rx_buf++ = (u8)v; 114 - } 115 - len -= OCTEON_SPI_MAX_BYTES; 116 - } 117 - 118 - for (i = 0; i < len; i++) { 119 - u8 d; 120 - if (tx_buf) 121 - d = *tx_buf++; 122 - else 123 - d = 0; 124 - cvmx_write_csr(p->register_base + OCTEON_SPI_DAT0 + (8 * i), d); 125 - } 126 - 127 - mpi_tx.u64 = 0; 128 - mpi_tx.s.csid = spi->chip_select; 129 - if (last_xfer) 130 - mpi_tx.s.leavecs = xfer->cs_change; 131 - else 132 - mpi_tx.s.leavecs = !xfer->cs_change; 133 - mpi_tx.s.txnum = tx_buf ? len : 0; 134 - mpi_tx.s.totnum = len; 135 - cvmx_write_csr(p->register_base + OCTEON_SPI_TX, mpi_tx.u64); 136 - 137 - octeon_spi_wait_ready(p); 138 - if (rx_buf) 139 - for (i = 0; i < len; i++) { 140 - u64 v = cvmx_read_csr(p->register_base + OCTEON_SPI_DAT0 + (8 * i)); 141 - *rx_buf++ = (u8)v; 142 - } 143 - 144 - if (xfer->delay_usecs) 145 - udelay(xfer->delay_usecs); 146 - 147 - return xfer->len; 148 - } 149 - 150 - static int octeon_spi_transfer_one_message(struct spi_master *master, 151 - struct spi_message *msg) 152 - { 153 - struct octeon_spi *p = spi_master_get_devdata(master); 154 - unsigned int total_len = 0; 155 - int status = 0; 156 - struct spi_transfer *xfer; 157 - 158 - list_for_each_entry(xfer, &msg->transfers, transfer_list) { 159 - bool last_xfer = list_is_last(&xfer->transfer_list, 160 - &msg->transfers); 161 - int r = octeon_spi_do_transfer(p, msg, xfer, last_xfer); 162 - if (r < 0) { 163 - status = r; 164 - goto err; 165 - } 166 - total_len += r; 167 - } 168 - err: 169 - msg->status = status; 170 - msg->actual_length = total_len; 171 - spi_finalize_current_message(master); 172 - return status; 173 - } 174 - 175 - static int octeon_spi_probe(struct platform_device *pdev) 176 - { 177 - struct resource *res_mem; 178 - void __iomem *reg_base; 179 - struct spi_master *master; 180 - struct octeon_spi *p; 181 - int err = -ENOENT; 182 - 183 - master = spi_alloc_master(&pdev->dev, sizeof(struct octeon_spi)); 184 - if (!master) 185 - return -ENOMEM; 186 - p = spi_master_get_devdata(master); 187 - platform_set_drvdata(pdev, master); 188 - 189 - res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 190 - reg_base = devm_ioremap_resource(&pdev->dev, res_mem); 191 - if (IS_ERR(reg_base)) { 192 - err = PTR_ERR(reg_base); 193 - goto fail; 194 - } 195 - 196 - p->register_base = (u64)reg_base; 197 - 198 - master->num_chipselect = 4; 199 - master->mode_bits = SPI_CPHA | 200 - SPI_CPOL | 201 - SPI_CS_HIGH | 202 - SPI_LSB_FIRST | 203 - SPI_3WIRE; 204 - 205 - master->transfer_one_message = octeon_spi_transfer_one_message; 206 - master->bits_per_word_mask = SPI_BPW_MASK(8); 207 - master->max_speed_hz = OCTEON_SPI_MAX_CLOCK_HZ; 208 - 209 - master->dev.of_node = pdev->dev.of_node; 210 - err = devm_spi_register_master(&pdev->dev, master); 211 - if (err) { 212 - dev_err(&pdev->dev, "register master failed: %d\n", err); 213 - goto fail; 214 - } 215 - 216 - dev_info(&pdev->dev, "OCTEON SPI bus driver\n"); 217 - 218 - return 0; 219 - fail: 220 - spi_master_put(master); 221 - return err; 222 - } 223 - 224 - static int octeon_spi_remove(struct platform_device *pdev) 225 - { 226 - struct spi_master *master = platform_get_drvdata(pdev); 227 - struct octeon_spi *p = spi_master_get_devdata(master); 228 - u64 register_base = p->register_base; 229 - 230 - /* Clear the CSENA* and put everything in a known state. */ 231 - cvmx_write_csr(register_base + OCTEON_SPI_CFG, 0); 232 - 233 - return 0; 234 - } 235 - 236 - static const struct of_device_id octeon_spi_match[] = { 237 - { .compatible = "cavium,octeon-3010-spi", }, 238 - {}, 239 - }; 240 - MODULE_DEVICE_TABLE(of, octeon_spi_match); 241 - 242 - static struct platform_driver octeon_spi_driver = { 243 - .driver = { 244 - .name = "spi-octeon", 245 - .of_match_table = octeon_spi_match, 246 - }, 247 - .probe = octeon_spi_probe, 248 - .remove = octeon_spi_remove, 249 - }; 250 - 251 - module_platform_driver(octeon_spi_driver); 252 - 253 - MODULE_DESCRIPTION("Cavium, Inc. OCTEON SPI bus driver"); 254 - MODULE_AUTHOR("David Daney"); 255 - MODULE_LICENSE("GPL");
+69 -76
drivers/spi/spi-omap2-mcspi.c
··· 419 419 420 420 if (mcspi_dma->dma_tx) { 421 421 struct dma_async_tx_descriptor *tx; 422 - struct scatterlist sg; 423 422 424 423 dmaengine_slave_config(mcspi_dma->dma_tx, &cfg); 425 424 426 - sg_init_table(&sg, 1); 427 - sg_dma_address(&sg) = xfer->tx_dma; 428 - sg_dma_len(&sg) = xfer->len; 429 - 430 - tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, &sg, 1, 431 - DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 425 + tx = dmaengine_prep_slave_sg(mcspi_dma->dma_tx, xfer->tx_sg.sgl, 426 + xfer->tx_sg.nents, 427 + DMA_MEM_TO_DEV, 428 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 432 429 if (tx) { 433 430 tx->callback = omap2_mcspi_tx_callback; 434 431 tx->callback_param = spi; ··· 446 449 { 447 450 struct omap2_mcspi *mcspi; 448 451 struct omap2_mcspi_dma *mcspi_dma; 449 - unsigned int count, dma_count; 452 + unsigned int count, transfer_reduction = 0; 453 + struct scatterlist *sg_out[2]; 454 + int nb_sizes = 0, out_mapped_nents[2], ret, x; 455 + size_t sizes[2]; 450 456 u32 l; 451 457 int elements = 0; 452 458 int word_len, element_count; ··· 457 457 mcspi = spi_master_get_devdata(spi->master); 458 458 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 459 459 count = xfer->len; 460 - dma_count = xfer->len; 461 460 461 + /* 462 + * In the "End-of-Transfer Procedure" section for DMA RX in OMAP35x TRM 463 + * it mentions reducing DMA transfer length by one element in master 464 + * normal mode. 465 + */ 462 466 if (mcspi->fifo_depth == 0) 463 - dma_count -= es; 467 + transfer_reduction = es; 464 468 465 469 word_len = cs->word_len; 466 470 l = mcspi_cached_chconf0(spi); ··· 478 474 479 475 if (mcspi_dma->dma_rx) { 480 476 struct dma_async_tx_descriptor *tx; 481 - struct scatterlist sg; 482 477 483 478 dmaengine_slave_config(mcspi_dma->dma_rx, &cfg); 484 479 480 + /* 481 + * Reduce DMA transfer length by one more if McSPI is 482 + * configured in turbo mode. 483 + */ 485 484 if ((l & OMAP2_MCSPI_CHCONF_TURBO) && mcspi->fifo_depth == 0) 486 - dma_count -= es; 485 + transfer_reduction += es; 487 486 488 - sg_init_table(&sg, 1); 489 - sg_dma_address(&sg) = xfer->rx_dma; 490 - sg_dma_len(&sg) = dma_count; 487 + if (transfer_reduction) { 488 + /* Split sgl into two. The second sgl won't be used. */ 489 + sizes[0] = count - transfer_reduction; 490 + sizes[1] = transfer_reduction; 491 + nb_sizes = 2; 492 + } else { 493 + /* 494 + * Don't bother splitting the sgl. This essentially 495 + * clones the original sgl. 496 + */ 497 + sizes[0] = count; 498 + nb_sizes = 1; 499 + } 491 500 492 - tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, &sg, 1, 493 - DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | 494 - DMA_CTRL_ACK); 501 + ret = sg_split(xfer->rx_sg.sgl, xfer->rx_sg.nents, 502 + 0, nb_sizes, 503 + sizes, 504 + sg_out, out_mapped_nents, 505 + GFP_KERNEL); 506 + 507 + if (ret < 0) { 508 + dev_err(&spi->dev, "sg_split failed\n"); 509 + return 0; 510 + } 511 + 512 + tx = dmaengine_prep_slave_sg(mcspi_dma->dma_rx, 513 + sg_out[0], 514 + out_mapped_nents[0], 515 + DMA_DEV_TO_MEM, 516 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 495 517 if (tx) { 496 518 tx->callback = omap2_mcspi_rx_callback; 497 519 tx->callback_param = spi; ··· 531 501 omap2_mcspi_set_dma_req(spi, 1, 1); 532 502 533 503 wait_for_completion(&mcspi_dma->dma_rx_completion); 534 - dma_unmap_single(mcspi->dev, xfer->rx_dma, count, 535 - DMA_FROM_DEVICE); 504 + 505 + for (x = 0; x < nb_sizes; x++) 506 + kfree(sg_out[x]); 536 507 537 508 if (mcspi->fifo_depth > 0) 538 509 return count; 539 510 511 + /* 512 + * Due to the DMA transfer length reduction the missing bytes must 513 + * be read manually to receive all of the expected data. 514 + */ 540 515 omap2_mcspi_set_enable(spi, 0); 541 516 542 517 elements = element_count - 1; ··· 650 615 651 616 if (tx != NULL) { 652 617 wait_for_completion(&mcspi_dma->dma_tx_completion); 653 - dma_unmap_single(mcspi->dev, xfer->tx_dma, xfer->len, 654 - DMA_TO_DEVICE); 655 618 656 619 if (mcspi->fifo_depth > 0) { 657 620 irqstat_reg = mcspi->base + OMAP2_MCSPI_IRQSTATUS; ··· 1107 1074 gpio_free(spi->cs_gpio); 1108 1075 } 1109 1076 1110 - static int omap2_mcspi_work_one(struct omap2_mcspi *mcspi, 1111 - struct spi_device *spi, struct spi_transfer *t) 1077 + static int omap2_mcspi_transfer_one(struct spi_master *master, 1078 + struct spi_device *spi, 1079 + struct spi_transfer *t) 1112 1080 { 1113 1081 1114 1082 /* We only enable one channel at a time -- the one whose message is ··· 1119 1085 * chipselect with the FORCE bit ... CS != channel enable. 1120 1086 */ 1121 1087 1122 - struct spi_master *master; 1088 + struct omap2_mcspi *mcspi; 1123 1089 struct omap2_mcspi_dma *mcspi_dma; 1124 1090 struct omap2_mcspi_cs *cs; 1125 1091 struct omap2_mcspi_device_config *cd; ··· 1127 1093 int status = 0; 1128 1094 u32 chconf; 1129 1095 1130 - master = spi->master; 1096 + mcspi = spi_master_get_devdata(master); 1131 1097 mcspi_dma = mcspi->dma_channels + spi->chip_select; 1132 1098 cs = spi->controller_state; 1133 1099 cd = spi->controller_data; ··· 1187 1153 unsigned count; 1188 1154 1189 1155 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && 1190 - (t->len >= DMA_MIN_BYTES)) 1156 + master->cur_msg_mapped && 1157 + master->can_dma(master, spi, t)) 1191 1158 omap2_mcspi_set_fifo(spi, t, 1); 1192 1159 1193 1160 omap2_mcspi_set_enable(spi, 1); ··· 1199 1164 + OMAP2_MCSPI_TX0); 1200 1165 1201 1166 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && 1202 - (t->len >= DMA_MIN_BYTES)) 1167 + master->cur_msg_mapped && 1168 + master->can_dma(master, spi, t)) 1203 1169 count = omap2_mcspi_txrx_dma(spi, t); 1204 1170 else 1205 1171 count = omap2_mcspi_txrx_pio(spi, t); ··· 1269 1233 return 0; 1270 1234 } 1271 1235 1272 - static int omap2_mcspi_transfer_one(struct spi_master *master, 1273 - struct spi_device *spi, struct spi_transfer *t) 1236 + static bool omap2_mcspi_can_dma(struct spi_master *master, 1237 + struct spi_device *spi, 1238 + struct spi_transfer *xfer) 1274 1239 { 1275 - struct omap2_mcspi *mcspi; 1276 - struct omap2_mcspi_dma *mcspi_dma; 1277 - const void *tx_buf = t->tx_buf; 1278 - void *rx_buf = t->rx_buf; 1279 - unsigned len = t->len; 1280 - 1281 - mcspi = spi_master_get_devdata(master); 1282 - mcspi_dma = mcspi->dma_channels + spi->chip_select; 1283 - 1284 - if ((len && !(rx_buf || tx_buf))) { 1285 - dev_dbg(mcspi->dev, "transfer: %d Hz, %d %s%s, %d bpw\n", 1286 - t->speed_hz, 1287 - len, 1288 - tx_buf ? "tx" : "", 1289 - rx_buf ? "rx" : "", 1290 - t->bits_per_word); 1291 - return -EINVAL; 1292 - } 1293 - 1294 - if (len < DMA_MIN_BYTES) 1295 - goto skip_dma_map; 1296 - 1297 - if (mcspi_dma->dma_tx && tx_buf != NULL) { 1298 - t->tx_dma = dma_map_single(mcspi->dev, (void *) tx_buf, 1299 - len, DMA_TO_DEVICE); 1300 - if (dma_mapping_error(mcspi->dev, t->tx_dma)) { 1301 - dev_dbg(mcspi->dev, "dma %cX %d bytes error\n", 1302 - 'T', len); 1303 - return -EINVAL; 1304 - } 1305 - } 1306 - if (mcspi_dma->dma_rx && rx_buf != NULL) { 1307 - t->rx_dma = dma_map_single(mcspi->dev, rx_buf, t->len, 1308 - DMA_FROM_DEVICE); 1309 - if (dma_mapping_error(mcspi->dev, t->rx_dma)) { 1310 - dev_dbg(mcspi->dev, "dma %cX %d bytes error\n", 1311 - 'R', len); 1312 - if (tx_buf != NULL) 1313 - dma_unmap_single(mcspi->dev, t->tx_dma, 1314 - len, DMA_TO_DEVICE); 1315 - return -EINVAL; 1316 - } 1317 - } 1318 - 1319 - skip_dma_map: 1320 - return omap2_mcspi_work_one(mcspi, spi, t); 1240 + return (xfer->len >= DMA_MIN_BYTES); 1321 1241 } 1322 1242 1323 1243 static int omap2_mcspi_master_setup(struct omap2_mcspi *mcspi) ··· 1353 1361 master->setup = omap2_mcspi_setup; 1354 1362 master->auto_runtime_pm = true; 1355 1363 master->prepare_message = omap2_mcspi_prepare_message; 1364 + master->can_dma = omap2_mcspi_can_dma; 1356 1365 master->transfer_one = omap2_mcspi_transfer_one; 1357 1366 master->set_cs = omap2_mcspi_set_cs; 1358 1367 master->cleanup = omap2_mcspi_cleanup;
+88
drivers/spi/spi-orion.c
··· 18 18 #include <linux/module.h> 19 19 #include <linux/pm_runtime.h> 20 20 #include <linux/of.h> 21 + #include <linux/of_address.h> 21 22 #include <linux/of_device.h> 22 23 #include <linux/clk.h> 23 24 #include <linux/sizes.h> ··· 43 42 #define ORION_SPI_DATA_IN_REG 0x0c 44 43 #define ORION_SPI_INT_CAUSE_REG 0x10 45 44 #define ORION_SPI_TIMING_PARAMS_REG 0x18 45 + 46 + /* Register for the "Direct Mode" */ 47 + #define SPI_DIRECT_WRITE_CONFIG_REG 0x20 46 48 47 49 #define ORION_SPI_TMISO_SAMPLE_MASK (0x3 << 6) 48 50 #define ORION_SPI_TMISO_SAMPLE_1 (1 << 6) ··· 82 78 bool is_errata_50mhz_ac; 83 79 }; 84 80 81 + struct orion_direct_acc { 82 + void __iomem *vaddr; 83 + u32 size; 84 + }; 85 + 85 86 struct orion_spi { 86 87 struct spi_master *master; 87 88 void __iomem *base; 88 89 struct clk *clk; 89 90 const struct orion_spi_dev *devdata; 91 + 92 + struct orion_direct_acc direct_access[ORION_NUM_CHIPSELECTS]; 90 93 }; 91 94 92 95 static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg) ··· 383 372 { 384 373 unsigned int count; 385 374 int word_len; 375 + struct orion_spi *orion_spi; 376 + int cs = spi->chip_select; 386 377 387 378 word_len = spi->bits_per_word; 388 379 count = xfer->len; 380 + 381 + orion_spi = spi_master_get_devdata(spi->master); 382 + 383 + /* 384 + * Use SPI direct write mode if base address is available. Otherwise 385 + * fall back to PIO mode for this transfer. 386 + */ 387 + if ((orion_spi->direct_access[cs].vaddr) && (xfer->tx_buf) && 388 + (word_len == 8)) { 389 + unsigned int cnt = count / 4; 390 + unsigned int rem = count % 4; 391 + 392 + /* 393 + * Send the TX-data to the SPI device via the direct 394 + * mapped address window 395 + */ 396 + iowrite32_rep(orion_spi->direct_access[cs].vaddr, 397 + xfer->tx_buf, cnt); 398 + if (rem) { 399 + u32 *buf = (u32 *)xfer->tx_buf; 400 + 401 + iowrite8_rep(orion_spi->direct_access[cs].vaddr, 402 + &buf[cnt], rem); 403 + } 404 + 405 + return count; 406 + } 389 407 390 408 if (word_len == 8) { 391 409 const u8 *tx = xfer->tx_buf; ··· 465 425 { 466 426 /* Verify that the CS is deasserted */ 467 427 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1); 428 + 429 + /* Don't deassert CS between the direct mapped SPI transfers */ 430 + writel(0, spi_reg(orion_spi, SPI_DIRECT_WRITE_CONFIG_REG)); 431 + 468 432 return 0; 469 433 } 470 434 ··· 548 504 struct resource *r; 549 505 unsigned long tclk_hz; 550 506 int status = 0; 507 + struct device_node *np; 551 508 552 509 master = spi_alloc_master(&pdev->dev, sizeof(*spi)); 553 510 if (master == NULL) { ··· 619 574 if (IS_ERR(spi->base)) { 620 575 status = PTR_ERR(spi->base); 621 576 goto out_rel_clk; 577 + } 578 + 579 + /* Scan all SPI devices of this controller for direct mapped devices */ 580 + for_each_available_child_of_node(pdev->dev.of_node, np) { 581 + u32 cs; 582 + 583 + /* Get chip-select number from the "reg" property */ 584 + status = of_property_read_u32(np, "reg", &cs); 585 + if (status) { 586 + dev_err(&pdev->dev, 587 + "%s has no valid 'reg' property (%d)\n", 588 + np->full_name, status); 589 + status = 0; 590 + continue; 591 + } 592 + 593 + /* 594 + * Check if an address is configured for this SPI device. If 595 + * not, the MBus mapping via the 'ranges' property in the 'soc' 596 + * node is not configured and this device should not use the 597 + * direct mode. In this case, just continue with the next 598 + * device. 599 + */ 600 + status = of_address_to_resource(pdev->dev.of_node, cs + 1, r); 601 + if (status) 602 + continue; 603 + 604 + /* 605 + * Only map one page for direct access. This is enough for the 606 + * simple TX transfer which only writes to the first word. 607 + * This needs to get extended for the direct SPI-NOR / SPI-NAND 608 + * support, once this gets implemented. 609 + */ 610 + spi->direct_access[cs].vaddr = devm_ioremap(&pdev->dev, 611 + r->start, 612 + PAGE_SIZE); 613 + if (!spi->direct_access[cs].vaddr) { 614 + status = -ENOMEM; 615 + goto out_rel_clk; 616 + } 617 + spi->direct_access[cs].size = PAGE_SIZE; 618 + 619 + dev_info(&pdev->dev, "CS%d configured for direct access\n", cs); 622 620 } 623 621 624 622 pm_runtime_set_active(&pdev->dev);
+4 -3
drivers/spi/spi-pic32-sqi.c
··· 354 354 struct spi_transfer *xfer; 355 355 struct pic32_sqi *sqi; 356 356 int ret = 0, mode; 357 + unsigned long timeout; 357 358 u32 val; 358 359 359 360 sqi = spi_master_get_devdata(master); ··· 420 419 writel(val, sqi->regs + PESQI_BD_CTRL_REG); 421 420 422 421 /* wait for xfer completion */ 423 - ret = wait_for_completion_timeout(&sqi->xfer_done, 5 * HZ); 424 - if (ret <= 0) { 422 + timeout = wait_for_completion_timeout(&sqi->xfer_done, 5 * HZ); 423 + if (timeout == 0) { 425 424 dev_err(&sqi->master->dev, "wait timedout/interrupted\n"); 426 - ret = -EIO; 425 + ret = -ETIMEDOUT; 427 426 msg->status = ret; 428 427 } else { 429 428 /* success */
+3 -2
drivers/spi/spi-pic32.c
··· 507 507 { 508 508 struct pic32_spi *pic32s; 509 509 bool dma_issued = false; 510 + unsigned long timeout; 510 511 int ret; 511 512 512 513 pic32s = spi_master_get_devdata(master); ··· 554 553 } 555 554 556 555 /* wait for completion */ 557 - ret = wait_for_completion_timeout(&pic32s->xfer_done, 2 * HZ); 558 - if (ret <= 0) { 556 + timeout = wait_for_completion_timeout(&pic32s->xfer_done, 2 * HZ); 557 + if (timeout == 0) { 559 558 dev_err(&spi->dev, "wait error/timedout\n"); 560 559 if (dma_issued) { 561 560 dmaengine_terminate_all(master->dma_rx);