devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Zhao <richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
To: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org
Cc: B29397-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	B20596-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	marex-ynQEQJNshbs@public.gmane.org,
	shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	alexander.shishkin-VuQAYsv1563Yd54FQh9/CA@public.gmane.org,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
	fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	dong.aisheng-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org,
	richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	balbi-l0cyMroinI0@public.gmane.org
Subject: [PATCH v6 07/14] USB: Chipidea: add unified ci13xxx_{add,remove}_device for platform drivers
Date: Thu, 21 Jun 2012 14:41:08 +0800	[thread overview]
Message-ID: <1340260875-21934-8-git-send-email-richard.zhao@freescale.com> (raw)
In-Reply-To: <1340260875-21934-1-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>

Platform drivers do the similar things to add/remove ci13xxx device, so
create a unified one.

Signed-off-by: Richard Zhao <richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Reviewed-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
Signed-off-by: Alexander Shishkin <alexander.shishkin-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/usb/chipidea/ci13xxx_msm.c |   34 ++++++----------------------
 drivers/usb/chipidea/ci13xxx_pci.c |   34 +++++-----------------------
 drivers/usb/chipidea/core.c        |   43 ++++++++++++++++++++++++++++++++++++
 include/linux/usb/chipidea.h       |    7 ++++++
 4 files changed, 63 insertions(+), 55 deletions(-)

