All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomi Valkeinen <tomi.valkeinen@ti.com>
To: linux-fbdev@vger.kernel.org, linux-omap@vger.kernel.org,
	Archit Taneja <archit@ti.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Subject: [PATCH 12/32] OMAPDSS: Implement display (dis)connect support
Date: Thu, 30 May 2013 09:34:33 +0000	[thread overview]
Message-ID: <1369906493-27538-13-git-send-email-tomi.valkeinen@ti.com> (raw)
In-Reply-To: <1369906493-27538-1-git-send-email-tomi.valkeinen@ti.com>

We currently have two steps in panel initialization and startup: probing
and enabling. After the panel has been probed, it's ready and can be
configured and later enabled.

This model is not enough with more complex display pipelines, where we
may have, for example, two panels, of which only one can be used at a
time, connected to the same video output.

To support that kind of scenarios, we need to add new step to the
initialization: connect.

This patch adds support for connecting and disconnecting panels. After
probe, but before connect, no panel ops should be called. When the
connect is called, a proper video pipeline is established, and the panel
is ready for use. If some part in the video pipeline is already
connected (by some other panel), the connect call fails.

One key difference with the old style setup is that connect() handles
also connecting to the overlay manager. This means that the omapfb (or
omapdrm) no longer needs to figure out which overlay manager to use, but
it can just call connect() on the panel, and the proper overlay manager
is connected by omapdss.

This also allows us to add back the support for dynamic switching
between two exclusive panels. However, the current panel device model is
not changed to support this, as the new device model is implemented in
the following patches and the old model will be removed. The new device
model supports dynamic switching.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
---
 drivers/gpu/drm/omapdrm/omap_crtc.c      | 24 +++++++++++++++++
 drivers/gpu/drm/omapdrm/omap_drv.c       | 12 ++++++++-
 drivers/video/omap2/dss/apply.c          | 14 ++++++++++
 drivers/video/omap2/dss/core.c           | 44 +++++++++++++++++++++++++++++++
 drivers/video/omap2/dss/display-sysfs.c  | 28 +++++++++++---------
 drivers/video/omap2/dss/manager-sysfs.c  | 45 ++++++++++++++++++++------------
 drivers/video/omap2/dss/output.c         | 14 ++++++++++
 drivers/video/omap2/omapfb/omapfb-main.c | 25 ++++++++++--------
 include/video/omapdss.h                  | 23 ++++++++++++++++
 9 files changed, 188 insertions(+), 41 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c
index 02075bf..b2ab2f5 100644
--- a/drivers/gpu/drm/omapdrm/omap_crtc.c
+++ b/drivers/gpu/drm/omapdrm/omap_crtc.c
@@ -94,6 +94,28 @@ uint32_t pipe2vbl(struct drm_crtc *crtc)
 static struct omap_crtc *omap_crtcs[8];
 
 /* we can probably ignore these until we support command-mode panels: */
+static int omap_crtc_connect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	if (mgr->output)
+		return -EINVAL;
+
+	if ((mgr->supported_outputs & dst->id) = 0)
+		return -EINVAL;
+
+	dst->manager = mgr;
+	mgr->output = dst;
+
+	return 0;
+}
+
+static void omap_crtc_disconnect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	mgr->output->manager = NULL;
+	mgr->output = NULL;
+}
+
 static void omap_crtc_start_update(struct omap_overlay_manager *mgr)
 {
 }
@@ -138,6 +160,8 @@ static void omap_crtc_unregister_framedone_handler(
 }
 
 static const struct dss_mgr_ops mgr_ops = {
+		.connect = omap_crtc_connect,
+		.disconnect = omap_crtc_disconnect,
 		.start_update = omap_crtc_start_update,
 		.enable = omap_crtc_enable,
 		.disable = omap_crtc_disable,
diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c
index f8947f9..58bd259 100644
--- a/drivers/gpu/drm/omapdrm/omap_drv.c
+++ b/drivers/gpu/drm/omapdrm/omap_drv.c
@@ -97,6 +97,7 @@ static int omap_modeset_init(struct drm_device *dev)
 	int num_mgrs = dss_feat_get_num_mgrs();
 	int num_crtcs;
 	int i, id = 0;
+	int r;
 
 	omap_crtc_pre_init();
 
@@ -118,6 +119,7 @@ static int omap_modeset_init(struct drm_device *dev)
 		struct drm_connector *connector;
 		struct drm_encoder *encoder;
 		enum omap_channel channel;
+		struct omap_overlay_manager *mgr;
 
 		if (!dssdev->driver) {
 			dev_warn(dev->dev, "%s has no driver.. skipping it\n",
@@ -133,6 +135,13 @@ static int omap_modeset_init(struct drm_device *dev)
 			continue;
 		}
 
+		r = dssdev->driver->connect(dssdev);
+		if (r) {
+			dev_err(dev->dev, "could not connect display: %s\n",
+					dssdev->name);
+			continue;
+		}
+
 		encoder = omap_encoder_init(dev, dssdev);
 
 		if (!encoder) {
@@ -174,8 +183,9 @@ static int omap_modeset_init(struct drm_device *dev)
 		 * other possible channels to which the encoder can connect are
 		 * not considered.
 		 */
-		channel = dssdev->output->dispc_channel;
 
+		mgr = omapdss_find_mgr_from_display(dssdev);
+		channel = mgr->id;
 		/*
 		 * if this channel hasn't already been taken by a previously
 		 * allocated crtc, we create a new crtc for it
diff --git a/drivers/video/omap2/dss/apply.c b/drivers/video/omap2/dss/apply.c
index c844071..dbd3c2f 100644
--- a/drivers/video/omap2/dss/apply.c
+++ b/drivers/video/omap2/dss/apply.c
@@ -790,6 +790,18 @@ static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
 	}
 }
 
+static int dss_mgr_connect_compat(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	return mgr->set_output(mgr, dst);
+}
+
+static void dss_mgr_disconnect_compat(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	mgr->unset_output(mgr);
+}
+
 static void dss_mgr_start_update_compat(struct omap_overlay_manager *mgr)
 {
 	struct mgr_priv_data *mp = get_mgr_priv(mgr);
@@ -1552,6 +1564,8 @@ static void dss_mgr_unregister_framedone_handler_compat(struct omap_overlay_mana
 }
 
 static const struct dss_mgr_ops apply_mgr_ops = {
+	.connect = dss_mgr_connect_compat,
+	.disconnect = dss_mgr_disconnect_compat,
 	.start_update = dss_mgr_start_update_compat,
 	.enable = dss_mgr_enable_compat,
 	.disable = dss_mgr_disable_compat,
diff --git a/drivers/video/omap2/dss/core.c b/drivers/video/omap2/dss/core.c
index 502ec1b..4bd8f79 100644
--- a/drivers/video/omap2/dss/core.c
+++ b/drivers/video/omap2/dss/core.c
@@ -371,6 +371,46 @@ static int dss_driver_remove(struct device *dev)
 	return 0;
 }
 
+static int omapdss_default_connect(struct omap_dss_device *dssdev)
+{
+	struct omap_dss_output *out;
+	struct omap_overlay_manager *mgr;
+	int r;
+
+	out = dssdev->output;
+
+	if (out = NULL)
+		return -ENODEV;
+
+	mgr = omap_dss_get_overlay_manager(out->dispc_channel);
+	if (!mgr)
+		return -ENODEV;
+
+	r = dss_mgr_connect(mgr, out);
+	if (r)
+		return r;
+
+	return 0;
+}
+
+static void omapdss_default_disconnect(struct omap_dss_device *dssdev)
+{
+	struct omap_dss_output *out;
+	struct omap_overlay_manager *mgr;
+
+	out = dssdev->output;
+
+	if (out = NULL)
+		return;
+
+	mgr = out->manager;
+
+	if (mgr = NULL)
+		return;
+
+	dss_mgr_disconnect(mgr, out);
+}
+
 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
 {
 	dssdriver->driver.bus = &dss_bus_type;
@@ -384,6 +424,10 @@ int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
 			omapdss_default_get_recommended_bpp;
 	if (dssdriver->get_timings = NULL)
 		dssdriver->get_timings = omapdss_default_get_timings;
+	if (dssdriver->connect = NULL)
+		dssdriver->connect = omapdss_default_connect;
+	if (dssdriver->disconnect = NULL)
+		dssdriver->disconnect = omapdss_default_disconnect;
 
 	return driver_register(&dssdriver->driver);
 }
diff --git a/drivers/video/omap2/dss/display-sysfs.c b/drivers/video/omap2/dss/display-sysfs.c
index 18211a9..81d5dc6 100644
--- a/drivers/video/omap2/dss/display-sysfs.c
+++ b/drivers/video/omap2/dss/display-sysfs.c
@@ -33,9 +33,9 @@ static ssize_t display_enabled_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct omap_dss_device *dssdev = to_dss_device(dev);
-	bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
+	return snprintf(buf, PAGE_SIZE, "%d\n",
+			omapdss_device_is_enabled(dssdev));
 }
 
 static ssize_t display_enabled_store(struct device *dev,
@@ -44,20 +44,24 @@ static ssize_t display_enabled_store(struct device *dev,
 {
 	struct omap_dss_device *dssdev = to_dss_device(dev);
 	int r;
-	bool enabled;
+	bool enable;
 
-	r = strtobool(buf, &enabled);
+	r = strtobool(buf, &enable);
 	if (r)
 		return r;
 
-	if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
-		if (enabled) {
-			r = dssdev->driver->enable(dssdev);
-			if (r)
-				return r;
-		} else {
-			dssdev->driver->disable(dssdev);
-		}
+	if (enable = omapdss_device_is_enabled(dssdev))
+		return size;
+
+	if (omapdss_device_is_connected(dssdev) = false)
+		return -ENODEV;
+
+	if (enable) {
+		r = dssdev->driver->enable(dssdev);
+		if (r)
+			return r;
+	} else {
+		dssdev->driver->disable(dssdev);
 	}
 
 	return size;
diff --git a/drivers/video/omap2/dss/manager-sysfs.c b/drivers/video/omap2/dss/manager-sysfs.c
index 72784b3..de7e7b5 100644
--- a/drivers/video/omap2/dss/manager-sysfs.c
+++ b/drivers/video/omap2/dss/manager-sysfs.c
@@ -50,6 +50,7 @@ static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
 	int r = 0;
 	size_t len = size;
 	struct omap_dss_device *dssdev = NULL;
+	struct omap_dss_device *old_dssdev;
 
 	int match(struct omap_dss_device *dssdev, void *data)
 	{
@@ -66,34 +67,44 @@ static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
 	if (len > 0 && dssdev = NULL)
 		return -EINVAL;
 
-	if (dssdev)
+	if (dssdev) {
 		DSSDBG("display %s found\n", dssdev->name);
 
-	if (mgr->output) {
-		r = mgr->unset_output(mgr);
-		if (r) {
-			DSSERR("failed to unset current output\n");
+		if (omapdss_device_is_connected(dssdev)) {
+			DSSERR("new display is already connected\n");
+			r = -EINVAL;
+			goto put_device;
+		}
+
+		if (omapdss_device_is_enabled(dssdev)) {
+			DSSERR("new display is not disabled\n");
+			r = -EINVAL;
 			goto put_device;
 		}
 	}
 
-	if (dssdev) {
-		struct omap_dss_output *out;
+	old_dssdev = mgr->get_device(mgr);
+	if (old_dssdev) {
+		if (omapdss_device_is_enabled(old_dssdev)) {
+			DSSERR("old display is not disabled\n");
+			r = -EINVAL;
+			goto put_device;
+		}
 
-		out = omapdss_find_output_from_display(dssdev);
+		old_dssdev->driver->disconnect(old_dssdev);
+	}
 
-		/*
-		 * a registered device should have an output connected to it
-		 * already
-		 */
-		if (!out) {
-			DSSERR("device has no output connected to it\n");
+	if (dssdev) {
+		r = dssdev->driver->connect(dssdev);
+		if (r) {
+			DSSERR("failed to connect new device\n");
 			goto put_device;
 		}
 
-		r = mgr->set_output(mgr, out);
-		if (r) {
-			DSSERR("failed to set manager output\n");
+		old_dssdev = mgr->get_device(mgr);
+		if (old_dssdev != dssdev) {
+			DSSERR("failed to connect device to this manager\n");
+			dssdev->driver->disconnect(dssdev);
 			goto put_device;
 		}
 
diff --git a/drivers/video/omap2/dss/output.c b/drivers/video/omap2/dss/output.c
index ab2c0f0..a53b08b 100644
--- a/drivers/video/omap2/dss/output.c
+++ b/drivers/video/omap2/dss/output.c
@@ -179,6 +179,20 @@ void dss_uninstall_mgr_ops(void)
 }
 EXPORT_SYMBOL(dss_uninstall_mgr_ops);
 
+int dss_mgr_connect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	return dss_mgr_ops->connect(mgr, dst);
+}
+EXPORT_SYMBOL(dss_mgr_connect);
+
+void dss_mgr_disconnect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	dss_mgr_ops->disconnect(mgr, dst);
+}
+EXPORT_SYMBOL(dss_mgr_disconnect);
+
 void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
 		const struct omap_video_timings *timings)
 {
diff --git a/drivers/video/omap2/omapfb/omapfb-main.c b/drivers/video/omap2/omapfb/omapfb-main.c
index dd972c5..eacbafa 100644
--- a/drivers/video/omap2/omapfb/omapfb-main.c
+++ b/drivers/video/omap2/omapfb/omapfb-main.c
@@ -1853,6 +1853,8 @@ static void omapfb_free_resources(struct omapfb2_device *fbdev)
 		if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
 			dssdev->driver->disable(dssdev);
 
+		dssdev->driver->disconnect(dssdev);
+
 		omap_dss_put_device(dssdev);
 	}
 
@@ -2363,22 +2365,23 @@ static int omapfb_init_connections(struct omapfb2_device *fbdev,
 	int i, r;
 	struct omap_overlay_manager *mgr;
 
+	r = def_dssdev->driver->connect(def_dssdev);
+	if (r) {
+		dev_err(fbdev->dev, "failed to connect default display\n");
+		return r;
+	}
+
 	for (i = 0; i < fbdev->num_displays; ++i) {
 		struct omap_dss_device *dssdev = fbdev->displays[i].dssdev;
-		struct omap_dss_output *out;
 
-		out = omapdss_find_output_from_display(dssdev);
-		if (!out)
+		if (dssdev = def_dssdev)
 			continue;
 
-		mgr = omap_dss_get_overlay_manager(out->dispc_channel);
-		if (!mgr)
-			continue;
-
-		if (mgr->output)
-			mgr->unset_output(mgr);
-
-		mgr->set_output(mgr, out);
+		/*
+		 * We don't care if the connect succeeds or not. We just want to
+		 * connect as many displays as possible.
+		 */
+		dssdev->driver->connect(dssdev);
 	}
 
 	mgr = omapdss_find_mgr_from_display(def_dssdev);
diff --git a/include/video/omapdss.h b/include/video/omapdss.h
index 68b2345..f747266 100644
--- a/include/video/omapdss.h
+++ b/include/video/omapdss.h
@@ -689,6 +689,9 @@ struct omap_dss_driver {
 	int (*probe)(struct omap_dss_device *);
 	void (*remove)(struct omap_dss_device *);
 
+	int (*connect)(struct omap_dss_device *dssdev);
+	void (*disconnect)(struct omap_dss_device *dssdev);
+
 	int (*enable)(struct omap_dss_device *display);
 	void (*disable)(struct omap_dss_device *display);
 	int (*run_test)(struct omap_dss_device *display, int test);
@@ -888,6 +891,11 @@ int omapdss_compat_init(void);
 void omapdss_compat_uninit(void);
 
 struct dss_mgr_ops {
+	int (*connect)(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst);
+	void (*disconnect)(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst);
+
 	void (*start_update)(struct omap_overlay_manager *mgr);
 	int (*enable)(struct omap_overlay_manager *mgr);
 	void (*disable)(struct omap_overlay_manager *mgr);
@@ -904,6 +912,10 @@ struct dss_mgr_ops {
 int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops);
 void dss_uninstall_mgr_ops(void);
 
+int dss_mgr_connect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst);
+void dss_mgr_disconnect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst);
 void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
 		const struct omap_video_timings *timings);
 void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
@@ -915,4 +927,15 @@ int dss_mgr_register_framedone_handler(struct omap_overlay_manager *mgr,
 		void (*handler)(void *), void *data);
 void dss_mgr_unregister_framedone_handler(struct omap_overlay_manager *mgr,
 		void (*handler)(void *), void *data);
+
+static inline bool omapdss_device_is_connected(struct omap_dss_device *dssdev)
+{
+	return dssdev->output;
+}
+
+static inline bool omapdss_device_is_enabled(struct omap_dss_device *dssdev)
+{
+	return dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
+}
+
 #endif
-- 
1.8.1.2


WARNING: multiple messages have this Message-ID (diff)
From: Tomi Valkeinen <tomi.valkeinen@ti.com>
To: linux-fbdev@vger.kernel.org, linux-omap@vger.kernel.org,
	Archit Taneja <archit@ti.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Subject: [PATCH 12/32] OMAPDSS: Implement display (dis)connect support
Date: Thu, 30 May 2013 12:34:33 +0300	[thread overview]
Message-ID: <1369906493-27538-13-git-send-email-tomi.valkeinen@ti.com> (raw)
In-Reply-To: <1369906493-27538-1-git-send-email-tomi.valkeinen@ti.com>

We currently have two steps in panel initialization and startup: probing
and enabling. After the panel has been probed, it's ready and can be
configured and later enabled.

This model is not enough with more complex display pipelines, where we
may have, for example, two panels, of which only one can be used at a
time, connected to the same video output.

To support that kind of scenarios, we need to add new step to the
initialization: connect.

This patch adds support for connecting and disconnecting panels. After
probe, but before connect, no panel ops should be called. When the
connect is called, a proper video pipeline is established, and the panel
is ready for use. If some part in the video pipeline is already
connected (by some other panel), the connect call fails.

One key difference with the old style setup is that connect() handles
also connecting to the overlay manager. This means that the omapfb (or
omapdrm) no longer needs to figure out which overlay manager to use, but
it can just call connect() on the panel, and the proper overlay manager
is connected by omapdss.

This also allows us to add back the support for dynamic switching
between two exclusive panels. However, the current panel device model is
not changed to support this, as the new device model is implemented in
the following patches and the old model will be removed. The new device
model supports dynamic switching.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
---
 drivers/gpu/drm/omapdrm/omap_crtc.c      | 24 +++++++++++++++++
 drivers/gpu/drm/omapdrm/omap_drv.c       | 12 ++++++++-
 drivers/video/omap2/dss/apply.c          | 14 ++++++++++
 drivers/video/omap2/dss/core.c           | 44 +++++++++++++++++++++++++++++++
 drivers/video/omap2/dss/display-sysfs.c  | 28 +++++++++++---------
 drivers/video/omap2/dss/manager-sysfs.c  | 45 ++++++++++++++++++++------------
 drivers/video/omap2/dss/output.c         | 14 ++++++++++
 drivers/video/omap2/omapfb/omapfb-main.c | 25 ++++++++++--------
 include/video/omapdss.h                  | 23 ++++++++++++++++
 9 files changed, 188 insertions(+), 41 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c
index 02075bf..b2ab2f5 100644
--- a/drivers/gpu/drm/omapdrm/omap_crtc.c
+++ b/drivers/gpu/drm/omapdrm/omap_crtc.c
@@ -94,6 +94,28 @@ uint32_t pipe2vbl(struct drm_crtc *crtc)
 static struct omap_crtc *omap_crtcs[8];
 
 /* we can probably ignore these until we support command-mode panels: */
+static int omap_crtc_connect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	if (mgr->output)
+		return -EINVAL;
+
+	if ((mgr->supported_outputs & dst->id) == 0)
+		return -EINVAL;
+
+	dst->manager = mgr;
+	mgr->output = dst;
+
+	return 0;
+}
+
+static void omap_crtc_disconnect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	mgr->output->manager = NULL;
+	mgr->output = NULL;
+}
+
 static void omap_crtc_start_update(struct omap_overlay_manager *mgr)
 {
 }
