kernel: bump 4.14 to 4.14.125 (FS#2305 FS#2297)
[oweals/openwrt.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 --- 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);
22  }
23  
24 +/* ignore the error if the clock does not exist */
25 +static struct clk *optional_clk_get(struct device *dev, const char *id)
26 +{
27 +       struct clk *opt_clk;
28 +
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))
32 +               opt_clk = NULL;
33 +
34 +       return opt_clk;
35 +}
36 +
37 +static int xhci_mtk_clks_get(struct xhci_hcd_mtk *mtk)
38 +{
39 +       struct device *dev = mtk->dev;
40 +
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);
45 +       }
46 +
47 +       mtk->ref_clk = optional_clk_get(dev, "ref_ck");
48 +       if (IS_ERR(mtk->ref_clk))
49 +               return PTR_ERR(mtk->ref_clk);
50 +
51 +       mtk->mcu_clk = optional_clk_get(dev, "mcu_ck");
52 +       if (IS_ERR(mtk->mcu_clk))
53 +               return PTR_ERR(mtk->mcu_clk);
54 +
55 +       mtk->dma_clk = optional_clk_get(dev, "dma_ck");
56 +       if (IS_ERR(mtk->dma_clk))
57 +               return PTR_ERR(mtk->dma_clk);
58 +
59 +       return 0;
60 +}
61 +
62  static int xhci_mtk_clks_enable(struct xhci_hcd_mtk *mtk)
63  {
64         int ret;
65 @@ -237,16 +275,34 @@ static int xhci_mtk_clks_enable(struct x
66                 goto sys_clk_err;
67         }
68  
69 +       ret = clk_prepare_enable(mtk->mcu_clk);
70 +       if (ret) {
71 +               dev_err(mtk->dev, "failed to enable mcu_clk\n");
72 +               goto mcu_clk_err;
73 +       }
74 +
75 +       ret = clk_prepare_enable(mtk->dma_clk);
76 +       if (ret) {
77 +               dev_err(mtk->dev, "failed to enable dma_clk\n");
78 +               goto dma_clk_err;
79 +       }
80 +
81         return 0;
82  
83 +dma_clk_err:
84 +       clk_disable_unprepare(mtk->mcu_clk);
85 +mcu_clk_err:
86 +       clk_disable_unprepare(mtk->sys_clk);
87  sys_clk_err:
88         clk_disable_unprepare(mtk->ref_clk);
89  ref_clk_err:
90 -       return -EINVAL;
91 +       return ret;
92  }
93  
94  static void xhci_mtk_clks_disable(struct xhci_hcd_mtk *mtk)
95  {
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);
100  }
101 @@ -529,24 +585,9 @@ static int xhci_mtk_probe(struct platfor
102                 return PTR_ERR(mtk->vusb33);
103         }
104  
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);
109 -       }
110 -
111 -       /*
112 -        * reference clock is usually a "fixed-clock", make it optional
113 -        * for backward compatibility and ignore the error if it does
114 -        * not exist.
115 -        */
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;
120 -
121 -               mtk->ref_clk = NULL;
122 -       }
123 +       ret = xhci_mtk_clks_get(mtk);
124 +       if (ret)
125 +               return ret;
126  
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 */
134         struct clk *ref_clk;
135 +       struct clk *mcu_clk;
136 +       struct clk *dma_clk;
137         struct regmap *pericfg;
138         struct phy **phys;
139         int num_phys;