aaf4a59d172811029a2edd903a0ba814a8ba0c10
[openwrt/staging/ansuel.git] /
1 From 776041498c2b285a7f745c924e10fc11ef720eae Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Thu, 10 Sep 2015 14:53:53 +0200
4 Subject: [PATCH 3/3] spi/bcm63xx-hsspi: allow for probing through devicetree
5
6 Add required binding support to probe through device tree.
7
8 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
9 ---
10 drivers/spi/spi-bcm63xx-hsspi.c | 23 ++++++++++++++++++++---
11 1 file changed, 20 insertions(+), 3 deletions(-)
12
13 --- a/drivers/spi/spi-bcm63xx-hsspi.c
14 +++ b/drivers/spi/spi-bcm63xx-hsspi.c
15 @@ -19,6 +19,7 @@
16 #include <linux/interrupt.h>
17 #include <linux/spi/spi.h>
18 #include <linux/mutex.h>
19 +#include <linux/of.h>
20
21 #define HSSPI_GLOBAL_CTRL_REG 0x0
22 #define GLOBAL_CTRL_CS_POLARITY_SHIFT 0
23 @@ -91,6 +92,7 @@
24
25 #define HSSPI_MAX_SYNC_CLOCK 30000000
26
27 +#define HSSPI_SPI_MAX_CS 8
28 #define HSSPI_BUS_NUM 1 /* 0 is legacy SPI */
29
30 struct bcm63xx_hsspi {
31 @@ -332,7 +334,7 @@ static int bcm63xx_hsspi_probe(struct pl
32 struct device *dev = &pdev->dev;
33 struct clk *clk;
34 int irq, ret;
35 - u32 reg, rate;
36 + u32 reg, rate, num_cs = HSSPI_SPI_MAX_CS;
37
38 irq = platform_get_irq(pdev, 0);
39 if (irq < 0) {
40 @@ -382,8 +384,17 @@ static int bcm63xx_hsspi_probe(struct pl
41 mutex_init(&bs->bus_mutex);
42 init_completion(&bs->done);
43
44 - master->bus_num = HSSPI_BUS_NUM;
45 - master->num_chipselect = 8;
46 + master->dev.of_node = dev->of_node;
47 + if (!dev->of_node)
48 + master->bus_num = HSSPI_BUS_NUM;
49 +
50 + of_property_read_u32(dev->of_node, "num-cs", &num_cs);
51 + if (num_cs > 8) {
52 + dev_warn(dev, "unsupported number of cs (%i), reducing to 8\n",
53 + num_cs);
54 + num_cs = HSSPI_SPI_MAX_CS;
55 + }
56 + master->num_chipselect = num_cs;
57 master->setup = bcm63xx_hsspi_setup;
58 master->transfer_one_message = bcm63xx_hsspi_transfer_one;
59 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH |
60 @@ -469,10 +480,16 @@ static int bcm63xx_hsspi_resume(struct d
61 static SIMPLE_DEV_PM_OPS(bcm63xx_hsspi_pm_ops, bcm63xx_hsspi_suspend,
62 bcm63xx_hsspi_resume);
63
64 +static const struct of_device_id bcm63xx_hsspi_of_match[] = {
65 + { .compatible = "brcm,bcm6328-hsspi", },
66 + { },
67 +};
68 +
69 static struct platform_driver bcm63xx_hsspi_driver = {
70 .driver = {
71 .name = "bcm63xx-hsspi",
72 .pm = &bcm63xx_hsspi_pm_ops,
73 + .of_match_table = bcm63xx_hsspi_of_match,
74 },
75 .probe = bcm63xx_hsspi_probe,
76 .remove = bcm63xx_hsspi_remove,