Lines Matching +full:toggle +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/dma-mapping.h>
13 #define RNDIS_REG(x) (0x80 + ((x - 1) * 4))
50 unsigned int mode);
57 u8 toggle; in save_rx_toggle() local
59 if (cppi41_channel->is_tx) in save_rx_toggle()
61 if (!is_host_active(cppi41_channel->controller->controller.musb)) in save_rx_toggle()
64 csr = musb_readw(cppi41_channel->hw_ep->regs, MUSB_RXCSR); in save_rx_toggle()
65 toggle = csr & MUSB_RXCSR_H_DATATOGGLE ? 1 : 0; in save_rx_toggle()
67 cppi41_channel->usb_toggle = toggle; in save_rx_toggle()
72 struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; in update_rx_toggle()
73 struct musb *musb = hw_ep->musb; in update_rx_toggle()
75 u8 toggle; in update_rx_toggle() local
77 if (cppi41_channel->is_tx) in update_rx_toggle()
82 musb_ep_select(musb->mregs, hw_ep->epnum); in update_rx_toggle()
83 csr = musb_readw(hw_ep->regs, MUSB_RXCSR); in update_rx_toggle()
84 toggle = csr & MUSB_RXCSR_H_DATATOGGLE ? 1 : 0; in update_rx_toggle()
88 * data toggle may reset from DATA1 to DATA0 during receiving data from in update_rx_toggle()
91 if (!toggle && toggle == cppi41_channel->usb_toggle) { in update_rx_toggle()
93 musb_writew(cppi41_channel->hw_ep->regs, MUSB_RXCSR, csr); in update_rx_toggle()
94 musb_dbg(musb, "Restoring DATA1 toggle."); in update_rx_toggle()
97 cppi41_channel->usb_toggle = toggle; in update_rx_toggle()
102 u8 epnum = hw_ep->epnum; in musb_is_tx_fifo_empty()
103 struct musb *musb = hw_ep->musb; in musb_is_tx_fifo_empty()
104 void __iomem *epio = musb->endpoints[epnum].regs; in musb_is_tx_fifo_empty()
107 musb_ep_select(musb->mregs, hw_ep->epnum); in musb_is_tx_fifo_empty()
119 struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; in cppi41_trans_done()
120 struct musb *musb = hw_ep->musb; in cppi41_trans_done()
121 void __iomem *epio = hw_ep->regs; in cppi41_trans_done()
124 if (!cppi41_channel->prog_len || in cppi41_trans_done()
125 (cppi41_channel->channel.status == MUSB_DMA_STATUS_FREE)) { in cppi41_trans_done()
128 cppi41_channel->channel.actual_len = in cppi41_trans_done()
129 cppi41_channel->transferred; in cppi41_trans_done()
130 cppi41_channel->channel.status = MUSB_DMA_STATUS_FREE; in cppi41_trans_done()
131 cppi41_channel->channel.rx_packet_done = true; in cppi41_trans_done()
134 * transmit ZLP using PIO mode for transfers which size is in cppi41_trans_done()
137 if (cppi41_channel->tx_zlp && (cppi41_channel->transferred % in cppi41_trans_done()
138 cppi41_channel->packet_sz) == 0) { in cppi41_trans_done()
139 musb_ep_select(musb->mregs, hw_ep->epnum); in cppi41_trans_done()
145 musb_dma_completion(musb, hw_ep->epnum, cppi41_channel->is_tx); in cppi41_trans_done()
148 struct dma_chan *dc = cppi41_channel->dc; in cppi41_trans_done()
153 cppi41_channel->buf_addr += cppi41_channel->packet_sz; in cppi41_trans_done()
155 remain_bytes = cppi41_channel->total_len; in cppi41_trans_done()
156 remain_bytes -= cppi41_channel->transferred; in cppi41_trans_done()
157 remain_bytes = min(remain_bytes, cppi41_channel->packet_sz); in cppi41_trans_done()
158 cppi41_channel->prog_len = remain_bytes; in cppi41_trans_done()
160 direction = cppi41_channel->is_tx ? DMA_MEM_TO_DEV in cppi41_trans_done()
163 cppi41_channel->buf_addr, in cppi41_trans_done()
170 dma_desc->callback_result = cppi41_dma_callback; in cppi41_trans_done()
171 dma_desc->callback_param = &cppi41_channel->channel; in cppi41_trans_done()
172 cppi41_channel->cookie = dma_desc->tx_submit(dma_desc); in cppi41_trans_done()
176 if (!cppi41_channel->is_tx) { in cppi41_trans_done()
177 musb_ep_select(musb->mregs, hw_ep->epnum); in cppi41_trans_done()
195 musb = controller->controller.musb; in cppi41_recheck_tx_req()
197 spin_lock_irqsave(&musb->lock, flags); in cppi41_recheck_tx_req()
198 list_for_each_entry_safe(cppi41_channel, n, &controller->early_tx_list, in cppi41_recheck_tx_req()
201 struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; in cppi41_recheck_tx_req()
205 list_del_init(&cppi41_channel->tx_check); in cppi41_recheck_tx_req()
210 if (!list_empty(&controller->early_tx_list) && in cppi41_recheck_tx_req()
211 !hrtimer_is_queued(&controller->early_tx)) { in cppi41_recheck_tx_req()
213 hrtimer_forward_now(&controller->early_tx, 20 * NSEC_PER_USEC); in cppi41_recheck_tx_req()
216 spin_unlock_irqrestore(&musb->lock, flags); in cppi41_recheck_tx_req()
224 struct cppi41_dma_channel *cppi41_channel = channel->private_data; in cppi41_dma_callback()
225 struct musb_hw_ep *hw_ep = cppi41_channel->hw_ep; in cppi41_dma_callback()
227 struct musb *musb = hw_ep->musb; in cppi41_dma_callback()
234 controller = cppi41_channel->controller; in cppi41_dma_callback()
235 if (controller->controller.dma_callback) in cppi41_dma_callback()
236 controller->controller.dma_callback(&controller->controller); in cppi41_dma_callback()
238 if (result->result == DMA_TRANS_ABORTED) in cppi41_dma_callback()
241 spin_lock_irqsave(&musb->lock, flags); in cppi41_dma_callback()
243 dmaengine_tx_status(cppi41_channel->dc, cppi41_channel->cookie, in cppi41_dma_callback()
245 transferred = cppi41_channel->prog_len - txstate.residue; in cppi41_dma_callback()
246 cppi41_channel->transferred += transferred; in cppi41_dma_callback()
251 if (cppi41_channel->transferred == cppi41_channel->total_len || in cppi41_dma_callback()
252 transferred < cppi41_channel->packet_sz) in cppi41_dma_callback()
253 cppi41_channel->prog_len = 0; in cppi41_dma_callback()
255 if (cppi41_channel->is_tx) { in cppi41_dma_callback()
259 type = hw_ep->out_qh->type; in cppi41_dma_callback()
261 type = hw_ep->ep_in.type; in cppi41_dma_callback()
265 * Don't use the early-TX-interrupt workaround below in cppi41_dma_callback()
277 if (!cppi41_channel->is_tx || empty) { in cppi41_dma_callback()
288 * 110us - 150us depending on the transfer size. in cppi41_dma_callback()
293 if (musb->port1_status & USB_PORT_STAT_HIGH_SPEED) in cppi41_dma_callback()
296 if (musb->g.speed == USB_SPEED_HIGH) in cppi41_dma_callback()
308 wait--; in cppi41_dma_callback()
314 list_add_tail(&cppi41_channel->tx_check, in cppi41_dma_callback()
315 &controller->early_tx_list); in cppi41_dma_callback()
316 if (!hrtimer_is_queued(&controller->early_tx)) { in cppi41_dma_callback()
317 unsigned long usecs = cppi41_channel->total_len / 10; in cppi41_dma_callback()
319 hrtimer_start_range_ns(&controller->early_tx, in cppi41_dma_callback()
326 spin_unlock_irqrestore(&musb->lock, flags); in cppi41_dma_callback()
329 static u32 update_ep_mode(unsigned ep, unsigned mode, u32 old) in update_ep_mode() argument
333 shift = (ep - 1) * 2; in update_ep_mode()
335 old |= mode << shift; in update_ep_mode()
340 unsigned mode) in cppi41_set_dma_mode() argument
342 struct cppi41_dma_controller *controller = cppi41_channel->controller; in cppi41_set_dma_mode()
343 struct musb *musb = controller->controller.musb; in cppi41_set_dma_mode()
348 if (cppi41_channel->is_tx) in cppi41_set_dma_mode()
349 old_mode = controller->tx_mode; in cppi41_set_dma_mode()
351 old_mode = controller->rx_mode; in cppi41_set_dma_mode()
352 port = cppi41_channel->port_num; in cppi41_set_dma_mode()
353 new_mode = update_ep_mode(port, mode, old_mode); in cppi41_set_dma_mode()
357 if (cppi41_channel->is_tx) { in cppi41_set_dma_mode()
358 controller->tx_mode = new_mode; in cppi41_set_dma_mode()
359 musb_writel(musb->ctrl_base, USB_CTRL_TX_MODE, new_mode); in cppi41_set_dma_mode()
361 controller->rx_mode = new_mode; in cppi41_set_dma_mode()
362 musb_writel(musb->ctrl_base, USB_CTRL_RX_MODE, new_mode); in cppi41_set_dma_mode()
367 unsigned int mode) in da8xx_set_dma_mode() argument
369 struct cppi41_dma_controller *controller = cppi41_channel->controller; in da8xx_set_dma_mode()
370 struct musb *musb = controller->controller.musb; in da8xx_set_dma_mode()
376 old_mode = controller->tx_mode; in da8xx_set_dma_mode()
377 port = cppi41_channel->port_num; in da8xx_set_dma_mode()
379 shift = (port - 1) * 4; in da8xx_set_dma_mode()
380 if (!cppi41_channel->is_tx) in da8xx_set_dma_mode()
383 new_mode |= mode << shift; in da8xx_set_dma_mode()
387 controller->tx_mode = new_mode; in da8xx_set_dma_mode()
388 musb_writel(musb->ctrl_base, DA8XX_USB_MODE, new_mode); in da8xx_set_dma_mode()
393 unsigned mode) in cppi41_set_autoreq_mode() argument
395 struct cppi41_dma_controller *controller = cppi41_channel->controller; in cppi41_set_autoreq_mode()
400 old_mode = controller->auto_req; in cppi41_set_autoreq_mode()
401 port = cppi41_channel->port_num; in cppi41_set_autoreq_mode()
402 new_mode = update_ep_mode(port, mode, old_mode); in cppi41_set_autoreq_mode()
406 controller->auto_req = new_mode; in cppi41_set_autoreq_mode()
407 musb_writel(controller->controller.musb->ctrl_base, in cppi41_set_autoreq_mode()
408 controller->autoreq_reg, new_mode); in cppi41_set_autoreq_mode()
412 u16 packet_sz, u8 mode, in cppi41_configure_channel() argument
415 struct cppi41_dma_channel *cppi41_channel = channel->private_data; in cppi41_configure_channel()
416 struct cppi41_dma_controller *controller = cppi41_channel->controller; in cppi41_configure_channel()
417 struct dma_chan *dc = cppi41_channel->dc; in cppi41_configure_channel()
420 struct musb *musb = cppi41_channel->controller->controller.musb; in cppi41_configure_channel()
423 cppi41_channel->buf_addr = dma_addr; in cppi41_configure_channel()
424 cppi41_channel->total_len = len; in cppi41_configure_channel()
425 cppi41_channel->transferred = 0; in cppi41_configure_channel()
426 cppi41_channel->packet_sz = packet_sz; in cppi41_configure_channel()
427 cppi41_channel->tx_zlp = (cppi41_channel->is_tx && mode) ? 1 : 0; in cppi41_configure_channel()
433 if (cppi41_channel->is_tx) in cppi41_configure_channel()
437 /* RNDIS mode */ in cppi41_configure_channel()
439 musb_writel(musb->ctrl_base, in cppi41_configure_channel()
440 RNDIS_REG(cppi41_channel->port_num), len); in cppi41_configure_channel()
442 controller->set_dma_mode(cppi41_channel, in cppi41_configure_channel()
449 musb_writel(musb->ctrl_base, in cppi41_configure_channel()
450 RNDIS_REG(cppi41_channel->port_num), 0); in cppi41_configure_channel()
451 controller->set_dma_mode(cppi41_channel, in cppi41_configure_channel()
457 /* fallback mode */ in cppi41_configure_channel()
458 controller->set_dma_mode(cppi41_channel, in cppi41_configure_channel()
463 cppi41_channel->prog_len = len; in cppi41_configure_channel()
464 direction = cppi41_channel->is_tx ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; in cppi41_configure_channel()
470 dma_desc->callback_result = cppi41_dma_callback; in cppi41_configure_channel()
471 dma_desc->callback_param = channel; in cppi41_configure_channel()
472 cppi41_channel->cookie = dma_desc->tx_submit(dma_desc); in cppi41_configure_channel()
473 cppi41_channel->channel.rx_packet_done = false; in cppi41_configure_channel()
488 u8 ch_num = hw_ep->epnum - 1; in cppi41_dma_channel_allocate()
490 if (ch_num >= controller->num_channels) in cppi41_dma_channel_allocate()
494 cppi41_channel = &controller->tx_channel[ch_num]; in cppi41_dma_channel_allocate()
496 cppi41_channel = &controller->rx_channel[ch_num]; in cppi41_dma_channel_allocate()
498 if (!cppi41_channel->dc) in cppi41_dma_channel_allocate()
501 if (cppi41_channel->is_allocated) in cppi41_dma_channel_allocate()
504 cppi41_channel->hw_ep = hw_ep; in cppi41_dma_channel_allocate()
505 cppi41_channel->is_allocated = 1; in cppi41_dma_channel_allocate()
508 return &cppi41_channel->channel; in cppi41_dma_channel_allocate()
513 struct cppi41_dma_channel *cppi41_channel = channel->private_data; in cppi41_dma_channel_release()
516 if (cppi41_channel->is_allocated) { in cppi41_dma_channel_release()
517 cppi41_channel->is_allocated = 0; in cppi41_dma_channel_release()
518 channel->status = MUSB_DMA_STATUS_FREE; in cppi41_dma_channel_release()
519 channel->actual_len = 0; in cppi41_dma_channel_release()
524 u16 packet_sz, u8 mode, in cppi41_dma_channel_program() argument
528 struct cppi41_dma_channel *cppi41_channel = channel->private_data; in cppi41_dma_channel_program()
531 BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN || in cppi41_dma_channel_program()
532 channel->status == MUSB_DMA_STATUS_BUSY); in cppi41_dma_channel_program()
534 if (is_host_active(cppi41_channel->controller->controller.musb)) { in cppi41_dma_channel_program()
535 if (cppi41_channel->is_tx) in cppi41_dma_channel_program()
536 hb_mult = cppi41_channel->hw_ep->out_qh->hb_mult; in cppi41_dma_channel_program()
538 hb_mult = cppi41_channel->hw_ep->in_qh->hb_mult; in cppi41_dma_channel_program()
541 channel->status = MUSB_DMA_STATUS_BUSY; in cppi41_dma_channel_program()
542 channel->actual_len = 0; in cppi41_dma_channel_program()
547 ret = cppi41_configure_channel(channel, packet_sz, mode, dma_addr, len); in cppi41_dma_channel_program()
549 channel->status = MUSB_DMA_STATUS_FREE; in cppi41_dma_channel_program()
557 struct cppi41_dma_channel *cppi41_channel = channel->private_data; in cppi41_is_compatible()
558 struct cppi41_dma_controller *controller = cppi41_channel->controller; in cppi41_is_compatible()
559 struct musb *musb = controller->controller.musb; in cppi41_is_compatible()
565 if (cppi41_channel->hw_ep->ep_in.type != USB_ENDPOINT_XFER_BULK) in cppi41_is_compatible()
567 if (cppi41_channel->is_tx) in cppi41_is_compatible()
569 /* AM335x Advisory 1.0.13. No workaround for device RX mode */ in cppi41_is_compatible()
575 struct cppi41_dma_channel *cppi41_channel = channel->private_data; in cppi41_dma_channel_abort()
576 struct cppi41_dma_controller *controller = cppi41_channel->controller; in cppi41_dma_channel_abort()
577 struct musb *musb = controller->controller.musb; in cppi41_dma_channel_abort()
578 void __iomem *epio = cppi41_channel->hw_ep->regs; in cppi41_dma_channel_abort()
584 is_tx = cppi41_channel->is_tx; in cppi41_dma_channel_abort()
587 if (cppi41_channel->channel.status == MUSB_DMA_STATUS_FREE) in cppi41_dma_channel_abort()
590 list_del_init(&cppi41_channel->tx_check); in cppi41_dma_channel_abort()
617 if (musb->ops->quirks & MUSB_DA8XX) in cppi41_dma_channel_abort()
620 tdbit = 1 << cppi41_channel->port_num; in cppi41_dma_channel_abort()
626 musb_writel(musb->ctrl_base, controller->tdown_reg, in cppi41_dma_channel_abort()
628 ret = dmaengine_terminate_all(cppi41_channel->dc); in cppi41_dma_channel_abort()
629 } while (ret == -EAGAIN); in cppi41_dma_channel_abort()
632 musb_writel(musb->ctrl_base, controller->tdown_reg, tdbit); in cppi41_dma_channel_abort()
641 cppi41_channel->channel.status = MUSB_DMA_STATUS_FREE; in cppi41_dma_channel_abort()
650 for (i = 0; i < ctrl->num_channels; i++) { in cppi41_release_all_dma_chans()
651 dc = ctrl->tx_channel[i].dc; in cppi41_release_all_dma_chans()
654 dc = ctrl->rx_channel[i].dc; in cppi41_release_all_dma_chans()
667 struct musb *musb = controller->controller.musb; in cppi41_dma_controller_start()
668 struct device *dev = musb->controller; in cppi41_dma_controller_start()
669 struct device_node *np = dev->parent->of_node; in cppi41_dma_controller_start()
675 count = of_property_count_strings(np, "dma-names"); in cppi41_dma_controller_start()
686 ret = of_property_read_string_index(np, "dma-names", i, &str); in cppi41_dma_controller_start()
701 ret = -EINVAL; in cppi41_dma_controller_start()
702 if (port > controller->num_channels || !port) in cppi41_dma_controller_start()
705 cppi41_channel = &controller->tx_channel[port - 1]; in cppi41_dma_controller_start()
707 cppi41_channel = &controller->rx_channel[port - 1]; in cppi41_dma_controller_start()
709 cppi41_channel->controller = controller; in cppi41_dma_controller_start()
710 cppi41_channel->port_num = port; in cppi41_dma_controller_start()
711 cppi41_channel->is_tx = is_tx; in cppi41_dma_controller_start()
712 INIT_LIST_HEAD(&cppi41_channel->tx_check); in cppi41_dma_controller_start()
714 musb_dma = &cppi41_channel->channel; in cppi41_dma_controller_start()
715 musb_dma->private_data = cppi41_channel; in cppi41_dma_controller_start()
716 musb_dma->status = MUSB_DMA_STATUS_FREE; in cppi41_dma_controller_start()
717 musb_dma->max_len = SZ_4M; in cppi41_dma_controller_start()
719 dc = dma_request_chan(dev->parent, str); in cppi41_dma_controller_start()
726 cppi41_channel->dc = dc; in cppi41_dma_controller_start()
739 hrtimer_cancel(&controller->early_tx); in cppi41_dma_controller_destroy()
741 kfree(controller->rx_channel); in cppi41_dma_controller_destroy()
742 kfree(controller->tx_channel); in cppi41_dma_controller_destroy()
754 if (!musb->controller->parent->of_node) { in cppi41_dma_controller_create()
755 dev_err(musb->controller, "Need DT for the DMA engine.\n"); in cppi41_dma_controller_create()
763 hrtimer_init(&controller->early_tx, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in cppi41_dma_controller_create()
764 controller->early_tx.function = cppi41_recheck_tx_req; in cppi41_dma_controller_create()
765 INIT_LIST_HEAD(&controller->early_tx_list); in cppi41_dma_controller_create()
767 controller->controller.channel_alloc = cppi41_dma_channel_allocate; in cppi41_dma_controller_create()
768 controller->controller.channel_release = cppi41_dma_channel_release; in cppi41_dma_controller_create()
769 controller->controller.channel_program = cppi41_dma_channel_program; in cppi41_dma_controller_create()
770 controller->controller.channel_abort = cppi41_dma_channel_abort; in cppi41_dma_controller_create()
771 controller->controller.is_compatible = cppi41_is_compatible; in cppi41_dma_controller_create()
772 controller->controller.musb = musb; in cppi41_dma_controller_create()
774 if (musb->ops->quirks & MUSB_DA8XX) { in cppi41_dma_controller_create()
775 controller->tdown_reg = DA8XX_USB_TEARDOWN; in cppi41_dma_controller_create()
776 controller->autoreq_reg = DA8XX_USB_AUTOREQ; in cppi41_dma_controller_create()
777 controller->set_dma_mode = da8xx_set_dma_mode; in cppi41_dma_controller_create()
778 controller->num_channels = DA8XX_DMA_NUM_CHANNELS; in cppi41_dma_controller_create()
780 controller->tdown_reg = USB_TDOWN; in cppi41_dma_controller_create()
781 controller->autoreq_reg = USB_CTRL_AUTOREQ; in cppi41_dma_controller_create()
782 controller->set_dma_mode = cppi41_set_dma_mode; in cppi41_dma_controller_create()
783 controller->num_channels = MUSB_DMA_NUM_CHANNELS; in cppi41_dma_controller_create()
786 channel_size = controller->num_channels * in cppi41_dma_controller_create()
788 controller->rx_channel = kzalloc(channel_size, GFP_KERNEL); in cppi41_dma_controller_create()
789 if (!controller->rx_channel) in cppi41_dma_controller_create()
791 controller->tx_channel = kzalloc(channel_size, GFP_KERNEL); in cppi41_dma_controller_create()
792 if (!controller->tx_channel) in cppi41_dma_controller_create()
798 return &controller->controller; in cppi41_dma_controller_create()
801 kfree(controller->tx_channel); in cppi41_dma_controller_create()
803 kfree(controller->rx_channel); in cppi41_dma_controller_create()
807 if (ret == -EPROBE_DEFER) in cppi41_dma_controller_create()