2 * linux/drivers/video/amba-clcd.c
4 * Copyright (C) 2001 ARM Limited, by David A Rusling
5 * Updated to 2.5, Deep Blue Solutions Ltd.
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive
11 * ARM PrimeCell PL110 Color LCD Controller
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/string.h>
17 #include <linux/slab.h>
18 #include <linux/delay.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/memblock.h>
24 #include <linux/init.h>
25 #include <linux/ioport.h>
26 #include <linux/list.h>
27 #include <linux/amba/bus.h>
28 #include <linux/amba/clcd.h>
29 #include <linux/clk.h>
30 #include <linux/hardirq.h>
32 #include <asm/sizes.h>
34 #define to_clcd(info) container_of(info, struct clcd_fb, fb)
37 #define clcdfb_dma_alloc dma_alloc_writecombine
38 #define clcdfb_dma_free dma_free_writecombine
39 #define clcdfb_dma_mmap dma_mmap_writecombine
41 #define clcdfb_dma_alloc dma_alloc_coherent
42 #define clcdfb_dma_free dma_free_coherent
43 #define clcdfb_dma_mmap dma_mmap_coherent
46 /* This is limited to 16 characters when displayed by X startup */
47 static const char *clcd_name = "CLCD FB";
48 static char *def_mode;
49 module_param_named(mode, def_mode, charp, 0);
52 * Unfortunately, the enable/disable functions may be called either from
53 * process or IRQ context, and we _need_ to delay. This is _not_ good.
55 static inline void clcdfb_sleep(unsigned int ms)
64 static inline void clcdfb_set_start(struct clcd_fb *fb)
66 unsigned long ustart = fb->fb.fix.smem_start;
69 ustart += fb->fb.var.yoffset * fb->fb.fix.line_length;
70 lstart = ustart + fb->fb.var.yres * fb->fb.fix.line_length / 2;
72 writel(ustart, fb->regs + CLCD_UBAS);
73 writel(lstart, fb->regs + CLCD_LBAS);
76 static void clcdfb_disable(struct clcd_fb *fb)
80 if (fb->board->disable)
81 fb->board->disable(fb);
83 val = readl(fb->regs + fb->off_cntl);
84 if (val & CNTL_LCDPWR) {
86 writel(val, fb->regs + fb->off_cntl);
90 if (val & CNTL_LCDEN) {
92 writel(val, fb->regs + fb->off_cntl);
96 * Disable CLCD clock source.
98 if (fb->clk_enabled) {
99 fb->clk_enabled = false;
100 clk_disable(fb->clk);
104 static void clcdfb_enable(struct clcd_fb *fb, u32 cntl)
107 * Enable the CLCD clock source.
109 if (!fb->clk_enabled) {
110 fb->clk_enabled = true;
115 * Bring up by first enabling..
118 writel(cntl, fb->regs + fb->off_cntl);
123 * and now apply power.
126 writel(cntl, fb->regs + fb->off_cntl);
129 * finally, enable the interface.
131 if (fb->board->enable)
132 fb->board->enable(fb);
136 clcdfb_set_bitfields(struct clcd_fb *fb, struct fb_var_screeninfo *var)
141 if (fb->panel->caps && fb->board->caps)
142 caps = fb->panel->caps & fb->board->caps;
144 /* Old way of specifying what can be used */
145 caps = fb->panel->cntl & CNTL_BGR ?
146 CLCD_CAP_BGR : CLCD_CAP_RGB;
147 /* But mask out 444 modes as they weren't supported */
148 caps &= ~CLCD_CAP_444;
151 /* Only TFT panels can do RGB888/BGR888 */
152 if (!(fb->panel->cntl & CNTL_LCDTFT))
153 caps &= ~CLCD_CAP_888;
155 memset(&var->transp, 0, sizeof(var->transp));
157 var->red.msb_right = 0;
158 var->green.msb_right = 0;
159 var->blue.msb_right = 0;
161 switch (var->bits_per_pixel) {
166 /* If we can't do 5551, reject */
167 caps &= CLCD_CAP_5551;
173 var->red.length = var->bits_per_pixel;
175 var->green.length = var->bits_per_pixel;
176 var->green.offset = 0;
177 var->blue.length = var->bits_per_pixel;
178 var->blue.offset = 0;
182 /* If we can't do 444, 5551 or 565, reject */
183 if (!(caps & (CLCD_CAP_444 | CLCD_CAP_5551 | CLCD_CAP_565))) {
189 * Green length can be 4, 5 or 6 depending whether
190 * we're operating in 444, 5551 or 565 mode.
192 if (var->green.length == 4 && caps & CLCD_CAP_444)
193 caps &= CLCD_CAP_444;
194 if (var->green.length == 5 && caps & CLCD_CAP_5551)
195 caps &= CLCD_CAP_5551;
196 else if (var->green.length == 6 && caps & CLCD_CAP_565)
197 caps &= CLCD_CAP_565;
200 * PL110 officially only supports RGB555,
201 * but may be wired up to allow RGB565.
203 if (caps & CLCD_CAP_565) {
204 var->green.length = 6;
205 caps &= CLCD_CAP_565;
206 } else if (caps & CLCD_CAP_5551) {
207 var->green.length = 5;
208 caps &= CLCD_CAP_5551;
210 var->green.length = 4;
211 caps &= CLCD_CAP_444;
215 if (var->green.length >= 5) {
217 var->blue.length = 5;
220 var->blue.length = 4;
224 /* If we can't do 888, reject */
225 caps &= CLCD_CAP_888;
232 var->green.length = 8;
233 var->blue.length = 8;
241 * >= 16bpp displays have separate colour component bitfields
242 * encoded in the pixel data. Calculate their position from
243 * the bitfield length defined above.
245 if (ret == 0 && var->bits_per_pixel >= 16) {
248 bgr = caps & CLCD_CAP_BGR && var->blue.offset == 0;
249 rgb = caps & CLCD_CAP_RGB && var->red.offset == 0;
253 * The requested format was not possible, try just
254 * our capabilities. One of BGR or RGB must be
257 bgr = caps & CLCD_CAP_BGR;
260 var->blue.offset = 0;
261 var->green.offset = var->blue.offset + var->blue.length;
262 var->red.offset = var->green.offset + var->green.length;
265 var->green.offset = var->red.offset + var->red.length;
266 var->blue.offset = var->green.offset + var->green.length;
273 static int clcdfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
275 struct clcd_fb *fb = to_clcd(info);
278 if (fb->board->check)
279 ret = fb->board->check(fb, var);
282 var->xres_virtual * var->bits_per_pixel / 8 *
283 var->yres_virtual > fb->fb.fix.smem_len)
287 ret = clcdfb_set_bitfields(fb, var);
292 static int clcdfb_set_par(struct fb_info *info)
294 struct clcd_fb *fb = to_clcd(info);
295 struct clcd_regs regs;
297 fb->fb.fix.line_length = fb->fb.var.xres_virtual *
298 fb->fb.var.bits_per_pixel / 8;
300 if (fb->fb.var.bits_per_pixel <= 8)
301 fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
303 fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
305 fb->board->decode(fb, ®s);
309 writel(regs.tim0, fb->regs + CLCD_TIM0);
310 writel(regs.tim1, fb->regs + CLCD_TIM1);
311 writel(regs.tim2, fb->regs + CLCD_TIM2);
312 writel(regs.tim3, fb->regs + CLCD_TIM3);
314 clcdfb_set_start(fb);
316 clk_set_rate(fb->clk, (1000000000 / regs.pixclock) * 1000);
318 fb->clcd_cntl = regs.cntl;
320 clcdfb_enable(fb, regs.cntl);
324 "CLCD: Registers set to\n"
325 " %08x %08x %08x %08x\n"
326 " %08x %08x %08x %08x\n",
327 readl(fb->regs + CLCD_TIM0), readl(fb->regs + CLCD_TIM1),
328 readl(fb->regs + CLCD_TIM2), readl(fb->regs + CLCD_TIM3),
329 readl(fb->regs + CLCD_UBAS), readl(fb->regs + CLCD_LBAS),
330 readl(fb->regs + fb->off_ienb), readl(fb->regs + fb->off_cntl));
336 static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
338 unsigned int mask = (1 << bf->length) - 1;
340 return (val >> (16 - bf->length) & mask) << bf->offset;
344 * Set a single color register. The values supplied have a 16 bit
345 * magnitude. Return != 0 for invalid regno.
348 clcdfb_setcolreg(unsigned int regno, unsigned int red, unsigned int green,
349 unsigned int blue, unsigned int transp, struct fb_info *info)
351 struct clcd_fb *fb = to_clcd(info);
354 fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
355 convert_bitfield(blue, &fb->fb.var.blue) |
356 convert_bitfield(green, &fb->fb.var.green) |
357 convert_bitfield(red, &fb->fb.var.red);
359 if (fb->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR && regno < 256) {
360 int hw_reg = CLCD_PALETTE + ((regno * 2) & ~3);
361 u32 val, mask, newval;
363 newval = (red >> 11) & 0x001f;
364 newval |= (green >> 6) & 0x03e0;
365 newval |= (blue >> 1) & 0x7c00;
368 * 3.2.11: if we're configured for big endian
369 * byte order, the palette entries are swapped.
371 if (fb->clcd_cntl & CNTL_BEBO)
381 val = readl(fb->regs + hw_reg) & mask;
382 writel(val | newval, fb->regs + hw_reg);
389 * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
390 * then the caller blanks by setting the CLUT (Color Look Up Table) to all
391 * black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due
392 * to e.g. a video mode which doesn't support it. Implements VESA suspend
393 * and powerdown modes on hardware that supports disabling hsync/vsync:
394 * blank_mode == 2: suspend vsync
395 * blank_mode == 3: suspend hsync
396 * blank_mode == 4: powerdown
398 static int clcdfb_blank(int blank_mode, struct fb_info *info)
400 struct clcd_fb *fb = to_clcd(info);
402 if (blank_mode != 0) {
405 clcdfb_enable(fb, fb->clcd_cntl);
410 int clcdfb_mmap_dma(struct clcd_fb *fb, struct vm_area_struct *vma)
412 return clcdfb_dma_mmap(&fb->dev->dev, vma,
414 fb->fb.fix.smem_start,
415 fb->fb.fix.smem_len);
418 int clcdfb_mmap_io(struct clcd_fb *fb, struct vm_area_struct *vma)
420 unsigned long user_count, count, pfn, off;
422 user_count = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
423 count = PAGE_ALIGN(fb->fb.fix.smem_len) >> PAGE_SHIFT;
424 pfn = fb->fb.fix.smem_start >> PAGE_SHIFT;
427 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
429 if (off < count && user_count <= (count - off))
430 return remap_pfn_range(vma, vma->vm_start, pfn + off,
431 user_count << PAGE_SHIFT,
437 void clcdfb_remove_dma(struct clcd_fb *fb)
439 clcdfb_dma_free(&fb->dev->dev, fb->fb.fix.smem_len,
440 fb->fb.screen_base, fb->fb.fix.smem_start);
443 void clcdfb_remove_io(struct clcd_fb *fb)
445 iounmap(fb->fb.screen_base);
448 static int clcdfb_mmap(struct fb_info *info,
449 struct vm_area_struct *vma)
451 struct clcd_fb *fb = to_clcd(info);
452 unsigned long len, off = vma->vm_pgoff << PAGE_SHIFT;
455 len = info->fix.smem_len;
457 if (off <= len && vma->vm_end - vma->vm_start <= len - off &&
459 ret = fb->board->mmap(fb, vma);
464 static struct fb_ops clcdfb_ops = {
465 .owner = THIS_MODULE,
466 .fb_check_var = clcdfb_check_var,
467 .fb_set_par = clcdfb_set_par,
468 .fb_setcolreg = clcdfb_setcolreg,
469 .fb_blank = clcdfb_blank,
470 .fb_fillrect = cfb_fillrect,
471 .fb_copyarea = cfb_copyarea,
472 .fb_imageblit = cfb_imageblit,
473 .fb_mmap = clcdfb_mmap,
476 static int clcdfb_register(struct clcd_fb *fb)
481 * ARM PL111 always has IENB at 0x1c; it's only PL110
482 * which is reversed on some platforms.
484 if (amba_manf(fb->dev) == 0x41 && amba_part(fb->dev) == 0x111) {
485 fb->off_ienb = CLCD_PL111_IENB;
486 fb->off_cntl = CLCD_PL111_CNTL;
488 #ifdef CONFIG_ARCH_VERSATILE
489 fb->off_ienb = CLCD_PL111_IENB;
490 fb->off_cntl = CLCD_PL111_CNTL;
492 fb->off_ienb = CLCD_PL110_IENB;
493 fb->off_cntl = CLCD_PL110_CNTL;
497 fb->clk = clk_get(&fb->dev->dev, NULL);
498 if (IS_ERR(fb->clk)) {
499 ret = PTR_ERR(fb->clk);
503 ret = clk_prepare(fb->clk);
507 fb->fb.device = &fb->dev->dev;
509 fb->fb.fix.mmio_start = fb->dev->res.start;
510 fb->fb.fix.mmio_len = resource_size(&fb->dev->res);
512 fb->regs = ioremap(fb->fb.fix.mmio_start, fb->fb.fix.mmio_len);
514 printk(KERN_ERR "CLCD: unable to remap registers\n");
519 fb->fb.fbops = &clcdfb_ops;
520 fb->fb.flags = FBINFO_FLAG_DEFAULT;
521 fb->fb.pseudo_palette = fb->cmap;
523 strncpy(fb->fb.fix.id, clcd_name, sizeof(fb->fb.fix.id));
524 fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
525 fb->fb.fix.type_aux = 0;
526 fb->fb.fix.xpanstep = 0;
527 fb->fb.fix.ypanstep = 0;
528 fb->fb.fix.ywrapstep = 0;
529 fb->fb.fix.accel = FB_ACCEL_NONE;
531 fb->fb.var.xres = fb->panel->mode.xres;
532 fb->fb.var.yres = fb->panel->mode.yres;
533 fb->fb.var.xres_virtual = fb->panel->mode.xres;
534 fb->fb.var.yres_virtual = fb->panel->mode.yres;
535 fb->fb.var.bits_per_pixel = fb->panel->bpp;
536 fb->fb.var.grayscale = fb->panel->grayscale;
537 fb->fb.var.pixclock = fb->panel->mode.pixclock;
538 fb->fb.var.left_margin = fb->panel->mode.left_margin;
539 fb->fb.var.right_margin = fb->panel->mode.right_margin;
540 fb->fb.var.upper_margin = fb->panel->mode.upper_margin;
541 fb->fb.var.lower_margin = fb->panel->mode.lower_margin;
542 fb->fb.var.hsync_len = fb->panel->mode.hsync_len;
543 fb->fb.var.vsync_len = fb->panel->mode.vsync_len;
544 fb->fb.var.sync = fb->panel->mode.sync;
545 fb->fb.var.vmode = fb->panel->mode.vmode;
546 fb->fb.var.activate = FB_ACTIVATE_NOW;
547 fb->fb.var.nonstd = 0;
548 fb->fb.var.height = fb->panel->height;
549 fb->fb.var.width = fb->panel->width;
550 fb->fb.var.accel_flags = 0;
552 fb->fb.monspecs.hfmin = 0;
553 fb->fb.monspecs.hfmax = 100000;
554 fb->fb.monspecs.vfmin = 0;
555 fb->fb.monspecs.vfmax = 400;
556 fb->fb.monspecs.dclkmin = 1000000;
557 fb->fb.monspecs.dclkmax = 100000000;
560 * Make sure that the bitfields are set appropriately.
562 clcdfb_set_bitfields(fb, &fb->fb.var);
565 * Allocate colourmap.
567 ret = fb_alloc_cmap(&fb->fb.cmap, 256, 0);
572 * Ensure interrupts are disabled.
574 writel(0, fb->regs + fb->off_ienb);
576 fb_set_var(&fb->fb, &fb->fb.var);
578 dev_info(&fb->dev->dev, "%s hardware, %s display\n",
579 fb->board->name, fb->panel->mode.name);
581 ret = register_framebuffer(&fb->fb);
585 printk(KERN_ERR "CLCD: cannot register framebuffer (%d)\n", ret);
587 fb_dealloc_cmap(&fb->fb.cmap);
591 clk_unprepare(fb->clk);
598 struct string_lookup {
603 static struct string_lookup vmode_lookups[] = {
604 { "FB_VMODE_NONINTERLACED", FB_VMODE_NONINTERLACED},
605 { "FB_VMODE_INTERLACED", FB_VMODE_INTERLACED},
606 { "FB_VMODE_DOUBLE", FB_VMODE_DOUBLE},
607 { "FB_VMODE_ODD_FLD_FIRST", FB_VMODE_ODD_FLD_FIRST},
611 static struct string_lookup tim2_lookups[] = {
612 { "TIM2_CLKSEL", TIM2_CLKSEL},
613 { "TIM2_IVS", TIM2_IVS},
614 { "TIM2_IHS", TIM2_IHS},
615 { "TIM2_IPC", TIM2_IPC},
616 { "TIM2_IOE", TIM2_IOE},
617 { "TIM2_BCD", TIM2_BCD},
620 static struct string_lookup cntl_lookups[] = {
621 {"CNTL_LCDEN", CNTL_LCDEN},
622 {"CNTL_LCDBPP1", CNTL_LCDBPP1},
623 {"CNTL_LCDBPP2", CNTL_LCDBPP2},
624 {"CNTL_LCDBPP4", CNTL_LCDBPP4},
625 {"CNTL_LCDBPP8", CNTL_LCDBPP8},
626 {"CNTL_LCDBPP16", CNTL_LCDBPP16},
627 {"CNTL_LCDBPP16_565", CNTL_LCDBPP16_565},
628 {"CNTL_LCDBPP16_444", CNTL_LCDBPP16_444},
629 {"CNTL_LCDBPP24", CNTL_LCDBPP24},
630 {"CNTL_LCDBW", CNTL_LCDBW},
631 {"CNTL_LCDTFT", CNTL_LCDTFT},
632 {"CNTL_LCDMONO8", CNTL_LCDMONO8},
633 {"CNTL_LCDDUAL", CNTL_LCDDUAL},
634 {"CNTL_BGR", CNTL_BGR},
635 {"CNTL_BEBO", CNTL_BEBO},
636 {"CNTL_BEPO", CNTL_BEPO},
637 {"CNTL_LCDPWR", CNTL_LCDPWR},
638 {"CNTL_LCDVCOMP(1)", CNTL_LCDVCOMP(1)},
639 {"CNTL_LCDVCOMP(2)", CNTL_LCDVCOMP(2)},
640 {"CNTL_LCDVCOMP(3)", CNTL_LCDVCOMP(3)},
641 {"CNTL_LCDVCOMP(4)", CNTL_LCDVCOMP(4)},
642 {"CNTL_LCDVCOMP(5)", CNTL_LCDVCOMP(5)},
643 {"CNTL_LCDVCOMP(6)", CNTL_LCDVCOMP(6)},
644 {"CNTL_LCDVCOMP(7)", CNTL_LCDVCOMP(7)},
645 {"CNTL_LDMAFIFOTIME", CNTL_LDMAFIFOTIME},
646 {"CNTL_WATERMARK", CNTL_WATERMARK},
649 static struct string_lookup caps_lookups[] = {
650 {"CLCD_CAP_RGB444", CLCD_CAP_RGB444},
651 {"CLCD_CAP_RGB5551", CLCD_CAP_RGB5551},
652 {"CLCD_CAP_RGB565", CLCD_CAP_RGB565},
653 {"CLCD_CAP_RGB888", CLCD_CAP_RGB888},
654 {"CLCD_CAP_BGR444", CLCD_CAP_BGR444},
655 {"CLCD_CAP_BGR5551", CLCD_CAP_BGR5551},
656 {"CLCD_CAP_BGR565", CLCD_CAP_BGR565},
657 {"CLCD_CAP_BGR888", CLCD_CAP_BGR888},
658 {"CLCD_CAP_444", CLCD_CAP_444},
659 {"CLCD_CAP_5551", CLCD_CAP_5551},
660 {"CLCD_CAP_565", CLCD_CAP_565},
661 {"CLCD_CAP_888", CLCD_CAP_888},
662 {"CLCD_CAP_RGB", CLCD_CAP_RGB},
663 {"CLCD_CAP_BGR", CLCD_CAP_BGR},
664 {"CLCD_CAP_ALL", CLCD_CAP_ALL},
668 u32 parse_setting(struct string_lookup *lookup, const char *name)
671 while (lookup[i].string != NULL) {
672 if (strcmp(lookup[i].string, name) == 0)
673 return lookup[i].val;
679 u32 get_string_lookup(struct device_node *node, const char *name,
680 struct string_lookup *lookup)
683 int count, i, ret = 0;
685 count = of_property_count_strings(node, name);
687 for (i = 0; i < count; i++)
688 if (of_property_read_string_index(node, name, i,
690 ret |= parse_setting(lookup, string);
694 int get_val(struct device_node *node, const char *string)
698 if (of_property_read_u32(node, string, &ret))
703 struct clcd_panel *getPanel(struct device_node *node)
705 static struct clcd_panel panel;
707 panel.mode.refresh = get_val(node, "refresh");
708 panel.mode.xres = get_val(node, "xres");
709 panel.mode.yres = get_val(node, "yres");
710 panel.mode.pixclock = get_val(node, "pixclock");
711 panel.mode.left_margin = get_val(node, "left_margin");
712 panel.mode.right_margin = get_val(node, "right_margin");
713 panel.mode.upper_margin = get_val(node, "upper_margin");
714 panel.mode.lower_margin = get_val(node, "lower_margin");
715 panel.mode.hsync_len = get_val(node, "hsync_len");
716 panel.mode.vsync_len = get_val(node, "vsync_len");
717 panel.mode.sync = get_val(node, "sync");
718 panel.bpp = get_val(node, "bpp");
719 panel.width = (signed short) get_val(node, "width");
720 panel.height = (signed short) get_val(node, "height");
722 panel.mode.vmode = get_string_lookup(node, "vmode", vmode_lookups);
723 panel.tim2 = get_string_lookup(node, "tim2", tim2_lookups);
724 panel.cntl = get_string_lookup(node, "cntl", cntl_lookups);
725 panel.caps = get_string_lookup(node, "caps", caps_lookups);
730 struct clcd_panel *clcdfb_get_panel(const char *name)
732 struct device_node *node = NULL;
734 struct clcd_panel *panel = NULL;
737 node = of_find_compatible_node(node, NULL, "panel");
739 if (of_property_read_string(node, "mode", &mode) == 0)
740 if (strcmp(mode, name) == 0) {
741 panel = getPanel(node);
742 panel->mode.name = name;
744 } while (node != NULL);
750 static int clcdfb_dt_init(struct clcd_fb *fb)
753 struct device_node *node;
759 phys_addr_t fb_base, fb_size;
761 node = fb->dev->dev.of_node;
765 na = of_n_addr_cells(node);
766 ns = of_n_size_cells(node);
768 if (def_mode && strlen(def_mode) > 0) {
769 fb->panel = clcdfb_get_panel(def_mode);
771 printk(KERN_ERR "CLCD: invalid mode specified on the command line (%s)\n", def_mode);
775 if (WARN_ON(of_property_read_string(node, "mode", &mode)))
777 fb->panel = clcdfb_get_panel(mode);
782 fb->fb.fix.smem_len = fb->panel->mode.xres * fb->panel->mode.yres * 2;
784 fb->board->name = "Device Tree CLCD PL111";
785 fb->board->caps = CLCD_CAP_5551 | CLCD_CAP_565;
786 fb->board->check = clcdfb_check;
787 fb->board->decode = clcdfb_decode;
789 if (of_property_read_u32(node, "use_dma", &use_dma))
793 fb->fb.screen_base = clcdfb_dma_alloc(&fb->dev->dev,
796 if (!fb->fb.screen_base) {
797 pr_err("CLCD: unable to map framebuffer\n");
801 fb->fb.fix.smem_start = dma;
802 fb->board->mmap = clcdfb_mmap_dma;
803 fb->board->remove = clcdfb_remove_dma;
805 prop = of_get_property(node, "framebuffer", &len);
806 if (WARN_ON(!prop || len < (na + ns) * sizeof(*prop)))
809 fb_base = of_read_number(prop, na);
810 fb_size = of_read_number(prop + na, ns);
812 fb->fb.fix.smem_start = fb_base;
813 fb->fb.screen_base = ioremap_wc(fb_base, fb_size);
814 fb->board->mmap = clcdfb_mmap_io;
815 fb->board->remove = clcdfb_remove_io;
820 #endif /* CONFIG_OF */
822 static int clcdfb_probe(struct amba_device *dev, const struct amba_id *id)
824 struct clcd_board *board = dev->dev.platform_data;
830 if (dev->dev.of_node) {
831 board = kzalloc(sizeof(struct clcd_board), GFP_KERNEL);
834 board->setup = clcdfb_dt_init;
840 ret = amba_request_regions(dev, NULL);
842 printk(KERN_ERR "CLCD: unable to reserve regs region\n");
846 fb = kzalloc(sizeof(struct clcd_fb), GFP_KERNEL);
848 printk(KERN_INFO "CLCD: could not allocate new clcd_fb struct\n");
856 dev_info(&fb->dev->dev, "PL%03x rev%u at 0x%08llx\n",
857 amba_part(dev), amba_rev(dev),
858 (unsigned long long)dev->res.start);
860 ret = fb->board->setup(fb);
864 ret = clcdfb_register(fb);
866 amba_set_drvdata(dev, fb);
870 fb->board->remove(fb);
874 amba_release_regions(dev);
879 static int clcdfb_remove(struct amba_device *dev)
881 struct clcd_fb *fb = amba_get_drvdata(dev);
883 amba_set_drvdata(dev, NULL);
886 unregister_framebuffer(&fb->fb);
888 fb_dealloc_cmap(&fb->fb.cmap);
890 clk_unprepare(fb->clk);
893 fb->board->remove(fb);
897 amba_release_regions(dev);
902 static struct amba_id clcdfb_id_table[] = {
910 MODULE_DEVICE_TABLE(amba, clcdfb_id_table);
912 static struct amba_driver clcd_driver = {
914 .name = "clcd-pl11x",
916 .probe = clcdfb_probe,
917 .remove = clcdfb_remove,
918 .id_table = clcdfb_id_table,
921 static int __init amba_clcdfb_init(void)
923 if (fb_get_options("ambafb", NULL))
926 return amba_driver_register(&clcd_driver);
929 module_init(amba_clcdfb_init);
931 static void __exit amba_clcdfb_exit(void)
933 amba_driver_unregister(&clcd_driver);
936 module_exit(amba_clcdfb_exit);
938 MODULE_DESCRIPTION("ARM PrimeCell PL110 CLCD core driver");
939 MODULE_LICENSE("GPL");