Skip to contentSkip to conversation

spi/bcm63xx: add device tree support

PATCH In review Jonas Gorski 2 participants 6 messages Sep 10, 2015 – Sep 11, 2015 4 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover spi/bcm63xx: add device tree support

Add support for probing spi-bcm63xx through device tree.

Depends on "spi/bcm63xx: cleanup and decouple from arch code".

Jonas Gorski (2):
spi/bcm63xx: document device tree bindings spi/bcm63xx: add support for probing through devicetree

 .../devicetree/bindings/spi/spi-bcm63xx.txt        | 33 +++++++++++++
 drivers/spi/spi-bcm63xx.c                          | 56 ++++++++++++++++------
 2 files changed, 75 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-bcm63xx.txt
Signature · 5 lines
2.1.4
--
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

A message that is not in the archive (sent off-list or not yet received): 1441898975-22540-1-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org

#2 lore raw

PATCH 1/2 spi/bcm63xx: document device tree bindings

Add documentation for the bindings of the low speed SPI controller found on most bcm63xx SoCs.

---
 .../devicetree/bindings/spi/spi-bcm63xx.txt        | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-bcm63xx.txt
Documentation/devicetree/bindings/spi/spi-bcm63xx.txt new file +33 -0
new file mode 100644
index 0000000..1a60bb9
@@ -0,0 +1,33 @@
+Binding for Broadcom BCM6348/BCM6358 SPI controller
+
+Required properties:
+- compatible: must contain one of "brcm,bcm6348-spi", "brcm,bcm6458-spi".
+- reg: Base address and size of the controllers memory area.
+- interrupts: Interrupt for the SPI block.
+- clocks: phandle of the SPI clock.
+- clock-names: has to be "spi".
+- #address-cells: <1>, as required by generic SPI binding.
+- #size-cells: <0>, also as required by generic SPI binding.
+
+Optional properties:
+- num-cs: some controllers have less than 8 cs signals. Defaults to 8
+  if absent.
+
+Child nodes as per the generic SPI binding.
+
+Example:
+
+	spi@10000800 {
+		compatible = "brcm,bcm6368-spi", "brcm,bcm6358-spi";
+		reg = <0x10000800 0x70c>;
+
+		interrupts = <1>;
+
+		clocks = <&clkctl 9>;
+		clock-names = "spi";
+
+		num-cs = <5>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
Signature · 5 lines
2.1.4
--
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

A message that is not in the archive (sent off-list or not yet received): 1441898975-22540-2-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org

Reviewed-by
#4 lore raw

Re: [PATCH 1/2] spi/bcm63xx: document device tree bindings

Quoted 15 lines · Jonas Gorski

Add documentation for the bindings of the low speed SPI controller found on most bcm63xx SoCs.

---
 .../devicetree/bindings/spi/spi-bcm63xx.txt        | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-bcm63xx.txt
Documentation/devicetree/bindings/spi/spi-bcm63xx.txt new file +0 -0
new file mode 100644
index 0000000..1a60bb9

Documentation/devicetree/bindings/spi/spi-bcm63xx.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/spi/spi-bcm63xx.txt new file +4 -0
@@ -0,0 +1,33 @@
+Binding for Broadcom BCM6348/BCM6358 SPI controller
+
+Required properties:
+- compatible: must contain one of "brcm,bcm6348-spi", "brcm,bcm6458-spi".

Typo, the second compatible should "brcm,bcm6358-spi", other than that:

Quoted 20 lines
Documentation/devicetree/bindings/spi/spi-bcm63xx.txt new file +19 -0
+- reg: Base address and size of the controllers memory area.
+- interrupts: Interrupt for the SPI block.
+- clocks: phandle of the SPI clock.
+- clock-names: has to be "spi".
+- #address-cells: <1>, as required by generic SPI binding.
+- #size-cells: <0>, also as required by generic SPI binding.
+
+Optional properties:
+- num-cs: some controllers have less than 8 cs signals. Defaults to 8
+  if absent.
+
+Child nodes as per the generic SPI binding.
+
+Example:
+
+	spi@10000800 {
+		compatible = "brcm,bcm6368-spi", "brcm,bcm6358-spi";
+		reg = <0x10000800 0x70c>;
+

Documentation/devicetree/bindings/spi/spi-bcm63xx.txt line 33

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-bcm63xx.txt new file +10 -0
+		interrupts = <1>;
+
+		clocks = <&clkctl 9>;
+		clock-names = "spi";
+
+		num-cs = <5>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};

--
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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH 1/2] spi/bcm63xx: document device tree bindings

Quoted 10 lines · Florian Fainelli
Quoted 9 lines · Jonas Gorski

Add documentation for the bindings of the low speed SPI controller found on most bcm63xx SoCs.

---
 .../devicetree/bindings/spi/spi-bcm63xx.txt        | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-bcm63xx.txt
Quoted 12 lines

