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;
239 #ifdef CONFIG_BACKLIGHT_RK29_BL
240 /* drivers/video/backlight/rk29_backlight.c */
241 extern void rk29_backlight_set(bool on);
243 void rk29_backlight_set(bool on)
245 /* please add backlight switching-related code here or on your backlight driver
246 parameter: on=1 ==> open spk
251 typedef enum _TRSP_MODE
263 unsigned long bitperpixel;
272 unsigned long src_uv;
273 unsigned long dst_width;
274 unsigned long dst_height;
275 //struct mutex fb_lock;
276 volatile unsigned long fb_lock;
280 struct wimo_fb_info wimo_info;
281 unsigned char* ui_buffer;
282 unsigned char* ui_buffer_map;
283 //unsigned char* overlay_buffer;
284 //unsigned char* overlay_buffer_map;
287 struct platform_device *g_pdev = NULL;
288 //static int win1fb_set_par(struct fb_info *info);
291 #define CHK_SUSPEND(inf) \
292 if(inf->in_suspend) { \
293 fbprintk(">>>>>> fb is in suspend! return! \n"); \
297 #define CHK_SUSPEND(inf)
299 static DECLARE_WAIT_QUEUE_HEAD(fb0_wait_queue);
300 static volatile int idle_condition = 1; //1:idel, 0:busy
302 static DECLARE_WAIT_QUEUE_HEAD(wq);
303 static int wq_condition = 0;
304 static int wq_condition2 = 0;
305 static int fb1_open_init = 0;
306 #if ANDROID_USE_THREE_BUFS
307 static int new_frame_seted = 1;
309 static struct wake_lock idlelock; /* only for fb */
310 #ifdef CONFIG_FB_ROTATE_VIDEO
312 static bool has_set_rotate;
313 static u32 last_yuv_phy[2] = {0,0};
315 int fb0_first_buff_bits = 32;
316 int fb0_second_buff_bits = 32;
317 int fb_compose_layer_count = 0;
318 static BLOCKING_NOTIFIER_HEAD(rk29fb_notifier_list);
319 int rk29fb_register_notifier(struct notifier_block *nb)
323 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
325 if (inf->cur_screen && inf->cur_screen->type == SCREEN_HDMI)
326 nb->notifier_call(nb, RK29FB_EVENT_HDMI_ON, inf->cur_screen);
327 if (inf->fb1 && inf->fb1->par) {
328 struct win0_par *par = inf->fb1->par;
330 nb->notifier_call(nb, RK29FB_EVENT_FB1_ON, inf->cur_screen);
334 ret = blocking_notifier_chain_register(&rk29fb_notifier_list, nb);
339 int rk29fb_unregister_notifier(struct notifier_block *nb)
341 return blocking_notifier_chain_unregister(&rk29fb_notifier_list, nb);
344 static int rk29fb_notify(struct rk29fb_inf *inf, unsigned long event)
346 return blocking_notifier_call_chain(&rk29fb_notifier_list, event, inf->cur_screen);
349 int mcu_do_refresh(struct rk29fb_inf *inf)
351 if(inf->mcu_stopflush) return 0;
353 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
358 inf->mcu_needflush = 1;
362 // not use frame mark
363 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
365 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
367 inf->mcu_needflush = 1;
371 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
372 inf->mcu_needflush = 0;
374 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
381 void mcutimer_callback(unsigned long arg)
383 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
384 static int waitcnt = 0;
386 mod_timer(&inf->mcutimer, jiffies + HZ/10);
388 switch(inf->mcu_status)
391 inf->mcu_status = MS_MCU;
394 if(inf->mcu_usetimer) mcu_do_refresh(inf);
397 inf->mcu_status = MS_EWAITEND;
405 inf->mcu_status = MS_EEND;
409 inf->mcu_status = MS_MCU;
412 inf->mcu_status = MS_MCU;
417 int mcu_refresh(struct rk29fb_inf *inf)
419 static int mcutimer_inited = 0;
421 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
426 init_timer(&inf->mcutimer);
427 inf->mcutimer.function = mcutimer_callback;
428 inf->mcutimer.expires = jiffies + HZ/5;
429 inf->mcu_status = MS_IDLE;
430 add_timer(&inf->mcutimer);
433 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
438 int mcu_ioctl(unsigned int cmd, unsigned long arg)
440 struct rk29fb_inf *inf = NULL;
441 if(!g_pdev) return -1;
443 inf = dev_get_drvdata(&g_pdev->dev);
448 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
449 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
450 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
454 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
455 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
459 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
460 LcdWrReg(inf, REG_CFG_DONE, 0x01);
470 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
472 struct platform_device *pdev = (struct platform_device*)dev_id;
473 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
474 struct rk29fb_screen *screen;
476 if(!inf) return IRQ_HANDLED;
478 screen = inf->cur_screen;
480 if(0==screen->mcu_usefmk) {
484 if(inf->mcu_fmksync == 1)
487 inf->mcu_fmksync = 1;
488 if(inf->mcu_needflush)
490 inf->mcu_needflush = 0;
492 if(inf->cur_screen->refresh)
493 inf->cur_screen->refresh(REFRESH_PRE);
494 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
496 inf->mcu_fmksync = 0;
501 int init_lcdc(struct fb_info *info)
503 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
506 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
508 inf->clk = clk_get(NULL, "hclk_lcdc");
509 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
510 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
511 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
512 inf->pd_display = clk_get(NULL, "pd_display");
513 if ((IS_ERR(inf->clk)) ||
514 (IS_ERR(inf->aclk_ddr_lcdc)) ||
515 (IS_ERR(inf->aclk_disp_matrix)) ||
516 (IS_ERR(inf->hclk_cpu_display)) ||
517 (IS_ERR(inf->pd_display)))
519 printk(KERN_ERR "failed to get lcdc_hclk source\n");
520 return PTR_ERR(inf->clk);
522 clk_enable(inf->aclk_disp_matrix);
523 clk_enable(inf->hclk_cpu_display);
524 clk_enable(inf->clk);
525 clk_enable(inf->pd_display);
526 //pmu_set_power_domain(PD_DISPLAY, 1);
527 clk_enable(inf->aclk_ddr_lcdc);
529 // set AHB access rule and disable all windows
530 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
531 LcdWrReg(inf, SWAP_CTRL, 0);
532 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
533 LcdWrReg(inf, AXI_MS_ID, 0x54321);
535 // and mcu holdmode; and set win1 top.
536 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
537 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
539 // disable blank out, black out, tristate out, yuv2rgb bypass
540 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
541 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
542 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
543 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
546 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
547 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
549 LcdWrReg(inf, DSP_CTRL1, 0);
551 // initialize all interrupt
552 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
554 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
556 LcdWrReg(inf, INT_STATUS, clr | msk);
558 // let above to take effect
559 LcdWrReg(inf, REG_CFG_DONE, 0x01);
564 void load_screen(struct fb_info *info, bool initscreen)
567 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
568 struct rk29fb_screen *screen = inf->cur_screen;
570 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
571 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
572 u16 x_res = screen->x_res, y_res = screen->y_res;
573 u32 aclk_rate = 150000000;
576 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
580 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
582 // set the rgb or mcu
583 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
585 // set out format and mcu timing
586 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
587 if(mcu_total>31) mcu_total = 31;
588 if(mcu_total<3) mcu_total = 3;
589 mcu_rwstart = (mcu_total+1)/4 - 1;
590 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
591 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
592 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
594 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
595 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
597 LcdMskReg(inf, MCU_TIMING_CTRL,
598 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
599 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
600 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
601 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
602 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
605 // set synchronous pin polarity and data pin swap rule
606 switch (screen->face)
610 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
614 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
618 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
622 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
626 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
627 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
630 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
631 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
636 LcdMskReg(inf, DSP_CTRL0,
637 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
638 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
639 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
640 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
643 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
645 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
646 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));
648 // set horizontal & vertical out timing
649 if(SCREEN_MCU==inf->cur_screen->type)
651 right_margin = x_res/6;
654 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
655 screen->hsync_len , screen->left_margin , x_res , right_margin );
656 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
657 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
658 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
659 v_BIT12HI(screen->hsync_len + screen->left_margin));
661 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
662 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
663 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
664 v_BIT11HI(screen->vsync_len + screen->upper_margin));
666 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
667 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
669 // let above to take effect
670 LcdWrReg(inf, REG_CFG_DONE, 0x01);
672 inf->dclk = clk_get(NULL, "dclk_lcdc");
673 if (IS_ERR(inf->dclk))
675 printk(KERN_ERR "failed to get lcd dclock source\n");
679 inf->aclk = clk_get(NULL, "aclk_lcdc");
680 if (IS_ERR(inf->aclk))
682 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
685 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
686 if (IS_ERR(inf->aclk_parent))
688 printk(KERN_ERR "failed to get lcd clock parent source\n");
693 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
695 if(initscreen == 0) //not init
697 clk_disable(inf->dclk);
698 // clk_disable(inf->aclk);
701 // clk_disable(inf->aclk_ddr_lcdc);
702 // clk_disable(inf->aclk_disp_matrix);
703 // clk_disable(inf->hclk_cpu_display);
705 // clk_disable(inf->clk);
708 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
710 ret = clk_set_rate(inf->dclk, screen->pixclock);
713 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
715 inf->fb0->var.pixclock = inf->fb1->var.pixclock = div_u64(1000000000000llu, clk_get_rate(inf->dclk));
718 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
719 if(screen->lcdc_aclk){
720 aclk_rate = screen->lcdc_aclk;
722 ret = clk_set_rate(inf->aclk, aclk_rate);
724 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
726 clk_enable(inf->aclk);
728 // clk_enable(inf->aclk_ddr_lcdc);
729 // clk_enable(inf->aclk_disp_matrix);
730 // clk_enable(inf->hclk_cpu_display);
731 // clk_enable(inf->clk);
732 clk_enable(inf->dclk);
740 #if 0 //def CONFIG_CPU_FREQ
742 * CPU clock speed change handler. We need to adjust the LCD timing
743 * parameters when the CPU clock is adjusted by the power management
746 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
749 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
751 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
752 struct rk29fb_screen *screen = inf->cur_screen;
757 case CPUFREQ_PRECHANGE:
759 case CPUFREQ_POSTCHANGE:
761 dclk_rate = screen->pixclock * 1000000;
763 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
765 clk_set_rate(inf->dclk_divider, dclk_rate);
773 static inline unsigned int chan_to_field(unsigned int chan,
774 struct fb_bitfield *bf)
777 chan >>= 16 - bf->length;
778 return chan << bf->offset;
781 static int fb_setcolreg(unsigned regno,
782 unsigned red, unsigned green, unsigned blue,
783 unsigned transp, struct fb_info *info)
786 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
788 switch (info->fix.visual) {
789 case FB_VISUAL_TRUECOLOR:
790 /* true-colour, use pseudo-palette */
792 u32 *pal = info->pseudo_palette;
793 val = chan_to_field(red, &info->var.red);
794 val |= chan_to_field(green, &info->var.green);
795 val |= chan_to_field(blue, &info->var.blue);
800 return -1; /* unknown type */
806 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
809 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
811 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
813 LcdWrReg(inf, REG_CFG_DONE, 0x01);
817 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
819 struct rk29fb_screen *screen = inf->cur_screen;
822 if (x >= 0x800 || y >= 0x800 )
824 //printk("%s: %08x,%08x \n",__func__, x, y);
825 x += (screen->left_margin + screen->hsync_len);
826 y += (screen->upper_margin + screen->vsync_len);
827 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
828 LcdWrReg(inf, REG_CFG_DONE, 0x01);
833 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
835 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
836 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
837 LcdWrReg(inf, REG_CFG_DONE, 0x01);
841 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
842 int rk29_set_cursor_img_transform(char *data)
845 char *dst = (char*)rk29_cursor_buf;
846 unsigned char dmsk = 0;
847 unsigned int op,shift,offset;
849 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
850 * clears it to transparent then combines the cursor
851 * shape plane with the colour plane to set the
853 for (y = 0; y < 32; y++)
855 for (x = 0; x < 32; x++)
862 op = (dmsk & 0x80) ? 2 : 3;
865 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
875 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
879 rk29_set_cursor_img_transform(data);
883 rk29_set_cursor_img_transform(cursor_img);
885 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
886 //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
887 LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
889 LcdWrReg(inf, REG_CFG_DONE, 0x01);
894 int rk29_set_cursor_test(struct fb_info *info)
896 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
897 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
898 rk29_set_cursor_pos(inf, 0, 0);
899 rk29_set_cursor_img(inf, 0);
900 rk29_set_cursor_en(inf, 1);
905 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
907 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
909 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
911 /* check not being asked to exceed capabilities */
913 if (cursor->image.width > 32)
916 if (cursor->image.height > 32)
919 if (cursor->image.depth > 1)
923 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
925 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
928 if (cursor->set & FB_CUR_SETPOS)
930 unsigned int x = cursor->image.dx;
931 unsigned int y = cursor->image.dy;
933 if (x >= 0x800 || y >= 0x800 )
935 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
939 if (cursor->set & FB_CUR_SETCMAP)
941 unsigned int bg_col = cursor->image.bg_color;
942 unsigned int fg_col = cursor->image.fg_color;
944 fbprintk("%s: update cmap (%08x,%08x)\n",
945 __func__, bg_col, fg_col);
947 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
948 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));
950 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
951 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));
954 if ((cursor->set & FB_CUR_SETSIZE ||
955 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
956 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
958 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
959 * clears it to transparent then combines the cursor
960 * shape plane with the colour plane to set the
963 const unsigned char *pcol = cursor->image.data;
964 const unsigned char *pmsk = cursor->mask;
966 unsigned long cursor_mem_start;
967 unsigned char dcol = 0;
968 unsigned char dmsk = 0;
971 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
972 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
974 fbprintk("%s: setting shape (%d,%d)\n",
975 __func__, cursor->image.width, cursor->image.height);
977 memset(dst, 0, CURSOR_BUF_SIZE);
979 for (y = 0; y < cursor->image.height; y++)
981 for (x = 0; x < cursor->image.width; x++)
992 op = (dcol & 1) ? 1 : 3;
993 op <<= ((x % 4) * 2);
994 *(u8*)(dst+(x/4)) |= op;
999 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
1000 LcdWrReg(inf, HWC_MST, cursor_mem_start);
1001 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1002 if(SCREEN_MCU == inf->cur_screen->type) {
1003 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1007 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1009 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
1015 static int hdmi_get_fbscale(void)
1018 return hdmi_get_scale();
1023 static void hdmi_set_fbscale(struct fb_info *info)
1026 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1027 struct rk29fb_screen *screen = inf->cur_screen;
1028 struct win0_par *par = info->par;
1031 scale = hdmi_get_scale();
1034 par->xpos += screen->x_res * (100-scale) / 200;
1035 par->ypos += screen->y_res * (100-scale) / 200;
1036 par->xsize = par->xsize *scale /100;
1037 par->ysize = par->ysize *scale /100;
1040 static int win0_blank(int blank_mode, struct fb_info *info)
1042 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1044 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1050 case FB_BLANK_UNBLANK:
1051 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1052 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1054 case FB_BLANK_NORMAL:
1055 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1058 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1059 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1060 #ifdef CONFIG_DDR_RECONFIG
1070 static int win0_set_par(struct fb_info *info)
1072 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1073 struct rk29fb_screen *screen = inf->cur_screen;
1074 struct fb_var_screeninfo *var = &info->var;
1075 struct fb_fix_screeninfo *fix = &info->fix;
1076 struct win0_par *par = info->par;
1077 u32 xact, yact, xvir, yvir, xpos, ypos, ScaleYrgbX,ScaleYrgbY, ScaleCbrX, ScaleCbrY, y_addr,uv_addr;
1078 hdmi_set_fbscale(info);
1079 xact = var->xres; /* visible resolution */
1081 xvir = var->xres_virtual; /* virtual resolution */
1082 yvir = var->yres_virtual;
1083 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
1084 //u32 yact_st = var->yoffset; /* resolution */
1093 y_addr = 0; //user alloc buf addr y
1096 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1100 if((var->rotate%360!=0)&& (inf->video_mode))
1102 #ifdef CONFIG_FB_ROTATE_VIDEO
1103 if(xact > screen->x_res)
1105 xact = screen->x_res; /* visible resolution */
1106 yact = screen->y_res;
1107 xvir = screen->x_res; /* virtual resolution */
1108 yvir = screen->y_res;
1110 xact = var->xres; /* visible resolution */
1112 xvir = var->xres_virtual; /* virtual resolution */
1113 yvir = var->yres_virtual;
1114 printk("xact=%d yact =%d \n",xact,yact);
1116 #else //CONFIG_FB_ROTATE_VIDEO
1117 printk("LCDC not support rotate!\n");
1122 // calculate the display phy address
1123 y_addr = fix->smem_start + par->y_offset;
1124 uv_addr = fix->mmio_start + par->c_offset;
1126 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1127 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1129 switch (par->format)
1132 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1133 ScaleCbrY = CalScaleW0(yact, par->ysize);
1137 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1138 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1141 ScaleCbrX= CalScaleW0(xact, par->xsize);
1142 ScaleCbrY = CalScaleW0(yact, par->ysize);
1148 xpos += (screen->left_margin + screen->hsync_len);
1149 ypos += (screen->upper_margin + screen->vsync_len);
1151 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1152 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1154 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1156 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1157 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1158 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1159 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1160 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1161 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1166 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,
1167 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));
1170 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,
1171 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));
1174 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,
1175 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) |
1176 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1179 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,
1180 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) );
1184 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1190 static int win0_pan( struct fb_info *info )
1192 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1193 // struct fb_var_screeninfo *var0 = &info->var;
1194 struct fb_fix_screeninfo *fix0 = &info->fix;
1195 struct win0_par *par = info->par;
1196 u32 y_addr=0, uv_addr=0;
1198 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1202 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1203 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1205 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1206 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1207 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1209 // enable win0 after the win0 addr is seted
1210 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1216 static int win1_blank(int blank_mode, struct fb_info *info)
1218 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1220 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1226 case FB_BLANK_UNBLANK:
1227 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1228 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1230 case FB_BLANK_NORMAL:
1231 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1234 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1235 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1245 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1246 static void win1_check_work_func(struct work_struct *work)
1248 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
1249 struct fb_info *fb0_inf = inf->fb0;
1250 struct fb_var_screeninfo *var = &fb0_inf->var;
1253 int blank_data,total_data;
1255 u16 xres_virtual = fb0_inf->var.xres_virtual; //virtual screen size
1256 u16 xpos_virtual = fb0_inf->var.xoffset; //visiable offset in virtual screen
1257 u16 ypos_virtual = fb0_inf->var.yoffset;
1259 int offset = 0;//(ypos_virtual*xres_virtual + xpos_virtual)*((inf->fb0_color_deepth || fb0_inf->var.bits_per_pixel==32)? 4:2)/4;
1260 switch(var->bits_per_pixel)
1264 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1265 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1266 offset -= var->yres * var->xres *2;
1270 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1271 if(ypos_virtual >= 2*var->yres)
1274 if(ypos_virtual == 3*var->yres)
1276 offset -= var->yres * var->xres *2;
1281 p = (u32)fb0_inf->screen_base + offset;
1282 blank_data = (inf->fb0_color_deepth==32) ? 0xff000000 : 0;
1283 total_data = fb0_inf->var.xres * fb0_inf->var.yres / (format+1);
1285 // 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);
1287 for(i=0; i < total_data; i++)
1289 if(*p++ != blank_data)
1291 //printk("win1 have no 0 data in %d, total %d\n",i,total_data);
1296 win1_blank(FB_BLANK_POWERDOWN, fb0_inf);
1297 // printk("%s close win1!\n",__func__);
1299 static DECLARE_DELAYED_WORK(rk29_win1_check_work, win1_check_work_func);
1301 static int win1_set_par(struct fb_info *info)
1303 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1304 struct fb_fix_screeninfo *fix = &info->fix;
1305 struct rk29fb_screen *screen = inf->cur_screen;
1306 struct win0_par *par = info->par;
1307 struct fb_var_screeninfo *var = &info->var;
1309 u16 xres_virtual,xpos,ypos;
1310 u8 trspval,trspmode;
1311 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1312 cancel_delayed_work_sync(&rk29_win1_check_work);
1314 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1315 #ifndef CONFIG_FB_SCALING_OSD_1080P
1316 && !((screen->x_res>1280) && (var->bits_per_pixel == 32))
1320 hdmi_set_fbscale(info);
1322 #ifndef CONFIG_FB_SCALING_OSD_1080P
1323 else if(((screen->x_res==1920) ))
1325 if(hdmi_get_fbscale() < 100)
1326 par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1329 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1331 xres_virtual = 0; //virtual screen size
1333 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1334 //u16 ypos_virtual = var->yoffset;
1336 xpos = par->xpos; //visiable offset in panel
1339 trspmode = TRSP_CLOSE;
1342 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1344 #ifdef CONFIG_FB_SCALING_OSD
1345 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1346 #ifndef CONFIG_FB_SCALING_OSD_1080P
1347 && (screen->x_res<=1280)
1351 addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1352 xres_virtual = screen->x_res* hdmi_get_fbscale()/100; //virtual screen size
1357 addr = fix->smem_start + par->y_offset;
1358 xres_virtual = var->xres_virtual; //virtual screen size
1360 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(fb1_open_init?0:1)|v_W1_FORMAT(par->format));
1362 xpos += (screen->left_margin + screen->hsync_len);
1363 ypos += (screen->upper_margin + screen->vsync_len);
1365 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1367 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1368 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1370 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1372 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1373 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1375 // enable win1 color key and set the color to black(rgb=0)
1376 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1378 if(1==par->format) //rgb565
1380 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1381 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1385 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1386 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1388 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1391 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1393 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
1394 schedule_delayed_work(&rk29_win1_check_work, msecs_to_jiffies(5000));
1400 static int win1_pan( struct fb_info *info )
1402 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1403 struct fb_fix_screeninfo *fix1 = &info->fix;
1404 struct win0_par *par = info->par;
1407 #ifdef CONFIG_FB_SCALING_OSD
1408 struct rk29fb_screen *screen = inf->cur_screen;
1409 struct fb_var_screeninfo *var = &info->var;
1410 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1411 #ifndef CONFIG_FB_SCALING_OSD_1080P
1412 && (screen->x_res<=1280)
1416 addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1421 addr = fix1->smem_start + par->y_offset;
1424 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1426 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1427 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1433 static int fb0_blank(int blank_mode, struct fb_info *info)
1435 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1437 if(inf->video_mode == 1)
1439 win1_blank(blank_mode, info);
1443 win0_blank(blank_mode, info);
1448 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1450 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1451 struct rk29fb_screen *screen = inf->cur_screen;
1452 u16 xpos = (var->nonstd>>8) & 0xfff;
1453 u16 ypos = (var->nonstd>>20) & 0xfff;
1454 u16 xlcd = screen->x_res;
1455 u16 ylcd = screen->y_res;
1457 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1461 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1462 0==var->xres || 0==var->yres || var->xres<16 ||
1463 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1465 printk(">>>>>> fb0_check_var fail 1!!! \n");
1466 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1467 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1468 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1472 if( (var->xoffset+var->xres)>var->xres_virtual ||
1473 (var->yoffset+var->yres)>var->yres_virtual*2 )
1475 printk(">>>>>> fb0_check_var fail 2!!! \n");
1476 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1477 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1478 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1482 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1483 switch(var->bits_per_pixel)
1486 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1487 var->xres = (var->xres + 0x1) & (~0x1);
1488 var->xoffset = (var->xoffset) & (~0x1);
1491 var->bits_per_pixel = 32;
1499 static int fb0_set_par(struct fb_info *info)
1501 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1502 struct fb_var_screeninfo *var = &info->var;
1503 struct fb_fix_screeninfo *fix = &info->fix;
1504 struct rk29fb_screen *screen = inf->cur_screen;
1505 struct win0_par *par = info->par;
1507 u32 offset=0, smem_len=0;
1508 u16 xres_virtual = var->xres_virtual; //virtual screen size
1509 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1510 u16 ypos_virtual = var->yoffset;
1512 #ifdef CONFIG_FB_SCALING_OSD
1513 struct rk29_ipp_req ipp_req;
1515 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1518 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1519 wait_event_interruptible(fb0_wait_queue, idle_condition);
1525 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1526 #if !defined(CONFIG_FB_SCALING_OSD)
1527 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1530 switch(var->bits_per_pixel)
1534 if( ypos_virtual == 0)
1535 fb0_first_buff_bits = 16;
1537 fb0_second_buff_bits = 16;
1539 //fix->line_length = 2 * xres_virtual;
1540 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1542 #ifdef CONFIG_FB_SCALING_OSD
1543 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1544 ipp_req.src0.fmt = IPP_RGB_565;
1545 ipp_req.dst0.fmt = IPP_RGB_565;
1547 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1548 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1549 offset -= var->yres * var->xres *2;
1554 if( ypos_virtual == 0)
1555 fb0_first_buff_bits = 32;
1557 fb0_second_buff_bits = 32;
1558 fix->line_length = 4 * xres_virtual;
1559 #ifdef CONFIG_FB_SCALING_OSD
1560 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1562 ipp_req.src0.fmt = IPP_XRGB_8888;
1563 ipp_req.dst0.fmt = IPP_XRGB_8888;
1565 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1567 if(ypos_virtual >= 2*var->yres)
1570 #ifdef CONFIG_FB_SCALING_OSD
1571 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1572 ipp_req.src0.fmt = IPP_RGB_565;
1573 ipp_req.dst0.fmt = IPP_RGB_565;
1575 if(ypos_virtual == 3*var->yres)
1577 offset -= var->yres * var->xres *2;
1583 smem_len = fix->line_length * var->yres_virtual;
1584 //map_size = PAGE_ALIGN(smem_len);
1586 if (smem_len > fix->smem_len) // buffer need realloc
1588 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1589 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1590 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1594 par->addr_seted = 1;
1595 #if ANDROID_USE_THREE_BUFS
1596 if(0==new_frame_seted) {
1598 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1600 new_frame_seted = 0;
1603 if(inf->video_mode == 1)
1605 #ifdef CONFIG_FB_SCALING_OSD
1606 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1607 #ifndef CONFIG_FB_SCALING_OSD_1080P
1608 && (screen->x_res<=1280)
1614 par->xsize = screen->x_res;
1615 par->ysize = screen->y_res;
1616 par->y_offset = dstoffset;
1618 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1619 ipp_req.src0.w = var->xres;
1620 ipp_req.src0.h = var->yres;
1622 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1623 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1624 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1626 ipp_req.src_vir_w = ipp_req.src0.w;
1627 ipp_req.dst_vir_w = ipp_req.dst0.w;
1628 ipp_req.timeout = 100;
1629 ipp_req.flag = IPP_ROT_0;
1630 //ipp_do_blit(&ipp_req);
1631 ipp_blit_sync(&ipp_req);
1635 par->y_offset = offset;
1636 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1637 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1638 par->xsize = var->xres; //visiable size in panel
1639 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1645 par->y_offset = offset;
1648 par->xsize = screen->x_res;
1649 par->ysize = screen->y_res;
1654 wake_up_interruptible_sync(&fb0_wait_queue);
1658 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1661 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1662 struct fb_var_screeninfo *var1 = &info->var;
1663 struct rk29fb_screen *screen = inf->cur_screen;
1664 struct win0_par *par = info->par;
1667 u16 ypos_virtual = var->yoffset;
1668 u16 xpos_virtual = var->xoffset;
1669 #ifdef CONFIG_FB_SCALING_OSD
1670 struct fb_fix_screeninfo *fix = &info->fix;
1671 struct rk29_ipp_req ipp_req;
1673 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1675 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1679 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1680 #if !defined(CONFIG_FB_SCALING_OSD)
1681 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1684 switch(var1->bits_per_pixel)
1687 var->xoffset = (var->xoffset) & (~0x1);
1688 #ifdef CONFIG_FB_SCALING_OSD
1689 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1690 ipp_req.src0.fmt = IPP_RGB_565;
1691 ipp_req.dst0.fmt = IPP_RGB_565;
1693 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1694 if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1695 offset -= var->yres * var->xres *2;
1698 #ifdef CONFIG_FB_SCALING_OSD
1699 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1700 ipp_req.src0.fmt = IPP_XRGB_8888;
1701 ipp_req.dst0.fmt = IPP_XRGB_8888;
1703 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1704 if(ypos_virtual >= 2*var->yres)
1707 #ifdef CONFIG_FB_SCALING_OSD
1708 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1709 ipp_req.src0.fmt = IPP_RGB_565;
1710 ipp_req.dst0.fmt = IPP_RGB_565;
1712 if(ypos_virtual == 3*var->yres)
1714 offset -= var->yres * var->xres *2;
1722 if(inf->video_mode == 1)
1724 #ifdef CONFIG_FB_SCALING_OSD
1725 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1726 #ifndef CONFIG_FB_SCALING_OSD_1080P
1727 && (screen->x_res<=1280)
1731 par->y_offset = dstoffset;
1733 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1734 ipp_req.src0.w = var->xres;
1735 ipp_req.src0.h = var->yres;
1737 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1738 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1739 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1741 ipp_req.src_vir_w = ipp_req.src0.w;
1742 ipp_req.dst_vir_w = ipp_req.dst0.w;
1743 ipp_req.timeout = 100;
1744 ipp_req.flag = IPP_ROT_0;
1745 //ipp_do_blit(&ipp_req);
1746 ipp_blit_sync(&ipp_req);
1751 par->y_offset = offset;
1756 par->y_offset = offset;
1759 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1760 #if !ANDROID_USE_THREE_BUFS
1761 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1762 if(SCREEN_MCU == inf->cur_screen->type) {
1763 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1767 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1774 unsigned long temp_vv;
1775 static int frame_num = 0;
1776 static int wimo_set_buff(struct fb_info *info,unsigned long *temp)
1778 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1780 ui_buffer = temp[0];
1781 ui_buffer_map = ioremap(temp[0],temp[1]);
1782 if(ui_buffer_map == NULL)
1784 printk("can't map a buffer for ui\n");
1788 printk("ui_buffer %x ",ui_buffer_map);
1789 memset(&wimo_info,0,sizeof(wimo_info) );
1791 wimo_info.mode = inf->video_mode;
1792 // wimo_info.bitperpixel = var->bits_per_pixel;
1795 wimo_info.dst_width = (temp[2] + 15) & 0xfff0;
1796 wimo_info.dst_height = (temp[3] + 15) & 0xfff0;
1798 static int wimo_get_buff(struct fb_info *info)
1801 struct rk29_ipp_req overlay_req;
1802 struct rk29_ipp_req overlay_req_1;
1803 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1805 memset(&overlay_req, 0 , sizeof(overlay_req));
1806 memset(&overlay_req_1, 0 , sizeof(overlay_req_1));
1808 if(inf->video_mode == 0 )
1810 struct win0_par *par = info->par;
1813 wimo_info.xsize = 0;
1814 wimo_info.ysize = 0;
1816 if(par->format == 1)
1817 wimo_info.bitperpixel = 16;
1819 wimo_info.bitperpixel =32;// wimo_info.bitperpixel_fb1;
1820 overlay_req.src0.YrgbMst = info->fix.smem_start + par->y_offset;//info->screen_base + par->y_offset;//info_buffer[8];
1821 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];
1822 overlay_req.src0.w = wimo_info.dst_width ;//dst_width;//info_buffer[2];
1823 overlay_req.src0.h = wimo_info.dst_height ;//dst_height;//info_buffer[3];
1824 overlay_req.src0.fmt = (wimo_info.bitperpixel == 16) ? 1 : 0;//3;
1825 overlay_req.dst0.YrgbMst = ui_buffer;//overlay_buffer + info_buffer[4] + info_buffer[5] * dst_width;
1826 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];
1827 overlay_req.dst0.w = wimo_info.dst_width ;//dst_width;//info_buffer[6];
1828 overlay_req.dst0.h = wimo_info.dst_height ;//dst_height;//info_buffer[7];
1829 overlay_req.dst0.fmt = (wimo_info.bitperpixel== 16) ? 1 : 0;//3;3;
1830 overlay_req.deinterlace_enable = 0;
1831 overlay_req.timeout = 1000000;
1832 overlay_req.src_vir_w = wimo_info.dst_width ;//dst_width;//info_buffer[2];
1833 overlay_req.dst_vir_w = wimo_info.dst_width ;//dst_width;
1834 overlay_req.flag = IPP_ROT_0;
1835 ipp_blit_sync(&overlay_req);
1843 static int wimo_time = 0;
1844 unsigned long *overlay_buffer_map_temp;
1845 unsigned long *map_temp;
1846 unsigned long sign_memset = 0;
1847 struct fb_var_screeninfo *var = &inf->fb1->var;
1848 struct win0_par *par = inf->fb1->par;
1850 // printk("overlay setbuffer in\n");
1851 // mutex_lock(&wimo_info.fb_lock);
1852 wimo_info.fb_lock = 1;
1854 wimo_info.xaff = var->xres;
1855 wimo_info.yaff = var->yres;
1856 if((wimo_info.xpos != par->xpos) ||(wimo_info.ypos != par->ypos)||(wimo_info.xsize != par->xsize) ||(wimo_info.ysize != par->ysize))
1858 wimo_info.xpos = par->xpos;
1859 wimo_info.ypos = par->ypos;
1860 wimo_info.xsize = par->xsize;
1861 wimo_info.ysize = par->ysize;
1863 memset(ui_buffer_map,0,wimo_info.dst_height * wimo_info.dst_width);//dst_width*dst_height);
1864 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);
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 );
1868 //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 );
1869 if(wimo_info.xaff * 3 < wimo_info.xsize || wimo_info.yaff * 3 < wimo_info.ysize)// 3time or bigger scale up
1871 unsigned long mid_width, mid_height;
1872 struct rk29_ipp_req overlay_req_1;
1873 if(wimo_info.xaff * 3 < wimo_info.xsize)
1874 mid_width = wimo_info.xaff * 3;
1876 mid_width = wimo_info.xsize;
1878 if(wimo_info.yaff * 3 < wimo_info.ysize)
1879 mid_height = wimo_info.yaff * 3;
1881 mid_height = wimo_info.ysize;
1882 overlay_req.src0.YrgbMst = wimo_info.src_y;//info_buffer[8];
1883 overlay_req.src0.CbrMst = wimo_info.src_uv;//info_buffer[9];
1884 overlay_req.src0.w = wimo_info.xaff;// info_buffer[2];
1885 overlay_req.src0.h = wimo_info.yaff;// info_buffer[3];
1886 overlay_req.src0.fmt = 3;
1887 overlay_req.dst0.YrgbMst = ui_buffer + 2048000 ;//info_buffer[4] + info_buffer[5] * dst_width; //С³ß´çƬԴÐèÒª2´Î·Å´ó£¬ËùÒÔ½«bufferµÄºó°ë¶ÎÓÃÓÚ»º´æ
1888 overlay_req.dst0.CbrMst = (unsigned char*) ui_buffer + mid_height * mid_width + 2048000;
1890 overlay_req.dst0.w = mid_width;//info_buffer[6];
1891 overlay_req.dst0.h = mid_height;//info_buffer[7];
1892 overlay_req.dst0.fmt = 3;
1893 overlay_req.timeout = 100000;
1894 overlay_req.src_vir_w = wimo_info.xaff;//info_buffer[2];
1895 overlay_req.dst_vir_w = mid_width;//dst_width;
1896 overlay_req.flag = IPP_ROT_0;
1898 overlay_req_1.src0.YrgbMst = ui_buffer + 2048000;
1899 overlay_req_1.src0.CbrMst = (unsigned char*) ui_buffer + mid_height * mid_width + 2048000;
1900 overlay_req_1.src0.w = mid_width;
1901 overlay_req_1.src0.h = mid_height;// info_buffer[3];
1902 overlay_req_1.src0.fmt = 3;
1903 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;
1904 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 ;
1906 overlay_req_1.dst0.w = wimo_info.xsize;//info_buffer[6];
1907 overlay_req_1.dst0.h = wimo_info.ysize;//info_buffer[7];
1908 overlay_req_1.dst0.fmt = 3;
1909 overlay_req_1.timeout = 100000;
1910 overlay_req_1.src_vir_w = mid_width;//info_buffer[2];
1911 overlay_req_1.dst_vir_w = wimo_info.dst_width;//dst_width;
1912 overlay_req_1.flag = IPP_ROT_0;
1915 err = ipp_blit_sync(&overlay_req);
1916 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);
1917 err = ipp_blit_sync(&overlay_req_1);
1922 overlay_req.src0.YrgbMst = wimo_info.src_y;//info_buffer[8];
1923 overlay_req.src0.CbrMst = wimo_info.src_uv;//info_buffer[9];
1924 overlay_req.src0.w = wimo_info.xaff;// info_buffer[2];
1925 overlay_req.src0.h = wimo_info.yaff;// info_buffer[3];
1926 overlay_req.src0.fmt = 3;
1927 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;
1928 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 ;
1930 overlay_req.dst0.w = wimo_info.xsize;//wimo_info.xsize;//wimo_info.xaff;// wimo_info.xsize;//info_buffer[6];
1931 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];
1932 overlay_req.dst0.fmt = 3;
1933 overlay_req.timeout = 100000;
1934 overlay_req.src_vir_w = wimo_info.xaff;//info_buffer[2];
1935 overlay_req.dst_vir_w = wimo_info.dst_width;//wimo_info.dst_width;//wimo_info.yaff;//wimo_info.dst_width;//dst_width;
1936 overlay_req.flag = IPP_ROT_0;
1938 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);
1939 err = ipp_blit_sync(&overlay_req);
1942 // printk("overlay setbuffer exit\n");
1944 wimo_info.fb_lock = 0;
1951 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1953 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1954 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1960 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1963 inf->mcu_usetimer = 0;
1966 case FBIOPUT_16OR32:
1968 inf->fb0_color_deepth = arg;
1971 case FBIOGET_16OR32:
1972 return inf->fb0_color_deepth;
1973 case FBIOGET_IDLEFBUff_16OR32:
1974 if(info->var.yoffset == 0)
1976 return fb0_second_buff_bits;
1980 return fb0_first_buff_bits;
1982 case FBIOSET_COMPOSE_LAYER_COUNTS:
1983 fb_compose_layer_count = arg;
1986 case FBIOGET_COMPOSE_LAYER_COUNTS:
1988 return fb_compose_layer_count;
1990 case FBIOPUT_FBPHYADD:
1991 return info->fix.smem_start;
1992 case FBIOGET_OVERLAY_STATE:
1993 return inf->video_mode;
1994 case FBIOGET_SCREEN_STATE:
1995 return inf->cur_screen->type;
1997 case FBIOPUT_SET_CURSOR_EN:
2000 if(copy_from_user(&en, (void*)arg, sizeof(int)))
2002 rk29_set_cursor_en(inf, en);
2005 case FBIOPUT_SET_CURSOR_POS:
2007 struct fbcurpos pos;
2008 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
2010 rk29_set_cursor_pos(inf, pos.x , pos.y);
2013 case FBIOPUT_SET_CURSOR_IMG:
2015 char cursor_buf[CURSOR_BUF_SIZE];
2016 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
2018 rk29_set_cursor_img(inf, cursor_buf);
2021 case FBIOPUT_SET_CURSOR_CMAP:
2023 struct fb_image img;
2024 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
2026 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
2029 case FBIOPUT_GET_CURSOR_RESOLUTION:
2032 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2033 if((inf->fb1->var.rotate &0x1ff ) == 270) {
2034 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
2035 panel_size[1] = inf->cur_screen->x_res;
2037 panel_size[0] = inf->cur_screen->x_res;
2038 panel_size[1] = inf->cur_screen->y_res;
2040 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
2043 case FBIOPUT_GET_CURSOR_EN:
2045 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
2046 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
2050 case FB0_IOCTL_SET_BUF:
2052 unsigned long temp[4];
2053 copy_from_user(temp, (void*)arg, 20);
2054 wimo_set_buff( info,temp);
2058 case FB0_IOCTL_CLOSE_BUF:
2060 if(ui_buffer != NULL && ui_buffer_map !=NULL )
2062 iounmap(ui_buffer_map);
2065 memset(&wimo_info,0,sizeof(wimo_info));
2068 printk("somethint wrong with wimo in close");
2073 case FB0_IOCTL_COPY_CURBUF:
2075 unsigned long temp_data[3];
2076 copy_from_user(&temp_vv, (void*)arg, 4);
2077 if(ui_buffer != NULL && ui_buffer_map !=NULL )
2079 temp_data[1] = wimo_get_buff(info);
2080 temp_data[0] = wimo_info.bitperpixel;
2086 temp_data[0] = wimo_info.bitperpixel;
2087 printk("somethint wrong with wimo in getbuf");
2089 temp_data[2] = frame_num++;
2090 //printk("FB0_IOCTL_COPY_CURBUF %d %d %d\n",temp_data[0],temp_data[1],temp_data[2]);
2091 copy_to_user((void*)arg, &temp_data, 12);
2101 static int fb1_blank(int blank_mode, struct fb_info *info)
2103 win0_blank(blank_mode, info);
2107 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
2109 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2110 struct rk29fb_screen *screen = inf->cur_screen;
2112 u32 ScaleYRGBY=0x1000;
2113 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
2114 u16 ypos = (var->nonstd>>20) & 0xfff;
2115 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
2116 u16 ysize = (var->grayscale>>20) & 0xfff;
2117 u16 xlcd = screen->x_res; //size of panel
2118 u16 ylcd = screen->y_res;
2121 struct hdmi *hdmi = get_hdmi_struct(0);
2124 if((var->rotate & 0x1ff) == 90 ||(var->rotate &0x1ff)== 270) {
2125 #ifdef CONFIG_FB_ROTATE_VIDEO
2126 xlcd = screen->y_res;
2127 ylcd = screen->x_res;
2128 #else //CONFIG_FB_ROTATE_VIDEO
2129 printk("LCDC not support rotate!\n");
2134 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2135 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2136 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2137 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2139 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2143 if( 0==var->xres_virtual || 0==var->yres_virtual ||
2144 0==var->xres || 0==var->yres || var->xres<16 ||
2145 0==xsize || 0==ysize || xsize<16 ||
2146 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
2148 printk(">>>>>> win0fb_check_var fail 1!!! \n");
2149 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
2150 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
2151 var->bits_per_pixel, var->bits_per_pixel);
2155 if( (var->xoffset+var->xres)>var->xres_virtual ||
2156 (var->yoffset+var->yres)>var->yres_virtual ||
2157 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
2159 printk(">>>>>> win0fb_check_var fail 2!!! \n");
2160 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
2161 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
2162 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
2166 switch(var->nonstd&0x0f)
2169 switch(var->bits_per_pixel)
2172 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
2173 var->xres = (var->xres + 0x1) & (~0x1);
2174 var->xoffset = (var->xoffset) & (~0x1);
2177 var->bits_per_pixel = 32;
2180 var->nonstd &= ~0xc0; //not support I2P in this format
2183 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2184 var->xres = (var->xres + 0x3) & (~0x3);
2185 var->xoffset = (var->xoffset) & (~0x3);
2188 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2189 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
2190 var->xres = (var->xres + 0x3) & (~0x3);
2191 var->yres = (var->yres + 0x1) & (~0x1);
2192 var->xoffset = (var->xoffset) & (~0x3);
2193 var->yoffset = (var->yoffset) & (~0x1);
2196 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2197 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
2198 var->xres = (var->xres + 0x3) & (~0x3);
2199 var->yres = (var->yres + 0x1) & (~0x1);
2200 var->xoffset = (var->xoffset) & (~0x3);
2201 var->yoffset = (var->yoffset) & (~0x1);
2202 var->nonstd &= ~0xc0; //not support I2P in this format
2206 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2207 var->xres = (var->xres + 0x3) & (~0x3);
2208 var->xoffset = (var->xoffset) & (~0x3);
2209 var->nonstd &= ~0xc0; //not support I2P in this format
2212 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
2216 if((var->rotate & 0x1ff ) == 90 ||(var->rotate & 0x1ff ) == 270)
2225 ScaleYRGBY = CalScaleW0(yres, ysize);
2227 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
2229 return -EINVAL; // multiple of scale down or scale up can't exceed 8
2232 if(inf->video_mode == 1) {
2233 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
2235 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2236 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2237 init_completion(&hdmi->complete);
2239 wait_for_completion_interruptible_timeout(&hdmi->complete,
2240 msecs_to_jiffies(10000));
2247 static int fb1_set_par(struct fb_info *info)
2249 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2250 struct rk29fb_screen *screen = inf->cur_screen;
2251 struct fb_var_screeninfo *var = &info->var;
2252 struct fb_fix_screeninfo *fix = &info->fix;
2253 struct win0_par *par = info->par;
2256 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
2258 //u32 xact = var->xres; /* visible resolution */
2259 //u32 yact = var->yres;
2260 u32 xvir = var->xres_virtual; /* virtual resolution */
2261 u32 yvir = var->yres_virtual;
2262 u32 xact_st = var->xoffset; /* offset from virtual to visible */
2263 u32 yact_st = var->yoffset; /* resolution */
2265 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
2266 u16 ypos = (var->nonstd>>20) & 0xfff;
2267 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
2268 u16 ysize = (var->grayscale>>20) & 0xfff;
2270 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
2271 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
2273 u8 data_format = var->nonstd&0x0f;
2274 // u32 win0_en = var->reserved[2];
2275 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
2276 // u32 uv_addr = var->reserved[4];
2278 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2280 if((var->rotate & 0x1ff ) == 90 || (var->rotate & 0x1ff ) == 270)
2282 #ifdef CONFIG_FB_ROTATE_VIDEO
2283 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
2284 ypos = (var->nonstd>>8) & 0xfff;
2285 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
2286 ysize = (var->grayscale>>8) & 0xfff;
2287 #else //CONFIG_FB_ROTATE_VIDEO
2288 printk("LCDC not support rotate!\n");
2292 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2293 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2294 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2295 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2297 /* calculate y_offset,c_offset,line_length,cblen and crlen */
2298 switch (data_format)
2301 switch(var->bits_per_pixel)
2305 fix->line_length = 2 * xvir;
2306 par->y_offset = (yact_st*xvir + xact_st)*2;
2310 fix->line_length = 4 * xvir;
2311 par->y_offset = (yact_st*xvir + xact_st)*4;
2319 fix->line_length = xvir;
2320 cblen = crlen = (xvir*yvir)/2;
2321 par->y_offset = yact_st*xvir + xact_st;
2322 par->c_offset = yact_st*xvir + xact_st;
2326 fix->line_length = xvir;
2327 cblen = crlen = (xvir*yvir)/4;
2329 par->y_offset = yact_st*xvir + xact_st;
2330 par->c_offset = (yact_st/2)*xvir + xact_st;
2335 fix->line_length = xvir;
2336 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
2337 par->c_offset = (yact_st/2)*xvir + xact_st;
2338 cblen = crlen = (xvir*yvir)/4;
2343 fix->line_length = xvir;
2344 par->y_offset = yact_st*xvir + xact_st;
2345 par->c_offset = yact_st*2*xvir + xact_st*2;
2346 cblen = crlen = (xvir*yvir);
2352 smem_len = fix->line_length * yvir + cblen + crlen;
2353 map_size = PAGE_ALIGN(smem_len);
2355 // fix->smem_start = y_addr;
2356 fix->smem_len = smem_len;
2357 // fix->mmio_start = uv_addr;
2359 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
2360 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);
2362 par->format = format;
2369 if ( wq_condition2 == 0 ) {
2370 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
2374 #ifdef CONFIG_FB_ROTATE_VIDEO
2375 //need refresh ,zyc add
2376 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
2379 struct rk29_ipp_req ipp_req;
2380 static u32 dstoffset = 0;
2381 static int fb_index = 0;
2382 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2383 yuv_phy[0] = last_yuv_phy[0];
2384 yuv_phy[1] = last_yuv_phy[1];
2385 yuv_phy[0] += par->y_offset;
2386 yuv_phy[1] += par->c_offset;
2388 if((var->rotate == 90) ||(var->rotate == 270))
2390 if(var->rotate%360 != 0)
2393 #ifdef CONFIG_FB_ROTATE_VIDEO
2394 dstoffset = (dstoffset+1)%2;
2395 ipp_req.src0.fmt = 3;
2396 ipp_req.src0.YrgbMst = yuv_phy[0];
2397 ipp_req.src0.CbrMst = yuv_phy[1];
2398 ipp_req.src0.w = var->xres;
2399 ipp_req.src0.h = var->yres;
2401 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2402 ipp_req.dst_vir_w=screen->x_res;
2404 ipp_req.dst0.fmt = 3;
2405 #ifdef CONFIG_FB_MIRROR_X_Y
2406 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2408 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*4;
2409 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*5;
2413 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2414 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2417 if(var->xres > screen->x_res)
2419 ipp_req.dst0.w = screen->x_res;
2420 ipp_req.dst0.h = screen->y_res;
2422 ipp_req.dst0.w = var->xres;
2423 ipp_req.dst0.h = var->yres;
2425 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2426 ipp_req.timeout = 100;
2427 if((var->rotate & 0x1ff) == 90)
2428 ipp_req.flag = IPP_ROT_90;
2429 else if ((var->rotate & 0x1ff) == 180)
2430 ipp_req.flag = IPP_ROT_180;
2431 else if((var->rotate & 0x1ff) == 270)
2432 ipp_req.flag = IPP_ROT_270;
2433 else if((var->rotate & X_MIRROR) == X_MIRROR )
2434 ipp_req.flag = IPP_ROT_X_FLIP;
2435 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2436 ipp_req.flag = IPP_ROT_Y_FLIP;
2437 //ipp_do_blit(&ipp_req);
2438 ipp_blit_sync(&ipp_req);
2439 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2440 yuv_phy[1] = ipp_req.dst0.CbrMst;
2441 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2443 memset(&ipp_req,0,sizeof(struct rk29_ipp_req));
2445 if((var->rotate & X_MIRROR) == X_MIRROR)
2446 ipp_req.flag = IPP_ROT_X_FLIP;
2447 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2448 ipp_req.flag = IPP_ROT_Y_FLIP;
2450 printk(">>>>>> %d rotate is not support!\n",var->rotate);
2452 if(var->xres > screen->x_res)
2454 ipp_req.dst0.w = screen->x_res;
2455 ipp_req.dst0.h = screen->y_res;
2457 ipp_req.dst0.w = var->xres;
2458 ipp_req.dst0.h = var->yres;
2460 ipp_req.src0.fmt = 3;
2461 ipp_req.src0.YrgbMst = yuv_phy[0];
2462 ipp_req.src0.CbrMst = yuv_phy[1];
2463 ipp_req.src0.w = ipp_req.dst0.w;
2464 ipp_req.src0.h = ipp_req.dst0.h;
2466 ipp_req.src_vir_w= (ipp_req.dst0.w + 15) & (~15);
2467 ipp_req.dst_vir_w= (ipp_req.dst0.w + 15) & (~15);
2469 ipp_req.dst0.fmt = 3;
2470 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2471 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2473 ipp_req.timeout = 100;
2474 ipp_blit_sync(&ipp_req);
2475 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2476 yuv_phy[1] = ipp_req.dst0.CbrMst;
2478 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2480 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2481 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2482 if(var->xres > screen->x_res)
2484 ipp_req.dst0.w = screen->x_res;
2485 ipp_req.dst0.h = screen->y_res;
2487 ipp_req.dst0.w = var->xres;
2488 ipp_req.dst0.h = var->yres;
2491 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2492 ipp_req.timeout = 100;
2493 if(var->rotate == 90)
2494 ipp_req.flag = IPP_ROT_90;
2495 else if(var->rotate == 180)
2496 ipp_req.flag = IPP_ROT_180;
2497 else if(var->rotate == 270)
2498 ipp_req.flag = IPP_ROT_270;
2499 //ipp_do_blit(&ipp_req);
2500 ipp_blit_sync(&ipp_req);
2502 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2503 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2504 yuv_phy[1] = ipp_req.dst0.CbrMst;
2506 fix->smem_start = yuv_phy[0];
2507 fix->mmio_start = yuv_phy[1];
2508 #else //CONFIG_FB_ROTATE_VIDEO
2509 printk("LCDC not support rotate!\n");
2515 fix->smem_start = yuv_phy[0];
2516 fix->mmio_start = yuv_phy[1];
2519 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2520 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2521 // enable win0 after the win0 par is seted
2522 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2523 par->addr_seted = 1;
2524 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2525 if(par->addr_seted ) {
2526 unsigned long flags;
2528 local_irq_save(flags);
2529 par->mirror.y_offset = yuv_phy[0];
2530 par->mirror.c_offset = yuv_phy[1];
2531 local_irq_restore(flags);
2534 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2539 has_set_rotate = false;
2544 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2546 struct win0_par *par = info->par;
2547 // enable win0 after the win0 addr is seted
2554 int fb1_open(struct fb_info *info, int user)
2556 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2557 struct win0_par *par = info->par;
2558 struct rk29fb_screen *screen = inf->cur_screen;
2560 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2563 par->addr_seted = 0;
2564 inf->video_mode = 1;
2566 #ifdef CONFIG_FB_ROTATE_VIDEO
2567 //reinitialize the var when open,zyc
2568 last_yuv_phy[0] = 0;
2569 last_yuv_phy[1] = 0;
2573 printk(">>>>>> fb1 has opened! \n");
2577 win0_blank(FB_BLANK_NORMAL, info);
2578 if(screen->x_res>1280)
2580 fb0_set_par(inf->fb0);
2582 rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2587 int fb1_release(struct fb_info *info, int user)
2589 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2590 struct win0_par *par = info->par;
2591 struct fb_var_screeninfo *var0 = &info->var;
2593 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2594 if(inf->setFlag == 0)
2596 wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2600 inf->video_mode = 0;
2602 par->addr_seted = 0;
2603 win1_blank(FB_BLANK_NORMAL, info);
2605 //if(inf->cur_screen->type != SCREEN_HDMI)
2606 fb0_set_par(inf->fb0);
2609 info->screen_base = 0;
2610 info->fix.smem_start = 0;
2611 info->fix.smem_len = 0;
2612 // clean the var param
2613 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2614 rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2615 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
2616 cancel_delayed_work_sync(&rk29_win1_check_work);
2623 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2625 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2626 struct win0_par *par = info->par;
2627 struct fb_fix_screeninfo *fix0 = &info->fix;
2628 struct fb_var_screeninfo *var = &info->var;
2629 void __user *argp = (void __user *)arg;
2631 #ifdef CONFIG_FB_ROTATE_VIDEO
2632 struct rk29fb_screen *screen = inf->cur_screen;
2633 struct rk29_ipp_req ipp_req;
2634 static u32 dstoffset = 0;
2635 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2638 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2639 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2645 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2648 if((var->rotate & 0x1ff) == 270 ||(var->rotate & 0x1ff) == 90) {
2649 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2650 panel_size[1] = inf->panel1_info.x_res;
2652 panel_size[0] = inf->panel1_info.x_res;
2653 panel_size[1] = inf->panel1_info.y_res;
2656 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2660 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2664 // printk("FB1_IOCTL_SET_YUV_ADDR1 \n");
2665 // while(wimo_info.fb_lock)
2669 // printk("FB1_IOCTL_SET_YUV_ADDR 2\n");
2671 if (copy_from_user(yuv_phy, argp, 8))
2673 #ifdef CONFIG_FB_ROTATE_VIDEO
2675 if(has_set_rotate == true)
2677 last_yuv_phy[0] = yuv_phy[0];
2678 last_yuv_phy[1] = yuv_phy[1];
2681 fix0->smem_start = yuv_phy[0];
2682 fix0->mmio_start = yuv_phy[1];
2683 yuv_phy[0] += par->y_offset;
2684 yuv_phy[1] += par->c_offset;
2686 wimo_info.src_y = yuv_phy[0];
2687 wimo_info.src_uv = yuv_phy[1];
2692 if((var->rotate == 90) ||(var->rotate == 270))
2694 if(var->rotate%360 != 0)
2697 #ifdef CONFIG_FB_ROTATE_VIDEO
2698 dstoffset = (dstoffset+1)%2;
2699 ipp_req.src0.fmt = 3;
2700 ipp_req.src0.YrgbMst = yuv_phy[0];
2701 ipp_req.src0.CbrMst = yuv_phy[1];
2702 ipp_req.src0.w = var->xres ;
2703 ipp_req.src0.h = var->yres ;
2704 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2705 ipp_req.dst_vir_w=screen->x_res;
2707 ipp_req.dst0.fmt = 3;
2708 #ifdef CONFIG_FB_MIRROR_X_Y
2709 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2711 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*4;
2712 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*5;
2716 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2717 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2720 if(var->xres > screen->x_res)
2722 ipp_req.dst0.w = screen->x_res;
2723 ipp_req.dst0.h = screen->y_res;
2725 ipp_req.dst0.w = var->xres;
2726 ipp_req.dst0.h = var->yres;
2728 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2729 ipp_req.timeout = 100;
2730 if((var->rotate & 0x1ff) == 90)
2731 ipp_req.flag = IPP_ROT_90;
2732 else if ((var->rotate & 0x1ff) == 180)
2733 ipp_req.flag = IPP_ROT_180;
2734 else if((var->rotate & 0x1ff) == 270)
2735 ipp_req.flag = IPP_ROT_270;
2736 else if((var->rotate & X_MIRROR) == X_MIRROR )
2737 ipp_req.flag = IPP_ROT_X_FLIP;
2738 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2739 ipp_req.flag = IPP_ROT_Y_FLIP;
2740 //ipp_do_blit(&ipp_req);
2741 ipp_blit_sync(&ipp_req);
2742 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2743 yuv_phy[1] = ipp_req.dst0.CbrMst;
2744 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2746 memset(&ipp_req,0,sizeof(struct rk29_ipp_req));
2748 if((var->rotate & X_MIRROR) == X_MIRROR)
2749 ipp_req.flag = IPP_ROT_X_FLIP;
2750 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2751 ipp_req.flag = IPP_ROT_Y_FLIP;
2753 printk(">>>>>> %d rotate is not support!\n",var->rotate);
2755 if(var->xres > screen->x_res)
2757 ipp_req.dst0.w = screen->x_res;
2758 ipp_req.dst0.h = screen->y_res;
2760 ipp_req.dst0.w = var->xres;
2761 ipp_req.dst0.h = var->yres;
2763 ipp_req.src0.fmt = 3;
2764 ipp_req.src0.YrgbMst = yuv_phy[0];
2765 ipp_req.src0.CbrMst = yuv_phy[1];
2766 ipp_req.src0.w = ipp_req.dst0.w;
2767 ipp_req.src0.h = ipp_req.dst0.h;
2769 ipp_req.src_vir_w= (ipp_req.dst0.w + 15) & (~15);
2770 ipp_req.dst_vir_w= (ipp_req.dst0.w + 15) & (~15);
2772 ipp_req.dst0.fmt = 3;
2773 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2774 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2776 ipp_req.timeout = 100;
2777 ipp_blit_sync(&ipp_req);
2778 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2779 yuv_phy[1] = ipp_req.dst0.CbrMst;
2781 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2783 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2784 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2785 if(var->xres > screen->x_res)
2787 ipp_req.dst0.w = screen->x_res;
2788 ipp_req.dst0.h = screen->y_res;
2790 ipp_req.dst0.w = var->xres;
2791 ipp_req.dst0.h = var->yres;
2794 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2795 ipp_req.timeout = 100;
2796 if(var->rotate == 90)
2797 ipp_req.flag = IPP_ROT_90;
2798 else if(var->rotate == 180)
2799 ipp_req.flag = IPP_ROT_180;
2800 else if(var->rotate == 270)
2801 ipp_req.flag = IPP_ROT_270;
2802 //ipp_do_blit(&ipp_req);
2803 ipp_blit_sync(&ipp_req);
2805 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2806 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2807 yuv_phy[1] = ipp_req.dst0.CbrMst;
2809 fix0->smem_start = yuv_phy[0];
2810 fix0->mmio_start = yuv_phy[1];
2811 #else //CONFIG_FB_ROTATE_VIDEO
2812 printk("LCDC not support rotate!\n");
2816 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2817 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2818 // enable win0 after the win0 par is seted
2819 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2820 par->addr_seted = 1;
2821 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2822 if(par->par_seted) {
2823 unsigned long flags;
2825 local_irq_save(flags);
2826 par->mirror.y_offset = yuv_phy[0];
2827 par->mirror.c_offset = yuv_phy[1];
2828 local_irq_restore(flags);
2831 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2836 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2837 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2838 #ifdef CONFIG_FB_ROTATE_VIDEO
2840 has_set_rotate = true;
2841 #ifdef CONFIG_FB_MIRROR_X_Y
2842 if( ((arg&0x1ff)%90) == 0 && ( arg&(~0xfff))==0 )
2844 if( (arg&( X_MIRROR | Y_MIRROR ) )== (X_MIRROR | Y_MIRROR) )
2845 var->rotate = ROTATE_180;
2846 else if((arg&( ROTATE_90 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_90 | X_MIRROR | Y_MIRROR))
2847 var->rotate = ROTATE_270;
2848 else if((arg&( ROTATE_180 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_180 | X_MIRROR | Y_MIRROR))
2849 var->rotate = ROTATE_90;
2850 else if((arg&( ROTATE_270 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_270 | X_MIRROR | Y_MIRROR))
2851 var->rotate = ROTATE_0;
2854 if(arg == ROTATE_0 || arg==ROTATE_90 || arg == ROTATE_180 || arg==ROTATE_270)
2860 printk(">>>>>> %d rotate is not support!\n",(int)arg);
2862 #else //CONFIG_FB_ROTATE_VIDEO
2863 printk("LCDC not support rotate!\n");
2866 case FB1_IOCTL_SET_WIN0_TOP:
2867 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2868 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2869 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2877 static struct fb_ops fb1_ops = {
2878 .owner = THIS_MODULE,
2879 .fb_open = fb1_open,
2880 .fb_release = fb1_release,
2881 .fb_check_var = fb1_check_var,
2882 .fb_set_par = fb1_set_par,
2883 .fb_blank = fb1_blank,
2884 .fb_pan_display = fb1_pan_display,
2885 .fb_ioctl = fb1_ioctl,
2886 .fb_setcolreg = fb_setcolreg,
2887 .fb_fillrect = cfb_fillrect,
2888 .fb_copyarea = cfb_copyarea,
2889 .fb_imageblit = cfb_imageblit,
2892 static struct fb_ops fb0_ops = {
2893 .owner = THIS_MODULE,
2894 .fb_check_var = fb0_check_var,
2895 .fb_set_par = fb0_set_par,
2896 .fb_blank = fb0_blank,
2897 .fb_pan_display = fb0_pan_display,
2898 .fb_ioctl = fb0_ioctl,
2899 .fb_setcolreg = fb_setcolreg,
2900 .fb_fillrect = cfb_fillrect,
2901 .fb_copyarea = cfb_copyarea,
2902 .fb_imageblit = cfb_imageblit,
2903 //.fb_cursor = rk29_set_cursor,
2906 int fb_get_video_mode(void)
2908 struct rk29fb_inf *inf;
2911 inf = platform_get_drvdata(g_pdev);
2912 return inf->video_mode;
2915 enable: 1, switch to tv or hdmi; 0, switch to lcd
2917 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2919 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2920 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2921 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2923 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2925 if(enable)inf->cur_screen = &inf->panel2_info;
2926 else inf->cur_screen = &inf->panel1_info;
2928 /* Black out, because some display device need clock to standby */
2929 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2930 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2931 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2932 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2933 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2934 wake_lock(&idlelock);
2936 wake_unlock(&idlelock);
2938 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2939 // operate the display_on pin to power down the lcd
2940 #ifdef CONFIG_HDMI_DUAL_DISP
2941 inf->panel1_info.sscreen_get(&inf->panel1_info,inf->panel2_info.hdmi_resolution);
2942 inf->panel1_info.sscreen_set(&inf->panel1_info,enable);
2944 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2945 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2947 load_screen(inf->fb0, 0);
2950 fb1_set_par(inf->fb1);
2951 fb0_set_par(inf->fb0);
2952 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2953 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2955 rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2959 static ssize_t dsp_win0_info_read(struct device *device,
2960 struct device_attribute *attr, char *buf)
2963 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2964 struct rk29fb_screen *screen = inf->cur_screen;
2966 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2968 fbprintk("%s\n",__FUNCTION__);
2969 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2970 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2972 xpos -= (screen->left_margin + screen->hsync_len);
2973 ypos -= (screen->upper_margin + screen->vsync_len);
2975 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2976 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2977 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2978 rk29_set_cursor_test(inf->fb0);
2980 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2983 static ssize_t dsp_win0_info_write(struct device *device,
2984 struct device_attribute *attr, const char *buf, size_t count)
2986 printk("%s\n",__FUNCTION__);
2987 printk("%s %x \n",__FUNCTION__,*buf);
2991 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2993 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2995 struct platform_device *pdev = (struct platform_device*)dev_id;
2996 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2997 struct win0_par *par = (struct win0_par *)inf->fb1->par;
3001 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
3003 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
3005 if(SCREEN_MCU == inf->cur_screen->type)
3007 inf->mcu_isrcnt = !inf->mcu_isrcnt;
3013 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
3015 inf->mcu_fmksync = 1;
3016 if(inf->cur_screen->refresh)
3017 inf->cur_screen->refresh(REFRESH_END);
3018 inf->mcu_fmksync = 0;
3027 if(inf->mcu_needflush) {
3028 if(inf->cur_screen->refresh)
3029 inf->cur_screen->refresh(REFRESH_PRE);
3030 inf->mcu_needflush = 0;
3031 inf->mcu_isrcnt = 0;
3032 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
3034 if(inf->cur_screen->refresh)
3035 inf->cur_screen->refresh(REFRESH_END);
3039 #if ANDROID_USE_THREE_BUFS
3040 new_frame_seted = 1;
3043 if(waitqueue_active(&par->wait)) {
3044 if (par->mirror.c_offset == 0)
3045 printk("error: no new buffer to display\n");
3047 par->done.y_offset = par->displ.y_offset;
3048 par->done.c_offset = par->displ.c_offset;
3049 par->displ.y_offset = par->mirror.y_offset;
3050 par->displ.c_offset = par->mirror.c_offset;
3051 par->mirror.y_offset = 0;
3052 par->mirror.c_offset = 0;
3054 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
3055 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
3056 wake_up_interruptible(&par->wait);
3061 wake_up_interruptible(&wq);
3063 rk29fb_irq_notify_ddr();
3067 #ifdef CONFIG_HAS_EARLYSUSPEND
3069 struct suspend_info {
3070 struct early_suspend early_suspend;
3071 struct rk29fb_inf *inf;
3074 static void rk29fb_early_suspend(struct early_suspend *h)
3076 struct suspend_info *info = container_of(h, struct suspend_info,
3079 struct rk29fb_inf *inf = info->inf;
3080 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
3082 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3085 printk("inf==0, rk29fb_suspend fail! \n");
3089 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC
3090 cancel_delayed_work_sync(&rk29_win1_check_work);
3093 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
3094 mach_info->io_disable(); //close lcd out
3096 if(inf->cur_screen->standby)
3098 fbprintk(">>>>>> power down the screen! \n");
3099 inf->cur_screen->standby(1);
3101 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE | m_W1_ENABLE, v_W0_ENABLE(0) | v_W1_ENABLE(0));
3103 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
3104 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
3106 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3107 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3108 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3110 if(!inf->in_suspend)
3112 fbprintk(">>>>>> diable the lcdc clk! \n");
3113 wake_lock(&idlelock);
3115 wake_unlock(&idlelock);
3116 clk_disable(inf->aclk_ddr_lcdc);
3117 clk_disable(inf->aclk_disp_matrix);
3118 clk_disable(inf->hclk_cpu_display);
3119 clk_disable(inf->clk);
3121 clk_disable(inf->dclk);
3124 clk_disable(inf->aclk);
3126 //clk_disable(inf->pd_display);
3128 inf->in_suspend = 1;
3132 static void rk29fb_early_resume(struct early_suspend *h)
3134 struct suspend_info *info = container_of(h, struct suspend_info,
3137 struct rk29fb_inf *inf = info->inf;
3138 struct rk29fb_screen *screen = inf->cur_screen;
3139 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
3141 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3143 printk("inf==0, rk29fb_resume fail! \n");
3149 inf->in_suspend = 0;
3150 fbprintk(">>>>>> enable the lcdc clk! \n");
3151 // clk_enable(inf->pd_display);
3152 clk_enable(inf->aclk_disp_matrix);
3153 clk_enable(inf->hclk_cpu_display);
3154 clk_enable(inf->clk);
3155 clk_enable(inf->aclk_ddr_lcdc);
3158 clk_enable(inf->dclk);
3161 clk_enable(inf->aclk);
3163 usleep_range(100*1000, 100*1000);
3165 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
3166 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
3167 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3169 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
3170 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
3172 if(inf->cur_screen->standby)
3174 fbprintk(">>>>>> power on the screen! \n");
3175 inf->cur_screen->standby(0);
3177 usleep_range(10*1000, 10*1000);
3178 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
3179 usleep_range(40*1000, 40*1000);
3181 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
3182 mach_info->io_enable(); //close lcd out
3186 static struct suspend_info suspend_info = {
3187 .early_suspend.suspend = rk29fb_early_suspend,
3188 .early_suspend.resume = rk29fb_early_resume,
3189 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
3192 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
3193 static int __devinit rk29fb_probe (struct platform_device *pdev)
3195 struct rk29fb_inf *inf = NULL;
3196 struct resource *res = NULL;
3197 struct resource *mem = NULL;
3198 struct rk29fb_info *mach_info = NULL;
3199 struct rk29fb_screen *screen = NULL;
3200 struct win0_par* par = NULL;
3204 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3206 /* Malloc rk29fb_inf and set it to pdev for drvdata */
3207 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
3208 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
3211 dev_err(&pdev->dev, ">> inf kmalloc fail!");
3213 goto release_drvdata;
3215 memset(inf, 0, sizeof(struct rk29fb_inf));
3216 platform_set_drvdata(pdev, inf);
3218 mach_info = pdev->dev.platform_data;
3219 /* Fill screen info and set current screen */
3220 fbprintk(">> Fill screen info and set current screen \n");
3221 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
3222 hdmi_get_default_resolution(&inf->panel1_info);
3224 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
3227 inf->cur_screen = &inf->panel1_info;
3228 screen = inf->cur_screen;
3229 if(SCREEN_NULL==screen->type)
3231 dev_err(&pdev->dev, ">> Please select a display device! \n");
3233 goto release_drvdata;
3236 /* get virtual basic address of lcdc register */
3237 fbprintk(">> get virtual basic address of lcdc register \n");
3238 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
3241 dev_err(&pdev->dev, "failed to get memory registers\n");
3243 goto release_drvdata;
3245 inf->reg_phy_base = res->start;
3246 inf->len = (res->end - res->start) + 1;
3247 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
3250 dev_err(&pdev->dev, "failed to get memory region\n");
3252 goto release_drvdata;
3254 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
3255 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
3256 if (inf->reg_vir_base == NULL)
3258 dev_err(&pdev->dev, "ioremap() of registers failed\n");
3260 goto release_drvdata;
3262 inf->preg = (LCDC_REG*)inf->reg_vir_base;
3264 /* Prepare win1 info */
3265 fbprintk(">> Prepare win1 info \n");
3266 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
3269 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
3272 goto release_win1fb;
3275 par = (struct win0_par*)inf->fb0->par;
3276 strcpy(inf->fb0->fix.id, "fb0");
3277 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
3278 inf->fb0->fix.type_aux = 0;
3279 inf->fb0->fix.xpanstep = 1;
3280 inf->fb0->fix.ypanstep = 1;
3281 inf->fb0->fix.ywrapstep = 0;
3282 inf->fb0->fix.accel = FB_ACCEL_NONE;
3283 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
3284 inf->fb0->fix.smem_len = 0;
3285 inf->fb0->fix.line_length = 0;
3286 inf->fb0->fix.smem_start = 0;
3288 inf->fb0->var.xres = screen->x_res;
3289 inf->fb0->var.yres = screen->y_res;
3290 inf->fb0->var.bits_per_pixel = 16;
3291 inf->fb0_color_deepth = 0;
3292 inf->fb0->var.xres_virtual = screen->x_res;
3293 inf->fb0->var.yres_virtual = screen->y_res;
3294 inf->fb0->var.width = screen->width;
3295 inf->fb0->var.height = screen->height;
3296 //inf->fb0->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
3297 inf->fb0->var.left_margin = screen->left_margin;
3298 inf->fb0->var.right_margin = screen->right_margin;
3299 inf->fb0->var.upper_margin = screen->upper_margin;
3300 inf->fb0->var.lower_margin = screen->lower_margin;
3301 inf->fb0->var.vsync_len = screen->vsync_len;
3302 inf->fb0->var.hsync_len = screen->hsync_len;
3303 inf->fb0->var.red = def_rgb_16.red;
3304 inf->fb0->var.green = def_rgb_16.green;
3305 inf->fb0->var.blue = def_rgb_16.blue;
3306 inf->fb0->var.transp = def_rgb_16.transp;
3308 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
3309 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
3310 inf->fb0->var.activate = FB_ACTIVATE_NOW;
3311 inf->fb0->var.accel_flags = 0;
3312 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
3314 inf->fb0->fbops = &fb0_ops;
3315 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
3316 inf->fb0->pseudo_palette = par->pseudo_pal;
3317 inf->fb0->screen_base = 0;
3319 memset(par, 0, sizeof(struct win0_par));
3321 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
3325 g_fb0_inf = inf->fb0; //add cym@rk 20101027
3327 /* alloc win1 buf */
3328 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
3331 dev_err(&pdev->dev, "failed to get win1 memory \n");
3333 goto release_win1fb;
3335 inf->fb0->fix.smem_start = res->start;
3336 inf->fb0->fix.smem_len = res->end - res->start + 1;
3337 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
3338 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
3340 #ifdef CONFIG_FB_WORK_IPP
3341 /* alloc win1 ipp buf */
3342 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
3345 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
3347 goto release_win1fb;
3349 inf->fb0->fix.mmio_start = res->start;
3350 inf->fb0->fix.mmio_len = res->end - res->start + 1;
3353 /* Prepare win0 info */
3354 fbprintk(">> Prepare win0 info \n");
3355 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
3358 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
3361 goto release_win0fb;
3364 par = (struct win0_par*)inf->fb1->par;
3366 strcpy(inf->fb1->fix.id, "fb1");
3367 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
3368 inf->fb1->fix.type_aux = 0;
3369 inf->fb1->fix.xpanstep = 1;
3370 inf->fb1->fix.ypanstep = 1;
3371 inf->fb1->fix.ywrapstep = 0;
3372 inf->fb1->fix.accel = FB_ACCEL_NONE;
3373 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
3374 inf->fb1->fix.smem_len = 0;
3375 inf->fb1->fix.line_length = 0;
3376 inf->fb1->fix.smem_start = 0;
3378 inf->fb1->var.xres = screen->x_res;
3379 inf->fb1->var.yres = screen->y_res;
3380 inf->fb1->var.bits_per_pixel = 16;
3381 inf->fb1->var.xres_virtual = screen->x_res;
3382 inf->fb1->var.yres_virtual = screen->y_res;
3383 inf->fb1->var.width = screen->width;
3384 inf->fb1->var.height = screen->height;
3385 //inf->fb1->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
3386 inf->fb1->var.left_margin = screen->left_margin;
3387 inf->fb1->var.right_margin = screen->right_margin;
3388 inf->fb1->var.upper_margin = screen->upper_margin;
3389 inf->fb1->var.lower_margin = screen->lower_margin;
3390 inf->fb1->var.vsync_len = screen->vsync_len;
3391 inf->fb1->var.hsync_len = screen->hsync_len;
3392 inf->fb1->var.red = def_rgb_16.red;
3393 inf->fb1->var.green = def_rgb_16.green;
3394 inf->fb1->var.blue = def_rgb_16.blue;
3395 inf->fb1->var.transp = def_rgb_16.transp;
3397 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
3398 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
3399 inf->fb1->var.activate = FB_ACTIVATE_NOW;
3400 inf->fb1->var.accel_flags = 0;
3401 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
3403 inf->fb1->fbops = &fb1_ops;
3404 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
3405 inf->fb1->pseudo_palette = par->pseudo_pal;
3406 inf->fb1->screen_base = 0;
3408 memset(par, 0, sizeof(struct win0_par));
3410 init_waitqueue_head(&par->wait);
3412 /* Init all lcdc and lcd before register_framebuffer. */
3413 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
3414 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
3415 init_lcdc(inf->fb0);
3417 #if 0 //def CONFIG_CPU_FREQ
3418 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
3419 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3421 fbprintk("got clock\n");
3425 struct rk29_fb_setting_info fb_setting;
3426 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
3428 fb_setting.data_num = 24;
3430 else if(OUT_P666 == inf->cur_screen->face )
3432 fb_setting.data_num = 18;
3436 fb_setting.data_num = 16;
3438 fb_setting.den_en = 1;
3439 fb_setting.vsync_en = 1;
3440 fb_setting.disp_on_en = 1;
3441 fb_setting.standby_en = 1;
3442 if( inf->cur_screen->mcu_usefmk )
3443 fb_setting.mcu_fmk_en =1;
3444 mach_info->io_init(&fb_setting);
3447 //set_lcd_pin(pdev, 1);
3450 inf->mcu_usetimer = 1;
3451 inf->mcu_fmksync = 0;
3452 load_screen(inf->fb0, 1);
3454 /* Register framebuffer(fb0 & fb1) */
3455 fbprintk(">> Register framebuffer(fb0) \n");
3456 ret = register_framebuffer(inf->fb0);
3459 printk(">> fb0 register_framebuffer fail!\n");
3461 goto release_win0fb;
3463 fbprintk(">> Register framebuffer(fb1) \n");
3465 ret = register_framebuffer(inf->fb1);
3468 printk(">> fb1 register_framebuffer fail!\n");
3470 goto unregister_win1fb;
3473 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3476 printk(">> fb1 dsp win0 info device_create_file err\n");
3479 #ifdef CONFIG_HAS_EARLYSUSPEND
3480 suspend_info.inf = inf;
3481 register_early_suspend(&suspend_info.early_suspend);
3484 /* get and request irq */
3485 fbprintk(">> get and request irq \n");
3486 irq = platform_get_irq(pdev, 0);
3488 dev_err(&pdev->dev, "no irq for device\n");
3490 goto unregister_win1fb;
3492 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
3494 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
3499 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
3501 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
3504 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
3509 #ifdef CONFIG_MFD_RK610
3510 rk610_lcd_scaler_set_param(&inf->panel1_info,0);
3512 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
3513 fb0_set_par(inf->fb0);
3514 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
3515 /* Start display and show logo on boot */
3516 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
3517 fb_show_logo(inf->fb0, FB_ROTATE_UR);
3518 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
3522 printk(" %s ok\n", __FUNCTION__);
3527 free_irq(irq, pdev);
3529 unregister_framebuffer(inf->fb0);
3532 framebuffer_release(inf->fb1);
3536 fb_dealloc_cmap(&inf->fb0->cmap);
3539 framebuffer_release(inf->fb0);
3542 if(inf && inf->reg_vir_base)
3543 iounmap(inf->reg_vir_base);
3545 release_mem_region(inf->reg_phy_base, inf->len);
3548 platform_set_drvdata(pdev, NULL);
3552 static int __devexit rk29fb_remove(struct platform_device *pdev)
3554 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3555 struct fb_info *info = NULL;
3557 struct rk29fb_info *mach_info = NULL;
3560 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3563 printk("inf==0, rk29_fb_remove fail! \n");
3566 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3568 irq = platform_get_irq(pdev, 0);
3571 free_irq(irq, pdev);
3574 mach_info = pdev->dev.platform_data;
3575 if(mach_info->mcu_fmk_pin)
3577 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
3580 if(mach_info->io_disable)
3581 mach_info->io_disable(); //close lcd out
3585 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
3587 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
3590 //rk29fb_suspend(pdev, msg);
3591 // unmap memory and release framebuffer
3594 if (info->screen_base) {
3595 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3596 info->screen_base = 0;
3597 info->fix.smem_start = 0;
3598 info->fix.smem_len = 0;
3600 unregister_framebuffer(inf->fb1);
3601 framebuffer_release(inf->fb1);
3606 if (info->screen_base) {
3607 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3608 info->screen_base = 0;
3609 info->fix.smem_start = 0;
3610 info->fix.smem_len = 0;
3612 unregister_framebuffer(inf->fb0);
3613 framebuffer_release(inf->fb0);
3617 #if 0 //def CONFIG_CPU_FREQ
3618 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3625 clk_disable(inf->clk);
3631 clk_disable(inf->dclk);
3637 platform_set_drvdata(pdev, NULL);
3642 static void rk29fb_shutdown(struct platform_device *pdev)
3644 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3645 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3647 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3649 if(mach_info->io_disable)
3650 mach_info->io_disable(); //close lcd out
3652 if(!inf->in_suspend)
3654 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3655 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3656 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3658 clk_disable(inf->aclk_ddr_lcdc);
3659 clk_disable(inf->aclk_disp_matrix);
3660 clk_disable(inf->hclk_cpu_display);
3661 clk_disable(inf->clk);
3663 clk_disable(inf->dclk);
3666 clk_disable(inf->aclk);
3668 clk_disable(inf->pd_display);
3669 //pmu_set_power_domain(PD_DISPLAY, 0);
3670 inf->in_suspend = 1;
3675 static struct platform_driver rk29fb_driver = {
3676 .probe = rk29fb_probe,
3677 .remove = __devexit_p(rk29fb_remove),
3680 .owner = THIS_MODULE,
3682 .shutdown = rk29fb_shutdown,
3685 static int __init rk29fb_init(void)
3687 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3688 return platform_driver_register(&rk29fb_driver);
3691 static void __exit rk29fb_exit(void)
3693 platform_driver_unregister(&rk29fb_driver);
3696 fs_initcall(rk29fb_init);
3697 module_exit(rk29fb_exit);
3700 MODULE_AUTHOR(" zyw@rock-chips.com");
3701 MODULE_DESCRIPTION("Driver for rk29 fb device");
3702 MODULE_LICENSE("GPL");