Commit 86878827 authored by Timo von Holtz's avatar Timo von Holtz Committed by Greg Kroah-Hartman

Staging: dabusb: fixed coding style issues

Fixed coding style issues
Signed-off-by: default avatarTimo von Holtz <tvh@informatik.uni-kiel.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 046d747e
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/init.h> #include <linux/init.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/atomic.h> #include <linux/atomic.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/mutex.h> #include <linux/mutex.h>
...@@ -66,28 +66,29 @@ static struct usb_driver dabusb_driver; ...@@ -66,28 +66,29 @@ static struct usb_driver dabusb_driver;
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static int dabusb_add_buf_tail (pdabusb_t s, struct list_head *dst, struct list_head *src) static int dabusb_add_buf_tail(pdabusb_t s, struct list_head *dst,
struct list_head *src)
{ {
unsigned long flags; unsigned long flags;
struct list_head *tmp; struct list_head *tmp;
int ret = 0; int ret = 0;
spin_lock_irqsave (&s->lock, flags); spin_lock_irqsave(&s->lock, flags);
if (list_empty (src)) { if (list_empty(src)) {
// no elements in source buffer /* no elements in source buffer */
ret = -1; ret = -1;
goto err; goto err;
} }
tmp = src->next; tmp = src->next;
list_move_tail (tmp, dst); list_move_tail(tmp, dst);
err: spin_unlock_irqrestore (&s->lock, flags); err: spin_unlock_irqrestore(&s->lock, flags);
return ret; return ret;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
#ifdef DEBUG #ifdef DEBUG
static void dump_urb (struct urb *urb) static void dump_urb(struct urb *urb)
{ {
dbg("urb :%p", urb); dbg("urb :%p", urb);
dbg("dev :%p", urb->dev); dbg("dev :%p", urb->dev);
...@@ -107,26 +108,26 @@ static void dump_urb (struct urb *urb) ...@@ -107,26 +108,26 @@ static void dump_urb (struct urb *urb)
} }
#endif #endif
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static int dabusb_cancel_queue (pdabusb_t s, struct list_head *q) static int dabusb_cancel_queue(pdabusb_t s, struct list_head *q)
{ {
unsigned long flags; unsigned long flags;
pbuff_t b; pbuff_t b;
dbg("dabusb_cancel_queue"); dbg("dabusb_cancel_queue");
spin_lock_irqsave (&s->lock, flags); spin_lock_irqsave(&s->lock, flags);
list_for_each_entry(b, q, buff_list) { list_for_each_entry(b, q, buff_list) {
#ifdef DEBUG #ifdef DEBUG
dump_urb(b->purb); dump_urb(b->purb);
#endif #endif
usb_unlink_urb (b->purb); usb_unlink_urb(b->purb);
} }
spin_unlock_irqrestore (&s->lock, flags); spin_unlock_irqrestore(&s->lock, flags);
return 0; return 0;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static int dabusb_free_queue (struct list_head *q) static int dabusb_free_queue(struct list_head *q)
{ {
struct list_head *tmp; struct list_head *tmp;
struct list_head *p; struct list_head *p;
...@@ -134,7 +135,7 @@ static int dabusb_free_queue (struct list_head *q) ...@@ -134,7 +135,7 @@ static int dabusb_free_queue (struct list_head *q)
dbg("dabusb_free_queue"); dbg("dabusb_free_queue");
for (p = q->next; p != q;) { for (p = q->next; p != q;) {
b = list_entry (p, buff_t, buff_list); b = list_entry(p, buff_t, buff_list);
#ifdef DEBUG #ifdef DEBUG
dump_urb(b->purb); dump_urb(b->purb);
...@@ -142,23 +143,23 @@ static int dabusb_free_queue (struct list_head *q) ...@@ -142,23 +143,23 @@ static int dabusb_free_queue (struct list_head *q)
kfree(b->purb->transfer_buffer); kfree(b->purb->transfer_buffer);
usb_free_urb(b->purb); usb_free_urb(b->purb);
tmp = p->next; tmp = p->next;
list_del (p); list_del(p);
kfree (b); kfree(b);
p = tmp; p = tmp;
} }
return 0; return 0;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static int dabusb_free_buffers (pdabusb_t s) static int dabusb_free_buffers(pdabusb_t s)
{ {
unsigned long flags; unsigned long flags;
dbg("dabusb_free_buffers"); dbg("dabusb_free_buffers");
spin_lock_irqsave(&s->lock, flags); spin_lock_irqsave(&s->lock, flags);
dabusb_free_queue (&s->free_buff_list); dabusb_free_queue(&s->free_buff_list);
dabusb_free_queue (&s->rec_buff_list); dabusb_free_queue(&s->rec_buff_list);
spin_unlock_irqrestore(&s->lock, flags); spin_unlock_irqrestore(&s->lock, flags);
...@@ -166,7 +167,7 @@ static int dabusb_free_buffers (pdabusb_t s) ...@@ -166,7 +167,7 @@ static int dabusb_free_buffers (pdabusb_t s)
return 0; return 0;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static void dabusb_iso_complete (struct urb *purb) static void dabusb_iso_complete(struct urb *purb)
{ {
pbuff_t b = purb->context; pbuff_t b = purb->context;
pdabusb_t s = b->s; pdabusb_t s = b->s;
...@@ -177,42 +178,45 @@ static void dabusb_iso_complete (struct urb *purb) ...@@ -177,42 +178,45 @@ static void dabusb_iso_complete (struct urb *purb)
dbg("dabusb_iso_complete"); dbg("dabusb_iso_complete");
// process if URB was not killed /* process if URB was not killed */
if (purb->status != -ENOENT) { if (purb->status != -ENOENT) {
unsigned int pipe = usb_rcvisocpipe (purb->dev, _DABUSB_ISOPIPE); unsigned int pipe = usb_rcvisocpipe(purb->dev, _DABUSB_ISOPIPE);
int pipesize = usb_maxpacket (purb->dev, pipe, usb_pipeout (pipe)); int pipesize = usb_maxpacket(purb->dev, pipe,
usb_pipeout(pipe));
for (i = 0; i < purb->number_of_packets; i++) for (i = 0; i < purb->number_of_packets; i++)
if (!purb->iso_frame_desc[i].status) { if (!purb->iso_frame_desc[i].status) {
len = purb->iso_frame_desc[i].actual_length; len = purb->iso_frame_desc[i].actual_length;
if (len <= pipesize) { if (len <= pipesize) {
memcpy (buf + dst, buf + purb->iso_frame_desc[i].offset, len); memcpy(buf + dst, buf + purb->iso_frame_desc[i].offset, len);
dst += len; dst += len;
} } else
else
dev_err(&purb->dev->dev, dev_err(&purb->dev->dev,
"dabusb_iso_complete: invalid len %d\n", len); "dabusb_iso_complete: invalid len %d\n",
} len);
else } else
dev_warn(&purb->dev->dev, "dabusb_iso_complete: corrupted packet status: %d\n", purb->iso_frame_desc[i].status); dev_warn(&purb->dev->dev,
"dabusb_iso_complete: corrupted packet status: %d\n",
purb->iso_frame_desc[i].status);
if (dst != purb->actual_length) if (dst != purb->actual_length)
dev_err(&purb->dev->dev, dev_err(&purb->dev->dev,
"dst!=purb->actual_length:%d!=%d\n", "dst!=purb->actual_length:%d!=%d\n",
dst, purb->actual_length); dst, purb->actual_length);
} }
if (atomic_dec_and_test (&s->pending_io) && !s->remove_pending && s->state != _stopped) { if (atomic_dec_and_test(&s->pending_io) &&
!s->remove_pending && s->state != _stopped) {
s->overruns++; s->overruns++;
dev_err(&purb->dev->dev, "overrun (%d)\n", s->overruns); dev_err(&purb->dev->dev, "overrun (%d)\n", s->overruns);
} }
wake_up (&s->wait); wake_up(&s->wait);
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static int dabusb_alloc_buffers (pdabusb_t s) static int dabusb_alloc_buffers(pdabusb_t s)
{ {
int transfer_len = 0; int transfer_len = 0;
pbuff_t b; pbuff_t b;
unsigned int pipe = usb_rcvisocpipe (s->usbdev, _DABUSB_ISOPIPE); unsigned int pipe = usb_rcvisocpipe(s->usbdev, _DABUSB_ISOPIPE);
int pipesize = usb_maxpacket (s->usbdev, pipe, usb_pipeout (pipe)); int pipesize = usb_maxpacket(s->usbdev, pipe, usb_pipeout(pipe));
int packets = _ISOPIPESIZE / pipesize; int packets = _ISOPIPESIZE / pipesize;
int transfer_buffer_length = packets * pipesize; int transfer_buffer_length = packets * pipesize;
int i; int i;
...@@ -221,7 +225,7 @@ static int dabusb_alloc_buffers (pdabusb_t s) ...@@ -221,7 +225,7 @@ static int dabusb_alloc_buffers (pdabusb_t s)
pipesize, packets, transfer_buffer_length); pipesize, packets, transfer_buffer_length);
while (transfer_len < (s->total_buffer_size << 10)) { while (transfer_len < (s->total_buffer_size << 10)) {
b = kzalloc(sizeof (buff_t), GFP_KERNEL); b = kzalloc(sizeof(buff_t), GFP_KERNEL);
if (!b) { if (!b) {
dev_err(&s->usbdev->dev, dev_err(&s->usbdev->dev,
"kzalloc(sizeof(buff_t))==NULL\n"); "kzalloc(sizeof(buff_t))==NULL\n");
...@@ -231,14 +235,15 @@ static int dabusb_alloc_buffers (pdabusb_t s) ...@@ -231,14 +235,15 @@ static int dabusb_alloc_buffers (pdabusb_t s)
b->purb = usb_alloc_urb(packets, GFP_KERNEL); b->purb = usb_alloc_urb(packets, GFP_KERNEL);
if (!b->purb) { if (!b->purb) {
dev_err(&s->usbdev->dev, "usb_alloc_urb == NULL\n"); dev_err(&s->usbdev->dev, "usb_alloc_urb == NULL\n");
kfree (b); kfree(b);
goto err; goto err;
} }
b->purb->transfer_buffer = kmalloc (transfer_buffer_length, GFP_KERNEL); b->purb->transfer_buffer = kmalloc(transfer_buffer_length,
GFP_KERNEL);
if (!b->purb->transfer_buffer) { if (!b->purb->transfer_buffer) {
kfree (b->purb); kfree(b->purb);
kfree (b); kfree(b);
dev_err(&s->usbdev->dev, dev_err(&s->usbdev->dev,
"kmalloc(%d)==NULL\n", transfer_buffer_length); "kmalloc(%d)==NULL\n", transfer_buffer_length);
goto err; goto err;
...@@ -258,18 +263,18 @@ static int dabusb_alloc_buffers (pdabusb_t s) ...@@ -258,18 +263,18 @@ static int dabusb_alloc_buffers (pdabusb_t s)
} }
transfer_len += transfer_buffer_length; transfer_len += transfer_buffer_length;
list_add_tail (&b->buff_list, &s->free_buff_list); list_add_tail(&b->buff_list, &s->free_buff_list);
} }
s->got_mem = transfer_len; s->got_mem = transfer_len;
return 0; return 0;
err: err:
dabusb_free_buffers (s); dabusb_free_buffers(s);
return -ENOMEM; return -ENOMEM;
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static int dabusb_bulk (pdabusb_t s, pbulk_transfer_t pb) static int dabusb_bulk(pdabusb_t s, pbulk_transfer_t pb)
{ {
int ret; int ret;
unsigned int pipe; unsigned int pipe;
...@@ -278,25 +283,26 @@ static int dabusb_bulk (pdabusb_t s, pbulk_transfer_t pb) ...@@ -278,25 +283,26 @@ static int dabusb_bulk (pdabusb_t s, pbulk_transfer_t pb)
dbg("dabusb_bulk"); dbg("dabusb_bulk");
if (!pb->pipe) if (!pb->pipe)
pipe = usb_rcvbulkpipe (s->usbdev, 2); pipe = usb_rcvbulkpipe(s->usbdev, 2);
else else
pipe = usb_sndbulkpipe (s->usbdev, 2); pipe = usb_sndbulkpipe(s->usbdev, 2);
ret=usb_bulk_msg(s->usbdev, pipe, pb->data, pb->size, &actual_length, 100); ret = usb_bulk_msg(s->usbdev, pipe, pb->data,
if(ret<0) { pb->size, &actual_length, 100);
if (ret < 0) {
dev_err(&s->usbdev->dev, dev_err(&s->usbdev->dev,
"usb_bulk_msg failed(%d)\n", ret); "usb_bulk_msg failed(%d)\n", ret);
if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) { if (usb_set_interface(s->usbdev, _DABUSB_IF, 1) < 0) {
dev_err(&s->usbdev->dev, "set_interface failed\n"); dev_err(&s->usbdev->dev, "set_interface failed\n");
return -EINVAL; return -EINVAL;
} }
} }
if( ret == -EPIPE ) { if (ret == -EPIPE) {
dev_warn(&s->usbdev->dev, "CLEAR_FEATURE request to remove STALL condition.\n"); dev_warn(&s->usbdev->dev, "CLEAR_FEATURE request to remove STALL condition.\n");
if(usb_clear_halt(s->usbdev, usb_pipeendpoint(pipe))) if (usb_clear_halt(s->usbdev, usb_pipeendpoint(pipe)))
dev_err(&s->usbdev->dev, "request failed\n"); dev_err(&s->usbdev->dev, "request failed\n");
} }
...@@ -304,11 +310,11 @@ static int dabusb_bulk (pdabusb_t s, pbulk_transfer_t pb) ...@@ -304,11 +310,11 @@ static int dabusb_bulk (pdabusb_t s, pbulk_transfer_t pb)
return ret; return ret;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int dabusb_writemem (pdabusb_t s, int pos, const unsigned char *data, static int dabusb_writemem(pdabusb_t s, int pos, const unsigned char *data,
int len) int len)
{ {
int ret; int ret;
unsigned char *transfer_buffer = kmalloc (len, GFP_KERNEL); unsigned char *transfer_buffer = kmalloc(len, GFP_KERNEL);
if (!transfer_buffer) { if (!transfer_buffer) {
dev_err(&s->usbdev->dev, dev_err(&s->usbdev->dev,
...@@ -316,21 +322,22 @@ static int dabusb_writemem (pdabusb_t s, int pos, const unsigned char *data, ...@@ -316,21 +322,22 @@ static int dabusb_writemem (pdabusb_t s, int pos, const unsigned char *data,
return -ENOMEM; return -ENOMEM;
} }
memcpy (transfer_buffer, data, len); memcpy(transfer_buffer, data, len);
ret=usb_control_msg(s->usbdev, usb_sndctrlpipe( s->usbdev, 0 ), 0xa0, 0x40, pos, 0, transfer_buffer, len, 300); ret = usb_control_msg(s->usbdev, usb_sndctrlpipe(s->usbdev, 0),
0xa0, 0x40, pos, 0, transfer_buffer, len, 300);
kfree (transfer_buffer); kfree(transfer_buffer);
return ret; return ret;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int dabusb_8051_reset (pdabusb_t s, unsigned char reset_bit) static int dabusb_8051_reset(pdabusb_t s, unsigned char reset_bit)
{ {
dbg("dabusb_8051_reset: %d",reset_bit); dbg("dabusb_8051_reset: %d", reset_bit);
return dabusb_writemem (s, CPUCS_REG, &reset_bit, 1); return dabusb_writemem(s, CPUCS_REG, &reset_bit, 1);
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int dabusb_loadmem (pdabusb_t s, const char *fname) static int dabusb_loadmem(pdabusb_t s, const char *fname)
{ {
int ret; int ret;
const struct ihex_binrec *rec; const struct ihex_binrec *rec;
...@@ -344,7 +351,7 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname) ...@@ -344,7 +351,7 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname)
"Failed to load \"dabusb/firmware.fw\": %d\n", ret); "Failed to load \"dabusb/firmware.fw\": %d\n", ret);
goto out; goto out;
} }
ret = dabusb_8051_reset (s, 1); ret = dabusb_8051_reset(s, 1);
for (rec = (const struct ihex_binrec *)fw->data; rec; for (rec = (const struct ihex_binrec *)fw->data; rec;
rec = ihex_next_binrec(rec)) { rec = ihex_next_binrec(rec)) {
...@@ -361,7 +368,7 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname) ...@@ -361,7 +368,7 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname)
break; break;
} }
} }
ret = dabusb_8051_reset (s, 0); ret = dabusb_8051_reset(s, 0);
release_firmware(fw); release_firmware(fw);
out: out:
dbg("dabusb_loadmem: exit"); dbg("dabusb_loadmem: exit");
...@@ -369,7 +376,7 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname) ...@@ -369,7 +376,7 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname)
return ret; return ret;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int dabusb_fpga_clear (pdabusb_t s, pbulk_transfer_t b) static int dabusb_fpga_clear(pdabusb_t s, pbulk_transfer_t b)
{ {
b->size = 4; b->size = 4;
b->data[0] = 0x2a; b->data[0] = 0x2a;
...@@ -379,10 +386,10 @@ static int dabusb_fpga_clear (pdabusb_t s, pbulk_transfer_t b) ...@@ -379,10 +386,10 @@ static int dabusb_fpga_clear (pdabusb_t s, pbulk_transfer_t b)
dbg("dabusb_fpga_clear"); dbg("dabusb_fpga_clear");
return dabusb_bulk (s, b); return dabusb_bulk(s, b);
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int dabusb_fpga_init (pdabusb_t s, pbulk_transfer_t b) static int dabusb_fpga_init(pdabusb_t s, pbulk_transfer_t b)
{ {
b->size = 4; b->size = 4;
b->data[0] = 0x2c; b->data[0] = 0x2c;
...@@ -392,12 +399,12 @@ static int dabusb_fpga_init (pdabusb_t s, pbulk_transfer_t b) ...@@ -392,12 +399,12 @@ static int dabusb_fpga_init (pdabusb_t s, pbulk_transfer_t b)
dbg("dabusb_fpga_init"); dbg("dabusb_fpga_init");
return dabusb_bulk (s, b); return dabusb_bulk(s, b);
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int dabusb_fpga_download (pdabusb_t s, const char *fname) static int dabusb_fpga_download(pdabusb_t s, const char *fname)
{ {
pbulk_transfer_t b = kmalloc (sizeof (bulk_transfer_t), GFP_KERNEL); pbulk_transfer_t b = kmalloc(sizeof(bulk_transfer_t), GFP_KERNEL);
const struct firmware *fw; const struct firmware *fw;
unsigned int blen, n; unsigned int blen, n;
int ret; int ret;
...@@ -419,8 +426,8 @@ static int dabusb_fpga_download (pdabusb_t s, const char *fname) ...@@ -419,8 +426,8 @@ static int dabusb_fpga_download (pdabusb_t s, const char *fname)
} }
b->pipe = 1; b->pipe = 1;
ret = dabusb_fpga_clear (s, b); ret = dabusb_fpga_clear(s, b);
mdelay (10); mdelay(10);
blen = fw->data[73] + (fw->data[72] << 8); blen = fw->data[73] + (fw->data[72] << 8);
dbg("Bitstream len: %i", blen); dbg("Bitstream len: %i", blen);
...@@ -431,19 +438,19 @@ static int dabusb_fpga_download (pdabusb_t s, const char *fname) ...@@ -431,19 +438,19 @@ static int dabusb_fpga_download (pdabusb_t s, const char *fname)
b->data[3] = 60; b->data[3] = 60;
for (n = 0; n <= blen + 60; n += 60) { for (n = 0; n <= blen + 60; n += 60) {
// some cclks for startup /* some cclks for startup */
b->size = 64; b->size = 64;
memcpy (b->data + 4, fw->data + 74 + n, 60); memcpy(b->data + 4, fw->data + 74 + n, 60);
ret = dabusb_bulk (s, b); ret = dabusb_bulk(s, b);
if (ret < 0) { if (ret < 0) {
dev_err(&s->usbdev->dev, "dabusb_bulk failed.\n"); dev_err(&s->usbdev->dev, "dabusb_bulk failed.\n");
break; break;
} }
mdelay (1); mdelay(1);
} }
ret = dabusb_fpga_init (s, b); ret = dabusb_fpga_init(s, b);
kfree (b); kfree(b);
release_firmware(fw); release_firmware(fw);
dbg("exit dabusb_fpga_download"); dbg("exit dabusb_fpga_download");
...@@ -451,12 +458,12 @@ static int dabusb_fpga_download (pdabusb_t s, const char *fname) ...@@ -451,12 +458,12 @@ static int dabusb_fpga_download (pdabusb_t s, const char *fname)
return ret; return ret;
} }
static int dabusb_stop (pdabusb_t s) static int dabusb_stop(pdabusb_t s)
{ {
dbg("dabusb_stop"); dbg("dabusb_stop");
s->state = _stopped; s->state = _stopped;
dabusb_cancel_queue (s, &s->rec_buff_list); dabusb_cancel_queue(s, &s->rec_buff_list);
dbg("pending_io: %d", s->pending_io.counter); dbg("pending_io: %d", s->pending_io.counter);
...@@ -464,50 +471,53 @@ static int dabusb_stop (pdabusb_t s) ...@@ -464,50 +471,53 @@ static int dabusb_stop (pdabusb_t s)
return 0; return 0;
} }
static int dabusb_startrek (pdabusb_t s) static int dabusb_startrek(pdabusb_t s)
{ {
if (!s->got_mem && s->state != _started) { if (!s->got_mem && s->state != _started) {
dbg("dabusb_startrek"); dbg("dabusb_startrek");
if (dabusb_alloc_buffers (s) < 0) if (dabusb_alloc_buffers(s) < 0)
return -ENOMEM; return -ENOMEM;
dabusb_stop (s); dabusb_stop(s);
s->state = _started; s->state = _started;
s->readptr = 0; s->readptr = 0;
} }
if (!list_empty (&s->free_buff_list)) { if (!list_empty(&s->free_buff_list)) {
pbuff_t end; pbuff_t end;
int ret; int ret;
while (!dabusb_add_buf_tail (s, &s->rec_buff_list, &s->free_buff_list)) { while (!dabusb_add_buf_tail(s, &s->rec_buff_list, &s->free_buff_list)) {
dbg("submitting: end:%p s->rec_buff_list:%p", s->rec_buff_list.prev, &s->rec_buff_list); dbg("submitting: end:%p s->rec_buff_list:%p",
s->rec_buff_list.prev, &s->rec_buff_list);
end = list_entry (s->rec_buff_list.prev, buff_t, buff_list); end = list_entry(s->rec_buff_list.prev,
buff_t, buff_list);
ret = usb_submit_urb (end->purb, GFP_KERNEL); ret = usb_submit_urb(end->purb, GFP_KERNEL);
if (ret) { if (ret) {
dev_err(&s->usbdev->dev, dev_err(&s->usbdev->dev,
"usb_submit_urb returned:%d\n", ret); "usb_submit_urb returned:%d\n", ret);
if (dabusb_add_buf_tail (s, &s->free_buff_list, &s->rec_buff_list)) if (dabusb_add_buf_tail(s, &s->free_buff_list,
&s->rec_buff_list))
dev_err(&s->usbdev->dev, dev_err(&s->usbdev->dev,
"startrek: dabusb_add_buf_tail failed\n"); "startrek: dabusb_add_buf_tail failed\n");
break; break;
} else
atomic_inc(&s->pending_io);
} }
else dbg("pending_io: %d", s->pending_io.counter);
atomic_inc (&s->pending_io);
}
dbg("pending_io: %d",s->pending_io.counter);
} }
return 0; return 0;
} }
static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, loff_t * ppos) static ssize_t dabusb_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{ {
pdabusb_t s = (pdabusb_t) file->private_data; pdabusb_t s = (pdabusb_t)file->private_data;
unsigned long flags; unsigned long flags;
unsigned ret = 0; unsigned ret = 0;
int rem; int rem;
...@@ -528,11 +538,11 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l ...@@ -528,11 +538,11 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
return -EIO; return -EIO;
while (count > 0) { while (count > 0) {
dabusb_startrek (s); dabusb_startrek(s);
spin_lock_irqsave (&s->lock, flags); spin_lock_irqsave(&s->lock, flags);
if (list_empty (&s->rec_buff_list)) { if (list_empty(&s->rec_buff_list)) {
spin_unlock_irqrestore(&s->lock, flags); spin_unlock_irqrestore(&s->lock, flags);
...@@ -541,30 +551,30 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l ...@@ -541,30 +551,30 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
goto err; goto err;
} }
b = list_entry (s->rec_buff_list.next, buff_t, buff_list); b = list_entry(s->rec_buff_list.next, buff_t, buff_list);
purb = b->purb; purb = b->purb;
spin_unlock_irqrestore(&s->lock, flags); spin_unlock_irqrestore(&s->lock, flags);
if (purb->status == -EINPROGRESS) { if (purb->status == -EINPROGRESS) {
if (file->f_flags & O_NONBLOCK) // return nonblocking /* return nonblocking */
{ if (file->f_flags & O_NONBLOCK) {
if (!ret) if (!ret)
ret = -EAGAIN; ret = -EAGAIN;
goto err; goto err;
} }
interruptible_sleep_on (&s->wait); interruptible_sleep_on(&s->wait);
if (signal_pending (current)) { if (signal_pending(current)) {
if (!ret) if (!ret)
ret = -ERESTARTSYS; ret = -ERESTARTSYS;
goto err; goto err;
} }
spin_lock_irqsave (&s->lock, flags); spin_lock_irqsave(&s->lock, flags);
if (list_empty (&s->rec_buff_list)) { if (list_empty(&s->rec_buff_list)) {
spin_unlock_irqrestore(&s->lock, flags); spin_unlock_irqrestore(&s->lock, flags);
dev_err(&s->usbdev->dev, dev_err(&s->usbdev->dev,
"error: still no buffer available.\n"); "error: still no buffer available.\n");
...@@ -578,16 +588,20 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l ...@@ -578,16 +588,20 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
goto err; goto err;
} }
rem = purb->actual_length - s->readptr; // set remaining bytes to copy /* set remaining bytes to copy */
rem = purb->actual_length - s->readptr;
if (count >= rem) if (count >= rem)
cnt = rem; cnt = rem;
else else
cnt = count; cnt = count;
dbg("copy_to_user:%p %p %d",buf, purb->transfer_buffer + s->readptr, cnt); dbg("copy_to_user:%p %p %d", buf,
purb->transfer_buffer + s->readptr, cnt);
if (copy_to_user (buf, purb->transfer_buffer + s->readptr, cnt)) { if (copy_to_user(buf,
purb->transfer_buffer + s->readptr,
cnt)) {
dev_err(&s->usbdev->dev, "read: copy_to_user failed\n"); dev_err(&s->usbdev->dev, "read: copy_to_user failed\n");
if (!ret) if (!ret)
ret = -EFAULT; ret = -EFAULT;
...@@ -600,18 +614,19 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l ...@@ -600,18 +614,19 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
ret += cnt; ret += cnt;
if (s->readptr == purb->actual_length) { if (s->readptr == purb->actual_length) {
// finished, take next buffer /* finished, take next buffer */
if (dabusb_add_buf_tail (s, &s->free_buff_list, &s->rec_buff_list)) if (dabusb_add_buf_tail(s, &s->free_buff_list,
&s->rec_buff_list))
dev_err(&s->usbdev->dev, dev_err(&s->usbdev->dev,
"read: dabusb_add_buf_tail failed\n"); "read: dabusb_add_buf_tail failed\n");
s->readptr = 0; s->readptr = 0;
} }
} }
err: //mutex_unlock(&s->mutex); err: /*mutex_unlock(&s->mutex);*/
return ret; return ret;
} }
static int dabusb_open (struct inode *inode, struct file *file) static int dabusb_open(struct inode *inode, struct file *file)
{ {
int devnum = iminor(inode); int devnum = iminor(inode);
pdabusb_t s; pdabusb_t s;
...@@ -632,11 +647,11 @@ static int dabusb_open (struct inode *inode, struct file *file) ...@@ -632,11 +647,11 @@ static int dabusb_open (struct inode *inode, struct file *file)
return -EBUSY; return -EBUSY;
msleep_interruptible(500); msleep_interruptible(500);
if (signal_pending (current)) if (signal_pending(current))
return -EAGAIN; return -EAGAIN;
mutex_lock(&s->mutex); mutex_lock(&s->mutex);
} }
if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) { if (usb_set_interface(s->usbdev, _DABUSB_IF, 1) < 0) {
mutex_unlock(&s->mutex); mutex_unlock(&s->mutex);
dev_err(&s->usbdev->dev, "set_interface failed\n"); dev_err(&s->usbdev->dev, "set_interface failed\n");
return -EINVAL; return -EINVAL;
...@@ -651,31 +666,30 @@ static int dabusb_open (struct inode *inode, struct file *file) ...@@ -651,31 +666,30 @@ static int dabusb_open (struct inode *inode, struct file *file)
return r; return r;
} }
static int dabusb_release (struct inode *inode, struct file *file) static int dabusb_release(struct inode *inode, struct file *file)
{ {
pdabusb_t s = (pdabusb_t) file->private_data; pdabusb_t s = (pdabusb_t)file->private_data;
dbg("dabusb_release"); dbg("dabusb_release");
mutex_lock(&s->mutex); mutex_lock(&s->mutex);
dabusb_stop (s); dabusb_stop(s);
dabusb_free_buffers (s); dabusb_free_buffers(s);
mutex_unlock(&s->mutex); mutex_unlock(&s->mutex);
if (!s->remove_pending) { if (!s->remove_pending) {
if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0) if (usb_set_interface(s->usbdev, _DABUSB_IF, 0) < 0)
dev_err(&s->usbdev->dev, "set_interface failed\n"); dev_err(&s->usbdev->dev, "set_interface failed\n");
} } else
else wake_up(&s->remove_ok);
wake_up (&s->remove_ok);
s->opened = 0; s->opened = 0;
return 0; return 0;
} }
static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg) static long dabusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{ {
pdabusb_t s = (pdabusb_t) file->private_data; pdabusb_t s = (pdabusb_t)file->private_data;
pbulk_transfer_t pbulk; pbulk_transfer_t pbulk;
int ret = 0; int ret = 0;
int version = DABUSB_VERSION; int version = DABUSB_VERSION;
...@@ -703,20 +717,20 @@ static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg ...@@ -703,20 +717,20 @@ static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg
break; break;
} }
ret=dabusb_bulk (s, pbulk); ret = dabusb_bulk(s, pbulk);
if(ret==0) if (ret == 0)
if (copy_to_user((void __user *)arg, pbulk, if (copy_to_user((void __user *)arg, pbulk,
sizeof(bulk_transfer_t))) sizeof(bulk_transfer_t)))
ret = -EFAULT; ret = -EFAULT;
kfree (pbulk); kfree(pbulk);
break; break;
case IOCTL_DAB_OVERRUNS: case IOCTL_DAB_OVERRUNS:
ret = put_user (s->overruns, (unsigned int __user *) arg); ret = put_user(s->overruns, (unsigned int __user *) arg);
break; break;
case IOCTL_DAB_VERSION: case IOCTL_DAB_VERSION:
ret = put_user (version, (unsigned int __user *) arg); ret = put_user(version, (unsigned int __user *) arg);
break; break;
default: default:
...@@ -727,8 +741,7 @@ static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg ...@@ -727,8 +741,7 @@ static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg
return ret; return ret;
} }
static const struct file_operations dabusb_fops = static const struct file_operations dabusb_fops = {
{
.owner = THIS_MODULE, .owner = THIS_MODULE,
.llseek = no_llseek, .llseek = no_llseek,
.read = dabusb_read, .read = dabusb_read,
...@@ -751,7 +764,7 @@ static struct usb_class_driver dabusb_class = { ...@@ -751,7 +764,7 @@ static struct usb_class_driver dabusb_class = {
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int dabusb_probe (struct usb_interface *intf, static int dabusb_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct usb_device *usbdev = interface_to_usbdev(intf); struct usb_device *usbdev = interface_to_usbdev(intf);
...@@ -780,54 +793,53 @@ static int dabusb_probe (struct usb_interface *intf, ...@@ -780,54 +793,53 @@ static int dabusb_probe (struct usb_interface *intf,
s->usbdev = usbdev; s->usbdev = usbdev;
s->devnum = intf->minor; s->devnum = intf->minor;
if (usb_reset_configuration (usbdev) < 0) { if (usb_reset_configuration(usbdev) < 0) {
dev_err(&intf->dev, "reset_configuration failed\n"); dev_err(&intf->dev, "reset_configuration failed\n");
goto reject; goto reject;
} }
if (le16_to_cpu(usbdev->descriptor.idProduct) == 0x2131) { if (le16_to_cpu(usbdev->descriptor.idProduct) == 0x2131) {
dabusb_loadmem (s, NULL); dabusb_loadmem(s, NULL);
goto reject; goto reject;
} } else {
else { dabusb_fpga_download(s, NULL);
dabusb_fpga_download (s, NULL);
if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0) { if (usb_set_interface(s->usbdev, _DABUSB_IF, 0) < 0) {
dev_err(&intf->dev, "set_interface failed\n"); dev_err(&intf->dev, "set_interface failed\n");
goto reject; goto reject;
} }
} }
dbg("bound to interface: %d", intf->altsetting->desc.bInterfaceNumber); dbg("bound to interface: %d", intf->altsetting->desc.bInterfaceNumber);
usb_set_intfdata (intf, s); usb_set_intfdata(intf, s);
mutex_unlock(&s->mutex); mutex_unlock(&s->mutex);
retval = usb_register_dev(intf, &dabusb_class); retval = usb_register_dev(intf, &dabusb_class);
if (retval) { if (retval) {
usb_set_intfdata (intf, NULL); usb_set_intfdata(intf, NULL);
return -ENOMEM; return -ENOMEM;
} }
return 0; return 0;
reject: reject:
mutex_unlock(&s->mutex); mutex_unlock(&s->mutex);
s->usbdev = NULL; s->usbdev = NULL;
return -ENODEV; return -ENODEV;
} }
static void dabusb_disconnect (struct usb_interface *intf) static void dabusb_disconnect(struct usb_interface *intf)
{ {
wait_queue_t __wait; wait_queue_t __wait;
pdabusb_t s = usb_get_intfdata (intf); pdabusb_t s = usb_get_intfdata(intf);
dbg("dabusb_disconnect"); dbg("dabusb_disconnect");
init_waitqueue_entry(&__wait, current); init_waitqueue_entry(&__wait, current);
usb_set_intfdata (intf, NULL); usb_set_intfdata(intf, NULL);
if (s) { if (s) {
usb_deregister_dev (intf, &dabusb_class); usb_deregister_dev(intf, &dabusb_class);
s->remove_pending = 1; s->remove_pending = 1;
wake_up (&s->wait); wake_up(&s->wait);
add_wait_queue(&s->remove_ok, &__wait); add_wait_queue(&s->remove_ok, &__wait);
set_current_state(TASK_UNINTERRUPTIBLE); set_current_state(TASK_UNINTERRUPTIBLE);
if (s->state == _started) if (s->state == _started)
...@@ -840,13 +852,13 @@ static void dabusb_disconnect (struct usb_interface *intf) ...@@ -840,13 +852,13 @@ static void dabusb_disconnect (struct usb_interface *intf)
} }
} }
static struct usb_device_id dabusb_ids [] = { static struct usb_device_id dabusb_ids[] = {
// { USB_DEVICE(0x0547, 0x2131) }, /* An2131 chip, no boot ROM */ /* { USB_DEVICE(0x0547, 0x2131) },*/ /* An2131 chip, no boot ROM */
{ USB_DEVICE(0x0547, 0x9999) }, { USB_DEVICE(0x0547, 0x9999) },
{ } /* Terminating entry */ { } /* Terminating entry */
}; };
MODULE_DEVICE_TABLE (usb, dabusb_ids); MODULE_DEVICE_TABLE(usb, dabusb_ids);
static struct usb_driver dabusb_driver = { static struct usb_driver dabusb_driver = {
.name = "dabusb", .name = "dabusb",
...@@ -857,7 +869,7 @@ static struct usb_driver dabusb_driver = { ...@@ -857,7 +869,7 @@ static struct usb_driver dabusb_driver = {
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int __init dabusb_init (void) static int __init dabusb_init(void)
{ {
int retval; int retval;
unsigned u; unsigned u;
...@@ -865,15 +877,15 @@ static int __init dabusb_init (void) ...@@ -865,15 +877,15 @@ static int __init dabusb_init (void)
/* initialize struct */ /* initialize struct */
for (u = 0; u < NRDABUSB; u++) { for (u = 0; u < NRDABUSB; u++) {
pdabusb_t s = &dabusb[u]; pdabusb_t s = &dabusb[u];
memset (s, 0, sizeof (dabusb_t)); memset(s, 0, sizeof(dabusb_t));
mutex_init (&s->mutex); mutex_init(&s->mutex);
s->usbdev = NULL; s->usbdev = NULL;
s->total_buffer_size = buffers; s->total_buffer_size = buffers;
init_waitqueue_head (&s->wait); init_waitqueue_head(&s->wait);
init_waitqueue_head (&s->remove_ok); init_waitqueue_head(&s->remove_ok);
spin_lock_init (&s->lock); spin_lock_init(&s->lock);
INIT_LIST_HEAD (&s->free_buff_list); INIT_LIST_HEAD(&s->free_buff_list);
INIT_LIST_HEAD (&s->rec_buff_list); INIT_LIST_HEAD(&s->rec_buff_list);
} }
/* register misc device */ /* register misc device */
...@@ -890,25 +902,25 @@ static int __init dabusb_init (void) ...@@ -890,25 +902,25 @@ static int __init dabusb_init (void)
return retval; return retval;
} }
static void __exit dabusb_cleanup (void) static void __exit dabusb_cleanup(void)
{ {
dbg("dabusb_cleanup"); dbg("dabusb_cleanup");
usb_deregister (&dabusb_driver); usb_deregister(&dabusb_driver);
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
MODULE_AUTHOR( DRIVER_AUTHOR ); MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION( DRIVER_DESC ); MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_FIRMWARE("dabusb/firmware.fw"); MODULE_FIRMWARE("dabusb/firmware.fw");
MODULE_FIRMWARE("dabusb/bitstream.bin"); MODULE_FIRMWARE("dabusb/bitstream.bin");
module_param(buffers, int, 0); module_param(buffers, int, 0);
MODULE_PARM_DESC (buffers, "Number of buffers (default=256)"); MODULE_PARM_DESC(buffers, "Number of buffers (default=256)");
module_init (dabusb_init); module_init(dabusb_init);
module_exit (dabusb_cleanup); module_exit(dabusb_cleanup);
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define _BULK_DATA_LEN 64 #define _BULK_DATA_LEN 64
typedef struct typedef struct {
{
unsigned char data[_BULK_DATA_LEN]; unsigned char data[_BULK_DATA_LEN];
unsigned int size; unsigned int size;
unsigned int pipe; unsigned int pipe;
}bulk_transfer_t,*pbulk_transfer_t; } bulk_transfer_t, *pbulk_transfer_t;
#define DABUSB_MINOR 240 /* some unassigned USB minor */ #define DABUSB_MINOR 240 /* some unassigned USB minor */
#define DABUSB_VERSION 0x1000 #define DABUSB_VERSION 0x1000
...@@ -14,10 +13,9 @@ typedef struct ...@@ -14,10 +13,9 @@ typedef struct
#ifdef __KERNEL__ #ifdef __KERNEL__
typedef enum { _stopped=0, _started } driver_state_t; typedef enum { _stopped = 0, _started } driver_state_t;
typedef struct typedef struct {
{
struct mutex mutex; struct mutex mutex;
struct usb_device *usbdev; struct usb_device *usbdev;
wait_queue_head_t wait; wait_queue_head_t wait;
...@@ -34,17 +32,15 @@ typedef struct ...@@ -34,17 +32,15 @@ typedef struct
int devnum; int devnum;
struct list_head free_buff_list; struct list_head free_buff_list;
struct list_head rec_buff_list; struct list_head rec_buff_list;
} dabusb_t,*pdabusb_t; } dabusb_t, *pdabusb_t;
typedef struct typedef struct {
{
pdabusb_t s; pdabusb_t s;
struct urb *purb; struct urb *purb;
struct list_head buff_list; struct list_head buff_list;
} buff_t,*pbuff_t; } buff_t, *pbuff_t;
typedef struct typedef struct {
{
wait_queue_head_t wait; wait_queue_head_t wait;
} bulk_completion_context_t, *pbulk_completion_context_t; } bulk_completion_context_t, *pbulk_completion_context_t;
...@@ -54,11 +50,11 @@ typedef struct ...@@ -54,11 +50,11 @@ typedef struct
#define _ISOPIPESIZE 16384 #define _ISOPIPESIZE 16384
#define _BULK_DATA_LEN 64 #define _BULK_DATA_LEN 64
// Vendor specific request code for Anchor Upload/Download /* Vendor specific request code for Anchor Upload/Download
// This one is implemented in the core *This one is implemented in the core */
#define ANCHOR_LOAD_INTERNAL 0xA0 #define ANCHOR_LOAD_INTERNAL 0xA0
// EZ-USB Control and Status Register. Bit 0 controls 8051 reset /* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
#define CPUCS_REG 0x7F92 #define CPUCS_REG 0x7F92
#define _TOTAL_BUFFERS 384 #define _TOTAL_BUFFERS 384
...@@ -67,15 +63,14 @@ typedef struct ...@@ -67,15 +63,14 @@ typedef struct
#ifndef _BYTE_DEFINED #ifndef _BYTE_DEFINED
#define _BYTE_DEFINED #define _BYTE_DEFINED
typedef unsigned char BYTE; typedef unsigned char BYTE;
#endif // !_BYTE_DEFINED #endif /* !_BYTE_DEFINED */
#ifndef _WORD_DEFINED #ifndef _WORD_DEFINED
#define _WORD_DEFINED #define _WORD_DEFINED
typedef unsigned short WORD; typedef unsigned short WORD;
#endif // !_WORD_DEFINED #endif /* !_WORD_DEFINED */
typedef struct _INTEL_HEX_RECORD typedef struct _INTEL_HEX_RECORD {
{
BYTE Length; BYTE Length;
WORD Address; WORD Address;
BYTE Type; BYTE Type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment