Lines Matching +full:dma +full:- +full:byte +full:- +full:en

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2010 - Maxim Levitsky
44 * memstick_debug_get_tpc_name - debug helper that returns string for
49 return tpc_names[tpc-1]; in memstick_debug_get_tpc_name()
55 u32 value = readl(dev->mmio + address); in r592_read_reg()
64 dbg_reg("reg #%02d <- 0x%08x", address, value); in r592_write_reg()
65 writel(value, dev->mmio + address); in r592_write_reg()
71 u32 value = __raw_readl(dev->mmio + address); in r592_read_reg_raw_be()
80 dbg_reg("reg #%02d <- 0x%08x", address, value); in r592_write_reg_raw_be()
81 __raw_writel(cpu_to_be32(value), dev->mmio + address); in r592_write_reg_raw_be()
88 u32 reg = readl(dev->mmio + address); in r592_set_reg_mask()
90 writel(reg | mask , dev->mmio + address); in r592_set_reg_mask()
97 u32 reg = readl(dev->mmio + address); in r592_clear_reg_mask()
100 writel(reg & ~mask, dev->mmio + address); in r592_clear_reg_mask()
121 return -EIO; in r592_wait_status()
125 return -ETIME; in r592_wait_status()
132 dbg("%sabling the device", enable ? "en" : "dis"); in r592_enable_device()
174 dev->parallel_mode = parallel_mode; in r592_set_mode()
183 r592_set_mode(dev, dev->parallel_mode); in r592_host_reset()
203 return -EIO; in r592_test_io_error()
219 return -EIO; in r592_test_fifo_empty()
222 /* Activates the DMA transfer from to FIFO */
227 spin_lock_irqsave(&dev->irq_lock, flags); in r592_start_dma()
233 /* Set DMA address */ in r592_start_dma()
234 r592_write_reg(dev, R592_FIFO_DMA, sg_dma_address(&dev->req->sg)); in r592_start_dma()
236 /* Enable the DMA */ in r592_start_dma()
246 spin_unlock_irqrestore(&dev->irq_lock, flags); in r592_start_dma()
249 /* Cleanups DMA related settings */
257 dev->dummy_dma_page_physical_address); in r592_stop_dma()
261 dev->dma_error = error; in r592_stop_dma()
264 /* Test if hardware supports DMA */
267 dev->dma_capable = r592_enable_dma && in r592_check_dma()
272 /* Transfers fifo contents in/out using DMA */
278 if (!dev->dma_capable || !dev->req->long_data) in r592_transfer_fifo_dma()
279 return -EINVAL; in r592_transfer_fifo_dma()
281 len = dev->req->sg.length; in r592_transfer_fifo_dma()
282 is_write = dev->req->data_dir == WRITE; in r592_transfer_fifo_dma()
285 return -EINVAL; in r592_transfer_fifo_dma()
287 dbg_verbose("doing dma transfer"); in r592_transfer_fifo_dma()
289 dev->dma_error = 0; in r592_transfer_fifo_dma()
290 reinit_completion(&dev->dma_done); in r592_transfer_fifo_dma()
293 sg_count = dma_map_sg(&dev->pci_dev->dev, &dev->req->sg, 1, is_write ? in r592_transfer_fifo_dma()
296 if (sg_count != 1 || sg_dma_len(&dev->req->sg) < R592_LFIFO_SIZE) { in r592_transfer_fifo_dma()
298 return -EIO; in r592_transfer_fifo_dma()
303 /* Wait for DMA completion */ in r592_transfer_fifo_dma()
305 &dev->dma_done, msecs_to_jiffies(1000))) { in r592_transfer_fifo_dma()
306 message("DMA timeout"); in r592_transfer_fifo_dma()
307 r592_stop_dma(dev, -ETIMEDOUT); in r592_transfer_fifo_dma()
310 dma_unmap_sg(&dev->pci_dev->dev, &dev->req->sg, 1, is_write ? in r592_transfer_fifo_dma()
313 return dev->dma_error; in r592_transfer_fifo_dma()
317 * Writes the FIFO in 4 byte chunks.
318 * If length isn't 4 byte aligned, rest of the data if put to a fifo
327 if (!kfifo_is_empty(&dev->pio_fifo)) { in r592_write_fifo_pio()
330 int copy_len = kfifo_in(&dev->pio_fifo, buffer, len); in r592_write_fifo_pio()
332 if (!kfifo_is_full(&dev->pio_fifo)) in r592_write_fifo_pio()
334 len -= copy_len; in r592_write_fifo_pio()
337 copy_len = kfifo_out(&dev->pio_fifo, tmp, 4); in r592_write_fifo_pio()
342 WARN_ON(!kfifo_is_empty(&dev->pio_fifo)); in r592_write_fifo_pio()
348 len -= 4; in r592_write_fifo_pio()
353 kfifo_in(&dev->pio_fifo, buffer, len); in r592_write_fifo_pio()
362 if (kfifo_is_empty(&dev->pio_fifo)) in r592_flush_fifo_write()
365 ret = kfifo_out(&dev->pio_fifo, buffer, 4); in r592_flush_fifo_write()
382 if (!kfifo_is_empty(&dev->pio_fifo)) { in r592_read_fifo_pio()
384 kfifo_out(&dev->pio_fifo, buffer, min(4, len)); in r592_read_fifo_pio()
386 len -= bytes_copied; in r592_read_fifo_pio()
388 if (!kfifo_is_empty(&dev->pio_fifo)) in r592_read_fifo_pio()
396 len -= 4; in r592_read_fifo_pio()
401 kfifo_in(&dev->pio_fifo, tmp, 4); in r592_read_fifo_pio()
402 len -= kfifo_out(&dev->pio_fifo, buffer, len); in r592_read_fifo_pio()
414 bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS; in r592_transfer_fifo_pio()
417 kfifo_reset(&dev->pio_fifo); in r592_transfer_fifo_pio()
419 if (!dev->req->long_data) { in r592_transfer_fifo_pio()
421 r592_write_fifo_pio(dev, dev->req->data, in r592_transfer_fifo_pio()
422 dev->req->data_len); in r592_transfer_fifo_pio()
425 r592_read_fifo_pio(dev, dev->req->data, in r592_transfer_fifo_pio()
426 dev->req->data_len); in r592_transfer_fifo_pio()
431 sg_miter_start(&miter, &dev->req->sg, 1, SG_MITER_ATOMIC | in r592_transfer_fifo_pio()
434 /* Do the transfer fifo<->memory*/ in r592_transfer_fifo_pio()
458 if (!dev->req) { in r592_execute_tpc()
463 is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS; in r592_execute_tpc()
464 len = dev->req->long_data ? in r592_execute_tpc()
465 dev->req->sg.length : dev->req->data_len; in r592_execute_tpc()
470 error = -ENOSYS; in r592_execute_tpc()
476 error = -ENODEV; in r592_execute_tpc()
481 memstick_debug_get_tpc_name(dev->req->tpc), len); in r592_execute_tpc()
497 if (error == -EINVAL) in r592_execute_tpc()
506 (dev->req->tpc << R592_TPC_EXEC_TPC_SHIFT) | in r592_execute_tpc()
513 if (dev->req->need_card_int) in r592_execute_tpc()
532 if (error == -EINVAL) in r592_execute_tpc()
538 if (dev->parallel_mode && dev->req->need_card_int) { in r592_execute_tpc()
540 dev->req->int_reg = 0; in r592_execute_tpc()
544 dev->req->int_reg |= MEMSTICK_INT_CMDNAK; in r592_execute_tpc()
546 dev->req->int_reg |= MEMSTICK_INT_BREQ; in r592_execute_tpc()
548 dev->req->int_reg |= MEMSTICK_INT_ERR; in r592_execute_tpc()
550 dev->req->int_reg |= MEMSTICK_INT_CED; in r592_execute_tpc()
556 dev->req->error = error; in r592_execute_tpc()
569 spin_lock_irqsave(&dev->io_thread_lock, flags); in r592_process_thread()
571 error = memstick_next_req(dev->host, &dev->req); in r592_process_thread()
572 spin_unlock_irqrestore(&dev->io_thread_lock, flags); in r592_process_thread()
575 if (error == -ENXIO || error == -EAGAIN) { in r592_process_thread()
619 memstick_detect_change(dev->host); in r592_detect_timer()
632 spin_lock_irqsave(&dev->irq_lock, flags); in r592_irq()
654 mod_timer(&dev->detect_timer, in r592_irq()
663 message("IRQ: DMA error"); in r592_irq()
664 error = -EIO; in r592_irq()
666 dbg_verbose("IRQ: dma done"); in r592_irq()
671 complete(&dev->dma_done); in r592_irq()
674 spin_unlock_irqrestore(&dev->irq_lock, flags); in r592_irq()
692 return -EINVAL; in r592_set_param()
701 return -EINVAL; in r592_set_param()
704 return -EINVAL; in r592_set_param()
714 if (dev->req) in r592_submit_req()
717 spin_lock_irqsave(&dev->io_thread_lock, flags); in r592_submit_req()
718 if (wake_up_process(dev->io_thread)) in r592_submit_req()
720 spin_unlock_irqrestore(&dev->io_thread_lock, flags); in r592_submit_req()
732 int error = -ENOMEM; in r592_probe()
737 host = memstick_alloc_host(sizeof(struct r592_device), &pdev->dev); in r592_probe()
742 dev->host = host; in r592_probe()
743 dev->pci_dev = pdev; in r592_probe()
752 error = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); in r592_probe()
760 dev->mmio = pci_ioremap_bar(pdev, 0); in r592_probe()
761 if (!dev->mmio) { in r592_probe()
762 error = -ENOMEM; in r592_probe()
766 dev->irq = pdev->irq; in r592_probe()
767 spin_lock_init(&dev->irq_lock); in r592_probe()
768 spin_lock_init(&dev->io_thread_lock); in r592_probe()
769 init_completion(&dev->dma_done); in r592_probe()
770 INIT_KFIFO(dev->pio_fifo); in r592_probe()
771 timer_setup(&dev->detect_timer, r592_detect_timer, 0); in r592_probe()
774 host->caps = MEMSTICK_CAP_PAR4; in r592_probe()
775 host->request = r592_submit_req; in r592_probe()
776 host->set_param = r592_set_param; in r592_probe()
779 dev->io_thread = kthread_run(r592_process_thread, dev, "r592_io"); in r592_probe()
780 if (IS_ERR(dev->io_thread)) { in r592_probe()
781 error = PTR_ERR(dev->io_thread); in r592_probe()
786 dev->dummy_dma_page = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, in r592_probe()
787 &dev->dummy_dma_page_physical_address, GFP_KERNEL); in r592_probe()
790 error = request_irq(dev->irq, &r592_irq, IRQF_SHARED, in r592_probe()
803 free_irq(dev->irq, dev); in r592_probe()
805 if (dev->dummy_dma_page) in r592_probe()
806 dma_free_coherent(&pdev->dev, PAGE_SIZE, dev->dummy_dma_page, in r592_probe()
807 dev->dummy_dma_page_physical_address); in r592_probe()
809 kthread_stop(dev->io_thread); in r592_probe()
811 iounmap(dev->mmio); in r592_probe()
829 kthread_stop(dev->io_thread); in r592_remove()
830 del_timer_sync(&dev->detect_timer); in r592_remove()
833 while (!error && dev->req) { in r592_remove()
834 dev->req->error = -ETIME; in r592_remove()
835 error = memstick_next_req(dev->host, &dev->req); in r592_remove()
837 memstick_remove_host(dev->host); in r592_remove()
839 if (dev->dummy_dma_page) in r592_remove()
840 dma_free_coherent(&pdev->dev, PAGE_SIZE, dev->dummy_dma_page, in r592_remove()
841 dev->dummy_dma_page_physical_address); in r592_remove()
843 free_irq(dev->irq, dev); in r592_remove()
844 iounmap(dev->mmio); in r592_remove()
847 memstick_free_host(dev->host); in r592_remove()
856 memstick_suspend_host(dev->host); in r592_suspend()
857 del_timer_sync(&dev->detect_timer); in r592_suspend()
867 memstick_resume_host(dev->host); in r592_resume()
888 MODULE_PARM_DESC(enable_dma, "Enable usage of the DMA (default)");
890 MODULE_PARM_DESC(debug, "Debug level (0-3)");