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 * PM support added by Rodolfo Giometti <giometti@linux.it>
11 * Cursor enable/disable by Rodolfo Giometti <giometti@linux.it>
13 * Copyright 2002 MontaVista Software
14 * Author: MontaVista Software, Inc.
15 * ppopov@mvista.com or source@mvista.com
17 * Copyright 2002 Alchemy Semiconductor
18 * Author: Alchemy Semiconductor
21 * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
22 * Created 28 Dec 1997 by Geert Uytterhoeven
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the
26 * Free Software Foundation; either version 2 of the License, or (at your
27 * option) any later version.
29 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
32 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
35 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
36 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * You should have received a copy of the GNU General Public License along
41 * with this program; if not, write to the Free Software Foundation, Inc.,
42 * 675 Mass Ave, Cambridge, MA 02139, USA.
44 #include <linux/clk.h>
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/errno.h>
48 #include <linux/string.h>
51 #include <linux/init.h>
52 #include <linux/interrupt.h>
53 #include <linux/ctype.h>
54 #include <linux/dma-mapping.h>
55 #include <linux/platform_device.h>
56 #include <linux/slab.h>
58 #include <asm/mach-au1x00/au1000.h>
64 #define DRIVER_NAME "au1100fb"
65 #define DRIVER_DESC "LCD controller driver for AU1100 processors"
67 #define to_au1100fb_device(_info) \
68 (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
70 /* Bitfields format supported by the controller. Note that the order of formats
71 * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
72 * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
74 struct fb_bitfield rgb_bitfields[][4] =
76 /* Red, Green, Blue, Transp */
77 { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
78 { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
79 { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
80 { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
81 { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
83 /* The last is used to describe 12bpp format */
84 { { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
87 static struct fb_fix_screeninfo au1100fb_fix = {
91 .type = FB_TYPE_PACKED_PIXELS,
92 .accel = FB_ACCEL_NONE,
95 static struct fb_var_screeninfo au1100fb_var = {
96 .activate = FB_ACTIVATE_NOW,
99 .vmode = FB_VMODE_NONINTERLACED,
103 * Blank the screen. Depending on the mode, the screen will be
104 * activated with the backlight color, or desactivated
106 static int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
108 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
110 print_dbg("fb_blank %d %p", blank_mode, fbi);
112 switch (blank_mode) {
114 case VESA_NO_BLANKING:
116 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
117 wmb(); /* drain writebuffer */
120 case VESA_VSYNC_SUSPEND:
121 case VESA_HSYNC_SUSPEND:
124 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
125 wmb(); /* drain writebuffer */
135 * Set hardware with var settings. This will enable the controller with a specific
136 * mode, normally validated with the fb_check_var method
138 int au1100fb_setmode(struct au1100fb_device *fbdev)
140 struct fb_info *info = &fbdev->info;
147 /* Update var-dependent FB info */
148 if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
149 if (info->var.bits_per_pixel <= 8) {
151 info->var.red.offset = 0;
152 info->var.red.length = info->var.bits_per_pixel;
153 info->var.red.msb_right = 0;
155 info->var.green.offset = 0;
156 info->var.green.length = info->var.bits_per_pixel;
157 info->var.green.msb_right = 0;
159 info->var.blue.offset = 0;
160 info->var.blue.length = info->var.bits_per_pixel;
161 info->var.blue.msb_right = 0;
163 info->var.transp.offset = 0;
164 info->var.transp.length = 0;
165 info->var.transp.msb_right = 0;
167 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
168 info->fix.line_length = info->var.xres_virtual /
169 (8/info->var.bits_per_pixel);
172 index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
173 info->var.red = rgb_bitfields[index][0];
174 info->var.green = rgb_bitfields[index][1];
175 info->var.blue = rgb_bitfields[index][2];
176 info->var.transp = rgb_bitfields[index][3];
178 info->fix.visual = FB_VISUAL_TRUECOLOR;
179 info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
183 info->fix.visual = FB_VISUAL_MONO10;
184 info->fix.line_length = info->var.xres_virtual / 8;
187 info->screen_size = info->fix.line_length * info->var.yres_virtual;
188 info->var.rotate = ((fbdev->panel->control_base&LCD_CONTROL_SM_MASK) \
189 >> LCD_CONTROL_SM_BIT) * 90;
191 /* Determine BPP mode and format */
192 fbdev->regs->lcd_control = fbdev->panel->control_base;
193 fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
194 fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
195 fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
196 fbdev->regs->lcd_intenable = 0;
197 fbdev->regs->lcd_intstatus = 0;
198 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
200 if (panel_is_dual(fbdev->panel)) {
201 /* Second panel display seconf half of screen if possible,
202 * otherwise display the same as the first panel */
203 if (info->var.yres_virtual >= (info->var.yres << 1)) {
204 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
205 (info->fix.line_length *
206 (info->var.yres_virtual >> 1)));
208 fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
212 words = info->fix.line_length / sizeof(u32);
213 if (!info->var.rotate || (info->var.rotate == 180)) {
214 words *= info->var.yres_virtual;
215 if (info->var.rotate /* 180 */) {
216 words -= (words % 8); /* should be divisable by 8 */
219 fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
221 fbdev->regs->lcd_pwmdiv = 0;
222 fbdev->regs->lcd_pwmhi = 0;
224 /* Resume controller */
225 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
227 au1100fb_fb_blank(VESA_NO_BLANKING, info);
233 * Set color in LCD palette.
235 int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
237 struct au1100fb_device *fbdev;
241 fbdev = to_au1100fb_device(fbi);
242 palette = fbdev->regs->lcd_pallettebase;
244 if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
247 if (fbi->var.grayscale) {
248 /* Convert color to grayscale */
250 (19595 * red + 38470 * green + 7471 * blue) >> 16;
253 if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
254 /* Place color in the pseudopalette */
258 palette = (u32*)fbi->pseudo_palette;
260 red >>= (16 - fbi->var.red.length);
261 green >>= (16 - fbi->var.green.length);
262 blue >>= (16 - fbi->var.blue.length);
264 value = (red << fbi->var.red.offset) |
265 (green << fbi->var.green.offset)|
266 (blue << fbi->var.blue.offset);
269 } else if (panel_is_active(fbdev->panel)) {
270 /* COLOR TFT PALLETTIZED (use RGB 565) */
271 value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
274 } else if (panel_is_color(fbdev->panel)) {
276 value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
277 ((green >> 8) & 0x00F0) |
278 (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
281 /* MONOCHROME MODE */
282 value = (green >> 12) & 0x000F;
286 palette[regno] = value;
292 * Pan display in x and/or y as specified
294 int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
296 struct au1100fb_device *fbdev;
299 fbdev = to_au1100fb_device(fbi);
301 print_dbg("fb_pan_display %p %p", var, fbi);
303 if (!var || !fbdev) {
307 if (var->xoffset - fbi->var.xoffset) {
308 /* No support for X panning for now! */
312 print_dbg("fb_pan_display 2 %p %p", var, fbi);
313 dy = var->yoffset - fbi->var.yoffset;
318 print_dbg("Panning screen of %d lines", dy);
320 dmaaddr = fbdev->regs->lcd_dmaaddr0;
321 dmaaddr += (fbi->fix.line_length * dy);
323 /* TODO: Wait for current frame to finished */
324 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
326 if (panel_is_dual(fbdev->panel)) {
327 dmaaddr = fbdev->regs->lcd_dmaaddr1;
328 dmaaddr += (fbi->fix.line_length * dy);
329 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
332 print_dbg("fb_pan_display 3 %p %p", var, fbi);
338 * Rotate the display of this angle. This doesn't seems to be used by the core,
339 * but as our hardware supports it, so why not implementing it...
341 void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
343 struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
345 print_dbg("fb_rotate %p %d", fbi, angle);
347 if (fbdev && (angle > 0) && !(angle % 90)) {
349 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
351 fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
352 fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
354 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
359 * Map video memory in user space. We don't use the generic fb_mmap method mainly
360 * to allow the use of the TLB streaming flag (CCA=6)
362 int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
364 struct au1100fb_device *fbdev;
366 fbdev = to_au1100fb_device(fbi);
368 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
369 pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
371 return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
374 static struct fb_ops au1100fb_ops =
376 .owner = THIS_MODULE,
377 .fb_setcolreg = au1100fb_fb_setcolreg,
378 .fb_blank = au1100fb_fb_blank,
379 .fb_pan_display = au1100fb_fb_pan_display,
380 .fb_fillrect = cfb_fillrect,
381 .fb_copyarea = cfb_copyarea,
382 .fb_imageblit = cfb_imageblit,
383 .fb_rotate = au1100fb_fb_rotate,
384 .fb_mmap = au1100fb_fb_mmap,
388 /*-------------------------------------------------------------------------*/
390 static int au1100fb_setup(struct au1100fb_device *fbdev)
392 char *this_opt, *options;
393 int num_panels = ARRAY_SIZE(known_lcd_panels);
395 if (num_panels <= 0) {
396 print_err("No LCD panels supported by driver!");
400 if (fb_get_options(DRIVER_NAME, &options))
405 while ((this_opt = strsep(&options, ",")) != NULL) {
407 if (!strncmp(this_opt, "panel:", 6)) {
410 for (i = 0; i < num_panels; i++) {
411 if (!strncmp(this_opt, known_lcd_panels[i].name,
413 fbdev->panel = &known_lcd_panels[i];
414 fbdev->panel_idx = i;
418 if (i >= num_panels) {
419 print_warn("Panel '%s' not supported!", this_opt);
423 /* Unsupported option */
425 print_warn("Unsupported option \"%s\"", this_opt);
428 print_info("Panel=%s", fbdev->panel->name);
433 static int au1100fb_drv_probe(struct platform_device *dev)
435 struct au1100fb_device *fbdev = NULL;
436 struct resource *regs_res;
440 /* Allocate new device private */
441 fbdev = devm_kzalloc(&dev->dev, sizeof(struct au1100fb_device),
444 print_err("fail to allocate device private record");
448 if (au1100fb_setup(fbdev))
451 platform_set_drvdata(dev, (void *)fbdev);
453 /* Allocate region for our registers and map them */
454 regs_res = platform_get_resource(dev, IORESOURCE_MEM, 0);
456 print_err("fail to retrieve registers resource");
460 au1100fb_fix.mmio_start = regs_res->start;
461 au1100fb_fix.mmio_len = resource_size(regs_res);
463 if (!devm_request_mem_region(&dev->dev,
464 au1100fb_fix.mmio_start,
465 au1100fb_fix.mmio_len,
467 print_err("fail to lock memory region at 0x%08lx",
468 au1100fb_fix.mmio_start);
472 fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
474 print_dbg("Register memory map at %p", fbdev->regs);
475 print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
477 c = clk_get(NULL, "lcd_intclk");
480 clk_set_rate(c, 48000000);
481 clk_prepare_enable(c);
484 /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
485 fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
486 (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
488 fbdev->fb_mem = dmam_alloc_coherent(&dev->dev,
489 PAGE_ALIGN(fbdev->fb_len),
490 &fbdev->fb_phys, GFP_KERNEL);
491 if (!fbdev->fb_mem) {
492 print_err("fail to allocate frambuffer (size: %dK))",
493 fbdev->fb_len / 1024);
497 au1100fb_fix.smem_start = fbdev->fb_phys;
498 au1100fb_fix.smem_len = fbdev->fb_len;
501 * Set page reserved so that mmap will work. This is necessary
502 * since we'll be remapping normal memory.
504 for (page = (unsigned long)fbdev->fb_mem;
505 page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
507 #ifdef CONFIG_DMA_NONCOHERENT
508 SetPageReserved(virt_to_page(CAC_ADDR((void *)page)));
510 SetPageReserved(virt_to_page(page));
514 print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
515 print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
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 fbdev->info.pseudo_palette =
529 devm_kzalloc(&dev->dev, sizeof(u32) * 16, GFP_KERNEL);
530 if (!fbdev->info.pseudo_palette)
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);
539 fbdev->info.var = au1100fb_var;
541 /* Set h/w registers */
542 au1100fb_setmode(fbdev);
544 /* Register new framebuffer */
545 if (register_framebuffer(&fbdev->info) < 0) {
546 print_err("cannot register new framebuffer");
554 clk_disable_unprepare(fbdev->lcdclk);
555 clk_put(fbdev->lcdclk);
558 dma_free_noncoherent(&dev->dev, fbdev->fb_len, fbdev->fb_mem,
561 if (fbdev->info.cmap.len != 0) {
562 fb_dealloc_cmap(&fbdev->info.cmap);
568 int au1100fb_drv_remove(struct platform_device *dev)
570 struct au1100fb_device *fbdev = NULL;
575 fbdev = platform_get_drvdata(dev);
577 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
578 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
580 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
582 /* Clean up all probe data */
583 unregister_framebuffer(&fbdev->info);
585 fb_dealloc_cmap(&fbdev->info.cmap);
588 clk_disable_unprepare(fbdev->lcdclk);
589 clk_put(fbdev->lcdclk);
596 static struct au1100fb_regs fbregs;
598 int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
600 struct au1100fb_device *fbdev = platform_get_drvdata(dev);
606 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
609 clk_disable(fbdev->lcdclk);
611 memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
616 int au1100fb_drv_resume(struct platform_device *dev)
618 struct au1100fb_device *fbdev = platform_get_drvdata(dev);
623 memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
626 clk_enable(fbdev->lcdclk);
628 /* Unblank the LCD */
629 au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
634 #define au1100fb_drv_suspend NULL
635 #define au1100fb_drv_resume NULL
638 static struct platform_driver au1100fb_driver = {
640 .name = "au1100-lcd",
641 .owner = THIS_MODULE,
643 .probe = au1100fb_drv_probe,
644 .remove = au1100fb_drv_remove,
645 .suspend = au1100fb_drv_suspend,
646 .resume = au1100fb_drv_resume,
648 module_platform_driver(au1100fb_driver);
650 MODULE_DESCRIPTION(DRIVER_DESC);
651 MODULE_LICENSE("GPL");