Lines Matching +full:num +full:- +full:channels

1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/dma-mapping.h>
36 return gpiod_get_value(omap_port->wake_gpio); in ssi_wakein()
44 debugfs_remove_recursive(omap_port->dir); in ssi_debug_remove_port()
49 struct hsi_port *port = m->private; in ssi_port_regs_show()
51 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_port_regs_show()
53 void __iomem *base = omap_ssi->sys; in ssi_port_regs_show()
56 pm_runtime_get_sync(omap_port->pdev); in ssi_port_regs_show()
57 if (omap_port->wake_irq > 0) in ssi_port_regs_show()
60 readl(base + SSI_WAKE_REG(port->num))); in ssi_port_regs_show()
62 readl(base + SSI_MPU_ENABLE_REG(port->num, 0))); in ssi_port_regs_show()
64 readl(base + SSI_MPU_STATUS_REG(port->num, 0))); in ssi_port_regs_show()
66 base = omap_port->sst_base; in ssi_port_regs_show()
76 seq_printf(m, "CHANNELS\t: 0x%08x\n", in ssi_port_regs_show()
86 for (ch = 0; ch < omap_port->channels; ch++) { in ssi_port_regs_show()
91 base = omap_port->ssr_base; in ssi_port_regs_show()
99 seq_printf(m, "CHANNELS\t: 0x%08x\n", in ssi_port_regs_show()
113 for (ch = 0; ch < omap_port->channels; ch++) { in ssi_port_regs_show()
117 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_port_regs_show()
129 pm_runtime_get_sync(omap_port->pdev); in ssi_div_get()
130 *val = readl(omap_port->sst_base + SSI_SST_DIVISOR_REG); in ssi_div_get()
131 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_div_get()
142 return -EINVAL; in ssi_div_set()
144 pm_runtime_get_sync(omap_port->pdev); in ssi_div_set()
145 writel(val, omap_port->sst_base + SSI_SST_DIVISOR_REG); in ssi_div_set()
146 omap_port->sst.divisor = val; in ssi_div_set()
147 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_div_set()
157 struct hsi_port *port = to_hsi_port(omap_port->dev); in ssi_debug_add_port()
159 dir = debugfs_create_dir(dev_name(omap_port->dev), dir); in ssi_debug_add_port()
160 omap_port->dir = dir; in ssi_debug_add_port()
176 list_for_each_safe(head, tmp, &omap_port->errqueue) { in ssi_process_errqueue()
178 msg->complete(msg); in ssi_process_errqueue()
186 struct hsi_port *port = hsi_get_port(msg->cl); in ssi_claim_lch()
187 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_claim_lch()
192 if (!omap_ssi->gdd_trn[lch].msg) { in ssi_claim_lch()
193 omap_ssi->gdd_trn[lch].msg = msg; in ssi_claim_lch()
194 omap_ssi->gdd_trn[lch].sg = msg->sgt.sgl; in ssi_claim_lch()
198 return -EBUSY; in ssi_claim_lch()
203 struct hsi_port *port = hsi_get_port(msg->cl); in ssi_start_dma()
205 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_start_dma()
207 void __iomem *gdd = omap_ssi->gdd; in ssi_start_dma()
216 pm_runtime_get(omap_port->pdev); in ssi_start_dma()
218 if (!pm_runtime_active(omap_port->pdev)) { in ssi_start_dma()
219 dev_warn(&port->device, "ssi_start_dma called without runtime PM!\n"); in ssi_start_dma()
220 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_start_dma()
221 return -EREMOTEIO; in ssi_start_dma()
224 if (msg->ttype == HSI_MSG_READ) { in ssi_start_dma()
225 err = dma_map_sg(&ssi->device, msg->sgt.sgl, msg->sgt.nents, in ssi_start_dma()
228 dev_dbg(&ssi->device, "DMA map SG failed !\n"); in ssi_start_dma()
229 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_start_dma()
230 return -EIO; in ssi_start_dma()
235 ccr = msg->channel + 0x10 + (port->num * 8); /* Sync */ in ssi_start_dma()
238 s_addr = omap_port->ssr_dma + in ssi_start_dma()
239 SSI_SSR_BUFFER_CH_REG(msg->channel); in ssi_start_dma()
240 d_addr = sg_dma_address(msg->sgt.sgl); in ssi_start_dma()
242 err = dma_map_sg(&ssi->device, msg->sgt.sgl, msg->sgt.nents, in ssi_start_dma()
245 dev_dbg(&ssi->device, "DMA map SG failed !\n"); in ssi_start_dma()
246 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_start_dma()
247 return -EIO; in ssi_start_dma()
252 ccr = (msg->channel + 1 + (port->num * 8)) & 0xf; /* Sync */ in ssi_start_dma()
255 s_addr = sg_dma_address(msg->sgt.sgl); in ssi_start_dma()
256 d_addr = omap_port->sst_dma + in ssi_start_dma()
257 SSI_SST_BUFFER_CH_REG(msg->channel); in ssi_start_dma()
259 dev_dbg(&ssi->device, "lch %d cdsp %08x ccr %04x s_addr %08x d_addr %08x\n", in ssi_start_dma()
266 writew_relaxed(SSI_BYTES_TO_FRAMES(msg->sgt.sgl->length), in ssi_start_dma()
269 spin_lock_bh(&omap_ssi->lock); in ssi_start_dma()
270 tmp = readl(omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG); in ssi_start_dma()
272 writel_relaxed(tmp, omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG); in ssi_start_dma()
273 spin_unlock_bh(&omap_ssi->lock); in ssi_start_dma()
275 msg->status = HSI_STATUS_PROCEEDING; in ssi_start_dma()
282 struct hsi_port *port = hsi_get_port(msg->cl); in ssi_start_pio()
284 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_start_pio()
288 pm_runtime_get(omap_port->pdev); in ssi_start_pio()
290 if (!pm_runtime_active(omap_port->pdev)) { in ssi_start_pio()
291 dev_warn(&port->device, "ssi_start_pio called without runtime PM!\n"); in ssi_start_pio()
292 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_start_pio()
293 return -EREMOTEIO; in ssi_start_pio()
296 if (msg->ttype == HSI_MSG_WRITE) { in ssi_start_pio()
297 val = SSI_DATAACCEPT(msg->channel); in ssi_start_pio()
299 pm_runtime_get(omap_port->pdev); in ssi_start_pio()
301 val = SSI_DATAAVAILABLE(msg->channel) | SSI_ERROROCCURED; in ssi_start_pio()
303 dev_dbg(&port->device, "Single %s transfer\n", in ssi_start_pio()
304 msg->ttype ? "write" : "read"); in ssi_start_pio()
305 val |= readl(omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_start_pio()
306 writel(val, omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_start_pio()
307 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_start_pio()
308 msg->actual_len = 0; in ssi_start_pio()
309 msg->status = HSI_STATUS_PROCEEDING; in ssi_start_pio()
317 int lch = -1; in ssi_start_transfer()
322 if (msg->status != HSI_STATUS_QUEUED) in ssi_start_transfer()
324 if ((msg->sgt.nents) && (msg->sgt.sgl->length > sizeof(u32))) in ssi_start_transfer()
334 struct hsi_port *port = hsi_get_port(msg->cl); in ssi_async_break()
336 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_async_break()
341 pm_runtime_get_sync(omap_port->pdev); in ssi_async_break()
342 if (msg->ttype == HSI_MSG_WRITE) { in ssi_async_break()
343 if (omap_port->sst.mode != SSI_MODE_FRAME) { in ssi_async_break()
344 err = -EINVAL; in ssi_async_break()
347 writel(1, omap_port->sst_base + SSI_SST_BREAK_REG); in ssi_async_break()
348 msg->status = HSI_STATUS_COMPLETED; in ssi_async_break()
349 msg->complete(msg); in ssi_async_break()
351 if (omap_port->ssr.mode != SSI_MODE_FRAME) { in ssi_async_break()
352 err = -EINVAL; in ssi_async_break()
355 spin_lock_bh(&omap_port->lock); in ssi_async_break()
356 tmp = readl(omap_ssi->sys + in ssi_async_break()
357 SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_async_break()
359 omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_async_break()
360 msg->status = HSI_STATUS_PROCEEDING; in ssi_async_break()
361 list_add_tail(&msg->link, &omap_port->brkqueue); in ssi_async_break()
362 spin_unlock_bh(&omap_port->lock); in ssi_async_break()
365 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_async_break()
366 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_async_break()
373 struct hsi_port *port = hsi_get_port(msg->cl); in ssi_async()
380 if (msg->sgt.nents > 1) in ssi_async()
381 return -ENOSYS; /* TODO: Add sg support */ in ssi_async()
383 if (msg->break_frame) in ssi_async()
386 if (msg->ttype) { in ssi_async()
387 BUG_ON(msg->channel >= omap_port->sst.channels); in ssi_async()
388 queue = &omap_port->txqueue[msg->channel]; in ssi_async()
390 BUG_ON(msg->channel >= omap_port->ssr.channels); in ssi_async()
391 queue = &omap_port->rxqueue[msg->channel]; in ssi_async()
393 msg->status = HSI_STATUS_QUEUED; in ssi_async()
395 pm_runtime_get_sync(omap_port->pdev); in ssi_async()
396 spin_lock_bh(&omap_port->lock); in ssi_async()
397 list_add_tail(&msg->link, queue); in ssi_async()
400 list_del(&msg->link); in ssi_async()
401 msg->status = HSI_STATUS_ERROR; in ssi_async()
403 spin_unlock_bh(&omap_port->lock); in ssi_async()
404 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_async()
405 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_async()
406 dev_dbg(&port->device, "msg status %d ttype %d ch %d\n", in ssi_async()
407 msg->status, msg->ttype, msg->channel); in ssi_async()
415 u32 tx_fckrate = (u32) omap_ssi->fck_rate; in ssi_calculate_div()
419 /* Round down when tx_fckrate % omap_ssi->max_speed == 0 */ in ssi_calculate_div()
420 tx_fckrate--; in ssi_calculate_div()
421 dev_dbg(&ssi->device, "TX div %d for fck_rate %lu Khz speed %d Kb/s\n", in ssi_calculate_div()
422 tx_fckrate / omap_ssi->max_speed, omap_ssi->fck_rate, in ssi_calculate_div()
423 omap_ssi->max_speed); in ssi_calculate_div()
425 return tx_fckrate / omap_ssi->max_speed; in ssi_calculate_div()
435 if ((cl) && (cl != msg->cl)) in ssi_flush_queue()
439 msg->channel, msg, msg->sgt.sgl->length, in ssi_flush_queue()
440 msg->ttype, msg->context); in ssi_flush_queue()
441 if (msg->destructor) in ssi_flush_queue()
442 msg->destructor(msg); in ssi_flush_queue()
450 struct hsi_port *port = to_hsi_port(cl->device.parent); in ssi_setup()
452 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_setup()
454 void __iomem *sst = omap_port->sst_base; in ssi_setup()
455 void __iomem *ssr = omap_port->ssr_base; in ssi_setup()
460 pm_runtime_get_sync(omap_port->pdev); in ssi_setup()
461 spin_lock_bh(&omap_port->lock); in ssi_setup()
462 if (cl->tx_cfg.speed) in ssi_setup()
463 omap_ssi->max_speed = cl->tx_cfg.speed; in ssi_setup()
466 dev_err(&cl->device, "Invalid TX speed %d Mb/s (div %d)\n", in ssi_setup()
467 cl->tx_cfg.speed, div); in ssi_setup()
468 err = -EINVAL; in ssi_setup()
479 writel_relaxed(cl->tx_cfg.num_hw_channels, sst + SSI_SST_CHANNELS_REG); in ssi_setup()
480 writel_relaxed(cl->tx_cfg.arb_mode, sst + SSI_SST_ARBMODE_REG); in ssi_setup()
481 writel_relaxed(cl->tx_cfg.mode, sst + SSI_SST_MODE_REG); in ssi_setup()
484 writel_relaxed(cl->rx_cfg.num_hw_channels, ssr + SSI_SSR_CHANNELS_REG); in ssi_setup()
487 if ((omap_port->ssr.mode == SSI_MODE_FRAME) && in ssi_setup()
488 (cl->rx_cfg.mode != SSI_MODE_FRAME)) in ssi_setup()
489 ssi_flush_queue(&omap_port->brkqueue, cl); in ssi_setup()
490 writel_relaxed(cl->rx_cfg.mode, ssr + SSI_SSR_MODE_REG); in ssi_setup()
491 omap_port->channels = max(cl->rx_cfg.num_hw_channels, in ssi_setup()
492 cl->tx_cfg.num_hw_channels); in ssi_setup()
495 omap_port->sst.divisor = div; in ssi_setup()
496 omap_port->sst.frame_size = 31; in ssi_setup()
497 omap_port->sst.channels = cl->tx_cfg.num_hw_channels; in ssi_setup()
498 omap_port->sst.arb_mode = cl->tx_cfg.arb_mode; in ssi_setup()
499 omap_port->sst.mode = cl->tx_cfg.mode; in ssi_setup()
501 omap_port->ssr.frame_size = 31; in ssi_setup()
502 omap_port->ssr.timeout = 0; in ssi_setup()
503 omap_port->ssr.channels = cl->rx_cfg.num_hw_channels; in ssi_setup()
504 omap_port->ssr.mode = cl->rx_cfg.mode; in ssi_setup()
506 spin_unlock_bh(&omap_port->lock); in ssi_setup()
507 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_setup()
508 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_setup()
517 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_flush()
520 void __iomem *sst = omap_port->sst_base; in ssi_flush()
521 void __iomem *ssr = omap_port->ssr_base; in ssi_flush()
525 pm_runtime_get_sync(omap_port->pdev); in ssi_flush()
526 spin_lock_bh(&omap_port->lock); in ssi_flush()
529 pinctrl_pm_select_idle_state(omap_port->pdev); in ssi_flush()
534 msg = omap_ssi->gdd_trn[i].msg; in ssi_flush()
535 if (!msg || (port != hsi_get_port(msg->cl))) in ssi_flush()
537 writew_relaxed(0, omap_ssi->gdd + SSI_GDD_CCR_REG(i)); in ssi_flush()
538 if (msg->ttype == HSI_MSG_READ) in ssi_flush()
539 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_flush()
540 omap_ssi->gdd_trn[i].msg = NULL; in ssi_flush()
554 writel_relaxed(0, omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_flush()
556 omap_ssi->sys + SSI_MPU_STATUS_REG(port->num, 0)); in ssi_flush()
557 writel_relaxed(0, omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG); in ssi_flush()
558 writel(0xff, omap_ssi->sys + SSI_GDD_MPU_IRQ_STATUS_REG); in ssi_flush()
560 for (i = 0; i < omap_port->channels; i++) { in ssi_flush()
562 if (!list_empty(&omap_port->txqueue[i])) in ssi_flush()
563 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_flush()
564 ssi_flush_queue(&omap_port->txqueue[i], NULL); in ssi_flush()
565 ssi_flush_queue(&omap_port->rxqueue[i], NULL); in ssi_flush()
567 ssi_flush_queue(&omap_port->brkqueue, NULL); in ssi_flush()
570 pinctrl_pm_select_default_state(omap_port->pdev); in ssi_flush()
572 spin_unlock_bh(&omap_port->lock); in ssi_flush()
573 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_flush()
574 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_flush()
583 struct hsi_port *port = to_hsi_port(omap_port->dev); in start_tx_work()
584 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in start_tx_work()
587 pm_runtime_get_sync(omap_port->pdev); /* Grab clocks */ in start_tx_work()
588 writel(SSI_WAKE(0), omap_ssi->sys + SSI_SET_WAKE_REG(port->num)); in start_tx_work()
596 dev_dbg(&port->device, "Wake out high %d\n", omap_port->wk_refcount); in ssi_start_tx()
598 spin_lock_bh(&omap_port->wk_lock); in ssi_start_tx()
599 if (omap_port->wk_refcount++) { in ssi_start_tx()
600 spin_unlock_bh(&omap_port->wk_lock); in ssi_start_tx()
603 spin_unlock_bh(&omap_port->wk_lock); in ssi_start_tx()
605 schedule_work(&omap_port->work); in ssi_start_tx()
614 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_stop_tx()
617 dev_dbg(&port->device, "Wake out low %d\n", omap_port->wk_refcount); in ssi_stop_tx()
619 spin_lock_bh(&omap_port->wk_lock); in ssi_stop_tx()
620 BUG_ON(!omap_port->wk_refcount); in ssi_stop_tx()
621 if (--omap_port->wk_refcount) { in ssi_stop_tx()
622 spin_unlock_bh(&omap_port->wk_lock); in ssi_stop_tx()
625 writel(SSI_WAKE(0), omap_ssi->sys + SSI_CLEAR_WAKE_REG(port->num)); in ssi_stop_tx()
626 spin_unlock_bh(&omap_port->wk_lock); in ssi_stop_tx()
628 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_stop_tx()
629 pm_runtime_put_autosuspend(omap_port->pdev); /* Release clocks */ in ssi_stop_tx()
639 int err = -1; in ssi_transfer()
641 pm_runtime_get(omap_port->pdev); in ssi_transfer()
642 spin_lock_bh(&omap_port->lock); in ssi_transfer()
647 msg->status = HSI_STATUS_ERROR; in ssi_transfer()
648 msg->actual_len = 0; in ssi_transfer()
649 list_del(&msg->link); in ssi_transfer()
650 spin_unlock_bh(&omap_port->lock); in ssi_transfer()
651 msg->complete(msg); in ssi_transfer()
652 spin_lock_bh(&omap_port->lock); in ssi_transfer()
655 spin_unlock_bh(&omap_port->lock); in ssi_transfer()
656 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_transfer()
657 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_transfer()
664 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_cleanup_queues()
673 ssi_flush_queue(&omap_port->brkqueue, cl); in ssi_cleanup_queues()
674 if (list_empty(&omap_port->brkqueue)) in ssi_cleanup_queues()
677 for (i = 0; i < omap_port->channels; i++) { in ssi_cleanup_queues()
678 if (list_empty(&omap_port->txqueue[i])) in ssi_cleanup_queues()
680 msg = list_first_entry(&omap_port->txqueue[i], struct hsi_msg, in ssi_cleanup_queues()
682 if ((msg->cl == cl) && (msg->status == HSI_STATUS_PROCEEDING)) { in ssi_cleanup_queues()
686 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_cleanup_queues()
687 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_cleanup_queues()
689 ssi_flush_queue(&omap_port->txqueue[i], cl); in ssi_cleanup_queues()
691 for (i = 0; i < omap_port->channels; i++) { in ssi_cleanup_queues()
692 if (list_empty(&omap_port->rxqueue[i])) in ssi_cleanup_queues()
694 msg = list_first_entry(&omap_port->rxqueue[i], struct hsi_msg, in ssi_cleanup_queues()
696 if ((msg->cl == cl) && (msg->status == HSI_STATUS_PROCEEDING)) { in ssi_cleanup_queues()
700 ssi_flush_queue(&omap_port->rxqueue[i], cl); in ssi_cleanup_queues()
702 if (!list_empty(&omap_port->rxqueue[i])) in ssi_cleanup_queues()
706 tmp = readl(omap_port->sst_base + SSI_SST_BUFSTATE_REG); in ssi_cleanup_queues()
708 writel_relaxed(tmp, omap_port->sst_base + SSI_SST_BUFSTATE_REG); in ssi_cleanup_queues()
710 tmp = readl(omap_port->ssr_base + SSI_SSR_BUFSTATE_REG); in ssi_cleanup_queues()
712 writel_relaxed(tmp, omap_port->ssr_base + SSI_SSR_BUFSTATE_REG); in ssi_cleanup_queues()
714 tmp = readl(omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_cleanup_queues()
716 writel_relaxed(tmp, omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_cleanup_queues()
717 writel_relaxed(status, omap_ssi->sys + in ssi_cleanup_queues()
718 SSI_MPU_STATUS_REG(port->num, 0)); in ssi_cleanup_queues()
732 msg = omap_ssi->gdd_trn[i].msg; in ssi_cleanup_gdd()
733 if ((!msg) || (msg->cl != cl)) in ssi_cleanup_gdd()
735 writew_relaxed(0, omap_ssi->gdd + SSI_GDD_CCR_REG(i)); in ssi_cleanup_gdd()
741 if (msg->ttype == HSI_MSG_READ) { in ssi_cleanup_gdd()
742 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_cleanup_gdd()
743 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_cleanup_gdd()
745 omap_ssi->gdd_trn[i].msg = NULL; in ssi_cleanup_gdd()
747 tmp = readl_relaxed(omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG); in ssi_cleanup_gdd()
749 writel_relaxed(tmp, omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG); in ssi_cleanup_gdd()
750 writel(val, omap_ssi->sys + SSI_GDD_MPU_IRQ_STATUS_REG); in ssi_cleanup_gdd()
755 writel(mode, omap_port->sst_base + SSI_SST_MODE_REG); in ssi_set_port_mode()
756 writel(mode, omap_port->ssr_base + SSI_SSR_MODE_REG); in ssi_set_port_mode()
758 mode = readl(omap_port->ssr_base + SSI_SSR_MODE_REG); in ssi_set_port_mode()
767 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_release()
769 pm_runtime_get_sync(omap_port->pdev); in ssi_release()
770 spin_lock_bh(&omap_port->lock); in ssi_release()
776 if (port->claimed <= 1) { in ssi_release()
781 if (test_and_clear_bit(SSI_WAKE_EN, &omap_port->flags)) in ssi_release()
782 pm_runtime_put_sync(omap_port->pdev); in ssi_release()
783 pm_runtime_get(omap_port->pdev); in ssi_release()
786 omap_port->sst.mode = SSI_MODE_SLEEP; in ssi_release()
787 omap_port->ssr.mode = SSI_MODE_SLEEP; in ssi_release()
788 pm_runtime_put(omap_port->pdev); in ssi_release()
789 WARN_ON(omap_port->wk_refcount != 0); in ssi_release()
791 spin_unlock_bh(&omap_port->lock); in ssi_release()
792 pm_runtime_put_sync(omap_port->pdev); in ssi_release()
802 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_error()
811 err = readl(omap_port->ssr_base + SSI_SSR_ERROR_REG); in ssi_error()
812 dev_err(&port->device, "SSI error: 0x%02x\n", err); in ssi_error()
814 dev_dbg(&port->device, "spurious SSI error ignored!\n"); in ssi_error()
817 spin_lock(&omap_ssi->lock); in ssi_error()
820 msg = omap_ssi->gdd_trn[i].msg; in ssi_error()
821 if ((msg) && (msg->ttype == HSI_MSG_READ)) { in ssi_error()
822 writew_relaxed(0, omap_ssi->gdd + SSI_GDD_CCR_REG(i)); in ssi_error()
824 omap_ssi->gdd_trn[i].msg = NULL; in ssi_error()
827 tmp = readl(omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG); in ssi_error()
829 writel_relaxed(tmp, omap_ssi->sys + SSI_GDD_MPU_IRQ_ENABLE_REG); in ssi_error()
830 spin_unlock(&omap_ssi->lock); in ssi_error()
832 spin_lock(&omap_port->lock); in ssi_error()
833 tmp = readl(omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_error()
835 writel_relaxed(tmp, omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_error()
837 writel_relaxed(err, omap_port->ssr_base + SSI_SSR_ERRORACK_REG); in ssi_error()
839 omap_ssi->sys + SSI_MPU_STATUS_REG(port->num, 0)); in ssi_error()
841 for (i = 0; i < omap_port->channels; i++) { in ssi_error()
842 if (list_empty(&omap_port->rxqueue[i])) in ssi_error()
844 msg = list_first_entry(&omap_port->rxqueue[i], struct hsi_msg, in ssi_error()
846 list_del(&msg->link); in ssi_error()
847 msg->status = HSI_STATUS_ERROR; in ssi_error()
848 spin_unlock(&omap_port->lock); in ssi_error()
849 msg->complete(msg); in ssi_error()
851 ssi_transfer(omap_port, &omap_port->rxqueue[i]); in ssi_error()
852 spin_lock(&omap_port->lock); in ssi_error()
854 spin_unlock(&omap_port->lock); in ssi_error()
860 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_break_complete()
866 dev_dbg(&port->device, "HWBREAK received\n"); in ssi_break_complete()
868 spin_lock(&omap_port->lock); in ssi_break_complete()
869 val = readl(omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_break_complete()
871 writel_relaxed(val, omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_break_complete()
872 writel_relaxed(0, omap_port->ssr_base + SSI_SSR_BREAK_REG); in ssi_break_complete()
874 omap_ssi->sys + SSI_MPU_STATUS_REG(port->num, 0)); in ssi_break_complete()
875 spin_unlock(&omap_port->lock); in ssi_break_complete()
877 list_for_each_entry_safe(msg, tmp, &omap_port->brkqueue, link) { in ssi_break_complete()
878 msg->status = HSI_STATUS_COMPLETED; in ssi_break_complete()
879 spin_lock(&omap_port->lock); in ssi_break_complete()
880 list_del(&msg->link); in ssi_break_complete()
881 spin_unlock(&omap_port->lock); in ssi_break_complete()
882 msg->complete(msg); in ssi_break_complete()
889 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_pio_complete()
897 spin_lock_bh(&omap_port->lock); in ssi_pio_complete()
899 if ((!msg->sgt.nents) || (!msg->sgt.sgl->length)) { in ssi_pio_complete()
900 msg->actual_len = 0; in ssi_pio_complete()
901 msg->status = HSI_STATUS_PENDING; in ssi_pio_complete()
903 if (msg->ttype == HSI_MSG_WRITE) in ssi_pio_complete()
904 val = SSI_DATAACCEPT(msg->channel); in ssi_pio_complete()
906 val = SSI_DATAAVAILABLE(msg->channel); in ssi_pio_complete()
907 if (msg->status == HSI_STATUS_PROCEEDING) { in ssi_pio_complete()
908 buf = sg_virt(msg->sgt.sgl) + msg->actual_len; in ssi_pio_complete()
909 if (msg->ttype == HSI_MSG_WRITE) in ssi_pio_complete()
910 writel(*buf, omap_port->sst_base + in ssi_pio_complete()
911 SSI_SST_BUFFER_CH_REG(msg->channel)); in ssi_pio_complete()
913 *buf = readl(omap_port->ssr_base + in ssi_pio_complete()
914 SSI_SSR_BUFFER_CH_REG(msg->channel)); in ssi_pio_complete()
915 dev_dbg(&port->device, "ch %d ttype %d 0x%08x\n", msg->channel, in ssi_pio_complete()
916 msg->ttype, *buf); in ssi_pio_complete()
917 msg->actual_len += sizeof(*buf); in ssi_pio_complete()
918 if (msg->actual_len >= msg->sgt.sgl->length) in ssi_pio_complete()
919 msg->status = HSI_STATUS_COMPLETED; in ssi_pio_complete()
924 if ((msg->status == HSI_STATUS_PROCEEDING) || in ssi_pio_complete()
925 ((msg->status == HSI_STATUS_COMPLETED) && in ssi_pio_complete()
926 (msg->ttype == HSI_MSG_WRITE))) { in ssi_pio_complete()
927 writel(val, omap_ssi->sys + in ssi_pio_complete()
928 SSI_MPU_STATUS_REG(port->num, 0)); in ssi_pio_complete()
929 spin_unlock_bh(&omap_port->lock); in ssi_pio_complete()
936 reg = readl(omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_pio_complete()
937 if (msg->ttype == HSI_MSG_WRITE) { in ssi_pio_complete()
939 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_pio_complete()
940 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_pio_complete()
943 writel_relaxed(reg, omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_pio_complete()
944 writel_relaxed(val, omap_ssi->sys + SSI_MPU_STATUS_REG(port->num, 0)); in ssi_pio_complete()
945 list_del(&msg->link); in ssi_pio_complete()
946 spin_unlock_bh(&omap_port->lock); in ssi_pio_complete()
947 msg->complete(msg); in ssi_pio_complete()
954 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_pio_thread()
957 void __iomem *sys = omap_ssi->sys; in ssi_pio_thread()
961 pm_runtime_get_sync(omap_port->pdev); in ssi_pio_thread()
964 status_reg = readl(sys + SSI_MPU_STATUS_REG(port->num, 0)); in ssi_pio_thread()
965 status_reg &= readl(sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_pio_thread()
967 for (ch = 0; ch < omap_port->channels; ch++) { in ssi_pio_thread()
969 ssi_pio_complete(port, &omap_port->txqueue[ch]); in ssi_pio_thread()
971 ssi_pio_complete(port, &omap_port->rxqueue[ch]); in ssi_pio_thread()
978 status_reg = readl(sys + SSI_MPU_STATUS_REG(port->num, 0)); in ssi_pio_thread()
979 status_reg &= readl(sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_pio_thread()
984 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_pio_thread()
985 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_pio_thread()
993 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_wake_thread()
999 * We can have a quick High-Low-High transition in the line. in ssi_wake_thread()
1005 if (!test_and_set_bit(SSI_WAKE_EN, &omap_port->flags)) in ssi_wake_thread()
1006 pm_runtime_get_sync(omap_port->pdev); in ssi_wake_thread()
1007 dev_dbg(&ssi->device, "Wake in high\n"); in ssi_wake_thread()
1008 if (omap_port->wktest) { /* FIXME: HACK ! To be removed */ in ssi_wake_thread()
1010 omap_ssi->sys + SSI_SET_WAKE_REG(port->num)); in ssi_wake_thread()
1014 dev_dbg(&ssi->device, "Wake in low\n"); in ssi_wake_thread()
1015 if (omap_port->wktest) { /* FIXME: HACK ! To be removed */ in ssi_wake_thread()
1017 omap_ssi->sys + SSI_CLEAR_WAKE_REG(port->num)); in ssi_wake_thread()
1020 if (test_and_clear_bit(SSI_WAKE_EN, &omap_port->flags)) { in ssi_wake_thread()
1021 pm_runtime_mark_last_busy(omap_port->pdev); in ssi_wake_thread()
1022 pm_runtime_put_autosuspend(omap_port->pdev); in ssi_wake_thread()
1037 omap_port->irq = err; in ssi_port_irq()
1038 err = devm_request_threaded_irq(&port->device, omap_port->irq, NULL, in ssi_port_irq()
1041 dev_err(&port->device, "Request IRQ %d failed (%d)\n", in ssi_port_irq()
1042 omap_port->irq, err); in ssi_port_irq()
1052 if (!omap_port->wake_gpio) { in ssi_wake_irq()
1053 omap_port->wake_irq = -1; in ssi_wake_irq()
1057 cawake_irq = gpiod_to_irq(omap_port->wake_gpio); in ssi_wake_irq()
1058 omap_port->wake_irq = cawake_irq; in ssi_wake_irq()
1060 err = devm_request_threaded_irq(&port->device, cawake_irq, NULL, in ssi_wake_irq()
1065 dev_err(&port->device, "Request Wake in IRQ %d failed %d\n", in ssi_wake_irq()
1069 dev_err(&port->device, "Enable wake on the wakeline in irq %d failed %d\n", in ssi_wake_irq()
1080 INIT_LIST_HEAD(&omap_port->txqueue[ch]); in ssi_queues_init()
1081 INIT_LIST_HEAD(&omap_port->rxqueue[ch]); in ssi_queues_init()
1083 INIT_LIST_HEAD(&omap_port->brkqueue); in ssi_queues_init()
1096 dev_err(&pd->dev, "IO memory region missing (%s)\n", name); in ssi_port_get_iomem()
1097 return -ENXIO; in ssi_port_get_iomem()
1099 ioarea = devm_request_mem_region(&port->device, mem->start, in ssi_port_get_iomem()
1100 resource_size(mem), dev_name(&pd->dev)); in ssi_port_get_iomem()
1102 dev_err(&pd->dev, "%s IO memory region request failed\n", in ssi_port_get_iomem()
1103 mem->name); in ssi_port_get_iomem()
1104 return -ENXIO; in ssi_port_get_iomem()
1106 base = devm_ioremap(&port->device, mem->start, resource_size(mem)); in ssi_port_get_iomem()
1108 dev_err(&pd->dev, "%s IO remap failed\n", mem->name); in ssi_port_get_iomem()
1109 return -ENXIO; in ssi_port_get_iomem()
1114 *phy = mem->start; in ssi_port_get_iomem()
1121 struct device_node *np = pd->dev.of_node; in ssi_port_probe()
1124 struct hsi_controller *ssi = dev_get_drvdata(pd->dev.parent); in ssi_port_probe()
1130 dev_dbg(&pd->dev, "init ssi port...\n"); in ssi_port_probe()
1132 if (!ssi->port || !omap_ssi->port) { in ssi_port_probe()
1133 dev_err(&pd->dev, "ssi controller not initialized!\n"); in ssi_port_probe()
1134 err = -ENODEV; in ssi_port_probe()
1139 for (port_id = 0; port_id < ssi->num_ports && omap_ssi->port[port_id]; in ssi_port_probe()
1143 if (port_id >= ssi->num_ports) { in ssi_port_probe()
1144 dev_err(&pd->dev, "port id out of range!\n"); in ssi_port_probe()
1145 err = -ENODEV; in ssi_port_probe()
1149 port = ssi->port[port_id]; in ssi_port_probe()
1152 dev_err(&pd->dev, "missing device tree data\n"); in ssi_port_probe()
1153 err = -EINVAL; in ssi_port_probe()
1157 cawake_gpio = devm_gpiod_get(&pd->dev, "ti,ssi-cawake", GPIOD_IN); in ssi_port_probe()
1160 dev_err(&pd->dev, "couldn't get cawake gpio (err=%d)!\n", err); in ssi_port_probe()
1164 omap_port = devm_kzalloc(&port->device, sizeof(*omap_port), GFP_KERNEL); in ssi_port_probe()
1166 err = -ENOMEM; in ssi_port_probe()
1169 omap_port->wake_gpio = cawake_gpio; in ssi_port_probe()
1170 omap_port->pdev = &pd->dev; in ssi_port_probe()
1171 omap_port->port_id = port_id; in ssi_port_probe()
1173 INIT_DEFERRABLE_WORK(&omap_port->errqueue_work, ssi_process_errqueue); in ssi_port_probe()
1174 INIT_WORK(&omap_port->work, start_tx_work); in ssi_port_probe()
1177 port->async = ssi_async; in ssi_port_probe()
1178 port->setup = ssi_setup; in ssi_port_probe()
1179 port->flush = ssi_flush; in ssi_port_probe()
1180 port->start_tx = ssi_start_tx; in ssi_port_probe()
1181 port->stop_tx = ssi_stop_tx; in ssi_port_probe()
1182 port->release = ssi_release; in ssi_port_probe()
1184 omap_ssi->port[port_id] = omap_port; in ssi_port_probe()
1188 err = ssi_port_get_iomem(pd, "tx", &omap_port->sst_base, in ssi_port_probe()
1189 &omap_port->sst_dma); in ssi_port_probe()
1192 err = ssi_port_get_iomem(pd, "rx", &omap_port->ssr_base, in ssi_port_probe()
1193 &omap_port->ssr_dma); in ssi_port_probe()
1205 spin_lock_init(&omap_port->lock); in ssi_port_probe()
1206 spin_lock_init(&omap_port->wk_lock); in ssi_port_probe()
1207 omap_port->dev = &port->device; in ssi_port_probe()
1209 pm_runtime_use_autosuspend(omap_port->pdev); in ssi_port_probe()
1210 pm_runtime_set_autosuspend_delay(omap_port->pdev, 250); in ssi_port_probe()
1211 pm_runtime_enable(omap_port->pdev); in ssi_port_probe()
1214 ssi_debug_add_port(omap_port, omap_ssi->dir); in ssi_port_probe()
1219 dev_info(&pd->dev, "ssi port %u successfully initialized\n", port_id); in ssi_port_probe()
1231 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_port_remove()
1238 cancel_delayed_work_sync(&omap_port->errqueue_work); in ssi_port_remove()
1242 port->async = hsi_dummy_msg; in ssi_port_remove()
1243 port->setup = hsi_dummy_cl; in ssi_port_remove()
1244 port->flush = hsi_dummy_cl; in ssi_port_remove()
1245 port->start_tx = hsi_dummy_cl; in ssi_port_remove()
1246 port->stop_tx = hsi_dummy_cl; in ssi_port_remove()
1247 port->release = hsi_dummy_cl; in ssi_port_remove()
1249 omap_ssi->port[omap_port->port_id] = NULL; in ssi_port_remove()
1252 pm_runtime_dont_use_autosuspend(&pd->dev); in ssi_port_remove()
1253 pm_runtime_disable(&pd->dev); in ssi_port_remove()
1258 writel_relaxed(omap_port->sst.divisor, in ssi_restore_divisor()
1259 omap_port->sst_base + SSI_SST_DIVISOR_REG); in ssi_restore_divisor()
1269 omap_port->sst.divisor = div; in omap_ssi_port_update_fclk()
1276 struct hsi_port *port = to_hsi_port(omap_port->dev); in ssi_save_port_ctx()
1277 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_save_port_ctx()
1280 omap_port->sys_mpu_enable = readl(omap_ssi->sys + in ssi_save_port_ctx()
1281 SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_save_port_ctx()
1288 struct hsi_port *port = to_hsi_port(omap_port->dev); in ssi_restore_port_ctx()
1289 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in ssi_restore_port_ctx()
1293 writel_relaxed(omap_port->sys_mpu_enable, in ssi_restore_port_ctx()
1294 omap_ssi->sys + SSI_MPU_ENABLE_REG(port->num, 0)); in ssi_restore_port_ctx()
1297 base = omap_port->sst_base; in ssi_restore_port_ctx()
1298 writel_relaxed(omap_port->sst.frame_size, base + SSI_SST_FRAMESIZE_REG); in ssi_restore_port_ctx()
1299 writel_relaxed(omap_port->sst.channels, base + SSI_SST_CHANNELS_REG); in ssi_restore_port_ctx()
1300 writel_relaxed(omap_port->sst.arb_mode, base + SSI_SST_ARBMODE_REG); in ssi_restore_port_ctx()
1303 base = omap_port->ssr_base; in ssi_restore_port_ctx()
1304 writel_relaxed(omap_port->ssr.frame_size, base + SSI_SSR_FRAMESIZE_REG); in ssi_restore_port_ctx()
1305 writel_relaxed(omap_port->ssr.channels, base + SSI_SSR_CHANNELS_REG); in ssi_restore_port_ctx()
1306 writel_relaxed(omap_port->ssr.timeout, base + SSI_SSR_TIMEOUT_REG); in ssi_restore_port_ctx()
1315 writel_relaxed(omap_port->sst.mode, in ssi_restore_port_mode()
1316 omap_port->sst_base + SSI_SST_MODE_REG); in ssi_restore_port_mode()
1317 writel_relaxed(omap_port->ssr.mode, in ssi_restore_port_mode()
1318 omap_port->ssr_base + SSI_SSR_MODE_REG); in ssi_restore_port_mode()
1320 mode = readl(omap_port->ssr_base + SSI_SSR_MODE_REG); in ssi_restore_port_mode()
1329 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in omap_ssi_port_runtime_suspend()
1335 if (omap_ssi->get_loss) in omap_ssi_port_runtime_suspend()
1336 omap_port->loss_count = in omap_ssi_port_runtime_suspend()
1337 omap_ssi->get_loss(ssi->device.parent); in omap_ssi_port_runtime_suspend()
1347 struct hsi_controller *ssi = to_hsi_controller(port->device.parent); in omap_ssi_port_runtime_resume()
1352 if ((omap_ssi->get_loss) && (omap_port->loss_count == in omap_ssi_port_runtime_resume()
1353 omap_ssi->get_loss(ssi->device.parent))) in omap_ssi_port_runtime_resume()
1378 { .compatible = "ti,omap3-ssi-port", },