Signed-off-by: Jules Maselbas <jmaselbas@xxxxxxxxx> --- drivers/usb/dwc2/core.c | 33 +++++++++++++++++++++++++++++++++ drivers/usb/dwc2/dwc2.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index c4a3cc789..f83788d51 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -1,6 +1,39 @@ // SPDX-License-Identifier: GPL-2.0+ #include "dwc2.h" +int dwc2_ulpi_read(struct dwc2 *dwc2, u8 addr) +{ + u32 gpvndctl; + int data; + + gpvndctl = GPVNDCTL_NEWREGREQ; + gpvndctl |= (addr << GPVNDCTL_REGADDR_SHIFT) & GPVNDCTL_REGADDR_MASK; + + dwc2_writel(dwc2, gpvndctl, GPVNDCTL); + + if (dwc2_wait_bit_set(dwc2, GPVNDCTL, GPVNDCTL_VSTSDONE, 10000)) + dwc2_err(dwc2, "Timeout: Waiting for phy read to complete\n"); + + gpvndctl = dwc2_readl(dwc2, GPVNDCTL); + data = (gpvndctl & GPVNDCTL_REGDATA_MASK) >> GPVNDCTL_REGDATA_SHIFT; + + return data; +} + +void dwc2_ulpi_write(struct dwc2 *dwc2, u32 addr, u32 data) +{ + u32 gpvndctl; + + gpvndctl = GPVNDCTL_NEWREGREQ | GPVNDCTL_REGWR; + gpvndctl |= (addr << GPVNDCTL_REGADDR_SHIFT) & GPVNDCTL_REGADDR_MASK; + gpvndctl |= (data << GPVNDCTL_REGDATA_SHIFT) & GPVNDCTL_REGDATA_MASK; + + dwc2_writel(dwc2, gpvndctl, GPVNDCTL); + + if (dwc2_wait_bit_set(dwc2, GPVNDCTL, GPVNDCTL_VSTSDONE, 10000)) + dwc2_err(dwc2, "Timeout: Waiting for phy write to complete\n"); +} + /* Returns the controller's GHWCFG2.OTG_MODE. */ static unsigned int dwc2_op_mode(struct dwc2 *dwc2) { diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h index 5e845f349..2475fd005 100644 --- a/drivers/usb/dwc2/dwc2.h +++ b/drivers/usb/dwc2/dwc2.h @@ -28,6 +28,9 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2); int dwc2_core_reset(struct dwc2 *dwc2); void dwc2_core_init(struct dwc2 *dwc2); +int dwc2_ulpi_read(struct dwc2 *dwc2, u8 addr); +void dwc2_ulpi_write(struct dwc2 *dwc2, u32 addr, u32 data); + /* Host functions */ #ifdef CONFIG_USB_DWC2_HOST int dwc2_submit_roothub(struct dwc2 *dwc2, struct usb_device *dev, -- 2.17.1 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox