Skip to contentSkip to conversation

drm/msm/dsi: add a helper method to compute the dsi byte clk

PATCH In review Abhinav Kumar 2 participants 17 messages Sep 22, 2022 – Jan 10, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/msm/dsi: add a helper method to compute the dsi byte clk

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
 drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++
 drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------
 2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
 int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
 void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
 void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+		const struct drm_display_mode *mode);
 int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
 int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
 void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
drivers/gpu/drm/msm/dsi/dsi_host.c +19 -8
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host)
 	clk_disable_unprepare(msm_host->byte_clk);
 }
 
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode, bool is_bonded_dsi)
 {
-	struct drm_display_mode *mode = msm_host->mode;
 	unsigned long pclk_rate;
 
 	pclk_rate = mode->clock * 1000;
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bo
 	return pclk_rate;
 }
 
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+		const struct drm_display_mode *mode)
 {
+	struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
 	u8 lanes = msm_host->lanes;
 	u32 bpp = dsi_get_bpp(msm_host->format);
-	unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-	u64 pclk_bpp = (u64)pclk_rate * bpp;
+	unsigned long pclk_rate;
+	u64 pclk_bpp;
+
+	pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+	pclk_bpp = (u64)pclk_rate * bpp;
 
 	if (lanes == 0) {
 		pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 	else
 		do_div(pclk_bpp, (8 * lanes));
 
-	msm_host->pixel_clk_rate = pclk_rate;
-	msm_host->byte_clk_rate = pclk_bpp;
+	return pclk_bpp;
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+{
+	msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+	msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+			msm_host->mode);
 
 	DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate,
 				msm_host->byte_clk_rate);
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 
 	dsi_calc_pclk(msm_host, is_bonded_dsi);
 
-	pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+	pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi) * bpp;
 	do_div(pclk_bpp, 8);
 	msm_host->src_clk_rate = pclk_bpp;
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 drm/msm/dsi: implement opp table based check for dsi_mgr_bridge_mode_valid()

Currently there is no protection against a user trying to set an unsupported mode on DSI. Implement a check based on the opp table whether the byte clock for the mode can be supported by validating whether an opp table entry exists.

For devices which have not added opp table support yet, skip this check otherwise it will break bootup on those devices.

---
 drivers/gpu/drm/msm/dsi/dsi_manager.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_manager.c +23 -0
index 3a1417397283..87b518c42965 100644
@@ -450,6 +450,29 @@ static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
 	int id = dsi_mgr_bridge_get_id(bridge);
 	struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
 	struct mipi_dsi_host *host = msm_dsi->host;
+	struct platform_device *pdev = msm_dsi->pdev;
+	struct dev_pm_opp *opp;
+	struct opp_table *opp_tbl;
+	unsigned long byte_clk_rate;
+
+	byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), mode);
+
+	/*
+	 * first check if there is an opp table available for the calculated
+	 * byte clock and then check DSC related info. Some devices have not
+	 * added support for OPP table. Skip the check for those.
+	 */
+	opp_tbl = dev_pm_opp_get_opp_table(&pdev->dev);
+	if (opp_tbl) {
+		opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate);
+		if (IS_ERR(opp)) {
+			pr_err("opp table not found for freq %lu err: %ld\n",
+					byte_clk_rate, PTR_ERR(opp));
+			return PTR_ERR(opp);
+		}
+		dev_pm_opp_put(opp);
+		dev_pm_opp_put_opp_table(opp_tbl);
+	}
 
 	return msm_dsi_host_check_dsc(host, mode);
 }
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 2/2] drm/msm/dsi: implement opp table based check for dsi_mgr_bridge_mode_valid()

Quoted 26 lines · Abhinav Kumar

Currently there is no protection against a user trying to set an unsupported mode on DSI. Implement a check based on the opp table whether the byte clock for the mode can be supported by validating whether an opp table entry exists.

For devices which have not added opp table support yet, skip this check otherwise it will break bootup on those devices.

---
  drivers/gpu/drm/msm/dsi/dsi_manager.c | 23 +++++++++++++++++++++++
  1 file changed, 23 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_manager.c +3 -0
index 3a1417397283..87b518c42965 100644
@@ -450,6 +450,29 @@ static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
  	int id = dsi_mgr_bridge_get_id(bridge);
  	struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
  	struct mipi_dsi_host *host = msm_dsi->host;
+	struct platform_device *pdev = msm_dsi->pdev;
+	struct dev_pm_opp *opp;
+	struct opp_table *opp_tbl;

drivers/gpu/drm/msm/dsi/dsi_manager.c static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge, · line 465

Quoted 10 lines
drivers/gpu/drm/msm/dsi/dsi_manager.c +10 -0
+	unsigned long byte_clk_rate;
+
+	byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), mode);
+
+	/*
+	 * first check if there is an opp table available for the calculated
+	 * byte clock and then check DSC related info. Some devices have not
+	 * added support for OPP table. Skip the check for those.
+	 */
+	opp_tbl = dev_pm_opp_get_opp_table(&pdev->dev);

Can we store the table inside the msm_dsi during the init? Then we won't have to get it again and again during each mode_valid call.

Quoted 13 lines
drivers/gpu/drm/msm/dsi/dsi_manager.c +10 -0
+	if (opp_tbl) {
+		opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate);
+		if (IS_ERR(opp)) {
+			pr_err("opp table not found for freq %lu err: %ld\n",
+					byte_clk_rate, PTR_ERR(opp));
+			return PTR_ERR(opp);
+		}
+		dev_pm_opp_put(opp);
+		dev_pm_opp_put_opp_table(opp_tbl);
+	}
 
  	return msm_dsi_host_check_dsc(host, mode);
  }
Signature · 2 lines
With best wishes
Dmitry
#3 lore raw

Re: [PATCH 2/2] drm/msm/dsi: implement opp table based check for dsi_mgr_bridge_mode_valid()

Quoted 32 lines · Dmitry Baryshkov
Quoted 31 lines · Abhinav Kumar

Currently there is no protection against a user trying to set an unsupported mode on DSI. Implement a check based on the opp table whether the byte clock for the mode can be supported by validating whether an opp table entry exists.

For devices which have not added opp table support yet, skip this check otherwise it will break bootup on those devices.

---
  drivers/gpu/drm/msm/dsi/dsi_manager.c | 23 +++++++++++++++++++++++

  1 file changed, 23 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_manager.c +7 -0
index 3a1417397283..87b518c42965 100644
@@ -450,6 +450,29 @@ static enum drm_mode_status 
 dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
       int id = dsi_mgr_bridge_get_id(bridge);
       struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
       struct mipi_dsi_host *host = msm_dsi->host;
+    struct platform_device *pdev = msm_dsi->pdev;
+    struct dev_pm_opp *opp;
+    struct opp_table *opp_tbl;
+    unsigned long byte_clk_rate;
+
+    byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), mode);
+
Quoted 8 lines

