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)
261 static DECLARE_WAIT_QUEUE_HEAD(wq);
262 static int wq_condition = 0;
263 static int wq_condition2 = 0;
264 #if ANDROID_USE_THREE_BUFS
265 static int new_frame_seted = 1;
267 static struct wake_lock idlelock; /* only for fb */
268 #ifdef CONFIG_FB_ROTATE_VIDEO
270 static bool has_set_rotate;
271 static u32 last_yuv_phy[2] = {0,0};
273 int fb0_first_buff_bits = 32;
274 int fb0_second_buff_bits = 32;
275 int fb_compose_layer_count = 0;
276 static BLOCKING_NOTIFIER_HEAD(rk29fb_notifier_list);
277 int rk29fb_register_notifier(struct notifier_block *nb)
281 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
283 if (inf->cur_screen && inf->cur_screen->type == SCREEN_HDMI)
284 nb->notifier_call(nb, RK29FB_EVENT_HDMI_ON, inf->cur_screen);
285 if (inf->fb1 && inf->fb1->par) {
286 struct win0_par *par = inf->fb1->par;
288 nb->notifier_call(nb, RK29FB_EVENT_FB1_ON, inf->cur_screen);
292 ret = blocking_notifier_chain_register(&rk29fb_notifier_list, nb);
297 int rk29fb_unregister_notifier(struct notifier_block *nb)
299 return blocking_notifier_chain_unregister(&rk29fb_notifier_list, nb);
302 static int rk29fb_notify(struct rk29fb_inf *inf, unsigned long event)
304 return blocking_notifier_call_chain(&rk29fb_notifier_list, event, inf->cur_screen);
307 int mcu_do_refresh(struct rk29fb_inf *inf)
309 if(inf->mcu_stopflush) return 0;
311 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
316 inf->mcu_needflush = 1;
320 // not use frame mark
321 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
323 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
325 inf->mcu_needflush = 1;
329 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
330 inf->mcu_needflush = 0;
332 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
339 void mcutimer_callback(unsigned long arg)
341 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
342 static int waitcnt = 0;
344 mod_timer(&inf->mcutimer, jiffies + HZ/10);
346 switch(inf->mcu_status)
349 inf->mcu_status = MS_MCU;
352 if(inf->mcu_usetimer) mcu_do_refresh(inf);
355 inf->mcu_status = MS_EWAITEND;
363 inf->mcu_status = MS_EEND;
367 inf->mcu_status = MS_MCU;
370 inf->mcu_status = MS_MCU;
375 int mcu_refresh(struct rk29fb_inf *inf)
377 static int mcutimer_inited = 0;
379 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
384 init_timer(&inf->mcutimer);
385 inf->mcutimer.function = mcutimer_callback;
386 inf->mcutimer.expires = jiffies + HZ/5;
387 inf->mcu_status = MS_IDLE;
388 add_timer(&inf->mcutimer);
391 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
396 int mcu_ioctl(unsigned int cmd, unsigned long arg)
398 struct rk29fb_inf *inf = NULL;
399 if(!g_pdev) return -1;
401 inf = dev_get_drvdata(&g_pdev->dev);
406 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
407 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
408 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
412 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
413 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
417 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
418 LcdWrReg(inf, REG_CFG_DONE, 0x01);
428 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
430 struct platform_device *pdev = (struct platform_device*)dev_id;
431 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
432 struct rk29fb_screen *screen;
434 if(!inf) return IRQ_HANDLED;
436 screen = inf->cur_screen;
438 if(0==screen->mcu_usefmk) {
442 if(inf->mcu_fmksync == 1)
445 inf->mcu_fmksync = 1;
446 if(inf->mcu_needflush)
448 inf->mcu_needflush = 0;
450 if(inf->cur_screen->refresh)
451 inf->cur_screen->refresh(REFRESH_PRE);
452 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
454 inf->mcu_fmksync = 0;
459 int init_lcdc(struct fb_info *info)
461 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
464 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
466 inf->clk = clk_get(NULL, "hclk_lcdc");
467 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
468 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
469 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
470 inf->pd_display = clk_get(NULL, "pd_display");
471 if ((IS_ERR(inf->clk)) ||
472 (IS_ERR(inf->aclk_ddr_lcdc)) ||
473 (IS_ERR(inf->aclk_disp_matrix)) ||
474 (IS_ERR(inf->hclk_cpu_display)) ||
475 (IS_ERR(inf->pd_display)))
477 printk(KERN_ERR "failed to get lcdc_hclk source\n");
478 return PTR_ERR(inf->clk);
480 clk_enable(inf->aclk_disp_matrix);
481 clk_enable(inf->hclk_cpu_display);
482 clk_enable(inf->clk);
483 clk_enable(inf->pd_display);
484 //pmu_set_power_domain(PD_DISPLAY, 1);
485 clk_enable(inf->aclk_ddr_lcdc);
487 // set AHB access rule and disable all windows
488 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
489 LcdWrReg(inf, SWAP_CTRL, 0);
490 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
491 LcdWrReg(inf, AXI_MS_ID, 0x54321);
493 // and mcu holdmode; and set win1 top.
494 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
495 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
497 // disable blank out, black out, tristate out, yuv2rgb bypass
498 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
499 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
500 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
501 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
504 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
505 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
507 LcdWrReg(inf, DSP_CTRL1, 0);
509 // initialize all interrupt
510 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
512 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
514 LcdWrReg(inf, INT_STATUS, clr | msk);
516 // let above to take effect
517 LcdWrReg(inf, REG_CFG_DONE, 0x01);
522 void load_screen(struct fb_info *info, bool initscreen)
525 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
526 struct rk29fb_screen *screen = inf->cur_screen;
528 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
529 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
530 u16 x_res = screen->x_res, y_res = screen->y_res;
531 u32 aclk_rate = 150000000;
534 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
538 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
540 // set the rgb or mcu
541 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
543 // set out format and mcu timing
544 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
545 if(mcu_total>31) mcu_total = 31;
546 if(mcu_total<3) mcu_total = 3;
547 mcu_rwstart = (mcu_total+1)/4 - 1;
548 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
549 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
550 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
552 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
553 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
555 LcdMskReg(inf, MCU_TIMING_CTRL,
556 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
557 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
558 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
559 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
560 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
563 // set synchronous pin polarity and data pin swap rule
564 switch (screen->face)
568 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
572 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
576 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
580 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
584 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
585 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
588 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
589 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
594 LcdMskReg(inf, DSP_CTRL0,
595 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
596 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
597 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
598 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
601 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
603 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
604 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));
606 // set horizontal & vertical out timing
607 if(SCREEN_MCU==inf->cur_screen->type)
609 right_margin = x_res/6;
612 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
613 screen->hsync_len , screen->left_margin , x_res , right_margin );
614 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
615 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
616 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
617 v_BIT12HI(screen->hsync_len + screen->left_margin));
619 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
620 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
621 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
622 v_BIT11HI(screen->vsync_len + screen->upper_margin));
624 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
625 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
627 // let above to take effect
628 LcdWrReg(inf, REG_CFG_DONE, 0x01);
630 inf->dclk = clk_get(NULL, "dclk_lcdc");
631 if (IS_ERR(inf->dclk))
633 printk(KERN_ERR "failed to get lcd dclock source\n");
637 inf->aclk = clk_get(NULL, "aclk_lcdc");
638 if (IS_ERR(inf->aclk))
640 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
643 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
644 if (IS_ERR(inf->aclk_parent))
646 printk(KERN_ERR "failed to get lcd clock parent source\n");
651 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
653 if(initscreen == 0) //not init
655 clk_disable(inf->dclk);
656 // clk_disable(inf->aclk);
659 // clk_disable(inf->aclk_ddr_lcdc);
660 // clk_disable(inf->aclk_disp_matrix);
661 // clk_disable(inf->hclk_cpu_display);
663 // clk_disable(inf->clk);
666 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
668 ret = clk_set_rate(inf->dclk, screen->pixclock);
671 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
673 inf->fb0->var.pixclock = inf->fb1->var.pixclock = div_u64(1000000000000llu, clk_get_rate(inf->dclk));
676 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
677 if(screen->lcdc_aclk){
678 aclk_rate = screen->lcdc_aclk;
680 ret = clk_set_rate(inf->aclk, aclk_rate);
682 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
684 clk_enable(inf->aclk);
686 // clk_enable(inf->aclk_ddr_lcdc);
687 // clk_enable(inf->aclk_disp_matrix);
688 // clk_enable(inf->hclk_cpu_display);
689 // clk_enable(inf->clk);
690 clk_enable(inf->dclk);
698 #if 0 //def CONFIG_CPU_FREQ
700 * CPU clock speed change handler. We need to adjust the LCD timing
701 * parameters when the CPU clock is adjusted by the power management
704 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
707 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
709 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
710 struct rk29fb_screen *screen = inf->cur_screen;
715 case CPUFREQ_PRECHANGE:
717 case CPUFREQ_POSTCHANGE:
719 dclk_rate = screen->pixclock * 1000000;
721 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
723 clk_set_rate(inf->dclk_divider, dclk_rate);
731 static inline unsigned int chan_to_field(unsigned int chan,
732 struct fb_bitfield *bf)
735 chan >>= 16 - bf->length;
736 return chan << bf->offset;
739 static int fb_setcolreg(unsigned regno,
740 unsigned red, unsigned green, unsigned blue,
741 unsigned transp, struct fb_info *info)
744 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
746 switch (info->fix.visual) {
747 case FB_VISUAL_TRUECOLOR:
748 /* true-colour, use pseudo-palette */
750 u32 *pal = info->pseudo_palette;
751 val = chan_to_field(red, &info->var.red);
752 val |= chan_to_field(green, &info->var.green);
753 val |= chan_to_field(blue, &info->var.blue);
758 return -1; /* unknown type */
764 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
767 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
769 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
771 LcdWrReg(inf, REG_CFG_DONE, 0x01);
775 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
777 struct rk29fb_screen *screen = inf->cur_screen;
780 if (x >= 0x800 || y >= 0x800 )
782 //printk("%s: %08x,%08x \n",__func__, x, y);
783 x += (screen->left_margin + screen->hsync_len);
784 y += (screen->upper_margin + screen->vsync_len);
785 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
786 LcdWrReg(inf, REG_CFG_DONE, 0x01);
791 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
793 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
794 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
795 LcdWrReg(inf, REG_CFG_DONE, 0x01);
799 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
800 int rk29_set_cursor_img_transform(char *data)
803 char *dst = (char*)rk29_cursor_buf;
804 unsigned char dmsk = 0;
805 unsigned int op,shift,offset;
807 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
808 * clears it to transparent then combines the cursor
809 * shape plane with the colour plane to set the
811 for (y = 0; y < 32; y++)
813 for (x = 0; x < 32; x++)
820 op = (dmsk & 0x80) ? 2 : 3;
823 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
833 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
837 rk29_set_cursor_img_transform(data);
841 rk29_set_cursor_img_transform(cursor_img);
843 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
844 //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
845 LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
847 LcdWrReg(inf, REG_CFG_DONE, 0x01);
852 int rk29_set_cursor_test(struct fb_info *info)
854 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
855 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
856 rk29_set_cursor_pos(inf, 0, 0);
857 rk29_set_cursor_img(inf, 0);
858 rk29_set_cursor_en(inf, 1);
863 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
865 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
867 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
869 /* check not being asked to exceed capabilities */
871 if (cursor->image.width > 32)
874 if (cursor->image.height > 32)
877 if (cursor->image.depth > 1)
881 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
883 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
886 if (cursor->set & FB_CUR_SETPOS)
888 unsigned int x = cursor->image.dx;
889 unsigned int y = cursor->image.dy;
891 if (x >= 0x800 || y >= 0x800 )
893 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
897 if (cursor->set & FB_CUR_SETCMAP)
899 unsigned int bg_col = cursor->image.bg_color;
900 unsigned int fg_col = cursor->image.fg_color;
902 fbprintk("%s: update cmap (%08x,%08x)\n",
903 __func__, bg_col, fg_col);
905 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
906 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));
908 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
909 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));
912 if ((cursor->set & FB_CUR_SETSIZE ||
913 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
914 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
916 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
917 * clears it to transparent then combines the cursor
918 * shape plane with the colour plane to set the
921 const unsigned char *pcol = cursor->image.data;
922 const unsigned char *pmsk = cursor->mask;
924 unsigned long cursor_mem_start;
925 unsigned char dcol = 0;
926 unsigned char dmsk = 0;
929 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
930 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
932 fbprintk("%s: setting shape (%d,%d)\n",
933 __func__, cursor->image.width, cursor->image.height);
935 memset(dst, 0, CURSOR_BUF_SIZE);
937 for (y = 0; y < cursor->image.height; y++)
939 for (x = 0; x < cursor->image.width; x++)
950 op = (dcol & 1) ? 1 : 3;
951 op <<= ((x % 4) * 2);
952 *(u8*)(dst+(x/4)) |= op;
957 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
958 LcdWrReg(inf, HWC_MST, cursor_mem_start);
959 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
960 if(SCREEN_MCU == inf->cur_screen->type) {
961 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
965 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
967 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
973 static int hdmi_get_fbscale(void)
976 return hdmi_get_scale();
981 static void hdmi_set_fbscale(struct fb_info *info)
984 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
985 struct rk29fb_screen *screen = inf->cur_screen;
986 struct win0_par *par = info->par;
989 scale = hdmi_get_scale();
992 par->xpos += screen->x_res * (100-scale) / 200;
993 par->ypos += screen->y_res * (100-scale) / 200;
994 par->xsize = par->xsize *scale /100;
995 par->ysize = par->ysize *scale /100;
998 static int win0_blank(int blank_mode, struct fb_info *info)
1000 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1002 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1008 case FB_BLANK_UNBLANK:
1009 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1010 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1012 case FB_BLANK_NORMAL:
1013 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1016 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1017 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1018 #ifdef CONFIG_DDR_RECONFIG
1028 static int win0_set_par(struct fb_info *info)
1030 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1031 struct rk29fb_screen *screen = inf->cur_screen;
1032 struct fb_var_screeninfo *var = &info->var;
1033 struct fb_fix_screeninfo *fix = &info->fix;
1034 struct win0_par *par = info->par;
1035 u32 xact, yact, xvir, yvir, xpos, ypos, ScaleYrgbX,ScaleYrgbY, ScaleCbrX, ScaleCbrY, y_addr,uv_addr;
1036 hdmi_set_fbscale(info);
1037 xact = var->xres; /* visible resolution */
1039 xvir = var->xres_virtual; /* virtual resolution */
1040 yvir = var->yres_virtual;
1041 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
1042 //u32 yact_st = var->yoffset; /* resolution */
1051 y_addr = 0; //user alloc buf addr y
1054 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1058 if(((var->rotate == 270)||(var->rotate == 90) || (var->rotate == 180)) && (inf->video_mode))
1060 #ifdef CONFIG_FB_ROTATE_VIDEO
1061 if(xact > screen->x_res)
1063 xact = screen->x_res; /* visible resolution */
1064 yact = screen->y_res;
1065 xvir = screen->x_res; /* virtual resolution */
1066 yvir = screen->y_res;
1068 xact = var->xres; /* visible resolution */
1070 xvir = var->xres_virtual; /* virtual resolution */
1071 yvir = var->yres_virtual;
1072 printk("xact=%d yact =%d \n",xact,yact);
1074 #else //CONFIG_FB_ROTATE_VIDEO
1075 printk("LCDC not support rotate!\n");
1080 // calculate the display phy address
1081 y_addr = fix->smem_start + par->y_offset;
1082 uv_addr = fix->mmio_start + par->c_offset;
1084 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1085 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1087 switch (par->format)
1090 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1091 ScaleCbrY = CalScaleW0(yact, par->ysize);
1095 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1096 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1099 ScaleCbrX= CalScaleW0(xact, par->xsize);
1100 ScaleCbrY = CalScaleW0(yact, par->ysize);
1106 xpos += (screen->left_margin + screen->hsync_len);
1107 ypos += (screen->upper_margin + screen->vsync_len);
1109 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1110 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1112 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1114 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1115 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1116 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1117 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1118 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1119 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1124 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,
1125 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));
1128 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,
1129 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));
1132 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,
1133 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) |
1134 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1137 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,
1138 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) );
1142 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1148 static int win0_pan( struct fb_info *info )
1150 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1151 // struct fb_var_screeninfo *var0 = &info->var;
1152 struct fb_fix_screeninfo *fix0 = &info->fix;
1153 struct win0_par *par = info->par;
1154 u32 y_addr=0, uv_addr=0;
1156 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1160 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1161 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1163 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1164 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1165 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1167 // enable win0 after the win0 addr is seted
1168 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1174 static int win1_blank(int blank_mode, struct fb_info *info)
1176 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1178 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1184 case FB_BLANK_UNBLANK:
1185 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1186 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1188 case FB_BLANK_NORMAL:
1189 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1192 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1193 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1203 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1204 static void win1_check_work_func(struct work_struct *work)
1206 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
1207 struct fb_info *fb0_inf = inf->fb0;
1208 struct fb_var_screeninfo *var = &fb0_inf->var;
1211 int blank_data,total_data;
1213 u16 xres_virtual = fb0_inf->var.xres_virtual; //virtual screen size
1214 u16 xpos_virtual = fb0_inf->var.xoffset; //visiable offset in virtual screen
1215 u16 ypos_virtual = fb0_inf->var.yoffset;
1217 int offset = 0;//(ypos_virtual*xres_virtual + xpos_virtual)*((inf->fb0_color_deepth || fb0_inf->var.bits_per_pixel==32)? 4:2)/4;
1218 switch(var->bits_per_pixel)
1222 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1223 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1224 offset -= var->yres * var->xres *2;
1228 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1229 if(ypos_virtual >= 2*var->yres)
1232 if(ypos_virtual == 3*var->yres)
1234 offset -= var->yres * var->xres *2;
1239 p = (int*)fb0_inf->screen_base + offset;
1240 blank_data = (inf->fb0_color_deepth==32) ? 0xff000000 : 0;
1241 total_data = fb0_inf->var.xres * fb0_inf->var.yres / (format+1);
1243 // 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);
1245 for(i=0; i < total_data; i++)
1247 if(*p++ != blank_data)
1249 //printk("win1 have no 0 data in %d, total %d\n",i,total_data);
1254 win1_blank(FB_BLANK_POWERDOWN, fb0_inf);
1255 // printk("%s close win1!\n",__func__);
1257 static DECLARE_DELAYED_WORK(rk29_win1_check_work, win1_check_work_func);
1259 static int win1_set_par(struct fb_info *info)
1261 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1262 struct fb_fix_screeninfo *fix = &info->fix;
1263 struct rk29fb_screen *screen = inf->cur_screen;
1264 struct win0_par *par = info->par;
1265 struct fb_var_screeninfo *var = &info->var;
1267 u16 xres_virtual,xpos,ypos;
1268 u8 trspval,trspmode;
1269 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1270 cancel_delayed_work_sync(&rk29_win1_check_work);
1272 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1273 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1275 hdmi_set_fbscale(info);
1276 }else if(((screen->x_res==1920) ))
1278 if(hdmi_get_fbscale() < 100)
1279 par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1281 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1283 xres_virtual = 0; //virtual screen size
1285 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1286 //u16 ypos_virtual = var->yoffset;
1288 xpos = par->xpos; //visiable offset in panel
1291 trspmode = TRSP_CLOSE;
1294 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1296 #ifdef CONFIG_FB_SCALING_OSD
1297 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1298 && (screen->x_res<=1280))
1300 addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1301 xres_virtual = screen->x_res* hdmi_get_fbscale()/100; //virtual screen size
1306 addr = fix->smem_start + par->y_offset;
1307 xres_virtual = var->xres_virtual; //virtual screen size
1309 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1311 xpos += (screen->left_margin + screen->hsync_len);
1312 ypos += (screen->upper_margin + screen->vsync_len);
1314 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1316 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1317 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1319 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1321 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1322 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1324 // enable win1 color key and set the color to black(rgb=0)
1325 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1327 if(1==par->format) //rgb565
1329 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1330 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1334 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1335 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1337 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1340 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1342 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1343 schedule_delayed_work(&rk29_win1_check_work, msecs_to_jiffies(5000));
1349 static int win1_pan( struct fb_info *info )
1351 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1352 struct fb_fix_screeninfo *fix1 = &info->fix;
1353 struct win0_par *par = info->par;
1356 #ifdef CONFIG_FB_SCALING_OSD
1357 struct rk29fb_screen *screen = inf->cur_screen;
1358 struct fb_var_screeninfo *var = &info->var;
1359 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1360 && (screen->x_res<=1280))
1362 addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1367 addr = fix1->smem_start + par->y_offset;
1370 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1372 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1373 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1379 static int fb0_blank(int blank_mode, struct fb_info *info)
1381 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1383 if(inf->video_mode == 1)
1385 win1_blank(blank_mode, info);
1389 win0_blank(blank_mode, info);
1394 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1396 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1397 struct rk29fb_screen *screen = inf->cur_screen;
1398 u16 xpos = (var->nonstd>>8) & 0xfff;
1399 u16 ypos = (var->nonstd>>20) & 0xfff;
1400 u16 xlcd = screen->x_res;
1401 u16 ylcd = screen->y_res;
1403 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1407 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1408 0==var->xres || 0==var->yres || var->xres<16 ||
1409 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1411 printk(">>>>>> fb0_check_var fail 1!!! \n");
1412 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1413 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1414 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1418 if( (var->xoffset+var->xres)>var->xres_virtual ||
1419 (var->yoffset+var->yres)>var->yres_virtual*2 )
1421 printk(">>>>>> fb0_check_var fail 2!!! \n");
1422 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1423 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1424 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1428 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1429 switch(var->bits_per_pixel)
1432 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1433 var->xres = (var->xres + 0x1) & (~0x1);
1434 var->xoffset = (var->xoffset) & (~0x1);
1437 var->bits_per_pixel = 32;
1445 static int fb0_set_par(struct fb_info *info)
1447 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1448 struct fb_var_screeninfo *var = &info->var;
1449 struct fb_fix_screeninfo *fix = &info->fix;
1450 struct rk29fb_screen *screen = inf->cur_screen;
1451 struct win0_par *par = info->par;
1453 u32 offset=0, smem_len=0;
1454 u16 xres_virtual = var->xres_virtual; //virtual screen size
1455 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1456 u16 ypos_virtual = var->yoffset;
1458 #ifdef CONFIG_FB_SCALING_OSD
1459 struct rk29_ipp_req ipp_req;
1461 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1464 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1469 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1470 #if !defined(CONFIG_FB_SCALING_OSD)
1471 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1474 switch(var->bits_per_pixel)
1478 if( ypos_virtual == 0)
1479 fb0_first_buff_bits = 16;
1481 fb0_second_buff_bits = 16;
1483 //fix->line_length = 2 * xres_virtual;
1484 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1486 #ifdef CONFIG_FB_SCALING_OSD
1487 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1488 ipp_req.src0.fmt = IPP_RGB_565;
1489 ipp_req.dst0.fmt = IPP_RGB_565;
1491 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1492 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1493 offset -= var->yres * var->xres *2;
1498 if( ypos_virtual == 0)
1499 fb0_first_buff_bits = 32;
1501 fb0_second_buff_bits = 32;
1502 fix->line_length = 4 * xres_virtual;
1503 #ifdef CONFIG_FB_SCALING_OSD
1504 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1506 ipp_req.src0.fmt = IPP_XRGB_8888;
1507 ipp_req.dst0.fmt = IPP_XRGB_8888;
1509 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1511 if(ypos_virtual >= 2*var->yres)
1514 #ifdef CONFIG_FB_SCALING_OSD
1515 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1516 ipp_req.src0.fmt = IPP_RGB_565;
1517 ipp_req.dst0.fmt = IPP_RGB_565;
1519 if(ypos_virtual == 3*var->yres)
1521 offset -= var->yres * var->xres *2;
1527 smem_len = fix->line_length * var->yres_virtual;
1528 //map_size = PAGE_ALIGN(smem_len);
1530 if (smem_len > fix->smem_len) // buffer need realloc
1532 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1533 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1534 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1538 par->addr_seted = 1;
1539 #if ANDROID_USE_THREE_BUFS
1540 if(0==new_frame_seted) {
1542 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1544 new_frame_seted = 0;
1547 if(inf->video_mode == 1)
1549 #ifdef CONFIG_FB_SCALING_OSD
1550 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1551 && (screen->x_res<=1280))
1555 par->xsize = screen->x_res;
1556 par->ysize = screen->y_res;
1557 par->y_offset = dstoffset;
1559 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1560 ipp_req.src0.w = var->xres;
1561 ipp_req.src0.h = var->yres;
1563 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1564 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1565 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1567 ipp_req.src_vir_w = ipp_req.src0.w;
1568 ipp_req.dst_vir_w = ipp_req.dst0.w;
1569 ipp_req.timeout = 100;
1570 ipp_req.flag = IPP_ROT_0;
1571 //ipp_do_blit(&ipp_req);
1572 ipp_blit_sync(&ipp_req);
1576 par->y_offset = offset;
1577 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1578 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1579 par->xsize = var->xres; //visiable size in panel
1580 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1586 par->y_offset = offset;
1589 par->xsize = screen->x_res;
1590 par->ysize = screen->y_res;
1597 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1600 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1601 struct fb_var_screeninfo *var1 = &info->var;
1602 struct rk29fb_screen *screen = inf->cur_screen;
1603 struct win0_par *par = info->par;
1606 u16 ypos_virtual = var->yoffset;
1607 u16 xpos_virtual = var->xoffset;
1608 #ifdef CONFIG_FB_SCALING_OSD
1609 struct fb_fix_screeninfo *fix = &info->fix;
1610 struct rk29_ipp_req ipp_req;
1612 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1614 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1618 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1619 #if !defined(CONFIG_FB_SCALING_OSD)
1620 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1623 switch(var1->bits_per_pixel)
1626 var->xoffset = (var->xoffset) & (~0x1);
1627 #ifdef CONFIG_FB_SCALING_OSD
1628 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1629 ipp_req.src0.fmt = IPP_RGB_565;
1630 ipp_req.dst0.fmt = IPP_RGB_565;
1632 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1633 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1634 offset -= var->yres * var->xres *2;
1637 #ifdef CONFIG_FB_SCALING_OSD
1638 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1639 ipp_req.src0.fmt = IPP_XRGB_8888;
1640 ipp_req.dst0.fmt = IPP_XRGB_8888;
1642 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1643 if(ypos_virtual >= 2*var->yres)
1646 #ifdef CONFIG_FB_SCALING_OSD
1647 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1648 ipp_req.src0.fmt = IPP_RGB_565;
1649 ipp_req.dst0.fmt = IPP_RGB_565;
1651 if(ypos_virtual == 3*var->yres)
1653 offset -= var->yres * var->xres *2;
1661 if(inf->video_mode == 1)
1663 #ifdef CONFIG_FB_SCALING_OSD
1664 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1665 && (screen->x_res<=1280))
1667 par->y_offset = dstoffset;
1669 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1670 ipp_req.src0.w = var->xres;
1671 ipp_req.src0.h = var->yres;
1673 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1674 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1675 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1677 ipp_req.src_vir_w = ipp_req.src0.w;
1678 ipp_req.dst_vir_w = ipp_req.dst0.w;
1679 ipp_req.timeout = 100;
1680 ipp_req.flag = IPP_ROT_0;
1681 //ipp_do_blit(&ipp_req);
1682 ipp_blit_sync(&ipp_req);
1687 par->y_offset = offset;
1692 par->y_offset = offset;
1695 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1696 #if !ANDROID_USE_THREE_BUFS
1697 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1698 if(SCREEN_MCU == inf->cur_screen->type) {
1699 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1703 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1709 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1711 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1712 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1718 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1721 inf->mcu_usetimer = 0;
1724 case FBIOPUT_16OR32:
1726 inf->fb0_color_deepth = arg;
1729 case FBIOGET_16OR32:
1730 return inf->fb0_color_deepth;
1731 case FBIOGET_IDLEFBUff_16OR32:
1732 if(info->var.yoffset == 0)
1734 return fb0_second_buff_bits;
1738 return fb0_first_buff_bits;
1740 case FBIOSET_COMPOSE_LAYER_COUNTS:
1741 fb_compose_layer_count = arg;
1744 case FBIOGET_COMPOSE_LAYER_COUNTS:
1746 return fb_compose_layer_count;
1748 case FBIOPUT_FBPHYADD:
1749 return info->fix.smem_start;
1750 case FBIOGET_OVERLAY_STATE:
1751 return inf->video_mode;
1752 case FBIOGET_SCREEN_STATE:
1753 return inf->cur_screen->type;
1755 case FBIOPUT_SET_CURSOR_EN:
1758 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1760 rk29_set_cursor_en(inf, en);
1763 case FBIOPUT_SET_CURSOR_POS:
1765 struct fbcurpos pos;
1766 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1768 rk29_set_cursor_pos(inf, pos.x , pos.y);
1771 case FBIOPUT_SET_CURSOR_IMG:
1773 char cursor_buf[CURSOR_BUF_SIZE];
1774 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1776 rk29_set_cursor_img(inf, cursor_buf);
1779 case FBIOPUT_SET_CURSOR_CMAP:
1781 struct fb_image img;
1782 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1784 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1787 case FBIOPUT_GET_CURSOR_RESOLUTION:
1790 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1791 if(inf->fb1->var.rotate == 270) {
1792 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1793 panel_size[1] = inf->cur_screen->x_res;
1795 panel_size[0] = inf->cur_screen->x_res;
1796 panel_size[1] = inf->cur_screen->y_res;
1798 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1801 case FBIOPUT_GET_CURSOR_EN:
1803 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1804 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1813 static int fb1_blank(int blank_mode, struct fb_info *info)
1815 win0_blank(blank_mode, info);
1819 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1821 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1822 struct rk29fb_screen *screen = inf->cur_screen;
1824 u32 ScaleYRGBY=0x1000;
1825 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1826 u16 ypos = (var->nonstd>>20) & 0xfff;
1827 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1828 u16 ysize = (var->grayscale>>20) & 0xfff;
1829 u16 xlcd = screen->x_res; //size of panel
1830 u16 ylcd = screen->y_res;
1833 struct hdmi *hdmi = get_hdmi_struct(0);
1836 if((var->rotate == 270)||(var->rotate == 90)) {
1837 #ifdef CONFIG_FB_ROTATE_VIDEO
1838 xlcd = screen->y_res;
1839 ylcd = screen->x_res;
1840 #else //CONFIG_FB_ROTATE_VIDEO
1841 printk("LCDC not support rotate!\n");
1846 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1847 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1848 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1849 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1851 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1855 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1856 0==var->xres || 0==var->yres || var->xres<16 ||
1857 0==xsize || 0==ysize || xsize<16 ||
1858 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1860 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1861 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1862 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1863 var->bits_per_pixel, var->bits_per_pixel);
1867 if( (var->xoffset+var->xres)>var->xres_virtual ||
1868 (var->yoffset+var->yres)>var->yres_virtual ||
1869 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1871 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1872 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1873 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1874 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1878 switch(var->nonstd&0x0f)
1881 switch(var->bits_per_pixel)
1884 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1885 var->xres = (var->xres + 0x1) & (~0x1);
1886 var->xoffset = (var->xoffset) & (~0x1);
1889 var->bits_per_pixel = 32;
1892 var->nonstd &= ~0xc0; //not support I2P in this format
1895 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1896 var->xres = (var->xres + 0x3) & (~0x3);
1897 var->xoffset = (var->xoffset) & (~0x3);
1900 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1901 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1902 var->xres = (var->xres + 0x3) & (~0x3);
1903 var->yres = (var->yres + 0x1) & (~0x1);
1904 var->xoffset = (var->xoffset) & (~0x3);
1905 var->yoffset = (var->yoffset) & (~0x1);
1908 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1909 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1910 var->xres = (var->xres + 0x3) & (~0x3);
1911 var->yres = (var->yres + 0x1) & (~0x1);
1912 var->xoffset = (var->xoffset) & (~0x3);
1913 var->yoffset = (var->yoffset) & (~0x1);
1914 var->nonstd &= ~0xc0; //not support I2P in this format
1918 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1919 var->xres = (var->xres + 0x3) & (~0x3);
1920 var->xoffset = (var->xoffset) & (~0x3);
1921 var->nonstd &= ~0xc0; //not support I2P in this format
1924 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1928 if((var->rotate == 270)||(var->rotate == 90))
1937 ScaleYRGBY = CalScaleW0(yres, ysize);
1939 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1941 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1944 if(inf->video_mode == 1) {
1945 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1947 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1948 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1949 init_completion(&hdmi->complete);
1951 wait_for_completion_interruptible_timeout(&hdmi->complete,
1952 msecs_to_jiffies(10000));
1959 static int fb1_set_par(struct fb_info *info)
1961 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1962 struct rk29fb_screen *screen = inf->cur_screen;
1963 struct fb_var_screeninfo *var = &info->var;
1964 struct fb_fix_screeninfo *fix = &info->fix;
1965 struct win0_par *par = info->par;
1968 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1970 //u32 xact = var->xres; /* visible resolution */
1971 //u32 yact = var->yres;
1972 u32 xvir = var->xres_virtual; /* virtual resolution */
1973 u32 yvir = var->yres_virtual;
1974 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1975 u32 yact_st = var->yoffset; /* resolution */
1977 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1978 u16 ypos = (var->nonstd>>20) & 0xfff;
1979 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1980 u16 ysize = (var->grayscale>>20) & 0xfff;
1982 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1983 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1985 u8 data_format = var->nonstd&0x0f;
1986 // u32 win0_en = var->reserved[2];
1987 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1988 // u32 uv_addr = var->reserved[4];
1990 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1993 if((var->rotate == 270)||(var->rotate == 90))
1995 #ifdef CONFIG_FB_ROTATE_VIDEO
1996 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1997 ypos = (var->nonstd>>8) & 0xfff;
1998 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1999 ysize = (var->grayscale>>8) & 0xfff;
2000 #else //CONFIG_FB_ROTATE_VIDEO
2001 printk("LCDC not support rotate!\n");
2005 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2006 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2007 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2008 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2010 /* calculate y_offset,c_offset,line_length,cblen and crlen */
2011 switch (data_format)
2014 switch(var->bits_per_pixel)
2018 fix->line_length = 2 * xvir;
2019 par->y_offset = (yact_st*xvir + xact_st)*2;
2023 fix->line_length = 4 * xvir;
2024 par->y_offset = (yact_st*xvir + xact_st)*4;
2032 fix->line_length = xvir;
2033 cblen = crlen = (xvir*yvir)/2;
2034 par->y_offset = yact_st*xvir + xact_st;
2035 par->c_offset = yact_st*xvir + xact_st;
2039 fix->line_length = xvir;
2040 cblen = crlen = (xvir*yvir)/4;
2042 par->y_offset = yact_st*xvir + xact_st;
2043 par->c_offset = (yact_st/2)*xvir + xact_st;
2048 fix->line_length = xvir;
2049 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
2050 par->c_offset = (yact_st/2)*xvir + xact_st;
2051 cblen = crlen = (xvir*yvir)/4;
2056 fix->line_length = xvir;
2057 par->y_offset = yact_st*xvir + xact_st;
2058 par->c_offset = yact_st*2*xvir + xact_st*2;
2059 cblen = crlen = (xvir*yvir);
2065 smem_len = fix->line_length * yvir + cblen + crlen;
2066 map_size = PAGE_ALIGN(smem_len);
2068 // fix->smem_start = y_addr;
2069 fix->smem_len = smem_len;
2070 // fix->mmio_start = uv_addr;
2072 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
2073 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);
2075 par->format = format;
2082 if ( wq_condition2 == 0 ) {
2083 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
2087 #ifdef CONFIG_FB_ROTATE_VIDEO
2088 //need refresh ,zyc add
2089 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
2092 struct rk29_ipp_req ipp_req;
2093 static u32 dstoffset = 0;
2094 static int fb_index = 0;
2095 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2096 yuv_phy[0] = last_yuv_phy[0];
2097 yuv_phy[1] = last_yuv_phy[1];
2098 yuv_phy[0] += par->y_offset;
2099 yuv_phy[1] += par->c_offset;
2101 if((var->rotate == 90) ||(var->rotate == 270))
2103 if(var->rotate%360 != 0)
2106 dstoffset = (dstoffset+1)%2;
2107 ipp_req.src0.fmt = 3;
2108 ipp_req.src0.YrgbMst = yuv_phy[0];
2109 ipp_req.src0.CbrMst = yuv_phy[1];
2110 ipp_req.src0.w = var->xres;
2111 ipp_req.src0.h = var->yres;
2113 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2114 ipp_req.dst_vir_w=screen->x_res;
2116 ipp_req.dst0.fmt = 3;
2117 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2118 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2119 if(var->xres > screen->x_res)
2121 ipp_req.dst0.w = screen->x_res;
2122 ipp_req.dst0.h = screen->y_res;
2124 ipp_req.dst0.w = var->xres;
2125 ipp_req.dst0.h = var->yres;
2127 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2129 ipp_req.timeout = 100;
2130 if(var->rotate == 90)
2131 ipp_req.flag = IPP_ROT_90;
2132 else if (var->rotate == 180)
2133 ipp_req.flag = IPP_ROT_180;
2134 else if(var->rotate == 270)
2135 ipp_req.flag = IPP_ROT_270;
2136 //ipp_do_blit(&ipp_req);
2137 ipp_blit_sync(&ipp_req);
2138 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2139 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2140 yuv_phy[1] = ipp_req.dst0.CbrMst;
2141 fix->smem_start = yuv_phy[0];
2142 fix->mmio_start = yuv_phy[1];
2147 fix->smem_start = yuv_phy[0];
2148 fix->mmio_start = yuv_phy[1];
2151 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2152 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2153 // enable win0 after the win0 par is seted
2154 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2155 par->addr_seted = 1;
2156 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2157 if(par->addr_seted ) {
2158 unsigned long flags;
2160 local_irq_save(flags);
2161 par->mirror.y_offset = yuv_phy[0];
2162 par->mirror.c_offset = yuv_phy[1];
2163 local_irq_restore(flags);
2166 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2171 has_set_rotate = false;
2176 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2178 struct win0_par *par = info->par;
2179 // enable win0 after the win0 addr is seted
2186 int fb1_open(struct fb_info *info, int user)
2188 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2189 struct win0_par *par = info->par;
2191 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2194 par->addr_seted = 0;
2195 inf->video_mode = 1;
2197 #ifdef CONFIG_FB_ROTATE_VIDEO
2198 //reinitialize the var when open,zyc
2199 last_yuv_phy[0] = 0;
2200 last_yuv_phy[1] = 0;
2204 printk(">>>>>> fb1 has opened! \n");
2208 win0_blank(FB_BLANK_NORMAL, info);
2209 fb0_set_par(inf->fb0);
2211 rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2216 int fb1_release(struct fb_info *info, int user)
2218 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2219 struct win0_par *par = info->par;
2220 struct fb_var_screeninfo *var0 = &info->var;
2222 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2223 if(inf->setFlag == 0)
2225 wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2229 inf->video_mode = 0;
2231 par->addr_seted = 0;
2232 win1_blank(FB_BLANK_NORMAL, info);
2233 if(inf->cur_screen->type != SCREEN_HDMI)
2234 fb0_set_par(inf->fb0);
2237 info->screen_base = 0;
2238 info->fix.smem_start = 0;
2239 info->fix.smem_len = 0;
2240 // clean the var param
2241 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2242 rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2243 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2244 cancel_delayed_work_sync(&rk29_win1_check_work);
2251 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2253 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2254 struct win0_par *par = info->par;
2255 struct fb_fix_screeninfo *fix0 = &info->fix;
2256 struct fb_var_screeninfo *var = &info->var;
2257 void __user *argp = (void __user *)arg;
2259 #ifdef CONFIG_FB_ROTATE_VIDEO
2260 struct rk29fb_screen *screen = inf->cur_screen;
2261 struct rk29_ipp_req ipp_req;
2262 static u32 dstoffset = 0;
2263 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2266 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2267 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2273 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2276 if((var->rotate == 270)||(var->rotate == 90)) {
2277 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2278 panel_size[1] = inf->panel1_info.x_res;
2280 panel_size[0] = inf->panel1_info.x_res;
2281 panel_size[1] = inf->panel1_info.y_res;
2284 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2288 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2291 if (copy_from_user(yuv_phy, argp, 8))
2293 #ifdef CONFIG_FB_ROTATE_VIDEO
2295 if(has_set_rotate == true)
2297 last_yuv_phy[0] = yuv_phy[0];
2298 last_yuv_phy[1] = yuv_phy[1];
2301 fix0->smem_start = yuv_phy[0];
2302 fix0->mmio_start = yuv_phy[1];
2303 yuv_phy[0] += par->y_offset;
2304 yuv_phy[1] += par->c_offset;
2307 if((var->rotate == 90) ||(var->rotate == 270))
2309 if(var->rotate%360 != 0)
2312 #ifdef CONFIG_FB_ROTATE_VIDEO
2313 dstoffset = (dstoffset+1)%2;
2314 ipp_req.src0.fmt = 3;
2315 ipp_req.src0.YrgbMst = yuv_phy[0];
2316 ipp_req.src0.CbrMst = yuv_phy[1];
2317 ipp_req.src0.w = var->xres ;
2318 ipp_req.src0.h = var->yres ;
2319 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2320 ipp_req.dst_vir_w=screen->x_res;
2322 ipp_req.dst0.fmt = 3;
2323 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2324 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2325 if(var->xres > screen->x_res)
2327 ipp_req.dst0.w = screen->x_res;
2328 ipp_req.dst0.h = screen->y_res;
2330 ipp_req.dst0.w = var->xres;
2331 ipp_req.dst0.h = var->yres;
2334 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2335 ipp_req.timeout = 100;
2336 if(var->rotate == 90)
2337 ipp_req.flag = IPP_ROT_90;
2338 else if(var->rotate == 180)
2339 ipp_req.flag = IPP_ROT_180;
2340 else if(var->rotate == 270)
2341 ipp_req.flag = IPP_ROT_270;
2342 //ipp_do_blit(&ipp_req);
2343 ipp_blit_sync(&ipp_req);
2345 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2346 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2347 yuv_phy[1] = ipp_req.dst0.CbrMst;
2348 fix0->smem_start = yuv_phy[0];
2349 fix0->mmio_start = yuv_phy[1];
2350 #else //CONFIG_FB_ROTATE_VIDEO
2351 printk("LCDC not support rotate!\n");
2355 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2356 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2357 // enable win0 after the win0 par is seted
2358 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2359 par->addr_seted = 1;
2360 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2361 if(par->par_seted) {
2362 unsigned long flags;
2364 local_irq_save(flags);
2365 par->mirror.y_offset = yuv_phy[0];
2366 par->mirror.c_offset = yuv_phy[1];
2367 local_irq_restore(flags);
2370 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2375 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2376 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2377 #ifdef CONFIG_FB_ROTATE_VIDEO
2379 has_set_rotate = true;
2380 if(arg == 0 || arg==180)
2382 else if (arg == 90 || arg==270)
2384 #else //CONFIG_FB_ROTATE_VIDEO
2385 printk("LCDC not support rotate!\n");
2388 case FB1_IOCTL_SET_WIN0_TOP:
2389 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2390 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2391 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2399 static struct fb_ops fb1_ops = {
2400 .owner = THIS_MODULE,
2401 .fb_open = fb1_open,
2402 .fb_release = fb1_release,
2403 .fb_check_var = fb1_check_var,
2404 .fb_set_par = fb1_set_par,
2405 .fb_blank = fb1_blank,
2406 .fb_pan_display = fb1_pan_display,
2407 .fb_ioctl = fb1_ioctl,
2408 .fb_setcolreg = fb_setcolreg,
2409 .fb_fillrect = cfb_fillrect,
2410 .fb_copyarea = cfb_copyarea,
2411 .fb_imageblit = cfb_imageblit,
2414 static struct fb_ops fb0_ops = {
2415 .owner = THIS_MODULE,
2416 .fb_check_var = fb0_check_var,
2417 .fb_set_par = fb0_set_par,
2418 .fb_blank = fb0_blank,
2419 .fb_pan_display = fb0_pan_display,
2420 .fb_ioctl = fb0_ioctl,
2421 .fb_setcolreg = fb_setcolreg,
2422 .fb_fillrect = cfb_fillrect,
2423 .fb_copyarea = cfb_copyarea,
2424 .fb_imageblit = cfb_imageblit,
2425 //.fb_cursor = rk29_set_cursor,
2428 int fb_get_video_mode(void)
2430 struct rk29fb_inf *inf;
2433 inf = platform_get_drvdata(g_pdev);
2434 return inf->video_mode;
2437 enable: 1, switch to tv or hdmi; 0, switch to lcd
2439 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2441 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2442 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2443 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2445 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2447 if(enable)inf->cur_screen = &inf->panel2_info;
2448 else inf->cur_screen = &inf->panel1_info;
2450 /* Black out, because some display device need clock to standby */
2451 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2452 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2453 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2454 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2455 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2456 wake_lock(&idlelock);
2458 wake_unlock(&idlelock);
2460 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2461 // operate the display_on pin to power down the lcd
2463 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2464 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2466 load_screen(inf->fb0, 0);
2469 fb1_set_par(inf->fb1);
2470 fb0_set_par(inf->fb0);
2471 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2472 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2473 rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2477 static ssize_t dsp_win0_info_read(struct device *device,
2478 struct device_attribute *attr, char *buf)
2481 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2482 struct rk29fb_screen *screen = inf->cur_screen;
2484 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2486 fbprintk("%s\n",__FUNCTION__);
2487 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2488 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2490 xpos -= (screen->left_margin + screen->hsync_len);
2491 ypos -= (screen->upper_margin + screen->vsync_len);
2493 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2494 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2495 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2496 rk29_set_cursor_test(inf->fb0);
2498 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2501 static ssize_t dsp_win0_info_write(struct device *device,
2502 struct device_attribute *attr, const char *buf, size_t count)
2504 printk("%s\n",__FUNCTION__);
2505 printk("%s %x \n",__FUNCTION__,*buf);
2509 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2511 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2513 struct platform_device *pdev = (struct platform_device*)dev_id;
2514 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2515 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2519 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2521 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2523 if(SCREEN_MCU == inf->cur_screen->type)
2525 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2531 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2533 inf->mcu_fmksync = 1;
2534 if(inf->cur_screen->refresh)
2535 inf->cur_screen->refresh(REFRESH_END);
2536 inf->mcu_fmksync = 0;
2545 if(inf->mcu_needflush) {
2546 if(inf->cur_screen->refresh)
2547 inf->cur_screen->refresh(REFRESH_PRE);
2548 inf->mcu_needflush = 0;
2549 inf->mcu_isrcnt = 0;
2550 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2552 if(inf->cur_screen->refresh)
2553 inf->cur_screen->refresh(REFRESH_END);
2557 #if ANDROID_USE_THREE_BUFS
2558 new_frame_seted = 1;
2561 if(waitqueue_active(&par->wait)) {
2562 if (par->mirror.c_offset == 0)
2563 printk("error: no new buffer to display\n");
2565 par->done.y_offset = par->displ.y_offset;
2566 par->done.c_offset = par->displ.c_offset;
2567 par->displ.y_offset = par->mirror.y_offset;
2568 par->displ.c_offset = par->mirror.c_offset;
2569 par->mirror.y_offset = 0;
2570 par->mirror.c_offset = 0;
2572 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2573 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2574 wake_up_interruptible(&par->wait);
2579 wake_up_interruptible(&wq);
2581 rk29fb_irq_notify_ddr();
2585 #ifdef CONFIG_HAS_EARLYSUSPEND
2587 struct suspend_info {
2588 struct early_suspend early_suspend;
2589 struct rk29fb_inf *inf;
2592 static void rk29fb_early_suspend(struct early_suspend *h)
2594 struct suspend_info *info = container_of(h, struct suspend_info,
2597 struct rk29fb_inf *inf = info->inf;
2598 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2600 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2603 printk("inf==0, rk29fb_suspend fail! \n");
2607 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2608 cancel_delayed_work_sync(&rk29_win1_check_work);
2611 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2612 mach_info->io_disable(); //close lcd out
2614 if(inf->cur_screen->standby)
2616 fbprintk(">>>>>> power down the screen! \n");
2617 inf->cur_screen->standby(1);
2620 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2621 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2623 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2624 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2625 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2627 if(!inf->in_suspend)
2629 fbprintk(">>>>>> diable the lcdc clk! \n");
2630 wake_lock(&idlelock);
2632 wake_unlock(&idlelock);
2633 clk_disable(inf->aclk_ddr_lcdc);
2634 clk_disable(inf->aclk_disp_matrix);
2635 clk_disable(inf->hclk_cpu_display);
2636 clk_disable(inf->clk);
2638 clk_disable(inf->dclk);
2641 clk_disable(inf->aclk);
2643 //clk_disable(inf->pd_display);
2645 inf->in_suspend = 1;
2649 static void rk29fb_early_resume(struct early_suspend *h)
2651 struct suspend_info *info = container_of(h, struct suspend_info,
2654 struct rk29fb_inf *inf = info->inf;
2655 struct rk29fb_screen *screen = inf->cur_screen;
2656 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2658 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2660 printk("inf==0, rk29fb_resume fail! \n");
2666 inf->in_suspend = 0;
2667 fbprintk(">>>>>> enable the lcdc clk! \n");
2668 // clk_enable(inf->pd_display);
2669 clk_enable(inf->aclk_disp_matrix);
2670 clk_enable(inf->hclk_cpu_display);
2671 clk_enable(inf->clk);
2672 clk_enable(inf->aclk_ddr_lcdc);
2675 clk_enable(inf->dclk);
2678 clk_enable(inf->aclk);
2680 usleep_range(100*1000, 100*1000);
2682 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2683 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2684 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2686 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2687 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2689 if(inf->cur_screen->standby)
2691 fbprintk(">>>>>> power on the screen! \n");
2692 inf->cur_screen->standby(0);
2694 usleep_range(10*1000, 10*1000);
2695 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2696 usleep_range(40*1000, 40*1000);
2698 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2699 mach_info->io_enable(); //close lcd out
2703 static struct suspend_info suspend_info = {
2704 .early_suspend.suspend = rk29fb_early_suspend,
2705 .early_suspend.resume = rk29fb_early_resume,
2706 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2709 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2710 static int __init rk29fb_probe (struct platform_device *pdev)
2712 struct rk29fb_inf *inf = NULL;
2713 struct resource *res = NULL;
2714 struct resource *mem = NULL;
2715 struct rk29fb_info *mach_info = NULL;
2716 struct rk29fb_screen *screen = NULL;
2717 struct win0_par* par = NULL;
2721 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2723 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2724 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2725 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2728 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2730 goto release_drvdata;
2732 memset(inf, 0, sizeof(struct rk29fb_inf));
2733 platform_set_drvdata(pdev, inf);
2735 mach_info = pdev->dev.platform_data;
2736 /* Fill screen info and set current screen */
2737 fbprintk(">> Fill screen info and set current screen \n");
2738 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2739 hdmi_get_default_resolution(&inf->panel1_info);
2741 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2743 inf->cur_screen = &inf->panel1_info;
2744 screen = inf->cur_screen;
2745 if(SCREEN_NULL==screen->type)
2747 dev_err(&pdev->dev, ">> Please select a display device! \n");
2749 goto release_drvdata;
2752 /* get virtual basic address of lcdc register */
2753 fbprintk(">> get virtual basic address of lcdc register \n");
2754 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2757 dev_err(&pdev->dev, "failed to get memory registers\n");
2759 goto release_drvdata;
2761 inf->reg_phy_base = res->start;
2762 inf->len = (res->end - res->start) + 1;
2763 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2766 dev_err(&pdev->dev, "failed to get memory region\n");
2768 goto release_drvdata;
2770 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2771 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2772 if (inf->reg_vir_base == NULL)
2774 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2776 goto release_drvdata;
2778 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2780 /* Prepare win1 info */
2781 fbprintk(">> Prepare win1 info \n");
2782 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2785 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2788 goto release_win1fb;
2791 par = (struct win0_par*)inf->fb0->par;
2792 strcpy(inf->fb0->fix.id, "fb0");
2793 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2794 inf->fb0->fix.type_aux = 0;
2795 inf->fb0->fix.xpanstep = 1;
2796 inf->fb0->fix.ypanstep = 1;
2797 inf->fb0->fix.ywrapstep = 0;
2798 inf->fb0->fix.accel = FB_ACCEL_NONE;
2799 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2800 inf->fb0->fix.smem_len = 0;
2801 inf->fb0->fix.line_length = 0;
2802 inf->fb0->fix.smem_start = 0;
2804 inf->fb0->var.xres = screen->x_res;
2805 inf->fb0->var.yres = screen->y_res;
2806 inf->fb0->var.bits_per_pixel = 16;
2807 inf->fb0_color_deepth = 0;
2808 inf->fb0->var.xres_virtual = screen->x_res;
2809 inf->fb0->var.yres_virtual = screen->y_res;
2810 inf->fb0->var.width = screen->width;
2811 inf->fb0->var.height = screen->height;
2812 //inf->fb0->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
2813 inf->fb0->var.left_margin = screen->left_margin;
2814 inf->fb0->var.right_margin = screen->right_margin;
2815 inf->fb0->var.upper_margin = screen->upper_margin;
2816 inf->fb0->var.lower_margin = screen->lower_margin;
2817 inf->fb0->var.vsync_len = screen->vsync_len;
2818 inf->fb0->var.hsync_len = screen->hsync_len;
2819 inf->fb0->var.red = def_rgb_16.red;
2820 inf->fb0->var.green = def_rgb_16.green;
2821 inf->fb0->var.blue = def_rgb_16.blue;
2822 inf->fb0->var.transp = def_rgb_16.transp;
2824 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2825 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2826 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2827 inf->fb0->var.accel_flags = 0;
2828 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2830 inf->fb0->fbops = &fb0_ops;
2831 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2832 inf->fb0->pseudo_palette = par->pseudo_pal;
2833 inf->fb0->screen_base = 0;
2835 memset(par, 0, sizeof(struct win0_par));
2837 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2841 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2843 /* alloc win1 buf */
2844 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2847 dev_err(&pdev->dev, "failed to get win1 memory \n");
2849 goto release_win1fb;
2851 inf->fb0->fix.smem_start = res->start;
2852 inf->fb0->fix.smem_len = res->end - res->start + 1;
2853 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2854 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2856 #ifdef CONFIG_FB_WORK_IPP
2857 /* alloc win1 ipp buf */
2858 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2861 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2863 goto release_win1fb;
2865 inf->fb0->fix.mmio_start = res->start;
2866 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2869 /* Prepare win0 info */
2870 fbprintk(">> Prepare win0 info \n");
2871 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2874 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2877 goto release_win0fb;
2880 par = (struct win0_par*)inf->fb1->par;
2882 strcpy(inf->fb1->fix.id, "fb1");
2883 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2884 inf->fb1->fix.type_aux = 0;
2885 inf->fb1->fix.xpanstep = 1;
2886 inf->fb1->fix.ypanstep = 1;
2887 inf->fb1->fix.ywrapstep = 0;
2888 inf->fb1->fix.accel = FB_ACCEL_NONE;
2889 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2890 inf->fb1->fix.smem_len = 0;
2891 inf->fb1->fix.line_length = 0;
2892 inf->fb1->fix.smem_start = 0;
2894 inf->fb1->var.xres = screen->x_res;
2895 inf->fb1->var.yres = screen->y_res;
2896 inf->fb1->var.bits_per_pixel = 16;
2897 inf->fb1->var.xres_virtual = screen->x_res;
2898 inf->fb1->var.yres_virtual = screen->y_res;
2899 inf->fb1->var.width = screen->width;
2900 inf->fb1->var.height = screen->height;
2901 //inf->fb1->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
2902 inf->fb1->var.left_margin = screen->left_margin;
2903 inf->fb1->var.right_margin = screen->right_margin;
2904 inf->fb1->var.upper_margin = screen->upper_margin;
2905 inf->fb1->var.lower_margin = screen->lower_margin;
2906 inf->fb1->var.vsync_len = screen->vsync_len;
2907 inf->fb1->var.hsync_len = screen->hsync_len;
2908 inf->fb1->var.red = def_rgb_16.red;
2909 inf->fb1->var.green = def_rgb_16.green;
2910 inf->fb1->var.blue = def_rgb_16.blue;
2911 inf->fb1->var.transp = def_rgb_16.transp;
2913 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2914 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2915 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2916 inf->fb1->var.accel_flags = 0;
2917 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2919 inf->fb1->fbops = &fb1_ops;
2920 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2921 inf->fb1->pseudo_palette = par->pseudo_pal;
2922 inf->fb1->screen_base = 0;
2924 memset(par, 0, sizeof(struct win0_par));
2926 init_waitqueue_head(&par->wait);
2928 /* Init all lcdc and lcd before register_framebuffer. */
2929 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2930 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2931 init_lcdc(inf->fb0);
2933 #if 0 //def CONFIG_CPU_FREQ
2934 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2935 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2937 fbprintk("got clock\n");
2941 struct rk29_fb_setting_info fb_setting;
2942 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2944 fb_setting.data_num = 24;
2946 else if(OUT_P666 == inf->cur_screen->face )
2948 fb_setting.data_num = 18;
2952 fb_setting.data_num = 16;
2954 fb_setting.den_en = 1;
2955 fb_setting.vsync_en = 1;
2956 fb_setting.disp_on_en = 1;
2957 fb_setting.standby_en = 1;
2958 if( inf->cur_screen->mcu_usefmk )
2959 fb_setting.mcu_fmk_en =1;
2960 mach_info->io_init(&fb_setting);
2963 //set_lcd_pin(pdev, 1);
2966 inf->mcu_usetimer = 1;
2967 inf->mcu_fmksync = 0;
2968 load_screen(inf->fb0, 1);
2970 /* Register framebuffer(fb0 & fb1) */
2971 fbprintk(">> Register framebuffer(fb0) \n");
2972 ret = register_framebuffer(inf->fb0);
2975 printk(">> fb0 register_framebuffer fail!\n");
2977 goto release_win0fb;
2979 fbprintk(">> Register framebuffer(fb1) \n");
2981 ret = register_framebuffer(inf->fb1);
2984 printk(">> fb1 register_framebuffer fail!\n");
2986 goto unregister_win1fb;
2989 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2992 printk(">> fb1 dsp win0 info device_create_file err\n");
2995 #ifdef CONFIG_HAS_EARLYSUSPEND
2996 suspend_info.inf = inf;
2997 register_early_suspend(&suspend_info.early_suspend);
3000 /* get and request irq */
3001 fbprintk(">> get and request irq \n");
3002 irq = platform_get_irq(pdev, 0);
3004 dev_err(&pdev->dev, "no irq for device\n");
3006 goto unregister_win1fb;
3008 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
3010 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
3015 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
3017 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
3020 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
3026 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
3027 fb0_set_par(inf->fb0);
3028 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
3029 /* Start display and show logo on boot */
3030 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
3031 fb_show_logo(inf->fb0, FB_ROTATE_UR);
3032 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
3036 printk(" %s ok\n", __FUNCTION__);
3041 free_irq(irq, pdev);
3043 unregister_framebuffer(inf->fb0);
3046 framebuffer_release(inf->fb1);
3050 fb_dealloc_cmap(&inf->fb0->cmap);
3053 framebuffer_release(inf->fb0);
3056 if(inf && inf->reg_vir_base)
3057 iounmap(inf->reg_vir_base);
3059 release_mem_region(inf->reg_phy_base, inf->len);
3062 platform_set_drvdata(pdev, NULL);
3066 static int rk29fb_remove(struct platform_device *pdev)
3068 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3069 struct fb_info *info = NULL;
3071 struct rk29fb_info *mach_info = NULL;
3074 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3077 printk("inf==0, rk29_fb_remove fail! \n");
3080 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3082 irq = platform_get_irq(pdev, 0);
3085 free_irq(irq, pdev);
3088 mach_info = pdev->dev.platform_data;
3089 if(mach_info->mcu_fmk_pin)
3091 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
3094 if(mach_info->io_disable)
3095 mach_info->io_disable(); //close lcd out
3099 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
3101 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
3104 //rk29fb_suspend(pdev, msg);
3105 // unmap memory and release framebuffer
3108 if (info->screen_base) {
3109 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3110 info->screen_base = 0;
3111 info->fix.smem_start = 0;
3112 info->fix.smem_len = 0;
3114 unregister_framebuffer(inf->fb1);
3115 framebuffer_release(inf->fb1);
3120 if (info->screen_base) {
3121 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3122 info->screen_base = 0;
3123 info->fix.smem_start = 0;
3124 info->fix.smem_len = 0;
3126 unregister_framebuffer(inf->fb0);
3127 framebuffer_release(inf->fb0);
3131 #if 0 //def CONFIG_CPU_FREQ
3132 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3139 clk_disable(inf->clk);
3145 clk_disable(inf->dclk);
3151 platform_set_drvdata(pdev, NULL);
3156 static void rk29fb_shutdown(struct platform_device *pdev)
3158 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3159 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3161 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3163 if(mach_info->io_disable)
3164 mach_info->io_disable(); //close lcd out
3166 if(!inf->in_suspend)
3168 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3169 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3170 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3172 clk_disable(inf->aclk_ddr_lcdc);
3173 clk_disable(inf->aclk_disp_matrix);
3174 clk_disable(inf->hclk_cpu_display);
3175 clk_disable(inf->clk);
3177 clk_disable(inf->dclk);
3180 clk_disable(inf->aclk);
3182 clk_disable(inf->pd_display);
3183 //pmu_set_power_domain(PD_DISPLAY, 0);
3184 inf->in_suspend = 1;
3189 static struct platform_driver rk29fb_driver = {
3190 .probe = rk29fb_probe,
3191 .remove = rk29fb_remove,
3194 .owner = THIS_MODULE,
3196 .shutdown = rk29fb_shutdown,
3199 static int __init rk29fb_init(void)
3201 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3202 return platform_driver_register(&rk29fb_driver);
3205 static void __exit rk29fb_exit(void)
3207 platform_driver_unregister(&rk29fb_driver);
3210 fs_initcall(rk29fb_init);
3211 module_exit(rk29fb_exit);
3214 MODULE_AUTHOR(" zyw@rock-chips.com");
3215 MODULE_DESCRIPTION("Driver for rk29 fb device");
3216 MODULE_LICENSE("GPL");