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
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
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>
14 drivers/usb/host/xhci-mtk.c | 79 ++++++++++++++++++++++++++++++++++-----------
15 drivers/usb/host/xhci-mtk.h | 2 ++
16 2 files changed, 62 insertions(+), 19 deletions(-)
18 --- a/drivers/usb/host/xhci-mtk.c
19 +++ b/drivers/usb/host/xhci-mtk.c
20 @@ -221,6 +221,44 @@ static int xhci_mtk_ssusb_config(struct
21 return xhci_mtk_host_enable(mtk);
24 +/* ignore the error if the clock does not exist */
25 +static struct clk *optional_clk_get(struct device *dev, const char *id)
27 + struct clk *opt_clk;
29 + opt_clk = devm_clk_get(dev, id);
30 + /* ignore error number except EPROBE_DEFER */
31 + if (IS_ERR(opt_clk) && (PTR_ERR(opt_clk) != -EPROBE_DEFER))
37 +static int xhci_mtk_clks_get(struct xhci_hcd_mtk *mtk)
39 + struct device *dev = mtk->dev;
41 + mtk->sys_clk = devm_clk_get(dev, "sys_ck");
42 + if (IS_ERR(mtk->sys_clk)) {
43 + dev_err(dev, "fail to get sys_ck\n");
44 + return PTR_ERR(mtk->sys_clk);
47 + mtk->ref_clk = optional_clk_get(dev, "ref_ck");
48 + if (IS_ERR(mtk->ref_clk))
49 + return PTR_ERR(mtk->ref_clk);
51 + mtk->mcu_clk = optional_clk_get(dev, "mcu_ck");
52 + if (IS_ERR(mtk->mcu_clk))
53 + return PTR_ERR(mtk->mcu_clk);
55 + mtk->dma_clk = optional_clk_get(dev, "dma_ck");
56 + if (IS_ERR(mtk->dma_clk))
57 + return PTR_ERR(mtk->dma_clk);
62 static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
65 @@ -237,16 +275,34 @@ static int xhci_mtk_clks_enable(struct x
69 + ret = clk_prepare_enable(mtk->mcu_clk);
71 + dev_err(mtk->dev, "failed to enable mcu_clk\n");
75 + ret = clk_prepare_enable(mtk->dma_clk);
77 + dev_err(mtk->dev, "failed to enable dma_clk\n");
84 + clk_disable_unprepare(mtk->mcu_clk);
86 + clk_disable_unprepare(mtk->sys_clk);
88 clk_disable_unprepare(mtk->ref_clk);
94 static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)
96 + clk_disable_unprepare(mtk->dma_clk);
97 + clk_disable_unprepare(mtk->mcu_clk);
98 clk_disable_unprepare(mtk->sys_clk);
99 clk_disable_unprepare(mtk->ref_clk);
101 @@ -529,24 +585,9 @@ static int xhci_mtk_probe(struct platfor
102 return PTR_ERR(mtk->vusb33);
105 - mtk->sys_clk = devm_clk_get(dev, "sys_ck");
106 - if (IS_ERR(mtk->sys_clk)) {
107 - dev_err(dev, "fail to get sys_ck\n");
108 - return PTR_ERR(mtk->sys_clk);
112 - * reference clock is usually a "fixed-clock", make it optional
113 - * for backward compatibility and ignore the error if it does
116 - mtk->ref_clk = devm_clk_get(dev, "ref_ck");
117 - if (IS_ERR(mtk->ref_clk)) {
118 - if (PTR_ERR(mtk->ref_clk) == -EPROBE_DEFER)
119 - return -EPROBE_DEFER;
121 - mtk->ref_clk = NULL;
123 + ret = xhci_mtk_clks_get(mtk);
127 mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable");
128 /* optional property, ignore the error if it does not exist */
129 --- a/drivers/usb/host/xhci-mtk.h
130 +++ b/drivers/usb/host/xhci-mtk.h
131 @@ -126,6 +126,8 @@ struct xhci_hcd_mtk {
132 struct regulator *vbus;
133 struct clk *sys_clk; /* sys and mac clock */
135 + struct clk *mcu_clk;
136 + struct clk *dma_clk;
137 struct regmap *pericfg;