diff mbox series

[v2,07/12] usb: common: Add functions to get lanes and lsm

Message ID 830743026ec46eacc5f7f28f39d2f1dae413dc05.1595468673.git.thinhn@synopsys.com (mailing list archive)
State Superseded
Headers show
Series usb: Handle different sublink speeds | expand

Commit Message

Thinh Nguyen July 23, 2020, 2:12 a.m. UTC
Add common functions to get the requested number of lanes and lane speed
mantissa from device properties.

Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
---
Changes in v2:
- New commit

 drivers/usb/common/common.c | 26 ++++++++++++++++++++++++++
 include/linux/usb/ch9.h     | 19 +++++++++++++++++++
 2 files changed, 45 insertions(+)
diff mbox series

Patch

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 1433260d99b4..871a7326b6b7 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -92,6 +92,32 @@  enum usb_device_speed usb_get_maximum_speed(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_get_maximum_speed);
 
+u8 usb_get_num_lanes(struct device *dev)
+{
+	u8 num_lanes;
+	int ret;
+
+	ret = device_property_read_u8(dev, "num-lanes", &num_lanes);
+	if (ret < 0)
+		return 0;
+
+	return num_lanes;
+}
+EXPORT_SYMBOL_GPL(usb_get_num_lanes);
+
+u16 usb_get_lsm(struct device *dev)
+{
+	u16 lsm;
+	int ret;
+
+	ret = device_property_read_u16(dev, "lane-speed-mantissa-gbps", &lsm);
+	if (ret < 0)
+		return 0;
+
+	return lsm;
+}
+EXPORT_SYMBOL_GPL(usb_get_lsm);
+
 const char *usb_state_string(enum usb_device_state state)
 {
 	static const char *const names[] = {
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index f87ef9a2f859..1097c6f8e2ef 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -105,6 +105,25 @@  extern const char *usb_speed_string(enum usb_device_speed speed);
  */
 extern enum usb_device_speed usb_get_maximum_speed(struct device *dev);
 
+/**
+ * usb_get_num_lanes - Get maximum number of requested lanes for a given USB
+ * controller.
+ * @dev: Pointer to the given USB controller device
+ *
+ * The function returns the number of requested lanes from the property
+ * "num-lanes".
+ */
+extern u8 usb_get_num_lanes(struct device *dev);
+
+/**
+ * usb_get_lsm - Get requested lane speed mantissa for a given USB controller.
+ * @dev: Pointer to the given USB controller device
+ *
+ * The function returns the requested symmetric lane speed mantissa in Gbps from
+ * the property "lane-speed-mantissa-gbps".
+ */
+extern u16 usb_get_lsm(struct device *dev);
+
 /**
  * usb_state_string - Returns human readable name for the state.
  * @state: The state to return a human-readable name for. If it's not