linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Hancock <robert.hancock@calian.com>
To: "Thinh.Nguyen@synopsys.com" <Thinh.Nguyen@synopsys.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Cc: "manish.narani@xilinx.com" <manish.narani@xilinx.com>,
	"mounika.grace.akula@xilinx.com" <mounika.grace.akula@xilinx.com>,
	"michal.simek@xilinx.com" <michal.simek@xilinx.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"balbi@kernel.org" <balbi@kernel.org>
Subject: Re: [PATCH 3/4] usb: dwc3: add reference clock FLADJ configuration
Date: Mon, 10 Jan 2022 19:33:27 +0000	[thread overview]
Message-ID: <cfe7deae90b464ba527d4039fdfa7675edf3b769.camel@calian.com> (raw)
In-Reply-To: <2a420d1e-12c9-64c3-2b67-6b08014e4b56@synopsys.com>

On Sat, 2022-01-08 at 00:17 +0000, Thinh Nguyen wrote:
> Robert Hancock wrote:
> > Previously a device tree property was added to allow overriding the
> > reference clock period parameter if the default value used was incorrect.
> > However, there is another register field, GFLADJ_REFCLK_FLADJ, which
> > reflects the fractional nanosecond portion of the reference clock
> > period. Add a snps,ref-clock-fladj property to allow configuring this
> > as well.
> > 
> > On the Xilinx ZynqMP platform, the reference clock appears to always
> > be 20 MHz, giving a clock period of 50 ns. However, the default value
> > of GFLADJ_REFCLK_FLADJ was 1008 rather than 0 as it should have been,
> > which prevented many USB devices from functioning properly. The
> > psu_init code run by the Xilinx first-stage boot loader sets this
> > value to 0, however when the controller is reset by the dwc3-xilinx
> > layer, the incorrect default value is restored. This configuration
> > property allows ensuring that the correct value is always used.
> > 
> > Signed-off-by: Robert Hancock <robert.hancock@calian.com>
> > ---
> >  drivers/usb/dwc3/core.c | 32 ++++++++++++++++++++++++++++++++
> >  drivers/usb/dwc3/core.h |  3 +++
> >  2 files changed, 35 insertions(+)
> > 
> > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > index f4c09951b517..6289fbcbad45 100644
> > --- a/drivers/usb/dwc3/core.c
> > +++ b/drivers/usb/dwc3/core.c
> > @@ -359,6 +359,34 @@ static void dwc3_ref_clk_period(struct dwc3 *dwc)
> >  }
> >  
> >  
> > +/*
> 
> Use kernel doc style "/**"

Will update in v2.

> 
> > + * dwc3_ref_clk_fladj - Reference clock period (fractional portion)
> > configuration
> > + * GFLADJ_REFCLK_FLADJ contains the fractional portion of the reference
> > clock
> > + * period set in GUCTL_REFCLKPER.
> 
> It's not a direct "fractional portion" the way it's described here. It
> may cause some confusion. Let's use the word adjustment to account for
> the fractional portion that's calculated as below.
> 
> > + * Calculated as: ((125000/ref_clk_period_integer)-
> > (125000/ref_clk_period)) * ref_clk_period
> 
> Note that ref_clk_period_integer is the value in GUCTL.REFCLKPER, and
> the "ref_clk_period" is the period with fractional value.

Rewording this for v2.

> 
> > + * This value can be specified in the device tree if the default value is
> > incorrect.
> > + * Note that 0 is a valid value.
> > + *
> > + * @dwc3: Pointer to our controller context structure
> > + */
> > +static void dwc3_ref_clk_fladj(struct dwc3 *dwc)
> > +{
> > +	u32 reg, reg_new;
> 
> I believe Felipe prefers to declare them in separate lines. Let's keep
> it consistent as how we do it in for this driver.

Will do.

> 
> > +
> > +	if (DWC3_VER_IS_PRIOR(DWC3, 250A))
> > +		return;
> > +
> > +	if (!dwc->ref_clk_fladj_set)
> > +		return;
> > +
> > +	reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
> > +	reg_new = reg & ~DWC3_GFLADJ_REFCLK_FLADJ_MASK;
> > +	reg_new |= FIELD_PREP(DWC3_GFLADJ_REFCLK_FLADJ_MASK, dwc-
> > >ref_clk_fladj);
> > +	if (reg_new != reg)
> > +		dwc3_writel(dwc->regs, DWC3_GFLADJ, reg_new);
> > +}
> > +
> > +
> >  /**
> >   * dwc3_free_one_event_buffer - Frees one event buffer
> >   * @dwc: Pointer to our controller context structure
> > @@ -1033,6 +1061,7 @@ static int dwc3_core_init(struct dwc3 *dwc)
> >  
> >  	/* Adjust Reference Clock Period */
> >  	dwc3_ref_clk_period(dwc);
> > +	dwc3_ref_clk_fladj(dwc);
> >  
> >  	dwc3_set_incr_burst_type(dwc);
> >  
> > @@ -1418,6 +1447,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)
> >  				 &dwc->fladj);
> >  	device_property_read_u32(dev, "snps,ref-clock-period-ns",
> >  				 &dwc->ref_clk_per);
> > +	if (!device_property_read_u32(dev, "snps,ref-clock-fladj",
> > +				      &dwc->ref_clk_fladj))
> > +		dwc->ref_clk_fladj_set = true;
> 
> Please document it in the dwc3 DT file whenever we introduce a new property.

Whoops, forgot that. Will add as a separate patch in v2.

> 
> Also, do we need to add a new dwc->ref_clk_fladj_set? Can we just define
> some default value for dwc->ref_clk_fladj as unspecified and have the
> driver check against that (e.g. #define DWC3_REFCLK_FLADJ_UNSPECIFIED
> 0xffffffff).

I figured this was the most explicit/cleanest way to do it that would work with
the default zero initialization of the structure. Most of these other settings
seem to use 0 as the "don't change anything" value but in this case we do
sometimes need to override the value with 0.

> 
> Thanks,
> Thinh
> 
> >  
> >  	dwc->dis_metastability_quirk = device_property_read_bool(dev,
> >  				"snps,dis_metastability_quirk");
> > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> > index e1cc3f7398fb..650d4c2e7a67 100644
> > --- a/drivers/usb/dwc3/core.h
> > +++ b/drivers/usb/dwc3/core.h
> > @@ -388,6 +388,7 @@
> >  /* Global Frame Length Adjustment Register */
> >  #define DWC3_GFLADJ_30MHZ_SDBND_SEL		BIT(7)
> >  #define DWC3_GFLADJ_30MHZ_MASK			0x3f
> > +#define DWC3_GFLADJ_REFCLK_FLADJ_MASK		0x3fff00
> >  
> >  /* Global User Control Register*/
> >  #define DWC3_GUCTL_REFCLKPER_MASK		0xffc00000
> > @@ -1166,6 +1167,8 @@ struct dwc3 {
> >  
> >  	u32			fladj;
> >  	u32			ref_clk_per;
> > +	bool			ref_clk_fladj_set;
> > +	u32			ref_clk_fladj;
> >  	u32			irq_gadget;
> >  	u32			otg_irq;
> >  	u32			current_otg_role;

  reply	other threads:[~2022-01-10 19:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07  0:13 [PATCH 0/4] Xilinx ZynqMP USB fixes Robert Hancock
2022-01-07  0:13 ` [PATCH 1/4] usb: dwc3: xilinx: Fix PIPE clock selection for USB2.0 mode Robert Hancock
2022-01-07  0:13 ` [PATCH 2/4] usb: dwc3: xilinx: Fix error handling when getting USB3 PHY Robert Hancock
2022-01-07  0:13 ` [PATCH 3/4] usb: dwc3: add reference clock FLADJ configuration Robert Hancock
2022-01-08  0:17   ` Thinh Nguyen
2022-01-10 19:33     ` Robert Hancock [this message]
2022-01-07  0:13 ` [PATCH 4/4] arm64: dts: zynqmp: Add DWC3 USB reference clock period configuration Robert Hancock

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=cfe7deae90b464ba527d4039fdfa7675edf3b769.camel@calian.com \
    --to=robert.hancock@calian.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=manish.narani@xilinx.com \
    --cc=michal.simek@xilinx.com \
    --cc=mounika.grace.akula@xilinx.com \
    /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).