usb: chipidea: udc: implement get_frame
authorMichael Grzeschik <m.grzeschik@pengutronix.de>
Thu, 16 Jun 2022 19:44:59 +0000 (21:44 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 21 Jun 2022 14:40:51 +0000 (16:40 +0200)
The chipidea udc core is capable of reading the current frame index from
hardware. This patch adds the get_frame callback to the driver.

Acked-by: Peter Chen <peter.chen@kernel.org>
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20220616194459.2981519-1-m.grzeschik@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/chipidea/ci.h
drivers/usb/chipidea/core.c
drivers/usb/chipidea/udc.c

index 99440ba..a4a3be0 100644 (file)
@@ -49,6 +49,7 @@ enum ci_hw_regs {
        OP_USBCMD,
        OP_USBSTS,
        OP_USBINTR,
+       OP_FRINDEX,
        OP_DEVICEADDR,
        OP_ENDPTLISTADDR,
        OP_TTCTRL,
index 5359b2a..6330fa9 100644 (file)
@@ -53,6 +53,7 @@ static const u8 ci_regs_nolpm[] = {
        [OP_USBCMD]             = 0x00U,
        [OP_USBSTS]             = 0x04U,
        [OP_USBINTR]            = 0x08U,
+       [OP_FRINDEX]            = 0x0CU,
        [OP_DEVICEADDR]         = 0x14U,
        [OP_ENDPTLISTADDR]      = 0x18U,
        [OP_TTCTRL]             = 0x1CU,
@@ -78,6 +79,7 @@ static const u8 ci_regs_lpm[] = {
        [OP_USBCMD]             = 0x00U,
        [OP_USBSTS]             = 0x04U,
        [OP_USBINTR]            = 0x08U,
+       [OP_FRINDEX]            = 0x0CU,
        [OP_DEVICEADDR]         = 0x14U,
        [OP_ENDPTLISTADDR]      = 0x18U,
        [OP_TTCTRL]             = 0x1CU,
index dc6c96e..0c9ae97 100644 (file)
@@ -1651,6 +1651,19 @@ static const struct usb_ep_ops usb_ep_ops = {
 /******************************************************************************
  * GADGET block
  *****************************************************************************/
+
+static int ci_udc_get_frame(struct usb_gadget *_gadget)
+{
+       struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
+       unsigned long flags;
+       int ret;
+
+       spin_lock_irqsave(&ci->lock, flags);
+       ret = hw_read(ci, OP_FRINDEX, 0x3fff);
+       spin_unlock_irqrestore(&ci->lock, flags);
+       return ret >> 3;
+}
+
 /*
  * ci_hdrc_gadget_connect: caller makes sure gadget driver is binded
  */
@@ -1807,6 +1820,7 @@ static struct usb_ep *ci_udc_match_ep(struct usb_gadget *gadget,
  * Check  "usb_gadget.h" for details
  */
 static const struct usb_gadget_ops usb_gadget_ops = {
+       .get_frame      = ci_udc_get_frame,
        .vbus_session   = ci_udc_vbus_session,
        .wakeup         = ci_udc_wakeup,
        .set_selfpowered        = ci_udc_selfpowered,