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

drm/exynos: use helper to set possible crtcs

All encoders share the same code to set encoders possible_crtcs field.
The patch creates helper to abstract out this code.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Inki Dae <inki.dae@samsung.com>

authored by

Andrzej Hajda and committed by
Inki Dae
1ca582f1 30b8913f

+53 -59
+5 -10
drivers/gpu/drm/exynos/exynos_dp.c
··· 155 155 struct exynos_dp_device *dp = dev_get_drvdata(dev); 156 156 struct drm_encoder *encoder = &dp->encoder; 157 157 struct drm_device *drm_dev = data; 158 - int pipe, ret; 158 + int ret; 159 159 160 160 /* 161 161 * Just like the probe function said, we don't need the ··· 179 179 return ret; 180 180 } 181 181 182 - pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev, 183 - EXYNOS_DISPLAY_TYPE_LCD); 184 - if (pipe < 0) 185 - return pipe; 186 - 187 - encoder->possible_crtcs = 1 << pipe; 188 - 189 - DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); 190 - 191 182 drm_encoder_init(drm_dev, encoder, &exynos_dp_encoder_funcs, 192 183 DRM_MODE_ENCODER_TMDS, NULL); 193 184 194 185 drm_encoder_helper_add(encoder, &exynos_dp_encoder_helper_funcs); 186 + 187 + ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_LCD); 188 + if (ret < 0) 189 + return ret; 195 190 196 191 dp->plat_data.encoder = encoder; 197 192
+1
drivers/gpu/drm/exynos/exynos_drm_core.c
··· 13 13 */ 14 14 15 15 #include <drm/drmP.h> 16 + 16 17 #include "exynos_drm_drv.h" 17 18 #include "exynos_drm_crtc.h" 18 19
+18 -3
drivers/gpu/drm/exynos/exynos_drm_crtc.c
··· 16 16 #include <drm/drm_crtc_helper.h> 17 17 #include <drm/drm_atomic.h> 18 18 #include <drm/drm_atomic_helper.h> 19 + #include <drm/drm_encoder.h> 19 20 20 21 #include "exynos_drm_crtc.h" 21 22 #include "exynos_drm_drv.h" ··· 192 191 return ERR_PTR(ret); 193 192 } 194 193 195 - int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev, 194 + struct exynos_drm_crtc *exynos_drm_crtc_get_by_type(struct drm_device *drm_dev, 196 195 enum exynos_drm_output_type out_type) 197 196 { 198 197 struct drm_crtc *crtc; 199 198 200 199 drm_for_each_crtc(crtc, drm_dev) 201 200 if (to_exynos_crtc(crtc)->type == out_type) 202 - return drm_crtc_index(crtc); 201 + return to_exynos_crtc(crtc); 203 202 204 - return -EPERM; 203 + return ERR_PTR(-EPERM); 204 + } 205 + 206 + int exynos_drm_set_possible_crtcs(struct drm_encoder *encoder, 207 + enum exynos_drm_output_type out_type) 208 + { 209 + struct exynos_drm_crtc *crtc = exynos_drm_crtc_get_by_type(encoder->dev, 210 + out_type); 211 + 212 + if (IS_ERR(crtc)) 213 + return PTR_ERR(crtc); 214 + 215 + encoder->possible_crtcs = drm_crtc_mask(&crtc->base); 216 + 217 + return 0; 205 218 } 206 219 207 220 void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
+7 -3
drivers/gpu/drm/exynos/exynos_drm_crtc.h
··· 15 15 #ifndef _EXYNOS_DRM_CRTC_H_ 16 16 #define _EXYNOS_DRM_CRTC_H_ 17 17 18 + 18 19 #include "exynos_drm_drv.h" 19 20 20 21 struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev, 21 22 struct drm_plane *plane, 22 - enum exynos_drm_output_type type, 23 + enum exynos_drm_output_type out_type, 23 24 const struct exynos_drm_crtc_ops *ops, 24 25 void *context); 25 26 void exynos_drm_crtc_wait_pending_update(struct exynos_drm_crtc *exynos_crtc); 26 27 void exynos_drm_crtc_finish_update(struct exynos_drm_crtc *exynos_crtc, 27 28 struct exynos_drm_plane *exynos_plane); 28 29 29 - /* This function gets pipe value to crtc device matched with out_type. */ 30 - int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev, 30 + /* This function gets crtc device matched with out_type. */ 31 + struct exynos_drm_crtc *exynos_drm_crtc_get_by_type(struct drm_device *drm_dev, 31 32 enum exynos_drm_output_type out_type); 33 + 34 + int exynos_drm_set_possible_crtcs(struct drm_encoder *encoder, 35 + enum exynos_drm_output_type out_type); 32 36 33 37 /* 34 38 * This function calls the crtc device(manager)'s te_handler() callback
+4 -8
drivers/gpu/drm/exynos/exynos_drm_dpi.c
··· 202 202 { 203 203 int ret; 204 204 205 - ret = exynos_drm_crtc_get_pipe_from_type(dev, EXYNOS_DISPLAY_TYPE_LCD); 206 - if (ret < 0) 207 - return ret; 208 - 209 - encoder->possible_crtcs = 1 << ret; 210 - 211 - DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); 212 - 213 205 drm_encoder_init(dev, encoder, &exynos_dpi_encoder_funcs, 214 206 DRM_MODE_ENCODER_TMDS, NULL); 215 207 216 208 drm_encoder_helper_add(encoder, &exynos_dpi_encoder_helper_funcs); 209 + 210 + ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_LCD); 211 + if (ret < 0) 212 + return ret; 217 213 218 214 ret = exynos_dpi_create_connector(encoder); 219 215 if (ret) {
+4 -9
drivers/gpu/drm/exynos/exynos_drm_dsi.c
··· 1662 1662 struct drm_bridge *bridge; 1663 1663 int ret; 1664 1664 1665 - ret = exynos_drm_crtc_get_pipe_from_type(drm_dev, 1666 - EXYNOS_DISPLAY_TYPE_LCD); 1667 - if (ret < 0) 1668 - return ret; 1669 - 1670 - encoder->possible_crtcs = 1 << ret; 1671 - 1672 - DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); 1673 - 1674 1665 drm_encoder_init(drm_dev, encoder, &exynos_dsi_encoder_funcs, 1675 1666 DRM_MODE_ENCODER_TMDS, NULL); 1676 1667 1677 1668 drm_encoder_helper_add(encoder, &exynos_dsi_encoder_helper_funcs); 1669 + 1670 + ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_LCD); 1671 + if (ret < 0) 1672 + return ret; 1678 1673 1679 1674 ret = exynos_dsi_create_connector(encoder); 1680 1675 if (ret) {
+5 -10
drivers/gpu/drm/exynos/exynos_drm_vidi.c
··· 381 381 struct exynos_drm_plane *exynos_plane; 382 382 struct exynos_drm_plane_config plane_config = { 0 }; 383 383 unsigned int i; 384 - int pipe, ret; 384 + int ret; 385 385 386 386 ctx->drm_dev = drm_dev; 387 387 ··· 406 406 return PTR_ERR(ctx->crtc); 407 407 } 408 408 409 - pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev, 410 - EXYNOS_DISPLAY_TYPE_VIDI); 411 - if (pipe < 0) 412 - return pipe; 413 - 414 - encoder->possible_crtcs = 1 << pipe; 415 - 416 - DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); 417 - 418 409 drm_encoder_init(drm_dev, encoder, &exynos_vidi_encoder_funcs, 419 410 DRM_MODE_ENCODER_TMDS, NULL); 420 411 421 412 drm_encoder_helper_add(encoder, &exynos_vidi_encoder_helper_funcs); 413 + 414 + ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_VIDI); 415 + if (ret < 0) 416 + return ret; 422 417 423 418 ret = vidi_create_connector(encoder); 424 419 if (ret) {
+9 -16
drivers/gpu/drm/exynos/exynos_hdmi.c
··· 1697 1697 struct drm_device *drm_dev = data; 1698 1698 struct hdmi_context *hdata = dev_get_drvdata(dev); 1699 1699 struct drm_encoder *encoder = &hdata->encoder; 1700 - struct exynos_drm_crtc *exynos_crtc; 1701 - struct drm_crtc *crtc; 1702 - int ret, pipe; 1700 + struct exynos_drm_crtc *crtc; 1701 + int ret; 1703 1702 1704 1703 hdata->drm_dev = drm_dev; 1705 1704 1706 - pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev, 1707 - EXYNOS_DISPLAY_TYPE_HDMI); 1708 - if (pipe < 0) 1709 - return pipe; 1710 - 1711 1705 hdata->phy_clk.enable = hdmiphy_clk_enable; 1712 - 1713 - crtc = drm_crtc_from_index(drm_dev, pipe); 1714 - exynos_crtc = to_exynos_crtc(crtc); 1715 - exynos_crtc->pipe_clk = &hdata->phy_clk; 1716 - 1717 - encoder->possible_crtcs = 1 << pipe; 1718 - 1719 - DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); 1720 1706 1721 1707 drm_encoder_init(drm_dev, encoder, &exynos_hdmi_encoder_funcs, 1722 1708 DRM_MODE_ENCODER_TMDS, NULL); 1723 1709 1724 1710 drm_encoder_helper_add(encoder, &exynos_hdmi_encoder_helper_funcs); 1711 + 1712 + ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_HDMI); 1713 + if (ret < 0) 1714 + return ret; 1715 + 1716 + crtc = exynos_drm_crtc_get_by_type(drm_dev, EXYNOS_DISPLAY_TYPE_HDMI); 1717 + crtc->pipe_clk = &hdata->phy_clk; 1725 1718 1726 1719 ret = hdmi_create_connector(encoder); 1727 1720 if (ret) {