mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: dri-devel@lists.freedesktop.org
Cc: daniel@ffwll.ch, treding@nvidia.com,
	linux-kernel@vger.kernel.org,
	"Noralf Trønnes" <noralf@tronnes.org>
Subject: [PATCH 4/4] drm/panel: Add helper for simple panel connector
Date: Thu,  5 May 2016 15:24:34 +0200	[thread overview]
Message-ID: <1462454674-2246-5-git-send-email-noralf@tronnes.org> (raw)
In-Reply-To: <1462454674-2246-1-git-send-email-noralf@tronnes.org>

Add function to create a simple connector for a panel.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
 drivers/gpu/drm/Makefile           |   1 +
 drivers/gpu/drm/drm_panel_helper.c | 117 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/panel/Kconfig      |   7 +++
 include/drm/drm_panel_helper.h     |  20 +++++++
 4 files changed, 145 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_panel_helper.c
 create mode 100644 include/drm/drm_panel_helper.h

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 7e99923..3f3696c 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -18,6 +18,7 @@ drm-$(CONFIG_COMPAT) += drm_ioc32.o
 drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
 drm-$(CONFIG_PCI) += ati_pcigart.o
 drm-$(CONFIG_DRM_PANEL) += drm_panel.o
+drm-$(CONFIG_DRM_PANEL_HELPER) += drm_panel_helper.o
 drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_AGP) += drm_agpsupport.o
 
diff --git a/drivers/gpu/drm/drm_panel_helper.c b/drivers/gpu/drm/drm_panel_helper.c
new file mode 100644
index 0000000..5d8b623
--- /dev/null
+++ b/drivers/gpu/drm/drm_panel_helper.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2016 Noralf Trønnes
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include <drm/drmP.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_panel.h>
+
+struct drm_panel_connector {
+	struct drm_connector base;
+	struct drm_panel *panel;
+};
+
+static inline struct drm_panel_connector *
+to_drm_panel_connector(struct drm_connector *connector)
+{
+	return container_of(connector, struct drm_panel_connector, base);
+}
+
+static int drm_panel_connector_get_modes(struct drm_connector *connector)
+{
+	return drm_panel_get_modes(to_drm_panel_connector(connector)->panel);
+}
+
+static struct drm_encoder *
+drm_panel_connector_best_encoder(struct drm_connector *connector)
+{
+	return drm_encoder_find(connector->dev, connector->encoder_ids[0]);
+}
+
+static const struct drm_connector_helper_funcs drm_panel_connector_hfuncs = {
+	.get_modes = drm_panel_connector_get_modes,
+	.best_encoder = drm_panel_connector_best_encoder,
+};
+
+static enum drm_connector_status
+drm_panel_connector_detect(struct drm_connector *connector, bool force)
+{
+	if (drm_device_is_unplugged(connector->dev))
+		return connector_status_disconnected;
+
+	return connector->status;
+}
+
+static void drm_panel_connector_destroy(struct drm_connector *connector)
+{
+	struct drm_panel_connector *panel_connector;
+
+	panel_connector = to_drm_panel_connector(connector);
+	drm_panel_detach(panel_connector->panel);
+	drm_panel_remove(panel_connector->panel);
+	drm_connector_unregister(connector);
+	drm_connector_cleanup(connector);
+	kfree(panel_connector);
+}
+
+static const struct drm_connector_funcs drm_panel_connector_funcs = {
+	.dpms = drm_atomic_helper_connector_dpms,
+	.reset = drm_atomic_helper_connector_reset,
+	.detect = drm_panel_connector_detect,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.destroy = drm_panel_connector_destroy,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+/**
+ * drm_panel_connector_create - Create simple connector for panel
+ * @dev: DRM device
+ * @panel: DRM panel
+ * @connector_type: user visible type of the connector
+ *
+ * Creates a simple connector for a panel.
+ * The panel needs to provide a get_modes() function.
+ *
+ * Returns:
+ * Pointer to new connector or ERR_PTR on failure.
+ */
+struct drm_connector *drm_panel_connector_create(struct drm_device *dev,
+						 struct drm_panel *panel,
+						 int connector_type)
+{
+	struct drm_panel_connector *panel_connector;
+	struct drm_connector *connector;
+	int ret;
+
+	panel_connector = kzalloc(sizeof(*panel_connector), GFP_KERNEL);
+	if (!panel_connector)
+		return ERR_PTR(-ENOMEM);
+
+	panel_connector->panel = panel;
+	connector = &panel_connector->base;
+	drm_connector_helper_add(connector, &drm_panel_connector_hfuncs);
+	ret = drm_connector_init(dev, connector, &drm_panel_connector_funcs,
+				 connector_type);
+	if (ret) {
+		kfree(panel_connector);
+		return ERR_PTR(ret);
+	}
+
+	connector->status = connector_status_connected;
+	drm_panel_init(panel);
+	drm_panel_add(panel);
+	drm_panel_attach(panel, connector);
+
+	return connector;
+}
+EXPORT_SYMBOL(drm_panel_connector_create);
diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 1500ab9..87264a3 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -4,6 +4,13 @@ config DRM_PANEL
 	help
 	  Panel registration and lookup framework.
 
+config DRM_PANEL_HELPER
+	bool
+	depends on DRM
+	select DRM_PANEL
+	help
+	  Panel helper.
+
 menu "Display Panels"
 	depends on DRM && DRM_PANEL
 
diff --git a/include/drm/drm_panel_helper.h b/include/drm/drm_panel_helper.h
new file mode 100644
index 0000000..c3355e3
--- /dev/null
+++ b/include/drm/drm_panel_helper.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 Noralf Trønnes
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef __DRM_PANEL_HELPER_H__
+#define __DRM_PANEL_HELPER_H__
+
+struct drm_device;
+struct drm_panel;
+
+struct drm_connector *drm_panel_connector_create(struct drm_device *dev,
+						 struct drm_panel *panel,
+						 int connector_type);
+
+#endif
-- 
2.2.2

  parent reply	other threads:[~2016-05-05 13:25 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-05 13:24 [PATCH 0/4] drm: Add various helpers for simple drivers Noralf Trønnes
2016-05-05 13:24 ` [PATCH 1/4] drm/fb-cma-helper: Add function drm_fb_cma_create_with_funcs() Noralf Trønnes
2016-05-05 16:27   ` Daniel Vetter
2016-05-06 13:01     ` Noralf Trønnes
2016-05-06 13:13       ` Daniel Vetter
2016-05-05 13:24 ` [PATCH 2/4] drm: Make drm_encoder_helper_funcs optional Noralf Trønnes
2016-05-05 16:23   ` Daniel Vetter
2016-05-09 19:19     ` Noralf Trønnes
2016-05-10  6:53       ` Daniel Vetter
2016-05-05 13:24 ` [PATCH 3/4] drm: Add helper for simple display pipeline Noralf Trønnes
2016-05-05 16:45   ` Daniel Vetter
2016-05-09 14:46   ` Daniel Vetter
2016-05-09 18:37     ` Noralf Trønnes
2016-05-10  6:59       ` Daniel Vetter
2016-05-10 22:36         ` Daniel Vetter
2016-05-05 13:24 ` Noralf Trønnes [this message]
2016-05-05 17:03   ` [PATCH 4/4] drm/panel: Add helper for simple panel connector Daniel Vetter
2016-05-06 13:39     ` Noralf Trønnes
2016-05-06 14:01       ` Thierry Reding
2016-05-06 14:07         ` Daniel Vetter
2016-05-06 14:03   ` Thierry Reding
2016-05-06 14:08     ` Daniel Vetter
2016-05-06 14:15       ` Thierry Reding
2016-05-06 14:34         ` Noralf Trønnes
2016-05-06 14:41           ` Daniel Vetter
2016-05-06 14:43           ` Thierry Reding
2016-05-06 19:45             ` Noralf Trønnes
2016-05-07  9:59               ` Daniel Vetter
2016-05-07 12:46                 ` Noralf Trønnes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462454674-2246-5-git-send-email-noralf@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=treding@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®