0131-usb-xhci-mtk-add-optional-mcu-and-dma-bus-clocks.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. From 9dce908d64ffb8b0ab71cb3a4b79db398d2e6dc3 Mon Sep 17 00:00:00 2001
  2. From: Chunfeng Yun <[email protected]>
  3. Date: Fri, 13 Oct 2017 16:26:38 +0800
  4. Subject: [PATCH 131/224] usb: xhci-mtk: add optional mcu and dma bus clocks
  5. There are mcu_bus and dma_bus clocks needed to be controlled by
  6. driver on some SoCs, so add them as optional ones
  7. Signed-off-by: Chunfeng Yun <[email protected]>
  8. Acked-by: Mathias Nyman <[email protected]>
  9. Reviewed-by: Matthias Brugger <[email protected]>
  10. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  11. ---
  12. drivers/usb/host/xhci-mtk.c | 79 ++++++++++++++++++++++++++++++++++-----------
  13. drivers/usb/host/xhci-mtk.h | 2 ++
  14. 2 files changed, 62 insertions(+), 19 deletions(-)
  15. diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
  16. index d60463c07c54..e5caabe7eebe 100644
  17. --- a/drivers/usb/host/xhci-mtk.c
  18. +++ b/drivers/usb/host/xhci-mtk.c
  19. @@ -221,6 +221,44 @@ static int xhci_mtk_ssusb_config(struct xhci_hcd_mtk *mtk)
  20. return xhci_mtk_host_enable(mtk);
  21. }
  22. +/* ignore the error if the clock does not exist */
  23. +static struct clk *optional_clk_get(struct device *dev, const char *id)
  24. +{
  25. + struct clk *opt_clk;
  26. +
  27. + opt_clk = devm_clk_get(dev, id);
  28. + /* ignore error number except EPROBE_DEFER */
  29. + if (IS_ERR(opt_clk) && (PTR_ERR(opt_clk) != -EPROBE_DEFER))
  30. + opt_clk = NULL;
  31. +
  32. + return opt_clk;
  33. +}
  34. +
  35. +static int xhci_mtk_clks_get(struct xhci_hcd_mtk *mtk)
  36. +{
  37. + struct device *dev = mtk->dev;
  38. +
  39. + mtk->sys_clk = devm_clk_get(dev, "sys_ck");
  40. + if (IS_ERR(mtk->sys_clk)) {
  41. + dev_err(dev, "fail to get sys_ck\n");
  42. + return PTR_ERR(mtk->sys_clk);
  43. + }
  44. +
  45. + mtk->ref_clk = optional_clk_get(dev, "ref_ck");
  46. + if (IS_ERR(mtk->ref_clk))
  47. + return PTR_ERR(mtk->ref_clk);
  48. +
  49. + mtk->mcu_clk = optional_clk_get(dev, "mcu_ck");
  50. + if (IS_ERR(mtk->mcu_clk))
  51. + return PTR_ERR(mtk->mcu_clk);
  52. +
  53. + mtk->dma_clk = optional_clk_get(dev, "dma_ck");
  54. + if (IS_ERR(mtk->dma_clk))
  55. + return PTR_ERR(mtk->dma_clk);
  56. +
  57. + return 0;
  58. +}
  59. +
  60. static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
  61. {
  62. int ret;
  63. @@ -237,16 +275,34 @@ static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
  64. goto sys_clk_err;
  65. }
  66. + ret = clk_prepare_enable(mtk->mcu_clk);
  67. + if (ret) {
  68. + dev_err(mtk->dev, "failed to enable mcu_clk\n");
  69. + goto mcu_clk_err;
  70. + }
  71. +
  72. + ret = clk_prepare_enable(mtk->dma_clk);
  73. + if (ret) {
  74. + dev_err(mtk->dev, "failed to enable dma_clk\n");
  75. + goto dma_clk_err;
  76. + }
  77. +
  78. return 0;
  79. +dma_clk_err:
  80. + clk_disable_unprepare(mtk->mcu_clk);
  81. +mcu_clk_err:
  82. + clk_disable_unprepare(mtk->sys_clk);
  83. sys_clk_err:
  84. clk_disable_unprepare(mtk->ref_clk);
  85. ref_clk_err:
  86. - return -EINVAL;
  87. + return ret;
  88. }
  89. static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)
  90. {
  91. + clk_disable_unprepare(mtk->dma_clk);
  92. + clk_disable_unprepare(mtk->mcu_clk);
  93. clk_disable_unprepare(mtk->sys_clk);
  94. clk_disable_unprepare(mtk->ref_clk);
  95. }
  96. @@ -529,24 +585,9 @@ static int xhci_mtk_probe(struct platform_device *pdev)
  97. return PTR_ERR(mtk->vusb33);
  98. }
  99. - mtk->sys_clk = devm_clk_get(dev, "sys_ck");
  100. - if (IS_ERR(mtk->sys_clk)) {
  101. - dev_err(dev, "fail to get sys_ck\n");
  102. - return PTR_ERR(mtk->sys_clk);
  103. - }
  104. -
  105. - /*
  106. - * reference clock is usually a "fixed-clock", make it optional
  107. - * for backward compatibility and ignore the error if it does
  108. - * not exist.
  109. - */
  110. - mtk->ref_clk = devm_clk_get(dev, "ref_ck");
  111. - if (IS_ERR(mtk->ref_clk)) {
  112. - if (PTR_ERR(mtk->ref_clk) == -EPROBE_DEFER)
  113. - return -EPROBE_DEFER;
  114. -
  115. - mtk->ref_clk = NULL;
  116. - }
  117. + ret = xhci_mtk_clks_get(mtk);
  118. + if (ret)
  119. + return ret;
  120. mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable");
  121. /* optional property, ignore the error if it does not exist */
  122. diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
  123. index 67783a7af509..45ff5c67efb5 100644
  124. --- a/drivers/usb/host/xhci-mtk.h
  125. +++ b/drivers/usb/host/xhci-mtk.h
  126. @@ -126,6 +126,8 @@ struct xhci_hcd_mtk {
  127. struct regulator *vbus;
  128. struct clk *sys_clk; /* sys and mac clock */
  129. struct clk *ref_clk;
  130. + struct clk *mcu_clk;
  131. + struct clk *dma_clk;
  132. struct regmap *pericfg;
  133. struct phy **phys;
  134. int num_phys;
  135. --
  136. 2.11.0