| .. | .. |
|---|
| 35 | 35 | #define KVASER_USB_RX_BUFFER_SIZE 3072 |
|---|
| 36 | 36 | #define KVASER_USB_MAX_NET_DEVICES 5 |
|---|
| 37 | 37 | |
|---|
| 38 | | -/* USB devices features */ |
|---|
| 39 | | -#define KVASER_USB_HAS_SILENT_MODE BIT(0) |
|---|
| 40 | | -#define KVASER_USB_HAS_TXRX_ERRORS BIT(1) |
|---|
| 38 | +/* Kvaser USB device quirks */ |
|---|
| 39 | +#define KVASER_USB_QUIRK_HAS_SILENT_MODE BIT(0) |
|---|
| 40 | +#define KVASER_USB_QUIRK_HAS_TXRX_ERRORS BIT(1) |
|---|
| 41 | +#define KVASER_USB_QUIRK_IGNORE_CLK_FREQ BIT(2) |
|---|
| 41 | 42 | |
|---|
| 42 | 43 | /* Device capabilities */ |
|---|
| 43 | 44 | #define KVASER_USB_CAP_BERR_CAP 0x01 |
|---|
| .. | .. |
|---|
| 65 | 66 | struct kvaser_usb_dev_card_data { |
|---|
| 66 | 67 | u32 ctrlmode_supported; |
|---|
| 67 | 68 | u32 capabilities; |
|---|
| 68 | | - union { |
|---|
| 69 | | - struct { |
|---|
| 70 | | - enum kvaser_usb_leaf_family family; |
|---|
| 71 | | - } leaf; |
|---|
| 72 | | - struct kvaser_usb_dev_card_data_hydra hydra; |
|---|
| 73 | | - }; |
|---|
| 69 | + struct kvaser_usb_dev_card_data_hydra hydra; |
|---|
| 74 | 70 | }; |
|---|
| 75 | 71 | |
|---|
| 76 | 72 | /* Context for an outstanding, not yet ACKed, transmission */ |
|---|
| .. | .. |
|---|
| 80 | 76 | int dlc; |
|---|
| 81 | 77 | }; |
|---|
| 82 | 78 | |
|---|
| 79 | +struct kvaser_usb_busparams { |
|---|
| 80 | + __le32 bitrate; |
|---|
| 81 | + u8 tseg1; |
|---|
| 82 | + u8 tseg2; |
|---|
| 83 | + u8 sjw; |
|---|
| 84 | + u8 nsamples; |
|---|
| 85 | +} __packed; |
|---|
| 86 | + |
|---|
| 83 | 87 | struct kvaser_usb { |
|---|
| 84 | 88 | struct usb_device *udev; |
|---|
| 85 | 89 | struct usb_interface *intf; |
|---|
| 86 | 90 | struct kvaser_usb_net_priv *nets[KVASER_USB_MAX_NET_DEVICES]; |
|---|
| 87 | | - const struct kvaser_usb_dev_ops *ops; |
|---|
| 91 | + const struct kvaser_usb_driver_info *driver_info; |
|---|
| 88 | 92 | const struct kvaser_usb_dev_cfg *cfg; |
|---|
| 89 | 93 | |
|---|
| 90 | 94 | struct usb_endpoint_descriptor *bulk_in, *bulk_out; |
|---|
| .. | .. |
|---|
| 108 | 112 | struct can_priv can; |
|---|
| 109 | 113 | struct can_berr_counter bec; |
|---|
| 110 | 114 | |
|---|
| 115 | + /* subdriver-specific data */ |
|---|
| 116 | + void *sub_priv; |
|---|
| 117 | + |
|---|
| 111 | 118 | struct kvaser_usb *dev; |
|---|
| 112 | 119 | struct net_device *netdev; |
|---|
| 113 | 120 | int channel; |
|---|
| 114 | 121 | |
|---|
| 115 | | - struct completion start_comp, stop_comp, flush_comp; |
|---|
| 122 | + struct completion start_comp, stop_comp, flush_comp, |
|---|
| 123 | + get_busparams_comp; |
|---|
| 116 | 124 | struct usb_anchor tx_submitted; |
|---|
| 125 | + |
|---|
| 126 | + struct kvaser_usb_busparams busparams_nominal, busparams_data; |
|---|
| 117 | 127 | |
|---|
| 118 | 128 | spinlock_t tx_contexts_lock; /* lock for active_tx_contexts */ |
|---|
| 119 | 129 | int active_tx_contexts; |
|---|
| .. | .. |
|---|
| 124 | 134 | * struct kvaser_usb_dev_ops - Device specific functions |
|---|
| 125 | 135 | * @dev_set_mode: used for can.do_set_mode |
|---|
| 126 | 136 | * @dev_set_bittiming: used for can.do_set_bittiming |
|---|
| 137 | + * @dev_get_busparams: readback arbitration busparams |
|---|
| 127 | 138 | * @dev_set_data_bittiming: used for can.do_set_data_bittiming |
|---|
| 139 | + * @dev_get_data_busparams: readback data busparams |
|---|
| 128 | 140 | * @dev_get_berr_counter: used for can.do_get_berr_counter |
|---|
| 129 | 141 | * |
|---|
| 130 | 142 | * @dev_setup_endpoints: setup USB in and out endpoints |
|---|
| 131 | 143 | * @dev_init_card: initialize card |
|---|
| 144 | + * @dev_init_channel: initialize channel |
|---|
| 145 | + * @dev_remove_channel: uninitialize channel |
|---|
| 132 | 146 | * @dev_get_software_info: get software info |
|---|
| 133 | 147 | * @dev_get_software_details: get software details |
|---|
| 134 | 148 | * @dev_get_card_info: get card info |
|---|
| .. | .. |
|---|
| 144 | 158 | */ |
|---|
| 145 | 159 | struct kvaser_usb_dev_ops { |
|---|
| 146 | 160 | int (*dev_set_mode)(struct net_device *netdev, enum can_mode mode); |
|---|
| 147 | | - int (*dev_set_bittiming)(struct net_device *netdev); |
|---|
| 148 | | - int (*dev_set_data_bittiming)(struct net_device *netdev); |
|---|
| 161 | + int (*dev_set_bittiming)(const struct net_device *netdev, |
|---|
| 162 | + const struct kvaser_usb_busparams *busparams); |
|---|
| 163 | + int (*dev_get_busparams)(struct kvaser_usb_net_priv *priv); |
|---|
| 164 | + int (*dev_set_data_bittiming)(const struct net_device *netdev, |
|---|
| 165 | + const struct kvaser_usb_busparams *busparams); |
|---|
| 166 | + int (*dev_get_data_busparams)(struct kvaser_usb_net_priv *priv); |
|---|
| 149 | 167 | int (*dev_get_berr_counter)(const struct net_device *netdev, |
|---|
| 150 | 168 | struct can_berr_counter *bec); |
|---|
| 151 | 169 | int (*dev_setup_endpoints)(struct kvaser_usb *dev); |
|---|
| 152 | 170 | int (*dev_init_card)(struct kvaser_usb *dev); |
|---|
| 171 | + int (*dev_init_channel)(struct kvaser_usb_net_priv *priv); |
|---|
| 172 | + void (*dev_remove_channel)(struct kvaser_usb_net_priv *priv); |
|---|
| 153 | 173 | int (*dev_get_software_info)(struct kvaser_usb *dev); |
|---|
| 154 | 174 | int (*dev_get_software_details)(struct kvaser_usb *dev); |
|---|
| 155 | 175 | int (*dev_get_card_info)(struct kvaser_usb *dev); |
|---|
| .. | .. |
|---|
| 166 | 186 | int *cmd_len, u16 transid); |
|---|
| 167 | 187 | }; |
|---|
| 168 | 188 | |
|---|
| 189 | +struct kvaser_usb_driver_info { |
|---|
| 190 | + u32 quirks; |
|---|
| 191 | + enum kvaser_usb_leaf_family family; |
|---|
| 192 | + const struct kvaser_usb_dev_ops *ops; |
|---|
| 193 | +}; |
|---|
| 194 | + |
|---|
| 169 | 195 | struct kvaser_usb_dev_cfg { |
|---|
| 170 | 196 | const struct can_clock clock; |
|---|
| 171 | 197 | const unsigned int timestamp_freq; |
|---|
| .. | .. |
|---|
| 176 | 202 | extern const struct kvaser_usb_dev_ops kvaser_usb_hydra_dev_ops; |
|---|
| 177 | 203 | extern const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops; |
|---|
| 178 | 204 | |
|---|
| 205 | +void kvaser_usb_unlink_tx_urbs(struct kvaser_usb_net_priv *priv); |
|---|
| 206 | + |
|---|
| 179 | 207 | int kvaser_usb_recv_cmd(const struct kvaser_usb *dev, void *cmd, int len, |
|---|
| 180 | 208 | int *actual_len); |
|---|
| 181 | 209 | |
|---|
| .. | .. |
|---|
| 185 | 213 | int len); |
|---|
| 186 | 214 | |
|---|
| 187 | 215 | int kvaser_usb_can_rx_over_error(struct net_device *netdev); |
|---|
| 216 | + |
|---|
| 217 | +extern const struct can_bittiming_const kvaser_usb_flexc_bittiming_const; |
|---|
| 218 | + |
|---|
| 188 | 219 | #endif /* KVASER_USB_H */ |
|---|