Documentation/devicetree/bindings/spi/spi-bcm63xx.txt line 4

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-bcm63xx.txt new file +4 -0
new file mode 100644
index 0000000..1a60bb9
@@ -0,0 +1,33 @@
+Binding for Broadcom BCM6348/BCM6358 SPI controller
+
+Required properties:
+- compatible: must contain one of "brcm,bcm6348-spi", "brcm,bcm6458-spi".

Typo, the second compatible should "brcm,bcm6358-spi", other than that:

Oops, will fix that in v2.

Quoted 2 lines

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

#7 lore raw

PATCH 2/2 spi/bcm63xx: add support for probing through devicetree

In reply to a message not in the archive

Add required binding support to probe through device tree.

Use the compatible instead of the resource size for identifiying the block type, and allow reducing the number of cs lines through OF.

---
 drivers/spi/spi-bcm63xx.c | 56 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 42 insertions(+), 14 deletions(-)
drivers/spi/spi-bcm63xx.c +42 -14
index 42f33bc..ec094b1 100644
@@ -26,6 +26,7 @@
 #include <linux/completion.h>
 #include <linux/err.h>
 #include <linux/pm_runtime.h>
+#include <linux/of.h>
 
 /* BCM 6338/6348 SPI core */
 #define SPI_6348_RSET_SIZE		64
@@ -465,6 +466,12 @@ static const unsigned long bcm6358_spi_reg_offsets[] = {
 	[SPI_MSG_DATA_SIZE]	= SPI_6358_MSG_DATA_SIZE,
 };
 
+static const struct of_device_id bcm63xx_spi_of_match[] = {
+	{ .compatible = "brcm,bcm6348-spi", .data = &bcm6348_spi_reg_offsets },
+	{ .compatible = "brcm,bcm6358-spi", .data = &bcm6358_spi_reg_offsets },
+	{ },
+};
+
 static int bcm63xx_spi_probe(struct platform_device *pdev)
 {
 	struct resource *r;
@@ -474,6 +481,7 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
 	struct clk *clk;
 	struct bcm63xx_spi *bs;
 	int ret;
+	u32 num_cs = BCM63XX_SPI_MAX_CS;
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
@@ -516,27 +524,46 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
 		goto out_err;
 	}
 
-	master->bus_num = BCM63XX_SPI_BUS_NUM;
-	master->num_chipselect = BCM63XX_SPI_MAX_CS;
 	master->transfer_one_message = bcm63xx_spi_transfer_one;
 	master->mode_bits = MODEBITS;
 	master->bits_per_word_mask = SPI_BPW_MASK(8);
 	master->auto_runtime_pm = true;
 
-	switch (resource_size(r)) {
-	case SPI_6348_RSET_SIZE:
-		bs->reg_offsets = bcm6348_spi_reg_offsets;
-		break;
-	case SPI_6358_RSET_SIZE:
-		bs->reg_offsets = bcm6358_spi_reg_offsets;
-		break;
-	default:
-		ret = -EINVAL;
-		dev_err(dev, "unsupported register size: %i\n",
-			resource_size(r));
-		goto out_err;
+	if (dev->of_node) {
+		const struct of_device_id *match;
+
+		match = of_match_node(bcm63xx_spi_of_match, dev->of_node);
+		if (!match) {
+			ret = -EINVAL;
+			goto out_err;
+		}
+		bs->reg_offsets = match->data;
+		master->dev.of_node = dev->of_node;
+		of_property_read_u32(dev->of_node, "num-cs", &num_cs);
+		if (num_cs > BCM63XX_SPI_MAX_CS) {
+			dev_warn(dev, "unsupported number of cs (%i), reducing to 8\n",
+				 num_cs);
+			num_cs = BCM63XX_SPI_MAX_CS;
+		}
+	} else {
+		master->bus_num = BCM63XX_SPI_BUS_NUM;
+
+		switch (resource_size(r)) {
+		case SPI_6348_RSET_SIZE:
+			bs->reg_offsets = bcm6348_spi_reg_offsets;
+			break;
+		case SPI_6358_RSET_SIZE:
+			bs->reg_offsets = bcm6358_spi_reg_offsets;
+			break;
+		default:
+			ret = -EINVAL;
+			dev_err(dev, "unsupported register size: %i\n",
+				resource_size(r));
+			goto out_err;
+		}
 	}
 
+	master->num_chipselect = num_cs;
 	bs->msg_type_shift = bs->reg_offsets[SPI_MSG_TYPE_SHIFT];
 	bs->msg_ctl_width = bs->reg_offsets[SPI_MSG_CTL_WIDTH];
 	bs->fifo_size = bs->reg_offsets[SPI_MSG_DATA_SIZE];
@@ -621,6 +648,7 @@ static struct platform_driver bcm63xx_spi_driver = {
 	.driver = {
 		.name	= "bcm63xx-spi",
 		.pm	= &bcm63xx_spi_pm_ops,
+		.of_match_table = bcm63xx_spi_of_match,
 	},
 	.probe		= bcm63xx_spi_probe,
 	.remove		= bcm63xx_spi_remove,
Signature · 5 lines
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1441898975-22540-3-git-send-email-jogo-p3rKhJxN3npAfugRpC6u6w@public.gmane.org

Reviewed-by
#9 lore raw

Re: [PATCH 2/2] spi/bcm63xx: add support for probing through devicetree

Quoted 4 lines · Jonas Gorski

Add required binding support to probe through device tree.

Use the compatible instead of the resource size for identifiying the block type, and allow reducing the number of cs lines through OF.

This looks good to me, since this builds on top of your other 6 patches, the end-result might be different, especially if we end-up using platform_device_id as suggested. Other than that:

Thanks for doing this!

Quoted 102 lines
---
 drivers/spi/spi-bcm63xx.c | 56 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 42 insertions(+), 14 deletions(-)
drivers/spi/spi-bcm63xx.c +41 -14
index 42f33bc..ec094b1 100644
@@ -26,6 +26,7 @@
 #include <linux/completion.h>
 #include <linux/err.h>
 #include <linux/pm_runtime.h>
+#include <linux/of.h>
 
 /* BCM 6338/6348 SPI core */
 #define SPI_6348_RSET_SIZE		64
@@ -465,6 +466,12 @@ static const unsigned long bcm6358_spi_reg_offsets[] = {
 	[SPI_MSG_DATA_SIZE]	= SPI_6358_MSG_DATA_SIZE,
 };
 
+static const struct of_device_id bcm63xx_spi_of_match[] = {
+	{ .compatible = "brcm,bcm6348-spi", .data = &bcm6348_spi_reg_offsets },
+	{ .compatible = "brcm,bcm6358-spi", .data = &bcm6358_spi_reg_offsets },
+	{ },
+};
+
 static int bcm63xx_spi_probe(struct platform_device *pdev)
 {
 	struct resource *r;
@@ -474,6 +481,7 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
 	struct clk *clk;
 	struct bcm63xx_spi *bs;
 	int ret;
+	u32 num_cs = BCM63XX_SPI_MAX_CS;
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
@@ -516,27 +524,46 @@ static int bcm63xx_spi_probe(struct platform_device *pdev)
 		goto out_err;
 	}
 
-	master->bus_num = BCM63XX_SPI_BUS_NUM;
-	master->num_chipselect = BCM63XX_SPI_MAX_CS;
 	master->transfer_one_message = bcm63xx_spi_transfer_one;
 	master->mode_bits = MODEBITS;
 	master->bits_per_word_mask = SPI_BPW_MASK(8);
 	master->auto_runtime_pm = true;
 
-	switch (resource_size(r)) {
-	case SPI_6348_RSET_SIZE:
-		bs->reg_offsets = bcm6348_spi_reg_offsets;
-		break;
-	case SPI_6358_RSET_SIZE:
-		bs->reg_offsets = bcm6358_spi_reg_offsets;
-		break;
-	default:
-		ret = -EINVAL;
-		dev_err(dev, "unsupported register size: %i\n",
-			resource_size(r));
-		goto out_err;
+	if (dev->of_node) {
+		const struct of_device_id *match;
+
+		match = of_match_node(bcm63xx_spi_of_match, dev->of_node);
+		if (!match) {
+			ret = -EINVAL;
+			goto out_err;
+		}
+		bs->reg_offsets = match->data;
+		master->dev.of_node = dev->of_node;
+		of_property_read_u32(dev->of_node, "num-cs", &num_cs);
+		if (num_cs > BCM63XX_SPI_MAX_CS) {
+			dev_warn(dev, "unsupported number of cs (%i), reducing to 8\n",
+				 num_cs);
+			num_cs = BCM63XX_SPI_MAX_CS;
+		}
+	} else {
+		master->bus_num = BCM63XX_SPI_BUS_NUM;
+
+		switch (resource_size(r)) {
+		case SPI_6348_RSET_SIZE:
+			bs->reg_offsets = bcm6348_spi_reg_offsets;
+			break;
+		case SPI_6358_RSET_SIZE:
+			bs->reg_offsets = bcm6358_spi_reg_offsets;
+			break;
+		default:
+			ret = -EINVAL;
+			dev_err(dev, "unsupported register size: %i\n",
+				resource_size(r));
+			goto out_err;
+		}
 	}
 
+	master->num_chipselect = num_cs;
 	bs->msg_type_shift = bs->reg_offsets[SPI_MSG_TYPE_SHIFT];
 	bs->msg_ctl_width = bs->reg_offsets[SPI_MSG_CTL_WIDTH];
 	bs->fifo_size = bs->reg_offsets[SPI_MSG_DATA_SIZE];

drivers/spi/spi-bcm63xx.c static struct platform_driver bcm63xx_spi_driver = { · line 654

Quoted 7 lines
drivers/spi/spi-bcm63xx.c +1 -0
@@ -621,6 +648,7 @@ static struct platform_driver bcm63xx_spi_driver = {
 	.driver = {
 		.name	= "bcm63xx-spi",
 		.pm	= &bcm63xx_spi_pm_ops,
+		.of_match_table = bcm63xx_spi_of_match,
 	},
 	.probe		= bcm63xx_spi_probe,
 	.remove		= bcm63xx_spi_remove,

--
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