Commit Graph

182 Commits

Author SHA1 Message Date
Mark Salter 44ae47f50f spi: spi-imx: spi_imx_transfer_one(): check for DMA transfer first
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit e85e9e0d8cb759013d6474011c227f92e442d746
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Wed, 16 Nov 2022 17:49:30 +0100

    The SPI framework checks for each transfer (with the struct
    spi_controller::can_dma callback) whether the driver wants to use DMA
    for the transfer. If the driver returns true, the SPI framework will
    map the transfer's data to the device, start the actual transfer and
    map the data back.

    In commit 07e759387788 ("spi: spi-imx: add PIO polling support") the
    spi-imx driver's spi_imx_transfer_one() function was extended. If the
    estimated duration of a transfer does not exceed a configurable
    duration, a polling transfer function is used. This check happens
    before checking if the driver decided earlier for a DMA transfer.

    If spi_imx_can_dma() decided to use a DMA transfer, and the user
    configured a big maximum polling duration, a polling transfer will be
    used. The DMA unmap after the transfer destroys the transferred data.

    To fix this problem check in spi_imx_transfer_one() if the driver
    decided for DMA transfer first, then check the limits for a polling
    transfer.

    Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
    Link: https://lore.kernel.org/all/20221111003032.82371-1-festevam@gmail.com
    Reported-by: Frieder Schrempf <frieder.schrempf@kontron.de>
    Reported-by: Fabio Estevam <festevam@gmail.com>
    Tested-by: Fabio Estevam <festevam@gmail.com>
    Cc: David Jander <david@protonic.nl>
    Cc: stable@vger.kernel.org
    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Tested-by: Frieder Schrempf <frieder.schrempf@kontron.de>
    Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
    Link: https://lore.kernel.org/r/20221116164930.855362-1-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 13:30:56 -05:00
Mark Salter e1e53f437f spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit db2d2dc9a0b58c6faefb6b002fdbed4f0362d1a4
Author: Frieder Schrempf <frieder.schrempf@kontron.de>
Date: Tue, 15 Nov 2022 19:10:00 +0100

    In case the requested bus clock is higher than the input clock, the correct
    dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but
    *fres is left uninitialized and therefore contains an arbitrary value.

    This causes trouble for the recently introduced PIO polling feature as the
    value in spi_imx->spi_bus_clk is used there to calculate for which
    transfers to enable PIO polling.

    Fix this by setting *fres even if no clock dividers are in use.

    This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set
    to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR
    flash.

    With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the
    following:

    spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000,
    post: 0, pre: 0

    Fixes: 6fd8b8503a ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds")
    Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
    Cc: Marc Kleine-Budde <mkl@pengutronix.de>
    Cc: David Jander <david@protonic.nl>
    Cc: Fabio Estevam <festevam@gmail.com>
    Cc: Mark Brown <broonie@kernel.org>
    Cc: Marek Vasut <marex@denx.de>
    Cc: stable@vger.kernel.org
    Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
    Tested-by: Fabio Estevam <festevam@gmail.com>
    Acked-by: Marek Vasut <marex@denx.de>
    Link: https://lore.kernel.org/r/20221115181002.2068270-1-frieder@fris.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 13:30:56 -05:00
Mark Salter dbe7090866 spi: spi-imx: mx51_ecspi_prepare_message(): skip writing MX51_ECSPI_CONFIG register if unchanged
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 184434fcd6177b76f929570348935d7c9f22d296
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:57 +0200

    In mx51_ecspi_prepare_message() the MX51_ECSPI_CONFIG register is
    setup for the current spi_message. After writing the register, there
    is a delay to ensure that the changes hit the hardware.

    This patch checks if the register MX51_ECSPI_CONFIG actually needs to
    be changed. If the register content is unchanged the function is left
    early, skipping the write to the hardware and the delay. This leads to
    a small, but measurable performance increase. For a given workload
    with small transfers on an imx6 single core the CPU load decreases
    from 30% to ~27%.

    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-10-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:48:57 -05:00
Mark Salter 179122fd04 spi: spi-imx: add PIO polling support
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 07e7593877882fbd07c55b26b7dcf88760449323
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:56 +0200

    The driver supports several modes, one of them is PIO/IRQ
    "spi_imx_pio_transfer()". The data is exchanged with the IP core using
    PIO, an IRQ is setup to signal empty/full FIFOs and the end of the
    transfer. The IRQ and scheduling overhead for short transfers is
    significant. Using polling instead of IRQs can be beneficial to reduce
    the overall CPU load, especially on small transfer workloads.

    On an imx6 single core, a given RX workload of the mcp251xfd driver
    results in 40% CPU load. Using polling mode reduces the CPU load to
    30%.

    This patch adds PIO polling support to the driver. For transfers with
    a duration of less than 30 µs the polling mode instead of IRQ based
    PIO mode is used. 30 µs seems to be a good compromise, which is used
    the by the SPI drivers for the raspberry Pi (spi-bcm2835,
    spi-bcm2835), too.

    Co-developed-by: David Jander <david@protonic.nl>
    Signed-off-by: David Jander <david@protonic.nl>
    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-9-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:48:22 -05:00
