2 * BRIEF MODULE DESCRIPTION
5 * Rewritten for 2.6 by Embedded Alley Solutions
6 * <source@embeddedalley.com>, based on submissions by
7 * Karl Lessard <klessard@sunrisetelecom.com>
8 * <c.pellegrin@exadron.com>
10 * Copyright 2002 MontaVista Software
11 * Author: MontaVista Software, Inc.
12 * ppopov@mvista.com or source@mvista.com
14 * Copyright 2002 Alchemy Semiconductor
15 * Author: Alchemy Semiconductor
18 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
19 * Created 28 Dec 1997 by Geert Uytterhoeven
21 * This program is free software; you can redistribute it and/or modify it
22 * under the terms of the GNU General Public License as published by the
23 * Free Software Foundation; either version 2 of the License, or (at your
24 * option) any later version.
26 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
29 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
32 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * You should have received a copy of the GNU General Public License along
38 * with this program; if not, write to the Free Software Foundation, Inc.,
39 * 675 Mass Ave, Cambridge, MA 02139, USA.
41 #include <linux/config.h>
42 #include <linux/module.h>
43 #include <linux/kernel.h>
44 #include <linux/errno.h>
45 #include <linux/string.h>
48 #include <linux/init.h>
49 #include <linux/interrupt.h>
50 #include <linux/ctype.h>
51 #include <linux/dma-mapping.h>
53 #include <asm/mach-au1x00/au1000.h>
60 * Sanity check. If this is a new Au1100 based board, search for
61 * the PB1100 ifdefs to make sure you modify the code accordingly.
63 #if defined(CONFIG_MIPS_PB1100)
64 #include <asm/mach-pb1x00/pb1100.h>
65 #elif defined(CONFIG_MIPS_DB1100)
66 #include <asm/mach-db1x00/db1x00.h>
68 #error "Unknown Au1100 board, Au1100 FB driver not supported"
71 #define DRIVER_NAME "au1100fb"
72 #define DRIVER_DESC "LCD controller driver for AU1100 processors"
74 #define to_au1100fb_device(_info) \
75 (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
77 /* Bitfields format supported by the controller. Note that the order of formats
78 * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
79 * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
81 struct fb_bitfield rgb_bitfields[][4] =
83 /* Red, Green, Blue, Transp */
84 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
85 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
86 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
87 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
88 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
90 /* The last is used to describe 12bpp format */
91 { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
94 static struct fb_fix_screeninfo au1100fb_fix __initdata = {
98 .type = FB_TYPE_PACKED_PIXELS,
99 .accel = FB_ACCEL_NONE,
102 static struct fb_var_screeninfo au1100fb_var __initdata = {
103 .activate = FB_ACTIVATE_NOW,
106 .vmode = FB_VMODE_NONINTERLACED,
109 static struct au1100fb_drv_info drv_info;
112 * Set hardware with var settings. This will enable the controller with a specific
113 * mode, normally validated with the fb_check_var method
115 int au1100fb_setmode(struct au1100fb_device *fbdev)
117 struct fb_info *info = &fbdev->info;
124 /* Update var-dependent FB info */
125 if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
126 if (info->var.bits_per_pixel <= 8) {
128 info->var.red.offset = 0;
129 info->var.red.length = info->var.bits_per_pixel;
130 info->var.red.msb_right = 0;
132 info->var.green.offset = 0;
133 info->var.green.length = info->var.bits_per_pixel;
134 info->var.green.msb_right = 0;
136 info->var.blue.offset = 0;
137 info->var.blue.length = info->var.bits_per_pixel;
138 info->var.blue.msb_right = 0;
140 info->var.transp.offset = 0;
141 info->var.transp.length = 0;
142 info->var.transp.msb_right = 0;
144 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
145 info->fix.line_length = info->var.xres_virtual /
146 (8/info->var.bits_per_pixel);
149 index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
150 info->var.red = rgb_bitfields[index][0];
151 info->var.green = rgb_bitfields[index][1];
152 info->var.blue = rgb_bitfields[index][2];
153 info->var.transp = rgb_bitfields[index][3];
155 info->fix.visual = FB_VISUAL_TRUECOLOR;
156 info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
160 info->fix.visual = FB_VISUAL_MONO10;
161 info->fix.line_length = info->var.xres_virtual / 8;
164 info->screen_size = info->fix.line_length * info->var.yres_virtual;
166 /* Determine BPP mode and format */
167 fbdev->regs->lcd_control = fbdev->panel->control_base |
168 ((info->var.rotate/90) << LCD_CONTROL_SM_BIT);
170 fbdev->regs->lcd_intenable = 0;
171 fbdev->regs->lcd_intstatus = 0;
173 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
175 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
177 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
179 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
181 if (panel_is_dual(fbdev->panel)) {
182 /* Second panel display seconf half of screen if possible,
183 * otherwise display the same as the first panel */
184 if (info->var.yres_virtual >= (info->var.yres << 1)) {
185 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
186 (info->fix.line_length *
187 (info->var.yres_virtual >> 1)));
189 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
193 words = info->fix.line_length / sizeof(u32);
194 if (!info->var.rotate || (info->var.rotate == 180)) {
195 words *= info->var.yres_virtual;
196 if (info->var.rotate /* 180 */) {
197 words -= (words % 8); /* should be divisable by 8 */
200 fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
202 fbdev->regs->lcd_pwmdiv = 0;
203 fbdev->regs->lcd_pwmhi = 0;
205 /* Resume controller */
206 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
212 * Set color in LCD palette.
214 int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
216 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
217 u32 *palette = fbdev->regs->lcd_pallettebase;
220 if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
223 if (fbi->var.grayscale) {
224 /* Convert color to grayscale */
226 (19595 * red + 38470 * green + 7471 * blue) >> 16;
229 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
230 /* Place color in the pseudopalette */
234 palette = (u32*)fbi->pseudo_palette;
236 red >>= (16 - fbi->var.red.length);
237 green >>= (16 - fbi->var.green.length);
238 blue >>= (16 - fbi->var.blue.length);
240 value = (red << fbi->var.red.offset) |
241 (green << fbi->var.green.offset)|
242 (blue << fbi->var.blue.offset);
245 } else if (panel_is_active(fbdev->panel)) {
246 /* COLOR TFT PALLETTIZED (use RGB 565) */
247 value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
250 } else if (panel_is_color(fbdev->panel)) {
252 value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
253 ((green >> 8) & 0x00F0) |
254 (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
257 /* MONOCHROME MODE */
258 value = (green >> 12) & 0x000F;
262 palette[regno] = value;
268 * Blank the screen. Depending on the mode, the screen will be
269 * activated with the backlight color, or desactivated
271 int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
273 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
275 print_dbg("fb_blank %d %p", blank_mode, fbi);
277 switch (blank_mode) {
279 case VESA_NO_BLANKING:
281 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
282 #ifdef CONFIG_MIPS_PB1100
283 if (drv_info.panel_idx == 1) {
284 au_writew(au_readw(PB1100_G_CONTROL)
285 | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
292 case VESA_VSYNC_SUSPEND:
293 case VESA_HSYNC_SUSPEND:
296 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
297 #ifdef CONFIG_MIPS_PB1100
298 if (drv_info.panel_idx == 1) {
299 au_writew(au_readw(PB1100_G_CONTROL)
300 & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
314 * Pan display in x and/or y as specified
316 int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
318 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
321 print_dbg("fb_pan_display %p %p", var, fbi);
323 if (!var || !fbdev) {
327 if (var->xoffset - fbi->var.xoffset) {
328 /* No support for X panning for now! */
332 print_dbg("fb_pan_display 2 %p %p", var, fbi);
333 dy = var->yoffset - fbi->var.yoffset;
338 print_dbg("Panning screen of %d lines", dy);
340 dmaaddr = fbdev->regs->lcd_dmaaddr0;
341 dmaaddr += (fbi->fix.line_length * dy);
343 /* TODO: Wait for current frame to finished */
344 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
346 if (panel_is_dual(fbdev->panel)) {
347 dmaaddr = fbdev->regs->lcd_dmaaddr1;
348 dmaaddr += (fbi->fix.line_length * dy);
349 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
352 print_dbg("fb_pan_display 3 %p %p", var, fbi);
358 * Rotate the display of this angle. This doesn't seems to be used by the core,
359 * but as our hardware supports it, so why not implementing it...
361 void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
363 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
365 print_dbg("fb_rotate %p %d", fbi, angle);
367 if (fbdev && (angle > 0) && !(angle % 90)) {
369 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
371 fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
372 fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
374 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
379 * Map video memory in user space. We don't use the generic fb_mmap method mainly
380 * to allow the use of the TLB streaming flag (CCA=6)
382 int au1100fb_fb_mmap(struct fb_info *fbi, struct file *file, struct vm_area_struct *vma)
384 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
386 unsigned long start=0, off;
388 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
392 start = fbdev->fb_phys & PAGE_MASK;
393 len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
395 off = vma->vm_pgoff << PAGE_SHIFT;
397 if ((vma->vm_end - vma->vm_start + off) > len) {
402 vma->vm_pgoff = off >> PAGE_SHIFT;
404 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
405 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
407 vma->vm_flags |= VM_IO;
409 if (io_remap_page_range(vma, vma->vm_start, off,
410 vma->vm_end - vma->vm_start,
411 vma->vm_page_prot)) {
418 static struct fb_ops au1100fb_ops =
420 .owner = THIS_MODULE,
421 .fb_setcolreg = au1100fb_fb_setcolreg,
422 .fb_blank = au1100fb_fb_blank,
423 .fb_pan_display = au1100fb_fb_pan_display,
424 .fb_fillrect = cfb_fillrect,
425 .fb_copyarea = cfb_copyarea,
426 .fb_imageblit = cfb_imageblit,
427 .fb_rotate = au1100fb_fb_rotate,
428 .fb_mmap = au1100fb_fb_mmap,
432 /*-------------------------------------------------------------------------*/
434 /* AU1100 LCD controller device driver */
436 int au1100fb_drv_probe(struct device *dev)
438 struct au1100fb_device *fbdev = NULL;
439 struct resource *regs_res;
446 /* Allocate new device private */
447 if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
448 print_err("fail to allocate device private record");
451 memset((void*)fbdev, 0, sizeof(struct au1100fb_device));
453 fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
455 dev_set_drvdata(dev, (void*)fbdev);
457 /* Allocate region for our registers and map them */
458 if (!(regs_res = platform_get_resource(to_platform_device(dev),
459 IORESOURCE_MEM, 0))) {
460 print_err("fail to retrieve registers resource");
464 au1100fb_fix.mmio_start = regs_res->start;
465 au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1;
467 if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len,
469 print_err("fail to lock memory region at 0x%08x",
470 au1100fb_fix.mmio_start);
474 fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
476 print_dbg("Register memory map at %p", fbdev->regs);
477 print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
481 /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
482 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
483 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
485 fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len),
486 &fbdev->fb_phys, GFP_KERNEL);
487 if (!fbdev->fb_mem) {
488 print_err("fail to allocate frambuffer (size: %dK))",
489 fbdev->fb_len / 1024);
493 au1100fb_fix.smem_start = fbdev->fb_phys;
494 au1100fb_fix.smem_len = fbdev->fb_len;
497 * Set page reserved so that mmap will work. This is necessary
498 * since we'll be remapping normal memory.
500 for (page = (unsigned long)fbdev->fb_mem;
501 page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
503 #if CONFIG_DMA_NONCOHERENT
504 SetPageReserved(virt_to_page(CAC_ADDR(page)));
506 SetPageReserved(virt_to_page(page));
510 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
511 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
513 /* Setup LCD clock to AUX (48 MHz) */
514 sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
515 au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC);
517 /* load the panel info into the var struct */
518 au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
519 au1100fb_var.xres = fbdev->panel->xres;
520 au1100fb_var.xres_virtual = au1100fb_var.xres;
521 au1100fb_var.yres = fbdev->panel->yres;
522 au1100fb_var.yres_virtual = au1100fb_var.yres;
524 fbdev->info.screen_base = fbdev->fb_mem;
525 fbdev->info.fbops = &au1100fb_ops;
526 fbdev->info.fix = au1100fb_fix;
528 if (!(fbdev->info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL))) {
531 memset(fbdev->info.pseudo_palette, 0, sizeof(u32) * 16);
533 if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
534 print_err("Fail to allocate colormap (%d entries)",
535 AU1100_LCD_NBR_PALETTE_ENTRIES);
536 kfree(fbdev->info.pseudo_palette);
540 fbdev->info.var = au1100fb_var;
542 /* Set h/w registers */
543 au1100fb_setmode(fbdev);
545 /* Register new framebuffer */
546 if (register_framebuffer(&fbdev->info) < 0) {
547 print_err("cannot register new framebuffer");
555 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
558 dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys);
560 if (fbdev->info.cmap.len != 0) {
561 fb_dealloc_cmap(&fbdev->info.cmap);
564 dev_set_drvdata(dev, NULL);
569 int au1100fb_drv_remove(struct device *dev)
571 struct au1100fb_device *fbdev = NULL;
576 fbdev = (struct au1100fb_device*) dev_get_drvdata(dev);
578 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
579 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
581 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
583 /* Clean up all probe data */
584 unregister_framebuffer(&fbdev->info);
586 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
588 dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys);
590 fb_dealloc_cmap(&fbdev->info.cmap);
591 kfree(fbdev->info.pseudo_palette);
597 int au1100fb_drv_suspend(struct device *dev, u32 state, u32 level)
603 int au1100fb_drv_resume(struct device *dev, u32 level)
609 static struct device_driver au1100fb_driver = {
610 .name = "au1100-lcd",
611 .bus = &platform_bus_type,
613 .probe = au1100fb_drv_probe,
614 .remove = au1100fb_drv_remove,
615 .suspend = au1100fb_drv_suspend,
616 .resume = au1100fb_drv_resume,
619 /*-------------------------------------------------------------------------*/
623 int au1100fb_setup(char *options)
626 int num_panels = ARRAY_SIZE(known_lcd_panels);
630 if (num_panels <= 0) {
631 print_err("No LCD panels supported by driver!");
636 while ((this_opt = strsep(&options,",")) != NULL) {
638 if (!strncmp(this_opt, "panel:", 6)) {
641 for (i = 0; i < num_panels; i++) {
642 if (!strncmp(this_opt,
643 known_lcd_panels[i].name,
649 if (i >= num_panels) {
650 print_warn("Panel %s not supported!", this_opt);
653 /* Mode option (only option that start with digit) */
654 else if (isdigit(this_opt[0])) {
655 mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
656 strncpy(mode, this_opt, strlen(this_opt) + 1);
658 /* Unsupported option */
660 print_warn("Unsupported option \"%s\"", this_opt);
665 drv_info.panel_idx = panel_idx;
666 drv_info.opt_mode = mode;
668 print_info("Panel=%s Mode=%s",
669 known_lcd_panels[drv_info.panel_idx].name,
670 drv_info.opt_mode ? drv_info.opt_mode : "default");
675 int __init au1100fb_init(void)
680 print_info("" DRIVER_DESC "");
682 memset(&drv_info, 0, sizeof(drv_info));
684 if (fb_get_options(DRIVER_NAME, &options))
687 /* Setup driver with options */
688 ret = au1100fb_setup(options);
690 print_err("Fail to setup driver");
694 return driver_register(&au1100fb_driver);
697 void __exit au1100fb_cleanup(void)
699 driver_unregister(&au1100fb_driver);
701 if (drv_info.opt_mode)
702 kfree(drv_info.opt_mode);
705 module_init(au1100fb_init);
706 module_exit(au1100fb_cleanup);
708 MODULE_DESCRIPTION(DRIVER_DESC);
709 MODULE_LICENSE("GPL");