Skip to contentSkip to conversation

spi: add spi controller master driver for Blackfin 6xx processor

PATCH In review Scott Jiang 2 participants 3 messages Jun 4, 2012 – Jun 5, 2012 2 messages not in the archive SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: add spi controller master driver for Blackfin 6xx processor

New spi controller is integrated into Blackfin 6xx processor. Comparing to bf5xx spi controller, we support 32 bits word size and independent receive and transmit DMA channels now. Also mode 0 and 2 (CPHA = 0) can get fully supported becasue cs line may be controlled by the software.

---
 drivers/spi/Kconfig       |    8 +-
 drivers/spi/Makefile      |    1 +
 drivers/spi/spi-bfin6xx.c | 1254 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1262 insertions(+), 1 deletions(-)
 create mode 100644 drivers/spi/spi-bfin6xx.c
drivers/spi/Kconfig +7 -1
index 00c0240..7c9a235 100644
@@ -76,10 +76,16 @@ config SPI_ATMEL
 
 config SPI_BFIN5XX
 	tristate "SPI controller driver for ADI Blackfin5xx"
-	depends on BLACKFIN
+	depends on BLACKFIN && !BF60x
 	help
 	  This is the SPI controller master driver for Blackfin 5xx processor.
 
+config SPI_BFIN6XX
+	tristate "SPI controller driver for ADI Blackfin6xx"
+	depends on BLACKFIN && BF60x
+	help
+	  This is the SPI controller master driver for Blackfin 6xx processor.
+
 config SPI_BFIN_SPORT
 	tristate "SPI bus via Blackfin SPORT"
 	depends on BLACKFIN
drivers/spi/Makefile +1 -0
index 9d75d21..d6d7abf 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_SPI_ATH79)			+= spi-ath79.o
 obj-$(CONFIG_SPI_AU1550)		+= spi-au1550.o
 obj-$(CONFIG_SPI_BCM63XX)		+= spi-bcm63xx.o
 obj-$(CONFIG_SPI_BFIN5XX)		+= spi-bfin5xx.o
+obj-$(CONFIG_SPI_BFIN6XX)               += spi-bfin6xx.o
 obj-$(CONFIG_SPI_BFIN_SPORT)		+= spi-bfin-sport.o
 obj-$(CONFIG_SPI_BITBANG)		+= spi-bitbang.o
 obj-$(CONFIG_SPI_BUTTERFLY)		+= spi-butterfly.o
drivers/spi/spi-bfin6xx.c new file +1254 -0

1,254 lines not on this page · raw message

Signature · 1 line
1.7.0.4

A message that is not in the archive (sent off-list or not yet received): 1338837689-19114-1-git-send-email-scott.jiang.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

Hi Scott,
Some minor comments?

Quoted 5 lines · Scott Jiang

New spi controller is integrated into Blackfin 6xx processor. Comparing to bf5xx spi controller, we support 32 bits word size and independent receive and transmit DMA channels now. Also mode 0 and 2 (CPHA = 0) can get fully supported becasue cs line may be controlled by the software.

<Snip>

how about using spi core queuing?

Quoted 105 lines
drivers/spi/spi-bfin6xx.c new file +105 -0
+
+       status = bfin_spi_start_queue(drv_data);
+       if (status != 0) {
+               dev_err(dev, "problem starting queue\n");
+               goto err_destroy_queue;
+       }
+
+       bfin_write(&drv_data->regs->control, SPI_CTL_MSTR | SPI_CTL_CPHA);
+       bfin_write(&drv_data->regs->ssel, 0x0000FE00);
+       bfin_write(&drv_data->regs->delay, 0x0);
+
+       /* Register with the SPI framework */
+       platform_set_drvdata(pdev, drv_data);
+       status = spi_register_master(master);
+       if (status != 0) {
+               dev_err(dev, "problem registering spi master\n");
+               goto err_free_peripheral;
+       }
+
+       dev_info(dev, "bfin-spi probe success\n");
+       return status;
+
+err_destroy_queue:
+       bfin_spi_destroy_queue(drv_data);
+err_free_peripheral:
+       peripheral_free_list(drv_data->pin_req);
+err_free_rx_dma:
+       free_dma(drv_data->rx_dma);
+err_free_tx_dma:
+       free_dma(drv_data->tx_dma);
+err_iounmap:
+       iounmap(drv_data->regs);
+err_put_master:
+       spi_master_put(master);
+
+       return status;
+}
+
+/* stop hardware and remove the driver */
+static int __devexit bfin_spi_remove(struct platform_device *pdev)
+{
+       struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev);
+
+       if (!drv_data)
+               return 0;
+
+       /* Remove the queue */
+       bfin_spi_destroy_queue(drv_data);
+
+       /* Disable the SSP at the peripheral and SOC level */
+       bfin_spi_disable(drv_data);
+
+       peripheral_free_list(drv_data->pin_req);
+       free_dma(drv_data->rx_dma);
+       free_dma(drv_data->tx_dma);
+       iounmap(drv_data->regs);
+
+       /* Disconnect from the SPI framework */
+       spi_unregister_master(drv_data->master);
+       spi_master_put(drv_data->master);
+       /* Prevent double remove */
+       platform_set_drvdata(pdev, NULL);
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int bfin_spi_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev);
+       int status = 0;
+
+       status = bfin_spi_stop_queue(drv_data);
+       if (status != 0)
+               return status;
+
+       drv_data->control = bfin_read(&drv_data->regs->control);
+       drv_data->ssel = bfin_read(&drv_data->regs->ssel);
+
+       bfin_write(&drv_data->regs->control, SPI_CTL_MSTR | SPI_CTL_CPHA);
+       bfin_write(&drv_data->regs->ssel, 0x0000FE00);
+
+       return 0;
+}
+
+static int bfin_spi_resume(struct platform_device *pdev)
+{
+       struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev);
+       int status = 0;
+
+       bfin_write(&drv_data->regs->control, drv_data->control);
+       bfin_write(&drv_data->regs->ssel, drv_data->ssel);
+
+       /* Start the queue running */
+       status = bfin_spi_start_queue(drv_data);
+       if (status != 0) {
+               dev_err(&pdev->dev, "problem starting queue (%d)\n", status);
+               return status;
+       }
+
+       return 0;
+}
+#else
+#define bfin_spi_suspend NULL
+#define bfin_spi_resume NULL

drivers/spi/spi-bfin6xx.c line 1236

Quoted 10 lines
drivers/spi/spi-bfin6xx.c new file +10 -0
+#endif /* CONFIG_PM */
+
+MODULE_ALIAS("platform:bfin-spi");
+static struct platform_driver bfin_spi_driver = {
+       .driver = {
+               .name   = "bfin-spi",
+               .owner  = THIS_MODULE,
+       },
+       .suspend        = bfin_spi_suspend,
+       .resume         = bfin_spi_resume,

Can we move to dev pm ops instead?

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

A message that is not in the archive (sent off-list or not yet received): CAM=Q2ctr6+LeP9YQDVzeOeVQ_-X_S7NoWeZtuR6dARbqyUWW6w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw
Quoted 1 line

how about using spi core queuing?

It seems this feature is not merged when I wrote this driver. I'll convert to use it.

Quoted 9 lines
Quoted 7 lines

+static struct platform_driver bfin_spi_driver = {
+       .driver = {
+               .name   = "bfin-spi",
+               .owner  = THIS_MODULE,
+       },
+       .suspend        = bfin_spi_suspend,
+       .resume         = bfin_spi_resume,

Can we move to dev pm ops instead?

ok.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/