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>
41 #include <asm/cacheflush.h>
49 #include <linux/completion.h>
51 #include <linux/hdmi.h>
54 #include <mach/iomux.h>
55 #include <mach/gpio.h>
56 #include <mach/board.h>
57 #include <mach/rk29_iomap.h>
59 #include <mach/rk29-ipp.h>
62 #include "./display/screen/screen.h"
64 #define ANDROID_USE_THREE_BUFS 0 //android use three buffers to accelerate UI display in rgb plane
65 #define CURSOR_BUF_SIZE 256 //RK2818 cursor need 256B buf
66 int rk29_cursor_buf[CURSOR_BUF_SIZE];
103 #define fbprintk(msg...) printk(msg);
105 #define fbprintk(msg...)
110 #define fbprintk2(msg...) printk(msg);
112 #define fbprintk2(msg...)
115 #define LcdReadBit(inf, addr, msk) ((inf->regbak.addr=inf->preg->addr)&(msk))
116 #define LcdWrReg(inf, addr, val) inf->preg->addr=inf->regbak.addr=(val)
117 #define LcdRdReg(inf, addr) (inf->preg->addr)
118 #define LcdSetBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) |= (msk))
119 #define LcdClrBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) &= ~(msk))
120 #define LcdSetRegisterBit(inf, addr, msk) inf->preg->addr=((inf->preg->addr) |= (msk))
121 #define LcdMskReg(inf, addr, msk, val) (inf->regbak.addr)&=~(msk); inf->preg->addr=(inf->regbak.addr|=(val))
124 #define IsMcuLandscape() ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
125 #define IsMcuUseFmk() ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
127 #define CalScaleW0(x, y) (((u32)x*0x1000)/y)
130 struct fb_bitfield red;
131 struct fb_bitfield green;
132 struct fb_bitfield blue;
133 struct fb_bitfield transp;
136 static struct rk29fb_rgb def_rgb_16 = {
137 red: { offset: 11, length: 5, },
138 green: { offset: 5, length: 6, },
139 blue: { offset: 0, length: 5, },
140 transp: { offset: 0, length: 0, },
144 volatile u32 y_offset;
145 volatile u32 c_offset;
153 u32 xpos; //size in panel
155 u32 xsize; //start point in panel
159 wait_queue_head_t wait;
160 struct win_set mirror;
161 struct win_set displ;
186 void __iomem *reg_vir_base; // virtual basic address of lcdc register
187 u32 reg_phy_base; // physical basic address of lcdc register
188 u32 len; // physical map length of lcdc register
192 struct clk *dclk; //lcdc dclk
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;
218 /* external memery */
219 char __iomem *screen_base2;
221 unsigned long smem_start2;
223 char __iomem *cursor_base; /* cursor Virtual address*/
224 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
225 unsigned long cursor_start;
227 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
228 struct rk29fb_screen panel2_info; // 2nd panel
229 struct rk29fb_screen *cur_screen;
230 #if 0 //def CONFIG_CPU_FREQ
231 struct notifier_block freq_transition;
236 typedef enum _TRSP_MODE
248 struct platform_device *g_pdev = NULL;
249 //static int win1fb_set_par(struct fb_info *info);
252 #define CHK_SUSPEND(inf) \
253 if(inf->in_suspend) { \
254 fbprintk(">>>>>> fb is in suspend! return! \n"); \
258 #define CHK_SUSPEND(inf)
260 static DECLARE_WAIT_QUEUE_HEAD(fb0_wait_queue);
261 static volatile int idle_condition = 1; //1:idel, 0:busy
263 static DECLARE_WAIT_QUEUE_HEAD(wq);
264 static int wq_condition = 0;
265 static int wq_condition2 = 0;
266 #if ANDROID_USE_THREE_BUFS
267 static int new_frame_seted = 1;
269 static struct wake_lock idlelock; /* only for fb */
270 #ifdef CONFIG_FB_ROTATE_VIDEO
272 static bool has_set_rotate;
273 static u32 last_yuv_phy[2] = {0,0};
275 int fb0_first_buff_bits = 32;
276 int fb0_second_buff_bits = 32;
277 int fb_compose_layer_count = 0;
278 static BLOCKING_NOTIFIER_HEAD(rk29fb_notifier_list);
279 int rk29fb_register_notifier(struct notifier_block *nb)
283 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
285 if (inf->cur_screen && inf->cur_screen->type == SCREEN_HDMI)
286 nb->notifier_call(nb, RK29FB_EVENT_HDMI_ON, inf->cur_screen);
287 if (inf->fb1 && inf->fb1->par) {
288 struct win0_par *par = inf->fb1->par;
290 nb->notifier_call(nb, RK29FB_EVENT_FB1_ON, inf->cur_screen);
294 ret = blocking_notifier_chain_register(&rk29fb_notifier_list, nb);
299 int rk29fb_unregister_notifier(struct notifier_block *nb)
301 return blocking_notifier_chain_unregister(&rk29fb_notifier_list, nb);
304 static int rk29fb_notify(struct rk29fb_inf *inf, unsigned long event)
306 return blocking_notifier_call_chain(&rk29fb_notifier_list, event, inf->cur_screen);
309 int mcu_do_refresh(struct rk29fb_inf *inf)
311 if(inf->mcu_stopflush) return 0;
313 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
318 inf->mcu_needflush = 1;
322 // not use frame mark
323 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
325 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
327 inf->mcu_needflush = 1;
331 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
332 inf->mcu_needflush = 0;
334 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
341 void mcutimer_callback(unsigned long arg)
343 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
344 static int waitcnt = 0;
346 mod_timer(&inf->mcutimer, jiffies + HZ/10);
348 switch(inf->mcu_status)
351 inf->mcu_status = MS_MCU;
354 if(inf->mcu_usetimer) mcu_do_refresh(inf);
357 inf->mcu_status = MS_EWAITEND;
365 inf->mcu_status = MS_EEND;
369 inf->mcu_status = MS_MCU;
372 inf->mcu_status = MS_MCU;
377 int mcu_refresh(struct rk29fb_inf *inf)
379 static int mcutimer_inited = 0;
381 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
386 init_timer(&inf->mcutimer);
387 inf->mcutimer.function = mcutimer_callback;
388 inf->mcutimer.expires = jiffies + HZ/5;
389 inf->mcu_status = MS_IDLE;
390 add_timer(&inf->mcutimer);
393 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
398 int mcu_ioctl(unsigned int cmd, unsigned long arg)
400 struct rk29fb_inf *inf = NULL;
401 if(!g_pdev) return -1;
403 inf = dev_get_drvdata(&g_pdev->dev);
408 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
409 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
410 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
414 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
415 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
419 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
420 LcdWrReg(inf, REG_CFG_DONE, 0x01);
430 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
432 struct platform_device *pdev = (struct platform_device*)dev_id;
433 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
434 struct rk29fb_screen *screen;
436 if(!inf) return IRQ_HANDLED;
438 screen = inf->cur_screen;
440 if(0==screen->mcu_usefmk) {
444 if(inf->mcu_fmksync == 1)
447 inf->mcu_fmksync = 1;
448 if(inf->mcu_needflush)
450 inf->mcu_needflush = 0;
452 if(inf->cur_screen->refresh)
453 inf->cur_screen->refresh(REFRESH_PRE);
454 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
456 inf->mcu_fmksync = 0;
461 int init_lcdc(struct fb_info *info)
463 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
466 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
468 inf->clk = clk_get(NULL, "hclk_lcdc");
469 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
470 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
471 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
472 inf->pd_display = clk_get(NULL, "pd_display");
473 if ((IS_ERR(inf->clk)) ||
474 (IS_ERR(inf->aclk_ddr_lcdc)) ||
475 (IS_ERR(inf->aclk_disp_matrix)) ||
476 (IS_ERR(inf->hclk_cpu_display)) ||
477 (IS_ERR(inf->pd_display)))
479 printk(KERN_ERR "failed to get lcdc_hclk source\n");
480 return PTR_ERR(inf->clk);
482 clk_enable(inf->aclk_disp_matrix);
483 clk_enable(inf->hclk_cpu_display);
484 clk_enable(inf->clk);
485 clk_enable(inf->pd_display);
486 //pmu_set_power_domain(PD_DISPLAY, 1);
487 clk_enable(inf->aclk_ddr_lcdc);
489 // set AHB access rule and disable all windows
490 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
491 LcdWrReg(inf, SWAP_CTRL, 0);
492 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
493 LcdWrReg(inf, AXI_MS_ID, 0x54321);
495 // and mcu holdmode; and set win1 top.
496 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
497 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
499 // disable blank out, black out, tristate out, yuv2rgb bypass
500 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
501 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
502 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
503 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
506 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
507 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
509 LcdWrReg(inf, DSP_CTRL1, 0);
511 // initialize all interrupt
512 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
514 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
516 LcdWrReg(inf, INT_STATUS, clr | msk);
518 // let above to take effect
519 LcdWrReg(inf, REG_CFG_DONE, 0x01);
524 void load_screen(struct fb_info *info, bool initscreen)
527 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
528 struct rk29fb_screen *screen = inf->cur_screen;
530 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
531 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
532 u16 x_res = screen->x_res, y_res = screen->y_res;
533 u32 aclk_rate = 150000000;
536 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
540 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
542 // set the rgb or mcu
543 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
545 // set out format and mcu timing
546 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
547 if(mcu_total>31) mcu_total = 31;
548 if(mcu_total<3) mcu_total = 3;
549 mcu_rwstart = (mcu_total+1)/4 - 1;
550 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
551 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
552 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
554 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
555 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
557 LcdMskReg(inf, MCU_TIMING_CTRL,
558 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
559 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
560 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
561 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
562 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
565 // set synchronous pin polarity and data pin swap rule
566 switch (screen->face)
570 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
574 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
578 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
582 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
586 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
587 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
590 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
591 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
596 LcdMskReg(inf, DSP_CTRL0,
597 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
598 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
599 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
600 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
603 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
605 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
606 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));
608 // set horizontal & vertical out timing
609 if(SCREEN_MCU==inf->cur_screen->type)
611 right_margin = x_res/6;
614 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
615 screen->hsync_len , screen->left_margin , x_res , right_margin );
616 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
617 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
618 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
619 v_BIT12HI(screen->hsync_len + screen->left_margin));
621 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
622 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
623 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
624 v_BIT11HI(screen->vsync_len + screen->upper_margin));
626 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
627 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
629 // let above to take effect
630 LcdWrReg(inf, REG_CFG_DONE, 0x01);
632 inf->dclk = clk_get(NULL, "dclk_lcdc");
633 if (IS_ERR(inf->dclk))
635 printk(KERN_ERR "failed to get lcd dclock source\n");
639 inf->aclk = clk_get(NULL, "aclk_lcdc");
640 if (IS_ERR(inf->aclk))
642 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
645 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
646 if (IS_ERR(inf->aclk_parent))
648 printk(KERN_ERR "failed to get lcd clock parent source\n");
653 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
655 if(initscreen == 0) //not init
657 clk_disable(inf->dclk);
658 // clk_disable(inf->aclk);
661 // clk_disable(inf->aclk_ddr_lcdc);
662 // clk_disable(inf->aclk_disp_matrix);
663 // clk_disable(inf->hclk_cpu_display);
665 // clk_disable(inf->clk);
668 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
670 ret = clk_set_rate(inf->dclk, screen->pixclock);
673 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
675 inf->fb0->var.pixclock = inf->fb1->var.pixclock = div_u64(1000000000000llu, clk_get_rate(inf->dclk));
678 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
679 if(screen->lcdc_aclk){
680 aclk_rate = screen->lcdc_aclk;
682 ret = clk_set_rate(inf->aclk, aclk_rate);
684 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
686 clk_enable(inf->aclk);
688 // clk_enable(inf->aclk_ddr_lcdc);
689 // clk_enable(inf->aclk_disp_matrix);
690 // clk_enable(inf->hclk_cpu_display);
691 // clk_enable(inf->clk);
692 clk_enable(inf->dclk);
700 #if 0 //def CONFIG_CPU_FREQ
702 * CPU clock speed change handler. We need to adjust the LCD timing
703 * parameters when the CPU clock is adjusted by the power management
706 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
709 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
711 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
712 struct rk29fb_screen *screen = inf->cur_screen;
717 case CPUFREQ_PRECHANGE:
719 case CPUFREQ_POSTCHANGE:
721 dclk_rate = screen->pixclock * 1000000;
723 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
725 clk_set_rate(inf->dclk_divider, dclk_rate);
733 static inline unsigned int chan_to_field(unsigned int chan,
734 struct fb_bitfield *bf)
737 chan >>= 16 - bf->length;
738 return chan << bf->offset;
741 static int fb_setcolreg(unsigned regno,
742 unsigned red, unsigned green, unsigned blue,
743 unsigned transp, struct fb_info *info)
746 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
748 switch (info->fix.visual) {
749 case FB_VISUAL_TRUECOLOR:
750 /* true-colour, use pseudo-palette */
752 u32 *pal = info->pseudo_palette;
753 val = chan_to_field(red, &info->var.red);
754 val |= chan_to_field(green, &info->var.green);
755 val |= chan_to_field(blue, &info->var.blue);
760 return -1; /* unknown type */
766 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
769 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
771 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
773 LcdWrReg(inf, REG_CFG_DONE, 0x01);
777 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
779 struct rk29fb_screen *screen = inf->cur_screen;
782 if (x >= 0x800 || y >= 0x800 )
784 //printk("%s: %08x,%08x \n",__func__, x, y);
785 x += (screen->left_margin + screen->hsync_len);
786 y += (screen->upper_margin + screen->vsync_len);
787 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
788 LcdWrReg(inf, REG_CFG_DONE, 0x01);
793 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
795 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
796 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
797 LcdWrReg(inf, REG_CFG_DONE, 0x01);
801 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
802 int rk29_set_cursor_img_transform(char *data)
805 char *dst = (char*)rk29_cursor_buf;
806 unsigned char dmsk = 0;
807 unsigned int op,shift,offset;
809 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
810 * clears it to transparent then combines the cursor
811 * shape plane with the colour plane to set the
813 for (y = 0; y < 32; y++)
815 for (x = 0; x < 32; x++)
822 op = (dmsk & 0x80) ? 2 : 3;
825 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
835 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
839 rk29_set_cursor_img_transform(data);
843 rk29_set_cursor_img_transform(cursor_img);
845 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
846 //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
847 LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
849 LcdWrReg(inf, REG_CFG_DONE, 0x01);
854 int rk29_set_cursor_test(struct fb_info *info)
856 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
857 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
858 rk29_set_cursor_pos(inf, 0, 0);
859 rk29_set_cursor_img(inf, 0);
860 rk29_set_cursor_en(inf, 1);
865 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
867 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
869 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
871 /* check not being asked to exceed capabilities */
873 if (cursor->image.width > 32)
876 if (cursor->image.height > 32)
879 if (cursor->image.depth > 1)
883 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
885 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
888 if (cursor->set & FB_CUR_SETPOS)
890 unsigned int x = cursor->image.dx;
891 unsigned int y = cursor->image.dy;
893 if (x >= 0x800 || y >= 0x800 )
895 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
899 if (cursor->set & FB_CUR_SETCMAP)
901 unsigned int bg_col = cursor->image.bg_color;
902 unsigned int fg_col = cursor->image.fg_color;
904 fbprintk("%s: update cmap (%08x,%08x)\n",
905 __func__, bg_col, fg_col);
907 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
908 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));
910 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
911 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));
914 if ((cursor->set & FB_CUR_SETSIZE ||
915 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
916 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
918 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
919 * clears it to transparent then combines the cursor
920 * shape plane with the colour plane to set the
923 const unsigned char *pcol = cursor->image.data;
924 const unsigned char *pmsk = cursor->mask;
926 unsigned long cursor_mem_start;
927 unsigned char dcol = 0;
928 unsigned char dmsk = 0;
931 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
932 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
934 fbprintk("%s: setting shape (%d,%d)\n",
935 __func__, cursor->image.width, cursor->image.height);
937 memset(dst, 0, CURSOR_BUF_SIZE);
939 for (y = 0; y < cursor->image.height; y++)
941 for (x = 0; x < cursor->image.width; x++)
952 op = (dcol & 1) ? 1 : 3;
953 op <<= ((x % 4) * 2);
954 *(u8*)(dst+(x/4)) |= op;
959 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
960 LcdWrReg(inf, HWC_MST, cursor_mem_start);
961 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
962 if(SCREEN_MCU == inf->cur_screen->type) {
963 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
967 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
969 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
975 static int hdmi_get_fbscale(void)
978 return hdmi_get_scale();
983 static void hdmi_set_fbscale(struct fb_info *info)
986 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
987 struct rk29fb_screen *screen = inf->cur_screen;
988 struct win0_par *par = info->par;
991 scale = hdmi_get_scale();
994 par->xpos += screen->x_res * (100-scale) / 200;
995 par->ypos += screen->y_res * (100-scale) / 200;
996 par->xsize = par->xsize *scale /100;
997 par->ysize = par->ysize *scale /100;
1000 static int win0_blank(int blank_mode, struct fb_info *info)
1002 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1004 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1010 case FB_BLANK_UNBLANK:
1011 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1012 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1014 case FB_BLANK_NORMAL:
1015 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1018 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1019 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1020 #ifdef CONFIG_DDR_RECONFIG
1030 static int win0_set_par(struct fb_info *info)
1032 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1033 struct rk29fb_screen *screen = inf->cur_screen;
1034 struct fb_var_screeninfo *var = &info->var;
1035 struct fb_fix_screeninfo *fix = &info->fix;
1036 struct win0_par *par = info->par;
1037 u32 xact, yact, xvir, yvir, xpos, ypos, ScaleYrgbX,ScaleYrgbY, ScaleCbrX, ScaleCbrY, y_addr,uv_addr;
1038 hdmi_set_fbscale(info);
1039 xact = var->xres; /* visible resolution */
1041 xvir = var->xres_virtual; /* virtual resolution */
1042 yvir = var->yres_virtual;
1043 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
1044 //u32 yact_st = var->yoffset; /* resolution */
1053 y_addr = 0; //user alloc buf addr y
1056 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1060 if(((var->rotate == 270)||(var->rotate == 90) || (var->rotate == 180)) && (inf->video_mode))
1062 #ifdef CONFIG_FB_ROTATE_VIDEO
1063 if(xact > screen->x_res)
1065 xact = screen->x_res; /* visible resolution */
1066 yact = screen->y_res;
1067 xvir = screen->x_res; /* virtual resolution */
1068 yvir = screen->y_res;
1070 xact = var->xres; /* visible resolution */
1072 xvir = var->xres_virtual; /* virtual resolution */
1073 yvir = var->yres_virtual;
1074 printk("xact=%d yact =%d \n",xact,yact);
1076 #else //CONFIG_FB_ROTATE_VIDEO
1077 printk("LCDC not support rotate!\n");
1082 // calculate the display phy address
1083 y_addr = fix->smem_start + par->y_offset;
1084 uv_addr = fix->mmio_start + par->c_offset;
1086 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1087 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1089 switch (par->format)
1092 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1093 ScaleCbrY = CalScaleW0(yact, par->ysize);
1097 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1098 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1101 ScaleCbrX= CalScaleW0(xact, par->xsize);
1102 ScaleCbrY = CalScaleW0(yact, par->ysize);
1108 xpos += (screen->left_margin + screen->hsync_len);
1109 ypos += (screen->upper_margin + screen->vsync_len);
1111 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1112 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1114 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1116 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1117 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1118 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1119 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1120 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1121 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1126 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,
1127 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));
1130 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,
1131 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));
1134 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,
1135 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) |
1136 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1139 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,
1140 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) );
1144 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1150 static int win0_pan( struct fb_info *info )
1152 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1153 // struct fb_var_screeninfo *var0 = &info->var;
1154 struct fb_fix_screeninfo *fix0 = &info->fix;
1155 struct win0_par *par = info->par;
1156 u32 y_addr=0, uv_addr=0;
1158 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1162 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1163 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1165 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1166 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1167 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1169 // enable win0 after the win0 addr is seted
1170 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1176 static int win1_blank(int blank_mode, struct fb_info *info)
1178 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1180 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1186 case FB_BLANK_UNBLANK:
1187 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1188 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1190 case FB_BLANK_NORMAL:
1191 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1194 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1195 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1205 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1206 static void win1_check_work_func(struct work_struct *work)
1208 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
1209 struct fb_info *fb0_inf = inf->fb0;
1210 struct fb_var_screeninfo *var = &fb0_inf->var;
1213 int blank_data,total_data;
1215 u16 xres_virtual = fb0_inf->var.xres_virtual; //virtual screen size
1216 u16 xpos_virtual = fb0_inf->var.xoffset; //visiable offset in virtual screen
1217 u16 ypos_virtual = fb0_inf->var.yoffset;
1219 int offset = 0;//(ypos_virtual*xres_virtual + xpos_virtual)*((inf->fb0_color_deepth || fb0_inf->var.bits_per_pixel==32)? 4:2)/4;
1220 switch(var->bits_per_pixel)
1224 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1225 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1226 offset -= var->yres * var->xres *2;
1230 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1231 if(ypos_virtual >= 2*var->yres)
1234 if(ypos_virtual == 3*var->yres)
1236 offset -= var->yres * var->xres *2;
1241 p = (u32)fb0_inf->screen_base + offset;
1242 blank_data = (inf->fb0_color_deepth==32) ? 0xff000000 : 0;
1243 total_data = fb0_inf->var.xres * fb0_inf->var.yres / (format+1);
1245 // printk("var->bits_per_pixel=%d,ypos_virtual=%d, var->yres=%d,offset=%d,total_data=%d\n",var->bits_per_pixel,ypos_virtual,var->yres,offset,total_data);
1247 for(i=0; i < total_data; i++)
1249 if(*p++ != blank_data)
1251 //printk("win1 have no 0 data in %d, total %d\n",i,total_data);
1256 win1_blank(FB_BLANK_POWERDOWN, fb0_inf);
1257 // printk("%s close win1!\n",__func__);
1259 static DECLARE_DELAYED_WORK(rk29_win1_check_work, win1_check_work_func);
1261 static int win1_set_par(struct fb_info *info)
1263 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1264 struct fb_fix_screeninfo *fix = &info->fix;
1265 struct rk29fb_screen *screen = inf->cur_screen;
1266 struct win0_par *par = info->par;
1267 struct fb_var_screeninfo *var = &info->var;
1269 u16 xres_virtual,xpos,ypos;
1270 u8 trspval,trspmode;
1271 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1272 cancel_delayed_work_sync(&rk29_win1_check_work);
1274 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1275 #ifndef CONFIG_FB_SCALING_OSD_1080P
1276 && !((screen->x_res>1280) && (var->bits_per_pixel == 32))
1280 hdmi_set_fbscale(info);
1282 #ifndef CONFIG_FB_SCALING_OSD_1080P
1283 else if(((screen->x_res==1920) ))
1285 if(hdmi_get_fbscale() < 100)
1286 par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1289 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1291 xres_virtual = 0; //virtual screen size
1293 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1294 //u16 ypos_virtual = var->yoffset;
1296 xpos = par->xpos; //visiable offset in panel
1299 trspmode = TRSP_CLOSE;
1302 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1304 #ifdef CONFIG_FB_SCALING_OSD
1305 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1306 #ifndef CONFIG_FB_SCALING_OSD_1080P
1307 && (screen->x_res<=1280)
1311 addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1312 xres_virtual = screen->x_res* hdmi_get_fbscale()/100; //virtual screen size
1317 addr = fix->smem_start + par->y_offset;
1318 xres_virtual = var->xres_virtual; //virtual screen size
1320 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1322 xpos += (screen->left_margin + screen->hsync_len);
1323 ypos += (screen->upper_margin + screen->vsync_len);
1325 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1327 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1328 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1330 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1332 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1333 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1335 // enable win1 color key and set the color to black(rgb=0)
1336 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1338 if(1==par->format) //rgb565
1340 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1341 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1345 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1346 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1348 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1351 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1353 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1354 schedule_delayed_work(&rk29_win1_check_work, msecs_to_jiffies(5000));
1360 static int win1_pan( struct fb_info *info )
1362 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1363 struct fb_fix_screeninfo *fix1 = &info->fix;
1364 struct win0_par *par = info->par;
1367 #ifdef CONFIG_FB_SCALING_OSD
1368 struct rk29fb_screen *screen = inf->cur_screen;
1369 struct fb_var_screeninfo *var = &info->var;
1370 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1371 #ifndef CONFIG_FB_SCALING_OSD_1080P
1372 && (screen->x_res<=1280)
1376 addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1381 addr = fix1->smem_start + par->y_offset;
1384 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1386 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1387 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1393 static int fb0_blank(int blank_mode, struct fb_info *info)
1395 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1397 if(inf->video_mode == 1)
1399 win1_blank(blank_mode, info);
1403 win0_blank(blank_mode, info);
1408 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1410 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1411 struct rk29fb_screen *screen = inf->cur_screen;
1412 u16 xpos = (var->nonstd>>8) & 0xfff;
1413 u16 ypos = (var->nonstd>>20) & 0xfff;
1414 u16 xlcd = screen->x_res;
1415 u16 ylcd = screen->y_res;
1417 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1421 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1422 0==var->xres || 0==var->yres || var->xres<16 ||
1423 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1425 printk(">>>>>> fb0_check_var fail 1!!! \n");
1426 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1427 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1428 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1432 if( (var->xoffset+var->xres)>var->xres_virtual ||
1433 (var->yoffset+var->yres)>var->yres_virtual*2 )
1435 printk(">>>>>> fb0_check_var fail 2!!! \n");
1436 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1437 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1438 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1442 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1443 switch(var->bits_per_pixel)
1446 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1447 var->xres = (var->xres + 0x1) & (~0x1);
1448 var->xoffset = (var->xoffset) & (~0x1);
1451 var->bits_per_pixel = 32;
1459 static int fb0_set_par(struct fb_info *info)
1461 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1462 struct fb_var_screeninfo *var = &info->var;
1463 struct fb_fix_screeninfo *fix = &info->fix;
1464 struct rk29fb_screen *screen = inf->cur_screen;
1465 struct win0_par *par = info->par;
1467 u32 offset=0, smem_len=0;
1468 u16 xres_virtual = var->xres_virtual; //virtual screen size
1469 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1470 u16 ypos_virtual = var->yoffset;
1472 #ifdef CONFIG_FB_SCALING_OSD
1473 struct rk29_ipp_req ipp_req;
1475 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1478 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1479 wait_event_interruptible(fb0_wait_queue, idle_condition);
1485 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1486 #if !defined(CONFIG_FB_SCALING_OSD)
1487 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1490 switch(var->bits_per_pixel)
1494 if( ypos_virtual == 0)
1495 fb0_first_buff_bits = 16;
1497 fb0_second_buff_bits = 16;
1499 //fix->line_length = 2 * xres_virtual;
1500 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1502 #ifdef CONFIG_FB_SCALING_OSD
1503 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1504 ipp_req.src0.fmt = IPP_RGB_565;
1505 ipp_req.dst0.fmt = IPP_RGB_565;
1507 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1508 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1509 offset -= var->yres * var->xres *2;
1514 if( ypos_virtual == 0)
1515 fb0_first_buff_bits = 32;
1517 fb0_second_buff_bits = 32;
1518 fix->line_length = 4 * xres_virtual;
1519 #ifdef CONFIG_FB_SCALING_OSD
1520 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1522 ipp_req.src0.fmt = IPP_XRGB_8888;
1523 ipp_req.dst0.fmt = IPP_XRGB_8888;
1525 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1527 if(ypos_virtual >= 2*var->yres)
1530 #ifdef CONFIG_FB_SCALING_OSD
1531 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1532 ipp_req.src0.fmt = IPP_RGB_565;
1533 ipp_req.dst0.fmt = IPP_RGB_565;
1535 if(ypos_virtual == 3*var->yres)
1537 offset -= var->yres * var->xres *2;
1543 smem_len = fix->line_length * var->yres_virtual;
1544 //map_size = PAGE_ALIGN(smem_len);
1546 if (smem_len > fix->smem_len) // buffer need realloc
1548 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1549 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1550 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1554 par->addr_seted = 1;
1555 #if ANDROID_USE_THREE_BUFS
1556 if(0==new_frame_seted) {
1558 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1560 new_frame_seted = 0;
1563 if(inf->video_mode == 1)
1565 #ifdef CONFIG_FB_SCALING_OSD
1566 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1567 #ifndef CONFIG_FB_SCALING_OSD_1080P
1568 && (screen->x_res<=1280)
1574 par->xsize = screen->x_res;
1575 par->ysize = screen->y_res;
1576 par->y_offset = dstoffset;
1578 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1579 ipp_req.src0.w = var->xres;
1580 ipp_req.src0.h = var->yres;
1582 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1583 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1584 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1586 ipp_req.src_vir_w = ipp_req.src0.w;
1587 ipp_req.dst_vir_w = ipp_req.dst0.w;
1588 ipp_req.timeout = 100;
1589 ipp_req.flag = IPP_ROT_0;
1590 //ipp_do_blit(&ipp_req);
1591 ipp_blit_sync(&ipp_req);
1595 par->y_offset = offset;
1596 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1597 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1598 par->xsize = var->xres; //visiable size in panel
1599 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1605 par->y_offset = offset;
1608 par->xsize = screen->x_res;
1609 par->ysize = screen->y_res;
1614 wake_up_interruptible_sync(&fb0_wait_queue);
1618 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1621 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1622 struct fb_var_screeninfo *var1 = &info->var;
1623 struct rk29fb_screen *screen = inf->cur_screen;
1624 struct win0_par *par = info->par;
1627 u16 ypos_virtual = var->yoffset;
1628 u16 xpos_virtual = var->xoffset;
1629 #ifdef CONFIG_FB_SCALING_OSD
1630 struct fb_fix_screeninfo *fix = &info->fix;
1631 struct rk29_ipp_req ipp_req;
1633 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1635 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1639 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1640 #if !defined(CONFIG_FB_SCALING_OSD)
1641 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1644 switch(var1->bits_per_pixel)
1647 var->xoffset = (var->xoffset) & (~0x1);
1648 #ifdef CONFIG_FB_SCALING_OSD
1649 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1650 ipp_req.src0.fmt = IPP_RGB_565;
1651 ipp_req.dst0.fmt = IPP_RGB_565;
1653 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1654 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1655 offset -= var->yres * var->xres *2;
1658 #ifdef CONFIG_FB_SCALING_OSD
1659 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1660 ipp_req.src0.fmt = IPP_XRGB_8888;
1661 ipp_req.dst0.fmt = IPP_XRGB_8888;
1663 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1664 if(ypos_virtual >= 2*var->yres)
1667 #ifdef CONFIG_FB_SCALING_OSD
1668 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1669 ipp_req.src0.fmt = IPP_RGB_565;
1670 ipp_req.dst0.fmt = IPP_RGB_565;
1672 if(ypos_virtual == 3*var->yres)
1674 offset -= var->yres * var->xres *2;
1682 if(inf->video_mode == 1)
1684 #ifdef CONFIG_FB_SCALING_OSD
1685 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1686 #ifndef CONFIG_FB_SCALING_OSD_1080P
1687 && (screen->x_res<=1280)
1691 par->y_offset = dstoffset;
1693 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1694 ipp_req.src0.w = var->xres;
1695 ipp_req.src0.h = var->yres;
1697 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1698 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1699 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1701 ipp_req.src_vir_w = ipp_req.src0.w;
1702 ipp_req.dst_vir_w = ipp_req.dst0.w;
1703 ipp_req.timeout = 100;
1704 ipp_req.flag = IPP_ROT_0;
1705 //ipp_do_blit(&ipp_req);
1706 ipp_blit_sync(&ipp_req);
1711 par->y_offset = offset;
1716 par->y_offset = offset;
1719 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1720 #if !ANDROID_USE_THREE_BUFS
1721 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1722 if(SCREEN_MCU == inf->cur_screen->type) {
1723 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1727 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1733 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1735 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1736 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1742 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1745 inf->mcu_usetimer = 0;
1748 case FBIOPUT_16OR32:
1750 inf->fb0_color_deepth = arg;
1753 case FBIOGET_16OR32:
1754 return inf->fb0_color_deepth;
1755 case FBIOGET_IDLEFBUff_16OR32:
1756 if(info->var.yoffset == 0)
1758 return fb0_second_buff_bits;
1762 return fb0_first_buff_bits;
1764 case FBIOSET_COMPOSE_LAYER_COUNTS:
1765 fb_compose_layer_count = arg;
1768 case FBIOGET_COMPOSE_LAYER_COUNTS:
1770 return fb_compose_layer_count;
1772 case FBIOPUT_FBPHYADD:
1773 return info->fix.smem_start;
1774 case FBIOGET_OVERLAY_STATE:
1775 return inf->video_mode;
1776 case FBIOGET_SCREEN_STATE:
1777 return inf->cur_screen->type;
1779 case FBIOPUT_SET_CURSOR_EN:
1782 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1784 rk29_set_cursor_en(inf, en);
1787 case FBIOPUT_SET_CURSOR_POS:
1789 struct fbcurpos pos;
1790 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1792 rk29_set_cursor_pos(inf, pos.x , pos.y);
1795 case FBIOPUT_SET_CURSOR_IMG:
1797 char cursor_buf[CURSOR_BUF_SIZE];
1798 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1800 rk29_set_cursor_img(inf, cursor_buf);
1803 case FBIOPUT_SET_CURSOR_CMAP:
1805 struct fb_image img;
1806 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1808 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1811 case FBIOPUT_GET_CURSOR_RESOLUTION:
1814 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1815 if(inf->fb1->var.rotate == 270) {
1816 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1817 panel_size[1] = inf->cur_screen->x_res;
1819 panel_size[0] = inf->cur_screen->x_res;
1820 panel_size[1] = inf->cur_screen->y_res;
1822 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1825 case FBIOPUT_GET_CURSOR_EN:
1827 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1828 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1837 static int fb1_blank(int blank_mode, struct fb_info *info)
1839 win0_blank(blank_mode, info);
1843 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1845 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1846 struct rk29fb_screen *screen = inf->cur_screen;
1848 u32 ScaleYRGBY=0x1000;
1849 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1850 u16 ypos = (var->nonstd>>20) & 0xfff;
1851 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1852 u16 ysize = (var->grayscale>>20) & 0xfff;
1853 u16 xlcd = screen->x_res; //size of panel
1854 u16 ylcd = screen->y_res;
1857 struct hdmi *hdmi = get_hdmi_struct(0);
1860 if((var->rotate == 270)||(var->rotate == 90)) {
1861 #ifdef CONFIG_FB_ROTATE_VIDEO
1862 xlcd = screen->y_res;
1863 ylcd = screen->x_res;
1864 #else //CONFIG_FB_ROTATE_VIDEO
1865 printk("LCDC not support rotate!\n");
1870 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1871 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1872 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1873 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1875 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1879 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1880 0==var->xres || 0==var->yres || var->xres<16 ||
1881 0==xsize || 0==ysize || xsize<16 ||
1882 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1884 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1885 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1886 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1887 var->bits_per_pixel, var->bits_per_pixel);
1891 if( (var->xoffset+var->xres)>var->xres_virtual ||
1892 (var->yoffset+var->yres)>var->yres_virtual ||
1893 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1895 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1896 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1897 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1898 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1902 switch(var->nonstd&0x0f)
1905 switch(var->bits_per_pixel)
1908 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1909 var->xres = (var->xres + 0x1) & (~0x1);
1910 var->xoffset = (var->xoffset) & (~0x1);
1913 var->bits_per_pixel = 32;
1916 var->nonstd &= ~0xc0; //not support I2P in this format
1919 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1920 var->xres = (var->xres + 0x3) & (~0x3);
1921 var->xoffset = (var->xoffset) & (~0x3);
1924 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1925 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1926 var->xres = (var->xres + 0x3) & (~0x3);
1927 var->yres = (var->yres + 0x1) & (~0x1);
1928 var->xoffset = (var->xoffset) & (~0x3);
1929 var->yoffset = (var->yoffset) & (~0x1);
1932 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1933 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1934 var->xres = (var->xres + 0x3) & (~0x3);
1935 var->yres = (var->yres + 0x1) & (~0x1);
1936 var->xoffset = (var->xoffset) & (~0x3);
1937 var->yoffset = (var->yoffset) & (~0x1);
1938 var->nonstd &= ~0xc0; //not support I2P in this format
1942 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1943 var->xres = (var->xres + 0x3) & (~0x3);
1944 var->xoffset = (var->xoffset) & (~0x3);
1945 var->nonstd &= ~0xc0; //not support I2P in this format
1948 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1952 if((var->rotate == 270)||(var->rotate == 90))
1961 ScaleYRGBY = CalScaleW0(yres, ysize);
1963 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1965 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1968 if(inf->video_mode == 1) {
1969 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1971 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1972 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1973 init_completion(&hdmi->complete);
1975 wait_for_completion_interruptible_timeout(&hdmi->complete,
1976 msecs_to_jiffies(10000));
1983 static int fb1_set_par(struct fb_info *info)
1985 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1986 struct rk29fb_screen *screen = inf->cur_screen;
1987 struct fb_var_screeninfo *var = &info->var;
1988 struct fb_fix_screeninfo *fix = &info->fix;
1989 struct win0_par *par = info->par;
1992 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1994 //u32 xact = var->xres; /* visible resolution */
1995 //u32 yact = var->yres;
1996 u32 xvir = var->xres_virtual; /* virtual resolution */
1997 u32 yvir = var->yres_virtual;
1998 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1999 u32 yact_st = var->yoffset; /* resolution */
2001 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
2002 u16 ypos = (var->nonstd>>20) & 0xfff;
2003 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
2004 u16 ysize = (var->grayscale>>20) & 0xfff;
2006 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
2007 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
2009 u8 data_format = var->nonstd&0x0f;
2010 // u32 win0_en = var->reserved[2];
2011 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
2012 // u32 uv_addr = var->reserved[4];
2014 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2017 if((var->rotate == 270)||(var->rotate == 90))
2019 #ifdef CONFIG_FB_ROTATE_VIDEO
2020 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
2021 ypos = (var->nonstd>>8) & 0xfff;
2022 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
2023 ysize = (var->grayscale>>8) & 0xfff;
2024 #else //CONFIG_FB_ROTATE_VIDEO
2025 printk("LCDC not support rotate!\n");
2029 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2030 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2031 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2032 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2034 /* calculate y_offset,c_offset,line_length,cblen and crlen */
2035 switch (data_format)
2038 switch(var->bits_per_pixel)
2042 fix->line_length = 2 * xvir;
2043 par->y_offset = (yact_st*xvir + xact_st)*2;
2047 fix->line_length = 4 * xvir;
2048 par->y_offset = (yact_st*xvir + xact_st)*4;
2056 fix->line_length = xvir;
2057 cblen = crlen = (xvir*yvir)/2;
2058 par->y_offset = yact_st*xvir + xact_st;
2059 par->c_offset = yact_st*xvir + xact_st;
2063 fix->line_length = xvir;
2064 cblen = crlen = (xvir*yvir)/4;
2066 par->y_offset = yact_st*xvir + xact_st;
2067 par->c_offset = (yact_st/2)*xvir + xact_st;
2072 fix->line_length = xvir;
2073 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
2074 par->c_offset = (yact_st/2)*xvir + xact_st;
2075 cblen = crlen = (xvir*yvir)/4;
2080 fix->line_length = xvir;
2081 par->y_offset = yact_st*xvir + xact_st;
2082 par->c_offset = yact_st*2*xvir + xact_st*2;
2083 cblen = crlen = (xvir*yvir);
2089 smem_len = fix->line_length * yvir + cblen + crlen;
2090 map_size = PAGE_ALIGN(smem_len);
2092 // fix->smem_start = y_addr;
2093 fix->smem_len = smem_len;
2094 // fix->mmio_start = uv_addr;
2096 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
2097 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);
2099 par->format = format;
2106 if ( wq_condition2 == 0 ) {
2107 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
2111 #ifdef CONFIG_FB_ROTATE_VIDEO
2112 //need refresh ,zyc add
2113 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
2116 struct rk29_ipp_req ipp_req;
2117 static u32 dstoffset = 0;
2118 static int fb_index = 0;
2119 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2120 yuv_phy[0] = last_yuv_phy[0];
2121 yuv_phy[1] = last_yuv_phy[1];
2122 yuv_phy[0] += par->y_offset;
2123 yuv_phy[1] += par->c_offset;
2125 if((var->rotate == 90) ||(var->rotate == 270))
2127 if(var->rotate%360 != 0)
2130 dstoffset = (dstoffset+1)%2;
2131 ipp_req.src0.fmt = 3;
2132 ipp_req.src0.YrgbMst = yuv_phy[0];
2133 ipp_req.src0.CbrMst = yuv_phy[1];
2134 ipp_req.src0.w = var->xres;
2135 ipp_req.src0.h = var->yres;
2137 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2138 ipp_req.dst_vir_w=screen->x_res;
2140 ipp_req.dst0.fmt = 3;
2141 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2142 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2143 if(var->xres > screen->x_res)
2145 ipp_req.dst0.w = screen->x_res;
2146 ipp_req.dst0.h = screen->y_res;
2148 ipp_req.dst0.w = var->xres;
2149 ipp_req.dst0.h = var->yres;
2151 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2153 ipp_req.timeout = 100;
2154 if(var->rotate == 90)
2155 ipp_req.flag = IPP_ROT_90;
2156 else if (var->rotate == 180)
2157 ipp_req.flag = IPP_ROT_180;
2158 else if(var->rotate == 270)
2159 ipp_req.flag = IPP_ROT_270;
2160 //ipp_do_blit(&ipp_req);
2161 ipp_blit_sync(&ipp_req);
2162 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2163 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2164 yuv_phy[1] = ipp_req.dst0.CbrMst;
2165 fix->smem_start = yuv_phy[0];
2166 fix->mmio_start = yuv_phy[1];
2171 fix->smem_start = yuv_phy[0];
2172 fix->mmio_start = yuv_phy[1];
2175 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2176 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2177 // enable win0 after the win0 par is seted
2178 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2179 par->addr_seted = 1;
2180 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2181 if(par->addr_seted ) {
2182 unsigned long flags;
2184 local_irq_save(flags);
2185 par->mirror.y_offset = yuv_phy[0];
2186 par->mirror.c_offset = yuv_phy[1];
2187 local_irq_restore(flags);
2190 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2195 has_set_rotate = false;
2200 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2202 struct win0_par *par = info->par;
2203 // enable win0 after the win0 addr is seted
2210 int fb1_open(struct fb_info *info, int user)
2212 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2213 struct win0_par *par = info->par;
2215 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2218 par->addr_seted = 0;
2219 inf->video_mode = 1;
2221 #ifdef CONFIG_FB_ROTATE_VIDEO
2222 //reinitialize the var when open,zyc
2223 last_yuv_phy[0] = 0;
2224 last_yuv_phy[1] = 0;
2228 printk(">>>>>> fb1 has opened! \n");
2232 win0_blank(FB_BLANK_NORMAL, info);
2233 fb0_set_par(inf->fb0);
2235 rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2240 int fb1_release(struct fb_info *info, int user)
2242 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2243 struct win0_par *par = info->par;
2244 struct fb_var_screeninfo *var0 = &info->var;
2246 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2247 if(inf->setFlag == 0)
2249 wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2253 inf->video_mode = 0;
2255 par->addr_seted = 0;
2256 win1_blank(FB_BLANK_NORMAL, info);
2258 //if(inf->cur_screen->type != SCREEN_HDMI)
2259 fb0_set_par(inf->fb0);
2262 info->screen_base = 0;
2263 info->fix.smem_start = 0;
2264 info->fix.smem_len = 0;
2265 // clean the var param
2266 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2267 rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2268 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2269 cancel_delayed_work_sync(&rk29_win1_check_work);
2276 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2278 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2279 struct win0_par *par = info->par;
2280 struct fb_fix_screeninfo *fix0 = &info->fix;
2281 struct fb_var_screeninfo *var = &info->var;
2282 void __user *argp = (void __user *)arg;
2284 #ifdef CONFIG_FB_ROTATE_VIDEO
2285 struct rk29fb_screen *screen = inf->cur_screen;
2286 struct rk29_ipp_req ipp_req;
2287 static u32 dstoffset = 0;
2288 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2291 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2292 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2298 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2301 if((var->rotate == 270)||(var->rotate == 90)) {
2302 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2303 panel_size[1] = inf->panel1_info.x_res;
2305 panel_size[0] = inf->panel1_info.x_res;
2306 panel_size[1] = inf->panel1_info.y_res;
2309 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2313 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2316 if (copy_from_user(yuv_phy, argp, 8))
2318 #ifdef CONFIG_FB_ROTATE_VIDEO
2320 if(has_set_rotate == true)
2322 last_yuv_phy[0] = yuv_phy[0];
2323 last_yuv_phy[1] = yuv_phy[1];
2326 fix0->smem_start = yuv_phy[0];
2327 fix0->mmio_start = yuv_phy[1];
2328 yuv_phy[0] += par->y_offset;
2329 yuv_phy[1] += par->c_offset;
2332 if((var->rotate == 90) ||(var->rotate == 270))
2334 if(var->rotate%360 != 0)
2337 #ifdef CONFIG_FB_ROTATE_VIDEO
2338 dstoffset = (dstoffset+1)%2;
2339 ipp_req.src0.fmt = 3;
2340 ipp_req.src0.YrgbMst = yuv_phy[0];
2341 ipp_req.src0.CbrMst = yuv_phy[1];
2342 ipp_req.src0.w = var->xres ;
2343 ipp_req.src0.h = var->yres ;
2344 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2345 ipp_req.dst_vir_w=screen->x_res;
2347 ipp_req.dst0.fmt = 3;
2348 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2349 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2350 if(var->xres > screen->x_res)
2352 ipp_req.dst0.w = screen->x_res;
2353 ipp_req.dst0.h = screen->y_res;
2355 ipp_req.dst0.w = var->xres;
2356 ipp_req.dst0.h = var->yres;
2359 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2360 ipp_req.timeout = 100;
2361 if(var->rotate == 90)
2362 ipp_req.flag = IPP_ROT_90;
2363 else if(var->rotate == 180)
2364 ipp_req.flag = IPP_ROT_180;
2365 else if(var->rotate == 270)
2366 ipp_req.flag = IPP_ROT_270;
2367 //ipp_do_blit(&ipp_req);
2368 ipp_blit_sync(&ipp_req);
2370 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2371 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2372 yuv_phy[1] = ipp_req.dst0.CbrMst;
2373 fix0->smem_start = yuv_phy[0];
2374 fix0->mmio_start = yuv_phy[1];
2375 #else //CONFIG_FB_ROTATE_VIDEO
2376 printk("LCDC not support rotate!\n");
2380 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2381 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2382 // enable win0 after the win0 par is seted
2383 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2384 par->addr_seted = 1;
2385 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2386 if(par->par_seted) {
2387 unsigned long flags;
2389 local_irq_save(flags);
2390 par->mirror.y_offset = yuv_phy[0];
2391 par->mirror.c_offset = yuv_phy[1];
2392 local_irq_restore(flags);
2395 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2400 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2401 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2402 #ifdef CONFIG_FB_ROTATE_VIDEO
2404 has_set_rotate = true;
2405 if(arg == 0 || arg==180)
2407 else if (arg == 90 || arg==270)
2409 #else //CONFIG_FB_ROTATE_VIDEO
2410 printk("LCDC not support rotate!\n");
2413 case FB1_IOCTL_SET_WIN0_TOP:
2414 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2415 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2416 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2424 static struct fb_ops fb1_ops = {
2425 .owner = THIS_MODULE,
2426 .fb_open = fb1_open,
2427 .fb_release = fb1_release,
2428 .fb_check_var = fb1_check_var,
2429 .fb_set_par = fb1_set_par,
2430 .fb_blank = fb1_blank,
2431 .fb_pan_display = fb1_pan_display,
2432 .fb_ioctl = fb1_ioctl,
2433 .fb_setcolreg = fb_setcolreg,
2434 .fb_fillrect = cfb_fillrect,
2435 .fb_copyarea = cfb_copyarea,
2436 .fb_imageblit = cfb_imageblit,
2439 static struct fb_ops fb0_ops = {
2440 .owner = THIS_MODULE,
2441 .fb_check_var = fb0_check_var,
2442 .fb_set_par = fb0_set_par,
2443 .fb_blank = fb0_blank,
2444 .fb_pan_display = fb0_pan_display,
2445 .fb_ioctl = fb0_ioctl,
2446 .fb_setcolreg = fb_setcolreg,
2447 .fb_fillrect = cfb_fillrect,
2448 .fb_copyarea = cfb_copyarea,
2449 .fb_imageblit = cfb_imageblit,
2450 //.fb_cursor = rk29_set_cursor,
2453 int fb_get_video_mode(void)
2455 struct rk29fb_inf *inf;
2458 inf = platform_get_drvdata(g_pdev);
2459 return inf->video_mode;
2462 enable: 1, switch to tv or hdmi; 0, switch to lcd
2464 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2466 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2467 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2468 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2470 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2472 if(enable)inf->cur_screen = &inf->panel2_info;
2473 else inf->cur_screen = &inf->panel1_info;
2475 /* Black out, because some display device need clock to standby */
2476 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2477 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2478 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2479 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2480 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2481 wake_lock(&idlelock);
2483 wake_unlock(&idlelock);
2485 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2486 // operate the display_on pin to power down the lcd
2488 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2489 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2491 load_screen(inf->fb0, 0);
2494 fb1_set_par(inf->fb1);
2495 fb0_set_par(inf->fb0);
2496 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2497 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2498 rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2502 static ssize_t dsp_win0_info_read(struct device *device,
2503 struct device_attribute *attr, char *buf)
2506 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2507 struct rk29fb_screen *screen = inf->cur_screen;
2509 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2511 fbprintk("%s\n",__FUNCTION__);
2512 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2513 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2515 xpos -= (screen->left_margin + screen->hsync_len);
2516 ypos -= (screen->upper_margin + screen->vsync_len);
2518 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2519 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2520 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2521 rk29_set_cursor_test(inf->fb0);
2523 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2526 static ssize_t dsp_win0_info_write(struct device *device,
2527 struct device_attribute *attr, const char *buf, size_t count)
2529 printk("%s\n",__FUNCTION__);
2530 printk("%s %x \n",__FUNCTION__,*buf);
2534 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2536 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2538 struct platform_device *pdev = (struct platform_device*)dev_id;
2539 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2540 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2544 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2546 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2548 if(SCREEN_MCU == inf->cur_screen->type)
2550 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2556 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2558 inf->mcu_fmksync = 1;
2559 if(inf->cur_screen->refresh)
2560 inf->cur_screen->refresh(REFRESH_END);
2561 inf->mcu_fmksync = 0;
2570 if(inf->mcu_needflush) {
2571 if(inf->cur_screen->refresh)
2572 inf->cur_screen->refresh(REFRESH_PRE);
2573 inf->mcu_needflush = 0;
2574 inf->mcu_isrcnt = 0;
2575 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2577 if(inf->cur_screen->refresh)
2578 inf->cur_screen->refresh(REFRESH_END);
2582 #if ANDROID_USE_THREE_BUFS
2583 new_frame_seted = 1;
2586 if(waitqueue_active(&par->wait)) {
2587 if (par->mirror.c_offset == 0)
2588 printk("error: no new buffer to display\n");
2590 par->done.y_offset = par->displ.y_offset;
2591 par->done.c_offset = par->displ.c_offset;
2592 par->displ.y_offset = par->mirror.y_offset;
2593 par->displ.c_offset = par->mirror.c_offset;
2594 par->mirror.y_offset = 0;
2595 par->mirror.c_offset = 0;
2597 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2598 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2599 wake_up_interruptible(&par->wait);
2604 wake_up_interruptible(&wq);
2606 rk29fb_irq_notify_ddr();
2610 #ifdef CONFIG_HAS_EARLYSUSPEND
2612 struct suspend_info {
2613 struct early_suspend early_suspend;
2614 struct rk29fb_inf *inf;
2617 static void rk29fb_early_suspend(struct early_suspend *h)
2619 struct suspend_info *info = container_of(h, struct suspend_info,
2622 struct rk29fb_inf *inf = info->inf;
2623 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2625 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2628 printk("inf==0, rk29fb_suspend fail! \n");
2632 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2633 cancel_delayed_work_sync(&rk29_win1_check_work);
2636 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2637 mach_info->io_disable(); //close lcd out
2639 if(inf->cur_screen->standby)
2641 fbprintk(">>>>>> power down the screen! \n");
2642 inf->cur_screen->standby(1);
2645 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2646 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2648 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2649 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2650 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2652 if(!inf->in_suspend)
2654 fbprintk(">>>>>> diable the lcdc clk! \n");
2655 wake_lock(&idlelock);
2657 wake_unlock(&idlelock);
2658 clk_disable(inf->aclk_ddr_lcdc);
2659 clk_disable(inf->aclk_disp_matrix);
2660 clk_disable(inf->hclk_cpu_display);
2661 clk_disable(inf->clk);
2663 clk_disable(inf->dclk);
2666 clk_disable(inf->aclk);
2668 //clk_disable(inf->pd_display);
2670 inf->in_suspend = 1;
2674 static void rk29fb_early_resume(struct early_suspend *h)
2676 struct suspend_info *info = container_of(h, struct suspend_info,
2679 struct rk29fb_inf *inf = info->inf;
2680 struct rk29fb_screen *screen = inf->cur_screen;
2681 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2683 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2685 printk("inf==0, rk29fb_resume fail! \n");
2691 inf->in_suspend = 0;
2692 fbprintk(">>>>>> enable the lcdc clk! \n");
2693 // clk_enable(inf->pd_display);
2694 clk_enable(inf->aclk_disp_matrix);
2695 clk_enable(inf->hclk_cpu_display);
2696 clk_enable(inf->clk);
2697 clk_enable(inf->aclk_ddr_lcdc);
2700 clk_enable(inf->dclk);
2703 clk_enable(inf->aclk);
2705 usleep_range(100*1000, 100*1000);
2707 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2708 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2709 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2711 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2712 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2714 if(inf->cur_screen->standby)
2716 fbprintk(">>>>>> power on the screen! \n");
2717 inf->cur_screen->standby(0);
2719 usleep_range(10*1000, 10*1000);
2720 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2721 usleep_range(40*1000, 40*1000);
2723 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2724 mach_info->io_enable(); //close lcd out
2728 static struct suspend_info suspend_info = {
2729 .early_suspend.suspend = rk29fb_early_suspend,
2730 .early_suspend.resume = rk29fb_early_resume,
2731 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2734 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2735 static int __init rk29fb_probe (struct platform_device *pdev)
2737 struct rk29fb_inf *inf = NULL;
2738 struct resource *res = NULL;
2739 struct resource *mem = NULL;
2740 struct rk29fb_info *mach_info = NULL;
2741 struct rk29fb_screen *screen = NULL;
2742 struct win0_par* par = NULL;
2746 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2748 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2749 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2750 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2753 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2755 goto release_drvdata;
2757 memset(inf, 0, sizeof(struct rk29fb_inf));
2758 platform_set_drvdata(pdev, inf);
2760 mach_info = pdev->dev.platform_data;
2761 /* Fill screen info and set current screen */
2762 fbprintk(">> Fill screen info and set current screen \n");
2763 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2764 hdmi_get_default_resolution(&inf->panel1_info);
2766 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2768 inf->cur_screen = &inf->panel1_info;
2769 screen = inf->cur_screen;
2770 if(SCREEN_NULL==screen->type)
2772 dev_err(&pdev->dev, ">> Please select a display device! \n");
2774 goto release_drvdata;
2777 /* get virtual basic address of lcdc register */
2778 fbprintk(">> get virtual basic address of lcdc register \n");
2779 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2782 dev_err(&pdev->dev, "failed to get memory registers\n");
2784 goto release_drvdata;
2786 inf->reg_phy_base = res->start;
2787 inf->len = (res->end - res->start) + 1;
2788 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2791 dev_err(&pdev->dev, "failed to get memory region\n");
2793 goto release_drvdata;
2795 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2796 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2797 if (inf->reg_vir_base == NULL)
2799 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2801 goto release_drvdata;
2803 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2805 /* Prepare win1 info */
2806 fbprintk(">> Prepare win1 info \n");
2807 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2810 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2813 goto release_win1fb;
2816 par = (struct win0_par*)inf->fb0->par;
2817 strcpy(inf->fb0->fix.id, "fb0");
2818 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2819 inf->fb0->fix.type_aux = 0;
2820 inf->fb0->fix.xpanstep = 1;
2821 inf->fb0->fix.ypanstep = 1;
2822 inf->fb0->fix.ywrapstep = 0;
2823 inf->fb0->fix.accel = FB_ACCEL_NONE;
2824 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2825 inf->fb0->fix.smem_len = 0;
2826 inf->fb0->fix.line_length = 0;
2827 inf->fb0->fix.smem_start = 0;
2829 inf->fb0->var.xres = screen->x_res;
2830 inf->fb0->var.yres = screen->y_res;
2831 inf->fb0->var.bits_per_pixel = 16;
2832 inf->fb0_color_deepth = 0;
2833 inf->fb0->var.xres_virtual = screen->x_res;
2834 inf->fb0->var.yres_virtual = screen->y_res;
2835 inf->fb0->var.width = screen->width;
2836 inf->fb0->var.height = screen->height;
2837 //inf->fb0->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
2838 inf->fb0->var.left_margin = screen->left_margin;
2839 inf->fb0->var.right_margin = screen->right_margin;
2840 inf->fb0->var.upper_margin = screen->upper_margin;
2841 inf->fb0->var.lower_margin = screen->lower_margin;
2842 inf->fb0->var.vsync_len = screen->vsync_len;
2843 inf->fb0->var.hsync_len = screen->hsync_len;
2844 inf->fb0->var.red = def_rgb_16.red;
2845 inf->fb0->var.green = def_rgb_16.green;
2846 inf->fb0->var.blue = def_rgb_16.blue;
2847 inf->fb0->var.transp = def_rgb_16.transp;
2849 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2850 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2851 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2852 inf->fb0->var.accel_flags = 0;
2853 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2855 inf->fb0->fbops = &fb0_ops;
2856 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2857 inf->fb0->pseudo_palette = par->pseudo_pal;
2858 inf->fb0->screen_base = 0;
2860 memset(par, 0, sizeof(struct win0_par));
2862 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2866 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2868 /* alloc win1 buf */
2869 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2872 dev_err(&pdev->dev, "failed to get win1 memory \n");
2874 goto release_win1fb;
2876 inf->fb0->fix.smem_start = res->start;
2877 inf->fb0->fix.smem_len = res->end - res->start + 1;
2878 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2879 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2881 #ifdef CONFIG_FB_WORK_IPP
2882 /* alloc win1 ipp buf */
2883 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2886 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2888 goto release_win1fb;
2890 inf->fb0->fix.mmio_start = res->start;
2891 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2894 /* Prepare win0 info */
2895 fbprintk(">> Prepare win0 info \n");
2896 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2899 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2902 goto release_win0fb;
2905 par = (struct win0_par*)inf->fb1->par;
2907 strcpy(inf->fb1->fix.id, "fb1");
2908 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2909 inf->fb1->fix.type_aux = 0;
2910 inf->fb1->fix.xpanstep = 1;
2911 inf->fb1->fix.ypanstep = 1;
2912 inf->fb1->fix.ywrapstep = 0;
2913 inf->fb1->fix.accel = FB_ACCEL_NONE;
2914 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2915 inf->fb1->fix.smem_len = 0;
2916 inf->fb1->fix.line_length = 0;
2917 inf->fb1->fix.smem_start = 0;
2919 inf->fb1->var.xres = screen->x_res;
2920 inf->fb1->var.yres = screen->y_res;
2921 inf->fb1->var.bits_per_pixel = 16;
2922 inf->fb1->var.xres_virtual = screen->x_res;
2923 inf->fb1->var.yres_virtual = screen->y_res;
2924 inf->fb1->var.width = screen->width;
2925 inf->fb1->var.height = screen->height;
2926 //inf->fb1->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
2927 inf->fb1->var.left_margin = screen->left_margin;
2928 inf->fb1->var.right_margin = screen->right_margin;
2929 inf->fb1->var.upper_margin = screen->upper_margin;
2930 inf->fb1->var.lower_margin = screen->lower_margin;
2931 inf->fb1->var.vsync_len = screen->vsync_len;
2932 inf->fb1->var.hsync_len = screen->hsync_len;
2933 inf->fb1->var.red = def_rgb_16.red;
2934 inf->fb1->var.green = def_rgb_16.green;
2935 inf->fb1->var.blue = def_rgb_16.blue;
2936 inf->fb1->var.transp = def_rgb_16.transp;
2938 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2939 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2940 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2941 inf->fb1->var.accel_flags = 0;
2942 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2944 inf->fb1->fbops = &fb1_ops;
2945 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2946 inf->fb1->pseudo_palette = par->pseudo_pal;
2947 inf->fb1->screen_base = 0;
2949 memset(par, 0, sizeof(struct win0_par));
2951 init_waitqueue_head(&par->wait);
2953 /* Init all lcdc and lcd before register_framebuffer. */
2954 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2955 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2956 init_lcdc(inf->fb0);
2958 #if 0 //def CONFIG_CPU_FREQ
2959 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2960 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2962 fbprintk("got clock\n");
2966 struct rk29_fb_setting_info fb_setting;
2967 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2969 fb_setting.data_num = 24;
2971 else if(OUT_P666 == inf->cur_screen->face )
2973 fb_setting.data_num = 18;
2977 fb_setting.data_num = 16;
2979 fb_setting.den_en = 1;
2980 fb_setting.vsync_en = 1;
2981 fb_setting.disp_on_en = 1;
2982 fb_setting.standby_en = 1;
2983 if( inf->cur_screen->mcu_usefmk )
2984 fb_setting.mcu_fmk_en =1;
2985 mach_info->io_init(&fb_setting);
2988 //set_lcd_pin(pdev, 1);
2991 inf->mcu_usetimer = 1;
2992 inf->mcu_fmksync = 0;
2993 load_screen(inf->fb0, 1);
2995 /* Register framebuffer(fb0 & fb1) */
2996 fbprintk(">> Register framebuffer(fb0) \n");
2997 ret = register_framebuffer(inf->fb0);
3000 printk(">> fb0 register_framebuffer fail!\n");
3002 goto release_win0fb;
3004 fbprintk(">> Register framebuffer(fb1) \n");
3006 ret = register_framebuffer(inf->fb1);
3009 printk(">> fb1 register_framebuffer fail!\n");
3011 goto unregister_win1fb;
3014 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3017 printk(">> fb1 dsp win0 info device_create_file err\n");
3020 #ifdef CONFIG_HAS_EARLYSUSPEND
3021 suspend_info.inf = inf;
3022 register_early_suspend(&suspend_info.early_suspend);
3025 /* get and request irq */
3026 fbprintk(">> get and request irq \n");
3027 irq = platform_get_irq(pdev, 0);
3029 dev_err(&pdev->dev, "no irq for device\n");
3031 goto unregister_win1fb;
3033 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
3035 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
3040 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
3042 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
3045 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
3051 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
3052 fb0_set_par(inf->fb0);
3053 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
3054 /* Start display and show logo on boot */
3055 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
3056 fb_show_logo(inf->fb0, FB_ROTATE_UR);
3057 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
3061 printk(" %s ok\n", __FUNCTION__);
3066 free_irq(irq, pdev);
3068 unregister_framebuffer(inf->fb0);
3071 framebuffer_release(inf->fb1);
3075 fb_dealloc_cmap(&inf->fb0->cmap);
3078 framebuffer_release(inf->fb0);
3081 if(inf && inf->reg_vir_base)
3082 iounmap(inf->reg_vir_base);
3084 release_mem_region(inf->reg_phy_base, inf->len);
3087 platform_set_drvdata(pdev, NULL);
3091 static int rk29fb_remove(struct platform_device *pdev)
3093 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3094 struct fb_info *info = NULL;
3096 struct rk29fb_info *mach_info = NULL;
3099 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3102 printk("inf==0, rk29_fb_remove fail! \n");
3105 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3107 irq = platform_get_irq(pdev, 0);
3110 free_irq(irq, pdev);
3113 mach_info = pdev->dev.platform_data;
3114 if(mach_info->mcu_fmk_pin)
3116 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
3119 if(mach_info->io_disable)
3120 mach_info->io_disable(); //close lcd out
3124 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
3126 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
3129 //rk29fb_suspend(pdev, msg);
3130 // unmap memory and release framebuffer
3133 if (info->screen_base) {
3134 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3135 info->screen_base = 0;
3136 info->fix.smem_start = 0;
3137 info->fix.smem_len = 0;
3139 unregister_framebuffer(inf->fb1);
3140 framebuffer_release(inf->fb1);
3145 if (info->screen_base) {
3146 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3147 info->screen_base = 0;
3148 info->fix.smem_start = 0;
3149 info->fix.smem_len = 0;
3151 unregister_framebuffer(inf->fb0);
3152 framebuffer_release(inf->fb0);
3156 #if 0 //def CONFIG_CPU_FREQ
3157 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3164 clk_disable(inf->clk);
3170 clk_disable(inf->dclk);
3176 platform_set_drvdata(pdev, NULL);
3181 static void rk29fb_shutdown(struct platform_device *pdev)
3183 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3184 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3186 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3188 if(mach_info->io_disable)
3189 mach_info->io_disable(); //close lcd out
3191 if(!inf->in_suspend)
3193 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3194 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3195 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3197 clk_disable(inf->aclk_ddr_lcdc);
3198 clk_disable(inf->aclk_disp_matrix);
3199 clk_disable(inf->hclk_cpu_display);
3200 clk_disable(inf->clk);
3202 clk_disable(inf->dclk);
3205 clk_disable(inf->aclk);
3207 clk_disable(inf->pd_display);
3208 //pmu_set_power_domain(PD_DISPLAY, 0);
3209 inf->in_suspend = 1;
3214 static struct platform_driver rk29fb_driver = {
3215 .probe = rk29fb_probe,
3216 .remove = rk29fb_remove,
3219 .owner = THIS_MODULE,
3221 .shutdown = rk29fb_shutdown,
3224 static int __init rk29fb_init(void)
3226 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3227 return platform_driver_register(&rk29fb_driver);
3230 static void __exit rk29fb_exit(void)
3232 platform_driver_unregister(&rk29fb_driver);
3235 fs_initcall(rk29fb_init);
3236 module_exit(rk29fb_exit);
3239 MODULE_AUTHOR(" zyw@rock-chips.com");
3240 MODULE_DESCRIPTION("Driver for rk29 fb device");
3241 MODULE_LICENSE("GPL");