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>
48 #include <linux/completion.h>
50 #include <linux/hdmi.h>
53 #include <mach/iomux.h>
54 #include <mach/gpio.h>
55 #include <mach/board.h>
56 #include <mach/rk29_iomap.h>
58 #include <mach/rk29-ipp.h>
60 #include "./display/screen/screen.h"
62 #define ANDROID_USE_THREE_BUFS 0 //android use three buffers to accelerate UI display in rgb plane
63 #define CURSOR_BUF_SIZE 256 //RK2818 cursor need 256B buf
64 int rk29_cursor_buf[CURSOR_BUF_SIZE];
101 #define fbprintk(msg...) printk(msg);
103 #define fbprintk(msg...)
108 #define fbprintk2(msg...) printk(msg);
110 #define fbprintk2(msg...)
113 #define LcdReadBit(inf, addr, msk) ((inf->regbak.addr=inf->preg->addr)&(msk))
114 #define LcdWrReg(inf, addr, val) inf->preg->addr=inf->regbak.addr=(val)
115 #define LcdRdReg(inf, addr) (inf->preg->addr)
116 #define LcdSetBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) |= (msk))
117 #define LcdClrBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) &= ~(msk))
118 #define LcdSetRegisterBit(inf, addr, msk) inf->preg->addr=((inf->preg->addr) |= (msk))
119 #define LcdMskReg(inf, addr, msk, val) (inf->regbak.addr)&=~(msk); inf->preg->addr=(inf->regbak.addr|=(val))
122 #define IsMcuLandscape() ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
123 #define IsMcuUseFmk() ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
125 #define CalScaleW0(x, y) (((u32)x*0x1000)/y)
128 struct fb_bitfield red;
129 struct fb_bitfield green;
130 struct fb_bitfield blue;
131 struct fb_bitfield transp;
134 static struct rk29fb_rgb def_rgb_16 = {
135 red: { offset: 11, length: 5, },
136 green: { offset: 5, length: 6, },
137 blue: { offset: 0, length: 5, },
138 transp: { offset: 0, length: 0, },
142 volatile u32 y_offset;
143 volatile u32 c_offset;
151 u32 xpos; //size in panel
153 u32 xsize; //start point in panel
157 wait_queue_head_t wait;
158 struct win_set mirror;
159 struct win_set displ;
184 void __iomem *reg_vir_base; // virtual basic address of lcdc register
185 u32 reg_phy_base; // physical basic address of lcdc register
186 u32 len; // physical map length of lcdc register
190 struct clk *dclk; //lcdc dclk
191 struct clk *aclk; //lcdc share memory frequency
192 struct clk *aclk_parent; //lcdc aclk divider frequency source
193 struct clk *aclk_ddr_lcdc; //DDR LCDC AXI clock disable.
194 struct clk *aclk_disp_matrix; //DISPLAY matrix AXI clock disable.
195 struct clk *hclk_cpu_display; //CPU DISPLAY AHB bus clock disable.
196 struct clk *pd_display; // display power domain
197 unsigned long dclk_rate;
199 /* lcdc reg base address and backup reg */
204 int fb0_color_deepth;
205 /* variable used in mcu panel */
209 struct timer_list mcutimer;
215 /* external memery */
216 char __iomem *screen_base2;
218 unsigned long smem_start2;
220 char __iomem *cursor_base; /* cursor Virtual address*/
221 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
222 unsigned long cursor_start;
224 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
225 struct rk29fb_screen panel2_info; // 2nd panel
226 struct rk29fb_screen *cur_screen;
227 #if 0 //def CONFIG_CPU_FREQ
228 struct notifier_block freq_transition;
233 typedef enum _TRSP_MODE
245 struct platform_device *g_pdev = NULL;
246 //static int win1fb_set_par(struct fb_info *info);
249 #define CHK_SUSPEND(inf) \
250 if(inf->in_suspend) { \
251 fbprintk(">>>>>> fb is in suspend! return! \n"); \
255 #define CHK_SUSPEND(inf)
258 static DECLARE_WAIT_QUEUE_HEAD(wq);
259 static int wq_condition = 0;
260 static int wq_condition2 = 0;
261 #if ANDROID_USE_THREE_BUFS
262 static int new_frame_seted = 1;
264 static struct wake_lock idlelock; /* only for fb */
265 #ifdef CONFIG_FB_ROTATE_VIDEO
267 static bool has_set_rotate;
268 static u32 last_yuv_phy[2] = {0,0};
271 int mcu_do_refresh(struct rk29fb_inf *inf)
273 if(inf->mcu_stopflush) return 0;
275 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
280 inf->mcu_needflush = 1;
284 // not use frame mark
285 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
287 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
289 inf->mcu_needflush = 1;
293 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
294 inf->mcu_needflush = 0;
296 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
303 void mcutimer_callback(unsigned long arg)
305 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
306 static int waitcnt = 0;
308 mod_timer(&inf->mcutimer, jiffies + HZ/10);
310 switch(inf->mcu_status)
313 inf->mcu_status = MS_MCU;
316 if(inf->mcu_usetimer) mcu_do_refresh(inf);
319 inf->mcu_status = MS_EWAITEND;
327 inf->mcu_status = MS_EEND;
331 inf->mcu_status = MS_MCU;
334 inf->mcu_status = MS_MCU;
339 int mcu_refresh(struct rk29fb_inf *inf)
341 static int mcutimer_inited = 0;
343 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
348 init_timer(&inf->mcutimer);
349 inf->mcutimer.function = mcutimer_callback;
350 inf->mcutimer.expires = jiffies + HZ/5;
351 inf->mcu_status = MS_IDLE;
352 add_timer(&inf->mcutimer);
355 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
360 int mcu_ioctl(unsigned int cmd, unsigned long arg)
362 struct rk29fb_inf *inf = NULL;
363 if(!g_pdev) return -1;
365 inf = dev_get_drvdata(&g_pdev->dev);
370 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
371 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
372 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
376 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
377 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
381 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
382 LcdWrReg(inf, REG_CFG_DONE, 0x01);
392 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
394 struct platform_device *pdev = (struct platform_device*)dev_id;
395 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
396 struct rk29fb_screen *screen;
398 if(!inf) return IRQ_HANDLED;
400 screen = inf->cur_screen;
402 if(0==screen->mcu_usefmk) {
406 if(inf->mcu_fmksync == 1)
409 inf->mcu_fmksync = 1;
410 if(inf->mcu_needflush)
412 inf->mcu_needflush = 0;
414 if(inf->cur_screen->refresh)
415 inf->cur_screen->refresh(REFRESH_PRE);
416 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
418 inf->mcu_fmksync = 0;
423 int init_lcdc(struct fb_info *info)
425 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
428 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
430 inf->clk = clk_get(NULL, "hclk_lcdc");
431 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
432 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
433 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
434 inf->pd_display = clk_get(NULL, "pd_display");
435 if ((IS_ERR(inf->clk)) ||
436 (IS_ERR(inf->aclk_ddr_lcdc)) ||
437 (IS_ERR(inf->aclk_disp_matrix)) ||
438 (IS_ERR(inf->hclk_cpu_display)) ||
439 (IS_ERR(inf->pd_display)))
441 printk(KERN_ERR "failed to get lcdc_hclk source\n");
442 return PTR_ERR(inf->clk);
444 clk_enable(inf->aclk_disp_matrix);
445 clk_enable(inf->hclk_cpu_display);
446 clk_enable(inf->clk);
447 clk_enable(inf->pd_display);
448 //pmu_set_power_domain(PD_DISPLAY, 1);
449 clk_enable(inf->aclk_ddr_lcdc);
451 // set AHB access rule and disable all windows
452 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
453 LcdWrReg(inf, SWAP_CTRL, 0);
454 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
455 LcdWrReg(inf, AXI_MS_ID, 0x54321);
457 // and mcu holdmode; and set win1 top.
458 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
459 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
461 // disable blank out, black out, tristate out, yuv2rgb bypass
462 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
463 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
464 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
465 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
468 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
469 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
471 LcdWrReg(inf, DSP_CTRL1, 0);
473 // initialize all interrupt
474 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
476 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
478 LcdWrReg(inf, INT_STATUS, clr | msk);
480 // let above to take effect
481 LcdWrReg(inf, REG_CFG_DONE, 0x01);
486 void load_screen(struct fb_info *info, bool initscreen)
489 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
490 struct rk29fb_screen *screen = inf->cur_screen;
492 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
493 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
494 u16 x_res = screen->x_res, y_res = screen->y_res;
495 u32 aclk_rate = 150000000;
498 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
502 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
504 // set the rgb or mcu
505 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
507 // set out format and mcu timing
508 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
509 if(mcu_total>31) mcu_total = 31;
510 if(mcu_total<3) mcu_total = 3;
511 mcu_rwstart = (mcu_total+1)/4 - 1;
512 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
513 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
514 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
516 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
517 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
519 LcdMskReg(inf, MCU_TIMING_CTRL,
520 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
521 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
522 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
523 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
524 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
527 // set synchronous pin polarity and data pin swap rule
528 switch (screen->face)
532 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
536 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
540 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
544 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
548 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
549 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
552 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
553 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
558 LcdMskReg(inf, DSP_CTRL0,
559 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
560 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
561 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
562 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
565 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
567 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
568 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));
570 // set horizontal & vertical out timing
571 if(SCREEN_MCU==inf->cur_screen->type)
573 right_margin = x_res/6;
576 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
577 screen->hsync_len , screen->left_margin , x_res , right_margin );
578 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
579 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
580 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
581 v_BIT12HI(screen->hsync_len + screen->left_margin));
583 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
584 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
585 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
586 v_BIT11HI(screen->vsync_len + screen->upper_margin));
588 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
589 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
591 // let above to take effect
592 LcdWrReg(inf, REG_CFG_DONE, 0x01);
594 inf->dclk = clk_get(NULL, "dclk_lcdc");
595 if (IS_ERR(inf->dclk))
597 printk(KERN_ERR "failed to get lcd dclock source\n");
601 inf->aclk = clk_get(NULL, "aclk_lcdc");
602 if (IS_ERR(inf->aclk))
604 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
607 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
608 if (IS_ERR(inf->aclk_parent))
610 printk(KERN_ERR "failed to get lcd clock parent source\n");
615 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
617 if(initscreen == 0) //not init
619 clk_disable(inf->dclk);
620 clk_disable(inf->aclk);
623 clk_disable(inf->aclk_ddr_lcdc);
624 clk_disable(inf->aclk_disp_matrix);
625 clk_disable(inf->hclk_cpu_display);
627 clk_disable(inf->clk);
628 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
630 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
632 ret = clk_set_rate(inf->dclk, screen->pixclock);
635 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
638 if(screen->lcdc_aclk){
639 aclk_rate = screen->lcdc_aclk;
641 ret = clk_set_rate(inf->aclk, aclk_rate);
643 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
646 clk_enable(inf->aclk_ddr_lcdc);
647 clk_enable(inf->aclk_disp_matrix);
648 clk_enable(inf->hclk_cpu_display);
650 clk_enable(inf->aclk);
651 clk_enable(inf->clk);
652 clk_enable(inf->dclk);
660 #if 0 //def CONFIG_CPU_FREQ
662 * CPU clock speed change handler. We need to adjust the LCD timing
663 * parameters when the CPU clock is adjusted by the power management
666 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
669 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
671 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
672 struct rk29fb_screen *screen = inf->cur_screen;
677 case CPUFREQ_PRECHANGE:
679 case CPUFREQ_POSTCHANGE:
681 dclk_rate = screen->pixclock * 1000000;
683 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
685 clk_set_rate(inf->dclk_divider, dclk_rate);
693 static inline unsigned int chan_to_field(unsigned int chan,
694 struct fb_bitfield *bf)
697 chan >>= 16 - bf->length;
698 return chan << bf->offset;
701 static int fb_setcolreg(unsigned regno,
702 unsigned red, unsigned green, unsigned blue,
703 unsigned transp, struct fb_info *info)
706 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
708 switch (info->fix.visual) {
709 case FB_VISUAL_TRUECOLOR:
710 /* true-colour, use pseudo-palette */
712 u32 *pal = info->pseudo_palette;
713 val = chan_to_field(red, &info->var.red);
714 val |= chan_to_field(green, &info->var.green);
715 val |= chan_to_field(blue, &info->var.blue);
720 return -1; /* unknown type */
726 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
729 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
731 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
733 LcdWrReg(inf, REG_CFG_DONE, 0x01);
737 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
739 struct rk29fb_screen *screen = inf->cur_screen;
742 if (x >= 0x800 || y >= 0x800 )
744 //printk("%s: %08x,%08x \n",__func__, x, y);
745 x += (screen->left_margin + screen->hsync_len);
746 y += (screen->upper_margin + screen->vsync_len);
747 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
748 LcdWrReg(inf, REG_CFG_DONE, 0x01);
753 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
755 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
756 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
757 LcdWrReg(inf, REG_CFG_DONE, 0x01);
761 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
762 int rk29_set_cursor_img_transform(char *data)
765 char *dst = (char*)rk29_cursor_buf;
766 unsigned char dmsk = 0;
767 unsigned int op,shift,offset;
769 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
770 * clears it to transparent then combines the cursor
771 * shape plane with the colour plane to set the
773 for (y = 0; y < 32; y++)
775 for (x = 0; x < 32; x++)
782 op = (dmsk & 0x80) ? 2 : 3;
785 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
795 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
799 rk29_set_cursor_img_transform(data);
803 rk29_set_cursor_img_transform(cursor_img);
805 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
806 LcdSetRegisterBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
807 LcdWrReg(inf, REG_CFG_DONE, 0x01);
811 int rk29_set_cursor_test(struct fb_info *info)
813 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
814 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
815 rk29_set_cursor_pos(inf, 0, 0);
816 rk29_set_cursor_img(inf, 0);
817 rk29_set_cursor_en(inf, 1);
822 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
824 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
826 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
828 /* check not being asked to exceed capabilities */
830 if (cursor->image.width > 32)
833 if (cursor->image.height > 32)
836 if (cursor->image.depth > 1)
840 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
842 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
845 if (cursor->set & FB_CUR_SETPOS)
847 unsigned int x = cursor->image.dx;
848 unsigned int y = cursor->image.dy;
850 if (x >= 0x800 || y >= 0x800 )
852 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
856 if (cursor->set & FB_CUR_SETCMAP)
858 unsigned int bg_col = cursor->image.bg_color;
859 unsigned int fg_col = cursor->image.fg_color;
861 fbprintk("%s: update cmap (%08x,%08x)\n",
862 __func__, bg_col, fg_col);
864 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
865 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));
867 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
868 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));
871 if ((cursor->set & FB_CUR_SETSIZE ||
872 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
873 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
875 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
876 * clears it to transparent then combines the cursor
877 * shape plane with the colour plane to set the
880 const unsigned char *pcol = cursor->image.data;
881 const unsigned char *pmsk = cursor->mask;
883 unsigned long cursor_mem_start;
884 unsigned char dcol = 0;
885 unsigned char dmsk = 0;
888 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
889 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
891 fbprintk("%s: setting shape (%d,%d)\n",
892 __func__, cursor->image.width, cursor->image.height);
894 memset(dst, 0, CURSOR_BUF_SIZE);
896 for (y = 0; y < cursor->image.height; y++)
898 for (x = 0; x < cursor->image.width; x++)
909 op = (dcol & 1) ? 1 : 3;
910 op <<= ((x % 4) * 2);
911 *(u8*)(dst+(x/4)) |= op;
916 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
917 LcdWrReg(inf, HWC_MST, cursor_mem_start);
918 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
919 if(SCREEN_MCU == inf->cur_screen->type) {
920 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
924 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
926 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
933 static int win0_blank(int blank_mode, struct fb_info *info)
935 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
937 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
943 case FB_BLANK_UNBLANK:
944 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
947 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
950 LcdWrReg(inf, REG_CFG_DONE, 0x01);
956 static int win0_set_par(struct fb_info *info)
958 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
959 struct rk29fb_screen *screen = inf->cur_screen;
960 struct fb_var_screeninfo *var = &info->var;
961 struct fb_fix_screeninfo *fix = &info->fix;
962 struct win0_par *par = info->par;
964 u32 xact = var->xres; /* visible resolution */
965 u32 yact = var->yres;
966 u32 xvir = var->xres_virtual; /* virtual resolution */
967 u32 yvir = var->yres_virtual;
968 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
969 //u32 yact_st = var->yoffset; /* resolution */
970 u32 xpos = par->xpos;
971 u32 ypos = par->ypos;
973 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
974 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
976 u32 y_addr = 0; //user alloc buf addr y
979 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
983 if(((var->rotate == 270)||(var->rotate == 90)) && (inf->video_mode))
985 #ifdef CONFIG_FB_ROTATE_VIDEO
986 // if(xact > screen->x_res)
988 xact = screen->x_res; /* visible resolution */
989 yact = screen->y_res;
990 xvir = screen->x_res; /* virtual resolution */
991 yvir = screen->y_res;
993 // xact = var->yres; /* visible resolution */
995 // xvir = var->yres_virtual; /* virtual resolution */
996 // yvir = var->xres_virtual;
998 #else //CONFIG_FB_ROTATE_VIDEO
999 printk("LCDC not support rotate!\n");
1004 // calculate the display phy address
1005 y_addr = fix->smem_start + par->y_offset;
1006 uv_addr = fix->mmio_start + par->c_offset;
1008 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1009 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1011 switch (par->format)
1014 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1015 ScaleCbrY = CalScaleW0(yact, par->ysize);
1019 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1020 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1023 ScaleCbrX= CalScaleW0(xact, par->xsize);
1024 ScaleCbrY = CalScaleW0(yact, par->ysize);
1030 xpos += (screen->left_margin + screen->hsync_len);
1031 ypos += (screen->upper_margin + screen->vsync_len);
1033 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1034 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1036 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1038 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1039 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1040 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1041 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1042 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1043 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1048 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,
1049 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));
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(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));
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) |
1058 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1061 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,
1062 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) );
1066 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1072 static int win0_pan( struct fb_info *info )
1074 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1075 // struct fb_var_screeninfo *var0 = &info->var;
1076 struct fb_fix_screeninfo *fix0 = &info->fix;
1077 struct win0_par *par = info->par;
1078 u32 y_addr=0, uv_addr=0;
1080 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1084 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1085 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1087 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1088 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1089 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1091 // enable win0 after the win0 addr is seted
1092 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1098 static int win1_blank(int blank_mode, struct fb_info *info)
1100 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1102 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1108 case FB_BLANK_UNBLANK:
1109 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1112 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1115 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1121 static int win1_set_par(struct fb_info *info)
1123 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1124 struct fb_fix_screeninfo *fix = &info->fix;
1125 struct rk29fb_screen *screen = inf->cur_screen;
1126 struct win0_par *par = info->par;
1127 struct fb_var_screeninfo *var = &info->var;
1129 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1131 u16 xres_virtual = 0; //virtual screen size
1133 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1134 //u16 ypos_virtual = var->yoffset;
1136 u16 xpos = par->xpos; //visiable offset in panel
1137 u16 ypos = par->ypos;
1139 u8 trspmode = TRSP_CLOSE;
1142 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1144 #ifdef CONFIG_FB_SCALING_OSD
1145 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1146 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1148 addr = fix->mmio_start + par->y_offset;
1149 xres_virtual = screen->x_res; //virtual screen size
1154 addr = fix->smem_start + par->y_offset;
1155 xres_virtual = var->xres_virtual; //virtual screen size
1157 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1159 xpos += (screen->left_margin + screen->hsync_len);
1160 ypos += (screen->upper_margin + screen->vsync_len);
1162 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1164 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1165 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1167 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1169 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1170 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1172 // enable win1 color key and set the color to black(rgb=0)
1173 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1175 if(1==par->format) //rgb565
1177 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1178 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1182 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1183 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1185 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1188 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1193 static int win1_pan( struct fb_info *info )
1195 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1196 struct fb_fix_screeninfo *fix1 = &info->fix;
1197 struct win0_par *par = info->par;
1200 #ifdef CONFIG_FB_SCALING_OSD
1201 struct rk29fb_screen *screen = inf->cur_screen;
1202 struct fb_var_screeninfo *var = &info->var;
1203 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1204 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1206 addr = fix1->mmio_start + par->y_offset;
1211 addr = fix1->smem_start + par->y_offset;
1214 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1216 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1217 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1223 static int fb0_blank(int blank_mode, struct fb_info *info)
1225 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1227 if(inf->video_mode == 1)
1229 win1_blank(blank_mode, info);
1233 win0_blank(blank_mode, info);
1238 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1240 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1241 struct rk29fb_screen *screen = inf->cur_screen;
1242 u16 xpos = (var->nonstd>>8) & 0xfff;
1243 u16 ypos = (var->nonstd>>20) & 0xfff;
1244 u16 xlcd = screen->x_res;
1245 u16 ylcd = screen->y_res;
1247 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1251 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1252 0==var->xres || 0==var->yres || var->xres<16 ||
1253 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1255 printk(">>>>>> fb0_check_var fail 1!!! \n");
1256 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1257 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1258 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1262 if( (var->xoffset+var->xres)>var->xres_virtual ||
1263 (var->yoffset+var->yres)>var->yres_virtual )
1265 printk(">>>>>> fb0_check_var fail 2!!! \n");
1266 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1267 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1268 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1272 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1273 switch(var->bits_per_pixel)
1276 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1277 var->xres = (var->xres + 0x1) & (~0x1);
1278 var->xoffset = (var->xoffset) & (~0x1);
1281 var->bits_per_pixel = 32;
1289 static int fb0_set_par(struct fb_info *info)
1291 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1292 struct fb_var_screeninfo *var = &info->var;
1293 struct fb_fix_screeninfo *fix = &info->fix;
1294 struct rk29fb_screen *screen = inf->cur_screen;
1295 struct win0_par *par = info->par;
1297 u32 offset=0, smem_len=0;
1298 u16 xres_virtual = var->xres_virtual; //virtual screen size
1299 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1300 u16 ypos_virtual = var->yoffset;
1302 #ifdef CONFIG_FB_SCALING_OSD
1303 struct rk29_ipp_req ipp_req;
1307 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1311 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1312 #if !defined(CONFIG_FB_SCALING_OSD)
1313 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1316 switch(var->bits_per_pixel)
1320 //fix->line_length = 2 * xres_virtual;
1321 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1323 #ifdef CONFIG_FB_SCALING_OSD
1324 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1325 ipp_req.src0.fmt = IPP_RGB_565;
1326 ipp_req.dst0.fmt = IPP_RGB_565;
1328 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1333 fix->line_length = 4 * xres_virtual;
1334 #ifdef CONFIG_FB_SCALING_OSD
1335 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1336 ipp_req.src0.fmt = IPP_XRGB_8888;
1337 ipp_req.dst0.fmt = IPP_XRGB_8888;
1339 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1343 smem_len = fix->line_length * var->yres_virtual;
1344 //map_size = PAGE_ALIGN(smem_len);
1346 if (smem_len > fix->smem_len) // buffer need realloc
1348 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1349 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1350 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1354 par->addr_seted = 1;
1355 #if ANDROID_USE_THREE_BUFS
1356 if(0==new_frame_seted) {
1358 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1360 new_frame_seted = 0;
1363 if(inf->video_mode == 1)
1365 #ifdef CONFIG_FB_SCALING_OSD
1366 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1367 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1371 par->xsize = screen->x_res;
1372 par->ysize = screen->y_res;
1373 par->y_offset = dstoffset;
1375 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1376 ipp_req.src0.w = var->xres;
1377 ipp_req.src0.h = var->yres;
1379 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1380 ipp_req.dst0.w = screen->x_res;
1381 ipp_req.dst0.h = screen->y_res;
1383 ipp_req.src_vir_w = ipp_req.src0.w;
1384 ipp_req.dst_vir_w = ipp_req.dst0.w;
1385 ipp_req.timeout = 100;
1386 ipp_req.flag = IPP_ROT_0;
1387 //ipp_do_blit(&ipp_req);
1388 ipp_blit_sync(&ipp_req);
1392 par->y_offset = offset;
1393 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1394 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1395 par->xsize = var->xres; //visiable size in panel
1396 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1402 par->y_offset = offset;
1405 par->xsize = screen->x_res;
1406 par->ysize = screen->y_res;
1413 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1416 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1417 struct fb_var_screeninfo *var1 = &info->var;
1418 struct rk29fb_screen *screen = inf->cur_screen;
1419 struct win0_par *par = info->par;
1422 u16 ypos_virtual = var->yoffset;
1423 u16 xpos_virtual = var->xoffset;
1424 #ifdef CONFIG_FB_SCALING_OSD
1425 struct fb_fix_screeninfo *fix = &info->fix;
1426 struct rk29_ipp_req ipp_req;
1429 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1433 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1434 #if !defined(CONFIG_FB_SCALING_OSD)
1435 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1438 switch(var1->bits_per_pixel)
1441 var->xoffset = (var->xoffset) & (~0x1);
1442 #ifdef CONFIG_FB_SCALING_OSD
1443 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1444 ipp_req.src0.fmt = IPP_RGB_565;
1445 ipp_req.dst0.fmt = IPP_RGB_565;
1447 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1450 #ifdef CONFIG_FB_SCALING_OSD
1451 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1452 ipp_req.src0.fmt = IPP_XRGB_8888;
1453 ipp_req.dst0.fmt = IPP_XRGB_8888;
1455 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1461 if(inf->video_mode == 1)
1463 #ifdef CONFIG_FB_SCALING_OSD
1464 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1465 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1467 par->y_offset = dstoffset;
1469 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1470 ipp_req.src0.w = var->xres;
1471 ipp_req.src0.h = var->yres;
1473 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1474 ipp_req.dst0.w = screen->x_res;
1475 ipp_req.dst0.h = screen->y_res;
1477 ipp_req.src_vir_w = ipp_req.src0.w;
1478 ipp_req.dst_vir_w = ipp_req.dst0.w;
1479 ipp_req.timeout = 100;
1480 ipp_req.flag = IPP_ROT_0;
1481 //ipp_do_blit(&ipp_req);
1482 ipp_blit_sync(&ipp_req);
1487 par->y_offset = offset;
1492 par->y_offset = offset;
1495 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1496 #if !ANDROID_USE_THREE_BUFS
1497 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1498 if(SCREEN_MCU == inf->cur_screen->type) {
1499 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1503 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1509 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1511 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1512 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1518 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1521 inf->mcu_usetimer = 0;
1524 case FBIOPUT_16OR32:
1526 inf->fb0_color_deepth = arg;
1529 case FBIOPUT_FBPHYADD:
1530 return info->fix.smem_start;
1531 case FBIOGET_OVERLAY_STATE:
1532 return inf->video_mode;
1533 case FBIOGET_SCREEN_STATE:
1534 return inf->cur_screen->type;
1536 case FBIOPUT_SET_CURSOR_EN:
1539 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1541 rk29_set_cursor_en(inf, en);
1544 case FBIOPUT_SET_CURSOR_POS:
1546 struct fbcurpos pos;
1547 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1549 rk29_set_cursor_pos(inf, pos.x , pos.y);
1552 case FBIOPUT_SET_CURSOR_IMG:
1554 char cursor_buf[CURSOR_BUF_SIZE];
1555 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1557 rk29_set_cursor_img(inf, cursor_buf);
1560 case FBIOPUT_SET_CURSOR_CMAP:
1562 struct fb_image img;
1563 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1565 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1568 case FBIOPUT_GET_CURSOR_RESOLUTION:
1571 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1572 if(inf->fb1->var.rotate == 270) {
1573 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1574 panel_size[1] = inf->cur_screen->x_res;
1576 panel_size[0] = inf->cur_screen->x_res;
1577 panel_size[1] = inf->cur_screen->y_res;
1579 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1582 case FBIOPUT_GET_CURSOR_EN:
1584 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1585 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1594 static int fb1_blank(int blank_mode, struct fb_info *info)
1596 win0_blank(blank_mode, info);
1600 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1602 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1603 struct rk29fb_screen *screen = inf->cur_screen;
1605 u32 ScaleYRGBY=0x1000;
1606 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1607 u16 ypos = (var->nonstd>>20) & 0xfff;
1608 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1609 u16 ysize = (var->grayscale>>20) & 0xfff;
1610 u16 xlcd = screen->x_res; //size of panel
1611 u16 ylcd = screen->y_res;
1614 struct hdmi *hdmi = get_hdmi_struct(0);
1617 if((var->rotate == 270)||(var->rotate == 90)) {
1618 #ifdef CONFIG_FB_ROTATE_VIDEO
1619 xlcd = screen->y_res;
1620 ylcd = screen->x_res;
1621 #else //CONFIG_FB_ROTATE_VIDEO
1622 printk("LCDC not support rotate!\n");
1627 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1628 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1629 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1630 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1632 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1636 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1637 0==var->xres || 0==var->yres || var->xres<16 ||
1638 0==xsize || 0==ysize || xsize<16 ||
1639 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1641 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1642 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1643 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1644 var->bits_per_pixel, var->bits_per_pixel);
1648 if( (var->xoffset+var->xres)>var->xres_virtual ||
1649 (var->yoffset+var->yres)>var->yres_virtual ||
1650 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1652 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1653 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1654 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1655 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1659 switch(var->nonstd&0x0f)
1662 switch(var->bits_per_pixel)
1665 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1666 var->xres = (var->xres + 0x1) & (~0x1);
1667 var->xoffset = (var->xoffset) & (~0x1);
1670 var->bits_per_pixel = 32;
1673 var->nonstd &= ~0xc0; //not support I2P in this format
1676 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1677 var->xres = (var->xres + 0x3) & (~0x3);
1678 var->xoffset = (var->xoffset) & (~0x3);
1681 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1682 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1683 var->xres = (var->xres + 0x3) & (~0x3);
1684 var->yres = (var->yres + 0x1) & (~0x1);
1685 var->xoffset = (var->xoffset) & (~0x3);
1686 var->yoffset = (var->yoffset) & (~0x1);
1689 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1690 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1691 var->xres = (var->xres + 0x3) & (~0x3);
1692 var->yres = (var->yres + 0x1) & (~0x1);
1693 var->xoffset = (var->xoffset) & (~0x3);
1694 var->yoffset = (var->yoffset) & (~0x1);
1695 var->nonstd &= ~0xc0; //not support I2P in this format
1699 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1700 var->xres = (var->xres + 0x3) & (~0x3);
1701 var->xoffset = (var->xoffset) & (~0x3);
1702 var->nonstd &= ~0xc0; //not support I2P in this format
1705 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1709 if((var->rotate == 270)||(var->rotate == 90))
1718 ScaleYRGBY = CalScaleW0(yres, ysize);
1720 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1722 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1725 if(inf->video_mode == 1) {
1726 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1728 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1729 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1730 init_completion(&hdmi->complete);
1732 wait_for_completion_interruptible_timeout(&hdmi->complete,
1733 msecs_to_jiffies(10000));
1740 static int fb1_set_par(struct fb_info *info)
1742 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1743 struct rk29fb_screen *screen = inf->cur_screen;
1744 struct fb_var_screeninfo *var = &info->var;
1745 struct fb_fix_screeninfo *fix = &info->fix;
1746 struct win0_par *par = info->par;
1749 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1751 //u32 xact = var->xres; /* visible resolution */
1752 //u32 yact = var->yres;
1753 u32 xvir = var->xres_virtual; /* virtual resolution */
1754 u32 yvir = var->yres_virtual;
1755 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1756 u32 yact_st = var->yoffset; /* resolution */
1758 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1759 u16 ypos = (var->nonstd>>20) & 0xfff;
1760 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1761 u16 ysize = (var->grayscale>>20) & 0xfff;
1763 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1764 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1766 u8 data_format = var->nonstd&0x0f;
1767 // u32 win0_en = var->reserved[2];
1768 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1769 // u32 uv_addr = var->reserved[4];
1771 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1774 if((var->rotate == 270)||(var->rotate == 90))
1776 #ifdef CONFIG_FB_ROTATE_VIDEO
1777 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1778 ypos = (var->nonstd>>8) & 0xfff;
1779 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1780 ysize = (var->grayscale>>8) & 0xfff;
1781 #else //CONFIG_FB_ROTATE_VIDEO
1782 printk("LCDC not support rotate!\n");
1786 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1787 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1788 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1789 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1791 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1792 switch (data_format)
1795 switch(var->bits_per_pixel)
1799 fix->line_length = 2 * xvir;
1800 par->y_offset = (yact_st*xvir + xact_st)*2;
1804 fix->line_length = 4 * xvir;
1805 par->y_offset = (yact_st*xvir + xact_st)*4;
1813 fix->line_length = xvir;
1814 cblen = crlen = (xvir*yvir)/2;
1815 par->y_offset = yact_st*xvir + xact_st;
1816 par->c_offset = yact_st*xvir + xact_st;
1820 fix->line_length = xvir;
1821 cblen = crlen = (xvir*yvir)/4;
1823 par->y_offset = yact_st*xvir + xact_st;
1824 par->c_offset = (yact_st/2)*xvir + xact_st;
1829 fix->line_length = xvir;
1830 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1831 par->c_offset = (yact_st/2)*xvir + xact_st;
1832 cblen = crlen = (xvir*yvir)/4;
1837 fix->line_length = xvir;
1838 par->y_offset = yact_st*xvir + xact_st;
1839 par->c_offset = yact_st*2*xvir + xact_st*2;
1840 cblen = crlen = (xvir*yvir);
1846 smem_len = fix->line_length * yvir + cblen + crlen;
1847 map_size = PAGE_ALIGN(smem_len);
1849 // fix->smem_start = y_addr;
1850 fix->smem_len = smem_len;
1851 // fix->mmio_start = uv_addr;
1853 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1854 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);
1856 par->format = format;
1863 if ( wq_condition2 == 0 ) {
1864 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
1868 #ifdef CONFIG_FB_ROTATE_VIDEO
1869 //need refresh ,zyc add
1870 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
1873 struct rk29_ipp_req ipp_req;
1874 static u32 dstoffset = 0;
1875 static int fb_index = 0;
1877 yuv_phy[0] = last_yuv_phy[0];
1878 yuv_phy[1] = last_yuv_phy[1];
1879 yuv_phy[0] += par->y_offset;
1880 yuv_phy[1] += par->c_offset;
1881 if((var->rotate == 90) ||(var->rotate == 270))
1883 dstoffset = (dstoffset+1)%2;
1884 ipp_req.src0.fmt = 3;
1885 ipp_req.src0.YrgbMst = yuv_phy[0];
1886 ipp_req.src0.CbrMst = yuv_phy[1];
1887 ipp_req.src0.w = var->xres;
1888 ipp_req.src0.h = var->yres;
1890 ipp_req.dst0.fmt = 3;
1891 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
1892 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
1893 // if(var->xres > screen->x_res)
1895 ipp_req.dst0.w = screen->x_res;
1896 ipp_req.dst0.h = screen->y_res;
1898 // ipp_req.dst0.w = var->yres;
1899 // ipp_req.dst0.h = var->xres;
1901 ipp_req.src_vir_w = ipp_req.src0.w;
1902 ipp_req.dst_vir_w = ipp_req.dst0.w;
1903 ipp_req.timeout = 100;
1904 if(var->rotate == 90)
1905 ipp_req.flag = IPP_ROT_90;
1906 else if(var->rotate == 270)
1907 ipp_req.flag = IPP_ROT_270;
1909 //ipp_do_blit(&ipp_req);
1910 ipp_blit_sync(&ipp_req);
1911 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
1912 yuv_phy[0] = ipp_req.dst0.YrgbMst;
1913 yuv_phy[1] = ipp_req.dst0.CbrMst;
1914 fix->smem_start = yuv_phy[0];
1915 fix->mmio_start = yuv_phy[1];
1920 fix->smem_start = yuv_phy[0];
1921 fix->mmio_start = yuv_phy[1];
1924 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
1925 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
1926 // enable win0 after the win0 par is seted
1927 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
1928 par->addr_seted = 1;
1929 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1930 if(par->addr_seted ) {
1931 unsigned long flags;
1933 local_irq_save(flags);
1934 par->mirror.y_offset = yuv_phy[0];
1935 par->mirror.c_offset = yuv_phy[1];
1936 local_irq_restore(flags);
1939 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
1944 has_set_rotate = false;
1949 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1951 struct win0_par *par = info->par;
1952 // enable win0 after the win0 addr is seted
1959 int fb1_open(struct fb_info *info, int user)
1961 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1962 struct win0_par *par = info->par;
1964 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1967 par->addr_seted = 0;
1968 inf->video_mode = 1;
1970 #ifdef CONFIG_FB_ROTATE_VIDEO
1971 //reinitialize the var when open,zyc
1972 last_yuv_phy[0] = 0;
1973 last_yuv_phy[1] = 0;
1977 printk(">>>>>> fb1 has opened! \n");
1981 fb0_set_par(inf->fb0);
1982 fb0_pan_display(&inf->fb0->var, inf->fb0);
1983 win0_blank(FB_BLANK_POWERDOWN, info);
1988 int fb1_release(struct fb_info *info, int user)
1990 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1991 struct win0_par *par = info->par;
1992 struct fb_var_screeninfo *var0 = &info->var;
1994 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1998 inf->video_mode = 0;
2000 par->addr_seted = 0;
2001 //win0_blank(FB_BLANK_POWERDOWN, info);
2002 fb0_set_par(inf->fb0);
2003 fb0_pan_display(&inf->fb0->var, inf->fb0);
2004 win1_blank(FB_BLANK_POWERDOWN, info);
2005 // wait for lcdc stop access memory
2009 info->screen_base = 0;
2010 info->fix.smem_start = 0;
2011 info->fix.smem_len = 0;
2012 // clean the var param
2013 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2019 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2021 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2022 struct win0_par *par = info->par;
2023 struct fb_fix_screeninfo *fix0 = &info->fix;
2024 struct fb_var_screeninfo *var = &info->var;
2025 void __user *argp = (void __user *)arg;
2027 #ifdef CONFIG_FB_ROTATE_VIDEO
2028 struct rk29fb_screen *screen = inf->cur_screen;
2029 struct rk29_ipp_req ipp_req;
2030 static u32 dstoffset = 0;
2034 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2035 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2041 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2044 if((var->rotate == 270)||(var->rotate == 90)) {
2045 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2046 panel_size[1] = inf->panel1_info.x_res;
2048 panel_size[0] = inf->panel1_info.x_res;
2049 panel_size[1] = inf->panel1_info.y_res;
2052 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2056 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2059 if (copy_from_user(yuv_phy, argp, 8))
2061 #ifdef CONFIG_FB_ROTATE_VIDEO
2063 if(has_set_rotate == true)
2065 last_yuv_phy[0] = yuv_phy[0];
2066 last_yuv_phy[1] = yuv_phy[1];
2069 fix0->smem_start = yuv_phy[0];
2070 fix0->mmio_start = yuv_phy[1];
2071 yuv_phy[0] += par->y_offset;
2072 yuv_phy[1] += par->c_offset;
2074 if((var->rotate == 270)||(var->rotate == 90))
2076 #ifdef CONFIG_FB_ROTATE_VIDEO
2077 dstoffset = (dstoffset+1)%2;
2078 ipp_req.src0.fmt = 3;
2079 ipp_req.src0.YrgbMst = yuv_phy[0];
2080 ipp_req.src0.CbrMst = yuv_phy[1];
2081 ipp_req.src0.w = var->xres;
2082 ipp_req.src0.h = var->yres;
2084 ipp_req.dst0.fmt = 3;
2085 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2086 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2087 // if(var->xres > screen->x_res)
2089 ipp_req.dst0.w = screen->x_res;
2090 ipp_req.dst0.h = screen->y_res;
2092 // ipp_req.dst0.w = var->yres;
2093 // ipp_req.dst0.h = var->xres;
2095 ipp_req.src_vir_w = ipp_req.src0.w;
2096 ipp_req.dst_vir_w = ipp_req.dst0.w;
2097 ipp_req.timeout = 100;
2098 if(var->rotate == 90)
2099 ipp_req.flag = IPP_ROT_90;
2100 else if(var->rotate == 270)
2101 ipp_req.flag = IPP_ROT_270;
2102 //ipp_do_blit(&ipp_req);
2103 ipp_blit_sync(&ipp_req);
2104 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2105 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2106 yuv_phy[1] = ipp_req.dst0.CbrMst;
2107 fix0->smem_start = yuv_phy[0];
2108 fix0->mmio_start = yuv_phy[1];
2109 #else //CONFIG_FB_ROTATE_VIDEO
2110 printk("LCDC not support rotate!\n");
2114 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2115 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2116 // enable win0 after the win0 par is seted
2117 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2118 par->addr_seted = 1;
2119 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2120 if(par->par_seted) {
2121 unsigned long flags;
2123 local_irq_save(flags);
2124 par->mirror.y_offset = yuv_phy[0];
2125 par->mirror.c_offset = yuv_phy[1];
2126 local_irq_restore(flags);
2129 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2134 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2135 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2136 #ifdef CONFIG_FB_ROTATE_VIDEO
2138 has_set_rotate = true;
2139 if(arg == 0 || arg==180)
2141 else if (arg == 90 || arg==270)
2143 #else //CONFIG_FB_ROTATE_VIDEO
2144 printk("LCDC not support rotate!\n");
2147 case FB1_IOCTL_SET_WIN0_TOP:
2148 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2149 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2150 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2158 static struct fb_ops fb1_ops = {
2159 .owner = THIS_MODULE,
2160 .fb_open = fb1_open,
2161 .fb_release = fb1_release,
2162 .fb_check_var = fb1_check_var,
2163 .fb_set_par = fb1_set_par,
2164 .fb_blank = fb1_blank,
2165 .fb_pan_display = fb1_pan_display,
2166 .fb_ioctl = fb1_ioctl,
2167 .fb_setcolreg = fb_setcolreg,
2168 .fb_fillrect = cfb_fillrect,
2169 .fb_copyarea = cfb_copyarea,
2170 .fb_imageblit = cfb_imageblit,
2173 static struct fb_ops fb0_ops = {
2174 .owner = THIS_MODULE,
2175 .fb_check_var = fb0_check_var,
2176 .fb_set_par = fb0_set_par,
2177 .fb_blank = fb0_blank,
2178 .fb_pan_display = fb0_pan_display,
2179 .fb_ioctl = fb0_ioctl,
2180 .fb_setcolreg = fb_setcolreg,
2181 .fb_fillrect = cfb_fillrect,
2182 .fb_copyarea = cfb_copyarea,
2183 .fb_imageblit = cfb_imageblit,
2184 //.fb_cursor = rk29_set_cursor,
2188 enable: 1, switch to tv or hdmi; 0, switch to lcd
2190 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2192 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2193 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2194 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2196 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2198 if(enable)inf->cur_screen = &inf->panel2_info;
2199 else inf->cur_screen = &inf->panel1_info;
2201 /* Black out, because some display device need clock to standby */
2202 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2203 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2204 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2205 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2206 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2207 wake_lock(&idlelock);
2209 wake_unlock(&idlelock);
2211 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2212 // operate the display_on pin to power down the lcd
2214 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2215 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2217 load_screen(inf->fb0, 0);
2220 fb1_set_par(inf->fb1);
2221 fb0_set_par(inf->fb0);
2222 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2223 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2227 static ssize_t dsp_win0_info_read(struct device *device,
2228 struct device_attribute *attr, char *buf)
2231 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2232 struct rk29fb_screen *screen = inf->cur_screen;
2234 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2236 fbprintk("%s\n",__FUNCTION__);
2237 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2238 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2240 xpos -= (screen->left_margin + screen->hsync_len);
2241 ypos -= (screen->upper_margin + screen->vsync_len);
2243 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2244 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2245 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2246 rk29_set_cursor_test(inf->fb0);
2248 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2251 static ssize_t dsp_win0_info_write(struct device *device,
2252 struct device_attribute *attr, const char *buf, size_t count)
2254 printk("%s\n",__FUNCTION__);
2255 printk("%s %x \n",__FUNCTION__,*buf);
2259 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2261 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2263 struct platform_device *pdev = (struct platform_device*)dev_id;
2264 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2265 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2269 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2271 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2273 if(SCREEN_MCU == inf->cur_screen->type)
2275 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2281 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2283 inf->mcu_fmksync = 1;
2284 if(inf->cur_screen->refresh)
2285 inf->cur_screen->refresh(REFRESH_END);
2286 inf->mcu_fmksync = 0;
2295 if(inf->mcu_needflush) {
2296 if(inf->cur_screen->refresh)
2297 inf->cur_screen->refresh(REFRESH_PRE);
2298 inf->mcu_needflush = 0;
2299 inf->mcu_isrcnt = 0;
2300 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2302 if(inf->cur_screen->refresh)
2303 inf->cur_screen->refresh(REFRESH_END);
2307 #if ANDROID_USE_THREE_BUFS
2308 new_frame_seted = 1;
2311 if(waitqueue_active(&par->wait)) {
2312 if (par->mirror.c_offset == 0)
2313 printk("error: no new buffer to display\n");
2315 par->done.y_offset = par->displ.y_offset;
2316 par->done.c_offset = par->displ.c_offset;
2317 par->displ.y_offset = par->mirror.y_offset;
2318 par->displ.c_offset = par->mirror.c_offset;
2319 par->mirror.y_offset = 0;
2320 par->mirror.c_offset = 0;
2322 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2323 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2324 wake_up_interruptible(&par->wait);
2329 wake_up_interruptible(&wq);
2334 #ifdef CONFIG_HAS_EARLYSUSPEND
2336 struct suspend_info {
2337 struct early_suspend early_suspend;
2338 struct rk29fb_inf *inf;
2341 static void rk29fb_early_suspend(struct early_suspend *h)
2343 struct suspend_info *info = container_of(h, struct suspend_info,
2346 struct rk29fb_inf *inf = info->inf;
2347 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2349 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2352 printk("inf==0, rk29fb_suspend fail! \n");
2356 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2357 mach_info->io_disable(); //close lcd out
2359 if(inf->cur_screen->standby)
2361 fbprintk(">>>>>> power down the screen! \n");
2362 inf->cur_screen->standby(1);
2365 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2366 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2368 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2369 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2370 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2372 if(!inf->in_suspend)
2374 fbprintk(">>>>>> diable the lcdc clk! \n");
2375 wake_lock(&idlelock);
2377 wake_unlock(&idlelock);
2378 clk_disable(inf->aclk_ddr_lcdc);
2379 clk_disable(inf->aclk_disp_matrix);
2380 clk_disable(inf->hclk_cpu_display);
2381 clk_disable(inf->clk);
2383 clk_disable(inf->dclk);
2386 clk_disable(inf->aclk);
2388 clk_disable(inf->pd_display);
2390 inf->in_suspend = 1;
2394 static void rk29fb_early_resume(struct early_suspend *h)
2396 struct suspend_info *info = container_of(h, struct suspend_info,
2399 struct rk29fb_inf *inf = info->inf;
2400 struct rk29fb_screen *screen = inf->cur_screen;
2401 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2403 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2405 printk("inf==0, rk29fb_resume fail! \n");
2411 inf->in_suspend = 0;
2412 fbprintk(">>>>>> enable the lcdc clk! \n");
2413 clk_enable(inf->pd_display);
2414 clk_enable(inf->aclk_disp_matrix);
2415 clk_enable(inf->hclk_cpu_display);
2416 clk_enable(inf->clk);
2417 clk_enable(inf->aclk_ddr_lcdc);
2420 clk_enable(inf->dclk);
2423 clk_enable(inf->aclk);
2427 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2428 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2429 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2431 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2432 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2434 if(inf->cur_screen->standby)
2436 fbprintk(">>>>>> power on the screen! \n");
2437 inf->cur_screen->standby(0);
2440 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2443 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2444 mach_info->io_enable(); //close lcd out
2448 static struct suspend_info suspend_info = {
2449 .early_suspend.suspend = rk29fb_early_suspend,
2450 .early_suspend.resume = rk29fb_early_resume,
2451 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2454 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2455 static int __init rk29fb_probe (struct platform_device *pdev)
2457 struct rk29fb_inf *inf = NULL;
2458 struct resource *res = NULL;
2459 struct resource *mem = NULL;
2460 struct rk29fb_info *mach_info = NULL;
2461 struct rk29fb_screen *screen = NULL;
2462 struct win0_par* par = NULL;
2466 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2468 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2469 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2470 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2473 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2475 goto release_drvdata;
2477 memset(inf, 0, sizeof(struct rk29fb_inf));
2478 platform_set_drvdata(pdev, inf);
2480 mach_info = pdev->dev.platform_data;
2481 /* Fill screen info and set current screen */
2482 fbprintk(">> Fill screen info and set current screen \n");
2483 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2484 hdmi_get_default_resolution(&inf->panel1_info);
2486 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2488 inf->cur_screen = &inf->panel1_info;
2489 screen = inf->cur_screen;
2490 if(SCREEN_NULL==screen->type)
2492 dev_err(&pdev->dev, ">> Please select a display device! \n");
2494 goto release_drvdata;
2497 /* get virtual basic address of lcdc register */
2498 fbprintk(">> get virtual basic address of lcdc register \n");
2499 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2502 dev_err(&pdev->dev, "failed to get memory registers\n");
2504 goto release_drvdata;
2506 inf->reg_phy_base = res->start;
2507 inf->len = (res->end - res->start) + 1;
2508 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2511 dev_err(&pdev->dev, "failed to get memory region\n");
2513 goto release_drvdata;
2515 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2516 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2517 if (inf->reg_vir_base == NULL)
2519 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2521 goto release_drvdata;
2523 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2525 /* Prepare win1 info */
2526 fbprintk(">> Prepare win1 info \n");
2527 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2530 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2533 goto release_win1fb;
2536 par = (struct win0_par*)inf->fb0->par;
2537 strcpy(inf->fb0->fix.id, "fb0");
2538 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2539 inf->fb0->fix.type_aux = 0;
2540 inf->fb0->fix.xpanstep = 1;
2541 inf->fb0->fix.ypanstep = 1;
2542 inf->fb0->fix.ywrapstep = 0;
2543 inf->fb0->fix.accel = FB_ACCEL_NONE;
2544 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2545 inf->fb0->fix.smem_len = 0;
2546 inf->fb0->fix.line_length = 0;
2547 inf->fb0->fix.smem_start = 0;
2549 inf->fb0->var.xres = screen->x_res;
2550 inf->fb0->var.yres = screen->y_res;
2551 inf->fb0->var.bits_per_pixel = 16;
2552 inf->fb0_color_deepth = 0;
2553 inf->fb0->var.xres_virtual = screen->x_res;
2554 inf->fb0->var.yres_virtual = screen->y_res;
2555 inf->fb0->var.width = screen->width;
2556 inf->fb0->var.height = screen->height;
2557 inf->fb0->var.pixclock = screen->pixclock;
2558 inf->fb0->var.left_margin = screen->left_margin;
2559 inf->fb0->var.right_margin = screen->right_margin;
2560 inf->fb0->var.upper_margin = screen->upper_margin;
2561 inf->fb0->var.lower_margin = screen->lower_margin;
2562 inf->fb0->var.vsync_len = screen->vsync_len;
2563 inf->fb0->var.hsync_len = screen->hsync_len;
2564 inf->fb0->var.red = def_rgb_16.red;
2565 inf->fb0->var.green = def_rgb_16.green;
2566 inf->fb0->var.blue = def_rgb_16.blue;
2567 inf->fb0->var.transp = def_rgb_16.transp;
2569 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2570 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2571 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2572 inf->fb0->var.accel_flags = 0;
2573 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2575 inf->fb0->fbops = &fb0_ops;
2576 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2577 inf->fb0->pseudo_palette = par->pseudo_pal;
2578 inf->fb0->screen_base = 0;
2580 memset(par, 0, sizeof(struct win0_par));
2582 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2586 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2588 /* alloc win1 buf */
2589 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2592 dev_err(&pdev->dev, "failed to get win1 memory \n");
2594 goto release_win1fb;
2596 inf->fb0->fix.smem_start = res->start;
2597 inf->fb0->fix.smem_len = res->end - res->start + 1;
2598 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2599 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2601 #ifdef CONFIG_FB_WORK_IPP
2602 /* alloc win1 ipp buf */
2603 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2606 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2608 goto release_win1fb;
2610 inf->fb0->fix.mmio_start = res->start;
2611 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2614 /* Prepare win0 info */
2615 fbprintk(">> Prepare win0 info \n");
2616 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2619 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2622 goto release_win0fb;
2625 par = (struct win0_par*)inf->fb1->par;
2627 strcpy(inf->fb1->fix.id, "fb1");
2628 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2629 inf->fb1->fix.type_aux = 0;
2630 inf->fb1->fix.xpanstep = 1;
2631 inf->fb1->fix.ypanstep = 1;
2632 inf->fb1->fix.ywrapstep = 0;
2633 inf->fb1->fix.accel = FB_ACCEL_NONE;
2634 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2635 inf->fb1->fix.smem_len = 0;
2636 inf->fb1->fix.line_length = 0;
2637 inf->fb1->fix.smem_start = 0;
2639 inf->fb1->var.xres = screen->x_res;
2640 inf->fb1->var.yres = screen->y_res;
2641 inf->fb1->var.bits_per_pixel = 16;
2642 inf->fb1->var.xres_virtual = screen->x_res;
2643 inf->fb1->var.yres_virtual = screen->y_res;
2644 inf->fb1->var.width = screen->width;
2645 inf->fb1->var.height = screen->height;
2646 inf->fb1->var.pixclock = screen->pixclock;
2647 inf->fb1->var.left_margin = screen->left_margin;
2648 inf->fb1->var.right_margin = screen->right_margin;
2649 inf->fb1->var.upper_margin = screen->upper_margin;
2650 inf->fb1->var.lower_margin = screen->lower_margin;
2651 inf->fb1->var.vsync_len = screen->vsync_len;
2652 inf->fb1->var.hsync_len = screen->hsync_len;
2653 inf->fb1->var.red = def_rgb_16.red;
2654 inf->fb1->var.green = def_rgb_16.green;
2655 inf->fb1->var.blue = def_rgb_16.blue;
2656 inf->fb1->var.transp = def_rgb_16.transp;
2658 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2659 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2660 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2661 inf->fb1->var.accel_flags = 0;
2662 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2664 inf->fb1->fbops = &fb1_ops;
2665 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2666 inf->fb1->pseudo_palette = par->pseudo_pal;
2667 inf->fb1->screen_base = 0;
2669 memset(par, 0, sizeof(struct win0_par));
2671 init_waitqueue_head(&par->wait);
2673 /* Init all lcdc and lcd before register_framebuffer. */
2674 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2675 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2676 init_lcdc(inf->fb0);
2678 #if 0 //def CONFIG_CPU_FREQ
2679 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2680 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2682 fbprintk("got clock\n");
2686 struct rk29_fb_setting_info fb_setting;
2687 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2689 fb_setting.data_num = 24;
2691 else if(OUT_P666 == inf->cur_screen->face )
2693 fb_setting.data_num = 18;
2697 fb_setting.data_num = 16;
2699 fb_setting.den_en = 1;
2700 fb_setting.vsync_en = 1;
2701 fb_setting.disp_on_en = 1;
2702 fb_setting.standby_en = 1;
2703 if( inf->cur_screen->mcu_usefmk )
2704 fb_setting.mcu_fmk_en =1;
2705 mach_info->io_init(&fb_setting);
2708 //set_lcd_pin(pdev, 1);
2711 inf->mcu_usetimer = 1;
2712 inf->mcu_fmksync = 0;
2713 load_screen(inf->fb0, 1);
2715 /* Register framebuffer(fb0 & fb1) */
2716 fbprintk(">> Register framebuffer(fb0) \n");
2717 ret = register_framebuffer(inf->fb0);
2720 printk(">> fb0 register_framebuffer fail!\n");
2722 goto release_win0fb;
2724 fbprintk(">> Register framebuffer(fb1) \n");
2726 ret = register_framebuffer(inf->fb1);
2729 printk(">> fb1 register_framebuffer fail!\n");
2731 goto unregister_win1fb;
2734 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2737 printk(">> fb1 dsp win0 info device_create_file err\n");
2740 #ifdef CONFIG_HAS_EARLYSUSPEND
2741 suspend_info.inf = inf;
2742 register_early_suspend(&suspend_info.early_suspend);
2745 /* get and request irq */
2746 fbprintk(">> get and request irq \n");
2747 irq = platform_get_irq(pdev, 0);
2749 dev_err(&pdev->dev, "no irq for device\n");
2751 goto unregister_win1fb;
2753 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2755 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2760 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2762 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2765 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2771 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2772 fb0_set_par(inf->fb0);
2773 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2774 /* Start display and show logo on boot */
2775 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2776 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2777 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2781 printk(" %s ok\n", __FUNCTION__);
2786 free_irq(irq, pdev);
2788 unregister_framebuffer(inf->fb0);
2791 framebuffer_release(inf->fb1);
2795 fb_dealloc_cmap(&inf->fb0->cmap);
2798 framebuffer_release(inf->fb0);
2801 if(inf && inf->reg_vir_base)
2802 iounmap(inf->reg_vir_base);
2804 release_mem_region(inf->reg_phy_base, inf->len);
2807 platform_set_drvdata(pdev, NULL);
2811 static int rk29fb_remove(struct platform_device *pdev)
2813 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2814 struct fb_info *info = NULL;
2816 struct rk29fb_info *mach_info = NULL;
2819 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2822 printk("inf==0, rk29_fb_remove fail! \n");
2825 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2827 irq = platform_get_irq(pdev, 0);
2830 free_irq(irq, pdev);
2833 mach_info = pdev->dev.platform_data;
2834 if(mach_info->mcu_fmk_pin)
2836 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2839 if(mach_info->io_disable)
2840 mach_info->io_disable(); //close lcd out
2844 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2846 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2849 //rk29fb_suspend(pdev, msg);
2850 // unmap memory and release framebuffer
2853 if (info->screen_base) {
2854 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2855 info->screen_base = 0;
2856 info->fix.smem_start = 0;
2857 info->fix.smem_len = 0;
2859 unregister_framebuffer(inf->fb1);
2860 framebuffer_release(inf->fb1);
2865 if (info->screen_base) {
2866 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2867 info->screen_base = 0;
2868 info->fix.smem_start = 0;
2869 info->fix.smem_len = 0;
2871 unregister_framebuffer(inf->fb0);
2872 framebuffer_release(inf->fb0);
2876 #if 0 //def CONFIG_CPU_FREQ
2877 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2884 clk_disable(inf->clk);
2890 clk_disable(inf->dclk);
2896 platform_set_drvdata(pdev, NULL);
2901 static void rk29fb_shutdown(struct platform_device *pdev)
2903 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2904 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
2906 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
2908 if(mach_info->io_disable)
2909 mach_info->io_disable(); //close lcd out
2911 if(!inf->in_suspend)
2913 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2914 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2915 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2917 clk_disable(inf->aclk_ddr_lcdc);
2918 clk_disable(inf->aclk_disp_matrix);
2919 clk_disable(inf->hclk_cpu_display);
2920 clk_disable(inf->clk);
2922 clk_disable(inf->dclk);
2925 clk_disable(inf->aclk);
2927 clk_disable(inf->pd_display);
2928 //pmu_set_power_domain(PD_DISPLAY, 0);
2929 inf->in_suspend = 1;
2934 static struct platform_driver rk29fb_driver = {
2935 .probe = rk29fb_probe,
2936 .remove = rk29fb_remove,
2939 .owner = THIS_MODULE,
2941 .shutdown = rk29fb_shutdown,
2944 static int __init rk29fb_init(void)
2946 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
2947 return platform_driver_register(&rk29fb_driver);
2950 static void __exit rk29fb_exit(void)
2952 platform_driver_unregister(&rk29fb_driver);
2955 fs_initcall(rk29fb_init);
2956 module_exit(rk29fb_exit);
2959 MODULE_AUTHOR(" zyw@rock-chips.com");
2960 MODULE_DESCRIPTION("Driver for rk29 fb device");
2961 MODULE_LICENSE("GPL");