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