diff mbox series

[1/2] phy: introduce phy mode PHY_MODE_UART and phy_get_mode_ext()

Message ID 1627383013-4535-1-git-send-email-macpaul.lin@mediatek.com
State Changes Requested
Headers show
Series [1/2] phy: introduce phy mode PHY_MODE_UART and phy_get_mode_ext() | expand

Commit Message

Macpaul Lin July 27, 2021, 10:50 a.m. UTC
Some embedded platform shared PINs between USB and UART.

For example, some phone will use special cable detection in boot loader
to switch USB port function into UART mode. Hence Kernel need to query
the hardware state from PHY registers to confirm the initialzation flow
for PHY and USB driver.

To support this kind of PIN switch, new PHY MODE and query API is
required. Here we introduce a new PHY mode: PHY_MODE_UART.

API phy_get_mode_ext() can be used to query the MODE from hardware
instead of reading it from phy attributes.

Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
---
 drivers/phy/phy-core.c  |   17 +++++++++++++++++
 include/linux/phy/phy.h |    3 +++
 2 files changed, 20 insertions(+)

Comments

kernel test robot July 27, 2021, 1:33 p.m. UTC | #1
Hi Macpaul,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.14-rc3 next-20210726]
[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/0day-ci/linux/commits/Macpaul-Lin/phy-introduce-phy-mode-PHY_MODE_UART-and-phy_get_mode_ext/20210727-185332
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ff1176468d368232b684f75e82563369208bc371
config: mips-randconfig-s031-20210727 (attached as .config)
compiler: mips-linux-gcc (GCC) 10.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/fa58db3bf0689ed034e7871c053bfd65592b486e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Macpaul-Lin/phy-introduce-phy-mode-PHY_MODE_UART-and-phy_get_mode_ext/20210727-185332
        git checkout fa58db3bf0689ed034e7871c053bfd65592b486e
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=mips 

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

All warnings (new ones prefixed by >>):

>> drivers/phy/phy-core.c:376:5: warning: no previous prototype for 'phy_get_mode_ext' [-Wmissing-prototypes]
     376 | int phy_get_mode_ext(struct phy *phy)
         |     ^~~~~~~~~~~~~~~~


vim +/phy_get_mode_ext +376 drivers/phy/phy-core.c

   375	
 > 376	int phy_get_mode_ext(struct phy *phy)
   377	{
   378		int ret;
   379	
   380		if (!phy || !phy->ops->get_mode_ext)
   381			return 0;
   382	
   383		mutex_lock(&phy->mutex);
   384		ret = phy->ops->get_mode_ext(phy);
   385		if (!ret)
   386			ret = phy->attrs.mode;
   387		mutex_unlock(&phy->mutex);
   388	
   389		return ret;
   390	}
   391	EXPORT_SYMBOL_GPL(phy_get_mode_ext);
   392	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot July 27, 2021, 3:48 p.m. UTC | #2
Hi Macpaul,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.14-rc3 next-20210726]
[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/0day-ci/linux/commits/Macpaul-Lin/phy-introduce-phy-mode-PHY_MODE_UART-and-phy_get_mode_ext/20210727-185332
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ff1176468d368232b684f75e82563369208bc371
config: x86_64-randconfig-c001-20210727 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project c658b472f3e61e1818e1909bf02f3d65470018a5)
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
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/fa58db3bf0689ed034e7871c053bfd65592b486e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Macpaul-Lin/phy-introduce-phy-mode-PHY_MODE_UART-and-phy_get_mode_ext/20210727-185332
        git checkout fa58db3bf0689ed034e7871c053bfd65592b486e
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

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

All warnings (new ones prefixed by >>):

>> drivers/phy/phy-core.c:376:5: warning: no previous prototype for function 'phy_get_mode_ext' [-Wmissing-prototypes]
   int phy_get_mode_ext(struct phy *phy)
       ^
   drivers/phy/phy-core.c:376:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int phy_get_mode_ext(struct phy *phy)
   ^
   static 
   1 warning generated.


vim +/phy_get_mode_ext +376 drivers/phy/phy-core.c

   375	
 > 376	int phy_get_mode_ext(struct phy *phy)
   377	{
   378		int ret;
   379	
   380		if (!phy || !phy->ops->get_mode_ext)
   381			return 0;
   382	
   383		mutex_lock(&phy->mutex);
   384		ret = phy->ops->get_mode_ext(phy);
   385		if (!ret)
   386			ret = phy->attrs.mode;
   387		mutex_unlock(&phy->mutex);
   388	
   389		return ret;
   390	}
   391	EXPORT_SYMBOL_GPL(phy_get_mode_ext);
   392	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot July 27, 2021, 3:48 p.m. UTC | #3
Hi Macpaul,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.14-rc3 next-20210726]
[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/0day-ci/linux/commits/Macpaul-Lin/phy-introduce-phy-mode-PHY_MODE_UART-and-phy_get_mode_ext/20210727-185332
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git ff1176468d368232b684f75e82563369208bc371
config: x86_64-randconfig-a003-20210727 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project c658b472f3e61e1818e1909bf02f3d65470018a5)
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
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/fa58db3bf0689ed034e7871c053bfd65592b486e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Macpaul-Lin/phy-introduce-phy-mode-PHY_MODE_UART-and-phy_get_mode_ext/20210727-185332
        git checkout fa58db3bf0689ed034e7871c053bfd65592b486e
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

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

All warnings (new ones prefixed by >>):

>> drivers/phy/phy-core.c:376:5: warning: no previous prototype for function 'phy_get_mode_ext' [-Wmissing-prototypes]
   int phy_get_mode_ext(struct phy *phy)
       ^
   drivers/phy/phy-core.c:376:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   int phy_get_mode_ext(struct phy *phy)
   ^
   static 
   1 warning generated.


vim +/phy_get_mode_ext +376 drivers/phy/phy-core.c

   375	
 > 376	int phy_get_mode_ext(struct phy *phy)
   377	{
   378		int ret;
   379	
   380		if (!phy || !phy->ops->get_mode_ext)
   381			return 0;
   382	
   383		mutex_lock(&phy->mutex);
   384		ret = phy->ops->get_mode_ext(phy);
   385		if (!ret)
   386			ret = phy->attrs.mode;
   387		mutex_unlock(&phy->mutex);
   388	
   389		return ret;
   390	}
   391	EXPORT_SYMBOL_GPL(phy_get_mode_ext);
   392	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Chunfeng Yun July 28, 2021, 1:35 a.m. UTC | #4
On Tue, 2021-07-27 at 18:50 +0800, Macpaul Lin wrote:
> Some embedded platform shared PINs between USB and UART.
> 
> For example, some phone will use special cable detection in boot loader
> to switch USB port function into UART mode. Hence Kernel need to query
> the hardware state from PHY registers to confirm the initialzation flow
> for PHY and USB driver.
> 
> To support this kind of PIN switch, new PHY MODE and query API is
> required. Here we introduce a new PHY mode: PHY_MODE_UART.
> 
> API phy_get_mode_ext() can be used to query the MODE from hardware
> instead of reading it from phy attributes.
> 
> Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
> ---
>  drivers/phy/phy-core.c  |   17 +++++++++++++++++
>  include/linux/phy/phy.h |    3 +++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index ccb575b..b8f6539 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -373,6 +373,23 @@ int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode)
>  }
>  EXPORT_SYMBOL_GPL(phy_set_mode_ext);
>  
> +int phy_get_mode_ext(struct phy *phy)
> +{
> +	int ret;
> +
> +	if (!phy || !phy->ops->get_mode_ext)
> +		return 0;
> +
> +	mutex_lock(&phy->mutex);
> +	ret = phy->ops->get_mode_ext(phy);
> +	if (!ret)
> +		ret = phy->attrs.mode;
> +	mutex_unlock(&phy->mutex);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(phy_get_mode_ext);
> +
>  int phy_set_media(struct phy *phy, enum phy_media media)
>  {
>  	int ret;
> diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
> index 0ed434d..7d32c6b 100644
> --- a/include/linux/phy/phy.h
> +++ b/include/linux/phy/phy.h
> @@ -34,6 +34,7 @@ enum phy_mode {
>  	PHY_MODE_USB_DEVICE_HS,
>  	PHY_MODE_USB_DEVICE_SS,
>  	PHY_MODE_USB_OTG,
> +	PHY_MODE_UART,
>  	PHY_MODE_UFS_HS_A,
>  	PHY_MODE_UFS_HS_B,
>  	PHY_MODE_PCIE,
> @@ -70,6 +71,7 @@ enum phy_media {
>   * @power_on: powering on the phy
>   * @power_off: powering off the phy
>   * @set_mode: set the mode of the phy
> + * @get_mode_ext: get the extented mode of the phy
>   * @set_media: set the media type of the phy (optional)
>   * @set_speed: set the speed of the phy (optional)
>   * @reset: resetting the phy
> @@ -83,6 +85,7 @@ struct phy_ops {
>  	int	(*power_on)(struct phy *phy);
>  	int	(*power_off)(struct phy *phy);
>  	int	(*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
> +	int	(*get_mode_ext)(struct phy *phy);
>  	int	(*set_media)(struct phy *phy, enum phy_media media);
>  	int	(*set_speed)(struct phy *phy, int speed);
>  
add prototype of phy_get_mode_ext(struct phy *phy) for both cases that
CONFIG_GENERIC_PHY is enabled or not in linux/phy/phy.h
diff mbox series

Patch

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index ccb575b..b8f6539 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -373,6 +373,23 @@  int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode)
 }
 EXPORT_SYMBOL_GPL(phy_set_mode_ext);
 
+int phy_get_mode_ext(struct phy *phy)
+{
+	int ret;
+
+	if (!phy || !phy->ops->get_mode_ext)
+		return 0;
+
+	mutex_lock(&phy->mutex);
+	ret = phy->ops->get_mode_ext(phy);
+	if (!ret)
+		ret = phy->attrs.mode;
+	mutex_unlock(&phy->mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(phy_get_mode_ext);
+
 int phy_set_media(struct phy *phy, enum phy_media media)
 {
 	int ret;
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 0ed434d..7d32c6b 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -34,6 +34,7 @@  enum phy_mode {
 	PHY_MODE_USB_DEVICE_HS,
 	PHY_MODE_USB_DEVICE_SS,
 	PHY_MODE_USB_OTG,
+	PHY_MODE_UART,
 	PHY_MODE_UFS_HS_A,
 	PHY_MODE_UFS_HS_B,
 	PHY_MODE_PCIE,
@@ -70,6 +71,7 @@  enum phy_media {
  * @power_on: powering on the phy
  * @power_off: powering off the phy
  * @set_mode: set the mode of the phy
+ * @get_mode_ext: get the extented mode of the phy
  * @set_media: set the media type of the phy (optional)
  * @set_speed: set the speed of the phy (optional)
  * @reset: resetting the phy
@@ -83,6 +85,7 @@  struct phy_ops {
 	int	(*power_on)(struct phy *phy);
 	int	(*power_off)(struct phy *phy);
 	int	(*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
+	int	(*get_mode_ext)(struct phy *phy);
 	int	(*set_media)(struct phy *phy, enum phy_media media);
 	int	(*set_speed)(struct phy *phy, int speed);