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 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);
26 +/* ignore the error if the clock does not exist */
27 +static struct clk *optional_clk_get(struct device *dev, const char *id)
29 + struct clk *opt_clk;
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))
39 +static int xhci_mtk_clks_get(struct xhci_hcd_mtk *mtk)
41 + struct device *dev = mtk->dev;
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);
49 + mtk->ref_clk = optional_clk_get(dev, "ref_ck");
50 + if (IS_ERR(mtk->ref_clk))
51 + return PTR_ERR(mtk->ref_clk);
53 + mtk->mcu_clk = optional_clk_get(dev, "mcu_ck");
54 + if (IS_ERR(mtk->mcu_clk))
55 + return PTR_ERR(mtk->mcu_clk);
57 + mtk->dma_clk = optional_clk_get(dev, "dma_ck");
58 + if (IS_ERR(mtk->dma_clk))
59 + return PTR_ERR(mtk->dma_clk);
64 static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
67 @@ -237,16 +275,34 @@ static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
71 + ret = clk_prepare_enable(mtk->mcu_clk);
73 + dev_err(mtk->dev, "failed to enable mcu_clk\n");
77 + ret = clk_prepare_enable(mtk->dma_clk);
79 + dev_err(mtk->dev, "failed to enable dma_clk\n");
86 + clk_disable_unprepare(mtk->mcu_clk);
88 + clk_disable_unprepare(mtk->sys_clk);
90 clk_disable_unprepare(mtk->ref_clk);
96 static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)
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);
103 @@ -529,24 +585,9 @@ static int xhci_mtk_probe(struct platform_device *pdev)
104 return PTR_ERR(mtk->vusb33);
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);
114 - * reference clock is usually a "fixed-clock", make it optional
115 - * for backward compatibility and ignore the error if it does
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;
123 - mtk->ref_clk = NULL;
125 + ret = xhci_mtk_clks_get(mtk);
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 */
139 + struct clk *mcu_clk;
140 + struct clk *dma_clk;
141 struct regmap *pericfg;