Skip to content

Commit

Permalink
drivers/spi: port from N9 OSRC
Browse files Browse the repository at this point in the history
  • Loading branch information
duhansysl committed Sep 26, 2024
1 parent 5a4d6f8 commit 5fae0e2
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 157 deletions.
12 changes: 6 additions & 6 deletions drivers/spi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ config SPI_BCM2835AUX
"universal SPI master", and the regular SPI controller.
This driver is for the universal/auxiliary SPI controller.

config SENSORS_FP_SPI_NUMBER
int "Fingerprint spi port number"
default -1
help
Exclude setting of the Fingerprint Sensor

config SPI_BFIN5XX
tristate "SPI controller driver for ADI Blackfin5xx"
depends on BLACKFIN && !BF60x
Expand Down Expand Up @@ -409,6 +403,12 @@ config SPI_NUC900
help
SPI driver for Nuvoton NUC900 series ARM SoCs

config SENSORS_FP_SPI_NUMBER
int "Fingerprint spi port number"
default -1
help
Exclude setting of the Fingerprint Sensor

config SPI_OC_TINY
tristate "OpenCores tiny SPI"
depends on GPIOLIB || COMPILE_TEST
Expand Down
19 changes: 10 additions & 9 deletions drivers/spi/spi-bcm2835.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct bcm2835_spi {
u8 *rx_buf;
int tx_len;
int rx_len;
unsigned int dma_pending;
bool dma_pending;
};

static inline u32 bcm2835_rd(struct bcm2835_spi *bs, unsigned reg)
Expand Down Expand Up @@ -155,7 +155,8 @@ static irqreturn_t bcm2835_spi_interrupt(int irq, void *dev_id)
/* Write as many bytes as possible to FIFO */
bcm2835_wr_fifo(bs);

