Merge branch 'next-spi' of git://git.secretlab.ca/git/linux-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 17 Dec 2009 23:59:05 +0000 (15:59 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 17 Dec 2009 23:59:05 +0000 (15:59 -0800)
* 'next-spi' of git://git.secretlab.ca/git/linux-2.6:
  spi: spi_txx9.c: use resource_size()
  spi: spi_sh_sci.c: use resource_size()
  spi: spi_mpc8xxx.c: use resource_size()
  spi: spi_bfin5xx.c: use resource_size()
  spi: atmel_spi.c: use resource_size()
  spi: Add s3c64xx SPI Controller driver
  atmel_spi: fix dma addr calculation for len > BUFFER_SIZE
  spi_s3c24xx: add FIQ pseudo-DMA support
  spi: controller driver for Designware SPI core
  spidev: add proper section markers
  spidev: use DECLARE_BITMAP instead of declaring the array

1  2 
drivers/spi/Kconfig
drivers/spi/spi_mpc8xxx.c
drivers/spi/spi_s3c24xx.c
drivers/spi/spi_txx9.c
drivers/spi/spidev.c

diff --combined drivers/spi/Kconfig
@@@ -155,6 -155,9 +155,6 @@@ config SPI_MPC8xx
          This enables using the Freescale MPC8xxx SPI controllers in master
          mode.
  
 -        This driver uses a simple set of shift registers for data (opposed
 -        to the CPM based descriptor model).
 -
  config SPI_OMAP_UWIRE
        tristate "OMAP1 MicroWire"
        depends on ARCH_OMAP1
@@@ -216,6 -219,17 +216,17 @@@ config SPI_S3C24X
        help
          SPI driver for Samsung S3C24XX series ARM SoCs
  
+ config SPI_S3C24XX_FIQ
+       bool "S3C24XX driver with FIQ pseudo-DMA"
+       depends on SPI_S3C24XX
+       select FIQ
+       help
+         Enable FIQ support for the S3C24XX SPI driver to provide pseudo
+         DMA by using the fast-interrupt request framework, This allows
+         the driver to get DMA-like performance when there are either
+         no free DMA channels, or when doing transfers that required both
+         TX and RX data paths.
  config SPI_S3C24XX_GPIO
        tristate "Samsung S3C24XX series SPI by GPIO"
        depends on ARCH_S3C2410 && EXPERIMENTAL
          the inbuilt hardware cannot provide the transfer mode, or
          where the board is using non hardware connected pins.
  
+ config SPI_S3C64XX
+       tristate "Samsung S3C64XX series type SPI"
+       depends on ARCH_S3C64XX && EXPERIMENTAL
+       select S3C64XX_DMA
+       help
+         SPI driver for Samsung S3C64XX and newer SoCs.
  config SPI_SH_MSIOF
        tristate "SuperH MSIOF SPI controller"
        depends on SUPERH && HAVE_CLK
@@@ -289,6 -310,16 +307,16 @@@ config SPI_NUC90
  # Add new SPI master controllers in alphabetical order above this line
  #
  
+ config SPI_DESIGNWARE
+       bool "DesignWare SPI controller core support"
+       depends on SPI_MASTER
+       help
+         general driver for SPI controller core from DesignWare
+ config SPI_DW_PCI
+       tristate "PCI interface driver for DW SPI core"
+       depends on SPI_DESIGNWARE && PCI
  #
  # There are lots of SPI device types, with sensors and memory
  # being probably the most widely used ones.
@@@ -5,10 -5,6 +5,10 @@@
   *
   * Copyright (C) 2006 Polycom, Inc.
   *
 + * CPM SPI and QE buffer descriptors mode support:
 + * Copyright (c) 2009  MontaVista Software, Inc.
 + * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
 + *
   * This program is free software; you can redistribute  it and/or modify it
   * under  the terms of  the GNU General  Public License as published by the
   * Free Software Foundation;  either version 2 of the  License, or (at your
@@@ -31,9 -27,6 +31,9 @@@
  #include <linux/spi/spi_bitbang.h>
  #include <linux/platform_device.h>
  #include <linux/fsl_devices.h>
 +#include <linux/dma-mapping.h>
 +#include <linux/mm.h>
 +#include <linux/mutex.h>
  #include <linux/of.h>
  #include <linux/of_platform.h>
  #include <linux/gpio.h>
  #include <linux/of_spi.h>
  
  #include <sysdev/fsl_soc.h>
 +#include <asm/cpm.h>
 +#include <asm/qe.h>
  #include <asm/irq.h>
  
 +/* CPM1 and CPM2 are mutually exclusive. */
 +#ifdef CONFIG_CPM1
 +#include <asm/cpm1.h>
 +#define CPM_SPI_CMD mk_cr_cmd(CPM_CR_CH_SPI, 0)
 +#else
 +#include <asm/cpm2.h>
 +#define CPM_SPI_CMD mk_cr_cmd(CPM_CR_SPI_PAGE, CPM_CR_SPI_SBLOCK, 0, 0)
 +#endif
 +
  /* SPI Controller registers */
  struct mpc8xxx_spi_reg {
        u8 res1[0x20];
        __be32 receive;
  };
  
 +/* SPI Parameter RAM */
 +struct spi_pram {
 +      __be16  rbase;  /* Rx Buffer descriptor base address */
 +      __be16  tbase;  /* Tx Buffer descriptor base address */
 +      u8      rfcr;   /* Rx function code */
 +      u8      tfcr;   /* Tx function code */
 +      __be16  mrblr;  /* Max receive buffer length */
 +      __be32  rstate; /* Internal */
 +      __be32  rdp;    /* Internal */
 +      __be16  rbptr;  /* Internal */
 +      __be16  rbc;    /* Internal */
 +      __be32  rxtmp;  /* Internal */
 +      __be32  tstate; /* Internal */
 +      __be32  tdp;    /* Internal */
 +      __be16  tbptr;  /* Internal */
 +      __be16  tbc;    /* Internal */
 +      __be32  txtmp;  /* Internal */
 +      __be32  res;    /* Tx temp. */
 +      __be16  rpbase; /* Relocation pointer (CPM1 only) */
 +      __be16  res1;   /* Reserved */
 +};
 +
  /* SPI Controller mode register definitions */
  #define       SPMODE_LOOP             (1 << 30)
  #define       SPMODE_CI_INACTIVEHIGH  (1 << 29)
  #define       SPIM_NE         0x00000200      /* Not empty */
  #define       SPIM_NF         0x00000100      /* Not full */
  
 +#define       SPIE_TXB        0x00000200      /* Last char is written to tx fifo */
 +#define       SPIE_RXB        0x00000100      /* Last char is written to rx buf */
 +
 +/* SPCOM register values */
 +#define       SPCOM_STR       (1 << 23)       /* Start transmit */
 +
 +#define       SPI_PRAM_SIZE   0x100
 +#define       SPI_MRBLR       ((unsigned int)PAGE_SIZE)
 +
  /* SPI Controller driver's private data. */
  struct mpc8xxx_spi {
 +      struct device *dev;
        struct mpc8xxx_spi_reg __iomem *base;
  
        /* rx & tx bufs from the spi_transfer */
        const void *tx;
        void *rx;
  
 +      int subblock;
 +      struct spi_pram __iomem *pram;
 +      struct cpm_buf_desc __iomem *tx_bd;
 +      struct cpm_buf_desc __iomem *rx_bd;
 +
 +      struct spi_transfer *xfer_in_progress;
 +
 +      /* dma addresses for CPM transfers */
 +      dma_addr_t tx_dma;
 +      dma_addr_t rx_dma;
 +      bool map_tx_dma;
 +      bool map_rx_dma;
 +
 +      dma_addr_t dma_dummy_tx;
 +      dma_addr_t dma_dummy_rx;
 +
        /* functions to deal with different sized buffers */
        void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
        u32(*get_tx) (struct mpc8xxx_spi *);
        u32 rx_shift;           /* RX data reg shift when in qe mode */
        u32 tx_shift;           /* TX data reg shift when in qe mode */
  
 -      bool qe_mode;
 +      unsigned int flags;
  
        struct workqueue_struct *workqueue;
        struct work_struct work;
        struct completion done;
  };
  
 +static void *mpc8xxx_dummy_rx;
 +static DEFINE_MUTEX(mpc8xxx_dummy_rx_lock);
 +static int mpc8xxx_dummy_rx_refcnt;
 +
  struct spi_mpc8xxx_cs {
        /* functions to deal with different sized buffers */
        void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
@@@ -225,42 -155,6 +225,42 @@@ MPC83XX_SPI_TX_BUF(u8
  MPC83XX_SPI_TX_BUF(u16)
  MPC83XX_SPI_TX_BUF(u32)
  
 +static void mpc8xxx_spi_change_mode(struct spi_device *spi)
 +{
 +      struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
 +      struct spi_mpc8xxx_cs *cs = spi->controller_state;
 +      __be32 __iomem *mode = &mspi->base->mode;
 +      unsigned long flags;
 +
 +      if (cs->hw_mode == mpc8xxx_spi_read_reg(mode))
 +              return;
 +
 +      /* Turn off IRQs locally to minimize time that SPI is disabled. */
 +      local_irq_save(flags);
 +
 +      /* Turn off SPI unit prior changing mode */
 +      mpc8xxx_spi_write_reg(mode, cs->hw_mode & ~SPMODE_ENABLE);
 +      mpc8xxx_spi_write_reg(mode, cs->hw_mode);
 +
 +      /* When in CPM mode, we need to reinit tx and rx. */
 +      if (mspi->flags & SPI_CPM_MODE) {
 +              if (mspi->flags & SPI_QE) {
 +                      qe_issue_cmd(QE_INIT_TX_RX, mspi->subblock,
 +                                   QE_CR_PROTOCOL_UNSPECIFIED, 0);
 +              } else {
 +                      cpm_command(CPM_SPI_CMD, CPM_CR_INIT_TRX);
 +                      if (mspi->flags & SPI_CPM1) {
 +                              out_be16(&mspi->pram->rbptr,
 +                                       in_be16(&mspi->pram->rbase));
 +                              out_be16(&mspi->pram->tbptr,
 +                                       in_be16(&mspi->pram->tbase));
 +                      }
 +              }
 +      }
 +
 +      local_irq_restore(flags);
 +}
 +
  static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value)
  {
        struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
        }
  
        if (value == BITBANG_CS_ACTIVE) {
 -              u32 regval = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode);
 -
                mpc8xxx_spi->rx_shift = cs->rx_shift;
                mpc8xxx_spi->tx_shift = cs->tx_shift;
                mpc8xxx_spi->get_rx = cs->get_rx;
                mpc8xxx_spi->get_tx = cs->get_tx;
  
 -              if (cs->hw_mode != regval) {
 -                      unsigned long flags;
 -                      __be32 __iomem *mode = &mpc8xxx_spi->base->mode;
 -
 -                      regval = cs->hw_mode;
 -                      /* Turn off IRQs locally to minimize time that
 -                       * SPI is disabled
 -                       */
 -                      local_irq_save(flags);
 -                      /* Turn off SPI unit prior changing mode */
 -                      mpc8xxx_spi_write_reg(mode, regval & ~SPMODE_ENABLE);
 -                      mpc8xxx_spi_write_reg(mode, regval);
 -                      local_irq_restore(flags);
 -              }
 +              mpc8xxx_spi_change_mode(spi);
 +
                if (pdata->cs_control)
                        pdata->cs_control(spi, pol);
        }
@@@ -290,6 -198,7 +290,6 @@@ stati
  int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
  {
        struct mpc8xxx_spi *mpc8xxx_spi;
 -      u32 regval;
        u8 bits_per_word, pm;
        u32 hz;
        struct spi_mpc8xxx_cs   *cs = spi->controller_state;
        if (bits_per_word <= 8) {
                cs->get_rx = mpc8xxx_spi_rx_buf_u8;
                cs->get_tx = mpc8xxx_spi_tx_buf_u8;
 -              if (mpc8xxx_spi->qe_mode) {
 +              if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
                        cs->rx_shift = 16;
                        cs->tx_shift = 24;
                }
        } else if (bits_per_word <= 16) {
                cs->get_rx = mpc8xxx_spi_rx_buf_u16;
                cs->get_tx = mpc8xxx_spi_tx_buf_u16;
 -              if (mpc8xxx_spi->qe_mode) {
 +              if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
                        cs->rx_shift = 16;
                        cs->tx_shift = 16;
                }
        } else
                return -EINVAL;
  
 -      if (mpc8xxx_spi->qe_mode && spi->mode & SPI_LSB_FIRST) {
 +      if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE &&
 +                      spi->mode & SPI_LSB_FIRST) {
                cs->tx_shift = 0;
                if (bits_per_word <= 8)
                        cs->rx_shift = 8;
                pm--;
  
        cs->hw_mode |= SPMODE_PM(pm);
 -      regval =  mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode);
 -      if (cs->hw_mode != regval) {
 -              unsigned long flags;
 -              __be32 __iomem *mode = &mpc8xxx_spi->base->mode;
 -
 -              regval = cs->hw_mode;
 -              /* Turn off IRQs locally to minimize time
 -               * that SPI is disabled
 -               */
 -              local_irq_save(flags);
 -              /* Turn off SPI unit prior changing mode */
 -              mpc8xxx_spi_write_reg(mode, regval & ~SPMODE_ENABLE);
 -              mpc8xxx_spi_write_reg(mode, regval);
 -              local_irq_restore(flags);
 +
 +      mpc8xxx_spi_change_mode(spi);
 +      return 0;
 +}
 +
 +static void mpc8xxx_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi)
 +{
 +      struct cpm_buf_desc __iomem *tx_bd = mspi->tx_bd;
 +      struct cpm_buf_desc __iomem *rx_bd = mspi->rx_bd;
 +      unsigned int xfer_len = min(mspi->count, SPI_MRBLR);
 +      unsigned int xfer_ofs;
 +
 +      xfer_ofs = mspi->xfer_in_progress->len - mspi->count;
 +
 +      out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma + xfer_ofs);
 +      out_be16(&rx_bd->cbd_datlen, 0);
 +      out_be16(&rx_bd->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT | BD_SC_WRAP);
 +
 +      out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma + xfer_ofs);
 +      out_be16(&tx_bd->cbd_datlen, xfer_len);
 +      out_be16(&tx_bd->cbd_sc, BD_SC_READY | BD_SC_INTRPT | BD_SC_WRAP |
 +                               BD_SC_LAST);
 +
 +      /* start transfer */
 +      mpc8xxx_spi_write_reg(&mspi->base->command, SPCOM_STR);
 +}
 +
 +static int mpc8xxx_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
 +                              struct spi_transfer *t, bool is_dma_mapped)
 +{
 +      struct device *dev = mspi->dev;
 +
 +      if (is_dma_mapped) {
 +              mspi->map_tx_dma = 0;
 +              mspi->map_rx_dma = 0;
 +      } else {
 +              mspi->map_tx_dma = 1;
 +              mspi->map_rx_dma = 1;
 +      }
 +
 +      if (!t->tx_buf) {
 +              mspi->tx_dma = mspi->dma_dummy_tx;
 +              mspi->map_tx_dma = 0;
 +      }
 +
 +      if (!t->rx_buf) {
 +              mspi->rx_dma = mspi->dma_dummy_rx;
 +              mspi->map_rx_dma = 0;
 +      }
 +
 +      if (mspi->map_tx_dma) {
 +              void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */
 +
 +              mspi->tx_dma = dma_map_single(dev, nonconst_tx, t->len,
 +                                            DMA_TO_DEVICE);
 +              if (dma_mapping_error(dev, mspi->tx_dma)) {
 +                      dev_err(dev, "unable to map tx dma\n");
 +                      return -ENOMEM;
 +              }
 +      } else {
 +              mspi->tx_dma = t->tx_dma;
 +      }
 +
 +      if (mspi->map_rx_dma) {
 +              mspi->rx_dma = dma_map_single(dev, mspi->rx, t->len,
 +                                            DMA_FROM_DEVICE);
 +              if (dma_mapping_error(dev, mspi->rx_dma)) {
 +                      dev_err(dev, "unable to map rx dma\n");
 +                      goto err_rx_dma;
 +              }
 +      } else {
 +              mspi->rx_dma = t->rx_dma;
        }
 +
 +      /* enable rx ints */
 +      mpc8xxx_spi_write_reg(&mspi->base->mask, SPIE_RXB);
 +
 +      mspi->xfer_in_progress = t;
 +      mspi->count = t->len;
 +
 +      /* start CPM transfers */
 +      mpc8xxx_spi_cpm_bufs_start(mspi);
 +
        return 0;
 +
 +err_rx_dma:
 +      if (mspi->map_tx_dma)
 +              dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE);
 +      return -ENOMEM;
  }
  
 -static int mpc8xxx_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 +static void mpc8xxx_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi)
  {
 -      struct mpc8xxx_spi *mpc8xxx_spi;
 -      u32 word, len, bits_per_word;
 +      struct device *dev = mspi->dev;
 +      struct spi_transfer *t = mspi->xfer_in_progress;
 +
 +      if (mspi->map_tx_dma)
 +              dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE);
 +      if (mspi->map_tx_dma)
 +              dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE);
 +      mspi->xfer_in_progress = NULL;
 +}
  
 -      mpc8xxx_spi = spi_master_get_devdata(spi->master);
 +static int mpc8xxx_spi_cpu_bufs(struct mpc8xxx_spi *mspi,
 +                              struct spi_transfer *t, unsigned int len)
 +{
 +      u32 word;
 +
 +      mspi->count = len;
 +
 +      /* enable rx ints */
 +      mpc8xxx_spi_write_reg(&mspi->base->mask, SPIM_NE);
 +
 +      /* transmit word */
 +      word = mspi->get_tx(mspi);
 +      mpc8xxx_spi_write_reg(&mspi->base->transmit, word);
 +
 +      return 0;
 +}
 +
 +static int mpc8xxx_spi_bufs(struct spi_device *spi, struct spi_transfer *t,
 +                          bool is_dma_mapped)
 +{
 +      struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
 +      unsigned int len = t->len;
 +      u8 bits_per_word;
 +      int ret;
  
 -      mpc8xxx_spi->tx = t->tx_buf;
 -      mpc8xxx_spi->rx = t->rx_buf;
        bits_per_word = spi->bits_per_word;
        if (t->bits_per_word)
                bits_per_word = t->bits_per_word;
 -      len = t->len;
 +
        if (bits_per_word > 8) {
                /* invalid length? */
                if (len & 1)
                        return -EINVAL;
                len /= 2;
        }
 -      mpc8xxx_spi->count = len;
  
 -      INIT_COMPLETION(mpc8xxx_spi->done);
 +      mpc8xxx_spi->tx = t->tx_buf;
 +      mpc8xxx_spi->rx = t->rx_buf;
  
 -      /* enable rx ints */
 -      mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, SPIM_NE);
 +      INIT_COMPLETION(mpc8xxx_spi->done);
  
 -      /* transmit word */
 -      word = mpc8xxx_spi->get_tx(mpc8xxx_spi);
 -      mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->transmit, word);
 +      if (mpc8xxx_spi->flags & SPI_CPM_MODE)
 +              ret = mpc8xxx_spi_cpm_bufs(mpc8xxx_spi, t, is_dma_mapped);
 +      else
 +              ret = mpc8xxx_spi_cpu_bufs(mpc8xxx_spi, t, len);
 +      if (ret)
 +              return ret;
  
        wait_for_completion(&mpc8xxx_spi->done);
  
        /* disable rx ints */
        mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, 0);
  
 +      if (mpc8xxx_spi->flags & SPI_CPM_MODE)
 +              mpc8xxx_spi_cpm_bufs_complete(mpc8xxx_spi);
 +
        return mpc8xxx_spi->count;
  }
  
@@@ -573,7 -375,7 +573,7 @@@ static void mpc8xxx_spi_do_one_msg(stru
                }
                cs_change = t->cs_change;
                if (t->len)
 -                      status = mpc8xxx_spi_bufs(spi, t);
 +                      status = mpc8xxx_spi_bufs(spi, t, m->is_dma_mapped);
                if (status) {
                        status = -EMSGSIZE;
                        break;
@@@ -662,80 -464,45 +662,80 @@@ static int mpc8xxx_spi_setup(struct spi
        return 0;
  }
  
 -static irqreturn_t mpc8xxx_spi_irq(s32 irq, void *context_data)
 +static void mpc8xxx_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events)
  {
 -      struct mpc8xxx_spi *mpc8xxx_spi = context_data;
 -      u32 event;
 -      irqreturn_t ret = IRQ_NONE;
 +      u16 len;
  
 -      /* Get interrupt events(tx/rx) */
 -      event = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->event);
 +      dev_dbg(mspi->dev, "%s: bd datlen %d, count %d\n", __func__,
 +              in_be16(&mspi->rx_bd->cbd_datlen), mspi->count);
  
 -      /* We need handle RX first */
 -      if (event & SPIE_NE) {
 -              u32 rx_data = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->receive);
 +      len = in_be16(&mspi->rx_bd->cbd_datlen);
 +      if (len > mspi->count) {
 +              WARN_ON(1);
 +              len = mspi->count;
 +      }
  
 -              if (mpc8xxx_spi->rx)
 -                      mpc8xxx_spi->get_rx(rx_data, mpc8xxx_spi);
 +      /* Clear the events */
 +      mpc8xxx_spi_write_reg(&mspi->base->event, events);
  
 -              ret = IRQ_HANDLED;
 +      mspi->count -= len;
 +      if (mspi->count)
 +              mpc8xxx_spi_cpm_bufs_start(mspi);
 +      else
 +              complete(&mspi->done);
 +}
 +
 +static void mpc8xxx_spi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
 +{
 +      /* We need handle RX first */
 +      if (events & SPIE_NE) {
 +              u32 rx_data = mpc8xxx_spi_read_reg(&mspi->base->receive);
 +
 +              if (mspi->rx)
 +                      mspi->get_rx(rx_data, mspi);
        }
  
 -      if ((event & SPIE_NF) == 0)
 +      if ((events & SPIE_NF) == 0)
                /* spin until TX is done */
 -              while (((event =
 -                       mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->event)) &
 +              while (((events =
 +                      mpc8xxx_spi_read_reg(&mspi->base->event)) &
                                                SPIE_NF) == 0)
                        cpu_relax();
  
 -      mpc8xxx_spi->count -= 1;
 -      if (mpc8xxx_spi->count) {
 -              u32 word = mpc8xxx_spi->get_tx(mpc8xxx_spi);
 -              mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->transmit, word);
 +      /* Clear the events */
 +      mpc8xxx_spi_write_reg(&mspi->base->event, events);
 +
 +      mspi->count -= 1;
 +      if (mspi->count) {
 +              u32 word = mspi->get_tx(mspi);
 +
 +              mpc8xxx_spi_write_reg(&mspi->base->transmit, word);
        } else {
 -              complete(&mpc8xxx_spi->done);
 +              complete(&mspi->done);
        }
 +}
  
 -      /* Clear the events */
 -      mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->event, event);
 +static irqreturn_t mpc8xxx_spi_irq(s32 irq, void *context_data)
 +{
 +      struct mpc8xxx_spi *mspi = context_data;
 +      irqreturn_t ret = IRQ_NONE;
 +      u32 events;
 +
 +      /* Get interrupt events(tx/rx) */
 +      events = mpc8xxx_spi_read_reg(&mspi->base->event);
 +      if (events)
 +              ret = IRQ_HANDLED;
 +
 +      dev_dbg(mspi->dev, "%s: events %x\n", __func__, events);
 +
 +      if (mspi->flags & SPI_CPM_MODE)
 +              mpc8xxx_spi_cpm_irq(mspi, events);
 +      else
 +              mpc8xxx_spi_cpu_irq(mspi, events);
  
        return ret;
  }
 +
  static int mpc8xxx_spi_transfer(struct spi_device *spi,
                                struct spi_message *m)
  {
@@@ -759,215 -526,6 +759,215 @@@ static void mpc8xxx_spi_cleanup(struct 
        kfree(spi->controller_state);
  }
  
 +static void *mpc8xxx_spi_alloc_dummy_rx(void)
 +{
 +      mutex_lock(&mpc8xxx_dummy_rx_lock);
 +
 +      if (!mpc8xxx_dummy_rx)
 +              mpc8xxx_dummy_rx = kmalloc(SPI_MRBLR, GFP_KERNEL);
 +      if (mpc8xxx_dummy_rx)
 +              mpc8xxx_dummy_rx_refcnt++;
 +
 +      mutex_unlock(&mpc8xxx_dummy_rx_lock);
 +
 +      return mpc8xxx_dummy_rx;
 +}
 +
 +static void mpc8xxx_spi_free_dummy_rx(void)
 +{
 +      mutex_lock(&mpc8xxx_dummy_rx_lock);
 +
 +      switch (mpc8xxx_dummy_rx_refcnt) {
 +      case 0:
 +              WARN_ON(1);
 +              break;
 +      case 1:
 +              kfree(mpc8xxx_dummy_rx);
 +              mpc8xxx_dummy_rx = NULL;
 +              /* fall through */
 +      default:
 +              mpc8xxx_dummy_rx_refcnt--;
 +              break;
 +      }
 +
 +      mutex_unlock(&mpc8xxx_dummy_rx_lock);
 +}
 +
 +static unsigned long mpc8xxx_spi_cpm_get_pram(struct mpc8xxx_spi *mspi)
 +{
 +      struct device *dev = mspi->dev;
 +      struct device_node *np = dev_archdata_get_node(&dev->archdata);
 +      const u32 *iprop;
 +      int size;
 +      unsigned long spi_base_ofs;
 +      unsigned long pram_ofs = -ENOMEM;
 +
 +      /* Can't use of_address_to_resource(), QE muram isn't at 0. */
 +      iprop = of_get_property(np, "reg", &size);
 +
 +      /* QE with a fixed pram location? */
 +      if (mspi->flags & SPI_QE && iprop && size == sizeof(*iprop) * 4)
 +              return cpm_muram_alloc_fixed(iprop[2], SPI_PRAM_SIZE);
 +
 +      /* QE but with a dynamic pram location? */
 +      if (mspi->flags & SPI_QE) {
 +              pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64);
 +              qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, mspi->subblock,
 +                              QE_CR_PROTOCOL_UNSPECIFIED, pram_ofs);
 +              return pram_ofs;
 +      }
 +
 +      /* CPM1 and CPM2 pram must be at a fixed addr. */
 +      if (!iprop || size != sizeof(*iprop) * 4)
 +              return -ENOMEM;
 +
 +      spi_base_ofs = cpm_muram_alloc_fixed(iprop[2], 2);
 +      if (IS_ERR_VALUE(spi_base_ofs))
 +              return -ENOMEM;
 +
 +      if (mspi->flags & SPI_CPM2) {
 +              pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64);
 +              if (!IS_ERR_VALUE(pram_ofs)) {
 +                      u16 __iomem *spi_base = cpm_muram_addr(spi_base_ofs);
 +
 +                      out_be16(spi_base, pram_ofs);
 +              }
 +      } else {
 +              struct spi_pram __iomem *pram = cpm_muram_addr(spi_base_ofs);
 +              u16 rpbase = in_be16(&pram->rpbase);
 +
 +              /* Microcode relocation patch applied? */
 +              if (rpbase)
 +                      pram_ofs = rpbase;
 +              else
 +                      return spi_base_ofs;
 +      }
 +
 +      cpm_muram_free(spi_base_ofs);
 +      return pram_ofs;
 +}
 +
 +static int mpc8xxx_spi_cpm_init(struct mpc8xxx_spi *mspi)
 +{
 +      struct device *dev = mspi->dev;
 +      struct device_node *np = dev_archdata_get_node(&dev->archdata);
 +      const u32 *iprop;
 +      int size;
 +      unsigned long pram_ofs;
 +      unsigned long bds_ofs;
 +
 +      if (!(mspi->flags & SPI_CPM_MODE))
 +              return 0;
 +
 +      if (!mpc8xxx_spi_alloc_dummy_rx())
 +              return -ENOMEM;
 +
 +      if (mspi->flags & SPI_QE) {
 +              iprop = of_get_property(np, "cell-index", &size);
 +              if (iprop && size == sizeof(*iprop))
 +                      mspi->subblock = *iprop;
 +
 +              switch (mspi->subblock) {
 +              default:
 +                      dev_warn(dev, "cell-index unspecified, assuming SPI1");
 +                      /* fall through */
 +              case 0:
 +                      mspi->subblock = QE_CR_SUBBLOCK_SPI1;
 +                      break;
 +              case 1:
 +                      mspi->subblock = QE_CR_SUBBLOCK_SPI2;
 +                      break;
 +              }
 +      }
 +
 +      pram_ofs = mpc8xxx_spi_cpm_get_pram(mspi);
 +      if (IS_ERR_VALUE(pram_ofs)) {
 +              dev_err(dev, "can't allocate spi parameter ram\n");
 +              goto err_pram;
 +      }
 +
 +      bds_ofs = cpm_muram_alloc(sizeof(*mspi->tx_bd) +
 +                                sizeof(*mspi->rx_bd), 8);
 +      if (IS_ERR_VALUE(bds_ofs)) {
 +              dev_err(dev, "can't allocate bds\n");
 +              goto err_bds;
 +      }
 +
 +      mspi->dma_dummy_tx = dma_map_single(dev, empty_zero_page, PAGE_SIZE,
 +                                          DMA_TO_DEVICE);
 +      if (dma_mapping_error(dev, mspi->dma_dummy_tx)) {
 +              dev_err(dev, "unable to map dummy tx buffer\n");
 +              goto err_dummy_tx;
 +      }
 +
 +      mspi->dma_dummy_rx = dma_map_single(dev, mpc8xxx_dummy_rx, SPI_MRBLR,
 +                                          DMA_FROM_DEVICE);
 +      if (dma_mapping_error(dev, mspi->dma_dummy_rx)) {
 +              dev_err(dev, "unable to map dummy rx buffer\n");
 +              goto err_dummy_rx;
 +      }
 +
 +      mspi->pram = cpm_muram_addr(pram_ofs);
 +
 +      mspi->tx_bd = cpm_muram_addr(bds_ofs);
 +      mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd));
 +
 +      /* Initialize parameter ram. */
 +      out_be16(&mspi->pram->tbase, cpm_muram_offset(mspi->tx_bd));
 +      out_be16(&mspi->pram->rbase, cpm_muram_offset(mspi->rx_bd));
 +      out_8(&mspi->pram->tfcr, CPMFCR_EB | CPMFCR_GBL);
 +      out_8(&mspi->pram->rfcr, CPMFCR_EB | CPMFCR_GBL);
 +      out_be16(&mspi->pram->mrblr, SPI_MRBLR);
 +      out_be32(&mspi->pram->rstate, 0);
 +      out_be32(&mspi->pram->rdp, 0);
 +      out_be16(&mspi->pram->rbptr, 0);
 +      out_be16(&mspi->pram->rbc, 0);
 +      out_be32(&mspi->pram->rxtmp, 0);
 +      out_be32(&mspi->pram->tstate, 0);
 +      out_be32(&mspi->pram->tdp, 0);
 +      out_be16(&mspi->pram->tbptr, 0);
 +      out_be16(&mspi->pram->tbc, 0);
 +      out_be32(&mspi->pram->txtmp, 0);
 +
 +      return 0;
 +
 +err_dummy_rx:
 +      dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE);
 +err_dummy_tx:
 +      cpm_muram_free(bds_ofs);
 +err_bds:
 +      cpm_muram_free(pram_ofs);
 +err_pram:
 +      mpc8xxx_spi_free_dummy_rx();
 +      return -ENOMEM;
 +}
 +
 +static void mpc8xxx_spi_cpm_free(struct mpc8xxx_spi *mspi)
 +{
 +      struct device *dev = mspi->dev;
 +
 +      dma_unmap_single(dev, mspi->dma_dummy_rx, SPI_MRBLR, DMA_FROM_DEVICE);
 +      dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE);
 +      cpm_muram_free(cpm_muram_offset(mspi->tx_bd));
 +      cpm_muram_free(cpm_muram_offset(mspi->pram));
 +      mpc8xxx_spi_free_dummy_rx();
 +}
 +
 +static const char *mpc8xxx_spi_strmode(unsigned int flags)
 +{
 +      if (flags & SPI_QE_CPU_MODE) {
 +              return "QE CPU";
 +      } else if (flags & SPI_CPM_MODE) {
 +              if (flags & SPI_QE)
 +                      return "QE";
 +              else if (flags & SPI_CPM2)
 +                      return "CPM2";
 +              else
 +                      return "CPM1";
 +      }
 +      return "CPU";
 +}
 +
  static struct spi_master * __devinit
  mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
  {
        master->cleanup = mpc8xxx_spi_cleanup;
  
        mpc8xxx_spi = spi_master_get_devdata(master);
 -      mpc8xxx_spi->qe_mode = pdata->qe_mode;
 +      mpc8xxx_spi->dev = dev;
        mpc8xxx_spi->get_rx = mpc8xxx_spi_rx_buf_u8;
        mpc8xxx_spi->get_tx = mpc8xxx_spi_tx_buf_u8;
 +      mpc8xxx_spi->flags = pdata->flags;
        mpc8xxx_spi->spibrg = pdata->sysclk;
  
 +      ret = mpc8xxx_spi_cpm_init(mpc8xxx_spi);
 +      if (ret)
 +              goto err_cpm_init;
 +
        mpc8xxx_spi->rx_shift = 0;
        mpc8xxx_spi->tx_shift = 0;
 -      if (mpc8xxx_spi->qe_mode) {
 +      if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
                mpc8xxx_spi->rx_shift = 16;
                mpc8xxx_spi->tx_shift = 24;
        }
  
        init_completion(&mpc8xxx_spi->done);
  
-       mpc8xxx_spi->base = ioremap(mem->start, mem->end - mem->start + 1);
+       mpc8xxx_spi->base = ioremap(mem->start, resource_size(mem));
        if (mpc8xxx_spi->base == NULL) {
                ret = -ENOMEM;
 -              goto put_master;
 +              goto err_ioremap;
        }
  
        mpc8xxx_spi->irq = irq;
  
        /* Enable SPI interface */
        regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE;
 -      if (pdata->qe_mode)
 +      if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE)
                regval |= SPMODE_OP;
  
        mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mode, regval);
        if (ret < 0)
                goto unreg_master;
  
 -      printk(KERN_INFO
 -             "%s: MPC8xxx SPI Controller driver at 0x%p (irq = %d)\n",
 -             dev_name(dev), mpc8xxx_spi->base, mpc8xxx_spi->irq);
 +      dev_info(dev, "at 0x%p (irq = %d), %s mode\n", mpc8xxx_spi->base,
 +               mpc8xxx_spi->irq, mpc8xxx_spi_strmode(mpc8xxx_spi->flags));
  
        return master;
  
@@@ -1070,9 -624,7 +1070,9 @@@ free_irq
        free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
  unmap_io:
        iounmap(mpc8xxx_spi->base);
 -put_master:
 +err_ioremap:
 +      mpc8xxx_spi_cpm_free(mpc8xxx_spi);
 +err_cpm_init:
        spi_master_put(master);
  err:
        return ERR_PTR(ret);
@@@ -1092,7 -644,6 +1092,7 @@@ static int __devexit mpc8xxx_spi_remove
  
        free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
        iounmap(mpc8xxx_spi->base);
 +      mpc8xxx_spi_cpm_free(mpc8xxx_spi);
  
        return 0;
  }
@@@ -1158,7 -709,6 +1158,7 @@@ static int of_mpc8xxx_spi_get_chipselec
                gpio = of_get_gpio_flags(np, i, &flags);
                if (!gpio_is_valid(gpio)) {
                        dev_err(dev, "invalid gpio #%d: %d\n", i, gpio);
 +                      ret = gpio;
                        goto err_loop;
                }
  
@@@ -1254,13 -804,7 +1254,13 @@@ static int __devinit of_mpc8xxx_spi_pro
  
        prop = of_get_property(np, "mode", NULL);
        if (prop && !strcmp(prop, "cpu-qe"))
 -              pdata->qe_mode = 1;
 +              pdata->flags = SPI_QE_CPU_MODE;
 +      else if (prop && !strcmp(prop, "qe"))
 +              pdata->flags = SPI_CPM_MODE | SPI_QE;
 +      else if (of_device_is_compatible(np, "fsl,cpm2-spi"))
 +              pdata->flags = SPI_CPM_MODE | SPI_CPM2;
 +      else if (of_device_is_compatible(np, "fsl,cpm1-spi"))
 +              pdata->flags = SPI_CPM_MODE | SPI_CPM1;
  
        ret = of_mpc8xxx_spi_get_chipselects(dev);
        if (ret)
@@@ -1,7 -1,7 +1,7 @@@
  /* linux/drivers/spi/spi_s3c24xx.c
   *
   * Copyright (c) 2006 Ben Dooks
-  * Copyright (c) 2006 Simtec Electronics
+  * Copyright 2006-2009 Simtec Electronics
   *    Ben Dooks <ben@simtec.co.uk>
   *
   * This program is free software; you can redistribute it and/or modify
  #include <plat/regs-spi.h>
  #include <mach/spi.h>
  
+ #include <plat/fiq.h>
+ #include <asm/fiq.h>
+ #include "spi_s3c24xx_fiq.h"
  /**
   * s3c24xx_spi_devstate - per device data
   * @hz: Last frequency calculated for @sppre field.
@@@ -42,6 -47,13 +47,13 @@@ struct s3c24xx_spi_devstate 
        u8              sppre;
  };
  
+ enum spi_fiq_mode {
+       FIQ_MODE_NONE   = 0,
+       FIQ_MODE_TX     = 1,
+       FIQ_MODE_RX     = 2,
+       FIQ_MODE_TXRX   = 3,
+ };
  struct s3c24xx_spi {
        /* bitbang has to be first */
        struct spi_bitbang       bitbang;
        int                      len;
        int                      count;
  
+       struct fiq_handler       fiq_handler;
+       enum spi_fiq_mode        fiq_mode;
+       unsigned char            fiq_inuse;
+       unsigned char            fiq_claimed;
        void                    (*set_cs)(struct s3c2410_spi_info *spi,
                                          int cs, int pol);
  
