Skip to contentSkip to conversation

Add support for DisplayPort driver on SnapDragon 845

PATCH In review Chandan Uddaraju 8 participants 20 messages Oct 10, 2018 – Mar 10, 2019 6 messages not in the archive Page 2 of 3

Subsystems (5)
lore
Share & tools
lore
reviewer
#20 lore raw

Re: [DPU PATCH 3/3] drm/msm/dp: add support for DP PLL driver

In reply to Chandan Uddaraju
Quoted 33 lines · Chandan Uddaraju

Add the needed DP PLL specific files to support
display port interface on msm targets.

The DP driver calls the DP PLL driver registration. The DP driver sets the link and pixel clock sources.

---
 drivers/gpu/drm/msm/Kconfig                   |  16 +
 drivers/gpu/drm/msm/Makefile                  |   6 +
 drivers/gpu/drm/msm/dp/dp_ctrl.c              |   1 +
 drivers/gpu/drm/msm/dp/dp_display.c           |  50 +++
 drivers/gpu/drm/msm/dp/dp_display.h           |   3 +
 drivers/gpu/drm/msm/dp/dp_parser.h            |   3 +
 drivers/gpu/drm/msm/dp/dp_power.c             |  77 +++-
 drivers/gpu/drm/msm/dp/dp_power.h             |   2 +
 drivers/gpu/drm/msm/dp/pll/dp_pll.c           | 153 ++++++++
 drivers/gpu/drm/msm/dp/pll/dp_pll.h           |  64 ++++
 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c      | 401 +++++++++++++++++++
 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h      |  94 +++++
 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c | 531 ++++++++++++++++++++++++++
 13 files changed, 1389 insertions(+), 12 deletions(-)
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll.c
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll.h
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c
drivers/gpu/drm/msm/Kconfig +0 -0
index c363f24..1e0b9158 100644

drivers/gpu/drm/msm/Kconfig config DRM_MSM_DP · line 65

Quoted 8 lines
drivers/gpu/drm/msm/Kconfig +5 -0
@@ -58,6 +58,22 @@ config DRM_MSM_DP
 	  driver. DP external display support is enabled
 	  through this config option. It can be primary or
 	  secondary display on device.
+
+config DRM_MSM_DP_PLL
+	bool "Enable DP PLL driver in MSM DRM"
+	depends on DRM_MSM_DP && COMMON_CLK
+	default y

The default should be n

drivers/gpu/drm/msm/Kconfig config DRM_MSM_DP · line 72

Quoted 7 lines
drivers/gpu/drm/msm/Kconfig +7 -0
+	help
+	  Choose this option to enable DP PLL driver which provides DP
+	  source clocks under common clock framework.
+
+config DRM_MSM_DP_10NM_PLL
+	bool "Enable DP 10nm PLL driver in MSM DRM (used by SDM845)"
+	depends on DRM_MSM_DP

Should this be DRM_MSM_DP_PLL instead?

drivers/gpu/drm/msm/Kconfig config DRM_MSM_DP · line 73

Quoted 1 line
drivers/gpu/drm/msm/Kconfig +1 -0
+	default y

The default should be n

Quoted 11 lines
drivers/gpu/drm/msm/Kconfig +3 -0
+	help
+	  Choose this option if DP PLL on SDM845 is used on the platform.
+
 config DRM_MSM_DSI
 	bool "Enable DSI support in MSM DRM driver"
 	depends on DRM_MSM
drivers/gpu/drm/msm/Makefile +0 -0
index 765a8d8..8d18353 100644

drivers/gpu/drm/msm/Makefile msm-$(CONFIG_DRM_MSM_DSI_14NM_PHY) += dsi/pll/dsi_pll_14nm.o · line 143

Quoted 7 lines
drivers/gpu/drm/msm/Makefile +4 -0
@@ -137,4 +137,10 @@ msm-$(CONFIG_DRM_MSM_DSI_14NM_PHY) += dsi/pll/dsi_pll_14nm.o
 msm-$(CONFIG_DRM_MSM_DSI_10NM_PHY) += dsi/pll/dsi_pll_10nm.o
 endif
 
+ifeq ($(CONFIG_DRM_MSM_DP_PLL),y)
+msm-y += dp/pll/dp_pll.o
+msm-y += dp/pll/dp_pll_10nm.o
+msm-y += dp/pll/dp_pll_10nm_util.o

Instead of the ifeq, these should follow the form:

msm-$(CONFIG_BLAH) +=

Quoted 32 lines
drivers/gpu/drm/msm/Makefile +2 -0
+endif
+
 obj-$(CONFIG_DRM_MSM)	+= msm.o
drivers/gpu/drm/msm/dp/dp_ctrl.c +1 -0
index 08a52f5..e23beee 100644
@@ -1051,6 +1051,7 @@ static int dp_ctrl_enable_mainlink_clocks(struct dp_ctrl_private *ctrl)
 {
 	int ret = 0;
 
+	ctrl->power->set_link_clk_parent(ctrl->power);
 	ctrl->power->set_pixel_clk_parent(ctrl->power);
 
 	dp_ctrl_set_clock_rate(ctrl, "ctrl_link_clk",
drivers/gpu/drm/msm/dp/dp_display.c +9 -0
index 8c98399..2bf6635 100644
@@ -72,6 +72,48 @@ struct dp_display_private {
 	{}
 };
 
+static int dp_get_pll(struct dp_display_private *dp_priv)
+{
+	struct platform_device *pdev = NULL;
+	struct platform_device *pll_pdev;
+	struct device_node *pll_node;
+	struct dp_parser *dp_parser = NULL;
+
+	if (!dp_priv) {
+		pr_err("Invalid Arguments\n");

drivers/gpu/drm/msm/dp/dp_display.c struct dp_display_private { · line 93

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +10 -0
+		return -EINVAL;
+	}
+
+	pdev = dp_priv->pdev;
+	dp_parser = dp_priv->parser;
+
+	if (!dp_parser) {
+		pr_err("Parser not initialized.\n");
+		return -EINVAL;
+	}

Can we please remove the unnecessary null checks from this patch too?

drivers/gpu/drm/msm/dp/dp_display.c struct dp_display_private { · line 103

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +10 -0
+
+	pll_node = of_parse_phandle(pdev->dev.of_node, "pll-node", 0);
+	if (!pll_node) {
+		dev_err(&pdev->dev, "cannot find pll device\n");
+		return -ENXIO;
+	}
+
+	pll_pdev = of_find_device_by_node(pll_node);
+	if (pll_pdev)
+		dp_parser->pll = platform_get_drvdata(pll_pdev);

What if the pll driver goes away before the dp driver?

drivers/gpu/drm/msm/dp/dp_display.c struct dp_display_private { · line 108

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_display.c +5 -0
+
+	of_node_put(pll_node);
+
+	if (!pll_pdev || !dp_parser->pll) {
+		dev_err(&pdev->dev, "%s: pll driver is not ready\n", __func__);

This patch (and even just this function) has both pr_err and dev_err, oy!

Please convert everything to one logging medium. The msm driver was recently converted to DRM_DEV_*, so let's go with that for all of msm/dp/*

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_display.c +8 -0
+		return -EPROBE_DEFER;
+	}
+
+	dp_parser->pll_dev = get_device(&pll_pdev->dev);
+
+	return 0;
+}
+
 static irqreturn_t dp_display_irq(int irq, void *dev_id)
 {
 	struct dp_display_private *dp = dev_id;

drivers/gpu/drm/msm/dp/dp_display.c static int dp_display_bind(struct device *dev, struct device *master, · line 172

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_display.c +3 -0
@@ -125,6 +167,12 @@ static int dp_display_bind(struct device *dev, struct device *master,
 		goto end;
 	}
 
+	rc = dp_get_pll(dp);
+	if (rc) {
+		pr_err(" DP get PLL instance failed\n");

Print rc, here and everywhere else.

Quoted 47 lines
drivers/gpu/drm/msm/dp/dp_display.c +5 -0
+		goto end;
+	}
+
 	rc = dp->aux->drm_aux_register(dp->aux);
 	if (rc) {
 		pr_err("DRM DP AUX register failed\n");
@@ -921,6 +969,7 @@ int __init msm_dp_register(void)
 {
 	int ret;
 
+	msm_dp_pll_driver_register();
 	ret = platform_driver_register(&dp_display_driver);
 	if (ret) {
 		pr_err("driver register failed");
@@ -932,6 +981,7 @@ int __init msm_dp_register(void)
 
 void __exit msm_dp_unregister(void)
 {
+	msm_dp_pll_driver_unregister();
 	platform_driver_unregister(&dp_display_driver);
 }
 
drivers/gpu/drm/msm/dp/dp_display.h +3 -0
index ca5eae5..9cd6a6b 100644
@@ -52,4 +52,7 @@ struct msm_dp {
 
 int dp_display_get_num_of_displays(void);
 int dp_display_get_displays(void **displays, int count);
+void __init msm_dp_pll_driver_register(void);
+void __exit msm_dp_pll_driver_unregister(void);
+
 #endif /* _DP_DISPLAY_H_ */
drivers/gpu/drm/msm/dp/dp_parser.h +1 -0
index b39ea02..372997e 100644
@@ -16,6 +16,7 @@
 #define _DP_PARSER_H_
 
 #include "dpu_io_util.h"
+#include "pll/dp_pll.h"
 
 #define DP_LABEL "MDSS DP DISPLAY"
 #define AUX_CFG_LEN	10

drivers/gpu/drm/msm/dp/dp_parser.h struct dp_parser { · line 180

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_parser.h +2 -0
@@ -175,6 +176,8 @@ struct dp_parser {
 	struct dp_pinctrl pinctrl;
 	struct dp_io io;
 	struct dp_display_data disp_data;
+	struct msm_dp_pll *pll;
+	struct device *pll_dev;

Store pll_dev in msm_dp_pll as 'dev' and remove this?

Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_parser.h +0 -0
 	u8 l_map[4];
 	struct dp_aux_cfg aux_cfg[AUX_CFG_LEN];
drivers/gpu/drm/msm/dp/dp_power.c +3 -1
index 1d58480..3a1679c 100644
@@ -23,7 +23,9 @@ struct dp_power_private {
 	struct dp_parser *parser;
 	struct platform_device *pdev;
 	struct clk *pixel_clk_rcg;
-	struct clk *pixel_parent;
+	struct clk *link_clk_src;
+	struct clk *pixel_provider;
+	struct clk *link_provider;
 
 	struct dp_power dp_power;
 

drivers/gpu/drm/msm/dp/dp_power.c static int dp_power_clk_init(struct dp_power_private *power, bool enable) · line 161

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_power.c +3 -0
@@ -154,6 +156,16 @@ static int dp_power_clk_init(struct dp_power_private *power, bool enable)
 		goto exit;
 	}
 
+	if (power->parser->pll && power->parser->pll->get_provider) {
+		rc = power->parser->pll->get_provider(power->parser->pll,
+				&power->link_provider, &power->pixel_provider);

Hopefully this gets simplified when you de-abstract the rest of the dp driver.

Quoted 44 lines
drivers/gpu/drm/msm/dp/dp_power.c +19 -9
+		if (rc) {
+			pr_info("%s: can't get provider from pll, don't set parent\n",
+				__func__);
+			return 0;
+		}
+	}
+
 	if (enable) {
 		rc = msm_dss_get_clk(dev, core->clk_config, core->num_clk);
 		if (rc) {
@@ -173,17 +185,10 @@ static int dp_power_clk_init(struct dp_power_private *power, bool enable)
 		if (IS_ERR(power->pixel_clk_rcg)) {
 			pr_debug("Unable to get DP pixel clk RCG\n");
 			power->pixel_clk_rcg = NULL;
-		}
-
-		power->pixel_parent = devm_clk_get(dev, "pixel_parent");
-		if (IS_ERR(power->pixel_parent)) {
-			pr_debug("Unable to get DP pixel RCG parent\n");
-			power->pixel_parent = NULL;
+			rc = -ENODEV;
+			goto ctrl_get_error;
 		}
 	} else {
-		if (power->pixel_parent)
-			devm_clk_put(dev, power->pixel_parent);
-
 		if (power->pixel_clk_rcg)
 			devm_clk_put(dev, power->pixel_clk_rcg);
 
@@ -459,6 +464,49 @@ static void dp_power_client_deinit(struct dp_power *dp_power)
 
 }
 
+static int dp_power_set_link_clk_parent(struct dp_power *dp_power)
+{
+	int rc = 0;
+	struct dp_power_private *power;
+	u32 num;
+	struct dss_clk *cfg;
+	char *name = "ctrl_link_clk";
+
+	if (!dp_power) {
+		pr_err("invalid power data\n");

drivers/gpu/drm/msm/dp/dp_power.c static void dp_power_client_deinit(struct dp_power *dp_power) · line 486

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_power.c +10 -0
+		rc = -EINVAL;
+		goto exit;
+	}
+
+	power = container_of(dp_power, struct dp_power_private, dp_power);
+
+	num = power->parser->mp[DP_CTRL_PM].num_clk;
+	cfg = power->parser->mp[DP_CTRL_PM].clk_config;
+
+	while (num && strcmp(cfg->clk_name, name)) {

I think I commented on this in the other patch, but don't use strings to do lookups, please just store the pointer directly if you need a reference.

drivers/gpu/drm/msm/dp/dp_power.c static void dp_power_client_deinit(struct dp_power *dp_power) · line 492

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_power.c +6 -0
+		num--;
+		cfg++;
+	}
+
+	if (num && power->link_provider) {
+		power->link_clk_src = clk_get_parent(cfg->clk);

Check return for ERR_PTR

drivers/gpu/drm/msm/dp/dp_power.c static void dp_power_client_deinit(struct dp_power *dp_power) · line 493

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_power.c +1 -0
+			if (power->link_clk_src) {

Indenting is wrong on this block

drivers/gpu/drm/msm/dp/dp_power.c static void dp_power_client_deinit(struct dp_power *dp_power) · line 500

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_power.c +7 -0
+				clk_set_parent(power->link_clk_src, power->link_provider);
+				pr_debug("%s: is the parent of clk=%s\n",
+						__clk_get_name(power->link_provider),
+						__clk_get_name(power->link_clk_src));
+			} else {
+				pr_err("couldn't get parent for clk=%s\n", name);
+				rc = -EINVAL;

Make thi:

        if (!power->link_clk_src) {
                DRM_DEV_ERROR(...)
                return -EINVAL;
        }

        ret = clk_set_parent(power->link_clk_src, power->link_provider);
        if (ret) {
                /* propertly handle error */
        }
        pr_debug("%s: is the parent of clk=%s\n",
                 __clk_get_name(power->link_provider),
                 __clk_get_name(power->link_clk_src));

drivers/gpu/drm/msm/dp/dp_power.c static void dp_power_client_deinit(struct dp_power *dp_power) · line 505

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_power.c +5 -0
+			}
+	} else {
+		pr_err("%s clock could not be set parent\n", name);
+		rc = -EINVAL;
+	}

Same thing here, flip the if condition to check for error and return early, thus saving yourself a level of indentation for the successful case.

drivers/gpu/drm/msm/dp/dp_power.c static void dp_power_client_deinit(struct dp_power *dp_power) · line 507

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_power.c +2 -0
+exit:
+	return rc;

Remove exit label and return directly above

drivers/gpu/drm/msm/dp/dp_power.c static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power) · line 524

Quoted 13 lines
drivers/gpu/drm/msm/dp/dp_power.c +4 -2
+}
+
 static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power)
 {
 	int rc = 0;
@@ -472,8 +520,12 @@ static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power)
 
 	power = container_of(dp_power, struct dp_power_private, dp_power);
 
-	if (power->pixel_clk_rcg && power->pixel_parent)
-		clk_set_parent(power->pixel_clk_rcg, power->pixel_parent);
+	if (power->pixel_clk_rcg && power->pixel_provider) {
+		clk_set_parent(power->pixel_clk_rcg, power->pixel_provider);

s/pixel_parent/pixel_provider/ isn't related to this change, can you please use the final name in the main dp patch so it's correct in this one?

drivers/gpu/drm/msm/dp/dp_power.c static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power) · line 527

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_power.c +3 -0
+		pr_debug("%s: is the parent of clk=%s\n",
+					__clk_get_name(power->pixel_provider),
+					__clk_get_name(power->pixel_clk_rcg));

Same comment here, this debug can go in the main patch.

drivers/gpu/drm/msm/dp/dp_power.c struct dp_power *dp_power_get(struct dp_parser *parser) · line 632

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_power.c +2 -0
+	}
 exit:
 	return rc;
 }
@@ -577,6 +629,7 @@ struct dp_power *dp_power_get(struct dp_parser *parser)
 	dp_power->init = dp_power_init;
 	dp_power->deinit = dp_power_deinit;
 	dp_power->clk_enable = dp_power_clk_enable;
+	dp_power->set_link_clk_parent = dp_power_set_link_clk_parent;

Same comment here regarding the unnecessary indirection, just call this thing directly where applicable.

Quoted 31 lines
drivers/gpu/drm/msm/dp/dp_power.c +0 -0
 	dp_power->set_pixel_clk_parent = dp_power_set_pixel_clk_parent;
 	dp_power->power_client_init = dp_power_client_init;
 	dp_power->power_client_deinit = dp_power_client_deinit;
drivers/gpu/drm/msm/dp/dp_power.h +2 -0
index d1adaaf..5effd32 100644
@@ -24,6 +24,7 @@
  * @init: initializes the regulators/core clocks/GPIOs/pinctrl
  * @deinit: turns off the regulators/core clocks/GPIOs/pinctrl
  * @clk_enable: enable/disable the DP clocks
+ * @set_link_clk_parent: set the parent of DP link clock
  * @set_pixel_clk_parent: set the parent of DP pixel clock
  */
 struct dp_power {
@@ -31,6 +32,7 @@ struct dp_power {
 	int (*deinit)(struct dp_power *power);
 	int (*clk_enable)(struct dp_power *power, enum dp_pm_type pm_type,
 				bool enable);
+	int (*set_link_clk_parent)(struct dp_power *power);
 	int (*set_pixel_clk_parent)(struct dp_power *power);
 	int (*power_client_init)(struct dp_power *power);
 	void (*power_client_deinit)(struct dp_power *power);
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +2 -0
new file mode 100644
index 0000000..a8612b5
@@ -0,0 +1,153 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 12

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */

SPDX please (and elsewhere).

Quoted 33 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +33 -0
+
+#include "dp_pll.h"
+
+int msm_dp_pll_util_parse_dt_clock(struct platform_device *pdev,
+					struct msm_dp_pll *pll)
+{
+	u32 i = 0, rc = 0;
+	struct dss_module_power *mp = &pll->mp;
+	const char *clock_name;
+	u32 clock_rate;
+
+	mp->num_clk = of_property_count_strings(pdev->dev.of_node,
+							"clock-names");
+	if (mp->num_clk <= 0) {
+		pr_err("clocks are not defined\n");
+		goto clk_err;
+	}
+
+	mp->clk_config = devm_kzalloc(&pdev->dev,
+			sizeof(struct dss_clk) * mp->num_clk, GFP_KERNEL);
+	if (!mp->clk_config) {
+		rc = -ENOMEM;
+		mp->num_clk = 0;
+		goto clk_err;
+	}
+
+	for (i = 0; i < mp->num_clk; i++) {
+		of_property_read_string_index(pdev->dev.of_node, "clock-names",
+							i, &clock_name);
+		strlcpy(mp->clk_config[i].clk_name, clock_name,
+				sizeof(mp->clk_config[i].clk_name));
+
+		of_property_read_u32_index(pdev->dev.of_node, "clock-rate",

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 55

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+							i, &clock_rate);
+		mp->clk_config[i].rate = clock_rate;
+
+		if (!clock_rate)
+			mp->clk_config[i].type = DSS_CLK_AHB;
+		else
+			mp->clk_config[i].type = DSS_CLK_PCLK;
+	}
+
+clk_err:

remove clk_err and return directly above

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 59

Quoted 4 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +4 -0
+	return rc;
+}
+
+struct msm_dp_pll *msm_dp_pll_init(struct platform_device *pdev,

static please

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+			enum msm_dp_pll_type type, int id)
+{
+	struct device *dev = &pdev->dev;
+	struct msm_dp_pll *pll;
+
+	switch (type) {
+	case MSM_DP_PLL_10NM:
+		pll = msm_dp_pll_10nm_init(pdev, id);
+		break;
+	default:

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 79

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+		pll = ERR_PTR(-ENXIO);
+		break;
+	}
+
+	if (IS_ERR(pll)) {
+		dev_err(dev, "%s: failed to init DP PLL\n", __func__);
+		return pll;
+	}
+
+	pll->type = type;

This should be set in the type-specific init function (ie:
msm_dp_pll_10nm_init()). That will let you simplify this entire function to:

{
        switch (type) {
        case MSM_DP_PLL_10NM:
                return msm_dp_pll_10nm_init(pdev, id);
	default:
                DRM_DEV_ERROR(&pdev->dev, "Invalid pll type: %d\n", type);
                return ERR_PTR(-ENXIO);
	}
}

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 87

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +8 -0
+
+	DBG("DP:%d PLL registered", id);
+
+	return pll;
+}
+
+static const struct of_device_id dp_pll_dt_match[] = {
+#ifdef CONFIG_DRM_MSM_DP_10NM_PLL

I don't think you need this ifdef check, you've already provided a stub for the init function

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +8 -0
+	{ .compatible = "qcom,dp-pll-10nm" },
+#endif
+	{}
+};
+
+static int dp_pll_driver_probe(struct platform_device *pdev)
+{
+	struct msm_dp_pll *pll;

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 105

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+	struct device *dev = &pdev->dev;
+	const struct of_device_id *match;
+	enum msm_dp_pll_type type;
+
+	match = of_match_node(dp_pll_dt_match, dev->of_node);
+	if (!match)
+		return -ENODEV;
+
+	if (!strcmp(match->compatible, "qcom,dp-pll-10nm"))
+		type = MSM_DP_PLL_10NM;

This is what of_device_id->data is for, use it to store the type. Can you also check the rest of the driver and do the same there?

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 111

Quoted 6 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +6 -0
+	else
+		type = MSM_DP_PLL_MAX;
+
+	pll = msm_dp_pll_init(pdev, type, 0);
+	if (IS_ERR_OR_NULL(pll)) {
+		dev_info(dev,

Why info level?

Quoted 6 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +6 -0
+			"%s: pll init failed: %ld, need separate pll clk driver\n",
+			__func__, PTR_ERR(pll));
+		return -ENODEV;
+	}
+
+	platform_set_drvdata(pdev, pll);

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 127

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+
+	return 0;
+}
+
+static int dp_pll_driver_remove(struct platform_device *pdev)
+{
+	struct msm_dp_pll *pll = platform_get_drvdata(pdev);
+
+	if (pll) {
+		//msm_dsi_pll_destroy(pll);

Hmm.

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 128

Quoted 1 line
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +1 -0
+		pll = NULL;

No need to clear a local variable

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 131

Quoted 3 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +3 -0
+	}
+
+	platform_set_drvdata(pdev, NULL);

You don't need to clear this either

Quoted 44 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +22 -0
+
+	return 0;
+}
+
+static struct platform_driver dp_pll_platform_driver = {
+	.probe      = dp_pll_driver_probe,
+	.remove     = dp_pll_driver_remove,
+	.driver     = {
+		.name   = "msm_dp_pll",
+		.of_match_table = dp_pll_dt_match,
+	},
+};
+
+void __init msm_dp_pll_driver_register(void)
+{
+	platform_driver_register(&dp_pll_platform_driver);
+}
+
+void __exit msm_dp_pll_driver_unregister(void)
+{
+	platform_driver_unregister(&dp_pll_platform_driver);
+}
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +16 -0
new file mode 100644
index 0000000..d52a81a
@@ -0,0 +1,64 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __DP_PLL_H
+#define __DP_PLL_H
+

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 26

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +10 -0
+#include <linux/clk.h>
+#include <linux/clk-provider.h>
+#include <linux/platform_device.h>
+
+#include "dpu_io_util.h"
+#include "msm_drv.h"
+
+#define PLL_REG_W(base, offset, data)	\
+				writel_relaxed((data), (base) + (offset))
+#define PLL_REG_R(base, offset)	readl_relaxed((base) + (offset))

These macros aren't really useful, tbh. It'd be better to have a function that takes a msm_dp_pll, offset and data.

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 34

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +8 -0
+
+enum msm_dp_pll_type {
+	MSM_DP_PLL_10NM,
+	MSM_DP_PLL_MAX
+};
+
+struct msm_dp_pll {
+	enum msm_dp_pll_type type;

Storing this doesn't seem to gain you anything. So move the dp_pll_type enum into msm_dp_pll.c, turf the _MAX and make embed it in the .data element of the of_device_id structs. Then you can use it when you're initializing and promptly throw it away.

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 39

Quoted 5 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +5 -0
+	struct clk_hw clk_hw;
+	unsigned long	rate;		/* current vco rate */
+	u64		min_rate;	/* min vco rate */
+	u64		max_rate;	/* max vco rate */
+	bool		pll_on;

The clk_hw/etc part of this patch should be reviewed by swboyd (cc'd). It's not really in my wheelhouse, tbh.

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 40

Quoted 1 line
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +1 -0
+	void		*priv;

Was going to comment on using an opaque pointer, but it not used anywhere \o/

Please remove

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 48

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +8 -0
+	/* Pll specific resources like GPIO, power supply, clocks, etc*/
+	struct dss_module_power mp;
+	int (*get_provider)(struct msm_dp_pll *pll,
+			struct clk **link_clk_provider,
+			struct clk **pixel_clk_provider);
+};
+
+#define hw_clk_to_pll(x) container_of(x, struct msm_dp_pll, clk_hw)

Please make this a type-safe inline function.

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 51

Quoted 3 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +3 -0
+
+struct msm_dp_pll *msm_dp_pll_init(struct platform_device *pdev,
+			enum msm_dp_pll_type type, int id);

Remove this and make that func static

Quoted 70 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +13 -0
+
+int msm_dp_pll_util_parse_dt_clock(struct platform_device *pdev,
+					struct msm_dp_pll *pll);
+
+#ifdef CONFIG_DRM_MSM_DP_10NM_PLL
+struct msm_dp_pll *msm_dp_pll_10nm_init(struct platform_device *pdev, int id);
+#else
+struct msm_dp_pll *msm_dp_pll_10nm_init(struct platform_device *pdev, int id)
+{
+	return ERR_PTR(-ENODEV);
+}
+#endif
+#endif /* __DP_PLL_H */
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +51 -0
new file mode 100644
index 0000000..a180413
@@ -0,0 +1,401 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/*
+ * Display Port PLL driver block diagram for branch clocks
+ *
+ *		+------------------------------+
+ *		|         DP_VCO_CLK           |
+ *		|                              |
+ *		|    +-------------------+     |
+ *		|    |   (DP PLL/VCO)    |     |
+ *		|    +---------+---------+     |
+ *		|              v               |
+ *		|   +----------+-----------+   |
+ *		|   | hsclk_divsel_clk_src |   |
+ *		|   +----------+-----------+   |
+ *		+------------------------------+
+ *				|
+ *	 +------------<---------v------------>----------+
+ *	 |                                              |
+ * +-----v------------+                                 |
+ * | dp_link_clk_src  |                                 |
+ * |    divsel_ten    |                                 |
+ * +---------+--------+                                 |
+ *	|                                               |
+ *	|                                               |
+ *	v                                               v
+ * Input to DISPCC block                                |
+ * for link clk, crypto clk                             |
+ * and interface clock                                  |
+ *							|
+ *							|
+ *	+--------<------------+-----------------+---<---+
+ *	|                     |                 |
+ * +-------v------+  +--------v-----+  +--------v------+
+ * | vco_divided  |  | vco_divided  |  | vco_divided   |
+ * |    _clk_src  |  |    _clk_src  |  |    _clk_src   |
+ * |              |  |              |  |               |
+ * |divsel_six    |  |  divsel_two  |  |  divsel_four  |
+ * +-------+------+  +-----+--------+  +--------+------+
+ *         |	           |		        |

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 61

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+ *	v------->----------v-------------<------v
+ *                         |
+ *		+----------+---------+
+ *		|   vco_divided_clk  |
+ *		|       _src_mux     |
+ *		+---------+----------+
+ *                        |
+ *                        v
+ *              Input to DISPCC block
+ *              for DP pixel clock

Some of your vertical lines seem misaligned here, can you please fix this up?

Quoted 5 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +5 -0
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/err.h>

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 76

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+#include <linux/delay.h>
+#include <linux/regmap.h>
+#include <linux/clk.h>
+
+#include "dp_pll_10nm.h"
+
+#define NUM_PROVIDED_CLKS		2
+
+#define DP_LINK_CLK_SRC			0
+#define DP_PIXEL_CLK_SRC		1

Instead of using an array to store the clocks in one place, why not just store a pointer for each clk? Then you can get rid of these and just use the clk directly.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 78

Quoted 2 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +2 -0
+
+static struct dp_pll_10nm *dp_pdb;

This isn't used (nor should it be).

Quoted 11 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +11 -0
+
+/* Op structures */
+static const struct clk_ops dp_10nm_vco_clk_ops = {
+	.recalc_rate = dp_vco_recalc_rate_10nm,
+	.set_rate = dp_vco_set_rate_10nm,
+	.round_rate = dp_vco_round_rate_10nm,
+	.prepare = dp_vco_prepare_10nm,
+	.unprepare = dp_vco_unprepare_10nm,
+};
+
+struct dp_pll_10nm_pclksel {

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 99

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+	struct clk_hw hw;
+
+	/* divider params */
+	u8 shift;
+	u8 width;
+	u8 flags; /* same flags as used by clk_divider struct */
+
+	struct dp_pll_10nm *pll;
+};
+#define to_pll_10nm_pclksel(_hw) container_of(_hw, struct dp_pll_10nm_pclksel, hw)

typesafe static inline please. Everywhere you use pclksel, you just grab ->pll from the result and never use pclksel again. So make the function return dp_pll_10nm * directly and save yourself the local var.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 108

Quoted 9 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +9 -0
+
+static int dp_mux_set_parent_10nm(struct clk_hw *hw, u8 val)
+{
+	struct dp_pll_10nm_pclksel *pclksel = to_pll_10nm_pclksel(hw);
+	struct dp_pll_10nm *dp_res = pclksel->pll;
+	u32 auxclk_div;
+
+	auxclk_div = PLL_REG_R(dp_res->phy_base, DP_PHY_VCO_DIV);
+	auxclk_div &= ~0x03;	/* bits 0 to 1 */

This comment isn't really useful :) Could you please #define all of the hardcoded values in the patch?

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 120

Quoted 12 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +12 -0
+
+	if (val == 0) /* mux parent index = 0 */
+		auxclk_div |= 1;
+	else if (val == 1) /* mux parent index = 1 */
+		auxclk_div |= 2;
+	else if (val == 2) /* mux parent index = 2 */
+		auxclk_div |= 0;
+
+	PLL_REG_W(dp_res->phy_base,
+			DP_PHY_VCO_DIV, auxclk_div);
+	/* Make sure the PHY registers writes are done */
+	wmb();

Same comments about needing wmb to work around using _relaxed

Quoted 22 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +22 -0
+	pr_debug("%s: mux=%d auxclk_div=%x\n", __func__, val, auxclk_div);
+
+	return 0;
+}
+
+static u8 dp_mux_get_parent_10nm(struct clk_hw *hw)
+{
+	u32 auxclk_div = 0;
+	struct dp_pll_10nm_pclksel *pclksel = to_pll_10nm_pclksel(hw);
+	struct dp_pll_10nm *dp_res = pclksel->pll;
+	u8 val = 0;
+
+	pr_err("clk_hw->init->name = %s\n", hw->init->name);
+	auxclk_div = PLL_REG_R(dp_res->phy_base, DP_PHY_VCO_DIV);
+	auxclk_div &= 0x03;
+
+	if (auxclk_div == 1) /* Default divider */
+		val = 0;
+	else if (auxclk_div == 2)
+		val = 1;
+	else if (auxclk_div == 0)
+		val = 2;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 152

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+
+	pr_debug("%s: auxclk_div=%d, val=%d\n", __func__, auxclk_div, val);
+
+	return val;
+}
+
+static int clk_mux_determine_rate(struct clk_hw *hw,
+				     struct clk_rate_request *req)
+{
+	int ret = 0;

no need to init this to 0

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 160

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +8 -0
+
+	ret = __clk_mux_determine_rate_closest(hw, req);
+	if (ret)
+		return ret;
+
+	/* Set the new parent of mux if there is a new valid parent */
+	if (hw->clk && req->best_parent_hw->clk)
+		clk_set_parent(hw->clk, req->best_parent_hw->clk);

What about the return value? All other clk_set_parent calls in this patch are also unchecked, so please add those as well.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 172

Quoted 12 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +12 -0
+
+	return 0;
+}
+
+static unsigned long mux_recalc_rate(struct clk_hw *hw,
+					unsigned long parent_rate)
+{
+	struct clk *div_clk = NULL, *vco_clk = NULL;
+	struct msm_dp_pll *vco = NULL;
+
+	div_clk = clk_get_parent(hw->clk);
+	if (!div_clk)

According to the header documentation, clk_get_parent can return ERR_PTR as well. Same comment applies to other callsites.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 184

Quoted 12 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +12 -0
+		return 0;
+
+	vco_clk = clk_get_parent(div_clk);
+	if (!vco_clk)
+		return 0;
+
+	vco = hw_clk_to_pll(__clk_get_hw(vco_clk));
+	if (!vco)
+		return 0;
+
+	if (vco->rate == DP_VCO_HSCLK_RATE_8100MHZDIV1000)
+		return (vco->rate / 6);

Unnecessary () here and below

Quoted 9 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +9 -0
+	else if (vco->rate == DP_VCO_HSCLK_RATE_5400MHZDIV1000)
+		return (vco->rate / 4);
+	else
+		return (vco->rate / 2);
+}
+
+static int dp_pll_10nm_get_provider(struct msm_dp_pll *pll,
+				     struct clk **link_clk_provider,
+				     struct clk **pixel_clk_provider)

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 203

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+{
+	struct dp_pll_10nm *pll_10nm = to_dp_pll_10nm(pll);
+	struct clk_hw_onecell_data *hw_data = pll_10nm->hw_data;
+
+	if (link_clk_provider)
+		*link_clk_provider = hw_data->hws[DP_LINK_CLK_SRC]->clk;
+	if (pixel_clk_provider)
+		*pixel_clk_provider = hw_data->hws[DP_PIXEL_CLK_SRC]->clk;
+
+	return 0;

Why have a return value when the only place always returns 0? Make it void and simplify error checking at the callsite.

Quoted 24 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +24 -0
+}
+
+static const struct clk_ops dp_10nm_pclksel_clk_ops = {
+	.get_parent = dp_mux_get_parent_10nm,
+	.set_parent = dp_mux_set_parent_10nm,
+	.recalc_rate = mux_recalc_rate,
+	.determine_rate = clk_mux_determine_rate,
+};
+
+static struct clk_hw *dp_pll_10nm_pixel_clk_sel(struct dp_pll_10nm *pll_10nm)
+{
+	struct device *dev = &pll_10nm->pdev->dev;
+	struct dp_pll_10nm_pclksel *pll_pclksel;
+	struct clk_init_data pclksel_init = {
+		.parent_names = (const char *[]){
+				"dp_vco_divsel_two_clk_src",
+				"dp_vco_divsel_four_clk_src",
+				"dp_vco_divsel_six_clk_src" },
+		.num_parents = 3,
+		.name = "dp_vco_divided_clk_src_mux",
+		.flags = CLK_IGNORE_UNUSED,
+		.ops = &dp_10nm_pclksel_clk_ops,
+	};
+	int ret;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 237

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+
+	pll_pclksel = devm_kzalloc(dev, sizeof(*pll_pclksel), GFP_KERNEL);
+	if (!pll_pclksel)
+		return ERR_PTR(-ENOMEM);
+
+	pll_pclksel->pll = pll_10nm;
+	pll_pclksel->shift = 0;
+	pll_pclksel->width = 4;
+	pll_pclksel->flags = CLK_DIVIDER_ONE_BASED;
+	pll_pclksel->hw.init = &pclksel_init;

pclksel_init goes out of scope at the end of the function, yet it is persisted in pll_pclksel. That should be fixed.

Quoted 25 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +25 -0
+
+	ret = clk_hw_register(dev, &pll_pclksel->hw);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return &pll_pclksel->hw;
+}
+
+static int dp_pll_10nm_register(struct dp_pll_10nm *pll_10nm)
+{
+	char clk_name[32], parent[32], vco_name[32];
+	struct clk_init_data vco_init = {
+		.parent_names = (const char *[]){ "bi_tcxo" },
+		.num_parents = 1,
+		.name = vco_name,
+		.flags = CLK_IGNORE_UNUSED,
+		.ops = &dp_10nm_vco_clk_ops,
+	};
+	struct device *dev = &pll_10nm->pdev->dev;
+	struct clk_hw **hws = pll_10nm->hws;
+	struct clk_hw_onecell_data *hw_data;
+	struct clk_hw *hw;
+	int num = 0;
+	int ret;
+

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 272

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+	DBG("DP->id = %d", pll_10nm->id);
+
+	hw_data = devm_kzalloc(dev, sizeof(*hw_data) +
+			       NUM_PROVIDED_CLKS * sizeof(struct clk_hw *),
+			       GFP_KERNEL);
+	if (!hw_data)
+		return -ENOMEM;
+
+	snprintf(vco_name, 32, "dp_vco_clk");
+	pll_10nm->base.clk_hw.init = &vco_init;

Same comment about scope here

Quoted 34 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +34 -0
+	ret = clk_hw_register(dev, &pll_10nm->base.clk_hw);
+	if (ret)
+		return ret;
+	hws[num++] = &pll_10nm->base.clk_hw;
+
+	snprintf(clk_name, 32, "dp_link_clk_divsel_ten");
+	snprintf(parent, 32, "dp_vco_clk");
+	hw = clk_hw_register_fixed_factor(dev, clk_name, parent,
+					  CLK_SET_RATE_PARENT, 1, 10);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+	hws[num++] = hw;
+	hw_data->hws[DP_LINK_CLK_SRC] = hw;
+
+	snprintf(clk_name, 32, "dp_vco_divsel_two_clk_src");
+	snprintf(parent, 32, "dp_vco_clk");
+	hw = clk_hw_register_fixed_factor(dev, clk_name, parent,
+					  0, 1, 2);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+	hws[num++] = hw;
+
+	snprintf(clk_name, 32, "dp_vco_divsel_four_clk_src");
+	snprintf(parent, 32, "dp_vco_clk");
+	hw = clk_hw_register_fixed_factor(dev, clk_name, parent,
+					  0, 1, 4);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+	hws[num++] = hw;
+
+	snprintf(clk_name, 32, "dp_vco_divsel_six_clk_src");
+	snprintf(parent, 32, "dp_vco_clk");
+	hw = clk_hw_register_fixed_factor(dev, clk_name, parent,
+					  0, 1, 6);

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 316

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+	hws[num++] = hw;
+
+	hw = dp_pll_10nm_pixel_clk_sel(pll_10nm);
+	if (IS_ERR(hw))
+		return PTR_ERR(hw);
+
+	hws[num++] = hw;
+	hw_data->hws[DP_PIXEL_CLK_SRC] = hw;

I'm going to leave this chunk for Stephen to comment on, but again I'd rather not store these clocks as an array and do string lookups on them.

Quoted 20 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +20 -0
+
+	pll_10nm->num_hws = num;
+
+	hw_data->num = NUM_PROVIDED_CLKS;
+	pll_10nm->hw_data = hw_data;
+
+	ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
+				     pll_10nm->hw_data);
+	if (ret) {
+		dev_err(dev, "failed to register clk provider: %d\n", ret);
+		return ret;
+	}
+
+	return ret;
+}
+
+struct msm_dp_pll *msm_dp_pll_10nm_init(struct platform_device *pdev, int id)
+{
+	struct dp_pll_10nm *dp_10nm_pll;
+	struct msm_dp_pll *pll;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 346

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+	int ret;
+
+	if (!pdev)
+		return ERR_PTR(-ENODEV);
+
+	dp_10nm_pll = devm_kzalloc(&pdev->dev, sizeof(*dp_10nm_pll), GFP_KERNEL);
+	if (!dp_10nm_pll)
+		return ERR_PTR(-ENOMEM);
+
+	DBG("DP PLL%d", id);

Please remove (or convert to DRM_DEV_DEBUG)

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 354

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +8 -0
+
+	dp_10nm_pll->pdev = pdev;
+	dp_10nm_pll->id = id;
+	dp_pdb = dp_10nm_pll;
+
+	dp_10nm_pll->pll_base = msm_ioremap(pdev, "pll_base", "DP_PLL");
+	if (IS_ERR_OR_NULL(dp_10nm_pll->pll_base)) {
+		dev_err(&pdev->dev, "failed to map CMN PLL base\n");

Print the error if pll_base is ERR_PTR, same for below.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 355

Quoted 1 line
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +1 -0
+		return ERR_PTR(-ENOMEM);

You should preserve the error if pll_base is an ERR_PTR, same for below.

Quoted 14 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +14 -0
+	}
+
+	dp_10nm_pll->phy_base = msm_ioremap(pdev, "phy_base", "DP_PHY");
+	if (IS_ERR_OR_NULL(dp_10nm_pll->phy_base)) {
+		dev_err(&pdev->dev, "failed to map CMN PHY base\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	dp_10nm_pll->ln_tx0_base = msm_ioremap(pdev, "ln_tx0_base", "DP_LN_TX0");
+	if (IS_ERR_OR_NULL(dp_10nm_pll->ln_tx0_base)) {
+		dev_err(&pdev->dev, "failed to map CMN LN_TX0 base\n");
+		return ERR_PTR(-ENOMEM);
+	}
+

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 379

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+	dp_10nm_pll->ln_tx1_base = msm_ioremap(pdev, "ln_tx1_base", "DP_LN_TX1");
+	if (IS_ERR_OR_NULL(dp_10nm_pll->ln_tx1_base)) {
+		dev_err(&pdev->dev, "failed to map CMN LN_TX1 base\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	ret = of_property_read_u32(pdev->dev.of_node, "cell-index",
+				&dp_10nm_pll->index);
+	if (ret) {
+		pr_err("Unable to get the cell-index ret=%d\n", ret);

If this is truly an error condition, we should return an error. If it's not, downgrade this to info

Quoted 38 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +22 -0
+		dp_10nm_pll->index = 0;
+	}
+
+	ret = msm_dp_pll_util_parse_dt_clock(pdev, &dp_10nm_pll->base);
+	if (ret) {
+		pr_err("Unable to parse dt clocks ret=%d\n", ret);
+		return ERR_PTR(ret);
+	}
+
+	ret = dp_pll_10nm_register(dp_10nm_pll);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register PLL: %d\n", ret);
+		return ERR_PTR(ret);
+	}
+
+	pll = &dp_10nm_pll->base;
+	pll->min_rate = DP_VCO_HSCLK_RATE_1620MHZDIV1000;
+	pll->max_rate = DP_VCO_HSCLK_RATE_8100MHZDIV1000;
+	pll->get_provider = dp_pll_10nm_get_provider;
+
+	return pll;
+}
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +10 -0
new file mode 100644
index 0000000..f966beb
@@ -0,0 +1,94 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h line 20

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +10 -0
+ *
+ */
+
+#ifndef __DP_PLL_10NM_H
+#define __DP_PLL_10NM_H
+
+#include "dp_pll.h"
+#include "dp_reg.h"
+
+#define DP_VCO_HSCLK_RATE_1620MHZDIV1000	1620000UL

Isn't MHZDIV1000 just KHZ? Same for below

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h line 28

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +8 -0
+#define DP_VCO_HSCLK_RATE_2700MHZDIV1000	2700000UL
+#define DP_VCO_HSCLK_RATE_5400MHZDIV1000	5400000UL
+#define DP_VCO_HSCLK_RATE_8100MHZDIV1000	8100000UL
+
+#define NUM_DP_CLOCKS_MAX			6
+
+#define DP_PHY_PLL_POLL_SLEEP_US		500
+#define DP_PHY_PLL_POLL_TIMEOUT_US		10000

These can go in the c file (and probably the others too)

Quoted 46 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +46 -0
+
+#define DP_VCO_RATE_8100MHZDIV1000		8100000UL
+#define DP_VCO_RATE_9720MHZDIV1000		9720000UL
+#define DP_VCO_RATE_10800MHZDIV1000		10800000UL
+
+struct dp_pll_10nm {
+	struct msm_dp_pll base;
+
+	int id;
+	struct platform_device *pdev;
+
+	void __iomem *pll_base;
+	void __iomem *phy_base;
+	void __iomem *ln_tx0_base;
+	void __iomem *ln_tx1_base;
+
+	/* private clocks: */
+	struct clk_hw *hws[NUM_DP_CLOCKS_MAX];
+	u32 num_hws;
+
+	/* clock-provider: */
+	struct clk_hw_onecell_data *hw_data;
+
+	/* lane and orientation settings */
+	u8 lane_cnt;
+	u8 orientation;
+
+	/* COM PHY settings */
+	u32 hsclk_sel;
+	u32 dec_start_mode0;
+	u32 div_frac_start1_mode0;
+	u32 div_frac_start2_mode0;
+	u32 div_frac_start3_mode0;
+	u32 integloop_gain0_mode0;
+	u32 integloop_gain1_mode0;
+	u32 vco_tune_map;
+	u32 lock_cmp1_mode0;
+	u32 lock_cmp2_mode0;
+	u32 lock_cmp3_mode0;
+	u32 lock_cmp_en;
+
+	/* PHY vco divider */
+	u32 phy_vco_div;
+	/*
+	 * Certain pll's needs to update the same vco rate after resume in
+	 * suspend/resume scenario. Cached the vco rate for such plls.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h line 84

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +10 -0
+	 */
+	unsigned long	vco_cached_rate;
+	u32		cached_cfg0;
+	u32		cached_cfg1;
+	u32		cached_outdiv;
+
+	uint32_t index;
+};
+
+#define to_dp_pll_10nm(x)	container_of(x, struct dp_pll_10nm, base)

typesafe inline pls

Quoted 112 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +10 -0
+
+int dp_vco_set_rate_10nm(struct clk_hw *hw, unsigned long rate,
+				unsigned long parent_rate);
+unsigned long dp_vco_recalc_rate_10nm(struct clk_hw *hw,
+				unsigned long parent_rate);
+long dp_vco_round_rate_10nm(struct clk_hw *hw, unsigned long rate,
+				unsigned long *parent_rate);
+int dp_vco_prepare_10nm(struct clk_hw *hw);
+void dp_vco_unprepare_10nm(struct clk_hw *hw);
+#endif /* __DP_PLL_10NM_H */
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +96 -0
new file mode 100644
index 0000000..9eb6881
@@ -0,0 +1,531 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#define pr_fmt(fmt)	"%s: " fmt, __func__
+
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/iopoll.h>
+#include <linux/delay.h>
+
+#include "dp_pll.h"
+#include "dp_pll_10nm.h"
+#include "dp_extcon.h"
+
+static int dp_vco_pll_init_db_10nm(struct msm_dp_pll *pll,
+		unsigned long rate)
+{
+	struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+	u32 spare_value = 0;
+
+	spare_value = PLL_REG_R(dp_res->phy_base, DP_PHY_SPARE0);
+	dp_res->lane_cnt = spare_value & 0x0F;
+	dp_res->orientation = (spare_value & 0xF0) >> 4;
+
+	pr_debug("%s: spare_value=0x%x, ln_cnt=0x%x, orientation=0x%x\n",
+			__func__, spare_value, dp_res->lane_cnt, dp_res->orientation);
+
+	switch (rate) {
+	case DP_VCO_HSCLK_RATE_1620MHZDIV1000:
+		pr_debug("%s: VCO rate: %ld\n", __func__,
+				DP_VCO_RATE_9720MHZDIV1000);
+		dp_res->hsclk_sel = 0x0c;
+		dp_res->dec_start_mode0 = 0x69;
+		dp_res->div_frac_start1_mode0 = 0x00;
+		dp_res->div_frac_start2_mode0 = 0x80;
+		dp_res->div_frac_start3_mode0 = 0x07;
+		dp_res->integloop_gain0_mode0 = 0x3f;
+		dp_res->integloop_gain1_mode0 = 0x00;
+		dp_res->vco_tune_map = 0x00;
+		dp_res->lock_cmp1_mode0 = 0x6f;
+		dp_res->lock_cmp2_mode0 = 0x08;
+		dp_res->lock_cmp3_mode0 = 0x00;
+		dp_res->phy_vco_div = 0x1;
+		dp_res->lock_cmp_en = 0x00;
+		break;
+	case DP_VCO_HSCLK_RATE_2700MHZDIV1000:
+		pr_debug("%s: VCO rate: %ld\n", __func__,
+				DP_VCO_RATE_10800MHZDIV1000);
+		dp_res->hsclk_sel = 0x04;
+		dp_res->dec_start_mode0 = 0x69;
+		dp_res->div_frac_start1_mode0 = 0x00;
+		dp_res->div_frac_start2_mode0 = 0x80;
+		dp_res->div_frac_start3_mode0 = 0x07;
+		dp_res->integloop_gain0_mode0 = 0x3f;
+		dp_res->integloop_gain1_mode0 = 0x00;
+		dp_res->vco_tune_map = 0x00;
+		dp_res->lock_cmp1_mode0 = 0x0f;
+		dp_res->lock_cmp2_mode0 = 0x0e;
+		dp_res->lock_cmp3_mode0 = 0x00;
+		dp_res->phy_vco_div = 0x1;
+		dp_res->lock_cmp_en = 0x00;
+		break;
+	case DP_VCO_HSCLK_RATE_5400MHZDIV1000:
+		pr_debug("%s: VCO rate: %ld\n", __func__,
+				DP_VCO_RATE_10800MHZDIV1000);
+		dp_res->hsclk_sel = 0x00;
+		dp_res->dec_start_mode0 = 0x8c;
+		dp_res->div_frac_start1_mode0 = 0x00;
+		dp_res->div_frac_start2_mode0 = 0x00;
+		dp_res->div_frac_start3_mode0 = 0x0a;
+		dp_res->integloop_gain0_mode0 = 0x3f;
+		dp_res->integloop_gain1_mode0 = 0x00;
+		dp_res->vco_tune_map = 0x00;
+		dp_res->lock_cmp1_mode0 = 0x1f;
+		dp_res->lock_cmp2_mode0 = 0x1c;
+		dp_res->lock_cmp3_mode0 = 0x00;
+		dp_res->phy_vco_div = 0x2;
+		dp_res->lock_cmp_en = 0x00;
+		break;
+	case DP_VCO_HSCLK_RATE_8100MHZDIV1000:
+		pr_debug("%s: VCO rate: %ld\n", __func__,
+				DP_VCO_RATE_8100MHZDIV1000);
+		dp_res->hsclk_sel = 0x03;
+		dp_res->dec_start_mode0 = 0x69;
+		dp_res->div_frac_start1_mode0 = 0x00;
+		dp_res->div_frac_start2_mode0 = 0x80;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 106

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+		dp_res->div_frac_start3_mode0 = 0x07;
+		dp_res->integloop_gain0_mode0 = 0x3f;
+		dp_res->integloop_gain1_mode0 = 0x00;
+		dp_res->vco_tune_map = 0x00;
+		dp_res->lock_cmp1_mode0 = 0x2f;
+		dp_res->lock_cmp2_mode0 = 0x2a;
+		dp_res->lock_cmp3_mode0 = 0x00;
+		dp_res->phy_vco_div = 0x0;
+		dp_res->lock_cmp_en = 0x08;
+		break;

Since this is all static, a static const lookup table would probably be more appropriate.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 108

Quoted 2 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +2 -0
+	default:
+		return -EINVAL;

Log this please

Quoted 216 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +216 -0
+	}
+	return 0;
+}
+
+static int dp_config_vco_rate_10nm(struct msm_dp_pll *pll,
+		unsigned long rate)
+{
+	u32 res = 0;
+	struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+
+	res = dp_vco_pll_init_db_10nm(pll, rate);
+	if (res) {
+		pr_err("VCO Init DB failed\n");
+		return res;
+	}
+
+	if (dp_res->lane_cnt != 4) {
+		if (dp_res->orientation == ORIENTATION_CC2)
+			PLL_REG_W(dp_res->phy_base, DP_PHY_PD_CTL, 0x6d);
+		else
+			PLL_REG_W(dp_res->phy_base, DP_PHY_PD_CTL, 0x75);
+	} else {
+		PLL_REG_W(dp_res->phy_base, DP_PHY_PD_CTL, 0x7d);
+	}
+
+	/* Make sure the PHY register writes are done */
+	wmb();
+
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_SVS_MODE_CLK_SEL, 0x01);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_SYSCLK_EN_SEL, 0x37);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_SYS_CLK_CTRL, 0x02);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_CLK_ENABLE1, 0x0e);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_SYSCLK_BUF_ENABLE, 0x06);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_CLK_SEL, 0x30);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_CMN_CONFIG, 0x02);
+
+	/* Different for each clock rates */
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_HSCLK_SEL, dp_res->hsclk_sel);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_DEC_START_MODE0, dp_res->dec_start_mode0);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_DIV_FRAC_START1_MODE0, dp_res->div_frac_start1_mode0);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_DIV_FRAC_START2_MODE0, dp_res->div_frac_start2_mode0);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_DIV_FRAC_START3_MODE0, dp_res->div_frac_start3_mode0);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_INTEGLOOP_GAIN0_MODE0, dp_res->integloop_gain0_mode0);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_INTEGLOOP_GAIN1_MODE0, dp_res->integloop_gain1_mode0);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_VCO_TUNE_MAP, dp_res->vco_tune_map);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_LOCK_CMP1_MODE0, dp_res->lock_cmp1_mode0);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_LOCK_CMP2_MODE0, dp_res->lock_cmp2_mode0);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_LOCK_CMP3_MODE0, dp_res->lock_cmp3_mode0);
+	/* Make sure the PLL register writes are done */
+	wmb();
+
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_BG_TIMER, 0x0a);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_CORECLK_DIV_MODE0, 0x0a);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_VCO_TUNE_CTRL, 0x00);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x3f);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_CORE_CLK_EN, 0x1f);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_PLL_IVCO, 0x07);
+	PLL_REG_W(dp_res->pll_base,
+		QSERDES_COM_LOCK_CMP_EN, dp_res->lock_cmp_en);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_PLL_CCTRL_MODE0, 0x36);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_PLL_RCTRL_MODE0, 0x16);
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_CP_CTRL_MODE0, 0x06);
+	/* Make sure the PHY register writes are done */
+	wmb();
+
+	if (dp_res->orientation == ORIENTATION_CC2)
+		PLL_REG_W(dp_res->phy_base, DP_PHY_MODE, 0x4c);
+	else
+		PLL_REG_W(dp_res->phy_base, DP_PHY_MODE, 0x5c);
+	/* Make sure the PLL register writes are done */
+	wmb();
+
+	/* TX Lane configuration */
+	PLL_REG_W(dp_res->phy_base,
+			DP_PHY_TX0_TX1_LANE_CTL, 0x05);
+	PLL_REG_W(dp_res->phy_base,
+			DP_PHY_TX2_TX3_LANE_CTL, 0x05);
+
+	/* TX-0 register configuration */
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_TRANSCEIVER_BIAS_EN, 0x1a);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_VMODE_CTRL1, 0x40);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_PRE_STALL_LDO_BOOST_EN, 0x30);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_INTERFACE_SELECT, 0x3d);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_CLKBUF_ENABLE, 0x0f);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_RESET_TSYNC_EN, 0x03);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_TRAN_DRVR_EMP_EN, 0x03);
+	PLL_REG_W(dp_res->ln_tx0_base,
+		TXn_PARRATE_REC_DETECT_IDLE_EN, 0x00);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_INTERFACE_MODE, 0x00);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_BAND, 0x4);
+
+	/* TX-1 register configuration */
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_TRANSCEIVER_BIAS_EN, 0x1a);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_VMODE_CTRL1, 0x40);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_PRE_STALL_LDO_BOOST_EN, 0x30);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_INTERFACE_SELECT, 0x3d);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_CLKBUF_ENABLE, 0x0f);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_RESET_TSYNC_EN, 0x03);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_TRAN_DRVR_EMP_EN, 0x03);
+	PLL_REG_W(dp_res->ln_tx1_base,
+		TXn_PARRATE_REC_DETECT_IDLE_EN, 0x00);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_INTERFACE_MODE, 0x00);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_BAND, 0x4);
+	/* Make sure the PHY register writes are done */
+	wmb();
+
+	/* dependent on the vco frequency */
+	PLL_REG_W(dp_res->phy_base, DP_PHY_VCO_DIV, dp_res->phy_vco_div);
+
+	return res;
+}
+
+static bool dp_10nm_pll_lock_status(struct dp_pll_10nm *dp_res)
+{
+	u32 status;
+	bool pll_locked;
+
+	/* poll for PLL lock status */
+	if (readl_poll_timeout_atomic((dp_res->pll_base +
+			QSERDES_COM_C_READY_STATUS),
+			status,
+			((status & BIT(0)) > 0),
+			DP_PHY_PLL_POLL_SLEEP_US,
+			DP_PHY_PLL_POLL_TIMEOUT_US)) {
+		pr_err("%s: C_READY status is not high. Status=%x\n",
+				__func__, status);
+		pll_locked = false;
+	} else {
+		pll_locked = true;
+	}
+
+	return pll_locked;
+}
+
+static bool dp_10nm_phy_rdy_status(struct dp_pll_10nm *dp_res)
+{
+	u32 status;
+	bool phy_ready = true;
+
+	/* poll for PHY ready status */
+	if (readl_poll_timeout_atomic((dp_res->phy_base +
+			DP_PHY_STATUS),
+			status,
+			((status & (BIT(1))) > 0),
+			DP_PHY_PLL_POLL_SLEEP_US,
+			DP_PHY_PLL_POLL_TIMEOUT_US)) {
+		pr_err("%s: Phy_ready is not high. Status=%x\n",
+				__func__, status);
+		phy_ready = false;
+	}
+
+	return phy_ready;
+}
+
+static int dp_pll_enable_10nm(struct clk_hw *hw)
+{
+	int rc = 0;
+	struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+	struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+	u32 bias_en, drvr_en;
+
+	PLL_REG_W(dp_res->phy_base, DP_PHY_AUX_CFG2, 0x04);
+	PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x01);
+	PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x05);
+	PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x01);
+	PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x09);
+	wmb(); /* Make sure the PHY register writes are done */
+
+	PLL_REG_W(dp_res->pll_base, QSERDES_COM_RESETSM_CNTRL, 0x20);
+	wmb();	/* Make sure the PLL register writes are done */
+
+	if (!dp_10nm_pll_lock_status(dp_res)) {
+		rc = -EINVAL;
+		goto lock_err;
+	}
+
+	PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x19);
+	/* Make sure the PHY register writes are done */
+	wmb();
+	/* poll for PHY ready status */
+	if (!dp_10nm_phy_rdy_status(dp_res)) {
+		rc = -EINVAL;
+		goto lock_err;
+	}
+
+	pr_debug("%s: PLL is locked\n", __func__);
+
+	if (dp_res->lane_cnt == 1) {
+		bias_en = 0x3e;
+		drvr_en = 0x13;
+	} else {
+		bias_en = 0x3f;
+		drvr_en = 0x10;
+	}
+
+	if (dp_res->lane_cnt != 4) {
+		if (dp_res->orientation == ORIENTATION_CC1) {
+			PLL_REG_W(dp_res->ln_tx1_base,
+				TXn_HIGHZ_DRVR_EN, drvr_en);
+			PLL_REG_W(dp_res->ln_tx1_base,
+				TXn_TRANSCEIVER_BIAS_EN, bias_en);
+		} else {
+			PLL_REG_W(dp_res->ln_tx0_base,
+				TXn_HIGHZ_DRVR_EN, drvr_en);
+			PLL_REG_W(dp_res->ln_tx0_base,

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 334

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+				TXn_TRANSCEIVER_BIAS_EN, bias_en);
+		}
+	} else {
+		PLL_REG_W(dp_res->ln_tx0_base, TXn_HIGHZ_DRVR_EN, drvr_en);
+		PLL_REG_W(dp_res->ln_tx0_base,
+			TXn_TRANSCEIVER_BIAS_EN, bias_en);
+		PLL_REG_W(dp_res->ln_tx1_base, TXn_HIGHZ_DRVR_EN, drvr_en);
+		PLL_REG_W(dp_res->ln_tx1_base,
+			TXn_TRANSCEIVER_BIAS_EN, bias_en);
+	}

I think you could probably simplify this code block with a bit of effort, especially the top condition.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 339

Quoted 5 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +5 -0
+
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_POL_INV, 0x0a);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_POL_INV, 0x0a);
+	PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x18);
+	udelay(2000);

why udelay?

Quoted 18 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +18 -0
+
+	PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x19);
+
+	/*
+	 * Make sure all the register writes are completed before
+	 * doing any other operation
+	 */
+	wmb();
+
+	/* poll for PHY ready status */
+	if (!dp_10nm_phy_rdy_status(dp_res)) {
+		rc = -EINVAL;
+		goto lock_err;
+	}
+
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_DRV_LVL, 0x38);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_DRV_LVL, 0x38);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_EMP_POST1_LVL, 0x20);

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 367

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_EMP_POST1_LVL, 0x20);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_RES_CODE_LANE_OFFSET_TX, 0x06);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_RES_CODE_LANE_OFFSET_TX, 0x06);
+	PLL_REG_W(dp_res->ln_tx0_base, TXn_RES_CODE_LANE_OFFSET_RX, 0x07);
+	PLL_REG_W(dp_res->ln_tx1_base, TXn_RES_CODE_LANE_OFFSET_RX, 0x07);
+	/* Make sure the PHY register writes are done */
+	wmb();
+
+lock_err:
+	return rc;

Remove lock_err and return directly above.

Quoted 19 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +19 -0
+}
+
+static int dp_pll_disable_10nm(struct clk_hw *hw)
+{
+	int rc = 0;
+	struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+	struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+
+	/* Assert DP PHY power down */
+	PLL_REG_W(dp_res->phy_base, DP_PHY_PD_CTL, 0x2);
+	/*
+	 * Make sure all the register writes to disable PLL are
+	 * completed before doing any other operation
+	 */
+	wmb();
+
+	return rc;
+}
+

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 396

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+
+int dp_vco_prepare_10nm(struct clk_hw *hw)
+{
+	int rc = 0;
+	struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+	struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+
+	pr_debug("rate=%ld\n", pll->rate);
+	if ((dp_res->vco_cached_rate != 0)
+		&& (dp_res->vco_cached_rate == pll->rate)) {
	if (dp_res->vco_cached_rate && dp_res->vco_cached_rate == pll->rate) {
Quoted 7 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +7 -0
+		rc = pll->clk_hw.init->ops->set_rate(hw,
+			dp_res->vco_cached_rate, dp_res->vco_cached_rate);
+		if (rc) {
+			pr_err("index=%d vco_set_rate failed. rc=%d\n",
+				rc, dp_res->index);
+			goto error;
+		}

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 413

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+	}
+
+	rc = dp_pll_enable_10nm(hw);
+	if (rc) {
+		pr_err("ndx=%d failed to enable dp pll\n",
+					dp_res->index);
+		goto error;
+	}
+
+	pll->pll_on = true;

Do you need locking around the prepare/unprepare functions?

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 415

Quoted 2 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +2 -0
+error:
+	return rc;

Same comment as always

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+}
+
+void dp_vco_unprepare_10nm(struct clk_hw *hw)
+{
+	struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+	struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+
+	if (!dp_res) {
+		pr_err("Invalid input parameter\n");
+		return;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 435

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+	}
+
+	if (!pll->pll_on) {
+		pr_err("pll resource can't be enabled\n");
+		return;
+	}
+	dp_res->vco_cached_rate = pll->rate;
+	dp_pll_disable_10nm(hw);
+
+	//dp_res->handoff_resources = false;

??

Quoted 4 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +4 -0
+	pll->pll_on = false;
+}
+
+int dp_vco_set_rate_10nm(struct clk_hw *hw, unsigned long rate,

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 449

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+					unsigned long parent_rate)
+{
+	struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+	int rc;
+
+	pr_debug("DP lane CLK rate=%ld\n", rate);
+
+	rc = dp_config_vco_rate_10nm(pll, rate);
+	if (rc)
+		pr_err("%s: Failed to set clk rate\n", __func__);

Should you return early here?

Quoted 49 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +49 -0
+
+	pll->rate = rate;
+
+	return 0;
+}
+
+unsigned long dp_vco_recalc_rate_10nm(struct clk_hw *hw,
+					unsigned long parent_rate)
+{
+	struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+	struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+	u32 div, hsclk_div, link_clk_div = 0;
+	u64 vco_rate;
+
+	div = PLL_REG_R(dp_res->pll_base, QSERDES_COM_HSCLK_SEL);
+	div &= 0x0f;
+
+	if (div == 12)
+		hsclk_div = 6; /* Default */
+	else if (div == 4)
+		hsclk_div = 4;
+	else if (div == 0)
+		hsclk_div = 2;
+	else if (div == 3)
+		hsclk_div = 1;
+	else {
+		pr_debug("unknown divider. forcing to default\n");
+		hsclk_div = 5;
+	}
+
+	div = PLL_REG_R(dp_res->phy_base, DP_PHY_AUX_CFG2);
+	div >>= 2;
+
+	if ((div & 0x3) == 0)
+		link_clk_div = 5;
+	else if ((div & 0x3) == 1)
+		link_clk_div = 10;
+	else if ((div & 0x3) == 2)
+		link_clk_div = 20;
+	else
+		pr_err("%s: unsupported div. Phy_mode: %d\n", __func__, div);
+
+	if (link_clk_div == 20) {
+		vco_rate = DP_VCO_HSCLK_RATE_2700MHZDIV1000;
+	} else {
+		if (hsclk_div == 6)
+			vco_rate = DP_VCO_HSCLK_RATE_1620MHZDIV1000;
+		else if (hsclk_div == 4)
+			vco_rate = DP_VCO_HSCLK_RATE_2700MHZDIV1000;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 508

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+		else if (hsclk_div == 2)
+			vco_rate = DP_VCO_HSCLK_RATE_5400MHZDIV1000;
+		else
+			vco_rate = DP_VCO_HSCLK_RATE_8100MHZDIV1000;
+	}
+
+	pr_debug("returning vco rate = %lu\n", (unsigned long)vco_rate);
+
+	dp_res->vco_cached_rate = pll->rate = vco_rate;
+	return (unsigned long)vco_rate;

Hopefully this function will become easier to parse with #define'd values

Quoted 6 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +6 -0
+}
+
+long dp_vco_round_rate_10nm(struct clk_hw *hw, unsigned long rate,
+			unsigned long *parent_rate)
+{
+	unsigned long rrate = rate;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 524

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+	struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+
+	if (rate <= pll->min_rate)
+		rrate = pll->min_rate;
+	else if (rate <= DP_VCO_HSCLK_RATE_2700MHZDIV1000)
+		rrate = DP_VCO_HSCLK_RATE_2700MHZDIV1000;
+	else if (rate <= DP_VCO_HSCLK_RATE_5400MHZDIV1000)
+		rrate = DP_VCO_HSCLK_RATE_5400MHZDIV1000;
+	else
+		rrate = pll->max_rate;

You're assuming min_rate is < 2.7MHz and max_rate > 5.4 MHz. This is true in the current code, but could change in the future. Fortunatley min/max_rate are only used here. So delete them from the struct and use the DP_VCO_HSCLK_RATE_* values directly here.

Quoted 11 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +7 -0
+
+	pr_debug("%s: rrate=%ld\n", __func__, rrate);
+
+	*parent_rate = rrate;
+	return rrate;
+}
+
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#21 lore raw

Re: [Freedreno] [DPU PATCH 3/3] drm/msm/dp: add support for DP PLL driver

Quoted 28 lines · Sean Paul
Quoted 27 lines · Chandan Uddaraju

Add the needed DP PLL specific files to support
display port interface on msm targets.

The DP driver calls the DP PLL driver registration. The DP driver sets the link and pixel clock sources.

---
 drivers/gpu/drm/msm/Kconfig                   |  16 +
 drivers/gpu/drm/msm/Makefile                  |   6 +
 drivers/gpu/drm/msm/dp/dp_ctrl.c              |   1 +
 drivers/gpu/drm/msm/dp/dp_display.c           |  50 +++
 drivers/gpu/drm/msm/dp/dp_display.h           |   3 +
 drivers/gpu/drm/msm/dp/dp_parser.h            |   3 +
 drivers/gpu/drm/msm/dp/dp_power.c             |  77 +++-
 drivers/gpu/drm/msm/dp/dp_power.h             |   2 +
 drivers/gpu/drm/msm/dp/pll/dp_pll.c           | 153 ++++++++
 drivers/gpu/drm/msm/dp/pll/dp_pll.h           |  64 ++++
 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c      | 401 +++++++++++++++++++
 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h      |  94 +++++
 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c | 531 ++++++++++++++++++++++++++
 13 files changed, 1389 insertions(+), 12 deletions(-)
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll.c
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll.h
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h
 create mode 100644 drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c

<snip>

Quoted 17 lines
Quoted 4 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +4 -0
+struct msm_dp_pll *msm_dp_pll_10nm_init(struct platform_device *pdev, int id)
+{
+	struct dp_pll_10nm *dp_10nm_pll;
+	struct msm_dp_pll *pll;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 346

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+	int ret;
+
+	if (!pdev)
+		return ERR_PTR(-ENODEV);
+
+	dp_10nm_pll = devm_kzalloc(&pdev->dev, sizeof(*dp_10nm_pll), GFP_KERNEL);
+	if (!dp_10nm_pll)
+		return ERR_PTR(-ENOMEM);
+
+	DBG("DP PLL%d", id);

Please remove (or convert to DRM_DEV_DEBUG)

Quoted 10 lines

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 354

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +8 -0
+
+	dp_10nm_pll->pdev = pdev;
+	dp_10nm_pll->id = id;
+	dp_pdb = dp_10nm_pll;
+
+	dp_10nm_pll->pll_base = msm_ioremap(pdev, "pll_base", "DP_PLL");
+	if (IS_ERR_OR_NULL(dp_10nm_pll->pll_base)) {
+		dev_err(&pdev->dev, "failed to map CMN PLL base\n");

Print the error if pll_base is ERR_PTR, same for below.

FWIW the return value from msm_ioremap is always ERR_PTR never NULL. And msm_ioremap prints error messages on all failures so all you need is:

if (IS_ERR(ptr))

    return ERR_CAST(ptr);
Quoted 15 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		return ERR_PTR(-ENOMEM);

You should preserve the error if pll_base is an ERR_PTR, same for below.

Quoted 11 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +11 -0
+	}
+
+	dp_10nm_pll->phy_base = msm_ioremap(pdev, "phy_base", "DP_PHY");
+	if (IS_ERR_OR_NULL(dp_10nm_pll->phy_base)) {
+		dev_err(&pdev->dev, "failed to map CMN PHY base\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	dp_10nm_pll->ln_tx0_base = msm_ioremap(pdev, "ln_tx0_base", "DP_LN_TX0");
+	if (IS_ERR_OR_NULL(dp_10nm_pll->ln_tx0_base)) {
+		dev_err(&pdev->dev, "failed to map CMN LN_TX0 base\n");
Quoted 8 lines

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 374

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +8 -0
+		return ERR_PTR(-ENOMEM);
+	}
+
+	dp_10nm_pll->ln_tx1_base = msm_ioremap(pdev, "ln_tx1_base", "DP_LN_TX1");
+	if (IS_ERR_OR_NULL(dp_10nm_pll->ln_tx1_base)) {
+		dev_err(&pdev->dev, "failed to map CMN LN_TX1 base\n");
+		return ERR_PTR(-ENOMEM);
+	}

<snip>

Jordan

Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#22 lore raw

Re: [DPU PATCH 3/3] drm/msm/dp: add support for DP PLL driver

In reply to Sean Paul

Quoting Sean Paul (2018-11-01 14:03:15)

Quoted 19 lines · Chandan Uddaraju
Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_power.c +2 -0
+}
+
 static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power)
 {
      int rc = 0;

drivers/gpu/drm/msm/dp/dp_power.c static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power) · line 524

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_power.c +2 -2
@@ -472,8 +520,12 @@ static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power)
 
      power = container_of(dp_power, struct dp_power_private, dp_power);
 
-     if (power->pixel_clk_rcg && power->pixel_parent)
-             clk_set_parent(power->pixel_clk_rcg, power->pixel_parent);
+     if (power->pixel_clk_rcg && power->pixel_provider) {
+             clk_set_parent(power->pixel_clk_rcg, power->pixel_provider);

s/pixel_parent/pixel_provider/ isn't related to this change, can you please use the final name in the main dp patch so it's correct in this one?

Quoted 5 lines

drivers/gpu/drm/msm/dp/dp_power.c static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power) · line 527

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_power.c +3 -0
+             pr_debug("%s: is the parent of clk=%s\n",
+                                     __clk_get_name(power->pixel_provider),
+                                     __clk_get_name(power->pixel_clk_rcg));

Same comment here, this debug can go in the main patch.

Is there any reason why assigned-clock-parents wouldn't work here?

Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_power.h +1 -0
index d1adaaf..5effd32 100644
@@ -24,6 +24,7 @@
  * @init: initializes the regulators/core clocks/GPIOs/pinctrl
  * @deinit: turns off the regulators/core clocks/GPIOs/pinctrl
  * @clk_enable: enable/disable the DP clocks
+ * @set_link_clk_parent: set the parent of DP link clock
  * @set_pixel_clk_parent: set the parent of DP pixel clock
  */
 struct dp_power {

[...]

Quoted 8 lines

drivers/gpu/drm/msm/dp/dp_power.h

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_power.h +5 -0
+
+static int clk_mux_determine_rate(struct clk_hw *hw,
+                                  struct clk_rate_request *req)
+{
+     int ret = 0;

no need to init this to 0

Quoted 11 lines

drivers/gpu/drm/msm/dp/dp_power.h

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_power.h +8 -0
+
+     ret = __clk_mux_determine_rate_closest(hw, req);
+     if (ret)
+             return ret;
+
+     /* Set the new parent of mux if there is a new valid parent */
+     if (hw->clk && req->best_parent_hw->clk)
+             clk_set_parent(hw->clk, req->best_parent_hw->clk);

What about the return value? All other clk_set_parent calls in this patch are also unchecked, so please add those as well.

The determine_rate clk_op should _never_ change clk hardware. It's a function that's about determining what rate a clk can support based on the rate that's requested and what the hardware can do.

Ok, let me just take a pass at the overall clk parts of this patch instead of doing an "and also" review on Sean's review.

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

#5 lore raw

Re: [DPU PATCH 1/3] dt-bindings: msm/dp: add bindings of DP/DP-PLL driver for Snapdragon 845

In reply to a message not in the archive

Quoting Chandan Uddaraju (2018-10-10 10:15:57)

Documentation/devicetree/bindings/display/msm/dp.txt line 7

Quoted 13 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +7 -0
new file mode 100644
index 0000000..0155266
@@ -0,0 +1,249 @@
+Qualcomm Technologies, Inc.
+DP is the master Display Port device which supports DP host controllers that are compatible with VESA Display Port interface specification.
+DP Controller: Required properties:
+- compatible:           Should be "qcom,dp-display".
+- reg:                  Base address and length of DP hardware's memory mapped regions.
+- cell-index:           Specifies the controller instance.
+- reg-names:            A list of strings that name the list of regs.

This is a lot of register regions! There are probably multiple devices in here.

Documentation/devicetree/bindings/display/msm/dp.txt line 12

Quoted 5 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +5 -0
+                       "dp_ahb" - DP controller memory region.
+                       "dp_aux" - DP AUX memory region.
+                       "dp_link" - DP link layer memory region.
+                       "dp_p0" - DP pixel clock domain memory region.
+                       "dp_phy" - DP PHY memory region.

So a phy driver? Should be different binding and device than the DP controller?

Documentation/devicetree/bindings/display/msm/dp.txt line 14

Quoted 2 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +2 -0
+                       "dp_ln_tx0" - USB3 DP PHY combo TX-0 lane memory region.
+                       "dp_ln_tx1" - USB3 DP PHY combo TX-1 lane memory region.

Presumably part of the phy device. Again, different binding?

Documentation/devicetree/bindings/display/msm/dp.txt line 15

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+                       "dp_mmss_cc" - Display Clock Control memory region.

No. This shouldn't be reaching into the display clock controller region. That should be it's own node and device driver.

Documentation/devicetree/bindings/display/msm/dp.txt line 16

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+                       "qfprom_physical" - QFPROM Phys memory region.

qfprom is accessed through nvmem framework, please use it instead of remapping it and reading random bits directly from your driver.

Documentation/devicetree/bindings/display/msm/dp.txt line 18

Quoted 2 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +2 -0
+                       "dp_pll" - USB3 DP combo PLL memory region.
+                       "usb3_dp_com" - USB3 DP PHY combo memory region.

I guess this would go with the DP phy node?

Documentation/devicetree/bindings/display/msm/dp.txt line 19

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+                       "hdcp_physical" - DP HDCP memory region.

Goes with the main DP device?

Please drop the full stop from all of these lines.

Documentation/devicetree/bindings/display/msm/dp.txt line 20

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+- interrupt-parent     phandle to the interrupt parent device node.

We don't need this sort of duplicate information. If it's part of standard spec and not specific to this binding it can be left out.

Documentation/devicetree/bindings/display/msm/dp.txt line 26

Quoted 6 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +6 -0
+- interrupts:          The interrupt signal from the DP block.
+- clocks:               Clocks required for Display Port operation. See [1] for details on clock bindings.
+- clock-names:          Names of the clocks corresponding to handles. Following clocks are required:
+                       "core_aux_clk", "core_usb_ref_clk_src","core_usb_ref_clk", "core_usb_cfg_ahb_clk",
+                       "core_usb_pipe_clk", "ctrl_link_clk", "ctrl_link_iface_clk", "ctrl_crypto_clk",
+                       "ctrl_pixel_clk", "pixel_clk_rcg", "pixel_parent".

Please remove "_clk" from all your clock-names. It's redundant and makes things harder to read.

Documentation/devicetree/bindings/display/msm/dp.txt line 27

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+- pll-node:            phandle to DP PLL node.

Huh?

Documentation/devicetree/bindings/display/msm/dp.txt line 29

Quoted 2 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +2 -0
+- vdda-1p2-supply:             phandle to vdda 1.2V regulator node.
+- vdda-0p9-supply:             phandle to vdda 0.9V regulator node.

Perhaps these have other names besides vdda? Maybe vdda-pll and vdda? I'd also drop the 1p2 and 0p9 from them and just describe that in freeform in the binding.

Quoted 30 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +30 -0
+- qcom,aux-cfg0-settings:              Specifies the DP AUX configuration 0 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg1-settings:              Specifies the DP AUX configuration 1 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg2-settings:              Specifies the DP AUX configuration 2 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg3-settings:              Specifies the DP AUX configuration 3 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg4-settings:              Specifies the DP AUX configuration 4 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg5-settings:              Specifies the DP AUX configuration 5 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg6-settings:              Specifies the DP AUX configuration 6 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg7-settings:              Specifies the DP AUX configuration 7 settings. The first
+                                       entry in this array corresponds to the register offset

Documentation/devicetree/bindings/display/msm/dp.txt line 69

Quoted 10 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +10 -0
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg8-settings:              Specifies the DP AUX configuration 8 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.
+- qcom,aux-cfg9-settings:              Specifies the DP AUX configuration 9 settings. The first
+                                       entry in this array corresponds to the register offset
+                                       within DP AUX, while the remaining entries indicate the
+                                       programmable values.

Look like magic bits. Can they just be thrown into the driver? Or specified in some way that us mere mortals know what to put into these bits.

Documentation/devicetree/bindings/display/msm/dp.txt line 70

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+- qcom,max-pclk-frequency-khz: An integer specifying the maximum. pixel clock in KHz supported by Display Port.

Why is this in the binding? It isn't known based on the device compatible string?

Documentation/devicetree/bindings/display/msm/dp.txt line 71

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+- extcon:                              Phandle for the external connector class interface.

Is this for typec? Would be good to say what it's for.

Quoted 5 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +5 -0
+- qcom,<type>-supply-entries:          A node that lists the elements of the supply used by the a particular "type" of DP module. The module "types"
+                                       can be "core", "ctrl", and "phy". Within the same type,
+                                       there can be more than one instance of this binding,
+                                       in which case the entry would be appended with the
+                                       supply entry index.

Documentation/devicetree/bindings/display/msm/dp.txt line 86

Quoted 10 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +10 -0
+                                       e.g. qcom,ctrl-supply-entry@0
+                                       -- qcom,supply-name: name of the supply (vdd/vdda/vddio)
+                                       -- qcom,supply-min-voltage: minimum voltage level (uV)
+                                       -- qcom,supply-max-voltage: maximum voltage level (uV)
+                                       -- qcom,supply-enable-load: load drawn (uA) from enabled supply
+                                       -- qcom,supply-disable-load: load drawn (uA) from disabled supply
+                                       -- qcom,supply-pre-on-sleep: time to sleep (ms) before turning on
+                                       -- qcom,supply-post-on-sleep: time to sleep (ms) after turning on
+                                       -- qcom,supply-pre-off-sleep: time to sleep (ms) before turning off
+                                       -- qcom,supply-post-off-sleep: time to sleep (ms) after turning off

All these properties should go away. min/max should be handled by board constraints. Sleep times should be handled by regulator framework for those particular regulators. Maybe the load would be important, but I'm still sort of lost how that wouldn't be expressed through some SoC compatible string for the device and then hardcoded into the driver.

Documentation/devicetree/bindings/display/msm/dp.txt line 91

Quoted 5 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +5 -0
+- pinctrl-names:       List of names to assign mdss pin states defined in pinctrl device node
+                                       Refer to pinctrl-bindings.txt
+- pinctrl-<0..n>:      Lists phandles each pointing to the pin configuration node within a pin
+                                       controller. These pin configurations are installed in the pinctrl
+                                       device node. Refer to pinctrl-bindings.txt

This isn't needed in the binding. Or at least, I don't see where it's expressed in the example, so probably just noise?

Documentation/devicetree/bindings/display/msm/dp.txt line 99

Quoted 8 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +8 -0
+DP Endpoint properties:
+  - remote-endpoint: For port@0, set to phandle of the connected panel/bridge's
+    input endpoint. For port@1, set to the DPU interface output. See [2] for
+    device graph info.
+
+Optional properties:
+- qcom,aux-en-gpio:            Specifies the aux-channel enable gpio.
+- qcom,aux-sel-gpio:           Specifies the aux-channel select gpio.

These should follow standard 'gpios' properties, like aux-enable-gpios and aux-select-gpios. I guess these would need pinctrl muxing too.

Documentation/devicetree/bindings/display/msm/dp.txt line 111

Quoted 12 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +12 -0
+
+
+DP PLL: Required properties:
+- compatible:           Should be "qcom,dp-pll-10nm".
+- reg:                  Base address and length of DP hardware's memory mapped regions.
+- cell-index:           Specifies the PLL instance.
+- reg-names:            A list of strings that name the list of regs.
+                       "pll_base" - DP PLL memory region.
+                       "phy_base" - DP PHY memory region.
+                       "ln_tx0_base" - USB3 DP PHY combo TX-0 lane memory region.
+                       "ln_tx1_base" - USB3 DP PHY combo TX-1 lane memory region.
+                       "gdsc_base" - gdsc memory region.

Why a gdsc_base? GDSCs should be handled by power domains?

Documentation/devicetree/bindings/display/msm/dp.txt line 112

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+- interrupt-parent     phandle to the interrupt parent device node.

Again, drop this one.

Documentation/devicetree/bindings/display/msm/dp.txt line 116

Quoted 4 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +4 -0
+- interrupts:          The interrupt signal from the DP block.
+- clocks:               Clocks required for Display Port operation. See [1] for details on clock bindings.
+- clock-names:          Names of the clocks corresponding to handles. Following clocks are required:
+                       "iface_clk", "ref_clk", cfg_ahb_clk", "pipe_clk".

Again, drop "_clk" please.

Documentation/devicetree/bindings/display/msm/dp.txt line 118

Quoted 2 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +2 -0
+- clock-rate:           Initial clock rate to be configured. For the shared clocks, the default value                       is set to zero so that minimum clock value is configured. Non-zero clock
+                       value can be used to configure DP pixel clock.

We have assigned-clock-rates for this. Can you use that?

Documentation/devicetree/bindings/display/msm/dp.txt line 126

Quoted 8 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +8 -0
+
+
+[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
+[2] Documentation/devicetree/bindings/graph.txt
+
+Example:
+       msm_dp: dp_display@ae90000{
+               cell-index = <0>;

Is this needed?

Documentation/devicetree/bindings/display/msm/dp.txt line 132

Quoted 6 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +6 -0
+               compatible = "qcom,dp-display";
+
+               reg =   <0 0x90000 0x0dc>,
+                       <0 0x90200 0x0c0>,
+                       <0 0x90400 0x508>,
+                       <0 0x90a00 0x094>,

Looks like one device with one reg property:

		<0x90000 0x1000>

Documentation/devicetree/bindings/display/msm/dp.txt line 135

Quoted 3 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +3 -0
+                       <1 0xeaa00 0x200>,
+                       <1 0xea200 0x200>,
+                       <1 0xea600 0x200>,

Looks like another device with one reg property:

		<0xea000 0x1000>;

Documentation/devicetree/bindings/display/msm/dp.txt line 138

Quoted 3 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +3 -0
+                       <2 0x02000 0x1a0>,
+                       <3 0x00000 0x621c>,
+                       <1 0xea000 0x180>,

This is part of the one above.

Documentation/devicetree/bindings/display/msm/dp.txt line 139

Quoted 1 line
Documentation/devicetree/bindings/display/msm/dp.txt new file +1 -0
+                       <1 0xe8000 0x20>,

Well maybe this is also part of the DP phy? Then it would start somewhere a little earlier I supposed.

Documentation/devicetree/bindings/display/msm/dp.txt line 147

Quoted 8 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +8 -0
+                       <4 0xe1000 0x034>;
+               reg-names = "dp_ahb", "dp_aux", "dp_link",
+                       "dp_p0", "dp_phy", "dp_ln_tx0", "dp_ln_tx1",
+                       "dp_mmss_cc", "qfprom_physical", "dp_pll",
+                       "usb3_dp_com", "hdcp_physical";
+
+               interrupt-parent = <&mdss>;
+               interrupts = <12 0>;

Why is this interrupt-parent stuff being done?

Documentation/devicetree/bindings/display/msm/dp.txt line 154

Quoted 7 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +7 -0
+
+               extcon = <&usb_1_ssphy>;
+               clocks =  <&dispcc DISP_CC_MDSS_DP_AUX_CLK>,
+                       <&rpmhcc RPMH_CXO_CLK>,
+                       <&gcc GCC_USB3_PRIM_CLKREF_CLK>,
+                       <&gcc GCC_USB_PHY_CFG_AHB2PHY_CLK>,
+                       <&gcc GCC_USB3_PRIM_PHY_PIPE_CLK>,

It's really odd that this device needs USB phy clocks. Is it really necessary to do this?

Quoted 42 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +42 -0
+                       <&dispcc DISP_CC_MDSS_DP_LINK_CLK>,
+                       <&dispcc DISP_CC_MDSS_DP_LINK_INTF_CLK>,
+                       <&dispcc DISP_CC_MDSS_DP_PIXEL_CLK>,
+                       <&dispcc DISP_CC_MDSS_DP_CRYPTO_CLK>,
+                       <&dispcc DISP_CC_MDSS_DP_PIXEL_CLK_SRC>;
+               clock-names = "core_aux_clk", "core_ref_clk_src",
+                       "core_usb_ref_clk", "core_usb_cfg_ahb_clk",
+                       "core_usb_pipe_clk", "ctrl_link_clk",
+                       "ctrl_link_iface_clk", "ctrl_pixel_clk",
+                       "crypto_clk", "pixel_clk_rcg";
+
+               pll-node = <&dp_pll>;
+               qcom,aux-cfg0-settings = [20 00];
+               qcom,aux-cfg1-settings = [24 13 23 1d];
+               qcom,aux-cfg2-settings = [28 24];
+               qcom,aux-cfg3-settings = [2c 00];
+               qcom,aux-cfg4-settings = [30 0a];
+               qcom,aux-cfg5-settings = [34 26];
+               qcom,aux-cfg6-settings = [38 0a];
+               qcom,aux-cfg7-settings = [3c 03];
+               qcom,aux-cfg8-settings = [40 bb];
+               qcom,aux-cfg9-settings = [44 03];
+
+               qcom,max-pclk-frequency-khz = <675000>;
+
+               qcom,ctrl-supply-entries {
+                       #address-cells = <1>;
+                       #size-cells = <0>;
+
+                       qcom,ctrl-supply-entry@0 {
+                               reg = <0>;
+                               qcom,supply-name = "vdda-1p2";
+                               qcom,supply-min-voltage = <1200000>;
+                               qcom,supply-max-voltage = <1200000>;
+                               qcom,supply-enable-load = <21800>;
+                               qcom,supply-disable-load = <4>;
+                       };
+               };
+
+               qcom,phy-supply-entries {
+                       #address-cells = <1>;
+                       #size-cells = <0>;

Documentation/devicetree/bindings/display/msm/dp.txt line 206

Quoted 10 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +10 -0
+
+                       qcom,phy-supply-entry@0 {
+                               reg = <0>;
+                               qcom,supply-name = "vdda-0p9";
+                               qcom,supply-min-voltage = <880000>;
+                               qcom,supply-max-voltage = <880000>;
+                               qcom,supply-enable-load = <36000>;
+                               qcom,supply-disable-load = <32>;
+                       };
+               };

NAK on the above two nodes.

Quoted 11 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +11 -0
+
+               ports {
+                       #address-cells = <1>;
+                       #size-cells = <0>;
+
+                       port@0 {
+                               reg = <0>;
+                               dp_in: endpoint {
+                                       remote-endpoint = <&dpu_intf0_out>;
+                               };
+                       };

Documentation/devicetree/bindings/display/msm/dp.txt line 227

Quoted 10 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +10 -0
+
+                       port@1 {
+                               reg = <1>;
+                               dp_out: endpoint {
+                               };
+                       };
+               };
+       };
+
+       dp_pll: dp-pll@c011000 {

This doesn't even match reg property.

Documentation/devicetree/bindings/display/msm/dp.txt line 237

Quoted 10 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +10 -0
+               compatible = "qcom,dp-pll-10nm";
+               label = "DP PLL";
+               cell-index = <0>;
+               #clock-cells = <1>;
+
+               reg = <1 0xea000 0x200>,
+                     <1 0xeaa00 0x200>,
+                     <1 0xea200 0x200>,
+                     <1 0xea600 0x200>,
+                     <2 0x03000 0x8>;

Why 1 and 2? What's going on in this example.

Documentation/devicetree/bindings/display/msm/dp.txt line 239

Quoted 2 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +2 -0
+               reg-names = "pll_base", "phy_base", "ln_tx0_base",
+                       "ln_tx1_base", "gdsc_base";

Don't think we really need "_base" on these reg-names either. Seems redundant.

Documentation/devicetree/bindings/display/msm/dp.txt line 249

Quoted 10 lines
Documentation/devicetree/bindings/display/msm/dp.txt new file +10 -0
+
+               clocks = <&dispcc DISP_CC_MDSS_AHB_CLK>,
+                        <&gcc GCC_USB3_PRIM_CLKREF_CLK>,
+                        <&gcc GCC_USB_PHY_CFG_AHB2PHY_CLK>,
+                        <&gcc GCC_USB3_PRIM_PHY_PIPE_CLK>;
+               clock-names = "iface_clk", "ref_clk",
+                       "cfg_ahb_clk", "pipe_clk";
+               clock-rate = <0>;
+
+       };

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

#24 lore raw

Re: [DPU PATCH 3/3] drm/msm/dp: add support for DP PLL driver

In reply to a message not in the archive

This patch is too big. Please split it up more. I have far too many review comments on it so it will help if you keep splitting the patch up into smaller parts that can be more easily reviewed and fixed.

Quoting Chandan Uddaraju (2018-10-10 10:15:59)

Quoted 48 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c +1 -0
index 08a52f5..e23beee 100644
@@ -1051,6 +1051,7 @@ static int dp_ctrl_enable_mainlink_clocks(struct dp_ctrl_private *ctrl)
 {
        int ret = 0;
 
+       ctrl->power->set_link_clk_parent(ctrl->power);
        ctrl->power->set_pixel_clk_parent(ctrl->power);
 
        dp_ctrl_set_clock_rate(ctrl, "ctrl_link_clk",
drivers/gpu/drm/msm/dp/dp_display.c +28 -0
index 8c98399..2bf6635 100644
@@ -72,6 +72,48 @@ struct dp_display_private {
        {}
 };
 
+static int dp_get_pll(struct dp_display_private *dp_priv)
+{
+       struct platform_device *pdev = NULL;
+       struct platform_device *pll_pdev;
+       struct device_node *pll_node;
+       struct dp_parser *dp_parser = NULL;
+
+       if (!dp_priv) {
+               pr_err("Invalid Arguments\n");
+               return -EINVAL;
+       }
+
+       pdev = dp_priv->pdev;
+       dp_parser = dp_priv->parser;
+
+       if (!dp_parser) {
+               pr_err("Parser not initialized.\n");
+               return -EINVAL;
+       }
+
+       pll_node = of_parse_phandle(pdev->dev.of_node, "pll-node", 0);
+       if (!pll_node) {
+               dev_err(&pdev->dev, "cannot find pll device\n");
+               return -ENXIO;
+       }
+
+       pll_pdev = of_find_device_by_node(pll_node);
+       if (pll_pdev)

drivers/gpu/drm/msm/dp/dp_display.c struct dp_display_private { · line 112

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +10 -0
+               dp_parser->pll = platform_get_drvdata(pll_pdev);
+
+       of_node_put(pll_node);
+
+       if (!pll_pdev || !dp_parser->pll) {
+               dev_err(&pdev->dev, "%s: pll driver is not ready\n", __func__);
+               return -EPROBE_DEFER;
+       }
+
+       dp_parser->pll_dev = get_device(&pll_pdev->dev);

Why do we need this code? Are we working around some lack of ability to link different devices together by resource requesting?

Quoted 41 lines
drivers/gpu/drm/msm/dp/dp_display.c +12 -0
+
+       return 0;
+}
+
 static irqreturn_t dp_display_irq(int irq, void *dev_id)
 {
        struct dp_display_private *dp = dev_id;
@@ -125,6 +167,12 @@ static int dp_display_bind(struct device *dev, struct device *master,
                goto end;
        }
 
+       rc = dp_get_pll(dp);
+       if (rc) {
+               pr_err(" DP get PLL instance failed\n");
+               goto end;
+       }
+
        rc = dp->aux->drm_aux_register(dp->aux);
        if (rc) {
                pr_err("DRM DP AUX register failed\n");
@@ -921,6 +969,7 @@ int __init msm_dp_register(void)
 {
        int ret;
 
+       msm_dp_pll_driver_register();
        ret = platform_driver_register(&dp_display_driver);
        if (ret) {
                pr_err("driver register failed");
@@ -932,6 +981,7 @@ int __init msm_dp_register(void)
 
 void __exit msm_dp_unregister(void)
 {
+       msm_dp_pll_driver_unregister();
        platform_driver_unregister(&dp_display_driver);
 }
 
drivers/gpu/drm/msm/dp/dp_display.h +0 -0
index ca5eae5..9cd6a6b 100644

drivers/gpu/drm/msm/dp/dp_display.h struct msm_dp { · line 56

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_display.h +2 -0
@@ -52,4 +52,7 @@ struct msm_dp {
 
 int dp_display_get_num_of_displays(void);
 int dp_display_get_displays(void **displays, int count);
+void __init msm_dp_pll_driver_register(void);
+void __exit msm_dp_pll_driver_unregister(void);

__init and __exit in header files does nothing.

Quoted 87 lines
drivers/gpu/drm/msm/dp/dp_display.h +1 -0
+
 #endif /* _DP_DISPLAY_H_ */
drivers/gpu/drm/msm/dp/dp_power.c +44 -10
index 1d58480..3a1679c 100644
@@ -23,7 +23,9 @@ struct dp_power_private {
        struct dp_parser *parser;
        struct platform_device *pdev;
        struct clk *pixel_clk_rcg;
-       struct clk *pixel_parent;
+       struct clk *link_clk_src;
+       struct clk *pixel_provider;
+       struct clk *link_provider;
 
        struct dp_power dp_power;
 
@@ -154,6 +156,16 @@ static int dp_power_clk_init(struct dp_power_private *power, bool enable)
                goto exit;
        }
 
+       if (power->parser->pll && power->parser->pll->get_provider) {
+               rc = power->parser->pll->get_provider(power->parser->pll,
+                               &power->link_provider, &power->pixel_provider);
+               if (rc) {
+                       pr_info("%s: can't get provider from pll, don't set parent\n",
+                               __func__);
+                       return 0;
+               }
+       }
+
        if (enable) {
                rc = msm_dss_get_clk(dev, core->clk_config, core->num_clk);
                if (rc) {
@@ -173,17 +185,10 @@ static int dp_power_clk_init(struct dp_power_private *power, bool enable)
                if (IS_ERR(power->pixel_clk_rcg)) {
                        pr_debug("Unable to get DP pixel clk RCG\n");
                        power->pixel_clk_rcg = NULL;
-               }
-
-               power->pixel_parent = devm_clk_get(dev, "pixel_parent");
-               if (IS_ERR(power->pixel_parent)) {
-                       pr_debug("Unable to get DP pixel RCG parent\n");
-                       power->pixel_parent = NULL;
+                       rc = -ENODEV;
+                       goto ctrl_get_error;
                }
        } else {
-               if (power->pixel_parent)
-                       devm_clk_put(dev, power->pixel_parent);
-
                if (power->pixel_clk_rcg)
                        devm_clk_put(dev, power->pixel_clk_rcg);
 
@@ -459,6 +464,49 @@ static void dp_power_client_deinit(struct dp_power *dp_power)
 
 }
 
+static int dp_power_set_link_clk_parent(struct dp_power *dp_power)
+{
+       int rc = 0;
+       struct dp_power_private *power;
+       u32 num;
+       struct dss_clk *cfg;
+       char *name = "ctrl_link_clk";
+
+       if (!dp_power) {
+               pr_err("invalid power data\n");
+               rc = -EINVAL;
+               goto exit;
+       }
+
+       power = container_of(dp_power, struct dp_power_private, dp_power);
+
+       num = power->parser->mp[DP_CTRL_PM].num_clk;
+       cfg = power->parser->mp[DP_CTRL_PM].clk_config;
+
+       while (num && strcmp(cfg->clk_name, name)) {
+               num--;
+               cfg++;
+       }
+
+       if (num && power->link_provider) {
+               power->link_clk_src = clk_get_parent(cfg->clk);
+                       if (power->link_clk_src) {
+                               clk_set_parent(power->link_clk_src, power->link_provider);
+                               pr_debug("%s: is the parent of clk=%s\n",

drivers/gpu/drm/msm/dp/dp_power.c static void dp_power_client_deinit(struct dp_power *dp_power) · line 505

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_power.c +10 -0
+                                               __clk_get_name(power->link_provider),
+                                               __clk_get_name(power->link_clk_src));
+                       } else {
+                               pr_err("couldn't get parent for clk=%s\n", name);
+                               rc = -EINVAL;
+                       }
+       } else {
+               pr_err("%s clock could not be set parent\n", name);
+               rc = -EINVAL;
+       }

Hopefully this can just be done with assigned-clock-parents.

Quoted 20 lines
drivers/gpu/drm/msm/dp/dp_power.c +4 -0
+exit:
+       return rc;
+}
+
 static int dp_power_set_pixel_clk_parent(struct dp_power *dp_power)
 {
        int rc = 0;
drivers/gpu/drm/msm/dp/dp_power.h +1 -0
index d1adaaf..5effd32 100644
@@ -24,6 +24,7 @@
  * @init: initializes the regulators/core clocks/GPIOs/pinctrl
  * @deinit: turns off the regulators/core clocks/GPIOs/pinctrl
  * @clk_enable: enable/disable the DP clocks
+ * @set_link_clk_parent: set the parent of DP link clock
  * @set_pixel_clk_parent: set the parent of DP pixel clock
  */
 struct dp_power {

drivers/gpu/drm/msm/dp/dp_power.h struct dp_power { · line 36

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_power.h +1 -0
@@ -31,6 +32,7 @@ struct dp_power {
        int (*deinit)(struct dp_power *power);
        int (*clk_enable)(struct dp_power *power, enum dp_pm_type pm_type,
                                bool enable);
+       int (*set_link_clk_parent)(struct dp_power *power);
        int (*set_pixel_clk_parent)(struct dp_power *power);

Seeing these clk wrappers is quite scary. Is this driver written with some sort of linux abstraction layer inside?

Quoted 50 lines
drivers/gpu/drm/msm/dp/dp_power.h +0 -0
        int (*power_client_init)(struct dp_power *power);
        void (*power_client_deinit)(struct dp_power *power);
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +42 -0
new file mode 100644
index 0000000..a8612b5
@@ -0,0 +1,153 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include "dp_pll.h"
+
+int msm_dp_pll_util_parse_dt_clock(struct platform_device *pdev,
+                                       struct msm_dp_pll *pll)
+{
+       u32 i = 0, rc = 0;
+       struct dss_module_power *mp = &pll->mp;
+       const char *clock_name;
+       u32 clock_rate;
+
+       mp->num_clk = of_property_count_strings(pdev->dev.of_node,
+                                                       "clock-names");
+       if (mp->num_clk <= 0) {
+               pr_err("clocks are not defined\n");
+               goto clk_err;
+       }
+
+       mp->clk_config = devm_kzalloc(&pdev->dev,
+                       sizeof(struct dss_clk) * mp->num_clk, GFP_KERNEL);
+       if (!mp->clk_config) {
+               rc = -ENOMEM;
+               mp->num_clk = 0;
+               goto clk_err;
+       }
+
+       for (i = 0; i < mp->num_clk; i++) {
+               of_property_read_string_index(pdev->dev.of_node, "clock-names",
+                                                       i, &clock_name);
+               strlcpy(mp->clk_config[i].clk_name, clock_name,

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 52

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+                               sizeof(mp->clk_config[i].clk_name));
+
+               of_property_read_u32_index(pdev->dev.of_node, "clock-rate",
+                                                       i, &clock_rate);
+               mp->clk_config[i].rate = clock_rate;
+
+               if (!clock_rate)
+                       mp->clk_config[i].type = DSS_CLK_AHB;
+               else
+                       mp->clk_config[i].type = DSS_CLK_PCLK;

Is this custom assigned-clock-rates?

Quoted 25 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +25 -0
+       }
+
+clk_err:
+       return rc;
+}
+
+struct msm_dp_pll *msm_dp_pll_init(struct platform_device *pdev,
+                       enum msm_dp_pll_type type, int id)
+{
+       struct device *dev = &pdev->dev;
+       struct msm_dp_pll *pll;
+
+       switch (type) {
+       case MSM_DP_PLL_10NM:
+               pll = msm_dp_pll_10nm_init(pdev, id);
+               break;
+       default:
+               pll = ERR_PTR(-ENXIO);
+               break;
+       }
+
+       if (IS_ERR(pll)) {
+               dev_err(dev, "%s: failed to init DP PLL\n", __func__);
+               return pll;
+       }

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 87

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+
+       pll->type = type;
+
+       DBG("DP:%d PLL registered", id);
+
+       return pll;
+}
+
+static const struct of_device_id dp_pll_dt_match[] = {
+#ifdef CONFIG_DRM_MSM_DP_10NM_PLL

Don't do this.

Quoted 13 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +13 -0
+       { .compatible = "qcom,dp-pll-10nm" },
+#endif
+       {}
+};
+
+static int dp_pll_driver_probe(struct platform_device *pdev)
+{
+       struct msm_dp_pll *pll;
+       struct device *dev = &pdev->dev;
+       const struct of_device_id *match;
+       enum msm_dp_pll_type type;
+
+       match = of_match_node(dp_pll_dt_match, dev->of_node);

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 110

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+       if (!match)
+               return -ENODEV;
+
+       if (!strcmp(match->compatible, "qcom,dp-pll-10nm"))
+               type = MSM_DP_PLL_10NM;
+       else
+               type = MSM_DP_PLL_MAX;
+
+       pll = msm_dp_pll_init(pdev, type, 0);
+       if (IS_ERR_OR_NULL(pll)) {

IS_ERR_OR_NULL is typically a bad sign.

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 113

Quoted 3 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +3 -0
+               dev_info(dev,
+                       "%s: pll init failed: %ld, need separate pll clk driver\n",
+                       __func__, PTR_ERR(pll));

Well if it's NULL, then it's not a PTR_ERR.

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 114

Quoted 1 line
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +1 -0
+               return -ENODEV;

And then we just overwrite whatever is returned, ouch.

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 127

Quoted 13 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +13 -0
+       }
+
+       platform_set_drvdata(pdev, pll);
+
+       return 0;
+}
+
+static int dp_pll_driver_remove(struct platform_device *pdev)
+{
+       struct msm_dp_pll *pll = platform_get_drvdata(pdev);
+
+       if (pll) {
+               //msm_dsi_pll_destroy(pll);

Leftovers?

Quoted 16 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +16 -0
+               pll = NULL;
+       }
+
+       platform_set_drvdata(pdev, NULL);
+
+       return 0;
+}
+
+static struct platform_driver dp_pll_platform_driver = {
+       .probe      = dp_pll_driver_probe,
+       .remove     = dp_pll_driver_remove,
+       .driver     = {
+               .name   = "msm_dp_pll",
+               .of_match_table = dp_pll_dt_match,
+       },
+};

drivers/gpu/drm/msm/dp/pll/dp_pll.c line 153

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.c new file +10 -0
+
+void __init msm_dp_pll_driver_register(void)
+{
+       platform_driver_register(&dp_pll_platform_driver);
+}
+
+void __exit msm_dp_pll_driver_unregister(void)
+{
+       platform_driver_unregister(&dp_pll_platform_driver);
+}

Consider module_platform_driver()? Why is this directly probed from somewhere else? Some sort of DPU design?

Quoted 14 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +8 -0
new file mode 100644
index 0000000..d52a81a
@@ -0,0 +1,64 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 18

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +10 -0
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __DP_PLL_H
+#define __DP_PLL_H
+
+#include <linux/clk.h>
+#include <linux/clk-provider.h>

Typically a bad sign to see a clk provider and consumer in the same place.

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 26

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +8 -0
+#include <linux/platform_device.h>
+
+#include "dpu_io_util.h"
+#include "msm_drv.h"
+
+#define PLL_REG_W(base, offset, data)  \
+                               writel_relaxed((data), (base) + (offset))
+#define PLL_REG_R(base, offset)        readl_relaxed((base) + (offset))

Can't we just use writel and readl directly?

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 36

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +10 -0
+
+enum msm_dp_pll_type {
+       MSM_DP_PLL_10NM,
+       MSM_DP_PLL_MAX
+};
+
+struct msm_dp_pll {
+       enum msm_dp_pll_type type;
+       struct clk_hw clk_hw;
+       unsigned long   rate;           /* current vco rate */

Why are we duplicating what is known to the framework?

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 38

Quoted 2 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +2 -0
+       u64             min_rate;       /* min vco rate */
+       u64             max_rate;       /* max vco rate */

Use clk_hw_set_rate_range?

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 39

Quoted 1 line
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +1 -0
+       bool            pll_on;

More duplicating of what clk framework knows?

drivers/gpu/drm/msm/dp/pll/dp_pll.h line 48

Quoted 9 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +9 -0
+       void            *priv;
+       /* Pll specific resources like GPIO, power supply, clocks, etc*/
+       struct dss_module_power mp;
+       int (*get_provider)(struct msm_dp_pll *pll,
+                       struct clk **link_clk_provider,
+                       struct clk **pixel_clk_provider);
+};
+
+#define hw_clk_to_pll(x) container_of(x, struct msm_dp_pll, clk_hw)

Usually this would be called to_msm_dp_pll().

Quoted 27 lines
drivers/gpu/drm/msm/dp/pll/dp_pll.h new file +5 -0
+
+struct msm_dp_pll *msm_dp_pll_init(struct platform_device *pdev,
+                       enum msm_dp_pll_type type, int id);
+
+int msm_dp_pll_util_parse_dt_clock(struct platform_device *pdev,
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +16 -0
new file mode 100644
index 0000000..a180413
@@ -0,0 +1,401 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+/*
+ * Display Port PLL driver block diagram for branch clocks
+ *

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 26

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+ *             +------------------------------+
+ *             |         DP_VCO_CLK           |
+ *             |                              |
+ *             |    +-------------------+     |
+ *             |    |   (DP PLL/VCO)    |     |
+ *             |    +---------+---------+     |
+ *             |              v               |
+ *             |   +----------+-----------+   |
+ *             |   | hsclk_divsel_clk_src |   |
+ *             |   +----------+-----------+   |

Is this a divider?

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 34

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +8 -0
+ *             +------------------------------+
+ *                             |
+ *      +------------<---------v------------>----------+
+ *      |                                              |
+ * +-----v------------+                                 |
+ * | dp_link_clk_src  |                                 |
+ * |    divsel_ten    |                                 |
+ * +---------+--------+                                 |

And dispcc gets a fixed div-10 on the output of the PLL divider?

Quoted 25 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +25 -0
+ *     |                                               |
+ *     |                                               |
+ *     v                                               v
+ * Input to DISPCC block                                |
+ * for link clk, crypto clk                             |
+ * and interface clock                                  |
+ *                                                     |
+ *                                                     |
+ *     +--------<------------+-----------------+---<---+
+ *     |                     |                 |
+ * +-------v------+  +--------v-----+  +--------v------+
+ * | vco_divided  |  | vco_divided  |  | vco_divided   |
+ * |    _clk_src  |  |    _clk_src  |  |    _clk_src   |
+ * |              |  |              |  |               |
+ * |divsel_six    |  |  divsel_two  |  |  divsel_four  |
+ * +-------+------+  +-----+--------+  +--------+------+
+ *         |              |                    |
+ *     v------->----------v-------------<------v
+ *                         |
+ *             +----------+---------+
+ *             |   vco_divided_clk  |
+ *             |       _src_mux     |
+ *             +---------+----------+
+ *                        |
+ *                        v

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 69

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+ *              Input to DISPCC block
+ *              for DP pixel clock
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/delay.h>
+#include <linux/regmap.h>
+#include <linux/clk.h>

I'd expect clk-provider.h here, instead of clk.h

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 80

Quoted 11 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +11 -0
+
+#include "dp_pll_10nm.h"
+
+#define NUM_PROVIDED_CLKS              2
+
+#define DP_LINK_CLK_SRC                        0
+#define DP_PIXEL_CLK_SRC               1
+
+static struct dp_pll_10nm *dp_pdb;
+
+/* Op structures */

Drop useless comments please.

Quoted 25 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +25 -0
+static const struct clk_ops dp_10nm_vco_clk_ops = {
+       .recalc_rate = dp_vco_recalc_rate_10nm,
+       .set_rate = dp_vco_set_rate_10nm,
+       .round_rate = dp_vco_round_rate_10nm,
+       .prepare = dp_vco_prepare_10nm,
+       .unprepare = dp_vco_unprepare_10nm,
+};
+
+struct dp_pll_10nm_pclksel {
+       struct clk_hw hw;
+
+       /* divider params */
+       u8 shift;
+       u8 width;
+       u8 flags; /* same flags as used by clk_divider struct */
+
+       struct dp_pll_10nm *pll;
+};
+#define to_pll_10nm_pclksel(_hw) container_of(_hw, struct dp_pll_10nm_pclksel, hw)
+
+static int dp_mux_set_parent_10nm(struct clk_hw *hw, u8 val)
+{
+       struct dp_pll_10nm_pclksel *pclksel = to_pll_10nm_pclksel(hw);
+       struct dp_pll_10nm *dp_res = pclksel->pll;
+       u32 auxclk_div;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 115

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+
+       auxclk_div = PLL_REG_R(dp_res->phy_base, DP_PHY_VCO_DIV);
+       auxclk_div &= ~0x03;    /* bits 0 to 1 */
+
+       if (val == 0) /* mux parent index = 0 */
+               auxclk_div |= 1;
+       else if (val == 1) /* mux parent index = 1 */
+               auxclk_div |= 2;
+       else if (val == 2) /* mux parent index = 2 */
+               auxclk_div |= 0;

Is this really a mux? It looks like it's a divider that divides the PLL frequency down. Why add in an extra level of set_parent things when we could just as easily do division and call up to parent with some multiplied rate?

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 119

Quoted 4 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +4 -0
+
+       PLL_REG_W(dp_res->phy_base,
+                       DP_PHY_VCO_DIV, auxclk_div);
+       /* Make sure the PHY registers writes are done */

Which this wmb() doesn't do.

Quoted 17 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +17 -0
+       wmb();
+       pr_debug("%s: mux=%d auxclk_div=%x\n", __func__, val, auxclk_div);
+
+       return 0;
+}
+
+static u8 dp_mux_get_parent_10nm(struct clk_hw *hw)
+{
+       u32 auxclk_div = 0;
+       struct dp_pll_10nm_pclksel *pclksel = to_pll_10nm_pclksel(hw);
+       struct dp_pll_10nm *dp_res = pclksel->pll;
+       u8 val = 0;
+
+       pr_err("clk_hw->init->name = %s\n", hw->init->name);
+       auxclk_div = PLL_REG_R(dp_res->phy_base, DP_PHY_VCO_DIV);
+       auxclk_div &= 0x03;
+

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 146

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+       if (auxclk_div == 1) /* Default divider */
+               val = 0;
+       else if (auxclk_div == 2)
+               val = 1;
+       else if (auxclk_div == 0)
+               val = 2;
+
+       pr_debug("%s: auxclk_div=%d, val=%d\n", __func__, auxclk_div, val);
+
+       return val;

Yes, all very odd!

Quoted 4 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +4 -0
+}
+
+static int clk_mux_determine_rate(struct clk_hw *hw,
+                                    struct clk_rate_request *req)

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 160

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+{
+       int ret = 0;
+
+       ret = __clk_mux_determine_rate_closest(hw, req);
+       if (ret)
+               return ret;
+
+       /* Set the new parent of mux if there is a new valid parent */
+       if (hw->clk && req->best_parent_hw->clk)
+               clk_set_parent(hw->clk, req->best_parent_hw->clk);

No idea what this is, but again we shouldn't be touching the hardware in determine_rate, and we certainly shouldn't be using clk consumer APIs from within clk provider ops.

Quoted 11 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +11 -0
+
+       return 0;
+}
+
+static unsigned long mux_recalc_rate(struct clk_hw *hw,
+                                       unsigned long parent_rate)
+{
+       struct clk *div_clk = NULL, *vco_clk = NULL;
+       struct msm_dp_pll *vco = NULL;
+
+       div_clk = clk_get_parent(hw->clk);

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 181

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+       if (!div_clk)
+               return 0;
+
+       vco_clk = clk_get_parent(div_clk);
+       if (!vco_clk)
+               return 0;
+
+       vco = hw_clk_to_pll(__clk_get_hw(vco_clk));
+       if (!vco)
+               return 0;

All this parent checking should go away.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 188

Quoted 7 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +7 -0
+
+       if (vco->rate == DP_VCO_HSCLK_RATE_8100MHZDIV1000)
+               return (vco->rate / 6);
+       else if (vco->rate == DP_VCO_HSCLK_RATE_5400MHZDIV1000)
+               return (vco->rate / 4);
+       else
+               return (vco->rate / 2);

I'd expect the recalc_rate callback to read some hardware register and figure out what rate is coming through the clk. This doesn't look to be doing that. Instead it's reaching up two levels and then looking at some cached rate inside there to figure out what rate is coming here? That is weird.

Quoted 6 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +6 -0
+}
+
+static int dp_pll_10nm_get_provider(struct msm_dp_pll *pll,
+                                    struct clk **link_clk_provider,
+                                    struct clk **pixel_clk_provider)
+{

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 204

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+       struct dp_pll_10nm *pll_10nm = to_dp_pll_10nm(pll);
+       struct clk_hw_onecell_data *hw_data = pll_10nm->hw_data;
+
+       if (link_clk_provider)
+               *link_clk_provider = hw_data->hws[DP_LINK_CLK_SRC]->clk;
+       if (pixel_clk_provider)
+               *pixel_clk_provider = hw_data->hws[DP_PIXEL_CLK_SRC]->clk;
+
+       return 0;
+}

I don't know what this function is for, but it looks like some weird wrapper around kernel things which just makes for more reading and less transferable knowledge because we have to learn how different drivers decide to wrap kernel constructs.

Quoted 7 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +7 -0
+
+static const struct clk_ops dp_10nm_pclksel_clk_ops = {
+       .get_parent = dp_mux_get_parent_10nm,
+       .set_parent = dp_mux_set_parent_10nm,
+       .recalc_rate = mux_recalc_rate,
+       .determine_rate = clk_mux_determine_rate,
+};

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 221

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+
+static struct clk_hw *dp_pll_10nm_pixel_clk_sel(struct dp_pll_10nm *pll_10nm)
+{
+       struct device *dev = &pll_10nm->pdev->dev;
+       struct dp_pll_10nm_pclksel *pll_pclksel;
+       struct clk_init_data pclksel_init = {
+               .parent_names = (const char *[]){
+                               "dp_vco_divsel_two_clk_src",
+                               "dp_vco_divsel_four_clk_src",
+                               "dp_vco_divsel_six_clk_src" },

As I said earlier, this should probably just be a divider and not a mux.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 224

Quoted 3 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +3 -0
+               .num_parents = 3,
+               .name = "dp_vco_divided_clk_src_mux",
+               .flags = CLK_IGNORE_UNUSED,

Why have this flag? Seems like a workaround for some problem, but who knows what that problem is.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 236

Quoted 12 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +12 -0
+               .ops = &dp_10nm_pclksel_clk_ops,
+       };
+       int ret;
+
+       pll_pclksel = devm_kzalloc(dev, sizeof(*pll_pclksel), GFP_KERNEL);
+       if (!pll_pclksel)
+               return ERR_PTR(-ENOMEM);
+
+       pll_pclksel->pll = pll_10nm;
+       pll_pclksel->shift = 0;
+       pll_pclksel->width = 4;
+       pll_pclksel->flags = CLK_DIVIDER_ONE_BASED;

And it is a divider? But not really?

Quoted 33 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +33 -0
+       pll_pclksel->hw.init = &pclksel_init;
+
+       ret = clk_hw_register(dev, &pll_pclksel->hw);
+       if (ret)
+               return ERR_PTR(ret);
+
+       return &pll_pclksel->hw;
+}
+
+static int dp_pll_10nm_register(struct dp_pll_10nm *pll_10nm)
+{
+       char clk_name[32], parent[32], vco_name[32];
+       struct clk_init_data vco_init = {
+               .parent_names = (const char *[]){ "bi_tcxo" },
+               .num_parents = 1,
+               .name = vco_name,
+               .flags = CLK_IGNORE_UNUSED,
+               .ops = &dp_10nm_vco_clk_ops,
+       };
+       struct device *dev = &pll_10nm->pdev->dev;
+       struct clk_hw **hws = pll_10nm->hws;
+       struct clk_hw_onecell_data *hw_data;
+       struct clk_hw *hw;
+       int num = 0;
+       int ret;
+
+       DBG("DP->id = %d", pll_10nm->id);
+
+       hw_data = devm_kzalloc(dev, sizeof(*hw_data) +
+                              NUM_PROVIDED_CLKS * sizeof(struct clk_hw *),
+                              GFP_KERNEL);
+       if (!hw_data)
+               return -ENOMEM;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 279

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+
+       snprintf(vco_name, 32, "dp_vco_clk");
+       pll_10nm->base.clk_hw.init = &vco_init;
+       ret = clk_hw_register(dev, &pll_10nm->base.clk_hw);
+       if (ret)
+               return ret;
+       hws[num++] = &pll_10nm->base.clk_hw;
+
+       snprintf(clk_name, 32, "dp_link_clk_divsel_ten");
+       snprintf(parent, 32, "dp_vco_clk");

Why are we snprintf strings that are static? Why not just pass them in places they're used?

Quoted 27 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +27 -0
+       hw = clk_hw_register_fixed_factor(dev, clk_name, parent,
+                                         CLK_SET_RATE_PARENT, 1, 10);
+       if (IS_ERR(hw))
+               return PTR_ERR(hw);
+       hws[num++] = hw;
+       hw_data->hws[DP_LINK_CLK_SRC] = hw;
+
+       snprintf(clk_name, 32, "dp_vco_divsel_two_clk_src");
+       snprintf(parent, 32, "dp_vco_clk");
+       hw = clk_hw_register_fixed_factor(dev, clk_name, parent,
+                                         0, 1, 2);
+       if (IS_ERR(hw))
+               return PTR_ERR(hw);
+       hws[num++] = hw;
+
+       snprintf(clk_name, 32, "dp_vco_divsel_four_clk_src");
+       snprintf(parent, 32, "dp_vco_clk");
+       hw = clk_hw_register_fixed_factor(dev, clk_name, parent,
+                                         0, 1, 4);
+       if (IS_ERR(hw))
+               return PTR_ERR(hw);
+       hws[num++] = hw;
+
+       snprintf(clk_name, 32, "dp_vco_divsel_six_clk_src");
+       snprintf(parent, 32, "dp_vco_clk");
+       hw = clk_hw_register_fixed_factor(dev, clk_name, parent,
+                                         0, 1, 6);

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 316

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+       if (IS_ERR(hw))
+               return PTR_ERR(hw);
+       hws[num++] = hw;
+
+       hw = dp_pll_10nm_pixel_clk_sel(pll_10nm);
+       if (IS_ERR(hw))
+               return PTR_ERR(hw);
+
+       hws[num++] = hw;
+       hw_data->hws[DP_PIXEL_CLK_SRC] = hw;

The good news is that this should be sharply reduced by implementing a divider instead of fixed dividers that a virtual mux picks from.

Quoted 71 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +71 -0
+
+       pll_10nm->num_hws = num;
+
+       hw_data->num = NUM_PROVIDED_CLKS;
+       pll_10nm->hw_data = hw_data;
+
+       ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
+                                    pll_10nm->hw_data);
+       if (ret) {
+               dev_err(dev, "failed to register clk provider: %d\n", ret);
+               return ret;
+       }
+
+       return ret;
+}
+
+struct msm_dp_pll *msm_dp_pll_10nm_init(struct platform_device *pdev, int id)
+{
+       struct dp_pll_10nm *dp_10nm_pll;
+       struct msm_dp_pll *pll;
+       int ret;
+
+       if (!pdev)
+               return ERR_PTR(-ENODEV);
+
+       dp_10nm_pll = devm_kzalloc(&pdev->dev, sizeof(*dp_10nm_pll), GFP_KERNEL);
+       if (!dp_10nm_pll)
+               return ERR_PTR(-ENOMEM);
+
+       DBG("DP PLL%d", id);
+
+       dp_10nm_pll->pdev = pdev;
+       dp_10nm_pll->id = id;
+       dp_pdb = dp_10nm_pll;
+
+       dp_10nm_pll->pll_base = msm_ioremap(pdev, "pll_base", "DP_PLL");
+       if (IS_ERR_OR_NULL(dp_10nm_pll->pll_base)) {
+               dev_err(&pdev->dev, "failed to map CMN PLL base\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       dp_10nm_pll->phy_base = msm_ioremap(pdev, "phy_base", "DP_PHY");
+       if (IS_ERR_OR_NULL(dp_10nm_pll->phy_base)) {
+               dev_err(&pdev->dev, "failed to map CMN PHY base\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       dp_10nm_pll->ln_tx0_base = msm_ioremap(pdev, "ln_tx0_base", "DP_LN_TX0");
+       if (IS_ERR_OR_NULL(dp_10nm_pll->ln_tx0_base)) {
+               dev_err(&pdev->dev, "failed to map CMN LN_TX0 base\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       dp_10nm_pll->ln_tx1_base = msm_ioremap(pdev, "ln_tx1_base", "DP_LN_TX1");
+       if (IS_ERR_OR_NULL(dp_10nm_pll->ln_tx1_base)) {
+               dev_err(&pdev->dev, "failed to map CMN LN_TX1 base\n");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       ret = of_property_read_u32(pdev->dev.of_node, "cell-index",
+                               &dp_10nm_pll->index);
+       if (ret) {
+               pr_err("Unable to get the cell-index ret=%d\n", ret);
+               dp_10nm_pll->index = 0;
+       }
+
+       ret = msm_dp_pll_util_parse_dt_clock(pdev, &dp_10nm_pll->base);
+       if (ret) {
+               pr_err("Unable to parse dt clocks ret=%d\n", ret);
+               return ERR_PTR(ret);
+       }

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c line 397

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +10 -0
+
+       ret = dp_pll_10nm_register(dp_10nm_pll);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to register PLL: %d\n", ret);
+               return ERR_PTR(ret);
+       }
+
+       pll = &dp_10nm_pll->base;
+       pll->min_rate = DP_VCO_HSCLK_RATE_1620MHZDIV1000;
+       pll->max_rate = DP_VCO_HSCLK_RATE_8100MHZDIV1000;

Pass this to the framework with clk_hw_set_rate_range() and let the common clk framework clamp min/max for you.

Quoted 73 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.c new file +4 -0
+       pll->get_provider = dp_pll_10nm_get_provider;
+
+       return pll;
+}
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +63 -0
new file mode 100644
index 0000000..f966beb
@@ -0,0 +1,94 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __DP_PLL_10NM_H
+#define __DP_PLL_10NM_H
+
+#include "dp_pll.h"
+#include "dp_reg.h"
+
+#define DP_VCO_HSCLK_RATE_1620MHZDIV1000       1620000UL
+#define DP_VCO_HSCLK_RATE_2700MHZDIV1000       2700000UL
+#define DP_VCO_HSCLK_RATE_5400MHZDIV1000       5400000UL
+#define DP_VCO_HSCLK_RATE_8100MHZDIV1000       8100000UL
+
+#define NUM_DP_CLOCKS_MAX                      6
+
+#define DP_PHY_PLL_POLL_SLEEP_US               500
+#define DP_PHY_PLL_POLL_TIMEOUT_US             10000
+
+#define DP_VCO_RATE_8100MHZDIV1000             8100000UL
+#define DP_VCO_RATE_9720MHZDIV1000             9720000UL
+#define DP_VCO_RATE_10800MHZDIV1000            10800000UL
+
+struct dp_pll_10nm {
+       struct msm_dp_pll base;
+
+       int id;
+       struct platform_device *pdev;
+
+       void __iomem *pll_base;
+       void __iomem *phy_base;
+       void __iomem *ln_tx0_base;
+       void __iomem *ln_tx1_base;
+
+       /* private clocks: */
+       struct clk_hw *hws[NUM_DP_CLOCKS_MAX];
+       u32 num_hws;
+
+       /* clock-provider: */
+       struct clk_hw_onecell_data *hw_data;
+
+       /* lane and orientation settings */
+       u8 lane_cnt;
+       u8 orientation;
+
+       /* COM PHY settings */
+       u32 hsclk_sel;
+       u32 dec_start_mode0;
+       u32 div_frac_start1_mode0;
+       u32 div_frac_start2_mode0;
+       u32 div_frac_start3_mode0;
+       u32 integloop_gain0_mode0;
+       u32 integloop_gain1_mode0;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h line 73

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +10 -0
+       u32 vco_tune_map;
+       u32 lock_cmp1_mode0;
+       u32 lock_cmp2_mode0;
+       u32 lock_cmp3_mode0;
+       u32 lock_cmp_en;
+
+       /* PHY vco divider */
+       u32 phy_vco_div;
+       /*
+        * Certain pll's needs to update the same vco rate after resume in

PLLs is plural, not possessive.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h line 74

Quoted 1 line
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +1 -0
+        * suspend/resume scenario. Cached the vco rate for such plls.

There you go!

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h line 79

Quoted 5 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +5 -0
+        */
+       unsigned long   vco_cached_rate;
+       u32             cached_cfg0;
+       u32             cached_cfg1;
+       u32             cached_outdiv;

Is this to restore across suspend/resume?

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h line 81

Quoted 2 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +2 -0
+
+       uint32_t index;

We use u32 in kernel code, not uint32_t.

Quoted 28 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm.h new file +13 -0
+};
+
+#define to_dp_pll_10nm(x)      container_of(x, struct dp_pll_10nm, base)
+
+int dp_vco_set_rate_10nm(struct clk_hw *hw, unsigned long rate,
+                               unsigned long parent_rate);
+unsigned long dp_vco_recalc_rate_10nm(struct clk_hw *hw,
+                               unsigned long parent_rate);
+long dp_vco_round_rate_10nm(struct clk_hw *hw, unsigned long rate,
+                               unsigned long *parent_rate);
+int dp_vco_prepare_10nm(struct clk_hw *hw);
+void dp_vco_unprepare_10nm(struct clk_hw *hw);
+#endif /* __DP_PLL_10NM_H */
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +9 -0
new file mode 100644
index 0000000..9eb6881
@@ -0,0 +1,531 @@
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 19

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+ * GNU General Public License for more details.
+ *
+ */
+
+#define pr_fmt(fmt)    "%s: " fmt, __func__
+
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/iopoll.h>
+#include <linux/delay.h>

Where's clk-provider.h?

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 23

Quoted 4 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +4 -0
+
+#include "dp_pll.h"
+#include "dp_pll_10nm.h"
+#include "dp_extcon.h"

Is this used?

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +8 -0
+
+static int dp_vco_pll_init_db_10nm(struct msm_dp_pll *pll,
+               unsigned long rate)
+{
+       struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+       u32 spare_value = 0;
+
+       spare_value = PLL_REG_R(dp_res->phy_base, DP_PHY_SPARE0);

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 41

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+       dp_res->lane_cnt = spare_value & 0x0F;
+       dp_res->orientation = (spare_value & 0xF0) >> 4;
+
+       pr_debug("%s: spare_value=0x%x, ln_cnt=0x%x, orientation=0x%x\n",
+                       __func__, spare_value, dp_res->lane_cnt, dp_res->orientation);
+
+       switch (rate) {
+       case DP_VCO_HSCLK_RATE_1620MHZDIV1000:
+               pr_debug("%s: VCO rate: %ld\n", __func__,
+                               DP_VCO_RATE_9720MHZDIV1000);

These debug prints don't match the case statement above. Why?

Quoted 41 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +41 -0
+               dp_res->hsclk_sel = 0x0c;
+               dp_res->dec_start_mode0 = 0x69;
+               dp_res->div_frac_start1_mode0 = 0x00;
+               dp_res->div_frac_start2_mode0 = 0x80;
+               dp_res->div_frac_start3_mode0 = 0x07;
+               dp_res->integloop_gain0_mode0 = 0x3f;
+               dp_res->integloop_gain1_mode0 = 0x00;
+               dp_res->vco_tune_map = 0x00;
+               dp_res->lock_cmp1_mode0 = 0x6f;
+               dp_res->lock_cmp2_mode0 = 0x08;
+               dp_res->lock_cmp3_mode0 = 0x00;
+               dp_res->phy_vco_div = 0x1;
+               dp_res->lock_cmp_en = 0x00;
+               break;
+       case DP_VCO_HSCLK_RATE_2700MHZDIV1000:
+               pr_debug("%s: VCO rate: %ld\n", __func__,
+                               DP_VCO_RATE_10800MHZDIV1000);
+               dp_res->hsclk_sel = 0x04;
+               dp_res->dec_start_mode0 = 0x69;
+               dp_res->div_frac_start1_mode0 = 0x00;
+               dp_res->div_frac_start2_mode0 = 0x80;
+               dp_res->div_frac_start3_mode0 = 0x07;
+               dp_res->integloop_gain0_mode0 = 0x3f;
+               dp_res->integloop_gain1_mode0 = 0x00;
+               dp_res->vco_tune_map = 0x00;
+               dp_res->lock_cmp1_mode0 = 0x0f;
+               dp_res->lock_cmp2_mode0 = 0x0e;
+               dp_res->lock_cmp3_mode0 = 0x00;
+               dp_res->phy_vco_div = 0x1;
+               dp_res->lock_cmp_en = 0x00;
+               break;
+       case DP_VCO_HSCLK_RATE_5400MHZDIV1000:
+               pr_debug("%s: VCO rate: %ld\n", __func__,
+                               DP_VCO_RATE_10800MHZDIV1000);
+               dp_res->hsclk_sel = 0x00;
+               dp_res->dec_start_mode0 = 0x8c;
+               dp_res->div_frac_start1_mode0 = 0x00;
+               dp_res->div_frac_start2_mode0 = 0x00;
+               dp_res->div_frac_start3_mode0 = 0x0a;
+               dp_res->integloop_gain0_mode0 = 0x3f;
+               dp_res->integloop_gain1_mode0 = 0x00;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 92

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+               dp_res->vco_tune_map = 0x00;
+               dp_res->lock_cmp1_mode0 = 0x1f;
+               dp_res->lock_cmp2_mode0 = 0x1c;
+               dp_res->lock_cmp3_mode0 = 0x00;
+               dp_res->phy_vco_div = 0x2;
+               dp_res->lock_cmp_en = 0x00;
+               break;
+       case DP_VCO_HSCLK_RATE_8100MHZDIV1000:
+               pr_debug("%s: VCO rate: %ld\n", __func__,
+                               DP_VCO_RATE_8100MHZDIV1000);

Ah this one matches though.

Quoted 41 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +41 -0
+               dp_res->hsclk_sel = 0x03;
+               dp_res->dec_start_mode0 = 0x69;
+               dp_res->div_frac_start1_mode0 = 0x00;
+               dp_res->div_frac_start2_mode0 = 0x80;
+               dp_res->div_frac_start3_mode0 = 0x07;
+               dp_res->integloop_gain0_mode0 = 0x3f;
+               dp_res->integloop_gain1_mode0 = 0x00;
+               dp_res->vco_tune_map = 0x00;
+               dp_res->lock_cmp1_mode0 = 0x2f;
+               dp_res->lock_cmp2_mode0 = 0x2a;
+               dp_res->lock_cmp3_mode0 = 0x00;
+               dp_res->phy_vco_div = 0x0;
+               dp_res->lock_cmp_en = 0x08;
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static int dp_config_vco_rate_10nm(struct msm_dp_pll *pll,
+               unsigned long rate)
+{
+       u32 res = 0;
+       struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+
+       res = dp_vco_pll_init_db_10nm(pll, rate);
+       if (res) {
+               pr_err("VCO Init DB failed\n");
+               return res;
+       }
+
+       if (dp_res->lane_cnt != 4) {
+               if (dp_res->orientation == ORIENTATION_CC2)
+                       PLL_REG_W(dp_res->phy_base, DP_PHY_PD_CTL, 0x6d);
+               else
+                       PLL_REG_W(dp_res->phy_base, DP_PHY_PD_CTL, 0x75);
+       } else {
+               PLL_REG_W(dp_res->phy_base, DP_PHY_PD_CTL, 0x7d);
+       }
+

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 143

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+       /* Make sure the PHY register writes are done */
+       wmb();
+
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_SVS_MODE_CLK_SEL, 0x01);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_SYSCLK_EN_SEL, 0x37);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_SYS_CLK_CTRL, 0x02);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_CLK_ENABLE1, 0x0e);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_SYSCLK_BUF_ENABLE, 0x06);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_CLK_SEL, 0x30);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_CMN_CONFIG, 0x02);

All these lines could be much shorter with a local variable, 'base', that got assigned once at the start and then used throughout.

Quoted 16 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +16 -0
+
+       /* Different for each clock rates */
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_HSCLK_SEL, dp_res->hsclk_sel);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_DEC_START_MODE0, dp_res->dec_start_mode0);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_DIV_FRAC_START1_MODE0, dp_res->div_frac_start1_mode0);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_DIV_FRAC_START2_MODE0, dp_res->div_frac_start2_mode0);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_DIV_FRAC_START3_MODE0, dp_res->div_frac_start3_mode0);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_INTEGLOOP_GAIN0_MODE0, dp_res->integloop_gain0_mode0);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_INTEGLOOP_GAIN1_MODE0, dp_res->integloop_gain1_mode0);

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 169

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_VCO_TUNE_MAP, dp_res->vco_tune_map);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_LOCK_CMP1_MODE0, dp_res->lock_cmp1_mode0);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_LOCK_CMP2_MODE0, dp_res->lock_cmp2_mode0);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_LOCK_CMP3_MODE0, dp_res->lock_cmp3_mode0);
+       /* Make sure the PLL register writes are done */
+       wmb();

Is this to make sure that the next register writes happen after the above register writes? The comment could say that instead, but then realize that they may be sitting somewhere in the bus waiting to write to the device still, so if it really has to be written to the device we need to read back the last register written to be sure that the write posted to the device.

Quoted 59 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +59 -0
+
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_BG_TIMER, 0x0a);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_CORECLK_DIV_MODE0, 0x0a);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_VCO_TUNE_CTRL, 0x00);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x3f);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_CORE_CLK_EN, 0x1f);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_PLL_IVCO, 0x07);
+       PLL_REG_W(dp_res->pll_base,
+               QSERDES_COM_LOCK_CMP_EN, dp_res->lock_cmp_en);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_PLL_CCTRL_MODE0, 0x36);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_PLL_RCTRL_MODE0, 0x16);
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_CP_CTRL_MODE0, 0x06);
+       /* Make sure the PHY register writes are done */
+       wmb();
+
+       if (dp_res->orientation == ORIENTATION_CC2)
+               PLL_REG_W(dp_res->phy_base, DP_PHY_MODE, 0x4c);
+       else
+               PLL_REG_W(dp_res->phy_base, DP_PHY_MODE, 0x5c);
+       /* Make sure the PLL register writes are done */
+       wmb();
+
+       /* TX Lane configuration */
+       PLL_REG_W(dp_res->phy_base,
+                       DP_PHY_TX0_TX1_LANE_CTL, 0x05);
+       PLL_REG_W(dp_res->phy_base,
+                       DP_PHY_TX2_TX3_LANE_CTL, 0x05);
+
+       /* TX-0 register configuration */
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_TRANSCEIVER_BIAS_EN, 0x1a);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_VMODE_CTRL1, 0x40);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_PRE_STALL_LDO_BOOST_EN, 0x30);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_INTERFACE_SELECT, 0x3d);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_CLKBUF_ENABLE, 0x0f);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_RESET_TSYNC_EN, 0x03);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_TRAN_DRVR_EMP_EN, 0x03);
+       PLL_REG_W(dp_res->ln_tx0_base,
+               TXn_PARRATE_REC_DETECT_IDLE_EN, 0x00);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_INTERFACE_MODE, 0x00);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_BAND, 0x4);
+
+       /* TX-1 register configuration */
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_TRANSCEIVER_BIAS_EN, 0x1a);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_VMODE_CTRL1, 0x40);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_PRE_STALL_LDO_BOOST_EN, 0x30);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_INTERFACE_SELECT, 0x3d);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_CLKBUF_ENABLE, 0x0f);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_RESET_TSYNC_EN, 0x03);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_TRAN_DRVR_EMP_EN, 0x03);
+       PLL_REG_W(dp_res->ln_tx1_base,
+               TXn_PARRATE_REC_DETECT_IDLE_EN, 0x00);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_INTERFACE_MODE, 0x00);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_BAND, 0x4);
+       /* Make sure the PHY register writes are done */
+       wmb();
+
+       /* dependent on the vco frequency */
+       PLL_REG_W(dp_res->phy_base, DP_PHY_VCO_DIV, dp_res->phy_vco_div);
+

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 238

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+       return res;
+}
+
+static bool dp_10nm_pll_lock_status(struct dp_pll_10nm *dp_res)
+{
+       u32 status;
+       bool pll_locked;
+
+       /* poll for PLL lock status */
+       if (readl_poll_timeout_atomic((dp_res->pll_base +

Why atomic? As far as I can tell this is done in sleepable context because it all falls into clk_prepare() path.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 246

Quoted 8 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +8 -0
+                       QSERDES_COM_C_READY_STATUS),
+                       status,
+                       ((status & BIT(0)) > 0),
+                       DP_PHY_PLL_POLL_SLEEP_US,
+                       DP_PHY_PLL_POLL_TIMEOUT_US)) {
+               pr_err("%s: C_READY status is not high. Status=%x\n",
+                               __func__, status);
+               pll_locked = false;

Just 'return false'?

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 251

Quoted 5 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +5 -0
+       } else {
+               pll_locked = true;
+       }
+
+       return pll_locked;

And reduce this to 'return true'?

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 260

Quoted 9 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +9 -0
+}
+
+static bool dp_10nm_phy_rdy_status(struct dp_pll_10nm *dp_res)
+{
+       u32 status;
+       bool phy_ready = true;
+
+       /* poll for PHY ready status */
+       if (readl_poll_timeout_atomic((dp_res->phy_base +

No need for atomic?

Quoted 69 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +69 -0
+                       DP_PHY_STATUS),
+                       status,
+                       ((status & (BIT(1))) > 0),
+                       DP_PHY_PLL_POLL_SLEEP_US,
+                       DP_PHY_PLL_POLL_TIMEOUT_US)) {
+               pr_err("%s: Phy_ready is not high. Status=%x\n",
+                               __func__, status);
+               phy_ready = false;
+       }
+
+       return phy_ready;
+}
+
+static int dp_pll_enable_10nm(struct clk_hw *hw)
+{
+       int rc = 0;
+       struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+       struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+       u32 bias_en, drvr_en;
+
+       PLL_REG_W(dp_res->phy_base, DP_PHY_AUX_CFG2, 0x04);
+       PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x01);
+       PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x05);
+       PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x01);
+       PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x09);
+       wmb(); /* Make sure the PHY register writes are done */
+
+       PLL_REG_W(dp_res->pll_base, QSERDES_COM_RESETSM_CNTRL, 0x20);
+       wmb();  /* Make sure the PLL register writes are done */
+
+       if (!dp_10nm_pll_lock_status(dp_res)) {
+               rc = -EINVAL;
+               goto lock_err;
+       }
+
+       PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x19);
+       /* Make sure the PHY register writes are done */
+       wmb();
+       /* poll for PHY ready status */
+       if (!dp_10nm_phy_rdy_status(dp_res)) {
+               rc = -EINVAL;
+               goto lock_err;
+       }
+
+       pr_debug("%s: PLL is locked\n", __func__);
+
+       if (dp_res->lane_cnt == 1) {
+               bias_en = 0x3e;
+               drvr_en = 0x13;
+       } else {
+               bias_en = 0x3f;
+               drvr_en = 0x10;
+       }
+
+       if (dp_res->lane_cnt != 4) {
+               if (dp_res->orientation == ORIENTATION_CC1) {
+                       PLL_REG_W(dp_res->ln_tx1_base,
+                               TXn_HIGHZ_DRVR_EN, drvr_en);
+                       PLL_REG_W(dp_res->ln_tx1_base,
+                               TXn_TRANSCEIVER_BIAS_EN, bias_en);
+               } else {
+                       PLL_REG_W(dp_res->ln_tx0_base,
+                               TXn_HIGHZ_DRVR_EN, drvr_en);
+                       PLL_REG_W(dp_res->ln_tx0_base,
+                               TXn_TRANSCEIVER_BIAS_EN, bias_en);
+               }
+       } else {
+               PLL_REG_W(dp_res->ln_tx0_base, TXn_HIGHZ_DRVR_EN, drvr_en);
+               PLL_REG_W(dp_res->ln_tx0_base,

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 339

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+                       TXn_TRANSCEIVER_BIAS_EN, bias_en);
+               PLL_REG_W(dp_res->ln_tx1_base, TXn_HIGHZ_DRVR_EN, drvr_en);
+               PLL_REG_W(dp_res->ln_tx1_base,
+                       TXn_TRANSCEIVER_BIAS_EN, bias_en);
+       }
+
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_POL_INV, 0x0a);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_POL_INV, 0x0a);
+       PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x18);
+       udelay(2000);

What are we waiting for? You need an explicit readl() if you're waiting for that DP_PHY_CFG write to post and do something.

Quoted 53 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +53 -0
+
+       PLL_REG_W(dp_res->phy_base, DP_PHY_CFG, 0x19);
+
+       /*
+        * Make sure all the register writes are completed before
+        * doing any other operation
+        */
+       wmb();
+
+       /* poll for PHY ready status */
+       if (!dp_10nm_phy_rdy_status(dp_res)) {
+               rc = -EINVAL;
+               goto lock_err;
+       }
+
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_DRV_LVL, 0x38);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_DRV_LVL, 0x38);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_TX_EMP_POST1_LVL, 0x20);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_TX_EMP_POST1_LVL, 0x20);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_RES_CODE_LANE_OFFSET_TX, 0x06);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_RES_CODE_LANE_OFFSET_TX, 0x06);
+       PLL_REG_W(dp_res->ln_tx0_base, TXn_RES_CODE_LANE_OFFSET_RX, 0x07);
+       PLL_REG_W(dp_res->ln_tx1_base, TXn_RES_CODE_LANE_OFFSET_RX, 0x07);
+       /* Make sure the PHY register writes are done */
+       wmb();
+
+lock_err:
+       return rc;
+}
+
+static int dp_pll_disable_10nm(struct clk_hw *hw)
+{
+       int rc = 0;
+       struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+       struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+
+       /* Assert DP PHY power down */
+       PLL_REG_W(dp_res->phy_base, DP_PHY_PD_CTL, 0x2);
+       /*
+        * Make sure all the register writes to disable PLL are
+        * completed before doing any other operation
+        */
+       wmb();
+
+       return rc;
+}
+
+
+int dp_vco_prepare_10nm(struct clk_hw *hw)
+{
+       int rc = 0;
+       struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+       struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 402

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+
+       pr_debug("rate=%ld\n", pll->rate);
+       if ((dp_res->vco_cached_rate != 0)
+               && (dp_res->vco_cached_rate == pll->rate)) {
+               rc = pll->clk_hw.init->ops->set_rate(hw,
+                       dp_res->vco_cached_rate, dp_res->vco_cached_rate);
+               if (rc) {
+                       pr_err("index=%d vco_set_rate failed. rc=%d\n",
+                               rc, dp_res->index);
+                       goto error;

Please just return instead of goto return.

Quoted 20 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +20 -0
+               }
+       }
+
+       rc = dp_pll_enable_10nm(hw);
+       if (rc) {
+               pr_err("ndx=%d failed to enable dp pll\n",
+                                       dp_res->index);
+               goto error;
+       }
+
+       pll->pll_on = true;
+error:
+       return rc;
+}
+
+void dp_vco_unprepare_10nm(struct clk_hw *hw)
+{
+       struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+       struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 432

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+       if (!dp_res) {
+               pr_err("Invalid input parameter\n");
+               return;
+       }
+
+       if (!pll->pll_on) {
+               pr_err("pll resource can't be enabled\n");
+               return;
+       }
+       dp_res->vco_cached_rate = pll->rate;

Why are we caching rates on unprepare? I'd think we would want to save away the rate regardless of on/off state and then restore the rate when the device is powered back on. That wouldn't necessarily follow the on/off state.

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 435

Quoted 3 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +3 -0
+       dp_pll_disable_10nm(hw);
+
+       //dp_res->handoff_resources = false;

Please remove commented out code.

Quoted 67 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +67 -0
+       pll->pll_on = false;
+}
+
+int dp_vco_set_rate_10nm(struct clk_hw *hw, unsigned long rate,
+                                       unsigned long parent_rate)
+{
+       struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+       int rc;
+
+       pr_debug("DP lane CLK rate=%ld\n", rate);
+
+       rc = dp_config_vco_rate_10nm(pll, rate);
+       if (rc)
+               pr_err("%s: Failed to set clk rate\n", __func__);
+
+       pll->rate = rate;
+
+       return 0;
+}
+
+unsigned long dp_vco_recalc_rate_10nm(struct clk_hw *hw,
+                                       unsigned long parent_rate)
+{
+       struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+       struct dp_pll_10nm *dp_res = to_dp_pll_10nm(pll);
+       u32 div, hsclk_div, link_clk_div = 0;
+       u64 vco_rate;
+
+       div = PLL_REG_R(dp_res->pll_base, QSERDES_COM_HSCLK_SEL);
+       div &= 0x0f;
+
+       if (div == 12)
+               hsclk_div = 6; /* Default */
+       else if (div == 4)
+               hsclk_div = 4;
+       else if (div == 0)
+               hsclk_div = 2;
+       else if (div == 3)
+               hsclk_div = 1;
+       else {
+               pr_debug("unknown divider. forcing to default\n");
+               hsclk_div = 5;
+       }
+
+       div = PLL_REG_R(dp_res->phy_base, DP_PHY_AUX_CFG2);
+       div >>= 2;
+
+       if ((div & 0x3) == 0)
+               link_clk_div = 5;
+       else if ((div & 0x3) == 1)
+               link_clk_div = 10;
+       else if ((div & 0x3) == 2)
+               link_clk_div = 20;
+       else
+               pr_err("%s: unsupported div. Phy_mode: %d\n", __func__, div);
+
+       if (link_clk_div == 20) {
+               vco_rate = DP_VCO_HSCLK_RATE_2700MHZDIV1000;
+       } else {
+               if (hsclk_div == 6)
+                       vco_rate = DP_VCO_HSCLK_RATE_1620MHZDIV1000;
+               else if (hsclk_div == 4)
+                       vco_rate = DP_VCO_HSCLK_RATE_2700MHZDIV1000;
+               else if (hsclk_div == 2)
+                       vco_rate = DP_VCO_HSCLK_RATE_5400MHZDIV1000;
+               else
+                       vco_rate = DP_VCO_HSCLK_RATE_8100MHZDIV1000;

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 512

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+       }
+
+       pr_debug("returning vco rate = %lu\n", (unsigned long)vco_rate);
+
+       dp_res->vco_cached_rate = pll->rate = vco_rate;
+       return (unsigned long)vco_rate;
+}
+
+long dp_vco_round_rate_10nm(struct clk_hw *hw, unsigned long rate,
+                       unsigned long *parent_rate)

Implement determine_rate op instead. It lets you clamp rates better.

Quoted 7 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +7 -0
+{
+       unsigned long rrate = rate;
+       struct msm_dp_pll *pll = hw_clk_to_pll(hw);
+
+       if (rate <= pll->min_rate)
+               rrate = pll->min_rate;
+       else if (rate <= DP_VCO_HSCLK_RATE_2700MHZDIV1000)

drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c line 529

Quoted 10 lines
drivers/gpu/drm/msm/dp/pll/dp_pll_10nm_util.c new file +10 -0
+               rrate = DP_VCO_HSCLK_RATE_2700MHZDIV1000;
+       else if (rate <= DP_VCO_HSCLK_RATE_5400MHZDIV1000)
+               rrate = DP_VCO_HSCLK_RATE_5400MHZDIV1000;
+       else
+               rrate = pll->max_rate;
+
+       pr_debug("%s: rrate=%ld\n", __func__, rrate);
+
+       *parent_rate = rrate;
+       return rrate;

This whole function looks not very useful though. Just pass up the rate to the parent and have it do the rounding?

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

#12 lore raw

Re: [DPU PATCH 2/3] drm/msm/dp: add displayPort driver support

In reply to Sean Paul
Quoted 9 lines · Sean Paul
Quoted 7 lines · Chandan Uddaraju

Add the needed displayPort files to enable DP driver on msm target.

"dp_display" module is the main module that calls into other sub-modules. "dp_drm" file represents the interface between DRM framework and DP driver.

Hello Sean,
I had few queries regarding your comments. Shared my queries below. Please share your feedback.

Quoted 540 lines

Hi Chandan,
A few themes which I've pointed out below, but want to call out at the top so it's obvious.

- Please remove all superfluous NULL checks at the beginning of functions.
Included in this is reflowing initialization of variables and
checking that
return types still make sense (ie: if a function's only error path is
the NULL
check, make it void).
- Please remove all of the new callbacks and just call functions directly. This
should also get rid of the _get/_put functions that allocate/set them
up
- Please consolidate state structs into one struct with a few substructs,
there's too much state right now.
- Please #define hardcoded values
- Instead of sprinkling wmb() everywhere, use readl/writel instead of *_relaxed
- There are a bunch of races that I found, please audit the code and remove
races with locks as necessary
- I tried to catch as much dead code as possible, please audit the rest for
unused structs/variables/functions/etc
- Use drm dp helper structs for link parameter storage

Quoted 67 lines
---
 drivers/gpu/drm/msm/Kconfig                 |    9 +
 drivers/gpu/drm/msm/Makefile                |   15 +-
 drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c |  206 ++++
 drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h |   44 +
 drivers/gpu/drm/msm/dp/dp_aux.c             |  570 ++++++++++
 drivers/gpu/drm/msm/dp/dp_aux.h             |   44 +
 drivers/gpu/drm/msm/dp/dp_catalog.c         | 1188 
++++++++++++++++++++
 drivers/gpu/drm/msm/dp/dp_catalog.h         |  144 +++
 drivers/gpu/drm/msm/dp/dp_ctrl.c            | 1475 
+++++++++++++++++++++++++
 drivers/gpu/drm/msm/dp/dp_ctrl.h            |   50 +
 drivers/gpu/drm/msm/dp/dp_debug.c           |  507 +++++++++
 drivers/gpu/drm/msm/dp/dp_debug.h           |   81 ++
 drivers/gpu/drm/msm/dp/dp_display.c         |  977 +++++++++++++++++
 drivers/gpu/drm/msm/dp/dp_display.h         |   55 +
 drivers/gpu/drm/msm/dp/dp_drm.c             |  542 ++++++++++
 drivers/gpu/drm/msm/dp/dp_drm.h             |   52 +
 drivers/gpu/drm/msm/dp/dp_extcon.c          |  400 +++++++
 drivers/gpu/drm/msm/dp/dp_extcon.h          |  111 ++
 drivers/gpu/drm/msm/dp/dp_link.c            | 1549 
+++++++++++++++++++++++++++
 drivers/gpu/drm/msm/dp/dp_link.h            |  184 ++++
 drivers/gpu/drm/msm/dp/dp_panel.c           |  624 +++++++++++
 drivers/gpu/drm/msm/dp/dp_panel.h           |  121 +++
 drivers/gpu/drm/msm/dp/dp_parser.c          |  679 ++++++++++++
 drivers/gpu/drm/msm/dp/dp_parser.h          |  205 ++++
 drivers/gpu/drm/msm/dp/dp_power.c           |  599 +++++++++++
 drivers/gpu/drm/msm/dp/dp_power.h           |   57 +
 drivers/gpu/drm/msm/dp/dp_reg.h             |  357 ++++++
 drivers/gpu/drm/msm/msm_drv.c               |    2 +
 drivers/gpu/drm/msm/msm_drv.h               |   22 +
 include/drm/drm_dp_helper.h                 |   19 +
 30 files changed, 10887 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/msm/dp/dp_aux.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_aux.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_catalog.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_catalog.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_ctrl.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_ctrl.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_debug.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_debug.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_display.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_display.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_drm.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_drm.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_extcon.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_extcon.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_link.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_link.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_panel.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_panel.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_parser.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_parser.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_power.c
 create mode 100644 drivers/gpu/drm/msm/dp/dp_power.h
 create mode 100644 drivers/gpu/drm/msm/dp/dp_reg.h
drivers/gpu/drm/msm/Kconfig +0 -0
index 843a9d4..c363f24 100644
@@ -49,6 +49,15 @@ config DRM_MSM_HDMI_HDCP
 	help
 	  Choose this option to enable HDCP state machine

drivers/gpu/drm/msm/Kconfig config DRM_MSM_HDMI_HDCP · line 60

Quoted 10 lines
drivers/gpu/drm/msm/Kconfig +9 -0
 
+config DRM_MSM_DP
+	bool "Enable DP support in MSM DRM driver"
+	depends on DRM_MSM
+	default n
+	help
+	  Compile in support for DP driver in msm drm
+	  driver. DP external display support is enabled
+	  through this config option. It can be primary or
+	  secondary display on device.

Why are these line lengths so short? You can go to 80 columns. Please also add an empty line here.

Quoted 16 lines
drivers/gpu/drm/msm/Kconfig +0 -0
 config DRM_MSM_DSI
 	bool "Enable DSI support in MSM DRM driver"
 	depends on DRM_MSM
drivers/gpu/drm/msm/Makefile +1 -0
index 19ab521..765a8d8 100644
@@ -2,6 +2,7 @@
 ccflags-y := -Idrivers/gpu/drm/msm
 ccflags-y += -Idrivers/gpu/drm/msm/disp/dpu1
 ccflags-$(CONFIG_DRM_MSM_DSI) += -Idrivers/gpu/drm/msm/dsi
+ccflags-$(CONFIG_DRM_MSM_DP) += -Idrivers/gpu/drm/msm/dp
 
 msm-y := \
 	adreno/adreno_device.o \

drivers/gpu/drm/msm/Makefile msm-y := \ · line 98

Quoted 6 lines
drivers/gpu/drm/msm/Makefile +2 -1
@@ -93,7 +94,19 @@ msm-y := \
 	msm_submitqueue.o
 
 msm-$(CONFIG_DEBUG_FS) += adreno/a5xx_debugfs.o \
-			  disp/dpu1/dpu_dbg.o
+			  disp/dpu1/dpu_dbg.o \
+			  dp/dp_debug.o

Does this compile if CONFIG_DEBUG_FS is selected, but not CONFIG_DRM_MSM_DP?

drivers/gpu/drm/msm/Makefile msm-y := \ · line 109

Quoted 11 lines
drivers/gpu/drm/msm/Makefile +11 -0
+
+msm-$(CONFIG_DRM_MSM_DP)+= dp/dp_extcon.o \
+	dp/dp_parser.o \
+	dp/dp_power.o \
+	dp/dp_catalog.o \
+	dp/dp_aux.o \
+	dp/dp_panel.o \
+	dp/dp_link.o \
+	dp/dp_ctrl.o \
+	dp/dp_display.o \
+	dp/dp_drm.o

The rest of the file has files in alphabetical order, this should too.

Quoted 20 lines
drivers/gpu/drm/msm/Makefile +0 -0
 msm-$(CONFIG_DRM_FBDEV_EMULATION) += msm_fbdev.o
 msm-$(CONFIG_COMMON_CLK) += disp/mdp4/mdp4_lvds_pll.o
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +4 -0
index 790d39f..0f53a15 100644
@@ -14,10 +14,216 @@
 #include <linux/clk.h>
 #include <linux/clk/clk-conf.h>
 #include <linux/err.h>
+#include <linux/io.h>
+#include <linux/regulator/consumer.h>
 #include <linux/delay.h>
 
 #include "dpu_io_util.h"
 
+static struct resource *msm_dss_get_res_byname(struct platform_device 
 *pdev,
+					       unsigned int type,

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c line 35

Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +10 -0
+					       const char *name)
+{
+	struct resource *res = NULL;
+
+	res = platform_get_resource_byname(pdev, type, name);
+	if (!res)
+		DEV_ERR("%s: '%s' resource not found\n", __func__, name);
+
+	return res;
+} /* msm_dss_get_res_byname */

Why don't you just call platform_get_resource_byname directly?

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c line 41

Quoted 7 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +7 -0
+
+int msm_dss_ioremap_byname(struct platform_device *pdev,
+			   struct dss_io_data *io_data, const char *name)
+{
+	struct resource *res = NULL;
+
+	if (!pdev || !io_data) {

Given that we've been aggressively trying to get rid of these superfluous checks, I'm not thrilled that they're being re-introduced. Can you please go through the patch and remove all of the unnecessary checks?

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c line 50

Quoted 9 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +9 -0
+		DEV_ERR("%pS->%s: invalid input\n",
+			__builtin_return_address(0), __func__);
+		return -EINVAL;
+	}
+
+	res = msm_dss_get_res_byname(pdev, IORESOURCE_MEM, name);
+	if (!res) {
+		DEV_ERR("%pS->%s: '%s' msm_dss_get_res_byname failed\n",
+			__builtin_return_address(0), __func__, name);

Yet another error format :) Could we please stick with one of DPU_ERROR, DRM_ERROR, or DRM_DEV_ERROR?

Quoted 18 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +18 -0
+		return -ENODEV;
+	}
+
+	io_data->len = (u32)resource_size(res);
+	io_data->base = ioremap(res->start, io_data->len);
+	if (!io_data->base) {
+		DEV_ERR("%pS->%s: '%s' ioremap failed\n",
+			__builtin_return_address(0), __func__, name);
+		return -EIO;
+	}
+
+	return 0;
+} /* msm_dss_ioremap_byname */
+
+void msm_dss_iounmap(struct dss_io_data *io_data)
+{
+	if (!io_data) {
+		DEV_ERR("%pS->%s: invalid input\n",

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c line 78

Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +10 -0
+			__builtin_return_address(0), __func__);
+		return;
+	}
+
+	if (io_data->base) {
+		iounmap(io_data->base);
+		io_data->base = NULL;
+	}
+	io_data->len = 0;
+} /* msm_dss_iounmap */

These two functions are only used in dp_parser.c, why not just make them static functions there?

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c line 81

Quoted 3 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +3 -0
+
+int msm_dss_config_vreg(struct device *dev, struct dss_vreg *in_vreg,
+			int num_vreg, int config)

This should be 2 functions, one for initialization and one for deinitializing, the 2 paths don't share any code, so there's no need to combine them.

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c line 93

Quoted 12 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +12 -0
+{
+	int i = 0, rc = 0;
+	struct dss_vreg *curr_vreg = NULL;
+	enum dss_vreg_type type;
+
+	if (!in_vreg || !num_vreg)
+		return rc;
+
+	if (config) {
+		for (i = 0; i < num_vreg; i++) {
+			curr_vreg = &in_vreg[i];
+			curr_vreg->vreg = regulator_get(dev,

Use devm_* please

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c line 95

Quoted 2 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +2 -0
+				curr_vreg->vreg_name);
+			rc = PTR_RET(curr_vreg->vreg);

PTR_RET is deprecated. The pattern for this is usually:

                        ptr = some_func();
                        if (IS_ERR_OR_NULL(ptr)) {
                                ...
                                rc = PTR_ERR(ptr);
                                goto fail_label:
                        }
Quoted 121 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +120 -0
+			if (rc) {
+				DEV_ERR("%pS->%s: %s get failed. rc=%d\n",
+					 __builtin_return_address(0), __func__,
+					 curr_vreg->vreg_name, rc);
+				curr_vreg->vreg = NULL;
+				goto vreg_get_fail;
+			}
+			type = (regulator_count_voltages(curr_vreg->vreg) > 0)
+					? DSS_REG_LDO : DSS_REG_VS;
+			if (type == DSS_REG_LDO) {
+				rc = regulator_set_voltage(
+					curr_vreg->vreg,
+					curr_vreg->min_voltage,
+					curr_vreg->max_voltage);
+				if (rc < 0) {
+					DEV_ERR("%pS->%s: %s set vltg fail\n",
+						__builtin_return_address(0),
+						__func__,
+						curr_vreg->vreg_name);
+					goto vreg_set_voltage_fail;
+				}
+			}
+		}
+	} else {
+		for (i = num_vreg-1; i >= 0; i--) {
+			curr_vreg = &in_vreg[i];
+			if (curr_vreg->vreg) {
+				type = (regulator_count_voltages(
+					curr_vreg->vreg) > 0)
+					? DSS_REG_LDO : DSS_REG_VS;
+				if (type == DSS_REG_LDO) {
+					regulator_set_voltage(curr_vreg->vreg,
+						0, curr_vreg->max_voltage);
+				}
+				regulator_put(curr_vreg->vreg);
+				curr_vreg->vreg = NULL;
+			}
+		}
+	}
+	return 0;
+
+vreg_unconfig:
+if (type == DSS_REG_LDO)
+	regulator_set_load(curr_vreg->vreg, 0);
+
+vreg_set_voltage_fail:
+	regulator_put(curr_vreg->vreg);
+	curr_vreg->vreg = NULL;
+
+vreg_get_fail:
+	for (i--; i >= 0; i--) {
+		curr_vreg = &in_vreg[i];
+		type = (regulator_count_voltages(curr_vreg->vreg) > 0)
+			? DSS_REG_LDO : DSS_REG_VS;
+		goto vreg_unconfig;
+	}
+	return rc;
+} /* msm_dss_config_vreg */
+
+int msm_dss_enable_vreg(struct dss_vreg *in_vreg, int num_vreg, int 
 enable)
+{
+	int i = 0, rc = 0;
+	bool need_sleep;
+
+	if (enable) {
+		for (i = 0; i < num_vreg; i++) {
+			rc = PTR_RET(in_vreg[i].vreg);
+			if (rc) {
+				DEV_ERR("%pS->%s: %s regulator error. rc=%d\n",
+					__builtin_return_address(0), __func__,
+					in_vreg[i].vreg_name, rc);
+				goto vreg_set_opt_mode_fail;
+			}
+			need_sleep = !regulator_is_enabled(in_vreg[i].vreg);
+			if (in_vreg[i].pre_on_sleep && need_sleep)
+				usleep_range(in_vreg[i].pre_on_sleep * 1000,
+					in_vreg[i].pre_on_sleep * 1000);
+			rc = regulator_set_load(in_vreg[i].vreg,
+				in_vreg[i].enable_load);
+			if (rc < 0) {
+				DEV_ERR("%pS->%s: %s set opt m fail\n",
+					__builtin_return_address(0), __func__,
+					in_vreg[i].vreg_name);
+				goto vreg_set_opt_mode_fail;
+			}
+			rc = regulator_enable(in_vreg[i].vreg);
+			if (in_vreg[i].post_on_sleep && need_sleep)
+				usleep_range(in_vreg[i].post_on_sleep * 1000,
+					in_vreg[i].post_on_sleep * 1000);
+			if (rc < 0) {
+				DEV_ERR("%pS->%s: %s enable failed\n",
+					__builtin_return_address(0), __func__,
+					in_vreg[i].vreg_name);
+				goto disable_vreg;
+			}
+		}
+	} else {
+		for (i = num_vreg-1; i >= 0; i--) {
+			if (in_vreg[i].pre_off_sleep)
+				usleep_range(in_vreg[i].pre_off_sleep * 1000,
+					in_vreg[i].pre_off_sleep * 1000);
+			regulator_set_load(in_vreg[i].vreg,
+				in_vreg[i].disable_load);
+			regulator_disable(in_vreg[i].vreg);
+			if (in_vreg[i].post_off_sleep)
+				usleep_range(in_vreg[i].post_off_sleep * 1000,
+					in_vreg[i].post_off_sleep * 1000);
+		}
+	}
+	return rc;
+
+disable_vreg:
+	regulator_set_load(in_vreg[i].vreg, in_vreg[i].disable_load);
+
+vreg_set_opt_mode_fail:
+	for (i--; i >= 0; i--) {
+		if (in_vreg[i].pre_off_sleep)
+			usleep_range(in_vreg[i].pre_off_sleep * 1000,
+				in_vreg[i].pre_off_sleep * 1000);
+		regulator_set_load(in_vreg[i].vreg,

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c line 225

Quoted 10 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +10 -0
+			in_vreg[i].disable_load);
+		regulator_disable(in_vreg[i].vreg);
+		if (in_vreg[i].post_off_sleep)
+			usleep_range(in_vreg[i].post_off_sleep * 1000,
+				in_vreg[i].post_off_sleep * 1000);
+	}
+
+	return rc;
+} /* msm_dss_enable_vreg */
+

Same question here, but with dp_power.

Quoted 17 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +1 -0
+
 void msm_dss_put_clk(struct dss_clk *clk_arry, int num_clk)

{

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.c +0 -0
 	int i;
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +1 -0
index bc07381..524b394 100644
@@ -15,6 +15,7 @@
 
 #include <linux/gpio.h>
 #include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
 #include <linux/types.h>
 
 #define DEV_DBG(fmt, args...)   pr_debug(fmt, ##args)

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h line 29

Quoted 7 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +4 -0
@@ -22,6 +23,39 @@
 #define DEV_WARN(fmt, args...)  pr_warn(fmt, ##args)
 #define DEV_ERR(fmt, args...)   pr_err(fmt, ##args)
 
+struct dss_io_data {
+	u32 len;
+	void __iomem *base;
+};

len isn't used anywhere, so this struct can go away. If the struct goes away, you can really simplify (or eliminate msm_dss_ioremap_byname())

Quoted 12 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +8 -0
+
+/*
+void dss_reg_w(struct dss_io_data *io, u32 offset, u32 value, u32 
 debug);
+u32 dss_reg_r(struct dss_io_data *io, u32 offset, u32 debug);
+void dss_reg_dump(void __iomem *base, u32 len, const char *prefix, 
 u32 debug);
+
+#define DSS_REG_W_ND(io, offset, val)  dss_reg_w(io, offset, val, 
 false)
+#define DSS_REG_W(io, offset, val)     dss_reg_w(io, offset, val, 

true)

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h line 40

Quoted 3 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +3 -0
+#define DSS_REG_R_ND(io, offset)       dss_reg_r(io, offset, false)
+#define DSS_REG_R(io, offset)          dss_reg_r(io, offset, true)
+*/

None of the dss_reg_*/DSS_REG_* functions/macros are used. Please remove.

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h line 44

Quoted 4 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +4 -0
+enum dss_vreg_type {
+	DSS_REG_LDO,
+	DSS_REG_VS,
+};

These are only used in msm_dss_config_vreg(). Please remove.

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h line 50

Quoted 6 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +6 -0
+
+struct dss_vreg {
+	struct regulator *vreg; /* vreg handle */
+	char vreg_name[32];
+	int min_voltage;
+	int max_voltage;

Can't we deduce these from the regulator subsystem with regulator_list_voltage()?

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h line 52

Quoted 2 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +2 -0
+	int enable_load;
+	int disable_load;

These are really a function of the dp device than the regulator.

drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h line 56

Quoted 4 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +4 -0
+	int pre_on_sleep;
+	int post_on_sleep;
+	int pre_off_sleep;
+	int post_off_sleep;

None of these sleep values are set? Also, shouldn't these constraints usually expressed/acted upon in the regulator driver?

Quoted 1 line

+};

So if we can remove all of the extra goop around the regulator, then we can get rid of dss_vreg.

Quoted 27 lines
drivers/gpu/drm/msm/disp/dpu1/dpu_io_util.h +11 -0
+
 struct dss_gpio {
 	unsigned int gpio;
 	unsigned int value;
@@ -42,12 +76,22 @@ struct dss_clk {
 };
 
 struct dss_module_power {
+	unsigned int num_vreg;
+	struct dss_vreg *vreg_config;
 	unsigned int num_gpio;
 	struct dss_gpio *gpio_config;
 	unsigned int num_clk;
 	struct dss_clk *clk_config;
 };
 
+int msm_dss_ioremap_byname(struct platform_device *pdev,
+			   struct dss_io_data *io_data, const char *name);
+void msm_dss_iounmap(struct dss_io_data *io_data);
+
+int msm_dss_config_vreg(struct device *dev, struct dss_vreg *in_vreg,
+			int num_vreg, int config);
+int msm_dss_enable_vreg(struct dss_vreg *in_vreg, int num_vreg,	int 
 enable);
+
 int msm_dss_get_clk(struct device *dev, struct dss_clk *clk_arry, int 
 num_clk);
Quoted 1 line

void msm_dss_put_clk(struct dss_clk *clk_arry, int num_clk);

Why are these msm_dss* functions in dpu_io_util.h?

drivers/gpu/drm/msm/dp/dp_aux.c

Quoted 7 lines

int msm_dss_clk_set_rate(struct dss_clk *clk_arry, int num_clk);

drivers/gpu/drm/msm/dp/dp_aux.c new file +0 -0
new file mode 100644
index 0000000..00b82c2
@@ -0,0 +1,570 @@

/snip

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +0 -0
new file mode 100644
index 0000000..0c300ed

/snip

Quoted 3 lines

I didn't really review the dp_aux.* files as-is. Please convert to using drm_dp_aux and I'll take another look.

Please correct me if I am wrong. Looks like you are suggesting to use most of the drm_dp_aux struct variable instead of what we have defined locally.

Quoted 1,411 lines
Quoted 23 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
new file mode 100644
index 0000000..5818612
@@ -0,0 +1,1188 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights 

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_catalog.c new file +1 -0
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 24

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+#define pr_fmt(fmt)	"[drm-dp] %s: " fmt, __func__
+
+#include <linux/delay.h>
+#include <drm/drm_dp_helper.h>
+
+#include "dp_catalog.h"
+#include "dp_reg.h"
+
+#define DP_GET_MSB(x)	(x >> 8)
+#define DP_GET_LSB(x)	(x & 0xff)

These aren't used anywhere

drivers/gpu/drm/msm/dp/dp_catalog.c line 27

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +3 -0
+
+#define dp_read(offset) readl_relaxed((offset))
+#define dp_write(offset, data) writel_relaxed((data), (offset))

These macros aren't useful. I think you'd be much better having a read_/write_ for the different io types, ie:

static inline u32 dp_read_audio(struct dp_catalog *catalog, u32 offset)

{
        return readl_relaxed(catalog->io->dp_link.base + offset);
}

Then you can remove a ton of boilerplate code below getting base;

drivers/gpu/drm/msm/dp/dp_catalog.c line 29

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+
+#define dp_catalog_get_priv(x) { \

static inline struct dp_catalog_private *dp_catalog_get_priv(...)

{
        ...
}
Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	struct dp_catalog *dp_catalog; \
+	dp_catalog = container_of(x, struct dp_catalog, x); \
+	catalog = container_of(dp_catalog, struct dp_catalog_private, \
+				dp_catalog); \
+}
+
+#define DP_INTERRUPT_STATUS1 \
+	(DP_INTR_AUX_I2C_DONE| \
+	DP_INTR_WRONG_ADDR | DP_INTR_TIMEOUT | \
+	DP_INTR_NACK_DEFER | DP_INTR_WRONG_DATA_CNT | \

drivers/gpu/drm/msm/dp/dp_catalog.c line 49

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	DP_INTR_I2C_NACK | DP_INTR_I2C_DEFER | \
+	DP_INTR_PLL_UNLOCKED | DP_INTR_AUX_ERROR)
+
+#define DP_INTR_MASK1		(DP_INTERRUPT_STATUS1 << 2)
+
+#define DP_INTERRUPT_STATUS2 \
+	(DP_INTR_READY_FOR_VIDEO | DP_INTR_IDLE_PATTERN_SENT | \
+	DP_INTR_FRAME_END | DP_INTR_CRC_UPDATED)
+
+#define DP_INTR_MASK2		(DP_INTERRUPT_STATUS2 << 2)

Can you please rename these to be consistent with each other? DP_INTERRUPT_STATUS2_MASK perhaps?

Quoted 23 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +23 -0
+
+static u8 const vm_pre_emphasis[4][4] = {
+	{0x00, 0x0B, 0x12, 0xFF},       /* pe0, 0 db */
+	{0x00, 0x0A, 0x12, 0xFF},       /* pe1, 3.5 db */
+	{0x00, 0x0C, 0xFF, 0xFF},       /* pe2, 6.0 db */
+	{0xFF, 0xFF, 0xFF, 0xFF}        /* pe3, 9.5 db */
+};
+
+/* voltage swing, 0.2v and 1.0v are not support */
+static u8 const vm_voltage_swing[4][4] = {
+	{0x07, 0x0F, 0x14, 0xFF}, /* sw0, 0.4v  */
+	{0x11, 0x1D, 0x1F, 0xFF}, /* sw1, 0.6 v */
+	{0x18, 0x1F, 0xFF, 0xFF}, /* sw1, 0.8 v */
+	{0xFF, 0xFF, 0xFF, 0xFF}  /* sw1, 1.2 v, optional */
+};
+
+/* audio related catalog functions */
+struct dp_catalog_private {
+	struct device *dev;
+	struct dp_io *io;
+
+	u32 (*audio_map)[DP_AUDIO_SDP_HEADER_MAX];
+	struct dp_catalog dp_catalog;

drivers/gpu/drm/msm/dp/dp_catalog.c line 82

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+};
+
+/* aux related catalog functions */
+static u32 dp_catalog_aux_read_data(struct dp_catalog_aux *aux)
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!aux) {
+		pr_err("invalid input\n");

And another logging type, please remove pr_* and use a DPU_/DRM_/DRM_DEV_ variant.

drivers/gpu/drm/msm/dp/dp_catalog.c line 91

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +9 -0
+		goto end;
+	}
+
+	dp_catalog_get_priv(aux);
+	base = catalog->io->dp_aux.base;
+
+	return dp_read(base + DP_AUX_DATA);
+end:
+	return 0;

... or you could just return directly in the if above and remove the label :) Same comment applies below.

Also, probably shouldn't return 0 in an error case.

Then again, I'm guessing hitting the NULL case is likely impossible, so you can probably remove all of the machinery around checking !aux.

Quoted 77 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +43 -0
+}
+
+static int dp_catalog_aux_write_data(struct dp_catalog_aux *aux)
+{
+	int rc = 0;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!aux) {
+		pr_err("invalid input\n");
+		rc = -EINVAL;
+		goto end;
+	}
+
+	dp_catalog_get_priv(aux);
+	base = catalog->io->dp_aux.base;
+
+	dp_write(base + DP_AUX_DATA, aux->data);
+end:
+	return rc;
+}
+
+static int dp_catalog_aux_write_trans(struct dp_catalog_aux *aux)
+{
+	int rc = 0;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!aux) {
+		pr_err("invalid input\n");
+		rc = -EINVAL;
+		goto end;
+	}
+
+	dp_catalog_get_priv(aux);
+	base = catalog->io->dp_aux.base;
+
+	dp_write(base + DP_AUX_TRANS_CTRL, aux->data);
+end:
+	return rc;
+}
+
+static int dp_catalog_aux_clear_trans(struct dp_catalog_aux *aux, 

bool read)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +33 -0
+{
+	int rc = 0;
+	u32 data = 0;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!aux) {
+		pr_err("invalid input\n");
+		rc = -EINVAL;
+		goto end;
+	}
+
+	dp_catalog_get_priv(aux);
+	base = catalog->io->dp_aux.base;
+
+	if (read) {
+		data = dp_read(base + DP_AUX_TRANS_CTRL);
+		data &= ~BIT(9);
+		dp_write(base + DP_AUX_TRANS_CTRL, data);
+	} else {
+		dp_write(base + DP_AUX_TRANS_CTRL, 0);
+	}
+end:
+	return rc;
+}
+
+static void dp_catalog_aux_reset(struct dp_catalog_aux *aux)
+{
+	u32 aux_ctrl;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!aux) {

drivers/gpu/drm/msm/dp/dp_catalog.c line 177

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(aux);
+	base = catalog->io->dp_aux.base;
+
+	aux_ctrl = dp_read(base + DP_AUX_CTRL);
+
+	aux_ctrl |= BIT(1);

What's BIT(1)? Can you please #define it?

drivers/gpu/drm/msm/dp/dp_catalog.c line 179

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+	dp_write(base + DP_AUX_CTRL, aux_ctrl);
+	usleep_range(1000, 1010); /* h/w recommended delay */

10us diff is right on the line of enough delay to make usleep_range worth it. I'd recommend increasing to 100us to increase the chance of the scheduler being able to batch this wakeup with another.

drivers/gpu/drm/msm/dp/dp_catalog.c line 183

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+
+	aux_ctrl &= ~BIT(1);
+	dp_write(base + DP_AUX_CTRL, aux_ctrl);
+	wmb();

Can you just use writel for these cases instead of using _relaxed and then wmb()? This applies elsewhere too.

Quoted 13 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +3 -0
+}
+
+static void dp_catalog_aux_enable(struct dp_catalog_aux *aux, bool 

enable)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +9 -0
+{
+	u32 aux_ctrl;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!aux) {
+		pr_err("invalid input\n");
+		return;
+	}

drivers/gpu/drm/msm/dp/dp_catalog.c line 205

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+
+	dp_catalog_get_priv(aux);
+	base = catalog->io->dp_aux.base;
+
+	aux_ctrl = dp_read(base + DP_AUX_CTRL);
+
+	if (enable) {
+		dp_write(base + DP_TIMEOUT_COUNT, 0xffff);
+		dp_write(base + DP_AUX_LIMITS, 0xffff);
+		aux_ctrl |= BIT(0);

Please #define BIT(0)

Quoted 35 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +35 -0
+	} else {
+		aux_ctrl &= ~BIT(0);
+	}
+
+	dp_write(base + DP_AUX_CTRL, aux_ctrl);
+}
+
+static void dp_catalog_aux_update_cfg(struct dp_catalog_aux *aux,
+		struct dp_aux_cfg *cfg, enum dp_phy_aux_config_type type)
+{
+	struct dp_catalog_private *catalog;
+	u32 new_index = 0, current_index = 0;
+
+	if (!aux || !cfg || (type >= PHY_AUX_CFG_MAX)) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(aux);
+
+	current_index = cfg[type].current_index;
+	new_index = (current_index + 1) % cfg[type].cfg_cnt;
+	pr_debug("Updating %s from 0x%08x to 0x%08x\n",
+		dp_phy_aux_config_type_to_string(type),
+	cfg[type].lut[current_index], cfg[type].lut[new_index]);
+
+	dp_write(catalog->io->phy_io.base + cfg[type].offset,
+			cfg[type].lut[new_index]);
+	cfg[type].current_index = new_index;
+}
+
+static void dp_catalog_aux_setup(struct dp_catalog_aux *aux,
+		struct dp_aux_cfg *cfg)
+{
+	struct dp_catalog_private *catalog;

drivers/gpu/drm/msm/dp/dp_catalog.c line 250

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	int i = 0;
+
+	if (!aux || !cfg) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(aux);
+
+	dp_write(catalog->io->phy_io.base + DP_PHY_PD_CTL, 0x65);

What's 0x65? Please #define

drivers/gpu/drm/msm/dp/dp_catalog.c line 255

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +5 -0
+	wmb(); /* make sure PD programming happened */
+
+	/* Turn on BIAS current for PHY/PLL */
+	dp_write(catalog->io->dp_pll_io.base +
+		QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x1b);

Same here for 0x1b. I'm going to stop mentioning this, please audit the driver for other instances of hardcoded values (like this and the one at the end of this function) and break them out into meaningful #defines.

Quoted 125 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +11 -0
+
+	/* DP AUX CFG register programming */
+	for (i = 0; i < PHY_AUX_CFG_MAX; i++) {
+		pr_debug("%s: offset=0x%08x, value=0x%08x\n",
+			dp_phy_aux_config_type_to_string(i),
+			cfg[i].offset, cfg[i].lut[cfg[i].current_index]);
+		dp_write(catalog->io->phy_io.base + cfg[i].offset,
+			cfg[i].lut[cfg[i].current_index]);
+	}
+
+	dp_write(catalog->io->phy_io.base + DP_PHY_AUX_INTERRUPT_MASK, 

0x1F);

drivers/gpu/drm/msm/dp/dp_catalog.c new file +3 -0
+}
+
+static void dp_catalog_aux_get_irq(struct dp_catalog_aux *aux, bool 

cmd_busy)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +23 -0
+{
+	u32 ack;
+	struct dp_catalog_private *catalog;
+	void __iomem *ahb_base;
+
+	if (!aux) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(aux);
+	ahb_base = catalog->io->dp_ahb.base;
+
+	aux->isr = dp_read(ahb_base + DP_INTR_STATUS);
+	aux->isr &= ~DP_INTR_MASK1;
+	ack = aux->isr & DP_INTERRUPT_STATUS1;
+	ack <<= 1;
+	ack |= DP_INTR_MASK1;
+	dp_write(ahb_base + DP_INTR_STATUS, ack);
+}
+
+/* controller related catalog functions */
+static void dp_catalog_ctrl_update_transfer_unit(struct 

dp_catalog_ctrl *ctrl)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +18 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_link.base;
+
+	dp_write(base + DP_VALID_BOUNDARY, ctrl->valid_boundary);
+	dp_write(base + DP_TU, ctrl->dp_tu);
+	dp_write(base + DP_VALID_BOUNDARY_2, ctrl->valid_boundary2);
+}
+
+static void dp_catalog_ctrl_state_ctrl(struct dp_catalog_ctrl *ctrl, 

u32 state)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +16 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_link.base;
+
+	dp_write(base + DP_STATE_CTRL, state);
+}
+
+static void dp_catalog_ctrl_config_ctrl(struct dp_catalog_ctrl *ctrl, 

u32 cfg)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +18 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *link_base;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	link_base = catalog->io->dp_link.base;
+
+	pr_debug("DP_CONFIGURATION_CTRL=0x%x\n", cfg);
+
+	dp_write(link_base + DP_CONFIGURATION_CTRL, cfg);
+}
+
+static void dp_catalog_ctrl_lane_mapping(struct dp_catalog_ctrl 

*ctrl)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +16 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_link.base;
+
+	dp_write(base + DP_LOGICAL2PHYSICAL_LANE_MAPPING, 0xe4);
+}
+
+static void dp_catalog_ctrl_mainlink_ctrl(struct dp_catalog_ctrl 

*ctrl,

drivers/gpu/drm/msm/dp/dp_catalog.c new file +13 -0
+						bool enable)
+{
+	u32 mainlink_ctrl;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_link.base;

drivers/gpu/drm/msm/dp/dp_catalog.c line 383

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+
+	if (enable) {
+		dp_write(base + DP_MAINLINK_CTRL, 0x02000000);
+		wmb(); /* make sure mainlink is turned off before reset */
+		dp_write(base + DP_MAINLINK_CTRL, 0x02000002);
+		wmb(); /* make sure mainlink entered reset */
+		dp_write(base + DP_MAINLINK_CTRL, 0x02000000);
+		wmb(); /* make sure mainlink reset done */
+		dp_write(base + DP_MAINLINK_CTRL, 0x02000001);
+		wmb(); /* make sure mainlink turned on */

Same comments here re: readl vs readl_relaxed + wmb

Please #define the bits you're setting.

Quoted 14 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +14 -0
+	} else {
+		mainlink_ctrl = dp_read(base + DP_MAINLINK_CTRL);
+		mainlink_ctrl &= ~BIT(0);
+		dp_write(base + DP_MAINLINK_CTRL, mainlink_ctrl);
+	}
+}
+
+static void dp_catalog_ctrl_config_misc(struct dp_catalog_ctrl *ctrl,
+					u32 cc, u32 tb)
+{
+	u32 misc_val;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 407

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_link.base;
+
+	misc_val = dp_read(base + DP_MISC1_MISC0);
+	misc_val |= cc;

Should you mask this so it doesn't stomp areas it shouldn't?

drivers/gpu/drm/msm/dp/dp_catalog.c line 408

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_catalog.c new file +1 -0
+	misc_val |= (tb << 5);

Parentheses are unnecessary

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+	misc_val |= BIT(0); /* Configure clock to synchronous mode */
+
+	pr_debug("misc settings = 0x%x\n", misc_val);
+	dp_write(base + DP_MISC1_MISC0, misc_val);

drivers/gpu/drm/msm/dp/dp_catalog.c line 422

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+}
+
+static void dp_catalog_ctrl_config_msa(struct dp_catalog_ctrl *ctrl,
+					u32 rate, u32 stream_rate_khz,
+					bool fixed_nvid)
+{
+	u32 pixel_m, pixel_n;
+	u32 mvid, nvid;
+	u64 mvid_calc;
+	u32 const nvid_fixed = 0x8000;

You should pull this out into a #define in drm_dp_helper.h and use the new define in the i915 driver (in a separate patch) as well as here.

Quoted 37 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +37 -0
+	u32 const link_rate_hbr2 = 540000;
+	u32 const link_rate_hbr3 = 810000;
+	struct dp_catalog_private *catalog;
+	void __iomem *base_cc, *base_ctrl;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	if (fixed_nvid) {
+		pr_debug("use fixed NVID=0x%x\n", nvid_fixed);
+		nvid = nvid_fixed;
+
+		pr_debug("link rate=%dkbps, stream_rate_khz=%uKhz",
+			rate, stream_rate_khz);
+
+		/*
+		 * For intermediate results, use 64 bit arithmetic to avoid
+		 * loss of precision.
+		 */
+		mvid_calc = (u64) stream_rate_khz * nvid;
+		mvid_calc = div_u64(mvid_calc, rate);
+
+		/*
+		 * truncate back to 32 bits as this final divided value will
+		 * always be within the range of a 32 bit unsigned int.
+		 */
+		mvid = (u32) mvid_calc;
+	} else {
+		base_cc = catalog->io->dp_cc_io.base;
+
+		pixel_m = dp_read(base_cc + MMSS_DP_PIXEL_M);
+		pixel_n = dp_read(base_cc + MMSS_DP_PIXEL_N);
+		pr_debug("pixel_m=0x%x, pixel_n=0x%x\n", pixel_m, pixel_n);
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 469

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+		mvid = (pixel_m & 0xFFFF) * 5;
+		nvid = (0xFFFF & (~pixel_n)) + (pixel_m & 0xFFFF);
+
+		pr_debug("rate = %d\n", rate);
+
+		if (link_rate_hbr2 == rate)
+			nvid *= 2;
+
+		if (link_rate_hbr3 == rate)
+			nvid *= 3;
                switch (drm_dp_bw_code_to_link_rate(rate)) {
                case DP_LINK_BW_5_4:
                        nvid *= 2;
                        break;
                case DP_LINK_BW_8_1:
                        nvid *= 3;
                        break;
                default:
                        break;
                }

And remove link_rate_hbr* above.

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +16 -0
+	}
+
+	base_ctrl = catalog->io->dp_link.base;
+	pr_debug("mvid=0x%x, nvid=0x%x\n", mvid, nvid);
+	dp_write(base_ctrl + DP_SOFTWARE_MVID, mvid);
+	dp_write(base_ctrl + DP_SOFTWARE_NVID, nvid);
+}
+
+static void dp_catalog_ctrl_set_pattern(struct dp_catalog_ctrl *ctrl,
+					u32 pattern)
+{
+	int bit, cnt = 10;
+	u32 data;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 495

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_link.base;
+
+	bit = 1;
+	bit <<= (pattern - 1);
        bit = BIT(pattern - 1);

drivers/gpu/drm/msm/dp/dp_catalog.c line 500

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +5 -0
+	pr_debug("hw: bit=%d train=%d\n", bit, pattern);
+	dp_write(base + DP_STATE_CTRL, bit);
+
+	bit = 8;
+	bit <<= (pattern - 1);
        bit = BIT(pattern - 1) << 3;

drivers/gpu/drm/msm/dp/dp_catalog.c line 505

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +5 -0
+
+	while (cnt--) {
+		data = dp_read(base + DP_MAINLINK_READY);
+		if (data & bit)
+			break;

Should there be a sleep in here? Also, consider using readx_poll_timeout instead of rolling your own polling.

drivers/gpu/drm/msm/dp/dp_catalog.c line 509

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+	}
+
+	if (cnt == 0)
+		pr_err("set link_train=%d failed\n", pattern);

This function should return an int and report this failure instead of ignoring it.

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +3 -0
+}
+
+static void dp_catalog_ctrl_usb_reset(struct dp_catalog_ctrl *ctrl, 

bool flip)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 526

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+
+	base = catalog->io->usb3_dp_com.base;
+
+	dp_write(base + USB3_DP_COM_RESET_OVRD_CTRL, 0x0a);

Again, all of these magic values need to be pulled out into #defines so we know what the values mean.

drivers/gpu/drm/msm/dp/dp_catalog.c line 530

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+	dp_write(base + USB3_DP_COM_PHY_MODE_CTRL, 0x02);
+	dp_write(base + USB3_DP_COM_SW_RESET, 0x01);
+	/* make sure usb3 com phy software reset is done */
+	wmb();

Same comments here wrt wmb()

drivers/gpu/drm/msm/dp/dp_catalog.c line 535

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +5 -0
+
+	if (!flip) /* CC1 */
+		dp_write(base + USB3_DP_COM_TYPEC_CTRL, 0x02);
+	else /* CC2 */
+		dp_write(base + USB3_DP_COM_TYPEC_CTRL, 0x03);
        u32 val;
        ...
        val = SOME_DEFINE_THAT_MAKES_SENSE;
        if (flip)
                val |= ANOTHER_DEFINE_THAT_MEANS_FLIP;

        dp_io_write(USB3_DP_COM_TYPEC_CTRL, val);
Quoted 24 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +24 -0
+
+	dp_write(base + USB3_DP_COM_SWI_CTRL, 0x00);
+	dp_write(base + USB3_DP_COM_SW_RESET, 0x00);
+	/* make sure the software reset is done */
+	wmb();
+
+	dp_write(base + USB3_DP_COM_POWER_DOWN_CTRL, 0x01);
+	dp_write(base + USB3_DP_COM_RESET_OVRD_CTRL, 0x00);
+	/* make sure phy is brought out of reset */
+	wmb();
+
+}
+
+static void dp_catalog_panel_tpg_cfg(struct dp_catalog_panel *panel,
+	bool enable)
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!panel) {
+		pr_err("invalid input\n");
+		return;
+	}
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 569

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	dp_catalog_get_priv(panel);
+	base = catalog->io->dp_p0.base;
+
+	if (!enable) {
+		dp_write(base + MMSS_DP_TPG_MAIN_CONTROL, 0x0);
+		dp_write(base + MMSS_DP_BIST_ENABLE, 0x0);
+		dp_write(base + MMSS_DP_TIMING_ENGINE_EN, 0x0);
+		wmb(); /* ensure Timing generator is turned off */
+		return;
+	}

There's really no reason to have both the enable + disable path in the same function, they don't share any code (aside from writing a few different values to the same registers). Could you please split this function into a timing_generator_disable and timing_generator_enable?

Quoted 41 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +6 -0
+
+	dp_write(base + MMSS_DP_INTF_CONFIG, 0x0);
+	dp_write(base + MMSS_DP_INTF_HSYNC_CTL, panel->hsync_ctl);
+	dp_write(base + MMSS_DP_INTF_VSYNC_PERIOD_F0, panel->vsync_period *
+			panel->hsync_period);
+	dp_write(base + MMSS_DP_INTF_VSYNC_PULSE_WIDTH_F0, 

panel->v_sync_width *

drivers/gpu/drm/msm/dp/dp_catalog.c new file +6 -0
+			panel->hsync_period);
+	dp_write(base + MMSS_DP_INTF_VSYNC_PERIOD_F1, 0);
+	dp_write(base + MMSS_DP_INTF_VSYNC_PULSE_WIDTH_F1, 0);
+	dp_write(base + MMSS_DP_INTF_DISPLAY_HCTL, panel->display_hctl);
+	dp_write(base + MMSS_DP_INTF_ACTIVE_HCTL, 0);
+	dp_write(base + MMSS_INTF_DISPLAY_V_START_F0, 

panel->display_v_start);

drivers/gpu/drm/msm/dp/dp_catalog.c new file +1 -0
+	dp_write(base + MMSS_DP_INTF_DISPLAY_V_END_F0, 

panel->display_v_end);

drivers/gpu/drm/msm/dp/dp_catalog.c new file +25 -0
+	dp_write(base + MMSS_INTF_DISPLAY_V_START_F1, 0);
+	dp_write(base + MMSS_DP_INTF_DISPLAY_V_END_F1, 0);
+	dp_write(base + MMSS_DP_INTF_ACTIVE_V_START_F0, 0);
+	dp_write(base + MMSS_DP_INTF_ACTIVE_V_END_F0, 0);
+	dp_write(base + MMSS_DP_INTF_ACTIVE_V_START_F1, 0);
+	dp_write(base + MMSS_DP_INTF_ACTIVE_V_END_F1, 0);
+	dp_write(base + MMSS_DP_INTF_POLARITY_CTL, 0);
+	wmb(); /* ensure TPG registers are programmed */
+
+	dp_write(base + MMSS_DP_TPG_MAIN_CONTROL, 0x100);
+	dp_write(base + MMSS_DP_TPG_VIDEO_CONFIG, 0x5);
+	wmb(); /* ensure TPG config is programmed */
+	dp_write(base + MMSS_DP_BIST_ENABLE, 0x1);
+	dp_write(base + MMSS_DP_TIMING_ENGINE_EN, 0x1);
+	wmb(); /* ensure Timing generator is turned on */
+	pr_debug("%s: enabled tpg\n", __func__);
+}
+
+static void dp_catalog_ctrl_reset(struct dp_catalog_ctrl *ctrl)
+{
+	u32 sw_reset;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!ctrl) {

drivers/gpu/drm/msm/dp/dp_catalog.c line 617

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_ahb.base;
+
+	sw_reset = dp_read(base + DP_SW_RESET);
+
+	sw_reset |= BIT(0);

Should be a #define

drivers/gpu/drm/msm/dp/dp_catalog.c line 619

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+	dp_write(base + DP_SW_RESET, sw_reset);
+	usleep_range(1000, 1010); /* h/w recommended delay */

Same comment here regarding the 10us range

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +6 -0
+
+	sw_reset &= ~BIT(0);
+	dp_write(base + DP_SW_RESET, sw_reset);
+}
+
+static bool dp_catalog_ctrl_mainlink_ready(struct dp_catalog_ctrl 

*ctrl)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +11 -0
+{
+	u32 data;
+	int cnt = 10;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		goto end;
+	}
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 646

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_link.base;
+
+	while (--cnt) {
+		/* DP_MAINLINK_READY */
+		data = dp_read(base + DP_MAINLINK_READY);
+		if (data & BIT(0))
+			return true;
+
+		usleep_range(1000, 1010); /* 1ms wait before next reg read */

Same comment here regarding using readx_poll_timeout wrapped in a helper, also 10us comment.

Quoted 41 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +30 -0
+	}
+	pr_err("mainlink not ready\n");
+end:
+	return false;
+}
+
+static void dp_catalog_ctrl_enable_irq(struct dp_catalog_ctrl *ctrl,
+						bool enable)
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_ahb.base;
+
+	if (enable) {
+		dp_write(base + DP_INTR_STATUS, DP_INTR_MASK1);
+		dp_write(base + DP_INTR_STATUS2, DP_INTR_MASK2);
+	} else {
+		dp_write(base + DP_INTR_STATUS, 0x00);
+		dp_write(base + DP_INTR_STATUS2, 0x00);
+	}
+}
+
+static void dp_catalog_ctrl_hpd_config(struct dp_catalog_ctrl *ctrl, 

bool en)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);

drivers/gpu/drm/msm/dp/dp_catalog.c line 696

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	base = catalog->io->dp_aux.base;
+
+	if (en) {
+		u32 reftimer = dp_read(base + DP_DP_HPD_REFTIMER);
+
+		dp_write(base + DP_DP_HPD_INT_ACK, 0xF);
+		dp_write(base + DP_DP_HPD_INT_MASK, 0xF);
+
+		/* Enabling REFTIMER */
+		reftimer |= BIT(16);

You don't use this anywhere?

drivers/gpu/drm/msm/dp/dp_catalog.c line 701

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +5 -0
+		dp_write(base + DP_DP_HPD_REFTIMER, 0xF);
+		/* Enable HPD */
+		dp_write(base + DP_DP_HPD_CTRL, 0x1);
+	} else {
+		/*Disable HPD */

Space after *

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +5 -0
+		dp_write(base + DP_DP_HPD_CTRL, 0x0);
+	}
+}
+
+static void dp_catalog_ctrl_get_interrupt(struct dp_catalog_ctrl 

*ctrl)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+{
+	u32 ack = 0;
+	struct dp_catalog_private *catalog;
+	void __iomem *base;

drivers/gpu/drm/msm/dp/dp_catalog.c line 720

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_ahb.base;
+
+	ctrl->isr = dp_read(base + DP_INTR_STATUS2);

This value should just get returned instead of being stored.

drivers/gpu/drm/msm/dp/dp_catalog.c line 721

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_catalog.c new file +1 -0
+	ctrl->isr &= ~DP_INTR_MASK2;

Unmasking the interrupts should not be returned from this function, it should be part of the ack below.

drivers/gpu/drm/msm/dp/dp_catalog.c line 722

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_catalog.c new file +1 -0
+	ack = ctrl->isr & DP_INTERRUPT_STATUS2;

And this does the above unmask already, so you can just turf it.

drivers/gpu/drm/msm/dp/dp_catalog.c line 724

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+	ack <<= 1;
+	ack |= DP_INTR_MASK2;

Instead of rolling the ack code yourself, I'd prefer what you did with _MASK, where you define DP_INTERRUPT_STATUS2_ACK above and just do a bitwise-OR to add the acks here. Without the register map in front of me, it would take a while to figure out what you're trying to accomplish.

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +7 -0
+	dp_write(base + DP_INTR_STATUS2, ack);
+}
+
+static void dp_catalog_ctrl_phy_reset(struct dp_catalog_ctrl *ctrl)
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;

drivers/gpu/drm/msm/dp/dp_catalog.c line 741

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+	base = catalog->io->dp_ahb.base;
+
+	dp_write(base + DP_PHY_CTRL, 0x5); /* bit 0 & 2 */

The comment doesn't help here, please #define these bits

drivers/gpu/drm/msm/dp/dp_catalog.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_catalog.c new file +1 -0
+	usleep_range(1000, 1010); /* h/w recommended delay */

Same comment re: delay range

drivers/gpu/drm/msm/dp/dp_catalog.c line 744

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+	dp_write(base + DP_PHY_CTRL, 0x0);
+	wmb(); /* make sure PHY reset done */

Same comment re: wmb

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +3 -0
+}
+
+static void dp_catalog_ctrl_phy_lane_cfg(struct dp_catalog_ctrl 

*ctrl,

drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+		bool flipped, u8 ln_cnt)
+{
+	u32 info = 0x0;
+	struct dp_catalog_private *catalog;

drivers/gpu/drm/msm/dp/dp_catalog.c line 761

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	u8 orientation = BIT(!!flipped);
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+
+	info |= (ln_cnt & 0x0F);

Remove the | and just make this an assignment (and you can remove the initialization to 0 above)

drivers/gpu/drm/msm/dp/dp_catalog.c line 773

Quoted 13 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +7 -0
+	info |= ((orientation & 0x0F) << 4);
+	pr_debug("Shared Info = 0x%x\n", info);
+
+	dp_write(catalog->io->phy_io.base + DP_PHY_SPARE0, info);
+}
+
+static void dp_catalog_ctrl_update_vx_px(struct dp_catalog_ctrl 

*ctrl,

drivers/gpu/drm/msm/dp/dp_catalog.c new file +5 -0
+		u8 v_level, u8 p_level)
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base0, *base1;
+	u8 value0, value1;

Can we please pick better names for these?!

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +6 -0
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 789

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	dp_catalog_get_priv(ctrl);
+	base0 = catalog->io->ln_tx0_io.base;
+	base1 = catalog->io->ln_tx1_io.base;
+
+	pr_debug("hw: v=%d p=%d\n", v_level, p_level);
+
+	value0 = vm_voltage_swing[v_level][p_level];
+	value1 = vm_pre_emphasis[v_level][p_level];
+
+	/* program default setting first */

Why do you need to do this?

drivers/gpu/drm/msm/dp/dp_catalog.c line 793

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+	dp_write(base0 + TXn_TX_DRV_LVL, 0x2A);
+	dp_write(base1 + TXn_TX_DRV_LVL, 0x2A);
+	dp_write(base0 + TXn_TX_EMP_POST1_LVL, 0x20);
+	dp_write(base1 + TXn_TX_EMP_POST1_LVL, 0x20);

#define these magic values

drivers/gpu/drm/msm/dp/dp_catalog.c line 797

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+
+	/* Enable MUX to use Cursor values from these registers */
+	value0 |= BIT(5);
+	value1 |= BIT(5);

#define these bits please

drivers/gpu/drm/msm/dp/dp_catalog.c line 800

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +3 -0
+
+	/* Configure host and panel only if both values are allowed */
+	if (value0 != 0xFF && value1 != 0xFF) {

You can check this a lot earlier in the function.

drivers/gpu/drm/msm/dp/dp_catalog.c line 810

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+		dp_write(base0 + TXn_TX_DRV_LVL, value0);
+		dp_write(base1 + TXn_TX_DRV_LVL, value0);
+		dp_write(base0 + TXn_TX_EMP_POST1_LVL, value1);
+		dp_write(base1 + TXn_TX_EMP_POST1_LVL, value1);
+
+		pr_debug("hw: vx_value=0x%x px_value=0x%x\n",
+			value0, value1);
+	} else {
+		pr_err("invalid vx (0x%x=0x%x), px (0x%x=0x%x\n",
+			v_level, value0, p_level, value1);

Seems like returning an error in this case would be useful

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+	}
+}
+
+static void dp_catalog_ctrl_send_phy_pattern(struct dp_catalog_ctrl 

*ctrl,

drivers/gpu/drm/msm/dp/dp_catalog.c new file +6 -0
+			u32 pattern)
+{
+	struct dp_catalog_private *catalog;
+	u32 value = 0x0;
+	void __iomem *base = NULL;
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 830

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	dp_catalog_get_priv(ctrl);
+
+	base = catalog->io->dp_link.base;
+
+	dp_write(base + DP_STATE_CTRL, 0x0);

Do you really need to do this?

Quoted 22 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +22 -0
+
+	switch (pattern) {
+	case DP_TEST_PHY_PATTERN_D10_2_NO_SCRAMBLING:
+		dp_write(base + DP_STATE_CTRL, 0x1);
+		break;
+	case DP_TEST_PHY_PATTERN_SYMBOL_ERR_MEASUREMENT_CNT:
+		value &= ~(1 << 16);
+		dp_write(base + DP_HBR2_COMPLIANCE_SCRAMBLER_RESET, value);
+		value |= 0xFC;
+		dp_write(base + DP_HBR2_COMPLIANCE_SCRAMBLER_RESET, value);
+		dp_write(base + DP_MAINLINK_LEVELS, 0x2);
+		dp_write(base + DP_STATE_CTRL, 0x10);
+		break;
+	case DP_TEST_PHY_PATTERN_PRBS7:
+		dp_write(base + DP_STATE_CTRL, 0x20);
+		break;
+	case DP_TEST_PHY_PATTERN_80_BIT_CUSTOM_PATTERN:
+		dp_write(base + DP_STATE_CTRL, 0x40);
+		/* 00111110000011111000001111100000 */
+		dp_write(base + DP_TEST_80BIT_CUSTOM_PATTERN_REG0, 0x3E0F83E0);
+		/* 00001111100000111110000011111000 */
+		dp_write(base + DP_TEST_80BIT_CUSTOM_PATTERN_REG1, 0x0F83E0F8);

drivers/gpu/drm/msm/dp/dp_catalog.c line 862

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+		/* 1111100000111110 */
+		dp_write(base + DP_TEST_80BIT_CUSTOM_PATTERN_REG2, 0x0000F83E);
+		break;
+	case DP_TEST_PHY_PATTERN_HBR2_CTS_EYE_PATTERN:
+		value = BIT(16);
+		dp_write(base + DP_HBR2_COMPLIANCE_SCRAMBLER_RESET, value);
+		value |= 0xFC;
+		dp_write(base + DP_HBR2_COMPLIANCE_SCRAMBLER_RESET, value);
+		dp_write(base + DP_MAINLINK_LEVELS, 0x2);
+		dp_write(base + DP_STATE_CTRL, 0x10);

This code is the exact same as the case for DP_TEST_PHY_PATTERN_SYMBOL_ERR_MEASUREMENT_CNT, aside from BIT(16) vs ~BIT(16). Can you please combine these cases
and share code?

drivers/gpu/drm/msm/dp/dp_catalog.c line 867

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +5 -0
+		break;
+	default:
+		pr_debug("No valid test pattern requested: 0x%x\n", pattern);
+		return;
+	}

All of the DP_STATE_CTRL values should be #defined, and you can move the write down here instead of duplicating it everywhere (with DP_TEST_PHY_PATTERN_80_BIT_CUSTOM_PATTERN writing a 0).

Quoted 42 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +6 -0
+
+	/* Make sure the test pattern is programmed in the hardware */
+	wmb();
+}
+
+static u32 dp_catalog_ctrl_read_phy_pattern(struct dp_catalog_ctrl 

*ctrl)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +18 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base = NULL;
+
+	if (!ctrl) {
+		pr_err("invalid input\n");
+		return 0;
+	}
+
+	dp_catalog_get_priv(ctrl);
+
+	base = catalog->io->dp_link.base;
+
+	return dp_read(base + DP_MAINLINK_READY);
+}
+
+/* panel related catalog functions */
+static int dp_catalog_panel_timing_cfg(struct dp_catalog_panel 

*panel)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +15 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+
+	if (!panel) {
+		pr_err("invalid input\n");
+		goto end;
+	}
+
+	dp_catalog_get_priv(panel);
+	base = catalog->io->dp_link.base;
+
+	dp_write(base + DP_TOTAL_HOR_VER, panel->total);
+	dp_write(base + DP_START_HOR_VER_FROM_SYNC, panel->sync_start);
+	dp_write(base + DP_HSYNC_VSYNC_WIDTH_POLARITY, 

panel->width_blanking);

drivers/gpu/drm/msm/dp/dp_catalog.c line 908

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+	dp_write(base + DP_ACTIVE_HOR_VER, panel->dp_active);
+end:

useless label, but it'll probably go away when you strip out all of the unnecessary NULL checks from the driver.

Quoted 30 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +30 -0
+	return 0;
+}
+
+static void dp_catalog_audio_init(struct dp_catalog_audio *audio)
+{
+	struct dp_catalog_private *catalog;
+	static u32 sdp_map[][DP_AUDIO_SDP_HEADER_MAX] = {
+		{
+			MMSS_DP_AUDIO_STREAM_0,
+			MMSS_DP_AUDIO_STREAM_1,
+			MMSS_DP_AUDIO_STREAM_1,
+		},
+		{
+			MMSS_DP_AUDIO_TIMESTAMP_0,
+			MMSS_DP_AUDIO_TIMESTAMP_1,
+			MMSS_DP_AUDIO_TIMESTAMP_1,
+		},
+		{
+			MMSS_DP_AUDIO_INFOFRAME_0,
+			MMSS_DP_AUDIO_INFOFRAME_1,
+			MMSS_DP_AUDIO_INFOFRAME_1,
+		},
+		{
+			MMSS_DP_AUDIO_COPYMANAGEMENT_0,
+			MMSS_DP_AUDIO_COPYMANAGEMENT_1,
+			MMSS_DP_AUDIO_COPYMANAGEMENT_1,
+		},
+		{
+			MMSS_DP_AUDIO_ISRC_0,
+			MMSS_DP_AUDIO_ISRC_1,

drivers/gpu/drm/msm/dp/dp_catalog.c line 948

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+			MMSS_DP_AUDIO_ISRC_1,
+		},
+	};
+
+	if (!audio)
+		return;
+
+	dp_catalog_get_priv(audio);
+
+	catalog->audio_map = sdp_map;

Hmm, this is a bit spooky, we're storing a (non-const) pointer to a static stack variable. Fortunately this looks like it'll be easy to fix since this data is only accessed in this file. So move the map into a static const global and reference it directly when needed (and drop audio_map).

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +3 -0
+}
+
+static void dp_catalog_audio_config_sdp(struct dp_catalog_audio 

*audio)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +14 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+	u32 sdp_cfg = 0;
+	u32 sdp_cfg2 = 0;
+
+	if (!audio)
+		return;
+
+	dp_catalog_get_priv(audio);
+	base = catalog->io->dp_link.base;
+
+	sdp_cfg = dp_read(base + MMSS_DP_SDP_CFG);
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 975

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	/* AUDIO_TIMESTAMP_SDP_EN */
+	sdp_cfg |= BIT(1);
+	/* AUDIO_STREAM_SDP_EN */
+	sdp_cfg |= BIT(2);
+	/* AUDIO_COPY_MANAGEMENT_SDP_EN */
+	sdp_cfg |= BIT(5);
+	/* AUDIO_ISRC_SDP_EN  */
+	sdp_cfg |= BIT(6);
+	/* AUDIO_INFOFRAME_SDP_EN  */
+	sdp_cfg |= BIT(20);

#define the values and combine the assignment

drivers/gpu/drm/msm/dp/dp_catalog.c line 984

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +9 -0
+
+	pr_debug("sdp_cfg = 0x%x\n", sdp_cfg);
+	dp_write(base + MMSS_DP_SDP_CFG, sdp_cfg);
+
+	sdp_cfg2 = dp_read(base + MMSS_DP_SDP_CFG2);
+	/* IFRM_REGSRC -> Do not use reg values */
+	sdp_cfg2 &= ~BIT(0);
+	/* AUDIO_STREAM_HB3_REGSRC-> Do not use reg values */
+	sdp_cfg2 &= ~BIT(1);

The reset value of this register is 0x4, so how can the bits in position 0/1 get flipped? We shouldn't need this code, afaict.

If we do, the same comments regarding #define and combination as above.

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +6 -0
+
+	pr_debug("sdp_cfg2 = 0x%x\n", sdp_cfg2);
+	dp_write(base + MMSS_DP_SDP_CFG2, sdp_cfg2);
+}
+
+static void dp_catalog_audio_get_header(struct dp_catalog_audio 

*audio)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +9 -0
+{
+	struct dp_catalog_private *catalog;
+	u32 (*sdp_map)[DP_AUDIO_SDP_HEADER_MAX];
+	void __iomem *base;
+	enum dp_catalog_audio_sdp_type sdp;
+	enum dp_catalog_audio_header_type header;
+
+	if (!audio)
+		return;

drivers/gpu/drm/msm/dp/dp_catalog.c line 1009

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+
+	dp_catalog_get_priv(audio);
+
+	base    = catalog->io->dp_link.base;
+	sdp_map = catalog->audio_map;
+	sdp     = audio->sdp_type;
+	header  = audio->sdp_header;
+
+	audio->data = dp_read(base + sdp_map[sdp][header]);
+}

This function is unused, please remove.

Quoted 14 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+
+static void dp_catalog_audio_set_header(struct dp_catalog_audio 

*audio)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +11 -0
+{
+	struct dp_catalog_private *catalog;
+	u32 (*sdp_map)[DP_AUDIO_SDP_HEADER_MAX];
+	void __iomem *base;
+	enum dp_catalog_audio_sdp_type sdp;
+	enum dp_catalog_audio_header_type header;
+	u32 data;
+
+	if (!audio)
+		return;
+

drivers/gpu/drm/msm/dp/dp_catalog.c line 1032

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	dp_catalog_get_priv(audio);
+
+	base    = catalog->io->dp_link.base;
+	sdp_map = catalog->audio_map;
+	sdp     = audio->sdp_type;
+	header  = audio->sdp_header;
+	data    = audio->data;
+
+	dp_write(base + sdp_map[sdp][header], data);
+}

This function is unused, please remove.

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+
+static void dp_catalog_audio_config_acr(struct dp_catalog_audio 

*audio)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +6 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+	u32 acr_ctrl, select;
+
+	dp_catalog_get_priv(audio);

drivers/gpu/drm/msm/dp/dp_catalog.c line 1050

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+
+	select = audio->data;
+	base   = catalog->io->dp_link.base;
+
+	acr_ctrl = select << 4 | BIT(31) | BIT(8) | BIT(14);
+
+	pr_debug("select = 0x%x, acr_ctrl = 0x%x\n", select, acr_ctrl);
+
+	dp_write(base + MMSS_DP_AUDIO_ACR_CTRL, acr_ctrl);
+}

This function is unused, please remove.

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+
+static void dp_catalog_audio_safe_to_exit_level(struct 

dp_catalog_audio *audio)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +9 -0
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+	u32 mainlink_levels, safe_to_exit_level;
+
+	dp_catalog_get_priv(audio);
+
+	base   = catalog->io->dp_link.base;
+	safe_to_exit_level = audio->data;

drivers/gpu/drm/msm/dp/dp_catalog.c line 1071

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+
+	mainlink_levels = dp_read(base + DP_MAINLINK_LEVELS);
+	mainlink_levels &= 0xFE0;
+	mainlink_levels |= safe_to_exit_level;
+
+	pr_debug("mainlink_level = 0x%x, safe_to_exit_level = 0x%x\n",
+			mainlink_levels, safe_to_exit_level);
+
+	dp_write(base + DP_MAINLINK_LEVELS, mainlink_levels);
+}

This function is unused, please remove.

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +16 -0
+
+static void dp_catalog_audio_enable(struct dp_catalog_audio *audio)
+{
+	struct dp_catalog_private *catalog;
+	void __iomem *base;
+	bool enable;
+	u32 audio_ctrl;
+
+	dp_catalog_get_priv(audio);
+
+	base   = catalog->io->dp_link.base;
+	enable = !!audio->data;
+
+	audio_ctrl = dp_read(base + MMSS_DP_AUDIO_CFG);
+
+	if (enable)

drivers/gpu/drm/msm/dp/dp_catalog.c line 1097

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+		audio_ctrl |= BIT(0);
+	else
+		audio_ctrl &= ~BIT(0);
+
+	pr_debug("dp_audio_cfg = 0x%x\n", audio_ctrl);
+	dp_write(base + MMSS_DP_AUDIO_CFG, audio_ctrl);
+
+	/* make sure audio engine is disabled */
+	wmb();
+}

This function is unused, please remove.

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +2 -0
+
+struct dp_catalog *dp_catalog_get(struct device *dev, struct dp_io 

*io)

drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+{
+	int rc = 0;
+	struct dp_catalog *dp_catalog;
+	struct dp_catalog_private *catalog;

drivers/gpu/drm/msm/dp/dp_catalog.c line 1113

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +10 -0
+	struct dp_catalog_aux aux = {
+		.read_data     = dp_catalog_aux_read_data,
+		.write_data    = dp_catalog_aux_write_data,
+		.write_trans   = dp_catalog_aux_write_trans,
+		.clear_trans   = dp_catalog_aux_clear_trans,
+		.reset         = dp_catalog_aux_reset,
+		.update_aux_cfg = dp_catalog_aux_update_cfg,
+		.enable        = dp_catalog_aux_enable,
+		.setup         = dp_catalog_aux_setup,
+		.get_irq       = dp_catalog_aux_get_irq,

Out of these, it seems like write_trans, clear_trans, update_aux_cfg, setup and get_irq are all unused. Please remove them.

Please also check the other functions to ensure they're used.

Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +17 -0
+	};
+	struct dp_catalog_ctrl ctrl = {
+		.state_ctrl     = dp_catalog_ctrl_state_ctrl,
+		.config_ctrl    = dp_catalog_ctrl_config_ctrl,
+		.lane_mapping   = dp_catalog_ctrl_lane_mapping,
+		.mainlink_ctrl  = dp_catalog_ctrl_mainlink_ctrl,
+		.config_misc    = dp_catalog_ctrl_config_misc,
+		.config_msa     = dp_catalog_ctrl_config_msa,
+		.set_pattern    = dp_catalog_ctrl_set_pattern,
+		.reset          = dp_catalog_ctrl_reset,
+		.usb_reset      = dp_catalog_ctrl_usb_reset,
+		.mainlink_ready = dp_catalog_ctrl_mainlink_ready,
+		.enable_irq     = dp_catalog_ctrl_enable_irq,
+		.hpd_config     = dp_catalog_ctrl_hpd_config,
+		.phy_reset      = dp_catalog_ctrl_phy_reset,
+		.phy_lane_cfg   = dp_catalog_ctrl_phy_lane_cfg,
+		.update_vx_px   = dp_catalog_ctrl_update_vx_px,
Quoted 8 lines

drivers/gpu/drm/msm/dp/dp_catalog.c line 1134

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +4 -0
+		.get_interrupt  = dp_catalog_ctrl_get_interrupt,
+		.update_transfer_unit = dp_catalog_ctrl_update_transfer_unit,
+		.send_phy_pattern    = dp_catalog_ctrl_send_phy_pattern,
+		.read_phy_pattern = dp_catalog_ctrl_read_phy_pattern,

So, what's the benefit of adding the catalog abstractions? Do you ever have multiple/alternate implementations of a catalog? It doesn't seem like it. You should just remove all of the catalog overhead and call the functions directly.

We use catalog abstractions for two different reasons:
1. To support multiple hardware since these implementations are hardware specific.
2. To virtualize DP hardware.

Our internal hardware already supports multiple chips. We want to keep these abstractions to make the code consistent between upstream and internal implementation.

Quoted 660 lines
Quoted 165 lines
drivers/gpu/drm/msm/dp/dp_catalog.c new file +54 -0
+	};
+	struct dp_catalog_audio audio = {
+		.init       = dp_catalog_audio_init,
+		.config_acr = dp_catalog_audio_config_acr,
+		.enable     = dp_catalog_audio_enable,
+		.config_sdp = dp_catalog_audio_config_sdp,
+		.set_header = dp_catalog_audio_set_header,
+		.get_header = dp_catalog_audio_get_header,
+		.safe_to_exit_level = dp_catalog_audio_safe_to_exit_level,
+	};
+	struct dp_catalog_panel panel = {
+		.timing_cfg = dp_catalog_panel_timing_cfg,
+		.tpg_config = dp_catalog_panel_tpg_cfg,
+	};
+
+	if (!io) {
+		pr_err("invalid input\n");
+		rc = -EINVAL;
+		goto error;
+	}
+
+	catalog  = devm_kzalloc(dev, sizeof(*catalog), GFP_KERNEL);
+	if (!catalog) {
+		rc = -ENOMEM;
+		goto error;
+	}
+
+	catalog->dev = dev;
+	catalog->io = io;
+
+	dp_catalog = &catalog->dp_catalog;
+
+	dp_catalog->aux   = aux;
+	dp_catalog->ctrl  = ctrl;
+	dp_catalog->audio = audio;
+	dp_catalog->panel = panel;
+
+	return dp_catalog;
+error:
+	return ERR_PTR(rc);
+}
+
+void dp_catalog_put(struct dp_catalog *dp_catalog)
+{
+	struct dp_catalog_private *catalog;
+
+	if (!dp_catalog)
+		return;
+
+	catalog = container_of(dp_catalog, struct dp_catalog_private,
+				dp_catalog);
+
+	devm_kfree(catalog->dev, catalog);
+}
drivers/gpu/drm/msm/dp/dp_catalog.h new file +2 -0
new file mode 100644
index 0000000..58951df
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights 

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_catalog.h new file +89 -0
+
+#ifndef _DP_CATALOG_H_
+#define _DP_CATALOG_H_
+
+#include "dp_parser.h"
+
+/* interrupts */
+#define DP_INTR_HPD		BIT(0)
+#define DP_INTR_AUX_I2C_DONE	BIT(3)
+#define DP_INTR_WRONG_ADDR	BIT(6)
+#define DP_INTR_TIMEOUT		BIT(9)
+#define DP_INTR_NACK_DEFER	BIT(12)
+#define DP_INTR_WRONG_DATA_CNT	BIT(15)
+#define DP_INTR_I2C_NACK	BIT(18)
+#define DP_INTR_I2C_DEFER	BIT(21)
+#define DP_INTR_PLL_UNLOCKED	BIT(24)
+#define DP_INTR_AUX_ERROR	BIT(27)
+
+#define DP_INTR_READY_FOR_VIDEO		BIT(0)
+#define DP_INTR_IDLE_PATTERN_SENT	BIT(3)
+#define DP_INTR_FRAME_END		BIT(6)
+#define DP_INTR_CRC_UPDATED		BIT(9)
+
+struct dp_catalog_aux {
+	u32 data;
+	u32 isr;
+
+	u32 (*read_data)(struct dp_catalog_aux *aux);
+	int (*write_data)(struct dp_catalog_aux *aux);
+	int (*write_trans)(struct dp_catalog_aux *aux);
+	int (*clear_trans)(struct dp_catalog_aux *aux, bool read);
+	void (*reset)(struct dp_catalog_aux *aux);
+	void (*enable)(struct dp_catalog_aux *aux, bool enable);
+	void (*update_aux_cfg)(struct dp_catalog_aux *aux,
+		struct dp_aux_cfg *cfg, enum dp_phy_aux_config_type type);
+	void (*setup)(struct dp_catalog_aux *aux,
+			struct dp_aux_cfg *aux_cfg);
+	void (*get_irq)(struct dp_catalog_aux *aux, bool cmd_busy);
+};
+
+struct dp_catalog_ctrl {
+	u32 dp_tu;
+	u32 valid_boundary;
+	u32 valid_boundary2;
+	u32 isr;
+
+	void (*state_ctrl)(struct dp_catalog_ctrl *ctrl, u32 state);
+	void (*config_ctrl)(struct dp_catalog_ctrl *ctrl, u32 config);
+	void (*lane_mapping)(struct dp_catalog_ctrl *ctrl);
+	void (*mainlink_ctrl)(struct dp_catalog_ctrl *ctrl, bool enable);
+	void (*config_misc)(struct dp_catalog_ctrl *ctrl, u32 cc, u32 tb);
+	void (*config_msa)(struct dp_catalog_ctrl *ctrl, u32 rate,
+				u32 stream_rate_khz, bool fixed_nvid);
+	void (*set_pattern)(struct dp_catalog_ctrl *ctrl, u32 pattern);
+	void (*reset)(struct dp_catalog_ctrl *ctrl);
+	void (*usb_reset)(struct dp_catalog_ctrl *ctrl, bool flip);
+	bool (*mainlink_ready)(struct dp_catalog_ctrl *ctrl);
+	void (*enable_irq)(struct dp_catalog_ctrl *ctrl, bool enable);
+	void (*hpd_config)(struct dp_catalog_ctrl *ctrl, bool enable);
+	void (*phy_reset)(struct dp_catalog_ctrl *ctrl);
+	void (*phy_lane_cfg)(struct dp_catalog_ctrl *ctrl, bool flipped,
+				u8 lane_cnt);
+	void (*update_vx_px)(struct dp_catalog_ctrl *ctrl, u8 v_level,
+				u8 p_level);
+	void (*get_interrupt)(struct dp_catalog_ctrl *ctrl);
+	void (*update_transfer_unit)(struct dp_catalog_ctrl *ctrl);
+	void (*send_phy_pattern)(struct dp_catalog_ctrl *ctrl,
+			u32 pattern);
+	u32 (*read_phy_pattern)(struct dp_catalog_ctrl *ctrl);
+};
+
+enum dp_catalog_audio_sdp_type {
+	DP_AUDIO_SDP_STREAM,
+	DP_AUDIO_SDP_TIMESTAMP,
+	DP_AUDIO_SDP_INFOFRAME,
+	DP_AUDIO_SDP_COPYMANAGEMENT,
+	DP_AUDIO_SDP_ISRC,
+	DP_AUDIO_SDP_MAX,
+};
+
+enum dp_catalog_audio_header_type {
+	DP_AUDIO_SDP_HEADER_1,
+	DP_AUDIO_SDP_HEADER_2,
+	DP_AUDIO_SDP_HEADER_3,
+	DP_AUDIO_SDP_HEADER_MAX,
+};
+
+struct dp_catalog_audio {
+	enum dp_catalog_audio_sdp_type sdp_type;

drivers/gpu/drm/msm/dp/dp_catalog.h line 112

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.h new file +10 -0
+	enum dp_catalog_audio_header_type sdp_header;
+	u32 data;
+
+	void (*init)(struct dp_catalog_audio *audio);
+	void (*enable)(struct dp_catalog_audio *audio);
+	void (*config_acr)(struct dp_catalog_audio *audio);
+	void (*config_sdp)(struct dp_catalog_audio *audio);
+	void (*set_header)(struct dp_catalog_audio *audio);
+	void (*get_header)(struct dp_catalog_audio *audio);
+	void (*safe_to_exit_level)(struct dp_catalog_audio *audio);

None of these are called? So get rid of this entire structure, the functions that aren't called, and the audio enums above.

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_catalog.h new file +6 -0
+};
+
+struct dp_catalog_panel {
+	u32 total;
+	u32 sync_start;
+	u32 width_blanking;

drivers/gpu/drm/msm/dp/dp_catalog.h line 128

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.h new file +10 -0
+	u32 dp_active;
+
+	/* TPG */
+	u32 hsync_period;
+	u32 vsync_period;
+	u32 display_v_start;
+	u32 display_v_end;
+	u32 v_sync_width;
+	u32 hsync_ctl;
+	u32 display_hctl;

All of this information is already available from drm core, so it can go.

drivers/gpu/drm/msm/dp/dp_catalog.h line 131

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_catalog.h new file +3 -0
+
+	int (*timing_cfg)(struct dp_catalog_panel *panel);
+	void (*tpg_config)(struct dp_catalog_panel *panel, bool enable);

As suggested elsewhere, these functions should just be called directly wherever applicable. So we can get rid of this struct.

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_catalog.h new file +10 -0
+};
+
+struct dp_catalog {
+	struct dp_catalog_aux aux;
+	struct dp_catalog_ctrl ctrl;
+	struct dp_catalog_audio audio;
+	struct dp_catalog_panel panel;
+};
+
+struct dp_catalog *dp_catalog_get(struct device *dev, struct dp_io 
Quoted 2 lines

*io);
+void dp_catalog_put(struct dp_catalog *catalog);

As mentioned above, all of this should be removed. We can just call the functions directly.

Quoted 37 lines
drivers/gpu/drm/msm/dp/dp_catalog.h new file +2 -0
+
+#endif /* _DP_CATALOG_H_ */
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
new file mode 100644
index 0000000..08a52f5
@@ -0,0 +1,1475 @@
+/*
+ * Copyright (c) 2012-2018, The Linux Foundation. All rights 

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +14 -0
+
+#define pr_fmt(fmt)	"[drm-dp] %s: " fmt, __func__
+
+#include <linux/types.h>
+#include <linux/completion.h>
+#include <linux/delay.h>
+
+#include "dp_ctrl.h"
+
+#define DP_KHZ_TO_HZ 1000
+
+#define DP_CTRL_INTR_READY_FOR_VIDEO     BIT(0)
+#define DP_CTRL_INTR_IDLE_PATTERN_SENT  BIT(3)
+

drivers/gpu/drm/msm/dp/dp_ctrl.c line 37

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+/* dp state ctrl */
+#define ST_TRAIN_PATTERN_1		BIT(0)
+#define ST_TRAIN_PATTERN_2		BIT(1)
+#define ST_TRAIN_PATTERN_3		BIT(2)
+#define ST_TRAIN_PATTERN_4		BIT(3)
+#define ST_SYMBOL_ERR_RATE_MEASUREMENT	BIT(4)
+#define ST_PRBS7			BIT(5)
+#define ST_CUSTOM_80_BIT_PATTERN	BIT(6)
+#define ST_SEND_VIDEO			BIT(7)
+#define ST_PUSH_IDLE			BIT(8)

I'd like to see these defined with DP_STATE_CTRL (and s/ST/DP_STATE_CTRL/).

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +8 -0
+
+#define MR_LINK_TRAINING1  0x8
+#define MR_LINK_SYMBOL_ERM 0x80
+#define MR_LINK_PRBS7 0x100
+#define MR_LINK_CUSTOM80 0x200
+
+struct dp_vc_tu_mapping_table {
+	u32 vic;

drivers/gpu/drm/msm/dp/dp_ctrl.c line 55

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	u8 lanes;
+	u8 lrate; /* DP_LINK_RATE -> 162(6), 270(10), 540(20), 810 (30) */
+	u8 bpp;
+	u8 valid_boundary_link;
+	u16 delay_start_link;
+	bool boundary_moderation_en;
+	u8 valid_lower_boundary_link;
+	u8 upper_boundary_count;
+	u8 lower_boundary_count;
+	u8 tu_size_minus1;

Please check this struct for unused members, there are at least a couple.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 67

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +12 -0
+};
+
+struct dp_ctrl_private {
+	struct dp_ctrl dp_ctrl;
+
+	struct device *dev;
+	struct dp_aux *aux;
+	struct dp_panel *panel;
+	struct dp_link *link;
+	struct dp_power *power;
+	struct dp_parser *parser;
+	struct dp_catalog_ctrl *catalog;

Once you remove struct dp_ctrl and call the functions directly, I suspect you can get rid of all of these.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 76

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +9 -0
+
+	struct completion idle_comp;
+	struct completion video_comp;
+
+	bool orientation;
+	atomic_t aborted;
+
+	u32 pixel_rate;
+	u32 vic;

'u32 vic' shows up in 3 places in this driver, but there is not one use of any vic :) Please remove from here and elsewhere.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 85

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +9 -0
+};
+
+enum notification_status {
+	NOTIFY_UNKNOWN,
+	NOTIFY_CONNECT,
+	NOTIFY_DISCONNECT,
+	NOTIFY_CONNECT_IRQ_HPD,
+	NOTIFY_DISCONNECT_IRQ_HPD,
+};

Unused, please remove.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 97

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +12 -0
+
+static void dp_ctrl_idle_patterns_sent(struct dp_ctrl_private *ctrl)
+{
+	pr_debug("idle_patterns_sent\n");
+	complete(&ctrl->idle_comp);
+}
+
+static void dp_ctrl_video_ready(struct dp_ctrl_private *ctrl)
+{
+	pr_debug("dp_video_ready\n");
+	complete(&ctrl->video_comp);
+}

These functions don't provide value, please remove and just call complete() directly.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 108

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +11 -0
+
+static void dp_ctrl_abort(struct dp_ctrl *dp_ctrl)
+{
+	struct dp_ctrl_private *ctrl;
+
+	if (!dp_ctrl) {
+		pr_err("Invalid input data\n");
+		return;
+	}
+
+	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);

JFYI, this is sprinkled everywhere, would be a good candidate for an inline function. Since dp_ctrl can be removed, it's kind of a moot point now.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 115

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+
+	atomic_set(&ctrl->aborted, 1);
+}
+
+static void dp_ctrl_state_ctrl(struct dp_ctrl_private *ctrl, u32 

state)

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+{
+	ctrl->catalog->state_ctrl(ctrl->catalog, state);

No need to wrap this in a function

drivers/gpu/drm/msm/dp/dp_ctrl.c line 120

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+}
+
+static void dp_ctrl_push_idle(struct dp_ctrl *dp_ctrl)
+{
+	int const idle_pattern_completion_timeout_ms = 3 * HZ / 100;

This should be #define'd outside of the functioninstead. Also, why the '_ms_' suffix? The units are in jiffies.

I think something like

#define IDLE_PATTERN_COMPLETION_TIMEOUT_JIFFIES (30 * HZ / 1000) /* 30 ms */

would be clearer.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 130

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	struct dp_ctrl_private *ctrl;
+
+	if (!dp_ctrl) {
+		pr_err("Invalid input data\n");
+		return;
+	}
+
+	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
+
+	reinit_completion(&ctrl->idle_comp);

This function is called from a bunch of places, and idle_comp is also used in a bunch of places. Are you certain this is thread-safe if you have concurrent callers or users of idle_comp?

drivers/gpu/drm/msm/dp/dp_ctrl.c line 135

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+	dp_ctrl_state_ctrl(ctrl, ST_PUSH_IDLE);
+
+	if (!wait_for_completion_timeout(&ctrl->idle_comp,
+			idle_pattern_completion_timeout_ms))
+		pr_warn("PUSH_IDLE pattern timedout\n");

Return an error?

drivers/gpu/drm/msm/dp/dp_ctrl.c line 145

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+
+	pr_debug("mainlink off done\n");
+}
+
+static void dp_ctrl_config_ctrl(struct dp_ctrl_private *ctrl)
+{
+	u32 config = 0, tbd;
+	u8 *dpcd = ctrl->panel->dpcd;
+
+	config |= (2 << 13); /* Default-> LSCLK DIV: 1/4 LCLK  */

#define value

drivers/gpu/drm/msm/dp/dp_ctrl.c line 146

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +1 -0
+	config |= (0 << 11); /* RGB */

This is a no-op, can be removed

drivers/gpu/drm/msm/dp/dp_ctrl.c line 155

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+
+	/* Scrambler reset enable */
+	if (dpcd[DP_EDP_CONFIGURATION_CAP] & 

DP_ALTERNATE_SCRAMBLER_RESET_CAP)

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+		config |= (1 << 10);
+
+	tbd = ctrl->link->get_test_bits_depth(ctrl->link,
+			ctrl->panel->pinfo.bpp);
+
+	if (tbd == DP_TEST_BIT_DEPTH_UNKNOWN)

Should we print a debug message here?

drivers/gpu/drm/msm/dp/dp_ctrl.c line 161

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+		tbd = DP_TEST_BIT_DEPTH_8;
+
+	config |= tbd << 8;
+
+	/* Num of Lanes */
+	config |= ((ctrl->link->link_params.lane_count - 1) << 4);

These shift values should be #defined

drivers/gpu/drm/msm/dp/dp_ctrl.c line 164

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+
+	if (drm_dp_enhanced_frame_cap(dpcd))
+		config |= 0x40;

#define 0x40

drivers/gpu/drm/msm/dp/dp_ctrl.c line 168

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+
+	config |= 0x04; /* progressive video */
+
+	config |= 0x03;	/* sycn clock & static Mvid */

And these, plus s/sycn/sync/

Quoted 15 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+
+	ctrl->catalog->config_ctrl(ctrl->catalog, config);
+}
+
+/**
+ * dp_ctrl_configure_source_params() - configures DP transmitter 

source params
+ * @ctrl: Display Port Driver data
+ *
+ * Configures the DP transmitter source params including details such as lane
+ * configuration, output format and sink/panel timing information.
+ */
+static void dp_ctrl_configure_source_params(struct dp_ctrl_private *ctrl)

drivers/gpu/drm/msm/dp/dp_ctrl.c line 185

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+{
+	u32 cc, tb;
+
+	ctrl->catalog->lane_mapping(ctrl->catalog);
+	ctrl->catalog->mainlink_ctrl(ctrl->catalog, true);

We go through ctrl->catalog->callback_hook to call a function that is specific to ctrl and only called in this file. It could easily just be a static function without having to go through 2 structs and a callback hook.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 192

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +7 -0
+
+	dp_ctrl_config_ctrl(ctrl);
+
+	tb = ctrl->link->get_test_bits_depth(ctrl->link,
+		ctrl->panel->pinfo.bpp);
+	cc = ctrl->link->get_colorimetry_config(ctrl->link);
+	ctrl->catalog->config_misc(ctrl->catalog, cc, tb);

Same comments with these hooks, they're only called from this file. I'll stop harping on this, but could we please remove the layers of indirection and just embed and call functions as appropriate?

Quoted 22 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +22 -0
+	ctrl->panel->timing_cfg(ctrl->panel);
+}
+
+static void dp_ctrl_get_extra_req_bytes(u64 result_valid,
+					int valid_bdary_link,
+					u64 value1, u64 value2,
+					bool *negative, u64 *result,
+					u64 compare)
+{
+	*negative = false;
+	if (result_valid >= compare) {
+		if (valid_bdary_link
+				>= compare)
+			*result = value1 + value2;
+		else {
+			if (value1 < value2)
+				*negative = true;
+			*result = (value1 >= value2) ?
+				(value1 - value2) : (value2 - value1);
+		}
+	} else {
+		if (valid_bdary_link

drivers/gpu/drm/msm/dp/dp_ctrl.c line 224

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+				>= compare) {
+			if (value1 >= value2)
+				*negative = true;
+			*result = (value1 >= value2) ?
+				(value1 - value2) : (value2 - value1);
+		} else {
+			*result = value1 + value2;
+			*negative = true;
+		}
+	}

I think this can be simplified to the following, it's still super hard to follow, but I'm not sure if that can be helped.

        bool result_bigger = result_valid >= compare;
        bool valid_bdary_bigger = valid_bdary_link >= compare;

	if (result_bigger && valid_bdary_bigger ||
            !result_bigger && !valid_bdary_bigger) {
                *negative = !valid_bdary_bigger;
                return value1 + value2;
        }

        *negative = (result_bigger && !valid_bdary_bigger && value1 < 
value2) ||
                    (!result_bigger && valid_bdary_bigger && value1 >= 
value2);
        return max(value1, value2) - min(value1, value2);

I don't know. The more I stare at this the less convinced I become that it's better. So take it or leave it. At the very least you can collapse the

if (cond)

        *negative = true;

to

*negative = cond;

and do the max(v,v) - min(v,v) trick to shave off some of the conditionals in the original.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 231

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +7 -0
+}
+
+static u64 roundup_u64(u64 x, u64 y)
+{
+	x += (y - 1);
+	return (div64_ul(x, y) * y);
+}

Please replace all usage with DIV_ROUND_UP_ULL

drivers/gpu/drm/msm/dp/dp_ctrl.c line 239

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +8 -0
+
+static u64 rounddown_u64(u64 x, u64 y)
+{
+	u64 rem;
+
+	div64_u64_rem(x, y, &rem);
+	return (x - rem);
+}

Please replace all usage with DIV_ROUND_DOWN_ULL

Quoted 58 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +58 -0
+
+static void dp_ctrl_calc_tu_parameters(struct dp_ctrl_private *ctrl,
+				       struct dp_vc_tu_mapping_table *tu_table)
+{
+	u32 multiplier = 1000000;
+	u64 pclk, lclk;
+	u8 bpp, ln_cnt;
+	int run_idx = 0;
+	u32 lwidth, h_blank;
+	u32 fifo_empty = 0;
+	u32 ratio_scale = 1001;
+	u64 temp, ratio, original_ratio;
+	u64 temp2, reminder;
+	u64 temp3, temp4, result = 0;
+
+	u64 err = multiplier;
+	u64 n_err = 0, n_n_err = 0;
+	bool n_err_neg, nn_err_neg;
+	u8 hblank_margin = 16;
+
+	u8 tu_size, tu_size_desired = 0, tu_size_minus1;
+	int valid_boundary_link;
+	u64 resulting_valid;
+	u64 total_valid;
+	u64 effective_valid;
+	u64 effective_valid_recorded;
+	int n_tus;
+	int n_tus_per_lane;
+	int paired_tus;
+	int remainder_tus;
+	int remainder_tus_upper, remainder_tus_lower;
+	int extra_bytes;
+	int filler_size;
+	int delay_start_link;
+	int boundary_moderation_en = 0;
+	int upper_bdry_cnt = 0;
+	int lower_bdry_cnt = 0;
+	int i_upper_bdry_cnt = 0;
+	int i_lower_bdry_cnt = 0;
+	int valid_lower_boundary_link = 0;
+	int even_distribution_bf = 0;
+	int even_distribution_legacy = 0;
+	int even_distribution = 0;
+	int min_hblank = 0;
+	int extra_pclk_cycles;
+	u8 extra_pclk_cycle_delay = 4;
+	int extra_pclk_cycles_in_link_clk;
+	u64 ratio_by_tu;
+	u64 average_valid2;
+	u64 extra_buffer_margin;
+	int new_valid_boundary_link;
+
+	u64 resulting_valid_tmp;
+	u64 ratio_by_tu_tmp;
+	int n_tus_tmp;
+	int extra_pclk_cycles_tmp;
+	int extra_pclk_cycles_in_lclk_tmp;
+	int extra_req_bytes_new_tmp;

drivers/gpu/drm/msm/dp/dp_ctrl.c line 307

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	int filler_size_tmp;
+	int lower_filler_size_tmp;
+	int delay_start_link_tmp;
+	int min_hblank_tmp = 0;
+	bool extra_req_bytes_is_neg = false;
+	struct dp_panel_info *pinfo = &ctrl->panel->pinfo;
+
+	u8 dp_brute_force = 1;
+	u64 brute_force_threshold = 10;
+	u64 diff_abs;

76 stack vars and ~450 lines must be a new record somewhere :)

Quoted 2 lines

I'm going to skip reviewing this function and let you split/simplify/reduce it. Please just make it more readable (comments, docs, helper functions, etc).

Yes, will try to split this function as modular as possible.
JFYI, this function is IP/hardware specific implementation. It might not be possible to provide lot of comments to make is understandable.

Quoted 3,155 lines
Quoted 408 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +58 -0
+
+	ln_cnt =  ctrl->link->link_params.lane_count;
+
+	bpp = pinfo->bpp;
+	lwidth = pinfo->h_active;
+	h_blank = pinfo->h_back_porch + pinfo->h_front_porch +
+				pinfo->h_sync_width;
+	pclk = pinfo->pixel_clk_khz * 1000;
+
+	boundary_moderation_en = 0;
+	upper_bdry_cnt = 0;
+	lower_bdry_cnt = 0;
+	i_upper_bdry_cnt = 0;
+	i_lower_bdry_cnt = 0;
+	valid_lower_boundary_link = 0;
+	even_distribution_bf = 0;
+	even_distribution_legacy = 0;
+	even_distribution = 0;
+	min_hblank = 0;
+
+	lclk = drm_dp_bw_code_to_link_rate(
+		ctrl->link->link_params.bw_code) * DP_KHZ_TO_HZ;
+
+	pr_debug("pclk=%lld, active_width=%d, h_blank=%d\n",
+						pclk, lwidth, h_blank);
+	pr_debug("lclk = %lld, ln_cnt = %d\n", lclk, ln_cnt);
+	ratio = div64_u64_rem(pclk * bpp * multiplier,
+				8 * ln_cnt * lclk, &reminder);
+	ratio = div64_u64((pclk * bpp * multiplier), (8 * ln_cnt * lclk));
+	original_ratio = ratio;
+
+	extra_buffer_margin = roundup_u64(div64_u64(extra_pclk_cycle_delay
+				* lclk * multiplier, pclk), multiplier);
+	extra_buffer_margin = div64_u64(extra_buffer_margin, multiplier);
+
+	/* To deal with cases where lines are not distributable */
+	if (((lwidth % ln_cnt) != 0) && ratio < multiplier) {
+		ratio = ratio * ratio_scale;
+		ratio = ratio < (1000 * multiplier)
+				? ratio : (1000 * multiplier);
+	}
+	pr_debug("ratio = %lld\n", ratio);
+
+	for (tu_size = 32; tu_size <= 64; tu_size++) {
+		temp = ratio * tu_size;
+		temp2 = ((temp / multiplier) + 1) * multiplier;
+		n_err = roundup_u64(temp, multiplier) - temp;
+
+		if (n_err < err) {
+			err = n_err;
+			tu_size_desired = tu_size;
+		}
+	}
+	pr_debug("Info: tu_size_desired = %d\n", tu_size_desired);
+
+	tu_size_minus1 = tu_size_desired - 1;
+
+	valid_boundary_link = roundup_u64(ratio * tu_size_desired, 

multiplier);

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +15 -0
+	valid_boundary_link /= multiplier;
+	n_tus = rounddown((lwidth * bpp * multiplier)
+			/ (8 * valid_boundary_link), multiplier) / multiplier;
+	even_distribution_legacy = n_tus % ln_cnt == 0 ? 1 : 0;
+	pr_debug("Info: n_symbol_per_tu=%d, number_of_tus=%d\n",
+					valid_boundary_link, n_tus);
+
+	extra_bytes = roundup_u64((n_tus + 1)
+			* ((valid_boundary_link * multiplier)
+			- (original_ratio * tu_size_desired)), multiplier);
+	extra_bytes /= multiplier;
+	extra_pclk_cycles = roundup(extra_bytes * 8 * multiplier / bpp,
+			multiplier);
+	extra_pclk_cycles /= multiplier;
+	extra_pclk_cycles_in_link_clk = 

roundup_u64(div64_u64(extra_pclk_cycles

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +256 -0
+				* lclk * multiplier, pclk), multiplier);
+	extra_pclk_cycles_in_link_clk /= multiplier;
+	filler_size = roundup_u64((tu_size_desired - valid_boundary_link)
+						* multiplier, multiplier);
+	filler_size /= multiplier;
+	ratio_by_tu = div64_u64(ratio * tu_size_desired, multiplier);
+
+	pr_debug("extra_pclk_cycles_in_link_clk=%d, extra_bytes=%d\n",
+				extra_pclk_cycles_in_link_clk, extra_bytes);
+	pr_debug("extra_pclk_cycles_in_link_clk=%d\n",
+				extra_pclk_cycles_in_link_clk);
+	pr_debug("filler_size=%d, extra_buffer_margin=%lld\n",
+				filler_size, extra_buffer_margin);
+
+	delay_start_link = ((extra_bytes > extra_pclk_cycles_in_link_clk)
+			? extra_bytes
+			: extra_pclk_cycles_in_link_clk)
+				+ filler_size + extra_buffer_margin;
+	resulting_valid = valid_boundary_link;
+	pr_debug("Info: delay_start_link=%d, filler_size=%d\n",
+				delay_start_link, filler_size);
+	pr_debug("valid_boundary_link=%d ratio_by_tu=%lld\n",
+				valid_boundary_link, ratio_by_tu);
+
+	diff_abs = (resulting_valid >= ratio_by_tu)
+				? (resulting_valid - ratio_by_tu)
+				: (ratio_by_tu - resulting_valid);
+
+	if (err != 0 && ((diff_abs > brute_force_threshold)
+			|| (even_distribution_legacy == 0)
+			|| (dp_brute_force == 1))) {
+		err = multiplier;
+		for (tu_size = 32; tu_size <= 64; tu_size++) {
+			for (i_upper_bdry_cnt = 1; i_upper_bdry_cnt <= 15;
+						i_upper_bdry_cnt++) {
+				for (i_lower_bdry_cnt = 1;
+					i_lower_bdry_cnt <= 15;
+					i_lower_bdry_cnt++) {
+					new_valid_boundary_link =
+						roundup_u64(ratio
+						* tu_size, multiplier);
+					average_valid2 = (i_upper_bdry_cnt
+						* new_valid_boundary_link
+						+ i_lower_bdry_cnt
+						* (new_valid_boundary_link
+							- multiplier))
+						/ (i_upper_bdry_cnt
+							+ i_lower_bdry_cnt);
+					n_tus = rounddown_u64(div64_u64(lwidth
+						* multiplier * multiplier
+						* (bpp / 8), average_valid2),
+							multiplier);
+					n_tus /= multiplier;
+					n_tus_per_lane
+						= rounddown(n_tus
+							* multiplier
+							/ ln_cnt, multiplier);
+					n_tus_per_lane /= multiplier;
+					paired_tus =
+						rounddown((n_tus_per_lane)
+							* multiplier
+							/ (i_upper_bdry_cnt
+							+ i_lower_bdry_cnt),
+							multiplier);
+					paired_tus /= multiplier;
+					remainder_tus = n_tus_per_lane
+							- paired_tus
+						* (i_upper_bdry_cnt
+							+ i_lower_bdry_cnt);
+					if ((remainder_tus
+						- i_upper_bdry_cnt) > 0) {
+						remainder_tus_upper
+							= i_upper_bdry_cnt;
+						remainder_tus_lower =
+							remainder_tus
+							- i_upper_bdry_cnt;
+					} else {
+						remainder_tus_upper
+							= remainder_tus;
+						remainder_tus_lower = 0;
+					}
+					total_valid = paired_tus
+						* (i_upper_bdry_cnt
+						* new_valid_boundary_link
+							+ i_lower_bdry_cnt
+						* (new_valid_boundary_link
+							- multiplier))
+						+ (remainder_tus_upper
+						* new_valid_boundary_link)
+						+ (remainder_tus_lower
+						* (new_valid_boundary_link
+							- multiplier));
+					n_err_neg = nn_err_neg = false;
+					effective_valid
+						= div_u64(total_valid,
+							n_tus_per_lane);
+					n_n_err = (effective_valid
+							>= (ratio * tu_size))
+						? (effective_valid
+							- (ratio * tu_size))
+						: ((ratio * tu_size)
+							- effective_valid);
+					if (effective_valid < (ratio * tu_size))
+						nn_err_neg = true;
+					n_err = (average_valid2
+						>= (ratio * tu_size))
+						? (average_valid2
+							- (ratio * tu_size))
+						: ((ratio * tu_size)
+							- average_valid2);
+					if (average_valid2 < (ratio * tu_size))
+						n_err_neg = true;
+					even_distribution =
+						n_tus % ln_cnt == 0 ? 1 : 0;
+					diff_abs =
+						resulting_valid >= ratio_by_tu
+						? (resulting_valid
+							- ratio_by_tu)
+						: (ratio_by_tu
+							- resulting_valid);
+
+					resulting_valid_tmp = div64_u64(
+						(i_upper_bdry_cnt
+						* new_valid_boundary_link
+						+ i_lower_bdry_cnt
+						* (new_valid_boundary_link
+							- multiplier)),
+						(i_upper_bdry_cnt
+							+ i_lower_bdry_cnt));
+					ratio_by_tu_tmp =
+						original_ratio * tu_size;
+					ratio_by_tu_tmp /= multiplier;
+					n_tus_tmp = rounddown_u64(
+						div64_u64(lwidth
+						* multiplier * multiplier
+						* bpp / 8,
+						resulting_valid_tmp),
+						multiplier);
+					n_tus_tmp /= multiplier;
+
+					temp3 = (resulting_valid_tmp
+						>= (original_ratio * tu_size))
+						? (resulting_valid_tmp
+						- original_ratio * tu_size)
+						: (original_ratio * tu_size)
+						- resulting_valid_tmp;
+					temp3 = (n_tus_tmp + 1) * temp3;
+					temp4 = (new_valid_boundary_link
+						>= (original_ratio * tu_size))
+						? (new_valid_boundary_link
+							- original_ratio
+							* tu_size)
+						: (original_ratio * tu_size)
+						- new_valid_boundary_link;
+					temp4 = (i_upper_bdry_cnt
+							* ln_cnt * temp4);
+
+					temp3 = roundup_u64(temp3, multiplier);
+					temp4 = roundup_u64(temp4, multiplier);
+					dp_ctrl_get_extra_req_bytes
+						(resulting_valid_tmp,
+						new_valid_boundary_link,
+						temp3, temp4,
+						&extra_req_bytes_is_neg,
+						&result,
+						(original_ratio * tu_size));
+					extra_req_bytes_new_tmp
+						= div64_ul(result, multiplier);
+					if ((extra_req_bytes_is_neg)
+						&& (extra_req_bytes_new_tmp
+							> 1))
+						extra_req_bytes_new_tmp
+						= extra_req_bytes_new_tmp - 1;
+					if (extra_req_bytes_new_tmp == 0)
+						extra_req_bytes_new_tmp = 1;
+					extra_pclk_cycles_tmp =
+						(u64)(extra_req_bytes_new_tmp
+						      * 8 * multiplier) / bpp;
+					extra_pclk_cycles_tmp /= multiplier;
+
+					if (extra_pclk_cycles_tmp <= 0)
+						extra_pclk_cycles_tmp = 1;
+					extra_pclk_cycles_in_lclk_tmp =
+						roundup_u64(div64_u64(
+							extra_pclk_cycles_tmp
+							* lclk * multiplier,
+							pclk), multiplier);
+					extra_pclk_cycles_in_lclk_tmp
+						/= multiplier;
+					filler_size_tmp = roundup_u64(
+						(tu_size * multiplier *
+						new_valid_boundary_link),
+						multiplier);
+					filler_size_tmp /= multiplier;
+					lower_filler_size_tmp =
+						filler_size_tmp + 1;
+					if (extra_req_bytes_is_neg)
+						temp3 = (extra_req_bytes_new_tmp
+						> extra_pclk_cycles_in_lclk_tmp
+						? extra_pclk_cycles_in_lclk_tmp
+						: extra_req_bytes_new_tmp);
+					else
+						temp3 = (extra_req_bytes_new_tmp
+						> extra_pclk_cycles_in_lclk_tmp
+						? extra_req_bytes_new_tmp :
+						extra_pclk_cycles_in_lclk_tmp);
+
+					temp4 = lower_filler_size_tmp
+						+ extra_buffer_margin;
+					if (extra_req_bytes_is_neg)
+						delay_start_link_tmp
+							= (temp3 >= temp4)
+							? (temp3 - temp4)
+							: (temp4 - temp3);
+					else
+						delay_start_link_tmp
+							= temp3 + temp4;
+
+					min_hblank_tmp = (int)div64_u64(
+						roundup_u64(
+						div64_u64(delay_start_link_tmp
+						* pclk * multiplier, lclk),
+						multiplier), multiplier)
+						+ hblank_margin;
+
+					if (((even_distribution == 1)
+						|| ((even_distribution_bf == 0)
+						&& (even_distribution_legacy
+								== 0)))
+						&& !n_err_neg && !nn_err_neg
+						&& n_n_err < err
+						&& (n_n_err < diff_abs
+						|| (dp_brute_force == 1))
+						&& (new_valid_boundary_link
+									- 1) > 0
+						&& (h_blank >=
+							(u32)min_hblank_tmp)) {
+						upper_bdry_cnt =
+							i_upper_bdry_cnt;
+						lower_bdry_cnt =
+							i_lower_bdry_cnt;
+						err = n_n_err;
+						boundary_moderation_en = 1;
+						tu_size_desired = tu_size;
+						valid_boundary_link =
+							new_valid_boundary_link;
+						effective_valid_recorded
+							= effective_valid;
+						delay_start_link
+							= delay_start_link_tmp;
+						filler_size = filler_size_tmp;
+						min_hblank = min_hblank_tmp;
+						n_tus = n_tus_tmp;
+						even_distribution_bf = 1;
+
+						pr_debug("upper_bdry_cnt=%d, lower_boundary_cnt=%d, err=%lld, 

tu_size_desired=%d, valid_boundary_link=%d, effective_valid=%lld\n",

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +31 -0
+							upper_bdry_cnt,
+							lower_bdry_cnt, err,
+							tu_size_desired,
+							valid_boundary_link,
+							effective_valid);
+					}
+				}
+			}
+		}
+
+		if (boundary_moderation_en == 1) {
+			resulting_valid = (u64)(upper_bdry_cnt
+					*valid_boundary_link + lower_bdry_cnt
+					* (valid_boundary_link - 1))
+					/ (upper_bdry_cnt + lower_bdry_cnt);
+			ratio_by_tu = original_ratio * tu_size_desired;
+			valid_lower_boundary_link =
+				(valid_boundary_link / multiplier) - 1;
+
+			tu_size_minus1 = tu_size_desired - 1;
+			even_distribution_bf = 1;
+			valid_boundary_link /= multiplier;
+			pr_debug("Info: Boundary_moderation enabled\n");
+		}
+	}
+
+	min_hblank = ((int) roundup_u64(div64_u64(delay_start_link * pclk
+			* multiplier, lclk), multiplier))
+			/ multiplier + hblank_margin;
+	if (h_blank < (u32)min_hblank) {
+		pr_debug(" WARNING: run_idx=%d Programmed h_blank %d is smaller 

than the min_hblank %d supported.\n",

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +11 -0
+					run_idx, h_blank, min_hblank);
+	}
+
+	if (fifo_empty)	{
+		tu_size_minus1 = 31;
+		valid_boundary_link = 32;
+		delay_start_link = 0;
+		boundary_moderation_en = 0;
+	}
+
+	pr_debug("tu_size_minus1=%d valid_boundary_link=%d 

delay_start_link=%d boundary_moderation_en=%d\n upper_boundary_cnt=%d lower_boundary_cnt=%d valid_lower_boundary_link=%d min_hblank=%d\n",

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +31 -0
+		tu_size_minus1, valid_boundary_link, delay_start_link,
+		boundary_moderation_en, upper_bdry_cnt, lower_bdry_cnt,
+		valid_lower_boundary_link, min_hblank);
+
+	tu_table->valid_boundary_link = valid_boundary_link;
+	tu_table->delay_start_link = delay_start_link;
+	tu_table->boundary_moderation_en = boundary_moderation_en;
+	tu_table->valid_lower_boundary_link = valid_lower_boundary_link;
+	tu_table->upper_boundary_count = upper_bdry_cnt;
+	tu_table->lower_boundary_count = lower_bdry_cnt;
+	tu_table->tu_size_minus1 = tu_size_minus1;
+}
+
+static void dp_ctrl_setup_tr_unit(struct dp_ctrl_private *ctrl)
+{
+	u32 dp_tu = 0x0;
+	u32 valid_boundary = 0x0;
+	u32 valid_boundary2 = 0x0;
+	struct dp_vc_tu_mapping_table tu_calc_table;
+
+	dp_ctrl_calc_tu_parameters(ctrl, &tu_calc_table);
+
+	dp_tu |= tu_calc_table.tu_size_minus1;
+	valid_boundary |= tu_calc_table.valid_boundary_link;
+	valid_boundary |= (tu_calc_table.delay_start_link << 16);
+
+	valid_boundary2 |= (tu_calc_table.valid_lower_boundary_link << 1);
+	valid_boundary2 |= (tu_calc_table.upper_boundary_count << 16);
+	valid_boundary2 |= (tu_calc_table.lower_boundary_count << 20);
+
+	if (tu_calc_table.boundary_moderation_en)

drivers/gpu/drm/msm/dp/dp_ctrl.c line 719

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+		valid_boundary2 |= BIT(0);
+
+	pr_debug("dp_tu=0x%x, valid_boundary=0x%x, valid_boundary2=0x%x\n",
+			dp_tu, valid_boundary, valid_boundary2);
+
+	ctrl->catalog->dp_tu = dp_tu;
+	ctrl->catalog->valid_boundary = valid_boundary;
+	ctrl->catalog->valid_boundary2 = valid_boundary2;
+
+	ctrl->catalog->update_transfer_unit(ctrl->catalog);

Again here, if you just call the function directly, you can avoid the callback. If you add function arguments, you can avoid having to store dp_tu/valid_boundary/
valid_boundary2 entirely.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 726

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +7 -0
+}
+
+static int dp_ctrl_wait4video_ready(struct dp_ctrl_private *ctrl)
+{
+	int ret = 0;
+
+	ret = wait_for_completion_timeout(&ctrl->video_comp, HZ / 2);

Break out the timeout into a #define

drivers/gpu/drm/msm/dp/dp_ctrl.c line 732

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+	if (ret <= 0) {
+		pr_err("Link Train timedout\n");
+		ret = -EINVAL;
+	}
+
+	return ret;

You're not checking the return value at the callsite.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 736

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+}
+
+static int dp_ctrl_update_sink_vx_px(struct dp_ctrl_private *ctrl,
+				     u32 voltage_level, u32 pre_emphasis_level)

I don't think this needs to be a function, just move it all into dp_ctrl_update_vx_px.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 745

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +9 -0
+{
+	int i;
+	u8 buf[4];
+	u32 max_level_reached = 0;
+
+	if (voltage_level == DP_LINK_VOLTAGE_MAX) {
+		pr_debug("max. voltage swing level reached %d\n",
+				voltage_level);
+		max_level_reached |= BIT(2);

DP_TRAIN_MAX_SWING_REACHED

drivers/gpu/drm/msm/dp/dp_ctrl.c line 751

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+	}
+
+	if (pre_emphasis_level == DP_LINK_PRE_EMPHASIS_MAX) {
+		pr_debug("max. pre-emphasis level reached %d\n",
+				pre_emphasis_level);
+		max_level_reached  |= BIT(5);

DP_TRAIN_MAX_PRE_EMPHASIS_REACHED

drivers/gpu/drm/msm/dp/dp_ctrl.c line 754

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+	}
+
+	pre_emphasis_level <<= 3;

This is DP_TRAIN_PRE_EMPHASIS_SHIFT, but I'm guessing you aren't using the DP_TRAIN_PRE_EMPH_LEVEL_* values when you set p_level. So the right way to fix this is to use those #defines and get rid of this shift.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 756

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+
+	for (i = 0; i < 4; i++)

You shouldn't assume 4 lanes here, use drm_dp_link->num_lanes

drivers/gpu/drm/msm/dp/dp_ctrl.c line 760

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+		buf[i] = voltage_level | pre_emphasis_level | max_level_reached;
+
+	pr_debug("sink: p|v=0x%x\n", voltage_level | pre_emphasis_level);
+	return drm_dp_dpcd_write(ctrl->aux->drm_aux, 0x103, buf, 4);

s/0x103/DP_TRAINING_LANE0_SET/ and s/4/drm_dp_link->num_lanes/

Also, this will return number of bytes transmitted, not (0 || -errno).

drivers/gpu/drm/msm/dp/dp_ctrl.c line 771

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +11 -0
+}
+
+static void dp_ctrl_update_vx_px(struct dp_ctrl_private *ctrl)
+{
+	struct dp_link *link = ctrl->link;
+
+	ctrl->catalog->update_vx_px(ctrl->catalog,
+		link->phy_params.v_level, link->phy_params.p_level);
+
+	dp_ctrl_update_sink_vx_px(ctrl, link->phy_params.v_level,
+		link->phy_params.p_level);

Fortunately (or unfortunately), the return value isn't checked. So please check the return value.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 777

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+}
+
+static void dp_ctrl_train_pattern_set(struct dp_ctrl_private *ctrl,
+		u8 pattern)
+{
+	u8 buf[4];

Why 4?

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+
+	pr_debug("sink: pattern=%x\n", pattern);
+
+	buf[0] = pattern;
+	drm_dp_dpcd_write(ctrl->aux->drm_aux, DP_TRAINING_PATTERN_SET, buf, 

1);

Check the return value of this and alll drm_dp_dpcd_(read|write) calls.

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+}
+
+static int dp_ctrl_read_link_status(struct dp_ctrl_private *ctrl,
+				    u8 *link_status)
+{
+	int ret = 0, len;

drivers/gpu/drm/msm/dp/dp_ctrl.c line 798

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	u32 const offset = DP_LANE_ALIGN_STATUS_UPDATED - DP_LANE0_1_STATUS;
+	u32 link_status_read_max_retries = 100;
+
+	while (--link_status_read_max_retries) {
+		len = drm_dp_dpcd_read_link_status(ctrl->aux->drm_aux,
+			link_status);
+		if (len != DP_LINK_STATUS_SIZE) {
+			pr_err("DP link status read failed, err: %d\n", len);
+			ret = len;
+			break;

Just return directly here. You can also just drop len and use ret (or drop ret and use len).

drivers/gpu/drm/msm/dp/dp_ctrl.c line 802

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+		}
+
+		if (!(link_status[offset] & DP_LINK_STATUS_UPDATED))
+			break;

And return 0 directly here

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+	}
+
+	return ret;

Here you're returning successful in the timeout case :( Once you convert the above
to direct returns, this can become return -ETIMEDOUT;

I think you should also drop the number of retries drastically.

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+}
+
+static int dp_ctrl_link_train_1(struct dp_ctrl_private *ctrl)
+{
+	int tries, old_v_level, ret = 0;
+	u8 link_status[DP_LINK_STATUS_SIZE];
+	int const maximum_retries = 5;
+
+	dp_ctrl_state_ctrl(ctrl, 0);
+	/* Make sure to clear the current pattern before starting a new one 

*/

drivers/gpu/drm/msm/dp/dp_ctrl.c line 818

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+	wmb();
+
+	ctrl->catalog->set_pattern(ctrl->catalog, 0x01);

#define that bit please

drivers/gpu/drm/msm/dp/dp_ctrl.c line 820

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+	dp_ctrl_train_pattern_set(ctrl, DP_TRAINING_PATTERN_1 |
+		DP_LINK_SCRAMBLING_DISABLE); /* train_1 */

the train_1 comment isn't needed.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 825

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+	dp_ctrl_update_vx_px(ctrl);
+
+	tries = 0;
+	old_v_level = ctrl->link->phy_params.v_level;
+	while (1) {

Instead of unbounded, this should be:

        for (tries = 0; tries < maximum_retries; tries++) {

You'll need to s/break/return ret/ in the rest of the loop and move the timeout error to the bottom of the function

drivers/gpu/drm/msm/dp/dp_ctrl.c line 837

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +12 -0
+		drm_dp_link_train_clock_recovery_delay(ctrl->panel->dpcd);
+
+		ret = dp_ctrl_read_link_status(ctrl, link_status);
+		if (ret)
+			break;
+
+		if (drm_dp_clock_recovery_ok(link_status,
+			ctrl->link->link_params.lane_count)) {
+			break;
+		}
+
+		if (ctrl->link->phy_params.v_level == DP_LINK_VOLTAGE_MAX) {

Since DP_LINK_VOLTAGE_MAX == DP_LINK_VOLTAGE_LEVEL_2, you'll end up not retrying LEVEL_2 at all.

Quoted 54 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +53 -0
+			pr_err_ratelimited("max v_level reached\n");
+			ret = -EAGAIN;
+			break;
+		}
+
+		if (old_v_level == ctrl->link->phy_params.v_level) {
+			tries++;
+			if (tries >= maximum_retries) {
+				pr_err("max tries reached\n");
+				ret = -ETIMEDOUT;
+				break;
+			}
+		} else {
+			tries = 0;
+			old_v_level = ctrl->link->phy_params.v_level;
+		}
+
+		pr_debug("clock recovery not done, adjusting vx px\n");
+
+		ctrl->link->adjust_levels(ctrl->link, link_status);
+		dp_ctrl_update_vx_px(ctrl);
+	}
+
+	return ret;
+}
+
+static int dp_ctrl_link_rate_down_shift(struct dp_ctrl_private *ctrl)
+{
+	int ret = 0;
+
+	if (!ctrl)
+		return -EINVAL;
+
+	switch (ctrl->link->link_params.bw_code) {
+	case DP_LINK_BW_8_1:
+		ctrl->link->link_params.bw_code = DP_LINK_BW_5_4;
+		break;
+	case DP_LINK_BW_5_4:
+		ctrl->link->link_params.bw_code = DP_LINK_BW_2_7;
+		break;
+	case DP_LINK_BW_2_7:
+	case DP_LINK_BW_1_62:
+	default:
+		ctrl->link->link_params.bw_code = DP_LINK_BW_1_62;
+		break;
+	};
+
+	pr_debug("new bw code=0x%x\n", ctrl->link->link_params.bw_code);
+
+	return ret;
+}
+
+static void dp_ctrl_clear_training_pattern(struct dp_ctrl_private 

*ctrl)

drivers/gpu/drm/msm/dp/dp_ctrl.c line 892

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+{
+	dp_ctrl_train_pattern_set(ctrl, 0);

DP_TRAINING_PATTERN_DISABLE

Quoted 24 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +12 -0
+	drm_dp_link_train_channel_eq_delay(ctrl->panel->dpcd);
+}
+
+static int dp_ctrl_link_training_2(struct dp_ctrl_private *ctrl)
+{
+	int tries = 0, ret = 0;
+	char pattern;
+	int const maximum_retries = 5;
+	u8 link_status[DP_LINK_STATUS_SIZE];
+
+	dp_ctrl_state_ctrl(ctrl, 0);
+	/* Make sure to clear the current pattern before starting a new one 

*/

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	wmb();
+
+	if (drm_dp_tps3_supported(ctrl->panel->dpcd))
+		pattern = DP_TRAINING_PATTERN_3;
+	else
+		pattern = DP_TRAINING_PATTERN_2;
+
+	dp_ctrl_update_vx_px(ctrl);
+	ctrl->catalog->set_pattern(ctrl->catalog, pattern);
+	dp_ctrl_train_pattern_set(ctrl, pattern | 

DP_RECOVERED_CLOCK_OUT_EN);

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+
+	do  {

for (tries = 0; tries < maximum_retries; tries++)

Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +17 -0
+		drm_dp_link_train_channel_eq_delay(ctrl->panel->dpcd);
+
+		ret = dp_ctrl_read_link_status(ctrl, link_status);
+		if (ret)
+			break;
+
+		if (drm_dp_channel_eq_ok(link_status,
+			ctrl->link->link_params.lane_count))
+			break;
+
+		if (tries > maximum_retries) {
+			ret = -ETIMEDOUT;
+			break;
+		}
+		tries++;
+
+		ctrl->link->adjust_levels(ctrl->link, link_status);

drivers/gpu/drm/msm/dp/dp_ctrl.c line 943

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+		dp_ctrl_update_vx_px(ctrl);
+	} while (1);
+
+	return ret;
+}
+
+static int dp_ctrl_link_train(struct dp_ctrl_private *ctrl)
+{
+	int ret = 0;
+	u8 encoding = 0x1;

DP_SET_ANSI_8B10B

drivers/gpu/drm/msm/dp/dp_ctrl.c line 954

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +11 -0
+	struct drm_dp_link link_info = {0};
+
+	ctrl->link->phy_params.p_level = 0;
+	ctrl->link->phy_params.v_level = 0;
+
+	dp_ctrl_config_ctrl(ctrl);
+
+	link_info.num_lanes = ctrl->link->link_params.lane_count;
+	link_info.rate = drm_dp_bw_code_to_link_rate(
+		ctrl->link->link_params.bw_code);
+	link_info.capabilities = ctrl->panel->link_info.capabilities;

Drop the hand-rolled ctrl->panel->link_info and use drm_dp_link_probe to fill in drm_dp_link.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 962

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+
+	drm_dp_link_configure(ctrl->aux->drm_aux, &link_info);
+	drm_dp_dpcd_write(ctrl->aux->drm_aux, 

DP_MAIN_LINK_CHANNEL_CODING_SET,

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+				&encoding, 1);
+
+	ret = dp_ctrl_link_train_1(ctrl);
+	if (ret) {
+		pr_err("link training #1 failed\n");

print ret

drivers/gpu/drm/msm/dp/dp_ctrl.c line 967

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+		goto end;
+	}
+
+	/* print success info as this is a result of user initiated action 

*/

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +1 -0
+	pr_info("link training #1 successful\n");

this should be debug loglevel

drivers/gpu/drm/msm/dp/dp_ctrl.c line 971

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+
+	ret = dp_ctrl_link_training_2(ctrl);
+	if (ret) {
+		pr_err("link training #2 failed\n");

print ret

drivers/gpu/drm/msm/dp/dp_ctrl.c line 976

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+		goto end;
+	}
+
+	/* print success info as this is a result of user initiated action 

*/

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +1 -0
+	pr_info("link training #2 successful\n");

debug loglevel

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+
+end:
+	dp_ctrl_state_ctrl(ctrl, 0);
+	/* Make sure to clear the current pattern before starting a new one 

*/

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +1 -0
+	wmb();

Same comments re: wmb

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+
+	dp_ctrl_clear_training_pattern(ctrl);
+	return ret;
+}
+
+static int dp_ctrl_setup_main_link(struct dp_ctrl_private *ctrl, bool 

train)

drivers/gpu/drm/msm/dp/dp_ctrl.c line 995

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +8 -0
+{
+	bool mainlink_ready = false;
+	int ret = 0;
+
+	ctrl->catalog->mainlink_ctrl(ctrl->catalog, true);
+
+	ret = ctrl->link->psm_config(ctrl->link,
+		&ctrl->panel->link_info, false);

This can fit on one line

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+	if (ret)
+		goto end;

All of the "goto end"'s can be replaced with "return ret", then delete the end label.

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+
+	if (ctrl->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN)

You should really protect sink_request with a lock, it's racy. I'm trying to catch the race conditions while I review, but I'd urge you to audit the driver for other places that need locking.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1003

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+		goto end;
+
+	if (!train)
+		goto send_video;

Instead of adding the label, just wrap the reset and train calls in an if (train) {} block.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1008

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+
+	/*
+	 * As part of previous calls, DP controller state might have
+	 * transitioned to PUSH_IDLE. In order to start transmitting a link
+	 * training pattern, we have to first to a DP software reset.

"we have to first _do_ a..."

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+	 */
+	ctrl->catalog->reset(ctrl->catalog);
+
+	ret = dp_ctrl_link_train(ctrl);
+	if (ret)
+		goto end;

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1024

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+
+send_video:
+	/*
+	 * Set up transfer unit values and set controller state to send
+	 * video.
+	 */
+	dp_ctrl_setup_tr_unit(ctrl);
+	ctrl->catalog->state_ctrl(ctrl->catalog, ST_SEND_VIDEO);
+
+	dp_ctrl_wait4video_ready(ctrl);

Check return value please

Quoted 14 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +14 -0
+	mainlink_ready = ctrl->catalog->mainlink_ready(ctrl->catalog);
+	pr_debug("mainlink %s\n", mainlink_ready ? "READY" : "NOT READY");
+end:
+	return ret;
+}
+
+static void dp_ctrl_set_clock_rate(struct dp_ctrl_private *ctrl,
+				   char *name, u32 rate)
+{
+	u32 num = ctrl->parser->mp[DP_CTRL_PM].num_clk;
+	struct dss_clk *cfg = ctrl->parser->mp[DP_CTRL_PM].clk_config;
+
+	while (num && strcmp(cfg->clk_name, name)) {
+		num--;

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1048

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+		cfg++;
+	}
+
+	pr_debug("setting rate=%d on clk=%s\n", rate, name);
+
+	if (num)
+		cfg->rate = rate;
+	else
+		pr_err("%s clock could not be set with rate %d\n", name, rate);
+}

Instead of doing all of this work, just store pointers to the link and pixel clock when you parse the dt. That way you can just access them directly in dp_ctrl_enable_mainlink_clocks.

Quoted 24 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+
+static int dp_ctrl_enable_mainlink_clocks(struct dp_ctrl_private 

*ctrl)

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +20 -0
+{
+	int ret = 0;
+
+	ctrl->power->set_pixel_clk_parent(ctrl->power);
+
+	dp_ctrl_set_clock_rate(ctrl, "ctrl_link_clk",
+		drm_dp_bw_code_to_link_rate(ctrl->link->link_params.bw_code));
+
+	dp_ctrl_set_clock_rate(ctrl, "ctrl_pixel_clk", ctrl->pixel_rate);
+
+	ret = ctrl->power->clk_enable(ctrl->power, DP_CTRL_PM, true);
+	if (ret) {
+		pr_err("Unabled to start link clocks\n");
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+static int dp_ctrl_disable_mainlink_clocks(struct dp_ctrl_private 

*ctrl)

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1073

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+{
+	return ctrl->power->clk_enable(ctrl->power, DP_CTRL_PM, false);
+}

This function isn't necesary (even less so when all of the catalog abstractions are gone).

Quoted 53 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +53 -0
+
+static int dp_ctrl_host_init(struct dp_ctrl *dp_ctrl, bool flip)
+{
+	struct dp_ctrl_private *ctrl;
+	struct dp_catalog_ctrl *catalog;
+
+	if (!dp_ctrl) {
+		pr_err("Invalid input data\n");
+		return -EINVAL;
+	}
+
+	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
+
+	ctrl->orientation = flip;
+	catalog = ctrl->catalog;
+
+	catalog->usb_reset(ctrl->catalog, flip);
+	catalog->phy_reset(ctrl->catalog);
+	catalog->enable_irq(ctrl->catalog, true);
+
+	return 0;
+}
+
+/**
+ * dp_ctrl_host_deinit() - Uninitialize DP controller
+ * @ctrl: Display Port Driver data
+ *
+ * Perform required steps to uninitialize DP controller
+ * and its resources.
+ */
+static void dp_ctrl_host_deinit(struct dp_ctrl *dp_ctrl)
+{
+	struct dp_ctrl_private *ctrl;
+
+	if (!dp_ctrl) {
+		pr_err("Invalid input data\n");
+		return;
+	}
+
+	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
+
+	ctrl->catalog->enable_irq(ctrl->catalog, false);
+
+	pr_debug("Host deinitialized successfully\n");
+}
+
+static bool dp_ctrl_use_fixed_nvid(struct dp_ctrl_private *ctrl)
+{
+	u8 *dpcd = ctrl->panel->dpcd;
+
+	/*
+	 * For better interop experience, used a fixed NVID=0x8000
+	 * whenever connected to a VGA dongle downstream.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1136

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	 */
+	if (dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT) {
+		u8 type = dpcd[DP_DOWNSTREAMPORT_PRESENT] &
+			DP_DWN_STRM_PORT_TYPE_MASK;
+		if (type == DP_DWN_STRM_PORT_TYPE_ANALOG)
+			return true;
+	}
+
+	return false;
+}

For this, you should use the DP_DPCD_QUIRK_CONSTANT_N quirk and drm_dp_has_quirk() instead.

Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +17 -0
+
+static int dp_ctrl_link_maintenance(struct dp_ctrl_private *ctrl)
+{
+	int ret = 0;
+
+	ctrl->dp_ctrl.push_idle(&ctrl->dp_ctrl);
+	ctrl->dp_ctrl.reset(&ctrl->dp_ctrl);
+
+	ctrl->pixel_rate = ctrl->panel->pinfo.pixel_clk_khz;
+
+	do {
+		if (ret == -EAGAIN) {
+			/* try with lower link rate */
+			dp_ctrl_link_rate_down_shift(ctrl);
+
+			ctrl->catalog->mainlink_ctrl(ctrl->catalog, false);
+		}

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1163

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+
+		ctrl->catalog->phy_lane_cfg(ctrl->catalog,
+			ctrl->orientation, ctrl->link->link_params.lane_count);
+
+		/*
+		 * Disable and re-enable the mainlink clock since the
+		 * link clock might have been adjusted as part of the
+		 * link maintenance.
+		 */
+		dp_ctrl_disable_mainlink_clocks(ctrl);

Return value should be checked

Below you have:

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+		/* hw recommended delay before re-enabling clocks */
+		msleep(20);

Between the disable and enable, so you should probably have that here too?

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1167

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+
+		ret = dp_ctrl_enable_mainlink_clocks(ctrl);
+		if (ret)
+			continue;

Do you really want to continue here? Seems like you could get into an infinite loop pretty easily in the -EINVAL case.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1176

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +9 -0
+
+		dp_ctrl_configure_source_params(ctrl);
+
+		ctrl->catalog->config_msa(ctrl->catalog,
+			drm_dp_bw_code_to_link_rate(
+			ctrl->link->link_params.bw_code),
+			ctrl->pixel_rate, dp_ctrl_use_fixed_nvid(ctrl));
+
+		reinit_completion(&ctrl->idle_comp);

Are you guaranteed that this doesn't race with other idle_comp uses?

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1179

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+
+		ret = dp_ctrl_setup_main_link(ctrl, true);
+	} while (ret == -EAGAIN);

The do/while is a bit awkward, especially since it starts with a conditional block that can't possibly be true on the first iteration. How about:

	for (tries = 0; tries < max_tries; tries++) {
		ctrl->catalog->phy_lane_cfg(ctrl->catalog,
			ctrl->orientation, ctrl->link->link_params.lane_count);

		/*
		 * Disable and re-enable the mainlink clock since the
		 * link clock might have been adjusted as part of the
		 * link maintenance.
		 */
		ret = dp_ctrl_disable_mainlink_clocks(ctrl);
                if (ret)
                        return ret;

		ret = dp_ctrl_enable_mainlink_clocks(ctrl);
		if (ret)
			return ret;

		dp_ctrl_configure_source_params(ctrl);

		ctrl->catalog->config_msa(ctrl->catalog,
			drm_dp_bw_code_to_link_rate(
			ctrl->link->link_params.bw_code),
			ctrl->pixel_rate, dp_ctrl_use_fixed_nvid(ctrl));

		reinit_completion(&ctrl->idle_comp);

		ret = dp_ctrl_setup_main_link(ctrl, true);
		if (ret != -EAGAIN)
                        return ret;

                /* try with lower link rate */
                dp_ctrl_link_rate_down_shift(ctrl);

                ctrl->catalog->mainlink_ctrl(ctrl->catalog, false);
	}

        return -ETIMEDOUT;

There's a lot of similarity between this code and dp_ctrl_on. If the code were shared, we wouldn't have the missing 20ms delay above. So can you please pull the common bits which [re-]initialize the link into a helper function that you call from both functions?

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+
+	return ret;

It's nice that we return a value here, but it's never checked by our callers :(

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1193

Quoted 13 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+}
+
+static void dp_ctrl_process_phy_test_request(struct dp_ctrl_private 

*ctrl)

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +9 -0
+{
+	int ret = 0;
+
+	if (!ctrl->link->phy_params.phy_test_pattern_sel) {
+		pr_debug("no test pattern selected by sink\n");
+		return;
+	}
+
+	pr_debug("start\n");

This and the "end" debug statements should be removed

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1197

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+
+	ctrl->dp_ctrl.push_idle(&ctrl->dp_ctrl);
+	/*
+	 * The global reset will need DP link ralated clocks to be

s/related/ralated/

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1206

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +9 -0
+	 * running. Add the global reset just before disabling the
+	 * link clocks and core clocks.
+	 */
+	ctrl->dp_ctrl.reset(&ctrl->dp_ctrl);
+	ctrl->dp_ctrl.off(&ctrl->dp_ctrl);
+
+	ret = ctrl->dp_ctrl.on(&ctrl->dp_ctrl);
+	if (ret)
+		pr_err("failed to enable DP controller\n");

Please propagate errors instead of swallowing them.

Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+
+	pr_debug("end\n");
+}
+
+static void dp_ctrl_send_phy_test_pattern(struct dp_ctrl_private 

*ctrl)

drivers/gpu/drm/msm/dp/dp_ctrl.c new file +11 -0
+{
+	bool success = false;
+	u32 pattern_sent = 0x0;
+	u32 pattern_requested = ctrl->link->phy_params.phy_test_pattern_sel;
+
+	pr_debug("request: %s\n",
+			dp_link_get_phy_test_pattern(pattern_requested));
+
+	ctrl->catalog->update_vx_px(ctrl->catalog,
+			ctrl->link->phy_params.v_level,
+			ctrl->link->phy_params.p_level);

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1232

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	ctrl->catalog->send_phy_pattern(ctrl->catalog, pattern_requested);
+	ctrl->link->send_test_response(ctrl->link);
+
+	pattern_sent = ctrl->catalog->read_phy_pattern(ctrl->catalog);
+
+	switch (pattern_sent) {
+	case MR_LINK_TRAINING1:
+		if (pattern_requested ==
+				DP_TEST_PHY_PATTERN_D10_2_NO_SCRAMBLING)
+			success = true;

success = pattern_requested == DP_LINK_QUAL_PATTERN_11_D10_2;

Same can be done below.

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +11 -0
+		break;
+	case MR_LINK_SYMBOL_ERM:
+		if ((pattern_requested ==
+				DP_TEST_PHY_PATTERN_SYMBOL_ERR_MEASUREMENT_CNT)
+			|| (pattern_requested ==
+				DP_TEST_PHY_PATTERN_HBR2_CTS_EYE_PATTERN))
+			success = true;
+		break;
+	case MR_LINK_PRBS7:
+		if (pattern_requested == DP_TEST_PHY_PATTERN_PRBS7)
+			success = true;

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1253

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+		break;
+	case MR_LINK_CUSTOM80:
+		if (pattern_requested ==
+				DP_TEST_PHY_PATTERN_80_BIT_CUSTOM_PATTERN)
+			success = true;
+		break;
+	default:
+		success = false;
+		return;
+	}

I feel like you should return success (or a ret). As it is, this doesn't do much.

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+
+	pr_debug("%s: %s\n", success ? "success" : "failed",
+			dp_link_get_phy_test_pattern(pattern_requested));
+}
+
+static void dp_ctrl_handle_sink_request(struct dp_ctrl *dp_ctrl)
+{
+	struct dp_ctrl_private *ctrl;
+	u32 sink_request = 0x0;
+

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1273

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	if (!dp_ctrl) {
+		pr_err("invalid input\n");
+		return;
+	}
+
+	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
+	sink_request = ctrl->link->sink_request;
+
+	if (sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) {
+		pr_info("PHY_TEST_PATTERN request\n");

Downgrade to DEBUG level please

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1278

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+		dp_ctrl_process_phy_test_request(ctrl);
+	}
+
+	if (sink_request & DP_LINK_STATUS_UPDATED)
+		dp_ctrl_link_maintenance(ctrl);

Check return value

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1282

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+
+	if (sink_request & DP_TEST_LINK_TRAINING) {
+		ctrl->link->send_test_response(ctrl->link);
+		dp_ctrl_link_maintenance(ctrl);

Check return value

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +5 -0
+	}
+}
+
+static void dp_ctrl_reset(struct dp_ctrl *dp_ctrl)
+{

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1297

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+	struct dp_ctrl_private *ctrl;
+
+	if (!dp_ctrl) {
+		pr_err("invalid params\n");
+		return;
+	}
+
+	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
+	ctrl->catalog->reset(ctrl->catalog);
+}

I think this function goes away with all of the catalog stuff removed.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1304

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +7 -0
+
+static int dp_ctrl_on(struct dp_ctrl *dp_ctrl)
+{
+	int rc = 0;
+	struct dp_ctrl_private *ctrl;
+	u32 rate = 0;
+	u32 link_train_max_retries = 100;

This amount is excessive, 5 times should suffice (unless you have data that suggests otherwise).

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1305

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +1 -0
+	u32 const phy_cts_pixel_clk_khz = 148500;

Should this be a #define in drm_dp_helper?

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1314

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +9 -0
+
+	if (!dp_ctrl) {
+		rc = -EINVAL;
+		goto end;
+	}
+
+	ctrl = container_of(dp_ctrl, struct dp_ctrl_private, dp_ctrl);
+
+	atomic_set(&ctrl->aborted, 0);

Why is this needed over is_connected? It seems like if you had proper locking around is_connected (which I think is necessary), you could just acquire the lock
and try the training. If it fails b/c someone unplugged the cable, that's quite Ok.

Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +19 -0
+	rate = ctrl->panel->link_info.rate;
+
+	ctrl->power->clk_enable(ctrl->power, DP_CORE_PM, true);
+	ctrl->catalog->hpd_config(ctrl->catalog, true);
+
+	if (ctrl->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN) {
+		pr_debug("using phy test link parameters\n");
+		if (!ctrl->panel->pinfo.pixel_clk_khz)
+			ctrl->pixel_rate = phy_cts_pixel_clk_khz;
+	} else {
+		ctrl->link->link_params.bw_code =
+			drm_dp_link_rate_to_bw_code(rate);
+		ctrl->link->link_params.lane_count =
+			ctrl->panel->link_info.num_lanes;
+		ctrl->pixel_rate = ctrl->panel->pinfo.pixel_clk_khz;
+	}
+
+	pr_debug("bw_code=%d, lane_count=%d, pixel_rate=%d\n",
+		ctrl->link->link_params.bw_code,

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1343

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+		ctrl->link->link_params.lane_count, ctrl->pixel_rate);
+
+	ctrl->catalog->phy_lane_cfg(ctrl->catalog,
+			ctrl->orientation, ctrl->link->link_params.lane_count);
+
+	rc = dp_ctrl_enable_mainlink_clocks(ctrl);
+	if (rc)
+		goto end;
+
+	reinit_completion(&ctrl->idle_comp);

Are you guaranteed that this doesn't race with other idle_comp uses (or other dp_ctrl_on callers)?

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +9 -0
+
+	dp_ctrl_configure_source_params(ctrl);
+
+	while (--link_train_max_retries && !atomic_read(&ctrl->aborted)) {
+		ctrl->catalog->config_msa(ctrl->catalog,
+			drm_dp_bw_code_to_link_rate(
+			ctrl->link->link_params.bw_code),
+			ctrl->pixel_rate, dp_ctrl_use_fixed_nvid(ctrl));
+

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1362

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +10 -0
+		rc = dp_ctrl_setup_main_link(ctrl, true);
+		if (!rc)
+			break;
+
+		/* try with lower link rate */
+		dp_ctrl_link_rate_down_shift(ctrl);
+
+		ctrl->catalog->mainlink_ctrl(ctrl->catalog, false);
+
+		dp_ctrl_disable_mainlink_clocks(ctrl);

Check return code

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1366

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +4 -0
+		/* hw recommended delay before re-enabling clocks */
+		msleep(20);
+
+		dp_ctrl_enable_mainlink_clocks(ctrl);

Check return code

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +1 -0
+	}

Same comment here as in dp_ctrl_link_maintenance(), we should pull out the common code and put it in a helper.

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0
+
+	if (ctrl->link->sink_request & DP_TEST_LINK_PHY_TEST_PATTERN)

This is racy, sink_request could change between the check above and here.

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1372

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +3 -0
+		dp_ctrl_send_phy_test_pattern(ctrl);
+
+	pr_debug("End-\n");

Please remove

Quoted 13 lines

drivers/gpu/drm/msm/dp/dp_ctrl.c line 1378

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0
+
+end:
+	return rc;
+}
+
+static void dp_ctrl_off(struct dp_ctrl *dp_ctrl)
[… more lines in the raw message]

readl/wmb nit

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check and propagate return value

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 14 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This should return the isr instead of store it in ctrl->catalog->isr, since that could potentially be overwritten after this function acks the current interrupts.

(Also, it's only used in this function, so there's no need to store it). One you remove the catalog indirection, hopefully there will be a bunch of these cases that become clear.

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

As mentioned above, just call the completions directly.

drivers/gpu/drm/msm/dp/dp_ctrl.c

Quoted 62 lines
drivers/gpu/drm/msm/dp/dp_ctrl.c new file +62 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Once again, these functions can be deleted. Just store the _necessary_ data in a central struct (with substructs as necessary) and call functions directly.

drivers/gpu/drm/msm/dp/dp_ctrl.h

Quoted 43 lines
drivers/gpu/drm/msm/dp/dp_ctrl.h new file +2 -0
new file mode 100644
index 0000000..6ab221a

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_ctrl.h new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same comment as catalog, these should just be functions to be called directly.

drivers/gpu/drm/msm/dp/dp_ctrl.h

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_ctrl.h new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This struct is not needed, function arguments work just as well.

drivers/gpu/drm/msm/dp/dp_debug.c

Quoted 391 lines
drivers/gpu/drm/msm/dp/dp_ctrl.h new file +5 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_debug.c new file +2 -0
new file mode 100644
index 0000000..5c0a8ce

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_debug.c new file +180 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*len)

drivers/gpu/drm/msm/dp/dp_debug.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*user_buff,

drivers/gpu/drm/msm/dp/dp_debug.c new file +171 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

edid, hpd, and connected can all be deleted. They're provided by core.

AFAICT, you can also infer the information from dp_debug, so I think you can just drop this entire file.

drivers/gpu/drm/msm/dp/dp_debug.h

Quoted 222 lines
drivers/gpu/drm/msm/dp/dp_debug.c new file +62 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*panel,

drivers/gpu/drm/msm/dp/dp_debug.c new file +69 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_debug.h new file +2 -0
new file mode 100644
index 0000000..a6480e1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_debug.h new file +28 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

data
+ *
+ * @dev: device instance of the caller
+ * @panel: instance of panel module
+ * @usbpd: instance of usbpd module
+ * @link: instance of link module
+ * @connector: double pointer to display connector
+ * return: pointer to allocated debug module data
+ *
+ * This function sets up the debug module and provides a way
+ * for debugfs input to be communicated with existing modules
+ */
+struct dp_debug *dp_debug_get(struct device *dev, struct dp_panel *panel,

drivers/gpu/drm/msm/dp/dp_debug.h new file +15 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*panel,

drivers/gpu/drm/msm/dp/dp_debug.h new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Drop this too

drivers/gpu/drm/msm/dp/dp_display.c

Quoted 220 lines
drivers/gpu/drm/msm/dp/dp_debug.h new file +2 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_display.c new file +2 -0
new file mode 100644
index 0000000..8c98399

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_display.c new file +131 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*master,

drivers/gpu/drm/msm/dp/dp_display.c new file +35 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dp)

drivers/gpu/drm/msm/dp/dp_display.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dp,

drivers/gpu/drm/msm/dp/dp_display.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This function is called from a few different threads with no locking. It seems like there's good opportunity for is_connected and notification_comp to get out of sync.

Additionally, is_connected is set to true before the function returns (and enable has been completed). So is that going to cause problems when we call detect/get_modes where is_connected == true and the hw is not up?

Perhaps I'm misreading this function, but it seems like the plan is to block until userspace has been notified and does a full modeset (ie: enable)? If that is the case, we usually don't want to have the hardware lit up until it's actually going to be used. In these cases, we'll wrap get_modes in enable/disable (with proper locking), and wait for modeset to leave it on.

drivers/gpu/drm/msm/dp/dp_display.c

Quoted 700 lines
drivers/gpu/drm/msm/dp/dp_display.c new file +168 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dp)

drivers/gpu/drm/msm/dp/dp_display.c new file +70 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dp)

drivers/gpu/drm/msm/dp/dp_display.c new file +135 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

mode_pclk_khz)

drivers/gpu/drm/msm/dp/dp_display.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_display);

drivers/gpu/drm/msm/dp/dp_display.c new file +80 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

These 2 functions are never used, and as such g_dp_display is never used. AFAICT, the callback hooks linked from g_dp_display also aren't called from anywhere else. So can you just dump these functions, the struct, and all of the unused callback hooks?

Quoted 42 lines
drivers/gpu/drm/msm/dp/dp_display.c new file +42 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines

drivers/gpu/drm/msm/dp/dp_display.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_display.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dev,

drivers/gpu/drm/msm/dp/dp_display.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Where is this called?

This is called from dpu_kms.c. The changes from DPU will be dependent on these changes.

Quoted 401 lines

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 232 lines
drivers/gpu/drm/msm/dp/dp_display.c new file +38 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_display.h new file +2 -0
new file mode 100644
index 0000000..ca5eae5

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_display.h new file +42 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_drm.c new file +2 -0
new file mode 100644
index 0000000..64d6449

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_drm.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*drm_mode,

drivers/gpu/drm/msm/dp/dp_drm.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drm_mode->hsync_end;

drivers/gpu/drm/msm/dp/dp_drm.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drm_mode->vsync_end;

drivers/gpu/drm/msm/dp/dp_drm.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dp_mode,

drivers/gpu/drm/msm/dp/dp_drm.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_mode->timing.h_back_porch;

drivers/gpu/drm/msm/dp/dp_drm.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_mode->timing.v_back_porch;

drivers/gpu/drm/msm/dp/dp_drm.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just use the drm modes directly and delete these functions.

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 160 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/msm/dp/dp_drm.c new file +143 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

I'm not convinced you need any of this. The only advantage a bridge gets you is to be involved in modeset. However the only thing you do in modeset is save the mode (which is only used in enable). So why not just use the mode from the crtc's state when encoder->enable is called?

Quoted 2 lines

That allows you to delete all of the bridge stuff here.

Will keep enable, disable and mode_set func ops and remove the remaining ops. Please let me know if you still have concerns with these func ops.

Quoted 4,707 lines

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*display)

drivers/gpu/drm/msm/dp/dp_drm.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This isn't called from anything?

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 22 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

connected
+ * @connector: Pointer to drm connector structure
+ * @force: Force detect setting from drm framework
+ * Returns: Connector 'is connected' status
+ */
+static enum drm_connector_status dp_connector_detect(struct drm_connector *conn,

drivers/gpu/drm/msm/dp/dp_drm.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

connector_status_unknown;

drivers/gpu/drm/msm/dp/dp_drm.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

no need for dp_conn, just do

        dp = to_dp_connector(conn)->dp_display;

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This is always true.

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

detect() should never do work, please remove.

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Why?

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Once dp_conn is devm managed, you can just remove this function and set .destroy to drm_connector_cleanup

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Where is this called?

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 37 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drm_mode_probed_add()
+ * @connector: Pointer to drm connector structure
+ * Returns: Number of modes added
+ */

drivers/gpu/drm/msm/dp/dp_drm.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

When you get rid of dp_display_mode, please use the stack for the new drm_display_mode

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Why is only one mode returned?

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_drm.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This can also return -errno, you should check for that too.

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_drm.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Why continue if you know you failed?

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 14 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You shouldn't overwrite these.

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This shouldn't be an error

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 88 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +63 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

is valid
+ * @connector: Pointer to drm connector structure
+ * @mode: Pointer to drm mode structure
+ * Returns: Validity status for specified mode
+ */
+static enum drm_mode_status dp_connector_mode_valid(struct drm_connector *connector,

drivers/gpu/drm/msm/dp/dp_drm.c new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

I think the value of max_pclk_khz is racy, you'll probably want to audit its use.

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Please drop this.

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

So I guess I was wrong when I said none of the g_dp_display functions are being used. I'm still unsure where they're set, perhaps there's some missing code. At any rate, what's the benefit of sticking all of that work into an abstract callback hook when it only has one implementation and one callsite.

All of that code can move in here (and the same goes for the other callbacks (move the code where it's used).

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 27 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drm_atomic_helper_connector_duplicate_state,

drivers/gpu/drm/msm/dp/dp_drm.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_connector_helper_funcs = {

drivers/gpu/drm/msm/dp/dp_drm.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dp_display)

drivers/gpu/drm/msm/dp/dp_drm.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Use devm_kzalloc (you've already got a memory leak if drm_connector_init fails below).

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&dp_connector_funcs,

drivers/gpu/drm/msm/dp/dp_drm.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

These lines don't extend to 80 chars

drivers/gpu/drm/msm/dp/dp_drm.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

These are already false by virtue of kzalloc

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 122 lines
drivers/gpu/drm/msm/dp/dp_drm.c new file +5 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_drm.h new file +2 -0
new file mode 100644
index 0000000..efbc1be

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_drm.h new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

initialization steps
+ * @connector: Pointer to drm connector structure
+ * @display: Pointer to private display handle
+ * Returns: Zero on success
+ */
+int dp_connector_post_init(struct drm_connector *connector, void *display);

drivers/gpu/drm/msm/dp/dp_drm.h new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dp_display);

drivers/gpu/drm/msm/dp/dp_drm.h new file +3 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_extcon.c new file +2 -0
new file mode 100644
index 0000000..635c13b

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_extcon.c new file +33 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Where is this used?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 26 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +26 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No need to have this just for one debug statement, just print the enum value with %d below.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same here.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 23 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +23 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Where is this called from?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Please #define hardcoded values

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

All of the values in cap->port seem to be hardcoded, so why not just use the #define's directly where applicable?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Where is this called?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 22 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Only multi_func, hpd_high, and hpd_irq are used out of this struct. Can you cull the values down? hpd_irq is also only set to its hardcoded value, so just use that value directly where applicable.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This function is also unused

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 44 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +44 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just return -EINVAL and get rid of the error label and rc.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

If forced_disconnect is always !dp_usbpd->hpd_high, why not just use !dp_usbpd->hpd_high directly?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Do you need locking in this function/file?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 22 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

        return (property.intval) ? 2 : 4;

and delete lanes

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 20 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +20 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Can fit on 1 line

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Can fit on 1 line, plus remove all () from this, they're not needed.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This part is a bit confusing, you add a helper function to get the lanes, and interpret the USB_SS property to return 2 vs. 4, but then immediately convert that back into what the USB_SS property returns. Instead, remove the helper function and read USB_SS directly here.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

I feel like this can never be false anyways, but you're not using either of these members in the conditional block. So why not just call dp_extcon_connect unconditionally?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_extcon.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check return value

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same here.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_extcon.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check return value

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*extcon_priv)

drivers/gpu/drm/msm/dp/dp_extcon.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

create_singlethread_workqueue("drm_dp_extcon");

What's the benefit of using a dedicated workqueue instead of the system wq?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This function can't fail, so it should return void. In fact, this really doesn't need to be a separate function, roll it into dp_extcon_register().

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 23 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +23 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Yikes, this doesn't look like an error!

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_usbpd);

drivers/gpu/drm/msm/dp/dp_extcon.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

extcon_priv->extcon,

drivers/gpu/drm/msm/dp/dp_extcon.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Why keep going and create the workqueue if we have no notifier? This should probably be a return.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

return ret?

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same here

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 13 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

remove.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dp_usbpd);

drivers/gpu/drm/msm/dp/dp_extcon.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

extcon_priv->extcon,

drivers/gpu/drm/msm/dp/dp_extcon.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

remove.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*cb)

drivers/gpu/drm/msm/dp/dp_extcon.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

remove.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 21 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

remove.

drivers/gpu/drm/msm/dp/dp_extcon.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This label isn't useful, return directly where applicable.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 168 lines
drivers/gpu/drm/msm/dp/dp_extcon.c new file +16 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_extcon.h new file +2 -0
new file mode 100644
index 0000000..1f83a18

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_extcon.h new file +91 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*cb);

drivers/gpu/drm/msm/dp/dp_extcon.h new file +7 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0
new file mode 100644
index 0000000..5ab1efc

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_link.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

These should be in drm_dp_helper.h

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 335 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +67 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

addr)

drivers/gpu/drm/msm/dp/dp_link.c new file +31 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*link)

drivers/gpu/drm/msm/dp/dp_link.c new file +65 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*link)

drivers/gpu/drm/msm/dp/dp_link.c new file +80 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

from DPCD
+ * @link: Display Port Driver data
+ *
+ * Returns 0 if it successfully parses the audio link pattern parameters.
+ */
+static int dp_link_parse_audio_pattern_params(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +81 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No need for this, just print the value in the debug statement.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 34 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +34 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same thing here, just remove this and print the enum value.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

pass-by-value doesn't need const same comment applies elsewhere, please sweep the code for other instances.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

If you're going to check len < 2, you should probably also check len > 2 to prevent overflow. At this point, len can really only be 2, so you can just remove
it entirely as an argument.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 22 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same comment here rt bounds checking

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 31 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +31 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Putting aside the uninformative names, these dp_link_parse_timing_params* can be combined into one pretty easily, like:

static int dp_link_read_u32(struct dp_link_private *link, unsigned int offset,
u32 *val, int num_bytes)

{
        int i;
        ssize_t ret;
        __be32 tmp_val;

        for (i = 0; num_bytes > 0; i += sizeof(*val)) {
                int to_read = min(sizeof(tmp_val), num_bytes);

                tmp_val = 0;
                ret = drm_dp_dpcd_read(link->aux->drm_aux, offset + i, 
&tmp_val,
                                       to_read);
                if (rlen < 0) {
                        /* print error message here */
                        return rlen;
                }
                val[i] = be32_to_cpu(tmp_val);
                num_bytes -= to_read;
        }
        return 0;
}

If you need to strip off the first bit, do it from the caller.

I didn't compile or test this, so it might need tweaking, but you get the idea.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

from DPCD
+ * @link: Display Port Driver data
+ *
+ * Returns 0 if it successfully parses the video link pattern and the link
+ * bit depth requested by the sink and, and if the values parsed are valid.
+ */
+static int dp_link_parse_video_pattern_params(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ssize_t

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Why do you need data and bp? I think you only need one.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 37 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +25 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/msm/dp/dp_link.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This mask isolates one bit from data

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

and this function returns true if the input is 0 || 1

So remove this code, and remove dp_link_is_dynamic_range_valid.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

And now you can just assign this directly. You should probably stay consistent and store the value shifted like the other values you're storing.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 118 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

link->dp_link.test_video.test_h_total);

drivers/gpu/drm/msm/dp/dp_link.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

link->dp_link.test_video.test_v_total);

drivers/gpu/drm/msm/dp/dp_link.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

link->dp_link.test_video.test_h_start);

drivers/gpu/drm/msm/dp/dp_link.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

link->dp_link.test_video.test_v_start);

drivers/gpu/drm/msm/dp/dp_link.c new file +32 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

link->dp_link.test_video.test_h_width);

drivers/gpu/drm/msm/dp/dp_link.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DP_TEST_REFRESH_RATE_NUMERATOR,

drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

(DP_TEST_REFRESH_RATE_NUMERATOR)\n");

drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Instead of sprinkling all of these pr_debug messages around, just have one big debug at the end to print everything.

Quoted 1 line

+exit:

This label isn't useful, just return directly above

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

parameters from
+ * DPCD
+ * @link: Display Port Driver data
+ *
+ * Returns 0 if it successfully parses the link rate (Byte 0x219) and lane
+ * count (Byte 0x220), and if these values parse are valid.
+ */
+static int dp_link_parse_link_training_params(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You don't need both bp and data

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ssize_t

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just use 1 directly below.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 28 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +28 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DP_MAX_LANE_COUNT_MASK

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You might also want to data against max lanes

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

return directly above and remove exit + ret;

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 31 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

phy_test_pattern_sel)

drivers/gpu/drm/msm/dp/dp_link.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

being
+ * requested.
+ */
+static int dp_link_parse_phy_test_params(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Only need one of these.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ssize_t

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just use 1 below

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

FWIW, drm_dp_dpcd_read will return either len or an -errno. Partial reads return -EPROTO. So instead of checking that rlen < param_len, you can just do rlen < 0.

Please also change all of the 1-byte reads over to using drm_dp_dpcd_readb().

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

print and return rlen.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just embed that code here.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove label/ret and return directly

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 20 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +20 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove this and just print the enum.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

link request
+ * @link: link requested by the sink
+ *
+ * Returns true if the requested link is a permitted audio/video link.
+ */

drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Should you be masking link to isolate these bits?

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

And once you mask the value, just check if any of the bits are set instead of enumerating all possible values.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 15 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

supported
+ * @test_requested: link requested by the sink
+ *
+ * Returns true if the requested link is supported.
+ */

drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

I think this all equates to:

	return test_requested != DP_TEST_LINK_FAUX_PATTERN;

and in that case, you can just remove this function and insert that condition in the if statement below.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This doesn't warrant its own function. Also, should this be & instead of ==?

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 15 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

sink
+ * @link: Display Port Driver data
+ *
+ * Parses the DPCD to check if an automated link is requested (Byte 0x201),
+ * and what type of link automation is being requested (Byte 0x218).
+ */

drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Only need 1 of bp/data

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ssize_t

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Not needed, use drm_dp_dpcd_readb()

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Print error. This goes for other failure messages in this file.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 35 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +33 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

data);

drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

If test_requested is only used in the scope of this function, just use a local and pass it around. If test_requested is used outside the scope of this function, you need locking.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check the return here or it could get stomped

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check the return here or it could get stomped

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Should fit on 1 line, I think

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check the return here or it could get stomped

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

/*

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 29 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

send

drivers/gpu/drm/msm/dp/dp_link.c new file +20 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Content
+ * Protection enabled.
+ */

drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drm_dp_dpcd_readb

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

print ret

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

return ret

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cp_ready is only used in this function, please don't store stuff like this beyond its scope.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Don't need this comment

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 29 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*link)

drivers/gpu/drm/msm/dp/dp_link.c new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*link)

drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No need for dedicated function

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 30 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

requests
+ * @link: Display Port link data
+ *
+ * This function will handle new link training requests that are initiated by
+ * the sink. In particular, it will update the requested lane count and link
+ * link rate, and then trigger the link retraining procedure.
+ *
+ * The function will return 0 if a link training request has been processed,
+ * otherwise it will return -EINVAL.
+ */
+static int dp_link_process_link_training_request(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

link->request.test_lane_count;

drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Should be using dp helper structs for this stuff

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

I strongly suspect you should have locking protecting test_response.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This is another racy function where you could be simultaneously powering up and powering down the link. So you might want some locking.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

unneeded (). You could probably reword to fit on one line too

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

checksum)

drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drm_dp_dpcd_readb. I'll stop commenting on these, just please go through and convert all 1-byte reads/writes

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check and return the result

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Only need one of these

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_link.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drm_dp_dpcd_readb

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ssize_t

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

remove

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DP_ADJUST_REQUEST_LANE0_1,

drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

print error

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 40 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DP_ADJUST_REQUEST_LANE2_3,

drivers/gpu/drm/msm/dp/dp_link.c new file +20 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

I think you can use drm_dp_get_adjust_request_voltage() for all of this.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove

Quoted 1 line

+end:

return directly everywhere and remove end & ret

Quoted 20 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

requests
+ * @link: Display Port Driver data
+ *
+ * This function will handle new phy link pattern requests that are initiated
+ * by the sink. The function will return 0 if a phy link pattern has been
+ * processed, otherwise it will return -EINVAL.
+ */

drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

{

Is test_requested always expected to have this value populated when dp_link_process_request()?

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just use these values directly instead of adding more locals.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

These should be debug level prints

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

link->request.test_lane_count;

drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check return value and propagate it.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

int r)

drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

I don't think you're really supposed to reach into the link_status like this. How about adding a new helper to check for DP_LINK_STATUS_UPDATED and one for DP_DOWNSTREAM_PORT_STATUS_CHANGED?

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 27 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

updates
+ * @link: Display Port link module data
+ *
+ * This function will check for changes in the link status, e.g. clock
+ * recovery done on all lanes, and trigger link training if there is a
+ * failure/error on the link.
+ *
+ * The function will return 0 if the a link status update has been processed,
+ * otherwise it will return -EINVAL.
+ */
+static int dp_link_process_link_status_update(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DP_LANE_ALIGN_STATUS_UPDATED) &

drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Can you please fix the alignment here, it's tough to read.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 20 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*link)

drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&

drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

It seems like this is running in a separate thread from where prev_sink_count is set, potential race here?

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	return link->prev_sink_count != link->dp_link.sink_count.count;

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 20 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

status changes
+ * @link: Display Port Driver data
+ *
+ * This function will handle downstream port updates that are initiated by
+ * the sink. If the downstream port status has changed, the EDID is read via
+ * AUX.
+ *
+ * The function will return 0 if a downstream port update has been
+ * processed, otherwise it will return -EINVAL.
+ */
+static int dp_link_process_ds_port_status_change(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just embed the contents of is_ds_port_status_changed here, no need for 2 funcs

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 41 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*link)

drivers/gpu/drm/msm/dp/dp_link.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*link)

drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

pattern request
+ * @link: Display Port link module's data
+ *
+ * This function will handle a new video pattern request that are initiated by
+ * the sink. This is acheieved by first sending a disconnect notification to
+ * the sink followed by a subsequent connect notification to the user modules,
+ * where it is expected that the user modules would draw the required link
+ * pattern.
+ */
+static int dp_link_process_video_pattern_request(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just do this directly in dp_link_process_request and get rid of this function

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 33 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

pattern request
+ * @link: Display Port link module data
+ *
+ * This function will handle a new audio pattern request that is initiated by
+ * the sink. This is acheieved by sending the necessary secondary data packets
+ * to the sink. It is expected that any simulatenous requests for video
+ * patterns will be handled before the audio pattern is sent to the sink.
+ */
+static int dp_link_process_audio_pattern_request(struct dp_link_private *link)

drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same here

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 33 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +33 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

memset?

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 73 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

to HIGH
+ * (including cases when there are back to back HPD IRQ HIGH) indicating
+ * the start of a new link training request or sink status update.
+ */

drivers/gpu/drm/msm/dp/dp_link.c new file +61 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

remove exit & ret, just return values directly

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

s/CEA_VESA/RGB_VESA?

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

s/nd/and/

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

If you store the value shifted like I suggested, you don't have to do this switch (which really should be an if anyways since the range is 0:1).

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 37 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*link_status)

drivers/gpu/drm/msm/dp/dp_link.c new file +31 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You can combine these loops and do the work at once (check out intel_get_adjust_train)

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 45 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

within

drivers/gpu/drm/msm/dp/dp_link.c new file +29 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

req)

drivers/gpu/drm/msm/dp/dp_link.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This is a stub, why do this?

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Further, why have a stub at all? The hook is never called, so delete it all please.

drivers/gpu/drm/msm/dp/dp_link.c

Quoted 29 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

bpp)

drivers/gpu/drm/msm/dp/dp_link.c new file +25 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

AFAICT tbd corresponds to a SoC register value, as opposed to the DPCD value. It's a happy coincidence that they're the same, however I think you should use a separate msm-specific #define instead of the drm_dp_helper values.

drivers/gpu/drm/msm/dp/dp_link.h

Quoted 89 lines
drivers/gpu/drm/msm/dp/dp_link.c new file +52 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_link.h new file +2 -0
new file mode 100644
index 0000000..6d6ef43

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_link.h new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DP_TRAIN_VOLTAGE_SWING_*

drivers/gpu/drm/msm/dp/dp_link.h

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_link.h new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DP_TRAIN_PRE_EMPH*

drivers/gpu/drm/msm/dp/dp_link.h

Quoted 48 lines
drivers/gpu/drm/msm/dp/dp_link.h new file +48 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Use drm_dp_link

drivers/gpu/drm/msm/dp/dp_link.h

Quoted 47 lines
drivers/gpu/drm/msm/dp/dp_link.h new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

phy_test_pattern_sel)

drivers/gpu/drm/msm/dp/dp_link.h new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This is only used for debug statements, just remove it and print the enum as an int. This will let you remove DP_LINK_ENUM_STR as well.

drivers/gpu/drm/msm/dp/dp_link.h

Quoted 35 lines
drivers/gpu/drm/msm/dp/dp_link.h new file +35 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just return directly from each case.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 49 lines
drivers/gpu/drm/msm/dp/dp_link.h new file +19 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_panel.c new file +2 -0
new file mode 100644
index 0000000..e497b44

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_panel.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

unused

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

unused

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 27 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Drop this, userspace can add a mode if appropriate

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 46 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +46 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

All of the link_info initialization should be done by drm_dp_link_probe().

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Move this down to where it's used

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You don't use ds_ports anywhere, so remove this and remove ds_ports

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Should this be an error?

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same drill as before

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*dp_panel)
+{

Let's just fail instead of doing this.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 43 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +43 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

The core will do retrys when aux reads fail, so you don't need to. With that, you can just remove this function and call drm_get_edid in read_sink_caps

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 30 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Since the defaults are going away, this gets simpler (and even simpler if you stash bw_code):

	bw_code = drm_dp_link_rate_to_bw_code(dp_panel->link_info.rate);
	if (rc || !is_link_rate_valid(bw_code) ||
            !is_lane_count_valid(dp_panel->link_info.num_lanes) ||
	    bw_code > dp_panel->max_bw_code) {
		pr_err("read_dpcd failed %d\n", rc);
		return rc;
	}

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Why read the edid so early? Can't you wait until get_modes is called (you'll have to re-read anyways).

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check return value. Should you also check the rate/lane_count validity again too?

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_panel.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Should you have locking for aux_cfg_update_done?

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 21 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Watch out for underflow here.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 32 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +32 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

As mentioned earlier, no need to duplicate drm_display_mode into dp_display_mode, same goes for dp_panel_info, please just use drm_display_mode.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 47 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +47 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

remove

Ok, so this is where you should be reading edid.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 3 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Join on one line and check return value

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check return value

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This is always 0

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Indentation is wrong

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Delete fail safe and return 0;

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No need to initialize these.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

I doubt last_block will ever be NULL, so this check is kind of pointless. Perhaps call drm_edid_block_valid() instead.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 75 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +26 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

enable)

drivers/gpu/drm/msm/dp/dp_panel.c new file +37 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

pinfo->h_back_porch;

drivers/gpu/drm/msm/dp/dp_panel.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

More mode timing parameters to delete!

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This is called from 2 different places, do you need locking?

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 46 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +46 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Again, all of this should be derived from a drm_display_mode at the point where it is committed to hardware. No need to store it in another form in the interim

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove end/rc and return directly

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 37 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +37 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No info level logs, please.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove end/rc and return directly

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

The only way to call this function is through a dp_panel callback, and yet we check if dp_panel is NULL :)

The same is true for most functions in this patch. Things will be a lot simpler when all of these are removed. This function will no longer have an error path and lane_cnt/pinfo can be initialized directly above.

drivers/gpu/drm/msm/dp/dp_panel.c

Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove end and return directly above

drivers/gpu/drm/msm/dp/dp_panel.h

Quoted 94 lines
drivers/gpu/drm/msm/dp/dp_panel.c new file +56 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_panel.h new file +2 -0
new file mode 100644
index 0000000..bf802df

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_panel.h new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You don't need an enum for this, the value coming from dpcd is just an integer and
can be used as such.

drivers/gpu/drm/msm/dp/dp_panel.h

Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_panel.h new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Drop this struct and use drm_display_mode

drivers/gpu/drm/msm/dp/dp_panel.h

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_panel.h new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Why + 1?

drivers/gpu/drm/msm/dp/dp_panel.h

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_panel.h new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This function isn't called anywhere

drivers/gpu/drm/msm/dp/dp_panel.h

Quoted 20 lines
drivers/gpu/drm/msm/dp/dp_panel.h new file +20 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Each of these conditions has unneeded ()

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 75 lines
drivers/gpu/drm/msm/dp/dp_panel.h new file +18 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_parser.c new file +2 -0
new file mode 100644
index 0000000..a366dc5

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_parser.c new file +36 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This can be a direct return of rc.

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Print rc here and below.

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 100 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +100 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No need for a separate function, just put the loop in the error label below.

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just use 1 directly

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

You should use of_property_read_u32() instead of reading as a string

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Remove extra ()

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 13 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

And this could use of_property_read_u32_array()

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 43 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +43 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

What if it's NULL?

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

What if it's NULL?

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 25 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +25 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

If you do this first, you can s/ARRAY_SIZE(dp_gpios)/mp->num_gpio/ in the rest of the function.

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

As mentioned earlier, please don't implement your own string store/lookup, just provide access to the gpios in a more direct manner (pointer or function).

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 43 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +43 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This doesn't need to be wrapped in an else

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 21 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Instead of storing the name just to get a regulator reference later, why don't you just grab the reference now and avoid the string ops?

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 57 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +57 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This shouldn't be necessary, that's the nice thing about device managed resources.

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same here, this function can go away once you take out the dp_parser abstraction layer.

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

And here you can just return the error directly and the resources will be freed magically.

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

And this becomes return 0;

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*clk_name)

drivers/gpu/drm/msm/dp/dp_parser.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This is likely not what you want since this will look for prefix _anywhere_ in clk name. An example of how this could go sideways:

	dp_parser_check_prefix("core", "core-dp-power-ctrl");
	dp_parser_check_prefix("ctrl", "core-dp-power-ctrl");

Both return true.

Anyways, strncmp is a better choice here (if we must do string operations).

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 55 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +55 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check return value

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just use "core"/"ctrl" directly here.

Quoted 2 lines

Have you considered just having 2 clock lists? That would avoid having to do this.

I am not clear on what you are suggesting? We currently have two clock-lists (core & ctrl).

Quoted 51 lines

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

How does this get below 0?

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

How does this get below 0?

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 21 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Just return directly and delete exit

Quoted 14 lines

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 12 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

---- START hmmmm

I didn't understand, can you please provide more details regarding "START" and "END".

Quoted 1,647 lines

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

---- END hmmmm

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check return value

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 17 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

strncmp

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Delete the label and return directly

drivers/gpu/drm/msm/dp/dp_parser.c

Quoted 39 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +39 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Delete the label and return directly

drivers/gpu/drm/msm/dp/dp_parser.h

Quoted 84 lines
drivers/gpu/drm/msm/dp/dp_parser.c new file +37 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_parser.h new file +2 -0
new file mode 100644
index 0000000..b39ea02

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_parser.h new file +26 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Delete the function and just print the enum value

drivers/gpu/drm/msm/dp/dp_parser.h

Quoted 64 lines
drivers/gpu/drm/msm/dp/dp_parser.h new file +64 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Once you get rid of all of the enum->string functions that are used for debugging, you can delete this.

drivers/gpu/drm/msm/dp/dp_parser.h

Quoted 58 lines
drivers/gpu/drm/msm/dp/dp_parser.h new file +58 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Same deal as the others, remove and print the enum value instead.

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 72 lines
drivers/gpu/drm/msm/dp/dp_parser.h new file +44 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_power.c new file +2 -0
new file mode 100644
index 0000000..1d58480

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_power.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Unused

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 21 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Move these initializations up to the declaration. Please apply this to the rest of the code as well.

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

No need to check rc when the only place it can go non-zero is the place that has a break;

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Put this loop in the error label and return 0 above it. Better yet, just call the dp_power_regulator_deinit in error.

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 18 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Unnecessary (), applies elsewhere too, please make a pass

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 38 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

bool enable)

drivers/gpu/drm/msm/dp/dp_power.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This function is basically identical to dp_power_regulator_init(), please delete this function and use dp_power_regulator_init().

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

active)

drivers/gpu/drm/msm/dp/dp_power.c new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

How is this not possible? You check these on initialization.

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Combine on 1 line

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Combine on one line. Also return immediately if this is the case.

Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

enable)

Split this into init/deinit, the paths don't share code.

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 48 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +48 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

device managed resources don't need to be freed

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Since this is only used in one place, just do it above and return directly.

Quoted 1 line

+exit:

Delete exit label and return directly

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 35 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +35 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This function actually can share code, but it doesn't :( Please pull this out for both paths

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Delete exit label and return directly

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 21 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Strip out unnecessary ()

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Here too

Combine on one line as well

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

and here

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

and here

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

This doesn't need to be wrapped in the else

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 24 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Delete error label and return directly

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 24 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

if (!gpio_is_valid(gpio))

	continue;

and save yourself some indent space

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 16 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

gpios are device managed, so you shouldn't need this.

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 33 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

flip)

drivers/gpu/drm/msm/dp/dp_power.c new file +23 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Instead of all of these string ops, please just make pointers accessible so you can get at the gpio directly.

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

flip,

drivers/gpu/drm/msm/dp/dp_power.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Split into 2 functions

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 43 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +43 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Print rc

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Print rc

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 43 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +43 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Check return value

Quoted 1 line

+exit:

Delete label/rc, return immediately.

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 20 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +20 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Print rc

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Print rc

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Print rc

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Print rc

drivers/gpu/drm/msm/dp/dp_power.c

Quoted 36 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +36 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Delete exit label/rc and return directly

drivers/gpu/drm/msm/msm_drv.h

Quoted 511 lines
drivers/gpu/drm/msm/dp/dp_power.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GFP_KERNEL);

drivers/gpu/drm/msm/dp/dp_power.c new file +33 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_power.h new file +2 -0
new file mode 100644
index 0000000..d1adaaf

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_power.h new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

data
+ *
+ * @parser: instance of parser module
+ * return: pointer to allocated power module data
+ *
+ * This API will configure the DisplayPort's power module and provides
+ * methods to be called by the client to configure the power related
+ * modueles.
+ */

drivers/gpu/drm/msm/dp/dp_power.h new file +9 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/dp/dp_reg.h new file +2 -0
new file mode 100644
index 0000000..77b5c0e

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

drivers/gpu/drm/msm/dp/dp_reg.h new file +344 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/msm_drv.c +2 -0
index f5cd7f6..be801be 100644

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/msm/msm_drv.h +1 -0
index 9d11f32..fb1e6f4 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Can you please add an extra line here?

include/drm/drm_dp_helper.h

Quoted 38 lines
drivers/gpu/drm/msm/msm_drv.h +0 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drivers/gpu/drm/msm/msm_drv.h +21 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

void __exit msm_mdp_unregister(void);
void __init msm_dpu_register(void);

include/drm/drm_dp_helper.h +0 -0
index 2a3843f..b0816f5 100644

Split these changes out into a separate patch, please

include/drm/drm_dp_helper.h

Quoted 6 lines
include/drm/drm_dp_helper.h +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Add DPCD version in comments for these like above.

include/drm/drm_dp_helper.h

Quoted 13 lines
include/drm/drm_dp_helper.h +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

These are already in drm_dp_helper under DP_LINK_QUAL_PATTERN_*

Quoted 25 lines
include/drm/drm_dp_helper.h +11 -1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

Quoted 4 lines
Quoted 4 lines

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

Part of the diff is not shown here. View the raw message.

#14 lore raw

Re: [DPU PATCH 2/3] drm/msm/dp: add displayPort driver support

In reply to a message not in the archive
Quoted 11 lines · On Mon, Nov 19, 2018 at 02:34:53PM -0800, [email protected] wrote:
Quoted 9 lines · Sean Paul
Quoted 7 lines · Chandan Uddaraju

Add the needed displayPort files to enable DP driver on msm target.

"dp_display" module is the main module that calls into other sub-modules. "dp_drm" file represents the interface between DRM framework and DP driver.

Quoted 3 lines

Hello Sean,
I had few queries regarding your comments. Shared my queries below. Please share your feedback.

/snip

Quoted 19 lines
Quoted 19 lines

drivers/gpu/drm/msm/dp/dp_aux.c

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_aux.c new file +0 -0
new file mode 100644
index 0000000..00b82c2
@@ -0,0 +1,570 @@

/snip

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +0 -0
new file mode 100644
index 0000000..0c300ed

/snip

Quoted 8 lines
Quoted 3 lines

I didn't really review the dp_aux.* files as-is. Please convert to using drm_dp_aux and I'll take another look.

Please correct me if I am wrong. Looks like you are suggesting to use most of the drm_dp_aux struct variable
instead of what we have defined locally.

Correct

/snip

Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +19 -0
+	struct dp_catalog_ctrl ctrl = {
+		.state_ctrl     = dp_catalog_ctrl_state_ctrl,
+		.config_ctrl    = dp_catalog_ctrl_config_ctrl,
+		.lane_mapping   = dp_catalog_ctrl_lane_mapping,
+		.mainlink_ctrl  = dp_catalog_ctrl_mainlink_ctrl,
+		.config_misc    = dp_catalog_ctrl_config_misc,
+		.config_msa     = dp_catalog_ctrl_config_msa,
+		.set_pattern    = dp_catalog_ctrl_set_pattern,
+		.reset          = dp_catalog_ctrl_reset,
+		.usb_reset      = dp_catalog_ctrl_usb_reset,
+		.mainlink_ready = dp_catalog_ctrl_mainlink_ready,
+		.enable_irq     = dp_catalog_ctrl_enable_irq,
+		.hpd_config     = dp_catalog_ctrl_hpd_config,
+		.phy_reset      = dp_catalog_ctrl_phy_reset,
+		.phy_lane_cfg   = dp_catalog_ctrl_phy_lane_cfg,
+		.update_vx_px   = dp_catalog_ctrl_update_vx_px,
+		.get_interrupt  = dp_catalog_ctrl_get_interrupt,
+		.update_transfer_unit = dp_catalog_ctrl_update_transfer_unit,
+		.send_phy_pattern    = dp_catalog_ctrl_send_phy_pattern,
Quoted 8 lines

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 1 line
drivers/gpu/drm/msm/dp/dp_aux.h new file +1 -0
+		.read_phy_pattern = dp_catalog_ctrl_read_phy_pattern,

So, what's the benefit of adding the catalog abstractions? Do you ever have
multiple/alternate implementations of a catalog? It doesn't seem like it. You
should just remove all of the catalog overhead and call the functions directly.

Quoted 9 lines

We use catalog abstractions for two different reasons:
1. To support multiple hardware since these implementations are hardware specific.
2. To virtualize DP hardware.

Our internal hardware already supports multiple chips. We want to keep these abstractions to
make the code consistent between upstream and internal implementation.

I'm not sure how this differs from having a common header/function declarations and multiple definitions in a .c gated by CONFIG_*? Ideally even this wouldn't be necessary since hw changes are either incremental and can be done more precisely than wholesale changing the implementation.

If you want to virtualize, you can do the CONFIG_* thing. However since that's not going upstream, you can carry the Kconfig/Makefile change in your downstream.

All of these abstractions add thousands of lines of code, extra files, and multiple levels of indirection. IMO, I don't think the benefits outweigh the costs.

/snip

Quoted 76 lines
Quoted 71 lines
Quoted 57 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +57 -0
+static void dp_ctrl_calc_tu_parameters(struct dp_ctrl_private *ctrl,
+				       struct dp_vc_tu_mapping_table *tu_table)
+{
+	u32 multiplier = 1000000;
+	u64 pclk, lclk;
+	u8 bpp, ln_cnt;
+	int run_idx = 0;
+	u32 lwidth, h_blank;
+	u32 fifo_empty = 0;
+	u32 ratio_scale = 1001;
+	u64 temp, ratio, original_ratio;
+	u64 temp2, reminder;
+	u64 temp3, temp4, result = 0;
+
+	u64 err = multiplier;
+	u64 n_err = 0, n_n_err = 0;
+	bool n_err_neg, nn_err_neg;
+	u8 hblank_margin = 16;
+
+	u8 tu_size, tu_size_desired = 0, tu_size_minus1;
+	int valid_boundary_link;
+	u64 resulting_valid;
+	u64 total_valid;
+	u64 effective_valid;
+	u64 effective_valid_recorded;
+	int n_tus;
+	int n_tus_per_lane;
+	int paired_tus;
+	int remainder_tus;
+	int remainder_tus_upper, remainder_tus_lower;
+	int extra_bytes;
+	int filler_size;
+	int delay_start_link;
+	int boundary_moderation_en = 0;
+	int upper_bdry_cnt = 0;
+	int lower_bdry_cnt = 0;
+	int i_upper_bdry_cnt = 0;
+	int i_lower_bdry_cnt = 0;
+	int valid_lower_boundary_link = 0;
+	int even_distribution_bf = 0;
+	int even_distribution_legacy = 0;
+	int even_distribution = 0;
+	int min_hblank = 0;
+	int extra_pclk_cycles;
+	u8 extra_pclk_cycle_delay = 4;
+	int extra_pclk_cycles_in_link_clk;
+	u64 ratio_by_tu;
+	u64 average_valid2;
+	u64 extra_buffer_margin;
+	int new_valid_boundary_link;
+
+	u64 resulting_valid_tmp;
+	u64 ratio_by_tu_tmp;
+	int n_tus_tmp;
+	int extra_pclk_cycles_tmp;
+	int extra_pclk_cycles_in_lclk_tmp;
+	int extra_req_bytes_new_tmp;

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +10 -0
+	int filler_size_tmp;
+	int lower_filler_size_tmp;
+	int delay_start_link_tmp;
+	int min_hblank_tmp = 0;
+	bool extra_req_bytes_is_neg = false;
+	struct dp_panel_info *pinfo = &ctrl->panel->pinfo;
+
+	u8 dp_brute_force = 1;
+	u64 brute_force_threshold = 10;
+	u64 diff_abs;

76 stack vars and ~450 lines must be a new record somewhere :)

Quoted 4 lines

I'm going to skip reviewing this function and let you split/simplify/reduce it.
Please just make it more readable (comments, docs, helper functions, etc).

Quoted 4 lines

Yes, will try to split this function as modular as possible. JFYI, this function is IP/hardware specific implementation. It might not be possible
to provide lot of comments to make is understandable.

Ok, please do what you can to simplify/split and add a comment that this is magic from the HW team.

/snip

Quoted 9 lines
Quoted 5 lines

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 3 lines

+int msm_dp_modeset_init(struct msm_dp *dp_display, struct drm_device *dev,

drivers/gpu/drm/msm/dp/dp_aux.h new file +1 -0
+			struct drm_encoder *encoder)

Where is this called?

This is called from dpu_kms.c. The changes from DPU will be dependent on these changes.

Hmm, is that code missing? I don't see this function being called anywhere in this patch.

/snip

Quoted 17 lines
Quoted 17 lines

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +8 -0
+static const struct drm_bridge_funcs dp_bridge_ops = {
+	.mode_fixup   = dp_bridge_mode_fixup,
+	.pre_enable   = dp_bridge_pre_enable,
+	.enable       = dp_bridge_enable,
+	.disable      = dp_bridge_disable,
+	.post_disable = dp_bridge_post_disable,
+	.mode_set     = dp_bridge_mode_set,
+};

I'm not convinced you need any of this. The only advantage a bridge gets you is
to be involved in modeset. However the only thing you do in modeset is save the
mode (which is only used in enable). So why not just use the mode from the
crtc's state when encoder->enable is called?

Quoted 6 lines
Quoted 2 lines

That allows you to delete all of the bridge stuff here.

Will keep enable, disable and mode_set func ops and remove the remaining ops.
Please let me know if you still have concerns with these func ops.

Why not remove all of it and call this code from the encoder's enable function? You shouldn't need a bridge at all.

/snip

Quoted 33 lines
Quoted 33 lines
Quoted 11 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +11 -0
+static int dp_parser_init_clk_data(struct dp_parser *parser)
+{
+	int num_clk = 0, i = 0, rc = 0;
+	int core_clk_count = 0, ctrl_clk_count = 0;
+	const char *core_clk = "core";
+	const char *ctrl_clk = "ctrl";
+	const char *clk_name;
+	struct device *dev = &parser->pdev->dev;
+	struct dss_module_power *core_power = &parser->mp[DP_CORE_PM];
+	struct dss_module_power *ctrl_power = &parser->mp[DP_CTRL_PM];
+

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +10 -0
+	num_clk = of_property_count_strings(dev->of_node, "clock-names");
+	if (num_clk <= 0) {
+		pr_err("no clocks are defined\n");
+		rc = -EINVAL;
+		goto exit;
+	}
+
+	for (i = 0; i < num_clk; i++) {
+		of_property_read_string_index(dev->of_node,
+				"clock-names", i, &clk_name);

Check return value

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +6 -0
+
+		if (dp_parser_check_prefix(core_clk, clk_name))
+			core_clk_count++;
+
+		if (dp_parser_check_prefix(ctrl_clk, clk_name))
+			ctrl_clk_count++;

Just use "core"/"ctrl" directly here.

Quoted 7 lines
Quoted 3 lines

Have you considered just having 2 clock lists? That would avoid having to do
this.

I am not clear on what you are suggesting? We currently have two clock-lists (core & ctrl).

I meant in the dt bindings. Instead of one clocks list, could you split into core and ctrl? That way you wouldn't have to parse based on name.

/snip

Quoted 13 lines
Quoted 2 lines

---- START hmmmm

I didn't understand, can you please provide more details regarding "START" and "END".

Quoted 9 lines

drivers/gpu/drm/msm/dp/dp_aux.h

Quoted 6 lines
drivers/gpu/drm/msm/dp/dp_aux.h new file +5 -0
+	struct dss_module_power *core_power = &parser->mp[DP_CORE_PM];
+	struct dss_module_power *ctrl_power = &parser->mp[DP_CTRL_PM];
+
+	core_power = &parser->mp[DP_CORE_PM];
+	ctrl_power = &parser->mp[DP_CTRL_PM];

---- END hmmmm

You assign core_power and ctrl_power in the declaration and then immediately assign the value again.

/snip

Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno