From: Roger Quadros <rogerq@ti.com>
To: balbi@ti.com
Cc: keshava_mgowda@ti.com, linux-usb@vger.kernel.org,
linux-omap@vger.kernel.org
Subject: Re: [PATCH 02/16] mfd: omap-usb-tll: Clean up clock handling
Date: Wed, 21 Nov 2012 14:36:48 +0200 [thread overview]
Message-ID: <50ACCAE0.3030907@ti.com> (raw)
In-Reply-To: <20121121115556.GD10216@arwen.pp.htv.fi>
Felipe,
Thanks for reviewing.
On 11/21/2012 01:55 PM, Felipe Balbi wrote:
> On Thu, Nov 15, 2012 at 04:34:00PM +0200, Roger Quadros wrote:
>> Every channel has a functional clock that is similarly named.
>> It makes sense to use a for loop to manage these clocks as OMAPs
>> can come with upto 3 channels.
>
> s/upto/up to
>
> BTW, this patch is doing a lot more than "cleaning up clock handling".
> This needs to be split into smaller patches.
>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>> drivers/mfd/omap-usb-tll.c | 130 +++++++++++++++++++++++++-------------------
>> 1 files changed, 74 insertions(+), 56 deletions(-)
>>
>> diff --git a/drivers/mfd/omap-usb-tll.c b/drivers/mfd/omap-usb-tll.c
>> index d1750a4..943ac14 100644
>> --- a/drivers/mfd/omap-usb-tll.c
>> +++ b/drivers/mfd/omap-usb-tll.c
>> @@ -82,8 +82,12 @@
>> #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
>> #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
>>
>> -#define OMAP_REV2_TLL_CHANNEL_COUNT 2
>> -#define OMAP_TLL_CHANNEL_COUNT 3
>> +#define REV2_TLL_CHANNEL_COUNT 2
>
> why are you dropping the OMAP_ prefix ? You shouldn't do that.
>
>> +#define DEFAULT_TLL_CHANNEL_COUNT 3
>
> Add OMAP_ prefix here.
>
>> +
>> +/* Update if any chip has more */
>> +#define MAX_TLL_CHANNEL_COUNT 3
>
> can't you figure this one out in runtime ? If this isn't in any
> registers (and looks like it's not), you can pass this information to
> the driver via DT or just use driver_data field on struct
> platform_driver.
>
>> #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 0)
>> #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 1)
>> #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 2)
>> @@ -96,8 +100,9 @@
>> #define is_ehci_tll_mode(x) (x == OMAP_EHCI_PORT_MODE_TLL)
>>
>> struct usbtll_omap {
>> - struct clk *usbtll_p1_fck;
>> - struct clk *usbtll_p2_fck;
>> + void __iomem *base;
>> + int nch; /* number of channels */
>> + struct clk *ch_clk[MAX_TLL_CHANNEL_COUNT];
>
> should be allocated dynamically.
>
>> struct usbtll_omap_platform_data *pdata;
>> /* secure the register updates */
>> spinlock_t lock;
>> @@ -210,49 +215,35 @@ static int __devinit usbtll_omap_probe(struct platform_device *pdev)
>> unsigned reg;
>> unsigned long flags;
>> int ret = 0;
>> - int i, ver, count;
>> + int i, ver;
>>
>> dev_dbg(dev, "starting TI HSUSB TLL Controller\n");
>>
>> tll = kzalloc(sizeof(struct usbtll_omap), GFP_KERNEL);
>> if (!tll) {
>> dev_err(dev, "Memory allocation failed\n");
>> - ret = -ENOMEM;
>> - goto end;
>> + return -ENOMEM;
>> }
>>
>> spin_lock_init(&tll->lock);
>>
>> tll->pdata = pdata;
>>
>> - tll->usbtll_p1_fck = clk_get(dev, "usb_tll_hs_usb_ch0_clk");
>> - if (IS_ERR(tll->usbtll_p1_fck)) {
>> - ret = PTR_ERR(tll->usbtll_p1_fck);
>> - dev_err(dev, "usbtll_p1_fck failed error:%d\n", ret);
>> - goto err_tll;
>> - }
>> -
>> - tll->usbtll_p2_fck = clk_get(dev, "usb_tll_hs_usb_ch1_clk");
>> - if (IS_ERR(tll->usbtll_p2_fck)) {
>> - ret = PTR_ERR(tll->usbtll_p2_fck);
>> - dev_err(dev, "usbtll_p2_fck failed error:%d\n", ret);
>> - goto err_usbtll_p1_fck;
>> - }
>> -
>> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>> if (!res) {
>> dev_err(dev, "usb tll get resource failed\n");
>> ret = -ENODEV;
>> - goto err_usbtll_p2_fck;
>> + goto err_mem;
>> }
>>
>> base = ioremap(res->start, resource_size(res));
>> if (!base) {
>> dev_err(dev, "TLL ioremap failed\n");
>> ret = -ENOMEM;
>> - goto err_usbtll_p2_fck;
>> + goto err_mem;
>> }
>>
>> + tll->base = base;
>> platform_set_drvdata(pdev, tll);
>> pm_runtime_enable(dev);
>> pm_runtime_get_sync(dev);
>> @@ -262,16 +253,33 @@ static int __devinit usbtll_omap_probe(struct platform_device *pdev)
>> ver = usbtll_read(base, OMAP_USBTLL_REVISION);
>> switch (ver) {
>> case OMAP_USBTLL_REV1:
>> - case OMAP_USBTLL_REV2:
>> - count = OMAP_TLL_CHANNEL_COUNT;
>> + tll->nch = DEFAULT_TLL_CHANNEL_COUNT;
>> break;
>> + case OMAP_USBTLL_REV2:
>> case OMAP_USBTLL_REV3:
>> - count = OMAP_REV2_TLL_CHANNEL_COUNT;
>> + tll->nch = REV2_TLL_CHANNEL_COUNT;
>
> nice, you *can* figure that out based on the revision... In that case,
> you shouldn't even define MAX_TLL_CHANNEL_COUNT, just allocate the array
> dynamically for the exact size you need.
>
OK.
>> break;
>> default:
>> - dev_err(dev, "TLL version failed\n");
>> - ret = -ENODEV;
>> - goto err_ioremap;
>> + tll->nch = DEFAULT_TLL_CHANNEL_COUNT;
>> + dev_info(dev,
>> + "USB TLL Rev : 0x%x not recognized, assuming %d channels\n",
>> + ver, tll->nch);
>
> this hsould be dev_dbg().
>
I think it should be more of a warning because it signals a problem.
There is another pr_info in the success path which could probably be a
dev_dbg.
>> + break;
>> + }
>> +
>> + for (i = 0; i < tll->nch; i++) {
>> + char clk_name[] = "usb_tll_hs_usb_chx_clk";
>
> just lazyness of counting the amount of letters ? :-p
;)
>
>> + struct clk *fck;
>> +
>> + sprintf(clk_name, "usb_tll_hs_usb_ch%d_clk", i);
>
> this will overflow if 'i' (for whatever reason) goes over 9.
OK i'll add an extra character. Highly unlikely to go above 99 :)
>
>> + fck = clk_get(dev, clk_name);
>
> please use devm_clk_get().
>
>> + if (IS_ERR(fck)) {
>> + dev_err(dev, "can't get clock : %s\n", clk_name);
>> + ret = PTR_ERR(fck);
>> + goto err_clk;
>> + }
>> + tll->ch_clk[i] = fck;
>> }
>>
>> if (is_ehci_tll_mode(pdata->port_mode[0]) ||
>> @@ -291,7 +299,7 @@ static int __devinit usbtll_omap_probe(struct platform_device *pdev)
>> usbtll_write(base, OMAP_TLL_SHARED_CONF, reg);
>>
>> /* Enable channels now */
>> - for (i = 0; i < count; i++) {
>> + for (i = 0; i < tll->nch; i++) {
>> reg = usbtll_read(base, OMAP_TLL_CHANNEL_CONF(i));
>>
>> if (is_ohci_port(pdata->port_mode[i])) {
>> @@ -319,25 +327,25 @@ static int __devinit usbtll_omap_probe(struct platform_device *pdev)
>> }
>> }
>>
>> -err_ioremap:
>> - spin_unlock_irqrestore(&tll->lock, flags);
>> - iounmap(base);
>> - pm_runtime_put_sync(dev);
>> tll_pdev = pdev;
>> - if (!ret)
>> - goto end;
>> - pm_runtime_disable(dev);
>>
>> -err_usbtll_p2_fck:
>> - clk_put(tll->usbtll_p2_fck);
>> +err_clk:
>> + for (--i; i >= 0 ; i--)
>> + clk_put(tll->ch_clk[i]);
>
> is clk_put(NULL) safe ??
>
>> -err_usbtll_p1_fck:
>> - clk_put(tll->usbtll_p1_fck);
>> + spin_unlock_irqrestore(&tll->lock, flags);
>> + pm_runtime_put_sync(dev);
>> + if (ret == 0) {
>> + pr_info("OMAP USB TLL : revision 0x%x, channels %d\n",
>> + ver, tll->nch);
>> + return 0;
>> + }
>
> the whole thing is quite confusing. Please while cleaning up the driver,
> also try to clean up the error path.
>
>> -err_tll:
>> - kfree(tll);
>> + iounmap(base);
>
> could be using devm_request_and_ioremap()
>
>> + pm_runtime_disable(dev);
>>
>> -end:
>> +err_mem:
>> + kfree(tll);
>
> could be using devm_kzalloc()
>
>> return ret;
>> }
>>
>> @@ -350,9 +358,12 @@ end:
>> static int __devexit usbtll_omap_remove(struct platform_device *pdev)
>> {
>> struct usbtll_omap *tll = platform_get_drvdata(pdev);
>> + int i;
>> +
>> + iounmap(tll->base);
>> + for (i = 0; i < tll->nch; i++)
>> + clk_put(tll->ch_clk[i]);
>>
>> - clk_put(tll->usbtll_p2_fck);
>> - clk_put(tll->usbtll_p1_fck);
>> pm_runtime_disable(&pdev->dev);
>> kfree(tll);
>> return 0;
>> @@ -363,6 +374,7 @@ static int usbtll_runtime_resume(struct device *dev)
>> struct usbtll_omap *tll = dev_get_drvdata(dev);
>> struct usbtll_omap_platform_data *pdata = tll->pdata;
>> unsigned long flags;
>> + int i;
>>
>> dev_dbg(dev, "usbtll_runtime_resume\n");
>>
>> @@ -373,11 +385,17 @@ static int usbtll_runtime_resume(struct device *dev)
>>
>> spin_lock_irqsave(&tll->lock, flags);
>>
>> - if (is_ehci_tll_mode(pdata->port_mode[0]))
>> - clk_enable(tll->usbtll_p1_fck);
>> -
>> - if (is_ehci_tll_mode(pdata->port_mode[1]))
>> - clk_enable(tll->usbtll_p2_fck);
>> + for (i = 0; i < tll->nch; i++) {
>> + if (is_ehci_tll_mode(pdata->port_mode[i])) {
>> + int r;
>> + r = clk_enable(tll->ch_clk[i]);
>> + if (r) {
>> + dev_err(dev,
>> + "%s : Error enabling ch %d clock: %d\n",
>> + __func__, i, r);
>
> you don't need __func__.
>
Thought it would be useful to point out where the message is coming
from. But it should be easy to grep too so I'll remove it.
cheers,
-roger
next prev parent reply other threads:[~2012-11-21 12:36 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-15 14:33 [PATCH 00/16] OMAP USB Host cleanup Roger Quadros
2012-11-15 14:33 ` [PATCH 01/16] mfd: omap-usb-tll: Avoid creating copy of platform data Roger Quadros
2012-11-21 11:42 ` Felipe Balbi
2012-11-15 14:34 ` [PATCH 02/16] mfd: omap-usb-tll: Clean up clock handling Roger Quadros
2012-11-21 11:55 ` Felipe Balbi
2012-11-21 12:36 ` Roger Quadros [this message]
2012-11-21 14:03 ` Felipe Balbi
[not found] ` <20121121140354.GR10216-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-21 15:39 ` Roger Quadros
[not found] ` <50ACF5CD.9010209-l0cyMroinI0@public.gmane.org>
2012-11-21 19:39 ` Felipe Balbi
2012-11-22 8:19 ` Roger Quadros
2012-11-15 14:34 ` [PATCH 03/16] mfd: omap-usb-tll: introduce and use mode_needs_tll() Roger Quadros
2012-11-21 11:57 ` Felipe Balbi
[not found] ` <20121121115705.GE10216-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-21 12:37 ` Roger Quadros
2012-11-15 14:34 ` [PATCH 07/16] mfd: omap_usb_host: Avoid creating copy of platform_data Roger Quadros
2012-11-21 13:40 ` Felipe Balbi
2012-11-15 14:34 ` [PATCH 08/16] mfd: omap-usb-host: know about number of ports from revision register Roger Quadros
2012-11-21 13:43 ` Felipe Balbi
[not found] ` <20121121134300.GJ10216-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-21 14:45 ` Roger Quadros
2012-11-21 19:44 ` Felipe Balbi
2012-11-15 14:34 ` [PATCH 09/16] mfd: omap-usb-host: override number of ports from platform data Roger Quadros
[not found] ` <1352990054-14680-10-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2012-11-21 13:45 ` Felipe Balbi
2012-11-21 14:50 ` Roger Quadros
2012-11-21 19:47 ` Felipe Balbi
2012-11-15 14:34 ` [PATCH 10/16] mfd: omap-usb-host: Intialize all available ports Roger Quadros
2012-11-21 13:52 ` Felipe Balbi
2012-11-21 15:47 ` Roger Quadros
2012-11-21 19:48 ` Felipe Balbi
2012-11-27 12:10 ` Roger Quadros
2012-11-27 13:28 ` Felipe Balbi
[not found] ` <20121127132827.GC22556-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-27 13:39 ` Roger Quadros
2012-11-15 14:34 ` [PATCH 12/16] ARM: OMAP2+: clock data: Merge utmi_px_gfclk into usb_host_hs_utmi_px_clk Roger Quadros
2012-11-15 14:34 ` [PATCH 13/16] mfd: omap-usb-host: Get rid of unnecessary spinlock Roger Quadros
[not found] ` <1352990054-14680-14-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2012-11-21 13:57 ` Felipe Balbi
[not found] ` <20121121135732.GN10216-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-21 15:55 ` Roger Quadros
2012-11-21 19:50 ` Felipe Balbi
2012-11-15 14:34 ` [PATCH 14/16] mfd: omap-usb-host: Support an auxiliary clock per port Roger Quadros
[not found] ` <1352990054-14680-15-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2012-11-21 13:58 ` Felipe Balbi
[not found] ` <20121121135841.GO10216-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-21 16:00 ` Roger Quadros
2012-11-15 14:34 ` [PATCH 16/16] ARM: OMAP: omap4panda: Power down the USB PHY and ETH when not in use Roger Quadros
2012-11-21 14:00 ` Felipe Balbi
[not found] ` <20121121140044.GQ10216-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-21 14:52 ` Alan Stern
2012-11-21 15:13 ` Roger Quadros
[not found] ` <50ACEFA5.4080104-l0cyMroinI0@public.gmane.org>
2012-11-21 15:32 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1211211028200.1731-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-21 16:07 ` Roger Quadros
2012-11-21 19:54 ` Felipe Balbi
[not found] ` <20121121195436.GF14290-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-22 1:13 ` Andy Green
2012-11-22 12:21 ` Felipe Balbi
[not found] ` <20121122121845.GB18022-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-22 13:49 ` Andy Green
2012-11-22 13:56 ` Felipe Balbi
[not found] ` <20121122135603.GA20066-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-22 15:00 ` Roger Quadros
[not found] ` <50AE3E1D.9000607-l0cyMroinI0@public.gmane.org>
2012-11-22 16:12 ` Felipe Balbi
[not found] ` <20121122161228.GB20665-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-23 10:23 ` Roger Quadros
[not found] ` <50AF4EB8.9010800-l0cyMroinI0@public.gmane.org>
2012-11-23 10:44 ` Felipe Balbi
[not found] ` <20121123104416.GD29585-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-23 16:25 ` Alan Stern
2012-11-23 20:37 ` Andy Green
2012-11-24 15:38 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1211241032490.4291-100000-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-24 22:00 ` Andy Green
[not found] ` <50B14395.4010404-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-25 0:41 ` Alan Stern
2012-11-22 17:36 ` Alan Stern
2012-11-22 17:53 ` Felipe Balbi
[not found] ` <20121122175340.GA22614-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-22 18:32 ` Alan Stern
2012-11-22 20:15 ` Felipe Balbi
2012-11-23 2:35 ` Alan Stern
2012-11-23 10:38 ` Felipe Balbi
[not found] ` <20121123103817.GC29585-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-23 16:27 ` Alan Stern
2012-11-26 8:52 ` Felipe Balbi
[not found] ` <Pine.LNX.4.44L0.1211221226360.2255-100000-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org>
2012-11-23 0:19 ` Andy Green
[not found] ` <1352990054-14680-1-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2012-11-15 14:34 ` [PATCH 04/16] mfd: omap-usb-tll: Move port clock handling out of runtime ops Roger Quadros
[not found] ` <1352990054-14680-5-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2012-11-21 12:06 ` Felipe Balbi
2012-11-21 12:45 ` Roger Quadros
[not found] ` <50ACCCFA.6060605-l0cyMroinI0@public.gmane.org>
2012-11-21 14:07 ` Felipe Balbi
2012-11-15 14:34 ` [PATCH 05/16] mfd: omap-usb-tll: Add OMAP5 revision and HSIC support Roger Quadros
[not found] ` <1352990054-14680-6-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2012-11-21 12:12 ` Felipe Balbi
[not found] ` <20121121121238.GG10216-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-21 12:49 ` Roger Quadros
2012-11-21 14:08 ` Felipe Balbi
2012-11-15 14:34 ` [PATCH 06/16] mfd: omap-usb-host: cleanup clock management code Roger Quadros
[not found] ` <1352990054-14680-7-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2012-11-21 13:39 ` Felipe Balbi
2012-11-26 15:14 ` Roger Quadros
[not found] ` <50B38765.5070901-l0cyMroinI0@public.gmane.org>
2012-11-26 20:02 ` Felipe Balbi
2012-11-27 9:41 ` Roger Quadros
2012-11-15 14:34 ` [PATCH 11/16] mfd: omap-usb-host: Manage HSIC clocks for HSIC mode Roger Quadros
[not found] ` <1352990054-14680-12-git-send-email-rogerq-l0cyMroinI0@public.gmane.org>
2012-11-21 13:54 ` Felipe Balbi
[not found] ` <20121121135451.GM10216-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-11-21 15:49 ` Roger Quadros
2012-11-15 14:34 ` [PATCH 15/16] ARM: OMAP4: omap4panda: Don't enable USB PHY clock from board Roger Quadros
2012-11-21 13:59 ` Felipe Balbi
2012-11-16 20:08 ` [PATCH 00/16] OMAP USB Host cleanup Kevin Hilman
[not found] ` <87fw49cnvh.fsf-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2012-11-19 10:11 ` Roger Quadros
[not found] ` <50AA05C3.7010003-l0cyMroinI0@public.gmane.org>
2012-11-19 23:22 ` Kevin Hilman
2012-11-20 23:13 ` Tony Lindgren
2012-11-21 10:05 ` Roger Quadros
2012-11-21 11:41 ` Felipe Balbi
2012-11-27 14:42 ` Roger Quadros
2012-11-27 16:30 ` Felipe Balbi
[not found] ` <20121127163022.GB24240-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-12-04 14:46 ` Grazvydas Ignotas
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=50ACCAE0.3030907@ti.com \
--to=rogerq@ti.com \
--cc=balbi@ti.com \
--cc=keshava_mgowda@ti.com \
--cc=linux-omap@vger.kernel.org \
--cc=linux-usb@vger.kernel.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 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.