]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
Merge tag 'spi-v3.14-2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Jan 2014 21:20:36 +0000 (13:20 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 25 Jan 2014 21:20:36 +0000 (13:20 -0800)
Pull spi updates from Mark Brown:
 "A respun version of the merges for the pull request previously sent
  with a few additional fixes.  The last two merges were fixed up by
  hand since the branches have moved on and currently have the prior
  merge in them.

  Quite a busy release for the SPI subsystem, mostly in cleanups big and
  small scattered through the stack rather than anything else:

   - New driver for the Broadcom BC63xx HSSPI controller
   - Fix duplicate device registration for ACPI
   - Conversion of s3c64xx to DMAEngine (this pulls in platform and DMA
     changes upon which the transiton depends)
   - Some small optimisations to reduce the amount of time we hold locks
     in the datapath, eliminate some redundant checks and the size of a
     spi_transfer
   - Lots of fixes, cleanups and general enhancements to drivers,
     especially the rspi and Atmel drivers"

* tag 'spi-v3.14-2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (112 commits)
  spi: core: Fix transfer failure when master->transfer_one returns positive value
  spi: Correct set_cs() documentation
  spi: Clarify transfer_one() w.r.t. spi_finalize_current_transfer()
  spi: Spelling s/finised/finished/
  spi: sc18is602: Convert to use bits_per_word_mask
  spi: Remove duplicate code to set default bits_per_word setting
  spi/pxa2xx: fix compilation warning when !CONFIG_PM_SLEEP
  spi: clps711x: Add MODULE_ALIAS to support module auto-loading
  spi: rspi: Add missing clk_disable() calls in error and cleanup paths
  spi: rspi: Spelling s/transmition/transmission/
  spi: rspi: Add support for specifying CPHA/CPOL
  spi/pxa2xx: initialize DMA channels to -1 to prevent inadvertent match
  spi: rspi: Add more QSPI register documentation
  spi: rspi: Add more RSPI register documentation
  spi: rspi: Remove dependency on DMAE for SHMOBILE
  spi/s3c64xx: Correct indentation
  spi: sh: Use spi_sh_clear_bit() instead of open-coded
  spi: bitbang: Grammar s/make to make/to make/
  spi: sh-hspi: Spelling s/recive/receive/
  spi: core: Improve tx/rx_nbits check comments
  ...

1  2 
drivers/spi/Kconfig
drivers/spi/spi-tegra114.c
drivers/spi/spi-tegra20-sflash.c
drivers/spi/spi-tegra20-slink.c
drivers/spi/spi.c

diff --combined drivers/spi/Kconfig
index 385602f77cadf74a0b69c7d8cda1394cb71eba73,5072b71baf5e8424ce5c5bba63d9367d73952177..ba9310bc9acb7449a91ccb59b8f7de5c09c5801d
@@@ -118,6 -118,13 +118,13 @@@ config SPI_BCM63X
        help
            Enable support for the SPI controller on the Broadcom BCM63xx SoCs.
  
+ config SPI_BCM63XX_HSSPI
+       tristate "Broadcom BCM63XX HS SPI controller driver"
+       depends on BCM63XX || COMPILE_TEST
+       help
+         This enables support for the High Speed SPI controller present on
+         newer Broadcom BCM63XX SoCs.
  config SPI_BITBANG
        tristate "Utilities for Bitbanging SPI masters"
        help
@@@ -159,7 -166,6 +166,6 @@@ config SPI_DAVINC
        tristate "Texas Instruments DaVinci/DA8x/OMAP-L/AM1x SoC SPI controller"
        depends on ARCH_DAVINCI || ARCH_KEYSTONE
        select SPI_BITBANG
-       select TI_EDMA
        help
          SPI master controller for DaVinci/DA8x/OMAP-L/AM1x SPI modules.
  
@@@ -301,6 -307,7 +307,7 @@@ config SPI_OMAP_UWIR
  
  config SPI_OMAP24XX
        tristate "McSPI driver for OMAP"
+       depends on ARM || ARM64 || AVR32 || HEXAGON || MIPS || SH
        depends on ARCH_OMAP2PLUS || COMPILE_TEST
        help
          SPI master controller for OMAP24XX and later Multichannel SPI
@@@ -370,7 -377,7 +377,7 @@@ config SPI_PXA2XX_PC
  
  config SPI_RSPI
        tristate "Renesas RSPI controller"
-       depends on (SUPERH || ARCH_SHMOBILE) && SH_DMAE_BASE
+       depends on (SUPERH && SH_DMAE_BASE) || ARCH_SHMOBILE
        help
          SPI driver for Renesas RSPI blocks.
  
@@@ -407,7 -414,8 +414,8 @@@ config SPI_SC18IS60
  
  config SPI_SH_MSIOF
        tristate "SuperH MSIOF SPI controller"
-       depends on (SUPERH || ARCH_SHMOBILE) && HAVE_CLK
+       depends on HAVE_CLK
+       depends on SUPERH || ARCH_SHMOBILE || COMPILE_TEST
        select SPI_BITBANG
        help
          SPI driver for SuperH and SH Mobile MSIOF blocks.
@@@ -448,7 -456,6 +456,7 @@@ config SPI_MX
  config SPI_TEGRA114
        tristate "NVIDIA Tegra114 SPI Controller"
        depends on (ARCH_TEGRA && TEGRA20_APB_DMA) || COMPILE_TEST
 +      depends on RESET_CONTROLLER
        help
          SPI driver for NVIDIA Tegra114 SPI Controller interface. This controller
          is different than the older SoCs SPI controller and also register interface
  config SPI_TEGRA20_SFLASH
        tristate "Nvidia Tegra20 Serial flash Controller"
        depends on ARCH_TEGRA || COMPILE_TEST
 +      depends on RESET_CONTROLLER
        help
          SPI driver for Nvidia Tegra20 Serial flash Controller interface.
          The main usecase of this controller is to use spi flash as boot
  config SPI_TEGRA20_SLINK
        tristate "Nvidia Tegra20/Tegra30 SLINK Controller"
        depends on (ARCH_TEGRA && TEGRA20_APB_DMA) || COMPILE_TEST
 +      depends on RESET_CONTROLLER
        help
          SPI driver for Nvidia Tegra20/Tegra30 SLINK Controller interface.
  
index c8604981a05840cf04b790b358807f5fb0add2ee,47b93cc4bd1912d584d520eb39b4ae24f8595dcd..413c718434927f0d3278c051d15040639a68237a
@@@ -17,6 -17,7 +17,6 @@@
   */
  
  #include <linux/clk.h>
 -#include <linux/clk/tegra.h>
  #include <linux/completion.h>
  #include <linux/delay.h>
  #include <linux/dmaengine.h>
@@@ -33,7 -34,6 +33,7 @@@
  #include <linux/pm_runtime.h>
  #include <linux/of.h>
  #include <linux/of_device.h>
 +#include <linux/reset.h>
  #include <linux/spi/spi.h>
  
  #define SPI_COMMAND1                          0x000
  #define SPI_CS_SS_VAL                         (1 << 20)
  #define SPI_CS_SW_HW                          (1 << 21)
  /* SPI_CS_POL_INACTIVE bits are default high */
- #define SPI_CS_POL_INACTIVE                   22
- #define SPI_CS_POL_INACTIVE_0                 (1 << 22)
- #define SPI_CS_POL_INACTIVE_1                 (1 << 23)
- #define SPI_CS_POL_INACTIVE_2                 (1 << 24)
- #define SPI_CS_POL_INACTIVE_3                 (1 << 25)
+                                               /* n from 0 to 3 */
+ #define SPI_CS_POL_INACTIVE(n)                        (1 << (22 + (n)))
  #define SPI_CS_POL_INACTIVE_MASK              (0xF << 22)
  
  #define SPI_CS_SEL_0                          (0 << 26)
  #define MAX_HOLD_CYCLES                               16
  #define SPI_DEFAULT_SPEED                     25000000
  
- #define MAX_CHIP_SELECT                               4
- #define SPI_FIFO_DEPTH                                64
  struct tegra_spi_data {
        struct device                           *dev;
        struct spi_master                       *master;
        spinlock_t                              lock;
  
        struct clk                              *clk;
 +      struct reset_control                    *rst;
        void __iomem                            *base;
        phys_addr_t                             phys;
        unsigned                                irq;
 -      int                                     dma_req_sel;
        u32                                     spi_max_frequency;
        u32                                     cur_speed;
  
        struct spi_device                       *cur_spi;
        struct spi_device                       *cs_control;
        unsigned                                cur_pos;
-       unsigned                                cur_len;
        unsigned                                words_per_32bit;
        unsigned                                bytes_per_word;
        unsigned                                curr_dma_words;
        u32                                     rx_status;
        u32                                     status_reg;
        bool                                    is_packed;
-       unsigned long                           packed_size;
  
        u32                                     command1_reg;
        u32                                     dma_control_reg;
        u32                                     def_command1_reg;
-       u32                                     spi_cs_timing;
  
        struct completion                       xfer_completion;
        struct spi_transfer                     *curr_xfer;
  static int tegra_spi_runtime_suspend(struct device *dev);
  static int tegra_spi_runtime_resume(struct device *dev);
  
- static inline unsigned long tegra_spi_readl(struct tegra_spi_data *tspi,
+ static inline u32 tegra_spi_readl(struct tegra_spi_data *tspi,
                unsigned long reg)
  {
        return readl(tspi->base + reg);
  }
  
  static inline void tegra_spi_writel(struct tegra_spi_data *tspi,
-               unsigned long val, unsigned long reg)
+               u32 val, unsigned long reg)
  {
        writel(val, tspi->base + reg);
  
  
  static void tegra_spi_clear_status(struct tegra_spi_data *tspi)
  {
-       unsigned long val;
+       u32 val;
  
        /* Write 1 to clear status register */
        val = tegra_spi_readl(tspi, SPI_TRANS_STATUS);
@@@ -296,10 -287,9 +287,9 @@@ static unsigned tegra_spi_fill_tx_fifo_
  {
        unsigned nbytes;
        unsigned tx_empty_count;
-       unsigned long fifo_status;
+       u32 fifo_status;
        unsigned max_n_32bit;
        unsigned i, count;
-       unsigned long x;
        unsigned int written_words;
        unsigned fifo_words_left;
        u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos;
                nbytes = written_words * tspi->bytes_per_word;
                max_n_32bit = DIV_ROUND_UP(nbytes, 4);
                for (count = 0; count < max_n_32bit; count++) {
-                       x = 0;
+                       u32 x = 0;
                        for (i = 0; (i < 4) && nbytes; i++, nbytes--)
-                               x |= (*tx_buf++) << (i*8);
+                               x |= (u32)(*tx_buf++) << (i * 8);
                        tegra_spi_writel(tspi, x, SPI_TX_FIFO);
                }
        } else {
                written_words = max_n_32bit;
                nbytes = written_words * tspi->bytes_per_word;
                for (count = 0; count < max_n_32bit; count++) {
-                       x = 0;
+                       u32 x = 0;
                        for (i = 0; nbytes && (i < tspi->bytes_per_word);
                                                        i++, nbytes--)
-                               x |= ((*tx_buf++) << i*8);
+                               x |= (u32)(*tx_buf++) << (i * 8);
                        tegra_spi_writel(tspi, x, SPI_TX_FIFO);
                }
        }
@@@ -338,9 -328,8 +328,8 @@@ static unsigned int tegra_spi_read_rx_f
                struct tegra_spi_data *tspi, struct spi_transfer *t)
  {
        unsigned rx_full_count;
-       unsigned long fifo_status;
+       u32 fifo_status;
        unsigned i, count;
-       unsigned long x;
        unsigned int read_words = 0;
        unsigned len;
        u8 *rx_buf = (u8 *)t->rx_buf + tspi->cur_rx_pos;
        if (tspi->is_packed) {
                len = tspi->curr_dma_words * tspi->bytes_per_word;
                for (count = 0; count < rx_full_count; count++) {
-                       x = tegra_spi_readl(tspi, SPI_RX_FIFO);
+                       u32 x = tegra_spi_readl(tspi, SPI_RX_FIFO);
                        for (i = 0; len && (i < 4); i++, len--)
                                *rx_buf++ = (x >> i*8) & 0xFF;
                }
                tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word;
                read_words += tspi->curr_dma_words;
        } else {
-               unsigned int rx_mask;
-               unsigned int bits_per_word = t->bits_per_word;
-               rx_mask = (1 << bits_per_word) - 1;
+               u32 rx_mask = ((u32)1 << t->bits_per_word) - 1;
                for (count = 0; count < rx_full_count; count++) {
-                       x = tegra_spi_readl(tspi, SPI_RX_FIFO);
-                       x &= rx_mask;
+                       u32 x = tegra_spi_readl(tspi, SPI_RX_FIFO) & rx_mask;
                        for (i = 0; (i < tspi->bytes_per_word); i++)
                                *rx_buf++ = (x >> (i*8)) & 0xFF;
                }
  static void tegra_spi_copy_client_txbuf_to_spi_txbuf(
                struct tegra_spi_data *tspi, struct spi_transfer *t)
  {
-       unsigned len;
        /* Make the dma buffer to read by cpu */
        dma_sync_single_for_cpu(tspi->dev, tspi->tx_dma_phys,
                                tspi->dma_buf_size, DMA_TO_DEVICE);
  
        if (tspi->is_packed) {
-               len = tspi->curr_dma_words * tspi->bytes_per_word;
+               unsigned len = tspi->curr_dma_words * tspi->bytes_per_word;
                memcpy(tspi->tx_dma_buf, t->tx_buf + tspi->cur_pos, len);
        } else {
                unsigned int i;
                unsigned int count;
                u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos;
                unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word;
-               unsigned int x;
  
                for (count = 0; count < tspi->curr_dma_words; count++) {
-                       x = 0;
+                       u32 x = 0;
                        for (i = 0; consume && (i < tspi->bytes_per_word);
                                                        i++, consume--)
-                               x |= ((*tx_buf++) << i * 8);
+                               x |= (u32)(*tx_buf++) << (i * 8);
                        tspi->tx_dma_buf[count] = x;
                }
        }
  static void tegra_spi_copy_spi_rxbuf_to_client_rxbuf(
                struct tegra_spi_data *tspi, struct spi_transfer *t)
  {
-       unsigned len;
        /* Make the dma buffer to read by cpu */
        dma_sync_single_for_cpu(tspi->dev, tspi->rx_dma_phys,
                tspi->dma_buf_size, DMA_FROM_DEVICE);
  
        if (tspi->is_packed) {
-               len = tspi->curr_dma_words * tspi->bytes_per_word;
+               unsigned len = tspi->curr_dma_words * tspi->bytes_per_word;
                memcpy(t->rx_buf + tspi->cur_rx_pos, tspi->rx_dma_buf, len);
        } else {
                unsigned int i;
                unsigned int count;
                unsigned char *rx_buf = t->rx_buf + tspi->cur_rx_pos;
-               unsigned int x;
-               unsigned int rx_mask;
-               unsigned int bits_per_word = t->bits_per_word;
+               u32 rx_mask = ((u32)1 << t->bits_per_word) - 1;
  
-               rx_mask = (1 << bits_per_word) - 1;
                for (count = 0; count < tspi->curr_dma_words; count++) {
-                       x = tspi->rx_dma_buf[count];
-                       x &= rx_mask;
+                       u32 x = tspi->rx_dma_buf[count] & rx_mask;
                        for (i = 0; (i < tspi->bytes_per_word); i++)
                                *rx_buf++ = (x >> (i*8)) & 0xFF;
                }
@@@ -490,16 -466,16 +466,16 @@@ static int tegra_spi_start_rx_dma(struc
  static int tegra_spi_start_dma_based_transfer(
                struct tegra_spi_data *tspi, struct spi_transfer *t)
  {
-       unsigned long val;
+       u32 val;
        unsigned int len;
        int ret = 0;
-       unsigned long status;
+       u32 status;
  
        /* Make sure that Rx and Tx fifo are empty */
        status = tegra_spi_readl(tspi, SPI_FIFO_STATUS);
        if ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) {
-               dev_err(tspi->dev,
-                       "Rx/Tx fifo are not empty status 0x%08lx\n", status);
+               dev_err(tspi->dev, "Rx/Tx fifo are not empty status 0x%08x\n",
+                       (unsigned)status);
                return -EIO;
        }
  
  static int tegra_spi_start_cpu_based_transfer(
                struct tegra_spi_data *tspi, struct spi_transfer *t)
  {
-       unsigned long val;
+       u32 val;
        unsigned cur_words;
  
        if (tspi->cur_direction & DATA_DIR_TX)
@@@ -600,15 -576,15 +576,15 @@@ static int tegra_spi_init_dma_param(str
        dma_addr_t dma_phys;
        int ret;
        struct dma_slave_config dma_sconfig;
 -      dma_cap_mask_t mask;
 -
 -      dma_cap_zero(mask);
 -      dma_cap_set(DMA_SLAVE, mask);
 -      dma_chan = dma_request_channel(mask, NULL, NULL);
 -      if (!dma_chan) {
 -              dev_err(tspi->dev,
 -                      "Dma channel is not available, will try later\n");
 -              return -EPROBE_DEFER;
 +
 +      dma_chan = dma_request_slave_channel_reason(tspi->dev,
 +                                      dma_to_memory ? "rx" : "tx");
 +      if (IS_ERR(dma_chan)) {
 +              ret = PTR_ERR(dma_chan);
 +              if (ret != -EPROBE_DEFER)
 +                      dev_err(tspi->dev,
 +                              "Dma channel is not available: %d\n", ret);
 +              return ret;
        }
  
        dma_buf = dma_alloc_coherent(tspi->dev, tspi->dma_buf_size,
                return -ENOMEM;
        }
  
 -      dma_sconfig.slave_id = tspi->dma_req_sel;
        if (dma_to_memory) {
                dma_sconfig.src_addr = tspi->phys + SPI_RX_FIFO;
                dma_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
@@@ -676,13 -653,13 +652,13 @@@ static void tegra_spi_deinit_dma_param(
        dma_release_channel(dma_chan);
  }
  
- static unsigned long tegra_spi_setup_transfer_one(struct spi_device *spi,
+ static u32 tegra_spi_setup_transfer_one(struct spi_device *spi,
                struct spi_transfer *t, bool is_first_of_msg)
  {
        struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
        u32 speed = t->speed_hz;
        u8 bits_per_word = t->bits_per_word;
-       unsigned long command1;
+       u32 command1;
        int req_mode;
  
        if (speed != tspi->cur_speed) {
  }
  
  static int tegra_spi_start_transfer_one(struct spi_device *spi,
-               struct spi_transfer *t, unsigned long command1)
+               struct spi_transfer *t, u32 command1)
  {
        struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
        unsigned total_fifo_words;
        tegra_spi_writel(tspi, command1, SPI_COMMAND1);
        tspi->command1_reg = command1;
  
-       dev_dbg(tspi->dev, "The def 0x%x and written 0x%lx\n",
-                               tspi->def_command1_reg, command1);
+       dev_dbg(tspi->dev, "The def 0x%x and written 0x%x\n",
+               tspi->def_command1_reg, (unsigned)command1);
  
        if (total_fifo_words > SPI_FIFO_DEPTH)
                ret = tegra_spi_start_dma_based_transfer(tspi, t);
  static int tegra_spi_setup(struct spi_device *spi)
  {
        struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
-       unsigned long val;
+       u32 val;
        unsigned long flags;
        int ret;
-       unsigned int cs_pol_bit[MAX_CHIP_SELECT] = {
-                       SPI_CS_POL_INACTIVE_0,
-                       SPI_CS_POL_INACTIVE_1,
-                       SPI_CS_POL_INACTIVE_2,
-                       SPI_CS_POL_INACTIVE_3,
-       };
  
        dev_dbg(&spi->dev, "setup %d bpw, %scpol, %scpha, %dHz\n",
                spi->bits_per_word,
        spin_lock_irqsave(&tspi->lock, flags);
        val = tspi->def_command1_reg;
        if (spi->mode & SPI_CS_HIGH)
-               val &= ~cs_pol_bit[spi->chip_select];
+               val &= ~SPI_CS_POL_INACTIVE(spi->chip_select);
        else
-               val |= cs_pol_bit[spi->chip_select];
+               val |= SPI_CS_POL_INACTIVE(spi->chip_select);
        tspi->def_command1_reg = val;
        tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1);
        spin_unlock_irqrestore(&tspi->lock, flags);
@@@ -841,7 -812,7 +811,7 @@@ static int tegra_spi_transfer_one_messa
        msg->actual_length = 0;
  
        list_for_each_entry(xfer, &msg->transfers, transfer_list) {
-               unsigned long cmd1;
+               u32 cmd1;
  
                reinit_completion(&tspi->xfer_completion);
  
@@@ -917,9 -888,9 +887,9 @@@ static irqreturn_t handle_cpu_based_xfe
                        tspi->status_reg);
                dev_err(tspi->dev, "CpuXfer 0x%08x:0x%08x\n",
                        tspi->command1_reg, tspi->dma_control_reg);
 -              tegra_periph_reset_assert(tspi->clk);
 +              reset_control_assert(tspi->rst);
                udelay(2);
 -              tegra_periph_reset_deassert(tspi->clk);
 +              reset_control_deassert(tspi->rst);
                complete(&tspi->xfer_completion);
                goto exit;
        }
@@@ -989,9 -960,9 +959,9 @@@ static irqreturn_t handle_dma_based_xfe
                        tspi->status_reg);
                dev_err(tspi->dev, "DmaXfer 0x%08x:0x%08x\n",
                        tspi->command1_reg, tspi->dma_control_reg);
 -              tegra_periph_reset_assert(tspi->clk);
 +              reset_control_assert(tspi->rst);
                udelay(2);
 -              tegra_periph_reset_deassert(tspi->clk);
 +              reset_control_deassert(tspi->rst);
                complete(&tspi->xfer_completion);
                spin_unlock_irqrestore(&tspi->lock, flags);
                return IRQ_HANDLED;
@@@ -1053,6 -1024,11 +1023,6 @@@ static void tegra_spi_parse_dt(struct p
        struct tegra_spi_data *tspi)
  {
        struct device_node *np = pdev->dev.of_node;
 -      u32 of_dma[2];
 -
 -      if (of_property_read_u32_array(np, "nvidia,dma-request-selector",
 -                              of_dma, 2) >= 0)
 -              tspi->dma_req_sel = of_dma[1];
  
        if (of_property_read_u32(np, "spi-max-frequency",
                                &tspi->spi_max_frequency))
@@@ -1121,25 -1097,25 +1091,25 @@@ static int tegra_spi_probe(struct platf
                goto exit_free_irq;
        }
  
 +      tspi->rst = devm_reset_control_get(&pdev->dev, "spi");
 +      if (IS_ERR(tspi->rst)) {
 +              dev_err(&pdev->dev, "can not get reset\n");
 +              ret = PTR_ERR(tspi->rst);
 +              goto exit_free_irq;
 +      }
 +
        tspi->max_buf_size = SPI_FIFO_DEPTH << 2;
        tspi->dma_buf_size = DEFAULT_SPI_DMA_BUF_LEN;
  
 -      if (tspi->dma_req_sel) {
 -              ret = tegra_spi_init_dma_param(tspi, true);
 -              if (ret < 0) {
 -                      dev_err(&pdev->dev, "RxDma Init failed, err %d\n", ret);
 -                      goto exit_free_irq;
 -              }
 -
 -              ret = tegra_spi_init_dma_param(tspi, false);
 -              if (ret < 0) {
 -                      dev_err(&pdev->dev, "TxDma Init failed, err %d\n", ret);
 -                      goto exit_rx_dma_free;
 -              }
 -              tspi->max_buf_size = tspi->dma_buf_size;
 -              init_completion(&tspi->tx_dma_complete);
 -              init_completion(&tspi->rx_dma_complete);
 -      }
 +      ret = tegra_spi_init_dma_param(tspi, true);
 +      if (ret < 0)
 +              goto exit_free_irq;
 +      ret = tegra_spi_init_dma_param(tspi, false);
 +      if (ret < 0)
 +              goto exit_rx_dma_free;
 +      tspi->max_buf_size = tspi->dma_buf_size;
 +      init_completion(&tspi->tx_dma_complete);
 +      init_completion(&tspi->rx_dma_complete);
  
        init_completion(&tspi->xfer_completion);
  
index e6f382b338184b4cb98b5a1b40bd0964a3ff463d,af78c17388d24097bd23d8b5b99a45868d41b12a..08794977f21ae38e35186e5347d40d8bb7bdcb7d
@@@ -32,8 -32,8 +32,8 @@@
  #include <linux/pm_runtime.h>
  #include <linux/of.h>
  #include <linux/of_device.h>
 +#include <linux/reset.h>
  #include <linux/spi/spi.h>
 -#include <linux/clk/tegra.h>
  
  #define SPI_COMMAND                           0x000
  #define SPI_GO                                        BIT(30)
@@@ -118,7 -118,6 +118,7 @@@ struct tegra_sflash_data 
        spinlock_t                              lock;
  
        struct clk                              *clk;
 +      struct reset_control                    *rst;
        void __iomem                            *base;
        unsigned                                irq;
        u32                                     spi_max_frequency;
  static int tegra_sflash_runtime_suspend(struct device *dev);
  static int tegra_sflash_runtime_resume(struct device *dev);
  
- static inline unsigned long tegra_sflash_readl(struct tegra_sflash_data *tsd,
+ static inline u32 tegra_sflash_readl(struct tegra_sflash_data *tsd,
                unsigned long reg)
  {
        return readl(tsd->base + reg);
  }
  
  static inline void tegra_sflash_writel(struct tegra_sflash_data *tsd,
-               unsigned long val, unsigned long reg)
+               u32 val, unsigned long reg)
  {
        writel(val, tsd->base + reg);
  }
@@@ -186,7 -185,7 +186,7 @@@ static unsigned tegra_sflash_fill_tx_fi
        struct tegra_sflash_data *tsd, struct spi_transfer *t)
  {
        unsigned nbytes;
-       unsigned long status;
+       u32 status;
        unsigned max_n_32bit = tsd->curr_xfer_words;
        u8 *tx_buf = (u8 *)t->tx_buf + tsd->cur_tx_pos;
  
        status = tegra_sflash_readl(tsd, SPI_STATUS);
        while (!(status & SPI_TXF_FULL)) {
                int i;
-               unsigned int x = 0;
+               u32 x = 0;
  
                for (i = 0; nbytes && (i < tsd->bytes_per_word);
                                                        i++, nbytes--)
-                               x |= ((*tx_buf++) << i*8);
+                       x |= (u32)(*tx_buf++) << (i * 8);
                tegra_sflash_writel(tsd, x, SPI_TX_FIFO);
                if (!nbytes)
                        break;
  static int tegra_sflash_read_rx_fifo_to_client_rxbuf(
                struct tegra_sflash_data *tsd, struct spi_transfer *t)
  {
-       unsigned long status;
+       u32 status;
        unsigned int read_words = 0;
        u8 *rx_buf = (u8 *)t->rx_buf + tsd->cur_rx_pos;
  
        status = tegra_sflash_readl(tsd, SPI_STATUS);
        while (!(status & SPI_RXF_EMPTY)) {
                int i;
-               unsigned long x;
-               x = tegra_sflash_readl(tsd, SPI_RX_FIFO);
+               u32 x = tegra_sflash_readl(tsd, SPI_RX_FIFO);
                for (i = 0; (i < tsd->bytes_per_word); i++)
                        *rx_buf++ = (x >> (i*8)) & 0xFF;
                read_words++;
  static int tegra_sflash_start_cpu_based_transfer(
                struct tegra_sflash_data *tsd, struct spi_transfer *t)
  {
-       unsigned long val = 0;
+       u32 val = 0;
        unsigned cur_words;
  
        if (tsd->cur_direction & DATA_DIR_TX)
@@@ -267,7 -264,7 +265,7 @@@ static int tegra_sflash_start_transfer_
  {
        struct tegra_sflash_data *tsd = spi_master_get_devdata(spi->master);
        u32 speed;
-       unsigned long command;
+       u32 command;
  
        speed = t->speed_hz;
        if (speed != tsd->cur_speed) {
        tegra_sflash_writel(tsd, command, SPI_COMMAND);
        tsd->command_reg = command;
  
-       return  tegra_sflash_start_cpu_based_transfer(tsd, t);
+       return tegra_sflash_start_cpu_based_transfer(tsd, t);
  }
  
  static int tegra_sflash_setup(struct spi_device *spi)
@@@ -390,9 -387,9 +388,9 @@@ static irqreturn_t handle_cpu_based_xfe
                dev_err(tsd->dev,
                        "CpuXfer 0x%08x:0x%08x\n", tsd->command_reg,
                                tsd->dma_control_reg);
 -              tegra_periph_reset_assert(tsd->clk);
 +              reset_control_assert(tsd->rst);
                udelay(2);
 -              tegra_periph_reset_deassert(tsd->clk);
 +              reset_control_deassert(tsd->rst);
                complete(&tsd->xfer_completion);
                goto exit;
        }
@@@ -506,13 -503,6 +504,13 @@@ static int tegra_sflash_probe(struct pl
                goto exit_free_irq;
        }
  
 +      tsd->rst = devm_reset_control_get(&pdev->dev, "spi");
 +      if (IS_ERR(tsd->rst)) {
 +              dev_err(&pdev->dev, "can not get reset\n");
 +              ret = PTR_ERR(tsd->rst);
 +              goto exit_free_irq;
 +      }
 +
        init_completion(&tsd->xfer_completion);
        pm_runtime_enable(&pdev->dev);
        if (!pm_runtime_enabled(&pdev->dev)) {
        }
  
        /* Reset controller */
 -      tegra_periph_reset_assert(tsd->clk);
 +      reset_control_assert(tsd->rst);
        udelay(2);
 -      tegra_periph_reset_deassert(tsd->clk);
 +      reset_control_deassert(tsd->rst);
  
        tsd->def_command_reg  = SPI_M_S | SPI_CS_SW;
        tegra_sflash_writel(tsd, tsd->def_command_reg, SPI_COMMAND);
index a728bb82090fa5a956b68eca4f5c613c346a2a5f,3ce1de8872f0ad3e34445d7fd58ae50a2f9c4609..be3a069879c3d42bfb482771bc83733318c2273d
@@@ -33,8 -33,8 +33,8 @@@
  #include <linux/pm_runtime.h>
  #include <linux/of.h>
  #include <linux/of_device.h>
 +#include <linux/reset.h>
  #include <linux/spi/spi.h>
 -#include <linux/clk/tegra.h>
  
  #define SLINK_COMMAND                 0x000
  #define SLINK_BIT_LENGTH(x)           (((x) & 0x1f) << 0)
@@@ -167,10 -167,10 +167,10 @@@ struct tegra_slink_data 
        spinlock_t                              lock;
  
        struct clk                              *clk;
 +      struct reset_control                    *rst;
        void __iomem                            *base;
        phys_addr_t                             phys;
        unsigned                                irq;
 -      int                                     dma_req_sel;
        u32                                     spi_max_frequency;
        u32                                     cur_speed;
  
        u32                                     rx_status;
        u32                                     status_reg;
        bool                                    is_packed;
-       unsigned long                           packed_size;
+       u32                                     packed_size;
  
        u32                                     command_reg;
        u32                                     command2_reg;
  static int tegra_slink_runtime_suspend(struct device *dev);
  static int tegra_slink_runtime_resume(struct device *dev);
  
- static inline unsigned long tegra_slink_readl(struct tegra_slink_data *tspi,
+ static inline u32 tegra_slink_readl(struct tegra_slink_data *tspi,
                unsigned long reg)
  {
        return readl(tspi->base + reg);
  }
  
  static inline void tegra_slink_writel(struct tegra_slink_data *tspi,
-               unsigned long val, unsigned long reg)
+               u32 val, unsigned long reg)
  {
        writel(val, tspi->base + reg);
  
  
  static void tegra_slink_clear_status(struct tegra_slink_data *tspi)
  {
-       unsigned long val;
-       unsigned long val_write = 0;
+       u32 val_write;
  
-       val = tegra_slink_readl(tspi, SLINK_STATUS);
+       tegra_slink_readl(tspi, SLINK_STATUS);
  
        /* Write 1 to clear status register */
        val_write = SLINK_RDY | SLINK_FIFO_ERROR;
        tegra_slink_writel(tspi, val_write, SLINK_STATUS);
  }
  
- static unsigned long tegra_slink_get_packed_size(struct tegra_slink_data *tspi,
+ static u32 tegra_slink_get_packed_size(struct tegra_slink_data *tspi,
                                  struct spi_transfer *t)
  {
-       unsigned long val;
        switch (tspi->bytes_per_word) {
        case 0:
-               val = SLINK_PACK_SIZE_4;
-               break;
+               return SLINK_PACK_SIZE_4;
        case 1:
-               val = SLINK_PACK_SIZE_8;
-               break;
+               return SLINK_PACK_SIZE_8;
        case 2:
-               val = SLINK_PACK_SIZE_16;
-               break;
+               return SLINK_PACK_SIZE_16;
        case 4:
-               val = SLINK_PACK_SIZE_32;
-               break;
+               return SLINK_PACK_SIZE_32;
        default:
-               val = 0;
+               return 0;
        }
-       return val;
  }
  
  static unsigned tegra_slink_calculate_curr_xfer_param(
@@@ -312,10 -304,9 +304,9 @@@ static unsigned tegra_slink_fill_tx_fif
  {
        unsigned nbytes;
        unsigned tx_empty_count;
-       unsigned long fifo_status;
+       u32 fifo_status;
        unsigned max_n_32bit;
        unsigned i, count;
-       unsigned long x;
        unsigned int written_words;
        unsigned fifo_words_left;
        u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos;
                nbytes = written_words * tspi->bytes_per_word;
                max_n_32bit = DIV_ROUND_UP(nbytes, 4);
                for (count = 0; count < max_n_32bit; count++) {
-                       x = 0;
+                       u32 x = 0;
                        for (i = 0; (i < 4) && nbytes; i++, nbytes--)
-                               x |= (*tx_buf++) << (i*8);
+                               x |= (u32)(*tx_buf++) << (i * 8);
                        tegra_slink_writel(tspi, x, SLINK_TX_FIFO);
                }
        } else {
                written_words = max_n_32bit;
                nbytes = written_words * tspi->bytes_per_word;
                for (count = 0; count < max_n_32bit; count++) {
-                       x = 0;
+                       u32 x = 0;
                        for (i = 0; nbytes && (i < tspi->bytes_per_word);
                                                        i++, nbytes--)
-                               x |= ((*tx_buf++) << i*8);
+                               x |= (u32)(*tx_buf++) << (i * 8);
                        tegra_slink_writel(tspi, x, SLINK_TX_FIFO);
                }
        }
@@@ -354,9 -345,8 +345,8 @@@ static unsigned int tegra_slink_read_rx
                struct tegra_slink_data *tspi, struct spi_transfer *t)
  {
        unsigned rx_full_count;
-       unsigned long fifo_status;
+       u32 fifo_status;
        unsigned i, count;
-       unsigned long x;
        unsigned int read_words = 0;
        unsigned len;
        u8 *rx_buf = (u8 *)t->rx_buf + tspi->cur_rx_pos;
        if (tspi->is_packed) {
                len = tspi->curr_dma_words * tspi->bytes_per_word;
                for (count = 0; count < rx_full_count; count++) {
-                       x = tegra_slink_readl(tspi, SLINK_RX_FIFO);
+                       u32 x = tegra_slink_readl(tspi, SLINK_RX_FIFO);
                        for (i = 0; len && (i < 4); i++, len--)
                                *rx_buf++ = (x >> i*8) & 0xFF;
                }
                read_words += tspi->curr_dma_words;
        } else {
                for (count = 0; count < rx_full_count; count++) {
-                       x = tegra_slink_readl(tspi, SLINK_RX_FIFO);
+                       u32 x = tegra_slink_readl(tspi, SLINK_RX_FIFO);
                        for (i = 0; (i < tspi->bytes_per_word); i++)
                                *rx_buf++ = (x >> (i*8)) & 0xFF;
                }
  static void tegra_slink_copy_client_txbuf_to_spi_txbuf(
                struct tegra_slink_data *tspi, struct spi_transfer *t)
  {
-       unsigned len;
        /* Make the dma buffer to read by cpu */
        dma_sync_single_for_cpu(tspi->dev, tspi->tx_dma_phys,
                                tspi->dma_buf_size, DMA_TO_DEVICE);
  
        if (tspi->is_packed) {
-               len = tspi->curr_dma_words * tspi->bytes_per_word;
+               unsigned len = tspi->curr_dma_words * tspi->bytes_per_word;
                memcpy(tspi->tx_dma_buf, t->tx_buf + tspi->cur_pos, len);
        } else {
                unsigned int i;
                unsigned int count;
                u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos;
                unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word;
-               unsigned int x;
  
                for (count = 0; count < tspi->curr_dma_words; count++) {
-                       x = 0;
+                       u32 x = 0;
                        for (i = 0; consume && (i < tspi->bytes_per_word);
                                                        i++, consume--)
-                               x |= ((*tx_buf++) << i * 8);
+                               x |= (u32)(*tx_buf++) << (i * 8);
                        tspi->tx_dma_buf[count] = x;
                }
        }
@@@ -434,14 -421,10 +421,10 @@@ static void tegra_slink_copy_spi_rxbuf_
                unsigned int i;
                unsigned int count;
                unsigned char *rx_buf = t->rx_buf + tspi->cur_rx_pos;
-               unsigned int x;
-               unsigned int rx_mask, bits_per_word;
+               u32 rx_mask = ((u32)1 << t->bits_per_word) - 1;
  
-               bits_per_word = t->bits_per_word;
-               rx_mask = (1 << bits_per_word) - 1;
                for (count = 0; count < tspi->curr_dma_words; count++) {
-                       x = tspi->rx_dma_buf[count];
-                       x &= rx_mask;
+                       u32 x = tspi->rx_dma_buf[count] & rx_mask;
                        for (i = 0; (i < tspi->bytes_per_word); i++)
                                *rx_buf++ = (x >> (i*8)) & 0xFF;
                }
@@@ -501,17 -484,16 +484,16 @@@ static int tegra_slink_start_rx_dma(str
  static int tegra_slink_start_dma_based_transfer(
                struct tegra_slink_data *tspi, struct spi_transfer *t)
  {
-       unsigned long val;
-       unsigned long test_val;
+       u32 val;
        unsigned int len;
        int ret = 0;
-       unsigned long status;
+       u32 status;
  
        /* Make sure that Rx and Tx fifo are empty */
        status = tegra_slink_readl(tspi, SLINK_STATUS);
        if ((status & SLINK_FIFO_EMPTY) != SLINK_FIFO_EMPTY) {
-               dev_err(tspi->dev,
-                       "Rx/Tx fifo are not empty status 0x%08lx\n", status);
+               dev_err(tspi->dev, "Rx/Tx fifo are not empty status 0x%08x\n",
+                       (unsigned)status);
                return -EIO;
        }
  
                }
  
                /* Wait for tx fifo to be fill before starting slink */
-               test_val = tegra_slink_readl(tspi, SLINK_STATUS);
-               while (!(test_val & SLINK_TX_FULL))
-                       test_val = tegra_slink_readl(tspi, SLINK_STATUS);
+               status = tegra_slink_readl(tspi, SLINK_STATUS);
+               while (!(status & SLINK_TX_FULL))
+                       status = tegra_slink_readl(tspi, SLINK_STATUS);
        }
  
        if (tspi->cur_direction & DATA_DIR_RX) {
  static int tegra_slink_start_cpu_based_transfer(
                struct tegra_slink_data *tspi, struct spi_transfer *t)
  {
-       unsigned long val;
+       u32 val;
        unsigned cur_words;
  
        val = tspi->packed_size;
@@@ -629,15 -611,15 +611,15 @@@ static int tegra_slink_init_dma_param(s
        dma_addr_t dma_phys;
        int ret;
        struct dma_slave_config dma_sconfig;
 -      dma_cap_mask_t mask;
  
 -      dma_cap_zero(mask);
 -      dma_cap_set(DMA_SLAVE, mask);
 -      dma_chan = dma_request_channel(mask, NULL, NULL);
 -      if (!dma_chan) {
 -              dev_err(tspi->dev,
 -                      "Dma channel is not available, will try later\n");
 -              return -EPROBE_DEFER;
 +      dma_chan = dma_request_slave_channel_reason(tspi->dev,
 +                                              dma_to_memory ? "rx" : "tx");
 +      if (IS_ERR(dma_chan)) {
 +              ret = PTR_ERR(dma_chan);
 +              if (ret != -EPROBE_DEFER)
 +                      dev_err(tspi->dev,
 +                              "Dma channel is not available: %d\n", ret);
 +              return ret;
        }
  
        dma_buf = dma_alloc_coherent(tspi->dev, tspi->dma_buf_size,
                return -ENOMEM;
        }
  
 -      dma_sconfig.slave_id = tspi->dma_req_sel;
        if (dma_to_memory) {
                dma_sconfig.src_addr = tspi->phys + SLINK_RX_FIFO;
                dma_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
@@@ -713,8 -696,8 +695,8 @@@ static int tegra_slink_start_transfer_o
        u8 bits_per_word;
        unsigned total_fifo_words;
        int ret;
-       unsigned long command;
-       unsigned long command2;
+       u32 command;
+       u32 command2;
  
        bits_per_word = t->bits_per_word;
        speed = t->speed_hz;
  
  static int tegra_slink_setup(struct spi_device *spi)
  {
-       struct tegra_slink_data *tspi = spi_master_get_devdata(spi->master);
-       unsigned long val;
-       unsigned long flags;
-       int ret;
-       unsigned int cs_pol_bit[MAX_CHIP_SELECT] = {
+       static const u32 cs_pol_bit[MAX_CHIP_SELECT] = {
                        SLINK_CS_POLARITY,
                        SLINK_CS_POLARITY1,
                        SLINK_CS_POLARITY2,
                        SLINK_CS_POLARITY3,
        };
  
+       struct tegra_slink_data *tspi = spi_master_get_devdata(spi->master);
+       u32 val;
+       unsigned long flags;
+       int ret;
        dev_dbg(&spi->dev, "setup %d bpw, %scpol, %scpha, %dHz\n",
                spi->bits_per_word,
                spi->mode & SPI_CPOL ? "" : "~",
@@@ -883,9 -867,9 +866,9 @@@ static irqreturn_t handle_cpu_based_xfe
                dev_err(tspi->dev,
                        "CpuXfer 0x%08x:0x%08x:0x%08x\n", tspi->command_reg,
                                tspi->command2_reg, tspi->dma_control_reg);
 -              tegra_periph_reset_assert(tspi->clk);
 +              reset_control_assert(tspi->rst);
                udelay(2);
 -              tegra_periph_reset_deassert(tspi->clk);
 +              reset_control_deassert(tspi->rst);
                complete(&tspi->xfer_completion);
                goto exit;
        }
@@@ -956,9 -940,9 +939,9 @@@ static irqreturn_t handle_dma_based_xfe
                dev_err(tspi->dev,
                        "DmaXfer 0x%08x:0x%08x:0x%08x\n", tspi->command_reg,
                                tspi->command2_reg, tspi->dma_control_reg);
 -              tegra_periph_reset_assert(tspi->clk);
 +              reset_control_assert(tspi->rst);
                udelay(2);
 -              tegra_periph_reset_deassert(tspi->clk);
 +              reset_control_assert(tspi->rst);
                complete(&tspi->xfer_completion);
                spin_unlock_irqrestore(&tspi->lock, flags);
                return IRQ_HANDLED;
@@@ -1019,6 -1003,11 +1002,6 @@@ static irqreturn_t tegra_slink_isr(int 
  static void tegra_slink_parse_dt(struct tegra_slink_data *tspi)
  {
        struct device_node *np = tspi->dev->of_node;
 -      u32 of_dma[2];
 -
 -      if (of_property_read_u32_array(np, "nvidia,dma-request-selector",
 -                              of_dma, 2) >= 0)
 -              tspi->dma_req_sel = of_dma[1];
  
        if (of_property_read_u32(np, "spi-max-frequency",
                                        &tspi->spi_max_frequency))
@@@ -1112,25 -1101,25 +1095,25 @@@ static int tegra_slink_probe(struct pla
                goto exit_free_irq;
        }
  
 +      tspi->rst = devm_reset_control_get(&pdev->dev, "spi");
 +      if (IS_ERR(tspi->rst)) {
 +              dev_err(&pdev->dev, "can not get reset\n");
 +              ret = PTR_ERR(tspi->rst);
 +              goto exit_free_irq;
 +      }
 +
        tspi->max_buf_size = SLINK_FIFO_DEPTH << 2;
        tspi->dma_buf_size = DEFAULT_SPI_DMA_BUF_LEN;
  
 -      if (tspi->dma_req_sel) {
 -              ret = tegra_slink_init_dma_param(tspi, true);
 -              if (ret < 0) {
 -                      dev_err(&pdev->dev, "RxDma Init failed, err %d\n", ret);
 -                      goto exit_free_irq;
 -              }
 -
 -              ret = tegra_slink_init_dma_param(tspi, false);
 -              if (ret < 0) {
 -                      dev_err(&pdev->dev, "TxDma Init failed, err %d\n", ret);
 -                      goto exit_rx_dma_free;
 -              }
 -              tspi->max_buf_size = tspi->dma_buf_size;
 -              init_completion(&tspi->tx_dma_complete);
 -              init_completion(&tspi->rx_dma_complete);
 -      }
 +      ret = tegra_slink_init_dma_param(tspi, true);
 +      if (ret < 0)
 +              goto exit_free_irq;
 +      ret = tegra_slink_init_dma_param(tspi, false);
 +      if (ret < 0)
 +              goto exit_rx_dma_free;
 +      tspi->max_buf_size = tspi->dma_buf_size;
 +      init_completion(&tspi->tx_dma_complete);
 +      init_completion(&tspi->rx_dma_complete);
  
        init_completion(&tspi->xfer_completion);
  
diff --combined drivers/spi/spi.c
index 827ff49d3d4f4133e0e46fc27d5e628f339fcc37,63613a96233c3f1eddc77846affea03ffe92a852..23756b0f90363c2f776718925cf7fba84d13c4a3
@@@ -58,11 -58,6 +58,11 @@@ static ssize_
  modalias_show(struct device *dev, struct device_attribute *a, char *buf)
  {
        const struct spi_device *spi = to_spi_device(dev);
 +      int len;
 +
 +      len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1);
 +      if (len != -ENODEV)
 +              return len;
  
        return sprintf(buf, "%s%s\n", SPI_MODULE_PREFIX, spi->modalias);
  }
@@@ -119,11 -114,6 +119,11 @@@ static int spi_match_device(struct devi
  static int spi_uevent(struct device *dev, struct kobj_uevent_env *env)
  {
        const struct spi_device         *spi = to_spi_device(dev);
 +      int rc;
 +
 +      rc = acpi_device_uevent_modalias(dev, env);
 +      if (rc != -ENODEV)
 +              return rc;
  
        add_uevent_var(env, "MODALIAS=%s%s", SPI_MODULE_PREFIX, spi->modalias);
        return 0;
@@@ -380,6 -370,17 +380,17 @@@ static void spi_dev_set_name(struct spi
                     spi->chip_select);
  }
  
+ static int spi_dev_check(struct device *dev, void *data)
+ {
+       struct spi_device *spi = to_spi_device(dev);
+       struct spi_device *new_spi = data;
+       if (spi->master == new_spi->master &&
+           spi->chip_select == new_spi->chip_select)
+               return -EBUSY;
+       return 0;
+ }
  /**
   * spi_add_device - Add spi_device allocated with spi_alloc_device
   * @spi: spi_device to register
@@@ -394,7 -395,6 +405,6 @@@ int spi_add_device(struct spi_device *s
        static DEFINE_MUTEX(spi_add_lock);
        struct spi_master *master = spi->master;
        struct device *dev = master->dev.parent;
-       struct device *d;
        int status;
  
        /* Chipselects are numbered 0..max; validate. */
         */
        mutex_lock(&spi_add_lock);
  
-       d = bus_find_device_by_name(&spi_bus_type, NULL, dev_name(&spi->dev));
-       if (d != NULL) {
+       status = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check);
+       if (status) {
                dev_err(dev, "chipselect %d already in use\n",
                                spi->chip_select);
-               put_device(d);
-               status = -EBUSY;
                goto done;
        }
  
@@@ -601,8 -599,10 +609,10 @@@ static int spi_transfer_one_message(str
                        goto out;
                }
  
-               if (ret > 0)
+               if (ret > 0) {
+                       ret = 0;
                        wait_for_completion(&master->xfer_completion);
+               }
  
                trace_spi_transfer_stop(msg, xfer);
  
@@@ -642,7 -642,7 +652,7 @@@ out
   *
   * Called by SPI drivers using the core transfer_one_message()
   * implementation to notify it that the current interrupt driven
-  * transfer has finised and the next one may be scheduled.
+  * transfer has finished and the next one may be scheduled.
   */
  void spi_finalize_current_transfer(struct spi_master *master)
  {
@@@ -695,7 -695,7 +705,7 @@@ static void spi_pump_messages(struct kt
        }
        /* Extract head of queue */
        master->cur_msg =
-           list_entry(master->queue.next, struct spi_message, queue);
+               list_first_entry(&master->queue, struct spi_message, queue);
  
        list_del_init(&master->cur_msg->queue);
        if (master->busy)
        ret = master->transfer_one_message(master, master->cur_msg);
        if (ret) {
                dev_err(&master->dev,
-                       "failed to transfer one message from queue\n");
+                       "failed to transfer one message from queue: %d\n", ret);
+               master->cur_msg->status = ret;
+               spi_finalize_current_message(master);
                return;
        }
  }
@@@ -801,11 -803,8 +813,8 @@@ struct spi_message *spi_get_next_queued
  
        /* get a pointer to the next message, if any */
        spin_lock_irqsave(&master->queue_lock, flags);
-       if (list_empty(&master->queue))
-               next = NULL;
-       else
-               next = list_entry(master->queue.next,
-                                 struct spi_message, queue);
+       next = list_first_entry_or_null(&master->queue, struct spi_message,
+                                       queue);
        spin_unlock_irqrestore(&master->queue_lock, flags);
  
        return next;
@@@ -1606,15 -1605,11 +1615,11 @@@ int spi_setup(struct spi_device *spi
  }
  EXPORT_SYMBOL_GPL(spi_setup);
  
- static int __spi_async(struct spi_device *spi, struct spi_message *message)
+ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
  {
        struct spi_master *master = spi->master;
        struct spi_transfer *xfer;
  
-       message->spi = spi;
-       trace_spi_message_submit(message);
        if (list_empty(&message->transfers))
                return -EINVAL;
        if (!message->complete)
                if (xfer->rx_buf && !xfer->rx_nbits)
                        xfer->rx_nbits = SPI_NBITS_SINGLE;
                /* check transfer tx/rx_nbits:
-                * 1. keep the value is not out of single, dual and quad
-                * 2. keep tx/rx_nbits is contained by mode in spi_device
-                * 3. if SPI_3WIRE, tx/rx_nbits should be in single
+                * 1. check the value matches one of single, dual and quad
+                * 2. check tx/rx_nbits match the mode in spi_device
                 */
                if (xfer->tx_buf) {
                        if (xfer->tx_nbits != SPI_NBITS_SINGLE &&
                        if ((xfer->tx_nbits == SPI_NBITS_QUAD) &&
                                !(spi->mode & SPI_TX_QUAD))
                                return -EINVAL;
-                       if ((spi->mode & SPI_3WIRE) &&
-                               (xfer->tx_nbits != SPI_NBITS_SINGLE))
-                               return -EINVAL;
                }
                /* check transfer rx_nbits */
                if (xfer->rx_buf) {
                        if ((xfer->rx_nbits == SPI_NBITS_QUAD) &&
                                !(spi->mode & SPI_RX_QUAD))
                                return -EINVAL;
-                       if ((spi->mode & SPI_3WIRE) &&
-                               (xfer->rx_nbits != SPI_NBITS_SINGLE))
-                               return -EINVAL;
                }
        }
  
        message->status = -EINPROGRESS;
+       return 0;
+ }
+ static int __spi_async(struct spi_device *spi, struct spi_message *message)
+ {
+       struct spi_master *master = spi->master;
+       message->spi = spi;
+       trace_spi_message_submit(message);
        return master->transfer(spi, message);
  }
  
@@@ -1753,6 -1753,10 +1763,10 @@@ int spi_async(struct spi_device *spi, s
        int ret;
        unsigned long flags;
  
+       ret = __spi_validate(spi, message);
+       if (ret != 0)
+               return ret;
        spin_lock_irqsave(&master->bus_lock_spinlock, flags);
  
        if (master->bus_lock_flag)
@@@ -1801,6 -1805,10 +1815,10 @@@ int spi_async_locked(struct spi_device 
        int ret;
        unsigned long flags;
  
+       ret = __spi_validate(spi, message);
+       if (ret != 0)
+               return ret;
        spin_lock_irqsave(&master->bus_lock_spinlock, flags);
  
        ret = __spi_async(spi, message);