Cc: Jean-Hugues Deschenes <[email protected]>
Signed-off-by: Baruch Siach <[email protected]>
---
 drivers/spi/spi-dw-mmio.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index 1492f5ee9aaa..86d247ecd2d2 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -16,6 +16,7 @@
 #include <linux/spi/spi.h>
 #include <linux/scatterlist.h>
 #include <linux/module.h>
+#include <linux/of.h>
 
 #include "spi-dw.h"
 
@@ -32,6 +33,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
        struct dw_spi *dws;
        struct resource *mem;
        int ret;
+       u32 tmp;
 
        dwsmmio = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_mmio),
                        GFP_KERNEL);
@@ -67,7 +69,15 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
                return ret;
 
        dws->bus_num = pdev->id;
-       dws->num_cs = 4;
+       if (pdev->dev.of_node == NULL)
+               dws->num_cs = 4;
+       ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &tmp);
+       if (ret == 0)
+               dws->num_cs = tmp;
+       if (dws->num_cs == 0) {
+               dev_err(&pdev->dev, "missing or wrong num-cs property\n");
+               goto out;
+       }
        dws->max_freq = clk_get_rate(dwsmmio->clk);
 
        ret = dw_spi_add_host(&pdev->dev, dws);
@@ -92,12 +102,21 @@ static int dw_spi_mmio_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_OF
+static struct of_device_id dw_spi_dt_ids[] = {
+       { .compatible = "snps,designware-spi" },
+       {}
+};
+MODULE_DEVICE_TABLE(of, dw_spi_dt_ids);
+#endif
+
 static struct platform_driver dw_spi_mmio_driver = {
        .probe          = dw_spi_mmio_probe,
        .remove         = dw_spi_mmio_remove,
        .driver         = {
                .name   = DRIVER_NAME,
                .owner  = THIS_MODULE,
+               .of_match_table = of_match_ptr(dw_spi_dt_ids),
        },
 };
 module_platform_driver(dw_spi_mmio_driver);
-- 
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to