platform/kernel/linux-starfive.git
5 years agospi: abort spi_sync if failed to prepare_transfer_hardware
Super Liu [Wed, 22 May 2019 06:30:14 +0000 (14:30 +0800)]
spi: abort spi_sync if failed to prepare_transfer_hardware

There is no chance to wait spi message complete if failed to
prepare_transfer_hardware(). Therefore, finalize this message and abort
transfer with corresponding return status to release this block case.

Logs:

[17400.283005] c7   3267 PM: PM: suspend entry 2019-05-04 03:01:14.403097147 UTC
[17400.283013] c7   3267 PM: suspend entry (deep)
[17400.283016] c6   3267 PM: Syncing filesystems ... done.
[17400.584395] c1    753 spi_geni 890000.spi: spi_geni_prepare_transfer_hardware:Error enabling SE resources -13
[17400.584404] c1    753 spi_master spi1: failed to prepare transfer hardware
[17400.664611] c4   3267 PM: PM: suspend exit 2019-05-04 03:01:15.235273018 UTC

Flow:

__spi_sync@spi.c
|    if (status == 0) {
|        /* Push out the messages in the calling context if we
|         * can.
|         */
|        if (ctlr->transfer == spi_queued_transfer) {
|            SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics,
| spi_sync_immediate);
|            SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics,
| spi_sync_immediate);
| __spi_pump_messages(ctlr, false);
|        }
|
|        wait_for_completion(&done); <== stuck here!!!
|        status = message->status;
|    }
|    message->context = NULL;
|    return status;
|
--> __spi_pump_messages@spi.c
|    if (!was_busy && ctlr->prepare_transfer_hardware) {
|        ret = ctlr->prepare_transfer_hardware(ctlr);
|        if (ret) {
|            dev_err(&ctlr->dev,
| "failed to prepare transfer hardware\n");
|
|        if (ctlr->auto_runtime_pm)
|            pm_runtime_put(ctlr->dev.parent);
|            mutex_unlock(&ctlr->io_mutex);
|            return;
|        }
|    }
|
--> spi_geni_prepare_transfer_hardware@spi-geni-qcom.c
|    ret = pm_runtime_get_sync(mas->dev);
|    if (ret < 0) {
|        dev_err(mas->dev,
| "%s:Error enabling SE resources %d\n",
| __func__, ret);
|    pm_runtime_put_noidle(mas->dev);
|    goto exit_prepare_transfer_hardware;

Signed-off-by: Super Liu <supercjliu@google.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-fsl-spi: call spi_finalize_current_message() at the end
Christophe Leroy [Wed, 22 May 2019 11:00:36 +0000 (11:00 +0000)]
spi: spi-fsl-spi: call spi_finalize_current_message() at the end

spi_finalize_current_message() shall be called once all
actions are finished, otherwise the last actions might
step over a newly started transfer.

Fixes: c592becbe704 ("spi: fsl-(e)spi: migrate to generic master queueing")
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bitbang: Fix NULL pointer dereference in spi_unregister_master
YueHaibing [Thu, 16 May 2019 07:56:56 +0000 (15:56 +0800)]
spi: bitbang: Fix NULL pointer dereference in spi_unregister_master

If spi_register_master fails in spi_bitbang_start
because device_add failure, We should return the
error code other than 0, otherwise calling
spi_bitbang_stop may trigger NULL pointer dereference
like this:

BUG: KASAN: null-ptr-deref in __list_del_entry_valid+0x45/0xd0
Read of size 8 at addr 0000000000000000 by task syz-executor.0/3661

CPU: 0 PID: 3661 Comm: syz-executor.0 Not tainted 5.1.0+ #28
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
Call Trace:
 dump_stack+0xa9/0x10e
 ? __list_del_entry_valid+0x45/0xd0
 ? __list_del_entry_valid+0x45/0xd0
 __kasan_report+0x171/0x18d
 ? __list_del_entry_valid+0x45/0xd0
 kasan_report+0xe/0x20
 __list_del_entry_valid+0x45/0xd0
 spi_unregister_controller+0x99/0x1b0
 spi_lm70llp_attach+0x3ae/0x4b0 [spi_lm70llp]
 ? 0xffffffffc1128000
 ? klist_next+0x131/0x1e0
 ? driver_detach+0x40/0x40 [parport]
 port_check+0x3b/0x50 [parport]
 bus_for_each_dev+0x115/0x180
 ? subsys_dev_iter_exit+0x20/0x20
 __parport_register_driver+0x1f0/0x210 [parport]
 ? 0xffffffffc1150000
 do_one_initcall+0xb9/0x3b5
 ? perf_trace_initcall_level+0x270/0x270
 ? kasan_unpoison_shadow+0x30/0x40
 ? kasan_unpoison_shadow+0x30/0x40
 do_init_module+0xe0/0x330
 load_module+0x38eb/0x4270
 ? module_frob_arch_sections+0x20/0x20
 ? kernel_read_file+0x188/0x3f0
 ? find_held_lock+0x6d/0xd0
 ? fput_many+0x1a/0xe0
 ? __do_sys_finit_module+0x162/0x190
 __do_sys_finit_module+0x162/0x190
 ? __ia32_sys_init_module+0x40/0x40
 ? __mutex_unlock_slowpath+0xb4/0x3f0
 ? wait_for_completion+0x240/0x240
 ? vfs_write+0x160/0x2a0
 ? lockdep_hardirqs_off+0xb5/0x100
 ? mark_held_locks+0x1a/0x90
 ? do_syscall_64+0x14/0x2a0
 do_syscall_64+0x72/0x2a0
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: 702a4879ec33 ("spi: bitbang: Let spi_bitbang_start() take a reference to master")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Axel Lin <axel.lin@ingics.com>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: Fix Raspberry Pi breakage
Mark Brown [Thu, 9 May 2019 02:27:17 +0000 (11:27 +0900)]
spi: Fix Raspberry Pi breakage

This reverts commit c9ba7a16d0f1 (Release spi_res after finalizing
message) which causes races during cleanup.

Reported-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: Clear SPI_CS_HIGH flag from bad_bits for GPIO chip-select
Serge Semin [Fri, 26 Apr 2019 10:30:07 +0000 (13:30 +0300)]
spi: Clear SPI_CS_HIGH flag from bad_bits for GPIO chip-select

When GPIO chip-select is used nothing prevents any available SPI
controllers to work with both CS-high and traditional CS-low modes.
In fact the SPI bus core code already does it, so we don't need to
introduce any modification there. But spi_setup() still fails to
switch the interface settings if CS-high flag is set for the case
of GPIO-driven slave chip-select when the SPI controller doesn't
support the hardwired CS-inversion. Lets fix it by clearing the
SPI_CS_HIGH flag out from bad_bits (unsupported by controller) when
client chip is selected by GPIO.

This feature is useful for slave devices, which in accordance with
communication protocol can work with both active-high and active-low
chip-selects. I am aware of one such device. It is MMC-SPI interface,
when at init sequence the driver needs to perform a read operation with
low and high chip-select sequentially (requirement of 74 clock cycles
with both chipselect, see the mmc_spi driver for details).

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: ep93xx: Convert to use CS GPIO descriptors
Linus Walleij [Sat, 20 Apr 2019 11:05:59 +0000 (13:05 +0200)]
spi: ep93xx: Convert to use CS GPIO descriptors

This converts the EP93xx SPI master driver to use GPIO
descriptors for chip select handling.

EP93xx was using platform data to pass in GPIO lines,
by converting all board files to use GPIO descriptor
tables the core will look up the GPIO lines from the
SPI device in the same manner as for device tree.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: AD ASoC: declare missing of table
Daniel Gomez [Mon, 22 Apr 2019 19:12:33 +0000 (21:12 +0200)]
spi: AD ASoC: declare missing of table

Add missing <of_device_id> table for SPI driver relying on SPI
device match since compatible is in a DT binding or in a DTS.

Before this patch:
modinfo sound/soc/codecs/snd-soc-adau1977-spi.ko | grep alias
alias:          spi:adau1979
alias:          spi:adau1978
alias:          spi:adau1977

After this patch:
modinfo sound/soc/codecs/snd-soc-adau1977-spi.ko | grep alias
alias:          of:N*T*Cadi,adau1979C*
alias:          of:N*T*Cadi,adau1979
alias:          of:N*T*Cadi,adau1978C*
alias:          of:N*T*Cadi,adau1978
alias:          of:N*T*Cadi,adau1977C*
alias:          of:N*T*Cadi,adau1977
alias:          spi:adau1979
alias:          spi:adau1978
alias:          spi:adau1977

Reported-by: Javier Martinez Canillas <javier@dowhile0.org>
Signed-off-by: Daniel Gomez <dagmcr@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-mem: zynq-qspi: Fix build error on architectures missing readsl/writesl
Naga Sureshkumar Relli [Mon, 22 Apr 2019 07:26:49 +0000 (12:56 +0530)]
spi: spi-mem: zynq-qspi: Fix build error on architectures missing readsl/writesl

Alpha and some of the architectures are missing readsl/writesl functions.
so the zynq-qspi driver won't be able to build on these arches. hence use
ioread32_rep()/iowrite32_rep() instead of readsl()/writesl().

Signed-off-by: Naga Sureshkumar Relli <naga.sureshkumar.relli@xilinx.com>
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: stm32-qspi: manage the get_irq error case
Fabien Dessenne [Wed, 24 Apr 2019 15:19:00 +0000 (17:19 +0200)]
spi: stm32-qspi: manage the get_irq error case

During probe, check the "get_irq" error value.

Signed-off-by: Fabien Dessenne <fabien.dessenne@st.com>
Acked-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi/spi-bcm2835: Split transfers that exceed DLEN
Meghana Madhyastha [Sat, 13 Apr 2019 18:24:14 +0000 (20:24 +0200)]
spi/spi-bcm2835: Split transfers that exceed DLEN

Split spi transfers into chunks of <=65532 to enable the driver to
perform DMA transfer on big buffers. The DLEN register specifies the
number of bytes to transfer in DMA mode. It is 16-bit wide and thus the
maximum DMA transfer is 65535 bytes. Set the maximum to 65532 (4 byte
aligned) since the FIFO in DMA mode is accessed in 4 byte chunks.

->max_dma_len is the value the spi core uses when splitting the buffer
into scatter gather entries.
The BCM2835 DMA block has 2 types of channels/engines:
- Normal: Max length: 1G
- Lite: Max length: 65535

Even when using a Lite channel we will not exceed the max length, so
let's drop setting ->max_dma_len.

Signed-off-by: Meghana Madhyastha <meghana.madhyastha@gmail.com>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: expand mode support
Sowjanya Komatineni [Mon, 15 Apr 2019 21:30:27 +0000 (14:30 -0700)]
spi: expand mode support

This patch changes mode and mode_bits from u16 to u32 to allow more
mode configurations.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agodt-bindings: spi: spi-mt65xx: add support for MT8516
Leilk Liu [Wed, 17 Apr 2019 08:47:16 +0000 (16:47 +0800)]
dt-bindings: spi: spi-mt65xx: add support for MT8516

Add binding documentation of spi-mt65xx for MT8516 SOC.

Signed-off-by: Leilk Liu <leilk.liu@mediatek.com>
Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: pxa2xx: Add support for Intel Comet Lake
Evan Green [Tue, 16 Apr 2019 03:27:43 +0000 (20:27 -0700)]
spi: pxa2xx: Add support for Intel Comet Lake

Add PCI IDs for SPI on Comet Lake.

Signed-off-by: Evan Green <evgreen@chromium.org>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi/trace: Cap buffer contents at 64 bytes
Noralf Trønnes [Sat, 13 Apr 2019 20:48:55 +0000 (22:48 +0200)]
spi/trace: Cap buffer contents at 64 bytes

Large transfers (64kB) doesn't show up in the trace. Not sure why, but
since printk can only display buffers up to 64 bytes in length, we only
need to store the first 64 bytes.

Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: Release spi_res after finalizing message
Noralf Trønnes [Sat, 13 Apr 2019 18:24:13 +0000 (20:24 +0200)]
spi: Release spi_res after finalizing message

spi_split_transfers_maxsize() can be used to split a transfer. This
function uses spi_res to lifetime manage the added transfer structures.
So in order to finalize the current message while it contains the split
transfers, spi_res_release() must be called after finalizing.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: Remove warning in spi_split_transfers_maxsize()
Noralf Trønnes [Sat, 13 Apr 2019 18:24:12 +0000 (20:24 +0200)]
spi: Remove warning in spi_split_transfers_maxsize()

Don't warn about splitting transfers, the info is available in the
statistics if needed.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: Remove one needless transfer speed fall back case
Jarkko Nikula [Fri, 12 Apr 2019 13:25:51 +0000 (16:25 +0300)]
spi: Remove one needless transfer speed fall back case

Falling back to maximum speed of the controller in case of SPI slave
maximum speed is not set is needless. It already defaults to maximum
speed of the controller since commit 052eb2d49006 ("spi: core: Set
max_speed_hz of spi_device default to max_speed_hz of controller").

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: sh-msiof: Document r8a77470 bindings
Cao Van Dong [Thu, 11 Apr 2019 07:54:21 +0000 (16:54 +0900)]
spi: sh-msiof: Document r8a77470 bindings

Document SoC specific bindings for R-Car RZ/G1C(r8a77470) SoC.

Signed-off-by: Cao Van Dong <cv-dong@jinso.co.jp>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: pxa2xx: use a module softdep for dw_dmac
Flavio Suligoi [Wed, 10 Apr 2019 12:51:36 +0000 (14:51 +0200)]
spi: pxa2xx: use a module softdep for dw_dmac

With dw_dmac, sometimes the request of a DMA channel fails because
the DMA driver is not ready, so an explicit dependency request
is necessary.

Signed-off-by: Flavio Suligoi <f.suligoi@asem.it>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-mem: Make spi_mem_default_supports_op() static inline
YueHaibing [Wed, 10 Apr 2019 13:18:28 +0000 (21:18 +0800)]
spi: spi-mem: Make spi_mem_default_supports_op() static inline

Stub helper spi_mem_default_supports_op() should
be set to static inline

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-mem: Fix build error without CONFIG_SPI_MEM
YueHaibing [Mon, 8 Apr 2019 14:39:49 +0000 (22:39 +0800)]
spi: spi-mem: Fix build error without CONFIG_SPI_MEM

When building with CONFIG_SPI_MEM is not set
gc warns this:

drivers/spi/spi-zynq-qspi.o: In function `zynq_qspi_supports_op':
spi-zynq-qspi.c:(.text+0x1da): undefined reference to `spi_mem_default_supports_op'

Fixes: 67dca5e580f1 ("spi: spi-mem: Add support for Zynq QSPI controller")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: document tx/rx clock delay properties
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:18 +0000 (17:14 -0700)]
spi: document tx/rx clock delay properties

Tegra SPI controller has TX and RX trimmers to tuning the delay of
SPI master clock with respect to the data.

TX and RX tap values are based on the platform validation across the
PVT and the trimmer values vary based on the trace lengths to the
corresponding SPI devices.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: add a method for configuring CS timing
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:16 +0000 (17:14 -0700)]
spi: add a method for configuring CS timing

This patch creates set_cs_timing SPI master optional method for
SPI masters to implement configuring CS timing if applicable.

This patch also creates spi_cs_timing accessory for SPI clients to
use for requesting SPI master controllers to configure device requested
CS setup time, hold time and inactive delay.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi-summary: document set_cs_timing
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:15 +0000 (17:14 -0700)]
spi-summary: document set_cs_timing

This patch documents set_cs_timing SPI master method.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: add support for interrupt mask
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:12 +0000 (17:14 -0700)]
spi: tegra114: add support for interrupt mask

This patch creates tegra_spi_soc_data structure to maintain and implement
SPI HW feature differences between different Tegra chips and also creates
a separate compatible string for T124/T210.

Tegra210 and later has a separate interrupt mask register SPI_INTR_MASK
for enabling or disabling interrupts while Tegra124 and prior uses
interrupt enable bits in SPI_DMA_CTL register.

This patch creates flag has_intr_mask_reg in tegra_spi_soc_data to
identify this and implements accordingly.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: add 3 wire transfer mode support
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:08 +0000 (17:14 -0700)]
spi: tegra114: add 3 wire transfer mode support

This patch adds 3 wire transfer support to SPI mode list along with
its implementation.

3 wire or Bi-directional mode uses only one serial data pin for the
transfer. SPI in master mode uses MOSI data line only and MISO data
line is not used.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: add dual mode support
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:07 +0000 (17:14 -0700)]
spi: tegra114: add dual mode support

This patch adds support for dual mode SPI transfer.

Dual mode uses both MOSI and MISO lines in parallel where the data
is interleaved on MOSI and MISO lines increasing the throughput.

Packet from Tx FIFO is transmitted on both MOSI and MISO lines and
packet to Rx FIFO is received from both MOSI and MISO lines. Even
bits are transmitted or received on the MOSI data line and odd bits
are transmitted or received on the MISO data line.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Use devm_spi_register_master()
Andrey Smirnov [Wed, 3 Apr 2019 04:01:33 +0000 (21:01 -0700)]
spi: gpio: Use devm_spi_register_master()

Replace spi_bitbang_start() with a combination of spi_bitbang_init()
and devm_spi_register_master() and drop all of the explicit
cleanup-related code that's no longer necessary.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bitbang: Introduce spi_bitbang_init()
Andrey Smirnov [Wed, 3 Apr 2019 04:01:32 +0000 (21:01 -0700)]
spi: bitbang: Introduce spi_bitbang_init()

Move all of the code doing struct spi_bitbang initialization, so that
it can be paired with devm_spi_register_master() in order to avoid
having to call spi_bitbang_stop() explicitly.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Make sure spi_master_put() is called in every error path
Andrey Smirnov [Wed, 3 Apr 2019 04:01:31 +0000 (21:01 -0700)]
spi: gpio: Make sure spi_master_put() is called in every error path

There's a number of failure paths in spi_gpio_probe() that do not call
spi_master_put() potentially leaking memory. Fix this problem by
registering a cleanup funciont via devm_add_action_or_reset() right
after SPI controller is allocated.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: pxa2xxx: change "no DMA channels..." msg from debug to warning
Flavio Suligoi [Fri, 5 Apr 2019 12:40:22 +0000 (14:40 +0200)]
spi: pxa2xxx: change "no DMA channels..." msg from debug to warning

Change the type of the diagnostic message:

"no DMA channels available, using PIO"

from debug to warning.

The lack of an available DMA channel is very important regard the
spi-pxa2xx performance. The transfer speed can be reduced more than 50%.

So it is very important to warn the user about this, without enabling
the full SPI debug with CONFIG_SPI_DEBUG.

Moreover, enabling the full SPI debug only to enable this specific
debug message, the dmesg buffer fills quickly with a lot of
repetitive information during the SPI data transfer.
This cause the loss of all the first important messages
written during the initialization.

Signed-off-by: Flavio Suligoi <f.suligoi@asem.it>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: fsl-lpspi: Clean up fsl_lpspi_probe
Axel Lin [Sun, 7 Apr 2019 14:58:17 +0000 (22:58 +0800)]
spi: fsl-lpspi: Clean up fsl_lpspi_probe

Use is_slave local variable to avoid calling of_property_read_bool() twice.
Remove redudant assignment for controller->bus_num, set it once is enough.
Move setting controller->bits_per_word_mask close to the code init other
controller fields.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: fsl-lpspi: Fix build warning when !CONFIG_PM
Axel Lin [Sun, 7 Apr 2019 14:58:16 +0000 (22:58 +0800)]
spi: fsl-lpspi: Fix build warning when !CONFIG_PM

Add #ifdef CONFIG_PM guard to fix build warning when !CONFIG_PM
drivers/spi/spi-fsl-lpspi.c:810:12: warning: ‘fsl_lpspi_runtime_suspend’ defined but not used [-Wunused-function]
 static int fsl_lpspi_runtime_suspend(struct device *dev)
            ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/spi-fsl-lpspi.c:789:12: warning: ‘fsl_lpspi_runtime_resume’ defined but not used [-Wunused-function]
 static int fsl_lpspi_runtime_resume(struct device *dev)
            ^~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 944c01a889d9 ("spi: lpspi: enable runtime pm for lpspi")
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: fsl-lpspi: Fix problematic dev_set_drvdata call
Axel Lin [Sun, 7 Apr 2019 14:58:15 +0000 (22:58 +0800)]
spi: fsl-lpspi: Fix problematic dev_set_drvdata call

The original code already set controller as drvdata:
platform_set_drvdata(pdev, controller);

But commit 944c01a889d9 ("spi: lpspi: enable runtime pm for lpspi")
added dev_set_drvdata(&pdev->dev, fsl_lpspi);
so fsl_lpspi_remove() will get wrong pointer by platform_get_drvdata().

Fixes: 944c01a889d9 ("spi: lpspi: enable runtime pm for lpspi")
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi-mem: fix kernel-doc for spi_mem_dirmap_{read|write}()
Sergei Shtylyov [Sat, 6 Apr 2019 18:33:29 +0000 (21:33 +0300)]
spi-mem: fix kernel-doc for spi_mem_dirmap_{read|write}()

The function names in the kernel-doc comments were mistyped, with a word
"dirmap" being repeated twice, so fix them.

Fixes: aa167f3fed0c ("spi: spi-mem: Add a new API to support direct mapping")
Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: Fix build error without CONFIG_DEBUG_FS
YueHaibing [Sat, 6 Apr 2019 15:14:57 +0000 (23:14 +0800)]
spi: bcm2835aux: Fix build error without CONFIG_DEBUG_FS

When building CONFIG_DEBUG_FS is not set
gcc warn this:

drivers/spi/spi-bcm2835aux.c: In function bcm2835aux_spi_probe:
drivers/spi/spi-bcm2835aux.c:591:2: error: too many arguments to function bcm2835aux_debugfs_create
  bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev));
  ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/spi/spi-bcm2835aux.c:145:13: note: declared here
 static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs)

Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: 8048d151eb4d ("spi: bcm2835aux: add driver stats to debugfs")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: kill useless initializer in spi_register_controller()
Sergei Shtylyov [Fri, 5 Apr 2019 15:48:50 +0000 (18:48 +0300)]
spi: kill useless initializer in spi_register_controller()

The 'status' local variable is initialized but this value is never used,
thus kill that initializer.

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-mem: Add support for Zynq QSPI controller
Naga Sureshkumar Relli [Mon, 1 Apr 2019 07:59:13 +0000 (13:29 +0530)]
spi: spi-mem: Add support for Zynq QSPI controller

Add support for QSPI controller driver used by Xilinx Zynq SOC.

Signed-off-by: Naga Sureshkumar Relli <naga.sureshkumar.relli@xilinx.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agodt-bindings: spi: Add device tree binding documentation for Zynq QSPI controller
Naga Sureshkumar Relli [Mon, 1 Apr 2019 07:58:32 +0000 (13:28 +0530)]
dt-bindings: spi: Add device tree binding documentation for Zynq QSPI controller

This patch adds the dts binding document for Zynq SOC QSPI controller.

Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Naga Sureshkumar Relli <naga.sureshkumar.relli@xilinx.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Drop unused pdev field in struct spi_gpio
Andrey Smirnov [Wed, 3 Apr 2019 04:01:30 +0000 (21:01 -0700)]
spi: gpio: Drop unused pdev field in struct spi_gpio

There's no code using 'pdev' field in struct spi_gpio. Drop it.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Drop mflags argument from spi_gpio_request()
Andrey Smirnov [Wed, 3 Apr 2019 04:01:29 +0000 (21:01 -0700)]
spi: gpio: Drop mflags argument from spi_gpio_request()

The logic of setting mflags in spi_gpio_request() is very simple and
there isn't much benefit in having it in that function. Move all of
that code outside into spi_gpio_probe() in order to simplify things.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: Don't call spi_get_gpio_descs() before device name is set
Andrey Smirnov [Wed, 3 Apr 2019 04:01:28 +0000 (21:01 -0700)]
spi: Don't call spi_get_gpio_descs() before device name is set

Move code calling spi_get_gpio_descs() to happen after ctlr->dev's
name is set in order to have proper GPIO consumer names.

Before:

cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/40049000.gpio, vf610-gpio:
 gpio-6   (                    |regulator-usb0-vbus ) out lo

gpiochip1: GPIOs 32-63, parent: platform/4004a000.gpio, vf610-gpio:
 gpio-36  (                    |scl                 ) in  hi
 gpio-37  (                    |sda                 ) in  hi
 gpio-40  (                    |(null) CS1          ) out lo
 gpio-41  (                    |(null) CS0          ) out lo ACTIVE LOW
 gpio-42  (                    |miso                ) in  hi
 gpio-43  (                    |mosi                ) in  lo
 gpio-44  (                    |sck                 ) out lo

After:

cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/40049000.gpio, vf610-gpio:
 gpio-6   (                    |regulator-usb0-vbus ) out lo

gpiochip1: GPIOs 32-63, parent: platform/4004a000.gpio, vf610-gpio:
 gpio-36  (                    |scl                 ) in  hi
 gpio-37  (                    |sda                 ) in  hi
 gpio-40  (                    |spi0 CS1            ) out lo
 gpio-41  (                    |spi0 CS0            ) out lo ACTIVE LOW
 gpio-42  (                    |miso                ) in  hi
 gpio-43  (                    |mosi                ) in  lo
 gpio-44  (                    |sck                 ) out lo

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Don't request CS GPIO in DT use-case
Andrey Smirnov [Wed, 3 Apr 2019 04:01:27 +0000 (21:01 -0700)]
spi: gpio: Don't request CS GPIO in DT use-case

DT use-case already relies on SPI core to control CS (requested by
of_spi_register_master() and controlled spi_set_cs()), so there's no
need to try to request those GPIO in spi-gpio code. Change the code
such that spi-gpio's CS related code is only used if device is probed
via pdata.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: set bus number based on id
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:06 +0000 (17:14 -0700)]
spi: tegra114: set bus number based on id

This patch sets SPI device id from the device tree as the bus number.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: use unpacked mode for below 4 bytes
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:01 +0000 (17:14 -0700)]
spi: tegra114: use unpacked mode for below 4 bytes

Packed mode expects minimum transfer length of 4 bytes.

This patch fixes this by using unpacked mode for transfers less
than 4 bytes.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: set supported bits per word
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:05 +0000 (17:14 -0700)]
spi: tegra114: set supported bits per word

Tegra SPI supports 4 through 32 bits per word.

This patch sets bits_per_word_mask accordingly to support transfer
with these bits per word.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: dump SPI registers during timeout
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:04 +0000 (17:14 -0700)]
spi: tegra114: dump SPI registers during timeout

This patch dumps SPI registers on transfer error or timeout for debug
purpose.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agoMerge branch 'spi-5.1' into spi-5.2
Mark Brown [Fri, 5 Apr 2019 03:19:10 +0000 (10:19 +0700)]
Merge branch 'spi-5.1' into spi-5.2

5 years agospi: tegra114: avoid reset call in atomic context
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:03 +0000 (17:14 -0700)]
spi: tegra114: avoid reset call in atomic context

This patch moves SPI controller reset out of spin lock.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: de-assert CS before SPI mode change
Sowjanya Komatineni [Fri, 5 Apr 2019 00:14:02 +0000 (17:14 -0700)]
spi: tegra114: de-assert CS before SPI mode change

With SW CS, during the transfer completion CS is de-asserted by writing
default command1 register value to SPI_COMMAND1 register. With this both
mode and CS state are set at the same time and if current transfer mode
is different to default SPI mode and if mode change happens prior to CS
de-assert, clock polarity can change while CS is active before transfer
finishes.

This causes Slave to see spurious clock edges resulting in data mismatch.

This patch fixes this by de-asserting CS before writing SPI_COMMAND1 to
its default value so through out the transfer it will be in same SPI mode.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: sh-msiof: Convert to use GPIO descriptors
Geert Uytterhoeven [Wed, 3 Apr 2019 15:08:52 +0000 (17:08 +0200)]
spi: sh-msiof: Convert to use GPIO descriptors

Convert GPIO chip selects in the Renesas MSIOF SPI driver from legacy
GPIO numbers to GPIO descriptors.

Notes:
  - The board file for the SH7724-based Ecovec24 development board now
    registers a GPIO descriptor lookup, instead of passing a GPIO number
    through controller_data,
  - sh_msiof_get_cs_gpios() must release all GPIOs, else
    spi_get_gpio_descs() cannot claim them during SPI controller
    registration.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: polling_limit_us can be static
kbuild test robot [Wed, 3 Apr 2019 18:16:51 +0000 (02:16 +0800)]
spi: bcm2835aux: polling_limit_us can be static

Fixes: 5fd917afc4bf ("spi: bcm2835aux: make the polling duration limits configurable")
Signed-off-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: Add missing error handling for CS GPIOs
Geert Uytterhoeven [Wed, 3 Apr 2019 14:46:56 +0000 (16:46 +0200)]
spi: Add missing error handling for CS GPIOs

While devm_gpiod_get_index_optional() returns NULL if the GPIO is not
present (i.e. -ENOENT), it may still return other error codes, like
-EPROBE_DEFER.  Currently these are not handled, leading to
unrecoverable failures later in case of probe deferral:

    gpiod_set_consumer_name: invalid GPIO (errorpointer)
    gpiod_direction_output: invalid GPIO (errorpointer)
    gpiod_set_value_cansleep: invalid GPIO (errorpointer)
    gpiod_set_value_cansleep: invalid GPIO (errorpointer)
    gpiod_set_value_cansleep: invalid GPIO (errorpointer)

Detect and propagate errors to fix this.

Fixes: f3186dd876697e69 ("spi: Optionally use GPIO descriptors for CS GPIOs")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-gpio: Remove spi->controller_data comment
Geert Uytterhoeven [Wed, 3 Apr 2019 14:46:02 +0000 (16:46 +0200)]
spi: spi-gpio: Remove spi->controller_data comment

The conversion from GPIO numbers to GPIO descriptors removed the use of
spi->controller_data, but forgot to update a comment referring to it.

Fixes: 9b00bc7b901ff672 ("spi: spi-gpio: Rewrite to use GPIO descriptors")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: add driver stats to debugfs
Martin Sperl [Sat, 30 Mar 2019 10:13:53 +0000 (10:13 +0000)]
spi: bcm2835aux: add driver stats to debugfs

To estimate efficiency add statistics on transfer types
(polling and interrupt) used to debugfs.

Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: sh-msiof: Add reset of registers before starting transfer
Geert Uytterhoeven [Tue, 2 Apr 2019 14:40:23 +0000 (16:40 +0200)]
spi: sh-msiof: Add reset of registers before starting transfer

In accordance with hardware specification Ver 1.0, reset register
transmission / reception setting before transfer.

Signed-off-by: Hiromitsu Yamasaki <hiromitsu.yamasaki.ym@renesas.com>
[geert: Use readl_poll_timeout_atomic()]
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: sh-msiof: Use readl_poll_timeout_atomic() instead of open-coding
Geert Uytterhoeven [Tue, 2 Apr 2019 14:40:22 +0000 (16:40 +0200)]
spi: sh-msiof: Use readl_poll_timeout_atomic() instead of open-coding

Replace the open-coded loop in sh_msiof_modify_ctr_wait() by a call to
the readl_poll_timeout_atomic() helper macro.

Suggested-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: lpspi: add missing complete in abort func at dma mode
Clark Wang [Tue, 2 Apr 2019 12:45:53 +0000 (12:45 +0000)]
spi: lpspi: add missing complete in abort func at dma mode

Add the missing complete operations for dma_completion to fix the
problem of blocking at the wait_for_completion_interruptible()
function when use spi_slave_abort().

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Drop unused pdata copy in struct spi_gpio
Andrey Smirnov [Wed, 3 Apr 2019 04:01:26 +0000 (21:01 -0700)]
spi: gpio: Drop unused pdata copy in struct spi_gpio

Drop unused pdata copy in struct spi_gpio. No functional change
intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Simplify SPI_MASTER_NO_TX check in spi_gpio_probe()
Andrey Smirnov [Wed, 3 Apr 2019 04:01:25 +0000 (21:01 -0700)]
spi: gpio: Simplify SPI_MASTER_NO_TX check in spi_gpio_probe()

Swap branches of the if statement in order to simplify it's logical
condition being checked. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Add local struct spi_bitbang pointer in spi_gpio_probe()
Andrey Smirnov [Wed, 3 Apr 2019 04:01:24 +0000 (21:01 -0700)]
spi: gpio: Add local struct spi_bitbang pointer in spi_gpio_probe()

Use a local "struct spi_bitbang *bb" in spi_gpio_probe() for
brevity. No functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Add local struct device pointer in spi_gpio_probe()
Andrey Smirnov [Wed, 3 Apr 2019 04:01:23 +0000 (21:01 -0700)]
spi: gpio: Add local struct device pointer in spi_gpio_probe()

Use a local "struct device *dev" in spi_gpio_probe() for brevity. No
functional change intended.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: gpio: Drop unused spi_to_pdata()
Andrey Smirnov [Wed, 3 Apr 2019 04:01:22 +0000 (21:01 -0700)]
spi: gpio: Drop unused spi_to_pdata()

Spi_to_pdata() is not used anywhere in the code. Drop it.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Chris Healy <cphealy@gmail.com>
Cc: linux-spi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: make the polling duration limits configurable
Martin Sperl [Sat, 30 Mar 2019 09:31:06 +0000 (09:31 +0000)]
spi: bcm2835aux: make the polling duration limits configurable

Under some circumstances the default 30 us polling limit is not optimal
and may lead to long delays because we are waiting on an interrupt.
with this patch we have the possibility to influence this policy.

So make this limit (in us) configurable via a module parameters
(but also modifyable via /sys/modules/...)

Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: setup gpio-cs to output and correct level during setup
Martin Sperl [Sat, 30 Mar 2019 09:31:04 +0000 (09:31 +0000)]
spi: bcm2835aux: setup gpio-cs to output and correct level during setup

Setup gpio-cs to the correct levels during setup and also make the
gpio definitely an output GPIO.

This is transparently fixing some badly configured DTs in the process
where cs-gpio is set but the gpios are still configured with native cs.

It also makes 100% sure that the initial CS levels are as expected -
especially on systems with devices on a bus with mixed CS_HIGH/CS_LOW
settings.

Fixes: 1ea29b39f4c812ec ("spi: bcm2835aux: add bcm2835 auxiliary spi device...")
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: warn in dmesg that native cs is not really supported
Martin Sperl [Sat, 30 Mar 2019 09:31:03 +0000 (09:31 +0000)]
spi: bcm2835aux: warn in dmesg that native cs is not really supported

From personal bad experience (even as the author of the original driver)
it shows that native-cs is "somewhat" supported by the spi bus driver
when using a buggy device tree.

So make sure that the driver is warning in dmesg about this fact
that we are running in a not supported mode that may have surprizing
limitations.

Fixes: 1ea29b39f4c812ec ("spi: bcm2835aux: add bcm2835 auxiliary spi device...")
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: fix driver to not allow 65535 (=-1) cs-gpios
Martin Sperl [Sat, 30 Mar 2019 09:31:02 +0000 (09:31 +0000)]
spi: bcm2835aux: fix driver to not allow 65535 (=-1) cs-gpios

The original driver by default defines num_chipselects as -1.
This actually allicates an array of 65535 entries in
of_spi_register_master.

There is a side-effect for buggy device trees that (contrary to
dt-binding documentation) have no cs-gpio defined.

This mode was never supported by the driver due to limitations
of native cs and additional code complexity and is explicitly
not stated to be implemented.

To keep backwards compatibility with such buggy DTs we limit
the number of chip_selects to 1, as for all practical purposes
it is only ever realistic to use a single chip select in
native cs mode without negative side-effects.

Fixes: 1ea29b39f4c812ec ("spi: bcm2835aux: add bcm2835 auxiliary spi device...")
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: remove dead code
Martin Sperl [Sat, 30 Mar 2019 09:31:01 +0000 (09:31 +0000)]
spi: bcm2835aux: remove dead code

Remove dead code that never can get reached, as we limit count to
a max of 3.

Suggested-by: Hubert Denkmair <h.denkmair@intence.de>
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: fix corruptions for longer spi transfers
Martin Sperl [Sat, 30 Mar 2019 09:31:00 +0000 (09:31 +0000)]
spi: bcm2835aux: fix corruptions for longer spi transfers

On long running tests with a mcp2517fd can controller it showed that
on rare occations the data read shows corruptions for longer spi transfers.

Example of a 22 byte transfer:

expected (as captured on logic analyzer):
FF FF 78 00 00 00 08 06 00 00 91 20 77 56 84 85 86 87 88 89 8a 8b

read by the driver:
FF FF 78 00 00 00 08 06 00 00 91 20 77 56 84 88 89 8a 00 00 8b 9b

To fix this use BCM2835_AUX_SPI_STAT_RX_LVL to determine when we may
read data from the fifo reliably without any corruption.

Surprisingly the only values ever empirically read in
BCM2835_AUX_SPI_STAT_RX_LVL are 0x00, 0x10, 0x20 and 0x30.
So whenever the mask is not 0 we can read from the fifo in a safe manner.

The patch has now been tested intensively and we are no longer
able to reproduce the "RX" issue any longer.

Fixes: 1ea29b39f4c812ec ("spi: bcm2835aux: add bcm2835 auxiliary spi device...")
Reported-by: Hubert Denkmair <h.denkmair@intence.de>
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: remove dangerous uncontrolled read of fifo
Martin Sperl [Sat, 30 Mar 2019 09:30:59 +0000 (09:30 +0000)]
spi: bcm2835aux: remove dangerous uncontrolled read of fifo

This read of the fifo is a potential candidate for a race condition
as the spi transfer is not necessarily finished and so can lead to
an early read of the fifo that still misses data.

So it has been removed.

Fixes: 1ea29b39f4c812ec ("spi: bcm2835aux: add bcm2835 auxiliary spi device...")
Suggested-by: Hubert Denkmair <h.denkmair@intence.de>
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: bcm2835aux: unifying code between polling and interrupt driven code
Martin Sperl [Sat, 30 Mar 2019 09:30:58 +0000 (09:30 +0000)]
spi: bcm2835aux: unifying code between polling and interrupt driven code

Sharing more code between polling and interrupt-driven mode.

Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-mem: export spi_mem_default_supports_op()
Naga Sureshkumar Relli [Mon, 1 Apr 2019 07:59:00 +0000 (13:29 +0530)]
spi: spi-mem: export spi_mem_default_supports_op()

Export spi_mem_default_supports_op(), so that controller drivers
can use this.
spi-mem driver already exports this using EXPORT_SYMBOL,
but not declared it in spi-mem.h.
This patch declares spi_mem_default_supports_op() in spi-mem.h and
also removes the static from the function prototype.

Signed-off-by: Naga Sureshkumar Relli <naga.sureshkumar.relli@xilinx.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: sh-msiof: Use BIT() and GENMASK()
Geert Uytterhoeven [Tue, 2 Apr 2019 14:40:21 +0000 (16:40 +0200)]
spi: sh-msiof: Use BIT() and GENMASK()

Improve maintainability by converting the register bit, bitmask, and
bitfield definitions from hexadecimal constants to constructs using
BIT(), GENMASK(), or "val << shift".

Suggested-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-fsl-spi: automatically adapt bits-per-word in cpu mode
Rasmus Villemoes [Wed, 27 Mar 2019 14:30:52 +0000 (14:30 +0000)]
spi: spi-fsl-spi: automatically adapt bits-per-word in cpu mode

Taking one interrupt for every byte is rather slow. Since the
controller is perfectly capable of transmitting 32 bits at a time,
change t->bits_per-word to 32 when the length is divisible by 4 and
large enough that the reduced number of interrupts easily compensates
for the one or two extra fsl_spi_setup_transfer() calls this causes.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-fsl-spi: allow changing bits_per_word while CS is still active
Rasmus Villemoes [Wed, 27 Mar 2019 14:30:51 +0000 (14:30 +0000)]
spi: spi-fsl-spi: allow changing bits_per_word while CS is still active

Commit c9bfcb315104 (spi_mpc83xx: much improved driver) introduced
logic to ensure bits_per_word and speed_hz stay the same for a series
of spi_transfers with CS active, arguing that

    The current driver may cause glitches on SPI CLK line since one
    must disable the SPI controller before changing any HW settings.

This sounds quite reasonable. So this is a quite naive attempt at
relaxing this sanity checking to only ensure that speed_hz is
constant - in the faint hope that if we do not causes changes to the
clock-related fields of the SPMODE register (DIV16 and PM), those
glitches won't appear.

The purpose of this change is to allow automatically optimizing large
transfers to use 32 bits-per-word; taking one interrupt for every byte
is extremely slow.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: pxa2xx: Unify remaing prints in pxa2xx_spi_transfer_one()
Jarkko Nikula [Fri, 29 Mar 2019 13:00:46 +0000 (15:00 +0200)]
spi: pxa2xx: Unify remaing prints in pxa2xx_spi_transfer_one()

Use SPI device pointer in the remaining two error and warning prints in
pxa2xx_spi_transfer_one() instead of platform device of the controller

It make prints in the function uniform and more useful especially the
error print here as it can reveal the driver that has mapped the DMA
itself and attempts to transfer more than the maximum supported DMA
transfer length.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: pxa2xx: Use struct spi_device directly in pxa2xx_spi_transfer_one()
Jarkko Nikula [Fri, 29 Mar 2019 13:00:45 +0000 (15:00 +0200)]
spi: pxa2xx: Use struct spi_device directly in pxa2xx_spi_transfer_one()

Pointer to a SPI device is passed to pxa2xx_spi_transfer_one() so there
is no need to access it through the current SPI message pointer.

Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: add SPI_LSB_FIRST support
Sowjanya Komatineni [Wed, 27 Mar 2019 05:56:33 +0000 (22:56 -0700)]
spi: tegra114: add SPI_LSB_FIRST support

Tegra SPI controller supports lsb first mode. Default is MSB bit first
and on selection of SPI_LSB_FIRST through SPI mode transmission happens
with LSB bit first.

This patch adds SPI_LSB_FIRST flag to mode_bits and also configures it
on request.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: use packed mode for 32 bits per word
Sowjanya Komatineni [Wed, 27 Mar 2019 05:56:25 +0000 (22:56 -0700)]
spi: tegra114: use packed mode for 32 bits per word

Fixes: Use packed mode for 32 bits per word transfers to increase
performance as each packet is a full 32-bit word.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-fsl-spi: relax message sanity checking a little
Rasmus Villemoes [Wed, 27 Mar 2019 14:30:51 +0000 (14:30 +0000)]
spi: spi-fsl-spi: relax message sanity checking a little

The comment says that we should not allow changes (to
bits_per_word/speed_hz) while CS is active, and indeed the code below
does fsl_spi_setup_transfer() when the ->cs_change of the previous
spi_transfer was set (and for the very first transfer).

So the sanity checking is a bit too strict - we can change it to
follow the same logic as is used by the actual transfer loop.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: spi-fsl-spi: remove always-true conditional in fsl_spi_do_one_msg
Rasmus Villemoes [Wed, 27 Mar 2019 14:30:50 +0000 (14:30 +0000)]
spi: spi-fsl-spi: remove always-true conditional in fsl_spi_do_one_msg

__spi_validate() in the generic SPI code sets ->speed_hz and
->bits_per_word to non-zero values, so this condition is always true.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: reset controller on probe
Sowjanya Komatineni [Wed, 27 Mar 2019 05:56:32 +0000 (22:56 -0700)]
spi: tegra114: reset controller on probe

Fixes: SPI driver can be built as module so perform SPI controller reset
on probe to make sure it is in valid state before initiating transfer.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: configure dma burst size to fifo trig level
Sowjanya Komatineni [Wed, 27 Mar 2019 05:56:29 +0000 (22:56 -0700)]
spi: tegra114: configure dma burst size to fifo trig level

Fixes: Configure DMA burst size to be same as SPI TX/RX trigger levels
to avoid mismatch.

SPI FIFO trigger levels are calculated based on the transfer length.
So this patch moves DMA slave configuration to happen before start
of DMAs.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: flush fifos
Sowjanya Komatineni [Wed, 27 Mar 2019 05:56:28 +0000 (22:56 -0700)]
spi: tegra114: flush fifos

Fixes: Flush TX and RX FIFOs before start of new transfer and on FIFO
overflow or underrun errors.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: terminate dma and reset on transfer timeout
Sowjanya Komatineni [Wed, 27 Mar 2019 05:56:27 +0000 (22:56 -0700)]
spi: tegra114: terminate dma and reset on transfer timeout

Fixes: terminate DMA and perform controller reset on transfer timeout
to clear the FIFO's and errors.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: fix for unpacked mode transfers
Sowjanya Komatineni [Wed, 27 Mar 2019 05:56:24 +0000 (22:56 -0700)]
spi: tegra114: fix for unpacked mode transfers

Fixes: computation of actual bytes to fill/receive in/from FIFO in unpacked
mode when transfer length is not a multiple of requested bits per word.

unpacked mode transfers fails when the transfer includes partial bytes in
the last word.

Total words to be written/read to/from FIFO is computed based on transfer
length and bits per word. Unpacked mode includes 0 padding bytes for partial
words to align with bits per word and these extra bytes are also accounted
for calculating bytes left to transfer in the current driver.

This causes extra bytes access of tx/rx buffers along with buffer index
position crossing actual length where remain_len becomes negative and due to
unsigned type, negative value is a 32 bit representation of signed value
and transferred bytes never meets the actual transfer length resulting in
transfer timeout and a hang.

