Lines Matching refs:mtk
23 #include "xhci-mtk.h"
76 static int xhci_mtk_host_enable(struct xhci_hcd_mtk *mtk)
78 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs;
84 if (!mtk->has_ippc)
93 for (i = 0; i < mtk->num_u3_ports; i++) {
94 if ((0x1 << i) & mtk->u3p_dis_msk) {
106 for (i = 0; i < mtk->num_u2_ports; i++) {
120 if (mtk->num_u3_ports > u3_ports_disabled)
126 dev_err(mtk->dev, "clocks are not stable (0x%x)\n", value);
133 static int xhci_mtk_host_disable(struct xhci_hcd_mtk *mtk)
135 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs;
140 if (!mtk->has_ippc)
144 for (i = 0; i < mtk->num_u3_ports; i++) {
145 if ((0x1 << i) & mtk->u3p_dis_msk)
154 for (i = 0; i < mtk->num_u2_ports; i++) {
169 dev_err(mtk->dev, "ip sleep failed!!!\n");
175 static int xhci_mtk_ssusb_config(struct xhci_hcd_mtk *mtk)
177 struct mu3c_ippc_regs __iomem *ippc = mtk->ippc_regs;
180 if (!mtk->has_ippc)
201 mtk->num_u3_ports = CAP_U3_PORT_NUM(value);
202 mtk->num_u2_ports = CAP_U2_PORT_NUM(value);
203 dev_dbg(mtk->dev, "%s u2p:%d, u3p:%d\n", __func__,
204 mtk->num_u2_ports, mtk->num_u3_ports);
206 return xhci_mtk_host_enable(mtk);
209 static int xhci_mtk_clks_get(struct xhci_hcd_mtk *mtk)
211 struct device *dev = mtk->dev;
213 mtk->sys_clk = devm_clk_get(dev, "sys_ck");
214 if (IS_ERR(mtk->sys_clk)) {
216 return PTR_ERR(mtk->sys_clk);
219 mtk->xhci_clk = devm_clk_get_optional(dev, "xhci_ck");
220 if (IS_ERR(mtk->xhci_clk))
221 return PTR_ERR(mtk->xhci_clk);
223 mtk->ref_clk = devm_clk_get_optional(dev, "ref_ck");
224 if (IS_ERR(mtk->ref_clk))
225 return PTR_ERR(mtk->ref_clk);
227 mtk->mcu_clk = devm_clk_get_optional(dev, "mcu_ck");
228 if (IS_ERR(mtk->mcu_clk))
229 return PTR_ERR(mtk->mcu_clk);
231 mtk->dma_clk = devm_clk_get_optional(dev, "dma_ck");
232 return PTR_ERR_OR_ZERO(mtk->dma_clk);
235 static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
239 ret = clk_prepare_enable(mtk->ref_clk);
241 dev_err(mtk->dev, "failed to enable ref_clk\n");
245 ret = clk_prepare_enable(mtk->sys_clk);
247 dev_err(mtk->dev, "failed to enable sys_clk\n");
251 ret = clk_prepare_enable(mtk->xhci_clk);
253 dev_err(mtk->dev, "failed to enable xhci_clk\n");
257 ret = clk_prepare_enable(mtk->mcu_clk);
259 dev_err(mtk->dev, "failed to enable mcu_clk\n");
263 ret = clk_prepare_enable(mtk->dma_clk);
265 dev_err(mtk->dev, "failed to enable dma_clk\n");
272 clk_disable_unprepare(mtk->mcu_clk);
274 clk_disable_unprepare(mtk->xhci_clk);
276 clk_disable_unprepare(mtk->sys_clk);
278 clk_disable_unprepare(mtk->ref_clk);
283 static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)
285 clk_disable_unprepare(mtk->dma_clk);
286 clk_disable_unprepare(mtk->mcu_clk);
287 clk_disable_unprepare(mtk->xhci_clk);
288 clk_disable_unprepare(mtk->sys_clk);
289 clk_disable_unprepare(mtk->ref_clk);
293 static void usb_wakeup_ip_sleep_set(struct xhci_hcd_mtk *mtk, bool enable)
297 switch (mtk->uwk_vers) {
299 reg = mtk->uwk_reg_base + PERI_WK_CTRL1;
304 reg = mtk->uwk_reg_base + PERI_SSUSB_SPM_CTRL;
311 regmap_update_bits(mtk->uwk, reg, msk, val);
314 static int usb_wakeup_of_property_parse(struct xhci_hcd_mtk *mtk,
321 mtk->uwk_en = of_property_read_bool(dn, "wakeup-source");
322 if (!mtk->uwk_en)
330 mtk->uwk_reg_base = args.args[0];
331 mtk->uwk_vers = args.args[1];
332 mtk->uwk = syscon_node_to_regmap(args.np);
334 dev_info(mtk->dev, "uwk - reg:0x%x, version:%d\n",
335 mtk->uwk_reg_base, mtk->uwk_vers);
337 return PTR_ERR_OR_ZERO(mtk->uwk);
341 static void usb_wakeup_set(struct xhci_hcd_mtk *mtk, bool enable)
343 if (mtk->uwk_en)
344 usb_wakeup_ip_sleep_set(mtk, enable);
356 static int xhci_mtk_ldos_enable(struct xhci_hcd_mtk *mtk)
360 ret = regulator_enable(mtk->vbus);
362 dev_err(mtk->dev, "failed to enable vbus\n");
366 ret = regulator_enable(mtk->vusb33);
368 dev_err(mtk->dev, "failed to enable vusb33\n");
369 regulator_disable(mtk->vbus);
375 static void xhci_mtk_ldos_disable(struct xhci_hcd_mtk *mtk)
377 regulator_disable(mtk->vbus);
378 regulator_disable(mtk->vusb33);
384 struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
398 if (mtk->lpm_support)
400 if (mtk->u2_lpm_disable)
414 struct xhci_hcd_mtk *mtk = hcd_to_mtk(hcd);
418 ret = xhci_mtk_ssusb_config(mtk);
428 ret = xhci_mtk_sch_init(mtk);
440 struct xhci_hcd_mtk *mtk;
452 mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL);
453 if (!mtk)
456 mtk->dev = dev;
457 mtk->vbus = devm_regulator_get(dev, "vbus");
458 if (IS_ERR(mtk->vbus)) {
460 return PTR_ERR(mtk->vbus);
463 mtk->vusb33 = devm_regulator_get(dev, "vusb33");
464 if (IS_ERR(mtk->vusb33)) {
466 return PTR_ERR(mtk->vusb33);
469 ret = xhci_mtk_clks_get(mtk);
473 mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable");
474 mtk->u2_lpm_disable = of_property_read_bool(node, "usb2-lpm-disable");
477 &mtk->u3p_dis_msk);
479 ret = usb_wakeup_of_property_parse(mtk, node);
489 ret = xhci_mtk_ldos_enable(mtk);
493 ret = xhci_mtk_clks_enable(mtk);
511 * Swap it with mtk HCD.
513 mtk->hcd = platform_get_drvdata(pdev);
514 platform_set_drvdata(pdev, mtk);
527 mtk->ippc_regs = devm_ioremap_resource(dev, res);
528 if (IS_ERR(mtk->ippc_regs)) {
529 ret = PTR_ERR(mtk->ippc_regs);
532 mtk->has_ippc = true;
534 mtk->has_ippc = false;
576 xhci_mtk_sch_exit(mtk);
586 xhci_mtk_clks_disable(mtk);
589 xhci_mtk_ldos_disable(mtk);
599 struct xhci_hcd_mtk *mtk = platform_get_drvdata(dev);
600 struct usb_hcd *hcd = mtk->hcd;
614 xhci_mtk_sch_exit(mtk);
615 xhci_mtk_clks_disable(mtk);
616 xhci_mtk_ldos_disable(mtk);
630 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);
631 struct usb_hcd *hcd = mtk->hcd;
640 xhci_mtk_host_disable(mtk);
641 xhci_mtk_clks_disable(mtk);
642 usb_wakeup_set(mtk, true);
648 struct xhci_hcd_mtk *mtk = dev_get_drvdata(dev);
649 struct usb_hcd *hcd = mtk->hcd;
652 usb_wakeup_set(mtk, false);
653 xhci_mtk_clks_enable(mtk);
654 xhci_mtk_host_enable(mtk);
672 { .compatible = "mediatek,mtk-xhci"},
682 .name = "xhci-mtk",
687 MODULE_ALIAS("platform:xhci-mtk");