Lines Matching +full:rclk +full:- +full:- +full:- +full:- +full:-

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2017, The Linux Foundation
88 /* Resource group info for manager, and non-ported generic device-components */
116 struct clk *rclk; member
125 __iowrite32_copy(ctrl->base + tx_reg, buf, count); in qcom_slim_queue_tx()
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()
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()
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()
199 err = -ENOTCONN; in qcom_slim_handle_tx_irq()
214 pkt[0] = readl_relaxed(ctrl->base + MGR_RX_MSG); in qcom_slim_handle_rx_irq()
221 * let work-queue handle it 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()
247 (u8)(*rx_buf >> 24), (len - 4)); 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()
266 u32 stat = readl_relaxed(ctrl->base + MGR_INT_STAT); in qcom_slim_interrupt()
280 struct qcom_slim_ctrl *ctrl = dev_get_drvdata(sctrl->dev); in qcom_clk_pause_wakeup()
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()
290 * HW Workaround: Currently, slave is reporting lost-sync messages in qcom_clk_pause_wakeup()
295 * being 250 usecs, we wait for 5-10 superframes here to ensure in qcom_clk_pause_wakeup()
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()
331 unsigned long ms = txn->rl + HZ; in qcom_xfer_msg()
335 u8 la = txn->la; in qcom_xfer_msg()
338 txn->rl--; in qcom_xfer_msg()
342 while (retries--) { in qcom_xfer_msg()
351 return -ENOMEM; in qcom_xfer_msg()
356 if (txn->dt == SLIM_MSG_DEST_LOGICALADDR) { in qcom_xfer_msg()
357 *head = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, in qcom_xfer_msg()
358 txn->mc, 0, la); in qcom_xfer_msg()
361 *head = SLIM_MSG_ASM_FIRST_WORD(txn->rl, txn->mt, in qcom_xfer_msg()
362 txn->mc, 1, la); in qcom_xfer_msg()
366 if (slim_tid_txn(txn->mt, txn->mc)) in qcom_xfer_msg()
367 *(puc++) = txn->tid; in qcom_xfer_msg()
369 if (slim_ec_txn(txn->mt, txn->mc)) { in qcom_xfer_msg()
370 *(puc++) = (txn->ec & 0xFF); in qcom_xfer_msg()
371 *(puc++) = (txn->ec >> 8) & 0xFF; in qcom_xfer_msg()
374 if (txn->msg && txn->msg->wbuf) in qcom_xfer_msg()
375 memcpy(puc, txn->msg->wbuf, txn->msg->num_bytes); in qcom_xfer_msg()
377 qcom_slim_queue_tx(ctrl, head, txn->rl, MGR_TX_MSG); in qcom_xfer_msg()
381 dev_err(ctrl->dev, "TX timed out:MC:0x%x,mt:0x%x", txn->mc, in qcom_xfer_msg()
382 txn->mt); in qcom_xfer_msg()
383 ret = -ETIMEDOUT; in qcom_xfer_msg()
393 struct qcom_slim_ctrl *ctrl = dev_get_drvdata(sctrl->dev); in qcom_set_laddr()
406 p.manf_id = cpu_to_be16(ead->manf_id); in qcom_set_laddr()
407 p.prod_code = cpu_to_be16(ead->prod_code); in qcom_set_laddr()
408 p.dev_index = ead->dev_index; in qcom_set_laddr()
409 p.instance = ead->instance; in qcom_set_laddr()
414 ret = slim_do_transfer(&ctrl->ctrl, &txn); in qcom_set_laddr()
417 dev_err(ctrl->dev, "set LA:0x%x failed:ret:%d\n", in qcom_set_laddr()
426 spin_lock_irqsave(&ctrl->rx.lock, flags); in slim_get_current_rxbuf()
427 if (ctrl->rx.tail == ctrl->rx.head) { in slim_get_current_rxbuf()
428 spin_unlock_irqrestore(&ctrl->rx.lock, flags); in slim_get_current_rxbuf()
429 return -ENODATA; in slim_get_current_rxbuf()
431 memcpy(buf, ctrl->rx.base + (ctrl->rx.head * ctrl->rx.sl_sz), in slim_get_current_rxbuf()
432 ctrl->rx.sl_sz); in slim_get_current_rxbuf()
434 ctrl->rx.head = (ctrl->rx.head + 1) % ctrl->rx.n; in slim_get_current_rxbuf()
435 spin_unlock_irqrestore(&ctrl->rx.lock, flags); in slim_get_current_rxbuf()
448 while ((slim_get_current_rxbuf(ctrl, buf)) != -ENODATA) { in qcom_slim_rxwq()
461 ret = slim_device_report_present(&ctrl->ctrl, &ea, in qcom_slim_rxwq()
464 dev_err(ctrl->dev, "assign laddr failed:%d\n", in qcom_slim_rxwq()
467 dev_err(ctrl->dev, "unexpected message:mc:%x, mt:%x\n", in qcom_slim_rxwq()
476 if (!ctrl->slew_reg) { in qcom_slim_prg_slew()
478 ctrl->slew_reg = devm_platform_ioremap_resource_byname(pdev, "slew"); in qcom_slim_prg_slew()
479 if (IS_ERR(ctrl->slew_reg)) in qcom_slim_prg_slew()
483 writel_relaxed(1, ctrl->slew_reg); in qcom_slim_prg_slew()
484 /* Make sure SLIMbus-slew rate enabling goes through */ in qcom_slim_prg_slew()
494 ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); in qcom_slim_probe()
496 return -ENOMEM; in qcom_slim_probe()
498 ctrl->hclk = devm_clk_get(&pdev->dev, "iface"); in qcom_slim_probe()
499 if (IS_ERR(ctrl->hclk)) in qcom_slim_probe()
500 return PTR_ERR(ctrl->hclk); in qcom_slim_probe()
502 ctrl->rclk = devm_clk_get(&pdev->dev, "core"); in qcom_slim_probe()
503 if (IS_ERR(ctrl->rclk)) in qcom_slim_probe()
504 return PTR_ERR(ctrl->rclk); in qcom_slim_probe()
506 ret = clk_set_rate(ctrl->rclk, SLIM_ROOT_FREQ); in qcom_slim_probe()
508 dev_err(&pdev->dev, "ref-clock set-rate failed:%d\n", ret); in qcom_slim_probe()
512 ctrl->irq = platform_get_irq(pdev, 0); in qcom_slim_probe()
513 if (ctrl->irq < 0) in qcom_slim_probe()
514 return ctrl->irq; in qcom_slim_probe()
516 sctrl = &ctrl->ctrl; in qcom_slim_probe()
517 sctrl->dev = &pdev->dev; in qcom_slim_probe()
518 ctrl->dev = &pdev->dev; in qcom_slim_probe()
520 dev_set_drvdata(ctrl->dev, ctrl); in qcom_slim_probe()
522 ctrl->base = devm_platform_ioremap_resource_byname(pdev, "ctrl"); in qcom_slim_probe()
523 if (IS_ERR(ctrl->base)) in qcom_slim_probe()
524 return PTR_ERR(ctrl->base); in qcom_slim_probe()
526 sctrl->set_laddr = qcom_set_laddr; in qcom_slim_probe()
527 sctrl->xfer_msg = qcom_xfer_msg; in qcom_slim_probe()
528 sctrl->wakeup = qcom_clk_pause_wakeup; in qcom_slim_probe()
529 ctrl->tx.n = QCOM_TX_MSGS; in qcom_slim_probe()
530 ctrl->tx.sl_sz = SLIM_MSGQ_BUF_LEN; in qcom_slim_probe()
531 ctrl->rx.n = QCOM_RX_MSGS; in qcom_slim_probe()
532 ctrl->rx.sl_sz = SLIM_MSGQ_BUF_LEN; in qcom_slim_probe()
533 ctrl->wr_comp = kcalloc(QCOM_TX_MSGS, sizeof(struct completion *), in qcom_slim_probe()
535 if (!ctrl->wr_comp) in qcom_slim_probe()
536 return -ENOMEM; in qcom_slim_probe()
538 spin_lock_init(&ctrl->rx.lock); in qcom_slim_probe()
539 spin_lock_init(&ctrl->tx.lock); in qcom_slim_probe()
540 INIT_WORK(&ctrl->wd, qcom_slim_rxwq); in qcom_slim_probe()
541 ctrl->rxwq = create_singlethread_workqueue("qcom_slim_rx"); in qcom_slim_probe()
542 if (!ctrl->rxwq) { in qcom_slim_probe()
543 dev_err(ctrl->dev, "Failed to start Rx WQ\n"); in qcom_slim_probe()
544 return -ENOMEM; in qcom_slim_probe()
547 ctrl->framer.rootfreq = SLIM_ROOT_FREQ / 8; in qcom_slim_probe()
548 ctrl->framer.superfreq = in qcom_slim_probe()
549 ctrl->framer.rootfreq / SLIM_CL_PER_SUPERFRAME_DIV8; in qcom_slim_probe()
550 sctrl->a_framer = &ctrl->framer; in qcom_slim_probe()
551 sctrl->clkgear = SLIM_MAX_CLK_GEAR; in qcom_slim_probe()
555 ret = devm_request_irq(&pdev->dev, ctrl->irq, qcom_slim_interrupt, in qcom_slim_probe()
558 dev_err(&pdev->dev, "request IRQ failed\n"); in qcom_slim_probe()
562 ret = clk_prepare_enable(ctrl->hclk); in qcom_slim_probe()
566 ret = clk_prepare_enable(ctrl->rclk); in qcom_slim_probe()
570 ctrl->tx.base = devm_kcalloc(&pdev->dev, ctrl->tx.n, ctrl->tx.sl_sz, in qcom_slim_probe()
572 if (!ctrl->tx.base) { in qcom_slim_probe()
573 ret = -ENOMEM; in qcom_slim_probe()
577 ctrl->rx.base = devm_kcalloc(&pdev->dev,ctrl->rx.n, ctrl->rx.sl_sz, in qcom_slim_probe()
579 if (!ctrl->rx.base) { in qcom_slim_probe()
580 ret = -ENOMEM; in qcom_slim_probe()
585 ret = slim_register_controller(&ctrl->ctrl); in qcom_slim_probe()
587 dev_err(ctrl->dev, "error adding controller\n"); in qcom_slim_probe()
591 ver = readl_relaxed(ctrl->base); in qcom_slim_probe()
595 writel(1, ctrl->base + CFG_PORT(COMP_CFG, ver)); in qcom_slim_probe()
597 ctrl->base + CFG_PORT(COMP_TRUST_CFG, ver)); in qcom_slim_probe()
601 MGR_INT_TX_MSG_SENT), ctrl->base + MGR_INT_EN); in qcom_slim_probe()
602 writel(1, ctrl->base + MGR_CFG); in qcom_slim_probe()
606 ctrl->base + FRM_CFG); in qcom_slim_probe()
607 writel(MGR_CFG_ENABLE, ctrl->base + MGR_CFG); in qcom_slim_probe()
608 writel(1, ctrl->base + INTF_CFG); in qcom_slim_probe()
609 writel(1, ctrl->base + CFG_PORT(COMP_CFG, ver)); in qcom_slim_probe()
611 pm_runtime_use_autosuspend(&pdev->dev); in qcom_slim_probe()
612 pm_runtime_set_autosuspend_delay(&pdev->dev, QCOM_SLIM_AUTOSUSPEND); in qcom_slim_probe()
613 pm_runtime_set_active(&pdev->dev); in qcom_slim_probe()
614 pm_runtime_mark_last_busy(&pdev->dev); in qcom_slim_probe()
615 pm_runtime_enable(&pdev->dev); in qcom_slim_probe()
617 dev_dbg(ctrl->dev, "QCOM SB controller is up:ver:0x%x!\n", ver); in qcom_slim_probe()
621 clk_disable_unprepare(ctrl->rclk); in qcom_slim_probe()
623 clk_disable_unprepare(ctrl->hclk); in qcom_slim_probe()
626 destroy_workqueue(ctrl->rxwq); in qcom_slim_probe()
634 pm_runtime_disable(&pdev->dev); in qcom_slim_remove()
635 slim_unregister_controller(&ctrl->ctrl); in qcom_slim_remove()
636 clk_disable_unprepare(ctrl->rclk); in qcom_slim_remove()
637 clk_disable_unprepare(ctrl->hclk); in qcom_slim_remove()
638 destroy_workqueue(ctrl->rxwq); in qcom_slim_remove()
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()
669 ret = slim_ctrl_clk_pause(&ctrl->ctrl, true, 0); in qcom_slim_runtime_resume()