22 #include <linux/kernel.h>
26 #include <linux/module.h>
38 #define PFX KBUILD_MODNAME
39 #define DRV_VER "0.1.2"
79 static inline void bcm_spi_writeb(
struct bcm63xx_spi *bs,
85 static inline void bcm_spi_writew(
struct bcm63xx_spi *bs,
86 u16 value,
unsigned int offset)
91 static const unsigned bcm63xx_spi_freq_table[
SPI_CLK_MASK][2] = {
101 static int bcm63xx_spi_check_transfer(
struct spi_device *
spi,
107 if (bits_per_word != 8) {
108 dev_err(&spi->
dev,
"%s, unsupported bits_per_word=%d\n",
109 __func__, bits_per_word);
114 dev_err(&spi->
dev,
"%s, unsupported slave %d\n",
122 static void bcm63xx_spi_setup_transfer(
struct spi_device *spi,
134 if (hz >= bcm63xx_spi_freq_table[i][0]) {
135 clk_cfg = bcm63xx_spi_freq_table[
i][1];
141 if (i == SPI_CLK_MASK)
146 reg &= ~SPI_CLK_MASK;
150 dev_dbg(&spi->
dev,
"Setting clock register to %02x (hz %d)\n",
155 #define MODEBITS (SPI_CPOL | SPI_CPHA)
157 static int bcm63xx_spi_setup(
struct spi_device *spi)
162 bs = spi_master_get_devdata(spi->
master);
168 dev_err(&spi->
dev,
"%s, unsupported mode bits %x\n",
173 ret = bcm63xx_spi_check_transfer(spi,
NULL);
175 dev_err(&spi->
dev,
"setup: unsupported mode bits %x\n",
180 dev_dbg(&spi->
dev,
"%s, mode %d, %u bits/w, %u nsec/bit\n",
187 static void bcm63xx_spi_fill_tx_fifo(
struct bcm63xx_spi *bs)
198 static unsigned int bcm63xx_txrx_bufs(
struct spi_device *spi,
208 dev_dbg(&spi->
dev,
"txrx: tx %p, rx %p, len %d\n",
217 bcm63xx_spi_fill_tx_fifo(bs);
220 init_completion(&bs->
done);
245 bcm_spi_writew(bs, cmd,
SPI_CMD);
253 static int bcm63xx_spi_prepare_transfer(
struct spi_master *master)
255 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
257 pm_runtime_get_sync(&bs->
pdev->dev);
262 static int bcm63xx_spi_unprepare_transfer(
struct spi_master *master)
264 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
266 pm_runtime_put(&bs->
pdev->dev);
271 static int bcm63xx_spi_transfer_one(
struct spi_master *master,
274 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
281 unsigned int len = t->
len;
284 status = bcm63xx_spi_check_transfer(spi, t);
289 bcm63xx_spi_setup_transfer(spi, t);
293 len -= bcm63xx_txrx_bufs(spi, t);
324 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
367 dev_err(dev,
"no clock for device\n");
374 dev_err(dev,
"out of memory\n");
379 bs = spi_master_get_devdata(master);
381 platform_set_drvdata(pdev, master);
385 resource_size(r),
PFX)) {
386 dev_err(dev,
"iomem request failed\n");
394 dev_err(dev,
"unable to ioremap regs\n");
403 ret = devm_request_irq(&pdev->
dev, irq, bcm63xx_spi_interrupt, 0,
406 dev_err(dev,
"unable to request irq\n");
412 master->
setup = bcm63xx_spi_setup;
428 dev_err(dev,
"unsupported MSG_CTL width: %d\n",
430 goto out_clk_disable;
440 dev_err(dev,
"spi register failed\n");
441 goto out_clk_disable;
444 dev_info(dev,
"at 0x%08x (irq %d, FIFOs size %d) v%s\n",
452 platform_set_drvdata(pdev,
NULL);
453 spi_master_put(master);
462 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev));
463 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
474 platform_set_drvdata(pdev, 0);
476 spi_master_put(master);
482 static int bcm63xx_spi_suspend(
struct device *dev)
486 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
493 static int bcm63xx_spi_resume(
struct device *dev)
497 struct bcm63xx_spi *bs = spi_master_get_devdata(master);
504 static const struct dev_pm_ops bcm63xx_spi_pm_ops = {
505 .
suspend = bcm63xx_spi_suspend,
506 .resume = bcm63xx_spi_resume,
509 #define BCM63XX_SPI_PM_OPS (&bcm63xx_spi_pm_ops)
511 #define BCM63XX_SPI_PM_OPS NULL
516 .name =
"bcm63xx-spi",
520 .probe = bcm63xx_spi_probe,