Commit e76171b0 authored by Russell King's avatar Russell King

imx-drm: imx-drm-core: sanitise imx_drm_encoder_get_mux_id()

Address the following issues:
- imx_drm_encoder_get_mux_id() searches the CRTC list for the matching
  CRTC, and returns the position within this list as the MUX programming
  value for encoders.  This is sub-optimal for two reasons:
  1. It relies upon the CRTC list not changing during the lifetime of
     the driver.
  2. It is dependent on the initialisation order of the CRTCs.

  We address (1) in this patch, leaving (2) until a better solution can
  be found, as (2) requires larger changes.

- imx_drm_encoder is unused.  Instead, pass the drm_encoder which is
  slightly more useful; all callers pass encoder->crtc as the required
  crtc, so move this inside the function.
Acked-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Acked-by: default avatarShawn Guo <shawn.guo@linaro.org>
Reviewed-by: default avatarFabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent cf83eb24
...@@ -53,6 +53,7 @@ struct imx_drm_crtc { ...@@ -53,6 +53,7 @@ struct imx_drm_crtc {
struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs; struct imx_drm_crtc_helper_funcs imx_drm_helper_funcs;
struct module *owner; struct module *owner;
struct crtc_cookie cookie; struct crtc_cookie cookie;
int mux_id;
}; };
struct imx_drm_encoder { struct imx_drm_encoder {
...@@ -503,7 +504,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc, ...@@ -503,7 +504,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
imx_drm_crtc->pipe = imxdrm->pipes++; imx_drm_crtc->pipe = imxdrm->pipes++;
imx_drm_crtc->cookie.cookie = cookie; imx_drm_crtc->cookie.cookie = cookie;
imx_drm_crtc->cookie.id = id; imx_drm_crtc->cookie.id = id;
imx_drm_crtc->mux_id = imx_drm_crtc->pipe;
imx_drm_crtc->crtc = crtc; imx_drm_crtc->crtc = crtc;
imx_drm_crtc->imxdrm = imxdrm; imx_drm_crtc->imxdrm = imxdrm;
...@@ -657,22 +658,16 @@ int imx_drm_encoder_add_possible_crtcs( ...@@ -657,22 +658,16 @@ int imx_drm_encoder_add_possible_crtcs(
} }
EXPORT_SYMBOL_GPL(imx_drm_encoder_add_possible_crtcs); EXPORT_SYMBOL_GPL(imx_drm_encoder_add_possible_crtcs);
int imx_drm_encoder_get_mux_id(struct imx_drm_encoder *imx_drm_encoder, int imx_drm_encoder_get_mux_id(struct drm_encoder *encoder)
struct drm_crtc *crtc)
{ {
struct imx_drm_device *imxdrm = __imx_drm_device(); struct imx_drm_device *imxdrm = __imx_drm_device();
struct imx_drm_crtc *imx_crtc; struct imx_drm_crtc *imx_crtc;
int i = 0;
list_for_each_entry(imx_crtc, &imxdrm->crtc_list, list) { list_for_each_entry(imx_crtc, &imxdrm->crtc_list, list)
if (imx_crtc->crtc == crtc) if (imx_crtc->crtc == encoder->crtc)
goto found; return imx_crtc->mux_id;
i++;
}
return -EINVAL; return -EINVAL;
found:
return i;
} }
EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id); EXPORT_SYMBOL_GPL(imx_drm_encoder_get_mux_id);
......
...@@ -64,8 +64,7 @@ void imx_drm_fb_helper_set(struct drm_fbdev_cma *fbdev_helper); ...@@ -64,8 +64,7 @@ void imx_drm_fb_helper_set(struct drm_fbdev_cma *fbdev_helper);
struct device_node; struct device_node;
int imx_drm_encoder_get_mux_id(struct imx_drm_encoder *imx_drm_encoder, int imx_drm_encoder_get_mux_id(struct drm_encoder *encoder);
struct drm_crtc *crtc);
int imx_drm_encoder_add_possible_crtcs(struct imx_drm_encoder *imx_drm_encoder, int imx_drm_encoder_add_possible_crtcs(struct imx_drm_encoder *imx_drm_encoder,
struct device_node *np); struct device_node *np);
......
...@@ -1467,8 +1467,7 @@ static void imx_hdmi_encoder_prepare(struct drm_encoder *encoder) ...@@ -1467,8 +1467,7 @@ static void imx_hdmi_encoder_prepare(struct drm_encoder *encoder)
static void imx_hdmi_encoder_commit(struct drm_encoder *encoder) static void imx_hdmi_encoder_commit(struct drm_encoder *encoder)
{ {
struct imx_hdmi *hdmi = container_of(encoder, struct imx_hdmi, encoder); struct imx_hdmi *hdmi = container_of(encoder, struct imx_hdmi, encoder);
int mux = imx_drm_encoder_get_mux_id(hdmi->imx_drm_encoder, int mux = imx_drm_encoder_get_mux_id(encoder);
encoder->crtc);
imx_hdmi_set_ipu_di_mux(hdmi, mux); imx_hdmi_set_ipu_di_mux(hdmi, mux);
......
...@@ -179,8 +179,7 @@ static void imx_ldb_encoder_prepare(struct drm_encoder *encoder) ...@@ -179,8 +179,7 @@ static void imx_ldb_encoder_prepare(struct drm_encoder *encoder)
u32 pixel_fmt; u32 pixel_fmt;
unsigned long serial_clk; unsigned long serial_clk;
unsigned long di_clk = mode->clock * 1000; unsigned long di_clk = mode->clock * 1000;
int mux = imx_drm_encoder_get_mux_id(imx_ldb_ch->imx_drm_encoder, int mux = imx_drm_encoder_get_mux_id(encoder);
encoder->crtc);
if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) { if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
/* dual channel LVDS mode */ /* dual channel LVDS mode */
...@@ -216,8 +215,7 @@ static void imx_ldb_encoder_commit(struct drm_encoder *encoder) ...@@ -216,8 +215,7 @@ static void imx_ldb_encoder_commit(struct drm_encoder *encoder)
struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
struct imx_ldb *ldb = imx_ldb_ch->ldb; struct imx_ldb *ldb = imx_ldb_ch->ldb;
int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
int mux = imx_drm_encoder_get_mux_id(imx_ldb_ch->imx_drm_encoder, int mux = imx_drm_encoder_get_mux_id(encoder);
encoder->crtc);
if (dual) { if (dual) {
clk_prepare_enable(ldb->clk[0]); clk_prepare_enable(ldb->clk[0]);
......
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