[PATCH 4/7] usb: dwc3: pci: Move platform creation from probe function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Refactor and move dwc3 platform creation from dwc3_pci_probe() to a
new function called dwc3_pci_add_platform_device(). This way, it can be
called later.

Signed-off-by: Thinh Nguyen <thinhn@xxxxxxxxxxxx>
---
 drivers/usb/dwc3/dwc3-pci.c | 89 ++++++++++++++++++++++++++++-----------------
 1 file changed, 56 insertions(+), 33 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index bab8c6c1da38..e2bc735bbcca 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -243,6 +243,60 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
 	return 0;
 }
 
+static int dwc3_pci_add_platform_device(struct dwc3_pci *dwc)
+{
+	struct resource		res[2];
+	int			ret;
+	struct pci_dev		*pci = dwc->pci;
+	struct device		*dev = &pci->dev;
+
+	dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
+	if (!dwc->dwc3)
+		return -ENOMEM;
+
+	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
+
+	res[0].start	= pci_resource_start(pci, 0);
+	res[0].end	= pci_resource_end(pci, 0);
+	res[0].name	= "dwc_usb3";
+	res[0].flags	= IORESOURCE_MEM;
+
+	res[1].start	= pci->irq;
+	res[1].name	= "dwc_usb3";
+	res[1].flags	= IORESOURCE_IRQ;
+
+	ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
+	if (ret) {
+		dev_err(dev, "couldn't add resources to dwc3 device\n");
+		goto err;
+	}
+
+	dwc->dwc3->dev.parent = dev;
+	ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev));
+
+	if (dwc->properties[0].name) {
+		ret = platform_device_add_properties(dwc->dwc3,
+						     dwc->properties);
+		if (ret) {
+			dev_err(dev, "couldn't add properties to device\n");
+			goto err;
+		}
+	}
+
+	ret = platform_device_add(dwc->dwc3);
+	if (ret) {
+		dev_err(dev, "failed to register dwc3 device\n");
+		goto err;
+	}
+
+	return 0;
+
+err:
+	platform_device_put(dwc->dwc3);
+	dwc->dwc3 = NULL;
+	return ret;
+}
+
 #ifdef CONFIG_PM
 static void dwc3_pci_resume_work(struct work_struct *work)
 {
@@ -263,7 +317,6 @@ static int dwc3_pci_probe(struct pci_dev *pci,
 		const struct pci_device_id *id)
 {
 	struct dwc3_pci		*dwc;
-	struct resource		res[2];
 	int			ret;
 	struct device		*dev = &pci->dev;
 
@@ -279,31 +332,8 @@ static int dwc3_pci_probe(struct pci_dev *pci,
 	if (!dwc)
 		return -ENOMEM;
 
-	dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
-	if (!dwc->dwc3)
-		return -ENOMEM;
-
-	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
-
-	res[0].start	= pci_resource_start(pci, 0);
-	res[0].end	= pci_resource_end(pci, 0);
-	res[0].name	= "dwc_usb3";
-	res[0].flags	= IORESOURCE_MEM;
-
-	res[1].start	= pci->irq;
-	res[1].name	= "dwc_usb3";
-	res[1].flags	= IORESOURCE_IRQ;
-
-	ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
-	if (ret) {
-		dev_err(dev, "couldn't add resources to dwc3 device\n");
-		goto err;
-	}
-
 	dwc->pci = pci;
-	dwc->dwc3->dev.parent = dev;
-	ACPI_COMPANION_SET(&dwc->dwc3->dev, ACPI_COMPANION(dev));
-
+	dwc->dwc3 = NULL;
 	dwc->property_array_size = PROPERTY_ARRAY_INITIAL_SIZE;
 	dwc->properties = kcalloc(dwc->property_array_size,
 				  sizeof(*dwc->properties), GFP_KERNEL);
@@ -319,16 +349,10 @@ static int dwc3_pci_probe(struct pci_dev *pci,
 	if (ret)
 		goto err;
 
-	ret = platform_device_add_properties(dwc->dwc3, dwc->properties);
+	ret = dwc3_pci_add_platform_device(dwc);
 	if (ret)
 		goto err;
 
-	ret = platform_device_add(dwc->dwc3);
-	if (ret) {
-		dev_err(dev, "failed to register dwc3 device\n");
-		goto err;
-	}
-
 	device_init_wakeup(dev, true);
 	pci_set_drvdata(pci, dwc);
 	pm_runtime_put(dev);
@@ -339,7 +363,6 @@ static int dwc3_pci_probe(struct pci_dev *pci,
 	return 0;
 err:
 	kfree(dwc->properties);
-	platform_device_put(dwc->dwc3);
 	return ret;
 }
 
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux