From patchwork Sun Jan 20 11:43:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10772363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00AB314E5 for ; Sun, 20 Jan 2019 11:43:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E48BB2AA4A for ; Sun, 20 Jan 2019 11:43:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D91322AA4C; Sun, 20 Jan 2019 11:43:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 706052AA4A for ; Sun, 20 Jan 2019 11:43:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AB1E06E5F2; Sun, 20 Jan 2019 11:43:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 477086E5EB for ; Sun, 20 Jan 2019 11:43:31 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:41476 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1glBVh-0000O0-DZ; Sun, 20 Jan 2019 12:43:29 +0100 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 03/11] drm/simple-kms-helper: Add drm_simple_connector_create() Date: Sun, 20 Jan 2019 12:43:10 +0100 Message-Id: <20190120114318.49199-4-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190120114318.49199-1-noralf@tronnes.org> References: <20190120114318.49199-1-noralf@tronnes.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: david@lechnology.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This adds a function that creates a simple connector that has only one static mode. Additionally add a helper to set &drm_mode_config width and height from the static mode. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_simple_kms_helper.c | 122 ++++++++++++++++++++++++ include/drm/drm_simple_kms_helper.h | 6 ++ 2 files changed, 128 insertions(+) diff --git a/drivers/gpu/drm/drm_simple_kms_helper.c b/drivers/gpu/drm/drm_simple_kms_helper.c index 917812448d1b..ca29975afefe 100644 --- a/drivers/gpu/drm/drm_simple_kms_helper.c +++ b/drivers/gpu/drm/drm_simple_kms_helper.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include @@ -299,4 +301,124 @@ int drm_simple_display_pipe_init(struct drm_device *dev, } EXPORT_SYMBOL(drm_simple_display_pipe_init); +static const struct drm_connector_helper_funcs drm_simple_connector_hfuncs = { + /* dummy for the atomic helper */ +}; + +static int drm_simple_connector_fill_modes(struct drm_connector *connector, + uint32_t maxX, uint32_t maxY) +{ + return 1; +} + +static void drm_simple_connector_destroy(struct drm_connector *connector) +{ + drm_connector_cleanup(connector); + kfree(connector); +} + +static const struct drm_connector_funcs drm_simple_connector_funcs = { + .reset = drm_atomic_helper_connector_reset, + .fill_modes = drm_simple_connector_fill_modes, + .destroy = drm_simple_connector_destroy, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, +}; + +/** + * drm_simple_connector_create - Create a connector with one static mode + * @dev: DRM device + * @connector_type: Connector type + * @mode: Supported display mode + * @rotation: Initial @mode rotation in degrees + * + * This function creates a &drm_connector that has one fixed &drm_display_mode + * which will be rotated according to @rotation. + * + * Returns: + * Pointer to connector on success, or ERR_PTR on failure. + */ +struct drm_connector * +drm_simple_connector_create(struct drm_device *dev, int connector_type, + const struct drm_display_mode *mode, + unsigned int rotation) +{ + struct drm_display_mode *mode_dup = NULL; + struct drm_connector *connector; + int ret; + + connector = kzalloc(sizeof(*connector), GFP_KERNEL); + if (!connector) + return ERR_PTR(-ENOMEM); + + drm_connector_helper_add(connector, &drm_simple_connector_hfuncs); + ret = drm_connector_init(dev, connector, &drm_simple_connector_funcs, + connector_type); + if (ret) + goto err_free; + + connector->status = connector_status_connected; + + mode_dup = drm_mode_duplicate(dev, mode); + if (!mode_dup) { + ret = -ENOMEM; + goto err_cleanup; + } + + if (rotation == 90 || rotation == 270) { + swap(mode_dup->hdisplay, mode_dup->vdisplay); + swap(mode_dup->hsync_start, mode_dup->vsync_start); + swap(mode_dup->hsync_end, mode_dup->vsync_end); + swap(mode_dup->htotal, mode_dup->vtotal); + swap(mode_dup->width_mm, mode_dup->height_mm); + } else if (rotation != 0 && rotation != 180) { + DRM_ERROR("Illegal rotation value %u\n", rotation); + ret = -EINVAL; + goto err_cleanup; + } + + mode_dup->type |= DRM_MODE_TYPE_PREFERRED; + if (mode_dup->name[0] == '\0') + drm_mode_set_name(mode_dup); + + list_add(&mode_dup->head, &connector->modes); + + connector->display_info.width_mm = mode_dup->width_mm; + connector->display_info.height_mm = mode_dup->height_mm; + + return connector; + +err_cleanup: + drm_connector_cleanup(connector); + drm_mode_destroy(dev, mode_dup); +err_free: + kfree(connector); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL(drm_simple_connector_create); + +/** + * drm_simple_connector_set_mode_config - Set &drm_mode_config width and height + * @connector: Connector + * + * This function sets the &drm_mode_config min/max width and height based on the + * connector fixed display mode. + */ +void drm_simple_connector_set_mode_config(struct drm_connector *connector) +{ + struct drm_mode_config *mode_config = &connector->dev->mode_config; + struct drm_display_mode *mode; + + mode = list_first_entry(&connector->modes, struct drm_display_mode, head); + if (WARN_ON(!mode)) + return; + + mode_config->min_width = mode->hdisplay; + mode_config->max_width = mode->hdisplay; + mode_config->min_height = mode->vdisplay; + mode_config->max_height = mode->vdisplay; +} +EXPORT_SYMBOL(drm_simple_connector_set_mode_config); + MODULE_LICENSE("GPL"); diff --git a/include/drm/drm_simple_kms_helper.h b/include/drm/drm_simple_kms_helper.h index 451960438a29..ab3d847b7713 100644 --- a/include/drm/drm_simple_kms_helper.h +++ b/include/drm/drm_simple_kms_helper.h @@ -182,4 +182,10 @@ int drm_simple_display_pipe_init(struct drm_device *dev, const uint64_t *format_modifiers, struct drm_connector *connector); +struct drm_connector * +drm_simple_connector_create(struct drm_device *dev, int connector_type, + const struct drm_display_mode *mode, + unsigned int rotation); +void drm_simple_connector_set_mode_config(struct drm_connector *connector); + #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */