2 * drivers/video/rk29_fb.c
4 * Copyright (C) 2010 ROCKCHIP, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
25 #include <linux/init.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/interrupt.h>
28 #include <linux/platform_device.h>
29 #include <linux/clk.h>
30 #include <linux/backlight.h>
31 #include <linux/timer.h>
32 #include <linux/time.h>
33 #include <linux/wait.h>
34 #include <linux/earlysuspend.h>
35 #include <linux/cpufreq.h>
36 #include <linux/wakelock.h>
39 #include <asm/div64.h>
40 #include <asm/uaccess.h>
41 #include <asm/cacheflush.h>
49 #include <linux/completion.h>
51 #include <linux/hdmi.h>
54 #include <mach/iomux.h>
55 #include <mach/gpio.h>
56 #include <mach/board.h>
57 #include <mach/rk29_iomap.h>
59 #include <mach/rk29-ipp.h>
62 #include "./display/screen/screen.h"
64 #define ANDROID_USE_THREE_BUFS 0 //android use three buffers to accelerate UI display in rgb plane
65 #define CURSOR_BUF_SIZE 256 //RK2818 cursor need 256B buf
66 int rk29_cursor_buf[CURSOR_BUF_SIZE];
103 #define fbprintk(msg...) printk(msg);
105 #define fbprintk(msg...)
110 #define fbprintk2(msg...) printk(msg);
112 #define fbprintk2(msg...)
115 #define LcdReadBit(inf, addr, msk) ((inf->regbak.addr=inf->preg->addr)&(msk))
116 #define LcdWrReg(inf, addr, val) inf->preg->addr=inf->regbak.addr=(val)
117 #define LcdRdReg(inf, addr) (inf->preg->addr)
118 #define LcdSetBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) |= (msk))
119 #define LcdClrBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) &= ~(msk))
120 #define LcdSetRegisterBit(inf, addr, msk) inf->preg->addr=((inf->preg->addr) |= (msk))
121 #define LcdMskReg(inf, addr, msk, val) (inf->regbak.addr)&=~(msk); inf->preg->addr=(inf->regbak.addr|=(val))
124 #define IsMcuLandscape() ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
125 #define IsMcuUseFmk() ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
127 #define CalScaleW0(x, y) (((u32)x*0x1000)/y)
130 struct fb_bitfield red;
131 struct fb_bitfield green;
132 struct fb_bitfield blue;
133 struct fb_bitfield transp;
136 static struct rk29fb_rgb def_rgb_16 = {
137 red: { offset: 11, length: 5, },
138 green: { offset: 5, length: 6, },
139 blue: { offset: 0, length: 5, },
140 transp: { offset: 0, length: 0, },
144 volatile u32 y_offset;
145 volatile u32 c_offset;
153 u32 xpos; //size in panel
155 u32 xsize; //start point in panel
159 wait_queue_head_t wait;
160 struct win_set mirror;
161 struct win_set displ;
186 void __iomem *reg_vir_base; // virtual basic address of lcdc register
187 u32 reg_phy_base; // physical basic address of lcdc register
188 u32 len; // physical map length of lcdc register
192 struct clk *dclk; //lcdc dclk
193 struct clk *aclk; //lcdc share memory frequency
194 struct clk *aclk_parent; //lcdc aclk divider frequency source
195 struct clk *aclk_ddr_lcdc; //DDR LCDC AXI clock disable.
196 struct clk *aclk_disp_matrix; //DISPLAY matrix AXI clock disable.
197 struct clk *hclk_cpu_display; //CPU DISPLAY AHB bus clock disable.
198 struct clk *pd_display; // display power domain
199 unsigned long dclk_rate;
201 /* lcdc reg base address and backup reg */
206 int fb0_color_deepth;
207 /* variable used in mcu panel */
211 struct timer_list mcutimer;
218 /* external memery */
219 char __iomem *screen_base2;
221 unsigned long smem_start2;
223 char __iomem *cursor_base; /* cursor Virtual address*/
224 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
225 unsigned long cursor_start;
227 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
228 struct rk29fb_screen panel2_info; // 2nd panel
229 struct rk29fb_screen *cur_screen;
230 #if 0 //def CONFIG_CPU_FREQ
231 struct notifier_block freq_transition;
236 typedef enum _TRSP_MODE
248 struct platform_device *g_pdev = NULL;
249 //static int win1fb_set_par(struct fb_info *info);
252 #define CHK_SUSPEND(inf) \
253 if(inf->in_suspend) { \
254 fbprintk(">>>>>> fb is in suspend! return! \n"); \
258 #define CHK_SUSPEND(inf)
261 static DECLARE_WAIT_QUEUE_HEAD(wq);
262 static int wq_condition = 0;
263 static int wq_condition2 = 0;
264 #if ANDROID_USE_THREE_BUFS
265 static int new_frame_seted = 1;
267 static struct wake_lock idlelock; /* only for fb */
268 #ifdef CONFIG_FB_ROTATE_VIDEO
270 static bool has_set_rotate;
271 static u32 last_yuv_phy[2] = {0,0};
274 static BLOCKING_NOTIFIER_HEAD(rk29fb_notifier_list);
275 int rk29fb_register_notifier(struct notifier_block *nb)
279 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
281 if (inf->cur_screen && inf->cur_screen->type == SCREEN_HDMI)
282 nb->notifier_call(nb, RK29FB_EVENT_HDMI_ON, inf->cur_screen);
283 if (inf->fb1 && inf->fb1->par) {
284 struct win0_par *par = inf->fb1->par;
286 nb->notifier_call(nb, RK29FB_EVENT_FB1_ON, inf->cur_screen);
290 ret = blocking_notifier_chain_register(&rk29fb_notifier_list, nb);
295 int rk29fb_unregister_notifier(struct notifier_block *nb)
297 return blocking_notifier_chain_unregister(&rk29fb_notifier_list, nb);
300 static int rk29fb_notify(struct rk29fb_inf *inf, unsigned long event)
302 return blocking_notifier_call_chain(&rk29fb_notifier_list, event, inf->cur_screen);
305 int mcu_do_refresh(struct rk29fb_inf *inf)
307 if(inf->mcu_stopflush) return 0;
309 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
314 inf->mcu_needflush = 1;
318 // not use frame mark
319 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
321 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
323 inf->mcu_needflush = 1;
327 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
328 inf->mcu_needflush = 0;
330 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
337 void mcutimer_callback(unsigned long arg)
339 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
340 static int waitcnt = 0;
342 mod_timer(&inf->mcutimer, jiffies + HZ/10);
344 switch(inf->mcu_status)
347 inf->mcu_status = MS_MCU;
350 if(inf->mcu_usetimer) mcu_do_refresh(inf);
353 inf->mcu_status = MS_EWAITEND;
361 inf->mcu_status = MS_EEND;
365 inf->mcu_status = MS_MCU;
368 inf->mcu_status = MS_MCU;
373 int mcu_refresh(struct rk29fb_inf *inf)
375 static int mcutimer_inited = 0;
377 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
382 init_timer(&inf->mcutimer);
383 inf->mcutimer.function = mcutimer_callback;
384 inf->mcutimer.expires = jiffies + HZ/5;
385 inf->mcu_status = MS_IDLE;
386 add_timer(&inf->mcutimer);
389 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
394 int mcu_ioctl(unsigned int cmd, unsigned long arg)
396 struct rk29fb_inf *inf = NULL;
397 if(!g_pdev) return -1;
399 inf = dev_get_drvdata(&g_pdev->dev);
404 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
405 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
406 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
410 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
411 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
415 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
416 LcdWrReg(inf, REG_CFG_DONE, 0x01);
426 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
428 struct platform_device *pdev = (struct platform_device*)dev_id;
429 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
430 struct rk29fb_screen *screen;
432 if(!inf) return IRQ_HANDLED;
434 screen = inf->cur_screen;
436 if(0==screen->mcu_usefmk) {
440 if(inf->mcu_fmksync == 1)
443 inf->mcu_fmksync = 1;
444 if(inf->mcu_needflush)
446 inf->mcu_needflush = 0;
448 if(inf->cur_screen->refresh)
449 inf->cur_screen->refresh(REFRESH_PRE);
450 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
452 inf->mcu_fmksync = 0;
457 int init_lcdc(struct fb_info *info)
459 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
462 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
464 inf->clk = clk_get(NULL, "hclk_lcdc");
465 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
466 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
467 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
468 inf->pd_display = clk_get(NULL, "pd_display");
469 if ((IS_ERR(inf->clk)) ||
470 (IS_ERR(inf->aclk_ddr_lcdc)) ||
471 (IS_ERR(inf->aclk_disp_matrix)) ||
472 (IS_ERR(inf->hclk_cpu_display)) ||
473 (IS_ERR(inf->pd_display)))
475 printk(KERN_ERR "failed to get lcdc_hclk source\n");
476 return PTR_ERR(inf->clk);
478 clk_enable(inf->aclk_disp_matrix);
479 clk_enable(inf->hclk_cpu_display);
480 clk_enable(inf->clk);
481 clk_enable(inf->pd_display);
482 //pmu_set_power_domain(PD_DISPLAY, 1);
483 clk_enable(inf->aclk_ddr_lcdc);
485 // set AHB access rule and disable all windows
486 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
487 LcdWrReg(inf, SWAP_CTRL, 0);
488 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
489 LcdWrReg(inf, AXI_MS_ID, 0x54321);
491 // and mcu holdmode; and set win1 top.
492 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
493 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
495 // disable blank out, black out, tristate out, yuv2rgb bypass
496 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
497 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
498 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
499 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
502 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
503 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
505 LcdWrReg(inf, DSP_CTRL1, 0);
507 // initialize all interrupt
508 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
510 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
512 LcdWrReg(inf, INT_STATUS, clr | msk);
514 // let above to take effect
515 LcdWrReg(inf, REG_CFG_DONE, 0x01);
520 void load_screen(struct fb_info *info, bool initscreen)
523 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
524 struct rk29fb_screen *screen = inf->cur_screen;
526 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
527 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
528 u16 x_res = screen->x_res, y_res = screen->y_res;
529 u32 aclk_rate = 150000000;
532 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
536 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
538 // set the rgb or mcu
539 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
541 // set out format and mcu timing
542 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
543 if(mcu_total>31) mcu_total = 31;
544 if(mcu_total<3) mcu_total = 3;
545 mcu_rwstart = (mcu_total+1)/4 - 1;
546 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
547 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
548 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
550 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
551 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
553 LcdMskReg(inf, MCU_TIMING_CTRL,
554 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
555 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
556 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
557 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
558 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
561 // set synchronous pin polarity and data pin swap rule
562 switch (screen->face)
566 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
570 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
574 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
578 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
582 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
583 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
586 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
587 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
592 LcdMskReg(inf, DSP_CTRL0,
593 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
594 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
595 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
596 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
599 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
601 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
602 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));
604 // set horizontal & vertical out timing
605 if(SCREEN_MCU==inf->cur_screen->type)
607 right_margin = x_res/6;
610 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
611 screen->hsync_len , screen->left_margin , x_res , right_margin );
612 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
613 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
614 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
615 v_BIT12HI(screen->hsync_len + screen->left_margin));
617 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
618 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
619 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
620 v_BIT11HI(screen->vsync_len + screen->upper_margin));
622 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
623 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
625 // let above to take effect
626 LcdWrReg(inf, REG_CFG_DONE, 0x01);
628 inf->dclk = clk_get(NULL, "dclk_lcdc");
629 if (IS_ERR(inf->dclk))
631 printk(KERN_ERR "failed to get lcd dclock source\n");
635 inf->aclk = clk_get(NULL, "aclk_lcdc");
636 if (IS_ERR(inf->aclk))
638 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
641 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
642 if (IS_ERR(inf->aclk_parent))
644 printk(KERN_ERR "failed to get lcd clock parent source\n");
649 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
651 if(initscreen == 0) //not init
653 clk_disable(inf->dclk);
654 // clk_disable(inf->aclk);
657 // clk_disable(inf->aclk_ddr_lcdc);
658 // clk_disable(inf->aclk_disp_matrix);
659 // clk_disable(inf->hclk_cpu_display);
661 // clk_disable(inf->clk);
664 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
666 ret = clk_set_rate(inf->dclk, screen->pixclock);
669 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
674 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
675 if(screen->lcdc_aclk){
676 aclk_rate = screen->lcdc_aclk;
678 ret = clk_set_rate(inf->aclk, aclk_rate);
680 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
682 clk_enable(inf->aclk);
684 // clk_enable(inf->aclk_ddr_lcdc);
685 // clk_enable(inf->aclk_disp_matrix);
686 // clk_enable(inf->hclk_cpu_display);
687 // clk_enable(inf->clk);
688 clk_enable(inf->dclk);
696 #if 0 //def CONFIG_CPU_FREQ
698 * CPU clock speed change handler. We need to adjust the LCD timing
699 * parameters when the CPU clock is adjusted by the power management
702 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
705 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
707 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
708 struct rk29fb_screen *screen = inf->cur_screen;
713 case CPUFREQ_PRECHANGE:
715 case CPUFREQ_POSTCHANGE:
717 dclk_rate = screen->pixclock * 1000000;
719 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
721 clk_set_rate(inf->dclk_divider, dclk_rate);
729 static inline unsigned int chan_to_field(unsigned int chan,
730 struct fb_bitfield *bf)
733 chan >>= 16 - bf->length;
734 return chan << bf->offset;
737 static int fb_setcolreg(unsigned regno,
738 unsigned red, unsigned green, unsigned blue,
739 unsigned transp, struct fb_info *info)
742 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
744 switch (info->fix.visual) {
745 case FB_VISUAL_TRUECOLOR:
746 /* true-colour, use pseudo-palette */
748 u32 *pal = info->pseudo_palette;
749 val = chan_to_field(red, &info->var.red);
750 val |= chan_to_field(green, &info->var.green);
751 val |= chan_to_field(blue, &info->var.blue);
756 return -1; /* unknown type */
762 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
765 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
767 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
769 LcdWrReg(inf, REG_CFG_DONE, 0x01);
773 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
775 struct rk29fb_screen *screen = inf->cur_screen;
778 if (x >= 0x800 || y >= 0x800 )
780 //printk("%s: %08x,%08x \n",__func__, x, y);
781 x += (screen->left_margin + screen->hsync_len);
782 y += (screen->upper_margin + screen->vsync_len);
783 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
784 LcdWrReg(inf, REG_CFG_DONE, 0x01);
789 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
791 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
792 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
793 LcdWrReg(inf, REG_CFG_DONE, 0x01);
797 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
798 int rk29_set_cursor_img_transform(char *data)
801 char *dst = (char*)rk29_cursor_buf;
802 unsigned char dmsk = 0;
803 unsigned int op,shift,offset;
805 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
806 * clears it to transparent then combines the cursor
807 * shape plane with the colour plane to set the
809 for (y = 0; y < 32; y++)
811 for (x = 0; x < 32; x++)
818 op = (dmsk & 0x80) ? 2 : 3;
821 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
831 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
835 rk29_set_cursor_img_transform(data);
839 rk29_set_cursor_img_transform(cursor_img);
841 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
842 //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
843 LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
845 LcdWrReg(inf, REG_CFG_DONE, 0x01);
850 int rk29_set_cursor_test(struct fb_info *info)
852 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
853 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
854 rk29_set_cursor_pos(inf, 0, 0);
855 rk29_set_cursor_img(inf, 0);
856 rk29_set_cursor_en(inf, 1);
861 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
863 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
865 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
867 /* check not being asked to exceed capabilities */
869 if (cursor->image.width > 32)
872 if (cursor->image.height > 32)
875 if (cursor->image.depth > 1)
879 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
881 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
884 if (cursor->set & FB_CUR_SETPOS)
886 unsigned int x = cursor->image.dx;
887 unsigned int y = cursor->image.dy;
889 if (x >= 0x800 || y >= 0x800 )
891 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
895 if (cursor->set & FB_CUR_SETCMAP)
897 unsigned int bg_col = cursor->image.bg_color;
898 unsigned int fg_col = cursor->image.fg_color;
900 fbprintk("%s: update cmap (%08x,%08x)\n",
901 __func__, bg_col, fg_col);
903 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
904 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));
906 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
907 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));
910 if ((cursor->set & FB_CUR_SETSIZE ||
911 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
912 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
914 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
915 * clears it to transparent then combines the cursor
916 * shape plane with the colour plane to set the
919 const unsigned char *pcol = cursor->image.data;
920 const unsigned char *pmsk = cursor->mask;
922 unsigned long cursor_mem_start;
923 unsigned char dcol = 0;
924 unsigned char dmsk = 0;
927 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
928 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
930 fbprintk("%s: setting shape (%d,%d)\n",
931 __func__, cursor->image.width, cursor->image.height);
933 memset(dst, 0, CURSOR_BUF_SIZE);
935 for (y = 0; y < cursor->image.height; y++)
937 for (x = 0; x < cursor->image.width; x++)
948 op = (dcol & 1) ? 1 : 3;
949 op <<= ((x % 4) * 2);
950 *(u8*)(dst+(x/4)) |= op;
955 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
956 LcdWrReg(inf, HWC_MST, cursor_mem_start);
957 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
958 if(SCREEN_MCU == inf->cur_screen->type) {
959 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
963 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
965 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
971 static int hdmi_get_fbscale(void)
974 return hdmi_get_scale();
979 static void hdmi_set_fbscale(struct fb_info *info)
982 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
983 struct rk29fb_screen *screen = inf->cur_screen;
984 struct win0_par *par = info->par;
987 scale = hdmi_get_scale();
990 par->xpos += screen->x_res * (100-scale) / 200;
991 par->ypos += screen->y_res * (100-scale) / 200;
992 par->xsize = par->xsize *scale /100;
993 par->ysize = par->ysize *scale /100;
996 static int win0_blank(int blank_mode, struct fb_info *info)
998 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1000 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1006 case FB_BLANK_UNBLANK:
1007 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1008 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1011 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1012 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1013 #ifdef CONFIG_DDR_RECONFIG
1023 static int win0_set_par(struct fb_info *info)
1025 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1026 struct rk29fb_screen *screen = inf->cur_screen;
1027 struct fb_var_screeninfo *var = &info->var;
1028 struct fb_fix_screeninfo *fix = &info->fix;
1029 struct win0_par *par = info->par;
1030 u32 xact, yact, xvir, yvir, xpos, ypos, ScaleYrgbX,ScaleYrgbY, ScaleCbrX, ScaleCbrY, y_addr,uv_addr;
1031 hdmi_set_fbscale(info);
1032 xact = var->xres; /* visible resolution */
1034 xvir = var->xres_virtual; /* virtual resolution */
1035 yvir = var->yres_virtual;
1036 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
1037 //u32 yact_st = var->yoffset; /* resolution */
1046 y_addr = 0; //user alloc buf addr y
1049 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1053 if(((var->rotate == 270)||(var->rotate == 90) || (var->rotate == 180)) && (inf->video_mode))
1055 #ifdef CONFIG_FB_ROTATE_VIDEO
1056 // if(xact > screen->x_res)
1058 xact = screen->x_res; /* visible resolution */
1059 yact = screen->y_res;
1060 xvir = screen->x_res; /* virtual resolution */
1061 yvir = screen->y_res;
1063 // xact = var->yres; /* visible resolution */
1064 // yact = var->xres;
1065 // xvir = var->yres_virtual; /* virtual resolution */
1066 // yvir = var->xres_virtual;
1068 #else //CONFIG_FB_ROTATE_VIDEO
1069 printk("LCDC not support rotate!\n");
1074 // calculate the display phy address
1075 y_addr = fix->smem_start + par->y_offset;
1076 uv_addr = fix->mmio_start + par->c_offset;
1078 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1079 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1081 switch (par->format)
1084 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1085 ScaleCbrY = CalScaleW0(yact, par->ysize);
1089 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1090 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1093 ScaleCbrX= CalScaleW0(xact, par->xsize);
1094 ScaleCbrY = CalScaleW0(yact, par->ysize);
1100 xpos += (screen->left_margin + screen->hsync_len);
1101 ypos += (screen->upper_margin + screen->vsync_len);
1103 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1104 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1106 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1108 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1109 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1110 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1111 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1112 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1113 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1118 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,
1119 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));
1122 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,
1123 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));
1126 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,
1127 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) |
1128 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1131 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,
1132 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) );
1136 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1142 static int win0_pan( struct fb_info *info )
1144 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1145 // struct fb_var_screeninfo *var0 = &info->var;
1146 struct fb_fix_screeninfo *fix0 = &info->fix;
1147 struct win0_par *par = info->par;
1148 u32 y_addr=0, uv_addr=0;
1150 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1154 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1155 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1157 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1158 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1159 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1161 // enable win0 after the win0 addr is seted
1162 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1168 static int win1_blank(int blank_mode, struct fb_info *info)
1170 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1172 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1178 case FB_BLANK_UNBLANK:
1179 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1182 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1185 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1191 static int win1_set_par(struct fb_info *info)
1193 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1194 struct fb_fix_screeninfo *fix = &info->fix;
1195 struct rk29fb_screen *screen = inf->cur_screen;
1196 struct win0_par *par = info->par;
1197 struct fb_var_screeninfo *var = &info->var;
1199 u16 xres_virtual,xpos,ypos;
1200 u8 trspval,trspmode;
1201 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1202 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1204 hdmi_set_fbscale(info);
1205 }else if(((screen->x_res==1920) ))
1207 if(hdmi_get_fbscale() < 100)
1208 par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1210 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1212 xres_virtual = 0; //virtual screen size
1214 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1215 //u16 ypos_virtual = var->yoffset;
1217 xpos = par->xpos; //visiable offset in panel
1220 trspmode = TRSP_CLOSE;
1223 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1225 #ifdef CONFIG_FB_SCALING_OSD
1226 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1227 && (screen->x_res<=1280))
1229 addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1230 xres_virtual = screen->x_res* hdmi_get_fbscale()/100; //virtual screen size
1235 addr = fix->smem_start + par->y_offset;
1236 xres_virtual = var->xres_virtual; //virtual screen size
1238 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1240 xpos += (screen->left_margin + screen->hsync_len);
1241 ypos += (screen->upper_margin + screen->vsync_len);
1243 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1245 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1246 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1248 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1250 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1251 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1253 // enable win1 color key and set the color to black(rgb=0)
1254 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1256 if(1==par->format) //rgb565
1258 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1259 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1263 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1264 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1266 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1269 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1274 static int win1_pan( struct fb_info *info )
1276 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1277 struct fb_fix_screeninfo *fix1 = &info->fix;
1278 struct win0_par *par = info->par;
1281 #ifdef CONFIG_FB_SCALING_OSD
1282 struct rk29fb_screen *screen = inf->cur_screen;
1283 struct fb_var_screeninfo *var = &info->var;
1284 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1285 && (screen->x_res<=1280))
1287 addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1292 addr = fix1->smem_start + par->y_offset;
1295 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1297 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1298 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1304 static int fb0_blank(int blank_mode, struct fb_info *info)
1306 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1308 if(inf->video_mode == 1)
1310 win1_blank(blank_mode, info);
1314 win0_blank(blank_mode, info);
1319 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1321 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1322 struct rk29fb_screen *screen = inf->cur_screen;
1323 u16 xpos = (var->nonstd>>8) & 0xfff;
1324 u16 ypos = (var->nonstd>>20) & 0xfff;
1325 u16 xlcd = screen->x_res;
1326 u16 ylcd = screen->y_res;
1328 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1332 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1333 0==var->xres || 0==var->yres || var->xres<16 ||
1334 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1336 printk(">>>>>> fb0_check_var fail 1!!! \n");
1337 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1338 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1339 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1343 if( (var->xoffset+var->xres)>var->xres_virtual ||
1344 (var->yoffset+var->yres)>var->yres_virtual )
1346 printk(">>>>>> fb0_check_var fail 2!!! \n");
1347 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1348 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1349 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1353 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1354 switch(var->bits_per_pixel)
1357 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1358 var->xres = (var->xres + 0x1) & (~0x1);
1359 var->xoffset = (var->xoffset) & (~0x1);
1362 var->bits_per_pixel = 32;
1370 static int fb0_set_par(struct fb_info *info)
1372 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1373 struct fb_var_screeninfo *var = &info->var;
1374 struct fb_fix_screeninfo *fix = &info->fix;
1375 struct rk29fb_screen *screen = inf->cur_screen;
1376 struct win0_par *par = info->par;
1378 u32 offset=0, smem_len=0;
1379 u16 xres_virtual = var->xres_virtual; //virtual screen size
1380 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1381 u16 ypos_virtual = var->yoffset;
1383 #ifdef CONFIG_FB_SCALING_OSD
1384 struct rk29_ipp_req ipp_req;
1388 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1393 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1394 #if !defined(CONFIG_FB_SCALING_OSD)
1395 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1398 switch(var->bits_per_pixel)
1402 //fix->line_length = 2 * xres_virtual;
1403 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1405 #ifdef CONFIG_FB_SCALING_OSD
1406 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1407 ipp_req.src0.fmt = IPP_RGB_565;
1408 ipp_req.dst0.fmt = IPP_RGB_565;
1410 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1415 fix->line_length = 4 * xres_virtual;
1416 #ifdef CONFIG_FB_SCALING_OSD
1417 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1418 ipp_req.src0.fmt = IPP_XRGB_8888;
1419 ipp_req.dst0.fmt = IPP_XRGB_8888;
1421 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1425 smem_len = fix->line_length * var->yres_virtual;
1426 //map_size = PAGE_ALIGN(smem_len);
1428 if (smem_len > fix->smem_len) // buffer need realloc
1430 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1431 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1432 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1436 par->addr_seted = 1;
1437 #if ANDROID_USE_THREE_BUFS
1438 if(0==new_frame_seted) {
1440 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1442 new_frame_seted = 0;
1445 if(inf->video_mode == 1)
1447 #ifdef CONFIG_FB_SCALING_OSD
1448 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1449 && (screen->x_res<=1280))
1453 par->xsize = screen->x_res;
1454 par->ysize = screen->y_res;
1455 par->y_offset = dstoffset;
1457 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1458 ipp_req.src0.w = var->xres;
1459 ipp_req.src0.h = var->yres;
1461 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1462 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1463 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1465 ipp_req.src_vir_w = ipp_req.src0.w;
1466 ipp_req.dst_vir_w = ipp_req.dst0.w;
1467 ipp_req.timeout = 100;
1468 ipp_req.flag = IPP_ROT_0;
1469 //ipp_do_blit(&ipp_req);
1470 ipp_blit_sync(&ipp_req);
1474 par->y_offset = offset;
1475 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1476 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1477 par->xsize = var->xres; //visiable size in panel
1478 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1484 par->y_offset = offset;
1487 par->xsize = screen->x_res;
1488 par->ysize = screen->y_res;
1495 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1498 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1499 struct fb_var_screeninfo *var1 = &info->var;
1500 struct rk29fb_screen *screen = inf->cur_screen;
1501 struct win0_par *par = info->par;
1504 u16 ypos_virtual = var->yoffset;
1505 u16 xpos_virtual = var->xoffset;
1506 #ifdef CONFIG_FB_SCALING_OSD
1507 struct fb_fix_screeninfo *fix = &info->fix;
1508 struct rk29_ipp_req ipp_req;
1511 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1515 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1516 #if !defined(CONFIG_FB_SCALING_OSD)
1517 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1520 switch(var1->bits_per_pixel)
1523 var->xoffset = (var->xoffset) & (~0x1);
1524 #ifdef CONFIG_FB_SCALING_OSD
1525 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1526 ipp_req.src0.fmt = IPP_RGB_565;
1527 ipp_req.dst0.fmt = IPP_RGB_565;
1529 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1532 #ifdef CONFIG_FB_SCALING_OSD
1533 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1534 ipp_req.src0.fmt = IPP_XRGB_8888;
1535 ipp_req.dst0.fmt = IPP_XRGB_8888;
1537 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1543 if(inf->video_mode == 1)
1545 #ifdef CONFIG_FB_SCALING_OSD
1546 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1547 && (screen->x_res<=1280))
1549 par->y_offset = dstoffset;
1551 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1552 ipp_req.src0.w = var->xres;
1553 ipp_req.src0.h = var->yres;
1555 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1556 ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1557 ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1559 ipp_req.src_vir_w = ipp_req.src0.w;
1560 ipp_req.dst_vir_w = ipp_req.dst0.w;
1561 ipp_req.timeout = 100;
1562 ipp_req.flag = IPP_ROT_0;
1563 //ipp_do_blit(&ipp_req);
1564 ipp_blit_sync(&ipp_req);
1569 par->y_offset = offset;
1574 par->y_offset = offset;
1577 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1578 #if !ANDROID_USE_THREE_BUFS
1579 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1580 if(SCREEN_MCU == inf->cur_screen->type) {
1581 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1585 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1591 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1593 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1594 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1600 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1603 inf->mcu_usetimer = 0;
1606 case FBIOPUT_16OR32:
1608 inf->fb0_color_deepth = arg;
1611 case FBIOPUT_FBPHYADD:
1612 return info->fix.smem_start;
1613 case FBIOGET_OVERLAY_STATE:
1614 return inf->video_mode;
1615 case FBIOGET_SCREEN_STATE:
1616 return inf->cur_screen->type;
1618 case FBIOPUT_SET_CURSOR_EN:
1621 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1623 rk29_set_cursor_en(inf, en);
1626 case FBIOPUT_SET_CURSOR_POS:
1628 struct fbcurpos pos;
1629 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1631 rk29_set_cursor_pos(inf, pos.x , pos.y);
1634 case FBIOPUT_SET_CURSOR_IMG:
1636 char cursor_buf[CURSOR_BUF_SIZE];
1637 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1639 rk29_set_cursor_img(inf, cursor_buf);
1642 case FBIOPUT_SET_CURSOR_CMAP:
1644 struct fb_image img;
1645 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1647 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1650 case FBIOPUT_GET_CURSOR_RESOLUTION:
1653 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1654 if(inf->fb1->var.rotate == 270) {
1655 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1656 panel_size[1] = inf->cur_screen->x_res;
1658 panel_size[0] = inf->cur_screen->x_res;
1659 panel_size[1] = inf->cur_screen->y_res;
1661 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1664 case FBIOPUT_GET_CURSOR_EN:
1666 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1667 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1676 static int fb1_blank(int blank_mode, struct fb_info *info)
1678 win0_blank(blank_mode, info);
1682 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1684 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1685 struct rk29fb_screen *screen = inf->cur_screen;
1687 u32 ScaleYRGBY=0x1000;
1688 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1689 u16 ypos = (var->nonstd>>20) & 0xfff;
1690 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1691 u16 ysize = (var->grayscale>>20) & 0xfff;
1692 u16 xlcd = screen->x_res; //size of panel
1693 u16 ylcd = screen->y_res;
1696 struct hdmi *hdmi = get_hdmi_struct(0);
1699 if((var->rotate == 270)||(var->rotate == 90)) {
1700 #ifdef CONFIG_FB_ROTATE_VIDEO
1701 xlcd = screen->y_res;
1702 ylcd = screen->x_res;
1703 #else //CONFIG_FB_ROTATE_VIDEO
1704 printk("LCDC not support rotate!\n");
1709 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1710 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1711 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1712 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1714 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1718 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1719 0==var->xres || 0==var->yres || var->xres<16 ||
1720 0==xsize || 0==ysize || xsize<16 ||
1721 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1723 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1724 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1725 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1726 var->bits_per_pixel, var->bits_per_pixel);
1730 if( (var->xoffset+var->xres)>var->xres_virtual ||
1731 (var->yoffset+var->yres)>var->yres_virtual ||
1732 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1734 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1735 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1736 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1737 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1741 switch(var->nonstd&0x0f)
1744 switch(var->bits_per_pixel)
1747 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1748 var->xres = (var->xres + 0x1) & (~0x1);
1749 var->xoffset = (var->xoffset) & (~0x1);
1752 var->bits_per_pixel = 32;
1755 var->nonstd &= ~0xc0; //not support I2P in this format
1758 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1759 var->xres = (var->xres + 0x3) & (~0x3);
1760 var->xoffset = (var->xoffset) & (~0x3);
1763 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1764 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1765 var->xres = (var->xres + 0x3) & (~0x3);
1766 var->yres = (var->yres + 0x1) & (~0x1);
1767 var->xoffset = (var->xoffset) & (~0x3);
1768 var->yoffset = (var->yoffset) & (~0x1);
1771 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1772 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1773 var->xres = (var->xres + 0x3) & (~0x3);
1774 var->yres = (var->yres + 0x1) & (~0x1);
1775 var->xoffset = (var->xoffset) & (~0x3);
1776 var->yoffset = (var->yoffset) & (~0x1);
1777 var->nonstd &= ~0xc0; //not support I2P in this format
1781 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1782 var->xres = (var->xres + 0x3) & (~0x3);
1783 var->xoffset = (var->xoffset) & (~0x3);
1784 var->nonstd &= ~0xc0; //not support I2P in this format
1787 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1791 if((var->rotate == 270)||(var->rotate == 90))
1800 ScaleYRGBY = CalScaleW0(yres, ysize);
1802 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1804 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1807 if(inf->video_mode == 1) {
1808 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1810 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1811 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1812 init_completion(&hdmi->complete);
1814 wait_for_completion_interruptible_timeout(&hdmi->complete,
1815 msecs_to_jiffies(10000));
1822 static int fb1_set_par(struct fb_info *info)
1824 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1825 struct rk29fb_screen *screen = inf->cur_screen;
1826 struct fb_var_screeninfo *var = &info->var;
1827 struct fb_fix_screeninfo *fix = &info->fix;
1828 struct win0_par *par = info->par;
1831 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1833 //u32 xact = var->xres; /* visible resolution */
1834 //u32 yact = var->yres;
1835 u32 xvir = var->xres_virtual; /* virtual resolution */
1836 u32 yvir = var->yres_virtual;
1837 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1838 u32 yact_st = var->yoffset; /* resolution */
1840 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1841 u16 ypos = (var->nonstd>>20) & 0xfff;
1842 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1843 u16 ysize = (var->grayscale>>20) & 0xfff;
1845 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1846 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1848 u8 data_format = var->nonstd&0x0f;
1849 // u32 win0_en = var->reserved[2];
1850 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1851 // u32 uv_addr = var->reserved[4];
1853 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1856 if((var->rotate == 270)||(var->rotate == 90))
1858 #ifdef CONFIG_FB_ROTATE_VIDEO
1859 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1860 ypos = (var->nonstd>>8) & 0xfff;
1861 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1862 ysize = (var->grayscale>>8) & 0xfff;
1863 #else //CONFIG_FB_ROTATE_VIDEO
1864 printk("LCDC not support rotate!\n");
1868 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1869 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1870 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1871 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1873 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1874 switch (data_format)
1877 switch(var->bits_per_pixel)
1881 fix->line_length = 2 * xvir;
1882 par->y_offset = (yact_st*xvir + xact_st)*2;
1886 fix->line_length = 4 * xvir;
1887 par->y_offset = (yact_st*xvir + xact_st)*4;
1895 fix->line_length = xvir;
1896 cblen = crlen = (xvir*yvir)/2;
1897 par->y_offset = yact_st*xvir + xact_st;
1898 par->c_offset = yact_st*xvir + xact_st;
1902 fix->line_length = xvir;
1903 cblen = crlen = (xvir*yvir)/4;
1905 par->y_offset = yact_st*xvir + xact_st;
1906 par->c_offset = (yact_st/2)*xvir + xact_st;
1911 fix->line_length = xvir;
1912 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1913 par->c_offset = (yact_st/2)*xvir + xact_st;
1914 cblen = crlen = (xvir*yvir)/4;
1919 fix->line_length = xvir;
1920 par->y_offset = yact_st*xvir + xact_st;
1921 par->c_offset = yact_st*2*xvir + xact_st*2;
1922 cblen = crlen = (xvir*yvir);
1928 smem_len = fix->line_length * yvir + cblen + crlen;
1929 map_size = PAGE_ALIGN(smem_len);
1931 // fix->smem_start = y_addr;
1932 fix->smem_len = smem_len;
1933 // fix->mmio_start = uv_addr;
1935 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1936 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);
1938 par->format = format;
1945 if ( wq_condition2 == 0 ) {
1946 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
1950 #ifdef CONFIG_FB_ROTATE_VIDEO
1951 //need refresh ,zyc add
1952 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
1955 struct rk29_ipp_req ipp_req;
1956 static u32 dstoffset = 0;
1957 static int fb_index = 0;
1959 yuv_phy[0] = last_yuv_phy[0];
1960 yuv_phy[1] = last_yuv_phy[1];
1961 yuv_phy[0] += par->y_offset;
1962 yuv_phy[1] += par->c_offset;
1964 if((var->rotate == 90) ||(var->rotate == 270))
1966 if(var->rotate%360 != 0)
1969 dstoffset = (dstoffset+1)%2;
1970 ipp_req.src0.fmt = 3;
1971 ipp_req.src0.YrgbMst = yuv_phy[0];
1972 ipp_req.src0.CbrMst = yuv_phy[1];
1973 ipp_req.src0.w = var->xres;
1974 ipp_req.src0.h = var->yres;
1976 ipp_req.src_vir_w= (var->xres + 15) & (~15);
1977 ipp_req.dst_vir_w=screen->x_res;
1979 ipp_req.dst0.fmt = 3;
1980 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
1981 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
1982 // if(var->xres > screen->x_res)
1984 ipp_req.dst0.w = var->xres;
1985 ipp_req.dst0.h = var->yres;
1987 // ipp_req.dst0.w = var->yres;
1988 // ipp_req.dst0.h = var->xres;
1990 //ipp_req.src_vir_w = ipp_req.src0.w;
1991 //ipp_req.dst_vir_w = ipp_req.dst0.w;
1992 ipp_req.timeout = 100;
1993 if(var->rotate == 90)
1994 ipp_req.flag = IPP_ROT_90;
1995 else if (var->rotate == 180)
1996 ipp_req.flag = IPP_ROT_180;
1997 else if(var->rotate == 270)
1998 ipp_req.flag = IPP_ROT_270;
1999 //ipp_do_blit(&ipp_req);
2000 ipp_blit_sync(&ipp_req);
2001 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2002 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2003 yuv_phy[1] = ipp_req.dst0.CbrMst;
2004 fix->smem_start = yuv_phy[0];
2005 fix->mmio_start = yuv_phy[1];
2010 fix->smem_start = yuv_phy[0];
2011 fix->mmio_start = yuv_phy[1];
2014 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2015 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2016 // enable win0 after the win0 par is seted
2017 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2018 par->addr_seted = 1;
2019 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2020 if(par->addr_seted ) {
2021 unsigned long flags;
2023 local_irq_save(flags);
2024 par->mirror.y_offset = yuv_phy[0];
2025 par->mirror.c_offset = yuv_phy[1];
2026 local_irq_restore(flags);
2029 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2034 has_set_rotate = false;
2039 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2041 struct win0_par *par = info->par;
2042 // enable win0 after the win0 addr is seted
2049 int fb1_open(struct fb_info *info, int user)
2051 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2052 struct win0_par *par = info->par;
2054 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2057 par->addr_seted = 0;
2058 inf->video_mode = 1;
2060 #ifdef CONFIG_FB_ROTATE_VIDEO
2061 //reinitialize the var when open,zyc
2062 last_yuv_phy[0] = 0;
2063 last_yuv_phy[1] = 0;
2067 printk(">>>>>> fb1 has opened! \n");
2071 fb0_set_par(inf->fb0);
2072 fb0_pan_display(&inf->fb0->var, inf->fb0);
2073 win0_blank(FB_BLANK_POWERDOWN, info);
2074 rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2079 int fb1_release(struct fb_info *info, int user)
2081 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2082 struct win0_par *par = info->par;
2083 struct fb_var_screeninfo *var0 = &info->var;
2085 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2086 if(inf->setFlag == 0)
2088 wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2092 inf->video_mode = 0;
2094 par->addr_seted = 0;
2095 //win0_blank(FB_BLANK_POWERDOWN, info);
2096 fb0_set_par(inf->fb0);
2097 fb0_pan_display(&inf->fb0->var, inf->fb0);
2098 win1_blank(FB_BLANK_POWERDOWN, info);
2099 // wait for lcdc stop access memory
2103 info->screen_base = 0;
2104 info->fix.smem_start = 0;
2105 info->fix.smem_len = 0;
2106 // clean the var param
2107 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2108 rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2114 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2116 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2117 struct win0_par *par = info->par;
2118 struct fb_fix_screeninfo *fix0 = &info->fix;
2119 struct fb_var_screeninfo *var = &info->var;
2120 void __user *argp = (void __user *)arg;
2122 #ifdef CONFIG_FB_ROTATE_VIDEO
2123 struct rk29fb_screen *screen = inf->cur_screen;
2124 struct rk29_ipp_req ipp_req;
2125 static u32 dstoffset = 0;
2129 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2130 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2136 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2139 if((var->rotate == 270)||(var->rotate == 90)) {
2140 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2141 panel_size[1] = inf->panel1_info.x_res;
2143 panel_size[0] = inf->panel1_info.x_res;
2144 panel_size[1] = inf->panel1_info.y_res;
2147 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2151 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2154 if (copy_from_user(yuv_phy, argp, 8))
2156 #ifdef CONFIG_FB_ROTATE_VIDEO
2158 if(has_set_rotate == true)
2160 last_yuv_phy[0] = yuv_phy[0];
2161 last_yuv_phy[1] = yuv_phy[1];
2164 fix0->smem_start = yuv_phy[0];
2165 fix0->mmio_start = yuv_phy[1];
2166 yuv_phy[0] += par->y_offset;
2167 yuv_phy[1] += par->c_offset;
2170 if((var->rotate == 90) ||(var->rotate == 270))
2172 if(var->rotate%360 != 0)
2175 #ifdef CONFIG_FB_ROTATE_VIDEO
2176 dstoffset = (dstoffset+1)%2;
2177 ipp_req.src0.fmt = 3;
2178 ipp_req.src0.YrgbMst = yuv_phy[0];
2179 ipp_req.src0.CbrMst = yuv_phy[1];
2180 ipp_req.src0.w = var->xres ;
2181 ipp_req.src0.h = var->yres ;
2182 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2183 ipp_req.dst_vir_w=screen->x_res;
2185 ipp_req.dst0.fmt = 3;
2186 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2187 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2188 // if(var->xres > screen->x_res)
2190 ipp_req.dst0.w = screen->x_res;
2191 ipp_req.dst0.h = screen->y_res;
2193 // ipp_req.dst0.w = var->yres;
2194 // ipp_req.dst0.h = var->xres;
2196 // ipp_req.src_vir_w = ipp_req.src0.w;
2197 // ipp_req.dst_vir_w = ipp_req.dst0.w;
2198 ipp_req.timeout = 100;
2199 if(var->rotate == 90)
2200 ipp_req.flag = IPP_ROT_90;
2201 else if(var->rotate == 180)
2202 ipp_req.flag = IPP_ROT_180;
2203 else if(var->rotate == 270)
2204 ipp_req.flag = IPP_ROT_270;
2205 //ipp_do_blit(&ipp_req);
2206 ipp_blit_sync(&ipp_req);
2207 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2208 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2209 yuv_phy[1] = ipp_req.dst0.CbrMst;
2210 fix0->smem_start = yuv_phy[0];
2211 fix0->mmio_start = yuv_phy[1];
2212 #else //CONFIG_FB_ROTATE_VIDEO
2213 printk("LCDC not support rotate!\n");
2217 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2218 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2219 // enable win0 after the win0 par is seted
2220 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2221 par->addr_seted = 1;
2222 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2223 if(par->par_seted) {
2224 unsigned long flags;
2226 local_irq_save(flags);
2227 par->mirror.y_offset = yuv_phy[0];
2228 par->mirror.c_offset = yuv_phy[1];
2229 local_irq_restore(flags);
2232 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2237 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2238 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2239 #ifdef CONFIG_FB_ROTATE_VIDEO
2241 has_set_rotate = true;
2242 if(arg == 0 || arg==180)
2244 else if (arg == 90 || arg==270)
2246 #else //CONFIG_FB_ROTATE_VIDEO
2247 printk("LCDC not support rotate!\n");
2250 case FB1_IOCTL_SET_WIN0_TOP:
2251 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2252 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2253 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2261 static struct fb_ops fb1_ops = {
2262 .owner = THIS_MODULE,
2263 .fb_open = fb1_open,
2264 .fb_release = fb1_release,
2265 .fb_check_var = fb1_check_var,
2266 .fb_set_par = fb1_set_par,
2267 .fb_blank = fb1_blank,
2268 .fb_pan_display = fb1_pan_display,
2269 .fb_ioctl = fb1_ioctl,
2270 .fb_setcolreg = fb_setcolreg,
2271 .fb_fillrect = cfb_fillrect,
2272 .fb_copyarea = cfb_copyarea,
2273 .fb_imageblit = cfb_imageblit,
2276 static struct fb_ops fb0_ops = {
2277 .owner = THIS_MODULE,
2278 .fb_check_var = fb0_check_var,
2279 .fb_set_par = fb0_set_par,
2280 .fb_blank = fb0_blank,
2281 .fb_pan_display = fb0_pan_display,
2282 .fb_ioctl = fb0_ioctl,
2283 .fb_setcolreg = fb_setcolreg,
2284 .fb_fillrect = cfb_fillrect,
2285 .fb_copyarea = cfb_copyarea,
2286 .fb_imageblit = cfb_imageblit,
2287 //.fb_cursor = rk29_set_cursor,
2290 int fb_get_video_mode(void)
2292 struct rk29fb_inf *inf;
2295 inf = platform_get_drvdata(g_pdev);
2296 return inf->video_mode;
2299 enable: 1, switch to tv or hdmi; 0, switch to lcd
2301 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2303 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2304 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2305 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2307 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2309 if(enable)inf->cur_screen = &inf->panel2_info;
2310 else inf->cur_screen = &inf->panel1_info;
2312 /* Black out, because some display device need clock to standby */
2313 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2314 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2315 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2316 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2317 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2318 wake_lock(&idlelock);
2320 wake_unlock(&idlelock);
2322 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2323 // operate the display_on pin to power down the lcd
2325 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2326 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2328 load_screen(inf->fb0, 0);
2331 fb1_set_par(inf->fb1);
2332 fb0_set_par(inf->fb0);
2333 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2334 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2335 rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2339 static ssize_t dsp_win0_info_read(struct device *device,
2340 struct device_attribute *attr, char *buf)
2343 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2344 struct rk29fb_screen *screen = inf->cur_screen;
2346 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2348 fbprintk("%s\n",__FUNCTION__);
2349 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2350 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2352 xpos -= (screen->left_margin + screen->hsync_len);
2353 ypos -= (screen->upper_margin + screen->vsync_len);
2355 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2356 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2357 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2358 rk29_set_cursor_test(inf->fb0);
2360 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2363 static ssize_t dsp_win0_info_write(struct device *device,
2364 struct device_attribute *attr, const char *buf, size_t count)
2366 printk("%s\n",__FUNCTION__);
2367 printk("%s %x \n",__FUNCTION__,*buf);
2371 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2373 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2375 struct platform_device *pdev = (struct platform_device*)dev_id;
2376 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2377 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2381 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2383 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2385 if(SCREEN_MCU == inf->cur_screen->type)
2387 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2393 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2395 inf->mcu_fmksync = 1;
2396 if(inf->cur_screen->refresh)
2397 inf->cur_screen->refresh(REFRESH_END);
2398 inf->mcu_fmksync = 0;
2407 if(inf->mcu_needflush) {
2408 if(inf->cur_screen->refresh)
2409 inf->cur_screen->refresh(REFRESH_PRE);
2410 inf->mcu_needflush = 0;
2411 inf->mcu_isrcnt = 0;
2412 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2414 if(inf->cur_screen->refresh)
2415 inf->cur_screen->refresh(REFRESH_END);
2419 #if ANDROID_USE_THREE_BUFS
2420 new_frame_seted = 1;
2423 if(waitqueue_active(&par->wait)) {
2424 if (par->mirror.c_offset == 0)
2425 printk("error: no new buffer to display\n");
2427 par->done.y_offset = par->displ.y_offset;
2428 par->done.c_offset = par->displ.c_offset;
2429 par->displ.y_offset = par->mirror.y_offset;
2430 par->displ.c_offset = par->mirror.c_offset;
2431 par->mirror.y_offset = 0;
2432 par->mirror.c_offset = 0;
2434 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2435 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2436 wake_up_interruptible(&par->wait);
2441 wake_up_interruptible(&wq);
2443 rk29fb_irq_notify_ddr();
2447 #ifdef CONFIG_HAS_EARLYSUSPEND
2449 struct suspend_info {
2450 struct early_suspend early_suspend;
2451 struct rk29fb_inf *inf;
2454 static void rk29fb_early_suspend(struct early_suspend *h)
2456 struct suspend_info *info = container_of(h, struct suspend_info,
2459 struct rk29fb_inf *inf = info->inf;
2460 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2462 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2465 printk("inf==0, rk29fb_suspend fail! \n");
2469 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2470 mach_info->io_disable(); //close lcd out
2472 if(inf->cur_screen->standby)
2474 fbprintk(">>>>>> power down the screen! \n");
2475 inf->cur_screen->standby(1);
2478 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2479 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2481 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2482 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2483 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2485 if(!inf->in_suspend)
2487 fbprintk(">>>>>> diable the lcdc clk! \n");
2488 wake_lock(&idlelock);
2490 wake_unlock(&idlelock);
2491 clk_disable(inf->aclk_ddr_lcdc);
2492 clk_disable(inf->aclk_disp_matrix);
2493 clk_disable(inf->hclk_cpu_display);
2494 clk_disable(inf->clk);
2496 clk_disable(inf->dclk);
2499 clk_disable(inf->aclk);
2501 clk_disable(inf->pd_display);
2503 inf->in_suspend = 1;
2507 static void rk29fb_early_resume(struct early_suspend *h)
2509 struct suspend_info *info = container_of(h, struct suspend_info,
2512 struct rk29fb_inf *inf = info->inf;
2513 struct rk29fb_screen *screen = inf->cur_screen;
2514 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2516 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2518 printk("inf==0, rk29fb_resume fail! \n");
2524 inf->in_suspend = 0;
2525 fbprintk(">>>>>> enable the lcdc clk! \n");
2526 clk_enable(inf->pd_display);
2527 clk_enable(inf->aclk_disp_matrix);
2528 clk_enable(inf->hclk_cpu_display);
2529 clk_enable(inf->clk);
2530 clk_enable(inf->aclk_ddr_lcdc);
2533 clk_enable(inf->dclk);
2536 clk_enable(inf->aclk);
2538 usleep_range(100*1000, 100*1000);
2540 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2541 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2542 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2544 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2545 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2547 if(inf->cur_screen->standby)
2549 fbprintk(">>>>>> power on the screen! \n");
2550 inf->cur_screen->standby(0);
2552 usleep_range(10*1000, 10*1000);
2553 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2554 usleep_range(40*1000, 40*1000);
2556 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2557 mach_info->io_enable(); //close lcd out
2561 static struct suspend_info suspend_info = {
2562 .early_suspend.suspend = rk29fb_early_suspend,
2563 .early_suspend.resume = rk29fb_early_resume,
2564 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2567 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2568 static int __init rk29fb_probe (struct platform_device *pdev)
2570 struct rk29fb_inf *inf = NULL;
2571 struct resource *res = NULL;
2572 struct resource *mem = NULL;
2573 struct rk29fb_info *mach_info = NULL;
2574 struct rk29fb_screen *screen = NULL;
2575 struct win0_par* par = NULL;
2579 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2581 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2582 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2583 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2586 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2588 goto release_drvdata;
2590 memset(inf, 0, sizeof(struct rk29fb_inf));
2591 platform_set_drvdata(pdev, inf);
2593 mach_info = pdev->dev.platform_data;
2594 /* Fill screen info and set current screen */
2595 fbprintk(">> Fill screen info and set current screen \n");
2596 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2597 hdmi_get_default_resolution(&inf->panel1_info);
2599 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2601 inf->cur_screen = &inf->panel1_info;
2602 screen = inf->cur_screen;
2603 if(SCREEN_NULL==screen->type)
2605 dev_err(&pdev->dev, ">> Please select a display device! \n");
2607 goto release_drvdata;
2610 /* get virtual basic address of lcdc register */
2611 fbprintk(">> get virtual basic address of lcdc register \n");
2612 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2615 dev_err(&pdev->dev, "failed to get memory registers\n");
2617 goto release_drvdata;
2619 inf->reg_phy_base = res->start;
2620 inf->len = (res->end - res->start) + 1;
2621 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2624 dev_err(&pdev->dev, "failed to get memory region\n");
2626 goto release_drvdata;
2628 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2629 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2630 if (inf->reg_vir_base == NULL)
2632 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2634 goto release_drvdata;
2636 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2638 /* Prepare win1 info */
2639 fbprintk(">> Prepare win1 info \n");
2640 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2643 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2646 goto release_win1fb;
2649 par = (struct win0_par*)inf->fb0->par;
2650 strcpy(inf->fb0->fix.id, "fb0");
2651 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2652 inf->fb0->fix.type_aux = 0;
2653 inf->fb0->fix.xpanstep = 1;
2654 inf->fb0->fix.ypanstep = 1;
2655 inf->fb0->fix.ywrapstep = 0;
2656 inf->fb0->fix.accel = FB_ACCEL_NONE;
2657 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2658 inf->fb0->fix.smem_len = 0;
2659 inf->fb0->fix.line_length = 0;
2660 inf->fb0->fix.smem_start = 0;
2662 inf->fb0->var.xres = screen->x_res;
2663 inf->fb0->var.yres = screen->y_res;
2664 inf->fb0->var.bits_per_pixel = 16;
2665 inf->fb0_color_deepth = 0;
2666 inf->fb0->var.xres_virtual = screen->x_res;
2667 inf->fb0->var.yres_virtual = screen->y_res;
2668 inf->fb0->var.width = screen->width;
2669 inf->fb0->var.height = screen->height;
2670 inf->fb0->var.pixclock = screen->pixclock;
2671 inf->fb0->var.left_margin = screen->left_margin;
2672 inf->fb0->var.right_margin = screen->right_margin;
2673 inf->fb0->var.upper_margin = screen->upper_margin;
2674 inf->fb0->var.lower_margin = screen->lower_margin;
2675 inf->fb0->var.vsync_len = screen->vsync_len;
2676 inf->fb0->var.hsync_len = screen->hsync_len;
2677 inf->fb0->var.red = def_rgb_16.red;
2678 inf->fb0->var.green = def_rgb_16.green;
2679 inf->fb0->var.blue = def_rgb_16.blue;
2680 inf->fb0->var.transp = def_rgb_16.transp;
2682 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2683 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2684 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2685 inf->fb0->var.accel_flags = 0;
2686 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2688 inf->fb0->fbops = &fb0_ops;
2689 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2690 inf->fb0->pseudo_palette = par->pseudo_pal;
2691 inf->fb0->screen_base = 0;
2693 memset(par, 0, sizeof(struct win0_par));
2695 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2699 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2701 /* alloc win1 buf */
2702 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2705 dev_err(&pdev->dev, "failed to get win1 memory \n");
2707 goto release_win1fb;
2709 inf->fb0->fix.smem_start = res->start;
2710 inf->fb0->fix.smem_len = res->end - res->start + 1;
2711 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2712 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2714 #ifdef CONFIG_FB_WORK_IPP
2715 /* alloc win1 ipp buf */
2716 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2719 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2721 goto release_win1fb;
2723 inf->fb0->fix.mmio_start = res->start;
2724 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2727 /* Prepare win0 info */
2728 fbprintk(">> Prepare win0 info \n");
2729 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2732 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2735 goto release_win0fb;
2738 par = (struct win0_par*)inf->fb1->par;
2740 strcpy(inf->fb1->fix.id, "fb1");
2741 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2742 inf->fb1->fix.type_aux = 0;
2743 inf->fb1->fix.xpanstep = 1;
2744 inf->fb1->fix.ypanstep = 1;
2745 inf->fb1->fix.ywrapstep = 0;
2746 inf->fb1->fix.accel = FB_ACCEL_NONE;
2747 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2748 inf->fb1->fix.smem_len = 0;
2749 inf->fb1->fix.line_length = 0;
2750 inf->fb1->fix.smem_start = 0;
2752 inf->fb1->var.xres = screen->x_res;
2753 inf->fb1->var.yres = screen->y_res;
2754 inf->fb1->var.bits_per_pixel = 16;
2755 inf->fb1->var.xres_virtual = screen->x_res;
2756 inf->fb1->var.yres_virtual = screen->y_res;
2757 inf->fb1->var.width = screen->width;
2758 inf->fb1->var.height = screen->height;
2759 inf->fb1->var.pixclock = screen->pixclock;
2760 inf->fb1->var.left_margin = screen->left_margin;
2761 inf->fb1->var.right_margin = screen->right_margin;
2762 inf->fb1->var.upper_margin = screen->upper_margin;
2763 inf->fb1->var.lower_margin = screen->lower_margin;
2764 inf->fb1->var.vsync_len = screen->vsync_len;
2765 inf->fb1->var.hsync_len = screen->hsync_len;
2766 inf->fb1->var.red = def_rgb_16.red;
2767 inf->fb1->var.green = def_rgb_16.green;
2768 inf->fb1->var.blue = def_rgb_16.blue;
2769 inf->fb1->var.transp = def_rgb_16.transp;
2771 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2772 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2773 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2774 inf->fb1->var.accel_flags = 0;
2775 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2777 inf->fb1->fbops = &fb1_ops;
2778 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2779 inf->fb1->pseudo_palette = par->pseudo_pal;
2780 inf->fb1->screen_base = 0;
2782 memset(par, 0, sizeof(struct win0_par));
2784 init_waitqueue_head(&par->wait);
2786 /* Init all lcdc and lcd before register_framebuffer. */
2787 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2788 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2789 init_lcdc(inf->fb0);
2791 #if 0 //def CONFIG_CPU_FREQ
2792 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2793 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2795 fbprintk("got clock\n");
2799 struct rk29_fb_setting_info fb_setting;
2800 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2802 fb_setting.data_num = 24;
2804 else if(OUT_P666 == inf->cur_screen->face )
2806 fb_setting.data_num = 18;
2810 fb_setting.data_num = 16;
2812 fb_setting.den_en = 1;
2813 fb_setting.vsync_en = 1;
2814 fb_setting.disp_on_en = 1;
2815 fb_setting.standby_en = 1;
2816 if( inf->cur_screen->mcu_usefmk )
2817 fb_setting.mcu_fmk_en =1;
2818 mach_info->io_init(&fb_setting);
2821 //set_lcd_pin(pdev, 1);
2824 inf->mcu_usetimer = 1;
2825 inf->mcu_fmksync = 0;
2826 load_screen(inf->fb0, 1);
2828 /* Register framebuffer(fb0 & fb1) */
2829 fbprintk(">> Register framebuffer(fb0) \n");
2830 ret = register_framebuffer(inf->fb0);
2833 printk(">> fb0 register_framebuffer fail!\n");
2835 goto release_win0fb;
2837 fbprintk(">> Register framebuffer(fb1) \n");
2839 ret = register_framebuffer(inf->fb1);
2842 printk(">> fb1 register_framebuffer fail!\n");
2844 goto unregister_win1fb;
2847 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2850 printk(">> fb1 dsp win0 info device_create_file err\n");
2853 #ifdef CONFIG_HAS_EARLYSUSPEND
2854 suspend_info.inf = inf;
2855 register_early_suspend(&suspend_info.early_suspend);
2858 /* get and request irq */
2859 fbprintk(">> get and request irq \n");
2860 irq = platform_get_irq(pdev, 0);
2862 dev_err(&pdev->dev, "no irq for device\n");
2864 goto unregister_win1fb;
2866 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2868 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2873 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2875 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2878 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2884 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2885 fb0_set_par(inf->fb0);
2886 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2887 /* Start display and show logo on boot */
2888 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2889 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2890 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2894 printk(" %s ok\n", __FUNCTION__);
2899 free_irq(irq, pdev);
2901 unregister_framebuffer(inf->fb0);
2904 framebuffer_release(inf->fb1);
2908 fb_dealloc_cmap(&inf->fb0->cmap);
2911 framebuffer_release(inf->fb0);
2914 if(inf && inf->reg_vir_base)
2915 iounmap(inf->reg_vir_base);
2917 release_mem_region(inf->reg_phy_base, inf->len);
2920 platform_set_drvdata(pdev, NULL);
2924 static int rk29fb_remove(struct platform_device *pdev)
2926 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2927 struct fb_info *info = NULL;
2929 struct rk29fb_info *mach_info = NULL;
2932 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2935 printk("inf==0, rk29_fb_remove fail! \n");
2938 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2940 irq = platform_get_irq(pdev, 0);
2943 free_irq(irq, pdev);
2946 mach_info = pdev->dev.platform_data;
2947 if(mach_info->mcu_fmk_pin)
2949 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2952 if(mach_info->io_disable)
2953 mach_info->io_disable(); //close lcd out
2957 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2959 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2962 //rk29fb_suspend(pdev, msg);
2963 // unmap memory and release framebuffer
2966 if (info->screen_base) {
2967 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2968 info->screen_base = 0;
2969 info->fix.smem_start = 0;
2970 info->fix.smem_len = 0;
2972 unregister_framebuffer(inf->fb1);
2973 framebuffer_release(inf->fb1);
2978 if (info->screen_base) {
2979 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2980 info->screen_base = 0;
2981 info->fix.smem_start = 0;
2982 info->fix.smem_len = 0;
2984 unregister_framebuffer(inf->fb0);
2985 framebuffer_release(inf->fb0);
2989 #if 0 //def CONFIG_CPU_FREQ
2990 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2997 clk_disable(inf->clk);
3003 clk_disable(inf->dclk);
3009 platform_set_drvdata(pdev, NULL);
3014 static void rk29fb_shutdown(struct platform_device *pdev)
3016 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3017 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3019 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3021 if(mach_info->io_disable)
3022 mach_info->io_disable(); //close lcd out
3024 if(!inf->in_suspend)
3026 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3027 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3028 LcdWrReg(inf, REG_CFG_DONE, 0x01);
3030 clk_disable(inf->aclk_ddr_lcdc);
3031 clk_disable(inf->aclk_disp_matrix);
3032 clk_disable(inf->hclk_cpu_display);
3033 clk_disable(inf->clk);
3035 clk_disable(inf->dclk);
3038 clk_disable(inf->aclk);
3040 clk_disable(inf->pd_display);
3041 //pmu_set_power_domain(PD_DISPLAY, 0);
3042 inf->in_suspend = 1;
3047 static struct platform_driver rk29fb_driver = {
3048 .probe = rk29fb_probe,
3049 .remove = rk29fb_remove,
3052 .owner = THIS_MODULE,
3054 .shutdown = rk29fb_shutdown,
3057 static int __init rk29fb_init(void)
3059 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3060 return platform_driver_register(&rk29fb_driver);
3063 static void __exit rk29fb_exit(void)
3065 platform_driver_unregister(&rk29fb_driver);
3068 fs_initcall(rk29fb_init);
3069 module_exit(rk29fb_exit);
3072 MODULE_AUTHOR(" zyw@rock-chips.com");
3073 MODULE_DESCRIPTION("Driver for rk29 fb device");
3074 MODULE_LICENSE("GPL");