Lines Matching refs:ctrl

103 	struct slim_controller  ctrl;  member
120 static void qcom_slim_queue_tx(struct qcom_slim_ctrl *ctrl, void *buf, in qcom_slim_queue_tx() argument
125 __iowrite32_copy(ctrl->base + tx_reg, buf, count); in qcom_slim_queue_tx()
131 static void *slim_alloc_rxbuf(struct qcom_slim_ctrl *ctrl) in slim_alloc_rxbuf() argument
136 spin_lock_irqsave(&ctrl->rx.lock, flags); in slim_alloc_rxbuf()
137 if ((ctrl->rx.tail + 1) % ctrl->rx.n == ctrl->rx.head) { in slim_alloc_rxbuf()
138 spin_unlock_irqrestore(&ctrl->rx.lock, flags); in slim_alloc_rxbuf()
139 dev_err(ctrl->dev, "RX QUEUE full!"); in slim_alloc_rxbuf()
142 idx = ctrl->rx.tail; in slim_alloc_rxbuf()
143 ctrl->rx.tail = (ctrl->rx.tail + 1) % ctrl->rx.n; in slim_alloc_rxbuf()
144 spin_unlock_irqrestore(&ctrl->rx.lock, flags); in slim_alloc_rxbuf()
146 return ctrl->rx.base + (idx * ctrl->rx.sl_sz); in slim_alloc_rxbuf()
149 static void slim_ack_txn(struct qcom_slim_ctrl *ctrl, int err) in slim_ack_txn() argument
155 spin_lock_irqsave(&ctrl->tx.lock, flags); in slim_ack_txn()
156 idx = ctrl->tx.head; in slim_ack_txn()
157 ctrl->tx.head = (ctrl->tx.head + 1) % ctrl->tx.n; in slim_ack_txn()
158 spin_unlock_irqrestore(&ctrl->tx.lock, flags); in slim_ack_txn()
160 comp = ctrl->wr_comp[idx]; in slim_ack_txn()
161 ctrl->wr_comp[idx] = NULL; in slim_ack_txn()
166 static irqreturn_t qcom_slim_handle_tx_irq(struct qcom_slim_ctrl *ctrl, in qcom_slim_handle_tx_irq() argument
173 ctrl->base + MGR_INT_CLR); in qcom_slim_handle_tx_irq()
176 u32 mgr_stat = readl_relaxed(ctrl->base + MGR_STATUS); in qcom_slim_handle_tx_irq()
177 u32 mgr_ie_stat = readl_relaxed(ctrl->base + MGR_IE_STAT); in qcom_slim_handle_tx_irq()
178 u32 frm_stat = readl_relaxed(ctrl->base + FRM_STAT); in qcom_slim_handle_tx_irq()
179 u32 frm_cfg = readl_relaxed(ctrl->base + FRM_CFG); in qcom_slim_handle_tx_irq()
180 u32 frm_intr_stat = readl_relaxed(ctrl->base + FRM_INT_STAT); in qcom_slim_handle_tx_irq()
181 u32 frm_ie_stat = readl_relaxed(ctrl->base + FRM_IE_STAT); in qcom_slim_handle_tx_irq()
182 u32 intf_stat = readl_relaxed(ctrl->base + INTF_STAT); in qcom_slim_handle_tx_irq()
183 u32 intf_intr_stat = readl_relaxed(ctrl->base + INTF_INT_STAT); in qcom_slim_handle_tx_irq()
184 u32 intf_ie_stat = readl_relaxed(ctrl->base + INTF_IE_STAT); in qcom_slim_handle_tx_irq()
186 writel_relaxed(MGR_INT_TX_NACKED_2, ctrl->base + MGR_INT_CLR); in qcom_slim_handle_tx_irq()
188 dev_err(ctrl->dev, "TX Nack MGR:int:0x%x, stat:0x%x\n", in qcom_slim_handle_tx_irq()
190 dev_err(ctrl->dev, "TX Nack MGR:ie:0x%x\n", mgr_ie_stat); in qcom_slim_handle_tx_irq()
191 dev_err(ctrl->dev, "TX Nack FRM:int:0x%x, stat:0x%x\n", in qcom_slim_handle_tx_irq()
193 dev_err(ctrl->dev, "TX Nack FRM:cfg:0x%x, ie:0x%x\n", in qcom_slim_handle_tx_irq()
195 dev_err(ctrl->dev, "TX Nack INTF:intr:0x%x, stat:0x%x\n", in qcom_slim_handle_tx_irq()
197 dev_err(ctrl->dev, "TX Nack INTF:ie:0x%x\n", in qcom_slim_handle_tx_irq()
202 slim_ack_txn(ctrl, err); in qcom_slim_handle_tx_irq()
207 static irqreturn_t qcom_slim_handle_rx_irq(struct qcom_slim_ctrl *ctrl, in qcom_slim_handle_rx_irq() argument
214 pkt[0] = readl_relaxed(ctrl->base + MGR_RX_MSG); in qcom_slim_handle_rx_irq()
224 rx_buf = (u32 *)slim_alloc_rxbuf(ctrl); in qcom_slim_handle_rx_irq()
226 dev_err(ctrl->dev, "dropping RX:0x%x due to RX full\n", in qcom_slim_handle_rx_irq()
236 __ioread32_copy(rx_buf + 1, ctrl->base + MGR_RX_MSG + 4, in qcom_slim_handle_rx_irq()
246 slim_msg_response(&ctrl->ctrl, (u8 *)(rx_buf + 1), in qcom_slim_handle_rx_irq()
250 dev_err(ctrl->dev, "unsupported MC,%x MT:%x\n", in qcom_slim_handle_rx_irq()
255 writel(MGR_INT_RX_MSG_RCVD, ctrl->base + in qcom_slim_handle_rx_irq()
258 queue_work(ctrl->rxwq, &ctrl->wd); in qcom_slim_handle_rx_irq()
265 struct qcom_slim_ctrl *ctrl = d; in qcom_slim_interrupt() local
266 u32 stat = readl_relaxed(ctrl->base + MGR_INT_STAT); in qcom_slim_interrupt()
270 ret = qcom_slim_handle_tx_irq(ctrl, stat); in qcom_slim_interrupt()
273 ret = qcom_slim_handle_rx_irq(ctrl, stat); in qcom_slim_interrupt()
280 struct qcom_slim_ctrl *ctrl = dev_get_drvdata(sctrl->dev); in qcom_clk_pause_wakeup() local
282 clk_prepare_enable(ctrl->hclk); in qcom_clk_pause_wakeup()
283 clk_prepare_enable(ctrl->rclk); in qcom_clk_pause_wakeup()
284 enable_irq(ctrl->irq); in qcom_clk_pause_wakeup()
286 writel_relaxed(1, ctrl->base + FRM_WAKEUP); in qcom_clk_pause_wakeup()
302 static void *slim_alloc_txbuf(struct qcom_slim_ctrl *ctrl, in slim_alloc_txbuf() argument
309 spin_lock_irqsave(&ctrl->tx.lock, flags); in slim_alloc_txbuf()
310 if (((ctrl->tx.head + 1) % ctrl->tx.n) == ctrl->tx.tail) { in slim_alloc_txbuf()
311 spin_unlock_irqrestore(&ctrl->tx.lock, flags); in slim_alloc_txbuf()
312 dev_err(ctrl->dev, "controller TX buf unavailable"); in slim_alloc_txbuf()
315 idx = ctrl->tx.tail; in slim_alloc_txbuf()
316 ctrl->wr_comp[idx] = done; in slim_alloc_txbuf()
317 ctrl->tx.tail = (ctrl->tx.tail + 1) % ctrl->tx.n; in slim_alloc_txbuf()
319 spin_unlock_irqrestore(&ctrl->tx.lock, flags); in slim_alloc_txbuf()
321 return ctrl->tx.base + (idx * ctrl->tx.sl_sz); in slim_alloc_txbuf()
328 struct qcom_slim_ctrl *ctrl = dev_get_drvdata(sctrl->dev); in qcom_xfer_msg() local
330 void *pbuf = slim_alloc_txbuf(ctrl, txn, &done); in qcom_xfer_msg()
343 pbuf = slim_alloc_txbuf(ctrl, txn, &done); in qcom_xfer_msg()
376 qcom_slim_queue_tx(ctrl, head, txn->rl, MGR_TX_MSG); in qcom_xfer_msg()
380 dev_err(ctrl->dev, "TX timed out:MC:0x%x,mt:0x%x", txn->mc, in qcom_xfer_msg()
392 struct qcom_slim_ctrl *ctrl = dev_get_drvdata(sctrl->dev); in qcom_set_laddr() local
413 ret = slim_do_transfer(&ctrl->ctrl, &txn); in qcom_set_laddr()
416 dev_err(ctrl->dev, "set LA:0x%x failed:ret:%d\n", in qcom_set_laddr()
421 static int slim_get_current_rxbuf(struct qcom_slim_ctrl *ctrl, void *buf) in slim_get_current_rxbuf() argument
425 spin_lock_irqsave(&ctrl->rx.lock, flags); in slim_get_current_rxbuf()
426 if (ctrl->rx.tail == ctrl->rx.head) { in slim_get_current_rxbuf()
427 spin_unlock_irqrestore(&ctrl->rx.lock, flags); in slim_get_current_rxbuf()
430 memcpy(buf, ctrl->rx.base + (ctrl->rx.head * ctrl->rx.sl_sz), in slim_get_current_rxbuf()
431 ctrl->rx.sl_sz); in slim_get_current_rxbuf()
433 ctrl->rx.head = (ctrl->rx.head + 1) % ctrl->rx.n; in slim_get_current_rxbuf()
434 spin_unlock_irqrestore(&ctrl->rx.lock, flags); in slim_get_current_rxbuf()
444 struct qcom_slim_ctrl *ctrl = container_of(work, struct qcom_slim_ctrl, in qcom_slim_rxwq() local
447 while ((slim_get_current_rxbuf(ctrl, buf)) != -ENODATA) { in qcom_slim_rxwq()
460 ret = slim_device_report_present(&ctrl->ctrl, &ea, in qcom_slim_rxwq()
463 dev_err(ctrl->dev, "assign laddr failed:%d\n", in qcom_slim_rxwq()
466 dev_err(ctrl->dev, "unexpected message:mc:%x, mt:%x\n", in qcom_slim_rxwq()
473 struct qcom_slim_ctrl *ctrl) in qcom_slim_prg_slew() argument
475 if (!ctrl->slew_reg) { in qcom_slim_prg_slew()
477 ctrl->slew_reg = devm_platform_ioremap_resource_byname(pdev, "slew"); in qcom_slim_prg_slew()
478 if (IS_ERR(ctrl->slew_reg)) in qcom_slim_prg_slew()
482 writel_relaxed(1, ctrl->slew_reg); in qcom_slim_prg_slew()
489 struct qcom_slim_ctrl *ctrl; in qcom_slim_probe() local
493 ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); in qcom_slim_probe()
494 if (!ctrl) in qcom_slim_probe()
497 ctrl->hclk = devm_clk_get(&pdev->dev, "iface"); in qcom_slim_probe()
498 if (IS_ERR(ctrl->hclk)) in qcom_slim_probe()
499 return PTR_ERR(ctrl->hclk); in qcom_slim_probe()
501 ctrl->rclk = devm_clk_get(&pdev->dev, "core"); in qcom_slim_probe()
502 if (IS_ERR(ctrl->rclk)) in qcom_slim_probe()
503 return PTR_ERR(ctrl->rclk); in qcom_slim_probe()
505 ret = clk_set_rate(ctrl->rclk, SLIM_ROOT_FREQ); in qcom_slim_probe()
511 ctrl->irq = platform_get_irq(pdev, 0); in qcom_slim_probe()
512 if (ctrl->irq < 0) in qcom_slim_probe()
513 return ctrl->irq; in qcom_slim_probe()
515 sctrl = &ctrl->ctrl; in qcom_slim_probe()
517 ctrl->dev = &pdev->dev; in qcom_slim_probe()
518 platform_set_drvdata(pdev, ctrl); in qcom_slim_probe()
519 dev_set_drvdata(ctrl->dev, ctrl); in qcom_slim_probe()
521 ctrl->base = devm_platform_ioremap_resource_byname(pdev, "ctrl"); in qcom_slim_probe()
522 if (IS_ERR(ctrl->base)) in qcom_slim_probe()
523 return PTR_ERR(ctrl->base); in qcom_slim_probe()
528 ctrl->tx.n = QCOM_TX_MSGS; in qcom_slim_probe()
529 ctrl->tx.sl_sz = SLIM_MSGQ_BUF_LEN; in qcom_slim_probe()
530 ctrl->rx.n = QCOM_RX_MSGS; in qcom_slim_probe()
531 ctrl->rx.sl_sz = SLIM_MSGQ_BUF_LEN; in qcom_slim_probe()
532 ctrl->wr_comp = kcalloc(QCOM_TX_MSGS, sizeof(struct completion *), in qcom_slim_probe()
534 if (!ctrl->wr_comp) in qcom_slim_probe()
537 spin_lock_init(&ctrl->rx.lock); in qcom_slim_probe()
538 spin_lock_init(&ctrl->tx.lock); in qcom_slim_probe()
539 INIT_WORK(&ctrl->wd, qcom_slim_rxwq); in qcom_slim_probe()
540 ctrl->rxwq = create_singlethread_workqueue("qcom_slim_rx"); in qcom_slim_probe()
541 if (!ctrl->rxwq) { in qcom_slim_probe()
542 dev_err(ctrl->dev, "Failed to start Rx WQ\n"); in qcom_slim_probe()
546 ctrl->framer.rootfreq = SLIM_ROOT_FREQ / 8; in qcom_slim_probe()
547 ctrl->framer.superfreq = in qcom_slim_probe()
548 ctrl->framer.rootfreq / SLIM_CL_PER_SUPERFRAME_DIV8; in qcom_slim_probe()
549 sctrl->a_framer = &ctrl->framer; in qcom_slim_probe()
552 qcom_slim_prg_slew(pdev, ctrl); in qcom_slim_probe()
554 ret = devm_request_irq(&pdev->dev, ctrl->irq, qcom_slim_interrupt, in qcom_slim_probe()
555 IRQF_TRIGGER_HIGH, "qcom_slim_irq", ctrl); in qcom_slim_probe()
561 ret = clk_prepare_enable(ctrl->hclk); in qcom_slim_probe()
565 ret = clk_prepare_enable(ctrl->rclk); in qcom_slim_probe()
569 ctrl->tx.base = devm_kcalloc(&pdev->dev, ctrl->tx.n, ctrl->tx.sl_sz, in qcom_slim_probe()
571 if (!ctrl->tx.base) { in qcom_slim_probe()
576 ctrl->rx.base = devm_kcalloc(&pdev->dev,ctrl->rx.n, ctrl->rx.sl_sz, in qcom_slim_probe()
578 if (!ctrl->rx.base) { in qcom_slim_probe()
584 ret = slim_register_controller(&ctrl->ctrl); in qcom_slim_probe()
586 dev_err(ctrl->dev, "error adding controller\n"); in qcom_slim_probe()
590 ver = readl_relaxed(ctrl->base); in qcom_slim_probe()
594 writel(1, ctrl->base + CFG_PORT(COMP_CFG, ver)); in qcom_slim_probe()
596 ctrl->base + CFG_PORT(COMP_TRUST_CFG, ver)); in qcom_slim_probe()
600 MGR_INT_TX_MSG_SENT), ctrl->base + MGR_INT_EN); in qcom_slim_probe()
601 writel(1, ctrl->base + MGR_CFG); in qcom_slim_probe()
605 ctrl->base + FRM_CFG); in qcom_slim_probe()
606 writel(MGR_CFG_ENABLE, ctrl->base + MGR_CFG); in qcom_slim_probe()
607 writel(1, ctrl->base + INTF_CFG); in qcom_slim_probe()
608 writel(1, ctrl->base + CFG_PORT(COMP_CFG, ver)); in qcom_slim_probe()
616 dev_dbg(ctrl->dev, "QCOM SB controller is up:ver:0x%x!\n", ver); in qcom_slim_probe()
620 clk_disable_unprepare(ctrl->rclk); in qcom_slim_probe()
622 clk_disable_unprepare(ctrl->hclk); in qcom_slim_probe()
625 destroy_workqueue(ctrl->rxwq); in qcom_slim_probe()
631 struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev); in qcom_slim_remove() local
634 slim_unregister_controller(&ctrl->ctrl); in qcom_slim_remove()
635 clk_disable_unprepare(ctrl->rclk); in qcom_slim_remove()
636 clk_disable_unprepare(ctrl->hclk); in qcom_slim_remove()
637 destroy_workqueue(ctrl->rxwq); in qcom_slim_remove()
648 struct qcom_slim_ctrl *ctrl = dev_get_drvdata(device); in qcom_slim_runtime_suspend() local
652 ret = slim_ctrl_clk_pause(&ctrl->ctrl, false, SLIM_CLK_UNSPECIFIED); in qcom_slim_runtime_suspend()
656 disable_irq(ctrl->irq); in qcom_slim_runtime_suspend()
657 clk_disable_unprepare(ctrl->hclk); in qcom_slim_runtime_suspend()
658 clk_disable_unprepare(ctrl->rclk); in qcom_slim_runtime_suspend()
665 struct qcom_slim_ctrl *ctrl = dev_get_drvdata(device); in qcom_slim_runtime_resume() local
669 ret = slim_ctrl_clk_pause(&ctrl->ctrl, true, 0); in qcom_slim_runtime_resume()