RE: iMX8MM USB support?

2020-04-01 Thread Sherry Sun
Hi Igor,

I’m sorry, now I don’t do the jobs about USB any more. Maybe Peng know who can 
help you.

Best regards
Sherry Sun

From: Igor Opaniuk 
Sent: 2020年4月2日 5:35
To: Sherry Sun 
Cc: u-boot ; Fabio Estevam ; Peng Fan 
; thar...@gateworks.com
Subject: Re: iMX8MM USB support?

+ Sherry, as he was working on iMX8* USB support

On Wed, Apr 1, 2020, 20:55 Tim Harvey 
mailto:thar...@gateworks.com>> wrote:
Peng,

It looks like IMX8MM USB support hasn't made it upstream yet. Is this
something your working on?

I'm interested in booting an IMX8MM via SDP.

Best Regards,

Tim


Re: [U-Boot] [PATCH v4 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor

2019-09-16 Thread Sherry Sun
Hi Lukasz,

Ping. Any comments on V4?

Best regards
Sherry Sun

> 
> Because the buffer length of sdp usb request is 65, we have to allocate
> 65 bytes not 64 bytes. Otherwise there is potential buffer overflow.
> 
> So the wMaxPacketSize of fullspeed can't meet the needs. Add HS endpoint
> descriptor for SDP. Then we can use high speed endpoint, and the SDP device
> can send packet with 512 byte size.
> 
> Signed-off-by: Sherry Sun 
> Signed-off-by: Ye Li 
> ---
>  drivers/usb/gadget/f_sdp.c | 37 ++---
>  1 file changed, 34 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index
> 841814bc07..e7daa1a4f5 100644
> --- a/drivers/usb/gadget/f_sdp.c
> +++ b/drivers/usb/gadget/f_sdp.c
> @@ -70,6 +70,11 @@ struct hid_report {
> 
>  #define SDP_COMMAND_LEN  16
> 
> +/* The first data is for report id, the next 64 bytes are the maximum
> +amount
> + * of data we need to send to usb host. So a total of 65 bytes are needed.
> + */
> +#define SDP_USB_REQUEST_BUFLEN   65
> +
>  struct sdp_command {
>   u16 cmd;
>   u32 addr;
> @@ -158,6 +163,16 @@ static struct usb_endpoint_descriptor in_desc = {
>   .bInterval =1,
>  };
> 
> +static struct usb_endpoint_descriptor in_hs_desc = {
> + .bLength =  USB_DT_ENDPOINT_SIZE,
> + .bDescriptorType =  USB_DT_ENDPOINT,
> /*USB_DT_CS_ENDPOINT*/
> +
> + .bEndpointAddress = 1 | USB_DIR_IN,
> + .bmAttributes = USB_ENDPOINT_XFER_INT,
> + .wMaxPacketSize =   512,
> + .bInterval =1,
> +};
> +
>  static struct usb_descriptor_header *sdp_runtime_descs[] = {
>   (struct usb_descriptor_header *)_intf_runtime,
>   (struct usb_descriptor_header *)_hid_desc, @@ -165,6 +180,13
> @@ static struct usb_descriptor_header *sdp_runtime_descs[] = {
>   NULL,
>  };
> 
> +static struct usb_descriptor_header *sdp_runtime_hs_descs[] = {
> + (struct usb_descriptor_header *)_intf_runtime,
> + (struct usb_descriptor_header *)_hid_desc,
> + (struct usb_descriptor_header *)_hs_desc,
> + NULL,
> +};
> +
>  /* This is synchronized with what the SoC implementation reports */  static
> struct hid_report sdp_hid_report = {
>   .usage_page = {
> @@ -490,6 +512,11 @@ static int sdp_bind(struct usb_configuration *c,
> struct usb_function *f)
>   goto error;
>   }
> 
> + if (gadget_is_dualspeed(gadget)) {
> + /* Assume endpoint addresses are the same for both speeds
> */
> + in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress;
> + }
> +
>   sdp->in_ep = ep; /* Store IN EP for enabling @ setup */
> 
>   cdev->req->context = sdp;
> @@ -527,7 +554,7 @@ static struct usb_request *sdp_start_ep(struct
> usb_ep *ep)  {
>   struct usb_request *req;
> 
> - req = alloc_ep_req(ep, 64);
> + req = alloc_ep_req(ep, SDP_USB_REQUEST_BUFLEN);
>   debug("%s: ep:%p req:%p\n", __func__, ep, req);
> 
>   if (!req)
> @@ -542,11 +569,15 @@ static int sdp_set_alt(struct usb_function *f,
> unsigned intf, unsigned alt)  {
>   struct f_sdp *sdp = func_to_sdp(f);
>   struct usb_composite_dev *cdev = f->config->cdev;
> + struct usb_gadget *gadget = cdev->gadget;
>   int result;
> 
>   debug("%s: intf: %d alt: %d\n", __func__, intf, alt);
> 
> - result = usb_ep_enable(sdp->in_ep, _desc);
> + if (gadget_is_dualspeed(gadget) && gadget->speed ==
> USB_SPEED_HIGH)
> + result = usb_ep_enable(sdp->in_ep, _hs_desc);
> + else
> + result = usb_ep_enable(sdp->in_ep, _desc);
>   if (result)
>   return result;
>   sdp->in_req = sdp_start_ep(sdp->in_ep); @@ -592,7 +623,7 @@
> static int sdp_bind_config(struct usb_configuration *c)
>   memset(sdp_func, 0, sizeof(*sdp_func));
> 
>   sdp_func->usb_function.name = "sdp";
> - sdp_func->usb_function.hs_descriptors = sdp_runtime_descs;
> + sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs;
>   sdp_func->usb_function.descriptors = sdp_runtime_descs;
>   sdp_func->usb_function.bind = sdp_bind;
>   sdp_func->usb_function.unbind = sdp_unbind;
> --
> 2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-09-09 Thread Sherry Sun
Hi Jean,

> 
> Hi Sherry,
> 
> On 03/09/2019 14:44, Sherry Sun wrote:
> > Hi Jean,
> >
> >>
> >> On 02/09/2019 13:29, Sherry Sun wrote:
> >>> Hi Vignesh,
> >>>
> >>>> Hi Sherry,
> >>>>
> >>>> [...]
> >>>>>> AFAIK, U-Boot does not support runtime switching of USB port to
> >>>>>> host from device and vice versa. This is the case for existing
> >>>>>> driver like
> >>>> DWC3/MUSB etc.
> >>>>>> Ideally we would need a role switch driver that unbinds and
> >>>>>> rebinds host vs device driver as when required based on U-Boot
> >>>>>> cmd or via an API (if required to be done during SPL stage etc).
> >>>>> I wonder if we can add two subnodes under the wrapper node as
> >>>>> below,
> >>>> one bind to usb gadget driver and another bind to usb host driver.
> >>>>> So if we want to use usb device, just call the gadget driver, and
> >>>>> if want to
> >>>> use usb host, just call the host driver. The driver will probe
> >>>> correspond
> >> node.
> >>>>> I'm not sure if it is feasible, what do you think about it?
> >>>>>
> >>>>> usbss0: cdns_usb@4104000 {
> >>>>> compatible = "ti,j721e-usb";
> >>>>> []
> >>>>> usb0: usb@601 { /* xhci reg address*/
> >>>>> compatible = "cdns,usb3-1.0.1";
> >>>>> dr_mode = "host";
> >>>>> []
> >>>>> }
> >>>>> usb1: usb@602 { /* dev reg address*/
> >>>>> compatible = "cdns,usb3-1.0.1";
> >>>>> dr_mode = "peripheral";
> >>>>> []
> >>>>> }
> >>>>>   }
> >>>>>
> >>>> But this is not how DT would look in kernel. There will be single
> >>>> DT node representing both Host and Device node. DT repesentation
> >>>> should not be changed based on OS/bootloader, its HW description
> >>>> and must
> >> remain same.
> >>>> Unbinding host/gadget driver and rebinding with a different role
> >>>> should not be hard as the U-Boot core infrastructure exists.
> >>>>
> >>>> Moreover if xhci reg and dev reg are separated into different nodes
> >>>> dont we still need access to OTG register block to switch b/w host
> >>>> and
> >> device mode?
> >>> I think we may not need to access OTG register if we add two
> >>> subnodes for
> >> gadget and host.
> >>> But I see a for loop in dwc3_glue_bind() as follows, if there only
> >>> one single
> >> node representing both Host and Device node under usb wrapper node,
> >> why we need this for loop?
> >>> 212 for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node >
> 0;
> >>> 213  node = fdt_next_subnode(fdt, node)) {
> >> I believe this is a legacy from the code it was inspired from.
> >>
> >> Indeed the loop is not required.
> >>
> >> Like Vignesh I think we must stick with the dt-bindings used by the kernel.
> > Thanks for your reply, I understand now.
> >
> >> BTW we are working on the USB3 support right now that is lacking in our
> tree.
> >> I choose to keep the PHY drivers as close as possible to their linux
> >> version. I'll probably start posting preliminary patches this week.
> >>
> >> If you have the USB3 working in the kernel, can you point to a tree
> >> where I can have a look at the drivers and dt-bindings ?
> > Sure, you can see our downstream kernel code at my github, here is the
> link address:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub
> .com%2Fsherrysun1%2Flinux-
> imx.gitdata=02%7C01%7Csherry.sun%40nxp.com%7C368ba21c33c048
> fd137208d735199870%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> C637036256383501199sdata=y4AB0RpG%2F7Skk34yccpkW9TQsDWpi
> 6OJhtlRWid1DM0%3Dreserved=0.
> > And look forward to seeing your patches in uboot maillist.
> 
> It will take some times before I can post on the mailing list because I did 
> the
> work on top TI's u-boot. But you can find th

Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-09-03 Thread Sherry Sun
Hi Jean,

> 
> 
> On 02/09/2019 13:29, Sherry Sun wrote:
> > Hi Vignesh,
> >
> >> Hi Sherry,
> >>
> >> [...]
> >>>> AFAIK, U-Boot does not support runtime switching of USB port to
> >>>> host from device and vice versa. This is the case for existing
> >>>> driver like
> >> DWC3/MUSB etc.
> >>>> Ideally we would need a role switch driver that unbinds and rebinds
> >>>> host vs device driver as when required based on U-Boot cmd or via
> >>>> an API (if required to be done during SPL stage etc).
> >>> I wonder if we can add two subnodes under the wrapper node as below,
> >> one bind to usb gadget driver and another bind to usb host driver.
> >>> So if we want to use usb device, just call the gadget driver, and if
> >>> want to
> >> use usb host, just call the host driver. The driver will probe correspond
> node.
> >>> I'm not sure if it is feasible, what do you think about it?
> >>>
> >>>usbss0: cdns_usb@4104000 {
> >>>compatible = "ti,j721e-usb";
> >>>[]
> >>>usb0: usb@601 {/* xhci reg address*/
> >>>compatible = "cdns,usb3-1.0.1";
> >>>   dr_mode = "host";
> >>>   []
> >>>   }
> >>>usb1: usb@602 {/* dev reg address*/
> >>>compatible = "cdns,usb3-1.0.1";
> >>>   dr_mode = "peripheral";
> >>>   []
> >>>   }
> >>>  }
> >>>
> >> But this is not how DT would look in kernel. There will be single DT
> >> node representing both Host and Device node. DT repesentation should
> >> not be changed based on OS/bootloader, its HW description and must
> remain same.
> >> Unbinding host/gadget driver and rebinding with a different role
> >> should not be hard as the U-Boot core infrastructure exists.
> >>
> >> Moreover if xhci reg and dev reg are separated into different nodes
> >> dont we still need access to OTG register block to switch b/w host and
> device mode?
> > I think we may not need to access OTG register if we add two subnodes for
> gadget and host.
> >
> > But I see a for loop in dwc3_glue_bind() as follows, if there only one 
> > single
> node representing both Host and Device node under usb wrapper node, why
> we need this for loop?
> >
> > 212 for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0;
> > 213  node = fdt_next_subnode(fdt, node)) {
> 
> I believe this is a legacy from the code it was inspired from.
> 
> Indeed the loop is not required.
> 
> Like Vignesh I think we must stick with the dt-bindings used by the kernel.

Thanks for your reply, I understand now. 

> 
> BTW we are working on the USB3 support right now that is lacking in our tree.
> I choose to keep the PHY drivers as close as possible to their linux version. 
> I'll
> probably start posting preliminary patches this week.
> 
> If you have the USB3 working in the kernel, can you point to a tree where I
> can have a look at the drivers and dt-bindings ?

Sure, you can see our downstream kernel code at my github, here is the link 
address: https://github.com/sherrysun1/linux-imx.git.
And look forward to seeing your patches in uboot maillist.

Best regards
Sherry sun

> 
> JJ
> 
> >
> > Best regards
> > Sherry sun
> >
> >> Regards
> >> Vignesh
> >>
> >>> Best regards
> >>> Sherry sun
> >>>
> >>>> Regards
> >>>> Vignesh
> >>>>
> >>>>> Best regards
> >>>>> Sherry sun
> >>>>>
> >>>>>> JJ
> >>>>>>
> >>>>>>>> Then when binding the wrapper node, it will hard-coded the two
> >>>>>> subnodes
> >>>>>>>> to different driver(gadge/host driver) according to the dr_mode
> >>>>>>>> property
> >>>>>> in
> >>>>>>>> nodes.
> >>>>>>>>
> >>>>>>> Do you think I understand it right?
> >>>>>>> Best regards
> >>>>>>> Sherry sun
> >>>>>>>
> >>>>>>>> Best regards
> >>>>>>>> Sherry sun
> >>>>>>>>
> >>>>>>>>> JJ
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>>>>>> + { }
> >>>>>>>>>>>>>>> +};
> >>>>>>>> ___
> >>>>>>>> U-Boot mailing list
> >>>>>>>> U-Boot@lists.denx.de
> >>>>>>>> https://l
> >>>>>>>>
> >>
> ists.ddata=02%7C01%7Csherry.sun%40nxp.com%7C7d1d76a7124f4c3f
> >>>> e9
> >>
> 9d08d72d3ddf82%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63
> >>>> 70276
> >>
> 16080089878sdata=70BPVQkomokcNpxsHRD3njfZQvuG51VSD1QKBjQ
> >>>> o1kA%3
> >>>>>>>> Dreserved=0
> >>>>>>>> enx.de%2Flistinfo%2Fu-
> >>>>>>>>
> >>
> bootdata=02%7C01%7Csherry.sun%40nxp.com%7C35f1d34da1ea4b7
> >>
> 670ba08d72b823e9a%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> >>
> C637025710721487079sdata=Nfk0qWtSViz60wJHAOr2m5tgIwTWjNwI
> >>>>>>>> GrNOxDH6HC0%3Dreserved=0
> >>>> --
> >>>> Regards
> >>>> Vignesh
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-09-02 Thread Sherry Sun
Hi Vignesh,

> 
> Hi Sherry,
> 
> [...]
> >> AFAIK, U-Boot does not support runtime switching of USB port to host
> >> from device and vice versa. This is the case for existing driver like
> DWC3/MUSB etc.
> >>
> >> Ideally we would need a role switch driver that unbinds and rebinds
> >> host vs device driver as when required based on U-Boot cmd or via an
> >> API (if required to be done during SPL stage etc).
> >
> > I wonder if we can add two subnodes under the wrapper node as below,
> one bind to usb gadget driver and another bind to usb host driver.
> > So if we want to use usb device, just call the gadget driver, and if want to
> use usb host, just call the host driver. The driver will probe correspond 
> node.
> > I'm not sure if it is feasible, what do you think about it?
> >
> >   usbss0: cdns_usb@4104000 {
> >   compatible = "ti,j721e-usb";
> >   []
> >   usb0: usb@601 {   /* xhci reg address*/
> >   compatible = "cdns,usb3-1.0.1";
> > dr_mode = "host";
> > []
> > }
> >   usb1: usb@602 {   /* dev reg address*/
> >   compatible = "cdns,usb3-1.0.1";
> > dr_mode = "peripheral";
> > []
> > }
> > }
> >
> 
> But this is not how DT would look in kernel. There will be single DT node
> representing both Host and Device node. DT repesentation should not be
> changed based on OS/bootloader, its HW description and must remain same.
> Unbinding host/gadget driver and rebinding with a different role should not
> be hard as the U-Boot core infrastructure exists.
> 
> Moreover if xhci reg and dev reg are separated into different nodes dont we
> still need access to OTG register block to switch b/w host and device mode?

I think we may not need to access OTG register if we add two subnodes for 
gadget and host.

But I see a for loop in dwc3_glue_bind() as follows, if there only one single 
node representing both Host and Device node under usb wrapper node, why we need 
this for loop?

212 for (node = fdt_first_subnode(fdt, dev_of_offset(parent)); node > 0;
213  node = fdt_next_subnode(fdt, node)) {

Best regards
Sherry sun

> 
> Regards
> Vignesh
> 
> > Best regards
> > Sherry sun
> >
> >>
> >> Regards
> >> Vignesh
> >>
> >>> Best regards
> >>> Sherry sun
> >>>
> >>>>
> >>>> JJ
> >>>>
> >>>>>> Then when binding the wrapper node, it will hard-coded the two
> >>>> subnodes
> >>>>>> to different driver(gadge/host driver) according to the dr_mode
> >>>>>> property
> >>>> in
> >>>>>> nodes.
> >>>>>>
> >>>>> Do you think I understand it right?
> >>>>
> >>>>>
> >>>>> Best regards
> >>>>> Sherry sun
> >>>>>
> >>>>>> Best regards
> >>>>>> Sherry sun
> >>>>>>
> >>>>>>> JJ
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>>>>>>> +   { }
> >>>>>>>>>>>>> +};
> >>>>>> ___
> >>>>>> U-Boot mailing list
> >>>>>> U-Boot@lists.denx.de
> >>>>>> https://l
> >>>>>>
> >>
> ists.ddata=02%7C01%7Csherry.sun%40nxp.com%7C7d1d76a7124f4c3f
> >> e9
> >>>>>>
> >>
> 9d08d72d3ddf82%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63
> >> 70276
> >>>>>>
> >>
> 16080089878sdata=70BPVQkomokcNpxsHRD3njfZQvuG51VSD1QKBjQ
> >> o1kA%3
> >>>>>> Dreserved=0
> >>>>>> enx.de%2Flistinfo%2Fu-
> >>>>>>
> >>>>
> >>
> bootdata=02%7C01%7Csherry.sun%40nxp.com%7C35f1d34da1ea4b7
> >>>>>>
> >>>>
> >>
> 670ba08d72b823e9a%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> >>>>>>
> >>>>
> >>
> C637025710721487079sdata=Nfk0qWtSViz60wJHAOr2m5tgIwTWjNwI
> >>>>>> GrNOxDH6HC0%3Dreserved=0
> >>
> >> --
> >> Regards
> >> Vignesh
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-30 Thread Sherry Sun
Hi Vignesh,

> 
> 
> 
> On 30/08/19 3:36 PM, Sherry Sun wrote:
> > Hi Jean,
> >
> >>
> >>
> >> On 28/08/2019 13:50, Sherry Sun wrote:
> >>> Hi Jean,
> >>>
> >>>> Hi Jean,
> >>>>
> >>>>> Hi Marek, Sherry,
> >>>>>
> >>>>>
> >>>>>>>>> we keep the cdns3 node for usb gadget driver, then add a usb
> >>>>>>>>> host node for
> >>>>>>>>> xhci-imx8 driver in *-uboot.dtsi. so here is no need to change
> >>>>>>>>> the host driver
> >>>>>>>> compatible.
> >>>>>>>>> But the compatible in gadget driver should be changed later.
> >>>>>>>> We should try avoiding ABI breaks in DT.
> >>>>>>> But the cdns3 usb gaget driver and host driver in different
> >>>>>>> uclass need two
> >>>>> dt nodes to bind with.
> >>>>>>> And the compatible of the two node cannot be same.
> >>>>>>> So for gadget driver, the compatible may use "cdns,usb3-1.0.0",
> >>>>>>> for host
> >>>>> driver, the compatible will use "cdns,usb3-1.0.0-host".
> >>>>>>> What do you think about it?
> >>>>>> CCing Jean, since I think he did solve similar topic for his platform.
> >>>>> I've been OOO for a few weeks and didn't look at the whole series.
> >>>>>
> >>>>> For this particular issue, the solution I used is to let the
> >>>>> wrapper do the binding job. The name of the driver to use is
> >>>>> hard-coded in the
> >>>> wrapper diver.
> >>>>> This is done in dwc3_glue_bind().
> >>>> Thanks for your suggestions.
> >>>>
> >>>> So if I want to use the cdns3 usb node as both usb gadget device
> >>>> and usb host device, do you mean that I should make the cdns3 usb
> >>>> node as a usb wrapper device, and create two subnodes in it.
> >>
> >> I think we should not change the binding to adapt to out driver but
> >> keep the bindings that exist in linux and adapt the u-boot driver
> >>
> >> In the version used by our platform, there is a wrapper around the USB:
> >>
> >>      usbss0: cdns_usb@4104000 {
> >>          compatible = "ti,j721e-usb";
> >>      []
> >>          usb0: usb@600 {
> >>              compatible = "cdns,usb3-1.0.1";
> >>
> >> The driver selection (host or device) could be done by the wrapper
> >> when it binds its children (same as the dwc3).
> >>
> >> OR
> >>
> >> The "cdns,usb3-1.0.1" could be a dumb driver the role of which would
> >> be only to bind a new driver (host or device) based on "dr_mode". The
> >> binding could be done using the same node, it doesn't have to be a
> subnode.
> >>
> >>
> >> Maybe the second solution will be better, as it would work for
> >> platforms that do not use a wrapper.
> >>
> >
> > I just communicated with Vignesh Raghavendra , and he
> suggest that I should keep this cdns3 driver under Linux kernel and U-Boot in
> sync. And show me your downstream code with v10  of Cadence USB3 kernel
> driver ported to U-Boot. So I decide to follow your way to deal with this 
> issue.
> >
> > But I want to ask another question:
> > The two solutions you gave before both make the usb node with
> compatible "cdns,usb3-1.0.1" as a definite device (host or gadget) by its
> dr_mode property. If I want use this usb device works as both host and
> gadget driver, which means I want to change its status runtime, such as I
> want to use this usb device to run both fastboot or usb start command, how
> can we deal with this?  .
> >
> 
> AFAIK, U-Boot does not support runtime switching of USB port to host from
> device and vice versa. This is the case for existing driver like DWC3/MUSB 
> etc.
> 
> Ideally we would need a role switch driver that unbinds and rebinds host vs
> device driver as when required based on U-Boot cmd or via an API (if
> required to be done during SPL stage etc).

I wonder if we can add two subnodes under the wrapper node as below, one bind 
to usb gadget driver and another bind to usb host driver.
So if we want to use usb device, just call the gadget driver, and if want to 

Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-30 Thread Sherry Sun
Hi Jean,

> 
> 
> On 28/08/2019 13:50, Sherry Sun wrote:
> > Hi Jean,
> >
> >> Hi Jean,
> >>
> >>> Hi Marek, Sherry,
> >>>
> >>>
> >>>>>>> we keep the cdns3 node for usb gadget driver, then add a usb
> >>>>>>> host node for
> >>>>>>> xhci-imx8 driver in *-uboot.dtsi. so here is no need to change
> >>>>>>> the host driver
> >>>>>> compatible.
> >>>>>>> But the compatible in gadget driver should be changed later.
> >>>>>> We should try avoiding ABI breaks in DT.
> >>>>> But the cdns3 usb gaget driver and host driver in different uclass
> >>>>> need two
> >>> dt nodes to bind with.
> >>>>> And the compatible of the two node cannot be same.
> >>>>> So for gadget driver, the compatible may use "cdns,usb3-1.0.0",
> >>>>> for host
> >>> driver, the compatible will use "cdns,usb3-1.0.0-host".
> >>>>> What do you think about it?
> >>>> CCing Jean, since I think he did solve similar topic for his platform.
> >>> I've been OOO for a few weeks and didn't look at the whole series.
> >>>
> >>> For this particular issue, the solution I used is to let the wrapper
> >>> do the binding job. The name of the driver to use is hard-coded in
> >>> the
> >> wrapper diver.
> >>> This is done in dwc3_glue_bind().
> >> Thanks for your suggestions.
> >>
> >> So if I want to use the cdns3 usb node as both usb gadget device and
> >> usb host device, do you mean that I should make the cdns3 usb node as
> >> a usb wrapper device, and create two subnodes in it.
> 
> I think we should not change the binding to adapt to out driver but keep the
> bindings that exist in linux and adapt the u-boot driver
> 
> In the version used by our platform, there is a wrapper around the USB:
> 
>      usbss0: cdns_usb@4104000 {
>          compatible = "ti,j721e-usb";
>      []
>          usb0: usb@600 {
>              compatible = "cdns,usb3-1.0.1";
> 
> The driver selection (host or device) could be done by the wrapper when it
> binds its children (same as the dwc3).
> 
> OR
> 
> The "cdns,usb3-1.0.1" could be a dumb driver the role of which would be
> only to bind a new driver (host or device) based on "dr_mode". The binding
> could be done using the same node, it doesn't have to be a subnode.
> 
> 
> Maybe the second solution will be better, as it would work for platforms that
> do not use a wrapper.
> 

I just communicated with Vignesh Raghavendra , and he suggest 
that I should keep this cdns3 driver under Linux kernel and U-Boot in sync. And 
show me your downstream code with v10  of Cadence USB3 kernel driver ported to 
U-Boot. So I decide to follow your way to deal with this issue.

But I want to ask another question: 
The two solutions you gave before both make the usb node with compatible 
"cdns,usb3-1.0.1" as a definite device (host or gadget) by its dr_mode 
property. If I want use this usb device works as both host and gadget driver, 
which means I want to change its status runtime, such as I want to use this usb 
device to run both fastboot or usb start command, how can we deal with this?  .

Best regards
Sherry sun

> 
> JJ
> 
> >> Then when binding the wrapper node, it will hard-coded the two
> subnodes
> >> to different driver(gadge/host driver) according to the dr_mode property
> in
> >> nodes.
> >>
> > Do you think I understand it right?
> 
> >
> > Best regards
> > Sherry sun
> >
> >> Best regards
> >> Sherry sun
> >>
> >>> JJ
> >>>
> >>>
> >>>
> >>>>>>>>> +   { }
> >>>>>>>>> +};
> >> ___
> >> U-Boot mailing list
> >> U-Boot@lists.denx.de
> >> https://lists.d
> >> enx.de%2Flistinfo%2Fu-
> >>
> bootdata=02%7C01%7Csherry.sun%40nxp.com%7C35f1d34da1ea4b7
> >>
> 670ba08d72b823e9a%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> >>
> C637025710721487079sdata=Nfk0qWtSViz60wJHAOr2m5tgIwTWjNwI
> >> GrNOxDH6HC0%3Dreserved=0
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 0/7] usb: Add cadence USB3 gadget/host/phy driver

2019-08-30 Thread Sherry Sun
Hi Vignesh,

> 
> Hi,
> 
> On 28/08/19 7:52 PM, Sherry Sun wrote:
> > Hi Vignesh,
> [...]
> >> I see that Cadence USB driver for Linux kernel is still under
> >> development and DT compatible binding is supposed to be "cdns,usb3"
> not "cdns,usb3-1.0.0".
> >> See v11:
> >> https://patch
> >>
> work.kernel.org%2Fpatch%2F4415%2Fdata=02%7C01%7Csherry.s
> >>
> un%40nxp.com%7C97d431d6b569451ff8ac08d72bb5f883%7C686ea1d3bc2b
> >>
> 4c6fa92cd99c5c301635%7C0%7C0%7C637025932942549390sdata=Jltlk
> >> Te7SXTAQAKtF7HzOqY291upS67Eixeke9oXQ2w%3Dreserved=0
> >> Deviating from kernel binding will break sync'ing of DTs b/w kernel
> >> and U- Boot.
> >>
> >
> > Thanks for your reminder, I only noticed the DT compatible in v5 last time.
> So I will change it to "cdns,usb3" in next version.
> >
> >> Also, why not sync the latest host/gadget driver patches from kernel as is?
> >> That should help in borrowing bug fixes/features whenever Cadence
> >> updates kernel driver in future.
> >
> > Since there are many differences between the cdns3 driver in uboot and
> > kernel, such as in uboot, we didn't support host mode in cdns3 core.c,
> > instead we add an
> > xhci-imx8 driver as host driver. So the patches from kernel can't be applied
> to this driver.
> >
> 
> I see that xhci-imx8.c is generic enough to be used with v11 upstream
> cdns3/core.c and cdns3/host.c once IMX specific stuff is moved to top level
> wrapper.
> 
> I see you use a separate compatible for host driver which does not match
> with kernel (as there is no separate node for host vs device). Moreover the dt
> bindings listed in patch 1/7 lists non core registers as part of Cadence USB3
> controller node.
> 
> Above issues make it impossible to sync Kernel DT nodes with U-Boot DT
> nodes which is not acceptable for U-Boot. All non Cadence core registers and
> configurations need to part of a separate wrapper driver that then binds to
> appropriate host/device Cadence USB3 controller node based on dr_mode
> property. E.g: see who dwc3 is modeled [3]:
> Also see cdns-ti.c in the TI U-Boot branch [1] [2])
> 
> If there are more customization required for host driver cdns3/host.c we can
> provide vendor specific hooks/callbacks to be called from cdns3/host.c
> Current series is not usable on TI platform with Cadence USB3 IP at least in
> host mode and would need core host driver to be ported from kernel.
> 
> Keeping Linux kernel and U-Boot driver stack in sync has a big advantage for
> you as well. It simplifies borrowing bug fixes and new features or functions
> (especially in subsystems like USB where code is pretty large)
> 
> BTW, I have a tree with v10  of Cadence USB3 kernel driver ported to U-Boot
> here[1]. It is based on 2019.01 U-Boot but should apply as is on the latest
> tree as well. (Tree is still missing USB3 PHY support and thus USB 3.0 
> support)
> and works on TI platform. I am waiting for bindings to be frozen in Linux
> before posting to U-Boot list.
> 
> Hopefully we can find a way to collaborate!

I think your suggestions are reasonable, I agree that keep Linux kernel and 
U-Boot driver stack in sync is a good choice!
So I will try to test your code[1] on i.MX8 platform later, if the common core 
part can work well, maybe you can post it to U-Boot list after the Linux cdns3 
driver version is frozen.

Best regards
Sherry sun

> 
> [1] git://git.ti.com/~vigneshr/ti-u-boot/vigneshr-ti-u-boot.git
> branch: dfu
> [2]
> https://eur01.safelinks.protection.outlook.com/?url=http:%2F%2Fgit.ti.com%
> 2Fcgit%2Fcgit.cgi%2F~vigneshr%2Fti-u-boot%2Fvigneshr-ti-u-
> boot.git%2Ftree%2Farch%2Farm%2Fdts%2Fk3-j721e-
> main.dtsi%3Fh%3Ddfu%23n430data=02%7C01%7Csherry.sun%40nxp.
> com%7C25c139bf8e6c4d6575ab08d72c996ba4%7C686ea1d3bc2b4c6fa92cd9
> 9c5c301635%7C0%7C0%7C637026909770138936sdata=lj44%2BFC0AKi
> cD%2BY81zHKhUl23DzxY4b%2Fu9fGstr3nOI%3Dreserved=0
> [3]
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.
> bootlin.com%2Fu-
> boot%2Flatest%2Fsource%2Fdrivers%2Fusb%2Fdwc3%2Fdwc3-
> generic.cdata=02%7C01%7Csherry.sun%40nxp.com%7C25c139bf8e6c
> 4d6575ab08d72c996ba4%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> %7C637026909770138936sdata=mGur%2FVZFiUef5tblBuVPh3i86FQpe
> yunPg15m%2Bwh1mk%3Dreserved=0
> 
> 
> 
> --
> Regards
> Vignesh
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 0/7] usb: Add cadence USB3 gadget/host/phy driver

2019-08-28 Thread Sherry Sun
Hi Vignesh,

> 
> Hi Sherry,
> 
> On 21/08/19 8:05 PM, Sherry Sun wrote:
> > These patches introduce new Cadence driver to U-Boot.
> > The first patch is to add the Cadence USB3 IP(CDNS3) core and driver
> > for the usb gadget.
> > The second patch introduce the xhci-imx8 usb host driver separately.
> > The third patch introduce the cdns3 phy driver which can be used for
> > both
> > cdns3 host driver and gadget driver.
> > The cdns3 usb gadget/host/phy driver are all used DM mode.
> >
> > The current driver has been validated on i.MX8 platform.
> > If someone want to test it, please note that the additional dts nodes/
> > config macros/clock driver are also essential. You can also get my
> > test patches at
> >
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub
> .com%2Fsherrysun1%2Fu-boot-
> imx.gitdata=02%7C01%7Csherry.sun%40nxp.com%7C97d431d6b5694
> 51ff8ac08d72bb5f883%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%
> 7C637025932942549390sdata=XEFSCN0TtgU1H1zhNAgZeZIRgDInL%2B
> 2Gb8ec3KO4AsI%3Dreserved=0 to start your test quickly.
> >
> 
> I see that Cadence USB driver for Linux kernel is still under development and
> DT compatible binding is supposed to be "cdns,usb3" not "cdns,usb3-1.0.0".
> See v11:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
> work.kernel.org%2Fpatch%2F4415%2Fdata=02%7C01%7Csherry.s
> un%40nxp.com%7C97d431d6b569451ff8ac08d72bb5f883%7C686ea1d3bc2b
> 4c6fa92cd99c5c301635%7C0%7C0%7C637025932942549390sdata=Jltlk
> Te7SXTAQAKtF7HzOqY291upS67Eixeke9oXQ2w%3Dreserved=0
> Deviating from kernel binding will break sync'ing of DTs b/w kernel and U-
> Boot.
> 

Thanks for your reminder, I only noticed the DT compatible in v5 last time. So 
I will change it to "cdns,usb3" in next version.

> Also, why not sync the latest host/gadget driver patches from kernel as is?
> That should help in borrowing bug fixes/features whenever Cadence updates
> kernel driver in future.

Since there are many differences between the cdns3 driver in uboot and kernel, 
such as in uboot, we didn't support host mode in cdns3 core.c, instead we add 
an 
xhci-imx8 driver as host driver. So the patches from kernel can't be applied  
to this driver.

> 
> BTW, have you tested gadget driver with functions that use bulk endpoints
> such as f_mass_storage or f_fastboot?

Yes, I have tested the ums and fastboot function already, and it has proved to 
work well on i.MX8 platform.

Best regards
Sherry sun

> 
> Regards
> Vignesh
> 
> > Changes in v5:
> >  - Delete some unnecessary code.
> >  - Fix some issues about lack of parentheses.
> >  - Add separate patch for core framework changes.
> >  - Add "reg-names" for usb nodes in DT and use it to get reg  values.
> >  - Use "cdns,usb3-1.0.0" compatible instead "cdns,usb3".
> >  - Add DM_FLAG_OS_PREPARE flag to xhci-imx8 driver.
> >
> > Sherry Sun (7):
> >   dt-bindings: add dt-binding doc for CDNS3 controller
> >   usb: gadget: Add the cadence USB3 gadget driver
> >   usb: gadget: Add match_ep call back to usb_gadget_ops
> >   usb: gadget: Add gadget_is_cdns3 checking to provide bcdUSB value
> >   usb: host: Add the USB3 host driver
> >   phy: Add USB PHY driver for the cadence USB3
> >   usb: gadget: core: introduce ->udc_set_speed() method
> >
> >  Makefile   |1 +
> >  doc/device-tree-bindings/usb/cdns-usb3.txt |   53 +
> >  drivers/phy/Kconfig|8 +
> >  drivers/phy/Makefile   |1 +
> >  drivers/phy/cdns3-usb-phy.c|  241 +++
> >  drivers/usb/Kconfig|2 +
> >  drivers/usb/cdns3/Kconfig  |   20 +
> >  drivers/usb/cdns3/Makefile |5 +
> >  drivers/usb/cdns3/cdns3-generic.c  |  114 +
> >  drivers/usb/cdns3/cdns3-nxp-reg-def.h  |   93 +
> >  drivers/usb/cdns3/core.c   |  203 ++
> >  drivers/usb/cdns3/core.h   |  118 ++
> >  drivers/usb/cdns3/dev-regs-macro.h |  116 ++
> >  drivers/usb/cdns3/dev-regs-map.h   |  117 ++
> >  drivers/usb/cdns3/gadget-export.h  |   26 +
> >  drivers/usb/cdns3/gadget.c | 2183 
> >  drivers/usb/cdns3/gadget.h |  225 ++
> >  drivers/usb/cdns3/io.h |   27 +
> >  drivers/usb/gadget/epautoconf.c|4 +
> >  drivers/usb/gadget/gadget_chips.h  |7 +
> >  drivers/usb/gadget/udc/Makefile|1 +
> > 

Re: [U-Boot] [PATCH v5 6/7] phy: Add USB PHY driver for the cadence USB3

2019-08-28 Thread Sherry Sun
Hi Jean,

> 
> +Kishon who worked on this PHY under linux
> 
> 
> Hi Sherry,
> 
> 
> On 28/08/2019 10:05, Sherry Sun wrote:
> > Hi Jean,
> >
> >> Hi Sherry,
> >>
> >> On 21/08/2019 16:36, Sherry Sun wrote:
> >>> The cdns3-usb-phy driver supports both host and peripheral mode of
> >>> usb driver which use cadence usb3 IP.
> >>>
> >>> Signed-off-by: Sherry Sun 
> >>> ---
> >>>drivers/phy/Kconfig |   8 ++
> >>>drivers/phy/Makefile|   1 +
> >>>drivers/phy/cdns3-usb-phy.c | 241
> >> 
> >>>3 files changed, 250 insertions(+)
> >>>create mode 100644 drivers/phy/cdns3-usb-phy.c
> >>>
> >>> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index
> >>> 3942f035eb..1837b32c31 100644
> >>> --- a/drivers/phy/Kconfig
> >>> +++ b/drivers/phy/Kconfig
> >>> @@ -205,4 +205,12 @@ config MT76X8_USB_PHY
> >>>
> >>> This PHY is found on MT76x8 devices supporting USB.
> >>>
> >>> +config CDNS3_USB_PHY
> >>> + bool "Support CDNS3 USB PHY"
> >>> + depends on PHY
> >>> + help
> >>> +   Support for the USB PHY in CDNS3 IP.
> >>> +
> >>> +   This PHY is found on CDNS3 IP devices supporting USB.
> >>> +
> >>>endmenu
> >>> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index
> >>> 3157f1b7ee..0e062214d3 100644
> >>> --- a/drivers/phy/Makefile
> >>> +++ b/drivers/phy/Makefile
> >>> @@ -22,4 +22,5 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-
> >> usbh-phy.o
> >>>obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
> >>>obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
> >>>obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
> >>> +obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
> >>>obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o diff --git
> >>> a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c new file
> >>> mode 100644 index 00..c0d308075b
> >>> --- /dev/null
> >>> +++ b/drivers/phy/cdns3-usb-phy.c
> >>> @@ -0,0 +1,241 @@
> >>> +// SPDX-License-Identifier: GPL-2.0+
> >>> +/*
> >>> + * Copyright 2019 NXP
> >>> + *
> >>> + * Cadence3 USB PHY driver
> >>> + *
> >>> + * Author: Sherry Sun   */
> >>> +
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +
> >>> +/* PHY registers */
> >>> +#define PHY_PMA_CMN_CTRL1(0xC800 * 4)
> >>> +#define TB_ADDR_CMN_DIAG_HSCLK_SEL   (0x01e0 * 4)
> >>> +#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR (0x0084 * 4)
> >>> +#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR (0x0085 * 4)
> >>> +#define TB_ADDR_CMN_PLL0_INTDIV  (0x0094 * 4)
> >>> +#define TB_ADDR_CMN_PLL0_FRACDIV (0x0095 * 4)
> >>> +#define TB_ADDR_CMN_PLL0_HIGH_THR(0x0096 * 4)
> >>> +#define TB_ADDR_CMN_PLL0_SS_CTRL1(0x0098 * 4)
> >>> +#define TB_ADDR_CMN_PLL0_SS_CTRL2(0x0099 * 4)
> >>> +#define TB_ADDR_CMN_PLL0_DSM_DIAG(0x0097 * 4)
> >>> +#define TB_ADDR_CMN_DIAG_PLL0_OVRD   (0x01c2 * 4)
> >>> +#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD   (0x01c0 * 4)
> >>> +#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD   (0x01c1 * 4)
> >>> +#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE  (0x01C5 * 4)
> >>> +#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE   (0x01C6 * 4)
> >>> +#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG   (0x01C7 * 4)
> >>> +#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE  (0x01c4 * 4)
> >>> +#define TB_ADDR_CMN_PSM_CLK_CTRL (0x0061 * 4)
> >>> +#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR(0x40ea * 4)
> >>> +#define TB_ADDR_XCVR_PSM_RCTRL   (0x4001 * 4)
> >>> +#define TB_ADDR_TX_PSC_A0(0x4100 * 4)
> >>> +#define TB_ADDR_TX_PSC_A1(0x4101 * 4)
> >>> +#define TB_ADDR_TX_PSC_A2(0x4102 * 4)
> >>> +#define TB_ADDR_TX_PSC_A3(0x4103 * 4)
> >>> +#define TB_ADDR_

Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-28 Thread Sherry Sun
Hi Jean,

> 
> Hi Jean,
> 
> >
> > Hi Marek, Sherry,
> >
> >
> > >>>> we keep the cdns3 node for usb gadget driver, then add a usb host
> > >>>> node for
> > >>>> xhci-imx8 driver in *-uboot.dtsi. so here is no need to change
> > >>>> the host driver
> > >>> compatible.
> > >>>> But the compatible in gadget driver should be changed later.
> > >>> We should try avoiding ABI breaks in DT.
> > >> But the cdns3 usb gaget driver and host driver in different uclass
> > >> need two
> > dt nodes to bind with.
> > >> And the compatible of the two node cannot be same.
> > >> So for gadget driver, the compatible may use "cdns,usb3-1.0.0", for
> > >> host
> > driver, the compatible will use "cdns,usb3-1.0.0-host".
> > >> What do you think about it?
> > > CCing Jean, since I think he did solve similar topic for his platform.
> >
> > I've been OOO for a few weeks and didn't look at the whole series.
> >
> > For this particular issue, the solution I used is to let the wrapper
> > do the binding job. The name of the driver to use is hard-coded in the
> wrapper diver.
> >
> > This is done in dwc3_glue_bind().
> 
> Thanks for your suggestions.
> 
> So if I want to use the cdns3 usb node as both usb gadget device and usb
> host device, do you mean that I should make the cdns3 usb node as a usb
> wrapper device, and create two subnodes in it.
> Then when binding the wrapper node, it will hard-coded the two subnodes
> to different driver(gadge/host driver) according to the dr_mode property in
> nodes.
> 

Do you think I understand it right?

Best regards
Sherry sun

> Best regards
> Sherry sun
> 
> >
> > JJ
> >
> >
> >
> > >
> > >>>>>> +{ }
> > >>>>>> +};
> > >
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.d
> enx.de%2Flistinfo%2Fu-
> bootdata=02%7C01%7Csherry.sun%40nxp.com%7C35f1d34da1ea4b7
> 670ba08d72b823e9a%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> C637025710721487079sdata=Nfk0qWtSViz60wJHAOr2m5tgIwTWjNwI
> GrNOxDH6HC0%3Dreserved=0
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5 6/7] phy: Add USB PHY driver for the cadence USB3

2019-08-28 Thread Sherry Sun
Hi Jean,

> 
> Hi Sherry,
> 
> On 21/08/2019 16:36, Sherry Sun wrote:
> > The cdns3-usb-phy driver supports both host and peripheral mode of usb
> > driver which use cadence usb3 IP.
> >
> > Signed-off-by: Sherry Sun 
> > ---
> >   drivers/phy/Kconfig |   8 ++
> >   drivers/phy/Makefile|   1 +
> >   drivers/phy/cdns3-usb-phy.c | 241
> 
> >   3 files changed, 250 insertions(+)
> >   create mode 100644 drivers/phy/cdns3-usb-phy.c
> >
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index
> > 3942f035eb..1837b32c31 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -205,4 +205,12 @@ config MT76X8_USB_PHY
> >
> >   This PHY is found on MT76x8 devices supporting USB.
> >
> > +config CDNS3_USB_PHY
> > +   bool "Support CDNS3 USB PHY"
> > +   depends on PHY
> > +   help
> > + Support for the USB PHY in CDNS3 IP.
> > +
> > + This PHY is found on CDNS3 IP devices supporting USB.
> > +
> >   endmenu
> > diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index
> > 3157f1b7ee..0e062214d3 100644
> > --- a/drivers/phy/Makefile
> > +++ b/drivers/phy/Makefile
> > @@ -22,4 +22,5 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-
> usbh-phy.o
> >   obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
> >   obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
> >   obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
> > +obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
> >   obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o diff --git
> > a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c new file
> > mode 100644 index 00..c0d308075b
> > --- /dev/null
> > +++ b/drivers/phy/cdns3-usb-phy.c
> > @@ -0,0 +1,241 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright 2019 NXP
> > + *
> > + * Cadence3 USB PHY driver
> > + *
> > + * Author: Sherry Sun   */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/* PHY registers */
> > +#define PHY_PMA_CMN_CTRL1  (0xC800 * 4)
> > +#define TB_ADDR_CMN_DIAG_HSCLK_SEL (0x01e0 * 4)
> > +#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR   (0x0084 * 4)
> > +#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR   (0x0085 * 4)
> > +#define TB_ADDR_CMN_PLL0_INTDIV(0x0094 * 4)
> > +#define TB_ADDR_CMN_PLL0_FRACDIV   (0x0095 * 4)
> > +#define TB_ADDR_CMN_PLL0_HIGH_THR  (0x0096 * 4)
> > +#define TB_ADDR_CMN_PLL0_SS_CTRL1  (0x0098 * 4)
> > +#define TB_ADDR_CMN_PLL0_SS_CTRL2  (0x0099 * 4)
> > +#define TB_ADDR_CMN_PLL0_DSM_DIAG  (0x0097 * 4)
> > +#define TB_ADDR_CMN_DIAG_PLL0_OVRD (0x01c2 * 4)
> > +#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD (0x01c0 * 4)
> > +#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD (0x01c1 * 4)
> > +#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE  (0x01C5 * 4)
> > +#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE   (0x01C6 * 4)
> > +#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG   (0x01C7 * 4)
> > +#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE(0x01c4 * 4)
> > +#define TB_ADDR_CMN_PSM_CLK_CTRL   (0x0061 * 4)
> > +#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR  (0x40ea * 4)
> > +#define TB_ADDR_XCVR_PSM_RCTRL (0x4001 * 4)
> > +#define TB_ADDR_TX_PSC_A0  (0x4100 * 4)
> > +#define TB_ADDR_TX_PSC_A1  (0x4101 * 4)
> > +#define TB_ADDR_TX_PSC_A2  (0x4102 * 4)
> > +#define TB_ADDR_TX_PSC_A3  (0x4103 * 4)
> > +#define TB_ADDR_TX_DIAG_ECTRL_OVRD (0x41f5 * 4)
> > +#define TB_ADDR_TX_PSC_CAL (0x4106 * 4)
> > +#define TB_ADDR_TX_PSC_RDY (0x4107 * 4)
> > +#define TB_ADDR_RX_PSC_A0  (0x8000 * 4)
> > +#define TB_ADDR_RX_PSC_A1  (0x8001 * 4)
> > +#define TB_ADDR_RX_PSC_A2  (0x8002 * 4)
> > +#define TB_ADDR_RX_PSC_A3  (0x8003 * 4)
> > +#define TB_ADDR_RX_PSC_CAL (0x8006 * 4)
> > +#define TB_ADDR_RX_PSC_RDY (0x8007 * 4)
> > +#define TB_ADDR_TX_TXCC_MGNLS_MULT_000 (0x4058 * 4)
> > +#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY (0x41e7 * 4)
> > +#define TB_ADDR_RX_SLC_CU_ITER_TMR (0x80e3 * 4)
> > +#define TB_ADDR_RX_SIGDET_HL_FILT_TMR  (0x8090 * 4)
> > +#define TB_ADDR_RX_SAMP_DAC_CTRL   (0x8058 * 4)

Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-28 Thread Sherry Sun
Hi Jean,

>
> Hi Marek, Sherry,
> 
> 
> >>>> we keep the cdns3 node for usb gadget driver, then add a usb host
> >>>> node for
> >>>> xhci-imx8 driver in *-uboot.dtsi. so here is no need to change the
> >>>> host driver
> >>> compatible.
> >>>> But the compatible in gadget driver should be changed later.
> >>> We should try avoiding ABI breaks in DT.
> >> But the cdns3 usb gaget driver and host driver in different uclass need two
> dt nodes to bind with.
> >> And the compatible of the two node cannot be same.
> >> So for gadget driver, the compatible may use "cdns,usb3-1.0.0", for host
> driver, the compatible will use "cdns,usb3-1.0.0-host".
> >> What do you think about it?
> > CCing Jean, since I think he did solve similar topic for his platform.
> 
> I've been OOO for a few weeks and didn't look at the whole series.
> 
> For this particular issue, the solution I used is to let the wrapper do the
> binding job. The name of the driver to use is hard-coded in the wrapper diver.
> 
> This is done in dwc3_glue_bind().

Thanks for your suggestions.

So if I want to use the cdns3 usb node as both usb gadget device and usb host 
device,
do you mean that I should make the cdns3 usb node as a usb wrapper device, and 
create two subnodes in it.
Then when binding the wrapper node, it will hard-coded the two subnodes to 
different driver(gadge/host driver) 
according to the dr_mode property in nodes.

Best regards 
Sherry sun

> 
> JJ
> 
> 
> 
> >
> >>>>>> +  { }
> >>>>>> +};
> >
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 2/4] SDP: use CONFIG_SDP_LOADADDR as default load address

2019-08-26 Thread Sherry Sun
If SDP_WRITE and SDP_JUMP command addr is zero, use CONFIG_SDP_LOADADDR
as default address.

Signed-off-by: Sherry Sun 
Signed-off-by: Frank Li 
Reviewed-by: Lukasz Majewski 
---
 drivers/usb/gadget/Kconfig | 4 
 drivers/usb/gadget/f_sdp.c | 6 --
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 26b4d12a09..172a82195b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -115,6 +115,10 @@ config USB_GADGET_VBUS_DRAW
   This value will be used except for system-specific gadget
   drivers that have more specific information.
 
+config SDP_LOADADDR
+   hex "Default load address at SDP_WRITE and SDP_JUMP"
+   default 0
+
 # Selected by UDC drivers that support high-speed operation.
 config USB_GADGET_DUALSPEED
bool
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index bcd1c5d47c..841814bc07 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -276,7 +276,8 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
sdp->error_status = SDP_WRITE_FILE_COMPLETE;
 
sdp->state = SDP_STATE_RX_FILE_DATA;
-   sdp->dnl_address = be32_to_cpu(cmd->addr);
+   sdp->dnl_address = cmd->addr ? be32_to_cpu(cmd->addr) :
+  CONFIG_SDP_LOADADDR;
sdp->dnl_bytes_remaining = be32_to_cpu(cmd->cnt);
sdp->dnl_bytes = sdp->dnl_bytes_remaining;
sdp->next_state = SDP_STATE_IDLE;
@@ -304,7 +305,8 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
sdp->always_send_status = false;
sdp->error_status = 0;
 
-   sdp->jmp_address = be32_to_cpu(cmd->addr);
+   sdp->jmp_address = cmd->addr ? be32_to_cpu(cmd->addr) :
+  CONFIG_SDP_LOADADDR;
sdp->state = SDP_STATE_TX_SEC_CONF;
sdp->next_state = SDP_STATE_JUMP;
break;
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor

2019-08-26 Thread Sherry Sun
Because the buffer length of sdp usb request is 65, we have to allocate
65 bytes not 64 bytes. Otherwise there is potential buffer overflow.

So the wMaxPacketSize of fullspeed can't meet the needs. Add HS
endpoint descriptor for SDP. Then we can use high speed endpoint,
and the SDP device can send packet with 512 byte size.

Signed-off-by: Sherry Sun 
Signed-off-by: Ye Li 
---
 drivers/usb/gadget/f_sdp.c | 37 ++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index 841814bc07..e7daa1a4f5 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -70,6 +70,11 @@ struct hid_report {
 
 #define SDP_COMMAND_LEN16
 
+/* The first data is for report id, the next 64 bytes are the maximum amount
+ * of data we need to send to usb host. So a total of 65 bytes are needed.
+ */
+#define SDP_USB_REQUEST_BUFLEN 65
+
 struct sdp_command {
u16 cmd;
u32 addr;
@@ -158,6 +163,16 @@ static struct usb_endpoint_descriptor in_desc = {
.bInterval =1,
 };
 
+static struct usb_endpoint_descriptor in_hs_desc = {
+   .bLength =  USB_DT_ENDPOINT_SIZE,
+   .bDescriptorType =  USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/
+
+   .bEndpointAddress = 1 | USB_DIR_IN,
+   .bmAttributes = USB_ENDPOINT_XFER_INT,
+   .wMaxPacketSize =   512,
+   .bInterval =1,
+};
+
 static struct usb_descriptor_header *sdp_runtime_descs[] = {
(struct usb_descriptor_header *)_intf_runtime,
(struct usb_descriptor_header *)_hid_desc,
@@ -165,6 +180,13 @@ static struct usb_descriptor_header *sdp_runtime_descs[] = 
{
NULL,
 };
 
+static struct usb_descriptor_header *sdp_runtime_hs_descs[] = {
+   (struct usb_descriptor_header *)_intf_runtime,
+   (struct usb_descriptor_header *)_hid_desc,
+   (struct usb_descriptor_header *)_hs_desc,
+   NULL,
+};
+
 /* This is synchronized with what the SoC implementation reports */
 static struct hid_report sdp_hid_report = {
.usage_page = {
@@ -490,6 +512,11 @@ static int sdp_bind(struct usb_configuration *c, struct 
usb_function *f)
goto error;
}
 
+   if (gadget_is_dualspeed(gadget)) {
+   /* Assume endpoint addresses are the same for both speeds */
+   in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress;
+   }
+
sdp->in_ep = ep; /* Store IN EP for enabling @ setup */
 
cdev->req->context = sdp;
@@ -527,7 +554,7 @@ static struct usb_request *sdp_start_ep(struct usb_ep *ep)
 {
struct usb_request *req;
 
-   req = alloc_ep_req(ep, 64);
+   req = alloc_ep_req(ep, SDP_USB_REQUEST_BUFLEN);
debug("%s: ep:%p req:%p\n", __func__, ep, req);
 
if (!req)
@@ -542,11 +569,15 @@ static int sdp_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
 {
struct f_sdp *sdp = func_to_sdp(f);
struct usb_composite_dev *cdev = f->config->cdev;
+   struct usb_gadget *gadget = cdev->gadget;
int result;
 
debug("%s: intf: %d alt: %d\n", __func__, intf, alt);
 
-   result = usb_ep_enable(sdp->in_ep, _desc);
+   if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH)
+   result = usb_ep_enable(sdp->in_ep, _hs_desc);
+   else
+   result = usb_ep_enable(sdp->in_ep, _desc);
if (result)
return result;
sdp->in_req = sdp_start_ep(sdp->in_ep);
@@ -592,7 +623,7 @@ static int sdp_bind_config(struct usb_configuration *c)
memset(sdp_func, 0, sizeof(*sdp_func));
 
sdp_func->usb_function.name = "sdp";
-   sdp_func->usb_function.hs_descriptors = sdp_runtime_descs;
+   sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs;
sdp_func->usb_function.descriptors = sdp_runtime_descs;
sdp_func->usb_function.bind = sdp_bind;
sdp_func->usb_function.unbind = sdp_unbind;
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 4/4] SDP: Call usb_gadget_initialize and usb_gadget_release to support UDC

2019-08-26 Thread Sherry Sun
Need initialize UDC before run sdp download and release it at the end of
sdp.

Signed-off-by: Sherry Sun 
Signed-off-by: Frank Li 
Reviewed-by: Lukasz Majewski 
---
 common/spl/spl_sdp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c
index 806bf1327e..7b0a213d4c 100644
--- a/common/spl/spl_sdp.c
+++ b/common/spl/spl_sdp.c
@@ -16,6 +16,8 @@ static int spl_sdp_load_image(struct spl_image_info 
*spl_image,
int ret;
const int controller_index = 0;
 
+   usb_gadget_initialize(controller_index);
+
g_dnl_clear_detach();
ret = g_dnl_register("usb_dnl_sdp");
if (ret) {
@@ -37,6 +39,8 @@ static int spl_sdp_load_image(struct spl_image_info 
*spl_image,
ret = spl_sdp_handle(controller_index, spl_image);
debug("SDP ended\n");
 
+   usb_gadget_release(controller_index);
+
return ret;
 }
 SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 1/4] imx: spl: Change USB boot device type for imx8/8m

2019-08-26 Thread Sherry Sun
The SPL SDP is configured as BOOT_DEVICE_BOARD, but for i.MX8 and
i.MX8M, the boot_device_spl is still set to BOOT_DEVICE_USB, which
may cause SDP can't work, in order to fix this issue, when booting
from USB in spl, we change its type to BOOT_DEVICE_BOARD.

Signed-off-by: Sherry Sun 
Signed-off-by: Ye Li 
Reviewed-by: Lukasz Majewski 
---
 arch/arm/mach-imx/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index 1f230aca33..a74d222dd6 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -158,7 +158,7 @@ u32 spl_boot_device(void)
case SPI_NOR_BOOT:
return BOOT_DEVICE_SPI;
case USB_BOOT:
-   return BOOT_DEVICE_USB;
+   return BOOT_DEVICE_BOARD;
default:
return BOOT_DEVICE_NONE;
}
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 0/4] Make some changes to SDP

2019-08-26 Thread Sherry Sun
Changes in v4:
 - Add SDP_USB_REQUEST_BUFLEN instead of magic number (65) in patch3/4.
 - Remove the unnecessary blank lines in patch3/4.

Changes in v3:
 - Add reviewed-by tag for patch2/4 and patch4/4 since this two have
 been reviewed in v1.

Changes in v2:
 - Update the commit log in patch 1/4.

This patchset adds:
1. Add usb_gadget_initialize() and usb_gadget_release() to initialize and
release UDC during sdp download.
2. Add high speed endpoint descriptor for sdp. 
3. Add a macro definition--CONFIG_SDP_LOADADDR as default sdp load
address while SDP_WRITE and SDP_JUMP command addr is zero.

The current patches have been validated on both i.MX8 and i.MX8M platform.

Sherry Sun (4):
  imx: spl: Change USB boot device type for imx8/8m
  SDP: use CONFIG_SDP_LOADADDR as default load address
  SDP: fix wrong usb request size and add high speed endpoint descriptor
  SDP: Call usb_gadget_initialize and usb_gadget_release to support UDC

 arch/arm/mach-imx/spl.c|  2 +-
 common/spl/spl_sdp.c   |  4 
 drivers/usb/gadget/Kconfig |  4 
 drivers/usb/gadget/f_sdp.c | 43 +-
 4 files changed, 47 insertions(+), 6 deletions(-)

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor

2019-08-26 Thread Sherry Sun
Hi Lukasz,

> 
> On Thu, 22 Aug 2019 01:46:20 +0000
> Sherry Sun  wrote:
> 
> > Because the buffer length of sdp usb request is 65, we have to
> > allocate 65 bytes not 64 bytes. Otherwise there is potential buffer
> > overflow.
> >
> > So the wMaxPacketSize of fullspeed can't meet the needs. Add HS
> > endpoint descriptor for SDP. Then we can use high speed endpoint, and
> > the SDP device can send packet with 512 byte size.
> >
> > Signed-off-by: Sherry Sun 
> > Signed-off-by: Ye Li 
> > ---
> >  drivers/usb/gadget/f_sdp.c | 33 ++---
> >  1 file changed, 30 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
> > index 841814bc07..8aaed92e9b 100644
> > --- a/drivers/usb/gadget/f_sdp.c
> > +++ b/drivers/usb/gadget/f_sdp.c
> > @@ -158,6 +158,16 @@ static struct usb_endpoint_descriptor in_desc = {
> > .bInterval =1,
> >  };
> >
> > +static struct usb_endpoint_descriptor in_hs_desc = {
> > +   .bLength =  USB_DT_ENDPOINT_SIZE,
> > +   .bDescriptorType =  USB_DT_ENDPOINT,
> > /*USB_DT_CS_ENDPOINT*/ +
> > +   .bEndpointAddress = 1 | USB_DIR_IN,
> > +   .bmAttributes = USB_ENDPOINT_XFER_INT,
> > +   .wMaxPacketSize =   512,
> > +   .bInterval =1,
> > +};
> > +
> >  static struct usb_descriptor_header *sdp_runtime_descs[] = {
> > (struct usb_descriptor_header *)_intf_runtime,
> > (struct usb_descriptor_header *)_hid_desc, @@ -165,6 +175,13
> @@
> > static struct usb_descriptor_header *sdp_runtime_descs[] = { NULL,  };
> >
> > +static struct usb_descriptor_header *sdp_runtime_hs_descs[] = {
> > +   (struct usb_descriptor_header *)_intf_runtime,
> > +   (struct usb_descriptor_header *)_hid_desc,
> > +   (struct usb_descriptor_header *)_hs_desc,
> > +   NULL,
> > +};
> > +
> >  /* This is synchronized with what the SoC implementation reports */
> > static struct hid_report sdp_hid_report = {
> > .usage_page = {
> > @@ -490,6 +507,11 @@ static int sdp_bind(struct usb_configuration *c,
> > struct usb_function *f) goto error;
> > }
> >
> > +   if (gadget_is_dualspeed(gadget)) {
> > +   /* Assume endpoint addresses are the same for both
> > speeds */
> > +   in_hs_desc.bEndpointAddress =
> > in_desc.bEndpointAddress;
> > +   }
> > +
> > sdp->in_ep = ep; /* Store IN EP for enabling @ setup */
> >
> > cdev->req->context = sdp;
> > @@ -527,7 +549,7 @@ static struct usb_request *sdp_start_ep(struct
> > usb_ep *ep) {
> > struct usb_request *req;
> >
> > -   req = alloc_ep_req(ep, 64);
> > +   req = alloc_ep_req(ep, 65);
> 
> Maybe it would be good to have the #define for this magic number (65)?
> 
> If normally we have 64, then it is pretty clear. With 65 we may need #define
> with some extra comment in the code.

Okay, I will add this.

> 
> > debug("%s: ep:%p req:%p\n", __func__, ep, req);
> >
> > if (!req)
> > @@ -542,11 +564,15 @@ static int sdp_set_alt(struct usb_function *f,
> > unsigned intf, unsigned alt) {
> > struct f_sdp *sdp = func_to_sdp(f);
> > struct usb_composite_dev *cdev = f->config->cdev;
> > +   struct usb_gadget *gadget = cdev->gadget;
> > int result;
> >
> > debug("%s: intf: %d alt: %d\n", __func__, intf, alt);
> >
> > -   result = usb_ep_enable(sdp->in_ep, _desc);
> > +   if (gadget_is_dualspeed(gadget) && gadget->speed ==
> > USB_SPEED_HIGH)
> > +   result = usb_ep_enable(sdp->in_ep, _hs_desc);
> > +   else
> > +   result = usb_ep_enable(sdp->in_ep, _desc);
> > if (result)
> > return result;
> > sdp->in_req = sdp_start_ep(sdp->in_ep); @@ -592,7 +618,7 @@
> static
> > int sdp_bind_config(struct usb_configuration *c) memset(sdp_func, 0,
> > sizeof(*sdp_func));
> >
> > sdp_func->usb_function.name = "sdp";
> > -   sdp_func->usb_function.hs_descriptors = sdp_runtime_descs;
> > +   sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs;
> > sdp_func->usb_function.descriptors = sdp_runtime_descs;
> > sdp_func->usb_function.bind = sdp_bind;
> > sdp_func->usb_function.unbind = sdp_unbind; @@ -725,6 +751,7
> @@
> > static void sdp_handle_in_ep(struct spl_image_info *spl_image) /* In
> > SPL, allow jumps to U-Boot images */
> >

[U-Boot] [PATCH v3 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor

2019-08-21 Thread Sherry Sun
Because the buffer length of sdp usb request is 65, we have to allocate
65 bytes not 64 bytes. Otherwise there is potential buffer overflow.

So the wMaxPacketSize of fullspeed can't meet the needs. Add HS
endpoint descriptor for SDP. Then we can use high speed endpoint,
and the SDP device can send packet with 512 byte size.

Signed-off-by: Sherry Sun 
Signed-off-by: Ye Li 
---
 drivers/usb/gadget/f_sdp.c | 33 ++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index 841814bc07..8aaed92e9b 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -158,6 +158,16 @@ static struct usb_endpoint_descriptor in_desc = {
.bInterval =1,
 };
 
+static struct usb_endpoint_descriptor in_hs_desc = {
+   .bLength =  USB_DT_ENDPOINT_SIZE,
+   .bDescriptorType =  USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/
+
+   .bEndpointAddress = 1 | USB_DIR_IN,
+   .bmAttributes = USB_ENDPOINT_XFER_INT,
+   .wMaxPacketSize =   512,
+   .bInterval =1,
+};
+
 static struct usb_descriptor_header *sdp_runtime_descs[] = {
(struct usb_descriptor_header *)_intf_runtime,
(struct usb_descriptor_header *)_hid_desc,
@@ -165,6 +175,13 @@ static struct usb_descriptor_header *sdp_runtime_descs[] = 
{
NULL,
 };
 
+static struct usb_descriptor_header *sdp_runtime_hs_descs[] = {
+   (struct usb_descriptor_header *)_intf_runtime,
+   (struct usb_descriptor_header *)_hid_desc,
+   (struct usb_descriptor_header *)_hs_desc,
+   NULL,
+};
+
 /* This is synchronized with what the SoC implementation reports */
 static struct hid_report sdp_hid_report = {
.usage_page = {
@@ -490,6 +507,11 @@ static int sdp_bind(struct usb_configuration *c, struct 
usb_function *f)
goto error;
}
 
+   if (gadget_is_dualspeed(gadget)) {
+   /* Assume endpoint addresses are the same for both speeds */
+   in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress;
+   }
+
sdp->in_ep = ep; /* Store IN EP for enabling @ setup */
 
cdev->req->context = sdp;
@@ -527,7 +549,7 @@ static struct usb_request *sdp_start_ep(struct usb_ep *ep)
 {
struct usb_request *req;
 
-   req = alloc_ep_req(ep, 64);
+   req = alloc_ep_req(ep, 65);
debug("%s: ep:%p req:%p\n", __func__, ep, req);
 
if (!req)
@@ -542,11 +564,15 @@ static int sdp_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
 {
struct f_sdp *sdp = func_to_sdp(f);
struct usb_composite_dev *cdev = f->config->cdev;
+   struct usb_gadget *gadget = cdev->gadget;
int result;
 
debug("%s: intf: %d alt: %d\n", __func__, intf, alt);
 
-   result = usb_ep_enable(sdp->in_ep, _desc);
+   if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH)
+   result = usb_ep_enable(sdp->in_ep, _hs_desc);
+   else
+   result = usb_ep_enable(sdp->in_ep, _desc);
if (result)
return result;
sdp->in_req = sdp_start_ep(sdp->in_ep);
@@ -592,7 +618,7 @@ static int sdp_bind_config(struct usb_configuration *c)
memset(sdp_func, 0, sizeof(*sdp_func));
 
sdp_func->usb_function.name = "sdp";
-   sdp_func->usb_function.hs_descriptors = sdp_runtime_descs;
+   sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs;
sdp_func->usb_function.descriptors = sdp_runtime_descs;
sdp_func->usb_function.bind = sdp_bind;
sdp_func->usb_function.unbind = sdp_unbind;
@@ -725,6 +751,7 @@ static void sdp_handle_in_ep(struct spl_image_info 
*spl_image)
/* In SPL, allow jumps to U-Boot images */
struct spl_image_info spl_image = {};
spl_parse_image_header(_image, header);
+
jump_to_image_no_args(_image);
 #else
/* In U-Boot, allow jumps to scripts */
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 1/4] imx: spl: Change USB boot device type for imx8/8m

2019-08-21 Thread Sherry Sun
The SPL SDP is configured as BOOT_DEVICE_BOARD, but for i.MX8 and
i.MX8M, the boot_device_spl is still set to BOOT_DEVICE_USB, which
may cause SDP can't work, in order to fix this issue, when booting
from USB in spl, we change its type to BOOT_DEVICE_BOARD.

Signed-off-by: Sherry Sun 
Signed-off-by: Ye Li 
---
 arch/arm/mach-imx/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index 1f230aca33..a74d222dd6 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -158,7 +158,7 @@ u32 spl_boot_device(void)
case SPI_NOR_BOOT:
return BOOT_DEVICE_SPI;
case USB_BOOT:
-   return BOOT_DEVICE_USB;
+   return BOOT_DEVICE_BOARD;
default:
return BOOT_DEVICE_NONE;
}
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 4/4] SDP: Call usb_gadget_initialize and usb_gadget_release to support UDC

2019-08-21 Thread Sherry Sun
Need initialize UDC before run sdp download and release it at the end of
sdp.

Signed-off-by: Sherry Sun 
Signed-off-by: Frank Li 
Reviewed-by: Lukasz Majewski 
---
 common/spl/spl_sdp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c
index 806bf1327e..7b0a213d4c 100644
--- a/common/spl/spl_sdp.c
+++ b/common/spl/spl_sdp.c
@@ -16,6 +16,8 @@ static int spl_sdp_load_image(struct spl_image_info 
*spl_image,
int ret;
const int controller_index = 0;
 
+   usb_gadget_initialize(controller_index);
+
g_dnl_clear_detach();
ret = g_dnl_register("usb_dnl_sdp");
if (ret) {
@@ -37,6 +39,8 @@ static int spl_sdp_load_image(struct spl_image_info 
*spl_image,
ret = spl_sdp_handle(controller_index, spl_image);
debug("SDP ended\n");
 
+   usb_gadget_release(controller_index);
+
return ret;
 }
 SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 0/4] Make some changes to SDP

2019-08-21 Thread Sherry Sun
Changes in v3:
 - Add reviewed-by tag for patch2/4 and patch4/4 since this two have
 been reviewed in v1.

Changes in v2:
 - Update the commit log in patch 1/4.

This patchset adds:
1. Add usb_gadget_initialize() and usb_gadget_release() to initialize and
release UDC during sdp download.
2. Add high speed endpoint descriptor for sdp. 
3. Add a macro definition--CONFIG_SDP_LOADADDR as default sdp load
address while SDP_WRITE and SDP_JUMP command addr is zero.

The current patches have been validated on both i.MX8 and i.MX8M platform.

Sherry Sun (4):
  imx: spl: Change USB boot device type for imx8/8m
  SDP: use CONFIG_SDP_LOADADDR as default load address
  SDP: fix wrong usb request size and add high speed endpoint descriptor
  SDP: Call usb_gadget_initialize and usb_gadget_release to support UDC

 arch/arm/mach-imx/spl.c|  2 +-
 common/spl/spl_sdp.c   |  4 
 drivers/usb/gadget/Kconfig |  4 
 drivers/usb/gadget/f_sdp.c | 39 +-
 4 files changed, 43 insertions(+), 6 deletions(-)

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 2/4] SDP: use CONFIG_SDP_LOADADDR as default load address

2019-08-21 Thread Sherry Sun
If SDP_WRITE and SDP_JUMP command addr is zero, use CONFIG_SDP_LOADADDR
as default address.

Signed-off-by: Sherry Sun 
Signed-off-by: Frank Li 
Reviewed-by: Lukasz Majewski 
---
 drivers/usb/gadget/Kconfig | 4 
 drivers/usb/gadget/f_sdp.c | 6 --
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 26b4d12a09..172a82195b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -115,6 +115,10 @@ config USB_GADGET_VBUS_DRAW
   This value will be used except for system-specific gadget
   drivers that have more specific information.
 
+config SDP_LOADADDR
+   hex "Default load address at SDP_WRITE and SDP_JUMP"
+   default 0
+
 # Selected by UDC drivers that support high-speed operation.
 config USB_GADGET_DUALSPEED
bool
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index bcd1c5d47c..841814bc07 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -276,7 +276,8 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
sdp->error_status = SDP_WRITE_FILE_COMPLETE;
 
sdp->state = SDP_STATE_RX_FILE_DATA;
-   sdp->dnl_address = be32_to_cpu(cmd->addr);
+   sdp->dnl_address = cmd->addr ? be32_to_cpu(cmd->addr) :
+  CONFIG_SDP_LOADADDR;
sdp->dnl_bytes_remaining = be32_to_cpu(cmd->cnt);
sdp->dnl_bytes = sdp->dnl_bytes_remaining;
sdp->next_state = SDP_STATE_IDLE;
@@ -304,7 +305,8 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
sdp->always_send_status = false;
sdp->error_status = 0;
 
-   sdp->jmp_address = be32_to_cpu(cmd->addr);
+   sdp->jmp_address = cmd->addr ? be32_to_cpu(cmd->addr) :
+  CONFIG_SDP_LOADADDR;
sdp->state = SDP_STATE_TX_SEC_CONF;
sdp->next_state = SDP_STATE_JUMP;
break;
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 2/4] SDP: use CONFIG_SDP_LOADADDR as default load address

2019-08-21 Thread Sherry Sun
If SDP_WRITE and SDP_JUMP command addr is zero, use CONFIG_SDP_LOADADDR
as default address.

Signed-off-by: Sherry Sun 
Signed-off-by: Frank Li 
---
 drivers/usb/gadget/Kconfig | 4 
 drivers/usb/gadget/f_sdp.c | 6 --
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 26b4d12a09..172a82195b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -115,6 +115,10 @@ config USB_GADGET_VBUS_DRAW
   This value will be used except for system-specific gadget
   drivers that have more specific information.
 
+config SDP_LOADADDR
+   hex "Default load address at SDP_WRITE and SDP_JUMP"
+   default 0
+
 # Selected by UDC drivers that support high-speed operation.
 config USB_GADGET_DUALSPEED
bool
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index bcd1c5d47c..841814bc07 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -276,7 +276,8 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
sdp->error_status = SDP_WRITE_FILE_COMPLETE;
 
sdp->state = SDP_STATE_RX_FILE_DATA;
-   sdp->dnl_address = be32_to_cpu(cmd->addr);
+   sdp->dnl_address = cmd->addr ? be32_to_cpu(cmd->addr) :
+  CONFIG_SDP_LOADADDR;
sdp->dnl_bytes_remaining = be32_to_cpu(cmd->cnt);
sdp->dnl_bytes = sdp->dnl_bytes_remaining;
sdp->next_state = SDP_STATE_IDLE;
@@ -304,7 +305,8 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
sdp->always_send_status = false;
sdp->error_status = 0;
 
-   sdp->jmp_address = be32_to_cpu(cmd->addr);
+   sdp->jmp_address = cmd->addr ? be32_to_cpu(cmd->addr) :
+  CONFIG_SDP_LOADADDR;
sdp->state = SDP_STATE_TX_SEC_CONF;
sdp->next_state = SDP_STATE_JUMP;
break;
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 1/4] imx: spl: Change USB boot device type for imx8/8m

2019-08-21 Thread Sherry Sun
The SPL SDP is configured as BOOT_DEVICE_BOARD, but for i.MX8 and
i.MX8M, the boot_device_spl is still set to BOOT_DEVICE_USB, which
may cause SDP can't work, in order to fix this issue, when booting
from USB in spl, we change its type to BOOT_DEVICE_BOARD.

Signed-off-by: Sherry Sun 
Signed-off-by: Ye Li 
---
 arch/arm/mach-imx/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index 1f230aca33..a74d222dd6 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -158,7 +158,7 @@ u32 spl_boot_device(void)
case SPI_NOR_BOOT:
return BOOT_DEVICE_SPI;
case USB_BOOT:
-   return BOOT_DEVICE_USB;
+   return BOOT_DEVICE_BOARD;
default:
return BOOT_DEVICE_NONE;
}
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor

2019-08-21 Thread Sherry Sun
Because the buffer length of sdp usb request is 65, we have to allocate
65 bytes not 64 bytes. Otherwise there is potential buffer overflow.

So the wMaxPacketSize of fullspeed can't meet the needs. Add HS
endpoint descriptor for SDP. Then we can use high speed endpoint,
and the SDP device can send packet with 512 byte size.

Signed-off-by: Sherry Sun 
Signed-off-by: Ye Li 
---
 drivers/usb/gadget/f_sdp.c | 33 ++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index 841814bc07..8aaed92e9b 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -158,6 +158,16 @@ static struct usb_endpoint_descriptor in_desc = {
.bInterval =1,
 };
 
+static struct usb_endpoint_descriptor in_hs_desc = {
+   .bLength =  USB_DT_ENDPOINT_SIZE,
+   .bDescriptorType =  USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/
+
+   .bEndpointAddress = 1 | USB_DIR_IN,
+   .bmAttributes = USB_ENDPOINT_XFER_INT,
+   .wMaxPacketSize =   512,
+   .bInterval =1,
+};
+
 static struct usb_descriptor_header *sdp_runtime_descs[] = {
(struct usb_descriptor_header *)_intf_runtime,
(struct usb_descriptor_header *)_hid_desc,
@@ -165,6 +175,13 @@ static struct usb_descriptor_header *sdp_runtime_descs[] = 
{
NULL,
 };
 
+static struct usb_descriptor_header *sdp_runtime_hs_descs[] = {
+   (struct usb_descriptor_header *)_intf_runtime,
+   (struct usb_descriptor_header *)_hid_desc,
+   (struct usb_descriptor_header *)_hs_desc,
+   NULL,
+};
+
 /* This is synchronized with what the SoC implementation reports */
 static struct hid_report sdp_hid_report = {
.usage_page = {
@@ -490,6 +507,11 @@ static int sdp_bind(struct usb_configuration *c, struct 
usb_function *f)
goto error;
}
 
+   if (gadget_is_dualspeed(gadget)) {
+   /* Assume endpoint addresses are the same for both speeds */
+   in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress;
+   }
+
sdp->in_ep = ep; /* Store IN EP for enabling @ setup */
 
cdev->req->context = sdp;
@@ -527,7 +549,7 @@ static struct usb_request *sdp_start_ep(struct usb_ep *ep)
 {
struct usb_request *req;
 
-   req = alloc_ep_req(ep, 64);
+   req = alloc_ep_req(ep, 65);
debug("%s: ep:%p req:%p\n", __func__, ep, req);
 
if (!req)
@@ -542,11 +564,15 @@ static int sdp_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
 {
struct f_sdp *sdp = func_to_sdp(f);
struct usb_composite_dev *cdev = f->config->cdev;
+   struct usb_gadget *gadget = cdev->gadget;
int result;
 
debug("%s: intf: %d alt: %d\n", __func__, intf, alt);
 
-   result = usb_ep_enable(sdp->in_ep, _desc);
+   if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH)
+   result = usb_ep_enable(sdp->in_ep, _hs_desc);
+   else
+   result = usb_ep_enable(sdp->in_ep, _desc);
if (result)
return result;
sdp->in_req = sdp_start_ep(sdp->in_ep);
@@ -592,7 +618,7 @@ static int sdp_bind_config(struct usb_configuration *c)
memset(sdp_func, 0, sizeof(*sdp_func));
 
sdp_func->usb_function.name = "sdp";
-   sdp_func->usb_function.hs_descriptors = sdp_runtime_descs;
+   sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs;
sdp_func->usb_function.descriptors = sdp_runtime_descs;
sdp_func->usb_function.bind = sdp_bind;
sdp_func->usb_function.unbind = sdp_unbind;
@@ -725,6 +751,7 @@ static void sdp_handle_in_ep(struct spl_image_info 
*spl_image)
/* In SPL, allow jumps to U-Boot images */
struct spl_image_info spl_image = {};
spl_parse_image_header(_image, header);
+
jump_to_image_no_args(_image);
 #else
/* In U-Boot, allow jumps to scripts */
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 0/4] Make some changes to SDP

2019-08-21 Thread Sherry Sun
Changes in v2:
 - Update the commit log in patch 1/4.
The current patches have been validated on both i.MX8 and i.MX8M platform.

This patchset adds:
1. Add usb_gadget_initialize() and usb_gadget_release() to initialize and
release UDC during sdp download.
2. Add high speed endpoint descriptor for sdp. 
3. Add a macro definition--CONFIG_SDP_LOADADDR as default sdp load
address while SDP_WRITE and SDP_JUMP command addr is zero.

Sherry Sun (4):
  imx: spl: Change USB boot device type for imx8/8m
  SDP: use CONFIG_SDP_LOADADDR as default load address
  SDP: fix wrong usb request size and add high speed endpoint descriptor
  SDP: Call usb_gadget_initialize and usb_gadget_release to support UDC

 arch/arm/mach-imx/spl.c|  2 +-
 common/spl/spl_sdp.c   |  4 
 drivers/usb/gadget/Kconfig |  4 
 drivers/usb/gadget/f_sdp.c | 39 +-
 4 files changed, 43 insertions(+), 6 deletions(-)

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 4/4] SDP: Call usb_gadget_initialize and usb_gadget_release to support UDC

2019-08-21 Thread Sherry Sun
Need initialize UDC before run sdp download and release it at the end of
sdp.

Signed-off-by: Sherry Sun 
Signed-off-by: Frank Li 
---
 common/spl/spl_sdp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c
index 806bf1327e..7b0a213d4c 100644
--- a/common/spl/spl_sdp.c
+++ b/common/spl/spl_sdp.c
@@ -16,6 +16,8 @@ static int spl_sdp_load_image(struct spl_image_info 
*spl_image,
int ret;
const int controller_index = 0;
 
+   usb_gadget_initialize(controller_index);
+
g_dnl_clear_detach();
ret = g_dnl_register("usb_dnl_sdp");
if (ret) {
@@ -37,6 +39,8 @@ static int spl_sdp_load_image(struct spl_image_info 
*spl_image,
ret = spl_sdp_handle(controller_index, spl_image);
debug("SDP ended\n");
 
+   usb_gadget_release(controller_index);
+
return ret;
 }
 SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 5/7] usb: host: Add the USB3 host driver

2019-08-21 Thread Sherry Sun
Add the USB3 host driver for NXP imx8 platform, and the
cadence IP is in it. The USB3 host driver support DM
mode, it will probe USB3 host node in dts.

Signed-off-by: Sherry Sun 
---
 drivers/usb/host/Kconfig |   9 ++
 drivers/usb/host/Makefile|   1 +
 drivers/usb/host/xhci-imx8.c | 210 +++
 3 files changed, 220 insertions(+)
 create mode 100644 drivers/usb/host/xhci-imx8.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 42046c8062..e3d9717b33 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -95,6 +95,15 @@ config USB_XHCI_FSL
depends on !SPL_NO_USB
help
  Enables support for the on-chip xHCI controller on NXP Layerscape 
SoCs.
+
+config USB_XHCI_IMX8
+   bool "XHCI support for i.MX8"
+   depends on ARCH_IMX8
+   default y
+   help
+ Enables support for the on-chip xHCI controller on i.MX8QM and
+ i.MX8QXP SoCs.
+
 endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index dd13528475..d40a236be0 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
 obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
 obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
+obj-$(CONFIG_USB_XHCI_IMX8) += xhci-imx8.o
 
 # designware
 obj-$(CONFIG_USB_DWC2) += dwc2.o
diff --git a/drivers/usb/host/xhci-imx8.c b/drivers/usb/host/xhci-imx8.c
new file mode 100644
index 00..d87f009644
--- /dev/null
+++ b/drivers/usb/host/xhci-imx8.c
@@ -0,0 +1,210 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * NXP i.MX8 USB HOST xHCI Controller (Cadence IP)
+ *
+ * Author: Peter Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "xhci.h"
+
+/* Declare global data pointer */
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Host registers */
+#define HCIVERSION_CAPLENGTH   0x1
+#define USBSTS 0x10084
+
+/* None-core registers */
+#define USB3_CORE_CTRL10x00
+#define USB3_CORE_STATUS   0x0c
+#define USB3_SSPHY_STATUS  0x4c
+
+/* USB3_CORE_CTRL1 */
+#define ALL_SW_RESET   0xfc00
+#define MODE_STRAP_MASK0x7
+#define PHYAHB_SW_RESETBIT(26)
+#define OC_DISABLE BIT(9)
+#define HOST_MODE  BIT(1)
+#define OTG_MODE   BIT(0)
+
+/* USB3_CORE_STATUS */
+#define HOST_POWER_ON_READYBIT(12)
+
+/* USBSTS */
+#define CONTROLLER_NOT_READY   BIT(11)
+
+/* USB3_SSPHY_STATUS */
+#define CLK_VLD0xf000
+
+struct xhci_imx8_data {
+   void __iomem *usb3_ctrl_base;
+   void __iomem *usb3_core_base;
+   struct clk_bulk clks;
+   struct phy phy;
+};
+
+static struct xhci_imx8_data imx8_data;
+
+static int imx8_xhci_init(void)
+{
+   int ret;
+
+   writel(CLK_VLD, imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   ret = wait_for_bit_le32(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS,
+   CLK_VLD, true, 100, false);
+   if (ret) {
+   printf("clkvld is incorrect\n");
+   return ret;
+   }
+
+   clrsetbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1,
+   MODE_STRAP_MASK,  HOST_MODE | OC_DISABLE);
+   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1,
+PHYAHB_SW_RESET);
+   generic_phy_init(_data.phy);
+
+   /* clear all sw_rst */
+   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1, ALL_SW_RESET);
+
+   debug("wait xhci_power_on_ready\n");
+   ret = wait_for_bit_le32(imx8_data.usb3_ctrl_base + USB3_CORE_STATUS,
+   HOST_POWER_ON_READY, true, 100, false);
+   if (ret) {
+   printf("wait xhci_power_on_ready timeout\n");
+   return ret;
+   }
+   debug("xhci_power_on_ready\n");
+
+   debug("waiting CNR\n");
+   ret = wait_for_bit_le32(imx8_data.usb3_core_base + USBSTS,
+   CONTROLLER_NOT_READY, false, 100, false);
+   if (ret) {
+   printf("wait CNR timeout\n");
+   return ret;
+   }
+   debug("check CNR has finished\n");
+
+   return 0;
+}
+
+static void imx8_xhci_reset(void)
+{
+   /* Set CORE ctrl to default value, that all rst are hold */
+   writel(ALL_SW_RESET | OTG_MODE,
+  imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1);
+}
+
+static int xhci_imx8_clk_init(struct udevice *dev)
+{
+   int ret;
+
+   ret = clk_get_bulk(dev, _data.clks);
+   if (ret)
+   return ret;
+
+   ret = clk_enable_bulk(_data.clks);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+static inline void xhci_imx8_get_reg_addr(struct

[U-Boot] [PATCH v5 7/7] usb: gadget: core: introduce ->udc_set_speed() method

2019-08-21 Thread Sherry Sun
This patch was copied from kernel commit: 67fdfda4a99ed.

Sometimes, the gadget driver we want to run has max_speed lower than
what the UDC supports. In such situations, UDC might want to make sure
we don't try to connect on speeds not supported by the gadget
driver because that will just fail.

So here introduce a new optional ->udc_set_speed() method which can be
implemented by interested UDC drivers to achieve this purpose.

Signed-off-by: Sherry Sun 
---
 drivers/usb/gadget/udc/udc-core.c | 23 +++
 include/linux/usb/gadget.h|  2 ++
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 62b47781dd..8d1d90e3e3 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -267,6 +267,27 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
 /* - */
 
+/**
+ * usb_gadget_udc_set_speed - tells usb device controller speed supported by
+ *current driver
+ * @udc: The device we want to set maximum speed
+ * @speed: The maximum speed to allowed to run
+ *
+ * This call is issued by the UDC Class driver before calling
+ * usb_gadget_udc_start() in order to make sure that we don't try to
+ * connect on speeds the gadget driver doesn't support.
+ */
+static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
+   enum usb_device_speed speed)
+{
+   if (udc->gadget->ops->udc_set_speed) {
+   enum usb_device_speed s;
+
+   s = min(speed, udc->gadget->max_speed);
+   udc->gadget->ops->udc_set_speed(udc->gadget, s);
+   }
+}
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver 
*driver)
 {
int ret;
@@ -276,6 +297,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct 
usb_gadget_driver *dri
 
udc->driver = driver;
 
+   usb_gadget_udc_set_speed(udc, driver->speed);
+
ret = driver->bind(udc->gadget);
if (ret)
goto err1;
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index a34f3478f3..78e245a1b5 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -450,6 +450,8 @@ struct usb_gadget_ops {
int   (*match_ep)(struct usb_gadget *gadget,
  struct usb_ep *ep,
  struct usb_endpoint_descriptor *desc);
+   void(*udc_set_speed)(struct usb_gadget *gadget,
+enum usb_device_speed);
 };
 
 /**
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 4/7] usb: gadget: Add gadget_is_cdns3 checking to provide bcdUSB value

2019-08-21 Thread Sherry Sun
Like other usb controllers, add gadget_is_cdns3 checking to
provide bcdUSB value in device descriptor.

Signed-off-by: Sherry Sun 
---
 drivers/usb/gadget/gadget_chips.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/gadget/gadget_chips.h 
b/drivers/usb/gadget/gadget_chips.h
index 2c8f235d51..ba9114cf37 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -149,6 +149,11 @@
 #define gadget_is_dwc3(g)0
 #endif
 
+#ifdef CONFIG_USB_CDNS3_GADGET
+#define gadget_is_cdns3(g)(!strcmp("cdns3-gadget", (g)->name))
+#else
+#define gadget_is_cdns3(g)0
+#endif
 /**
  * usb_gadget_controller_number - support bcdDevice id convention
  * @gadget: the controller being driven
@@ -208,5 +213,7 @@ static inline int usb_gadget_controller_number(struct 
usb_gadget *gadget)
return 0x22;
else if (gadget_is_dwc3(gadget))
return 0x23;
+   else if (gadget_is_cdns3(gadget))
+   return 0x24;
return -ENOENT;
 }
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 3/7] usb: gadget: Add match_ep call back to usb_gadget_ops

2019-08-21 Thread Sherry Sun
Since some new fields in usb_ep structure been moved to usb_ss_ep.
The CDNS3 gadget driver should replies on this operation to bind the
usb_ss_ep with the endpoint descriptor when function layer uses
usb_ep_autoconfig to add endpoint descriptors to gadget. So that
CDNS3 driver can know the EP information and configure the EP once
the set configuration request is received.

Signed-off-by: Sherry Sun 
---
 drivers/usb/gadget/epautoconf.c | 4 
 include/linux/usb/gadget.h  | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 179b94cdd0..360f2b75ff 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -167,6 +167,10 @@ static int ep_matches(
size = 64;
put_unaligned(cpu_to_le16(size), >wMaxPacketSize);
}
+
+   if (gadget->ops->match_ep)
+   return gadget->ops->match_ep(gadget, ep, desc);
+
return 1;
 }
 
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 497798a32a..a34f3478f3 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -447,6 +447,9 @@ struct usb_gadget_ops {
int (*udc_start)(struct usb_gadget *,
 struct usb_gadget_driver *);
int (*udc_stop)(struct usb_gadget *);
+   int   (*match_ep)(struct usb_gadget *gadget,
+ struct usb_ep *ep,
+ struct usb_endpoint_descriptor *desc);
 };
 
 /**
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 6/7] phy: Add USB PHY driver for the cadence USB3

2019-08-21 Thread Sherry Sun
The cdns3-usb-phy driver supports both host and peripheral
mode of usb driver which use cadence usb3 IP.

Signed-off-by: Sherry Sun 
---
 drivers/phy/Kconfig |   8 ++
 drivers/phy/Makefile|   1 +
 drivers/phy/cdns3-usb-phy.c | 241 
 3 files changed, 250 insertions(+)
 create mode 100644 drivers/phy/cdns3-usb-phy.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 3942f035eb..1837b32c31 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -205,4 +205,12 @@ config MT76X8_USB_PHY
 
  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+   bool "Support CDNS3 USB PHY"
+   depends on PHY
+   help
+ Support for the USB PHY in CDNS3 IP.
+
+ This PHY is found on CDNS3 IP devices supporting USB.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 3157f1b7ee..0e062214d3 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -22,4 +22,5 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
 obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
 obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
 obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
 obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o
diff --git a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c
new file mode 100644
index 00..c0d308075b
--- /dev/null
+++ b/drivers/phy/cdns3-usb-phy.c
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Cadence3 USB PHY driver
+ *
+ * Author: Sherry Sun 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* PHY registers */
+#define PHY_PMA_CMN_CTRL1  (0xC800 * 4)
+#define TB_ADDR_CMN_DIAG_HSCLK_SEL (0x01e0 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR   (0x0084 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR   (0x0085 * 4)
+#define TB_ADDR_CMN_PLL0_INTDIV(0x0094 * 4)
+#define TB_ADDR_CMN_PLL0_FRACDIV   (0x0095 * 4)
+#define TB_ADDR_CMN_PLL0_HIGH_THR  (0x0096 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL1  (0x0098 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL2  (0x0099 * 4)
+#define TB_ADDR_CMN_PLL0_DSM_DIAG  (0x0097 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_OVRD (0x01c2 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD (0x01c0 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD (0x01c1 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE  (0x01C5 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE   (0x01C6 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG   (0x01C7 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE(0x01c4 * 4)
+#define TB_ADDR_CMN_PSM_CLK_CTRL   (0x0061 * 4)
+#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR  (0x40ea * 4)
+#define TB_ADDR_XCVR_PSM_RCTRL (0x4001 * 4)
+#define TB_ADDR_TX_PSC_A0  (0x4100 * 4)
+#define TB_ADDR_TX_PSC_A1  (0x4101 * 4)
+#define TB_ADDR_TX_PSC_A2  (0x4102 * 4)
+#define TB_ADDR_TX_PSC_A3  (0x4103 * 4)
+#define TB_ADDR_TX_DIAG_ECTRL_OVRD (0x41f5 * 4)
+#define TB_ADDR_TX_PSC_CAL (0x4106 * 4)
+#define TB_ADDR_TX_PSC_RDY (0x4107 * 4)
+#define TB_ADDR_RX_PSC_A0  (0x8000 * 4)
+#define TB_ADDR_RX_PSC_A1  (0x8001 * 4)
+#define TB_ADDR_RX_PSC_A2  (0x8002 * 4)
+#define TB_ADDR_RX_PSC_A3  (0x8003 * 4)
+#define TB_ADDR_RX_PSC_CAL (0x8006 * 4)
+#define TB_ADDR_RX_PSC_RDY (0x8007 * 4)
+#define TB_ADDR_TX_TXCC_MGNLS_MULT_000 (0x4058 * 4)
+#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY (0x41e7 * 4)
+#define TB_ADDR_RX_SLC_CU_ITER_TMR (0x80e3 * 4)
+#define TB_ADDR_RX_SIGDET_HL_FILT_TMR  (0x8090 * 4)
+#define TB_ADDR_RX_SAMP_DAC_CTRL   (0x8058 * 4)
+#define TB_ADDR_RX_DIAG_SIGDET_TUNE(0x81dc * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE2  (0x81df * 4)
+#define TB_ADDR_RX_DIAG_BS_TM  (0x81f5 * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL1  (0x81d3 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM4  (0x81c7 * 4)
+#define TB_ADDR_RX_DIAG_ILL_E_TRIM0(0x81c2 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQ_TRIM0   (0x81c1 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM6  (0x81c9 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM3   (0x81f8 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM4   (0x81f9 * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE   (0x81dd * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL3  (0x81d5 * 4)
+#define TB_ADDR_RX_DIAG_SC2C_DELAY (0x81e1 * 4)
+#define TB_ADDR_RX_REE_VGA_GAIN_NODFE  (0x81bf * 4)
+#define TB_ADDR_XCVR_PSM_CAL_TMR   (0x4002 * 4)
+#define TB_ADDR_XCVR_PSM

[U-Boot] [PATCH v5 2/7] usb: gadget: Add the cadence USB3 gadget driver

2019-08-21 Thread Sherry Sun
This driver is ported from NXP i.MX U-Boot version imx_v2019.04
and some changes have also been made to adapt to U-Boot.

Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode).
The CDNS3 gadget driver support DM mode. CONFIG_DM_USB_GADGET should
be enabled when use this driver.

Signed-off-by: Sherry Sun 
---
 Makefile  |1 +
 drivers/usb/Kconfig   |2 +
 drivers/usb/cdns3/Kconfig |   20 +
 drivers/usb/cdns3/Makefile|5 +
 drivers/usb/cdns3/cdns3-generic.c |  114 ++
 drivers/usb/cdns3/cdns3-nxp-reg-def.h |   93 ++
 drivers/usb/cdns3/core.c  |  203 +++
 drivers/usb/cdns3/core.h  |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h|  116 ++
 drivers/usb/cdns3/dev-regs-map.h  |  117 ++
 drivers/usb/cdns3/gadget-export.h |   26 +
 drivers/usb/cdns3/gadget.c| 2183 +
 drivers/usb/cdns3/gadget.h|  225 +++
 drivers/usb/cdns3/io.h|   27 +
 drivers/usb/gadget/udc/Makefile   |1 +
 scripts/Makefile.spl  |1 +
 16 files changed, 3252 insertions(+)
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h

diff --git a/Makefile b/Makefile
index 3b0864ae8e..37b82eff05 100644
--- a/Makefile
+++ b/Makefile
@@ -728,6 +728,7 @@ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
 libs-$(CONFIG_$(SPL_)ALTERA_SDRAM) += drivers/ddr/altera/
 libs-y += drivers/serial/
+libs-y += drivers/usb/cdns3/
 libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/common/
 libs-y += drivers/usb/emul/
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 3b53bf2c58..98f5e936e5 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -70,6 +70,8 @@ source "drivers/usb/host/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
 
+source "drivers/usb/cdns3/Kconfig"
+
 source "drivers/usb/musb/Kconfig"
 
 source "drivers/usb/musb-new/Kconfig"
diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
new file mode 100644
index 00..11a7144b05
--- /dev/null
+++ b/drivers/usb/cdns3/Kconfig
@@ -0,0 +1,20 @@
+config USB_CDNS3
+   tristate "Cadence USB3 Dual-Role Controller"
+depends on (USB && USB_GADGET)
+   help
+ Say Y here if your system has a cadence USB3 dual-role controller.
+ It supports: dual-role switch Host-only, and Peripheral-only.
+
+ When compiled dynamically, the module will be called cdns3.ko.
+
+if USB_CDNS3
+
+config USB_CDNS3_GADGET
+   bool "Cadence USB3 device controller"
+   depends on USB_GADGET
+select USB_GADGET_DUALSPEED
+   help
+ Say Y here to enable device controller functionality of the
+ cadence usb3 driver.
+
+endif
diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
new file mode 100644
index 00..374fa06efa
--- /dev/null
+++ b/drivers/usb/cdns3/Makefile
@@ -0,0 +1,5 @@
+obj-$(CONFIG_USB_CDNS3)+= cdns3.o
+
+cdns3-y:= core.o
+cdns3-$(CONFIG_USB_CDNS3_GADGET)   += gadget.o
+cdns3-$(CONFIG_$(SPL_)DM_USB_GADGET)   += cdns3-generic.o
diff --git a/drivers/usb/cdns3/cdns3-generic.c 
b/drivers/usb/cdns3/cdns3-generic.c
new file mode 100644
index 00..6f8d63f74d
--- /dev/null
+++ b/drivers/usb/cdns3/cdns3-generic.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 NXP
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "core.h"
+#include "gadget.h"
+
+static int cdns3_generic_peripheral_clk_init(struct udevice *dev,
+struct cdns3_generic_peripheral
+*priv)
+{
+#if CONFIG_IS_ENABLED(CLK)
+   int ret;
+
+   ret = clk_get_bulk(dev, >clks);
+   if (ret == -ENOSYS)
+   return 0;
+   if (ret)
+   return ret;
+
+   ret = clk_enable_bulk(>clks);
+   if (ret) {
+   clk_release_bulk(>clks);
+   return ret;
+   }
+#endif
+
+   return 0;
+}
+
+int dm_usb_gadget_handle_interrupts(struct udevice *dev)
+{
+   struct cdns3_generic_peripheral *priv = dev_get_priv(dev);
+   struct cdns3 *cdns3 = >cdns3;
+
+   cdns3_role_irq_handler(cdns3);
+
+   ret

[U-Boot] [PATCH v5 1/7] dt-bindings: add dt-binding doc for CDNS3 controller

2019-08-21 Thread Sherry Sun
This patch aim at documenting USB related dt-bindings for the
Cadence USB controller.

Signed-off-by: Sherry Sun 
---
 doc/device-tree-bindings/usb/cdns-usb3.txt | 53 ++
 1 file changed, 53 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt

diff --git a/doc/device-tree-bindings/usb/cdns-usb3.txt 
b/doc/device-tree-bindings/usb/cdns-usb3.txt
new file mode 100644
index 00..8aba13b88a
--- /dev/null
+++ b/doc/device-tree-bindings/usb/cdns-usb3.txt
@@ -0,0 +1,53 @@
+* Cadence USB3 Controller
+
+Required properties:
+- compatible: should contain: "cdns,usb3-1.0.0"
+- reg: physical base address and size of the controller's register areas
+   Controller has 5 different regions:
+   region 1 - NONE-CORE registers area
+   region 2 - HOST registers area
+   region 3 - DEVICE registers area
+   region 4 - PHY registers area
+   region 5 - OTG registers area
+- reg-names - register memory area names:
+   "none-core" - for NONE-CORE registers space
+   "xhci" - for HOST registers space
+   "dev" - for DEVICE registers space
+   "phy" - for PHY registers space
+   "otg" - for OTG registers space
+- interrupts: interrupts used by cdns3 controller
+- interrupt-parent: the interrupt parent for this module
+- clocks: reference to the USB clock
+- clock-names: the name of clocks
+- phys: reference to the USB PHY
+
+Optional properties:
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
+- extcon: extcon phandler for cdns3 device
+- power-domains: the power domain for cdns3 controller and phy
+
+Examples:
+
+usbotg3: cdns3@5b11 {
+   compatible = "cdns,usb3-1.0.0";
+   reg = <0x0 0x5B11 0x0 0x1>,
+   <0x0 0x5B13 0x0 0x1>,
+   <0x0 0x5B14 0x0 0x1>,
+   <0x0 0x5B16 0x0 0x4>,
+   <0x0 0x5B12 0x0 0x1>;
+   reg-names = "none-core", "xhci", "dev", "phy", "otg";
+   interrupt-parent = <>;
+   interrupts = ;
+   clocks = < IMX8QM_USB3_LPM_CLK>,
+   < IMX8QM_USB3_BUS_CLK>,
+   < IMX8QM_USB3_ACLK>,
+   < IMX8QM_USB3_IPG_CLK>,
+   < IMX8QM_USB3_CORE_PCLK>;
+   clock-names = "usb3_lpm_clk", "usb3_bus_clk", "usb3_aclk",
+   "usb3_ipg_clk", "usb3_core_pclk";
+   power-domains = <_conn_usb2>;
+   phys = <>;
+   dr_mode = "otg";
+   extcon = <_ptn5150>;
+   status = "disabled";
+};
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5 0/7] usb: Add cadence USB3 gadget/host/phy driver

2019-08-21 Thread Sherry Sun
These patches introduce new Cadence driver to U-Boot.
The first patch is to add the Cadence USB3 IP(CDNS3) core and driver for 
the usb gadget.
The second patch introduce the xhci-imx8 usb host driver separately.
The third patch introduce the cdns3 phy driver which can be used for both 
cdns3 host driver and gadget driver.
The cdns3 usb gadget/host/phy driver are all used DM mode.

The current driver has been validated on i.MX8 platform.
If someone want to test it, please note that the additional dts nodes/
config macros/clock driver are also essential. You can also get
my test patches at https://github.com/sherrysun1/u-boot-imx.git to 
start your test quickly.

Changes in v5:
 - Delete some unnecessary code.
 - Fix some issues about lack of parentheses.
 - Add separate patch for core framework changes. 
 - Add "reg-names" for usb nodes in DT and use it to get reg
 values.
 - Use "cdns,usb3-1.0.0" compatible instead "cdns,usb3".
 - Add DM_FLAG_OS_PREPARE flag to xhci-imx8 driver.

Sherry Sun (7):
  dt-bindings: add dt-binding doc for CDNS3 controller
  usb: gadget: Add the cadence USB3 gadget driver
  usb: gadget: Add match_ep call back to usb_gadget_ops
  usb: gadget: Add gadget_is_cdns3 checking to provide bcdUSB value
  usb: host: Add the USB3 host driver
  phy: Add USB PHY driver for the cadence USB3
  usb: gadget: core: introduce ->udc_set_speed() method

 Makefile   |1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   53 +
 drivers/phy/Kconfig|8 +
 drivers/phy/Makefile   |1 +
 drivers/phy/cdns3-usb-phy.c|  241 +++
 drivers/usb/Kconfig|2 +
 drivers/usb/cdns3/Kconfig  |   20 +
 drivers/usb/cdns3/Makefile |5 +
 drivers/usb/cdns3/cdns3-generic.c  |  114 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h  |   93 +
 drivers/usb/cdns3/core.c   |  203 ++
 drivers/usb/cdns3/core.h   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h |  116 ++
 drivers/usb/cdns3/dev-regs-map.h   |  117 ++
 drivers/usb/cdns3/gadget-export.h  |   26 +
 drivers/usb/cdns3/gadget.c | 2183 
 drivers/usb/cdns3/gadget.h |  225 ++
 drivers/usb/cdns3/io.h |   27 +
 drivers/usb/gadget/epautoconf.c|4 +
 drivers/usb/gadget/gadget_chips.h  |7 +
 drivers/usb/gadget/udc/Makefile|1 +
 drivers/usb/gadget/udc/udc-core.c  |   23 +
 drivers/usb/host/Kconfig   |9 +
 drivers/usb/host/Makefile  |1 +
 drivers/usb/host/xhci-imx8.c   |  210 ++
 include/linux/usb/gadget.h |5 +
 scripts/Makefile.spl   |1 +
 27 files changed, 3814 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/phy/cdns3-usb-phy.c
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h
 create mode 100644 drivers/usb/host/xhci-imx8.c

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-20 Thread Sherry Sun
Hi Marek,

> 
> On 8/20/19 5:42 PM, Sherry Sun wrote:
> [...]
> 
> >>>>>>> +U_BOOT_DRIVER(xhci_imx8) = {
> >>>>>>> + .name   = "xhci_imx8",
> >>>>>>> + .id = UCLASS_USB,
> >>>>>>> + .of_match = xhci_usb_ids,
> >>>>>>> + .probe = xhci_imx8_probe,
> >>>>>>> + .remove = xhci_imx8_remove,
> >>>>>>> + .ops= _usb_ops,
> >>>>>>> + .platdata_auto_alloc_size = sizeof(struct usb_platdata),
> >>>>>>> + .priv_auto_alloc_size = sizeof(struct xhci_ctrl),
> >>>>>>> + .flags  = DM_FLAG_ALLOC_PRIV_DMA,
> >>>>>>
> >>>>>> I think you also need DM_FLAG_OS_PREPARE to trigger .remove
> >>>>>> before booting Linux, but I might be wrong. Please check that.
> >>>>>
> >>>>> When use usb stop command to stop the usb host driver,
> >>>>> device_remove(bus, DM_REMOVE_NORMAL) is called by usb_stop(), so
> >>>>> normally we don’t need the DM_FLAG_OS_PREPARE flag.
> >>>>> But considering some special circumstances, maybe add this flag is
> helpful.
> >>>>
> >>>> I'm not talking about "usb stop", I am talking about booting Linux.
> >>>> That's when then .remove should be called to tear down the driver. Is it?
> >>>
> >>> I know what you mean. The only function of DM_FLAG_OS_PREPARE is to
> >>> call .remove before booting kernel, to make sure the device is
> >>> removed.
> >>> But normally, the host device is removed every time after we use it.
> >>
> >> How so ? The controller is left running until you call .remove()
> >
> > We usually start the host driver in uboot by using the usb start command,
> right?
> > And we will call usb stop command to finish the usb start command.
> > .remove will be called in usb_stop(). So I think the controller has already
> been teared before booting kernel.
> 
> That is only if you assume that every user will manually call usb stop, 
> always,
> and never fail to do so. And also every piece of code which might have inited
> the USB will also tear down the controller. That is not realistic.
> 
> Hence. you should call the .remove() before boot to tear down the controller.

Okay, you are right, I will add this flag, thanks.

Best regards
Sherry sun
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-20 Thread Sherry Sun
Hi Marek,

> 
> On 8/20/19 5:24 PM, Sherry Sun wrote:
> > Hi Marek,
> 
> Hi,
> 
> >> On 8/20/19 10:31 AM, Sherry Sun wrote:
> >>> Hi Marek,
> >>>
> >>>>
> >>>> On 8/19/19 8:10 AM, Sherry Sun wrote:
> >>>>> Add the USB3 host driver for NXP imx8 platform, and the cadence IP
> >>>>> is in it. The USB3 host driver support DM mode, it will probe USB3
> >>>>> host node in dts.
> >>>>>
> >>>>> Signed-off-by: Sherry Sun 
> >>>>
> >>>> [...]
> >>>>
> >>>>> +static void xhci_imx8_get_reg_addr(struct udevice *dev) {
> >>>>> +   imx8_data.usb3_ctrl_base =
> >>>>> +   (void __iomem *)devfdt_get_addr_index(dev, 0);
> >>>>> +   imx8_data.usb3_core_base =
> >>>>> +   (void __iomem *)devfdt_get_addr_index(dev, 4); }
> >>>>
> >>>> Inline this.
> >>>>
> >>>> Also, look at drivers/mtd/renesas_rpc_hf.c to handle both 32bit and
> >>>> 64bit DTs with multiple "reg" entries.
> >>>>
> >>>
> >>> Actually, I don't think it's needed to change the way getting reg in dts.
> >>> For two reasons:
> >>> 1. This xhci-imx8 driver is only target on imx8 platform which all
> >>> use 64bit
> >> dts.
> >>> 2. devfdt_get_addr_index() can handle both 32/64 bits dts too.
> >>
> >> By hard-coding this "4" offset, you assume the DT is using 64bit
> >> addressing, that's wrong, so please fix it. The iMX8 does support
> >> aarch32, right ? So someone might pass in 32bit DT and this would break.
> >
> > Sorry, maybe there are some misunderstandings in the code.
> > There five reg elements in dts node, which are none_core_regs/ xhci_regs/
> dev_regs/ phy_regs/ otg_regs.
> > devfdt_get_addr_index(dev, 4) only want to get the fifth reg value, instead 
> > of
> meanning 64bit address.
> >
> > 586 usbotg3: usb3@5b11 {
> > 587 compatible = "cdns,usb3";
> > 588 reg = <0x0 0x5B11 0x0 0x1>,
> > 589 <0x0 0x5B13 0x0 0x1>,
> > 590 <0x0 0x5B14 0x0 0x1>,
> > 591 <0x0 0x5B16 0x0 0x4>,
> > 592 <0x0 0x5B12 0x0 0x1>;
> 
> Look the registers up by name then, each entry should have it's own name in
> the DT. git grep for "reg-names" .
> 

Okay, I understand, will change it.

> [...]
> 
> >>> And note that in uboot, one dts node can only bind with one driver,
> >>> so we keep the cdns3 node for usb gadget driver, then add a usb host
> >>> node for
> >>> xhci-imx8 driver in *-uboot.dtsi. so here is no need to change the
> >>> host driver
> >> compatible.
> >>> But the compatible in gadget driver should be changed later.
> >>
> >> We should try avoiding ABI breaks in DT.
> >
> > But the cdns3 usb gaget driver and host driver in different uclass need two 
> > dt
> nodes to bind with.
> > And the compatible of the two node cannot be same.
> > So for gadget driver, the compatible may use "cdns,usb3-1.0.0", for host
> driver, the compatible will use "cdns,usb3-1.0.0-host".
> > What do you think about it?
> 
> CCing Jean, since I think he did solve similar topic for his platform.
> 

Hi, Jean, may you please give me some advice about this problem? Thanks.

> >>>>> +   { }
> >>>>> +};
> >>>>> +
> >>>>> +U_BOOT_DRIVER(xhci_imx8) = {
> >>>>> +   .name   = "xhci_imx8",
> >>>>> +   .id = UCLASS_USB,
> >>>>> +   .of_match = xhci_usb_ids,
> >>>>> +   .probe = xhci_imx8_probe,
> >>>>> +   .remove = xhci_imx8_remove,
> >>>>> +   .ops= _usb_ops,
> >>>>> +   .platdata_auto_alloc_size = sizeof(struct usb_platdata),
> >>>>> +   .priv_auto_alloc_size = sizeof(struct xhci_ctrl),
> >>>>> +   .flags  = DM_FLAG_ALLOC_PRIV_DMA,
> >>>>
> >>>> I think you also need DM_FLAG_OS_PREPARE to trigger .remove before
> >>>> booting Linux, but I might be wrong. Please check that.
> >>>
> >>> When use usb stop command to stop the usb host driver,
> &g

Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-20 Thread Sherry Sun
Hi Marek,

> 
> On 8/20/19 10:31 AM, Sherry Sun wrote:
> > Hi Marek,
> >
> >>
> >> On 8/19/19 8:10 AM, Sherry Sun wrote:
> >>> Add the USB3 host driver for NXP imx8 platform, and the cadence IP
> >>> is in it. The USB3 host driver support DM mode, it will probe USB3
> >>> host node in dts.
> >>>
> >>> Signed-off-by: Sherry Sun 
> >>
> >> [...]
> >>
> >>> +static void xhci_imx8_get_reg_addr(struct udevice *dev) {
> >>> + imx8_data.usb3_ctrl_base =
> >>> + (void __iomem *)devfdt_get_addr_index(dev, 0);
> >>> + imx8_data.usb3_core_base =
> >>> + (void __iomem *)devfdt_get_addr_index(dev, 4); }
> >>
> >> Inline this.
> >>
> >> Also, look at drivers/mtd/renesas_rpc_hf.c to handle both 32bit and
> >> 64bit DTs with multiple "reg" entries.
> >>
> >
> > Actually, I don't think it's needed to change the way getting reg in dts.
> > For two reasons:
> > 1. This xhci-imx8 driver is only target on imx8 platform which all use 64bit
> dts.
> > 2. devfdt_get_addr_index() can handle both 32/64 bits dts too.
> 
> By hard-coding this "4" offset, you assume the DT is using 64bit addressing,
> that's wrong, so please fix it. The iMX8 does support aarch32, right ? So
> someone might pass in 32bit DT and this would break.

Sorry, maybe there are some misunderstandings in the code.
There five reg elements in dts node, which are none_core_regs/ xhci_regs/ 
dev_regs/ phy_regs/ otg_regs.
devfdt_get_addr_index(dev, 4) only want to get the fifth reg value, instead of 
meanning 64bit address.

586 usbotg3: usb3@5b11 {
587 compatible = "cdns,usb3";
588 reg = <0x0 0x5B11 0x0 0x1>,
589 <0x0 0x5B13 0x0 0x1>,
590 <0x0 0x5B14 0x0 0x1>,
591 <0x0 0x5B16 0x0 0x4>,
592 <0x0 0x5B12 0x0 0x1>;

> 
> >> [...]
> >>
> >>> +static const struct udevice_id xhci_usb_ids[] = {
> >>> + { .compatible = "cdns,usb3-host", },
> >>
> >> https://lore.ker
> >>
> nel.org%2Fpatchwork%2Fpatch%2F1059917%2Fdata=02%7C01%7Cshe
> >>
> rry.sun%40nxp.com%7C70e116ce152a4060dbd508d724987b54%7C686ea1d
> >>
> 3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637018109631327748sd
> >>
> ata=GzX5KNQ8m0CCeBa9tPSV%2BOEwwuSsxDdAiJd1T6or8P0%3Dreser
> >> ved=0 would suggest that
> >> cdns,usb3-1.0.0 is the compatible. But I might be wrong.
> >
> > This patch has not been accepted by the kernel, right?
> > So I think maybe we can do this change to synchronize with kernel
> > after the cdns3 kernel patch been accepted.
> 
> Or, we can start with at least reasonably OK DT compatible right away to
> reasonably avoid ABI breakage.

Sure, will change the compatible from "cdns,usb3" to "cdns,usb3-1.0.0".

> 
> > And note that in uboot, one dts node can only bind with one driver, so
> > we keep the cdns3 node for usb gadget driver, then add a usb host node
> > for
> > xhci-imx8 driver in *-uboot.dtsi. so here is no need to change the host 
> > driver
> compatible.
> > But the compatible in gadget driver should be changed later.
> 
> We should try avoiding ABI breaks in DT.

But the cdns3 usb gaget driver and host driver in different uclass need two dt 
nodes to bind with.
And the compatible of the two node cannot be same.
So for gadget driver, the compatible may use "cdns,usb3-1.0.0", for host 
driver, the compatible will use "cdns,usb3-1.0.0-host".
What do you think about it?

> 
> >>> + { }
> >>> +};
> >>> +
> >>> +U_BOOT_DRIVER(xhci_imx8) = {
> >>> + .name   = "xhci_imx8",
> >>> + .id = UCLASS_USB,
> >>> + .of_match = xhci_usb_ids,
> >>> + .probe = xhci_imx8_probe,
> >>> + .remove = xhci_imx8_remove,
> >>> + .ops= _usb_ops,
> >>> + .platdata_auto_alloc_size = sizeof(struct usb_platdata),
> >>> + .priv_auto_alloc_size = sizeof(struct xhci_ctrl),
> >>> + .flags  = DM_FLAG_ALLOC_PRIV_DMA,
> >>
> >> I think you also need DM_FLAG_OS_PREPARE to trigger .remove before
> >> booting Linux, but I might be wrong. Please check that.
> >
> > When use usb stop command to stop the usb host driver,
> > device_remove(bus, DM_REMOVE_NORMAL) is called by usb_stop(), so
> > normally we don’t need the DM_FLAG_OS_PREPARE flag.
> > But considering some special circumstances, maybe add this flag is helpful.
> 
> I'm not talking about "usb stop", I am talking about booting Linux.
> That's when then .remove should be called to tear down the driver. Is it?

I know what you mean. The only function of DM_FLAG_OS_PREPARE 
is to call .remove before booting kernel, to make sure the device is 
removed.
But normally, the host device is removed every time after we use it.
So even the flag is set, the .remove won't be called again before booting kernel
because the device is checked to be removed already.
Add the flag just make sure the device will be removed before booting kernel.
Do you think so?

Best regard
Sherry sun
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-20 Thread Sherry Sun
Hi Marek,

> 
> On 8/19/19 8:10 AM, Sherry Sun wrote:
> > Add the USB3 host driver for NXP imx8 platform, and the cadence IP is
> > in it. The USB3 host driver support DM mode, it will probe USB3 host
> > node in dts.
> >
> > Signed-off-by: Sherry Sun 
> 
> [...]
> 
> > +static void xhci_imx8_get_reg_addr(struct udevice *dev) {
> > +   imx8_data.usb3_ctrl_base =
> > +   (void __iomem *)devfdt_get_addr_index(dev, 0);
> > +   imx8_data.usb3_core_base =
> > +   (void __iomem *)devfdt_get_addr_index(dev, 4); }
> 
> Inline this.
> 
> Also, look at drivers/mtd/renesas_rpc_hf.c to handle both 32bit and 64bit DTs
> with multiple "reg" entries.
> 

Actually, I don't think it's needed to change the way getting reg in dts.
For two reasons:
1. This xhci-imx8 driver is only target on imx8 platform which all use 64bit 
dts.
2. devfdt_get_addr_index() can handle both 32/64 bits dts too.

> [...]
> 
> > +static const struct udevice_id xhci_usb_ids[] = {
> > +   { .compatible = "cdns,usb3-host", },
> 
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ker
> nel.org%2Fpatchwork%2Fpatch%2F1059917%2Fdata=02%7C01%7Cshe
> rry.sun%40nxp.com%7C70e116ce152a4060dbd508d724987b54%7C686ea1d
> 3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637018109631327748sd
> ata=GzX5KNQ8m0CCeBa9tPSV%2BOEwwuSsxDdAiJd1T6or8P0%3Dreser
> ved=0 would suggest that
> cdns,usb3-1.0.0 is the compatible. But I might be wrong.

This patch has not been accepted by the kernel, right?
So I think maybe we can do this change to synchronize with kernel after the 
cdns3 
kernel patch been accepted. And note that in uboot, one dts node can only bind 
with
one driver, so we keep the cdns3 node for usb gadget driver, then add a usb 
host node for 
xhci-imx8 driver in *-uboot.dtsi. so here is no need to change the host driver 
compatible.
But the compatible in gadget driver should be changed later.

> 
> > +   { }
> > +};
> > +
> > +U_BOOT_DRIVER(xhci_imx8) = {
> > +   .name   = "xhci_imx8",
> > +   .id = UCLASS_USB,
> > +   .of_match = xhci_usb_ids,
> > +   .probe = xhci_imx8_probe,
> > +   .remove = xhci_imx8_remove,
> > +   .ops= _usb_ops,
> > +   .platdata_auto_alloc_size = sizeof(struct usb_platdata),
> > +   .priv_auto_alloc_size = sizeof(struct xhci_ctrl),
> > +   .flags  = DM_FLAG_ALLOC_PRIV_DMA,
> 
> I think you also need DM_FLAG_OS_PREPARE to trigger .remove before booting
> Linux, but I might be wrong. Please check that.

When use usb stop command to stop the usb host driver, 
device_remove(bus, DM_REMOVE_NORMAL) is called by usb_stop(),
so normally we don’t need the DM_FLAG_OS_PREPARE flag.
But considering some special circumstances, maybe add this flag is helpful.

Best regard
Sherry sun
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 1/4] USB: gadget: Add the cadence USB3 gadget driver

2019-08-20 Thread Sherry Sun
Hi Marek,

> 
> On 8/19/19 8:10 AM, Sherry Sun wrote:
> > This driver is ported from NXP i.MX U-Boot version imx_v2019.04 and
> > some changes have also been made to adapt to U-Boot.
> >
> > Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode).
> > The CDNS3 gadget driver support DM mode. CONFIG_DM_USB_GADGET
> should
> > be enabled when use this driver.
> >
> > Signed-off-by: Sherry Sun 
> 
> [...]
> 
> > +static int cdns_req_ep0_set_configuration(struct usb_ss_dev *usb_ss,
> > + struct usb_ctrlrequest *ctrl_req) {
> > +   enum usb_device_state device_state = usb_ss->gadget.state;
> > +   u32 config = le16_to_cpu(ctrl_req->wValue);
> > +   struct usb_ep *ep;
> > +   struct usb_ss_endpoint *usb_ss_ep, *temp_ss_ep;
> > +   int i, result = 0;
> > +
> > +   switch (device_state) {
> > +   case USB_STATE_ADDRESS:
> > +   /* Configure non-control EPs */
> > +   list_for_each_entry_safe(usb_ss_ep, temp_ss_ep,
> > +_ss->ep_match_list,
> > +ep_match_pending_list) {
> > +   cdns_ep_config(usb_ss_ep);
> > +   list_del(_ss_ep->ep_match_pending_list);
> > +   }
> > +
> > +   list_for_each_entry(ep, _ss->gadget.ep_list, ep_list) {
> > +   usb_ss_ep = to_usb_ss_ep(ep);
> > +   if (usb_ss_ep->used)
> > +   cdns_ep_config(usb_ss_ep);
> > +   }
> > +
> > +#ifdef CDNS_THREADED_IRQ_HANDLING
> > +   usb_ss->ep_ien = cdns_readl(_ss->regs->ep_ien)
> > +   | EP_IEN__EOUTEN0__MASK | EP_IEN__EINEN0__MASK; #endif
> 
> This is probably not needed ?
> 

Yes, you are right, I have removed those unneeded code.

> [...]
> 
> > +/* Common TRB fields */
> > +#define TRB_SET_CYCLE_BIT  1uL
> > +#define TRB_SET_CHAIN_BIT  0x10
> > +
> > +/* offset 0 */
> > +#define TRB_DATA_BUFFER_POINTER_MASK   0x
> > +#define TRB_SET_DATA_BUFFER_POINTER(p) (p &
> TRB_DATA_BUFFER_POINTER_MASK)
> > +
> > +/* offset 4 */
> > +#define TRB_TRANSFER_LENGTH_MASK   0x1
> > +#define TRB_SET_TRANSFER_LENGTH(l) (l &
> TRB_TRANSFER_LENGTH_MASK)
> > +
> > +#define TRB_BURST_LENGTH_MASK  0xFF
> > +#define TRB_SET_BURST_LENGTH(l)((l & TRB_BURST_LENGTH_MASK)
> << 24)
> > +
> > +/* offset 8 */
> > +#define TRB_SET_INT_ON_SHORT_PACKET0x04
> > +#define TRB_SET_FIFO_MODE  0x08
> > +#define TRB_SET_INT_ON_COMPLETION  0x20
> > +
> > +#define TRB_TYPE_NORMAL0x400
> > +
> > +#define TRB_STREAM_ID_MASK 0x
> > +#define TRB_SET_STREAM_ID(sid) ((sid & TRB_STREAM_ID_MASK) <<
> 16)
> > +
> 
> $sid needs parenthesis, that is (((sid) & TRB_STREAM_ID_MASK) << 16)
> 
> there are a few more such issues above, fix them too.

Okay, thanks for reminding.

> 
> [...]
> 
> > +#endif /* __DRIVERS_CDNS3_GADGET */
> > diff --git a/drivers/usb/cdns3/io.h b/drivers/usb/cdns3/io.h new file
> > mode 100644 index 00..22b1b03950
> > --- /dev/null
> > +++ b/drivers/usb/cdns3/io.h
> > @@ -0,0 +1,30 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Copyright (C) 2016 Cadence Design Systems -
> >
> +https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww
> >
> +.cadence.com%2Fdata=02%7C01%7Csherry.sun%40nxp.com%7C8c397
> 93120e
> >
> +840bf693608d7249879e6%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%
> 7C0%7C63
> >
> +7018109609981006sdata=aCuyDMx%2Fv8Bp3hSAG%2FrFenr3duDX5
> UG2GaByBf
> > +hDuk8%3Dreserved=0
> > + * Copyright 2019 NXP
> > + */
> > +
> > +#ifndef __DRIVERS_USB_CDNS_IO_H
> > +#define __DRIVERS_USB_CDNS_IO_H
> > +
> > +#include 
> > +
> > +static inline u32 cdns_readl(u32 __iomem *reg) {
> > +   u32 value = 0;
> 
> return readl() ? The value is assigned twice here, for no reason.

I have fixed this issue.

> 
> > +   value = readl(reg);
> > +   return value;
> > +}
> > +
> > +static inline void cdns_writel(u32 __iomem *reg, u32 value) {
> > +   writel(value, reg);
> > +}
> > +
> > +static inline void cdns_flush_cache(uintptr_t addr, int length) {
> > +   flush_dcache_range(addr, addr + ROUND(length,
> ARCH_DMA_MINALIGN));
> 
> Drop the ROUND() thi

[U-Boot] [PATCH v4 1/4] USB: gadget: Add the cadence USB3 gadget driver

2019-08-19 Thread Sherry Sun
This driver is ported from NXP i.MX U-Boot version imx_v2019.04
and some changes have also been made to adapt to U-Boot.

Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode).
The CDNS3 gadget driver support DM mode. CONFIG_DM_USB_GADGET should
be enabled when use this driver.

Signed-off-by: Sherry Sun 
---
 Makefile   |1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   39 +
 drivers/usb/Kconfig|2 +
 drivers/usb/cdns3/Kconfig  |   20 +
 drivers/usb/cdns3/Makefile |5 +
 drivers/usb/cdns3/cdns3-generic.c  |  113 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h  |   93 +
 drivers/usb/cdns3/core.c   |  203 ++
 drivers/usb/cdns3/core.h   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h |  116 +
 drivers/usb/cdns3/dev-regs-map.h   |  117 ++
 drivers/usb/cdns3/gadget-export.h  |   26 +
 drivers/usb/cdns3/gadget.c | 2218 
 drivers/usb/cdns3/gadget.h |  225 ++
 drivers/usb/cdns3/io.h |   30 +
 drivers/usb/gadget/epautoconf.c|4 +
 drivers/usb/gadget/gadget_chips.h  |7 +
 drivers/usb/gadget/udc/Makefile|1 +
 include/linux/usb/gadget.h |3 +
 scripts/Makefile.spl   |1 +
 20 files changed, 3342 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h

diff --git a/Makefile b/Makefile
index 8513db94e3..fab1220114 100644
--- a/Makefile
+++ b/Makefile
@@ -728,6 +728,7 @@ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
 libs-$(CONFIG_$(SPL_)ALTERA_SDRAM) += drivers/ddr/altera/
 libs-y += drivers/serial/
+libs-y += drivers/usb/cdns3/
 libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/common/
 libs-y += drivers/usb/emul/
diff --git a/doc/device-tree-bindings/usb/cdns-usb3.txt 
b/doc/device-tree-bindings/usb/cdns-usb3.txt
new file mode 100644
index 00..0c8710507d
--- /dev/null
+++ b/doc/device-tree-bindings/usb/cdns-usb3.txt
@@ -0,0 +1,39 @@
+* Cadence USB3 Controller
+
+Required properties:
+- compatible: "cdns,usb3";
+- reg: base address and length of the registers
+- interrupts: interrupt for the USB controller
+- interrupt-parent: the interrupt parent for this module
+- clocks: reference to the USB clock
+- clock-names: the name of clocks
+- phys: reference to the USB PHY
+
+Optional properties:
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
+- extcon: extcon phandler for cdns3 device
+- power-domains: the power domain for cdns3 controller and phy
+
+Examples:
+
+usbotg3: cdns3@5b11 {
+   compatible = "cdns,usb3";
+   reg = <0x0 0x5B11 0x0 0x1>,
+   <0x0 0x5B13 0x0 0x1>,
+   <0x0 0x5B14 0x0 0x1>,
+   <0x0 0x5B16 0x0 0x4>;
+   interrupt-parent = <>;
+   interrupts = ;
+   clocks = < IMX8QM_USB3_LPM_CLK>,
+   < IMX8QM_USB3_BUS_CLK>,
+   < IMX8QM_USB3_ACLK>,
+   < IMX8QM_USB3_IPG_CLK>,
+   < IMX8QM_USB3_CORE_PCLK>;
+   clock-names = "usb3_lpm_clk", "usb3_bus_clk", "usb3_aclk",
+   "usb3_ipg_clk", "usb3_core_pclk";
+   power-domains = <_conn_usb2>;
+   phys = <>;
+   dr_mode = "otg";
+   extcon = <_ptn5150>;
+   status = "disabled";
+};
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 3b53bf2c58..98f5e936e5 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -70,6 +70,8 @@ source "drivers/usb/host/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
 
+source "drivers/usb/cdns3/Kconfig"
+
 source "drivers/usb/musb/Kconfig"
 
 source "drivers/usb/musb-new/Kconfig"
diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
new file mode 100644
index 00..11a7144b05
--- /dev/null
+++ b/drivers/usb/cdns3/Kconfig
@@ -0,0 +1,20 @@
+config USB_CDNS3
+   tristate "Cadence USB3 Dual-Role Controller"
+depends on (USB && USB_GADGET)
+   help
+  

Re: [U-Boot] [PATCH 0/4] Make some changes to SDP

2019-08-19 Thread Sherry Sun
Hi Angus,

I have just finished the SDP test on imx8mq_evk and the SDP can work with some 
board configs.
I guess it may be two problems that lead your SDP can't work on imx8mq_evk. You 
can add
the follow two changes and test it again.

The first change:
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -262,6 +262,7 @@ struct usb_ep *usb_ep_autoconfig(
ep = find_ep(gadget, "ep1-bulk");
if (ep && ep_matches(gadget, ep, desc))
return ep;
+#ifndef CONFIG_SPL_BUILD
} else if (gadget_is_dwc3(gadget)) {
const char *name = NULL;
/*
@@ -284,6 +285,7 @@ struct usb_ep *usb_ep_autoconfig(
ep = find_ep(gadget, name);
if (ep && ep_matches(gadget, ep, desc))
return ep;
+#endif
}

The second change:
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -55,6 +55,13 @@ void enable_tzc380(void)
/* Enable TZASC and lock setting */
setbits_le32(>gpr[10], GPR_TZASC_EN);
setbits_le32(>gpr[10], GPR_TZASC_EN_LOCK);
+
+   /*
+* set Region 0 attribute to allow secure and non-secure read/write 
permission
+* Found some masters like usb dwc3 controllers can't work with secure 
memory.
+*/
+   writel(0xf000, TZASC_BASE_ADDR + 0x108);
+
}

If there is anything you don’t understand, you can also get my test patches at
https://github.com/sherrysun1/u-boot-imx.git. You just need check the first 
four patches  which I
used to test for imx8mq_evk.

And feel free to let me know if any problems.

Best regards
Sherry sun



Hi Sherry,

On Aug. 8, 2019 2:38 a.m., Sherry Sun 
mailto:sherry@nxp.com>> wrote:

Hi Angus,

Sorry for the late reply.

>
> Hi Peng,
>
> On 2019-08-01 18:01, Peng Fan wrote:
> > Angus,
> >
> >> Subject: Re: 答复: [U-Boot] [PATCH 0/4] Make some changes to SDP
> >>
> >> Hi Sherry,
> >>
> >> On 2019-07-31 19:56, Sherry Sun wrote:
> >> > Hi Angus
> >> >
> >> >>
> >> >> Hi Sherry,
> >> >>
> >> >> On 2019-07-17 18:40, sherry sun wrote:
> >> >> > From: Sherry Sun mailto:sherry@nxp.com>>
> >> >> >
> >> >> > This patchset adds:
> >> >> > 1. Add usb_gadget_initialize() and usb_gadget_release() to
> >> >> > initialize and release UDC during sdp download.
> >> >> > 2. Add high speed endpoint descriptor for sdp.
> >> >> > 3. Add a macro definition--CONFIG_SDP_LOADADDR as default sdp
> >> >> > load address while SDP_WRITE and SDP_JUMP command addr is zero.
> >> >> >
> >> >> > Sherry Sun (4):
> >> >> >   imx: spl: Change USB boot device type
> >> >> >   SDP: use CONFIG_SDP_LOADADDR as default load address
> >> >> >   SDP: fix wrong usb request size and add high speed endpoint
> >> >> > descriptor
> >> >> >   SDP: Call usb_gadget_initialize and usb_gadget_release to
> >> >> > support UDC
> >> >>
> >> >> These changes look like like they target SDP on imx8. For imx8mq
> >> >> is this all that is required to get SDP working with uuu or are
> >> >> there additional changes required ?
> >> >>
> >> >
> >> > The changes in patch 1/4 are target on both imx8 and imx8m.
> >> > The rest three patches are target on all boards which used SDP.
> >> > So for imx8mq, if your usb gadget driver is ready ,these changes
> >> > are enough to get SDP working with UUU.
> >> >
> >>
> >> I'm trying to use SDP on the imx8mq-evk but it doesn't look like it's
> >> enabled there. Do you have patches to enable SDP on the imx8mq-evk ,
> >> even if they aren't ready to go upstream ?
> >
> > You could try downstream code,
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsour
> >
> ce.codeaurora.org%2Fexternal%2Fimx%2Fuboot-imx%2Fdata=02%7C01
> %7Cs
> >
> herry.sun%40nxp.com%7C6d63289fbb104168bce308d716f157c4%7C686ea1
> d3bc2b4
> >
> c6fa92cd99c5c301635%7C0%7C0%7C637003098143081621sdata=beh
> 08%2Fv3f
> > s8ZZPP29F1iVMfo3uNTWGf91SYYyak2GVU%3Dreserved=0
> > branch: imx_v2019.04_4.19.35_1.0.0
> >
>
> I already have SDP  working with the vendor u-boot. I'm trying to switch to
> mainline u-boot so I'm looking for mainline patches.
>

May I ask, is your usb gadget driver is working? 

[U-Boot] [PATCH v4 3/4] phy: Add USB PHY driver for the cadence USB3

2019-08-19 Thread Sherry Sun
The cdns3-usb-phy driver supports both host and peripheral
mode of usb driver which use cadence usb3 IP.

Signed-off-by: Sherry Sun 
---
 drivers/phy/Kconfig |   8 ++
 drivers/phy/Makefile|   1 +
 drivers/phy/cdns3-usb-phy.c | 241 
 3 files changed, 250 insertions(+)
 create mode 100644 drivers/phy/cdns3-usb-phy.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 957efb3984..6e50365d90 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -190,4 +190,12 @@ config MT76X8_USB_PHY
 
  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+   bool "Support CDNS3 USB PHY"
+   depends on PHY
+   help
+ Support for the USB PHY in CDNS3 IP.
+
+ This PHY is found on CDNS3 IP devices supporting USB.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 90646ca55b..d9933e0439 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -21,3 +21,4 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
 obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
 obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
 obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
diff --git a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c
new file mode 100644
index 00..c0d308075b
--- /dev/null
+++ b/drivers/phy/cdns3-usb-phy.c
@@ -0,0 +1,241 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Cadence3 USB PHY driver
+ *
+ * Author: Sherry Sun 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* PHY registers */
+#define PHY_PMA_CMN_CTRL1  (0xC800 * 4)
+#define TB_ADDR_CMN_DIAG_HSCLK_SEL (0x01e0 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR   (0x0084 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR   (0x0085 * 4)
+#define TB_ADDR_CMN_PLL0_INTDIV(0x0094 * 4)
+#define TB_ADDR_CMN_PLL0_FRACDIV   (0x0095 * 4)
+#define TB_ADDR_CMN_PLL0_HIGH_THR  (0x0096 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL1  (0x0098 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL2  (0x0099 * 4)
+#define TB_ADDR_CMN_PLL0_DSM_DIAG  (0x0097 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_OVRD (0x01c2 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD (0x01c0 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD (0x01c1 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE  (0x01C5 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE   (0x01C6 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG   (0x01C7 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE(0x01c4 * 4)
+#define TB_ADDR_CMN_PSM_CLK_CTRL   (0x0061 * 4)
+#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR  (0x40ea * 4)
+#define TB_ADDR_XCVR_PSM_RCTRL (0x4001 * 4)
+#define TB_ADDR_TX_PSC_A0  (0x4100 * 4)
+#define TB_ADDR_TX_PSC_A1  (0x4101 * 4)
+#define TB_ADDR_TX_PSC_A2  (0x4102 * 4)
+#define TB_ADDR_TX_PSC_A3  (0x4103 * 4)
+#define TB_ADDR_TX_DIAG_ECTRL_OVRD (0x41f5 * 4)
+#define TB_ADDR_TX_PSC_CAL (0x4106 * 4)
+#define TB_ADDR_TX_PSC_RDY (0x4107 * 4)
+#define TB_ADDR_RX_PSC_A0  (0x8000 * 4)
+#define TB_ADDR_RX_PSC_A1  (0x8001 * 4)
+#define TB_ADDR_RX_PSC_A2  (0x8002 * 4)
+#define TB_ADDR_RX_PSC_A3  (0x8003 * 4)
+#define TB_ADDR_RX_PSC_CAL (0x8006 * 4)
+#define TB_ADDR_RX_PSC_RDY (0x8007 * 4)
+#define TB_ADDR_TX_TXCC_MGNLS_MULT_000 (0x4058 * 4)
+#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY (0x41e7 * 4)
+#define TB_ADDR_RX_SLC_CU_ITER_TMR (0x80e3 * 4)
+#define TB_ADDR_RX_SIGDET_HL_FILT_TMR  (0x8090 * 4)
+#define TB_ADDR_RX_SAMP_DAC_CTRL   (0x8058 * 4)
+#define TB_ADDR_RX_DIAG_SIGDET_TUNE(0x81dc * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE2  (0x81df * 4)
+#define TB_ADDR_RX_DIAG_BS_TM  (0x81f5 * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL1  (0x81d3 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM4  (0x81c7 * 4)
+#define TB_ADDR_RX_DIAG_ILL_E_TRIM0(0x81c2 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQ_TRIM0   (0x81c1 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM6  (0x81c9 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM3   (0x81f8 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM4   (0x81f9 * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE   (0x81dd * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL3  (0x81d5 * 4)
+#define TB_ADDR_RX_DIAG_SC2C_DELAY (0x81e1 * 4)
+#define TB_ADDR_RX_REE_VGA_GAIN_NODFE  (0x81bf * 4)
+#define TB_ADDR_XCVR_PSM_CAL_TMR   (0x4002 * 4)
+#define TB_ADDR_XCVR_PSM_A0BYP_TMR (0x4004 * 4

[U-Boot] [PATCH v4 4/4] USB: gadget: core: introduce ->udc_set_speed() method

2019-08-19 Thread Sherry Sun
This patch was copied from kernel commit: 67fdfda4a99ed.

Sometimes, the gadget driver we want to run has max_speed lower than
what the UDC supports. In such situations, UDC might want to make sure
we don't try to connect on speeds not supported by the gadget
driver because that will just fail.

So here introduce a new optional ->udc_set_speed() method which can be
implemented by interested UDC drivers to achieve this purpose.

Signed-off-by: Sherry Sun 
---
 drivers/usb/gadget/udc/udc-core.c | 23 +++
 include/linux/usb/gadget.h|  2 ++
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 62b47781dd..8d1d90e3e3 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -267,6 +267,27 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
 /* - */
 
+/**
+ * usb_gadget_udc_set_speed - tells usb device controller speed supported by
+ *current driver
+ * @udc: The device we want to set maximum speed
+ * @speed: The maximum speed to allowed to run
+ *
+ * This call is issued by the UDC Class driver before calling
+ * usb_gadget_udc_start() in order to make sure that we don't try to
+ * connect on speeds the gadget driver doesn't support.
+ */
+static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
+   enum usb_device_speed speed)
+{
+   if (udc->gadget->ops->udc_set_speed) {
+   enum usb_device_speed s;
+
+   s = min(speed, udc->gadget->max_speed);
+   udc->gadget->ops->udc_set_speed(udc->gadget, s);
+   }
+}
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver 
*driver)
 {
int ret;
@@ -276,6 +297,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct 
usb_gadget_driver *dri
 
udc->driver = driver;
 
+   usb_gadget_udc_set_speed(udc, driver->speed);
+
ret = driver->bind(udc->gadget);
if (ret)
goto err1;
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index a34f3478f3..78e245a1b5 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -450,6 +450,8 @@ struct usb_gadget_ops {
int   (*match_ep)(struct usb_gadget *gadget,
  struct usb_ep *ep,
  struct usb_endpoint_descriptor *desc);
+   void(*udc_set_speed)(struct usb_gadget *gadget,
+enum usb_device_speed);
 };
 
 /**
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4 2/4] USB: host: Add the USB3 host driver

2019-08-19 Thread Sherry Sun
Add the USB3 host driver for NXP imx8 platform, and the
cadence IP is in it. The USB3 host driver support DM
mode, it will probe USB3 host node in dts.

Signed-off-by: Sherry Sun 
---
 drivers/usb/host/Kconfig |   9 ++
 drivers/usb/host/Makefile|   1 +
 drivers/usb/host/xhci-imx8.c | 209 +++
 3 files changed, 219 insertions(+)
 create mode 100644 drivers/usb/host/xhci-imx8.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index ac68aa2d27..8360ca3869 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -95,6 +95,15 @@ config USB_XHCI_FSL
depends on !SPL_NO_USB
help
  Enables support for the on-chip xHCI controller on NXP Layerscape 
SoCs.
+
+config USB_XHCI_IMX8
+   bool "XHCI support for i.MX8"
+   depends on ARCH_IMX8
+   default y
+   help
+ Enables support for the on-chip xHCI controller on i.MX8QM and
+ i.MX8QXP SoCs.
+
 endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 6aa574f6f7..e5a0a4ea5a 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
 obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
 obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
+obj-$(CONFIG_USB_XHCI_IMX8) += xhci-imx8.o
 
 # designware
 obj-$(CONFIG_USB_DWC2) += dwc2.o
diff --git a/drivers/usb/host/xhci-imx8.c b/drivers/usb/host/xhci-imx8.c
new file mode 100644
index 00..20a0196060
--- /dev/null
+++ b/drivers/usb/host/xhci-imx8.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * NXP i.MX8 USB HOST xHCI Controller (Cadence IP)
+ *
+ * Author: Peter Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "xhci.h"
+
+/* Declare global data pointer */
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Host registers */
+#define HCIVERSION_CAPLENGTH   0x1
+#define USBSTS 0x10084
+
+/* None-core registers */
+#define USB3_CORE_CTRL10x00
+#define USB3_CORE_STATUS   0x0c
+#define USB3_SSPHY_STATUS  0x4c
+
+/* USB3_CORE_CTRL1 */
+#define ALL_SW_RESET   0xfc00
+#define MODE_STRAP_MASK0x7
+#define PHYAHB_SW_RESETBIT(26)
+#define OC_DISABLE BIT(9)
+#define HOST_MODE  BIT(1)
+#define OTG_MODE   BIT(0)
+
+/* USB3_CORE_STATUS */
+#define HOST_POWER_ON_READYBIT(12)
+
+/* USBSTS */
+#define CONTROLLER_NOT_READY   BIT(11)
+
+/* USB3_SSPHY_STATUS */
+#define CLK_VLD0xf000
+
+struct xhci_imx8_data {
+   void __iomem *usb3_ctrl_base;
+   void __iomem *usb3_core_base;
+   struct clk_bulk clks;
+   struct phy phy;
+};
+
+static struct xhci_imx8_data imx8_data;
+
+static int imx8_xhci_init(void)
+{
+   int ret;
+
+   writel(CLK_VLD, imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   ret = wait_for_bit_le32(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS,
+   CLK_VLD, true, 100, false);
+   if (ret) {
+   printf("clkvld is incorrect\n");
+   return ret;
+   }
+
+   clrsetbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1,
+   MODE_STRAP_MASK,  HOST_MODE | OC_DISABLE);
+   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1,
+PHYAHB_SW_RESET);
+   generic_phy_init(_data.phy);
+
+   /* clear all sw_rst */
+   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1, ALL_SW_RESET);
+
+   debug("wait xhci_power_on_ready\n");
+   ret = wait_for_bit_le32(imx8_data.usb3_ctrl_base + USB3_CORE_STATUS,
+   HOST_POWER_ON_READY, true, 100, false);
+   if (ret) {
+   printf("wait xhci_power_on_ready timeout\n");
+   return ret;
+   }
+   debug("xhci_power_on_ready\n");
+
+   debug("waiting CNR\n");
+   ret = wait_for_bit_le32(imx8_data.usb3_core_base + USBSTS,
+   CONTROLLER_NOT_READY, false, 100, false);
+   if (ret) {
+   printf("wait CNR timeout\n");
+   return ret;
+   }
+   debug("check CNR has finished\n");
+
+   return 0;
+}
+
+static void imx8_xhci_reset(void)
+{
+   /* Set CORE ctrl to default value, that all rst are hold */
+   writel(ALL_SW_RESET | OTG_MODE,
+  imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1);
+}
+
+static int xhci_imx8_clk_init(struct udevice *dev)
+{
+   int ret;
+
+   ret = clk_get_bulk(dev, _data.clks);
+   if (ret)
+   return ret;
+
+   ret = clk_enable_bulk(_data.clks);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+static void xhci_imx8_get_reg_addr(struct

[U-Boot] [PATCH v4 0/4] USB: Add cadence USB3 gadget/host/phy driver

2019-08-19 Thread Sherry Sun
These patches introduce new Cadence driver to U-Boot.
The first patch is to add the Cadence USB3 IP(CDNS3) core and driver for 
the usb gadget.
The second patch introduce the xhci-imx8 usb host driver separately.
The third patch introduce the cdns3 phy driver which can be used for both 
cdns3 host driver and gadget driver.
The cdns3 usb gadget/host/phy driver are all used DM mode.

The current driver has been validated on i.MX8 platform.
If someone want to test it, please note that the additional dts nodes/
config macros/clock driver are also essential. You can also get
my test patches at https://github.com/sherrysun1/u-boot-imx.git to 
start your test quickly.

Changes in v4:
 - Keep all include list in files sorted.
 - Delete the unnecessary registers read in code. 
 - Add ret return after wait_for_bit_le32() is failed. 
 - Add macros instead those magic values. 

Sherry Sun (4):
  USB: gadget: Add the cadence USB3 gadget driver
  USB: host: Add the USB3 host driver
  phy: Add USB PHY driver for the cadence USB3
  USB: gadget: core: introduce ->udc_set_speed() method

 Makefile   |1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   39 +
 drivers/phy/Kconfig|8 +
 drivers/phy/Makefile   |1 +
 drivers/phy/cdns3-usb-phy.c|  241 +++
 drivers/usb/Kconfig|2 +
 drivers/usb/cdns3/Kconfig  |   20 +
 drivers/usb/cdns3/Makefile |5 +
 drivers/usb/cdns3/cdns3-generic.c  |  113 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h  |   93 +
 drivers/usb/cdns3/core.c   |  203 ++
 drivers/usb/cdns3/core.h   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h |  116 +
 drivers/usb/cdns3/dev-regs-map.h   |  117 ++
 drivers/usb/cdns3/gadget-export.h  |   26 +
 drivers/usb/cdns3/gadget.c | 2218 
 drivers/usb/cdns3/gadget.h |  225 ++
 drivers/usb/cdns3/io.h |   30 +
 drivers/usb/gadget/epautoconf.c|4 +
 drivers/usb/gadget/gadget_chips.h  |7 +
 drivers/usb/gadget/udc/Makefile|1 +
 drivers/usb/gadget/udc/udc-core.c  |   23 +
 drivers/usb/host/Kconfig   |9 +
 drivers/usb/host/Makefile  |1 +
 drivers/usb/host/xhci-imx8.c   |  209 ++
 include/linux/usb/gadget.h |5 +
 scripts/Makefile.spl   |1 +
 27 files changed, 3836 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/phy/cdns3-usb-phy.c
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h
 create mode 100644 drivers/usb/host/xhci-imx8.c

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 2/4] USB: host: Add the USB3 host driver

2019-08-18 Thread Sherry Sun
Hi Marek,

> 
> On 8/16/19 8:10 AM, Sherry Sun wrote:
> 
> [...]
> 
> > diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index
> > ac68aa2d27..cc1dfe463b 100644
> > --- a/drivers/usb/host/Kconfig
> > +++ b/drivers/usb/host/Kconfig
> > @@ -95,6 +95,15 @@ config USB_XHCI_FSL
> > depends on !SPL_NO_USB
> > help
> >   Enables support for the on-chip xHCI controller on NXP Layerscape
> SoCs.
> > +
> > +config USB_XHCI_IMX8
> > +   bool "XHCI support for imx8"
> 
> i.MX8 I guess ?

Yes, you are right, I have changed these to i.MX8 instead of imx8.

> 
> [...]
> 
> > diff --git a/drivers/usb/host/xhci-imx8.c
> > b/drivers/usb/host/xhci-imx8.c new file mode 100644 index
> > 00..0669a05c17
> > --- /dev/null
> > +++ b/drivers/usb/host/xhci-imx8.c
> > @@ -0,0 +1,189 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright 2019 NXP
> > + *
> > + * NXP i.MX8 USB HOST xHCI Controller (Cadence IP)
> > + *
> > + * Author: Peter Chen   */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> Keep the list sorted

Okay, I have done this.

> 
> > +#include "xhci.h"
> > +
> > +/* Declare global data pointer */
> > +DECLARE_GLOBAL_DATA_PTR;
> > +
> > +/* Host registers */
> > +#define HCIVERSION_CAPLENGTH  0x1
> > +#define USBSTS0x10084
> > +
> > +/* None-core registers */
> > +#define USB3_CORE_CTRL10x00
> > +#define USB3_CORE_STATUS   0x0c
> > +#define USB3_SSPHY_STATUS  0x4c
> > +
> > +struct xhci_imx8_data {
> > +   void __iomem *usb3_ctrl_base;
> > +   void __iomem *usb3_core_base;
> > +   struct clk_bulk clks;
> > +   struct phy phy;
> > +};
> > +
> > +static struct xhci_imx8_data imx8_data;
> > +
> > +static void imx8_xhci_init(void)
> > +{
> > +   u32 tmp_data;
> > +   int ret;
> > +
> > +   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
> > +   writel(tmp_data, imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
> 
> Is this read-write really needed ?

I reviewed this register definition. And found the read is not needed, but the 
write is needed.
I have changed this read-write already.

> 
> > +   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
> > +   ret = wait_for_bit_le32(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS,
> > +   0xf000, true, 100, false);
> > +   if (ret)
> > +   printf("clkvld is incorrect\n");
> 
> Shouldn't this return ret ?

Okay, have done this.
> 
> > +   clrsetbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1,
> > +   0x7, 0x202);
> > +   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1, 1 << 26);
> > +   generic_phy_init(_data.phy);
> > +
> > +   /* clear all sw_rst */
> > +   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1, 0xFC <<
> > +24);
> > +
> > +   debug("wait xhci_power_on_ready\n");
> > +   ret = wait_for_bit_le32(imx8_data.usb3_ctrl_base + USB3_CORE_STATUS,
> > +   0x1000, true, 100, false);
> > +   if (ret)
> > +   printf("wait xhci_power_on_ready timeout\n");
> 
> return ret on failure ?
Okay, have done this.

> 
> > +   debug("xhci_power_on_ready\n");
> > +
> > +   debug("waiting CNR 0x%x\n", tmp_data);
> > +   ret = wait_for_bit_le32(imx8_data.usb3_core_base + USBSTS,
> > +   0x800, false, 100, false);
> > +   if (ret)
> > +   printf("wait CNR timeout\n");
> 
> return ret on failure ?
Okay, have done this.

> 
> > +   debug("check CNR has finished\n");
> > +}
> > +
> > +static void imx8_xhci_reset(void)
> > +{
> > +   /* Set CORE ctrl to default value, that all rst are hold */
> > +   writel(0xfc01, imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1);
> 
> What are these magic values ? Add macros for them.
Okay, have done this.

> 
> > +}
> > +
> > +static int xhci_imx8_clk_init(struct udevice *dev) {
> > +   int ret;
> > +
> > +   ret = clk_get_bulk(dev, _data.clks);
> > +   if (ret)
> > +   return ret;
> > +
> > +   ret = clk_enable_bulk(_data.clks);
> &g

[U-Boot] 答复: 答复: [PATCH v2 1/4] USB: gadget: Add the cadence USB3 gadget driver

2019-08-17 Thread Sherry Sun
Hi Marek

> 
> On 8/16/19 6:45 AM, Sherry Sun wrote:
> > Hi Marek
> >
> >>
> >> On 8/14/19 2:16 PM, sherry sun wrote:
> >>> From: Sherry Sun 
> >>>
> >>> This driver is ported from NXP i.MX U-Boot version imx_v2019.04 and
> >>> some changes have also been made to adapt to U-Boot.
> >>>
> >>> Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode).
> >>> The CDNS3 gadget driver support DM mode. CONFIG_DM_USB_GADGET
> >> should
> >>> be enabled when use this driver. And gadget_is_cdns3 checking is
> >>> added to provide bcdUSB value in device descriptor.
> >>
> >> The cadence core isn't xhci compatible ? Sigh ...
> >>
> >
> > Actually, I'm not very understand what the xhci compatible means?
> > The cadence core can support usb peripheral and host. But for now, we
> > just done the gadget part in the core code. If it needed later, we can
> > add the host part to it.
> 
> So this is all needed to support gadget on the cadence3 ?

Yes, this patch is all needed for cdns3 usb gadget driver.
I have already validated this on i.MX8 platform.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 1/4] USB: gadget: Add the cadence USB3 gadget driver

2019-08-16 Thread Sherry Sun
This driver is ported from NXP i.MX U-Boot version imx_v2019.04
and some changes have also been made to adapt to U-Boot.

Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode).
The CDNS3 gadget driver support DM mode. CONFIG_DM_USB_GADGET should
be enabled when use this driver.

Signed-off-by: Sherry Sun 
---
 Makefile   |1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   39 +
 drivers/usb/Kconfig|2 +
 drivers/usb/cdns3/Kconfig  |   20 +
 drivers/usb/cdns3/Makefile |5 +
 drivers/usb/cdns3/cdns3-generic.c  |  115 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h  |   89 +
 drivers/usb/cdns3/core.c   |  194 ++
 drivers/usb/cdns3/core.h   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h |  116 +
 drivers/usb/cdns3/dev-regs-map.h   |  117 ++
 drivers/usb/cdns3/gadget-export.h  |   26 +
 drivers/usb/cdns3/gadget.c | 2218 
 drivers/usb/cdns3/gadget.h |  225 ++
 drivers/usb/cdns3/io.h |   30 +
 drivers/usb/gadget/epautoconf.c|4 +
 drivers/usb/gadget/gadget_chips.h  |7 +
 drivers/usb/gadget/udc/Makefile|1 +
 include/linux/usb/gadget.h |3 +
 scripts/Makefile.spl   |1 +
 20 files changed, 3331 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h

diff --git a/Makefile b/Makefile
index 8513db94e3..fab1220114 100644
--- a/Makefile
+++ b/Makefile
@@ -728,6 +728,7 @@ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
 libs-$(CONFIG_$(SPL_)ALTERA_SDRAM) += drivers/ddr/altera/
 libs-y += drivers/serial/
+libs-y += drivers/usb/cdns3/
 libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/common/
 libs-y += drivers/usb/emul/
diff --git a/doc/device-tree-bindings/usb/cdns-usb3.txt 
b/doc/device-tree-bindings/usb/cdns-usb3.txt
new file mode 100644
index 00..0c8710507d
--- /dev/null
+++ b/doc/device-tree-bindings/usb/cdns-usb3.txt
@@ -0,0 +1,39 @@
+* Cadence USB3 Controller
+
+Required properties:
+- compatible: "cdns,usb3";
+- reg: base address and length of the registers
+- interrupts: interrupt for the USB controller
+- interrupt-parent: the interrupt parent for this module
+- clocks: reference to the USB clock
+- clock-names: the name of clocks
+- phys: reference to the USB PHY
+
+Optional properties:
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
+- extcon: extcon phandler for cdns3 device
+- power-domains: the power domain for cdns3 controller and phy
+
+Examples:
+
+usbotg3: cdns3@5b11 {
+   compatible = "cdns,usb3";
+   reg = <0x0 0x5B11 0x0 0x1>,
+   <0x0 0x5B13 0x0 0x1>,
+   <0x0 0x5B14 0x0 0x1>,
+   <0x0 0x5B16 0x0 0x4>;
+   interrupt-parent = <>;
+   interrupts = ;
+   clocks = < IMX8QM_USB3_LPM_CLK>,
+   < IMX8QM_USB3_BUS_CLK>,
+   < IMX8QM_USB3_ACLK>,
+   < IMX8QM_USB3_IPG_CLK>,
+   < IMX8QM_USB3_CORE_PCLK>;
+   clock-names = "usb3_lpm_clk", "usb3_bus_clk", "usb3_aclk",
+   "usb3_ipg_clk", "usb3_core_pclk";
+   power-domains = <_conn_usb2>;
+   phys = <>;
+   dr_mode = "otg";
+   extcon = <_ptn5150>;
+   status = "disabled";
+};
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 3b53bf2c58..98f5e936e5 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -70,6 +70,8 @@ source "drivers/usb/host/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
 
+source "drivers/usb/cdns3/Kconfig"
+
 source "drivers/usb/musb/Kconfig"
 
 source "drivers/usb/musb-new/Kconfig"
diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
new file mode 100644
index 00..11a7144b05
--- /dev/null
+++ b/drivers/usb/cdns3/Kconfig
@@ -0,0 +1,20 @@
+config USB_CDNS3
+   tristate "Cadence USB3 Dual-Role Controller"
+depends on (USB && USB_GADGET)
+   help
+  

[U-Boot] [PATCH v3 4/4] USB: gadget: core: introduce ->udc_set_speed() method

2019-08-16 Thread Sherry Sun
This patch was copied from kernel commit: 67fdfda4a99ed.

Sometimes, the gadget driver we want to run has max_speed lower than
what the UDC supports. In such situations, UDC might want to make sure
we don't try to connect on speeds not supported by the gadget
driver because that will just fail.

So here introduce a new optional ->udc_set_speed() method which can be
implemented by interested UDC drivers to achieve this purpose.

Signed-off-by: Sherry Sun 
---
 drivers/usb/gadget/udc/udc-core.c | 23 +++
 include/linux/usb/gadget.h|  2 ++
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 62b47781dd..8d1d90e3e3 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -267,6 +267,27 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
 /* - */
 
+/**
+ * usb_gadget_udc_set_speed - tells usb device controller speed supported by
+ *current driver
+ * @udc: The device we want to set maximum speed
+ * @speed: The maximum speed to allowed to run
+ *
+ * This call is issued by the UDC Class driver before calling
+ * usb_gadget_udc_start() in order to make sure that we don't try to
+ * connect on speeds the gadget driver doesn't support.
+ */
+static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
+   enum usb_device_speed speed)
+{
+   if (udc->gadget->ops->udc_set_speed) {
+   enum usb_device_speed s;
+
+   s = min(speed, udc->gadget->max_speed);
+   udc->gadget->ops->udc_set_speed(udc->gadget, s);
+   }
+}
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver 
*driver)
 {
int ret;
@@ -276,6 +297,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct 
usb_gadget_driver *dri
 
udc->driver = driver;
 
+   usb_gadget_udc_set_speed(udc, driver->speed);
+
ret = driver->bind(udc->gadget);
if (ret)
goto err1;
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index a34f3478f3..78e245a1b5 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -450,6 +450,8 @@ struct usb_gadget_ops {
int   (*match_ep)(struct usb_gadget *gadget,
  struct usb_ep *ep,
  struct usb_endpoint_descriptor *desc);
+   void(*udc_set_speed)(struct usb_gadget *gadget,
+enum usb_device_speed);
 };
 
 /**
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 2/4] USB: host: Add the USB3 host driver

2019-08-16 Thread Sherry Sun
Add the USB3 host driver for NXP imx8 platform, and the
cadence IP is in it. The USB3 host driver support DM
mode, it will probe USB3 host node in dts.

Signed-off-by: Sherry Sun 
---
 drivers/usb/host/Kconfig |   9 ++
 drivers/usb/host/Makefile|   1 +
 drivers/usb/host/xhci-imx8.c | 189 +++
 3 files changed, 199 insertions(+)
 create mode 100644 drivers/usb/host/xhci-imx8.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index ac68aa2d27..cc1dfe463b 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -95,6 +95,15 @@ config USB_XHCI_FSL
depends on !SPL_NO_USB
help
  Enables support for the on-chip xHCI controller on NXP Layerscape 
SoCs.
+
+config USB_XHCI_IMX8
+   bool "XHCI support for imx8"
+   depends on ARCH_IMX8
+   default y
+   help
+ Enables support for the on-chip xHCI controller on imx8qm and
+ imx8qxp SoCs.
+
 endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 6aa574f6f7..e5a0a4ea5a 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
 obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
 obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
+obj-$(CONFIG_USB_XHCI_IMX8) += xhci-imx8.o
 
 # designware
 obj-$(CONFIG_USB_DWC2) += dwc2.o
diff --git a/drivers/usb/host/xhci-imx8.c b/drivers/usb/host/xhci-imx8.c
new file mode 100644
index 00..0669a05c17
--- /dev/null
+++ b/drivers/usb/host/xhci-imx8.c
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * NXP i.MX8 USB HOST xHCI Controller (Cadence IP)
+ *
+ * Author: Peter Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "xhci.h"
+
+/* Declare global data pointer */
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Host registers */
+#define HCIVERSION_CAPLENGTH  0x1
+#define USBSTS0x10084
+
+/* None-core registers */
+#define USB3_CORE_CTRL10x00
+#define USB3_CORE_STATUS   0x0c
+#define USB3_SSPHY_STATUS  0x4c
+
+struct xhci_imx8_data {
+   void __iomem *usb3_ctrl_base;
+   void __iomem *usb3_core_base;
+   struct clk_bulk clks;
+   struct phy phy;
+};
+
+static struct xhci_imx8_data imx8_data;
+
+static void imx8_xhci_init(void)
+{
+   u32 tmp_data;
+   int ret;
+
+   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   writel(tmp_data, imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   ret = wait_for_bit_le32(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS,
+   0xf000, true, 100, false);
+   if (ret)
+   printf("clkvld is incorrect\n");
+
+   clrsetbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1,
+   0x7, 0x202);
+   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1, 1 << 26);
+   generic_phy_init(_data.phy);
+
+   /* clear all sw_rst */
+   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1, 0xFC << 24);
+
+   debug("wait xhci_power_on_ready\n");
+   ret = wait_for_bit_le32(imx8_data.usb3_ctrl_base + USB3_CORE_STATUS,
+   0x1000, true, 100, false);
+   if (ret)
+   printf("wait xhci_power_on_ready timeout\n");
+   debug("xhci_power_on_ready\n");
+
+   debug("waiting CNR 0x%x\n", tmp_data);
+   ret = wait_for_bit_le32(imx8_data.usb3_core_base + USBSTS,
+   0x800, false, 100, false);
+   if (ret)
+   printf("wait CNR timeout\n");
+   debug("check CNR has finished\n");
+}
+
+static void imx8_xhci_reset(void)
+{
+   /* Set CORE ctrl to default value, that all rst are hold */
+   writel(0xfc01, imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1);
+}
+
+static int xhci_imx8_clk_init(struct udevice *dev)
+{
+   int ret;
+
+   ret = clk_get_bulk(dev, _data.clks);
+   if (ret)
+   return ret;
+
+   ret = clk_enable_bulk(_data.clks);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+static int xhci_imx8_get_reg_addr(struct udevice *dev)
+{
+   imx8_data.usb3_ctrl_base =
+   (void __iomem *)devfdt_get_addr_index(dev, 0);
+   imx8_data.usb3_core_base =
+   (void __iomem *)devfdt_get_addr_index(dev, 4);
+
+   return 0;
+}
+
+static int xhci_imx8_probe(struct udevice *dev)
+{
+   struct xhci_hccr *hccr;
+   struct xhci_hcor *hcor;
+   struct udevice usbotg_dev;
+   struct power_domain pd;
+   int usbot

[U-Boot] [PATCH v3 3/4] phy: Add USB PHY driver for the cadence USB3

2019-08-16 Thread Sherry Sun
The cdns3-usb-phy driver supports both host and peripheral
mode of usb driver which use cadence usb3 IP.

Signed-off-by: Sherry Sun 
---
 drivers/phy/Kconfig |   8 ++
 drivers/phy/Makefile|   1 +
 drivers/phy/cdns3-usb-phy.c | 243 
 3 files changed, 252 insertions(+)
 create mode 100644 drivers/phy/cdns3-usb-phy.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 957efb3984..6e50365d90 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -190,4 +190,12 @@ config MT76X8_USB_PHY
 
  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+   bool "Support CDNS3 USB PHY"
+   depends on PHY
+   help
+ Support for the USB PHY in CDNS3 IP.
+
+ This PHY is found on CDNS3 IP devices supporting USB.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 90646ca55b..d9933e0439 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -21,3 +21,4 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
 obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
 obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
 obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
diff --git a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c
new file mode 100644
index 00..b060db3c14
--- /dev/null
+++ b/drivers/phy/cdns3-usb-phy.c
@@ -0,0 +1,243 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Cadence3 USB PHY driver
+ *
+ * Author: Sherry Sun 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* PHY registers */
+#define PHY_PMA_CMN_CTRL1  (0xC800 * 4)
+#define TB_ADDR_CMN_DIAG_HSCLK_SEL (0x01e0 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR   (0x0084 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR   (0x0085 * 4)
+#define TB_ADDR_CMN_PLL0_INTDIV(0x0094 * 4)
+#define TB_ADDR_CMN_PLL0_FRACDIV   (0x0095 * 4)
+#define TB_ADDR_CMN_PLL0_HIGH_THR  (0x0096 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL1  (0x0098 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL2  (0x0099 * 4)
+#define TB_ADDR_CMN_PLL0_DSM_DIAG  (0x0097 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_OVRD (0x01c2 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD (0x01c0 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD (0x01c1 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE  (0x01C5 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE   (0x01C6 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG   (0x01C7 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE(0x01c4 * 4)
+#define TB_ADDR_CMN_PSM_CLK_CTRL   (0x0061 * 4)
+#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR  (0x40ea * 4)
+#define TB_ADDR_XCVR_PSM_RCTRL (0x4001 * 4)
+#define TB_ADDR_TX_PSC_A0  (0x4100 * 4)
+#define TB_ADDR_TX_PSC_A1  (0x4101 * 4)
+#define TB_ADDR_TX_PSC_A2  (0x4102 * 4)
+#define TB_ADDR_TX_PSC_A3  (0x4103 * 4)
+#define TB_ADDR_TX_DIAG_ECTRL_OVRD (0x41f5 * 4)
+#define TB_ADDR_TX_PSC_CAL (0x4106 * 4)
+#define TB_ADDR_TX_PSC_RDY (0x4107 * 4)
+#define TB_ADDR_RX_PSC_A0  (0x8000 * 4)
+#define TB_ADDR_RX_PSC_A1  (0x8001 * 4)
+#define TB_ADDR_RX_PSC_A2  (0x8002 * 4)
+#define TB_ADDR_RX_PSC_A3  (0x8003 * 4)
+#define TB_ADDR_RX_PSC_CAL (0x8006 * 4)
+#define TB_ADDR_RX_PSC_RDY (0x8007 * 4)
+#define TB_ADDR_TX_TXCC_MGNLS_MULT_000 (0x4058 * 4)
+#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY (0x41e7 * 4)
+#define TB_ADDR_RX_SLC_CU_ITER_TMR (0x80e3 * 4)
+#define TB_ADDR_RX_SIGDET_HL_FILT_TMR  (0x8090 * 4)
+#define TB_ADDR_RX_SAMP_DAC_CTRL   (0x8058 * 4)
+#define TB_ADDR_RX_DIAG_SIGDET_TUNE(0x81dc * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE2  (0x81df * 4)
+#define TB_ADDR_RX_DIAG_BS_TM  (0x81f5 * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL1  (0x81d3 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM4  (0x81c7 * 4)
+#define TB_ADDR_RX_DIAG_ILL_E_TRIM0(0x81c2 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQ_TRIM0   (0x81c1 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM6  (0x81c9 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM3   (0x81f8 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM4   (0x81f9 * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE   (0x81dd * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL3  (0x81d5 * 4)
+#define TB_ADDR_RX_DIAG_SC2C_DELAY (0x81e1 * 4)
+#define TB_ADDR_RX_REE_VGA_GAIN_NODFE  (0x81bf * 4)
+#define TB_ADDR_XCVR_PSM_CAL_TMR   (0x4002 * 4)
+#define TB_ADDR_XCVR_PSM_A0BYP_TMR (0x4004 * 4

[U-Boot] [PATCH v3 0/4] USB: Add cadence USB3 gadget/host/phy driver

2019-08-16 Thread Sherry Sun
These patches introduce new Cadence driver to U-Boot.
The first patch is to add the Cadence USB3 IP(CDNS3) core and driver for 
the usb gadget.
The second patch introduce the xhci-imx8 usb host driver separately.
The third patch introduce the cdns3 phy driver which can be used for both 
cdns3 host driver and gadget driver.
The cdns3 usb gadget/host/phy driver are all used DM mode.

The current driver has been validated on i.MX8 platform.
If someone want to test it, please note that the additional dts nodes/
config macros/clock driver are also essential. You can also get
my test patches at https://github.com/sherrysun1/u-boot-imx.git to 
start your test quickly.

Changes in v3:
 - Changed all compatible from "Cadence,usb3" to "cdns,usb3".
 - Use wait_for_bit_le32() and clrsetbits_le32() globally. 
 - Use u32 instead of unint_32 globally. 
 - Split cdns3_set_role() into two functions: 
   cdns3_host_role_set() and cdns3_gadget_role_set().

Sherry Sun (4):
  USB: gadget: Add the cadence USB3 gadget driver
  USB: host: Add the USB3 host driver
  phy: Add USB PHY driver for the cadence USB3
  USB: gadget: core: introduce ->udc_set_speed() method

 Makefile   |1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   39 +
 drivers/phy/Kconfig|8 +
 drivers/phy/Makefile   |1 +
 drivers/phy/cdns3-usb-phy.c|  243 +++
 drivers/usb/Kconfig|2 +
 drivers/usb/cdns3/Kconfig  |   20 +
 drivers/usb/cdns3/Makefile |5 +
 drivers/usb/cdns3/cdns3-generic.c  |  115 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h  |   89 +
 drivers/usb/cdns3/core.c   |  194 ++
 drivers/usb/cdns3/core.h   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h |  116 +
 drivers/usb/cdns3/dev-regs-map.h   |  117 ++
 drivers/usb/cdns3/gadget-export.h  |   26 +
 drivers/usb/cdns3/gadget.c | 2218 
 drivers/usb/cdns3/gadget.h |  225 ++
 drivers/usb/cdns3/io.h |   30 +
 drivers/usb/gadget/epautoconf.c|4 +
 drivers/usb/gadget/gadget_chips.h  |7 +
 drivers/usb/gadget/udc/Makefile|1 +
 drivers/usb/gadget/udc/udc-core.c  |   23 +
 drivers/usb/host/Kconfig   |9 +
 drivers/usb/host/Makefile  |1 +
 drivers/usb/host/xhci-imx8.c   |  189 ++
 include/linux/usb/gadget.h |5 +
 scripts/Makefile.spl   |1 +
 27 files changed, 3807 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/phy/cdns3-usb-phy.c
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h
 create mode 100644 drivers/usb/host/xhci-imx8.c

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: [PATCH v2 1/4] USB: gadget: Add the cadence USB3 gadget driver

2019-08-15 Thread Sherry Sun
Hi Marek

> 
> On 8/14/19 2:16 PM, sherry sun wrote:
> > From: Sherry Sun 
> >
> > This driver is ported from NXP i.MX U-Boot version imx_v2019.04 and
> > some changes have also been made to adapt to U-Boot.
> >
> > Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode).
> > The CDNS3 gadget driver support DM mode. CONFIG_DM_USB_GADGET
> should
> > be enabled when use this driver. And gadget_is_cdns3 checking is added
> > to provide bcdUSB value in device descriptor.
> 
> The cadence core isn't xhci compatible ? Sigh ...
> 

Actually, I'm not very understand what the xhci compatible means?
The cadence core can support usb peripheral and host. But for now,
we just done the gadget part in the core code. If it needed later, we 
can add the host part to it.

> [...]
> 
> > +++ b/doc/device-tree-bindings/usb/cdns-usb3.txt
> > @@ -0,0 +1,39 @@
> > +* Cadence USB3 Controller
> > +
> > +Required properties:
> > +- compatible: "Cadence,usb3";
> 
> cdns , no ?

Yes, I have already changed all compatible to "cdns,usb3".

> 
> [...]
> 
> > +static int cdns3_generic_peripheral_clk_init(struct udevice *dev,
> > +struct cdns3_generic_peripheral
> > +*priv)
> > +{
> > +   int ret;
> > +
> > +   ret = clk_get_bulk(dev, >clks);
> > +   if (ret)
> > +   return ret;
> > +
> > +#if CONFIG_IS_ENABLED(CLK)
> 
> Why is the ifdef protecting only half of the clock functions ?

Because the clk_get_bulk() also has function define even if CONFIG_CLK is not 
defined.
So this way would not cause undefined reference error.
But for the sake of uniformity, I will move clk_get_bulk() into the ifdef 
protecting.

> 
> > +   ret = clk_enable_bulk(>clks);
> > +   if (ret) {
> > +   clk_release_bulk(>clks);
> > +   return ret;
> > +   }
> > +#endif
> > +
> > +   return 0;
> > +}
> 
> 
> [...]
> 
> > +static void cdns3_set_role(struct cdns3 *cdns, enum cdns3_roles role)
> > +{
> > +   u32 value;
> > +   int timeout_us = 10;
> > +   struct cdns3_generic_peripheral *priv = container_of(cdns,
> > +   struct cdns3_generic_peripheral, cdns3);
> > +
> > +   if (role == CDNS3_ROLE_END)
> > +   return;
> > +
> > +   /* Wait clk value */
> > +   value = readl(cdns->none_core_regs + USB3_SSPHY_STATUS);
> > +   writel(value, cdns->none_core_regs + USB3_SSPHY_STATUS);
> > +   udelay(1);
> > +   value = readl(cdns->none_core_regs + USB3_SSPHY_STATUS);
> > +   while ((value & 0xf000) != 0xf000 && timeout_us-- > 0) {
> > +   value = readl(cdns->none_core_regs + USB3_SSPHY_STATUS);
> > +   udelay(1);
> > +   }
> 
> Is this like wait_for_bit() ?

Yes, thanks for the reminder, I have already use wait_for_bit_le32() to replace 
these.

> 
> > +   if (timeout_us <= 0)
> > +   dev_err(cdns->dev, "wait clkvld timeout\n");
> > +
> > +   /* Set all Reset bits */
> > +   setbits_le32(cdns->none_core_regs + USB3_CORE_CTRL1,
> ALL_SW_RESET);
> > +   udelay(1);
> > +
> > +   if (role == CDNS3_ROLE_HOST) {
> 
> Do we need custom controller role definition ? I don't think so, just use the
> one in the USB stack.
> 

Actually we need create an array with two elements to store the corresponding 
host/gadge 
function pointer in struct cdns3. And use CDNS3_ROLE_END to do the check.
If we use the role define in USB stack, the array[USB_DR_MODE_UNKNOWN] will 
always be 
defined but not used. So I think the controller role definition is needed here. 
But if you really think the controller role definition isn’t appropriate, I 
will change it.

 10 enum cdns3_roles {
 11 CDNS3_ROLE_HOST = 0,
 12 CDNS3_ROLE_GADGET,
 13 CDNS3_ROLE_END,
 14 };

 12 enum usb_dr_mode {
 13 USB_DR_MODE_UNKNOWN,
 14 USB_DR_MODE_HOST,
 15 USB_DR_MODE_PERIPHERAL,
 16 USB_DR_MODE_OTG,
 17 };

> Also, use clrsetbits_le32()
Sure.

> 
> > +   value = readl(cdns->none_core_regs + USB3_CORE_CTRL1);
> > +   value = (value & ~MODE_STRAP_MASK) | HOST_MODE |
> OC_DISABLE;
> > +   writel(value, cdns->none_core_regs + USB3_CORE_CTRL1);
> > +   clrbits_le32(cdns->none_core_regs + USB3_CORE_CTRL1,
> > +PHYAHB_SW_RESET);
> > +   mdelay(1);
> > +   generic_phy_init(>phy);
> > +   setbits_le32(cdns->phy_regs + TB_ADDR_TX_RCVDETSC_CTR

[U-Boot] 答复: [PATCH v2 2/4] USB: host: Add the USB3 host driver

2019-08-14 Thread Sherry Sun
Hi Marek,
> 
> Hi Marek,
> 
> >
> > On 8/14/19 2:16 PM, sherry sun wrote:
> > > From: Sherry Sun 
> > >
> > > Add the USB3 host driver for NXP imx8 platform, and the cadence IP
> > > is in it. The USB3 host driver support DM mode, it will probe USB3
> > > host node in dts.
> >
> > We already have a generic xhci driver, so why do we need that massive
> > custom cadence driver ?
> 
> Sorry, may I ask which generic xhci driver do you mean?

Actually, this xhci-imx8 driver only did some specific work, such as call phy 
driver, non-core registers configurate and so on. 
The generic xhci configurate work still done in xhci.c by calling 
xhci_register()
in xhci_imx8_probe(). So I think this specific driver is needed.

Best regards
Sherry sun

> 
> Best regards
> Sherry sun
> ___
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.de
> nx.de%2Flistinfo%2Fu-bootdata=02%7C01%7Csherry.sun%40nxp.com%
> 7C568638198c214b189ffe08d721215f9c%7C686ea1d3bc2b4c6fa92cd99c5c3
> 01635%7C0%7C0%7C637014299551499522sdata=jg%2BsBQWN4BxBt
> UPbpOEQdl%2F2JppSg5NSfsb0fWQkIk0%3Dreserved=0
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: [PATCH v2 2/4] USB: host: Add the USB3 host driver

2019-08-14 Thread Sherry Sun
Hi Marek,

> 
> On 8/14/19 2:16 PM, sherry sun wrote:
> > From: Sherry Sun 
> >
> > Add the USB3 host driver for NXP imx8 platform, and the cadence IP is
> > in it. The USB3 host driver support DM mode, it will probe USB3 host
> > node in dts.
> 
> We already have a generic xhci driver, so why do we need that massive custom
> cadence driver ?

Sorry, may I ask which generic xhci driver do you mean?

Best regards
Sherry sun
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 1/4] USB: gadget: Add the cadence USB3 gadget driver

2019-08-14 Thread sherry sun
From: Sherry Sun 

This driver is ported from NXP i.MX U-Boot version imx_v2019.04
and some changes have also been made to adapt to U-Boot.

Add the Cadence USB3 IP(CDNS3) driver for the gadget (device mode).
The CDNS3 gadget driver support DM mode. CONFIG_DM_USB_GADGET should
be enabled when use this driver. And gadget_is_cdns3 checking is
added to provide bcdUSB value in device descriptor.

Signed-off-by: Sherry Sun 
---
 Makefile   |1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   39 +
 drivers/usb/Kconfig|2 +
 drivers/usb/cdns3/Kconfig  |   20 +
 drivers/usb/cdns3/Makefile |5 +
 drivers/usb/cdns3/cdns3-generic.c  |  115 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h  |   89 +
 drivers/usb/cdns3/core.c   |  197 ++
 drivers/usb/cdns3/core.h   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h |  116 +
 drivers/usb/cdns3/dev-regs-map.h   |  117 ++
 drivers/usb/cdns3/gadget-export.h  |   26 +
 drivers/usb/cdns3/gadget.c |  
 drivers/usb/cdns3/gadget.h |  225 ++
 drivers/usb/cdns3/io.h |   30 +
 drivers/usb/gadget/epautoconf.c|4 +
 drivers/usb/gadget/gadget_chips.h  |7 +
 drivers/usb/gadget/udc/Makefile|1 +
 include/linux/usb/gadget.h |3 +
 scripts/Makefile.spl   |1 +
 20 files changed, 3338 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h

diff --git a/Makefile b/Makefile
index 8513db94e3..fab1220114 100644
--- a/Makefile
+++ b/Makefile
@@ -728,6 +728,7 @@ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
 libs-$(CONFIG_$(SPL_)ALTERA_SDRAM) += drivers/ddr/altera/
 libs-y += drivers/serial/
+libs-y += drivers/usb/cdns3/
 libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/common/
 libs-y += drivers/usb/emul/
diff --git a/doc/device-tree-bindings/usb/cdns-usb3.txt 
b/doc/device-tree-bindings/usb/cdns-usb3.txt
new file mode 100644
index 00..613a460e7b
--- /dev/null
+++ b/doc/device-tree-bindings/usb/cdns-usb3.txt
@@ -0,0 +1,39 @@
+* Cadence USB3 Controller
+
+Required properties:
+- compatible: "Cadence,usb3";
+- reg: base address and length of the registers
+- interrupts: interrupt for the USB controller
+- interrupt-parent: the interrupt parent for this module
+- clocks: reference to the USB clock
+- clock-names: the name of clocks
+- phys: reference to the USB PHY
+
+Optional properties:
+- dr_mode: One of "host", "peripheral" or "otg". Defaults to "otg"
+- extcon: extcon phandler for cdns3 device
+- power-domains: the power domain for cdns3 controller and phy
+
+Examples:
+
+usbotg3: cdns3@5b11 {
+   compatible = "Cadence,usb3";
+   reg = <0x0 0x5B11 0x0 0x1>,
+   <0x0 0x5B13 0x0 0x1>,
+   <0x0 0x5B14 0x0 0x1>,
+   <0x0 0x5B16 0x0 0x4>;
+   interrupt-parent = <>;
+   interrupts = ;
+   clocks = < IMX8QM_USB3_LPM_CLK>,
+   < IMX8QM_USB3_BUS_CLK>,
+   < IMX8QM_USB3_ACLK>,
+   < IMX8QM_USB3_IPG_CLK>,
+   < IMX8QM_USB3_CORE_PCLK>;
+   clock-names = "usb3_lpm_clk", "usb3_bus_clk", "usb3_aclk",
+   "usb3_ipg_clk", "usb3_core_pclk";
+   power-domains = <_conn_usb2>;
+   phys = <>;
+   dr_mode = "otg";
+   extcon = <_ptn5150>;
+   status = "disabled";
+};
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 3b53bf2c58..98f5e936e5 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -70,6 +70,8 @@ source "drivers/usb/host/Kconfig"
 
 source "drivers/usb/dwc3/Kconfig"
 
+source "drivers/usb/cdns3/Kconfig"
+
 source "drivers/usb/musb/Kconfig"
 
 source "drivers/usb/musb-new/Kconfig"
diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
new file mode 100644
index 00..11a7144b05
--- /dev/null
+++ b/drivers/usb/cdns3/Kconfig
@@ -0,0 +1,20 @@
+config USB_CDNS3
+   t

[U-Boot] [PATCH v2 3/4] phy: Add USB PHY driver for the cadence USB3

2019-08-14 Thread sherry sun
From: Sherry Sun 

The cdns3-usb-phy driver supports both host and peripheral
mode of usb driver which use cadence usb3 IP.

Signed-off-by: Sherry Sun 
---
 drivers/phy/Kconfig |   8 ++
 drivers/phy/Makefile|   1 +
 drivers/phy/cdns3-usb-phy.c | 242 
 3 files changed, 251 insertions(+)
 create mode 100644 drivers/phy/cdns3-usb-phy.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 957efb3984..6e50365d90 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -190,4 +190,12 @@ config MT76X8_USB_PHY
 
  This PHY is found on MT76x8 devices supporting USB.
 
+config CDNS3_USB_PHY
+   bool "Support CDNS3 USB PHY"
+   depends on PHY
+   help
+ Support for the USB PHY in CDNS3 IP.
+
+ This PHY is found on CDNS3 IP devices supporting USB.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 90646ca55b..d9933e0439 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -21,3 +21,4 @@ obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
 obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
 obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
 obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
+obj-$(CONFIG_CDNS3_USB_PHY) += cdns3-usb-phy.o
diff --git a/drivers/phy/cdns3-usb-phy.c b/drivers/phy/cdns3-usb-phy.c
new file mode 100644
index 00..0cd8ed4a7c
--- /dev/null
+++ b/drivers/phy/cdns3-usb-phy.c
@@ -0,0 +1,242 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * Cadence3 USB PHY driver
+ *
+ * Author: Sherry Sun 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* PHY registers */
+#define PHY_PMA_CMN_CTRL1  (0xC800 * 4)
+#define TB_ADDR_CMN_DIAG_HSCLK_SEL (0x01e0 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR   (0x0084 * 4)
+#define TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR   (0x0085 * 4)
+#define TB_ADDR_CMN_PLL0_INTDIV(0x0094 * 4)
+#define TB_ADDR_CMN_PLL0_FRACDIV   (0x0095 * 4)
+#define TB_ADDR_CMN_PLL0_HIGH_THR  (0x0096 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL1  (0x0098 * 4)
+#define TB_ADDR_CMN_PLL0_SS_CTRL2  (0x0099 * 4)
+#define TB_ADDR_CMN_PLL0_DSM_DIAG  (0x0097 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_OVRD (0x01c2 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD (0x01c0 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD (0x01c1 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE  (0x01C5 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_CP_TUNE   (0x01C6 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_LF_PROG   (0x01C7 * 4)
+#define TB_ADDR_CMN_DIAG_PLL0_TEST_MODE(0x01c4 * 4)
+#define TB_ADDR_CMN_PSM_CLK_CTRL   (0x0061 * 4)
+#define TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR  (0x40ea * 4)
+#define TB_ADDR_XCVR_PSM_RCTRL (0x4001 * 4)
+#define TB_ADDR_TX_PSC_A0  (0x4100 * 4)
+#define TB_ADDR_TX_PSC_A1  (0x4101 * 4)
+#define TB_ADDR_TX_PSC_A2  (0x4102 * 4)
+#define TB_ADDR_TX_PSC_A3  (0x4103 * 4)
+#define TB_ADDR_TX_DIAG_ECTRL_OVRD (0x41f5 * 4)
+#define TB_ADDR_TX_PSC_CAL (0x4106 * 4)
+#define TB_ADDR_TX_PSC_RDY (0x4107 * 4)
+#define TB_ADDR_RX_PSC_A0  (0x8000 * 4)
+#define TB_ADDR_RX_PSC_A1  (0x8001 * 4)
+#define TB_ADDR_RX_PSC_A2  (0x8002 * 4)
+#define TB_ADDR_RX_PSC_A3  (0x8003 * 4)
+#define TB_ADDR_RX_PSC_CAL (0x8006 * 4)
+#define TB_ADDR_RX_PSC_RDY (0x8007 * 4)
+#define TB_ADDR_TX_TXCC_MGNLS_MULT_000 (0x4058 * 4)
+#define TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY (0x41e7 * 4)
+#define TB_ADDR_RX_SLC_CU_ITER_TMR (0x80e3 * 4)
+#define TB_ADDR_RX_SIGDET_HL_FILT_TMR  (0x8090 * 4)
+#define TB_ADDR_RX_SAMP_DAC_CTRL   (0x8058 * 4)
+#define TB_ADDR_RX_DIAG_SIGDET_TUNE(0x81dc * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE2  (0x81df * 4)
+#define TB_ADDR_RX_DIAG_BS_TM  (0x81f5 * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL1  (0x81d3 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM4  (0x81c7 * 4)
+#define TB_ADDR_RX_DIAG_ILL_E_TRIM0(0x81c2 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQ_TRIM0   (0x81c1 * 4)
+#define TB_ADDR_RX_DIAG_ILL_IQE_TRIM6  (0x81c9 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM3   (0x81f8 * 4)
+#define TB_ADDR_RX_DIAG_RXFE_TM4   (0x81f9 * 4)
+#define TB_ADDR_RX_DIAG_LFPSDET_TUNE   (0x81dd * 4)
+#define TB_ADDR_RX_DIAG_DFE_CTRL3  (0x81d5 * 4)
+#define TB_ADDR_RX_DIAG_SC2C_DELAY (0x81e1 * 4)
+#define TB_ADDR_RX_REE_VGA_GAIN_NODFE  (0x81bf * 4)
+#define TB_ADDR_XCVR_PSM_CAL_TMR   (0x4002 * 4)
+#define TB_ADDR_XCVR_PSM

[U-Boot] [PATCH v2 4/4] USB: gadget: core: introduce ->udc_set_speed() method

2019-08-14 Thread sherry sun
From: Sherry Sun 

This patch was copied from kernel commit: 67fdfda4a99ed.

Sometimes, the gadget driver we want to run has max_speed lower than
what the UDC supports. In such situations, UDC might want to make sure
we don't try to connect on speeds not supported by the gadget
driver because that will just fail.

So here introduce a new optional ->udc_set_speed() method which can be
implemented by interested UDC drivers to achieve this purpose.

Signed-off-by: Sherry Sun 
---
 drivers/usb/gadget/udc/udc-core.c | 23 +++
 include/linux/usb/gadget.h|  2 ++
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 62b47781dd..8d1d90e3e3 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -267,6 +267,27 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
 /* - */
 
+/**
+ * usb_gadget_udc_set_speed - tells usb device controller speed supported by
+ *current driver
+ * @udc: The device we want to set maximum speed
+ * @speed: The maximum speed to allowed to run
+ *
+ * This call is issued by the UDC Class driver before calling
+ * usb_gadget_udc_start() in order to make sure that we don't try to
+ * connect on speeds the gadget driver doesn't support.
+ */
+static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
+   enum usb_device_speed speed)
+{
+   if (udc->gadget->ops->udc_set_speed) {
+   enum usb_device_speed s;
+
+   s = min(speed, udc->gadget->max_speed);
+   udc->gadget->ops->udc_set_speed(udc->gadget, s);
+   }
+}
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver 
*driver)
 {
int ret;
@@ -276,6 +297,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct 
usb_gadget_driver *dri
 
udc->driver = driver;
 
+   usb_gadget_udc_set_speed(udc, driver->speed);
+
ret = driver->bind(udc->gadget);
if (ret)
goto err1;
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index a34f3478f3..78e245a1b5 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -450,6 +450,8 @@ struct usb_gadget_ops {
int   (*match_ep)(struct usb_gadget *gadget,
  struct usb_ep *ep,
  struct usb_endpoint_descriptor *desc);
+   void(*udc_set_speed)(struct usb_gadget *gadget,
+enum usb_device_speed);
 };
 
 /**
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2 2/4] USB: host: Add the USB3 host driver

2019-08-14 Thread sherry sun
From: Sherry Sun 

Add the USB3 host driver for NXP imx8 platform, and the
cadence IP is in it. The USB3 host driver support DM
mode, it will probe USB3 host node in dts.

Signed-off-by: Sherry Sun 
---
 drivers/usb/host/Kconfig |   9 ++
 drivers/usb/host/Makefile|   1 +
 drivers/usb/host/xhci-imx8.c | 201 +++
 3 files changed, 211 insertions(+)
 create mode 100644 drivers/usb/host/xhci-imx8.c

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index ac68aa2d27..cc1dfe463b 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -95,6 +95,15 @@ config USB_XHCI_FSL
depends on !SPL_NO_USB
help
  Enables support for the on-chip xHCI controller on NXP Layerscape 
SoCs.
+
+config USB_XHCI_IMX8
+   bool "XHCI support for imx8"
+   depends on ARCH_IMX8
+   default y
+   help
+ Enables support for the on-chip xHCI controller on imx8qm and
+ imx8qxp SoCs.
+
 endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 6aa574f6f7..e5a0a4ea5a 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
 obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
 obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
+obj-$(CONFIG_USB_XHCI_IMX8) += xhci-imx8.o
 
 # designware
 obj-$(CONFIG_USB_DWC2) += dwc2.o
diff --git a/drivers/usb/host/xhci-imx8.c b/drivers/usb/host/xhci-imx8.c
new file mode 100644
index 00..3a7086742d
--- /dev/null
+++ b/drivers/usb/host/xhci-imx8.c
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * NXP i.MX8 USB HOST xHCI Controller (Cadence IP)
+ *
+ * Author: Peter Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "xhci.h"
+
+/* Declare global data pointer */
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Host registers */
+#define HCIVERSION_CAPLENGTH  0x1
+#define USBSTS0x10084
+
+/* None-core registers */
+#define USB3_CORE_CTRL10x00
+#define USB3_CORE_STATUS   0x0c
+#define USB3_SSPHY_STATUS  0x4c
+
+struct xhci_imx8_data {
+   void __iomem *usb3_ctrl_base;
+   void __iomem *usb3_core_base;
+   struct clk_bulk clks;
+   struct phy phy;
+};
+
+static struct xhci_imx8_data imx8_data;
+
+static void imx8_xhci_init(void)
+{
+   u32 tmp_data;
+   int timeout_us = 10;
+
+   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   writel(tmp_data, imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   while ((tmp_data & 0xf000) != 0xf000 && timeout_us-- > 0) {
+   udelay(10);
+   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_SSPHY_STATUS);
+   }
+
+   if (timeout_us <= 0)
+   printf("clkvld is incorrect = 0x%x\n", tmp_data);
+
+   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1);
+   tmp_data = (tmp_data & 0xfff8) | 0x202;
+   writel(tmp_data, imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1);
+   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1, 1 << 26);
+   generic_phy_init(_data.phy);
+
+   /* clear all sw_rst */
+   clrbits_le32(imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1, 0xFC << 24);
+
+   debug("wait xhci_power_on_ready\n");
+   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_CORE_STATUS);
+   timeout_us = 10;
+   while (!(tmp_data & 0x1000) && timeout_us-- > 0) {
+   tmp_data = readl(imx8_data.usb3_ctrl_base + USB3_CORE_STATUS);
+   udelay(1);
+   }
+
+   if (timeout_us <= 0)
+   printf("wait xhci_power_on_ready timeout\n");
+   debug("xhci_power_on_ready\n");
+
+   tmp_data = readl(imx8_data.usb3_core_base + USBSTS);
+   debug("waiting CNR 0x%x\n", tmp_data);
+   timeout_us = 10;
+   while (tmp_data & 0x800 && timeout_us-- > 0) {
+   tmp_data = readl(imx8_data.usb3_core_base + USBSTS);
+   udelay(1);
+   }
+
+   if (timeout_us <= 0)
+   printf("wait CNR timeout\n");
+   debug("check CNR has finished\n");
+}
+
+static void imx8_xhci_reset(void)
+{
+   /* Set CORE ctrl to default value, that all rst are hold */
+   writel(0xfc01, imx8_data.usb3_ctrl_base + USB3_CORE_CTRL1);
+}
+
+static int xhci_imx8_clk_init(struct udevice *dev)
+{
+   int ret;
+
+   ret = clk_get_bulk(dev, _data.clks);
+   if (ret)
+   return ret;
+
+   ret = clk_enable_bulk(_data.clks);
+   if (ret)
+   return r

[U-Boot] [PATCH v2 0/4] USB: Add cadence USB3 gadget driver and host driver

2019-08-14 Thread sherry sun
From: Sherry Sun 

These patches introduce new Cadence USBSS driver to U-Boot.
The first patch is to add the Cadence USB3 IP(CDNS3) core and driver for 
the usb gadget.
The second patch introduce the xhci-imx8 usb host driver separately.
The third patch introduce the cdns3 phy driver which can be used for both 
cdns3 host driver and gadget driver.
The cdns3 usb gadget driver/host/phy driver are all used DM mode.

The current driver has been validated on i.MX8 platform.
If anyone want to test it, please note that the additional dts nodes/
config macros/clock driver are also essential. You can also get
my test patches at https://github.com/sherrysun1/u-boot-imx.git.

Changes in v2:
 - Add doc/device-tree-bindings/usb/cdns-usb3.txt to describe the usb node
   properties in dts.
 - Add cdns3 usb phy driver instead of implementing it in cdns3 gadget/host
   driver.
 - Use clrbits_le32() and setbits_le32() globally. 
 - Remove some macros that are not used temporarily.


Sherry Sun (4):
  USB: gadget: Add the cadence USB3 gadget driver
  USB: host: Add the USB3 host driver
  phy: Add USB PHY driver for the cadence USB3
  USB: gadget: core: introduce ->udc_set_speed() method

 Makefile   |1 +
 doc/device-tree-bindings/usb/cdns-usb3.txt |   39 +
 drivers/phy/Kconfig|8 +
 drivers/phy/Makefile   |1 +
 drivers/phy/cdns3-usb-phy.c|  242 +++
 drivers/usb/Kconfig|2 +
 drivers/usb/cdns3/Kconfig  |   20 +
 drivers/usb/cdns3/Makefile |5 +
 drivers/usb/cdns3/cdns3-generic.c  |  115 +
 drivers/usb/cdns3/cdns3-nxp-reg-def.h  |   89 +
 drivers/usb/cdns3/core.c   |  197 ++
 drivers/usb/cdns3/core.h   |  118 ++
 drivers/usb/cdns3/dev-regs-macro.h |  116 +
 drivers/usb/cdns3/dev-regs-map.h   |  117 ++
 drivers/usb/cdns3/gadget-export.h  |   26 +
 drivers/usb/cdns3/gadget.c |  
 drivers/usb/cdns3/gadget.h |  225 ++
 drivers/usb/cdns3/io.h |   30 +
 drivers/usb/gadget/epautoconf.c|4 +
 drivers/usb/gadget/gadget_chips.h  |7 +
 drivers/usb/gadget/udc/Makefile|1 +
 drivers/usb/gadget/udc/udc-core.c  |   23 +
 drivers/usb/host/Kconfig   |9 +
 drivers/usb/host/Makefile  |1 +
 drivers/usb/host/xhci-imx8.c   |  201 ++
 include/linux/usb/gadget.h |5 +
 scripts/Makefile.spl   |1 +
 27 files changed, 3825 insertions(+)
 create mode 100644 doc/device-tree-bindings/usb/cdns-usb3.txt
 create mode 100644 drivers/phy/cdns3-usb-phy.c
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h
 create mode 100644 drivers/usb/host/xhci-imx8.c

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: 答复: 答复: [PATCH 0/4] Make some changes to SDP

2019-08-09 Thread Sherry Sun
Hi Angus,


Hi Sherry,

On Aug. 8, 2019 2:38 a.m., Sherry Sun 
mailto:sherry@nxp.com>> wrote:

Hi Angus,

Sorry for the late reply.

> -邮件原件-
> 发件人: Angus Ainslie mailto:an...@akkea.ca>>
> 发送时间: 2019年8月2日 10:30
> 收件人: Peng Fan mailto:peng....@nxp.com>>
> 抄送: Sherry Sun mailto:sherry@nxp.com>>; 
> sba...@denx.de<mailto:sba...@denx.de>;
> feste...@gmail.com<mailto:feste...@gmail.com>; 
> lu...@denx.de<mailto:lu...@denx.de>; ma...@denx.de<mailto:ma...@denx.de>;
> u-boot@lists.denx.de<mailto:u-boot@lists.denx.de>; dl-uboot-imx 
> mailto:uboot-...@nxp.com>>
> 主题: Re: 答复: [U-Boot] [PATCH 0/4] Make some changes to SDP
>
> Hi Peng,
>
> On 2019-08-01 18:01, Peng Fan wrote:
> > Angus,
> >
> >> Subject: Re: 答复: [U-Boot] [PATCH 0/4] Make some changes to SDP
> >>
> >> Hi Sherry,
> >>
> >> On 2019-07-31 19:56, Sherry Sun wrote:
> >> > Hi Angus
> >> >
> >> >>
> >> >> Hi Sherry,
> >> >>
> >> >> On 2019-07-17 18:40, sherry sun wrote:
> >> >> > From: Sherry Sun mailto:sherry@nxp.com>>
> >> >> >
> >> >> > This patchset adds:
> >> >> > 1. Add usb_gadget_initialize() and usb_gadget_release() to
> >> >> > initialize and release UDC during sdp download.
> >> >> > 2. Add high speed endpoint descriptor for sdp.
> >> >> > 3. Add a macro definition--CONFIG_SDP_LOADADDR as default sdp
> >> >> > load address while SDP_WRITE and SDP_JUMP command addr is zero.
> >> >> >
> >> >> > Sherry Sun (4):
> >> >> >   imx: spl: Change USB boot device type
> >> >> >   SDP: use CONFIG_SDP_LOADADDR as default load address
> >> >> >   SDP: fix wrong usb request size and add high speed endpoint
> >> >> > descriptor
> >> >> >   SDP: Call usb_gadget_initialize and usb_gadget_release to
> >> >> > support UDC
> >> >>
> >> >> These changes look like like they target SDP on imx8. For imx8mq
> >> >> is this all that is required to get SDP working with uuu or are
> >> >> there additional changes required ?
> >> >>
> >> >
> >> > The changes in patch 1/4 are target on both imx8 and imx8m.
> >> > The rest three patches are target on all boards which used SDP.
> >> > So for imx8mq, if your usb gadget driver is ready ,these changes
> >> > are enough to get SDP working with UUU.
> >> >
> >>
> >> I'm trying to use SDP on the imx8mq-evk but it doesn't look like it's
> >> enabled there. Do you have patches to enable SDP on the imx8mq-evk ,
> >> even if they aren't ready to go upstream ?
> >
> > You could try downstream code,
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsour
> >
> ce.codeaurora.org%2Fexternal%2Fimx%2Fuboot-imx%2Fdata=02%7C01
> %7Cs
> >
> herry.sun%40nxp.com%7C6d63289fbb104168bce308d716f157c4%7C686ea1
> d3bc2b4
> >
> c6fa92cd99c5c301635%7C0%7C0%7C637003098143081621sdata=beh
> 08%2Fv3f
> > s8ZZPP29F1iVMfo3uNTWGf91SYYyak2GVU%3Dreserved=0
> > branch: imx_v2019.04_4.19.35_1.0.0
> >
>
> I already have SDP  working with the vendor u-boot. I'm trying to switch to
> mainline u-boot so I'm looking for mainline patches.
>

May I ask, is your usb gadget driver is working? Such as you can use it for 
fastboot or ums.
>If I enable dwc3 gadget and DM for the SPL then I must start removing other 
>SPL features to get it to fit in the 124k allocation.
>
>It sounds like you haven't tested this on the imx8mq-evk then ?

Yes, I  have not used imx8mq-evk yet. I will try to test it later.

Best regards
Sherry sun

>Thanks
>Angus

Best regards
Sherry sun

> Thanks
> Angus
>
> > Regards,
> > Peng.
> >
> >>
> >> Thanks
> >> Angus
> >>
> >> > Best regards
> >> > Sherry sun
> >> >
> >> >> Thanks
> >> >> Angus
> >> >>
> >> >> >
> >> >> >  arch/arm/mach-imx/spl.c|  2 +-
> >> >> >  common/spl/spl_sdp.c   |  4 
> >> >> >  drivers/usb/gadget/Kconfig |  4 
> >> >> > drivers/usb/gadget/f_sdp.c |
> >> >> > 39
> >> >> > +-
> >> >> >  4 files changed, 43 insertions(+), 6 deletions(-)

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: 答复: [PATCH 0/4] Make some changes to SDP

2019-08-08 Thread Sherry Sun
Hi Angus,

Sorry for the late reply.

> -邮件原件-
> 发件人: Angus Ainslie 
> 发送时间: 2019年8月2日 10:30
> 收件人: Peng Fan 
> 抄送: Sherry Sun ; sba...@denx.de;
> feste...@gmail.com; lu...@denx.de; ma...@denx.de;
> u-boot@lists.denx.de; dl-uboot-imx 
> 主题: Re: 答复: [U-Boot] [PATCH 0/4] Make some changes to SDP
> 
> Hi Peng,
> 
> On 2019-08-01 18:01, Peng Fan wrote:
> > Angus,
> >
> >> Subject: Re: 答复: [U-Boot] [PATCH 0/4] Make some changes to SDP
> >>
> >> Hi Sherry,
> >>
> >> On 2019-07-31 19:56, Sherry Sun wrote:
> >> > Hi Angus
> >> >
> >> >>
> >> >> Hi Sherry,
> >> >>
> >> >> On 2019-07-17 18:40, sherry sun wrote:
> >> >> > From: Sherry Sun 
> >> >> >
> >> >> > This patchset adds:
> >> >> > 1. Add usb_gadget_initialize() and usb_gadget_release() to
> >> >> > initialize and release UDC during sdp download.
> >> >> > 2. Add high speed endpoint descriptor for sdp.
> >> >> > 3. Add a macro definition--CONFIG_SDP_LOADADDR as default sdp
> >> >> > load address while SDP_WRITE and SDP_JUMP command addr is zero.
> >> >> >
> >> >> > Sherry Sun (4):
> >> >> >   imx: spl: Change USB boot device type
> >> >> >   SDP: use CONFIG_SDP_LOADADDR as default load address
> >> >> >   SDP: fix wrong usb request size and add high speed endpoint
> >> >> > descriptor
> >> >> >   SDP: Call usb_gadget_initialize and usb_gadget_release to
> >> >> > support UDC
> >> >>
> >> >> These changes look like like they target SDP on imx8. For imx8mq
> >> >> is this all that is required to get SDP working with uuu or are
> >> >> there additional changes required ?
> >> >>
> >> >
> >> > The changes in patch 1/4 are target on both imx8 and imx8m.
> >> > The rest three patches are target on all boards which used SDP.
> >> > So for imx8mq, if your usb gadget driver is ready ,these changes
> >> > are enough to get SDP working with UUU.
> >> >
> >>
> >> I'm trying to use SDP on the imx8mq-evk but it doesn't look like it's
> >> enabled there. Do you have patches to enable SDP on the imx8mq-evk ,
> >> even if they aren't ready to go upstream ?
> >
> > You could try downstream code,
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsour
> >
> ce.codeaurora.org%2Fexternal%2Fimx%2Fuboot-imx%2Fdata=02%7C01
> %7Cs
> >
> herry.sun%40nxp.com%7C6d63289fbb104168bce308d716f157c4%7C686ea1
> d3bc2b4
> >
> c6fa92cd99c5c301635%7C0%7C0%7C637003098143081621sdata=beh
> 08%2Fv3f
> > s8ZZPP29F1iVMfo3uNTWGf91SYYyak2GVU%3Dreserved=0
> > branch: imx_v2019.04_4.19.35_1.0.0
> >
> 
> I already have SDP  working with the vendor u-boot. I'm trying to switch to
> mainline u-boot so I'm looking for mainline patches.
> 

May I ask, is your usb gadget driver is working? Such as you can use it for 
fastboot or ums.

Best regards
Sherry sun

> Thanks
> Angus
> 
> > Regards,
> > Peng.
> >
> >>
> >> Thanks
> >> Angus
> >>
> >> > Best regards
> >> > Sherry sun
> >> >
> >> >> Thanks
> >> >> Angus
> >> >>
> >> >> >
> >> >> >  arch/arm/mach-imx/spl.c|  2 +-
> >> >> >  common/spl/spl_sdp.c   |  4 
> >> >> >  drivers/usb/gadget/Kconfig |  4 
> >> >> > drivers/usb/gadget/f_sdp.c |
> >> >> > 39
> >> >> > +-
> >> >> >  4 files changed, 43 insertions(+), 6 deletions(-)
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: [PATCH 0/3] USB: Add cadence USB3 gadget driver and host driver

2019-08-08 Thread Sherry Sun
Hi Igor,

Sorry for the late reply.

> 
> Igor,
> 
> > Subject: Re: [U-Boot] [PATCH 0/3] USB: Add cadence USB3 gadget driver
> > and host driver
> >
> > Hi Sherry,
> >
> > On Tue, Jul 16, 2019 at 4:15 PM sherry sun 
> wrote:
> > >
> > > From: Sherry Sun 
> > >
> > > These patches introduce new Cadence USBSS driver to U-Boot.
> > >
> > > The first patch is to add the Cadence USB3 IP(CDNS3) driver for the
> > > usb gadget, but the host mode is not supported now. The second patch
> > > introduce the xhci-imx8 usb host driver separately. The cdns3 usb
> > > gadget driver and xhci-imx8 host driver both use DM mode.
> > >
> > > The current driver has been validated on i.MX8 platform.
> > >
> > > Sherry Sun (3):
> > >   USB: gadget: Add the cadence USB3 gadget driver
> > >   USB: host: Add the USB3 host driver
> > >   USB: gadget: core: introduce ->udc_set_speed() method
> > >
> > >  Makefile  |1 +
> > >  drivers/usb/Kconfig   |2 +
> > >  drivers/usb/cdns3/Kconfig |   20 +
> > >  drivers/usb/cdns3/Makefile|5 +
> > >  drivers/usb/cdns3/cdns3-generic.c |  176 ++
> > >  drivers/usb/cdns3/cdns3-nxp-reg-def.h |  158 ++
> > >  drivers/usb/cdns3/core.c  |  408 +
> > >  drivers/usb/cdns3/core.h  |  129 ++
> > >  drivers/usb/cdns3/dev-regs-macro.h|  116 ++
> > >  drivers/usb/cdns3/dev-regs-map.h  |  117 ++
> > >  drivers/usb/cdns3/gadget-export.h |   26 +
> > >  drivers/usb/cdns3/gadget.c| 2278
> > +
> > >  drivers/usb/cdns3/gadget.h|  238 +++
> > >  drivers/usb/cdns3/io.h|   30 +
> > >  drivers/usb/cdns3/linux-compat.h  |   16 +
> > >  drivers/usb/gadget/epautoconf.c   |4 +
> > >  drivers/usb/gadget/gadget_chips.h |7 +
> > >  drivers/usb/gadget/udc/Makefile   |1 +
> > >  drivers/usb/gadget/udc/udc-core.c |   23 +
> > >  drivers/usb/host/Kconfig  |9 +
> > >  drivers/usb/host/Makefile |1 +
> > >  drivers/usb/host/xhci-imx8.c  |  311 
> > >  include/cdns3-uboot.h |   26 +
> > >  include/linux/usb/gadget.h|5 +
> > >  include/usb/imx8_usb3_reg_def.h   |  455 +
> > >  scripts/Makefile.spl  |1 +
> > >  26 files changed, 4563 insertions(+)  create mode 100644
> > > drivers/usb/cdns3/Kconfig  create mode 100644
> > > drivers/usb/cdns3/Makefile  create mode 100644
> > > drivers/usb/cdns3/cdns3-generic.c  create mode 100644
> > > drivers/usb/cdns3/cdns3-nxp-reg-def.h
> > >  create mode 100644 drivers/usb/cdns3/core.c  create mode 100644
> > > drivers/usb/cdns3/core.h  create mode 100644
> > > drivers/usb/cdns3/dev-regs-macro.h
> > >  create mode 100644 drivers/usb/cdns3/dev-regs-map.h  create
> mode
> > > 100644 drivers/usb/cdns3/gadget-export.h  create mode 100644
> > > drivers/usb/cdns3/gadget.c  create mode 100644
> > > drivers/usb/cdns3/gadget.h  create mode 100644
> > > drivers/usb/cdns3/io.h create mode 100644
> > > drivers/usb/cdns3/linux-compat.h  create mode
> > > 100644 drivers/usb/host/xhci-imx8.c  create mode 100644
> > > include/cdns3-uboot.h  create mode 100644
> > > include/usb/imx8_usb3_reg_def.h
> > >
> > > --
> > > 2.17.1
> > >
> > > ___
> > > U-Boot mailing list
> > > U-Boot@lists.denx.de
> > >
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fli
> > > st
> > >
> >
> s.denx.de%2Flistinfo%2Fu-bootdata=02%7C01%7Cpeng.fan%40nx
> p.co
> > m%7C
> > >
> >
> fbf069e4184b49805ff608d716792228%7C686ea1d3bc2b4c6fa92cd99c
> 5c301
> > 635%7C
> > >
> >
> 0%7C0%7C637002581830489188sdata=2sLbnCK6jSV9a3NQZFK8i
> wc1r
> > lh5jSyAR
> > > qSveO4nebg%3Dreserved=0
> >
> > Thanks for your patches!
> > Taking into account that this series introduces a brand new driver, it
> > would be really nice to also have proper device tree bindings in
> > doc/device-tree-bindings (so I can at least quickly enable it for my
> > board, test it and leave my T-b tags).
> 
> Currently there is also no linux upstream bindings for the new IP, so this
> w

[U-Boot] 答复: [PATCH 2/3] USB: host: Add the USB3 host driver

2019-08-01 Thread Sherry Sun
Hi, Marek

I'm so sorry to check the e-mail and reply you so late.

> On 7/16/19 2:08 PM, sherry sun wrote:
> > From: Sherry Sun 
> >
> > This driver is ported from NXP i.MX U-Boot version imx_v2019.04 and
> > some changes have also been made to adapt to U-Boot.
> 
> I don't this this line above is particularly useful.

Ok, I will remove this from the commit messages.

> 
> > Add the USB3 host driver for NXP imx8 platform, and the cadence IP is
> > in it.
> >
> > The USB3 host driver support DM mode. It will probe USB3 host node,
> > enable the power and clk of both USB3 controller and USB3 PHY.
> >
> > Signed-off-by: Sherry Sun 
> > ---
> >  drivers/usb/host/Kconfig|   9 +
> >  drivers/usb/host/Makefile   |   1 +
> >  drivers/usb/host/xhci-imx8.c| 311 ++
> >  include/usb/imx8_usb3_reg_def.h | 455
> > 
> >  4 files changed, 776 insertions(+)
> >  create mode 100644 drivers/usb/host/xhci-imx8.c  create mode 100644
> > include/usb/imx8_usb3_reg_def.h
> >
> > diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index
> > b1188bcbf5..73c98e0cf4 100644
> > --- a/drivers/usb/host/Kconfig
> > +++ b/drivers/usb/host/Kconfig
> > @@ -94,6 +94,15 @@ config USB_XHCI_FSL
> > depends on !SPL_NO_USB
> > help
> >   Enables support for the on-chip xHCI controller on NXP Layerscape
> SoCs.
> > +
> > +config USB_XHCI_IMX8
> > +   bool "XHCI support for imx8"
> > +   depends on ARCH_IMX8
> > +   default y
> > +   help
> > + Enables support for the on-chip xHCI controller on imx8qm and
> > + imx8qxp SoCs.
> > +
> >  endif # USB_XHCI_HCD
> >
> >  config USB_EHCI_HCD
> > diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
> > index 6aa574f6f7..e5a0a4ea5a 100644
> > --- a/drivers/usb/host/Makefile
> > +++ b/drivers/usb/host/Makefile
> > @@ -55,6 +55,7 @@ obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
> >  obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
> >  obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
> >  obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
> > +obj-$(CONFIG_USB_XHCI_IMX8) += xhci-imx8.o
> >
> >  # designware
> >  obj-$(CONFIG_USB_DWC2) += dwc2.o
> > diff --git a/drivers/usb/host/xhci-imx8.c
> > b/drivers/usb/host/xhci-imx8.c new file mode 100644 index
> > 00..abac37d446
> > --- /dev/null
> > +++ b/drivers/usb/host/xhci-imx8.c
> > @@ -0,0 +1,311 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright 2019 NXP
> > + *
> > + * NXP i.MX8 USB HOST xHCI Controller (Cadence IP)
> > + *
> > + * Author: Peter Chen   */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include "xhci.h"
> > +
> > +/* Declare global data pointer */
> > +DECLARE_GLOBAL_DATA_PTR;
> 
> Is this needed ?
> 

Yes, the global_data pointer will be used in later functions.
So the declare is needed here.

> > +
> > +/* According to UG CH 3.1.1 Bring-up Sequence */ static void
> > +imx_usb3_phy_init(void) {
> 
> Shouldn't this be a separate PHY driver ?

Okay, I will try to add a new PHY driver to replace the code below.

> 
> > +   writel(0x0830, PHY_PMA_CMN_CTRL1);
> > +   writel(0x10, TB_ADDR_CMN_DIAG_HSCLK_SEL);
> > +   writel(0x00F0, TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR);
> > +   writel(0x0018, TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR);
> > +   writel(0x00D0, TB_ADDR_CMN_PLL0_INTDIV);
> > +   writel(0x4aaa, TB_ADDR_CMN_PLL0_FRACDIV);
> > +   writel(0x0034, TB_ADDR_CMN_PLL0_HIGH_THR);
> > +   writel(0x1ee, TB_ADDR_CMN_PLL0_SS_CTRL1);
> > +   writel(0x7F03, TB_ADDR_CMN_PLL0_SS_CTRL2);
> > +   writel(0x0020, TB_ADDR_CMN_PLL0_DSM_DIAG);
> > +   writel(0x, TB_ADDR_CMN_DIAG_PLL0_OVRD);
> > +   writel(0x, TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD);
> > +   writel(0x, TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD);
> > +   writel(0x0007, TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE);
> > +   writel(0x0027, TB_ADDR_CMN_DIAG_PLL0_CP_TUNE);
> > +   writel(0x0008, TB_ADDR_CMN_DIAG_PLL0_LF_PROG);
> > +   writel(0x0022, TB_ADDR_CMN_DIAG_PLL0_TEST_MODE);
> > +   writel(0x000a, TB_ADDR_CMN_PSM_CLK_CTRL);
> > +   writel(0x139, TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR);
> > +   writel(0xbefc, TB_ADDR_XCVR_PSM_RCTRL);
> > +
> > +   writel(0x7799, TB_ADDR_TX_PSC_A0);
> > +   writel(0x7798, TB_ADDR_TX_PSC_A1);
&

[U-Boot] 答复: [PATCH 0/4] Make some changes to SDP

2019-07-31 Thread Sherry Sun
Hi Angus

> 
> Hi Sherry,
> 
> On 2019-07-17 18:40, sherry sun wrote:
> > From: Sherry Sun 
> >
> > This patchset adds:
> > 1. Add usb_gadget_initialize() and usb_gadget_release() to initialize
> > and release UDC during sdp download.
> > 2. Add high speed endpoint descriptor for sdp.
> > 3. Add a macro definition--CONFIG_SDP_LOADADDR as default sdp load
> > address while SDP_WRITE and SDP_JUMP command addr is zero.
> >
> > Sherry Sun (4):
> >   imx: spl: Change USB boot device type
> >   SDP: use CONFIG_SDP_LOADADDR as default load address
> >   SDP: fix wrong usb request size and add high speed endpoint
> > descriptor
> >   SDP: Call usb_gadget_initialize and usb_gadget_release to support
> > UDC
> 
> These changes look like like they target SDP on imx8. For imx8mq is this all
> that is required to get SDP working with uuu or are there additional changes
> required ?
> 

The changes in patch 1/4 are target on both imx8 and imx8m.
The rest three patches are target on all boards which used SDP.
So for imx8mq, if your usb gadget driver is ready ,these changes are enough to 
get SDP working with UUU. 

Best regards
Sherry sun

> Thanks
> Angus
> 
> >
> >  arch/arm/mach-imx/spl.c|  2 +-
> >  common/spl/spl_sdp.c   |  4 
> >  drivers/usb/gadget/Kconfig |  4 
> >  drivers/usb/gadget/f_sdp.c | 39
> > +-
> >  4 files changed, 43 insertions(+), 6 deletions(-)
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: [EXT] Re: Upstreaming usb host drivers for iMX8/iMX8M

2019-07-24 Thread Sherry Sun
Hi,Igor

> -邮件原件-
> 发件人: Igor Opaniuk 
> 发送时间: 2019年7月23日 20:43
> 收件人: Sherry Sun 
> 抄送: Ying Liu ; Peng Fan ; Jun Li
> ; Ye Li ; U-Boot Mailing List
> ; Peter Chen ; dl-uboot-imx
> ; Marcel Ziswiler ; Max
> Krummenacher ; Igor Opaniuk
> ; Frank Li 
> 主题: Re: [EXT] Re: Upstreaming usb host drivers for iMX8/iMX8M
> 
> Hi Sherry,
> 
> On Tue, Jul 2, 2019 at 4:26 AM Sherry Sun  wrote:
> >
> > + Ying
> >
> > > -邮件原件-
> > > 发件人: Igor Opaniuk 
> > > 发送时间: 2019年7月1日 19:32
> > > 收件人: Sherry Sun 
> > > 抄送: Peng Fan ; Jun Li ; Ye Li
> > > ; U-Boot Mailing List ; Peter
> > > Chen ; dl-uboot-imx ;
> Marcel
> > > Ziswiler ; Max Krummenacher
> > > ; Igor Opaniuk
> > > ; Frank Li 
> > > 主题: [EXT] Re: Upstreaming usb host drivers for iMX8/iMX8M
> > >
> > > Caution: EXT Email
> > >
> > > Hi Sherry,
> > >
> > > On Fri, Jun 28, 2019 at 8:02 AM Sherry Sun  wrote:
> > > >
> > > > Hi, Igor
> > > >
> > > > We have the plan to do the upstream job of cdns3 host/gadget
> > > > drivers on
> > > imx8.
> > > > Now we just have done the DM switch of cdns3 gadget driver, and
> > > > there also some changes in xhci_imx8.c.
> > > Thanks for the details!
> > >
> > > > We plan to start our upstream job from next week, and the first
> > > > version will be send to maintainer within two or three weeks. We
> > > > hope it will be included in uboot v2019.07 RC2.
> > > I'm afraid we're a bit late here.
> > > v2019.07 is going to be released next Monday (there was a release of
> > > v2019.07-rc4 already in June 11), so the next merge window for
> > > v2019.10 opens July 9.
> >
> > Yes, you are right.
> > Anyway, I will try my best and finish the upstream job as soon as possible.
> >
> > > > Do you think this is okay?
> > > Sounds good! Looking forward to your patches in the mailing list!
> > >
> > > >
> > > > Best regards
> > > > Sherry sun
> > > >
> > > >
> > > Just a bit off-topic, but are you aware about similar plans for
> > > upstreaming of DPU driver for i.MX8 (driver/video/imxdpuv1.c)?
> >
> > Sorry, I am not quite sure.
> > Ying knows more about this. Maybe he can answer you.
> >
> > Best regards
> > Sherry sun
> >
> > > > -邮件原件-
> > > > 发件人: Peng Fan
> > > > 发送时间: 2019年6月27日 17:58
> > > > 收件人: Igor Opaniuk ; Sherry Sun
> > > > ; Jun Li 
> > > > 抄送: U-Boot Mailing List ; Ye Li
> > > > ; Peter Chen ; dl-uboot-imx
> > > > ; Marcel Ziswiler
> > > > ; Max Krummenacher
> > > > ; Igor Opaniuk
> > > > ; Frank Li 
> > > > 主题: RE: Upstreaming usb host drivers for iMX8/iMX8M
> > > >
> > > > + Sherry, Jun
> > > >
> > > > > Subject: Re: Upstreaming usb host drivers for iMX8/iMX8M
> > > > >
> > > > > Hi Peng,
> > > > >
> > > > > On Thu, Jun 27, 2019 at 8:32 AM Peng Fan 
> wrote:
> > > > > >
> > > > > >
> > > > > > Hi Igor,
> > > > > >
> > > > > > > Subject: Upstreaming usb host drivers for iMX8/iMX8M
> > > > > > >
> > > > > > > Hi Peng, Ye, Peter,
> > > > > > >
> > > > > > > Currently there in no any usb host/gadget support in the
> > > > > > > mainline U-boot, and seems that no one has posted anything
> > > > > > > yet to the mailing list (at least I haven't found anything
> > > > > > > related to this in the
> > > ML archives).
> > > > > > >
> > > > > > > I've spent some time testing (usb host, ums etc.) the one in
> > > > > > > the downstream NXP U-boot (I'm still not sure where is the
> > > > > > > official NXP downstream rep, because there are no any
> > > > > > > updates in [1] for the last two years, so I looked into [2],
> > > > > > > [3]), and just curious if there any plans to get it upstreamed in 
> > > > > > > the
> near future?
> > > > > >
> > > > > > In NXP downstream, there is work to migrate the i.MX8
> > > > > > usb/gadget to
> > > DM.

[U-Boot] 答复: [PATCH 1/4] imx: spl: Change USB boot device type

2019-07-18 Thread Sherry Sun
Hi, Lukasz

> 
> On Thu, 18 Jul 2019 07:47:53 +
> Peng Fan  wrote:
> 
> > > Subject: Re: [PATCH 1/4] imx: spl: Change USB boot device type
> > >
> > > On Thu, 18 Jul 2019 07:38:10 +
> > > Peng Fan  wrote:
> > >
> > > > Hi Lukasz,
> > > >
> > > > > Subject: Re: [PATCH 1/4] imx: spl: Change USB boot device type
> > > > >
> > > > > Hi Sherry,
> > > > >
> > > > > > From: Sherry Sun 
> > > > > >
> > > > > > The SPL SDP is configured as BOOT_DEVICE_BOARD, so when
> > > > > > booting from USB, change its type to BOOT_DEVICE_BOARD, so we
> > > > > > can use SDP.
> > > > > >
> > > > > > Signed-off-by: Sherry Sun 
> > > > > > Signed-off-by: Ye Li 
> > > > > > ---
> > > > > >  arch/arm/mach-imx/spl.c | 2 +-
> > > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > >
> > > > > > diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
> > > > > > index 9f1e0f6a72..2355019243 100644
> > > > > > --- a/arch/arm/mach-imx/spl.c
> > > > > > +++ b/arch/arm/mach-imx/spl.c
> > > > > > @@ -156,7 +156,7 @@ u32 spl_boot_device(void)
> > > > > > case SPI_NOR_BOOT:
> > > > > > return BOOT_DEVICE_SPI;
> > > > > > case USB_BOOT:
> > > > > > -   return BOOT_DEVICE_USB;
> > > > > > +   return BOOT_DEVICE_BOARD;
> > > > >
> > > > > Why this change is required? What is the problem you are trying
> > > > > to solve here? (And it is always welcome if one write the
> > > > > detailed description of the problem in the commit message).
> > > >
> > > > It is spl sdp need it.
> > > > SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD,
> > > > spl_sdp_load_image);
> > >
> > > My point is why this error was not apparent earlier (or when I was
> > > using the uuu with newest u-boot)?
> >
> > The patch changes the i.MX7/8/8M spl_boot_device,
> > i.MX7 already have BOARD support. i.MX8/8M has not been verified SDP
> > before, so this patch is to fix for i.MX8/8M SDP.
> 
> I've looked into the source code and this fix is indeed for IMX7/8.
> 
> That was not apparent from either the code nor commit message.
> 
> Please prepare more detailed commit messages, so we would know much
> more from the patch without the need to see the relevant source code.
> 


Okay, I will add more commit messages for this patch. Thanks for your comments.


> >
> > Regards,
> > Peng.
> >
> > >
> > > I'm just curious why let's say "average" uuu/SDP user did not
> > > encountered this problem (as I had also to recover SPL on my i.MX6
> > > board).
> > > >
> > > > Regards,
> > > > Peng.
> > > >
> > > > >
> > > > > I've been using recently SDP (with uuu on imx6q) and I did not
> > > > > experience any issues.
> > > > >
> > > > > > default:
> > > > > > return BOOT_DEVICE_NONE;
> > > > > > }
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Best regards,
> > > > >
> > > > > Lukasz Majewski
> > > > >
> > > > > --
> > > > >
> > > > > DENX Software Engineering GmbH,  Managing Director: Wolfgang
> > > > > Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194
> > > > > Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax:
> > > > > (+49)-8142-66989-80 Email: lu...@denx.de
> > >
> > >
> > >
> > >
> > > Best regards,
> > >
> > > Lukasz Majewski
> > >
> > > --
> > >
> > > DENX Software Engineering GmbH,  Managing Director: Wolfgang
> > > Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell,
> > > Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> > > lu...@denx.de
> 
> 
> 
> 
> Best regards,
> 
> Lukasz Majewski
> 
> --
> 
> DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> lu...@denx.de

Best regards
Sherry sun
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: [EXT] Re: [PATCH 1/4] imx: spl: Change USB boot device type

2019-07-18 Thread Sherry Sun
Hi, Lukasz


> 
> On Thu, 18 Jul 2019 07:38:10 +
> Peng Fan  wrote:
> 
> > Hi Lukasz,
> >
> > > Subject: Re: [PATCH 1/4] imx: spl: Change USB boot device type
> > >
> > > Hi Sherry,
> > >
> > > > From: Sherry Sun 
> > > >
> > > > The SPL SDP is configured as BOOT_DEVICE_BOARD, so when booting
> > > > from USB, change its type to BOOT_DEVICE_BOARD, so we can use SDP.
> > > >
> > > > Signed-off-by: Sherry Sun 
> > > > Signed-off-by: Ye Li 
> > > > ---
> > > >  arch/arm/mach-imx/spl.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
> > > > index 9f1e0f6a72..2355019243 100644
> > > > --- a/arch/arm/mach-imx/spl.c
> > > > +++ b/arch/arm/mach-imx/spl.c
> > > > @@ -156,7 +156,7 @@ u32 spl_boot_device(void)
> > > > case SPI_NOR_BOOT:
> > > > return BOOT_DEVICE_SPI;
> > > > case USB_BOOT:
> > > > -   return BOOT_DEVICE_USB;
> > > > +   return BOOT_DEVICE_BOARD;
> > >
> > > Why this change is required? What is the problem you are trying to
> > > solve here? (And it is always welcome if one write the detailed
> > > description of the problem in the commit message).
> >
> > It is spl sdp need it.
> > SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD,
> > spl_sdp_load_image);
> 
> My point is why this error was not apparent earlier (or when I was using the
> uuu with newest u-boot)?
> 
> I'm just curious why let's say "average" uuu/SDP user did not encountered this
> problem (as I had also to recover SPL on my i.MX6 board).

This change is only available on imx8 and imx8m platform.

For imx7, BOOT_DEVICE_BOARD has already been set at the beginning of u32 
spl_boot_device(void).
For imx6, BOOT_DEVICE_BOARD also has been set as below.
 21#if defined(CONFIG_MX6)
 22 /* determine boot device from SRC_SBMR1 (BOOT_CFG[4:1]) or SRC_GPR9 
register */
 23 u32 spl_boot_device(void)
 24 {
 25 unsigned int bmode = readl(_base->sbmr2);
 26 u32 reg = imx6_src_get_boot_mode();
 27
 28 /*
 29  * Check for BMODE if serial downloader is enabled
 30  * BOOT_MODE - see IMX6DQRM Table 8-1
 31  */
 32 if (((bmode >> 24) & 0x03) == 0x01) /* Serial Downloader */
 33 return BOOT_DEVICE_BOARD;


> 
> >
> > Regards,
> > Peng.
> >
> > >
> > > I've been using recently SDP (with uuu on imx6q) and I did not
> > > experience any issues.
> > >
> > > > default:
> > > > return BOOT_DEVICE_NONE;
> > > > }
> > >
> > >
> > >
> > >
> > > Best regards,
> > >
> > > Lukasz Majewski
> > >
> > > --
> > >
> > > DENX Software Engineering GmbH,  Managing Director: Wolfgang
> > > Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell,
> > > Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> > > lu...@denx.de
> 
> 
> 
> 
> Best regards,
> 
> Lukasz Majewski
> 
> --
> 
> DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
> lu...@denx.de


Best regards
Sherry sun
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: [PATCH 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor

2019-07-18 Thread Sherry Sun

Hi, Lukasz

> 
> Hi Sherry,
> 
> > From: Sherry Sun 
> >
> > Because the buffer length of sdp usb request is 65,
> 
> Is the value 65 mentioned somewhere (in any doc/spec)?
> 
> As fair as I remember other protocols - like DFU use 64B. Do we need here to
> store extra \0 or \n ?
> 

You can see case SDP_STATE_TX_STATUS and case SDP_STATE_TX_REGISTER in
static void sdp_handle_in_ep(struct spl_image_info *spl_image)
Here sdp_func->in_req->length = 65; 

Data[0] is the report id, and the next 64 bytes are the date to host.
So totally we need 65 bytes.

> The 64 bytes are default packet size on EP0.
> 
> 
> If I may ask - what user space program do you use? imx_loader (imx_usb) or
> uuu ?
> 

Yes, I use uuu.


> > we have to
> > allocate 65 bytes not 64 bytes. Otherwise there is potential buffer
> > overflow.
> >
> > So the wMaxPacketSize of fullspeed can't meet the needs. Add HS
> > endpoint descriptor for SDP. Then we can use high speed endpoint, and
> > the SDP device can send packet with 512 byte size.
> >
> > Signed-off-by: Sherry Sun 
> > Signed-off-by: Ye Li 
> > ---
> >  drivers/usb/gadget/f_sdp.c | 33 ++---
> >  1 file changed, 30 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
> > index b1601575e0..532041063a 100644
> > --- a/drivers/usb/gadget/f_sdp.c
> > +++ b/drivers/usb/gadget/f_sdp.c
> > @@ -157,6 +157,16 @@ static struct usb_endpoint_descriptor in_desc = {
> > .bInterval =1,
> >  };
> >
> > +static struct usb_endpoint_descriptor in_hs_desc = {
> > +   .bLength =  USB_DT_ENDPOINT_SIZE,
> > +   .bDescriptorType =
> > USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ +
> > +   .bEndpointAddress = 1 | USB_DIR_IN,
> > +   .bmAttributes = USB_ENDPOINT_XFER_INT,
> > +   .wMaxPacketSize =   512,
> > +   .bInterval =1,
> 
> Which endpoint do we use in SDP? EP0 or EP1...n ?

We use EP0 to transfer datas from host to device in report 1 and report 2.
And use EP1 to transfer datas from device to host in report3 and report 4.


> 
> > +};
> > +
> >  static struct usb_descriptor_header *sdp_runtime_descs[] = {
> > (struct usb_descriptor_header *)_intf_runtime,
> > (struct usb_descriptor_header *)_hid_desc, @@ -164,6 +174,13 @@
> > static struct usb_descriptor_header *sdp_runtime_descs[] = { NULL,  };
> >
> > +static struct usb_descriptor_header *sdp_runtime_hs_descs[] = {
> > +   (struct usb_descriptor_header *)_intf_runtime,
> > +   (struct usb_descriptor_header *)_hid_desc,
> > +   (struct usb_descriptor_header *)_hs_desc,
> > +   NULL,
> > +};
> > +
> >  /* This is synchronized with what the SoC implementation reports */
> > static struct hid_report sdp_hid_report = {
> > .usage_page = {
> > @@ -489,6 +506,11 @@ static int sdp_bind(struct usb_configuration *c,
> > struct usb_function *f) goto error;
> > }
> >
> > +   if (gadget_is_dualspeed(gadget)) {
> > +   /* Assume endpoint addresses are the same for both
> > speeds */
> > +   in_hs_desc.bEndpointAddress =
> > in_desc.bEndpointAddress;
> > +   }
> > +
> > sdp->in_ep = ep; /* Store IN EP for enabling @ setup */
> >
> > cdev->req->context = sdp;
> > @@ -526,7 +548,7 @@ static struct usb_request *sdp_start_ep(struct
> > usb_ep *ep) {
> > struct usb_request *req;
> >
> > -   req = alloc_ep_req(ep, 64);
> > +   req = alloc_ep_req(ep, 65);
> > debug("%s: ep:%p req:%p\n", __func__, ep, req);
> >
> > if (!req)
> > @@ -541,11 +563,15 @@ static int sdp_set_alt(struct usb_function *f,
> > unsigned intf, unsigned alt) {
> > struct f_sdp *sdp = func_to_sdp(f);
> > struct usb_composite_dev *cdev = f->config->cdev;
> > +   struct usb_gadget *gadget = cdev->gadget;
> > int result;
> >
> > debug("%s: intf: %d alt: %d\n", __func__, intf, alt);
> >
> > -   result = usb_ep_enable(sdp->in_ep, _desc);
> > +   if (gadget_is_dualspeed(gadget) && gadget->speed ==
> > USB_SPEED_HIGH)
> > +   result = usb_ep_enable(sdp->in_ep, _hs_desc);
> > +   else
> > +   result = usb_ep_enable(sdp->in_ep, _desc);
> > if (result)
> > return result;
> > sdp->in_req = sdp_start_ep(sdp->in_ep); @@ -591,7 +617,7 @@ static
> > int sdp_bind_config(struct usb_configuration *c) memset(sdp_func, 0,
> >

[U-Boot] [PATCH 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor

2019-07-17 Thread sherry sun
From: Sherry Sun 

Because the buffer length of sdp usb request is 65, we have to allocate
65 bytes not 64 bytes. Otherwise there is potential buffer overflow.

So the wMaxPacketSize of fullspeed can't meet the needs. Add HS
endpoint descriptor for SDP. Then we can use high speed endpoint,
and the SDP device can send packet with 512 byte size.

Signed-off-by: Sherry Sun 
Signed-off-by: Ye Li 
---
 drivers/usb/gadget/f_sdp.c | 33 ++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index b1601575e0..532041063a 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -157,6 +157,16 @@ static struct usb_endpoint_descriptor in_desc = {
.bInterval =1,
 };
 
+static struct usb_endpoint_descriptor in_hs_desc = {
+   .bLength =  USB_DT_ENDPOINT_SIZE,
+   .bDescriptorType =  USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/
+
+   .bEndpointAddress = 1 | USB_DIR_IN,
+   .bmAttributes = USB_ENDPOINT_XFER_INT,
+   .wMaxPacketSize =   512,
+   .bInterval =1,
+};
+
 static struct usb_descriptor_header *sdp_runtime_descs[] = {
(struct usb_descriptor_header *)_intf_runtime,
(struct usb_descriptor_header *)_hid_desc,
@@ -164,6 +174,13 @@ static struct usb_descriptor_header *sdp_runtime_descs[] = 
{
NULL,
 };
 
+static struct usb_descriptor_header *sdp_runtime_hs_descs[] = {
+   (struct usb_descriptor_header *)_intf_runtime,
+   (struct usb_descriptor_header *)_hid_desc,
+   (struct usb_descriptor_header *)_hs_desc,
+   NULL,
+};
+
 /* This is synchronized with what the SoC implementation reports */
 static struct hid_report sdp_hid_report = {
.usage_page = {
@@ -489,6 +506,11 @@ static int sdp_bind(struct usb_configuration *c, struct 
usb_function *f)
goto error;
}
 
+   if (gadget_is_dualspeed(gadget)) {
+   /* Assume endpoint addresses are the same for both speeds */
+   in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress;
+   }
+
sdp->in_ep = ep; /* Store IN EP for enabling @ setup */
 
cdev->req->context = sdp;
@@ -526,7 +548,7 @@ static struct usb_request *sdp_start_ep(struct usb_ep *ep)
 {
struct usb_request *req;
 
-   req = alloc_ep_req(ep, 64);
+   req = alloc_ep_req(ep, 65);
debug("%s: ep:%p req:%p\n", __func__, ep, req);
 
if (!req)
@@ -541,11 +563,15 @@ static int sdp_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
 {
struct f_sdp *sdp = func_to_sdp(f);
struct usb_composite_dev *cdev = f->config->cdev;
+   struct usb_gadget *gadget = cdev->gadget;
int result;
 
debug("%s: intf: %d alt: %d\n", __func__, intf, alt);
 
-   result = usb_ep_enable(sdp->in_ep, _desc);
+   if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH)
+   result = usb_ep_enable(sdp->in_ep, _hs_desc);
+   else
+   result = usb_ep_enable(sdp->in_ep, _desc);
if (result)
return result;
sdp->in_req = sdp_start_ep(sdp->in_ep);
@@ -591,7 +617,7 @@ static int sdp_bind_config(struct usb_configuration *c)
memset(sdp_func, 0, sizeof(*sdp_func));
 
sdp_func->usb_function.name = "sdp";
-   sdp_func->usb_function.hs_descriptors = sdp_runtime_descs;
+   sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs;
sdp_func->usb_function.descriptors = sdp_runtime_descs;
sdp_func->usb_function.bind = sdp_bind;
sdp_func->usb_function.unbind = sdp_unbind;
@@ -724,6 +750,7 @@ static void sdp_handle_in_ep(struct spl_image_info 
*spl_image)
/* In SPL, allow jumps to U-Boot images */
struct spl_image_info spl_image = {};
spl_parse_image_header(_image, header);
+
jump_to_image_no_args(_image);
 #else
/* In U-Boot, allow jumps to scripts */
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 0/4] Make some changes to SDP

2019-07-17 Thread sherry sun
From: Sherry Sun 

This patchset adds:
1. Add usb_gadget_initialize() and usb_gadget_release() to initialize and
release UDC during sdp download.
2. Add high speed endpoint descriptor for sdp. 
3. Add a macro definition--CONFIG_SDP_LOADADDR as default sdp load
address while SDP_WRITE and SDP_JUMP command addr is zero.

Sherry Sun (4):
  imx: spl: Change USB boot device type
  SDP: use CONFIG_SDP_LOADADDR as default load address
  SDP: fix wrong usb request size and add high speed endpoint descriptor
  SDP: Call usb_gadget_initialize and usb_gadget_release to support UDC

 arch/arm/mach-imx/spl.c|  2 +-
 common/spl/spl_sdp.c   |  4 
 drivers/usb/gadget/Kconfig |  4 
 drivers/usb/gadget/f_sdp.c | 39 +-
 4 files changed, 43 insertions(+), 6 deletions(-)

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/4] SDP: use CONFIG_SDP_LOADADDR as default load address

2019-07-17 Thread sherry sun
From: Sherry Sun 

If SDP_WRITE and SDP_JUMP command addr is zero, use CONFIG_SDP_LOADADDR
as default address.

Signed-off-by: Sherry Sun 
Signed-off-by: Frank Li 
---
 drivers/usb/gadget/Kconfig | 4 
 drivers/usb/gadget/f_sdp.c | 6 --
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 26b4d12a09..172a82195b 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -115,6 +115,10 @@ config USB_GADGET_VBUS_DRAW
   This value will be used except for system-specific gadget
   drivers that have more specific information.
 
+config SDP_LOADADDR
+   hex "Default load address at SDP_WRITE and SDP_JUMP"
+   default 0
+
 # Selected by UDC drivers that support high-speed operation.
 config USB_GADGET_DUALSPEED
bool
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
index fab7ce6f97..b1601575e0 100644
--- a/drivers/usb/gadget/f_sdp.c
+++ b/drivers/usb/gadget/f_sdp.c
@@ -275,7 +275,8 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
sdp->error_status = SDP_WRITE_FILE_COMPLETE;
 
sdp->state = SDP_STATE_RX_FILE_DATA;
-   sdp->dnl_address = be32_to_cpu(cmd->addr);
+   sdp->dnl_address = cmd->addr ? be32_to_cpu(cmd->addr) :
+  CONFIG_SDP_LOADADDR;
sdp->dnl_bytes_remaining = be32_to_cpu(cmd->cnt);
sdp->dnl_bytes = sdp->dnl_bytes_remaining;
sdp->next_state = SDP_STATE_IDLE;
@@ -303,7 +304,8 @@ static void sdp_rx_command_complete(struct usb_ep *ep, 
struct usb_request *req)
sdp->always_send_status = false;
sdp->error_status = 0;
 
-   sdp->jmp_address = be32_to_cpu(cmd->addr);
+   sdp->jmp_address = cmd->addr ? be32_to_cpu(cmd->addr) :
+  CONFIG_SDP_LOADADDR;
sdp->state = SDP_STATE_TX_SEC_CONF;
sdp->next_state = SDP_STATE_JUMP;
break;
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 4/4] SDP: Call usb_gadget_initialize and usb_gadget_release to support UDC

2019-07-17 Thread sherry sun
From: Sherry Sun 

Need initialize UDC before run sdp download and release it at the end of
sdp.

Signed-off-by: Sherry Sun 
Signed-off-by: Frank Li 
---
 common/spl/spl_sdp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/common/spl/spl_sdp.c b/common/spl/spl_sdp.c
index 806bf1327e..7b0a213d4c 100644
--- a/common/spl/spl_sdp.c
+++ b/common/spl/spl_sdp.c
@@ -16,6 +16,8 @@ static int spl_sdp_load_image(struct spl_image_info 
*spl_image,
int ret;
const int controller_index = 0;
 
+   usb_gadget_initialize(controller_index);
+
g_dnl_clear_detach();
ret = g_dnl_register("usb_dnl_sdp");
if (ret) {
@@ -37,6 +39,8 @@ static int spl_sdp_load_image(struct spl_image_info 
*spl_image,
ret = spl_sdp_handle(controller_index, spl_image);
debug("SDP ended\n");
 
+   usb_gadget_release(controller_index);
+
return ret;
 }
 SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/4] imx: spl: Change USB boot device type

2019-07-17 Thread sherry sun
From: Sherry Sun 

The SPL SDP is configured as BOOT_DEVICE_BOARD, so when booting from
USB, change its type to BOOT_DEVICE_BOARD, so we can use SDP.

Signed-off-by: Sherry Sun 
Signed-off-by: Ye Li 
---
 arch/arm/mach-imx/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index 9f1e0f6a72..2355019243 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -156,7 +156,7 @@ u32 spl_boot_device(void)
case SPI_NOR_BOOT:
return BOOT_DEVICE_SPI;
case USB_BOOT:
-   return BOOT_DEVICE_USB;
+   return BOOT_DEVICE_BOARD;
default:
return BOOT_DEVICE_NONE;
}
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 3/3] USB: gadget: core: introduce ->udc_set_speed() method

2019-07-16 Thread sherry sun
From: Sherry Sun 

This patch was copied from kernel commit: 67fdfda4a99ed.

Sometimes, the gadget driver we want to run has max_speed lower than
what the UDC supports. In such situations, UDC might want to make sure
we don't try to connect on speeds not supported by the gadget
driver because that will just fail.

So here introduce a new optional ->udc_set_speed() method which can be
implemented by interested UDC drivers to achieve this purpose.

Signed-off-by: Sherry Sun 
---
 drivers/usb/gadget/udc/udc-core.c | 23 +++
 include/linux/usb/gadget.h|  2 ++
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index 62b47781dd..8d1d90e3e3 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -267,6 +267,27 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
 /* - */
 
+/**
+ * usb_gadget_udc_set_speed - tells usb device controller speed supported by
+ *current driver
+ * @udc: The device we want to set maximum speed
+ * @speed: The maximum speed to allowed to run
+ *
+ * This call is issued by the UDC Class driver before calling
+ * usb_gadget_udc_start() in order to make sure that we don't try to
+ * connect on speeds the gadget driver doesn't support.
+ */
+static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
+   enum usb_device_speed speed)
+{
+   if (udc->gadget->ops->udc_set_speed) {
+   enum usb_device_speed s;
+
+   s = min(speed, udc->gadget->max_speed);
+   udc->gadget->ops->udc_set_speed(udc->gadget, s);
+   }
+}
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver 
*driver)
 {
int ret;
@@ -276,6 +297,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct 
usb_gadget_driver *dri
 
udc->driver = driver;
 
+   usb_gadget_udc_set_speed(udc, driver->speed);
+
ret = driver->bind(udc->gadget);
if (ret)
goto err1;
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index a34f3478f3..78e245a1b5 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -450,6 +450,8 @@ struct usb_gadget_ops {
int   (*match_ep)(struct usb_gadget *gadget,
  struct usb_ep *ep,
  struct usb_endpoint_descriptor *desc);
+   void(*udc_set_speed)(struct usb_gadget *gadget,
+enum usb_device_speed);
 };
 
 /**
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/3] USB: host: Add the USB3 host driver

2019-07-16 Thread sherry sun
From: Sherry Sun 

This driver is ported from NXP i.MX U-Boot version imx_v2019.04
and some changes have also been made to adapt to U-Boot.

Add the USB3 host driver for NXP imx8 platform, and the
cadence IP is in it.

The USB3 host driver support DM mode. It will probe USB3
host node, enable the power and clk of both USB3 controller
and USB3 PHY.

Signed-off-by: Sherry Sun 
---
 drivers/usb/host/Kconfig|   9 +
 drivers/usb/host/Makefile   |   1 +
 drivers/usb/host/xhci-imx8.c| 311 ++
 include/usb/imx8_usb3_reg_def.h | 455 
 4 files changed, 776 insertions(+)
 create mode 100644 drivers/usb/host/xhci-imx8.c
 create mode 100644 include/usb/imx8_usb3_reg_def.h

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index b1188bcbf5..73c98e0cf4 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -94,6 +94,15 @@ config USB_XHCI_FSL
depends on !SPL_NO_USB
help
  Enables support for the on-chip xHCI controller on NXP Layerscape 
SoCs.
+
+config USB_XHCI_IMX8
+   bool "XHCI support for imx8"
+   depends on ARCH_IMX8
+   default y
+   help
+ Enables support for the on-chip xHCI controller on imx8qm and
+ imx8qxp SoCs.
+
 endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 6aa574f6f7..e5a0a4ea5a 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o
 obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o
 obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o
 obj-$(CONFIG_USB_XHCI_STI) += dwc3-sti-glue.o
+obj-$(CONFIG_USB_XHCI_IMX8) += xhci-imx8.o
 
 # designware
 obj-$(CONFIG_USB_DWC2) += dwc2.o
diff --git a/drivers/usb/host/xhci-imx8.c b/drivers/usb/host/xhci-imx8.c
new file mode 100644
index 00..abac37d446
--- /dev/null
+++ b/drivers/usb/host/xhci-imx8.c
@@ -0,0 +1,311 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 NXP
+ *
+ * NXP i.MX8 USB HOST xHCI Controller (Cadence IP)
+ *
+ * Author: Peter Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "xhci.h"
+
+/* Declare global data pointer */
+DECLARE_GLOBAL_DATA_PTR;
+
+/* According to UG CH 3.1.1 Bring-up Sequence */
+static void imx_usb3_phy_init(void)
+{
+   writel(0x0830, PHY_PMA_CMN_CTRL1);
+   writel(0x10, TB_ADDR_CMN_DIAG_HSCLK_SEL);
+   writel(0x00F0, TB_ADDR_CMN_PLL0_VCOCAL_INIT_TMR);
+   writel(0x0018, TB_ADDR_CMN_PLL0_VCOCAL_ITER_TMR);
+   writel(0x00D0, TB_ADDR_CMN_PLL0_INTDIV);
+   writel(0x4aaa, TB_ADDR_CMN_PLL0_FRACDIV);
+   writel(0x0034, TB_ADDR_CMN_PLL0_HIGH_THR);
+   writel(0x1ee, TB_ADDR_CMN_PLL0_SS_CTRL1);
+   writel(0x7F03, TB_ADDR_CMN_PLL0_SS_CTRL2);
+   writel(0x0020, TB_ADDR_CMN_PLL0_DSM_DIAG);
+   writel(0x, TB_ADDR_CMN_DIAG_PLL0_OVRD);
+   writel(0x, TB_ADDR_CMN_DIAG_PLL0_FBH_OVRD);
+   writel(0x, TB_ADDR_CMN_DIAG_PLL0_FBL_OVRD);
+   writel(0x0007, TB_ADDR_CMN_DIAG_PLL0_V2I_TUNE);
+   writel(0x0027, TB_ADDR_CMN_DIAG_PLL0_CP_TUNE);
+   writel(0x0008, TB_ADDR_CMN_DIAG_PLL0_LF_PROG);
+   writel(0x0022, TB_ADDR_CMN_DIAG_PLL0_TEST_MODE);
+   writel(0x000a, TB_ADDR_CMN_PSM_CLK_CTRL);
+   writel(0x139, TB_ADDR_XCVR_DIAG_RX_LANE_CAL_RST_TMR);
+   writel(0xbefc, TB_ADDR_XCVR_PSM_RCTRL);
+
+   writel(0x7799, TB_ADDR_TX_PSC_A0);
+   writel(0x7798, TB_ADDR_TX_PSC_A1);
+   writel(0x509b, TB_ADDR_TX_PSC_A2);
+   writel(0x3, TB_ADDR_TX_DIAG_ECTRL_OVRD);
+   writel(0x5098, TB_ADDR_TX_PSC_A3);
+   writel(0x2090, TB_ADDR_TX_PSC_CAL);
+   writel(0x2090, TB_ADDR_TX_PSC_RDY);
+
+   writel(0xA6FD, TB_ADDR_RX_PSC_A0);
+   writel(0xA6FD, TB_ADDR_RX_PSC_A1);
+   writel(0xA410, TB_ADDR_RX_PSC_A2);
+   writel(0x2410, TB_ADDR_RX_PSC_A3);
+
+   writel(0x23FF, TB_ADDR_RX_PSC_CAL);
+   writel(0x2010, TB_ADDR_RX_PSC_RDY);
+
+   writel(0x0020, TB_ADDR_TX_TXCC_MGNLS_MULT_000);
+   writel(0x00ff, TB_ADDR_TX_DIAG_BGREF_PREDRV_DELAY);
+   writel(0x0002, TB_ADDR_RX_SLC_CU_ITER_TMR);
+   writel(0x0013, TB_ADDR_RX_SIGDET_HL_FILT_TMR);
+   writel(0x, TB_ADDR_RX_SAMP_DAC_CTRL);
+   writel(0x1004, TB_ADDR_RX_DIAG_SIGDET_TUNE);
+   writel(0x4041, TB_ADDR_RX_DIAG_LFPSDET_TUNE2);
+   writel(0x0480, TB_ADDR_RX_DIAG_BS_TM);
+   writel(0x8006, TB_ADDR_RX_DIAG_DFE_CTRL1);
+   writel(0x003f, TB_ADDR_RX_DIAG_ILL_IQE_TRIM4);
+   writel(0x543f, TB_ADDR_RX_DIAG_ILL_E_TRIM0);
+   writel(0x543f, TB_ADDR_RX_DIAG_ILL_IQ_TRIM0);
+   writel(0x, TB_ADDR_RX_DIAG_ILL_IQE_TRIM6);
+   writel(0x8000, TB_ADDR_RX_DIAG_RXFE_TM3);
+   writel(0x0003, TB_ADDR_RX_DIAG_RXFE_TM4);
+   writel(0x2408, TB_ADDR_RX_DIAG_LFPSDET_TUNE);
+   writel(0x05ca, TB_ADDR_RX_DIAG_DFE_CTRL3);
+   writel(0x0258, TB_ADD

[U-Boot] [PATCH 0/3] USB: Add cadence USB3 gadget driver and host driver

2019-07-16 Thread sherry sun
From: Sherry Sun 

These patches introduce new Cadence USBSS driver to U-Boot.

The first patch is to add the Cadence USB3 IP(CDNS3) driver for the usb
gadget, but the host mode is not supported now. The second patch
introduce the xhci-imx8 usb host driver separately. The cdns3 usb
gadget driver and xhci-imx8 host driver both use DM mode.

The current driver has been validated on i.MX8 platform.

Sherry Sun (3):
  USB: gadget: Add the cadence USB3 gadget driver
  USB: host: Add the USB3 host driver
  USB: gadget: core: introduce ->udc_set_speed() method

 Makefile  |1 +
 drivers/usb/Kconfig   |2 +
 drivers/usb/cdns3/Kconfig |   20 +
 drivers/usb/cdns3/Makefile|5 +
 drivers/usb/cdns3/cdns3-generic.c |  176 ++
 drivers/usb/cdns3/cdns3-nxp-reg-def.h |  158 ++
 drivers/usb/cdns3/core.c  |  408 +
 drivers/usb/cdns3/core.h  |  129 ++
 drivers/usb/cdns3/dev-regs-macro.h|  116 ++
 drivers/usb/cdns3/dev-regs-map.h  |  117 ++
 drivers/usb/cdns3/gadget-export.h |   26 +
 drivers/usb/cdns3/gadget.c| 2278 +
 drivers/usb/cdns3/gadget.h|  238 +++
 drivers/usb/cdns3/io.h|   30 +
 drivers/usb/cdns3/linux-compat.h  |   16 +
 drivers/usb/gadget/epautoconf.c   |4 +
 drivers/usb/gadget/gadget_chips.h |7 +
 drivers/usb/gadget/udc/Makefile   |1 +
 drivers/usb/gadget/udc/udc-core.c |   23 +
 drivers/usb/host/Kconfig  |9 +
 drivers/usb/host/Makefile |1 +
 drivers/usb/host/xhci-imx8.c  |  311 
 include/cdns3-uboot.h |   26 +
 include/linux/usb/gadget.h|5 +
 include/usb/imx8_usb3_reg_def.h   |  455 +
 scripts/Makefile.spl  |1 +
 26 files changed, 4563 insertions(+)
 create mode 100644 drivers/usb/cdns3/Kconfig
 create mode 100644 drivers/usb/cdns3/Makefile
 create mode 100644 drivers/usb/cdns3/cdns3-generic.c
 create mode 100644 drivers/usb/cdns3/cdns3-nxp-reg-def.h
 create mode 100644 drivers/usb/cdns3/core.c
 create mode 100644 drivers/usb/cdns3/core.h
 create mode 100644 drivers/usb/cdns3/dev-regs-macro.h
 create mode 100644 drivers/usb/cdns3/dev-regs-map.h
 create mode 100644 drivers/usb/cdns3/gadget-export.h
 create mode 100644 drivers/usb/cdns3/gadget.c
 create mode 100644 drivers/usb/cdns3/gadget.h
 create mode 100644 drivers/usb/cdns3/io.h
 create mode 100644 drivers/usb/cdns3/linux-compat.h
 create mode 100644 drivers/usb/host/xhci-imx8.c
 create mode 100644 include/cdns3-uboot.h
 create mode 100644 include/usb/imx8_usb3_reg_def.h

-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] 答复: [EXT] Re: Upstreaming usb host drivers for iMX8/iMX8M

2019-07-01 Thread Sherry Sun
+ Ying

> -邮件原件-
> 发件人: Igor Opaniuk 
> 发送时间: 2019年7月1日 19:32
> 收件人: Sherry Sun 
> 抄送: Peng Fan ; Jun Li ; Ye Li
> ; U-Boot Mailing List ; Peter Chen
> ; dl-uboot-imx ; Marcel Ziswiler
> ; Max Krummenacher
> ; Igor Opaniuk
> ; Frank Li 
> 主题: [EXT] Re: Upstreaming usb host drivers for iMX8/iMX8M
> 
> Caution: EXT Email
> 
> Hi Sherry,
> 
> On Fri, Jun 28, 2019 at 8:02 AM Sherry Sun  wrote:
> >
> > Hi, Igor
> >
> > We have the plan to do the upstream job of cdns3 host/gadget drivers on
> imx8.
> > Now we just have done the DM switch of cdns3 gadget driver, and there
> > also some changes in xhci_imx8.c.
> Thanks for the details!
> 
> > We plan to start our upstream job from next week, and the first
> > version will be send to maintainer within two or three weeks. We hope
> > it will be included in uboot v2019.07 RC2.
> I'm afraid we're a bit late here.
> v2019.07 is going to be released next Monday (there was a release of
> v2019.07-rc4 already in June 11), so the next merge window for
> v2019.10 opens July 9.

Yes, you are right. 
Anyway, I will try my best and finish the upstream job as soon as possible.

> > Do you think this is okay?
> Sounds good! Looking forward to your patches in the mailing list!
> 
> >
> > Best regards
> > Sherry sun
> >
> >
> Just a bit off-topic, but are you aware about similar plans for upstreaming of
> DPU driver for i.MX8 (driver/video/imxdpuv1.c)?

Sorry, I am not quite sure. 
Ying knows more about this. Maybe he can answer you.

Best regards
Sherry sun

> > -邮件原件-
> > 发件人: Peng Fan
> > 发送时间: 2019年6月27日 17:58
> > 收件人: Igor Opaniuk ; Sherry Sun
> > ; Jun Li 
> > 抄送: U-Boot Mailing List ; Ye Li ;
> > Peter Chen ; dl-uboot-imx ;
> > Marcel Ziswiler ; Max Krummenacher
> > ; Igor Opaniuk
> > ; Frank Li 
> > 主题: RE: Upstreaming usb host drivers for iMX8/iMX8M
> >
> > + Sherry, Jun
> >
> > > Subject: Re: Upstreaming usb host drivers for iMX8/iMX8M
> > >
> > > Hi Peng,
> > >
> > > On Thu, Jun 27, 2019 at 8:32 AM Peng Fan  wrote:
> > > >
> > > >
> > > > Hi Igor,
> > > >
> > > > > Subject: Upstreaming usb host drivers for iMX8/iMX8M
> > > > >
> > > > > Hi Peng, Ye, Peter,
> > > > >
> > > > > Currently there in no any usb host/gadget support in the
> > > > > mainline U-boot, and seems that no one has posted anything yet
> > > > > to the mailing list (at least I haven't found anything related to 
> > > > > this in the
> ML archives).
> > > > >
> > > > > I've spent some time testing (usb host, ums etc.) the one in the
> > > > > downstream NXP U-boot (I'm still not sure where is the official
> > > > > NXP downstream rep, because there are no any updates in [1] for
> > > > > the last two years, so I looked into [2], [3]), and just curious
> > > > > if there any plans to get it upstreamed in the near future?
> > > >
> > > > In NXP downstream, there is work to migrate the i.MX8 usb/gadget to
> DM.
> > > > When that ready, the patches will be posted to community.
> > >
> > > So do you need any help with this?
> >
> > I am not working on that. But I welcome any contribution to make more
> features supported in upstream.
> >
> > Won't you mind if we start up-streaming at
> > > least xhci-imx8.c, which is used in both our SoMs Apalis iMX8 and
> > > Colibri iMX8QXP. Based on what I've seen in [1], the initial
> > > conversion to DM_USB is already done. Is there anything else that is
> > > expected to be changed in xhci-imx8.c (by asking this I just want to avoid
> duplicating the effort)?
> >
> > Sherry, Jun has some work on the driver. So they might have comments to
> avoid duplicating efforts, in case they has plan recently.
> >
> > Regards,
> > Peng.
> >
> > >
> > > Frankly, this is currently a kind of showstopper for us, as it adds
> > > some complications for the next release of our BSP (we would like to
> > > enable usb host/gadget support or iMX8-based SoMS, including all
> > > dependent features like fastboot/usb storage/ums etc.), where we
> > > made a decision to move towards the usage of the mainline U-boot
> > > (with the minimal divergence and minimal amount of legacy downstream
> patches on top of it).
> > >
> > > >
> > > >
> > > >