diff options
author | Matthias Fuchs <matthias.fuchs@esd.eu> | 2012-10-29 05:54:48 -0400 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2012-11-15 11:26:02 -0500 |
commit | 7653ebd5f6a4cd1976cb82e8ef94ebbe3ff001f3 (patch) | |
tree | 983c6a9e5abe9dec0414174766e73303094b7352 /drivers/net/can | |
parent | a5f8f0e1a57025287697df78ce5e6b7d6b2b07b0 (diff) |
can: usb: esd_usb2: Add support for CAN-USB/Micro
This patch extends the esd_usb2 driver to support the
tiny CAN-USB/Micro CAN/USB interface.
Signed-off-by: Matthias Fuchs <matthias.fuchs@esd.eu>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'drivers/net/can')
-rw-r--r-- | drivers/net/can/usb/esd_usb2.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c index f4317c0efed4..124e0dd3490c 100644 --- a/drivers/net/can/usb/esd_usb2.c +++ b/drivers/net/can/usb/esd_usb2.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * CAN driver for esd CAN-USB/2 | 2 | * CAN driver for esd CAN-USB/2 and CAN-USB/Micro |
3 | * | 3 | * |
4 | * Copyright (C) 2010 Matthias Fuchs <matthias.fuchs@esd.eu>, esd gmbh | 4 | * Copyright (C) 2010-2012 Matthias Fuchs <matthias.fuchs@esd.eu>, esd gmbh |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | 6 | * This program is free software; you can redistribute it and/or modify it |
7 | * under the terms of the GNU General Public License as published | 7 | * under the terms of the GNU General Public License as published |
@@ -28,14 +28,16 @@ | |||
28 | #include <linux/can/error.h> | 28 | #include <linux/can/error.h> |
29 | 29 | ||
30 | MODULE_AUTHOR("Matthias Fuchs <matthias.fuchs@esd.eu>"); | 30 | MODULE_AUTHOR("Matthias Fuchs <matthias.fuchs@esd.eu>"); |
31 | MODULE_DESCRIPTION("CAN driver for esd CAN-USB/2 interfaces"); | 31 | MODULE_DESCRIPTION("CAN driver for esd CAN-USB/2 and CAN-USB/Micro interfaces"); |
32 | MODULE_LICENSE("GPL v2"); | 32 | MODULE_LICENSE("GPL v2"); |
33 | 33 | ||
34 | /* Define these values to match your devices */ | 34 | /* Define these values to match your devices */ |
35 | #define USB_ESDGMBH_VENDOR_ID 0x0ab4 | 35 | #define USB_ESDGMBH_VENDOR_ID 0x0ab4 |
36 | #define USB_CANUSB2_PRODUCT_ID 0x0010 | 36 | #define USB_CANUSB2_PRODUCT_ID 0x0010 |
37 | #define USB_CANUSBM_PRODUCT_ID 0x0011 | ||
37 | 38 | ||
38 | #define ESD_USB2_CAN_CLOCK 60000000 | 39 | #define ESD_USB2_CAN_CLOCK 60000000 |
40 | #define ESD_USBM_CAN_CLOCK 36000000 | ||
39 | #define ESD_USB2_MAX_NETS 2 | 41 | #define ESD_USB2_MAX_NETS 2 |
40 | 42 | ||
41 | /* USB2 commands */ | 43 | /* USB2 commands */ |
@@ -69,6 +71,7 @@ MODULE_LICENSE("GPL v2"); | |||
69 | #define ESD_USB2_TSEG2_SHIFT 20 | 71 | #define ESD_USB2_TSEG2_SHIFT 20 |
70 | #define ESD_USB2_SJW_MAX 4 | 72 | #define ESD_USB2_SJW_MAX 4 |
71 | #define ESD_USB2_SJW_SHIFT 14 | 73 | #define ESD_USB2_SJW_SHIFT 14 |
74 | #define ESD_USBM_SJW_SHIFT 24 | ||
72 | #define ESD_USB2_BRP_MIN 1 | 75 | #define ESD_USB2_BRP_MIN 1 |
73 | #define ESD_USB2_BRP_MAX 1024 | 76 | #define ESD_USB2_BRP_MAX 1024 |
74 | #define ESD_USB2_BRP_INC 1 | 77 | #define ESD_USB2_BRP_INC 1 |
@@ -183,6 +186,7 @@ struct __attribute__ ((packed)) esd_usb2_msg { | |||
183 | 186 | ||
184 | static struct usb_device_id esd_usb2_table[] = { | 187 | static struct usb_device_id esd_usb2_table[] = { |
185 | {USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSB2_PRODUCT_ID)}, | 188 | {USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSB2_PRODUCT_ID)}, |
189 | {USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSBM_PRODUCT_ID)}, | ||
186 | {} | 190 | {} |
187 | }; | 191 | }; |
188 | MODULE_DEVICE_TABLE(usb, esd_usb2_table); | 192 | MODULE_DEVICE_TABLE(usb, esd_usb2_table); |
@@ -889,14 +893,22 @@ static int esd_usb2_set_bittiming(struct net_device *netdev) | |||
889 | struct can_bittiming *bt = &priv->can.bittiming; | 893 | struct can_bittiming *bt = &priv->can.bittiming; |
890 | struct esd_usb2_msg msg; | 894 | struct esd_usb2_msg msg; |
891 | u32 canbtr; | 895 | u32 canbtr; |
896 | int sjw_shift; | ||
892 | 897 | ||
893 | canbtr = ESD_USB2_UBR; | 898 | canbtr = ESD_USB2_UBR; |
894 | if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) | 899 | if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) |
895 | canbtr |= ESD_USB2_LOM; | 900 | canbtr |= ESD_USB2_LOM; |
896 | 901 | ||
897 | canbtr |= (bt->brp - 1) & (ESD_USB2_BRP_MAX - 1); | 902 | canbtr |= (bt->brp - 1) & (ESD_USB2_BRP_MAX - 1); |
903 | |||
904 | if (le16_to_cpu(priv->usb2->udev->descriptor.idProduct) == | ||
905 | USB_CANUSBM_PRODUCT_ID) | ||
906 | sjw_shift = ESD_USBM_SJW_SHIFT; | ||
907 | else | ||
908 | sjw_shift = ESD_USB2_SJW_SHIFT; | ||
909 | |||
898 | canbtr |= ((bt->sjw - 1) & (ESD_USB2_SJW_MAX - 1)) | 910 | canbtr |= ((bt->sjw - 1) & (ESD_USB2_SJW_MAX - 1)) |
899 | << ESD_USB2_SJW_SHIFT; | 911 | << sjw_shift; |
900 | canbtr |= ((bt->prop_seg + bt->phase_seg1 - 1) | 912 | canbtr |= ((bt->prop_seg + bt->phase_seg1 - 1) |
901 | & (ESD_USB2_TSEG1_MAX - 1)) | 913 | & (ESD_USB2_TSEG1_MAX - 1)) |
902 | << ESD_USB2_TSEG1_SHIFT; | 914 | << ESD_USB2_TSEG1_SHIFT; |
@@ -975,12 +987,19 @@ static int esd_usb2_probe_one_net(struct usb_interface *intf, int index) | |||
975 | 987 | ||
976 | priv->can.state = CAN_STATE_STOPPED; | 988 | priv->can.state = CAN_STATE_STOPPED; |
977 | priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY; | 989 | priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY; |
978 | priv->can.clock.freq = ESD_USB2_CAN_CLOCK; | 990 | |
991 | if (le16_to_cpu(dev->udev->descriptor.idProduct) == | ||
992 | USB_CANUSBM_PRODUCT_ID) | ||
993 | priv->can.clock.freq = ESD_USBM_CAN_CLOCK; | ||
994 | else { | ||
995 | priv->can.clock.freq = ESD_USB2_CAN_CLOCK; | ||
996 | priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES; | ||
997 | } | ||
998 | |||
979 | priv->can.bittiming_const = &esd_usb2_bittiming_const; | 999 | priv->can.bittiming_const = &esd_usb2_bittiming_const; |
980 | priv->can.do_set_bittiming = esd_usb2_set_bittiming; | 1000 | priv->can.do_set_bittiming = esd_usb2_set_bittiming; |
981 | priv->can.do_set_mode = esd_usb2_set_mode; | 1001 | priv->can.do_set_mode = esd_usb2_set_mode; |
982 | priv->can.do_get_berr_counter = esd_usb2_get_berr_counter; | 1002 | priv->can.do_get_berr_counter = esd_usb2_get_berr_counter; |
983 | priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES; | ||
984 | 1003 | ||
985 | netdev->flags |= IFF_ECHO; /* we support local echo */ | 1004 | netdev->flags |= IFF_ECHO; /* we support local echo */ |
986 | 1005 | ||