devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
To: sundeep subbaraya <sundeep.lkml-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: balbi-l0cyMroinI0@public.gmane.org,
	Subbaraya Sundeep Bhatta
	<subbaraya.sundeep.bhatta-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>,
	Greg Kroah-Hartman
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	Michal Simek <michals-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>,
	"linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Subbaraya Sundeep Bhatta
	<sbhatta-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>
Subject: Re: Fwd: [PATCH v2 2/2] usb: gadget: Add xilinx axi usb2 device support
Date: Tue, 8 Apr 2014 16:24:21 -0500	[thread overview]
Message-ID: <20140408212421.GA1431@saruman.home> (raw)
In-Reply-To: <CALHRZuotnNf-sCaeQJQ_PnSVET=+GvZ_PmvF7E3oEg8bKZ8a2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 5679 bytes --]

Hi,

On Tue, Apr 08, 2014 at 09:31:29PM +0530, sundeep subbaraya wrote:
> >> >> +static const struct usb_gadget_ops xusb_udc_ops = {
> >> >> +     .get_frame = xudc_get_frame,
> >> >> +     .wakeup = xudc_wakeup,
> >> >> +     .udc_start = xudc_start,
> >> >> +     .udc_stop  = xudc_stop,
> >> >
> >> > no pullup ??? What gives ? This HW doesn't support it ? really ?
> >>
> >> Yes, there is no pull up. writing to control register to start udc is
> >> sufficient for this IP.
> >
> > right, but is there a bit inside control register which actually starts
> > the IP ? You might want to move that to ->pullup(), see how we did on
> > drivers/usb/dwc3/gadget.c::dwc3_gadget_pullup(); we're basically using
> > that to control RUN/STOP bit in DCTL register. That bit has two
> > functions: a) actually enable the ip; b) connect data pullups.
> >
> > You can actually see with a scope that the line goes high and low when
> > you mess with that bit.
> >
> > The reason I suggest this is because you don't want to let your host see
> > a connection until your gadget driver is registered and ready to go and
> > that's what the pullup method would guarantee.
> 
> No.There are only two bits in Control register, one for Ready bit, another for
> sending remote wakeup and remaining are reserved as zeroes. Until ready is
> set host do not see the gadget.

so this READY bit is what you want to toggle on pullup().