@@ -138,6 +160,8 @@ static void omap_crtc_unregister_framedone_handler(
 }
 
 static const struct dss_mgr_ops mgr_ops = {
+		.connect = omap_crtc_connect,
+		.disconnect = omap_crtc_disconnect,
 		.start_update = omap_crtc_start_update,
 		.enable = omap_crtc_enable,
 		.disable = omap_crtc_disable,
diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c
index f8947f9..58bd259 100644
--- a/drivers/gpu/drm/omapdrm/omap_drv.c
+++ b/drivers/gpu/drm/omapdrm/omap_drv.c
@@ -97,6 +97,7 @@ static int omap_modeset_init(struct drm_device *dev)
 	int num_mgrs = dss_feat_get_num_mgrs();
 	int num_crtcs;
 	int i, id = 0;
+	int r;
 
 	omap_crtc_pre_init();
 
@@ -118,6 +119,7 @@ static int omap_modeset_init(struct drm_device *dev)
 		struct drm_connector *connector;
 		struct drm_encoder *encoder;
 		enum omap_channel channel;
+		struct omap_overlay_manager *mgr;
 
 		if (!dssdev->driver) {
 			dev_warn(dev->dev, "%s has no driver.. skipping it\n",
@@ -133,6 +135,13 @@ static int omap_modeset_init(struct drm_device *dev)
 			continue;
 		}
 
+		r = dssdev->driver->connect(dssdev);
+		if (r) {
+			dev_err(dev->dev, "could not connect display: %s\n",
+					dssdev->name);
+			continue;
+		}
+
 		encoder = omap_encoder_init(dev, dssdev);
 
 		if (!encoder) {
@@ -174,8 +183,9 @@ static int omap_modeset_init(struct drm_device *dev)
 		 * other possible channels to which the encoder can connect are
 		 * not considered.
 		 */
-		channel = dssdev->output->dispc_channel;
 
+		mgr = omapdss_find_mgr_from_display(dssdev);
+		channel = mgr->id;
 		/*
 		 * if this channel hasn't already been taken by a previously
 		 * allocated crtc, we create a new crtc for it
diff --git a/drivers/video/omap2/dss/apply.c b/drivers/video/omap2/dss/apply.c
index c844071..dbd3c2f 100644
--- a/drivers/video/omap2/dss/apply.c
+++ b/drivers/video/omap2/dss/apply.c
@@ -790,6 +790,18 @@ static void mgr_clear_shadow_dirty(struct omap_overlay_manager *mgr)
 	}
 }
 
+static int dss_mgr_connect_compat(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	return mgr->set_output(mgr, dst);
+}
+
+static void dss_mgr_disconnect_compat(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	mgr->unset_output(mgr);
+}
+
 static void dss_mgr_start_update_compat(struct omap_overlay_manager *mgr)
 {
 	struct mgr_priv_data *mp = get_mgr_priv(mgr);
@@ -1552,6 +1564,8 @@ static void dss_mgr_unregister_framedone_handler_compat(struct omap_overlay_mana
 }
 
 static const struct dss_mgr_ops apply_mgr_ops = {
+	.connect = dss_mgr_connect_compat,
+	.disconnect = dss_mgr_disconnect_compat,
 	.start_update = dss_mgr_start_update_compat,
 	.enable = dss_mgr_enable_compat,
 	.disable = dss_mgr_disable_compat,
diff --git a/drivers/video/omap2/dss/core.c b/drivers/video/omap2/dss/core.c
index 502ec1b..4bd8f79 100644
--- a/drivers/video/omap2/dss/core.c
+++ b/drivers/video/omap2/dss/core.c
@@ -371,6 +371,46 @@ static int dss_driver_remove(struct device *dev)
 	return 0;
 }
 
+static int omapdss_default_connect(struct omap_dss_device *dssdev)
+{
+	struct omap_dss_output *out;
+	struct omap_overlay_manager *mgr;
+	int r;
+
+	out = dssdev->output;
+
+	if (out == NULL)
+		return -ENODEV;
+
+	mgr = omap_dss_get_overlay_manager(out->dispc_channel);
+	if (!mgr)
+		return -ENODEV;
+
+	r = dss_mgr_connect(mgr, out);
+	if (r)
+		return r;
+
+	return 0;
+}
+
+static void omapdss_default_disconnect(struct omap_dss_device *dssdev)
+{
+	struct omap_dss_output *out;
+	struct omap_overlay_manager *mgr;
+
+	out = dssdev->output;
+
+	if (out == NULL)
+		return;
+
+	mgr = out->manager;
+
+	if (mgr == NULL)
+		return;
+
+	dss_mgr_disconnect(mgr, out);
+}
+
 int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
 {
 	dssdriver->driver.bus = &dss_bus_type;
@@ -384,6 +424,10 @@ int omap_dss_register_driver(struct omap_dss_driver *dssdriver)
 			omapdss_default_get_recommended_bpp;
 	if (dssdriver->get_timings == NULL)
 		dssdriver->get_timings = omapdss_default_get_timings;
+	if (dssdriver->connect == NULL)
+		dssdriver->connect = omapdss_default_connect;
+	if (dssdriver->disconnect == NULL)
+		dssdriver->disconnect = omapdss_default_disconnect;
 
 	return driver_register(&dssdriver->driver);
 }
diff --git a/drivers/video/omap2/dss/display-sysfs.c b/drivers/video/omap2/dss/display-sysfs.c
index 18211a9..81d5dc6 100644
--- a/drivers/video/omap2/dss/display-sysfs.c
+++ b/drivers/video/omap2/dss/display-sysfs.c
@@ -33,9 +33,9 @@ static ssize_t display_enabled_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
 	struct omap_dss_device *dssdev = to_dss_device(dev);
-	bool enabled = dssdev->state != OMAP_DSS_DISPLAY_DISABLED;
 
-	return snprintf(buf, PAGE_SIZE, "%d\n", enabled);
+	return snprintf(buf, PAGE_SIZE, "%d\n",
+			omapdss_device_is_enabled(dssdev));
 }
 
 static ssize_t display_enabled_store(struct device *dev,
@@ -44,20 +44,24 @@ static ssize_t display_enabled_store(struct device *dev,
 {
 	struct omap_dss_device *dssdev = to_dss_device(dev);
 	int r;
-	bool enabled;
+	bool enable;
 
-	r = strtobool(buf, &enabled);
+	r = strtobool(buf, &enable);
 	if (r)
 		return r;
 
-	if (enabled != (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)) {
-		if (enabled) {
-			r = dssdev->driver->enable(dssdev);
-			if (r)
-				return r;
-		} else {
-			dssdev->driver->disable(dssdev);
-		}
+	if (enable == omapdss_device_is_enabled(dssdev))
+		return size;
+
+	if (omapdss_device_is_connected(dssdev) == false)
+		return -ENODEV;
+
+	if (enable) {
+		r = dssdev->driver->enable(dssdev);
+		if (r)
+			return r;
+	} else {
+		dssdev->driver->disable(dssdev);
 	}
 
 	return size;
diff --git a/drivers/video/omap2/dss/manager-sysfs.c b/drivers/video/omap2/dss/manager-sysfs.c
index 72784b3..de7e7b5 100644
--- a/drivers/video/omap2/dss/manager-sysfs.c
+++ b/drivers/video/omap2/dss/manager-sysfs.c
@@ -50,6 +50,7 @@ static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
 	int r = 0;
 	size_t len = size;
 	struct omap_dss_device *dssdev = NULL;
+	struct omap_dss_device *old_dssdev;
 
 	int match(struct omap_dss_device *dssdev, void *data)
 	{
@@ -66,34 +67,44 @@ static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
 	if (len > 0 && dssdev == NULL)
 		return -EINVAL;
 
-	if (dssdev)
+	if (dssdev) {
 		DSSDBG("display %s found\n", dssdev->name);
 
-	if (mgr->output) {
-		r = mgr->unset_output(mgr);
-		if (r) {
-			DSSERR("failed to unset current output\n");
+		if (omapdss_device_is_connected(dssdev)) {
+			DSSERR("new display is already connected\n");
+			r = -EINVAL;
+			goto put_device;
+		}
+
+		if (omapdss_device_is_enabled(dssdev)) {
+			DSSERR("new display is not disabled\n");
+			r = -EINVAL;
 			goto put_device;
 		}
 	}
 
-	if (dssdev) {
-		struct omap_dss_output *out;
+	old_dssdev = mgr->get_device(mgr);
+	if (old_dssdev) {
+		if (omapdss_device_is_enabled(old_dssdev)) {
+			DSSERR("old display is not disabled\n");
+			r = -EINVAL;
+			goto put_device;
+		}
 
-		out = omapdss_find_output_from_display(dssdev);
+		old_dssdev->driver->disconnect(old_dssdev);
+	}
 
-		/*
-		 * a registered device should have an output connected to it
-		 * already
-		 */
-		if (!out) {
-			DSSERR("device has no output connected to it\n");
+	if (dssdev) {
+		r = dssdev->driver->connect(dssdev);
+		if (r) {
+			DSSERR("failed to connect new device\n");
 			goto put_device;
 		}
 
-		r = mgr->set_output(mgr, out);
-		if (r) {
-			DSSERR("failed to set manager output\n");
+		old_dssdev = mgr->get_device(mgr);
+		if (old_dssdev != dssdev) {
+			DSSERR("failed to connect device to this manager\n");
+			dssdev->driver->disconnect(dssdev);
 			goto put_device;
 		}
 
diff --git a/drivers/video/omap2/dss/output.c b/drivers/video/omap2/dss/output.c
index ab2c0f0..a53b08b 100644
--- a/drivers/video/omap2/dss/output.c
+++ b/drivers/video/omap2/dss/output.c
@@ -179,6 +179,20 @@ void dss_uninstall_mgr_ops(void)
 }
 EXPORT_SYMBOL(dss_uninstall_mgr_ops);
 
+int dss_mgr_connect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	return dss_mgr_ops->connect(mgr, dst);
+}
+EXPORT_SYMBOL(dss_mgr_connect);
+
+void dss_mgr_disconnect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst)
+{
+	dss_mgr_ops->disconnect(mgr, dst);
+}
+EXPORT_SYMBOL(dss_mgr_disconnect);
+
 void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
 		const struct omap_video_timings *timings)
 {
diff --git a/drivers/video/omap2/omapfb/omapfb-main.c b/drivers/video/omap2/omapfb/omapfb-main.c
index dd972c5..eacbafa 100644
--- a/drivers/video/omap2/omapfb/omapfb-main.c
+++ b/drivers/video/omap2/omapfb/omapfb-main.c
@@ -1853,6 +1853,8 @@ static void omapfb_free_resources(struct omapfb2_device *fbdev)
 		if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
 			dssdev->driver->disable(dssdev);
 
+		dssdev->driver->disconnect(dssdev);
+
 		omap_dss_put_device(dssdev);
 	}
 
@@ -2363,22 +2365,23 @@ static int omapfb_init_connections(struct omapfb2_device *fbdev,
 	int i, r;
 	struct omap_overlay_manager *mgr;
 
+	r = def_dssdev->driver->connect(def_dssdev);
+	if (r) {
+		dev_err(fbdev->dev, "failed to connect default display\n");
+		return r;
+	}
+
 	for (i = 0; i < fbdev->num_displays; ++i) {
 		struct omap_dss_device *dssdev = fbdev->displays[i].dssdev;
-		struct omap_dss_output *out;
 
-		out = omapdss_find_output_from_display(dssdev);
-		if (!out)
+		if (dssdev == def_dssdev)
 			continue;
 
-		mgr = omap_dss_get_overlay_manager(out->dispc_channel);
-		if (!mgr)
-			continue;
-
-		if (mgr->output)
-			mgr->unset_output(mgr);
-
-		mgr->set_output(mgr, out);
+		/*
+		 * We don't care if the connect succeeds or not. We just want to
+		 * connect as many displays as possible.
+		 */
+		dssdev->driver->connect(dssdev);
 	}
 
 	mgr = omapdss_find_mgr_from_display(def_dssdev);
diff --git a/include/video/omapdss.h b/include/video/omapdss.h
index 68b2345..f747266 100644
--- a/include/video/omapdss.h
+++ b/include/video/omapdss.h
@@ -689,6 +689,9 @@ struct omap_dss_driver {
 	int (*probe)(struct omap_dss_device *);
 	void (*remove)(struct omap_dss_device *);
 
+	int (*connect)(struct omap_dss_device *dssdev);
+	void (*disconnect)(struct omap_dss_device *dssdev);
+
 	int (*enable)(struct omap_dss_device *display);
 	void (*disable)(struct omap_dss_device *display);
 	int (*run_test)(struct omap_dss_device *display, int test);
@@ -888,6 +891,11 @@ int omapdss_compat_init(void);
 void omapdss_compat_uninit(void);
 
 struct dss_mgr_ops {
+	int (*connect)(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst);
+	void (*disconnect)(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst);
+
 	void (*start_update)(struct omap_overlay_manager *mgr);
 	int (*enable)(struct omap_overlay_manager *mgr);
 	void (*disable)(struct omap_overlay_manager *mgr);
@@ -904,6 +912,10 @@ struct dss_mgr_ops {
 int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops);
 void dss_uninstall_mgr_ops(void);
 
+int dss_mgr_connect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst);
+void dss_mgr_disconnect(struct omap_overlay_manager *mgr,
+		struct omap_dss_output *dst);
 void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
 		const struct omap_video_timings *timings);
 void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
@@ -915,4 +927,15 @@ int dss_mgr_register_framedone_handler(struct omap_overlay_manager *mgr,
 		void (*handler)(void *), void *data);
 void dss_mgr_unregister_framedone_handler(struct omap_overlay_manager *mgr,
 		void (*handler)(void *), void *data);
+
+static inline bool omapdss_device_is_connected(struct omap_dss_device *dssdev)
+{
+	return dssdev->output;
+}
+
+static inline bool omapdss_device_is_enabled(struct omap_dss_device *dssdev)
+{
+	return dssdev->state == OMAP_DSS_DISPLAY_ACTIVE;
+}
+
 #endif
-- 
1.8.1.2


  parent reply	other threads:[~2013-05-30  9:34 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-30  9:34 [PATCH 00/32] OMAPDSS: dss-dev-model "base" (Part 1/2) Tomi Valkeinen
2013-05-30  9:34 ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 01/32] OMAPDSS: add pdata->default_display_name Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 02/32] OMAPDSS: only probe pdata if there's one Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 03/32] OMAPDSS: add omap_dss_find_output() Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30 11:07   ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 11:07     ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 11:40     ` Tomi Valkeinen
2013-05-30 11:40       ` Tomi Valkeinen
2013-05-30 15:40       ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 15:40         ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 16:54         ` Tomi Valkeinen
2013-05-30 16:54           ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 04/32] OMAPDSS: add omap_dss_find_output_by_node() Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 05/32] OMAPDSS: fix dss_get_ctx_loss_count for DT Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30 11:09   ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 11:09     ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 11:28     ` Tomi Valkeinen
2013-05-30 11:28       ` Tomi Valkeinen
2013-05-30 15:43       ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 15:43         ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 16:14         ` Tomi Valkeinen
2013-05-30 16:14           ` Tomi Valkeinen
2013-05-30 16:36   ` Kevin Hilman
2013-05-30 16:36     ` Kevin Hilman
2013-05-30 17:21     ` Tomi Valkeinen
2013-05-30 17:21       ` Tomi Valkeinen
2013-05-31 15:17     ` Grygorii Strashko
2013-05-31 15:17       ` Grygorii Strashko
2013-05-31 19:31       ` Kevin Hilman
2013-05-31 19:31         ` Kevin Hilman
2013-05-30  9:34 ` [PATCH 06/32] OMAPDSS: DPI: fix regulators " Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30 11:12   ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 11:12     ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 11:35     ` Tomi Valkeinen
2013-05-30 11:35       ` Tomi Valkeinen
2013-05-30 13:05       ` Arnd Bergmann
2013-05-30 13:05         ` Arnd Bergmann
2013-05-30 15:54         ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-30 15:54           ` Jean-Christophe PLAGNIOL-VILLARD
2013-06-07  5:56   ` Archit Taneja
2013-06-07  5:57     ` Archit Taneja
2013-05-30  9:34 ` [PATCH 07/32] OMAPDSS: SDI: " Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 08/32] OMAPDSS: clean up dss_[ovl|mgr]_get_device() Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 09/32] OMAPDSS: add helpers to get mgr or output from display Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 10/32] OMAPDSS: split overlay manager creation Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-06-07  6:19   ` Archit Taneja
2013-06-07  6:31     ` Archit Taneja
2013-06-07  9:53     ` Tomi Valkeinen
2013-06-07  9:53       ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 11/32] OMAPDRM: fix overlay manager handling Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-06-07  6:21   ` Archit Taneja
2013-06-07  6:33     ` Archit Taneja
2013-05-30  9:34 ` Tomi Valkeinen [this message]
2013-05-30  9:34   ` [PATCH 12/32] OMAPDSS: Implement display (dis)connect support Tomi Valkeinen
2013-06-07  6:46   ` Archit Taneja
2013-06-07  6:58     ` Archit Taneja
2013-06-07  8:31     ` Tomi Valkeinen
2013-06-07  8:31       ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 13/32] OMAPDSS: CORE: use devm_regulator_get Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 14/32] OMAPDSS: DSI: cleanup regulator init Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-06-07  6:49   ` Archit Taneja
2013-06-07  6:50     ` Archit Taneja
2013-05-30  9:34 ` [PATCH 15/32] OMAPDSS: DPI: cleanup pll & " Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-06-07  6:51   ` Archit Taneja
2013-06-07  6:52     ` Archit Taneja
2013-06-07  8:45     ` Tomi Valkeinen
2013-06-07  8:45       ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 16/32] OMAPDSS: HDMI: add hdmi_init_regulator Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 17/32] OMAPDSS: SDI: clean up regulator init Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 18/32] OMAPDSS: VENC: " Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 19/32] OMAPDSS: add videomode conversion support Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-06-07  7:06   ` Archit Taneja
2013-06-07  7:18     ` Archit Taneja
2013-06-07  8:35     ` Tomi Valkeinen
2013-06-07  8:35       ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 20/32] OMAPDSS: remove dssdev uses in trivial cases Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 21/32] OMAPDSS: add panel list Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 22/32] OMAPDSS: use the panel list in omap_dss_get_next_device Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 23/32] OMAPDSS: don't use dss bus in suspend/resume Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 24/32] OMAPDSS: implement display sysfs without dss bus Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 25/32] OMAPDSS: Add panel dev pointer to dssdev Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 26/32] OMAPDSS: remove omap_dss_start/stop_device() Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 27/32] OMAPDSS: combine omap_dss_output into omap_dss_device Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 28/32] OMAPDSS: omapdss.h: add owner field to omap_dss_device Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 29/32] OMAPDSS: add module_get/put to omap_dss_get/put_device() Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 30/32] OMAPDSS: add THIS_MODULE owner to DSS outputs Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 31/32] OMAPDSS: output: increase refcount in find_output funcs Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen
2013-05-30  9:34 ` [PATCH 32/32] OMAPFB: use EPROBE_DEFER if default display is not present Tomi Valkeinen
2013-05-30  9:34   ` Tomi Valkeinen

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=1369906493-27538-13-git-send-email-tomi.valkeinen@ti.com \
    --to=tomi.valkeinen@ti.com \
    --cc=archit@ti.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-omap@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.