phy: core: add notify_connect and notify_disconnect callback
Subsystems (2)
PATCH RESEND v3 1/4 phy: core: add notify_connect and notify_disconnect callback
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.
---
RESEND:
Because 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. So I no use the EXTCON framework for notifying connect/disconnect.
v2 to v3:
No change
v1 to v2:
No change
--- drivers/phy/phy-core.c | 47 +++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 18 ++++++++++++++++ 2 files changed, 65 insertions(+)
drivers/phy/phy-core.c +47 -0
@@ -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); +/** * phy_configure() - Changes the phy parameters * @phy: the phy returned by phy_get()
include/linux/phy/phy.h +18 -0
@@ -122,6 +122,8 @@ struct phy_ops { union phy_configure_opts *opts);int (*reset)(struct phy *phy);int (*calibrate)(struct phy *phy); +int (*connect)(struct phy *phy,int port); +int (*disconnect)(struct phy *phy,int port);void (*release)(struct phy *phy);struct module *owner; };
@@ -243,6 +245,8 @@ static inline enum phy_mode phy_get_mode(struct phy *phy) }int phy_reset (struct phy *phy);int phy_calibrate (struct phy *phy); +int phy_notify_connect (struct phy *phy,int port); +int phy_notify_disconnect (struct phy *phy,int port);static inline int phy_get_bus_width (struct phy *phy) {return phy->attrs.bus_width;
@@ -396,6 +400,20 @@ static inline int phy_calibrate(struct phy *phy)return -ENOSYS ; } +static inline int phy_notify_connect (struct phy *phy,int index) +{ +if (!phy) +return 0 ; +return -ENOSYS ; +} + +static inline int phy_notify_disconnect (struct phy *phy,int index) +{ +if (!phy) +return 0 ; +return -ENOSYS ; +} +static inline int phy_configure (struct phy *phy,union phy_configure_opts *opts) {
Signature · 1 line
2.34.1
PATCH RESEND v3 2/4 phy: realtek: usb: add new driver for the Realtek RTD SoC USB 2.0 PHY
Realtek DHC (digital home center) RTD SoCs support DWC3 XHCI USB controller. Added the driver to drive the USB 2.0 PHY transceivers.
Note: New driver,remove the port status notification on legacy USB PHY. Use the generic PHY to notify the usb device connect and disconnect. To avoid using these PHYs would require describing the very same PHY using both the generic "phy" property and the deprecated "usb-phy" property.
---
v2 to v3 change:
remove MODULE_ALIAS
v1 to v2 change:
rebase the driver to include the revert part on 7a784bcdd7e54f0599da3b2360e472238412623e
--- drivers/phy/Kconfig | 1 + drivers/phy/Makefile | 1 + drivers/phy/realtek/Kconfig | 20 + drivers/phy/realtek/Makefile | 2 + drivers/phy/realtek/phy-rtk-usb2.c | 1312 ++++++++++++++++++++++++++++ 5 files changed, 1336 insertions(+) create mode 100644 drivers/phy/realtek/Kconfig create mode 100644 drivers/phy/realtek/Makefile create mode 100644 drivers/phy/realtek/phy-rtk-usb2.c
drivers/phy/Kconfig +1 -0
@@ -87,6 +87,7 @@ source "drivers/phy/motorola/Kconfig" source "drivers/phy/mscc/Kconfig" source "drivers/phy/qualcomm/Kconfig" source "drivers/phy/ralink/Kconfig" +source "drivers/phy/realtek/Kconfig" source "drivers/phy/renesas/Kconfig" source "drivers/phy/rockchip/Kconfig" source "drivers/phy/samsung/Kconfig"
drivers/phy/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-y += allwinner/ \ mscc/ \ qualcomm/ \ ralink/ \ + realtek/ \ renesas/ \ rockchip/ \ samsung/ \
drivers/phy/realtek/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Phy drivers for Realtek platforms +# + +if ARCH_REALTEK || COMPILE_TEST + +config PHY_RTK_RTD_USB2PHY + tristate "Realtek RTD USB2 PHY Transceiver Driver" + depends on USB_SUPPORT + select GENERIC_PHY + select USB_PHY + select USB_COMMON + help + Enable this to support Realtek SoC USB2 phy transceiver. + The DHC (digital home center) RTD series SoCs used the Synopsys + DWC3 USB IP. This driver will do the PHY initialization + of the parameters. + +endif # ARCH_REALTEK || COMPILE_TEST
drivers/phy/realtek/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_PHY_RTK_RTD_USB2PHY) += phy-rtk-usb2.o
drivers/phy/realtek/phy-rtk-usb2.c new file +1312 -0
1,312 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH RESEND v3 3/4 phy: realtek: usb: add new driver for the Realtek RTD SoC USB 3.0 PHY
In reply to Stanley ChangRealtek DHC (digital home center) RTD SoCs support DWC3 XHCI USB controller. Added the driver to drive the USB 3.0 PHY transceivers.
Note: New driver, remove the port status notification on legacy USB PHY. Use the generic PHY to notify the usb device connect and disconnect. To avoid using these PHYs would require describing the very same PHY using both the generic "phy" property and the deprecated "usb-phy" property.
---
v2 to v3 change:
remove MODULE_ALIAS
v1 to v2 change:
rebase the driver to include the revert part on 258ea41c926b7b3a16d0d7aa210a1401c4a1601b
--- drivers/phy/realtek/Kconfig | 12 + drivers/phy/realtek/Makefile | 1 + drivers/phy/realtek/phy-rtk-usb3.c | 748 +++++++++++++++++++++++++++++ 3 files changed, 761 insertions(+) create mode 100644 drivers/phy/realtek/phy-rtk-usb3.c
drivers/phy/realtek/Kconfig +12 -0
@@ -17,4 +17,16 @@ config PHY_RTK_RTD_USB2PHY DWC3 USB IP. This driver will do the PHY initialization of the parameters. +config PHY_RTK_RTD_USB3PHY + tristate "Realtek RTD USB3 PHY Transceiver Driver" + depends on USB_SUPPORT + select GENERIC_PHY + select USB_PHY + select USB_COMMON + help + Enable this to support Realtek SoC USB3 phy transceiver. + The DHC (digital home center) RTD series SoCs used the Synopsys + DWC3 USB IP. This driver will do the PHY initialization + of the parameters. + endif # ARCH_REALTEK || COMPILE_TEST
drivers/phy/realtek/Makefile +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_PHY_RTK_RTD_USB2PHY) += phy-rtk-usb2.o +obj-$(CONFIG_PHY_RTK_RTD_USB3PHY) += phy-rtk-usb3.o
drivers/phy/realtek/phy-rtk-usb3.c new file +748 -0
748 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH RESEND v3 4/4 usb: core: add phy notify connect and disconnect
In reply to Stanley ChangIn Realtek SoC, the parameter of usb phy is designed to can dynamic tuning base on port status. Therefore, add a notify callback of generic phy driver when usb device connect and disconnect change.
The Realtek phy driver is designed to dynamically adjust disconnection level and calibrate phy parameters. When the device connected bit changes and when the disconnected bit changes, do connection change notification:
Check if portstatus is USB_PORT_STAT_CONNECTION and portchange is USB_PORT_STAT_C_CONNECTION.
1. The device is connected, the driver lowers the disconnection level and calibrates the phy parameters.
2. The device disconnects, the driver increases the disconnect level and calibrates the phy parameters.
Generic phy driver in usb core framework does not support device connect and disconnect notifications. Therefore, we add an api to notify phy the connection changes.
Additionally, the generic phy only specifies primary_hcd in the original design. Added specific "usb2-phy" on primary_hcd and "usb3-phy" on shared_hcd.
---
v2 to v3:
No change
v1 to v2 change:
rebase the driver to remove the part of usb phy notify API
--- drivers/usb/core/hcd.c | 14 +++++-- drivers/usb/core/hub.c | 29 +++++++++++++ drivers/usb/core/phy.c | 94 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/core/phy.h | 3 ++ 4 files changed, 136 insertions(+), 4 deletions(-)
drivers/usb/core/hcd.c +10 -4
@@ -2794,10 +2794,16 @@ int usb_add_hcd(struct usb_hcd *hcd,struct usb_device *rhdev;struct usb_hcd *shared_hcd; -if (!hcd->skip_phy_initialization &&usb_hcd_is_primary_hcd (hcd)) { - hcd->phy_roothub =usb_phy_roothub_alloc (hcd->self.sysdev); -if (IS_ERR (hcd->phy_roothub)) -return PTR_ERR (hcd->phy_roothub); +if (!hcd->skip_phy_initialization) { +if (usb_hcd_is_primary_hcd (hcd)) { + hcd->phy_roothub =usb_phy_roothub_alloc (hcd->self.sysdev); +if (IS_ERR (hcd->phy_roothub)) +return PTR_ERR (hcd->phy_roothub); + }else { + hcd->phy_roothub =usb_phy_roothub_alloc_usb3_phy (hcd->self.sysdev); +if (IS_ERR (hcd->phy_roothub)) +return PTR_ERR (hcd->phy_roothub); + } retval =usb_phy_roothub_init (hcd->phy_roothub);if (retval)
drivers/usb/core/hub.c +29 -0
@@ -37,6 +37,7 @@#include <asm/byteorder.h> #include "hub.h" +#include "phy.h" #include "otg_productlist.h" #define USB_VENDOR_GENESYS_LOGIC 0x05e3
@@ -622,6 +623,34 @@ static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, ret =0 ; }mutex_unlock (&hub->status_mutex); + +/* +* There is no need to lock status_mutex here, because status_mutex +* protects hub->status, and the phy driver only checks the port +* status without changing the status. +*/ +if (!ret) { +struct usb_device *hdev = hub->hdev; + +/* +* Only roothub will be notified of connection changes, +* since the USB PHY only cares about changes at the next +* level. +*/ +if (is_root_hub (hdev)) { +struct usb_hcd *hcd =bus_to_hcd (hdev->bus); +bool connect; +bool connect_change; + + connect_change = *change &USB_PORT_STAT_C_CONNECTION ; + connect = *status &USB_PORT_STAT_CONNECTION ; +if (connect_change && connect) +usb_phy_roothub_notify_connect (hcd->phy_roothub, port1 -1 ); +else if (connect_change) +usb_phy_roothub_notify_disconnect (hcd->phy_roothub, port1 -1 ); + } + } +return ret; }
drivers/usb/core/phy.c +94 -0
118 lines not on this page · raw message
drivers/usb/core/phy.h +3 -0
@@ -12,6 +12,7 @@ struct device;struct usb_phy_roothub ;struct usb_phy_roothub *usb_phy_roothub_alloc (struct device *dev); +struct usb_phy_roothub *usb_phy_roothub_alloc_usb3_phy (struct device *dev);int usb_phy_roothub_init (struct usb_phy_roothub *phy_roothub);int usb_phy_roothub_exit (struct usb_phy_roothub *phy_roothub);
@@ -19,6 +20,8 @@ int usb_phy_roothub_exit(struct usb_phy_roothub *phy_roothub);int usb_phy_roothub_set_mode (struct usb_phy_roothub *phy_roothub,enum phy_mode mode);int usb_phy_roothub_calibrate (struct usb_phy_roothub *phy_roothub); +int usb_phy_roothub_notify_connect (struct usb_phy_roothub *phy_roothub,int port); +int usb_phy_roothub_notify_disconnect (struct usb_phy_roothub *phy_roothub,int port);int usb_phy_roothub_power_on (struct usb_phy_roothub *phy_roothub);void usb_phy_roothub_power_off (struct usb_phy_roothub *phy_roothub);
Signature · 1 line
2.34.1
Greg Kroah-Hartman
maintainerRe: [PATCH v3 RESEND 4/4] usb: core: add phy notify connect and disconnect
Quoted 187 lines · Stanley Chang
In Realtek SoC, the parameter of usb phy is designed to can dynamic tuning base on port status. Therefore, add a notify callback of generic phy driver when usb device connect and disconnect change.
The Realtek phy driver is designed to dynamically adjust disconnection level and calibrate phy parameters. When the device connected bit changes and when the disconnected bit changes, do connection change notification:
Check if portstatus is
USB_PORT_STAT_CONNECTIONand portchange isUSB_PORT_STAT_C_CONNECTION.
1. The device is connected, the driver lowers the disconnection level and calibrates the phy parameters.
2. The device disconnects, the driver increases the disconnect level and calibrates the phy parameters.Generic phy driver in usb core framework does not support device connect and disconnect notifications. Therefore, we add an api to notify phy the connection changes.
Additionally, the generic phy only specifies
primary_hcdin the original design. Added specific "usb2-phy" onprimary_hcdand "usb3-phy" onshared_hcd.Signed-off-by Stanley Chang <[email protected]>---
v2 to v3:
No change
v1 to v2 change:
rebase the driver to remove the part of usb phy notify API--- drivers/usb/core/hcd.c | 14 +++++-- drivers/usb/core/hub.c | 29 +++++++++++++ drivers/usb/core/phy.c | 94 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/core/phy.h | 3 ++ 4 files changed, 136 insertions(+), 4 deletions(-)drivers/usb/core/hcd.c +10
-4@@ -2794,10 +2794,16 @@ int usb_add_hcd(struct usb_hcd *hcd,struct usb_device *rhdev;struct usb_hcd *shared_hcd; -if (!hcd->skip_phy_initialization &&usb_hcd_is_primary_hcd (hcd)) { - hcd->phy_roothub =usb_phy_roothub_alloc (hcd->self.sysdev); -if (IS_ERR (hcd->phy_roothub)) -return PTR_ERR (hcd->phy_roothub); +if (!hcd->skip_phy_initialization) { +if (usb_hcd_is_primary_hcd (hcd)) { + hcd->phy_roothub =usb_phy_roothub_alloc (hcd->self.sysdev); +if (IS_ERR (hcd->phy_roothub)) +return PTR_ERR (hcd->phy_roothub); + }else { + hcd->phy_roothub =usb_phy_roothub_alloc_usb3_phy (hcd->self.sysdev); +if (IS_ERR (hcd->phy_roothub)) +return PTR_ERR (hcd->phy_roothub); + } retval =usb_phy_roothub_init (hcd->phy_roothub);if (retval)drivers/usb/core/hub.c +29
-0@@ -37,6 +37,7 @@#include <asm/byteorder.h> #include "hub.h" +#include "phy.h" #include "otg_productlist.h" #define USB_VENDOR_GENESYS_LOGIC 0x05e3@@ -622,6 +623,34 @@ static int hub_ext_port_status(struct usb_hub *hub, int port1, int type, ret =0 ; }mutex_unlock (&hub->status_mutex); + +/* +* There is no need to lock status_mutex here, because status_mutex +* protects hub->status, and the phy driver only checks the port +* status without changing the status. +*/ +if (!ret) { +struct usb_device *hdev = hub->hdev; + +/* +* Only roothub will be notified of connection changes, +* since the USB PHY only cares about changes at the next +* level. +*/ +if (is_root_hub (hdev)) { +struct usb_hcd *hcd =bus_to_hcd (hdev->bus); +bool connect; +bool connect_change; + + connect_change = *change &USB_PORT_STAT_C_CONNECTION ; + connect = *status &USB_PORT_STAT_CONNECTION ; +if (connect_change && connect) +usb_phy_roothub_notify_connect (hcd->phy_roothub, port1 -1 ); +else if (connect_change) +usb_phy_roothub_notify_disconnect (hcd->phy_roothub, port1 -1 ); + } + } +return ret; }drivers/usb/core/phy.c +52
-0@@ -19,6 +19,29 @@ struct usb_phy_roothub {struct list_head list; }; +static int usb_phy_roothub_add_phy_by_name (struct device *dev,const char *name, +struct list_head *list) +{ +struct usb_phy_roothub *roothub_entry; +struct phy *phy; + + phy =devm_of_phy_get (dev, dev->of_node, name); +if (IS_ERR (phy)) +return PTR_ERR (phy); + + roothub_entry =devm_kzalloc (dev,sizeof (*roothub_entry),GFP_KERNEL ); +if (!roothub_entry) +return -ENOMEM ; + +INIT_LIST_HEAD (&roothub_entry->list); + + roothub_entry->phy = phy; + +list_add_tail (&roothub_entry->list, list); + +return 0 ; +} +static int usb_phy_roothub_add_phy (struct device *dev,int index,struct list_head *list) {@@ -65,6 +88,9 @@ struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)INIT_LIST_HEAD (&phy_roothub->list); +if (!usb_phy_roothub_add_phy_by_name (dev,"usb2-phy" , &phy_roothub->list)) +return phy_roothub; +for (i =0 ; i < num_phys; i++) { err =usb_phy_roothub_add_phy (dev, i, &phy_roothub->list);if (err)@@ -75,6 +101,32 @@ struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev) }EXPORT_SYMBOL_GPL (usb_phy_roothub_alloc); +struct usb_phy_roothub *usb_phy_roothub_alloc_usb3_phy (struct device *dev) +{ +struct usb_phy_roothub *phy_roothub; +int num_phys; + +if (!IS_ENABLED (CONFIG_GENERIC_PHY )) +return NULL ; + + num_phys =of_count_phandle_with_args (dev->of_node,"phys" , +"#phy-cells" ); +if (num_phys <=0 ) +return NULL ; + + phy_roothub =devm_kzalloc (dev,sizeof (*phy_roothub),GFP_KERNEL ); +if (!phy_roothub) +return ERR_PTR (-ENOMEM ); + +INIT_LIST_HEAD (&phy_roothub->list); + +if (!usb_phy_roothub_add_phy_by_name (dev,"usb3-phy" , &phy_roothub->list)) +return phy_roothub; + +return NULL ; +} +EXPORT_SYMBOL_GPL (usb_phy_roothub_alloc_usb3_phy); +int usb_phy_roothub_init (struct usb_phy_roothub *phy_roothub) {struct usb_phy_roothub *roothub_entry;@@ -172,6 +224,48 @@ int usb_phy_roothub_calibrate(struct usb_phy_roothub *phy_roothub) }
drivers/usb/core/phy.c int usb_phy_roothub_calibrate(struct usb_phy_roothub *phy_roothub) · line 234
Quoted 10 lines
drivers/usb/core/phy.c +8
-0EXPORT_SYMBOL_GPL (usb_phy_roothub_calibrate); +int usb_phy_roothub_notify_connect (struct usb_phy_roothub *phy_roothub,int port) +{ +struct usb_phy_roothub *roothub_entry; +struct list_head *head; +int err; + +if (!phy_roothub) +return 0 ;
How can phy_roothub ever be NULL?
drivers/usb/core/phy.c int usb_phy_roothub_calibrate(struct usb_phy_roothub *phy_roothub)
Quoted 9 lines
drivers/usb/core/phy.c +8
-0+ + head = &phy_roothub->list; + +list_for_each_entry (roothub_entry, head, list) { + err =phy_notify_connect (roothub_entry->phy, port); +if (err) +return err; + }
You walk a list with no locking at all? That does not seem right at all.
Also, this is a new function that is exported with no documentation? Please fix.
thanks,
greg k-h
RE: [PATCH v3 RESEND 4/4] usb: core: add phy notify connect and disconnect
Hi Greg,
Quoted 11 lines
drivers/usb/core/phy.c int usb_phy_roothub_calibrate(struct usb_phy_roothub *phy_roothub) · line 234
Quoted 8 lines
drivers/usb/core/phy.c +8
-0+int usb_phy_roothub_notify_connect (struct usb_phy_roothub +*phy_roothub,int port) { +struct usb_phy_roothub *roothub_entry; +struct list_head *head; +int err; + +if (!phy_roothub) +return 0 ;How can
phy_roothubever be NULL?
This is possible. If the host no use generic phy, then usb_phy_roothub_alloc will return NULL. And other callbacks also follow this rule.
Quoted 11 lines
drivers/usb/core/phy.c int usb_phy_roothub_calibrate(struct usb_phy_roothub *phy_roothub) · line 242
Quoted 9 lines
drivers/usb/core/phy.c +8
-0+ + head = &phy_roothub->list; + +list_for_each_entry (roothub_entry, head, list) { + err =phy_notify_connect (roothub_entry->phy, port); +if (err) +return err; + }You walk a list with no locking at all? That does not seem right at all.
The lock seems unnecessary.
And other similar APIs also don't use any locks.
Quoted 3 lines
Also, this is a new function that is exported with no documentation? Please fix.
Okay, I will add.
Thanks,
Stanley
Quoted 2 lines · Stanley Chang
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
To be able to do dynamic tuning based in the port status, maybe?
Quoted 3 lines
driver when usb connection/disconnection change.
Signed-off-by Stanley Chang <[email protected]>
[...]
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 493
Quoted 10 lines
drivers/phy/phy-core.c +2
-0@@ -489,6 +489,53 @@ int phy_calibrate(struct phy *phy) }EXPORT_SYMBOL_GPL (phy_calibrate); +/** +* phy_notify_connect() - phy connect notify
Notification?
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 497
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+* @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.
If the PHY needs to get the connection status, maybe?
Quoted 9 lines
drivers/phy/phy-core.c +9
-0+* 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 ; +
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 516
Quoted 10 lines
drivers/phy/phy-core.c +10
-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
Notification?
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 520
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+* @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.
If the PHY needs to get the connection status, maybe?
[...]
include/linux/phy/phy.h
Quoted 4 lines
include/linux/phy/phy.h +0
-0
[...]
MBR, Sergey
Hi Sergei,
Quoted 8 lines · Stanley Chang
Quoted 3 lines
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
To be able to do dynamic tuning based in the port status, maybe?
Okay, I will revise.
Quoted 12 lines
Quoted 4 lines
driver when usb connection/disconnection change.
Signed-off-by Stanley Chang <[email protected]>[...]
Quoted 7 lines
drivers/phy/phy-core.c index renamed from drivers/phy/phy-core.c +0
-0
96a0b1e111f3..a84ad4896b7f100644drivers/phy/phy-core.c +0
-0@@ -489,6 +489,53 @@ int phy_calibrate(struct phy *phy) }EXPORT_SYMBOL_GPL (phy_calibrate);
Quoted 4 lines
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 493
Quoted 2 lines
drivers/phy/phy-core.c +2
-0+/** +* phy_notify_connect() - phy connect notify Notification?
Okay, I will revise.
Quoted 18 lines
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 497
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+* @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. If the PHY needs to get the connection status, maybe?
Quoted 11 lines
drivers/phy/phy-core.c +11
-0+* 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); +
Quoted 8 lines
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 516
Quoted 6 lines
drivers/phy/phy-core.c +6
-0+return ret; +} +EXPORT_SYMBOL_GPL (phy_notify_connect); + +/** +* phy_notify_disconnect() - phy disconnect notify Notification?
Okay, I will revise.
Quoted 6 lines
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 520
Quoted 4 lines
drivers/phy/phy-core.c +4
-0+* @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. If the PHY needs to get the connection status, maybe?
Okay, I will revise.
Thanks,
Stanley
Greg Kroah-Hartman
maintainerQuoted 33 lines · Stanley Chang
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]>---
RESEND:
Because 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. So I no use the EXTCON framework for notifying connect/disconnect.
v2 to v3:
No change
v1 to v2:
No change--- drivers/phy/phy-core.c | 47 +++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 18 ++++++++++++++++ 2 files changed, 65 insertions(+)drivers/phy/phy-core.c +4
-0@@ -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
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 505
Quoted 10 lines
drivers/phy/phy-core.c +10
-0+* +* 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 ;
How can phy be null?
And it is not successful if connect is not valid, so why not return an error there?
Quoted 14 lines
drivers/phy/phy-core.c +14
-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 +*
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 529
Quoted 10 lines
drivers/phy/phy-core.c +10
-0+* 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 ;
Same as above.
Quoted 17 lines
drivers/phy/phy-core.c +9
-0+ +mutex_lock (&phy->mutex); + ret = phy->ops->disconnect (phy, port); +mutex_unlock (&phy->mutex); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_notify_disconnect); +/** * phy_configure() - Changes the phy parameters * @phy: the phy returned by phy_get() include/linux/phy/phy.h +0
-0
include/linux/phy/phy.h struct phy_ops { · line 126
Quoted 5 lines
include/linux/phy/phy.h +2
-0@@ -122,6 +122,8 @@ struct phy_ops { union phy_configure_opts *opts);int (*reset)(struct phy *phy);int (*calibrate)(struct phy *phy); +int (*connect)(struct phy *phy,int port); +int (*disconnect)(struct phy *phy,int port);
You forgot to document these and would have a warning from the documentation build if this was applied :(
Quoted 13 lines
include/linux/phy/phy.h +2
-0void (*release)(struct phy *phy);struct module *owner; };@@ -243,6 +245,8 @@ static inline enum phy_mode phy_get_mode(struct phy *phy) }int phy_reset (struct phy *phy);int phy_calibrate (struct phy *phy); +int phy_notify_connect (struct phy *phy,int port); +int phy_notify_disconnect (struct phy *phy,int port);static inline int phy_get_bus_width (struct phy *phy) {return phy->attrs.bus_width;
include/linux/phy/phy.h static inline int phy_calibrate(struct phy *phy) · line 406
Quoted 7 lines
include/linux/phy/phy.h +4
-0@@ -396,6 +400,20 @@ static inline int phy_calibrate(struct phy *phy)return -ENOSYS ; } +static inline int phy_notify_connect (struct phy *phy,int index) +{ +if (!phy) +return 0 ;
Why check this?
include/linux/phy/phy.h static inline int phy_calibrate(struct phy *phy) · line 413
Quoted 7 lines
include/linux/phy/phy.h +7
-0+return -ENOSYS ; +} + +static inline int phy_notify_disconnect (struct phy *phy,int index) +{ +if (!phy) +return 0 ;
Again, why check this?
thanks,
greg k-h
Hi Greg,
Quoted 46 lines · Stanley Chang
Quoted 31 lines
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]>---
RESEND:
Because 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. So I no use the EXTCON framework for notifying connect/disconnect.
v2 to v3:
No change
v1 to v2:
No change--- drivers/phy/phy-core.c | 47 +++++++++++++++++++++++++++++++++++++++++ include/linux/phy/phy.h | 18 ++++++++++++++++ 2 files changed, 65 insertions(+)drivers/phy/phy-core.c index renamed from drivers/phy/phy-core.c +0
-0
96a0b1e111f3..a84ad4896b7f100644drivers/phy/phy-core.c +2
-0@@ -489,6 +489,53 @@ int phy_calibrate(struct phy *phy) }EXPORT_SYMBOL_GPL (phy_calibrate); +/** +* phy_notify_connect() - phy connect notify drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) } · line 502
Quoted 10 lines
drivers/phy/phy-core.c +10
-0+* @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 ;How can phy be null?
Quoted 1 line
And it is not successful if connect is not valid, so why not return an error there?
This is possible. If a caller no use the generic phy or no define the connect callback. And if no define connect callback, it will do nothing. So no any error.
Quoted 16 lines
Quoted 16 lines
drivers/phy/phy-core.c +16
-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. +*
Quoted 8 lines
drivers/phy/phy-core.c int phy_calibrate(struct phy *phy) · line 529
Quoted 6 lines
drivers/phy/phy-core.c +6
-0+* 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 ;Same as above.
Same as connect callback.
Quoted 17 lines
Quoted 17 lines
drivers/phy/phy-core.c +9
-0+ +mutex_lock (&phy->mutex); + ret = phy->ops->disconnect (phy, port); +mutex_unlock (&phy->mutex); + +return ret; +} +EXPORT_SYMBOL_GPL (phy_notify_disconnect); +/** * phy_configure() - Changes the phy parameters * @phy: the phy returned by phy_get() diff --git
a/include/linux/phy/phy.hb/include/linux/phy/phy.hindexf6d607ef0e80..cf98cb29ddaa100644include/linux/phy/phy.h +0
-0@@ -122,6 +122,8 @@ struct phy_ops {
Quoted 9 lines
include/linux/phy/phy.h struct phy_ops { · line 126
Quoted 5 lines
include/linux/phy/phy.h +2
-0union phy_configure_opts *opts);int (*reset)(struct phy *phy);int (*calibrate)(struct phy *phy); +int (*connect)(struct phy *phy,int port); +int (*disconnect)(struct phy *phy,int port);You forgot to document these and would have a warning from the documentation build if this was applied :(
I will add a description.
Quoted 14 lines
Quoted 14 lines
include/linux/phy/phy.h +0
-0void (*release)(struct phy *phy);struct module *owner; };@@ -243,6 +245,8 @@ static inline enum phy_mode phy_get_mode(structphy *phy) } int
phy_reset(struct phy *phy); intphy_calibrate(struct phy *phy);include/linux/phy/phy.h +2
-0+int phy_notify_connect (struct phy *phy,int port);int +phy_notify_disconnect (struct phy *phy,int port);static inline int phy_get_bus_width (struct phy *phy) {return phy->attrs.bus_width;@@ -396,6 +400,20 @@ static inline int phy_calibrate(struct phy *phy)return -ENOSYS ; }
Quoted 5 lines
include/linux/phy/phy.h static inline int phy_calibrate(struct phy *phy) · line 406
Quoted 3 lines
include/linux/phy/phy.h +3
-0+static inline int phy_notify_connect (struct phy *phy,int index) { +if (!phy) +return 0 ;Why check this?
It is normal for phy to be null.
But if phy is not empty, -ENOSYS should be returned to indicate the error "Operation not supported". Other callbacks also follow this rule.
Quoted 8 lines
include/linux/phy/phy.h static inline int phy_calibrate(struct phy *phy) · line 413
Quoted 6 lines
include/linux/phy/phy.h +6
-0+return -ENOSYS ; +} + +static inline int phy_notify_disconnect (struct phy *phy,int index) { +if (!phy) +return 0 ;Again, why check this?
As above.
Thanks,
Stanley