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>
55 #include <mach/iomux.h>
56 #include <mach/gpio.h>
57 #include <mach/board.h>
58 #include <mach/rk29_iomap.h>
60 #include <mach/rk29-ipp.h>
63 #include "./display/screen/screen.h"
65 #ifdef CONFIG_MFD_RK610
66 #include "./display/lcd/rk610_lcd.h"
68 #define ANDROID_USE_THREE_BUFS 0 //android use three buffers to accelerate UI display in rgb plane
69 #define CURSOR_BUF_SIZE 256 //RK2818 cursor need 256B buf
70 int rk29_cursor_buf[CURSOR_BUF_SIZE];
107 #define fbprintk(msg...) printk(msg);
109 #define fbprintk(msg...)
114 #define fbprintk2(msg...) printk(msg);
116 #define fbprintk2(msg...)
119 #define LcdReadBit(inf, addr, msk) ((inf->regbak.addr=inf->preg->addr)&(msk))
120 #define LcdWrReg(inf, addr, val) inf->preg->addr=inf->regbak.addr=(val)
121 #define LcdRdReg(inf, addr) (inf->preg->addr)
122 #define LcdSetBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) |= (msk))
123 #define LcdClrBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) &= ~(msk))
124 #define LcdSetRegisterBit(inf, addr, msk) inf->preg->addr=((inf->preg->addr) |= (msk))
125 #define LcdMskReg(inf, addr, msk, val) (inf->regbak.addr)&=~(msk); inf->preg->addr=(inf->regbak.addr|=(val))
128 #define IsMcuLandscape() ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
129 #define IsMcuUseFmk() ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
131 #define CalScaleW0(x, y) (((u32)x*0x1000)/y)
134 struct fb_bitfield red;
135 struct fb_bitfield green;
136 struct fb_bitfield blue;
137 struct fb_bitfield transp;
140 static struct rk29fb_rgb def_rgb_16 = {
141 red: { offset: 11, length: 5, },
142 green: { offset: 5, length: 6, },
143 blue: { offset: 0, length: 5, },
144 transp: { offset: 0, length: 0, },
148 volatile u32 y_offset;
149 volatile u32 c_offset;
157 u32 xpos; //size in panel
159 u32 xsize; //start point in panel
163 wait_queue_head_t wait;
164 struct win_set mirror;
165 struct win_set displ;
190 void __iomem *reg_vir_base; // virtual basic address of lcdc register
191 u32 reg_phy_base; // physical basic address of lcdc register
192 u32 len; // physical map length of lcdc register
196 struct clk *dclk; //lcdc dclk
197 struct clk *aclk; //lcdc share memory frequency
198 struct clk *aclk_parent; //lcdc aclk divider frequency source
199 struct clk *aclk_ddr_lcdc; //DDR LCDC AXI clock disable.
200 struct clk *aclk_disp_matrix; //DISPLAY matrix AXI clock disable.
201 struct clk *hclk_cpu_display; //CPU DISPLAY AHB bus clock disable.
202 struct clk *pd_display; // display power domain
203 unsigned long dclk_rate;
205 /* lcdc reg base address and backup reg */
210 int fb0_color_deepth;
211 /* variable used in mcu panel */
215 struct timer_list mcutimer;
222 /* external memery */
223 char __iomem *screen_base2;
225 unsigned long smem_start2;
227 char __iomem *cursor_base; /* cursor Virtual address*/
228 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
229 unsigned long cursor_start;
231 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
232 struct rk29fb_screen panel2_info; // 2nd panel
233 struct rk29fb_screen *cur_screen;
234 #if 0 //def CONFIG_CPU_FREQ
235 struct notifier_block freq_transition;
240 typedef enum _TRSP_MODE
252 unsigned long bitperpixel;
261 unsigned long src_uv;
262 unsigned long dst_width;
263 unsigned long dst_height;
264 //struct mutex fb_lock;
265 volatile unsigned long fb_lock;
269 struct wimo_fb_info wimo_info;
270 unsigned char* ui_buffer;
271 unsigned char* ui_buffer_map;
272 //unsigned char* overlay_buffer;
273 //unsigned char* overlay_buffer_map;
276 struct platform_device *g_pdev = NULL;
277 //static int win1fb_set_par(struct fb_info *info);
280 #define CHK_SUSPEND(inf) \
281 if(inf->in_suspend) { \
282 fbprintk(">>>>>> fb is in suspend! return! \n"); \
286 #define CHK_SUSPEND(inf)
288 static DECLARE_WAIT_QUEUE_HEAD(fb0_wait_queue);
289 static volatile int idle_condition = 1; //1:idel, 0:busy
291 static DECLARE_WAIT_QUEUE_HEAD(wq);
292 static int wq_condition = 0;
293 static int wq_condition2 = 0;
294 static int fb1_open_init = 0;
295 #if ANDROID_USE_THREE_BUFS
296 static int new_frame_seted = 1;
298 static struct wake_lock idlelock; /* only for fb */
299 #ifdef CONFIG_FB_ROTATE_VIDEO
301 static bool has_set_rotate;
302 static u32 last_yuv_phy[2] = {0,0};
304 int fb0_first_buff_bits = 32;
305 int fb0_second_buff_bits = 32;
306 int fb_compose_layer_count = 0;
307 static BLOCKING_NOTIFIER_HEAD(rk29fb_notifier_list);
308 int rk29fb_register_notifier(struct notifier_block *nb)
312 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
314 if (inf->cur_screen && inf->cur_screen->type == SCREEN_HDMI)
315 nb->notifier_call(nb, RK29FB_EVENT_HDMI_ON, inf->cur_screen);
316 if (inf->fb1 && inf->fb1->par) {
317 struct win0_par *par = inf->fb1->par;
319 nb->notifier_call(nb, RK29FB_EVENT_FB1_ON, inf->cur_screen);
323 ret = blocking_notifier_chain_register(&rk29fb_notifier_list, nb);
328 int rk29fb_unregister_notifier(struct notifier_block *nb)
330 return blocking_notifier_chain_unregister(&rk29fb_notifier_list, nb);
333 static int rk29fb_notify(struct rk29fb_inf *inf, unsigned long event)
335 return blocking_notifier_call_chain(&rk29fb_notifier_list, event, inf->cur_screen);
337 void rk29_lcd_set(bool on)
339 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
340 if(on == 1 &&mach_info->io_enable)
341 mach_info->io_enable(); //open lcd out
342 else if(mach_info->io_disable)
343 mach_info->io_disable(); //close lcd out
346 int mcu_do_refresh(struct rk29fb_inf *inf)
348 if(inf->mcu_stopflush) return 0;
350 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
355 inf->mcu_needflush = 1;
359 // not use frame mark
360 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
362 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
364 inf->mcu_needflush = 1;
368 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
369 inf->mcu_needflush = 0;
371 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
378 void mcutimer_callback(unsigned long arg)
380 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
381 static int waitcnt = 0;
383 mod_timer(&inf->mcutimer, jiffies + HZ/10);
385 switch(inf->mcu_status)
388 inf->mcu_status = MS_MCU;
391 if(inf->mcu_usetimer) mcu_do_refresh(inf);
394 inf->mcu_status = MS_EWAITEND;
402 inf->mcu_status = MS_EEND;
406 inf->mcu_status = MS_MCU;
409 inf->mcu_status = MS_MCU;
414 int mcu_refresh(struct rk29fb_inf *inf)
416 static int mcutimer_inited = 0;
418 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
423 init_timer(&inf->mcutimer);
424 inf->mcutimer.function = mcutimer_callback;
425 inf->mcutimer.expires = jiffies + HZ/5;
426 inf->mcu_status = MS_IDLE;
427 add_timer(&inf->mcutimer);
430 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
435 int mcu_ioctl(unsigned int cmd, unsigned long arg)
437 struct rk29fb_inf *inf = NULL;
438 if(!g_pdev) return -1;
440 inf = dev_get_drvdata(&g_pdev->dev);
445 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
446 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
447 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
451 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
452 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
456 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
457 LcdWrReg(inf, REG_CFG_DONE, 0x01);
467 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
469 struct platform_device *pdev = (struct platform_device*)dev_id;
470 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
471 struct rk29fb_screen *screen;
473 if(!inf) return IRQ_HANDLED;
475 screen = inf->cur_screen;
477 if(0==screen->mcu_usefmk) {
481 if(inf->mcu_fmksync == 1)
484 inf->mcu_fmksync = 1;
485 if(inf->mcu_needflush)
487 inf->mcu_needflush = 0;
489 if(inf->cur_screen->refresh)
490 inf->cur_screen->refresh(REFRESH_PRE);
491 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
493 inf->mcu_fmksync = 0;
498 int init_lcdc(struct fb_info *info)
500 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
503 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
505 inf->clk = clk_get(NULL, "hclk_lcdc");
506 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
507 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
508 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
509 inf->pd_display = clk_get(NULL, "pd_display");
510 if ((IS_ERR(inf->clk)) ||
511 (IS_ERR(inf->aclk_ddr_lcdc)) ||
512 (IS_ERR(inf->aclk_disp_matrix)) ||
513 (IS_ERR(inf->hclk_cpu_display)) ||
514 (IS_ERR(inf->pd_display)))
516 printk(KERN_ERR "failed to get lcdc_hclk source\n");
517 return PTR_ERR(inf->clk);
519 clk_enable(inf->aclk_disp_matrix);
520 clk_enable(inf->hclk_cpu_display);
521 clk_enable(inf->clk);
522 clk_enable(inf->pd_display);
523 //pmu_set_power_domain(PD_DISPLAY, 1);
524 clk_enable(inf->aclk_ddr_lcdc);
526 // set AHB access rule and disable all windows
527 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
528 LcdWrReg(inf, SWAP_CTRL, 0);
529 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
530 LcdWrReg(inf, AXI_MS_ID, 0x54321);
532 // and mcu holdmode; and set win1 top.
533 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
534 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
536 // disable blank out, black out, tristate out, yuv2rgb bypass
537 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
538 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
539 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
540 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
543 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
544 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
546 LcdWrReg(inf, DSP_CTRL1, 0);
548 // initialize all interrupt
549 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
551 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
553 LcdWrReg(inf, INT_STATUS, clr | msk);
555 // let above to take effect
556 LcdWrReg(inf, REG_CFG_DONE, 0x01);
561 void load_screen(struct fb_info *info, bool initscreen)
564 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
565 struct rk29fb_screen *screen = inf->cur_screen;
567 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
568 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
569 u16 x_res = screen->x_res, y_res = screen->y_res;
570 u32 aclk_rate = 150000000;
573 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
577 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
579 // set the rgb or mcu
580 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
582 // set out format and mcu timing
583 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
584 if(mcu_total>31) mcu_total = 31;
585 if(mcu_total<3) mcu_total = 3;
586 mcu_rwstart = (mcu_total+1)/4 - 1;
587 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
588 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
589 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
591 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
592 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
594 LcdMskReg(inf, MCU_TIMING_CTRL,
595 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
596 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
597 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
598 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
599 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
602 // set synchronous pin polarity and data pin swap rule
603 switch (screen->face)
607 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
611 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
615 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
619 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
623 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
624 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
627 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
628 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
633 LcdMskReg(inf, DSP_CTRL0,
634 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
635 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
636 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
637 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
640 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
642 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
643 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));
645 // set horizontal & vertical out timing
646 if(SCREEN_MCU==inf->cur_screen->type)
648 right_margin = x_res/6;
651 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
652 screen->hsync_len , screen->left_margin , x_res , right_margin );
653 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
654 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
655 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
656 v_BIT12HI(screen->hsync_len + screen->left_margin));
658 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
659 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
660 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
661 v_BIT11HI(screen->vsync_len + screen->upper_margin));
663 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
664 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
666 // let above to take effect
667 LcdWrReg(inf, REG_CFG_DONE, 0x01);
669 inf->dclk = clk_get(NULL, "dclk_lcdc");
670 if (IS_ERR(inf->dclk))
672 printk(KERN_ERR "failed to get lcd dclock source\n");
676 inf->aclk = clk_get(NULL, "aclk_lcdc");
677 if (IS_ERR(inf->aclk))
679 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
682 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
683 if (IS_ERR(inf->aclk_parent))
685 printk(KERN_ERR "failed to get lcd clock parent source\n");
690 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
692 if(initscreen == 0) //not init
694 clk_disable(inf->dclk);
695 // clk_disable(inf->aclk);
698 // clk_disable(inf->aclk_ddr_lcdc);
699 // clk_disable(inf->aclk_disp_matrix);
700 // clk_disable(inf->hclk_cpu_display);
702 // clk_disable(inf->clk);
705 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
707 ret = clk_set_rate(inf->dclk, screen->pixclock);
710 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
712 inf->fb0->var.pixclock = inf->fb1->var.pixclock = div_u64(1000000000000llu, clk_get_rate(inf->dclk));
715 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
716 if(screen->lcdc_aclk){
717 aclk_rate = screen->lcdc_aclk;
719 ret = clk_set_rate(inf->aclk, aclk_rate);
721 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
723 clk_enable(inf->aclk);
725 // clk_enable(inf->aclk_ddr_lcdc);
726 // clk_enable(inf->aclk_disp_matrix);
727 // clk_enable(inf->hclk_cpu_display);
728 // clk_enable(inf->clk);
729 clk_enable(inf->dclk);
737 #if 0 //def CONFIG_CPU_FREQ
739 * CPU clock speed change handler. We need to adjust the LCD timing
740 * parameters when the CPU clock is adjusted by the power management
743 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
746 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
748 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
749 struct rk29fb_screen *screen = inf->cur_screen;
754 case CPUFREQ_PRECHANGE:
756 case CPUFREQ_POSTCHANGE:
758 dclk_rate = screen->pixclock * 1000000;
760 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
762 clk_set_rate(inf->dclk_divider, dclk_rate);
770 static inline unsigned int chan_to_field(unsigned int chan,
771 struct fb_bitfield *bf)
774 chan >>= 16 - bf->length;
775 return chan << bf->offset;
778 static int fb_setcolreg(unsigned regno,
779 unsigned red, unsigned green, unsigned blue,
780 unsigned transp, struct fb_info *info)
783 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
785 switch (info->fix.visual) {
786 case FB_VISUAL_TRUECOLOR:
787 /* true-colour, use pseudo-palette */
789 u32 *pal = info->pseudo_palette;
790 val = chan_to_field(red, &info->var.red);
791 val |= chan_to_field(green, &info->var.green);
792 val |= chan_to_field(blue, &info->var.blue);
797 return -1; /* unknown type */
803 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
806 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
808 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
810 LcdWrReg(inf, REG_CFG_DONE, 0x01);
814 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
816 struct rk29fb_screen *screen = inf->cur_screen;
819 if (x >= 0x800 || y >= 0x800 )
821 //printk("%s: %08x,%08x \n",__func__, x, y);
822 x += (screen->left_margin + screen->hsync_len);
823 y += (screen->upper_margin + screen->vsync_len);
824 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
825 LcdWrReg(inf, REG_CFG_DONE, 0x01);
830 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
832 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
833 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
834 LcdWrReg(inf, REG_CFG_DONE, 0x01);
838 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
839 int rk29_set_cursor_img_transform(char *data)
842 char *dst = (char*)rk29_cursor_buf;
843 unsigned char dmsk = 0;
844 unsigned int op,shift,offset;
846 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
847 * clears it to transparent then combines the cursor
848 * shape plane with the colour plane to set the
850 for (y = 0; y < 32; y++)
852 for (x = 0; x < 32; x++)
859 op = (dmsk & 0x80) ? 2 : 3;
862 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
872 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
876 rk29_set_cursor_img_transform(data);
880 rk29_set_cursor_img_transform(cursor_img);
882 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
883 //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
884 LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
886 LcdWrReg(inf, REG_CFG_DONE, 0x01);
891 int rk29_set_cursor_test(struct fb_info *info)
893 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
894 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
895 rk29_set_cursor_pos(inf, 0, 0);
896 rk29_set_cursor_img(inf, 0);
897 rk29_set_cursor_en(inf, 1);
902 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
904 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
906 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
908 /* check not being asked to exceed capabilities */
910 if (cursor->image.width > 32)
913 if (cursor->image.height > 32)
916 if (cursor->image.depth > 1)
920 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
922 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
925 if (cursor->set & FB_CUR_SETPOS)
927 unsigned int x = cursor->image.dx;
928 unsigned int y = cursor->image.dy;
930 if (x >= 0x800 || y >= 0x800 )
932 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
936 if (cursor->set & FB_CUR_SETCMAP)
938 unsigned int bg_col = cursor->image.bg_color;
939 unsigned int fg_col = cursor->image.fg_color;
941 fbprintk("%s: update cmap (%08x,%08x)\n",
942 __func__, bg_col, fg_col);
944 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
945 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));
947 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
948 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));
951 if ((cursor->set & FB_CUR_SETSIZE ||
952 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
953 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
955 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
956 * clears it to transparent then combines the cursor
957 * shape plane with the colour plane to set the
960 const unsigned char *pcol = cursor->image.data;
961 const unsigned char *pmsk = cursor->mask;
963 unsigned long cursor_mem_start;
964 unsigned char dcol = 0;
965 unsigned char dmsk = 0;
968 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
969 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
971 fbprintk("%s: setting shape (%d,%d)\n",
972 __func__, cursor->image.width, cursor->image.height);
974 memset(dst, 0, CURSOR_BUF_SIZE);
976 for (y = 0; y < cursor->image.height; y++)
978 for (x = 0; x < cursor->image.width; x++)
989 op = (dcol & 1) ? 1 : 3;
990 op <<= ((x % 4) * 2);
991 *(u8*)(dst+(x/4)) |= op;
996 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
997 LcdWrReg(inf, HWC_MST, cursor_mem_start);
998 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
999 if(SCREEN_MCU == inf->cur_screen->type) {
1000 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1004 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1006 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
1012 static int hdmi_get_fbscale(void)
1015 return hdmi_get_scale();
1020 static void hdmi_set_fbscale(struct fb_info *info)
1023 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1024 struct rk29fb_screen *screen = inf->cur_screen;
1025 struct win0_par *par = info->par;
1028 scale = hdmi_get_scale();
1031 par->xpos += screen->x_res * (100-scale) / 200;
1032 par->ypos += screen->y_res * (100-scale) / 200;
1033 par->xsize = par->xsize *scale /100;
1034 par->ysize = par->ysize *scale /100;
1037 static int win0_blank(int blank_mode, struct fb_info *info)
1039 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1041 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1047 case FB_BLANK_UNBLANK:
1048 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1049 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1051 case FB_BLANK_NORMAL:
1052 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1055 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1056 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1057 #ifdef CONFIG_DDR_RECONFIG
1067 static int win0_set_par(struct fb_info *info)
1069 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1070 struct rk29fb_screen *screen = inf->cur_screen;
1071 struct fb_var_screeninfo *var = &info->var;
1072 struct fb_fix_screeninfo *fix = &info->fix;
1073 struct win0_par *par = info->par;
1074 u32 xact, yact, xvir, yvir, xpos, ypos, ScaleYrgbX,ScaleYrgbY, ScaleCbrX, ScaleCbrY, y_addr,uv_addr;
1075 hdmi_set_fbscale(info);
1076 xact = var->xres; /* visible resolution */
1078 xvir = var->xres_virtual; /* virtual resolution */
1079 yvir = var->yres_virtual;
1080 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
1081 //u32 yact_st = var->yoffset; /* resolution */
1090 y_addr = 0; //user alloc buf addr y
1093 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1097 if((var->rotate%360!=0)&& (inf->video_mode))
1099 #ifdef CONFIG_FB_ROTATE_VIDEO
1100 if(xact > screen->x_res)
1102 xact = screen->x_res; /* visible resolution */
1103 yact = screen->y_res;
1104 xvir = screen->x_res; /* virtual resolution */
1105 yvir = screen->y_res;
1107 xact = var->xres; /* visible resolution */
1109 xvir = var->xres_virtual; /* virtual resolution */
1110 yvir = var->yres_virtual;
1111 printk("xact=%d yact =%d \n",xact,yact);
1113 #else //CONFIG_FB_ROTATE_VIDEO
1114 printk("LCDC not support rotate!\n");
1119 // calculate the display phy address
1120 y_addr = fix->smem_start + par->y_offset;
1121 uv_addr = fix->mmio_start + par->c_offset;
1123 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1124 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1126 switch (par->format)
1129 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1130 ScaleCbrY = CalScaleW0(yact, par->ysize);
1134 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1135 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1138 ScaleCbrX= CalScaleW0(xact, par->xsize);
1139 ScaleCbrY = CalScaleW0(yact, par->ysize);
1145 xpos += (screen->left_margin + screen->hsync_len);
1146 ypos += (screen->upper_margin + screen->vsync_len);
1148 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1149 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1151 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1153 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1154 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1155 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1156 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1157 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1158 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1163 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,
1164 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));
1167 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,
1168 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));
1171 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,
1172 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) |
1173 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1176 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,
1177 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) );
1181 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1187 static int win0_pan( struct fb_info *info )
1189 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1190 // struct fb_var_screeninfo *var0 = &info->var;
1191 struct fb_fix_screeninfo *fix0 = &info->fix;
1192 struct win0_par *par = info->par;
1193 u32 y_addr=0, uv_addr=0;
1195 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1199 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1200 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1202 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1203 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1204 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1206 // enable win0 after the win0 addr is seted
1207 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1213 static int win1_blank(int blank_mode, struct fb_info *info)
1215 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1217 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1223 case FB_BLANK_UNBLANK:
1224 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1225 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1227 case FB_BLANK_NORMAL:
1228 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1231 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1232 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1242 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1243 static void win1_check_work_func(struct work_struct *work)
1245 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
1246 struct fb_info *fb0_inf = inf->fb0;
1247 struct fb_var_screeninfo *var = &fb0_inf->var;
1250 int blank_data,total_data;
1252 u16 xres_virtual = fb0_inf->var.xres_virtual; //virtual screen size
1253 u16 xpos_virtual = fb0_inf->var.xoffset; //visiable offset in virtual screen
1254 u16 ypos_virtual = fb0_inf->var.yoffset;
1256 int offset = 0;//(ypos_virtual*xres_virtual + xpos_virtual)*((inf->fb0_color_deepth || fb0_inf->var.bits_per_pixel==32)? 4:2)/4;
1257 switch(var->bits_per_pixel)
1261 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1262 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1263 offset -= var->yres * var->xres *2;
1267 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1268 if(ypos_virtual >= 2*var->yres)
1271 if(ypos_virtual == 3*var->yres)
1273 offset -= var->yres * var->xres *2;
1278 p = (u32)fb0_inf->screen_base + offset;
1279 blank_data = (inf->fb0_color_deepth==32) ? 0xff000000 : 0;
1280 total_data = fb0_inf->var.xres * fb0_inf->var.yres / (format+1);
1282 // 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);
1284 for(i=0; i < total_data; i++)
1286 if(*p++ != blank_data)
1288 //printk("win1 have no 0 data in %d, total %d\n",i,total_data);
1293 win1_blank(FB_BLANK_POWERDOWN, fb0_inf);
1294 // printk("%s close win1!\n",__func__);
1296 static DECLARE_DELAYED_WORK(rk29_win1_check_work, win1_check_work_func);
1298 static int win1_set_par(struct fb_info *info)
1300 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1301 struct fb_fix_screeninfo *fix = &info->fix;
1302 struct rk29fb_screen *screen = inf->cur_screen;
1303 struct win0_par *par = info->par;
1304 struct fb_var_screeninfo *var = &info->var;
1306 u16 xres_virtual,xpos,ypos;
1307 u8 trspval,trspmode;
1308 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1309 cancel_delayed_work_sync(&rk29_win1_check_work);
1311 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1312 #ifndef CONFIG_FB_SCALING_OSD_1080P
1313 && !((screen->x_res>1280) && (var->bits_per_pixel == 32))
1317 hdmi_set_fbscale(info);
1319 #ifndef CONFIG_FB_SCALING_OSD_1080P
1320 else if(((screen->x_res==1920) ))
1322 if(hdmi_get_fbscale() < 100)
1323 par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1326 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1328 xres_virtual = 0; //virtual screen size
1330 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1331 //u16 ypos_virtual = var->yoffset;
1333 xpos = par->xpos; //visiable offset in panel
1336 trspmode = TRSP_CLOSE;
1339 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1341 #ifdef CONFIG_FB_SCALING_OSD
1342 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1343 #ifndef CONFIG_FB_SCALING_OSD_1080P
1344 && (screen->x_res<=1280)
1348 addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1349 xres_virtual = screen->x_res* hdmi_get_fbscale()/100; //virtual screen size
1354 addr = fix->smem_start + par->y_offset;
1355 xres_virtual = var->xres_virtual; //virtual screen size
1357 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(fb1_open_init?0:1)|v_W1_FORMAT(par->format));
1359 xpos += (screen->left_margin + screen->hsync_len);
1360 ypos += (screen->upper_margin + screen->vsync_len);
1362 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1364 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1365 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1367 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1369 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1370 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1372 // enable win1 color key and set the color to black(rgb=0)
1373 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1375 if(1==par->format) //rgb565
1377 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1378 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1382 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1383 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1385 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1388 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1390 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1391 schedule_delayed_work(&rk29_win1_check_work, msecs_to_jiffies(5000));
1397 static int win1_pan( struct fb_info *info )
1399 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1400 struct fb_fix_screeninfo *fix1 = &info->fix;
1401 struct win0_par *par = info->par;
1404 #ifdef CONFIG_FB_SCALING_OSD
1405 struct rk29fb_screen *screen = inf->cur_screen;
1406 struct fb_var_screeninfo *var = &info->var;
1407 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1408 #ifndef CONFIG_FB_SCALING_OSD_1080P
1409 && (screen->x_res<=1280)
1413 addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1418 addr = fix1->smem_start + par->y_offset;
1421 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1423 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1424 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1430 static int fb0_blank(int blank_mode, struct fb_info *info)
1432 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1434 if(inf->video_mode == 1)
1436 win1_blank(blank_mode, info);
1440 win0_blank(blank_mode, info);
1445 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1447 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1448 struct rk29fb_screen *screen = inf->cur_screen;
1449 u16 xpos = (var->nonstd>>8) & 0xfff;
1450 u16 ypos = (var->nonstd>>20) & 0xfff;
1451 u16 xlcd = screen->x_res;
1452 u16 ylcd = screen->y_res;
1454 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1458 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1459 0==var->xres || 0==var->yres || var->xres<16 ||
1460 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1462 printk(">>>>>> fb0_check_var fail 1!!! \n");
1463 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1464 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1465 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1469 if( (var->xoffset+var->xres)>var->xres_virtual ||
1470 (var->yoffset+var->yres)>var->yres_virtual*2 )
1472 printk(">>>>>> fb0_check_var fail 2!!! \n");
1473 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1474 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1475 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1479 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1480 switch(var->bits_per_pixel)
1483 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1484 var->xres = (var->xres + 0x1) & (~0x1);
1485 var->xoffset = (var->xoffset) & (~0x1);
1488 var->bits_per_pixel = 32;
1496 static int fb0_set_par(struct fb_info *info)
1498 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1499 struct fb_var_screeninfo *var = &info->var;
1500 struct fb_fix_screeninfo *fix = &info->fix;
1501 struct rk29fb_screen *screen = inf->cur_screen;
1502 struct win0_par *par = info->par;
1504 u32 offset=0, smem_len=0;
1505 u16 xres_virtual = var->xres_virtual; //virtual screen size
1506 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1507 u16 ypos_virtual = var->yoffset;
1509 #ifdef CONFIG_FB_SCALING_OSD
1510 struct rk29_ipp_req ipp_req;
1512 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1515 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1516 wait_event_interruptible(fb0_wait_queue, idle_condition);
1522 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1523 #if !defined(CONFIG_FB_SCALING_OSD)
1524 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1527 switch(var->bits_per_pixel)
1531 if( ypos_virtual == 0)
1532 fb0_first_buff_bits = 16;
1534 fb0_second_buff_bits = 16;
1536 //fix->line_length = 2 * xres_virtual;
1537 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1539 #ifdef CONFIG_FB_SCALING_OSD
1540 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1541 ipp_req.src0.fmt = IPP_RGB_565;
1542 ipp_req.dst0.fmt = IPP_RGB_565;
1544 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1545 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1546 offset -= var->yres * var->xres *2;
1551 if( ypos_virtual == 0)
1552 fb0_first_buff_bits = 32;
1554 fb0_second_buff_bits = 32;
1555 fix->line_length = 4 * xres_virtual;
1556 #ifdef CONFIG_FB_SCALING_OSD
1557 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1559 ipp_req.src0.fmt = IPP_XRGB_8888;
1560 ipp_req.dst0.fmt = IPP_XRGB_8888;
1562 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1564 if(ypos_virtual >= 2*var->yres)
1567 #ifdef CONFIG_FB_SCALING_OSD
1568 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1569 ipp_req.src0.fmt = IPP_RGB_565;
1570 ipp_req.dst0.fmt = IPP_RGB_565;
1572 if(ypos_virtual == 3*var->yres)
1574 offset -= var->yres * var->xres *2;
1580 smem_len = fix->line_length * var->yres_virtual;
1581 //map_size = PAGE_ALIGN(smem_len);
1583 if (smem_len > fix->smem_len) // buffer need realloc
1585 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1586 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1587 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1591 par->addr_seted = 1;
1592 #if ANDROID_USE_THREE_BUFS
1593 if(0==new_frame_seted) {
1595 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1597 new_frame_seted = 0;
1600 if(inf->video_mode == 1)
1602 #ifdef CONFIG_FB_SCALING_OSD
1603 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1604 #ifndef CONFIG_FB_SCALING_OSD_1080P
1605 && (screen->x_res<=1280)
1611 par->xsize = screen->x_res;
1612 par->ysize = screen->y_res;
1613 par->y_offset = dstoffset;
1615 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1616 ipp_req.src0.w = var->xres;
1617 ipp_req.src0.h = var->yres;
1619 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1620 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1621 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1623 ipp_req.src_vir_w = ipp_req.src0.w;
1624 ipp_req.dst_vir_w = ipp_req.dst0.w;
1625 ipp_req.timeout = 100;
1626 ipp_req.flag = IPP_ROT_0;
1627 //ipp_do_blit(&ipp_req);
1628 ipp_blit_sync(&ipp_req);
1632 par->y_offset = offset;
1633 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1634 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1635 par->xsize = var->xres; //visiable size in panel
1636 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1642 par->y_offset = offset;
1645 par->xsize = screen->x_res;
1646 par->ysize = screen->y_res;
1651 wake_up_interruptible_sync(&fb0_wait_queue);
1655 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1658 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1659 struct fb_var_screeninfo *var1 = &info->var;
1660 struct rk29fb_screen *screen = inf->cur_screen;
1661 struct win0_par *par = info->par;
1664 u16 ypos_virtual = var->yoffset;
1665 u16 xpos_virtual = var->xoffset;
1666 #ifdef CONFIG_FB_SCALING_OSD
1667 struct fb_fix_screeninfo *fix = &info->fix;
1668 struct rk29_ipp_req ipp_req;
1670 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1672 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1676 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1677 #if !defined(CONFIG_FB_SCALING_OSD)
1678 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1681 switch(var1->bits_per_pixel)
1684 var->xoffset = (var->xoffset) & (~0x1);
1685 #ifdef CONFIG_FB_SCALING_OSD
1686 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1687 ipp_req.src0.fmt = IPP_RGB_565;
1688 ipp_req.dst0.fmt = IPP_RGB_565;
1690 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1691 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1692 offset -= var->yres * var->xres *2;
1695 #ifdef CONFIG_FB_SCALING_OSD
1696 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1697 ipp_req.src0.fmt = IPP_XRGB_8888;
1698 ipp_req.dst0.fmt = IPP_XRGB_8888;
1700 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1701 if(ypos_virtual >= 2*var->yres)
1704 #ifdef CONFIG_FB_SCALING_OSD
1705 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1706 ipp_req.src0.fmt = IPP_RGB_565;
1707 ipp_req.dst0.fmt = IPP_RGB_565;
1709 if(ypos_virtual == 3*var->yres)
1711 offset -= var->yres * var->xres *2;
1719 if(inf->video_mode == 1)
1721 #ifdef CONFIG_FB_SCALING_OSD
1722 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1723 #ifndef CONFIG_FB_SCALING_OSD_1080P
1724 && (screen->x_res<=1280)
1728 par->y_offset = dstoffset;
1730 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1731 ipp_req.src0.w = var->xres;
1732 ipp_req.src0.h = var->yres;
1734 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1735 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1736 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1738 ipp_req.src_vir_w = ipp_req.src0.w;
1739 ipp_req.dst_vir_w = ipp_req.dst0.w;
1740 ipp_req.timeout = 100;
1741 ipp_req.flag = IPP_ROT_0;
1742 //ipp_do_blit(&ipp_req);
1743 ipp_blit_sync(&ipp_req);
1748 par->y_offset = offset;
1753 par->y_offset = offset;
1756 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1757 #if !ANDROID_USE_THREE_BUFS
1758 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1759 if(SCREEN_MCU == inf->cur_screen->type) {
1760 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1764 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1771 unsigned long temp_vv;
1772 static int frame_num = 0;
1773 static int wimo_set_buff(struct fb_info *info,unsigned long *temp)
1775 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1777 ui_buffer = temp[0];
1778 ui_buffer_map = ioremap(temp[0],temp[1]);
1779 if(ui_buffer_map == NULL)
1781 printk("can't map a buffer for ui\n");
1785 printk("ui_buffer %x ",ui_buffer_map);
1786 memset(&wimo_info,0,sizeof(wimo_info) );
1788 wimo_info.mode = inf->video_mode;
1789 // wimo_info.bitperpixel = var->bits_per_pixel;
1792 wimo_info.dst_width = (temp[2] + 15) & 0xfff0;
1793 wimo_info.dst_height = (temp[3] + 15) & 0xfff0;
1795 static int wimo_get_buff(struct fb_info *info)
1798 struct rk29_ipp_req overlay_req;
1799 struct rk29_ipp_req overlay_req_1;
1800 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1802 memset(&overlay_req, 0 , sizeof(overlay_req));
1803 memset(&overlay_req_1, 0 , sizeof(overlay_req_1));
1805 if(inf->video_mode == 0 )
1807 struct win0_par *par = info->par;
1810 wimo_info.xsize = 0;
1811 wimo_info.ysize = 0;
1813 if(par->format == 1)
1814 wimo_info.bitperpixel = 16;
1816 wimo_info.bitperpixel =32;// wimo_info.bitperpixel_fb1;
1817 overlay_req.src0.YrgbMst = info->fix.smem_start + par->y_offset;//info->screen_base + par->y_offset;//info_buffer[8];
1818 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];
1819 overlay_req.src0.w = wimo_info.dst_width ;//dst_width;//info_buffer[2];
1820 overlay_req.src0.h = wimo_info.dst_height ;//dst_height;//info_buffer[3];
1821 overlay_req.src0.fmt = (wimo_info.bitperpixel == 16) ? 1 : 0;//3;
1822 overlay_req.dst0.YrgbMst = ui_buffer;//overlay_buffer + info_buffer[4] + info_buffer[5] * dst_width;
1823 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];
1824 overlay_req.dst0.w = wimo_info.dst_width ;//dst_width;//info_buffer[6];
1825 overlay_req.dst0.h = wimo_info.dst_height ;//dst_height;//info_buffer[7];
1826 overlay_req.dst0.fmt = (wimo_info.bitperpixel== 16) ? 1 : 0;//3;3;
1827 overlay_req.deinterlace_enable = 0;
1828 overlay_req.timeout = 1000000;
1829 overlay_req.src_vir_w = wimo_info.dst_width ;//dst_width;//info_buffer[2];
1830 overlay_req.dst_vir_w = wimo_info.dst_width ;//dst_width;
1831 overlay_req.flag = IPP_ROT_0;
1832 ipp_blit_sync(&overlay_req);
1840 static int wimo_time = 0;
1841 unsigned long *overlay_buffer_map_temp;
1842 unsigned long *map_temp;
1843 unsigned long sign_memset = 0;
1844 struct fb_var_screeninfo *var = &inf->fb1->var;
1845 struct win0_par *par = inf->fb1->par;
1847 // printk("overlay setbuffer in\n");
1848 // mutex_lock(&wimo_info.fb_lock);
1849 wimo_info.fb_lock = 1;
1851 wimo_info.xaff = var->xres;
1852 wimo_info.yaff = var->yres;
1853 if((wimo_info.xpos != par->xpos) ||(wimo_info.ypos != par->ypos)||(wimo_info.xsize != par->xsize) ||(wimo_info.ysize != par->ysize))
1855 wimo_info.xpos = par->xpos;
1856 wimo_info.ypos = par->ypos;
1857 wimo_info.xsize = par->xsize;
1858 wimo_info.ysize = par->ysize;
1860 memset(ui_buffer_map,0,wimo_info.dst_height * wimo_info.dst_width);//dst_width*dst_height);
1861 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);
1862 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 );
1865 //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 );
1866 if(wimo_info.xaff * 3 < wimo_info.xsize || wimo_info.yaff * 3 < wimo_info.ysize)// 3time or bigger scale up
1868 unsigned long mid_width, mid_height;
1869 struct rk29_ipp_req overlay_req_1;
1870 if(wimo_info.xaff * 3 < wimo_info.xsize)
1871 mid_width = wimo_info.xaff * 3;
1873 mid_width = wimo_info.xsize;
1875 if(wimo_info.yaff * 3 < wimo_info.ysize)
1876 mid_height = wimo_info.yaff * 3;
1878 mid_height = wimo_info.ysize;
1879 overlay_req.src0.YrgbMst = wimo_info.src_y;//info_buffer[8];
1880 overlay_req.src0.CbrMst = wimo_info.src_uv;//info_buffer[9];
1881 overlay_req.src0.w = wimo_info.xaff;// info_buffer[2];
1882 overlay_req.src0.h = wimo_info.yaff;// info_buffer[3];
1883 overlay_req.src0.fmt = 3;
1884 overlay_req.dst0.YrgbMst = ui_buffer + 2048000 ;//info_buffer[4] + info_buffer[5] * dst_width; //С³ß´çƬԴÐèÒª2´Î·Å´ó£¬ËùÒÔ½«bufferµÄºó°ë¶ÎÓÃÓÚ»º´æ
1885 overlay_req.dst0.CbrMst = (unsigned char*) ui_buffer + mid_height * mid_width + 2048000;
1887 overlay_req.dst0.w = mid_width;//info_buffer[6];
1888 overlay_req.dst0.h = mid_height;//info_buffer[7];
1889 overlay_req.dst0.fmt = 3;
1890 overlay_req.timeout = 100000;
1891 overlay_req.src_vir_w = wimo_info.xaff;//info_buffer[2];
1892 overlay_req.dst_vir_w = mid_width;//dst_width;
1893 overlay_req.flag = IPP_ROT_0;
1895 overlay_req_1.src0.YrgbMst = ui_buffer + 2048000;
1896 overlay_req_1.src0.CbrMst = (unsigned char*) ui_buffer + mid_height * mid_width + 2048000;
1897 overlay_req_1.src0.w = mid_width;
1898 overlay_req_1.src0.h = mid_height;// info_buffer[3];
1899 overlay_req_1.src0.fmt = 3;
1900 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;
1901 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 ;
1903 overlay_req_1.dst0.w = wimo_info.xsize;//info_buffer[6];
1904 overlay_req_1.dst0.h = wimo_info.ysize;//info_buffer[7];
1905 overlay_req_1.dst0.fmt = 3;
1906 overlay_req_1.timeout = 100000;
1907 overlay_req_1.src_vir_w = mid_width;//info_buffer[2];
1908 overlay_req_1.dst_vir_w = wimo_info.dst_width;//dst_width;
1909 overlay_req_1.flag = IPP_ROT_0;
1912 err = ipp_blit_sync(&overlay_req);
1913 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);
1914 err = ipp_blit_sync(&overlay_req_1);
1919 overlay_req.src0.YrgbMst = wimo_info.src_y;//info_buffer[8];
1920 overlay_req.src0.CbrMst = wimo_info.src_uv;//info_buffer[9];
1921 overlay_req.src0.w = wimo_info.xaff;// info_buffer[2];
1922 overlay_req.src0.h = wimo_info.yaff;// info_buffer[3];
1923 overlay_req.src0.fmt = 3;
1924 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;
1925 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 ;
1927 overlay_req.dst0.w = wimo_info.xsize;//wimo_info.xsize;//wimo_info.xaff;// wimo_info.xsize;//info_buffer[6];
1928 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];
1929 overlay_req.dst0.fmt = 3;
1930 overlay_req.timeout = 100000;
1931 overlay_req.src_vir_w = wimo_info.xaff;//info_buffer[2];
1932 overlay_req.dst_vir_w = wimo_info.dst_width;//wimo_info.dst_width;//wimo_info.yaff;//wimo_info.dst_width;//dst_width;
1933 overlay_req.flag = IPP_ROT_0;
1935 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);
1936 err = ipp_blit_sync(&overlay_req);
1939 // printk("overlay setbuffer exit\n");
1941 wimo_info.fb_lock = 0;
1948 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1950 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1951 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1957 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1960 inf->mcu_usetimer = 0;
1963 case FBIOPUT_16OR32:
1965 inf->fb0_color_deepth = arg;
1968 case FBIOGET_16OR32:
1969 return inf->fb0_color_deepth;
1970 case FBIOGET_IDLEFBUff_16OR32:
1971 if(info->var.yoffset == 0)
1973 return fb0_second_buff_bits;
1977 return fb0_first_buff_bits;
1979 case FBIOSET_COMPOSE_LAYER_COUNTS:
1980 fb_compose_layer_count = arg;
1983 case FBIOGET_COMPOSE_LAYER_COUNTS:
1985 return fb_compose_layer_count;
1987 case FBIOPUT_FBPHYADD:
1988 return info->fix.smem_start;
1989 case FBIOGET_OVERLAY_STATE:
1990 return inf->video_mode;
1991 case FBIOGET_SCREEN_STATE:
1992 return inf->cur_screen->type;
1994 case FBIOPUT_SET_CURSOR_EN:
1997 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1999 rk29_set_cursor_en(inf, en);
2002 case FBIOPUT_SET_CURSOR_POS:
2004 struct fbcurpos pos;
2005 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
2007 rk29_set_cursor_pos(inf, pos.x , pos.y);
2010 case FBIOPUT_SET_CURSOR_IMG:
2012 char cursor_buf[CURSOR_BUF_SIZE];
2013 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
2015 rk29_set_cursor_img(inf, cursor_buf);
2018 case FBIOPUT_SET_CURSOR_CMAP:
2020 struct fb_image img;
2021 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
2023 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
2026 case FBIOPUT_GET_CURSOR_RESOLUTION:
2029 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2030 if((inf->fb1->var.rotate &0x1ff ) == 270) {
2031 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
2032 panel_size[1] = inf->cur_screen->x_res;
2034 panel_size[0] = inf->cur_screen->x_res;
2035 panel_size[1] = inf->cur_screen->y_res;
2037 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
2040 case FBIOPUT_GET_CURSOR_EN:
2042 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
2043 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
2047 case FB0_IOCTL_SET_BUF:
2049 unsigned long temp[4];
2050 copy_from_user(temp, (void*)arg, 20);
2051 wimo_set_buff( info,temp);
2055 case FB0_IOCTL_CLOSE_BUF:
2057 if(ui_buffer != NULL && ui_buffer_map !=NULL )
2059 iounmap(ui_buffer_map);
2062 memset(&wimo_info,0,sizeof(wimo_info));
2065 printk("somethint wrong with wimo in close");
2070 case FB0_IOCTL_COPY_CURBUF:
2072 unsigned long temp_data[3];
2073 copy_from_user(&temp_vv, (void*)arg, 4);
2074 if(ui_buffer != NULL && ui_buffer_map !=NULL )
2076 temp_data[1] = wimo_get_buff(info);
2077 temp_data[0] = wimo_info.bitperpixel;
2083 temp_data[0] = wimo_info.bitperpixel;
2084 printk("somethint wrong with wimo in getbuf");
2086 temp_data[2] = frame_num++;
2087 //printk("FB0_IOCTL_COPY_CURBUF %d %d %d\n",temp_data[0],temp_data[1],temp_data[2]);
2088 copy_to_user((void*)arg, &temp_data, 12);
2098 static int fb1_blank(int blank_mode, struct fb_info *info)
2100 win0_blank(blank_mode, info);
2104 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
2106 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2107 struct rk29fb_screen *screen = inf->cur_screen;
2109 u32 ScaleYRGBY=0x1000;
2110 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
2111 u16 ypos = (var->nonstd>>20) & 0xfff;
2112 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
2113 u16 ysize = (var->grayscale>>20) & 0xfff;
2114 u16 xlcd = screen->x_res; //size of panel
2115 u16 ylcd = screen->y_res;
2118 struct hdmi *hdmi = get_hdmi_struct(0);
2121 if((var->rotate & 0x1ff) == 90 ||(var->rotate &0x1ff)== 270) {
2122 #ifdef CONFIG_FB_ROTATE_VIDEO
2123 xlcd = screen->y_res;
2124 ylcd = screen->x_res;
2125 #else //CONFIG_FB_ROTATE_VIDEO
2126 printk("LCDC not support rotate!\n");
2131 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2132 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2133 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2134 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2136 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2140 if( 0==var->xres_virtual || 0==var->yres_virtual ||
2141 0==var->xres || 0==var->yres || var->xres<16 ||
2142 0==xsize || 0==ysize || xsize<16 ||
2143 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
2145 printk(">>>>>> win0fb_check_var fail 1!!! \n");
2146 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
2147 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
2148 var->bits_per_pixel, var->bits_per_pixel);
2152 if( (var->xoffset+var->xres)>var->xres_virtual ||
2153 (var->yoffset+var->yres)>var->yres_virtual ||
2154 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
2156 printk(">>>>>> win0fb_check_var fail 2!!! \n");
2157 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
2158 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
2159 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
2163 switch(var->nonstd&0x0f)
2166 switch(var->bits_per_pixel)
2169 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
2170 var->xres = (var->xres + 0x1) & (~0x1);
2171 var->xoffset = (var->xoffset) & (~0x1);
2174 var->bits_per_pixel = 32;
2177 var->nonstd &= ~0xc0; //not support I2P in this format
2180 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2181 var->xres = (var->xres + 0x3) & (~0x3);
2182 var->xoffset = (var->xoffset) & (~0x3);
2185 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2186 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
2187 var->xres = (var->xres + 0x3) & (~0x3);
2188 var->yres = (var->yres + 0x1) & (~0x1);
2189 var->xoffset = (var->xoffset) & (~0x3);
2190 var->yoffset = (var->yoffset) & (~0x1);
2193 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2194 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
2195 var->xres = (var->xres + 0x3) & (~0x3);
2196 var->yres = (var->yres + 0x1) & (~0x1);
2197 var->xoffset = (var->xoffset) & (~0x3);
2198 var->yoffset = (var->yoffset) & (~0x1);
2199 var->nonstd &= ~0xc0; //not support I2P in this format
2203 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2204 var->xres = (var->xres + 0x3) & (~0x3);
2205 var->xoffset = (var->xoffset) & (~0x3);
2206 var->nonstd &= ~0xc0; //not support I2P in this format
2209 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
2213 if((var->rotate & 0x1ff ) == 90 ||(var->rotate & 0x1ff ) == 270)
2222 ScaleYRGBY = CalScaleW0(yres, ysize);
2224 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
2226 return -EINVAL; // multiple of scale down or scale up can't exceed 8
2229 if(inf->video_mode == 1) {
2230 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
2232 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2233 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2234 init_completion(&hdmi->complete);
2236 wait_for_completion_interruptible_timeout(&hdmi->complete,
2237 msecs_to_jiffies(10000));
2244 static int fb1_set_par(struct fb_info *info)
2246 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2247 struct rk29fb_screen *screen = inf->cur_screen;
2248 struct fb_var_screeninfo *var = &info->var;
2249 struct fb_fix_screeninfo *fix = &info->fix;
2250 struct win0_par *par = info->par;
2253 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
2255 //u32 xact = var->xres; /* visible resolution */
2256 //u32 yact = var->yres;
2257 u32 xvir = var->xres_virtual; /* virtual resolution */
2258 u32 yvir = var->yres_virtual;
2259 u32 xact_st = var->xoffset; /* offset from virtual to visible */
2260 u32 yact_st = var->yoffset; /* resolution */
2262 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
2263 u16 ypos = (var->nonstd>>20) & 0xfff;
2264 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
2265 u16 ysize = (var->grayscale>>20) & 0xfff;
2267 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
2268 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
2270 u8 data_format = var->nonstd&0x0f;
2271 // u32 win0_en = var->reserved[2];
2272 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
2273 // u32 uv_addr = var->reserved[4];
2275 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2277 if((var->rotate & 0x1ff ) == 90 || (var->rotate & 0x1ff ) == 270)
2279 #ifdef CONFIG_FB_ROTATE_VIDEO
2280 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
2281 ypos = (var->nonstd>>8) & 0xfff;
2282 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
2283 ysize = (var->grayscale>>8) & 0xfff;
2284 #else //CONFIG_FB_ROTATE_VIDEO
2285 printk("LCDC not support rotate!\n");
2289 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2290 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2291 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2292 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2294 /* calculate y_offset,c_offset,line_length,cblen and crlen */
2295 switch (data_format)
2298 switch(var->bits_per_pixel)
2302 fix->line_length = 2 * xvir;
2303 par->y_offset = (yact_st*xvir + xact_st)*2;
2307 fix->line_length = 4 * xvir;
2308 par->y_offset = (yact_st*xvir + xact_st)*4;
2316 fix->line_length = xvir;
2317 cblen = crlen = (xvir*yvir)/2;
2318 par->y_offset = yact_st*xvir + xact_st;
2319 par->c_offset = yact_st*xvir + xact_st;
2323 fix->line_length = xvir;
2324 cblen = crlen = (xvir*yvir)/4;
2326 par->y_offset = yact_st*xvir + xact_st;
2327 par->c_offset = (yact_st/2)*xvir + xact_st;
2332 fix->line_length = xvir;
2333 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
2334 par->c_offset = (yact_st/2)*xvir + xact_st;
2335 cblen = crlen = (xvir*yvir)/4;
2340 fix->line_length = xvir;
2341 par->y_offset = yact_st*xvir + xact_st;
2342 par->c_offset = yact_st*2*xvir + xact_st*2;
2343 cblen = crlen = (xvir*yvir);
2349 smem_len = fix->line_length * yvir + cblen + crlen;
2350 map_size = PAGE_ALIGN(smem_len);
2352 // fix->smem_start = y_addr;
2353 fix->smem_len = smem_len;
2354 // fix->mmio_start = uv_addr;
2356 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
2357 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);
2359 par->format = format;
2366 if ( wq_condition2 == 0 ) {
2367 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
2371 #ifdef CONFIG_FB_ROTATE_VIDEO
2372 //need refresh ,zyc add
2373 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
2376 struct rk29_ipp_req ipp_req;
2377 static u32 dstoffset = 0;
2378 static int fb_index = 0;
2379 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2380 yuv_phy[0] = last_yuv_phy[0];
2381 yuv_phy[1] = last_yuv_phy[1];
2382 yuv_phy[0] += par->y_offset;
2383 yuv_phy[1] += par->c_offset;
2385 if((var->rotate == 90) ||(var->rotate == 270))
2387 if(var->rotate%360 != 0)
2390 #ifdef CONFIG_FB_ROTATE_VIDEO
2391 dstoffset = (dstoffset+1)%2;
2392 ipp_req.src0.fmt = 3;
2393 ipp_req.src0.YrgbMst = yuv_phy[0];
2394 ipp_req.src0.CbrMst = yuv_phy[1];
2395 ipp_req.src0.w = var->xres;
2396 ipp_req.src0.h = var->yres;
2398 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2399 ipp_req.dst_vir_w=screen->x_res;
2401 ipp_req.dst0.fmt = 3;
2402 #ifdef CONFIG_FB_MIRROR_X_Y
2403 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2405 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*4;
2406 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*5;
2410 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2411 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2414 if(var->xres > screen->x_res)
2416 ipp_req.dst0.w = screen->x_res;
2417 ipp_req.dst0.h = screen->y_res;
2419 ipp_req.dst0.w = var->xres;
2420 ipp_req.dst0.h = var->yres;
2422 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2423 ipp_req.timeout = 100;
2424 if((var->rotate & 0x1ff) == 90)
2425 ipp_req.flag = IPP_ROT_90;
2426 else if ((var->rotate & 0x1ff) == 180)
2427 ipp_req.flag = IPP_ROT_180;
2428 else if((var->rotate & 0x1ff) == 270)
2429 ipp_req.flag = IPP_ROT_270;
2430 else 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;
2434 //ipp_do_blit(&ipp_req);
2435 ipp_blit_sync(&ipp_req);
2436 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2437 yuv_phy[1] = ipp_req.dst0.CbrMst;
2438 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2440 memset(&ipp_req,0,sizeof(struct rk29_ipp_req));
2442 if((var->rotate & X_MIRROR) == X_MIRROR)
2443 ipp_req.flag = IPP_ROT_X_FLIP;
2444 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2445 ipp_req.flag = IPP_ROT_Y_FLIP;
2447 printk(">>>>>> %d rotate is not support!\n",var->rotate);
2449 if(var->xres > screen->x_res)
2451 ipp_req.dst0.w = screen->x_res;
2452 ipp_req.dst0.h = screen->y_res;
2454 ipp_req.dst0.w = var->xres;
2455 ipp_req.dst0.h = var->yres;
2457 ipp_req.src0.fmt = 3;
2458 ipp_req.src0.YrgbMst = yuv_phy[0];
2459 ipp_req.src0.CbrMst = yuv_phy[1];
2460 ipp_req.src0.w = ipp_req.dst0.w;
2461 ipp_req.src0.h = ipp_req.dst0.h;
2463 ipp_req.src_vir_w= (ipp_req.dst0.w + 15) & (~15);
2464 ipp_req.dst_vir_w= (ipp_req.dst0.w + 15) & (~15);
2466 ipp_req.dst0.fmt = 3;
2467 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2468 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2470 ipp_req.timeout = 100;
2471 ipp_blit_sync(&ipp_req);
2472 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2473 yuv_phy[1] = ipp_req.dst0.CbrMst;
2475 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2477 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2478 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2479 if(var->xres > screen->x_res)
2481 ipp_req.dst0.w = screen->x_res;
2482 ipp_req.dst0.h = screen->y_res;
2484 ipp_req.dst0.w = var->xres;
2485 ipp_req.dst0.h = var->yres;
2488 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2489 ipp_req.timeout = 100;
2490 if(var->rotate == 90)
2491 ipp_req.flag = IPP_ROT_90;
2492 else if(var->rotate == 180)
2493 ipp_req.flag = IPP_ROT_180;
2494 else if(var->rotate == 270)
2495 ipp_req.flag = IPP_ROT_270;
2496 //ipp_do_blit(&ipp_req);
2497 ipp_blit_sync(&ipp_req);
2499 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2500 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2501 yuv_phy[1] = ipp_req.dst0.CbrMst;
2503 fix->smem_start = yuv_phy[0];
2504 fix->mmio_start = yuv_phy[1];
2505 #else //CONFIG_FB_ROTATE_VIDEO
2506 printk("LCDC not support rotate!\n");
2512 fix->smem_start = yuv_phy[0];
2513 fix->mmio_start = yuv_phy[1];
2516 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2517 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2518 // enable win0 after the win0 par is seted
2519 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2520 par->addr_seted = 1;
2521 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2522 if(par->addr_seted ) {
2523 unsigned long flags;
2525 local_irq_save(flags);
2526 par->mirror.y_offset = yuv_phy[0];
2527 par->mirror.c_offset = yuv_phy[1];
2528 local_irq_restore(flags);
2531 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2536 has_set_rotate = false;
2541 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2543 struct win0_par *par = info->par;
2544 // enable win0 after the win0 addr is seted
2551 int fb1_open(struct fb_info *info, int user)
2553 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2554 struct win0_par *par = info->par;
2555 struct rk29fb_screen *screen = inf->cur_screen;
2557 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2560 par->addr_seted = 0;
2561 inf->video_mode = 1;
2563 #ifdef CONFIG_FB_ROTATE_VIDEO
2564 //reinitialize the var when open,zyc
2565 last_yuv_phy[0] = 0;
2566 last_yuv_phy[1] = 0;
2570 printk(">>>>>> fb1 has opened! \n");
2574 win0_blank(FB_BLANK_NORMAL, info);
2575 if(screen->x_res>1280)
2577 fb0_set_par(inf->fb0);
2579 rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2584 int fb1_release(struct fb_info *info, int user)
2586 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2587 struct win0_par *par = info->par;
2588 struct fb_var_screeninfo *var0 = &info->var;
2590 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2591 if(inf->setFlag == 0)
2593 wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2597 inf->video_mode = 0;
2599 par->addr_seted = 0;
2600 win1_blank(FB_BLANK_NORMAL, info);
2602 //if(inf->cur_screen->type != SCREEN_HDMI)
2603 fb0_set_par(inf->fb0);
2606 info->screen_base = 0;
2607 info->fix.smem_start = 0;
2608 info->fix.smem_len = 0;
2609 // clean the var param
2610 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2611 rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2612 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2613 cancel_delayed_work_sync(&rk29_win1_check_work);
2620 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2622 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2623 struct win0_par *par = info->par;
2624 struct fb_fix_screeninfo *fix0 = &info->fix;
2625 struct fb_var_screeninfo *var = &info->var;
2626 void __user *argp = (void __user *)arg;
2628 #ifdef CONFIG_FB_ROTATE_VIDEO
2629 struct rk29fb_screen *screen = inf->cur_screen;
2630 struct rk29_ipp_req ipp_req;
2631 static u32 dstoffset = 0;
2632 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2635 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2636 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2642 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2645 if((var->rotate & 0x1ff) == 270 ||(var->rotate & 0x1ff) == 90) {
2646 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2647 panel_size[1] = inf->panel1_info.x_res;
2649 panel_size[0] = inf->panel1_info.x_res;
2650 panel_size[1] = inf->panel1_info.y_res;
2653 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2657 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2661 // printk("FB1_IOCTL_SET_YUV_ADDR1 \n");
2662 // while(wimo_info.fb_lock)
2666 // printk("FB1_IOCTL_SET_YUV_ADDR 2\n");
2668 if (copy_from_user(yuv_phy, argp, 8))
2670 #ifdef CONFIG_FB_ROTATE_VIDEO
2672 if(has_set_rotate == true)
2674 last_yuv_phy[0] = yuv_phy[0];
2675 last_yuv_phy[1] = yuv_phy[1];
2678 fix0->smem_start = yuv_phy[0];
2679 fix0->mmio_start = yuv_phy[1];
2680 yuv_phy[0] += par->y_offset;
2681 yuv_phy[1] += par->c_offset;
2683 wimo_info.src_y = yuv_phy[0];
2684 wimo_info.src_uv = yuv_phy[1];
2689 if((var->rotate == 90) ||(var->rotate == 270))
2691 if(var->rotate%360 != 0)
2694 #ifdef CONFIG_FB_ROTATE_VIDEO
2695 dstoffset = (dstoffset+1)%2;
2696 ipp_req.src0.fmt = 3;
2697 ipp_req.src0.YrgbMst = yuv_phy[0];
2698 ipp_req.src0.CbrMst = yuv_phy[1];
2699 ipp_req.src0.w = var->xres ;
2700 ipp_req.src0.h = var->yres ;
2701 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2702 ipp_req.dst_vir_w=screen->x_res;
2704 ipp_req.dst0.fmt = 3;
2705 #ifdef CONFIG_FB_MIRROR_X_Y
2706 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2708 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*4;
2709 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*5;
2713 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2714 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2717 if(var->xres > screen->x_res)
2719 ipp_req.dst0.w = screen->x_res;
2720 ipp_req.dst0.h = screen->y_res;
2722 ipp_req.dst0.w = var->xres;
2723 ipp_req.dst0.h = var->yres;
2725 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2726 ipp_req.timeout = 100;
2727 if((var->rotate & 0x1ff) == 90)
2728 ipp_req.flag = IPP_ROT_90;
2729 else if ((var->rotate & 0x1ff) == 180)
2730 ipp_req.flag = IPP_ROT_180;
2731 else if((var->rotate & 0x1ff) == 270)
2732 ipp_req.flag = IPP_ROT_270;
2733 else 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;
2737 //ipp_do_blit(&ipp_req);
2738 ipp_blit_sync(&ipp_req);
2739 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2740 yuv_phy[1] = ipp_req.dst0.CbrMst;
2741 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2743 memset(&ipp_req,0,sizeof(struct rk29_ipp_req));
2745 if((var->rotate & X_MIRROR) == X_MIRROR)
2746 ipp_req.flag = IPP_ROT_X_FLIP;
2747 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2748 ipp_req.flag = IPP_ROT_Y_FLIP;
2750 printk(">>>>>> %d rotate is not support!\n",var->rotate);
2752 if(var->xres > screen->x_res)
2754 ipp_req.dst0.w = screen->x_res;
2755 ipp_req.dst0.h = screen->y_res;
2757 ipp_req.dst0.w = var->xres;
2758 ipp_req.dst0.h = var->yres;
2760 ipp_req.src0.fmt = 3;
2761 ipp_req.src0.YrgbMst = yuv_phy[0];
2762 ipp_req.src0.CbrMst = yuv_phy[1];
2763 ipp_req.src0.w = ipp_req.dst0.w;
2764 ipp_req.src0.h = ipp_req.dst0.h;
2766 ipp_req.src_vir_w= (ipp_req.dst0.w + 15) & (~15);
2767 ipp_req.dst_vir_w= (ipp_req.dst0.w + 15) & (~15);
2769 ipp_req.dst0.fmt = 3;
2770 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2771 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2773 ipp_req.timeout = 100;
2774 ipp_blit_sync(&ipp_req);
2775 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2776 yuv_phy[1] = ipp_req.dst0.CbrMst;
2778 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2780 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2781 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2782 if(var->xres > screen->x_res)
2784 ipp_req.dst0.w = screen->x_res;
2785 ipp_req.dst0.h = screen->y_res;
2787 ipp_req.dst0.w = var->xres;
2788 ipp_req.dst0.h = var->yres;
2791 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2792 ipp_req.timeout = 100;
2793 if(var->rotate == 90)
2794 ipp_req.flag = IPP_ROT_90;
2795 else if(var->rotate == 180)
2796 ipp_req.flag = IPP_ROT_180;
2797 else if(var->rotate == 270)
2798 ipp_req.flag = IPP_ROT_270;
2799 //ipp_do_blit(&ipp_req);
2800 ipp_blit_sync(&ipp_req);
2802 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2803 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2804 yuv_phy[1] = ipp_req.dst0.CbrMst;
2806 fix0->smem_start = yuv_phy[0];
2807 fix0->mmio_start = yuv_phy[1];
2808 #else //CONFIG_FB_ROTATE_VIDEO
2809 printk("LCDC not support rotate!\n");
2813 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2814 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2815 // enable win0 after the win0 par is seted
2816 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2817 par->addr_seted = 1;
2818 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2819 if(par->par_seted) {
2820 unsigned long flags;
2822 local_irq_save(flags);
2823 par->mirror.y_offset = yuv_phy[0];
2824 par->mirror.c_offset = yuv_phy[1];
2825 local_irq_restore(flags);
2828 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2833 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2834 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2835 #ifdef CONFIG_FB_ROTATE_VIDEO
2837 has_set_rotate = true;
2838 #ifdef CONFIG_FB_MIRROR_X_Y
2839 if( ((arg&0x1ff)%90) == 0 && ( arg&(~0xfff))==0 )
2841 if( (arg&( X_MIRROR | Y_MIRROR ) )== (X_MIRROR | Y_MIRROR) )
2842 var->rotate = ROTATE_180;
2843 else if((arg&( ROTATE_90 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_90 | X_MIRROR | Y_MIRROR))
2844 var->rotate = ROTATE_270;
2845 else if((arg&( ROTATE_180 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_180 | X_MIRROR | Y_MIRROR))
2846 var->rotate = ROTATE_90;
2847 else if((arg&( ROTATE_270 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_270 | X_MIRROR | Y_MIRROR))
2848 var->rotate = ROTATE_0;
2851 if(arg == ROTATE_0 || arg==ROTATE_90 || arg == ROTATE_180 || arg==ROTATE_270)
2857 printk(">>>>>> %d rotate is not support!\n",(int)arg);
2859 #else //CONFIG_FB_ROTATE_VIDEO
2860 printk("LCDC not support rotate!\n");
2863 case FB1_IOCTL_SET_WIN0_TOP:
2864 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2865 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2866 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2874 static struct fb_ops fb1_ops = {
2875 .owner = THIS_MODULE,
2876 .fb_open = fb1_open,
2877 .fb_release = fb1_release,
2878 .fb_check_var = fb1_check_var,
2879 .fb_set_par = fb1_set_par,
2880 .fb_blank = fb1_blank,
2881 .fb_pan_display = fb1_pan_display,
2882 .fb_ioctl = fb1_ioctl,
2883 .fb_setcolreg = fb_setcolreg,
2884 .fb_fillrect = cfb_fillrect,
2885 .fb_copyarea = cfb_copyarea,
2886 .fb_imageblit = cfb_imageblit,
2889 static struct fb_ops fb0_ops = {
2890 .owner = THIS_MODULE,
2891 .fb_check_var = fb0_check_var,
2892 .fb_set_par = fb0_set_par,
2893 .fb_blank = fb0_blank,
2894 .fb_pan_display = fb0_pan_display,
2895 .fb_ioctl = fb0_ioctl,
2896 .fb_setcolreg = fb_setcolreg,
2897 .fb_fillrect = cfb_fillrect,
2898 .fb_copyarea = cfb_copyarea,
2899 .fb_imageblit = cfb_imageblit,
2900 //.fb_cursor = rk29_set_cursor,
2903 int fb_get_video_mode(void)
2905 struct rk29fb_inf *inf;
2908 inf = platform_get_drvdata(g_pdev);
2909 return inf->video_mode;
2912 enable: 1, switch to tv or hdmi; 0, switch to lcd
2914 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2916 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2917 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2918 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2920 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2922 if(enable)inf->cur_screen = &inf->panel2_info;
2923 else inf->cur_screen = &inf->panel1_info;
2925 /* Black out, because some display device need clock to standby */
2926 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2927 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2928 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2929 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2930 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2931 wake_lock(&idlelock);
2933 wake_unlock(&idlelock);
2935 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2936 // operate the display_on pin to power down the lcd
2937 #ifdef CONFIG_HDMI_DUAL_DISP
2938 if(inf->panel1_info.sscreen_get!=NULL)
2939 inf->panel1_info.sscreen_get(&inf->panel1_info,inf->panel2_info.hdmi_resolution);
2941 printk("warnig : LCD driver do not support dual display");
2942 if(inf->panel1_info.sscreen_set!=NULL)
2943 inf->panel1_info.sscreen_set(&inf->panel1_info,enable);
2945 printk("warnig : LCD driver do not support dual display");
2947 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2948 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2950 load_screen(inf->fb0, 0);
2953 fb1_set_par(inf->fb1);
2954 fb0_set_par(inf->fb0);
2955 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2956 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2958 rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2962 static ssize_t dsp_win0_info_read(struct device *device,
2963 struct device_attribute *attr, char *buf)
2966 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2967 struct rk29fb_screen *screen = inf->cur_screen;
2969 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2971 fbprintk("%s\n",__FUNCTION__);
2972 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2973 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2975 xpos -= (screen->left_margin + screen->hsync_len);
2976 ypos -= (screen->upper_margin + screen->vsync_len);
2978 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2979 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2980 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2981 rk29_set_cursor_test(inf->fb0);
2983 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2986 static ssize_t dsp_win0_info_write(struct device *device,
2987 struct device_attribute *attr, const char *buf, size_t count)
2989 printk("%s\n",__FUNCTION__);
2990 printk("%s %x \n",__FUNCTION__,*buf);
2994 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2996 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2998 struct platform_device *pdev = (struct platform_device*)dev_id;
2999 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3000 struct win0_par *par = (struct win0_par *)inf->fb1->par;
3004 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
3006 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
3008 if(SCREEN_MCU == inf->cur_screen->type)
3010 inf->mcu_isrcnt = !inf->mcu_isrcnt;
3016 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
3018 inf->mcu_fmksync = 1;
3019 if(inf->cur_screen->refresh)
3020 inf->cur_screen->refresh(REFRESH_END);
3021 inf->mcu_fmksync = 0;
3030 if(inf->mcu_needflush) {
3031 if(inf->cur_screen->refresh)
3032 inf->cur_screen->refresh(REFRESH_PRE);
3033 inf->mcu_needflush = 0;
3034 inf->mcu_isrcnt = 0;
3035 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
3037 if(inf->cur_screen->refresh)
3038 inf->cur_screen->refresh(REFRESH_END);
3042 #if ANDROID_USE_THREE_BUFS
3043 new_frame_seted = 1;
3046 if(waitqueue_active(&par->wait)) {
3047 if (par->mirror.c_offset == 0)
3048 printk("error: no new buffer to display\n");
3050 par->done.y_offset = par->displ.y_offset;
3051 par->done.c_offset = par->displ.c_offset;
3052 par->displ.y_offset = par->mirror.y_offset;
3053 par->displ.c_offset = par->mirror.c_offset;
3054 par->mirror.y_offset = 0;
3055 par->mirror.c_offset = 0;
3057 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
3058 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
3059 wake_up_interruptible(&par->wait);
3064 wake_up_interruptible(&wq);
3066 rk29fb_irq_notify_ddr();
3070 #ifdef CONFIG_HAS_EARLYSUSPEND
3072 struct suspend_info {
3073 struct early_suspend early_suspend;
3074 struct rk29fb_inf *inf;
3077 static void rk29fb_early_suspend(struct early_suspend *h)
3079 struct suspend_info *info = container_of(h, struct suspend_info,
3082 struct rk29fb_inf *inf = info->inf;
3083 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
3085 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3088 printk("inf==0, rk29fb_suspend fail! \n");
3092 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
3093 cancel_delayed_work_sync(&rk29_win1_check_work);
3095 #ifdef CONFIG_HDMI_DUAL_DISP
3096 if(mach_info->io_disable) // close lcd pwr when output screen is lcd
3097 mach_info->io_disable(); //close lcd out
3099 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
3100 mach_info->io_disable(); //close lcd out
3102 if(inf->cur_screen->standby)
3104 fbprintk(">>>>>> power down the screen! \n");
3105 inf->cur_screen->standby(1);
3107 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE | m_W1_ENABLE, v_W0_ENABLE(0) | v_W1_ENABLE(0));
3109 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
3110 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
3112 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3113 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3114 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3116 if(!inf->in_suspend)
3118 fbprintk(">>>>>> diable the lcdc clk! \n");
3119 wake_lock(&idlelock);
3121 wake_unlock(&idlelock);
3122 clk_disable(inf->aclk_ddr_lcdc);
3123 clk_disable(inf->aclk_disp_matrix);
3124 clk_disable(inf->hclk_cpu_display);
3125 clk_disable(inf->clk);
3127 clk_disable(inf->dclk);
3130 clk_disable(inf->aclk);
3132 //clk_disable(inf->pd_display);
3134 inf->in_suspend = 1;
3138 static void rk29fb_early_resume(struct early_suspend *h)
3140 struct suspend_info *info = container_of(h, struct suspend_info,
3143 struct rk29fb_inf *inf = info->inf;
3144 struct rk29fb_screen *screen = inf->cur_screen;
3145 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
3147 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3149 printk("inf==0, rk29fb_resume fail! \n");
3155 inf->in_suspend = 0;
3156 fbprintk(">>>>>> enable the lcdc clk! \n");
3157 // clk_enable(inf->pd_display);
3158 clk_enable(inf->aclk_disp_matrix);
3159 clk_enable(inf->hclk_cpu_display);
3160 clk_enable(inf->clk);
3161 clk_enable(inf->aclk_ddr_lcdc);
3164 clk_enable(inf->dclk);
3167 clk_enable(inf->aclk);
3169 usleep_range(100*1000, 100*1000);
3171 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
3172 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
3173 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3175 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
3176 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
3178 if(inf->cur_screen->standby)
3180 fbprintk(">>>>>> power on the screen! \n");
3181 inf->cur_screen->standby(0);
3183 usleep_range(10*1000, 10*1000);
3184 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
3185 usleep_range(40*1000, 40*1000);
3186 #ifdef CONFIG_HDMI_DUAL_DISP
3187 if(mach_info->io_enable) // open lcd pwr when output screen is lcd
3188 mach_info->io_enable(); //close lcd out
3190 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
3191 mach_info->io_enable(); //close lcd out
3195 static struct suspend_info suspend_info = {
3196 .early_suspend.suspend = rk29fb_early_suspend,
3197 .early_suspend.resume = rk29fb_early_resume,
3198 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
3201 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
3202 static int __devinit rk29fb_probe (struct platform_device *pdev)
3204 struct rk29fb_inf *inf = NULL;
3205 struct resource *res = NULL;
3206 struct resource *mem = NULL;
3207 struct rk29fb_info *mach_info = NULL;
3208 struct rk29fb_screen *screen = NULL;
3209 struct win0_par* par = NULL;
3213 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3215 /* Malloc rk29fb_inf and set it to pdev for drvdata */
3216 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
3217 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
3220 dev_err(&pdev->dev, ">> inf kmalloc fail!");
3222 goto release_drvdata;
3224 memset(inf, 0, sizeof(struct rk29fb_inf));
3225 platform_set_drvdata(pdev, inf);
3227 mach_info = pdev->dev.platform_data;
3228 /* Fill screen info and set current screen */
3229 fbprintk(">> Fill screen info and set current screen \n");
3230 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
3231 hdmi_get_default_resolution(&inf->panel1_info);
3233 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
3236 inf->cur_screen = &inf->panel1_info;
3237 screen = inf->cur_screen;
3238 if(SCREEN_NULL==screen->type)
3240 dev_err(&pdev->dev, ">> Please select a display device! \n");
3242 goto release_drvdata;
3245 /* get virtual basic address of lcdc register */
3246 fbprintk(">> get virtual basic address of lcdc register \n");
3247 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
3250 dev_err(&pdev->dev, "failed to get memory registers\n");
3252 goto release_drvdata;
3254 inf->reg_phy_base = res->start;
3255 inf->len = (res->end - res->start) + 1;
3256 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
3259 dev_err(&pdev->dev, "failed to get memory region\n");
3261 goto release_drvdata;
3263 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
3264 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
3265 if (inf->reg_vir_base == NULL)
3267 dev_err(&pdev->dev, "ioremap() of registers failed\n");
3269 goto release_drvdata;
3271 inf->preg = (LCDC_REG*)inf->reg_vir_base;
3273 /* Prepare win1 info */
3274 fbprintk(">> Prepare win1 info \n");
3275 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
3278 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
3281 goto release_win1fb;
3284 par = (struct win0_par*)inf->fb0->par;
3285 strcpy(inf->fb0->fix.id, "fb0");
3286 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
3287 inf->fb0->fix.type_aux = 0;
3288 inf->fb0->fix.xpanstep = 1;
3289 inf->fb0->fix.ypanstep = 1;
3290 inf->fb0->fix.ywrapstep = 0;
3291 inf->fb0->fix.accel = FB_ACCEL_NONE;
3292 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
3293 inf->fb0->fix.smem_len = 0;
3294 inf->fb0->fix.line_length = 0;
3295 inf->fb0->fix.smem_start = 0;
3297 inf->fb0->var.xres = screen->x_res;
3298 inf->fb0->var.yres = screen->y_res;
3299 inf->fb0->var.bits_per_pixel = 16;
3300 inf->fb0_color_deepth = 0;
3301 inf->fb0->var.xres_virtual = screen->x_res;
3302 inf->fb0->var.yres_virtual = screen->y_res;
3303 inf->fb0->var.width = screen->width;
3304 inf->fb0->var.height = screen->height;
3305 //inf->fb0->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
3306 inf->fb0->var.left_margin = screen->left_margin;
3307 inf->fb0->var.right_margin = screen->right_margin;
3308 inf->fb0->var.upper_margin = screen->upper_margin;
3309 inf->fb0->var.lower_margin = screen->lower_margin;
3310 inf->fb0->var.vsync_len = screen->vsync_len;
3311 inf->fb0->var.hsync_len = screen->hsync_len;
3312 inf->fb0->var.red = def_rgb_16.red;
3313 inf->fb0->var.green = def_rgb_16.green;
3314 inf->fb0->var.blue = def_rgb_16.blue;
3315 inf->fb0->var.transp = def_rgb_16.transp;
3317 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
3318 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
3319 inf->fb0->var.activate = FB_ACTIVATE_NOW;
3320 inf->fb0->var.accel_flags = 0;
3321 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
3323 inf->fb0->fbops = &fb0_ops;
3324 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
3325 inf->fb0->pseudo_palette = par->pseudo_pal;
3326 inf->fb0->screen_base = 0;
3328 memset(par, 0, sizeof(struct win0_par));
3330 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
3334 g_fb0_inf = inf->fb0; //add cym@rk 20101027
3336 /* alloc win1 buf */
3337 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
3340 dev_err(&pdev->dev, "failed to get win1 memory \n");
3342 goto release_win1fb;
3344 inf->fb0->fix.smem_start = res->start;
3345 inf->fb0->fix.smem_len = res->end - res->start + 1;
3346 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
3347 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
3349 #ifdef CONFIG_FB_WORK_IPP
3350 /* alloc win1 ipp buf */
3351 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
3354 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
3356 goto release_win1fb;
3358 inf->fb0->fix.mmio_start = res->start;
3359 inf->fb0->fix.mmio_len = res->end - res->start + 1;
3362 /* Prepare win0 info */
3363 fbprintk(">> Prepare win0 info \n");
3364 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
3367 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
3370 goto release_win0fb;
3373 par = (struct win0_par*)inf->fb1->par;
3375 strcpy(inf->fb1->fix.id, "fb1");
3376 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
3377 inf->fb1->fix.type_aux = 0;
3378 inf->fb1->fix.xpanstep = 1;
3379 inf->fb1->fix.ypanstep = 1;
3380 inf->fb1->fix.ywrapstep = 0;
3381 inf->fb1->fix.accel = FB_ACCEL_NONE;
3382 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
3383 inf->fb1->fix.smem_len = 0;
3384 inf->fb1->fix.line_length = 0;
3385 inf->fb1->fix.smem_start = 0;
3387 inf->fb1->var.xres = screen->x_res;
3388 inf->fb1->var.yres = screen->y_res;
3389 inf->fb1->var.bits_per_pixel = 16;
3390 inf->fb1->var.xres_virtual = screen->x_res;
3391 inf->fb1->var.yres_virtual = screen->y_res;
3392 inf->fb1->var.width = screen->width;
3393 inf->fb1->var.height = screen->height;
3394 //inf->fb1->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
3395 inf->fb1->var.left_margin = screen->left_margin;
3396 inf->fb1->var.right_margin = screen->right_margin;
3397 inf->fb1->var.upper_margin = screen->upper_margin;
3398 inf->fb1->var.lower_margin = screen->lower_margin;
3399 inf->fb1->var.vsync_len = screen->vsync_len;
3400 inf->fb1->var.hsync_len = screen->hsync_len;
3401 inf->fb1->var.red = def_rgb_16.red;
3402 inf->fb1->var.green = def_rgb_16.green;
3403 inf->fb1->var.blue = def_rgb_16.blue;
3404 inf->fb1->var.transp = def_rgb_16.transp;
3406 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
3407 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
3408 inf->fb1->var.activate = FB_ACTIVATE_NOW;
3409 inf->fb1->var.accel_flags = 0;
3410 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
3412 inf->fb1->fbops = &fb1_ops;
3413 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
3414 inf->fb1->pseudo_palette = par->pseudo_pal;
3415 inf->fb1->screen_base = 0;
3417 memset(par, 0, sizeof(struct win0_par));
3419 init_waitqueue_head(&par->wait);
3421 /* Init all lcdc and lcd before register_framebuffer. */
3422 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
3423 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
3424 init_lcdc(inf->fb0);
3426 #if 0 //def CONFIG_CPU_FREQ
3427 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
3428 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3430 fbprintk("got clock\n");
3434 struct rk29_fb_setting_info fb_setting;
3435 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
3437 fb_setting.data_num = 24;
3439 else if(OUT_P666 == inf->cur_screen->face )
3441 fb_setting.data_num = 18;
3445 fb_setting.data_num = 16;
3447 fb_setting.den_en = 1;
3448 fb_setting.vsync_en = 1;
3449 fb_setting.disp_on_en = 1;
3450 fb_setting.standby_en = 1;
3451 if( inf->cur_screen->mcu_usefmk )
3452 fb_setting.mcu_fmk_en =1;
3453 mach_info->io_init(&fb_setting);
3456 //set_lcd_pin(pdev, 1);
3459 inf->mcu_usetimer = 1;
3460 inf->mcu_fmksync = 0;
3461 load_screen(inf->fb0, 1);
3463 /* Register framebuffer(fb0 & fb1) */
3464 fbprintk(">> Register framebuffer(fb0) \n");
3465 ret = register_framebuffer(inf->fb0);
3468 printk(">> fb0 register_framebuffer fail!\n");
3470 goto release_win0fb;
3472 fbprintk(">> Register framebuffer(fb1) \n");
3474 ret = register_framebuffer(inf->fb1);
3477 printk(">> fb1 register_framebuffer fail!\n");
3479 goto unregister_win1fb;
3482 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3485 printk(">> fb1 dsp win0 info device_create_file err\n");
3488 #ifdef CONFIG_HAS_EARLYSUSPEND
3489 suspend_info.inf = inf;
3490 register_early_suspend(&suspend_info.early_suspend);
3493 /* get and request irq */
3494 fbprintk(">> get and request irq \n");
3495 irq = platform_get_irq(pdev, 0);
3497 dev_err(&pdev->dev, "no irq for device\n");
3499 goto unregister_win1fb;
3501 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
3503 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
3508 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
3510 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
3513 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
3518 #ifdef CONFIG_MFD_RK610
3519 rk610_lcd_scaler_set_param(&inf->panel1_info,0);
3521 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
3522 fb0_set_par(inf->fb0);
3523 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
3524 /* Start display and show logo on boot */
3525 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
3526 fb_show_logo(inf->fb0, FB_ROTATE_UR);
3527 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
3531 printk(" %s ok\n", __FUNCTION__);
3536 free_irq(irq, pdev);
3538 unregister_framebuffer(inf->fb0);
3541 framebuffer_release(inf->fb1);
3545 fb_dealloc_cmap(&inf->fb0->cmap);
3548 framebuffer_release(inf->fb0);
3551 if(inf && inf->reg_vir_base)
3552 iounmap(inf->reg_vir_base);
3554 release_mem_region(inf->reg_phy_base, inf->len);
3557 platform_set_drvdata(pdev, NULL);
3561 static int __devexit rk29fb_remove(struct platform_device *pdev)
3563 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3564 struct fb_info *info = NULL;
3566 struct rk29fb_info *mach_info = NULL;
3569 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3572 printk("inf==0, rk29_fb_remove fail! \n");
3575 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3577 irq = platform_get_irq(pdev, 0);
3580 free_irq(irq, pdev);
3583 mach_info = pdev->dev.platform_data;
3584 if(mach_info->mcu_fmk_pin)
3586 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
3589 if(mach_info->io_disable)
3590 mach_info->io_disable(); //close lcd out
3594 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
3596 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
3599 //rk29fb_suspend(pdev, msg);
3600 // unmap memory and release framebuffer
3603 if (info->screen_base) {
3604 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3605 info->screen_base = 0;
3606 info->fix.smem_start = 0;
3607 info->fix.smem_len = 0;
3609 unregister_framebuffer(inf->fb1);
3610 framebuffer_release(inf->fb1);
3615 if (info->screen_base) {
3616 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3617 info->screen_base = 0;
3618 info->fix.smem_start = 0;
3619 info->fix.smem_len = 0;
3621 unregister_framebuffer(inf->fb0);
3622 framebuffer_release(inf->fb0);
3626 #if 0 //def CONFIG_CPU_FREQ
3627 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3634 clk_disable(inf->clk);
3640 clk_disable(inf->dclk);
3646 platform_set_drvdata(pdev, NULL);
3651 static void rk29fb_shutdown(struct platform_device *pdev)
3653 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3654 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3656 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3658 if(mach_info->io_disable)
3659 mach_info->io_disable(); //close lcd out
3661 if(!inf->in_suspend)
3663 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3664 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3665 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3667 clk_disable(inf->aclk_ddr_lcdc);
3668 clk_disable(inf->aclk_disp_matrix);
3669 clk_disable(inf->hclk_cpu_display);
3670 clk_disable(inf->clk);
3672 clk_disable(inf->dclk);
3675 clk_disable(inf->aclk);
3677 clk_disable(inf->pd_display);
3678 //pmu_set_power_domain(PD_DISPLAY, 0);
3679 inf->in_suspend = 1;
3684 static struct platform_driver rk29fb_driver = {
3685 .probe = rk29fb_probe,
3686 .remove = __devexit_p(rk29fb_remove),
3689 .owner = THIS_MODULE,
3691 .shutdown = rk29fb_shutdown,
3694 static int __init rk29fb_init(void)
3696 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3697 return platform_driver_register(&rk29fb_driver);
3700 static void __exit rk29fb_exit(void)
3702 platform_driver_unregister(&rk29fb_driver);
3705 fs_initcall(rk29fb_init);
3706 module_exit(rk29fb_exit);
3709 MODULE_AUTHOR(" zyw@rock-chips.com");
3710 MODULE_DESCRIPTION("Driver for rk29 fb device");
3711 MODULE_LICENSE("GPL");