Skip to contentSkip to conversation

can: mcp251x: Add device tree support

PATCH In review Alexander Shiyan 3 participants 3 messages Nov 13, 2013

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

PATCH 3/3 can: mcp251x: Add device tree support

This patch adds Device Tree support to the Microchip MCP251X driver.

---
 .../bindings/net/can/microchip,mcp251x.txt         | 25 ++++++++++
 drivers/net/can/mcp251x.c                          | 57 ++++++++++++++++------
 2 files changed, 66 insertions(+), 16 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt new file +25 -0
new file mode 100644
index 0000000..06d95ee
@@ -0,0 +1,25 @@
+* Microchip MCP251X device tree bindings
+
+Registers a Microchip MCP251X stand-alone CAN controller connected to SPI bus.
+
+Required properties:
+ - compatible: Should be one of the following:
+   - "microchip,mcp2510" for MCP2510.
+   - "microchip,mcp2515" for MCP2515.
+ - reg: SPI chip select.
+ - clocks: The clock feeding the CAN controller.
+ - interrupt-parent: The parent interrupt controller.
+ - interrupts: Should contain IRQ line for the CAN controller.
+
+Optional properties:
+ - vdd-supply: Regulator that powers the CAN controller.
+ - xceiver-supply: Regulator that powers the CAN transceiver.
+
+Example:
+	can0: can@1 {
+		compatible = "microchip,mcp2515";
+		reg = <1>;
+		clocks = <&clk24m>;
+		interrupt-parent = <&gpio4>;
+		interrupts = <13 0x2>;
+	};
drivers/net/can/mcp251x.c +41 -16

88 lines not on this page · raw message

Signature · 1 line
1.8.1.5
maintainer Acked-by on v1 3/3
#1 lore raw
Quoted 123 lines · Alexander Shiyan

This patch adds Device Tree support to the Microchip MCP251X driver.

---
 .../bindings/net/can/microchip,mcp251x.txt         | 25 ++++++++++
 drivers/net/can/mcp251x.c                          | 57 ++++++++++++++++------
 2 files changed, 66 insertions(+), 16 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt new file +25 -0
new file mode 100644
index 0000000..06d95ee
@@ -0,0 +1,25 @@
+* Microchip MCP251X device tree bindings
+
+Registers a Microchip MCP251X stand-alone CAN controller connected to SPI bus.
+
+Required properties:
+ - compatible: Should be one of the following:
+   - "microchip,mcp2510" for MCP2510.
+   - "microchip,mcp2515" for MCP2515.
+ - reg: SPI chip select.
+ - clocks: The clock feeding the CAN controller.
+ - interrupt-parent: The parent interrupt controller.
+ - interrupts: Should contain IRQ line for the CAN controller.
+
+Optional properties:
+ - vdd-supply: Regulator that powers the CAN controller.
+ - xceiver-supply: Regulator that powers the CAN transceiver.
+
+Example:
+	can0: can@1 {
+		compatible = "microchip,mcp2515";
+		reg = <1>;
+		clocks = <&clk24m>;
+		interrupt-parent = <&gpio4>;
+		interrupts = <13 0x2>;
+	};
drivers/net/can/mcp251x.c +36 -12
index 8e133aa..9aa2822 100644
@@ -60,6 +60,8 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/spi/spi.h>
@@ -987,10 +989,38 @@ static const struct net_device_ops mcp251x_netdev_ops = {
 	.ndo_start_xmit = mcp251x_hard_start_xmit,
 };
 
