Re: [PATCH] can: gs_usb: add switchable termination support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 18.09.2022 22:23:48, Marc Kleine-Budde wrote:
> The candleLight community is working on switchable termination support
> for the candleLight firmware. As the the Linux CAN framework supports
> switchable termination add this feature to the gs_usb driver.
> 
> Devices supporting the feature should set the
> GS_CAN_FEATURE_TERMINATION and implement the
> GS_USB_BREQ_SET_TERMINATION and GS_USB_BREQ_GET_TERMINATION control
> messages.
> 
> For now the driver assumes for activated termination the standard
> termination of 120Ω.
> 
> Link: https://github.com/candle-usb/candleLight_fw/issues/92
> Link: https://github.com/candle-usb/candleLight_fw/pull/108
> Cc: Daniel Trevitz <daniel.trevitz@xxxxxxxx>
> Cc: Ryan Edwards <ryan.edwards@xxxxxxxxx>
> Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>

[...]

> +static int gs_usb_get_termination(struct net_device *netdev, u16 *term)
> +{
> +	struct gs_can *dev = netdev_priv(netdev);
> +	struct gs_termination_state state;
> +	int rc;
> +
> +	rc = usb_control_msg_recv(interface_to_usbdev(dev->iface), 0,
> +				  GS_USB_BREQ_GET_TERMINATION,
> +				  USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
> +				  dev->channel, 0,
> +				  &state, sizeof(state), 1000,
> +				  GFP_KERNEL);
> +
> +	return rc;
> +}
> +
> +static int gs_usb_set_termination(struct net_device *netdev, u16 term)
> +{
> +	struct gs_can *dev = netdev_priv(netdev);
> +	struct gs_termination_state state;
> +	u16 actual_term;
> +	int rc;
> +
> +	if (term == GS_USB_TERMINATION_ENABLED)
> +		state.state = cpu_to_le32(GS_CAN_TERMINATION_STATE_ON);
> +	else
> +		state.state = cpu_to_le32(GS_CAN_TERMINATION_STATE_OFF);
> +
> +	rc = usb_control_msg_send(interface_to_usbdev(dev->iface), 0,
> +				  GS_USB_BREQ_SET_TERMINATION,
> +				  USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
> +				  dev->channel, 0,
> +				  &state, sizeof(state), 1000,
> +				  GFP_KERNEL);
> +
> +	if (rc)
> +		return rc;
> +
> +	rc = gs_usb_get_termination(netdev, &actual_term);

I'm not sure if we need this. The usb_control_msg_send() should only
return if the request succeeds.

I'll add a gs_usb_get_termination() call to the probe function, so that
the driver knows the termination state.

> +	if (rc)
> +		return rc;
> +
> +	if (term != actual_term)
> +		return -EIO;
> +
> +	return rc;
> +}
> +

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux