Lines Matching +full:fifo +full:- +full:depth +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0+
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 1997-2002 David A. Schleef <ds@schleef.org>
11 * The PCI-MIO E series driver was originally written by
18 * DAQ-STC reference manual
27 * 321791a.pdf discontinuation of at-mio-16e-10 rev. c
28 * 321808a.pdf about at-mio-16e-10 rev P
29 * 321837a.pdf discontinuation of at-mio-16de-10 rev d
30 * 321838a.pdf about at-mio-16de-10 rev N
73 #define CHOR_ABORT BIT(3) /* stop without emptying fifo */
74 #define CHOR_STOP BIT(2) /* stop after emptying fifo */
162 #define MITE_FCR(x) (0x40 + MITE_CHAN(x)) /* fifo count */
164 /* common bits for the memory/device/link config registers */
186 return (ilog2(size) - 1) & 0x1f; in MITE_IODWBSR_1_WSIZE_bits()
202 /* This also works on m-series when using channels (drq_line) 4 or 5. */ in mite_drq_reqs()
208 unsigned int fcr_bits = readl(mite->mmio + MITE_FCR(channel)); in mite_fifo_size()
217 struct mite *mite = mite_chan->mite; in mite_device_bytes_transferred()
219 return readl(mite->mmio + MITE_DAR(mite_chan->channel)); in mite_device_bytes_transferred()
223 * mite_bytes_in_transit() - Returns the number of unread bytes in the fifo.
228 struct mite *mite = mite_chan->mite; in mite_bytes_in_transit()
230 return readl(mite->mmio + MITE_FCR(mite_chan->channel)) & 0xff; in mite_bytes_in_transit()
240 return device_byte_count - mite_bytes_in_transit(mite_chan); in mite_bytes_written_to_memory_lb()
249 return mite_device_bytes_transferred(mite_chan) - in_transit_count; in mite_bytes_written_to_memory_ub()
273 struct comedi_async *async = s->async; in mite_sync_input_dma()
277 old_alloc_count = async->buf_write_alloc_count; in mite_sync_input_dma()
279 comedi_buf_write_alloc(s, async->prealloc_bufsz); in mite_sync_input_dma()
282 if ((int)(mite_bytes_written_to_memory_ub(mite_chan) - in mite_sync_input_dma()
284 dev_warn(s->device->class_dev, in mite_sync_input_dma()
286 async->events |= COMEDI_CB_OVERFLOW; in mite_sync_input_dma()
290 count = nbytes - async->buf_write_count; in mite_sync_input_dma()
298 async->events |= COMEDI_CB_BLOCK; in mite_sync_input_dma()
305 struct comedi_async *async = s->async; in mite_sync_output_dma()
306 struct comedi_cmd *cmd = &async->cmd; in mite_sync_output_dma()
307 u32 stop_count = cmd->stop_arg * comedi_bytes_per_scan(s); in mite_sync_output_dma()
308 unsigned int old_alloc_count = async->buf_read_alloc_count; in mite_sync_output_dma()
311 bool finite_regen = (cmd->stop_src == TRIG_NONE && stop_count != 0); in mite_sync_output_dma()
314 comedi_buf_read_alloc(s, async->prealloc_bufsz); in mite_sync_output_dma()
316 if (cmd->stop_src == TRIG_COUNT && (int)(nbytes_lb - stop_count) > 0) in mite_sync_output_dma()
319 if (cmd->stop_src == TRIG_COUNT && (int)(nbytes_ub - stop_count) > 0) in mite_sync_output_dma()
323 ((int)(nbytes_ub - old_alloc_count) > 0)) { in mite_sync_output_dma()
324 dev_warn(s->device->class_dev, "mite: DMA underrun\n"); in mite_sync_output_dma()
325 async->events |= COMEDI_CB_OVERFLOW; in mite_sync_output_dma()
339 count = nbytes_lb - async->buf_read_count; in mite_sync_output_dma()
342 async->events |= COMEDI_CB_BLOCK; in mite_sync_output_dma()
347 * mite_sync_dma() - Sync the MITE dma with the COMEDI async buffer.
353 if (mite_chan->dir == COMEDI_INPUT) in mite_sync_dma()
362 struct mite *mite = mite_chan->mite; in mite_get_status()
366 spin_lock_irqsave(&mite->lock, flags); in mite_get_status()
367 status = readl(mite->mmio + MITE_CHSR(mite_chan->channel)); in mite_get_status()
369 mite_chan->done = 1; in mite_get_status()
371 mite->mmio + MITE_CHOR(mite_chan->channel)); in mite_get_status()
373 spin_unlock_irqrestore(&mite->lock, flags); in mite_get_status()
378 * mite_ack_linkc() - Check and ack the LINKC interrupt,
389 struct mite *mite = mite_chan->mite; in mite_ack_linkc()
394 writel(CHOR_CLRLC, mite->mmio + MITE_CHOR(mite_chan->channel)); in mite_ack_linkc()
401 dev_err(s->device->class_dev, in mite_ack_linkc()
403 s->async->events |= COMEDI_CB_ERROR; in mite_ack_linkc()
409 * mite_done() - Check is a MITE dma transfer is complete.
416 struct mite *mite = mite_chan->mite; in mite_done()
421 spin_lock_irqsave(&mite->lock, flags); in mite_done()
422 done = mite_chan->done; in mite_done()
423 spin_unlock_irqrestore(&mite->lock, flags); in mite_done()
431 mite_chan->mite->mmio + MITE_CHOR(mite_chan->channel)); in mite_dma_reset()
435 * mite_dma_arm() - Start a MITE dma transfer.
440 struct mite *mite = mite_chan->mite; in mite_dma_arm()
448 spin_lock_irqsave(&mite->lock, flags); in mite_dma_arm()
449 mite_chan->done = 0; in mite_dma_arm()
451 writel(CHOR_START, mite->mmio + MITE_CHOR(mite_chan->channel)); in mite_dma_arm()
452 spin_unlock_irqrestore(&mite->lock, flags); in mite_dma_arm()
457 * mite_dma_disarm() - Stop a MITE dma transfer.
462 struct mite *mite = mite_chan->mite; in mite_dma_disarm()
465 writel(CHOR_ABORT, mite->mmio + MITE_CHOR(mite_chan->channel)); in mite_dma_disarm()
470 * mite_prep_dma() - Prepare a MITE dma channel for transfers.
472 * @num_device_bits: device transfer size (8, 16, or 32-bits).
473 * @num_memory_bits: memory transfer size (8, 16, or 32-bits).
478 struct mite *mite = mite_chan->mite; in mite_prep_dma()
498 * samples into the fifo in the right order. Tested doing 32 bit in mite_prep_dma()
500 * pxi-6281, which has mite version = 1, type = 4. This also in mite_prep_dma()
501 * works for dma reads from the counters on e-series boards. in mite_prep_dma()
505 if (mite_chan->dir == COMEDI_INPUT) in mite_prep_dma()
508 writel(chcr, mite->mmio + MITE_CHCR(mite_chan->channel)); in mite_prep_dma()
526 writel(mcr, mite->mmio + MITE_MCR(mite_chan->channel)); in mite_prep_dma()
530 dcr |= CR_PORTIO | CR_AMDEVICE | mite_drq_reqs(mite_chan->channel); in mite_prep_dma()
545 writel(dcr, mite->mmio + MITE_DCR(mite_chan->channel)); in mite_prep_dma()
548 writel(0, mite->mmio + MITE_DAR(mite_chan->channel)); in mite_prep_dma()
550 /* the link is 32bits */ in mite_prep_dma()
552 writel(lkcr, mite->mmio + MITE_LKCR(mite_chan->channel)); in mite_prep_dma()
555 writel(mite_chan->ring->dma_addr, in mite_prep_dma()
556 mite->mmio + MITE_LKAR(mite_chan->channel)); in mite_prep_dma()
561 * mite_request_channel_in_range() - Request a MITE dma channel.
580 spin_lock_irqsave(&mite->lock, flags); in mite_request_channel_in_range()
582 mite_chan = &mite->channels[i]; in mite_request_channel_in_range()
583 if (!mite_chan->ring) { in mite_request_channel_in_range()
584 mite_chan->ring = ring; in mite_request_channel_in_range()
589 spin_unlock_irqrestore(&mite->lock, flags); in mite_request_channel_in_range()
595 * mite_request_channel() - Request a MITE dma channel.
603 mite->num_channels - 1); in mite_request_channel()
608 * mite_release_channel() - Release a MITE dma channel.
613 struct mite *mite = mite_chan->mite; in mite_release_channel()
617 spin_lock_irqsave(&mite->lock, flags); in mite_release_channel()
618 if (mite_chan->ring) { in mite_release_channel()
629 mite->mmio + MITE_CHCR(mite_chan->channel)); in mite_release_channel()
630 mite_chan->ring = NULL; in mite_release_channel()
632 spin_unlock_irqrestore(&mite->lock, flags); in mite_release_channel()
637 * mite_init_ring_descriptors() - Initialize a MITE dma ring descriptors.
646 * later to re-initialize and shorten the amount of memory that will be
653 struct comedi_async *async = s->async; in mite_init_ring_descriptors()
659 dev_dbg(s->device->class_dev, in mite_init_ring_descriptors()
662 if ((n_full_links + (remainder > 0 ? 1 : 0)) > ring->n_links) { in mite_init_ring_descriptors()
663 dev_err(s->device->class_dev, in mite_init_ring_descriptors()
665 return -ENOMEM; in mite_init_ring_descriptors()
670 desc = &ring->descs[i]; in mite_init_ring_descriptors()
671 desc->count = cpu_to_le32(PAGE_SIZE); in mite_init_ring_descriptors()
672 desc->addr = cpu_to_le32(async->buf_map->page_list[i].dma_addr); in mite_init_ring_descriptors()
673 desc->next = cpu_to_le32(ring->dma_addr + in mite_init_ring_descriptors()
679 desc = &ring->descs[i]; in mite_init_ring_descriptors()
681 desc->count = cpu_to_le32(remainder); in mite_init_ring_descriptors()
682 desc->addr = cpu_to_le32(async->buf_map->page_list[i].dma_addr); in mite_init_ring_descriptors()
685 /* Assign the last link->next to point back to the head of the list. */ in mite_init_ring_descriptors()
686 desc->next = cpu_to_le32(ring->dma_addr); in mite_init_ring_descriptors()
699 struct mite_dma_desc *descs = ring->descs; in mite_free_dma_descs()
702 dma_free_coherent(ring->hw_dev, in mite_free_dma_descs()
703 ring->n_links * sizeof(*descs), in mite_free_dma_descs()
704 descs, ring->dma_addr); in mite_free_dma_descs()
705 ring->descs = NULL; in mite_free_dma_descs()
706 ring->dma_addr = 0; in mite_free_dma_descs()
707 ring->n_links = 0; in mite_free_dma_descs()
712 * mite_buf_change() - COMEDI subdevice (*buf_change) for a MITE dma ring.
718 struct comedi_async *async = s->async; in mite_buf_change()
724 if (async->prealloc_bufsz == 0) in mite_buf_change()
727 n_links = async->prealloc_bufsz >> PAGE_SHIFT; in mite_buf_change()
729 descs = dma_alloc_coherent(ring->hw_dev, in mite_buf_change()
731 &ring->dma_addr, GFP_KERNEL); in mite_buf_change()
733 dev_err(s->device->class_dev, in mite_buf_change()
735 return -ENOMEM; in mite_buf_change()
737 ring->descs = descs; in mite_buf_change()
738 ring->n_links = n_links; in mite_buf_change()
745 * mite_alloc_ring() - Allocate a MITE dma ring.
755 ring->hw_dev = get_device(&mite->pcidev->dev); in mite_alloc_ring()
756 if (!ring->hw_dev) { in mite_alloc_ring()
760 ring->n_links = 0; in mite_alloc_ring()
761 ring->descs = NULL; in mite_alloc_ring()
762 ring->dma_addr = 0; in mite_alloc_ring()
768 * mite_free_ring() - Free a MITE dma ring and its descriptors.
775 put_device(ring->hw_dev); in mite_free_ring()
791 pci_set_master(mite->pcidev); in mite_setup()
793 mite->mmio = pci_ioremap_bar(mite->pcidev, 0); in mite_setup()
794 if (!mite->mmio) in mite_setup()
795 return -ENOMEM; in mite_setup()
797 dev->mmio = pci_ioremap_bar(mite->pcidev, 1); in mite_setup()
798 if (!dev->mmio) in mite_setup()
799 return -ENOMEM; in mite_setup()
800 daq_phys_addr = pci_resource_start(mite->pcidev, 1); in mite_setup()
801 length = pci_resource_len(mite->pcidev, 1); in mite_setup()
804 writel(0, mite->mmio + MITE_IODWBSR); in mite_setup()
805 dev_dbg(dev->class_dev, in mite_setup()
809 mite->mmio + MITE_IODWBSR_1); in mite_setup()
810 writel(0, mite->mmio + MITE_IODWCR_1); in mite_setup()
812 writel(daq_phys_addr | WENAB, mite->mmio + MITE_IODWBSR); in mite_setup()
816 * on a pxi-6281 and a pxi-6713. 6713 powered up with register value in mite_setup()
819 * register, then does a bitwise-or of 0x600 with it and writes it back. in mite_setup()
821 * The bits 0x90180700 in MITE_UNKNOWN_DMA_BURST_REG can be in mite_setup()
822 * written and read back. The bits 0x1f always read as 1. in mite_setup()
825 unknown_dma_burst_bits = readl(mite->mmio + MITE_UNKNOWN_DMA_BURST_REG); in mite_setup()
827 writel(unknown_dma_burst_bits, mite->mmio + MITE_UNKNOWN_DMA_BURST_REG); in mite_setup()
829 csigr_bits = readl(mite->mmio + MITE_CSIGR); in mite_setup()
830 mite->num_channels = CSIGR_TO_DMAC(csigr_bits); in mite_setup()
831 if (mite->num_channels > MAX_MITE_DMA_CHANNELS) { in mite_setup()
832 dev_warn(dev->class_dev, in mite_setup()
834 mite->num_channels, MAX_MITE_DMA_CHANNELS); in mite_setup()
835 mite->num_channels = MAX_MITE_DMA_CHANNELS; in mite_setup()
838 /* get the wpdep bits and convert it to the write port fifo depth */ in mite_setup()
843 dev_dbg(dev->class_dev, in mite_setup()
847 dev_dbg(dev->class_dev, in mite_setup()
848 "mite: num channels = %i, write post fifo depth = %i, wins = %i, iowins = %i\n", in mite_setup()
852 for (i = 0; i < mite->num_channels; i++) { in mite_setup()
853 writel(CHOR_DMARESET, mite->mmio + MITE_CHOR(i)); in mite_setup()
858 mite->mmio + MITE_CHCR(i)); in mite_setup()
860 mite->fifo_size = mite_fifo_size(mite, 0); in mite_setup()
861 dev_dbg(dev->class_dev, "mite: fifo size is %i.\n", mite->fifo_size); in mite_setup()
866 * mite_attach() - Allocate and initialize a MITE device for a comedi driver.
886 spin_lock_init(&mite->lock); in mite_attach()
887 mite->pcidev = pcidev; in mite_attach()
889 mite->channels[i].mite = mite; in mite_attach()
890 mite->channels[i].channel = i; in mite_attach()
891 mite->channels[i].done = 1; in mite_attach()
896 if (mite->mmio) in mite_attach()
897 iounmap(mite->mmio); in mite_attach()
907 * mite_detach() - Unmap and free a MITE device for a comedi driver.
917 if (mite->mmio) in mite_detach()
918 iounmap(mite->mmio); in mite_detach()