From patchwork Wed Feb 2 20:46:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Khoruzhick X-Patchwork-Id: 527471 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p12Kqc59031837 for ; Wed, 2 Feb 2011 20:52:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752930Ab1BBUwh (ORCPT ); Wed, 2 Feb 2011 15:52:37 -0500 Received: from mail-ey0-f174.google.com ([209.85.215.174]:57908 "EHLO mail-ey0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753059Ab1BBUwh (ORCPT ); Wed, 2 Feb 2011 15:52:37 -0500 Received: by eye27 with SMTP id 27so325578eye.19 for ; Wed, 02 Feb 2011 12:52:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=qzUvrv7clxoz4eVsBtAasivDORQMtsMJpy2AtAzav7U=; b=wtKGJcmXHj0BsLnl3RdGev+8en5KJqtv9Gq+BX2rpL1tbhjFTN8Q+rgHDuITVDgcj8 SHmU+lW8QSo1Yn1y3n2aP+ezl+dha/rLagoqIyDgMtRNhwnIm0sKBishUDLaHtojVfCl pxSxGWgdF2K5zHumL0v01++JxN/ct/FPeYBic= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=SkS6Ej257QKfYqCgPhdmxLRGB6kCSmUZKZnCDQdS9/7fdvzrSBeYXP1RZtwJhEW+ss lUO2O++w5O/L+YjSiyTPxwB62h/T+T+9I/M8pntfQKQvLn5l0q1Hlg3fN4vfONeYuRu3 MJOr2vVsuIpCSj6XfyavtmFQGP7Nn+dvEvKLY= Received: by 10.14.16.164 with SMTP id h36mr3016101eeh.37.1296679955621; Wed, 02 Feb 2011 12:52:35 -0800 (PST) Received: from localhost.localdomain ([46.28.101.209]) by mx.google.com with ESMTPS id t5sm29899eeh.2.2011.02.02.12.52.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 02 Feb 2011 12:52:33 -0800 (PST) From: Vasily Khoruzhick To: "Russell King - ARM Linux" , Marek Vasut , linux-arm-kernel@lists.infradead.org, Eric Miao , linux-fbdev@vger.kernel.org Cc: Vasily Khoruzhick Subject: [PATCH] ARM: PXA: Make PXA27x/PXA3xx overlay actually work Date: Wed, 2 Feb 2011 22:46:59 +0200 Message-Id: <1296679619-32666-1-git-send-email-anarsoul@gmail.com> X-Mailer: git-send-email 1.7.4.rc1 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 02 Feb 2011 20:53:03 +0000 (UTC) diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c index 825b665..33f607a 100644 --- a/drivers/video/pxafb.c +++ b/drivers/video/pxafb.c @@ -629,16 +629,19 @@ static void overlay1fb_disable(struct pxafb_layer *ofb) { uint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5); - lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] & ~OVLxC1_OEN); + if (lcd_readl(ofb->fbi, OVL1C1) & OVLxC1_OEN) { + lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] & ~OVLxC1_OEN); - lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(1)); - lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(1)); - lcd_writel(ofb->fbi, FBR1, ofb->fbi->fdadr[DMA_OV1] | 0x3); + lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(1)); + lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(1)); + lcd_writel(ofb->fbi, FBR1, ofb->fbi->fdadr[DMA_OV1] | 0x3); - if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0) - pr_warning("%s: timeout disabling overlay1\n", __func__); + if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0) + pr_warning("%s: timeout disabling overlay1\n", + __func__); - lcd_writel(ofb->fbi, LCCR5, lccr5); + lcd_writel(ofb->fbi, LCCR5, lccr5); + } } static void overlay2fb_setup(struct pxafb_layer *ofb) @@ -687,16 +690,19 @@ static void overlay2fb_disable(struct pxafb_layer *ofb) { uint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5); - lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] & ~OVLxC1_OEN); + if (lcd_readl(ofb->fbi, OVL2C1) & OVLxC1_OEN) { + lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] & ~OVLxC1_OEN); - lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(2)); - lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(2)); - lcd_writel(ofb->fbi, FBR2, ofb->fbi->fdadr[DMA_OV2_Y] | 0x3); - lcd_writel(ofb->fbi, FBR3, ofb->fbi->fdadr[DMA_OV2_Cb] | 0x3); - lcd_writel(ofb->fbi, FBR4, ofb->fbi->fdadr[DMA_OV2_Cr] | 0x3); + lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(2)); + lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(2)); + lcd_writel(ofb->fbi, FBR2, ofb->fbi->fdadr[DMA_OV2_Y] | 0x3); + lcd_writel(ofb->fbi, FBR3, ofb->fbi->fdadr[DMA_OV2_Cb] | 0x3); + lcd_writel(ofb->fbi, FBR4, ofb->fbi->fdadr[DMA_OV2_Cr] | 0x3); - if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0) - pr_warning("%s: timeout disabling overlay2\n", __func__); + if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0) + pr_warning("%s: timeout disabling overlay2\n", + __func__); + } } static struct pxafb_layer_ops ofb_ops[] = { @@ -720,12 +726,10 @@ static int overlayfb_open(struct fb_info *info, int user) if (user == 0) return -ENODEV; - /* allow only one user at a time */ - if (atomic_inc_and_test(&ofb->usage)) - return -EBUSY; + if (ofb->usage++ == 0) + /* unblank the base framebuffer */ + fb_blank(&ofb->fbi->fb, FB_BLANK_UNBLANK); - /* unblank the base framebuffer */ - fb_blank(&ofb->fbi->fb, FB_BLANK_UNBLANK); return 0; } @@ -733,12 +737,24 @@ static int overlayfb_release(struct fb_info *info, int user) { struct pxafb_layer *ofb = (struct pxafb_layer*) info; - atomic_dec(&ofb->usage); - ofb->ops->disable(ofb); - - free_pages_exact(ofb->video_mem, ofb->video_mem_size); - ofb->video_mem = NULL; - ofb->video_mem_size = 0; + if (--ofb->usage == 0) { + ofb->ops->disable(ofb); + ofb->fb.var.height = -1; + ofb->fb.var.width = -1; + ofb->fb.var.xres = ofb->fb.var.xres_virtual = 0; + ofb->fb.var.yres = ofb->fb.var.yres_virtual = 0; + + mutex_lock(&ofb->fb.mm_lock); + ofb->fb.fix.smem_start = 0; + ofb->fb.fix.smem_len = 0; + mutex_unlock(&ofb->fb.mm_lock); + + if (ofb->video_mem) { + free_pages_exact(ofb->video_mem, ofb->video_mem_size); + ofb->video_mem = NULL; + ofb->video_mem_size = 0; + } + } return 0; } @@ -817,7 +833,8 @@ static int overlayfb_map_video_memory(struct pxafb_layer *ofb) if (ofb->video_mem_size >= size) return 0; - free_pages_exact(ofb->video_mem, ofb->video_mem_size); + /* don't re-allocate: userspace may have the buffer mapped */ + return -EINVAL; } ofb->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO); @@ -891,7 +908,7 @@ static void __devinit init_pxafb_overlay(struct pxafb_info *fbi, ofb->id = id; ofb->ops = &ofb_ops[id]; - atomic_set(&ofb->usage, 0); + ofb->usage = 0; ofb->fbi = fbi; init_completion(&ofb->branch_done); } @@ -923,8 +940,6 @@ static int __devinit pxafb_overlay_init(struct pxafb_info *fbi) /* mask all IU/BS/EOF/SOF interrupts */ lcd_writel(fbi, LCCR5, ~0); - /* place overlay(s) on top of base */ - fbi->lccr0 |= LCCR0_OUC; pr_info("PXA Overlay driver loaded successfully!\n"); return 0; } @@ -1368,7 +1383,8 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var, (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) || (lcd_readl(fbi, LCCR4) != fbi->reg_lccr4) || (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) || - (lcd_readl(fbi, FDADR1) != fbi->fdadr[1])) + ((fbi->lccr0 & LCCR0_SDS) && + (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))) pxafb_schedule_work(fbi, C_REENABLE); return 0; @@ -1420,7 +1436,8 @@ static void pxafb_enable_controller(struct pxafb_info *fbi) lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB); lcd_writel(fbi, FDADR0, fbi->fdadr[0]); - lcd_writel(fbi, FDADR1, fbi->fdadr[1]); + if (fbi->lccr0 & LCCR0_SDS) + lcd_writel(fbi, FDADR1, fbi->fdadr[1]); lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB); } @@ -1806,6 +1823,11 @@ static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev) pxafb_decode_mach_info(fbi, inf); +#ifdef CONFIG_FB_PXA_OVERLAY + if (cpu_is_pxa27x()) + fbi->lccr0 |= LCCR0_OUC; +#endif + init_waitqueue_head(&fbi->ctrlr_wait); INIT_WORK(&fbi->task, pxafb_task); mutex_init(&fbi->ctrlr_lock); diff --git a/drivers/video/pxafb.h b/drivers/video/pxafb.h index 2353521..84e3ae1 100644 --- a/drivers/video/pxafb.h +++ b/drivers/video/pxafb.h @@ -92,7 +92,7 @@ struct pxafb_layer_ops { struct pxafb_layer { struct fb_info fb; int id; - atomic_t usage; + uint32_t usage; uint32_t control[2]; struct pxafb_layer_ops *ops;