Lines Matching full:ctrl

136 	struct qcom_slim_ngd_ctrl *ctrl;  member
151 struct slim_controller ctrl; member
348 static int qcom_slim_qmi_send_select_inst_req(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_qmi_send_select_inst_req() argument
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()
401 static int qcom_slim_qmi_send_power_request(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_qmi_send_power_request() argument
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()
448 static int qcom_slim_qmi_init(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_qmi_init() argument
455 handle = devm_kzalloc(ctrl->dev, sizeof(*handle), GFP_KERNEL); in qcom_slim_qmi_init()
462 dev_err(ctrl->dev, "QMI client init failed: %d\n", rc); 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()
486 rc = qcom_slim_qmi_send_select_inst_req(ctrl, &req); 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()
503 static void qcom_slim_qmi_exit(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_qmi_exit() argument
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()
513 static int qcom_slim_qmi_power_request(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_qmi_power_request() argument
525 return qcom_slim_qmi_send_power_request(ctrl, &req); in qcom_slim_qmi_power_request()
528 static u32 *qcom_slim_ngd_tx_msg_get(struct qcom_slim_ngd_ctrl *ctrl, int len, in qcom_slim_ngd_tx_msg_get() argument
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()
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()
553 struct qcom_slim_ngd_ctrl *ctrl = desc->ctrl; in qcom_slim_ngd_tx_msg_dma_cb() local
556 spin_lock_irqsave(&ctrl->tx_buf_lock, flags); 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()
567 static int qcom_slim_ngd_tx_msg_post(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_ngd_tx_msg_post() argument
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()
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()
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()
603 static void qcom_slim_ngd_rx(struct qcom_slim_ngd_ctrl *ctrl, u8 *buf) in qcom_slim_ngd_rx() argument
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() local
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()
637 dev_err(ctrl->dev, "Unable to prepare rx channel\n"); in qcom_slim_ngd_rx_msgq_cb()
644 dma_async_issue_pending(ctrl->dma_rx_channel); in qcom_slim_ngd_rx_msgq_cb()
647 static int qcom_slim_ngd_post_rx_msgq(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_post_rx_msgq() argument
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()
662 dev_err(ctrl->dev, "Unable to prepare rx channel\n"); in qcom_slim_ngd_post_rx_msgq()
670 dma_async_issue_pending(ctrl->dma_rx_channel); in qcom_slim_ngd_post_rx_msgq()
675 static int qcom_slim_ngd_init_rx_msgq(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_init_rx_msgq() argument
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()
696 ret = qcom_slim_ngd_post_rx_msgq(ctrl); 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()
711 static int qcom_slim_ngd_init_tx_msgq(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_init_tx_msgq() argument
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()
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()
745 static int qcom_slim_ngd_init_dma(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_init_dma() argument
749 ret = qcom_slim_ngd_init_rx_msgq(ctrl); in qcom_slim_ngd_init_dma()
751 dev_err(ctrl->dev, "rx dma init failed\n"); in qcom_slim_ngd_init_dma()
755 ret = qcom_slim_ngd_init_tx_msgq(ctrl); in qcom_slim_ngd_init_dma()
757 dev_err(ctrl->dev, "tx dma init failed\n"); in qcom_slim_ngd_init_dma()
764 struct qcom_slim_ngd_ctrl *ctrl = d; in qcom_slim_ngd_interrupt() local
765 void __iomem *base = ctrl->ngd->base; in qcom_slim_ngd_interrupt()
771 dev_err(ctrl->dev, "Error Interrupt received 0x%x\n", stat); in qcom_slim_ngd_interrupt()
782 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(sctrl->dev); in qcom_slim_ngd_xfer_msg() local
803 dev_err(ctrl->dev, "msg exceeds HW limit\n"); in qcom_slim_ngd_xfer_msg()
807 pbuf = qcom_slim_ngd_tx_msg_get(ctrl, txn->rl, &tx_sent); in qcom_slim_ngd_xfer_msg()
809 dev_err(ctrl->dev, "Message buffer unavailable\n"); in qcom_slim_ngd_xfer_msg()
843 dev_err(ctrl->dev, "Unable to allocate TID\n"); in qcom_slim_ngd_xfer_msg()
880 mutex_lock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
881 ret = qcom_slim_ngd_tx_msg_post(ctrl, pbuf, txn->rl); in qcom_slim_ngd_xfer_msg()
883 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
891 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
900 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
905 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_xfer_msg()
909 static int qcom_slim_ngd_xfer_msg_sync(struct slim_controller *ctrl, in qcom_slim_ngd_xfer_msg_sync() argument
915 pm_runtime_get_sync(ctrl->dev); in qcom_slim_ngd_xfer_msg_sync()
919 ret = qcom_slim_ngd_xfer_msg(ctrl, txn); in qcom_slim_ngd_xfer_msg_sync()
925 dev_err(ctrl->dev, "TX timed out:MC:0x%x,mt:0x%x", txn->mc, in qcom_slim_ngd_xfer_msg_sync()
935 struct slim_controller *ctrl = sdev->ctrl; in qcom_slim_ngd_enable_stream() local
977 ret = slim_alloc_txn_tid(ctrl, &txn); in qcom_slim_ngd_enable_stream()
989 ret = qcom_slim_ngd_xfer_msg_sync(ctrl, &txn); in qcom_slim_ngd_enable_stream()
991 slim_free_txn_tid(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1002 ret = slim_alloc_txn_tid(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1004 dev_err(ctrl->dev, "Fail to allocate TID\n"); in qcom_slim_ngd_enable_stream()
1009 ret = qcom_slim_ngd_xfer_msg_sync(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1011 slim_free_txn_tid(ctrl, &txn); in qcom_slim_ngd_enable_stream()
1019 static int qcom_slim_ngd_get_laddr(struct slim_controller *ctrl, in qcom_slim_ngd_get_laddr() argument
1041 ret = slim_alloc_txn_tid(ctrl, &txn); in qcom_slim_ngd_get_laddr()
1048 ret = qcom_slim_ngd_xfer_msg_sync(ctrl, &txn); in qcom_slim_ngd_get_laddr()
1050 slim_free_txn_tid(ctrl, &txn); in qcom_slim_ngd_get_laddr()
1062 static int qcom_slim_ngd_exit_dma(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_exit_dma() argument
1064 if (ctrl->dma_rx_channel) { in qcom_slim_ngd_exit_dma()
1065 dmaengine_terminate_sync(ctrl->dma_rx_channel); in qcom_slim_ngd_exit_dma()
1066 dma_release_channel(ctrl->dma_rx_channel); in qcom_slim_ngd_exit_dma()
1069 if (ctrl->dma_tx_channel) { in qcom_slim_ngd_exit_dma()
1070 dmaengine_terminate_sync(ctrl->dma_tx_channel); in qcom_slim_ngd_exit_dma()
1071 dma_release_channel(ctrl->dma_tx_channel); in qcom_slim_ngd_exit_dma()
1074 ctrl->dma_tx_channel = ctrl->dma_rx_channel = NULL; in qcom_slim_ngd_exit_dma()
1079 static void qcom_slim_ngd_setup(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_setup() argument
1081 u32 cfg = readl_relaxed(ctrl->ngd->base); in qcom_slim_ngd_setup()
1083 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN || in qcom_slim_ngd_setup()
1084 ctrl->state == QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_setup()
1085 qcom_slim_ngd_init_dma(ctrl); in qcom_slim_ngd_setup()
1095 writel_relaxed(cfg, ctrl->ngd->base); in qcom_slim_ngd_setup()
1098 static int qcom_slim_ngd_power_up(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_power_up() argument
1100 enum qcom_slim_ngd_state cur_state = ctrl->state; in qcom_slim_ngd_power_up()
1101 struct qcom_slim_ngd *ngd = ctrl->ngd; in qcom_slim_ngd_power_up()
1105 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_power_up()
1106 timeout = wait_for_completion_timeout(&ctrl->qmi.qmi_comp, HZ); in qcom_slim_ngd_power_up()
1111 if (ctrl->state == QCOM_SLIM_NGD_CTRL_ASLEEP || in qcom_slim_ngd_power_up()
1112 ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_power_up()
1113 ret = qcom_slim_qmi_power_request(ctrl, true); in qcom_slim_ngd_power_up()
1115 dev_err(ctrl->dev, "SLIM QMI power request failed:%d\n", in qcom_slim_ngd_power_up()
1121 ctrl->ver = readl_relaxed(ctrl->base); in qcom_slim_ngd_power_up()
1123 ctrl->ver >>= 16; in qcom_slim_ngd_power_up()
1132 dev_info(ctrl->dev, "Subsys restart: ADSP active framer\n"); in qcom_slim_ngd_power_up()
1135 qcom_slim_ngd_setup(ctrl); in qcom_slim_ngd_power_up()
1144 qcom_slim_ngd_setup(ctrl); in qcom_slim_ngd_power_up()
1146 timeout = wait_for_completion_timeout(&ctrl->reconf, HZ); in qcom_slim_ngd_power_up()
1148 dev_err(ctrl->dev, "capability exchange timed-out\n"); in qcom_slim_ngd_power_up()
1155 static void qcom_slim_ngd_notify_slaves(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_notify_slaves() argument
1160 for_each_child_of_node(ctrl->ngd->pdev->dev.of_node, node) { in qcom_slim_ngd_notify_slaves()
1161 sbdev = of_slim_get_device(&ctrl->ctrl, node); in qcom_slim_ngd_notify_slaves()
1166 dev_err(ctrl->dev, "Failed to get logical address\n"); in qcom_slim_ngd_notify_slaves()
1172 struct qcom_slim_ngd_ctrl *ctrl; in qcom_slim_ngd_master_worker() local
1179 ctrl = container_of(work, struct qcom_slim_ngd_ctrl, m_work); in qcom_slim_ngd_master_worker()
1194 dev_info(ctrl->dev, "SLIM SAT: Rcvd master capability\n"); in qcom_slim_ngd_master_worker()
1197 ret = qcom_slim_ngd_xfer_msg(&ctrl->ctrl, &txn); in qcom_slim_ngd_master_worker()
1199 if (ctrl->state >= QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_master_worker()
1200 complete(&ctrl->reconf); in qcom_slim_ngd_master_worker()
1202 dev_err(ctrl->dev, "unexpected state:%d\n", in qcom_slim_ngd_master_worker()
1203 ctrl->state); in qcom_slim_ngd_master_worker()
1205 if (ctrl->state == QCOM_SLIM_NGD_CTRL_DOWN) in qcom_slim_ngd_master_worker()
1206 qcom_slim_ngd_notify_slaves(ctrl); in qcom_slim_ngd_master_worker()
1209 dev_err(ctrl->dev, "capability message NACKed, retrying\n"); in qcom_slim_ngd_master_worker()
1216 dev_err(ctrl->dev, "SLIM: capability TX failed:%d\n", ret); in qcom_slim_ngd_master_worker()
1229 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev); in qcom_slim_ngd_runtime_resume() local
1232 if (!ctrl->qmi.handle) in qcom_slim_ngd_runtime_resume()
1235 if (ctrl->state >= QCOM_SLIM_NGD_CTRL_ASLEEP) in qcom_slim_ngd_runtime_resume()
1236 ret = qcom_slim_ngd_power_up(ctrl); in qcom_slim_ngd_runtime_resume()
1239 if (ctrl->state != QCOM_SLIM_NGD_CTRL_DOWN) in qcom_slim_ngd_runtime_resume()
1240 ctrl->state = QCOM_SLIM_NGD_CTRL_ASLEEP; in qcom_slim_ngd_runtime_resume()
1242 dev_err(ctrl->dev, "HW wakeup attempt during SSR\n"); in qcom_slim_ngd_runtime_resume()
1244 ctrl->state = QCOM_SLIM_NGD_CTRL_AWAKE; in qcom_slim_ngd_runtime_resume()
1250 static int qcom_slim_ngd_enable(struct qcom_slim_ngd_ctrl *ctrl, bool enable) in qcom_slim_ngd_enable() argument
1253 int ret = qcom_slim_qmi_init(ctrl, false); in qcom_slim_ngd_enable()
1256 dev_err(ctrl->dev, "qmi init fail, ret:%d, state:%d\n", in qcom_slim_ngd_enable()
1257 ret, ctrl->state); in qcom_slim_ngd_enable()
1261 complete(&ctrl->qmi.qmi_comp); in qcom_slim_ngd_enable()
1262 if (!pm_runtime_enabled(ctrl->ctrl.dev) || in qcom_slim_ngd_enable()
1263 !pm_runtime_suspended(ctrl->ctrl.dev)) in qcom_slim_ngd_enable()
1264 qcom_slim_ngd_runtime_resume(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1266 pm_runtime_resume(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1268 pm_runtime_mark_last_busy(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1269 pm_runtime_put(ctrl->ctrl.dev); in qcom_slim_ngd_enable()
1271 ret = slim_register_controller(&ctrl->ctrl); in qcom_slim_ngd_enable()
1273 dev_err(ctrl->dev, "error adding slim controller\n"); in qcom_slim_ngd_enable()
1277 dev_info(ctrl->dev, "SLIM controller Registered\n"); in qcom_slim_ngd_enable()
1279 qcom_slim_qmi_exit(ctrl); in qcom_slim_ngd_enable()
1280 slim_unregister_controller(&ctrl->ctrl); in qcom_slim_ngd_enable()
1291 struct qcom_slim_ngd_ctrl *ctrl = in qcom_slim_ngd_qmi_new_server() local
1298 complete(&ctrl->qmi_up); in qcom_slim_ngd_qmi_new_server()
1308 struct qcom_slim_ngd_ctrl *ctrl = in qcom_slim_ngd_qmi_del_server() local
1311 reinit_completion(&ctrl->qmi_up); in qcom_slim_ngd_qmi_del_server()
1321 static int qcom_slim_ngd_qmi_svc_event_init(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_qmi_svc_event_init() argument
1323 struct qcom_slim_ngd_qmi *qmi = &ctrl->qmi; in qcom_slim_ngd_qmi_svc_event_init()
1329 dev_err(ctrl->dev, "qmi_handle_init failed: %d\n", ret); in qcom_slim_ngd_qmi_svc_event_init()
1336 dev_err(ctrl->dev, "qmi_add_lookup failed: %d\n", ret); in qcom_slim_ngd_qmi_svc_event_init()
1363 static void qcom_slim_ngd_down(struct qcom_slim_ngd_ctrl *ctrl) in qcom_slim_ngd_down() argument
1365 mutex_lock(&ctrl->ssr_lock); in qcom_slim_ngd_down()
1366 device_for_each_child(ctrl->ctrl.dev, NULL, in qcom_slim_ngd_down()
1368 qcom_slim_ngd_enable(ctrl, false); in qcom_slim_ngd_down()
1369 mutex_unlock(&ctrl->ssr_lock); in qcom_slim_ngd_down()
1374 struct qcom_slim_ngd_ctrl *ctrl; in qcom_slim_ngd_up_worker() local
1376 ctrl = container_of(work, struct qcom_slim_ngd_ctrl, ngd_up_work); in qcom_slim_ngd_up_worker()
1379 wait_for_completion_interruptible(&ctrl->qmi_up); in qcom_slim_ngd_up_worker()
1381 mutex_lock(&ctrl->ssr_lock); in qcom_slim_ngd_up_worker()
1382 qcom_slim_ngd_enable(ctrl, true); in qcom_slim_ngd_up_worker()
1383 mutex_unlock(&ctrl->ssr_lock); in qcom_slim_ngd_up_worker()
1386 static int qcom_slim_ngd_ssr_pdr_notify(struct qcom_slim_ngd_ctrl *ctrl, in qcom_slim_ngd_ssr_pdr_notify() argument
1393 mutex_lock(&ctrl->tx_lock); in qcom_slim_ngd_ssr_pdr_notify()
1394 if (ctrl->state != QCOM_SLIM_NGD_CTRL_DOWN) { in qcom_slim_ngd_ssr_pdr_notify()
1395 pm_runtime_get_noresume(ctrl->ctrl.dev); in qcom_slim_ngd_ssr_pdr_notify()
1396 ctrl->state = QCOM_SLIM_NGD_CTRL_DOWN; in qcom_slim_ngd_ssr_pdr_notify()
1397 qcom_slim_ngd_down(ctrl); in qcom_slim_ngd_ssr_pdr_notify()
1398 qcom_slim_ngd_exit_dma(ctrl); in qcom_slim_ngd_ssr_pdr_notify()
1400 mutex_unlock(&ctrl->tx_lock); in qcom_slim_ngd_ssr_pdr_notify()
1404 schedule_work(&ctrl->ngd_up_work); in qcom_slim_ngd_ssr_pdr_notify()
1417 struct qcom_slim_ngd_ctrl *ctrl = container_of(nb, in qcom_slim_ngd_ssr_notify() local
1420 return qcom_slim_ngd_ssr_pdr_notify(ctrl, action); in qcom_slim_ngd_ssr_notify()
1425 struct qcom_slim_ngd_ctrl *ctrl = (struct qcom_slim_ngd_ctrl *)priv; in slim_pd_status() local
1427 qcom_slim_ngd_ssr_pdr_notify(ctrl, state); in slim_pd_status()
1430 struct qcom_slim_ngd_ctrl *ctrl) in of_qcom_slim_ngd_register() argument
1471 ctrl->ngd = ngd; in of_qcom_slim_ngd_register()
1480 ngd->base = ctrl->base + ngd->id * data->offset + in of_qcom_slim_ngd_register()
1492 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev->parent); in qcom_slim_ngd_probe() local
1495 ctrl->ctrl.dev = dev; in qcom_slim_ngd_probe()
1497 platform_set_drvdata(pdev, ctrl); in qcom_slim_ngd_probe()
1503 ret = qcom_slim_ngd_qmi_svc_event_init(ctrl); in qcom_slim_ngd_probe()
1509 INIT_WORK(&ctrl->m_work, qcom_slim_ngd_master_worker); in qcom_slim_ngd_probe()
1510 INIT_WORK(&ctrl->ngd_up_work, qcom_slim_ngd_up_worker); in qcom_slim_ngd_probe()
1511 ctrl->mwq = create_singlethread_workqueue("ngd_master"); in qcom_slim_ngd_probe()
1512 if (!ctrl->mwq) { in qcom_slim_ngd_probe()
1520 qcom_slim_ngd_qmi_svc_event_deinit(&ctrl->qmi); in qcom_slim_ngd_probe()
1521 if (ctrl->mwq) in qcom_slim_ngd_probe()
1522 destroy_workqueue(ctrl->mwq); in qcom_slim_ngd_probe()
1530 struct qcom_slim_ngd_ctrl *ctrl; in qcom_slim_ngd_ctrl_probe() local
1535 ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); in qcom_slim_ngd_ctrl_probe()
1536 if (!ctrl) in qcom_slim_ngd_ctrl_probe()
1539 dev_set_drvdata(dev, ctrl); in qcom_slim_ngd_ctrl_probe()
1542 ctrl->base = devm_ioremap_resource(dev, res); in qcom_slim_ngd_ctrl_probe()
1543 if (IS_ERR(ctrl->base)) in qcom_slim_ngd_ctrl_probe()
1544 return PTR_ERR(ctrl->base); in qcom_slim_ngd_ctrl_probe()
1551 IRQF_TRIGGER_HIGH, "slim-ngd", ctrl); in qcom_slim_ngd_ctrl_probe()
1555 ctrl->nb.notifier_call = qcom_slim_ngd_ssr_notify; in qcom_slim_ngd_ctrl_probe()
1556 ctrl->notifier = qcom_register_ssr_notifier("lpass", &ctrl->nb); in qcom_slim_ngd_ctrl_probe()
1557 if (IS_ERR(ctrl->notifier)) in qcom_slim_ngd_ctrl_probe()
1558 return PTR_ERR(ctrl->notifier); in qcom_slim_ngd_ctrl_probe()
1560 ctrl->dev = dev; in qcom_slim_ngd_ctrl_probe()
1561 ctrl->framer.rootfreq = SLIM_ROOT_FREQ >> 3; in qcom_slim_ngd_ctrl_probe()
1562 ctrl->framer.superfreq = in qcom_slim_ngd_ctrl_probe()
1563 ctrl->framer.rootfreq / SLIM_CL_PER_SUPERFRAME_DIV8; in qcom_slim_ngd_ctrl_probe()
1565 ctrl->ctrl.a_framer = &ctrl->framer; in qcom_slim_ngd_ctrl_probe()
1566 ctrl->ctrl.clkgear = SLIM_MAX_CLK_GEAR; in qcom_slim_ngd_ctrl_probe()
1567 ctrl->ctrl.get_laddr = qcom_slim_ngd_get_laddr; in qcom_slim_ngd_ctrl_probe()
1568 ctrl->ctrl.enable_stream = qcom_slim_ngd_enable_stream; in qcom_slim_ngd_ctrl_probe()
1569 ctrl->ctrl.xfer_msg = qcom_slim_ngd_xfer_msg; in qcom_slim_ngd_ctrl_probe()
1570 ctrl->ctrl.wakeup = NULL; in qcom_slim_ngd_ctrl_probe()
1571 ctrl->state = QCOM_SLIM_NGD_CTRL_DOWN; in qcom_slim_ngd_ctrl_probe()
1573 mutex_init(&ctrl->tx_lock); in qcom_slim_ngd_ctrl_probe()
1574 mutex_init(&ctrl->ssr_lock); in qcom_slim_ngd_ctrl_probe()
1575 spin_lock_init(&ctrl->tx_buf_lock); in qcom_slim_ngd_ctrl_probe()
1576 init_completion(&ctrl->reconf); in qcom_slim_ngd_ctrl_probe()
1577 init_completion(&ctrl->qmi.qmi_comp); in qcom_slim_ngd_ctrl_probe()
1578 init_completion(&ctrl->qmi_up); in qcom_slim_ngd_ctrl_probe()
1580 ctrl->pdr = pdr_handle_alloc(slim_pd_status, ctrl); in qcom_slim_ngd_ctrl_probe()
1581 if (IS_ERR(ctrl->pdr)) { in qcom_slim_ngd_ctrl_probe()
1582 ret = dev_err_probe(dev, PTR_ERR(ctrl->pdr), in qcom_slim_ngd_ctrl_probe()
1587 pds = pdr_add_lookup(ctrl->pdr, "avs/audio", "msm/adsp/audio_pd"); in qcom_slim_ngd_ctrl_probe()
1594 return of_qcom_slim_ngd_register(dev, ctrl); in qcom_slim_ngd_ctrl_probe()
1597 qcom_unregister_ssr_notifier(ctrl->notifier, &ctrl->nb); in qcom_slim_ngd_ctrl_probe()
1600 pdr_handle_release(ctrl->pdr); in qcom_slim_ngd_ctrl_probe()
1614 struct qcom_slim_ngd_ctrl *ctrl = platform_get_drvdata(pdev); in qcom_slim_ngd_remove() local
1617 pdr_handle_release(ctrl->pdr); in qcom_slim_ngd_remove()
1618 qcom_unregister_ssr_notifier(ctrl->notifier, &ctrl->nb); in qcom_slim_ngd_remove()
1619 qcom_slim_ngd_enable(ctrl, false); in qcom_slim_ngd_remove()
1620 qcom_slim_ngd_exit_dma(ctrl); in qcom_slim_ngd_remove()
1621 qcom_slim_ngd_qmi_svc_event_deinit(&ctrl->qmi); in qcom_slim_ngd_remove()
1622 if (ctrl->mwq) in qcom_slim_ngd_remove()
1623 destroy_workqueue(ctrl->mwq); in qcom_slim_ngd_remove()
1625 kfree(ctrl->ngd); in qcom_slim_ngd_remove()
1626 ctrl->ngd = NULL; in qcom_slim_ngd_remove()
1632 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev); in qcom_slim_ngd_runtime_idle() local
1634 if (ctrl->state == QCOM_SLIM_NGD_CTRL_AWAKE) in qcom_slim_ngd_runtime_idle()
1635 ctrl->state = QCOM_SLIM_NGD_CTRL_IDLE; in qcom_slim_ngd_runtime_idle()
1642 struct qcom_slim_ngd_ctrl *ctrl = dev_get_drvdata(dev); in qcom_slim_ngd_runtime_suspend() local
1645 qcom_slim_ngd_exit_dma(ctrl); in qcom_slim_ngd_runtime_suspend()
1646 if (!ctrl->qmi.handle) in qcom_slim_ngd_runtime_suspend()
1649 ret = qcom_slim_qmi_power_request(ctrl, false); in qcom_slim_ngd_runtime_suspend()
1651 dev_info(ctrl->dev, "slim resource not idle:%d\n", ret); in qcom_slim_ngd_runtime_suspend()
1653 ctrl->state = QCOM_SLIM_NGD_CTRL_ASLEEP; in qcom_slim_ngd_runtime_suspend()
1672 .name = "qcom,slim-ngd-ctrl",