[PATCHv1 2.6.34-rc6 1/3] mxc: gadget: remove 60mhz clock requirement for freescale mx51 usb core

Previous thread: Re: Fw: Re: [PATCH] bsdacct: delete timer with sync intension by Vitaliy Gusev on Wednesday, May 5, 2010 - 3:44 pm. (1 message)

Next thread: patch usb-gadget-webcam-depends-on-video_dev.patch added to gregkh-2.6 tree by gregkh on Wednesday, May 5, 2010 - 4:48 pm. (1 message)
From: Dinh Nguyen
Date: Wednesday, May 5, 2010 - 3:56 pm

This series of 3 patches is part of enabling usb gadget on freescale mx51 babbage hw.

PATCH 1/3
There is a conditional if statement for the usb clock to be 60MHz +/-1kHz in the 
mxc gadget driver, this requirement is not needed on mx51 because the usb core 
is clocked at 66.5MHz or any other frequency that are not multiples of 60MHz.

PATCH 2/3
PLL3 can be used for TVE output and/or USB. No need to turn on a whole PLL 
just for USB. Using PLL2 is a better source for the usb clock.

PATCH 3/3
Defines device structure for gadget on OTG port and registers it in the board file.
Defines the appropriate clock.
Defines KCONFIG option for enabling OTG port for EHCI or Gadget.
Conditionalizes the OTG port for EHCI or Gadget feature.

git diff --stat for all 3 patches:
arch/arm/mach-mx5/board-mx51_babbage.c |   11 +++++++++++
arch/arm/mach-mx5/clock-mx51.c         |    4 +++-
arch/arm/mach-mx5/devices.c            |   12 ++++++++++++
arch/arm/mach-mx5/devices.h            |    1 +
drivers/usb/gadget/fsl_mx3_udc.c       |   14 ++++++++------
drivers/usb/host/Kconfig               |    8 ++++++++
6 files changed, 43 insertions(+), 7 deletions(-)

Thanks,
Dinh Nguyen

--

From: Dinh Nguyen
Date: Wednesday, May 5, 2010 - 3:56 pm

This patch enables usb gadget for freescale mx51 babbage hw. It adds
a kconfig condition for enabling either host or gadget on the OTG
port.

Signed-off-by: Dinh Nguyen <Dinh.Nguyen@freescale.com>
---
 arch/arm/mach-mx5/board-mx51_babbage.c |   11 +++++++++++
 arch/arm/mach-mx5/clock-mx51.c         |    2 ++
 arch/arm/mach-mx5/devices.c            |   12 ++++++++++++
 arch/arm/mach-mx5/devices.h            |    1 +
 drivers/usb/host/Kconfig               |    8 ++++++++
 5 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-mx5/board-mx51_babbage.c b/arch/arm/mach-mx5/board-mx51_babbage.c
index 99f7ea9..fac8ce0 100644
--- a/arch/arm/mach-mx5/board-mx51_babbage.c
+++ b/arch/arm/mach-mx5/board-mx51_babbage.c
@@ -15,6 +15,7 @@
 #include <linux/gpio.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/fsl_devices.h>
 
 #include <mach/common.h>
 #include <mach/hardware.h>
@@ -179,6 +180,11 @@ static struct mxc_usbh_platform_data dr_utmi_config = {
 	.flags	= MXC_EHCI_INTERNAL_PHY,
 };
 
+static struct fsl_usb2_platform_data usb_pdata = {
+	.operating_mode	= FSL_USB2_DR_DEVICE,
+	.phy_mode	= FSL_USB2_PHY_UTMI_WIDE,
+};
+
 static struct mxc_usbh_platform_data usbh1_config = {
 	.init		= initialize_usbh1_port,
 	.portsc	= MXC_EHCI_MODE_ULPI,
@@ -197,7 +203,12 @@ static void __init mxc_board_init(void)
 	mxc_init_imx_uart();
 	platform_add_devices(devices, ARRAY_SIZE(devices));
 
+#if defined(CONFIG_USB_EHCI_MXC_OTG)
 	mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
+#elif defined(CONFIG_USB_GADGET_FSL_USB2)
+	initialize_otg_port(NULL);
+	mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata);
+#endif
 
 	gpio_usbh1_active();
 	mxc_register_device(&mxc_usbh1_device, &usbh1_config);
diff --git a/arch/arm/mach-mx5/clock-mx51.c b/arch/arm/mach-mx5/clock-mx51.c
index 933c0d1..ff15424 100644
--- a/arch/arm/mach-mx5/clock-mx51.c
+++ b/arch/arm/mach-mx5/clock-mx51.c
@@ -786,6 +786,8 @@ static struct clk_lookup ...
From: Sascha Hauer
Date: Thursday, May 6, 2010 - 12:27 am

I used a command line option for our boards which I find far more
convenient. Have a look at arch/arch/mach-mx2/mach-pca100.c how this is
done.
As a side effect you get rid of the 'defined but not used' warnings this
patch introduces and you don't have to put platform related kconfig
options to a totally unrelated place.


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
--

From: Dinh Nguyen
Date: Wednesday, May 5, 2010 - 3:56 pm

For power management reasons, pll2 should be used to source the USBOH3
clock for mx51. PLL3 can be completely gated off when USB is not used.

Signed-off-by: Dinh Nguyen <Dinh.Nguyen@freescale.com>
---
 arch/arm/mach-mx5/clock-mx51.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-mx5/clock-mx51.c b/arch/arm/mach-mx5/clock-mx51.c
index dcca330..933c0d1 100644
--- a/arch/arm/mach-mx5/clock-mx51.c
+++ b/arch/arm/mach-mx5/clock-mx51.c
@@ -763,7 +763,7 @@ DEFINE_CLOCK(gpt_ipg_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG10_OFFSET,
 
 /* USB */
 DEFINE_CLOCK(usboh3_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG14_OFFSET,
-	NULL, NULL, &pll3_sw_clk, NULL);
+	NULL, NULL, &pll2_sw_clk, NULL);
 
 /* FEC */
 DEFINE_CLOCK(fec_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG12_OFFSET,
-- 
1.6.0.4

--

From: Sascha Hauer
Date: Thursday, May 6, 2010 - 12:14 am

The commit message suggests that the parent is changed in this patch.
The only thing this patch changes is that when usboh3_clk is enabled,
pll2 instead of pll3 gets enabled. The real parent of this clock
is defined by the status quo of the CSCMR1/usboh3_clk_sel bits.

So the solution here is to initialize the parent field during runtime
according to the bits in hardware or to change the hardware bits
according to the parent field. Either way, please make sure that
hardware and state of the clock tree are consistent.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
--

From: Dinh Nguyen
Date: Wednesday, May 5, 2010 - 3:56 pm

for mx51, usb core is clocked from sources that are not 60mhz.

Signed-off-by: Dinh Nguyen <Dinh.Nguyen@freescale.com>
---
 drivers/usb/gadget/fsl_mx3_udc.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/fsl_mx3_udc.c b/drivers/usb/gadget/fsl_mx3_udc.c
index 20a802e..d0b8bde 100644
--- a/drivers/usb/gadget/fsl_mx3_udc.c
+++ b/drivers/usb/gadget/fsl_mx3_udc.c
@@ -50,12 +50,14 @@ int fsl_udc_clk_init(struct platform_device *pdev)
 		goto egusb;
 	}
 
-	freq = clk_get_rate(mxc_usb_clk);
-	if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
-	    (freq < 59999000 || freq > 60001000)) {
-		dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
-		ret = -EINVAL;
-		goto eclkrate;
+	if (!cpu_is_mx51()) {
+		freq = clk_get_rate(mxc_usb_clk);
+		if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
+		    (freq < 59999000 || freq > 60001000)) {
+			dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
+			ret = -EINVAL;
+			goto eclkrate;
+		}
 	}
 
 	ret = clk_enable(mxc_usb_clk);
-- 
1.6.0.4

--

Previous thread: Re: Fw: Re: [PATCH] bsdacct: delete timer with sync intension by Vitaliy Gusev on Wednesday, May 5, 2010 - 3:44 pm. (1 message)

Next thread: patch usb-gadget-webcam-depends-on-video_dev.patch added to gregkh-2.6 tree by gregkh on Wednesday, May 5, 2010 - 4:48 pm. (1 message)