e4a0f314dc9ce80f1819521815a3679f21a98ccb
[openwrt/staging/ansuel.git] /
1 From d3bc6269e21fc474763708e79c7a118740befb94 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 26 Oct 2021 11:37:16 +0200
4 Subject: [PATCH] phy: bcm-ns-usb2: support updated DT binding with PHY reg
5 space
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Updated DT binding maps just a PHY's register space instead of the whole
11 DMU block. Accessing a common CRU reg is handled using syscon &
12 regmap.
13
14 The old binding has been deprecated and remains supported as a fallback
15 method.
16
17 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
18 Link: https://lore.kernel.org/r/20211026093716.5567-1-zajec5@gmail.com
19 Signed-off-by: Vinod Koul <vkoul@kernel.org>
20 ---
21 drivers/phy/broadcom/phy-bcm-ns-usb2.c | 52 +++++++++++++++++++++-----
22 1 file changed, 43 insertions(+), 9 deletions(-)
23
24 --- a/drivers/phy/broadcom/phy-bcm-ns-usb2.c
25 +++ b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
26 @@ -9,17 +9,23 @@
27 #include <linux/clk.h>
28 #include <linux/delay.h>
29 #include <linux/err.h>
30 +#include <linux/mfd/syscon.h>
31 #include <linux/module.h>
32 #include <linux/of_address.h>
33 #include <linux/of_platform.h>
34 #include <linux/phy/phy.h>
35 #include <linux/platform_device.h>
36 +#include <linux/regmap.h>
37 #include <linux/slab.h>
38
39 struct bcm_ns_usb2 {
40 struct device *dev;
41 struct clk *ref_clk;
42 struct phy *phy;
43 + struct regmap *clkset;
44 + void __iomem *base;
45 +
46 + /* Deprecated binding */
47 void __iomem *dmu;
48 };
49
50 @@ -27,7 +33,6 @@ static int bcm_ns_usb2_phy_init(struct p
51 {
52 struct bcm_ns_usb2 *usb2 = phy_get_drvdata(phy);
53 struct device *dev = usb2->dev;
54 - void __iomem *dmu = usb2->dmu;
55 u32 ref_clk_rate, usb2ctl, usb_pll_ndiv, usb_pll_pdiv;
56 int err = 0;
57
58 @@ -44,7 +49,10 @@ static int bcm_ns_usb2_phy_init(struct p
59 goto err_clk_off;
60 }
61
62 - usb2ctl = readl(dmu + BCMA_DMU_CRU_USB2_CONTROL);
63 + if (usb2->base)
64 + usb2ctl = readl(usb2->base);
65 + else
66 + usb2ctl = readl(usb2->dmu + BCMA_DMU_CRU_USB2_CONTROL);
67
68 if (usb2ctl & BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_PDIV_MASK) {
69 usb_pll_pdiv = usb2ctl;
70 @@ -58,15 +66,24 @@ static int bcm_ns_usb2_phy_init(struct p
71 usb_pll_ndiv = (1920000000 * usb_pll_pdiv) / ref_clk_rate;
72
73 /* Unlock DMU PLL settings with some magic value */
74 - writel(0x0000ea68, dmu + BCMA_DMU_CRU_CLKSET_KEY);
75 + if (usb2->clkset)
76 + regmap_write(usb2->clkset, 0, 0x0000ea68);
77 + else
78 + writel(0x0000ea68, usb2->dmu + BCMA_DMU_CRU_CLKSET_KEY);
79
80 /* Write USB 2.0 PLL control setting */
81 usb2ctl &= ~BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_MASK;
82 usb2ctl |= usb_pll_ndiv << BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_SHIFT;
83 - writel(usb2ctl, dmu + BCMA_DMU_CRU_USB2_CONTROL);
84 + if (usb2->base)
85 + writel(usb2ctl, usb2->base);
86 + else
87 + writel(usb2ctl, usb2->dmu + BCMA_DMU_CRU_USB2_CONTROL);
88
89 /* Lock DMU PLL settings */
90 - writel(0x00000000, dmu + BCMA_DMU_CRU_CLKSET_KEY);
91 + if (usb2->clkset)
92 + regmap_write(usb2->clkset, 0, 0x00000000);
93 + else
94 + writel(0x00000000, usb2->dmu + BCMA_DMU_CRU_CLKSET_KEY);
95
96 err_clk_off:
97 clk_disable_unprepare(usb2->ref_clk);
98 @@ -90,10 +107,27 @@ static int bcm_ns_usb2_probe(struct plat
99 return -ENOMEM;
100 usb2->dev = dev;
101
102 - usb2->dmu = devm_platform_ioremap_resource_byname(pdev, "dmu");
103 - if (IS_ERR(usb2->dmu)) {
104 - dev_err(dev, "Failed to map DMU regs\n");
105 - return PTR_ERR(usb2->dmu);
106 + if (of_find_property(dev->of_node, "brcm,syscon-clkset", NULL)) {
107 + usb2->base = devm_platform_ioremap_resource(pdev, 0);
108 + if (IS_ERR(usb2->base)) {
109 + dev_err(dev, "Failed to map control reg\n");
110 + return PTR_ERR(usb2->base);
111 + }
112 +
113 + usb2->clkset = syscon_regmap_lookup_by_phandle(dev->of_node,
114 + "brcm,syscon-clkset");
115 + if (IS_ERR(usb2->clkset)) {
116 + dev_err(dev, "Failed to lookup clkset regmap\n");
117 + return PTR_ERR(usb2->clkset);
118 + }
119 + } else {
120 + usb2->dmu = devm_platform_ioremap_resource_byname(pdev, "dmu");
121 + if (IS_ERR(usb2->dmu)) {
122 + dev_err(dev, "Failed to map DMU regs\n");
123 + return PTR_ERR(usb2->dmu);
124 + }
125 +
126 + dev_warn(dev, "using deprecated DT binding\n");
127 }
128
129 usb2->ref_clk = devm_clk_get(dev, "phy-ref-clk");