diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2010-10-14 11:32:53 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-11-09 23:41:28 -0500 |
commit | eae6cb31d890e2860f9ce1b8ba73c27b6005af68 (patch) | |
tree | c0e7984b6f3a872be3a0deeb088fb402e1e06cd8 /drivers/spi/xilinx_spi.c | |
parent | 8fd8821b62397f8ddb7bfb23c3246a22770ab2ee (diff) |
spi/xilinx: merge OF support code into main driver
Now that the of_platform_bus_type has been merged with the platform
bus type, a single platform driver can handle both OF and non-OF use
cases. This patch merges the OF support into the platform driver.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Tested-by: Michal Simek <monstr@monstr.eu>
Diffstat (limited to 'drivers/spi/xilinx_spi.c')
-rw-r--r-- | drivers/spi/xilinx_spi.c | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c index bb3b520df9dd..7adaef62a991 100644 --- a/drivers/spi/xilinx_spi.c +++ b/drivers/spi/xilinx_spi.c | |||
@@ -16,13 +16,12 @@ | |||
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
19 | #include <linux/of.h> | ||
19 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
20 | #include <linux/spi/spi.h> | 21 | #include <linux/spi/spi.h> |
21 | #include <linux/spi/spi_bitbang.h> | 22 | #include <linux/spi/spi_bitbang.h> |
22 | #include <linux/io.h> | ||
23 | |||
24 | #include "xilinx_spi.h" | ||
25 | #include <linux/spi/xilinx_spi.h> | 23 | #include <linux/spi/xilinx_spi.h> |
24 | #include <linux/io.h> | ||
26 | 25 | ||
27 | #define XILINX_SPI_NAME "xilinx_spi" | 26 | #define XILINX_SPI_NAME "xilinx_spi" |
28 | 27 | ||
@@ -352,6 +351,15 @@ static irqreturn_t xilinx_spi_irq(int irq, void *dev_id) | |||
352 | return IRQ_HANDLED; | 351 | return IRQ_HANDLED; |
353 | } | 352 | } |
354 | 353 | ||
354 | #ifdef CONFIG_OF | ||
355 | static const struct of_device_id xilinx_spi_of_match[] = { | ||
356 | { .compatible = "xlnx,xps-spi-2.00.a", }, | ||
357 | { .compatible = "xlnx,xps-spi-2.00.b", }, | ||
358 | {} | ||
359 | }; | ||
360 | MODULE_DEVICE_TABLE(of, xilinx_spi_of_match); | ||
361 | #endif | ||
362 | |||
355 | struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem, | 363 | struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem, |
356 | u32 irq, s16 bus_num, int num_cs, int little_endian, int bits_per_word) | 364 | u32 irq, s16 bus_num, int num_cs, int little_endian, int bits_per_word) |
357 | { | 365 | { |
@@ -462,13 +470,35 @@ static int __devinit xilinx_spi_probe(struct platform_device *dev) | |||
462 | { | 470 | { |
463 | struct xspi_platform_data *pdata; | 471 | struct xspi_platform_data *pdata; |
464 | struct resource *r; | 472 | struct resource *r; |
465 | int irq; | 473 | int irq, num_cs = 0, little_endian = 0, bits_per_word = 8; |
466 | struct spi_master *master; | 474 | struct spi_master *master; |
467 | u8 i; | 475 | u8 i; |
468 | 476 | ||
469 | pdata = dev->dev.platform_data; | 477 | pdata = dev->dev.platform_data; |
470 | if (!pdata) | 478 | if (pdata) { |
471 | return -ENODEV; | 479 | num_cs = pdata->num_chipselect; |
480 | little_endian = pdata->little_endian; | ||
481 | bits_per_word = pdata->bits_per_word; | ||
482 | } | ||
483 | |||
484 | #ifdef CONFIG_OF | ||
485 | if (dev->dev.of_node) { | ||
486 | const __be32 *prop; | ||
487 | int len; | ||
488 | |||
489 | /* number of slave select bits is required */ | ||
490 | prop = of_get_property(dev->dev.of_node, "xlnx,num-ss-bits", | ||
491 | &len); | ||
492 | if (prop && len >= sizeof(*prop)) | ||
493 | num_cs = __be32_to_cpup(prop); | ||
494 | } | ||
495 | #endif | ||
496 | |||
497 | if (!num_cs) { | ||
498 | dev_err(&dev->dev, "Missing slave select configuration data\n"); | ||
499 | return -EINVAL; | ||
500 | } | ||
501 | |||
472 | 502 | ||
473 | r = platform_get_resource(dev, IORESOURCE_MEM, 0); | 503 | r = platform_get_resource(dev, IORESOURCE_MEM, 0); |
474 | if (!r) | 504 | if (!r) |
@@ -478,14 +508,15 @@ static int __devinit xilinx_spi_probe(struct platform_device *dev) | |||
478 | if (irq < 0) | 508 | if (irq < 0) |
479 | return -ENXIO; | 509 | return -ENXIO; |
480 | 510 | ||
481 | master = xilinx_spi_init(&dev->dev, r, irq, dev->id, | 511 | master = xilinx_spi_init(&dev->dev, r, irq, dev->id, num_cs, |
482 | pdata->num_chipselect, pdata->little_endian, | 512 | little_endian, bits_per_word); |
483 | pdata->bits_per_word); | ||
484 | if (!master) | 513 | if (!master) |
485 | return -ENODEV; | 514 | return -ENODEV; |
486 | 515 | ||
487 | for (i = 0; i < pdata->num_devices; i++) | 516 | if (pdata) { |
488 | spi_new_device(master, pdata->devices + i); | 517 | for (i = 0; i < pdata->num_devices; i++) |
518 | spi_new_device(master, pdata->devices + i); | ||
519 | } | ||
489 | 520 | ||
490 | platform_set_drvdata(dev, master); | 521 | platform_set_drvdata(dev, master); |
491 | return 0; | 522 | return 0; |
@@ -508,6 +539,9 @@ static struct platform_driver xilinx_spi_driver = { | |||
508 | .driver = { | 539 | .driver = { |
509 | .name = XILINX_SPI_NAME, | 540 | .name = XILINX_SPI_NAME, |
510 | .owner = THIS_MODULE, | 541 | .owner = THIS_MODULE, |
542 | #ifdef CONFIG_OF | ||
543 | .of_match_table = xilinx_spi_of_match, | ||
544 | #endif | ||
511 | }, | 545 | }, |
512 | }; | 546 | }; |
513 | 547 | ||