RE: [PATCH v3 6/6] phy: cadence-torrent: Add support to drive refclk out

2021-03-14 Thread Swapnil Kashinath Jakhade



> -Original Message-
> From: Kishon Vijay Abraham I 
> Sent: Wednesday, March 10, 2021 5:39 PM
> To: Kishon Vijay Abraham I ; Vinod Koul
> ; Swapnil Kashinath Jakhade 
> Cc: linux-kernel@vger.kernel.org; linux-...@lists.infradead.org; Lokesh
> Vutla 
> Subject: [PATCH v3 6/6] phy: cadence-torrent: Add support to drive refclk out
> 
> EXTERNAL MAIL
> 
> 
> cmn_refclk_ lines in Torrent SERDES is used for connecting external
> reference clock. cmn_refclk_ can also be configured to output the
> reference clock. Model this derived reference clock as a "clock" so that
> platforms like AM642 EVM can enable it.
> 
> This is used by PCIe to use the same refclk both in local SERDES
> and remote device. Add support here to drive refclk out.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> ---
>  drivers/phy/cadence/Kconfig   |   1 +
>  drivers/phy/cadence/phy-cadence-torrent.c | 188 +-
>  2 files changed, 186 insertions(+), 3 deletions(-)
> 

Reviewed-by: Swapnil Jakhade 

Thanks & regards,
Swapnil

> diff --git a/drivers/phy/cadence/Kconfig b/drivers/phy/cadence/Kconfig
> index 432832bdbd16..27e9d6c377e5 100644
> --- a/drivers/phy/cadence/Kconfig
> +++ b/drivers/phy/cadence/Kconfig
> @@ -7,6 +7,7 @@ config PHY_CADENCE_TORRENT
>   tristate "Cadence Torrent PHY driver"
>   depends on OF
>   depends on HAS_IOMEM
> + depends on COMMON_CLK
>   select GENERIC_PHY
>   help
> Support for Cadence Torrent PHY.
> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c
> b/drivers/phy/cadence/phy-cadence-torrent.c
> index 591a15834b48..c6fee7f75f57 100644
> --- a/drivers/phy/cadence/phy-cadence-torrent.c
> +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> @@ -7,7 +7,9 @@
>   */
> 
>  #include 
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -84,6 +86,8 @@
>  #define CMN_PLLSM1_PLLLOCK_TMR   0x0034U
>  #define CMN_CDIAG_CDB_PWRI_OVRD  0x0041U
>  #define CMN_CDIAG_XCVRC_PWRI_OVRD0x0047U
> +#define CMN_CDIAG_REFCLK_OVRD0x004CU
> +#define CMN_CDIAG_REFCLK_DRV0_CTRL   0x0050U
>  #define CMN_BGCAL_INIT_TMR   0x0064U
>  #define CMN_BGCAL_ITER_TMR   0x0065U
>  #define CMN_IBCAL_INIT_TMR   0x0074U
> @@ -206,6 +210,7 @@
>  #define RX_DIAG_ACYA 0x01FFU
> 
>  /* PHY PCS common registers */
> +#define PHY_PIPE_CMN_CTRL1   0xU
>  #define PHY_PLL_CFG  0x000EU
>  #define PHY_PIPE_USB3_GEN2_PRE_CFG0  0x0020U
>  #define PHY_PIPE_USB3_GEN2_POST_CFG0 0x0022U
> @@ -216,6 +221,10 @@
>  #define PHY_PMA_CMN_CTRL20x0001U
>  #define PHY_PMA_PLL_RAW_CTRL 0x0003U
> 
> +static const char * const clk_names[] = {
> + [CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver",
> +};
> +
>  static const struct reg_field phy_pll_cfg =
>   REG_FIELD(PHY_PLL_CFG, 0, 1);
> 
> @@ -231,6 +240,26 @@ static const struct reg_field phy_pma_pll_raw_ctrl =
>  static const struct reg_field phy_reset_ctrl =
>   REG_FIELD(PHY_RESET, 8, 8);
> 
> +static const struct reg_field phy_pipe_cmn_ctrl1_0 =
> REG_FIELD(PHY_PIPE_CMN_CTRL1, 0, 0);
> +
> +#define REFCLK_OUT_NUM_CMN_CONFIG5
> +
> +enum cdns_torrent_refclk_out_cmn {
> + CMN_CDIAG_REFCLK_OVRD_4,
> + CMN_CDIAG_REFCLK_DRV0_CTRL_1,
> + CMN_CDIAG_REFCLK_DRV0_CTRL_4,
> + CMN_CDIAG_REFCLK_DRV0_CTRL_5,
> + CMN_CDIAG_REFCLK_DRV0_CTRL_6,
> +};
> +
> +static const struct reg_field refclk_out_cmn_cfg[] = {
> + [CMN_CDIAG_REFCLK_OVRD_4]   =
> REG_FIELD(CMN_CDIAG_REFCLK_OVRD, 4, 4),
> + [CMN_CDIAG_REFCLK_DRV0_CTRL_1]  =
> REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 1, 1),
> + [CMN_CDIAG_REFCLK_DRV0_CTRL_4]  =
> REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 4, 4),
> + [CMN_CDIAG_REFCLK_DRV0_CTRL_5]  =
> REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 5, 5),
> + [CMN_CDIAG_REFCLK_DRV0_CTRL_6]  =
> REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 6, 6),
> +};
> +
>  enum cdns_torrent_phy_type {
>   TYPE_NONE,
>   TYPE_DP,
> @@ -279,6 +308,8 @@ struct cdns_torrent_phy {
>   struct regmap_field *phy_pma_cmn_ctrl_2;
>   struct regmap_field *phy_pma_pll_raw_ctrl;
>   struct regmap_field *phy_reset_ctrl;
> + struct clk *clks[CDNS_TORRENT_REFCLK_DRIVER + 1];
> + struct clk_onecell_data clk_data;
>  };
> 
>  enum phy_powerstate {
> @@ -288,6 +319,16 @@ enum phy_powerstate {
>   POWERSTATE_A3 = 3,
>  };
> 
> +struct cdns_torrent_derived_refclk {
> + struct clk_hw   hw;
> + struct re

Re: [PATCH v3 6/6] phy: cadence-torrent: Add support to drive refclk out

2021-03-10 Thread kernel test robot
Hi Kishon,

I love your patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.12-rc2 next-20210310]
[cannot apply to phy/next]
[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/Kishon-Vijay-Abraham-I/AM64-Add-SERDES-driver-support/20210310-201224
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
144c79ef33536b4ecb4951e07dbc1f2b7fa99d32
config: arc-randconfig-r022-20210308 (attached as .config)
compiler: arc-elf-gcc (GCC) 9.3.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/0day-ci/linux/commit/918d7061e3f8808f1665112ca2bc8ed424d108bd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Kishon-Vijay-Abraham-I/AM64-Add-SERDES-driver-support/20210310-201224
git checkout 918d7061e3f8808f1665112ca2bc8ed424d108bd
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

>> drivers/phy/cadence/phy-cadence-torrent.c:225:3: error: 
>> 'CDNS_TORRENT_REFCLK_DRIVER' undeclared here (not in a function)
 225 |  [CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver",
 |   ^~
>> drivers/phy/cadence/phy-cadence-torrent.c:225:3: error: array index in 
>> initializer not of integer type
   drivers/phy/cadence/phy-cadence-torrent.c:225:3: note: (near initialization 
for 'clk_names')


vim +/CDNS_TORRENT_REFCLK_DRIVER +225 drivers/phy/cadence/phy-cadence-torrent.c

   223  
   224  static const char * const clk_names[] = {
 > 225  [CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver",
   226  };
   227  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


Re: [PATCH v3 6/6] phy: cadence-torrent: Add support to drive refclk out

2021-03-10 Thread kernel test robot
Hi Kishon,

I love your patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.12-rc2 next-20210310]
[cannot apply to phy/next]
[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/Kishon-Vijay-Abraham-I/AM64-Add-SERDES-driver-support/20210310-201224
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
144c79ef33536b4ecb4951e07dbc1f2b7fa99d32
config: powerpc64-randconfig-r013-20210308 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
cd9a69289c7825d54450cb6829fef2c8e0f1963a)
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 powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# 
https://github.com/0day-ci/linux/commit/918d7061e3f8808f1665112ca2bc8ed424d108bd
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Kishon-Vijay-Abraham-I/AM64-Add-SERDES-driver-support/20210310-201224
git checkout 918d7061e3f8808f1665112ca2bc8ed424d108bd
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross 
ARCH=powerpc64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All errors (new ones prefixed by >>):

   In file included from drivers/phy/cadence/phy-cadence-torrent.c:15:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:619:
   arch/powerpc/include/asm/io-defs.h:43:1: warning: performing pointer 
arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insb, (unsigned long p, void *b, unsigned long c),
   ^~~
   arch/powerpc/include/asm/io.h:616:3: note: expanded from macro 
'DEF_PCI_AC_NORET'
   __do_##name al; \
   ^~
   :184:1: note: expanded from here
   __do_insb
   ^
   arch/powerpc/include/asm/io.h:556:56: note: expanded from macro '__do_insb'
   #define __do_insb(p, b, n)  readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
  ~^
   In file included from drivers/phy/cadence/phy-cadence-torrent.c:15:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:619:
   arch/powerpc/include/asm/io-defs.h:45:1: warning: performing pointer 
arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insw, (unsigned long p, void *b, unsigned long c),
   ^~~
   arch/powerpc/include/asm/io.h:616:3: note: expanded from macro 
'DEF_PCI_AC_NORET'
   __do_##name al; \
   ^~
   :186:1: note: expanded from here
   __do_insw
   ^
   arch/powerpc/include/asm/io.h:557:56: note: expanded from macro '__do_insw'
   #define __do_insw(p, b, n)  readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
  ~^
   In file included from drivers/phy/cadence/phy-cadence-torrent.c:15:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:619:
   arch/powerpc/include/asm/io-defs.h:47:1: warning: performing pointer 
arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(insl, (unsigned long p, void *b, unsigned long c),
   ^~~
   arch/powerpc/include/asm/io.h:616:3: note: expanded from macro 
'DEF_PCI_AC_NORET'
   __do_##name al; \
   ^~
   :188:1: note: expanded from here
   __do_insl
   ^
   arch/powerpc/include/asm/io.h:558:56: note: expanded from macro '__do_insl'
   #define __do_insl(p, b, n)  readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n))
  ~^
   In file included from drivers/phy/cadence/phy-cadence-torrent.c:15:
   In file included from include/linux/io.h:13:
   In file included from arch/powerpc/include/asm/io.h:619:
   arch/powerpc/include/asm/io-defs.h:49:1: warning: performing pointer 
arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
   DEF_PCI_AC_NORET(outsb, (unsigned long p, const void *b, unsigned long c),
   

[PATCH v3 6/6] phy: cadence-torrent: Add support to drive refclk out

2021-03-10 Thread Kishon Vijay Abraham I
cmn_refclk_ lines in Torrent SERDES is used for connecting external
reference clock. cmn_refclk_ can also be configured to output the
reference clock. Model this derived reference clock as a "clock" so that
platforms like AM642 EVM can enable it.

This is used by PCIe to use the same refclk both in local SERDES
and remote device. Add support here to drive refclk out.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/phy/cadence/Kconfig   |   1 +
 drivers/phy/cadence/phy-cadence-torrent.c | 188 +-
 2 files changed, 186 insertions(+), 3 deletions(-)

diff --git a/drivers/phy/cadence/Kconfig b/drivers/phy/cadence/Kconfig
index 432832bdbd16..27e9d6c377e5 100644
--- a/drivers/phy/cadence/Kconfig
+++ b/drivers/phy/cadence/Kconfig
@@ -7,6 +7,7 @@ config PHY_CADENCE_TORRENT
tristate "Cadence Torrent PHY driver"
depends on OF
depends on HAS_IOMEM
+   depends on COMMON_CLK
select GENERIC_PHY
help
  Support for Cadence Torrent PHY.
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c 
b/drivers/phy/cadence/phy-cadence-torrent.c
index 591a15834b48..c6fee7f75f57 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -7,7 +7,9 @@
  */
 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -84,6 +86,8 @@
 #define CMN_PLLSM1_PLLLOCK_TMR 0x0034U
 #define CMN_CDIAG_CDB_PWRI_OVRD0x0041U
 #define CMN_CDIAG_XCVRC_PWRI_OVRD  0x0047U
+#define CMN_CDIAG_REFCLK_OVRD  0x004CU
+#define CMN_CDIAG_REFCLK_DRV0_CTRL 0x0050U
 #define CMN_BGCAL_INIT_TMR 0x0064U
 #define CMN_BGCAL_ITER_TMR 0x0065U
 #define CMN_IBCAL_INIT_TMR 0x0074U
@@ -206,6 +210,7 @@
 #define RX_DIAG_ACYA   0x01FFU
 
 /* PHY PCS common registers */
+#define PHY_PIPE_CMN_CTRL1 0xU
 #define PHY_PLL_CFG0x000EU
 #define PHY_PIPE_USB3_GEN2_PRE_CFG00x0020U
 #define PHY_PIPE_USB3_GEN2_POST_CFG0   0x0022U
@@ -216,6 +221,10 @@
 #define PHY_PMA_CMN_CTRL2  0x0001U
 #define PHY_PMA_PLL_RAW_CTRL   0x0003U
 
+static const char * const clk_names[] = {
+   [CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver",
+};
+
 static const struct reg_field phy_pll_cfg =
REG_FIELD(PHY_PLL_CFG, 0, 1);
 
@@ -231,6 +240,26 @@ static const struct reg_field phy_pma_pll_raw_ctrl =
 static const struct reg_field phy_reset_ctrl =
REG_FIELD(PHY_RESET, 8, 8);
 
+static const struct reg_field phy_pipe_cmn_ctrl1_0 = 
REG_FIELD(PHY_PIPE_CMN_CTRL1, 0, 0);
+
+#define REFCLK_OUT_NUM_CMN_CONFIG  5
+
+enum cdns_torrent_refclk_out_cmn {
+   CMN_CDIAG_REFCLK_OVRD_4,
+   CMN_CDIAG_REFCLK_DRV0_CTRL_1,
+   CMN_CDIAG_REFCLK_DRV0_CTRL_4,
+   CMN_CDIAG_REFCLK_DRV0_CTRL_5,
+   CMN_CDIAG_REFCLK_DRV0_CTRL_6,
+};
+
+static const struct reg_field refclk_out_cmn_cfg[] = {
+   [CMN_CDIAG_REFCLK_OVRD_4]   = REG_FIELD(CMN_CDIAG_REFCLK_OVRD, 4, 
4),
+   [CMN_CDIAG_REFCLK_DRV0_CTRL_1]  = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 
1, 1),
+   [CMN_CDIAG_REFCLK_DRV0_CTRL_4]  = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 
4, 4),
+   [CMN_CDIAG_REFCLK_DRV0_CTRL_5]  = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 
5, 5),
+   [CMN_CDIAG_REFCLK_DRV0_CTRL_6]  = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 
6, 6),
+};
+
 enum cdns_torrent_phy_type {
TYPE_NONE,
TYPE_DP,
@@ -279,6 +308,8 @@ struct cdns_torrent_phy {
struct regmap_field *phy_pma_cmn_ctrl_2;
struct regmap_field *phy_pma_pll_raw_ctrl;
struct regmap_field *phy_reset_ctrl;
+   struct clk *clks[CDNS_TORRENT_REFCLK_DRIVER + 1];
+   struct clk_onecell_data clk_data;
 };
 
 enum phy_powerstate {
@@ -288,6 +319,16 @@ enum phy_powerstate {
POWERSTATE_A3 = 3,
 };
 
+struct cdns_torrent_derived_refclk {
+   struct clk_hw   hw;
+   struct regmap_field *phy_pipe_cmn_ctrl1_0;
+   struct regmap_field *cmn_fields[REFCLK_OUT_NUM_CMN_CONFIG];
+   struct clk_init_dataclk_data;
+};
+
+#define to_cdns_torrent_derived_refclk(_hw)\
+   container_of(_hw, struct cdns_torrent_derived_refclk, 
hw)
+
 static int cdns_torrent_phy_init(struct phy *phy);
 static int cdns_torrent_dp_init(struct phy *phy);
 static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy,
@@ -1604,6 +1645,108 @@ static int cdns_torrent_dp_run(struct cdns_torrent_phy 
*cdns_phy, u32 num_lanes)
return ret;
 }
 
+static int cdns_torrent_derived_refclk_enable(struct clk_hw *hw)
+{
+   struct cdns_torrent_derived_refclk *derived_refclk = 
to_cdns_torrent_derived_refclk(hw);
+
+   
regmap_field_write(derived_refclk->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0);
+   
regmap_field_write(derived_refclk->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1);
+