Mark Salter 9566dfd322 spi: spi-imx: replace struct spi_imx_data::bitbang by pointer to struct spi_controller
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 307c897db762d1e0feee9477276b08f6deca4a5b
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:55 +0200

    There's no need to embed the struct spi_bitbang into our private
    data (struct spi_imx_data), the spi core is flexible enough, so that
    we only need a pointer to the allocated struct spi_controller.

    This is also a preparation patch to add PIO based polling support to
    the driver.

    Co-developed-by: David Jander <david@protonic.nl>
    Signed-off-by: David Jander <david@protonic.nl>
    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-8-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:48:22 -05:00
Mark Salter 338384cfa1 spi: spi-imx: spi_imx_buf_rx_swap_u32(): replace open coded swahw32s()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit baaadffe8854ea14eed1a5f3c09f2136c3aa4427
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:53 +0200

    This patch replaces an open coded swahw32s().

    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-6-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:45:34 -05:00
Mark Salter 567d29a296 spi: spi-imx: spi_imx_buf_rx_swap_u32(): fix sparse warning: use swab32s() instead of cpu_to_be32()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit dae336d0dca669143e0fdf6b82c333bf6a8d9e0a
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:52 +0200

    This patch fixes the following sparse warning by using a swab32s()
    instead of a cpu_to_be32(). The driver is used on little endian
    systems only and we really want to swap the bytes.

    | drivers/spi/spi-imx.c:305:29: warning: incorrect type in assignment (different base types)
    | drivers/spi/spi-imx.c:305:29:    expected unsigned int val
    | drivers/spi/spi-imx.c:305:29:    got restricted __be32 [usertype]
    | drivers/spi/spi-imx.c:361:21: warning: incorrect type in assignment (different base types)
    | drivers/spi/spi-imx.c:361:21:    expected unsigned int [assigned] [usertype] val
    | drivers/spi/spi-imx.c:361:21:    got restricted __be32 [usertype]

    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-5-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:45:34 -05:00
Mark Salter 78f080bbe0 spi: spi-imx: mx51_ecspi_intctrl(): prefer 'unsigned int' to bare use of 'unsigned'
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 1a23461a8a08c4a32972dec31a394eee3302511d
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:51 +0200

    This patch fixes the following checkpatch warning, by making val an
    "unsigned int".

    | WARNING: Prefer 'unsigned int' to bare use of 'unsigned'
    | +       unsigned val = 0;

    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-4-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:45:34 -05:00
Mark Salter 01ca66408b spi: spi-imx: avoid unnecessary line continuations
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit a8c785c1e75538876b524247a3738db53b1f78b8
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:50 +0200

    This patch fixes the following checkpatch warning by removing the
    trailing backslash:

    | WARNING: Avoid unnecessary line continuations
    | +       spi_imx->bitbang.master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \

    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-3-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:45:34 -05:00
Mark Salter 1f5b237f93 spi: spi-imx: fix sparse warning: add identifier name to function definition
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit f7b8787164551a09fca287b1dea15d0c4d646e4a
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:49 +0200

    This patch fixes the following and similar sparse warnings by adding
    the missing identifier names to the function definitions:

    | WARNING: function definition argument 'struct spi_imx_data *' should also have an identifier name
    | #68: FILE: drivers/spi/spi-imx.c:68:
    | +       int (*prepare_message)(struct spi_imx_data *, struct spi_message *);

    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-2-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:45:33 -05:00
Mark Salter f498afc99b spi: spi-imx: complete conversion from master -> controller
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 63cd96b70f9366f67048fbc07294ce5823001ded
Author: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 2 May 2022 19:54:54 +0200

    With patch:
    | 8caab75fd2 ("spi: Generalize SPI "master" to "controller"")
    the SPI "master" was generalized to "controller". This patch completed
    the conversion of the spi-imx driver by replacing the remaining
    occurrences of master to controller.

    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Link: https://lore.kernel.org/r/20220502175457.1977983-7-mkl@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:45:33 -05:00
Mark Salter b7b57c3432 spi: spi-imx: using pm_runtime_resume_and_get instead of pm_runtime_get_sync
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 7d34ff58f35c82207698f43af79817a05e1342e5
Author: Minghao Chi <chi.minghao@zte.com.cn>
Date: Thu, 14 Apr 2022 08:53:42 +0000

    Using pm_runtime_resume_and_get() to replace pm_runtime_get_sync and
    pm_runtime_put_noidle. This change is just to simplify the code, no
    actual functional changes.

    Reported-by: Zeal Robot <zealci@zte.com.cn>
    Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
    Link: https://lore.kernel.org/r/20220414085343.2541608-1-chi.minghao@zte.com.cn
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:44:23 -05:00
Mark Salter 1e91a2280a spi: spi-imx: add support for SPI_RX_CPHA_FLIP
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 79422ed9bd7fbd79f84d8a5abb0094c16221f55b
Author: Baruch Siach <baruch.siach@siklu.com>
Date: Mon, 11 Apr 2022 21:45:29 +0300

    When SPI_RX_CPHA_FLIP is set, flip CPHA on Rx only transfers. This is
    useful to access devices that use inverted CPHA for MISO vs MOSI
    signals.

    Only support the mx51/mx53 variants for now.

    Tested on i.MX6ULL based system.

    Signed-off-by: Baruch Siach <baruch.siach@siklu.com>
    Link: https://lore.kernel.org/r/e11b4446afe9a46a282dd923d22c27d03fae15f8.1649702729.git.baruch@tkos.co.il
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:44:22 -05:00
Mark Salter 45907eb0cf spi: imx: Implement support for CS_WORD
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 6e95b23a5b2d1fcbe5a84a362170a4871a3d5731
Author: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
Date: Tue, 27 Jul 2021 14:42:26 +0200

    This only works when the native chipselect is in use. On a board with a
    Ti ADS7950 8 channel ADC. This patch reduces the time to read out all
    channels once from 280 us to 20 us.

    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Link: https://lore.kernel.org/r/20210727124226.5571-1-u.kleine-koenig@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:44:19 -05:00
Mark Salter 8455640773 spi: imx: remove ERR009165 workaround on i.mx6ul
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 8eb1252bbedfb0e800bbbd3e9055a7db0ae2cac9
Author: Robin Gong <yibin.gong@nxp.com>
Date: Wed, 14 Jul 2021 18:20:48 +0800

    ERR009165 fixed on i.mx6ul/6ull/6sll. All other i.mx6/7 and
    i.mx8m/8mm still need this errata. Please refer to nxp official
    errata document from https://www.nxp.com/ .

    For removing workaround on those chips. Add new i.mx6ul type.

    Signed-off-by: Robin Gong <yibin.gong@nxp.com>
    Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
    Acked-by: Mark Brown <broonie@kernel.org>
    Signed-off-by: Shawn Guo <shawnguo@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:44:19 -05:00
Mark Salter 8de3ee8ca4 spi: imx: fix ERR009165
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit 980f884866eed4dda2a18de888c5a67dde67d640
Author: Robin Gong <yibin.gong@nxp.com>
Date: Wed, 14 Jul 2021 18:20:47 +0800

    Change to XCH  mode even in dma mode, please refer to the below
    errata:
    https://www.nxp.com/docs/en/errata/IMX6DQCE.pdf

    Signed-off-by: Robin Gong <yibin.gong@nxp.com>
    Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
    Acked-by: Mark Brown <broonie@kernel.org>
    Signed-off-by: Shawn Guo <shawnguo@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:44:18 -05:00
Mark Salter 5ed725a00a spi: imx: Simplify logic in spi_imx_push()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071848
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122415

commit bd9616996bb8cd6fbceedf00f1aa72fd9a845519
Author: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
Date: Fri, 16 Jul 2021 19:39:27 +0200

    For each usage of fifo_words it is clear if ->dynamic_burst is true or
    not. This can be used to simplify the function a bit.

    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Reviewed-by: Fabio Estevam <festevam@gmail.com>
    Link: https://lore.kernel.org/r/20210716173927.2050620-1-u.kleine-koenig@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

Signed-off-by: Mark Salter <msalter@redhat.com>
2023-01-26 12:44:18 -05:00
Jerry Snitselaar 97befdbb38 dmaengine: imx: Move header to include/dma/
Bugzilla: https://bugzilla.redhat.com/2112028
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit c6547c2ed0e1487c91983faccad841611ab6a783
Author: Sascha Hauer <s.hauer@pengutronix.de>
Date:   Thu Apr 14 18:22:37 2022 +0200

    dmaengine: imx: Move header to include/dma/

    The i.MX DMA drivers are device tree only, nothing in
    include/linux/platform_data/dma-imx.h has platform_data in it, so move
    the file to include/linux/dma/imx-dma.h.

    Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
    Acked-By: Vinod Koul <vkoul@kernel.org>
    Link: https://lore.kernel.org/r/20220414162249.3934543-10-s.hauer@pengutronix.de
    Signed-off-by: Mark Brown <broonie@kernel.org>

(cherry picked from commit c6547c2ed0e1487c91983faccad841611ab6a783)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
2022-08-31 15:33:03 -07:00
Marek Vasut 36c2530ea9
spi: imx: mx51-ecspi: Fix CONFIGREG delay comment
For (2 * 1000000) / min_speed_hz < 10 to be true in naturals with zero,
the min_speed_hz must be above 200000 (i.e. 200001 rounds down to 9, so
the condition triggers). Update the comment. No functional change.

Fixes: 6fd8b8503a ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds")
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Mark Brown <broonie@kernel.org>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20210727160428.7673-1-marex@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-07-28 16:39:22 +01:00
Marek Vasut 53ca18acbe
spi: imx: mx51-ecspi: Fix low-speed CONFIGREG delay calculation
The spi_imx->spi_bus_clk may be uninitialized and thus also zero in
mx51_ecspi_prepare_message(), which would lead to division by zero
in kernel. Since bitbang .setup_transfer callback which initializes
the spi_imx->spi_bus_clk is called after bitbang prepare_message
callback, iterate over all the transfers in spi_message, find the
one with lowest bus frequency, and use that bus frequency for the
delay calculation.

Note that it is not possible to move this CONFIGREG delay back into
the .setup_transfer callback, because that is invoked too late, after
the GPIO chipselects were already configured.

Fixes: 135cbd378e ("spi: imx: mx51-ecspi: Reinstate low-speed CONFIGREG delay")
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210726100102.5188-1-marex@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-07-26 18:57:14 +01:00
Marek Vasut 135cbd378e
spi: imx: mx51-ecspi: Reinstate low-speed CONFIGREG delay
Since 00b80ac935 ("spi: imx: mx51-ecspi: Move some initialisation to
prepare_message hook."), the MX51_ECSPI_CONFIG write no longer happens
in prepare_transfer hook, but rather in prepare_message hook, however
the MX51_ECSPI_CONFIG delay is still left in prepare_transfer hook and
thus has no effect. This leads to low bus frequency operation problems
described in 6fd8b8503a ("spi: spi-imx: Fix out-of-order CS/SCLK
operation at low speeds") again.

Move the MX51_ECSPI_CONFIG write delay into the prepare_message hook
as well, thus reinstating the low bus frequency fix.

Fixes: 00b80ac935 ("spi: imx: mx51-ecspi: Move some initialisation to prepare_message hook.")
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20210703022300.296114-1-marex@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-07-07 12:01:35 +01:00
Linus Torvalds b71428d7ab sound updates for 5.13
No surprises in this development cycle, and most of works are about
 the fixes and the improvements of the existing code, while a new LED
 control layer and a few new drivers have been introduced.
 
 Here are some highlights:
 
 Core:
 - A common mute-LED framework was introduced;
   used by HD-audio for now, more adaption will follow later.
   The former "Mic Mute-LED Mode" mixer control has been replaced with
   the corresponding sysfs now.
 - User-control management was changed to count consumed bytes instead
   of capping by number of elements;
   this will allow more controls in the normal usage pattern while
   avoiding the possible memory exhaustion DoS
 
 ASoC:
 - Continued refactoring and cleanups in ASoC core and generic card
   drivers
 - Wide range of small cppcheck and warning fixes
 - New drivers for Freescale i.MX DMA over rpmsg, Mediatek MT6358
    accessory detection, and Realtek RT1019, RT1316, RT711 and RT715
 
 USB-audio:
 - Continued improvements and fixes of the implicit feedback mode,
   including better support for Pioneer and Roland/BOSS devices
 
 HD-audio:
 - Default back to non-buffer preallocation on x86
 - Cirrus codec improvements, more quirks for Realtek codecs
 
 Others:
 - New virtio sound driver
 - FireWire Bebob updates
 
 Note that this PR includes a couple of changes in reset and SPI
 drivers, too, and some merge conflicts might happen.
 -----BEGIN PGP SIGNATURE-----
 
 iQJCBAABCAAsFiEEIXTw5fNLNI7mMiVaLtJE4w1nLE8FAmCMJaAOHHRpd2FpQHN1
 c2UuZGUACgkQLtJE4w1nLE/T6A//Ti0SAWYnAr5l/7ccuwS4zljHcuHngwvIxRPY
 BokU1ZUlagi+Ro2HLUq13G8T4AlUAQ8r2ecz7EJQHHl9tkrIg7Cc0+fiBPHju1Yu
 0F3Vjc78/JsJHvAR2DPll2rwhsdD3usSQXFo181k38J098X02iNcrzsj3kW5Bpzb
 DBvXzOBIAg/PPfPa4edSYsSurqYeZTkhshedTohlwOCnVbW9NN5b5T9yoXP+t5na
 rvK1Vhu0He8nVMBPDrzjKgE5rjm7Kn0FNXZ6CMDekU9sRVzm/PbgAqqmRnn6bUKa
 GDpcQzlaiDrw8a7/uTVgUZy85F9kMXMMnfYpBy4bBXOt6RWOplXY1yMxy1RXV+op
 3qC9k5R+IsjSWFQZ2z5bIHtGBNCG0698z9fQcvpsWTv+R68rUyfj+jeO/G9zzvpi
 qpQTloBfI28NoP+iGis7wtrlQ15ut47YMCQS8QiOEvLmd5/3xKXRut4Ac/VmvDpS
 q7fLivL8MZ/SMoXY74q/kByMBkXNpryQCAN+xAslaJ5P0aefNYJJdBt/sJlsDd9J
 Ya2VIxHoP+Sb1MG6OLq1Y8c53Di9lwY80pOtF3plcz/ZWgzipirf6BhFj0OttiKP
 a6+VewXA7zZcWEdw+Ik4dWP2dybWL+CuNl7Bwug8SyG9iWqg8Ph7FgoCTWAi93Fx
 KKUJxsc=
 =YT3U
 -----END PGP SIGNATURE-----

Merge tag 'sound-5.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound

Pull sound updates from Takashi Iwai:
 "No surprises in this development cycle, and most of work is about the
  fixes and the improvements of the existing code, while a new LED
  control layer and a few new drivers have been introduced.

  Here are some highlights:

  Core:
   - A common mute-LED framework was introduced. It is used by HD-audio
     for now, more adaption will follow later. The former "Mic Mute-LED
     Mode" mixer control has been replaced with the corresponding sysfs
     now.
   - User-control management was changed to count consumed bytes instead
     of capping by number of elements; this will allow more controls in
     the normal usage pattern while avoiding the possible memory
     exhaustion DoS

  ASoC:
   - Continued refactoring and cleanups in ASoC core and generic card
     drivers
   - Wide range of small cppcheck and warning fixes
   - New drivers for Freescale i.MX DMA over rpmsg, Mediatek MT6358
     accessory detection, and Realtek RT1019, RT1316, RT711 and RT715

  USB-audio:
   - Continued improvements and fixes of the implicit feedback mode,
     including better support for Pioneer and Roland/BOSS devices

  HD-audio:
   - Default back to non-buffer preallocation on x86
   - Cirrus codec improvements, more quirks for Realtek codecs

  Others:
   - New virtio sound driver
   - FireWire Bebob updates"

* tag 'sound-5.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (587 commits)
  ALSA: hda/conexant: Re-order CX5066 quirk table entries
  ALSA: hda/realtek: Remove redundant entry for ALC861 Haier/Uniwill devices
  ALSA: hda/realtek: Re-order ALC662 quirk table entries
  ALSA: hda/realtek: Re-order remaining ALC269 quirk table entries
  ALSA: hda/realtek: Re-order ALC269 Lenovo quirk table entries
  ALSA: hda/realtek: Re-order ALC269 Sony quirk table entries
  ALSA: hda/realtek: Re-order ALC269 ASUS quirk table entries
  ALSA: hda/realtek: Re-order ALC269 Dell quirk table entries
  ALSA: hda/realtek: Re-order ALC269 Acer quirk table entries
  ALSA: hda/realtek: Re-order ALC269 HP quirk table entries
  ALSA: hda/realtek: Re-order ALC882 Clevo quirk table entries
  ALSA: hda/realtek: Re-order ALC882 Sony quirk table entries
  ALSA: hda/realtek: Re-order ALC882 Acer quirk table entries
  ALSA: usb-audio: Remove redundant assignment to len
  ALSA: hda/realtek: Add quirk for Intel Clevo PCx0Dx
  ALSA: virtio: fix kernel-doc
  ALSA: hda/cirrus: Use CS8409 filter to fix abnormal sounds on Bullseye
  ALSA: hda/cirrus: Set Initial DMIC volume for Bullseye to -26 dB
  ALSA: sb: Fix two use after free in snd_sb_qsound_build
  ALSA: emu8000: Fix a use after free in snd_emu8000_create_mixer
  ...
2021-04-30 12:48:14 -07:00
Clark Wang 4df2f5e137
spi: imx: add a check for speed_hz before calculating the clock
When some drivers use spi to send data, spi_transfer->speed_hz is
not assigned. If spidev->max_speed_hz is not assigned as well, it
will cause an error in configuring the clock.
Add a check for these two values before configuring the clock. An
error will be returned when they are not assigned.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Link: https://lore.kernel.org/r/20210408103347.244313-2-xiaoning.wang@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-04-09 13:44:01 +01:00
Tian Tao 200d925e23
spi: imx: Use of_device_get_match_data() helper
Use the of_device_get_match_data() helper instead of open coding.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
Link: https://lore.kernel.org/r/1616385476-53327-1-git-send-email-tiantao6@hisilicon.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-03-25 13:58:55 +00:00
Fabio Estevam 92bad4a4c7
spi: imx: Improve driver description
"SPI Controller driver" is a too generic description.

Make it i.MX specific instead.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20210316180922.239805-1-festevam@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-03-17 13:10:49 +00:00
Guido Günther 8346633f2c
spi: imx: Don't print error on -EPROBEDEFER
This avoids

[    0.962538] spi_imx 30820000.spi: bitbang start failed with -517

durig driver probe.

Fixes: 8197f489f4 ("spi: imx: Fix failure path leak on GPIO request error correctly")
Signed-off-by: Guido Günther <agx@sigxcpu.org>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/0f51ab42e7c7a3452f2f8652794d81584303ea0d.1610987414.git.agx@sigxcpu.org
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-01-19 14:09:26 +00:00
Mark Brown db4a831997
Merge branch 'for-5.10' of https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi into spi-5.11 2020-11-27 16:18:32 +00:00
Clark Wang 7cd7120296
spi: imx: fix the unbalanced spi runtime pm management
If set active without increase the usage count of pm, the dont use
autosuspend function will call the suspend callback to close the two
clocks of spi because the usage count is reduced to -1.
This will cause the warning dump below when the defer-probe occurs.

[  129.379701] ecspi2_root_clk already disabled
[  129.384005] WARNING: CPU: 1 PID: 33 at drivers/clk/clk.c:952 clk_core_disable+0xa4/0xb0

So add the get noresume function before set active.

Fixes: 43b6bf406c spi: imx: fix runtime pm support for !CONFIG_PM
Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Link: https://lore.kernel.org/r/20201124085247.18025-1-xiaoning.wang@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-24 14:14:02 +00:00
Fabio Estevam 6e3dbfcb3c
spi: imx: Remove unused .id_table support
Since 5.10-rc1 i.MX is a devicetree-only platform and the existing
.id_table support in this driver was only useful for old non-devicetree
platforms.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20201116202606.29888-1-festevam@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-17 18:54:01 +00:00
Zhang Qilong 1dcbdd9448
spi: imx: fix reference leak in two imx operations
pm_runtime_get_sync will increment pm usage counter even it
failed. Forgetting to pm_runtime_put_noidle will result in
reference leak in callers(spi_imx_prepare_message and
spi_imx_remove), so we should fix it.

Fixes: 525c9e5a32 ("spi: imx: enable runtime pm support")
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201102145835.4765-1-zhangqilong3@huawei.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-11-10 15:59:10 +00:00
Mark Brown 3bfd5f422f Linux 5.10-rc1
-----BEGIN PGP SIGNATURE-----
 
 iQFSBAABCAA8FiEEq68RxlopcLEwq+PEeb4+QwBBGIYFAl+V+LMeHHRvcnZhbGRz
 QGxpbnV4LWZvdW5kYXRpb24ub3JnAAoJEHm+PkMAQRiGGQoH/1FIf6373lekuQf0
 pSq+2PPeILjL6+BppjNGJdwTKTEFEaz7xBpDwZURW2dt0M5jib2sn/0VJ/lh0Ln3
 880hXPjVyziU7/p1vTiPFYwKxav/ZE5cHrEW+nKimucyYPgkDxikFRuvrPQ1M0Sc
 vLZMmwjQlBD1kTsh9WR5lQ9Z8KqUtOazW47AbWE5QTTCQPmIXIdqByqLXlqS46Ok
 gW8tqaCI+FpBLP3fJn0EX5UTYH1Tsj9TmIFE8jqm5lGa/+VDM5KNyczEosKv86Xk
 0hBEUbAAZWdwieySJwBH7Njqu9g1o7bRUIJJsbXm0Fcnu+Ft619r3mJkkkXaaWKN
 mk7M/Uk=
 =1dE8
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAl+Z5IsACgkQJNaLcl1U
 h9Cvdgf+N7vBWWbr4UlB7oXxZenMd/xolkHGoYmbCIuVu3ZIxKd+sLddCvT/VYN1
 yhKHM4ctr/i8RWOXEr+fWyn8Ry2y0yQO5ROATY2nOAfakXYAmI3dIAoYVLaFk8JK
 oTaWq86/Ozfg+9UgPJfZvNJZieOLou9d0HaYjE7mocJ9Rw7Ugl4XydPaRFBALv1f
 hQITqTp8mUlYwda35dniiTiZDVAhsYzSYc3rQP7iDK6gL39EJlyFhttLH5m8YpE7
 560l0JZwvXZYD6JGlPfU6UTPQYzJp2F0ZdAMt2p9e54juw5RawtXWXeJOAkMEfae
 uPMIlGxwPN5+uYC82DRQS2WHJDLFTw==
 =weSU
 -----END PGP SIGNATURE-----

Merge tag 'v5.10-rc1' into spi-5.10

Linux 5.10-rc1
2020-10-28 21:36:51 +00:00
Mark Brown 2ee1b42e8a
Merge existing fixes from spi/for-5.10 2020-10-26 20:28:19 +00:00
Sascha Hauer 43b6bf406c
spi: imx: fix runtime pm support for !CONFIG_PM
525c9e5a32 introduced pm_runtime support for the i.MX SPI driver. With
this pm_runtime is used to bring up the clocks initially. When CONFIG_PM
is disabled the clocks are no longer enabled and the driver doesn't work
anymore. Fix this by enabling the clocks in the probe function and
telling pm_runtime that the device is active using
pm_runtime_set_active().

Fixes: 525c9e5a32 spi: imx: enable runtime pm support
Tested-by: Christian Eggers <ceggers@arri.de> [tested for !CONFIG_PM only]
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Link: https://lore.kernel.org/r/20201021104513.21560-1-s.hauer@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-10-23 18:29:00 +01:00
Mark Brown 9887311813
Merge remote-tracking branch 'spi/for-5.10' into spi-next 2020-10-09 16:01:22 +01:00
Marek Vasut 45f0bbdafd
spi: imx: Fix freeing of DMA channels if spi_bitbang_start() fails
If the SPI controller has has_dmamode = true and spi_bitbang_start() fails
in spi_imx_probe(), then the driver must release the DMA channels acquired
in spi_imx_sdma_init() by calling spi_imx_sdma_exit() in the fail path.

Fixes: f62caccd12 ("spi: spi-imx: add DMA support")
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: NXP Linux Team <linux-imx@nxp.com>
Cc: Robin Gong <b38343@freescale.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Link: https://lore.kernel.org/r/20201005132229.513119-1-marex@denx.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-10-05 16:54:13 +01:00
Marc Kleine-Budde bf253e6bf6
spi: spi-imx: spi_imx_transfer(): add support for effective_speed_hz
This patch implementes the reporting of the effectivly used speed_hz for the
transfer by setting tfr->effective_speed_hz.

See the following patch, which adds this feature to the SPI core for more
information:

    5d7e2b5ed5 spi: core: allow reporting the effectivly used speed_hz for a transfer

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://lore.kernel.org/r/20200917202420.1914104-1-mkl@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-09-23 19:59:32 +01:00
Fabio Estevam c76964e810
spi: imx: Remove unneeded probe message
There is no point in printing a plain "probed" message on successful probe.

Just remove it and make the kernel log a bit less noisy.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20200819123330.22880-1-festevam@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-08-20 22:47:11 +01:00
Fabio Estevam 0ec0da744b
spi: imx: Do not print an error when PIO is used
There are cases that DMA is not used and the driver gracefully
falls back to PIO mode.

Do not treat it like an error message and move it to debug level instead.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20200818223519.8737-1-festevam@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-08-19 13:14:19 +01:00
Clark Wang 525c9e5a32
spi: imx: enable runtime pm support
Enable runtime pm support for spi-imx driver.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Link: https://lore.kernel.org/r/20200727063354.17031-1-xiaoning.wang@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-07-27 14:55:20 +01:00
Linus Walleij 8cdcd8aeee
spi: imx/fsl-lpspi: Convert to GPIO descriptors
This converts the two Freescale i.MX SPI drivers
Freescale i.MX (CONFIG_SPI_IMX) and Freescale i.MX LPSPI
(CONFIG_SPI_FSL_LPSPI) to use GPIO descriptors handled in
the SPI core for GPIO chip selects whether defined in
the device tree or a board file.

The reason why both are converted at the same time is
that they were both using the same platform data and
platform device population helpers when using
board files intertwining the code so this gives a cleaner
cut.

The platform device creation was passing a platform data
container from each boardfile down to the driver using
struct spi_imx_master from <linux/platform_data/spi-imx.h>,
but this was only conveying the number of chipselects and
an int * array of the chipselect GPIO numbers.

The imx27 and imx31 platforms had code passing the
now-unused platform data when creating the platform devices,
this has been repurposed to pass around GPIO descriptor
tables. The platform data struct that was just passing an
array of integers and number of chip selects for the GPIO
lines has been removed.

The number of chipselects used to be passed from the board
file, because this number also limits the number of native
chipselects that the platform can use. To deal with this we
just augment the i.MX (CONFIG_SPI_IMX) driver to support 3
chipselects if the platform does not define "num-cs" as a
device property (such as from the device tree). This covers
all the legacy boards as these use <= 3 native chip selects
(or GPIO lines, and in that case the number of chip selects
is determined by the core from the number of available
GPIO lines). Any new boards should use device tree, so
this is a reasonable simplification to cover all old
boards.

The LPSPI driver never assigned the number of chipselects
and thus always fall back to the core default of 1 chip
select if no GPIOs are defined in the device tree.

The Freescale i.MX driver was already partly utilizing
the SPI core to obtain the GPIO numbers from the device tree,
so this completes the transtion to let the core handle all
of it.

All board files and the core i.MX boardfile registration
code is augmented to account for these changes.

This has been compile-tested with the imx_v4_v5_defconfig
and the imx_v6_v7_defconfig.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Shawn Guo <shawnguo@kernel.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Robin Gong <yibin.gong@nxp.com>
Cc: Trent Piepho <tpiepho@impinj.com>
Cc: Clark Wang <xiaoning.wang@nxp.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: NXP Linux Team <linux-imx@nxp.com>
Link: https://lore.kernel.org/r/20200625200252.207614-1-linus.walleij@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-07-13 18:27:06 +01:00
Robin Gong 7a908832ac
spi: imx: add fallback feature
Add fallback pio feature in case  dma transfer failed before start.
Besides, another whole pio transfer including setup_transfer will be
issued by spi core, no need to restore jobs like commit bcd8e7761e ("spi:
imx: fallback to PIO if dma setup failure").

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
Link: https://lore.kernel.org/r/1592347329-28363-3-git-send-email-yibin.gong@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-06-23 13:38:15 +01:00
Robin Gong bcd8e7761e
spi: imx: fallback to PIO if dma setup failure
Fallback to PIO in case dma setup failed. For example, sdma firmware not
updated but ERR009165 workaroud added in kernel.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
Link: https://lore.kernel.org/r/1590006865-20900-6-git-send-email-yibin.gong@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-05-28 13:41:48 +01:00
zhengbin e6a8b2cc51
spi: imx: use true,false for bool variable
Fixes coccicheck warning:

drivers/spi/spi-imx.c:1233:2-17: WARNING: Assignment of 0/1 to bool variable
drivers/spi/spi-imx.c:1235:2-17: WARNING: Assignment of 0/1 to bool variable

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: zhengbin <zhengbin13@huawei.com>
Link: https://lore.kernel.org/r/1577159526-33689-3-git-send-email-zhengbin13@huawei.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2019-12-25 18:17:25 +00:00
Peter Ujfalusi 5d3aa9ccf4
spi: imx: Use dma_request_chan() directly for channel request
dma_request_slave_channel_reason() is:
#define dma_request_slave_channel_reason(dev, name) \
	dma_request_chan(dev, name)

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Link: https://lore.kernel.org/r/20191113094256.1108-5-peter.ujfalusi@ti.com
Signed-off-by: Mark Brown <broonie@kernel.org>
2019-11-15 12:14:00 +00:00
Mark Brown 3949ba3b37
Merge branch 'spi-5.1' into spi-5.2 for stm32 2019-03-15 17:06:34 +00:00
Trent Piepho c842749ea1
spi: imx: stop buffer overflow in RX FIFO flush
Commit 71abd29057 ("spi: imx: Add support for SPI Slave mode") added
an RX FIFO flush before start of a transfer.  In slave mode, the master
may have sent more data than expected and this data will still be in the
RX FIFO at the start of the next transfer, and so needs to be flushed.

However, the code to do the flush was accidentally saving this data into
the previous transfer's RX buffer, clobbering the contents of whatever
followed that buffer.

Change it to empty the FIFO and throw away the data.  Every one of the
RX functions for the different eCSPI versions and modes reads the RX
FIFO data using the same readl() call, so just use that, rather than
using the spi_imx->rx function pointer and making sure all the different
rx functions have a working "throw away" mode.

There is another issue, which affects master mode when switching from
DMA to PIO.  There can be extra data in the RX FIFO which triggers this
flush code, causing memory corruption in the same manner.  I don't know
why this data is unexpectedly in the FIFO.  It's likely there is a
different bug or erratum responsible for that.  But regardless of that,
I think this is proper fix the for bug at hand here.

Fixes: 71abd29057 ("spi: imx: Add support for SPI Slave mode")
Cc: Jiada Wang <jiada_wang@mentor.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Stefan Agner <stefan@agner.ch>
Cc: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Trent Piepho <tpiepho@impinj.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2019-03-13 15:16:24 +00:00
Trent Piepho 0a9c8998e7
spi: imx: add module parameter to control DMA use
Add the boolean module parameter "use_dma" to control the use of DMA by
the driver.  There are about two dozen other drivers with a "use_dma"
parameter of some sort.

DMA may allow faster and more efficient transfers than using PIO, but it
also adds overhead for small transfers.

High speed receive operations may be less likely to have issues with
FIFO overflow when using DMA than when using PIO.

The eCSPI appears to insert a 4 bit pause after each word in DMA mode,
not done in PIO mode, which can make DMA transfers 50% slower than PIO.

In some cases DMA may be a net win while in others PIO might be.  It
depends on the application.  So allow DMA to be enabled or disabled at
the driver level.  The default will be to have it enabled when possible.

Signed-off-by: Trent Piepho <tpiepho@impinj.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2019-03-11 16:49:16 +00:00
Uwe Kleine-König 3f75720d0e
spi: imx: drop useless member speed_hz from driver data struct
The driver data's member variable just caches the transfer's speed_hz
member. All users of the former now have access directly to the latter.
So fix them to use the uncached value and remove the cache.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
2018-12-11 12:00:18 +00:00
Uwe Kleine-König 1d374703fb
spi: imx: rename config callback and add useful parameters
The config callback is called once per transfer while some things can (and
should) be done on a per message manner. To have unambiguous naming in the
end include "transfer" in the callback's name and rename the
implementations accordingly. Also pass the driver struct and transfer
which allows further simplifications in the following patch.

There is no change in behavior intended here.

Reviewed-by: Marek Vasut <marex@denx.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
2018-12-11 12:00:03 +00:00
Uwe Kleine-König 30d6714223
spi: imx: style fixes
This change fixes some random style issues that I noticed while debugging
the driver: Remove some double spaces, use tabs for indention instead
of spaces if possible, fix comment style.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
2018-12-11 11:59:48 +00:00