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 *dclk_parent; //lcdc dclk divider frequency source
192 struct clk *dclk_divider; //lcdc demodulator divider frequency
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;
217 /* external memery */
218 char __iomem *screen_base2;
220 unsigned long smem_start2;
222 char __iomem *cursor_base; /* cursor Virtual address*/
223 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
224 unsigned long cursor_start;
226 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
227 struct rk29fb_screen panel2_info; // 2nd panel
228 struct rk29fb_screen *cur_screen;
229 #if 0 //def CONFIG_CPU_FREQ
230 struct notifier_block freq_transition;
235 typedef enum _TRSP_MODE
247 struct platform_device *g_pdev = NULL;
248 //static int win1fb_set_par(struct fb_info *info);
251 #define CHK_SUSPEND(inf) \
252 if(inf->in_suspend) { \
253 fbprintk(">>>>>> fb is in suspend! return! \n"); \
257 #define CHK_SUSPEND(inf)
260 static DECLARE_WAIT_QUEUE_HEAD(wq);
261 static int wq_condition = 0;
262 static int wq_condition2 = 0;
263 #if ANDROID_USE_THREE_BUFS
264 static int new_frame_seted = 1;
266 static struct wake_lock idlelock; /* only for fb */
268 void set_lcd_pin(struct platform_device *pdev, int enable)
270 struct rk29fb_info *mach_info = pdev->dev.platform_data;
272 unsigned display_on = mach_info->disp_on_pin;
273 unsigned lcd_standby = mach_info->standby_pin;
275 int display_on_pol = mach_info->disp_on_value;
276 int lcd_standby_pol = mach_info->standby_value;
278 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
279 fbprintk(">>>>>> display_on(%d) = %d \n", display_on, enable ? display_on_pol : !display_on_pol);
280 fbprintk(">>>>>> lcd_standby(%d) = %d \n", lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);
284 if(display_on != INVALID_GPIO)
286 gpio_direction_output(display_on, 0);
287 gpio_set_value(display_on, enable ? display_on_pol : !display_on_pol);
289 if(lcd_standby != INVALID_GPIO)
291 gpio_direction_output(lcd_standby, 0);
292 gpio_set_value(lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);
296 int mcu_do_refresh(struct rk29fb_inf *inf)
298 if(inf->mcu_stopflush) return 0;
300 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
305 inf->mcu_needflush = 1;
309 // not use frame mark
310 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
312 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
314 inf->mcu_needflush = 1;
318 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
319 inf->mcu_needflush = 0;
321 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
328 void mcutimer_callback(unsigned long arg)
330 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
331 static int waitcnt = 0;
333 mod_timer(&inf->mcutimer, jiffies + HZ/10);
335 switch(inf->mcu_status)
338 inf->mcu_status = MS_MCU;
341 if(inf->mcu_usetimer) mcu_do_refresh(inf);
344 inf->mcu_status = MS_EWAITEND;
352 inf->mcu_status = MS_EEND;
356 inf->mcu_status = MS_MCU;
359 inf->mcu_status = MS_MCU;
364 int mcu_refresh(struct rk29fb_inf *inf)
366 static int mcutimer_inited = 0;
368 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
373 init_timer(&inf->mcutimer);
374 inf->mcutimer.function = mcutimer_callback;
375 inf->mcutimer.expires = jiffies + HZ/5;
376 inf->mcu_status = MS_IDLE;
377 add_timer(&inf->mcutimer);
380 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
385 int mcu_ioctl(unsigned int cmd, unsigned long arg)
387 struct rk29fb_inf *inf = NULL;
388 if(!g_pdev) return -1;
390 inf = dev_get_drvdata(&g_pdev->dev);
395 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
396 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
397 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
401 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
402 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
406 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
407 LcdWrReg(inf, REG_CFG_DONE, 0x01);
417 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
419 struct platform_device *pdev = (struct platform_device*)dev_id;
420 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
421 struct rk29fb_screen *screen;
423 if(!inf) return IRQ_HANDLED;
425 screen = inf->cur_screen;
427 if(0==screen->mcu_usefmk) {
431 if(inf->mcu_fmksync == 1)
434 inf->mcu_fmksync = 1;
435 if(inf->mcu_needflush)
437 inf->mcu_needflush = 0;
439 if(inf->cur_screen->refresh)
440 inf->cur_screen->refresh(REFRESH_PRE);
441 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
443 inf->mcu_fmksync = 0;
448 int init_lcdc(struct fb_info *info)
450 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
453 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
455 inf->clk = clk_get(NULL, "hclk_lcdc");
456 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
457 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
458 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
459 inf->pd_display = clk_get(NULL, "pd_display");
460 if ((IS_ERR(inf->clk)) ||
461 (IS_ERR(inf->aclk_ddr_lcdc)) ||
462 (IS_ERR(inf->aclk_disp_matrix)) ||
463 (IS_ERR(inf->hclk_cpu_display)) ||
464 (IS_ERR(inf->pd_display)))
466 printk(KERN_ERR "failed to get lcdc_hclk source\n");
467 return PTR_ERR(inf->clk);
469 clk_enable(inf->aclk_disp_matrix);
470 clk_enable(inf->hclk_cpu_display);
471 clk_enable(inf->clk);
472 clk_enable(inf->pd_display);
473 //pmu_set_power_domain(PD_DISPLAY, 1);
474 clk_enable(inf->aclk_ddr_lcdc);
476 // set AHB access rule and disable all windows
477 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
478 LcdWrReg(inf, SWAP_CTRL, 0);
479 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
480 LcdWrReg(inf, AXI_MS_ID, 0x54321);
482 // and mcu holdmode; and set win1 top.
483 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
484 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
486 // disable blank out, black out, tristate out, yuv2rgb bypass
487 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
488 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
489 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
490 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
493 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
494 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
496 LcdWrReg(inf, DSP_CTRL1, 0);
498 // initialize all interrupt
499 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
501 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
503 LcdWrReg(inf, INT_STATUS, clr | msk);
505 // let above to take effect
506 LcdWrReg(inf, REG_CFG_DONE, 0x01);
511 void load_screen(struct fb_info *info, bool initscreen)
514 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
515 struct rk29fb_screen *screen = inf->cur_screen;
517 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
518 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
519 u16 x_res = screen->x_res, y_res = screen->y_res;
520 u32 aclk_rate = 150000000;
523 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
527 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
529 // set the rgb or mcu
530 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
532 // set out format and mcu timing
533 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
534 if(mcu_total>31) mcu_total = 31;
535 if(mcu_total<3) mcu_total = 3;
536 mcu_rwstart = (mcu_total+1)/4 - 1;
537 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
538 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
539 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
541 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
542 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
544 LcdMskReg(inf, MCU_TIMING_CTRL,
545 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
546 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
547 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
548 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
549 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
552 // set synchronous pin polarity and data pin swap rule
553 switch (screen->face)
557 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
561 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
565 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
569 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
573 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
574 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
577 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
578 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
583 LcdMskReg(inf, DSP_CTRL0,
584 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
585 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
586 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
587 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
590 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
592 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
593 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));
595 // set horizontal & vertical out timing
596 if(SCREEN_MCU==inf->cur_screen->type)
598 right_margin = x_res/6;
601 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
602 screen->hsync_len , screen->left_margin , x_res , right_margin );
603 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
604 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
605 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
606 v_BIT12HI(screen->hsync_len + screen->left_margin));
608 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
609 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
610 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
611 v_BIT11HI(screen->vsync_len + screen->upper_margin));
613 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
614 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
616 // let above to take effect
617 LcdWrReg(inf, REG_CFG_DONE, 0x01);
619 inf->dclk = clk_get(NULL, "dclk_lcdc");
620 if (IS_ERR(inf->dclk))
622 printk(KERN_ERR "failed to get lcd dclock source\n");
625 inf->dclk_divider= clk_get(NULL, "dclk_lcdc_div");
626 if (IS_ERR(inf->dclk_divider))
628 printk(KERN_ERR "failed to get lcd clock lcdc_divider source \n");
632 if((inf->cur_screen->type == SCREEN_HDMI) || (inf->cur_screen->type == SCREEN_TVOUT)){
633 inf->dclk_parent = clk_get(NULL, "codec_pll");
634 clk_set_rate(inf->dclk_parent, 594000000);
636 inf->dclk_parent = clk_get(NULL, "general_pll");
639 if (IS_ERR(inf->dclk_parent))
641 printk(KERN_ERR "failed to get lcd dclock parent source\n");
645 inf->aclk = clk_get(NULL, "aclk_lcdc");
646 if (IS_ERR(inf->aclk))
648 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
651 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
652 if (IS_ERR(inf->dclk_parent))
654 printk(KERN_ERR "failed to get lcd dclock parent source\n");
659 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
661 if(initscreen == 0) //not init
663 clk_disable(inf->dclk);
664 clk_disable(inf->aclk);
667 clk_disable(inf->aclk_ddr_lcdc);
668 clk_disable(inf->aclk_disp_matrix);
669 clk_disable(inf->hclk_cpu_display);
671 clk_disable(inf->clk);
672 clk_set_parent(inf->dclk_divider, inf->dclk_parent);
673 clk_set_parent(inf->dclk, inf->dclk_divider);
674 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
676 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
678 ret = clk_set_rate(inf->dclk_divider, screen->pixclock);
681 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
684 if(screen->lcdc_aclk){
685 aclk_rate = screen->lcdc_aclk;
687 ret = clk_set_rate(inf->aclk, aclk_rate);
689 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
692 clk_enable(inf->aclk_ddr_lcdc);
693 clk_enable(inf->aclk_disp_matrix);
694 clk_enable(inf->hclk_cpu_display);
696 clk_enable(inf->aclk);
697 clk_enable(inf->clk);
698 clk_enable(inf->dclk);
706 #if 0 //def CONFIG_CPU_FREQ
708 * CPU clock speed change handler. We need to adjust the LCD timing
709 * parameters when the CPU clock is adjusted by the power management
712 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
715 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
717 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
718 struct rk29fb_screen *screen = inf->cur_screen;
723 case CPUFREQ_PRECHANGE:
725 case CPUFREQ_POSTCHANGE:
727 dclk_rate = screen->pixclock * 1000000;
729 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
731 clk_set_rate(inf->dclk_divider, dclk_rate);
739 static inline unsigned int chan_to_field(unsigned int chan,
740 struct fb_bitfield *bf)
743 chan >>= 16 - bf->length;
744 return chan << bf->offset;
747 static int fb_setcolreg(unsigned regno,
748 unsigned red, unsigned green, unsigned blue,
749 unsigned transp, struct fb_info *info)
752 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
754 switch (info->fix.visual) {
755 case FB_VISUAL_TRUECOLOR:
756 /* true-colour, use pseudo-palette */
758 u32 *pal = info->pseudo_palette;
759 val = chan_to_field(red, &info->var.red);
760 val |= chan_to_field(green, &info->var.green);
761 val |= chan_to_field(blue, &info->var.blue);
766 return -1; /* unknown type */
772 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
775 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
777 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
779 LcdWrReg(inf, REG_CFG_DONE, 0x01);
783 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
785 struct rk29fb_screen *screen = inf->cur_screen;
788 if (x >= 0x800 || y >= 0x800 )
790 //printk("%s: %08x,%08x \n",__func__, x, y);
791 x += (screen->left_margin + screen->hsync_len);
792 y += (screen->upper_margin + screen->vsync_len);
793 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
794 LcdWrReg(inf, REG_CFG_DONE, 0x01);
799 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
801 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
802 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
803 LcdWrReg(inf, REG_CFG_DONE, 0x01);
807 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
808 int rk29_set_cursor_img_transform(char *data)
811 char *dst = (char*)rk29_cursor_buf;
812 unsigned char dmsk = 0;
813 unsigned int op,shift,offset;
815 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
816 * clears it to transparent then combines the cursor
817 * shape plane with the colour plane to set the
819 for (y = 0; y < 32; y++)
821 for (x = 0; x < 32; x++)
828 op = (dmsk & 0x80) ? 2 : 3;
831 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
841 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
845 rk29_set_cursor_img_transform(data);
849 rk29_set_cursor_img_transform(cursor_img);
851 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
852 LcdSetRegisterBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
853 LcdWrReg(inf, REG_CFG_DONE, 0x01);
857 int rk29_set_cursor_test(struct fb_info *info)
859 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
860 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
861 rk29_set_cursor_pos(inf, 0, 0);
862 rk29_set_cursor_img(inf, 0);
863 rk29_set_cursor_en(inf, 1);
868 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
870 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
872 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
874 /* check not being asked to exceed capabilities */
876 if (cursor->image.width > 32)
879 if (cursor->image.height > 32)
882 if (cursor->image.depth > 1)
886 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
888 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
891 if (cursor->set & FB_CUR_SETPOS)
893 unsigned int x = cursor->image.dx;
894 unsigned int y = cursor->image.dy;
896 if (x >= 0x800 || y >= 0x800 )
898 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
902 if (cursor->set & FB_CUR_SETCMAP)
904 unsigned int bg_col = cursor->image.bg_color;
905 unsigned int fg_col = cursor->image.fg_color;
907 fbprintk("%s: update cmap (%08x,%08x)\n",
908 __func__, bg_col, fg_col);
910 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
911 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));
913 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
914 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));
917 if ((cursor->set & FB_CUR_SETSIZE ||
918 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
919 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
921 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
922 * clears it to transparent then combines the cursor
923 * shape plane with the colour plane to set the
926 const unsigned char *pcol = cursor->image.data;
927 const unsigned char *pmsk = cursor->mask;
929 unsigned long cursor_mem_start;
930 unsigned char dcol = 0;
931 unsigned char dmsk = 0;
934 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
935 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
937 fbprintk("%s: setting shape (%d,%d)\n",
938 __func__, cursor->image.width, cursor->image.height);
940 memset(dst, 0, CURSOR_BUF_SIZE);
942 for (y = 0; y < cursor->image.height; y++)
944 for (x = 0; x < cursor->image.width; x++)
955 op = (dcol & 1) ? 1 : 3;
956 op <<= ((x % 4) * 2);
957 *(u8*)(dst+(x/4)) |= op;
962 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
963 LcdWrReg(inf, HWC_MST, cursor_mem_start);
964 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
965 if(SCREEN_MCU == inf->cur_screen->type) {
966 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
970 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
972 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
979 static int win0_blank(int blank_mode, struct fb_info *info)
981 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
983 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
989 case FB_BLANK_UNBLANK:
990 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
993 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
996 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1002 static int win0_set_par(struct fb_info *info)
1004 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1005 struct rk29fb_screen *screen = inf->cur_screen;
1006 struct fb_var_screeninfo *var = &info->var;
1007 struct fb_fix_screeninfo *fix = &info->fix;
1008 struct win0_par *par = info->par;
1010 u32 xact = var->xres; /* visible resolution */
1011 u32 yact = var->yres;
1012 u32 xvir = var->xres_virtual; /* virtual resolution */
1013 u32 yvir = var->yres_virtual;
1014 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
1015 //u32 yact_st = var->yoffset; /* resolution */
1016 u32 xpos = par->xpos;
1017 u32 ypos = par->ypos;
1019 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1020 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1022 u32 y_addr = 0; //user alloc buf addr y
1025 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1029 if(((var->rotate == 270)||(var->rotate == 90)) && (inf->video_mode))
1031 #ifdef CONFIG_FB_ROTATE_VIDEO
1032 // if(xact > screen->x_res)
1034 xact = screen->x_res; /* visible resolution */
1035 yact = screen->y_res;
1036 xvir = screen->x_res; /* virtual resolution */
1037 yvir = screen->y_res;
1039 // xact = var->yres; /* visible resolution */
1040 // yact = var->xres;
1041 // xvir = var->yres_virtual; /* virtual resolution */
1042 // yvir = var->xres_virtual;
1044 #else //CONFIG_FB_ROTATE_VIDEO
1045 printk("LCDC not support rotate!\n");
1050 // calculate the display phy address
1051 y_addr = fix->smem_start + par->y_offset;
1052 uv_addr = fix->mmio_start + par->c_offset;
1054 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1055 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1057 switch (par->format)
1060 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1061 ScaleCbrY = CalScaleW0(yact, par->ysize);
1065 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1066 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1069 ScaleCbrX= CalScaleW0(xact, par->xsize);
1070 ScaleCbrY = CalScaleW0(yact, par->ysize);
1076 xpos += (screen->left_margin + screen->hsync_len);
1077 ypos += (screen->upper_margin + screen->vsync_len);
1079 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1080 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1082 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1084 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1085 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1086 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1087 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1088 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1089 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1094 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,
1095 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));
1098 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,
1099 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));
1102 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,
1103 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) |
1104 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1107 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,
1108 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) );
1112 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1118 static int win0_pan( struct fb_info *info )
1120 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1121 // struct fb_var_screeninfo *var0 = &info->var;
1122 struct fb_fix_screeninfo *fix0 = &info->fix;
1123 struct win0_par *par = info->par;
1124 u32 y_addr=0, uv_addr=0;
1126 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1130 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1131 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1133 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1134 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1135 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1137 // enable win0 after the win0 addr is seted
1138 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1144 static int win1_blank(int blank_mode, struct fb_info *info)
1146 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1148 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1154 case FB_BLANK_UNBLANK:
1155 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1158 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1161 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1167 static int win1_set_par(struct fb_info *info)
1169 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1170 struct fb_fix_screeninfo *fix = &info->fix;
1171 struct rk29fb_screen *screen = inf->cur_screen;
1172 struct win0_par *par = info->par;
1173 struct fb_var_screeninfo *var = &info->var;
1175 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1177 u16 xres_virtual = 0; //virtual screen size
1179 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1180 //u16 ypos_virtual = var->yoffset;
1182 u16 xpos = par->xpos; //visiable offset in panel
1183 u16 ypos = par->ypos;
1185 u8 trspmode = TRSP_CLOSE;
1188 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1190 #ifdef CONFIG_FB_SCALING_OSD
1191 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1192 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1194 addr = fix->mmio_start + par->y_offset;
1195 xres_virtual = screen->x_res; //virtual screen size
1200 addr = fix->smem_start + par->y_offset;
1201 xres_virtual = var->xres_virtual; //virtual screen size
1203 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1205 xpos += (screen->left_margin + screen->hsync_len);
1206 ypos += (screen->upper_margin + screen->vsync_len);
1208 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1210 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1211 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1213 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1215 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1216 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1218 // enable win1 color key and set the color to black(rgb=0)
1219 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1221 if(1==par->format) //rgb565
1223 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1224 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1228 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1229 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1231 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1234 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1239 static int win1_pan( struct fb_info *info )
1241 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1242 struct fb_fix_screeninfo *fix1 = &info->fix;
1243 struct win0_par *par = info->par;
1246 #ifdef CONFIG_FB_SCALING_OSD
1247 struct rk29fb_screen *screen = inf->cur_screen;
1248 struct fb_var_screeninfo *var = &info->var;
1249 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1250 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1252 addr = fix1->mmio_start + par->y_offset;
1257 addr = fix1->smem_start + par->y_offset;
1260 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1262 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1263 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1269 static int fb0_blank(int blank_mode, struct fb_info *info)
1271 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1273 if(inf->video_mode == 1)
1275 win1_blank(blank_mode, info);
1279 win0_blank(blank_mode, info);
1284 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1286 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1287 struct rk29fb_screen *screen = inf->cur_screen;
1288 u16 xpos = (var->nonstd>>8) & 0xfff;
1289 u16 ypos = (var->nonstd>>20) & 0xfff;
1290 u16 xlcd = screen->x_res;
1291 u16 ylcd = screen->y_res;
1293 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1297 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1298 0==var->xres || 0==var->yres || var->xres<16 ||
1299 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1301 printk(">>>>>> fb0_check_var fail 1!!! \n");
1302 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1303 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1304 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1308 if( (var->xoffset+var->xres)>var->xres_virtual ||
1309 (var->yoffset+var->yres)>var->yres_virtual )
1311 printk(">>>>>> fb0_check_var fail 2!!! \n");
1312 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1313 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1314 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1318 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1319 switch(var->bits_per_pixel)
1322 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1323 var->xres = (var->xres + 0x1) & (~0x1);
1324 var->xoffset = (var->xoffset) & (~0x1);
1327 var->bits_per_pixel = 32;
1335 static int fb0_set_par(struct fb_info *info)
1337 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1338 struct fb_var_screeninfo *var = &info->var;
1339 struct fb_fix_screeninfo *fix = &info->fix;
1340 struct rk29fb_screen *screen = inf->cur_screen;
1341 struct win0_par *par = info->par;
1343 u32 offset=0, smem_len=0;
1344 u16 xres_virtual = var->xres_virtual; //virtual screen size
1345 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1346 u16 ypos_virtual = var->yoffset;
1348 #ifdef CONFIG_FB_SCALING_OSD
1349 struct rk29_ipp_req ipp_req;
1353 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1357 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1358 #if !defined(CONFIG_FB_SCALING_OSD)
1359 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1362 switch(var->bits_per_pixel)
1366 //fix->line_length = 2 * xres_virtual;
1367 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1369 #ifdef CONFIG_FB_SCALING_OSD
1370 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1371 ipp_req.src0.fmt = IPP_RGB_565;
1372 ipp_req.dst0.fmt = IPP_RGB_565;
1374 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1379 fix->line_length = 4 * xres_virtual;
1380 #ifdef CONFIG_FB_SCALING_OSD
1381 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1382 ipp_req.src0.fmt = IPP_XRGB_8888;
1383 ipp_req.dst0.fmt = IPP_XRGB_8888;
1385 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1389 smem_len = fix->line_length * var->yres_virtual;
1390 //map_size = PAGE_ALIGN(smem_len);
1392 if (smem_len > fix->smem_len) // buffer need realloc
1394 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1395 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1396 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1400 par->addr_seted = 1;
1401 #if ANDROID_USE_THREE_BUFS
1402 if(0==new_frame_seted) {
1404 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1406 new_frame_seted = 0;
1409 if(inf->video_mode == 1)
1411 #ifdef CONFIG_FB_SCALING_OSD
1412 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1413 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1417 par->xsize = screen->x_res;
1418 par->ysize = screen->y_res;
1419 par->y_offset = dstoffset;
1421 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1422 ipp_req.src0.w = var->xres;
1423 ipp_req.src0.h = var->yres;
1425 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1426 ipp_req.dst0.w = screen->x_res;
1427 ipp_req.dst0.h = screen->y_res;
1429 ipp_req.src_vir_w = ipp_req.src0.w;
1430 ipp_req.dst_vir_w = ipp_req.dst0.w;
1431 ipp_req.timeout = 100;
1432 ipp_req.flag = IPP_ROT_0;
1433 ipp_do_blit(&ipp_req);
1437 par->y_offset = offset;
1438 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1439 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1440 par->xsize = var->xres; //visiable size in panel
1441 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1447 par->y_offset = offset;
1450 par->xsize = screen->x_res;
1451 par->ysize = screen->y_res;
1458 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1461 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1462 struct fb_var_screeninfo *var1 = &info->var;
1463 struct rk29fb_screen *screen = inf->cur_screen;
1464 struct win0_par *par = info->par;
1467 u16 ypos_virtual = var->yoffset;
1468 u16 xpos_virtual = var->xoffset;
1469 #ifdef CONFIG_FB_SCALING_OSD
1470 struct fb_fix_screeninfo *fix = &info->fix;
1471 struct rk29_ipp_req ipp_req;
1474 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1478 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1479 #if !defined(CONFIG_FB_SCALING_OSD)
1480 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1483 switch(var1->bits_per_pixel)
1486 var->xoffset = (var->xoffset) & (~0x1);
1487 #ifdef CONFIG_FB_SCALING_OSD
1488 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1489 ipp_req.src0.fmt = IPP_RGB_565;
1490 ipp_req.dst0.fmt = IPP_RGB_565;
1492 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1495 #ifdef CONFIG_FB_SCALING_OSD
1496 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1497 ipp_req.src0.fmt = IPP_XRGB_8888;
1498 ipp_req.dst0.fmt = IPP_XRGB_8888;
1500 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1506 if(inf->video_mode == 1)
1508 #ifdef CONFIG_FB_SCALING_OSD
1509 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1510 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1512 par->y_offset = dstoffset;
1514 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1515 ipp_req.src0.w = var->xres;
1516 ipp_req.src0.h = var->yres;
1518 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1519 ipp_req.dst0.w = screen->x_res;
1520 ipp_req.dst0.h = screen->y_res;
1522 ipp_req.src_vir_w = ipp_req.src0.w;
1523 ipp_req.dst_vir_w = ipp_req.dst0.w;
1524 ipp_req.timeout = 100;
1525 ipp_req.flag = IPP_ROT_0;
1526 ipp_do_blit(&ipp_req);
1531 par->y_offset = offset;
1536 par->y_offset = offset;
1539 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1540 #if !ANDROID_USE_THREE_BUFS
1541 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1542 if(SCREEN_MCU == inf->cur_screen->type) {
1543 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1547 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1553 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1555 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1556 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1562 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1565 inf->mcu_usetimer = 0;
1568 case FBIOPUT_16OR32:
1570 inf->fb0_color_deepth = arg;
1573 case FBIOPUT_FBPHYADD:
1574 return info->fix.smem_start;
1575 case FBIOGET_OVERLAY_STATE:
1576 return inf->video_mode;
1577 case FBIOGET_SCREEN_STATE:
1578 return inf->cur_screen->type;
1580 case FBIOPUT_SET_CURSOR_EN:
1583 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1585 rk29_set_cursor_en(inf, en);
1588 case FBIOPUT_SET_CURSOR_POS:
1590 struct fbcurpos pos;
1591 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1593 rk29_set_cursor_pos(inf, pos.x , pos.y);
1596 case FBIOPUT_SET_CURSOR_IMG:
1598 char cursor_buf[CURSOR_BUF_SIZE];
1599 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1601 rk29_set_cursor_img(inf, cursor_buf);
1604 case FBIOPUT_SET_CURSOR_CMAP:
1606 struct fb_image img;
1607 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1609 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1612 case FBIOPUT_GET_CURSOR_RESOLUTION:
1615 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1616 if(inf->fb1->var.rotate == 270) {
1617 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1618 panel_size[1] = inf->cur_screen->x_res;
1620 panel_size[0] = inf->cur_screen->x_res;
1621 panel_size[1] = inf->cur_screen->y_res;
1623 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1626 case FBIOPUT_GET_CURSOR_EN:
1628 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1629 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1638 static int fb1_blank(int blank_mode, struct fb_info *info)
1640 win0_blank(blank_mode, info);
1644 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1646 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1647 struct rk29fb_screen *screen = inf->cur_screen;
1649 u32 ScaleYRGBY=0x1000;
1650 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1651 u16 ypos = (var->nonstd>>20) & 0xfff;
1652 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1653 u16 ysize = (var->grayscale>>20) & 0xfff;
1654 u16 xlcd = screen->x_res; //size of panel
1655 u16 ylcd = screen->y_res;
1658 struct hdmi *hdmi = get_hdmi_struct(0);
1661 if((var->rotate == 270)||(var->rotate == 90)) {
1662 #ifdef CONFIG_FB_ROTATE_VIDEO
1663 xlcd = screen->y_res;
1664 ylcd = screen->x_res;
1665 #else //CONFIG_FB_ROTATE_VIDEO
1666 printk("LCDC not support rotate!\n");
1671 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1672 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1673 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1674 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1676 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1680 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1681 0==var->xres || 0==var->yres || var->xres<16 ||
1682 0==xsize || 0==ysize || xsize<16 ||
1683 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1685 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1686 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1687 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1688 var->bits_per_pixel, var->bits_per_pixel);
1692 if( (var->xoffset+var->xres)>var->xres_virtual ||
1693 (var->yoffset+var->yres)>var->yres_virtual ||
1694 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1696 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1697 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1698 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1699 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1703 switch(var->nonstd&0x0f)
1706 switch(var->bits_per_pixel)
1709 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1710 var->xres = (var->xres + 0x1) & (~0x1);
1711 var->xoffset = (var->xoffset) & (~0x1);
1714 var->bits_per_pixel = 32;
1717 var->nonstd &= ~0xc0; //not support I2P in this format
1720 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1721 var->xres = (var->xres + 0x3) & (~0x3);
1722 var->xoffset = (var->xoffset) & (~0x3);
1725 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1726 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1727 var->xres = (var->xres + 0x3) & (~0x3);
1728 var->yres = (var->yres + 0x1) & (~0x1);
1729 var->xoffset = (var->xoffset) & (~0x3);
1730 var->yoffset = (var->yoffset) & (~0x1);
1733 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1734 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1735 var->xres = (var->xres + 0x3) & (~0x3);
1736 var->yres = (var->yres + 0x1) & (~0x1);
1737 var->xoffset = (var->xoffset) & (~0x3);
1738 var->yoffset = (var->yoffset) & (~0x1);
1739 var->nonstd &= ~0xc0; //not support I2P in this format
1743 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1744 var->xres = (var->xres + 0x3) & (~0x3);
1745 var->xoffset = (var->xoffset) & (~0x3);
1746 var->nonstd &= ~0xc0; //not support I2P in this format
1749 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1753 if((var->rotate == 270)||(var->rotate == 90))
1762 ScaleYRGBY = CalScaleW0(yres, ysize);
1764 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1766 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1769 if(inf->video_mode == 1) {
1770 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1772 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1773 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1774 init_completion(&hdmi->complete);
1776 wait_for_completion_interruptible_timeout(&hdmi->complete,
1777 msecs_to_jiffies(10000));
1784 static int fb1_set_par(struct fb_info *info)
1786 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1787 struct rk29fb_screen *screen = inf->cur_screen;
1788 struct fb_var_screeninfo *var = &info->var;
1789 struct fb_fix_screeninfo *fix = &info->fix;
1790 struct win0_par *par = info->par;
1793 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1795 //u32 xact = var->xres; /* visible resolution */
1796 //u32 yact = var->yres;
1797 u32 xvir = var->xres_virtual; /* virtual resolution */
1798 u32 yvir = var->yres_virtual;
1799 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1800 u32 yact_st = var->yoffset; /* resolution */
1802 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1803 u16 ypos = (var->nonstd>>20) & 0xfff;
1804 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1805 u16 ysize = (var->grayscale>>20) & 0xfff;
1807 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1808 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1810 u8 data_format = var->nonstd&0x0f;
1811 // u32 win0_en = var->reserved[2];
1812 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1813 // u32 uv_addr = var->reserved[4];
1815 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1818 if((var->rotate == 270)||(var->rotate == 90))
1820 #if CONFIG_FB_ROTATE_VIDEO
1821 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1822 ypos = (var->nonstd>>8) & 0xfff;
1823 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1824 ysize = (var->grayscale>>8) & 0xfff;
1825 #else //CONFIG_FB_ROTATE_VIDEO
1826 printk("LCDC not support rotate!\n");
1830 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1831 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1832 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1833 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1835 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1836 switch (data_format)
1839 switch(var->bits_per_pixel)
1843 fix->line_length = 2 * xvir;
1844 par->y_offset = (yact_st*xvir + xact_st)*2;
1848 fix->line_length = 4 * xvir;
1849 par->y_offset = (yact_st*xvir + xact_st)*4;
1857 fix->line_length = xvir;
1858 cblen = crlen = (xvir*yvir)/2;
1859 par->y_offset = yact_st*xvir + xact_st;
1860 par->c_offset = yact_st*xvir + xact_st;
1864 fix->line_length = xvir;
1865 cblen = crlen = (xvir*yvir)/4;
1867 par->y_offset = yact_st*xvir + xact_st;
1868 par->c_offset = (yact_st/2)*xvir + xact_st;
1873 fix->line_length = xvir;
1874 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1875 par->c_offset = (yact_st/2)*xvir + xact_st;
1876 cblen = crlen = (xvir*yvir)/4;
1881 fix->line_length = xvir;
1882 par->y_offset = yact_st*xvir + xact_st;
1883 par->c_offset = yact_st*2*xvir + xact_st*2;
1884 cblen = crlen = (xvir*yvir);
1890 smem_len = fix->line_length * yvir + cblen + crlen;
1891 map_size = PAGE_ALIGN(smem_len);
1893 // fix->smem_start = y_addr;
1894 fix->smem_len = smem_len;
1895 // fix->mmio_start = uv_addr;
1897 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1898 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);
1900 par->format = format;
1907 if ( wq_condition2 == 0 ) {
1908 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
1915 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1917 struct win0_par *par = info->par;
1918 // enable win0 after the win0 addr is seted
1925 int fb1_open(struct fb_info *info, int user)
1927 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1928 struct win0_par *par = info->par;
1930 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1933 par->addr_seted = 0;
1934 inf->video_mode = 1;
1937 printk(">>>>>> fb1 has opened! \n");
1941 fb0_set_par(inf->fb0);
1942 fb0_pan_display(&inf->fb0->var, inf->fb0);
1943 win0_blank(FB_BLANK_POWERDOWN, info);
1948 int fb1_release(struct fb_info *info, int user)
1950 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1951 struct win0_par *par = info->par;
1952 struct fb_var_screeninfo *var0 = &info->var;
1954 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1958 inf->video_mode = 0;
1960 par->addr_seted = 0;
1961 //win0_blank(FB_BLANK_POWERDOWN, info);
1962 fb0_set_par(inf->fb0);
1963 fb0_pan_display(&inf->fb0->var, inf->fb0);
1964 win1_blank(FB_BLANK_POWERDOWN, info);
1965 // wait for lcdc stop access memory
1969 info->screen_base = 0;
1970 info->fix.smem_start = 0;
1971 info->fix.smem_len = 0;
1972 // clean the var param
1973 memset(var0, 0, sizeof(struct fb_var_screeninfo));
1979 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1981 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1982 struct win0_par *par = info->par;
1983 struct fb_fix_screeninfo *fix0 = &info->fix;
1984 struct fb_var_screeninfo *var = &info->var;
1985 void __user *argp = (void __user *)arg;
1987 #ifdef CONFIG_FB_ROTATE_VIDEO
1988 struct rk29fb_screen *screen = inf->cur_screen;
1989 struct rk29_ipp_req ipp_req;
1990 static u32 dstoffset = 0;
1994 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1995 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2001 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2004 if((var->rotate == 270)||(var->rotate == 90)) {
2005 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2006 panel_size[1] = inf->panel1_info.x_res;
2008 panel_size[0] = inf->panel1_info.x_res;
2009 panel_size[1] = inf->panel1_info.y_res;
2012 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2016 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2019 if (copy_from_user(yuv_phy, argp, 8))
2022 fix0->smem_start = yuv_phy[0];
2023 fix0->mmio_start = yuv_phy[1];
2024 yuv_phy[0] += par->y_offset;
2025 yuv_phy[1] += par->c_offset;
2027 if((var->rotate == 270)||(var->rotate == 90))
2029 #ifdef CONFIG_FB_ROTATE_VIDEO
2030 dstoffset = (dstoffset+1)%2;
2031 ipp_req.src0.fmt = 3;
2032 ipp_req.src0.YrgbMst = yuv_phy[0];
2033 ipp_req.src0.CbrMst = yuv_phy[1];
2034 ipp_req.src0.w = var->xres;
2035 ipp_req.src0.h = var->yres;
2037 ipp_req.dst0.fmt = 3;
2038 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2039 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2040 // if(var->xres > screen->x_res)
2042 ipp_req.dst0.w = screen->x_res;
2043 ipp_req.dst0.h = screen->y_res;
2045 // ipp_req.dst0.w = var->yres;
2046 // ipp_req.dst0.h = var->xres;
2048 ipp_req.src_vir_w = ipp_req.src0.w;
2049 ipp_req.dst_vir_w = ipp_req.dst0.w;
2050 ipp_req.timeout = 100;
2051 if(var->rotate == 90)
2052 ipp_req.flag = IPP_ROT_90;
2053 else if(var->rotate == 270)
2054 ipp_req.flag = IPP_ROT_270;
2055 ipp_do_blit(&ipp_req);
2056 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2057 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2058 yuv_phy[1] = ipp_req.dst0.CbrMst;
2059 fix0->smem_start = yuv_phy[0];
2060 fix0->mmio_start = yuv_phy[1];
2061 #else //CONFIG_FB_ROTATE_VIDEO
2062 printk("LCDC not support rotate!\n");
2066 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2067 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2068 // enable win0 after the win0 par is seted
2069 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2070 par->addr_seted = 1;
2071 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2072 if(par->par_seted) {
2073 unsigned long flags;
2075 local_irq_save(flags);
2076 par->mirror.y_offset = yuv_phy[0];
2077 par->mirror.c_offset = yuv_phy[1];
2078 local_irq_restore(flags);
2081 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2086 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2087 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2088 #ifdef CONFIG_FB_ROTATE_VIDEO
2089 if(arg == 0 || arg==180)
2091 else if (arg == 90 || arg==270)
2093 #else //CONFIG_FB_ROTATE_VIDEO
2094 printk("LCDC not support rotate!\n");
2097 case FB1_IOCTL_SET_WIN0_TOP:
2098 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2099 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2100 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2108 static struct fb_ops fb1_ops = {
2109 .owner = THIS_MODULE,
2110 .fb_open = fb1_open,
2111 .fb_release = fb1_release,
2112 .fb_check_var = fb1_check_var,
2113 .fb_set_par = fb1_set_par,
2114 .fb_blank = fb1_blank,
2115 .fb_pan_display = fb1_pan_display,
2116 .fb_ioctl = fb1_ioctl,
2117 .fb_setcolreg = fb_setcolreg,
2118 .fb_fillrect = cfb_fillrect,
2119 .fb_copyarea = cfb_copyarea,
2120 .fb_imageblit = cfb_imageblit,
2123 static struct fb_ops fb0_ops = {
2124 .owner = THIS_MODULE,
2125 .fb_check_var = fb0_check_var,
2126 .fb_set_par = fb0_set_par,
2127 .fb_blank = fb0_blank,
2128 .fb_pan_display = fb0_pan_display,
2129 .fb_ioctl = fb0_ioctl,
2130 .fb_setcolreg = fb_setcolreg,
2131 .fb_fillrect = cfb_fillrect,
2132 .fb_copyarea = cfb_copyarea,
2133 .fb_imageblit = cfb_imageblit,
2134 //.fb_cursor = rk29_set_cursor,
2138 enable: 1, switch to tv or hdmi; 0, switch to lcd
2140 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2142 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2143 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2145 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2147 if(enable)inf->cur_screen = &inf->panel2_info;
2148 else inf->cur_screen = &inf->panel1_info;
2150 /* Black out, because some display device need clock to standby */
2151 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2152 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2153 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2154 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2155 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2156 wake_lock(&idlelock);
2158 wake_unlock(&idlelock);
2160 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2161 // operate the display_on pin to power down the lcd
2162 set_lcd_pin(g_pdev, (enable==0));
2164 load_screen(inf->fb0, 0);
2167 fb1_set_par(inf->fb1);
2168 fb0_set_par(inf->fb0);
2169 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2170 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2174 static ssize_t dsp_win0_info_read(struct device *device,
2175 struct device_attribute *attr, char *buf)
2178 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2179 struct rk29fb_screen *screen = inf->cur_screen;
2181 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2183 fbprintk("%s\n",__FUNCTION__);
2184 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2185 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2187 xpos -= (screen->left_margin + screen->hsync_len);
2188 ypos -= (screen->upper_margin + screen->vsync_len);
2190 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2191 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2192 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2193 rk29_set_cursor_test(inf->fb0);
2195 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2198 static ssize_t dsp_win0_info_write(struct device *device,
2199 struct device_attribute *attr, const char *buf, size_t count)
2201 printk("%s\n",__FUNCTION__);
2202 printk("%s %x \n",__FUNCTION__,*buf);
2206 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2208 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2210 struct platform_device *pdev = (struct platform_device*)dev_id;
2211 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2212 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2216 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2218 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2220 if(SCREEN_MCU == inf->cur_screen->type)
2222 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2228 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2230 inf->mcu_fmksync = 1;
2231 if(inf->cur_screen->refresh)
2232 inf->cur_screen->refresh(REFRESH_END);
2233 inf->mcu_fmksync = 0;
2242 if(inf->mcu_needflush) {
2243 if(inf->cur_screen->refresh)
2244 inf->cur_screen->refresh(REFRESH_PRE);
2245 inf->mcu_needflush = 0;
2246 inf->mcu_isrcnt = 0;
2247 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2249 if(inf->cur_screen->refresh)
2250 inf->cur_screen->refresh(REFRESH_END);
2254 #if ANDROID_USE_THREE_BUFS
2255 new_frame_seted = 1;
2258 if(waitqueue_active(&par->wait)) {
2259 if (par->mirror.c_offset == 0)
2260 printk("error: no new buffer to display\n");
2262 par->done.y_offset = par->displ.y_offset;
2263 par->done.c_offset = par->displ.c_offset;
2264 par->displ.y_offset = par->mirror.y_offset;
2265 par->displ.c_offset = par->mirror.c_offset;
2266 par->mirror.y_offset = 0;
2267 par->mirror.c_offset = 0;
2269 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2270 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2271 wake_up_interruptible(&par->wait);
2276 wake_up_interruptible(&wq);
2281 #ifdef CONFIG_HAS_EARLYSUSPEND
2283 struct suspend_info {
2284 struct early_suspend early_suspend;
2285 struct rk29fb_inf *inf;
2288 static void rk29fb_early_suspend(struct early_suspend *h)
2290 struct suspend_info *info = container_of(h, struct suspend_info,
2293 struct rk29fb_inf *inf = info->inf;
2295 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2298 printk("inf==0, rk29fb_suspend fail! \n");
2302 if(inf->cur_screen != &inf->panel2_info) // close lcd pwr when output screen is lcd
2303 set_lcd_pin(g_pdev, 0);
2305 if(inf->cur_screen->standby)
2307 fbprintk(">>>>>> power down the screen! \n");
2308 inf->cur_screen->standby(1);
2311 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2312 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2314 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2315 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2316 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2318 if(!inf->in_suspend)
2320 fbprintk(">>>>>> diable the lcdc clk! \n");
2321 wake_lock(&idlelock);
2323 wake_unlock(&idlelock);
2324 clk_disable(inf->aclk_ddr_lcdc);
2325 clk_disable(inf->aclk_disp_matrix);
2326 clk_disable(inf->hclk_cpu_display);
2327 clk_disable(inf->clk);
2329 clk_disable(inf->dclk);
2332 clk_disable(inf->aclk);
2334 clk_disable(inf->pd_display);
2336 inf->in_suspend = 1;
2340 static void rk29fb_early_resume(struct early_suspend *h)
2342 struct suspend_info *info = container_of(h, struct suspend_info,
2345 struct rk29fb_inf *inf = info->inf;
2346 struct rk29fb_screen *screen = inf->cur_screen;
2348 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2350 printk("inf==0, rk29fb_resume fail! \n");
2356 inf->in_suspend = 0;
2357 fbprintk(">>>>>> enable the lcdc clk! \n");
2358 clk_enable(inf->pd_display);
2359 clk_enable(inf->aclk_disp_matrix);
2360 clk_enable(inf->hclk_cpu_display);
2361 clk_enable(inf->clk);
2362 clk_enable(inf->aclk_ddr_lcdc);
2365 clk_enable(inf->dclk);
2368 clk_enable(inf->aclk);
2372 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2373 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2374 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2376 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2377 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2379 if(inf->cur_screen->standby)
2381 fbprintk(">>>>>> power on the screen! \n");
2382 inf->cur_screen->standby(0);
2385 if(inf->cur_screen != &inf->panel2_info) // open lcd pwr when output screen is lcd
2386 set_lcd_pin(g_pdev, 1);
2387 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2390 static struct suspend_info suspend_info = {
2391 .early_suspend.suspend = rk29fb_early_suspend,
2392 .early_suspend.resume = rk29fb_early_resume,
2393 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2396 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2397 static int __init rk29fb_probe (struct platform_device *pdev)
2399 struct rk29fb_inf *inf = NULL;
2400 struct resource *res = NULL;
2401 struct resource *mem = NULL;
2402 struct rk29fb_info *mach_info = NULL;
2403 struct rk29fb_screen *screen = NULL;
2404 struct win0_par* par = NULL;
2408 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2410 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2411 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2412 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2415 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2417 goto release_drvdata;
2419 memset(inf, 0, sizeof(struct rk29fb_inf));
2420 platform_set_drvdata(pdev, inf);
2422 mach_info = pdev->dev.platform_data;
2423 /* Fill screen info and set current screen */
2424 fbprintk(">> Fill screen info and set current screen \n");
2425 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2426 hdmi_get_default_resolution(&inf->panel1_info);
2428 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2430 inf->cur_screen = &inf->panel1_info;
2431 screen = inf->cur_screen;
2432 if(SCREEN_NULL==screen->type)
2434 dev_err(&pdev->dev, ">> Please select a display device! \n");
2436 goto release_drvdata;
2439 /* get virtual basic address of lcdc register */
2440 fbprintk(">> get virtual basic address of lcdc register \n");
2441 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2444 dev_err(&pdev->dev, "failed to get memory registers\n");
2446 goto release_drvdata;
2448 inf->reg_phy_base = res->start;
2449 inf->len = (res->end - res->start) + 1;
2450 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2453 dev_err(&pdev->dev, "failed to get memory region\n");
2455 goto release_drvdata;
2457 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2458 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2459 if (inf->reg_vir_base == NULL)
2461 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2463 goto release_drvdata;
2465 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2467 /* Prepare win1 info */
2468 fbprintk(">> Prepare win1 info \n");
2469 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2472 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2475 goto release_win1fb;
2478 par = (struct win0_par*)inf->fb0->par;
2479 strcpy(inf->fb0->fix.id, "fb0");
2480 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2481 inf->fb0->fix.type_aux = 0;
2482 inf->fb0->fix.xpanstep = 1;
2483 inf->fb0->fix.ypanstep = 1;
2484 inf->fb0->fix.ywrapstep = 0;
2485 inf->fb0->fix.accel = FB_ACCEL_NONE;
2486 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2487 inf->fb0->fix.smem_len = 0;
2488 inf->fb0->fix.line_length = 0;
2489 inf->fb0->fix.smem_start = 0;
2491 inf->fb0->var.xres = screen->x_res;
2492 inf->fb0->var.yres = screen->y_res;
2493 inf->fb0->var.bits_per_pixel = 16;
2494 inf->fb0_color_deepth = 0;
2495 inf->fb0->var.xres_virtual = screen->x_res;
2496 inf->fb0->var.yres_virtual = screen->y_res;
2497 inf->fb0->var.width = screen->width;
2498 inf->fb0->var.height = screen->height;
2499 inf->fb0->var.pixclock = screen->pixclock;
2500 inf->fb0->var.left_margin = screen->left_margin;
2501 inf->fb0->var.right_margin = screen->right_margin;
2502 inf->fb0->var.upper_margin = screen->upper_margin;
2503 inf->fb0->var.lower_margin = screen->lower_margin;
2504 inf->fb0->var.vsync_len = screen->vsync_len;
2505 inf->fb0->var.hsync_len = screen->hsync_len;
2506 inf->fb0->var.red = def_rgb_16.red;
2507 inf->fb0->var.green = def_rgb_16.green;
2508 inf->fb0->var.blue = def_rgb_16.blue;
2509 inf->fb0->var.transp = def_rgb_16.transp;
2511 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2512 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2513 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2514 inf->fb0->var.accel_flags = 0;
2515 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2517 inf->fb0->fbops = &fb0_ops;
2518 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2519 inf->fb0->pseudo_palette = par->pseudo_pal;
2520 inf->fb0->screen_base = 0;
2522 memset(par, 0, sizeof(struct win0_par));
2524 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2528 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2530 /* alloc win1 buf */
2531 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2534 dev_err(&pdev->dev, "failed to get win1 memory \n");
2536 goto release_win1fb;
2538 inf->fb0->fix.smem_start = res->start;
2539 inf->fb0->fix.smem_len = res->end - res->start + 1;
2540 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2541 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2543 #ifdef CONFIG_FB_WORK_IPP
2544 /* alloc win1 ipp buf */
2545 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2548 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2550 goto release_win1fb;
2552 inf->fb0->fix.mmio_start = res->start;
2553 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2556 /* Prepare win0 info */
2557 fbprintk(">> Prepare win0 info \n");
2558 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2561 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2564 goto release_win0fb;
2567 par = (struct win0_par*)inf->fb1->par;
2569 strcpy(inf->fb1->fix.id, "fb1");
2570 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2571 inf->fb1->fix.type_aux = 0;
2572 inf->fb1->fix.xpanstep = 1;
2573 inf->fb1->fix.ypanstep = 1;
2574 inf->fb1->fix.ywrapstep = 0;
2575 inf->fb1->fix.accel = FB_ACCEL_NONE;
2576 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2577 inf->fb1->fix.smem_len = 0;
2578 inf->fb1->fix.line_length = 0;
2579 inf->fb1->fix.smem_start = 0;
2581 inf->fb1->var.xres = screen->x_res;
2582 inf->fb1->var.yres = screen->y_res;
2583 inf->fb1->var.bits_per_pixel = 16;
2584 inf->fb1->var.xres_virtual = screen->x_res;
2585 inf->fb1->var.yres_virtual = screen->y_res;
2586 inf->fb1->var.width = screen->width;
2587 inf->fb1->var.height = screen->height;
2588 inf->fb1->var.pixclock = screen->pixclock;
2589 inf->fb1->var.left_margin = screen->left_margin;
2590 inf->fb1->var.right_margin = screen->right_margin;
2591 inf->fb1->var.upper_margin = screen->upper_margin;
2592 inf->fb1->var.lower_margin = screen->lower_margin;
2593 inf->fb1->var.vsync_len = screen->vsync_len;
2594 inf->fb1->var.hsync_len = screen->hsync_len;
2595 inf->fb1->var.red = def_rgb_16.red;
2596 inf->fb1->var.green = def_rgb_16.green;
2597 inf->fb1->var.blue = def_rgb_16.blue;
2598 inf->fb1->var.transp = def_rgb_16.transp;
2600 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2601 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2602 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2603 inf->fb1->var.accel_flags = 0;
2604 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2606 inf->fb1->fbops = &fb1_ops;
2607 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2608 inf->fb1->pseudo_palette = par->pseudo_pal;
2609 inf->fb1->screen_base = 0;
2611 memset(par, 0, sizeof(struct win0_par));
2613 init_waitqueue_head(&par->wait);
2615 /* Init all lcdc and lcd before register_framebuffer. */
2616 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2617 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2618 init_lcdc(inf->fb0);
2620 #if 0 //def CONFIG_CPU_FREQ
2621 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2622 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2624 fbprintk("got clock\n");
2628 struct rk29_fb_setting_info fb_setting;
2629 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2631 fb_setting.data_num = 24;
2633 else if(OUT_P666 == inf->cur_screen->face )
2635 fb_setting.data_num = 18;
2639 fb_setting.data_num = 16;
2641 fb_setting.den_en = 1;
2642 fb_setting.vsync_en = 1;
2643 fb_setting.disp_on_en = 1;
2644 fb_setting.standby_en = 1;
2645 if( inf->cur_screen->mcu_usefmk )
2646 fb_setting.mcu_fmk_en =1;
2647 mach_info->io_init(&fb_setting);
2650 set_lcd_pin(pdev, 1);
2653 inf->mcu_usetimer = 1;
2654 inf->mcu_fmksync = 0;
2655 load_screen(inf->fb0, 1);
2657 /* Register framebuffer(fb0 & fb1) */
2658 fbprintk(">> Register framebuffer(fb0) \n");
2659 ret = register_framebuffer(inf->fb0);
2662 printk(">> fb0 register_framebuffer fail!\n");
2664 goto release_win0fb;
2666 fbprintk(">> Register framebuffer(fb1) \n");
2668 ret = register_framebuffer(inf->fb1);
2671 printk(">> fb1 register_framebuffer fail!\n");
2673 goto unregister_win1fb;
2676 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2679 printk(">> fb1 dsp win0 info device_create_file err\n");
2682 #ifdef CONFIG_HAS_EARLYSUSPEND
2683 suspend_info.inf = inf;
2684 register_early_suspend(&suspend_info.early_suspend);
2687 /* get and request irq */
2688 fbprintk(">> get and request irq \n");
2689 irq = platform_get_irq(pdev, 0);
2691 dev_err(&pdev->dev, "no irq for device\n");
2693 goto unregister_win1fb;
2695 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2697 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2702 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2704 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2707 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2713 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2714 fb0_set_par(inf->fb0);
2715 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2716 /* Start display and show logo on boot */
2717 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2718 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2719 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2723 printk(" %s ok\n", __FUNCTION__);
2728 free_irq(irq, pdev);
2730 unregister_framebuffer(inf->fb0);
2733 framebuffer_release(inf->fb1);
2737 fb_dealloc_cmap(&inf->fb0->cmap);
2740 framebuffer_release(inf->fb0);
2743 if(inf && inf->reg_vir_base)
2744 iounmap(inf->reg_vir_base);
2746 release_mem_region(inf->reg_phy_base, inf->len);
2749 platform_set_drvdata(pdev, NULL);
2753 static int rk29fb_remove(struct platform_device *pdev)
2755 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2756 struct fb_info *info = NULL;
2758 struct rk29fb_info *mach_info = NULL;
2761 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2764 printk("inf==0, rk29_fb_remove fail! \n");
2767 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2769 irq = platform_get_irq(pdev, 0);
2772 free_irq(irq, pdev);
2775 mach_info = pdev->dev.platform_data;
2776 if(mach_info->mcu_fmk_pin)
2778 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2781 set_lcd_pin(pdev, 0);
2785 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2787 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2790 //rk29fb_suspend(pdev, msg);
2791 // unmap memory and release framebuffer
2794 if (info->screen_base) {
2795 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2796 info->screen_base = 0;
2797 info->fix.smem_start = 0;
2798 info->fix.smem_len = 0;
2800 unregister_framebuffer(inf->fb1);
2801 framebuffer_release(inf->fb1);
2806 if (info->screen_base) {
2807 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2808 info->screen_base = 0;
2809 info->fix.smem_start = 0;
2810 info->fix.smem_len = 0;
2812 unregister_framebuffer(inf->fb0);
2813 framebuffer_release(inf->fb0);
2817 #if 0 //def CONFIG_CPU_FREQ
2818 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2825 clk_disable(inf->clk);
2831 clk_disable(inf->dclk);
2837 platform_set_drvdata(pdev, NULL);
2842 static void rk29fb_shutdown(struct platform_device *pdev)
2844 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2846 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
2848 set_lcd_pin(pdev, 0);
2849 if(!inf->in_suspend)
2851 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2852 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2853 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2855 clk_disable(inf->aclk_ddr_lcdc);
2856 clk_disable(inf->aclk_disp_matrix);
2857 clk_disable(inf->hclk_cpu_display);
2858 clk_disable(inf->clk);
2860 clk_disable(inf->dclk);
2863 clk_disable(inf->aclk);
2865 clk_disable(inf->pd_display);
2866 //pmu_set_power_domain(PD_DISPLAY, 0);
2867 inf->in_suspend = 1;
2872 static struct platform_driver rk29fb_driver = {
2873 .probe = rk29fb_probe,
2874 .remove = rk29fb_remove,
2877 .owner = THIS_MODULE,
2879 .shutdown = rk29fb_shutdown,
2882 static int __init rk29fb_init(void)
2884 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
2885 return platform_driver_register(&rk29fb_driver);
2888 static void __exit rk29fb_exit(void)
2890 platform_driver_unregister(&rk29fb_driver);
2893 fs_initcall(rk29fb_init);
2894 module_exit(rk29fb_exit);
2897 MODULE_AUTHOR(" zyw@rock-chips.com");
2898 MODULE_DESCRIPTION("Driver for rk29 fb device");
2899 MODULE_LICENSE("GPL");