From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 8/9] usb: imx-us-phy: Convert driver to generic phy support
Date: Thu, 29 Sep 2016 14:38:59 +0200 [thread overview]
Message-ID: <20160929123900.24853-8-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20160929123900.24853-1-s.hauer@pengutronix.de>
The generic phy layer now supports USB phys, so convert
the driver over to use it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/configs/imx_defconfig | 2 ++
arch/arm/configs/imx_v7_defconfig | 2 ++
drivers/usb/imx/Kconfig | 3 +--
drivers/usb/imx/chipidea-imx.c | 21 ++++++++++++++++++
drivers/usb/imx/imx-usb-phy.c | 46 +++++++++++++++++++++++++++++++++++++--
5 files changed, 70 insertions(+), 4 deletions(-)
diff --git a/arch/arm/configs/imx_defconfig b/arch/arm/configs/imx_defconfig
index 69ab021..7d061cd 100644
--- a/arch/arm/configs/imx_defconfig
+++ b/arch/arm/configs/imx_defconfig
@@ -107,6 +107,8 @@ CONFIG_EEPROM_AT24=y
CONFIG_WATCHDOG=y
CONFIG_WATCHDOG_IMX=y
CONFIG_IMX_WEIM=y
+CONFIG_GENERIC_PHY=y
+CONFIG_USB_NOP_XCEIV=y
CONFIG_FS_EXT4=y
CONFIG_FS_TFTP=y
CONFIG_FS_NFS=y
diff --git a/arch/arm/configs/imx_v7_defconfig b/arch/arm/configs/imx_v7_defconfig
index e3a8f47..ac649ac 100644
--- a/arch/arm/configs/imx_v7_defconfig
+++ b/arch/arm/configs/imx_v7_defconfig
@@ -177,6 +177,8 @@ CONFIG_MXS_APBH_DMA=y
CONFIG_GPIO_STMPE=y
CONFIG_REGULATOR=y
CONFIG_REGULATOR_FIXED=y
+CONFIG_GENERIC_PHY=y
+CONFIG_USB_NOP_XCEIV=y
CONFIG_FS_EXT4=y
CONFIG_FS_TFTP=y
CONFIG_FS_NFS=y
diff --git a/drivers/usb/imx/Kconfig b/drivers/usb/imx/Kconfig
index b1ce682..b0c6a41 100644
--- a/drivers/usb/imx/Kconfig
+++ b/drivers/usb/imx/Kconfig
@@ -16,5 +16,4 @@ config USB_IMX_CHIPIDEA
config USB_IMX_PHY
bool
- depends on ARCH_IMX
- default y if ARCH_IMX6
+ default y if ARCH_IMX6 && GENERIC_PHY
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index a6f5926..ed00ff4 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -26,6 +26,7 @@
#include <usb/ulpi.h>
#include <usb/fsl_usb2.h>
#include <linux/err.h>
+#include <linux/phy/phy.h>
#define MXC_EHCI_PORTSC_MASK ((0xf << 28) | (1 << 25))
@@ -40,6 +41,8 @@ struct imx_chipidea {
struct param_d *param_mode;
int role_registered;
struct regulator *vbus;
+ struct phy *phy;
+ struct usb_phy *usbphy;
};
static int imx_chipidea_port_init(void *drvdata)
@@ -260,6 +263,23 @@ static int imx_chipidea_probe(struct device_d *dev)
if (IS_ERR(ci->vbus))
ci->vbus = NULL;
+ if (of_property_read_bool(dev->device_node, "fsl,usbphy")) {
+ ci->phy = of_phy_get_by_phandle(dev, "fsl,usbphy", 0);
+ if (IS_ERR(ci->phy)) {
+ ret = PTR_ERR(ci->phy);
+ dev_err(dev, "Cannot get phy: %s\n", strerror(-ret));
+ return ret;
+ } else {
+ ci->usbphy = phy_to_usbphy(ci->phy);
+ if (IS_ERR(ci->usbphy))
+ return PTR_ERR(ci->usbphy);
+
+ ret = phy_init(ci->phy);
+ if (ret)
+ return ret;
+ }
+ }
+
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
return PTR_ERR(iores);
@@ -270,6 +290,7 @@ static int imx_chipidea_probe(struct device_d *dev)
ci->data.init = imx_chipidea_port_init;
ci->data.post_init = imx_chipidea_port_post_init;
ci->data.drvdata = ci;
+ ci->data.usbphy = ci->usbphy;
if ((ci->flags & MXC_EHCI_PORTSC_MASK) == MXC_EHCI_MODE_HSIC)
imx_chipidea_port_init(ci);
diff --git a/drivers/usb/imx/imx-usb-phy.c b/drivers/usb/imx/imx-usb-phy.c
index eec195d..2829ffc 100644
--- a/drivers/usb/imx/imx-usb-phy.c
+++ b/drivers/usb/imx/imx-usb-phy.c
@@ -19,6 +19,8 @@
#include <errno.h>
#include <driver.h>
#include <malloc.h>
+#include <usb/phy.h>
+#include <linux/phy/phy.h>
#include <linux/clk.h>
#include <linux/err.h>
@@ -33,12 +35,17 @@
#define USBPHY_CTRL_ENUTMILEVEL2 (1 << 14)
struct imx_usbphy {
+ struct usb_phy usb_phy;
+ struct phy *phy;
void __iomem *base;
struct clk *clk;
+ struct phy_provider *provider;
};
-static int imx_usbphy_enable(struct imx_usbphy *imxphy)
+static int imx_usbphy_phy_init(struct phy *phy)
{
+ struct imx_usbphy *imxphy = phy_get_drvdata(phy);
+
clk_enable(imxphy->clk);
/* reset usbphy */
@@ -60,6 +67,26 @@ static int imx_usbphy_enable(struct imx_usbphy *imxphy)
return 0;
}
+static struct phy *imx_usbphy_xlate(struct device_d *dev,
+ struct of_phandle_args *args)
+{
+ struct imx_usbphy *imxphy = dev->priv;
+
+ return imxphy->phy;
+}
+
+static struct usb_phy *imx_usbphy_to_usbphy(struct phy *phy)
+{
+ struct imx_usbphy *imxphy = phy_get_drvdata(phy);
+
+ return &imxphy->usb_phy;
+}
+
+static const struct phy_ops imx_phy_ops = {
+ .init = imx_usbphy_phy_init,
+ .to_usbphy = imx_usbphy_to_usbphy,
+};
+
static int imx_usbphy_probe(struct device_d *dev)
{
struct resource *iores;
@@ -82,7 +109,22 @@ static int imx_usbphy_probe(struct device_d *dev)
goto err_clk;
}
- imx_usbphy_enable(imxphy);
+ dev->priv = imxphy;
+
+ imxphy->usb_phy.dev = dev;
+ imxphy->phy = phy_create(dev, NULL, &imx_phy_ops, NULL);
+ if (IS_ERR(imxphy->phy)) {
+ ret = PTR_ERR(imxphy->phy);
+ goto err_clk;
+ }
+
+ phy_set_drvdata(imxphy->phy, imxphy);
+
+ imxphy->provider = of_phy_provider_register(dev, imx_usbphy_xlate);
+ if (IS_ERR(imxphy->provider)) {
+ ret = PTR_ERR(imxphy->provider);
+ goto err_clk;
+ }
dev_dbg(dev, "phy enabled\n");
--
2.9.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-09-29 12:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-29 12:38 [PATCH 1/9] usb: Use standard debug macro Sascha Hauer
2016-09-29 12:38 ` [PATCH 2/9] usb: Add usb phy to usb host Sascha Hauer
2016-09-29 12:38 ` [PATCH 3/9] usb: ehci: forward phy given in registration data to host Sascha Hauer
2016-09-29 12:38 ` [PATCH 4/9] usb: imx-usb-phy: Drop unnecessary read/modify/write Sascha Hauer
2016-09-29 12:38 ` [PATCH 5/9] phy: Introduce of_phy_get_by_phandle Sascha Hauer
2016-09-29 12:38 ` [PATCH 6/9] phy: Introduce to_usbphy conversion function Sascha Hauer
2016-09-29 12:38 ` [PATCH 7/9] phy: Add usb-nop-xceiv support Sascha Hauer
2016-09-29 12:38 ` Sascha Hauer [this message]
2016-09-29 12:39 ` [PATCH 9/9] usb: imx-us-phy: implement notify_(dis)concect Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160929123900.24853-8-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox