All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping
@ 2013-08-23 11:09 Anatolij Gustschin
  2013-08-23 11:09 ` [PATCH RESEND next 2/2] net: can: mscan: improve clock API use Anatolij Gustschin
  2013-08-23 11:29 ` [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping Marc Kleine-Budde
  0 siblings, 2 replies; 7+ messages in thread
From: Anatolij Gustschin @ 2013-08-23 11:09 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc Kleine-Budde; +Cc: Gerhard Sittig, linux-can, netdev

From: Gerhard Sittig <gsi@denx.de>

add a comment about the magic of deriving an MSCAN component index
from the peripheral's physical address / register offset

Cc: linux-can@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Anatolij Gustschin <agust@denx.de>
---
 drivers/net/can/mscan/mpc5xxx_can.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/mscan/mpc5xxx_can.c b/drivers/net/can/mscan/mpc5xxx_can.c
index 5b0ee8e..bc422ba 100644
--- a/drivers/net/can/mscan/mpc5xxx_can.c
+++ b/drivers/net/can/mscan/mpc5xxx_can.c
@@ -148,7 +148,10 @@ static u32 mpc512x_can_get_clock(struct platform_device *ofdev,
 		goto exit_put;
 	}
 
-	/* Determine the MSCAN device index from the physical address */
+	/* Determine the MSCAN device index from the peripheral's
+	 * physical address. Register address offsets against the
+	 * IMMR base are:  0x1300, 0x1380, 0x2300, 0x2380
+	 */
 	pval = of_get_property(ofdev->dev.of_node, "reg", &plen);
 	BUG_ON(!pval || plen < sizeof(*pval));
 	clockidx = (*pval & 0x80) ? 1 : 0;
-- 
1.7.9.5


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

* [PATCH RESEND next 2/2] net: can: mscan: improve clock API use
  2013-08-23 11:09 [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping Anatolij Gustschin
@ 2013-08-23 11:09 ` Anatolij Gustschin
  2013-08-23 11:29 ` [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping Marc Kleine-Budde
  1 sibling, 0 replies; 7+ messages in thread
From: Anatolij Gustschin @ 2013-08-23 11:09 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc Kleine-Budde; +Cc: Gerhard Sittig, linux-can, netdev

From: Gerhard Sittig <gsi@denx.de>

the .get_clock() callback is run from probe() and might allocate
resources, introduce a .put_clock() callback that is run from remove()
to undo any allocation activities

prepare and enable the clocks in open(), disable and unprepare the
clocks in close() if clocks were acquired during probe(), to not assume
knowledge about which activities are done in probe() and remove()

use devm_get_clk() to lookup the SYS and REF clocks, to have the clocks
put upon device shutdown

store pointers to data structures upon successful allocation already
instead of deferral until complete setup, such that subroutines in the
setup sequence may access those data structures as well to track their
resource acquisition

since clock allocation remains optional, the release callback as well as
the enable/disable calls in open/close are optional as well

Cc: linux-can@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Gerhard Sittig <gsi@denx.de>
Signed-off-by: Anatolij Gustschin <agust@denx.de>
---
 drivers/net/can/mscan/mpc5xxx_can.c |   18 ++++++++++++------
 drivers/net/can/mscan/mscan.c       |   25 ++++++++++++++++++++++++-
 drivers/net/can/mscan/mscan.h       |    3 +++
 3 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/drivers/net/can/mscan/mpc5xxx_can.c b/drivers/net/can/mscan/mpc5xxx_can.c
index bc422ba..e59b3a3 100644
--- a/drivers/net/can/mscan/mpc5xxx_can.c
+++ b/drivers/net/can/mscan/mpc5xxx_can.c
@@ -40,6 +40,7 @@ struct mpc5xxx_can_data {
 	unsigned int type;
 	u32 (*get_clock)(struct platform_device *ofdev, const char *clock_name,
 			 int *mscan_clksrc);
+	void (*put_clock)(struct platform_device *ofdev);
 };
 
 #ifdef CONFIG_PPC_MPC52xx
@@ -180,7 +181,7 @@ static u32 mpc512x_can_get_clock(struct platform_device *ofdev,
 			clockdiv = 1;
 
 		if (!clock_name || !strcmp(clock_name, "sys")) {
-			sys_clk = clk_get(&ofdev->dev, "sys_clk");
+			sys_clk = devm_clk_get(&ofdev->dev, "sys_clk");
 			if (IS_ERR(sys_clk)) {
 				dev_err(&ofdev->dev, "couldn't get sys_clk\n");
 				goto exit_unmap;
@@ -203,7 +204,7 @@ static u32 mpc512x_can_get_clock(struct platform_device *ofdev,
 		}
 
 		if (clocksrc < 0) {
-			ref_clk = clk_get(&ofdev->dev, "ref_clk");
+			ref_clk = devm_clk_get(&ofdev->dev, "ref_clk");
 			if (IS_ERR(ref_clk)) {
 				dev_err(&ofdev->dev, "couldn't get ref_clk\n");
 				goto exit_unmap;
@@ -280,6 +281,8 @@ static int mpc5xxx_can_probe(struct platform_device *ofdev)
 	dev = alloc_mscandev();
 	if (!dev)
 		goto exit_dispose_irq;
+	platform_set_drvdata(ofdev, dev);
+	SET_NETDEV_DEV(dev, &ofdev->dev);
 
 	priv = netdev_priv(dev);
 	priv->reg_base = base;
@@ -296,8 +299,6 @@ static int mpc5xxx_can_probe(struct platform_device *ofdev)
 		goto exit_free_mscan;
 	}
 
-	SET_NETDEV_DEV(dev, &ofdev->dev);
-
 	err = register_mscandev(dev, mscan_clksrc);
 	if (err) {
 		dev_err(&ofdev->dev, "registering %s failed (err=%d)\n",
@@ -305,8 +306,6 @@ static int mpc5xxx_can_probe(struct platform_device *ofdev)
 		goto exit_free_mscan;
 	}
 
-	platform_set_drvdata(ofdev, dev);
-
 	dev_info(&ofdev->dev, "MSCAN at 0x%p, irq %d, clock %d Hz\n",
 		 priv->reg_base, dev->irq, priv->can.clock.freq);
 
@@ -324,10 +323,17 @@ exit_unmap_mem:
 
 static int mpc5xxx_can_remove(struct platform_device *ofdev)
 {
+	const struct of_device_id *match;
+	const struct mpc5xxx_can_data *data;
 	struct net_device *dev = platform_get_drvdata(ofdev);
 	struct mscan_priv *priv = netdev_priv(dev);
 
+	match = of_match_device(mpc5xxx_can_table, &ofdev->dev);
+	data = match ? match->data : NULL;
+
 	unregister_mscandev(dev);
+	if (data && data->put_clock)
+		data->put_clock(ofdev);
 	iounmap(priv->reg_base);
 	irq_dispose_mapping(dev->irq);
 	free_candev(dev);
diff --git a/drivers/net/can/mscan/mscan.c b/drivers/net/can/mscan/mscan.c
index e6b4095..a955ec8 100644
--- a/drivers/net/can/mscan/mscan.c
+++ b/drivers/net/can/mscan/mscan.c
@@ -573,10 +573,21 @@ static int mscan_open(struct net_device *dev)
 	struct mscan_priv *priv = netdev_priv(dev);
 	struct mscan_regs __iomem *regs = priv->reg_base;
 
+	if (priv->clk_ipg) {
+		ret = clk_prepare_enable(priv->clk_ipg);
+		if (ret)
+			goto exit_retcode;
+	}
+	if (priv->clk_can) {
+		ret = clk_prepare_enable(priv->clk_can);
+		if (ret)
+			goto exit_dis_ipg_clock;
+	}
+
 	/* common open */
 	ret = open_candev(dev);
 	if (ret)
-		return ret;
+		goto exit_dis_can_clock;
 
 	napi_enable(&priv->napi);
 
@@ -604,6 +615,13 @@ exit_free_irq:
 exit_napi_disable:
 	napi_disable(&priv->napi);
 	close_candev(dev);
+exit_dis_can_clock:
+	if (priv->clk_can)
+		clk_disable_unprepare(priv->clk_can);
+exit_dis_ipg_clock:
+	if (priv->clk_ipg)
+		clk_disable_unprepare(priv->clk_ipg);
+exit_retcode:
 	return ret;
 }
 
@@ -621,6 +639,11 @@ static int mscan_close(struct net_device *dev)
 	close_candev(dev);
 	free_irq(dev->irq, dev);
 
+	if (priv->clk_can)
+		clk_disable_unprepare(priv->clk_can);
+	if (priv->clk_ipg)
+		clk_disable_unprepare(priv->clk_ipg);
+
 	return 0;
 }
 
diff --git a/drivers/net/can/mscan/mscan.h b/drivers/net/can/mscan/mscan.h
index af2ed8b..9c24d60 100644
--- a/drivers/net/can/mscan/mscan.h
+++ b/drivers/net/can/mscan/mscan.h
@@ -21,6 +21,7 @@
 #ifndef __MSCAN_H__
 #define __MSCAN_H__
 
+#include <linux/clk.h>
 #include <linux/types.h>
 
 /* MSCAN control register 0 (CANCTL0) bits */
@@ -283,6 +284,8 @@ struct mscan_priv {
 	unsigned int type; 	/* MSCAN type variants */
 	unsigned long flags;
 	void __iomem *reg_base;	/* ioremap'ed address to registers */
+	struct clk *clk_ipg;	/* clock for registers */
+	struct clk *clk_can;	/* clock for bitrates */
 	u8 shadow_statflg;
 	u8 shadow_canrier;
 	u8 cur_pri;
-- 
1.7.9.5

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

* Re: [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping
  2013-08-23 11:09 [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping Anatolij Gustschin
  2013-08-23 11:09 ` [PATCH RESEND next 2/2] net: can: mscan: improve clock API use Anatolij Gustschin
@ 2013-08-23 11:29 ` Marc Kleine-Budde
  2013-08-25 16:42   ` Oliver Hartkopp
  1 sibling, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-08-23 11:29 UTC (permalink / raw)
  To: Anatolij Gustschin; +Cc: Wolfgang Grandegger, Gerhard Sittig, linux-can, netdev

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

On 08/23/2013 01:09 PM, Anatolij Gustschin wrote:
> From: Gerhard Sittig <gsi@denx.de>
> 
> add a comment about the magic of deriving an MSCAN component index
> from the peripheral's physical address / register offset
> 
> Cc: linux-can@vger.kernel.org
> Cc: netdev@vger.kernel.org
> Signed-off-by: Gerhard Sittig <gsi@denx.de>
> Signed-off-by: Anatolij Gustschin <agust@denx.de>

Tnx, both applied to linux-can-next/testing. Will be included in the net
pull request to Daivd.

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

* Re: [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping
  2013-08-23 11:29 ` [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping Marc Kleine-Budde
@ 2013-08-25 16:42   ` Oliver Hartkopp
  2013-08-26  7:20     ` Marc Kleine-Budde
  0 siblings, 1 reply; 7+ messages in thread
From: Oliver Hartkopp @ 2013-08-25 16:42 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can

On 23.08.2013 13:29, Marc Kleine-Budde wrote:
> On 08/23/2013 01:09 PM, Anatolij Gustschin wrote:
>> From: Gerhard Sittig <gsi@denx.de>
>>
>> add a comment about the magic of deriving an MSCAN component index
>> from the peripheral's physical address / register offset
>>
>> Cc: linux-can@vger.kernel.org
>> Cc: netdev@vger.kernel.org
>> Signed-off-by: Gerhard Sittig <gsi@denx.de>
>> Signed-off-by: Anatolij Gustschin <agust@denx.de>
> 
> Tnx, both applied to linux-can-next/testing. Will be included in the net
> pull request to Daivd.

For net-next or for net?

When this stuff would be for net-next i could add a new feature for can-gw too ...

So that there's not always only one lonely item to pull for Dave ;-)

Regards,
Oliver



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

* Re: [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping
  2013-08-25 16:42   ` Oliver Hartkopp
@ 2013-08-26  7:20     ` Marc Kleine-Budde
  2013-08-29 15:29       ` Oliver Hartkopp
  0 siblings, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-08-26  7:20 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: linux-can

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

On 08/25/2013 06:42 PM, Oliver Hartkopp wrote:
> On 23.08.2013 13:29, Marc Kleine-Budde wrote:
>> On 08/23/2013 01:09 PM, Anatolij Gustschin wrote:
>>> From: Gerhard Sittig <gsi@denx.de>
>>>
>>> add a comment about the magic of deriving an MSCAN component index
>>> from the peripheral's physical address / register offset
>>>
>>> Cc: linux-can@vger.kernel.org
>>> Cc: netdev@vger.kernel.org
>>> Signed-off-by: Gerhard Sittig <gsi@denx.de>
>>> Signed-off-by: Anatolij Gustschin <agust@denx.de>
>>
>> Tnx, both applied to linux-can-next/testing. Will be included in the net
>> pull request to Daivd.
> 
> For net-next or for net?

Typo: should read "next" pull request to David. As the patches are in
the linux-can-next/testing branch, they will go into David's
net-next/master.

> When this stuff would be for net-next i could add a new feature for can-gw too ...
> So that there's not always only one lonely item to pull for Dave ;-)

Just send your patches. :D

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

* Re: [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping
  2013-08-26  7:20     ` Marc Kleine-Budde
@ 2013-08-29 15:29       ` Oliver Hartkopp
  2013-08-29 21:14         ` Marc Kleine-Budde
  0 siblings, 1 reply; 7+ messages in thread
From: Oliver Hartkopp @ 2013-08-29 15:29 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can

On 26.08.2013 09:20, Marc Kleine-Budde wrote:
> On 08/25/2013 06:42 PM, Oliver Hartkopp wrote:

>> When this stuff would be for net-next i could add a new feature for can-gw too ...
>> So that there's not always only one lonely item to pull for Dave ;-)
> 
> Just send your patches. :D

Done on 26th.

Any objections to send a pull request to Dave today/tomorrow?

If Linus intends to finalize Linux 3.11 within a week, the merge window will
close the next few days ...

https://plus.google.com/+Linux/posts/f96weYxzEu1

Regards,
Oliver



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

* Re: [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping
  2013-08-29 15:29       ` Oliver Hartkopp
@ 2013-08-29 21:14         ` Marc Kleine-Budde
  0 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2013-08-29 21:14 UTC (permalink / raw)
  To: Oliver Hartkopp; +Cc: linux-can

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

On 08/29/2013 05:29 PM, Oliver Hartkopp wrote:
> On 26.08.2013 09:20, Marc Kleine-Budde wrote:
>> On 08/25/2013 06:42 PM, Oliver Hartkopp wrote:
> 
>>> When this stuff would be for net-next i could add a new feature for can-gw too ...
>>> So that there's not always only one lonely item to pull for Dave ;-)
>>
>> Just send your patches. :D
> 
> Done on 26th.
> 
> Any objections to send a pull request to Dave today/tomorrow?
done

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

end of thread, other threads:[~2013-08-29 21:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-23 11:09 [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping Anatolij Gustschin
2013-08-23 11:09 ` [PATCH RESEND next 2/2] net: can: mscan: improve clock API use Anatolij Gustschin
2013-08-23 11:29 ` [PATCH RESEND next 1/2] net: can: mscan: add a comment on reg to idx mapping Marc Kleine-Budde
2013-08-25 16:42   ` Oliver Hartkopp
2013-08-26  7:20     ` Marc Kleine-Budde
2013-08-29 15:29       ` Oliver Hartkopp
2013-08-29 21:14         ` 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.