+static struct of_device_id mcp251x_of_match[] = {
+	{
+		.compatible	= "microchip,mcp2510",
+		.data		= (void *)CAN_MCP251X_MCP2510,
+	},
+	{
+		.compatible	= "microchip,mcp2515",
+		.data		= (void *)CAN_MCP251X_MCP2515,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, mcp251x_of_match);
+
+static const struct spi_device_id mcp251x_id_table[] = {
+	{
+		.name		= "mcp2510",
+		.driver_data	= (kernel_ulong_t)CAN_MCP251X_MCP2510,
+	},
+	{
+		.name		= "mcp2515",
+		.driver_data	= (kernel_ulong_t)CAN_MCP251X_MCP2515,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, mcp251x_id_table);
+
 static int mcp251x_can_probe(struct spi_device *spi)
 {
 	struct net_device *net;
 	struct mcp251x_priv *priv;
+	const struct of_device_id *of_id = of_match_device(mcp251x_of_match,
+							   &spi->dev);
 	int ret;
 
 	/* Allocate can/net device */
@@ -1017,7 +1047,10 @@ static int mcp251x_can_probe(struct spi_device *spi)
 	priv->can.clock.freq = clk_get_rate(priv->clk) / 2;
 	priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
 		CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY;
-	priv->model = spi_get_device_id(spi)->driver_data;
+	if (of_id)
+		priv->model = (enum mcp251x_model)of_id->data;
+	else
+		priv->model = spi_get_device_id(spi)->driver_data;
 	priv->net = net;
 
 	priv->power = devm_regulator_get(&spi->dev, "vdd");
@@ -1198,24 +1231,16 @@ static int mcp251x_can_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(mcp251x_can_pm_ops, mcp251x_can_suspend,
 	mcp251x_can_resume);
 
-static const struct spi_device_id mcp251x_id_table[] = {
-	{ "mcp2510",	CAN_MCP251X_MCP2510 },
-	{ "mcp2515",	CAN_MCP251X_MCP2515 },
-	{ },
-};
-
-MODULE_DEVICE_TABLE(spi, mcp251x_id_table);
-
 static struct spi_driver mcp251x_can_driver = {
 	.driver = {
-		.name = DEVICE_NAME,
-		.owner = THIS_MODULE,
-		.pm = &mcp251x_can_pm_ops,
+		.name		= DEVICE_NAME,
+		.owner		= THIS_MODULE,

drivers/net/can/mcp251x.c static int mcp251x_can_resume(struct device *dev) · line 1243

Quoted 10 lines
drivers/net/can/mcp251x.c +5 -4
+		.of_match_table	= of_match_ptr(mcp251x_of_match),
+		.pm		= &mcp251x_can_pm_ops,
 	},
-
-	.id_table = mcp251x_id_table,
-	.probe = mcp251x_can_probe,
-	.remove = mcp251x_can_remove,
+	.id_table	= mcp251x_id_table,
+	.probe		= mcp251x_can_probe,
+	.remove		= mcp251x_can_remove,

Please don't reformat this. I personally don't like alignment here, as it tends to be to short if another member is added to the struct.

Looks good otherwise, please add my:

Marc

Quoted 4 lines
drivers/net/can/mcp251x.c +0 -0
 };
 module_spi_driver(mcp251x_can_driver);
 
Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#2 lore raw
In reply to Alexander Shiyan
Quoted 15 lines · Alexander Shiyan

This patch adds Device Tree support to the Microchip MCP251X driver.

---
.../bindings/net/can/microchip,mcp251x.txt | 25 ++++++++++
drivers/net/can/mcp251x.c | 57 ++++++++++++++++------

2 files changed, 66 insertions(+), 16 deletions(-)

create mode 100644 Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt

Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt new file +0 -0
new file mode 100644
index 0000000..06d95ee

Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt line 3

Quoted 3 lines
Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt new file +3 -0
@@ -0,0 +1,25 @@
+* Microchip MCP251X device tree bindings
+
+Registers a Microchip MCP251X stand-alone CAN controller connected to SPI bus.

“Register a” doesn’t seem like it should be in a binding spec.

Quoted 11 lines
Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt new file +11 -0
+
+Required properties:
+ - compatible: Should be one of the following:
+   - "microchip,mcp2510" for MCP2510.
+   - "microchip,mcp2515" for MCP2515.
+ - reg: SPI chip select.
+ - clocks: The clock feeding the CAN controller.
+ - interrupt-parent: The parent interrupt controller.
+ - interrupts: Should contain IRQ line for the CAN controller.
+
+Optional properties:

Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt line 24

Quoted 10 lines
Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt new file +10 -0
+ - vdd-supply: Regulator that powers the CAN controller.
+ - xceiver-supply: Regulator that powers the CAN transceiver.
+
+Example:
+	can0: can@1 {
+		compatible = "microchip,mcp2515";
+		reg = <1>;
+		clocks = <&clk24m>;
+		interrupt-parent = <&gpio4>;
+		interrupts = <13 0x2>;

Usually good to have example show all properties used (even optional ones)

Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt line 25

Quoted 1 line
Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt new file +1 -0
+	};

Other than the nits, binding looks good.

- k

Signature · 2 lines
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation