[PATCH] EHCI : introduce a common ehci_setup

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

 




This allow to clean duplicated code in most of SOC driver.

Signed-off-by: Matthieu CASTET <castet.matthieu@xxxxxxx>
---
drivers/usb/host/ehci-atmel.c     |   20 +-------------------
drivers/usb/host/ehci-cns3xxx.c   |   10 +---------
drivers/usb/host/ehci-fsl.c       |   21 ++-------------------
drivers/usb/host/ehci-hcd.c       |   29 +++++++++++++++++++++++++++++
drivers/usb/host/ehci-ixp4xx.c    |    7 +------
drivers/usb/host/ehci-msm.c       |   20 +-------------------
drivers/usb/host/ehci-mxc.c       |   17 +----------------
drivers/usb/host/ehci-orion.c     |   14 +-------------
drivers/usb/host/ehci-ppc-of.c    |   19 +------------------
drivers/usb/host/ehci-ps3.c       |   19 +------------------
drivers/usb/host/ehci-sh.c        |   16 +---------------
drivers/usb/host/ehci-spear.c     |   10 +---------
drivers/usb/host/ehci-xilinx-of.c |   15 +--------------
13 files changed, 42 insertions(+), 175 deletions(-)

diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index b2ed55c..c5d5b4b 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -55,26 +55,8 @@ static int ehci_atmel_setup(struct usb_hcd *hcd)

	/* registers start at offset 0x0 */
	ehci->caps = hcd->regs;
-	ehci->regs = hcd->regs +
-		HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
-	dbg_hcs_params(ehci, "reset");
-	dbg_hcc_params(ehci, "reset");
+	retval = ehci_setup(hcd);

-	/* cache this readonly data; minimize chip reads */
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-
-	retval = ehci_halt(ehci);
-	if (retval)
-		return retval;
-
-	/* data structure init */
-	retval = ehci_init(hcd);
-	if (retval)
-		return retval;
-
-	ehci->sbrn = 0x20;
-
-	ehci_reset(ehci);
	ehci_port_power(ehci, 0);

	return retval;
diff --git a/drivers/usb/host/ehci-cns3xxx.c b/drivers/usb/host/ehci-cns3xxx.c
index 708a05b..99b7d09 100644
--- a/drivers/usb/host/ehci-cns3xxx.c
+++ b/drivers/usb/host/ehci-cns3xxx.c
@@ -33,16 +33,8 @@ static int cns3xxx_ehci_init(struct usb_hcd *hcd)
	}

	ehci->caps = hcd->regs;
-	ehci->regs = hcd->regs
-		+ HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-
	hcd->has_tt = 0;
-	ehci_reset(ehci);
-
-	retval = ehci_init(hcd);
-	if (retval)
-		return retval;
+	retval = ehci_setup(hcd);

	ehci_port_power(ehci, 0);

diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 5c761df..20c6130 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -288,31 +288,14 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
	ehci->big_endian_desc = pdata->big_endian_desc;
	ehci->big_endian_mmio = pdata->big_endian_mmio;

+	hcd->has_tt = 1;
	/* EHCI registers start at offset 0x100 */
	ehci->caps = hcd->regs + 0x100;
-	ehci->regs = hcd->regs + 0x100 +
-	    HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
-	dbg_hcs_params(ehci, "reset");
-	dbg_hcc_params(ehci, "reset");
-
-	/* cache this readonly data; minimize chip reads */
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-
-	hcd->has_tt = 1;
-
-	retval = ehci_halt(ehci);
-	if (retval)
-		return retval;

-	/* data structure init */
-	retval = ehci_init(hcd);
+	retval = ehci_setup(hcd);
	if (retval)
		return retval;

-	ehci->sbrn = 0x20;
-
-	ehci_reset(ehci);
-
	retval = ehci_fsl_reinit(ehci);
	return retval;
}
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 78561d1..8a047e18 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -759,6 +759,35 @@ static int ehci_run (struct usb_hcd *hcd)
	return 0;
}

+static int __maybe_unused ehci_setup (struct usb_hcd *hcd)
+{
+	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+	int retval;
+
+	ehci->regs = (void __iomem *)ehci->caps +
+	    HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
+	dbg_hcs_params(ehci, "reset");
+	dbg_hcc_params(ehci, "reset");
+
+	/* cache this readonly data; minimize chip reads */
+	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
+
+	ehci->sbrn = HCD_USB2;
+
+	retval = ehci_halt(ehci);
+	if (retval)
+		return retval;
+
+	/* data structure init */
+	retval = ehci_init(hcd);
+	if (retval)
+		return retval;
+
+	ehci_reset(ehci);
+
+	return 0;
+}
+
/*-------------------------------------------------------------------------*/

static irqreturn_t ehci_irq (struct usb_hcd *hcd)
diff --git a/drivers/usb/host/ehci-ixp4xx.c b/drivers/usb/host/ehci-ixp4xx.c
index 89b7c70..c44fc33 100644
--- a/drivers/usb/host/ehci-ixp4xx.c
+++ b/drivers/usb/host/ehci-ixp4xx.c
@@ -22,14 +22,9 @@ static int ixp4xx_ehci_init(struct usb_hcd *hcd)
	ehci->big_endian_mmio = 1;

	ehci->caps = hcd->regs + 0x100;
-	ehci->regs = hcd->regs + 0x100
-		+ HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-
	hcd->has_tt = 1;
-	ehci_reset(ehci);

-	retval = ehci_init(hcd);
+	retval = ehci_setup(hcd);
	if (retval)
		return retval;

diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 9ce1b0b..592d5f7 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -40,27 +40,9 @@ static int ehci_msm_reset(struct usb_hcd *hcd)
	int retval;

	ehci->caps = USB_CAPLENGTH;
-	ehci->regs = USB_CAPLENGTH +
-		HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
-	dbg_hcs_params(ehci, "reset");
-	dbg_hcc_params(ehci, "reset");
-
-	/* cache the data to minimize the chip reads*/
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-
	hcd->has_tt = 1;
-	ehci->sbrn = HCD_USB2;
-
-	retval = ehci_halt(ehci);
-	if (retval)
-		return retval;
-
-	/* data structure init */
-	retval = ehci_init(hcd);
-	if (retval)
-		return retval;

-	retval = ehci_reset(ehci);
+	retval = ehci_setup(hcd);
	if (retval)
		return retval;

diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
index 25c8c10..1e16744 100644
--- a/drivers/usb/host/ehci-mxc.c
+++ b/drivers/usb/host/ehci-mxc.c
@@ -41,27 +41,12 @@ static int ehci_mxc_setup(struct usb_hcd *hcd)
	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
	int retval;

-	dbg_hcs_params(ehci, "reset");
-	dbg_hcc_params(ehci, "reset");
-
-	/* cache this readonly data; minimize chip reads */
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-
	hcd->has_tt = 1;

-	retval = ehci_halt(ehci);
+	retval = ehci_setup(hcd);
	if (retval)
		return retval;

-	/* data structure init */
-	retval = ehci_init(hcd);
-	if (retval)
-		return retval;
-
-	ehci->sbrn = 0x20;
-
-	ehci_reset(ehci);
-
	ehci_port_power(ehci, 0);
	return 0;
}
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 281e094..bd1a589 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -107,19 +107,10 @@ static int ehci_orion_setup(struct usb_hcd *hcd)

	hcd->has_tt = 1;

-	retval = ehci_halt(ehci);
+	retval = ehci_setup(hcd);
	if (retval)
		return retval;

-	/*
-	 * data structure init
-	 */
-	retval = ehci_init(hcd);
-	if (retval)
-		return retval;
-
-	ehci_reset(ehci);
-
	ehci_port_power(ehci, 0);

	return retval;
@@ -252,9 +243,6 @@ static int __devinit ehci_orion_drv_probe(struct platform_device *pdev)
	ehci->caps = hcd->regs + 0x100;
	ehci->regs = hcd->regs + 0x100 +
		HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-	hcd->has_tt = 1;
-	ehci->sbrn = 0x20;

	/*
	 * (Re-)program MBUS remapping windows if we are asked to.
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 1f09f25..dd6a6dd 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -20,19 +20,7 @@
/* called during probe() after chip reset completes */
static int ehci_ppc_of_setup(struct usb_hcd *hcd)
{
-	struct ehci_hcd	*ehci = hcd_to_ehci(hcd);
-	int		retval;
-
-	retval = ehci_halt(ehci);
-	if (retval)
-		return retval;
-
-	retval = ehci_init(hcd);
-	if (retval)
-		return retval;
-
-	ehci->sbrn = 0x20;
-	return ehci_reset(ehci);
+	return ehci_setup(hcd);
}


@@ -178,11 +166,6 @@ static int __devinit ehci_hcd_ppc_of_probe(struct platform_device *op)
		ehci->big_endian_desc = 1;

	ehci->caps = hcd->regs;
-	ehci->regs = hcd->regs +
-			HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
-
-	/* cache this readonly data; minimize chip reads */
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);

	if (of_device_is_compatible(dn, "ibm,usb-ehci-440epx")) {
		rv = ppc44x_enable_bmt(dn);
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index 1dee33b..35e0706 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -29,25 +29,8 @@ static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
	ehci->big_endian_mmio = 1;

	ehci->caps = hcd->regs;
-	ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci,
-		&ehci->caps->hc_capbase));

-	dbg_hcs_params(ehci, "reset");
-	dbg_hcc_params(ehci, "reset");
-
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-
-	result = ehci_halt(ehci);
-
-	if (result)
-		return result;
-
-	result = ehci_init(hcd);
-
-	if (result)
-		return result;
-
-	ehci_reset(ehci);
+	result = ehci_setup(hcd);

	return result;
}
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index 595f70f..72686a1 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -23,25 +23,11 @@ static int ehci_sh_reset(struct usb_hcd *hcd)
	int ret;

	ehci->caps = hcd->regs;
-	ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci,
-		&ehci->caps->hc_capbase));

-	dbg_hcs_params(ehci, "reset");
-	dbg_hcc_params(ehci, "reset");
-
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-
-	ret = ehci_halt(ehci);
-	if (unlikely(ret))
-		return ret;
-
-	ret = ehci_init(hcd);
+	ret = ehci_setup(hcd);
	if (unlikely(ret))
		return ret;

-	ehci->sbrn = 0x20;
-
-	ehci_reset(ehci);
	ehci_port_power(ehci, 0);

	return ret;
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
index 75c0087..7d00b84 100644
--- a/drivers/usb/host/ehci-spear.c
+++ b/drivers/usb/host/ehci-spear.c
@@ -38,19 +38,11 @@ static int ehci_spear_setup(struct usb_hcd *hcd)

	/* registers start at offset 0x0 */
	ehci->caps = hcd->regs;
-	ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci,
-				&ehci->caps->hc_capbase));
-	/* cache this readonly data; minimize chip reads */
-	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
-	retval = ehci_halt(ehci);
-	if (retval)
-		return retval;

-	retval = ehci_init(hcd);
+	retval = ehci_setup(hcd);
	if (retval)
		return retval;

-	ehci_reset(ehci);
	ehci_port_power(ehci, 0);

	return retval;
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
index effc58d..9cb9950 100644
--- a/drivers/usb/host/ehci-xilinx-of.c
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -39,20 +39,7 @@
 */
static int ehci_xilinx_of_setup(struct usb_hcd *hcd)
{
-	struct ehci_hcd	*ehci = hcd_to_ehci(hcd);
-	int		retval;
-
-	retval = ehci_halt(ehci);
-	if (retval)
-		return retval;
-
-	retval = ehci_init(hcd);
-	if (retval)
-		return retval;
-
-	ehci->sbrn = 0x20;
-
-	return ehci_reset(ehci);
+	return ehci_setup(hcd);
}

/**
--
1.7.4.1

--
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