aboutsummaryrefslogtreecommitdiff
path: root/drivers/video
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2013-01-28 12:06:58 +0000
committerAlex Shi <alex.shi@linaro.org>2014-07-16 09:57:56 +0800
commitd0b33c5e8156fa98a4222bc9100ba76ecafc99ef (patch)
tree888f03d47ff50dd9889ea08db4c3f54d03559ba6 /drivers/video
parent8817e955d1bc5fb5bd68fe4447b500a32facfb67 (diff)
amba-clcd: separate ioremap framebuffer from DMA implementation
The amba-clcd device can be configured to use either DMA or, when this feature is not available, an ioremapped frambuffer in static ram. In the case of the latter, we must take care not to pass ioremapped addresses to dma_common_mmap, since this expects only addresses from dma_mmap_coherent, which reside in the kernel linear mapping. This patch reworks the fb initialisation code so that either DMA or IO implementations of the mmap/remove functions are chosen as appropriate. Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> (cherry picked from commit 1602190741cb36f1833a91ff999bc14e82c6a08a) Signed-off-by: Alex Shi <alex.shi@linaro.org>
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/amba-clcd.c84
1 files changed, 56 insertions, 28 deletions
diff --git a/drivers/video/amba-clcd.c b/drivers/video/amba-clcd.c
index da2dd690ddf6..a0044a8e4e43 100644
--- a/drivers/video/amba-clcd.c
+++ b/drivers/video/amba-clcd.c
@@ -405,21 +405,43 @@ static int clcdfb_blank(int blank_mode, struct fb_info *info)
}
return 0;
}
+
int clcdfb_mmap_dma(struct clcd_fb *fb, struct vm_area_struct *vma)
{
- return clcdfb_dma_mmap(&fb->dev->dev, vma, fb->fb.screen_base,
- fb->fb.fix.smem_start, fb->fb.fix.smem_len);
+ return clcdfb_dma_mmap(&fb->dev->dev, vma,
+ fb->fb.screen_base,
+ fb->fb.fix.smem_start,
+ fb->fb.fix.smem_len);
+}
+
+int clcdfb_mmap_io(struct clcd_fb *fb, struct vm_area_struct *vma)
+{
+ unsigned long user_count, count, pfn, off;
+
+ user_count = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
+ count = PAGE_ALIGN(fb->fb.fix.smem_len) >> PAGE_SHIFT;
+ pfn = fb->fb.fix.smem_start >> PAGE_SHIFT;
+ off = vma->vm_pgoff;
+
+ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+ if (off < count && user_count <= (count - off))
+ return remap_pfn_range(vma, vma->vm_start, pfn + off,
+ user_count << PAGE_SHIFT,
+ vma->vm_page_prot);
+
+ return -ENXIO;
}
void clcdfb_remove_dma(struct clcd_fb *fb)
{
- struct device_node *node = fb->dev->dev.of_node;
- u32 use_dma = 0;
+ clcdfb_dma_free(&fb->dev->dev, fb->fb.fix.smem_len,
+ fb->fb.screen_base, fb->fb.fix.smem_start);
+}
- of_property_read_u32(node, "use_dma", &use_dma);
- if (use_dma)
- clcdfb_dma_free(&fb->dev->dev, fb->fb.fix.smem_len,
- fb->fb.screen_base, fb->fb.fix.smem_start);
+void clcdfb_remove_io(struct clcd_fb *fb)
+{
+ iounmap(fb->fb.screen_base);
}
static int clcdfb_mmap(struct fb_info *info,
@@ -750,26 +772,40 @@ static int clcdfb_dt_init(struct clcd_fb *fb)
return -EINVAL;
fb->fb.fix.smem_len = fb->panel->mode.xres * fb->panel->mode.yres * 2;
+ fb->board->name = "Device Tree CLCD PL111";
+ fb->board->caps = CLCD_CAP_5551 | CLCD_CAP_565;
+ fb->board->check = clcdfb_check;
+ fb->board->decode = clcdfb_decode;
+
if (of_property_read_u32(node, "use_dma", &use_dma))
use_dma = 0;
+
if (use_dma) {
fb->fb.screen_base = clcdfb_dma_alloc(&fb->dev->dev,
- fb->fb.fix.smem_len, &dma, GFP_KERNEL);
+ fb->fb.fix.smem_len,
+ &dma, GFP_KERNEL);
if (!fb->fb.screen_base) {
pr_err("CLCD: unable to map framebuffer\n");
- err = -ENOMEM;
- } else
- fb->fb.fix.smem_start = dma;
+ return -ENOMEM;
+ }
+
+ fb->fb.fix.smem_start = dma;
+ fb->board->mmap = clcdfb_mmap_dma;
+ fb->board->remove = clcdfb_remove_dma;
} else {
prop = of_get_property(node, "framebuffer", &len);
if (WARN_ON(!prop || len < (na + ns) * sizeof(*prop)))
return -EINVAL;
+
fb_base = of_read_number(prop, na);
fb_size = of_read_number(prop + na, ns);
- fb->fb.fix.smem_start = fb_base;
- fb->fb.screen_base = ioremap_wc(fb->fb.fix.smem_start, fb_size);
+ fb->fb.fix.smem_start = fb_base;
+ fb->fb.screen_base = ioremap_wc(fb_base, fb_size);
+ fb->board->mmap = clcdfb_mmap_io;
+ fb->board->remove = clcdfb_remove_io;
}
+
return err;
}
#endif /* CONFIG_OF */
@@ -780,25 +816,17 @@ static int clcdfb_probe(struct amba_device *dev, const struct amba_id *id)
struct clcd_fb *fb;
int ret;
+ if (!board) {
#ifdef CONFIG_OF
- if (dev->dev.of_node) {
- if (!board) {
+ if (dev->dev.of_node) {
board = kzalloc(sizeof(struct clcd_board), GFP_KERNEL);
if (!board)
- return -EINVAL;
- board->name = "Device Tree CLCD PL111";
- board->caps = CLCD_CAP_5551 | CLCD_CAP_565;
- board->check = clcdfb_check;
- board->decode = clcdfb_decode;
+ return -ENOMEM;
board->setup = clcdfb_dt_init;
- board->mmap = clcdfb_mmap_dma;
- board->remove = clcdfb_remove_dma;
- }
+ } else
+#endif
+ return -EINVAL;
}
-#endif /* CONFIG_OF */
-
- if (!board)
- return -EINVAL;
ret = dma_set_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
if (ret)