2 * Copyright (C) 2008-2009 MontaVista Software Inc.
3 * Copyright (C) 2008-2009 Texas Instruments Inc
5 * Based on the LCD driver for TI Avalanche processors written by
6 * Ajay Singh and Shalom Hai.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option)any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/module.h>
23 #include <linux/kernel.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/device.h>
27 #include <linux/platform_device.h>
28 #include <linux/uaccess.h>
29 #include <linux/interrupt.h>
30 #include <linux/clk.h>
31 #include <video/da8xx-fb.h>
33 #define DRIVER_NAME "da8xx_lcdc"
35 /* LCD Status Register */
36 #define LCD_END_OF_FRAME0 BIT(8)
37 #define LCD_FIFO_UNDERFLOW BIT(5)
38 #define LCD_SYNC_LOST BIT(2)
40 /* LCD DMA Control Register */
41 #define LCD_DMA_BURST_SIZE(x) ((x) << 4)
42 #define LCD_DMA_BURST_1 0x0
43 #define LCD_DMA_BURST_2 0x1
44 #define LCD_DMA_BURST_4 0x2
45 #define LCD_DMA_BURST_8 0x3
46 #define LCD_DMA_BURST_16 0x4
47 #define LCD_END_OF_FRAME_INT_ENA BIT(2)
48 #define LCD_DUAL_FRAME_BUFFER_ENABLE BIT(0)
50 /* LCD Control Register */
51 #define LCD_CLK_DIVISOR(x) ((x) << 8)
52 #define LCD_RASTER_MODE 0x01
54 /* LCD Raster Control Register */
55 #define LCD_PALETTE_LOAD_MODE(x) ((x) << 20)
56 #define PALETTE_AND_DATA 0x00
57 #define PALETTE_ONLY 0x01
59 #define LCD_MONO_8BIT_MODE BIT(9)
60 #define LCD_RASTER_ORDER BIT(8)
61 #define LCD_TFT_MODE BIT(7)
62 #define LCD_UNDERFLOW_INT_ENA BIT(6)
63 #define LCD_MONOCHROME_MODE BIT(1)
64 #define LCD_RASTER_ENABLE BIT(0)
65 #define LCD_TFT_ALT_ENABLE BIT(23)
66 #define LCD_STN_565_ENABLE BIT(24)
68 /* LCD Raster Timing 2 Register */
69 #define LCD_AC_BIAS_TRANSITIONS_PER_INT(x) ((x) << 16)
70 #define LCD_AC_BIAS_FREQUENCY(x) ((x) << 8)
71 #define LCD_SYNC_CTRL BIT(25)
72 #define LCD_SYNC_EDGE BIT(24)
73 #define LCD_INVERT_PIXEL_CLOCK BIT(22)
74 #define LCD_INVERT_LINE_CLOCK BIT(21)
75 #define LCD_INVERT_FRAME_CLOCK BIT(20)
78 #define LCD_CTRL_REG 0x4
79 #define LCD_STAT_REG 0x8
80 #define LCD_RASTER_CTRL_REG 0x28
81 #define LCD_RASTER_TIMING_0_REG 0x2C
82 #define LCD_RASTER_TIMING_1_REG 0x30
83 #define LCD_RASTER_TIMING_2_REG 0x34
84 #define LCD_DMA_CTRL_REG 0x40
85 #define LCD_DMA_FRM_BUF_BASE_ADDR_0_REG 0x44
86 #define LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG 0x48
88 #define WSI_TIMEOUT 50
89 #define PALETTE_SIZE 256
90 #define LEFT_MARGIN 64
91 #define RIGHT_MARGIN 64
92 #define UPPER_MARGIN 32
93 #define LOWER_MARGIN 32
95 static resource_size_t da8xx_fb_reg_base
;
96 static struct resource
*lcdc_regs
;
98 static inline unsigned int lcdc_read(unsigned int addr
)
100 return (unsigned int)__raw_readl(da8xx_fb_reg_base
+ (addr
));
103 static inline void lcdc_write(unsigned int val
, unsigned int addr
)
105 __raw_writel(val
, da8xx_fb_reg_base
+ (addr
));
108 struct da8xx_fb_par
{
109 resource_size_t p_palette_base
;
110 unsigned char *v_palette_base
;
111 struct clk
*lcdc_clk
;
113 unsigned short pseudo_palette
[16];
114 unsigned int databuf_sz
;
115 unsigned int palette_sz
;
118 /* Variable Screen Information */
119 static struct fb_var_screeninfo da8xx_fb_var __devinitdata
= {
127 .pixclock
= 46666, /* 46us - AUO display */
129 .left_margin
= LEFT_MARGIN
,
130 .right_margin
= RIGHT_MARGIN
,
131 .upper_margin
= UPPER_MARGIN
,
132 .lower_margin
= LOWER_MARGIN
,
134 .vmode
= FB_VMODE_NONINTERLACED
137 static struct fb_fix_screeninfo da8xx_fb_fix __devinitdata
= {
138 .id
= "DA8xx FB Drv",
139 .type
= FB_TYPE_PACKED_PIXELS
,
141 .visual
= FB_VISUAL_PSEUDOCOLOR
,
145 .accel
= FB_ACCEL_NONE
149 const char name
[25]; /* Full name <vendor>_<model> */
150 unsigned short width
;
151 unsigned short height
;
152 int hfp
; /* Horizontal front porch */
153 int hbp
; /* Horizontal back porch */
154 int hsw
; /* Horizontal Sync Pulse Width */
155 int vfp
; /* Vertical front porch */
156 int vbp
; /* Vertical back porch */
157 int vsw
; /* Vertical Sync Pulse Width */
158 int pxl_clk
; /* Pixel clock */
159 unsigned char invert_pxl_clk
; /* Invert Pixel clock */
162 static struct da8xx_panel known_lcd_panels
[] = {
163 /* Sharp LCD035Q3DG01 */
165 .name
= "Sharp_LCD035Q3DG01",
177 /* Sharp LK043T1DG01 */
179 .name
= "Sharp_LK043T1DG01",
193 /* Disable the Raster Engine of the LCD Controller */
194 static void lcd_disable_raster(struct da8xx_fb_par
*par
)
198 reg
= lcdc_read(LCD_RASTER_CTRL_REG
);
199 if (reg
& LCD_RASTER_ENABLE
)
200 lcdc_write(reg
& ~LCD_RASTER_ENABLE
, LCD_RASTER_CTRL_REG
);
203 static void lcd_blit(int load_mode
, struct da8xx_fb_par
*par
)
205 u32 tmp
= par
->p_palette_base
+ par
->databuf_sz
- 4;
208 /* Update the databuf in the hw. */
209 lcdc_write(par
->p_palette_base
, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG
);
210 lcdc_write(tmp
, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG
);
213 reg
= lcdc_read(LCD_RASTER_CTRL_REG
);
215 if (load_mode
== LOAD_DATA
)
216 reg
|= LCD_PALETTE_LOAD_MODE(PALETTE_AND_DATA
);
217 else if (load_mode
== LOAD_PALETTE
)
218 reg
|= LCD_PALETTE_LOAD_MODE(PALETTE_ONLY
);
220 lcdc_write(reg
, LCD_RASTER_CTRL_REG
);
223 /* Configure the Burst Size of DMA */
224 static int lcd_cfg_dma(int burst_size
)
228 reg
= lcdc_read(LCD_DMA_CTRL_REG
) & 0x00000001;
229 switch (burst_size
) {
231 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_1
);
234 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_2
);
237 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_4
);
240 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_8
);
243 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_16
);
248 lcdc_write(reg
, LCD_DMA_CTRL_REG
);
253 static void lcd_cfg_ac_bias(int period
, int transitions_per_int
)
257 /* Set the AC Bias Period and Number of Transisitons per Interrupt */
258 reg
= lcdc_read(LCD_RASTER_TIMING_2_REG
) & 0xFFF00000;
259 reg
|= LCD_AC_BIAS_FREQUENCY(period
) |
260 LCD_AC_BIAS_TRANSITIONS_PER_INT(transitions_per_int
);
261 lcdc_write(reg
, LCD_RASTER_TIMING_2_REG
);
264 static void lcd_cfg_horizontal_sync(int back_porch
, int pulse_width
,
269 reg
= lcdc_read(LCD_RASTER_TIMING_0_REG
) & 0xf;
270 reg
|= ((back_porch
& 0xff) << 24)
271 | ((front_porch
& 0xff) << 16)
272 | ((pulse_width
& 0x3f) << 10);
273 lcdc_write(reg
, LCD_RASTER_TIMING_0_REG
);
276 static void lcd_cfg_vertical_sync(int back_porch
, int pulse_width
,
281 reg
= lcdc_read(LCD_RASTER_TIMING_1_REG
) & 0x3ff;
282 reg
|= ((back_porch
& 0xff) << 24)
283 | ((front_porch
& 0xff) << 16)
284 | ((pulse_width
& 0x3f) << 10);
285 lcdc_write(reg
, LCD_RASTER_TIMING_1_REG
);
288 static int lcd_cfg_display(const struct lcd_ctrl_config
*cfg
)
292 reg
= lcdc_read(LCD_RASTER_CTRL_REG
) & ~(LCD_TFT_MODE
|
294 LCD_MONOCHROME_MODE
);
296 switch (cfg
->p_disp_panel
->panel_shade
) {
298 reg
|= LCD_MONOCHROME_MODE
;
299 if (cfg
->mono_8bit_mode
)
300 reg
|= LCD_MONO_8BIT_MODE
;
304 if (cfg
->tft_alt_mode
)
305 reg
|= LCD_TFT_ALT_ENABLE
;
309 if (cfg
->stn_565_mode
)
310 reg
|= LCD_STN_565_ENABLE
;
317 /* enable additional interrupts here */
318 reg
|= LCD_UNDERFLOW_INT_ENA
;
320 lcdc_write(reg
, LCD_RASTER_CTRL_REG
);
322 reg
= lcdc_read(LCD_RASTER_TIMING_2_REG
);
325 reg
|= LCD_SYNC_CTRL
;
327 reg
&= ~LCD_SYNC_CTRL
;
330 reg
|= LCD_SYNC_EDGE
;
332 reg
&= ~LCD_SYNC_EDGE
;
334 if (cfg
->invert_line_clock
)
335 reg
|= LCD_INVERT_LINE_CLOCK
;
337 reg
&= ~LCD_INVERT_LINE_CLOCK
;
339 if (cfg
->invert_frm_clock
)
340 reg
|= LCD_INVERT_FRAME_CLOCK
;
342 reg
&= ~LCD_INVERT_FRAME_CLOCK
;
344 lcdc_write(reg
, LCD_RASTER_TIMING_2_REG
);
349 static int lcd_cfg_frame_buffer(struct da8xx_fb_par
*par
, u32 width
, u32 height
,
350 u32 bpp
, u32 raster_order
)
354 /* Disable Dual Frame Buffer. */
355 reg
= lcdc_read(LCD_DMA_CTRL_REG
);
356 lcdc_write(reg
& ~LCD_DUAL_FRAME_BUFFER_ENABLE
,
358 /* Set the Panel Width */
359 /* Pixels per line = (PPL + 1)*16 */
360 /*0x3F in bits 4..9 gives max horisontal resolution = 1024 pixels*/
362 reg
= lcdc_read(LCD_RASTER_TIMING_0_REG
);
364 reg
|= ((width
>> 4) - 1) << 4;
365 lcdc_write(reg
, LCD_RASTER_TIMING_0_REG
);
367 /* Set the Panel Height */
368 reg
= lcdc_read(LCD_RASTER_TIMING_1_REG
);
369 reg
= ((height
- 1) & 0x3ff) | (reg
& 0xfffffc00);
370 lcdc_write(reg
, LCD_RASTER_TIMING_1_REG
);
372 /* Set the Raster Order of the Frame Buffer */
373 reg
= lcdc_read(LCD_RASTER_CTRL_REG
) & ~(1 << 8);
375 reg
|= LCD_RASTER_ORDER
;
376 lcdc_write(reg
, LCD_RASTER_CTRL_REG
);
383 par
->palette_sz
= 16 * 2;
387 par
->palette_sz
= 256 * 2;
394 bpl
= width
* bpp
/ 8;
395 par
->databuf_sz
= height
* bpl
+ par
->palette_sz
;
400 static int fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
401 unsigned blue
, unsigned transp
,
402 struct fb_info
*info
)
404 struct da8xx_fb_par
*par
= info
->par
;
405 unsigned short *palette
= (unsigned short *)par
->v_palette_base
;
411 if (info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
)
414 if (info
->var
.bits_per_pixel
== 8) {
419 pal
= (red
& 0x0f00);
420 pal
|= (green
& 0x00f0);
421 pal
|= (blue
& 0x000f);
423 palette
[regno
] = pal
;
425 } else if ((info
->var
.bits_per_pixel
== 16) && regno
< 16) {
426 red
>>= (16 - info
->var
.red
.length
);
427 red
<<= info
->var
.red
.offset
;
429 green
>>= (16 - info
->var
.green
.length
);
430 green
<<= info
->var
.green
.offset
;
432 blue
>>= (16 - info
->var
.blue
.length
);
433 blue
<<= info
->var
.blue
.offset
;
435 par
->pseudo_palette
[regno
] = red
| green
| blue
;
443 static void lcd_reset(struct da8xx_fb_par
*par
)
445 /* Disable the Raster if previously Enabled */
446 if (lcdc_read(LCD_RASTER_CTRL_REG
) & LCD_RASTER_ENABLE
)
447 lcd_disable_raster(par
);
449 /* DMA has to be disabled */
450 lcdc_write(0, LCD_DMA_CTRL_REG
);
451 lcdc_write(0, LCD_RASTER_CTRL_REG
);
454 static int lcd_init(struct da8xx_fb_par
*par
, const struct lcd_ctrl_config
*cfg
,
455 struct da8xx_panel
*panel
)
462 /* Configure the LCD clock divisor. */
463 lcdc_write(LCD_CLK_DIVISOR(panel
->pxl_clk
) |
464 (LCD_RASTER_MODE
& 0x1), LCD_CTRL_REG
);
466 if (panel
->invert_pxl_clk
)
467 lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG
) |
468 LCD_INVERT_PIXEL_CLOCK
), LCD_RASTER_TIMING_2_REG
);
470 lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG
) &
471 ~LCD_INVERT_PIXEL_CLOCK
), LCD_RASTER_TIMING_2_REG
);
473 /* Configure the DMA burst size. */
474 ret
= lcd_cfg_dma(cfg
->dma_burst_sz
);
478 /* Configure the AC bias properties. */
479 lcd_cfg_ac_bias(cfg
->ac_bias
, cfg
->ac_bias_intrpt
);
481 /* Configure the vertical and horizontal sync properties. */
482 lcd_cfg_vertical_sync(panel
->vbp
, panel
->vsw
, panel
->vfp
);
483 lcd_cfg_horizontal_sync(panel
->hbp
, panel
->hsw
, panel
->hfp
);
485 /* Configure for disply */
486 ret
= lcd_cfg_display(cfg
);
490 if (QVGA
!= cfg
->p_disp_panel
->panel_type
)
493 if (cfg
->bpp
<= cfg
->p_disp_panel
->max_bpp
&&
494 cfg
->bpp
>= cfg
->p_disp_panel
->min_bpp
)
497 bpp
= cfg
->p_disp_panel
->max_bpp
;
500 ret
= lcd_cfg_frame_buffer(par
, (unsigned int)panel
->width
,
501 (unsigned int)panel
->height
, bpp
,
507 lcdc_write((lcdc_read(LCD_RASTER_CTRL_REG
) & 0xfff00fff) |
508 (cfg
->fdd
<< 12), LCD_RASTER_CTRL_REG
);
513 static irqreturn_t
lcdc_irq_handler(int irq
, void *arg
)
515 u32 stat
= lcdc_read(LCD_STAT_REG
);
518 if ((stat
& LCD_SYNC_LOST
) && (stat
& LCD_FIFO_UNDERFLOW
)) {
519 reg
= lcdc_read(LCD_RASTER_CTRL_REG
);
520 lcdc_write(reg
& ~LCD_RASTER_ENABLE
, LCD_RASTER_CTRL_REG
);
521 lcdc_write(stat
, LCD_STAT_REG
);
522 lcdc_write(reg
| LCD_RASTER_ENABLE
, LCD_RASTER_CTRL_REG
);
524 lcdc_write(stat
, LCD_STAT_REG
);
529 static int fb_check_var(struct fb_var_screeninfo
*var
,
530 struct fb_info
*info
)
534 switch (var
->bits_per_pixel
) {
539 var
->green
.offset
= 0;
540 var
->green
.length
= 8;
541 var
->blue
.offset
= 0;
542 var
->blue
.length
= 8;
543 var
->transp
.offset
= 0;
544 var
->transp
.length
= 0;
549 var
->green
.offset
= 0;
550 var
->green
.length
= 4;
551 var
->blue
.offset
= 0;
552 var
->blue
.length
= 4;
553 var
->transp
.offset
= 0;
554 var
->transp
.length
= 0;
556 case 16: /* RGB 565 */
557 var
->red
.offset
= 11;
559 var
->green
.offset
= 5;
560 var
->green
.length
= 6;
561 var
->blue
.offset
= 0;
562 var
->blue
.length
= 5;
563 var
->transp
.offset
= 0;
564 var
->transp
.length
= 0;
570 var
->red
.msb_right
= 0;
571 var
->green
.msb_right
= 0;
572 var
->blue
.msb_right
= 0;
573 var
->transp
.msb_right
= 0;
577 static int __devexit
fb_remove(struct platform_device
*dev
)
579 struct fb_info
*info
= dev_get_drvdata(&dev
->dev
);
582 struct da8xx_fb_par
*par
= info
->par
;
584 if (lcdc_read(LCD_RASTER_CTRL_REG
) & LCD_RASTER_ENABLE
)
585 lcd_disable_raster(par
);
586 lcdc_write(0, LCD_RASTER_CTRL_REG
);
589 lcdc_write(0, LCD_DMA_CTRL_REG
);
591 unregister_framebuffer(info
);
592 fb_dealloc_cmap(&info
->cmap
);
593 dma_free_coherent(NULL
, par
->databuf_sz
+ PAGE_SIZE
,
594 info
->screen_base
- PAGE_SIZE
,
595 info
->fix
.smem_start
);
596 free_irq(par
->irq
, par
);
597 clk_disable(par
->lcdc_clk
);
598 clk_put(par
->lcdc_clk
);
599 framebuffer_release(info
);
600 iounmap((void __iomem
*)da8xx_fb_reg_base
);
601 release_mem_region(lcdc_regs
->start
, resource_size(lcdc_regs
));
607 static int fb_ioctl(struct fb_info
*info
, unsigned int cmd
,
610 struct lcd_sync_arg sync_arg
;
613 case FBIOGET_CONTRAST
:
614 case FBIOPUT_CONTRAST
:
615 case FBIGET_BRIGHTNESS
:
616 case FBIPUT_BRIGHTNESS
:
621 if (copy_from_user(&sync_arg
, (char *)arg
,
622 sizeof(struct lcd_sync_arg
)))
624 lcd_cfg_horizontal_sync(sync_arg
.back_porch
,
625 sync_arg
.pulse_width
,
626 sync_arg
.front_porch
);
629 if (copy_from_user(&sync_arg
, (char *)arg
,
630 sizeof(struct lcd_sync_arg
)))
632 lcd_cfg_vertical_sync(sync_arg
.back_porch
,
633 sync_arg
.pulse_width
,
634 sync_arg
.front_porch
);
642 static struct fb_ops da8xx_fb_ops
= {
643 .owner
= THIS_MODULE
,
644 .fb_check_var
= fb_check_var
,
645 .fb_setcolreg
= fb_setcolreg
,
646 .fb_ioctl
= fb_ioctl
,
647 .fb_fillrect
= cfb_fillrect
,
648 .fb_copyarea
= cfb_copyarea
,
649 .fb_imageblit
= cfb_imageblit
,
652 static int __init
fb_probe(struct platform_device
*device
)
654 struct da8xx_lcdc_platform_data
*fb_pdata
=
655 device
->dev
.platform_data
;
656 struct lcd_ctrl_config
*lcd_cfg
;
657 struct da8xx_panel
*lcdc_info
;
658 struct fb_info
*da8xx_fb_info
;
659 struct clk
*fb_clk
= NULL
;
660 struct da8xx_fb_par
*par
;
664 if (fb_pdata
== NULL
) {
665 dev_err(&device
->dev
, "Can not get platform data\n");
669 lcdc_regs
= platform_get_resource(device
, IORESOURCE_MEM
, 0);
671 dev_err(&device
->dev
,
672 "Can not get memory resource for LCD controller\n");
676 len
= resource_size(lcdc_regs
);
678 lcdc_regs
= request_mem_region(lcdc_regs
->start
, len
, lcdc_regs
->name
);
682 da8xx_fb_reg_base
= (resource_size_t
)ioremap(lcdc_regs
->start
, len
);
683 if (!da8xx_fb_reg_base
) {
685 goto err_request_mem
;
688 fb_clk
= clk_get(&device
->dev
, NULL
);
689 if (IS_ERR(fb_clk
)) {
690 dev_err(&device
->dev
, "Can not get device clock\n");
694 ret
= clk_enable(fb_clk
);
698 for (i
= 0, lcdc_info
= known_lcd_panels
;
699 i
< ARRAY_SIZE(known_lcd_panels
);
701 if (strcmp(fb_pdata
->type
, lcdc_info
->name
) == 0)
705 if (i
== ARRAY_SIZE(known_lcd_panels
)) {
706 dev_err(&device
->dev
, "GLCD: No valid panel found\n");
708 goto err_clk_disable
;
710 dev_info(&device
->dev
, "GLCD: Found %s panel\n",
713 lcd_cfg
= (struct lcd_ctrl_config
*)fb_pdata
->controller_data
;
715 da8xx_fb_info
= framebuffer_alloc(sizeof(struct da8xx_fb_par
),
717 if (!da8xx_fb_info
) {
718 dev_dbg(&device
->dev
, "Memory allocation failed for fb_info\n");
720 goto err_clk_disable
;
723 par
= da8xx_fb_info
->par
;
725 if (lcd_init(par
, lcd_cfg
, lcdc_info
) < 0) {
726 dev_err(&device
->dev
, "lcd_init failed\n");
731 /* allocate frame buffer */
732 da8xx_fb_info
->screen_base
= dma_alloc_coherent(NULL
,
733 par
->databuf_sz
+ PAGE_SIZE
,
735 &da8xx_fb_info
->fix
.smem_start
,
736 GFP_KERNEL
| GFP_DMA
);
738 if (!da8xx_fb_info
->screen_base
) {
739 dev_err(&device
->dev
,
740 "GLCD: kmalloc for frame buffer failed\n");
745 /* move palette base pointer by (PAGE_SIZE - palette_sz) bytes */
746 par
->v_palette_base
= da8xx_fb_info
->screen_base
+
747 (PAGE_SIZE
- par
->palette_sz
);
748 par
->p_palette_base
= da8xx_fb_info
->fix
.smem_start
+
749 (PAGE_SIZE
- par
->palette_sz
);
751 /* the rest of the frame buffer is pixel data */
752 da8xx_fb_info
->screen_base
= par
->v_palette_base
+ par
->palette_sz
;
753 da8xx_fb_fix
.smem_start
= par
->p_palette_base
+ par
->palette_sz
;
754 da8xx_fb_fix
.smem_len
= par
->databuf_sz
- par
->palette_sz
;
755 da8xx_fb_fix
.line_length
= (lcdc_info
->width
* lcd_cfg
->bpp
) / 8;
757 par
->lcdc_clk
= fb_clk
;
759 par
->irq
= platform_get_irq(device
, 0);
762 goto err_release_fb_mem
;
765 ret
= request_irq(par
->irq
, lcdc_irq_handler
, 0, DRIVER_NAME
, par
);
767 goto err_release_fb_mem
;
770 da8xx_fb_info
->var
.bits_per_pixel
= lcd_cfg
->bpp
;
772 da8xx_fb_var
.xres
= lcdc_info
->width
;
773 da8xx_fb_var
.xres_virtual
= lcdc_info
->width
;
775 da8xx_fb_var
.yres
= lcdc_info
->height
;
776 da8xx_fb_var
.yres_virtual
= lcdc_info
->height
;
778 da8xx_fb_var
.grayscale
=
779 lcd_cfg
->p_disp_panel
->panel_shade
== MONOCHROME
? 1 : 0;
780 da8xx_fb_var
.bits_per_pixel
= lcd_cfg
->bpp
;
782 da8xx_fb_var
.hsync_len
= lcdc_info
->hsw
;
783 da8xx_fb_var
.vsync_len
= lcdc_info
->vsw
;
785 /* Initialize fbinfo */
786 da8xx_fb_info
->flags
= FBINFO_FLAG_DEFAULT
;
787 da8xx_fb_info
->fix
= da8xx_fb_fix
;
788 da8xx_fb_info
->var
= da8xx_fb_var
;
789 da8xx_fb_info
->fbops
= &da8xx_fb_ops
;
790 da8xx_fb_info
->pseudo_palette
= par
->pseudo_palette
;
791 da8xx_fb_info
->fix
.visual
= (da8xx_fb_info
->var
.bits_per_pixel
<= 8) ?
792 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
794 ret
= fb_alloc_cmap(&da8xx_fb_info
->cmap
, PALETTE_SIZE
, 0);
798 /* First palette_sz byte of the frame buffer is the palette */
799 da8xx_fb_info
->cmap
.len
= par
->palette_sz
;
801 /* Flush the buffer to the screen. */
802 lcd_blit(LOAD_DATA
, par
);
804 /* initialize var_screeninfo */
805 da8xx_fb_var
.activate
= FB_ACTIVATE_FORCE
;
806 fb_set_var(da8xx_fb_info
, &da8xx_fb_var
);
808 dev_set_drvdata(&device
->dev
, da8xx_fb_info
);
809 /* Register the Frame Buffer */
810 if (register_framebuffer(da8xx_fb_info
) < 0) {
811 dev_err(&device
->dev
,
812 "GLCD: Frame Buffer Registration Failed!\n");
814 goto err_dealloc_cmap
;
817 /* enable raster engine */
818 lcdc_write(lcdc_read(LCD_RASTER_CTRL_REG
) |
819 LCD_RASTER_ENABLE
, LCD_RASTER_CTRL_REG
);
824 fb_dealloc_cmap(&da8xx_fb_info
->cmap
);
827 free_irq(par
->irq
, par
);
830 dma_free_coherent(NULL
, par
->databuf_sz
+ PAGE_SIZE
,
831 da8xx_fb_info
->screen_base
- PAGE_SIZE
,
832 da8xx_fb_info
->fix
.smem_start
);
835 framebuffer_release(da8xx_fb_info
);
844 iounmap((void __iomem
*)da8xx_fb_reg_base
);
847 release_mem_region(lcdc_regs
->start
, len
);
853 static int fb_suspend(struct platform_device
*dev
, pm_message_t state
)
857 static int fb_resume(struct platform_device
*dev
)
862 #define fb_suspend NULL
863 #define fb_resume NULL
866 static struct platform_driver da8xx_fb_driver
= {
869 .suspend
= fb_suspend
,
873 .owner
= THIS_MODULE
,
877 static int __init
da8xx_fb_init(void)
879 return platform_driver_register(&da8xx_fb_driver
);
882 static void __exit
da8xx_fb_cleanup(void)
884 platform_driver_unregister(&da8xx_fb_driver
);
887 module_init(da8xx_fb_init
);
888 module_exit(da8xx_fb_cleanup
);
890 MODULE_DESCRIPTION("Framebuffer driver for TI da8xx/omap-l1xx");
891 MODULE_AUTHOR("Texas Instruments");
892 MODULE_LICENSE("GPL");