All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/3] rockchip: evb-rv1108: add usb init function for dwc2 gadget
Date: Fri, 8 Sep 2017 22:54:45 -0600	[thread overview]
Message-ID: <CAPnjgZ1ETtM6dgk_0AU9dNuaiWRGNhnq4k77e8e+jWuWg37Z4A@mail.gmail.com> (raw)
In-Reply-To: <19f8cdc0-5408-bad2-433b-660736f7394b@rock-chips.com>

Hi,

On 14 August 2017 at 04:05, wlf <wulf@rock-chips.com> wrote:
> Dear Simon,
>
>
> 在 2017年08月14日 05:35, Simon Glass 写道:
>>
>> On 8 August 2017 at 21:36, William Wu <william.wu@rock-chips.com> wrote:
>>>
>>> This patch implements board_usb_init() for dwc2 gadget, it
>>> generally called from do_fastboot to do dwc2 udc probe and
>>> support fastboot over USB.
>>>
>>> Signed-off-by: William Wu <william.wu@rock-chips.com>
>>> ---
>>>   board/rockchip/evb_rv1108/evb_rv1108.c | 47
>>> ++++++++++++++++++++++++++++++++++
>>>   1 file changed, 47 insertions(+)
>>>
>>> diff --git a/board/rockchip/evb_rv1108/evb_rv1108.c
>>> b/board/rockchip/evb_rv1108/evb_rv1108.c
>>> index fe37eac..8ca5ee6 100644
>>> --- a/board/rockchip/evb_rv1108/evb_rv1108.c
>>> +++ b/board/rockchip/evb_rv1108/evb_rv1108.c
>>> @@ -50,3 +50,50 @@ int dram_init_banksize(void)
>>>
>>>          return 0;
>>>   }
>>> +
>>> +#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
>>> +#include <usb.h>
>>> +#include <usb/dwc2_udc.h>
>>> +
>>> +static struct dwc2_plat_otg_data rv1108_otg_data = {
>>> +       .rx_fifo_sz     = 512,
>>> +       .np_tx_fifo_sz  = 16,
>>> +       .tx_fifo_sz     = 128,
>>> +};
>>> +
>>> +int board_usb_init(int index, enum usb_init_type init)
>>> +{
>>> +       int node;
>>> +       const char *mode;
>>> +       bool matched = false;
>>> +       const void *blob = gd->fdt_blob;
>>> +
>>> +       /* find the usb_otg node */
>>> +       node = fdt_node_offset_by_compatible(blob, -1,
>>> +                                       "rockchip,rv1108-usb");
>>> +
>>> +       while (node > 0) {
>>> +               mode = fdt_getprop(blob, node, "dr_mode", NULL);
>>> +               if (mode && strcmp(mode, "otg") == 0) {
>>> +                       matched = true;
>>> +                       break;
>>> +               }
>>> +
>>> +               node = fdt_node_offset_by_compatible(blob, node,
>>> +                                       "rockchip,rv1108-usb");
>>> +       }
>>> +       if (!matched) {
>>> +               debug("Not found usb_otg device\n");
>>> +               return -ENODEV;
>>> +       }
>>> +
>>> +       rv1108_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
>>> +
>>> +       return dwc2_udc_probe(&rv1108_otg_data);
>>
>> These USB init things have been bothering me for a while. Do you think
>> this could be changed into a driver that you could probe with
>> device_probe()? Then much of the code in here would not be needed and
>> it might be easier to tidy it up when we have proper driver-model
>> support for USB device mode.
>
> Yes,  on rockchip platforms, it did most of the same USB init things in
> different board special drivers.
> I think may be we can try to optimize the code in two different ways.
>
> Method1.
> 1. Move the USB init things from board_usb_init(), just simply call
> dwc2_udc_probe().
> 2. Create a new USB init  function in drivers/usb/gadget/dwc2_udc_otg.c,
>      and call it in dwc2_udc_probe().
> 3. Use fdt (Flat Device Tree manipulation )  to parse the dts, and get the
> regs_phy, regs_otg and so on.
>
> Method2.
> Just like your  suggestion, use driver-model method to probe with
> device_probe,
> actually, I don't know much about the driver-model, as far as I know, we may
> need
> to do the following work:
> 1. Create a new uclass id for usb udc, and declare a new uclass_driver with
> UCLASS_DRIVER,
>     and also need to create a  new U-boot driver for dwc2 controller with
> U_BOOT_DRIVER.
> 2. How to call device_probe()? Maybe it's better to create a new driver
> (like drivers/usb/host/usb-uclass.c)
>     in drivers/usb/gadget to match different usb gadget controllers, and
> wrap the device_probe()
>     to a new function (like udc_pre_probe()), and then different udc driver
> can call it,
>     e.g.
>     dwc2_udc_probe() --> udc_pre_probe() --> device_probe()
>
> In summary, method1 is easily to be done, but method2 is more generic.
>
> I hope I haven't misunderstood your proposal, and hope to get your reply.
> Thank you!

Yes I think method 2 is better.

You will have to call device_probe() as you say. I think what you
suggest is reasonable, since something has to decide that the USB
device mode should be started.

Regards,
Simon

  parent reply	other threads:[~2017-09-09  4:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-09  3:36 [U-Boot] [PATCH 0/3] rockchip: rv1108: support USB OTG and Host ports on evb-rv1108 William Wu
2017-08-09  3:36 ` [U-Boot] [PATCH 1/3] configs: rockchip: add USB configs for evb-rv1108 board William Wu
2017-08-13 21:35   ` Simon Glass
2017-08-18 16:08   ` [U-Boot] [U-Boot, " Philipp Tomsich
2017-09-05  9:52   ` Philipp Tomsich
2017-09-05 12:22   ` Philipp Tomsich
2017-08-09  3:36 ` [U-Boot] [PATCH 2/3] ARM: dts: rockchip: add USB nodes for evb-rv1108 William Wu
2017-08-13 21:35   ` Simon Glass
2017-08-18 16:08   ` [U-Boot] [U-Boot, " Philipp Tomsich
2017-09-05  9:52   ` Philipp Tomsich
2017-09-05 12:22   ` Philipp Tomsich
2017-08-09  3:36 ` [U-Boot] [PATCH 3/3] rockchip: evb-rv1108: add usb init function for dwc2 gadget William Wu
2017-08-13 21:35   ` Simon Glass
2017-08-14 10:05     ` wlf
2017-09-05  4:14       ` wlf
2017-09-09  4:54       ` Simon Glass [this message]
2017-09-11  3:51         ` wlf
2017-08-18 16:08   ` [U-Boot] [U-Boot, " Philipp Tomsich
  -- strict thread matches above, loose matches on Subject: below --
2017-08-09  3:12 [U-Boot] [PATCH 0/3] rockchip: rv1108: support USB OTG and Host ports on evb-rv1108 William Wu
2017-08-09  3:12 ` [U-Boot] [PATCH 3/3] rockchip: evb-rv1108: add usb init function for dwc2 gadget William Wu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPnjgZ1ETtM6dgk_0AU9dNuaiWRGNhnq4k77e8e+jWuWg37Z4A@mail.gmail.com \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.