Skip to content

Commit

Permalink
usb: dwc3: Add hibernation support when operating as gadget
Browse files Browse the repository at this point in the history
This patch adds hibernation support when dwc3 controller is
operating in gadget mode

Signed-off-by: Anurag Kumar Vulisha <anuragku@xilinx.com>
Signed-off-by: Mayank Adesara <mayank.adesara@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
  • Loading branch information
Anurag Kumar Vulisha authored and Michal Simek committed Mar 1, 2018
1 parent cbc6b69 commit e061efc
Show file tree
Hide file tree
Showing 6 changed files with 729 additions and 24 deletions.
2 changes: 1 addition & 1 deletion drivers/usb/dwc3/Makefile
Expand Up @@ -15,7 +15,7 @@ ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE) $(CONFIG_
endif

ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) $(CONFIG_USB_DWC3_DUAL_ROLE) $(CONFIG_USB_DWC3_OTG)),)
dwc3-y += gadget.o ep0.o
dwc3-y += gadget.o ep0.o gadget_hibernation.o
endif

ifneq ($(CONFIG_USB_DWC3_OTG),)
Expand Down
11 changes: 9 additions & 2 deletions drivers/usb/dwc3/core.c
Expand Up @@ -230,7 +230,7 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)
* XHCI driver will reset the host block. If dwc3 was configured for
* host-only mode, then we can return early.
*/
if (dwc->dr_mode == USB_DR_MODE_HOST)
if (dwc->dr_mode == USB_DR_MODE_HOST || dwc->is_hibernated == true)
return 0;

reg = dwc3_readl(dwc->regs, DWC3_DCTL);
Expand Down Expand Up @@ -745,8 +745,15 @@ static void dwc3_core_setup_global_control(struct dwc3 *dwc)
reg &= ~DWC3_GCTL_DSBLCLKGTNG;
break;
case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
if (!device_property_read_bool(dwc->dev,
"snps,enable-hibernation")) {
dev_dbg(dwc->dev, "Hibernation not enabled\n");
break;
}

/* enable hibernation here */
dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
dwc->has_hibernation = 1;

/*
* REVISIT Enabling this bit so that host-mode hibernation
Expand Down Expand Up @@ -796,7 +803,7 @@ static int dwc3_core_get_phy(struct dwc3 *dwc);
*
* Returns 0 on success otherwise negative errno.
*/
static int dwc3_core_init(struct dwc3 *dwc)
int dwc3_core_init(struct dwc3 *dwc)
{
u32 reg;
int ret;
Expand Down
12 changes: 12 additions & 0 deletions drivers/usb/dwc3/core.h
Expand Up @@ -396,6 +396,7 @@

/* Device Status Register */
#define DWC3_DSTS_DCNRD BIT(29)
#define DWC3_DSTS_SRE BIT(28)

/* This applies for core versions 1.87a and earlier */
#define DWC3_DSTS_PWRUPREQ BIT(24)
Expand Down Expand Up @@ -884,6 +885,7 @@ struct dwc3_scratchpad_array {
* @dis_tx_ipgap_linecheck_quirk: set if we disable u2mac linestate
* check during HS transmit.
* @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
* @is_hibernated: true when dwc3 is hibernated; abort processing events
* @tx_de_emphasis: Tx de-emphasis value
* 0 - -6dB de-emphasis
* 1 - -3.5dB de-emphasis
Expand All @@ -892,6 +894,11 @@ struct dwc3_scratchpad_array {
* @imod_interval: set the interrupt moderation interval in 250ns
* increments or 0 to disable.
* @is_d3: set if the controller is in d3 state
* @saved_regs: registers to be saved/restored during hibernation/wakeup events
* @irq_wakeup: wakeup IRQ number, triggered when host asks to wakeup from
* hibernation
* @force_hiber_wake: flag set when the gadget driver is forcefully triggering
a hibernation wakeup event
*/
struct dwc3 {
struct work_struct drd_work;
Expand Down Expand Up @@ -1048,9 +1055,13 @@ struct dwc3 {

unsigned tx_de_emphasis_quirk:1;
unsigned tx_de_emphasis:2;
unsigned is_hibernated:1;

u16 imod_interval;
bool is_d3;
u32 *saved_regs;
u32 irq_wakeup;
bool force_hiber_wake;
};

#define work_to_dwc(w) (container_of((w), struct dwc3, drd_work))
Expand Down Expand Up @@ -1267,6 +1278,7 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
struct dwc3_gadget_ep_cmd_params *params);
int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param);
int dwc3_core_init(struct dwc3 *dwc);
#else
static inline int dwc3_gadget_init(struct dwc3 *dwc)
{ return 0; }
Expand Down

0 comments on commit e061efc

Please sign in to comment.