linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amelie Delaunay <amelie.delaunay@st.com>
To: John Youn <johnyoun@synopsys.com>,
	Felipe Balbi <balbi@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Amelie Delaunay" <amelie.delaunay@st.com>
Subject: [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes
Date: Mon, 27 Nov 2017 15:41:31 +0100	[thread overview]
Message-ID: <1511793691-6325-1-git-send-email-amelie.delaunay@st.com> (raw)

In case of OTG mode, with an OTG adapter plugged, the
dwc2_check_param_tx_fifo_sizes function reads DPTXFSIZN registers while
the controller is in Host mode, and, because DPTXFSIZN registers are
Device specific registers, the values read are 0.
Then, g_tx_fifo_size[fifo] values are considered invalid because in the
comparison test, they need to be greater than min and lower than dptxfszn
which is 0.
To fix this issue, force the controller in device mode if needed before
reading the DPTXFSIZN registers, and restore the previous mode if needed
after reading.

Fixes: 3c6aea7344c3 ("usb: dwc2: gadget: Add checking for g-tx-fifo-size
parameter")
Signed-off-by: Amelie Delaunay <amelie.delaunay@st.com>
---
 drivers/usb/dwc2/params.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index ef73af6..302fefb 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -469,6 +469,7 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
 	int fifo;
 	int min;
 	u32 total = 0;
+	bool forced;
 	u32 dptxfszn;
 
 	fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
@@ -483,6 +484,12 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
 		dwc2_set_param_tx_fifo_sizes(hsotg);
 	}
 
+	/*
+	 * Reading DPTXFSIZN registers requires the controller to be in device
+	 * mode. The mode will be forced, if necessary, to read these values.
+	 */
+	forced = dwc2_force_mode_if_needed(hsotg, false);
+
 	for (fifo = 1; fifo <= fifo_count; fifo++) {
 		dptxfszn = (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) &
 			FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
@@ -495,6 +502,9 @@ static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
 			hsotg->params.g_tx_fifo_size[fifo] = dptxfszn;
 		}
 	}
+
+	if (forced)
+		dwc2_clear_force_mode(hsotg);
 }
 
 #define CHECK_RANGE(_param, _min, _max, _def) do {			\
-- 
2.7.4

             reply	other threads:[~2017-11-27 14:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27 14:41 Amelie Delaunay [this message]
2017-11-30  9:43 ` [PATCH] usb: dwc2: gadget: fix dwc2_check_param_tx_fifo_sizes Minas Harutyunyan
2017-11-30 13:12   ` Amelie DELAUNAY

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=1511793691-6325-1-git-send-email-amelie.delaunay@st.com \
    --to=amelie.delaunay@st.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johnyoun@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).