public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Venu Byravarasu <vbyravarasu@nvidia.com>,
	gregkh@linuxfoundation.org, balbi@ti.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: Re: [PATCH 4/4] usb: Add APIs to access host registers from Tegra PHY
Date: Wed, 16 Jan 2013 14:56:07 -0700	[thread overview]
Message-ID: <50F721F7.2030907@wwwdotorg.org> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1301161004380.1704-100000@iolanthe.rowland.org>

On 01/16/2013 08:08 AM, Alan Stern wrote:
> On Wed, 16 Jan 2013, Venu Byravarasu wrote:
> 
>> As Tegra PHY driver needs to access one of the Host registers,
>> added few APIs.

>> --- a/drivers/usb/host/ehci-tegra.c
>> +++ b/drivers/usb/host/ehci-tegra.c

>> +void tegra_ehci_set_wakeon_events(struct usb_phy *x, bool enable)
>> +{
>> +	unsigned long val;
>> +	struct usb_hcd *hcd = bus_to_hcd(x->otg->host);
>> +	void __iomem *base = hcd->regs;
>> +	u32 wake = USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN;
>> +
>> +	val = readl(base + USB_PORTSC1);
>> +	if (enable)
>> +		val |= wake;
>> +	else
>> +		val &= ~wake;
>> +	writel(val, base + USB_PORTSC1);
>> +}
> 
> Here and below, this sort of code is highly questionable.  You
> evidently don't realize that some of the bits in the PORTSC registers
> are R/WC.  This means writing a 1 to these bits will clear them.  
> 
> Consequently it is almost always wrong to read a PORTSC register and
> then write back the same (or a slightly modified) value.

Sorry I'm not familiar with USB... Are the bits being manipulated here
(i.e. USB_PORTSC1_WKOC | USB_PORTSC1_WKDS | USB_PORTSC1_WKCN)
standardized USBisms, or some custom Tegra stuff?

Anyway, is the solution here to do:

val = readl(addr)

// i.e. add the following line:
val &= ~(all write-to-clear bits);

if (enable) val |= wake; else val &= ~wake;

writel(val, addr)

... or is there more broken than just that?

Also note that the driver is already doing exactly what is in these new
functions; the code is just being split out so that only the EHCI driver
touches EHCI registers, and the PHY driver only touches PHY registers.
Still, I'll admit it's a good time to fix any mistakes in this part of
the code.

  reply	other threads:[~2013-01-16 21:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-16 13:30 [PATCH 0/4] usb: Supporting patches for registering Tegra USB PHY as a platform driver Venu Byravarasu
2013-01-16 13:30 ` [PATCH 1/4] arm: tegra: Add DT nodes for Tegra USB PHY Venu Byravarasu
2013-01-16 21:49   ` Stephen Warren
2013-01-16 13:30 ` [PATCH 2/4] USB: PHY: Get rid of instance number to differentiate legacy controller Venu Byravarasu
     [not found]   ` <1358343022-28919-3-git-send-email-vbyravarasu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-01-18 18:34     ` Felipe Balbi
2013-01-16 13:30 ` [PATCH 3/4] USB: PHY: Tegra: Get rid of instance number to differentiate PHY type Venu Byravarasu
2013-01-18 17:04   ` Stephen Warren
     [not found]     ` <50F98089.6040008-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-01-18 17:07       ` Stephen Warren
     [not found]   ` <1358343022-28919-4-git-send-email-vbyravarasu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-01-18 18:34     ` Felipe Balbi
     [not found] ` <1358343022-28919-1-git-send-email-vbyravarasu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-01-16 13:30   ` [PATCH 4/4] usb: Add APIs to access host registers from Tegra PHY Venu Byravarasu
     [not found]     ` <1358343022-28919-5-git-send-email-vbyravarasu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-01-16 15:08       ` Alan Stern
2013-01-16 21:56         ` Stephen Warren [this message]
2013-01-16 22:25           ` Alan Stern

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=50F721F7.2030907@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=vbyravarasu@nvidia.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox