Skip to content

Commit

Permalink
imx-drm: initialise drm components directly
Browse files Browse the repository at this point in the history
Now that our bind function is only ever called during the main DRM
driver ->load callback, we don't need to have the imx_drm_connector or
imx_drm_encoder abstractions anymore.  So let's get rid of it, and move
the DRM connector and encoder setup into the connector support files.

Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
Reviewed-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  • Loading branch information
Russell King committed Feb 24, 2014
1 parent 8a51a33 commit 1b3f767
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 174 deletions.
56 changes: 15 additions & 41 deletions drivers/staging/imx-drm/imx-hdmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ struct hdmi_data_info {

struct imx_hdmi {
struct drm_connector connector;
struct imx_drm_connector *imx_drm_connector;
struct drm_encoder encoder;
struct imx_drm_encoder *imx_drm_encoder;

enum imx_hdmi_devtype dev_type;
struct device *dev;
Expand Down Expand Up @@ -1378,10 +1376,6 @@ static enum drm_connector_status imx_hdmi_connector_detect(struct drm_connector
return connector_status_connected;
}

static void imx_hdmi_connector_destroy(struct drm_connector *connector)
{
}

static int imx_hdmi_connector_get_modes(struct drm_connector *connector)
{
struct imx_hdmi *hdmi = container_of(connector, struct imx_hdmi,
Expand Down Expand Up @@ -1467,13 +1461,8 @@ static void imx_hdmi_encoder_commit(struct drm_encoder *encoder)
imx_hdmi_poweron(hdmi);
}

static void imx_hdmi_encoder_destroy(struct drm_encoder *encoder)
{
return;
}

static struct drm_encoder_funcs imx_hdmi_encoder_funcs = {
.destroy = imx_hdmi_encoder_destroy,
.destroy = imx_drm_encoder_destroy,
};

static struct drm_encoder_helper_funcs imx_hdmi_encoder_helper_funcs = {
Expand All @@ -1489,7 +1478,7 @@ static struct drm_connector_funcs imx_hdmi_connector_funcs = {
.dpms = drm_helper_connector_dpms,
.fill_modes = drm_helper_probe_single_connector_modes,
.detect = imx_hdmi_connector_detect,
.destroy = imx_hdmi_connector_destroy,
.destroy = imx_drm_connector_destroy,
};

static struct drm_connector_helper_funcs imx_hdmi_connector_helper_funcs = {
Expand Down Expand Up @@ -1529,34 +1518,23 @@ static irqreturn_t imx_hdmi_irq(int irq, void *dev_id)
return IRQ_HANDLED;
}

static int imx_hdmi_register(struct imx_hdmi *hdmi)
static int imx_hdmi_register(struct drm_device *drm, struct imx_hdmi *hdmi)
{
int ret;

hdmi->connector.funcs = &imx_hdmi_connector_funcs;
hdmi->encoder.funcs = &imx_hdmi_encoder_funcs;

hdmi->encoder.encoder_type = DRM_MODE_ENCODER_TMDS;
hdmi->connector.connector_type = DRM_MODE_CONNECTOR_HDMIA;
ret = imx_drm_encoder_parse_of(drm, &hdmi->encoder,
hdmi->dev->of_node);
if (ret)
return ret;

drm_encoder_helper_add(&hdmi->encoder, &imx_hdmi_encoder_helper_funcs);
ret = imx_drm_add_encoder(&hdmi->encoder, &hdmi->imx_drm_encoder,
THIS_MODULE);
if (ret) {
dev_err(hdmi->dev, "adding encoder failed: %d\n", ret);
return ret;
}
drm_encoder_init(drm, &hdmi->encoder, &imx_hdmi_encoder_funcs,
DRM_MODE_ENCODER_TMDS);

drm_connector_helper_add(&hdmi->connector,
&imx_hdmi_connector_helper_funcs);

ret = imx_drm_add_connector(&hdmi->connector,
&hdmi->imx_drm_connector, THIS_MODULE);
if (ret) {
imx_drm_remove_encoder(hdmi->imx_drm_encoder);
dev_err(hdmi->dev, "adding connector failed: %d\n", ret);
return ret;
}
drm_connector_init(drm, &hdmi->connector, &imx_hdmi_connector_funcs,
DRM_MODE_CONNECTOR_HDMIA);

hdmi->connector.encoder = &hdmi->encoder;

Expand Down Expand Up @@ -1588,6 +1566,7 @@ static int imx_hdmi_bind(struct device *dev, struct device *master, void *data)
struct platform_device *pdev = to_platform_device(dev);
const struct of_device_id *of_id =
of_match_device(imx_hdmi_dt_ids, dev);
struct drm_device *drm = data;
struct device_node *np = dev->of_node;
struct device_node *ddc_node;
struct imx_hdmi *hdmi;
Expand Down Expand Up @@ -1695,12 +1674,10 @@ static int imx_hdmi_bind(struct device *dev, struct device *master, void *data)
if (ret)
goto err_iahb;

ret = imx_hdmi_register(hdmi);
ret = imx_hdmi_register(drm, hdmi);
if (ret)
goto err_iahb;

imx_drm_encoder_add_possible_crtcs(hdmi->imx_drm_encoder, np);

dev_set_drvdata(dev, hdmi);

return 0;
Expand All @@ -1717,12 +1694,9 @@ static void imx_hdmi_unbind(struct device *dev, struct device *master,
void *data)
{
struct imx_hdmi *hdmi = dev_get_drvdata(dev);
struct drm_connector *connector = &hdmi->connector;
struct drm_encoder *encoder = &hdmi->encoder;

drm_mode_connector_detach_encoder(connector, encoder);
imx_drm_remove_connector(hdmi->imx_drm_connector);
imx_drm_remove_encoder(hdmi->imx_drm_encoder);
hdmi->connector.funcs->destroy(&hdmi->connector);
hdmi->encoder.funcs->destroy(&hdmi->encoder);

clk_disable_unprepare(hdmi->iahb_clk);
clk_disable_unprepare(hdmi->isfr_clk);
Expand Down
68 changes: 22 additions & 46 deletions drivers/staging/imx-drm/imx-ldb.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ struct imx_ldb;
struct imx_ldb_channel {
struct imx_ldb *ldb;
struct drm_connector connector;
struct imx_drm_connector *imx_drm_connector;
struct drm_encoder encoder;
struct imx_drm_encoder *imx_drm_encoder;
struct device_node *child;
int chno;
void *edid;
int edid_len;
Expand Down Expand Up @@ -92,11 +91,6 @@ static enum drm_connector_status imx_ldb_connector_detect(
return connector_status_connected;
}

static void imx_ldb_connector_destroy(struct drm_connector *connector)
{
/* do not free here */
}

static int imx_ldb_connector_get_modes(struct drm_connector *connector)
{
struct imx_ldb_channel *imx_ldb_ch = con_to_imx_ldb_ch(connector);
Expand Down Expand Up @@ -308,16 +302,11 @@ static void imx_ldb_encoder_disable(struct drm_encoder *encoder)
}
}

static void imx_ldb_encoder_destroy(struct drm_encoder *encoder)
{
/* do not free here */
}

static struct drm_connector_funcs imx_ldb_connector_funcs = {
.dpms = drm_helper_connector_dpms,
.fill_modes = drm_helper_probe_single_connector_modes,
.detect = imx_ldb_connector_detect,
.destroy = imx_ldb_connector_destroy,
.destroy = imx_drm_connector_destroy,
};

static struct drm_connector_helper_funcs imx_ldb_connector_helper_funcs = {
Expand All @@ -327,7 +316,7 @@ static struct drm_connector_helper_funcs imx_ldb_connector_helper_funcs = {
};

static struct drm_encoder_funcs imx_ldb_encoder_funcs = {
.destroy = imx_ldb_encoder_destroy,
.destroy = imx_drm_encoder_destroy,
};

static struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = {
Expand All @@ -354,45 +343,36 @@ static int imx_ldb_get_clk(struct imx_ldb *ldb, int chno)
return PTR_ERR_OR_ZERO(ldb->clk_pll[chno]);
}

static int imx_ldb_register(struct imx_ldb_channel *imx_ldb_ch)
static int imx_ldb_register(struct drm_device *drm,
struct imx_ldb_channel *imx_ldb_ch)
{
int ret;
struct imx_ldb *ldb = imx_ldb_ch->ldb;
int ret;

ret = imx_drm_encoder_parse_of(drm, &imx_ldb_ch->encoder,
imx_ldb_ch->child);
if (ret)
return ret;

ret = imx_ldb_get_clk(ldb, imx_ldb_ch->chno);
if (ret)
return ret;

if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
ret |= imx_ldb_get_clk(ldb, 1);
ret = imx_ldb_get_clk(ldb, 1);
if (ret)
return ret;
}

imx_ldb_ch->connector.funcs = &imx_ldb_connector_funcs;
imx_ldb_ch->encoder.funcs = &imx_ldb_encoder_funcs;

imx_ldb_ch->encoder.encoder_type = DRM_MODE_ENCODER_LVDS;
imx_ldb_ch->connector.connector_type = DRM_MODE_CONNECTOR_LVDS;

drm_encoder_helper_add(&imx_ldb_ch->encoder,
&imx_ldb_encoder_helper_funcs);
ret = imx_drm_add_encoder(&imx_ldb_ch->encoder,
&imx_ldb_ch->imx_drm_encoder, THIS_MODULE);
if (ret) {
dev_err(ldb->dev, "adding encoder failed with %d\n", ret);
return ret;
}
drm_encoder_init(drm, &imx_ldb_ch->encoder, &imx_ldb_encoder_funcs,
DRM_MODE_ENCODER_LVDS);

drm_connector_helper_add(&imx_ldb_ch->connector,
&imx_ldb_connector_helper_funcs);

ret = imx_drm_add_connector(&imx_ldb_ch->connector,
&imx_ldb_ch->imx_drm_connector, THIS_MODULE);
if (ret) {
imx_drm_remove_encoder(imx_ldb_ch->imx_drm_encoder);
dev_err(ldb->dev, "adding connector failed with %d\n", ret);
return ret;
}
drm_connector_init(drm, &imx_ldb_ch->connector,
&imx_ldb_connector_funcs, DRM_MODE_CONNECTOR_LVDS);

drm_mode_connector_attach_encoder(&imx_ldb_ch->connector,
&imx_ldb_ch->encoder);
Expand Down Expand Up @@ -453,6 +433,7 @@ MODULE_DEVICE_TABLE(of, imx_ldb_dt_ids);

static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
{
struct drm_device *drm = data;
struct device_node *np = dev->of_node;
const struct of_device_id *of_id =
of_match_device(imx_ldb_dt_ids, dev);
Expand Down Expand Up @@ -523,6 +504,7 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
channel = &imx_ldb->channel[i];
channel->ldb = imx_ldb;
channel->chno = i;
channel->child = child;

edidp = of_get_property(child, "edid", &channel->edid_len);
if (edidp) {
Expand Down Expand Up @@ -565,11 +547,9 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
return -EINVAL;
}

ret = imx_ldb_register(channel);
ret = imx_ldb_register(drm, channel);
if (ret)
return ret;

imx_drm_encoder_add_possible_crtcs(channel->imx_drm_encoder, child);
}

dev_set_drvdata(dev, imx_ldb);
Expand All @@ -585,13 +565,9 @@ static void imx_ldb_unbind(struct device *dev, struct device *master,

for (i = 0; i < 2; i++) {
struct imx_ldb_channel *channel = &imx_ldb->channel[i];
struct drm_connector *connector = &channel->connector;
struct drm_encoder *encoder = &channel->encoder;

drm_mode_connector_detach_encoder(connector, encoder);

imx_drm_remove_connector(channel->imx_drm_connector);
imx_drm_remove_encoder(channel->imx_drm_encoder);
channel->connector.funcs->destroy(&channel->connector);
channel->encoder.funcs->destroy(&channel->encoder);
}
}

Expand Down
Loading

0 comments on commit 1b3f767

Please sign in to comment.