All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] extcon: ptn5150: add usb role class support
@ 2022-04-06  9:42 ` Li Jun
  2022-04-06 10:15   ` Krzysztof Kozlowski
                     ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Li Jun @ 2022-04-06  9:42 UTC (permalink / raw)
  To: myungjoo.ham, cw00.choi, krzk; +Cc: linux-kernel, frank.li, xu.yang_2

Add support of usb role class consumer to do role switch.

Signed-off-by: Li Jun <jun.li@nxp.com>
---
 drivers/extcon/Kconfig          |  1 +
 drivers/extcon/extcon-ptn5150.c | 39 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 0d42e49105dd..9828ade787a8 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -132,6 +132,7 @@ config EXTCON_PTN5150
 	tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
 	depends on I2C && (GPIOLIB || COMPILE_TEST)
 	select REGMAP_I2C
+	select USB_ROLE_SWITCH
 	help
 	  Say Y here to enable support for USB peripheral and USB host
 	  detection by NXP PTN5150 CC (Configuration Channel) logic chip.
diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
index 5b9a3cf8df26..821b0f390308 100644
--- a/drivers/extcon/extcon-ptn5150.c
+++ b/drivers/extcon/extcon-ptn5150.c
@@ -17,6 +17,7 @@
 #include <linux/slab.h>
 #include <linux/extcon-provider.h>
 #include <linux/gpio/consumer.h>
+#include <linux/usb/role.h>
 
 /* PTN5150 registers */
 #define PTN5150_REG_DEVICE_ID			0x01
@@ -52,6 +53,7 @@ struct ptn5150_info {
 	int irq;
 	struct work_struct irq_work;
 	struct mutex mutex;
+	struct usb_role_switch *role_sw;
 };
 
 /* List of detectable cables */
@@ -85,6 +87,12 @@ static void ptn5150_check_state(struct ptn5150_info *info)
 		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
 		gpiod_set_value_cansleep(info->vbus_gpiod, 0);
 		extcon_set_state_sync(info->edev, EXTCON_USB, true);
+
+		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_DEVICE);
+		if (ret)
+			dev_err(info->dev, "failed to set device role: %d\n",
+				ret);
+
 		break;
 	case PTN5150_UFP_ATTACHED:
 		extcon_set_state_sync(info->edev, EXTCON_USB, false);
@@ -95,6 +103,12 @@ static void ptn5150_check_state(struct ptn5150_info *info)
 			gpiod_set_value_cansleep(info->vbus_gpiod, 1);
 
 		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
+
+		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_HOST);
+		if (ret)
+			dev_err(info->dev, "failed to set host role: %d\n",
+				ret);
+
 		break;
 	default:
 		break;
@@ -133,6 +147,13 @@ static void ptn5150_irq_work(struct work_struct *work)
 			extcon_set_state_sync(info->edev,
 					EXTCON_USB, false);
 			gpiod_set_value_cansleep(info->vbus_gpiod, 0);
+
+			ret = usb_role_switch_set_role(info->role_sw,
+						       USB_ROLE_NONE);
+			if (ret)
+				dev_err(info->dev,
+					"failed to set none role: %d\n",
+					ret);
 		}
 	}
 
@@ -194,6 +215,14 @@ static int ptn5150_init_dev_type(struct ptn5150_info *info)
 	return 0;
 }
 
+static void ptn5150_put_role_sw(void *data)
+{
+	struct ptn5150_info *info = data;
+
+	cancel_work_sync(&info->irq_work);
+	usb_role_switch_put(info->role_sw);
+}
+
 static int ptn5150_i2c_probe(struct i2c_client *i2c)
 {
 	struct device *dev = &i2c->dev;
@@ -284,6 +313,16 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)
 	if (ret)
 		return -EINVAL;
 
+	info->role_sw = usb_role_switch_get(info->dev);
+	if (IS_ERR(info->role_sw))
+		return PTR_ERR(info->role_sw);
+
+	if (info->role_sw) {
+		ret = devm_add_action_or_reset(dev, ptn5150_put_role_sw, info);
+		if (ret)
+			return ret;
+	}
+
 	/*
 	 * Update current extcon state if for example OTG connection was there
 	 * before the probe
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-06  9:42 ` [PATCH] extcon: ptn5150: add usb role class support Li Jun
@ 2022-04-06 10:15   ` Krzysztof Kozlowski
  2022-04-06 11:48     ` Jun Li
  2022-04-06 18:53   ` kernel test robot
  2022-04-07  2:17   ` Chanwoo Choi
  2 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-06 10:15 UTC (permalink / raw)
  To: Li Jun, myungjoo.ham, cw00.choi; +Cc: linux-kernel, frank.li, xu.yang_2

On 06/04/2022 11:42, Li Jun wrote:
> Add support of usb role class consumer to do role switch.

Please mention also why you are doing this.

> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> ---
>  drivers/extcon/Kconfig          |  1 +
>  drivers/extcon/extcon-ptn5150.c | 39 +++++++++++++++++++++++++++++++++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 0d42e49105dd..9828ade787a8 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -132,6 +132,7 @@ config EXTCON_PTN5150
>  	tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
>  	depends on I2C && (GPIOLIB || COMPILE_TEST)
>  	select REGMAP_I2C
> +	select USB_ROLE_SWITCH

You do not need to select it. Driver will work without role switch,
won't it? If it works, then probably it should be just imply.

>  	help
>  	  Say Y here to enable support for USB peripheral and USB host
>  	  detection by NXP PTN5150 CC (Configuration Channel) logic chip.
> diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
> index 5b9a3cf8df26..821b0f390308 100644
> --- a/drivers/extcon/extcon-ptn5150.c
> +++ b/drivers/extcon/extcon-ptn5150.c
> @@ -17,6 +17,7 @@
>  #include <linux/slab.h>
>  #include <linux/extcon-provider.h>
>  #include <linux/gpio/consumer.h>
> +#include <linux/usb/role.h>
>  
>  /* PTN5150 registers */
>  #define PTN5150_REG_DEVICE_ID			0x01
> @@ -52,6 +53,7 @@ struct ptn5150_info {
>  	int irq;
>  	struct work_struct irq_work;
>  	struct mutex mutex;
> +	struct usb_role_switch *role_sw;
>  };
>  
>  /* List of detectable cables */
> @@ -85,6 +87,12 @@ static void ptn5150_check_state(struct ptn5150_info *info)
>  		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
>  		gpiod_set_value_cansleep(info->vbus_gpiod, 0);
>  		extcon_set_state_sync(info->edev, EXTCON_USB, true);
> +
> +		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_DEVICE);
> +		if (ret)
> +			dev_err(info->dev, "failed to set device role: %d\n",
> +				ret);
> +
>  		break;
>  	case PTN5150_UFP_ATTACHED:
>  		extcon_set_state_sync(info->edev, EXTCON_USB, false);
> @@ -95,6 +103,12 @@ static void ptn5150_check_state(struct ptn5150_info *info)
>  			gpiod_set_value_cansleep(info->vbus_gpiod, 1);
>  
>  		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
> +
> +		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_HOST);
> +		if (ret)
> +			dev_err(info->dev, "failed to set host role: %d\n",
> +				ret);
> +


