49 #include "../comedidev.h"
67 #define DEBUG_PRINT(format, args...) printk(format , ## args)
69 #define DEBUG_PRINT(format, args...)
73 #define DMA_BUFFER_SIZE 0x10000
74 #define NUM_DMA_BUFFERS 4
75 #define NUM_DMA_DESCRIPTORS 256
109 if (channel == 0 || channel > 6) {
111 "gsc_hpdi: bug! invalid cable command channel\n");
124 return fwr_bits & 0xff;
129 return (fwr_bits >> 8) & 0xff;
134 return (fwr_bits >> 16) & 0xff;
188 return (num_words << 16) & 0xff0000;
193 return num_words & 0xffff;
199 return (bits >> 16) & 0xffff;
204 return bits & 0xffff;
237 return 0x1 << interrupt_source;
242 return divisor & 0xff;
247 return fifo_size_bits & 0xfffff;
252 return fifo_words_bits & 0xfffff;
257 return 0x1 << interrupt_source;
262 return 0x1 << interrupt_source;
272 static const struct hpdi_board hpdi_boards[] = {
274 .name =
"pci-hpdi32",
276 .subdevice_id = 0x2400,
280 .name =
"pxi-hpdi32",
282 .subdevice_id = 0x2705,
335 priv(dev)->dio_config_output = 1;
339 priv(dev)->dio_config_output = 0;
348 return dio_config_block_size(dev, data);
357 static void disable_plx_interrupts(
struct comedi_device *dev)
366 void __iomem *plx_iobase =
priv(dev)->plx9080_iobase;
381 DEBUG_PRINT(
" plx dma channel 0 pci address 0x%x\n",
383 DEBUG_PRINT(
" plx dma channel 0 local address 0x%x\n",
385 DEBUG_PRINT(
" plx dma channel 0 transfer size 0x%x\n",
387 DEBUG_PRINT(
" plx dma channel 0 descriptor 0x%x\n",
389 DEBUG_PRINT(
" plx dma channel 0 command status 0x%x\n",
401 disable_plx_interrupts(dev);
490 unsigned int buffer_index, buffer_offset;
497 transfer_size -= transfer_size %
sizeof(
uint32_t);
498 if (transfer_size == 0)
503 (
unsigned long)
priv(dev)->dma_desc_phys_addr);
509 priv(dev)->dma_desc[
i].pci_start_addr =
513 priv(dev)->dma_desc[
i].transfer_size =
515 priv(dev)->dma_desc[
i].next =
520 priv(dev)->desc_dio_buffer[
i] =
521 priv(dev)->dio_buffer[buffer_index] +
532 priv(dev)->desc_dio_buffer[i],
538 priv(dev)->num_dma_descriptors =
i;
540 priv(dev)->dma_desc[i - 1].next =
558 if (alloc_private(dev,
sizeof(
struct hpdi_private)) < 0)
568 hpdi_boards[i].subdevice_id,
582 }
while (pcidev !=
NULL);
590 "gsc_hpdi: found %s on bus %i, slot %i\n",
board(dev)->
name,
595 " failed enable PCI device and request regions\n");
603 priv(dev)->plx9080_phys_iobase =
605 priv(dev)->hpdi_phys_iobase =
612 priv(dev)->hpdi_iobase =
615 if (!
priv(dev)->plx9080_iobase || !
priv(dev)->hpdi_iobase) {
627 dev->
driver->driver_name, dev)) {
629 " unable to allocate irq %u\n", pcidev->
irq);
638 priv(dev)->dio_buffer[
i] =
640 &
priv(dev)->dio_buffer_phys_addr[i]);
641 DEBUG_PRINT(
"dio_buffer at virt 0x%p, phys 0x%lx\n",
642 priv(dev)->dio_buffer[i],
643 (
unsigned long)
priv(dev)->dio_buffer_phys_addr[i]);
651 if (
priv(dev)->dma_desc_phys_addr & 0xf) {
653 " dma descriptors not quad-word aligned (bug)\n");
657 retval = setup_dma_descriptors(dev, 0x1000);
661 retval = setup_subdevices(dev);
665 return init_hpdi(dev);
674 if ((
priv(dev)) && (
priv(dev)->hw_dev)) {
675 if (
priv(dev)->plx9080_iobase) {
676 disable_plx_interrupts(dev);
679 if (
priv(dev)->hpdi_iobase)
683 if (
priv(dev)->dio_buffer[i])
689 (dev)->dio_buffer_phys_addr
696 * NUM_DMA_DESCRIPTORS,
700 if (
priv(dev)->hpdi_phys_iobase)
706 static int dio_config_block_size(
struct comedi_device *dev,
unsigned int *data)
708 unsigned int requested_block_size;
711 requested_block_size = data[1];
713 retval = setup_dma_descriptors(dev, requested_block_size);
741 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
791 "chanlist must be ch 0 to 31 in order");
806 if (
priv(dev)->dio_config_output)
809 return di_cmd_test(dev, s, cmd);
816 priv(dev)->hpdi_iobase + offset);
832 priv(dev)->dma_desc_index = 0;
852 spin_unlock_irqrestore(&dev->
spinlock, flags);
857 priv(dev)->dio_count = 1;
874 if (
priv(dev)->dio_config_output)
877 return di_cmd(dev, s);
897 for (next_transfer_addr =
readl(pci_addr_reg);
898 (next_transfer_addr <
901 || next_transfer_addr >=
903 pci_start_addr) +
priv(dev)->block_size)
904 && j <
priv(dev)->num_dma_descriptors; j++) {
908 if (num_samples >
priv(dev)->dio_count)
909 num_samples =
priv(dev)->dio_count;
910 priv(dev)->dio_count -= num_samples;
913 priv(dev)->desc_dio_buffer[
priv(dev)->
916 priv(dev)->dma_desc_index++;
917 priv(dev)->dma_desc_index %=
priv(dev)->num_dma_descriptors;
919 DEBUG_PRINT(
"next desc addr 0x%lx\n", (
unsigned long)
922 DEBUG_PRINT(
"pci addr reg 0x%x\n", next_transfer_addr);
932 uint32_t hpdi_intr_status, hpdi_board_status;
935 uint8_t dma0_status, dma1_status;
950 if (hpdi_intr_status) {
951 DEBUG_PRINT(
"hpdi: intr status 0x%x, ", hpdi_intr_status);
963 if (dma0_status & PLX_DMA_EN_BIT)
964 drain_dma_buffers(dev, 0);
967 spin_unlock_irqrestore(&dev->
spinlock, flags);
979 spin_unlock_irqrestore(&dev->
spinlock, flags);
985 DEBUG_PRINT(
" cleared local doorbell bits 0x%x\n", plx_bits);
1001 if (
priv(dev)->dio_count == 0)
1004 DEBUG_PRINT(
"board status 0x%x, ", hpdi_board_status);
1014 static void abort_dma(
struct comedi_device *dev,
unsigned int channel)
1016 unsigned long flags;
1021 plx9080_abort_dma(
priv(dev)->plx9080_iobase, channel);
1023 spin_unlock_irqrestore(&dev->
spinlock, flags);
1038 .driver_name =
"gsc_hpdi",
1040 .attach = hpdi_attach,
1041 .detach = hpdi_detach,
1062 static struct pci_driver gsc_hpdi_pci_driver = {
1064 .id_table = gsc_hpdi_pci_table,
1065 .probe = gsc_hpdi_pci_probe,