* [PATCH v10] can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller
@ 2012-09-13 8:34 Marc Kleine-Budde
2012-09-13 9:09 ` AnilKumar, Chimata
0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2012-09-13 8:34 UTC (permalink / raw)
To: linux-can; +Cc: anilkumar, Marc Kleine-Budde
From: AnilKumar Ch <anilkumar@ti.com>
Add Runtime PM support to C_CAN/D_CAN controller. The runtime PM
APIs control clocks for C_CAN/D_CAN IP and prevent access to the
register of C_CAN/D_CAN IP when clock is turned off.
Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
Hello,
I've squashed both patches into one, also changed:
- add and use c_can_pm_runtime_{enable,disable}
- remove leftovers from c_can_platform.c
- cleaned up error path in register_c_can_dev
Please test.
Marc
drivers/net/can/c_can/c_can.c | 49 ++++++++++++++++++++++++++++++--
drivers/net/can/c_can/c_can.h | 1 +
drivers/net/can/c_can/c_can_platform.c | 1 +
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 4c538e3..768bb48 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -34,6 +34,7 @@
#include <linux/if_ether.h>
#include <linux/list.h>
#include <linux/io.h>
+#include <linux/pm_runtime.h>
#include <linux/can.h>
#include <linux/can/dev.h>
@@ -201,6 +202,30 @@ static const struct can_bittiming_const c_can_bittiming_const = {
.brp_inc = 1,
};
+static inline void c_can_pm_runtime_enable(const struct c_can_priv *priv)
+{
+ if (priv->device)
+ pm_runtime_enable(priv->device);
+}
+
+static inline void c_can_pm_runtime_disable(const struct c_can_priv *priv)
+{
+ if (priv->device)
+ pm_runtime_disable(priv->device);
+}
+
+static inline void c_can_pm_runtime_get_sync(const struct c_can_priv *priv)
+{
+ if (priv->device)
+ pm_runtime_get_sync(priv->device);
+}
+
+static inline void c_can_pm_runtime_put_sync(const struct c_can_priv *priv)
+{
+ if (priv->device)
+ pm_runtime_put_sync(priv->device);
+}
+
static inline int get_tx_next_msg_obj(const struct c_can_priv *priv)
{
return (priv->tx_next & C_CAN_NEXT_MSG_OBJ_MASK) +
@@ -673,11 +698,15 @@ static int c_can_get_berr_counter(const struct net_device *dev,
unsigned int reg_err_counter;
struct c_can_priv *priv = netdev_priv(dev);
+ c_can_pm_runtime_get_sync(priv);
+
reg_err_counter = priv->read_reg(priv, C_CAN_ERR_CNT_REG);
bec->rxerr = (reg_err_counter & ERR_CNT_REC_MASK) >>
ERR_CNT_REC_SHIFT;
bec->txerr = reg_err_counter & ERR_CNT_TEC_MASK;
+ c_can_pm_runtime_put_sync(priv);
+
return 0;
}
@@ -1053,11 +1082,13 @@ static int c_can_open(struct net_device *dev)
int err;
struct c_can_priv *priv = netdev_priv(dev);
+ c_can_pm_runtime_get_sync(priv);
+
/* open the can device */
err = open_candev(dev);
if (err) {
netdev_err(dev, "failed to open can device\n");
- return err;
+ goto exit_open_fail;
}
/* register interrupt handler */
@@ -1079,6 +1110,8 @@ static int c_can_open(struct net_device *dev)
exit_irq_fail:
close_candev(dev);
+exit_open_fail:
+ c_can_pm_runtime_put_sync(priv);
return err;
}
@@ -1091,6 +1124,7 @@ static int c_can_close(struct net_device *dev)
c_can_stop(dev);
free_irq(dev->irq, dev);
close_candev(dev);
+ c_can_pm_runtime_put_sync(priv);
return 0;
}
@@ -1133,10 +1167,19 @@ static const struct net_device_ops c_can_netdev_ops = {
int register_c_can_dev(struct net_device *dev)
{
+ struct c_can_priv *priv = netdev_priv(dev);
+ int err;
+
+ c_can_pm_runtime_enable(priv);
+
dev->flags |= IFF_ECHO; /* we support local echo */
dev->netdev_ops = &c_can_netdev_ops;
- return register_candev(dev);
+ err = register_candev(dev);
+ if (err)
+ c_can_pm_runtime_disable(priv);
+
+ return err;
}
EXPORT_SYMBOL_GPL(register_c_can_dev);
@@ -1148,6 +1191,8 @@ void unregister_c_can_dev(struct net_device *dev)
c_can_enable_all_interrupts(priv, DISABLE_ALL_INTERRUPTS);
unregister_candev(dev);
+
+ c_can_pm_runtime_disable(priv);
}
EXPORT_SYMBOL_GPL(unregister_c_can_dev);
diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h
index 4e56baa..1437a6d 100644
--- a/drivers/net/can/c_can/c_can.h
+++ b/drivers/net/can/c_can/c_can.h
@@ -153,6 +153,7 @@ struct c_can_priv {
struct can_priv can; /* must be the first member */
struct napi_struct napi;
struct net_device *dev;
+ struct device *device;
int tx_object;
int current_status;
int last_status;
diff --git a/drivers/net/can/c_can/c_can_platform.c b/drivers/net/can/c_can/c_can_platform.c
index d0a66cf..7b8b7a4 100644
--- a/drivers/net/can/c_can/c_can_platform.c
+++ b/drivers/net/can/c_can/c_can_platform.c
@@ -179,6 +179,7 @@ static int __devinit c_can_plat_probe(struct platform_device *pdev)
dev->irq = irq;
priv->base = addr;
+ priv->device = &pdev->dev;
priv->can.clock.freq = clk_get_rate(clk);
priv->priv = clk;
--
1.7.10
^ permalink raw reply related [flat|nested] 6+ messages in thread* RE: [PATCH v10] can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller
2012-09-13 8:34 [PATCH v10] can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller Marc Kleine-Budde
@ 2012-09-13 9:09 ` AnilKumar, Chimata
2012-09-13 9:14 ` Marc Kleine-Budde
0 siblings, 1 reply; 6+ messages in thread
From: AnilKumar, Chimata @ 2012-09-13 9:09 UTC (permalink / raw)
To: Marc Kleine-Budde, linux-can@vger.kernel.org
On Thu, Sep 13, 2012 at 14:04:23, Marc Kleine-Budde wrote:
> From: AnilKumar Ch <anilkumar@ti.com>
>
> Add Runtime PM support to C_CAN/D_CAN controller. The runtime PM
> APIs control clocks for C_CAN/D_CAN IP and prevent access to the
> register of C_CAN/D_CAN IP when clock is turned off.
>
> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
> Hello,
>
> I've squashed both patches into one, also changed:
> - add and use c_can_pm_runtime_{enable,disable}
> - remove leftovers from c_can_platform.c
> - cleaned up error path in register_c_can_dev
>
Thanks Marc, its working.
While committing "Adopt pinctrl support" patch on top
of this patch I saw some error, can you fix that?
Thanks
AnilKumar
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v10] can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller
2012-09-13 9:09 ` AnilKumar, Chimata
@ 2012-09-13 9:14 ` Marc Kleine-Budde
2012-09-13 9:20 ` AnilKumar, Chimata
0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2012-09-13 9:14 UTC (permalink / raw)
To: AnilKumar, Chimata; +Cc: linux-can@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]
On 09/13/2012 11:09 AM, AnilKumar, Chimata wrote:
> On Thu, Sep 13, 2012 at 14:04:23, Marc Kleine-Budde wrote:
>> From: AnilKumar Ch <anilkumar@ti.com>
>>
>> Add Runtime PM support to C_CAN/D_CAN controller. The runtime PM
>> APIs control clocks for C_CAN/D_CAN IP and prevent access to the
>> register of C_CAN/D_CAN IP when clock is turned off.
>>
>> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>> ---
>> Hello,
>>
>> I've squashed both patches into one, also changed:
>> - add and use c_can_pm_runtime_{enable,disable}
>> - remove leftovers from c_can_platform.c
>> - cleaned up error path in register_c_can_dev
>>
>
> Thanks Marc, its working.
>
> While committing "Adopt pinctrl support" patch on top
> of this patch I saw some error, can you fix that?
Sure, already done :) I'll force push that on net-next/master
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 v10] can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller
2012-09-13 9:14 ` Marc Kleine-Budde
@ 2012-09-13 9:20 ` AnilKumar, Chimata
2012-09-13 9:27 ` Marc Kleine-Budde
0 siblings, 1 reply; 6+ messages in thread
From: AnilKumar, Chimata @ 2012-09-13 9:20 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can@vger.kernel.org
On Thu, Sep 13, 2012 at 14:44:55, Marc Kleine-Budde wrote:
> On 09/13/2012 11:09 AM, AnilKumar, Chimata wrote:
> > On Thu, Sep 13, 2012 at 14:04:23, Marc Kleine-Budde wrote:
> >> From: AnilKumar Ch <anilkumar@ti.com>
> >>
> >> Add Runtime PM support to C_CAN/D_CAN controller. The runtime PM
> >> APIs control clocks for C_CAN/D_CAN IP and prevent access to the
> >> register of C_CAN/D_CAN IP when clock is turned off.
> >>
> >> Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
> >> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> >> ---
> >> Hello,
> >>
> >> I've squashed both patches into one, also changed:
> >> - add and use c_can_pm_runtime_{enable,disable}
> >> - remove leftovers from c_can_platform.c
> >> - cleaned up error path in register_c_can_dev
> >>
> >
> > Thanks Marc, its working.
> >
> > While committing "Adopt pinctrl support" patch on top
> > of this patch I saw some error, can you fix that?
>
> Sure, already done :) I'll force push that on net-next/master
>
Thanks much.
Regards
AnilKumar
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v10] can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller
2012-09-13 9:20 ` AnilKumar, Chimata
@ 2012-09-13 9:27 ` Marc Kleine-Budde
2012-09-13 10:46 ` AnilKumar, Chimata
0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2012-09-13 9:27 UTC (permalink / raw)
To: AnilKumar, Chimata; +Cc: linux-can@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 561 bytes --]
On 09/13/2012 11:20 AM, AnilKumar, Chimata wrote:
[...]
>>> While committing "Adopt pinctrl support" patch on top
>>> of this patch I saw some error, can you fix that?
>>
>> Sure, already done :) I'll force push that on net-next/master
Done, can you please retest.
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 v10] can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller
2012-09-13 9:27 ` Marc Kleine-Budde
@ 2012-09-13 10:46 ` AnilKumar, Chimata
0 siblings, 0 replies; 6+ messages in thread
From: AnilKumar, Chimata @ 2012-09-13 10:46 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can@vger.kernel.org
Marc,
On Thu, Sep 13, 2012 at 14:57:54, Marc Kleine-Budde wrote:
> On 09/13/2012 11:20 AM, AnilKumar, Chimata wrote:
> [...]
>
> >>> While committing "Adopt pinctrl support" patch on top
> >>> of this patch I saw some error, can you fix that?
> >>
> >> Sure, already done :) I'll force push that on net-next/master
>
> Done, can you please retest.
>
I have tested with latest linux-can/master, its working no
issues.
Thanks
AnilKumar
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-09-13 10:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-13 8:34 [PATCH v10] can: c_can: Add runtime PM support to Bosch C_CAN/D_CAN controller Marc Kleine-Budde
2012-09-13 9:09 ` AnilKumar, Chimata
2012-09-13 9:14 ` Marc Kleine-Budde
2012-09-13 9:20 ` AnilKumar, Chimata
2012-09-13 9:27 ` Marc Kleine-Budde
2012-09-13 10:46 ` AnilKumar, Chimata
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox