Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[ARM] pxafb: add support for overlay1 and overlay2 as framebuffer devices

PXA27x and later processors support overlay1 and overlay2 on-top of the
base framebuffer (although under-neath the base is also possible). They
support palette and no-palette RGB formats, as well as YUV formats (only
available on overlay2). These overlays have dedicated DMA channels and
behave in a similar way as a framebuffer.

This heavily simplified and re-structured work is based on the original
pxafb_overlay.c (which is pending for mainline merge for a long time).

The major problems with this pxafb_overlay.c are (if you are interested
in the history):

1. heavily redundant (the control logics for overlay1 and overlay2 are
actually identical except for some small operations, which are now
abstracted into a 'pxafb_layer_ops' structure)

2. a lot of useless and un-tested code (two workarounds which are now
fixed on mature silicons)

3. cursorfb is actually useless, hardware cursor should not be used
this way, and the code was actually un-tested for a long time.

The code in this patch should be self-explanatory, I tried to add minimum
comments. As said, this is basically simplified, there are several things
still on the pending list:

1. palette mode is un-supported and un-tested (although re-using the
palette code of the base framebuffer is actually very easy now with
previous clean-up patches)

2. fb_pan_display for overlay(s) is un-supported

3. the base framebuffer can actually be abstracted by 'pxafb_layer' as
well, which will help further re-use of the code and keep a better
and consistent structure. (This is the reason I named it 'pxafb_layer'
instead of 'pxafb_overlay' or something alike)

See Documentation/fb/pxafb.txt for additional usage information.

Signed-off-by: Eric Miao <eric.miao@marvell.com>
Cc: Rodolfo Giometti <giometti@linux.it>
Signed-off-by: Eric Miao <ycmiao@ycmiao-hp520.(none)>

authored by

Eric Miao and committed by
Eric Miao
198fc108 3f16ff60

+516 -16
+84
Documentation/fb/pxafb.txt
··· 56 56 pixclockpol:POLARITY 57 57 pixel clock polarity 58 58 0 => falling edge, 1 => rising edge 59 + 60 + 61 + Overlay Support for PXA27x and later LCD controllers 62 + ==================================================== 63 + 64 + PXA27x and later processors support overlay1 and overlay2 on-top of the 65 + base framebuffer (although under-neath the base is also possible). They 66 + support palette and no-palette RGB formats, as well as YUV formats (only 67 + available on overlay2). These overlays have dedicated DMA channels and 68 + behave in a similar way as a framebuffer. 69 + 70 + However, there are some differences between these overlay framebuffers 71 + and normal framebuffers, as listed below: 72 + 73 + 1. overlay can start at a 32-bit word aligned position within the base 74 + framebuffer, which means they have a start (x, y). This information 75 + is encoded into var->nonstd (no, var->xoffset and var->yoffset are 76 + not for such purpose). 77 + 78 + 2. overlay framebuffer is allocated dynamically according to specified 79 + 'struct fb_var_screeninfo', the amount is decided by: 80 + 81 + var->xres_virtual * var->yres_virtual * bpp 82 + 83 + bpp = 16 -- for RGB565 or RGBT555 84 + = 24 -- for YUV444 packed 85 + = 24 -- for YUV444 planar 86 + = 16 -- for YUV422 planar (1 pixel = 1 Y + 1/2 Cb + 1/2 Cr) 87 + = 12 -- for YUV420 planar (1 pixel = 1 Y + 1/4 Cb + 1/4 Cr) 88 + 89 + NOTE: 90 + 91 + a. overlay does not support panning in x-direction, thus 92 + var->xres_virtual will always be equal to var->xres 93 + 94 + b. line length of overlay(s) must be on a 32-bit word boundary, 95 + for YUV planar modes, it is a requirement for the component 96 + with minimum bits per pixel, e.g. for YUV420, Cr component 97 + for one pixel is actually 2-bits, it means the line length 98 + should be a multiple of 16-pixels 99 + 100 + c. starting horizontal position (XPOS) should start on a 32-bit 101 + word boundary, otherwise the fb_check_var() will just fail. 102 + 103 + d. the rectangle of the overlay should be within the base plane, 104 + otherwise fail 105 + 106 + Applications should follow the sequence below to operate an overlay 107 + framebuffer: 108 + 109 + a. open("/dev/fb[1-2]", ...) 110 + b. ioctl(fd, FBIOGET_VSCREENINFO, ...) 111 + c. modify 'var' with desired parameters: 112 + 1) var->xres and var->yres 113 + 2) larger var->yres_virtual if more memory is required, 114 + usually for double-buffering 115 + 3) var->nonstd for starting (x, y) and color format 116 + 4) var->{red, green, blue, transp} if RGB mode is to be used 117 + d. ioctl(fd, FBIOPUT_VSCREENINFO, ...) 118 + e. ioctl(fd, FBIOGET_FSCREENINFO, ...) 119 + f. mmap 120 + g. ... 121 + 122 + 3. for YUV planar formats, these are actually not supported within the 123 + framebuffer framework, application has to take care of the offsets 124 + and lengths of each component within the framebuffer. 125 + 126 + 4. var->nonstd is used to pass starting (x, y) position and color format, 127 + the detailed bit fields are shown below: 128 + 129 + 31 23 20 10 0 130 + +-----------------+---+----------+----------+ 131 + | ... unused ... |FOR| XPOS | YPOS | 132 + +-----------------+---+----------+----------+ 133 + 134 + FOR - color format, as defined by OVERLAY_FORMAT_* in pxafb.h 135 + 0 - RGB 136 + 1 - YUV444 PACKED 137 + 2 - YUV444 PLANAR 138 + 3 - YUV422 PLANAR 139 + 4 - YUR420 PLANAR 140 + 141 + XPOS - starting horizontal position 142 + YPOS - starting vertical position
+25 -9
arch/arm/mach-pxa/include/mach/regs-lcd.h
··· 12 12 #define LCCR3 (0x00C) /* LCD Controller Control Register 3 */ 13 13 #define LCCR4 (0x010) /* LCD Controller Control Register 4 */ 14 14 #define LCCR5 (0x014) /* LCD Controller Control Register 5 */ 15 - #define LCSR (0x038) /* LCD Controller Status Register */ 15 + #define LCSR (0x038) /* LCD Controller Status Register 0 */ 16 + #define LCSR1 (0x034) /* LCD Controller Status Register 1 */ 16 17 #define LIIDR (0x03C) /* LCD Controller Interrupt ID Register */ 17 18 #define TMEDRGBR (0x040) /* TMED RGB Seed Register */ 18 19 #define TMEDCR (0x044) /* TMED Control Register */ ··· 25 24 #define FBR4 (0x030) /* DMA Channel 2 Frame Branch Register */ 26 25 #define FBR5 (0x110) /* DMA Channel 2 Frame Branch Register */ 27 26 #define FBR6 (0x114) /* DMA Channel 2 Frame Branch Register */ 27 + 28 + #define OVL1C1 (0x050) /* Overlay 1 Control Register 1 */ 29 + #define OVL1C2 (0x060) /* Overlay 1 Control Register 2 */ 30 + #define OVL2C1 (0x070) /* Overlay 2 Control Register 1 */ 31 + #define OVL2C2 (0x080) /* Overlay 2 Control Register 2 */ 28 32 29 33 #define CMDCR (0x100) /* Command Control Register */ 30 34 #define PRSR (0x104) /* Panel Read Status Register */ ··· 48 42 #define LCCR4_PAL_FOR_MASK (3 << 15) 49 43 50 44 #define FDADR0 (0x200) /* DMA Channel 0 Frame Descriptor Address Register */ 51 - #define FSADR0 (0x204) /* DMA Channel 0 Frame Source Address Register */ 52 - #define FIDR0 (0x208) /* DMA Channel 0 Frame ID Register */ 53 - #define LDCMD0 (0x20C) /* DMA Channel 0 Command Register */ 54 45 #define FDADR1 (0x210) /* DMA Channel 1 Frame Descriptor Address Register */ 55 - #define FSADR1 (0x214) /* DMA Channel 1 Frame Source Address Register */ 56 - #define FIDR1 (0x218) /* DMA Channel 1 Frame ID Register */ 57 - #define LDCMD1 (0x21C) /* DMA Channel 1 Command Register */ 46 + #define FDADR2 (0x220) /* DMA Channel 2 Frame Descriptor Address Register */ 47 + #define FDADR3 (0x230) /* DMA Channel 3 Frame Descriptor Address Register */ 48 + #define FDADR4 (0x240) /* DMA Channel 4 Frame Descriptor Address Register */ 49 + #define FDADR5 (0x250) /* DMA Channel 5 Frame Descriptor Address Register */ 58 50 #define FDADR6 (0x260) /* DMA Channel 6 Frame Descriptor Address Register */ 59 - #define FSADR6 (0x264) /* DMA Channel 6 Frame Source Address Register */ 60 - #define FIDR6 (0x268) /* DMA Channel 6 Frame ID Register */ 61 51 62 52 #define LCCR0_ENB (1 << 0) /* LCD Controller enable */ 63 53 #define LCCR0_CMS (1 << 1) /* Color/Monochrome Display Select */ ··· 153 151 #define LCSR_RD_ST (1 << 11) /* read status */ 154 152 #define LCSR_CMD_INT (1 << 12) /* command interrupt */ 155 153 154 + #define LCSR1_IU(x) (1 << ((x) + 23)) /* Input FIFO underrun */ 155 + #define LCSR1_BS(x) (1 << ((x) + 15)) /* Branch Status */ 156 + #define LCSR1_EOF(x) (1 << ((x) + 7)) /* End of Frame Status */ 157 + #define LCSR1_SOF(x) (1 << ((x) - 1)) /* Start of Frame Status */ 158 + 156 159 #define LDCMD_PAL (1 << 26) /* instructs DMA to load palette buffer */ 160 + 161 + /* overlay control registers */ 162 + #define OVLxC1_PPL(x) ((((x) - 1) & 0x3ff) << 0) /* Pixels Per Line */ 163 + #define OVLxC1_LPO(x) ((((x) - 1) & 0x3ff) << 10) /* Number of Lines */ 164 + #define OVLxC1_BPP(x) (((x) & 0xf) << 20) /* Bits Per Pixel */ 165 + #define OVLxC1_OEN (1 << 31) /* Enable bit for Overlay */ 166 + #define OVLxC2_XPOS(x) (((x) & 0x3ff) << 0) /* Horizontal Position */ 167 + #define OVLxC2_YPOS(x) (((x) & 0x3ff) << 10) /* Vertical Position */ 168 + #define OVL2C2_PFOR(x) (((x) & 0x7) << 20) /* Pixel Format */ 157 169 158 170 /* smartpanel related */ 159 171 #define PRSR_DATA(x) ((x) & 0xff) /* Panel Data */
+5
drivers/video/Kconfig
··· 1817 1817 1818 1818 If unsure, say N. 1819 1819 1820 + config FB_PXA_OVERLAY 1821 + bool "Support PXA27x/PXA3xx Overlay(s) as framebuffer" 1822 + default n 1823 + depends on FB_PXA && (PXA27x || PXA3xx) 1824 + 1820 1825 config FB_PXA_SMARTPANEL 1821 1826 bool "PXA Smartpanel LCD support" 1822 1827 default n
+357 -7
drivers/video/pxafb.c
··· 20 20 * 21 21 * linux-arm-kernel@lists.arm.linux.org.uk 22 22 * 23 + * Add support for overlay1 and overlay2 based on pxafb_overlay.c: 24 + * 25 + * Copyright (C) 2004, Intel Corporation 26 + * 27 + * 2003/08/27: <yu.tang@intel.com> 28 + * 2004/03/10: <stanley.cai@intel.com> 29 + * 2004/10/28: <yan.yin@intel.com> 30 + * 31 + * Copyright (C) 2006-2008 Marvell International Ltd. 32 + * All Rights Reserved 23 33 */ 24 34 25 35 #include <linux/module.h> ··· 82 72 struct pxafb_info *); 83 73 static void set_ctrlr_state(struct pxafb_info *fbi, u_int state); 84 74 static void setup_base_frame(struct pxafb_info *fbi, int branch); 75 + static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal, 76 + unsigned long offset, size_t size); 85 77 86 78 static unsigned long video_mem_size = 0; 87 79 ··· 593 581 .fb_blank = pxafb_blank, 594 582 }; 595 583 584 + #ifdef CONFIG_FB_PXA_OVERLAY 585 + static void overlay1fb_setup(struct pxafb_layer *ofb) 586 + { 587 + int size = ofb->fb.fix.line_length * ofb->fb.var.yres_virtual; 588 + unsigned long start = ofb->video_mem_phys; 589 + setup_frame_dma(ofb->fbi, DMA_OV1, PAL_NONE, start, size); 590 + } 591 + 592 + /* Depending on the enable status of overlay1/2, the DMA should be 593 + * updated from FDADRx (when disabled) or FBRx (when enabled). 594 + */ 595 + static void overlay1fb_enable(struct pxafb_layer *ofb) 596 + { 597 + int enabled = lcd_readl(ofb->fbi, OVL1C1) & OVLxC1_OEN; 598 + uint32_t fdadr1 = ofb->fbi->fdadr[DMA_OV1] | (enabled ? 0x1 : 0); 599 + 600 + lcd_writel(ofb->fbi, enabled ? FBR1 : FDADR1, fdadr1); 601 + lcd_writel(ofb->fbi, OVL1C2, ofb->control[1]); 602 + lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] | OVLxC1_OEN); 603 + } 604 + 605 + static void overlay1fb_disable(struct pxafb_layer *ofb) 606 + { 607 + uint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5); 608 + 609 + lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] & ~OVLxC1_OEN); 610 + 611 + lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(1)); 612 + lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(1)); 613 + lcd_writel(ofb->fbi, FBR1, ofb->fbi->fdadr[DMA_OV1] | 0x3); 614 + 615 + if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0) 616 + pr_warning("%s: timeout disabling overlay1\n", __func__); 617 + 618 + lcd_writel(ofb->fbi, LCCR5, lccr5); 619 + } 620 + 621 + static void overlay2fb_setup(struct pxafb_layer *ofb) 622 + { 623 + int size, div = 1, pfor = NONSTD_TO_PFOR(ofb->fb.var.nonstd); 624 + unsigned long start[3] = { ofb->video_mem_phys, 0, 0 }; 625 + 626 + if (pfor == OVERLAY_FORMAT_RGB || pfor == OVERLAY_FORMAT_YUV444_PACKED) { 627 + size = ofb->fb.fix.line_length * ofb->fb.var.yres_virtual; 628 + setup_frame_dma(ofb->fbi, DMA_OV2_Y, -1, start[0], size); 629 + } else { 630 + size = ofb->fb.var.xres_virtual * ofb->fb.var.yres_virtual; 631 + switch (pfor) { 632 + case OVERLAY_FORMAT_YUV444_PLANAR: div = 1; break; 633 + case OVERLAY_FORMAT_YUV422_PLANAR: div = 2; break; 634 + case OVERLAY_FORMAT_YUV420_PLANAR: div = 4; break; 635 + } 636 + start[1] = start[0] + size; 637 + start[2] = start[1] + size / div; 638 + setup_frame_dma(ofb->fbi, DMA_OV2_Y, -1, start[0], size); 639 + setup_frame_dma(ofb->fbi, DMA_OV2_Cb, -1, start[1], size / div); 640 + setup_frame_dma(ofb->fbi, DMA_OV2_Cr, -1, start[2], size / div); 641 + } 642 + } 643 + 644 + static void overlay2fb_enable(struct pxafb_layer *ofb) 645 + { 646 + int pfor = NONSTD_TO_PFOR(ofb->fb.var.nonstd); 647 + int enabled = lcd_readl(ofb->fbi, OVL2C1) & OVLxC1_OEN; 648 + uint32_t fdadr2 = ofb->fbi->fdadr[DMA_OV2_Y] | (enabled ? 0x1 : 0); 649 + uint32_t fdadr3 = ofb->fbi->fdadr[DMA_OV2_Cb] | (enabled ? 0x1 : 0); 650 + uint32_t fdadr4 = ofb->fbi->fdadr[DMA_OV2_Cr] | (enabled ? 0x1 : 0); 651 + 652 + if (pfor == OVERLAY_FORMAT_RGB || pfor == OVERLAY_FORMAT_YUV444_PACKED) 653 + lcd_writel(ofb->fbi, enabled ? FBR2 : FDADR2, fdadr2); 654 + else { 655 + lcd_writel(ofb->fbi, enabled ? FBR2 : FDADR2, fdadr2); 656 + lcd_writel(ofb->fbi, enabled ? FBR3 : FDADR3, fdadr3); 657 + lcd_writel(ofb->fbi, enabled ? FBR4 : FDADR4, fdadr4); 658 + } 659 + lcd_writel(ofb->fbi, OVL2C2, ofb->control[1]); 660 + lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] | OVLxC1_OEN); 661 + } 662 + 663 + static void overlay2fb_disable(struct pxafb_layer *ofb) 664 + { 665 + uint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5); 666 + 667 + lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] & ~OVLxC1_OEN); 668 + 669 + lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(2)); 670 + lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(2)); 671 + lcd_writel(ofb->fbi, FBR2, ofb->fbi->fdadr[DMA_OV2_Y] | 0x3); 672 + lcd_writel(ofb->fbi, FBR3, ofb->fbi->fdadr[DMA_OV2_Cb] | 0x3); 673 + lcd_writel(ofb->fbi, FBR4, ofb->fbi->fdadr[DMA_OV2_Cr] | 0x3); 674 + 675 + if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0) 676 + pr_warning("%s: timeout disabling overlay2\n", __func__); 677 + } 678 + 679 + static struct pxafb_layer_ops ofb_ops[] = { 680 + [0] = { 681 + .enable = overlay1fb_enable, 682 + .disable = overlay1fb_disable, 683 + .setup = overlay1fb_setup, 684 + }, 685 + [1] = { 686 + .enable = overlay2fb_enable, 687 + .disable = overlay2fb_disable, 688 + .setup = overlay2fb_setup, 689 + }, 690 + }; 691 + 692 + static int overlayfb_open(struct fb_info *info, int user) 693 + { 694 + struct pxafb_layer *ofb = (struct pxafb_layer *)info; 695 + 696 + /* no support for framebuffer console on overlay */ 697 + if (user == 0) 698 + return -ENODEV; 699 + 700 + /* allow only one user at a time */ 701 + if (atomic_inc_and_test(&ofb->usage)) 702 + return -EBUSY; 703 + 704 + /* unblank the base framebuffer */ 705 + fb_blank(&ofb->fbi->fb, FB_BLANK_UNBLANK); 706 + return 0; 707 + } 708 + 709 + static int overlayfb_release(struct fb_info *info, int user) 710 + { 711 + struct pxafb_layer *ofb = (struct pxafb_layer*) info; 712 + 713 + atomic_dec(&ofb->usage); 714 + ofb->ops->disable(ofb); 715 + 716 + free_pages_exact(ofb->video_mem, ofb->video_mem_size); 717 + ofb->video_mem = NULL; 718 + ofb->video_mem_size = 0; 719 + return 0; 720 + } 721 + 722 + static int overlayfb_check_var(struct fb_var_screeninfo *var, 723 + struct fb_info *info) 724 + { 725 + struct pxafb_layer *ofb = (struct pxafb_layer *)info; 726 + struct fb_var_screeninfo *base_var = &ofb->fbi->fb.var; 727 + int xpos, ypos, pfor, bpp; 728 + 729 + xpos = NONSTD_TO_XPOS(var->nonstd); 730 + ypos = NONSTD_TO_XPOS(var->nonstd); 731 + pfor = NONSTD_TO_PFOR(var->nonstd); 732 + 733 + bpp = pxafb_var_to_bpp(var); 734 + if (bpp < 0) 735 + return -EINVAL; 736 + 737 + /* no support for YUV format on overlay1 */ 738 + if (ofb->id == OVERLAY1 && pfor != 0) 739 + return -EINVAL; 740 + 741 + /* for YUV packed formats, bpp = 'minimum bpp of YUV components' */ 742 + switch (pfor) { 743 + case OVERLAY_FORMAT_RGB: 744 + bpp = pxafb_var_to_bpp(var); 745 + if (bpp < 0) 746 + return -EINVAL; 747 + 748 + pxafb_set_pixfmt(var, var_to_depth(var)); 749 + break; 750 + case OVERLAY_FORMAT_YUV444_PACKED: bpp = 24; break; 751 + case OVERLAY_FORMAT_YUV444_PLANAR: bpp = 8; break; 752 + case OVERLAY_FORMAT_YUV422_PLANAR: bpp = 4; break; 753 + case OVERLAY_FORMAT_YUV420_PLANAR: bpp = 2; break; 754 + default: 755 + return -EINVAL; 756 + } 757 + 758 + /* each line must start at a 32-bit word boundary */ 759 + if ((xpos * bpp) % 32) 760 + return -EINVAL; 761 + 762 + /* xres must align on 32-bit word boundary */ 763 + var->xres = roundup(var->xres * bpp, 32) / bpp; 764 + 765 + if ((xpos + var->xres > base_var->xres) || 766 + (ypos + var->yres > base_var->yres)) 767 + return -EINVAL; 768 + 769 + var->xres_virtual = var->xres; 770 + var->yres_virtual = max(var->yres, var->yres_virtual); 771 + return 0; 772 + } 773 + 774 + static int overlayfb_map_video_memory(struct pxafb_layer *ofb) 775 + { 776 + struct fb_var_screeninfo *var = &ofb->fb.var; 777 + int pfor = NONSTD_TO_PFOR(var->nonstd); 778 + int size, bpp = 0; 779 + 780 + switch (pfor) { 781 + case OVERLAY_FORMAT_RGB: bpp = var->bits_per_pixel; break; 782 + case OVERLAY_FORMAT_YUV444_PACKED: bpp = 24; break; 783 + case OVERLAY_FORMAT_YUV444_PLANAR: bpp = 24; break; 784 + case OVERLAY_FORMAT_YUV422_PLANAR: bpp = 16; break; 785 + case OVERLAY_FORMAT_YUV420_PLANAR: bpp = 12; break; 786 + } 787 + 788 + ofb->fb.fix.line_length = var->xres_virtual * bpp / 8; 789 + 790 + size = PAGE_ALIGN(ofb->fb.fix.line_length * var->yres_virtual); 791 + 792 + /* don't re-allocate if the original video memory is enough */ 793 + if (ofb->video_mem) { 794 + if (ofb->video_mem_size >= size) 795 + return 0; 796 + 797 + free_pages_exact(ofb->video_mem, ofb->video_mem_size); 798 + } 799 + 800 + ofb->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO); 801 + if (ofb->video_mem == NULL) 802 + return -ENOMEM; 803 + 804 + ofb->video_mem_phys = virt_to_phys(ofb->video_mem); 805 + ofb->video_mem_size = size; 806 + 807 + ofb->fb.fix.smem_start = ofb->video_mem_phys; 808 + ofb->fb.fix.smem_len = ofb->fb.fix.line_length * var->yres_virtual; 809 + ofb->fb.screen_base = ofb->video_mem; 810 + return 0; 811 + } 812 + 813 + static int overlayfb_set_par(struct fb_info *info) 814 + { 815 + struct pxafb_layer *ofb = (struct pxafb_layer *)info; 816 + struct fb_var_screeninfo *var = &info->var; 817 + int xpos, ypos, pfor, bpp, ret; 818 + 819 + ret = overlayfb_map_video_memory(ofb); 820 + if (ret) 821 + return ret; 822 + 823 + bpp = pxafb_var_to_bpp(var); 824 + xpos = NONSTD_TO_XPOS(var->nonstd); 825 + ypos = NONSTD_TO_XPOS(var->nonstd); 826 + pfor = NONSTD_TO_PFOR(var->nonstd); 827 + 828 + ofb->control[0] = OVLxC1_PPL(var->xres) | OVLxC1_LPO(var->yres) | 829 + OVLxC1_BPP(bpp); 830 + ofb->control[1] = OVLxC2_XPOS(xpos) | OVLxC2_YPOS(ypos); 831 + 832 + if (ofb->id == OVERLAY2) 833 + ofb->control[1] |= OVL2C2_PFOR(pfor); 834 + 835 + ofb->ops->setup(ofb); 836 + ofb->ops->enable(ofb); 837 + return 0; 838 + } 839 + 840 + static struct fb_ops overlay_fb_ops = { 841 + .owner = THIS_MODULE, 842 + .fb_open = overlayfb_open, 843 + .fb_release = overlayfb_release, 844 + .fb_check_var = overlayfb_check_var, 845 + .fb_set_par = overlayfb_set_par, 846 + }; 847 + 848 + static void __devinit init_pxafb_overlay(struct pxafb_info *fbi, 849 + struct pxafb_layer *ofb, int id) 850 + { 851 + sprintf(ofb->fb.fix.id, "overlay%d", id + 1); 852 + 853 + ofb->fb.fix.type = FB_TYPE_PACKED_PIXELS; 854 + ofb->fb.fix.xpanstep = 0; 855 + ofb->fb.fix.ypanstep = 1; 856 + 857 + ofb->fb.var.activate = FB_ACTIVATE_NOW; 858 + ofb->fb.var.height = -1; 859 + ofb->fb.var.width = -1; 860 + ofb->fb.var.vmode = FB_VMODE_NONINTERLACED; 861 + 862 + ofb->fb.fbops = &overlay_fb_ops; 863 + ofb->fb.flags = FBINFO_FLAG_DEFAULT; 864 + ofb->fb.node = -1; 865 + ofb->fb.pseudo_palette = NULL; 866 + 867 + ofb->id = id; 868 + ofb->ops = &ofb_ops[id]; 869 + atomic_set(&ofb->usage, 0); 870 + ofb->fbi = fbi; 871 + init_completion(&ofb->branch_done); 872 + } 873 + 874 + static int __devinit pxafb_overlay_init(struct pxafb_info *fbi) 875 + { 876 + int i, ret; 877 + 878 + for (i = 0; i < 2; i++) { 879 + init_pxafb_overlay(fbi, &fbi->overlay[i], i); 880 + ret = register_framebuffer(&fbi->overlay[i].fb); 881 + if (ret) { 882 + dev_err(fbi->dev, "failed to register overlay %d\n", i); 883 + return ret; 884 + } 885 + } 886 + 887 + /* mask all IU/BS/EOF/SOF interrupts */ 888 + lcd_writel(fbi, LCCR5, ~0); 889 + 890 + /* place overlay(s) on top of base */ 891 + fbi->lccr0 |= LCCR0_OUC; 892 + pr_info("PXA Overlay driver loaded successfully!\n"); 893 + return 0; 894 + } 895 + 896 + static void __devexit pxafb_overlay_exit(struct pxafb_info *fbi) 897 + { 898 + int i; 899 + 900 + for (i = 0; i < 2; i++) 901 + unregister_framebuffer(&fbi->overlay[i].fb); 902 + } 903 + #else 904 + static inline void pxafb_overlay_init(struct pxafb_info *fbi) {} 905 + static inline void pxafb_overlay_exit(struct pxafb_info *fbi) {} 906 + #endif /* CONFIG_FB_PXA_OVERLAY */ 907 + 596 908 /* 597 909 * Calculate the PCD value from the clock rate (in picoseconds). 598 910 * We take account of the PPCR clock setting. ··· 996 660 EXPORT_SYMBOL(pxafb_get_hsync_time); 997 661 998 662 static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal, 999 - unsigned int offset, size_t size) 663 + unsigned long start, size_t size) 1000 664 { 1001 665 struct pxafb_dma_descriptor *dma_desc, *pal_desc; 1002 666 unsigned int dma_desc_off, pal_desc_off; ··· 1007 671 dma_desc = &fbi->dma_buff->dma_desc[dma]; 1008 672 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]); 1009 673 1010 - dma_desc->fsadr = fbi->video_mem_phys + offset; 674 + dma_desc->fsadr = start; 1011 675 dma_desc->fidr = 0; 1012 676 dma_desc->ldcmd = size; 1013 677 ··· 1041 705 { 1042 706 struct fb_var_screeninfo *var = &fbi->fb.var; 1043 707 struct fb_fix_screeninfo *fix = &fbi->fb.fix; 1044 - unsigned int nbytes, offset; 1045 - int dma, pal, bpp = var->bits_per_pixel; 708 + int nbytes, dma, pal, bpp = var->bits_per_pixel; 709 + unsigned long offset; 1046 710 1047 711 dma = DMA_BASE + (branch ? DMA_MAX : 0); 1048 712 pal = (bpp >= 16) ? PAL_NONE : PAL_BASE + (branch ? PAL_MAX : 0); 1049 713 1050 714 nbytes = fix->line_length * var->yres; 1051 - offset = fix->line_length * var->yoffset; 715 + offset = fix->line_length * var->yoffset + fbi->video_mem_phys; 1052 716 1053 717 if (fbi->lccr0 & LCCR0_SDS) { 1054 718 nbytes = nbytes / 2; ··· 1426 1090 static irqreturn_t pxafb_handle_irq(int irq, void *dev_id) 1427 1091 { 1428 1092 struct pxafb_info *fbi = dev_id; 1429 - unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR); 1093 + unsigned int lccr0, lcsr, lcsr1; 1430 1094 1095 + lcsr = lcd_readl(fbi, LCSR); 1431 1096 if (lcsr & LCSR_LDD) { 1432 1097 lccr0 = lcd_readl(fbi, LCCR0); 1433 1098 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM); ··· 1439 1102 if (lcsr & LCSR_CMD_INT) 1440 1103 complete(&fbi->command_done); 1441 1104 #endif 1442 - 1443 1105 lcd_writel(fbi, LCSR, lcsr); 1106 + 1107 + #ifdef CONFIG_FB_PXA_OVERLAY 1108 + lcsr1 = lcd_readl(fbi, LCSR1); 1109 + if (lcsr1 & LCSR1_BS(1)) 1110 + complete(&fbi->overlay[0].branch_done); 1111 + 1112 + if (lcsr1 & LCSR1_BS(2)) 1113 + complete(&fbi->overlay[1].branch_done); 1114 + 1115 + lcd_writel(fbi, LCSR1, lcsr1); 1116 + #endif 1444 1117 return IRQ_HANDLED; 1445 1118 } 1446 1119 ··· 2149 1802 goto failed_free_cmap; 2150 1803 } 2151 1804 1805 + pxafb_overlay_init(fbi); 1806 + 2152 1807 #ifdef CONFIG_CPU_FREQ 2153 1808 fbi->freq_transition.notifier_call = pxafb_freq_transition; 2154 1809 fbi->freq_policy.notifier_call = pxafb_freq_policy; ··· 2201 1852 2202 1853 info = &fbi->fb; 2203 1854 1855 + pxafb_overlay_exit(fbi); 2204 1856 unregister_framebuffer(info); 2205 1857 2206 1858 pxafb_disable_controller(fbi);
+45
drivers/video/pxafb.h
··· 64 64 struct pxafb_dma_descriptor dma_desc[DMA_MAX * 2]; 65 65 }; 66 66 67 + enum { 68 + OVERLAY1, 69 + OVERLAY2, 70 + }; 71 + 72 + enum { 73 + OVERLAY_FORMAT_RGB = 0, 74 + OVERLAY_FORMAT_YUV444_PACKED, 75 + OVERLAY_FORMAT_YUV444_PLANAR, 76 + OVERLAY_FORMAT_YUV422_PLANAR, 77 + OVERLAY_FORMAT_YUV420_PLANAR, 78 + }; 79 + 80 + #define NONSTD_TO_XPOS(x) (((x) >> 0) & 0x3ff) 81 + #define NONSTD_TO_YPOS(x) (((x) >> 10) & 0x3ff) 82 + #define NONSTD_TO_PFOR(x) (((x) >> 20) & 0x7) 83 + 84 + struct pxafb_layer; 85 + 86 + struct pxafb_layer_ops { 87 + void (*enable)(struct pxafb_layer *); 88 + void (*disable)(struct pxafb_layer *); 89 + void (*setup)(struct pxafb_layer *); 90 + }; 91 + 92 + struct pxafb_layer { 93 + struct fb_info fb; 94 + int id; 95 + atomic_t usage; 96 + uint32_t control[2]; 97 + 98 + struct pxafb_layer_ops *ops; 99 + 100 + void __iomem *video_mem; 101 + unsigned long video_mem_phys; 102 + size_t video_mem_size; 103 + struct completion branch_done; 104 + 105 + struct pxafb_info *fbi; 106 + }; 107 + 67 108 struct pxafb_info { 68 109 struct fb_info fb; 69 110 struct device *dev; ··· 153 112 struct completion command_done; 154 113 struct completion refresh_done; 155 114 struct task_struct *smart_thread; 115 + #endif 116 + 117 + #ifdef CONFIG_FB_PXA_OVERLAY 118 + struct pxafb_layer overlay[2]; 156 119 #endif 157 120 158 121 #ifdef CONFIG_CPU_FREQ