Skip to contentSkip to conversation

S3C64XX: Fix 48M clock enable

PATCH Superseded Paulius Zaleckas 2 participants 6 messages Oct 12, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover S3C64XX: Fix 48M clock enable

To enable 48M clock USB PHY must be initialized since 48M is output of USB PHY PLL.
So fix a problem where other devices requiring 48M clock will not work unless USB OTG driver is enabled.
is_osc was removed from OTG drivers platform data and implemented as separate function s3c6400_clk_xusbxti_is_osc which should be called from machine_init. Currently there is no in-kernel users of it.

This fix is only for S3C64xx family, but I am sure something similar will be needed for S5P family. I have started the work but I am unable to finnish it since I only have datasheet for S5PC100. Maybe Samsung guys could help me with this..? However current patches doesn't break S5P since it is not using s3c-hsotg driver (yet?).

---

Paulius Zaleckas (2):
USB: s3-hsotg: Remove PHY initialization code and use CLK API [v2]ARM: S3C64XX: Fix USB and 48M clock enable procedure

 arch/arm/mach-s3c64xx/clock.c               |   67 ++++++++++++++++++-
 arch/arm/plat-samsung/include/plat/clock.h  |    2 +
 arch/arm/plat-samsung/include/plat/udc-hs.h |    2 -
 drivers/usb/gadget/s3c-hsotg.c              |   94 +++++----------------------
 4 files changed, 79 insertions(+), 86 deletions(-)
#1 lore raw

PATCH v2 1/2 ARM: S3C64XX: Fix USB and 48M clock enable procedure

48M clock is output from USB PHY PLL. To enable 48M clock we must initialize USB PHY.

changes since v1:
- renamed s3c64xx_clk_xusbxti_is_osc() to s3c64xx_clk_xusbxti_set_osc()

---

 arch/arm/mach-s3c64xx/clock.c              |   67 +++++++++++++++++++++++++---
 arch/arm/plat-samsung/include/plat/clock.h |    2 +
 2 files changed, 63 insertions(+), 6 deletions(-)
arch/arm/mach-s3c64xx/clock.c +61 -6
index 7e03f0a..71131f7 100644
@@ -19,6 +19,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 
 #include <mach/hardware.h>
 #include <mach/map.h>
@@ -32,6 +33,7 @@
 #include <plat/cpu-freq.h>
 #include <plat/clock.h>
 #include <plat/clock-clksrc.h>
+#include <plat/regs-usb-hsotg-phy.h>
 
 /* fin_apll, fin_mpll and fin_epll are all the same clock, which we call
  * ext_xtal_mux for want of an actual name from the manual.
@@ -61,7 +63,20 @@ struct clk clk_27m = {
 	.rate		= 27000000,
 };
 
-static int clk_48m_ctrl(struct clk *clk, int enable)
+void __init s3c64xx_clk_xusbxti_set_osc(int is_osc)
+{
+	u32 val;
+
+	/* no need to protect since it will be called from machine init */
+	val = __raw_readl(S3C_PHYCLK);
+	if (is_osc)
+		val |= S3C_PHYCLK_EXT_OSC;
+	else
+		val &= ~S3C_PHYCLK_EXT_OSC;
+	__raw_writel(val, S3C_PHYCLK);
+}
+
+static int clk_xusbxti_ctrl(struct clk *clk, int enable)
 {
 	unsigned long flags;
 	u32 val;
@@ -76,22 +91,62 @@ static int clk_48m_ctrl(struct clk *clk, int enable)
 		val &= ~S3C64XX_OTHERS_USBMASK;
 
 	__raw_writel(val, S3C64XX_OTHERS);
+
+	val = __raw_readl(S3C_PHYPWR);
+	if (enable)
+		val &= ~(SRC_PHYPWR_OTG_DISABLE | SRC_PHYPWR_ANALOG_POWERDOWN |
+			 SRC_PHYPWR_FORCE_SUSPEND);
+	else
+		val |= (SRC_PHYPWR_OTG_DISABLE | SRC_PHYPWR_ANALOG_POWERDOWN |
+			SRC_PHYPWR_FORCE_SUSPEND);
+	__raw_writel(val, S3C_PHYPWR);
+	mdelay(1);
+
+	if (enable) {
+		val = __raw_readl(S3C_PHYCLK);
+
+		val &= ~S3C_PHYCLK_CLKSEL_MASK;
+
+		switch (clk->rate) {
+		case 12*MHZ:
+			val |= S3C_PHYCLK_CLKSEL_12M;
+			break;
+		case 24*MHZ:
+			val |= S3C_PHYCLK_CLKSEL_24M;
+			break;
+		default:
+			pr_err("Invalid USB PHY external clock frequency: %lu\n",
+			       clk->rate);
+		case 48*MHZ:
+			/* default reference clock */
+			break;
+		}
+
+		__raw_writel(val | S3C_PHYCLK_CLK_FORCE, S3C_PHYCLK);
+
+		/* issue a full set of resets to the otg and core */
+		__raw_writel(S3C_RSTCON_PHY, S3C_RSTCON);
+		udelay(20);	/* at-least 10uS */
+		__raw_writel(0, S3C_RSTCON);
+	}
+
 	local_irq_restore(flags);
 
 	return 0;
 }
 
-struct clk clk_48m = {
-	.name		= "clk_48m",
+struct clk clk_xusbxti = {
+	.name		= "xusbxti",
 	.id		= -1,
 	.rate		= 48000000,
-	.enable		= clk_48m_ctrl,
+	.enable		= clk_xusbxti_ctrl,
 };
 
-struct clk clk_xusbxti = {
-	.name		= "xusbxti",
+struct clk clk_48m = {
+	.name		= "clk_48m",
 	.id		= -1,
 	.rate		= 48000000,
+	.parent		= &clk_xusbxti,
 };
 
 static int inline s3c64xx_gate(void __iomem *reg,
arch/arm/plat-samsung/include/plat/clock.h +2 -0
index 0fbcd0e..ed6f6fa 100644
@@ -76,6 +76,8 @@ extern struct clk clk_27m;
 extern struct clk clk_48m;
 extern struct clk clk_xusbxti;
 
+extern void s3c64xx_clk_xusbxti_set_osc(int is_osc);
+
 extern int clk_default_setrate(struct clk *clk, unsigned long rate);
 extern struct clk_ops clk_ops_def_setrate;
 
#2 lore raw

PATCH v2 2/2 USB: s3-hsotg: Remove PHY initialization code and use CLK API

In reply to Paulius Zaleckas

All USB PHY initialization now is handled hy xusbxti clock enable procedure.

---

 arch/arm/plat-samsung/include/plat/udc-hs.h |    2 -
 drivers/usb/gadget/s3c-hsotg.c              |   94 +++++----------------------
 2 files changed, 16 insertions(+), 80 deletions(-)
arch/arm/plat-samsung/include/plat/udc-hs.h +0 -2
index a22a4f2..a8221cf 100644
@@ -21,9 +21,7 @@ enum s3c_hsotg_dmamode {
 /**
  * struct s3c_hsotg_plat - platform data for high-speed otg/udc
  * @dma: Whether to use DMA or not.
- * @is_osc: The clock source is an oscillator, not a crystal
  */
 struct s3c_hsotg_plat {
 	enum s3c_hsotg_dmamode	dma;
-	unsigned int		is_osc : 1;
 };
drivers/usb/gadget/s3c-hsotg.c +16 -78

155 lines not on this page · raw message

#3 lore raw

v2 cover S3C64XX: Fix 48M clock enable

In reply to Paulius Zaleckas

Hello,

Quoted 9 lines · Paulius Zaleckas

To enable 48M clock USB PHY must be initialized since 48M is output of USB PHY PLL.
So fix a problem where other devices requiring 48M clock will not work unless USB OTG driver is enabled.
is_osc was removed from OTG drivers platform data and implemented as separate function s3c6400_clk_xusbxti_is_osc which should be called from machine_init. Currently there is no in-kernel users of it.

Quoted 6 lines

This fix is only for S3C64xx family, but I am sure something similar will be needed for S5P family. I have started the work but I am unable to finnish it since I only have datasheet for S5PC100. Maybe Samsung guys could help me with this..? However current patches doesn't break S5P since it is not using s3c-hsotg driver (yet?).

There are patches that enables the driver on S5PC110/S5PV210 series on kgene/for-next tree. Please note that at least Samsung Goni and Samsung Aquila uses external oscillator to supply usb clock. Please refer to:

http://git.kernel.org/?p=linux/kernel/git/kgene/linux-samsung.git;a=commit;h=e5e044e637228be8bdf033c0772f9e5926269ae0
http://git.kernel.org/?p=linux/kernel/git/kgene/linux-samsung.git;a=commit;h=a33bc34103b4fc4eca13cdd61f2579857797bbf7

Best regards
--
Marek Szyprowski
Samsung Poland R&D Center

#4 lore raw

v2 cover S3C64XX: Fix 48M clock enable

Quoted 20 lines · Marek Szyprowski

Hello,

Quoted 9 lines · Paulius Zaleckas

To enable 48M clock USB PHY must be initialized since 48M is output of USB PHY PLL.
So fix a problem where other devices requiring 48M clock will not work unless USB OTG driver is enabled.
is_osc was removed from OTG drivers platform data and implemented as separate function s3c6400_clk_xusbxti_is_osc which should be called from machine_init. Currently there is no in-kernel users of it.

Quoted 6 lines

This fix is only for S3C64xx family, but I am sure something similar will be needed for S5P family. I have started the work but I am unable to finnish it since I only have datasheet for S5PC100. Maybe Samsung guys could help me with this..? However current patches doesn't break S5P since it is not using s3c-hsotg driver (yet?).

Quoted 6 lines

There are patches that enables the driver on S5PC110/S5PV210 series on kgene/for-next tree. Please note that at least Samsung Goni and Samsung Aquila uses external oscillator to supply usb clock. Please refer to:

http://git.kernel.org/?p=linux/kernel/git/kgene/linux-samsung.git;a=commit;h=e5e044e637228be8bdf033c0772f9e5926269ae0

Interesting patch... If Goni uses oscillator then it will fail with current otg driver since it will configure phy for crystal, because is_otg is not set in the platform data.

Quoted 1 line

http://git.kernel.org/?p=linux/kernel/git/kgene/linux-samsung.git;a=commit;h=a33bc34103b4fc4eca13cdd61f2579857797bbf7

This patch contains some really nasty workaround for S3C64XX_OTHERS Mine version allows to get rid of it.

I have some preliminary version of patch for s5p. I will send it to you in the evening.

#5 lore raw

v2 cover S3C64XX: Fix 48M clock enable

Hello,

Quoted 21 lines · Paulius Zaleckas
Quoted 21 lines
Quoted 9 lines

To enable 48M clock USB PHY must be initialized since 48M is output of USB PHY PLL.
So fix a problem where other devices requiring 48M clock will not work unless USB OTG driver is enabled.
is_osc was removed from OTG drivers platform data and implemented as separate function s3c6400_clk_xusbxti_is_osc which should be called from machine_init. Currently there is no in-kernel users of it.

Quoted 6 lines

This fix is only for S3C64xx family, but I am sure something similar will be needed for S5P family. I have started the work but I am unable to finnish it since I only have datasheet for S5PC100. Maybe Samsung guys could help me with this..? However current patches doesn't break S5P since it is not using s3c-hsotg driver (yet?).

There are patches that enables the driver on S5PC110/S5PV210 series on kgene/for-next tree. Please note that at least Samsung Goni and Samsung Aquila uses external oscillator to supply usb clock. Please refer to:

Quoted 6 lines
Quoted 1 line

http://git.kernel.org/?p=linux/kernel/git/kgene/linux-

samsung.git;a=commit;h=e5e044e637228be8bdf033c0772f9e5926269ae0

Interesting patch... If Goni uses oscillator then it will fail with current otg driver since it will configure phy for crystal, because is_otg is not set in the platform data.

Right, but the interesting is that fact that it was working. I will check it tomorrow again.

Quoted 5 lines
Quoted 1 line

http://git.kernel.org/?p=linux/kernel/git/kgene/linux-

samsung.git;a=commit;h=a33bc34103b4fc4eca13cdd61f2579857797bbf7

This patch contains some really nasty workaround for S3C64XX_OTHERS Mine version allows to get rid of it.

Right that approach was a hack. I really like the idea behind your patch.

Quoted 2 lines

I have some preliminary version of patch for s5p. I will send it to you in the evening.

Ok, I will check it tomorrow.

Best regards
--
Marek Szyprowski
Samsung Poland R&D Center