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};
274 static BLOCKING_NOTIFIER_HEAD(rk29fb_notifier_list);
275 int rk29fb_register_notifier(struct notifier_block *nb)
279 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
281 if (inf->cur_screen && inf->cur_screen->type == SCREEN_HDMI)
282 nb->notifier_call(nb, RK29FB_EVENT_HDMI_ON, inf->cur_screen);
283 if (inf->fb1 && inf->fb1->par) {
284 struct win0_par *par = inf->fb1->par;
286 nb->notifier_call(nb, RK29FB_EVENT_FB1_ON, inf->cur_screen);
290 ret = blocking_notifier_chain_register(&rk29fb_notifier_list, nb);
295 int rk29fb_unregister_notifier(struct notifier_block *nb)
297 return blocking_notifier_chain_unregister(&rk29fb_notifier_list, nb);
300 static int rk29fb_notify(struct rk29fb_inf *inf, unsigned long event)
302 return blocking_notifier_call_chain(&rk29fb_notifier_list, event, inf->cur_screen);
305 int mcu_do_refresh(struct rk29fb_inf *inf)
307 if(inf->mcu_stopflush) return 0;
309 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
314 inf->mcu_needflush = 1;
318 // not use frame mark
319 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
321 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
323 inf->mcu_needflush = 1;
327 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
328 inf->mcu_needflush = 0;
330 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
337 void mcutimer_callback(unsigned long arg)
339 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
340 static int waitcnt = 0;
342 mod_timer(&inf->mcutimer, jiffies + HZ/10);
344 switch(inf->mcu_status)
347 inf->mcu_status = MS_MCU;
350 if(inf->mcu_usetimer) mcu_do_refresh(inf);
353 inf->mcu_status = MS_EWAITEND;
361 inf->mcu_status = MS_EEND;
365 inf->mcu_status = MS_MCU;
368 inf->mcu_status = MS_MCU;
373 int mcu_refresh(struct rk29fb_inf *inf)
375 static int mcutimer_inited = 0;
377 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
382 init_timer(&inf->mcutimer);
383 inf->mcutimer.function = mcutimer_callback;
384 inf->mcutimer.expires = jiffies + HZ/5;
385 inf->mcu_status = MS_IDLE;
386 add_timer(&inf->mcutimer);
389 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
394 int mcu_ioctl(unsigned int cmd, unsigned long arg)
396 struct rk29fb_inf *inf = NULL;
397 if(!g_pdev) return -1;
399 inf = dev_get_drvdata(&g_pdev->dev);
404 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
405 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
406 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
410 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
411 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
415 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
416 LcdWrReg(inf, REG_CFG_DONE, 0x01);
426 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
428 struct platform_device *pdev = (struct platform_device*)dev_id;
429 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
430 struct rk29fb_screen *screen;
432 if(!inf) return IRQ_HANDLED;
434 screen = inf->cur_screen;
436 if(0==screen->mcu_usefmk) {
440 if(inf->mcu_fmksync == 1)
443 inf->mcu_fmksync = 1;
444 if(inf->mcu_needflush)
446 inf->mcu_needflush = 0;
448 if(inf->cur_screen->refresh)
449 inf->cur_screen->refresh(REFRESH_PRE);
450 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
452 inf->mcu_fmksync = 0;
457 int init_lcdc(struct fb_info *info)
459 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
462 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
464 inf->clk = clk_get(NULL, "hclk_lcdc");
465 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
466 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
467 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
468 inf->pd_display = clk_get(NULL, "pd_display");
469 if ((IS_ERR(inf->clk)) ||
470 (IS_ERR(inf->aclk_ddr_lcdc)) ||
471 (IS_ERR(inf->aclk_disp_matrix)) ||
472 (IS_ERR(inf->hclk_cpu_display)) ||
473 (IS_ERR(inf->pd_display)))
475 printk(KERN_ERR "failed to get lcdc_hclk source\n");
476 return PTR_ERR(inf->clk);
478 clk_enable(inf->aclk_disp_matrix);
479 clk_enable(inf->hclk_cpu_display);
480 clk_enable(inf->clk);
481 clk_enable(inf->pd_display);
482 //pmu_set_power_domain(PD_DISPLAY, 1);
483 clk_enable(inf->aclk_ddr_lcdc);
485 // set AHB access rule and disable all windows
486 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
487 LcdWrReg(inf, SWAP_CTRL, 0);
488 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
489 LcdWrReg(inf, AXI_MS_ID, 0x54321);
491 // and mcu holdmode; and set win1 top.
492 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
493 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
495 // disable blank out, black out, tristate out, yuv2rgb bypass
496 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
497 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
498 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
499 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
502 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
503 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
505 LcdWrReg(inf, DSP_CTRL1, 0);
507 // initialize all interrupt
508 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
510 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
512 LcdWrReg(inf, INT_STATUS, clr | msk);
514 // let above to take effect
515 LcdWrReg(inf, REG_CFG_DONE, 0x01);
520 void load_screen(struct fb_info *info, bool initscreen)
523 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
524 struct rk29fb_screen *screen = inf->cur_screen;
526 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
527 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
528 u16 x_res = screen->x_res, y_res = screen->y_res;
529 u32 aclk_rate = 150000000;
532 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
536 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
538 // set the rgb or mcu
539 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
541 // set out format and mcu timing
542 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
543 if(mcu_total>31) mcu_total = 31;
544 if(mcu_total<3) mcu_total = 3;
545 mcu_rwstart = (mcu_total+1)/4 - 1;
546 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
547 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
548 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
550 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
551 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
553 LcdMskReg(inf, MCU_TIMING_CTRL,
554 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
555 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
556 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
557 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
558 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
561 // set synchronous pin polarity and data pin swap rule
562 switch (screen->face)
566 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
570 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
574 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
578 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
582 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
583 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
586 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
587 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
592 LcdMskReg(inf, DSP_CTRL0,
593 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
594 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
595 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
596 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
599 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
601 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
602 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));
604 // set horizontal & vertical out timing
605 if(SCREEN_MCU==inf->cur_screen->type)
607 right_margin = x_res/6;
610 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
611 screen->hsync_len , screen->left_margin , x_res , right_margin );
612 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
613 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
614 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
615 v_BIT12HI(screen->hsync_len + screen->left_margin));
617 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
618 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
619 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
620 v_BIT11HI(screen->vsync_len + screen->upper_margin));
622 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
623 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
625 // let above to take effect
626 LcdWrReg(inf, REG_CFG_DONE, 0x01);
628 inf->dclk = clk_get(NULL, "dclk_lcdc");
629 if (IS_ERR(inf->dclk))
631 printk(KERN_ERR "failed to get lcd dclock source\n");
635 inf->aclk = clk_get(NULL, "aclk_lcdc");
636 if (IS_ERR(inf->aclk))
638 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
641 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
642 if (IS_ERR(inf->aclk_parent))
644 printk(KERN_ERR "failed to get lcd clock parent source\n");
649 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
651 if(initscreen == 0) //not init
653 clk_disable(inf->dclk);
654 // clk_disable(inf->aclk);
657 // clk_disable(inf->aclk_ddr_lcdc);
658 // clk_disable(inf->aclk_disp_matrix);
659 // clk_disable(inf->hclk_cpu_display);
661 // clk_disable(inf->clk);
664 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
666 ret = clk_set_rate(inf->dclk, screen->pixclock);
669 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
674 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
675 if(screen->lcdc_aclk){
676 aclk_rate = screen->lcdc_aclk;
678 ret = clk_set_rate(inf->aclk, aclk_rate);
680 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
682 clk_enable(inf->aclk);
684 // clk_enable(inf->aclk_ddr_lcdc);
685 // clk_enable(inf->aclk_disp_matrix);
686 // clk_enable(inf->hclk_cpu_display);
687 // clk_enable(inf->clk);
688 clk_enable(inf->dclk);
696 #if 0 //def CONFIG_CPU_FREQ
698 * CPU clock speed change handler. We need to adjust the LCD timing
699 * parameters when the CPU clock is adjusted by the power management
702 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
705 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
707 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
708 struct rk29fb_screen *screen = inf->cur_screen;
713 case CPUFREQ_PRECHANGE:
715 case CPUFREQ_POSTCHANGE:
717 dclk_rate = screen->pixclock * 1000000;
719 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
721 clk_set_rate(inf->dclk_divider, dclk_rate);
729 static inline unsigned int chan_to_field(unsigned int chan,
730 struct fb_bitfield *bf)
733 chan >>= 16 - bf->length;
734 return chan << bf->offset;
737 static int fb_setcolreg(unsigned regno,
738 unsigned red, unsigned green, unsigned blue,
739 unsigned transp, struct fb_info *info)
742 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
744 switch (info->fix.visual) {
745 case FB_VISUAL_TRUECOLOR:
746 /* true-colour, use pseudo-palette */
748 u32 *pal = info->pseudo_palette;
749 val = chan_to_field(red, &info->var.red);
750 val |= chan_to_field(green, &info->var.green);
751 val |= chan_to_field(blue, &info->var.blue);
756 return -1; /* unknown type */
762 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
765 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
767 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
769 LcdWrReg(inf, REG_CFG_DONE, 0x01);
773 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
775 struct rk29fb_screen *screen = inf->cur_screen;
778 if (x >= 0x800 || y >= 0x800 )
780 //printk("%s: %08x,%08x \n",__func__, x, y);
781 x += (screen->left_margin + screen->hsync_len);
782 y += (screen->upper_margin + screen->vsync_len);
783 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
784 LcdWrReg(inf, REG_CFG_DONE, 0x01);
789 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
791 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
792 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
793 LcdWrReg(inf, REG_CFG_DONE, 0x01);
797 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
798 int rk29_set_cursor_img_transform(char *data)
801 char *dst = (char*)rk29_cursor_buf;
802 unsigned char dmsk = 0;
803 unsigned int op,shift,offset;
805 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
806 * clears it to transparent then combines the cursor
807 * shape plane with the colour plane to set the
809 for (y = 0; y < 32; y++)
811 for (x = 0; x < 32; x++)
818 op = (dmsk & 0x80) ? 2 : 3;
821 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
831 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
835 rk29_set_cursor_img_transform(data);
839 rk29_set_cursor_img_transform(cursor_img);
841 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
842 //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
843 LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
845 LcdWrReg(inf, REG_CFG_DONE, 0x01);
850 int rk29_set_cursor_test(struct fb_info *info)
852 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
853 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
854 rk29_set_cursor_pos(inf, 0, 0);
855 rk29_set_cursor_img(inf, 0);
856 rk29_set_cursor_en(inf, 1);
861 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
863 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
865 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
867 /* check not being asked to exceed capabilities */
869 if (cursor->image.width > 32)
872 if (cursor->image.height > 32)
875 if (cursor->image.depth > 1)
879 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
881 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
884 if (cursor->set & FB_CUR_SETPOS)
886 unsigned int x = cursor->image.dx;
887 unsigned int y = cursor->image.dy;
889 if (x >= 0x800 || y >= 0x800 )
891 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
895 if (cursor->set & FB_CUR_SETCMAP)
897 unsigned int bg_col = cursor->image.bg_color;
898 unsigned int fg_col = cursor->image.fg_color;
900 fbprintk("%s: update cmap (%08x,%08x)\n",
901 __func__, bg_col, fg_col);
903 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
904 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));
906 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
907 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));
910 if ((cursor->set & FB_CUR_SETSIZE ||
911 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
912 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
914 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
915 * clears it to transparent then combines the cursor
916 * shape plane with the colour plane to set the
919 const unsigned char *pcol = cursor->image.data;
920 const unsigned char *pmsk = cursor->mask;
922 unsigned long cursor_mem_start;
923 unsigned char dcol = 0;
924 unsigned char dmsk = 0;
927 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
928 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
930 fbprintk("%s: setting shape (%d,%d)\n",
931 __func__, cursor->image.width, cursor->image.height);
933 memset(dst, 0, CURSOR_BUF_SIZE);
935 for (y = 0; y < cursor->image.height; y++)
937 for (x = 0; x < cursor->image.width; x++)
948 op = (dcol & 1) ? 1 : 3;
949 op <<= ((x % 4) * 2);
950 *(u8*)(dst+(x/4)) |= op;
955 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
956 LcdWrReg(inf, HWC_MST, cursor_mem_start);
957 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
958 if(SCREEN_MCU == inf->cur_screen->type) {
959 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
963 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
965 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
971 static int hdmi_get_fbscale(void)
974 return hdmi_get_scale();
979 static void hdmi_set_fbscale(struct fb_info *info)
982 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
983 struct rk29fb_screen *screen = inf->cur_screen;
984 struct win0_par *par = info->par;
987 scale = hdmi_get_scale();
990 par->xpos += screen->x_res * (100-scale) / 200;
991 par->ypos += screen->y_res * (100-scale) / 200;
992 par->xsize = par->xsize *scale /100;
993 par->ysize = par->ysize *scale /100;
996 static int win0_blank(int blank_mode, struct fb_info *info)
998 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1000 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1006 case FB_BLANK_UNBLANK:
1007 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1008 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1011 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1012 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1013 #ifdef CONFIG_DDR_RECONFIG
1023 static int win0_set_par(struct fb_info *info)
1025 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1026 struct rk29fb_screen *screen = inf->cur_screen;
1027 struct fb_var_screeninfo *var = &info->var;
1028 struct fb_fix_screeninfo *fix = &info->fix;
1029 struct win0_par *par = info->par;
1030 u32 xact, yact, xvir, yvir, xpos, ypos, ScaleYrgbX,ScaleYrgbY, ScaleCbrX, ScaleCbrY, y_addr,uv_addr;
1031 hdmi_set_fbscale(info);
1032 xact = var->xres; /* visible resolution */
1034 xvir = var->xres_virtual; /* virtual resolution */
1035 yvir = var->yres_virtual;
1036 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
1037 //u32 yact_st = var->yoffset; /* resolution */
1046 y_addr = 0; //user alloc buf addr y
1049 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1053 if(((var->rotate == 270)||(var->rotate == 90) || (var->rotate == 180)) && (inf->video_mode))
1055 #ifdef CONFIG_FB_ROTATE_VIDEO
1056 // if(xact > screen->x_res)
1058 xact = screen->x_res; /* visible resolution */
1059 yact = screen->y_res;
1060 xvir = screen->x_res; /* virtual resolution */
1061 yvir = screen->y_res;
1063 // xact = var->yres; /* visible resolution */
1064 // yact = var->xres;
1065 // xvir = var->yres_virtual; /* virtual resolution */
1066 // yvir = var->xres_virtual;
1068 #else //CONFIG_FB_ROTATE_VIDEO
1069 printk("LCDC not support rotate!\n");
1074 // calculate the display phy address
1075 y_addr = fix->smem_start + par->y_offset;
1076 uv_addr = fix->mmio_start + par->c_offset;
1078 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1079 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1081 switch (par->format)
1084 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1085 ScaleCbrY = CalScaleW0(yact, par->ysize);
1089 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1090 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1093 ScaleCbrX= CalScaleW0(xact, par->xsize);
1094 ScaleCbrY = CalScaleW0(yact, par->ysize);
1100 xpos += (screen->left_margin + screen->hsync_len);
1101 ypos += (screen->upper_margin + screen->vsync_len);
1103 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1104 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1106 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1108 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1109 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1110 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1111 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1112 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1113 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1118 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,
1119 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));
1122 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,
1123 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));
1126 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1127 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(0) |
1128 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1131 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,
1132 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) );
1136 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1142 static int win0_pan( struct fb_info *info )
1144 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1145 // struct fb_var_screeninfo *var0 = &info->var;
1146 struct fb_fix_screeninfo *fix0 = &info->fix;
1147 struct win0_par *par = info->par;
1148 u32 y_addr=0, uv_addr=0;
1150 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1154 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1155 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1157 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1158 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1159 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1161 // enable win0 after the win0 addr is seted
1162 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1168 static int win1_blank(int blank_mode, struct fb_info *info)
1170 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1172 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1178 case FB_BLANK_UNBLANK:
1179 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1182 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1185 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1192 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1193 static void win1_check_work_func(struct work_struct *work)
1195 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
1196 struct fb_info *fb0_inf = inf->fb0;
1199 int blank_data,total_data;
1201 u16 xres_virtual = fb0_inf->var.xres_virtual; //virtual screen size
1202 u16 xpos_virtual = fb0_inf->var.xoffset; //visiable offset in virtual screen
1203 u16 ypos_virtual = fb0_inf->var.yoffset;
1205 int offset = (ypos_virtual*xres_virtual + xpos_virtual)*((inf->fb0_color_deepth || fb0_inf->var.bits_per_pixel==32)? 4:2)/4;
1206 p = (int*)fb0_inf->screen_base + offset;
1207 blank_data = (inf->fb0_color_deepth==32) ? 0xff000000 : 0;
1208 total_data = fb0_inf->var.xres*fb0_inf->var.yres*fb0_inf->var.bits_per_pixel/32;
1210 for(i=0; i < total_data; i++)
1212 if(*p++ != blank_data)
1214 //printk("win1 have no 0 data in %d, total %d\n",i,total_data);
1219 win1_blank(FB_BLANK_POWERDOWN, fb0_inf);
1220 // printk("%s close win1!\n",__func__);
1222 static DECLARE_DELAYED_WORK(rk29_win1_check_work, win1_check_work_func);
1224 static int win1_set_par(struct fb_info *info)
1226 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1227 struct fb_fix_screeninfo *fix = &info->fix;
1228 struct rk29fb_screen *screen = inf->cur_screen;
1229 struct win0_par *par = info->par;
1230 struct fb_var_screeninfo *var = &info->var;
1232 u16 xres_virtual,xpos,ypos;
1233 u8 trspval,trspmode;
1234 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1235 cancel_delayed_work_sync(&rk29_win1_check_work);
1237 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1238 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1240 hdmi_set_fbscale(info);
1241 }else if(((screen->x_res==1920) ))
1243 if(hdmi_get_fbscale() < 100)
1244 par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1246 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1248 xres_virtual = 0; //virtual screen size
1250 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1251 //u16 ypos_virtual = var->yoffset;
1253 xpos = par->xpos; //visiable offset in panel
1256 trspmode = TRSP_CLOSE;
1259 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1261 #ifdef CONFIG_FB_SCALING_OSD
1262 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1263 && (screen->x_res<=1280))
1265 addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1266 xres_virtual = screen->x_res* hdmi_get_fbscale()/100; //virtual screen size
1271 addr = fix->smem_start + par->y_offset;
1272 xres_virtual = var->xres_virtual; //virtual screen size
1274 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1276 xpos += (screen->left_margin + screen->hsync_len);
1277 ypos += (screen->upper_margin + screen->vsync_len);
1279 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1281 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1282 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1284 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1286 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1287 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1289 // enable win1 color key and set the color to black(rgb=0)
1290 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1292 if(1==par->format) //rgb565
1294 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1295 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1299 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1300 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1302 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1305 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1307 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1308 schedule_delayed_work(&rk29_win1_check_work, msecs_to_jiffies(5000));
1314 static int win1_pan( struct fb_info *info )
1316 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1317 struct fb_fix_screeninfo *fix1 = &info->fix;
1318 struct win0_par *par = info->par;
1321 #ifdef CONFIG_FB_SCALING_OSD
1322 struct rk29fb_screen *screen = inf->cur_screen;
1323 struct fb_var_screeninfo *var = &info->var;
1324 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1325 && (screen->x_res<=1280))
1327 addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1332 addr = fix1->smem_start + par->y_offset;
1335 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1337 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1338 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1344 static int fb0_blank(int blank_mode, struct fb_info *info)
1346 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1348 if(inf->video_mode == 1)
1350 win1_blank(blank_mode, info);
1354 win0_blank(blank_mode, info);
1359 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1361 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1362 struct rk29fb_screen *screen = inf->cur_screen;
1363 u16 xpos = (var->nonstd>>8) & 0xfff;
1364 u16 ypos = (var->nonstd>>20) & 0xfff;
1365 u16 xlcd = screen->x_res;
1366 u16 ylcd = screen->y_res;
1368 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1372 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1373 0==var->xres || 0==var->yres || var->xres<16 ||
1374 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1376 printk(">>>>>> fb0_check_var fail 1!!! \n");
1377 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1378 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1379 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1383 if( (var->xoffset+var->xres)>var->xres_virtual ||
1384 (var->yoffset+var->yres)>var->yres_virtual )
1386 printk(">>>>>> fb0_check_var fail 2!!! \n");
1387 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1388 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1389 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1393 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1394 switch(var->bits_per_pixel)
1397 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1398 var->xres = (var->xres + 0x1) & (~0x1);
1399 var->xoffset = (var->xoffset) & (~0x1);
1402 var->bits_per_pixel = 32;
1410 static int fb0_set_par(struct fb_info *info)
1412 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1413 struct fb_var_screeninfo *var = &info->var;
1414 struct fb_fix_screeninfo *fix = &info->fix;
1415 struct rk29fb_screen *screen = inf->cur_screen;
1416 struct win0_par *par = info->par;
1418 u32 offset=0, smem_len=0;
1419 u16 xres_virtual = var->xres_virtual; //virtual screen size
1420 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1421 u16 ypos_virtual = var->yoffset;
1423 #ifdef CONFIG_FB_SCALING_OSD
1424 struct rk29_ipp_req ipp_req;
1428 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1433 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1434 #if !defined(CONFIG_FB_SCALING_OSD)
1435 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1438 switch(var->bits_per_pixel)
1442 //fix->line_length = 2 * xres_virtual;
1443 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1445 #ifdef CONFIG_FB_SCALING_OSD
1446 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1447 ipp_req.src0.fmt = IPP_RGB_565;
1448 ipp_req.dst0.fmt = IPP_RGB_565;
1450 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1455 fix->line_length = 4 * xres_virtual;
1456 #ifdef CONFIG_FB_SCALING_OSD
1457 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1458 ipp_req.src0.fmt = IPP_XRGB_8888;
1459 ipp_req.dst0.fmt = IPP_XRGB_8888;
1461 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1465 smem_len = fix->line_length * var->yres_virtual;
1466 //map_size = PAGE_ALIGN(smem_len);
1468 if (smem_len > fix->smem_len) // buffer need realloc
1470 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1471 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1472 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1476 par->addr_seted = 1;
1477 #if ANDROID_USE_THREE_BUFS
1478 if(0==new_frame_seted) {
1480 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1482 new_frame_seted = 0;
1485 if(inf->video_mode == 1)
1487 #ifdef CONFIG_FB_SCALING_OSD
1488 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1489 && (screen->x_res<=1280))
1493 par->xsize = screen->x_res;
1494 par->ysize = screen->y_res;
1495 par->y_offset = dstoffset;
1497 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1498 ipp_req.src0.w = var->xres;
1499 ipp_req.src0.h = var->yres;
1501 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1502 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1503 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1505 ipp_req.src_vir_w = ipp_req.src0.w;
1506 ipp_req.dst_vir_w = ipp_req.dst0.w;
1507 ipp_req.timeout = 100;
1508 ipp_req.flag = IPP_ROT_0;
1509 //ipp_do_blit(&ipp_req);
1510 ipp_blit_sync(&ipp_req);
1514 par->y_offset = offset;
1515 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1516 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1517 par->xsize = var->xres; //visiable size in panel
1518 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1524 par->y_offset = offset;
1527 par->xsize = screen->x_res;
1528 par->ysize = screen->y_res;
1535 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1538 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1539 struct fb_var_screeninfo *var1 = &info->var;
1540 struct rk29fb_screen *screen = inf->cur_screen;
1541 struct win0_par *par = info->par;
1544 u16 ypos_virtual = var->yoffset;
1545 u16 xpos_virtual = var->xoffset;
1546 #ifdef CONFIG_FB_SCALING_OSD
1547 struct fb_fix_screeninfo *fix = &info->fix;
1548 struct rk29_ipp_req ipp_req;
1551 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1555 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1556 #if !defined(CONFIG_FB_SCALING_OSD)
1557 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1560 switch(var1->bits_per_pixel)
1563 var->xoffset = (var->xoffset) & (~0x1);
1564 #ifdef CONFIG_FB_SCALING_OSD
1565 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1566 ipp_req.src0.fmt = IPP_RGB_565;
1567 ipp_req.dst0.fmt = IPP_RGB_565;
1569 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1572 #ifdef CONFIG_FB_SCALING_OSD
1573 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1574 ipp_req.src0.fmt = IPP_XRGB_8888;
1575 ipp_req.dst0.fmt = IPP_XRGB_8888;
1577 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1583 if(inf->video_mode == 1)
1585 #ifdef CONFIG_FB_SCALING_OSD
1586 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1587 && (screen->x_res<=1280))
1589 par->y_offset = dstoffset;
1591 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1592 ipp_req.src0.w = var->xres;
1593 ipp_req.src0.h = var->yres;
1595 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1596 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1597 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1599 ipp_req.src_vir_w = ipp_req.src0.w;
1600 ipp_req.dst_vir_w = ipp_req.dst0.w;
1601 ipp_req.timeout = 100;
1602 ipp_req.flag = IPP_ROT_0;
1603 //ipp_do_blit(&ipp_req);
1604 ipp_blit_sync(&ipp_req);
1609 par->y_offset = offset;
1614 par->y_offset = offset;
1617 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1618 #if !ANDROID_USE_THREE_BUFS
1619 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1620 if(SCREEN_MCU == inf->cur_screen->type) {
1621 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1625 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1631 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1633 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1634 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1640 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1643 inf->mcu_usetimer = 0;
1646 case FBIOPUT_16OR32:
1648 inf->fb0_color_deepth = arg;
1651 case FBIOPUT_FBPHYADD:
1652 return info->fix.smem_start;
1653 case FBIOGET_OVERLAY_STATE:
1654 return inf->video_mode;
1655 case FBIOGET_SCREEN_STATE:
1656 return inf->cur_screen->type;
1658 case FBIOPUT_SET_CURSOR_EN:
1661 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1663 rk29_set_cursor_en(inf, en);
1666 case FBIOPUT_SET_CURSOR_POS:
1668 struct fbcurpos pos;
1669 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1671 rk29_set_cursor_pos(inf, pos.x , pos.y);
1674 case FBIOPUT_SET_CURSOR_IMG:
1676 char cursor_buf[CURSOR_BUF_SIZE];
1677 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1679 rk29_set_cursor_img(inf, cursor_buf);
1682 case FBIOPUT_SET_CURSOR_CMAP:
1684 struct fb_image img;
1685 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1687 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1690 case FBIOPUT_GET_CURSOR_RESOLUTION:
1693 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1694 if(inf->fb1->var.rotate == 270) {
1695 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1696 panel_size[1] = inf->cur_screen->x_res;
1698 panel_size[0] = inf->cur_screen->x_res;
1699 panel_size[1] = inf->cur_screen->y_res;
1701 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1704 case FBIOPUT_GET_CURSOR_EN:
1706 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1707 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1716 static int fb1_blank(int blank_mode, struct fb_info *info)
1718 win0_blank(blank_mode, info);
1722 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1724 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1725 struct rk29fb_screen *screen = inf->cur_screen;
1727 u32 ScaleYRGBY=0x1000;
1728 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1729 u16 ypos = (var->nonstd>>20) & 0xfff;
1730 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1731 u16 ysize = (var->grayscale>>20) & 0xfff;
1732 u16 xlcd = screen->x_res; //size of panel
1733 u16 ylcd = screen->y_res;
1736 struct hdmi *hdmi = get_hdmi_struct(0);
1739 if((var->rotate == 270)||(var->rotate == 90)) {
1740 #ifdef CONFIG_FB_ROTATE_VIDEO
1741 xlcd = screen->y_res;
1742 ylcd = screen->x_res;
1743 #else //CONFIG_FB_ROTATE_VIDEO
1744 printk("LCDC not support rotate!\n");
1749 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1750 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1751 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1752 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1754 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1758 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1759 0==var->xres || 0==var->yres || var->xres<16 ||
1760 0==xsize || 0==ysize || xsize<16 ||
1761 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1763 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1764 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1765 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1766 var->bits_per_pixel, var->bits_per_pixel);
1770 if( (var->xoffset+var->xres)>var->xres_virtual ||
1771 (var->yoffset+var->yres)>var->yres_virtual ||
1772 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1774 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1775 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1776 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1777 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1781 switch(var->nonstd&0x0f)
1784 switch(var->bits_per_pixel)
1787 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1788 var->xres = (var->xres + 0x1) & (~0x1);
1789 var->xoffset = (var->xoffset) & (~0x1);
1792 var->bits_per_pixel = 32;
1795 var->nonstd &= ~0xc0; //not support I2P in this format
1798 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1799 var->xres = (var->xres + 0x3) & (~0x3);
1800 var->xoffset = (var->xoffset) & (~0x3);
1803 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1804 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1805 var->xres = (var->xres + 0x3) & (~0x3);
1806 var->yres = (var->yres + 0x1) & (~0x1);
1807 var->xoffset = (var->xoffset) & (~0x3);
1808 var->yoffset = (var->yoffset) & (~0x1);
1811 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1812 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1813 var->xres = (var->xres + 0x3) & (~0x3);
1814 var->yres = (var->yres + 0x1) & (~0x1);
1815 var->xoffset = (var->xoffset) & (~0x3);
1816 var->yoffset = (var->yoffset) & (~0x1);
1817 var->nonstd &= ~0xc0; //not support I2P in this format
1821 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1822 var->xres = (var->xres + 0x3) & (~0x3);
1823 var->xoffset = (var->xoffset) & (~0x3);
1824 var->nonstd &= ~0xc0; //not support I2P in this format
1827 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1831 if((var->rotate == 270)||(var->rotate == 90))
1840 ScaleYRGBY = CalScaleW0(yres, ysize);
1842 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1844 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1847 if(inf->video_mode == 1) {
1848 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1850 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1851 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1852 init_completion(&hdmi->complete);
1854 wait_for_completion_interruptible_timeout(&hdmi->complete,
1855 msecs_to_jiffies(10000));
1862 static int fb1_set_par(struct fb_info *info)
1864 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1865 struct rk29fb_screen *screen = inf->cur_screen;
1866 struct fb_var_screeninfo *var = &info->var;
1867 struct fb_fix_screeninfo *fix = &info->fix;
1868 struct win0_par *par = info->par;
1871 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1873 //u32 xact = var->xres; /* visible resolution */
1874 //u32 yact = var->yres;
1875 u32 xvir = var->xres_virtual; /* virtual resolution */
1876 u32 yvir = var->yres_virtual;
1877 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1878 u32 yact_st = var->yoffset; /* resolution */
1880 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1881 u16 ypos = (var->nonstd>>20) & 0xfff;
1882 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1883 u16 ysize = (var->grayscale>>20) & 0xfff;
1885 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1886 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1888 u8 data_format = var->nonstd&0x0f;
1889 // u32 win0_en = var->reserved[2];
1890 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1891 // u32 uv_addr = var->reserved[4];
1893 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1896 if((var->rotate == 270)||(var->rotate == 90))
1898 #ifdef CONFIG_FB_ROTATE_VIDEO
1899 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1900 ypos = (var->nonstd>>8) & 0xfff;
1901 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1902 ysize = (var->grayscale>>8) & 0xfff;
1903 #else //CONFIG_FB_ROTATE_VIDEO
1904 printk("LCDC not support rotate!\n");
1908 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1909 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1910 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1911 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1913 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1914 switch (data_format)
1917 switch(var->bits_per_pixel)
1921 fix->line_length = 2 * xvir;
1922 par->y_offset = (yact_st*xvir + xact_st)*2;
1926 fix->line_length = 4 * xvir;
1927 par->y_offset = (yact_st*xvir + xact_st)*4;
1935 fix->line_length = xvir;
1936 cblen = crlen = (xvir*yvir)/2;
1937 par->y_offset = yact_st*xvir + xact_st;
1938 par->c_offset = yact_st*xvir + xact_st;
1942 fix->line_length = xvir;
1943 cblen = crlen = (xvir*yvir)/4;
1945 par->y_offset = yact_st*xvir + xact_st;
1946 par->c_offset = (yact_st/2)*xvir + xact_st;
1951 fix->line_length = xvir;
1952 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1953 par->c_offset = (yact_st/2)*xvir + xact_st;
1954 cblen = crlen = (xvir*yvir)/4;
1959 fix->line_length = xvir;
1960 par->y_offset = yact_st*xvir + xact_st;
1961 par->c_offset = yact_st*2*xvir + xact_st*2;
1962 cblen = crlen = (xvir*yvir);
1968 smem_len = fix->line_length * yvir + cblen + crlen;
1969 map_size = PAGE_ALIGN(smem_len);
1971 // fix->smem_start = y_addr;
1972 fix->smem_len = smem_len;
1973 // fix->mmio_start = uv_addr;
1975 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1976 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);
1978 par->format = format;
1985 if ( wq_condition2 == 0 ) {
1986 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
1990 #ifdef CONFIG_FB_ROTATE_VIDEO
1991 //need refresh ,zyc add
1992 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
1995 struct rk29_ipp_req ipp_req;
1996 static u32 dstoffset = 0;
1997 static int fb_index = 0;
1999 yuv_phy[0] = last_yuv_phy[0];
2000 yuv_phy[1] = last_yuv_phy[1];
2001 yuv_phy[0] += par->y_offset;
2002 yuv_phy[1] += par->c_offset;
2004 if((var->rotate == 90) ||(var->rotate == 270))
2006 if(var->rotate%360 != 0)
2009 dstoffset = (dstoffset+1)%2;
2010 ipp_req.src0.fmt = 3;
2011 ipp_req.src0.YrgbMst = yuv_phy[0];
2012 ipp_req.src0.CbrMst = yuv_phy[1];
2013 ipp_req.src0.w = var->xres;
2014 ipp_req.src0.h = var->yres;
2016 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2017 ipp_req.dst_vir_w=screen->x_res;
2019 ipp_req.dst0.fmt = 3;
2020 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2021 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2022 // if(var->xres > screen->x_res)
2024 ipp_req.dst0.w = screen->x_res;
2025 ipp_req.dst0.h = screen->y_res;
2027 // ipp_req.dst0.w = var->yres;
2028 // ipp_req.dst0.h = var->xres;
2030 //ipp_req.src_vir_w = ipp_req.src0.w;
2031 //ipp_req.dst_vir_w = ipp_req.dst0.w;
2032 ipp_req.timeout = 100;
2033 if(var->rotate == 90)
2034 ipp_req.flag = IPP_ROT_90;
2035 else if (var->rotate == 180)
2036 ipp_req.flag = IPP_ROT_180;
2037 else if(var->rotate == 270)
2038 ipp_req.flag = IPP_ROT_270;
2039 //ipp_do_blit(&ipp_req);
2040 ipp_blit_sync(&ipp_req);
2041 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2042 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2043 yuv_phy[1] = ipp_req.dst0.CbrMst;
2044 fix->smem_start = yuv_phy[0];
2045 fix->mmio_start = yuv_phy[1];
2050 fix->smem_start = yuv_phy[0];
2051 fix->mmio_start = yuv_phy[1];
2054 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2055 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2056 // enable win0 after the win0 par is seted
2057 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2058 par->addr_seted = 1;
2059 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2060 if(par->addr_seted ) {
2061 unsigned long flags;
2063 local_irq_save(flags);
2064 par->mirror.y_offset = yuv_phy[0];
2065 par->mirror.c_offset = yuv_phy[1];
2066 local_irq_restore(flags);
2069 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2074 has_set_rotate = false;
2079 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2081 struct win0_par *par = info->par;
2082 // enable win0 after the win0 addr is seted
2089 int fb1_open(struct fb_info *info, int user)
2091 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2092 struct win0_par *par = info->par;
2094 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2097 par->addr_seted = 0;
2098 inf->video_mode = 1;
2100 #ifdef CONFIG_FB_ROTATE_VIDEO
2101 //reinitialize the var when open,zyc
2102 last_yuv_phy[0] = 0;
2103 last_yuv_phy[1] = 0;
2107 printk(">>>>>> fb1 has opened! \n");
2111 fb0_set_par(inf->fb0);
2112 fb0_pan_display(&inf->fb0->var, inf->fb0);
2113 win0_blank(FB_BLANK_POWERDOWN, info);
2114 rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2119 int fb1_release(struct fb_info *info, int user)
2121 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2122 struct win0_par *par = info->par;
2123 struct fb_var_screeninfo *var0 = &info->var;
2125 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2126 if(inf->setFlag == 0)
2128 wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2132 inf->video_mode = 0;
2134 par->addr_seted = 0;
2135 //win0_blank(FB_BLANK_POWERDOWN, info);
2136 fb0_set_par(inf->fb0);
2137 fb0_pan_display(&inf->fb0->var, inf->fb0);
2138 win1_blank(FB_BLANK_POWERDOWN, info);
2139 // wait for lcdc stop access memory
2143 info->screen_base = 0;
2144 info->fix.smem_start = 0;
2145 info->fix.smem_len = 0;
2146 // clean the var param
2147 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2148 rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2149 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2150 cancel_delayed_work_sync(&rk29_win1_check_work);
2157 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2159 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2160 struct win0_par *par = info->par;
2161 struct fb_fix_screeninfo *fix0 = &info->fix;
2162 struct fb_var_screeninfo *var = &info->var;
2163 void __user *argp = (void __user *)arg;
2165 #ifdef CONFIG_FB_ROTATE_VIDEO
2166 struct rk29fb_screen *screen = inf->cur_screen;
2167 struct rk29_ipp_req ipp_req;
2168 static u32 dstoffset = 0;
2172 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2173 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2179 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2182 if((var->rotate == 270)||(var->rotate == 90)) {
2183 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2184 panel_size[1] = inf->panel1_info.x_res;
2186 panel_size[0] = inf->panel1_info.x_res;
2187 panel_size[1] = inf->panel1_info.y_res;
2190 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2194 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2197 if (copy_from_user(yuv_phy, argp, 8))
2199 #ifdef CONFIG_FB_ROTATE_VIDEO
2201 if(has_set_rotate == true)
2203 last_yuv_phy[0] = yuv_phy[0];
2204 last_yuv_phy[1] = yuv_phy[1];
2207 fix0->smem_start = yuv_phy[0];
2208 fix0->mmio_start = yuv_phy[1];
2209 yuv_phy[0] += par->y_offset;
2210 yuv_phy[1] += par->c_offset;
2213 if((var->rotate == 90) ||(var->rotate == 270))
2215 if(var->rotate%360 != 0)
2218 #ifdef CONFIG_FB_ROTATE_VIDEO
2219 dstoffset = (dstoffset+1)%2;
2220 ipp_req.src0.fmt = 3;
2221 ipp_req.src0.YrgbMst = yuv_phy[0];
2222 ipp_req.src0.CbrMst = yuv_phy[1];
2223 ipp_req.src0.w = var->xres ;
2224 ipp_req.src0.h = var->yres ;
2225 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2226 ipp_req.dst_vir_w=screen->x_res;
2228 ipp_req.dst0.fmt = 3;
2229 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2230 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2231 // if(var->xres > screen->x_res)
2233 ipp_req.dst0.w = screen->x_res;
2234 ipp_req.dst0.h = screen->y_res;
2236 // ipp_req.dst0.w = var->yres;
2237 // ipp_req.dst0.h = var->xres;
2239 // ipp_req.src_vir_w = ipp_req.src0.w;
2240 // ipp_req.dst_vir_w = ipp_req.dst0.w;
2241 ipp_req.timeout = 100;
2242 if(var->rotate == 90)
2243 ipp_req.flag = IPP_ROT_90;
2244 else if(var->rotate == 180)
2245 ipp_req.flag = IPP_ROT_180;
2246 else if(var->rotate == 270)
2247 ipp_req.flag = IPP_ROT_270;
2248 //ipp_do_blit(&ipp_req);
2249 ipp_blit_sync(&ipp_req);
2250 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2251 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2252 yuv_phy[1] = ipp_req.dst0.CbrMst;
2253 fix0->smem_start = yuv_phy[0];
2254 fix0->mmio_start = yuv_phy[1];
2255 #else //CONFIG_FB_ROTATE_VIDEO
2256 printk("LCDC not support rotate!\n");
2260 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2261 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2262 // enable win0 after the win0 par is seted
2263 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2264 par->addr_seted = 1;
2265 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2266 if(par->par_seted) {
2267 unsigned long flags;
2269 local_irq_save(flags);
2270 par->mirror.y_offset = yuv_phy[0];
2271 par->mirror.c_offset = yuv_phy[1];
2272 local_irq_restore(flags);
2275 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2280 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2281 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2282 #ifdef CONFIG_FB_ROTATE_VIDEO
2284 has_set_rotate = true;
2285 if(arg == 0 || arg==180)
2287 else if (arg == 90 || arg==270)
2289 #else //CONFIG_FB_ROTATE_VIDEO
2290 printk("LCDC not support rotate!\n");
2293 case FB1_IOCTL_SET_WIN0_TOP:
2294 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2295 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2296 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2304 static struct fb_ops fb1_ops = {
2305 .owner = THIS_MODULE,
2306 .fb_open = fb1_open,
2307 .fb_release = fb1_release,
2308 .fb_check_var = fb1_check_var,
2309 .fb_set_par = fb1_set_par,
2310 .fb_blank = fb1_blank,
2311 .fb_pan_display = fb1_pan_display,
2312 .fb_ioctl = fb1_ioctl,
2313 .fb_setcolreg = fb_setcolreg,
2314 .fb_fillrect = cfb_fillrect,
2315 .fb_copyarea = cfb_copyarea,
2316 .fb_imageblit = cfb_imageblit,
2319 static struct fb_ops fb0_ops = {
2320 .owner = THIS_MODULE,
2321 .fb_check_var = fb0_check_var,
2322 .fb_set_par = fb0_set_par,
2323 .fb_blank = fb0_blank,
2324 .fb_pan_display = fb0_pan_display,
2325 .fb_ioctl = fb0_ioctl,
2326 .fb_setcolreg = fb_setcolreg,
2327 .fb_fillrect = cfb_fillrect,
2328 .fb_copyarea = cfb_copyarea,
2329 .fb_imageblit = cfb_imageblit,
2330 //.fb_cursor = rk29_set_cursor,
2333 int fb_get_video_mode(void)
2335 struct rk29fb_inf *inf;
2338 inf = platform_get_drvdata(g_pdev);
2339 return inf->video_mode;
2342 enable: 1, switch to tv or hdmi; 0, switch to lcd
2344 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2346 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2347 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2348 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2350 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2352 if(enable)inf->cur_screen = &inf->panel2_info;
2353 else inf->cur_screen = &inf->panel1_info;
2355 /* Black out, because some display device need clock to standby */
2356 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2357 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2358 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2359 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2360 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2361 wake_lock(&idlelock);
2363 wake_unlock(&idlelock);
2365 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2366 // operate the display_on pin to power down the lcd
2368 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2369 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2371 load_screen(inf->fb0, 0);
2374 fb1_set_par(inf->fb1);
2375 fb0_set_par(inf->fb0);
2376 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2377 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2378 rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2382 static ssize_t dsp_win0_info_read(struct device *device,
2383 struct device_attribute *attr, char *buf)
2386 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2387 struct rk29fb_screen *screen = inf->cur_screen;
2389 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2391 fbprintk("%s\n",__FUNCTION__);
2392 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2393 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2395 xpos -= (screen->left_margin + screen->hsync_len);
2396 ypos -= (screen->upper_margin + screen->vsync_len);
2398 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2399 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2400 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2401 rk29_set_cursor_test(inf->fb0);
2403 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2406 static ssize_t dsp_win0_info_write(struct device *device,
2407 struct device_attribute *attr, const char *buf, size_t count)
2409 printk("%s\n",__FUNCTION__);
2410 printk("%s %x \n",__FUNCTION__,*buf);
2414 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2416 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2418 struct platform_device *pdev = (struct platform_device*)dev_id;
2419 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2420 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2424 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2426 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2428 if(SCREEN_MCU == inf->cur_screen->type)
2430 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2436 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2438 inf->mcu_fmksync = 1;
2439 if(inf->cur_screen->refresh)
2440 inf->cur_screen->refresh(REFRESH_END);
2441 inf->mcu_fmksync = 0;
2450 if(inf->mcu_needflush) {
2451 if(inf->cur_screen->refresh)
2452 inf->cur_screen->refresh(REFRESH_PRE);
2453 inf->mcu_needflush = 0;
2454 inf->mcu_isrcnt = 0;
2455 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2457 if(inf->cur_screen->refresh)
2458 inf->cur_screen->refresh(REFRESH_END);
2462 #if ANDROID_USE_THREE_BUFS
2463 new_frame_seted = 1;
2466 if(waitqueue_active(&par->wait)) {
2467 if (par->mirror.c_offset == 0)
2468 printk("error: no new buffer to display\n");
2470 par->done.y_offset = par->displ.y_offset;
2471 par->done.c_offset = par->displ.c_offset;
2472 par->displ.y_offset = par->mirror.y_offset;
2473 par->displ.c_offset = par->mirror.c_offset;
2474 par->mirror.y_offset = 0;
2475 par->mirror.c_offset = 0;
2477 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2478 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2479 wake_up_interruptible(&par->wait);
2484 wake_up_interruptible(&wq);
2486 rk29fb_irq_notify_ddr();
2490 #ifdef CONFIG_HAS_EARLYSUSPEND
2492 struct suspend_info {
2493 struct early_suspend early_suspend;
2494 struct rk29fb_inf *inf;
2497 static void rk29fb_early_suspend(struct early_suspend *h)
2499 struct suspend_info *info = container_of(h, struct suspend_info,
2502 struct rk29fb_inf *inf = info->inf;
2503 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2505 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2508 printk("inf==0, rk29fb_suspend fail! \n");
2512 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2513 cancel_delayed_work_sync(&rk29_win1_check_work);
2516 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2517 mach_info->io_disable(); //close lcd out
2519 if(inf->cur_screen->standby)
2521 fbprintk(">>>>>> power down the screen! \n");
2522 inf->cur_screen->standby(1);
2525 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2526 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2528 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2529 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2530 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2532 if(!inf->in_suspend)
2534 fbprintk(">>>>>> diable the lcdc clk! \n");
2535 wake_lock(&idlelock);
2537 wake_unlock(&idlelock);
2538 clk_disable(inf->aclk_ddr_lcdc);
2539 clk_disable(inf->aclk_disp_matrix);
2540 clk_disable(inf->hclk_cpu_display);
2541 clk_disable(inf->clk);
2543 clk_disable(inf->dclk);
2546 clk_disable(inf->aclk);
2548 clk_disable(inf->pd_display);
2550 inf->in_suspend = 1;
2554 static void rk29fb_early_resume(struct early_suspend *h)
2556 struct suspend_info *info = container_of(h, struct suspend_info,
2559 struct rk29fb_inf *inf = info->inf;
2560 struct rk29fb_screen *screen = inf->cur_screen;
2561 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2563 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2565 printk("inf==0, rk29fb_resume fail! \n");
2571 inf->in_suspend = 0;
2572 fbprintk(">>>>>> enable the lcdc clk! \n");
2573 clk_enable(inf->pd_display);
2574 clk_enable(inf->aclk_disp_matrix);
2575 clk_enable(inf->hclk_cpu_display);
2576 clk_enable(inf->clk);
2577 clk_enable(inf->aclk_ddr_lcdc);
2580 clk_enable(inf->dclk);
2583 clk_enable(inf->aclk);
2585 usleep_range(100*1000, 100*1000);
2587 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2588 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2589 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2591 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2592 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2594 if(inf->cur_screen->standby)
2596 fbprintk(">>>>>> power on the screen! \n");
2597 inf->cur_screen->standby(0);
2599 usleep_range(10*1000, 10*1000);
2600 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2601 usleep_range(40*1000, 40*1000);
2603 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2604 mach_info->io_enable(); //close lcd out
2608 static struct suspend_info suspend_info = {
2609 .early_suspend.suspend = rk29fb_early_suspend,
2610 .early_suspend.resume = rk29fb_early_resume,
2611 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2614 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2615 static int __devinit rk29fb_probe (struct platform_device *pdev)
2617 struct rk29fb_inf *inf = NULL;
2618 struct resource *res = NULL;
2619 struct resource *mem = NULL;
2620 struct rk29fb_info *mach_info = NULL;
2621 struct rk29fb_screen *screen = NULL;
2622 struct win0_par* par = NULL;
2626 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2628 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2629 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2630 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2633 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2635 goto release_drvdata;
2637 memset(inf, 0, sizeof(struct rk29fb_inf));
2638 platform_set_drvdata(pdev, inf);
2640 mach_info = pdev->dev.platform_data;
2641 /* Fill screen info and set current screen */
2642 fbprintk(">> Fill screen info and set current screen \n");
2643 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2644 hdmi_get_default_resolution(&inf->panel1_info);
2646 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2648 inf->cur_screen = &inf->panel1_info;
2649 screen = inf->cur_screen;
2650 if(SCREEN_NULL==screen->type)
2652 dev_err(&pdev->dev, ">> Please select a display device! \n");
2654 goto release_drvdata;
2657 /* get virtual basic address of lcdc register */
2658 fbprintk(">> get virtual basic address of lcdc register \n");
2659 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2662 dev_err(&pdev->dev, "failed to get memory registers\n");
2664 goto release_drvdata;
2666 inf->reg_phy_base = res->start;
2667 inf->len = (res->end - res->start) + 1;
2668 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2671 dev_err(&pdev->dev, "failed to get memory region\n");
2673 goto release_drvdata;
2675 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2676 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2677 if (inf->reg_vir_base == NULL)
2679 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2681 goto release_drvdata;
2683 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2685 /* Prepare win1 info */
2686 fbprintk(">> Prepare win1 info \n");
2687 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2690 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2693 goto release_win1fb;
2696 par = (struct win0_par*)inf->fb0->par;
2697 strcpy(inf->fb0->fix.id, "fb0");
2698 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2699 inf->fb0->fix.type_aux = 0;
2700 inf->fb0->fix.xpanstep = 1;
2701 inf->fb0->fix.ypanstep = 1;
2702 inf->fb0->fix.ywrapstep = 0;
2703 inf->fb0->fix.accel = FB_ACCEL_NONE;
2704 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2705 inf->fb0->fix.smem_len = 0;
2706 inf->fb0->fix.line_length = 0;
2707 inf->fb0->fix.smem_start = 0;
2709 inf->fb0->var.xres = screen->x_res;
2710 inf->fb0->var.yres = screen->y_res;
2711 inf->fb0->var.bits_per_pixel = 16;
2712 inf->fb0_color_deepth = 0;
2713 inf->fb0->var.xres_virtual = screen->x_res;
2714 inf->fb0->var.yres_virtual = screen->y_res;
2715 inf->fb0->var.width = screen->width;
2716 inf->fb0->var.height = screen->height;
2717 inf->fb0->var.pixclock = screen->pixclock;
2718 inf->fb0->var.left_margin = screen->left_margin;
2719 inf->fb0->var.right_margin = screen->right_margin;
2720 inf->fb0->var.upper_margin = screen->upper_margin;
2721 inf->fb0->var.lower_margin = screen->lower_margin;
2722 inf->fb0->var.vsync_len = screen->vsync_len;
2723 inf->fb0->var.hsync_len = screen->hsync_len;
2724 inf->fb0->var.red = def_rgb_16.red;
2725 inf->fb0->var.green = def_rgb_16.green;
2726 inf->fb0->var.blue = def_rgb_16.blue;
2727 inf->fb0->var.transp = def_rgb_16.transp;
2729 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2730 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2731 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2732 inf->fb0->var.accel_flags = 0;
2733 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2735 inf->fb0->fbops = &fb0_ops;
2736 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2737 inf->fb0->pseudo_palette = par->pseudo_pal;
2738 inf->fb0->screen_base = 0;
2740 memset(par, 0, sizeof(struct win0_par));
2742 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2746 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2748 /* alloc win1 buf */
2749 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2752 dev_err(&pdev->dev, "failed to get win1 memory \n");
2754 goto release_win1fb;
2756 inf->fb0->fix.smem_start = res->start;
2757 inf->fb0->fix.smem_len = res->end - res->start + 1;
2758 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2759 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2761 #ifdef CONFIG_FB_WORK_IPP
2762 /* alloc win1 ipp buf */
2763 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2766 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2768 goto release_win1fb;
2770 inf->fb0->fix.mmio_start = res->start;
2771 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2774 /* Prepare win0 info */
2775 fbprintk(">> Prepare win0 info \n");
2776 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2779 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2782 goto release_win0fb;
2785 par = (struct win0_par*)inf->fb1->par;
2787 strcpy(inf->fb1->fix.id, "fb1");
2788 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2789 inf->fb1->fix.type_aux = 0;
2790 inf->fb1->fix.xpanstep = 1;
2791 inf->fb1->fix.ypanstep = 1;
2792 inf->fb1->fix.ywrapstep = 0;
2793 inf->fb1->fix.accel = FB_ACCEL_NONE;
2794 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2795 inf->fb1->fix.smem_len = 0;
2796 inf->fb1->fix.line_length = 0;
2797 inf->fb1->fix.smem_start = 0;
2799 inf->fb1->var.xres = screen->x_res;
2800 inf->fb1->var.yres = screen->y_res;
2801 inf->fb1->var.bits_per_pixel = 16;
2802 inf->fb1->var.xres_virtual = screen->x_res;
2803 inf->fb1->var.yres_virtual = screen->y_res;
2804 inf->fb1->var.width = screen->width;
2805 inf->fb1->var.height = screen->height;
2806 inf->fb1->var.pixclock = screen->pixclock;
2807 inf->fb1->var.left_margin = screen->left_margin;
2808 inf->fb1->var.right_margin = screen->right_margin;
2809 inf->fb1->var.upper_margin = screen->upper_margin;
2810 inf->fb1->var.lower_margin = screen->lower_margin;
2811 inf->fb1->var.vsync_len = screen->vsync_len;
2812 inf->fb1->var.hsync_len = screen->hsync_len;
2813 inf->fb1->var.red = def_rgb_16.red;
2814 inf->fb1->var.green = def_rgb_16.green;
2815 inf->fb1->var.blue = def_rgb_16.blue;
2816 inf->fb1->var.transp = def_rgb_16.transp;
2818 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2819 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2820 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2821 inf->fb1->var.accel_flags = 0;
2822 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2824 inf->fb1->fbops = &fb1_ops;
2825 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2826 inf->fb1->pseudo_palette = par->pseudo_pal;
2827 inf->fb1->screen_base = 0;
2829 memset(par, 0, sizeof(struct win0_par));
2831 init_waitqueue_head(&par->wait);
2833 /* Init all lcdc and lcd before register_framebuffer. */
2834 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2835 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2836 init_lcdc(inf->fb0);
2838 #if 0 //def CONFIG_CPU_FREQ
2839 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2840 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2842 fbprintk("got clock\n");
2846 struct rk29_fb_setting_info fb_setting;
2847 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2849 fb_setting.data_num = 24;
2851 else if(OUT_P666 == inf->cur_screen->face )
2853 fb_setting.data_num = 18;
2857 fb_setting.data_num = 16;
2859 fb_setting.den_en = 1;
2860 fb_setting.vsync_en = 1;
2861 fb_setting.disp_on_en = 1;
2862 fb_setting.standby_en = 1;
2863 if( inf->cur_screen->mcu_usefmk )
2864 fb_setting.mcu_fmk_en =1;
2865 mach_info->io_init(&fb_setting);
2868 //set_lcd_pin(pdev, 1);
2871 inf->mcu_usetimer = 1;
2872 inf->mcu_fmksync = 0;
2873 load_screen(inf->fb0, 1);
2875 /* Register framebuffer(fb0 & fb1) */
2876 fbprintk(">> Register framebuffer(fb0) \n");
2877 ret = register_framebuffer(inf->fb0);
2880 printk(">> fb0 register_framebuffer fail!\n");
2882 goto release_win0fb;
2884 fbprintk(">> Register framebuffer(fb1) \n");
2886 ret = register_framebuffer(inf->fb1);
2889 printk(">> fb1 register_framebuffer fail!\n");
2891 goto unregister_win1fb;
2894 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2897 printk(">> fb1 dsp win0 info device_create_file err\n");
2900 #ifdef CONFIG_HAS_EARLYSUSPEND
2901 suspend_info.inf = inf;
2902 register_early_suspend(&suspend_info.early_suspend);
2905 /* get and request irq */
2906 fbprintk(">> get and request irq \n");
2907 irq = platform_get_irq(pdev, 0);
2909 dev_err(&pdev->dev, "no irq for device\n");
2911 goto unregister_win1fb;
2913 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2915 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2920 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2922 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2925 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2931 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2932 fb0_set_par(inf->fb0);
2933 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2934 /* Start display and show logo on boot */
2935 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2936 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2937 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2941 printk(" %s ok\n", __FUNCTION__);
2946 free_irq(irq, pdev);
2948 unregister_framebuffer(inf->fb0);
2951 framebuffer_release(inf->fb1);
2955 fb_dealloc_cmap(&inf->fb0->cmap);
2958 framebuffer_release(inf->fb0);
2961 if(inf && inf->reg_vir_base)
2962 iounmap(inf->reg_vir_base);
2964 release_mem_region(inf->reg_phy_base, inf->len);
2967 platform_set_drvdata(pdev, NULL);
2971 static int __devexit rk29fb_remove(struct platform_device *pdev)
2973 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2974 struct fb_info *info = NULL;
2976 struct rk29fb_info *mach_info = NULL;
2979 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2982 printk("inf==0, rk29_fb_remove fail! \n");
2985 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2987 irq = platform_get_irq(pdev, 0);
2990 free_irq(irq, pdev);
2993 mach_info = pdev->dev.platform_data;
2994 if(mach_info->mcu_fmk_pin)
2996 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2999 if(mach_info->io_disable)
3000 mach_info->io_disable(); //close lcd out
3004 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
3006 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
3009 //rk29fb_suspend(pdev, msg);
3010 // unmap memory and release framebuffer
3013 if (info->screen_base) {
3014 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3015 info->screen_base = 0;
3016 info->fix.smem_start = 0;
3017 info->fix.smem_len = 0;
3019 unregister_framebuffer(inf->fb1);
3020 framebuffer_release(inf->fb1);
3025 if (info->screen_base) {
3026 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3027 info->screen_base = 0;
3028 info->fix.smem_start = 0;
3029 info->fix.smem_len = 0;
3031 unregister_framebuffer(inf->fb0);
3032 framebuffer_release(inf->fb0);
3036 #if 0 //def CONFIG_CPU_FREQ
3037 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3044 clk_disable(inf->clk);
3050 clk_disable(inf->dclk);
3056 platform_set_drvdata(pdev, NULL);
3061 static void rk29fb_shutdown(struct platform_device *pdev)
3063 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3064 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3066 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3068 if(mach_info->io_disable)
3069 mach_info->io_disable(); //close lcd out
3071 if(!inf->in_suspend)
3073 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3074 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3075 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3077 clk_disable(inf->aclk_ddr_lcdc);
3078 clk_disable(inf->aclk_disp_matrix);
3079 clk_disable(inf->hclk_cpu_display);
3080 clk_disable(inf->clk);
3082 clk_disable(inf->dclk);
3085 clk_disable(inf->aclk);
3087 clk_disable(inf->pd_display);
3088 //pmu_set_power_domain(PD_DISPLAY, 0);
3089 inf->in_suspend = 1;
3094 static struct platform_driver rk29fb_driver = {
3095 .probe = rk29fb_probe,
3096 .remove = __devexit_p(rk29fb_remove),
3099 .owner = THIS_MODULE,
3101 .shutdown = rk29fb_shutdown,
3104 static int __init rk29fb_init(void)
3106 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3107 return platform_driver_register(&rk29fb_driver);
3110 static void __exit rk29fb_exit(void)
3112 platform_driver_unregister(&rk29fb_driver);
3115 fs_initcall(rk29fb_init);
3116 module_exit(rk29fb_exit);
3119 MODULE_AUTHOR(" zyw@rock-chips.com");
3120 MODULE_DESCRIPTION("Driver for rk29 fb device");
3121 MODULE_LICENSE("GPL");