if (!bs->rx_len) {
/* based on flags decide if we can finish the transfer */
if (bcm2835_rd(bs, BCM2835_SPI_CS) & BCM2835_SPI_CS_DONE) {
/* Transfer complete - reset SPI HW */
bcm2835_spi_reset_hw(master);
/* wake up the framework */
Expand Down Expand Up @@ -232,9 +233,10 @@ static void bcm2835_spi_dma_done(void *data)
* is called the tx-dma must have finished - can't get to this
* situation otherwise...
*/
if (cmpxchg(&bs->dma_pending, true, false)) {
dmaengine_terminate_all(master->dma_tx);
}
dmaengine_terminate_all(master->dma_tx);

/* mark as no longer pending */
bs->dma_pending = 0;

/* and mark as completed */;
complete(&master->xfer_completion);
Expand Down Expand Up @@ -340,7 +342,6 @@ static int bcm2835_spi_transfer_one_dma(struct spi_master *master,
if (ret) {
/* need to reset on errors */
dmaengine_terminate_all(master->dma_tx);
bs->dma_pending = false;
bcm2835_spi_reset_hw(master);
return ret;
}
Expand Down Expand Up @@ -554,8 +555,7 @@ static int bcm2835_spi_transfer_one(struct spi_master *master,
bcm2835_wr(bs, BCM2835_SPI_CLK, cdiv);

/* handle all the 3-wire mode */
if (spi->mode & SPI_3WIRE && tfr->rx_buf &&
tfr->rx_buf != master->dummy_rx)
if ((spi->mode & SPI_3WIRE) && (tfr->rx_buf))
cs |= BCM2835_SPI_CS_REN;
else
cs &= ~BCM2835_SPI_CS_REN;
Expand Down Expand Up @@ -617,9 +617,10 @@ static void bcm2835_spi_handle_err(struct spi_master *master,
struct bcm2835_spi *bs = spi_master_get_devdata(master);

/* if an error occurred and we have an active dma, then terminate */
if (cmpxchg(&bs->dma_pending, true, false)) {
if (bs->dma_pending) {
dmaengine_terminate_all(master->dma_tx);
dmaengine_terminate_all(master->dma_rx);
bs->dma_pending = 0;
}
/* and reset */
bcm2835_spi_reset_hw(master);
Expand Down
2 changes: 1 addition & 1 deletion drivers/spi/spi-bitbang.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ int spi_bitbang_start(struct spi_bitbang *bitbang)
if (ret)
spi_master_put(master);

return ret;
return 0;
}
EXPORT_SYMBOL_GPL(spi_bitbang_start);

Expand Down
2 changes: 1 addition & 1 deletion drivers/spi/spi-davinci.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value)
pdata = &dspi->pdata;

/* program delay transfers if tx_delay is non zero */
if (spicfg && spicfg->wdelay)
if (spicfg->wdelay)
spidat1 |= SPIDAT1_WDEL;

/*
Expand Down
24 changes: 12 additions & 12 deletions drivers/spi/spi-fsl-dspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,30 +715,30 @@ static int dspi_probe(struct platform_device *pdev)
return PTR_ERR(dspi->regmap);
}

dspi->clk = devm_clk_get(&pdev->dev, "dspi");
if (IS_ERR(dspi->clk)) {
ret = PTR_ERR(dspi->clk);
dev_err(&pdev->dev, "unable to get clock\n");
goto out_master_put;
}
ret = clk_prepare_enable(dspi->clk);
if (ret)
goto out_master_put;

dspi_init(dspi);
dspi->irq = platform_get_irq(pdev, 0);
if (dspi->irq < 0) {
dev_err(&pdev->dev, "can't get platform irq\n");
ret = dspi->irq;
goto out_clk_put;
goto out_master_put;
}

ret = devm_request_irq(&pdev->dev, dspi->irq, dspi_interrupt, 0,
pdev->name, dspi);
if (ret < 0) {
dev_err(&pdev->dev, "Unable to attach DSPI interrupt\n");
goto out_clk_put;
goto out_master_put;
}

dspi->clk = devm_clk_get(&pdev->dev, "dspi");
if (IS_ERR(dspi->clk)) {
ret = PTR_ERR(dspi->clk);
dev_err(&pdev->dev, "unable to get clock\n");
goto out_master_put;
}
ret = clk_prepare_enable(dspi->clk);
if (ret)
goto out_master_put;

master->max_speed_hz =
clk_get_rate(dspi->clk) / dspi->devtype_data->max_clock_factor;
Expand Down
16 changes: 8 additions & 8 deletions drivers/spi/spi-pxa2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,14 +921,10 @@ static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)

rate = min_t(int, ssp_clk, rate);

/*
* Calculate the divisor for the SCR (Serial Clock Rate), avoiding
* that the SSP transmission rate can be greater than the device rate
*/
if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
return (DIV_ROUND_UP(ssp_clk, 2 * rate) - 1) & 0xff;
return (ssp_clk / (2 * rate) - 1) & 0xff;
else
return (DIV_ROUND_UP(ssp_clk, rate) - 1) & 0xfff;
return (ssp_clk / rate - 1) & 0xfff;
}

static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
Expand Down Expand Up @@ -1475,7 +1471,12 @@ static const struct pci_device_id pxa2xx_spi_pci_compound_match[] = {

static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
{
return param == chan->device->dev;
struct device *dev = param;

if (dev != chan->device->dev->parent)
return false;

return true;
}

static struct pxa2xx_spi_master *
Expand Down Expand Up @@ -1667,7 +1668,6 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
platform_info->enable_dma = false;
} else {
master->can_dma = pxa2xx_spi_can_dma;
master->max_dma_len = MAX_DMA_LEN;
}
}

Expand Down
43 changes: 7 additions & 36 deletions drivers/spi/spi-rspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ static int rspi_set_config_register(struct rspi_data *rspi, int access_size)
/* Sets parity, interrupt mask */
rspi_write8(rspi, 0x00, RSPI_SPCR2);

/* Resets sequencer */
rspi_write8(rspi, 0, RSPI_SPSCR);
/* Sets SPCMD */
rspi->spcmd |= SPCMD_SPB_8_TO_16(access_size);
rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0);

Expand Down Expand Up @@ -324,8 +323,7 @@ static int rspi_rz_set_config_register(struct rspi_data *rspi, int access_size)
rspi_write8(rspi, 0x00, RSPI_SSLND);
rspi_write8(rspi, 0x00, RSPI_SPND);

/* Resets sequencer */
rspi_write8(rspi, 0, RSPI_SPSCR);
/* Sets SPCMD */
rspi->spcmd |= SPCMD_SPB_8_TO_16(access_size);
rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0);