Instead of having usb_role_switch_set_role() in two places, how about:
1. setting local variable to USB_ROLE_HOST/USB_ROLE_NONE
2. return on default
3. one call to usb_role_switch_set_role() outside of the case?

Should create less code.

>  		break;
>  	default:
>  		break;
> @@ -133,6 +147,13 @@ static void ptn5150_irq_work(struct work_struct *work)
>  			extcon_set_state_sync(info->edev,
>  					EXTCON_USB, false);
>  			gpiod_set_value_cansleep(info->vbus_gpiod, 0);
> +
> +			ret = usb_role_switch_set_role(info->role_sw,
> +						       USB_ROLE_NONE);
> +			if (ret)
> +				dev_err(info->dev,
> +					"failed to set none role: %d\n",
> +					ret);
>  		}
>  	}
>  
> @@ -194,6 +215,14 @@ static int ptn5150_init_dev_type(struct ptn5150_info *info)
>  	return 0;
>  }
>  
> +static void ptn5150_put_role_sw(void *data)
> +{
> +	struct ptn5150_info *info = data;
> +
> +	cancel_work_sync(&info->irq_work);

This looks independent and should be executed always - even if getting
role_sw in probe does not succeed.

> +	usb_role_switch_put(info->role_sw);
> +}
> +



Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-06 10:15   ` Krzysztof Kozlowski
@ 2022-04-06 11:48     ` Jun Li
  2022-04-19  7:53       ` Jun Li
  0 siblings, 1 reply; 14+ messages in thread
From: Jun Li @ 2022-04-06 11:48 UTC (permalink / raw)
  To: Krzysztof Kozlowski, myungjoo.ham, cw00.choi
  Cc: linux-kernel, Frank Li, Xu Yang



> -----Original Message-----
> From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Sent: Wednesday, April 6, 2022 6:16 PM
> To: Jun Li <jun.li@nxp.com>; myungjoo.ham@samsung.com;
> cw00.choi@samsung.com
> Cc: linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
> <xu.yang_2@nxp.com>
> Subject: Re: [PATCH] extcon: ptn5150: add usb role class support
> 
> On 06/04/2022 11:42, Li Jun wrote:
> > Add support of usb role class consumer to do role switch.
> 
> Please mention also why you are doing this.

Will improve in v2.

> 
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >  drivers/extcon/Kconfig          |  1 +
> >  drivers/extcon/extcon-ptn5150.c | 39 +++++++++++++++++++++++++++++++++
> >  2 files changed, 40 insertions(+)
> >
> > diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> > index 0d42e49105dd..9828ade787a8 100644
> > --- a/drivers/extcon/Kconfig
> > +++ b/drivers/extcon/Kconfig
> > @@ -132,6 +132,7 @@ config EXTCON_PTN5150
> >  	tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
> >  	depends on I2C && (GPIOLIB || COMPILE_TEST)
> >  	select REGMAP_I2C
> > +	select USB_ROLE_SWITCH
> 
> You do not need to select it. Driver will work without role switch,
> won't it? If it works, then probably it should be just imply.

Okay, usb role class provider should enable this for me, will drop it.

> 
> >  	help
> >  	  Say Y here to enable support for USB peripheral and USB host
> >  	  detection by NXP PTN5150 CC (Configuration Channel) logic chip.
> > diff --git a/drivers/extcon/extcon-ptn5150.c
> b/drivers/extcon/extcon-ptn5150.c
> > index 5b9a3cf8df26..821b0f390308 100644
> > --- a/drivers/extcon/extcon-ptn5150.c
> > +++ b/drivers/extcon/extcon-ptn5150.c
> > @@ -17,6 +17,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/extcon-provider.h>
> >  #include <linux/gpio/consumer.h>
> > +#include <linux/usb/role.h>
> >
> >  /* PTN5150 registers */
> >  #define PTN5150_REG_DEVICE_ID			0x01
> > @@ -52,6 +53,7 @@ struct ptn5150_info {
> >  	int irq;
> >  	struct work_struct irq_work;
> >  	struct mutex mutex;
> > +	struct usb_role_switch *role_sw;
> >  };
> >
> >  /* List of detectable cables */
> > @@ -85,6 +87,12 @@ static void ptn5150_check_state(struct ptn5150_info
> *info)
> >  		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
> >  		gpiod_set_value_cansleep(info->vbus_gpiod, 0);
> >  		extcon_set_state_sync(info->edev, EXTCON_USB, true);
> > +
> > +		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_DEVICE);
> > +		if (ret)
> > +			dev_err(info->dev, "failed to set device role: %d\n",
> > +				ret);
> > +
> >  		break;
> >  	case PTN5150_UFP_ATTACHED:
> >  		extcon_set_state_sync(info->edev, EXTCON_USB, false);
> > @@ -95,6 +103,12 @@ static void ptn5150_check_state(struct ptn5150_info
> *info)
> >  			gpiod_set_value_cansleep(info->vbus_gpiod, 1);
> >
> >  		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
> > +
> > +		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_HOST);
> > +		if (ret)
> > +			dev_err(info->dev, "failed to set host role: %d\n",
> > +				ret);
> > +
> 
> 
> Instead of having usb_role_switch_set_role() in two places, how about:
> 1. setting local variable to USB_ROLE_HOST/USB_ROLE_NONE
> 2. return on default
> 3. one call to usb_role_switch_set_role() outside of the case?
> 
> Should create less code.

Yes, this will be better, I will update in v2.

> 
> >  		break;
> >  	default:
> >  		break;
> > @@ -133,6 +147,13 @@ static void ptn5150_irq_work(struct work_struct
> *work)
> >  			extcon_set_state_sync(info->edev,
> >  					EXTCON_USB, false);
> >  			gpiod_set_value_cansleep(info->vbus_gpiod, 0);
> > +
> > +			ret = usb_role_switch_set_role(info->role_sw,
> > +						       USB_ROLE_NONE);
> > +			if (ret)
> > +				dev_err(info->dev,
> > +					"failed to set none role: %d\n",
> > +					ret);
> >  		}
> >  	}
> >
> > @@ -194,6 +215,14 @@ static int ptn5150_init_dev_type(struct ptn5150_info
> *info)
> >  	return 0;
> >  }
> >
> > +static void ptn5150_put_role_sw(void *data)
> > +{
> > +	struct ptn5150_info *info = data;
> > +
> > +	cancel_work_sync(&info->irq_work);
> 
> This looks independent and should be executed always - even if getting
> role_sw in probe does not succeed.

Agreed, I will add one patch to make this action taken in all cases.

Thanks
Li Jun

> 
> > +	usb_role_switch_put(info->role_sw);
> > +}
> > +
> 
> 
> 
> Best regards,
> Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-06  9:42 ` [PATCH] extcon: ptn5150: add usb role class support Li Jun
  2022-04-06 10:15   ` Krzysztof Kozlowski
@ 2022-04-06 18:53   ` kernel test robot
  2022-04-07  2:17   ` Chanwoo Choi
  2 siblings, 0 replies; 14+ messages in thread
From: kernel test robot @ 2022-04-06 18:53 UTC (permalink / raw)
  To: Li Jun, myungjoo.ham, cw00.choi, krzk
  Cc: kbuild-all, linux-kernel, frank.li, xu.yang_2

Hi Li,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on chanwoo-extcon/extcon-next]
[also build test ERROR on v5.18-rc1 next-20220406]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Li-Jun/extcon-ptn5150-add-usb-role-class-support/20220406-212038
base:   https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git extcon-next
config: parisc-randconfig-r031-20220406 (https://download.01.org/0day-ci/archive/20220407/202204070226.kTAMpspa-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/beb6b76258bb1ae1e371486cd4fe97fee393ac83
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Li-Jun/extcon-ptn5150-add-usb-role-class-support/20220406-212038
        git checkout beb6b76258bb1ae1e371486cd4fe97fee393ac83
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=parisc SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   hppa-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_put_role_sw':
>> (.text+0x20): undefined reference to `usb_role_switch_put'
   hppa-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_check_state':
>> (.text+0xc8): undefined reference to `usb_role_switch_set_role'
>> hppa-linux-ld: (.text+0x11c): undefined reference to `usb_role_switch_set_role'
   hppa-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_irq_work':
   (.text+0x1f4): undefined reference to `usb_role_switch_set_role'
   hppa-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_i2c_probe':
>> (.text+0x4fc): undefined reference to `usb_role_switch_get'
>> hppa-linux-ld: (.text+0x53c): undefined reference to `usb_role_switch_put'

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for USB_ROLE_SWITCH
   Depends on USB_SUPPORT
   Selected by
   - EXTCON_PTN5150 && EXTCON && I2C && (GPIOLIB || COMPILE_TEST

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-06  9:42 ` [PATCH] extcon: ptn5150: add usb role class support Li Jun
  2022-04-06 10:15   ` Krzysztof Kozlowski
  2022-04-06 18:53   ` kernel test robot
@ 2022-04-07  2:17   ` Chanwoo Choi
  2022-04-19  7:48     ` Jun Li
  2 siblings, 1 reply; 14+ messages in thread
From: Chanwoo Choi @ 2022-04-07  2:17 UTC (permalink / raw)
  To: Li Jun, myungjoo.ham, krzk; +Cc: linux-kernel, frank.li, xu.yang_2

Hi, 

