linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Archit Taneja <archit@ti.com>
To: tomi.valkeinen@ti.com
Cc: linux-fbdev@vger.kernel.org, linux-omap@vger.kernel.org,
	Archit Taneja <archit@ti.com>
Subject: [RFC 11/11] Example: OMAPFB: clear framebuffers using writeback
Date: Wed, 07 Nov 2012 14:56:29 +0000	[thread overview]
Message-ID: <1352299469-17609-12-git-send-email-archit@ti.com> (raw)
In-Reply-To: <1352299469-17609-1-git-send-email-archit@ti.com>

This is an example to demonstrate how writeback is used to clear framebuffers.

The function omapfb_clear_fb_writeback is added as an alternative to the MPU
intensive function cfb_fillrect.

The writeback is attached to a free manager which has no overlays connected to
it, the manager's default color is set to black, and the size of both writeback
and manager are set to the framebuffer size. writeback_info is configured to
write the manager's output to the framebuffer address, and a mem to me update is
done.

This currently isn't full proof as it the logic of getting a free manager isn't
optimal yet and has a few corner cases.

Signed-off-by: Archit Taneja <archit@ti.com>
---
 drivers/video/omap2/omapfb/omapfb-main.c |  132 +++++++++++++++++++++++++++++-
 1 file changed, 131 insertions(+), 1 deletion(-)

diff --git a/drivers/video/omap2/omapfb/omapfb-main.c b/drivers/video/omap2/omapfb/omapfb-main.c
index be9096c..680f1eb 100644
--- a/drivers/video/omap2/omapfb/omapfb-main.c
+++ b/drivers/video/omap2/omapfb/omapfb-main.c
@@ -1590,8 +1590,131 @@ static int omapfb_allocate_all_fbs(struct omapfb2_device *fbdev)
 	return 0;
 }
 
+static struct omap_overlay_manager *get_free_manager(struct fb_info *fbi)
+{
+	struct omapfb_info *ofbi = FB2OFB(fbi);
+	struct omapfb2_device *fbdev = ofbi->fbdev;
+	struct omap_overlay *ovl;
+	struct omap_overlay_manager *mgr, *def_mgr;
+	int i;
+
+	ovl = omap_dss_get_overlay(0);
+	def_mgr = ovl->manager;
+
+	for (i = 0; i < fbdev->num_managers; i++) {
+		mgr = fbdev->managers[i];
+		if (mgr != def_mgr)
+			return mgr;
+	}
+
+	return NULL;
+}
+
+static void wb_callback(int err, void *data)
+{
+	struct omap_dss_output *wb = (struct omap_dss_output *) data;
+
+	omapdss_writeback_bus_unlock(wb);
+}
+
+static int omapfb_clear_fb_writeback(struct fb_info *fbi)
+{
+	struct fb_var_screeninfo *var = &fbi->var;
+	struct fb_fix_screeninfo *fix = &fbi->fix;
+	struct omapfb_info *ofbi = FB2OFB(fbi);
+	struct omap_overlay_manager *mgr = NULL;
+	struct omap_overlay_manager_info mgr_info;
+	struct omap_dss_output *wb, *orig_out = NULL;
+	struct omap_dss_writeback_info wb_info;
+	enum omap_color_mode mode;
+	u32 data_start_p = 0;
+	int r;
+
+	wb = omap_dss_get_writeback();
+	if (!wb)
+		return -ENODEV;
+
+	/* find the first unused overlay manager */
+	mgr = get_free_manager(fbi);
+	if (!mgr)
+		return -ENODEV;
+
+	/* free the manager output */
+	if (mgr->output) {
+		orig_out = mgr->output;
+		mgr->unset_output(mgr);
+	}
+
+	/* get framebuffer color mode */
+	r = fb_mode_to_dss_mode(var, &mode);
+	if (r)
+		return r;
+
+	/* calculate framebuffer buffer address */
+	if (ofbi->region->size)
+		omapfb_calc_addr(ofbi, var, fix, 0, &data_start_p);
+
+	/* link the free overlay manager to writeback */
+	mgr->set_output(mgr, wb);
+
+	omapdss_writeback_bus_lock(wb);
+
+	/* enable writeback to configure writeback and overlay manager params */
+	omapdss_writeback_enable(wb);
+
+	/* configure and apply manager info to set default color to zero */
+	mgr->get_manager_info(mgr, &mgr_info);
+
+	mgr_info.default_color = 0x0;
+
+	mgr->set_manager_info(mgr, &mgr_info);
+
+	mgr->apply(mgr);
+
+	/*
+	 * configure writeback parameters to write manager output to
+	 * framebuffer
+	 */
+	omapdss_writeback_set_input_size(wb, fbi->var.xres_virtual,
+		fbi->var.yres_virtual);
+
+	omapdss_writeback_get_info(wb, &wb_info);
+
+	wb_info.paddr = data_start_p;
+	wb_info.rotation_type = OMAP_DSS_ROT_DMA;
+	wb_info.rotation = 0;
+	wb_info.mirror = 0;
+	wb_info.width = fbi->var.xres_virtual;
+	wb_info.buf_width = fbi->var.xres_virtual;
+	wb_info.height = fbi->var.yres_virtual;
+	wb_info.color_mode = mode;
+
+	omapdss_writeback_set_info(wb, &wb_info);
+
+	omapdss_writeback_apply(wb);
+
+	/* start writeback update */
+	omapdss_writeback_update(wb, wb_callback, wb);
+
+	omapdss_writeback_bus_lock(wb);
+
+	/* disable writeback(and the connected manager) */
+	omapdss_writeback_disable(wb);
+
+	omapdss_writeback_bus_unlock(wb);
+
+	/* restore manager back to it's old state */
+	mgr->unset_output(mgr);
+
+	if (orig_out)
+		mgr->set_output(mgr, orig_out);
+
+	return 0;
+}
+
 static void omapfb_clear_fb(struct fb_info *fbi)
 {
+	int r;
 	const struct fb_fillrect rect = {
 		.dx = 0,
 		.dy = 0,
@@ -1601,7 +1724,14 @@ static void omapfb_clear_fb(struct fb_info *fbi)
 		.rop = ROP_COPY,
 	};
 
-	cfb_fillrect(fbi, &rect);
+	r = omapfb_clear_fb_writeback(fbi);
+
+	/*
+	 * if clearing through writeback failed, revert to clearing the
+	 * framebuffer through MPU
+	 */
+	if (r)
+		cfb_fillrect(fbi, &rect);
 }
 
 int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type)
-- 
1.7.9.5


      parent reply	other threads:[~2012-11-07 14:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-07 14:56 [RFC 00/11] OMAPDSS: Add writeback mem to mem mode support Archit Taneja
2012-11-07 14:56 ` [RFC 01/11] OMAPDSS: Add writeback output driver Archit Taneja
2012-11-07 14:56 ` [RFC 02/11] OMAPDSS: APPLY: Add get/set info functions for writeback Archit Taneja
2012-11-07 14:56 ` [RFC 03/11] OMAPDSS: APPLY: Apply writeback configurations Archit Taneja
2012-11-07 14:56 ` [RFC 04/11] OMAPDSS: writeback: Configure writeback input size Archit Taneja
2012-11-07 14:56 ` [RFC 05/11] OMAPDSS: APPLY: Add writeback enable/disable funcs Archit Taneja
2012-11-07 14:56 ` [RFC 06/11] OMAPDSS: APPLY: configure channel_in for writeback Archit Taneja
2012-11-07 14:56 ` [RFC 07/11] OMAPDSS: writeback: add mechanism to do mem to mem updates Archit Taneja
2012-11-07 14:56 ` [RFC 08/11] OMAPDSS: APPLY: Check if overlay is connected in mem to mem mode Archit Taneja
2012-11-07 14:56 ` [RFC 09/11] OMAPDSS: FEATURES: Add writeback as supported outputs for OMAP4 managers Archit Taneja
2012-11-07 14:56 ` [RFC 10/11] ARCH: ARM: OMAP: Create a platform device for writeback Archit Taneja
2012-11-07 14:56 ` Archit Taneja [this message]

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=1352299469-17609-12-git-send-email-archit@ti.com \
    --to=archit@ti.com \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=tomi.valkeinen@ti.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;
as well as URLs for NNTP newsgroup(s).