Skip to content

Commit 6bea962

Browse files
jysnpsFelipe Balbi
authored andcommitted
usb: dwc2: Add functions to check the HW OTG config
Added functions to query the GHWCFG2.OTG_MODE. This tells us whether the controller hardware is configured for OTG, device-only, or host-only. Signed-off-by: John Youn <[email protected]> Tested-by: Douglas Anderson <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent b5d308a commit 6bea962

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

drivers/usb/dwc2/core.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,6 +3342,43 @@ void dwc2_disable_global_interrupts(struct dwc2_hsotg *hsotg)
33423342
dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG);
33433343
}
33443344

3345+
/* Returns the controller's GHWCFG2.OTG_MODE. */
3346+
unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg)
3347+
{
3348+
u32 ghwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2);
3349+
3350+
return (ghwcfg2 & GHWCFG2_OP_MODE_MASK) >>
3351+
GHWCFG2_OP_MODE_SHIFT;
3352+
}
3353+
3354+
/* Returns true if the controller is capable of DRD. */
3355+
bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg)
3356+
{
3357+
unsigned op_mode = dwc2_op_mode(hsotg);
3358+
3359+
return (op_mode == GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) ||
3360+
(op_mode == GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE) ||
3361+
(op_mode == GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE);
3362+
}
3363+
3364+
/* Returns true if the controller is host-only. */
3365+
bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg)
3366+
{
3367+
unsigned op_mode = dwc2_op_mode(hsotg);
3368+
3369+
return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_HOST) ||
3370+
(op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST);
3371+
}
3372+
3373+
/* Returns true if the controller is device-only. */
3374+
bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg)
3375+
{
3376+
unsigned op_mode = dwc2_op_mode(hsotg);
3377+
3378+
return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
3379+
(op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE);
3380+
}
3381+
33453382
MODULE_DESCRIPTION("DESIGNWARE HS OTG Core");
33463383
MODULE_AUTHOR("Synopsys, Inc.");
33473384
MODULE_LICENSE("Dual BSD/GPL");

drivers/usb/dwc2/core.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,19 @@ extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
11371137
extern int dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg);
11381138
extern int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
11391139

1140+
/*
1141+
* The following functions check the controller's OTG operation mode
1142+
* capability (GHWCFG2.OTG_MODE).
1143+
*
1144+
* These functions can be used before the internal hsotg->hw_params
1145+
* are read in and cached so they always read directly from the
1146+
* GHWCFG2 register.
1147+
*/
1148+
unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg);
1149+
bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg);
1150+
bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg);
1151+
bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg);
1152+
11401153
/*
11411154
* Dump core registers and SPRAM
11421155
*/

0 commit comments

Comments
 (0)