464849bc690411f6f2ba6327c576bdfb09a57523
[openwrt/staging/blogic.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 @@ -91,11 +108,28 @@ static int bcm_ns_usb2_probe(struct plat
99 return -ENOMEM;
100 usb2->dev = dev;
101
102 - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
103 - usb2->dmu = devm_ioremap_resource(dev, res);
104 - if (IS_ERR(usb2->dmu)) {
105 - dev_err(dev, "Failed to map DMU regs\n");
106 - return PTR_ERR(usb2->dmu);
107 + if (of_find_property(dev->of_node, "brcm,syscon-clkset", NULL)) {
108 + usb2->base = devm_platform_ioremap_resource(pdev, 0);
109 + if (IS_ERR(usb2->base)) {
110 + dev_err(dev, "Failed to map control reg\n");
111 + return PTR_ERR(usb2->base);
112 + }
113 +
114 + usb2->clkset = syscon_regmap_lookup_by_phandle(dev->of_node,
115 + "brcm,syscon-clkset");
116 + if (IS_ERR(usb2->clkset)) {
117 + dev_err(dev, "Failed to lookup clkset regmap\n");
118 + return PTR_ERR(usb2->clkset);
119 + }
120 + } else {
121 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
122 + usb2->dmu = devm_ioremap_resource(dev, res);
123 + if (IS_ERR(usb2->dmu)) {
124 + dev_err(dev, "Failed to map DMU regs\n");
125 + return PTR_ERR(usb2->dmu);
126 + }
127 +
128 + dev_warn(dev, "using deprecated DT binding\n");
129 }
130
131 usb2->ref_clk = devm_clk_get(dev, "phy-ref-clk");