20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/slab.h>
51 static const char *
const as102_device_names[] = {
62 static uint8_t const as102_elna_cfg[] = {
73 .probe = as102_usb_probe,
74 .disconnect = as102_usb_disconnect,
75 .id_table = as102_usb_id_table
81 .release = as102_release,
84 static struct usb_class_driver as102_usb_class_driver = {
86 .fops = &as102_dev_fops,
91 unsigned char *send_buf,
int send_buf_len,
92 unsigned char *
recv_buf,
int recv_buf_len)
97 if (send_buf !=
NULL) {
99 usb_sndctrlpipe(bus_adap->
usb_dev, 0),
105 send_buf, send_buf_len,
106 USB_CTRL_SET_TIMEOUT );
108 dprintk(
debug,
"usb_control_msg(send) failed, err %i\n",
113 if (ret != send_buf_len) {
120 if (recv_buf !=
NULL) {
122 dprintk(
debug,
"want to read: %d bytes\n", recv_buf_len);
125 usb_rcvctrlpipe(bus_adap->
usb_dev, 0),
131 recv_buf, recv_buf_len,
132 USB_CTRL_GET_TIMEOUT );
134 dprintk(
debug,
"usb_control_msg(recv) failed, err %i\n",
148 unsigned char *send_buf,
152 int ret = 0, actual_len;
155 usb_sndbulkpipe(bus_adap->
usb_dev, 1),
156 send_buf, send_buf_len, &actual_len, 200);
158 dprintk(
debug,
"usb_bulk_msg(send) failed, err %i\n", ret);
162 if (actual_len != send_buf_len) {
164 actual_len, send_buf_len);
167 return ret ? ret : actual_len;
171 unsigned char *recv_buf,
int recv_buf_len)
173 int ret = 0, actual_len;
175 if (recv_buf ==
NULL)
179 usb_rcvbulkpipe(bus_adap->
usb_dev, 2),
180 recv_buf, recv_buf_len, &actual_len, 200);
182 dprintk(
debug,
"usb_bulk_msg(recv) failed, err %i\n", ret);
186 if (actual_len != recv_buf_len) {
188 actual_len, recv_buf_len);
191 return ret ? ret : actual_len;
195 .upload_fw_pkt = as102_send_ep1,
196 .xfer_cmd = as102_usb_xfer_cmd,
197 .as102_read_ep2 = as102_read_ep2,
198 .start_stream = as102_usb_start_stream,
199 .stop_stream = as102_usb_stop_stream,
206 usb_fill_bulk_urb(urb,
208 usb_rcvbulkpipe(dev->
bus_adap.usb_dev, 0x2),
209 urb->transfer_buffer,
216 dprintk(
debug,
"%s: usb_submit_urb failed\n", __func__);
225 if (urb->actual_length > 0) {
227 urb->transfer_buffer,
230 if (urb->actual_length == 0)
236 as102_submit_urb_stream(as102_dev, urb);
239 static void as102_free_usb_stream_buffer(
struct as102_dev_t *dev)
255 static int as102_alloc_usb_stream_buffer(
struct as102_dev_t *dev)
266 dprintk(
debug,
"%s: usb_buffer_alloc failed\n", __func__);
279 as102_free_usb_stream_buffer(dev);
285 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
294 static void as102_usb_stop_stream(
struct as102_dev_t *dev)
302 static int as102_usb_start_stream(
struct as102_dev_t *dev)
307 ret = as102_submit_urb_stream(dev, dev->
stream_urb[i]);
309 as102_usb_stop_stream(dev);
317 static void as102_usb_release(
struct kref *
kref)
324 if (as102_dev !=
NULL) {
339 as102_dev = usb_get_intfdata(intf);
345 as102_free_usb_stream_buffer(as102_dev);
347 usb_set_intfdata(intf,
NULL);
353 kref_put(&as102_dev->
kref, as102_usb_release);
371 (
sizeof(as102_device_names) /
sizeof(
const char *))) {
372 pr_err(
"Device names table invalid size");
377 if (as102_dev ==
NULL) {
378 dev_err(&intf->dev,
"%s: kzalloc failed\n", __func__);
383 for (i = 0; i <
ARRAY_SIZE(as102_usb_id_table); i++) {
384 if (
id == &as102_usb_id_table[i]) {
385 as102_dev->
name = as102_device_names[
i];
391 as102_dev->
name =
"Unknown AS102 device";
401 kref_init(&as102_dev->
kref);
404 usb_set_intfdata(intf, (
void *) as102_dev);
414 "%s: usb_register_dev() failed (errno = %d)\n",
422 ret = as102_alloc_usb_stream_buffer(as102_dev);
433 usb_set_intfdata(intf,
NULL);
440 int ret = 0,
minor = 0;
447 minor = iminor(inode);
452 pr_err(
"%s: can't find device for minor %d\n",
459 dev = usb_get_intfdata(intf);
469 kref_get(&dev->
kref);
476 static int as102_release(
struct inode *inode,
struct file *file)
486 kref_put(&dev->
kref, as102_usb_release);