mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-28 22:54:05 +08:00
spi: bitbang: Replace spinlock by mutex
chipselect (in the case of spi-gpio: spi_gpio_chipselect, which
calls gpiod_set_raw_value_cansleep) can sleep, so we should not
hold a spinlock while calling it from spi_bitbang_setup.
This issue was introduced by this commit, which converted spi-gpio
to cansleep variants:
d9dda5a191
"spi: spi-gpio: Use 'cansleep' variants to access GPIO"
Replacing the lock variable by a mutex fixes the issue: This is
safe as all instances where the lock is used are called from
contexts that can sleep.
Finally, update spi-ppc4xx and and spi-s3c24xx to use mutex
functions, as they directly hold the lock for similar purpose.
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
6ff33f3902
commit
c15f6ed3a1
@ -180,7 +180,6 @@ int spi_bitbang_setup(struct spi_device *spi)
|
|||||||
{
|
{
|
||||||
struct spi_bitbang_cs *cs = spi->controller_state;
|
struct spi_bitbang_cs *cs = spi->controller_state;
|
||||||
struct spi_bitbang *bitbang;
|
struct spi_bitbang *bitbang;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
bitbang = spi_master_get_devdata(spi->master);
|
bitbang = spi_master_get_devdata(spi->master);
|
||||||
|
|
||||||
@ -210,12 +209,12 @@ int spi_bitbang_setup(struct spi_device *spi)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* deselect chip (low or high) */
|
/* deselect chip (low or high) */
|
||||||
spin_lock_irqsave(&bitbang->lock, flags);
|
mutex_lock(&bitbang->lock);
|
||||||
if (!bitbang->busy) {
|
if (!bitbang->busy) {
|
||||||
bitbang->chipselect(spi, BITBANG_CS_INACTIVE);
|
bitbang->chipselect(spi, BITBANG_CS_INACTIVE);
|
||||||
ndelay(cs->nsecs);
|
ndelay(cs->nsecs);
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&bitbang->lock, flags);
|
mutex_unlock(&bitbang->lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -255,13 +254,12 @@ static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t)
|
|||||||
static int spi_bitbang_prepare_hardware(struct spi_master *spi)
|
static int spi_bitbang_prepare_hardware(struct spi_master *spi)
|
||||||
{
|
{
|
||||||
struct spi_bitbang *bitbang;
|
struct spi_bitbang *bitbang;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
bitbang = spi_master_get_devdata(spi);
|
bitbang = spi_master_get_devdata(spi);
|
||||||
|
|
||||||
spin_lock_irqsave(&bitbang->lock, flags);
|
mutex_lock(&bitbang->lock);
|
||||||
bitbang->busy = 1;
|
bitbang->busy = 1;
|
||||||
spin_unlock_irqrestore(&bitbang->lock, flags);
|
mutex_unlock(&bitbang->lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -378,13 +376,12 @@ static int spi_bitbang_transfer_one(struct spi_master *master,
|
|||||||
static int spi_bitbang_unprepare_hardware(struct spi_master *spi)
|
static int spi_bitbang_unprepare_hardware(struct spi_master *spi)
|
||||||
{
|
{
|
||||||
struct spi_bitbang *bitbang;
|
struct spi_bitbang *bitbang;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
bitbang = spi_master_get_devdata(spi);
|
bitbang = spi_master_get_devdata(spi);
|
||||||
|
|
||||||
spin_lock_irqsave(&bitbang->lock, flags);
|
mutex_lock(&bitbang->lock);
|
||||||
bitbang->busy = 0;
|
bitbang->busy = 0;
|
||||||
spin_unlock_irqrestore(&bitbang->lock, flags);
|
mutex_unlock(&bitbang->lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -427,7 +424,7 @@ int spi_bitbang_start(struct spi_bitbang *bitbang)
|
|||||||
if (!master || !bitbang->chipselect)
|
if (!master || !bitbang->chipselect)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
spin_lock_init(&bitbang->lock);
|
mutex_init(&bitbang->lock);
|
||||||
|
|
||||||
if (!master->mode_bits)
|
if (!master->mode_bits)
|
||||||
master->mode_bits = SPI_CPOL | SPI_CPHA | bitbang->flags;
|
master->mode_bits = SPI_CPOL | SPI_CPHA | bitbang->flags;
|
||||||
|
@ -210,12 +210,12 @@ static int spi_ppc4xx_setupxfer(struct spi_device *spi, struct spi_transfer *t)
|
|||||||
if (in_8(&hw->regs->cdm) != cdm)
|
if (in_8(&hw->regs->cdm) != cdm)
|
||||||
out_8(&hw->regs->cdm, cdm);
|
out_8(&hw->regs->cdm, cdm);
|
||||||
|
|
||||||
spin_lock(&hw->bitbang.lock);
|
mutex_lock(&hw->bitbang.lock);
|
||||||
if (!hw->bitbang.busy) {
|
if (!hw->bitbang.busy) {
|
||||||
hw->bitbang.chipselect(spi, BITBANG_CS_INACTIVE);
|
hw->bitbang.chipselect(spi, BITBANG_CS_INACTIVE);
|
||||||
/* Need to ndelay here? */
|
/* Need to ndelay here? */
|
||||||
}
|
}
|
||||||
spin_unlock(&hw->bitbang.lock);
|
mutex_unlock(&hw->bitbang.lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -198,12 +198,12 @@ static int s3c24xx_spi_setup(struct spi_device *spi)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
spin_lock(&hw->bitbang.lock);
|
mutex_lock(&hw->bitbang.lock);
|
||||||
if (!hw->bitbang.busy) {
|
if (!hw->bitbang.busy) {
|
||||||
hw->bitbang.chipselect(spi, BITBANG_CS_INACTIVE);
|
hw->bitbang.chipselect(spi, BITBANG_CS_INACTIVE);
|
||||||
/* need to ndelay for 0.5 clocktick ? */
|
/* need to ndelay for 0.5 clocktick ? */
|
||||||
}
|
}
|
||||||
spin_unlock(&hw->bitbang.lock);
|
mutex_unlock(&hw->bitbang.lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <linux/workqueue.h>
|
#include <linux/workqueue.h>
|
||||||
|
|
||||||
struct spi_bitbang {
|
struct spi_bitbang {
|
||||||
spinlock_t lock;
|
struct mutex lock;
|
||||||
u8 busy;
|
u8 busy;
|
||||||
u8 use_dma;
|
u8 use_dma;
|
||||||
u8 flags; /* extra spi->mode support */
|
u8 flags; /* extra spi->mode support */
|
||||||
|
Loading…
Reference in New Issue
Block a user