diff mbox series

[v2,17/21] phy: add USB PHY driver for MediaTek MT7620 SoC

Message ID 787247f6fbcacba94b9ac3322b75bf8e2d78a75a.1604047991.git.weijie.gao@mediatek.com
State Superseded
Delegated to: Tom Rini
Headers show
Series Add support for MediaTek MT7620 SoC | expand

Commit Message

Weijie Gao (高惟杰) Oct. 30, 2020, 9:35 a.m. UTC
This patch adds USB PHY driver for MediaTek MT7620 SoC

Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
---
v2 changes: none
---
 drivers/phy/Kconfig          |   7 +++
 drivers/phy/Makefile         |   1 +
 drivers/phy/mt7620-usb-phy.c | 113 +++++++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+)
 create mode 100644 drivers/phy/mt7620-usb-phy.c

Comments

Jagan Teki Nov. 2, 2020, 6:11 a.m. UTC | #1
On Fri, Oct 30, 2020 at 3:05 PM Weijie Gao <weijie.gao@mediatek.com> wrote:
>
> This patch adds USB PHY driver for MediaTek MT7620 SoC
>
> Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
> ---
> v2 changes: none
> ---
>  drivers/phy/Kconfig          |   7 +++
>  drivers/phy/Makefile         |   1 +
>  drivers/phy/mt7620-usb-phy.c | 113 +++++++++++++++++++++++++++++++++++
>  3 files changed, 121 insertions(+)
>  create mode 100644 drivers/phy/mt7620-usb-phy.c
>
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index d12a6b02ad..ab638f0e7d 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -218,6 +218,13 @@ config KEYSTONE_USB_PHY
>
>           This PHY is found on some Keystone (K2) devices supporting USB.
>
> +config MT7620_USB_PHY
> +       bool "MediaTek MT7620 USB PHY support"
> +       depends on PHY
> +       depends on SOC_MT7620
> +       help
> +          Support the intergated USB PHY in MediaTek MT7620 SoC
> +
>  config MT76X8_USB_PHY
>         bool "MediaTek MT76x8 (7628/88) USB PHY support"
>         depends on PHY
> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> index 45a7fe5b56..6b3761b8c8 100644
> --- a/drivers/phy/Makefile
> +++ b/drivers/phy/Makefile
> @@ -24,6 +24,7 @@ obj-$(CONFIG_MESON_G12A_USB_PHY) += meson-g12a-usb2.o meson-g12a-usb3-pcie.o
>  obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
>  obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
>  obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
> +obj-$(CONFIG_MT7620_USB_PHY) += mt7620-usb-phy.o
>  obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
>  obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o
>  obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
> diff --git a/drivers/phy/mt7620-usb-phy.c b/drivers/phy/mt7620-usb-phy.c
> new file mode 100644
> index 0000000000..59ac32f327
> --- /dev/null
> +++ b/drivers/phy/mt7620-usb-phy.c
> @@ -0,0 +1,113 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
> + *
> + * Author: Weijie Gao <weijie.gao@mediatek.com>
> + */
> +
> +#include <clk.h>
> +#include <dm.h>
> +#include <generic-phy.h>
> +#include <misc.h>
> +#include <reset.h>
> +#include <dm/device_compat.h>
> +#include <linux/delay.h>
> +#include <mach/mt7620-sysc.h>
> +
> +struct mt7620_usb_phy {
> +       struct udevice *dev;

Why this explicit dev required here? generic_phy_get_ calls will assign phy->dev
Weijie Gao (高惟杰) Nov. 9, 2020, 2:14 a.m. UTC | #2
On Mon, 2020-11-02 at 11:41 +0530, Jagan Teki wrote:
> On Fri, Oct 30, 2020 at 3:05 PM Weijie Gao <weijie.gao@mediatek.com> wrote:
> >
> > This patch adds USB PHY driver for MediaTek MT7620 SoC
> >
> > Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
> > ---
> > v2 changes: none
> > ---
> >  drivers/phy/Kconfig          |   7 +++
> >  drivers/phy/Makefile         |   1 +
> >  drivers/phy/mt7620-usb-phy.c | 113 +++++++++++++++++++++++++++++++++++
> >  3 files changed, 121 insertions(+)
> >  create mode 100644 drivers/phy/mt7620-usb-phy.c
> >
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index d12a6b02ad..ab638f0e7d 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -218,6 +218,13 @@ config KEYSTONE_USB_PHY
> >
> >           This PHY is found on some Keystone (K2) devices supporting USB.
> >
> > +config MT7620_USB_PHY
> > +       bool "MediaTek MT7620 USB PHY support"
> > +       depends on PHY
> > +       depends on SOC_MT7620
> > +       help
> > +          Support the intergated USB PHY in MediaTek MT7620 SoC
> > +
> >  config MT76X8_USB_PHY
> >         bool "MediaTek MT76x8 (7628/88) USB PHY support"
> >         depends on PHY
> > diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> > index 45a7fe5b56..6b3761b8c8 100644
> > --- a/drivers/phy/Makefile
> > +++ b/drivers/phy/Makefile
> > @@ -24,6 +24,7 @@ obj-$(CONFIG_MESON_G12A_USB_PHY) += meson-g12a-usb2.o meson-g12a-usb3-pcie.o
> >  obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
> >  obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
> >  obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
> > +obj-$(CONFIG_MT7620_USB_PHY) += mt7620-usb-phy.o
> >  obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
> >  obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o
> >  obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
> > diff --git a/drivers/phy/mt7620-usb-phy.c b/drivers/phy/mt7620-usb-phy.c
> > new file mode 100644
> > index 0000000000..59ac32f327
> > --- /dev/null
> > +++ b/drivers/phy/mt7620-usb-phy.c
> > @@ -0,0 +1,113 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
> > + *
> > + * Author: Weijie Gao <weijie.gao@mediatek.com>
> > + */
> > +
> > +#include <clk.h>
> > +#include <dm.h>
> > +#include <generic-phy.h>
> > +#include <misc.h>
> > +#include <reset.h>
> > +#include <dm/device_compat.h>
> > +#include <linux/delay.h>
> > +#include <mach/mt7620-sysc.h>
> > +
> > +struct mt7620_usb_phy {
> > +       struct udevice *dev;
> 
> Why this explicit dev required here? generic_phy_get_ calls will assign phy->dev

I didn't notice that. This will be modified in next series.
diff mbox series

Patch

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index d12a6b02ad..ab638f0e7d 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -218,6 +218,13 @@  config KEYSTONE_USB_PHY
 
 	  This PHY is found on some Keystone (K2) devices supporting USB.
 
+config MT7620_USB_PHY
+	bool "MediaTek MT7620 USB PHY support"
+	depends on PHY
+	depends on SOC_MT7620
+	help
+          Support the intergated USB PHY in MediaTek MT7620 SoC
+
 config MT76X8_USB_PHY
 	bool "MediaTek MT76x8 (7628/88) USB PHY support"
 	depends on PHY
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 45a7fe5b56..6b3761b8c8 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -24,6 +24,7 @@  obj-$(CONFIG_MESON_G12A_USB_PHY) += meson-g12a-usb2.o meson-g12a-usb3-pcie.o
 obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
 obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
 obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
+obj-$(CONFIG_MT7620_USB_PHY) += mt7620-usb-phy.o
 obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
 obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o
 obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
diff --git a/drivers/phy/mt7620-usb-phy.c b/drivers/phy/mt7620-usb-phy.c
new file mode 100644
index 0000000000..59ac32f327
--- /dev/null
+++ b/drivers/phy/mt7620-usb-phy.c
@@ -0,0 +1,113 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#include <clk.h>
+#include <dm.h>
+#include <generic-phy.h>
+#include <misc.h>
+#include <reset.h>
+#include <dm/device_compat.h>
+#include <linux/delay.h>
+#include <mach/mt7620-sysc.h>
+
+struct mt7620_usb_phy {
+	struct udevice *dev;
+	struct udevice *sysc;
+	struct clk_bulk clocks;
+	struct reset_ctl_bulk resets;
+};
+
+static int mt7620_usb_phy_power_on(struct phy *_phy)
+{
+	struct mt7620_usb_phy *phy = dev_get_priv(_phy->dev);
+	u32 mode = MT7620_SYSC_USB_HOST_MODE;
+	int ret;
+
+	reset_deassert_bulk(&phy->resets);
+
+	clk_enable_bulk(&phy->clocks);
+
+	mdelay(10);
+
+	ret = misc_ioctl(phy->sysc, MT7620_SYSC_IOCTL_SET_USB_MODE, &mode);
+	if (ret) {
+		dev_err(phy->dev,
+			"mt7620_usbphy: failed to set USB host mode\n");
+		return ret;
+	}
+
+	mdelay(10);
+
+	return 0;
+}
+
+static int mt7620_usb_phy_power_off(struct phy *_phy)
+{
+	struct mt7620_usb_phy *phy = dev_get_priv(_phy->dev);
+
+	clk_disable_bulk(&phy->clocks);
+
+	reset_assert_bulk(&phy->resets);
+
+	return 0;
+}
+
+static int mt7620_usb_phy_probe(struct udevice *dev)
+{
+	struct mt7620_usb_phy *phy = dev_get_priv(dev);
+	struct ofnode_phandle_args sysc_args;
+	int ret;
+
+	ret = ofnode_parse_phandle_with_args(dev->node, "mediatek,sysc", NULL,
+					     0, 0, &sysc_args);
+	if (ret) {
+		dev_err(dev, "mt7620_usbphy: sysc property not found\n");
+		return ret;
+	}
+
+	ret = uclass_get_device_by_ofnode(UCLASS_MISC, sysc_args.node,
+					  &phy->sysc);
+	if (ret) {
+		dev_err(dev, "mt7620_usbphy: failed to sysc device\n");
+		return ret;
+	}
+
+	ret = clk_get_bulk(dev, &phy->clocks);
+	if (ret) {
+		dev_err(dev, "mt7620_usbphy: failed to get clocks\n");
+		return ret;
+	}
+
+	ret = reset_get_bulk(dev, &phy->resets);
+	if (ret) {
+		dev_err(dev, "mt7620_usbphy: failed to get reset control\n");
+		return ret;
+	}
+
+	phy->dev = dev;
+
+	return 0;
+}
+
+static struct phy_ops mt7620_usb_phy_ops = {
+	.power_on = mt7620_usb_phy_power_on,
+	.power_off = mt7620_usb_phy_power_off,
+};
+
+static const struct udevice_id mt7620_usb_phy_ids[] = {
+	{ .compatible = "mediatek,mt7620-usbphy" },
+	{ }
+};
+
+U_BOOT_DRIVER(mt7620_usb_phy) = {
+	.name		= "mt7620_usb_phy",
+	.id		= UCLASS_PHY,
+	.of_match	= mt7620_usb_phy_ids,
+	.ops		= &mt7620_usb_phy_ops,
+	.probe		= mt7620_usb_phy_probe,
+	.priv_auto_alloc_size = sizeof(struct mt7620_usb_phy),
+};