linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Matthias Klein <matthias.klein@optimeas.de>,
	wg@grandegger.com, linux-can@vger.kernel.org,
	support@karo-electronics.de
Cc: bigeasy@linutronix.de
Subject: Re: [PATCH V2 4/5] can: flexcan: fix transition from and to freeze mode in chip_{,un}freeze
Date: Mon, 28 Jul 2014 08:38:28 +0200	[thread overview]
Message-ID: <53D5EFE4.8060308@pengutronix.de> (raw)
In-Reply-To: <1406529268-20126-4-git-send-email-matthias.klein@optimeas.de>

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

On 07/28/2014 08:34 AM, Matthias Klein wrote:
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> 
> This patch factors out freeze and unfreeze of the CAN core into seperate
> functions. Experiments have shown that the transition from and to freeze mode
> may take several microseconds, especially the time entering the freeze mode
> depends on the current bitrate.
> 
> This patch adds a while loop which polls the Freeze Mode ACK bit (FRZ_ACK) that
> indicates a successfull mode change. If the function runs into a timeout a
> error value is returned.
> 
> Cc: linux-stable <stable@vger.kernel.org>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Matthias Klein <matthias.klein@optimeas.de>

This patch is already mainline, please make your series based on the
latest net-next/master tree.

Marc

> ---
>  drivers/net/can/flexcan.c | 60 ++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 49 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
> index f6f95ae..b77f1da 100644
> --- a/drivers/net/can/flexcan.c
> +++ b/drivers/net/can/flexcan.c
> @@ -322,6 +322,44 @@ static int flexcan_chip_disable(struct flexcan_priv *priv)
>  	return 0;
>  }
>  
> +static int flexcan_chip_freeze(struct flexcan_priv *priv)
> +{
> +	struct flexcan_regs __iomem *regs = priv->base;
> +	unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
> +	u32 reg;
> +
> +	reg = flexcan_read(&regs->mcr);
> +	reg |= FLEXCAN_MCR_HALT;
> +	flexcan_write(reg, &regs->mcr);
> +
> +	while (timeout-- && !(flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
> +		usleep_range(100, 200);
> +
> +	if (!(flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
> +		return -ETIMEDOUT;
> +
> +	return 0;
> +}
> +
> +static int flexcan_chip_unfreeze(struct flexcan_priv *priv)
> +{
> +	struct flexcan_regs __iomem *regs = priv->base;
> +	unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
> +	u32 reg;
> +
> +	reg = flexcan_read(&regs->mcr);
> +	reg &= ~FLEXCAN_MCR_HALT;
> +	flexcan_write(reg, &regs->mcr);
> +
> +	while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
> +		usleep_range(10, 20);
> +
> +	if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK)
> +		return -ETIMEDOUT;
> +
> +	return 0;
> +}
> +
>  static int flexcan_get_berr_counter(const struct net_device *dev,
>  				    struct can_berr_counter *bec)
>  {
> @@ -776,7 +814,7 @@ static int flexcan_chip_start(struct net_device *dev)
>  		netdev_err(dev, "Failed to softreset can module (mcr=0x%08x)\n",
>  			   reg_mcr);
>  		err = -ENODEV;
> -		goto out;
> +		goto out_chip_disable;
>  	}
>  
>  	flexcan_set_bittiming(dev);
> @@ -846,12 +884,12 @@ static int flexcan_chip_start(struct net_device *dev)
>  
>  	err = flexcan_transceiver_enable(priv);
>  	if (err)
> -		goto out;
> +		goto out_chip_disable;
>  
>  	/* synchronize with the can bus */
> -	reg_mcr = flexcan_read(&regs->mcr);
> -	reg_mcr &= ~FLEXCAN_MCR_HALT;
> -	flexcan_write(reg_mcr, &regs->mcr);
> +	err = flexcan_chip_unfreeze(priv);
> +	if (err)
> +		goto out_transceiver_disable;
>  
>  	priv->can.state = CAN_STATE_ERROR_ACTIVE;
>  
> @@ -864,7 +902,9 @@ static int flexcan_chip_start(struct net_device *dev)
>  
>  	return 0;
>  
> - out:
> + out_transceiver_disable:
> +	flexcan_transceiver_disable(priv);
> + out_chip_disable:
>  	flexcan_chip_disable(priv);
>  	return err;
>  }
> @@ -879,12 +919,10 @@ static void flexcan_chip_stop(struct net_device *dev)
>  {
>  	struct flexcan_priv *priv = netdev_priv(dev);
>  	struct flexcan_regs __iomem *regs = priv->base;
> -	u32 reg;
>  
> -	/* Disable + halt module */
> -	reg = flexcan_read(&regs->mcr);
> -	reg |= FLEXCAN_MCR_MDIS | FLEXCAN_MCR_HALT;
> -	flexcan_write(reg, &regs->mcr);
> +	/* freeze + disable module */
> +	flexcan_chip_freeze(priv);
> +	flexcan_chip_disable(priv);
>  
>  	/* Disable all interrupts */
>  	flexcan_write(0, &regs->imask1);
> 


-- 
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: 242 bytes --]

  reply	other threads:[~2014-07-28  6:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-28  6:34 [PATCH V2 1/5] net: can: flexcan: provide propper return code in ISR Matthias Klein
2014-07-28  6:34 ` [PATCH V2 2/5] net: can: flexcan: disable error interrupts in non ERR-Active state Matthias Klein
2014-07-28  6:40   ` Varka Bhadram
2014-07-28  6:34 ` [PATCH V2 3/5] net: can: flexcan: handle state passive -> warning transition Matthias Klein
2014-07-28  6:34 ` [PATCH V2 4/5] can: flexcan: fix transition from and to freeze mode in chip_{,un}freeze Matthias Klein
2014-07-28  6:38   ` Marc Kleine-Budde [this message]
2014-07-28  6:34 ` [PATCH V2 5/5] net: can: flexcan: fix for wrong TX error count behaviour on i.MX53 Matthias Klein
2014-07-28  6:39   ` Varka Bhadram
2014-07-28  7:05   ` Marc Kleine-Budde
2014-07-28  7:08     ` Sebastian Andrzej Siewior
2014-07-28  6:36 ` [PATCH V2 1/5] net: can: flexcan: provide propper return code in ISR Varka Bhadram

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=53D5EFE4.8060308@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=matthias.klein@optimeas.de \
    --cc=support@karo-electronics.de \
    --cc=wg@grandegger.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).