From: Marc Kleine-Budde <mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public•gmane.org>
To: Robin Holt <holt-sJ/iWh9BUns@public•gmane.org>
Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w@public•gmane.org,
netdev-u79uwXL29TY76Z2rM5mHXA@public•gmane.org,
Wolfgang Grandegger <wg-5Yr1BZd7O62+XT7JhA+gdA@public•gmane.org>
Subject: Re: [RFC 2/4] [flexcan] Introduce a flexcan_clk set of functions.
Date: Fri, 05 Aug 2011 10:34:11 +0200 [thread overview]
Message-ID: <4E3BAB03.4040803@pengutronix.de> (raw)
In-Reply-To: <1312509979-13226-3-git-send-email-holt-sJ/iWh9BUns@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 6442 bytes --]
On 08/05/2011 04:06 AM, Robin Holt wrote:
> The freescale P1010RDB board does not have a
> clk_{get,put,get_rate,enable,disable} set of functions. Wrap these with a
> flexcan_ #define for arm, and implement a more complete function for ppc.
Some codingstyle nitpicks inline. I hope we'll find a cleaner solution
than this patch.
Marc
> Signed-off-by: Robin Holt <holt-sJ/iWh9BUns@public•gmane.org>
> To: Marc Kleine-Budde <mkl-bIcnvbaLZ9MEGnE8C9+IrQ@public•gmane.org>
> To: Wolfgang Grandegger <wg-5Yr1BZd7O62+XT7JhA+gdA@public•gmane.org>
> Cc: socketcan-core-0fE9KPoRgkgATYTw5x5z8w@public•gmane.org
> Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public•gmane.org
> ---
> drivers/net/can/flexcan.c | 114 +++++++++++++++++++++++++++++++++++++++++----
> 1 files changed, 105 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
> index 74b1706..3417d0b 100644
> --- a/drivers/net/can/flexcan.c
> +++ b/drivers/net/can/flexcan.c
> @@ -220,6 +220,102 @@ static inline void flexcan_write(u32 val, void __iomem *addr)
> }
> #endif
>
> +#if defined(__powerpc__)
> +struct flexcan_clk {
> + unsigned long rate;
> + void *data;
> +};
> +
> +static struct clk *flexcan_clk_get(struct device *dev, const char *id)
> +{
> + struct flexcan_clk *clock;
> + u32 *clock_freq;
> + u32 *clock_divider;
> + int err;
> +
> + clock = kmalloc(sizeof(struct flexcan_clk), GFP_KERNEL);
> + if (!clock) {
> + dev_err(dev, "Cannot allocate memory\n");
> + err = -ENOMEM;
> + goto failed_clock;
> + }
> + clock_freq = (u32 *)of_get_property(dev->of_node, "clock_freq", NULL);
> + if (!clock_freq) {
> + dev_err(dev, "Cannot find clock_freq property\n");
> + err = -EINVAL;
> + goto failed_clock;
> + }
> +
> + clock_divider = (u32 *) of_get_property(dev->of_node,
^
remove this space, please
> + "fsl,flexcan-clock-divider", NULL);
> + if (clock_divider == NULL) {
!clock_divider
> + dev_err(dev, "Cannot find fsl,flexcan-clock-divider property\n");
> + err = -EINVAL;
> + goto failed_clock;
> + }
> +
> + clock->rate = DIV_ROUND_CLOSEST(*clock_freq / *clock_divider, 1000);
> + clock->rate *= 1000;
> +
> + return (struct clk *)clock;
> +
> + failed_clock:
> + kfree(clock);
> + return ERR_PTR(err);
> +}
> +
> +static inline void flexcan_clk_put(struct clk *_clk)
> +{
> + struct flexcan_clk *clk = (struct flexcan_clk *)_clk;
that cast is not needed.
> +
> + kfree(clk);
> +}
> +
> +static inline int flexcan_clk_enable(struct clk *clk)
> +{
> + return 0;
> +}
> +
> +static inline void flexcan_clk_disable(struct clk *clk)
> +{
> + return;
> +}
> +
> +static inline unsigned long flexcan_clk_get_rate(struct clk *_clk)
> +{
> + struct flexcan_clk *clk = (struct flexcan_clk *)_clk;
> +
> + return clk->rate;
> +}
> +
> +#else
> +static inline struct clk *flexcan_clk_get(struct device *dev, const char *id)
> +{
> + return clk_get(dev, id);
> +}
> +
> +static inline void flexcan_clk_put(struct clk *clk)
> +{
> + clk_put(clk);
> +}
> +
> +static inline int flexcan_clk_enable(struct clk *clk)
> +{
> + return clk_enable(clk);
> +}
> +
> +static inline void flexcan_clk_disable(struct clk *clk)
> +{
> + clk_disable(clk);
> +}
> +
> +static inline unsigned long flexcan_clk_get_rate(struct clk *clk)
> +{
> + return clk_get_rate(clk);
> +}
> +
> +#endif
> +
> /*
> * Swtich transceiver on or off
> */
> @@ -807,7 +903,7 @@ static int flexcan_open(struct net_device *dev)
> struct flexcan_priv *priv = netdev_priv(dev);
> int err;
>
> - clk_enable(priv->clk);
> + flexcan_clk_enable(priv->clk);
>
> err = open_candev(dev);
> if (err)
> @@ -829,7 +925,7 @@ static int flexcan_open(struct net_device *dev)
> out_close:
> close_candev(dev);
> out:
> - clk_disable(priv->clk);
> + flexcan_clk_disable(priv->clk);
>
> return err;
> }
> @@ -843,7 +939,7 @@ static int flexcan_close(struct net_device *dev)
> flexcan_chip_stop(dev);
>
> free_irq(dev->irq, dev);
> - clk_disable(priv->clk);
> + flexcan_clk_disable(priv->clk);
>
> close_candev(dev);
>
> @@ -882,7 +978,7 @@ static int __devinit register_flexcandev(struct net_device *dev)
> struct flexcan_regs __iomem *regs = priv->base;
> u32 reg, err;
>
> - clk_enable(priv->clk);
> + flexcan_clk_enable(priv->clk);
>
> /* select "bus clock", chip must be disabled */
> flexcan_chip_disable(priv);
> @@ -916,7 +1012,7 @@ static int __devinit register_flexcandev(struct net_device *dev)
> out:
> /* disable core and turn off clocks */
> flexcan_chip_disable(priv);
> - clk_disable(priv->clk);
> + flexcan_clk_disable(priv->clk);
>
> return err;
> }
> @@ -936,7 +1032,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
> resource_size_t mem_size;
> int err, irq;
>
> - clk = clk_get(&pdev->dev, NULL);
> + clk = flexcan_clk_get(&pdev->dev, NULL);
> if (IS_ERR(clk)) {
> dev_err(&pdev->dev, "no clock defined\n");
> err = PTR_ERR(clk);
> @@ -973,7 +1069,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 = flexcan_clk_get_rate(clk);
> 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;
> @@ -1008,7 +1104,7 @@ static int __devinit flexcan_probe(struct platform_device *pdev)
> failed_map:
> release_mem_region(mem->start, mem_size);
> failed_get:
> - clk_put(clk);
> + flexcan_clk_put(clk);
> failed_clock:
> return err;
> }
> @@ -1026,7 +1122,7 @@ 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);
> + flexcan_clk_put(priv->clk);
>
> free_candev(dev);
>
--
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 #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
[-- Attachment #2: Type: text/plain, Size: 188 bytes --]
_______________________________________________
Socketcan-core mailing list
Socketcan-core-0fE9KPoRgkgATYTw5x5z8w@public•gmane.org
https://lists.berlios.de/mailman/listinfo/socketcan-core
next prev parent reply other threads:[~2011-08-05 8:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-05 2:06 [RFC 0/4] [flexcan] Add support for powerpc (freescale p1010) -V4 Robin Holt
2011-08-05 2:06 ` [RFC 1/4] [flexcan] Abstract off read/write for big/little endian Robin Holt
[not found] ` <1312509979-13226-2-git-send-email-holt-sJ/iWh9BUns@public.gmane.org>
2011-08-05 8:32 ` Marc Kleine-Budde
2011-08-05 2:06 ` [RFC 2/4] [flexcan] Introduce a flexcan_clk set of functions Robin Holt
[not found] ` <1312509979-13226-3-git-send-email-holt-sJ/iWh9BUns@public.gmane.org>
2011-08-05 8:34 ` Marc Kleine-Budde [this message]
2011-08-05 11:36 ` Robin Holt
[not found] ` <20110805113638.GF4926-sJ/iWh9BUns@public.gmane.org>
2011-08-05 12:29 ` Marc Kleine-Budde
[not found] ` <4E3BE23A.5080706-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2011-08-05 12:44 ` Robin Holt
2011-08-05 2:06 ` [RFC 3/4] [flexcan] Add of_match to platform_device definition Robin Holt
[not found] ` <1312509979-13226-4-git-send-email-holt-sJ/iWh9BUns@public.gmane.org>
2011-08-05 7:13 ` Marc Kleine-Budde
2011-08-05 2:06 ` [RFC 4/4] [flexcan] Add support for FLEXCAN_DEBUG Robin Holt
[not found] ` <1312509979-13226-5-git-send-email-holt-sJ/iWh9BUns@public.gmane.org>
2011-08-05 7:16 ` Marc Kleine-Budde
[not found] ` <4E3B98B6.4040003-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2011-08-05 14:01 ` Robin Holt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E3BAB03.4040803@pengutronix.de \
--to=mkl-bicnvbalz9megne8c9+irq@public$(echo .)gmane.org \
--cc=holt-sJ/iWh9BUns@public$(echo .)gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public$(echo .)gmane.org \
--cc=socketcan-core-0fE9KPoRgkgATYTw5x5z8w@public$(echo .)gmane.org \
--cc=wg-5Yr1BZd7O62+XT7JhA+gdA@public$(echo .)gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox