public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Kever Yang <kever.yang@rock-chips.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/4] usb: dwc2: add support for external vbus supply
Date: Tue, 29 Nov 2016 16:46:56 +0800	[thread overview]
Message-ID: <583D4080.2040902@rock-chips.com> (raw)
In-Reply-To: <92d6cb3e-d748-3a2d-9a6f-783d910eefd6@denx.de>

Hi Marek,

On 11/26/2016 12:46 AM, Marek Vasut wrote:
> On 11/24/2016 08:29 AM, Kever Yang wrote:
>> Some board do not use the dwc2 internal VBUS_DRV signal, but
>> use a gpio pin to enable the 5.0V VBUS power, add interface to
>> enable the power in dwc2 driver.
>>
>> Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
>> ---
>>
>> Changes in v2: None
>>
>>   drivers/usb/host/dwc2.c | 29 +++++++++++++++++++++++++++++
>>   1 file changed, 29 insertions(+)
>>
>> diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
>> index d08879d..8292aa8 100644
>> --- a/drivers/usb/host/dwc2.c
>> +++ b/drivers/usb/host/dwc2.c
>> @@ -15,6 +15,7 @@
>>   #include <usbroothubdes.h>
>>   #include <wait_bit.h>
>>   #include <asm/io.h>
>> +#include <power/regulator.h>
>>   
>>   #include "dwc2.h"
>>   
>> @@ -55,6 +56,8 @@ DEFINE_ALIGN_BUFFER(uint8_t, status_buffer_addr, DWC2_STATUS_BUF_SIZE,
>>   static struct dwc2_priv local;
>>   #endif
>>   
>> +static struct udevice *g_dwc2_udev;
> Can we avoid the static global var ?

I don't want to use this global var either, but I don't know how to get 
this udev structure
without this var, do you have any good suggestion?
BTW, of_container() is not available to find the udevice structure with 
dwc2_priv pointer.

>
>> +
>>   /*
>>    * DWC2 IP interface
>>    */
>> @@ -159,6 +162,29 @@ static void dwc_otg_core_reset(struct dwc2_core_regs *regs)
>>   	mdelay(100);
>>   }
>>   
>> +static int dwc_vbus_supply_init(void)
>> +{
>> +#if defined(CONFIG_DM_USB) && defined(CONFIG_DM_REGULATOR) && \
>> +	!defined(CONFIG_SPL_BUILD)
> Why does this not work for SPL ?

We do not enable the USB driver in SPL, in this case I can just drop the 
CONFIG_SPL_BUILD
because the driver in not compiled in SPL.

>
> btw, I'd rather see this as:
>
> #if FOO
> function bar()
> {
>   ...
> }
> #else
> static inline function bar()
> {
>   return 0;
> }
> #endif
>
>> +	struct udevice *vbus_supply;
>> +	int ret;
>> +
>> +	ret = device_get_supply_regulator(g_dwc2_udev, "vbus-supply",
>> +					  &vbus_supply);
> Is this compatible with the Linux DWC2 DT bindings ?

This compatible in kernel is in in phy dts node, the dwc2 driver and phy 
driver
in U-Boot are both very different from kernel now, so I chose a place 
which is
reasonable to enable the vbus.

>
>> +	if (ret) {
>> +		debug("%s: No vbus supply\n", g_dwc2_udev->name);
>> +		return 0;
>> +	}
>> +
>> +	ret = regulator_set_enable(vbus_supply, true);
> Shouldn't the regulator be enabled when we enable VBUS for a port
> instead of here ? And where is it disabled ?

I add this function just after the controller enable the port power bit, 
isn't it?
I didn't found anywhere the driver disable the vbus power, we do not need it
in U-Boot?

Thanks,
- Kever
>
>> +	if (ret) {
>> +		error("Error enabling vbus supply\n");
>> +		return ret;
>> +	}
>> +#endif
>> +	return 0;
>> +}
>> +
>>   /*
>>    * This function initializes the DWC_otg controller registers for
>>    * host mode.
>> @@ -248,6 +274,8 @@ static void dwc_otg_core_host_init(struct dwc2_core_regs *regs)
>>   			writel(hprt0, &regs->hprt0);
>>   		}
>>   	}
>> +
>> +	dwc_vbus_supply_init();
>>   }
>>   
>>   /*
>> @@ -1194,6 +1222,7 @@ static int dwc2_usb_ofdata_to_platdata(struct udevice *dev)
>>   	const void *prop;
>>   	fdt_addr_t addr;
>>   
>> +	g_dwc2_udev = dev;
>>   	addr = dev_get_addr(dev);
>>   	if (addr == FDT_ADDR_T_NONE)
>>   		return -EINVAL;
>>
>

  reply	other threads:[~2016-11-29  8:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-24  7:29 [U-Boot] [PATCH v2 0/4] Enable the host controller and hub on PopMetal board Kever Yang
2016-11-24  7:29 ` [U-Boot] [PATCH v2 1/4] usb: dwc2: add support for external vbus supply Kever Yang
2016-11-25 16:46   ` Marek Vasut
2016-11-29  8:46     ` Kever Yang [this message]
2016-11-30  2:00       ` Marek Vasut
2016-12-03  4:33         ` Simon Glass
2016-11-24  7:29 ` [U-Boot] [PATCH v2 2/4] board: popmetal: de-assert the host rst pin in board init Kever Yang
2016-11-25 19:39   ` Simon Glass
2016-11-29  8:49     ` Kever Yang
2016-11-30  0:34       ` Simon Glass
2016-12-03  4:50         ` Simon Glass
2016-11-24  7:29 ` [U-Boot] [PATCH v2 3/4] config: popmetal: enable the USB host controller and function Kever Yang
2016-12-03  4:51   ` Simon Glass
2016-11-24  7:29 ` [U-Boot] [PATCH v2 4/4] dts: popmetal: add usb host power supply node Kever Yang
2016-11-27 17:02   ` Simon Glass

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=583D4080.2040902@rock-chips.com \
    --to=kever.yang@rock-chips.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox