devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
To: airlied-cv59FeDIM0c@public.gmane.org,
	mark.yao-TNX95d0MmH7DzftRWevZcw@public.gmane.org,
	laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org
Cc: robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
Subject: [PATCH RFC v2 05/12] drm/components: add generic vga connector driver
Date: Wed,  1 Apr 2015 12:09:39 +0200	[thread overview]
Message-ID: <1427882986-19110-6-git-send-email-heiko@sntech.de> (raw)
In-Reply-To: <1427882986-19110-1-git-send-email-heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>

This adds a driver for generic vga connectors using a system i2c-bus for ddc.

An exception is included for rcar-du which implements the vga-connector
binding interally already and is not yet converted to the component framework.

Signed-off-by: Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
---
 drivers/gpu/drm/components/Kconfig         |   6 +
 drivers/gpu/drm/components/Makefile        |   1 +
 drivers/gpu/drm/components/vga-connector.c | 254 +++++++++++++++++++++++++++++
 3 files changed, 261 insertions(+)
 create mode 100644 drivers/gpu/drm/components/vga-connector.c

diff --git a/drivers/gpu/drm/components/Kconfig b/drivers/gpu/drm/components/Kconfig
index 647cea6..8424143 100644
--- a/drivers/gpu/drm/components/Kconfig
+++ b/drivers/gpu/drm/components/Kconfig
@@ -6,4 +6,10 @@ config DRM_COMPONENTS_VGA_ENCODER
 	help
 	  Support for generic vga encoder chips without any special controls.
 
+config DRM_COMPONENTS_VGA_CONNECTOR:
+	tristate "Generic vga connector"
+	help
+	  Support for simple vga connectors using a system i2c bus
+	  for ddc.
+
 endmenu
diff --git a/drivers/gpu/drm/components/Makefile b/drivers/gpu/drm/components/Makefile
index 719b1c9..2ff64da 100644
--- a/drivers/gpu/drm/components/Makefile
+++ b/drivers/gpu/drm/components/Makefile
@@ -1,3 +1,4 @@
 ccflags-y := -Iinclude/drm
 
 obj-$(CONFIG_DRM_COMPONENTS_VGA_ENCODER) += vga-encoder.o
+obj-$(CONFIG_DRM_COMPONENTS_VGA_CONNECTOR) += vga-connector.o
diff --git a/drivers/gpu/drm/components/vga-connector.c b/drivers/gpu/drm/components/vga-connector.c
new file mode 100644
index 0000000..400ceb7
--- /dev/null
+++ b/drivers/gpu/drm/components/vga-connector.c
@@ -0,0 +1,254 @@
+/*
+ * Simple vga encoder driver
+ *
+ * Copyright (C) 2014 Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/component.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/regulator/consumer.h>
+#include <linux/of_graph.h>
+#include <drm/drm_of.h>
+#include <drm/drmP.h>
+#include <drm/drm_crtc.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_edid.h>
+
+#define connector_to_vga_connector(x) container_of(x, struct vga_connector, connector)
+
+struct vga_connector {
+	struct drm_connector connector;
+	struct device *dev;
+	struct i2c_adapter *ddc;
+	struct drm_encoder *encoder;
+};
+
+enum drm_connector_status vga_connector_detect(struct drm_connector *connector,
+					    bool force)
+{
+	struct vga_connector *vga = connector_to_vga_connector(connector);
+
+	if (!vga->ddc)
+		return connector_status_unknown;
+
+	if (drm_probe_ddc(vga->ddc))
+		return connector_status_connected;
+
+	return connector_status_disconnected;
+}
+
+void vga_connector_connector_destroy(struct drm_connector *connector)
+{
+	drm_connector_unregister(connector);
+	drm_connector_cleanup(connector);
+}
+
+struct drm_connector_funcs vga_connector_connector_funcs = {
+	.dpms = drm_helper_connector_dpms,
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.detect = vga_connector_detect,
+	.destroy = vga_connector_connector_destroy,
+};
+
+/*
+ * Connector helper functions
+ */
+
+static int vga_connector_connector_get_modes(struct drm_connector *connector)
+{
+	struct vga_connector *vga = connector_to_vga_connector(connector);
+	struct edid *edid;
+	int ret = 0;
+
+	if (!vga->ddc)
+		return 0;
+
+	edid = drm_get_edid(connector, vga->ddc);
+	if (edid) {
+		drm_mode_connector_update_edid_property(connector, edid);
+		ret = drm_add_edid_modes(connector, edid);
+		kfree(edid);
+	}
+
+	return ret;
+}
+
+static int vga_connector_connector_mode_valid(struct drm_connector *connector,
+					struct drm_display_mode *mode)
+{
+	return MODE_OK;
+}
+
+static struct drm_encoder
+*vga_connector_connector_best_encoder(struct drm_connector *connector)
+{
+	struct vga_connector *vga = connector_to_vga_connector(connector);
+
+	return vga->encoder;
+}
+
+static struct drm_connector_helper_funcs vga_connector_connector_helper_funcs = {
+	.get_modes = vga_connector_connector_get_modes,
+	.best_encoder = vga_connector_connector_best_encoder,
+	.mode_valid = vga_connector_connector_mode_valid,
+};
+
+
+static int vga_connector_bind(struct device *dev, struct device *master,
+				 void *data)
+{
+	struct vga_connector *vga = dev_get_drvdata(dev);
+	struct drm_device *drm = data;
+	struct device_node *endpoint, *encp = NULL;
+
+	vga->connector.polled = DRM_CONNECTOR_POLL_CONNECT |
+				DRM_CONNECTOR_POLL_DISCONNECT;
+
+	drm_connector_helper_add(&vga->connector,
+				 &vga_connector_connector_helper_funcs);
+	drm_connector_init(drm, &vga->connector, &vga_connector_connector_funcs,
+			   DRM_MODE_CONNECTOR_VGA);
+
+	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
+	if (endpoint)
+		encp = of_graph_get_remote_port_parent(endpoint);
+	of_node_put(endpoint);
+
+	if (!encp)
+		return -ENODEV;
+
+	vga->encoder = of_drm_find_encoder(encp);
+	of_node_put(encp);
+
+	if (!vga->encoder)
+		return -EPROBE_DEFER;
+
+	drm_mode_connector_attach_encoder(&vga->connector, vga->encoder);
+
+	return 0;
+}
+
+static void vga_connector_unbind(struct device *dev, struct device *master,
+				    void *data)
+{
+	struct vga_connector *vga = dev_get_drvdata(dev);
+
+	vga->connector.funcs->destroy(&vga->connector);
+}
+
+static const struct component_ops vga_connector_ops = {
+	.bind = vga_connector_bind,
+	.unbind = vga_connector_unbind,
+};
+
+static int vga_connector_probe(struct platform_device *pdev)
+{
+	struct device_node *ddc_node, *np = pdev->dev.of_node;
+	struct device *dev = &pdev->dev;
+	struct vga_connector *vga;
+	int ret;
+
+	if (!np)
+		return -ENODEV;
+
+	vga = devm_kzalloc(dev, sizeof(*vga), GFP_KERNEL);
+	if (!vga)
+		return -ENOMEM;
+
+	vga->dev = dev;
+	vga->connector.of_node = np;
+
+	dev_set_drvdata(dev, vga);
+
+	ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0);
+	if (ddc_node) {
+		vga->ddc = of_find_i2c_adapter_by_node(ddc_node);
+		of_node_put(ddc_node);
+		if (!vga->ddc) {
+			dev_dbg(vga->dev, "failed to read ddc node\n");
+			return -EPROBE_DEFER;
+		}
+	} else {
+		dev_dbg(vga->dev, "no ddc property found\n");
+	}
+
+	ret = drm_connector_add(&vga->connector);
+	if (ret < 0)
+		return ret;
+
+	return component_add(dev, &vga_connector_ops);
+}
+
+static int vga_connector_remove(struct platform_device *pdev)
+{
+	struct vga_connector *vga = dev_get_drvdata(&pdev->dev);
+
+	component_del(&pdev->dev, &vga_connector_ops);
+	drm_connector_remove(&vga->connector);
+
+	return 0;
+}
+
+static const struct of_device_id vga_connector_ids[] = {
+	{ .compatible = "vga-connector", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, vga_connector_ids);
+
+static struct platform_driver vga_connector_driver = {
+	.probe  = vga_connector_probe,
+	.remove = vga_connector_remove,
+	.driver = {
+		.name = "vga-connector",
+		.of_match_table = vga_connector_ids,
+	},
+};
+
+static const struct of_device_id rcar_du_of_table[] = {
+	{ .compatible = "renesas,du-r8a7779" },
+	{ .compatible = "renesas,du-r8a7790" },
+	{ .compatible = "renesas,du-r8a7791" },
+	{ }
+};
+
+static int __init vga_connector_init(void)
+{
+	struct device_node *np;
+
+	/*
+	 * Play nice with rcar-du that is having its own implementation
+	 * of the vga-connector binding implementation and is not yet
+	 * converted to using components.
+	 */
+	np = of_find_matching_node(NULL, rcar_du_of_table);
+	if (np) {
+		of_node_put(np);
+		return 0;
+	}
+
+	return platform_driver_register(&vga_connector_driver);
+}
+
+static void __exit vga_connector_exit(void)
+{
+	platform_driver_unregister(&vga_connector_driver);
+}
+
+module_init(vga_connector_init);
+module_exit(vga_connector_exit);
+
+MODULE_AUTHOR("Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>");
+MODULE_DESCRIPTION("Simple vga converter");
+MODULE_LICENSE("GPL");
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-04-01 10:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-01 10:09 [PATCH RFC v2 00/12] drm/rockchip: add support for lvds controller and external encoders Heiko Stuebner
2015-04-01 10:09 ` [PATCH RFC v2 01/12] drm/encoder: add functionality to register encoders to a global list Heiko Stuebner
     [not found] ` <1427882986-19110-1-git-send-email-heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
2015-04-01 10:09   ` [PATCH RFC v2 02/12] drm/connector: add functionality to register connectors " Heiko Stuebner
2015-04-01 10:09   ` [PATCH RFC v2 03/12] drm: add components subdirectory and infrastructure Heiko Stuebner
2015-04-01 10:09   ` Heiko Stuebner [this message]
2015-04-01 10:09   ` [PATCH RFC v2 07/12] drm/rockchip: Add support for Rockchip Soc LVDS Heiko Stuebner
2015-04-01 10:09   ` [PATCH RFC v2 08/12] drm/rockchip: lvds: register a bridge when no panel is set Heiko Stuebner
2015-04-01 10:09 ` [PATCH RFC v2 04/12] drm/components: add generic vga encoder driver Heiko Stuebner
     [not found]   ` <1427882986-19110-5-git-send-email-heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
2015-04-01 10:27     ` Russell King - ARM Linux
2015-04-01 10:40       ` Heiko Stübner
2015-04-01 10:09 ` [PATCH RFC v2 06/12] dt-bindings: Add documentation for rockchip lvds Heiko Stuebner
2015-04-01 10:09 ` [PATCH RFC v2 09/12] drm/rockchip: enable rgb output of vops for all other connectors Heiko Stuebner
2015-04-01 10:09 ` [PATCH RFC v2 10/12] ARM: dts: rockchip: add rk3288 lcdc0 pinmux settings Heiko Stuebner
2015-04-01 10:09 ` [PATCH RFC v2 11/12] ARM: dts: rockchip: add rk3288 lvds node Heiko Stuebner
2015-04-01 10:09 ` [PATCH RFC v2 12/12] ARM: dts: rockchip: add vga encoder and enable lvds on rk3288-firefly Heiko Stuebner

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=1427882986-19110-6-git-send-email-heiko@sntech.de \
    --to=heiko-4mtyjxux2i+zqb+pc5nmwq@public.gmane.org \
    --cc=airlied-cv59FeDIM0c@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=mark.yao-TNX95d0MmH7DzftRWevZcw@public.gmane.org \
    --cc=robdclark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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;
as well as URLs for NNTP newsgroup(s).