All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chunfeng Yun <chunfeng.yun@mediatek.com>
To: u-boot@lists.denx.de
Subject: [PATCH v6 06/14] usb: dwc2_udc_otg: use the phy bulk API to get phys
Date: Mon, 20 Apr 2020 11:21:15 +0800	[thread overview]
Message-ID: <1587352883-8641-7-git-send-email-chunfeng.yun@mediatek.com> (raw)
In-Reply-To: <1587352883-8641-1-git-send-email-chunfeng.yun@mediatek.com>

Use the phy bulk API to get a group of phys

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Reviewed-by: Weijie Gao <weijie.gao@mediatek.com>
---
v6: add Reviewed-by Weijie

v5: no changes

v4: new patch
---
 drivers/usb/gadget/dwc2_udc_otg.c | 90 +++++--------------------------
 1 file changed, 12 insertions(+), 78 deletions(-)

diff --git a/drivers/usb/gadget/dwc2_udc_otg.c b/drivers/usb/gadget/dwc2_udc_otg.c
index b9c814cf73..b7162a3443 100644
--- a/drivers/usb/gadget/dwc2_udc_otg.c
+++ b/drivers/usb/gadget/dwc2_udc_otg.c
@@ -943,8 +943,7 @@ int usb_gadget_handle_interrupts(int index)
 struct dwc2_priv_data {
 	struct clk_bulk		clks;
 	struct reset_ctl_bulk	resets;
-	struct phy *phys;
-	int num_phys;
+	struct phy_bulk phys;
 	struct udevice *usb33d_supply;
 };
 
@@ -953,87 +952,22 @@ int dm_usb_gadget_handle_interrupts(struct udevice *dev)
 	return dwc2_udc_handle_interrupt();
 }
 
-int dwc2_phy_setup(struct udevice *dev, struct phy **array, int *num_phys)
+static int dwc2_phy_setup(struct udevice *dev, struct phy_bulk *phys)
 {
-	int i, ret, count;
-	struct phy *usb_phys;
-
-	/* Return if no phy declared */
-	if (!dev_read_prop(dev, "phys", NULL))
-		return 0;
-
-	count = dev_count_phandle_with_args(dev, "phys", "#phy-cells");
-	if (count <= 0)
-		return count;
-
-	usb_phys = devm_kcalloc(dev, count, sizeof(struct phy),
-				GFP_KERNEL);
-	if (!usb_phys)
-		return -ENOMEM;
-
-	for (i = 0; i < count; i++) {
-		ret = generic_phy_get_by_index(dev, i, &usb_phys[i]);
-		if (ret && ret != -ENOENT) {
-			dev_err(dev, "Failed to get USB PHY%d for %s\n",
-				i, dev->name);
-			return ret;
-		}
-	}
-
-	for (i = 0; i < count; i++) {
-		ret = generic_phy_init(&usb_phys[i]);
-		if (ret) {
-			dev_err(dev, "Can't init USB PHY%d for %s\n",
-				i, dev->name);
-			goto phys_init_err;
-		}
-	}
+	int ret;
 
-	for (i = 0; i < count; i++) {
-		ret = generic_phy_power_on(&usb_phys[i]);
-		if (ret) {
-			dev_err(dev, "Can't power USB PHY%d for %s\n",
-				i, dev->name);
-			goto phys_poweron_err;
-		}
+	ret = generic_phy_get_bulk(dev, phys);
+	if (ret) {
+		dev_err(dev, "Failed to get phys\n");
+		return ret;
 	}
 
-	*array = usb_phys;
-	*num_phys =  count;
-
-	return 0;
-
-phys_poweron_err:
-	for (i = count - 1; i >= 0; i--)
-		generic_phy_power_off(&usb_phys[i]);
-
-	for (i = 0; i < count; i++)
-		generic_phy_exit(&usb_phys[i]);
-
-	return ret;
-
-phys_init_err:
-	for (; i >= 0; i--)
-		generic_phy_exit(&usb_phys[i]);
-
-	return ret;
+	return generic_phy_enable_bulk(phys);
 }
 
-void dwc2_phy_shutdown(struct udevice *dev, struct phy *usb_phys, int num_phys)
+static void dwc2_phy_shutdown(struct udevice *dev, struct phy_bulk *phys)
 {
-	int i, ret;
-
-	for (i = 0; i < num_phys; i++) {
-		if (!generic_phy_valid(&usb_phys[i]))
-			continue;
-
-		ret = generic_phy_power_off(&usb_phys[i]);
-		ret |= generic_phy_exit(&usb_phys[i]);
-		if (ret) {
-			dev_err(dev, "Can't shutdown USB PHY%d for %s\n",
-				i, dev->name);
-		}
-	}
+	generic_phy_disable_bulk(phys);
 }
 
 static int dwc2_udc_otg_ofdata_to_platdata(struct udevice *dev)
@@ -1158,7 +1092,7 @@ static int dwc2_udc_otg_probe(struct udevice *dev)
 	if (ret)
 		return ret;
 
-	ret = dwc2_phy_setup(dev, &priv->phys, &priv->num_phys);
+	ret = dwc2_phy_setup(dev, &priv->phys);
 	if (ret)
 		return ret;
 
@@ -1208,7 +1142,7 @@ static int dwc2_udc_otg_remove(struct udevice *dev)
 
 	clk_release_bulk(&priv->clks);
 
-	dwc2_phy_shutdown(dev, priv->phys, priv->num_phys);
+	dwc2_phy_shutdown(dev, &priv->phys);
 
 	return dm_scan_fdt_dev(dev);
 }
-- 
2.25.1

  parent reply	other threads:[~2020-04-20  3:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20  3:21 [PATCH v6 00/14] Add support for MediaTek xHCI host controller Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 01/14] dm: core: Add function to get child count of ofnode or device Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 02/14] test: dm: add test item for ofnode_get_child_count() Chunfeng Yun
2020-04-20 13:10   ` Simon Glass
2020-04-20 14:07   ` Fabio Estevam
2020-04-21  1:39     ` Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 03/14] phy: Add get/enable/disable for a bulk of phys Chunfeng Yun
2020-04-25 13:28   ` Jagan Teki
2020-04-27  2:16     ` Chunfeng Yun
2020-04-28 19:45       ` Jagan Teki
2020-04-29  1:41         ` Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 04/14] test: dm: phy: add a test item for the phy_bulk API Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 05/14] usb: dwc3: use the phy bulk API to get phys Chunfeng Yun
2020-04-20  3:21 ` Chunfeng Yun [this message]
2020-04-20  3:21 ` [PATCH v6 07/14] phy: phy-mtk-tphy: add support USB phys Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 08/14] phy: phy-mtk-tphy: add support new version Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 09/14] phy: phy-mtk-tphy: add a new reference clock Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 10/14] xhci: mediatek: Add support for MTK xHCI host controller Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 11/14] arm: dts: mt7629: add usb related nodes Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 12/14] dt-bindings: phy-mtk-tphy: add properties of address mapping and clocks Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 13/14] dt-bindings: usb: mtk-xhci: Add binding for MediaTek xHCI host controller Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 14/14] MAINTAINERS: MediaTek: add USB related files Chunfeng Yun

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=1587352883-8641-7-git-send-email-chunfeng.yun@mediatek.com \
    --to=chunfeng.yun@mediatek.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.