Skip to content

Commit d79ee9a

Browse files
Merge branch 'can-peak_usb-cleanups-and-updates'
Stephane Grosjean contributes a peak-usb cleanup and update series. Signed-off-by: Marc Kleine-Budde <[email protected]>
2 parents 9e7c9b8 + 4f23248 commit d79ee9a

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

drivers/net/can/usb/peak_usb/pcan_usb_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ MODULE_DEVICE_TABLE(usb, peak_usb_table);
5757
* dump memory
5858
*/
5959
#define DUMP_WIDTH 16
60-
void pcan_dump_mem(char *prompt, void *p, int l)
60+
void pcan_dump_mem(const char *prompt, const void *p, int l)
6161
{
6262
pr_info("%s dumping %s (%d bytes):\n",
6363
PCAN_USB_DRIVER_NAME, prompt ? prompt : "memory", l);

drivers/net/can/usb/peak_usb/pcan_usb_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct peak_usb_device {
132132
struct peak_usb_device *next_siblings;
133133
};
134134

135-
void pcan_dump_mem(char *prompt, void *p, int l);
135+
void pcan_dump_mem(const char *prompt, const void *p, int l);
136136

137137
/* common timestamp management */
138138
void peak_usb_init_time_ref(struct peak_time_ref *time_ref,

drivers/net/can/usb/peak_usb/pcan_usb_fd.c

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#define PCAN_UFD_RX_BUFFER_SIZE 2048
3434
#define PCAN_UFD_TX_BUFFER_SIZE 512
3535

36+
/* struct pcan_ufd_fw_info::type */
37+
#define PCAN_USBFD_TYPE_STD 1
38+
#define PCAN_USBFD_TYPE_EXT 2 /* includes EP numbers */
39+
3640
/* read some versions info from the hw device */
3741
struct __packed pcan_ufd_fw_info {
3842
__le16 size_of; /* sizeof this */
@@ -44,6 +48,13 @@ struct __packed pcan_ufd_fw_info {
4448
__le32 dev_id[2]; /* "device id" per CAN */
4549
__le32 ser_no; /* S/N */
4650
__le32 flags; /* special functions */
51+
52+
/* extended data when type == PCAN_USBFD_TYPE_EXT */
53+
u8 cmd_out_ep; /* ep for cmd */
54+
u8 cmd_in_ep; /* ep for replies */
55+
u8 data_out_ep[2]; /* ep for CANx TX */
56+
u8 data_in_ep; /* ep for CAN RX */
57+
u8 dummy[3];
4758
};
4859

4960
/* handle device specific info used by the netdevices */
@@ -171,6 +182,9 @@ static inline void *pcan_usb_fd_cmd_buffer(struct peak_usb_device *dev)
171182
/* send PCAN-USB Pro FD commands synchronously */
172183
static int pcan_usb_fd_send_cmd(struct peak_usb_device *dev, void *cmd_tail)
173184
{
185+
struct pcan_usb_fd_device *pdev =
186+
container_of(dev, struct pcan_usb_fd_device, dev);
187+
struct pcan_ufd_fw_info *fw_info = &pdev->usb_if->fw_info;
174188
void *cmd_head = pcan_usb_fd_cmd_buffer(dev);
175189
int err = 0;
176190
u8 *packet_ptr;
@@ -200,7 +214,7 @@ static int pcan_usb_fd_send_cmd(struct peak_usb_device *dev, void *cmd_tail)
200214
do {
201215
err = usb_bulk_msg(dev->udev,
202216
usb_sndbulkpipe(dev->udev,
203-
PCAN_USBPRO_EP_CMDOUT),
217+
fw_info->cmd_out_ep),
204218
packet_ptr, packet_len,
205219
NULL, PCAN_UFD_CMD_TIMEOUT_MS);
206220
if (err) {
@@ -426,6 +440,9 @@ static int pcan_usb_fd_set_bittiming_fast(struct peak_usb_device *dev,
426440
static int pcan_usb_fd_restart_async(struct peak_usb_device *dev,
427441
struct urb *urb, u8 *buf)
428442
{
443+
struct pcan_usb_fd_device *pdev =
444+
container_of(dev, struct pcan_usb_fd_device, dev);
445+
struct pcan_ufd_fw_info *fw_info = &pdev->usb_if->fw_info;
429446
u8 *pc = buf;
430447

431448
/* build the entire cmds list in the provided buffer, to go back into
@@ -439,7 +456,7 @@ static int pcan_usb_fd_restart_async(struct peak_usb_device *dev,
439456

440457
/* complete the URB */
441458
usb_fill_bulk_urb(urb, dev->udev,
442-
usb_sndbulkpipe(dev->udev, PCAN_USBPRO_EP_CMDOUT),
459+
usb_sndbulkpipe(dev->udev, fw_info->cmd_out_ep),
443460
buf, pc - buf,
444461
pcan_usb_pro_restart_complete, dev);
445462

@@ -839,6 +856,15 @@ static int pcan_usb_fd_get_berr_counter(const struct net_device *netdev,
839856
return 0;
840857
}
841858

859+
/* probe function for all PCAN-USB FD family usb interfaces */
860+
static int pcan_usb_fd_probe(struct usb_interface *intf)
861+
{
862+
struct usb_host_interface *iface_desc = &intf->altsetting[0];
863+
864+
/* CAN interface is always interface #0 */
865+
return iface_desc->desc.bInterfaceNumber;
866+
}
867+
842868
/* stop interface (last chance before set bus off) */
843869
static int pcan_usb_fd_stop(struct peak_usb_device *dev)
844870
{
@@ -860,6 +886,7 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
860886
{
861887
struct pcan_usb_fd_device *pdev =
862888
container_of(dev, struct pcan_usb_fd_device, dev);
889+
struct pcan_ufd_fw_info *fw_info;
863890
int i, err = -ENOMEM;
864891

865892
/* do this for 1st channel only */
@@ -878,10 +905,12 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
878905
/* number of ts msgs to ignore before taking one into account */
879906
pdev->usb_if->cm_ignore_count = 5;
880907

908+
fw_info = &pdev->usb_if->fw_info;
909+
881910
err = pcan_usb_pro_send_req(dev, PCAN_USBPRO_REQ_INFO,
882911
PCAN_USBPRO_INFO_FW,
883-
&pdev->usb_if->fw_info,
884-
sizeof(pdev->usb_if->fw_info));
912+
fw_info,
913+
sizeof(*fw_info));
885914
if (err) {
886915
dev_err(dev->netdev->dev.parent,
887916
"unable to read %s firmware info (err %d)\n",
@@ -895,21 +924,29 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
895924
*/
896925
dev_info(dev->netdev->dev.parent,
897926
"PEAK-System %s v%u fw v%u.%u.%u (%u channels)\n",
898-
dev->adapter->name, pdev->usb_if->fw_info.hw_version,
899-
pdev->usb_if->fw_info.fw_version[0],
900-
pdev->usb_if->fw_info.fw_version[1],
901-
pdev->usb_if->fw_info.fw_version[2],
927+
dev->adapter->name, fw_info->hw_version,
928+
fw_info->fw_version[0],
929+
fw_info->fw_version[1],
930+
fw_info->fw_version[2],
902931
dev->adapter->ctrl_count);
903932

904933
/* check for ability to switch between ISO/non-ISO modes */
905-
if (pdev->usb_if->fw_info.fw_version[0] >= 2) {
934+
if (fw_info->fw_version[0] >= 2) {
906935
/* firmware >= 2.x supports ISO/non-ISO switching */
907936
dev->can.ctrlmode_supported |= CAN_CTRLMODE_FD_NON_ISO;
908937
} else {
909938
/* firmware < 2.x only supports fixed(!) non-ISO */
910939
dev->can.ctrlmode |= CAN_CTRLMODE_FD_NON_ISO;
911940
}
912941

942+
/* if vendor rsp is of type 2, then it contains EP numbers to
943+
* use for cmds pipes. If not, then default EP should be used.
944+
*/
945+
if (fw_info->type != cpu_to_le16(PCAN_USBFD_TYPE_EXT)) {
946+
fw_info->cmd_out_ep = PCAN_USBPRO_EP_CMDOUT;
947+
fw_info->cmd_in_ep = PCAN_USBPRO_EP_CMDIN;
948+
}
949+
913950
/* tell the hardware the can driver is running */
914951
err = pcan_usb_fd_drv_loaded(dev, 1);
915952
if (err) {
@@ -930,12 +967,23 @@ static int pcan_usb_fd_init(struct peak_usb_device *dev)
930967
/* do a copy of the ctrlmode[_supported] too */
931968
dev->can.ctrlmode = ppdev->dev.can.ctrlmode;
932969
dev->can.ctrlmode_supported = ppdev->dev.can.ctrlmode_supported;
970+
971+
fw_info = &pdev->usb_if->fw_info;
933972
}
934973

935974
pdev->usb_if->dev[dev->ctrl_idx] = dev;
936975
dev->device_number =
937976
le32_to_cpu(pdev->usb_if->fw_info.dev_id[dev->ctrl_idx]);
938977

978+
/* if vendor rsp is of type 2, then it contains EP numbers to
979+
* use for data pipes. If not, then statically defined EP are used
980+
* (see peak_usb_create_dev()).
981+
*/
982+
if (fw_info->type == cpu_to_le16(PCAN_USBFD_TYPE_EXT)) {
983+
dev->ep_msg_in = fw_info->data_in_ep;
984+
dev->ep_msg_out = fw_info->data_out_ep[dev->ctrl_idx];
985+
}
986+
939987
/* set clock domain */
940988
for (i = 0; i < ARRAY_SIZE(pcan_usb_fd_clk_freq); i++)
941989
if (dev->adapter->clock.freq == pcan_usb_fd_clk_freq[i])
@@ -1091,7 +1139,7 @@ const struct peak_usb_adapter pcan_usb_fd = {
10911139
.tx_buffer_size = PCAN_UFD_TX_BUFFER_SIZE,
10921140

10931141
/* device callbacks */
1094-
.intf_probe = pcan_usb_pro_probe, /* same as PCAN-USB Pro */
1142+
.intf_probe = pcan_usb_fd_probe,
10951143
.dev_init = pcan_usb_fd_init,
10961144

10971145
.dev_exit = pcan_usb_fd_exit,

drivers/net/can/usb/peak_usb/pcan_usb_pro.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ static int pcan_usb_pro_get_device_id(struct peak_usb_device *dev,
439439
return err;
440440

441441
pdn = (struct pcan_usb_pro_devid *)pc;
442-
*device_id = le32_to_cpu(pdn->serial_num);
442+
*device_id = le32_to_cpu(pdn->dev_num);
443443

444444
return err;
445445
}

drivers/net/can/usb/peak_usb/pcan_usb_pro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct __packed pcan_usb_pro_devid {
112112
u8 data_type;
113113
u8 channel;
114114
__le16 dummy;
115-
__le32 serial_num;
115+
__le32 dev_num;
116116
};
117117

118118
#define PCAN_USBPRO_LED_DEVICE 0x00

0 commit comments

Comments
 (0)