2 * drivers/video/rk29_fb.c
4 * Copyright (C) 2010 ROCKCHIP, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
25 #include <linux/init.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/interrupt.h>
28 #include <linux/platform_device.h>
29 #include <linux/clk.h>
30 #include <linux/backlight.h>
31 #include <linux/timer.h>
32 #include <linux/time.h>
33 #include <linux/wait.h>
34 #include <linux/earlysuspend.h>
35 #include <linux/cpufreq.h>
36 #include <linux/wakelock.h>
39 #include <asm/div64.h>
40 #include <asm/uaccess.h>
48 #include <linux/completion.h>
50 #include <linux/hdmi.h>
53 #include <mach/iomux.h>
54 #include <mach/gpio.h>
55 #include <mach/board.h>
56 #include <mach/rk29_iomap.h>
58 #include <mach/rk29-ipp.h>
60 #include "./display/screen/screen.h"
62 #define ANDROID_USE_THREE_BUFS 0 //android use three buffers to accelerate UI display in rgb plane
63 #define CURSOR_BUF_SIZE 256 //RK2818 cursor need 256B buf
64 int rk29_cursor_buf[CURSOR_BUF_SIZE];
101 #define fbprintk(msg...) printk(msg);
103 #define fbprintk(msg...)
108 #define fbprintk2(msg...) printk(msg);
110 #define fbprintk2(msg...)
113 #define LcdReadBit(inf, addr, msk) ((inf->regbak.addr=inf->preg->addr)&(msk))
114 #define LcdWrReg(inf, addr, val) inf->preg->addr=inf->regbak.addr=(val)
115 #define LcdRdReg(inf, addr) (inf->preg->addr)
116 #define LcdSetBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) |= (msk))
117 #define LcdClrBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) &= ~(msk))
118 #define LcdSetRegisterBit(inf, addr, msk) inf->preg->addr=((inf->preg->addr) |= (msk))
119 #define LcdMskReg(inf, addr, msk, val) (inf->regbak.addr)&=~(msk); inf->preg->addr=(inf->regbak.addr|=(val))
122 #define IsMcuLandscape() ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
123 #define IsMcuUseFmk() ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
125 #define CalScaleW0(x, y) (((u32)x*0x1000)/y)
128 struct fb_bitfield red;
129 struct fb_bitfield green;
130 struct fb_bitfield blue;
131 struct fb_bitfield transp;
134 static struct rk29fb_rgb def_rgb_16 = {
135 red: { offset: 11, length: 5, },
136 green: { offset: 5, length: 6, },
137 blue: { offset: 0, length: 5, },
138 transp: { offset: 0, length: 0, },
142 volatile u32 y_offset;
143 volatile u32 c_offset;
151 u32 xpos; //size in panel
153 u32 xsize; //start point in panel
157 wait_queue_head_t wait;
158 struct win_set mirror;
159 struct win_set displ;
184 void __iomem *reg_vir_base; // virtual basic address of lcdc register
185 u32 reg_phy_base; // physical basic address of lcdc register
186 u32 len; // physical map length of lcdc register
190 struct clk *dclk; //lcdc dclk
191 struct clk *dclk_parent; //lcdc dclk divider frequency source
192 struct clk *dclk_divider; //lcdc demodulator divider frequency
193 struct clk *aclk; //lcdc share memory frequency
194 struct clk *aclk_parent; //lcdc aclk divider frequency source
195 struct clk *aclk_ddr_lcdc; //DDR LCDC AXI clock disable.
196 struct clk *aclk_disp_matrix; //DISPLAY matrix AXI clock disable.
197 struct clk *hclk_cpu_display; //CPU DISPLAY AHB bus clock disable.
198 struct clk *pd_display; // display power domain
199 unsigned long dclk_rate;
201 /* lcdc reg base address and backup reg */
206 int fb0_color_deepth;
207 /* variable used in mcu panel */
211 struct timer_list mcutimer;
217 /* external memery */
218 char __iomem *screen_base2;
220 unsigned long smem_start2;
222 char __iomem *cursor_base; /* cursor Virtual address*/
223 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
224 unsigned long cursor_start;
226 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
227 struct rk29fb_screen panel2_info; // 2nd panel
228 struct rk29fb_screen *cur_screen;
229 #if 0 //def CONFIG_CPU_FREQ
230 struct notifier_block freq_transition;
235 typedef enum _TRSP_MODE
247 struct platform_device *g_pdev = NULL;
248 //static int win1fb_set_par(struct fb_info *info);
251 #define CHK_SUSPEND(inf) \
252 if(inf->in_suspend) { \
253 fbprintk(">>>>>> fb is in suspend! return! \n"); \
257 #define CHK_SUSPEND(inf)
260 static DECLARE_WAIT_QUEUE_HEAD(wq);
261 static int wq_condition = 0;
262 static int wq_condition2 = 0;
263 #if ANDROID_USE_THREE_BUFS
264 static int new_frame_seted = 1;
266 static struct wake_lock idlelock; /* only for fb */
267 #ifdef CONFIG_FB_ROTATE_VIDEO
269 static bool has_set_rotate;
270 static u32 last_yuv_phy[2] = {0,0};
273 int mcu_do_refresh(struct rk29fb_inf *inf)
275 if(inf->mcu_stopflush) return 0;
277 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
282 inf->mcu_needflush = 1;
286 // not use frame mark
287 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
289 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
291 inf->mcu_needflush = 1;
295 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
296 inf->mcu_needflush = 0;
298 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
305 void mcutimer_callback(unsigned long arg)
307 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
308 static int waitcnt = 0;
310 mod_timer(&inf->mcutimer, jiffies + HZ/10);
312 switch(inf->mcu_status)
315 inf->mcu_status = MS_MCU;
318 if(inf->mcu_usetimer) mcu_do_refresh(inf);
321 inf->mcu_status = MS_EWAITEND;
329 inf->mcu_status = MS_EEND;
333 inf->mcu_status = MS_MCU;
336 inf->mcu_status = MS_MCU;
341 int mcu_refresh(struct rk29fb_inf *inf)
343 static int mcutimer_inited = 0;
345 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
350 init_timer(&inf->mcutimer);
351 inf->mcutimer.function = mcutimer_callback;
352 inf->mcutimer.expires = jiffies + HZ/5;
353 inf->mcu_status = MS_IDLE;
354 add_timer(&inf->mcutimer);
357 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
362 int mcu_ioctl(unsigned int cmd, unsigned long arg)
364 struct rk29fb_inf *inf = NULL;
365 if(!g_pdev) return -1;
367 inf = dev_get_drvdata(&g_pdev->dev);
372 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
373 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
374 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
378 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
379 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
383 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
384 LcdWrReg(inf, REG_CFG_DONE, 0x01);
394 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
396 struct platform_device *pdev = (struct platform_device*)dev_id;
397 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
398 struct rk29fb_screen *screen;
400 if(!inf) return IRQ_HANDLED;
402 screen = inf->cur_screen;
404 if(0==screen->mcu_usefmk) {
408 if(inf->mcu_fmksync == 1)
411 inf->mcu_fmksync = 1;
412 if(inf->mcu_needflush)
414 inf->mcu_needflush = 0;
416 if(inf->cur_screen->refresh)
417 inf->cur_screen->refresh(REFRESH_PRE);
418 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
420 inf->mcu_fmksync = 0;
425 int init_lcdc(struct fb_info *info)
427 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
430 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
432 inf->clk = clk_get(NULL, "hclk_lcdc");
433 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
434 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
435 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
436 inf->pd_display = clk_get(NULL, "pd_display");
437 if ((IS_ERR(inf->clk)) ||
438 (IS_ERR(inf->aclk_ddr_lcdc)) ||
439 (IS_ERR(inf->aclk_disp_matrix)) ||
440 (IS_ERR(inf->hclk_cpu_display)) ||
441 (IS_ERR(inf->pd_display)))
443 printk(KERN_ERR "failed to get lcdc_hclk source\n");
444 return PTR_ERR(inf->clk);
446 clk_enable(inf->aclk_disp_matrix);
447 clk_enable(inf->hclk_cpu_display);
448 clk_enable(inf->clk);
449 clk_enable(inf->pd_display);
450 //pmu_set_power_domain(PD_DISPLAY, 1);
451 clk_enable(inf->aclk_ddr_lcdc);
453 // set AHB access rule and disable all windows
454 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
455 LcdWrReg(inf, SWAP_CTRL, 0);
456 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
457 LcdWrReg(inf, AXI_MS_ID, 0x54321);
459 // and mcu holdmode; and set win1 top.
460 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
461 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
463 // disable blank out, black out, tristate out, yuv2rgb bypass
464 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
465 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
466 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
467 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
470 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
471 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
473 LcdWrReg(inf, DSP_CTRL1, 0);
475 // initialize all interrupt
476 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
478 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
480 LcdWrReg(inf, INT_STATUS, clr | msk);
482 // let above to take effect
483 LcdWrReg(inf, REG_CFG_DONE, 0x01);
488 void load_screen(struct fb_info *info, bool initscreen)
491 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
492 struct rk29fb_screen *screen = inf->cur_screen;
494 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
495 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
496 u16 x_res = screen->x_res, y_res = screen->y_res;
497 u32 aclk_rate = 150000000;
500 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
504 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
506 // set the rgb or mcu
507 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
509 // set out format and mcu timing
510 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
511 if(mcu_total>31) mcu_total = 31;
512 if(mcu_total<3) mcu_total = 3;
513 mcu_rwstart = (mcu_total+1)/4 - 1;
514 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
515 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
516 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
518 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
519 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
521 LcdMskReg(inf, MCU_TIMING_CTRL,
522 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
523 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
524 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
525 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
526 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
529 // set synchronous pin polarity and data pin swap rule
530 switch (screen->face)
534 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
538 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
542 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
546 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
550 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
551 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
554 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
555 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
560 LcdMskReg(inf, DSP_CTRL0,
561 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
562 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
563 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
564 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
567 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
569 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
570 v_OUTPUT_RB_SWAP(screen->swap_rb) | v_OUTPUT_RG_SWAP(screen->swap_rg) | v_DELTA_SWAP(screen->swap_delta) | v_DUMMY_SWAP(screen->swap_dumy));
572 // set horizontal & vertical out timing
573 if(SCREEN_MCU==inf->cur_screen->type)
575 right_margin = x_res/6;
578 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
579 screen->hsync_len , screen->left_margin , x_res , right_margin );
580 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
581 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
582 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
583 v_BIT12HI(screen->hsync_len + screen->left_margin));
585 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
586 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
587 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
588 v_BIT11HI(screen->vsync_len + screen->upper_margin));
590 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
591 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
593 // let above to take effect
594 LcdWrReg(inf, REG_CFG_DONE, 0x01);
596 inf->dclk = clk_get(NULL, "dclk_lcdc");
597 if (IS_ERR(inf->dclk))
599 printk(KERN_ERR "failed to get lcd dclock source\n");
602 inf->dclk_divider= clk_get(NULL, "dclk_lcdc_div");
603 if (IS_ERR(inf->dclk_divider))
605 printk(KERN_ERR "failed to get lcd clock lcdc_divider source \n");
609 if((inf->cur_screen->type == SCREEN_HDMI) || (inf->cur_screen->type == SCREEN_TVOUT)){
610 inf->dclk_parent = clk_get(NULL, "codec_pll");
611 clk_set_rate(inf->dclk_parent, 594000000);
613 inf->dclk_parent = clk_get(NULL, "general_pll");
616 if (IS_ERR(inf->dclk_parent))
618 printk(KERN_ERR "failed to get lcd dclock parent source\n");
622 inf->aclk = clk_get(NULL, "aclk_lcdc");
623 if (IS_ERR(inf->aclk))
625 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
628 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
629 if (IS_ERR(inf->dclk_parent))
631 printk(KERN_ERR "failed to get lcd dclock parent source\n");
636 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
638 if(initscreen == 0) //not init
640 clk_disable(inf->dclk);
641 clk_disable(inf->aclk);
644 clk_disable(inf->aclk_ddr_lcdc);
645 clk_disable(inf->aclk_disp_matrix);
646 clk_disable(inf->hclk_cpu_display);
648 clk_disable(inf->clk);
649 clk_set_parent(inf->dclk_divider, inf->dclk_parent);
650 clk_set_parent(inf->dclk, inf->dclk_divider);
651 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
653 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
655 ret = clk_set_rate(inf->dclk_divider, screen->pixclock);
658 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
661 if(screen->lcdc_aclk){
662 aclk_rate = screen->lcdc_aclk;
664 ret = clk_set_rate(inf->aclk, aclk_rate);
666 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
669 clk_enable(inf->aclk_ddr_lcdc);
670 clk_enable(inf->aclk_disp_matrix);
671 clk_enable(inf->hclk_cpu_display);
673 clk_enable(inf->aclk);
674 clk_enable(inf->clk);
675 clk_enable(inf->dclk);
683 #if 0 //def CONFIG_CPU_FREQ
685 * CPU clock speed change handler. We need to adjust the LCD timing
686 * parameters when the CPU clock is adjusted by the power management
689 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
692 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
694 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
695 struct rk29fb_screen *screen = inf->cur_screen;
700 case CPUFREQ_PRECHANGE:
702 case CPUFREQ_POSTCHANGE:
704 dclk_rate = screen->pixclock * 1000000;
706 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
708 clk_set_rate(inf->dclk_divider, dclk_rate);
716 static inline unsigned int chan_to_field(unsigned int chan,
717 struct fb_bitfield *bf)
720 chan >>= 16 - bf->length;
721 return chan << bf->offset;
724 static int fb_setcolreg(unsigned regno,
725 unsigned red, unsigned green, unsigned blue,
726 unsigned transp, struct fb_info *info)
729 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
731 switch (info->fix.visual) {
732 case FB_VISUAL_TRUECOLOR:
733 /* true-colour, use pseudo-palette */
735 u32 *pal = info->pseudo_palette;
736 val = chan_to_field(red, &info->var.red);
737 val |= chan_to_field(green, &info->var.green);
738 val |= chan_to_field(blue, &info->var.blue);
743 return -1; /* unknown type */
749 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
752 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
754 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
756 LcdWrReg(inf, REG_CFG_DONE, 0x01);
760 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
762 struct rk29fb_screen *screen = inf->cur_screen;
765 if (x >= 0x800 || y >= 0x800 )
767 //printk("%s: %08x,%08x \n",__func__, x, y);
768 x += (screen->left_margin + screen->hsync_len);
769 y += (screen->upper_margin + screen->vsync_len);
770 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
771 LcdWrReg(inf, REG_CFG_DONE, 0x01);
776 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
778 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
779 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
780 LcdWrReg(inf, REG_CFG_DONE, 0x01);
784 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
785 int rk29_set_cursor_img_transform(char *data)
788 char *dst = (char*)rk29_cursor_buf;
789 unsigned char dmsk = 0;
790 unsigned int op,shift,offset;
792 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
793 * clears it to transparent then combines the cursor
794 * shape plane with the colour plane to set the
796 for (y = 0; y < 32; y++)
798 for (x = 0; x < 32; x++)
805 op = (dmsk & 0x80) ? 2 : 3;
808 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
818 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
822 rk29_set_cursor_img_transform(data);
826 rk29_set_cursor_img_transform(cursor_img);
828 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
829 LcdSetRegisterBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
830 LcdWrReg(inf, REG_CFG_DONE, 0x01);
834 int rk29_set_cursor_test(struct fb_info *info)
836 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
837 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
838 rk29_set_cursor_pos(inf, 0, 0);
839 rk29_set_cursor_img(inf, 0);
840 rk29_set_cursor_en(inf, 1);
845 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
847 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
849 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
851 /* check not being asked to exceed capabilities */
853 if (cursor->image.width > 32)
856 if (cursor->image.height > 32)
859 if (cursor->image.depth > 1)
863 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
865 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
868 if (cursor->set & FB_CUR_SETPOS)
870 unsigned int x = cursor->image.dx;
871 unsigned int y = cursor->image.dy;
873 if (x >= 0x800 || y >= 0x800 )
875 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
879 if (cursor->set & FB_CUR_SETCMAP)
881 unsigned int bg_col = cursor->image.bg_color;
882 unsigned int fg_col = cursor->image.fg_color;
884 fbprintk("%s: update cmap (%08x,%08x)\n",
885 __func__, bg_col, fg_col);
887 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
888 v_HWC_R(info->cmap.red[bg_col]>>8) | v_HWC_G(info->cmap.green[bg_col]>>8) | v_HWC_B(info->cmap.blue[bg_col]>>8));
890 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
891 v_HWC_R(info->cmap.red[fg_col]>>8) | v_HWC_G(info->cmap.green[fg_col]>>8) | v_HWC_B(info->cmap.blue[fg_col]>>8));
894 if ((cursor->set & FB_CUR_SETSIZE ||
895 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
896 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
898 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
899 * clears it to transparent then combines the cursor
900 * shape plane with the colour plane to set the
903 const unsigned char *pcol = cursor->image.data;
904 const unsigned char *pmsk = cursor->mask;
906 unsigned long cursor_mem_start;
907 unsigned char dcol = 0;
908 unsigned char dmsk = 0;
911 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
912 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
914 fbprintk("%s: setting shape (%d,%d)\n",
915 __func__, cursor->image.width, cursor->image.height);
917 memset(dst, 0, CURSOR_BUF_SIZE);
919 for (y = 0; y < cursor->image.height; y++)
921 for (x = 0; x < cursor->image.width; x++)
932 op = (dcol & 1) ? 1 : 3;
933 op <<= ((x % 4) * 2);
934 *(u8*)(dst+(x/4)) |= op;
939 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
940 LcdWrReg(inf, HWC_MST, cursor_mem_start);
941 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
942 if(SCREEN_MCU == inf->cur_screen->type) {
943 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
947 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
949 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
956 static int win0_blank(int blank_mode, struct fb_info *info)
958 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
960 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
966 case FB_BLANK_UNBLANK:
967 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
970 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
973 LcdWrReg(inf, REG_CFG_DONE, 0x01);
979 static int win0_set_par(struct fb_info *info)
981 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
982 struct rk29fb_screen *screen = inf->cur_screen;
983 struct fb_var_screeninfo *var = &info->var;
984 struct fb_fix_screeninfo *fix = &info->fix;
985 struct win0_par *par = info->par;
987 u32 xact = var->xres; /* visible resolution */
988 u32 yact = var->yres;
989 u32 xvir = var->xres_virtual; /* virtual resolution */
990 u32 yvir = var->yres_virtual;
991 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
992 //u32 yact_st = var->yoffset; /* resolution */
993 u32 xpos = par->xpos;
994 u32 ypos = par->ypos;
996 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
997 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
999 u32 y_addr = 0; //user alloc buf addr y
1002 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1006 if(((var->rotate == 270)||(var->rotate == 90)) && (inf->video_mode))
1008 #ifdef CONFIG_FB_ROTATE_VIDEO
1009 // if(xact > screen->x_res)
1011 xact = screen->x_res; /* visible resolution */
1012 yact = screen->y_res;
1013 xvir = screen->x_res; /* virtual resolution */
1014 yvir = screen->y_res;
1016 // xact = var->yres; /* visible resolution */
1017 // yact = var->xres;
1018 // xvir = var->yres_virtual; /* virtual resolution */
1019 // yvir = var->xres_virtual;
1021 #else //CONFIG_FB_ROTATE_VIDEO
1022 printk("LCDC not support rotate!\n");
1027 // calculate the display phy address
1028 y_addr = fix->smem_start + par->y_offset;
1029 uv_addr = fix->mmio_start + par->c_offset;
1031 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1032 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1034 switch (par->format)
1037 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1038 ScaleCbrY = CalScaleW0(yact, par->ysize);
1042 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1043 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1046 ScaleCbrX= CalScaleW0(xact, par->xsize);
1047 ScaleCbrY = CalScaleW0(yact, par->ysize);
1053 xpos += (screen->left_margin + screen->hsync_len);
1054 ypos += (screen->upper_margin + screen->vsync_len);
1056 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1057 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1059 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1061 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1062 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1063 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1064 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1065 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1066 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1071 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1072 v_W0_YRGB_8_SWAP(1) | v_W0_YRGB_16_SWAP(1) | v_W0_YRGB_R_SHIFT_SWAP(1) | v_W0_565_RB_SWAP(0) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0));
1075 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1076 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(0) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0));
1079 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1080 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(0) |
1081 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1084 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1085 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(0) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0) );
1089 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1095 static int win0_pan( struct fb_info *info )
1097 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1098 // struct fb_var_screeninfo *var0 = &info->var;
1099 struct fb_fix_screeninfo *fix0 = &info->fix;
1100 struct win0_par *par = info->par;
1101 u32 y_addr=0, uv_addr=0;
1103 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1107 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1108 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1110 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1111 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1112 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1114 // enable win0 after the win0 addr is seted
1115 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1121 static int win1_blank(int blank_mode, struct fb_info *info)
1123 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1125 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1131 case FB_BLANK_UNBLANK:
1132 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1135 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1138 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1144 static int win1_set_par(struct fb_info *info)
1146 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1147 struct fb_fix_screeninfo *fix = &info->fix;
1148 struct rk29fb_screen *screen = inf->cur_screen;
1149 struct win0_par *par = info->par;
1150 struct fb_var_screeninfo *var = &info->var;
1152 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1154 u16 xres_virtual = 0; //virtual screen size
1156 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1157 //u16 ypos_virtual = var->yoffset;
1159 u16 xpos = par->xpos; //visiable offset in panel
1160 u16 ypos = par->ypos;
1162 u8 trspmode = TRSP_CLOSE;
1165 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1167 #ifdef CONFIG_FB_SCALING_OSD
1168 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1169 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1171 addr = fix->mmio_start + par->y_offset;
1172 xres_virtual = screen->x_res; //virtual screen size
1177 addr = fix->smem_start + par->y_offset;
1178 xres_virtual = var->xres_virtual; //virtual screen size
1180 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1182 xpos += (screen->left_margin + screen->hsync_len);
1183 ypos += (screen->upper_margin + screen->vsync_len);
1185 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1187 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1188 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1190 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1192 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1193 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1195 // enable win1 color key and set the color to black(rgb=0)
1196 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1198 if(1==par->format) //rgb565
1200 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1201 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1205 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1206 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1208 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1211 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1216 static int win1_pan( struct fb_info *info )
1218 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1219 struct fb_fix_screeninfo *fix1 = &info->fix;
1220 struct win0_par *par = info->par;
1223 #ifdef CONFIG_FB_SCALING_OSD
1224 struct rk29fb_screen *screen = inf->cur_screen;
1225 struct fb_var_screeninfo *var = &info->var;
1226 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1227 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1229 addr = fix1->mmio_start + par->y_offset;
1234 addr = fix1->smem_start + par->y_offset;
1237 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1239 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1240 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1246 static int fb0_blank(int blank_mode, struct fb_info *info)
1248 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1250 if(inf->video_mode == 1)
1252 win1_blank(blank_mode, info);
1256 win0_blank(blank_mode, info);
1261 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1263 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1264 struct rk29fb_screen *screen = inf->cur_screen;
1265 u16 xpos = (var->nonstd>>8) & 0xfff;
1266 u16 ypos = (var->nonstd>>20) & 0xfff;
1267 u16 xlcd = screen->x_res;
1268 u16 ylcd = screen->y_res;
1270 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1274 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1275 0==var->xres || 0==var->yres || var->xres<16 ||
1276 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1278 printk(">>>>>> fb0_check_var fail 1!!! \n");
1279 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1280 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1281 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1285 if( (var->xoffset+var->xres)>var->xres_virtual ||
1286 (var->yoffset+var->yres)>var->yres_virtual )
1288 printk(">>>>>> fb0_check_var fail 2!!! \n");
1289 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1290 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1291 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1295 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1296 switch(var->bits_per_pixel)
1299 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1300 var->xres = (var->xres + 0x1) & (~0x1);
1301 var->xoffset = (var->xoffset) & (~0x1);
1304 var->bits_per_pixel = 32;
1312 static int fb0_set_par(struct fb_info *info)
1314 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1315 struct fb_var_screeninfo *var = &info->var;
1316 struct fb_fix_screeninfo *fix = &info->fix;
1317 struct rk29fb_screen *screen = inf->cur_screen;
1318 struct win0_par *par = info->par;
1320 u32 offset=0, smem_len=0;
1321 u16 xres_virtual = var->xres_virtual; //virtual screen size
1322 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1323 u16 ypos_virtual = var->yoffset;
1325 #ifdef CONFIG_FB_SCALING_OSD
1326 struct rk29_ipp_req ipp_req;
1330 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1334 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1335 #if !defined(CONFIG_FB_SCALING_OSD)
1336 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1339 switch(var->bits_per_pixel)
1343 //fix->line_length = 2 * xres_virtual;
1344 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1346 #ifdef CONFIG_FB_SCALING_OSD
1347 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1348 ipp_req.src0.fmt = IPP_RGB_565;
1349 ipp_req.dst0.fmt = IPP_RGB_565;
1351 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1356 fix->line_length = 4 * xres_virtual;
1357 #ifdef CONFIG_FB_SCALING_OSD
1358 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1359 ipp_req.src0.fmt = IPP_XRGB_8888;
1360 ipp_req.dst0.fmt = IPP_XRGB_8888;
1362 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1366 smem_len = fix->line_length * var->yres_virtual;
1367 //map_size = PAGE_ALIGN(smem_len);
1369 if (smem_len > fix->smem_len) // buffer need realloc
1371 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1372 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1373 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1377 par->addr_seted = 1;
1378 #if ANDROID_USE_THREE_BUFS
1379 if(0==new_frame_seted) {
1381 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1383 new_frame_seted = 0;
1386 if(inf->video_mode == 1)
1388 #ifdef CONFIG_FB_SCALING_OSD
1389 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1390 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1394 par->xsize = screen->x_res;
1395 par->ysize = screen->y_res;
1396 par->y_offset = dstoffset;
1398 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1399 ipp_req.src0.w = var->xres;
1400 ipp_req.src0.h = var->yres;
1402 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1403 ipp_req.dst0.w = screen->x_res;
1404 ipp_req.dst0.h = screen->y_res;
1406 ipp_req.src_vir_w = ipp_req.src0.w;
1407 ipp_req.dst_vir_w = ipp_req.dst0.w;
1408 ipp_req.timeout = 100;
1409 ipp_req.flag = IPP_ROT_0;
1410 ipp_do_blit(&ipp_req);
1414 par->y_offset = offset;
1415 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1416 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1417 par->xsize = var->xres; //visiable size in panel
1418 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1424 par->y_offset = offset;
1427 par->xsize = screen->x_res;
1428 par->ysize = screen->y_res;
1435 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1438 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1439 struct fb_var_screeninfo *var1 = &info->var;
1440 struct rk29fb_screen *screen = inf->cur_screen;
1441 struct win0_par *par = info->par;
1444 u16 ypos_virtual = var->yoffset;
1445 u16 xpos_virtual = var->xoffset;
1446 #ifdef CONFIG_FB_SCALING_OSD
1447 struct fb_fix_screeninfo *fix = &info->fix;
1448 struct rk29_ipp_req ipp_req;
1451 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1455 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1456 #if !defined(CONFIG_FB_SCALING_OSD)
1457 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1460 switch(var1->bits_per_pixel)
1463 var->xoffset = (var->xoffset) & (~0x1);
1464 #ifdef CONFIG_FB_SCALING_OSD
1465 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1466 ipp_req.src0.fmt = IPP_RGB_565;
1467 ipp_req.dst0.fmt = IPP_RGB_565;
1469 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1472 #ifdef CONFIG_FB_SCALING_OSD
1473 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1474 ipp_req.src0.fmt = IPP_XRGB_8888;
1475 ipp_req.dst0.fmt = IPP_XRGB_8888;
1477 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1483 if(inf->video_mode == 1)
1485 #ifdef CONFIG_FB_SCALING_OSD
1486 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1487 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1489 par->y_offset = dstoffset;
1491 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1492 ipp_req.src0.w = var->xres;
1493 ipp_req.src0.h = var->yres;
1495 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1496 ipp_req.dst0.w = screen->x_res;
1497 ipp_req.dst0.h = screen->y_res;
1499 ipp_req.src_vir_w = ipp_req.src0.w;
1500 ipp_req.dst_vir_w = ipp_req.dst0.w;
1501 ipp_req.timeout = 100;
1502 ipp_req.flag = IPP_ROT_0;
1503 ipp_do_blit(&ipp_req);
1508 par->y_offset = offset;
1513 par->y_offset = offset;
1516 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1517 #if !ANDROID_USE_THREE_BUFS
1518 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1519 if(SCREEN_MCU == inf->cur_screen->type) {
1520 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1524 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1530 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1532 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1533 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1539 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1542 inf->mcu_usetimer = 0;
1545 case FBIOPUT_16OR32:
1547 inf->fb0_color_deepth = arg;
1550 case FBIOPUT_FBPHYADD:
1551 return info->fix.smem_start;
1552 case FBIOGET_OVERLAY_STATE:
1553 return inf->video_mode;
1554 case FBIOGET_SCREEN_STATE:
1555 return inf->cur_screen->type;
1557 case FBIOPUT_SET_CURSOR_EN:
1560 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1562 rk29_set_cursor_en(inf, en);
1565 case FBIOPUT_SET_CURSOR_POS:
1567 struct fbcurpos pos;
1568 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1570 rk29_set_cursor_pos(inf, pos.x , pos.y);
1573 case FBIOPUT_SET_CURSOR_IMG:
1575 char cursor_buf[CURSOR_BUF_SIZE];
1576 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1578 rk29_set_cursor_img(inf, cursor_buf);
1581 case FBIOPUT_SET_CURSOR_CMAP:
1583 struct fb_image img;
1584 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1586 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1589 case FBIOPUT_GET_CURSOR_RESOLUTION:
1592 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1593 if(inf->fb1->var.rotate == 270) {
1594 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1595 panel_size[1] = inf->cur_screen->x_res;
1597 panel_size[0] = inf->cur_screen->x_res;
1598 panel_size[1] = inf->cur_screen->y_res;
1600 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1603 case FBIOPUT_GET_CURSOR_EN:
1605 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1606 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1615 static int fb1_blank(int blank_mode, struct fb_info *info)
1617 win0_blank(blank_mode, info);
1621 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1623 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1624 struct rk29fb_screen *screen = inf->cur_screen;
1626 u32 ScaleYRGBY=0x1000;
1627 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1628 u16 ypos = (var->nonstd>>20) & 0xfff;
1629 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1630 u16 ysize = (var->grayscale>>20) & 0xfff;
1631 u16 xlcd = screen->x_res; //size of panel
1632 u16 ylcd = screen->y_res;
1635 struct hdmi *hdmi = get_hdmi_struct(0);
1638 if((var->rotate == 270)||(var->rotate == 90)) {
1639 #ifdef CONFIG_FB_ROTATE_VIDEO
1640 xlcd = screen->y_res;
1641 ylcd = screen->x_res;
1642 #else //CONFIG_FB_ROTATE_VIDEO
1643 printk("LCDC not support rotate!\n");
1648 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1649 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1650 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1651 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1653 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1657 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1658 0==var->xres || 0==var->yres || var->xres<16 ||
1659 0==xsize || 0==ysize || xsize<16 ||
1660 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1662 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1663 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1664 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1665 var->bits_per_pixel, var->bits_per_pixel);
1669 if( (var->xoffset+var->xres)>var->xres_virtual ||
1670 (var->yoffset+var->yres)>var->yres_virtual ||
1671 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1673 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1674 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1675 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1676 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1680 switch(var->nonstd&0x0f)
1683 switch(var->bits_per_pixel)
1686 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1687 var->xres = (var->xres + 0x1) & (~0x1);
1688 var->xoffset = (var->xoffset) & (~0x1);
1691 var->bits_per_pixel = 32;
1694 var->nonstd &= ~0xc0; //not support I2P in this format
1697 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1698 var->xres = (var->xres + 0x3) & (~0x3);
1699 var->xoffset = (var->xoffset) & (~0x3);
1702 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1703 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1704 var->xres = (var->xres + 0x3) & (~0x3);
1705 var->yres = (var->yres + 0x1) & (~0x1);
1706 var->xoffset = (var->xoffset) & (~0x3);
1707 var->yoffset = (var->yoffset) & (~0x1);
1710 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1711 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1712 var->xres = (var->xres + 0x3) & (~0x3);
1713 var->yres = (var->yres + 0x1) & (~0x1);
1714 var->xoffset = (var->xoffset) & (~0x3);
1715 var->yoffset = (var->yoffset) & (~0x1);
1716 var->nonstd &= ~0xc0; //not support I2P in this format
1720 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1721 var->xres = (var->xres + 0x3) & (~0x3);
1722 var->xoffset = (var->xoffset) & (~0x3);
1723 var->nonstd &= ~0xc0; //not support I2P in this format
1726 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1730 if((var->rotate == 270)||(var->rotate == 90))
1739 ScaleYRGBY = CalScaleW0(yres, ysize);
1741 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1743 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1746 if(inf->video_mode == 1) {
1747 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1749 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1750 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1751 init_completion(&hdmi->complete);
1753 wait_for_completion_interruptible_timeout(&hdmi->complete,
1754 msecs_to_jiffies(10000));
1761 static int fb1_set_par(struct fb_info *info)
1763 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1764 struct rk29fb_screen *screen = inf->cur_screen;
1765 struct fb_var_screeninfo *var = &info->var;
1766 struct fb_fix_screeninfo *fix = &info->fix;
1767 struct win0_par *par = info->par;
1770 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1772 //u32 xact = var->xres; /* visible resolution */
1773 //u32 yact = var->yres;
1774 u32 xvir = var->xres_virtual; /* virtual resolution */
1775 u32 yvir = var->yres_virtual;
1776 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1777 u32 yact_st = var->yoffset; /* resolution */
1779 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1780 u16 ypos = (var->nonstd>>20) & 0xfff;
1781 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1782 u16 ysize = (var->grayscale>>20) & 0xfff;
1784 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1785 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1787 u8 data_format = var->nonstd&0x0f;
1788 // u32 win0_en = var->reserved[2];
1789 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1790 // u32 uv_addr = var->reserved[4];
1792 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1795 if((var->rotate == 270)||(var->rotate == 90))
1797 #if CONFIG_FB_ROTATE_VIDEO
1798 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1799 ypos = (var->nonstd>>8) & 0xfff;
1800 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1801 ysize = (var->grayscale>>8) & 0xfff;
1802 #else //CONFIG_FB_ROTATE_VIDEO
1803 printk("LCDC not support rotate!\n");
1807 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1808 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1809 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1810 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1812 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1813 switch (data_format)
1816 switch(var->bits_per_pixel)
1820 fix->line_length = 2 * xvir;
1821 par->y_offset = (yact_st*xvir + xact_st)*2;
1825 fix->line_length = 4 * xvir;
1826 par->y_offset = (yact_st*xvir + xact_st)*4;
1834 fix->line_length = xvir;
1835 cblen = crlen = (xvir*yvir)/2;
1836 par->y_offset = yact_st*xvir + xact_st;
1837 par->c_offset = yact_st*xvir + xact_st;
1841 fix->line_length = xvir;
1842 cblen = crlen = (xvir*yvir)/4;
1844 par->y_offset = yact_st*xvir + xact_st;
1845 par->c_offset = (yact_st/2)*xvir + xact_st;
1850 fix->line_length = xvir;
1851 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1852 par->c_offset = (yact_st/2)*xvir + xact_st;
1853 cblen = crlen = (xvir*yvir)/4;
1858 fix->line_length = xvir;
1859 par->y_offset = yact_st*xvir + xact_st;
1860 par->c_offset = yact_st*2*xvir + xact_st*2;
1861 cblen = crlen = (xvir*yvir);
1867 smem_len = fix->line_length * yvir + cblen + crlen;
1868 map_size = PAGE_ALIGN(smem_len);
1870 // fix->smem_start = y_addr;
1871 fix->smem_len = smem_len;
1872 // fix->mmio_start = uv_addr;
1874 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1875 fbprintk("buffer alloced by user fix->smem_start = %8x, fix->smem_len = %8x, fix->mmio_start = %8x \n", (u32)fix->smem_start, (u32)fix->smem_len, (u32)fix->mmio_start);
1877 par->format = format;
1884 if ( wq_condition2 == 0 ) {
1885 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
1889 #if CONFIG_FB_ROTATE_VIDEO
1890 //need refresh ,zyc add
1891 if(has_set_rotate == true)
1894 struct rk29_ipp_req ipp_req;
1895 static u32 dstoffset = 0;
1896 static int fb_index = 0;
1898 yuv_phy[0] = last_yuv_phy[0];
1899 yuv_phy[1] = last_yuv_phy[1];
1900 yuv_phy[0] += par->y_offset;
1901 yuv_phy[1] += par->c_offset;
1902 if((var->rotate == 90) ||(var->rotate == 270))
1904 dstoffset = (dstoffset+1)%2;
1905 ipp_req.src0.fmt = 3;
1906 ipp_req.src0.YrgbMst = yuv_phy[0];
1907 ipp_req.src0.CbrMst = yuv_phy[1];
1908 ipp_req.src0.w = var->xres;
1909 ipp_req.src0.h = var->yres;
1911 ipp_req.dst0.fmt = 3;
1912 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
1913 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
1914 // if(var->xres > screen->x_res)
1916 ipp_req.dst0.w = screen->x_res;
1917 ipp_req.dst0.h = screen->y_res;
1919 // ipp_req.dst0.w = var->yres;
1920 // ipp_req.dst0.h = var->xres;
1922 ipp_req.src_vir_w = ipp_req.src0.w;
1923 ipp_req.dst_vir_w = ipp_req.dst0.w;
1924 ipp_req.timeout = 100;
1925 if(var->rotate == 90)
1926 ipp_req.flag = IPP_ROT_90;
1927 else if(var->rotate == 270)
1928 ipp_req.flag = IPP_ROT_270;
1930 ipp_do_blit(&ipp_req);
1931 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
1932 yuv_phy[0] = ipp_req.dst0.YrgbMst;
1933 yuv_phy[1] = ipp_req.dst0.CbrMst;
1934 fix->smem_start = yuv_phy[0];
1935 fix->mmio_start = yuv_phy[1];
1940 fix->smem_start = yuv_phy[0];
1941 fix->mmio_start = yuv_phy[1];
1944 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
1945 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
1946 // enable win0 after the win0 par is seted
1947 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
1948 par->addr_seted = 1;
1949 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1950 if(par->addr_seted ) {
1951 unsigned long flags;
1953 local_irq_save(flags);
1954 par->mirror.y_offset = yuv_phy[0];
1955 par->mirror.c_offset = yuv_phy[1];
1956 local_irq_restore(flags);
1959 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
1964 has_set_rotate = false;
1969 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1971 struct win0_par *par = info->par;
1972 // enable win0 after the win0 addr is seted
1979 int fb1_open(struct fb_info *info, int user)
1981 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1982 struct win0_par *par = info->par;
1984 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1987 par->addr_seted = 0;
1988 inf->video_mode = 1;
1991 printk(">>>>>> fb1 has opened! \n");
1995 fb0_set_par(inf->fb0);
1996 fb0_pan_display(&inf->fb0->var, inf->fb0);
1997 win0_blank(FB_BLANK_POWERDOWN, info);
2002 int fb1_release(struct fb_info *info, int user)
2004 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2005 struct win0_par *par = info->par;
2006 struct fb_var_screeninfo *var0 = &info->var;
2008 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2012 inf->video_mode = 0;
2014 par->addr_seted = 0;
2015 //win0_blank(FB_BLANK_POWERDOWN, info);
2016 fb0_set_par(inf->fb0);
2017 fb0_pan_display(&inf->fb0->var, inf->fb0);
2018 win1_blank(FB_BLANK_POWERDOWN, info);
2019 // wait for lcdc stop access memory
2023 info->screen_base = 0;
2024 info->fix.smem_start = 0;
2025 info->fix.smem_len = 0;
2026 // clean the var param
2027 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2033 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2035 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2036 struct win0_par *par = info->par;
2037 struct fb_fix_screeninfo *fix0 = &info->fix;
2038 struct fb_var_screeninfo *var = &info->var;
2039 void __user *argp = (void __user *)arg;
2041 #ifdef CONFIG_FB_ROTATE_VIDEO
2042 struct rk29fb_screen *screen = inf->cur_screen;
2043 struct rk29_ipp_req ipp_req;
2044 static u32 dstoffset = 0;
2048 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2049 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2055 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2058 if((var->rotate == 270)||(var->rotate == 90)) {
2059 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2060 panel_size[1] = inf->panel1_info.x_res;
2062 panel_size[0] = inf->panel1_info.x_res;
2063 panel_size[1] = inf->panel1_info.y_res;
2066 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2070 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2073 if (copy_from_user(yuv_phy, argp, 8))
2075 #ifdef CONFIG_FB_ROTATE_VIDEO
2077 if(has_set_rotate == true)
2079 last_yuv_phy[0] = yuv_phy[0];
2080 last_yuv_phy[1] = yuv_phy[1];
2083 fix0->smem_start = yuv_phy[0];
2084 fix0->mmio_start = yuv_phy[1];
2085 yuv_phy[0] += par->y_offset;
2086 yuv_phy[1] += par->c_offset;
2088 if((var->rotate == 270)||(var->rotate == 90))
2090 #ifdef CONFIG_FB_ROTATE_VIDEO
2091 dstoffset = (dstoffset+1)%2;
2092 ipp_req.src0.fmt = 3;
2093 ipp_req.src0.YrgbMst = yuv_phy[0];
2094 ipp_req.src0.CbrMst = yuv_phy[1];
2095 ipp_req.src0.w = var->xres;
2096 ipp_req.src0.h = var->yres;
2098 ipp_req.dst0.fmt = 3;
2099 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2100 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2101 // if(var->xres > screen->x_res)
2103 ipp_req.dst0.w = screen->x_res;
2104 ipp_req.dst0.h = screen->y_res;
2106 // ipp_req.dst0.w = var->yres;
2107 // ipp_req.dst0.h = var->xres;
2109 ipp_req.src_vir_w = ipp_req.src0.w;
2110 ipp_req.dst_vir_w = ipp_req.dst0.w;
2111 ipp_req.timeout = 100;
2112 if(var->rotate == 90)
2113 ipp_req.flag = IPP_ROT_90;
2114 else if(var->rotate == 270)
2115 ipp_req.flag = IPP_ROT_270;
2116 ipp_do_blit(&ipp_req);
2117 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2118 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2119 yuv_phy[1] = ipp_req.dst0.CbrMst;
2120 fix0->smem_start = yuv_phy[0];
2121 fix0->mmio_start = yuv_phy[1];
2122 #else //CONFIG_FB_ROTATE_VIDEO
2123 printk("LCDC not support rotate!\n");
2127 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2128 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2129 // enable win0 after the win0 par is seted
2130 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2131 par->addr_seted = 1;
2132 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2133 if(par->par_seted) {
2134 unsigned long flags;
2136 local_irq_save(flags);
2137 par->mirror.y_offset = yuv_phy[0];
2138 par->mirror.c_offset = yuv_phy[1];
2139 local_irq_restore(flags);
2142 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2147 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2148 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2149 #ifdef CONFIG_FB_ROTATE_VIDEO
2151 has_set_rotate = true;
2152 if(arg == 0 || arg==180)
2154 else if (arg == 90 || arg==270)
2156 #else //CONFIG_FB_ROTATE_VIDEO
2157 printk("LCDC not support rotate!\n");
2160 case FB1_IOCTL_SET_WIN0_TOP:
2161 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2162 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2163 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2171 static struct fb_ops fb1_ops = {
2172 .owner = THIS_MODULE,
2173 .fb_open = fb1_open,
2174 .fb_release = fb1_release,
2175 .fb_check_var = fb1_check_var,
2176 .fb_set_par = fb1_set_par,
2177 .fb_blank = fb1_blank,
2178 .fb_pan_display = fb1_pan_display,
2179 .fb_ioctl = fb1_ioctl,
2180 .fb_setcolreg = fb_setcolreg,
2181 .fb_fillrect = cfb_fillrect,
2182 .fb_copyarea = cfb_copyarea,
2183 .fb_imageblit = cfb_imageblit,
2186 static struct fb_ops fb0_ops = {
2187 .owner = THIS_MODULE,
2188 .fb_check_var = fb0_check_var,
2189 .fb_set_par = fb0_set_par,
2190 .fb_blank = fb0_blank,
2191 .fb_pan_display = fb0_pan_display,
2192 .fb_ioctl = fb0_ioctl,
2193 .fb_setcolreg = fb_setcolreg,
2194 .fb_fillrect = cfb_fillrect,
2195 .fb_copyarea = cfb_copyarea,
2196 .fb_imageblit = cfb_imageblit,
2197 //.fb_cursor = rk29_set_cursor,
2201 enable: 1, switch to tv or hdmi; 0, switch to lcd
2203 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2205 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2206 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2207 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2209 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2211 if(enable)inf->cur_screen = &inf->panel2_info;
2212 else inf->cur_screen = &inf->panel1_info;
2214 /* Black out, because some display device need clock to standby */
2215 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2216 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2217 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2218 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2219 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2220 wake_lock(&idlelock);
2222 wake_unlock(&idlelock);
2224 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2225 // operate the display_on pin to power down the lcd
2227 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2228 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2230 load_screen(inf->fb0, 0);
2233 fb1_set_par(inf->fb1);
2234 fb0_set_par(inf->fb0);
2235 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2236 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2240 static ssize_t dsp_win0_info_read(struct device *device,
2241 struct device_attribute *attr, char *buf)
2244 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2245 struct rk29fb_screen *screen = inf->cur_screen;
2247 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2249 fbprintk("%s\n",__FUNCTION__);
2250 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2251 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2253 xpos -= (screen->left_margin + screen->hsync_len);
2254 ypos -= (screen->upper_margin + screen->vsync_len);
2256 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2257 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2258 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2259 rk29_set_cursor_test(inf->fb0);
2261 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2264 static ssize_t dsp_win0_info_write(struct device *device,
2265 struct device_attribute *attr, const char *buf, size_t count)
2267 printk("%s\n",__FUNCTION__);
2268 printk("%s %x \n",__FUNCTION__,*buf);
2272 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2274 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2276 struct platform_device *pdev = (struct platform_device*)dev_id;
2277 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2278 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2282 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2284 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2286 if(SCREEN_MCU == inf->cur_screen->type)
2288 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2294 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2296 inf->mcu_fmksync = 1;
2297 if(inf->cur_screen->refresh)
2298 inf->cur_screen->refresh(REFRESH_END);
2299 inf->mcu_fmksync = 0;
2308 if(inf->mcu_needflush) {
2309 if(inf->cur_screen->refresh)
2310 inf->cur_screen->refresh(REFRESH_PRE);
2311 inf->mcu_needflush = 0;
2312 inf->mcu_isrcnt = 0;
2313 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2315 if(inf->cur_screen->refresh)
2316 inf->cur_screen->refresh(REFRESH_END);
2320 #if ANDROID_USE_THREE_BUFS
2321 new_frame_seted = 1;
2324 if(waitqueue_active(&par->wait)) {
2325 if (par->mirror.c_offset == 0)
2326 printk("error: no new buffer to display\n");
2328 par->done.y_offset = par->displ.y_offset;
2329 par->done.c_offset = par->displ.c_offset;
2330 par->displ.y_offset = par->mirror.y_offset;
2331 par->displ.c_offset = par->mirror.c_offset;
2332 par->mirror.y_offset = 0;
2333 par->mirror.c_offset = 0;
2335 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2336 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2337 wake_up_interruptible(&par->wait);
2342 wake_up_interruptible(&wq);
2347 #ifdef CONFIG_HAS_EARLYSUSPEND
2349 struct suspend_info {
2350 struct early_suspend early_suspend;
2351 struct rk29fb_inf *inf;
2354 static void rk29fb_early_suspend(struct early_suspend *h)
2356 struct suspend_info *info = container_of(h, struct suspend_info,
2359 struct rk29fb_inf *inf = info->inf;
2360 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2362 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2365 printk("inf==0, rk29fb_suspend fail! \n");
2369 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2370 mach_info->io_disable(); //close lcd out
2372 if(inf->cur_screen->standby)
2374 fbprintk(">>>>>> power down the screen! \n");
2375 inf->cur_screen->standby(1);
2378 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2379 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2381 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2382 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2383 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2385 if(!inf->in_suspend)
2387 fbprintk(">>>>>> diable the lcdc clk! \n");
2388 wake_lock(&idlelock);
2390 wake_unlock(&idlelock);
2391 clk_disable(inf->aclk_ddr_lcdc);
2392 clk_disable(inf->aclk_disp_matrix);
2393 clk_disable(inf->hclk_cpu_display);
2394 clk_disable(inf->clk);
2396 clk_disable(inf->dclk);
2399 clk_disable(inf->aclk);
2401 clk_disable(inf->pd_display);
2403 inf->in_suspend = 1;
2407 static void rk29fb_early_resume(struct early_suspend *h)
2409 struct suspend_info *info = container_of(h, struct suspend_info,
2412 struct rk29fb_inf *inf = info->inf;
2413 struct rk29fb_screen *screen = inf->cur_screen;
2414 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2416 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2418 printk("inf==0, rk29fb_resume fail! \n");
2424 inf->in_suspend = 0;
2425 fbprintk(">>>>>> enable the lcdc clk! \n");
2426 clk_enable(inf->pd_display);
2427 clk_enable(inf->aclk_disp_matrix);
2428 clk_enable(inf->hclk_cpu_display);
2429 clk_enable(inf->clk);
2430 clk_enable(inf->aclk_ddr_lcdc);
2433 clk_enable(inf->dclk);
2436 clk_enable(inf->aclk);
2440 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2441 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2442 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2444 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2445 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2447 if(inf->cur_screen->standby)
2449 fbprintk(">>>>>> power on the screen! \n");
2450 inf->cur_screen->standby(0);
2453 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2456 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2457 mach_info->io_enable(); //close lcd out
2461 static struct suspend_info suspend_info = {
2462 .early_suspend.suspend = rk29fb_early_suspend,
2463 .early_suspend.resume = rk29fb_early_resume,
2464 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2467 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2468 static int __init rk29fb_probe (struct platform_device *pdev)
2470 struct rk29fb_inf *inf = NULL;
2471 struct resource *res = NULL;
2472 struct resource *mem = NULL;
2473 struct rk29fb_info *mach_info = NULL;
2474 struct rk29fb_screen *screen = NULL;
2475 struct win0_par* par = NULL;
2479 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2481 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2482 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2483 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2486 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2488 goto release_drvdata;
2490 memset(inf, 0, sizeof(struct rk29fb_inf));
2491 platform_set_drvdata(pdev, inf);
2493 mach_info = pdev->dev.platform_data;
2494 /* Fill screen info and set current screen */
2495 fbprintk(">> Fill screen info and set current screen \n");
2496 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2497 hdmi_get_default_resolution(&inf->panel1_info);
2499 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2501 inf->cur_screen = &inf->panel1_info;
2502 screen = inf->cur_screen;
2503 if(SCREEN_NULL==screen->type)
2505 dev_err(&pdev->dev, ">> Please select a display device! \n");
2507 goto release_drvdata;
2510 /* get virtual basic address of lcdc register */
2511 fbprintk(">> get virtual basic address of lcdc register \n");
2512 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2515 dev_err(&pdev->dev, "failed to get memory registers\n");
2517 goto release_drvdata;
2519 inf->reg_phy_base = res->start;
2520 inf->len = (res->end - res->start) + 1;
2521 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2524 dev_err(&pdev->dev, "failed to get memory region\n");
2526 goto release_drvdata;
2528 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2529 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2530 if (inf->reg_vir_base == NULL)
2532 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2534 goto release_drvdata;
2536 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2538 /* Prepare win1 info */
2539 fbprintk(">> Prepare win1 info \n");
2540 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2543 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2546 goto release_win1fb;
2549 par = (struct win0_par*)inf->fb0->par;
2550 strcpy(inf->fb0->fix.id, "fb0");
2551 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2552 inf->fb0->fix.type_aux = 0;
2553 inf->fb0->fix.xpanstep = 1;
2554 inf->fb0->fix.ypanstep = 1;
2555 inf->fb0->fix.ywrapstep = 0;
2556 inf->fb0->fix.accel = FB_ACCEL_NONE;
2557 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2558 inf->fb0->fix.smem_len = 0;
2559 inf->fb0->fix.line_length = 0;
2560 inf->fb0->fix.smem_start = 0;
2562 inf->fb0->var.xres = screen->x_res;
2563 inf->fb0->var.yres = screen->y_res;
2564 inf->fb0->var.bits_per_pixel = 16;
2565 inf->fb0_color_deepth = 0;
2566 inf->fb0->var.xres_virtual = screen->x_res;
2567 inf->fb0->var.yres_virtual = screen->y_res;
2568 inf->fb0->var.width = screen->width;
2569 inf->fb0->var.height = screen->height;
2570 inf->fb0->var.pixclock = screen->pixclock;
2571 inf->fb0->var.left_margin = screen->left_margin;
2572 inf->fb0->var.right_margin = screen->right_margin;
2573 inf->fb0->var.upper_margin = screen->upper_margin;
2574 inf->fb0->var.lower_margin = screen->lower_margin;
2575 inf->fb0->var.vsync_len = screen->vsync_len;
2576 inf->fb0->var.hsync_len = screen->hsync_len;
2577 inf->fb0->var.red = def_rgb_16.red;
2578 inf->fb0->var.green = def_rgb_16.green;
2579 inf->fb0->var.blue = def_rgb_16.blue;
2580 inf->fb0->var.transp = def_rgb_16.transp;
2582 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2583 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2584 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2585 inf->fb0->var.accel_flags = 0;
2586 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2588 inf->fb0->fbops = &fb0_ops;
2589 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2590 inf->fb0->pseudo_palette = par->pseudo_pal;
2591 inf->fb0->screen_base = 0;
2593 memset(par, 0, sizeof(struct win0_par));
2595 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2599 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2601 /* alloc win1 buf */
2602 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2605 dev_err(&pdev->dev, "failed to get win1 memory \n");
2607 goto release_win1fb;
2609 inf->fb0->fix.smem_start = res->start;
2610 inf->fb0->fix.smem_len = res->end - res->start + 1;
2611 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2612 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2614 #ifdef CONFIG_FB_WORK_IPP
2615 /* alloc win1 ipp buf */
2616 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2619 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2621 goto release_win1fb;
2623 inf->fb0->fix.mmio_start = res->start;
2624 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2627 /* Prepare win0 info */
2628 fbprintk(">> Prepare win0 info \n");
2629 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2632 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2635 goto release_win0fb;
2638 par = (struct win0_par*)inf->fb1->par;
2640 strcpy(inf->fb1->fix.id, "fb1");
2641 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2642 inf->fb1->fix.type_aux = 0;
2643 inf->fb1->fix.xpanstep = 1;
2644 inf->fb1->fix.ypanstep = 1;
2645 inf->fb1->fix.ywrapstep = 0;
2646 inf->fb1->fix.accel = FB_ACCEL_NONE;
2647 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2648 inf->fb1->fix.smem_len = 0;
2649 inf->fb1->fix.line_length = 0;
2650 inf->fb1->fix.smem_start = 0;
2652 inf->fb1->var.xres = screen->x_res;
2653 inf->fb1->var.yres = screen->y_res;
2654 inf->fb1->var.bits_per_pixel = 16;
2655 inf->fb1->var.xres_virtual = screen->x_res;
2656 inf->fb1->var.yres_virtual = screen->y_res;
2657 inf->fb1->var.width = screen->width;
2658 inf->fb1->var.height = screen->height;
2659 inf->fb1->var.pixclock = screen->pixclock;
2660 inf->fb1->var.left_margin = screen->left_margin;
2661 inf->fb1->var.right_margin = screen->right_margin;
2662 inf->fb1->var.upper_margin = screen->upper_margin;
2663 inf->fb1->var.lower_margin = screen->lower_margin;
2664 inf->fb1->var.vsync_len = screen->vsync_len;
2665 inf->fb1->var.hsync_len = screen->hsync_len;
2666 inf->fb1->var.red = def_rgb_16.red;
2667 inf->fb1->var.green = def_rgb_16.green;
2668 inf->fb1->var.blue = def_rgb_16.blue;
2669 inf->fb1->var.transp = def_rgb_16.transp;
2671 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2672 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2673 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2674 inf->fb1->var.accel_flags = 0;
2675 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2677 inf->fb1->fbops = &fb1_ops;
2678 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2679 inf->fb1->pseudo_palette = par->pseudo_pal;
2680 inf->fb1->screen_base = 0;
2682 memset(par, 0, sizeof(struct win0_par));
2684 init_waitqueue_head(&par->wait);
2686 /* Init all lcdc and lcd before register_framebuffer. */
2687 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2688 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2689 init_lcdc(inf->fb0);
2691 #if 0 //def CONFIG_CPU_FREQ
2692 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2693 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2695 fbprintk("got clock\n");
2699 struct rk29_fb_setting_info fb_setting;
2700 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2702 fb_setting.data_num = 24;
2704 else if(OUT_P666 == inf->cur_screen->face )
2706 fb_setting.data_num = 18;
2710 fb_setting.data_num = 16;
2712 fb_setting.den_en = 1;
2713 fb_setting.vsync_en = 1;
2714 fb_setting.disp_on_en = 1;
2715 fb_setting.standby_en = 1;
2716 if( inf->cur_screen->mcu_usefmk )
2717 fb_setting.mcu_fmk_en =1;
2718 mach_info->io_init(&fb_setting);
2721 //set_lcd_pin(pdev, 1);
2724 inf->mcu_usetimer = 1;
2725 inf->mcu_fmksync = 0;
2726 load_screen(inf->fb0, 1);
2728 /* Register framebuffer(fb0 & fb1) */
2729 fbprintk(">> Register framebuffer(fb0) \n");
2730 ret = register_framebuffer(inf->fb0);
2733 printk(">> fb0 register_framebuffer fail!\n");
2735 goto release_win0fb;
2737 fbprintk(">> Register framebuffer(fb1) \n");
2739 ret = register_framebuffer(inf->fb1);
2742 printk(">> fb1 register_framebuffer fail!\n");
2744 goto unregister_win1fb;
2747 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2750 printk(">> fb1 dsp win0 info device_create_file err\n");
2753 #ifdef CONFIG_HAS_EARLYSUSPEND
2754 suspend_info.inf = inf;
2755 register_early_suspend(&suspend_info.early_suspend);
2758 /* get and request irq */
2759 fbprintk(">> get and request irq \n");
2760 irq = platform_get_irq(pdev, 0);
2762 dev_err(&pdev->dev, "no irq for device\n");
2764 goto unregister_win1fb;
2766 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2768 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2773 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2775 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2778 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2784 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2785 fb0_set_par(inf->fb0);
2786 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2787 /* Start display and show logo on boot */
2788 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2789 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2790 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2794 printk(" %s ok\n", __FUNCTION__);
2799 free_irq(irq, pdev);
2801 unregister_framebuffer(inf->fb0);
2804 framebuffer_release(inf->fb1);
2808 fb_dealloc_cmap(&inf->fb0->cmap);
2811 framebuffer_release(inf->fb0);
2814 if(inf && inf->reg_vir_base)
2815 iounmap(inf->reg_vir_base);
2817 release_mem_region(inf->reg_phy_base, inf->len);
2820 platform_set_drvdata(pdev, NULL);
2824 static int rk29fb_remove(struct platform_device *pdev)
2826 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2827 struct fb_info *info = NULL;
2829 struct rk29fb_info *mach_info = NULL;
2832 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2835 printk("inf==0, rk29_fb_remove fail! \n");
2838 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2840 irq = platform_get_irq(pdev, 0);
2843 free_irq(irq, pdev);
2846 mach_info = pdev->dev.platform_data;
2847 if(mach_info->mcu_fmk_pin)
2849 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2852 if(mach_info->io_disable)
2853 mach_info->io_disable(); //close lcd out
2857 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2859 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2862 //rk29fb_suspend(pdev, msg);
2863 // unmap memory and release framebuffer
2866 if (info->screen_base) {
2867 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2868 info->screen_base = 0;
2869 info->fix.smem_start = 0;
2870 info->fix.smem_len = 0;
2872 unregister_framebuffer(inf->fb1);
2873 framebuffer_release(inf->fb1);
2878 if (info->screen_base) {
2879 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2880 info->screen_base = 0;
2881 info->fix.smem_start = 0;
2882 info->fix.smem_len = 0;
2884 unregister_framebuffer(inf->fb0);
2885 framebuffer_release(inf->fb0);
2889 #if 0 //def CONFIG_CPU_FREQ
2890 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2897 clk_disable(inf->clk);
2903 clk_disable(inf->dclk);
2909 platform_set_drvdata(pdev, NULL);
2914 static void rk29fb_shutdown(struct platform_device *pdev)
2916 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2917 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
2919 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
2921 if(mach_info->io_disable)
2922 mach_info->io_disable(); //close lcd out
2924 if(!inf->in_suspend)
2926 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2927 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2928 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2930 clk_disable(inf->aclk_ddr_lcdc);
2931 clk_disable(inf->aclk_disp_matrix);
2932 clk_disable(inf->hclk_cpu_display);
2933 clk_disable(inf->clk);
2935 clk_disable(inf->dclk);
2938 clk_disable(inf->aclk);
2940 clk_disable(inf->pd_display);
2941 //pmu_set_power_domain(PD_DISPLAY, 0);
2942 inf->in_suspend = 1;
2947 static struct platform_driver rk29fb_driver = {
2948 .probe = rk29fb_probe,
2949 .remove = rk29fb_remove,
2952 .owner = THIS_MODULE,
2954 .shutdown = rk29fb_shutdown,
2957 static int __init rk29fb_init(void)
2959 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
2960 return platform_driver_register(&rk29fb_driver);
2963 static void __exit rk29fb_exit(void)
2965 platform_driver_unregister(&rk29fb_driver);
2968 fs_initcall(rk29fb_init);
2969 module_exit(rk29fb_exit);
2972 MODULE_AUTHOR(" zyw@rock-chips.com");
2973 MODULE_DESCRIPTION("Driver for rk29 fb device");
2974 MODULE_LICENSE("GPL");