From patchwork Mon Nov 10 10:41:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Yan X-Patchwork-Id: 5265781 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2BBA99F2ED for ; Mon, 10 Nov 2014 12:31:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FB6C20173 for ; Mon, 10 Nov 2014 12:31:37 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 05FE220158 for ; Mon, 10 Nov 2014 12:31:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5D3266F774; Mon, 10 Nov 2014 04:31:27 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yk0-f195.google.com (mail-yk0-f195.google.com [209.85.160.195]) by gabe.freedesktop.org (Postfix) with ESMTP id 92EA96F5E7 for ; Mon, 10 Nov 2014 02:42:12 -0800 (PST) Received: by mail-yk0-f195.google.com with SMTP id 142so142788ykq.10 for ; Mon, 10 Nov 2014 02:42:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MjMIO8606vRUQQQSLQ9X2kUfN5A73wFG1pnwILfdGnU=; b=bTiAdhTp1z9BIX5zlFdGmdlI4wmuc2SueLWmD4EM1+/mIayUSVCG7X/dpns8o3+IpZ xmlLoORbVVw8o319+hgRnaFi4tLsTVO/r7HCshZF7r1ZlYFeziFMpxiuLhsMgUCHSxRn PWPJVWrnLTrx+rqGGuIJn3DeVSP8R5ka5qIK12zcC/eR3W2FpLLWvOjExmLGg2IX9K6P vuYy/lzsgctQiCNTcqU/hC5f5xR3dnS5bu/mBDIoClOnVfvWiJpf26Kcs0ZFkc76tiBh lj5EDU9bWXkKnyTjN+f3l7aF9NH9jy8O/G6utNsiblnII3x9+rs10O40yz5/Xgg5qeC8 jljw== X-Received: by 10.170.211.10 with SMTP id c10mr32684370ykf.112.1415616132260; Mon, 10 Nov 2014 02:42:12 -0800 (PST) Received: from localhost.localdomain ([192.255.70.46]) by mx.google.com with ESMTPSA id q40sm9084641yhg.32.2014.11.10.02.42.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Nov 2014 02:42:11 -0800 (PST) From: Andy Yan To: airlied@linux.ie, Zubair.Kakakhel@imgtec.com, rmk+kernel@arm.linux.org.uk, fabio.estevam@freescale.com, heiko@sntech.de Subject: [PATCH v6 6/7] drm: bridge/dw-hdmi: convert dw-hdmi to drm_bridge mode Date: Mon, 10 Nov 2014 18:41:01 +0800 Message-Id: <1415616062-30583-7-git-send-email-andy.yan@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415616062-30583-1-git-send-email-andy.yan@rock-chips.com> References: <1415616062-30583-1-git-send-email-andy.yan@rock-chips.com> X-Mailman-Approved-At: Mon, 10 Nov 2014 04:31:25 -0800 Cc: devel@driverdev.osuosl.org, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Yakir Yang , Andy Yan X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yakir Yang handle encoder in dw_hdmi-imx.c, keep the connector & birdge in dw_hdmi.c Signed-off-by: Andy Yan Signed-off-by: Yakir Yang --- Changes in v6: - move some modification from patch#5 Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/gpu/drm/bridge/dw_hdmi.c | 228 +++++++++++++++------------------- drivers/staging/imx-drm/dw_hdmi-imx.c | 145 ++++++++++++++------- include/drm/bridge/dw_hdmi.h | 13 +- 3 files changed, 199 insertions(+), 187 deletions(-) diff --git a/drivers/gpu/drm/bridge/dw_hdmi.c b/drivers/gpu/drm/bridge/dw_hdmi.c index c15c86e..25f2caf 100644 --- a/drivers/gpu/drm/bridge/dw_hdmi.c +++ b/drivers/gpu/drm/bridge/dw_hdmi.c @@ -11,7 +11,6 @@ * Copyright (C) 2010, Guennadi Liakhovetski */ -#include #include #include #include @@ -107,7 +106,8 @@ union dw_reg_ptr { struct dw_hdmi { struct drm_connector connector; - struct drm_encoder encoder; + struct drm_encoder *encoder; + struct drm_bridge *bridge; enum dw_hdmi_devtype dev_type; struct device *dev; @@ -1319,6 +1319,50 @@ static void dw_hdmi_poweroff(struct dw_hdmi *hdmi) dw_hdmi_phy_disable(hdmi); } +static void dw_hdmi_bridge_mode_set(struct drm_bridge *bridge, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + struct dw_hdmi *hdmi = bridge->driver_private; + + dw_hdmi_setup(hdmi, mode); + + /* Store the display mode for plugin/DKMS poweron events */ + memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode)); +} + +static bool dw_hdmi_bridge_mode_fixup(struct drm_bridge *bridge, + const struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + return true; +} + +static void dw_hdmi_bridge_disable(struct drm_bridge *bridge) +{ + struct dw_hdmi *hdmi = bridge->driver_private; + + dw_hdmi_poweroff(hdmi); +} + +static void dw_hdmi_bridge_enable(struct drm_bridge *bridge) +{ + struct dw_hdmi *hdmi = bridge->driver_private; + + dw_hdmi_poweron(hdmi); +} + +static void dw_hdmi_bridge_destroy(struct drm_bridge *bridge) +{ + drm_bridge_cleanup(bridge); + kfree(bridge); +} + +static void dw_hdmi_bridge_nope(struct drm_bridge *bridge) +{ + /* do nothing */ +} + static enum drm_connector_status dw_hdmi_connector_detect(struct drm_connector *connector, bool force) { @@ -1360,60 +1404,7 @@ static struct drm_encoder *dw_hdmi_connector_best_encoder(struct drm_connector struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, connector); - return &hdmi->encoder; -} - -static void dw_hdmi_encoder_mode_set(struct drm_encoder *encoder, - struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode) -{ - struct dw_hdmi *hdmi = container_of(encoder, struct dw_hdmi, encoder); - - dw_hdmi_setup(hdmi, mode); - - /* Store the display mode for plugin/DKMS poweron events */ - memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode)); -} - -static bool dw_hdmi_encoder_mode_fixup(struct drm_encoder *encoder, - const struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode) -{ - return true; -} - -static void dw_hdmi_encoder_disable(struct drm_encoder *encoder) -{ -} - -static void dw_hdmi_encoder_dpms(struct drm_encoder *encoder, int mode) -{ - struct dw_hdmi *hdmi = container_of(encoder, struct dw_hdmi, encoder); - - if (mode) - dw_hdmi_poweroff(hdmi); - else - dw_hdmi_poweron(hdmi); -} - -static void dw_hdmi_encoder_prepare(struct drm_encoder *encoder) -{ - struct dw_hdmi *hdmi = container_of(encoder, struct dw_hdmi, encoder); - - dw_hdmi_poweroff(hdmi); - - if (hdmi->plat_data->encoder_prepare) - hdmi->plat_data->encoder_prepare(&hdmi->connector, encoder); -} - -static void dw_hdmi_encoder_commit(struct drm_encoder *encoder) -{ - struct dw_hdmi *hdmi = container_of(encoder, struct dw_hdmi, encoder); - - if (hdmi->plat_data->encoder_commit) - hdmi->plat_data->encoder_commit(hdmi->priv, encoder); - - dw_hdmi_poweron(hdmi); + return hdmi->encoder; } void dw_hdmi_connector_destroy(struct drm_connector *connector) @@ -1422,19 +1413,6 @@ void dw_hdmi_connector_destroy(struct drm_connector *connector) drm_connector_cleanup(connector); } -static struct drm_encoder_funcs dw_hdmi_encoder_funcs = { - .destroy = drm_encoder_cleanup, -}; - -static struct drm_encoder_helper_funcs dw_hdmi_encoder_helper_funcs = { - .dpms = dw_hdmi_encoder_dpms, - .prepare = dw_hdmi_encoder_prepare, - .commit = dw_hdmi_encoder_commit, - .mode_set = dw_hdmi_encoder_mode_set, - .mode_fixup = dw_hdmi_encoder_mode_fixup, - .disable = dw_hdmi_encoder_disable, -}; - static struct drm_connector_funcs dw_hdmi_connector_funcs = { .dpms = drm_helper_connector_dpms, .fill_modes = drm_helper_probe_single_connector_modes, @@ -1447,6 +1425,16 @@ static struct drm_connector_helper_funcs dw_hdmi_connector_helper_funcs = { .best_encoder = dw_hdmi_connector_best_encoder, }; +struct drm_bridge_funcs dw_hdmi_bridge_funcs = { + .enable = dw_hdmi_bridge_enable, + .disable = dw_hdmi_bridge_disable, + .pre_enable = dw_hdmi_bridge_nope, + .post_disable = dw_hdmi_bridge_nope, + .mode_set = dw_hdmi_bridge_mode_set, + .mode_fixup = dw_hdmi_bridge_mode_fixup, + .destroy = dw_hdmi_bridge_destroy, +}; + static irqreturn_t dw_hdmi_hardirq(int irq, void *dev_id) { struct dw_hdmi *hdmi = dev_id; @@ -1495,40 +1483,64 @@ static irqreturn_t dw_hdmi_irq(int irq, void *dev_id) static int dw_hdmi_register(struct drm_device *drm, struct dw_hdmi *hdmi) { - struct drm_encoder *encoder = &hdmi->encoder; - struct device *dev = hdmi->dev; + struct drm_encoder *encoder = hdmi->encoder; + struct drm_bridge *bridge; + int ret; - encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node); + bridge = devm_kzalloc(drm->dev, sizeof(*bridge), GFP_KERNEL); + if (!bridge) { + DRM_ERROR("Failed to allocate drm bridge\n"); + return -ENOMEM; + } - hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD; + hdmi->bridge = bridge; + bridge->driver_private = hdmi; - drm_encoder_helper_add(&hdmi->encoder, &dw_hdmi_encoder_helper_funcs); - drm_encoder_init(drm, &hdmi->encoder, &dw_hdmi_encoder_funcs, - DRM_MODE_ENCODER_TMDS); + ret = drm_bridge_init(drm, bridge, &dw_hdmi_bridge_funcs); + if (ret) { + DRM_ERROR("Failed to initialize bridge with drm\n"); + return -EINVAL; + } + + encoder->bridge = bridge; + hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD; drm_connector_helper_add(&hdmi->connector, &dw_hdmi_connector_helper_funcs); drm_connector_init(drm, &hdmi->connector, &dw_hdmi_connector_funcs, DRM_MODE_CONNECTOR_HDMIA); - hdmi->connector.encoder = &hdmi->encoder; + hdmi->connector.encoder = encoder; - drm_mode_connector_attach_encoder(&hdmi->connector, &hdmi->encoder); + drm_mode_connector_attach_encoder(&hdmi->connector, encoder); return 0; } -static int dw_hdmi_bind(struct device *dev, struct device *master, void *data) +int dw_hdmi_bind(struct device *dev, struct device *master, + void *data, struct drm_encoder *encoder, + const struct dw_hdmi_plat_data *plat_data) { struct platform_device *pdev = to_platform_device(dev); - struct dw_hdmi *hdmi = platform_get_drvdata(pdev); struct drm_device *drm = data; struct device_node *np = dev->of_node; struct device_node *ddc_node; struct resource *iores; + struct dw_hdmi *hdmi; int ret, irq; u32 val = 1; + hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); + if (!hdmi) + return -ENOMEM; + + hdmi->plat_data = plat_data; + hdmi->dev = &pdev->dev; + hdmi->dev_type = plat_data->dev_type; + hdmi->sample_rate = 48000; + hdmi->ratio = 100; + hdmi->encoder = encoder; + of_property_read_u32(np, "reg-io-width", &val); switch (val) { @@ -1574,8 +1586,6 @@ static int dw_hdmi_bind(struct device *dev, struct device *master, void *data) if (IS_ERR(hdmi->regs.p32)) return PTR_ERR(hdmi->regs.p32); - if (hdmi->plat_data->setup) - hdmi->priv = hdmi->plat_data->setup(pdev); /* Product and revision IDs */ dev_info(dev, "Detected HDMI controller 0x%x:0x%x:0x%x:0x%x\n", @@ -1616,9 +1626,9 @@ static int dw_hdmi_bind(struct device *dev, struct device *master, void *data) return 0; } +EXPORT_SYMBOL_GPL(dw_hdmi_bind); -static void dw_hdmi_unbind(struct device *dev, struct device *master, - void *data) +void dw_hdmi_unbind(struct device *dev, struct device *master, void *data) { struct dw_hdmi *hdmi = dev_get_drvdata(dev); @@ -1626,57 +1636,15 @@ static void dw_hdmi_unbind(struct device *dev, struct device *master, hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); hdmi->connector.funcs->destroy(&hdmi->connector); - hdmi->encoder.funcs->destroy(&hdmi->encoder); - if (hdmi->plat_data->exit) - hdmi->plat_data->exit(hdmi->priv); - i2c_put_adapter(hdmi->ddc); -} - -static const struct component_ops hdmi_ops = { - .bind = dw_hdmi_bind, - .unbind = dw_hdmi_unbind, -}; - -static int dw_hdmi_platform_probe(struct platform_device *pdev) -{ - return component_add(&pdev->dev, &hdmi_ops); -} - -static int dw_hdmi_platform_remove(struct platform_device *pdev) -{ - component_del(&pdev->dev, &hdmi_ops); - return 0; -} - -int dw_hdmi_platform_register(struct platform_device *pdev, - const struct dw_hdmi_plat_data *plat_data) -{ - struct dw_hdmi *hdmi; - - hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL); - if (!hdmi) - return -ENOMEM; - - hdmi->plat_data = plat_data; - hdmi->dev = &pdev->dev; - hdmi->dev_type = plat_data->dev_type; - hdmi->sample_rate = 48000; - hdmi->ratio = 100; + hdmi->encoder->funcs->destroy(hdmi->encoder); - platform_set_drvdata(pdev, hdmi); - - return dw_hdmi_platform_probe(pdev); -} -EXPORT_SYMBOL_GPL(dw_hdmi_platform_register); - -int dw_hdmi_platform_unregister(struct platform_device *pdev) -{ - return dw_hdmi_platform_remove(pdev); + i2c_put_adapter(hdmi->ddc); } -EXPORT_SYMBOL_GPL(dw_hdmi_platform_unregister); +EXPORT_SYMBOL_GPL(dw_hdmi_unbind); MODULE_AUTHOR("Sascha Hauer "); MODULE_AUTHOR("Andy Yan "); +MODULE_AUTHOR("Yakir Yang "); MODULE_DESCRIPTION("DW HDMI transmitter driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:dw-hdmi"); diff --git a/drivers/staging/imx-drm/dw_hdmi-imx.c b/drivers/staging/imx-drm/dw_hdmi-imx.c index d205874..12d04c2 100644 --- a/drivers/staging/imx-drm/dw_hdmi-imx.c +++ b/drivers/staging/imx-drm/dw_hdmi-imx.c @@ -5,12 +5,19 @@ */ #include #include +#include #include #include #include #include