From patchwork Thu Jan 30 21:19:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 3559481 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 66959C02DC for ; Thu, 30 Jan 2014 21:23:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6BEC720173 for ; Thu, 30 Jan 2014 21:23:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 61CB320181 for ; Thu, 30 Jan 2014 21:23:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1AF56461EF; Thu, 30 Jan 2014 13:23:01 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qa0-f48.google.com (mail-qa0-f48.google.com [209.85.216.48]) by gabe.freedesktop.org (Postfix) with ESMTP id B71CF46AE9 for ; Thu, 30 Jan 2014 13:20:38 -0800 (PST) Received: by mail-qa0-f48.google.com with SMTP id f11so5187504qae.7 for ; Thu, 30 Jan 2014 13:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x1Srm7eVEU9hVQCIijp85Hkj2O4VOgqeVbZRXI36nnI=; b=En+5/YOh0uY5ovxs5ZXcarmrSpGS0KPZgRat1E97wAEUHpd7LPp+2hiSEnVkZfNA5P QemGY0tkeZ0Po1edIIAXVcd2143oeL93rS55LS8auB6YBuVgICoaUrrsYGL1H/cnHz2M TW58pBSgmV+2ey70UF22dEAM0jIBkqtvefNZQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x1Srm7eVEU9hVQCIijp85Hkj2O4VOgqeVbZRXI36nnI=; b=m3W7emqgeEDF3sPCEb0XGXB5kC9AahJQUisPn0ZEgeX2hCDYtZ2jBzGqq7YQB97tPt O4uTqyQcclnBMdymkBqil6V5NPZnzv6aTf4KZFqFNOBGs8blsE6aQfNy7FpN6DZf6R1c OaHT+65d8K19FGrrz3mX5+wDrJB+YrO2z1RiCcqpSnMz9W1lxhcmCzANR9l8bVHMbgRY 99OUzRn4rrJVJcfz+YzL9hvi5ygAW861h82KkakiSLUfoBVotP//ex3JrzDxkTqbl+7S YoSuqTennK3cUCWo16c1YNIcQUVUrsGsqNWprfXW/MP6FZB+svqQ7qHVkRYjS1+IsSqz xyng== X-Gm-Message-State: ALoCoQlpRXO8EuiW/SsGheZ0In/BlC2mAAU1l+C7IbNulF2J7/RVOYW+JddpGEYiMOmZI3HJrdtr X-Received: by 10.140.97.73 with SMTP id l67mr24562299qge.56.1391116838479; Thu, 30 Jan 2014 13:20:38 -0800 (PST) Received: from seanpaul-glaptop.roam.corp.google.com (cpe-173-095-180-236.nc.res.rr.com. [173.95.180.236]) by mx.google.com with ESMTPSA id r13sm20673608qan.7.2014.01.30.13.20.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jan 2014 13:20:37 -0800 (PST) From: Sean Paul To: dri-devel@lists.freedesktop.org, inki.dae@samsung.com Subject: [PATCH v4 30/34] drm/exynos: Implement drm_connector in hdmi directly Date: Thu, 30 Jan 2014 16:19:29 -0500 Message-Id: <1391116773-28471-31-git-send-email-seanpaul@chromium.org> X-Mailer: git-send-email 1.8.5.1 In-Reply-To: <1391116773-28471-1-git-send-email-seanpaul@chromium.org> References: <1391116773-28471-1-git-send-email-seanpaul@chromium.org> Cc: marcheu@chromium.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 This patch implements drm_connector in the hdmi driver directly, instead of using exynos_drm_connector. Signed-off-by: Sean Paul --- Changes in v3: - Added to the patchset Changes in v4: None drivers/gpu/drm/exynos/exynos_hdmi.c | 126 +++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 41 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_hdmi.c b/drivers/gpu/drm/exynos/exynos_hdmi.c index 3313743..925b2a2 100644 --- a/drivers/gpu/drm/exynos/exynos_hdmi.c +++ b/drivers/gpu/drm/exynos/exynos_hdmi.c @@ -44,9 +44,8 @@ #include #include -#define MAX_WIDTH 1920 -#define MAX_HEIGHT 1080 #define get_hdmi_display(dev) platform_get_drvdata(to_platform_device(dev)) +#define ctx_from_connector(c) container_of(c, struct hdmi_context, connector) /* AVI header and aspect ratio */ #define HDMI_AVI_VERSION 0x02 @@ -182,6 +181,8 @@ struct hdmi_conf_regs { struct hdmi_context { struct device *dev; struct drm_device *drm_dev; + struct drm_connector connector; + struct drm_encoder *encoder; bool hpd; bool powered; bool dvi_mode; @@ -740,42 +741,46 @@ static void hdmi_reg_infoframe(struct hdmi_context *hdata, } } -static int hdmi_initialize(struct exynos_drm_display *display, - struct drm_device *drm_dev) +static enum drm_connector_status hdmi_detect(struct drm_connector *connector, + bool force) { - struct hdmi_context *hdata = display->ctx; + struct hdmi_context *hdata = ctx_from_connector(connector); - hdata->drm_dev = drm_dev; - - return 0; + return hdata->hpd ? connector_status_connected : + connector_status_disconnected; } -static bool hdmi_is_connected(struct exynos_drm_display *display) +static void hdmi_connector_destroy(struct drm_connector *connector) { - struct hdmi_context *hdata = display->ctx; - - return hdata->hpd; } -static struct edid *hdmi_get_edid(struct exynos_drm_display *display, - struct drm_connector *connector) +static struct drm_connector_funcs hdmi_connector_funcs = { + .dpms = drm_helper_connector_dpms, + .fill_modes = drm_helper_probe_single_connector_modes, + .detect = hdmi_detect, + .destroy = hdmi_connector_destroy, +}; + +static int hdmi_get_modes(struct drm_connector *connector) { - struct edid *raw_edid; - struct hdmi_context *hdata = display->ctx; + struct hdmi_context *hdata = ctx_from_connector(connector); + struct edid *edid; if (!hdata->ddc_port) - return ERR_PTR(-ENODEV); + return -ENODEV; - raw_edid = drm_get_edid(connector, hdata->ddc_port->adapter); - if (!raw_edid) - return ERR_PTR(-ENODEV); + edid = drm_get_edid(connector, hdata->ddc_port->adapter); + if (!edid) + return -ENODEV; - hdata->dvi_mode = !drm_detect_hdmi_monitor(raw_edid); + hdata->dvi_mode = !drm_detect_hdmi_monitor(edid); DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n", (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"), - raw_edid->width_cm, raw_edid->height_cm); + edid->width_cm, edid->height_cm); + + drm_mode_connector_update_edid_property(connector, edid); - return raw_edid; + return drm_add_edid_modes(connector, edid); } static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock) @@ -800,10 +805,10 @@ static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock) return -EINVAL; } -static int hdmi_check_mode(struct exynos_drm_display *display, +static int hdmi_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode) { - struct hdmi_context *hdata = display->ctx; + struct hdmi_context *hdata = ctx_from_connector(connector); int ret; DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n", @@ -813,11 +818,60 @@ static int hdmi_check_mode(struct exynos_drm_display *display, ret = mixer_check_mode(mode); if (ret) - return ret; + return MODE_BAD; ret = hdmi_find_phy_conf(hdata, mode->clock * 1000); if (ret < 0) + return MODE_BAD; + + return MODE_OK; +} + +static struct drm_encoder *hdmi_best_encoder(struct drm_connector *connector) +{ + struct hdmi_context *hdata = ctx_from_connector(connector); + + return hdata->encoder; +} + +static struct drm_connector_helper_funcs hdmi_connector_helper_funcs = { + .get_modes = hdmi_get_modes, + .mode_valid = hdmi_mode_valid, + .best_encoder = hdmi_best_encoder, +}; + +static int hdmi_create_connector(struct exynos_drm_display *display, + struct drm_encoder *encoder) +{ + struct hdmi_context *hdata = display->ctx; + struct drm_connector *connector = &hdata->connector; + int ret; + + hdata->encoder = encoder; + connector->interlace_allowed = true; + connector->polled = DRM_CONNECTOR_POLL_HPD; + + ret = drm_connector_init(hdata->drm_dev, connector, + &hdmi_connector_funcs, DRM_MODE_CONNECTOR_HDMIA); + if (ret) { + DRM_ERROR("Failed to initialize connector with drm\n"); return ret; + } + + drm_connector_helper_add(connector, &hdmi_connector_helper_funcs); + drm_sysfs_connector_add(connector); + drm_mode_connector_attach_encoder(connector, encoder); + + return 0; +} + +static int hdmi_initialize(struct exynos_drm_display *display, + struct drm_device *drm_dev) +{ + struct hdmi_context *hdata = display->ctx; + + hdata->drm_dev = drm_dev; + return 0; } @@ -833,10 +887,10 @@ static void hdmi_mode_fixup(struct exynos_drm_display *display, drm_mode_set_crtcinfo(adjusted_mode, 0); - mode_ok = hdmi_check_mode(display, adjusted_mode); + mode_ok = hdmi_mode_valid(connector, adjusted_mode); /* just return if user desired mode exists. */ - if (mode_ok == 0) + if (mode_ok == MODE_OK) return; /* @@ -844,9 +898,9 @@ static void hdmi_mode_fixup(struct exynos_drm_display *display, * to adjusted_mode. */ list_for_each_entry(m, &connector->modes, head) { - mode_ok = hdmi_check_mode(display, m); + mode_ok = hdmi_mode_valid(connector, m); - if (mode_ok == 0) { + if (mode_ok == MODE_OK) { DRM_INFO("desired mode doesn't exist so\n"); DRM_INFO("use the most suitable mode among modes.\n"); @@ -1701,13 +1755,6 @@ static void hdmi_mode_set(struct exynos_drm_display *display, hdmi_v14_mode_set(hdata, mode); } -static void hdmi_get_max_resol(struct exynos_drm_display *display, - unsigned int *width, unsigned int *height) -{ - *width = MAX_WIDTH; - *height = MAX_HEIGHT; -} - static void hdmi_commit(struct exynos_drm_display *display) { struct hdmi_context *hdata = display->ctx; @@ -1802,10 +1849,7 @@ static void hdmi_dpms(struct exynos_drm_display *display, int mode) static struct exynos_drm_display_ops hdmi_display_ops = { .initialize = hdmi_initialize, - .is_connected = hdmi_is_connected, - .get_max_resol = hdmi_get_max_resol, - .get_edid = hdmi_get_edid, - .check_mode = hdmi_check_mode, + .create_connector = hdmi_create_connector, .mode_fixup = hdmi_mode_fixup, .mode_set = hdmi_mode_set, .dpms = hdmi_dpms,