All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] can: mcp251x: Convert to devm-* API
@ 2013-12-15 14:16 Alexander Shiyan
  2013-12-15 14:16 ` [PATCH v2 2/2] can: mcp251x: Add device tree support Alexander Shiyan
  2013-12-16 10:17 ` [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Marc Kleine-Budde
  0 siblings, 2 replies; 6+ messages in thread
From: Alexander Shiyan @ 2013-12-15 14:16 UTC (permalink / raw)
  To: linux-can
  Cc: devicetree, Wolfgang Grandegger, Marc Kleine-Budde, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Grant Likely,
	Alexander Shiyan

Replace existing resource handling in the driver with managed
device resource, this ensures more consistent error values and
simplifies error paths.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/net/can/mcp251x.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 08ac401..7a35729 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -1067,15 +1067,17 @@ static int mcp251x_can_probe(struct spi_device *spi)
 
 	/* Allocate non-DMA buffers */
 	if (!mcp251x_enable_dma) {
-		priv->spi_tx_buf = kmalloc(SPI_TRANSFER_BUF_LEN, GFP_KERNEL);
+		priv->spi_tx_buf = devm_kzalloc(&spi->dev, SPI_TRANSFER_BUF_LEN,
+						GFP_KERNEL);
 		if (!priv->spi_tx_buf) {
 			ret = -ENOMEM;
-			goto error_tx_buf;
+			goto error_probe;
 		}
-		priv->spi_rx_buf = kmalloc(SPI_TRANSFER_BUF_LEN, GFP_KERNEL);
+		priv->spi_rx_buf = devm_kzalloc(&spi->dev, SPI_TRANSFER_BUF_LEN,
+						GFP_KERNEL);
 		if (!priv->spi_rx_buf) {
 			ret = -ENOMEM;
-			goto error_rx_buf;
+			goto error_probe;
 		}
 	}
 
@@ -1108,12 +1110,6 @@ static int mcp251x_can_probe(struct spi_device *spi)
 	return ret;
 
 error_probe:
-	if (!mcp251x_enable_dma)
-		kfree(priv->spi_rx_buf);
-error_rx_buf:
-	if (!mcp251x_enable_dma)
-		kfree(priv->spi_tx_buf);
-error_tx_buf:
 	if (mcp251x_enable_dma)
 		dma_free_coherent(&spi->dev, PAGE_SIZE,
 				  priv->spi_tx_buf, priv->spi_tx_dma);
@@ -1136,9 +1132,6 @@ static int mcp251x_can_remove(struct spi_device *spi)
 	if (mcp251x_enable_dma) {
 		dma_free_coherent(&spi->dev, PAGE_SIZE,
 				  priv->spi_tx_buf, priv->spi_tx_dma);
-	} else {
-		kfree(priv->spi_tx_buf);
-		kfree(priv->spi_rx_buf);
 	}
 
 	mcp251x_power_enable(priv->power, 0);
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] can: mcp251x: Add device tree support
  2013-12-15 14:16 [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Alexander Shiyan
@ 2013-12-15 14:16 ` Alexander Shiyan
  2013-12-16 10:20   ` Marc Kleine-Budde
  2013-12-16 10:17 ` [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Marc Kleine-Budde
  1 sibling, 1 reply; 6+ messages in thread
From: Alexander Shiyan @ 2013-12-15 14:16 UTC (permalink / raw)
  To: linux-can
  Cc: devicetree, Wolfgang Grandegger, Marc Kleine-Budde, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Grant Likely,
	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                          | 85 +++++++++++++++++-----
 2 files changed, 93 insertions(+), 17 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..ee3723b
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt
@@ -0,0 +1,25 @@
+* Microchip MCP251X stand-alone CAN controller device tree bindings
+
+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>;
+		vdd-supply = <&reg5v0>;
+		xceiver-supply = <&reg5v0>;
+	};
diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
index 7a35729..0091ae1 100644
--- a/drivers/net/can/mcp251x.c
+++ b/drivers/net/can/mcp251x.c
@@ -59,6 +59,7 @@
 #include <linux/can/dev.h>
 #include <linux/can/led.h>
 #include <linux/can/platform/mcp251x.h>
+#include <linux/clk.h>
 #include <linux/completion.h>
 #include <linux/delay.h>
 #include <linux/device.h>
@@ -69,6 +70,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>
@@ -995,16 +998,69 @@ static const struct net_device_ops mcp251x_netdev_ops = {
 	.ndo_start_xmit = mcp251x_hard_start_xmit,
 };
 
+static int mcp251x_get_frequency(struct device *dev)
+{
+	struct clk *clk;
+	int freq;
+
+	if (!dev->of_node) {
+		struct mcp251x_platform_data *pdata = dev_get_platdata(dev);
+
+		if (!pdata)
+			return -ENODATA;
+
+		freq = pdata->oscillator_frequency;
+	} else {
+		clk = devm_clk_get(dev, NULL);
+		if (IS_ERR(clk))
+			return PTR_ERR(clk);
+
+		freq = clk_get_rate(clk);
+	}
+
+	/* Sanity check */
+	if (freq < 1000000 || freq > 25000000)
+		return -EINVAL;
+
+	return freq;
+}
+
+static struct of_device_id __maybe_unused 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)
 {
+	const struct of_device_id *of_id = of_match_device(mcp251x_of_match,
+							   &spi->dev);
+	int ret = -ENODEV, freq = mcp251x_get_frequency(&spi->dev);
 	struct net_device *net;
 	struct mcp251x_priv *priv;
-	struct mcp251x_platform_data *pdata = dev_get_platdata(&spi->dev);
-	int ret = -ENODEV;
 
-	if (!pdata)
-		/* Platform data is required for osc freq */
-		goto error_out;
+	if (freq < 0)
+		return freq;
 
 	/* Allocate can/net device */
 	net = alloc_candev(sizeof(struct mcp251x_priv), TX_ECHO_SKB_MAX);
@@ -1019,10 +1075,13 @@ static int mcp251x_can_probe(struct spi_device *spi)
 	priv = netdev_priv(net);
 	priv->can.bittiming_const = &mcp251x_bittiming_const;
 	priv->can.do_set_mode = mcp251x_do_set_mode;
-	priv->can.clock.freq = pdata->oscillator_frequency / 2;
+	priv->can.clock.freq = freq / 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");
@@ -1118,7 +1177,7 @@ error_power:
 	free_candev(net);
 error_alloc:
 	dev_err(&spi->dev, "probe failed\n");
-error_out:
+
 	return ret;
 }
 
@@ -1198,21 +1257,13 @@ 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,
+		.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,
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] can: mcp251x: Convert to devm-* API
  2013-12-15 14:16 [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Alexander Shiyan
  2013-12-15 14:16 ` [PATCH v2 2/2] can: mcp251x: Add device tree support Alexander Shiyan
@ 2013-12-16 10:17 ` Marc Kleine-Budde
  2013-12-17 11:08   ` Marc Kleine-Budde
  1 sibling, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2013-12-16 10:17 UTC (permalink / raw)
  To: Alexander Shiyan
  Cc: linux-can, devicetree, Wolfgang Grandegger, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Grant Likely

[-- Attachment #1: Type: text/plain, Size: 585 bytes --]

On 12/15/2013 03:16 PM, Alexander Shiyan wrote:
> Replace existing resource handling in the driver with managed
> device resource, this ensures more consistent error values and
> simplifies error paths.
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>

Lookgs good, applied to can-next.

Marc
-- 
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] 6+ messages in thread

* Re: [PATCH v2 2/2] can: mcp251x: Add device tree support
  2013-12-15 14:16 ` [PATCH v2 2/2] can: mcp251x: Add device tree support Alexander Shiyan
@ 2013-12-16 10:20   ` Marc Kleine-Budde
  2013-12-16 10:53     ` Alexander Shiyan
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2013-12-16 10:20 UTC (permalink / raw)
  To: Alexander Shiyan
  Cc: linux-can, devicetree, Wolfgang Grandegger, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Grant Likely

[-- Attachment #1: Type: text/plain, Size: 584 bytes --]

cOn 12/15/2013 03:16 PM, Alexander Shiyan wrote:
> This patch adds Device Tree support to the Microchip MCP251X driver.

What about completing the clock support for the driver, too? You get the
clock, but it's never enabled. It probably works on your board because
it's a fixed always on clock.

Marc
-- 
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] 6+ messages in thread

* Re: [PATCH v2 2/2] can: mcp251x: Add device tree support
  2013-12-16 10:20   ` Marc Kleine-Budde
@ 2013-12-16 10:53     ` Alexander Shiyan
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Shiyan @ 2013-12-16 10:53 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: linux-can, devicetree, Wolfgang Grandegger, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Grant Likely

> cOn 12/15/2013 03:16 PM, Alexander Shiyan wrote:
> > This patch adds Device Tree support to the Microchip MCP251X driver.
> 
> What about completing the clock support for the driver, too? You get the
> clock, but it's never enabled. It probably works on your board because
> it's a fixed always on clock.

Ah, yes. OK.

---

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] can: mcp251x: Convert to devm-* API
  2013-12-16 10:17 ` [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Marc Kleine-Budde
@ 2013-12-17 11:08   ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2013-12-17 11:08 UTC (permalink / raw)
  To: Alexander Shiyan
  Cc: linux-can, devicetree, Wolfgang Grandegger, Rob Herring,
	Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, Grant Likely

[-- Attachment #1: Type: text/plain, Size: 909 bytes --]

On 12/16/2013 11:17 AM, Marc Kleine-Budde wrote:
> On 12/15/2013 03:16 PM, Alexander Shiyan wrote:
>> Replace existing resource handling in the driver with managed
>> device resource, this ensures more consistent error values and
>> simplifies error paths.
>>
>> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> 
> Lookgs good, applied to can-next.

I have included this patch in the current pull request to David Miller's
net-next. Patch 2/2 is postponed, as discussed yesterday.

If you need a tree to base your patch on, feel free to use:

    git://gitorious.org/linux-can/linux-can-next.git for-davem

Marc
-- 
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] 6+ messages in thread

end of thread, other threads:[~2013-12-17 11:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-15 14:16 [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Alexander Shiyan
2013-12-15 14:16 ` [PATCH v2 2/2] can: mcp251x: Add device tree support Alexander Shiyan
2013-12-16 10:20   ` Marc Kleine-Budde
2013-12-16 10:53     ` Alexander Shiyan
2013-12-16 10:17 ` [PATCH v2 1/2] can: mcp251x: Convert to devm-* API Marc Kleine-Budde
2013-12-17 11:08   ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.