linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Alexander Stein <alexander.stein@systec-electronic.com>,
	Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-can@vger.kernel.org
Subject: Re: [PATCH 4/5] can: slcan: Add bitrate change support
Date: Thu, 17 Apr 2014 21:13:20 +0200	[thread overview]
Message-ID: <535027D0.5000608@pengutronix.de> (raw)
In-Reply-To: <1397573468-7619-5-git-send-email-alexander.stein@systec-electronic.com>

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

On 04/15/2014 04:51 PM, Alexander Stein wrote:
> Only a fixed set of bitrates are supported.
> 
> Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
> ---
>  drivers/net/can/Kconfig |  5 +++--
>  drivers/net/can/slcan.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 56 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
> index daea043..267aec2 100644
> --- a/drivers/net/can/Kconfig
> +++ b/drivers/net/can/Kconfig
> @@ -113,8 +113,9 @@ config CAN_SLCAN
>  	  via serial lines or via USB-to-serial adapters using the LAWICEL
>  	  ASCII protocol. The driver implements the tty linediscipline N_SLCAN.
>  
> -	  As only the sending and receiving of CAN frames is implemented, this
> -	  driver should work with the (serial/USB) CAN hardware from:
> +	  Sending, receiving of CAN frames as well as bitrate setting is
> +	  implemented, this driver should work with the
> +	  (serial/USB) CAN hardware from:
>  	  www.canusb.com / www.can232.com / www.mictronics.de / www.canhack.de
>  
>  	  Userspace tools to attach the SLCAN line discipline (slcan_attach,
> diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
> index 8a578bb..8d98f50 100644
> --- a/drivers/net/can/slcan.c
> +++ b/drivers/net/can/slcan.c
> @@ -454,6 +454,58 @@ static int slc_open(struct net_device *dev)
>  	return 0;
>  }
>  
> +static int slc_set_bittiming(struct net_device *dev)
> +{
> +	struct slcan *sl = netdev_priv(dev);
> +	const struct can_bittiming *bt = &sl->can.bittiming;
> +	int index, written, len;
> +	char buf[4];
> +
> +	switch (bt->bitrate) {
> +	case 1000000:
> +		index = 8;
> +		break;
> +	case 800000:
> +		index = 7;
> +		break;
> +	case 500000:
> +		index = 6;
> +		break;
> +	case 250000:
> +		index = 5;
> +		break;
> +	case 125000:
> +		index = 4;
> +		break;
> +	case 100000:
> +		index = 3;
> +		break;
> +	case 50000:
> +		index = 2;
> +		break;
> +	case 20000:
> +		index = 1;
> +		break;
> +	case 10000:
> +		index = 0;
> +		break;
> +	default:
> +		return -EINVAL;
> +	};
> +
> +	if (!sl->tty)
> +		return -ENOENT;
> +
> +	len = snprintf(buf, sizeof(buf), "S%d\r", index);
> +	written = sl->tty->ops->write(sl->tty, buf, len);
> +	if (written != len) {
> +		netdev_warn(sl->dev, "Setting bitrate command could not be sent!\n");
> +		return -EIO;
> +	}
> +
> +	return 0;
> +}
> +
>  /* Hook the destructor so we can free slcan devs at the right point in time */
>  static void slc_free_netdev(struct net_device *dev)
>  {
> @@ -613,6 +665,7 @@ static int slcan_open(struct tty_struct *tty)
>  		sl->rcount   = 0;
>  		sl->xleft    = 0;
>  
> +		sl->can.do_set_bittiming = slc_set_bittiming;

Can you move the slc_set_bittiming into the open function? Then you
don't need to assign this callback.

>  		set_bit(SLF_INUSE, &sl->flags);
>  
>  		err = register_candev(sl->dev);
> 

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

  reply	other threads:[~2014-04-17 19:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-15 14:51 Bitrate and CAN status support for slcan Alexander Stein
2014-04-15 14:51 ` [PATCH 1/5] can: slcan: Fix spinlock variant Alexander Stein
2014-04-22 19:58   ` Oliver Hartkopp
2014-04-24 20:32   ` Marc Kleine-Budde
2014-04-15 14:51 ` [PATCH 2/5] can: slcan: Convert to can_dev interface Alexander Stein
2014-04-17 19:10   ` Marc Kleine-Budde
2014-04-15 14:51 ` [PATCH 3/5] can: slcan: Send open/close command upon interface up/down Alexander Stein
2014-04-15 14:51 ` [PATCH 4/5] can: slcan: Add bitrate change support Alexander Stein
2014-04-17 19:13   ` Marc Kleine-Budde [this message]
2014-04-15 14:51 ` [PATCH 5/5] can: slcan: Add CAN status flag support Alexander Stein
2014-04-17 19:22   ` Marc Kleine-Budde
2014-04-19 20:38   ` Oliver Hartkopp
2014-04-19 19:24 ` Bitrate and CAN status support for slcan Oliver Hartkopp
2014-04-22  7:08   ` Alexander Stein
2014-04-22 19:50     ` Oliver Hartkopp

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=535027D0.5000608@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=alexander.stein@systec-electronic.com \
    --cc=linux-can@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).