Message ID | 1313078831-2511-6-git-send-email-holt@sgi.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On 08/11/2011 06:07 PM, Robin Holt wrote: > If our CAN device's device tree node has a clock-frequency property, > then use that value for the can devices clock frequency. If not, fall > back to asking the platform/mach code for the clock frequency associated > with the flexcan device. nitpicking follows inline: > Signed-off-by: Robin Holt <holt@sgi.com> > To: Kumar Gala <galak@kernel.crashing.org> > To: Wolfgang Grandegger <wg@grandegger.com>, > To: Marc Kleine-Budde <mkl@pengutronix.de>, > To: U Bhaskar-B22300 <B22300@freescale.com> > To: Scott Wood <scottwood@freescale.com> > To: Grant Likely <grant.likely@secretlab.ca> > Cc: socketcan-core@lists.berlios.de, > Cc: netdev@vger.kernel.org, > Cc: PPC list <linuxppc-dev@lists.ozlabs.org> > Cc: devicetree-discuss@lists.ozlabs.org > --- > .../devicetree/bindings/net/can/fsl-flexcan.txt | 2 + > drivers/net/can/flexcan.c | 33 +++++++++++++++----- > 2 files changed, 27 insertions(+), 8 deletions(-) > > diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt > index c78dcbb..a4382c7 100644 > --- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt > +++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt > @@ -11,6 +11,7 @@ Required properties: > > - reg : Offset and length of the register set for this device > - interrupts : Interrupt tuple for this device > +- clock-frequency : The oscillator frequency driving the flexcan device > > Example: > > @@ -19,4 +20,5 @@ Example: > reg = <0x1c000 0x1000>; > interrupts = <48 0x2>; > interrupt-parent = <&mpic>; > + clock-frequency = <0x0bebc1fc>; Does the device tree support dec coded integers? IMHO a frequency is best expressed in decimal. > }; > diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c > index 662f832..d40c38e 100644 > --- a/drivers/net/can/flexcan.c > +++ b/drivers/net/can/flexcan.c > @@ -33,6 +33,7 @@ > #include <linux/kernel.h> > #include <linux/list.h> > #include <linux/module.h> > +#include <linux/of.h> > #include <linux/platform_device.h> > > #define DRV_NAME "flexcan" > @@ -929,12 +930,26 @@ static int __devinit flexcan_probe(struct platform_device *pdev) > void __iomem *base; > resource_size_t mem_size; > int err, irq; > + u32 clock_freq = 0; > > - clk = clk_get(&pdev->dev, NULL); > - if (IS_ERR(clk)) { > - dev_err(&pdev->dev, "no clock defined\n"); > - err = PTR_ERR(clk); > - goto failed_clock; > + if (pdev->dev.of_node) { > + const u32 *clock_freq_p; > + > + clk = NULL; Hmmm - what about moving the clk = NULL into the definition of clk? > + clock_freq_p = of_get_property(pdev->dev.of_node, > + "clock-frequency", NULL); > + if (clock_freq_p) > + clock_freq = *clock_freq_p; > + } > + > + if (!clock_freq) { > + clk = clk_get(&pdev->dev, NULL); > + if (IS_ERR(clk)) { > + dev_err(&pdev->dev, "no clock defined\n"); > + err = PTR_ERR(clk); > + goto failed_clock; > + } > + clock_freq = clk_get_rate(clk); > } > > mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); > @@ -967,7 +982,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev) > dev->flags |= IFF_ECHO; /* we support local echo in hardware */ > > priv = netdev_priv(dev); > - priv->can.clock.freq = clk_get_rate(clk); > + priv->can.clock.freq = clock_freq; > priv->can.bittiming_const = &flexcan_bittiming_const; > priv->can.do_set_mode = flexcan_set_mode; > priv->can.do_get_berr_counter = flexcan_get_berr_counter; > @@ -1002,7 +1017,8 @@ static int __devinit flexcan_probe(struct platform_device *pdev) > failed_map: > release_mem_region(mem->start, mem_size); > failed_get: > - clk_put(clk); > + if (clk) > + clk_put(clk); > failed_clock: > return err; > } > @@ -1020,7 +1036,8 @@ static int __devexit flexcan_remove(struct platform_device *pdev) > mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); > release_mem_region(mem->start, resource_size(mem)); > > - clk_put(priv->clk); > + if (priv->clk) > + clk_put(priv->clk); > > free_candev(dev); > Marc
On 08/11/2011 06:07 PM, Robin Holt wrote: > If our CAN device's device tree node has a clock-frequency property, > then use that value for the can devices clock frequency. If not, fall > back to asking the platform/mach code for the clock frequency associated > with the flexcan device. > > Signed-off-by: Robin Holt <holt@sgi.com> > To: Kumar Gala <galak@kernel.crashing.org> > To: Wolfgang Grandegger <wg@grandegger.com>, > To: Marc Kleine-Budde <mkl@pengutronix.de>, > To: U Bhaskar-B22300 <B22300@freescale.com> > To: Scott Wood <scottwood@freescale.com> > To: Grant Likely <grant.likely@secretlab.ca> > Cc: socketcan-core@lists.berlios.de, > Cc: netdev@vger.kernel.org, > Cc: PPC list <linuxppc-dev@lists.ozlabs.org> > Cc: devicetree-discuss@lists.ozlabs.org > --- > .../devicetree/bindings/net/can/fsl-flexcan.txt | 2 + > drivers/net/can/flexcan.c | 33 +++++++++++++++----- > 2 files changed, 27 insertions(+), 8 deletions(-) > > diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt > index c78dcbb..a4382c7 100644 > --- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt > +++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt > @@ -11,6 +11,7 @@ Required properties: > > - reg : Offset and length of the register set for this device > - interrupts : Interrupt tuple for this device > +- clock-frequency : The oscillator frequency driving the flexcan device > > Example: > > @@ -19,4 +20,5 @@ Example: > reg = <0x1c000 0x1000>; > interrupts = <48 0x2>; > interrupt-parent = <&mpic>; > + clock-frequency = <0x0bebc1fc>; clock-frequency = <200000000>; // filled in by bootloader Is better readable. You should also add the comment. Wolfgang.
On Aug 11, 2011, at 11:18 AM, Marc Kleine-Budde wrote: > On 08/11/2011 06:07 PM, Robin Holt wrote: >> If our CAN device's device tree node has a clock-frequency property, >> then use that value for the can devices clock frequency. If not, fall >> back to asking the platform/mach code for the clock frequency associated >> with the flexcan device. > > nitpicking follows inline: > >> Signed-off-by: Robin Holt <holt@sgi.com> >> To: Kumar Gala <galak@kernel.crashing.org> >> To: Wolfgang Grandegger <wg@grandegger.com>, >> To: Marc Kleine-Budde <mkl@pengutronix.de>, >> To: U Bhaskar-B22300 <B22300@freescale.com> >> To: Scott Wood <scottwood@freescale.com> >> To: Grant Likely <grant.likely@secretlab.ca> >> Cc: socketcan-core@lists.berlios.de, >> Cc: netdev@vger.kernel.org, >> Cc: PPC list <linuxppc-dev@lists.ozlabs.org> >> Cc: devicetree-discuss@lists.ozlabs.org >> --- >> .../devicetree/bindings/net/can/fsl-flexcan.txt | 2 + >> drivers/net/can/flexcan.c | 33 +++++++++++++++----- >> 2 files changed, 27 insertions(+), 8 deletions(-) >> >> diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt >> index c78dcbb..a4382c7 100644 >> --- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt >> +++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt >> @@ -11,6 +11,7 @@ Required properties: >> >> - reg : Offset and length of the register set for this device >> - interrupts : Interrupt tuple for this device >> +- clock-frequency : The oscillator frequency driving the flexcan device >> >> Example: >> >> @@ -19,4 +20,5 @@ Example: >> reg = <0x1c000 0x1000>; >> interrupts = <48 0x2>; >> interrupt-parent = <&mpic>; >> + clock-frequency = <0x0bebc1fc>; > > Does the device tree support dec coded integers? IMHO a frequency is > best expressed in decimal. Yes it does, and agree that in the example a dec # might be better - k
diff --git a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt index c78dcbb..a4382c7 100644 --- a/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt +++ b/Documentation/devicetree/bindings/net/can/fsl-flexcan.txt @@ -11,6 +11,7 @@ Required properties: - reg : Offset and length of the register set for this device - interrupts : Interrupt tuple for this device +- clock-frequency : The oscillator frequency driving the flexcan device Example: @@ -19,4 +20,5 @@ Example: reg = <0x1c000 0x1000>; interrupts = <48 0x2>; interrupt-parent = <&mpic>; + clock-frequency = <0x0bebc1fc>; }; diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index 662f832..d40c38e 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -33,6 +33,7 @@ #include <linux/kernel.h> #include <linux/list.h> #include <linux/module.h> +#include <linux/of.h> #include <linux/platform_device.h> #define DRV_NAME "flexcan" @@ -929,12 +930,26 @@ static int __devinit flexcan_probe(struct platform_device *pdev) void __iomem *base; resource_size_t mem_size; int err, irq; + u32 clock_freq = 0; - clk = clk_get(&pdev->dev, NULL); - if (IS_ERR(clk)) { - dev_err(&pdev->dev, "no clock defined\n"); - err = PTR_ERR(clk); - goto failed_clock; + if (pdev->dev.of_node) { + const u32 *clock_freq_p; + + clk = NULL; + clock_freq_p = of_get_property(pdev->dev.of_node, + "clock-frequency", NULL); + if (clock_freq_p) + clock_freq = *clock_freq_p; + } + + if (!clock_freq) { + clk = clk_get(&pdev->dev, NULL); + if (IS_ERR(clk)) { + dev_err(&pdev->dev, "no clock defined\n"); + err = PTR_ERR(clk); + goto failed_clock; + } + clock_freq = clk_get_rate(clk); } mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -967,7 +982,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev) dev->flags |= IFF_ECHO; /* we support local echo in hardware */ priv = netdev_priv(dev); - priv->can.clock.freq = clk_get_rate(clk); + priv->can.clock.freq = clock_freq; priv->can.bittiming_const = &flexcan_bittiming_const; priv->can.do_set_mode = flexcan_set_mode; priv->can.do_get_berr_counter = flexcan_get_berr_counter; @@ -1002,7 +1017,8 @@ static int __devinit flexcan_probe(struct platform_device *pdev) failed_map: release_mem_region(mem->start, mem_size); failed_get: - clk_put(clk); + if (clk) + clk_put(clk); failed_clock: return err; } @@ -1020,7 +1036,8 @@ static int __devexit flexcan_remove(struct platform_device *pdev) mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); release_mem_region(mem->start, resource_size(mem)); - clk_put(priv->clk); + if (priv->clk) + clk_put(priv->clk); free_candev(dev);
If our CAN device's device tree node has a clock-frequency property, then use that value for the can devices clock frequency. If not, fall back to asking the platform/mach code for the clock frequency associated with the flexcan device. Signed-off-by: Robin Holt <holt@sgi.com> To: Kumar Gala <galak@kernel.crashing.org> To: Wolfgang Grandegger <wg@grandegger.com>, To: Marc Kleine-Budde <mkl@pengutronix.de>, To: U Bhaskar-B22300 <B22300@freescale.com> To: Scott Wood <scottwood@freescale.com> To: Grant Likely <grant.likely@secretlab.ca> Cc: socketcan-core@lists.berlios.de, Cc: netdev@vger.kernel.org, Cc: PPC list <linuxppc-dev@lists.ozlabs.org> Cc: devicetree-discuss@lists.ozlabs.org --- .../devicetree/bindings/net/can/fsl-flexcan.txt | 2 + drivers/net/can/flexcan.c | 33 +++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-)