linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon
@ 2019-01-07  8:25 Rafał Miłecki
  2019-01-07  8:25 ` [PATCH 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Rafał Miłecki @ 2019-01-07  8:25 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-kernel, Rob Herring, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

USB 2.0 PHY is a hardware block that happens to use two registers from
the CRU block to setup a single PLL. It's not part of the CRU or DMU
and so its binding shouldn't cover the whole DMU.

The correct way of handling this is to reference CRU block node using a
syscon. Document that & deprecate the old way.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 .../devicetree/bindings/phy/bcm-ns-usb2-phy.txt    | 27 ++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
index a7aee9ea8926..36b634d2f0ca 100644
--- a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
+++ b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
@@ -2,19 +2,38 @@ Driver for Broadcom Northstar USB 2.0 PHY
 
 Required properties:
 - compatible: brcm,ns-usb2-phy
-- reg: iomem address range of DMU (Device Management Unit)
-- reg-names: "dmu", the only needed & supported reg right now
+- syscon-cru: phandle to the CRU (Central Resource Unit) syscon
 - clocks: USB PHY reference clock
 - clock-names: "phy-ref-clk", the only needed & supported clock right now
 
+Deprecated:
+
+PHY block should not claim the whole DMU so such a binding has been deprecated.
+It only requires to access few CRU (a DMU subblock) registers and that should be
+handled with a syscon since CRU is a MFD (Multi-Function Device).
+
+- reg: iomem address range of DMU (Device Management Unit)
+- reg-names: "dmu", the only needed & supported reg right now
+
 To initialize USB 2.0 PHY driver needs to setup PLL correctly. To do this it
 requires passing phandle to the USB PHY reference clock.
 
 Example:
+	dmu@1800c000 {
+		compatible = "simple-bus";
+		ranges = <0 0x1800c000 0x1000>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		cru: cru@100 {
+			compatible = "syscon", "simple-mfd";
+			reg = <0x100 0x1a4>;
+		};
+	};
+
 	usb2-phy {
 		compatible = "brcm,ns-usb2-phy";
-		reg = <0x1800c000 0x1000>;
-		reg-names = "dmu";
+		syscon-cru = <&cru>;
 		#phy-cells = <0>;
 		clocks = <&genpll BCM_NSP_GENPLL_USB_PHY_REF_CLK>;
 		clock-names = "phy-ref-clk";
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] phy: bcm-ns-usb2: support updated DT binding with the CRU syscon
  2019-01-07  8:25 [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon Rafał Miłecki
@ 2019-01-07  8:25 ` Rafał Miłecki
  2019-01-07 18:47   ` Ray Jui
  2019-01-07 18:44 ` [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use " Ray Jui
  2019-01-08 12:39 ` [PATCH V2 " Rafał Miłecki
  2 siblings, 1 reply; 9+ messages in thread
From: Rafał Miłecki @ 2019-01-07  8:25 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-kernel, Rob Herring, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

This adds support for the "syscon-cru" DT property which simply requires
using regmap to access CRU registers.

The old binding has been deprecated and stays as a fallback method.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/phy/broadcom/phy-bcm-ns-usb2.c | 44 +++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/drivers/phy/broadcom/phy-bcm-ns-usb2.c b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
index 58dff80e9386..8dc6835b941c 100644
--- a/drivers/phy/broadcom/phy-bcm-ns-usb2.c
+++ b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
@@ -13,17 +13,23 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/err.h>
+#include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of_address.h>
 #include <linux/of_platform.h>
+#include <linux/regmap.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
+#define CRU_USB2_CONTROL			0x64
+#define CRU_CLKSET_KEY				0x80
+
 struct bcm_ns_usb2 {
 	struct device *dev;
 	struct clk *ref_clk;
 	struct phy *phy;
+	struct regmap *cru;
 	void __iomem *dmu;
 };
 
@@ -31,6 +37,7 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
 {
 	struct bcm_ns_usb2 *usb2 = phy_get_drvdata(phy);
 	struct device *dev = usb2->dev;
+	struct regmap *cru = usb2->cru;
 	void __iomem *dmu = usb2->dmu;
 	u32 ref_clk_rate, usb2ctl, usb_pll_ndiv, usb_pll_pdiv;
 	int err = 0;
@@ -48,7 +55,10 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
 		goto err_clk_off;
 	}
 
-	usb2ctl = readl(dmu + BCMA_DMU_CRU_USB2_CONTROL);
+	if (cru)
+		regmap_read(cru, CRU_USB2_CONTROL, &usb2ctl);
+	else
+		usb2ctl = readl(dmu + BCMA_DMU_CRU_USB2_CONTROL);
 
 	if (usb2ctl & BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_PDIV_MASK) {
 		usb_pll_pdiv = usb2ctl;
@@ -62,15 +72,24 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
 	usb_pll_ndiv = (1920000000 * usb_pll_pdiv) / ref_clk_rate;
 
 	/* Unlock DMU PLL settings with some magic value */
-	writel(0x0000ea68, dmu + BCMA_DMU_CRU_CLKSET_KEY);
+	if (cru)
+		regmap_write(cru, CRU_CLKSET_KEY, 0x0000ea68);
+	else
+		writel(0x0000ea68, dmu + BCMA_DMU_CRU_CLKSET_KEY);
 
 	/* Write USB 2.0 PLL control setting */
 	usb2ctl &= ~BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_MASK;
 	usb2ctl |= usb_pll_ndiv << BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_SHIFT;
-	writel(usb2ctl, dmu + BCMA_DMU_CRU_USB2_CONTROL);
+	if (cru)
+		regmap_write(cru, CRU_USB2_CONTROL, usb2ctl);
+	else
+		writel(usb2ctl, dmu + BCMA_DMU_CRU_USB2_CONTROL);
 
 	/* Lock DMU PLL settings */
-	writel(0x00000000, dmu + BCMA_DMU_CRU_CLKSET_KEY);
+	if (cru)
+		regmap_write(cru, CRU_CLKSET_KEY, 0x00000000);
+	else
+		writel(0x00000000, dmu + BCMA_DMU_CRU_CLKSET_KEY);
 
 err_clk_off:
 	clk_disable_unprepare(usb2->ref_clk);
@@ -86,6 +105,7 @@ static const struct phy_ops ops = {
 static int bcm_ns_usb2_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
+	struct device_node *cru_np;
 	struct bcm_ns_usb2 *usb2;
 	struct resource *res;
 	struct phy_provider *phy_provider;
@@ -95,11 +115,17 @@ static int bcm_ns_usb2_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	usb2->dev = dev;
 
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
-	usb2->dmu = devm_ioremap_resource(dev, res);
-	if (IS_ERR(usb2->dmu)) {
-		dev_err(dev, "Failed to map DMU regs\n");
-		return PTR_ERR(usb2->dmu);
+	cru_np = of_parse_phandle(dev->of_node, "syscon-cru", 0);
+	usb2->cru = syscon_node_to_regmap(cru_np);
+	if (IS_ERR(usb2->cru)) {
+		usb2->cru = NULL;
+
+		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
+		usb2->dmu = devm_ioremap_resource(dev, res);
+		if (IS_ERR(usb2->dmu)) {
+			dev_err(dev, "Failed to map DMU regs\n");
+			return PTR_ERR(usb2->dmu);
+		}
 	}
 
 	usb2->ref_clk = devm_clk_get(dev, "phy-ref-clk");
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon
  2019-01-07  8:25 [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon Rafał Miłecki
  2019-01-07  8:25 ` [PATCH 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
@ 2019-01-07 18:44 ` Ray Jui
  2019-01-08 12:39 ` [PATCH V2 " Rafał Miłecki
  2 siblings, 0 replies; 9+ messages in thread
From: Ray Jui @ 2019-01-07 18:44 UTC (permalink / raw)
  To: Rafał Miłecki, Kishon Vijay Abraham I
  Cc: linux-kernel, Rob Herring, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki



On 1/7/2019 12:25 AM, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> USB 2.0 PHY is a hardware block that happens to use two registers from
> the CRU block to setup a single PLL. It's not part of the CRU or DMU
> and so its binding shouldn't cover the whole DMU.
> 
> The correct way of handling this is to reference CRU block node using a
> syscon. Document that & deprecate the old way.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>  .../devicetree/bindings/phy/bcm-ns-usb2-phy.txt    | 27 ++++++++++++++++++----
>  1 file changed, 23 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> index a7aee9ea8926..36b634d2f0ca 100644
> --- a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> +++ b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> @@ -2,19 +2,38 @@ Driver for Broadcom Northstar USB 2.0 PHY
>  
>  Required properties:
>  - compatible: brcm,ns-usb2-phy
> -- reg: iomem address range of DMU (Device Management Unit)
> -- reg-names: "dmu", the only needed & supported reg right now
> +- syscon-cru: phandle to the CRU (Central Resource Unit) syscon
>  - clocks: USB PHY reference clock
>  - clock-names: "phy-ref-clk", the only needed & supported clock right now
>  
> +Deprecated:
> +
> +PHY block should not claim the whole DMU so such a binding has been deprecated.
> +It only requires to access few CRU (a DMU subblock) registers and that should be
> +handled with a syscon since CRU is a MFD (Multi-Function Device).
> +
> +- reg: iomem address range of DMU (Device Management Unit)
> +- reg-names: "dmu", the only needed & supported reg right now
> +
>  To initialize USB 2.0 PHY driver needs to setup PLL correctly. To do this it
>  requires passing phandle to the USB PHY reference clock.
>  
>  Example:
> +	dmu@1800c000 {
> +		compatible = "simple-bus";
> +		ranges = <0 0x1800c000 0x1000>;
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +
> +		cru: cru@100 {

cru: syscon@100 {

> +			compatible = "syscon", "simple-mfd";
> +			reg = <0x100 0x1a4>;
> +		};
> +	};
> +
>  	usb2-phy {
>  		compatible = "brcm,ns-usb2-phy";
> -		reg = <0x1800c000 0x1000>;
> -		reg-names = "dmu";
> +		syscon-cru = <&cru>;
>  		#phy-cells = <0>;
>  		clocks = <&genpll BCM_NSP_GENPLL_USB_PHY_REF_CLK>;
>  		clock-names = "phy-ref-clk";
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] phy: bcm-ns-usb2: support updated DT binding with the CRU syscon
  2019-01-07  8:25 ` [PATCH 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
@ 2019-01-07 18:47   ` Ray Jui
  0 siblings, 0 replies; 9+ messages in thread
From: Ray Jui @ 2019-01-07 18:47 UTC (permalink / raw)
  To: Rafał Miłecki, Kishon Vijay Abraham I
  Cc: linux-kernel, Rob Herring, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki



On 1/7/2019 12:25 AM, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> This adds support for the "syscon-cru" DT property which simply requires
> using regmap to access CRU registers.
> 
> The old binding has been deprecated and stays as a fallback method.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>  drivers/phy/broadcom/phy-bcm-ns-usb2.c | 44 +++++++++++++++++++++++++++-------
>  1 file changed, 35 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/phy/broadcom/phy-bcm-ns-usb2.c b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
> index 58dff80e9386..8dc6835b941c 100644
> --- a/drivers/phy/broadcom/phy-bcm-ns-usb2.c
> +++ b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
> @@ -13,17 +13,23 @@
>  #include <linux/clk.h>
>  #include <linux/delay.h>
>  #include <linux/err.h>
> +#include <linux/mfd/syscon.h>
>  #include <linux/module.h>
>  #include <linux/of_address.h>
>  #include <linux/of_platform.h>
> +#include <linux/regmap.h>

alphabetical order, so after platform_device.h

>  #include <linux/phy/phy.h>
>  #include <linux/platform_device.h>
>  #include <linux/slab.h>
>  
> +#define CRU_USB2_CONTROL			0x64
> +#define CRU_CLKSET_KEY				0x80
> +
>  struct bcm_ns_usb2 {
>  	struct device *dev;
>  	struct clk *ref_clk;
>  	struct phy *phy;
> +	struct regmap *cru;
>  	void __iomem *dmu;
>  };
>  
> @@ -31,6 +37,7 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
>  {
>  	struct bcm_ns_usb2 *usb2 = phy_get_drvdata(phy);
>  	struct device *dev = usb2->dev;
> +	struct regmap *cru = usb2->cru;
>  	void __iomem *dmu = usb2->dmu;
>  	u32 ref_clk_rate, usb2ctl, usb_pll_ndiv, usb_pll_pdiv;
>  	int err = 0;
> @@ -48,7 +55,10 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
>  		goto err_clk_off;
>  	}
>  
> -	usb2ctl = readl(dmu + BCMA_DMU_CRU_USB2_CONTROL);
> +	if (cru)
> +		regmap_read(cru, CRU_USB2_CONTROL, &usb2ctl);
> +	else
> +		usb2ctl = readl(dmu + BCMA_DMU_CRU_USB2_CONTROL);

Do you think it's cleaner to use a read/write wrapper to handle both the
syscon based case and the plain readl/writel? I thought that would make
the code much more readable.

>  
>  	if (usb2ctl & BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_PDIV_MASK) {
>  		usb_pll_pdiv = usb2ctl;
> @@ -62,15 +72,24 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
>  	usb_pll_ndiv = (1920000000 * usb_pll_pdiv) / ref_clk_rate;
>  
>  	/* Unlock DMU PLL settings with some magic value */
> -	writel(0x0000ea68, dmu + BCMA_DMU_CRU_CLKSET_KEY);
> +	if (cru)
> +		regmap_write(cru, CRU_CLKSET_KEY, 0x0000ea68);
> +	else
> +		writel(0x0000ea68, dmu + BCMA_DMU_CRU_CLKSET_KEY);
>  
>  	/* Write USB 2.0 PLL control setting */
>  	usb2ctl &= ~BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_MASK;
>  	usb2ctl |= usb_pll_ndiv << BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_SHIFT;
> -	writel(usb2ctl, dmu + BCMA_DMU_CRU_USB2_CONTROL);
> +	if (cru)
> +		regmap_write(cru, CRU_USB2_CONTROL, usb2ctl);
> +	else
> +		writel(usb2ctl, dmu + BCMA_DMU_CRU_USB2_CONTROL);
>  
>  	/* Lock DMU PLL settings */
> -	writel(0x00000000, dmu + BCMA_DMU_CRU_CLKSET_KEY);
> +	if (cru)
> +		regmap_write(cru, CRU_CLKSET_KEY, 0x00000000);
> +	else
> +		writel(0x00000000, dmu + BCMA_DMU_CRU_CLKSET_KEY);
>  
>  err_clk_off:
>  	clk_disable_unprepare(usb2->ref_clk);
> @@ -86,6 +105,7 @@ static const struct phy_ops ops = {
>  static int bcm_ns_usb2_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> +	struct device_node *cru_np;
>  	struct bcm_ns_usb2 *usb2;
>  	struct resource *res;
>  	struct phy_provider *phy_provider;
> @@ -95,11 +115,17 @@ static int bcm_ns_usb2_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  	usb2->dev = dev;
>  
> -	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
> -	usb2->dmu = devm_ioremap_resource(dev, res);
> -	if (IS_ERR(usb2->dmu)) {
> -		dev_err(dev, "Failed to map DMU regs\n");
> -		return PTR_ERR(usb2->dmu);
> +	cru_np = of_parse_phandle(dev->of_node, "syscon-cru", 0);
> +	usb2->cru = syscon_node_to_regmap(cru_np);

just use 'syscon_regmap_lookup_by_phandle'

> +	if (IS_ERR(usb2->cru)) {
> +		usb2->cru = NULL;
> +
> +		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
> +		usb2->dmu = devm_ioremap_resource(dev, res);
> +		if (IS_ERR(usb2->dmu)) {
> +			dev_err(dev, "Failed to map DMU regs\n");
> +			return PTR_ERR(usb2->dmu);
> +		}
>  	}
>  
>  	usb2->ref_clk = devm_clk_get(dev, "phy-ref-clk");
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V2 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon
  2019-01-07  8:25 [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon Rafał Miłecki
  2019-01-07  8:25 ` [PATCH 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
  2019-01-07 18:44 ` [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use " Ray Jui
@ 2019-01-08 12:39 ` Rafał Miłecki
  2019-01-08 12:39   ` [PATCH V2 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
                     ` (2 more replies)
  2 siblings, 3 replies; 9+ messages in thread
From: Rafał Miłecki @ 2019-01-08 12:39 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-kernel, Rob Herring, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

USB 2.0 PHY is a hardware block that happens to use two registers from
the CRU block to setup a single PLL. It's not part of the CRU or DMU
and so its binding shouldn't cover the whole DMU.

The correct way of handling this is to reference CRU block node using a
syscon. Document that & deprecate the old way.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: use syscon@ in example (thanks Ray)
---
 .../devicetree/bindings/phy/bcm-ns-usb2-phy.txt    | 27 ++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
index a7aee9ea8926..2cafee6b4a8b 100644
--- a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
+++ b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
@@ -2,19 +2,38 @@ Driver for Broadcom Northstar USB 2.0 PHY
 
 Required properties:
 - compatible: brcm,ns-usb2-phy
-- reg: iomem address range of DMU (Device Management Unit)
-- reg-names: "dmu", the only needed & supported reg right now
+- syscon-cru: phandle to the CRU (Central Resource Unit) syscon
 - clocks: USB PHY reference clock
 - clock-names: "phy-ref-clk", the only needed & supported clock right now
 
+Deprecated:
+
+PHY block should not claim the whole DMU so such a binding has been deprecated.
+It only requires to access few CRU (a DMU subblock) registers and that should be
+handled with a syscon since CRU is a MFD (Multi-Function Device).
+
+- reg: iomem address range of DMU (Device Management Unit)
+- reg-names: "dmu", the only needed & supported reg right now
+
 To initialize USB 2.0 PHY driver needs to setup PLL correctly. To do this it
 requires passing phandle to the USB PHY reference clock.
 
 Example:
+	dmu@1800c000 {
+		compatible = "simple-bus";
+		ranges = <0 0x1800c000 0x1000>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		cru: syscon@100 {
+			compatible = "syscon", "simple-mfd";
+			reg = <0x100 0x1a4>;
+		};
+	};
+
 	usb2-phy {
 		compatible = "brcm,ns-usb2-phy";
-		reg = <0x1800c000 0x1000>;
-		reg-names = "dmu";
+		syscon-cru = <&cru>;
 		#phy-cells = <0>;
 		clocks = <&genpll BCM_NSP_GENPLL_USB_PHY_REF_CLK>;
 		clock-names = "phy-ref-clk";
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH V2 2/2] phy: bcm-ns-usb2: support updated DT binding with the CRU syscon
  2019-01-08 12:39 ` [PATCH V2 " Rafał Miłecki
@ 2019-01-08 12:39   ` Rafał Miłecki
  2019-01-08 17:53     ` Ray Jui
  2019-01-08 17:51   ` [PATCH V2 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use " Ray Jui
  2019-01-15 20:53   ` Rob Herring
  2 siblings, 1 reply; 9+ messages in thread
From: Rafał Miłecki @ 2019-01-08 12:39 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: linux-kernel, Rob Herring, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki

From: Rafał Miłecki <rafal@milecki.pl>

This adds support for the "syscon-cru" DT property which simply requires
using regmap to access CRU registers.

The old binding has been deprecated and stays as a fallback method.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: Add bcm_ns_usb2_(read|write) & use syscon_regmap_lookup_by_phandle
---
 drivers/phy/broadcom/phy-bcm-ns-usb2.c | 50 +++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/drivers/phy/broadcom/phy-bcm-ns-usb2.c b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
index 58dff80e9386..b9d3ba6f9609 100644
--- a/drivers/phy/broadcom/phy-bcm-ns-usb2.c
+++ b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
@@ -13,25 +13,50 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/err.h>
+#include <linux/mfd/syscon.h>
 #include <linux/module.h>
 #include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 #include <linux/slab.h>
 
+#define CRU_USB2_CONTROL			0x64
+#define CRU_CLKSET_KEY				0x80
+
+#define DMU_CRU_OFFSET				0x100
+
 struct bcm_ns_usb2 {
 	struct device *dev;
 	struct clk *ref_clk;
 	struct phy *phy;
+	struct regmap *cru;
 	void __iomem *dmu;
 };
 
+static void bcm_ns_usb2_read(struct bcm_ns_usb2 *usb2, unsigned int reg,
+			     unsigned int *val)
+{
+	if (usb2->cru)
+		regmap_read(usb2->cru, reg, val);
+	else
+		*val = readl(usb2->dmu + DMU_CRU_OFFSET + reg);
+}
+
+static void bcm_ns_usb2_write(struct bcm_ns_usb2 *usb2, unsigned int reg,
+			      unsigned int val)
+{
+	if (usb2->cru)
+		regmap_write(usb2->cru, reg, val);
+	else
+		writel(val, usb2->dmu + DMU_CRU_OFFSET + reg);
+}
+
 static int bcm_ns_usb2_phy_init(struct phy *phy)
 {
 	struct bcm_ns_usb2 *usb2 = phy_get_drvdata(phy);
 	struct device *dev = usb2->dev;
-	void __iomem *dmu = usb2->dmu;
 	u32 ref_clk_rate, usb2ctl, usb_pll_ndiv, usb_pll_pdiv;
 	int err = 0;
 
@@ -48,7 +73,7 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
 		goto err_clk_off;
 	}
 
-	usb2ctl = readl(dmu + BCMA_DMU_CRU_USB2_CONTROL);
+	bcm_ns_usb2_read(usb2, CRU_USB2_CONTROL, &usb2ctl);
 
 	if (usb2ctl & BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_PDIV_MASK) {
 		usb_pll_pdiv = usb2ctl;
@@ -62,15 +87,15 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
 	usb_pll_ndiv = (1920000000 * usb_pll_pdiv) / ref_clk_rate;
 
 	/* Unlock DMU PLL settings with some magic value */
-	writel(0x0000ea68, dmu + BCMA_DMU_CRU_CLKSET_KEY);
+	bcm_ns_usb2_write(usb2, CRU_CLKSET_KEY, 0x0000ea68);
 
 	/* Write USB 2.0 PLL control setting */
 	usb2ctl &= ~BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_MASK;
 	usb2ctl |= usb_pll_ndiv << BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_SHIFT;
-	writel(usb2ctl, dmu + BCMA_DMU_CRU_USB2_CONTROL);
+	bcm_ns_usb2_write(usb2, CRU_USB2_CONTROL, usb2ctl);
 
 	/* Lock DMU PLL settings */
-	writel(0x00000000, dmu + BCMA_DMU_CRU_CLKSET_KEY);
+	bcm_ns_usb2_write(usb2, CRU_CLKSET_KEY, 0x00000000);
 
 err_clk_off:
 	clk_disable_unprepare(usb2->ref_clk);
@@ -95,11 +120,16 @@ static int bcm_ns_usb2_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	usb2->dev = dev;
 
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
-	usb2->dmu = devm_ioremap_resource(dev, res);
-	if (IS_ERR(usb2->dmu)) {
-		dev_err(dev, "Failed to map DMU regs\n");
-		return PTR_ERR(usb2->dmu);
+	usb2->cru = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon-cru");
+	if (IS_ERR(usb2->cru)) {
+		usb2->cru = NULL;
+
+		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
+		usb2->dmu = devm_ioremap_resource(dev, res);
+		if (IS_ERR(usb2->dmu)) {
+			dev_err(dev, "Failed to map DMU regs\n");
+			return PTR_ERR(usb2->dmu);
+		}
 	}
 
 	usb2->ref_clk = devm_clk_get(dev, "phy-ref-clk");
-- 
2.13.7


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH V2 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon
  2019-01-08 12:39 ` [PATCH V2 " Rafał Miłecki
  2019-01-08 12:39   ` [PATCH V2 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
@ 2019-01-08 17:51   ` Ray Jui
  2019-01-15 20:53   ` Rob Herring
  2 siblings, 0 replies; 9+ messages in thread
From: Ray Jui @ 2019-01-08 17:51 UTC (permalink / raw)
  To: Rafał Miłecki, Kishon Vijay Abraham I
  Cc: linux-kernel, Rob Herring, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki



On 1/8/2019 4:39 AM, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> USB 2.0 PHY is a hardware block that happens to use two registers from
> the CRU block to setup a single PLL. It's not part of the CRU or DMU
> and so its binding shouldn't cover the whole DMU.
> 
> The correct way of handling this is to reference CRU block node using a
> syscon. Document that & deprecate the old way.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> V2: use syscon@ in example (thanks Ray)
> ---
>  .../devicetree/bindings/phy/bcm-ns-usb2-phy.txt    | 27 ++++++++++++++++++----
>  1 file changed, 23 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> index a7aee9ea8926..2cafee6b4a8b 100644
> --- a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> +++ b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> @@ -2,19 +2,38 @@ Driver for Broadcom Northstar USB 2.0 PHY
>  
>  Required properties:
>  - compatible: brcm,ns-usb2-phy
> -- reg: iomem address range of DMU (Device Management Unit)
> -- reg-names: "dmu", the only needed & supported reg right now
> +- syscon-cru: phandle to the CRU (Central Resource Unit) syscon
>  - clocks: USB PHY reference clock
>  - clock-names: "phy-ref-clk", the only needed & supported clock right now
>  
> +Deprecated:
> +
> +PHY block should not claim the whole DMU so such a binding has been deprecated.
> +It only requires to access few CRU (a DMU subblock) registers and that should be
> +handled with a syscon since CRU is a MFD (Multi-Function Device).
> +
> +- reg: iomem address range of DMU (Device Management Unit)
> +- reg-names: "dmu", the only needed & supported reg right now
> +
>  To initialize USB 2.0 PHY driver needs to setup PLL correctly. To do this it
>  requires passing phandle to the USB PHY reference clock.
>  
>  Example:
> +	dmu@1800c000 {
> +		compatible = "simple-bus";
> +		ranges = <0 0x1800c000 0x1000>;
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +
> +		cru: syscon@100 {
> +			compatible = "syscon", "simple-mfd";
> +			reg = <0x100 0x1a4>;
> +		};
> +	};
> +
>  	usb2-phy {
>  		compatible = "brcm,ns-usb2-phy";
> -		reg = <0x1800c000 0x1000>;
> -		reg-names = "dmu";
> +		syscon-cru = <&cru>;
>  		#phy-cells = <0>;
>  		clocks = <&genpll BCM_NSP_GENPLL_USB_PHY_REF_CLK>;
>  		clock-names = "phy-ref-clk";
> 

Looks good to me!

Reviewed-by: Ray Jui <ray.jui@broadcom.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V2 2/2] phy: bcm-ns-usb2: support updated DT binding with the CRU syscon
  2019-01-08 12:39   ` [PATCH V2 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
@ 2019-01-08 17:53     ` Ray Jui
  0 siblings, 0 replies; 9+ messages in thread
From: Ray Jui @ 2019-01-08 17:53 UTC (permalink / raw)
  To: Rafał Miłecki, Kishon Vijay Abraham I
  Cc: linux-kernel, Rob Herring, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki



On 1/8/2019 4:39 AM, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> This adds support for the "syscon-cru" DT property which simply requires
> using regmap to access CRU registers.
> 
> The old binding has been deprecated and stays as a fallback method.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> V2: Add bcm_ns_usb2_(read|write) & use syscon_regmap_lookup_by_phandle
> ---
>  drivers/phy/broadcom/phy-bcm-ns-usb2.c | 50 +++++++++++++++++++++++++++-------
>  1 file changed, 40 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/phy/broadcom/phy-bcm-ns-usb2.c b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
> index 58dff80e9386..b9d3ba6f9609 100644
> --- a/drivers/phy/broadcom/phy-bcm-ns-usb2.c
> +++ b/drivers/phy/broadcom/phy-bcm-ns-usb2.c
> @@ -13,25 +13,50 @@
>  #include <linux/clk.h>
>  #include <linux/delay.h>
>  #include <linux/err.h>
> +#include <linux/mfd/syscon.h>
>  #include <linux/module.h>
>  #include <linux/of_address.h>
>  #include <linux/of_platform.h>
>  #include <linux/phy/phy.h>
>  #include <linux/platform_device.h>
> +#include <linux/regmap.h>
>  #include <linux/slab.h>
>  
> +#define CRU_USB2_CONTROL			0x64
> +#define CRU_CLKSET_KEY				0x80
> +
> +#define DMU_CRU_OFFSET				0x100
> +
>  struct bcm_ns_usb2 {
>  	struct device *dev;
>  	struct clk *ref_clk;
>  	struct phy *phy;
> +	struct regmap *cru;
>  	void __iomem *dmu;
>  };
>  
> +static void bcm_ns_usb2_read(struct bcm_ns_usb2 *usb2, unsigned int reg,
> +			     unsigned int *val)
> +{
> +	if (usb2->cru)
> +		regmap_read(usb2->cru, reg, val);
> +	else
> +		*val = readl(usb2->dmu + DMU_CRU_OFFSET + reg);
> +}
> +
> +static void bcm_ns_usb2_write(struct bcm_ns_usb2 *usb2, unsigned int reg,
> +			      unsigned int val)
> +{
> +	if (usb2->cru)
> +		regmap_write(usb2->cru, reg, val);
> +	else
> +		writel(val, usb2->dmu + DMU_CRU_OFFSET + reg);
> +}
> +
>  static int bcm_ns_usb2_phy_init(struct phy *phy)
>  {
>  	struct bcm_ns_usb2 *usb2 = phy_get_drvdata(phy);
>  	struct device *dev = usb2->dev;
> -	void __iomem *dmu = usb2->dmu;
>  	u32 ref_clk_rate, usb2ctl, usb_pll_ndiv, usb_pll_pdiv;
>  	int err = 0;
>  
> @@ -48,7 +73,7 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
>  		goto err_clk_off;
>  	}
>  
> -	usb2ctl = readl(dmu + BCMA_DMU_CRU_USB2_CONTROL);
> +	bcm_ns_usb2_read(usb2, CRU_USB2_CONTROL, &usb2ctl);
>  
>  	if (usb2ctl & BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_PDIV_MASK) {
>  		usb_pll_pdiv = usb2ctl;
> @@ -62,15 +87,15 @@ static int bcm_ns_usb2_phy_init(struct phy *phy)
>  	usb_pll_ndiv = (1920000000 * usb_pll_pdiv) / ref_clk_rate;
>  
>  	/* Unlock DMU PLL settings with some magic value */
> -	writel(0x0000ea68, dmu + BCMA_DMU_CRU_CLKSET_KEY);
> +	bcm_ns_usb2_write(usb2, CRU_CLKSET_KEY, 0x0000ea68);
>  
>  	/* Write USB 2.0 PLL control setting */
>  	usb2ctl &= ~BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_MASK;
>  	usb2ctl |= usb_pll_ndiv << BCMA_DMU_CRU_USB2_CONTROL_USB_PLL_NDIV_SHIFT;
> -	writel(usb2ctl, dmu + BCMA_DMU_CRU_USB2_CONTROL);
> +	bcm_ns_usb2_write(usb2, CRU_USB2_CONTROL, usb2ctl);
>  
>  	/* Lock DMU PLL settings */
> -	writel(0x00000000, dmu + BCMA_DMU_CRU_CLKSET_KEY);
> +	bcm_ns_usb2_write(usb2, CRU_CLKSET_KEY, 0x00000000);
>  
>  err_clk_off:
>  	clk_disable_unprepare(usb2->ref_clk);
> @@ -95,11 +120,16 @@ static int bcm_ns_usb2_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  	usb2->dev = dev;
>  
> -	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
> -	usb2->dmu = devm_ioremap_resource(dev, res);
> -	if (IS_ERR(usb2->dmu)) {
> -		dev_err(dev, "Failed to map DMU regs\n");
> -		return PTR_ERR(usb2->dmu);
> +	usb2->cru = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon-cru");
> +	if (IS_ERR(usb2->cru)) {
> +		usb2->cru = NULL;
> +
> +		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dmu");
> +		usb2->dmu = devm_ioremap_resource(dev, res);
> +		if (IS_ERR(usb2->dmu)) {
> +			dev_err(dev, "Failed to map DMU regs\n");
> +			return PTR_ERR(usb2->dmu);
> +		}
>  	}
>  
>  	usb2->ref_clk = devm_clk_get(dev, "phy-ref-clk");
> 

Looks good to me. Thanks!

Reviewed-by: Ray Jui <ray.jui@broadcom.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V2 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon
  2019-01-08 12:39 ` [PATCH V2 " Rafał Miłecki
  2019-01-08 12:39   ` [PATCH V2 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
  2019-01-08 17:51   ` [PATCH V2 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use " Ray Jui
@ 2019-01-15 20:53   ` Rob Herring
  2 siblings, 0 replies; 9+ messages in thread
From: Rob Herring @ 2019-01-15 20:53 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Kishon Vijay Abraham I, linux-kernel, Mark Rutland, devicetree,
	Hauke Mehrtens, bcm-kernel-feedback-list,
	Rafał Miłecki

On Tue, Jan 08, 2019 at 01:39:06PM +0100, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> USB 2.0 PHY is a hardware block that happens to use two registers from
> the CRU block to setup a single PLL. It's not part of the CRU or DMU
> and so its binding shouldn't cover the whole DMU.
> 
> The correct way of handling this is to reference CRU block node using a
> syscon. Document that & deprecate the old way.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> V2: use syscon@ in example (thanks Ray)
> ---
>  .../devicetree/bindings/phy/bcm-ns-usb2-phy.txt    | 27 ++++++++++++++++++----
>  1 file changed, 23 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> index a7aee9ea8926..2cafee6b4a8b 100644
> --- a/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> +++ b/Documentation/devicetree/bindings/phy/bcm-ns-usb2-phy.txt
> @@ -2,19 +2,38 @@ Driver for Broadcom Northstar USB 2.0 PHY
>  
>  Required properties:
>  - compatible: brcm,ns-usb2-phy
> -- reg: iomem address range of DMU (Device Management Unit)
> -- reg-names: "dmu", the only needed & supported reg right now
> +- syscon-cru: phandle to the CRU (Central Resource Unit) syscon
>  - clocks: USB PHY reference clock
>  - clock-names: "phy-ref-clk", the only needed & supported clock right now
>  
> +Deprecated:
> +
> +PHY block should not claim the whole DMU so such a binding has been deprecated.
> +It only requires to access few CRU (a DMU subblock) registers and that should be
> +handled with a syscon since CRU is a MFD (Multi-Function Device).
> +
> +- reg: iomem address range of DMU (Device Management Unit)
> +- reg-names: "dmu", the only needed & supported reg right now
> +
>  To initialize USB 2.0 PHY driver needs to setup PLL correctly. To do this it
>  requires passing phandle to the USB PHY reference clock.
>  
>  Example:
> +	dmu@1800c000 {
> +		compatible = "simple-bus";

DMU sounds like some sort of block, not just a bus.

> +		ranges = <0 0x1800c000 0x1000>;
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +
> +		cru: syscon@100 {
> +			compatible = "syscon", "simple-mfd";

Those 2 compatibles alone are not valid. And 'simple-mfd' implies child 
nodes.

Without any knowledge of what else is in the DMU, I can't give any 
advice as to what this should look like instead.

> +			reg = <0x100 0x1a4>;
> +		};
> +	};
> +
>  	usb2-phy {
>  		compatible = "brcm,ns-usb2-phy";
> -		reg = <0x1800c000 0x1000>;
> -		reg-names = "dmu";
> +		syscon-cru = <&cru>;

No need for this. Make it a child of cru node.

There's not a contiguous range of phy registers? If there are, keep 
'reg' even if Linux doesn't (currently) use it.

>  		#phy-cells = <0>;
>  		clocks = <&genpll BCM_NSP_GENPLL_USB_PHY_REF_CLK>;
>  		clock-names = "phy-ref-clk";
> -- 
> 2.13.7
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-01-15 20:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-07  8:25 [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use CRU syscon Rafał Miłecki
2019-01-07  8:25 ` [PATCH 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
2019-01-07 18:47   ` Ray Jui
2019-01-07 18:44 ` [PATCH 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use " Ray Jui
2019-01-08 12:39 ` [PATCH V2 " Rafał Miłecki
2019-01-08 12:39   ` [PATCH V2 2/2] phy: bcm-ns-usb2: support updated DT binding with the " Rafał Miłecki
2019-01-08 17:53     ` Ray Jui
2019-01-08 17:51   ` [PATCH V2 1/2] dt-bindings: bcm-ns-usb2-phy: rework binding to use " Ray Jui
2019-01-15 20:53   ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).