Re: [PATCH v2 07/13] drm/mediatek: separae hdmi phy to different file

2018-09-09 Thread CK Hu
Hi, Bibby:

On Wed, 2018-09-05 at 16:31 +0800, Bibby Hsieh wrote:
> From: chunhui dai 
> 
> Different IC has different phy setting of HDMI.
> This patch separaes the phy hardware relate part for mt8173.
> 
> Signed-off-by: chunhui dai 
> ---
>  drivers/gpu/drm/mediatek/Makefile  |  15 +--
>  drivers/gpu/drm/mediatek/mtk_hdmi.c|  30 +++--
>  drivers/gpu/drm/mediatek/mtk_hdmi.h|  26 +
>  drivers/gpu/drm/mediatek/mtk_hdmi_phy.c| 154 
> +
>  drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c | 129 ++---
>  5 files changed, 216 insertions(+), 138 deletions(-)
>  create mode 100644 drivers/gpu/drm/mediatek/mtk_hdmi_phy.c
> 
> diff --git a/drivers/gpu/drm/mediatek/Makefile 
> b/drivers/gpu/drm/mediatek/Makefile
> index ce83c396a742..7f947979d68f 100644
> --- a/drivers/gpu/drm/mediatek/Makefile
> +++ b/drivers/gpu/drm/mediatek/Makefile
> @@ -1,4 +1,12 @@
>  # SPDX-License-Identifier: GPL-2.0
> +mediatek-drm-hdmi-objs := mtk_cec.o \
> +   mtk_hdmi.o \
> +   mtk_hdmi_ddc.o \
> +   mtk_mt8173_hdmi_phy.o \
> +   mtk_hdmi_phy.o
> +
> +obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
> +

It looks like you just want to add mtk_hdmi_phy.o, I think you need not
to move mediatek-drm-hdmi-objs.

>  mediatek-drm-y := mtk_disp_color.o \
> mtk_disp_ovl.o \
> mtk_disp_rdma.o \
> @@ -14,10 +22,3 @@ mediatek-drm-y := mtk_disp_color.o \
> mtk_dpi.o
>  
>  obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
> -
> -mediatek-drm-hdmi-objs := mtk_cec.o \
> -   mtk_hdmi.o \
> -   mtk_hdmi_ddc.o \
> -   mtk_mt8173_hdmi_phy.o
> -
> -obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
> diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c 
> b/drivers/gpu/drm/mediatek/mtk_hdmi.c
> index 2d45d1dd9554..7c022f3f53ec 100644
> --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
> @@ -233,6 +233,7 @@ static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, 
> bool black)
>  static void mtk_hdmi_hw_make_reg_writable(struct mtk_hdmi *hdmi, bool enable)
>  {
>   struct arm_smccc_res res;
> + struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(hdmi->phy);
>  
>   /*
>* MT8173 HDMI hardware has an output control bit to enable/disable HDMI
> @@ -240,8 +241,13 @@ static void mtk_hdmi_hw_make_reg_writable(struct 
> mtk_hdmi *hdmi, bool enable)
>* The ARM trusted firmware provides an API for the HDMI driver to set
>* this control bit to enable HDMI output in supervisor mode.
>*/
> - arm_smccc_smc(MTK_SIP_SET_AUTHORIZED_SECURE_REG, 0x14000904, 0x8000,
> -   0, 0, 0, 0, 0, );
> + if (hdmi_phy->conf && hdmi_phy->conf->tz_enabled)
> + arm_smccc_smc(MTK_SIP_SET_AUTHORIZED_SECURE_REG, 0x14000904,
> +   0x8000, 0, 0, 0, 0, 0, );
> + else
> + regmap_update_bits(hdmi->sys_regmap,
> +hdmi->sys_offset + HDMI_SYS_CFG20,
> +0x80008005, enable ? 0x8005 : 0x8000);

I think this should be moved to 'drm/mediatek: add hdmi driver for
MT2701 and MT7623'. If you change the variable name to tz_disabled, you
could modify this in just one patch.

>  
>   regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20,
>  HDMI_PCLK_FREE_RUN, enable ? HDMI_PCLK_FREE_RUN : 0);
> @@ -1437,6 +1443,7 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi 
> *hdmi,
>   struct platform_device *cec_pdev;
>   struct regmap *regmap;
>   struct resource *mem;
> + const char *phy_name;
>   int ret;
>  
>   ret = mtk_hdmi_get_all_clk(hdmi, np);
> @@ -1445,6 +1452,18 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi 
> *hdmi,
>   return ret;
>   }
>  
> + ret = of_property_read_string(np, "phy-names", _name);
> + if (ret < 0) {
> + dev_err(dev, "Failed to read phy-names: %d\n", ret);
> + return ret;
> + }
> + hdmi->phy = devm_phy_get(dev, phy_name);
> + if (IS_ERR(hdmi->phy)) {
> + ret = PTR_ERR(hdmi->phy);
> + dev_err(dev, "Failed to get HDMI PHY: %d\n", ret);
> + return ret;
> + }
> +

I think this part is not related to 'separate hdmi phy to different
file' and I don't know why you do this? If you really need this,
separate this to an independent patch and describe why you do this.

Regards,
CK

>   /* The CEC module handles HDMI hotplug detection */
>   cec_np = of_find_compatible_node(np->parent, NULL,
>"mediatek,mt8173-cec");
> @@ -1677,13 +1696,6 @@ static int mtk_drm_hdmi_probe(struct platform_device 
> *pdev)
>   if (ret)
>   return ret;
>  
> - hdmi->phy = 

Re: [PATCH v2 07/13] drm/mediatek: separae hdmi phy to different file

2018-09-06 Thread CK Hu
Hi, Bibby:

On Wed, 2018-09-05 at 16:31 +0800, Bibby Hsieh wrote:
> From: chunhui dai 
> 
> Different IC has different phy setting of HDMI.
> This patch separaes the phy hardware relate part for mt8173.

I guess 'separae' is 'separate'. Am I right?

Regards,
CK

> 
> Signed-off-by: chunhui dai 
> ---
>  drivers/gpu/drm/mediatek/Makefile  |  15 +--
>  drivers/gpu/drm/mediatek/mtk_hdmi.c|  30 +++--
>  drivers/gpu/drm/mediatek/mtk_hdmi.h|  26 +
>  drivers/gpu/drm/mediatek/mtk_hdmi_phy.c| 154 
> +
>  drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c | 129 ++---
>  5 files changed, 216 insertions(+), 138 deletions(-)
>  create mode 100644 drivers/gpu/drm/mediatek/mtk_hdmi_phy.c
> 
> diff --git a/drivers/gpu/drm/mediatek/Makefile 
> b/drivers/gpu/drm/mediatek/Makefile
> index ce83c396a742..7f947979d68f 100644
> --- a/drivers/gpu/drm/mediatek/Makefile
> +++ b/drivers/gpu/drm/mediatek/Makefile
> @@ -1,4 +1,12 @@
>  # SPDX-License-Identifier: GPL-2.0
> +mediatek-drm-hdmi-objs := mtk_cec.o \
> +   mtk_hdmi.o \
> +   mtk_hdmi_ddc.o \
> +   mtk_mt8173_hdmi_phy.o \
> +   mtk_hdmi_phy.o
> +
> +obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
> +
>  mediatek-drm-y := mtk_disp_color.o \
> mtk_disp_ovl.o \
> mtk_disp_rdma.o \
> @@ -14,10 +22,3 @@ mediatek-drm-y := mtk_disp_color.o \
> mtk_dpi.o
>  
>  obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
> -
> -mediatek-drm-hdmi-objs := mtk_cec.o \
> -   mtk_hdmi.o \
> -   mtk_hdmi_ddc.o \
> -   mtk_mt8173_hdmi_phy.o
> -
> -obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
> diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c 
> b/drivers/gpu/drm/mediatek/mtk_hdmi.c
> index 2d45d1dd9554..7c022f3f53ec 100644
> --- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
> @@ -233,6 +233,7 @@ static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, 
> bool black)
>  static void mtk_hdmi_hw_make_reg_writable(struct mtk_hdmi *hdmi, bool enable)
>  {
>   struct arm_smccc_res res;
> + struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(hdmi->phy);
>  
>   /*
>* MT8173 HDMI hardware has an output control bit to enable/disable HDMI
> @@ -240,8 +241,13 @@ static void mtk_hdmi_hw_make_reg_writable(struct 
> mtk_hdmi *hdmi, bool enable)
>* The ARM trusted firmware provides an API for the HDMI driver to set
>* this control bit to enable HDMI output in supervisor mode.
>*/
> - arm_smccc_smc(MTK_SIP_SET_AUTHORIZED_SECURE_REG, 0x14000904, 0x8000,
> -   0, 0, 0, 0, 0, );
> + if (hdmi_phy->conf && hdmi_phy->conf->tz_enabled)
> + arm_smccc_smc(MTK_SIP_SET_AUTHORIZED_SECURE_REG, 0x14000904,
> +   0x8000, 0, 0, 0, 0, 0, );
> + else
> + regmap_update_bits(hdmi->sys_regmap,
> +hdmi->sys_offset + HDMI_SYS_CFG20,
> +0x80008005, enable ? 0x8005 : 0x8000);
>  
>   regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20,
>  HDMI_PCLK_FREE_RUN, enable ? HDMI_PCLK_FREE_RUN : 0);
> @@ -1437,6 +1443,7 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi 
> *hdmi,
>   struct platform_device *cec_pdev;
>   struct regmap *regmap;
>   struct resource *mem;
> + const char *phy_name;
>   int ret;
>  
>   ret = mtk_hdmi_get_all_clk(hdmi, np);
> @@ -1445,6 +1452,18 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi 
> *hdmi,
>   return ret;
>   }
>  
> + ret = of_property_read_string(np, "phy-names", _name);
> + if (ret < 0) {
> + dev_err(dev, "Failed to read phy-names: %d\n", ret);
> + return ret;
> + }
> + hdmi->phy = devm_phy_get(dev, phy_name);
> + if (IS_ERR(hdmi->phy)) {
> + ret = PTR_ERR(hdmi->phy);
> + dev_err(dev, "Failed to get HDMI PHY: %d\n", ret);
> + return ret;
> + }
> +
>   /* The CEC module handles HDMI hotplug detection */
>   cec_np = of_find_compatible_node(np->parent, NULL,
>"mediatek,mt8173-cec");
> @@ -1677,13 +1696,6 @@ static int mtk_drm_hdmi_probe(struct platform_device 
> *pdev)
>   if (ret)
>   return ret;
>  
> - hdmi->phy = devm_phy_get(dev, "hdmi");
> - if (IS_ERR(hdmi->phy)) {
> - ret = PTR_ERR(hdmi->phy);
> - dev_err(dev, "Failed to get HDMI PHY: %d\n", ret);
> - return ret;
> - }
> -
>   platform_set_drvdata(pdev, hdmi);
>  
>   ret = mtk_hdmi_output_init(hdmi);
> diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.h 
> b/drivers/gpu/drm/mediatek/mtk_hdmi.h
> index 6371b3de1ff6..a350a6c9271f 100644
> --- 

[PATCH v2 07/13] drm/mediatek: separae hdmi phy to different file

2018-09-05 Thread Bibby Hsieh
From: chunhui dai 

Different IC has different phy setting of HDMI.
This patch separaes the phy hardware relate part for mt8173.

Signed-off-by: chunhui dai 
---
 drivers/gpu/drm/mediatek/Makefile  |  15 +--
 drivers/gpu/drm/mediatek/mtk_hdmi.c|  30 +++--
 drivers/gpu/drm/mediatek/mtk_hdmi.h|  26 +
 drivers/gpu/drm/mediatek/mtk_hdmi_phy.c| 154 +
 drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c | 129 ++---
 5 files changed, 216 insertions(+), 138 deletions(-)
 create mode 100644 drivers/gpu/drm/mediatek/mtk_hdmi_phy.c

diff --git a/drivers/gpu/drm/mediatek/Makefile 
b/drivers/gpu/drm/mediatek/Makefile
index ce83c396a742..7f947979d68f 100644
--- a/drivers/gpu/drm/mediatek/Makefile
+++ b/drivers/gpu/drm/mediatek/Makefile
@@ -1,4 +1,12 @@
 # SPDX-License-Identifier: GPL-2.0
+mediatek-drm-hdmi-objs := mtk_cec.o \
+ mtk_hdmi.o \
+ mtk_hdmi_ddc.o \
+ mtk_mt8173_hdmi_phy.o \
+ mtk_hdmi_phy.o
+
+obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
+
 mediatek-drm-y := mtk_disp_color.o \
  mtk_disp_ovl.o \
  mtk_disp_rdma.o \
@@ -14,10 +22,3 @@ mediatek-drm-y := mtk_disp_color.o \
  mtk_dpi.o
 
 obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
-
-mediatek-drm-hdmi-objs := mtk_cec.o \
- mtk_hdmi.o \
- mtk_hdmi_ddc.o \
- mtk_mt8173_hdmi_phy.o
-
-obj-$(CONFIG_DRM_MEDIATEK_HDMI) += mediatek-drm-hdmi.o
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c 
b/drivers/gpu/drm/mediatek/mtk_hdmi.c
index 2d45d1dd9554..7c022f3f53ec 100644
--- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
+++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
@@ -233,6 +233,7 @@ static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, 
bool black)
 static void mtk_hdmi_hw_make_reg_writable(struct mtk_hdmi *hdmi, bool enable)
 {
struct arm_smccc_res res;
+   struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(hdmi->phy);
 
/*
 * MT8173 HDMI hardware has an output control bit to enable/disable HDMI
@@ -240,8 +241,13 @@ static void mtk_hdmi_hw_make_reg_writable(struct mtk_hdmi 
*hdmi, bool enable)
 * The ARM trusted firmware provides an API for the HDMI driver to set
 * this control bit to enable HDMI output in supervisor mode.
 */
-   arm_smccc_smc(MTK_SIP_SET_AUTHORIZED_SECURE_REG, 0x14000904, 0x8000,
- 0, 0, 0, 0, 0, );
+   if (hdmi_phy->conf && hdmi_phy->conf->tz_enabled)
+   arm_smccc_smc(MTK_SIP_SET_AUTHORIZED_SECURE_REG, 0x14000904,
+ 0x8000, 0, 0, 0, 0, 0, );
+   else
+   regmap_update_bits(hdmi->sys_regmap,
+  hdmi->sys_offset + HDMI_SYS_CFG20,
+  0x80008005, enable ? 0x8005 : 0x8000);
 
regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20,
   HDMI_PCLK_FREE_RUN, enable ? HDMI_PCLK_FREE_RUN : 0);
@@ -1437,6 +1443,7 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
struct platform_device *cec_pdev;
struct regmap *regmap;
struct resource *mem;
+   const char *phy_name;
int ret;
 
ret = mtk_hdmi_get_all_clk(hdmi, np);
@@ -1445,6 +1452,18 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
return ret;
}
 
+   ret = of_property_read_string(np, "phy-names", _name);
+   if (ret < 0) {
+   dev_err(dev, "Failed to read phy-names: %d\n", ret);
+   return ret;
+   }
+   hdmi->phy = devm_phy_get(dev, phy_name);
+   if (IS_ERR(hdmi->phy)) {
+   ret = PTR_ERR(hdmi->phy);
+   dev_err(dev, "Failed to get HDMI PHY: %d\n", ret);
+   return ret;
+   }
+
/* The CEC module handles HDMI hotplug detection */
cec_np = of_find_compatible_node(np->parent, NULL,
 "mediatek,mt8173-cec");
@@ -1677,13 +1696,6 @@ static int mtk_drm_hdmi_probe(struct platform_device 
*pdev)
if (ret)
return ret;
 
-   hdmi->phy = devm_phy_get(dev, "hdmi");
-   if (IS_ERR(hdmi->phy)) {
-   ret = PTR_ERR(hdmi->phy);
-   dev_err(dev, "Failed to get HDMI PHY: %d\n", ret);
-   return ret;
-   }
-
platform_set_drvdata(pdev, hdmi);
 
ret = mtk_hdmi_output_init(hdmi);
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.h 
b/drivers/gpu/drm/mediatek/mtk_hdmi.h
index 6371b3de1ff6..a350a6c9271f 100644
--- a/drivers/gpu/drm/mediatek/mtk_hdmi.h
+++ b/drivers/gpu/drm/mediatek/mtk_hdmi.h
@@ -13,11 +13,37 @@
  */
 #ifndef _MTK_HDMI_CTRL_H
 #define _MTK_HDMI_CTRL_H
+#include 
+#include 
+#include 
+#include 
+
+struct mtk_hdmi_phy_conf {
+   bool tz_enabled;
+   const