flexcan: add err_irq handler for flexcan
Subsystems (3)
PATCH v2 1/2 flexcan: add err_irq handler for flexcan
when flexcan is not physically linked, command 'cantest' will trigger an err_irq, add err_irq handler for it.
---
Changes for v2:
- use a space instead of tab
- use flexcan_poll_state instead of print
drivers/net/can/flexcan.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/can/flexcan.c +30 -1
@@ -208,6 +208,7 @@ struct flexcan_priv {void __iomem *base;u32 reg_esr;u32 reg_ctrl_default; +unsigned int err_irq;struct clk *clk_ipg;struct clk *clk_per;
@@ -744,6 +745,23 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)return IRQ_HANDLED ; } +static irqreturn_t flexcan_err_irq (int irq,void *dev_id) +{ +struct net_device *dev = dev_id; +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->base; +u32 reg_ctrl, reg_esr; + + reg_esr =flexcan_read (®s->esr); + reg_ctrl =flexcan_read (®s->ctrl); +if (reg_esr &FLEXCAN_ESR_TX_WRN ) { +flexcan_write (reg_esr & ~FLEXCAN_ESR_TX_WRN , ®s->esr); +flexcan_write (reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK , ®s->ctrl); +flexcan_poll_state (dev, reg_esr); + } +return IRQ_HANDLED ; +} +static void flexcan_set_bittiming (struct net_device *dev) {const struct flexcan_priv *priv =netdev_priv (dev);
@@ -944,6 +962,12 @@ static int flexcan_open(struct net_device *dev)if (err) goto out_close; +if (priv->err_irq) + err =request_irq (priv->err_irq, flexcan_err_irq,IRQF_SHARED , + dev->name, dev); +if (err) + goto out_close; +/* start chip and queuing */ err =flexcan_chip_start (dev);if (err)
@@ -1099,7 +1123,7 @@ static int flexcan_probe(struct platform_device *pdev)struct resource *mem;struct clk *clk_ipg =NULL , *clk_per =NULL ;void __iomem *base; -int err, irq; +int err, irq, err_irq;u32 clock_freq =0 ;if (pdev->dev.of_node)
@@ -1126,6 +1150,10 @@ static int flexcan_probe(struct platform_device *pdev)if (irq <=0 )return -ENODEV ; + err_irq =platform_get_irq (pdev,1 ); +if (err_irq <=0 ) + err_irq =0 ; + base =devm_ioremap_resource (&pdev->dev, mem);if (IS_ERR (base))return PTR_ERR (base);
@@ -1149,6 +1177,7 @@ static int flexcan_probe(struct platform_device *pdev) dev->flags |=IFF_ECHO ; priv =netdev_priv (dev); + priv->err_irq = err_irq; priv->can.clock.freq = clock_freq; priv->can.bittiming_const = &flexcan_bittiming_const; priv->can.do_set_mode = flexcan_set_mode;
Signature · 1 line
1.8.5
PATCH v2 2/2 flexcan: add err interrupt for p1010rdb
add err interrupt for p1010rdb into dts.
---
Changes for v2:
- add binding documentation update
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt | 7 +++++-- arch/powerpc/boot/dts/fsl/p1010si-post.dtsi | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +5 -2
@@ -10,7 +10,9 @@ Required properties: - fsl,p1010-flexcan - reg : Offset and length of the register set for this device -- interrupts : Interrupt tuple for this device +- interrupts : Interrupt tuple for this device. + The first interrupt is for FlexCAN(Message Buffer and Wake Up) + The second is for error(Shared with IFC, PEX1 and some other device) Optional properties:
@@ -23,7 +25,8 @@ Example: can@1c000 { compatible = "fsl,p1010-flexcan"; reg = <0x1c000 0x1000>; - interrupts = <48 0x2>; + interrupts = <48 0x2 0 0 + 16 0x2 0 0>; interrupt-parent = <&mpic>; clock-frequency = <200000000>; // filled in by bootloader };
arch/powerpc/boot/dts/fsl/p1010si-post.dtsi +4 -2
@@ -136,13 +136,15 @@ can0: can@1c000 { compatible = "fsl,p1010-flexcan"; reg = <0x1c000 0x1000>; - interrupts = <48 0x2 0 0>; + interrupts = <48 0x2 0 0 + 16 0x2 0 0>; }; can1: can@1d000 { compatible = "fsl,p1010-flexcan"; reg = <0x1d000 0x1000>; - interrupts = <61 0x2 0 0>; + interrupts = <61 0x2 0 0 + 16 0x2 0 0>; }; L2: l2-cache-controller@20000 {
Signature · 1 line
1.8.5
Marc Kleine-Budde
maintainerRe: [PATCH v2 2/2] flexcan: add err interrupt for p1010rdb
Quoted 16 lines · Zhao Qiang
add err interrupt for p1010rdb into dts.
Signed-off-by Zhao Qiang <[email protected]>---
Changes for v2:
- add binding documentation updateDocumentation/devicetree/bindings/net/can/fsl-flexcan.txt | 7 +++++-- arch/powerpc/boot/dts/fsl/p1010si-post.dtsi | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-)Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +0
-0
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt Required properties: · line 15
Quoted 7 lines
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +3
-1@@ -10,7 +10,9 @@ Required properties: - fsl,p1010-flexcan - reg : Offset and length of the register set for this device -- interrupts : Interrupt tuple for this device +- interrupts : Interrupt tuple for this device. + The first interrupt is for FlexCAN(Message Buffer and Wake Up) + The second is for error(Shared with IFC, PEX1 and some other device)
The second interrupt is optional, at least on ARM we don't need it, please reflect this in the documentation update.
Marc
Signature · 4 lines
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 |
Re: [PATCH v2 2/2] flexcan: add err interrupt for p1010rdb
Quoted 19 lines · Marc Kleine-Budde
Quoted 18 lines · Zhao Qiang
add err interrupt for p1010rdb into dts.
Signed-off-by Zhao Qiang <[email protected]>---
Changes for v2:
- add binding documentation updateDocumentation/devicetree/bindings/net/can/fsl-flexcan.txt | 7 +++++-- arch/powerpc/boot/dts/fsl/p1010si-post.dtsi | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-)Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +0
-0@@ -10,7 +10,9 @@ Required properties: - fsl,p1010-flexcan
Quoted 8 lines
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt Required properties: · line 15
Quoted 5 lines
Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +3
-1- reg : Offset and length of the register set for this device -- interrupts : Interrupt tuple for this device +- interrupts : Interrupt tuple for this device. + The first interrupt is for FlexCAN(Message Buffer and Wake Up) + The second is for error(Shared with IFC, PEX1 and some other device)The second interrupt is optional, at least on ARM we don't need it, please reflect this in the documentation update.
The binding also shouldn't specify that the interrupt is shared, much less with specific things. It's not relevant, and may not be universally true.
-Scott
Quoted 17 lines · Zhao Qiang
when flexcan is not physically linked, command 'cantest' will trigger an
err_irq, adderr_irqhandler for it.Signed-off-by Zhao Qiang <[email protected]>---
Changes for v2:
- use a space instead of tab
- useflexcan_poll_stateinstead of printdrivers/net/can/flexcan.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)drivers/net/can/flexcan.c +0
-0
drivers/net/can/flexcan.c struct flexcan_priv { · line 211
Quoted 4 lines
drivers/net/can/flexcan.c +1
-0@@ -208,6 +208,7 @@ struct flexcan_priv {void __iomem *base;u32 reg_esr;u32 reg_ctrl_default; +unsigned int err_irq;
Why unsigned?
Quoted 6 lines
drivers/net/can/flexcan.c +6
-0+static irqreturn_t flexcan_err_irq (int irq,void *dev_id) +{ +struct net_device *dev = dev_id; +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->base; +u32 reg_ctrl, reg_esr;
drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 763
Quoted 10 lines
drivers/net/can/flexcan.c +10
-0+ + reg_esr =flexcan_read (®s->esr); + reg_ctrl =flexcan_read (®s->ctrl); +if (reg_esr &FLEXCAN_ESR_TX_WRN ) { +flexcan_write (reg_esr & ~FLEXCAN_ESR_TX_WRN , ®s->esr); +flexcan_write (reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK , ®s->ctrl); +flexcan_poll_state (dev, reg_esr); + } +return IRQ_HANDLED ; +}
You should only return IRQ_HANDLED if there was something to handle.
drivers/net/can/flexcan.c static int flexcan_open(struct net_device *dev) · line 969
Quoted 9 lines
drivers/net/can/flexcan.c +5
-0@@ -944,6 +962,12 @@ static int flexcan_open(struct net_device *dev)if (err) goto out_close; +if (priv->err_irq) + err =request_irq (priv->err_irq, flexcan_err_irq,IRQF_SHARED , + dev->name, dev); +if (err) + goto out_close;
Is this really a fatal error? And why do you check err outside the "if (priv->err_irq)" block? What if some previous code left err non-zero (either now or after some future code change)?
drivers/net/can/flexcan.c static int flexcan_probe(struct platform_device *pdev) · line 1156
Quoted 8 lines
drivers/net/can/flexcan.c +4
-0@@ -1126,6 +1150,10 @@ static int flexcan_probe(struct platform_device *pdev)if (irq <=0 )return -ENODEV ; + err_irq =platform_get_irq (pdev,1 ); +if (err_irq <=0 ) + err_irq =0 ; +
Why is this <= 0 check needed?
-Scott
Quoted 21 lines · Wood Scott
-----Original Message-----
From: Wood Scott-B07421
Sent: Saturday, June 21, 2014 12:19 AM
To: Zhao Qiang-B45475
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Wood Scott-B07421
Subject: Re: [PATCH v2 1/2] flexcan: adderr_irqhandler for flexcanQuoted 12 lines · Zhao Qiang
when flexcan is not physically linked, command 'cantest' will trigger an
err_irq, adderr_irqhandler for it.Signed-off-by Zhao Qiang <[email protected]>---
Changes for v2:
- use a space instead of tab
- useflexcan_poll_stateinstead of printdrivers/net/can/flexcan.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
Quoted 11 lines
drivers/net/can/flexcan.c struct flexcan_priv { · line 211
Quoted 9 lines
drivers/net/can/flexcan.c +1
-0@@ -208,6 +208,7 @@ struct flexcan_priv {void __iomem *base;u32 reg_esr;u32 reg_ctrl_default; +unsigned int err_irq;Why unsigned?
Err_irq is from 0.
Quoted 38 lines
Quoted 6 lines
drivers/net/can/flexcan.c +5
-0+static irqreturn_t flexcan_err_irq (int irq,void *dev_id) { +struct net_device *dev = dev_id; +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->base; +u32 reg_ctrl, reg_esr;drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 763
Quoted 10 lines
drivers/net/can/flexcan.c +10
-0+ + reg_esr =flexcan_read (®s->esr); + reg_ctrl =flexcan_read (®s->ctrl); +if (reg_esr &FLEXCAN_ESR_TX_WRN ) { +flexcan_write (reg_esr & ~FLEXCAN_ESR_TX_WRN , ®s->esr); +flexcan_write (reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK , ®s->ctrl); +flexcan_poll_state (dev, reg_esr); + } +return IRQ_HANDLED ; +}You should only return
IRQ_HANDLEDif there was something to handle.drivers/net/can/flexcan.c static int flexcan_open(struct net_device *dev) · line 969
Quoted 9 lines
drivers/net/can/flexcan.c +5
-0@@ -944,6 +962,12 @@ static int flexcan_open(struct net_device *dev)if (err) goto out_close; +if (priv->err_irq) + err =request_irq (priv->err_irq, flexcan_err_irq,IRQF_SHARED , + dev->name, dev); +if (err) + goto out_close;Is this really a fatal error? And why do you check err outside the "if (
priv->err_irq)" block? What if some previous code left err non-zero (either now or after some future code change)?drivers/net/can/flexcan.c static int flexcan_probe(struct platform_device
Quoted 1 line
drivers/net/can/flexcan.c +0
-0@@ -1126,6 +1150,10 @@ static int flexcan_probe(struct platform_device*pdev)
Quoted 3 lines
drivers/net/can/flexcan.c +0
-0if (irq <=0 )return -ENODEV ;
Quoted 6 lines
drivers/net/can/flexcan.c static int flexcan_probe(struct platform_device *pdev) · line 1156
Quoted 4 lines
drivers/net/can/flexcan.c +4
-0+ err_irq =platform_get_irq (pdev,1 ); +if (err_irq <=0 ) + err_irq =0 ; +Why is this <= 0 check needed?
Interrupt[1] is optional. If there is not interrupt[1] in dtb, err_irq will be <=0.
Quoted 3 lines
-Scott
Quoted 34 lines · On Mon, 2014-06-23 at 01:20 -0500, Zhao Qiang-B45475 wrote:
Quoted 21 lines · Wood Scott
-----Original Message-----
From: Wood Scott-B07421
Sent: Saturday, June 21, 2014 12:19 AM
To: Zhao Qiang-B45475
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Wood Scott-B07421
Subject: Re: [PATCH v2 1/2] flexcan: adderr_irqhandler for flexcanQuoted 12 lines · Zhao Qiang
when flexcan is not physically linked, command 'cantest' will trigger an
err_irq, adderr_irqhandler for it.Signed-off-by Zhao Qiang <[email protected]>---
Changes for v2:
- use a space instead of tab
- useflexcan_poll_stateinstead of printdrivers/net/can/flexcan.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)Quoted 11 lines
drivers/net/can/flexcan.c struct flexcan_priv { · line 211
Quoted 9 lines
drivers/net/can/flexcan.c +1
-0@@ -208,6 +208,7 @@ struct flexcan_priv {void __iomem *base;u32 reg_esr;u32 reg_ctrl_default; +unsigned int err_irq;Why unsigned?
Quoted 1 line
Err_irqis from 0.
So? irqs are plain "int" almost everywhere in the kernel.
-Scott
________________________________________
From: Wood Scott-B07421
Sent: Wednesday, June 25, 2014 1:34 AM
To: Zhao Qiang-B45475
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 1/2] flexcan: add err_irq handler for flexcan
Quoted 34 lines · On Mon, 2014-06-23 at 01:20 -0500, Zhao Qiang-B45475 wrote:
Quoted 21 lines · Wood Scott
-----Original Message-----
From: Wood Scott-B07421
Sent: Saturday, June 21, 2014 12:19 AM
To: Zhao Qiang-B45475
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Wood Scott-B07421
Subject: Re: [PATCH v2 1/2] flexcan: adderr_irqhandler for flexcanQuoted 12 lines · Zhao Qiang
when flexcan is not physically linked, command 'cantest' will trigger an
err_irq, adderr_irqhandler for it.Signed-off-by Zhao Qiang <[email protected]>---
Changes for v2:
- use a space instead of tab
- useflexcan_poll_stateinstead of printdrivers/net/can/flexcan.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)Quoted 11 lines
drivers/net/can/flexcan.c struct flexcan_priv { · line 211
Quoted 9 lines
drivers/net/can/flexcan.c +1
-0@@ -208,6 +208,7 @@ struct flexcan_priv {void __iomem *base;u32 reg_esr;u32 reg_ctrl_default; +unsigned int err_irq;Why unsigned?
Quoted 1 line
Err_irqis from 0.
So? irqs are plain "int" almost everywhere in the kernel.
OK, I will change it.
-Zhao
Marc Kleine-Budde
maintainerQuoted 28 lines · Zhao Qiang
when flexcan is not physically linked, command 'cantest' will trigger an
err_irq, adderr_irqhandler for it.Signed-off-by Zhao Qiang <[email protected]>---
Changes for v2:
- use a space instead of tab
- useflexcan_poll_stateinstead of printdrivers/net/can/flexcan.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)drivers/net/can/flexcan.c +1
-0@@ -208,6 +208,7 @@ struct flexcan_priv {void __iomem *base;u32 reg_esr;u32 reg_ctrl_default; +unsigned int err_irq;struct clk *clk_ipg;struct clk *clk_per;@@ -744,6 +745,23 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)return IRQ_HANDLED ; }
drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 757
Quoted 10 lines
drivers/net/can/flexcan.c +10
-0+static irqreturn_t flexcan_err_irq (int irq,void *dev_id) +{ +struct net_device *dev = dev_id; +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->base; +u32 reg_ctrl, reg_esr; + + reg_esr =flexcan_read (®s->esr); + reg_ctrl =flexcan_read (®s->ctrl); +if (reg_esr &FLEXCAN_ESR_TX_WRN ) {
When is the err_irq triggered?
drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 760
Quoted 3 lines
drivers/net/can/flexcan.c +3
-0+flexcan_write (reg_esr & ~FLEXCAN_ESR_TX_WRN , ®s->esr); +flexcan_write (reg_ctrl & ~FLEXCAN_CTRL_ERR_MSK , ®s->ctrl); +flexcan_poll_state (dev, reg_esr);
poll_state() is does not work, if called from an IRQ handler.....Depending when err_irq is triggered, is it worth to just call the normal interrupt handler?
drivers/net/can/flexcan.c static irqreturn_t flexcan_irq(int irq, void *dev_id) · line 762
Quoted 2 lines
drivers/net/can/flexcan.c +2
-0+ } +return IRQ_HANDLED ;
Please return IRQ_HANDLED, only if there really was an interrupt.
Quoted 6 lines
drivers/net/can/flexcan.c +2
-0+} +static void flexcan_set_bittiming (struct net_device *dev) {const struct flexcan_priv *priv =netdev_priv (dev);
drivers/net/can/flexcan.c static int flexcan_open(struct net_device *dev) · line 969
Quoted 8 lines
drivers/net/can/flexcan.c +5
-0@@ -944,6 +962,12 @@ static int flexcan_open(struct net_device *dev)if (err) goto out_close; +if (priv->err_irq) + err =request_irq (priv->err_irq, flexcan_err_irq,IRQF_SHARED , + dev->name, dev); +if (err) + goto out_close;
In case of an error, you don't free() dev->irq.
Quoted 26 lines
drivers/net/can/flexcan.c +6
-1+/* start chip and queuing */ err =flexcan_chip_start (dev);if (err)@@ -1099,7 +1123,7 @@ static int flexcan_probe(struct platform_device *pdev)struct resource *mem;struct clk *clk_ipg =NULL , *clk_per =NULL ;void __iomem *base; -int err, irq; +int err, irq, err_irq;u32 clock_freq =0 ;if (pdev->dev.of_node)@@ -1126,6 +1150,10 @@ static int flexcan_probe(struct platform_device *pdev)if (irq <=0 )return -ENODEV ; + err_irq =platform_get_irq (pdev,1 ); +if (err_irq <=0 ) + err_irq =0 ; + base =devm_ioremap_resource (&pdev->dev, mem);if (IS_ERR (base))return PTR_ERR (base);
drivers/net/can/flexcan.c static int flexcan_probe(struct platform_device *pdev) · line 1183
Quoted 7 lines
drivers/net/can/flexcan.c +1
-0@@ -1149,6 +1177,7 @@ static int flexcan_probe(struct platform_device *pdev) dev->flags |=IFF_ECHO ; priv =netdev_priv (dev); + priv->err_irq = err_irq; priv->can.clock.freq = clock_freq; priv->can.bittiming_const = &flexcan_bittiming_const; priv->can.do_set_mode = flexcan_set_mode;
Marc
Signature · 4 lines
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 |