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/pm_runtime.h>
30 #include <linux/interrupt.h>
31 #include <linux/wait.h>
32 #include <linux/clk.h>
33 #include <linux/cpufreq.h>
34 #include <linux/console.h>
35 #include <linux/spinlock.h>
36 #include <linux/slab.h>
37 #include <linux/delay.h>
38 #include <linux/lcm.h>
39 #include <video/da8xx-fb.h>
40 #include <asm/div64.h>
42 #define DRIVER_NAME "da8xx_lcdc"
44 #define LCD_VERSION_1 1
45 #define LCD_VERSION_2 2
47 /* LCD Status Register */
48 #define LCD_END_OF_FRAME1 BIT(9)
49 #define LCD_END_OF_FRAME0 BIT(8)
50 #define LCD_PL_LOAD_DONE BIT(6)
51 #define LCD_FIFO_UNDERFLOW BIT(5)
52 #define LCD_SYNC_LOST BIT(2)
53 #define LCD_FRAME_DONE BIT(0)
55 /* LCD DMA Control Register */
56 #define LCD_DMA_BURST_SIZE(x) ((x) << 4)
57 #define LCD_DMA_BURST_1 0x0
58 #define LCD_DMA_BURST_2 0x1
59 #define LCD_DMA_BURST_4 0x2
60 #define LCD_DMA_BURST_8 0x3
61 #define LCD_DMA_BURST_16 0x4
62 #define LCD_V1_END_OF_FRAME_INT_ENA BIT(2)
63 #define LCD_V2_END_OF_FRAME0_INT_ENA BIT(8)
64 #define LCD_V2_END_OF_FRAME1_INT_ENA BIT(9)
65 #define LCD_DUAL_FRAME_BUFFER_ENABLE BIT(0)
67 /* LCD Control Register */
68 #define LCD_CLK_DIVISOR(x) ((x) << 8)
69 #define LCD_RASTER_MODE 0x01
71 /* LCD Raster Control Register */
72 #define LCD_PALETTE_LOAD_MODE(x) ((x) << 20)
73 #define PALETTE_AND_DATA 0x00
74 #define PALETTE_ONLY 0x01
75 #define DATA_ONLY 0x02
77 #define LCD_MONO_8BIT_MODE BIT(9)
78 #define LCD_RASTER_ORDER BIT(8)
79 #define LCD_TFT_MODE BIT(7)
80 #define LCD_V1_UNDERFLOW_INT_ENA BIT(6)
81 #define LCD_V2_UNDERFLOW_INT_ENA BIT(5)
82 #define LCD_V1_PL_INT_ENA BIT(4)
83 #define LCD_V2_PL_INT_ENA BIT(6)
84 #define LCD_MONOCHROME_MODE BIT(1)
85 #define LCD_RASTER_ENABLE BIT(0)
86 #define LCD_TFT_ALT_ENABLE BIT(23)
87 #define LCD_STN_565_ENABLE BIT(24)
88 #define LCD_V2_DMA_CLK_EN BIT(2)
89 #define LCD_V2_LIDD_CLK_EN BIT(1)
90 #define LCD_V2_CORE_CLK_EN BIT(0)
91 #define LCD_V2_LPP_B10 26
92 #define LCD_V2_TFT_24BPP_MODE BIT(25)
93 #define LCD_V2_TFT_24BPP_UNPACK BIT(26)
95 /* LCD Raster Timing 2 Register */
96 #define LCD_AC_BIAS_TRANSITIONS_PER_INT(x) ((x) << 16)
97 #define LCD_AC_BIAS_FREQUENCY(x) ((x) << 8)
98 #define LCD_SYNC_CTRL BIT(25)
99 #define LCD_SYNC_EDGE BIT(24)
100 #define LCD_INVERT_PIXEL_CLOCK BIT(22)
101 #define LCD_INVERT_LINE_CLOCK BIT(21)
102 #define LCD_INVERT_FRAME_CLOCK BIT(20)
105 #define LCD_PID_REG 0x0
106 #define LCD_CTRL_REG 0x4
107 #define LCD_STAT_REG 0x8
108 #define LCD_RASTER_CTRL_REG 0x28
109 #define LCD_RASTER_TIMING_0_REG 0x2C
110 #define LCD_RASTER_TIMING_1_REG 0x30
111 #define LCD_RASTER_TIMING_2_REG 0x34
112 #define LCD_DMA_CTRL_REG 0x40
113 #define LCD_DMA_FRM_BUF_BASE_ADDR_0_REG 0x44
114 #define LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG 0x48
115 #define LCD_DMA_FRM_BUF_BASE_ADDR_1_REG 0x4C
116 #define LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG 0x50
118 /* Interrupt Registers available only in Version 2 */
119 #define LCD_RAW_STAT_REG 0x58
120 #define LCD_MASKED_STAT_REG 0x5c
121 #define LCD_INT_ENABLE_SET_REG 0x60
122 #define LCD_INT_ENABLE_CLR_REG 0x64
123 #define LCD_END_OF_INT_IND_REG 0x68
125 /* Clock registers available only on Version 2 */
126 #define LCD_CLK_ENABLE_REG 0x6c
127 #define LCD_CLK_RESET_REG 0x70
128 #define LCD_CLK_MAIN_RESET BIT(3)
130 #define LCD_NUM_BUFFERS 2
132 #define WSI_TIMEOUT 50
133 #define PALETTE_SIZE 256
134 #define LEFT_MARGIN 64
135 #define RIGHT_MARGIN 64
136 #define UPPER_MARGIN 32
137 #define LOWER_MARGIN 32
139 static void __iomem
*da8xx_fb_reg_base
;
140 static struct resource
*lcdc_regs
;
141 static unsigned int lcd_revision
;
142 static irq_handler_t lcdc_irq_handler
;
143 static wait_queue_head_t frame_done_wq
;
144 static int frame_done_flag
;
146 static inline unsigned int lcdc_read(unsigned int addr
)
148 return (unsigned int)__raw_readl(da8xx_fb_reg_base
+ (addr
));
151 static inline void lcdc_write(unsigned int val
, unsigned int addr
)
153 __raw_writel(val
, da8xx_fb_reg_base
+ (addr
));
156 struct da8xx_fb_par
{
157 resource_size_t p_palette_base
;
158 unsigned char *v_palette_base
;
159 dma_addr_t vram_phys
;
160 unsigned long vram_size
;
162 unsigned int dma_start
;
163 unsigned int dma_end
;
164 struct clk
*lcdc_clk
;
166 unsigned int palette_sz
;
167 unsigned int pxl_clk
;
169 wait_queue_head_t vsync_wait
;
172 spinlock_t lock_for_chan_update
;
175 * LCDC has 2 ping pong DMA channels, channel 0
178 unsigned int which_dma_channel_done
;
179 #ifdef CONFIG_CPU_FREQ
180 struct notifier_block freq_transition
;
181 unsigned int lcd_fck_rate
;
183 void (*panel_power_ctrl
)(int);
184 u32 pseudo_palette
[16];
187 /* Variable Screen Information */
188 static struct fb_var_screeninfo da8xx_fb_var
= {
197 .left_margin
= LEFT_MARGIN
,
198 .right_margin
= RIGHT_MARGIN
,
199 .upper_margin
= UPPER_MARGIN
,
200 .lower_margin
= LOWER_MARGIN
,
202 .vmode
= FB_VMODE_NONINTERLACED
205 static struct fb_fix_screeninfo da8xx_fb_fix
= {
206 .id
= "DA8xx FB Drv",
207 .type
= FB_TYPE_PACKED_PIXELS
,
209 .visual
= FB_VISUAL_PSEUDOCOLOR
,
213 .accel
= FB_ACCEL_NONE
216 static struct fb_videomode known_lcd_panels
[] = {
217 /* Sharp LCD035Q3DG01 */
219 .name
= "Sharp_LCD035Q3DG01",
229 .sync
= FB_SYNC_CLK_INVERT
,
231 /* Sharp LK043T1DG01 */
233 .name
= "Sharp_LK043T1DG01",
247 /* Hitachi SP10Q010 */
263 /* Enable the Raster Engine of the LCD Controller */
264 static inline void lcd_enable_raster(void)
268 /* Put LCDC in reset for several cycles */
269 if (lcd_revision
== LCD_VERSION_2
)
270 /* Write 1 to reset LCDC */
271 lcdc_write(LCD_CLK_MAIN_RESET
, LCD_CLK_RESET_REG
);
274 /* Bring LCDC out of reset */
275 if (lcd_revision
== LCD_VERSION_2
)
276 lcdc_write(0, LCD_CLK_RESET_REG
);
279 /* Above reset sequence doesnot reset register context */
280 reg
= lcdc_read(LCD_RASTER_CTRL_REG
);
281 if (!(reg
& LCD_RASTER_ENABLE
))
282 lcdc_write(reg
| LCD_RASTER_ENABLE
, LCD_RASTER_CTRL_REG
);
285 /* Disable the Raster Engine of the LCD Controller */
286 static inline void lcd_disable_raster(bool wait_for_frame_done
)
291 reg
= lcdc_read(LCD_RASTER_CTRL_REG
);
292 if (reg
& LCD_RASTER_ENABLE
)
293 lcdc_write(reg
& ~LCD_RASTER_ENABLE
, LCD_RASTER_CTRL_REG
);
295 /* return if already disabled */
298 if ((wait_for_frame_done
== true) && (lcd_revision
== LCD_VERSION_2
)) {
300 ret
= wait_event_interruptible_timeout(frame_done_wq
,
301 frame_done_flag
!= 0,
302 msecs_to_jiffies(50));
304 pr_err("LCD Controller timed out\n");
308 static void lcd_blit(int load_mode
, struct da8xx_fb_par
*par
)
316 /* init reg to clear PLM (loading mode) fields */
317 reg_ras
= lcdc_read(LCD_RASTER_CTRL_REG
);
318 reg_ras
&= ~(3 << 20);
320 reg_dma
= lcdc_read(LCD_DMA_CTRL_REG
);
322 if (load_mode
== LOAD_DATA
) {
323 start
= par
->dma_start
;
326 reg_ras
|= LCD_PALETTE_LOAD_MODE(DATA_ONLY
);
327 if (lcd_revision
== LCD_VERSION_1
) {
328 reg_dma
|= LCD_V1_END_OF_FRAME_INT_ENA
;
330 reg_int
= lcdc_read(LCD_INT_ENABLE_SET_REG
) |
331 LCD_V2_END_OF_FRAME0_INT_ENA
|
332 LCD_V2_END_OF_FRAME1_INT_ENA
|
334 lcdc_write(reg_int
, LCD_INT_ENABLE_SET_REG
);
336 reg_dma
|= LCD_DUAL_FRAME_BUFFER_ENABLE
;
338 lcdc_write(start
, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG
);
339 lcdc_write(end
, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG
);
340 lcdc_write(start
, LCD_DMA_FRM_BUF_BASE_ADDR_1_REG
);
341 lcdc_write(end
, LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG
);
342 } else if (load_mode
== LOAD_PALETTE
) {
343 start
= par
->p_palette_base
;
344 end
= start
+ par
->palette_sz
- 1;
346 reg_ras
|= LCD_PALETTE_LOAD_MODE(PALETTE_ONLY
);
348 if (lcd_revision
== LCD_VERSION_1
) {
349 reg_ras
|= LCD_V1_PL_INT_ENA
;
351 reg_int
= lcdc_read(LCD_INT_ENABLE_SET_REG
) |
353 lcdc_write(reg_int
, LCD_INT_ENABLE_SET_REG
);
356 lcdc_write(start
, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG
);
357 lcdc_write(end
, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG
);
360 lcdc_write(reg_dma
, LCD_DMA_CTRL_REG
);
361 lcdc_write(reg_ras
, LCD_RASTER_CTRL_REG
);
364 * The Raster enable bit must be set after all other control fields are
370 /* Configure the Burst Size and fifo threhold of DMA */
371 static int lcd_cfg_dma(int burst_size
, int fifo_th
)
375 reg
= lcdc_read(LCD_DMA_CTRL_REG
) & 0x00000001;
376 switch (burst_size
) {
378 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_1
);
381 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_2
);
384 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_4
);
387 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_8
);
391 reg
|= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_16
);
395 reg
|= (fifo_th
<< 8);
397 lcdc_write(reg
, LCD_DMA_CTRL_REG
);
402 static void lcd_cfg_ac_bias(int period
, int transitions_per_int
)
406 /* Set the AC Bias Period and Number of Transisitons per Interrupt */
407 reg
= lcdc_read(LCD_RASTER_TIMING_2_REG
) & 0xFFF00000;
408 reg
|= LCD_AC_BIAS_FREQUENCY(period
) |
409 LCD_AC_BIAS_TRANSITIONS_PER_INT(transitions_per_int
);
410 lcdc_write(reg
, LCD_RASTER_TIMING_2_REG
);
413 static void lcd_cfg_horizontal_sync(int back_porch
, int pulse_width
,
418 reg
= lcdc_read(LCD_RASTER_TIMING_0_REG
) & 0xf;
419 reg
|= ((back_porch
& 0xff) << 24)
420 | ((front_porch
& 0xff) << 16)
421 | ((pulse_width
& 0x3f) << 10);
422 lcdc_write(reg
, LCD_RASTER_TIMING_0_REG
);
425 static void lcd_cfg_vertical_sync(int back_porch
, int pulse_width
,
430 reg
= lcdc_read(LCD_RASTER_TIMING_1_REG
) & 0x3ff;
431 reg
|= ((back_porch
& 0xff) << 24)
432 | ((front_porch
& 0xff) << 16)
433 | ((pulse_width
& 0x3f) << 10);
434 lcdc_write(reg
, LCD_RASTER_TIMING_1_REG
);
437 static int lcd_cfg_display(const struct lcd_ctrl_config
*cfg
,
438 struct fb_videomode
*panel
)
443 reg
= lcdc_read(LCD_RASTER_CTRL_REG
) & ~(LCD_TFT_MODE
|
445 LCD_MONOCHROME_MODE
);
447 switch (cfg
->panel_shade
) {
449 reg
|= LCD_MONOCHROME_MODE
;
450 if (cfg
->mono_8bit_mode
)
451 reg
|= LCD_MONO_8BIT_MODE
;
455 if (cfg
->tft_alt_mode
)
456 reg
|= LCD_TFT_ALT_ENABLE
;
460 /* AC bias applicable only for Pasive panels */
461 lcd_cfg_ac_bias(cfg
->ac_bias
, cfg
->ac_bias_intrpt
);
462 if (cfg
->bpp
== 12 && cfg
->stn_565_mode
)
463 reg
|= LCD_STN_565_ENABLE
;
470 /* enable additional interrupts here */
471 if (lcd_revision
== LCD_VERSION_1
) {
472 reg
|= LCD_V1_UNDERFLOW_INT_ENA
;
474 reg_int
= lcdc_read(LCD_INT_ENABLE_SET_REG
) |
475 LCD_V2_UNDERFLOW_INT_ENA
;
476 lcdc_write(reg_int
, LCD_INT_ENABLE_SET_REG
);
479 lcdc_write(reg
, LCD_RASTER_CTRL_REG
);
481 reg
= lcdc_read(LCD_RASTER_TIMING_2_REG
);
483 reg
|= LCD_SYNC_CTRL
;
486 reg
|= LCD_SYNC_EDGE
;
488 reg
&= ~LCD_SYNC_EDGE
;
490 if (panel
->sync
& FB_SYNC_HOR_HIGH_ACT
)
491 reg
|= LCD_INVERT_LINE_CLOCK
;
493 reg
&= ~LCD_INVERT_LINE_CLOCK
;
495 if (panel
->sync
& FB_SYNC_VERT_HIGH_ACT
)
496 reg
|= LCD_INVERT_FRAME_CLOCK
;
498 reg
&= ~LCD_INVERT_FRAME_CLOCK
;
500 lcdc_write(reg
, LCD_RASTER_TIMING_2_REG
);
505 static int lcd_cfg_frame_buffer(struct da8xx_fb_par
*par
, u32 width
, u32 height
,
506 u32 bpp
, u32 raster_order
)
510 if (bpp
> 16 && lcd_revision
== LCD_VERSION_1
)
513 /* Set the Panel Width */
514 /* Pixels per line = (PPL + 1)*16 */
515 if (lcd_revision
== LCD_VERSION_1
) {
517 * 0x3F in bits 4..9 gives max horizontal resolution = 1024
523 * 0x7F in bits 4..10 gives max horizontal resolution = 2048
529 reg
= lcdc_read(LCD_RASTER_TIMING_0_REG
);
531 if (lcd_revision
== LCD_VERSION_1
) {
532 reg
|= ((width
>> 4) - 1) << 4;
534 width
= (width
>> 4) - 1;
535 reg
|= ((width
& 0x3f) << 4) | ((width
& 0x40) >> 3);
537 lcdc_write(reg
, LCD_RASTER_TIMING_0_REG
);
539 /* Set the Panel Height */
540 /* Set bits 9:0 of Lines Per Pixel */
541 reg
= lcdc_read(LCD_RASTER_TIMING_1_REG
);
542 reg
= ((height
- 1) & 0x3ff) | (reg
& 0xfffffc00);
543 lcdc_write(reg
, LCD_RASTER_TIMING_1_REG
);
545 /* Set bit 10 of Lines Per Pixel */
546 if (lcd_revision
== LCD_VERSION_2
) {
547 reg
= lcdc_read(LCD_RASTER_TIMING_2_REG
);
548 reg
|= ((height
- 1) & 0x400) << 16;
549 lcdc_write(reg
, LCD_RASTER_TIMING_2_REG
);
552 /* Set the Raster Order of the Frame Buffer */
553 reg
= lcdc_read(LCD_RASTER_CTRL_REG
) & ~(1 << 8);
555 reg
|= LCD_RASTER_ORDER
;
557 par
->palette_sz
= 16 * 2;
566 reg
|= LCD_V2_TFT_24BPP_MODE
;
568 reg
|= LCD_V2_TFT_24BPP_UNPACK
;
572 par
->palette_sz
= 256 * 2;
579 lcdc_write(reg
, LCD_RASTER_CTRL_REG
);
584 #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16)
585 static int fb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
586 unsigned blue
, unsigned transp
,
587 struct fb_info
*info
)
589 struct da8xx_fb_par
*par
= info
->par
;
590 unsigned short *palette
= (unsigned short *) par
->v_palette_base
;
597 if (info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
)
600 if (info
->var
.bits_per_pixel
> 16 && lcd_revision
== LCD_VERSION_1
)
603 switch (info
->fix
.visual
) {
604 case FB_VISUAL_TRUECOLOR
:
605 red
= CNVT_TOHW(red
, info
->var
.red
.length
);
606 green
= CNVT_TOHW(green
, info
->var
.green
.length
);
607 blue
= CNVT_TOHW(blue
, info
->var
.blue
.length
);
609 case FB_VISUAL_PSEUDOCOLOR
:
610 switch (info
->var
.bits_per_pixel
) {
615 if (info
->var
.grayscale
) {
623 pal
|= green
& 0x00f0;
624 pal
|= blue
& 0x000f;
628 palette
[regno
] = pal
;
636 pal
= (red
& 0x0f00);
637 pal
|= (green
& 0x00f0);
638 pal
|= (blue
& 0x000f);
640 if (palette
[regno
] != pal
) {
642 palette
[regno
] = pal
;
649 /* Truecolor has hardware independent palette */
650 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
656 v
= (red
<< info
->var
.red
.offset
) |
657 (green
<< info
->var
.green
.offset
) |
658 (blue
<< info
->var
.blue
.offset
);
660 switch (info
->var
.bits_per_pixel
) {
662 ((u16
*) (info
->pseudo_palette
))[regno
] = v
;
666 ((u32
*) (info
->pseudo_palette
))[regno
] = v
;
669 if (palette
[0] != 0x4000) {
675 /* Update the palette in the h/w as needed. */
677 lcd_blit(LOAD_PALETTE
, par
);
683 static void lcd_reset(struct da8xx_fb_par
*par
)
685 /* Disable the Raster if previously Enabled */
686 lcd_disable_raster(false);
688 /* DMA has to be disabled */
689 lcdc_write(0, LCD_DMA_CTRL_REG
);
690 lcdc_write(0, LCD_RASTER_CTRL_REG
);
692 if (lcd_revision
== LCD_VERSION_2
) {
693 lcdc_write(0, LCD_INT_ENABLE_SET_REG
);
694 /* Write 1 to reset */
695 lcdc_write(LCD_CLK_MAIN_RESET
, LCD_CLK_RESET_REG
);
696 lcdc_write(0, LCD_CLK_RESET_REG
);
700 static void lcd_calc_clk_divider(struct da8xx_fb_par
*par
)
702 unsigned int lcd_clk
, div
;
704 lcd_clk
= clk_get_rate(par
->lcdc_clk
);
705 div
= lcd_clk
/ par
->pxl_clk
;
707 /* Configure the LCD clock divisor. */
708 lcdc_write(LCD_CLK_DIVISOR(div
) |
709 (LCD_RASTER_MODE
& 0x1), LCD_CTRL_REG
);
711 if (lcd_revision
== LCD_VERSION_2
)
712 lcdc_write(LCD_V2_DMA_CLK_EN
| LCD_V2_LIDD_CLK_EN
|
713 LCD_V2_CORE_CLK_EN
, LCD_CLK_ENABLE_REG
);
717 static int lcd_init(struct da8xx_fb_par
*par
, const struct lcd_ctrl_config
*cfg
,
718 struct fb_videomode
*panel
)
725 /* Calculate the divider */
726 lcd_calc_clk_divider(par
);
728 if (panel
->sync
& FB_SYNC_CLK_INVERT
)
729 lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG
) |
730 LCD_INVERT_PIXEL_CLOCK
), LCD_RASTER_TIMING_2_REG
);
732 lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG
) &
733 ~LCD_INVERT_PIXEL_CLOCK
), LCD_RASTER_TIMING_2_REG
);
735 /* Configure the DMA burst size and fifo threshold. */
736 ret
= lcd_cfg_dma(cfg
->dma_burst_sz
, cfg
->fifo_th
);
740 /* Configure the vertical and horizontal sync properties. */
741 lcd_cfg_vertical_sync(panel
->lower_margin
, panel
->vsync_len
,
742 panel
->upper_margin
);
743 lcd_cfg_horizontal_sync(panel
->right_margin
, panel
->hsync_len
,
746 /* Configure for disply */
747 ret
= lcd_cfg_display(cfg
, panel
);
755 ret
= lcd_cfg_frame_buffer(par
, (unsigned int)panel
->xres
,
756 (unsigned int)panel
->yres
, bpp
,
762 lcdc_write((lcdc_read(LCD_RASTER_CTRL_REG
) & 0xfff00fff) |
763 (cfg
->fdd
<< 12), LCD_RASTER_CTRL_REG
);
768 /* IRQ handler for version 2 of LCDC */
769 static irqreturn_t
lcdc_irq_handler_rev02(int irq
, void *arg
)
771 struct da8xx_fb_par
*par
= arg
;
772 u32 stat
= lcdc_read(LCD_MASKED_STAT_REG
);
774 if ((stat
& LCD_SYNC_LOST
) && (stat
& LCD_FIFO_UNDERFLOW
)) {
775 lcd_disable_raster(false);
776 lcdc_write(stat
, LCD_MASKED_STAT_REG
);
778 } else if (stat
& LCD_PL_LOAD_DONE
) {
780 * Must disable raster before changing state of any control bit.
781 * And also must be disabled before clearing the PL loading
782 * interrupt via the following write to the status register. If
783 * this is done after then one gets multiple PL done interrupts.
785 lcd_disable_raster(false);
787 lcdc_write(stat
, LCD_MASKED_STAT_REG
);
789 /* Disable PL completion interrupt */
790 lcdc_write(LCD_V2_PL_INT_ENA
, LCD_INT_ENABLE_CLR_REG
);
792 /* Setup and start data loading mode */
793 lcd_blit(LOAD_DATA
, par
);
795 lcdc_write(stat
, LCD_MASKED_STAT_REG
);
797 if (stat
& LCD_END_OF_FRAME0
) {
798 par
->which_dma_channel_done
= 0;
799 lcdc_write(par
->dma_start
,
800 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG
);
801 lcdc_write(par
->dma_end
,
802 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG
);
804 wake_up_interruptible(&par
->vsync_wait
);
807 if (stat
& LCD_END_OF_FRAME1
) {
808 par
->which_dma_channel_done
= 1;
809 lcdc_write(par
->dma_start
,
810 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG
);
811 lcdc_write(par
->dma_end
,
812 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG
);
814 wake_up_interruptible(&par
->vsync_wait
);
817 /* Set only when controller is disabled and at the end of
822 wake_up_interruptible(&frame_done_wq
);
826 lcdc_write(0, LCD_END_OF_INT_IND_REG
);
830 /* IRQ handler for version 1 LCDC */
831 static irqreturn_t
lcdc_irq_handler_rev01(int irq
, void *arg
)
833 struct da8xx_fb_par
*par
= arg
;
834 u32 stat
= lcdc_read(LCD_STAT_REG
);
837 if ((stat
& LCD_SYNC_LOST
) && (stat
& LCD_FIFO_UNDERFLOW
)) {
838 lcd_disable_raster(false);
839 lcdc_write(stat
, LCD_STAT_REG
);
841 } else if (stat
& LCD_PL_LOAD_DONE
) {
843 * Must disable raster before changing state of any control bit.
844 * And also must be disabled before clearing the PL loading
845 * interrupt via the following write to the status register. If
846 * this is done after then one gets multiple PL done interrupts.
848 lcd_disable_raster(false);
850 lcdc_write(stat
, LCD_STAT_REG
);
852 /* Disable PL completion inerrupt */
853 reg_ras
= lcdc_read(LCD_RASTER_CTRL_REG
);
854 reg_ras
&= ~LCD_V1_PL_INT_ENA
;
855 lcdc_write(reg_ras
, LCD_RASTER_CTRL_REG
);
857 /* Setup and start data loading mode */
858 lcd_blit(LOAD_DATA
, par
);
860 lcdc_write(stat
, LCD_STAT_REG
);
862 if (stat
& LCD_END_OF_FRAME0
) {
863 par
->which_dma_channel_done
= 0;
864 lcdc_write(par
->dma_start
,
865 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG
);
866 lcdc_write(par
->dma_end
,
867 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG
);
869 wake_up_interruptible(&par
->vsync_wait
);
872 if (stat
& LCD_END_OF_FRAME1
) {
873 par
->which_dma_channel_done
= 1;
874 lcdc_write(par
->dma_start
,
875 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG
);
876 lcdc_write(par
->dma_end
,
877 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG
);
879 wake_up_interruptible(&par
->vsync_wait
);
886 static int fb_check_var(struct fb_var_screeninfo
*var
,
887 struct fb_info
*info
)
891 if (var
->bits_per_pixel
> 16 && lcd_revision
== LCD_VERSION_1
)
894 switch (var
->bits_per_pixel
) {
899 var
->green
.offset
= 0;
900 var
->green
.length
= 8;
901 var
->blue
.offset
= 0;
902 var
->blue
.length
= 8;
903 var
->transp
.offset
= 0;
904 var
->transp
.length
= 0;
910 var
->green
.offset
= 0;
911 var
->green
.length
= 4;
912 var
->blue
.offset
= 0;
913 var
->blue
.length
= 4;
914 var
->transp
.offset
= 0;
915 var
->transp
.length
= 0;
916 var
->nonstd
= FB_NONSTD_REV_PIX_IN_B
;
918 case 16: /* RGB 565 */
919 var
->red
.offset
= 11;
921 var
->green
.offset
= 5;
922 var
->green
.length
= 6;
923 var
->blue
.offset
= 0;
924 var
->blue
.length
= 5;
925 var
->transp
.offset
= 0;
926 var
->transp
.length
= 0;
930 var
->red
.offset
= 16;
932 var
->green
.offset
= 8;
933 var
->green
.length
= 8;
934 var
->blue
.offset
= 0;
935 var
->blue
.length
= 8;
939 var
->transp
.offset
= 24;
940 var
->transp
.length
= 8;
941 var
->red
.offset
= 16;
943 var
->green
.offset
= 8;
944 var
->green
.length
= 8;
945 var
->blue
.offset
= 0;
946 var
->blue
.length
= 8;
953 var
->red
.msb_right
= 0;
954 var
->green
.msb_right
= 0;
955 var
->blue
.msb_right
= 0;
956 var
->transp
.msb_right
= 0;
960 #ifdef CONFIG_CPU_FREQ
961 static int lcd_da8xx_cpufreq_transition(struct notifier_block
*nb
,
962 unsigned long val
, void *data
)
964 struct da8xx_fb_par
*par
;
966 par
= container_of(nb
, struct da8xx_fb_par
, freq_transition
);
967 if (val
== CPUFREQ_POSTCHANGE
) {
968 if (par
->lcd_fck_rate
!= clk_get_rate(par
->lcdc_clk
)) {
969 par
->lcd_fck_rate
= clk_get_rate(par
->lcdc_clk
);
970 lcd_disable_raster(true);
971 lcd_calc_clk_divider(par
);
972 if (par
->blank
== FB_BLANK_UNBLANK
)
980 static inline int lcd_da8xx_cpufreq_register(struct da8xx_fb_par
*par
)
982 par
->freq_transition
.notifier_call
= lcd_da8xx_cpufreq_transition
;
984 return cpufreq_register_notifier(&par
->freq_transition
,
985 CPUFREQ_TRANSITION_NOTIFIER
);
988 static inline void lcd_da8xx_cpufreq_deregister(struct da8xx_fb_par
*par
)
990 cpufreq_unregister_notifier(&par
->freq_transition
,
991 CPUFREQ_TRANSITION_NOTIFIER
);
995 static int fb_remove(struct platform_device
*dev
)
997 struct fb_info
*info
= dev_get_drvdata(&dev
->dev
);
1000 struct da8xx_fb_par
*par
= info
->par
;
1002 #ifdef CONFIG_CPU_FREQ
1003 lcd_da8xx_cpufreq_deregister(par
);
1005 if (par
->panel_power_ctrl
)
1006 par
->panel_power_ctrl(0);
1008 lcd_disable_raster(true);
1009 lcdc_write(0, LCD_RASTER_CTRL_REG
);
1012 lcdc_write(0, LCD_DMA_CTRL_REG
);
1014 unregister_framebuffer(info
);
1015 fb_dealloc_cmap(&info
->cmap
);
1016 dma_free_coherent(NULL
, PALETTE_SIZE
, par
->v_palette_base
,
1017 par
->p_palette_base
);
1018 dma_free_coherent(NULL
, par
->vram_size
, par
->vram_virt
,
1020 free_irq(par
->irq
, par
);
1021 pm_runtime_put_sync(&dev
->dev
);
1022 pm_runtime_disable(&dev
->dev
);
1023 framebuffer_release(info
);
1024 iounmap(da8xx_fb_reg_base
);
1025 release_mem_region(lcdc_regs
->start
, resource_size(lcdc_regs
));
1032 * Function to wait for vertical sync which for this LCD peripheral
1033 * translates into waiting for the current raster frame to complete.
1035 static int fb_wait_for_vsync(struct fb_info
*info
)
1037 struct da8xx_fb_par
*par
= info
->par
;
1041 * Set flag to 0 and wait for isr to set to 1. It would seem there is a
1042 * race condition here where the ISR could have occurred just before or
1043 * just after this set. But since we are just coarsely waiting for
1044 * a frame to complete then that's OK. i.e. if the frame completed
1045 * just before this code executed then we have to wait another full
1046 * frame time but there is no way to avoid such a situation. On the
1047 * other hand if the frame completed just after then we don't need
1048 * to wait long at all. Either way we are guaranteed to return to the
1049 * user immediately after a frame completion which is all that is
1052 par
->vsync_flag
= 0;
1053 ret
= wait_event_interruptible_timeout(par
->vsync_wait
,
1054 par
->vsync_flag
!= 0,
1055 par
->vsync_timeout
);
1064 static int fb_ioctl(struct fb_info
*info
, unsigned int cmd
,
1067 struct lcd_sync_arg sync_arg
;
1070 case FBIOGET_CONTRAST
:
1071 case FBIOPUT_CONTRAST
:
1072 case FBIGET_BRIGHTNESS
:
1073 case FBIPUT_BRIGHTNESS
:
1078 if (copy_from_user(&sync_arg
, (char *)arg
,
1079 sizeof(struct lcd_sync_arg
)))
1081 lcd_cfg_horizontal_sync(sync_arg
.back_porch
,
1082 sync_arg
.pulse_width
,
1083 sync_arg
.front_porch
);
1086 if (copy_from_user(&sync_arg
, (char *)arg
,
1087 sizeof(struct lcd_sync_arg
)))
1089 lcd_cfg_vertical_sync(sync_arg
.back_porch
,
1090 sync_arg
.pulse_width
,
1091 sync_arg
.front_porch
);
1093 case FBIO_WAITFORVSYNC
:
1094 return fb_wait_for_vsync(info
);
1101 static int cfb_blank(int blank
, struct fb_info
*info
)
1103 struct da8xx_fb_par
*par
= info
->par
;
1106 if (par
->blank
== blank
)
1111 case FB_BLANK_UNBLANK
:
1112 lcd_enable_raster();
1114 if (par
->panel_power_ctrl
)
1115 par
->panel_power_ctrl(1);
1117 case FB_BLANK_NORMAL
:
1118 case FB_BLANK_VSYNC_SUSPEND
:
1119 case FB_BLANK_HSYNC_SUSPEND
:
1120 case FB_BLANK_POWERDOWN
:
1121 if (par
->panel_power_ctrl
)
1122 par
->panel_power_ctrl(0);
1124 lcd_disable_raster(true);
1134 * Set new x,y offsets in the virtual display for the visible area and switch
1137 static int da8xx_pan_display(struct fb_var_screeninfo
*var
,
1138 struct fb_info
*fbi
)
1141 struct fb_var_screeninfo new_var
;
1142 struct da8xx_fb_par
*par
= fbi
->par
;
1143 struct fb_fix_screeninfo
*fix
= &fbi
->fix
;
1146 unsigned long irq_flags
;
1148 if (var
->xoffset
!= fbi
->var
.xoffset
||
1149 var
->yoffset
!= fbi
->var
.yoffset
) {
1150 memcpy(&new_var
, &fbi
->var
, sizeof(new_var
));
1151 new_var
.xoffset
= var
->xoffset
;
1152 new_var
.yoffset
= var
->yoffset
;
1153 if (fb_check_var(&new_var
, fbi
))
1156 memcpy(&fbi
->var
, &new_var
, sizeof(new_var
));
1158 start
= fix
->smem_start
+
1159 new_var
.yoffset
* fix
->line_length
+
1160 new_var
.xoffset
* fbi
->var
.bits_per_pixel
/ 8;
1161 end
= start
+ fbi
->var
.yres
* fix
->line_length
- 1;
1162 par
->dma_start
= start
;
1164 spin_lock_irqsave(&par
->lock_for_chan_update
,
1166 if (par
->which_dma_channel_done
== 0) {
1167 lcdc_write(par
->dma_start
,
1168 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG
);
1169 lcdc_write(par
->dma_end
,
1170 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG
);
1171 } else if (par
->which_dma_channel_done
== 1) {
1172 lcdc_write(par
->dma_start
,
1173 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG
);
1174 lcdc_write(par
->dma_end
,
1175 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG
);
1177 spin_unlock_irqrestore(&par
->lock_for_chan_update
,
1185 static struct fb_ops da8xx_fb_ops
= {
1186 .owner
= THIS_MODULE
,
1187 .fb_check_var
= fb_check_var
,
1188 .fb_setcolreg
= fb_setcolreg
,
1189 .fb_pan_display
= da8xx_pan_display
,
1190 .fb_ioctl
= fb_ioctl
,
1191 .fb_fillrect
= cfb_fillrect
,
1192 .fb_copyarea
= cfb_copyarea
,
1193 .fb_imageblit
= cfb_imageblit
,
1194 .fb_blank
= cfb_blank
,
1197 /* Calculate and return pixel clock period in pico seconds */
1198 static unsigned int da8xxfb_pixel_clk_period(struct da8xx_fb_par
*par
)
1200 unsigned int lcd_clk
, div
;
1201 unsigned int configured_pix_clk
;
1202 unsigned long long pix_clk_period_picosec
= 1000000000000ULL;
1204 lcd_clk
= clk_get_rate(par
->lcdc_clk
);
1205 div
= lcd_clk
/ par
->pxl_clk
;
1206 configured_pix_clk
= (lcd_clk
/ div
);
1208 do_div(pix_clk_period_picosec
, configured_pix_clk
);
1210 return pix_clk_period_picosec
;
1213 static int fb_probe(struct platform_device
*device
)
1215 struct da8xx_lcdc_platform_data
*fb_pdata
=
1216 device
->dev
.platform_data
;
1217 struct lcd_ctrl_config
*lcd_cfg
;
1218 struct fb_videomode
*lcdc_info
;
1219 struct fb_info
*da8xx_fb_info
;
1220 struct clk
*fb_clk
= NULL
;
1221 struct da8xx_fb_par
*par
;
1222 resource_size_t len
;
1226 if (fb_pdata
== NULL
) {
1227 dev_err(&device
->dev
, "Can not get platform data\n");
1231 lcdc_regs
= platform_get_resource(device
, IORESOURCE_MEM
, 0);
1233 dev_err(&device
->dev
,
1234 "Can not get memory resource for LCD controller\n");
1238 len
= resource_size(lcdc_regs
);
1240 lcdc_regs
= request_mem_region(lcdc_regs
->start
, len
, lcdc_regs
->name
);
1244 da8xx_fb_reg_base
= ioremap(lcdc_regs
->start
, len
);
1245 if (!da8xx_fb_reg_base
) {
1247 goto err_request_mem
;
1250 fb_clk
= clk_get(&device
->dev
, "fck");
1251 if (IS_ERR(fb_clk
)) {
1252 dev_err(&device
->dev
, "Can not get device clock\n");
1257 pm_runtime_enable(&device
->dev
);
1258 pm_runtime_get_sync(&device
->dev
);
1260 /* Determine LCD IP Version */
1261 switch (lcdc_read(LCD_PID_REG
)) {
1263 lcd_revision
= LCD_VERSION_1
;
1267 lcd_revision
= LCD_VERSION_2
;
1270 dev_warn(&device
->dev
, "Unknown PID Reg value 0x%x, "
1271 "defaulting to LCD revision 1\n",
1272 lcdc_read(LCD_PID_REG
));
1273 lcd_revision
= LCD_VERSION_1
;
1277 for (i
= 0, lcdc_info
= known_lcd_panels
;
1278 i
< ARRAY_SIZE(known_lcd_panels
);
1280 if (strcmp(fb_pdata
->type
, lcdc_info
->name
) == 0)
1284 if (i
== ARRAY_SIZE(known_lcd_panels
)) {
1285 dev_err(&device
->dev
, "GLCD: No valid panel found\n");
1287 goto err_pm_runtime_disable
;
1289 dev_info(&device
->dev
, "GLCD: Found %s panel\n",
1292 lcd_cfg
= (struct lcd_ctrl_config
*)fb_pdata
->controller_data
;
1294 da8xx_fb_info
= framebuffer_alloc(sizeof(struct da8xx_fb_par
),
1296 if (!da8xx_fb_info
) {
1297 dev_dbg(&device
->dev
, "Memory allocation failed for fb_info\n");
1299 goto err_pm_runtime_disable
;
1302 par
= da8xx_fb_info
->par
;
1303 par
->lcdc_clk
= fb_clk
;
1304 #ifdef CONFIG_CPU_FREQ
1305 par
->lcd_fck_rate
= clk_get_rate(fb_clk
);
1307 par
->pxl_clk
= lcdc_info
->pixclock
;
1308 if (fb_pdata
->panel_power_ctrl
) {
1309 par
->panel_power_ctrl
= fb_pdata
->panel_power_ctrl
;
1310 par
->panel_power_ctrl(1);
1313 if (lcd_init(par
, lcd_cfg
, lcdc_info
) < 0) {
1314 dev_err(&device
->dev
, "lcd_init failed\n");
1316 goto err_release_fb
;
1319 /* allocate frame buffer */
1320 par
->vram_size
= lcdc_info
->xres
* lcdc_info
->yres
* lcd_cfg
->bpp
;
1321 ulcm
= lcm((lcdc_info
->xres
* lcd_cfg
->bpp
)/8, PAGE_SIZE
);
1322 par
->vram_size
= roundup(par
->vram_size
/8, ulcm
);
1323 par
->vram_size
= par
->vram_size
* LCD_NUM_BUFFERS
;
1325 par
->vram_virt
= dma_alloc_coherent(NULL
,
1327 (resource_size_t
*) &par
->vram_phys
,
1328 GFP_KERNEL
| GFP_DMA
);
1329 if (!par
->vram_virt
) {
1330 dev_err(&device
->dev
,
1331 "GLCD: kmalloc for frame buffer failed\n");
1333 goto err_release_fb
;
1336 da8xx_fb_info
->screen_base
= (char __iomem
*) par
->vram_virt
;
1337 da8xx_fb_fix
.smem_start
= par
->vram_phys
;
1338 da8xx_fb_fix
.smem_len
= par
->vram_size
;
1339 da8xx_fb_fix
.line_length
= (lcdc_info
->xres
* lcd_cfg
->bpp
) / 8;
1341 par
->dma_start
= par
->vram_phys
;
1342 par
->dma_end
= par
->dma_start
+ lcdc_info
->yres
*
1343 da8xx_fb_fix
.line_length
- 1;
1345 /* allocate palette buffer */
1346 par
->v_palette_base
= dma_alloc_coherent(NULL
,
1349 &par
->p_palette_base
,
1350 GFP_KERNEL
| GFP_DMA
);
1351 if (!par
->v_palette_base
) {
1352 dev_err(&device
->dev
,
1353 "GLCD: kmalloc for palette buffer failed\n");
1355 goto err_release_fb_mem
;
1357 memset(par
->v_palette_base
, 0, PALETTE_SIZE
);
1359 par
->irq
= platform_get_irq(device
, 0);
1362 goto err_release_pl_mem
;
1365 /* Initialize par */
1366 da8xx_fb_info
->var
.bits_per_pixel
= lcd_cfg
->bpp
;
1368 da8xx_fb_var
.xres
= lcdc_info
->xres
;
1369 da8xx_fb_var
.xres_virtual
= lcdc_info
->xres
;
1371 da8xx_fb_var
.yres
= lcdc_info
->yres
;
1372 da8xx_fb_var
.yres_virtual
= lcdc_info
->yres
* LCD_NUM_BUFFERS
;
1374 da8xx_fb_var
.grayscale
=
1375 lcd_cfg
->panel_shade
== MONOCHROME
? 1 : 0;
1376 da8xx_fb_var
.bits_per_pixel
= lcd_cfg
->bpp
;
1378 da8xx_fb_var
.hsync_len
= lcdc_info
->hsync_len
;
1379 da8xx_fb_var
.vsync_len
= lcdc_info
->vsync_len
;
1380 da8xx_fb_var
.right_margin
= lcdc_info
->right_margin
;
1381 da8xx_fb_var
.left_margin
= lcdc_info
->left_margin
;
1382 da8xx_fb_var
.lower_margin
= lcdc_info
->lower_margin
;
1383 da8xx_fb_var
.upper_margin
= lcdc_info
->upper_margin
;
1384 da8xx_fb_var
.pixclock
= da8xxfb_pixel_clk_period(par
);
1386 /* Initialize fbinfo */
1387 da8xx_fb_info
->flags
= FBINFO_FLAG_DEFAULT
;
1388 da8xx_fb_info
->fix
= da8xx_fb_fix
;
1389 da8xx_fb_info
->var
= da8xx_fb_var
;
1390 da8xx_fb_info
->fbops
= &da8xx_fb_ops
;
1391 da8xx_fb_info
->pseudo_palette
= par
->pseudo_palette
;
1392 da8xx_fb_info
->fix
.visual
= (da8xx_fb_info
->var
.bits_per_pixel
<= 8) ?
1393 FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
1395 ret
= fb_alloc_cmap(&da8xx_fb_info
->cmap
, PALETTE_SIZE
, 0);
1397 goto err_release_pl_mem
;
1398 da8xx_fb_info
->cmap
.len
= par
->palette_sz
;
1400 /* initialize var_screeninfo */
1401 da8xx_fb_var
.activate
= FB_ACTIVATE_FORCE
;
1402 fb_set_var(da8xx_fb_info
, &da8xx_fb_var
);
1404 dev_set_drvdata(&device
->dev
, da8xx_fb_info
);
1406 /* initialize the vsync wait queue */
1407 init_waitqueue_head(&par
->vsync_wait
);
1408 par
->vsync_timeout
= HZ
/ 5;
1409 par
->which_dma_channel_done
= -1;
1410 spin_lock_init(&par
->lock_for_chan_update
);
1412 /* Register the Frame Buffer */
1413 if (register_framebuffer(da8xx_fb_info
) < 0) {
1414 dev_err(&device
->dev
,
1415 "GLCD: Frame Buffer Registration Failed!\n");
1417 goto err_dealloc_cmap
;
1420 #ifdef CONFIG_CPU_FREQ
1421 ret
= lcd_da8xx_cpufreq_register(par
);
1423 dev_err(&device
->dev
, "failed to register cpufreq\n");
1428 if (lcd_revision
== LCD_VERSION_1
)
1429 lcdc_irq_handler
= lcdc_irq_handler_rev01
;
1431 init_waitqueue_head(&frame_done_wq
);
1432 lcdc_irq_handler
= lcdc_irq_handler_rev02
;
1435 ret
= request_irq(par
->irq
, lcdc_irq_handler
, 0,
1442 #ifdef CONFIG_CPU_FREQ
1443 lcd_da8xx_cpufreq_deregister(par
);
1446 unregister_framebuffer(da8xx_fb_info
);
1449 fb_dealloc_cmap(&da8xx_fb_info
->cmap
);
1452 dma_free_coherent(NULL
, PALETTE_SIZE
, par
->v_palette_base
,
1453 par
->p_palette_base
);
1456 dma_free_coherent(NULL
, par
->vram_size
, par
->vram_virt
, par
->vram_phys
);
1459 framebuffer_release(da8xx_fb_info
);
1461 err_pm_runtime_disable
:
1462 pm_runtime_put_sync(&device
->dev
);
1463 pm_runtime_disable(&device
->dev
);
1466 iounmap(da8xx_fb_reg_base
);
1469 release_mem_region(lcdc_regs
->start
, len
);
1475 struct lcdc_context
{
1479 u32 raster_timing_0
;
1480 u32 raster_timing_1
;
1481 u32 raster_timing_2
;
1483 u32 dma_frm_buf_base_addr_0
;
1484 u32 dma_frm_buf_ceiling_addr_0
;
1485 u32 dma_frm_buf_base_addr_1
;
1486 u32 dma_frm_buf_ceiling_addr_1
;
1490 static void lcd_context_save(void)
1492 if (lcd_revision
== LCD_VERSION_2
) {
1493 reg_context
.clk_enable
= lcdc_read(LCD_CLK_ENABLE_REG
);
1494 reg_context
.int_enable_set
= lcdc_read(LCD_INT_ENABLE_SET_REG
);
1497 reg_context
.ctrl
= lcdc_read(LCD_CTRL_REG
);
1498 reg_context
.dma_ctrl
= lcdc_read(LCD_DMA_CTRL_REG
);
1499 reg_context
.raster_timing_0
= lcdc_read(LCD_RASTER_TIMING_0_REG
);
1500 reg_context
.raster_timing_1
= lcdc_read(LCD_RASTER_TIMING_1_REG
);
1501 reg_context
.raster_timing_2
= lcdc_read(LCD_RASTER_TIMING_2_REG
);
1502 reg_context
.dma_frm_buf_base_addr_0
=
1503 lcdc_read(LCD_DMA_FRM_BUF_BASE_ADDR_0_REG
);
1504 reg_context
.dma_frm_buf_ceiling_addr_0
=
1505 lcdc_read(LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG
);
1506 reg_context
.dma_frm_buf_base_addr_1
=
1507 lcdc_read(LCD_DMA_FRM_BUF_BASE_ADDR_1_REG
);
1508 reg_context
.dma_frm_buf_ceiling_addr_1
=
1509 lcdc_read(LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG
);
1510 reg_context
.raster_ctrl
= lcdc_read(LCD_RASTER_CTRL_REG
);
1514 static void lcd_context_restore(void)
1516 if (lcd_revision
== LCD_VERSION_2
) {
1517 lcdc_write(reg_context
.clk_enable
, LCD_CLK_ENABLE_REG
);
1518 lcdc_write(reg_context
.int_enable_set
, LCD_INT_ENABLE_SET_REG
);
1521 lcdc_write(reg_context
.ctrl
, LCD_CTRL_REG
);
1522 lcdc_write(reg_context
.dma_ctrl
, LCD_DMA_CTRL_REG
);
1523 lcdc_write(reg_context
.raster_timing_0
, LCD_RASTER_TIMING_0_REG
);
1524 lcdc_write(reg_context
.raster_timing_1
, LCD_RASTER_TIMING_1_REG
);
1525 lcdc_write(reg_context
.raster_timing_2
, LCD_RASTER_TIMING_2_REG
);
1526 lcdc_write(reg_context
.dma_frm_buf_base_addr_0
,
1527 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG
);
1528 lcdc_write(reg_context
.dma_frm_buf_ceiling_addr_0
,
1529 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG
);
1530 lcdc_write(reg_context
.dma_frm_buf_base_addr_1
,
1531 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG
);
1532 lcdc_write(reg_context
.dma_frm_buf_ceiling_addr_1
,
1533 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG
);
1534 lcdc_write(reg_context
.raster_ctrl
, LCD_RASTER_CTRL_REG
);
1538 static int fb_suspend(struct platform_device
*dev
, pm_message_t state
)
1540 struct fb_info
*info
= platform_get_drvdata(dev
);
1541 struct da8xx_fb_par
*par
= info
->par
;
1544 if (par
->panel_power_ctrl
)
1545 par
->panel_power_ctrl(0);
1547 fb_set_suspend(info
, 1);
1548 lcd_disable_raster(true);
1550 pm_runtime_put_sync(&dev
->dev
);
1555 static int fb_resume(struct platform_device
*dev
)
1557 struct fb_info
*info
= platform_get_drvdata(dev
);
1558 struct da8xx_fb_par
*par
= info
->par
;
1561 pm_runtime_get_sync(&dev
->dev
);
1562 lcd_context_restore();
1563 if (par
->blank
== FB_BLANK_UNBLANK
) {
1564 lcd_enable_raster();
1566 if (par
->panel_power_ctrl
)
1567 par
->panel_power_ctrl(1);
1570 fb_set_suspend(info
, 0);
1576 #define fb_suspend NULL
1577 #define fb_resume NULL
1580 static struct platform_driver da8xx_fb_driver
= {
1582 .remove
= fb_remove
,
1583 .suspend
= fb_suspend
,
1584 .resume
= fb_resume
,
1586 .name
= DRIVER_NAME
,
1587 .owner
= THIS_MODULE
,
1591 static int __init
da8xx_fb_init(void)
1593 return platform_driver_register(&da8xx_fb_driver
);
1596 static void __exit
da8xx_fb_cleanup(void)
1598 platform_driver_unregister(&da8xx_fb_driver
);
1601 module_init(da8xx_fb_init
);
1602 module_exit(da8xx_fb_cleanup
);
1604 MODULE_DESCRIPTION("Framebuffer driver for TI da8xx/omap-l1xx");
1605 MODULE_AUTHOR("Texas Instruments");
1606 MODULE_LICENSE("GPL");