29 Jul, 2020

1 commit

  • [ Upstream commit 44b37eb79e16a56cb30ba55b2da452396b941e7a ]

    this patch use correct SPI_CFG2_REG offset.

    Signed-off-by: leilk.liu
    Link: https://lore.kernel.org/r/20200701090020.7935-1-leilk.liu@mediatek.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    leilk.liu
     

22 Jul, 2020

3 commits

  • commit 8bdd79dae1ff5397351b95e249abcae126572617 upstream.

    The watchdog counter consists of WDG_LOAD_LOW and WDG_LOAD_HIGH,
    which would be loaded to watchdog counter once writing WDG_LOAD_LOW.

    Fixes: ac1775012058 ("spi: sprd: Add the support of restarting the system")
    Signed-off-by: Lingling Xu
    Signed-off-by: Chunyan Zhang
    Link: https://lore.kernel.org/r/20200602082415.5848-1-zhang.lyra@gmail.com
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Lingling Xu
     
  • [ Upstream commit ed7815db70d17b1741883f2da8e1d80bc2efe517 ]

    A SPI transfer defines the _maximum_ speed of the SPI transfer. However the
    driver doesn't take into account that the clock divider is always rounded down
    (due to integer arithmetics). This results in a too high clock rate for the SPI
    transfer.

    E.g.: with a mclk_rate of 24 MHz and a SPI transfer speed of 10 MHz, the
    original code calculates a reg of "0", which results in a effective divider of
    "2" and a 12 MHz clock for the SPI transfer.

    This patch fixes the issue by using DIV_ROUND_UP() instead of a plain
    integer division.

    While there simplify the divider calculation for the CDR1 case, use
    order_base_2() instead of two ilog2() calculations.

    Fixes: 3558fe900e8a ("spi: sunxi: Add Allwinner A31 SPI controller driver")
    Signed-off-by: Marc Kleine-Budde
    Acked-by: Maxime Ripard
    Link: https://lore.kernel.org/r/20200706143443.9855-2-mkl@pengutronix.de
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Marc Kleine-Budde
     
  • [ Upstream commit 3c525b69e8c1a9a6944e976603c7a1a713e728f9 ]

    During shutdown, the driver should unregister the SPI controller
    and stop the hardware. Otherwise the dspi_transfer_one_message() could
    wait on completion infinitely.

    Additionally, calling spi_unregister_controller() first in device
    shutdown reverse-matches the probe function, where SPI controller is
    registered at the end.

    Fixes: dc234825997e ("spi: spi-fsl-dspi: Adding shutdown hook")
    Reported-by: Vladimir Oltean
    Signed-off-by: Krzysztof Kozlowski
    Tested-by: Vladimir Oltean
    Reviewed-by: Vladimir Oltean
    Cc:
    Link: https://lore.kernel.org/r/20200622110543.5035-2-krzk@kernel.org
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Krzysztof Kozlowski
     

16 Jul, 2020

4 commits

  • [ Upstream commit 06096cc6c5a84ced929634b0d79376b94c65a4bd ]

    If an spi device is unbounded from the driver before the release
    process, there will be an NULL pointer reference when it's
    referenced in spi_slave_abort().

    Fix it by checking it's already freed before reference.

    Signed-off-by: Zhenzhong Duan
    Link: https://lore.kernel.org/r/20200618032125.4650-2-zhenzhong.duan@gmail.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Zhenzhong Duan
     
  • [ Upstream commit abd42781c3d2155868821f1b947ae45bbc33330d ]

    Imagine below scene, spidev is referenced after it's freed.

    spidev_release() spidev_remove()
    ...
    spin_lock_irq(&spidev->spi_lock);
    spidev->spi = NULL;
    spin_unlock_irq(&spidev->spi_lock);
    mutex_lock(&device_list_lock);
    dofree = (spidev->spi == NULL);
    if (dofree)
    kfree(spidev);
    mutex_unlock(&device_list_lock);
    mutex_lock(&device_list_lock);
    list_del(&spidev->device_entry);
    device_destroy(spidev_class, spidev->devt);
    clear_bit(MINOR(spidev->devt), minors);
    if (spidev->users == 0)
    kfree(spidev);
    mutex_unlock(&device_list_lock);

    Fix it by resetting spidev->spi in device_list_lock's protection.

    Signed-off-by: Zhenzhong Duan
    Link: https://lore.kernel.org/r/20200618032125.4650-1-zhenzhong.duan@gmail.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Zhenzhong Duan
     
  • [ Upstream commit 7684580d45bd3d84ed9b453a4cadf7a9a5605a3f ]

    During device removal, the driver should unregister the SPI controller
    and stop the hardware. Otherwise the dspi_transfer_one_message() could
    wait on completion infinitely.

    Additionally, calling spi_unregister_controller() first in device
    removal reverse-matches the probe function, where SPI controller is
    registered at the end.

    Fixes: 05209f457069 ("spi: fsl-dspi: add missing clk_disable_unprepare() in dspi_remove()")
    Reported-by: Vladimir Oltean
    Signed-off-by: Krzysztof Kozlowski
    Cc:
    Link: https://lore.kernel.org/r/20200622110543.5035-1-krzk@kernel.org
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Krzysztof Kozlowski
     
  • [ Upstream commit dc234825997ec6ff05980ca9e2204f4ac3f8d695 ]

    We need to ensure dspi controller could be stopped in order for kexec
    to start the next kernel.
    So add the shutdown operation support.

    Signed-off-by: Peng Ma
    Link: https://lore.kernel.org/r/20200424061216.27445-1-peng.ma@nxp.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Peng Ma
     

09 Jul, 2020

1 commit

  • commit 3d87b613d6a3c6f0980e877ab0895785a2dde581 upstream.

    If shared interrupt comes late, during probe error path or device remove
    (could be triggered with CONFIG_DEBUG_SHIRQ), the interrupt handler
    dspi_interrupt() will access registers with the clock being disabled.
    This leads to external abort on non-linefetch on Toradex Colibri VF50
    module (with Vybrid VF5xx):

    $ echo 4002d000.spi > /sys/devices/platform/soc/40000000.bus/4002d000.spi/driver/unbind

    Unhandled fault: external abort on non-linefetch (0x1008) at 0x8887f02c
    Internal error: : 1008 [#1] ARM
    Hardware name: Freescale Vybrid VF5xx/VF6xx (Device Tree)
    Backtrace:
    (regmap_mmio_read32le)
    (regmap_mmio_read)
    (_regmap_bus_reg_read)
    (_regmap_read)
    (regmap_read)
    (dspi_interrupt)
    (free_irq)
    (devm_irq_release)
    (release_nodes)
    (devres_release_all)
    (device_release_driver_internal)

    The resource-managed framework should not be used for shared interrupt
    handling, because the interrupt handler might be called after releasing
    other resources and disabling clocks.

    Similar bug could happen during suspend - the shared interrupt handler
    could be invoked after suspending the device. Each device sharing this
    interrupt line should disable the IRQ during suspend so handler will be
    invoked only in following cases:
    1. None suspended,
    2. All devices resumed.

    Fixes: 349ad66c0ab0 ("spi:Add Freescale DSPI driver for Vybrid VF610 platform")
    Signed-off-by: Krzysztof Kozlowski
    Tested-by: Vladimir Oltean
    Reviewed-by: Vladimir Oltean
    Cc:
    Link: https://lore.kernel.org/r/20200622110543.5035-3-krzk@kernel.org
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Krzysztof Kozlowski
     

22 Jun, 2020

7 commits

  • [ Upstream commit f0410bbf7d0fb80149e3b17d11d31f5b5197873e ]

    DW APB SSI DMA-part of the driver may need to perform the requested
    SPI-transfer synchronously. In that case the dma_transfer() callback
    will return 0 as a marker of the SPI transfer being finished so the
    SPI core doesn't need to wait and may proceed with the SPI message
    trasnfers pumping procedure. This will be needed to fix the problem
    when DMA transactions are finished, but there is still data left in
    the SPI Tx/Rx FIFOs being sent/received. But for now make dma_transfer
    to return 1 as the normal dw_spi_transfer_one() method.

    Signed-off-by: Serge Semin
    Cc: Georgy Vlasov
    Cc: Ramil Zaripov
    Cc: Alexey Malahov
    Cc: Thomas Bogendoerfer
    Cc: Arnd Bergmann
    Cc: Andy Shevchenko
    Cc: Feng Tang
    Cc: Rob Herring
    Cc: linux-mips@vger.kernel.org
    Cc: devicetree@vger.kernel.org
    Link: https://lore.kernel.org/r/20200529131205.31838-3-Sergey.Semin@baikalelectronics.ru
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Serge Semin
     
  • [ Upstream commit 0dadde344d965566589cd82797893d5aa06557a3 ]

    By unknown reason the commit 64bee4d28c9e
    ("spi / ACPI: add ACPI enumeration support")
    missed the DataBitLength property to encounter when parse SPI slave
    device data from ACPI.

    Fill the gap here.

    Fixes: 64bee4d28c9e ("spi / ACPI: add ACPI enumeration support")
    Signed-off-by: Andy Shevchenko
    Link: https://lore.kernel.org/r/20200413180406.1826-1-andriy.shevchenko@linux.intel.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Andy Shevchenko
     
  • [ Upstream commit 46164fde6b7890e7a3982d54549947c8394c0192 ]

    Tx-only DMA transfers are working perfectly fine since in this case
    the code just ignores the Rx FIFO overflow interrupts. But it turns
    out the SPI Rx-only transfers are broken since nothing pushing any
    data to the shift registers, so the Rx FIFO is left empty and the
    SPI core subsystems just returns a timeout error. Since DW DMAC
    driver doesn't support something like cyclic write operations of
    a single byte to a device register, the only way to support the
    Rx-only SPI transfers is to fake it by using a dummy Tx-buffer.
    This is what we intend to fix in this commit by setting the
    SPI_CONTROLLER_MUST_TX flag for DMA-capable platform.

    Signed-off-by: Serge Semin
    Reviewed-by: Andy Shevchenko
    Cc: Georgy Vlasov
    Cc: Ramil Zaripov
    Cc: Alexey Malahov
    Cc: Thomas Bogendoerfer
    Cc: Arnd Bergmann
    Cc: Feng Tang
    Cc: Rob Herring
    Cc: linux-mips@vger.kernel.org
    Cc: devicetree@vger.kernel.org
    Link: https://lore.kernel.org/r/20200529131205.31838-9-Sergey.Semin@baikalelectronics.ru
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Serge Semin
     
  • [ Upstream commit 43dba9f3f98c2b184a19f856f06fe22817bfd9e0 ]

    It's pointless to track the Tx overrun interrupts if Rx-only SPI
    transfer is issued. Similarly there is no need in handling the Rx
    overrun/underrun interrupts if Tx-only SPI transfer is executed.
    So lets unmask the interrupts only if corresponding SPI
    transactions are implied.

    Co-developed-by: Georgy Vlasov
    Signed-off-by: Georgy Vlasov
    Signed-off-by: Serge Semin
    Cc: Ramil Zaripov
    Cc: Alexey Malahov
    Cc: Thomas Bogendoerfer
    Cc: Paul Burton
    Cc: Ralf Baechle
    Cc: Arnd Bergmann
    Cc: Andy Shevchenko
    Cc: Rob Herring
    Cc: linux-mips@vger.kernel.org
    Cc: devicetree@vger.kernel.org
    Link: https://lore.kernel.org/r/20200522000806.7381-3-Sergey.Semin@baikalelectronics.ru
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Serge Semin
     
  • [ Upstream commit 3cb97e223d277f84171cc4ccecab31e08b2ee7b5 ]

    Some DMA controller drivers do not tolerate non-zero values in
    the DMA configuration structures. Zero them to avoid issues with
    such DMA controller drivers. Even despite above this is a good
    practice per se.

    Fixes: 7063c0d942a1 ("spi/dw_spi: add DMA support")
    Signed-off-by: Andy Shevchenko
    Acked-by: Feng Tang
    Cc: Feng Tang
    Link: https://lore.kernel.org/r/20200506153025.21441-1-andriy.shevchenko@linux.intel.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Andy Shevchenko
     
  • [ Upstream commit 6eefaee4f2d366a389da0eb95e524ba82bf358c4 ]

    With a couple allies at Intel, and much badgering, I got confirmation
    from Intel that at least BXT suffers from the same SPI chip-select
    issue as Cannonlake (and beyond). The issue being that after going
    through runtime suspend/resume, toggling the chip-select line without
    also sending data does nothing.

    Add the quirk to BXT to briefly toggle dynamic clock gating off and
    on, forcing the fabric to wake up enough to notice the CS register
    change.

    Signed-off-by: Evan Green
    Cc: Shobhit Srivastava
    Cc: Andy Shevchenko
    Link: https://lore.kernel.org/r/20200427163238.1.Ib1faaabe236e37ea73be9b8dcc6aa034cb3c8804@changeid
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Evan Green
     
  • [ Upstream commit 80300a7d5f2d7178335652f41d2e55ba898b4ec1 ]

    Currently buswidths 2 and 4 are rejected for a device that advertises
    Octal capabilities. Allow these buswidths, just like is done for
    buswidth 2 and Quad-capable devices.

    Fixes: b12a084c8729ef42 ("spi: spi-mem: add support for octal mode I/O data transfer")
    Signed-off-by: Geert Uytterhoeven
    Link: https://lore.kernel.org/r/20200416101418.14379-1-geert+renesas@glider.be
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Geert Uytterhoeven
     

17 Jun, 2020

9 commits

  • commit 4df3bea7f9d2ddd9ac2c29ba945c7c4db2def29c upstream.

    Currently we set the tx/rx buffer to 0xff when NULL. This causes
    problems with some spi slaves where 0xff is a valid command. Looking
    at other drivers, the tx/rx buffer is usually set to 0x00 when NULL.
    Following this convention solves the issue.

    Fixes: fa236a7ef240 ("spi: bcm-qspi: Add Broadcom MSPI driver")
    Signed-off-by: Justin Chen
    Signed-off-by: Kamal Dasu
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20200420190853.45614-6-kdasu.kdev@gmail.com
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Justin Chen
     
  • commit 0392727c261bab65a35cd4f82ee9459bc237591d upstream.

    The clock provider may not be ready by the time spi-bcm-qspi gets
    probed, handle probe deferral using devm_clk_get_optional().

    Signed-off-by: Florian Fainelli
    Signed-off-by: Kamal Dasu
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20200420190853.45614-2-kdasu.kdev@gmail.com
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Florian Fainelli
     
  • commit b9dd3f6d417258ad0beeb292a1bc74200149f15d upstream.

    The BCM2835aux SPI driver uses devm_spi_register_master() on bind.
    As a consequence, on unbind, __device_release_driver() first invokes
    bcm2835aux_spi_remove() before unregistering the SPI controller via
    devres_release_all().

    This order is incorrect: bcm2835aux_spi_remove() turns off the SPI
    controller, including its interrupts and clock. The SPI controller
    is thus no longer usable.

    When the SPI controller is subsequently unregistered, it unbinds all
    its slave devices. If their drivers need to access the SPI bus,
    e.g. to quiesce their interrupts, unbinding will fail.

    As a rule, devm_spi_register_master() must not be used if the
    ->remove() hook performs teardown steps which shall be performed
    after unbinding of slaves.

    Fix by using the non-devm variant spi_register_master(). Note that the
    struct spi_master as well as the driver-private data are not freed until
    after bcm2835aux_spi_remove() has finished, so accessing them is safe.

    Fixes: 1ea29b39f4c8 ("spi: bcm2835aux: add bcm2835 auxiliary spi device driver")
    Signed-off-by: Lukas Wunner
    Cc: stable@vger.kernel.org # v4.4+
    Cc: Martin Sperl
    Link: https://lore.kernel.org/r/32f27f4d8242e4d75f9a53f7e8f1f77483b08669.1589557526.git.lukas@wunner.de
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Lukas Wunner
     
  • commit 9dd277ff92d06f6aa95b39936ad83981d781f49b upstream.

    The BCM2835 SPI driver uses devm_spi_register_controller() on bind.
    As a consequence, on unbind, __device_release_driver() first invokes
    bcm2835_spi_remove() before unregistering the SPI controller via
    devres_release_all().

    This order is incorrect: bcm2835_spi_remove() tears down the DMA
    channels and turns off the SPI controller, including its interrupts
    and clock. The SPI controller is thus no longer usable.

    When the SPI controller is subsequently unregistered, it unbinds all
    its slave devices. If their drivers need to access the SPI bus,
    e.g. to quiesce their interrupts, unbinding will fail.

    As a rule, devm_spi_register_controller() must not be used if the
    ->remove() hook performs teardown steps which shall be performed
    after unbinding of slaves.

    Fix by using the non-devm variant spi_register_controller(). Note that
    the struct spi_controller as well as the driver-private data are not
    freed until after bcm2835_spi_remove() has finished, so accessing them
    is safe.

    Fixes: 247263dba208 ("spi: bcm2835: use devm_spi_register_master()")
    Signed-off-by: Lukas Wunner
    Cc: stable@vger.kernel.org # v3.13+
    Link: https://lore.kernel.org/r/2397dd70cdbe95e0bc4da2b9fca0f31cb94e5aed.1589557526.git.lukas@wunner.de
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Lukas Wunner
     
  • commit 65e318e17358a3fd4fcb5a69d89b14016dee2f06 upstream.

    The PXA2xx SPI driver releases a runtime PM ref in the probe error path
    even though it hasn't acquired a ref earlier.

    Apparently commit e2b714afee32 ("spi: pxa2xx: Disable runtime PM if
    controller registration fails") sought to copy-paste the invocation of
    pm_runtime_disable() from pxa2xx_spi_remove(), but erroneously copied
    the call to pm_runtime_put_noidle() as well. Drop it.

    Fixes: e2b714afee32 ("spi: pxa2xx: Disable runtime PM if controller registration fails")
    Signed-off-by: Lukas Wunner
    Reviewed-by: Jarkko Nikula
    Reviewed-by: Andy Shevchenko
    Cc: stable@vger.kernel.org # v4.17+
    Cc: Jarkko Nikula
    Link: https://lore.kernel.org/r/58b2ac6942ca1f91aaeeafe512144bc5343e1d84.1590408496.git.lukas@wunner.de
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Lukas Wunner
     
  • commit 32e5b57232c0411e7dea96625c415510430ac079 upstream.

    The PXA2xx SPI driver uses devm_spi_register_controller() on bind.
    As a consequence, on unbind, __device_release_driver() first invokes
    pxa2xx_spi_remove() before unregistering the SPI controller via
    devres_release_all().

    This order is incorrect: pxa2xx_spi_remove() disables the chip,
    rendering the SPI bus inaccessible even though the SPI controller is
    still registered. When the SPI controller is subsequently unregistered,
    it unbinds all its slave devices. Because their drivers cannot access
    the SPI bus, e.g. to quiesce interrupts, the slave devices may be left
    in an improper state.

    As a rule, devm_spi_register_controller() must not be used if the
    ->remove() hook performs teardown steps which shall be performed after
    unregistering the controller and specifically after unbinding of slaves.

    Fix by reverting to the non-devm variant of spi_register_controller().

    An alternative approach would be to use device-managed functions for all
    steps in pxa2xx_spi_remove(), e.g. by calling devm_add_action_or_reset()
    on probe. However that approach would add more LoC to the driver and
    it wouldn't lend itself as well to backporting to stable.

    The improper use of devm_spi_register_controller() was introduced in 2013
    by commit a807fcd090d6 ("spi: pxa2xx: use devm_spi_register_master()"),
    but all earlier versions of the driver going back to 2006 were likewise
    broken because they invoked spi_unregister_master() at the end of
    pxa2xx_spi_remove(), rather than at the beginning.

    Fixes: e0c9905e87ac ("[PATCH] SPI: add PXA2xx SSP SPI Driver")
    Signed-off-by: Lukas Wunner
    Reviewed-by: Andy Shevchenko
    Cc: stable@vger.kernel.org # v2.6.17+
    Cc: Tsuchiya Yuto
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=206403#c1
    Link: https://lore.kernel.org/r/834c446b1cf3284d2660f1bee1ebe3e737cd02a9.1590408496.git.lukas@wunner.de
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Lukas Wunner
     
  • commit 84855678add8aba927faf76bc2f130a40f94b6f7 upstream.

    When an SPI controller unregisters, it unbinds all its slave devices.
    For this, their drivers may need to access the SPI bus, e.g. to quiesce
    interrupts.

    However since commit ffbbdd21329f ("spi: create a message queueing
    infrastructure"), spi_destroy_queue() is executed before unbinding the
    slaves. It sets ctlr->running = false, thereby preventing SPI bus
    access and causing unbinding of slave devices to fail.

    Fix by unbinding slaves before calling spi_destroy_queue().

    Fixes: ffbbdd21329f ("spi: create a message queueing infrastructure")
    Signed-off-by: Lukas Wunner
    Cc: stable@vger.kernel.org # v3.4+
    Cc: Linus Walleij
    Link: https://lore.kernel.org/r/8aaf9d44c153fe233b17bc2dec4eb679898d7e7b.1589557526.git.lukas@wunner.de
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Lukas Wunner
     
  • commit ca8b19d61e3fce5d2d7790cde27a0b57bcb3f341 upstream.

    The Designware SPI driver uses devm_spi_register_controller() on bind.
    As a consequence, on unbind, __device_release_driver() first invokes
    dw_spi_remove_host() before unregistering the SPI controller via
    devres_release_all().

    This order is incorrect: dw_spi_remove_host() shuts down the chip,
    rendering the SPI bus inaccessible even though the SPI controller is
    still registered. When the SPI controller is subsequently unregistered,
    it unbinds all its slave devices. Because their drivers cannot access
    the SPI bus, e.g. to quiesce interrupts, the slave devices may be left
    in an improper state.

    As a rule, devm_spi_register_controller() must not be used if the
    ->remove() hook performs teardown steps which shall be performed after
    unregistering the controller and specifically after unbinding of slaves.

    Fix by reverting to the non-devm variant of spi_register_controller().

    An alternative approach would be to use device-managed functions for all
    steps in dw_spi_remove_host(), e.g. by calling devm_add_action_or_reset()
    on probe. However that approach would add more LoC to the driver and
    it wouldn't lend itself as well to backporting to stable.

    Fixes: 04f421e7b0b1 ("spi: dw: use managed resources")
    Signed-off-by: Lukas Wunner
    Reviewed-by: Andy Shevchenko
    Cc: stable@vger.kernel.org # v3.14+
    Cc: Baruch Siach
    Link: https://lore.kernel.org/r/3fff8cb8ae44a9893840d0688be15bb88c090a14.1590408496.git.lukas@wunner.de
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Lukas Wunner
     
  • [ Upstream commit 9aea644ca17b94f82ad7fa767cbc4509642f4420 ]

    Commit 6e0a32d6f376 ("spi: dw: Fix default polarity of native
    chipselect") attempted to fix the problem when GPIO active-high
    chip-select is utilized to communicate with some SPI slave. It fixed
    the problem, but broke the normal native CS support. At the same time
    the reversion commit ada9e3fcc175 ("spi: dw: Correct handling of native
    chipselect") didn't solve the problem either, since it just inverted
    the set_cs() polarity perception without taking into account that
    CS-high might be applicable. Here is what is done to finally fix the
    problem.

    DW SPI controller demands any native CS being set in order to proceed
    with data transfer. So in order to activate the SPI communications we
    must set any bit in the Slave Select DW SPI controller register no
    matter whether the platform requests the GPIO- or native CS. Preferably
    it should be the bit corresponding to the SPI slave CS number. But
    currently the dw_spi_set_cs() method activates the chip-select
    only if the second argument is false. Since the second argument of the
    set_cs callback is expected to be a boolean with "is-high" semantics
    (actual chip-select pin state value), the bit in the DW SPI Slave
    Select register will be set only if SPI core requests the driver
    to set the CS in the low state. So this will work for active-low
    GPIO-based CS case, and won't work for active-high CS setting
    the bit when SPI core actually needs to deactivate the CS.

    This commit fixes the problem for all described cases. So no matter
    whether an SPI slave needs GPIO- or native-based CS with active-high
    or low signal the corresponding bit will be set in SER.

    Signed-off-by: Serge Semin
    Fixes: ada9e3fcc175 ("spi: dw: Correct handling of native chipselect")
    Fixes: 6e0a32d6f376 ("spi: dw: Fix default polarity of native chipselect")
    Reviewed-by: Charles Keepax
    Reviewed-by: Andy Shevchenko
    Acked-by: Linus Walleij

    Link: https://lore.kernel.org/r/20200515104758.6934-5-Sergey.Semin@baikalelectronics.ru
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Sasha Levin
     

07 Jun, 2020

1 commit

  • [ Upstream commit bfda044533b213985bc62bd7ca96f2b984d21b80 ]

    Because of out-of-order execution about some CPU architecture,
    In this debug stage we find Completing spi interrupt enable ->
    prodrucing TXEI interrupt -> running "interrupt_transfer" function
    will prior to set "dw->rx and dws->rx_end" data, so this patch add
    memory barrier to enable dw->rx and dw->rx_end to be visible and
    solve to send SPI data error.
    eg:
    it will fix to this following low possibility error in testing environment
    which using SPI control to connect TPM Modules

    kernel: tpm tpm0: Operation Timed out
    kernel: tpm tpm0: tpm_relinquish_locality: : error -1

    Signed-off-by: fengsheng
    Signed-off-by: Xinwei Kong
    Link: https://lore.kernel.org/r/1578019930-55858-1-git-send-email-kong.kongxinwei@hisilicon.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Xinwei Kong
     

17 Apr, 2020

1 commit

  • [ Upstream commit 4f5ee75ea1718a09149460b3df993f389a67b56a ]

    Currently the driver puts the process in interruptible sleep waiting for
    the interrupt train to finish transfer to/from the tx_buf and rx_buf.

    But exiting the process with ctrl-c may make the kernel panic: the
    wait_event_interruptible call will return -ERESTARTSYS, which a proper
    driver implementation is perhaps supposed to handle, but nonetheless
    this one doesn't, and aborts the transfer altogether.

    Actually when the task is interrupted, there is still a high chance that
    the dspi_interrupt is still triggering. And if dspi_transfer_one_message
    returns execution all the way to the spi_device driver, that can free
    the spi_message and spi_transfer structures, leaving the interrupts to
    access a freed tx_buf and rx_buf.

    hexdump -C /dev/mtd0
    00000000 00 75 68 75 0a ff ff ff ff ff ff ff ff ff ff ff
    |.uhu............|
    00000010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
    |................|
    *
    ^C[ 38.495955] fsl-dspi 2120000.spi: Waiting for transfer to complete failed!
    [ 38.503097] spi_master spi2: failed to transfer one message from queue
    [ 38.509729] Unable to handle kernel paging request at virtual address ffff800095ab3377
    [ 38.517676] Mem abort info:
    [ 38.520474] ESR = 0x96000045
    [ 38.523533] EC = 0x25: DABT (current EL), IL = 32 bits
    [ 38.528861] SET = 0, FnV = 0
    [ 38.531921] EA = 0, S1PTW = 0
    [ 38.535067] Data abort info:
    [ 38.537952] ISV = 0, ISS = 0x00000045
    [ 38.541797] CM = 0, WnR = 1
    [ 38.544771] swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000000082621000
    [ 38.551494] [ffff800095ab3377] pgd=00000020fffff003, p4d=00000020fffff003, pud=0000000000000000
    [ 38.560229] Internal error: Oops: 96000045 [#1] PREEMPT SMP
    [ 38.565819] Modules linked in:
    [ 38.568882] CPU: 0 PID: 2729 Comm: hexdump Not tainted 5.6.0-rc4-next-20200306-00052-gd8730cdc8a0b-dirty #193
    [ 38.578834] Hardware name: Kontron SMARC-sAL28 (Single PHY) on SMARC Eval 2.0 carrier (DT)
    [ 38.587129] pstate: 20000085 (nzCv daIf -PAN -UAO)
    [ 38.591941] pc : ktime_get_real_ts64+0x3c/0x110
    [ 38.596487] lr : spi_take_timestamp_pre+0x40/0x90
    [ 38.601203] sp : ffff800010003d90
    [ 38.604525] x29: ffff800010003d90 x28: ffff80001200e000
    [ 38.609854] x27: ffff800011da9000 x26: ffff002079c40400
    [ 38.615184] x25: ffff8000117fe018 x24: ffff800011daa1a0
    [ 38.620513] x23: ffff800015ab3860 x22: ffff800095ab3377
    [ 38.625841] x21: 000000000000146e x20: ffff8000120c3000
    [ 38.631170] x19: ffff0020795f6e80 x18: ffff800011da9948
    [ 38.636498] x17: 0000000000000000 x16: 0000000000000000
    [ 38.641826] x15: ffff800095ab3377 x14: 0720072007200720
    [ 38.647155] x13: 0720072007200765 x12: 0775076507750771
    [ 38.652483] x11: 0720076d076f0772 x10: 0000000000000040
    [ 38.657812] x9 : ffff8000108e2100 x8 : ffff800011dcabe8
    [ 38.663139] x7 : 0000000000000000 x6 : ffff800015ab3a60
    [ 38.668468] x5 : 0000000007200720 x4 : ffff800095ab3377
    [ 38.673796] x3 : 0000000000000000 x2 : 0000000000000ab0
    [ 38.679125] x1 : ffff800011daa000 x0 : 0000000000000026
    [ 38.684454] Call trace:
    [ 38.686905] ktime_get_real_ts64+0x3c/0x110
    [ 38.691100] spi_take_timestamp_pre+0x40/0x90
    [ 38.695470] dspi_fifo_write+0x58/0x2c0
    [ 38.699315] dspi_interrupt+0xbc/0xd0
    [ 38.702987] __handle_irq_event_percpu+0x78/0x2c0
    [ 38.707706] handle_irq_event_percpu+0x3c/0x90
    [ 38.712161] handle_irq_event+0x4c/0xd0
    [ 38.716008] handle_fasteoi_irq+0xbc/0x170
    [ 38.720115] generic_handle_irq+0x2c/0x40
    [ 38.724135] __handle_domain_irq+0x68/0xc0
    [ 38.728243] gic_handle_irq+0xc8/0x160
    [ 38.732000] el1_irq+0xb8/0x180
    [ 38.735149] spi_nor_spimem_read_data+0xe0/0x140
    [ 38.739779] spi_nor_read+0xc4/0x120
    [ 38.743364] mtd_read_oob+0xa8/0xc0
    [ 38.746860] mtd_read+0x4c/0x80
    [ 38.750007] mtdchar_read+0x108/0x2a0
    [ 38.753679] __vfs_read+0x20/0x50
    [ 38.757002] vfs_read+0xa4/0x190
    [ 38.760237] ksys_read+0x6c/0xf0
    [ 38.763471] __arm64_sys_read+0x20/0x30
    [ 38.767319] el0_svc_common.constprop.3+0x90/0x160
    [ 38.772125] do_el0_svc+0x28/0x90
    [ 38.775449] el0_sync_handler+0x118/0x190
    [ 38.779468] el0_sync+0x140/0x180
    [ 38.782793] Code: 91000294 1400000f d50339bf f9405e80 (f90002c0)
    [ 38.788910] ---[ end trace 55da560db4d6bef7 ]---
    [ 38.793540] Kernel panic - not syncing: Fatal exception in interrupt
    [ 38.799914] SMP: stopping secondary CPUs
    [ 38.803849] Kernel Offset: disabled
    [ 38.807344] CPU features: 0x10002,20006008
    [ 38.811451] Memory Limit: none
    [ 38.814513] ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]---

    So it is clear that the "interruptible" part isn't handled correctly.
    When the process receives a signal, one could either attempt a clean
    abort (which appears to be difficult with this hardware) or just keep
    restarting the sleep until the wait queue really completes. But checking
    in a loop for -ERESTARTSYS is a bit too complicated for this driver, so
    just make the sleep uninterruptible, to avoid all that nonsense.

    The wait queue was actually restructured as a completion, after polling
    other drivers for the most "popular" approach.

    Fixes: 349ad66c0ab0 ("spi:Add Freescale DSPI driver for Vybrid VF610 platform")
    Reported-by: Michael Walle
    Signed-off-by: Vladimir Oltean
    Tested-by: Michael Walle
    Link: https://lore.kernel.org/r/20200318001603.9650-7-olteanv@gmail.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Vladimir Oltean
     

25 Mar, 2020

5 commits

  • [ Upstream commit f9981d4f50b475d7dbb70f3022b87a3c8bba9fd6 ]

    Some error paths leave the bus id allocated. As a result the IDR
    allocation will fail after a deferred probe. Fix by freeing the bus id
    always on error.

    Signed-off-by: Aaro Koskinen
    Message-Id:
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Aaro Koskinen
     
  • [ Upstream commit 5dd8304981ecffa77bb72b1c57c4be5dfe6cfae9 ]

    In the public interface for chipselect, there is always an entry
    commented as "Dummy generic FIFO entry" pushed down to the fifo right
    after the activate/deactivate command. The dummy entry is 0x0,
    irregardless if the intention was to activate or deactive the cs. This
    causes the cs line to glitch rather than beeing activated in the case
    when there was an activate command.

    This has been observed on oscilloscope, and have caused problems for at
    least one specific flash device type connected to the qspi port. After
    the change the glitch is gone and cs goes active when intended.

    The reason why this worked before (except for the glitch) was because
    when sending the actual data, the CS bits are once again set. Since
    most flashes uses mode 0, there is always a half clk period anyway for
    cs to clk active setup time. If someone would rely on timing from a
    chip_select call to a transfer_one, it would fail though.

    It is unknown why the dummy entry was there in the first place, git log
    seems to be of no help in this case. The reference manual gives no
    indication of the necessity of this. In fact the lower 8 bits are a
    setup (or hold in case of deactivate) time expressed in cycles. So this
    should not be needed to fulfill any setup/hold timings.

    Signed-off-by: Thommy Jakobsson
    Reviewed-by: Naga Sureshkumar Relli
    Link: https://lore.kernel.org/r/20200224162643.29102-1-thommyj@gmail.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Thommy Jakobsson
     
  • [ Upstream commit 683f65ded66a9a7ff01ed7280804d2132ebfdf7e ]

    In some circumstances on Intel LPSS controllers, toggling the LPSS
    CS control register doesn't actually cause the CS line to toggle.
    This seems to be failure of dynamic clock gating that occurs after
    going through a suspend/resume transition, where the controller
    is sent through a reset transition. This ruins SPI transactions
    that either rely on delay_usecs, or toggle the CS line without
    sending data.

    Whenever CS is toggled, momentarily set the clock gating register
    to "Force On" to poke the controller into acting on CS.

    Signed-off-by: Rajat Jain
    Signed-off-by: Evan Green
    Link: https://lore.kernel.org/r/20200211223700.110252-1-rajatja@google.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Evan Green
     
  • [ Upstream commit 136b5cd2e2f97581ae560cff0db2a3b5369112da ]

    spi_qup_suspend() will cause synchronous external abort when
    runtime suspend is enabled and applied, as it tries to
    access SPI controller register while clock is already disabled
    in spi_qup_pm_suspend_runtime().

    Signed-off-by: Yuji sasaki
    Signed-off-by: Vinod Koul
    Link: https://lore.kernel.org/r/20200214074340.2286170-1-vkoul@kernel.org
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Yuji Sasaki
     
  • [ Upstream commit 32f2fc5dc3992b4b60cc6b1a6a31be605cc9c3a2 ]

    dma_request_channel() can return -EPROBE_DEFER, if DMA driver is not
    ready. Currently driver just falls back to PIO mode on probe deferral.
    Fix this by requesting all required channels during probe and
    propagating EPROBE_DEFER error code.

    Signed-off-by: Vignesh Raghavendra
    Link: https://lore.kernel.org/r/20200204124816.16735-3-vigneshr@ti.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Vignesh Raghavendra
     

12 Mar, 2020

3 commits

  • commit 8e093ea4d3593379be46b845b9e823179558047e upstream.

    The QSPI controller memory space is limited to 128MB:
    0x9000_00000-0x9800_00000/0XD000_0000--0XD800_0000.

    There are nor flashes that are bigger in size than the memory size
    supported by the controller: Micron MT25QL02G (256 MB).

    Check if the address exceeds the MMIO window size. An improvement
    would be to add support for regular SPI mode and fall back to it
    when the flash memories overrun the controller's memory space.

    Fixes: 0e6aae08e9ae ("spi: Add QuadSPI driver for Atmel SAMA5D2")
    Signed-off-by: Tudor Ambarus
    Link: https://lore.kernel.org/r/20200228155437.1558219-1-tudor.ambarus@microchip.com
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Tudor Ambarus
     
  • commit 51bddd4501bc414b8b1e8f4d096b4a5304068169 upstream.

    The purpose of commit 0fd85869c2a9 ("spi/bcm63xx-hsspi: keep pll clk enabled")
    was to keep the pll clk enabled through the lifetime of the device.

    In order to do that, some 'clk_prepare_enable()'/'clk_disable_unprepare()'
    calls have been added in the error handling path of the probe function, in
    the remove function and in the suspend and resume functions.

    However, a 'clk_disable_unprepare()' call has been unfortunately left in
    the probe function. So the commit seems to be more or less a no-op.

    Axe it now, so that the pll clk is left enabled through the lifetime of
    the device, as described in the commit.

    Fixes: 0fd85869c2a9 ("spi/bcm63xx-hsspi: keep pll clk enabled")
    Signed-off-by: Christophe JAILLET
    Acked-by: Jonas Gorski
    Link: https://lore.kernel.org/r/20200228213838.7124-1-christophe.jaillet@wanadoo.fr
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Christophe JAILLET
     
  • commit 138c9c32f090894614899eca15e0bb7279f59865 upstream.

    Commit f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
    amended of_spi_parse_dt() to always set SPI_CS_HIGH for SPI slaves whose
    Chip Select is defined by a "cs-gpios" devicetree property.

    This change broke userspace applications which issue an SPI_IOC_WR_MODE
    ioctl() to an spidev: Chip Select polarity will be incorrect unless the
    application is changed to set SPI_CS_HIGH. And once changed, it will be
    incompatible with kernels not containing the commit.

    Fix by setting SPI_CS_HIGH in spidev_ioctl() (under the same conditions
    as in of_spi_parse_dt()).

    Fixes: f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
    Reported-by: Simon Han
    Signed-off-by: Lukas Wunner
    Reviewed-by: Linus Walleij
    Link: https://lore.kernel.org/r/fca3ba7cdc930cd36854666ceac4fbcf01b89028.1582027457.git.lukas@wunner.de
    Signed-off-by: Mark Brown
    Cc: stable@vger.kernel.org # v5.1+
    Signed-off-by: Greg Kroah-Hartman

    Lukas Wunner
     

24 Feb, 2020

2 commits

  • [ Upstream commit b0177aca7aea7e8917d4e463334b51facb293d02 ]

    Make use of a core helper to ensure the desired width is respected
    when calling spi-mem operators.

    Otherwise only the SPI controller will be matched with the flash chip,
    which might lead to wrong widths. Also consider the width specified by
    the user in the device tree.

    Fixes: 84d043185dbe ("spi: Add a driver for the Freescale/NXP QuadSPI controller")
    Signed-off-by: Michael Walle
    Link: https://lore.kernel.org/r/20200114154613.8195-1-michael@walle.cc
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Michael Walle
     
  • [ Upstream commit bc3a8b295e5bca9d1ec2622a6ba38289f9fd3d8a ]

    Why it does not work at the moment:
    - num_chipselect sets the number of cs-gpios that are in the DT.
    This comes from drivers/spi/spi.c
    - num_chipselect gets set with devm_spi_register_controller, that is
    called in drivers/spi/spi.c
    - devm_spi_register_controller got called after num_chipselect has
    been used.

    How this commit fixes the issue:
    - devm_spi_register_controller gets called before num_chipselect is
    being used.

    Fixes: c7a402599504 ("spi: lpspi: use the core way to implement cs-gpio function")
    Signed-off-by: Philippe Schenker
    Link: https://lore.kernel.org/r/20191204141312.1411251-1-philippe.schenker@toradex.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Philippe Schenker
     

01 Feb, 2020

2 commits

  • [ Upstream commit f0cf17ed76cffa365001d263ced1f130ec794917 ]

    Add Intel Comet Lake-H LPSS SPI PCI IDs.

    Signed-off-by: Jarkko Nikula
    Link: https://lore.kernel.org/r/20191029115802.6779-1-jarkko.nikula@linux.intel.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    Jarkko Nikula
     
  • [ Upstream commit 19b61392c5a852b4e8a0bf35aecb969983c5932d ]

    dw_spi_irq() and dw_spi_transfer_one concurrent calls.

    I find a panic in dw_writer(): txw = *(u8 *)(dws->tx), when dw->tx==null,
    dw->len==4, and dw->tx_end==1.

    When tpm driver's message overtime dw_spi_irq() and dw_spi_transfer_one
    may concurrent visit dw_spi, so I think dw_spi structure lack of protection.

    Otherwise dw_spi_transfer_one set dw rx/tx buffer and then open irq,
    store dw rx/tx instructions and other cores handle irq load dw rx/tx
    instructions may out of order.

    [ 1025.321302] Call trace:
    ...
    [ 1025.321319] __crash_kexec+0x98/0x148
    [ 1025.321323] panic+0x17c/0x314
    [ 1025.321329] die+0x29c/0x2e8
    [ 1025.321334] die_kernel_fault+0x68/0x78
    [ 1025.321337] __do_kernel_fault+0x90/0xb0
    [ 1025.321346] do_page_fault+0x88/0x500
    [ 1025.321347] do_translation_fault+0xa8/0xb8
    [ 1025.321349] do_mem_abort+0x68/0x118
    [ 1025.321351] el1_da+0x20/0x8c
    [ 1025.321362] dw_writer+0xc8/0xd0
    [ 1025.321364] interrupt_transfer+0x60/0x110
    [ 1025.321365] dw_spi_irq+0x48/0x70
    ...

    Signed-off-by: wuxu.wu
    Link: https://lore.kernel.org/r/1577849981-31489-1-git-send-email-wuxu.wu@huawei.com
    Signed-off-by: Mark Brown
    Signed-off-by: Sasha Levin

    wuxu.wu
     

18 Jan, 2020

1 commit

  • commit 057b8945f78f76d0b04eeb5c27cd9225e5e7ad86 upstream.

    In fsl_lpspi_probe an SPI controller is allocated either via
    spi_alloc_slave or spi_alloc_master. In all but one error cases this
    controller is put by going to error handling code. This commit fixes the
    case when pm_runtime_get_sync fails and it should go to the error
    handling path.

    Fixes: 944c01a889d9 ("spi: lpspi: enable runtime pm for lpspi")
    Signed-off-by: Navid Emamdoost
    Link: https://lore.kernel.org/r/20190930034602.1467-1-navid.emamdoost@gmail.com
    Signed-off-by: Mark Brown
    Signed-off-by: Greg Kroah-Hartman

    Navid Emamdoost