This patch fixes this with proper computation of the actual bytes to fill in
FIFO during transmit and the actual bytes to read from FIFO during receive
ignoring 0 padded bytes.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra114: clear packed bit for unpacked mode
Sowjanya Komatineni [Wed, 27 Mar 2019 05:56:23 +0000 (22:56 -0700)]
spi: tegra114: clear packed bit for unpacked mode

Fixes: Clear packed bit when not using packed mode.

Packed bit is not cleared when not using packed mode. This results
in transfer timeouts for the unpacked mode transfers followed by the
packed mode transfers.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: pic32: fix dma channels termination
Cezary Gapinski [Tue, 26 Mar 2019 21:48:59 +0000 (22:48 +0100)]
spi: pic32: fix dma channels termination

When timeout occurs DMA TX and RX channels should be stopped
instead of stopping RX channel twice time.

Signed-off-by: Cezary Gapinski <cezary.gapinski@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: tegra20-slink: change chip select action order
Randolph Maaßen [Tue, 26 Mar 2019 14:30:50 +0000 (15:30 +0100)]
spi: tegra20-slink: change chip select action order

To transfer via SPI the tegra20-slink driver first sets the command
register, which contains the chip select value, and after that the
command2 register, which contains the chip select line. This leads to a
small spike in the chip selct 0 line between the set of the value and
the selection of the chip select line.

This commit changes the order of the register writes so that first the
chip select line is chosen and then the value is set, removing the
spike.

Signed-off-by: Randolph Maaßen <gaireg@gaireg.de>
Reviewed-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: stm32-qspi: add dma support
Ludovic Barre [Mon, 25 Mar 2019 17:01:40 +0000 (18:01 +0100)]
spi: stm32-qspi: add dma support

This patch adds the dma support for the stm32-qspi hardware.
The memory buffer constraints (lowmem, vmalloc, kmap) are taken into
account by framework. In read mode, the memory map is preferred vs
dma (due to better throughput). If the dma transfer fails the buffer
is sent by polling.

Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: stm32-qspi: add spi_master_put in release function
Ludovic Barre [Mon, 25 Mar 2019 17:01:39 +0000 (18:01 +0100)]
spi: stm32-qspi: add spi_master_put in release function

This patch adds spi_master_put in release function
to drop the controller's refcount.

Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: mt7621: Move SPI driver out of staging
Stefan Roese [Mon, 25 Mar 2019 08:29:25 +0000 (09:29 +0100)]
spi: mt7621: Move SPI driver out of staging

This patch moves the MT7621 SPI driver, which is used on some Ralink /
MediaTek MT76xx MIPS SoC's, out of the staging directory. No changes to
the source code are done in this patch.

This driver version was tested successfully on an MT7688 based platform
with an SPI NOR on CS0 and an SPI NAND on CS1 without any issues (so
far).

This patch also documents the devicetree bindings for the MT7621 SPI
device driver.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Rob Herring <robh@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: NeilBrown <neil@brown.name>
Cc: Sankalp Negi <sankalpnegi2310@gmail.com>
Cc: Chuanhong Guo <gch981213@gmail.com>
Cc: John Crispin <john@phrozen.org>
Cc: Armando Miraglia <arma2ff0@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: at91-usart: Remove duplicated checking for spi->bits_per_word
Axel Lin [Thu, 21 Mar 2019 15:53:48 +0000 (23:53 +0800)]
spi: at91-usart: Remove duplicated checking for spi->bits_per_word

This checking is already done in __spi_validate_bits_per_word().

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: atmel-quadspi: Make atmel_qspi_get_name static
YueHaibing [Thu, 21 Mar 2019 15:16:56 +0000 (23:16 +0800)]
spi: atmel-quadspi: Make atmel_qspi_get_name static

Fix sparse warning:

drivers/spi/atmel-quadspi.c:369:12: warning:
 symbol 'atmel_qspi_get_name' was not declared. Should it be static?

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: export tracepoint symbols to modules
Arnd Bergmann [Thu, 21 Mar 2019 12:42:25 +0000 (13:42 +0100)]
spi: export tracepoint symbols to modules

The newly added tracepoints in the spi-mxs driver cause a link
error when the driver is a loadable module:

ERROR: "__tracepoint_spi_transfer_stop" [drivers/spi/spi-mxs.ko] undefined!
ERROR: "__tracepoint_spi_transfer_start" [drivers/spi/spi-mxs.ko] undefined!

I'm not quite sure where to put the export statements, but
directly after the inclusion of the header seems as good as
any other place.

Fixes: f3fdea3af405 ("spi: mxs: add tracing to custom .transfer_one_message callback")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: lpspi: fix dataloss when SS is inactivated between every words
Clark Wang [Thu, 21 Mar 2019 09:57:12 +0000 (09:57 +0000)]
spi: lpspi: fix dataloss when SS is inactivated between every words

If we don't use CONT to keep SS activated or use DMA mode without
cs-gpio, SS will be inactivated between every words. The word here
means the data sent once which length can be set as 1/2/4 bytes.

In the isr function, we read the FSR_RXCOUNT just behind the
fsl_lpspi_read_rx_fifo. This causes the value of FSR_RXCOUNT cannot
reflect whether there is still data not sent timely. So do this
judgement by FSR_TXCOUNT.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: pxa2xx: Debug print DMA burst size
Andy Shevchenko [Tue, 19 Mar 2019 15:48:43 +0000 (17:48 +0200)]
spi: pxa2xx: Debug print DMA burst size

It's useful during debug to see what DMA burst size is.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: pxa2xx: Introduce DMA burst size support
Andy Shevchenko [Tue, 19 Mar 2019 15:48:42 +0000 (17:48 +0200)]
spi: pxa2xx: Introduce DMA burst size support

Some masters may have different DMA burst size than hard coded default.
In such case respect the value given by DMA burst size provided via
platform data.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agospi: dw: Add support for an optional interface clock
Phil Edworthy [Tue, 19 Mar 2019 15:52:07 +0000 (15:52 +0000)]
spi: dw: Add support for an optional interface clock

The Synopsys SSI Controller has an interface clock, but most SoCs hide
this away. However, on some SoCs you need to explicitly enable the
interface clock in order to access the registers. Therefore, add support
for an optional interface clock.

Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com>
Signed-off-by: Gareth Williams <gareth.williams.jx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
5 years agodt-bindings: snps,dw-apb-ssi: Add optional clock bindings documentation
Gareth Williams [Tue, 19 Mar 2019 15:52:06 +0000 (15:52 +0000)]
dt-bindings: snps,dw-apb-ssi: Add optional clock bindings documentation

Add documentation to the Synopsys SPI dt-bindings to support an
optional interface clock that may be used for register access.

Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com>
Signed-off-by: Gareth Williams <gareth.williams.jx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>