> >> >> +     }
> >> >> +     if (intrstatus & XUSB_STATUS_SUSPEND_MASK) {
> >> >> +
> >> >> +             DBG("Suspend\n");
> >> >> +
> >> >> +             /* Enable the reset and resume */
> >> >> +             intrreg = udc->read_fn(udc->base_address + XUSB_IER_OFFSET);
> >> >> +             intrreg |= XUSB_STATUS_RESET_MASK | XUSB_STATUS_RESUME_MASK;
> >> >> +             udc->write_fn(udc->base_address, XUSB_IER_OFFSET, intrreg);
> >> >> +             udc->usb_state = USB_STATE_SUSPENDED;
> >> >> +
> >> >> +             if (udc->driver->suspend)
> >> >> +                     udc->driver->suspend(&udc->gadget);
> >> >> +     }
> >> >
> >> > when are you going to call driver->resume() ??
> >>
> >> When an interrupt occurs we first check if udc->usb_state =
> >> USB_STATE_SUSPENDED,
> >> if yes driver->resume is called. Also if Resume bit is set then it is
> >> cleared too. Resume status bit is set
> >> when device is resumed by host after device sends Remote wakeup
> >> signalling to host.
> >
> > <snip>
> >
> >> >> +static irqreturn_t xudc_irq(int irq, void *_udc)
> >> >> +{
> >> >> +     struct xusb_udc *udc = _udc;
> >> >> +     u32 intrstatus;
> >> >> +     u32 intrreg;
> >> >> +     u8 index;
> >> >> +     u32 bufintr;
> >> >> +
> >> >> +     spin_lock(&(udc->lock));
> >> >> +
> >> >> +     intrreg = udc->read_fn(udc->base_address + XUSB_IER_OFFSET);
> >> >> +     intrreg &= ~XUSB_STATUS_INTR_EVENT_MASK;
> >> >> +     udc->write_fn(udc->base_address, XUSB_IER_OFFSET, intrreg);
> >> >> +
> >> >> +     /* Read the Interrupt Status Register.*/
> >> >> +     intrstatus = udc->read_fn(udc->base_address + XUSB_STATUS_OFFSET);
> >> >> +
> >> >> +     if (udc->usb_state == USB_STATE_SUSPENDED) {
> >> >> +
> >> >> +             DBG("Resume\n");
> >> >> +
> >> >> +             if (intrstatus & XUSB_STATUS_RESUME_MASK) {
> >> >> +                     /* Enable the reset and suspend */
> >> >> +                     intrreg = udc->read_fn(udc->base_address +
> >> >> +                                             XUSB_IER_OFFSET);
> >> >> +                     intrreg |= XUSB_STATUS_RESET_MASK |
> >> >> +                                     XUSB_STATUS_SUSPEND_MASK;
> >> >> +                     udc->write_fn(udc->base_address, XUSB_IER_OFFSET,
> >> >> +                                     intrreg);
> >> >> +             }
> >> >> +             udc->usb_state = 0;
> >> >> +
> >> >> +             if (udc->driver->resume)
> >> >> +                     udc->driver->resume(&udc->gadget);
> >
> > this is wrong, note that you would call ->resume() *every time*
> > usb_state == SUSPENDED and there's an interrupt. This means that if
> > gadget is suspended and you remove the cable, then you first call
> > ->resume() and then ->disconnect().
> >
> >> Here. calling driver->resume.
> >
> > Here's what I would do:
> >
> > if (intrstatus & XUSB_STATUS_RESUME_MASK) {
> >         bool condition = udc->usb_state != USB_STATE_SUSPENDED;
> >         dev_WARN_ONCE(dev, condition, "Resume IRQ while not suspended\n");
> >
> >         /* Enable the reset and suspend */
> >         intrreg = udc->read_fn(udc->base_address + XUSB_IER_OFFSET);
> >         intrreg |= XUSB_STATUS_RESET_MASK | XUSB_STATUS_SUSPEND_MASK;
> >         udc->write_fn(udc->base_address, XUSB_IER_OFFSET, intrreg);
> >
> >         if (udc->driver->resume)
> >                 udc->driver_resume(&udc->gadget);
> > }
> 
> Resume Interrupt bit is set only when Resume happens by device sending
> Remote wakeup.

so if the host drives resume signalling there will be no interrupt ?
Well, this is wrong :-) The gadget driver needs to know about that too.
The host side can decide to wake you up.

> I am assuming we need to call driver->resume for every
> driver->suspend. Hence I implemented

no you don't, you need to let host wake you up or you drive remote
wakeup on the bus. The thing is: if the bus is suspended, there will be
*no* activity on the bus prior to host driving Resume signal or device
driving Remote Wakeup signal.

Enable RESUME IRQ on probe and never disable it, it'll be a lot easier
to implement it.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2014-04-08 21:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1396510519-8555-1-git-send-email-sbhatta@xilinx.com>
2014-04-03  7:35 ` [PATCH v2 2/2] usb: gadget: Add xilinx axi usb2 device support Subbaraya Sundeep Bhatta
     [not found]   ` <113d0620-4003-417d-806b-0b79ae692829-+Ck8Kgl/v0/RNLY4SpiB+rjjLBE8jN/0@public.gmane.org>
2014-04-03 14:58     ` Felipe Balbi
     [not found]       ` <20140403145853.GD14162-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2014-04-03 15:23         ` Michal Simek
     [not found]           ` <533D7CF0.2000702-pSz03upnqPeHXe+LvDLADg@public.gmane.org>
2014-04-07  9:01             ` sundeep subbaraya
     [not found]       ` <CALHRZupk2ywMNKjzAtCPgg=9-KsDqrVBAKFNoHOoSJOQ4FDJkA@mail.gmail.com>
     [not found]         ` <CALHRZupk2ywMNKjzAtCPgg=9-KsDqrVBAKFNoHOoSJOQ4FDJkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-07  9:06           ` Fwd: " sundeep subbaraya
     [not found]             ` <CALHRZuqtEpK98vTS=RQ+f3yu-L_M1SnZSJOMTaBnDT8z+YqccQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-07 16:35               ` Felipe Balbi
2014-04-08 16:01                 ` sundeep subbaraya
     [not found]                   ` <CALHRZuotnNf-sCaeQJQ_PnSVET=+GvZ_PmvF7E3oEg8bKZ8a2Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-08 21:24                     ` Felipe Balbi [this message]
2014-04-16 10:39       ` sundeep subbaraya
2014-04-16 18:02         ` Felipe Balbi
     [not found]           ` <20140416180228.GK28035-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2014-04-17  9:31             ` sundeep subbaraya
     [not found]               ` <CALHRZuq6=TMryHtbjTw7rYoGwbu2w0BTdxiOA95HYS3_CG6vwQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-17 15:01                 ` Felipe Balbi
2014-04-18 14:04                   ` sundeep subbaraya
2014-04-21 16:08                     ` Felipe Balbi
2014-04-21 16:39                       ` Alan Stern
     [not found]                         ` <Pine.LNX.4.44L0.1404211228190.1201-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-04-22  7:28                           ` sundeep subbaraya
2014-04-22 13:57                             ` Alan Stern
2014-04-22 14:49                             ` Felipe Balbi
     [not found]                               ` <20140422144944.GF5524-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2014-04-23  4:27                                 ` sundeep subbaraya
     [not found]                                   ` <CALHRZuoq32qoh70hbb2LtVJNgkwB1j6bvzmYONmxcn3mBnGONQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-30 16:54                                     ` Felipe Balbi
2014-05-25 17:40                                       ` sundeep subbaraya
2014-07-02 16:46                                         ` Felipe Balbi
     [not found]                                           ` <20140702164629.GI5541-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2014-07-07  6:28                                             ` sundeep subbaraya
     [not found]         ` <CALHRZuoCtEz5-CmU17dUpVS_MjSDdYVLMSvgXq_RwxLj_KJMDA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-04-16 20:08           ` Paul Zimmerman
     [not found]             ` <A2CA0424C0A6F04399FB9E1CD98E03046D18F4A6-Yu2iAY70zvrYN67daEjeMPufCSb+aD3WLzEdoUbNIic@public.gmane.org>
2014-04-17 14:27               ` sundeep subbaraya

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=20140408212421.GA1431@saruman.home \
    --to=balbi-l0cymroini0@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=michals-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=sbhatta-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=subbaraya.sundeep.bhatta-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=sundeep.lkml-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).