linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pawel Laszczak <pawell@cadence.com>
To: <felipe.balbi@linux.intel.com>
Cc: <gregkh@linuxfoundation.org>, <linux-usb@vger.kernel.org>,
	<rogerq@ti.com>, <linux-kernel@vger.kernel.org>,
	<jbergsagel@ti.com>, <nsekhar@ti.com>, <nm@ti.com>,
	<sureshp@cadence.com>, <jpawar@cadence.com>,
	<kurahul@cadence.com>, <aniljoy@cadence.com>,
	Pawel Laszczak <pawell@cadence.com>
Subject: [PATCH 1/3] usb: common: Add usb_get_dr_mode_from_string and usb_dr_mode_to_string.
Date: Mon, 8 Jul 2019 14:35:24 +0100	[thread overview]
Message-ID: <1562592924-17528-1-git-send-email-pawell@cadence.com> (raw)
In-Reply-To: <all>

Patch introduces new function usb_dr_mode_to_string for converting dual
role mod to string and removes static from usb_dr_mode_to_string
definition.

Both changes have made to avoid duplication of code by cdns3 driver.

Signed-off-by: Pawel Laszczak <pawell@cadence.com>
---
 drivers/usb/common/common.c | 12 +++++++++++-
 include/linux/usb/otg.h     | 16 ++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index 18f5dcf58b0d..a485071325b3 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -118,13 +118,14 @@ static const char *const usb_dr_modes[] = {
 	[USB_DR_MODE_OTG]		= "otg",
 };
 
-static enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
+enum usb_dr_mode usb_get_dr_mode_from_string(const char *str)
 {
 	int ret;
 
 	ret = match_string(usb_dr_modes, ARRAY_SIZE(usb_dr_modes), str);
 	return (ret < 0) ? USB_DR_MODE_UNKNOWN : ret;
 }
+EXPORT_SYMBOL_GPL(usb_get_dr_mode_from_string);
 
 enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 {
@@ -139,6 +140,15 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_get_dr_mode);
 
+const char *usb_dr_mode_to_string(const enum usb_dr_mode dr_mode)
+{
+	if (dr_mode > USB_DR_MODE_UNKNOWN || dr_mode <= USB_DR_MODE_PERIPHERAL)
+		return usb_dr_modes[dr_mode];
+
+	return usb_dr_modes[USB_DR_MODE_UNKNOWN];
+}
+EXPORT_SYMBOL_GPL(usb_dr_mode_to_string);
+
 #ifdef CONFIG_OF
 /**
  * of_usb_get_dr_mode_by_phy - Get dual role mode for the controller device
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 69f1b6328532..c156817672c4 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -129,4 +129,20 @@ enum usb_dr_mode {
  */
 extern enum usb_dr_mode usb_get_dr_mode(struct device *dev);
 
+/**
+ * usb_get_dr_mode_from_string - Convert string to dual role mode.
+ * @str: Pointer to the given string
+ *
+ * The function gets string and returns the correspondig enum usb_dr_mode.
+ */
+extern enum usb_dr_mode usb_get_dr_mode_from_string(const char *str);
+
+/**
+ * usb_dr_mode_to_string - Convert dual role mode to string.
+ * @dr_mode: Pointer to the given dual role mode
+ *
+ * The function gets enum usb_dr_mode, and returns the correspondig string.
+ */
+extern const char *usb_dr_mode_to_string(const enum usb_dr_mode dr_mode);
+
 #endif /* __LINUX_USB_OTG_H */
-- 
2.17.1


       reply	other threads:[~2019-07-08 13:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <all>
2019-07-08 13:35 ` Pawel Laszczak [this message]
2019-07-09  6:11   ` [PATCH 1/3] usb: common: Add usb_get_dr_mode_from_string and usb_dr_mode_to_string Felipe Balbi
2019-07-09  6:23     ` Pawel Laszczak
2019-07-09  6:29       ` Felipe Balbi
2019-07-09  6:37         ` Pawel Laszczak
2019-07-21 14:54           ` Pawel Laszczak
2019-07-31  3:49             ` Pawel Laszczak

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=1562592924-17528-1-git-send-email-pawell@cadence.com \
    --to=pawell@cadence.com \
    --cc=aniljoy@cadence.com \
    --cc=felipe.balbi@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbergsagel@ti.com \
    --cc=jpawar@cadence.com \
    --cc=kurahul@cadence.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=nsekhar@ti.com \
    --cc=rogerq@ti.com \
    --cc=sureshp@cadence.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;
as well as URLs for NNTP newsgroup(s).