Hi Stanley,
On 11/10/2023 11:15 AM, Stanley Chang wrote:
> In Realtek SoC, the parameter of usb phy is designed to can dynamic
> tuning base on port status. Therefore, add a notify callback of phy
> driver when usb connection/disconnection change.
>
> Signed-off-by: Stanley Chang <[email protected]>
> ---
> v1 to v2:
> No change
> v2 to v3:
> No change
> ---
> drivers/phy/phy-core.c | 47 +++++++++++++++++++++++++++++++++++++++++
> include/linux/phy/phy.h | 18 ++++++++++++++++
> 2 files changed, 65 insertions(+)
>
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index 96a0b1e111f3..a84ad4896b7f 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -489,6 +489,53 @@ int phy_calibrate(struct phy *phy)
> }
> EXPORT_SYMBOL_GPL(phy_calibrate);
>
> +/**
> + * phy_notify_connect() - phy connect notify
> + * @phy: the phy returned by phy_get()
> + * @port: the port index for connect
> + *
> + * If phy need the get connection status, the callback can be used.
> + * Returns: %0 if successful, a negative error code otherwise
> + */
> +int phy_notify_connect(struct phy *phy, int port)
> +{
> + int ret;
> +
> + if (!phy || !phy->ops->connect)
> + return 0;
> +
> + mutex_lock(&phy->mutex);
> + ret = phy->ops->connect(phy, port);
> + mutex_unlock(&phy->mutex);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(phy_notify_connect);
> +
> +/**
> + * phy_notify_disconnect() - phy disconnect notify
> + * @phy: the phy returned by phy_get()
> + * @port: the port index for disconnect
> + *
> + * If phy need the get disconnection status, the callback can be used.
> + *
> + * Returns: %0 if successful, a negative error code otherwise
> + */
> +int phy_notify_disconnect(struct phy *phy, int port)
> +{
> + int ret;
> +
> + if (!phy || !phy->ops->disconnect)
> + return 0;
> +
> + mutex_lock(&phy->mutex);
> + ret = phy->ops->disconnect(phy, port);
> + mutex_unlock(&phy->mutex);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(phy_notify_disconnect);
Please use EXTCON framework for notifying connect/disconnect.
Thanks,
Kishon
Hi Kishon,
> -----Original Message-----
> From: Kishon Vijay Abraham I <[email protected]>
> Sent: Tuesday, November 21, 2023 1:47 PM
> To: Stanley Chang[昌育德] <[email protected]>; Greg
> Kroah-Hartman <[email protected]>
> Cc: Vinod Koul <[email protected]>; Johan Hovold <[email protected]>; Kishon
> Vijay Abraham I <[email protected]>; Geert Uytterhoeven
> <[email protected]>; Jinjie Ruan <[email protected]>; Rob
> Herring <[email protected]>; Alan Stern <[email protected]>; Yang
> Yingliang <[email protected]>; Flavio Suligoi <[email protected]>;
> Roy Luo <[email protected]>; Heikki Krogerus
> <[email protected]>; Ricardo Cañuelo
> <[email protected]>; [email protected];
> [email protected]; [email protected]
> Subject: Re: [PATCH v3 1/4] phy: core: add notify_connect and
> notify_disconnect callback
>
>
> External mail.
>
>
>
> Hi Stanley,
>
> On 11/10/2023 11:15 AM, Stanley Chang wrote:
> > In Realtek SoC, the parameter of usb phy is designed to can dynamic
> > tuning base on port status. Therefore, add a notify callback of phy
> > driver when usb connection/disconnection change.
> >
> > Signed-off-by: Stanley Chang <[email protected]>
> > ---
> > v1 to v2:
> > No change
> > v2 to v3:
> > No change
> > ---
> > drivers/phy/phy-core.c | 47
> +++++++++++++++++++++++++++++++++++++++++
> > include/linux/phy/phy.h | 18 ++++++++++++++++
> > 2 files changed, 65 insertions(+)
> >
> > diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index
> > 96a0b1e111f3..a84ad4896b7f 100644
> > --- a/drivers/phy/phy-core.c
> > +++ b/drivers/phy/phy-core.c
> > @@ -489,6 +489,53 @@ int phy_calibrate(struct phy *phy)
> > }
> > EXPORT_SYMBOL_GPL(phy_calibrate);
> >
> > +/**
> > + * phy_notify_connect() - phy connect notify
> > + * @phy: the phy returned by phy_get()
> > + * @port: the port index for connect
> > + *
> > + * If phy need the get connection status, the callback can be used.
> > + * Returns: %0 if successful, a negative error code otherwise */ int
> > +phy_notify_connect(struct phy *phy, int port) {
> > + int ret;
> > +
> > + if (!phy || !phy->ops->connect)
> > + return 0;
> > +
> > + mutex_lock(&phy->mutex);
> > + ret = phy->ops->connect(phy, port);
> > + mutex_unlock(&phy->mutex);
> > +
> > + return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(phy_notify_connect);
> > +
> > +/**
> > + * phy_notify_disconnect() - phy disconnect notify
> > + * @phy: the phy returned by phy_get()
> > + * @port: the port index for disconnect
> > + *
> > + * If phy need the get disconnection status, the callback can be used.
> > + *
> > + * Returns: %0 if successful, a negative error code otherwise */ int
> > +phy_notify_disconnect(struct phy *phy, int port) {
> > + int ret;
> > +
> > + if (!phy || !phy->ops->disconnect)
> > + return 0;
> > +
> > + mutex_lock(&phy->mutex);
> > + ret = phy->ops->disconnect(phy, port);
> > + mutex_unlock(&phy->mutex);
> > +
> > + return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(phy_notify_disconnect);
>
> Please use EXTCON framework for notifying connect/disconnect.
Do you mean registering notifications via extcon_register_notifier?
But there is no extcon device provided in the USB framework to notify connect and disconnect.
Therefore, I added the notification connection/disconnection based on the generic phy.
[v3,4/4] usb: core: add phy notify connect and disconnect
https://patchwork.kernel.org/project/linux-usb/patch/[email protected]/
Thanks,
Stanley