#define COSA_MAX_ID_STRING 128
/* Maximum length of the channel name */
-#define COSA_MAX_NAME (sizeof("cosaXXXcXXX")+1)
+#define COSA_MAX_NAME (sizeof("cosaXXXcXXX") + 1)
/* Per-channel data structure */
#undef DEBUG_IRQS //1 /* Print the message when the IRQ is received */
#undef DEBUG_IO //1 /* Dump the I/O traffic */
-#define TX_TIMEOUT (5*HZ)
+#define TX_TIMEOUT (5 * HZ)
/* Maybe the following should be allocated dynamically */
static struct cosa_data cosa_cards[MAX_CARDS];
static int nr_cards;
#ifdef COSA_ISA_AUTOPROBE
-static int io[MAX_CARDS+1] = { 0x220, 0x228, 0x210, 0x218, 0, };
+static int io[MAX_CARDS + 1] = {0x220, 0x228, 0x210, 0x218, 0,};
/* NOTE: DMA is not autoprobed!!! */
-static int dma[MAX_CARDS+1] = { 1, 7, 1, 7, 1, 7, 1, 7, 0, };
+static int dma[MAX_CARDS + 1] = {1, 7, 1, 7, 1, 7, 1, 7, 0,};
#else
-static int io[MAX_CARDS+1];
-static int dma[MAX_CARDS+1];
+static int io[MAX_CARDS + 1];
+static int dma[MAX_CARDS + 1];
#endif
/* IRQ can be safely autoprobed */
-static int irq[MAX_CARDS+1] = { -1, -1, -1, -1, -1, -1, 0, };
+static int irq[MAX_CARDS + 1] = {-1, -1, -1, -1, -1, -1, 0,};
/* for class stuff*/
static struct class *cosa_class;
goto out;
}
}
- for (i=0; i<MAX_CARDS; i++)
+ for (i = 0; i < MAX_CARDS; i++)
cosa_cards[i].num = -1;
- for (i=0; io[i] != 0 && i < MAX_CARDS; i++)
+ for (i = 0; io[i] != 0 && i < MAX_CARDS; i++)
cosa_probe(io[i], irq[i], dma[i]);
if (!nr_cards) {
pr_warn("no devices found\n");
static int cosa_probe(int base, int irq, int dma)
{
- struct cosa_data *cosa = cosa_cards+nr_cards;
+ struct cosa_data *cosa = cosa_cards + nr_cards;
int i, err = 0;
memset(cosa, 0, sizeof(struct cosa_data));
cosa->dma = dma;
cosa->datareg = base;
- cosa->statusreg = is_8bit(cosa)?base+1:base+2;
+ cosa->statusreg = is_8bit(cosa) ? base + 1 : base + 2;
spin_lock_init(&cosa->lock);
- if (!request_region(base, is_8bit(cosa)?2:4,"cosa"))
+ if (!request_region(base, is_8bit(cosa) ? 2 : 4, "cosa"))
return -1;
if (cosa_reset_and_read_id(cosa, cosa->id_string) < 0) {
if (!strncmp(cosa->id_string, "SRP", 3)) {
cosa->type = "srp";
} else if (!strncmp(cosa->id_string, "COSA", 4)) {
- cosa->type = is_8bit(cosa)? "cosa8": "cosa16";
+ cosa->type = is_8bit(cosa) ? "cosa8" : "cosa16";
} else {
/* Print a warning only if we are not autoprobing */
#ifndef COSA_ISA_AUTOPROBE
goto err_out;
}
/* Update the name of the region now we know the type of card */
- release_region(base, is_8bit(cosa)?2:4);
- if (!request_region(base, is_8bit(cosa)?2:4, cosa->type)) {
+ release_region(base, is_8bit(cosa) ? 2 : 4);
+ if (!request_region(base, is_8bit(cosa) ? 2 : 4, cosa->type)) {
printk(KERN_DEBUG "changing name at 0x%x failed.\n", base);
return -1;
}
goto err_out1;
}
- cosa->bouncebuf = kmalloc(COSA_MTU, GFP_KERNEL|GFP_DMA);
+ cosa->bouncebuf = kmalloc(COSA_MTU, GFP_KERNEL | GFP_DMA);
if (!cosa->bouncebuf) {
err = -ENOMEM;
goto err_out2;
err_out1:
free_irq(cosa->irq, cosa);
err_out:
- release_region(cosa->datareg,is_8bit(cosa)?2:4);
+ release_region(cosa->datareg, is_8bit(cosa) ? 2 : 4);
pr_notice("cosa%d: allocating resources failed\n", cosa->num);
return err;
}
if (mutex_lock_interruptible(&chan->rlock))
return -ERESTARTSYS;
- chan->rxdata = kmalloc(COSA_MTU, GFP_DMA|GFP_KERNEL);
+ chan->rxdata = kmalloc(COSA_MTU, GFP_DMA | GFP_KERNEL);
if (!chan->rxdata) {
mutex_unlock(&chan->rlock);
return -ENOMEM;
count = COSA_MTU;
/* Allocate the buffer */
- kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA);
+ kbuf = kmalloc(count, GFP_KERNEL | GFP_DMA);
if (!kbuf) {
up(&chan->wsem);
return -ENOMEM;
kfree(kbuf);
return -EFAULT;
}
- chan->tx_status=0;
+ chan->tx_status = 0;
cosa_start_tx(chan, kbuf, count);
spin_lock_irqsave(&cosa->lock, flags);
ret = -ENODEV;
goto out;
}
- cosa = cosa_cards+n;
+ cosa = cosa_cards + n;
n = iminor(file_inode(file)) & ((1 << CARD_MINOR_BITS) - 1);
if (n >= cosa->nchannels) {
if (cosa->usage > 1)
pr_info("cosa%d: WARNING: reset requested with cosa->usage > 1 (%d). Odd things may happen.\n",
cosa->num, cosa->usage);
- cosa->firmware_status &= ~(COSA_FW_RESET|COSA_FW_START);
+ cosa->firmware_status &= ~(COSA_FW_RESET | COSA_FW_START);
if (cosa_reset_and_read_id(cosa, idstring) < 0) {
pr_notice("cosa%d: reset failed\n", cosa->num);
return -EIO;
return -EINVAL;
/* If something fails, force the user to reset the card */
- cosa->firmware_status &= ~(COSA_FW_RESET|COSA_FW_DOWNLOAD);
+ cosa->firmware_status &= ~(COSA_FW_RESET | COSA_FW_DOWNLOAD);
i = download(cosa, d.code, d.len, d.addr);
if (i < 0) {
}
pr_info("cosa%d: downloading microcode - 0x%04x bytes at 0x%04x\n",
cosa->num, d.len, d.addr);
- cosa->firmware_status |= COSA_FW_RESET|COSA_FW_DOWNLOAD;
+ cosa->firmware_status |= COSA_FW_RESET | COSA_FW_DOWNLOAD;
return 0;
}
pr_info("cosa%d: WARNING: start microcode requested with cosa->usage > 1 (%d). Odd things may happen.\n",
cosa->num, cosa->usage);
- if ((cosa->firmware_status & (COSA_FW_RESET|COSA_FW_DOWNLOAD))
- != (COSA_FW_RESET|COSA_FW_DOWNLOAD)) {
+ if ((cosa->firmware_status & (COSA_FW_RESET | COSA_FW_DOWNLOAD))
+ != (COSA_FW_RESET | COSA_FW_DOWNLOAD)) {
pr_notice("%s: download the microcode and/or reset the card first (status %d)\n",
cosa->name, cosa->firmware_status);
return -EPERM;
/* Buffer of size at least COSA_MAX_ID_STRING is expected */
static inline int cosa_getidstr(struct cosa_data *cosa, char __user *string)
{
- int l = strlen(cosa->id_string)+1;
+ int l = strlen(cosa->id_string) + 1;
if (copy_to_user(string, cosa->id_string, l))
return -EFAULT;
/* Buffer of size at least COSA_MAX_ID_STRING is expected */
static inline int cosa_gettype(struct cosa_data *cosa, char __user *string)
{
- int l = strlen(cosa->type)+1;
+ int l = strlen(cosa->type) + 1;
if (copy_to_user(string, cosa->type, l))
return -EFAULT;
pr_info("cosa%dc%d: starting tx(0x%x)",
chan->cosa->num, chan->num, len);
- for (i=0; i<len; i++)
+ for (i = 0; i < len; i++)
pr_cont(" %02x", buf[i]&0xff);
pr_cont("\n");
#endif
status = (cosa->rxbitmap ? DRIVER_RX_READY : 0)
| (cosa->txbitmap ? DRIVER_TX_READY : 0)
- | (cosa->txbitmap? ~(cosa->txbitmap<<DRIVER_TXMAP_SHIFT)
- &DRIVER_TXMAP_MASK : 0);
+ | (cosa->txbitmap ? ~(cosa->txbitmap << DRIVER_TXMAP_SHIFT)
+ & DRIVER_TXMAP_MASK : 0);
if (!cosa->rxtx) {
- if (cosa->rxbitmap|cosa->txbitmap) {
+ if (cosa->rxbitmap | cosa->txbitmap) {
if (!cosa->enabled) {
cosa_putstatus(cosa, SR_RX_INT_ENA);
#ifdef DEBUG_IO
status = (cosa->rxbitmap ? DRIVER_RX_READY : 0)
| (cosa->txbitmap ? DRIVER_TX_READY : 0)
- | (cosa->txbitmap? ~(cosa->txbitmap<<DRIVER_TXMAP_SHIFT)
- &DRIVER_TXMAP_MASK : 0);
+ | (cosa->txbitmap ? ~(cosa->txbitmap << DRIVER_TXMAP_SHIFT)
+ & DRIVER_TXMAP_MASK : 0);
- if (cosa->rxbitmap|cosa->txbitmap) {
+ if (cosa->rxbitmap | cosa->txbitmap) {
cosa_putstatus(cosa, SR_RX_INT_ENA);
#ifdef DEBUG_IO
debug_status_out(cosa, SR_RX_INT_ENA);
static int count;
unsigned long b = (unsigned long)buf;
- if (b+len >= MAX_DMA_ADDRESS)
+ if (b + len >= MAX_DMA_ADDRESS)
return 0;
- if ((b^ (b+len)) & 0x10000) {
+ if ((b ^ (b + len)) & 0x10000) {
if (count++ < 5)
pr_info("%s: packet spanning a 64k boundary\n",
chan->name);
pr_info("0x%04x bytes remaining\n", length);
return -11;
}
- c=i;
+ c = i;
#if 1
if (put_user(c, microcode))
return -23; /* ??? */
*/
static int cosa_reset_and_read_id(struct cosa_data *cosa, char *idstring)
{
- int i=0, id=0, prev=0, curr=0;
+ int i = 0, id = 0, prev = 0, curr = 0;
/* Reset the card ... */
cosa_putstatus(cosa, 0);
* to avoid looping forever when for any reason
* the port returns '\r', '\n' or '\x2e' permanently.
*/
- for (i=0; i<COSA_MAX_ID_STRING-1; i++, prev=curr) {
+ for (i = 0; i < COSA_MAX_ID_STRING - 1; i++, prev = curr) {
curr = get_wait_data(cosa);
if (curr == -1)
return -1;
r = cosa_getdata8(cosa);
#if 0
pr_info("get_wait_data returning after %d retries\n",
- 999-retries);
+ 999 - retries);
#endif
return r;
}
if (cosa_getstatus(cosa) & SR_TX_RDY) {
cosa_putdata8(cosa, data);
#if 0
- pr_info("Putdata: %d retries\n", 999-retries);
+ pr_info("Putdata: %d retries\n", 999 - retries);
#endif
return 0;
}
/* Well, I should probably replace this by something faster. */
sprintf(temp, "%04X", number);
- for (i=0; i<4; i++) {
+ for (i = 0; i < 4; i++) {
if (put_wait_data(cosa, temp[i]) == -1) {
pr_notice("cosa%d: puthexnumber failed to write byte %d\n",
cosa->num, i);
- return -1-2*i;
+ return -1 - 2 * i;
}
if (get_wait_data(cosa) != temp[i]) {
pr_notice("cosa%d: puthexhumber failed to read echo of byte %d\n",
cosa->num, i);
- return -2-2*i;
+ return -2 - 2 * i;
}
}
return 0;
set_bit(TXBIT, &cosa->rxtx);
if (!test_bit(IRQBIT, &cosa->rxtx)) {
/* flow control, see the comment above */
- int i=0;
+ int i = 0;
if (!cosa->txbitmap) {
pr_warn("%s: No channel wants data in TX IRQ. Expect DMA timeout.\n",
i++;
if (cosa->txchan >= cosa->nchannels)
cosa->txchan = 0;
- if (!(cosa->txbitmap & (1<<cosa->txchan)))
+ if (!(cosa->txbitmap & (1 << cosa->txchan)))
continue;
- if (~status & (1 << (cosa->txchan+DRIVER_TXMAP_SHIFT)))
+ if (~status &
+ (1 << (cosa->txchan + DRIVER_TXMAP_SHIFT)))
break;
/* in second pass, accept first ready-to-TX channel */
if (i > cosa->nchannels) {
}
cosa->txsize = cosa->chan[cosa->txchan].txsize;
- if (cosa_dma_able(cosa->chan+cosa->txchan,
+ if (cosa_dma_able(cosa->chan + cosa->txchan,
cosa->chan[cosa->txchan].txbuf,
cosa->txsize)) {
cosa->txbuf = cosa->chan[cosa->txchan].txbuf;
if (is_8bit(cosa)) {
if (!test_bit(IRQBIT, &cosa->rxtx)) {
cosa_putstatus(cosa, SR_TX_INT_ENA);
- cosa_putdata8(cosa, ((cosa->txchan << 5) & 0xe0)|
+ cosa_putdata8(cosa, ((cosa->txchan << 5) & 0xe0) |
((cosa->txsize >> 8) & 0x1f));
#ifdef DEBUG_IO
debug_status_out(cosa, SR_TX_INT_ENA);
- debug_data_out(cosa, ((cosa->txchan << 5) & 0xe0)|
+ debug_data_out(cosa, ((cosa->txchan << 5) & 0xe0) |
((cosa->txsize >> 8) & 0x1f));
debug_data_in(cosa, cosa_getdata8(cosa));
#else
} else {
clear_bit(IRQBIT, &cosa->rxtx);
cosa_putstatus(cosa, 0);
- cosa_putdata8(cosa, cosa->txsize&0xff);
+ cosa_putdata8(cosa, cosa->txsize & 0xff);
#ifdef DEBUG_IO
debug_status_out(cosa, 0);
- debug_data_out(cosa, cosa->txsize&0xff);
+ debug_data_out(cosa, cosa->txsize & 0xff);
#endif
}
} else {
cosa_putstatus(cosa, SR_TX_INT_ENA);
- cosa_putdata16(cosa, ((cosa->txchan<<13) & 0xe000)
+ cosa_putdata16(cosa, ((cosa->txchan << 13) & 0xe000)
| (cosa->txsize & 0x1fff));
#ifdef DEBUG_IO
debug_status_out(cosa, SR_TX_INT_ENA);
- debug_data_out(cosa, ((cosa->txchan<<13) & 0xe000)
+ debug_data_out(cosa, ((cosa->txchan << 13) & 0xe000)
| (cosa->txsize & 0x1fff));
debug_data_in(cosa, cosa_getdata8(cosa));
debug_status_out(cosa, 0);
if (cosa->busmaster) {
unsigned long addr = virt_to_bus(cosa->txbuf);
- int count=0;
+ int count = 0;
pr_info("busmaster IRQ\n");
- while (!(cosa_getstatus(cosa)&SR_TX_RDY)) {
+ while (!(cosa_getstatus(cosa) & SR_TX_RDY)) {
count++;
udelay(10);
if (count > 1000)
}
pr_info("status %x\n", cosa_getstatus(cosa));
pr_info("ready after %d loops\n", count);
- cosa_putdata16(cosa, (addr >> 16)&0xffff);
+ cosa_putdata16(cosa, (addr >> 16) & 0xffff);
count = 0;
- while (!(cosa_getstatus(cosa)&SR_TX_RDY)) {
+ while (!(cosa_getstatus(cosa) & SR_TX_RDY)) {
count++;
if (count > 1000)
break;
udelay(10);
}
pr_info("ready after %d loops\n", count);
- cosa_putdata16(cosa, addr &0xffff);
+ cosa_putdata16(cosa, addr & 0xffff);
flags1 = claim_dma_lock();
set_dma_mode(cosa->dma, DMA_MODE_CASCADE);
enable_dma(cosa->dma);
enable_dma(cosa->dma);
release_dma_lock(flags1);
}
- cosa_putstatus(cosa, SR_TX_DMA_ENA|SR_USR_INT_ENA);
+ cosa_putstatus(cosa, SR_TX_DMA_ENA | SR_USR_INT_ENA);
#ifdef DEBUG_IO
- debug_status_out(cosa, SR_TX_DMA_ENA|SR_USR_INT_ENA);
+ debug_status_out(cosa, SR_TX_DMA_ENA | SR_USR_INT_ENA);
#endif
spin_unlock_irqrestore(&cosa->lock, flags);
}
if (!test_bit(IRQBIT, &cosa->rxtx)) {
set_bit(IRQBIT, &cosa->rxtx);
put_driver_status_nolock(cosa);
- cosa->rxsize = cosa_getdata8(cosa) <<8;
+ cosa->rxsize = cosa_getdata8(cosa) << 8;
#ifdef DEBUG_IO
debug_data_in(cosa, cosa->rxsize >> 8);
#endif
else
set_dma_addr(cosa->dma, virt_to_bus(cosa->bouncebuf));
- set_dma_count(cosa->dma, (cosa->rxsize&0x1fff));
+ set_dma_count(cosa->dma, (cosa->rxsize & 0x1fff));
enable_dma(cosa->dma);
release_dma_lock(flags);
spin_lock_irqsave(&cosa->lock, flags);
- cosa_putstatus(cosa, SR_RX_DMA_ENA|SR_USR_INT_ENA);
+ cosa_putstatus(cosa, SR_RX_DMA_ENA | SR_USR_INT_ENA);
if (!is_8bit(cosa) && (status & SR_TX_RDY))
cosa_putdata8(cosa, DRIVER_RX_READY);
#ifdef DEBUG_IO
- debug_status_out(cosa, SR_RX_DMA_ENA|SR_USR_INT_ENA);
+ debug_status_out(cosa, SR_RX_DMA_ENA | SR_USR_INT_ENA);
if (!is_8bit(cosa) && (status & SR_TX_RDY))
debug_data_cmd(cosa, DRIVER_RX_READY);
#endif
clear_dma_ff(cosa->dma);
release_dma_lock(flags1);
if (test_bit(TXBIT, &cosa->rxtx)) {
- struct channel_data *chan = cosa->chan+cosa->txchan;
+ struct channel_data *chan = cosa->chan + cosa->txchan;
if (chan->tx_done)
if (chan->tx_done(chan, cosa->txsize))
pr_info("cosa%dc%d: done rx(0x%x)",
cosa->num, cosa->rxchan->num, cosa->rxsize);
- for (i=0; i<cosa->rxsize; i++)
+ for (i = 0; i < cosa->rxsize; i++)
pr_cont(" %02x", cosa->rxbuf[i]&0xff);
pr_cont("\n");
}