From patchwork Mon Jul 29 19:55:25 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: 11064449 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 A3A391823 for ; Mon, 29 Jul 2019 19:55:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95B22209CE for ; Mon, 29 Jul 2019 19:55:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A15127FC0; Mon, 29 Jul 2019 19:55:56 +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 0B3EB27FB0 for ; Mon, 29 Jul 2019 19:55:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B4766E1D8; Mon, 29 Jul 2019 19:55:50 +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 3E22F89D44 for ; Mon, 29 Jul 2019 19:55:49 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:57528 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 1hsBkJ-0003F7-8z; Mon, 29 Jul 2019 21:55:47 +0200 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [RFC 3/4] drm/mipi-dbi: Support command mode panel drivers Date: Mon, 29 Jul 2019 21:55:25 +0200 Message-Id: <20190729195526.13337-4-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190729195526.13337-1-noralf@tronnes.org> References: <20190729195526.13337-1-noralf@tronnes.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=iUsAn6d1xonZz2FlYpvAh2knModBIOcpF6Herk4RzKk=; b=WlyaknEB+NAHQw8WErrA3h23DHAG5QjeIpXDrAhz+UwVKwS+INg0Ge7QDqKlwtxvJRI7xA/EyFUALYFOHr7KEFXEEIlHhWyLa1slusffPCaU+1t1e825k7MWQXCe7Sj+pxVvpkukKWURoY7YN/cr4taSb0fGzbgZ1980T0QI2t5moiv/aJxz24S0e79U+QzBBLU6Cj3v8BM3gW1ew5qvwfOOLIUxLn5DVdZVFMrc+TBjWmEvnKJYAGI/tcN4E4WnkaU62ohytpy+bosMYmqRG3Z/QmRRoy/jzzUBmwKUiVXLSv0o0DGvI1Wt2S6oku1CpJRKIILGNlggPPGYQRYZEQ==; 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: daniel.vetter@ffwll.ch, josef@lusticky.cz, thierry.reding@gmail.com, laurent.pinchart@ideasonboard.com, sam@ravnborg.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This adds a function that registers a DRM driver for use with MIPI DBI panels in command mode. That is, framebuffer upload over DBI. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/drm_mipi_dbi.c | 110 +++++++++++++++++++++++++++++++++ include/drm/drm_mipi_dbi.h | 8 +++ 2 files changed, 118 insertions(+) diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c index 1961f713aaab..ef6b843eaf31 100644 --- a/drivers/gpu/drm/drm_mipi_dbi.c +++ b/drivers/gpu/drm/drm_mipi_dbi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -17,11 +18,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -597,6 +600,113 @@ void mipi_dbi_release(struct drm_device *drm) } EXPORT_SYMBOL(mipi_dbi_release); +static void drm_mipi_dbi_panel_pipe_enable(struct drm_simple_display_pipe *pipe, + struct drm_crtc_state *crtc_state, + struct drm_plane_state *plane_state) +{ + struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); + struct drm_panel *panel = dbidev->panel; + int ret, idx; + + if (!drm_dev_enter(pipe->crtc.dev, &idx)) + return; + + DRM_DEBUG_KMS("\n"); + + ret = drm_panel_prepare(panel); + if (ret) + goto out_exit; + + mipi_dbi_enable_flush(dbidev, crtc_state, plane_state); + + drm_panel_enable(panel); +out_exit: + drm_dev_exit(idx); +} + +static void drm_mipi_dbi_panel_pipe_disable(struct drm_simple_display_pipe *pipe) +{ + struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); + struct drm_panel *panel = dbidev->panel; + + if (!dbidev->enabled) + return; + + DRM_DEBUG_KMS("\n"); + + dbidev->enabled = false; + drm_panel_disable(panel); + drm_panel_unprepare(panel); +} + +static const struct drm_simple_display_pipe_funcs drm_mipi_dbi_pipe_funcs = { + .enable = drm_mipi_dbi_panel_pipe_enable, + .disable = drm_mipi_dbi_panel_pipe_disable, + .update = mipi_dbi_pipe_update, + .prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb, +}; + +DEFINE_DRM_GEM_CMA_FOPS(drm_mipi_dbi_fops); + +static struct drm_driver drm_mipi_dbi_driver = { + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, + .fops = &drm_mipi_dbi_fops, + .release = mipi_dbi_release, + DRM_GEM_CMA_VMAP_DRIVER_OPS, + .debugfs_init = mipi_dbi_debugfs_init, + .name = "drm_mipi_dbi", + .desc = "DRM MIPI DBI", + .date = "20190729", + .major = 1, + .minor = 0, +}; + +/** + * drm_mipi_dbi_panel_register - Register a MIPI DBI DRM driver + * @panel: DRM Panel + * @dbidev: MIPI DBI device structure to initialize + * @mode: Display mode + * + * This function registeres a DRM driver with @panel attached. + * + * Returns: + * Zero on success, negative error code on failure. + */ +int drm_mipi_dbi_panel_register(struct drm_panel *panel, struct mipi_dbi_dev *dbidev, + const struct drm_display_mode *mode) +{ + struct device *dev = panel->dev; + struct drm_device *drm; + u32 rotation = 0; + int ret; + + dbidev->panel = panel; + + drm = &dbidev->drm; + ret = devm_drm_dev_init(dev, drm, &drm_mipi_dbi_driver); + if (ret) { + kfree(dbidev); + return ret; + } + + drm_mode_config_init(drm); + + device_property_read_u32(dev, "rotation", &rotation); + + ret = mipi_dbi_dev_init(dbidev, &drm_mipi_dbi_pipe_funcs, mode, rotation); + + drm_mode_config_reset(drm); + + ret = drm_dev_register(drm, 0); + if (ret) + return ret; + + drm_fbdev_generic_setup(drm, 16); + + return 0; +} +EXPORT_SYMBOL(drm_mipi_dbi_panel_register); + /** * mipi_dbi_hw_reset - Hardware reset of controller * @dbi: MIPI DBI structure diff --git a/include/drm/drm_mipi_dbi.h b/include/drm/drm_mipi_dbi.h index 67c66f5ee591..e5047208ffb8 100644 --- a/include/drm/drm_mipi_dbi.h +++ b/include/drm/drm_mipi_dbi.h @@ -12,6 +12,7 @@ #include #include +struct drm_panel; struct drm_rect; struct spi_device; struct gpio_desc; @@ -123,6 +124,11 @@ struct mipi_dbi_dev { * @dbi: MIPI DBI interface */ struct mipi_dbi dbi; + + /** + * @panel: Attached DRM panel. See drm_mipi_dbi_panel_register(). + */ + struct drm_panel *panel; }; static inline struct mipi_dbi_dev *drm_to_mipi_dbi_dev(struct drm_device *drm) @@ -140,6 +146,8 @@ int mipi_dbi_dev_init_with_formats(struct mipi_dbi_dev *dbidev, int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev, const struct drm_simple_display_pipe_funcs *funcs, const struct drm_display_mode *mode, unsigned int rotation); +int drm_mipi_dbi_panel_register(struct drm_panel *panel, struct mipi_dbi_dev *dbidev, + const struct drm_display_mode *mode); void mipi_dbi_release(struct drm_device *drm); void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe, struct drm_plane_state *old_state);