linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] video: sh_mobile_lcdcfb suspend/resume support
@ 2009-03-13 15:36 Magnus Damm
       [not found] ` <20090313152714.20494.42365.sendpatchset@rx1.opensource.se>
  0 siblings, 1 reply; 2+ messages in thread
From: Magnus Damm @ 2009-03-13 15:36 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: Magnus Damm, lethal, linux-sh

From: Magnus Damm <damm@igel.co.jp>

This patch adds suspend/resume support to the LCDC
driver for SuperH Mobile - sh_mobile_lcdcfb.

We simply stop hardware on suspend and start it again
on resume. For RGB panels this is trivial, but for SYS
panels in deferred io mode this becomes a bit more
difficult - we need to wait for a frame end interrupt
to make sure the clocks are balanced before stopping
the actual hardware.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 Tested on ap325 and Migo-R.

 drivers/video/sh_mobile_lcdcfb.c |   66 +++++++++++++++++++++++++++++++++-----
 1 file changed, 59 insertions(+), 7 deletions(-)

--- 0001/drivers/video/sh_mobile_lcdcfb.c
+++ work/drivers/video/sh_mobile_lcdcfb.c	2009-03-14 00:06:47.000000000 +0900
@@ -33,6 +33,8 @@ struct sh_mobile_lcdc_chan {
 	struct fb_info info;
 	dma_addr_t dma_handle;
 	struct fb_deferred_io defio;
+	unsigned long frame_end;
+	wait_queue_head_t frame_end_wait;
 };
 
 struct sh_mobile_lcdc_priv {
@@ -226,7 +228,10 @@ static void sh_mobile_lcdc_deferred_io_t
 static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
 {
 	struct sh_mobile_lcdc_priv *priv = data;
+	struct sh_mobile_lcdc_chan *ch;
 	unsigned long tmp;
+	int is_sub;
+	int k;
 
 	/* acknowledge interrupt */
 	tmp = lcdc_read(priv, _LDINTR);
@@ -234,8 +239,24 @@ static irqreturn_t sh_mobile_lcdc_irq(in
 	tmp |= 0x000000ff ^ LDINTR_FS; /* status in low 8 */
 	lcdc_write(priv, _LDINTR, tmp);
 
-	/* disable clocks */
-	sh_mobile_lcdc_clk_off(priv);
+	/* figure out if this interrupt is for main or sub lcd */
+	is_sub = (lcdc_read(priv, _LDSR) & (1 << 10)) ? 1 : 0;
+
+	/* wake up channel and disable clocks*/
+	for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
+		ch = &priv->ch[k];
+
+		if (!ch->enabled)
+			continue;
+
+		if (is_sub == lcdc_chan_is_sublcd(ch)) {
+			ch->frame_end = 1;
+			wake_up(&ch->frame_end_wait);
+
+			sh_mobile_lcdc_clk_off(priv);
+		}
+	}
+
 	return IRQ_HANDLED;
 }
 
@@ -448,18 +469,27 @@ static void sh_mobile_lcdc_stop(struct s
 	struct sh_mobile_lcdc_board_cfg	*board_cfg;
 	int k;
 
-	/* tell the board code to disable the panel */
+	/* clean up deferred io and ask board code to disable panel */
 	for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
 		ch = &priv->ch[k];
-		board_cfg = &ch->cfg.board_cfg;
-		if (board_cfg->display_off)
-			board_cfg->display_off(board_cfg->board_data);
 
-		/* cleanup deferred io if enabled */
+		/* deferred io mode:
+		 * flush frame, and wait for frame end interrupt
+		 * clean up deferred io and enable clock
+		 */
 		if (ch->info.fbdefio) {
+			ch->frame_end = 0;
+			schedule_delayed_work(&ch->info.deferred_work, 0);
+			wait_event(ch->frame_end_wait, ch->frame_end);
 			fb_deferred_io_cleanup(&ch->info);
 			ch->info.fbdefio = NULL;
+			sh_mobile_lcdc_clk_on(priv);
 		}
+
+		board_cfg = &ch->cfg.board_cfg;
+		if (board_cfg->display_off)
+			board_cfg->display_off(board_cfg->board_data);
+
 	}
 
 	/* stop the lcdc */
@@ -652,6 +682,26 @@ static int sh_mobile_lcdc_set_bpp(struct
 	return 0;
 }
 
+static int sh_mobile_lcdc_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
+	return 0;
+}
+
+static int sh_mobile_lcdc_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
+}
+
+static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
+	.suspend = sh_mobile_lcdc_suspend,
+	.resume = sh_mobile_lcdc_resume,
+};
+
 static int sh_mobile_lcdc_remove(struct platform_device *pdev);
 
 static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
@@ -707,6 +757,7 @@ static int __init sh_mobile_lcdc_probe(s
 			dev_err(&pdev->dev, "unsupported interface type\n");
 			goto err1;
 		}
+		init_waitqueue_head(&priv->ch[i].frame_end_wait);
 
 		switch (pdata->ch[i].chan) {
 		case LCDC_CHAN_MAINLCD:
@@ -860,6 +911,7 @@ static struct platform_driver sh_mobile_
 	.driver		= {
 		.name		= "sh_mobile_lcdc_fb",
 		.owner		= THIS_MODULE,
+		.pm		= &sh_mobile_lcdc_dev_pm_ops,
 	},
 	.probe		= sh_mobile_lcdc_probe,
 	.remove		= sh_mobile_lcdc_remove,

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] sh: SuperH Mobile suspend support V3
       [not found]   ` <20090313152304.20487.42793.sendpatchset@rx1.opensource.se>
@ 2009-03-16 11:00     ` Paul Mundt
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Mundt @ 2009-03-16 11:00 UTC (permalink / raw)
  To: Magnus Damm; +Cc: linux-sh, francesco.virlinzi, linux-fbdev-devel

On Sat, Mar 14, 2009 at 12:23:04AM +0900, Magnus Damm wrote:
> This patch contains CONFIG_SUSPEND support to the SuperH
> architecture V3. If enabled, SuperH Mobile processors will
> register their suspend callbacks during boot.
> 
> To suspend, use "echo mem > /sys/power/state". To allow
> wakeup, make sure "/sys/device/platform/../power/wakeup"
> contains "enabled". Additional per-device driver patches
> are most likely needed.
> 
> Signed-off-by: Magnus Damm <damm@igel.co.jp>

On Sat, Mar 14, 2009 at 12:27:14AM +0900, Magnus Damm wrote:
> Improve the ap325 board code to allow the lcd panel
> and backlight to be powered off.
> 
> Signed-off-by: Magnus Damm <damm@igel.co.jp>

On Sat, Mar 14, 2009 at 12:36:55AM +0900, Magnus Damm wrote:
> This patch adds suspend/resume support to the LCDC
> driver for SuperH Mobile - sh_mobile_lcdcfb.
> 
> We simply stop hardware on suspend and start it again
> on resume. For RGB panels this is trivial, but for SYS
> panels in deferred io mode this becomes a bit more
> difficult - we need to wait for a frame end interrupt
> to make sure the clocks are balanced before stopping
> the actual hardware.
> 
> Signed-off-by: Magnus Damm <damm@igel.co.jp>

All applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-03-16 11:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-13 15:36 [PATCH] video: sh_mobile_lcdcfb suspend/resume support Magnus Damm
     [not found] ` <20090313152714.20494.42365.sendpatchset@rx1.opensource.se>
     [not found]   ` <20090313152304.20487.42793.sendpatchset@rx1.opensource.se>
2009-03-16 11:00     ` [PATCH] sh: SuperH Mobile suspend support V3 Paul Mundt

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).