From 255c35f8fe6a9c345320e512c681c03678f3e0b4 Mon Sep 17 00:00:00 2001 From: Liu Ying Date: Fri, 8 Jul 2016 17:40:56 +0800 Subject: drm/imx: atomic phase 2 step 1: Wire up state ->reset, ->duplicate and ->destroy Wire up CRTCs', planes' and connectors' ->reset, ->duplicate and ->destroy state hooks to use the default implementations from the atomic helper library. The helpers track each DRM object state. Signed-off-by: Liu Ying Acked-by: Daniel Vetter Signed-off-by: Philipp Zabel --- drivers/gpu/drm/imx/parallel-display.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/gpu/drm/imx/parallel-display.c') diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c index 2d1fd02cd3d6..9fe88c9b4b0d 100644 --- a/drivers/gpu/drm/imx/parallel-display.c +++ b/drivers/gpu/drm/imx/parallel-display.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -134,6 +135,9 @@ static const struct drm_connector_funcs imx_pd_connector_funcs = { .fill_modes = drm_helper_probe_single_connector_modes, .detect = imx_pd_connector_detect, .destroy = imx_drm_connector_destroy, + .reset = drm_atomic_helper_connector_reset, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; static const struct drm_connector_helper_funcs imx_pd_connector_helper_funcs = { -- cgit v1.2.3 From 032003c5cd744e8e0baf5430fc5b3fd5462208e4 Mon Sep 17 00:00:00 2001 From: Liu Ying Date: Fri, 8 Jul 2016 17:40:58 +0800 Subject: drm/imx: Remove encoders' ->prepare callbacks The main task of imx encoders' ->prepare callbacks is to set bus_format, bus_flags, di_vsync_pin and di_hsync_pin. We may create a structure named imx_encoder to cache them. The atomic encoder callback ->disable may replace ->prepare later, so let's remove ->prepare. Signed-off-by: Liu Ying Acked-by: Daniel Vetter Signed-off-by: Philipp Zabel --- drivers/gpu/drm/imx/dw_hdmi-imx.c | 18 ++--- drivers/gpu/drm/imx/imx-drm-core.c | 39 ----------- drivers/gpu/drm/imx/imx-drm.h | 18 ++--- drivers/gpu/drm/imx/imx-ldb.c | 118 +++++++++++++++++---------------- drivers/gpu/drm/imx/imx-tve.c | 58 ++++++---------- drivers/gpu/drm/imx/ipuv3-crtc.c | 38 ++++------- drivers/gpu/drm/imx/parallel-display.c | 56 ++++++++-------- 7 files changed, 142 insertions(+), 203 deletions(-) (limited to 'drivers/gpu/drm/imx/parallel-display.c') diff --git a/drivers/gpu/drm/imx/dw_hdmi-imx.c b/drivers/gpu/drm/imx/dw_hdmi-imx.c index a24631fdf4ad..5f646748960a 100644 --- a/drivers/gpu/drm/imx/dw_hdmi-imx.c +++ b/drivers/gpu/drm/imx/dw_hdmi-imx.c @@ -22,9 +22,11 @@ #include "imx-drm.h" +#define imx_enc_to_imx_hdmi(x) container_of(x, struct imx_hdmi, imx_encoder) + struct imx_hdmi { struct device *dev; - struct drm_encoder encoder; + struct imx_drm_encoder imx_encoder; struct regmap *regmap; }; @@ -117,7 +119,8 @@ static void dw_hdmi_imx_encoder_mode_set(struct drm_encoder *encoder, static void dw_hdmi_imx_encoder_commit(struct drm_encoder *encoder) { - struct imx_hdmi *hdmi = container_of(encoder, struct imx_hdmi, encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_hdmi *hdmi = imx_enc_to_imx_hdmi(imx_encoder); int mux = drm_of_encoder_active_port_id(hdmi->dev->of_node, encoder); regmap_update_bits(hdmi->regmap, IOMUXC_GPR3, @@ -125,14 +128,8 @@ static void dw_hdmi_imx_encoder_commit(struct drm_encoder *encoder) mux << IMX6Q_GPR3_HDMI_MUX_CTL_SHIFT); } -static void dw_hdmi_imx_encoder_prepare(struct drm_encoder *encoder) -{ - imx_drm_set_bus_format(encoder, MEDIA_BUS_FMT_RGB888_1X24); -} - static const struct drm_encoder_helper_funcs dw_hdmi_imx_encoder_helper_funcs = { .mode_set = dw_hdmi_imx_encoder_mode_set, - .prepare = dw_hdmi_imx_encoder_prepare, .commit = dw_hdmi_imx_encoder_commit, .disable = dw_hdmi_imx_encoder_disable, }; @@ -215,7 +212,10 @@ static int dw_hdmi_imx_bind(struct device *dev, struct device *master, match = of_match_node(dw_hdmi_imx_dt_ids, pdev->dev.of_node); plat_data = match->data; hdmi->dev = &pdev->dev; - encoder = &hdmi->encoder; + encoder = &hdmi->imx_encoder.encoder; + hdmi->imx_encoder.bus_format = MEDIA_BUS_FMT_RGB888_1X24; + hdmi->imx_encoder.di_hsync_pin = 2; + hdmi->imx_encoder.di_vsync_pin = 3; irq = platform_get_irq(pdev, 0); if (irq < 0) diff --git a/drivers/gpu/drm/imx/imx-drm-core.c b/drivers/gpu/drm/imx/imx-drm-core.c index b5a5173b05af..f6e44c220874 100644 --- a/drivers/gpu/drm/imx/imx-drm-core.c +++ b/drivers/gpu/drm/imx/imx-drm-core.c @@ -85,45 +85,6 @@ static int imx_drm_driver_unload(struct drm_device *drm) return 0; } -static struct imx_drm_crtc *imx_drm_find_crtc(struct drm_crtc *crtc) -{ - struct imx_drm_device *imxdrm = crtc->dev->dev_private; - unsigned i; - - for (i = 0; i < MAX_CRTC; i++) - if (imxdrm->crtc[i] && imxdrm->crtc[i]->crtc == crtc) - return imxdrm->crtc[i]; - - return NULL; -} - -int imx_drm_set_bus_config(struct drm_encoder *encoder, u32 bus_format, - int hsync_pin, int vsync_pin, u32 bus_flags) -{ - struct imx_drm_crtc_helper_funcs *helper; - struct imx_drm_crtc *imx_crtc; - - imx_crtc = imx_drm_find_crtc(encoder->crtc); - if (!imx_crtc) - return -EINVAL; - - helper = &imx_crtc->imx_drm_helper_funcs; - if (helper->set_interface_pix_fmt) - return helper->set_interface_pix_fmt(encoder->crtc, - bus_format, hsync_pin, vsync_pin, - bus_flags); - return 0; -} -EXPORT_SYMBOL_GPL(imx_drm_set_bus_config); - -int imx_drm_set_bus_format(struct drm_encoder *encoder, u32 bus_format) -{ - return imx_drm_set_bus_config(encoder, bus_format, 2, 3, - DRM_BUS_FLAG_DE_HIGH | - DRM_BUS_FLAG_PIXDATA_NEGEDGE); -} -EXPORT_SYMBOL_GPL(imx_drm_set_bus_format); - int imx_drm_crtc_vblank_get(struct imx_drm_crtc *imx_drm_crtc) { return drm_crtc_vblank_get(imx_drm_crtc->crtc); diff --git a/drivers/gpu/drm/imx/imx-drm.h b/drivers/gpu/drm/imx/imx-drm.h index 74320a1723b7..39cef15c699b 100644 --- a/drivers/gpu/drm/imx/imx-drm.h +++ b/drivers/gpu/drm/imx/imx-drm.h @@ -15,12 +15,19 @@ struct platform_device; unsigned int imx_drm_crtc_id(struct imx_drm_crtc *crtc); +struct imx_drm_encoder { + struct drm_encoder encoder; + u32 bus_format; + u32 bus_flags; + int di_hsync_pin; + int di_vsync_pin; +}; + +#define enc_to_imx_enc(x) container_of(x, struct imx_drm_encoder, encoder) + struct imx_drm_crtc_helper_funcs { int (*enable_vblank)(struct drm_crtc *crtc); void (*disable_vblank)(struct drm_crtc *crtc); - int (*set_interface_pix_fmt)(struct drm_crtc *crtc, - u32 bus_format, int hsync_pin, int vsync_pin, - u32 bus_flags); const struct drm_crtc_helper_funcs *crtc_helper_funcs; const struct drm_crtc_funcs *crtc_funcs; }; @@ -42,11 +49,6 @@ void imx_drm_mode_config_init(struct drm_device *drm); struct drm_gem_cma_object *imx_drm_fb_get_obj(struct drm_framebuffer *fb); -int imx_drm_set_bus_config(struct drm_encoder *encoder, u32 bus_format, - int hsync_pin, int vsync_pin, u32 bus_flags); -int imx_drm_set_bus_format(struct drm_encoder *encoder, - u32 bus_format); - int imx_drm_encoder_parse_of(struct drm_device *drm, struct drm_encoder *encoder, struct device_node *np); diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index 12bf368ae6df..6e110bba35cb 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -51,14 +51,15 @@ #define LDB_BGREF_RMODE_INT (1 << 15) #define con_to_imx_ldb_ch(x) container_of(x, struct imx_ldb_channel, connector) -#define enc_to_imx_ldb_ch(x) container_of(x, struct imx_ldb_channel, encoder) +#define imx_enc_to_imx_ldb_ch(x) \ + container_of(x, struct imx_ldb_channel, imx_encoder) struct imx_ldb; struct imx_ldb_channel { struct imx_ldb *ldb; struct drm_connector connector; - struct drm_encoder encoder; + struct imx_drm_encoder imx_encoder; struct drm_panel *panel; struct device_node *child; struct i2c_adapter *ddc; @@ -67,7 +68,6 @@ struct imx_ldb_channel { int edid_len; struct drm_display_mode mode; int mode_valid; - int bus_format; }; struct bus_mux { @@ -94,6 +94,35 @@ static enum drm_connector_status imx_ldb_connector_detect( return connector_status_connected; } +static void imx_ldb_bus_format_translation(struct imx_ldb_channel *imx_ldb_ch, + u32 bus_format) +{ + struct imx_ldb *ldb = imx_ldb_ch->ldb; + int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; + + switch (bus_format) { + case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG: + imx_ldb_ch->imx_encoder.bus_format = MEDIA_BUS_FMT_RGB666_1X18; + break; + case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG: + imx_ldb_ch->imx_encoder.bus_format = MEDIA_BUS_FMT_RGB888_1X24; + if (imx_ldb_ch->chno == 0 || dual) + ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24; + if (imx_ldb_ch->chno == 1 || dual) + ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24; + break; + case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA: + imx_ldb_ch->imx_encoder.bus_format = MEDIA_BUS_FMT_RGB888_1X24; + if (imx_ldb_ch->chno == 0 || dual) + ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 | + LDB_BIT_MAP_CH0_JEIDA; + if (imx_ldb_ch->chno == 1 || dual) + ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 | + LDB_BIT_MAP_CH1_JEIDA; + break; + } +} + static int imx_ldb_connector_get_modes(struct drm_connector *connector) { struct imx_ldb_channel *imx_ldb_ch = con_to_imx_ldb_ch(connector); @@ -104,8 +133,9 @@ static int imx_ldb_connector_get_modes(struct drm_connector *connector) struct drm_display_info *di = &connector->display_info; num_modes = imx_ldb_ch->panel->funcs->get_modes(imx_ldb_ch->panel); - if (!imx_ldb_ch->bus_format && di->num_bus_formats) - imx_ldb_ch->bus_format = di->bus_formats[0]; + if (!imx_ldb_ch->imx_encoder.bus_format && di->num_bus_formats) + imx_ldb_bus_format_translation(imx_ldb_ch, + di->bus_formats[0]); if (num_modes > 0) return num_modes; } @@ -139,7 +169,7 @@ static struct drm_encoder *imx_ldb_connector_best_encoder( { struct imx_ldb_channel *imx_ldb_ch = con_to_imx_ldb_ch(connector); - return &imx_ldb_ch->encoder; + return &imx_ldb_ch->imx_encoder.encoder; } static void imx_ldb_encoder_dpms(struct drm_encoder *encoder, int mode) @@ -174,45 +204,10 @@ static void imx_ldb_set_clock(struct imx_ldb *ldb, int mux, int chno, chno); } -static void imx_ldb_encoder_prepare(struct drm_encoder *encoder) -{ - struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); - struct imx_ldb *ldb = imx_ldb_ch->ldb; - int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; - u32 bus_format; - - switch (imx_ldb_ch->bus_format) { - default: - dev_warn(ldb->dev, - "could not determine data mapping, default to 18-bit \"spwg\"\n"); - /* fallthrough */ - case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG: - bus_format = MEDIA_BUS_FMT_RGB666_1X18; - break; - case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG: - bus_format = MEDIA_BUS_FMT_RGB888_1X24; - if (imx_ldb_ch->chno == 0 || dual) - ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24; - if (imx_ldb_ch->chno == 1 || dual) - ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24; - break; - case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA: - bus_format = MEDIA_BUS_FMT_RGB888_1X24; - if (imx_ldb_ch->chno == 0 || dual) - ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 | - LDB_BIT_MAP_CH0_JEIDA; - if (imx_ldb_ch->chno == 1 || dual) - ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 | - LDB_BIT_MAP_CH1_JEIDA; - break; - } - - imx_drm_set_bus_format(encoder, bus_format); -} - 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_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_ldb_channel *imx_ldb_ch = imx_enc_to_imx_ldb_ch(imx_encoder); struct imx_ldb *ldb = imx_ldb_ch->ldb; int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); @@ -260,7 +255,8 @@ static void imx_ldb_encoder_mode_set(struct drm_encoder *encoder, struct drm_display_mode *orig_mode, struct drm_display_mode *mode) { - struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_ldb_channel *imx_ldb_ch = imx_enc_to_imx_ldb_ch(imx_encoder); struct imx_ldb *ldb = imx_ldb_ch->ldb; int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; unsigned long serial_clk; @@ -303,7 +299,8 @@ static void imx_ldb_encoder_mode_set(struct drm_encoder *encoder, static void imx_ldb_encoder_disable(struct drm_encoder *encoder) { - struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_ldb_channel *imx_ldb_ch = imx_enc_to_imx_ldb_ch(imx_encoder); struct imx_ldb *ldb = imx_ldb_ch->ldb; int mux, ret; @@ -379,7 +376,6 @@ static const struct drm_encoder_funcs imx_ldb_encoder_funcs = { static const struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = { .dpms = imx_ldb_encoder_dpms, - .prepare = imx_ldb_encoder_prepare, .commit = imx_ldb_encoder_commit, .mode_set = imx_ldb_encoder_mode_set, .disable = imx_ldb_encoder_disable, @@ -406,7 +402,7 @@ static int imx_ldb_register(struct drm_device *drm, struct imx_ldb *ldb = imx_ldb_ch->ldb; int ret; - ret = imx_drm_encoder_parse_of(drm, &imx_ldb_ch->encoder, + ret = imx_drm_encoder_parse_of(drm, &imx_ldb_ch->imx_encoder.encoder, imx_ldb_ch->child); if (ret) return ret; @@ -421,10 +417,10 @@ static int imx_ldb_register(struct drm_device *drm, return ret; } - drm_encoder_helper_add(&imx_ldb_ch->encoder, + drm_encoder_helper_add(&imx_ldb_ch->imx_encoder.encoder, &imx_ldb_encoder_helper_funcs); - drm_encoder_init(drm, &imx_ldb_ch->encoder, &imx_ldb_encoder_funcs, - DRM_MODE_ENCODER_LVDS, NULL); + drm_encoder_init(drm, &imx_ldb_ch->imx_encoder.encoder, + &imx_ldb_encoder_funcs, DRM_MODE_ENCODER_LVDS, NULL); drm_connector_helper_add(&imx_ldb_ch->connector, &imx_ldb_connector_helper_funcs); @@ -435,7 +431,7 @@ static int imx_ldb_register(struct drm_device *drm, drm_panel_attach(imx_ldb_ch->panel, &imx_ldb_ch->connector); drm_mode_connector_attach_encoder(&imx_ldb_ch->connector, - &imx_ldb_ch->encoder); + &imx_ldb_ch->imx_encoder.encoder); return 0; } @@ -564,6 +560,7 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data) struct imx_ldb_channel *channel; struct device_node *ddc_node; struct device_node *ep; + int bus_format; ret = of_property_read_u32(child, "reg", &i); if (ret || i < 0 || i > 1) @@ -636,21 +633,25 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data) } } - channel->bus_format = of_get_bus_format(dev, child); - if (channel->bus_format == -EINVAL) { + bus_format = of_get_bus_format(dev, child); + if (bus_format == -EINVAL) { /* * If no bus format was specified in the device tree, * we can still get it from the connected panel later. */ if (channel->panel && channel->panel->funcs && channel->panel->funcs->get_modes) - channel->bus_format = 0; + bus_format = 0; } - if (channel->bus_format < 0) { + if (bus_format < 0) { dev_err(dev, "could not determine data mapping: %d\n", - channel->bus_format); - return channel->bus_format; + bus_format); + return bus_format; } + imx_ldb_bus_format_translation(channel, bus_format); + + channel->imx_encoder.di_hsync_pin = 2; + channel->imx_encoder.di_vsync_pin = 3; ret = imx_ldb_register(drm, channel); if (ret) @@ -675,7 +676,8 @@ static void imx_ldb_unbind(struct device *dev, struct device *master, continue; channel->connector.funcs->destroy(&channel->connector); - channel->encoder.funcs->destroy(&channel->encoder); + channel->imx_encoder.encoder.funcs->destroy( + &channel->imx_encoder.encoder); kfree(channel->edid); i2c_put_adapter(channel->ddc); diff --git a/drivers/gpu/drm/imx/imx-tve.c b/drivers/gpu/drm/imx/imx-tve.c index 0b0aeee5c5f0..82a1edd74f20 100644 --- a/drivers/gpu/drm/imx/imx-tve.c +++ b/drivers/gpu/drm/imx/imx-tve.c @@ -99,7 +99,7 @@ #define TVE_TVDAC_TEST_MODE_MASK (0x7 << 0) #define con_to_tve(x) container_of(x, struct imx_tve, connector) -#define enc_to_tve(x) container_of(x, struct imx_tve, encoder) +#define imx_enc_to_tve(x) container_of(x, struct imx_tve, imx_encoder) enum { TVE_MODE_TVOUT, @@ -108,7 +108,7 @@ enum { struct imx_tve { struct drm_connector connector; - struct drm_encoder encoder; + struct imx_drm_encoder imx_encoder; struct device *dev; spinlock_t lock; /* register lock */ bool enabled; @@ -121,8 +121,6 @@ struct imx_tve { struct clk *di_sel_clk; struct clk_hw clk_hw_di; struct clk *di_clk; - int vsync_pin; - int hsync_pin; }; static void tve_lock(void *__tve) @@ -273,12 +271,13 @@ static struct drm_encoder *imx_tve_connector_best_encoder( { struct imx_tve *tve = con_to_tve(connector); - return &tve->encoder; + return &tve->imx_encoder.encoder; } static void imx_tve_encoder_dpms(struct drm_encoder *encoder, int mode) { - struct imx_tve *tve = enc_to_tve(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_tve *tve = imx_enc_to_tve(imx_encoder); int ret; ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, @@ -287,30 +286,12 @@ static void imx_tve_encoder_dpms(struct drm_encoder *encoder, int mode) dev_err(tve->dev, "failed to disable TVOUT: %d\n", ret); } -static void imx_tve_encoder_prepare(struct drm_encoder *encoder) -{ - struct imx_tve *tve = enc_to_tve(encoder); - - tve_disable(tve); - - switch (tve->mode) { - case TVE_MODE_VGA: - imx_drm_set_bus_config(encoder, MEDIA_BUS_FMT_GBR888_1X24, - tve->hsync_pin, tve->vsync_pin, - DRM_BUS_FLAG_DE_HIGH | - DRM_BUS_FLAG_PIXDATA_NEGEDGE); - break; - case TVE_MODE_TVOUT: - imx_drm_set_bus_format(encoder, MEDIA_BUS_FMT_YUV8_1X24); - break; - } -} - static void imx_tve_encoder_mode_set(struct drm_encoder *encoder, struct drm_display_mode *orig_mode, struct drm_display_mode *mode) { - struct imx_tve *tve = enc_to_tve(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_tve *tve = imx_enc_to_tve(imx_encoder); unsigned long rounded_rate; unsigned long rate; int div = 1; @@ -344,14 +325,16 @@ static void imx_tve_encoder_mode_set(struct drm_encoder *encoder, static void imx_tve_encoder_commit(struct drm_encoder *encoder) { - struct imx_tve *tve = enc_to_tve(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_tve *tve = imx_enc_to_tve(imx_encoder); tve_enable(tve); } static void imx_tve_encoder_disable(struct drm_encoder *encoder) { - struct imx_tve *tve = enc_to_tve(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_tve *tve = imx_enc_to_tve(imx_encoder); tve_disable(tve); } @@ -378,7 +361,6 @@ static const struct drm_encoder_funcs imx_tve_encoder_funcs = { static const struct drm_encoder_helper_funcs imx_tve_encoder_helper_funcs = { .dpms = imx_tve_encoder_dpms, - .prepare = imx_tve_encoder_prepare, .mode_set = imx_tve_encoder_mode_set, .commit = imx_tve_encoder_commit, .disable = imx_tve_encoder_disable, @@ -499,13 +481,14 @@ static int imx_tve_register(struct drm_device *drm, struct imx_tve *tve) encoder_type = tve->mode == TVE_MODE_VGA ? DRM_MODE_ENCODER_DAC : DRM_MODE_ENCODER_TVDAC; - ret = imx_drm_encoder_parse_of(drm, &tve->encoder, + ret = imx_drm_encoder_parse_of(drm, &tve->imx_encoder.encoder, tve->dev->of_node); if (ret) return ret; - drm_encoder_helper_add(&tve->encoder, &imx_tve_encoder_helper_funcs); - drm_encoder_init(drm, &tve->encoder, &imx_tve_encoder_funcs, + drm_encoder_helper_add(&tve->imx_encoder.encoder, + &imx_tve_encoder_helper_funcs); + drm_encoder_init(drm, &tve->imx_encoder.encoder, &imx_tve_encoder_funcs, encoder_type, NULL); drm_connector_helper_add(&tve->connector, @@ -513,7 +496,8 @@ static int imx_tve_register(struct drm_device *drm, struct imx_tve *tve) drm_connector_init(drm, &tve->connector, &imx_tve_connector_funcs, DRM_MODE_CONNECTOR_VGA); - drm_mode_connector_attach_encoder(&tve->connector, &tve->encoder); + drm_mode_connector_attach_encoder(&tve->connector, + &tve->imx_encoder.encoder); return 0; } @@ -591,7 +575,7 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) if (tve->mode == TVE_MODE_VGA) { ret = of_property_read_u32(np, "fsl,hsync-pin", - &tve->hsync_pin); + &tve->imx_encoder.di_hsync_pin); if (ret < 0) { dev_err(dev, "failed to get vsync pin\n"); @@ -599,12 +583,14 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) } ret |= of_property_read_u32(np, "fsl,vsync-pin", - &tve->vsync_pin); + &tve->imx_encoder.di_vsync_pin); if (ret < 0) { dev_err(dev, "failed to get vsync pin\n"); return ret; } + + tve->imx_encoder.bus_format = MEDIA_BUS_FMT_GBR888_1X24; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -693,7 +679,7 @@ static void imx_tve_unbind(struct device *dev, struct device *master, struct imx_tve *tve = dev_get_drvdata(dev); tve->connector.funcs->destroy(&tve->connector); - tve->encoder.funcs->destroy(&tve->encoder); + tve->imx_encoder.encoder.funcs->destroy(&tve->imx_encoder.encoder); if (!IS_ERR(tve->dac_reg)) regulator_disable(tve->dac_reg); diff --git a/drivers/gpu/drm/imx/ipuv3-crtc.c b/drivers/gpu/drm/imx/ipuv3-crtc.c index 7df51e81d895..f9d5d7c5cd79 100644 --- a/drivers/gpu/drm/imx/ipuv3-crtc.c +++ b/drivers/gpu/drm/imx/ipuv3-crtc.c @@ -67,10 +67,6 @@ struct ipu_crtc { struct workqueue_struct *flip_queue; struct ipu_flip_work *flip_work; int irq; - u32 bus_format; - u32 bus_flags; - int di_hsync_pin; - int di_vsync_pin; }; #define to_ipu_crtc(x) container_of(x, struct ipu_crtc, base) @@ -321,6 +317,7 @@ static void ipu_crtc_mode_set_nofb(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; struct drm_encoder *encoder; + struct imx_drm_encoder *imx_encoder = NULL; struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); struct drm_display_mode *mode = &crtc->state->adjusted_mode; struct ipu_di_signal_cfg sig_cfg = {}; @@ -331,9 +328,12 @@ static void ipu_crtc_mode_set_nofb(struct drm_crtc *crtc) dev_dbg(ipu_crtc->dev, "%s: mode->vdisplay: %d\n", __func__, mode->vdisplay); - list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) - if (encoder->crtc == crtc) + list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { + if (encoder->crtc == crtc) { encoder_types |= BIT(encoder->encoder_type); + imx_encoder = enc_to_imx_enc(encoder); + } + } dev_dbg(ipu_crtc->dev, "%s: attached to encoder types 0x%lx\n", __func__, encoder_types); @@ -351,20 +351,20 @@ static void ipu_crtc_mode_set_nofb(struct drm_crtc *crtc) else sig_cfg.clkflags = 0; - sig_cfg.enable_pol = !(ipu_crtc->bus_flags & DRM_BUS_FLAG_DE_LOW); + sig_cfg.enable_pol = !(imx_encoder->bus_flags & DRM_BUS_FLAG_DE_LOW); /* Default to driving pixel data on negative clock edges */ - sig_cfg.clk_pol = !!(ipu_crtc->bus_flags & + sig_cfg.clk_pol = !!(imx_encoder->bus_flags & DRM_BUS_FLAG_PIXDATA_POSEDGE); - sig_cfg.bus_format = ipu_crtc->bus_format; + sig_cfg.bus_format = imx_encoder->bus_format; sig_cfg.v_to_h_sync = 0; - sig_cfg.hsync_pin = ipu_crtc->di_hsync_pin; - sig_cfg.vsync_pin = ipu_crtc->di_vsync_pin; + sig_cfg.hsync_pin = imx_encoder->di_hsync_pin; + sig_cfg.vsync_pin = imx_encoder->di_vsync_pin; drm_display_mode_to_videomode(mode, &sig_cfg.mode); ipu_dc_init_sync(ipu_crtc->dc, ipu_crtc->di, mode->flags & DRM_MODE_FLAG_INTERLACE, - ipu_crtc->bus_format, mode->hdisplay); + imx_encoder->bus_format, mode->hdisplay); ipu_di_init_sync_panel(ipu_crtc->di, &sig_cfg); } @@ -402,23 +402,9 @@ static void ipu_disable_vblank(struct drm_crtc *crtc) disable_irq_nosync(ipu_crtc->irq); } -static int ipu_set_interface_pix_fmt(struct drm_crtc *crtc, - u32 bus_format, int hsync_pin, int vsync_pin, u32 bus_flags) -{ - struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); - - ipu_crtc->bus_format = bus_format; - ipu_crtc->bus_flags = bus_flags; - ipu_crtc->di_hsync_pin = hsync_pin; - ipu_crtc->di_vsync_pin = vsync_pin; - - return 0; -} - static const struct imx_drm_crtc_helper_funcs ipu_crtc_helper_funcs = { .enable_vblank = ipu_enable_vblank, .disable_vblank = ipu_disable_vblank, - .set_interface_pix_fmt = ipu_set_interface_pix_fmt, .crtc_funcs = &ipu_crtc_funcs, .crtc_helper_funcs = &ipu_helper_funcs, }; diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c index 9fe88c9b4b0d..7374d824a6d1 100644 --- a/drivers/gpu/drm/imx/parallel-display.c +++ b/drivers/gpu/drm/imx/parallel-display.c @@ -27,15 +27,15 @@ #include "imx-drm.h" #define con_to_imxpd(x) container_of(x, struct imx_parallel_display, connector) -#define enc_to_imxpd(x) container_of(x, struct imx_parallel_display, encoder) +#define imx_enc_to_imxpd(x) \ + container_of(x, struct imx_parallel_display, imx_encoder) struct imx_parallel_display { struct drm_connector connector; - struct drm_encoder encoder; + struct imx_drm_encoder imx_encoder; struct device *dev; void *edid; int edid_len; - u32 bus_format; struct drm_display_mode mode; struct drm_panel *panel; }; @@ -57,8 +57,9 @@ static int imx_pd_connector_get_modes(struct drm_connector *connector) struct drm_display_info *di = &connector->display_info; num_modes = imxpd->panel->funcs->get_modes(imxpd->panel); - if (!imxpd->bus_format && di->num_bus_formats) - imxpd->bus_format = di->bus_formats[0]; + if (!imxpd->imx_encoder.bus_format && di->num_bus_formats) + imxpd->imx_encoder.bus_format = di->bus_formats[0]; + imxpd->imx_encoder.bus_flags = di->bus_flags; if (num_modes > 0) return num_modes; } @@ -88,12 +89,13 @@ static struct drm_encoder *imx_pd_connector_best_encoder( { struct imx_parallel_display *imxpd = con_to_imxpd(connector); - return &imxpd->encoder; + return &imxpd->imx_encoder.encoder; } static void imx_pd_encoder_dpms(struct drm_encoder *encoder, int mode) { - struct imx_parallel_display *imxpd = enc_to_imxpd(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_parallel_display *imxpd = imx_enc_to_imxpd(imx_encoder); if (mode != DRM_MODE_DPMS_ON) drm_panel_disable(imxpd->panel); @@ -101,16 +103,10 @@ static void imx_pd_encoder_dpms(struct drm_encoder *encoder, int mode) drm_panel_enable(imxpd->panel); } -static void imx_pd_encoder_prepare(struct drm_encoder *encoder) -{ - struct imx_parallel_display *imxpd = enc_to_imxpd(encoder); - imx_drm_set_bus_config(encoder, imxpd->bus_format, 2, 3, - imxpd->connector.display_info.bus_flags); -} - static void imx_pd_encoder_commit(struct drm_encoder *encoder) { - struct imx_parallel_display *imxpd = enc_to_imxpd(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_parallel_display *imxpd = imx_enc_to_imxpd(imx_encoder); drm_panel_prepare(imxpd->panel); drm_panel_enable(imxpd->panel); @@ -124,7 +120,8 @@ static void imx_pd_encoder_mode_set(struct drm_encoder *encoder, static void imx_pd_encoder_disable(struct drm_encoder *encoder) { - struct imx_parallel_display *imxpd = enc_to_imxpd(encoder); + struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); + struct imx_parallel_display *imxpd = imx_enc_to_imxpd(imx_encoder); drm_panel_disable(imxpd->panel); drm_panel_unprepare(imxpd->panel); @@ -151,7 +148,6 @@ static const struct drm_encoder_funcs imx_pd_encoder_funcs = { static const struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = { .dpms = imx_pd_encoder_dpms, - .prepare = imx_pd_encoder_prepare, .commit = imx_pd_encoder_commit, .mode_set = imx_pd_encoder_mode_set, .disable = imx_pd_encoder_disable, @@ -162,7 +158,7 @@ static int imx_pd_register(struct drm_device *drm, { int ret; - ret = imx_drm_encoder_parse_of(drm, &imxpd->encoder, + ret = imx_drm_encoder_parse_of(drm, &imxpd->imx_encoder.encoder, imxpd->dev->of_node); if (ret) return ret; @@ -174,9 +170,10 @@ static int imx_pd_register(struct drm_device *drm, */ imxpd->connector.dpms = DRM_MODE_DPMS_OFF; - drm_encoder_helper_add(&imxpd->encoder, &imx_pd_encoder_helper_funcs); - drm_encoder_init(drm, &imxpd->encoder, &imx_pd_encoder_funcs, - DRM_MODE_ENCODER_NONE, NULL); + drm_encoder_helper_add(&imxpd->imx_encoder.encoder, + &imx_pd_encoder_helper_funcs); + drm_encoder_init(drm, &imxpd->imx_encoder.encoder, + &imx_pd_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL); drm_connector_helper_add(&imxpd->connector, &imx_pd_connector_helper_funcs); @@ -186,7 +183,8 @@ static int imx_pd_register(struct drm_device *drm, if (imxpd->panel) drm_panel_attach(imxpd->panel, &imxpd->connector); - drm_mode_connector_attach_encoder(&imxpd->connector, &imxpd->encoder); + drm_mode_connector_attach_encoder(&imxpd->connector, + &imxpd->imx_encoder.encoder); return 0; } @@ -199,6 +197,7 @@ static int imx_pd_bind(struct device *dev, struct device *master, void *data) const u8 *edidp; struct imx_parallel_display *imxpd; int ret; + u32 bus_format = 0; const char *fmt; imxpd = devm_kzalloc(dev, sizeof(*imxpd), GFP_KERNEL); @@ -212,14 +211,17 @@ static int imx_pd_bind(struct device *dev, struct device *master, void *data) ret = of_property_read_string(np, "interface-pix-fmt", &fmt); if (!ret) { if (!strcmp(fmt, "rgb24")) - imxpd->bus_format = MEDIA_BUS_FMT_RGB888_1X24; + bus_format = MEDIA_BUS_FMT_RGB888_1X24; else if (!strcmp(fmt, "rgb565")) - imxpd->bus_format = MEDIA_BUS_FMT_RGB565_1X16; + bus_format = MEDIA_BUS_FMT_RGB565_1X16; else if (!strcmp(fmt, "bgr666")) - imxpd->bus_format = MEDIA_BUS_FMT_RGB666_1X18; + bus_format = MEDIA_BUS_FMT_RGB666_1X18; else if (!strcmp(fmt, "lvds666")) - imxpd->bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI; + bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI; } + imxpd->imx_encoder.bus_format = bus_format; + imxpd->imx_encoder.di_hsync_pin = 2; + imxpd->imx_encoder.di_vsync_pin = 3; /* port@1 is the output port */ ep = of_graph_get_endpoint_by_regs(np, 1, -1); @@ -252,7 +254,7 @@ static void imx_pd_unbind(struct device *dev, struct device *master, { struct imx_parallel_display *imxpd = dev_get_drvdata(dev); - imxpd->encoder.funcs->destroy(&imxpd->encoder); + imxpd->imx_encoder.encoder.funcs->destroy(&imxpd->imx_encoder.encoder); imxpd->connector.funcs->destroy(&imxpd->connector); kfree(imxpd->edid); -- cgit v1.2.3 From f6e396e5096dec2523fade421bc27f3fae38e31d Mon Sep 17 00:00:00 2001 From: Liu Ying Date: Fri, 8 Jul 2016 17:41:01 +0800 Subject: drm/imx: atomic phase 3 step 2: Legacy callback fixups Now that we can use atomic configurations, all the legacy callbacks of CRTCs, encoders and connectors can be switched to the atomic version. For the imx-ldb driver, there is a clock parent setting mismatch bewteen ->enable and ->disable after the switch, so a fixup is added. For the imx-tve driver, since the encoder's callback ->dpms is replaced by ->disable, we need to move the setting for the IPU_CLK_EN bit(in register TVE_COM_CONF_REG) from ->enable/->disable to ->mode_set, otherwise, the relevant CRTC cannot be disabled correctly with a warning on DC stop timeout. Signed-off-by: Liu Ying Acked-by: Daniel Vetter Signed-off-by: Philipp Zabel --- drivers/gpu/drm/imx/dw_hdmi-imx.c | 4 ++-- drivers/gpu/drm/imx/imx-ldb.c | 16 ++++++------- drivers/gpu/drm/imx/imx-tve.c | 27 +++++++-------------- drivers/gpu/drm/imx/ipuv3-crtc.c | 44 +++++----------------------------- drivers/gpu/drm/imx/parallel-display.c | 18 +++----------- 5 files changed, 27 insertions(+), 82 deletions(-) (limited to 'drivers/gpu/drm/imx/parallel-display.c') diff --git a/drivers/gpu/drm/imx/dw_hdmi-imx.c b/drivers/gpu/drm/imx/dw_hdmi-imx.c index 5f646748960a..5f1d437405f8 100644 --- a/drivers/gpu/drm/imx/dw_hdmi-imx.c +++ b/drivers/gpu/drm/imx/dw_hdmi-imx.c @@ -117,7 +117,7 @@ static void dw_hdmi_imx_encoder_mode_set(struct drm_encoder *encoder, { } -static void dw_hdmi_imx_encoder_commit(struct drm_encoder *encoder) +static void dw_hdmi_imx_encoder_enable(struct drm_encoder *encoder) { struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); struct imx_hdmi *hdmi = imx_enc_to_imx_hdmi(imx_encoder); @@ -130,7 +130,7 @@ static void dw_hdmi_imx_encoder_commit(struct drm_encoder *encoder) static const struct drm_encoder_helper_funcs dw_hdmi_imx_encoder_helper_funcs = { .mode_set = dw_hdmi_imx_encoder_mode_set, - .commit = dw_hdmi_imx_encoder_commit, + .enable = dw_hdmi_imx_encoder_enable, .disable = dw_hdmi_imx_encoder_disable, }; diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index 6e110bba35cb..9c48c4b23a8c 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -172,10 +172,6 @@ static struct drm_encoder *imx_ldb_connector_best_encoder( return &imx_ldb_ch->imx_encoder.encoder; } -static void imx_ldb_encoder_dpms(struct drm_encoder *encoder, int mode) -{ -} - static void imx_ldb_set_clock(struct imx_ldb *ldb, int mux, int chno, unsigned long serial_clk, unsigned long di_clk) { @@ -204,7 +200,7 @@ static void imx_ldb_set_clock(struct imx_ldb *ldb, int mux, int chno, chno); } -static void imx_ldb_encoder_commit(struct drm_encoder *encoder) +static void imx_ldb_encoder_enable(struct drm_encoder *encoder) { struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); struct imx_ldb_channel *imx_ldb_ch = imx_enc_to_imx_ldb_ch(imx_encoder); @@ -215,8 +211,13 @@ static void imx_ldb_encoder_commit(struct drm_encoder *encoder) drm_panel_prepare(imx_ldb_ch->panel); if (dual) { + clk_set_parent(ldb->clk_sel[mux], ldb->clk[0]); + clk_set_parent(ldb->clk_sel[mux], ldb->clk[1]); + clk_prepare_enable(ldb->clk[0]); clk_prepare_enable(ldb->clk[1]); + } else { + clk_set_parent(ldb->clk_sel[mux], ldb->clk[imx_ldb_ch->chno]); } if (imx_ldb_ch == &ldb->channel[0] || dual) { @@ -356,7 +357,7 @@ static void imx_ldb_encoder_disable(struct drm_encoder *encoder) } static const struct drm_connector_funcs imx_ldb_connector_funcs = { - .dpms = drm_helper_connector_dpms, + .dpms = drm_atomic_helper_connector_dpms, .fill_modes = drm_helper_probe_single_connector_modes, .detect = imx_ldb_connector_detect, .destroy = imx_drm_connector_destroy, @@ -375,9 +376,8 @@ static const struct drm_encoder_funcs imx_ldb_encoder_funcs = { }; static const struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = { - .dpms = imx_ldb_encoder_dpms, - .commit = imx_ldb_encoder_commit, .mode_set = imx_ldb_encoder_mode_set, + .enable = imx_ldb_encoder_enable, .disable = imx_ldb_encoder_disable, }; diff --git a/drivers/gpu/drm/imx/imx-tve.c b/drivers/gpu/drm/imx/imx-tve.c index 82a1edd74f20..cd92aac5c3bc 100644 --- a/drivers/gpu/drm/imx/imx-tve.c +++ b/drivers/gpu/drm/imx/imx-tve.c @@ -147,8 +147,7 @@ static void tve_enable(struct imx_tve *tve) tve->enabled = true; clk_prepare_enable(tve->clk); ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, - TVE_IPU_CLK_EN | TVE_EN, - TVE_IPU_CLK_EN | TVE_EN); + TVE_EN, TVE_EN); } /* clear interrupt status register */ @@ -171,7 +170,7 @@ static void tve_disable(struct imx_tve *tve) if (tve->enabled) { tve->enabled = false; ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, - TVE_IPU_CLK_EN | TVE_EN, 0); + TVE_EN, 0); clk_disable_unprepare(tve->clk); } } @@ -274,18 +273,6 @@ static struct drm_encoder *imx_tve_connector_best_encoder( return &tve->imx_encoder.encoder; } -static void imx_tve_encoder_dpms(struct drm_encoder *encoder, int mode) -{ - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_tve *tve = imx_enc_to_tve(imx_encoder); - int ret; - - ret = regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, - TVE_TV_OUT_MODE_MASK, TVE_TV_OUT_DISABLE); - if (ret < 0) - dev_err(tve->dev, "failed to disable TVOUT: %d\n", ret); -} - static void imx_tve_encoder_mode_set(struct drm_encoder *encoder, struct drm_display_mode *orig_mode, struct drm_display_mode *mode) @@ -315,6 +302,9 @@ static void imx_tve_encoder_mode_set(struct drm_encoder *encoder, ret); } + regmap_update_bits(tve->regmap, TVE_COM_CONF_REG, + TVE_IPU_CLK_EN, TVE_IPU_CLK_EN); + if (tve->mode == TVE_MODE_VGA) ret = tve_setup_vga(tve); else @@ -323,7 +313,7 @@ static void imx_tve_encoder_mode_set(struct drm_encoder *encoder, dev_err(tve->dev, "failed to set configuration: %d\n", ret); } -static void imx_tve_encoder_commit(struct drm_encoder *encoder) +static void imx_tve_encoder_enable(struct drm_encoder *encoder) { struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); struct imx_tve *tve = imx_enc_to_tve(imx_encoder); @@ -340,7 +330,7 @@ static void imx_tve_encoder_disable(struct drm_encoder *encoder) } static const struct drm_connector_funcs imx_tve_connector_funcs = { - .dpms = drm_helper_connector_dpms, + .dpms = drm_atomic_helper_connector_dpms, .fill_modes = drm_helper_probe_single_connector_modes, .detect = imx_tve_connector_detect, .destroy = imx_drm_connector_destroy, @@ -360,9 +350,8 @@ static const struct drm_encoder_funcs imx_tve_encoder_funcs = { }; static const struct drm_encoder_helper_funcs imx_tve_encoder_helper_funcs = { - .dpms = imx_tve_encoder_dpms, .mode_set = imx_tve_encoder_mode_set, - .commit = imx_tve_encoder_commit, + .enable = imx_tve_encoder_enable, .disable = imx_tve_encoder_disable, }; diff --git a/drivers/gpu/drm/imx/ipuv3-crtc.c b/drivers/gpu/drm/imx/ipuv3-crtc.c index 3e8253455121..274b0e2f917c 100644 --- a/drivers/gpu/drm/imx/ipuv3-crtc.c +++ b/drivers/gpu/drm/imx/ipuv3-crtc.c @@ -48,8 +48,9 @@ struct ipu_crtc { #define to_ipu_crtc(x) container_of(x, struct ipu_crtc, base) -static void ipu_crtc_enable(struct ipu_crtc *ipu_crtc) +static void ipu_crtc_enable(struct drm_crtc *crtc) { + struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent); ipu_dc_enable(ipu); @@ -57,10 +58,10 @@ static void ipu_crtc_enable(struct ipu_crtc *ipu_crtc) ipu_di_enable(ipu_crtc->di); } -static void ipu_crtc_disable(struct ipu_crtc *ipu_crtc) +static void ipu_crtc_disable(struct drm_crtc *crtc) { + struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent); - struct drm_crtc *crtc = &ipu_crtc->base; ipu_dc_disable_channel(ipu_crtc->dc); ipu_di_disable(ipu_crtc->di); @@ -74,24 +75,6 @@ static void ipu_crtc_disable(struct ipu_crtc *ipu_crtc) spin_unlock_irq(&crtc->dev->event_lock); } -static void ipu_crtc_dpms(struct drm_crtc *crtc, int mode) -{ - struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); - - dev_dbg(ipu_crtc->dev, "%s mode: %d\n", __func__, mode); - - switch (mode) { - case DRM_MODE_DPMS_ON: - ipu_crtc_enable(ipu_crtc); - break; - case DRM_MODE_DPMS_STANDBY: - case DRM_MODE_DPMS_SUSPEND: - case DRM_MODE_DPMS_OFF: - ipu_crtc_disable(ipu_crtc); - break; - } -} - static const struct drm_crtc_funcs ipu_crtc_funcs = { .set_config = drm_atomic_helper_set_config, .destroy = drm_crtc_cleanup, @@ -132,20 +115,6 @@ static bool ipu_crtc_mode_fixup(struct drm_crtc *crtc, return true; } -static void ipu_crtc_prepare(struct drm_crtc *crtc) -{ - struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); - - ipu_crtc_disable(ipu_crtc); -} - -static void ipu_crtc_commit(struct drm_crtc *crtc) -{ - struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); - - ipu_crtc_enable(ipu_crtc); -} - static int ipu_crtc_atomic_check(struct drm_crtc *crtc, struct drm_crtc_state *state) { @@ -225,13 +194,12 @@ static void ipu_crtc_mode_set_nofb(struct drm_crtc *crtc) } static const struct drm_crtc_helper_funcs ipu_helper_funcs = { - .dpms = ipu_crtc_dpms, .mode_fixup = ipu_crtc_mode_fixup, .mode_set_nofb = ipu_crtc_mode_set_nofb, - .prepare = ipu_crtc_prepare, - .commit = ipu_crtc_commit, .atomic_check = ipu_crtc_atomic_check, .atomic_begin = ipu_crtc_atomic_begin, + .disable = ipu_crtc_disable, + .enable = ipu_crtc_enable, }; static int ipu_enable_vblank(struct drm_crtc *crtc) diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c index 7374d824a6d1..bb5dbd66fea7 100644 --- a/drivers/gpu/drm/imx/parallel-display.c +++ b/drivers/gpu/drm/imx/parallel-display.c @@ -92,18 +92,7 @@ static struct drm_encoder *imx_pd_connector_best_encoder( return &imxpd->imx_encoder.encoder; } -static void imx_pd_encoder_dpms(struct drm_encoder *encoder, int mode) -{ - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_parallel_display *imxpd = imx_enc_to_imxpd(imx_encoder); - - if (mode != DRM_MODE_DPMS_ON) - drm_panel_disable(imxpd->panel); - else - drm_panel_enable(imxpd->panel); -} - -static void imx_pd_encoder_commit(struct drm_encoder *encoder) +static void imx_pd_encoder_enable(struct drm_encoder *encoder) { struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); struct imx_parallel_display *imxpd = imx_enc_to_imxpd(imx_encoder); @@ -128,7 +117,7 @@ static void imx_pd_encoder_disable(struct drm_encoder *encoder) } static const struct drm_connector_funcs imx_pd_connector_funcs = { - .dpms = drm_helper_connector_dpms, + .dpms = drm_atomic_helper_connector_dpms, .fill_modes = drm_helper_probe_single_connector_modes, .detect = imx_pd_connector_detect, .destroy = imx_drm_connector_destroy, @@ -147,9 +136,8 @@ static const struct drm_encoder_funcs imx_pd_encoder_funcs = { }; static const struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = { - .dpms = imx_pd_encoder_dpms, - .commit = imx_pd_encoder_commit, .mode_set = imx_pd_encoder_mode_set, + .enable = imx_pd_encoder_enable, .disable = imx_pd_encoder_disable, }; -- cgit v1.2.3 From e41c5c2411bca56775663a4153e0c00ea8c8f130 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Wed, 6 Jul 2016 13:40:13 +0200 Subject: drm/imx: remove empty mode_set encoder callbacks With atomic modeset support, these callbacks are optional. Signed-off-by: Philipp Zabel --- drivers/gpu/drm/imx/dw_hdmi-imx.c | 7 ------- drivers/gpu/drm/imx/parallel-display.c | 7 ------- 2 files changed, 14 deletions(-) (limited to 'drivers/gpu/drm/imx/parallel-display.c') diff --git a/drivers/gpu/drm/imx/dw_hdmi-imx.c b/drivers/gpu/drm/imx/dw_hdmi-imx.c index 5f1d437405f8..dce1ea5f52a8 100644 --- a/drivers/gpu/drm/imx/dw_hdmi-imx.c +++ b/drivers/gpu/drm/imx/dw_hdmi-imx.c @@ -111,12 +111,6 @@ static void dw_hdmi_imx_encoder_disable(struct drm_encoder *encoder) { } -static void dw_hdmi_imx_encoder_mode_set(struct drm_encoder *encoder, - struct drm_display_mode *mode, - struct drm_display_mode *adj_mode) -{ -} - static void dw_hdmi_imx_encoder_enable(struct drm_encoder *encoder) { struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); @@ -129,7 +123,6 @@ static void dw_hdmi_imx_encoder_enable(struct drm_encoder *encoder) } static const struct drm_encoder_helper_funcs dw_hdmi_imx_encoder_helper_funcs = { - .mode_set = dw_hdmi_imx_encoder_mode_set, .enable = dw_hdmi_imx_encoder_enable, .disable = dw_hdmi_imx_encoder_disable, }; diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c index bb5dbd66fea7..4a2942ecec17 100644 --- a/drivers/gpu/drm/imx/parallel-display.c +++ b/drivers/gpu/drm/imx/parallel-display.c @@ -101,12 +101,6 @@ static void imx_pd_encoder_enable(struct drm_encoder *encoder) drm_panel_enable(imxpd->panel); } -static void imx_pd_encoder_mode_set(struct drm_encoder *encoder, - struct drm_display_mode *orig_mode, - struct drm_display_mode *mode) -{ -} - static void imx_pd_encoder_disable(struct drm_encoder *encoder) { struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); @@ -136,7 +130,6 @@ static const struct drm_encoder_funcs imx_pd_encoder_funcs = { }; static const struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = { - .mode_set = imx_pd_encoder_mode_set, .enable = imx_pd_encoder_enable, .disable = imx_pd_encoder_disable, }; -- cgit v1.2.3 From 49f98bc4d44a4ee507737f8d5531d05539787319 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Wed, 6 Jul 2016 14:49:24 +0200 Subject: drm/imx: store internal bus configuration in crtc state The internal bus configuration is imx-drm specific crtc state. Store it in imx_crtc_state and let the encoder atomic_check callbacks determine bus_flags, bus_format and the sync pins, possibly taking into account the mode and the connector display info. The custom imx_drm_encoder structure can be replaced again with drm_encoder. Signed-off-by: Philipp Zabel --- drivers/gpu/drm/imx/dw_hdmi-imx.c | 31 ++++++--- drivers/gpu/drm/imx/imx-drm.h | 9 ++- drivers/gpu/drm/imx/imx-ldb.c | 111 ++++++++++++++++++++++----------- drivers/gpu/drm/imx/imx-tve.c | 55 +++++++++------- drivers/gpu/drm/imx/ipuv3-crtc.c | 67 ++++++++++++++++---- drivers/gpu/drm/imx/parallel-display.c | 63 +++++++++++-------- 6 files changed, 229 insertions(+), 107 deletions(-) (limited to 'drivers/gpu/drm/imx/parallel-display.c') diff --git a/drivers/gpu/drm/imx/dw_hdmi-imx.c b/drivers/gpu/drm/imx/dw_hdmi-imx.c index dce1ea5f52a8..359cd2765552 100644 --- a/drivers/gpu/drm/imx/dw_hdmi-imx.c +++ b/drivers/gpu/drm/imx/dw_hdmi-imx.c @@ -22,14 +22,17 @@ #include "imx-drm.h" -#define imx_enc_to_imx_hdmi(x) container_of(x, struct imx_hdmi, imx_encoder) - struct imx_hdmi { struct device *dev; - struct imx_drm_encoder imx_encoder; + struct drm_encoder encoder; struct regmap *regmap; }; +static inline struct imx_hdmi *enc_to_imx_hdmi(struct drm_encoder *e) +{ + return container_of(e, struct imx_hdmi, encoder); +} + static const struct dw_hdmi_mpll_config imx_mpll_cfg[] = { { 45250000, { @@ -113,8 +116,7 @@ static void dw_hdmi_imx_encoder_disable(struct drm_encoder *encoder) static void dw_hdmi_imx_encoder_enable(struct drm_encoder *encoder) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_hdmi *hdmi = imx_enc_to_imx_hdmi(imx_encoder); + struct imx_hdmi *hdmi = enc_to_imx_hdmi(encoder); int mux = drm_of_encoder_active_port_id(hdmi->dev->of_node, encoder); regmap_update_bits(hdmi->regmap, IOMUXC_GPR3, @@ -122,9 +124,23 @@ static void dw_hdmi_imx_encoder_enable(struct drm_encoder *encoder) mux << IMX6Q_GPR3_HDMI_MUX_CTL_SHIFT); } +static int dw_hdmi_imx_atomic_check(struct drm_encoder *encoder, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state); + + imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24; + imx_crtc_state->di_hsync_pin = 2; + imx_crtc_state->di_vsync_pin = 3; + + return 0; +} + static const struct drm_encoder_helper_funcs dw_hdmi_imx_encoder_helper_funcs = { .enable = dw_hdmi_imx_encoder_enable, .disable = dw_hdmi_imx_encoder_disable, + .atomic_check = dw_hdmi_imx_atomic_check, }; static const struct drm_encoder_funcs dw_hdmi_imx_encoder_funcs = { @@ -205,10 +221,7 @@ static int dw_hdmi_imx_bind(struct device *dev, struct device *master, match = of_match_node(dw_hdmi_imx_dt_ids, pdev->dev.of_node); plat_data = match->data; hdmi->dev = &pdev->dev; - encoder = &hdmi->imx_encoder.encoder; - hdmi->imx_encoder.bus_format = MEDIA_BUS_FMT_RGB888_1X24; - hdmi->imx_encoder.di_hsync_pin = 2; - hdmi->imx_encoder.di_vsync_pin = 3; + encoder = &hdmi->encoder; irq = platform_get_irq(pdev, 0); if (irq < 0) diff --git a/drivers/gpu/drm/imx/imx-drm.h b/drivers/gpu/drm/imx/imx-drm.h index 39cef15c699b..07d33e45f90f 100644 --- a/drivers/gpu/drm/imx/imx-drm.h +++ b/drivers/gpu/drm/imx/imx-drm.h @@ -15,15 +15,18 @@ struct platform_device; unsigned int imx_drm_crtc_id(struct imx_drm_crtc *crtc); -struct imx_drm_encoder { - struct drm_encoder encoder; +struct imx_crtc_state { + struct drm_crtc_state base; u32 bus_format; u32 bus_flags; int di_hsync_pin; int di_vsync_pin; }; -#define enc_to_imx_enc(x) container_of(x, struct imx_drm_encoder, encoder) +static inline struct imx_crtc_state *to_imx_crtc_state(struct drm_crtc_state *s) +{ + return container_of(s, struct imx_crtc_state, base); +} struct imx_drm_crtc_helper_funcs { int (*enable_vblank)(struct drm_crtc *crtc); diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index 9c48c4b23a8c..9ac833540080 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -51,15 +52,13 @@ #define LDB_BGREF_RMODE_INT (1 << 15) #define con_to_imx_ldb_ch(x) container_of(x, struct imx_ldb_channel, connector) -#define imx_enc_to_imx_ldb_ch(x) \ - container_of(x, struct imx_ldb_channel, imx_encoder) struct imx_ldb; struct imx_ldb_channel { struct imx_ldb *ldb; struct drm_connector connector; - struct imx_drm_encoder imx_encoder; + struct drm_encoder encoder; struct drm_panel *panel; struct device_node *child; struct i2c_adapter *ddc; @@ -68,8 +67,14 @@ struct imx_ldb_channel { int edid_len; struct drm_display_mode mode; int mode_valid; + u32 bus_format; }; +static inline struct imx_ldb_channel *enc_to_imx_ldb_ch(struct drm_encoder *e) +{ + return container_of(e, struct imx_ldb_channel, encoder); +} + struct bus_mux { int reg; int shift; @@ -94,25 +99,22 @@ static enum drm_connector_status imx_ldb_connector_detect( return connector_status_connected; } -static void imx_ldb_bus_format_translation(struct imx_ldb_channel *imx_ldb_ch, - u32 bus_format) +static void imx_ldb_ch_set_bus_format(struct imx_ldb_channel *imx_ldb_ch, + u32 bus_format) { struct imx_ldb *ldb = imx_ldb_ch->ldb; int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; switch (bus_format) { case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG: - imx_ldb_ch->imx_encoder.bus_format = MEDIA_BUS_FMT_RGB666_1X18; break; case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG: - imx_ldb_ch->imx_encoder.bus_format = MEDIA_BUS_FMT_RGB888_1X24; if (imx_ldb_ch->chno == 0 || dual) ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24; if (imx_ldb_ch->chno == 1 || dual) ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24; break; case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA: - imx_ldb_ch->imx_encoder.bus_format = MEDIA_BUS_FMT_RGB888_1X24; if (imx_ldb_ch->chno == 0 || dual) ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 | LDB_BIT_MAP_CH0_JEIDA; @@ -130,12 +132,7 @@ static int imx_ldb_connector_get_modes(struct drm_connector *connector) if (imx_ldb_ch->panel && imx_ldb_ch->panel->funcs && imx_ldb_ch->panel->funcs->get_modes) { - struct drm_display_info *di = &connector->display_info; - num_modes = imx_ldb_ch->panel->funcs->get_modes(imx_ldb_ch->panel); - if (!imx_ldb_ch->imx_encoder.bus_format && di->num_bus_formats) - imx_ldb_bus_format_translation(imx_ldb_ch, - di->bus_formats[0]); if (num_modes > 0) return num_modes; } @@ -169,7 +166,7 @@ static struct drm_encoder *imx_ldb_connector_best_encoder( { struct imx_ldb_channel *imx_ldb_ch = con_to_imx_ldb_ch(connector); - return &imx_ldb_ch->imx_encoder.encoder; + return &imx_ldb_ch->encoder; } static void imx_ldb_set_clock(struct imx_ldb *ldb, int mux, int chno, @@ -202,8 +199,7 @@ static void imx_ldb_set_clock(struct imx_ldb *ldb, int mux, int chno, static void imx_ldb_encoder_enable(struct drm_encoder *encoder) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_ldb_channel *imx_ldb_ch = imx_enc_to_imx_ldb_ch(imx_encoder); + struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); struct imx_ldb *ldb = imx_ldb_ch->ldb; int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); @@ -256,13 +252,13 @@ static void imx_ldb_encoder_mode_set(struct drm_encoder *encoder, struct drm_display_mode *orig_mode, struct drm_display_mode *mode) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_ldb_channel *imx_ldb_ch = imx_enc_to_imx_ldb_ch(imx_encoder); + struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); struct imx_ldb *ldb = imx_ldb_ch->ldb; int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN; unsigned long serial_clk; unsigned long di_clk = mode->clock * 1000; int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder); + u32 bus_format = imx_ldb_ch->bus_format; if (mode->clock > 170000) { dev_warn(ldb->dev, @@ -284,24 +280,41 @@ static void imx_ldb_encoder_mode_set(struct drm_encoder *encoder, } /* FIXME - assumes straight connections DI0 --> CH0, DI1 --> CH1 */ - if (imx_ldb_ch == &ldb->channel[0]) { + if (imx_ldb_ch == &ldb->channel[0] || dual) { if (mode->flags & DRM_MODE_FLAG_NVSYNC) ldb->ldb_ctrl |= LDB_DI0_VS_POL_ACT_LOW; else if (mode->flags & DRM_MODE_FLAG_PVSYNC) ldb->ldb_ctrl &= ~LDB_DI0_VS_POL_ACT_LOW; } - if (imx_ldb_ch == &ldb->channel[1]) { + if (imx_ldb_ch == &ldb->channel[1] || dual) { if (mode->flags & DRM_MODE_FLAG_NVSYNC) ldb->ldb_ctrl |= LDB_DI1_VS_POL_ACT_LOW; else if (mode->flags & DRM_MODE_FLAG_PVSYNC) ldb->ldb_ctrl &= ~LDB_DI1_VS_POL_ACT_LOW; } + + if (!bus_format) { + struct drm_connector_state *conn_state; + struct drm_connector *connector; + int i; + + for_each_connector_in_state(encoder->crtc->state->state, + connector, conn_state, i) { + struct drm_display_info *di = &connector->display_info; + + if (conn_state->crtc == encoder->crtc && + di->num_bus_formats) { + bus_format = di->bus_formats[0]; + break; + } + } + } + imx_ldb_ch_set_bus_format(imx_ldb_ch, bus_format); } static void imx_ldb_encoder_disable(struct drm_encoder *encoder) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_ldb_channel *imx_ldb_ch = imx_enc_to_imx_ldb_ch(imx_encoder); + struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); struct imx_ldb *ldb = imx_ldb_ch->ldb; int mux, ret; @@ -356,6 +369,37 @@ static void imx_ldb_encoder_disable(struct drm_encoder *encoder) drm_panel_unprepare(imx_ldb_ch->panel); } +static int imx_ldb_encoder_atomic_check(struct drm_encoder *encoder, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state); + struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder); + struct drm_display_info *di = &conn_state->connector->display_info; + u32 bus_format = imx_ldb_ch->bus_format; + + /* Bus format description in DT overrides connector display info. */ + if (!bus_format && di->num_bus_formats) + bus_format = di->bus_formats[0]; + switch (bus_format) { + case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG: + imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB666_1X18; + break; + case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG: + case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA: + imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24; + break; + default: + return -EINVAL; + } + + imx_crtc_state->di_hsync_pin = 2; + imx_crtc_state->di_vsync_pin = 3; + + return 0; +} + + static const struct drm_connector_funcs imx_ldb_connector_funcs = { .dpms = drm_atomic_helper_connector_dpms, .fill_modes = drm_helper_probe_single_connector_modes, @@ -379,6 +423,7 @@ static const struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = { .mode_set = imx_ldb_encoder_mode_set, .enable = imx_ldb_encoder_enable, .disable = imx_ldb_encoder_disable, + .atomic_check = imx_ldb_encoder_atomic_check, }; static int imx_ldb_get_clk(struct imx_ldb *ldb, int chno) @@ -400,10 +445,10 @@ static int imx_ldb_register(struct drm_device *drm, struct imx_ldb_channel *imx_ldb_ch) { struct imx_ldb *ldb = imx_ldb_ch->ldb; + struct drm_encoder *encoder = &imx_ldb_ch->encoder; int ret; - ret = imx_drm_encoder_parse_of(drm, &imx_ldb_ch->imx_encoder.encoder, - imx_ldb_ch->child); + ret = imx_drm_encoder_parse_of(drm, encoder, imx_ldb_ch->child); if (ret) return ret; @@ -417,10 +462,9 @@ static int imx_ldb_register(struct drm_device *drm, return ret; } - drm_encoder_helper_add(&imx_ldb_ch->imx_encoder.encoder, - &imx_ldb_encoder_helper_funcs); - drm_encoder_init(drm, &imx_ldb_ch->imx_encoder.encoder, - &imx_ldb_encoder_funcs, DRM_MODE_ENCODER_LVDS, NULL); + drm_encoder_helper_add(encoder, &imx_ldb_encoder_helper_funcs); + drm_encoder_init(drm, encoder, &imx_ldb_encoder_funcs, + DRM_MODE_ENCODER_LVDS, NULL); drm_connector_helper_add(&imx_ldb_ch->connector, &imx_ldb_connector_helper_funcs); @@ -430,8 +474,7 @@ static int imx_ldb_register(struct drm_device *drm, if (imx_ldb_ch->panel) drm_panel_attach(imx_ldb_ch->panel, &imx_ldb_ch->connector); - drm_mode_connector_attach_encoder(&imx_ldb_ch->connector, - &imx_ldb_ch->imx_encoder.encoder); + drm_mode_connector_attach_encoder(&imx_ldb_ch->connector, encoder); return 0; } @@ -648,10 +691,7 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data) bus_format); return bus_format; } - imx_ldb_bus_format_translation(channel, bus_format); - - channel->imx_encoder.di_hsync_pin = 2; - channel->imx_encoder.di_vsync_pin = 3; + channel->bus_format = bus_format; ret = imx_ldb_register(drm, channel); if (ret) @@ -676,8 +716,7 @@ static void imx_ldb_unbind(struct device *dev, struct device *master, continue; channel->connector.funcs->destroy(&channel->connector); - channel->imx_encoder.encoder.funcs->destroy( - &channel->imx_encoder.encoder); + channel->encoder.funcs->destroy(&channel->encoder); kfree(channel->edid); i2c_put_adapter(channel->ddc); diff --git a/drivers/gpu/drm/imx/imx-tve.c b/drivers/gpu/drm/imx/imx-tve.c index cd92aac5c3bc..520b31228a6f 100644 --- a/drivers/gpu/drm/imx/imx-tve.c +++ b/drivers/gpu/drm/imx/imx-tve.c @@ -99,7 +99,6 @@ #define TVE_TVDAC_TEST_MODE_MASK (0x7 << 0) #define con_to_tve(x) container_of(x, struct imx_tve, connector) -#define imx_enc_to_tve(x) container_of(x, struct imx_tve, imx_encoder) enum { TVE_MODE_TVOUT, @@ -108,11 +107,13 @@ enum { struct imx_tve { struct drm_connector connector; - struct imx_drm_encoder imx_encoder; + struct drm_encoder encoder; struct device *dev; spinlock_t lock; /* register lock */ bool enabled; int mode; + int di_hsync_pin; + int di_vsync_pin; struct regmap *regmap; struct regulator *dac_reg; @@ -123,6 +124,11 @@ struct imx_tve { struct clk *di_clk; }; +static inline struct imx_tve *enc_to_tve(struct drm_encoder *e) +{ + return container_of(e, struct imx_tve, encoder); +} + static void tve_lock(void *__tve) __acquires(&tve->lock) { @@ -270,15 +276,14 @@ static struct drm_encoder *imx_tve_connector_best_encoder( { struct imx_tve *tve = con_to_tve(connector); - return &tve->imx_encoder.encoder; + return &tve->encoder; } static void imx_tve_encoder_mode_set(struct drm_encoder *encoder, struct drm_display_mode *orig_mode, struct drm_display_mode *mode) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_tve *tve = imx_enc_to_tve(imx_encoder); + struct imx_tve *tve = enc_to_tve(encoder); unsigned long rounded_rate; unsigned long rate; int div = 1; @@ -315,20 +320,32 @@ static void imx_tve_encoder_mode_set(struct drm_encoder *encoder, static void imx_tve_encoder_enable(struct drm_encoder *encoder) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_tve *tve = imx_enc_to_tve(imx_encoder); + struct imx_tve *tve = enc_to_tve(encoder); tve_enable(tve); } static void imx_tve_encoder_disable(struct drm_encoder *encoder) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_tve *tve = imx_enc_to_tve(imx_encoder); + struct imx_tve *tve = enc_to_tve(encoder); tve_disable(tve); } +static int imx_tve_atomic_check(struct drm_encoder *encoder, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state); + struct imx_tve *tve = enc_to_tve(encoder); + + imx_crtc_state->bus_format = MEDIA_BUS_FMT_GBR888_1X24; + imx_crtc_state->di_hsync_pin = tve->di_hsync_pin; + imx_crtc_state->di_vsync_pin = tve->di_vsync_pin; + + return 0; +} + static const struct drm_connector_funcs imx_tve_connector_funcs = { .dpms = drm_atomic_helper_connector_dpms, .fill_modes = drm_helper_probe_single_connector_modes, @@ -353,6 +370,7 @@ static const struct drm_encoder_helper_funcs imx_tve_encoder_helper_funcs = { .mode_set = imx_tve_encoder_mode_set, .enable = imx_tve_encoder_enable, .disable = imx_tve_encoder_disable, + .atomic_check = imx_tve_atomic_check, }; static irqreturn_t imx_tve_irq_handler(int irq, void *data) @@ -470,14 +488,12 @@ static int imx_tve_register(struct drm_device *drm, struct imx_tve *tve) encoder_type = tve->mode == TVE_MODE_VGA ? DRM_MODE_ENCODER_DAC : DRM_MODE_ENCODER_TVDAC; - ret = imx_drm_encoder_parse_of(drm, &tve->imx_encoder.encoder, - tve->dev->of_node); + ret = imx_drm_encoder_parse_of(drm, &tve->encoder, tve->dev->of_node); if (ret) return ret; - drm_encoder_helper_add(&tve->imx_encoder.encoder, - &imx_tve_encoder_helper_funcs); - drm_encoder_init(drm, &tve->imx_encoder.encoder, &imx_tve_encoder_funcs, + drm_encoder_helper_add(&tve->encoder, &imx_tve_encoder_helper_funcs); + drm_encoder_init(drm, &tve->encoder, &imx_tve_encoder_funcs, encoder_type, NULL); drm_connector_helper_add(&tve->connector, @@ -485,8 +501,7 @@ static int imx_tve_register(struct drm_device *drm, struct imx_tve *tve) drm_connector_init(drm, &tve->connector, &imx_tve_connector_funcs, DRM_MODE_CONNECTOR_VGA); - drm_mode_connector_attach_encoder(&tve->connector, - &tve->imx_encoder.encoder); + drm_mode_connector_attach_encoder(&tve->connector, &tve->encoder); return 0; } @@ -564,7 +579,7 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) if (tve->mode == TVE_MODE_VGA) { ret = of_property_read_u32(np, "fsl,hsync-pin", - &tve->imx_encoder.di_hsync_pin); + &tve->di_hsync_pin); if (ret < 0) { dev_err(dev, "failed to get vsync pin\n"); @@ -572,14 +587,12 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data) } ret |= of_property_read_u32(np, "fsl,vsync-pin", - &tve->imx_encoder.di_vsync_pin); + &tve->di_vsync_pin); if (ret < 0) { dev_err(dev, "failed to get vsync pin\n"); return ret; } - - tve->imx_encoder.bus_format = MEDIA_BUS_FMT_GBR888_1X24; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -668,7 +681,7 @@ static void imx_tve_unbind(struct device *dev, struct device *master, struct imx_tve *tve = dev_get_drvdata(dev); tve->connector.funcs->destroy(&tve->connector); - tve->imx_encoder.encoder.funcs->destroy(&tve->imx_encoder.encoder); + tve->encoder.funcs->destroy(&tve->encoder); if (!IS_ERR(tve->dac_reg)) regulator_disable(tve->dac_reg); diff --git a/drivers/gpu/drm/imx/ipuv3-crtc.c b/drivers/gpu/drm/imx/ipuv3-crtc.c index 274b0e2f917c..2791ef070e2e 100644 --- a/drivers/gpu/drm/imx/ipuv3-crtc.c +++ b/drivers/gpu/drm/imx/ipuv3-crtc.c @@ -75,13 +75,56 @@ static void ipu_crtc_disable(struct drm_crtc *crtc) spin_unlock_irq(&crtc->dev->event_lock); } +static void imx_drm_crtc_reset(struct drm_crtc *crtc) +{ + struct imx_crtc_state *state; + + if (crtc->state) { + if (crtc->state->mode_blob) + drm_property_unreference_blob(crtc->state->mode_blob); + + state = to_imx_crtc_state(crtc->state); + memset(state, 0, sizeof(*state)); + } else { + state = kzalloc(sizeof(*state), GFP_KERNEL); + if (!state) + return; + crtc->state = &state->base; + } + + state->base.crtc = crtc; +} + +static struct drm_crtc_state *imx_drm_crtc_duplicate_state(struct drm_crtc *crtc) +{ + struct imx_crtc_state *state; + + state = kzalloc(sizeof(*state), GFP_KERNEL); + if (!state) + return NULL; + + __drm_atomic_helper_crtc_duplicate_state(crtc, &state->base); + + WARN_ON(state->base.crtc != crtc); + state->base.crtc = crtc; + + return &state->base; +} + +static void imx_drm_crtc_destroy_state(struct drm_crtc *crtc, + struct drm_crtc_state *state) +{ + __drm_atomic_helper_crtc_destroy_state(state); + kfree(to_imx_crtc_state(state)); +} + static const struct drm_crtc_funcs ipu_crtc_funcs = { .set_config = drm_atomic_helper_set_config, .destroy = drm_crtc_cleanup, .page_flip = drm_atomic_helper_page_flip, - .reset = drm_atomic_helper_crtc_reset, - .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, + .reset = imx_drm_crtc_reset, + .atomic_duplicate_state = imx_drm_crtc_duplicate_state, + .atomic_destroy_state = imx_drm_crtc_destroy_state, }; static irqreturn_t ipu_irq_handler(int irq, void *dev_id) @@ -142,9 +185,9 @@ static void ipu_crtc_mode_set_nofb(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; struct drm_encoder *encoder; - struct imx_drm_encoder *imx_encoder = NULL; struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc); struct drm_display_mode *mode = &crtc->state->adjusted_mode; + struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc->state); struct ipu_di_signal_cfg sig_cfg = {}; unsigned long encoder_types = 0; @@ -154,10 +197,8 @@ static void ipu_crtc_mode_set_nofb(struct drm_crtc *crtc) mode->vdisplay); list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { - if (encoder->crtc == crtc) { + if (encoder->crtc == crtc) encoder_types |= BIT(encoder->encoder_type); - imx_encoder = enc_to_imx_enc(encoder); - } } dev_dbg(ipu_crtc->dev, "%s: attached to encoder types 0x%lx\n", @@ -176,20 +217,20 @@ static void ipu_crtc_mode_set_nofb(struct drm_crtc *crtc) else sig_cfg.clkflags = 0; - sig_cfg.enable_pol = !(imx_encoder->bus_flags & DRM_BUS_FLAG_DE_LOW); + sig_cfg.enable_pol = !(imx_crtc_state->bus_flags & DRM_BUS_FLAG_DE_LOW); /* Default to driving pixel data on negative clock edges */ - sig_cfg.clk_pol = !!(imx_encoder->bus_flags & + sig_cfg.clk_pol = !!(imx_crtc_state->bus_flags & DRM_BUS_FLAG_PIXDATA_POSEDGE); - sig_cfg.bus_format = imx_encoder->bus_format; + sig_cfg.bus_format = imx_crtc_state->bus_format; sig_cfg.v_to_h_sync = 0; - sig_cfg.hsync_pin = imx_encoder->di_hsync_pin; - sig_cfg.vsync_pin = imx_encoder->di_vsync_pin; + sig_cfg.hsync_pin = imx_crtc_state->di_hsync_pin; + sig_cfg.vsync_pin = imx_crtc_state->di_vsync_pin; drm_display_mode_to_videomode(mode, &sig_cfg.mode); ipu_dc_init_sync(ipu_crtc->dc, ipu_crtc->di, mode->flags & DRM_MODE_FLAG_INTERLACE, - imx_encoder->bus_format, mode->hdisplay); + imx_crtc_state->bus_format, mode->hdisplay); ipu_di_init_sync_panel(ipu_crtc->di, &sig_cfg); } diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c index 4a2942ecec17..9da60df5efa7 100644 --- a/drivers/gpu/drm/imx/parallel-display.c +++ b/drivers/gpu/drm/imx/parallel-display.c @@ -27,19 +27,23 @@ #include "imx-drm.h" #define con_to_imxpd(x) container_of(x, struct imx_parallel_display, connector) -#define imx_enc_to_imxpd(x) \ - container_of(x, struct imx_parallel_display, imx_encoder) struct imx_parallel_display { struct drm_connector connector; - struct imx_drm_encoder imx_encoder; + struct drm_encoder encoder; struct device *dev; void *edid; int edid_len; + u32 bus_format; struct drm_display_mode mode; struct drm_panel *panel; }; +static inline struct imx_parallel_display *enc_to_imxpd(struct drm_encoder *e) +{ + return container_of(e, struct imx_parallel_display, encoder); +} + static enum drm_connector_status imx_pd_connector_detect( struct drm_connector *connector, bool force) { @@ -54,12 +58,7 @@ static int imx_pd_connector_get_modes(struct drm_connector *connector) if (imxpd->panel && imxpd->panel->funcs && imxpd->panel->funcs->get_modes) { - struct drm_display_info *di = &connector->display_info; - num_modes = imxpd->panel->funcs->get_modes(imxpd->panel); - if (!imxpd->imx_encoder.bus_format && di->num_bus_formats) - imxpd->imx_encoder.bus_format = di->bus_formats[0]; - imxpd->imx_encoder.bus_flags = di->bus_flags; if (num_modes > 0) return num_modes; } @@ -89,13 +88,12 @@ static struct drm_encoder *imx_pd_connector_best_encoder( { struct imx_parallel_display *imxpd = con_to_imxpd(connector); - return &imxpd->imx_encoder.encoder; + return &imxpd->encoder; } static void imx_pd_encoder_enable(struct drm_encoder *encoder) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_parallel_display *imxpd = imx_enc_to_imxpd(imx_encoder); + struct imx_parallel_display *imxpd = enc_to_imxpd(encoder); drm_panel_prepare(imxpd->panel); drm_panel_enable(imxpd->panel); @@ -103,13 +101,31 @@ static void imx_pd_encoder_enable(struct drm_encoder *encoder) static void imx_pd_encoder_disable(struct drm_encoder *encoder) { - struct imx_drm_encoder *imx_encoder = enc_to_imx_enc(encoder); - struct imx_parallel_display *imxpd = imx_enc_to_imxpd(imx_encoder); + struct imx_parallel_display *imxpd = enc_to_imxpd(encoder); drm_panel_disable(imxpd->panel); drm_panel_unprepare(imxpd->panel); } +static int imx_pd_encoder_atomic_check(struct drm_encoder *encoder, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state); + struct drm_display_info *di = &conn_state->connector->display_info; + struct imx_parallel_display *imxpd = enc_to_imxpd(encoder); + + imx_crtc_state->bus_flags = di->bus_flags; + if (!imxpd->bus_format && di->num_bus_formats) + imx_crtc_state->bus_format = di->bus_formats[0]; + else + imx_crtc_state->bus_format = imxpd->bus_format; + imx_crtc_state->di_hsync_pin = 2; + imx_crtc_state->di_vsync_pin = 3; + + return 0; +} + static const struct drm_connector_funcs imx_pd_connector_funcs = { .dpms = drm_atomic_helper_connector_dpms, .fill_modes = drm_helper_probe_single_connector_modes, @@ -132,15 +148,16 @@ static const struct drm_encoder_funcs imx_pd_encoder_funcs = { static const struct drm_encoder_helper_funcs imx_pd_encoder_helper_funcs = { .enable = imx_pd_encoder_enable, .disable = imx_pd_encoder_disable, + .atomic_check = imx_pd_encoder_atomic_check, }; static int imx_pd_register(struct drm_device *drm, struct imx_parallel_display *imxpd) { + struct drm_encoder *encoder = &imxpd->encoder; int ret; - ret = imx_drm_encoder_parse_of(drm, &imxpd->imx_encoder.encoder, - imxpd->dev->of_node); + ret = imx_drm_encoder_parse_of(drm, encoder, imxpd->dev->of_node); if (ret) return ret; @@ -151,10 +168,9 @@ static int imx_pd_register(struct drm_device *drm, */ imxpd->connector.dpms = DRM_MODE_DPMS_OFF; - drm_encoder_helper_add(&imxpd->imx_encoder.encoder, - &imx_pd_encoder_helper_funcs); - drm_encoder_init(drm, &imxpd->imx_encoder.encoder, - &imx_pd_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL); + drm_encoder_helper_add(encoder, &imx_pd_encoder_helper_funcs); + drm_encoder_init(drm, encoder, &imx_pd_encoder_funcs, + DRM_MODE_ENCODER_NONE, NULL); drm_connector_helper_add(&imxpd->connector, &imx_pd_connector_helper_funcs); @@ -164,8 +180,7 @@ static int imx_pd_register(struct drm_device *drm, if (imxpd->panel) drm_panel_attach(imxpd->panel, &imxpd->connector); - drm_mode_connector_attach_encoder(&imxpd->connector, - &imxpd->imx_encoder.encoder); + drm_mode_connector_attach_encoder(&imxpd->connector, encoder); return 0; } @@ -200,9 +215,7 @@ static int imx_pd_bind(struct device *dev, struct device *master, void *data) else if (!strcmp(fmt, "lvds666")) bus_format = MEDIA_BUS_FMT_RGB666_1X24_CPADHI; } - imxpd->imx_encoder.bus_format = bus_format; - imxpd->imx_encoder.di_hsync_pin = 2; - imxpd->imx_encoder.di_vsync_pin = 3; + imxpd->bus_format = bus_format; /* port@1 is the output port */ ep = of_graph_get_endpoint_by_regs(np, 1, -1); @@ -235,7 +248,7 @@ static void imx_pd_unbind(struct device *dev, struct device *master, { struct imx_parallel_display *imxpd = dev_get_drvdata(dev); - imxpd->imx_encoder.encoder.funcs->destroy(&imxpd->imx_encoder.encoder); + imxpd->encoder.funcs->destroy(&imxpd->encoder); imxpd->connector.funcs->destroy(&imxpd->connector); kfree(imxpd->edid); -- cgit v1.2.3 From 3df0739052c23989b441883fa251a0988f75c0f3 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Wed, 6 Jul 2016 15:47:11 +0200 Subject: drm/imx: turn remaining container_of macros into inline functions This allows the compiler to do type checking. Signed-off-by: Philipp Zabel --- drivers/gpu/drm/imx/imx-ldb.c | 7 +++++-- drivers/gpu/drm/imx/imx-tve.c | 7 +++++-- drivers/gpu/drm/imx/ipuv3-crtc.c | 5 ++++- drivers/gpu/drm/imx/ipuv3-plane.c | 5 ++++- drivers/gpu/drm/imx/parallel-display.c | 7 +++++-- 5 files changed, 23 insertions(+), 8 deletions(-) (limited to 'drivers/gpu/drm/imx/parallel-display.c') diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c index 9ac833540080..00d67b5407d8 100644 --- a/drivers/gpu/drm/imx/imx-ldb.c +++ b/drivers/gpu/drm/imx/imx-ldb.c @@ -51,8 +51,6 @@ #define LDB_DI1_VS_POL_ACT_LOW (1 << 10) #define LDB_BGREF_RMODE_INT (1 << 15) -#define con_to_imx_ldb_ch(x) container_of(x, struct imx_ldb_channel, connector) - struct imx_ldb; struct imx_ldb_channel { @@ -70,6 +68,11 @@ struct imx_ldb_channel { u32 bus_format; }; +static inline struct imx_ldb_channel *con_to_imx_ldb_ch(struct drm_connector *c) +{ + return container_of(c, struct imx_ldb_channel, connector); +} + static inline struct imx_ldb_channel *enc_to_imx_ldb_ch(struct drm_encoder *e) { return container_of(e, struct imx_ldb_channel, encoder); diff --git a/drivers/gpu/drm/imx/imx-tve.c b/drivers/gpu/drm/imx/imx-tve.c index 520b31228a6f..a293a7dad0d9 100644 --- a/drivers/gpu/drm/imx/imx-tve.c +++ b/drivers/gpu/drm/imx/imx-tve.c @@ -98,8 +98,6 @@ /* TVE_TST_MODE_REG */ #define TVE_TVDAC_TEST_MODE_MASK (0x7 << 0) -#define con_to_tve(x) container_of(x, struct imx_tve, connector) - enum { TVE_MODE_TVOUT, TVE_MODE_VGA, @@ -124,6 +122,11 @@ struct imx_tve { struct clk *di_clk; }; +static inline struct imx_tve *con_to_tve(struct drm_connector *c) +{ + return container_of(c, struct imx_tve, connector); +} + static inline struct imx_tve *enc_to_tve(struct drm_encoder *e) { return container_of(e, struct imx_tve, encoder); diff --git a/drivers/gpu/drm/imx/ipuv3-crtc.c b/drivers/gpu/drm/imx/ipuv3-crtc.c index 2791ef070e2e..08e188bc10fc 100644 --- a/drivers/gpu/drm/imx/ipuv3-crtc.c +++ b/drivers/gpu/drm/imx/ipuv3-crtc.c @@ -46,7 +46,10 @@ struct ipu_crtc { int irq; }; -#define to_ipu_crtc(x) container_of(x, struct ipu_crtc, base) +static inline struct ipu_crtc *to_ipu_crtc(struct drm_crtc *crtc) +{ + return container_of(crtc, struct ipu_crtc, base); +} static void ipu_crtc_enable(struct drm_crtc *crtc) { diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c index 3f5f9566b152..4ad67d015ec7 100644 --- a/drivers/gpu/drm/imx/ipuv3-plane.c +++ b/drivers/gpu/drm/imx/ipuv3-plane.c @@ -23,7 +23,10 @@ #include "video/imx-ipu-v3.h" #include "ipuv3-plane.h" -#define to_ipu_plane(x) container_of(x, struct ipu_plane, base) +static inline struct ipu_plane *to_ipu_plane(struct drm_plane *p) +{ + return container_of(p, struct ipu_plane, base); +} static const uint32_t ipu_plane_formats[] = { DRM_FORMAT_ARGB1555, diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c index 9da60df5efa7..7b7bb3100831 100644 --- a/drivers/gpu/drm/imx/parallel-display.c +++ b/drivers/gpu/drm/imx/parallel-display.c @@ -26,8 +26,6 @@ #include "imx-drm.h" -#define con_to_imxpd(x) container_of(x, struct imx_parallel_display, connector) - struct imx_parallel_display { struct drm_connector connector; struct drm_encoder encoder; @@ -39,6 +37,11 @@ struct imx_parallel_display { struct drm_panel *panel; }; +static inline struct imx_parallel_display *con_to_imxpd(struct drm_connector *c) +{ + return container_of(c, struct imx_parallel_display, connector); +} + static inline struct imx_parallel_display *enc_to_imxpd(struct drm_encoder *e) { return container_of(e, struct imx_parallel_display, encoder); -- cgit v1.2.3 From 76ecd9c9fb24b014a6f33fbb1287ede3be12158b Mon Sep 17 00:00:00 2001 From: Lothar Waßmann Date: Tue, 12 Jul 2016 15:30:01 +0200 Subject: drm/imx: parallel-display: check return code from of_get_drm_display_mode() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit of_get_drm_display_mode() may fail. Check its return code and bail out on error. Signed-off-by: Lothar Waßmann Signed-off-by: Philipp Zabel --- drivers/gpu/drm/imx/parallel-display.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'drivers/gpu/drm/imx/parallel-display.c') diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c index 7b7bb3100831..4abac21c5c9b 100644 --- a/drivers/gpu/drm/imx/parallel-display.c +++ b/drivers/gpu/drm/imx/parallel-display.c @@ -73,10 +73,16 @@ static int imx_pd_connector_get_modes(struct drm_connector *connector) if (np) { struct drm_display_mode *mode = drm_mode_create(connector->dev); + int ret; if (!mode) return -EINVAL; - of_get_drm_display_mode(np, &imxpd->mode, OF_USE_NATIVE_MODE); + + ret = of_get_drm_display_mode(np, &imxpd->mode, + OF_USE_NATIVE_MODE); + if (ret) + return ret; + drm_mode_copy(mode, &imxpd->mode); mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, drm_mode_probed_add(connector, mode); -- cgit v1.2.3 From f140b0cc776f8771adfa45d2ef234da72662443d Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Mon, 27 Jun 2016 15:26:31 +0200 Subject: drm/imx: parallel-display: add bridge support Add support for bridge chips connected externally to the i.MX DISP0/DISP1 DPI interfaces. Signed-off-by: Philipp Zabel --- drivers/gpu/drm/imx/parallel-display.c | 50 ++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'drivers/gpu/drm/imx/parallel-display.c') diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c index 4abac21c5c9b..1dad297b01fd 100644 --- a/drivers/gpu/drm/imx/parallel-display.c +++ b/drivers/gpu/drm/imx/parallel-display.c @@ -35,6 +35,7 @@ struct imx_parallel_display { u32 bus_format; struct drm_display_mode mode; struct drm_panel *panel; + struct drm_bridge *bridge; }; static inline struct imx_parallel_display *con_to_imxpd(struct drm_connector *c) @@ -181,15 +182,29 @@ static int imx_pd_register(struct drm_device *drm, drm_encoder_init(drm, encoder, &imx_pd_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL); - drm_connector_helper_add(&imxpd->connector, - &imx_pd_connector_helper_funcs); - drm_connector_init(drm, &imxpd->connector, &imx_pd_connector_funcs, - DRM_MODE_CONNECTOR_VGA); + if (!imxpd->bridge) { + drm_connector_helper_add(&imxpd->connector, + &imx_pd_connector_helper_funcs); + drm_connector_init(drm, &imxpd->connector, + &imx_pd_connector_funcs, + DRM_MODE_CONNECTOR_VGA); + } if (imxpd->panel) drm_panel_attach(imxpd->panel, &imxpd->connector); - drm_mode_connector_attach_encoder(&imxpd->connector, encoder); + if (imxpd->bridge) { + imxpd->bridge->encoder = encoder; + encoder->bridge = imxpd->bridge; + ret = drm_bridge_attach(drm, imxpd->bridge); + if (ret < 0) { + dev_err(imxpd->dev, "failed to attach bridge: %d\n", + ret); + return ret; + } + } else { + drm_mode_connector_attach_encoder(&imxpd->connector, encoder); + } return 0; } @@ -232,13 +247,30 @@ static int imx_pd_bind(struct device *dev, struct device *master, void *data) struct device_node *remote; remote = of_graph_get_remote_port_parent(ep); + if (!remote) { + dev_warn(dev, "endpoint %s not connected\n", + ep->full_name); + of_node_put(ep); + return -ENODEV; + } of_node_put(ep); - if (remote) { - imxpd->panel = of_drm_find_panel(remote); - of_node_put(remote); + + imxpd->panel = of_drm_find_panel(remote); + if (imxpd->panel) { + dev_dbg(dev, "found panel %s\n", remote->full_name); + } else { + imxpd->bridge = of_drm_find_bridge(remote); + if (imxpd->bridge) + dev_dbg(dev, "found bridge %s\n", + remote->full_name); } - if (!imxpd->panel) + if (!imxpd->panel && !imxpd->bridge) { + dev_dbg(dev, "waiting for panel or bridge %s\n", + remote->full_name); + of_node_put(remote); return -EPROBE_DEFER; + } + of_node_put(remote); } imxpd->dev = dev; -- cgit v1.2.3