drivers/gpu/drm/msm/dsi/dsi_manager.c static enum drm_mode_status dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge, · line 465

Quoted 6 lines
drivers/gpu/drm/msm/dsi/dsi_manager.c +6 -0
+    /*
+     * first check if there is an opp table available for the calculated
+     * byte clock and then check DSC related info. Some devices have not
+     * added support for OPP table. Skip the check for those.
+     */
+    opp_tbl = dev_pm_opp_get_opp_table(&pdev->dev);

Can we store the table inside the msm_dsi during the init? Then we won't have to get it again and again during each mode_valid call.

I checked other drivers. I think we can skip the get_opp_table completely, can we not? Just handle ENODEV returned from dev_pm_opp_find_freq_ceil().

Quoted 14 lines
Quoted 13 lines
drivers/gpu/drm/msm/dsi/dsi_manager.c +10 -0
+    if (opp_tbl) {
+        opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate);
+        if (IS_ERR(opp)) {
+            pr_err("opp table not found for freq %lu err: %ld\n",
+                    byte_clk_rate, PTR_ERR(opp));
+            return PTR_ERR(opp);
+        }
+        dev_pm_opp_put(opp);
+        dev_pm_opp_put_opp_table(opp_tbl);
+    }
       return msm_dsi_host_check_dsc(host, mode);
   }
Signature · 2 lines
With best wishes
Dmitry
#4 lore raw

Re: [PATCH 2/2] drm/msm/dsi: implement opp table based check for dsi_mgr_bridge_mode_valid()

Quoted 44 lines · Dmitry Baryshkov
Quoted 34 lines · Dmitry Baryshkov
Quoted 33 lines · Abhinav Kumar

Currently there is no protection against a user trying to set an unsupported mode on DSI. Implement a check based on the opp table whether the byte clock for the mode can be supported by validating whether an opp table entry exists.

For devices which have not added opp table support yet, skip this check otherwise it will break bootup on those devices.

---
  drivers/gpu/drm/msm/dsi/dsi_manager.c | 23 +++++++++++++++++++++++

  1 file changed, 23 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_manager.c +9 -0
index 3a1417397283..87b518c42965 100644
@@ -450,6 +450,29 @@ static enum drm_mode_status 
 dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
       int id = dsi_mgr_bridge_get_id(bridge);
       struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
       struct mipi_dsi_host *host = msm_dsi->host;
+    struct platform_device *pdev = msm_dsi->pdev;
+    struct dev_pm_opp *opp;
+    struct opp_table *opp_tbl;
+    unsigned long byte_clk_rate;
+
+    byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), mode);
+
+    /*
+     * first check if there is an opp table available for the 
Quoted 8 lines
Quoted 6 lines

calculated
+     * byte clock and then check DSC related info. Some devices have not
+     * added support for OPP table. Skip the check for those. +     */
+    opp_tbl = dev_pm_opp_get_opp_table(&pdev->dev);

Can we store the table inside the msm_dsi during the init? Then we won't have to get it again and again during each mode_valid call.

Quoted 2 lines

I checked other drivers. I think we can skip the get_opp_table completely, can we not? Just handle ENODEV returned from dev_pm_opp_find_freq_ceil().

Your point is valid but I had a doubt on that API.

As per the documentation of that API, it says

639  * Return: matching *opp and refreshes *freq accordingly, else returns
640  * ERR_PTR in case of error and should be handled using IS_ERR. Error return
641  * values can be:
642  * EINVAL:	for bad pointer
643  * ERANGE:	no match found for search
644  * ENODEV:	if device not found in list of registered devices
645  *
646  * The callers are required to call dev_pm_opp_put() for the returned OPP after
647  * use.
648  */

649 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
650 unsigned long *freq)
651 {

So ideally yes, ENODEV means that table was not found but .... that API uses _find_opp_table under the hood.

which says

79  * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or
80  * -EINVAL based on type of error.
81  *
82  * The callers must call dev_pm_opp_put_opp_table() after the table is used.

Now, how would we know if the failure was due to table not found OR entry not found.

Table now found means that SOC has probably not started using OPP table which is alright and not an error.

But EINVAL could mean an entry not found which means it exceeds the opp table limits.

So there was some ambiguity on this. So I broke it down into two calls.

If my concern is invalid, let me know.

But I do agree with you that we can cache the opp table once rather than doing it in every mode_valid().

Quoted 15 lines
Quoted 14 lines
Quoted 13 lines

+    if (opp_tbl) {
+        opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate); +        if (IS_ERR(opp)) {
+            pr_err("opp table not found for freq %lu err: %ld\n", +                    byte_clk_rate, PTR_ERR(opp));
+            return PTR_ERR(opp);
+        }
+        dev_pm_opp_put(opp);
+        dev_pm_opp_put_opp_table(opp_tbl);
+    }
      return msm_dsi_host_check_dsc(host, mode);
  }

#5 lore raw

Re: [PATCH 2/2] drm/msm/dsi: implement opp table based check for dsi_mgr_bridge_mode_valid()

Quoted 78 lines · Abhinav Kumar
Quoted 45 lines · Dmitry Baryshkov
Quoted 35 lines · Dmitry Baryshkov
Quoted 34 lines · Abhinav Kumar

Currently there is no protection against a user trying to set an unsupported mode on DSI. Implement a check based on the opp table whether the byte clock for the mode can be supported by validating whether an opp table entry exists.

For devices which have not added opp table support yet, skip this check otherwise it will break bootup on those devices.

---
  drivers/gpu/drm/msm/dsi/dsi_manager.c | 23 +++++++++++++++++++++++

  1 file changed, 23 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_manager.c +9 -0
index 3a1417397283..87b518c42965 100644
@@ -450,6 +450,29 @@ static enum drm_mode_status 
 dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
       int id = dsi_mgr_bridge_get_id(bridge);
       struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
       struct mipi_dsi_host *host = msm_dsi->host;
+    struct platform_device *pdev = msm_dsi->pdev;
+    struct dev_pm_opp *opp;
+    struct opp_table *opp_tbl;
+    unsigned long byte_clk_rate;
+
+    byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), 
 mode);
+
+    /*
+     * first check if there is an opp table available for the 
Quoted 8 lines
Quoted 6 lines

calculated
+     * byte clock and then check DSC related info. Some devices have not
+     * added support for OPP table. Skip the check for those. +     */
+    opp_tbl = dev_pm_opp_get_opp_table(&pdev->dev);

Can we store the table inside the msm_dsi during the init? Then we won't have to get it again and again during each mode_valid call.

Quoted 2 lines

I checked other drivers. I think we can skip the get_opp_table completely, can we not? Just handle ENODEV returned from dev_pm_opp_find_freq_ceil().

Your point is valid but I had a doubt on that API.

As per the documentation of that API, it says

639  * Return: matching *opp and refreshes *freq accordingly, else returns 640  * ERR_PTR in case of error and should be handled using IS_ERR. Error return 641  * values can be:
642  * EINVAL:    for bad pointer
643  * ERANGE:    no match found for search
644  * ENODEV:    if device not found in list of registered devices 645  *
646  * The callers are required to call dev_pm_opp_put() for the returned OPP after 647  * use.
648  */
649 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, 650                          unsigned long *freq)
651 {

So ideally yes, ENODEV means that table was not found but .... that API uses _find_opp_table under the hood.

which says

79  * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or 80  * -EINVAL based on type of error.
81  *
82  * The callers must call dev_pm_opp_put_opp_table() after the table is used.

Quoted 5 lines

Now, how would we know if the failure was due to table not found OR entry not found.

Table now found means that SOC has probably not started using OPP table which is alright and not an error.

But EINVAL could mean an entry not found which means it exceeds the opp table limits.

I think this would be -ERANGE as documented.

EINVAL means dev is null or something of the same kind.

Quoted 22 lines

So there was some ambiguity on this. So I broke it down into two calls.

If my concern is invalid, let me know.

But I do agree with you that we can cache the opp table once rather than doing it in every mode_valid().

Quoted 15 lines
Quoted 14 lines
Quoted 13 lines

+    if (opp_tbl) {
+        opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate); +        if (IS_ERR(opp)) {
+            pr_err("opp table not found for freq %lu err: %ld\n", +                    byte_clk_rate, PTR_ERR(opp));
+            return PTR_ERR(opp);
+        }
+        dev_pm_opp_put(opp);
+        dev_pm_opp_put_opp_table(opp_tbl);
+    }
      return msm_dsi_host_check_dsc(host, mode);
  }

Signature · 2 lines
With best wishes
Dmitry
#6 lore raw

Re: [PATCH 2/2] drm/msm/dsi: implement opp table based check for dsi_mgr_bridge_mode_valid()

Quoted 82 lines · Dmitry Baryshkov
Quoted 81 lines · Abhinav Kumar
Quoted 45 lines · Dmitry Baryshkov
Quoted 35 lines · Dmitry Baryshkov
Quoted 34 lines · Abhinav Kumar

Currently there is no protection against a user trying to set an unsupported mode on DSI. Implement a check based on the opp table whether the byte clock for the mode can be supported by validating whether an opp table entry exists.

For devices which have not added opp table support yet, skip this check otherwise it will break bootup on those devices.

---
  drivers/gpu/drm/msm/dsi/dsi_manager.c | 23 +++++++++++++++++++++++

  1 file changed, 23 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_manager.c +9 -0
index 3a1417397283..87b518c42965 100644
@@ -450,6 +450,29 @@ static enum drm_mode_status 
 dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
       int id = dsi_mgr_bridge_get_id(bridge);
       struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
       struct mipi_dsi_host *host = msm_dsi->host;
+    struct platform_device *pdev = msm_dsi->pdev;
+    struct dev_pm_opp *opp;
+    struct opp_table *opp_tbl;
+    unsigned long byte_clk_rate;
+
+    byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), 
 mode);
+
+    /*
+     * first check if there is an opp table available for the 
Quoted 8 lines
Quoted 6 lines

calculated
+     * byte clock and then check DSC related info. Some devices have not
+     * added support for OPP table. Skip the check for those. +     */
+    opp_tbl = dev_pm_opp_get_opp_table(&pdev->dev);

Can we store the table inside the msm_dsi during the init? Then we won't have to get it again and again during each mode_valid call.

Quoted 2 lines

I checked other drivers. I think we can skip the get_opp_table completely, can we not? Just handle ENODEV returned from dev_pm_opp_find_freq_ceil().

Your point is valid but I had a doubt on that API.

As per the documentation of that API, it says

639  * Return: matching *opp and refreshes *freq accordingly, else returns 640  * ERR_PTR in case of error and should be handled using IS_ERR. Error return 641  * values can be:
642  * EINVAL:    for bad pointer
643  * ERANGE:    no match found for search
644  * ENODEV:    if device not found in list of registered devices 645  *
646  * The callers are required to call dev_pm_opp_put() for the returned OPP after 647  * use.
648  */
649 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, 650                          unsigned long *freq)
651 {

So ideally yes, ENODEV means that table was not found but .... that API uses _find_opp_table under the hood.

which says

79  * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or
80  * -EINVAL based on type of error.
81  *
82  * The callers must call dev_pm_opp_put_opp_table() after the table is used.

Now, how would we know if the failure was due to table not found OR entry not found.

Quoted 8 lines
Quoted 3 lines

Table now found means that SOC has probably not started using OPP table which is alright and not an error.

But EINVAL could mean an entry not found which means it exceeds the opp table limits.

I think this would be -ERANGE as documented.

EINVAL means dev is null or something of the same kind.

Okay, so EINVAL and ERANGE are genuine errors but ENODEV is not in our case as all SOCs might not have opp table yet.

Do you still think selective handling of these two errors is better than the current implementation? That way its separation is clear.

Quoted 23 lines
Quoted 22 lines

So there was some ambiguity on this. So I broke it down into two calls.

If my concern is invalid, let me know.

But I do agree with you that we can cache the opp table once rather than doing it in every mode_valid().

Quoted 15 lines
Quoted 14 lines
Quoted 13 lines

+    if (opp_tbl) {
+        opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate); +        if (IS_ERR(opp)) {
+            pr_err("opp table not found for freq %lu err: %ld\n", +                    byte_clk_rate, PTR_ERR(opp));
+            return PTR_ERR(opp);
+        }
+        dev_pm_opp_put(opp);
+        dev_pm_opp_put_opp_table(opp_tbl);
+    }
      return msm_dsi_host_check_dsc(host, mode);
  }

#7 lore raw

Re: [PATCH 2/2] drm/msm/dsi: implement opp table based check for dsi_mgr_bridge_mode_valid()

Quoted 89 lines · Abhinav Kumar
Quoted 86 lines · Dmitry Baryshkov
Quoted 84 lines · Abhinav Kumar
Quoted 45 lines · Dmitry Baryshkov
Quoted 35 lines · Dmitry Baryshkov
Quoted 34 lines · Abhinav Kumar

Currently there is no protection against a user trying to set an unsupported mode on DSI. Implement a check based on the opp table whether the byte clock for the mode can be supported by validating whether an opp table entry exists.

For devices which have not added opp table support yet, skip this check otherwise it will break bootup on those devices.

---
  drivers/gpu/drm/msm/dsi/dsi_manager.c | 23 +++++++++++++++++++++++

  1 file changed, 23 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_manager.c +9 -0
index 3a1417397283..87b518c42965 100644
@@ -450,6 +450,29 @@ static enum drm_mode_status 
 dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
       int id = dsi_mgr_bridge_get_id(bridge);
       struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
       struct mipi_dsi_host *host = msm_dsi->host;
+    struct platform_device *pdev = msm_dsi->pdev;
+    struct dev_pm_opp *opp;
+    struct opp_table *opp_tbl;
+    unsigned long byte_clk_rate;
+
+    byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), 
 mode);
+
+    /*
+     * first check if there is an opp table available for the 
Quoted 8 lines
Quoted 6 lines

calculated
+     * byte clock and then check DSC related info. Some devices have not
+     * added support for OPP table. Skip the check for those. +     */
+    opp_tbl = dev_pm_opp_get_opp_table(&pdev->dev);

Can we store the table inside the msm_dsi during the init? Then we won't have to get it again and again during each mode_valid call.

Quoted 2 lines

I checked other drivers. I think we can skip the get_opp_table completely, can we not? Just handle ENODEV returned from dev_pm_opp_find_freq_ceil().

Your point is valid but I had a doubt on that API.

As per the documentation of that API, it says

639  * Return: matching *opp and refreshes *freq accordingly, else returns 640  * ERR_PTR in case of error and should be handled using IS_ERR. Error return 641  * values can be:
642  * EINVAL:    for bad pointer
643  * ERANGE:    no match found for search
644  * ENODEV:    if device not found in list of registered devices 645  *
646  * The callers are required to call dev_pm_opp_put() for the returned OPP after 647  * use.
648  */
649 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, 650                          unsigned long *freq)
651 {

So ideally yes, ENODEV means that table was not found but .... that API uses _find_opp_table under the hood.

which says

79  * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or
80  * -EINVAL based on type of error.
81  *
82  * The callers must call dev_pm_opp_put_opp_table() after the table is used.

Now, how would we know if the failure was due to table not found OR entry not found.

Table now found means that SOC has probably not started using OPP table which is alright and not an error.

But EINVAL could mean an entry not found which means it exceeds the opp table limits.

Quoted 8 lines
Quoted 4 lines

I think this would be -ERANGE as documented.

EINVAL means dev is null or something of the same kind.

Okay, so EINVAL and ERANGE are genuine errors but ENODEV is not in our case as all SOCs might not have opp table yet.

Do you still think selective handling of these two errors is better than the current implementation? That way its separation is clear.

I think that we should drop the opp_table handling. Then select basing on the returned error:
ERANGE => MODE_CLOCK_HIGH
EINVAL and any other error => MODE_ERROR ENODEV => skip the check, continue with dsc

See below.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

So there was some ambiguity on this. So I broke it down into two calls.

If my concern is invalid, let me know.

But I do agree with you that we can cache the opp table once rather than doing it in every mode_valid().

Quoted 1 line
Quoted 1 line
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+    if (opp_tbl) {
+        opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate); +        if (IS_ERR(opp)) {
+            pr_err("opp table not found for freq %lu err: %ld\n", +                    byte_clk_rate, PTR_ERR(opp));
+            return PTR_ERR(opp);

Note: mode_valid returns enum drm_mode_status, so we can not return PTR_ERR here.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

+        }
+        dev_pm_opp_put(opp);
+        dev_pm_opp_put_opp_table(opp_tbl);
+    }
      return msm_dsi_host_check_dsc(host, mode);
  }

Signature · 2 lines
With best wishes
Dmitry
#8 lore raw

Re: [PATCH 2/2] drm/msm/dsi: implement opp table based check for dsi_mgr_bridge_mode_valid()

Quoted 99 lines · Dmitry Baryshkov
Quoted 89 lines · Abhinav Kumar
Quoted 86 lines · Dmitry Baryshkov
Quoted 84 lines · Abhinav Kumar
Quoted 45 lines · Dmitry Baryshkov
Quoted 35 lines · Dmitry Baryshkov
Quoted 34 lines · Abhinav Kumar

Currently there is no protection against a user trying to set an unsupported mode on DSI. Implement a check based on the opp table whether the byte clock for the mode can be supported by validating whether an opp table entry exists.

For devices which have not added opp table support yet, skip this check otherwise it will break bootup on those devices.

---
  drivers/gpu/drm/msm/dsi/dsi_manager.c | 23 +++++++++++++++++++++++

  1 file changed, 23 insertions(+)
drivers/gpu/drm/msm/dsi/dsi_manager.c +9 -0
index 3a1417397283..87b518c42965 100644
@@ -450,6 +450,29 @@ static enum drm_mode_status 
 dsi_mgr_bridge_mode_valid(struct drm_bridge *bridge,
       int id = dsi_mgr_bridge_get_id(bridge);
       struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
       struct mipi_dsi_host *host = msm_dsi->host;
+    struct platform_device *pdev = msm_dsi->pdev;
+    struct dev_pm_opp *opp;
+    struct opp_table *opp_tbl;
+    unsigned long byte_clk_rate;
+
+    byte_clk_rate = dsi_byte_clk_get_rate(host, IS_BONDED_DSI(), 
 mode);
+
+    /*
+     * first check if there is an opp table available for the 
Quoted 8 lines
Quoted 6 lines

calculated
+     * byte clock and then check DSC related info. Some devices have not
+     * added support for OPP table. Skip the check for those. +     */
+    opp_tbl = dev_pm_opp_get_opp_table(&pdev->dev);

Can we store the table inside the msm_dsi during the init? Then we won't have to get it again and again during each mode_valid call.

Quoted 2 lines

I checked other drivers. I think we can skip the get_opp_table completely, can we not? Just handle ENODEV returned from dev_pm_opp_find_freq_ceil().

Your point is valid but I had a doubt on that API.

As per the documentation of that API, it says

639  * Return: matching *opp and refreshes *freq accordingly, else returns 640  * ERR_PTR in case of error and should be handled using IS_ERR. Error return 641  * values can be:
642  * EINVAL:    for bad pointer
643  * ERANGE:    no match found for search
644  * ENODEV:    if device not found in list of registered devices 645  *
646  * The callers are required to call dev_pm_opp_put() for the returned OPP after 647  * use.
648  */
649 struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, 650                          unsigned long *freq)
651 {

So ideally yes, ENODEV means that table was not found but .... that API uses _find_opp_table under the hood.

which says

79  * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or
80  * -EINVAL based on type of error.
81  *
82  * The callers must call dev_pm_opp_put_opp_table() after the table is used.

Now, how would we know if the failure was due to table not found OR entry not found.

Table now found means that SOC has probably not started using OPP table which is alright and not an error.

But EINVAL could mean an entry not found which means it exceeds the opp table limits.

Quoted 8 lines
Quoted 4 lines

I think this would be -ERANGE as documented.

EINVAL means dev is null or something of the same kind.

Okay, so EINVAL and ERANGE are genuine errors but ENODEV is not in our case as all SOCs might not have opp table yet.

Do you still think selective handling of these two errors is better than the current implementation? That way its separation is clear.

Quoted 8 lines

I think that we should drop the opp_table handling. Then select basing on the returned error:
 ERANGE => MODE_CLOCK_HIGH
 EINVAL and any other error => MODE_ERROR ENODEV => skip the check, continue with dsc

See below.

Ack, lets do it this way.

I am clear now, will spin a v2.

Quoted 29 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

So there was some ambiguity on this. So I broke it down into two calls.

If my concern is invalid, let me know.

But I do agree with you that we can cache the opp table once rather than doing it in every mode_valid().

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

+    if (opp_tbl) {
+        opp = dev_pm_opp_find_freq_ceil(&pdev->dev, &byte_clk_rate);
+        if (IS_ERR(opp)) {
+            pr_err("opp table not found for freq %lu err: %ld\n", +                    byte_clk_rate, PTR_ERR(opp));
+            return PTR_ERR(opp);

Note: mode_valid returns enum drm_mode_status, so we can not return PTR_ERR here.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

+        }
+        dev_pm_opp_put(opp);
+        dev_pm_opp_put_opp_table(opp_tbl);
+    }
      return msm_dsi_host_check_dsc(host, mode);
  }

#9 lore raw
In reply to Abhinav Kumar
Quoted 66 lines · Abhinav Kumar

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
  drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++
  drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------
  2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
  int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
  void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
  void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+		const struct drm_display_mode *mode);
  int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
  int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
  void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
drivers/gpu/drm/msm/dsi/dsi_host.c +10 -5
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host)
  	clk_disable_unprepare(msm_host->byte_clk);
  }
 
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode, bool is_bonded_dsi)
  {
-	struct drm_display_mode *mode = msm_host->mode;
  	unsigned long pclk_rate;
 
  	pclk_rate = mode->clock * 1000;
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bo
  	return pclk_rate;
  }
 
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+		const struct drm_display_mode *mode)
  {
+	struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  	u8 lanes = msm_host->lanes;
  	u32 bpp = dsi_get_bpp(msm_host->format);
-	unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-	u64 pclk_bpp = (u64)pclk_rate * bpp;
+	unsigned long pclk_rate;
+	u64 pclk_bpp;
+
+	pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+	pclk_bpp = (u64)pclk_rate * bpp;
 
  	if (lanes == 0) {
  		pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
  	else
  		do_div(pclk_bpp, (8 * lanes));
 

drivers/gpu/drm/msm/dsi/dsi_host.c static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi) · line 621

Quoted 10 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +8 -2
-	msm_host->pixel_clk_rate = pclk_rate;
-	msm_host->byte_clk_rate = pclk_bpp;
+	return pclk_bpp;
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+{
+	msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+	msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+			msm_host->mode);

This way you are calling dsi_get_pclk_rate twice(), which is slightly inefficient. You can call it once (here) and then pass the resulting pclk_rate as an argument to dsi_byte_clk_get_rate().

drivers/gpu/drm/msm/dsi/dsi_host.c int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi) · line 649

Quoted 9 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
  	DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate,
  				msm_host->byte_clk_rate);
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 
  	dsi_calc_pclk(msm_host, is_bonded_dsi);
 
-	pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+	pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi) * bpp;

So... We have calculated all rates, stored the pclk_rate in msm_host->pixel_clk_rate. And now we are going to calculate it again. As you are touching this line of code, I'd suggest to just use msm_host->pixel_clk_rate instead of a function call.

Quoted 3 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
  	do_div(pclk_bpp, 8);
  	msm_host->src_clk_rate = pclk_bpp;
 
Signature · 2 lines
With best wishes
Dmitry
#10 lore raw
Quoted 79 lines · Dmitry Baryshkov
Quoted 78 lines · Abhinav Kumar

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
  drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++ drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------

  2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host 
 *msm_host);
   int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool 
 is_bonded_dsi,
+        const struct drm_display_mode *mode);
   int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);

  int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size); void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -2
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host 
 *msm_host)
       clk_disable_unprepare(msm_host->byte_clk);
   }
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, 
 bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct drm_display_mode 
 *mode, bool is_bonded_dsi)
   {
-    struct drm_display_mode *mode = msm_host->mode;
       unsigned long pclk_rate;

      pclk_rate = mode->clock * 1000;

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct 

msm_dsi_host *msm_host, bool is_bo
      return pclk_rate;
  }
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+        const struct drm_display_mode *mode)
  {
+    struct msm_dsi_host *msm_host = to_msm_dsi_host(host); u8 lanes = msm_host->lanes;
      u32 bpp = dsi_get_bpp(msm_host->format);
-    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-    u64 pclk_bpp = (u64)pclk_rate * bpp;
+    unsigned long pclk_rate;
+    u64 pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +4 -0
+
+    pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+    pclk_bpp = (u64)pclk_rate * bpp;

      if (lanes == 0) {
          pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)

      else
          do_div(pclk_bpp, (8 * lanes));
-    msm_host->pixel_clk_rate = pclk_rate;
-    msm_host->byte_clk_rate = pclk_bpp;
+    return pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +3 -0
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool 

is_bonded_dsi)

Quoted 8 lines
Quoted 6 lines

+{
+    msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+    msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+            msm_host->mode);

This way you are calling dsi_get_pclk_rate twice(), which is slightly inefficient. You can call it once (here) and then pass the resulting pclk_rate as an argument to dsi_byte_clk_get_rate().

So the goal was to have two independent APIs to calculate byte and pixel clk.

If we pass the output of one as the input to the other we are making them dependent.

Thats why i kept it separate.

Quoted 11 lines

drivers/gpu/drm/msm/dsi/dsi_host.c int dsi_calc_clk_rate_v2(struct msm_dsi_host · line 649

Quoted 9 lines

      DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate, msm_host->byte_clk_rate);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
       dsi_calc_pclk(msm_host, is_bonded_dsi);
-    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi) 
 * bpp;

So... We have calculated all rates, stored the pclk_rate in msm_host->pixel_clk_rate. And now we are going to calculate it again. As you are touching this line of code, I'd suggest to just use msm_host->pixel_clk_rate instead of a function call.

Ack, I will fix this.

Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
       do_div(pclk_bpp, 8);
       msm_host->src_clk_rate = pclk_bpp;
#11 lore raw
Quoted 91 lines · Abhinav Kumar
Quoted 79 lines · Dmitry Baryshkov
Quoted 78 lines · Abhinav Kumar

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
  drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++ drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------

  2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host 
 *msm_host);
   int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool 
 is_bonded_dsi,
+        const struct drm_display_mode *mode);
   int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);

  int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size); void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -2
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host 
 *msm_host)
       clk_disable_unprepare(msm_host->byte_clk);
   }
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct drm_display_mode 
 *mode, bool is_bonded_dsi)
   {
-    struct drm_display_mode *mode = msm_host->mode;
       unsigned long pclk_rate;

      pclk_rate = mode->clock * 1000;

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct 

msm_dsi_host *msm_host, bool is_bo
      return pclk_rate;
  }
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+        const struct drm_display_mode *mode)
  {
+    struct msm_dsi_host *msm_host = to_msm_dsi_host(host); u8 lanes = msm_host->lanes;
      u32 bpp = dsi_get_bpp(msm_host->format);
-    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-    u64 pclk_bpp = (u64)pclk_rate * bpp;
+    unsigned long pclk_rate;
+    u64 pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +4 -0
+
+    pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+    pclk_bpp = (u64)pclk_rate * bpp;

      if (lanes == 0) {
          pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)

      else
          do_div(pclk_bpp, (8 * lanes));
-    msm_host->pixel_clk_rate = pclk_rate;
-    msm_host->byte_clk_rate = pclk_bpp;
+    return pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +3 -0
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool 

is_bonded_dsi)

Quoted 8 lines
Quoted 6 lines

+{
+    msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+    msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+            msm_host->mode);

This way you are calling dsi_get_pclk_rate twice(), which is slightly inefficient. You can call it once (here) and then pass the resulting pclk_rate as an argument to dsi_byte_clk_get_rate().

Quoted 5 lines

So the goal was to have two independent APIs to calculate byte and pixel clk.

If we pass the output of one as the input to the other we are making them dependent.

Thats why i kept it separate.

Calling one function from another clearly points that they are not independent. And surely pixel and byte clocks can not be fully independent. I see your point about getting only the byte clock. But I think it would be easier to explicitly pass the pixel rate rather than calculating it again under the hood.

Quoted 19 lines
Quoted 12 lines

drivers/gpu/drm/msm/dsi/dsi_host.c int dsi_calc_clk_rate_v2(struct msm_dsi_host · line 649

Quoted 10 lines

      DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate, msm_host->byte_clk_rate);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
       dsi_calc_pclk(msm_host, is_bonded_dsi);
-    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi) 
 * bpp;

So... We have calculated all rates, stored the pclk_rate in msm_host->pixel_clk_rate. And now we are going to calculate it again. As you are touching this line of code, I'd suggest to just use msm_host->pixel_clk_rate instead of a function call.

Ack, I will fix this.

Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
       do_div(pclk_bpp, 8);
       msm_host->src_clk_rate = pclk_bpp;
Signature · 2 lines
With best wishes
Dmitry
#12 lore raw

Hi Dmitry

Sorry for the late response.

Quoted 92 lines · Dmitry Baryshkov
Quoted 91 lines · Abhinav Kumar
Quoted 87 lines · Dmitry Baryshkov
Quoted 77 lines · Abhinav Kumar

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
  drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++ drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------

  2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host 
 *msm_host);
   int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, 
 bool is_bonded_dsi,
+        const struct drm_display_mode *mode);
   int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);

  int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size); void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -2
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host 
 *msm_host)
       clk_disable_unprepare(msm_host->byte_clk);
   }
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct 
 drm_display_mode *mode, bool is_bonded_dsi)
   {
-    struct drm_display_mode *mode = msm_host->mode;
       unsigned long pclk_rate;

      pclk_rate = mode->clock * 1000;

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct 

msm_dsi_host *msm_host, bool is_bo
      return pclk_rate;
  }
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+        const struct drm_display_mode *mode)
  {
+    struct msm_dsi_host *msm_host = to_msm_dsi_host(host); u8 lanes = msm_host->lanes;
      u32 bpp = dsi_get_bpp(msm_host->format);
-    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-    u64 pclk_bpp = (u64)pclk_rate * bpp;
+    unsigned long pclk_rate;
+    u64 pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +4 -0
+
+    pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+    pclk_bpp = (u64)pclk_rate * bpp;

      if (lanes == 0) {
          pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)

      else
          do_div(pclk_bpp, (8 * lanes));
-    msm_host->pixel_clk_rate = pclk_rate;
-    msm_host->byte_clk_rate = pclk_bpp;
+    return pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +3 -0
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool 
Quoted 7 lines

is_bonded_dsi)
+{
+    msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+    msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+            msm_host->mode);

This way you are calling dsi_get_pclk_rate twice(), which is slightly inefficient. You can call it once (here) and then pass the resulting pclk_rate as an argument to dsi_byte_clk_get_rate().

Quoted 8 lines
Quoted 5 lines

So the goal was to have two independent APIs to calculate byte and pixel clk.

If we pass the output of one as the input to the other we are making them dependent.

Thats why i kept it separate.

Calling one function from another clearly points that they are not independent. And surely pixel and byte clocks can not be fully independent. I see your point about getting only the byte clock. But I think it would be easier to explicitly pass the pixel rate rather than calculating it again under the hood.

Yes, calling one function from another means they are dependent and thats true in this case because byte clk computation depends on the pclk.

The reason behind this separation was that in the next patch, we need to compute only the byte clock and use that to validate in the mode_valid against the opp table limits.

The opp table for DSI is based on the byte clk.

If we were to pass pclk as a parameter, then we would have to explicitly compute the pclk just to pass the parameter to the method which computes the byte clk. As opposed to this approach, where it just happens under the hood.

So for the purpose of the next patch I kept it this way.

Let me know what you think.

Quoted 20 lines
Quoted 19 lines
Quoted 12 lines

drivers/gpu/drm/msm/dsi/dsi_host.c int dsi_calc_clk_rate_v2(struct msm_dsi_host · line 649

Quoted 10 lines

      DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate, msm_host->byte_clk_rate);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
       dsi_calc_pclk(msm_host, is_bonded_dsi);
-    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, 
 is_bonded_dsi) * bpp;

So... We have calculated all rates, stored the pclk_rate in msm_host->pixel_clk_rate. And now we are going to calculate it again. As you are touching this line of code, I'd suggest to just use msm_host->pixel_clk_rate instead of a function call.

Ack, I will fix this.

Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
       do_div(pclk_bpp, 8);
       msm_host->src_clk_rate = pclk_bpp;
#13 lore raw
In reply to Abhinav Kumar
Quoted 49 lines · Abhinav Kumar

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
  drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++
  drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------
  2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host);
  int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
  void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
  void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+		const struct drm_display_mode *mode);
  int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);
  int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size);
  void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);
drivers/gpu/drm/msm/dsi/dsi_host.c +4 -3
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host)
  	clk_disable_unprepare(msm_host->byte_clk);
  }
 
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode, bool is_bonded_dsi)
  {
-	struct drm_display_mode *mode = msm_host->mode;
  	unsigned long pclk_rate;
 
  	pclk_rate = mode->clock * 1000;
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bo
  	return pclk_rate;
  }
 
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+		const struct drm_display_mode *mode)
  {
+	struct msm_dsi_host *msm_host = to_msm_dsi_host(host);

drivers/gpu/drm/msm/dsi/dsi_host.c static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bo · line 601

Quoted 10 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +6 -2
  	u8 lanes = msm_host->lanes;
  	u32 bpp = dsi_get_bpp(msm_host->format);
-	unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-	u64 pclk_bpp = (u64)pclk_rate * bpp;
+	unsigned long pclk_rate;
+	u64 pclk_bpp;
+
+	pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+	pclk_bpp = (u64)pclk_rate * bpp;

Any particular reason for this? The following patch would be more obvious:

Quoted 26 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
-	unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
+	unsigned long pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
 	u64 pclk_bpp = (u64)pclk_rate * bpp;
 
  
  	if (lanes == 0) {
  		pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);
drivers/gpu/drm/msm/dsi/dsi_host.c +8 -2
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
  	else
  		do_div(pclk_bpp, (8 * lanes));
 
-	msm_host->pixel_clk_rate = pclk_rate;
-	msm_host->byte_clk_rate = pclk_bpp;
+	return pclk_bpp;
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+{
+	msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+	msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+			msm_host->mode);
 
  	DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate,
  				msm_host->byte_clk_rate);

drivers/gpu/drm/msm/dsi/dsi_host.c int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi) · line 651

Quoted 7 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
 
  	dsi_calc_pclk(msm_host, is_bonded_dsi);
 
-	pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+	pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi) * bpp;
  	do_div(pclk_bpp, 8);
  	msm_host->src_clk_rate = pclk_bpp;

Following my previous feedback:

I think at this moment msm_host->src_clk_rate = msm_host->byte_clk_rate * msm_host->lanes. If so, we can drop dsi_get_pclk_rate() call and the multiply/do_div calculation and use the above formula instead.

If this looks logical, could you please prepend a patch changing this?

LGTM otherwise.

Signature · 2 lines
With best wishes
Dmitry
#14 lore raw
Quoted 108 lines · Dmitry Baryshkov
Quoted 61 lines · Abhinav Kumar

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
  drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++ drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------

  2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host 
 *msm_host);
   int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool 
 is_bonded_dsi,
+        const struct drm_display_mode *mode);
   int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);

  int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size); void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -2
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host 
 *msm_host)
       clk_disable_unprepare(msm_host->byte_clk);
   }
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, 
 bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct drm_display_mode 
 *mode, bool is_bonded_dsi)
   {
-    struct drm_display_mode *mode = msm_host->mode;
       unsigned long pclk_rate;

      pclk_rate = mode->clock * 1000;

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct 

msm_dsi_host *msm_host, bool is_bo
      return pclk_rate;
  }
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+        const struct drm_display_mode *mode)
  {
+    struct msm_dsi_host *msm_host = to_msm_dsi_host(host); u8 lanes = msm_host->lanes;
      u32 bpp = dsi_get_bpp(msm_host->format);
-    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-    u64 pclk_bpp = (u64)pclk_rate * bpp;
+    unsigned long pclk_rate;
+    u64 pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bo · line 601

Quoted 4 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +4 -0
+
+    pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+    pclk_bpp = (u64)pclk_rate * bpp;

Any particular reason for this? The following patch would be more obvious:

Quoted 1 line

-    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host,

is_bonded_dsi);

Quoted 26 lines

+    unsigned long pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi); u64 pclk_bpp = (u64)pclk_rate * bpp;

      if (lanes == 0) {
          pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)

      else
          do_div(pclk_bpp, (8 * lanes));
-    msm_host->pixel_clk_rate = pclk_rate;
-    msm_host->byte_clk_rate = pclk_bpp;
+    return pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +3 -0
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool 

is_bonded_dsi)
+{
+    msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+    msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+            msm_host->mode);
      DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate, msm_host->byte_clk_rate);

drivers/gpu/drm/msm/dsi/dsi_host.c int dsi_calc_clk_rate_v2(struct msm_dsi_host · line 651

Quoted 7 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
       dsi_calc_pclk(msm_host, is_bonded_dsi);
-    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi) 
 * bpp;
       do_div(pclk_bpp, 8);
       msm_host->src_clk_rate = pclk_bpp;

Following my previous feedback:

Quoted 2 lines

I think at this moment msm_host->src_clk_rate = msm_host->byte_clk_rate * msm_host->lanes. If so, we can drop dsi_get_pclk_rate() call and the multiply/do_div calculation and use the above formula instead.

From what I see msm_host->src_clk_rate = pixel_clk * bpp / 8;

From where did you get the above formula?

I just felt that by having two APIs the next patch becomes easier because I need to just invoke the API which calculates byte clk.

Quoted 4 lines

If this looks logical, could you please prepend a patch changing this?

LGTM otherwise.

#15 lore raw
Quoted 110 lines · Abhinav Kumar
Quoted 107 lines · Dmitry Baryshkov
Quoted 61 lines · Abhinav Kumar

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
  drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++ drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------

  2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host 
 *msm_host);
   int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool 
 is_bonded_dsi,
+        const struct drm_display_mode *mode);
   int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);

  int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size); void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -2
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host 
 *msm_host)
       clk_disable_unprepare(msm_host->byte_clk);
   }
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct drm_display_mode 
 *mode, bool is_bonded_dsi)
   {
-    struct drm_display_mode *mode = msm_host->mode;
       unsigned long pclk_rate;

      pclk_rate = mode->clock * 1000;

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct 

msm_dsi_host *msm_host, bool is_bo
      return pclk_rate;
  }
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+        const struct drm_display_mode *mode)
  {
+    struct msm_dsi_host *msm_host = to_msm_dsi_host(host); u8 lanes = msm_host->lanes;
      u32 bpp = dsi_get_bpp(msm_host->format);
-    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-    u64 pclk_bpp = (u64)pclk_rate * bpp;
+    unsigned long pclk_rate;
+    u64 pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bo · line 601

Quoted 4 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +4 -0
+
+    pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+    pclk_bpp = (u64)pclk_rate * bpp;

Any particular reason for this? The following patch would be more obvious:

 > -    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi); > +    unsigned long pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi); >      u64 pclk_bpp = (u64)pclk_rate * bpp;

Quoted 22 lines

      if (lanes == 0) {
          pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)

      else
          do_div(pclk_bpp, (8 * lanes));
-    msm_host->pixel_clk_rate = pclk_rate;
-    msm_host->byte_clk_rate = pclk_bpp;
+    return pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +3 -0
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool 

is_bonded_dsi)
+{
+    msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+    msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+            msm_host->mode);
      DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate, msm_host->byte_clk_rate);

drivers/gpu/drm/msm/dsi/dsi_host.c int dsi_calc_clk_rate_v2(struct msm_dsi_host · line 651

Quoted 7 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
       dsi_calc_pclk(msm_host, is_bonded_dsi);
-    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi) 
 * bpp;
       do_div(pclk_bpp, 8);
       msm_host->src_clk_rate = pclk_bpp;

Following my previous feedback:

Quoted 4 lines
Quoted 2 lines

I think at this moment msm_host->src_clk_rate = msm_host->byte_clk_rate * msm_host->lanes. If so, we can drop dsi_get_pclk_rate() call and the multiply/do_div calculation and use the above formula instead.

From what I see msm_host->src_clk_rate = pixel_clk * bpp / 8;

and msm_host->byte_clk_rate = pixel_clk * bpp / (8 * nlanes);

Quoted 4 lines

From where did you get the above formula?

I just felt that by having two APIs the next patch becomes easier because I need to just invoke the API which calculates byte clk.

Yes, I see that, it looks like a correct approach. You know, let's ignore the dsi_calc_clk_rate_v2() for now, it is definitely a separate change.

Could you please drop the opp_table handling from patch 2/2, move assignments in dsi_byte_clk_get_rate() back to the definition lines and then send it as v2?

Signature · 2 lines
With best wishes
Dmitry
#16 lore raw
Quoted 119 lines · Dmitry Baryshkov
Quoted 110 lines · Abhinav Kumar
Quoted 107 lines · Dmitry Baryshkov
Quoted 61 lines · Abhinav Kumar

Re-arrange the dsi_calc_pclk method to two helpers, one to compute the DSI byte clk and the other to compute the pclk.

This makes the separation of the two clean and also allows clients to compute and use the dsi byte clk separately.

---
  drivers/gpu/drm/msm/dsi/dsi.h      |  2 ++ drivers/gpu/drm/msm/dsi/dsi_host.c | 27 +++++++++++++++++++--------

  2 files changed, 21 insertions(+), 8 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +2 -0
index 2a96b4fe7839..60ba8e67f550 100644
@@ -118,6 +118,8 @@ int dsi_link_clk_enable_6g(struct msm_dsi_host 
 *msm_host);
   int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_6g(struct msm_dsi_host *msm_host);
   void dsi_link_clk_disable_v2(struct msm_dsi_host *msm_host);
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, 
 bool is_bonded_dsi,
+        const struct drm_display_mode *mode);
   int dsi_tx_buf_alloc_6g(struct msm_dsi_host *msm_host, int size);

  int dsi_tx_buf_alloc_v2(struct msm_dsi_host *msm_host, int size); void *dsi_tx_buf_get_6g(struct msm_dsi_host *msm_host);

drivers/gpu/drm/msm/dsi/dsi_host.c +1 -2
index 57a4c0fa614b..32b35d4ac1d3 100644
@@ -569,9 +569,8 @@ void dsi_link_clk_disable_v2(struct msm_dsi_host 
 *msm_host)
       clk_disable_unprepare(msm_host->byte_clk);
   }
-static unsigned long dsi_get_pclk_rate(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
+static unsigned long dsi_get_pclk_rate(const struct 
 drm_display_mode *mode, bool is_bonded_dsi)
   {
-    struct drm_display_mode *mode = msm_host->mode;
       unsigned long pclk_rate;

      pclk_rate = mode->clock * 1000;

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -588,12 +587,18 @@ static unsigned long dsi_get_pclk_rate(struct 

msm_dsi_host *msm_host, bool is_bo
      return pclk_rate;
  }
-static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
+unsigned long dsi_byte_clk_get_rate(struct mipi_dsi_host *host, bool is_bonded_dsi,
+        const struct drm_display_mode *mode)
  {
+    struct msm_dsi_host *msm_host = to_msm_dsi_host(host); u8 lanes = msm_host->lanes;
      u32 bpp = dsi_get_bpp(msm_host->format);
-    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi);
-    u64 pclk_bpp = (u64)pclk_rate * bpp;
+    unsigned long pclk_rate;
+    u64 pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c static unsigned long dsi_get_pclk_rate(struct msm_dsi_host *msm_host, bool is_bo · line 601

Quoted 4 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +4 -0
+
+    pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi);
+
+    pclk_bpp = (u64)pclk_rate * bpp;

Any particular reason for this? The following patch would be more obvious:

 > -    unsigned long pclk_rate = dsi_get_pclk_rate(msm_host, is_bonded_dsi); > +    unsigned long pclk_rate = dsi_get_pclk_rate(mode, is_bonded_dsi); >      u64 pclk_bpp = (u64)pclk_rate * bpp;

Quoted 22 lines

      if (lanes == 0) {
          pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);

drivers/gpu/drm/msm/dsi/dsi_host.c +0 -0
@@ -606,8 +611,14 @@ static void dsi_calc_pclk(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)

      else
          do_div(pclk_bpp, (8 * lanes));
-    msm_host->pixel_clk_rate = pclk_rate;
-    msm_host->byte_clk_rate = pclk_bpp;
+    return pclk_bpp;

drivers/gpu/drm/msm/dsi/dsi_host.c +3 -0
+}
+
+static void dsi_calc_pclk(struct msm_dsi_host *msm_host, bool 

is_bonded_dsi)
+{
+    msm_host->pixel_clk_rate = dsi_get_pclk_rate(msm_host->mode, is_bonded_dsi);
+    msm_host->byte_clk_rate = dsi_byte_clk_get_rate(&msm_host->base, is_bonded_dsi,
+            msm_host->mode);
      DBG("pclk=%lu, bclk=%lu", msm_host->pixel_clk_rate, msm_host->byte_clk_rate);

drivers/gpu/drm/msm/dsi/dsi_host.c int dsi_calc_clk_rate_v2(struct msm_dsi_host · line 651

Quoted 7 lines
drivers/gpu/drm/msm/dsi/dsi_host.c +1 -1
@@ -635,7 +646,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host 
 *msm_host, bool is_bonded_dsi)
       dsi_calc_pclk(msm_host, is_bonded_dsi);
-    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host, is_bonded_dsi) * bpp;
+    pclk_bpp = (u64)dsi_get_pclk_rate(msm_host->mode, 
 is_bonded_dsi) * bpp;
       do_div(pclk_bpp, 8);
       msm_host->src_clk_rate = pclk_bpp;

Following my previous feedback:

Quoted 4 lines
Quoted 2 lines

I think at this moment msm_host->src_clk_rate = msm_host->byte_clk_rate * msm_host->lanes. If so, we can drop dsi_get_pclk_rate() call and the multiply/do_div calculation and use the above formula instead.

 From what I see msm_host->src_clk_rate = pixel_clk * bpp / 8;

and msm_host->byte_clk_rate = pixel_clk * bpp / (8 * nlanes);

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

 From where did you get the above formula?

I just felt that by having two APIs the next patch becomes easier because I need to just invoke the API which calculates byte clk.

Yes, I see that, it looks like a correct approach. You know, let's ignore the dsi_calc_clk_rate_v2() for now, it is definitely a separate change.

Could you please drop the opp_table handling from patch 2/2, move assignments in dsi_byte_clk_get_rate() back to the definition lines and then send it as v2?

Ack, will move the assignments to definition lines. Regarding the patch 2/2, I have responded with my concerns.