From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: Xu Yang <xu.yang_2@nxp.com>
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, peter.chen@kernel.org,
linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
imx@lists.linux.dev, jun.li@nxp.com
Subject: Re: [PATCH v3 4/6] usb: chipidea: imx: add HSIO Block Control wakeup setting
Date: Fri, 28 Feb 2025 08:22:19 +0100 [thread overview]
Message-ID: <4411149.ejJDZkT8p0@steina-w> (raw)
In-Reply-To: <20250228023258.uznzhfnp7zsrxzed@hippo>
Hi,
Am Freitag, 28. Februar 2025, 03:33:29 CET schrieb Xu Yang:
> On Thu, Feb 27, 2025 at 04:12:54PM +0100, Alexander Stein wrote:
> > Hi,
> >
> > Am Donnerstag, 27. Februar 2025, 10:53:46 CET schrieb Xu Yang:
> > > 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 v3:
> > > - remove usbmisc_imx95_init(), use usbmisc_imx7d_init()
> > > Changes in v2:
> > > - add Rb tag
> > > ---
> > > drivers/usb/chipidea/usbmisc_imx.c | 72 ++++++++++++++++++++++++++++++
> > > 1 file changed, 72 insertions(+)
> > >
> > > diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
> > > index 1394881fde5f..8c30908c11ed 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,41 @@ 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);
> >
> > usbmisc->blkctl is NULL if DT does not provide a 2nd IORESOURCE_MEM.
>
> Good catch. Thanks!
>
> It may return an errno if usbmisc->blkctl is NULL.
>
> >
> > > +
> > > + return 0;
> > > +}
> > > +
> > > static const struct usbmisc_ops imx25_usbmisc_ops = {
> > > .init = usbmisc_imx25_init,
> > > .post = usbmisc_imx25_post,
> > > @@ -1068,6 +1120,14 @@ static const struct usbmisc_ops imx7ulp_usbmisc_ops = {
> > > .power_lost_check = usbmisc_imx7d_power_lost_check,
> > > };
> > >
> > > +static const struct usbmisc_ops imx95_usbmisc_ops = {
> > > + .init = usbmisc_imx7d_init,
> > > + .set_wakeup = usbmisc_imx95_set_wakeup,
> > > + .charger_detection = imx7d_charger_detection,
> > > + .power_lost_check = usbmisc_imx7d_power_lost_check,
> > > + .vbus_comparator_on = usbmisc_imx7d_vbus_comparator_on,
> > > +};
> > > +
> > > static inline bool is_imx53_usbmisc(struct imx_usbmisc_data *data)
> > > {
> > > struct imx_usbmisc *usbmisc = dev_get_drvdata(data->dev);
> > > @@ -1289,6 +1349,10 @@ static const struct of_device_id usbmisc_imx_dt_ids[] = {
> > > .compatible = "fsl,imx8ulp-usbmisc",
> > > .data = &imx7ulp_usbmisc_ops,
> > > },
> > > + {
> > > + .compatible = "fsl,imx95-usbmisc",
> > > + .data = &imx95_usbmisc_ops,
> > > + },
> > > { /* sentinel */ }
> > > };
> > > MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
> > > @@ -1296,6 +1360,7 @@ MODULE_DEVICE_TABLE(of, usbmisc_imx_dt_ids);
> > > static int usbmisc_imx_probe(struct platform_device *pdev)
> > > {
> > > struct imx_usbmisc *data;
> > > + struct resource *res;
> > >
> > > data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> > > if (!data)
> > > @@ -1307,6 +1372,13 @@ static int usbmisc_imx_probe(struct platform_device *pdev)
> > > if (IS_ERR(data->base))
> > > return PTR_ERR(data->base);
> > >
> > > + res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> > > + if (res) {
> > > + data->blkctl = devm_ioremap_resource(&pdev->dev, res);
> > > + if (IS_ERR(data->blkctl))
> > > + return PTR_ERR(data->blkctl);
> > > + }
> > > +
> >
> > Any chance to ensure imx95 has actually data->blkctl?
>
> I think let usbmisc_imx95_set_wakeup() return an error should be enough.
Better fail early rather than later.
> Some errors will be printed for user. Also dt-bindings has restriction for
> imx95.
That's true, but don't assume the DT is always setup correctly.
Best regards
Alexander
--
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
next prev parent reply other threads:[~2025-02-28 7:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-27 9:53 [PATCH v3 0/6] add USB2.0 support for i.MX95-19x19 EVK board Xu Yang
2025-02-27 9:53 ` [PATCH v3 1/6] dt-bindings: usb: chipidea: Add i.MX95 compatible string 'fsl,imx95-usb' Xu Yang
2025-02-27 9:53 ` [PATCH v3 2/6] dt-bindings: usb: usbmisc-imx: add support for i.MX95 platform Xu Yang
2025-02-27 9:53 ` [PATCH v3 3/6] usb: chipidea: imx: add wakeup interrupt handling Xu Yang
2025-02-27 9:53 ` [PATCH v3 4/6] usb: chipidea: imx: add HSIO Block Control wakeup setting Xu Yang
2025-02-27 15:12 ` Alexander Stein
2025-02-28 2:33 ` Xu Yang
2025-02-28 7:22 ` Alexander Stein [this message]
2025-02-28 9:16 ` Xu Yang
2025-02-28 10:41 ` Alexander Stein
2025-03-03 3:28 ` Xu Yang
2025-02-27 9:53 ` [PATCH v3 5/6] arm64: dts: imx95: add USB2.0 nodes Xu Yang
2025-02-27 15:15 ` Alexander Stein
2025-02-27 9:53 ` [PATCH v3 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=4411149.ejJDZkT8p0@steina-w \
--to=alexander.stein@ew.tq-group.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 \
--cc=xu.yang_2@nxp.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