diff --git a/drivers/usb/chipidea/ci13xxx_msm.c b/drivers/usb/chipidea/ci13xxx_msm.c
index a7dd9f1..92bfe36 100644
--- a/drivers/usb/chipidea/ci13xxx_msm.c
+++ b/drivers/usb/chipidea/ci13xxx_msm.c
@@ -58,50 +58,30 @@ static struct ci13xxx_platform_data ci13xxx_msm_platdata = {
 static int __devinit ci13xxx_msm_probe(struct platform_device *pdev)
 {
 	struct platform_device *plat_ci;
-	int ret;
 
 	dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
 
-	plat_ci = platform_device_alloc("ci_hdrc", -1);
-	if (!plat_ci) {
-		dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n");
-		return -ENOMEM;
+	plat_ci = ci13xxx_add_device(&pdev->dev,
+				pdev->resource, pdev->num_resources,
+				&ci13xxx_msm_platdata);
+	if (IS_ERR(plat_ci)) {
+		dev_err(&pdev->dev, "ci13xxx_add_device failed!\n");
+		return PTR_ERR(plat_ci);
 	}
 
-	ret = platform_device_add_resources(plat_ci, pdev->resource,
-					    pdev->num_resources);
-	if (ret) {
-		dev_err(&pdev->dev, "can't add resources to platform device\n");
-		goto put_platform;
-	}
-
-	ret = platform_device_add_data(plat_ci, &ci13xxx_msm_platdata,
-				       sizeof(ci13xxx_msm_platdata));
-	if (ret)
-		goto put_platform;
-
-	ret = platform_device_add(plat_ci);
-	if (ret)
-		goto put_platform;
-
 	platform_set_drvdata(pdev, plat_ci);
 
 	pm_runtime_no_callbacks(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
 
 	return 0;
-
-put_platform:
-	platform_device_put(plat_ci);
-
-	return ret;
 }
 
 static int __devexit ci13xxx_msm_remove(struct platform_device *pdev)
 {
 	struct platform_device *plat_ci = platform_get_drvdata(pdev);
 
-	platform_device_unregister(plat_ci);
+	ci13xxx_remove_device(plat_ci);
 
 	return 0;
 }
diff --git a/drivers/usb/chipidea/ci13xxx_pci.c b/drivers/usb/chipidea/ci13xxx_pci.c
index cdcac3a..918e149 100644
--- a/drivers/usb/chipidea/ci13xxx_pci.c
+++ b/drivers/usb/chipidea/ci13xxx_pci.c
@@ -75,13 +75,6 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
 	pci_set_master(pdev);
 	pci_try_set_mwi(pdev);
 
-	plat_ci = platform_device_alloc("ci_hdrc", -1);
-	if (!plat_ci) {
-		dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n");
-		retval = -ENOMEM;
-		goto disable_device;
-	}
-
 	memset(res, 0, sizeof(res));
 	res[0].start	= pci_resource_start(pdev, 0);
 	res[0].end	= pci_resource_end(pdev, 0);
@@ -89,32 +82,17 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
 	res[1].start	= pdev->irq;
 	res[1].flags	= IORESOURCE_IRQ;
 
-	retval = platform_device_add_resources(plat_ci, res, nres);
-	if (retval) {
-		dev_err(&pdev->dev, "can't add resources to platform device\n");
-		goto put_platform;
+	plat_ci = ci13xxx_add_device(&pdev->dev, res, nres, platdata);
+	if (IS_ERR(plat_ci)) {
+		dev_err(&pdev->dev, "ci13xxx_add_device failed!\n");
+		retval = PTR_ERR(plat_ci);
+		goto disable_device;
 	}
 
-	retval = platform_device_add_data(plat_ci, platdata, sizeof(*platdata));
-	if (retval)
-		goto put_platform;
-
-	dma_set_coherent_mask(&plat_ci->dev, pdev->dev.coherent_dma_mask);
-	plat_ci->dev.dma_mask = pdev->dev.dma_mask;
-	plat_ci->dev.dma_parms = pdev->dev.dma_parms;
-	plat_ci->dev.parent = &pdev->dev;
-
 	pci_set_drvdata(pdev, plat_ci);
 
-	retval = platform_device_add(plat_ci);
-	if (retval)
-		goto put_platform;
-
 	return 0;
 
- put_platform:
-	pci_set_drvdata(pdev, NULL);
-	platform_device_put(plat_ci);
  disable_device:
 	pci_disable_device(pdev);
  done:
@@ -133,7 +111,7 @@ static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
 {
 	struct platform_device *plat_ci = pci_get_drvdata(pdev);
 
-	platform_device_unregister(plat_ci);
+	ci13xxx_remove_device(plat_ci);
 	pci_set_drvdata(pdev, NULL);
 	pci_disable_device(pdev);
 }
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 9a883bd..8eccd1b 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -332,6 +332,49 @@ static irqreturn_t ci_irq(int irq, void *data)
 	return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci);
 }
 
+struct platform_device *ci13xxx_add_device(struct device *dev,
+			struct resource *res, int nres,
+			struct ci13xxx_platform_data *platdata)
+{
+	struct platform_device *pdev;
+	int ret;
+
+	/* FIXME: find a way to choose id */
+	pdev = platform_device_alloc("ci_hdrc", -1);
+	if (!pdev)
+		return ERR_PTR(-ENOMEM);
+
+	pdev->dev.parent = dev;
+	pdev->dev.dma_mask = dev->dma_mask;
+	pdev->dev.dma_parms = dev->dma_parms;
+	dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
+
+	ret = platform_device_add_resources(pdev, res, nres);
+	if (ret)
+		goto err;
+
+	ret = platform_device_add_data(pdev, platdata, sizeof(*platdata));
+	if (ret)
+		goto err;
+
+	ret = platform_device_add(pdev);
+	if (ret)
+		goto err;
+
+	return pdev;
+
+err:
+	platform_device_put(pdev);
+	return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(ci13xxx_add_device);
+
+void ci13xxx_remove_device(struct platform_device *pdev)
+{
+	platform_device_put(pdev);
+}
+EXPORT_SYMBOL_GPL(ci13xxx_remove_device);
+
 static int __devinit ci_hdrc_probe(struct platform_device *pdev)
 {
 	struct device	*dev = &pdev->dev;
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index d2f7e49..be078f0 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -25,4 +25,11 @@ struct ci13xxx_platform_data {
 /* Default offset of capability registers */
 #define DEF_CAPOFFSET		0x100
 
+/* Add ci13xxx device */
+struct platform_device *ci13xxx_add_device(struct device *dev,
+			struct resource *res, int nres,
+			struct ci13xxx_platform_data *platdata);
+/* Remove ci13xxx device */
+void ci13xxx_remove_device(struct platform_device *pdev);
+
 #endif
-- 
1.7.9.5


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

  parent reply	other threads:[~2012-06-21  6:41 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-21  6:41 [PATCH v6 00/14] add imx usb driver based on Greg next tree Richard Zhao
     [not found] ` <1340260875-21934-1-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-06-21  6:41   ` [PATCH v6 01/14] usb: chipidea: remove unneeded NULL check Richard Zhao
2012-06-21  6:41   ` [PATCH v6 02/14] usb: chipidea: drop useless arch-check Richard Zhao
2012-06-21  6:41   ` [PATCH v6 03/14] usb: chipidea: msm: add missing section annotation Richard Zhao
2012-06-21  6:41   ` [PATCH v6 04/14] usb: chipidea: msm: add remove method Richard Zhao
2012-06-21  6:41   ` [PATCH v6 05/14] USB: Chipidea: rename struct ci13xxx_udc_driver to struct ci13xxx_platform_data Richard Zhao
2012-06-21  6:41   ` [PATCH v6 06/14] USB: Chipidea: rename struct ci13xxx variables from udc to ci Richard Zhao
2012-06-21  6:41   ` Richard Zhao [this message]
     [not found]     ` <1340260875-21934-8-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-06-25  3:08       ` [PATCH v6 07/14] USB: Chipidea: add unified ci13xxx_{add,remove}_device for platform drivers Richard Zhao
2012-06-21  6:41   ` [PATCH v6 08/14] USB: Chipidea: add ci13xxx device id management Richard Zhao
2012-06-21  6:41   ` [PATCH v6 09/14] usb: chipidea: select USB_EHCI_ROOT_HUB_TT in USB_CHIPIDEA_HOST of Kconfig Richard Zhao
2012-06-21  6:41   ` [PATCH v6 10/14] usb: otg: add notify_connect/notify_disconnect callback Richard Zhao
2012-06-21  6:41   ` [PATCH v6 11/14] USB: notify phy when root hub port connect change Richard Zhao
2012-06-21  6:41   ` [PATCH v6 12/14] usb: chipidea: permit driver bindings pass phy pointer Richard Zhao
     [not found]     ` <1340260875-21934-13-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-06-21  7:18       ` Marc Kleine-Budde
     [not found]         ` <4FE2CABE.7050708-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-06-21  8:38           ` Richard Zhao
2012-06-21  8:51           ` [PATCH v7] " Richard Zhao
     [not found]             ` <1340268682-14654-1-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-06-21 20:42               ` Marc Kleine-Budde
     [not found]                 ` <4FE3874C.2040504-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-06-25  3:07                   ` Richard Zhao
2012-06-21  6:41   ` [PATCH v6 13/14] usb: otg: add basic mxs phy driver support Richard Zhao
     [not found]     ` <1340260875-21934-14-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-06-26  9:15       ` Alexander Shishkin
     [not found]         ` <87fw9iv3h0.fsf-qxRn5AmX6ZD9BXuAQUXR0fooFf0ArEBIu+b9c/7xato@public.gmane.org>
2012-06-27  6:47           ` Richard Zhao
2012-06-21  6:41   ` [PATCH v6 14/14] usb: chipidea: add imx platform driver Richard Zhao
     [not found]     ` <1340260875-21934-15-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-06-21 15:23       ` Richard Zhao
2012-06-21  7:24   ` [PATCH v6 00/14] add imx usb driver based on Greg next tree Marc Kleine-Budde
     [not found]     ` <4FE2CC37.8010202-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-06-21  8:52       ` Richard Zhao
     [not found]         ` <20120621085246.GC1582-iWYTGMXpHj9ITqJhDdzsOjpauB2SiJktrE5yTffgRl4@public.gmane.org>
2012-06-21  9:10           ` Marc Kleine-Budde
     [not found]             ` <4FE2E4FF.8030700-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-06-25  3:00               ` Richard Zhao
2012-06-25 16:18   ` Fabio Estevam
     [not found]     ` <CAOMZO5BEVrPrgZ7E5xUE-_3zXb317mzqoZXaxXw1SNACuRzOPw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-06-26  2:37       ` Shawn Guo
     [not found]         ` <20120626023754.GJ2342-rvtDTF3kK1ictlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-06-26 12:25           ` Marek Vasut
2012-07-30 22:27           ` Fabio Estevam

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=1340260875-21934-8-git-send-email-richard.zhao@freescale.com \
    --to=richard.zhao-kzfg59tc24xl57midrcfdg@public.gmane.org \
    --cc=B20596-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=B29397-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=alexander.shishkin-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=balbi-l0cyMroinI0@public.gmane.org \
    --cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=dong.aisheng-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=fabio.estevam-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linuxzsc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=marex-ynQEQJNshbs@public.gmane.org \
    --cc=shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.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;
as well as URLs for NNTP newsgroup(s).