drm/atmel-hlcdc: Replace the panel usage with drm_panel_bridge.

This cuts 135 lines of boilerplate, at the cost of losing the
filtering of get_modes() using atmel_hlcdc_dc_mode_valid().  The
atomic check will still check that we don't set an invalid mode,
though.

Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Archit Taneja <architt@codeaurora.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20170511183128.25085-7-eric@anholt.net
This commit is contained in:
Eric Anholt 2017-05-11 11:31:28 -07:00 committed by Archit Taneja
parent 510fc3c0d7
commit 96160a8071
1 changed files with 14 additions and 149 deletions

View File

@ -23,191 +23,56 @@
#include <drm/drmP.h> #include <drm/drmP.h>
#include <drm/drm_of.h> #include <drm/drm_of.h>
#include <drm/drm_bridge.h>
#include "atmel_hlcdc_dc.h" #include "atmel_hlcdc_dc.h"
/**
* Atmel HLCDC RGB connector structure
*
* This structure stores RGB slave device information.
*
* @connector: DRM connector
* @encoder: DRM encoder
* @dc: pointer to the atmel_hlcdc_dc structure
* @panel: panel connected on the RGB output
*/
struct atmel_hlcdc_rgb_output {
struct drm_connector connector;
struct drm_encoder encoder;
struct atmel_hlcdc_dc *dc;
struct drm_panel *panel;
};
static inline struct atmel_hlcdc_rgb_output *
drm_connector_to_atmel_hlcdc_rgb_output(struct drm_connector *connector)
{
return container_of(connector, struct atmel_hlcdc_rgb_output,
connector);
}
static inline struct atmel_hlcdc_rgb_output *
drm_encoder_to_atmel_hlcdc_rgb_output(struct drm_encoder *encoder)
{
return container_of(encoder, struct atmel_hlcdc_rgb_output, encoder);
}
static void atmel_hlcdc_rgb_encoder_enable(struct drm_encoder *encoder)
{
struct atmel_hlcdc_rgb_output *rgb =
drm_encoder_to_atmel_hlcdc_rgb_output(encoder);
if (rgb->panel) {
drm_panel_prepare(rgb->panel);
drm_panel_enable(rgb->panel);
}
}
static void atmel_hlcdc_rgb_encoder_disable(struct drm_encoder *encoder)
{
struct atmel_hlcdc_rgb_output *rgb =
drm_encoder_to_atmel_hlcdc_rgb_output(encoder);
if (rgb->panel) {
drm_panel_disable(rgb->panel);
drm_panel_unprepare(rgb->panel);
}
}
static const struct drm_encoder_helper_funcs atmel_hlcdc_panel_encoder_helper_funcs = {
.disable = atmel_hlcdc_rgb_encoder_disable,
.enable = atmel_hlcdc_rgb_encoder_enable,
};
static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs = { static const struct drm_encoder_funcs atmel_hlcdc_panel_encoder_funcs = {
.destroy = drm_encoder_cleanup, .destroy = drm_encoder_cleanup,
}; };
static int atmel_hlcdc_panel_get_modes(struct drm_connector *connector)
{
struct atmel_hlcdc_rgb_output *rgb =
drm_connector_to_atmel_hlcdc_rgb_output(connector);
if (rgb->panel)
return rgb->panel->funcs->get_modes(rgb->panel);
return 0;
}
static int atmel_hlcdc_rgb_mode_valid(struct drm_connector *connector,
struct drm_display_mode *mode)
{
struct atmel_hlcdc_rgb_output *rgb =
drm_connector_to_atmel_hlcdc_rgb_output(connector);
return atmel_hlcdc_dc_mode_valid(rgb->dc, mode);
}
static const struct drm_connector_helper_funcs atmel_hlcdc_panel_connector_helper_funcs = {
.get_modes = atmel_hlcdc_panel_get_modes,
.mode_valid = atmel_hlcdc_rgb_mode_valid,
};
static enum drm_connector_status
atmel_hlcdc_panel_connector_detect(struct drm_connector *connector, bool force)
{
struct atmel_hlcdc_rgb_output *rgb =
drm_connector_to_atmel_hlcdc_rgb_output(connector);
if (rgb->panel)
return connector_status_connected;
return connector_status_disconnected;
}
static void
atmel_hlcdc_panel_connector_destroy(struct drm_connector *connector)
{
struct atmel_hlcdc_rgb_output *rgb =
drm_connector_to_atmel_hlcdc_rgb_output(connector);
if (rgb->panel)
drm_panel_detach(rgb->panel);
drm_connector_cleanup(connector);
}
static const struct drm_connector_funcs atmel_hlcdc_panel_connector_funcs = {
.dpms = drm_atomic_helper_connector_dpms,
.detect = atmel_hlcdc_panel_connector_detect,
.fill_modes = drm_helper_probe_single_connector_modes,
.destroy = atmel_hlcdc_panel_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 int atmel_hlcdc_attach_endpoint(struct drm_device *dev, static int atmel_hlcdc_attach_endpoint(struct drm_device *dev,
const struct device_node *np) const struct device_node *np)
{ {
struct atmel_hlcdc_dc *dc = dev->dev_private; struct drm_encoder *encoder;
struct atmel_hlcdc_rgb_output *output;
struct drm_panel *panel; struct drm_panel *panel;
struct drm_bridge *bridge; struct drm_bridge *bridge;
int ret; int ret;
output = devm_kzalloc(dev->dev, sizeof(*output), GFP_KERNEL); encoder = devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL);
if (!output) if (!encoder)
return -EINVAL; return -EINVAL;
output->dc = dc; ret = drm_encoder_init(dev, encoder,
drm_encoder_helper_add(&output->encoder,
&atmel_hlcdc_panel_encoder_helper_funcs);
ret = drm_encoder_init(dev, &output->encoder,
&atmel_hlcdc_panel_encoder_funcs, &atmel_hlcdc_panel_encoder_funcs,
DRM_MODE_ENCODER_NONE, NULL); DRM_MODE_ENCODER_NONE, NULL);
if (ret) if (ret)
return ret; return ret;
output->encoder.possible_crtcs = 0x1; encoder->possible_crtcs = 0x1;
ret = drm_of_find_panel_or_bridge(np, 0, 0, &panel, &bridge); ret = drm_of_find_panel_or_bridge(np, 0, 0, &panel, &bridge);
if (ret) if (ret)
return ret; return ret;
if (panel) { if (panel) {
output->connector.dpms = DRM_MODE_DPMS_OFF; bridge = drm_panel_bridge_add(panel, DRM_MODE_CONNECTOR_Unknown);
output->connector.polled = DRM_CONNECTOR_POLL_CONNECT; if (IS_ERR(bridge))
drm_connector_helper_add(&output->connector, return PTR_ERR(bridge);
&atmel_hlcdc_panel_connector_helper_funcs);
ret = drm_connector_init(dev, &output->connector,
&atmel_hlcdc_panel_connector_funcs,
DRM_MODE_CONNECTOR_Unknown);
if (ret)
goto err_encoder_cleanup;
drm_mode_connector_attach_encoder(&output->connector,
&output->encoder);
ret = drm_panel_attach(panel, &output->connector);
if (ret) {
drm_connector_cleanup(&output->connector);
goto err_encoder_cleanup;
}
output->panel = panel;
return 0; return 0;
} }
if (bridge) { if (bridge) {
ret = drm_bridge_attach(&output->encoder, bridge, NULL); ret = drm_bridge_attach(encoder, bridge, NULL);
if (!ret) if (!ret)
return 0; return 0;
if (panel)
drm_panel_bridge_remove(bridge);
} }
err_encoder_cleanup: drm_encoder_cleanup(encoder);
drm_encoder_cleanup(&output->encoder);
return ret; return ret;
} }