Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/bridge: ti-sn65dsi86: Remove drm_encoder->crtc use

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

Fortunately, the atomic hooks provide the drm_atomic_state and we can
access our current CRTC from that, going from the bridge to its encoder,
to its connector, and to its CRTC.

This bridge driver uses the atomic hooks already, but dereferences the
drm_encoder->crtc pointer in functions that don't have access to it.

Let's rework the driver to pass the state where needed, and remove the
need for the drm_encoder->crtc dereference.

Reviewed-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Douglas Anderson <dianders@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20250313-bridge-connector-v6-16-511c54a604fb@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>

+38 -17
+38 -17
drivers/gpu/drm/bridge/ti-sn65dsi86.c
··· 243 243 regmap_bulk_write(pdata->regmap, reg, buf, ARRAY_SIZE(buf)); 244 244 } 245 245 246 - static u32 ti_sn_bridge_get_dsi_freq(struct ti_sn65dsi86 *pdata) 246 + static struct drm_display_mode * 247 + get_new_adjusted_display_mode(struct drm_bridge *bridge, 248 + struct drm_atomic_state *state) 249 + { 250 + struct drm_connector *connector = 251 + drm_atomic_get_new_connector_for_encoder(state, bridge->encoder); 252 + struct drm_connector_state *conn_state = 253 + drm_atomic_get_new_connector_state(state, connector); 254 + struct drm_crtc_state *crtc_state = 255 + drm_atomic_get_new_crtc_state(state, conn_state->crtc); 256 + 257 + return &crtc_state->adjusted_mode; 258 + } 259 + 260 + static u32 ti_sn_bridge_get_dsi_freq(struct ti_sn65dsi86 *pdata, 261 + struct drm_atomic_state *state) 247 262 { 248 263 u32 bit_rate_khz, clk_freq_khz; 249 264 struct drm_display_mode *mode = 250 - &pdata->bridge.encoder->crtc->state->adjusted_mode; 265 + get_new_adjusted_display_mode(&pdata->bridge, state); 251 266 252 267 bit_rate_khz = mode->clock * 253 268 mipi_dsi_pixel_format_to_bpp(pdata->dsi->format); ··· 289 274 460800000, 290 275 }; 291 276 292 - static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata) 277 + static void ti_sn_bridge_set_refclk_freq(struct ti_sn65dsi86 *pdata, 278 + struct drm_atomic_state *state) 293 279 { 294 280 int i; 295 281 u32 refclk_rate; ··· 303 287 refclk_lut_size = ARRAY_SIZE(ti_sn_bridge_refclk_lut); 304 288 clk_prepare_enable(pdata->refclk); 305 289 } else { 306 - refclk_rate = ti_sn_bridge_get_dsi_freq(pdata) * 1000; 290 + refclk_rate = ti_sn_bridge_get_dsi_freq(pdata, state) * 1000; 307 291 refclk_lut = ti_sn_bridge_dsiclk_lut; 308 292 refclk_lut_size = ARRAY_SIZE(ti_sn_bridge_dsiclk_lut); 309 293 } ··· 327 311 pdata->pwm_refclk_freq = ti_sn_bridge_refclk_lut[i]; 328 312 } 329 313 330 - static void ti_sn65dsi86_enable_comms(struct ti_sn65dsi86 *pdata) 314 + static void ti_sn65dsi86_enable_comms(struct ti_sn65dsi86 *pdata, 315 + struct drm_atomic_state *state) 331 316 { 332 317 mutex_lock(&pdata->comms_mutex); 333 318 334 319 /* configure bridge ref_clk */ 335 - ti_sn_bridge_set_refclk_freq(pdata); 320 + ti_sn_bridge_set_refclk_freq(pdata, state); 336 321 337 322 /* 338 323 * HPD on this bridge chip is a bit useless. This is an eDP bridge ··· 393 376 * clock so reading early doesn't work. 394 377 */ 395 378 if (pdata->refclk) 396 - ti_sn65dsi86_enable_comms(pdata); 379 + ti_sn65dsi86_enable_comms(pdata, NULL); 397 380 398 381 return ret; 399 382 } ··· 839 822 regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE, 0); 840 823 } 841 824 842 - static void ti_sn_bridge_set_dsi_rate(struct ti_sn65dsi86 *pdata) 825 + static void ti_sn_bridge_set_dsi_rate(struct ti_sn65dsi86 *pdata, 826 + struct drm_atomic_state *state) 843 827 { 844 828 unsigned int bit_rate_mhz, clk_freq_mhz; 845 829 unsigned int val; 846 830 struct drm_display_mode *mode = 847 - &pdata->bridge.encoder->crtc->state->adjusted_mode; 831 + get_new_adjusted_display_mode(&pdata->bridge, state); 848 832 849 833 /* set DSIA clk frequency */ 850 834 bit_rate_mhz = (mode->clock / 1000) * ··· 875 857 0, 1620, 2160, 2430, 2700, 3240, 4320, 5400 876 858 }; 877 859 878 - static int ti_sn_bridge_calc_min_dp_rate_idx(struct ti_sn65dsi86 *pdata, unsigned int bpp) 860 + static int ti_sn_bridge_calc_min_dp_rate_idx(struct ti_sn65dsi86 *pdata, 861 + struct drm_atomic_state *state, 862 + unsigned int bpp) 879 863 { 880 864 unsigned int bit_rate_khz, dp_rate_mhz; 881 865 unsigned int i; 882 866 struct drm_display_mode *mode = 883 - &pdata->bridge.encoder->crtc->state->adjusted_mode; 867 + get_new_adjusted_display_mode(&pdata->bridge, state); 884 868 885 869 /* Calculate minimum bit rate based on our pixel clock. */ 886 870 bit_rate_khz = mode->clock * bpp; ··· 981 961 return valid_rates; 982 962 } 983 963 984 - static void ti_sn_bridge_set_video_timings(struct ti_sn65dsi86 *pdata) 964 + static void ti_sn_bridge_set_video_timings(struct ti_sn65dsi86 *pdata, 965 + struct drm_atomic_state *state) 985 966 { 986 967 struct drm_display_mode *mode = 987 - &pdata->bridge.encoder->crtc->state->adjusted_mode; 968 + get_new_adjusted_display_mode(&pdata->bridge, state); 988 969 u8 hsync_polarity = 0, vsync_polarity = 0; 989 970 990 971 if (mode->flags & DRM_MODE_FLAG_NHSYNC) ··· 1127 1106 pdata->ln_polrs << LN_POLRS_OFFSET); 1128 1107 1129 1108 /* set dsi clk frequency value */ 1130 - ti_sn_bridge_set_dsi_rate(pdata); 1109 + ti_sn_bridge_set_dsi_rate(pdata, state); 1131 1110 1132 1111 /* 1133 1112 * The SN65DSI86 only supports ASSR Display Authentication method and ··· 1162 1141 valid_rates = ti_sn_bridge_read_valid_rates(pdata); 1163 1142 1164 1143 /* Train until we run out of rates */ 1165 - for (dp_rate_idx = ti_sn_bridge_calc_min_dp_rate_idx(pdata, bpp); 1144 + for (dp_rate_idx = ti_sn_bridge_calc_min_dp_rate_idx(pdata, state, bpp); 1166 1145 dp_rate_idx < ARRAY_SIZE(ti_sn_bridge_dp_rate_lut); 1167 1146 dp_rate_idx++) { 1168 1147 if (!(valid_rates & BIT(dp_rate_idx))) ··· 1178 1157 } 1179 1158 1180 1159 /* config video parameters */ 1181 - ti_sn_bridge_set_video_timings(pdata); 1160 + ti_sn_bridge_set_video_timings(pdata, state); 1182 1161 1183 1162 /* enable video stream */ 1184 1163 regmap_update_bits(pdata->regmap, SN_ENH_FRAME_REG, VSTREAM_ENABLE, ··· 1193 1172 pm_runtime_get_sync(pdata->dev); 1194 1173 1195 1174 if (!pdata->refclk) 1196 - ti_sn65dsi86_enable_comms(pdata); 1175 + ti_sn65dsi86_enable_comms(pdata, state); 1197 1176 1198 1177 /* td7: min 100 us after enable before DSI data */ 1199 1178 usleep_range(100, 110);