1. 06 Feb, 2019 3 commits
  2. 30 Jan, 2019 2 commits
    • Jonas Bonn's avatar
      spi-atmel: support inter-word delay · 473a78a7
      Jonas Bonn authored
      If the SPI slave requires an inter-word delay, configure the DLYBCT
      register accordingly.
      
      Tested on a SAMA5D2 board (derived from SAMA5D2-Xplained reference
      board).
      Signed-off-by: default avatarJonas Bonn <jonas@norrbonn.se>
      Acked-by: default avatarNicolas Ferre <nicolas.ferre@microchip.com>
      CC: Nicolas Ferre <nicolas.ferre@microchip.com>
      CC: Mark Brown <broonie@kernel.org>
      CC: Alexandre Belloni <alexandre.belloni@bootlin.com>
      CC: Ludovic Desroches <ludovic.desroches@microchip.com>
      CC: linux-spi@vger.kernel.org
      CC: linux-arm-kernel@lists.infradead.org
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      473a78a7
    • Jonas Bonn's avatar
      spi: support inter-word delay requirement for devices · b7bb367a
      Jonas Bonn authored
      Some devices are slow and cannot keep up with the SPI bus and therefore
      require a short delay between words of the SPI transfer.
      
      The example of this that I'm looking at is a SAMA5D2 with a minimum SPI
      clock of 400kHz talking to an AVR-based SPI slave.  The AVR cannot put
      bytes on the bus fast enough to keep up with the SoC's SPI controller
      even at the lowest bus speed.
      
      This patch introduces the ability to specify a required inter-word
      delay for SPI devices.  It is up to the controller driver to configure
      itself accordingly in order to introduce the requested delay.
      
      Note that, for spi_transfer, there is already a field word_delay that
      provides similar functionality.  This field, however, is specified in
      clock cycles (and worse, SPI controller cycles, not SCK cycles); that
      makes this value dependent on the master clock instead of the device
      clock for which the delay is intended to provide some relief.  This
      patch leaves this old word_delay in place and provides a time-based
      word_delay_us alongside it; the new field fits in the struct padding
      so struct size is constant.  There is only one in-kernel user of the
      word_delay field and presumably that driver could be reworked to use
      the time-based value instead.
      
      The time-based delay is limited to 8 bits as these delays are intended
      to be short.  The SAMA5D2 that I've tested this on limits delays to a
      maximum of ~100us, which is already many word-transfer periods even at
      the minimum transfer speed supported by the controller.
      Signed-off-by: default avatarJonas Bonn <jonas@norrbonn.se>
      CC: Mark Brown <broonie@kernel.org>
      CC: Rob Herring <robh+dt@kernel.org>
      CC: Mark Rutland <mark.rutland@arm.com>
      CC: linux-spi@vger.kernel.org
      CC: devicetree@vger.kernel.org
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      b7bb367a
  3. 29 Jan, 2019 3 commits
  4. 28 Jan, 2019 6 commits
  5. 24 Jan, 2019 4 commits
  6. 23 Jan, 2019 3 commits
  7. 21 Jan, 2019 1 commit
  8. 18 Jan, 2019 3 commits
  9. 17 Jan, 2019 4 commits
  10. 14 Jan, 2019 3 commits
    • Charles Keepax's avatar
      spi: cadence: Correct initialisation of runtime PM · 734882a8
      Charles Keepax authored
      Currently the driver calls pm_runtime_put_autosuspend but without ever
      having done a pm_runtime_get, this causes the reference count in the pm
      runtime core to become -1. The bad reference count causes the core to
      sometimes suspend whilst an active SPI transfer is in progress.
      
      arizona spi0.1: SPI transfer timed out
      spi_master spi0: failed to transfer one message from queue
      
      The correct proceedure is to do all the initialisation that requires the
      hardware to be powered up before enabling the PM runtime, then enable
      the PM runtime having called pm_runtime_set_active to inform it that the
      hardware is currently powered up. The core will then power it down at
      it's leisure and no explicit pm_runtime_put is required.
      
      Fixes: d36ccd9f ("spi: cadence: Runtime pm adaptation")
      Signed-off-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      734882a8
    • Stephen Boyd's avatar
      spi: spi-geni-qcom: Get rid of forward declaration · de43affe
      Stephen Boyd authored
      We don't need this forward declaration. Move the function to where it
      needed so we can drop it and shave some lines of code.
      
      CC: Girish Mahadevan <girishm@codeaurora.org>
      CC: Dilip Kota <dkota@codeaurora.org>
      CC: Alok Chauhan <alokc@codeaurora.org>
      Cc: Douglas Anderson <dianders@chromium.org>
      Signed-off-by: default avatarStephen Boyd <swboyd@chromium.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      de43affe
    • Stephen Boyd's avatar
      spi: spi-geni-qcom: Don't initialize completion for normal message · 0357a3da
      Stephen Boyd authored
      We only use this completion when we're doing something that isn't a
      message transfer. For example, changing CS or aborting/canceling a
      command. All of those situations properly reinitialize the completion
      before sending the GENI the special command to change CS or cancel, etc.
      Given that, let's remove the initialization here.
      
      Cc: Girish Mahadevan <girishm@codeaurora.org>
      Cc: Dilip Kota <dkota@codeaurora.org>
      Cc: Alok Chauhan <alokc@codeaurora.org>
      Cc: Douglas Anderson <dianders@chromium.org>
      Signed-off-by: default avatarStephen Boyd <swboyd@chromium.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      0357a3da
  11. 10 Jan, 2019 2 commits
  12. 09 Jan, 2019 6 commits
    • Martin Sperl's avatar
      spi: core: avoid waking pump thread from spi_sync instead run teardown delayed · 412e6037
      Martin Sperl authored
      When spi_sync is running alone with no other spi devices connected
      to the bus the worker thread is woken during spi_finalize_current_message
      to run the teardown code every time.
      
      This is totally unnecessary in the case that there is no message queued.
      
      On a multi-core system this results in one wakeup of the thread for each
      spi_message processed via spi_sync where in most cases the teardown does
      not happen as the hw is already in use.
      
      This patch now delays the teardown by 1 second by using a separate
      kthread_delayed_work for the teardown.
      
      This avoids waking the kthread too often.
      
      For spi_sync transfers in a tight loop (say 40k messages/s) this
      avoids the penalty of waking the worker thread 40k times/s.
      On a rasperry pi 3 with 4 cores the results in 32% of a single core
      only to find out that there is nothing in the queue and it can go back
      to sleep.
      
      With this patch applied the spi-worker is woken exactly once: after
      the load finishes and the spi bus is idle for 1 second.
      
      I believe I have also seen situations where during a spi_sync loop
      the worker thread (triggered by the last message finished) is slightly
      faster and _wins_ the race to process the message, so we are actually
      running the kthread and letting it do some work...
      
      This is also no longer observed with this patch applied as.
      
      Tested with a new CAN controller driver for the mcp2517fd which
      uses spi_sync for interrupt handling and spi_async for scheduling
      of can frames for transmission (in a different thread)
      
      Some statistics when receiving 100000 CAN frames with the mcp25xxfd driver
      on a Raspberry pi 3:
      
      without the patch:
      ------------------
      root@raspcm3:~# for x in $(pgrep spi0) $(pgrep irq/94-mcp25xxf) ; do awk '{printf "%-20s %6i\n", $2,$15}' /proc/$x/stat; done
      (spi0)                    5
      (irq/94-mcp25xxf)         0
      root@raspcm3:~# vmstat 1
      procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
       r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
       1  0      0 821960  13592  50848    0    0    80     2 1986  105  1  2 97  0  0
       0  0      0 821968  13592  50876    0    0     0     0 8046   30  0  0 100  0  0
       0  0      0 821936  13592  50876    0    0     0     0 8032   24  0  0 100  0  0
       0  0      0 821936  13592  50876    0    0     0     0 8035   30  0  0 100  0  0
       0  0      0 821936  13592  50876    0    0     0     0 8033   22  0  0 100  0  0
       2  0      0 821936  13592  50876    0    0     0     0 11598 7129  0  3 97  0  0
       1  0      0 821872  13592  50876    0    0     0     0 37741 59003  0 31 69  0  0
       2  0      0 821840  13592  50876    0    0     0     0 37762 59078  0 29 71  0  0
       2  0      0 821776  13592  50876    0    0     0     0 37593 58792  0 28 72  0  0
       1  0      0 821744  13592  50876    0    0     0     0 37642 58881  0 30 70  0  0
       2  0      0 821680  13592  50876    0    0     0     0 37490 58602  0 27 73  0  0
       1  0      0 821648  13592  50876    0    0     0     0 37412 58418  0 29 71  0  0
       1  0      0 821584  13592  50876    0    0     0     0 37337 58288  0 27 73  0  0
       1  0      0 821552  13592  50876    0    0     0     0 37584 58774  0 27 73  0  0
       0  0      0 821520  13592  50876    0    0     0     0 18363 20566  0  9 91  0  0
       0  0      0 821520  13592  50876    0    0     0     0 8037   32  0  0 100  0  0
       0  0      0 821520  13592  50876    0    0     0     0 8031   23  0  0 100  0  0
       0  0      0 821520  13592  50876    0    0     0     0 8034   26  0  0 100  0  0
       0  0      0 821520  13592  50876    0    0     0     0 8033   24  0  0 100  0  0
      ^C
      root@raspcm3:~# for x in $(pgrep spi0) $(pgrep irq/94-mcp25xxf) ; do awk '{printf "%-20s %6i\n", $2,$15}' /proc/$x/stat; done
      (spi0)                  228
      (irq/94-mcp25xxf)       794
      root@raspcm3:~# cat /proc/interrupts
                 CPU0       CPU1       CPU2       CPU3
       17:         34          0          0          0  ARMCTRL-level   1 Edge      3f00b880.mailbox
       27:          1          0          0          0  ARMCTRL-level  35 Edge      timer
       33:    1416870          0          0          0  ARMCTRL-level  41 Edge      3f980000.usb, dwc2_hsotg:usb1
       34:          1          0          0          0  ARMCTRL-level  42 Edge      vc4
       35:          0          0          0          0  ARMCTRL-level  43 Edge      3f004000.txp
       40:       1753          0          0          0  ARMCTRL-level  48 Edge      DMA IRQ
       42:         11          0          0          0  ARMCTRL-level  50 Edge      DMA IRQ
       44:         11          0          0          0  ARMCTRL-level  52 Edge      DMA IRQ
       45:          0          0          0          0  ARMCTRL-level  53 Edge      DMA IRQ
       66:          0          0          0          0  ARMCTRL-level  74 Edge      vc4 crtc
       69:          0          0          0          0  ARMCTRL-level  77 Edge      vc4 crtc
       70:          0          0          0          0  ARMCTRL-level  78 Edge      vc4 crtc
       77:         20          0          0          0  ARMCTRL-level  85 Edge      3f205000.i2c, 3f804000.i2c, 3f805000.i2c
       78:       6346          0          0          0  ARMCTRL-level  86 Edge      3f204000.spi
       80:        205          0          0          0  ARMCTRL-level  88 Edge      mmc0
       81:        493          0          0          0  ARMCTRL-level  89 Edge      uart-pl011
       89:          0          0          0          0  bcm2836-timer   0 Edge      arch_timer
       90:       4291       3821       2180       1649  bcm2836-timer   1 Edge      arch_timer
       94:      14289          0          0          0  pinctrl-bcm2835  16 Level     mcp25xxfd
      IPI0:          0          0          0          0  CPU wakeup interrupts
      IPI1:          0          0          0          0  Timer broadcast interrupts
      IPI2:       3645     242371       7919       1328  Rescheduling interrupts
      IPI3:        112        543        273        194  Function call interrupts
      IPI4:          0          0          0          0  CPU stop interrupts
      IPI5:          1          0          0          0  IRQ work interrupts
      IPI6:          0          0          0          0  completion interrupts
      Err:          0
      
      top shows 93% for the mcp25xxfd interrupt handler, 31% for spi0.
      
      with the patch:
      ---------------
      root@raspcm3:~# for x in $(pgrep spi0) $(pgrep irq/94-mcp25xxf) ; do awk '{printf "%-20s %6i\n", $2,$15}' /proc/$x/stat; done
      (spi0)                    0
      (irq/94-mcp25xxf)         0
      root@raspcm3:~# vmstat 1
      procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
       0  0      0 804768  13584  62628    0    0     0     0 8038   24  0  0 100  0  0
       0  0      0 804768  13584  62628    0    0     0     0 8042   25  0  0 100  0  0
       1  0      0 804704  13584  62628    0    0     0     0 9603 2967  0 20 80  0  0
       1  0      0 804672  13584  62628    0    0     0     0 9828 3380  0 24 76  0  0
       1  0      0 804608  13584  62628    0    0     0     0 9823 3375  0 23 77  0  0
       1  0      0 804608  13584  62628    0    0     0    12 9829 3394  0 23 77  0  0
       1  0      0 804544  13584  62628    0    0     0     0 9816 3362  0 22 78  0  0
       1  0      0 804512  13584  62628    0    0     0     0 9817 3367  0 23 77  0  0
       1  0      0 804448  13584  62628    0    0     0     0 9822 3370  0 22 78  0  0
       1  0      0 804416  13584  62628    0    0     0     0 9815 3367  0 23 77  0  0
       0  0      0 804352  13584  62628    0    0     0    84 9222 2250  0 14 86  0  0
       0  0      0 804352  13592  62620    0    0     0    24 8131  209  0  0 93  7  0
       0  0      0 804320  13592  62628    0    0     0     0 8041   27  0  0 100  0  0
       0  0      0 804352  13592  62628    0    0     0     0 8040   26  0  0 100  0  0
      root@raspcm3:~# for x in $(pgrep spi0) $(pgrep irq/94-mcp25xxf) ; do awk '{printf "%-20s %6i\n", $2,$15}' /proc/$x/stat; done
      (spi0)                    0
      (irq/94-mcp25xxf)       767
      root@raspcm3:~# cat /proc/interrupts
                 CPU0       CPU1       CPU2       CPU3
       17:         29          0          0          0  ARMCTRL-level   1 Edge      3f00b880.mailbox
       27:          1          0          0          0  ARMCTRL-level  35 Edge      timer
       33:    1024412          0          0          0  ARMCTRL-level  41 Edge      3f980000.usb, dwc2_hsotg:usb1
       34:          1          0          0          0  ARMCTRL-level  42 Edge      vc4
       35:          0          0          0          0  ARMCTRL-level  43 Edge      3f004000.txp
       40:       1773          0          0          0  ARMCTRL-level  48 Edge      DMA IRQ
       42:         11          0          0          0  ARMCTRL-level  50 Edge      DMA IRQ
       44:         11          0          0          0  ARMCTRL-level  52 Edge      DMA IRQ
       45:          0          0          0          0  ARMCTRL-level  53 Edge      DMA IRQ
       66:          0          0          0          0  ARMCTRL-level  74 Edge      vc4 crtc
       69:          0          0          0          0  ARMCTRL-level  77 Edge      vc4 crtc
       70:          0          0          0          0  ARMCTRL-level  78 Edge      vc4 crtc
       77:         20          0          0          0  ARMCTRL-level  85 Edge      3f205000.i2c, 3f804000.i2c, 3f805000.i2c
       78:       6417          0          0          0  ARMCTRL-level  86 Edge      3f204000.spi
       80:        237          0          0          0  ARMCTRL-level  88 Edge      mmc0
       81:        489          0          0          0  ARMCTRL-level  89 Edge      uart-pl011
       89:          0          0          0          0  bcm2836-timer   0 Edge      arch_timer
       90:       4048       3704       2383       1892  bcm2836-timer   1 Edge      arch_timer
       94:      14287          0          0          0  pinctrl-bcm2835  16 Level     mcp25xxfd
      IPI0:          0          0          0          0  CPU wakeup interrupts
      IPI1:          0          0          0          0  Timer broadcast interrupts
      IPI2:       2361       2948       7890       1616  Rescheduling interrupts
      IPI3:         65        617        301        166  Function call interrupts
      IPI4:          0          0          0          0  CPU stop interrupts
      IPI5:          1          0          0          0  IRQ work interrupts
      IPI6:          0          0          0          0  completion interrupts
      Err:          0
      top shows 91% for the mcp25xxfd interrupt handler, 0% for spi0
      
      So we see that spi0 is no longer getting scheduled wasting CPU cycles
      There are a lot less context switches and corresponding Rescheduling interrupts
      All of these show that this improves efficiency of the system and reduces
      CPU utilization.
      Signed-off-by: default avatarMartin Sperl <kernel@martin.sperl.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      412e6037
    • Linus Walleij's avatar
      spi: dw: Convert to use CS GPIO descriptors · 9400c41e
      Linus Walleij authored
      This converts the DesignWare (dw) SPI master driver to
      use GPIO descriptors for chip select handling.
      
      This driver has a duplicate DT parser in addition to the
      one in the core, sets up the line as non-asserted and
      relies on the core to drive the GPIOs.
      
      It is a pretty straight-forward conversion.
      
      Cc: Talel Shenhar <talel@amazon.com>
      Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
      Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
      Cc: Linuxarm <linuxarm@huawei.com>
      Tested-by: default avatarJay Fang <f.fangjian@huawei.com>
      Reviewed-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      9400c41e
    • Linus Walleij's avatar
      spi: davinci: Convert to use CS GPIO descriptors · 101a68e7
      Linus Walleij authored
      This converts the DaVinci SPI master driver to use GPIO
      descriptors for chip select handling.
      
      DaVinci parses the device tree a second time for the chip
      select GPIOs (no relying on the parsing already happening
      in the SPI core) and handles inversion semantics locally.
      
      We simply drop the extra parsing and set up and move the
      CS handling to the core and gpiolib. The fact that the
      driver is actively driving the GPIO in the
      davinci_spi_chipselect() callback is confusing since the
      host does not set SPI_MASTER_GPIO_SS so this should not
      ever get called when using GPIO CS. I put in a comment
      about this.
      
      This driver also supports instantiation from board files,
      but these are all using native chip selects so no problem
      with GPIO lines here.
      
      Cc: David Lechner <david@lechnology.com>
      Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
      Cc: Linuxarm <linuxarm@huawei.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      101a68e7
    • Linus Walleij's avatar
      spi: clps711x: Convert to use CS GPIO descriptors · 054320b2
      Linus Walleij authored
      This converts the CLPS711x SPI master driver to use GPIO
      descriptors for chip select handling.
      
      The CLPS711x driver was merely requesting the GPIO and
      setting the CS line non-asserted so this was a pretty
      straight-forward conversion. The setup callback goes away.
      
      Cc: Alexander Shiyan <shc_work@mail.ru>
      Cc: Linuxarm <linuxarm@huawei.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      054320b2
    • Linus Walleij's avatar
      spi: cadence: Convert to use CS GPIO descriptors · cfeefa79
      Linus Walleij authored
      This converts the Cadence SPI master driver to use GPIO
      descriptors for chip select handling.
      
      The Cadence driver was allocating a state container just
      to hold the requested GPIO line and contained lots of
      polarity inversion code. As this is all handled by gpiolib
      and a simple devm_* request in the core, and as the driver
      is fully device tree only, most of this code chunk goes
      away in favour of central handling. The setup/cleanup
      callbacks goes away.
      
      This driver does NOT drive the CS line by setting the
      value of the GPIO so it relies on the SPI core to do
      this, which should work just fine with the descriptors.
      
      Cc: Wei Yongjun <weiyongjun1@huawei.com>
      Cc: Janek Kotas <jank@cadence.com>
      Cc: Linuxarm <linuxarm@huawei.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      cfeefa79
    • Linus Walleij's avatar
      spi: atmel: Convert to use CS GPIO descriptors · efc92fbb
      Linus Walleij authored
      This converts the Atmel SPI master driver to use GPIO descriptors
      for chip select handling.
      
      The Atmel driver has duplicate code to look up and initialize CS
      GPIOs from the device tree, so this is removed. It further has code
      to retrieve a CS GPIO from .controller_data but this seems to be
      completely unused in the kernel (legacy codepath?) so I deleted
      this support. It keeps track of polarity when switching the CS, but
      this is not needed anymore since we moved this over to the gpiolib.
      
      The local handling of the "npcs_pin" (I guess this might mean
      "negative polarity chip select pin") is preserved, but I strongly
      suspect this can be switched over to handling by the core and
      using the SPI_MASTER_GPIO_SS flag on the master to assure that
      the additional CS handling in the driver is also done.
      
      Cc: Eugen Hristev <eugen.hristev@microchip.com>
      Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
      Cc: Radu Pirea <radu.pirea@microchip.com>
      Cc: Linuxarm <linuxarm@huawei.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      efc92fbb