Lines Matching full:ctrl
135 struct qcom_slim_ngd_ctrl *ctrl; member
150 struct slim_controller ctrl; member
347 static int qcom_slim_qmi_send_select_inst_req(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_qmi_send_select_inst_req() argument
354 rc = qmi_txn_init(ctrl->qmi.handle, &txn, in qcom_slim_qmi_send_select_inst_req()
357 dev_err(ctrl->dev, "QMI TXN init fail: %d\n", rc); in qcom_slim_qmi_send_select_inst_req()
361 rc = qmi_send_request(ctrl->qmi.handle, NULL, &txn, in qcom_slim_qmi_send_select_inst_req()
366 dev_err(ctrl->dev, "QMI send req fail %d\n", rc); in qcom_slim_qmi_send_select_inst_req()
373 dev_err(ctrl->dev, "QMI TXN wait fail: %d\n", rc); in qcom_slim_qmi_send_select_inst_req()
378 dev_err(ctrl->dev, "QMI request failed 0x%x\n", in qcom_slim_qmi_send_select_inst_req()
400 static int qcom_slim_qmi_send_power_request(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_qmi_send_power_request() argument
407 rc = qmi_txn_init(ctrl->qmi.handle, &txn, in qcom_slim_qmi_send_power_request()
410 rc = qmi_send_request(ctrl->qmi.handle, NULL, &txn, in qcom_slim_qmi_send_power_request()
415 dev_err(ctrl->dev, "QMI send req fail %d\n", rc); in qcom_slim_qmi_send_power_request()
422 dev_err(ctrl->dev, "QMI TXN wait fail: %d\n", rc); in qcom_slim_qmi_send_power_request()
428 dev_err(ctrl->dev, "QMI request failed 0x%x\n", in qcom_slim_qmi_send_power_request()
447 static int qcom_slim_qmi_init(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_qmi_init() argument
454 handle = devm_kzalloc(ctrl->dev, sizeof(*handle), GFP_KERNEL); in qcom_slim_qmi_init()
461 dev_err(ctrl->dev, "QMI client init failed: %d\n", rc); in qcom_slim_qmi_init()
466 (struct sockaddr *)&ctrl->qmi.svc_info, in qcom_slim_qmi_init()
467 sizeof(ctrl->qmi.svc_info), 0); in qcom_slim_qmi_init()
469 dev_err(ctrl->dev, "Remote Service connect failed: %d\n", rc); in qcom_slim_qmi_init()
474 req.instance = (ctrl->ngd->id >> 1); in qcom_slim_qmi_init()
483 ctrl->qmi.handle = handle; in qcom_slim_qmi_init()
485 rc = qcom_slim_qmi_send_select_inst_req(ctrl, &req); in qcom_slim_qmi_init()
487 dev_err(ctrl->dev, "failed to select h/w instance\n"); in qcom_slim_qmi_init()
494 ctrl->qmi.handle = NULL; in qcom_slim_qmi_init()
498 devm_kfree(ctrl->dev, handle); in qcom_slim_qmi_init()
502 static void qcom_slim_qmi_exit(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_qmi_exit() argument
504 if (!ctrl->qmi.handle) in qcom_slim_qmi_exit()
507 qmi_handle_release(ctrl->qmi.handle); in qcom_slim_qmi_exit()
508 devm_kfree(ctrl->dev, ctrl->qmi.handle); in qcom_slim_qmi_exit()
509 ctrl->qmi.handle = NULL; in qcom_slim_qmi_exit()
512 static int qcom_slim_qmi_power_request(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_qmi_power_request() argument
524 return qcom_slim_qmi_send_power_request(ctrl, &req); in qcom_slim_qmi_power_request()
527 static u32 *qcom_slim_ngd_tx_msg_get(struct qcom_slim_ngd_ctrl *ctrl, int len, in qcom_slim_ngd_tx_msg_get() argument
533 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_get()
535 if ((ctrl->tx_tail + 1) % QCOM_SLIM_NGD_DESC_NUM == ctrl->tx_head) { in qcom_slim_ngd_tx_msg_get()
536 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_get()
539 desc = &ctrl->txdesc[ctrl->tx_tail]; in qcom_slim_ngd_tx_msg_get()
540 desc->base = ctrl->tx_base + ctrl->tx_tail * SLIM_MSGQ_BUF_LEN; in qcom_slim_ngd_tx_msg_get()
542 ctrl->tx_tail = (ctrl->tx_tail + 1) % QCOM_SLIM_NGD_DESC_NUM; in qcom_slim_ngd_tx_msg_get()
544 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_get()
552 struct qcom_slim_ngd_ctrl *ctrl = desc->ctrl; in qcom_slim_ngd_tx_msg_dma_cb() local
555 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_dma_cb()
562 ctrl->tx_head = (ctrl->tx_head + 1) % QCOM_SLIM_NGD_DESC_NUM; in qcom_slim_ngd_tx_msg_dma_cb()
563 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_dma_cb()
566 static int qcom_slim_ngd_tx_msg_post(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_ngd_tx_msg_post() argument
573 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_post()
574 offset = buf - ctrl->tx_base; in qcom_slim_ngd_tx_msg_post()
577 desc = &ctrl->txdesc[index]; in qcom_slim_ngd_tx_msg_post()
578 desc->phys = ctrl->tx_phys_base + offset; in qcom_slim_ngd_tx_msg_post()
579 desc->base = ctrl->tx_base + offset; in qcom_slim_ngd_tx_msg_post()
580 desc->ctrl = ctrl; in qcom_slim_ngd_tx_msg_post()
583 desc->desc = dmaengine_prep_slave_single(ctrl->dma_tx_channel, in qcom_slim_ngd_tx_msg_post()
588 dev_err(ctrl->dev, "unable to prepare channel\n"); in qcom_slim_ngd_tx_msg_post()
589 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_post()
596 dma_async_issue_pending(ctrl->dma_tx_channel); in qcom_slim_ngd_tx_msg_post()
597 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_tx_msg_post()
602 static void qcom_slim_ngd_rx(struct qcom_slim_ngd_ctrl *ctrl, u8 *buf) in qcom_slim_ngd_rx() argument
612 queue_work(ctrl->mwq, &ctrl->m_work); in qcom_slim_ngd_rx()
619 slim_msg_response(&ctrl->ctrl, &buf[4], buf[3], len - 4); in qcom_slim_ngd_rx()
620 pm_runtime_mark_last_busy(ctrl->ctrl.dev); in qcom_slim_ngd_rx()
627 struct qcom_slim_ngd_ctrl *ctrl = desc->ctrl; in qcom_slim_ngd_rx_msgq_cb() local
629 qcom_slim_ngd_rx(ctrl, (u8 *)desc->base); in qcom_slim_ngd_rx_msgq_cb()
631 desc->desc = dmaengine_prep_slave_single(ctrl->dma_rx_channel, in qcom_slim_ngd_rx_msgq_cb()
636 dev_err(ctrl->dev, "Unable to prepare rx channel\n"); in qcom_slim_ngd_rx_msgq_cb()
643 dma_async_issue_pending(ctrl->dma_rx_channel); in qcom_slim_ngd_rx_msgq_cb()
646 static int qcom_slim_ngd_post_rx_msgq(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_post_rx_msgq() argument
652 desc = &ctrl->rx_desc[i]; in qcom_slim_ngd_post_rx_msgq()
653 desc->phys = ctrl->rx_phys_base + i * SLIM_MSGQ_BUF_LEN; in qcom_slim_ngd_post_rx_msgq()
654 desc->ctrl = ctrl; in qcom_slim_ngd_post_rx_msgq()
655 desc->base = ctrl->rx_base + i * SLIM_MSGQ_BUF_LEN; in qcom_slim_ngd_post_rx_msgq()
656 desc->desc = dmaengine_prep_slave_single(ctrl->dma_rx_channel, in qcom_slim_ngd_post_rx_msgq()
661 dev_err(ctrl->dev, "Unable to prepare rx channel\n"); in qcom_slim_ngd_post_rx_msgq()
669 dma_async_issue_pending(ctrl->dma_rx_channel); in qcom_slim_ngd_post_rx_msgq()
674 static int qcom_slim_ngd_init_rx_msgq(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_init_rx_msgq() argument
676 struct device *dev = ctrl->dev; in qcom_slim_ngd_init_rx_msgq()
679 ctrl->dma_rx_channel = dma_request_chan(dev, "rx"); in qcom_slim_ngd_init_rx_msgq()
680 if (IS_ERR(ctrl->dma_rx_channel)) { in qcom_slim_ngd_init_rx_msgq()
682 ret = PTR_ERR(ctrl->dma_rx_channel); in qcom_slim_ngd_init_rx_msgq()
683 ctrl->dma_rx_channel = NULL; in qcom_slim_ngd_init_rx_msgq()
688 ctrl->rx_base = dma_alloc_coherent(dev, size, &ctrl->rx_phys_base, in qcom_slim_ngd_init_rx_msgq()
690 if (!ctrl->rx_base) { in qcom_slim_ngd_init_rx_msgq()
695 ret = qcom_slim_ngd_post_rx_msgq(ctrl); in qcom_slim_ngd_init_rx_msgq()
704 dma_free_coherent(dev, size, ctrl->rx_base, ctrl->rx_phys_base); in qcom_slim_ngd_init_rx_msgq()
706 dma_release_channel(ctrl->dma_rx_channel); in qcom_slim_ngd_init_rx_msgq()
710 static int qcom_slim_ngd_init_tx_msgq(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_init_tx_msgq() argument
712 struct device *dev = ctrl->dev; in qcom_slim_ngd_init_tx_msgq()
717 ctrl->dma_tx_channel = dma_request_chan(dev, "tx"); in qcom_slim_ngd_init_tx_msgq()
718 if (IS_ERR(ctrl->dma_tx_channel)) { in qcom_slim_ngd_init_tx_msgq()
720 ret = PTR_ERR(ctrl->dma_tx_channel); in qcom_slim_ngd_init_tx_msgq()
721 ctrl->dma_tx_channel = NULL; in qcom_slim_ngd_init_tx_msgq()
726 ctrl->tx_base = dma_alloc_coherent(dev, size, &ctrl->tx_phys_base, in qcom_slim_ngd_init_tx_msgq()
728 if (!ctrl->tx_base) { in qcom_slim_ngd_init_tx_msgq()
733 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_init_tx_msgq()
734 ctrl->tx_tail = 0; in qcom_slim_ngd_init_tx_msgq()
735 ctrl->tx_head = 0; in qcom_slim_ngd_init_tx_msgq()
736 spin_unlock_irqrestore(&ctrl->tx_buf_lock, flags); in qcom_slim_ngd_init_tx_msgq()
740 dma_release_channel(ctrl->dma_tx_channel); in qcom_slim_ngd_init_tx_msgq()
744 static int qcom_slim_ngd_init_dma(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_init_dma() argument
748 ret = qcom_slim_ngd_init_rx_msgq(ctrl); in qcom_slim_ngd_init_dma()
750 dev_err(ctrl->dev, "rx dma init failed\n"); in qcom_slim_ngd_init_dma()
754 ret = qcom_slim_ngd_init_tx_msgq(ctrl); in qcom_slim_ngd_init_dma()
756 dev_err(ctrl->dev, "tx dma init failed\n"); in qcom_slim_ngd_init_dma()
763 struct qcom_slim_ngd_ctrl *ctrl = d; in qcom_slim_ngd_interrupt() local
764 void __iomem *base = ctrl->ngd->base; in qcom_slim_ngd_interrupt()
767 if (pm_runtime_suspended(ctrl->ctrl.dev)) { in qcom_slim_ngd_interrupt()
768 dev_warn_once(ctrl->dev, "Interrupt received while suspended\n"); in qcom_slim_ngd_interrupt()
777 dev_err(ctrl->dev, "Error Interrupt received 0x%x\n", stat); in qcom_slim_ngd_interrupt()
788 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(sctrl->dev); in qcom_slim_ngd_xfer_msg() local
810 dev_err(ctrl->dev, "msg exceeds HW limit\n"); 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()
850 dev_err(ctrl->dev, "Unable to allocate TID\n"); 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()
898 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
907 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
912 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
916 static int qcom_slim_ngd_xfer_msg_sync(struct slim_controller *ctrl, in qcom_slim_ngd_xfer_msg_sync() argument
923 ret = pm_runtime_get_sync(ctrl->dev); in qcom_slim_ngd_xfer_msg_sync()
929 ret = qcom_slim_ngd_xfer_msg(ctrl, txn); in qcom_slim_ngd_xfer_msg_sync()
935 dev_err(ctrl->dev, "TX timed out:MC:0x%x,mt:0x%x", txn->mc, in qcom_slim_ngd_xfer_msg_sync()
943 pm_runtime_put(ctrl->dev); in qcom_slim_ngd_xfer_msg_sync()
950 struct slim_controller *ctrl = rt->dev->ctrl; in qcom_slim_calc_coef() local
953 if (rt->ratem * ctrl->a_framer->superfreq < rt->rate) in qcom_slim_calc_coef()
999 struct slim_controller *ctrl = sdev->ctrl; in qcom_slim_ngd_enable_stream() local
1047 ret = slim_alloc_txn_tid(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1059 ret = qcom_slim_ngd_xfer_msg_sync(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1061 slim_free_txn_tid(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1072 ret = slim_alloc_txn_tid(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1074 dev_err(ctrl->dev, "Fail to allocate TID\n"); in qcom_slim_ngd_enable_stream()
1079 ret = qcom_slim_ngd_xfer_msg_sync(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1081 slim_free_txn_tid(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1089 static int qcom_slim_ngd_get_laddr(struct slim_controller *ctrl, in qcom_slim_ngd_get_laddr() argument
1111 ret = slim_alloc_txn_tid(ctrl, &txn); in qcom_slim_ngd_get_laddr()
1118 ret = qcom_slim_ngd_xfer_msg_sync(ctrl, &txn); in qcom_slim_ngd_get_laddr()
1120 slim_free_txn_tid(ctrl, &txn); in qcom_slim_ngd_get_laddr()
1132 static int qcom_slim_ngd_exit_dma(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_exit_dma() argument
1134 if (ctrl->dma_rx_channel) { in qcom_slim_ngd_exit_dma()
1135 dmaengine_terminate_sync(ctrl->dma_rx_channel); in qcom_slim_ngd_exit_dma()
1136 dma_release_channel(ctrl->dma_rx_channel); in qcom_slim_ngd_exit_dma()
1139 if (ctrl->dma_tx_channel) { in qcom_slim_ngd_exit_dma()
1140 dmaengine_terminate_sync(ctrl->dma_tx_channel); in qcom_slim_ngd_exit_dma()
1141 dma_release_channel(ctrl->dma_tx_channel); in qcom_slim_ngd_exit_dma()
1144 ctrl->dma_tx_channel = ctrl->dma_rx_channel = NULL; in qcom_slim_ngd_exit_dma()
1149 static void qcom_slim_ngd_setup(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_setup() argument
1151 u32 cfg = readl_relaxed(ctrl->ngd->base); in qcom_slim_ngd_setup()
1153 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN || in qcom_slim_ngd_setup()
1154 ctrl->state == QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_setup()
1155 qcom_slim_ngd_init_dma(ctrl); in qcom_slim_ngd_setup()
1165 writel_relaxed(cfg, ctrl->ngd->base); in qcom_slim_ngd_setup()
1168 static int qcom_slim_ngd_power_up(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_power_up() argument
1170 enum qcom_slim_ngd_state cur_state = ctrl->state; in qcom_slim_ngd_power_up()
1171 struct qcom_slim_ngd *ngd = ctrl->ngd; in qcom_slim_ngd_power_up()
1176 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_power_up()
1177 time_left = wait_for_completion_timeout(&ctrl->qmi.qmi_comp, HZ); in qcom_slim_ngd_power_up()
1182 if (ctrl->state == QCOM_SLIM_NGD_CTRL_ASLEEP || in qcom_slim_ngd_power_up()
1183 ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_power_up()
1184 ret = qcom_slim_qmi_power_request(ctrl, true); in qcom_slim_ngd_power_up()
1186 dev_err(ctrl->dev, "SLIM QMI power request failed:%d\n", in qcom_slim_ngd_power_up()
1192 ctrl->ver = readl_relaxed(ctrl->base); in qcom_slim_ngd_power_up()
1194 ctrl->ver >>= 16; in qcom_slim_ngd_power_up()
1203 dev_info(ctrl->dev, "Subsys restart: ADSP active framer\n"); in qcom_slim_ngd_power_up()
1206 qcom_slim_ngd_setup(ctrl); in qcom_slim_ngd_power_up()
1214 reinit_completion(&ctrl->reconf); in qcom_slim_ngd_power_up()
1221 qcom_slim_ngd_setup(ctrl); in qcom_slim_ngd_power_up()
1223 time_left = wait_for_completion_timeout(&ctrl->reconf, HZ); in qcom_slim_ngd_power_up()
1225 dev_err(ctrl->dev, "capability exchange timed-out\n"); in qcom_slim_ngd_power_up()
1232 static void qcom_slim_ngd_notify_slaves(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_notify_slaves() argument
1237 for_each_child_of_node(ctrl->ngd->pdev->dev.of_node, node) { in qcom_slim_ngd_notify_slaves()
1238 sbdev = of_slim_get_device(&ctrl->ctrl, node); in qcom_slim_ngd_notify_slaves()
1243 dev_err(ctrl->dev, "Failed to get logical address\n"); in qcom_slim_ngd_notify_slaves()
1249 struct qcom_slim_ngd_ctrl *ctrl; in qcom_slim_ngd_master_worker() local
1256 ctrl = container_of(work, struct qcom_slim_ngd_ctrl, m_work); in qcom_slim_ngd_master_worker()
1271 dev_info(ctrl->dev, "SLIM SAT: Rcvd master capability\n"); in qcom_slim_ngd_master_worker()
1274 ret = qcom_slim_ngd_xfer_msg(&ctrl->ctrl, &txn); in qcom_slim_ngd_master_worker()
1276 if (ctrl->state >= QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_master_worker()
1277 complete(&ctrl->reconf); in qcom_slim_ngd_master_worker()
1279 dev_err(ctrl->dev, "unexpected state:%d\n", in qcom_slim_ngd_master_worker()
1280 ctrl->state); in qcom_slim_ngd_master_worker()
1282 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) in qcom_slim_ngd_master_worker()
1283 qcom_slim_ngd_notify_slaves(ctrl); in qcom_slim_ngd_master_worker()
1286 dev_err(ctrl->dev, "capability message NACKed, retrying\n"); in qcom_slim_ngd_master_worker()
1293 dev_err(ctrl->dev, "SLIM: capability TX failed:%d\n", ret); in qcom_slim_ngd_master_worker()
1306 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev); in qcom_slim_ngd_runtime_resume() local
1309 if (!ctrl->qmi.handle) in qcom_slim_ngd_runtime_resume()
1312 if (ctrl->state >= QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_runtime_resume()
1313 ret = qcom_slim_ngd_power_up(ctrl); in qcom_slim_ngd_runtime_resume()
1316 if (ctrl->state != QCOM_SLIM_NGD_CTRL_DOWN) in qcom_slim_ngd_runtime_resume()
1317 ctrl->state = QCOM_SLIM_NGD_CTRL_ASLEEP; in qcom_slim_ngd_runtime_resume()
1319 dev_err(ctrl->dev, "HW wakeup attempt during SSR\n"); in qcom_slim_ngd_runtime_resume()
1321 ctrl->state = QCOM_SLIM_NGD_CTRL_AWAKE; in qcom_slim_ngd_runtime_resume()
1327 static int qcom_slim_ngd_enable(struct qcom_slim_ngd_ctrl *ctrl, bool enable) in qcom_slim_ngd_enable() argument
1330 int ret = qcom_slim_qmi_init(ctrl, false); in qcom_slim_ngd_enable()
1333 dev_err(ctrl->dev, "qmi init fail, ret:%d, state:%d\n", in qcom_slim_ngd_enable()
1334 ret, ctrl->state); in qcom_slim_ngd_enable()
1338 complete(&ctrl->qmi.qmi_comp); in qcom_slim_ngd_enable()
1339 if (!pm_runtime_enabled(ctrl->ctrl.dev) || in qcom_slim_ngd_enable()
1340 !pm_runtime_suspended(ctrl->ctrl.dev)) in qcom_slim_ngd_enable()
1341 qcom_slim_ngd_runtime_resume(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1343 pm_runtime_resume(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1345 pm_runtime_mark_last_busy(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1346 pm_runtime_put(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1348 ret = slim_register_controller(&ctrl->ctrl); in qcom_slim_ngd_enable()
1350 dev_err(ctrl->dev, "error adding slim controller\n"); in qcom_slim_ngd_enable()
1354 dev_info(ctrl->dev, "SLIM controller Registered\n"); in qcom_slim_ngd_enable()
1356 qcom_slim_qmi_exit(ctrl); in qcom_slim_ngd_enable()
1357 slim_unregister_controller(&ctrl->ctrl); in qcom_slim_ngd_enable()
1368 struct qcom_slim_ngd_ctrl *ctrl = in qcom_slim_ngd_qmi_new_server() local
1375 complete(&ctrl->qmi_up); in qcom_slim_ngd_qmi_new_server()
1385 struct qcom_slim_ngd_ctrl *ctrl = in qcom_slim_ngd_qmi_del_server() local
1388 reinit_completion(&ctrl->qmi_up); in qcom_slim_ngd_qmi_del_server()
1398 static int qcom_slim_ngd_qmi_svc_event_init(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_qmi_svc_event_init() argument
1400 struct qcom_slim_ngd_qmi *qmi = &ctrl->qmi; in qcom_slim_ngd_qmi_svc_event_init()
1406 dev_err(ctrl->dev, "qmi_handle_init failed: %d\n", ret); in qcom_slim_ngd_qmi_svc_event_init()
1413 dev_err(ctrl->dev, "qmi_add_lookup failed: %d\n", ret); in qcom_slim_ngd_qmi_svc_event_init()
1440 static void qcom_slim_ngd_down(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_down() argument
1442 mutex_lock(&ctrl->ssr_lock); in qcom_slim_ngd_down()
1443 device_for_each_child(ctrl->ctrl.dev, NULL, in qcom_slim_ngd_down()
1445 qcom_slim_ngd_enable(ctrl, false); in qcom_slim_ngd_down()
1446 mutex_unlock(&ctrl->ssr_lock); in qcom_slim_ngd_down()
1451 struct qcom_slim_ngd_ctrl *ctrl; in qcom_slim_ngd_up_worker() local
1453 ctrl = container_of(work, struct qcom_slim_ngd_ctrl, ngd_up_work); in qcom_slim_ngd_up_worker()
1456 if (!wait_for_completion_interruptible_timeout(&ctrl->qmi_up, in qcom_slim_ngd_up_worker()
1458 dev_err(ctrl->dev, "QMI wait timeout\n"); in qcom_slim_ngd_up_worker()
1462 mutex_lock(&ctrl->ssr_lock); in qcom_slim_ngd_up_worker()
1463 qcom_slim_ngd_enable(ctrl, true); in qcom_slim_ngd_up_worker()
1464 mutex_unlock(&ctrl->ssr_lock); in qcom_slim_ngd_up_worker()
1467 static int qcom_slim_ngd_ssr_pdr_notify(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_ngd_ssr_pdr_notify() argument
1474 mutex_lock(&ctrl->tx_lock); in qcom_slim_ngd_ssr_pdr_notify()
1475 if (ctrl->state != QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_ssr_pdr_notify()
1476 pm_runtime_get_noresume(ctrl->ctrl.dev); in qcom_slim_ngd_ssr_pdr_notify()
1477 ctrl->state = QCOM_SLIM_NGD_CTRL_DOWN; in qcom_slim_ngd_ssr_pdr_notify()
1478 qcom_slim_ngd_down(ctrl); in qcom_slim_ngd_ssr_pdr_notify()
1479 qcom_slim_ngd_exit_dma(ctrl); in qcom_slim_ngd_ssr_pdr_notify()
1481 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_ssr_pdr_notify()
1485 schedule_work(&ctrl->ngd_up_work); in qcom_slim_ngd_ssr_pdr_notify()
1498 struct qcom_slim_ngd_ctrl *ctrl = container_of(nb, in qcom_slim_ngd_ssr_notify() local
1501 return qcom_slim_ngd_ssr_pdr_notify(ctrl, action); in qcom_slim_ngd_ssr_notify()
1506 struct qcom_slim_ngd_ctrl *ctrl = (struct qcom_slim_ngd_ctrl *)priv; in slim_pd_status() local
1508 qcom_slim_ngd_ssr_pdr_notify(ctrl, state); in slim_pd_status()
1511 struct qcom_slim_ngd_ctrl *ctrl) in of_qcom_slim_ngd_register() argument
1552 ctrl->ngd = ngd; in of_qcom_slim_ngd_register()
1561 ngd->base = ctrl->base + ngd->id * data->offset + in of_qcom_slim_ngd_register()
1573 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev->parent); in qcom_slim_ngd_probe() local
1576 ctrl->ctrl.dev = dev; in qcom_slim_ngd_probe()
1578 platform_set_drvdata(pdev, ctrl); in qcom_slim_ngd_probe()
1584 ret = qcom_slim_ngd_qmi_svc_event_init(ctrl); in qcom_slim_ngd_probe()
1590 INIT_WORK(&ctrl->m_work, qcom_slim_ngd_master_worker); in qcom_slim_ngd_probe()
1591 INIT_WORK(&ctrl->ngd_up_work, qcom_slim_ngd_up_worker); in qcom_slim_ngd_probe()
1592 ctrl->mwq = create_singlethread_workqueue("ngd_master"); in qcom_slim_ngd_probe()
1593 if (!ctrl->mwq) { in qcom_slim_ngd_probe()
1601 qcom_slim_ngd_qmi_svc_event_deinit(&ctrl->qmi); in qcom_slim_ngd_probe()
1602 if (ctrl->mwq) in qcom_slim_ngd_probe()
1603 destroy_workqueue(ctrl->mwq); in qcom_slim_ngd_probe()
1611 struct qcom_slim_ngd_ctrl *ctrl; in qcom_slim_ngd_ctrl_probe() local
1615 ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); in qcom_slim_ngd_ctrl_probe()
1616 if (!ctrl) in qcom_slim_ngd_ctrl_probe()
1619 dev_set_drvdata(dev, ctrl); in qcom_slim_ngd_ctrl_probe()
1621 ctrl->base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in qcom_slim_ngd_ctrl_probe()
1622 if (IS_ERR(ctrl->base)) in qcom_slim_ngd_ctrl_probe()
1623 return PTR_ERR(ctrl->base); in qcom_slim_ngd_ctrl_probe()
1630 IRQF_TRIGGER_HIGH, "slim-ngd", ctrl); in qcom_slim_ngd_ctrl_probe()
1634 ctrl->nb.notifier_call = qcom_slim_ngd_ssr_notify; in qcom_slim_ngd_ctrl_probe()
1635 ctrl->notifier = qcom_register_ssr_notifier("lpass", &ctrl->nb); in qcom_slim_ngd_ctrl_probe()
1636 if (IS_ERR(ctrl->notifier)) in qcom_slim_ngd_ctrl_probe()
1637 return PTR_ERR(ctrl->notifier); in qcom_slim_ngd_ctrl_probe()
1639 ctrl->dev = dev; in qcom_slim_ngd_ctrl_probe()
1640 ctrl->framer.rootfreq = SLIM_ROOT_FREQ >> 3; in qcom_slim_ngd_ctrl_probe()
1641 ctrl->framer.superfreq = in qcom_slim_ngd_ctrl_probe()
1642 ctrl->framer.rootfreq / SLIM_CL_PER_SUPERFRAME_DIV8; in qcom_slim_ngd_ctrl_probe()
1644 ctrl->ctrl.a_framer = &ctrl->framer; in qcom_slim_ngd_ctrl_probe()
1645 ctrl->ctrl.clkgear = SLIM_MAX_CLK_GEAR; in qcom_slim_ngd_ctrl_probe()
1646 ctrl->ctrl.get_laddr = qcom_slim_ngd_get_laddr; in qcom_slim_ngd_ctrl_probe()
1647 ctrl->ctrl.enable_stream = qcom_slim_ngd_enable_stream; in qcom_slim_ngd_ctrl_probe()
1648 ctrl->ctrl.xfer_msg = qcom_slim_ngd_xfer_msg; in qcom_slim_ngd_ctrl_probe()
1649 ctrl->ctrl.wakeup = NULL; in qcom_slim_ngd_ctrl_probe()
1650 ctrl->state = QCOM_SLIM_NGD_CTRL_DOWN; in qcom_slim_ngd_ctrl_probe()
1652 mutex_init(&ctrl->tx_lock); in qcom_slim_ngd_ctrl_probe()
1653 mutex_init(&ctrl->ssr_lock); in qcom_slim_ngd_ctrl_probe()
1654 spin_lock_init(&ctrl->tx_buf_lock); in qcom_slim_ngd_ctrl_probe()
1655 init_completion(&ctrl->reconf); in qcom_slim_ngd_ctrl_probe()
1656 init_completion(&ctrl->qmi.qmi_comp); in qcom_slim_ngd_ctrl_probe()
1657 init_completion(&ctrl->qmi_up); in qcom_slim_ngd_ctrl_probe()
1659 ctrl->pdr = pdr_handle_alloc(slim_pd_status, ctrl); in qcom_slim_ngd_ctrl_probe()
1660 if (IS_ERR(ctrl->pdr)) { in qcom_slim_ngd_ctrl_probe()
1661 ret = dev_err_probe(dev, PTR_ERR(ctrl->pdr), in qcom_slim_ngd_ctrl_probe()
1666 pds = pdr_add_lookup(ctrl->pdr, "avs/audio", "msm/adsp/audio_pd"); in qcom_slim_ngd_ctrl_probe()
1673 return of_qcom_slim_ngd_register(dev, ctrl); in qcom_slim_ngd_ctrl_probe()
1676 qcom_unregister_ssr_notifier(ctrl->notifier, &ctrl->nb); in qcom_slim_ngd_ctrl_probe()
1679 pdr_handle_release(ctrl->pdr); in qcom_slim_ngd_ctrl_probe()
1691 struct qcom_slim_ngd_ctrl *ctrl = platform_get_drvdata(pdev); in qcom_slim_ngd_remove() local
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()
1696 qcom_slim_ngd_enable(ctrl, false); in qcom_slim_ngd_remove()
1697 qcom_slim_ngd_exit_dma(ctrl); 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()
1708 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev); in qcom_slim_ngd_runtime_idle() local
1710 if (ctrl->state == QCOM_SLIM_NGD_CTRL_AWAKE) in qcom_slim_ngd_runtime_idle()
1711 ctrl->state = QCOM_SLIM_NGD_CTRL_IDLE; in qcom_slim_ngd_runtime_idle()
1718 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev); in qcom_slim_ngd_runtime_suspend() local
1721 qcom_slim_ngd_exit_dma(ctrl); in qcom_slim_ngd_runtime_suspend()
1722 if (!ctrl->qmi.handle) in qcom_slim_ngd_runtime_suspend()
1725 ret = qcom_slim_qmi_power_request(ctrl, false); in qcom_slim_ngd_runtime_suspend()
1727 dev_info(ctrl->dev, "slim resource not idle:%d\n", ret); in qcom_slim_ngd_runtime_suspend()
1729 ctrl->state = QCOM_SLIM_NGD_CTRL_ASLEEP; in qcom_slim_ngd_runtime_suspend()
1748 .name = "qcom,slim-ngd-ctrl",