public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Xu Yang <xu.yang_2@nxp.com>
To: Peter Chen <peter.chen@kernel.org>
Cc: gregkh@linuxfoundation.org, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de,
	kernel@pengutronix.de, festevam@gmail.com,
	linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	imx@lists.linux.dev, jun.li@nxp.com
Subject: Re: [PATCH v2 3/6] usb: chipidea: imx: add HSIO Block Control wakeup setting
Date: Thu, 27 Feb 2025 14:32:35 +0800	[thread overview]
Message-ID: <20250227063235.kwfr4cixcleqbydf@hippo> (raw)
In-Reply-To: <Z7_Y3KIsyKBOqx3K@nchen-desktop>

On Thu, Feb 27, 2025 at 11:15:40AM +0800, Peter Chen wrote:
> On 25-02-25 13:39:52, Xu Yang wrote:
> > On i.MX95 platform, USB wakeup setting is controlled by HSIO Block
> > Control:
> > 
> > HSIO Block Control Overview:
> > - The HSIO block control include configuration and status registers that
> >   provide miscellaneous top-level controls for clocking, beat limiter
> >   enables, wakeup signal enables and interrupt status for the PCIe and USB
> >   interfaces.
> > 
> > The wakeup function of HSIO blkctl is basically same as non-core, except
> > improvements about power lost cases. This will add the wakeup setting for
> > HSIO blkctl on i.MX95. It will firstly ioremap hsio blkctl memory, then do
> > wakeup setting as needs.
> > 
> > Reviewed-by: Frank Li <Frank.Li@nxp.com>
> > Reviewed-by: Jun Li <jun.li@nxp.com>
> > Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> > 
> > ---
> > Changes in v2:
> >  - add Rb tag
> > ---
> >  drivers/usb/chipidea/usbmisc_imx.c | 107 +++++++++++++++++++++++++++++
> >  1 file changed, 107 insertions(+)
> > 
> > diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> > index 1394881fde5f..f933fc70be66 100644
> > --- a/drivers/usb/chipidea/usbmisc_imx.c
> > +++ b/drivers/usb/chipidea/usbmisc_imx.c
> > @@ -139,6 +139,22 @@
> >  #define MX6_USB_OTG_WAKEUP_BITS (MX6_BM_WAKEUP_ENABLE | MX6_BM_VBUS_WAKEUP | \
> >  				 MX6_BM_ID_WAKEUP | MX6SX_BM_DPDM_WAKEUP_EN)
> >  
> > +/*
> > + * HSIO Block Control Register
> > + */
> > +
> > +#define BLKCTL_USB_WAKEUP_CTRL		0x0
> > +#define BLKCTL_OTG_WAKE_ENABLE		BIT(31)
> > +#define BLKCTL_OTG_VBUS_SESSVALID	BIT(4)
> > +#define BLKCTL_OTG_ID_WAKEUP_EN		BIT(2)
> > +#define BLKCTL_OTG_VBUS_WAKEUP_EN	BIT(1)
> > +#define BLKCTL_OTG_DPDM_WAKEUP_EN	BIT(0)
> > +
> > +#define BLKCTL_WAKEUP_SOURCE		(BLKCTL_OTG_WAKE_ENABLE	   | \
> > +					 BLKCTL_OTG_ID_WAKEUP_EN   | \
> > +					 BLKCTL_OTG_VBUS_WAKEUP_EN | \
> > +					 BLKCTL_OTG_DPDM_WAKEUP_EN)
> > +
> >  struct usbmisc_ops {
> >  	/* It's called once when probe a usb device */
> >  	int (*init)(struct imx_usbmisc_data *data);
> > @@ -159,6 +175,7 @@ struct usbmisc_ops {
> >  
> >  struct imx_usbmisc {
> >  	void __iomem *base;
> > +	void __iomem *blkctl;
> >  	spinlock_t lock;
> >  	const struct usbmisc_ops *ops;
> >  };
> > @@ -1016,6 +1033,76 @@ static int usbmisc_imx6sx_power_lost_check(struct imx_usbmisc_data *data)
> >  		return 0;
> >  }
> >  
> > +static u32 usbmisc_blkctl_wakeup_setting(struct imx_usbmisc_data *data)
> > +{
> > +	u32 wakeup_setting = BLKCTL_WAKEUP_SOURCE;
> > +
> > +	if (data->ext_id || data->available_role != USB_DR_MODE_OTG)
> > +		wakeup_setting &= ~BLKCTL_OTG_ID_WAKEUP_EN;
> > +
> > +	if (data->ext_vbus || data->available_role == USB_DR_MODE_HOST)
> > +		wakeup_setting &= ~BLKCTL_OTG_VBUS_WAKEUP_EN;
> > +
> > +	/* Select session valid as VBUS wakeup source */
> > +	wakeup_setting |= BLKCTL_OTG_VBUS_SESSVALID;
> > +
> > +	return wakeup_setting;
> > +}
> > +
> > +static int usbmisc_imx95_set_wakeup(struct imx_usbmisc_data *data, bool enabled)
> > +{
> > +	struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
> > +	unsigned long flags;
> > +	u32 val;
> > +
> > +	spin_lock_irqsave(&usbmisc->lock, flags);
> > +	val = readl(usbmisc->blkctl + BLKCTL_USB_WAKEUP_CTRL);
> > +	val &= ~BLKCTL_WAKEUP_SOURCE;
> > +
> > +	if (enabled)
> > +		val |= usbmisc_blkctl_wakeup_setting(data);
> > +
> > +	writel(val, usbmisc->blkctl + BLKCTL_USB_WAKEUP_CTRL);
> > +	spin_unlock_irqrestore(&usbmisc->lock, flags);
> > +
> > +	return 0;
> > +}
> > +
> > +static int usbmisc_imx95_init(struct imx_usbmisc_data *data)
> > +{
> > +	struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
> > +	unsigned long flags;
> > +	u32 reg;
> > +
> > +	if (data->index >= 1)
> > +		return -EINVAL;
> > +
> > +	spin_lock_irqsave(&usbmisc->lock, flags);
> > +	reg = readl(usbmisc->base);
> > +
> > +	if (data->disable_oc) {
> > +		reg |= MX6_BM_OVER_CUR_DIS;
> > +	} else {
> > +		reg &= ~MX6_BM_OVER_CUR_DIS;
> > +
> > +		if (data->oc_pol_configured && data->oc_pol_active_low)
> > +			reg |= MX6_BM_OVER_CUR_POLARITY;
> > +		else if (data->oc_pol_configured)
> > +			reg &= ~MX6_BM_OVER_CUR_POLARITY;
> > +	}
> > +
> > +	if (data->pwr_pol == 1)
> > +		reg |= MX6_BM_PWR_POLARITY;
> > +
> > +	writel(reg, usbmisc->base);
> > +	spin_unlock_irqrestore(&usbmisc->lock, flags);
> > +
> > +	/* use HSIO blkctl wakeup as source, disable usbmisc setting*/
> > +	usbmisc_imx7d_set_wakeup(data, false);
> > +
> > +	return 0;
> > +}
> 
> Above code has duplicated with some imx7d and imx7ulp init code,
> Is it possible abstract some common code for all these three platforms?

Sure. Thanks for your suggestion. I'll do it.

Thanks,
Xu Yang

  reply	other threads:[~2025-02-27  6:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25  5:39 [PATCH v2 0/6] add USB2.0 support for i.MX95-19x19 EVK board Xu Yang
2025-02-25  5:39 ` [PATCH v2 1/6] dt-bindings: usb: chipidea: Add i.MX95 compatible string 'fsl,imx95-usb' Xu Yang
2025-02-25 15:54   ` Rob Herring (Arm)
2025-02-25  5:39 ` [PATCH v2 2/6] dt-bindings: usb: usbmisc-imx: add support for i.MX95 platform Xu Yang
2025-02-25 15:54   ` Rob Herring (Arm)
2025-02-25  5:39 ` [PATCH v2 3/6] usb: chipidea: imx: add HSIO Block Control wakeup setting Xu Yang
2025-02-27  3:15   ` Peter Chen
2025-02-27  6:32     ` Xu Yang [this message]
2025-02-27  9:41       ` Xu Yang
2025-02-25  5:39 ` [PATCH v2 4/6] usb: chipidea: imx: add wakeup interrupt handling Xu Yang
2025-02-26  7:16   ` kernel test robot
2025-02-27  3:25   ` Peter Chen
2025-02-27  6:34     ` Xu Yang
2025-02-25  5:39 ` [PATCH v2 5/6] arm64: dts: imx95: add USB2.0 nodes Xu Yang
2025-02-25  5:39 ` [PATCH v2 6/6] arm64: dts: imx95-19x19-evk: enable USB2.0 node Xu Yang

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=20250227063235.kwfr4cixcleqbydf@hippo \
    --to=xu.yang_2@nxp.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=jun.li@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.chen@kernel.org \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@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