All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>,
	 Simona Vetter <simona@ffwll.ch>,
	Andrzej Hajda <andrzej.hajda@intel.com>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	Robert Foss <rfoss@kernel.org>,
	 Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	 Jonas Karlman <jonas@kwiboo.se>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	 Douglas Anderson <dianders@chromium.org>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	 Maxime Ripard <mripard@kernel.org>
Subject: [PATCH 29/29] drm/bridge: ti-sn65dsi86: Use bridge_state crtc pointer
Date: Wed, 15 Jan 2025 22:05:36 +0100	[thread overview]
Message-ID: <20250115-bridge-connector-v1-29-9a2fecd886a6@kernel.org> (raw)
In-Reply-To: <20250115-bridge-connector-v1-0-9a2fecd886a6@kernel.org>

The TI sn65dsi86 driver follows the drm_encoder->crtc pointer that is
deprecated and shouldn't be used by atomic drivers.

This was due to the fact that we did't have any other alternative to
retrieve the CRTC pointer. Fortunately, the crtc pointer is now provided
in the bridge state, so we can move to atomic callbacks and drop that
deprecated pointer usage.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 41 ++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
index b3d617505dda7d22b38c000fb79de46376adf3f1..c17d9486cf5c36d61eb00af2bdf9ba1b6f890ffd 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
@@ -242,15 +242,16 @@ static void ti_sn65dsi86_write_u16(struct ti_sn65dsi86 *pdata,
 	u8 buf[2] = { val & 0xff, val >> 8 };
 
 	regmap_bulk_write(pdata->regmap, reg, buf, ARRAY_SIZE(buf));
 }
 
-static u32 ti_sn_bridge_get_dsi_freq(struct ti_sn65dsi86 *pdata)
+static u32 ti_sn_bridge_get_dsi_freq(struct ti_sn65dsi86 *pdata,
+				     struct drm_bridge_state *bridge_state)
 {
 	u32 bit_rate_khz, clk_freq_khz;
 	struct drm_display_mode *mode =
-		&pdata->bridge.encoder->crtc->state->adjusted_mode;
+		&bridge_state->crtc->state->adjusted_mode;
 
 	bit_rate_khz = mode->clock *
 			mipi_dsi_pixel_format_to_bpp(pdata->dsi->format);
 	clk_freq_khz = bit_rate_khz / (pdata->dsi->lanes * 2);
 
@@ -273,11 +274,12 @@ static const u32 ti_sn_bridge_dsiclk_lut[] = {
 	416000000,
 	486000000,
 	460800000,
 };
 
-static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata)
+static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata,
+					 struct drm_bridge_state *bridge_state)
 {
 	int i;
 	u32 refclk_rate;
 	const u32 *refclk_lut;
 	size_t refclk_lut_size;
@@ -286,11 +288,11 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata)
 		refclk_rate = clk_get_rate(pdata->refclk);
 		refclk_lut = ti_sn_bridge_refclk_lut;
 		refclk_lut_size = ARRAY_SIZE(ti_sn_bridge_refclk_lut);
 		clk_prepare_enable(pdata->refclk);
 	} else {
-		refclk_rate = ti_sn_bridge_get_dsi_freq(pdata) * 1000;
+		refclk_rate = ti_sn_bridge_get_dsi_freq(pdata, bridge_state) * 1000;
 		refclk_lut = ti_sn_bridge_dsiclk_lut;
 		refclk_lut_size = ARRAY_SIZE(ti_sn_bridge_dsiclk_lut);
 	}
 
 	/* for i equals to refclk_lut_size means default frequency */
@@ -310,16 +312,17 @@ static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata)
 	 * regardless of its actual sourcing.
 	 */
 	pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i];
 }
 
-static void ti_sn65dsi86_enable_comms(struct ti_sn65dsi86 *pdata)
+static void ti_sn65dsi86_enable_comms(struct ti_sn65dsi86 *pdata,
+				      struct drm_bridge_state *bridge_state)
 {
 	mutex_lock(&pdata->comms_mutex);
 
 	/* configure bridge ref_clk */
-	ti_sn_bridge_set_refclk_freq(pdata);
+	ti_sn_bridge_set_refclk_freq(pdata, bridge_state);
 
 	/*
 	 * HPD on this bridge chip is a bit useless.  This is an eDP bridge
 	 * so the HPD is an internal signal that's only there to signal that
 	 * the panel is done powering up.  ...but the bridge chip debounces
@@ -375,11 +378,11 @@ static int __maybe_unused ti_sn65dsi86_resume(struct device *dev)
 	 * so we can do it in resume which lets us read the EDID before
 	 * pre_enable(). Without a reference clock we need the MIPI reference
 	 * clock so reading early doesn't work.
 	 */
 	if (pdata->refclk)
-		ti_sn65dsi86_enable_comms(pdata);
+		ti_sn65dsi86_enable_comms(pdata, drm_bridge_get_current_state(&pdata->bridge));
 
 	return ret;
 }
 
 static int __maybe_unused ti_sn65dsi86_suspend(struct device *dev)
@@ -820,16 +823,17 @@ static void ti_sn_bridge_atomic_disable(struct drm_bridge *bridge,
 
 	/* disable video stream */
 	regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE, 0);
 }
 
-static void ti_sn_bridge_set_dsi_rate(struct ti_sn65dsi86 *pdata)
+static void ti_sn_bridge_set_dsi_rate(struct ti_sn65dsi86 *pdata,
+				      struct drm_bridge_state *bridge_state)
 {
 	unsigned int bit_rate_mhz, clk_freq_mhz;
 	unsigned int val;
 	struct drm_display_mode *mode =
-		&pdata->bridge.encoder->crtc->state->adjusted_mode;
+		&bridge_state->crtc->state->adjusted_mode;
 
 	/* set DSIA clk frequency */
 	bit_rate_mhz = (mode->clock / 1000) *
 			mipi_dsi_pixel_format_to_bpp(pdata->dsi->format);
 	clk_freq_mhz = bit_rate_mhz / (pdata->dsi->lanes * 2);
@@ -855,16 +859,18 @@ static unsigned int ti_sn_bridge_get_bpp(struct drm_connector *connector)
  */
 static const unsigned int ti_sn_bridge_dp_rate_lut[] = {
 	0, 1620, 2160, 2430, 2700, 3240, 4320, 5400
 };
 
-static int ti_sn_bridge_calc_min_dp_rate_idx(struct ti_sn65dsi86 *pdata, unsigned int bpp)
+static int ti_sn_bridge_calc_min_dp_rate_idx(struct ti_sn65dsi86 *pdata,
+					     struct drm_bridge_state *bridge_state,
+					     unsigned int bpp)
 {
 	unsigned int bit_rate_khz, dp_rate_mhz;
 	unsigned int i;
 	struct drm_display_mode *mode =
-		&pdata->bridge.encoder->crtc->state->adjusted_mode;
+		&bridge_state->crtc->state->adjusted_mode;
 
 	/* Calculate minimum bit rate based on our pixel clock. */
 	bit_rate_khz = mode->clock * bpp;
 
 	/* Calculate minimum DP data rate, taking 80% as per DP spec */
@@ -959,14 +965,15 @@ static unsigned int ti_sn_bridge_read_valid_rates(struct ti_sn65dsi86 *pdata)
 	}
 
 	return valid_rates;
 }
 
-static void ti_sn_bridge_set_video_timings(struct ti_sn65dsi86 *pdata)
+static void ti_sn_bridge_set_video_timings(struct ti_sn65dsi86 *pdata,
+					   struct drm_bridge_state *bridge_state)
 {
 	struct drm_display_mode *mode =
-		&pdata->bridge.encoder->crtc->state->adjusted_mode;
+		&bridge_state->crtc->state->adjusted_mode;
 	u8 hsync_polarity = 0, vsync_polarity = 0;
 
 	if (mode->flags & DRM_MODE_FLAG_NHSYNC)
 		hsync_polarity = CHA_HSYNC_POLARITY;
 	if (mode->flags & DRM_MODE_FLAG_NVSYNC)
@@ -1104,11 +1111,11 @@ static void ti_sn_bridge_atomic_enable(struct drm_bridge *bridge,
 	regmap_write(pdata->regmap, SN_LN_ASSIGN_REG, pdata->ln_assign);
 	regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, LN_POLRS_MASK,
 			   pdata->ln_polrs << LN_POLRS_OFFSET);
 
 	/* set dsi clk frequency value */
-	ti_sn_bridge_set_dsi_rate(pdata);
+	ti_sn_bridge_set_dsi_rate(pdata, old_bridge_state);
 
 	/*
 	 * The SN65DSI86 only supports ASSR Display Authentication method and
 	 * this method is enabled for eDP panels. An eDP panel must support this
 	 * authentication method. We need to enable this method in the eDP panel
@@ -1139,11 +1146,11 @@ static void ti_sn_bridge_atomic_enable(struct drm_bridge *bridge,
 			   val);
 
 	valid_rates = ti_sn_bridge_read_valid_rates(pdata);
 
 	/* Train until we run out of rates */
-	for (dp_rate_idx = ti_sn_bridge_calc_min_dp_rate_idx(pdata, bpp);
+	for (dp_rate_idx = ti_sn_bridge_calc_min_dp_rate_idx(pdata, old_bridge_state, bpp);
 	     dp_rate_idx < ARRAY_SIZE(ti_sn_bridge_dp_rate_lut);
 	     dp_rate_idx++) {
 		if (!(valid_rates & BIT(dp_rate_idx)))
 			continue;
 
@@ -1155,11 +1162,11 @@ static void ti_sn_bridge_atomic_enable(struct drm_bridge *bridge,
 		DRM_DEV_ERROR(pdata->dev, "%s (%d)\n", last_err_str, ret);
 		return;
 	}
 
 	/* config video parameters */
-	ti_sn_bridge_set_video_timings(pdata);
+	ti_sn_bridge_set_video_timings(pdata, old_bridge_state);
 
 	/* enable video stream */
 	regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE,
 			   VSTREAM_ENABLE);
 }
@@ -1170,11 +1177,11 @@ static void ti_sn_bridge_atomic_pre_enable(struct drm_bridge *bridge,
 	struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
 
 	pm_runtime_get_sync(pdata->dev);
 
 	if (!pdata->refclk)
-		ti_sn65dsi86_enable_comms(pdata);
+		ti_sn65dsi86_enable_comms(pdata, old_bridge_state);
 
 	/* td7: min 100 us after enable before DSI data */
 	usleep_range(100, 110);
 }
 

-- 
2.47.1


  parent reply	other threads:[~2025-01-15 21:07 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-15 21:05 [PATCH 00/29] drm/bridge: Various quality of life improvements Maxime Ripard
2025-01-15 21:05 ` [PATCH 01/29] drm/atomic-helper: Fix commit_tail state variable name Maxime Ripard
2025-01-16  1:36   ` Dmitry Baryshkov
2025-01-16 11:27     ` Simona Vetter
2025-01-15 21:05 ` [PATCH 02/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_wait_for_dependencies() Maxime Ripard
2025-01-15 21:05 ` [PATCH 03/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_commit_tail() Maxime Ripard
2025-01-15 21:05 ` [PATCH 04/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_commit_tail_rpm() Maxime Ripard
2025-01-15 21:05 ` [PATCH 05/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_modeset_disables() Maxime Ripard
2025-01-15 21:05 ` [PATCH 06/29] drm/atomic-helper: Change parameter name of disable_outputs() Maxime Ripard
2025-01-15 21:05 ` [PATCH 07/29] drm/bridge: Change parameter name of drm_atomic_bridge_chain_disable() Maxime Ripard
2025-01-15 21:05 ` [PATCH 08/29] drm/bridge: Change parameter name of drm_atomic_bridge_chain_post_disable() Maxime Ripard
2025-01-15 21:05 ` [PATCH 09/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_update_legacy_modeset_state() Maxime Ripard
2025-01-15 21:05 ` [PATCH 10/29] drm/atomic-helper: Change parameter name of crtc_set_mode() Maxime Ripard
2025-01-15 21:05 ` [PATCH 11/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_commit_planes() Maxime Ripard
2025-01-15 21:05 ` [PATCH 12/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_commit_modeset_enables() Maxime Ripard
2025-01-15 21:05 ` [PATCH 13/29] drm/bridge: Change parameter name of drm_atomic_bridge_chain_pre_enable() Maxime Ripard
2025-01-15 21:05 ` [PATCH 14/29] drm/bridge: Change parameter name of drm_atomic_bridge_chain_enable() Maxime Ripard
2025-01-15 21:05 ` [PATCH 15/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_commit_writebacks() Maxime Ripard
2025-01-15 21:05 ` [PATCH 16/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_fake_vblank() Maxime Ripard
2025-01-15 21:05 ` [PATCH 17/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_commit_hw_done() Maxime Ripard
2025-01-15 21:05 ` [PATCH 18/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_wait_for_vblanks() Maxime Ripard
2025-01-15 21:05 ` [PATCH 19/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_cleanup_planes() Maxime Ripard
2025-01-15 21:05 ` [PATCH 20/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_commit_cleanup_done() Maxime Ripard
2025-01-15 21:05 ` [PATCH 21/29] drm/atomic-helper: Change parameter name of drm_atomic_helper_wait_for_flip_done() Maxime Ripard
2025-01-15 21:05 ` [PATCH 22/29] drm/bridge: Rename atomic hooks parameters to drop old prefix Maxime Ripard
2025-01-16 11:34   ` Simona Vetter
2025-01-17 14:50     ` Maxime Ripard
2025-01-17 15:32       ` Simona Vetter
2025-01-15 21:05 ` [PATCH 23/29] drm/bridge: Provide a helper to retrieve current bridge state Maxime Ripard
2025-01-16  0:43   ` Dmitry Baryshkov
2025-01-16  8:30     ` Maxime Ripard
2025-01-16 11:35     ` Simona Vetter
2025-01-15 21:05 ` [PATCH 24/29] drm/bridge: Provide a helper to get the global state from a " Maxime Ripard
2025-01-16 11:31   ` Simona Vetter
2025-01-15 21:05 ` [PATCH 25/29] drm/bridge: Provide pointers to the connector and crtc in " Maxime Ripard
2025-01-16  1:04   ` Dmitry Baryshkov
2025-01-16  8:42     ` Maxime Ripard
2025-01-16  9:53       ` Dmitry Baryshkov
2025-01-15 21:05 ` [PATCH 26/29] drm/bridge: cdns-csi: Switch to atomic helpers Maxime Ripard
2025-01-16  1:06   ` Dmitry Baryshkov
2025-01-15 21:05 ` [PATCH 27/29] drm/bridge: tc358775: Switch to atomic commit Maxime Ripard
2025-01-16  1:06   ` Dmitry Baryshkov
2025-01-15 21:05 ` [PATCH 28/29] drm/bridge: tc358768: Convert to atomic helpers Maxime Ripard
2025-01-15 21:05 ` Maxime Ripard [this message]
2025-01-16  1:08   ` [PATCH 29/29] drm/bridge: ti-sn65dsi86: Use bridge_state crtc pointer Dmitry Baryshkov
2025-02-03 10:01     ` Maxime Ripard
2025-02-03 17:49       ` Dmitry Baryshkov
2025-02-04  8:23         ` Maxime Ripard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250115-bridge-connector-v1-29-9a2fecd886a6@kernel.org \
    --to=mripard@kernel.org \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=andrzej.hajda@intel.com \
    --cc=dianders@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=neil.armstrong@linaro.org \
    --cc=rfoss@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.