Commit 145cfc38 authored by Mark Brown's avatar Mark Brown

spi: mpc52xx-psc: Switch to using core message queue

We deprecated open coding of the transfer queue back in 2017 so it's high
time we finished up converting drivers to use the standard message queue
code. The mpc52xx-psc driver is fairly straightforward so convert to use
transfer_one_message(), it looks like the driver would be a good fit for
transfer_one() with a little bit of updating but this smaller change seems
safer.

The driver seems like a good candidate for transfer_one() but the chip
select function is actually doing rather more than just updating the chip
select and both transfer_one() and transfer_one_message() are current APIs
so leave that refactoring for another day, ideally by someone with the
hardware.
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20220613121946.136193-1-broonie@kernel.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent e2185072
...@@ -37,12 +37,6 @@ struct mpc52xx_psc_spi { ...@@ -37,12 +37,6 @@ struct mpc52xx_psc_spi {
struct mpc52xx_psc_fifo __iomem *fifo; struct mpc52xx_psc_fifo __iomem *fifo;
unsigned int irq; unsigned int irq;
u8 bits_per_word; u8 bits_per_word;
u8 busy;
struct work_struct work;
struct list_head queue;
spinlock_t lock;
struct completion done; struct completion done;
}; };
...@@ -198,24 +192,14 @@ static int mpc52xx_psc_spi_transfer_rxtx(struct spi_device *spi, ...@@ -198,24 +192,14 @@ static int mpc52xx_psc_spi_transfer_rxtx(struct spi_device *spi,
return 0; return 0;
} }
static void mpc52xx_psc_spi_work(struct work_struct *work) int mpc52xx_psc_spi_transfer_one_message(struct spi_controller *ctlr,
struct spi_message *m)
{ {
struct mpc52xx_psc_spi *mps =
container_of(work, struct mpc52xx_psc_spi, work);
spin_lock_irq(&mps->lock);
mps->busy = 1;
while (!list_empty(&mps->queue)) {
struct spi_message *m;
struct spi_device *spi; struct spi_device *spi;
struct spi_transfer *t = NULL; struct spi_transfer *t = NULL;
unsigned cs_change; unsigned cs_change;
int status; int status;
m = container_of(mps->queue.next, struct spi_message, queue);
list_del_init(&m->queue);
spin_unlock_irq(&mps->lock);
spi = m->spi; spi = m->spi;
cs_change = 1; cs_change = 1;
status = 0; status = 0;
...@@ -242,25 +226,19 @@ static void mpc52xx_psc_spi_work(struct work_struct *work) ...@@ -242,25 +226,19 @@ static void mpc52xx_psc_spi_work(struct work_struct *work)
} }
m->status = status; m->status = status;
if (m->complete)
m->complete(m->context);
if (status || !cs_change) if (status || !cs_change)
mpc52xx_psc_spi_deactivate_cs(spi); mpc52xx_psc_spi_deactivate_cs(spi);
mpc52xx_psc_spi_transfer_setup(spi, NULL); mpc52xx_psc_spi_transfer_setup(spi, NULL);
spin_lock_irq(&mps->lock); spi_finalize_current_message(ctlr);
}
mps->busy = 0; return 0;
spin_unlock_irq(&mps->lock);
} }
static int mpc52xx_psc_spi_setup(struct spi_device *spi) static int mpc52xx_psc_spi_setup(struct spi_device *spi)
{ {
struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
struct mpc52xx_psc_spi_cs *cs = spi->controller_state; struct mpc52xx_psc_spi_cs *cs = spi->controller_state;
unsigned long flags;
if (spi->bits_per_word%8) if (spi->bits_per_word%8)
return -EINVAL; return -EINVAL;
...@@ -275,28 +253,6 @@ static int mpc52xx_psc_spi_setup(struct spi_device *spi) ...@@ -275,28 +253,6 @@ static int mpc52xx_psc_spi_setup(struct spi_device *spi)
cs->bits_per_word = spi->bits_per_word; cs->bits_per_word = spi->bits_per_word;
cs->speed_hz = spi->max_speed_hz; cs->speed_hz = spi->max_speed_hz;
spin_lock_irqsave(&mps->lock, flags);
if (!mps->busy)
mpc52xx_psc_spi_deactivate_cs(spi);
spin_unlock_irqrestore(&mps->lock, flags);
return 0;
}
static int mpc52xx_psc_spi_transfer(struct spi_device *spi,
struct spi_message *m)
{
struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
unsigned long flags;
m->actual_length = 0;
m->status = -EINPROGRESS;
spin_lock_irqsave(&mps->lock, flags);
list_add_tail(&m->queue, &mps->queue);
schedule_work(&mps->work);
spin_unlock_irqrestore(&mps->lock, flags);
return 0; return 0;
} }
...@@ -391,7 +347,7 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr, ...@@ -391,7 +347,7 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
master->num_chipselect = pdata->max_chipselect; master->num_chipselect = pdata->max_chipselect;
} }
master->setup = mpc52xx_psc_spi_setup; master->setup = mpc52xx_psc_spi_setup;
master->transfer = mpc52xx_psc_spi_transfer; master->transfer_one_message = mpc52xx_psc_spi_transfer_one_message;
master->cleanup = mpc52xx_psc_spi_cleanup; master->cleanup = mpc52xx_psc_spi_cleanup;
master->dev.of_node = dev->of_node; master->dev.of_node = dev->of_node;
...@@ -415,10 +371,7 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr, ...@@ -415,10 +371,7 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
goto free_irq; goto free_irq;
} }
spin_lock_init(&mps->lock);
init_completion(&mps->done); init_completion(&mps->done);
INIT_WORK(&mps->work, mpc52xx_psc_spi_work);
INIT_LIST_HEAD(&mps->queue);
ret = spi_register_master(master); ret = spi_register_master(master);
if (ret < 0) if (ret < 0)
...@@ -470,7 +423,6 @@ static int mpc52xx_psc_spi_of_remove(struct platform_device *op) ...@@ -470,7 +423,6 @@ static int mpc52xx_psc_spi_of_remove(struct platform_device *op)
struct spi_master *master = spi_master_get(platform_get_drvdata(op)); struct spi_master *master = spi_master_get(platform_get_drvdata(op));
struct mpc52xx_psc_spi *mps = spi_master_get_devdata(master); struct mpc52xx_psc_spi *mps = spi_master_get_devdata(master);
flush_work(&mps->work);
spi_unregister_master(master); spi_unregister_master(master);
free_irq(mps->irq, mps); free_irq(mps->irq, mps);
if (mps->psc) if (mps->psc)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment