From patchwork Mon Aug 1 13:50:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12933803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E0C2C00144 for ; Mon, 1 Aug 2022 13:58:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4133C911C1; Mon, 1 Aug 2022 13:55:14 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB90EC17E5 for ; Mon, 1 Aug 2022 13:50:33 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 73BFD4DF19; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659361831; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K8tsSiUcjwfcZ+Zqt1YGyG3w6tB3AKlGHNxA15opI/0=; b=ds1/cbh7Mxa2/Wr4Ft6CjKEIc8v/wfX22alsHoznKnFAe32Qt5x79HhI1uWiH5IOz2rHZO JPYmiDgJ6TU/mFzrb9RAqEzs/PsHyy2trEvi44bkpV/Ao9jsczIMCaqKV2zHDswaBPGgD1 XUygdUDM+LKXZIPxiTwHf2FF6uwDTQU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659361831; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K8tsSiUcjwfcZ+Zqt1YGyG3w6tB3AKlGHNxA15opI/0=; b=xTSjkDqdYGG3w3GaXc9WwkufIOPfAAAHY7LbAGqdhxhoBYVrZ4daJHm/8U46o0uvEGZiLn dvMITsTPNQ0kMTDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5208213ADF; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id qDAoEyfa52IDRwAAMHmgww (envelope-from ); Mon, 01 Aug 2022 13:50:31 +0000 From: Thomas Zimmermann To: javierm@redhat.com, geert@linux-m68k.org, airlied@linux.ie, daniel@ffwll.ch Subject: [PATCH v3 1/5] drm/simpledrm: Remove mem field from device structure Date: Mon, 1 Aug 2022 15:50:24 +0200 Message-Id: <20220801135028.30647-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801135028.30647-1-tzimmermann@suse.de> References: <20220801135028.30647-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Remove the unused mem field from struct simpledrm_device. Signed-off-by: Thomas Zimmermann Acked-by: Javier Martinez Canillas --- drivers/gpu/drm/tiny/simpledrm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c index 5422363690e7..c5a0dabfb6df 100644 --- a/drivers/gpu/drm/tiny/simpledrm.c +++ b/drivers/gpu/drm/tiny/simpledrm.c @@ -217,7 +217,6 @@ struct simpledrm_device { unsigned int pitch; /* memory management */ - struct resource *mem; void __iomem *screen_base; /* modesetting */ @@ -558,7 +557,6 @@ static int simpledrm_device_init_mm(struct simpledrm_device *sdev) if (!screen_base) return -ENOMEM; - sdev->mem = mem; sdev->screen_base = screen_base; return 0; From patchwork Mon Aug 1 13:50:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12933802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5C3CC00144 for ; Mon, 1 Aug 2022 13:57:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 53179C333C; Mon, 1 Aug 2022 13:55:37 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB77CC064D for ; Mon, 1 Aug 2022 13:50:33 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A19CA4DF1A; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659361831; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kaaM+xgobQWgNInC0yxql3Y0zIhJUL3KoKKh1C+ERwU=; b=dWOVKLeU0VcnVIKagw67FeH8sCjcFMQLjMEBboPxqjOQpx9Gncr8ND/9j5W1RRDAPu1SOB tbPE7KpjnGl+hOnDgnQ08O3tXX5SnOnT5kNpGuZXFfcE156qFC1VhQro5noPfKaGHW5e97 tQlii/rPg/wmgx4NN7BL/WcL1KlzQt0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659361831; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kaaM+xgobQWgNInC0yxql3Y0zIhJUL3KoKKh1C+ERwU=; b=WNfVcTB+iyJsewhBByGC6LFt0+QImu0sWcR2vV2xcRlJh7dUUdxftpCh9dIpNu4s2UQEwP aYvfNHgG/vvnHsBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7727913A72; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YFEtHCfa52IDRwAAMHmgww (envelope-from ); Mon, 01 Aug 2022 13:50:31 +0000 From: Thomas Zimmermann To: javierm@redhat.com, geert@linux-m68k.org, airlied@linux.ie, daniel@ffwll.ch Subject: [PATCH v3 2/5] drm/simpledrm: Inline device-init helpers Date: Mon, 1 Aug 2022 15:50:25 +0200 Message-Id: <20220801135028.30647-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801135028.30647-1-tzimmermann@suse.de> References: <20220801135028.30647-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Inline the helpers for initializing the hardware FB, the memory management and the modesetting into the device-creation function. No functional changes. In the original code, init helpers depended on values from other init helpers. Inlining the functions ensures that steps are taken in the correct order. It's also easier to see what happens. The device is simple enough to be set up in one function. Only clocks and regulators are still set up in their own helpers, as their presence is system dependent. Signed-off-by: Thomas Zimmermann Acked-by: Javier Martinez Canillas --- drivers/gpu/drm/tiny/simpledrm.c | 291 ++++++++++++++----------------- 1 file changed, 128 insertions(+), 163 deletions(-) diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c index c5a0dabfb6df..f458e8bec63e 100644 --- a/drivers/gpu/drm/tiny/simpledrm.c +++ b/drivers/gpu/drm/tiny/simpledrm.c @@ -449,119 +449,6 @@ static int simpledrm_device_init_regulators(struct simpledrm_device *sdev) } #endif -/* - * Simplefb settings - */ - -static struct drm_display_mode simpledrm_mode(unsigned int width, - unsigned int height) -{ - struct drm_display_mode mode = { SIMPLEDRM_MODE(width, height) }; - - mode.clock = mode.hdisplay * mode.vdisplay * 60 / 1000 /* kHz */; - drm_mode_set_name(&mode); - - return mode; -} - -static int simpledrm_device_init_fb(struct simpledrm_device *sdev) -{ - int width, height, stride; - const struct drm_format_info *format; - struct drm_device *dev = &sdev->dev; - struct platform_device *pdev = sdev->pdev; - const struct simplefb_platform_data *pd = dev_get_platdata(&pdev->dev); - struct device_node *of_node = pdev->dev.of_node; - - if (pd) { - width = simplefb_get_width_pd(dev, pd); - if (width < 0) - return width; - height = simplefb_get_height_pd(dev, pd); - if (height < 0) - return height; - stride = simplefb_get_stride_pd(dev, pd); - if (stride < 0) - return stride; - format = simplefb_get_format_pd(dev, pd); - if (IS_ERR(format)) - return PTR_ERR(format); - } else if (of_node) { - width = simplefb_get_width_of(dev, of_node); - if (width < 0) - return width; - height = simplefb_get_height_of(dev, of_node); - if (height < 0) - return height; - stride = simplefb_get_stride_of(dev, of_node); - if (stride < 0) - return stride; - format = simplefb_get_format_of(dev, of_node); - if (IS_ERR(format)) - return PTR_ERR(format); - } else { - drm_err(dev, "no simplefb configuration found\n"); - return -ENODEV; - } - - sdev->mode = simpledrm_mode(width, height); - sdev->format = format; - sdev->pitch = stride; - - drm_dbg_kms(dev, "display mode={" DRM_MODE_FMT "}\n", - DRM_MODE_ARG(&sdev->mode)); - drm_dbg_kms(dev, - "framebuffer format=%p4cc, size=%dx%d, stride=%d byte\n", - &format->format, width, height, stride); - - return 0; -} - -/* - * Memory management - */ - -static int simpledrm_device_init_mm(struct simpledrm_device *sdev) -{ - struct drm_device *dev = &sdev->dev; - struct platform_device *pdev = sdev->pdev; - struct resource *res, *mem; - void __iomem *screen_base; - int ret; - - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) - return -EINVAL; - - ret = devm_aperture_acquire_from_firmware(dev, res->start, resource_size(res)); - if (ret) { - drm_err(dev, "could not acquire memory range %pr: error %d\n", - res, ret); - return ret; - } - - mem = devm_request_mem_region(&pdev->dev, res->start, resource_size(res), - sdev->dev.driver->name); - if (!mem) { - /* - * We cannot make this fatal. Sometimes this comes from magic - * spaces our resource handlers simply don't know about. Use - * the I/O-memory resource as-is and try to map that instead. - */ - drm_warn(dev, "could not acquire memory region %pr\n", res); - mem = res; - } - - screen_base = devm_ioremap_wc(&pdev->dev, mem->start, - resource_size(mem)); - if (!screen_base) - return -ENOMEM; - - sdev->screen_base = screen_base; - - return 0; -} - /* * Modesetting */ @@ -738,6 +625,21 @@ static const struct drm_mode_config_funcs simpledrm_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; +/* + * Init / Cleanup + */ + +static struct drm_display_mode simpledrm_mode(unsigned int width, + unsigned int height) +{ + struct drm_display_mode mode = { SIMPLEDRM_MODE(width, height) }; + + mode.clock = mode.hdisplay * mode.vdisplay * 60 / 1000 /* kHz */; + drm_mode_set_name(&mode); + + return mode; +} + static const uint32_t *simpledrm_device_formats(struct simpledrm_device *sdev, size_t *nformats_out) { @@ -777,88 +679,151 @@ static const uint32_t *simpledrm_device_formats(struct simpledrm_device *sdev, return sdev->formats; } -static int simpledrm_device_init_modeset(struct simpledrm_device *sdev) +static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, + struct platform_device *pdev) { - struct drm_device *dev = &sdev->dev; - struct drm_display_mode *mode = &sdev->mode; - struct drm_connector *connector = &sdev->connector; - struct drm_simple_display_pipe *pipe = &sdev->pipe; + const struct simplefb_platform_data *pd = dev_get_platdata(&pdev->dev); + struct device_node *of_node = pdev->dev.of_node; + struct simpledrm_device *sdev; + struct drm_device *dev; + int width, height, stride; + const struct drm_format_info *format; + struct resource *res, *mem; + void __iomem *screen_base; + struct drm_connector *connector; + struct drm_simple_display_pipe *pipe; unsigned long max_width, max_height; const uint32_t *formats; size_t nformats; int ret; + sdev = devm_drm_dev_alloc(&pdev->dev, drv, struct simpledrm_device, dev); + if (IS_ERR(sdev)) + return ERR_CAST(sdev); + dev = &sdev->dev; + sdev->pdev = pdev; + platform_set_drvdata(pdev, sdev); + + /* + * Hardware settings + */ + + ret = simpledrm_device_init_clocks(sdev); + if (ret) + return ERR_PTR(ret); + ret = simpledrm_device_init_regulators(sdev); + if (ret) + return ERR_PTR(ret); + + if (pd) { + width = simplefb_get_width_pd(dev, pd); + if (width < 0) + return ERR_PTR(width); + height = simplefb_get_height_pd(dev, pd); + if (height < 0) + return ERR_PTR(height); + stride = simplefb_get_stride_pd(dev, pd); + if (stride < 0) + return ERR_PTR(stride); + format = simplefb_get_format_pd(dev, pd); + if (IS_ERR(format)) + return ERR_CAST(format); + } else if (of_node) { + width = simplefb_get_width_of(dev, of_node); + if (width < 0) + return ERR_PTR(width); + height = simplefb_get_height_of(dev, of_node); + if (height < 0) + return ERR_PTR(height); + stride = simplefb_get_stride_of(dev, of_node); + if (stride < 0) + return ERR_PTR(stride); + format = simplefb_get_format_of(dev, of_node); + if (IS_ERR(format)) + return ERR_CAST(format); + } else { + drm_err(dev, "no simplefb configuration found\n"); + return ERR_PTR(-ENODEV); + } + sdev->mode = simpledrm_mode(width, height); + sdev->format = format; + sdev->pitch = stride; + + drm_dbg(dev, "display mode={" DRM_MODE_FMT "}\n", DRM_MODE_ARG(&sdev->mode)); + drm_dbg(dev, "framebuffer format=%p4cc, size=%dx%d, stride=%d byte\n", + &format->format, width, height, stride); + + /* + * Memory management + */ + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return ERR_PTR(-EINVAL); + + ret = devm_aperture_acquire_from_firmware(dev, res->start, resource_size(res)); + if (ret) { + drm_err(dev, "could not acquire memory range %pr: error %d\n", res, ret); + return ERR_PTR(ret); + } + + mem = devm_request_mem_region(&pdev->dev, res->start, resource_size(res), drv->name); + if (!mem) { + /* + * We cannot make this fatal. Sometimes this comes from magic + * spaces our resource handlers simply don't know about. Use + * the I/O-memory resource as-is and try to map that instead. + */ + drm_warn(dev, "could not acquire memory region %pr\n", res); + mem = res; + } + + screen_base = devm_ioremap_wc(&pdev->dev, mem->start, resource_size(mem)); + if (!screen_base) + return ERR_PTR(-ENOMEM); + sdev->screen_base = screen_base; + + /* + * Modesetting + */ + ret = drmm_mode_config_init(dev); if (ret) - return ret; + return ERR_PTR(ret); - max_width = max_t(unsigned long, mode->hdisplay, DRM_SHADOW_PLANE_MAX_WIDTH); - max_height = max_t(unsigned long, mode->vdisplay, DRM_SHADOW_PLANE_MAX_HEIGHT); + max_width = max_t(unsigned long, width, DRM_SHADOW_PLANE_MAX_WIDTH); + max_height = max_t(unsigned long, height, DRM_SHADOW_PLANE_MAX_HEIGHT); - dev->mode_config.min_width = mode->hdisplay; + dev->mode_config.min_width = width; dev->mode_config.max_width = max_width; - dev->mode_config.min_height = mode->vdisplay; + dev->mode_config.min_height = height; dev->mode_config.max_height = max_height; - dev->mode_config.preferred_depth = sdev->format->cpp[0] * 8; + dev->mode_config.preferred_depth = format->cpp[0] * 8; dev->mode_config.funcs = &simpledrm_mode_config_funcs; + connector = &sdev->connector; ret = drm_connector_init(dev, connector, &simpledrm_connector_funcs, DRM_MODE_CONNECTOR_Unknown); if (ret) - return ret; + return ERR_PTR(ret); drm_connector_helper_add(connector, &simpledrm_connector_helper_funcs); drm_connector_set_panel_orientation_with_quirk(connector, DRM_MODE_PANEL_ORIENTATION_UNKNOWN, - mode->hdisplay, mode->vdisplay); + width, height); formats = simpledrm_device_formats(sdev, &nformats); + pipe = &sdev->pipe; ret = drm_simple_display_pipe_init(dev, pipe, &simpledrm_simple_display_pipe_funcs, formats, nformats, simpledrm_format_modifiers, connector); if (ret) - return ret; + return ERR_PTR(ret); drm_plane_enable_fb_damage_clips(&pipe->plane); drm_mode_config_reset(dev); - return 0; -} - -/* - * Init / Cleanup - */ - -static struct simpledrm_device * -simpledrm_device_create(struct drm_driver *drv, struct platform_device *pdev) -{ - struct simpledrm_device *sdev; - int ret; - - sdev = devm_drm_dev_alloc(&pdev->dev, drv, struct simpledrm_device, - dev); - if (IS_ERR(sdev)) - return ERR_CAST(sdev); - sdev->pdev = pdev; - platform_set_drvdata(pdev, sdev); - - ret = simpledrm_device_init_clocks(sdev); - if (ret) - return ERR_PTR(ret); - ret = simpledrm_device_init_regulators(sdev); - if (ret) - return ERR_PTR(ret); - ret = simpledrm_device_init_fb(sdev); - if (ret) - return ERR_PTR(ret); - ret = simpledrm_device_init_mm(sdev); - if (ret) - return ERR_PTR(ret); - ret = simpledrm_device_init_modeset(sdev); - if (ret) - return ERR_PTR(ret); - return sdev; } From patchwork Mon Aug 1 13:50:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12933809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E05DCC00144 for ; Mon, 1 Aug 2022 14:03:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD548C4329; Mon, 1 Aug 2022 13:57:09 +0000 (UTC) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7FB0DC2AAA for ; Mon, 1 Aug 2022 13:50:33 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C87DB66F62; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659361831; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i+Ukcq0L/VDgL6LldtANlmqa+RYUdHWOf9CIBxm5wH4=; b=eSPyOSRfN2dZKBqQSzr/fRfPV294LcJRWKpSwiv1bgxi7DZnNxOLy07K4GAzMIrBwVbEFR 7sO00dwhF3ZWxbpRuTu71pK3+rnYa9Q8KvDRzi3jLlnoclcqRW3f+fZA7yaxkOIQETQJmK iVeC3z4gIqJbO1hYZE9EShUz292d8U0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659361831; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i+Ukcq0L/VDgL6LldtANlmqa+RYUdHWOf9CIBxm5wH4=; b=psBnotvplcdrEe6dUs50/feWmmWySMqqHn9aUiKpr8esN15M/okoSNDxp1UpedzTR3czz5 MiVJ3W66xETuI4Cw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A3A2413ADF; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AKAfJyfa52IDRwAAMHmgww (envelope-from ); Mon, 01 Aug 2022 13:50:31 +0000 From: Thomas Zimmermann To: javierm@redhat.com, geert@linux-m68k.org, airlied@linux.ie, daniel@ffwll.ch Subject: [PATCH v3 3/5] drm/simpledrm: Remove pdev field from device structure Date: Mon, 1 Aug 2022 15:50:26 +0200 Message-Id: <20220801135028.30647-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801135028.30647-1-tzimmermann@suse.de> References: <20220801135028.30647-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Replace the remaining uses of the field pdev by upcasts from the Linux device and remove the field. Signed-off-by: Thomas Zimmermann Acked-by: Javier Martinez Canillas --- drivers/gpu/drm/tiny/simpledrm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c index f458e8bec63e..9d27608d7369 100644 --- a/drivers/gpu/drm/tiny/simpledrm.c +++ b/drivers/gpu/drm/tiny/simpledrm.c @@ -198,7 +198,6 @@ simplefb_get_format_of(struct drm_device *dev, struct device_node *of_node) struct simpledrm_device { struct drm_device dev; - struct platform_device *pdev; /* clocks */ #if defined CONFIG_OF && defined CONFIG_COMMON_CLK @@ -271,7 +270,7 @@ static void simpledrm_device_release_clocks(void *res) static int simpledrm_device_init_clocks(struct simpledrm_device *sdev) { struct drm_device *dev = &sdev->dev; - struct platform_device *pdev = sdev->pdev; + struct platform_device *pdev = to_platform_device(dev->dev); struct device_node *of_node = pdev->dev.of_node; struct clk *clock; unsigned int i; @@ -369,7 +368,7 @@ static void simpledrm_device_release_regulators(void *res) static int simpledrm_device_init_regulators(struct simpledrm_device *sdev) { struct drm_device *dev = &sdev->dev; - struct platform_device *pdev = sdev->pdev; + struct platform_device *pdev = to_platform_device(dev->dev); struct device_node *of_node = pdev->dev.of_node; struct property *prop; struct regulator *regulator; @@ -701,7 +700,6 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, if (IS_ERR(sdev)) return ERR_CAST(sdev); dev = &sdev->dev; - sdev->pdev = pdev; platform_set_drvdata(pdev, sdev); /* From patchwork Mon Aug 1 13:50:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12933810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5F9EFC00144 for ; Mon, 1 Aug 2022 14:03:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 15B7E14B1BF; Mon, 1 Aug 2022 13:58:19 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB80DC0AC6 for ; Mon, 1 Aug 2022 13:50:33 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id EE3DF4DF11; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659361831; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=raR5oTMFAEw6H259zs6BoIPEDKNiUxVjC/LRRvYTjK8=; b=JUiNd1l/BNhZwbvfwfQMWcDN0yvPIR0HmRA811JVm80m52a3Igp2of/acg2J/Z436r4TY3 3wbrn6r2t40SJ3vG37YTe768dXjbEWj3MvyendWv9abeJr5u8B7Xb5zjW9Da/xBW8+5My+ Bn/fpRXyE4mH7//5JxSYJn5pLI9QaoE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659361831; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=raR5oTMFAEw6H259zs6BoIPEDKNiUxVjC/LRRvYTjK8=; b=LggrkZvKzIHAwedVCv1gx13kJOW6zb/TM2nJijcoSNYoh9nCXJxSrVuUyx2GaSFPQbIFgg /iI7o04cYwls2zDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CAA0213A72; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6FmcMCfa52IDRwAAMHmgww (envelope-from ); Mon, 01 Aug 2022 13:50:31 +0000 From: Thomas Zimmermann To: javierm@redhat.com, geert@linux-m68k.org, airlied@linux.ie, daniel@ffwll.ch Subject: [PATCH v3 4/5] drm/simpledrm: Compute framebuffer stride if not set Date: Mon, 1 Aug 2022 15:50:27 +0200 Message-Id: <20220801135028.30647-5-tzimmermann@suse.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801135028.30647-1-tzimmermann@suse.de> References: <20220801135028.30647-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Compute the framebuffer's scanline stride length if not given by the simplefb data. v3: * get pixel size from drm_format_info_bpp() (Geert, Javier) Signed-off-by: Thomas Zimmermann Acked-by: Javier Martinez Canillas --- drivers/gpu/drm/tiny/simpledrm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c index 9d27608d7369..11a7348ccf4d 100644 --- a/drivers/gpu/drm/tiny/simpledrm.c +++ b/drivers/gpu/drm/tiny/simpledrm.c @@ -743,6 +743,9 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, drm_err(dev, "no simplefb configuration found\n"); return ERR_PTR(-ENODEV); } + if (!stride) + stride = DIV_ROUND_UP(drm_format_info_bpp(format, 0) * width, 8); + sdev->mode = simpledrm_mode(width, height); sdev->format = format; sdev->pitch = stride; From patchwork Mon Aug 1 13:50:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12933801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D44E9C19F2B for ; Mon, 1 Aug 2022 13:56:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E9BD3C1E01; Mon, 1 Aug 2022 13:55:15 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id F20C7C1AD9 for ; Mon, 1 Aug 2022 13:50:33 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 245F34DF0E; Mon, 1 Aug 2022 13:50:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1659361832; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wCCOz51TO3XsDpxvOgDWxtb2EWMo+ZtFrA7OPE6RhB8=; b=lXIGgAsEXHiyHPNzomBo6AIcz0lV4atI1Xe6q/EdsuARoT31Rh+fnBouVCvPQ4BFo8AUYg jft/ShQ7Cdx8cIFbClpQslSA4t0vX3jwWNRXJeMKKw8YvQzlF6jG+S8HOxcHS6kqlv1Kg4 3HXrzSXVHtg8HlzWhMYmFmOoQzOqRPA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1659361832; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wCCOz51TO3XsDpxvOgDWxtb2EWMo+ZtFrA7OPE6RhB8=; b=v4ymiLePCIvkY7oixj4iqLNH9updIFRgnRjHjk8f5De3uiggJJzIwV6Hg5B9c4FDb+UFcK j4u3C0BWUG5fpkDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F338713A72; Mon, 1 Aug 2022 13:50:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2MSbOifa52IDRwAAMHmgww (envelope-from ); Mon, 01 Aug 2022 13:50:31 +0000 From: Thomas Zimmermann To: javierm@redhat.com, geert@linux-m68k.org, airlied@linux.ie, daniel@ffwll.ch Subject: [PATCH v3 5/5] drm/simpledrm: Convert to atomic helpers Date: Mon, 1 Aug 2022 15:50:28 +0200 Message-Id: <20220801135028.30647-6-tzimmermann@suse.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801135028.30647-1-tzimmermann@suse.de> References: <20220801135028.30647-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Replace the simple-KMS helpers with the regular atomic helpers. The regular helpers are better architectured and therefore allow for easier code sharing among drivers. No functional changes. v3: * remove empty CRTC helpers atomic_{enable, disable} (Javier) * unconditionally run drm_atomic_helper_check_plane_state() Signed-off-by: Thomas Zimmermann Acked-by: Javier Martinez Canillas --- drivers/gpu/drm/tiny/simpledrm.c | 273 +++++++++++++++++++------------ 1 file changed, 168 insertions(+), 105 deletions(-) diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c index 11a7348ccf4d..82fd98f77981 100644 --- a/drivers/gpu/drm/tiny/simpledrm.c +++ b/drivers/gpu/drm/tiny/simpledrm.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -20,8 +21,8 @@ #include #include #include +#include #include -#include #define DRIVER_NAME "simpledrm" #define DRIVER_DESC "DRM driver for simple-framebuffer platform devices" @@ -221,8 +222,10 @@ struct simpledrm_device { /* modesetting */ uint32_t formats[8]; size_t nformats; + struct drm_plane primary_plane; + struct drm_crtc crtc; + struct drm_encoder encoder; struct drm_connector connector; - struct drm_simple_display_pipe pipe; }; static struct simpledrm_device *simpledrm_device_of_dev(struct drm_device *dev) @@ -460,7 +463,7 @@ static int simpledrm_device_init_regulators(struct simpledrm_device *sdev) * TODO: Add blit helpers for remaining formats and uncomment * constants. */ -static const uint32_t simpledrm_default_formats[] = { +static const uint32_t simpledrm_primary_plane_formats[] = { DRM_FORMAT_XRGB8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, @@ -471,73 +474,44 @@ static const uint32_t simpledrm_default_formats[] = { DRM_FORMAT_ARGB2101010, }; -static const uint64_t simpledrm_format_modifiers[] = { +static const uint64_t simpledrm_primary_plane_format_modifiers[] = { DRM_FORMAT_MOD_LINEAR, DRM_FORMAT_MOD_INVALID }; -static int simpledrm_connector_helper_get_modes(struct drm_connector *connector) +static int simpledrm_primary_plane_helper_atomic_check(struct drm_plane *plane, + struct drm_atomic_state *new_state) { - struct simpledrm_device *sdev = simpledrm_device_of_dev(connector->dev); - struct drm_display_mode *mode; - - mode = drm_mode_duplicate(connector->dev, &sdev->mode); - if (!mode) - return 0; - - if (mode->name[0] == '\0') - drm_mode_set_name(mode); - - mode->type |= DRM_MODE_TYPE_PREFERRED; - drm_mode_probed_add(connector, mode); - - if (mode->width_mm) - connector->display_info.width_mm = mode->width_mm; - if (mode->height_mm) - connector->display_info.height_mm = mode->height_mm; - - return 1; -} - -static const struct drm_connector_helper_funcs simpledrm_connector_helper_funcs = { - .get_modes = simpledrm_connector_helper_get_modes, -}; - -static const struct drm_connector_funcs simpledrm_connector_funcs = { - .reset = drm_atomic_helper_connector_reset, - .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, -}; + struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane); + struct drm_crtc *new_crtc = new_plane_state->crtc; + struct drm_crtc_state *new_crtc_state = NULL; + int ret; -static enum drm_mode_status -simpledrm_simple_display_pipe_mode_valid(struct drm_simple_display_pipe *pipe, - const struct drm_display_mode *mode) -{ - struct simpledrm_device *sdev = simpledrm_device_of_dev(pipe->crtc.dev); + if (new_crtc) + new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc); - if (mode->hdisplay != sdev->mode.hdisplay && - mode->vdisplay != sdev->mode.vdisplay) - return MODE_ONE_SIZE; - else if (mode->hdisplay != sdev->mode.hdisplay) - return MODE_ONE_WIDTH; - else if (mode->vdisplay != sdev->mode.vdisplay) - return MODE_ONE_HEIGHT; + ret = drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state, + DRM_PLANE_NO_SCALING, + DRM_PLANE_NO_SCALING, + false, false); + if (ret) + return ret; + else if (!new_plane_state->visible) + return 0; - return MODE_OK; + return 0; } -static void -simpledrm_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, - struct drm_crtc_state *crtc_state, - struct drm_plane_state *plane_state) +static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane, + struct drm_atomic_state *old_state) { - struct simpledrm_device *sdev = simpledrm_device_of_dev(pipe->crtc.dev); + struct drm_plane_state *plane_state = plane->state; + struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(old_state, plane); struct drm_shadow_plane_state *shadow_plane_state = to_drm_shadow_plane_state(plane_state); - struct drm_framebuffer *fb = plane_state->fb; void *vmap = shadow_plane_state->data[0].vaddr; /* TODO: Use mapping abstraction */ - struct drm_device *dev = &sdev->dev; + struct drm_framebuffer *fb = plane_state->fb; + struct drm_device *dev = plane->dev; + struct simpledrm_device *sdev = simpledrm_device_of_dev(dev); void __iomem *dst = sdev->screen_base; struct drm_rect src_clip, dst_clip; int idx; @@ -545,7 +519,8 @@ simpledrm_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, if (!fb) return; - drm_rect_fp_to_int(&src_clip, &plane_state->src); + if (!drm_atomic_helper_damage_merged(old_plane_state, plane_state, &src_clip)) + return; dst_clip = plane_state->dst; if (!drm_rect_intersect(&dst_clip, &src_clip)) @@ -560,11 +535,11 @@ simpledrm_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, drm_dev_exit(idx); } -static void -simpledrm_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) +static void simpledrm_primary_plane_helper_atomic_disable(struct drm_plane *plane, + struct drm_atomic_state *old_state) { - struct simpledrm_device *sdev = simpledrm_device_of_dev(pipe->crtc.dev); - struct drm_device *dev = &sdev->dev; + struct drm_device *dev = plane->dev; + struct simpledrm_device *sdev = simpledrm_device_of_dev(dev); int idx; if (!drm_dev_enter(dev, &idx)) @@ -576,46 +551,105 @@ simpledrm_simple_display_pipe_disable(struct drm_simple_display_pipe *pipe) drm_dev_exit(idx); } -static void -simpledrm_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, - struct drm_plane_state *old_plane_state) +static const struct drm_plane_helper_funcs simpledrm_primary_plane_helper_funcs = { + DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, + .atomic_check = simpledrm_primary_plane_helper_atomic_check, + .atomic_update = simpledrm_primary_plane_helper_atomic_update, + .atomic_disable = simpledrm_primary_plane_helper_atomic_disable, +}; + +static const struct drm_plane_funcs simpledrm_primary_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = drm_plane_cleanup, + DRM_GEM_SHADOW_PLANE_FUNCS, +}; + +static enum drm_mode_status simpledrm_crtc_helper_mode_valid(struct drm_crtc *crtc, + const struct drm_display_mode *mode) { - struct simpledrm_device *sdev = simpledrm_device_of_dev(pipe->crtc.dev); - struct drm_plane_state *plane_state = pipe->plane.state; - struct drm_shadow_plane_state *shadow_plane_state = to_drm_shadow_plane_state(plane_state); - void *vmap = shadow_plane_state->data[0].vaddr; /* TODO: Use mapping abstraction */ - struct drm_framebuffer *fb = plane_state->fb; - struct drm_device *dev = &sdev->dev; - void __iomem *dst = sdev->screen_base; - struct drm_rect src_clip, dst_clip; - int idx; + struct simpledrm_device *sdev = simpledrm_device_of_dev(crtc->dev); - if (!fb) - return; + if (mode->hdisplay != sdev->mode.hdisplay && + mode->vdisplay != sdev->mode.vdisplay) + return MODE_ONE_SIZE; + else if (mode->hdisplay != sdev->mode.hdisplay) + return MODE_ONE_WIDTH; + else if (mode->vdisplay != sdev->mode.vdisplay) + return MODE_ONE_HEIGHT; - if (!drm_atomic_helper_damage_merged(old_plane_state, plane_state, &src_clip)) - return; + return MODE_OK; +} - dst_clip = plane_state->dst; - if (!drm_rect_intersect(&dst_clip, &src_clip)) - return; +static int simpledrm_crtc_helper_atomic_check(struct drm_crtc *crtc, + struct drm_atomic_state *new_state) +{ + struct drm_crtc_state *new_crtc_state = drm_atomic_get_new_crtc_state(new_state, crtc); + int ret; - if (!drm_dev_enter(dev, &idx)) - return; + ret = drm_atomic_helper_check_crtc_state(new_crtc_state, false); + if (ret) + return ret; - dst += drm_fb_clip_offset(sdev->pitch, sdev->format, &dst_clip); - drm_fb_blit_toio(dst, sdev->pitch, sdev->format->format, vmap, fb, &src_clip); + return drm_atomic_add_affected_planes(new_state, crtc); +} - drm_dev_exit(idx); +/* + * The CRTC is always enabled. Screen updates are performed by + * the primary plane's atomic_update function. Disabling clears + * the screen in the primary plane's atomic_disable function. + */ +static const struct drm_crtc_helper_funcs simpledrm_crtc_helper_funcs = { + .mode_valid = simpledrm_crtc_helper_mode_valid, + .atomic_check = simpledrm_crtc_helper_atomic_check, +}; + +static const struct drm_crtc_funcs simpledrm_crtc_funcs = { + .reset = drm_atomic_helper_crtc_reset, + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, +}; + +static const struct drm_encoder_funcs simpledrm_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + +static int simpledrm_connector_helper_get_modes(struct drm_connector *connector) +{ + struct simpledrm_device *sdev = simpledrm_device_of_dev(connector->dev); + struct drm_display_mode *mode; + + mode = drm_mode_duplicate(connector->dev, &sdev->mode); + if (!mode) + return 0; + + if (mode->name[0] == '\0') + drm_mode_set_name(mode); + + mode->type |= DRM_MODE_TYPE_PREFERRED; + drm_mode_probed_add(connector, mode); + + if (mode->width_mm) + connector->display_info.width_mm = mode->width_mm; + if (mode->height_mm) + connector->display_info.height_mm = mode->height_mm; + + return 1; } -static const struct drm_simple_display_pipe_funcs -simpledrm_simple_display_pipe_funcs = { - .mode_valid = simpledrm_simple_display_pipe_mode_valid, - .enable = simpledrm_simple_display_pipe_enable, - .disable = simpledrm_simple_display_pipe_disable, - .update = simpledrm_simple_display_pipe_update, - DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS, +static const struct drm_connector_helper_funcs simpledrm_connector_helper_funcs = { + .get_modes = simpledrm_connector_helper_get_modes, +}; + +static const struct drm_connector_funcs simpledrm_connector_funcs = { + .reset = drm_atomic_helper_connector_reset, + .fill_modes = drm_helper_probe_single_connector_modes, + .destroy = drm_connector_cleanup, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; static const struct drm_mode_config_funcs simpledrm_mode_config_funcs = { @@ -653,10 +687,10 @@ static const uint32_t *simpledrm_device_formats(struct simpledrm_device *sdev, sdev->nformats = 1; /* default formats go second */ - for (i = 0; i < ARRAY_SIZE(simpledrm_default_formats); ++i) { - if (simpledrm_default_formats[i] == sdev->format->format) + for (i = 0; i < ARRAY_SIZE(simpledrm_primary_plane_formats); ++i) { + if (simpledrm_primary_plane_formats[i] == sdev->format->format) continue; /* native format already went first */ - sdev->formats[sdev->nformats] = simpledrm_default_formats[i]; + sdev->formats[sdev->nformats] = simpledrm_primary_plane_formats[i]; sdev->nformats++; } @@ -689,8 +723,10 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, const struct drm_format_info *format; struct resource *res, *mem; void __iomem *screen_base; + struct drm_plane *primary_plane; + struct drm_crtc *crtc; + struct drm_encoder *encoder; struct drm_connector *connector; - struct drm_simple_display_pipe *pipe; unsigned long max_width, max_height; const uint32_t *formats; size_t nformats; @@ -802,6 +838,40 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, dev->mode_config.preferred_depth = format->cpp[0] * 8; dev->mode_config.funcs = &simpledrm_mode_config_funcs; + /* Primary plane */ + + formats = simpledrm_device_formats(sdev, &nformats); + + primary_plane = &sdev->primary_plane; + ret = drm_universal_plane_init(dev, primary_plane, 0, &simpledrm_primary_plane_funcs, + formats, nformats, + simpledrm_primary_plane_format_modifiers, + DRM_PLANE_TYPE_PRIMARY, NULL); + if (ret) + return ERR_PTR(ret); + drm_plane_helper_add(primary_plane, &simpledrm_primary_plane_helper_funcs); + drm_plane_enable_fb_damage_clips(primary_plane); + + /* CRTC */ + + crtc = &sdev->crtc; + ret = drm_crtc_init_with_planes(dev, crtc, primary_plane, NULL, + &simpledrm_crtc_funcs, NULL); + if (ret) + return ERR_PTR(ret); + drm_crtc_helper_add(crtc, &simpledrm_crtc_helper_funcs); + + /* Encoder */ + + encoder = &sdev->encoder; + ret = drm_encoder_init(dev, encoder, &simpledrm_encoder_funcs, + DRM_MODE_ENCODER_NONE, NULL); + if (ret) + return ERR_PTR(ret); + encoder->possible_crtcs = drm_crtc_mask(crtc); + + /* Connector */ + connector = &sdev->connector; ret = drm_connector_init(dev, connector, &simpledrm_connector_funcs, DRM_MODE_CONNECTOR_Unknown); @@ -812,17 +882,10 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, DRM_MODE_PANEL_ORIENTATION_UNKNOWN, width, height); - formats = simpledrm_device_formats(sdev, &nformats); - - pipe = &sdev->pipe; - ret = drm_simple_display_pipe_init(dev, pipe, &simpledrm_simple_display_pipe_funcs, - formats, nformats, simpledrm_format_modifiers, - connector); + ret = drm_connector_attach_encoder(connector, encoder); if (ret) return ERR_PTR(ret); - drm_plane_enable_fb_damage_clips(&pipe->plane); - drm_mode_config_reset(dev); return sdev;