[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5283437B.3010309@pengutronix.de>
Date: Wed, 13 Nov 2013 10:16:43 +0100
From: Marc Kleine-Budde <mkl@...gutronix.de>
To: Alexander Shiyan <shc_work@...l.ru>
CC: linux-can@...r.kernel.org, netdev@...r.kernel.org,
devicetree@...r.kernel.org,
Wolfgang Grandegger <wg@...ndegger.com>,
Rob Herring <rob.herring@...xeda.com>,
Pawel Moll <pawel.moll@....com>,
Mark Rutland <mark.rutland@....com>,
Stephen Warren <swarren@...dotorg.org>,
Ian Campbell <ijc+devicetree@...lion.org.uk>
Subject: Re: [PATCH 3/3] can: mcp251x: Add device tree support
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@...l.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@...gutronix.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 |
Download attachment "signature.asc" of type "application/pgp-signature" (260 bytes)
Powered by blists - more mailing lists