diff mbox series

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

Message ID 1621933165-9661-2-git-send-email-chunfeng.yun@mediatek.com
State Superseded
Headers show
Series None | expand

Commit Message

Chunfeng Yun (云春峰) May 25, 2021, 8:59 a.m. UTC
Add helper to get "role-switch-default-mode", and convert it
to the corresponding enum usb_dr_mode

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 drivers/usb/common/common.c | 20 ++++++++++++++++++++
 include/linux/usb/otg.h     |  1 +
 2 files changed, 21 insertions(+)

Comments

Greg Kroah-Hartman May 27, 2021, 7:28 a.m. UTC | #1
On Tue, May 25, 2021 at 04:59:24PM +0800, Chunfeng Yun wrote:
> Add helper to get "role-switch-default-mode", and convert it

> to the corresponding enum usb_dr_mode

> 

> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>

> ---

>  drivers/usb/common/common.c | 20 ++++++++++++++++++++

>  include/linux/usb/otg.h     |  1 +

>  2 files changed, 21 insertions(+)

> 

> diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c

> index fff318597337..78a625a4e526 100644

> --- a/drivers/usb/common/common.c

> +++ b/drivers/usb/common/common.c

> @@ -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

> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h

> index a86ee6aad51b..bde313c97fb6 100644

> --- a/include/linux/usb/otg.h

> +++ b/include/linux/usb/otg.h

> @@ -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
Chunfeng Yun (云春峰) May 27, 2021, 9:43 a.m. UTC | #2
On Thu, 2021-05-27 at 09:28 +0200, Greg Kroah-Hartman wrote:
> On Tue, May 25, 2021 at 04:59:24PM +0800, Chunfeng Yun wrote:

> > Add helper to get "role-switch-default-mode", and convert it

> > to the corresponding enum usb_dr_mode

> > 

> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>

> > ---

> >  drivers/usb/common/common.c | 20 ++++++++++++++++++++

> >  include/linux/usb/otg.h     |  1 +

> >  2 files changed, 21 insertions(+)

> > 

> > diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c

> > index fff318597337..78a625a4e526 100644

> > --- a/drivers/usb/common/common.c

> > +++ b/drivers/usb/common/common.c

> > @@ -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

> > diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h

> > index a86ee6aad51b..bde313c97fb6 100644

> > --- a/include/linux/usb/otg.h

> > +++ b/include/linux/usb/otg.h

> > @@ -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?

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

> 

> thanks,

> 

> greg k-h
Greg Kroah-Hartman May 27, 2021, 10:01 a.m. UTC | #3
On Thu, May 27, 2021 at 05:43:39PM +0800, Chunfeng Yun wrote:
> On Thu, 2021-05-27 at 09:28 +0200, Greg Kroah-Hartman wrote:

> > On Tue, May 25, 2021 at 04:59:24PM +0800, Chunfeng Yun wrote:

> > > Add helper to get "role-switch-default-mode", and convert it

> > > to the corresponding enum usb_dr_mode

> > > 

> > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>

> > > ---

> > >  drivers/usb/common/common.c | 20 ++++++++++++++++++++

> > >  include/linux/usb/otg.h     |  1 +

> > >  2 files changed, 21 insertions(+)

> > > 

> > > diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c

> > > index fff318597337..78a625a4e526 100644

> > > --- a/drivers/usb/common/common.c

> > > +++ b/drivers/usb/common/common.c

> > > @@ -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

> > > diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h

> > > index a86ee6aad51b..bde313c97fb6 100644

> > > --- a/include/linux/usb/otg.h

> > > +++ b/include/linux/usb/otg.h

> > > @@ -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?

> 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
Chunfeng Yun (云春峰) May 28, 2021, 2:07 a.m. UTC | #4
On Thu, 2021-05-27 at 12:01 +0200, Greg Kroah-Hartman wrote:
> On Thu, May 27, 2021 at 05:43:39PM +0800, Chunfeng Yun wrote:

> > On Thu, 2021-05-27 at 09:28 +0200, Greg Kroah-Hartman wrote:

> > > On Tue, May 25, 2021 at 04:59:24PM +0800, Chunfeng Yun wrote:

> > > > Add helper to get "role-switch-default-mode", and convert it

> > > > to the corresponding enum usb_dr_mode

> > > > 

> > > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>

> > > > ---

> > > >  drivers/usb/common/common.c | 20 ++++++++++++++++++++

> > > >  include/linux/usb/otg.h     |  1 +

> > > >  2 files changed, 21 insertions(+)

> > > > 

> > > > diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c

> > > > index fff318597337..78a625a4e526 100644

> > > > --- a/drivers/usb/common/common.c

> > > > +++ b/drivers/usb/common/common.c

> > > > @@ -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

> > > > diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h

> > > > index a86ee6aad51b..bde313c97fb6 100644

> > > > --- a/include/linux/usb/otg.h

> > > > +++ b/include/linux/usb/otg.h

> > > > @@ -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?

> > 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
> 

> thanks,

> 

> greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index fff318597337..78a625a4e526 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -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
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index a86ee6aad51b..bde313c97fb6 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -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 */