linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/3] phy: core: Add support for clock and reset to the phy core
@ 2017-02-05 19:52 Alban
  2017-02-05 19:52 ` [PATCH v4 2/3] phy: Add a driver for the ATH79 USB phy Alban
  2017-02-05 19:52 ` [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names Alban
  0 siblings, 2 replies; 6+ messages in thread
From: Alban @ 2017-02-05 19:52 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alban Bedel, Kishon Vijay Abraham I

From: Alban Bedel <albeu@free.fr>

Signed-off-by: Alban Bedel <albeu@free.fr>
---
 drivers/phy/phy-core.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy/phy.h |  4 ++++
 2 files changed, 52 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index a268f4d..e6c55af 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -22,6 +22,8 @@
 #include <linux/idr.h>
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
+#include <linux/reset.h>
+#include <linux/clk.h>
 
 static struct class *phy_class;
 static DEFINE_MUTEX(phy_provider_mutex);
@@ -286,6 +288,12 @@ int phy_power_on(struct phy *phy)
 			goto out;
 	}
 
+	if (phy->clk) {
+		ret = clk_prepare_enable(phy->clk);
+		if (ret)
+			goto err_clk_enable;
+	}
+
 	ret = phy_pm_runtime_get_sync(phy);
 	if (ret < 0 && ret != -ENOTSUPP)
 		goto err_pm_sync;
@@ -293,6 +301,11 @@ int phy_power_on(struct phy *phy)
 	ret = 0; /* Override possible ret == -ENOTSUPP */
 
 	mutex_lock(&phy->mutex);
+	if (phy->power_count == 0 && phy->reset) {
+		ret = reset_control_deassert(phy->reset);
+		if (ret)
+			goto err_reset_deassert;
+	}
 	if (phy->power_count == 0 && phy->ops->power_on) {
 		ret = phy->ops->power_on(phy);
 		if (ret < 0) {
@@ -305,9 +318,15 @@ int phy_power_on(struct phy *phy)
 	return 0;
 
 err_pwr_on:
+	if (phy->reset)
+		reset_control_assert(phy->reset);
+err_reset_deassert:
 	mutex_unlock(&phy->mutex);
 	phy_pm_runtime_put_sync(phy);
 err_pm_sync:
+	if (phy->clk)
+		clk_disable_unprepare(phy->clk);
+err_clk_enable:
 	if (phy->pwr)
 		regulator_disable(phy->pwr);
 out:
@@ -331,10 +350,18 @@ int phy_power_off(struct phy *phy)
 			return ret;
 		}
 	}
+	if (phy->power_count == 1 && phy->reset) {
+		ret = reset_control_assert(phy->reset);
+		if (ret < 0)
+			dev_warn(&phy->dev,
+				"phy reset assert failed --> %d\n", ret);
+	}
 	--phy->power_count;
 	mutex_unlock(&phy->mutex);
 	phy_pm_runtime_put(phy);
 
+	if (phy->clk)
+		clk_disable_unprepare(phy->clk);
 	if (phy->pwr)
 		regulator_disable(phy->pwr);
 
@@ -755,6 +782,24 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
 		phy->pwr = NULL;
 	}
 
+	phy->clk = clk_get(dev, "phy");
+	if (IS_ERR(phy->clk)) {
+		ret = PTR_ERR(phy->clk);
+		if (ret == -ENOENT)
+			phy->clk = NULL;
+		else
+			goto put_dev;
+	}
+
+	phy->reset = reset_control_get(dev, "phy");
+	if (IS_ERR(phy->reset)) {
+		ret = PTR_ERR(phy->reset);
+		if (ret == -ENOENT || ret == -ENOTSUPP)
+			phy->reset = NULL;
+		else
+			goto put_dev;
+	}
+
 	ret = device_add(&phy->dev);
 	if (ret)
 		goto put_dev;
@@ -991,6 +1036,9 @@ static void phy_release(struct device *dev)
 
 	phy = to_phy(dev);
 	dev_vdbg(dev, "releasing '%s'\n", dev_name(dev));
+	if (phy->reset)
+		reset_control_put(phy->reset);
+	clk_put(phy->clk);
 	regulator_put(phy->pwr);
 	ida_simple_remove(&phy_ida, phy->id);
 	kfree(phy);
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 78bb0d7..cc67d33 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -21,6 +21,8 @@
 #include <linux/regulator/consumer.h>
 
 struct phy;
+struct clk;
+struct reset_control;
 
 enum phy_mode {
 	PHY_MODE_INVALID,
@@ -77,6 +79,8 @@ struct phy {
 	int			power_count;
 	struct phy_attrs	attrs;
 	struct regulator	*pwr;
+	struct clk		*clk;
+	struct reset_control	*reset;
 };
 
 /**
-- 
2.7.4

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

* [PATCH v4 2/3] phy: Add a driver for the ATH79 USB phy
  2017-02-05 19:52 [PATCH v4 1/3] phy: core: Add support for clock and reset to the phy core Alban
@ 2017-02-05 19:52 ` Alban
  2017-02-05 19:52 ` [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names Alban
  1 sibling, 0 replies; 6+ messages in thread
From: Alban @ 2017-02-05 19:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: Alban Bedel, Kishon Vijay Abraham I, Greg Kroah-Hartman,
	David S. Miller, Geert Uytterhoeven, Andrew Morton,
	Mauro Carvalho Chehab, Guenter Roeck

From: Alban Bedel <albeu@free.fr>

The ATH79 USB phy is very simple, it only have a reset. On some SoC a
second reset is used to force the phy in suspend mode regardless of the
USB controller status.

Signed-off-by: Alban Bedel <albeu@free.fr>
---
Changelog:
v2: * Rebased on the simple PHY driver
    * Added myself as maintainer of the driver
v4: * Updated the copyright date
    * Use the new PHY core instead of the simple PHY driver
---
 MAINTAINERS                 |  8 ++++
 drivers/phy/Kconfig         |  8 ++++
 drivers/phy/Makefile        |  1 +
 drivers/phy/phy-ath79-usb.c | 92 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 109 insertions(+)
 create mode 100644 drivers/phy/phy-ath79-usb.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 187b961..9349472 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2105,6 +2105,14 @@ S:	Maintained
 F:	drivers/gpio/gpio-ath79.c
 F:	Documentation/devicetree/bindings/gpio/gpio-ath79.txt
 
+ATHEROS 71XX/9XXX USB PHY DRIVER
+M:	Alban Bedel <albeu@free.fr>
+W:	https://github.com/AlbanBedel/linux
+T:	git git://github.com/AlbanBedel/linux
+S:	Maintained
+F:	drivers/phy/phy-ath79-usb.c
+F:	Documentation/devicetree/bindings/phy/phy-ath79-usb.txt
+
 ATHEROS ATH GENERIC UTILITIES
 M:	"Luis R. Rodriguez" <mcgrof@do-not-panic.com>
 L:	linux-wireless@vger.kernel.org
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index e8eb7f2..129f5c7 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -15,6 +15,14 @@ config GENERIC_PHY
 	  phy users can obtain reference to the PHY. All the users of this
 	  framework should select this config.
 
+config PHY_ATH79_USB
+	tristate "Atheros AR71XX/9XXX USB PHY driver"
+	depends on ATH79 || COMPILE_TEST
+	default y if USB_EHCI_HCD_PLATFORM
+	select GENERIC_PHY
+	help
+	  Enable this to support the USB PHY on Atheros AR71XX/9XXX SoCs.
+
 config PHY_BCM_NS_USB2
 	tristate "Broadcom Northstar USB 2.0 PHY Driver"
 	depends on ARCH_BCM_IPROC || COMPILE_TEST
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 65eb2f4..23266779 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -3,6 +3,7 @@
 #
 
 obj-$(CONFIG_GENERIC_PHY)		+= phy-core.o
+obj-$(CONFIG_PHY_ATH79_USB)		+= phy-ath79-usb.o
 obj-$(CONFIG_PHY_BCM_NS_USB2)		+= phy-bcm-ns-usb2.o
 obj-$(CONFIG_PHY_BCM_NS_USB3)		+= phy-bcm-ns-usb3.o
 obj-$(CONFIG_PHY_BERLIN_USB)		+= phy-berlin-usb.o
diff --git a/drivers/phy/phy-ath79-usb.c b/drivers/phy/phy-ath79-usb.c
new file mode 100644
index 0000000..3f20d31
--- /dev/null
+++ b/drivers/phy/phy-ath79-usb.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2015-2017 Alban Bedel <albeu@free.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/phy/phy.h>
+#include <linux/reset.h>
+
+struct ath79_usb_phy {
+	struct reset_control *suspend_override;
+};
+
+static int ath79_usb_phy_power_on(struct phy *phy)
+{
+	struct ath79_usb_phy *priv = phy_get_drvdata(phy);
+	int err = 0;
+
+	if (priv->suspend_override)
+		err = reset_control_assert(priv->suspend_override);
+
+	return err;
+}
+
+static int ath79_usb_phy_power_off(struct phy *phy)
+{
+	struct ath79_usb_phy *priv = phy_get_drvdata(phy);
+	int err = 0;
+
+	if (priv->suspend_override)
+		err = reset_control_deassert(priv->suspend_override);
+
+	return err;
+}
+
+static const struct phy_ops ath79_usb_phy_ops = {
+	.power_on	= ath79_usb_phy_power_on,
+	.power_off	= ath79_usb_phy_power_off,
+	.owner		= THIS_MODULE,
+};
+
+static int ath79_usb_phy_probe(struct platform_device *pdev)
+{
+	struct ath79_usb_phy *priv;
+	struct phy *phy;
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->suspend_override = devm_reset_control_get_optional(
+		&pdev->dev, "suspend-override");
+	if (IS_ERR(priv->suspend_override)) {
+		if (PTR_ERR(priv->suspend_override) == -ENOENT)
+			priv->suspend_override = NULL;
+		else
+			return PTR_ERR(priv->suspend_override);
+	}
+
+	phy = devm_phy_create(&pdev->dev, NULL, &ath79_usb_phy_ops);
+	if (IS_ERR(phy))
+		return PTR_ERR(phy);
+
+	phy_set_drvdata(phy, priv);
+
+	return PTR_ERR_OR_ZERO(devm_of_phy_provider_register(
+				&pdev->dev, of_phy_simple_xlate));
+}
+
+static const struct of_device_id ath79_usb_phy_of_match[] = {
+	{ .compatible = "qca,ar7100-usb-phy" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, ath79_usb_phy_of_match);
+
+static struct platform_driver ath79_usb_phy_driver = {
+	.probe	= ath79_usb_phy_probe,
+	.driver = {
+		.of_match_table	= ath79_usb_phy_of_match,
+		.name		= "ath79-usb-phy",
+	}
+};
+module_platform_driver(ath79_usb_phy_driver);
+
+MODULE_DESCRIPTION("ATH79 USB PHY driver");
+MODULE_AUTHOR("Alban Bedel <albeu@free.fr>");
+MODULE_LICENSE("GPL");
-- 
2.7.4

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

* [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names
  2017-02-05 19:52 [PATCH v4 1/3] phy: core: Add support for clock and reset to the phy core Alban
  2017-02-05 19:52 ` [PATCH v4 2/3] phy: Add a driver for the ATH79 USB phy Alban
@ 2017-02-05 19:52 ` Alban
  2017-02-08 22:11   ` Rob Herring
  2017-02-11 22:01   ` James Hogan
  1 sibling, 2 replies; 6+ messages in thread
From: Alban @ 2017-02-05 19:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: Alban Bedel, Rob Herring, Mark Rutland, Ralf Baechle,
	Antony Pavlov, devicetree, linux-mips

From: Alban Bedel <albeu@free.fr>

The binding for the USB PHY went thru before the driver. However the
new version of the driver now use the PHY core support for reset, and
this expect the reset to be named "phy". So remove the "usb-" prefix
from the the reset names.

Signed-off-by: Alban Bedel <albeu@free.fr>
---
 Documentation/devicetree/bindings/phy/phy-ath79-usb.txt | 4 ++--
 arch/mips/boot/dts/qca/ar9132.dtsi                      | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/phy-ath79-usb.txt b/Documentation/devicetree/bindings/phy/phy-ath79-usb.txt
index cafe219..c3a29c5 100644
--- a/Documentation/devicetree/bindings/phy/phy-ath79-usb.txt
+++ b/Documentation/devicetree/bindings/phy/phy-ath79-usb.txt
@@ -3,7 +3,7 @@
 Required properties:
 - compatible: "qca,ar7100-usb-phy"
 - #phys-cells: should be 0
-- reset-names: "usb-phy"[, "usb-suspend-override"]
+- reset-names: "phy"[, "suspend-override"]
 - resets: references to the reset controllers
 
 Example:
@@ -11,7 +11,7 @@ Example:
 	usb-phy {
 		compatible = "qca,ar7100-usb-phy";
 
-		reset-names = "usb-phy", "usb-suspend-override";
+		reset-names = "phy", "suspend-override";
 		resets = <&rst 4>, <&rst 3>;
 
 		#phy-cells = <0>;
diff --git a/arch/mips/boot/dts/qca/ar9132.dtsi b/arch/mips/boot/dts/qca/ar9132.dtsi
index 302f0a8..808c2bb 100644
--- a/arch/mips/boot/dts/qca/ar9132.dtsi
+++ b/arch/mips/boot/dts/qca/ar9132.dtsi
@@ -160,7 +160,7 @@
 	usb_phy: usb-phy {
 		compatible = "qca,ar7100-usb-phy";
 
-		reset-names = "usb-phy", "usb-suspend-override";
+		reset-names = "phy", "suspend-override";
 		resets = <&rst 4>, <&rst 3>;
 
 		#phy-cells = <0>;
-- 
2.7.4

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

* Re: [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names
  2017-02-05 19:52 ` [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names Alban
@ 2017-02-08 22:11   ` Rob Herring
  2017-02-11 22:01   ` James Hogan
  1 sibling, 0 replies; 6+ messages in thread
From: Rob Herring @ 2017-02-08 22:11 UTC (permalink / raw)
  To: Alban
  Cc: linux-kernel, Mark Rutland, Ralf Baechle, Antony Pavlov,
	devicetree, linux-mips

On Sun, Feb 05, 2017 at 08:52:32PM +0100, Alban wrote:
> From: Alban Bedel <albeu@free.fr>
> 
> The binding for the USB PHY went thru before the driver. However the
> new version of the driver now use the PHY core support for reset, and
> this expect the reset to be named "phy". So remove the "usb-" prefix
> from the the reset names.
> 
> Signed-off-by: Alban Bedel <albeu@free.fr>
> ---
>  Documentation/devicetree/bindings/phy/phy-ath79-usb.txt | 4 ++--
>  arch/mips/boot/dts/qca/ar9132.dtsi                      | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names
  2017-02-05 19:52 ` [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names Alban
  2017-02-08 22:11   ` Rob Herring
@ 2017-02-11 22:01   ` James Hogan
  2017-02-13  8:30     ` Alban
  1 sibling, 1 reply; 6+ messages in thread
From: James Hogan @ 2017-02-11 22:01 UTC (permalink / raw)
  To: Alban
  Cc: linux-kernel, Rob Herring, Mark Rutland, Ralf Baechle,
	Antony Pavlov, devicetree, linux-mips

[-- Attachment #1: Type: text/plain, Size: 1044 bytes --]

Hi Alban,

On Sun, Feb 05, 2017 at 08:52:32PM +0100, Alban wrote:
> From: Alban Bedel <albeu@free.fr>
> 
> The binding for the USB PHY went thru before the driver. However the
> new version of the driver now use the PHY core support for reset, and
> this expect the reset to be named "phy". So remove the "usb-" prefix
> from the the reset names.
> 
> Signed-off-by: Alban Bedel <albeu@free.fr>
> ---
>  Documentation/devicetree/bindings/phy/phy-ath79-usb.txt | 4 ++--
>  arch/mips/boot/dts/qca/ar9132.dtsi                      | 2 +-

<snip>

> diff --git a/arch/mips/boot/dts/qca/ar9132.dtsi b/arch/mips/boot/dts/qca/ar9132.dtsi
> index 302f0a8..808c2bb 100644
> --- a/arch/mips/boot/dts/qca/ar9132.dtsi
> +++ b/arch/mips/boot/dts/qca/ar9132.dtsi
> @@ -160,7 +160,7 @@
>  	usb_phy: usb-phy {
>  		compatible = "qca,ar7100-usb-phy";
>  
> -		reset-names = "usb-phy", "usb-suspend-override";
> +		reset-names = "phy", "suspend-override";

Does arch/mips/boot/dts/qca/ar9331.dtsi need updating too?

Cheers
James

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names
  2017-02-11 22:01   ` James Hogan
@ 2017-02-13  8:30     ` Alban
  0 siblings, 0 replies; 6+ messages in thread
From: Alban @ 2017-02-13  8:30 UTC (permalink / raw)
  To: James Hogan
  Cc: Aban Bedel, linux-kernel, Rob Herring, Mark Rutland,
	Ralf Baechle, Antony Pavlov, devicetree, linux-mips

[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]

On Sat, 11 Feb 2017 22:01:29 +0000
James Hogan <james.hogan@imgtec.com> wrote:

> Hi Alban,
> 
> On Sun, Feb 05, 2017 at 08:52:32PM +0100, Alban wrote:
> > From: Alban Bedel <albeu@free.fr>
> > 
> > The binding for the USB PHY went thru before the driver. However the
> > new version of the driver now use the PHY core support for reset, and
> > this expect the reset to be named "phy". So remove the "usb-" prefix
> > from the the reset names.
> > 
> > Signed-off-by: Alban Bedel <albeu@free.fr>
> > ---
> >  Documentation/devicetree/bindings/phy/phy-ath79-usb.txt | 4 ++--
> >  arch/mips/boot/dts/qca/ar9132.dtsi                      | 2 +-  
> 
> <snip>
> 
> > diff --git a/arch/mips/boot/dts/qca/ar9132.dtsi b/arch/mips/boot/dts/qca/ar9132.dtsi
> > index 302f0a8..808c2bb 100644
> > --- a/arch/mips/boot/dts/qca/ar9132.dtsi
> > +++ b/arch/mips/boot/dts/qca/ar9132.dtsi
> > @@ -160,7 +160,7 @@
> >  	usb_phy: usb-phy {
> >  		compatible = "qca,ar7100-usb-phy";
> >  
> > -		reset-names = "usb-phy", "usb-suspend-override";
> > +		reset-names = "phy", "suspend-override";  
> 
> Does arch/mips/boot/dts/qca/ar9331.dtsi need updating too?

Right, I forgot the AR9331 had been added since then, I'll send a new
series.

Alban


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2017-02-13  8:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-05 19:52 [PATCH v4 1/3] phy: core: Add support for clock and reset to the phy core Alban
2017-02-05 19:52 ` [PATCH v4 2/3] phy: Add a driver for the ATH79 USB phy Alban
2017-02-05 19:52 ` [PATCH v4 3/3] MIPS: ath79: Fix the USB PHY reset names Alban
2017-02-08 22:11   ` Rob Herring
2017-02-11 22:01   ` James Hogan
2017-02-13  8:30     ` Alban

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).