netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Jeroen Hofstee <jhofstee@victronenergy.com>,
	"linux-can@vger.kernel.org" <linux-can@vger.kernel.org>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
	"David S. Miller" <davem@davemloft.net>,
	"open list:NETWORKING DRIVERS" <netdev@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] can: D_CAN: perform a sofware reset on open
Date: Tue, 1 Oct 2019 16:32:03 +0200	[thread overview]
Message-ID: <b30e9834-a324-ad97-2050-df9600a95347@pengutronix.de> (raw)
In-Reply-To: <20190926085005.24805-2-jhofstee@victronenergy.com>


[-- Attachment #1.1: Type: text/plain, Size: 2484 bytes --]

On 9/26/19 10:50 AM, Jeroen Hofstee wrote:
> When the C_CAN interface is closed it is put in power down mode, but
> does not reset the error counters / state. So reset the D_CAN on open,
> so the reported state and the actual state match.
> 
> According to [1], the C_CAN module doesn't have the software reset.
> 
> [1] http://www.bosch-semiconductors.com/media/ip_modules/pdf_2/c_can_fd8/users_manual_c_can_fd8_r210_1.pdf
> 
> Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com>
> ---
>  drivers/net/can/c_can/c_can.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
> index 606b7d8ffe13..502a181d02e7 100644
> --- a/drivers/net/can/c_can/c_can.c
> +++ b/drivers/net/can/c_can/c_can.c
> @@ -52,6 +52,7 @@
>  #define CONTROL_EX_PDR		BIT(8)
>  
>  /* control register */
> +#define CONTROL_SWR		BIT(15)
>  #define CONTROL_TEST		BIT(7)
>  #define CONTROL_CCE		BIT(6)
>  #define CONTROL_DISABLE_AR	BIT(5)
> @@ -569,6 +570,26 @@ static void c_can_configure_msg_objects(struct net_device *dev)
>  				   IF_MCONT_RCV_EOB);
>  }
>  
> +static int software_reset(struct net_device *dev)

Please add the common prefix "c_can_" to the function

> +{
> +	struct c_can_priv *priv = netdev_priv(dev);
> +	int retry = 0;
> +
> +	if (priv->type != BOSCH_D_CAN)
> +		return 0;
> +
> +	priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_SWR | CONTROL_INIT);
> +	while (priv->read_reg(priv, C_CAN_CTRL_REG) & CONTROL_SWR) {
> +		msleep(20);
> +		if (retry++ > 100) {
> +			netdev_err(dev, "CCTRL: software reset failed\n");
> +			return -EIO;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>  /*
>   * Configure C_CAN chip:
>   * - enable/disable auto-retransmission
> @@ -578,6 +599,11 @@ static void c_can_configure_msg_objects(struct net_device *dev)
>  static int c_can_chip_config(struct net_device *dev)
>  {
>  	struct c_can_priv *priv = netdev_priv(dev);
> +	int err;
> +
> +	err = software_reset(dev);
> +	if (err)
> +		return err;
>  
>  	/* enable automatic retransmission */
>  	priv->write_reg(priv, C_CAN_CTRL_REG, CONTROL_ENABLE_AR);
> 

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

  parent reply	other threads:[~2019-10-01 14:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190926085005.24805-1-jhofstee@victronenergy.com>
2019-09-26  8:50 ` [PATCH 1/2] can: D_CAN: perform a sofware reset on open Jeroen Hofstee
2019-10-01 13:39   ` Kurt Van Dijck
2019-10-01 14:32   ` Marc Kleine-Budde [this message]
2019-10-01 21:17     ` Jeroen Hofstee
2019-09-26  8:50 ` [PATCH 2/2] can: C_CAN: add bus recovery events Jeroen Hofstee
2019-10-01  7:40   ` Kurt Van Dijck
2019-10-01 13:37     ` Kurt Van Dijck

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=b30e9834-a324-ad97-2050-df9600a95347@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=jhofstee@victronenergy.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --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).