Commit 3a93a159 authored by Manuel Lauss's avatar Manuel Lauss Committed by Linus Torvalds

spi: au1550_spi: proper platform device

Remove the Au1550 resource table and instead extract MMIO/IRQ/DMA
resources from platform resource information like any well-behaved
platform driver.
Signed-off-by: default avatarManuel Lauss <mano@roarinelk.homelinux.net>
Signed-off-by: default avatarJan Nikitenko <jan.nikitenko@gmail.com>
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4ef754b7
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/resource.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/spi/spi_bitbang.h> #include <linux/spi/spi_bitbang.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
...@@ -81,6 +82,7 @@ struct au1550_spi { ...@@ -81,6 +82,7 @@ struct au1550_spi {
struct spi_master *master; struct spi_master *master;
struct device *dev; struct device *dev;
struct au1550_spi_info *pdata; struct au1550_spi_info *pdata;
struct resource *ioarea;
}; };
...@@ -96,6 +98,8 @@ static dbdev_tab_t au1550_spi_mem_dbdev = ...@@ -96,6 +98,8 @@ static dbdev_tab_t au1550_spi_mem_dbdev =
.dev_intpolarity = 0 .dev_intpolarity = 0
}; };
static int ddma_memid; /* id to above mem dma device */
static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw); static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw);
...@@ -732,6 +736,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev) ...@@ -732,6 +736,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
{ {
struct au1550_spi *hw; struct au1550_spi *hw;
struct spi_master *master; struct spi_master *master;
struct resource *r;
int err = 0; int err = 0;
master = spi_alloc_master(&pdev->dev, sizeof(struct au1550_spi)); master = spi_alloc_master(&pdev->dev, sizeof(struct au1550_spi));
...@@ -753,76 +758,64 @@ static int __init au1550_spi_probe(struct platform_device *pdev) ...@@ -753,76 +758,64 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
goto err_no_pdata; goto err_no_pdata;
} }
platform_set_drvdata(pdev, hw); r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!r) {
init_completion(&hw->master_done); dev_err(&pdev->dev, "no IRQ\n");
err = -ENODEV;
hw->bitbang.master = hw->master;
hw->bitbang.setup_transfer = au1550_spi_setupxfer;
hw->bitbang.chipselect = au1550_spi_chipsel;
hw->bitbang.master->setup = au1550_spi_setup;
hw->bitbang.txrx_bufs = au1550_spi_txrx_bufs;
switch (hw->pdata->bus_num) {
case 0:
hw->irq = AU1550_PSC0_INT;
hw->regs = (volatile psc_spi_t *)PSC0_BASE_ADDR;
hw->dma_rx_id = DSCR_CMD0_PSC0_RX;
hw->dma_tx_id = DSCR_CMD0_PSC0_TX;
break;
case 1:
hw->irq = AU1550_PSC1_INT;
hw->regs = (volatile psc_spi_t *)PSC1_BASE_ADDR;
hw->dma_rx_id = DSCR_CMD0_PSC1_RX;
hw->dma_tx_id = DSCR_CMD0_PSC1_TX;
break;
case 2:
hw->irq = AU1550_PSC2_INT;
hw->regs = (volatile psc_spi_t *)PSC2_BASE_ADDR;
hw->dma_rx_id = DSCR_CMD0_PSC2_RX;
hw->dma_tx_id = DSCR_CMD0_PSC2_TX;
break;
case 3:
hw->irq = AU1550_PSC3_INT;
hw->regs = (volatile psc_spi_t *)PSC3_BASE_ADDR;
hw->dma_rx_id = DSCR_CMD0_PSC3_RX;
hw->dma_tx_id = DSCR_CMD0_PSC3_TX;
break;
default:
dev_err(&pdev->dev, "Wrong bus_num of SPI\n");
err = -ENOENT;
goto err_no_pdata;
}
if (request_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t),
pdev->name) == NULL) {
dev_err(&pdev->dev, "Cannot reserve iomem region\n");
err = -ENXIO;
goto err_no_iores; goto err_no_iores;
} }
hw->irq = r->start;
hw->usedma = 0;
if (usedma) { r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
if (r) {
hw->dma_tx_id = r->start;
r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
if (r) {
hw->dma_rx_id = r->start;
if (usedma && ddma_memid) {
if (pdev->dev.dma_mask == NULL) if (pdev->dev.dma_mask == NULL)
dev_warn(&pdev->dev, "no dma mask\n"); dev_warn(&pdev->dev, "no dma mask\n");
else else
hw->usedma = 1; hw->usedma = 1;
} }
}
}
if (hw->usedma) { r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
/* if (!r) {
* create memory device with 8 bits dev_devwidth dev_err(&pdev->dev, "no mmio resource\n");
* needed for proper byte ordering to spi fifo err = -ENODEV;
*/ goto err_no_iores;
int memid = au1xxx_ddma_add_device(&au1550_spi_mem_dbdev); }
if (!memid) {
dev_err(&pdev->dev, hw->ioarea = request_mem_region(r->start, sizeof(psc_spi_t),
"Cannot create dma 8 bit mem device\n"); pdev->name);
if (!hw->ioarea) {
dev_err(&pdev->dev, "Cannot reserve iomem region\n");
err = -ENXIO;
goto err_no_iores;
}
hw->regs = (psc_spi_t __iomem *)ioremap(r->start, sizeof(psc_spi_t));
if (!hw->regs) {
dev_err(&pdev->dev, "cannot ioremap\n");
err = -ENXIO; err = -ENXIO;
goto err_dma_add_dev; goto err_ioremap;
} }
hw->dma_tx_ch = au1xxx_dbdma_chan_alloc(memid, platform_set_drvdata(pdev, hw);
init_completion(&hw->master_done);
hw->bitbang.master = hw->master;
hw->bitbang.setup_transfer = au1550_spi_setupxfer;
hw->bitbang.chipselect = au1550_spi_chipsel;
hw->bitbang.master->setup = au1550_spi_setup;
hw->bitbang.txrx_bufs = au1550_spi_txrx_bufs;
if (hw->usedma) {
hw->dma_tx_ch = au1xxx_dbdma_chan_alloc(ddma_memid,
hw->dma_tx_id, NULL, (void *)hw); hw->dma_tx_id, NULL, (void *)hw);
if (hw->dma_tx_ch == 0) { if (hw->dma_tx_ch == 0) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
...@@ -841,7 +834,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev) ...@@ -841,7 +834,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
hw->dma_rx_ch = au1xxx_dbdma_chan_alloc(hw->dma_rx_id, hw->dma_rx_ch = au1xxx_dbdma_chan_alloc(hw->dma_rx_id,
memid, NULL, (void *)hw); ddma_memid, NULL, (void *)hw);
if (hw->dma_rx_ch == 0) { if (hw->dma_rx_ch == 0) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Cannot allocate rx dma channel\n"); "Cannot allocate rx dma channel\n");
...@@ -874,7 +867,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev) ...@@ -874,7 +867,7 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
goto err_no_irq; goto err_no_irq;
} }
master->bus_num = hw->pdata->bus_num; master->bus_num = pdev->id;
master->num_chipselect = hw->pdata->num_chipselect; master->num_chipselect = hw->pdata->num_chipselect;
/* /*
...@@ -924,8 +917,11 @@ static int __init au1550_spi_probe(struct platform_device *pdev) ...@@ -924,8 +917,11 @@ static int __init au1550_spi_probe(struct platform_device *pdev)
au1xxx_dbdma_chan_free(hw->dma_tx_ch); au1xxx_dbdma_chan_free(hw->dma_tx_ch);
err_no_txdma: err_no_txdma:
err_dma_add_dev: iounmap((void __iomem *)hw->regs);
release_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t));
err_ioremap:
release_resource(hw->ioarea);
kfree(hw->ioarea);
err_no_iores: err_no_iores:
err_no_pdata: err_no_pdata:
...@@ -944,7 +940,9 @@ static int __exit au1550_spi_remove(struct platform_device *pdev) ...@@ -944,7 +940,9 @@ static int __exit au1550_spi_remove(struct platform_device *pdev)
spi_bitbang_stop(&hw->bitbang); spi_bitbang_stop(&hw->bitbang);
free_irq(hw->irq, hw); free_irq(hw->irq, hw);
release_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t)); iounmap((void __iomem *)hw->regs);
release_resource(hw->ioarea);
kfree(hw->ioarea);
if (hw->usedma) { if (hw->usedma) {
au1550_spi_dma_rxtmp_free(hw); au1550_spi_dma_rxtmp_free(hw);
...@@ -971,12 +969,24 @@ static struct platform_driver au1550_spi_drv = { ...@@ -971,12 +969,24 @@ static struct platform_driver au1550_spi_drv = {
static int __init au1550_spi_init(void) static int __init au1550_spi_init(void)
{ {
/*
* create memory device with 8 bits dev_devwidth
* needed for proper byte ordering to spi fifo
*/
if (usedma) {
ddma_memid = au1xxx_ddma_add_device(&au1550_spi_mem_dbdev);
if (!ddma_memid)
printk(KERN_ERR "au1550-spi: cannot add memory"
"dbdma device\n");
}
return platform_driver_probe(&au1550_spi_drv, au1550_spi_probe); return platform_driver_probe(&au1550_spi_drv, au1550_spi_probe);
} }
module_init(au1550_spi_init); module_init(au1550_spi_init);
static void __exit au1550_spi_exit(void) static void __exit au1550_spi_exit(void)
{ {
if (usedma && ddma_memid)
au1xxx_ddma_del_device(ddma_memid);
platform_driver_unregister(&au1550_spi_drv); platform_driver_unregister(&au1550_spi_drv);
} }
module_exit(au1550_spi_exit); module_exit(au1550_spi_exit);
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define _AU1550_SPI_H_ #define _AU1550_SPI_H_
struct au1550_spi_info { struct au1550_spi_info {
s16 bus_num; /* defines which PSC and IRQ to use */
u32 mainclk_hz; /* main input clock frequency of PSC */ u32 mainclk_hz; /* main input clock frequency of PSC */
u16 num_chipselect; /* number of chipselects supported */ u16 num_chipselect; /* number of chipselects supported */
void (*activate_cs)(struct au1550_spi_info *spi, int cs, int polarity); void (*activate_cs)(struct au1550_spi_info *spi, int cs, int polarity);
......
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