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 unsigned long bitperpixel;
257 unsigned long src_uv;
258 unsigned long dst_width;
259 unsigned long dst_height;
260 //struct mutex fb_lock;
261 volatile unsigned long fb_lock;
265 struct wimo_fb_info wimo_info;
266 unsigned char* ui_buffer;
267 unsigned char* ui_buffer_map;
268 //unsigned char* overlay_buffer;
269 //unsigned char* overlay_buffer_map;
272 struct platform_device *g_pdev = NULL;
273 //static int win1fb_set_par(struct fb_info *info);
276 #define CHK_SUSPEND(inf) \
277 if(inf->in_suspend) { \
278 fbprintk(">>>>>> fb is in suspend! return! \n"); \
282 #define CHK_SUSPEND(inf)
284 static DECLARE_WAIT_QUEUE_HEAD(fb0_wait_queue);
285 static volatile int idle_condition = 1; //1:idel, 0:busy
287 static DECLARE_WAIT_QUEUE_HEAD(wq);
288 static int wq_condition = 0;
289 static int wq_condition2 = 0;
290 static int fb1_open_init = 0;
291 #if ANDROID_USE_THREE_BUFS
292 static int new_frame_seted = 1;
294 static struct wake_lock idlelock; /* only for fb */
295 #ifdef CONFIG_FB_ROTATE_VIDEO
297 static bool has_set_rotate;
298 static u32 last_yuv_phy[2] = {0,0};
300 int fb0_first_buff_bits = 32;
301 int fb0_second_buff_bits = 32;
302 int fb_compose_layer_count = 0;
303 static BLOCKING_NOTIFIER_HEAD(rk29fb_notifier_list);
304 int rk29fb_register_notifier(struct notifier_block *nb)
308 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
310 if (inf->cur_screen && inf->cur_screen->type == SCREEN_HDMI)
311 nb->notifier_call(nb, RK29FB_EVENT_HDMI_ON, inf->cur_screen);
312 if (inf->fb1 && inf->fb1->par) {
313 struct win0_par *par = inf->fb1->par;
315 nb->notifier_call(nb, RK29FB_EVENT_FB1_ON, inf->cur_screen);
319 ret = blocking_notifier_chain_register(&rk29fb_notifier_list, nb);
324 int rk29fb_unregister_notifier(struct notifier_block *nb)
326 return blocking_notifier_chain_unregister(&rk29fb_notifier_list, nb);
329 static int rk29fb_notify(struct rk29fb_inf *inf, unsigned long event)
331 return blocking_notifier_call_chain(&rk29fb_notifier_list, event, inf->cur_screen);
334 int mcu_do_refresh(struct rk29fb_inf *inf)
336 if(inf->mcu_stopflush) return 0;
338 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
343 inf->mcu_needflush = 1;
347 // not use frame mark
348 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
350 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
352 inf->mcu_needflush = 1;
356 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
357 inf->mcu_needflush = 0;
359 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
366 void mcutimer_callback(unsigned long arg)
368 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
369 static int waitcnt = 0;
371 mod_timer(&inf->mcutimer, jiffies + HZ/10);
373 switch(inf->mcu_status)
376 inf->mcu_status = MS_MCU;
379 if(inf->mcu_usetimer) mcu_do_refresh(inf);
382 inf->mcu_status = MS_EWAITEND;
390 inf->mcu_status = MS_EEND;
394 inf->mcu_status = MS_MCU;
397 inf->mcu_status = MS_MCU;
402 int mcu_refresh(struct rk29fb_inf *inf)
404 static int mcutimer_inited = 0;
406 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
411 init_timer(&inf->mcutimer);
412 inf->mcutimer.function = mcutimer_callback;
413 inf->mcutimer.expires = jiffies + HZ/5;
414 inf->mcu_status = MS_IDLE;
415 add_timer(&inf->mcutimer);
418 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
423 int mcu_ioctl(unsigned int cmd, unsigned long arg)
425 struct rk29fb_inf *inf = NULL;
426 if(!g_pdev) return -1;
428 inf = dev_get_drvdata(&g_pdev->dev);
433 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
434 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
435 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
439 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
440 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
444 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
445 LcdWrReg(inf, REG_CFG_DONE, 0x01);
455 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
457 struct platform_device *pdev = (struct platform_device*)dev_id;
458 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
459 struct rk29fb_screen *screen;
461 if(!inf) return IRQ_HANDLED;
463 screen = inf->cur_screen;
465 if(0==screen->mcu_usefmk) {
469 if(inf->mcu_fmksync == 1)
472 inf->mcu_fmksync = 1;
473 if(inf->mcu_needflush)
475 inf->mcu_needflush = 0;
477 if(inf->cur_screen->refresh)
478 inf->cur_screen->refresh(REFRESH_PRE);
479 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
481 inf->mcu_fmksync = 0;
486 int init_lcdc(struct fb_info *info)
488 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
491 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
493 inf->clk = clk_get(NULL, "hclk_lcdc");
494 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
495 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
496 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
497 inf->pd_display = clk_get(NULL, "pd_display");
498 if ((IS_ERR(inf->clk)) ||
499 (IS_ERR(inf->aclk_ddr_lcdc)) ||
500 (IS_ERR(inf->aclk_disp_matrix)) ||
501 (IS_ERR(inf->hclk_cpu_display)) ||
502 (IS_ERR(inf->pd_display)))
504 printk(KERN_ERR "failed to get lcdc_hclk source\n");
505 return PTR_ERR(inf->clk);
507 clk_enable(inf->aclk_disp_matrix);
508 clk_enable(inf->hclk_cpu_display);
509 clk_enable(inf->clk);
510 clk_enable(inf->pd_display);
511 //pmu_set_power_domain(PD_DISPLAY, 1);
512 clk_enable(inf->aclk_ddr_lcdc);
514 // set AHB access rule and disable all windows
515 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
516 LcdWrReg(inf, SWAP_CTRL, 0);
517 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
518 LcdWrReg(inf, AXI_MS_ID, 0x54321);
520 // and mcu holdmode; and set win1 top.
521 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
522 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
524 // disable blank out, black out, tristate out, yuv2rgb bypass
525 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
526 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
527 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
528 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
531 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
532 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
534 LcdWrReg(inf, DSP_CTRL1, 0);
536 // initialize all interrupt
537 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
539 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
541 LcdWrReg(inf, INT_STATUS, clr | msk);
543 // let above to take effect
544 LcdWrReg(inf, REG_CFG_DONE, 0x01);
549 void load_screen(struct fb_info *info, bool initscreen)
552 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
553 struct rk29fb_screen *screen = inf->cur_screen;
555 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
556 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
557 u16 x_res = screen->x_res, y_res = screen->y_res;
558 u32 aclk_rate = 150000000;
561 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
565 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
567 // set the rgb or mcu
568 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
570 // set out format and mcu timing
571 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
572 if(mcu_total>31) mcu_total = 31;
573 if(mcu_total<3) mcu_total = 3;
574 mcu_rwstart = (mcu_total+1)/4 - 1;
575 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
576 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
577 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
579 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
580 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
582 LcdMskReg(inf, MCU_TIMING_CTRL,
583 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
584 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
585 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
586 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
587 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
590 // set synchronous pin polarity and data pin swap rule
591 switch (screen->face)
595 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
599 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
603 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
607 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
611 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
612 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
615 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
616 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
621 LcdMskReg(inf, DSP_CTRL0,
622 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
623 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
624 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
625 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
628 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
630 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
631 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));
633 // set horizontal & vertical out timing
634 if(SCREEN_MCU==inf->cur_screen->type)
636 right_margin = x_res/6;
639 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
640 screen->hsync_len , screen->left_margin , x_res , right_margin );
641 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
642 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
643 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
644 v_BIT12HI(screen->hsync_len + screen->left_margin));
646 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
647 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
648 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
649 v_BIT11HI(screen->vsync_len + screen->upper_margin));
651 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
652 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
654 // let above to take effect
655 LcdWrReg(inf, REG_CFG_DONE, 0x01);
657 inf->dclk = clk_get(NULL, "dclk_lcdc");
658 if (IS_ERR(inf->dclk))
660 printk(KERN_ERR "failed to get lcd dclock source\n");
664 inf->aclk = clk_get(NULL, "aclk_lcdc");
665 if (IS_ERR(inf->aclk))
667 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
670 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
671 if (IS_ERR(inf->aclk_parent))
673 printk(KERN_ERR "failed to get lcd clock parent source\n");
678 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
680 if(initscreen == 0) //not init
682 clk_disable(inf->dclk);
683 // clk_disable(inf->aclk);
686 // clk_disable(inf->aclk_ddr_lcdc);
687 // clk_disable(inf->aclk_disp_matrix);
688 // clk_disable(inf->hclk_cpu_display);
690 // clk_disable(inf->clk);
693 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
695 ret = clk_set_rate(inf->dclk, screen->pixclock);
698 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
700 inf->fb0->var.pixclock = inf->fb1->var.pixclock = div_u64(1000000000000llu, clk_get_rate(inf->dclk));
703 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
704 if(screen->lcdc_aclk){
705 aclk_rate = screen->lcdc_aclk;
707 ret = clk_set_rate(inf->aclk, aclk_rate);
709 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
711 clk_enable(inf->aclk);
713 // clk_enable(inf->aclk_ddr_lcdc);
714 // clk_enable(inf->aclk_disp_matrix);
715 // clk_enable(inf->hclk_cpu_display);
716 // clk_enable(inf->clk);
717 clk_enable(inf->dclk);
725 #if 0 //def CONFIG_CPU_FREQ
727 * CPU clock speed change handler. We need to adjust the LCD timing
728 * parameters when the CPU clock is adjusted by the power management
731 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
734 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
736 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
737 struct rk29fb_screen *screen = inf->cur_screen;
742 case CPUFREQ_PRECHANGE:
744 case CPUFREQ_POSTCHANGE:
746 dclk_rate = screen->pixclock * 1000000;
748 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
750 clk_set_rate(inf->dclk_divider, dclk_rate);
758 static inline unsigned int chan_to_field(unsigned int chan,
759 struct fb_bitfield *bf)
762 chan >>= 16 - bf->length;
763 return chan << bf->offset;
766 static int fb_setcolreg(unsigned regno,
767 unsigned red, unsigned green, unsigned blue,
768 unsigned transp, struct fb_info *info)
771 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
773 switch (info->fix.visual) {
774 case FB_VISUAL_TRUECOLOR:
775 /* true-colour, use pseudo-palette */
777 u32 *pal = info->pseudo_palette;
778 val = chan_to_field(red, &info->var.red);
779 val |= chan_to_field(green, &info->var.green);
780 val |= chan_to_field(blue, &info->var.blue);
785 return -1; /* unknown type */
791 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
794 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
796 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
798 LcdWrReg(inf, REG_CFG_DONE, 0x01);
802 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
804 struct rk29fb_screen *screen = inf->cur_screen;
807 if (x >= 0x800 || y >= 0x800 )
809 //printk("%s: %08x,%08x \n",__func__, x, y);
810 x += (screen->left_margin + screen->hsync_len);
811 y += (screen->upper_margin + screen->vsync_len);
812 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
813 LcdWrReg(inf, REG_CFG_DONE, 0x01);
818 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
820 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
821 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
822 LcdWrReg(inf, REG_CFG_DONE, 0x01);
826 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
827 int rk29_set_cursor_img_transform(char *data)
830 char *dst = (char*)rk29_cursor_buf;
831 unsigned char dmsk = 0;
832 unsigned int op,shift,offset;
834 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
835 * clears it to transparent then combines the cursor
836 * shape plane with the colour plane to set the
838 for (y = 0; y < 32; y++)
840 for (x = 0; x < 32; x++)
847 op = (dmsk & 0x80) ? 2 : 3;
850 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
860 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
864 rk29_set_cursor_img_transform(data);
868 rk29_set_cursor_img_transform(cursor_img);
870 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
871 //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
872 LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
874 LcdWrReg(inf, REG_CFG_DONE, 0x01);
879 int rk29_set_cursor_test(struct fb_info *info)
881 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
882 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
883 rk29_set_cursor_pos(inf, 0, 0);
884 rk29_set_cursor_img(inf, 0);
885 rk29_set_cursor_en(inf, 1);
890 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
892 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
894 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
896 /* check not being asked to exceed capabilities */
898 if (cursor->image.width > 32)
901 if (cursor->image.height > 32)
904 if (cursor->image.depth > 1)
908 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
910 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
913 if (cursor->set & FB_CUR_SETPOS)
915 unsigned int x = cursor->image.dx;
916 unsigned int y = cursor->image.dy;
918 if (x >= 0x800 || y >= 0x800 )
920 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
924 if (cursor->set & FB_CUR_SETCMAP)
926 unsigned int bg_col = cursor->image.bg_color;
927 unsigned int fg_col = cursor->image.fg_color;
929 fbprintk("%s: update cmap (%08x,%08x)\n",
930 __func__, bg_col, fg_col);
932 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
933 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));
935 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
936 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));
939 if ((cursor->set & FB_CUR_SETSIZE ||
940 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
941 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
943 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
944 * clears it to transparent then combines the cursor
945 * shape plane with the colour plane to set the
948 const unsigned char *pcol = cursor->image.data;
949 const unsigned char *pmsk = cursor->mask;
951 unsigned long cursor_mem_start;
952 unsigned char dcol = 0;
953 unsigned char dmsk = 0;
956 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
957 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
959 fbprintk("%s: setting shape (%d,%d)\n",
960 __func__, cursor->image.width, cursor->image.height);
962 memset(dst, 0, CURSOR_BUF_SIZE);
964 for (y = 0; y < cursor->image.height; y++)
966 for (x = 0; x < cursor->image.width; x++)
977 op = (dcol & 1) ? 1 : 3;
978 op <<= ((x % 4) * 2);
979 *(u8*)(dst+(x/4)) |= op;
984 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
985 LcdWrReg(inf, HWC_MST, cursor_mem_start);
986 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
987 if(SCREEN_MCU == inf->cur_screen->type) {
988 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
992 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
994 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
1000 static int hdmi_get_fbscale(void)
1003 return hdmi_get_scale();
1008 static void hdmi_set_fbscale(struct fb_info *info)
1011 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1012 struct rk29fb_screen *screen = inf->cur_screen;
1013 struct win0_par *par = info->par;
1016 scale = hdmi_get_scale();
1019 par->xpos += screen->x_res * (100-scale) / 200;
1020 par->ypos += screen->y_res * (100-scale) / 200;
1021 par->xsize = par->xsize *scale /100;
1022 par->ysize = par->ysize *scale /100;
1025 static int win0_blank(int blank_mode, struct fb_info *info)
1027 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1029 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1035 case FB_BLANK_UNBLANK:
1036 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1037 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1039 case FB_BLANK_NORMAL:
1040 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1043 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1044 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1045 #ifdef CONFIG_DDR_RECONFIG
1055 static int win0_set_par(struct fb_info *info)
1057 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1058 struct rk29fb_screen *screen = inf->cur_screen;
1059 struct fb_var_screeninfo *var = &info->var;
1060 struct fb_fix_screeninfo *fix = &info->fix;
1061 struct win0_par *par = info->par;
1062 u32 xact, yact, xvir, yvir, xpos, ypos, ScaleYrgbX,ScaleYrgbY, ScaleCbrX, ScaleCbrY, y_addr,uv_addr;
1063 hdmi_set_fbscale(info);
1064 xact = var->xres; /* visible resolution */
1066 xvir = var->xres_virtual; /* virtual resolution */
1067 yvir = var->yres_virtual;
1068 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
1069 //u32 yact_st = var->yoffset; /* resolution */
1078 y_addr = 0; //user alloc buf addr y
1081 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1085 if((var->rotate%360!=0)&& (inf->video_mode))
1087 #ifdef CONFIG_FB_ROTATE_VIDEO
1088 if(xact > screen->x_res)
1090 xact = screen->x_res; /* visible resolution */
1091 yact = screen->y_res;
1092 xvir = screen->x_res; /* virtual resolution */
1093 yvir = screen->y_res;
1095 xact = var->xres; /* visible resolution */
1097 xvir = var->xres_virtual; /* virtual resolution */
1098 yvir = var->yres_virtual;
1099 printk("xact=%d yact =%d \n",xact,yact);
1101 #else //CONFIG_FB_ROTATE_VIDEO
1102 printk("LCDC not support rotate!\n");
1107 // calculate the display phy address
1108 y_addr = fix->smem_start + par->y_offset;
1109 uv_addr = fix->mmio_start + par->c_offset;
1111 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1112 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1114 switch (par->format)
1117 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1118 ScaleCbrY = CalScaleW0(yact, par->ysize);
1122 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1123 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1126 ScaleCbrX= CalScaleW0(xact, par->xsize);
1127 ScaleCbrY = CalScaleW0(yact, par->ysize);
1133 xpos += (screen->left_margin + screen->hsync_len);
1134 ypos += (screen->upper_margin + screen->vsync_len);
1136 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1137 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1139 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1141 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1142 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1143 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1144 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1145 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1146 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1151 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,
1152 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));
1155 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,
1156 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));
1159 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,
1160 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) |
1161 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1164 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,
1165 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) );
1169 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1175 static int win0_pan( struct fb_info *info )
1177 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1178 // struct fb_var_screeninfo *var0 = &info->var;
1179 struct fb_fix_screeninfo *fix0 = &info->fix;
1180 struct win0_par *par = info->par;
1181 u32 y_addr=0, uv_addr=0;
1183 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1187 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1188 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1190 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1191 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1192 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1194 // enable win0 after the win0 addr is seted
1195 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1201 static int win1_blank(int blank_mode, struct fb_info *info)
1203 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1205 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1211 case FB_BLANK_UNBLANK:
1212 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1213 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1215 case FB_BLANK_NORMAL:
1216 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1219 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1220 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1230 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1231 static void win1_check_work_func(struct work_struct *work)
1233 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
1234 struct fb_info *fb0_inf = inf->fb0;
1235 struct fb_var_screeninfo *var = &fb0_inf->var;
1238 int blank_data,total_data;
1240 u16 xres_virtual = fb0_inf->var.xres_virtual; //virtual screen size
1241 u16 xpos_virtual = fb0_inf->var.xoffset; //visiable offset in virtual screen
1242 u16 ypos_virtual = fb0_inf->var.yoffset;
1244 int offset = 0;//(ypos_virtual*xres_virtual + xpos_virtual)*((inf->fb0_color_deepth || fb0_inf->var.bits_per_pixel==32)? 4:2)/4;
1245 switch(var->bits_per_pixel)
1249 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1250 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1251 offset -= var->yres * var->xres *2;
1255 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1256 if(ypos_virtual >= 2*var->yres)
1259 if(ypos_virtual == 3*var->yres)
1261 offset -= var->yres * var->xres *2;
1266 p = (u32)fb0_inf->screen_base + offset;
1267 blank_data = (inf->fb0_color_deepth==32) ? 0xff000000 : 0;
1268 total_data = fb0_inf->var.xres * fb0_inf->var.yres / (format+1);
1270 // printk("var->bits_per_pixel=%d,ypos_virtual=%d, var->yres=%d,offset=%d,total_data=%d\n",var->bits_per_pixel,ypos_virtual,var->yres,offset,total_data);
1272 for(i=0; i < total_data; i++)
1274 if(*p++ != blank_data)
1276 //printk("win1 have no 0 data in %d, total %d\n",i,total_data);
1281 win1_blank(FB_BLANK_POWERDOWN, fb0_inf);
1282 // printk("%s close win1!\n",__func__);
1284 static DECLARE_DELAYED_WORK(rk29_win1_check_work, win1_check_work_func);
1286 static int win1_set_par(struct fb_info *info)
1288 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1289 struct fb_fix_screeninfo *fix = &info->fix;
1290 struct rk29fb_screen *screen = inf->cur_screen;
1291 struct win0_par *par = info->par;
1292 struct fb_var_screeninfo *var = &info->var;
1294 u16 xres_virtual,xpos,ypos;
1295 u8 trspval,trspmode;
1296 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1297 cancel_delayed_work_sync(&rk29_win1_check_work);
1299 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1300 #ifndef CONFIG_FB_SCALING_OSD_1080P
1301 && !((screen->x_res>1280) && (var->bits_per_pixel == 32))
1305 hdmi_set_fbscale(info);
1307 #ifndef CONFIG_FB_SCALING_OSD_1080P
1308 else if(((screen->x_res==1920) ))
1310 if(hdmi_get_fbscale() < 100)
1311 par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1314 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1316 xres_virtual = 0; //virtual screen size
1318 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1319 //u16 ypos_virtual = var->yoffset;
1321 xpos = par->xpos; //visiable offset in panel
1324 trspmode = TRSP_CLOSE;
1327 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1329 #ifdef CONFIG_FB_SCALING_OSD
1330 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1331 #ifndef CONFIG_FB_SCALING_OSD_1080P
1332 && (screen->x_res<=1280)
1336 addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1337 xres_virtual = screen->x_res* hdmi_get_fbscale()/100; //virtual screen size
1342 addr = fix->smem_start + par->y_offset;
1343 xres_virtual = var->xres_virtual; //virtual screen size
1345 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(fb1_open_init?0:1)|v_W1_FORMAT(par->format));
1347 xpos += (screen->left_margin + screen->hsync_len);
1348 ypos += (screen->upper_margin + screen->vsync_len);
1350 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1352 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1353 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1355 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1357 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1358 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1360 // enable win1 color key and set the color to black(rgb=0)
1361 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1363 if(1==par->format) //rgb565
1365 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1366 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1370 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1371 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1373 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1376 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1378 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1379 schedule_delayed_work(&rk29_win1_check_work, msecs_to_jiffies(5000));
1385 static int win1_pan( struct fb_info *info )
1387 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1388 struct fb_fix_screeninfo *fix1 = &info->fix;
1389 struct win0_par *par = info->par;
1392 #ifdef CONFIG_FB_SCALING_OSD
1393 struct rk29fb_screen *screen = inf->cur_screen;
1394 struct fb_var_screeninfo *var = &info->var;
1395 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1396 #ifndef CONFIG_FB_SCALING_OSD_1080P
1397 && (screen->x_res<=1280)
1401 addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1406 addr = fix1->smem_start + par->y_offset;
1409 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1411 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1412 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1418 static int fb0_blank(int blank_mode, struct fb_info *info)
1420 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1422 if(inf->video_mode == 1)
1424 win1_blank(blank_mode, info);
1428 win0_blank(blank_mode, info);
1433 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1435 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1436 struct rk29fb_screen *screen = inf->cur_screen;
1437 u16 xpos = (var->nonstd>>8) & 0xfff;
1438 u16 ypos = (var->nonstd>>20) & 0xfff;
1439 u16 xlcd = screen->x_res;
1440 u16 ylcd = screen->y_res;
1442 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1446 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1447 0==var->xres || 0==var->yres || var->xres<16 ||
1448 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1450 printk(">>>>>> fb0_check_var fail 1!!! \n");
1451 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1452 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1453 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1457 if( (var->xoffset+var->xres)>var->xres_virtual ||
1458 (var->yoffset+var->yres)>var->yres_virtual*2 )
1460 printk(">>>>>> fb0_check_var fail 2!!! \n");
1461 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1462 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1463 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1467 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1468 switch(var->bits_per_pixel)
1471 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1472 var->xres = (var->xres + 0x1) & (~0x1);
1473 var->xoffset = (var->xoffset) & (~0x1);
1476 var->bits_per_pixel = 32;
1484 static int fb0_set_par(struct fb_info *info)
1486 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1487 struct fb_var_screeninfo *var = &info->var;
1488 struct fb_fix_screeninfo *fix = &info->fix;
1489 struct rk29fb_screen *screen = inf->cur_screen;
1490 struct win0_par *par = info->par;
1492 u32 offset=0, smem_len=0;
1493 u16 xres_virtual = var->xres_virtual; //virtual screen size
1494 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1495 u16 ypos_virtual = var->yoffset;
1497 #ifdef CONFIG_FB_SCALING_OSD
1498 struct rk29_ipp_req ipp_req;
1500 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1503 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1504 wait_event_interruptible(fb0_wait_queue, idle_condition);
1510 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1511 #if !defined(CONFIG_FB_SCALING_OSD)
1512 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1515 switch(var->bits_per_pixel)
1519 if( ypos_virtual == 0)
1520 fb0_first_buff_bits = 16;
1522 fb0_second_buff_bits = 16;
1524 //fix->line_length = 2 * xres_virtual;
1525 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1527 #ifdef CONFIG_FB_SCALING_OSD
1528 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1529 ipp_req.src0.fmt = IPP_RGB_565;
1530 ipp_req.dst0.fmt = IPP_RGB_565;
1532 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1533 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1534 offset -= var->yres * var->xres *2;
1539 if( ypos_virtual == 0)
1540 fb0_first_buff_bits = 32;
1542 fb0_second_buff_bits = 32;
1543 fix->line_length = 4 * xres_virtual;
1544 #ifdef CONFIG_FB_SCALING_OSD
1545 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1547 ipp_req.src0.fmt = IPP_XRGB_8888;
1548 ipp_req.dst0.fmt = IPP_XRGB_8888;
1550 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1552 if(ypos_virtual >= 2*var->yres)
1555 #ifdef CONFIG_FB_SCALING_OSD
1556 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1557 ipp_req.src0.fmt = IPP_RGB_565;
1558 ipp_req.dst0.fmt = IPP_RGB_565;
1560 if(ypos_virtual == 3*var->yres)
1562 offset -= var->yres * var->xres *2;
1568 smem_len = fix->line_length * var->yres_virtual;
1569 //map_size = PAGE_ALIGN(smem_len);
1571 if (smem_len > fix->smem_len) // buffer need realloc
1573 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1574 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1575 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1579 par->addr_seted = 1;
1580 #if ANDROID_USE_THREE_BUFS
1581 if(0==new_frame_seted) {
1583 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1585 new_frame_seted = 0;
1588 if(inf->video_mode == 1)
1590 #ifdef CONFIG_FB_SCALING_OSD
1591 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1592 #ifndef CONFIG_FB_SCALING_OSD_1080P
1593 && (screen->x_res<=1280)
1599 par->xsize = screen->x_res;
1600 par->ysize = screen->y_res;
1601 par->y_offset = dstoffset;
1603 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1604 ipp_req.src0.w = var->xres;
1605 ipp_req.src0.h = var->yres;
1607 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1608 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1609 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1611 ipp_req.src_vir_w = ipp_req.src0.w;
1612 ipp_req.dst_vir_w = ipp_req.dst0.w;
1613 ipp_req.timeout = 100;
1614 ipp_req.flag = IPP_ROT_0;
1615 //ipp_do_blit(&ipp_req);
1616 ipp_blit_sync(&ipp_req);
1620 par->y_offset = offset;
1621 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1622 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1623 par->xsize = var->xres; //visiable size in panel
1624 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1630 par->y_offset = offset;
1633 par->xsize = screen->x_res;
1634 par->ysize = screen->y_res;
1639 wake_up_interruptible_sync(&fb0_wait_queue);
1643 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1646 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1647 struct fb_var_screeninfo *var1 = &info->var;
1648 struct rk29fb_screen *screen = inf->cur_screen;
1649 struct win0_par *par = info->par;
1652 u16 ypos_virtual = var->yoffset;
1653 u16 xpos_virtual = var->xoffset;
1654 #ifdef CONFIG_FB_SCALING_OSD
1655 struct fb_fix_screeninfo *fix = &info->fix;
1656 struct rk29_ipp_req ipp_req;
1658 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1660 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1664 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1665 #if !defined(CONFIG_FB_SCALING_OSD)
1666 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1669 switch(var1->bits_per_pixel)
1672 var->xoffset = (var->xoffset) & (~0x1);
1673 #ifdef CONFIG_FB_SCALING_OSD
1674 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1675 ipp_req.src0.fmt = IPP_RGB_565;
1676 ipp_req.dst0.fmt = IPP_RGB_565;
1678 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1679 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1680 offset -= var->yres * var->xres *2;
1683 #ifdef CONFIG_FB_SCALING_OSD
1684 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1685 ipp_req.src0.fmt = IPP_XRGB_8888;
1686 ipp_req.dst0.fmt = IPP_XRGB_8888;
1688 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1689 if(ypos_virtual >= 2*var->yres)
1692 #ifdef CONFIG_FB_SCALING_OSD
1693 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1694 ipp_req.src0.fmt = IPP_RGB_565;
1695 ipp_req.dst0.fmt = IPP_RGB_565;
1697 if(ypos_virtual == 3*var->yres)
1699 offset -= var->yres * var->xres *2;
1707 if(inf->video_mode == 1)
1709 #ifdef CONFIG_FB_SCALING_OSD
1710 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1711 #ifndef CONFIG_FB_SCALING_OSD_1080P
1712 && (screen->x_res<=1280)
1716 par->y_offset = dstoffset;
1718 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1719 ipp_req.src0.w = var->xres;
1720 ipp_req.src0.h = var->yres;
1722 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1723 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1724 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1726 ipp_req.src_vir_w = ipp_req.src0.w;
1727 ipp_req.dst_vir_w = ipp_req.dst0.w;
1728 ipp_req.timeout = 100;
1729 ipp_req.flag = IPP_ROT_0;
1730 //ipp_do_blit(&ipp_req);
1731 ipp_blit_sync(&ipp_req);
1736 par->y_offset = offset;
1741 par->y_offset = offset;
1744 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1745 #if !ANDROID_USE_THREE_BUFS
1746 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1747 if(SCREEN_MCU == inf->cur_screen->type) {
1748 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1752 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1759 unsigned long temp_vv;
1760 static int frame_num = 0;
1761 static int wimo_set_buff(struct fb_info *info,unsigned long *temp)
1763 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1765 ui_buffer = temp[0];
1766 ui_buffer_map = ioremap(temp[0],temp[1]);
1767 if(ui_buffer_map == NULL)
1769 printk("can't map a buffer for ui\n");
1773 printk("ui_buffer %x ",ui_buffer_map);
1774 memset(&wimo_info,0,sizeof(wimo_info) );
1776 wimo_info.mode = inf->video_mode;
1777 // wimo_info.bitperpixel = var->bits_per_pixel;
1780 wimo_info.dst_width = (temp[2] + 15) & 0xfff0;
1781 wimo_info.dst_height = (temp[3] + 15) & 0xfff0;
1783 static int wimo_get_buff(struct fb_info *info)
1786 struct rk29_ipp_req overlay_req;
1787 struct rk29_ipp_req overlay_req_1;
1788 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1790 memset(&overlay_req, 0 , sizeof(overlay_req));
1791 memset(&overlay_req_1, 0 , sizeof(overlay_req_1));
1793 if(inf->video_mode == 0 )
1795 struct win0_par *par = info->par;
1798 wimo_info.xsize = 0;
1799 wimo_info.ysize = 0;
1801 if(par->format == 1)
1802 wimo_info.bitperpixel = 16;
1804 wimo_info.bitperpixel =32;// wimo_info.bitperpixel_fb1;
1805 overlay_req.src0.YrgbMst = info->fix.smem_start + par->y_offset;//info->screen_base + par->y_offset;//info_buffer[8];
1806 overlay_req.src0.CbrMst = info->fix.smem_start + par->y_offset + wimo_info.dst_width * wimo_info.dst_height;//dst_width*dst_height;//+ par->y_offset + dst_width*dst_height;//info_buffer[9];
1807 overlay_req.src0.w = wimo_info.dst_width ;//dst_width;//info_buffer[2];
1808 overlay_req.src0.h = wimo_info.dst_height ;//dst_height;//info_buffer[3];
1809 overlay_req.src0.fmt = (wimo_info.bitperpixel == 16) ? 1 : 0;//3;
1810 overlay_req.dst0.YrgbMst = ui_buffer;//overlay_buffer + info_buffer[4] + info_buffer[5] * dst_width;
1811 overlay_req.dst0.CbrMst = ui_buffer + wimo_info.dst_width * wimo_info.dst_height;//dst_width*dst_height;//(unsigned char*) overlay_buffer + dst_width*dst_height +info_buffer[4] + ( info_buffer[5] * dst_width) / 2;// info_buffer[6] * info_buffer[7];
1812 overlay_req.dst0.w = wimo_info.dst_width ;//dst_width;//info_buffer[6];
1813 overlay_req.dst0.h = wimo_info.dst_height ;//dst_height;//info_buffer[7];
1814 overlay_req.dst0.fmt = (wimo_info.bitperpixel== 16) ? 1 : 0;//3;3;
1815 overlay_req.deinterlace_enable = 0;
1816 overlay_req.timeout = 1000000;
1817 overlay_req.src_vir_w = wimo_info.dst_width ;//dst_width;//info_buffer[2];
1818 overlay_req.dst_vir_w = wimo_info.dst_width ;//dst_width;
1819 overlay_req.flag = IPP_ROT_0;
1820 ipp_blit_sync(&overlay_req);
1828 static int wimo_time = 0;
1829 unsigned long *overlay_buffer_map_temp;
1830 unsigned long *map_temp;
1831 unsigned long sign_memset = 0;
1832 struct fb_var_screeninfo *var = &inf->fb1->var;
1833 struct win0_par *par = inf->fb1->par;
1835 // printk("overlay setbuffer in\n");
1836 // mutex_lock(&wimo_info.fb_lock);
1837 wimo_info.fb_lock = 1;
1839 wimo_info.xaff = var->xres;
1840 wimo_info.yaff = var->yres;
1841 if((wimo_info.xpos != par->xpos) ||(wimo_info.ypos != par->ypos)||(wimo_info.xsize != par->xsize) ||(wimo_info.ysize != par->ysize))
1843 wimo_info.xpos = par->xpos;
1844 wimo_info.ypos = par->ypos;
1845 wimo_info.xsize = par->xsize;
1846 wimo_info.ysize = par->ysize;
1848 memset(ui_buffer_map,0,wimo_info.dst_height * wimo_info.dst_width);//dst_width*dst_height);
1849 memset(ui_buffer_map + wimo_info.dst_height * wimo_info.dst_width, 0x80,wimo_info.dst_height * wimo_info.dst_width / 2);//dst_width*dst_height,0x80,dst_width*dst_height/2);
1850 printk("wimo_info.xpos %d wimo_info.ypos %d wimo_info.xsize %d wimo_info.ysize %d\n",wimo_info.xpos, wimo_info.ypos, wimo_info.xsize, wimo_info.ysize );
1853 //printk("wimo_info.xpos %d wimo_info.ypos %d wimo_info.xsize %d wimo_info.ysize %d\n",wimo_info.xpos, wimo_info.ypos, wimo_info.xsize, wimo_info.ysize );
1854 if(wimo_info.xaff * 3 < wimo_info.xsize || wimo_info.yaff * 3 < wimo_info.ysize)// 3time or bigger scale up
1856 unsigned long mid_width, mid_height;
1857 struct rk29_ipp_req overlay_req_1;
1858 if(wimo_info.xaff * 3 < wimo_info.xsize)
1859 mid_width = wimo_info.xaff * 3;
1861 mid_width = wimo_info.xsize;
1863 if(wimo_info.yaff * 3 < wimo_info.ysize)
1864 mid_height = wimo_info.yaff * 3;
1866 mid_height = wimo_info.ysize;
1867 overlay_req.src0.YrgbMst = wimo_info.src_y;//info_buffer[8];
1868 overlay_req.src0.CbrMst = wimo_info.src_uv;//info_buffer[9];
1869 overlay_req.src0.w = wimo_info.xaff;// info_buffer[2];
1870 overlay_req.src0.h = wimo_info.yaff;// info_buffer[3];
1871 overlay_req.src0.fmt = 3;
1872 overlay_req.dst0.YrgbMst = ui_buffer + 2048000 ;//info_buffer[4] + info_buffer[5] * dst_width; //С³ß´çƬԴÐèÒª2´Î·Å´ó£¬ËùÒÔ½«bufferµÄºó°ë¶ÎÓÃÓÚ»º´æ
1873 overlay_req.dst0.CbrMst = (unsigned char*) ui_buffer + mid_height * mid_width + 2048000;
1875 overlay_req.dst0.w = mid_width;//info_buffer[6];
1876 overlay_req.dst0.h = mid_height;//info_buffer[7];
1877 overlay_req.dst0.fmt = 3;
1878 overlay_req.timeout = 100000;
1879 overlay_req.src_vir_w = wimo_info.xaff;//info_buffer[2];
1880 overlay_req.dst_vir_w = mid_width;//dst_width;
1881 overlay_req.flag = IPP_ROT_0;
1883 overlay_req_1.src0.YrgbMst = ui_buffer + 2048000;
1884 overlay_req_1.src0.CbrMst = (unsigned char*) ui_buffer + mid_height * mid_width + 2048000;
1885 overlay_req_1.src0.w = mid_width;
1886 overlay_req_1.src0.h = mid_height;// info_buffer[3];
1887 overlay_req_1.src0.fmt = 3;
1888 overlay_req_1.dst0.YrgbMst = ui_buffer + ((wimo_info.xpos + 1)&0xfffe) + wimo_info.ypos * wimo_info.dst_width;//info_buffer[4] + info_buffer[5] * dst_width;
1889 overlay_req_1.dst0.CbrMst =(unsigned char*) ui_buffer + wimo_info.dst_width * wimo_info.dst_height + ((wimo_info.xpos + 1)&0xfffe) + ( wimo_info.ypos / 2)* wimo_info.dst_width ;
1891 overlay_req_1.dst0.w = wimo_info.xsize;//info_buffer[6];
1892 overlay_req_1.dst0.h = wimo_info.ysize;//info_buffer[7];
1893 overlay_req_1.dst0.fmt = 3;
1894 overlay_req_1.timeout = 100000;
1895 overlay_req_1.src_vir_w = mid_width;//info_buffer[2];
1896 overlay_req_1.dst_vir_w = wimo_info.dst_width;//dst_width;
1897 overlay_req_1.flag = IPP_ROT_0;
1900 err = ipp_blit_sync(&overlay_req);
1901 dmac_flush_range(ui_buffer_map,ui_buffer_map + wimo_info.dst_height * wimo_info.dst_width * 3/2);//dst_width*dst_height*3/2);
1902 err = ipp_blit_sync(&overlay_req_1);
1907 overlay_req.src0.YrgbMst = wimo_info.src_y;//info_buffer[8];
1908 overlay_req.src0.CbrMst = wimo_info.src_uv;//info_buffer[9];
1909 overlay_req.src0.w = wimo_info.xaff;// info_buffer[2];
1910 overlay_req.src0.h = wimo_info.yaff;// info_buffer[3];
1911 overlay_req.src0.fmt = 3;
1912 overlay_req.dst0.YrgbMst = ui_buffer + ((wimo_info.xpos + 1)&0xfffe) + wimo_info.ypos * wimo_info.dst_width;//info_buffer[4] + info_buffer[5] * dst_width;
1913 overlay_req.dst0.CbrMst =(unsigned char*) ui_buffer + wimo_info.dst_width * wimo_info.dst_height + ((wimo_info.xpos + 1)&0xfffe) + ( wimo_info.ypos / 2)* wimo_info.dst_width ;
1915 overlay_req.dst0.w = wimo_info.xsize;//wimo_info.xsize;//wimo_info.xaff;// wimo_info.xsize;//info_buffer[6];
1916 overlay_req.dst0.h = (wimo_info.ysize + 1) & 0xfffe;//(wimo_info.ysize + 1) & 0xfffe;//wimo_info.yaff;//(wimo_info.ysize + 1) & 0xfffe;//info_buffer[7];
1917 overlay_req.dst0.fmt = 3;
1918 overlay_req.timeout = 100000;
1919 overlay_req.src_vir_w = wimo_info.xaff;//info_buffer[2];
1920 overlay_req.dst_vir_w = wimo_info.dst_width;//wimo_info.dst_width;//wimo_info.yaff;//wimo_info.dst_width;//dst_width;
1921 overlay_req.flag = IPP_ROT_0;
1923 dmac_flush_range(ui_buffer_map,ui_buffer_map + wimo_info.dst_height * wimo_info.dst_width * 3/2);//dst_width*dst_height*3/2);
1924 err = ipp_blit_sync(&overlay_req);
1927 // printk("overlay setbuffer exit\n");
1929 wimo_info.fb_lock = 0;
1936 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1938 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1939 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1945 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1948 inf->mcu_usetimer = 0;
1951 case FBIOPUT_16OR32:
1953 inf->fb0_color_deepth = arg;
1956 case FBIOGET_16OR32:
1957 return inf->fb0_color_deepth;
1958 case FBIOGET_IDLEFBUff_16OR32:
1959 if(info->var.yoffset == 0)
1961 return fb0_second_buff_bits;
1965 return fb0_first_buff_bits;
1967 case FBIOSET_COMPOSE_LAYER_COUNTS:
1968 fb_compose_layer_count = arg;
1971 case FBIOGET_COMPOSE_LAYER_COUNTS:
1973 return fb_compose_layer_count;
1975 case FBIOPUT_FBPHYADD:
1976 return info->fix.smem_start;
1977 case FBIOGET_OVERLAY_STATE:
1978 return inf->video_mode;
1979 case FBIOGET_SCREEN_STATE:
1980 return inf->cur_screen->type;
1982 case FBIOPUT_SET_CURSOR_EN:
1985 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1987 rk29_set_cursor_en(inf, en);
1990 case FBIOPUT_SET_CURSOR_POS:
1992 struct fbcurpos pos;
1993 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1995 rk29_set_cursor_pos(inf, pos.x , pos.y);
1998 case FBIOPUT_SET_CURSOR_IMG:
2000 char cursor_buf[CURSOR_BUF_SIZE];
2001 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
2003 rk29_set_cursor_img(inf, cursor_buf);
2006 case FBIOPUT_SET_CURSOR_CMAP:
2008 struct fb_image img;
2009 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
2011 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
2014 case FBIOPUT_GET_CURSOR_RESOLUTION:
2017 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2018 if((inf->fb1->var.rotate &0x1ff ) == 270) {
2019 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
2020 panel_size[1] = inf->cur_screen->x_res;
2022 panel_size[0] = inf->cur_screen->x_res;
2023 panel_size[1] = inf->cur_screen->y_res;
2025 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
2028 case FBIOPUT_GET_CURSOR_EN:
2030 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
2031 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
2035 case FB0_IOCTL_SET_BUF:
2037 unsigned long temp[4];
2038 copy_from_user(temp, (void*)arg, 20);
2039 wimo_set_buff( info,temp);
2043 case FB0_IOCTL_CLOSE_BUF:
2045 if(ui_buffer != NULL && ui_buffer_map !=NULL )
2047 iounmap(ui_buffer_map);
2050 memset(&wimo_info,0,sizeof(wimo_info));
2053 printk("somethint wrong with wimo in close");
2058 case FB0_IOCTL_COPY_CURBUF:
2060 unsigned long temp_data[3];
2061 copy_from_user(&temp_vv, (void*)arg, 4);
2062 if(ui_buffer != NULL && ui_buffer_map !=NULL )
2064 temp_data[1] = wimo_get_buff(info);
2065 temp_data[0] = wimo_info.bitperpixel;
2071 temp_data[0] = wimo_info.bitperpixel;
2072 printk("somethint wrong with wimo in getbuf");
2074 temp_data[2] = frame_num++;
2075 //printk("FB0_IOCTL_COPY_CURBUF %d %d %d\n",temp_data[0],temp_data[1],temp_data[2]);
2076 copy_to_user((void*)arg, &temp_data, 12);
2086 static int fb1_blank(int blank_mode, struct fb_info *info)
2088 win0_blank(blank_mode, info);
2092 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
2094 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2095 struct rk29fb_screen *screen = inf->cur_screen;
2097 u32 ScaleYRGBY=0x1000;
2098 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
2099 u16 ypos = (var->nonstd>>20) & 0xfff;
2100 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
2101 u16 ysize = (var->grayscale>>20) & 0xfff;
2102 u16 xlcd = screen->x_res; //size of panel
2103 u16 ylcd = screen->y_res;
2106 struct hdmi *hdmi = get_hdmi_struct(0);
2109 if((var->rotate & 0x1ff) == 90 ||(var->rotate &0x1ff)== 270) {
2110 #ifdef CONFIG_FB_ROTATE_VIDEO
2111 xlcd = screen->y_res;
2112 ylcd = screen->x_res;
2113 #else //CONFIG_FB_ROTATE_VIDEO
2114 printk("LCDC not support rotate!\n");
2119 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2120 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2121 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2122 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2124 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2128 if( 0==var->xres_virtual || 0==var->yres_virtual ||
2129 0==var->xres || 0==var->yres || var->xres<16 ||
2130 0==xsize || 0==ysize || xsize<16 ||
2131 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
2133 printk(">>>>>> win0fb_check_var fail 1!!! \n");
2134 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
2135 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
2136 var->bits_per_pixel, var->bits_per_pixel);
2140 if( (var->xoffset+var->xres)>var->xres_virtual ||
2141 (var->yoffset+var->yres)>var->yres_virtual ||
2142 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
2144 printk(">>>>>> win0fb_check_var fail 2!!! \n");
2145 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
2146 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
2147 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
2151 switch(var->nonstd&0x0f)
2154 switch(var->bits_per_pixel)
2157 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
2158 var->xres = (var->xres + 0x1) & (~0x1);
2159 var->xoffset = (var->xoffset) & (~0x1);
2162 var->bits_per_pixel = 32;
2165 var->nonstd &= ~0xc0; //not support I2P in this format
2168 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2169 var->xres = (var->xres + 0x3) & (~0x3);
2170 var->xoffset = (var->xoffset) & (~0x3);
2173 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2174 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
2175 var->xres = (var->xres + 0x3) & (~0x3);
2176 var->yres = (var->yres + 0x1) & (~0x1);
2177 var->xoffset = (var->xoffset) & (~0x3);
2178 var->yoffset = (var->yoffset) & (~0x1);
2181 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2182 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
2183 var->xres = (var->xres + 0x3) & (~0x3);
2184 var->yres = (var->yres + 0x1) & (~0x1);
2185 var->xoffset = (var->xoffset) & (~0x3);
2186 var->yoffset = (var->yoffset) & (~0x1);
2187 var->nonstd &= ~0xc0; //not support I2P in this format
2191 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2192 var->xres = (var->xres + 0x3) & (~0x3);
2193 var->xoffset = (var->xoffset) & (~0x3);
2194 var->nonstd &= ~0xc0; //not support I2P in this format
2197 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
2201 if((var->rotate & 0x1ff ) == 90 ||(var->rotate & 0x1ff ) == 270)
2210 ScaleYRGBY = CalScaleW0(yres, ysize);
2212 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
2214 return -EINVAL; // multiple of scale down or scale up can't exceed 8
2217 if(inf->video_mode == 1) {
2218 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
2220 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2221 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2222 init_completion(&hdmi->complete);
2224 wait_for_completion_interruptible_timeout(&hdmi->complete,
2225 msecs_to_jiffies(10000));
2232 static int fb1_set_par(struct fb_info *info)
2234 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2235 struct rk29fb_screen *screen = inf->cur_screen;
2236 struct fb_var_screeninfo *var = &info->var;
2237 struct fb_fix_screeninfo *fix = &info->fix;
2238 struct win0_par *par = info->par;
2241 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
2243 //u32 xact = var->xres; /* visible resolution */
2244 //u32 yact = var->yres;
2245 u32 xvir = var->xres_virtual; /* virtual resolution */
2246 u32 yvir = var->yres_virtual;
2247 u32 xact_st = var->xoffset; /* offset from virtual to visible */
2248 u32 yact_st = var->yoffset; /* resolution */
2250 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
2251 u16 ypos = (var->nonstd>>20) & 0xfff;
2252 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
2253 u16 ysize = (var->grayscale>>20) & 0xfff;
2255 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
2256 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
2258 u8 data_format = var->nonstd&0x0f;
2259 // u32 win0_en = var->reserved[2];
2260 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
2261 // u32 uv_addr = var->reserved[4];
2263 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2265 if((var->rotate & 0x1ff ) == 90 || (var->rotate & 0x1ff ) == 270)
2267 #ifdef CONFIG_FB_ROTATE_VIDEO
2268 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
2269 ypos = (var->nonstd>>8) & 0xfff;
2270 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
2271 ysize = (var->grayscale>>8) & 0xfff;
2272 #else //CONFIG_FB_ROTATE_VIDEO
2273 printk("LCDC not support rotate!\n");
2277 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2278 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2279 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2280 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2282 /* calculate y_offset,c_offset,line_length,cblen and crlen */
2283 switch (data_format)
2286 switch(var->bits_per_pixel)
2290 fix->line_length = 2 * xvir;
2291 par->y_offset = (yact_st*xvir + xact_st)*2;
2295 fix->line_length = 4 * xvir;
2296 par->y_offset = (yact_st*xvir + xact_st)*4;
2304 fix->line_length = xvir;
2305 cblen = crlen = (xvir*yvir)/2;
2306 par->y_offset = yact_st*xvir + xact_st;
2307 par->c_offset = yact_st*xvir + xact_st;
2311 fix->line_length = xvir;
2312 cblen = crlen = (xvir*yvir)/4;
2314 par->y_offset = yact_st*xvir + xact_st;
2315 par->c_offset = (yact_st/2)*xvir + xact_st;
2320 fix->line_length = xvir;
2321 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
2322 par->c_offset = (yact_st/2)*xvir + xact_st;
2323 cblen = crlen = (xvir*yvir)/4;
2328 fix->line_length = xvir;
2329 par->y_offset = yact_st*xvir + xact_st;
2330 par->c_offset = yact_st*2*xvir + xact_st*2;
2331 cblen = crlen = (xvir*yvir);
2337 smem_len = fix->line_length * yvir + cblen + crlen;
2338 map_size = PAGE_ALIGN(smem_len);
2340 // fix->smem_start = y_addr;
2341 fix->smem_len = smem_len;
2342 // fix->mmio_start = uv_addr;
2344 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
2345 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);
2347 par->format = format;
2354 if ( wq_condition2 == 0 ) {
2355 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
2359 #ifdef CONFIG_FB_ROTATE_VIDEO
2360 //need refresh ,zyc add
2361 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
2364 struct rk29_ipp_req ipp_req;
2365 static u32 dstoffset = 0;
2366 static int fb_index = 0;
2367 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2368 yuv_phy[0] = last_yuv_phy[0];
2369 yuv_phy[1] = last_yuv_phy[1];
2370 yuv_phy[0] += par->y_offset;
2371 yuv_phy[1] += par->c_offset;
2373 if((var->rotate == 90) ||(var->rotate == 270))
2375 if(var->rotate%360 != 0)
2378 #ifdef CONFIG_FB_ROTATE_VIDEO
2379 dstoffset = (dstoffset+1)%2;
2380 ipp_req.src0.fmt = 3;
2381 ipp_req.src0.YrgbMst = yuv_phy[0];
2382 ipp_req.src0.CbrMst = yuv_phy[1];
2383 ipp_req.src0.w = var->xres;
2384 ipp_req.src0.h = var->yres;
2386 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2387 ipp_req.dst_vir_w=screen->x_res;
2389 ipp_req.dst0.fmt = 3;
2390 #ifdef CONFIG_FB_MIRROR_X_Y
2391 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2393 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*4;
2394 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*5;
2398 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2399 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2402 if(var->xres > screen->x_res)
2404 ipp_req.dst0.w = screen->x_res;
2405 ipp_req.dst0.h = screen->y_res;
2407 ipp_req.dst0.w = var->xres;
2408 ipp_req.dst0.h = var->yres;
2410 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2411 ipp_req.timeout = 100;
2412 if((var->rotate & 0x1ff) == 90)
2413 ipp_req.flag = IPP_ROT_90;
2414 else if ((var->rotate & 0x1ff) == 180)
2415 ipp_req.flag = IPP_ROT_180;
2416 else if((var->rotate & 0x1ff) == 270)
2417 ipp_req.flag = IPP_ROT_270;
2418 else if((var->rotate & X_MIRROR) == X_MIRROR )
2419 ipp_req.flag = IPP_ROT_X_FLIP;
2420 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2421 ipp_req.flag = IPP_ROT_Y_FLIP;
2422 //ipp_do_blit(&ipp_req);
2423 ipp_blit_sync(&ipp_req);
2424 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2425 yuv_phy[1] = ipp_req.dst0.CbrMst;
2426 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2428 memset(&ipp_req,0,sizeof(struct rk29_ipp_req));
2430 if((var->rotate & X_MIRROR) == X_MIRROR)
2431 ipp_req.flag = IPP_ROT_X_FLIP;
2432 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2433 ipp_req.flag = IPP_ROT_Y_FLIP;
2435 printk(">>>>>> %d rotate is not support!\n",var->rotate);
2437 if(var->xres > screen->x_res)
2439 ipp_req.dst0.w = screen->x_res;
2440 ipp_req.dst0.h = screen->y_res;
2442 ipp_req.dst0.w = var->xres;
2443 ipp_req.dst0.h = var->yres;
2445 ipp_req.src0.fmt = 3;
2446 ipp_req.src0.YrgbMst = yuv_phy[0];
2447 ipp_req.src0.CbrMst = yuv_phy[1];
2448 ipp_req.src0.w = ipp_req.dst0.w;
2449 ipp_req.src0.h = ipp_req.dst0.h;
2451 ipp_req.src_vir_w= (ipp_req.dst0.w + 15) & (~15);
2452 ipp_req.dst_vir_w= (ipp_req.dst0.w + 15) & (~15);
2454 ipp_req.dst0.fmt = 3;
2455 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2456 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2458 ipp_req.timeout = 100;
2459 ipp_blit_sync(&ipp_req);
2460 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2461 yuv_phy[1] = ipp_req.dst0.CbrMst;
2463 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2465 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2466 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2467 if(var->xres > screen->x_res)
2469 ipp_req.dst0.w = screen->x_res;
2470 ipp_req.dst0.h = screen->y_res;
2472 ipp_req.dst0.w = var->xres;
2473 ipp_req.dst0.h = var->yres;
2476 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2477 ipp_req.timeout = 100;
2478 if(var->rotate == 90)
2479 ipp_req.flag = IPP_ROT_90;
2480 else if(var->rotate == 180)
2481 ipp_req.flag = IPP_ROT_180;
2482 else if(var->rotate == 270)
2483 ipp_req.flag = IPP_ROT_270;
2484 //ipp_do_blit(&ipp_req);
2485 ipp_blit_sync(&ipp_req);
2487 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2488 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2489 yuv_phy[1] = ipp_req.dst0.CbrMst;
2491 fix->smem_start = yuv_phy[0];
2492 fix->mmio_start = yuv_phy[1];
2493 #else //CONFIG_FB_ROTATE_VIDEO
2494 printk("LCDC not support rotate!\n");
2500 fix->smem_start = yuv_phy[0];
2501 fix->mmio_start = yuv_phy[1];
2504 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2505 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2506 // enable win0 after the win0 par is seted
2507 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2508 par->addr_seted = 1;
2509 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2510 if(par->addr_seted ) {
2511 unsigned long flags;
2513 local_irq_save(flags);
2514 par->mirror.y_offset = yuv_phy[0];
2515 par->mirror.c_offset = yuv_phy[1];
2516 local_irq_restore(flags);
2519 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2524 has_set_rotate = false;
2529 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2531 struct win0_par *par = info->par;
2532 // enable win0 after the win0 addr is seted
2539 int fb1_open(struct fb_info *info, int user)
2541 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2542 struct win0_par *par = info->par;
2543 struct rk29fb_screen *screen = inf->cur_screen;
2545 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2548 par->addr_seted = 0;
2549 inf->video_mode = 1;
2551 #ifdef CONFIG_FB_ROTATE_VIDEO
2552 //reinitialize the var when open,zyc
2553 last_yuv_phy[0] = 0;
2554 last_yuv_phy[1] = 0;
2558 printk(">>>>>> fb1 has opened! \n");
2562 win0_blank(FB_BLANK_NORMAL, info);
2563 if(screen->x_res>1280)
2565 fb0_set_par(inf->fb0);
2567 rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2572 int fb1_release(struct fb_info *info, int user)
2574 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2575 struct win0_par *par = info->par;
2576 struct fb_var_screeninfo *var0 = &info->var;
2578 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2579 if(inf->setFlag == 0)
2581 wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2585 inf->video_mode = 0;
2587 par->addr_seted = 0;
2588 win1_blank(FB_BLANK_NORMAL, info);
2590 //if(inf->cur_screen->type != SCREEN_HDMI)
2591 fb0_set_par(inf->fb0);
2594 info->screen_base = 0;
2595 info->fix.smem_start = 0;
2596 info->fix.smem_len = 0;
2597 // clean the var param
2598 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2599 rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2600 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2601 cancel_delayed_work_sync(&rk29_win1_check_work);
2608 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2610 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2611 struct win0_par *par = info->par;
2612 struct fb_fix_screeninfo *fix0 = &info->fix;
2613 struct fb_var_screeninfo *var = &info->var;
2614 void __user *argp = (void __user *)arg;
2616 #ifdef CONFIG_FB_ROTATE_VIDEO
2617 struct rk29fb_screen *screen = inf->cur_screen;
2618 struct rk29_ipp_req ipp_req;
2619 static u32 dstoffset = 0;
2620 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2623 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2624 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2630 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2633 if((var->rotate & 0x1ff) == 270 ||(var->rotate & 0x1ff) == 90) {
2634 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2635 panel_size[1] = inf->panel1_info.x_res;
2637 panel_size[0] = inf->panel1_info.x_res;
2638 panel_size[1] = inf->panel1_info.y_res;
2641 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2645 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2649 // printk("FB1_IOCTL_SET_YUV_ADDR1 \n");
2650 // while(wimo_info.fb_lock)
2654 // printk("FB1_IOCTL_SET_YUV_ADDR 2\n");
2656 if (copy_from_user(yuv_phy, argp, 8))
2658 #ifdef CONFIG_FB_ROTATE_VIDEO
2660 if(has_set_rotate == true)
2662 last_yuv_phy[0] = yuv_phy[0];
2663 last_yuv_phy[1] = yuv_phy[1];
2666 fix0->smem_start = yuv_phy[0];
2667 fix0->mmio_start = yuv_phy[1];
2668 yuv_phy[0] += par->y_offset;
2669 yuv_phy[1] += par->c_offset;
2671 wimo_info.src_y = yuv_phy[0];
2672 wimo_info.src_uv = yuv_phy[1];
2677 if((var->rotate == 90) ||(var->rotate == 270))
2679 if(var->rotate%360 != 0)
2682 #ifdef CONFIG_FB_ROTATE_VIDEO
2683 dstoffset = (dstoffset+1)%2;
2684 ipp_req.src0.fmt = 3;
2685 ipp_req.src0.YrgbMst = yuv_phy[0];
2686 ipp_req.src0.CbrMst = yuv_phy[1];
2687 ipp_req.src0.w = var->xres ;
2688 ipp_req.src0.h = var->yres ;
2689 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2690 ipp_req.dst_vir_w=screen->x_res;
2692 ipp_req.dst0.fmt = 3;
2693 #ifdef CONFIG_FB_MIRROR_X_Y
2694 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2696 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*4;
2697 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*5;
2701 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2702 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2705 if(var->xres > screen->x_res)
2707 ipp_req.dst0.w = screen->x_res;
2708 ipp_req.dst0.h = screen->y_res;
2710 ipp_req.dst0.w = var->xres;
2711 ipp_req.dst0.h = var->yres;
2713 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2714 ipp_req.timeout = 100;
2715 if((var->rotate & 0x1ff) == 90)
2716 ipp_req.flag = IPP_ROT_90;
2717 else if ((var->rotate & 0x1ff) == 180)
2718 ipp_req.flag = IPP_ROT_180;
2719 else if((var->rotate & 0x1ff) == 270)
2720 ipp_req.flag = IPP_ROT_270;
2721 else if((var->rotate & X_MIRROR) == X_MIRROR )
2722 ipp_req.flag = IPP_ROT_X_FLIP;
2723 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2724 ipp_req.flag = IPP_ROT_Y_FLIP;
2725 //ipp_do_blit(&ipp_req);
2726 ipp_blit_sync(&ipp_req);
2727 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2728 yuv_phy[1] = ipp_req.dst0.CbrMst;
2729 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2731 memset(&ipp_req,0,sizeof(struct rk29_ipp_req));
2733 if((var->rotate & X_MIRROR) == X_MIRROR)
2734 ipp_req.flag = IPP_ROT_X_FLIP;
2735 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2736 ipp_req.flag = IPP_ROT_Y_FLIP;
2738 printk(">>>>>> %d rotate is not support!\n",var->rotate);
2740 if(var->xres > screen->x_res)
2742 ipp_req.dst0.w = screen->x_res;
2743 ipp_req.dst0.h = screen->y_res;
2745 ipp_req.dst0.w = var->xres;
2746 ipp_req.dst0.h = var->yres;
2748 ipp_req.src0.fmt = 3;
2749 ipp_req.src0.YrgbMst = yuv_phy[0];
2750 ipp_req.src0.CbrMst = yuv_phy[1];
2751 ipp_req.src0.w = ipp_req.dst0.w;
2752 ipp_req.src0.h = ipp_req.dst0.h;
2754 ipp_req.src_vir_w= (ipp_req.dst0.w + 15) & (~15);
2755 ipp_req.dst_vir_w= (ipp_req.dst0.w + 15) & (~15);
2757 ipp_req.dst0.fmt = 3;
2758 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2759 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2761 ipp_req.timeout = 100;
2762 ipp_blit_sync(&ipp_req);
2763 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2764 yuv_phy[1] = ipp_req.dst0.CbrMst;
2766 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2768 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2769 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2770 if(var->xres > screen->x_res)
2772 ipp_req.dst0.w = screen->x_res;
2773 ipp_req.dst0.h = screen->y_res;
2775 ipp_req.dst0.w = var->xres;
2776 ipp_req.dst0.h = var->yres;
2779 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2780 ipp_req.timeout = 100;
2781 if(var->rotate == 90)
2782 ipp_req.flag = IPP_ROT_90;
2783 else if(var->rotate == 180)
2784 ipp_req.flag = IPP_ROT_180;
2785 else if(var->rotate == 270)
2786 ipp_req.flag = IPP_ROT_270;
2787 //ipp_do_blit(&ipp_req);
2788 ipp_blit_sync(&ipp_req);
2790 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2791 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2792 yuv_phy[1] = ipp_req.dst0.CbrMst;
2794 fix0->smem_start = yuv_phy[0];
2795 fix0->mmio_start = yuv_phy[1];
2796 #else //CONFIG_FB_ROTATE_VIDEO
2797 printk("LCDC not support rotate!\n");
2801 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2802 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2803 // enable win0 after the win0 par is seted
2804 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2805 par->addr_seted = 1;
2806 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2807 if(par->par_seted) {
2808 unsigned long flags;
2810 local_irq_save(flags);
2811 par->mirror.y_offset = yuv_phy[0];
2812 par->mirror.c_offset = yuv_phy[1];
2813 local_irq_restore(flags);
2816 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2821 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2822 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2823 #ifdef CONFIG_FB_ROTATE_VIDEO
2825 has_set_rotate = true;
2826 #ifdef CONFIG_FB_MIRROR_X_Y
2827 if( ((arg&0x1ff)%90) == 0 && ( arg&(~0xfff))==0 )
2829 if( (arg&( X_MIRROR | Y_MIRROR ) )== (X_MIRROR | Y_MIRROR) )
2830 var->rotate = ROTATE_180;
2831 else if((arg&( ROTATE_90 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_90 | X_MIRROR | Y_MIRROR))
2832 var->rotate = ROTATE_270;
2833 else if((arg&( ROTATE_180 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_180 | X_MIRROR | Y_MIRROR))
2834 var->rotate = ROTATE_90;
2835 else if((arg&( ROTATE_270 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_270 | X_MIRROR | Y_MIRROR))
2836 var->rotate = ROTATE_0;
2839 if(arg == ROTATE_0 || arg==ROTATE_90 || arg == ROTATE_180 || arg==ROTATE_270)
2845 printk(">>>>>> %d rotate is not support!\n",(int)arg);
2847 #else //CONFIG_FB_ROTATE_VIDEO
2848 printk("LCDC not support rotate!\n");
2851 case FB1_IOCTL_SET_WIN0_TOP:
2852 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2853 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2854 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2862 static struct fb_ops fb1_ops = {
2863 .owner = THIS_MODULE,
2864 .fb_open = fb1_open,
2865 .fb_release = fb1_release,
2866 .fb_check_var = fb1_check_var,
2867 .fb_set_par = fb1_set_par,
2868 .fb_blank = fb1_blank,
2869 .fb_pan_display = fb1_pan_display,
2870 .fb_ioctl = fb1_ioctl,
2871 .fb_setcolreg = fb_setcolreg,
2872 .fb_fillrect = cfb_fillrect,
2873 .fb_copyarea = cfb_copyarea,
2874 .fb_imageblit = cfb_imageblit,
2877 static struct fb_ops fb0_ops = {
2878 .owner = THIS_MODULE,
2879 .fb_check_var = fb0_check_var,
2880 .fb_set_par = fb0_set_par,
2881 .fb_blank = fb0_blank,
2882 .fb_pan_display = fb0_pan_display,
2883 .fb_ioctl = fb0_ioctl,
2884 .fb_setcolreg = fb_setcolreg,
2885 .fb_fillrect = cfb_fillrect,
2886 .fb_copyarea = cfb_copyarea,
2887 .fb_imageblit = cfb_imageblit,
2888 //.fb_cursor = rk29_set_cursor,
2891 int fb_get_video_mode(void)
2893 struct rk29fb_inf *inf;
2896 inf = platform_get_drvdata(g_pdev);
2897 return inf->video_mode;
2900 enable: 1, switch to tv or hdmi; 0, switch to lcd
2902 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2904 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2905 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2906 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2908 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2910 if(enable)inf->cur_screen = &inf->panel2_info;
2911 else inf->cur_screen = &inf->panel1_info;
2913 /* Black out, because some display device need clock to standby */
2914 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2915 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2916 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2917 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2918 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2919 wake_lock(&idlelock);
2921 wake_unlock(&idlelock);
2923 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2924 // operate the display_on pin to power down the lcd
2926 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2927 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2929 load_screen(inf->fb0, 0);
2932 fb1_set_par(inf->fb1);
2933 fb0_set_par(inf->fb0);
2934 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2935 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2936 rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2940 static ssize_t dsp_win0_info_read(struct device *device,
2941 struct device_attribute *attr, char *buf)
2944 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2945 struct rk29fb_screen *screen = inf->cur_screen;
2947 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2949 fbprintk("%s\n",__FUNCTION__);
2950 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2951 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2953 xpos -= (screen->left_margin + screen->hsync_len);
2954 ypos -= (screen->upper_margin + screen->vsync_len);
2956 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2957 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2958 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2959 rk29_set_cursor_test(inf->fb0);
2961 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2964 static ssize_t dsp_win0_info_write(struct device *device,
2965 struct device_attribute *attr, const char *buf, size_t count)
2967 printk("%s\n",__FUNCTION__);
2968 printk("%s %x \n",__FUNCTION__,*buf);
2972 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2974 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2976 struct platform_device *pdev = (struct platform_device*)dev_id;
2977 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2978 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2982 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2984 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2986 if(SCREEN_MCU == inf->cur_screen->type)
2988 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2994 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2996 inf->mcu_fmksync = 1;
2997 if(inf->cur_screen->refresh)
2998 inf->cur_screen->refresh(REFRESH_END);
2999 inf->mcu_fmksync = 0;
3008 if(inf->mcu_needflush) {
3009 if(inf->cur_screen->refresh)
3010 inf->cur_screen->refresh(REFRESH_PRE);
3011 inf->mcu_needflush = 0;
3012 inf->mcu_isrcnt = 0;
3013 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
3015 if(inf->cur_screen->refresh)
3016 inf->cur_screen->refresh(REFRESH_END);
3020 #if ANDROID_USE_THREE_BUFS
3021 new_frame_seted = 1;
3024 if(waitqueue_active(&par->wait)) {
3025 if (par->mirror.c_offset == 0)
3026 printk("error: no new buffer to display\n");
3028 par->done.y_offset = par->displ.y_offset;
3029 par->done.c_offset = par->displ.c_offset;
3030 par->displ.y_offset = par->mirror.y_offset;
3031 par->displ.c_offset = par->mirror.c_offset;
3032 par->mirror.y_offset = 0;
3033 par->mirror.c_offset = 0;
3035 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
3036 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
3037 wake_up_interruptible(&par->wait);
3042 wake_up_interruptible(&wq);
3044 rk29fb_irq_notify_ddr();
3048 #ifdef CONFIG_HAS_EARLYSUSPEND
3050 struct suspend_info {
3051 struct early_suspend early_suspend;
3052 struct rk29fb_inf *inf;
3055 static void rk29fb_early_suspend(struct early_suspend *h)
3057 struct suspend_info *info = container_of(h, struct suspend_info,
3060 struct rk29fb_inf *inf = info->inf;
3061 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
3063 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3066 printk("inf==0, rk29fb_suspend fail! \n");
3070 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
3071 cancel_delayed_work_sync(&rk29_win1_check_work);
3074 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
3075 mach_info->io_disable(); //close lcd out
3077 if(inf->cur_screen->standby)
3079 fbprintk(">>>>>> power down the screen! \n");
3080 inf->cur_screen->standby(1);
3082 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE | m_W1_ENABLE, v_W0_ENABLE(0) | v_W1_ENABLE(0));
3084 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
3085 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
3087 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3088 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3089 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3091 if(!inf->in_suspend)
3093 fbprintk(">>>>>> diable the lcdc clk! \n");
3094 wake_lock(&idlelock);
3096 wake_unlock(&idlelock);
3097 clk_disable(inf->aclk_ddr_lcdc);
3098 clk_disable(inf->aclk_disp_matrix);
3099 clk_disable(inf->hclk_cpu_display);
3100 clk_disable(inf->clk);
3102 clk_disable(inf->dclk);
3105 clk_disable(inf->aclk);
3107 //clk_disable(inf->pd_display);
3109 inf->in_suspend = 1;
3113 static void rk29fb_early_resume(struct early_suspend *h)
3115 struct suspend_info *info = container_of(h, struct suspend_info,
3118 struct rk29fb_inf *inf = info->inf;
3119 struct rk29fb_screen *screen = inf->cur_screen;
3120 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
3122 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3124 printk("inf==0, rk29fb_resume fail! \n");
3130 inf->in_suspend = 0;
3131 fbprintk(">>>>>> enable the lcdc clk! \n");
3132 // clk_enable(inf->pd_display);
3133 clk_enable(inf->aclk_disp_matrix);
3134 clk_enable(inf->hclk_cpu_display);
3135 clk_enable(inf->clk);
3136 clk_enable(inf->aclk_ddr_lcdc);
3139 clk_enable(inf->dclk);
3142 clk_enable(inf->aclk);
3144 usleep_range(100*1000, 100*1000);
3146 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
3147 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
3148 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3150 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
3151 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
3153 if(inf->cur_screen->standby)
3155 fbprintk(">>>>>> power on the screen! \n");
3156 inf->cur_screen->standby(0);
3158 usleep_range(10*1000, 10*1000);
3159 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
3160 usleep_range(40*1000, 40*1000);
3162 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
3163 mach_info->io_enable(); //close lcd out
3167 static struct suspend_info suspend_info = {
3168 .early_suspend.suspend = rk29fb_early_suspend,
3169 .early_suspend.resume = rk29fb_early_resume,
3170 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
3173 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
3174 static int __devinit rk29fb_probe (struct platform_device *pdev)
3176 struct rk29fb_inf *inf = NULL;
3177 struct resource *res = NULL;
3178 struct resource *mem = NULL;
3179 struct rk29fb_info *mach_info = NULL;
3180 struct rk29fb_screen *screen = NULL;
3181 struct win0_par* par = NULL;
3185 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3187 /* Malloc rk29fb_inf and set it to pdev for drvdata */
3188 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
3189 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
3192 dev_err(&pdev->dev, ">> inf kmalloc fail!");
3194 goto release_drvdata;
3196 memset(inf, 0, sizeof(struct rk29fb_inf));
3197 platform_set_drvdata(pdev, inf);
3199 mach_info = pdev->dev.platform_data;
3200 /* Fill screen info and set current screen */
3201 fbprintk(">> Fill screen info and set current screen \n");
3202 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
3203 hdmi_get_default_resolution(&inf->panel1_info);
3205 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
3207 inf->cur_screen = &inf->panel1_info;
3208 screen = inf->cur_screen;
3209 if(SCREEN_NULL==screen->type)
3211 dev_err(&pdev->dev, ">> Please select a display device! \n");
3213 goto release_drvdata;
3216 /* get virtual basic address of lcdc register */
3217 fbprintk(">> get virtual basic address of lcdc register \n");
3218 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
3221 dev_err(&pdev->dev, "failed to get memory registers\n");
3223 goto release_drvdata;
3225 inf->reg_phy_base = res->start;
3226 inf->len = (res->end - res->start) + 1;
3227 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
3230 dev_err(&pdev->dev, "failed to get memory region\n");
3232 goto release_drvdata;
3234 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
3235 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
3236 if (inf->reg_vir_base == NULL)
3238 dev_err(&pdev->dev, "ioremap() of registers failed\n");
3240 goto release_drvdata;
3242 inf->preg = (LCDC_REG*)inf->reg_vir_base;
3244 /* Prepare win1 info */
3245 fbprintk(">> Prepare win1 info \n");
3246 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
3249 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
3252 goto release_win1fb;
3255 par = (struct win0_par*)inf->fb0->par;
3256 strcpy(inf->fb0->fix.id, "fb0");
3257 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
3258 inf->fb0->fix.type_aux = 0;
3259 inf->fb0->fix.xpanstep = 1;
3260 inf->fb0->fix.ypanstep = 1;
3261 inf->fb0->fix.ywrapstep = 0;
3262 inf->fb0->fix.accel = FB_ACCEL_NONE;
3263 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
3264 inf->fb0->fix.smem_len = 0;
3265 inf->fb0->fix.line_length = 0;
3266 inf->fb0->fix.smem_start = 0;
3268 inf->fb0->var.xres = screen->x_res;
3269 inf->fb0->var.yres = screen->y_res;
3270 inf->fb0->var.bits_per_pixel = 16;
3271 inf->fb0_color_deepth = 0;
3272 inf->fb0->var.xres_virtual = screen->x_res;
3273 inf->fb0->var.yres_virtual = screen->y_res;
3274 inf->fb0->var.width = screen->width;
3275 inf->fb0->var.height = screen->height;
3276 //inf->fb0->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
3277 inf->fb0->var.left_margin = screen->left_margin;
3278 inf->fb0->var.right_margin = screen->right_margin;
3279 inf->fb0->var.upper_margin = screen->upper_margin;
3280 inf->fb0->var.lower_margin = screen->lower_margin;
3281 inf->fb0->var.vsync_len = screen->vsync_len;
3282 inf->fb0->var.hsync_len = screen->hsync_len;
3283 inf->fb0->var.red = def_rgb_16.red;
3284 inf->fb0->var.green = def_rgb_16.green;
3285 inf->fb0->var.blue = def_rgb_16.blue;
3286 inf->fb0->var.transp = def_rgb_16.transp;
3288 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
3289 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
3290 inf->fb0->var.activate = FB_ACTIVATE_NOW;
3291 inf->fb0->var.accel_flags = 0;
3292 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
3294 inf->fb0->fbops = &fb0_ops;
3295 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
3296 inf->fb0->pseudo_palette = par->pseudo_pal;
3297 inf->fb0->screen_base = 0;
3299 memset(par, 0, sizeof(struct win0_par));
3301 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
3305 g_fb0_inf = inf->fb0; //add cym@rk 20101027
3307 /* alloc win1 buf */
3308 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
3311 dev_err(&pdev->dev, "failed to get win1 memory \n");
3313 goto release_win1fb;
3315 inf->fb0->fix.smem_start = res->start;
3316 inf->fb0->fix.smem_len = res->end - res->start + 1;
3317 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
3318 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
3320 #ifdef CONFIG_FB_WORK_IPP
3321 /* alloc win1 ipp buf */
3322 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
3325 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
3327 goto release_win1fb;
3329 inf->fb0->fix.mmio_start = res->start;
3330 inf->fb0->fix.mmio_len = res->end - res->start + 1;
3333 /* Prepare win0 info */
3334 fbprintk(">> Prepare win0 info \n");
3335 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
3338 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
3341 goto release_win0fb;
3344 par = (struct win0_par*)inf->fb1->par;
3346 strcpy(inf->fb1->fix.id, "fb1");
3347 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
3348 inf->fb1->fix.type_aux = 0;
3349 inf->fb1->fix.xpanstep = 1;
3350 inf->fb1->fix.ypanstep = 1;
3351 inf->fb1->fix.ywrapstep = 0;
3352 inf->fb1->fix.accel = FB_ACCEL_NONE;
3353 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
3354 inf->fb1->fix.smem_len = 0;
3355 inf->fb1->fix.line_length = 0;
3356 inf->fb1->fix.smem_start = 0;
3358 inf->fb1->var.xres = screen->x_res;
3359 inf->fb1->var.yres = screen->y_res;
3360 inf->fb1->var.bits_per_pixel = 16;
3361 inf->fb1->var.xres_virtual = screen->x_res;
3362 inf->fb1->var.yres_virtual = screen->y_res;
3363 inf->fb1->var.width = screen->width;
3364 inf->fb1->var.height = screen->height;
3365 //inf->fb1->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
3366 inf->fb1->var.left_margin = screen->left_margin;
3367 inf->fb1->var.right_margin = screen->right_margin;
3368 inf->fb1->var.upper_margin = screen->upper_margin;
3369 inf->fb1->var.lower_margin = screen->lower_margin;
3370 inf->fb1->var.vsync_len = screen->vsync_len;
3371 inf->fb1->var.hsync_len = screen->hsync_len;
3372 inf->fb1->var.red = def_rgb_16.red;
3373 inf->fb1->var.green = def_rgb_16.green;
3374 inf->fb1->var.blue = def_rgb_16.blue;
3375 inf->fb1->var.transp = def_rgb_16.transp;
3377 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
3378 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
3379 inf->fb1->var.activate = FB_ACTIVATE_NOW;
3380 inf->fb1->var.accel_flags = 0;
3381 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
3383 inf->fb1->fbops = &fb1_ops;
3384 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
3385 inf->fb1->pseudo_palette = par->pseudo_pal;
3386 inf->fb1->screen_base = 0;
3388 memset(par, 0, sizeof(struct win0_par));
3390 init_waitqueue_head(&par->wait);
3392 /* Init all lcdc and lcd before register_framebuffer. */
3393 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
3394 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
3395 init_lcdc(inf->fb0);
3397 #if 0 //def CONFIG_CPU_FREQ
3398 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
3399 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3401 fbprintk("got clock\n");
3405 struct rk29_fb_setting_info fb_setting;
3406 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
3408 fb_setting.data_num = 24;
3410 else if(OUT_P666 == inf->cur_screen->face )
3412 fb_setting.data_num = 18;
3416 fb_setting.data_num = 16;
3418 fb_setting.den_en = 1;
3419 fb_setting.vsync_en = 1;
3420 fb_setting.disp_on_en = 1;
3421 fb_setting.standby_en = 1;
3422 if( inf->cur_screen->mcu_usefmk )
3423 fb_setting.mcu_fmk_en =1;
3424 mach_info->io_init(&fb_setting);
3427 //set_lcd_pin(pdev, 1);
3430 inf->mcu_usetimer = 1;
3431 inf->mcu_fmksync = 0;
3432 load_screen(inf->fb0, 1);
3434 /* Register framebuffer(fb0 & fb1) */
3435 fbprintk(">> Register framebuffer(fb0) \n");
3436 ret = register_framebuffer(inf->fb0);
3439 printk(">> fb0 register_framebuffer fail!\n");
3441 goto release_win0fb;
3443 fbprintk(">> Register framebuffer(fb1) \n");
3445 ret = register_framebuffer(inf->fb1);
3448 printk(">> fb1 register_framebuffer fail!\n");
3450 goto unregister_win1fb;
3453 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3456 printk(">> fb1 dsp win0 info device_create_file err\n");
3459 #ifdef CONFIG_HAS_EARLYSUSPEND
3460 suspend_info.inf = inf;
3461 register_early_suspend(&suspend_info.early_suspend);
3464 /* get and request irq */
3465 fbprintk(">> get and request irq \n");
3466 irq = platform_get_irq(pdev, 0);
3468 dev_err(&pdev->dev, "no irq for device\n");
3470 goto unregister_win1fb;
3472 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
3474 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
3479 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
3481 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
3484 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
3490 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
3491 fb0_set_par(inf->fb0);
3492 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
3493 /* Start display and show logo on boot */
3494 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
3495 fb_show_logo(inf->fb0, FB_ROTATE_UR);
3496 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
3500 printk(" %s ok\n", __FUNCTION__);
3505 free_irq(irq, pdev);
3507 unregister_framebuffer(inf->fb0);
3510 framebuffer_release(inf->fb1);
3514 fb_dealloc_cmap(&inf->fb0->cmap);
3517 framebuffer_release(inf->fb0);
3520 if(inf && inf->reg_vir_base)
3521 iounmap(inf->reg_vir_base);
3523 release_mem_region(inf->reg_phy_base, inf->len);
3526 platform_set_drvdata(pdev, NULL);
3530 static int __devexit rk29fb_remove(struct platform_device *pdev)
3532 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3533 struct fb_info *info = NULL;
3535 struct rk29fb_info *mach_info = NULL;
3538 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3541 printk("inf==0, rk29_fb_remove fail! \n");
3544 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3546 irq = platform_get_irq(pdev, 0);
3549 free_irq(irq, pdev);
3552 mach_info = pdev->dev.platform_data;
3553 if(mach_info->mcu_fmk_pin)
3555 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
3558 if(mach_info->io_disable)
3559 mach_info->io_disable(); //close lcd out
3563 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
3565 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
3568 //rk29fb_suspend(pdev, msg);
3569 // unmap memory and release framebuffer
3572 if (info->screen_base) {
3573 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3574 info->screen_base = 0;
3575 info->fix.smem_start = 0;
3576 info->fix.smem_len = 0;
3578 unregister_framebuffer(inf->fb1);
3579 framebuffer_release(inf->fb1);
3584 if (info->screen_base) {
3585 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3586 info->screen_base = 0;
3587 info->fix.smem_start = 0;
3588 info->fix.smem_len = 0;
3590 unregister_framebuffer(inf->fb0);
3591 framebuffer_release(inf->fb0);
3595 #if 0 //def CONFIG_CPU_FREQ
3596 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3603 clk_disable(inf->clk);
3609 clk_disable(inf->dclk);
3615 platform_set_drvdata(pdev, NULL);
3620 static void rk29fb_shutdown(struct platform_device *pdev)
3622 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3623 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3625 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3627 if(mach_info->io_disable)
3628 mach_info->io_disable(); //close lcd out
3630 if(!inf->in_suspend)
3632 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3633 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3634 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3636 clk_disable(inf->aclk_ddr_lcdc);
3637 clk_disable(inf->aclk_disp_matrix);
3638 clk_disable(inf->hclk_cpu_display);
3639 clk_disable(inf->clk);
3641 clk_disable(inf->dclk);
3644 clk_disable(inf->aclk);
3646 clk_disable(inf->pd_display);
3647 //pmu_set_power_domain(PD_DISPLAY, 0);
3648 inf->in_suspend = 1;
3653 static struct platform_driver rk29fb_driver = {
3654 .probe = rk29fb_probe,
3655 .remove = __devexit_p(rk29fb_remove),
3658 .owner = THIS_MODULE,
3660 .shutdown = rk29fb_shutdown,
3663 static int __init rk29fb_init(void)
3665 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3666 return platform_driver_register(&rk29fb_driver);
3669 static void __exit rk29fb_exit(void)
3671 platform_driver_unregister(&rk29fb_driver);
3674 fs_initcall(rk29fb_init);
3675 module_exit(rk29fb_exit);
3678 MODULE_AUTHOR(" zyw@rock-chips.com");
3679 MODULE_DESCRIPTION("Driver for rk29 fb device");
3680 MODULE_LICENSE("GPL");