@@@ -67,6 -84,7 +84,7 @@@
        struct s3c2410_spi_info *pdata;
  };
  
  #define SPCON_DEFAULT (S3C2410_SPCON_MSTR | S3C2410_SPCON_SMOD_INT)
  #define SPPIN_DEFAULT (S3C2410_SPPIN_KEEP)
  
@@@ -127,7 -145,7 +145,7 @@@ static int s3c24xx_spi_update_state(str
        }
  
        if (spi->mode != cs->mode) {
-               u8 spcon = SPCON_DEFAULT;
+               u8 spcon = SPCON_DEFAULT | S3C2410_SPCON_ENSCK;
  
                if (spi->mode & SPI_CPHA)
                        spcon |= S3C2410_SPCON_CPHA_FMTB;
@@@ -214,13 -232,196 +232,196 @@@ static inline unsigned int hw_txbyte(st
        return hw->tx ? hw->tx[count] : 0;
  }
  
+ #ifdef CONFIG_SPI_S3C24XX_FIQ
+ /* Support for FIQ based pseudo-DMA to improve the transfer speed.
+  *
+  * This code uses the assembly helper in spi_s3c24xx_spi.S which is
+  * used by the FIQ core to move data between main memory and the peripheral
+  * block. Since this is code running on the processor, there is no problem
+  * with cache coherency of the buffers, so we can use any buffer we like.
+  */
+ /**
+  * struct spi_fiq_code - FIQ code and header
+  * @length: The length of the code fragment, excluding this header.
+  * @ack_offset: The offset from @data to the word to place the IRQ ACK bit at.
+  * @data: The code itself to install as a FIQ handler.
+  */
+ struct spi_fiq_code {
+       u32     length;
+       u32     ack_offset;
+       u8      data[0];
+ };
+ extern struct spi_fiq_code s3c24xx_spi_fiq_txrx;
+ extern struct spi_fiq_code s3c24xx_spi_fiq_tx;
+ extern struct spi_fiq_code s3c24xx_spi_fiq_rx;
+ /**
+  * ack_bit - turn IRQ into IRQ acknowledgement bit
+  * @irq: The interrupt number
+  *
+  * Returns the bit to write to the interrupt acknowledge register.
+  */
+ static inline u32 ack_bit(unsigned int irq)
+ {
+       return 1 << (irq - IRQ_EINT0);
+ }
+ /**
+  * s3c24xx_spi_tryfiq - attempt to claim and setup FIQ for transfer
+  * @hw: The hardware state.
+  *
+  * Claim the FIQ handler (only one can be active at any one time) and
+  * then setup the correct transfer code for this transfer.
+  *
+  * This call updates all the necessary state information if sucessful,
+  * so the caller does not need to do anything more than start the transfer
+  * as normal, since the IRQ will have been re-routed to the FIQ handler.
+ */
+ void s3c24xx_spi_tryfiq(struct s3c24xx_spi *hw)
+ {
+       struct pt_regs regs;
+       enum spi_fiq_mode mode;
+       struct spi_fiq_code *code;
+       int ret;
+       if (!hw->fiq_claimed) {
+               /* try and claim fiq if we haven't got it, and if not
+                * then return and simply use another transfer method */
+               ret = claim_fiq(&hw->fiq_handler);
+               if (ret)
+                       return;
+       }
+       if (hw->tx && !hw->rx)
+               mode = FIQ_MODE_TX;
+       else if (hw->rx && !hw->tx)
+               mode = FIQ_MODE_RX;
+       else
+               mode = FIQ_MODE_TXRX;
+       regs.uregs[fiq_rspi] = (long)hw->regs;
+       regs.uregs[fiq_rrx]  = (long)hw->rx;
+       regs.uregs[fiq_rtx]  = (long)hw->tx + 1;
+       regs.uregs[fiq_rcount] = hw->len - 1;
+       regs.uregs[fiq_rirq] = (long)S3C24XX_VA_IRQ;
+       set_fiq_regs(&regs);
+       if (hw->fiq_mode != mode) {
+               u32 *ack_ptr;
+               hw->fiq_mode = mode;
+               switch (mode) {
+               case FIQ_MODE_TX:
+                       code = &s3c24xx_spi_fiq_tx;
+                       break;
+               case FIQ_MODE_RX:
+                       code = &s3c24xx_spi_fiq_rx;
+                       break;
+               case FIQ_MODE_TXRX:
+                       code = &s3c24xx_spi_fiq_txrx;
+                       break;
+               default:
+                       code = NULL;
+               }
+               BUG_ON(!code);
+               ack_ptr = (u32 *)&code->data[code->ack_offset];
+               *ack_ptr = ack_bit(hw->irq);
+               set_fiq_handler(&code->data, code->length);
+       }
+       s3c24xx_set_fiq(hw->irq, true);
+       hw->fiq_mode = mode;
+       hw->fiq_inuse = 1;
+ }
+ /**
+  * s3c24xx_spi_fiqop - FIQ core code callback
+  * @pw: Data registered with the handler
+  * @release: Whether this is a release or a return.
+  *
+  * Called by the FIQ code when another module wants to use the FIQ, so
+  * return whether we are currently using this or not and then update our
+  * internal state.
+  */
+ static int s3c24xx_spi_fiqop(void *pw, int release)
+ {
+       struct s3c24xx_spi *hw = pw;
+       int ret = 0;
+       if (release) {
+               if (hw->fiq_inuse)
+                       ret = -EBUSY;
+               /* note, we do not need to unroute the FIQ, as the FIQ
+                * vector code de-routes it to signal the end of transfer */
+               hw->fiq_mode = FIQ_MODE_NONE;
+               hw->fiq_claimed = 0;
+       } else {
+               hw->fiq_claimed = 1;
+       }
+       return ret;
+ }
+ /**
+  * s3c24xx_spi_initfiq - setup the information for the FIQ core
+  * @hw: The hardware state.
+  *
+  * Setup the fiq_handler block to pass to the FIQ core.
+  */
+ static inline void s3c24xx_spi_initfiq(struct s3c24xx_spi *hw)
+ {
+       hw->fiq_handler.dev_id = hw;
+       hw->fiq_handler.name = dev_name(hw->dev);
+       hw->fiq_handler.fiq_op = s3c24xx_spi_fiqop;
+ }
+ /**
+  * s3c24xx_spi_usefiq - return if we should be using FIQ.
+  * @hw: The hardware state.
+  *
+  * Return true if the platform data specifies whether this channel is
+  * allowed to use the FIQ.
+  */
+ static inline bool s3c24xx_spi_usefiq(struct s3c24xx_spi *hw)
+ {
+       return hw->pdata->use_fiq;
+ }
+ /**
+  * s3c24xx_spi_usingfiq - return if channel is using FIQ
+  * @spi: The hardware state.
+  *
+  * Return whether the channel is currently using the FIQ (separate from
+  * whether the FIQ is claimed).
+  */
+ static inline bool s3c24xx_spi_usingfiq(struct s3c24xx_spi *spi)
+ {
+       return spi->fiq_inuse;
+ }
+ #else
+ static inline void s3c24xx_spi_initfiq(struct s3c24xx_spi *s) { }
+ static inline void s3c24xx_spi_tryfiq(struct s3c24xx_spi *s) { }
+ static inline bool s3c24xx_spi_usefiq(struct s3c24xx_spi *s) { return false; }
+ static inline bool s3c24xx_spi_usingfiq(struct s3c24xx_spi *s) { return false; }
+ #endif /* CONFIG_SPI_S3C24XX_FIQ */
  static int s3c24xx_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
  {
        struct s3c24xx_spi *hw = to_hw(spi);
  
-       dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n",
-               t->tx_buf, t->rx_buf, t->len);
        hw->tx = t->tx_buf;
        hw->rx = t->rx_buf;
        hw->len = t->len;
  
        init_completion(&hw->done);
  
+       hw->fiq_inuse = 0;
+       if (s3c24xx_spi_usefiq(hw) && t->len >= 3)
+               s3c24xx_spi_tryfiq(hw);
        /* send the first byte */
        writeb(hw_txbyte(hw, 0), hw->regs + S3C2410_SPTDAT);
  
        wait_for_completion(&hw->done);
        return hw->count;
  }
  
@@@ -254,17 -458,27 +458,27 @@@ static irqreturn_t s3c24xx_spi_irq(int 
                goto irq_done;
        }
  
-       hw->count++;
+       if (!s3c24xx_spi_usingfiq(hw)) {
+               hw->count++;
  
-       if (hw->rx)
-               hw->rx[count] = readb(hw->regs + S3C2410_SPRDAT);
+               if (hw->rx)
+                       hw->rx[count] = readb(hw->regs + S3C2410_SPRDAT);
  
-       count++;
+               count++;
+               if (count < hw->len)
+                       writeb(hw_txbyte(hw, count), hw->regs + S3C2410_SPTDAT);
+               else
+                       complete(&hw->done);
+       } else {
+               hw->count = hw->len;
+               hw->fiq_inuse = 0;
+               if (hw->rx)
+                       hw->rx[hw->len-1] = readb(hw->regs + S3C2410_SPRDAT);
  
-       if (count < hw->len)
-               writeb(hw_txbyte(hw, count), hw->regs + S3C2410_SPTDAT);
-       else
                complete(&hw->done);
+       }
  
   irq_done:
        return IRQ_HANDLED;
@@@ -322,6 -536,10 +536,10 @@@ static int __init s3c24xx_spi_probe(str
        platform_set_drvdata(pdev, hw);
        init_completion(&hw->done);
  
+       /* initialise fiq handler */
+       s3c24xx_spi_initfiq(hw);
        /* setup the master state. */
  
        /* the spi->mode bits understood by this driver: */
@@@ -489,7 -707,7 +707,7 @@@ static int s3c24xx_spi_resume(struct de
        return 0;
  }
  
 -static struct dev_pm_ops s3c24xx_spi_pmops = {
 +static const struct dev_pm_ops s3c24xx_spi_pmops = {
        .suspend        = s3c24xx_spi_suspend,
        .resume         = s3c24xx_spi_resume,
  };
diff --combined drivers/spi/spi_txx9.c
@@@ -29,8 -29,6 +29,8 @@@
  
  
  #define SPI_FIFO_SIZE 4
 +#define SPI_MAX_DIVIDER 0xff  /* Max. value for SPCR1.SER */
 +#define SPI_MIN_DIVIDER 1     /* Min. value for SPCR1.SER */
  
  #define TXx9_SPMCR            0x00
  #define TXx9_SPCR0            0x04
@@@ -195,8 -193,11 +195,8 @@@ static void txx9spi_work_one(struct txx
  
                if (prev_speed_hz != speed_hz
                                || prev_bits_per_word != bits_per_word) {
 -                      u32 n = (c->baseclk + speed_hz - 1) / speed_hz;
 -                      if (n < 1)
 -                              n = 1;
 -                      else if (n > 0xff)
 -                              n = 0xff;
 +                      int n = DIV_ROUND_UP(c->baseclk, speed_hz) - 1;
 +                      n = clamp(n, SPI_MIN_DIVIDER, SPI_MAX_DIVIDER);
                        /* enter config mode */
                        txx9spi_wr(c, mcr | TXx9_SPMCR_CONFIG | TXx9_SPMCR_BCLR,
                                        TXx9_SPMCR);
@@@ -369,18 -370,16 +369,16 @@@ static int __init txx9spi_probe(struct 
                goto exit;
        }
        c->baseclk = clk_get_rate(c->clk);
 -      c->min_speed_hz = (c->baseclk + 0xff - 1) / 0xff;
 -      c->max_speed_hz = c->baseclk;
 +      c->min_speed_hz = DIV_ROUND_UP(c->baseclk, SPI_MAX_DIVIDER + 1);
 +      c->max_speed_hz = c->baseclk / (SPI_MIN_DIVIDER + 1);
  
        res = platform_get_resource(dev, IORESOURCE_MEM, 0);
        if (!res)
                goto exit_busy;
-       if (!devm_request_mem_region(&dev->dev,
-                                    res->start, res->end - res->start + 1,
+       if (!devm_request_mem_region(&dev->dev, res->start, resource_size(res),
                                     "spi_txx9"))
                goto exit_busy;
-       c->membase = devm_ioremap(&dev->dev,
-                                 res->start, res->end - res->start + 1);
+       c->membase = devm_ioremap(&dev->dev, res->start, resource_size(res));
        if (!c->membase)
                goto exit_busy;
  
diff --combined drivers/spi/spidev.c
@@@ -30,6 -30,7 +30,6 @@@
  #include <linux/errno.h>
  #include <linux/mutex.h>
  #include <linux/slab.h>
 -#include <linux/smp_lock.h>
  
  #include <linux/spi/spi.h>
  #include <linux/spi/spidev.h>
@@@ -41,7 -42,7 +41,7 @@@
   * This supports acccess to SPI devices using normal userspace I/O calls.
   * Note that while traditional UNIX/POSIX I/O semantics are half duplex,
   * and often mask message boundaries, full SPI support requires full duplex
 - * transfers.  There are several kinds of of internal message boundaries to
 + * transfers.  There are several kinds of internal message boundaries to
   * handle chipselect management and other protocol options.
   *
   * SPI has a character major number assigned.  We allocate minor numbers
@@@ -53,7 -54,7 +53,7 @@@
  #define SPIDEV_MAJOR                  153     /* assigned */
  #define N_SPI_MINORS                  32      /* ... up to 256 */
  
- static unsigned long  minors[N_SPI_MINORS / BITS_PER_LONG];
+ static DECLARE_BITMAP(minors, N_SPI_MINORS);
  
  
  /* Bit masks for spi_device.mode management.  Note that incorrect
@@@ -476,6 -477,7 +476,6 @@@ static int spidev_open(struct inode *in
        struct spidev_data      *spidev;
        int                     status = -ENXIO;
  
 -      lock_kernel();
        mutex_lock(&device_list_lock);
  
        list_for_each_entry(spidev, &device_list, device_entry) {
                pr_debug("spidev: nothing for minor %d\n", iminor(inode));
  
        mutex_unlock(&device_list_lock);
 -      unlock_kernel();
        return status;
  }
  
@@@ -558,7 -561,7 +558,7 @@@ static struct class *spidev_class
  
  /*-------------------------------------------------------------------------*/
  
- static int spidev_probe(struct spi_device *spi)
+ static int __devinit spidev_probe(struct spi_device *spi)
  {
        struct spidev_data      *spidev;
        int                     status;
        return status;
  }
  
- static int spidev_remove(struct spi_device *spi)
+ static int __devexit spidev_remove(struct spi_device *spi)
  {
        struct spidev_data      *spidev = spi_get_drvdata(spi);
  
        return 0;
  }
  
- static struct spi_driver spidev_spi = {
+ static struct spi_driver spidev_spi_driver = {
        .driver = {
                .name =         "spidev",
                .owner =        THIS_MODULE,
@@@ -661,14 -664,14 +661,14 @@@ static int __init spidev_init(void
  
        spidev_class = class_create(THIS_MODULE, "spidev");
        if (IS_ERR(spidev_class)) {
-               unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
+               unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
                return PTR_ERR(spidev_class);
        }
  
-       status = spi_register_driver(&spidev_spi);
+       status = spi_register_driver(&spidev_spi_driver);
        if (status < 0) {
                class_destroy(spidev_class);
-               unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
+               unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
        }
        return status;
  }
@@@ -676,9 -679,9 +676,9 @@@ module_init(spidev_init)
  
  static void __exit spidev_exit(void)
  {
-       spi_unregister_driver(&spidev_spi);
+       spi_unregister_driver(&spidev_spi_driver);
        class_destroy(spidev_class);
-       unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
+       unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
  }
  module_exit(spidev_exit);