Lines Matching +full:slim +full:- +full:ngd

1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
11 #include <linux/dma-mapping.h>
26 /* NGD (Non-ported Generic Device) registers */
153 struct qcom_slim_ngd *ngd; member
355 rc = qmi_txn_init(ctrl->qmi.handle, &txn, in qcom_slim_qmi_send_select_inst_req()
358 dev_err(ctrl->dev, "QMI TXN init fail: %d\n", rc); in qcom_slim_qmi_send_select_inst_req()
362 rc = qmi_send_request(ctrl->qmi.handle, NULL, &txn, in qcom_slim_qmi_send_select_inst_req()
367 dev_err(ctrl->dev, "QMI send req fail %d\n", rc); in qcom_slim_qmi_send_select_inst_req()
374 dev_err(ctrl->dev, "QMI TXN wait fail: %d\n", rc); in qcom_slim_qmi_send_select_inst_req()
379 dev_err(ctrl->dev, "QMI request failed 0x%x\n", in qcom_slim_qmi_send_select_inst_req()
381 return -EREMOTEIO; in qcom_slim_qmi_send_select_inst_req()
394 if (resp->resp.result != QMI_RESULT_SUCCESS_V01) in qcom_slim_qmi_power_resp_cb()
396 resp->resp.result); in qcom_slim_qmi_power_resp_cb()
398 complete(&txn->completion); in qcom_slim_qmi_power_resp_cb()
408 rc = qmi_txn_init(ctrl->qmi.handle, &txn, in qcom_slim_qmi_send_power_request()
411 rc = qmi_send_request(ctrl->qmi.handle, NULL, &txn, in qcom_slim_qmi_send_power_request()
416 dev_err(ctrl->dev, "QMI send req fail %d\n", rc); in qcom_slim_qmi_send_power_request()
423 dev_err(ctrl->dev, "QMI TXN wait fail: %d\n", rc); in qcom_slim_qmi_send_power_request()
429 dev_err(ctrl->dev, "QMI request failed 0x%x\n", in qcom_slim_qmi_send_power_request()
431 return -EREMOTEIO; in qcom_slim_qmi_send_power_request()
455 handle = devm_kzalloc(ctrl->dev, sizeof(*handle), GFP_KERNEL); in qcom_slim_qmi_init()
457 return -ENOMEM; in qcom_slim_qmi_init()
462 dev_err(ctrl->dev, "QMI client init failed: %d\n", rc); in qcom_slim_qmi_init()
466 rc = kernel_connect(handle->sock, in qcom_slim_qmi_init()
467 (struct sockaddr *)&ctrl->qmi.svc_info, in qcom_slim_qmi_init()
468 sizeof(ctrl->qmi.svc_info), 0); in qcom_slim_qmi_init()
470 dev_err(ctrl->dev, "Remote Service connect failed: %d\n", rc); in qcom_slim_qmi_init()
475 req.instance = (ctrl->ngd->id >> 1); in qcom_slim_qmi_init()
484 ctrl->qmi.handle = handle; in qcom_slim_qmi_init()
488 dev_err(ctrl->dev, "failed to select h/w instance\n"); in qcom_slim_qmi_init()
495 ctrl->qmi.handle = NULL; in qcom_slim_qmi_init()
499 devm_kfree(ctrl->dev, handle); in qcom_slim_qmi_init()
505 if (!ctrl->qmi.handle) in qcom_slim_qmi_exit()
508 qmi_handle_release(ctrl->qmi.handle); in qcom_slim_qmi_exit()
509 devm_kfree(ctrl->dev, ctrl->qmi.handle); in qcom_slim_qmi_exit()
510 ctrl->qmi.handle = NULL; in qcom_slim_qmi_exit()
534 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_get()
536 if ((ctrl->tx_tail + 1) % QCOM_SLIM_NGD_DESC_NUM == ctrl->tx_head) { in qcom_slim_ngd_tx_msg_get()
537 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_get()
540 desc = &ctrl->txdesc[ctrl->tx_tail]; in qcom_slim_ngd_tx_msg_get()
541 desc->base = ctrl->tx_base + ctrl->tx_tail * SLIM_MSGQ_BUF_LEN; in qcom_slim_ngd_tx_msg_get()
542 desc->comp = comp; in qcom_slim_ngd_tx_msg_get()
543 ctrl->tx_tail = (ctrl->tx_tail + 1) % QCOM_SLIM_NGD_DESC_NUM; in qcom_slim_ngd_tx_msg_get()
545 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_get()
547 return desc->base; in qcom_slim_ngd_tx_msg_get()
553 struct qcom_slim_ngd_ctrl *ctrl = desc->ctrl; in qcom_slim_ngd_tx_msg_dma_cb()
556 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_dma_cb()
558 if (desc->comp) { in qcom_slim_ngd_tx_msg_dma_cb()
559 complete(desc->comp); in qcom_slim_ngd_tx_msg_dma_cb()
560 desc->comp = NULL; in qcom_slim_ngd_tx_msg_dma_cb()
563 ctrl->tx_head = (ctrl->tx_head + 1) % QCOM_SLIM_NGD_DESC_NUM; in qcom_slim_ngd_tx_msg_dma_cb()
564 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_dma_cb()
574 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_post()
575 offset = buf - ctrl->tx_base; in qcom_slim_ngd_tx_msg_post()
578 desc = &ctrl->txdesc[index]; in qcom_slim_ngd_tx_msg_post()
579 desc->phys = ctrl->tx_phys_base + offset; in qcom_slim_ngd_tx_msg_post()
580 desc->base = ctrl->tx_base + offset; in qcom_slim_ngd_tx_msg_post()
581 desc->ctrl = ctrl; in qcom_slim_ngd_tx_msg_post()
584 desc->desc = dmaengine_prep_slave_single(ctrl->dma_tx_channel, in qcom_slim_ngd_tx_msg_post()
585 desc->phys, len, in qcom_slim_ngd_tx_msg_post()
588 if (!desc->desc) { in qcom_slim_ngd_tx_msg_post()
589 dev_err(ctrl->dev, "unable to prepare channel\n"); in qcom_slim_ngd_tx_msg_post()
590 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_post()
591 return -EINVAL; in qcom_slim_ngd_tx_msg_post()
594 desc->desc->callback = qcom_slim_ngd_tx_msg_dma_cb; in qcom_slim_ngd_tx_msg_post()
595 desc->desc->callback_param = desc; in qcom_slim_ngd_tx_msg_post()
596 desc->desc->cookie = dmaengine_submit(desc->desc); in qcom_slim_ngd_tx_msg_post()
597 dma_async_issue_pending(ctrl->dma_tx_channel); in qcom_slim_ngd_tx_msg_post()
598 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_post()
613 queue_work(ctrl->mwq, &ctrl->m_work); in qcom_slim_ngd_rx()
620 slim_msg_response(&ctrl->ctrl, &buf[4], buf[3], len - 4); in qcom_slim_ngd_rx()
621 pm_runtime_mark_last_busy(ctrl->ctrl.dev); in qcom_slim_ngd_rx()
628 struct qcom_slim_ngd_ctrl *ctrl = desc->ctrl; in qcom_slim_ngd_rx_msgq_cb()
630 qcom_slim_ngd_rx(ctrl, (u8 *)desc->base); in qcom_slim_ngd_rx_msgq_cb()
632 desc->desc = dmaengine_prep_slave_single(ctrl->dma_rx_channel, in qcom_slim_ngd_rx_msgq_cb()
633 desc->phys, SLIM_MSGQ_BUF_LEN, in qcom_slim_ngd_rx_msgq_cb()
636 if (!desc->desc) { in qcom_slim_ngd_rx_msgq_cb()
637 dev_err(ctrl->dev, "Unable to prepare rx channel\n"); in qcom_slim_ngd_rx_msgq_cb()
641 desc->desc->callback = qcom_slim_ngd_rx_msgq_cb; in qcom_slim_ngd_rx_msgq_cb()
642 desc->desc->callback_param = desc; in qcom_slim_ngd_rx_msgq_cb()
643 desc->desc->cookie = dmaengine_submit(desc->desc); in qcom_slim_ngd_rx_msgq_cb()
644 dma_async_issue_pending(ctrl->dma_rx_channel); in qcom_slim_ngd_rx_msgq_cb()
653 desc = &ctrl->rx_desc[i]; in qcom_slim_ngd_post_rx_msgq()
654 desc->phys = ctrl->rx_phys_base + i * SLIM_MSGQ_BUF_LEN; in qcom_slim_ngd_post_rx_msgq()
655 desc->ctrl = ctrl; in qcom_slim_ngd_post_rx_msgq()
656 desc->base = ctrl->rx_base + i * SLIM_MSGQ_BUF_LEN; in qcom_slim_ngd_post_rx_msgq()
657 desc->desc = dmaengine_prep_slave_single(ctrl->dma_rx_channel, in qcom_slim_ngd_post_rx_msgq()
658 desc->phys, SLIM_MSGQ_BUF_LEN, in qcom_slim_ngd_post_rx_msgq()
661 if (!desc->desc) { in qcom_slim_ngd_post_rx_msgq()
662 dev_err(ctrl->dev, "Unable to prepare rx channel\n"); in qcom_slim_ngd_post_rx_msgq()
663 return -EINVAL; in qcom_slim_ngd_post_rx_msgq()
666 desc->desc->callback = qcom_slim_ngd_rx_msgq_cb; in qcom_slim_ngd_post_rx_msgq()
667 desc->desc->callback_param = desc; in qcom_slim_ngd_post_rx_msgq()
668 desc->desc->cookie = dmaengine_submit(desc->desc); in qcom_slim_ngd_post_rx_msgq()
670 dma_async_issue_pending(ctrl->dma_rx_channel); in qcom_slim_ngd_post_rx_msgq()
677 struct device *dev = ctrl->dev; in qcom_slim_ngd_init_rx_msgq()
680 ctrl->dma_rx_channel = dma_request_chan(dev, "rx"); in qcom_slim_ngd_init_rx_msgq()
681 if (IS_ERR(ctrl->dma_rx_channel)) { in qcom_slim_ngd_init_rx_msgq()
683 ret = PTR_ERR(ctrl->dma_rx_channel); in qcom_slim_ngd_init_rx_msgq()
684 ctrl->dma_rx_channel = NULL; in qcom_slim_ngd_init_rx_msgq()
689 ctrl->rx_base = dma_alloc_coherent(dev, size, &ctrl->rx_phys_base, in qcom_slim_ngd_init_rx_msgq()
691 if (!ctrl->rx_base) { in qcom_slim_ngd_init_rx_msgq()
692 ret = -ENOMEM; in qcom_slim_ngd_init_rx_msgq()
705 dma_free_coherent(dev, size, ctrl->rx_base, ctrl->rx_phys_base); in qcom_slim_ngd_init_rx_msgq()
707 dma_release_channel(ctrl->dma_rx_channel); in qcom_slim_ngd_init_rx_msgq()
713 struct device *dev = ctrl->dev; in qcom_slim_ngd_init_tx_msgq()
718 ctrl->dma_tx_channel = dma_request_chan(dev, "tx"); in qcom_slim_ngd_init_tx_msgq()
719 if (IS_ERR(ctrl->dma_tx_channel)) { in qcom_slim_ngd_init_tx_msgq()
721 ret = PTR_ERR(ctrl->dma_tx_channel); in qcom_slim_ngd_init_tx_msgq()
722 ctrl->dma_tx_channel = NULL; in qcom_slim_ngd_init_tx_msgq()
727 ctrl->tx_base = dma_alloc_coherent(dev, size, &ctrl->tx_phys_base, in qcom_slim_ngd_init_tx_msgq()
729 if (!ctrl->tx_base) { in qcom_slim_ngd_init_tx_msgq()
730 ret = -EINVAL; in qcom_slim_ngd_init_tx_msgq()
734 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_init_tx_msgq()
735 ctrl->tx_tail = 0; in qcom_slim_ngd_init_tx_msgq()
736 ctrl->tx_head = 0; in qcom_slim_ngd_init_tx_msgq()
737 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_init_tx_msgq()
741 dma_release_channel(ctrl->dma_tx_channel); in qcom_slim_ngd_init_tx_msgq()
751 dev_err(ctrl->dev, "rx dma init failed\n"); in qcom_slim_ngd_init_dma()
757 dev_err(ctrl->dev, "tx dma init failed\n"); in qcom_slim_ngd_init_dma()
765 void __iomem *base = ctrl->ngd->base; in qcom_slim_ngd_interrupt()
768 if (pm_runtime_suspended(ctrl->ctrl.dev)) { in qcom_slim_ngd_interrupt()
769 dev_warn_once(ctrl->dev, "Interrupt received while suspended\n"); in qcom_slim_ngd_interrupt()
778 dev_err(ctrl->dev, "Error Interrupt received 0x%x\n", stat); in qcom_slim_ngd_interrupt()
789 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(sctrl->dev); in qcom_slim_ngd_xfer_msg()
797 u8 la = txn->la; in qcom_slim_ngd_xfer_msg()
800 if (txn->mt == SLIM_MSG_MT_CORE && in qcom_slim_ngd_xfer_msg()
801 (txn->mc >= SLIM_MSG_MC_BEGIN_RECONFIGURATION && in qcom_slim_ngd_xfer_msg()
802 txn->mc <= SLIM_MSG_MC_RECONFIGURE_NOW)) in qcom_slim_ngd_xfer_msg()
805 if (txn->dt == SLIM_MSG_DEST_ENUMADDR) in qcom_slim_ngd_xfer_msg()
806 return -EPROTONOSUPPORT; in qcom_slim_ngd_xfer_msg()
808 if (txn->msg->num_bytes > SLIM_MSGQ_BUF_LEN || in qcom_slim_ngd_xfer_msg()
809 txn->rl > SLIM_MSGQ_BUF_LEN) { in qcom_slim_ngd_xfer_msg()
810 dev_err(ctrl->dev, "msg exceeds HW limit\n"); in qcom_slim_ngd_xfer_msg()
811 return -EINVAL; in qcom_slim_ngd_xfer_msg()
814 pbuf = qcom_slim_ngd_tx_msg_get(ctrl, txn->rl, &tx_sent); in qcom_slim_ngd_xfer_msg()
816 dev_err(ctrl->dev, "Message buffer unavailable\n"); in qcom_slim_ngd_xfer_msg()
817 return -ENOMEM; in qcom_slim_ngd_xfer_msg()
820 if (txn->mt == SLIM_MSG_MT_CORE && in qcom_slim_ngd_xfer_msg()
821 (txn->mc == SLIM_MSG_MC_CONNECT_SOURCE || in qcom_slim_ngd_xfer_msg()
822 txn->mc == SLIM_MSG_MC_CONNECT_SINK || in qcom_slim_ngd_xfer_msg()
823 txn->mc == SLIM_MSG_MC_DISCONNECT_PORT)) { in qcom_slim_ngd_xfer_msg()
824 txn->mt = SLIM_MSG_MT_DEST_REFERRED_USER; in qcom_slim_ngd_xfer_msg()
825 switch (txn->mc) { in qcom_slim_ngd_xfer_msg()
827 txn->mc = SLIM_USR_MC_CONNECT_SRC; in qcom_slim_ngd_xfer_msg()
830 txn->mc = SLIM_USR_MC_CONNECT_SINK; in qcom_slim_ngd_xfer_msg()
833 txn->mc = SLIM_USR_MC_DISCONNECT_PORT; in qcom_slim_ngd_xfer_msg()
836 return -EINVAL; in qcom_slim_ngd_xfer_msg()
841 wbuf[i++] = txn->la; in qcom_slim_ngd_xfer_msg()
843 wbuf[i++] = txn->msg->wbuf[0]; in qcom_slim_ngd_xfer_msg()
844 if (txn->mc != SLIM_USR_MC_DISCONNECT_PORT) in qcom_slim_ngd_xfer_msg()
845 wbuf[i++] = txn->msg->wbuf[1]; in qcom_slim_ngd_xfer_msg()
847 txn->comp = &done; in qcom_slim_ngd_xfer_msg()
850 dev_err(ctrl->dev, "Unable to allocate TID\n"); in qcom_slim_ngd_xfer_msg()
854 wbuf[i++] = txn->tid; in qcom_slim_ngd_xfer_msg()
856 txn->msg->num_bytes = i; in qcom_slim_ngd_xfer_msg()
857 txn->msg->wbuf = wbuf; in qcom_slim_ngd_xfer_msg()
858 txn->msg->rbuf = rbuf; in qcom_slim_ngd_xfer_msg()
859 txn->rl = txn->msg->num_bytes + 4; in qcom_slim_ngd_xfer_msg()
863 txn->rl--; in qcom_slim_ngd_xfer_msg()
866 if (txn->dt == SLIM_MSG_DEST_LOGICALADDR) { in qcom_slim_ngd_xfer_msg()
867 *pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, txn->mc, 0, in qcom_slim_ngd_xfer_msg()
871 *pbuf = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, txn->mc, 1, in qcom_slim_ngd_xfer_msg()
876 if (slim_tid_txn(txn->mt, txn->mc)) in qcom_slim_ngd_xfer_msg()
877 *(puc++) = txn->tid; in qcom_slim_ngd_xfer_msg()
879 if (slim_ec_txn(txn->mt, txn->mc)) { in qcom_slim_ngd_xfer_msg()
880 *(puc++) = (txn->ec & 0xFF); in qcom_slim_ngd_xfer_msg()
881 *(puc++) = (txn->ec >> 8) & 0xFF; in qcom_slim_ngd_xfer_msg()
884 if (txn->msg && txn->msg->wbuf) in qcom_slim_ngd_xfer_msg()
885 memcpy(puc, txn->msg->wbuf, txn->msg->num_bytes); in qcom_slim_ngd_xfer_msg()
887 mutex_lock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
888 ret = qcom_slim_ngd_tx_msg_post(ctrl, pbuf, txn->rl); in qcom_slim_ngd_xfer_msg()
890 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
896 dev_err(sctrl->dev, "TX timed out:MC:0x%x,mt:0x%x", txn->mc, in qcom_slim_ngd_xfer_msg()
897 txn->mt); in qcom_slim_ngd_xfer_msg()
898 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
899 return -ETIMEDOUT; in qcom_slim_ngd_xfer_msg()
905 dev_err(sctrl->dev, "TX timed out:MC:0x%x,mt:0x%x", in qcom_slim_ngd_xfer_msg()
906 txn->mc, txn->mt); in qcom_slim_ngd_xfer_msg()
907 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
908 return -ETIMEDOUT; in qcom_slim_ngd_xfer_msg()
912 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
922 ret = pm_runtime_get_sync(ctrl->dev); in qcom_slim_ngd_xfer_msg_sync()
926 txn->comp = &done; in qcom_slim_ngd_xfer_msg_sync()
934 dev_err(ctrl->dev, "TX timed out:MC:0x%x,mt:0x%x", txn->mc, in qcom_slim_ngd_xfer_msg_sync()
935 txn->mt); in qcom_slim_ngd_xfer_msg_sync()
936 ret = -ETIMEDOUT; in qcom_slim_ngd_xfer_msg_sync()
942 pm_runtime_put(ctrl->dev); in qcom_slim_ngd_xfer_msg_sync()
949 struct slim_controller *ctrl = rt->dev->ctrl; in qcom_slim_calc_coef()
952 if (rt->ratem * ctrl->a_framer->superfreq < rt->rate) in qcom_slim_calc_coef()
953 rt->ratem++; in qcom_slim_calc_coef()
955 coef = rt->ratem; in qcom_slim_calc_coef()
984 return -EIO; in qcom_slim_calc_coef()
988 return -EIO; in qcom_slim_calc_coef()
997 struct slim_device *sdev = rt->dev; in qcom_slim_ngd_enable_stream()
998 struct slim_controller *ctrl = sdev->ctrl; in qcom_slim_ngd_enable_stream()
1010 txn.msg->num_bytes = 0; in qcom_slim_ngd_enable_stream()
1011 txn.msg->wbuf = wbuf; in qcom_slim_ngd_enable_stream()
1012 txn.msg->rbuf = rbuf; in qcom_slim_ngd_enable_stream()
1014 for (i = 0; i < rt->num_ports; i++) { in qcom_slim_ngd_enable_stream()
1015 struct slim_port *port = &rt->ports[i]; in qcom_slim_ngd_enable_stream()
1017 if (txn.msg->num_bytes == 0) { in qcom_slim_ngd_enable_stream()
1020 wbuf[txn.msg->num_bytes++] = sdev->laddr; in qcom_slim_ngd_enable_stream()
1021 wbuf[txn.msg->num_bytes] = rt->bps >> 2 | in qcom_slim_ngd_enable_stream()
1022 (port->ch.aux_fmt << 6); in qcom_slim_ngd_enable_stream()
1027 dev_err(&sdev->dev, in qcom_slim_ngd_enable_stream()
1030 return -EIO; in qcom_slim_ngd_enable_stream()
1034 wbuf[txn.msg->num_bytes] |= BIT(5); in qcom_slim_ngd_enable_stream()
1036 txn.msg->num_bytes++; in qcom_slim_ngd_enable_stream()
1037 wbuf[txn.msg->num_bytes++] = exp << 4 | rt->prot; in qcom_slim_ngd_enable_stream()
1039 if (rt->prot == SLIM_PROTO_ISO) in qcom_slim_ngd_enable_stream()
1040 wbuf[txn.msg->num_bytes++] = in qcom_slim_ngd_enable_stream()
1041 port->ch.prrate | in qcom_slim_ngd_enable_stream()
1044 wbuf[txn.msg->num_bytes++] = port->ch.prrate; in qcom_slim_ngd_enable_stream()
1048 dev_err(&sdev->dev, "Fail to allocate TID\n"); in qcom_slim_ngd_enable_stream()
1049 return -ENXIO; in qcom_slim_ngd_enable_stream()
1051 wbuf[txn.msg->num_bytes++] = txn.tid; in qcom_slim_ngd_enable_stream()
1053 wbuf[txn.msg->num_bytes++] = port->ch.id; in qcom_slim_ngd_enable_stream()
1057 txn.rl = txn.msg->num_bytes + 4; in qcom_slim_ngd_enable_stream()
1061 dev_err(&sdev->dev, "TX timed out:MC:0x%x,mt:0x%x", txn.mc, in qcom_slim_ngd_enable_stream()
1067 txn.msg->num_bytes = 2; in qcom_slim_ngd_enable_stream()
1068 wbuf[1] = sdev->laddr; in qcom_slim_ngd_enable_stream()
1069 txn.rl = txn.msg->num_bytes + 4; in qcom_slim_ngd_enable_stream()
1073 dev_err(ctrl->dev, "Fail to allocate TID\n"); in qcom_slim_ngd_enable_stream()
1081 dev_err(&sdev->dev, "TX timed out:MC:0x%x,mt:0x%x", txn.mc, in qcom_slim_ngd_enable_stream()
1106 txn.msg->num_bytes = 7; in qcom_slim_ngd_get_laddr()
1107 txn.msg->wbuf = wbuf; in qcom_slim_ngd_get_laddr()
1108 txn.msg->rbuf = rbuf; in qcom_slim_ngd_get_laddr()
1124 return -ENXIO; in qcom_slim_ngd_get_laddr()
1133 if (ctrl->dma_rx_channel) { in qcom_slim_ngd_exit_dma()
1134 dmaengine_terminate_sync(ctrl->dma_rx_channel); in qcom_slim_ngd_exit_dma()
1135 dma_release_channel(ctrl->dma_rx_channel); in qcom_slim_ngd_exit_dma()
1138 if (ctrl->dma_tx_channel) { in qcom_slim_ngd_exit_dma()
1139 dmaengine_terminate_sync(ctrl->dma_tx_channel); in qcom_slim_ngd_exit_dma()
1140 dma_release_channel(ctrl->dma_tx_channel); in qcom_slim_ngd_exit_dma()
1143 ctrl->dma_tx_channel = ctrl->dma_rx_channel = NULL; in qcom_slim_ngd_exit_dma()
1150 u32 cfg = readl_relaxed(ctrl->ngd->base); in qcom_slim_ngd_setup()
1152 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN || in qcom_slim_ngd_setup()
1153 ctrl->state == QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_setup()
1160 /* Enable NGD if it's not already enabled*/ in qcom_slim_ngd_setup()
1164 writel_relaxed(cfg, ctrl->ngd->base); in qcom_slim_ngd_setup()
1169 enum qcom_slim_ngd_state cur_state = ctrl->state; in qcom_slim_ngd_power_up()
1170 struct qcom_slim_ngd *ngd = ctrl->ngd; in qcom_slim_ngd_power_up() local
1174 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_power_up()
1175 timeout = wait_for_completion_timeout(&ctrl->qmi.qmi_comp, HZ); in qcom_slim_ngd_power_up()
1177 return -EREMOTEIO; in qcom_slim_ngd_power_up()
1180 if (ctrl->state == QCOM_SLIM_NGD_CTRL_ASLEEP || in qcom_slim_ngd_power_up()
1181 ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_power_up()
1184 dev_err(ctrl->dev, "SLIM QMI power request failed:%d\n", in qcom_slim_ngd_power_up()
1190 ctrl->ver = readl_relaxed(ctrl->base); in qcom_slim_ngd_power_up()
1192 ctrl->ver >>= 16; in qcom_slim_ngd_power_up()
1194 laddr = readl_relaxed(ngd->base + NGD_STATUS); in qcom_slim_ngd_power_up()
1201 dev_info(ctrl->dev, "Subsys restart: ADSP active framer\n"); in qcom_slim_ngd_power_up()
1210 * is lost for ngd. in qcom_slim_ngd_power_up()
1212 reinit_completion(&ctrl->reconf); in qcom_slim_ngd_power_up()
1214 writel_relaxed(DEF_NGD_INT_MASK, ngd->base + NGD_INT_EN); in qcom_slim_ngd_power_up()
1215 rx_msgq = readl_relaxed(ngd->base + NGD_RX_MSGQ_CFG); in qcom_slim_ngd_power_up()
1218 ngd->base + NGD_RX_MSGQ_CFG); in qcom_slim_ngd_power_up()
1221 timeout = wait_for_completion_timeout(&ctrl->reconf, HZ); in qcom_slim_ngd_power_up()
1223 dev_err(ctrl->dev, "capability exchange timed-out\n"); in qcom_slim_ngd_power_up()
1224 return -ETIMEDOUT; in qcom_slim_ngd_power_up()
1235 for_each_child_of_node(ctrl->ngd->pdev->dev.of_node, node) { in qcom_slim_ngd_notify_slaves()
1236 sbdev = of_slim_get_device(&ctrl->ctrl, node); in qcom_slim_ngd_notify_slaves()
1241 dev_err(ctrl->dev, "Failed to get logical address\n"); in qcom_slim_ngd_notify_slaves()
1265 txn.msg->wbuf = wbuf; in qcom_slim_ngd_master_worker()
1266 txn.msg->num_bytes = 4; in qcom_slim_ngd_master_worker()
1269 dev_info(ctrl->dev, "SLIM SAT: Rcvd master capability\n"); in qcom_slim_ngd_master_worker()
1272 ret = qcom_slim_ngd_xfer_msg(&ctrl->ctrl, &txn); in qcom_slim_ngd_master_worker()
1274 if (ctrl->state >= QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_master_worker()
1275 complete(&ctrl->reconf); in qcom_slim_ngd_master_worker()
1277 dev_err(ctrl->dev, "unexpected state:%d\n", in qcom_slim_ngd_master_worker()
1278 ctrl->state); in qcom_slim_ngd_master_worker()
1280 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) in qcom_slim_ngd_master_worker()
1283 } else if (ret == -EIO) { in qcom_slim_ngd_master_worker()
1284 dev_err(ctrl->dev, "capability message NACKed, retrying\n"); in qcom_slim_ngd_master_worker()
1291 dev_err(ctrl->dev, "SLIM: capability TX failed:%d\n", ret); in qcom_slim_ngd_master_worker()
1307 if (!ctrl->qmi.handle) in qcom_slim_ngd_runtime_resume()
1310 if (ctrl->state >= QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_runtime_resume()
1314 if (ctrl->state != QCOM_SLIM_NGD_CTRL_DOWN) in qcom_slim_ngd_runtime_resume()
1315 ctrl->state = QCOM_SLIM_NGD_CTRL_ASLEEP; in qcom_slim_ngd_runtime_resume()
1317 dev_err(ctrl->dev, "HW wakeup attempt during SSR\n"); in qcom_slim_ngd_runtime_resume()
1319 ctrl->state = QCOM_SLIM_NGD_CTRL_AWAKE; in qcom_slim_ngd_runtime_resume()
1331 dev_err(ctrl->dev, "qmi init fail, ret:%d, state:%d\n", in qcom_slim_ngd_enable()
1332 ret, ctrl->state); in qcom_slim_ngd_enable()
1336 complete(&ctrl->qmi.qmi_comp); in qcom_slim_ngd_enable()
1337 if (!pm_runtime_enabled(ctrl->ctrl.dev) || in qcom_slim_ngd_enable()
1338 !pm_runtime_suspended(ctrl->ctrl.dev)) in qcom_slim_ngd_enable()
1339 qcom_slim_ngd_runtime_resume(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1341 pm_runtime_resume(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1343 pm_runtime_mark_last_busy(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1344 pm_runtime_put(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1346 ret = slim_register_controller(&ctrl->ctrl); in qcom_slim_ngd_enable()
1348 dev_err(ctrl->dev, "error adding slim controller\n"); in qcom_slim_ngd_enable()
1352 dev_info(ctrl->dev, "SLIM controller Registered\n"); in qcom_slim_ngd_enable()
1355 slim_unregister_controller(&ctrl->ctrl); in qcom_slim_ngd_enable()
1369 qmi->svc_info.sq_family = AF_QIPCRTR; in qcom_slim_ngd_qmi_new_server()
1370 qmi->svc_info.sq_node = service->node; in qcom_slim_ngd_qmi_new_server()
1371 qmi->svc_info.sq_port = service->port; in qcom_slim_ngd_qmi_new_server()
1373 complete(&ctrl->qmi_up); in qcom_slim_ngd_qmi_new_server()
1386 reinit_completion(&ctrl->qmi_up); in qcom_slim_ngd_qmi_del_server()
1387 qmi->svc_info.sq_node = 0; in qcom_slim_ngd_qmi_del_server()
1388 qmi->svc_info.sq_port = 0; in qcom_slim_ngd_qmi_del_server()
1398 struct qcom_slim_ngd_qmi *qmi = &ctrl->qmi; in qcom_slim_ngd_qmi_svc_event_init()
1401 ret = qmi_handle_init(&qmi->svc_event_hdl, 0, in qcom_slim_ngd_qmi_svc_event_init()
1404 dev_err(ctrl->dev, "qmi_handle_init failed: %d\n", ret); in qcom_slim_ngd_qmi_svc_event_init()
1408 ret = qmi_add_lookup(&qmi->svc_event_hdl, SLIMBUS_QMI_SVC_ID, in qcom_slim_ngd_qmi_svc_event_init()
1411 dev_err(ctrl->dev, "qmi_add_lookup failed: %d\n", ret); in qcom_slim_ngd_qmi_svc_event_init()
1412 qmi_handle_release(&qmi->svc_event_hdl); in qcom_slim_ngd_qmi_svc_event_init()
1419 qmi_handle_release(&qmi->svc_event_hdl); in qcom_slim_ngd_qmi_svc_event_deinit()
1423 #define QCOM_SLIM_NGD_DRV_NAME "qcom,slim-ngd"
1427 .compatible = "qcom,slim-ngd-v1.5.0",
1430 .compatible = "qcom,slim-ngd-v2.1.0",
1440 mutex_lock(&ctrl->ssr_lock); in qcom_slim_ngd_down()
1441 device_for_each_child(ctrl->ctrl.dev, NULL, in qcom_slim_ngd_down()
1444 mutex_unlock(&ctrl->ssr_lock); in qcom_slim_ngd_down()
1454 if (!wait_for_completion_interruptible_timeout(&ctrl->qmi_up, in qcom_slim_ngd_up_worker()
1456 dev_err(ctrl->dev, "QMI wait timeout\n"); in qcom_slim_ngd_up_worker()
1460 mutex_lock(&ctrl->ssr_lock); in qcom_slim_ngd_up_worker()
1462 mutex_unlock(&ctrl->ssr_lock); in qcom_slim_ngd_up_worker()
1472 mutex_lock(&ctrl->tx_lock); in qcom_slim_ngd_ssr_pdr_notify()
1473 if (ctrl->state != QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_ssr_pdr_notify()
1474 pm_runtime_get_noresume(ctrl->ctrl.dev); in qcom_slim_ngd_ssr_pdr_notify()
1475 ctrl->state = QCOM_SLIM_NGD_CTRL_DOWN; in qcom_slim_ngd_ssr_pdr_notify()
1479 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_ssr_pdr_notify()
1483 schedule_work(&ctrl->ngd_up_work); in qcom_slim_ngd_ssr_pdr_notify()
1512 struct qcom_slim_ngd *ngd; in of_qcom_slim_ngd_register() local
1518 match = of_match_node(qcom_slim_ngd_dt_match, parent->of_node); in of_qcom_slim_ngd_register()
1519 data = match->data; in of_qcom_slim_ngd_register()
1520 for_each_available_child_of_node(parent->of_node, node) { in of_qcom_slim_ngd_register()
1524 ngd = kzalloc(sizeof(*ngd), GFP_KERNEL); in of_qcom_slim_ngd_register()
1525 if (!ngd) { in of_qcom_slim_ngd_register()
1527 return -ENOMEM; in of_qcom_slim_ngd_register()
1530 ngd->pdev = platform_device_alloc(QCOM_SLIM_NGD_DRV_NAME, id); in of_qcom_slim_ngd_register()
1531 if (!ngd->pdev) { in of_qcom_slim_ngd_register()
1532 kfree(ngd); in of_qcom_slim_ngd_register()
1534 return -ENOMEM; in of_qcom_slim_ngd_register()
1536 ngd->id = id; in of_qcom_slim_ngd_register()
1537 ngd->pdev->dev.parent = parent; in of_qcom_slim_ngd_register()
1539 ret = driver_set_override(&ngd->pdev->dev, in of_qcom_slim_ngd_register()
1540 &ngd->pdev->driver_override, in of_qcom_slim_ngd_register()
1544 platform_device_put(ngd->pdev); in of_qcom_slim_ngd_register()
1545 kfree(ngd); in of_qcom_slim_ngd_register()
1549 ngd->pdev->dev.of_node = node; in of_qcom_slim_ngd_register()
1550 ctrl->ngd = ngd; in of_qcom_slim_ngd_register()
1552 ret = platform_device_add(ngd->pdev); in of_qcom_slim_ngd_register()
1554 platform_device_put(ngd->pdev); in of_qcom_slim_ngd_register()
1555 kfree(ngd); in of_qcom_slim_ngd_register()
1559 ngd->base = ctrl->base + ngd->id * data->offset + in of_qcom_slim_ngd_register()
1560 (ngd->id - 1) * data->size; in of_qcom_slim_ngd_register()
1565 return -ENODEV; in of_qcom_slim_ngd_register()
1570 struct device *dev = &pdev->dev; in qcom_slim_ngd_probe()
1571 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev->parent); in qcom_slim_ngd_probe()
1574 ctrl->ctrl.dev = dev; in qcom_slim_ngd_probe()
1584 dev_err(&pdev->dev, "QMI service registration failed:%d", ret); in qcom_slim_ngd_probe()
1588 INIT_WORK(&ctrl->m_work, qcom_slim_ngd_master_worker); in qcom_slim_ngd_probe()
1589 INIT_WORK(&ctrl->ngd_up_work, qcom_slim_ngd_up_worker); in qcom_slim_ngd_probe()
1590 ctrl->mwq = create_singlethread_workqueue("ngd_master"); in qcom_slim_ngd_probe()
1591 if (!ctrl->mwq) { in qcom_slim_ngd_probe()
1592 dev_err(&pdev->dev, "Failed to start master worker\n"); in qcom_slim_ngd_probe()
1593 ret = -ENOMEM; in qcom_slim_ngd_probe()
1599 qcom_slim_ngd_qmi_svc_event_deinit(&ctrl->qmi); in qcom_slim_ngd_probe()
1600 if (ctrl->mwq) in qcom_slim_ngd_probe()
1601 destroy_workqueue(ctrl->mwq); in qcom_slim_ngd_probe()
1608 struct device *dev = &pdev->dev; in qcom_slim_ngd_ctrl_probe()
1615 return -ENOMEM; in qcom_slim_ngd_ctrl_probe()
1619 ctrl->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in qcom_slim_ngd_ctrl_probe()
1620 if (IS_ERR(ctrl->base)) in qcom_slim_ngd_ctrl_probe()
1621 return PTR_ERR(ctrl->base); in qcom_slim_ngd_ctrl_probe()
1628 IRQF_TRIGGER_HIGH, "slim-ngd", ctrl); in qcom_slim_ngd_ctrl_probe()
1630 return dev_err_probe(&pdev->dev, ret, "request IRQ failed\n"); in qcom_slim_ngd_ctrl_probe()
1632 ctrl->nb.notifier_call = qcom_slim_ngd_ssr_notify; in qcom_slim_ngd_ctrl_probe()
1633 ctrl->notifier = qcom_register_ssr_notifier("lpass", &ctrl->nb); in qcom_slim_ngd_ctrl_probe()
1634 if (IS_ERR(ctrl->notifier)) in qcom_slim_ngd_ctrl_probe()
1635 return PTR_ERR(ctrl->notifier); in qcom_slim_ngd_ctrl_probe()
1637 ctrl->dev = dev; in qcom_slim_ngd_ctrl_probe()
1638 ctrl->framer.rootfreq = SLIM_ROOT_FREQ >> 3; in qcom_slim_ngd_ctrl_probe()
1639 ctrl->framer.superfreq = in qcom_slim_ngd_ctrl_probe()
1640 ctrl->framer.rootfreq / SLIM_CL_PER_SUPERFRAME_DIV8; in qcom_slim_ngd_ctrl_probe()
1642 ctrl->ctrl.a_framer = &ctrl->framer; in qcom_slim_ngd_ctrl_probe()
1643 ctrl->ctrl.clkgear = SLIM_MAX_CLK_GEAR; in qcom_slim_ngd_ctrl_probe()
1644 ctrl->ctrl.get_laddr = qcom_slim_ngd_get_laddr; in qcom_slim_ngd_ctrl_probe()
1645 ctrl->ctrl.enable_stream = qcom_slim_ngd_enable_stream; in qcom_slim_ngd_ctrl_probe()
1646 ctrl->ctrl.xfer_msg = qcom_slim_ngd_xfer_msg; in qcom_slim_ngd_ctrl_probe()
1647 ctrl->ctrl.wakeup = NULL; in qcom_slim_ngd_ctrl_probe()
1648 ctrl->state = QCOM_SLIM_NGD_CTRL_DOWN; in qcom_slim_ngd_ctrl_probe()
1650 mutex_init(&ctrl->tx_lock); in qcom_slim_ngd_ctrl_probe()
1651 mutex_init(&ctrl->ssr_lock); in qcom_slim_ngd_ctrl_probe()
1652 spin_lock_init(&ctrl->tx_buf_lock); in qcom_slim_ngd_ctrl_probe()
1653 init_completion(&ctrl->reconf); in qcom_slim_ngd_ctrl_probe()
1654 init_completion(&ctrl->qmi.qmi_comp); in qcom_slim_ngd_ctrl_probe()
1655 init_completion(&ctrl->qmi_up); in qcom_slim_ngd_ctrl_probe()
1657 ctrl->pdr = pdr_handle_alloc(slim_pd_status, ctrl); in qcom_slim_ngd_ctrl_probe()
1658 if (IS_ERR(ctrl->pdr)) { in qcom_slim_ngd_ctrl_probe()
1659 ret = dev_err_probe(dev, PTR_ERR(ctrl->pdr), in qcom_slim_ngd_ctrl_probe()
1664 pds = pdr_add_lookup(ctrl->pdr, "avs/audio", "msm/adsp/audio_pd"); in qcom_slim_ngd_ctrl_probe()
1665 if (IS_ERR(pds) && PTR_ERR(pds) != -EALREADY) { in qcom_slim_ngd_ctrl_probe()
1674 qcom_unregister_ssr_notifier(ctrl->notifier, &ctrl->nb); in qcom_slim_ngd_ctrl_probe()
1677 pdr_handle_release(ctrl->pdr); in qcom_slim_ngd_ctrl_probe()
1693 pm_runtime_disable(&pdev->dev); in qcom_slim_ngd_remove()
1694 pdr_handle_release(ctrl->pdr); in qcom_slim_ngd_remove()
1695 qcom_unregister_ssr_notifier(ctrl->notifier, &ctrl->nb); in qcom_slim_ngd_remove()
1698 qcom_slim_ngd_qmi_svc_event_deinit(&ctrl->qmi); in qcom_slim_ngd_remove()
1699 if (ctrl->mwq) in qcom_slim_ngd_remove()
1700 destroy_workqueue(ctrl->mwq); in qcom_slim_ngd_remove()
1702 kfree(ctrl->ngd); in qcom_slim_ngd_remove()
1703 ctrl->ngd = NULL; in qcom_slim_ngd_remove()
1711 if (ctrl->state == QCOM_SLIM_NGD_CTRL_AWAKE) in qcom_slim_ngd_runtime_idle()
1712 ctrl->state = QCOM_SLIM_NGD_CTRL_IDLE; in qcom_slim_ngd_runtime_idle()
1714 return -EAGAIN; in qcom_slim_ngd_runtime_idle()
1723 if (!ctrl->qmi.handle) in qcom_slim_ngd_runtime_suspend()
1727 if (ret && ret != -EBUSY) in qcom_slim_ngd_runtime_suspend()
1728 dev_info(ctrl->dev, "slim resource not idle:%d\n", ret); in qcom_slim_ngd_runtime_suspend()
1729 if (!ret || ret == -ETIMEDOUT) in qcom_slim_ngd_runtime_suspend()
1730 ctrl->state = QCOM_SLIM_NGD_CTRL_ASLEEP; in qcom_slim_ngd_runtime_suspend()
1749 .name = "qcom,slim-ngd-ctrl",
1765 MODULE_DESCRIPTION("Qualcomm SLIMBus NGD controller");