* [PATCH 3/3] can: mcp251x: Add device tree support
@ 2013-11-13 8:45 Alexander Shiyan
2013-11-13 9:16 ` Marc Kleine-Budde
2013-11-13 10:53 ` Kumar Gala
0 siblings, 2 replies; 3+ messages in thread
From: Alexander Shiyan @ 2013-11-13 8:45 UTC (permalink / raw)
To: linux-can
Cc: netdev, devicetree, Wolfgang Grandegger, Marc Kleine-Budde,
Rob Herring, Pawel Moll, Mark Rutland, Stephen Warren,
Ian Campbell, Alexander Shiyan
This patch adds Device Tree support to the Microchip MCP251X driver.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
.../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
diff --git a/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt b/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
new file mode 100644
index 0000000..06d95ee
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
@@ -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>;
+ };
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 8e133aa..9aa2822 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -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,
+ .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,
};
module_spi_driver(mcp251x_can_driver);
--
1.8.1.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 3/3] can: mcp251x: Add device tree support
2013-11-13 8:45 [PATCH 3/3] can: mcp251x: Add device tree support Alexander Shiyan
@ 2013-11-13 9:16 ` Marc Kleine-Budde
2013-11-13 10:53 ` Kumar Gala
1 sibling, 0 replies; 3+ messages in thread
From: Marc Kleine-Budde @ 2013-11-13 9:16 UTC (permalink / raw)
To: Alexander Shiyan
Cc: linux-can, netdev, devicetree, Wolfgang Grandegger, Rob Herring,
Pawel Moll, Mark Rutland, Stephen Warren, Ian Campbell
[-- Attachment #1: Type: text/plain, Size: 5191 bytes --]
On 11/13/2013 09:45 AM, Alexander Shiyan wrote:
> This patch adds Device Tree support to the Microchip MCP251X driver.
>
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
> .../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
>
> diff --git a/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt b/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
> new file mode 100644
> index 0000000..06d95ee
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
> @@ -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>;
> + };
> diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
> index 8e133aa..9aa2822 100644
> --- a/drivers/net/can/mcp251x.c
> +++ b/drivers/net/can/mcp251x.c
> @@ -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,
> + .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:
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Marc
> };
> module_spi_driver(mcp251x_can_driver);
>
>
--
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 |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 3/3] can: mcp251x: Add device tree support
2013-11-13 8:45 [PATCH 3/3] can: mcp251x: Add device tree support Alexander Shiyan
2013-11-13 9:16 ` Marc Kleine-Budde
@ 2013-11-13 10:53 ` Kumar Gala
1 sibling, 0 replies; 3+ messages in thread
From: Kumar Gala @ 2013-11-13 10:53 UTC (permalink / raw)
To: Alexander Shiyan
Cc: linux-can, netdev, devicetree, Wolfgang Grandegger,
Marc Kleine-Budde, Rob Herring, Pawel Moll, Mark Rutland,
Stephen Warren, Ian Campbell
On Nov 13, 2013, at 2:45 AM, Alexander Shiyan <shc_work@mail.ru> wrote:
> This patch adds Device Tree support to the Microchip MCP251X driver.
>
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
> .../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
>
> diff --git a/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt b/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
> new file mode 100644
> index 0000000..06d95ee
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
> @@ -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.
> +
> +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>;
Usually good to have example show all properties used (even optional ones)
> + };
Other than the nits, binding looks good.
- k
--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-11-13 10:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-13 8:45 [PATCH 3/3] can: mcp251x: Add device tree support Alexander Shiyan
2013-11-13 9:16 ` Marc Kleine-Budde
2013-11-13 10:53 ` Kumar Gala
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).