Commit 1ca582f1 authored by Andrzej Hajda's avatar Andrzej Hajda Committed by Inki Dae

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: default avatarAndrzej Hajda <a.hajda@samsung.com>
Signed-off-by: default avatarInki Dae <inki.dae@samsung.com>
parent 30b8913f
...@@ -155,7 +155,7 @@ static int exynos_dp_bind(struct device *dev, struct device *master, void *data) ...@@ -155,7 +155,7 @@ static int exynos_dp_bind(struct device *dev, struct device *master, void *data)
struct exynos_dp_device *dp = dev_get_drvdata(dev); struct exynos_dp_device *dp = dev_get_drvdata(dev);
struct drm_encoder *encoder = &dp->encoder; struct drm_encoder *encoder = &dp->encoder;
struct drm_device *drm_dev = data; struct drm_device *drm_dev = data;
int pipe, ret; int ret;
/* /*
* Just like the probe function said, we don't need the * Just like the probe function said, we don't need the
...@@ -179,20 +179,15 @@ static int exynos_dp_bind(struct device *dev, struct device *master, void *data) ...@@ -179,20 +179,15 @@ static int exynos_dp_bind(struct device *dev, struct device *master, void *data)
return ret; return ret;
} }
pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev,
EXYNOS_DISPLAY_TYPE_LCD);
if (pipe < 0)
return pipe;
encoder->possible_crtcs = 1 << pipe;
DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
drm_encoder_init(drm_dev, encoder, &exynos_dp_encoder_funcs, drm_encoder_init(drm_dev, encoder, &exynos_dp_encoder_funcs,
DRM_MODE_ENCODER_TMDS, NULL); DRM_MODE_ENCODER_TMDS, NULL);
drm_encoder_helper_add(encoder, &exynos_dp_encoder_helper_funcs); drm_encoder_helper_add(encoder, &exynos_dp_encoder_helper_funcs);
ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_LCD);
if (ret < 0)
return ret;
dp->plat_data.encoder = encoder; dp->plat_data.encoder = encoder;
return analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data); return analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
*/ */
#include <drm/drmP.h> #include <drm/drmP.h>
#include "exynos_drm_drv.h" #include "exynos_drm_drv.h"
#include "exynos_drm_crtc.h" #include "exynos_drm_crtc.h"
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <drm/drm_crtc_helper.h> #include <drm/drm_crtc_helper.h>
#include <drm/drm_atomic.h> #include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h> #include <drm/drm_atomic_helper.h>
#include <drm/drm_encoder.h>
#include "exynos_drm_crtc.h" #include "exynos_drm_crtc.h"
#include "exynos_drm_drv.h" #include "exynos_drm_drv.h"
...@@ -191,16 +192,30 @@ struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev, ...@@ -191,16 +192,30 @@ struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
return ERR_PTR(ret); return ERR_PTR(ret);
} }
int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev, struct exynos_drm_crtc *exynos_drm_crtc_get_by_type(struct drm_device *drm_dev,
enum exynos_drm_output_type out_type) enum exynos_drm_output_type out_type)
{ {
struct drm_crtc *crtc; struct drm_crtc *crtc;
drm_for_each_crtc(crtc, drm_dev) drm_for_each_crtc(crtc, drm_dev)
if (to_exynos_crtc(crtc)->type == out_type) if (to_exynos_crtc(crtc)->type == out_type)
return drm_crtc_index(crtc); return to_exynos_crtc(crtc);
return -EPERM; return ERR_PTR(-EPERM);
}
int exynos_drm_set_possible_crtcs(struct drm_encoder *encoder,
enum exynos_drm_output_type out_type)
{
struct exynos_drm_crtc *crtc = exynos_drm_crtc_get_by_type(encoder->dev,
out_type);
if (IS_ERR(crtc))
return PTR_ERR(crtc);
encoder->possible_crtcs = drm_crtc_mask(&crtc->base);
return 0;
} }
void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
......
...@@ -15,21 +15,25 @@ ...@@ -15,21 +15,25 @@
#ifndef _EXYNOS_DRM_CRTC_H_ #ifndef _EXYNOS_DRM_CRTC_H_
#define _EXYNOS_DRM_CRTC_H_ #define _EXYNOS_DRM_CRTC_H_
#include "exynos_drm_drv.h" #include "exynos_drm_drv.h"
struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev, struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev,
struct drm_plane *plane, struct drm_plane *plane,
enum exynos_drm_output_type type, enum exynos_drm_output_type out_type,
const struct exynos_drm_crtc_ops *ops, const struct exynos_drm_crtc_ops *ops,
void *context); void *context);
void exynos_drm_crtc_wait_pending_update(struct exynos_drm_crtc *exynos_crtc); void exynos_drm_crtc_wait_pending_update(struct exynos_drm_crtc *exynos_crtc);
void exynos_drm_crtc_finish_update(struct exynos_drm_crtc *exynos_crtc, void exynos_drm_crtc_finish_update(struct exynos_drm_crtc *exynos_crtc,
struct exynos_drm_plane *exynos_plane); struct exynos_drm_plane *exynos_plane);
/* This function gets pipe value to crtc device matched with out_type. */ /* This function gets crtc device matched with out_type. */
int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev, struct exynos_drm_crtc *exynos_drm_crtc_get_by_type(struct drm_device *drm_dev,
enum exynos_drm_output_type out_type); enum exynos_drm_output_type out_type);
int exynos_drm_set_possible_crtcs(struct drm_encoder *encoder,
enum exynos_drm_output_type out_type);
/* /*
* This function calls the crtc device(manager)'s te_handler() callback * This function calls the crtc device(manager)'s te_handler() callback
* to trigger to transfer video image at the tearing effect synchronization * to trigger to transfer video image at the tearing effect synchronization
......
...@@ -202,19 +202,15 @@ int exynos_dpi_bind(struct drm_device *dev, struct drm_encoder *encoder) ...@@ -202,19 +202,15 @@ int exynos_dpi_bind(struct drm_device *dev, struct drm_encoder *encoder)
{ {
int ret; int ret;
ret = exynos_drm_crtc_get_pipe_from_type(dev, EXYNOS_DISPLAY_TYPE_LCD);
if (ret < 0)
return ret;
encoder->possible_crtcs = 1 << ret;
DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
drm_encoder_init(dev, encoder, &exynos_dpi_encoder_funcs, drm_encoder_init(dev, encoder, &exynos_dpi_encoder_funcs,
DRM_MODE_ENCODER_TMDS, NULL); DRM_MODE_ENCODER_TMDS, NULL);
drm_encoder_helper_add(encoder, &exynos_dpi_encoder_helper_funcs); drm_encoder_helper_add(encoder, &exynos_dpi_encoder_helper_funcs);
ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_LCD);
if (ret < 0)
return ret;
ret = exynos_dpi_create_connector(encoder); ret = exynos_dpi_create_connector(encoder);
if (ret) { if (ret) {
DRM_ERROR("failed to create connector ret = %d\n", ret); DRM_ERROR("failed to create connector ret = %d\n", ret);
......
...@@ -1662,20 +1662,15 @@ static int exynos_dsi_bind(struct device *dev, struct device *master, ...@@ -1662,20 +1662,15 @@ static int exynos_dsi_bind(struct device *dev, struct device *master,
struct drm_bridge *bridge; struct drm_bridge *bridge;
int ret; int ret;
ret = exynos_drm_crtc_get_pipe_from_type(drm_dev,
EXYNOS_DISPLAY_TYPE_LCD);
if (ret < 0)
return ret;
encoder->possible_crtcs = 1 << ret;
DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
drm_encoder_init(drm_dev, encoder, &exynos_dsi_encoder_funcs, drm_encoder_init(drm_dev, encoder, &exynos_dsi_encoder_funcs,
DRM_MODE_ENCODER_TMDS, NULL); DRM_MODE_ENCODER_TMDS, NULL);
drm_encoder_helper_add(encoder, &exynos_dsi_encoder_helper_funcs); drm_encoder_helper_add(encoder, &exynos_dsi_encoder_helper_funcs);
ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_LCD);
if (ret < 0)
return ret;
ret = exynos_dsi_create_connector(encoder); ret = exynos_dsi_create_connector(encoder);
if (ret) { if (ret) {
DRM_ERROR("failed to create connector ret = %d\n", ret); DRM_ERROR("failed to create connector ret = %d\n", ret);
......
...@@ -381,7 +381,7 @@ static int vidi_bind(struct device *dev, struct device *master, void *data) ...@@ -381,7 +381,7 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
struct exynos_drm_plane *exynos_plane; struct exynos_drm_plane *exynos_plane;
struct exynos_drm_plane_config plane_config = { 0 }; struct exynos_drm_plane_config plane_config = { 0 };
unsigned int i; unsigned int i;
int pipe, ret; int ret;
ctx->drm_dev = drm_dev; ctx->drm_dev = drm_dev;
...@@ -406,20 +406,15 @@ static int vidi_bind(struct device *dev, struct device *master, void *data) ...@@ -406,20 +406,15 @@ static int vidi_bind(struct device *dev, struct device *master, void *data)
return PTR_ERR(ctx->crtc); return PTR_ERR(ctx->crtc);
} }
pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev,
EXYNOS_DISPLAY_TYPE_VIDI);
if (pipe < 0)
return pipe;
encoder->possible_crtcs = 1 << pipe;
DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
drm_encoder_init(drm_dev, encoder, &exynos_vidi_encoder_funcs, drm_encoder_init(drm_dev, encoder, &exynos_vidi_encoder_funcs,
DRM_MODE_ENCODER_TMDS, NULL); DRM_MODE_ENCODER_TMDS, NULL);
drm_encoder_helper_add(encoder, &exynos_vidi_encoder_helper_funcs); drm_encoder_helper_add(encoder, &exynos_vidi_encoder_helper_funcs);
ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_VIDI);
if (ret < 0)
return ret;
ret = vidi_create_connector(encoder); ret = vidi_create_connector(encoder);
if (ret) { if (ret) {
DRM_ERROR("failed to create connector ret = %d\n", ret); DRM_ERROR("failed to create connector ret = %d\n", ret);
......
...@@ -1697,32 +1697,25 @@ static int hdmi_bind(struct device *dev, struct device *master, void *data) ...@@ -1697,32 +1697,25 @@ static int hdmi_bind(struct device *dev, struct device *master, void *data)
struct drm_device *drm_dev = data; struct drm_device *drm_dev = data;
struct hdmi_context *hdata = dev_get_drvdata(dev); struct hdmi_context *hdata = dev_get_drvdata(dev);
struct drm_encoder *encoder = &hdata->encoder; struct drm_encoder *encoder = &hdata->encoder;
struct exynos_drm_crtc *exynos_crtc; struct exynos_drm_crtc *crtc;
struct drm_crtc *crtc; int ret;
int ret, pipe;
hdata->drm_dev = drm_dev; hdata->drm_dev = drm_dev;
pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev,
EXYNOS_DISPLAY_TYPE_HDMI);
if (pipe < 0)
return pipe;
hdata->phy_clk.enable = hdmiphy_clk_enable; hdata->phy_clk.enable = hdmiphy_clk_enable;
crtc = drm_crtc_from_index(drm_dev, pipe);
exynos_crtc = to_exynos_crtc(crtc);
exynos_crtc->pipe_clk = &hdata->phy_clk;
encoder->possible_crtcs = 1 << pipe;
DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
drm_encoder_init(drm_dev, encoder, &exynos_hdmi_encoder_funcs, drm_encoder_init(drm_dev, encoder, &exynos_hdmi_encoder_funcs,
DRM_MODE_ENCODER_TMDS, NULL); DRM_MODE_ENCODER_TMDS, NULL);
drm_encoder_helper_add(encoder, &exynos_hdmi_encoder_helper_funcs); drm_encoder_helper_add(encoder, &exynos_hdmi_encoder_helper_funcs);
ret = exynos_drm_set_possible_crtcs(encoder, EXYNOS_DISPLAY_TYPE_HDMI);
if (ret < 0)
return ret;
crtc = exynos_drm_crtc_get_by_type(drm_dev, EXYNOS_DISPLAY_TYPE_HDMI);
crtc->pipe_clk = &hdata->phy_clk;
ret = hdmi_create_connector(encoder); ret = hdmi_create_connector(encoder);
if (ret) { if (ret) {
DRM_ERROR("failed to create connector ret = %d\n", ret); DRM_ERROR("failed to create connector ret = %d\n", ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment