linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daehwan Jung <dh10.jung@samsung.com>
To: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Mathias Nyman <mathias.nyman@intel.com>,
	Lukas Bulwahn <lukas.bulwahn@gmail.com>,
	Tony Lindgren <tony@atomide.com>, Juergen Gross <jgross@suse.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Matthias Kaehlcke <mka@chromium.org>
Cc: linux-kernel@vger.kernel.org (open list),
	linux-usb@vger.kernel.org (open list:DESIGNWARE USB3 DRD IP
	DRIVER),
	linux-arm-kernel@lists.infradead.org (moderated list:ARM/SAMSUNG
	S3C, S5P AND EXYNOS ARM ARCHITECTURES),
	linux-samsung-soc@vger.kernel.org (open list:ARM/SAMSUNG S3C,
	S5P AND EXYNOS ARM ARCHITECTURES),
	sc.suh@samsung.com, taehyun.cho@samsung.com,
	jh0801.jung@samsung.com, eomji.oh@samsung.com,
	Daehwan Jung <dh10.jung@samsung.com>
Subject: [PATCH RFC v5 6/6] usb: dwc3: dwc3-exynos: add host init
Date: Fri,  6 May 2022 15:31:19 +0900	[thread overview]
Message-ID: <1651818679-10594-7-git-send-email-dh10.jung@samsung.com> (raw)
In-Reply-To: <1651818679-10594-1-git-send-email-dh10.jung@samsung.com>

This is for xHCI Host Controller driver on Exynos SOC.
It registers vendor ops before loading xhci platform driver.

Signed-off-by: Daehwan Jung <dh10.jung@samsung.com>
---
 drivers/usb/dwc3/dwc3-exynos.c | 100 ++++++++++++++++++++++++++++++++-
 1 file changed, 99 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index 0ecf20eeceee..c22ea5cd6ab0 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -17,6 +17,12 @@
 #include <linux/of_platform.h>
 #include <linux/regulator/consumer.h>
 
+#include "core.h"
+
+#if IS_ENABLED(CONFIG_USB_XHCI_EXYNOS)
+int xhci_exynos_register_vendor_ops(void);
+#endif
+
 #define DWC3_EXYNOS_MAX_CLOCKS	4
 
 struct dwc3_exynos_driverdata {
@@ -27,6 +33,7 @@ struct dwc3_exynos_driverdata {
 
 struct dwc3_exynos {
 	struct device		*dev;
+	struct dwc3		*dwc;
 
 	const char		**clk_names;
 	struct clk		*clks[DWC3_EXYNOS_MAX_CLOCKS];
@@ -46,12 +53,81 @@ static int dwc3_exynos_remove_child(struct device *dev, void *unused)
 	return 0;
 }
 
+#if IS_ENABLED(CONFIG_USB_XHCI_EXYNOS)
+static int dwc3_exynos_host_init(struct dwc3_exynos *exynos)
+{
+	struct dwc3		*dwc = exynos->dwc;
+	struct device		*dev = exynos->dev;
+	struct platform_device	*xhci;
+	struct resource		*res;
+	struct platform_device	*dwc3_pdev = to_platform_device(dwc->dev);
+	int			ret = 0;
+
+	/* Configuration xhci resources */
+	xhci_exynos_register_vendor_ops();
+
+	res = platform_get_resource(dwc3_pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "missing memory resource\n");
+		return -ENODEV;
+	}
+	dwc->xhci_resources[0].start = res->start;
+	dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
+					DWC3_XHCI_REGS_END;
+	dwc->xhci_resources[0].flags = res->flags;
+	dwc->xhci_resources[0].name = res->name;
+
+	res = platform_get_resource(dwc3_pdev, IORESOURCE_IRQ, 0);
+	if (!res) {
+		dev_err(dev, "missing irq resource\n");
+		return -ENODEV;
+	}
+
+	dwc->xhci_resources[1].start = dwc->irq_gadget;
+	dwc->xhci_resources[1].end = dwc->irq_gadget;
+	dwc->xhci_resources[1].flags = res->flags;
+	dwc->xhci_resources[1].name = res->name;
+
+	xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
+	if (!xhci) {
+		dev_err(dwc->dev, "couldn't allocate xHCI device\n");
+		return -ENOMEM;
+	}
+
+	xhci->dev.parent	= dwc->dev;
+	ret = dma_set_mask_and_coherent(&xhci->dev, DMA_BIT_MASK(36));
+	if (ret) {
+		pr_err("xhci dma set mask ret = %d\n", ret);
+		return ret;
+	}
+
+	ret = platform_device_add_resources(xhci, dwc->xhci_resources,
+						DWC3_XHCI_RESOURCES_NUM);
+	if (ret) {
+		dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
+		goto err;
+	}
+
+	ret = platform_device_add(xhci);
+	if (ret) {
+		dev_err(dwc->dev, "couldn't add xHCI device\n");
+		goto err;
+	}
+
+	return 0;
+err:
+	platform_device_put(xhci);
+	return ret;
+}
+#endif
+
 static int dwc3_exynos_probe(struct platform_device *pdev)
 {
 	struct dwc3_exynos	*exynos;
 	struct device		*dev = &pdev->dev;
-	struct device_node	*node = dev->of_node;
+	struct device_node	*node = dev->of_node, *dwc3_np;
 	const struct dwc3_exynos_driverdata *driver_data;
+	struct platform_device *dwc3_pdev;
 	int			i, ret;
 
 	exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
@@ -109,6 +185,12 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 		goto vdd10_err;
 	}
 
+	dwc3_np = of_get_compatible_child(node, "snps,dwc3");
+	if (!dwc3_np) {
+		dev_err(dev, "failed to find dwc3 core child!\n");
+		goto vdd33_err;
+	}
+
 	if (node) {
 		ret = of_platform_populate(node, NULL, NULL, dev);
 		if (ret) {
@@ -121,6 +203,22 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 		goto populate_err;
 	}
 
+	dwc3_pdev = of_find_device_by_node(dwc3_np);
+	exynos->dwc = platform_get_drvdata(dwc3_pdev);
+	if (!exynos->dwc) {
+		ret = -EPROBE_DEFER;
+		dev_err(dev, "failed to get dwc3 core node!\n");
+		goto populate_err;
+	}
+
+#if IS_ENABLED(CONFIG_USB_XHCI_EXYNOS)
+	/* USB host initialization. */
+	ret = dwc3_exynos_host_init(exynos);
+	if (ret) {
+		dev_err(dev, "USB host pre-initialization fail!\n");
+		goto populate_err;
+	}
+#endif
 	return 0;
 
 populate_err:
-- 
2.31.1


  parent reply	other threads:[~2022-05-06  6:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20220506063316epcas2p197ed75070ed4f4ba29439f5c0def90b4@epcas2p1.samsung.com>
2022-05-06  6:31 ` [PATCH v5 0/6] Add xhci-exynos for Exynos SOC Daehwan Jung
     [not found]   ` <CGME20220506063336epcas2p3da4c57aaa5a74460a742985f8a9d4ce1@epcas2p3.samsung.com>
2022-05-06  6:31     ` [PATCH v5 1/6] usb: host: export symbols for xhci-exynos to use xhci hooks Daehwan Jung
     [not found]   ` <CGME20220506063338epcas2p3749d0e1a3fffde81a758f708861b62ec@epcas2p3.samsung.com>
2022-05-06  6:31     ` [PATCH v5 2/6] usb: host: add xhci hooks for xhci-exynos Daehwan Jung
     [not found]   ` <CGME20220506063338epcas2p37d0e07d937624e56cb2114d9f75fdd42@epcas2p3.samsung.com>
2022-05-06  6:31     ` [PATCH v5 3/6] usb: host: xhci-plat: support override of hc driver Daehwan Jung
     [not found]   ` <CGME20220506063339epcas2p1b94e823ab8b7974ac88fec9ea9c17109@epcas2p1.samsung.com>
2022-05-06  6:31     ` [PATCH v5 4/6] usb: host: add some to xhci overrides for xhci-exynos Daehwan Jung
     [not found]   ` <CGME20220506063339epcas2p41de479fb6b2d11012a45ac50ccc19a26@epcas2p4.samsung.com>
2022-05-06  6:31     ` [PATCH RFC v5 5/6] usb: host: add xhci-exynos driver Daehwan Jung
2022-05-06  6:58       ` Krzysztof Kozlowski
     [not found]   ` <CGME20220506063340epcas2p4c9d88670f9be952f3637e3a545a7d1da@epcas2p4.samsung.com>
2022-05-06  6:31     ` Daehwan Jung [this message]
2022-05-06  6:45       ` [PATCH RFC v5 6/6] usb: dwc3: dwc3-exynos: add host init Krzysztof Kozlowski
2022-05-09 11:30         ` Christoph Hellwig
2022-05-06  7:51       ` Arnd Bergmann

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=1651818679-10594-7-git-send-email-dh10.jung@samsung.com \
    --to=dh10.jung@samsung.com \
    --cc=alim.akhtar@samsung.com \
    --cc=arnd@arndb.de \
    --cc=balbi@kernel.org \
    --cc=eomji.oh@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jgross@suse.com \
    --cc=jh0801.jung@samsung.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=mathias.nyman@intel.com \
    --cc=mka@chromium.org \
    --cc=sc.suh@samsung.com \
    --cc=taehyun.cho@samsung.com \
    --cc=tony@atomide.com \
    /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;
as well as URLs for NNTP newsgroup(s).