2 * drivers/video/rk29_fb.c
4 * Copyright (C) 2010 ROCKCHIP, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
25 #include <linux/init.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/interrupt.h>
28 #include <linux/platform_device.h>
29 #include <linux/clk.h>
30 #include <linux/backlight.h>
31 #include <linux/timer.h>
32 #include <linux/time.h>
33 #include <linux/wait.h>
34 #include <linux/earlysuspend.h>
35 #include <linux/cpufreq.h>
36 #include <linux/wakelock.h>
39 #include <asm/div64.h>
40 #include <asm/uaccess.h>
41 #include <asm/cacheflush.h>
49 #include <linux/completion.h>
51 #include <linux/hdmi.h>
54 #include <mach/iomux.h>
55 #include <mach/gpio.h>
56 #include <mach/board.h>
57 #include <mach/rk29_iomap.h>
59 #include <mach/rk29-ipp.h>
61 #include "./display/screen/screen.h"
63 #define ANDROID_USE_THREE_BUFS 0 //android use three buffers to accelerate UI display in rgb plane
64 #define CURSOR_BUF_SIZE 256 //RK2818 cursor need 256B buf
65 int rk29_cursor_buf[CURSOR_BUF_SIZE];
102 #define fbprintk(msg...) printk(msg);
104 #define fbprintk(msg...)
109 #define fbprintk2(msg...) printk(msg);
111 #define fbprintk2(msg...)
114 #define LcdReadBit(inf, addr, msk) ((inf->regbak.addr=inf->preg->addr)&(msk))
115 #define LcdWrReg(inf, addr, val) inf->preg->addr=inf->regbak.addr=(val)
116 #define LcdRdReg(inf, addr) (inf->preg->addr)
117 #define LcdSetBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) |= (msk))
118 #define LcdClrBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) &= ~(msk))
119 #define LcdSetRegisterBit(inf, addr, msk) inf->preg->addr=((inf->preg->addr) |= (msk))
120 #define LcdMskReg(inf, addr, msk, val) (inf->regbak.addr)&=~(msk); inf->preg->addr=(inf->regbak.addr|=(val))
123 #define IsMcuLandscape() ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
124 #define IsMcuUseFmk() ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
126 #define CalScaleW0(x, y) (((u32)x*0x1000)/y)
129 struct fb_bitfield red;
130 struct fb_bitfield green;
131 struct fb_bitfield blue;
132 struct fb_bitfield transp;
135 static struct rk29fb_rgb def_rgb_16 = {
136 red: { offset: 11, length: 5, },
137 green: { offset: 5, length: 6, },
138 blue: { offset: 0, length: 5, },
139 transp: { offset: 0, length: 0, },
143 volatile u32 y_offset;
144 volatile u32 c_offset;
152 u32 xpos; //size in panel
154 u32 xsize; //start point in panel
158 wait_queue_head_t wait;
159 struct win_set mirror;
160 struct win_set displ;
185 void __iomem *reg_vir_base; // virtual basic address of lcdc register
186 u32 reg_phy_base; // physical basic address of lcdc register
187 u32 len; // physical map length of lcdc register
191 struct clk *dclk; //lcdc dclk
192 struct clk *aclk; //lcdc share memory frequency
193 struct clk *aclk_parent; //lcdc aclk divider frequency source
194 struct clk *aclk_ddr_lcdc; //DDR LCDC AXI clock disable.
195 struct clk *aclk_disp_matrix; //DISPLAY matrix AXI clock disable.
196 struct clk *hclk_cpu_display; //CPU DISPLAY AHB bus clock disable.
197 struct clk *pd_display; // display power domain
198 unsigned long dclk_rate;
200 /* lcdc reg base address and backup reg */
205 int fb0_color_deepth;
206 /* variable used in mcu panel */
210 struct timer_list mcutimer;
216 /* external memery */
217 char __iomem *screen_base2;
219 unsigned long smem_start2;
221 char __iomem *cursor_base; /* cursor Virtual address*/
222 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
223 unsigned long cursor_start;
225 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
226 struct rk29fb_screen panel2_info; // 2nd panel
227 struct rk29fb_screen *cur_screen;
228 #if 0 //def CONFIG_CPU_FREQ
229 struct notifier_block freq_transition;
234 typedef enum _TRSP_MODE
246 struct platform_device *g_pdev = NULL;
247 //static int win1fb_set_par(struct fb_info *info);
250 #define CHK_SUSPEND(inf) \
251 if(inf->in_suspend) { \
252 fbprintk(">>>>>> fb is in suspend! return! \n"); \
256 #define CHK_SUSPEND(inf)
259 static DECLARE_WAIT_QUEUE_HEAD(wq);
260 static int wq_condition = 0;
261 static int wq_condition2 = 0;
262 #if ANDROID_USE_THREE_BUFS
263 static int new_frame_seted = 1;
265 static struct wake_lock idlelock; /* only for fb */
266 #ifdef CONFIG_FB_ROTATE_VIDEO
268 static bool has_set_rotate;
269 static u32 last_yuv_phy[2] = {0,0};
272 int mcu_do_refresh(struct rk29fb_inf *inf)
274 if(inf->mcu_stopflush) return 0;
276 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
281 inf->mcu_needflush = 1;
285 // not use frame mark
286 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
288 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
290 inf->mcu_needflush = 1;
294 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
295 inf->mcu_needflush = 0;
297 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
304 void mcutimer_callback(unsigned long arg)
306 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
307 static int waitcnt = 0;
309 mod_timer(&inf->mcutimer, jiffies + HZ/10);
311 switch(inf->mcu_status)
314 inf->mcu_status = MS_MCU;
317 if(inf->mcu_usetimer) mcu_do_refresh(inf);
320 inf->mcu_status = MS_EWAITEND;
328 inf->mcu_status = MS_EEND;
332 inf->mcu_status = MS_MCU;
335 inf->mcu_status = MS_MCU;
340 int mcu_refresh(struct rk29fb_inf *inf)
342 static int mcutimer_inited = 0;
344 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
349 init_timer(&inf->mcutimer);
350 inf->mcutimer.function = mcutimer_callback;
351 inf->mcutimer.expires = jiffies + HZ/5;
352 inf->mcu_status = MS_IDLE;
353 add_timer(&inf->mcutimer);
356 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
361 int mcu_ioctl(unsigned int cmd, unsigned long arg)
363 struct rk29fb_inf *inf = NULL;
364 if(!g_pdev) return -1;
366 inf = dev_get_drvdata(&g_pdev->dev);
371 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
372 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
373 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
377 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
378 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
382 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
383 LcdWrReg(inf, REG_CFG_DONE, 0x01);
393 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
395 struct platform_device *pdev = (struct platform_device*)dev_id;
396 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
397 struct rk29fb_screen *screen;
399 if(!inf) return IRQ_HANDLED;
401 screen = inf->cur_screen;
403 if(0==screen->mcu_usefmk) {
407 if(inf->mcu_fmksync == 1)
410 inf->mcu_fmksync = 1;
411 if(inf->mcu_needflush)
413 inf->mcu_needflush = 0;
415 if(inf->cur_screen->refresh)
416 inf->cur_screen->refresh(REFRESH_PRE);
417 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
419 inf->mcu_fmksync = 0;
424 int init_lcdc(struct fb_info *info)
426 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
429 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
431 inf->clk = clk_get(NULL, "hclk_lcdc");
432 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
433 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
434 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
435 inf->pd_display = clk_get(NULL, "pd_display");
436 if ((IS_ERR(inf->clk)) ||
437 (IS_ERR(inf->aclk_ddr_lcdc)) ||
438 (IS_ERR(inf->aclk_disp_matrix)) ||
439 (IS_ERR(inf->hclk_cpu_display)) ||
440 (IS_ERR(inf->pd_display)))
442 printk(KERN_ERR "failed to get lcdc_hclk source\n");
443 return PTR_ERR(inf->clk);
445 clk_enable(inf->aclk_disp_matrix);
446 clk_enable(inf->hclk_cpu_display);
447 clk_enable(inf->clk);
448 clk_enable(inf->pd_display);
449 //pmu_set_power_domain(PD_DISPLAY, 1);
450 clk_enable(inf->aclk_ddr_lcdc);
452 // set AHB access rule and disable all windows
453 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
454 LcdWrReg(inf, SWAP_CTRL, 0);
455 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
456 LcdWrReg(inf, AXI_MS_ID, 0x54321);
458 // and mcu holdmode; and set win1 top.
459 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
460 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
462 // disable blank out, black out, tristate out, yuv2rgb bypass
463 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
464 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
465 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
466 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
469 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
470 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
472 LcdWrReg(inf, DSP_CTRL1, 0);
474 // initialize all interrupt
475 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
477 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
479 LcdWrReg(inf, INT_STATUS, clr | msk);
481 // let above to take effect
482 LcdWrReg(inf, REG_CFG_DONE, 0x01);
487 void load_screen(struct fb_info *info, bool initscreen)
490 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
491 struct rk29fb_screen *screen = inf->cur_screen;
493 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
494 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
495 u16 x_res = screen->x_res, y_res = screen->y_res;
496 u32 aclk_rate = 150000000;
499 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
503 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
505 // set the rgb or mcu
506 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
508 // set out format and mcu timing
509 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
510 if(mcu_total>31) mcu_total = 31;
511 if(mcu_total<3) mcu_total = 3;
512 mcu_rwstart = (mcu_total+1)/4 - 1;
513 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
514 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
515 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
517 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
518 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
520 LcdMskReg(inf, MCU_TIMING_CTRL,
521 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
522 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
523 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
524 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
525 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
528 // set synchronous pin polarity and data pin swap rule
529 switch (screen->face)
533 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
537 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
541 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
545 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
549 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
550 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
553 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
554 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
559 LcdMskReg(inf, DSP_CTRL0,
560 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
561 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
562 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
563 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
566 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
568 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
569 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));
571 // set horizontal & vertical out timing
572 if(SCREEN_MCU==inf->cur_screen->type)
574 right_margin = x_res/6;
577 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
578 screen->hsync_len , screen->left_margin , x_res , right_margin );
579 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
580 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
581 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
582 v_BIT12HI(screen->hsync_len + screen->left_margin));
584 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
585 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
586 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
587 v_BIT11HI(screen->vsync_len + screen->upper_margin));
589 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
590 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
592 // let above to take effect
593 LcdWrReg(inf, REG_CFG_DONE, 0x01);
595 inf->dclk = clk_get(NULL, "dclk_lcdc");
596 if (IS_ERR(inf->dclk))
598 printk(KERN_ERR "failed to get lcd dclock source\n");
602 inf->aclk = clk_get(NULL, "aclk_lcdc");
603 if (IS_ERR(inf->aclk))
605 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
608 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
609 if (IS_ERR(inf->aclk_parent))
611 printk(KERN_ERR "failed to get lcd clock parent source\n");
616 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
618 if(initscreen == 0) //not init
620 clk_disable(inf->dclk);
621 clk_disable(inf->aclk);
624 clk_disable(inf->aclk_ddr_lcdc);
625 clk_disable(inf->aclk_disp_matrix);
626 clk_disable(inf->hclk_cpu_display);
628 clk_disable(inf->clk);
629 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
631 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
633 ret = clk_set_rate(inf->dclk, screen->pixclock);
636 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
639 if(screen->lcdc_aclk){
640 aclk_rate = screen->lcdc_aclk;
642 ret = clk_set_rate(inf->aclk, aclk_rate);
644 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
647 clk_enable(inf->aclk_ddr_lcdc);
648 clk_enable(inf->aclk_disp_matrix);
649 clk_enable(inf->hclk_cpu_display);
651 clk_enable(inf->aclk);
652 clk_enable(inf->clk);
653 clk_enable(inf->dclk);
661 #if 0 //def CONFIG_CPU_FREQ
663 * CPU clock speed change handler. We need to adjust the LCD timing
664 * parameters when the CPU clock is adjusted by the power management
667 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
670 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
672 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
673 struct rk29fb_screen *screen = inf->cur_screen;
678 case CPUFREQ_PRECHANGE:
680 case CPUFREQ_POSTCHANGE:
682 dclk_rate = screen->pixclock * 1000000;
684 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
686 clk_set_rate(inf->dclk_divider, dclk_rate);
694 static inline unsigned int chan_to_field(unsigned int chan,
695 struct fb_bitfield *bf)
698 chan >>= 16 - bf->length;
699 return chan << bf->offset;
702 static int fb_setcolreg(unsigned regno,
703 unsigned red, unsigned green, unsigned blue,
704 unsigned transp, struct fb_info *info)
707 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
709 switch (info->fix.visual) {
710 case FB_VISUAL_TRUECOLOR:
711 /* true-colour, use pseudo-palette */
713 u32 *pal = info->pseudo_palette;
714 val = chan_to_field(red, &info->var.red);
715 val |= chan_to_field(green, &info->var.green);
716 val |= chan_to_field(blue, &info->var.blue);
721 return -1; /* unknown type */
727 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
730 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
732 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
734 LcdWrReg(inf, REG_CFG_DONE, 0x01);
738 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
740 struct rk29fb_screen *screen = inf->cur_screen;
743 if (x >= 0x800 || y >= 0x800 )
745 //printk("%s: %08x,%08x \n",__func__, x, y);
746 x += (screen->left_margin + screen->hsync_len);
747 y += (screen->upper_margin + screen->vsync_len);
748 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
749 LcdWrReg(inf, REG_CFG_DONE, 0x01);
754 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
756 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
757 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
758 LcdWrReg(inf, REG_CFG_DONE, 0x01);
762 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
763 int rk29_set_cursor_img_transform(char *data)
766 char *dst = (char*)rk29_cursor_buf;
767 unsigned char dmsk = 0;
768 unsigned int op,shift,offset;
770 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
771 * clears it to transparent then combines the cursor
772 * shape plane with the colour plane to set the
774 for (y = 0; y < 32; y++)
776 for (x = 0; x < 32; x++)
783 op = (dmsk & 0x80) ? 2 : 3;
786 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
796 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
800 rk29_set_cursor_img_transform(data);
804 rk29_set_cursor_img_transform(cursor_img);
806 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
807 //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
808 LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN |m_HWC_ENABLE);
810 LcdWrReg(inf, REG_CFG_DONE, 0x01);
815 int rk29_set_cursor_test(struct fb_info *info)
817 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
818 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
819 rk29_set_cursor_pos(inf, 0, 0);
820 rk29_set_cursor_img(inf, 0);
821 rk29_set_cursor_en(inf, 1);
826 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
828 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
830 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
832 /* check not being asked to exceed capabilities */
834 if (cursor->image.width > 32)
837 if (cursor->image.height > 32)
840 if (cursor->image.depth > 1)
844 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
846 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
849 if (cursor->set & FB_CUR_SETPOS)
851 unsigned int x = cursor->image.dx;
852 unsigned int y = cursor->image.dy;
854 if (x >= 0x800 || y >= 0x800 )
856 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
860 if (cursor->set & FB_CUR_SETCMAP)
862 unsigned int bg_col = cursor->image.bg_color;
863 unsigned int fg_col = cursor->image.fg_color;
865 fbprintk("%s: update cmap (%08x,%08x)\n",
866 __func__, bg_col, fg_col);
868 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
869 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));
871 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
872 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));
875 if ((cursor->set & FB_CUR_SETSIZE ||
876 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
877 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
879 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
880 * clears it to transparent then combines the cursor
881 * shape plane with the colour plane to set the
884 const unsigned char *pcol = cursor->image.data;
885 const unsigned char *pmsk = cursor->mask;
887 unsigned long cursor_mem_start;
888 unsigned char dcol = 0;
889 unsigned char dmsk = 0;
892 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
893 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
895 fbprintk("%s: setting shape (%d,%d)\n",
896 __func__, cursor->image.width, cursor->image.height);
898 memset(dst, 0, CURSOR_BUF_SIZE);
900 for (y = 0; y < cursor->image.height; y++)
902 for (x = 0; x < cursor->image.width; x++)
913 op = (dcol & 1) ? 1 : 3;
914 op <<= ((x % 4) * 2);
915 *(u8*)(dst+(x/4)) |= op;
920 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
921 LcdWrReg(inf, HWC_MST, cursor_mem_start);
922 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
923 if(SCREEN_MCU == inf->cur_screen->type) {
924 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
928 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
930 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
937 static int win0_blank(int blank_mode, struct fb_info *info)
939 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
941 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
947 case FB_BLANK_UNBLANK:
948 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
951 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
954 LcdWrReg(inf, REG_CFG_DONE, 0x01);
960 static int win0_set_par(struct fb_info *info)
962 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
963 struct rk29fb_screen *screen = inf->cur_screen;
964 struct fb_var_screeninfo *var = &info->var;
965 struct fb_fix_screeninfo *fix = &info->fix;
966 struct win0_par *par = info->par;
968 u32 xact = var->xres; /* visible resolution */
969 u32 yact = var->yres;
970 u32 xvir = var->xres_virtual; /* virtual resolution */
971 u32 yvir = var->yres_virtual;
972 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
973 //u32 yact_st = var->yoffset; /* resolution */
974 u32 xpos = par->xpos;
975 u32 ypos = par->ypos;
977 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
978 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
980 u32 y_addr = 0; //user alloc buf addr y
983 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
987 if(((var->rotate == 270)||(var->rotate == 90)) && (inf->video_mode))
989 #ifdef CONFIG_FB_ROTATE_VIDEO
990 // if(xact > screen->x_res)
992 xact = screen->x_res; /* visible resolution */
993 yact = screen->y_res;
994 xvir = screen->x_res; /* virtual resolution */
995 yvir = screen->y_res;
997 // xact = var->yres; /* visible resolution */
999 // xvir = var->yres_virtual; /* virtual resolution */
1000 // yvir = var->xres_virtual;
1002 #else //CONFIG_FB_ROTATE_VIDEO
1003 printk("LCDC not support rotate!\n");
1008 // calculate the display phy address
1009 y_addr = fix->smem_start + par->y_offset;
1010 uv_addr = fix->mmio_start + par->c_offset;
1012 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1013 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1015 switch (par->format)
1018 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1019 ScaleCbrY = CalScaleW0(yact, par->ysize);
1023 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1024 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1027 ScaleCbrX= CalScaleW0(xact, par->xsize);
1028 ScaleCbrY = CalScaleW0(yact, par->ysize);
1034 xpos += (screen->left_margin + screen->hsync_len);
1035 ypos += (screen->upper_margin + screen->vsync_len);
1037 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1038 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1040 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1042 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1043 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1044 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1045 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1046 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1047 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1052 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,
1053 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));
1056 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,
1057 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));
1060 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,
1061 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) |
1062 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1065 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,
1066 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) );
1070 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1076 static int win0_pan( struct fb_info *info )
1078 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1079 // struct fb_var_screeninfo *var0 = &info->var;
1080 struct fb_fix_screeninfo *fix0 = &info->fix;
1081 struct win0_par *par = info->par;
1082 u32 y_addr=0, uv_addr=0;
1084 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1088 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1089 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1091 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1092 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1093 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1095 // enable win0 after the win0 addr is seted
1096 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1102 static int win1_blank(int blank_mode, struct fb_info *info)
1104 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1106 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1112 case FB_BLANK_UNBLANK:
1113 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1116 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1119 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1125 static int win1_set_par(struct fb_info *info)
1127 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1128 struct fb_fix_screeninfo *fix = &info->fix;
1129 struct rk29fb_screen *screen = inf->cur_screen;
1130 struct win0_par *par = info->par;
1131 struct fb_var_screeninfo *var = &info->var;
1133 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1135 u16 xres_virtual = 0; //virtual screen size
1137 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1138 //u16 ypos_virtual = var->yoffset;
1140 u16 xpos = par->xpos; //visiable offset in panel
1141 u16 ypos = par->ypos;
1143 u8 trspmode = TRSP_CLOSE;
1146 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1148 #ifdef CONFIG_FB_SCALING_OSD
1149 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1150 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1152 addr = fix->mmio_start + par->y_offset;
1153 xres_virtual = screen->x_res; //virtual screen size
1158 addr = fix->smem_start + par->y_offset;
1159 xres_virtual = var->xres_virtual; //virtual screen size
1161 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1163 xpos += (screen->left_margin + screen->hsync_len);
1164 ypos += (screen->upper_margin + screen->vsync_len);
1166 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1168 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1169 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1171 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1173 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1174 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1176 // enable win1 color key and set the color to black(rgb=0)
1177 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1179 if(1==par->format) //rgb565
1181 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1182 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1186 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1187 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1189 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1192 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1197 static int win1_pan( struct fb_info *info )
1199 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1200 struct fb_fix_screeninfo *fix1 = &info->fix;
1201 struct win0_par *par = info->par;
1204 #ifdef CONFIG_FB_SCALING_OSD
1205 struct rk29fb_screen *screen = inf->cur_screen;
1206 struct fb_var_screeninfo *var = &info->var;
1207 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1208 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1210 addr = fix1->mmio_start + par->y_offset;
1215 addr = fix1->smem_start + par->y_offset;
1218 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1220 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1221 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1227 static int fb0_blank(int blank_mode, struct fb_info *info)
1229 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1231 if(inf->video_mode == 1)
1233 win1_blank(blank_mode, info);
1237 win0_blank(blank_mode, info);
1242 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1244 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1245 struct rk29fb_screen *screen = inf->cur_screen;
1246 u16 xpos = (var->nonstd>>8) & 0xfff;
1247 u16 ypos = (var->nonstd>>20) & 0xfff;
1248 u16 xlcd = screen->x_res;
1249 u16 ylcd = screen->y_res;
1251 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1255 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1256 0==var->xres || 0==var->yres || var->xres<16 ||
1257 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1259 printk(">>>>>> fb0_check_var fail 1!!! \n");
1260 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1261 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1262 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1266 if( (var->xoffset+var->xres)>var->xres_virtual ||
1267 (var->yoffset+var->yres)>var->yres_virtual )
1269 printk(">>>>>> fb0_check_var fail 2!!! \n");
1270 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1271 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1272 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1276 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1277 switch(var->bits_per_pixel)
1280 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1281 var->xres = (var->xres + 0x1) & (~0x1);
1282 var->xoffset = (var->xoffset) & (~0x1);
1285 var->bits_per_pixel = 32;
1293 static int fb0_set_par(struct fb_info *info)
1295 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1296 struct fb_var_screeninfo *var = &info->var;
1297 struct fb_fix_screeninfo *fix = &info->fix;
1298 struct rk29fb_screen *screen = inf->cur_screen;
1299 struct win0_par *par = info->par;
1301 u32 offset=0, smem_len=0;
1302 u16 xres_virtual = var->xres_virtual; //virtual screen size
1303 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1304 u16 ypos_virtual = var->yoffset;
1306 #ifdef CONFIG_FB_SCALING_OSD
1307 struct rk29_ipp_req ipp_req;
1311 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1315 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1316 #if !defined(CONFIG_FB_SCALING_OSD)
1317 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1320 switch(var->bits_per_pixel)
1324 //fix->line_length = 2 * xres_virtual;
1325 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1327 #ifdef CONFIG_FB_SCALING_OSD
1328 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1329 ipp_req.src0.fmt = IPP_RGB_565;
1330 ipp_req.dst0.fmt = IPP_RGB_565;
1332 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1337 fix->line_length = 4 * xres_virtual;
1338 #ifdef CONFIG_FB_SCALING_OSD
1339 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1340 ipp_req.src0.fmt = IPP_XRGB_8888;
1341 ipp_req.dst0.fmt = IPP_XRGB_8888;
1343 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1347 smem_len = fix->line_length * var->yres_virtual;
1348 //map_size = PAGE_ALIGN(smem_len);
1350 if (smem_len > fix->smem_len) // buffer need realloc
1352 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1353 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1354 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1358 par->addr_seted = 1;
1359 #if ANDROID_USE_THREE_BUFS
1360 if(0==new_frame_seted) {
1362 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1364 new_frame_seted = 0;
1367 if(inf->video_mode == 1)
1369 #ifdef CONFIG_FB_SCALING_OSD
1370 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1371 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1375 par->xsize = screen->x_res;
1376 par->ysize = screen->y_res;
1377 par->y_offset = dstoffset;
1379 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1380 ipp_req.src0.w = var->xres;
1381 ipp_req.src0.h = var->yres;
1383 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1384 ipp_req.dst0.w = screen->x_res;
1385 ipp_req.dst0.h = screen->y_res;
1387 ipp_req.src_vir_w = ipp_req.src0.w;
1388 ipp_req.dst_vir_w = ipp_req.dst0.w;
1389 ipp_req.timeout = 100;
1390 ipp_req.flag = IPP_ROT_0;
1391 //ipp_do_blit(&ipp_req);
1392 ipp_blit_sync(&ipp_req);
1396 par->y_offset = offset;
1397 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1398 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1399 par->xsize = var->xres; //visiable size in panel
1400 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1406 par->y_offset = offset;
1409 par->xsize = screen->x_res;
1410 par->ysize = screen->y_res;
1417 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1420 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1421 struct fb_var_screeninfo *var1 = &info->var;
1422 struct rk29fb_screen *screen = inf->cur_screen;
1423 struct win0_par *par = info->par;
1426 u16 ypos_virtual = var->yoffset;
1427 u16 xpos_virtual = var->xoffset;
1428 #ifdef CONFIG_FB_SCALING_OSD
1429 struct fb_fix_screeninfo *fix = &info->fix;
1430 struct rk29_ipp_req ipp_req;
1433 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1437 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1438 #if !defined(CONFIG_FB_SCALING_OSD)
1439 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1442 switch(var1->bits_per_pixel)
1445 var->xoffset = (var->xoffset) & (~0x1);
1446 #ifdef CONFIG_FB_SCALING_OSD
1447 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1448 ipp_req.src0.fmt = IPP_RGB_565;
1449 ipp_req.dst0.fmt = IPP_RGB_565;
1451 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1454 #ifdef CONFIG_FB_SCALING_OSD
1455 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1456 ipp_req.src0.fmt = IPP_XRGB_8888;
1457 ipp_req.dst0.fmt = IPP_XRGB_8888;
1459 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1465 if(inf->video_mode == 1)
1467 #ifdef CONFIG_FB_SCALING_OSD
1468 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1469 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1471 par->y_offset = dstoffset;
1473 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1474 ipp_req.src0.w = var->xres;
1475 ipp_req.src0.h = var->yres;
1477 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1478 ipp_req.dst0.w = screen->x_res;
1479 ipp_req.dst0.h = screen->y_res;
1481 ipp_req.src_vir_w = ipp_req.src0.w;
1482 ipp_req.dst_vir_w = ipp_req.dst0.w;
1483 ipp_req.timeout = 100;
1484 ipp_req.flag = IPP_ROT_0;
1485 //ipp_do_blit(&ipp_req);
1486 ipp_blit_sync(&ipp_req);
1491 par->y_offset = offset;
1496 par->y_offset = offset;
1499 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1500 #if !ANDROID_USE_THREE_BUFS
1501 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1502 if(SCREEN_MCU == inf->cur_screen->type) {
1503 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1507 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1513 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1515 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1516 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1522 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1525 inf->mcu_usetimer = 0;
1528 case FBIOPUT_16OR32:
1530 inf->fb0_color_deepth = arg;
1533 case FBIOPUT_FBPHYADD:
1534 return info->fix.smem_start;
1535 case FBIOGET_OVERLAY_STATE:
1536 return inf->video_mode;
1537 case FBIOGET_SCREEN_STATE:
1538 return inf->cur_screen->type;
1540 case FBIOPUT_SET_CURSOR_EN:
1543 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1545 rk29_set_cursor_en(inf, en);
1548 case FBIOPUT_SET_CURSOR_POS:
1550 struct fbcurpos pos;
1551 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1553 rk29_set_cursor_pos(inf, pos.x , pos.y);
1556 case FBIOPUT_SET_CURSOR_IMG:
1558 char cursor_buf[CURSOR_BUF_SIZE];
1559 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1561 rk29_set_cursor_img(inf, cursor_buf);
1564 case FBIOPUT_SET_CURSOR_CMAP:
1566 struct fb_image img;
1567 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1569 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1572 case FBIOPUT_GET_CURSOR_RESOLUTION:
1575 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1576 if(inf->fb1->var.rotate == 270) {
1577 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1578 panel_size[1] = inf->cur_screen->x_res;
1580 panel_size[0] = inf->cur_screen->x_res;
1581 panel_size[1] = inf->cur_screen->y_res;
1583 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1586 case FBIOPUT_GET_CURSOR_EN:
1588 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1589 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1598 static int fb1_blank(int blank_mode, struct fb_info *info)
1600 win0_blank(blank_mode, info);
1604 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1606 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1607 struct rk29fb_screen *screen = inf->cur_screen;
1609 u32 ScaleYRGBY=0x1000;
1610 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1611 u16 ypos = (var->nonstd>>20) & 0xfff;
1612 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1613 u16 ysize = (var->grayscale>>20) & 0xfff;
1614 u16 xlcd = screen->x_res; //size of panel
1615 u16 ylcd = screen->y_res;
1618 struct hdmi *hdmi = get_hdmi_struct(0);
1621 if((var->rotate == 270)||(var->rotate == 90)) {
1622 #ifdef CONFIG_FB_ROTATE_VIDEO
1623 xlcd = screen->y_res;
1624 ylcd = screen->x_res;
1625 #else //CONFIG_FB_ROTATE_VIDEO
1626 printk("LCDC not support rotate!\n");
1631 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1632 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1633 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1634 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1636 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1640 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1641 0==var->xres || 0==var->yres || var->xres<16 ||
1642 0==xsize || 0==ysize || xsize<16 ||
1643 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1645 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1646 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1647 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1648 var->bits_per_pixel, var->bits_per_pixel);
1652 if( (var->xoffset+var->xres)>var->xres_virtual ||
1653 (var->yoffset+var->yres)>var->yres_virtual ||
1654 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1656 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1657 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1658 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1659 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1663 switch(var->nonstd&0x0f)
1666 switch(var->bits_per_pixel)
1669 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1670 var->xres = (var->xres + 0x1) & (~0x1);
1671 var->xoffset = (var->xoffset) & (~0x1);
1674 var->bits_per_pixel = 32;
1677 var->nonstd &= ~0xc0; //not support I2P in this format
1680 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1681 var->xres = (var->xres + 0x3) & (~0x3);
1682 var->xoffset = (var->xoffset) & (~0x3);
1685 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1686 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1687 var->xres = (var->xres + 0x3) & (~0x3);
1688 var->yres = (var->yres + 0x1) & (~0x1);
1689 var->xoffset = (var->xoffset) & (~0x3);
1690 var->yoffset = (var->yoffset) & (~0x1);
1693 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1694 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1695 var->xres = (var->xres + 0x3) & (~0x3);
1696 var->yres = (var->yres + 0x1) & (~0x1);
1697 var->xoffset = (var->xoffset) & (~0x3);
1698 var->yoffset = (var->yoffset) & (~0x1);
1699 var->nonstd &= ~0xc0; //not support I2P in this format
1703 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1704 var->xres = (var->xres + 0x3) & (~0x3);
1705 var->xoffset = (var->xoffset) & (~0x3);
1706 var->nonstd &= ~0xc0; //not support I2P in this format
1709 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1713 if((var->rotate == 270)||(var->rotate == 90))
1722 ScaleYRGBY = CalScaleW0(yres, ysize);
1724 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1726 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1729 if(inf->video_mode == 1) {
1730 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1732 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1733 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1734 init_completion(&hdmi->complete);
1736 wait_for_completion_interruptible_timeout(&hdmi->complete,
1737 msecs_to_jiffies(10000));
1744 static int fb1_set_par(struct fb_info *info)
1746 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1747 struct rk29fb_screen *screen = inf->cur_screen;
1748 struct fb_var_screeninfo *var = &info->var;
1749 struct fb_fix_screeninfo *fix = &info->fix;
1750 struct win0_par *par = info->par;
1753 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1755 //u32 xact = var->xres; /* visible resolution */
1756 //u32 yact = var->yres;
1757 u32 xvir = var->xres_virtual; /* virtual resolution */
1758 u32 yvir = var->yres_virtual;
1759 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1760 u32 yact_st = var->yoffset; /* resolution */
1762 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1763 u16 ypos = (var->nonstd>>20) & 0xfff;
1764 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1765 u16 ysize = (var->grayscale>>20) & 0xfff;
1767 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1768 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1770 u8 data_format = var->nonstd&0x0f;
1771 // u32 win0_en = var->reserved[2];
1772 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1773 // u32 uv_addr = var->reserved[4];
1775 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1778 if((var->rotate == 270)||(var->rotate == 90))
1780 #ifdef CONFIG_FB_ROTATE_VIDEO
1781 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1782 ypos = (var->nonstd>>8) & 0xfff;
1783 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1784 ysize = (var->grayscale>>8) & 0xfff;
1785 #else //CONFIG_FB_ROTATE_VIDEO
1786 printk("LCDC not support rotate!\n");
1790 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1791 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1792 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1793 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1795 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1796 switch (data_format)
1799 switch(var->bits_per_pixel)
1803 fix->line_length = 2 * xvir;
1804 par->y_offset = (yact_st*xvir + xact_st)*2;
1808 fix->line_length = 4 * xvir;
1809 par->y_offset = (yact_st*xvir + xact_st)*4;
1817 fix->line_length = xvir;
1818 cblen = crlen = (xvir*yvir)/2;
1819 par->y_offset = yact_st*xvir + xact_st;
1820 par->c_offset = yact_st*xvir + xact_st;
1824 fix->line_length = xvir;
1825 cblen = crlen = (xvir*yvir)/4;
1827 par->y_offset = yact_st*xvir + xact_st;
1828 par->c_offset = (yact_st/2)*xvir + xact_st;
1833 fix->line_length = xvir;
1834 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1835 par->c_offset = (yact_st/2)*xvir + xact_st;
1836 cblen = crlen = (xvir*yvir)/4;
1841 fix->line_length = xvir;
1842 par->y_offset = yact_st*xvir + xact_st;
1843 par->c_offset = yact_st*2*xvir + xact_st*2;
1844 cblen = crlen = (xvir*yvir);
1850 smem_len = fix->line_length * yvir + cblen + crlen;
1851 map_size = PAGE_ALIGN(smem_len);
1853 // fix->smem_start = y_addr;
1854 fix->smem_len = smem_len;
1855 // fix->mmio_start = uv_addr;
1857 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1858 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);
1860 par->format = format;
1867 if ( wq_condition2 == 0 ) {
1868 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
1872 #ifdef CONFIG_FB_ROTATE_VIDEO
1873 //need refresh ,zyc add
1874 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
1877 struct rk29_ipp_req ipp_req;
1878 static u32 dstoffset = 0;
1879 static int fb_index = 0;
1881 yuv_phy[0] = last_yuv_phy[0];
1882 yuv_phy[1] = last_yuv_phy[1];
1883 yuv_phy[0] += par->y_offset;
1884 yuv_phy[1] += par->c_offset;
1885 if((var->rotate == 90) ||(var->rotate == 270))
1887 dstoffset = (dstoffset+1)%2;
1888 ipp_req.src0.fmt = 3;
1889 ipp_req.src0.YrgbMst = yuv_phy[0];
1890 ipp_req.src0.CbrMst = yuv_phy[1];
1891 ipp_req.src0.w = var->xres;
1892 ipp_req.src0.h = var->yres;
1894 ipp_req.dst0.fmt = 3;
1895 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
1896 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
1897 // if(var->xres > screen->x_res)
1899 ipp_req.dst0.w = screen->x_res;
1900 ipp_req.dst0.h = screen->y_res;
1902 // ipp_req.dst0.w = var->yres;
1903 // ipp_req.dst0.h = var->xres;
1905 ipp_req.src_vir_w = ipp_req.src0.w;
1906 ipp_req.dst_vir_w = ipp_req.dst0.w;
1907 ipp_req.timeout = 100;
1908 if(var->rotate == 90)
1909 ipp_req.flag = IPP_ROT_90;
1910 else if(var->rotate == 270)
1911 ipp_req.flag = IPP_ROT_270;
1913 //ipp_do_blit(&ipp_req);
1914 ipp_blit_sync(&ipp_req);
1915 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
1916 yuv_phy[0] = ipp_req.dst0.YrgbMst;
1917 yuv_phy[1] = ipp_req.dst0.CbrMst;
1918 fix->smem_start = yuv_phy[0];
1919 fix->mmio_start = yuv_phy[1];
1924 fix->smem_start = yuv_phy[0];
1925 fix->mmio_start = yuv_phy[1];
1928 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
1929 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
1930 // enable win0 after the win0 par is seted
1931 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
1932 par->addr_seted = 1;
1933 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1934 if(par->addr_seted ) {
1935 unsigned long flags;
1937 local_irq_save(flags);
1938 par->mirror.y_offset = yuv_phy[0];
1939 par->mirror.c_offset = yuv_phy[1];
1940 local_irq_restore(flags);
1943 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
1948 has_set_rotate = false;
1953 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1955 struct win0_par *par = info->par;
1956 // enable win0 after the win0 addr is seted
1963 int fb1_open(struct fb_info *info, int user)
1965 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1966 struct win0_par *par = info->par;
1968 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1971 par->addr_seted = 0;
1972 inf->video_mode = 1;
1974 #ifdef CONFIG_FB_ROTATE_VIDEO
1975 //reinitialize the var when open,zyc
1976 last_yuv_phy[0] = 0;
1977 last_yuv_phy[1] = 0;
1981 printk(">>>>>> fb1 has opened! \n");
1985 fb0_set_par(inf->fb0);
1986 fb0_pan_display(&inf->fb0->var, inf->fb0);
1987 win0_blank(FB_BLANK_POWERDOWN, info);
1992 int fb1_release(struct fb_info *info, int user)
1994 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1995 struct win0_par *par = info->par;
1996 struct fb_var_screeninfo *var0 = &info->var;
1998 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2002 inf->video_mode = 0;
2004 par->addr_seted = 0;
2005 //win0_blank(FB_BLANK_POWERDOWN, info);
2006 fb0_set_par(inf->fb0);
2007 fb0_pan_display(&inf->fb0->var, inf->fb0);
2008 win1_blank(FB_BLANK_POWERDOWN, info);
2009 // wait for lcdc stop access memory
2013 info->screen_base = 0;
2014 info->fix.smem_start = 0;
2015 info->fix.smem_len = 0;
2016 // clean the var param
2017 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2023 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2025 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2026 struct win0_par *par = info->par;
2027 struct fb_fix_screeninfo *fix0 = &info->fix;
2028 struct fb_var_screeninfo *var = &info->var;
2029 void __user *argp = (void __user *)arg;
2031 #ifdef CONFIG_FB_ROTATE_VIDEO
2032 struct rk29fb_screen *screen = inf->cur_screen;
2033 struct rk29_ipp_req ipp_req;
2034 static u32 dstoffset = 0;
2038 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2039 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2045 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2048 if((var->rotate == 270)||(var->rotate == 90)) {
2049 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2050 panel_size[1] = inf->panel1_info.x_res;
2052 panel_size[0] = inf->panel1_info.x_res;
2053 panel_size[1] = inf->panel1_info.y_res;
2056 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2060 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2063 if (copy_from_user(yuv_phy, argp, 8))
2065 #ifdef CONFIG_FB_ROTATE_VIDEO
2067 if(has_set_rotate == true)
2069 last_yuv_phy[0] = yuv_phy[0];
2070 last_yuv_phy[1] = yuv_phy[1];
2073 fix0->smem_start = yuv_phy[0];
2074 fix0->mmio_start = yuv_phy[1];
2075 yuv_phy[0] += par->y_offset;
2076 yuv_phy[1] += par->c_offset;
2078 if((var->rotate == 270)||(var->rotate == 90))
2080 #ifdef CONFIG_FB_ROTATE_VIDEO
2081 dstoffset = (dstoffset+1)%2;
2082 ipp_req.src0.fmt = 3;
2083 ipp_req.src0.YrgbMst = yuv_phy[0];
2084 ipp_req.src0.CbrMst = yuv_phy[1];
2085 ipp_req.src0.w = var->xres;
2086 ipp_req.src0.h = var->yres;
2088 ipp_req.dst0.fmt = 3;
2089 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2090 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2091 // if(var->xres > screen->x_res)
2093 ipp_req.dst0.w = screen->x_res;
2094 ipp_req.dst0.h = screen->y_res;
2096 // ipp_req.dst0.w = var->yres;
2097 // ipp_req.dst0.h = var->xres;
2099 ipp_req.src_vir_w = ipp_req.src0.w;
2100 ipp_req.dst_vir_w = ipp_req.dst0.w;
2101 ipp_req.timeout = 100;
2102 if(var->rotate == 90)
2103 ipp_req.flag = IPP_ROT_90;
2104 else if(var->rotate == 270)
2105 ipp_req.flag = IPP_ROT_270;
2106 //ipp_do_blit(&ipp_req);
2107 ipp_blit_sync(&ipp_req);
2108 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2109 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2110 yuv_phy[1] = ipp_req.dst0.CbrMst;
2111 fix0->smem_start = yuv_phy[0];
2112 fix0->mmio_start = yuv_phy[1];
2113 #else //CONFIG_FB_ROTATE_VIDEO
2114 printk("LCDC not support rotate!\n");
2118 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2119 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2120 // enable win0 after the win0 par is seted
2121 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2122 par->addr_seted = 1;
2123 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2124 if(par->par_seted) {
2125 unsigned long flags;
2127 local_irq_save(flags);
2128 par->mirror.y_offset = yuv_phy[0];
2129 par->mirror.c_offset = yuv_phy[1];
2130 local_irq_restore(flags);
2133 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2138 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2139 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2140 #ifdef CONFIG_FB_ROTATE_VIDEO
2142 has_set_rotate = true;
2143 if(arg == 0 || arg==180)
2145 else if (arg == 90 || arg==270)
2147 #else //CONFIG_FB_ROTATE_VIDEO
2148 printk("LCDC not support rotate!\n");
2151 case FB1_IOCTL_SET_WIN0_TOP:
2152 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2153 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2154 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2162 static struct fb_ops fb1_ops = {
2163 .owner = THIS_MODULE,
2164 .fb_open = fb1_open,
2165 .fb_release = fb1_release,
2166 .fb_check_var = fb1_check_var,
2167 .fb_set_par = fb1_set_par,
2168 .fb_blank = fb1_blank,
2169 .fb_pan_display = fb1_pan_display,
2170 .fb_ioctl = fb1_ioctl,
2171 .fb_setcolreg = fb_setcolreg,
2172 .fb_fillrect = cfb_fillrect,
2173 .fb_copyarea = cfb_copyarea,
2174 .fb_imageblit = cfb_imageblit,
2177 static struct fb_ops fb0_ops = {
2178 .owner = THIS_MODULE,
2179 .fb_check_var = fb0_check_var,
2180 .fb_set_par = fb0_set_par,
2181 .fb_blank = fb0_blank,
2182 .fb_pan_display = fb0_pan_display,
2183 .fb_ioctl = fb0_ioctl,
2184 .fb_setcolreg = fb_setcolreg,
2185 .fb_fillrect = cfb_fillrect,
2186 .fb_copyarea = cfb_copyarea,
2187 .fb_imageblit = cfb_imageblit,
2188 //.fb_cursor = rk29_set_cursor,
2192 enable: 1, switch to tv or hdmi; 0, switch to lcd
2194 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2196 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2197 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2198 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2200 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2202 if(enable)inf->cur_screen = &inf->panel2_info;
2203 else inf->cur_screen = &inf->panel1_info;
2205 /* Black out, because some display device need clock to standby */
2206 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2207 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2208 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2209 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2210 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2211 wake_lock(&idlelock);
2213 wake_unlock(&idlelock);
2215 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2216 // operate the display_on pin to power down the lcd
2218 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2219 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2221 load_screen(inf->fb0, 0);
2224 fb1_set_par(inf->fb1);
2225 fb0_set_par(inf->fb0);
2226 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2227 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2231 static ssize_t dsp_win0_info_read(struct device *device,
2232 struct device_attribute *attr, char *buf)
2235 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2236 struct rk29fb_screen *screen = inf->cur_screen;
2238 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2240 fbprintk("%s\n",__FUNCTION__);
2241 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2242 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2244 xpos -= (screen->left_margin + screen->hsync_len);
2245 ypos -= (screen->upper_margin + screen->vsync_len);
2247 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2248 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2249 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2250 rk29_set_cursor_test(inf->fb0);
2252 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2255 static ssize_t dsp_win0_info_write(struct device *device,
2256 struct device_attribute *attr, const char *buf, size_t count)
2258 printk("%s\n",__FUNCTION__);
2259 printk("%s %x \n",__FUNCTION__,*buf);
2263 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2265 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2267 struct platform_device *pdev = (struct platform_device*)dev_id;
2268 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2269 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2273 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2275 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2277 if(SCREEN_MCU == inf->cur_screen->type)
2279 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2285 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2287 inf->mcu_fmksync = 1;
2288 if(inf->cur_screen->refresh)
2289 inf->cur_screen->refresh(REFRESH_END);
2290 inf->mcu_fmksync = 0;
2299 if(inf->mcu_needflush) {
2300 if(inf->cur_screen->refresh)
2301 inf->cur_screen->refresh(REFRESH_PRE);
2302 inf->mcu_needflush = 0;
2303 inf->mcu_isrcnt = 0;
2304 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2306 if(inf->cur_screen->refresh)
2307 inf->cur_screen->refresh(REFRESH_END);
2311 #if ANDROID_USE_THREE_BUFS
2312 new_frame_seted = 1;
2315 if(waitqueue_active(&par->wait)) {
2316 if (par->mirror.c_offset == 0)
2317 printk("error: no new buffer to display\n");
2319 par->done.y_offset = par->displ.y_offset;
2320 par->done.c_offset = par->displ.c_offset;
2321 par->displ.y_offset = par->mirror.y_offset;
2322 par->displ.c_offset = par->mirror.c_offset;
2323 par->mirror.y_offset = 0;
2324 par->mirror.c_offset = 0;
2326 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2327 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2328 wake_up_interruptible(&par->wait);
2333 wake_up_interruptible(&wq);
2338 #ifdef CONFIG_HAS_EARLYSUSPEND
2340 struct suspend_info {
2341 struct early_suspend early_suspend;
2342 struct rk29fb_inf *inf;
2345 static void rk29fb_early_suspend(struct early_suspend *h)
2347 struct suspend_info *info = container_of(h, struct suspend_info,
2350 struct rk29fb_inf *inf = info->inf;
2351 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2353 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2356 printk("inf==0, rk29fb_suspend fail! \n");
2360 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2361 mach_info->io_disable(); //close lcd out
2363 if(inf->cur_screen->standby)
2365 fbprintk(">>>>>> power down the screen! \n");
2366 inf->cur_screen->standby(1);
2369 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2370 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2372 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2373 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2374 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2376 if(!inf->in_suspend)
2378 fbprintk(">>>>>> diable the lcdc clk! \n");
2379 wake_lock(&idlelock);
2381 wake_unlock(&idlelock);
2382 clk_disable(inf->aclk_ddr_lcdc);
2383 clk_disable(inf->aclk_disp_matrix);
2384 clk_disable(inf->hclk_cpu_display);
2385 clk_disable(inf->clk);
2387 clk_disable(inf->dclk);
2390 clk_disable(inf->aclk);
2392 clk_disable(inf->pd_display);
2394 inf->in_suspend = 1;
2398 static void rk29fb_early_resume(struct early_suspend *h)
2400 struct suspend_info *info = container_of(h, struct suspend_info,
2403 struct rk29fb_inf *inf = info->inf;
2404 struct rk29fb_screen *screen = inf->cur_screen;
2405 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2407 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2409 printk("inf==0, rk29fb_resume fail! \n");
2415 inf->in_suspend = 0;
2416 fbprintk(">>>>>> enable the lcdc clk! \n");
2417 clk_enable(inf->pd_display);
2418 clk_enable(inf->aclk_disp_matrix);
2419 clk_enable(inf->hclk_cpu_display);
2420 clk_enable(inf->clk);
2421 clk_enable(inf->aclk_ddr_lcdc);
2424 clk_enable(inf->dclk);
2427 clk_enable(inf->aclk);
2431 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2432 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2433 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2435 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2436 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2438 if(inf->cur_screen->standby)
2440 fbprintk(">>>>>> power on the screen! \n");
2441 inf->cur_screen->standby(0);
2444 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2447 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2448 mach_info->io_enable(); //close lcd out
2452 static struct suspend_info suspend_info = {
2453 .early_suspend.suspend = rk29fb_early_suspend,
2454 .early_suspend.resume = rk29fb_early_resume,
2455 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2458 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2459 static int __init rk29fb_probe (struct platform_device *pdev)
2461 struct rk29fb_inf *inf = NULL;
2462 struct resource *res = NULL;
2463 struct resource *mem = NULL;
2464 struct rk29fb_info *mach_info = NULL;
2465 struct rk29fb_screen *screen = NULL;
2466 struct win0_par* par = NULL;
2470 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2472 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2473 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2474 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2477 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2479 goto release_drvdata;
2481 memset(inf, 0, sizeof(struct rk29fb_inf));
2482 platform_set_drvdata(pdev, inf);
2484 mach_info = pdev->dev.platform_data;
2485 /* Fill screen info and set current screen */
2486 fbprintk(">> Fill screen info and set current screen \n");
2487 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2488 hdmi_get_default_resolution(&inf->panel1_info);
2490 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2492 inf->cur_screen = &inf->panel1_info;
2493 screen = inf->cur_screen;
2494 if(SCREEN_NULL==screen->type)
2496 dev_err(&pdev->dev, ">> Please select a display device! \n");
2498 goto release_drvdata;
2501 /* get virtual basic address of lcdc register */
2502 fbprintk(">> get virtual basic address of lcdc register \n");
2503 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2506 dev_err(&pdev->dev, "failed to get memory registers\n");
2508 goto release_drvdata;
2510 inf->reg_phy_base = res->start;
2511 inf->len = (res->end - res->start) + 1;
2512 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2515 dev_err(&pdev->dev, "failed to get memory region\n");
2517 goto release_drvdata;
2519 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2520 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2521 if (inf->reg_vir_base == NULL)
2523 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2525 goto release_drvdata;
2527 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2529 /* Prepare win1 info */
2530 fbprintk(">> Prepare win1 info \n");
2531 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2534 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2537 goto release_win1fb;
2540 par = (struct win0_par*)inf->fb0->par;
2541 strcpy(inf->fb0->fix.id, "fb0");
2542 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2543 inf->fb0->fix.type_aux = 0;
2544 inf->fb0->fix.xpanstep = 1;
2545 inf->fb0->fix.ypanstep = 1;
2546 inf->fb0->fix.ywrapstep = 0;
2547 inf->fb0->fix.accel = FB_ACCEL_NONE;
2548 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2549 inf->fb0->fix.smem_len = 0;
2550 inf->fb0->fix.line_length = 0;
2551 inf->fb0->fix.smem_start = 0;
2553 inf->fb0->var.xres = screen->x_res;
2554 inf->fb0->var.yres = screen->y_res;
2555 inf->fb0->var.bits_per_pixel = 16;
2556 inf->fb0_color_deepth = 0;
2557 inf->fb0->var.xres_virtual = screen->x_res;
2558 inf->fb0->var.yres_virtual = screen->y_res;
2559 inf->fb0->var.width = screen->width;
2560 inf->fb0->var.height = screen->height;
2561 inf->fb0->var.pixclock = screen->pixclock;
2562 inf->fb0->var.left_margin = screen->left_margin;
2563 inf->fb0->var.right_margin = screen->right_margin;
2564 inf->fb0->var.upper_margin = screen->upper_margin;
2565 inf->fb0->var.lower_margin = screen->lower_margin;
2566 inf->fb0->var.vsync_len = screen->vsync_len;
2567 inf->fb0->var.hsync_len = screen->hsync_len;
2568 inf->fb0->var.red = def_rgb_16.red;
2569 inf->fb0->var.green = def_rgb_16.green;
2570 inf->fb0->var.blue = def_rgb_16.blue;
2571 inf->fb0->var.transp = def_rgb_16.transp;
2573 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2574 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2575 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2576 inf->fb0->var.accel_flags = 0;
2577 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2579 inf->fb0->fbops = &fb0_ops;
2580 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2581 inf->fb0->pseudo_palette = par->pseudo_pal;
2582 inf->fb0->screen_base = 0;
2584 memset(par, 0, sizeof(struct win0_par));
2586 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2590 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2592 /* alloc win1 buf */
2593 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2596 dev_err(&pdev->dev, "failed to get win1 memory \n");
2598 goto release_win1fb;
2600 inf->fb0->fix.smem_start = res->start;
2601 inf->fb0->fix.smem_len = res->end - res->start + 1;
2602 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2603 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2605 #ifdef CONFIG_FB_WORK_IPP
2606 /* alloc win1 ipp buf */
2607 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2610 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2612 goto release_win1fb;
2614 inf->fb0->fix.mmio_start = res->start;
2615 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2618 /* Prepare win0 info */
2619 fbprintk(">> Prepare win0 info \n");
2620 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2623 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2626 goto release_win0fb;
2629 par = (struct win0_par*)inf->fb1->par;
2631 strcpy(inf->fb1->fix.id, "fb1");
2632 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2633 inf->fb1->fix.type_aux = 0;
2634 inf->fb1->fix.xpanstep = 1;
2635 inf->fb1->fix.ypanstep = 1;
2636 inf->fb1->fix.ywrapstep = 0;
2637 inf->fb1->fix.accel = FB_ACCEL_NONE;
2638 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2639 inf->fb1->fix.smem_len = 0;
2640 inf->fb1->fix.line_length = 0;
2641 inf->fb1->fix.smem_start = 0;
2643 inf->fb1->var.xres = screen->x_res;
2644 inf->fb1->var.yres = screen->y_res;
2645 inf->fb1->var.bits_per_pixel = 16;
2646 inf->fb1->var.xres_virtual = screen->x_res;
2647 inf->fb1->var.yres_virtual = screen->y_res;
2648 inf->fb1->var.width = screen->width;
2649 inf->fb1->var.height = screen->height;
2650 inf->fb1->var.pixclock = screen->pixclock;
2651 inf->fb1->var.left_margin = screen->left_margin;
2652 inf->fb1->var.right_margin = screen->right_margin;
2653 inf->fb1->var.upper_margin = screen->upper_margin;
2654 inf->fb1->var.lower_margin = screen->lower_margin;
2655 inf->fb1->var.vsync_len = screen->vsync_len;
2656 inf->fb1->var.hsync_len = screen->hsync_len;
2657 inf->fb1->var.red = def_rgb_16.red;
2658 inf->fb1->var.green = def_rgb_16.green;
2659 inf->fb1->var.blue = def_rgb_16.blue;
2660 inf->fb1->var.transp = def_rgb_16.transp;
2662 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2663 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2664 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2665 inf->fb1->var.accel_flags = 0;
2666 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2668 inf->fb1->fbops = &fb1_ops;
2669 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2670 inf->fb1->pseudo_palette = par->pseudo_pal;
2671 inf->fb1->screen_base = 0;
2673 memset(par, 0, sizeof(struct win0_par));
2675 init_waitqueue_head(&par->wait);
2677 /* Init all lcdc and lcd before register_framebuffer. */
2678 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2679 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2680 init_lcdc(inf->fb0);
2682 #if 0 //def CONFIG_CPU_FREQ
2683 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2684 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2686 fbprintk("got clock\n");
2690 struct rk29_fb_setting_info fb_setting;
2691 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2693 fb_setting.data_num = 24;
2695 else if(OUT_P666 == inf->cur_screen->face )
2697 fb_setting.data_num = 18;
2701 fb_setting.data_num = 16;
2703 fb_setting.den_en = 1;
2704 fb_setting.vsync_en = 1;
2705 fb_setting.disp_on_en = 1;
2706 fb_setting.standby_en = 1;
2707 if( inf->cur_screen->mcu_usefmk )
2708 fb_setting.mcu_fmk_en =1;
2709 mach_info->io_init(&fb_setting);
2712 //set_lcd_pin(pdev, 1);
2715 inf->mcu_usetimer = 1;
2716 inf->mcu_fmksync = 0;
2717 load_screen(inf->fb0, 1);
2719 /* Register framebuffer(fb0 & fb1) */
2720 fbprintk(">> Register framebuffer(fb0) \n");
2721 ret = register_framebuffer(inf->fb0);
2724 printk(">> fb0 register_framebuffer fail!\n");
2726 goto release_win0fb;
2728 fbprintk(">> Register framebuffer(fb1) \n");
2730 ret = register_framebuffer(inf->fb1);
2733 printk(">> fb1 register_framebuffer fail!\n");
2735 goto unregister_win1fb;
2738 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2741 printk(">> fb1 dsp win0 info device_create_file err\n");
2744 #ifdef CONFIG_HAS_EARLYSUSPEND
2745 suspend_info.inf = inf;
2746 register_early_suspend(&suspend_info.early_suspend);
2749 /* get and request irq */
2750 fbprintk(">> get and request irq \n");
2751 irq = platform_get_irq(pdev, 0);
2753 dev_err(&pdev->dev, "no irq for device\n");
2755 goto unregister_win1fb;
2757 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2759 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2764 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2766 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2769 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2775 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2776 fb0_set_par(inf->fb0);
2777 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2778 /* Start display and show logo on boot */
2779 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2780 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2781 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2785 printk(" %s ok\n", __FUNCTION__);
2790 free_irq(irq, pdev);
2792 unregister_framebuffer(inf->fb0);
2795 framebuffer_release(inf->fb1);
2799 fb_dealloc_cmap(&inf->fb0->cmap);
2802 framebuffer_release(inf->fb0);
2805 if(inf && inf->reg_vir_base)
2806 iounmap(inf->reg_vir_base);
2808 release_mem_region(inf->reg_phy_base, inf->len);
2811 platform_set_drvdata(pdev, NULL);
2815 static int rk29fb_remove(struct platform_device *pdev)
2817 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2818 struct fb_info *info = NULL;
2820 struct rk29fb_info *mach_info = NULL;
2823 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2826 printk("inf==0, rk29_fb_remove fail! \n");
2829 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2831 irq = platform_get_irq(pdev, 0);
2834 free_irq(irq, pdev);
2837 mach_info = pdev->dev.platform_data;
2838 if(mach_info->mcu_fmk_pin)
2840 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2843 if(mach_info->io_disable)
2844 mach_info->io_disable(); //close lcd out
2848 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2850 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2853 //rk29fb_suspend(pdev, msg);
2854 // unmap memory and release framebuffer
2857 if (info->screen_base) {
2858 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2859 info->screen_base = 0;
2860 info->fix.smem_start = 0;
2861 info->fix.smem_len = 0;
2863 unregister_framebuffer(inf->fb1);
2864 framebuffer_release(inf->fb1);
2869 if (info->screen_base) {
2870 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2871 info->screen_base = 0;
2872 info->fix.smem_start = 0;
2873 info->fix.smem_len = 0;
2875 unregister_framebuffer(inf->fb0);
2876 framebuffer_release(inf->fb0);
2880 #if 0 //def CONFIG_CPU_FREQ
2881 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2888 clk_disable(inf->clk);
2894 clk_disable(inf->dclk);
2900 platform_set_drvdata(pdev, NULL);
2905 static void rk29fb_shutdown(struct platform_device *pdev)
2907 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2908 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
2910 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
2912 if(mach_info->io_disable)
2913 mach_info->io_disable(); //close lcd out
2915 if(!inf->in_suspend)
2917 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2918 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2919 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2921 clk_disable(inf->aclk_ddr_lcdc);
2922 clk_disable(inf->aclk_disp_matrix);
2923 clk_disable(inf->hclk_cpu_display);
2924 clk_disable(inf->clk);
2926 clk_disable(inf->dclk);
2929 clk_disable(inf->aclk);
2931 clk_disable(inf->pd_display);
2932 //pmu_set_power_domain(PD_DISPLAY, 0);
2933 inf->in_suspend = 1;
2938 static struct platform_driver rk29fb_driver = {
2939 .probe = rk29fb_probe,
2940 .remove = rk29fb_remove,
2943 .owner = THIS_MODULE,
2945 .shutdown = rk29fb_shutdown,
2948 static int __init rk29fb_init(void)
2950 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
2951 return platform_driver_register(&rk29fb_driver);
2954 static void __exit rk29fb_exit(void)
2956 platform_driver_unregister(&rk29fb_driver);
2959 fs_initcall(rk29fb_init);
2960 module_exit(rk29fb_exit);
2963 MODULE_AUTHOR(" zyw@rock-chips.com");
2964 MODULE_DESCRIPTION("Driver for rk29 fb device");
2965 MODULE_LICENSE("GPL");