Expand Down Expand Up @@ -376,8 +374,7 @@ static int qspi_set_config_register(struct rspi_data *rspi, int access_size)
/* Sets buffer to allow normal operation */
rspi_write8(rspi, 0x00, QSPI_SPBFCR);

/* Resets sequencer */
rspi_write8(rspi, 0, RSPI_SPSCR);
/* Sets SPCMD */
rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0);

/* Enables SPI function in master mode */
Expand Down Expand Up @@ -600,13 +597,11 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx,

ret = wait_event_interruptible_timeout(rspi->wait,
rspi->dma_callbacked, HZ);
if (ret > 0 && rspi->dma_callbacked) {
if (ret > 0 && rspi->dma_callbacked)
ret = 0;
} else {
if (!ret) {
dev_err(&rspi->master->dev, "DMA timeout\n");
ret = -ETIMEDOUT;
}
else if (!ret) {
dev_err(&rspi->master->dev, "DMA timeout\n");
ret = -ETIMEDOUT;
if (tx)
dmaengine_terminate_all(rspi->master->dma_tx);
if (rx)
Expand Down Expand Up @@ -1318,36 +1313,12 @@ static const struct platform_device_id spi_driver_ids[] = {

MODULE_DEVICE_TABLE(platform, spi_driver_ids);

#ifdef CONFIG_PM_SLEEP
static int rspi_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct rspi_data *rspi = platform_get_drvdata(pdev);

return spi_master_suspend(rspi->master);
}

static int rspi_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct rspi_data *rspi = platform_get_drvdata(pdev);

return spi_master_resume(rspi->master);
}

static SIMPLE_DEV_PM_OPS(rspi_pm_ops, rspi_suspend, rspi_resume);
#define DEV_PM_OPS &rspi_pm_ops
#else
#define DEV_PM_OPS NULL
#endif /* CONFIG_PM_SLEEP */

static struct platform_driver rspi_driver = {
.probe = rspi_probe,
.remove = rspi_remove,
.id_table = spi_driver_ids,
.driver = {
.name = "renesas_spi",
.pm = DEV_PM_OPS,
.of_match_table = of_match_ptr(rspi_of_match),
},
};
Expand Down
28 changes: 1 addition & 27 deletions drivers/spi/spi-sh-msiof.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,

static void sh_msiof_reset_str(struct sh_msiof_spi_priv *p)
{
sh_msiof_write(p, STR,
sh_msiof_read(p, STR) & ~(STR_TDREQ | STR_RDREQ));
sh_msiof_write(p, STR, sh_msiof_read(p, STR));
}

static void sh_msiof_spi_write_fifo_8(struct sh_msiof_spi_priv *p,
Expand Down Expand Up @@ -1276,37 +1275,12 @@ static const struct platform_device_id spi_driver_ids[] = {
};
MODULE_DEVICE_TABLE(platform, spi_driver_ids);

#ifdef CONFIG_PM_SLEEP
static int sh_msiof_spi_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct sh_msiof_spi_priv *p = platform_get_drvdata(pdev);

return spi_master_suspend(p->master);
}

static int sh_msiof_spi_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct sh_msiof_spi_priv *p = platform_get_drvdata(pdev);

return spi_master_resume(p->master);
}

static SIMPLE_DEV_PM_OPS(sh_msiof_spi_pm_ops, sh_msiof_spi_suspend,
sh_msiof_spi_resume);
#define DEV_PM_OPS &sh_msiof_spi_pm_ops
#else
#define DEV_PM_OPS NULL
#endif /* CONFIG_PM_SLEEP */

static struct platform_driver sh_msiof_spi_drv = {
.probe = sh_msiof_spi_probe,
.remove = sh_msiof_spi_remove,
.id_table = spi_driver_ids,
.driver = {
.name = "spi_sh_msiof",
.pm = DEV_PM_OPS,
.of_match_table = of_match_ptr(sh_msiof_match),
},
};
Expand Down
Loading

0 comments on commit 5fae0e2

Please sign in to comment.