On 4/6/22 6:42 PM, Li Jun wrote:
> Add support of usb role class consumer to do role switch.
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> ---
>  drivers/extcon/Kconfig          |  1 +
>  drivers/extcon/extcon-ptn5150.c | 39 +++++++++++++++++++++++++++++++++
>  2 files changed, 40 insertions(+)
> 
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 0d42e49105dd..9828ade787a8 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -132,6 +132,7 @@ config EXTCON_PTN5150
>  	tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
>  	depends on I2C && (GPIOLIB || COMPILE_TEST)
>  	select REGMAP_I2C
> +	select USB_ROLE_SWITCH
>  	help
>  	  Say Y here to enable support for USB peripheral and USB host
>  	  detection by NXP PTN5150 CC (Configuration Channel) logic chip.
> diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
> index 5b9a3cf8df26..821b0f390308 100644
> --- a/drivers/extcon/extcon-ptn5150.c
> +++ b/drivers/extcon/extcon-ptn5150.c
> @@ -17,6 +17,7 @@
>  #include <linux/slab.h>
>  #include <linux/extcon-provider.h>
>  #include <linux/gpio/consumer.h>
> +#include <linux/usb/role.h>
>  
>  /* PTN5150 registers */
>  #define PTN5150_REG_DEVICE_ID			0x01
> @@ -52,6 +53,7 @@ struct ptn5150_info {
>  	int irq;
>  	struct work_struct irq_work;
>  	struct mutex mutex;
> +	struct usb_role_switch *role_sw;
>  };
>  
>  /* List of detectable cables */
> @@ -85,6 +87,12 @@ static void ptn5150_check_state(struct ptn5150_info *info)
>  		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
>  		gpiod_set_value_cansleep(info->vbus_gpiod, 0);
>  		extcon_set_state_sync(info->edev, EXTCON_USB, true);
> +
> +		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_DEVICE);
> +		if (ret)
> +			dev_err(info->dev, "failed to set device role: %d\n",
> +				ret);

> +
>  		break;
>  	case PTN5150_UFP_ATTACHED:
>  		extcon_set_state_sync(info->edev, EXTCON_USB, false);
> @@ -95,6 +103,12 @@ static void ptn5150_check_state(struct ptn5150_info *info)
>  			gpiod_set_value_cansleep(info->vbus_gpiod, 1);
>  
>  		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
> +
> +		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_HOST);
> +		if (ret)
> +			dev_err(info->dev, "failed to set host role: %d\n",
> +				ret);
> +
>  		break;
>  	default:
>  		break;
> @@ -133,6 +147,13 @@ static void ptn5150_irq_work(struct work_struct *work)
>  			extcon_set_state_sync(info->edev,
>  					EXTCON_USB, false);
>  			gpiod_set_value_cansleep(info->vbus_gpiod, 0);
> +
> +			ret = usb_role_switch_set_role(info->role_sw,
> +						       USB_ROLE_NONE);
> +			if (ret)
> +				dev_err(info->dev,
> +					"failed to set none role: %d\n",
> +					ret);
>  		}
>  	}
>  
> @@ -194,6 +215,14 @@ static int ptn5150_init_dev_type(struct ptn5150_info *info)
>  	return 0;
>  }
>  
> +static void ptn5150_put_role_sw(void *data)
> +{
> +	struct ptn5150_info *info = data;
> +
> +	cancel_work_sync(&info->irq_work);
> +	usb_role_switch_put(info->role_sw);
> +}
> +
>  static int ptn5150_i2c_probe(struct i2c_client *i2c)
>  {
>  	struct device *dev = &i2c->dev;
> @@ -284,6 +313,16 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)
>  	if (ret)
>  		return -EINVAL;
>  
> +	info->role_sw = usb_role_switch_get(info->dev);
> +	if (IS_ERR(info->role_sw))
> +		return PTR_ERR(info->role_sw);

If usb_role_switch is optional, you don't need to return error
when usb_role_switch_get returns error. Because 'usb_role_switch_set_role'
on this patch doesn't break the sequence. Just print the error log if error case.

