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;
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, screen->pixclock);
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;
1210 int blank_data,total_data;
1212 u16 xres_virtual = fb0_inf->var.xres_virtual; //virtual screen size
1213 u16 xpos_virtual = fb0_inf->var.xoffset; //visiable offset in virtual screen
1214 u16 ypos_virtual = fb0_inf->var.yoffset;
1216 int offset = (ypos_virtual*xres_virtual + xpos_virtual)*((inf->fb0_color_deepth || fb0_inf->var.bits_per_pixel==32)? 4:2)/4;
1217 p = (int*)fb0_inf->screen_base + offset;
1218 blank_data = (inf->fb0_color_deepth==32) ? 0xff000000 : 0;
1219 total_data = fb0_inf->var.xres*fb0_inf->var.yres*fb0_inf->var.bits_per_pixel/32;
1221 for(i=0; i < total_data; i++)
1223 if(*p++ != blank_data)
1225 //printk("win1 have no 0 data in %d, total %d\n",i,total_data);
1230 win1_blank(FB_BLANK_POWERDOWN, fb0_inf);
1231 // printk("%s close win1!\n",__func__);
1233 static DECLARE_DELAYED_WORK(rk29_win1_check_work, win1_check_work_func);
1235 static int win1_set_par(struct fb_info *info)
1237 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1238 struct fb_fix_screeninfo *fix = &info->fix;
1239 struct rk29fb_screen *screen = inf->cur_screen;
1240 struct win0_par *par = info->par;
1241 struct fb_var_screeninfo *var = &info->var;
1243 u16 xres_virtual,xpos,ypos;
1244 u8 trspval,trspmode;
1245 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1246 cancel_delayed_work_sync(&rk29_win1_check_work);
1248 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1249 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1251 hdmi_set_fbscale(info);
1252 }else if(((screen->x_res==1920) ))
1254 if(hdmi_get_fbscale() < 100)
1255 par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1257 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1259 xres_virtual = 0; //virtual screen size
1261 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1262 //u16 ypos_virtual = var->yoffset;
1264 xpos = par->xpos; //visiable offset in panel
1267 trspmode = TRSP_CLOSE;
1270 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1272 #ifdef CONFIG_FB_SCALING_OSD
1273 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1274 && (screen->x_res<=1280))
1276 addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1277 xres_virtual = screen->x_res* hdmi_get_fbscale()/100; //virtual screen size
1282 addr = fix->smem_start + par->y_offset;
1283 xres_virtual = var->xres_virtual; //virtual screen size
1285 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1287 xpos += (screen->left_margin + screen->hsync_len);
1288 ypos += (screen->upper_margin + screen->vsync_len);
1290 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1292 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1293 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1295 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1297 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1298 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1300 // enable win1 color key and set the color to black(rgb=0)
1301 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1303 if(1==par->format) //rgb565
1305 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1306 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1310 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1311 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1313 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1316 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1318 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1319 schedule_delayed_work(&rk29_win1_check_work, msecs_to_jiffies(5000));
1325 static int win1_pan( struct fb_info *info )
1327 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1328 struct fb_fix_screeninfo *fix1 = &info->fix;
1329 struct win0_par *par = info->par;
1332 #ifdef CONFIG_FB_SCALING_OSD
1333 struct rk29fb_screen *screen = inf->cur_screen;
1334 struct fb_var_screeninfo *var = &info->var;
1335 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1336 && (screen->x_res<=1280))
1338 addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1343 addr = fix1->smem_start + par->y_offset;
1346 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1348 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1349 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1355 static int fb0_blank(int blank_mode, struct fb_info *info)
1357 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1359 if(inf->video_mode == 1)
1361 win1_blank(blank_mode, info);
1365 win0_blank(blank_mode, info);
1370 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1372 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1373 struct rk29fb_screen *screen = inf->cur_screen;
1374 u16 xpos = (var->nonstd>>8) & 0xfff;
1375 u16 ypos = (var->nonstd>>20) & 0xfff;
1376 u16 xlcd = screen->x_res;
1377 u16 ylcd = screen->y_res;
1379 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1383 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1384 0==var->xres || 0==var->yres || var->xres<16 ||
1385 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1387 printk(">>>>>> fb0_check_var fail 1!!! \n");
1388 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1389 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1390 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1394 if( (var->xoffset+var->xres)>var->xres_virtual ||
1395 (var->yoffset+var->yres)>var->yres_virtual*2 )
1397 printk(">>>>>> fb0_check_var fail 2!!! \n");
1398 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1399 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1400 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1404 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1405 switch(var->bits_per_pixel)
1408 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1409 var->xres = (var->xres + 0x1) & (~0x1);
1410 var->xoffset = (var->xoffset) & (~0x1);
1413 var->bits_per_pixel = 32;
1421 static int fb0_set_par(struct fb_info *info)
1423 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1424 struct fb_var_screeninfo *var = &info->var;
1425 struct fb_fix_screeninfo *fix = &info->fix;
1426 struct rk29fb_screen *screen = inf->cur_screen;
1427 struct win0_par *par = info->par;
1429 u32 offset=0, smem_len=0;
1430 u16 xres_virtual = var->xres_virtual; //virtual screen size
1431 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1432 u16 ypos_virtual = var->yoffset;
1434 #ifdef CONFIG_FB_SCALING_OSD
1435 struct rk29_ipp_req ipp_req;
1439 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1444 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1445 #if !defined(CONFIG_FB_SCALING_OSD)
1446 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1449 switch(var->bits_per_pixel)
1453 if( ypos_virtual == 0)
1454 fb0_first_buff_bits = 16;
1456 fb0_second_buff_bits = 16;
1458 //fix->line_length = 2 * xres_virtual;
1459 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1461 #ifdef CONFIG_FB_SCALING_OSD
1462 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1463 ipp_req.src0.fmt = IPP_RGB_565;
1464 ipp_req.dst0.fmt = IPP_RGB_565;
1466 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1467 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1468 offset -= var->yres * var->xres *2;
1473 if( ypos_virtual == 0)
1474 fb0_first_buff_bits = 32;
1476 fb0_second_buff_bits = 32;
1477 fix->line_length = 4 * xres_virtual;
1478 #ifdef CONFIG_FB_SCALING_OSD
1479 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1481 ipp_req.src0.fmt = IPP_XRGB_8888;
1482 ipp_req.dst0.fmt = IPP_XRGB_8888;
1484 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1486 if(ypos_virtual >= 2*var->yres)
1489 #ifdef CONFIG_FB_SCALING_OSD
1490 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1491 ipp_req.src0.fmt = IPP_RGB_565;
1492 ipp_req.dst0.fmt = IPP_RGB_565;
1494 if(ypos_virtual == 3*var->yres)
1496 offset -= var->yres * var->xres *2;
1502 smem_len = fix->line_length * var->yres_virtual;
1503 //map_size = PAGE_ALIGN(smem_len);
1505 if (smem_len > fix->smem_len) // buffer need realloc
1507 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1508 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1509 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1513 par->addr_seted = 1;
1514 #if ANDROID_USE_THREE_BUFS
1515 if(0==new_frame_seted) {
1517 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1519 new_frame_seted = 0;
1522 if(inf->video_mode == 1)
1524 #ifdef CONFIG_FB_SCALING_OSD
1525 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1526 && (screen->x_res<=1280))
1530 par->xsize = screen->x_res;
1531 par->ysize = screen->y_res;
1532 par->y_offset = dstoffset;
1534 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1535 ipp_req.src0.w = var->xres;
1536 ipp_req.src0.h = var->yres;
1538 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1539 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1540 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1542 ipp_req.src_vir_w = ipp_req.src0.w;
1543 ipp_req.dst_vir_w = ipp_req.dst0.w;
1544 ipp_req.timeout = 100;
1545 ipp_req.flag = IPP_ROT_0;
1546 //ipp_do_blit(&ipp_req);
1547 ipp_blit_sync(&ipp_req);
1551 par->y_offset = offset;
1552 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1553 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1554 par->xsize = var->xres; //visiable size in panel
1555 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1561 par->y_offset = offset;
1564 par->xsize = screen->x_res;
1565 par->ysize = screen->y_res;
1572 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1575 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1576 struct fb_var_screeninfo *var1 = &info->var;
1577 struct rk29fb_screen *screen = inf->cur_screen;
1578 struct win0_par *par = info->par;
1581 u16 ypos_virtual = var->yoffset;
1582 u16 xpos_virtual = var->xoffset;
1583 #ifdef CONFIG_FB_SCALING_OSD
1584 struct fb_fix_screeninfo *fix = &info->fix;
1585 struct rk29_ipp_req ipp_req;
1588 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1592 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1593 #if !defined(CONFIG_FB_SCALING_OSD)
1594 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1597 switch(var1->bits_per_pixel)
1600 var->xoffset = (var->xoffset) & (~0x1);
1601 #ifdef CONFIG_FB_SCALING_OSD
1602 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1603 ipp_req.src0.fmt = IPP_RGB_565;
1604 ipp_req.dst0.fmt = IPP_RGB_565;
1606 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1607 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1608 offset -= var->yres * var->xres *2;
1611 #ifdef CONFIG_FB_SCALING_OSD
1612 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1613 ipp_req.src0.fmt = IPP_XRGB_8888;
1614 ipp_req.dst0.fmt = IPP_XRGB_8888;
1616 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1617 if(ypos_virtual >= 2*var->yres)
1620 #ifdef CONFIG_FB_SCALING_OSD
1621 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1622 ipp_req.src0.fmt = IPP_RGB_565;
1623 ipp_req.dst0.fmt = IPP_RGB_565;
1625 if(ypos_virtual == 3*var->yres)
1627 offset -= var->yres * var->xres *2;
1635 if(inf->video_mode == 1)
1637 #ifdef CONFIG_FB_SCALING_OSD
1638 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1639 && (screen->x_res<=1280))
1641 par->y_offset = dstoffset;
1643 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1644 ipp_req.src0.w = var->xres;
1645 ipp_req.src0.h = var->yres;
1647 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1648 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1649 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1651 ipp_req.src_vir_w = ipp_req.src0.w;
1652 ipp_req.dst_vir_w = ipp_req.dst0.w;
1653 ipp_req.timeout = 100;
1654 ipp_req.flag = IPP_ROT_0;
1655 //ipp_do_blit(&ipp_req);
1656 ipp_blit_sync(&ipp_req);
1661 par->y_offset = offset;
1666 par->y_offset = offset;
1669 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1670 #if !ANDROID_USE_THREE_BUFS
1671 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1672 if(SCREEN_MCU == inf->cur_screen->type) {
1673 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1677 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1683 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1685 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1686 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1692 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1695 inf->mcu_usetimer = 0;
1698 case FBIOPUT_16OR32:
1700 inf->fb0_color_deepth = arg;
1703 case FBIOGET_16OR32:
1704 return inf->fb0_color_deepth;
1705 case FBIOGET_IDLEFBUff_16OR32:
1706 if(info->var.yoffset == 0)
1708 return fb0_second_buff_bits;
1712 return fb0_first_buff_bits;
1714 case FBIOPUT_FBPHYADD:
1715 return info->fix.smem_start;
1716 case FBIOGET_OVERLAY_STATE:
1717 return inf->video_mode;
1718 case FBIOGET_SCREEN_STATE:
1719 return inf->cur_screen->type;
1721 case FBIOPUT_SET_CURSOR_EN:
1724 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1726 rk29_set_cursor_en(inf, en);
1729 case FBIOPUT_SET_CURSOR_POS:
1731 struct fbcurpos pos;
1732 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1734 rk29_set_cursor_pos(inf, pos.x , pos.y);
1737 case FBIOPUT_SET_CURSOR_IMG:
1739 char cursor_buf[CURSOR_BUF_SIZE];
1740 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1742 rk29_set_cursor_img(inf, cursor_buf);
1745 case FBIOPUT_SET_CURSOR_CMAP:
1747 struct fb_image img;
1748 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1750 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1753 case FBIOPUT_GET_CURSOR_RESOLUTION:
1756 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1757 if(inf->fb1->var.rotate == 270) {
1758 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1759 panel_size[1] = inf->cur_screen->x_res;
1761 panel_size[0] = inf->cur_screen->x_res;
1762 panel_size[1] = inf->cur_screen->y_res;
1764 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1767 case FBIOPUT_GET_CURSOR_EN:
1769 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1770 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1779 static int fb1_blank(int blank_mode, struct fb_info *info)
1781 win0_blank(blank_mode, info);
1785 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1787 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1788 struct rk29fb_screen *screen = inf->cur_screen;
1790 u32 ScaleYRGBY=0x1000;
1791 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1792 u16 ypos = (var->nonstd>>20) & 0xfff;
1793 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1794 u16 ysize = (var->grayscale>>20) & 0xfff;
1795 u16 xlcd = screen->x_res; //size of panel
1796 u16 ylcd = screen->y_res;
1799 struct hdmi *hdmi = get_hdmi_struct(0);
1802 if((var->rotate == 270)||(var->rotate == 90)) {
1803 #ifdef CONFIG_FB_ROTATE_VIDEO
1804 xlcd = screen->y_res;
1805 ylcd = screen->x_res;
1806 #else //CONFIG_FB_ROTATE_VIDEO
1807 printk("LCDC not support rotate!\n");
1812 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1813 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1814 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1815 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1817 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1821 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1822 0==var->xres || 0==var->yres || var->xres<16 ||
1823 0==xsize || 0==ysize || xsize<16 ||
1824 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1826 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1827 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1828 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1829 var->bits_per_pixel, var->bits_per_pixel);
1833 if( (var->xoffset+var->xres)>var->xres_virtual ||
1834 (var->yoffset+var->yres)>var->yres_virtual ||
1835 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1837 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1838 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1839 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1840 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1844 switch(var->nonstd&0x0f)
1847 switch(var->bits_per_pixel)
1850 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1851 var->xres = (var->xres + 0x1) & (~0x1);
1852 var->xoffset = (var->xoffset) & (~0x1);
1855 var->bits_per_pixel = 32;
1858 var->nonstd &= ~0xc0; //not support I2P in this format
1861 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1862 var->xres = (var->xres + 0x3) & (~0x3);
1863 var->xoffset = (var->xoffset) & (~0x3);
1866 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1867 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1868 var->xres = (var->xres + 0x3) & (~0x3);
1869 var->yres = (var->yres + 0x1) & (~0x1);
1870 var->xoffset = (var->xoffset) & (~0x3);
1871 var->yoffset = (var->yoffset) & (~0x1);
1874 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1875 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1876 var->xres = (var->xres + 0x3) & (~0x3);
1877 var->yres = (var->yres + 0x1) & (~0x1);
1878 var->xoffset = (var->xoffset) & (~0x3);
1879 var->yoffset = (var->yoffset) & (~0x1);
1880 var->nonstd &= ~0xc0; //not support I2P in this format
1884 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1885 var->xres = (var->xres + 0x3) & (~0x3);
1886 var->xoffset = (var->xoffset) & (~0x3);
1887 var->nonstd &= ~0xc0; //not support I2P in this format
1890 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1894 if((var->rotate == 270)||(var->rotate == 90))
1903 ScaleYRGBY = CalScaleW0(yres, ysize);
1905 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1907 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1910 if(inf->video_mode == 1) {
1911 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1913 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1914 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1915 init_completion(&hdmi->complete);
1917 wait_for_completion_interruptible_timeout(&hdmi->complete,
1918 msecs_to_jiffies(10000));
1925 static int fb1_set_par(struct fb_info *info)
1927 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1928 struct rk29fb_screen *screen = inf->cur_screen;
1929 struct fb_var_screeninfo *var = &info->var;
1930 struct fb_fix_screeninfo *fix = &info->fix;
1931 struct win0_par *par = info->par;
1934 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1936 //u32 xact = var->xres; /* visible resolution */
1937 //u32 yact = var->yres;
1938 u32 xvir = var->xres_virtual; /* virtual resolution */
1939 u32 yvir = var->yres_virtual;
1940 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1941 u32 yact_st = var->yoffset; /* resolution */
1943 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1944 u16 ypos = (var->nonstd>>20) & 0xfff;
1945 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1946 u16 ysize = (var->grayscale>>20) & 0xfff;
1948 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1949 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1951 u8 data_format = var->nonstd&0x0f;
1952 // u32 win0_en = var->reserved[2];
1953 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1954 // u32 uv_addr = var->reserved[4];
1956 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1959 if((var->rotate == 270)||(var->rotate == 90))
1961 #ifdef CONFIG_FB_ROTATE_VIDEO
1962 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1963 ypos = (var->nonstd>>8) & 0xfff;
1964 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1965 ysize = (var->grayscale>>8) & 0xfff;
1966 #else //CONFIG_FB_ROTATE_VIDEO
1967 printk("LCDC not support rotate!\n");
1971 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1972 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1973 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1974 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1976 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1977 switch (data_format)
1980 switch(var->bits_per_pixel)
1984 fix->line_length = 2 * xvir;
1985 par->y_offset = (yact_st*xvir + xact_st)*2;
1989 fix->line_length = 4 * xvir;
1990 par->y_offset = (yact_st*xvir + xact_st)*4;
1998 fix->line_length = xvir;
1999 cblen = crlen = (xvir*yvir)/2;
2000 par->y_offset = yact_st*xvir + xact_st;
2001 par->c_offset = yact_st*xvir + xact_st;
2005 fix->line_length = xvir;
2006 cblen = crlen = (xvir*yvir)/4;
2008 par->y_offset = yact_st*xvir + xact_st;
2009 par->c_offset = (yact_st/2)*xvir + xact_st;
2014 fix->line_length = xvir;
2015 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
2016 par->c_offset = (yact_st/2)*xvir + xact_st;
2017 cblen = crlen = (xvir*yvir)/4;
2022 fix->line_length = xvir;
2023 par->y_offset = yact_st*xvir + xact_st;
2024 par->c_offset = yact_st*2*xvir + xact_st*2;
2025 cblen = crlen = (xvir*yvir);
2031 smem_len = fix->line_length * yvir + cblen + crlen;
2032 map_size = PAGE_ALIGN(smem_len);
2034 // fix->smem_start = y_addr;
2035 fix->smem_len = smem_len;
2036 // fix->mmio_start = uv_addr;
2038 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
2039 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);
2041 par->format = format;
2048 if ( wq_condition2 == 0 ) {
2049 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
2053 #ifdef CONFIG_FB_ROTATE_VIDEO
2054 //need refresh ,zyc add
2055 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
2058 struct rk29_ipp_req ipp_req;
2059 static u32 dstoffset = 0;
2060 static int fb_index = 0;
2062 yuv_phy[0] = last_yuv_phy[0];
2063 yuv_phy[1] = last_yuv_phy[1];
2064 yuv_phy[0] += par->y_offset;
2065 yuv_phy[1] += par->c_offset;
2067 if((var->rotate == 90) ||(var->rotate == 270))
2069 if(var->rotate%360 != 0)
2072 dstoffset = (dstoffset+1)%2;
2073 ipp_req.src0.fmt = 3;
2074 ipp_req.src0.YrgbMst = yuv_phy[0];
2075 ipp_req.src0.CbrMst = yuv_phy[1];
2076 ipp_req.src0.w = var->xres;
2077 ipp_req.src0.h = var->yres;
2079 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2080 ipp_req.dst_vir_w=screen->x_res;
2082 ipp_req.dst0.fmt = 3;
2083 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2084 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2085 if(var->xres > screen->x_res)
2087 ipp_req.dst0.w = screen->x_res;
2088 ipp_req.dst0.h = screen->y_res;
2090 ipp_req.dst0.w = var->xres;
2091 ipp_req.dst0.h = var->yres;
2093 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2095 ipp_req.timeout = 100;
2096 if(var->rotate == 90)
2097 ipp_req.flag = IPP_ROT_90;
2098 else if (var->rotate == 180)
2099 ipp_req.flag = IPP_ROT_180;
2100 else if(var->rotate == 270)
2101 ipp_req.flag = IPP_ROT_270;
2102 //ipp_do_blit(&ipp_req);
2103 ipp_blit_sync(&ipp_req);
2104 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2105 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2106 yuv_phy[1] = ipp_req.dst0.CbrMst;
2107 fix->smem_start = yuv_phy[0];
2108 fix->mmio_start = yuv_phy[1];
2113 fix->smem_start = yuv_phy[0];
2114 fix->mmio_start = yuv_phy[1];
2117 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2118 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2119 // enable win0 after the win0 par is seted
2120 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2121 par->addr_seted = 1;
2122 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2123 if(par->addr_seted ) {
2124 unsigned long flags;
2126 local_irq_save(flags);
2127 par->mirror.y_offset = yuv_phy[0];
2128 par->mirror.c_offset = yuv_phy[1];
2129 local_irq_restore(flags);
2132 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2137 has_set_rotate = false;
2142 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2144 struct win0_par *par = info->par;
2145 // enable win0 after the win0 addr is seted
2152 int fb1_open(struct fb_info *info, int user)
2154 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2155 struct win0_par *par = info->par;
2157 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2160 par->addr_seted = 0;
2161 inf->video_mode = 1;
2163 #ifdef CONFIG_FB_ROTATE_VIDEO
2164 //reinitialize the var when open,zyc
2165 last_yuv_phy[0] = 0;
2166 last_yuv_phy[1] = 0;
2170 printk(">>>>>> fb1 has opened! \n");
2174 win0_blank(FB_BLANK_NORMAL, info);
2175 fb0_set_par(inf->fb0);
2177 rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2182 int fb1_release(struct fb_info *info, int user)
2184 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2185 struct win0_par *par = info->par;
2186 struct fb_var_screeninfo *var0 = &info->var;
2188 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2189 if(inf->setFlag == 0)
2191 wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2195 inf->video_mode = 0;
2197 par->addr_seted = 0;
2198 win1_blank(FB_BLANK_NORMAL, info);
2199 fb0_set_par(inf->fb0);
2202 info->screen_base = 0;
2203 info->fix.smem_start = 0;
2204 info->fix.smem_len = 0;
2205 // clean the var param
2206 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2207 rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2208 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2209 cancel_delayed_work_sync(&rk29_win1_check_work);
2216 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2218 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2219 struct win0_par *par = info->par;
2220 struct fb_fix_screeninfo *fix0 = &info->fix;
2221 struct fb_var_screeninfo *var = &info->var;
2222 void __user *argp = (void __user *)arg;
2224 #ifdef CONFIG_FB_ROTATE_VIDEO
2225 struct rk29fb_screen *screen = inf->cur_screen;
2226 struct rk29_ipp_req ipp_req;
2227 static u32 dstoffset = 0;
2231 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2232 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2238 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2241 if((var->rotate == 270)||(var->rotate == 90)) {
2242 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2243 panel_size[1] = inf->panel1_info.x_res;
2245 panel_size[0] = inf->panel1_info.x_res;
2246 panel_size[1] = inf->panel1_info.y_res;
2249 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2253 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2256 if (copy_from_user(yuv_phy, argp, 8))
2258 #ifdef CONFIG_FB_ROTATE_VIDEO
2260 if(has_set_rotate == true)
2262 last_yuv_phy[0] = yuv_phy[0];
2263 last_yuv_phy[1] = yuv_phy[1];
2266 fix0->smem_start = yuv_phy[0];
2267 fix0->mmio_start = yuv_phy[1];
2268 yuv_phy[0] += par->y_offset;
2269 yuv_phy[1] += par->c_offset;
2272 if((var->rotate == 90) ||(var->rotate == 270))
2274 if(var->rotate%360 != 0)
2277 #ifdef CONFIG_FB_ROTATE_VIDEO
2278 dstoffset = (dstoffset+1)%2;
2279 ipp_req.src0.fmt = 3;
2280 ipp_req.src0.YrgbMst = yuv_phy[0];
2281 ipp_req.src0.CbrMst = yuv_phy[1];
2282 ipp_req.src0.w = var->xres ;
2283 ipp_req.src0.h = var->yres ;
2284 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2285 ipp_req.dst_vir_w=screen->x_res;
2287 ipp_req.dst0.fmt = 3;
2288 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2289 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2290 if(var->xres > screen->x_res)
2292 ipp_req.dst0.w = screen->x_res;
2293 ipp_req.dst0.h = screen->y_res;
2295 ipp_req.dst0.w = var->xres;
2296 ipp_req.dst0.h = var->yres;
2299 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2300 ipp_req.timeout = 100;
2301 if(var->rotate == 90)
2302 ipp_req.flag = IPP_ROT_90;
2303 else if(var->rotate == 180)
2304 ipp_req.flag = IPP_ROT_180;
2305 else if(var->rotate == 270)
2306 ipp_req.flag = IPP_ROT_270;
2307 //ipp_do_blit(&ipp_req);
2308 ipp_blit_sync(&ipp_req);
2310 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2311 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2312 yuv_phy[1] = ipp_req.dst0.CbrMst;
2313 fix0->smem_start = yuv_phy[0];
2314 fix0->mmio_start = yuv_phy[1];
2315 #else //CONFIG_FB_ROTATE_VIDEO
2316 printk("LCDC not support rotate!\n");
2320 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2321 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2322 // enable win0 after the win0 par is seted
2323 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2324 par->addr_seted = 1;
2325 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2326 if(par->par_seted) {
2327 unsigned long flags;
2329 local_irq_save(flags);
2330 par->mirror.y_offset = yuv_phy[0];
2331 par->mirror.c_offset = yuv_phy[1];
2332 local_irq_restore(flags);
2335 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2340 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2341 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2342 #ifdef CONFIG_FB_ROTATE_VIDEO
2344 has_set_rotate = true;
2345 if(arg == 0 || arg==180)
2347 else if (arg == 90 || arg==270)
2349 #else //CONFIG_FB_ROTATE_VIDEO
2350 printk("LCDC not support rotate!\n");
2353 case FB1_IOCTL_SET_WIN0_TOP:
2354 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2355 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2356 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2364 static struct fb_ops fb1_ops = {
2365 .owner = THIS_MODULE,
2366 .fb_open = fb1_open,
2367 .fb_release = fb1_release,
2368 .fb_check_var = fb1_check_var,
2369 .fb_set_par = fb1_set_par,
2370 .fb_blank = fb1_blank,
2371 .fb_pan_display = fb1_pan_display,
2372 .fb_ioctl = fb1_ioctl,
2373 .fb_setcolreg = fb_setcolreg,
2374 .fb_fillrect = cfb_fillrect,
2375 .fb_copyarea = cfb_copyarea,
2376 .fb_imageblit = cfb_imageblit,
2379 static struct fb_ops fb0_ops = {
2380 .owner = THIS_MODULE,
2381 .fb_check_var = fb0_check_var,
2382 .fb_set_par = fb0_set_par,
2383 .fb_blank = fb0_blank,
2384 .fb_pan_display = fb0_pan_display,
2385 .fb_ioctl = fb0_ioctl,
2386 .fb_setcolreg = fb_setcolreg,
2387 .fb_fillrect = cfb_fillrect,
2388 .fb_copyarea = cfb_copyarea,
2389 .fb_imageblit = cfb_imageblit,
2390 //.fb_cursor = rk29_set_cursor,
2393 int fb_get_video_mode(void)
2395 struct rk29fb_inf *inf;
2398 inf = platform_get_drvdata(g_pdev);
2399 return inf->video_mode;
2402 enable: 1, switch to tv or hdmi; 0, switch to lcd
2404 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2406 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2407 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2408 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2410 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2412 if(enable)inf->cur_screen = &inf->panel2_info;
2413 else inf->cur_screen = &inf->panel1_info;
2415 /* Black out, because some display device need clock to standby */
2416 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2417 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2418 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2419 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2420 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2421 wake_lock(&idlelock);
2423 wake_unlock(&idlelock);
2425 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2426 // operate the display_on pin to power down the lcd
2428 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2429 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2431 load_screen(inf->fb0, 0);
2434 fb1_set_par(inf->fb1);
2435 fb0_set_par(inf->fb0);
2436 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2437 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2438 rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2442 static ssize_t dsp_win0_info_read(struct device *device,
2443 struct device_attribute *attr, char *buf)
2446 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2447 struct rk29fb_screen *screen = inf->cur_screen;
2449 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2451 fbprintk("%s\n",__FUNCTION__);
2452 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2453 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2455 xpos -= (screen->left_margin + screen->hsync_len);
2456 ypos -= (screen->upper_margin + screen->vsync_len);
2458 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2459 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2460 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2461 rk29_set_cursor_test(inf->fb0);
2463 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2466 static ssize_t dsp_win0_info_write(struct device *device,
2467 struct device_attribute *attr, const char *buf, size_t count)
2469 printk("%s\n",__FUNCTION__);
2470 printk("%s %x \n",__FUNCTION__,*buf);
2474 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2476 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2478 struct platform_device *pdev = (struct platform_device*)dev_id;
2479 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2480 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2484 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2486 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2488 if(SCREEN_MCU == inf->cur_screen->type)
2490 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2496 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2498 inf->mcu_fmksync = 1;
2499 if(inf->cur_screen->refresh)
2500 inf->cur_screen->refresh(REFRESH_END);
2501 inf->mcu_fmksync = 0;
2510 if(inf->mcu_needflush) {
2511 if(inf->cur_screen->refresh)
2512 inf->cur_screen->refresh(REFRESH_PRE);
2513 inf->mcu_needflush = 0;
2514 inf->mcu_isrcnt = 0;
2515 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2517 if(inf->cur_screen->refresh)
2518 inf->cur_screen->refresh(REFRESH_END);
2522 #if ANDROID_USE_THREE_BUFS
2523 new_frame_seted = 1;
2526 if(waitqueue_active(&par->wait)) {
2527 if (par->mirror.c_offset == 0)
2528 printk("error: no new buffer to display\n");
2530 par->done.y_offset = par->displ.y_offset;
2531 par->done.c_offset = par->displ.c_offset;
2532 par->displ.y_offset = par->mirror.y_offset;
2533 par->displ.c_offset = par->mirror.c_offset;
2534 par->mirror.y_offset = 0;
2535 par->mirror.c_offset = 0;
2537 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2538 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2539 wake_up_interruptible(&par->wait);
2544 wake_up_interruptible(&wq);
2546 rk29fb_irq_notify_ddr();
2550 #ifdef CONFIG_HAS_EARLYSUSPEND
2552 struct suspend_info {
2553 struct early_suspend early_suspend;
2554 struct rk29fb_inf *inf;
2557 static void rk29fb_early_suspend(struct early_suspend *h)
2559 struct suspend_info *info = container_of(h, struct suspend_info,
2562 struct rk29fb_inf *inf = info->inf;
2563 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2565 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2568 printk("inf==0, rk29fb_suspend fail! \n");
2572 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2573 cancel_delayed_work_sync(&rk29_win1_check_work);
2576 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2577 mach_info->io_disable(); //close lcd out
2579 if(inf->cur_screen->standby)
2581 fbprintk(">>>>>> power down the screen! \n");
2582 inf->cur_screen->standby(1);
2585 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2586 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2588 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2589 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2590 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2592 if(!inf->in_suspend)
2594 fbprintk(">>>>>> diable the lcdc clk! \n");
2595 wake_lock(&idlelock);
2597 wake_unlock(&idlelock);
2598 clk_disable(inf->aclk_ddr_lcdc);
2599 clk_disable(inf->aclk_disp_matrix);
2600 clk_disable(inf->hclk_cpu_display);
2601 clk_disable(inf->clk);
2603 clk_disable(inf->dclk);
2606 clk_disable(inf->aclk);
2608 //clk_disable(inf->pd_display);
2610 inf->in_suspend = 1;
2614 static void rk29fb_early_resume(struct early_suspend *h)
2616 struct suspend_info *info = container_of(h, struct suspend_info,
2619 struct rk29fb_inf *inf = info->inf;
2620 struct rk29fb_screen *screen = inf->cur_screen;
2621 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2623 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2625 printk("inf==0, rk29fb_resume fail! \n");
2631 inf->in_suspend = 0;
2632 fbprintk(">>>>>> enable the lcdc clk! \n");
2633 // clk_enable(inf->pd_display);
2634 clk_enable(inf->aclk_disp_matrix);
2635 clk_enable(inf->hclk_cpu_display);
2636 clk_enable(inf->clk);
2637 clk_enable(inf->aclk_ddr_lcdc);
2640 clk_enable(inf->dclk);
2643 clk_enable(inf->aclk);
2645 usleep_range(100*1000, 100*1000);
2647 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2648 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2649 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2651 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2652 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2654 if(inf->cur_screen->standby)
2656 fbprintk(">>>>>> power on the screen! \n");
2657 inf->cur_screen->standby(0);
2659 usleep_range(10*1000, 10*1000);
2660 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2661 usleep_range(40*1000, 40*1000);
2663 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2664 mach_info->io_enable(); //close lcd out
2668 static struct suspend_info suspend_info = {
2669 .early_suspend.suspend = rk29fb_early_suspend,
2670 .early_suspend.resume = rk29fb_early_resume,
2671 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2674 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2675 static int __init rk29fb_probe (struct platform_device *pdev)
2677 struct rk29fb_inf *inf = NULL;
2678 struct resource *res = NULL;
2679 struct resource *mem = NULL;
2680 struct rk29fb_info *mach_info = NULL;
2681 struct rk29fb_screen *screen = NULL;
2682 struct win0_par* par = NULL;
2686 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2688 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2689 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2690 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2693 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2695 goto release_drvdata;
2697 memset(inf, 0, sizeof(struct rk29fb_inf));
2698 platform_set_drvdata(pdev, inf);
2700 mach_info = pdev->dev.platform_data;
2701 /* Fill screen info and set current screen */
2702 fbprintk(">> Fill screen info and set current screen \n");
2703 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2704 hdmi_get_default_resolution(&inf->panel1_info);
2706 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2708 inf->cur_screen = &inf->panel1_info;
2709 screen = inf->cur_screen;
2710 if(SCREEN_NULL==screen->type)
2712 dev_err(&pdev->dev, ">> Please select a display device! \n");
2714 goto release_drvdata;
2717 /* get virtual basic address of lcdc register */
2718 fbprintk(">> get virtual basic address of lcdc register \n");
2719 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2722 dev_err(&pdev->dev, "failed to get memory registers\n");
2724 goto release_drvdata;
2726 inf->reg_phy_base = res->start;
2727 inf->len = (res->end - res->start) + 1;
2728 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2731 dev_err(&pdev->dev, "failed to get memory region\n");
2733 goto release_drvdata;
2735 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2736 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2737 if (inf->reg_vir_base == NULL)
2739 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2741 goto release_drvdata;
2743 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2745 /* Prepare win1 info */
2746 fbprintk(">> Prepare win1 info \n");
2747 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2750 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2753 goto release_win1fb;
2756 par = (struct win0_par*)inf->fb0->par;
2757 strcpy(inf->fb0->fix.id, "fb0");
2758 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2759 inf->fb0->fix.type_aux = 0;
2760 inf->fb0->fix.xpanstep = 1;
2761 inf->fb0->fix.ypanstep = 1;
2762 inf->fb0->fix.ywrapstep = 0;
2763 inf->fb0->fix.accel = FB_ACCEL_NONE;
2764 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2765 inf->fb0->fix.smem_len = 0;
2766 inf->fb0->fix.line_length = 0;
2767 inf->fb0->fix.smem_start = 0;
2769 inf->fb0->var.xres = screen->x_res;
2770 inf->fb0->var.yres = screen->y_res;
2771 inf->fb0->var.bits_per_pixel = 16;
2772 inf->fb0_color_deepth = 0;
2773 inf->fb0->var.xres_virtual = screen->x_res;
2774 inf->fb0->var.yres_virtual = screen->y_res;
2775 inf->fb0->var.width = screen->width;
2776 inf->fb0->var.height = screen->height;
2777 inf->fb0->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
2778 inf->fb0->var.left_margin = screen->left_margin;
2779 inf->fb0->var.right_margin = screen->right_margin;
2780 inf->fb0->var.upper_margin = screen->upper_margin;
2781 inf->fb0->var.lower_margin = screen->lower_margin;
2782 inf->fb0->var.vsync_len = screen->vsync_len;
2783 inf->fb0->var.hsync_len = screen->hsync_len;
2784 inf->fb0->var.red = def_rgb_16.red;
2785 inf->fb0->var.green = def_rgb_16.green;
2786 inf->fb0->var.blue = def_rgb_16.blue;
2787 inf->fb0->var.transp = def_rgb_16.transp;
2789 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2790 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2791 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2792 inf->fb0->var.accel_flags = 0;
2793 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2795 inf->fb0->fbops = &fb0_ops;
2796 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2797 inf->fb0->pseudo_palette = par->pseudo_pal;
2798 inf->fb0->screen_base = 0;
2800 memset(par, 0, sizeof(struct win0_par));
2802 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2806 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2808 /* alloc win1 buf */
2809 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2812 dev_err(&pdev->dev, "failed to get win1 memory \n");
2814 goto release_win1fb;
2816 inf->fb0->fix.smem_start = res->start;
2817 inf->fb0->fix.smem_len = res->end - res->start + 1;
2818 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2819 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2821 #ifdef CONFIG_FB_WORK_IPP
2822 /* alloc win1 ipp buf */
2823 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2826 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2828 goto release_win1fb;
2830 inf->fb0->fix.mmio_start = res->start;
2831 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2834 /* Prepare win0 info */
2835 fbprintk(">> Prepare win0 info \n");
2836 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2839 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2842 goto release_win0fb;
2845 par = (struct win0_par*)inf->fb1->par;
2847 strcpy(inf->fb1->fix.id, "fb1");
2848 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2849 inf->fb1->fix.type_aux = 0;
2850 inf->fb1->fix.xpanstep = 1;
2851 inf->fb1->fix.ypanstep = 1;
2852 inf->fb1->fix.ywrapstep = 0;
2853 inf->fb1->fix.accel = FB_ACCEL_NONE;
2854 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2855 inf->fb1->fix.smem_len = 0;
2856 inf->fb1->fix.line_length = 0;
2857 inf->fb1->fix.smem_start = 0;
2859 inf->fb1->var.xres = screen->x_res;
2860 inf->fb1->var.yres = screen->y_res;
2861 inf->fb1->var.bits_per_pixel = 16;
2862 inf->fb1->var.xres_virtual = screen->x_res;
2863 inf->fb1->var.yres_virtual = screen->y_res;
2864 inf->fb1->var.width = screen->width;
2865 inf->fb1->var.height = screen->height;
2866 inf->fb1->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
2867 inf->fb1->var.left_margin = screen->left_margin;
2868 inf->fb1->var.right_margin = screen->right_margin;
2869 inf->fb1->var.upper_margin = screen->upper_margin;
2870 inf->fb1->var.lower_margin = screen->lower_margin;
2871 inf->fb1->var.vsync_len = screen->vsync_len;
2872 inf->fb1->var.hsync_len = screen->hsync_len;
2873 inf->fb1->var.red = def_rgb_16.red;
2874 inf->fb1->var.green = def_rgb_16.green;
2875 inf->fb1->var.blue = def_rgb_16.blue;
2876 inf->fb1->var.transp = def_rgb_16.transp;
2878 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2879 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2880 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2881 inf->fb1->var.accel_flags = 0;
2882 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2884 inf->fb1->fbops = &fb1_ops;
2885 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2886 inf->fb1->pseudo_palette = par->pseudo_pal;
2887 inf->fb1->screen_base = 0;
2889 memset(par, 0, sizeof(struct win0_par));
2891 init_waitqueue_head(&par->wait);
2893 /* Init all lcdc and lcd before register_framebuffer. */
2894 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2895 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2896 init_lcdc(inf->fb0);
2898 #if 0 //def CONFIG_CPU_FREQ
2899 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2900 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2902 fbprintk("got clock\n");
2906 struct rk29_fb_setting_info fb_setting;
2907 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2909 fb_setting.data_num = 24;
2911 else if(OUT_P666 == inf->cur_screen->face )
2913 fb_setting.data_num = 18;
2917 fb_setting.data_num = 16;
2919 fb_setting.den_en = 1;
2920 fb_setting.vsync_en = 1;
2921 fb_setting.disp_on_en = 1;
2922 fb_setting.standby_en = 1;
2923 if( inf->cur_screen->mcu_usefmk )
2924 fb_setting.mcu_fmk_en =1;
2925 mach_info->io_init(&fb_setting);
2928 //set_lcd_pin(pdev, 1);
2931 inf->mcu_usetimer = 1;
2932 inf->mcu_fmksync = 0;
2933 load_screen(inf->fb0, 1);
2935 /* Register framebuffer(fb0 & fb1) */
2936 fbprintk(">> Register framebuffer(fb0) \n");
2937 ret = register_framebuffer(inf->fb0);
2940 printk(">> fb0 register_framebuffer fail!\n");
2942 goto release_win0fb;
2944 fbprintk(">> Register framebuffer(fb1) \n");
2946 ret = register_framebuffer(inf->fb1);
2949 printk(">> fb1 register_framebuffer fail!\n");
2951 goto unregister_win1fb;
2954 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2957 printk(">> fb1 dsp win0 info device_create_file err\n");
2960 #ifdef CONFIG_HAS_EARLYSUSPEND
2961 suspend_info.inf = inf;
2962 register_early_suspend(&suspend_info.early_suspend);
2965 /* get and request irq */
2966 fbprintk(">> get and request irq \n");
2967 irq = platform_get_irq(pdev, 0);
2969 dev_err(&pdev->dev, "no irq for device\n");
2971 goto unregister_win1fb;
2973 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2975 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2980 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2982 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2985 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2991 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2992 fb0_set_par(inf->fb0);
2993 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2994 /* Start display and show logo on boot */
2995 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2996 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2997 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
3001 printk(" %s ok\n", __FUNCTION__);
3006 free_irq(irq, pdev);
3008 unregister_framebuffer(inf->fb0);
3011 framebuffer_release(inf->fb1);
3015 fb_dealloc_cmap(&inf->fb0->cmap);
3018 framebuffer_release(inf->fb0);
3021 if(inf && inf->reg_vir_base)
3022 iounmap(inf->reg_vir_base);
3024 release_mem_region(inf->reg_phy_base, inf->len);
3027 platform_set_drvdata(pdev, NULL);
3031 static int rk29fb_remove(struct platform_device *pdev)
3033 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3034 struct fb_info *info = NULL;
3036 struct rk29fb_info *mach_info = NULL;
3039 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3042 printk("inf==0, rk29_fb_remove fail! \n");
3045 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3047 irq = platform_get_irq(pdev, 0);
3050 free_irq(irq, pdev);
3053 mach_info = pdev->dev.platform_data;
3054 if(mach_info->mcu_fmk_pin)
3056 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
3059 if(mach_info->io_disable)
3060 mach_info->io_disable(); //close lcd out
3064 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
3066 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
3069 //rk29fb_suspend(pdev, msg);
3070 // unmap memory and release framebuffer
3073 if (info->screen_base) {
3074 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3075 info->screen_base = 0;
3076 info->fix.smem_start = 0;
3077 info->fix.smem_len = 0;
3079 unregister_framebuffer(inf->fb1);
3080 framebuffer_release(inf->fb1);
3085 if (info->screen_base) {
3086 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3087 info->screen_base = 0;
3088 info->fix.smem_start = 0;
3089 info->fix.smem_len = 0;
3091 unregister_framebuffer(inf->fb0);
3092 framebuffer_release(inf->fb0);
3096 #if 0 //def CONFIG_CPU_FREQ
3097 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3104 clk_disable(inf->clk);
3110 clk_disable(inf->dclk);
3116 platform_set_drvdata(pdev, NULL);
3121 static void rk29fb_shutdown(struct platform_device *pdev)
3123 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3124 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3126 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3128 if(mach_info->io_disable)
3129 mach_info->io_disable(); //close lcd out
3131 if(!inf->in_suspend)
3133 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3134 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3135 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3137 clk_disable(inf->aclk_ddr_lcdc);
3138 clk_disable(inf->aclk_disp_matrix);
3139 clk_disable(inf->hclk_cpu_display);
3140 clk_disable(inf->clk);
3142 clk_disable(inf->dclk);
3145 clk_disable(inf->aclk);
3147 clk_disable(inf->pd_display);
3148 //pmu_set_power_domain(PD_DISPLAY, 0);
3149 inf->in_suspend = 1;
3154 static struct platform_driver rk29fb_driver = {
3155 .probe = rk29fb_probe,
3156 .remove = rk29fb_remove,
3159 .owner = THIS_MODULE,
3161 .shutdown = rk29fb_shutdown,
3164 static int __init rk29fb_init(void)
3166 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3167 return platform_driver_register(&rk29fb_driver);
3170 static void __exit rk29fb_exit(void)
3172 platform_driver_unregister(&rk29fb_driver);
3175 fs_initcall(rk29fb_init);
3176 module_exit(rk29fb_exit);
3179 MODULE_AUTHOR(" zyw@rock-chips.com");
3180 MODULE_DESCRIPTION("Driver for rk29 fb device");
3181 MODULE_LICENSE("GPL");