Commit ff82c587 authored by John Linn's avatar John Linn Committed by Grant Likely

Xilinx: SPI: updated driver for device tree

The driver was updated to use the device tree rather than the platform data.
Signed-off-by: default avatarJohn Linn <john.linn@xilinx.com>
parent 2526c151
...@@ -15,12 +15,15 @@ ...@@ -15,12 +15,15 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/of_device.h>
#include <linux/of_spi.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/io.h> #include <linux/io.h>
#include <syslib/virtex_devices.h>
#define XILINX_SPI_NAME "xilinx_spi" #define XILINX_SPI_NAME "xilinx_spi"
/* Register definitions as per "OPB Serial Peripheral Interface (SPI) (v1.00e) /* Register definitions as per "OPB Serial Peripheral Interface (SPI) (v1.00e)
...@@ -144,23 +147,14 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi, ...@@ -144,23 +147,14 @@ static int xilinx_spi_setup_transfer(struct spi_device *spi,
struct spi_transfer *t) struct spi_transfer *t)
{ {
u8 bits_per_word; u8 bits_per_word;
u32 hz;
struct xilinx_spi *xspi = spi_master_get_devdata(spi->master);
bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word; bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word;
hz = (t) ? t->speed_hz : spi->max_speed_hz;
if (bits_per_word != 8) { if (bits_per_word != 8) {
dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n", dev_err(&spi->dev, "%s, unsupported bits_per_word=%d\n",
__func__, bits_per_word); __func__, bits_per_word);
return -EINVAL; return -EINVAL;
} }
if (hz && xspi->speed_hz > hz) {
dev_err(&spi->dev, "%s, unsupported clock rate %uHz\n",
__func__, hz);
return -EINVAL;
}
return 0; return 0;
} }
...@@ -304,32 +298,38 @@ static irqreturn_t xilinx_spi_irq(int irq, void *dev_id) ...@@ -304,32 +298,38 @@ static irqreturn_t xilinx_spi_irq(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static int __init xilinx_spi_probe(struct platform_device *dev) static int __init xilinx_spi_of_probe(struct of_device *ofdev,
const struct of_device_id *match)
{ {
int ret = 0;
struct spi_master *master; struct spi_master *master;
struct xilinx_spi *xspi; struct xilinx_spi *xspi;
struct xspi_platform_data *pdata; struct resource r_irq_struct;
struct resource *r; struct resource r_mem_struct;
struct resource *r_irq = &r_irq_struct;
struct resource *r_mem = &r_mem_struct;
int rc = 0;
const u32 *prop;
int len;
/* Get resources(memory, IRQ) associated with the device */ /* Get resources(memory, IRQ) associated with the device */
master = spi_alloc_master(&dev->dev, sizeof(struct xilinx_spi)); master = spi_alloc_master(&ofdev->dev, sizeof(struct xilinx_spi));
if (master == NULL) { if (master == NULL) {
return -ENOMEM; return -ENOMEM;
} }
platform_set_drvdata(dev, master); dev_set_drvdata(&ofdev->dev, master);
pdata = dev->dev.platform_data;
if (pdata == NULL) { rc = of_address_to_resource(ofdev->node, 0, r_mem);
ret = -ENODEV; if (rc) {
dev_warn(&ofdev->dev, "invalid address\n");
goto put_master; goto put_master;
} }
r = platform_get_resource(dev, IORESOURCE_MEM, 0); rc = of_irq_to_resource(ofdev->node, 0, r_irq);
if (r == NULL) { if (rc == NO_IRQ) {
ret = -ENODEV; dev_warn(&ofdev->dev, "no IRQ found\n");
goto put_master; goto put_master;
} }
...@@ -341,47 +341,57 @@ static int __init xilinx_spi_probe(struct platform_device *dev) ...@@ -341,47 +341,57 @@ static int __init xilinx_spi_probe(struct platform_device *dev)
xspi->bitbang.master->setup = xilinx_spi_setup; xspi->bitbang.master->setup = xilinx_spi_setup;
init_completion(&xspi->done); init_completion(&xspi->done);
if (!request_mem_region(r->start, xspi->irq = r_irq->start;
r->end - r->start + 1, XILINX_SPI_NAME)) {
ret = -ENXIO; if (!request_mem_region(r_mem->start,
r_mem->end - r_mem->start + 1, XILINX_SPI_NAME)) {
rc = -ENXIO;
dev_warn(&ofdev->dev, "memory request failure\n");
goto put_master; goto put_master;
} }
xspi->regs = ioremap(r->start, r->end - r->start + 1); xspi->regs = ioremap(r_mem->start, r_mem->end - r_mem->start + 1);
if (xspi->regs == NULL) { if (xspi->regs == NULL) {
ret = -ENOMEM; rc = -ENOMEM;
dev_warn(&ofdev->dev, "ioremap failure\n");
goto put_master; goto put_master;
} }
xspi->irq = r_irq->start;
ret = platform_get_irq(dev, 0); /* dynamic bus assignment */
if (ret < 0) { master->bus_num = -1;
ret = -ENXIO;
goto unmap_io;
}
xspi->irq = ret;
master->bus_num = pdata->bus_num; /* number of slave select bits is required */
master->num_chipselect = pdata->num_chipselect; prop = of_get_property(ofdev->node, "xlnx,num-ss-bits", &len);
xspi->speed_hz = pdata->speed_hz; if (!prop || len < sizeof(*prop)) {
dev_warn(&ofdev->dev, "no 'xlnx,num-ss-bits' property\n");
goto put_master;
}
master->num_chipselect = *prop;
/* SPI controller initializations */ /* SPI controller initializations */
xspi_init_hw(xspi->regs); xspi_init_hw(xspi->regs);
/* Register for SPI Interrupt */ /* Register for SPI Interrupt */
ret = request_irq(xspi->irq, xilinx_spi_irq, 0, XILINX_SPI_NAME, xspi); rc = request_irq(xspi->irq, xilinx_spi_irq, 0, XILINX_SPI_NAME, xspi);
if (ret != 0) if (rc != 0) {
dev_warn(&ofdev->dev, "irq request failure: %d\n", xspi->irq);
goto unmap_io; goto unmap_io;
}
ret = spi_bitbang_start(&xspi->bitbang); rc = spi_bitbang_start(&xspi->bitbang);
if (ret != 0) { if (rc != 0) {
dev_err(&dev->dev, "spi_bitbang_start FAILED\n"); dev_err(&ofdev->dev, "spi_bitbang_start FAILED\n");
goto free_irq; goto free_irq;
} }
dev_info(&dev->dev, "at 0x%08X mapped to 0x%08X, irq=%d\n", dev_info(&ofdev->dev, "at 0x%08X mapped to 0x%08X, irq=%d\n",
r->start, (u32)xspi->regs, xspi->irq); (unsigned int)r_mem->start, (u32)xspi->regs, xspi->irq);
/* Add any subnodes on the SPI bus */
of_register_spi_devices(master, ofdev->node);
return ret; return rc;
free_irq: free_irq:
free_irq(xspi->irq, xspi); free_irq(xspi->irq, xspi);
...@@ -389,21 +399,21 @@ static int __init xilinx_spi_probe(struct platform_device *dev) ...@@ -389,21 +399,21 @@ static int __init xilinx_spi_probe(struct platform_device *dev)
iounmap(xspi->regs); iounmap(xspi->regs);
put_master: put_master:
spi_master_put(master); spi_master_put(master);
return ret; return rc;
} }
static int __devexit xilinx_spi_remove(struct platform_device *dev) static int __devexit xilinx_spi_remove(struct of_device *ofdev)
{ {
struct xilinx_spi *xspi; struct xilinx_spi *xspi;
struct spi_master *master; struct spi_master *master;
master = platform_get_drvdata(dev); master = platform_get_drvdata(ofdev);
xspi = spi_master_get_devdata(master); xspi = spi_master_get_devdata(master);
spi_bitbang_stop(&xspi->bitbang); spi_bitbang_stop(&xspi->bitbang);
free_irq(xspi->irq, xspi); free_irq(xspi->irq, xspi);
iounmap(xspi->regs); iounmap(xspi->regs);
platform_set_drvdata(dev, 0); dev_set_drvdata(&ofdev->dev, 0);
spi_master_put(xspi->bitbang.master); spi_master_put(xspi->bitbang.master);
return 0; return 0;
...@@ -412,27 +422,42 @@ static int __devexit xilinx_spi_remove(struct platform_device *dev) ...@@ -412,27 +422,42 @@ static int __devexit xilinx_spi_remove(struct platform_device *dev)
/* work with hotplug and coldplug */ /* work with hotplug and coldplug */
MODULE_ALIAS("platform:" XILINX_SPI_NAME); MODULE_ALIAS("platform:" XILINX_SPI_NAME);
static struct platform_driver xilinx_spi_driver = { static int __exit xilinx_spi_of_remove(struct of_device *op)
.probe = xilinx_spi_probe, {
.remove = __devexit_p(xilinx_spi_remove), return xilinx_spi_remove(op);
}
static struct of_device_id xilinx_spi_of_match[] = {
{ .compatible = "xlnx,xps-spi-2.00.a", },
{ .compatible = "xlnx,xps-spi-2.00.b", },
{}
};
MODULE_DEVICE_TABLE(of, xilinx_spi_of_match);
static struct of_platform_driver xilinx_spi_of_driver = {
.owner = THIS_MODULE,
.name = "xilinx-xps-spi",
.match_table = xilinx_spi_of_match,
.probe = xilinx_spi_of_probe,
.remove = __exit_p(xilinx_spi_of_remove),
.driver = { .driver = {
.name = XILINX_SPI_NAME, .name = "xilinx-xps-spi",
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
}; };
static int __init xilinx_spi_init(void) static int __init xilinx_spi_init(void)
{ {
return platform_driver_register(&xilinx_spi_driver); return of_register_platform_driver(&xilinx_spi_of_driver);
} }
module_init(xilinx_spi_init); module_init(xilinx_spi_init);
static void __exit xilinx_spi_exit(void) static void __exit xilinx_spi_exit(void)
{ {
platform_driver_unregister(&xilinx_spi_driver); of_unregister_platform_driver(&xilinx_spi_of_driver);
} }
module_exit(xilinx_spi_exit); module_exit(xilinx_spi_exit);
MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>"); MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>");
MODULE_DESCRIPTION("Xilinx SPI driver"); MODULE_DESCRIPTION("Xilinx SPI driver");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
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