> +
> +	if (info->role_sw) {
> +		ret = devm_add_action_or_reset(dev, ptn5150_put_role_sw, info);
> +		if (ret)
> +			return ret;
> +	}
> +
>  	/*
>  	 * Update current extcon state if for example OTG connection was there
>  	 * before the probe
> 


-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-07  2:17   ` Chanwoo Choi
@ 2022-04-19  7:48     ` Jun Li
  0 siblings, 0 replies; 14+ messages in thread
From: Jun Li @ 2022-04-19  7:48 UTC (permalink / raw)
  To: Chanwoo Choi, myungjoo.ham, krzk; +Cc: linux-kernel, Frank Li, Xu Yang

Hi

> -----Original Message-----
> From: Chanwoo Choi <cw00.choi@samsung.com>
> Sent: Thursday, April 7, 2022 10:18 AM
> To: Jun Li <jun.li@nxp.com>; myungjoo.ham@samsung.com; krzk@kernel.org
> Cc: linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
> <xu.yang_2@nxp.com>
> Subject: Re: [PATCH] extcon: ptn5150: add usb role class support
> 
> Hi,
> 
> On 4/6/22 6:42 PM, Li Jun wrote:
> > Add support of usb role class consumer to do role switch.
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> >  drivers/extcon/Kconfig          |  1 +
> >  drivers/extcon/extcon-ptn5150.c | 39
> > +++++++++++++++++++++++++++++++++
> >  2 files changed, 40 insertions(+)
> >
> > diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index
> > 0d42e49105dd..9828ade787a8 100644
> > --- a/drivers/extcon/Kconfig
> > +++ b/drivers/extcon/Kconfig
> > @@ -132,6 +132,7 @@ config EXTCON_PTN5150
> >  	tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
> >  	depends on I2C && (GPIOLIB || COMPILE_TEST)
> >  	select REGMAP_I2C
> > +	select USB_ROLE_SWITCH
> >  	help
> >  	  Say Y here to enable support for USB peripheral and USB host
> >  	  detection by NXP PTN5150 CC (Configuration Channel) logic chip.
> > diff --git a/drivers/extcon/extcon-ptn5150.c
> > b/drivers/extcon/extcon-ptn5150.c index 5b9a3cf8df26..821b0f390308
> > 100644
> > --- a/drivers/extcon/extcon-ptn5150.c
> > +++ b/drivers/extcon/extcon-ptn5150.c
> > @@ -17,6 +17,7 @@
> >  #include <linux/slab.h>
> >  #include <linux/extcon-provider.h>
> >  #include <linux/gpio/consumer.h>
> > +#include <linux/usb/role.h>
> >
> >  /* PTN5150 registers */
> >  #define PTN5150_REG_DEVICE_ID			0x01
> > @@ -52,6 +53,7 @@ struct ptn5150_info {
> >  	int irq;
> >  	struct work_struct irq_work;
> >  	struct mutex mutex;
> > +	struct usb_role_switch *role_sw;
> >  };
> >
> >  /* List of detectable cables */
> > @@ -85,6 +87,12 @@ static void ptn5150_check_state(struct ptn5150_info
> *info)
> >  		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
> >  		gpiod_set_value_cansleep(info->vbus_gpiod, 0);
> >  		extcon_set_state_sync(info->edev, EXTCON_USB, true);
> > +
> > +		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_DEVICE);
> > +		if (ret)
> > +			dev_err(info->dev, "failed to set device role: %d\n",
> > +				ret);
> 
> > +
> >  		break;
> >  	case PTN5150_UFP_ATTACHED:
> >  		extcon_set_state_sync(info->edev, EXTCON_USB, false); @@ -95,6
> > +103,12 @@ static void ptn5150_check_state(struct ptn5150_info *info)
> >  			gpiod_set_value_cansleep(info->vbus_gpiod, 1);
> >
> >  		extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
> > +
> > +		ret = usb_role_switch_set_role(info->role_sw, USB_ROLE_HOST);
> > +		if (ret)
> > +			dev_err(info->dev, "failed to set host role: %d\n",
> > +				ret);
> > +
> >  		break;
> >  	default:
> >  		break;
> > @@ -133,6 +147,13 @@ static void ptn5150_irq_work(struct work_struct
> *work)
> >  			extcon_set_state_sync(info->edev,
> >  					EXTCON_USB, false);
> >  			gpiod_set_value_cansleep(info->vbus_gpiod, 0);
> > +
> > +			ret = usb_role_switch_set_role(info->role_sw,
> > +						       USB_ROLE_NONE);
> > +			if (ret)
> > +				dev_err(info->dev,
> > +					"failed to set none role: %d\n",
> > +					ret);
> >  		}
> >  	}
> >
> > @@ -194,6 +215,14 @@ static int ptn5150_init_dev_type(struct ptn5150_info
> *info)
> >  	return 0;
> >  }
> >
> > +static void ptn5150_put_role_sw(void *data) {
> > +	struct ptn5150_info *info = data;
> > +
> > +	cancel_work_sync(&info->irq_work);
> > +	usb_role_switch_put(info->role_sw);
> > +}
> > +
> >  static int ptn5150_i2c_probe(struct i2c_client *i2c)  {
> >  	struct device *dev = &i2c->dev;
> > @@ -284,6 +313,16 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)
> >  	if (ret)
> >  		return -EINVAL;
> >
> > +	info->role_sw = usb_role_switch_get(info->dev);
> > +	if (IS_ERR(info->role_sw))
> > +		return PTR_ERR(info->role_sw);
> 
> If usb_role_switch is optional, you don't need to return error when
> usb_role_switch_get returns error. Because 'usb_role_switch_set_role'
> on this patch doesn't break the sequence. Just print the error log if error
> case.

Yes, it's optional, if the usb role switch is not provided, then
usb_role_switch_get() will return NULL, then usb role switch will
do nothing;
if the usb role switch is provided(intended to use) but there is
something wrong to get it, we must return error to force a failure
in probe(including probe defer).

Li Jun
> 
> > +
> > +	if (info->role_sw) {
> > +		ret = devm_add_action_or_reset(dev, ptn5150_put_role_sw, info);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> >  	/*
> >  	 * Update current extcon state if for example OTG connection was there
> >  	 * before the probe
> >
> 
> 
> --
> Best Regards,
> Chanwoo Choi
> Samsung Electronics

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-06 11:48     ` Jun Li
@ 2022-04-19  7:53       ` Jun Li
  2022-04-19  7:56         ` Krzysztof Kozlowski
  0 siblings, 1 reply; 14+ messages in thread
From: Jun Li @ 2022-04-19  7:53 UTC (permalink / raw)
  To: Krzysztof Kozlowski, myungjoo.ham, cw00.choi
  Cc: linux-kernel, Frank Li, Xu Yang



> -----Original Message-----
> From: Jun Li
> Sent: Wednesday, April 6, 2022 7:49 PM
> To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>;
> myungjoo.ham@samsung.com; cw00.choi@samsung.com
> Cc: linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
> <xu.yang_2@nxp.com>
> Subject: RE: [PATCH] extcon: ptn5150: add usb role class support
> 
> 
> 
> > -----Original Message-----
> > From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> > Sent: Wednesday, April 6, 2022 6:16 PM
> > To: Jun Li <jun.li@nxp.com>; myungjoo.ham@samsung.com;
> > cw00.choi@samsung.com
> > Cc: linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
> > <xu.yang_2@nxp.com>
> > Subject: Re: [PATCH] extcon: ptn5150: add usb role class support
> >
> > On 06/04/2022 11:42, Li Jun wrote:
> > > Add support of usb role class consumer to do role switch.
> >
> > Please mention also why you are doing this.
> 
> Will improve in v2.
> 
> >
> > >
> > > Signed-off-by: Li Jun <jun.li@nxp.com>
> > > ---
> > >  drivers/extcon/Kconfig          |  1 +
> > >  drivers/extcon/extcon-ptn5150.c | 39
> > > +++++++++++++++++++++++++++++++++
> > >  2 files changed, 40 insertions(+)
> > >
> > > diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index
> > > 0d42e49105dd..9828ade787a8 100644
> > > --- a/drivers/extcon/Kconfig
> > > +++ b/drivers/extcon/Kconfig
> > > @@ -132,6 +132,7 @@ config EXTCON_PTN5150
> > >  	tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
> > >  	depends on I2C && (GPIOLIB || COMPILE_TEST)
> > >  	select REGMAP_I2C
> > > +	select USB_ROLE_SWITCH
> >
> > You do not need to select it. Driver will work without role switch,
> > won't it? If it works, then probably it should be just imply.
> 
> Okay, usb role class provider should enable this for me, will drop it.

A second check on this and I think I still need this, there
maybe some usb controller driver without usb role switch
+ ptn5150 via extcon, so no need USB_ROLE_SWITCH, I need
select it to avoid build break.

Li Jun

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-19  7:53       ` Jun Li
@ 2022-04-19  7:56         ` Krzysztof Kozlowski
  2022-04-19  8:23           ` Jun Li
  0 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-19  7:56 UTC (permalink / raw)
  To: Jun Li; +Cc: myungjoo.ham, cw00.choi, linux-kernel, Frank Li, Xu Yang

On Tue, 19 Apr 2022 at 09:53, Jun Li <jun.li@nxp.com> wrote:
> > > > @@ -132,6 +132,7 @@ config EXTCON_PTN5150
> > > >   tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
> > > >   depends on I2C && (GPIOLIB || COMPILE_TEST)
> > > >   select REGMAP_I2C
> > > > + select USB_ROLE_SWITCH
> > >
> > > You do not need to select it. Driver will work without role switch,
> > > won't it? If it works, then probably it should be just imply.
> >
> > Okay, usb role class provider should enable this for me, will drop it.
>
> A second check on this and I think I still need this, there
> maybe some usb controller driver without usb role switch
> + ptn5150 via extcon, so no need USB_ROLE_SWITCH, I need
> select it to avoid build break.

What build problem exactly? Aren't there stubs for !USB_ROLE_SWITCH case?

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-19  7:56         ` Krzysztof Kozlowski
@ 2022-04-19  8:23           ` Jun Li
  2022-04-19  8:29             ` Krzysztof Kozlowski
  0 siblings, 1 reply; 14+ messages in thread
From: Jun Li @ 2022-04-19  8:23 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: myungjoo.ham, cw00.choi, linux-kernel, Frank Li, Xu Yang



> -----Original Message-----
> From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Sent: Tuesday, April 19, 2022 3:57 PM
> To: Jun Li <jun.li@nxp.com>
> Cc: myungjoo.ham@samsung.com; cw00.choi@samsung.com;
> linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
> <xu.yang_2@nxp.com>
> Subject: Re: [PATCH] extcon: ptn5150: add usb role class support
> 
> On Tue, 19 Apr 2022 at 09:53, Jun Li <jun.li@nxp.com> wrote:
> > > > > @@ -132,6 +132,7 @@ config EXTCON_PTN5150
> > > > >   tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
> > > > >   depends on I2C && (GPIOLIB || COMPILE_TEST)
> > > > >   select REGMAP_I2C
> > > > > + select USB_ROLE_SWITCH
> > > >
> > > > You do not need to select it. Driver will work without role
> > > > switch, won't it? If it works, then probably it should be just imply.
> > >
> > > Okay, usb role class provider should enable this for me, will drop it.
> >
> > A second check on this and I think I still need this, there maybe some
> > usb controller driver without usb role switch
> > + ptn5150 via extcon, so no need USB_ROLE_SWITCH, I need
> > select it to avoid build break.
> 
> What build problem exactly? Aren't there stubs for !USB_ROLE_SWITCH case?

Mostly cases USB_ROLE_SWITCH is enabled, but I cannot 100% ensure
that, at least I can via make menuconfig change by removing some
controllers drivers to create a config to generate a build break:

/opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_work_sync_and_put':
extcon-ptn5150.c:(.text+0x20): undefined reference to `usb_role_switch_put'
/opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_check_state':
extcon-ptn5150.c:(.text+0xc8): undefined reference to `usb_role_switch_set_role'
/opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld: extcon-ptn5150.c:(.text+0x138): undefined reference to `usb_role_switch_set_role'
/opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld: extcon-ptn5150.c:(.text+0x14c): undefined reference to `usb_role_string'
/opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_irq_work':
extcon-ptn5150.c:(.text+0x290): undefined reference to `usb_role_switch_set_role'
/opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_i2c_probe':
extcon-ptn5150.c:(.text+0x4f4): undefined reference to `usb_role_switch_get'
/opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld: extcon-ptn5150.c:(.text+0x530): undefined reference to `usb_role_switch_put'
make: *** [Makefile:1247: vmlinux] Error 1

thanks
Li Jun

> 
> Best regards,
> Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-19  8:23           ` Jun Li
@ 2022-04-19  8:29             ` Krzysztof Kozlowski
  2022-04-19  8:51               ` Jun Li
  0 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-19  8:29 UTC (permalink / raw)
  To: Jun Li; +Cc: myungjoo.ham, cw00.choi, linux-kernel, Frank Li, Xu Yang

On 19/04/2022 10:23, Jun Li wrote:
> 
> 
>> -----Original Message-----
>> From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>> Sent: Tuesday, April 19, 2022 3:57 PM
>> To: Jun Li <jun.li@nxp.com>
>> Cc: myungjoo.ham@samsung.com; cw00.choi@samsung.com;
>> linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
>> <xu.yang_2@nxp.com>
>> Subject: Re: [PATCH] extcon: ptn5150: add usb role class support
>>
>> On Tue, 19 Apr 2022 at 09:53, Jun Li <jun.li@nxp.com> wrote:
>>>>>> @@ -132,6 +132,7 @@ config EXTCON_PTN5150
>>>>>>   tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
>>>>>>   depends on I2C && (GPIOLIB || COMPILE_TEST)
>>>>>>   select REGMAP_I2C
>>>>>> + select USB_ROLE_SWITCH
>>>>>
>>>>> You do not need to select it. Driver will work without role
>>>>> switch, won't it? If it works, then probably it should be just imply.
>>>>
>>>> Okay, usb role class provider should enable this for me, will drop it.
>>>
>>> A second check on this and I think I still need this, there maybe some
>>> usb controller driver without usb role switch
>>> + ptn5150 via extcon, so no need USB_ROLE_SWITCH, I need
>>> select it to avoid build break.
>>
>> What build problem exactly? Aren't there stubs for !USB_ROLE_SWITCH case?
> 
> Mostly cases USB_ROLE_SWITCH is enabled, but I cannot 100% ensure
> that, at least I can via make menuconfig change by removing some
> controllers drivers to create a config to generate a build break:
> 
> /opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld: drivers/extcon/extcon-ptn5150.o: in function `ptn5150_work_sync_and_put':
> extcon-ptn5150.c:(.text+0x20): undefined reference to `usb_role_switch_put'

This is some old kernel - v5.15. Please test your changes on mainline. I
don't see such issue can happen on a recent kernel - there is an EXPORT
and a stub. Maybe your driver misses proper headers?

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-19  8:29             ` Krzysztof Kozlowski
@ 2022-04-19  8:51               ` Jun Li
  2022-04-19  9:12                 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 14+ messages in thread
From: Jun Li @ 2022-04-19  8:51 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: myungjoo.ham, cw00.choi, linux-kernel, Frank Li, Xu Yang



> -----Original Message-----
> From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Sent: Tuesday, April 19, 2022 4:30 PM
> To: Jun Li <jun.li@nxp.com>
> Cc: myungjoo.ham@samsung.com; cw00.choi@samsung.com;
> linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
> <xu.yang_2@nxp.com>
> Subject: Re: [PATCH] extcon: ptn5150: add usb role class support
> 
> On 19/04/2022 10:23, Jun Li wrote:
> >
> >
> >> -----Original Message-----
> >> From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> >> Sent: Tuesday, April 19, 2022 3:57 PM
> >> To: Jun Li <jun.li@nxp.com>
> >> Cc: myungjoo.ham@samsung.com; cw00.choi@samsung.com;
> >> linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
> >> <xu.yang_2@nxp.com>
> >> Subject: Re: [PATCH] extcon: ptn5150: add usb role class support
> >>
> >> On Tue, 19 Apr 2022 at 09:53, Jun Li <jun.li@nxp.com> wrote:
> >>>>>> @@ -132,6 +132,7 @@ config EXTCON_PTN5150
> >>>>>>   tristate "NXP PTN5150 CC LOGIC USB EXTCON support"
> >>>>>>   depends on I2C && (GPIOLIB || COMPILE_TEST)
> >>>>>>   select REGMAP_I2C
> >>>>>> + select USB_ROLE_SWITCH
> >>>>>
> >>>>> You do not need to select it. Driver will work without role
> >>>>> switch, won't it? If it works, then probably it should be just imply.
> >>>>
> >>>> Okay, usb role class provider should enable this for me, will drop it.
> >>>
> >>> A second check on this and I think I still need this, there maybe
> >>> some usb controller driver without usb role switch
> >>> + ptn5150 via extcon, so no need USB_ROLE_SWITCH, I need
> >>> select it to avoid build break.
> >>
> >> What build problem exactly? Aren't there stubs for !USB_ROLE_SWITCH case?
> >
> > Mostly cases USB_ROLE_SWITCH is enabled, but I cannot 100% ensure
> > that, at least I can via make menuconfig change by removing some
> > controllers drivers to create a config to generate a build break:
> >
> >
> /opt/fsl-imx-internal-xwayland/5.15-honister/sysroots/x86_64-pokysdk-li
> nux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-ld:
> drivers/extcon/extcon-ptn5150.o: in function `ptn5150_work_sync_and_put':
> > extcon-ptn5150.c:(.text+0x20): undefined reference to
> `usb_role_switch_put'
> 
> This is some old kernel - v5.15. Please test your changes on mainline. I
> don't see such issue can happen on a recent kernel - there is an EXPORT and
> a stub. Maybe your driver misses proper headers?

I am working on Linux-next 20220414

commit 40354149f4d738dc3492d9998e45b3f02950369a (tag: next-20220414, origin/master, origin/HEAD)
Author: Stephen Rothwell <sfr@canb.auug.org.au>
Date:   Thu Apr 14 15:22:31 2022 +1000

    Add linux-next specific files for 20220414
    
    Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>

My test config is making USB_ROLE_SWITCH=m, but PTN5150=y

So with below header file: 

#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
void usb_role_switch_put(struct usb_role_switch *sw);
#else
static inline void usb_role_switch_put(struct usb_role_switch *sw) { }
#endif

Will have link error.

Thanks
Li Jun
> 
> Best regards,
> Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-19  8:51               ` Jun Li
@ 2022-04-19  9:12                 ` Krzysztof Kozlowski
  2022-04-19  9:52                   ` Krzysztof Kozlowski
  0 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-19  9:12 UTC (permalink / raw)
  To: Jun Li; +Cc: myungjoo.ham, cw00.choi, linux-kernel, Frank Li, Xu Yang

On 19/04/2022 10:51, Jun Li wrote:
> My test config is making USB_ROLE_SWITCH=m, but PTN5150=y
> 
> So with below header file: 
> 
> #if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
> void usb_role_switch_put(struct usb_role_switch *sw);
> #else
> static inline void usb_role_switch_put(struct usb_role_switch *sw) { }
> #endif
> 
> Will have link error.

Yep, true. I cannot remember the solution for that... With the select
you cannot disable USB_ROLE_SWITCH. With "depends on X || depends on
!X", one still cannot disable USB_ROLE_SWITCH. However this is a common
problem and I am pretty sure people were working on this. :)

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-19  9:12                 ` Krzysztof Kozlowski
@ 2022-04-19  9:52                   ` Krzysztof Kozlowski
  2022-04-19 10:00                     ` Jun Li
  0 siblings, 1 reply; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-19  9:52 UTC (permalink / raw)
  To: Jun Li; +Cc: myungjoo.ham, cw00.choi, linux-kernel, Frank Li, Xu Yang

On 19/04/2022 11:12, Krzysztof Kozlowski wrote:
> On 19/04/2022 10:51, Jun Li wrote:
>> My test config is making USB_ROLE_SWITCH=m, but PTN5150=y
>>
>> So with below header file: 
>>
>> #if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
>> void usb_role_switch_put(struct usb_role_switch *sw);
>> #else
>> static inline void usb_role_switch_put(struct usb_role_switch *sw) { }
>> #endif
>>
>> Will have link error.
> 
> Yep, true. I cannot remember the solution for that... With the select
> you cannot disable USB_ROLE_SWITCH. With "depends on X || depends on
> !X", one still cannot disable USB_ROLE_SWITCH. However this is a common
> problem and I am pretty sure people were working on this. :)

Use:
depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH'

this should solve the problem.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH] extcon: ptn5150: add usb role class support
  2022-04-19  9:52                   ` Krzysztof Kozlowski
@ 2022-04-19 10:00                     ` Jun Li
  0 siblings, 0 replies; 14+ messages in thread
From: Jun Li @ 2022-04-19 10:00 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: myungjoo.ham, cw00.choi, linux-kernel, Frank Li, Xu Yang



> -----Original Message-----
> From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Sent: Tuesday, April 19, 2022 5:52 PM
> To: Jun Li <jun.li@nxp.com>
> Cc: myungjoo.ham@samsung.com; cw00.choi@samsung.com;
> linux-kernel@vger.kernel.org; Frank Li <frank.li@nxp.com>; Xu Yang
> <xu.yang_2@nxp.com>
> Subject: Re: [PATCH] extcon: ptn5150: add usb role class support
> 
> On 19/04/2022 11:12, Krzysztof Kozlowski wrote:
> > On 19/04/2022 10:51, Jun Li wrote:
> >> My test config is making USB_ROLE_SWITCH=m, but PTN5150=y
> >>
> >> So with below header file:
> >>
> >> #if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
> >> void usb_role_switch_put(struct usb_role_switch *sw); #else static
> >> inline void usb_role_switch_put(struct usb_role_switch *sw) { }
> >> #endif
> >>
> >> Will have link error.
> >
> > Yep, true. I cannot remember the solution for that... With the select
> > you cannot disable USB_ROLE_SWITCH. With "depends on X || depends on
> > !X", one still cannot disable USB_ROLE_SWITCH. However this is a
> > common problem and I am pretty sure people were working on this. :)
> 
> Use:
> depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH'
> 
> this should solve the problem.

This works, thanks for the review and suggestion, I will send out v3.

Li Jun
> 
> Best regards,
> Krzysztof

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-04-19 10:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20220406131913epcas1p485cd66f0f208031dc93579158e95be18@epcas1p4.samsung.com>
2022-04-06  9:42 ` [PATCH] extcon: ptn5150: add usb role class support Li Jun
2022-04-06 10:15   ` Krzysztof Kozlowski
2022-04-06 11:48     ` Jun Li
2022-04-19  7:53       ` Jun Li
2022-04-19  7:56         ` Krzysztof Kozlowski
2022-04-19  8:23           ` Jun Li
2022-04-19  8:29             ` Krzysztof Kozlowski
2022-04-19  8:51               ` Jun Li
2022-04-19  9:12                 ` Krzysztof Kozlowski
2022-04-19  9:52                   ` Krzysztof Kozlowski
2022-04-19 10:00                     ` Jun Li
2022-04-06 18:53   ` kernel test robot
2022-04-07  2:17   ` Chanwoo Choi
2022-04-19  7:48     ` Jun Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.