All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Babic <sbabic@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 05/14] mx51: Fix USB PHY clocks
Date: Fri, 28 Sep 2012 12:43:53 +0200	[thread overview]
Message-ID: <50657F69.30200@denx.de> (raw)
In-Reply-To: <334846973.5408083.1348828065883.JavaMail.root@advansee.com>

On 28/09/2012 12:27, Beno?t Th?baudeau wrote:
> Hi Igor,
> 
> On Friday, September 28, 2012 9:26:38 AM, Igor Grinberg wrote:
>> Hi Beno?t,
>>
>> please, see a minor #ifdef comment below
>>
>> On 09/27/12 22:21, Beno?t Th?baudeau wrote:
>>> The i.MX51 has a single USB PHY clock, while the i.MX53 has two.
>>> These 3 clocks
>>> have different clock gate control bit-fields.
>>>
>>> The existing code was correct only for i.MX53, so this patch fixes
>>> the i.MX51
>>> use case.
>>>
>>> Signed-off-by: Beno?t Th?baudeau <benoit.thebaudeau@advansee.com>
>>> Cc: Stefano Babic <sbabic@denx.de>
>>> Cc: Marek Vasut <marex@denx.de>
>>> Cc: Jana Rapava <fermata7@gmail.com>
>>> Cc: Wolfgang Grandegger <wg@denx.de>
>>> Cc: Igor Grinberg <grinberg@compulab.co.il>
>>> ---
>>> This patch supersedes http://patchwork.ozlabs.org/patch/177403/ .
>>> Changes for v2:
>>>  - Split patch into 3 parts (the 3, 4 and 5 from this v2 series).
>>>  - Merge the various set_usb_phy*_clk() functions (they were
>>>  identical).
>>>
>>>  .../arch/arm/cpu/armv7/mx5/clock.c                 |   20
>>>  +++++++++++++-------
>>>  .../arch/arm/include/asm/arch-mx5/clock.h          |    7 ++++++-
>>>  .../drivers/usb/host/ehci-mx5.c                    |    6 +++++-
>>>  3 files changed, 24 insertions(+), 9 deletions(-)
>>>
>>> diff --git u-boot-imx-e1eb75b.orig/arch/arm/cpu/armv7/mx5/clock.c
>>> u-boot-imx-e1eb75b/arch/arm/cpu/armv7/mx5/clock.c
>>> index df7e5cd..f727cfa 100644
>>> --- u-boot-imx-e1eb75b.orig/arch/arm/cpu/armv7/mx5/clock.c
>>> +++ u-boot-imx-e1eb75b/arch/arm/cpu/armv7/mx5/clock.c
>>> @@ -126,11 +126,21 @@ int enable_i2c_clk(unsigned char enable,
>>> unsigned i2c_num)
>>>  }
>>>  #endif
>>>  
>>> -void set_usb_phy1_clk(void)
>>> +void set_usb_phy_clk(void)
>>>  {
>>>  	clrbits_le32(&mxc_ccm->cscmr1, MXC_CCM_CSCMR1_USB_PHY_CLK_SEL);
>>>  }
>>>  
>>> +#if defined(CONFIG_MX51)
>>> +void enable_usb_phy_clk(unsigned char enable)
>>
>> I think the same name as the MX53 case will do better, see
>> explanation below.
>>
>>> +{
>>> +	unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON :
>>> MXC_CCM_CCGR_CG_OFF;
>>> +
>>> +	clrsetbits_le32(&mxc_ccm->CCGR2,
>>> +			MXC_CCM_CCGR2_USB_PHY(MXC_CCM_CCGR_CG_MASK),
>>> +			MXC_CCM_CCGR2_USB_PHY(cg));
>>> +}
>>
>> I would add here (again explanation below):
>> void enable_usb_phy2_clk(unsigned char enable)
>> {
>> 	/* MX51 has a single USB PHY clock, so do nothing here */
>> }
>>
>>> +#elif defined(CONFIG_MX53)
>>>  void enable_usb_phy1_clk(unsigned char enable)
>>>  {
>>>  	unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON :
>>>  	MXC_CCM_CCGR_CG_OFF;
>>> @@ -140,11 +150,6 @@ void enable_usb_phy1_clk(unsigned char enable)
>>>  			MXC_CCM_CCGR4_USB_PHY1(cg));
>>>  }
>>>  
>>> -void set_usb_phy2_clk(void)
>>> -{
>>> -	clrbits_le32(&mxc_ccm->cscmr1, MXC_CCM_CSCMR1_USB_PHY_CLK_SEL);
>>> -}
>>> -
>>>  void enable_usb_phy2_clk(unsigned char enable)
>>>  {
>>>  	unsigned int cg = enable ? MXC_CCM_CCGR_CG_ON :
>>>  	MXC_CCM_CCGR_CG_OFF;
>>> @@ -153,6 +158,7 @@ void enable_usb_phy2_clk(unsigned char enable)
>>>  			MXC_CCM_CCGR4_USB_PHY2(MXC_CCM_CCGR_CG_MASK),
>>>  			MXC_CCM_CCGR4_USB_PHY2(cg));
>>>  }
>>> +#endif
>>>  
>>>  /*
>>>   * Calculate the frequency of PLLn.
>>> @@ -803,7 +809,7 @@ void mxc_set_sata_internal_clock(void)
>>>  	u32 *tmp_base =
>>>  		(u32 *)(IIM_BASE_ADDR + 0x180c);
>>>  
>>> -	set_usb_phy1_clk();
>>> +	set_usb_phy_clk();
>>>  
>>>  	clrsetbits_le32(tmp_base, 0x6, 0x4);
>>>  }
>>> diff --git
>>> u-boot-imx-e1eb75b.orig/arch/arm/include/asm/arch-mx5/clock.h
>>> u-boot-imx-e1eb75b/arch/arm/include/asm/arch-mx5/clock.h
>>> index 55e3b51..e4ca417 100644
>>> --- u-boot-imx-e1eb75b.orig/arch/arm/include/asm/arch-mx5/clock.h
>>> +++ u-boot-imx-e1eb75b/arch/arm/include/asm/arch-mx5/clock.h
>>> @@ -56,8 +56,13 @@ u32 imx_get_uartclk(void);
>>>  u32 imx_get_fecclk(void);
>>>  unsigned int mxc_get_clock(enum mxc_clock clk);
>>>  int mxc_set_clock(u32 ref, u32 freq, u32 clk_type);
>>> -void set_usb_phy2_clk(void);
>>> +void set_usb_phy_clk(void);
>>> +#if defined(CONFIG_MX51)
>>> +void enable_usb_phy_clk(unsigned char enable);
>>> +#elif defined(CONFIG_MX53)
>>> +void enable_usb_phy1_clk(unsigned char enable);
>>>  void enable_usb_phy2_clk(unsigned char enable);
>>> +#endif
>>
>> If you follow my suggestion above, then here you will only have:
>>  -void set_usb_phy2_clk(void);
>>  +void set_usb_phy_clk(void);
>>  +void enable_usb_phy1_clk(unsigned char enable);
>>
>> and no complicating with #ifdefs needed.
>>
>>>  void set_usboh3_clk(void);
>>>  void enable_usboh3_clk(unsigned char enable);
>>>  void mxc_set_sata_internal_clock(void);
>>> diff --git u-boot-imx-e1eb75b.orig/drivers/usb/host/ehci-mx5.c
>>> u-boot-imx-e1eb75b/drivers/usb/host/ehci-mx5.c
>>> index 58cdcbe..5bf89f0 100644
>>> --- u-boot-imx-e1eb75b.orig/drivers/usb/host/ehci-mx5.c
>>> +++ u-boot-imx-e1eb75b/drivers/usb/host/ehci-mx5.c
>>> @@ -221,8 +221,12 @@ int ehci_hcd_init(void)
>>>  
>>>  	set_usboh3_clk();
>>>  	enable_usboh3_clk(1);
>>> -	set_usb_phy2_clk();
>>> +	set_usb_phy_clk();
>>> +#if defined(CONFIG_MX51) && CONFIG_MXC_USB_PORT == 0
>>> +	enable_usb_phy_clk(1);
>>> +#elif defined(CONFIG_MX53)
>>>  	enable_usb_phy2_clk(1);
>>> +#endif
>>
>> same here, it should be much cleaner.
>>
>>>  	mdelay(1);
>>>  
>>>  	/* Do board specific initialization */
>>>
> 
> Indeed. In clock.h, the #ifdefs could anyway be removed with the naming from my patch. The only difference would be an error at link time rather than at compile time if these functions were called for the wrong i.MX5. If we change the naming as you suggest, it's not a problem for set_usb_phy1_clk(), but for enable_usb_phy2_clk() I think that it would not really make sense. My point is that ehci-mx5.c should be cleaned even more deeply in order to initialize the USB PHYs corresponding to the selected EHCI ports, and not all (or only some for i.MX53) the PHYs at the beginning of ehci_hcd_init(). Also, calling enable_usb_phy2_clk() for i.MX51 would not make sense, even if it does nothing, because it would be confusing. So this solution has both advantages and drawbacks.
> 
> Stefano, Marek, what do you think?

I am much sensible regarding #ifdef. I admit, I hate them. Igor's
suggestion drop some of them, and IMHO the code is more readable,
independently if and when the ehci-mx5.c will be cleaned up. However, I
understand it is a personal taste ;-)

Best regards,
Stefano


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

  reply	other threads:[~2012-09-28 10:43 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14 18:05 [U-Boot] [PATCH 00/10] mx5: Fix clocks Benoît Thébaudeau
2012-08-14 18:06 ` [U-Boot] [PATCH 01/10] mx5: Undeclare imx_decode_pll() Benoît Thébaudeau
2012-08-23  9:10   ` Stefano Babic
2012-08-14 18:06 ` [U-Boot] [PATCH 02/10] mx5: Use explicit clock gate names Benoît Thébaudeau
2012-08-14 18:54   ` Marek Vasut
2012-08-14 19:13     ` Benoît Thébaudeau
2012-09-27 20:19   ` [U-Boot] [PATCH v2 01/14] mx5/6: Define default SoC input clock frequencies Benoît Thébaudeau
2012-09-27 20:20     ` [U-Boot] [PATCH v2 02/14] mx5 clocks: Cleanup Benoît Thébaudeau
2012-09-28  8:44       ` Stefano Babic
2012-09-27 20:21     ` [U-Boot] [PATCH v2 03/14] mx5: Use explicit clock gate names Benoît Thébaudeau
2012-09-28  8:53       ` Stefano Babic
2012-09-27 20:21     ` [U-Boot] [PATCH v2 04/14] mx5: Fix clock gate values Benoît Thébaudeau
2012-09-27 20:21     ` [U-Boot] [PATCH v2 05/14] mx51: Fix USB PHY clocks Benoît Thébaudeau
2012-09-27 20:47       ` Marek Vasut
2012-09-28  7:26       ` Igor Grinberg
2012-09-28 10:27         ` Benoît Thébaudeau
2012-09-28 10:43           ` Stefano Babic [this message]
2012-09-28 13:00             ` Benoît Thébaudeau
2012-09-28 15:02               ` Stefano Babic
2012-09-28 17:09       ` [U-Boot] [PATCH v3 " Benoît Thébaudeau
2012-10-02  8:35         ` Igor Grinberg
2012-09-27 20:22     ` [U-Boot] [PATCH v2 06/14] mx5 clocks: Add and use CCSR definitions Benoît Thébaudeau
2012-09-27 20:22     ` [U-Boot] [PATCH v2 07/14] mx5 clocks: Fix get_lp_apm() Benoît Thébaudeau
2012-09-27 20:22     ` [U-Boot] [PATCH v2 08/14] mx5 clocks: Fix get_periph_clk() Benoît Thébaudeau
2012-09-27 20:23     ` [U-Boot] [PATCH v2 09/14] mx5 clocks: Fix get_ipg_per_clk() Benoît Thébaudeau
2012-09-28  9:31       ` Stefano Babic
2012-09-28 10:42         ` Benoît Thébaudeau
2012-09-28 10:45           ` Stefano Babic
2012-09-28 12:55             ` Benoît Thébaudeau
2012-09-28 15:01               ` Stefano Babic
2012-09-27 20:23     ` [U-Boot] [PATCH v2 10/14] mx5 clocks: Fix get_uart_clk() Benoît Thébaudeau
2012-09-27 20:23     ` [U-Boot] [PATCH v2 11/14] mx5 clocks: Simplify imx_get_cspiclk() Benoît Thébaudeau
2012-09-27 20:23     ` [U-Boot] [PATCH v2 12/14] mx5 clocks: Fix MXC_FEC_CLK Benoît Thébaudeau
2012-09-27 20:24     ` [U-Boot] [PATCH v2 13/14] mx51: Fix I2C clock ID check Benoît Thébaudeau
2012-09-27 20:24     ` [U-Boot] [PATCH v2 14/14] mx5/6 clocks: Fix SDHC clocks Benoît Thébaudeau
2012-09-28  8:42     ` [U-Boot] [PATCH v2 01/14] mx5/6: Define default SoC input clock frequencies Stefano Babic
2012-09-30 10:28     ` Stefano Babic
2012-09-30 13:55       ` Benoît Thébaudeau
2012-09-30 14:05         ` Stefano Babic
2012-08-14 18:06 ` [U-Boot] [PATCH 03/10] mx5 clocks: Add and use CCSR definitions Benoît Thébaudeau
2012-08-14 18:55   ` Marek Vasut
2012-08-14 19:14     ` Benoît Thébaudeau
2012-08-14 19:11       ` Marek Vasut
2012-08-14 18:07 ` [U-Boot] [PATCH 04/10] mx5 clocks: Fix get_lp_apm() Benoît Thébaudeau
2012-08-14 18:07 ` [U-Boot] [PATCH 05/10] mx5 clocks: Fix get_periph_clk() Benoît Thébaudeau
2012-08-14 18:07 ` [U-Boot] [PATCH 06/10] mx5 clocks: Fix get_ipg_per_clk() Benoît Thébaudeau
2012-08-14 18:07 ` [U-Boot] [PATCH 07/10] mx5 clocks: Fix get_uart_clk() Benoît Thébaudeau
2012-08-20  9:52   ` Stefano Babic
2012-08-20 10:05     ` Stefano Babic
2012-08-14 18:07 ` [U-Boot] [PATCH 08/10] mx5 clocks: Simplify imx_get_cspiclk() Benoît Thébaudeau
2012-08-14 18:08 ` [U-Boot] [PATCH 09/10] mx5 clocks: Fix eSDHC clock Benoît Thébaudeau
2012-08-14 18:08 ` [U-Boot] [PATCH 10/10] mx5 clocks: Fix MXC_FEC_CLK Benoît Thébaudeau

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=50657F69.30200@denx.de \
    --to=sbabic@denx.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.