Skip to contentSkip to conversation

usb: common: move usb_get_dr_mode() kerneldoc next to its definition

PATCH In review Chunfeng Yun 2 participants 8 messages May 25, 2021 – May 28, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 usb: common: move usb_get_dr_mode() kerneldoc next to its definition

Following a general rule, add the kerneldoc for a function next to it's definition, but not next to its declaration in a header file, meanwhile fix typo 'correspondig'

---
 drivers/usb/common/common.c | 7 +++++++
 include/linux/usb/otg.h     | 7 -------
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/usb/common/common.c +7 -0
index 347fb3d3894a..fff318597337 100644
@@ -187,6 +187,13 @@ static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
 	return (ret < 0) ? USB_DR_MODE_UNKNOWN : ret;
 }
 
+/**
+ * usb_get_dr_mode - Get dual role mode for given device
+ * @dev: Pointer to the given device
+ *
+ * The function gets phy interface string from property 'dr_mode',
+ * and returns the corresponding enum usb_dr_mode
+ */
 enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 {
 	const char *dr_mode;
include/linux/usb/otg.h +0 -7
index 69f1b6328532..a86ee6aad51b 100644
@@ -120,13 +120,6 @@ enum usb_dr_mode {
 	USB_DR_MODE_OTG,
 };
 
-/**
- * usb_get_dr_mode - Get dual role mode for given device
- * @dev: Pointer to the given device
- *
- * The function gets phy interface string from property 'dr_mode',
- * and returns the correspondig enum usb_dr_mode
- */
 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
 
 #endif /* __LINUX_USB_OTG_H */
Signature · 1 line
2.18.0
#1 lore raw

PATCH 2/3 usb: common: add helper to get role-switch-default-mode

Add helper to get "role-switch-default-mode", and convert it to the corresponding enum usb_dr_mode

---
 drivers/usb/common/common.c | 20 ++++++++++++++++++++
 include/linux/usb/otg.h     |  1 +
 2 files changed, 21 insertions(+)
drivers/usb/common/common.c +20 -0
index fff318597337..78a625a4e526 100644
@@ -207,6 +207,26 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_get_dr_mode);
 
+/**
+ * usb_get_role_switch_default_mode - Get default mode for given device
+ * @dev: Pointer to the given device
+ *
+ * The function gets string from property 'role-switch-default-mode',
+ * and returns the corresponding enum usb_dr_mode.
+ */
+enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev)
+{
+	const char *str;
+	int ret;
+
+	ret = device_property_read_string(dev, "role-switch-default-mode", &str);
+	if (ret < 0)
+		return USB_DR_MODE_UNKNOWN;
+
+	return usb_get_dr_mode_from_string(str);
+}
+EXPORT_SYMBOL_GPL(usb_get_role_switch_default_mode);
+
 /**
  * usb_decode_interval - Decode bInterval into the time expressed in 1us unit
  * @epd: The descriptor of the endpoint
include/linux/usb/otg.h +1 -0
index a86ee6aad51b..bde313c97fb6 100644
@@ -121,5 +121,6 @@ enum usb_dr_mode {
 };
 
 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
+extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev);
 
 #endif /* __LINUX_USB_OTG_H */
Signature · 1 line
2.18.0
#2 lore raw

Re: [PATCH 2/3] usb: common: add helper to get role-switch-default-mode

Quoted 45 lines · Chunfeng Yun

Add helper to get "role-switch-default-mode", and convert it to the corresponding enum usb_dr_mode

---
 drivers/usb/common/common.c | 20 ++++++++++++++++++++
 include/linux/usb/otg.h     |  1 +
 2 files changed, 21 insertions(+)
drivers/usb/common/common.c +20 -0
index fff318597337..78a625a4e526 100644
@@ -207,6 +207,26 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_get_dr_mode);
 
+/**
+ * usb_get_role_switch_default_mode - Get default mode for given device
+ * @dev: Pointer to the given device
+ *
+ * The function gets string from property 'role-switch-default-mode',
+ * and returns the corresponding enum usb_dr_mode.
+ */
+enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev)
+{
+	const char *str;
+	int ret;
+
+	ret = device_property_read_string(dev, "role-switch-default-mode", &str);
+	if (ret < 0)
+		return USB_DR_MODE_UNKNOWN;
+
+	return usb_get_dr_mode_from_string(str);
+}
+EXPORT_SYMBOL_GPL(usb_get_role_switch_default_mode);
+
 /**
  * usb_decode_interval - Decode bInterval into the time expressed in 1us unit
  * @epd: The descriptor of the endpoint
include/linux/usb/otg.h +0 -0
index a86ee6aad51b..bde313c97fb6 100644

include/linux/usb/otg.h enum usb_dr_mode { · line 124

Quoted 4 lines
include/linux/usb/otg.h +1 -0
@@ -121,5 +121,6 @@ enum usb_dr_mode {
 };
 
 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
+extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev);

What other code outside of the dwc3 driver will ever need to call this?

thanks,

greg k-h

#3 lore raw

Re: [PATCH 2/3] usb: common: add helper to get role-switch-default-mode

Quoted 48 lines · Greg Kroah-Hartman
Quoted 47 lines · Chunfeng Yun

Add helper to get "role-switch-default-mode", and convert it to the corresponding enum usb_dr_mode

---
 drivers/usb/common/common.c | 20 ++++++++++++++++++++
 include/linux/usb/otg.h     |  1 +
 2 files changed, 21 insertions(+)
drivers/usb/common/common.c +20 -0
index fff318597337..78a625a4e526 100644
@@ -207,6 +207,26 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_get_dr_mode);
 
+/**
+ * usb_get_role_switch_default_mode - Get default mode for given device
+ * @dev: Pointer to the given device
+ *
+ * The function gets string from property 'role-switch-default-mode',
+ * and returns the corresponding enum usb_dr_mode.
+ */
+enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev)
+{
+	const char *str;
+	int ret;
+
+	ret = device_property_read_string(dev, "role-switch-default-mode", &str);
+	if (ret < 0)
+		return USB_DR_MODE_UNKNOWN;
+
+	return usb_get_dr_mode_from_string(str);
+}
+EXPORT_SYMBOL_GPL(usb_get_role_switch_default_mode);
+
 /**
  * usb_decode_interval - Decode bInterval into the time expressed in 1us unit
  * @epd: The descriptor of the endpoint
include/linux/usb/otg.h +0 -0
index a86ee6aad51b..bde313c97fb6 100644
@@ -121,5 +121,6 @@ enum usb_dr_mode {
 };
 
Quoted 4 lines

include/linux/usb/otg.h enum usb_dr_mode { · line 124

Quoted 2 lines
include/linux/usb/otg.h +1 -0
 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
+extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev);

What other code outside of the dwc3 driver will ever need to call this?

I prepare a series of pathes for mtu3, and will support "role-switch-default-mode" property

Quoted 4 lines

thanks,

greg k-h

#4 lore raw

Re: [PATCH 2/3] usb: common: add helper to get role-switch-default-mode

Quoted 49 lines · Chunfeng Yun
Quoted 48 lines · Greg Kroah-Hartman
Quoted 47 lines · Chunfeng Yun

Add helper to get "role-switch-default-mode", and convert it to the corresponding enum usb_dr_mode

---
 drivers/usb/common/common.c | 20 ++++++++++++++++++++
 include/linux/usb/otg.h     |  1 +
 2 files changed, 21 insertions(+)
drivers/usb/common/common.c +20 -0
index fff318597337..78a625a4e526 100644
@@ -207,6 +207,26 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_get_dr_mode);
 
+/**
+ * usb_get_role_switch_default_mode - Get default mode for given device
+ * @dev: Pointer to the given device
+ *
+ * The function gets string from property 'role-switch-default-mode',
+ * and returns the corresponding enum usb_dr_mode.
+ */
+enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev)
+{
+	const char *str;
+	int ret;
+
+	ret = device_property_read_string(dev, "role-switch-default-mode", &str);
+	if (ret < 0)
+		return USB_DR_MODE_UNKNOWN;
+
+	return usb_get_dr_mode_from_string(str);
+}
+EXPORT_SYMBOL_GPL(usb_get_role_switch_default_mode);
+
 /**
  * usb_decode_interval - Decode bInterval into the time expressed in 1us unit
  * @epd: The descriptor of the endpoint
include/linux/usb/otg.h +0 -0
index a86ee6aad51b..bde313c97fb6 100644
@@ -121,5 +121,6 @@ enum usb_dr_mode {
 };
 
Quoted 6 lines
Quoted 4 lines

include/linux/usb/otg.h enum usb_dr_mode { · line 124

Quoted 2 lines
include/linux/usb/otg.h +1 -0
 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
+extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev);

What other code outside of the dwc3 driver will ever need to call this?

I prepare a series of pathes for mtu3, and will support "role-switch-default-mode" property

Ok, how about we wait until at least 2 drivers need it before accepting this change.

thanks,

greg k-h

#5 lore raw

Re: [PATCH 2/3] usb: common: add helper to get role-switch-default-mode

Quoted 54 lines · Greg Kroah-Hartman
Quoted 53 lines · Chunfeng Yun
Quoted 52 lines · Greg Kroah-Hartman
Quoted 45 lines · Chunfeng Yun

Add helper to get "role-switch-default-mode", and convert it to the corresponding enum usb_dr_mode

---
 drivers/usb/common/common.c | 20 ++++++++++++++++++++
 include/linux/usb/otg.h     |  1 +
 2 files changed, 21 insertions(+)
drivers/usb/common/common.c +20 -0
index fff318597337..78a625a4e526 100644
@@ -207,6 +207,26 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_get_dr_mode);
 
+/**
+ * usb_get_role_switch_default_mode - Get default mode for given device
+ * @dev: Pointer to the given device
+ *
+ * The function gets string from property 'role-switch-default-mode',
+ * and returns the corresponding enum usb_dr_mode.
+ */
+enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev)
+{
+	const char *str;
+	int ret;
+
+	ret = device_property_read_string(dev, "role-switch-default-mode", &str);
+	if (ret < 0)
+		return USB_DR_MODE_UNKNOWN;
+
+	return usb_get_dr_mode_from_string(str);
+}
+EXPORT_SYMBOL_GPL(usb_get_role_switch_default_mode);
+
 /**
  * usb_decode_interval - Decode bInterval into the time expressed in 1us unit
  * @epd: The descriptor of the endpoint
include/linux/usb/otg.h +0 -0
index a86ee6aad51b..bde313c97fb6 100644

include/linux/usb/otg.h enum usb_dr_mode { · line 124

Quoted 4 lines
include/linux/usb/otg.h +1 -0
@@ -121,5 +121,6 @@ enum usb_dr_mode {
 };
 
 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
+extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev);

What other code outside of the dwc3 driver will ever need to call this?

Quoted 5 lines
Quoted 2 lines

I prepare a series of pathes for mtu3, and will support "role-switch-default-mode" property

Ok, how about we wait until at least 2 drivers need it before accepting this change.

Makes sense, thank you

Quoted 4 lines

thanks,

greg k-h

#6 lore raw

PATCH 3/3 usb: dwc3: drd: use helper to get role-switch-default-mode

In reply to Chunfeng Yun

Use the new helper usb_get_role_switch_default_mode() to get property of "role-switch-default-mode"

---
 drivers/usb/dwc3/drd.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/usb/dwc3/drd.c +2 -6
index e2b68bb770d1..4e0a26683b06 100644
@@ -541,14 +541,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct usb_role_switch *sw)
 static int dwc3_setup_role_switch(struct dwc3 *dwc)
 {
 	struct usb_role_switch_desc dwc3_role_switch = {NULL};
-	const char *str;
 	u32 mode;
-	int ret;
 
-	ret = device_property_read_string(dwc->dev, "role-switch-default-mode",
-					  &str);
-	if (ret >= 0  && !strncmp(str, "host", strlen("host"))) {
-		dwc->role_switch_default_mode = USB_DR_MODE_HOST;
+	dwc->role_switch_default_mode = usb_get_role_switch_default_mode(dwc->dev);
+	if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) {
 		mode = DWC3_GCTL_PRTCAP_HOST;
 	} else {
 		dwc->role_switch_default_mode = USB_DR_MODE_PERIPHERAL;
Signature · 1 line
2.18.0
#7 lore raw
In reply to Chunfeng Yun
Quoted 9 lines · Chunfeng Yun

Following a general rule, add the kerneldoc for a function next to it's definition, but not next to its declaration in a header file, meanwhile fix typo 'correspondig'

---
 drivers/usb/common/common.c | 7 +++++++
 include/linux/usb/otg.h     | 7 -------
 2 files changed, 7 insertions(+), 7 deletions(-)

Does not apply to my usb-next branch :(

thanks,

greg k-h