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 int mcu_do_refresh(struct rk29fb_inf *inf)
270 if(inf->mcu_stopflush) return 0;
272 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
277 inf->mcu_needflush = 1;
281 // not use frame mark
282 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
284 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
286 inf->mcu_needflush = 1;
290 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
291 inf->mcu_needflush = 0;
293 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
300 void mcutimer_callback(unsigned long arg)
302 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
303 static int waitcnt = 0;
305 mod_timer(&inf->mcutimer, jiffies + HZ/10);
307 switch(inf->mcu_status)
310 inf->mcu_status = MS_MCU;
313 if(inf->mcu_usetimer) mcu_do_refresh(inf);
316 inf->mcu_status = MS_EWAITEND;
324 inf->mcu_status = MS_EEND;
328 inf->mcu_status = MS_MCU;
331 inf->mcu_status = MS_MCU;
336 int mcu_refresh(struct rk29fb_inf *inf)
338 static int mcutimer_inited = 0;
340 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
345 init_timer(&inf->mcutimer);
346 inf->mcutimer.function = mcutimer_callback;
347 inf->mcutimer.expires = jiffies + HZ/5;
348 inf->mcu_status = MS_IDLE;
349 add_timer(&inf->mcutimer);
352 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
357 int mcu_ioctl(unsigned int cmd, unsigned long arg)
359 struct rk29fb_inf *inf = NULL;
360 if(!g_pdev) return -1;
362 inf = dev_get_drvdata(&g_pdev->dev);
367 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
368 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
369 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
373 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
374 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
378 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
379 LcdWrReg(inf, REG_CFG_DONE, 0x01);
389 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
391 struct platform_device *pdev = (struct platform_device*)dev_id;
392 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
393 struct rk29fb_screen *screen;
395 if(!inf) return IRQ_HANDLED;
397 screen = inf->cur_screen;
399 if(0==screen->mcu_usefmk) {
403 if(inf->mcu_fmksync == 1)
406 inf->mcu_fmksync = 1;
407 if(inf->mcu_needflush)
409 inf->mcu_needflush = 0;
411 if(inf->cur_screen->refresh)
412 inf->cur_screen->refresh(REFRESH_PRE);
413 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
415 inf->mcu_fmksync = 0;
420 int init_lcdc(struct fb_info *info)
422 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
425 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
427 inf->clk = clk_get(NULL, "hclk_lcdc");
428 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
429 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
430 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
431 inf->pd_display = clk_get(NULL, "pd_display");
432 if ((IS_ERR(inf->clk)) ||
433 (IS_ERR(inf->aclk_ddr_lcdc)) ||
434 (IS_ERR(inf->aclk_disp_matrix)) ||
435 (IS_ERR(inf->hclk_cpu_display)) ||
436 (IS_ERR(inf->pd_display)))
438 printk(KERN_ERR "failed to get lcdc_hclk source\n");
439 return PTR_ERR(inf->clk);
441 clk_enable(inf->aclk_disp_matrix);
442 clk_enable(inf->hclk_cpu_display);
443 clk_enable(inf->clk);
444 clk_enable(inf->pd_display);
445 //pmu_set_power_domain(PD_DISPLAY, 1);
446 clk_enable(inf->aclk_ddr_lcdc);
448 // set AHB access rule and disable all windows
449 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
450 LcdWrReg(inf, SWAP_CTRL, 0);
451 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
452 LcdWrReg(inf, AXI_MS_ID, 0x54321);
454 // and mcu holdmode; and set win1 top.
455 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
456 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
458 // disable blank out, black out, tristate out, yuv2rgb bypass
459 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
460 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
461 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
462 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
465 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
466 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
468 LcdWrReg(inf, DSP_CTRL1, 0);
470 // initialize all interrupt
471 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
473 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
475 LcdWrReg(inf, INT_STATUS, clr | msk);
477 // let above to take effect
478 LcdWrReg(inf, REG_CFG_DONE, 0x01);
483 void load_screen(struct fb_info *info, bool initscreen)
486 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
487 struct rk29fb_screen *screen = inf->cur_screen;
489 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
490 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
491 u16 x_res = screen->x_res, y_res = screen->y_res;
492 u32 aclk_rate = 150000000;
495 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
499 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
501 // set the rgb or mcu
502 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
504 // set out format and mcu timing
505 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
506 if(mcu_total>31) mcu_total = 31;
507 if(mcu_total<3) mcu_total = 3;
508 mcu_rwstart = (mcu_total+1)/4 - 1;
509 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
510 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
511 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
513 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
514 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
516 LcdMskReg(inf, MCU_TIMING_CTRL,
517 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
518 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
519 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
520 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
521 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
524 // set synchronous pin polarity and data pin swap rule
525 switch (screen->face)
529 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
533 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
537 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
541 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
545 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
546 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
549 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
550 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
555 LcdMskReg(inf, DSP_CTRL0,
556 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
557 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
558 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
559 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
562 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
564 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
565 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));
567 // set horizontal & vertical out timing
568 if(SCREEN_MCU==inf->cur_screen->type)
570 right_margin = x_res/6;
573 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
574 screen->hsync_len , screen->left_margin , x_res , right_margin );
575 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
576 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
577 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
578 v_BIT12HI(screen->hsync_len + screen->left_margin));
580 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
581 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
582 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
583 v_BIT11HI(screen->vsync_len + screen->upper_margin));
585 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
586 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
588 // let above to take effect
589 LcdWrReg(inf, REG_CFG_DONE, 0x01);
591 inf->dclk = clk_get(NULL, "dclk_lcdc");
592 if (IS_ERR(inf->dclk))
594 printk(KERN_ERR "failed to get lcd dclock source\n");
597 inf->dclk_divider= clk_get(NULL, "dclk_lcdc_div");
598 if (IS_ERR(inf->dclk_divider))
600 printk(KERN_ERR "failed to get lcd clock lcdc_divider source \n");
604 if((inf->cur_screen->type == SCREEN_HDMI) || (inf->cur_screen->type == SCREEN_TVOUT)){
605 inf->dclk_parent = clk_get(NULL, "codec_pll");
606 clk_set_rate(inf->dclk_parent, 594000000);
608 inf->dclk_parent = clk_get(NULL, "general_pll");
611 if (IS_ERR(inf->dclk_parent))
613 printk(KERN_ERR "failed to get lcd dclock parent source\n");
617 inf->aclk = clk_get(NULL, "aclk_lcdc");
618 if (IS_ERR(inf->aclk))
620 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
623 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
624 if (IS_ERR(inf->dclk_parent))
626 printk(KERN_ERR "failed to get lcd dclock parent source\n");
631 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
633 if(initscreen == 0) //not init
635 clk_disable(inf->dclk);
636 clk_disable(inf->aclk);
639 clk_disable(inf->aclk_ddr_lcdc);
640 clk_disable(inf->aclk_disp_matrix);
641 clk_disable(inf->hclk_cpu_display);
643 clk_disable(inf->clk);
644 clk_set_parent(inf->dclk_divider, inf->dclk_parent);
645 clk_set_parent(inf->dclk, inf->dclk_divider);
646 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
648 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
650 ret = clk_set_rate(inf->dclk_divider, screen->pixclock);
653 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
656 if(screen->lcdc_aclk){
657 aclk_rate = screen->lcdc_aclk;
659 ret = clk_set_rate(inf->aclk, aclk_rate);
661 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
664 clk_enable(inf->aclk_ddr_lcdc);
665 clk_enable(inf->aclk_disp_matrix);
666 clk_enable(inf->hclk_cpu_display);
668 clk_enable(inf->aclk);
669 clk_enable(inf->clk);
670 clk_enable(inf->dclk);
678 #if 0 //def CONFIG_CPU_FREQ
680 * CPU clock speed change handler. We need to adjust the LCD timing
681 * parameters when the CPU clock is adjusted by the power management
684 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
687 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
689 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
690 struct rk29fb_screen *screen = inf->cur_screen;
695 case CPUFREQ_PRECHANGE:
697 case CPUFREQ_POSTCHANGE:
699 dclk_rate = screen->pixclock * 1000000;
701 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
703 clk_set_rate(inf->dclk_divider, dclk_rate);
711 static inline unsigned int chan_to_field(unsigned int chan,
712 struct fb_bitfield *bf)
715 chan >>= 16 - bf->length;
716 return chan << bf->offset;
719 static int fb_setcolreg(unsigned regno,
720 unsigned red, unsigned green, unsigned blue,
721 unsigned transp, struct fb_info *info)
724 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
726 switch (info->fix.visual) {
727 case FB_VISUAL_TRUECOLOR:
728 /* true-colour, use pseudo-palette */
730 u32 *pal = info->pseudo_palette;
731 val = chan_to_field(red, &info->var.red);
732 val |= chan_to_field(green, &info->var.green);
733 val |= chan_to_field(blue, &info->var.blue);
738 return -1; /* unknown type */
744 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
747 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
749 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
751 LcdWrReg(inf, REG_CFG_DONE, 0x01);
755 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
757 struct rk29fb_screen *screen = inf->cur_screen;
760 if (x >= 0x800 || y >= 0x800 )
762 //printk("%s: %08x,%08x \n",__func__, x, y);
763 x += (screen->left_margin + screen->hsync_len);
764 y += (screen->upper_margin + screen->vsync_len);
765 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
766 LcdWrReg(inf, REG_CFG_DONE, 0x01);
771 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
773 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
774 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
775 LcdWrReg(inf, REG_CFG_DONE, 0x01);
779 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
780 int rk29_set_cursor_img_transform(char *data)
783 char *dst = (char*)rk29_cursor_buf;
784 unsigned char dmsk = 0;
785 unsigned int op,shift,offset;
787 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
788 * clears it to transparent then combines the cursor
789 * shape plane with the colour plane to set the
791 for (y = 0; y < 32; y++)
793 for (x = 0; x < 32; x++)
800 op = (dmsk & 0x80) ? 2 : 3;
803 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
813 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
817 rk29_set_cursor_img_transform(data);
821 rk29_set_cursor_img_transform(cursor_img);
823 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
824 LcdSetRegisterBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
825 LcdWrReg(inf, REG_CFG_DONE, 0x01);
829 int rk29_set_cursor_test(struct fb_info *info)
831 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
832 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
833 rk29_set_cursor_pos(inf, 0, 0);
834 rk29_set_cursor_img(inf, 0);
835 rk29_set_cursor_en(inf, 1);
840 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
842 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
844 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
846 /* check not being asked to exceed capabilities */
848 if (cursor->image.width > 32)
851 if (cursor->image.height > 32)
854 if (cursor->image.depth > 1)
858 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
860 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
863 if (cursor->set & FB_CUR_SETPOS)
865 unsigned int x = cursor->image.dx;
866 unsigned int y = cursor->image.dy;
868 if (x >= 0x800 || y >= 0x800 )
870 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
874 if (cursor->set & FB_CUR_SETCMAP)
876 unsigned int bg_col = cursor->image.bg_color;
877 unsigned int fg_col = cursor->image.fg_color;
879 fbprintk("%s: update cmap (%08x,%08x)\n",
880 __func__, bg_col, fg_col);
882 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
883 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));
885 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
886 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));
889 if ((cursor->set & FB_CUR_SETSIZE ||
890 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
891 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
893 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
894 * clears it to transparent then combines the cursor
895 * shape plane with the colour plane to set the
898 const unsigned char *pcol = cursor->image.data;
899 const unsigned char *pmsk = cursor->mask;
901 unsigned long cursor_mem_start;
902 unsigned char dcol = 0;
903 unsigned char dmsk = 0;
906 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
907 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
909 fbprintk("%s: setting shape (%d,%d)\n",
910 __func__, cursor->image.width, cursor->image.height);
912 memset(dst, 0, CURSOR_BUF_SIZE);
914 for (y = 0; y < cursor->image.height; y++)
916 for (x = 0; x < cursor->image.width; x++)
927 op = (dcol & 1) ? 1 : 3;
928 op <<= ((x % 4) * 2);
929 *(u8*)(dst+(x/4)) |= op;
934 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
935 LcdWrReg(inf, HWC_MST, cursor_mem_start);
936 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
937 if(SCREEN_MCU == inf->cur_screen->type) {
938 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
942 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
944 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
951 static int win0_blank(int blank_mode, struct fb_info *info)
953 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
955 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
961 case FB_BLANK_UNBLANK:
962 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
965 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
968 LcdWrReg(inf, REG_CFG_DONE, 0x01);
974 static int win0_set_par(struct fb_info *info)
976 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
977 struct rk29fb_screen *screen = inf->cur_screen;
978 struct fb_var_screeninfo *var = &info->var;
979 struct fb_fix_screeninfo *fix = &info->fix;
980 struct win0_par *par = info->par;
982 u32 xact = var->xres; /* visible resolution */
983 u32 yact = var->yres;
984 u32 xvir = var->xres_virtual; /* virtual resolution */
985 u32 yvir = var->yres_virtual;
986 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
987 //u32 yact_st = var->yoffset; /* resolution */
988 u32 xpos = par->xpos;
989 u32 ypos = par->ypos;
991 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
992 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
994 u32 y_addr = 0; //user alloc buf addr y
997 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1001 if(((var->rotate == 270)||(var->rotate == 90)) && (inf->video_mode))
1003 #ifdef CONFIG_FB_ROTATE_VIDEO
1004 // if(xact > screen->x_res)
1006 xact = screen->x_res; /* visible resolution */
1007 yact = screen->y_res;
1008 xvir = screen->x_res; /* virtual resolution */
1009 yvir = screen->y_res;
1011 // xact = var->yres; /* visible resolution */
1012 // yact = var->xres;
1013 // xvir = var->yres_virtual; /* virtual resolution */
1014 // yvir = var->xres_virtual;
1016 #else //CONFIG_FB_ROTATE_VIDEO
1017 printk("LCDC not support rotate!\n");
1022 // calculate the display phy address
1023 y_addr = fix->smem_start + par->y_offset;
1024 uv_addr = fix->mmio_start + par->c_offset;
1026 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1027 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1029 switch (par->format)
1032 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1033 ScaleCbrY = CalScaleW0(yact, par->ysize);
1037 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1038 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1041 ScaleCbrX= CalScaleW0(xact, par->xsize);
1042 ScaleCbrY = CalScaleW0(yact, par->ysize);
1048 xpos += (screen->left_margin + screen->hsync_len);
1049 ypos += (screen->upper_margin + screen->vsync_len);
1051 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1052 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1054 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1056 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1057 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1058 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1059 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1060 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1061 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1066 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,
1067 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));
1070 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,
1071 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));
1074 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,
1075 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) |
1076 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1079 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,
1080 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) );
1084 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1090 static int win0_pan( struct fb_info *info )
1092 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1093 // struct fb_var_screeninfo *var0 = &info->var;
1094 struct fb_fix_screeninfo *fix0 = &info->fix;
1095 struct win0_par *par = info->par;
1096 u32 y_addr=0, uv_addr=0;
1098 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1102 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1103 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1105 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1106 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1107 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1109 // enable win0 after the win0 addr is seted
1110 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1116 static int win1_blank(int blank_mode, struct fb_info *info)
1118 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1120 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1126 case FB_BLANK_UNBLANK:
1127 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1130 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1133 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1139 static int win1_set_par(struct fb_info *info)
1141 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1142 struct fb_fix_screeninfo *fix = &info->fix;
1143 struct rk29fb_screen *screen = inf->cur_screen;
1144 struct win0_par *par = info->par;
1145 struct fb_var_screeninfo *var = &info->var;
1147 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1149 u16 xres_virtual = 0; //virtual screen size
1151 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1152 //u16 ypos_virtual = var->yoffset;
1154 u16 xpos = par->xpos; //visiable offset in panel
1155 u16 ypos = par->ypos;
1157 u8 trspmode = TRSP_CLOSE;
1160 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1162 #ifdef CONFIG_FB_SCALING_OSD
1163 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1164 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1166 addr = fix->mmio_start + par->y_offset;
1167 xres_virtual = screen->x_res; //virtual screen size
1172 addr = fix->smem_start + par->y_offset;
1173 xres_virtual = var->xres_virtual; //virtual screen size
1175 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1177 xpos += (screen->left_margin + screen->hsync_len);
1178 ypos += (screen->upper_margin + screen->vsync_len);
1180 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1182 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1183 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1185 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1187 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1188 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1190 // enable win1 color key and set the color to black(rgb=0)
1191 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1193 if(1==par->format) //rgb565
1195 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1196 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1200 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1201 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1203 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1206 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1211 static int win1_pan( struct fb_info *info )
1213 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1214 struct fb_fix_screeninfo *fix1 = &info->fix;
1215 struct win0_par *par = info->par;
1218 #ifdef CONFIG_FB_SCALING_OSD
1219 struct rk29fb_screen *screen = inf->cur_screen;
1220 struct fb_var_screeninfo *var = &info->var;
1221 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1222 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1224 addr = fix1->mmio_start + par->y_offset;
1229 addr = fix1->smem_start + par->y_offset;
1232 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1234 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1235 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1241 static int fb0_blank(int blank_mode, struct fb_info *info)
1243 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1245 if(inf->video_mode == 1)
1247 win1_blank(blank_mode, info);
1251 win0_blank(blank_mode, info);
1256 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1258 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1259 struct rk29fb_screen *screen = inf->cur_screen;
1260 u16 xpos = (var->nonstd>>8) & 0xfff;
1261 u16 ypos = (var->nonstd>>20) & 0xfff;
1262 u16 xlcd = screen->x_res;
1263 u16 ylcd = screen->y_res;
1265 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1269 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1270 0==var->xres || 0==var->yres || var->xres<16 ||
1271 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1273 printk(">>>>>> fb0_check_var fail 1!!! \n");
1274 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1275 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1276 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1280 if( (var->xoffset+var->xres)>var->xres_virtual ||
1281 (var->yoffset+var->yres)>var->yres_virtual )
1283 printk(">>>>>> fb0_check_var fail 2!!! \n");
1284 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1285 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1286 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1290 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1291 switch(var->bits_per_pixel)
1294 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1295 var->xres = (var->xres + 0x1) & (~0x1);
1296 var->xoffset = (var->xoffset) & (~0x1);
1299 var->bits_per_pixel = 32;
1307 static int fb0_set_par(struct fb_info *info)
1309 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1310 struct fb_var_screeninfo *var = &info->var;
1311 struct fb_fix_screeninfo *fix = &info->fix;
1312 struct rk29fb_screen *screen = inf->cur_screen;
1313 struct win0_par *par = info->par;
1315 u32 offset=0, smem_len=0;
1316 u16 xres_virtual = var->xres_virtual; //virtual screen size
1317 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1318 u16 ypos_virtual = var->yoffset;
1320 #ifdef CONFIG_FB_SCALING_OSD
1321 struct rk29_ipp_req ipp_req;
1325 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1329 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1330 #if !defined(CONFIG_FB_SCALING_OSD)
1331 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1334 switch(var->bits_per_pixel)
1338 //fix->line_length = 2 * xres_virtual;
1339 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1341 #ifdef CONFIG_FB_SCALING_OSD
1342 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1343 ipp_req.src0.fmt = IPP_RGB_565;
1344 ipp_req.dst0.fmt = IPP_RGB_565;
1346 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1351 fix->line_length = 4 * xres_virtual;
1352 #ifdef CONFIG_FB_SCALING_OSD
1353 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1354 ipp_req.src0.fmt = IPP_XRGB_8888;
1355 ipp_req.dst0.fmt = IPP_XRGB_8888;
1357 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1361 smem_len = fix->line_length * var->yres_virtual;
1362 //map_size = PAGE_ALIGN(smem_len);
1364 if (smem_len > fix->smem_len) // buffer need realloc
1366 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1367 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1368 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1372 par->addr_seted = 1;
1373 #if ANDROID_USE_THREE_BUFS
1374 if(0==new_frame_seted) {
1376 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1378 new_frame_seted = 0;
1381 if(inf->video_mode == 1)
1383 #ifdef CONFIG_FB_SCALING_OSD
1384 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1385 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1389 par->xsize = screen->x_res;
1390 par->ysize = screen->y_res;
1391 par->y_offset = dstoffset;
1393 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1394 ipp_req.src0.w = var->xres;
1395 ipp_req.src0.h = var->yres;
1397 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1398 ipp_req.dst0.w = screen->x_res;
1399 ipp_req.dst0.h = screen->y_res;
1401 ipp_req.src_vir_w = ipp_req.src0.w;
1402 ipp_req.dst_vir_w = ipp_req.dst0.w;
1403 ipp_req.timeout = 100;
1404 ipp_req.flag = IPP_ROT_0;
1405 ipp_do_blit(&ipp_req);
1409 par->y_offset = offset;
1410 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1411 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1412 par->xsize = var->xres; //visiable size in panel
1413 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1419 par->y_offset = offset;
1422 par->xsize = screen->x_res;
1423 par->ysize = screen->y_res;
1430 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1433 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1434 struct fb_var_screeninfo *var1 = &info->var;
1435 struct rk29fb_screen *screen = inf->cur_screen;
1436 struct win0_par *par = info->par;
1439 u16 ypos_virtual = var->yoffset;
1440 u16 xpos_virtual = var->xoffset;
1441 #ifdef CONFIG_FB_SCALING_OSD
1442 struct fb_fix_screeninfo *fix = &info->fix;
1443 struct rk29_ipp_req ipp_req;
1446 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1450 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1451 #if !defined(CONFIG_FB_SCALING_OSD)
1452 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1455 switch(var1->bits_per_pixel)
1458 var->xoffset = (var->xoffset) & (~0x1);
1459 #ifdef CONFIG_FB_SCALING_OSD
1460 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1461 ipp_req.src0.fmt = IPP_RGB_565;
1462 ipp_req.dst0.fmt = IPP_RGB_565;
1464 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1467 #ifdef CONFIG_FB_SCALING_OSD
1468 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1469 ipp_req.src0.fmt = IPP_XRGB_8888;
1470 ipp_req.dst0.fmt = IPP_XRGB_8888;
1472 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1478 if(inf->video_mode == 1)
1480 #ifdef CONFIG_FB_SCALING_OSD
1481 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1482 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1484 par->y_offset = dstoffset;
1486 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1487 ipp_req.src0.w = var->xres;
1488 ipp_req.src0.h = var->yres;
1490 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1491 ipp_req.dst0.w = screen->x_res;
1492 ipp_req.dst0.h = screen->y_res;
1494 ipp_req.src_vir_w = ipp_req.src0.w;
1495 ipp_req.dst_vir_w = ipp_req.dst0.w;
1496 ipp_req.timeout = 100;
1497 ipp_req.flag = IPP_ROT_0;
1498 ipp_do_blit(&ipp_req);
1503 par->y_offset = offset;
1508 par->y_offset = offset;
1511 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1512 #if !ANDROID_USE_THREE_BUFS
1513 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1514 if(SCREEN_MCU == inf->cur_screen->type) {
1515 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1519 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1525 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1527 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1528 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1534 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1537 inf->mcu_usetimer = 0;
1540 case FBIOPUT_16OR32:
1542 inf->fb0_color_deepth = arg;
1545 case FBIOPUT_FBPHYADD:
1546 return info->fix.smem_start;
1547 case FBIOGET_OVERLAY_STATE:
1548 return inf->video_mode;
1549 case FBIOGET_SCREEN_STATE:
1550 return inf->cur_screen->type;
1552 case FBIOPUT_SET_CURSOR_EN:
1555 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1557 rk29_set_cursor_en(inf, en);
1560 case FBIOPUT_SET_CURSOR_POS:
1562 struct fbcurpos pos;
1563 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1565 rk29_set_cursor_pos(inf, pos.x , pos.y);
1568 case FBIOPUT_SET_CURSOR_IMG:
1570 char cursor_buf[CURSOR_BUF_SIZE];
1571 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1573 rk29_set_cursor_img(inf, cursor_buf);
1576 case FBIOPUT_SET_CURSOR_CMAP:
1578 struct fb_image img;
1579 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1581 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1584 case FBIOPUT_GET_CURSOR_RESOLUTION:
1587 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1588 if(inf->fb1->var.rotate == 270) {
1589 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1590 panel_size[1] = inf->cur_screen->x_res;
1592 panel_size[0] = inf->cur_screen->x_res;
1593 panel_size[1] = inf->cur_screen->y_res;
1595 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1598 case FBIOPUT_GET_CURSOR_EN:
1600 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1601 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1610 static int fb1_blank(int blank_mode, struct fb_info *info)
1612 win0_blank(blank_mode, info);
1616 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1618 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1619 struct rk29fb_screen *screen = inf->cur_screen;
1621 u32 ScaleYRGBY=0x1000;
1622 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1623 u16 ypos = (var->nonstd>>20) & 0xfff;
1624 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1625 u16 ysize = (var->grayscale>>20) & 0xfff;
1626 u16 xlcd = screen->x_res; //size of panel
1627 u16 ylcd = screen->y_res;
1630 struct hdmi *hdmi = get_hdmi_struct(0);
1633 if((var->rotate == 270)||(var->rotate == 90)) {
1634 #ifdef CONFIG_FB_ROTATE_VIDEO
1635 xlcd = screen->y_res;
1636 ylcd = screen->x_res;
1637 #else //CONFIG_FB_ROTATE_VIDEO
1638 printk("LCDC not support rotate!\n");
1643 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1644 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1645 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1646 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1648 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1652 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1653 0==var->xres || 0==var->yres || var->xres<16 ||
1654 0==xsize || 0==ysize || xsize<16 ||
1655 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1657 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1658 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1659 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1660 var->bits_per_pixel, var->bits_per_pixel);
1664 if( (var->xoffset+var->xres)>var->xres_virtual ||
1665 (var->yoffset+var->yres)>var->yres_virtual ||
1666 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1668 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1669 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1670 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1671 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1675 switch(var->nonstd&0x0f)
1678 switch(var->bits_per_pixel)
1681 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1682 var->xres = (var->xres + 0x1) & (~0x1);
1683 var->xoffset = (var->xoffset) & (~0x1);
1686 var->bits_per_pixel = 32;
1689 var->nonstd &= ~0xc0; //not support I2P in this format
1692 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1693 var->xres = (var->xres + 0x3) & (~0x3);
1694 var->xoffset = (var->xoffset) & (~0x3);
1697 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1698 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1699 var->xres = (var->xres + 0x3) & (~0x3);
1700 var->yres = (var->yres + 0x1) & (~0x1);
1701 var->xoffset = (var->xoffset) & (~0x3);
1702 var->yoffset = (var->yoffset) & (~0x1);
1705 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1706 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1707 var->xres = (var->xres + 0x3) & (~0x3);
1708 var->yres = (var->yres + 0x1) & (~0x1);
1709 var->xoffset = (var->xoffset) & (~0x3);
1710 var->yoffset = (var->yoffset) & (~0x1);
1711 var->nonstd &= ~0xc0; //not support I2P in this format
1715 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1716 var->xres = (var->xres + 0x3) & (~0x3);
1717 var->xoffset = (var->xoffset) & (~0x3);
1718 var->nonstd &= ~0xc0; //not support I2P in this format
1721 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1725 if((var->rotate == 270)||(var->rotate == 90))
1734 ScaleYRGBY = CalScaleW0(yres, ysize);
1736 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1738 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1741 if(inf->video_mode == 1) {
1742 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1744 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1745 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1746 init_completion(&hdmi->complete);
1748 wait_for_completion_interruptible_timeout(&hdmi->complete,
1749 msecs_to_jiffies(10000));
1756 static int fb1_set_par(struct fb_info *info)
1758 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1759 struct rk29fb_screen *screen = inf->cur_screen;
1760 struct fb_var_screeninfo *var = &info->var;
1761 struct fb_fix_screeninfo *fix = &info->fix;
1762 struct win0_par *par = info->par;
1765 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1767 //u32 xact = var->xres; /* visible resolution */
1768 //u32 yact = var->yres;
1769 u32 xvir = var->xres_virtual; /* virtual resolution */
1770 u32 yvir = var->yres_virtual;
1771 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1772 u32 yact_st = var->yoffset; /* resolution */
1774 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1775 u16 ypos = (var->nonstd>>20) & 0xfff;
1776 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1777 u16 ysize = (var->grayscale>>20) & 0xfff;
1779 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1780 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1782 u8 data_format = var->nonstd&0x0f;
1783 // u32 win0_en = var->reserved[2];
1784 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1785 // u32 uv_addr = var->reserved[4];
1787 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1790 if((var->rotate == 270)||(var->rotate == 90))
1792 #if CONFIG_FB_ROTATE_VIDEO
1793 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1794 ypos = (var->nonstd>>8) & 0xfff;
1795 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1796 ysize = (var->grayscale>>8) & 0xfff;
1797 #else //CONFIG_FB_ROTATE_VIDEO
1798 printk("LCDC not support rotate!\n");
1802 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1803 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1804 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1805 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1807 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1808 switch (data_format)
1811 switch(var->bits_per_pixel)
1815 fix->line_length = 2 * xvir;
1816 par->y_offset = (yact_st*xvir + xact_st)*2;
1820 fix->line_length = 4 * xvir;
1821 par->y_offset = (yact_st*xvir + xact_st)*4;
1829 fix->line_length = xvir;
1830 cblen = crlen = (xvir*yvir)/2;
1831 par->y_offset = yact_st*xvir + xact_st;
1832 par->c_offset = yact_st*xvir + xact_st;
1836 fix->line_length = xvir;
1837 cblen = crlen = (xvir*yvir)/4;
1839 par->y_offset = yact_st*xvir + xact_st;
1840 par->c_offset = (yact_st/2)*xvir + xact_st;
1845 fix->line_length = xvir;
1846 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1847 par->c_offset = (yact_st/2)*xvir + xact_st;
1848 cblen = crlen = (xvir*yvir)/4;
1853 fix->line_length = xvir;
1854 par->y_offset = yact_st*xvir + xact_st;
1855 par->c_offset = yact_st*2*xvir + xact_st*2;
1856 cblen = crlen = (xvir*yvir);
1862 smem_len = fix->line_length * yvir + cblen + crlen;
1863 map_size = PAGE_ALIGN(smem_len);
1865 // fix->smem_start = y_addr;
1866 fix->smem_len = smem_len;
1867 // fix->mmio_start = uv_addr;
1869 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1870 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);
1872 par->format = format;
1879 if ( wq_condition2 == 0 ) {
1880 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
1887 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1889 struct win0_par *par = info->par;
1890 // enable win0 after the win0 addr is seted
1897 int fb1_open(struct fb_info *info, int user)
1899 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1900 struct win0_par *par = info->par;
1902 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1905 par->addr_seted = 0;
1906 inf->video_mode = 1;
1909 printk(">>>>>> fb1 has opened! \n");
1913 fb0_set_par(inf->fb0);
1914 fb0_pan_display(&inf->fb0->var, inf->fb0);
1915 win0_blank(FB_BLANK_POWERDOWN, info);
1920 int fb1_release(struct fb_info *info, int user)
1922 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1923 struct win0_par *par = info->par;
1924 struct fb_var_screeninfo *var0 = &info->var;
1926 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1930 inf->video_mode = 0;
1932 par->addr_seted = 0;
1933 //win0_blank(FB_BLANK_POWERDOWN, info);
1934 fb0_set_par(inf->fb0);
1935 fb0_pan_display(&inf->fb0->var, inf->fb0);
1936 win1_blank(FB_BLANK_POWERDOWN, info);
1937 // wait for lcdc stop access memory
1941 info->screen_base = 0;
1942 info->fix.smem_start = 0;
1943 info->fix.smem_len = 0;
1944 // clean the var param
1945 memset(var0, 0, sizeof(struct fb_var_screeninfo));
1951 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1953 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1954 struct win0_par *par = info->par;
1955 struct fb_fix_screeninfo *fix0 = &info->fix;
1956 struct fb_var_screeninfo *var = &info->var;
1957 void __user *argp = (void __user *)arg;
1959 #ifdef CONFIG_FB_ROTATE_VIDEO
1960 struct rk29fb_screen *screen = inf->cur_screen;
1961 struct rk29_ipp_req ipp_req;
1962 static u32 dstoffset = 0;
1966 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1967 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
1973 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
1976 if((var->rotate == 270)||(var->rotate == 90)) {
1977 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
1978 panel_size[1] = inf->panel1_info.x_res;
1980 panel_size[0] = inf->panel1_info.x_res;
1981 panel_size[1] = inf->panel1_info.y_res;
1984 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
1988 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
1991 if (copy_from_user(yuv_phy, argp, 8))
1994 fix0->smem_start = yuv_phy[0];
1995 fix0->mmio_start = yuv_phy[1];
1996 yuv_phy[0] += par->y_offset;
1997 yuv_phy[1] += par->c_offset;
1999 if((var->rotate == 270)||(var->rotate == 90))
2001 #ifdef CONFIG_FB_ROTATE_VIDEO
2002 dstoffset = (dstoffset+1)%2;
2003 ipp_req.src0.fmt = 3;
2004 ipp_req.src0.YrgbMst = yuv_phy[0];
2005 ipp_req.src0.CbrMst = yuv_phy[1];
2006 ipp_req.src0.w = var->xres;
2007 ipp_req.src0.h = var->yres;
2009 ipp_req.dst0.fmt = 3;
2010 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2011 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2012 // if(var->xres > screen->x_res)
2014 ipp_req.dst0.w = screen->x_res;
2015 ipp_req.dst0.h = screen->y_res;
2017 // ipp_req.dst0.w = var->yres;
2018 // ipp_req.dst0.h = var->xres;
2020 ipp_req.src_vir_w = ipp_req.src0.w;
2021 ipp_req.dst_vir_w = ipp_req.dst0.w;
2022 ipp_req.timeout = 100;
2023 if(var->rotate == 90)
2024 ipp_req.flag = IPP_ROT_90;
2025 else if(var->rotate == 270)
2026 ipp_req.flag = IPP_ROT_270;
2027 ipp_do_blit(&ipp_req);
2028 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2029 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2030 yuv_phy[1] = ipp_req.dst0.CbrMst;
2031 fix0->smem_start = yuv_phy[0];
2032 fix0->mmio_start = yuv_phy[1];
2033 #else //CONFIG_FB_ROTATE_VIDEO
2034 printk("LCDC not support rotate!\n");
2038 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2039 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2040 // enable win0 after the win0 par is seted
2041 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2042 par->addr_seted = 1;
2043 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2044 if(par->par_seted) {
2045 unsigned long flags;
2047 local_irq_save(flags);
2048 par->mirror.y_offset = yuv_phy[0];
2049 par->mirror.c_offset = yuv_phy[1];
2050 local_irq_restore(flags);
2053 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2058 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2059 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2060 #ifdef CONFIG_FB_ROTATE_VIDEO
2061 if(arg == 0 || arg==180)
2063 else if (arg == 90 || arg==270)
2065 #else //CONFIG_FB_ROTATE_VIDEO
2066 printk("LCDC not support rotate!\n");
2069 case FB1_IOCTL_SET_WIN0_TOP:
2070 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2071 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2072 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2080 static struct fb_ops fb1_ops = {
2081 .owner = THIS_MODULE,
2082 .fb_open = fb1_open,
2083 .fb_release = fb1_release,
2084 .fb_check_var = fb1_check_var,
2085 .fb_set_par = fb1_set_par,
2086 .fb_blank = fb1_blank,
2087 .fb_pan_display = fb1_pan_display,
2088 .fb_ioctl = fb1_ioctl,
2089 .fb_setcolreg = fb_setcolreg,
2090 .fb_fillrect = cfb_fillrect,
2091 .fb_copyarea = cfb_copyarea,
2092 .fb_imageblit = cfb_imageblit,
2095 static struct fb_ops fb0_ops = {
2096 .owner = THIS_MODULE,
2097 .fb_check_var = fb0_check_var,
2098 .fb_set_par = fb0_set_par,
2099 .fb_blank = fb0_blank,
2100 .fb_pan_display = fb0_pan_display,
2101 .fb_ioctl = fb0_ioctl,
2102 .fb_setcolreg = fb_setcolreg,
2103 .fb_fillrect = cfb_fillrect,
2104 .fb_copyarea = cfb_copyarea,
2105 .fb_imageblit = cfb_imageblit,
2106 //.fb_cursor = rk29_set_cursor,
2110 enable: 1, switch to tv or hdmi; 0, switch to lcd
2112 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2114 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2115 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2116 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2118 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2120 if(enable)inf->cur_screen = &inf->panel2_info;
2121 else inf->cur_screen = &inf->panel1_info;
2123 /* Black out, because some display device need clock to standby */
2124 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2125 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2126 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2127 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2128 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2129 wake_lock(&idlelock);
2131 wake_unlock(&idlelock);
2133 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2134 // operate the display_on pin to power down the lcd
2136 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2137 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2139 load_screen(inf->fb0, 0);
2142 fb1_set_par(inf->fb1);
2143 fb0_set_par(inf->fb0);
2144 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2145 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2149 static ssize_t dsp_win0_info_read(struct device *device,
2150 struct device_attribute *attr, char *buf)
2153 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2154 struct rk29fb_screen *screen = inf->cur_screen;
2156 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2158 fbprintk("%s\n",__FUNCTION__);
2159 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2160 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2162 xpos -= (screen->left_margin + screen->hsync_len);
2163 ypos -= (screen->upper_margin + screen->vsync_len);
2165 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2166 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2167 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2168 rk29_set_cursor_test(inf->fb0);
2170 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2173 static ssize_t dsp_win0_info_write(struct device *device,
2174 struct device_attribute *attr, const char *buf, size_t count)
2176 printk("%s\n",__FUNCTION__);
2177 printk("%s %x \n",__FUNCTION__,*buf);
2181 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2183 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2185 struct platform_device *pdev = (struct platform_device*)dev_id;
2186 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2187 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2191 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2193 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2195 if(SCREEN_MCU == inf->cur_screen->type)
2197 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2203 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2205 inf->mcu_fmksync = 1;
2206 if(inf->cur_screen->refresh)
2207 inf->cur_screen->refresh(REFRESH_END);
2208 inf->mcu_fmksync = 0;
2217 if(inf->mcu_needflush) {
2218 if(inf->cur_screen->refresh)
2219 inf->cur_screen->refresh(REFRESH_PRE);
2220 inf->mcu_needflush = 0;
2221 inf->mcu_isrcnt = 0;
2222 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2224 if(inf->cur_screen->refresh)
2225 inf->cur_screen->refresh(REFRESH_END);
2229 #if ANDROID_USE_THREE_BUFS
2230 new_frame_seted = 1;
2233 if(waitqueue_active(&par->wait)) {
2234 if (par->mirror.c_offset == 0)
2235 printk("error: no new buffer to display\n");
2237 par->done.y_offset = par->displ.y_offset;
2238 par->done.c_offset = par->displ.c_offset;
2239 par->displ.y_offset = par->mirror.y_offset;
2240 par->displ.c_offset = par->mirror.c_offset;
2241 par->mirror.y_offset = 0;
2242 par->mirror.c_offset = 0;
2244 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2245 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2246 wake_up_interruptible(&par->wait);
2251 wake_up_interruptible(&wq);
2256 #ifdef CONFIG_HAS_EARLYSUSPEND
2258 struct suspend_info {
2259 struct early_suspend early_suspend;
2260 struct rk29fb_inf *inf;
2263 static void rk29fb_early_suspend(struct early_suspend *h)
2265 struct suspend_info *info = container_of(h, struct suspend_info,
2268 struct rk29fb_inf *inf = info->inf;
2269 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2271 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2274 printk("inf==0, rk29fb_suspend fail! \n");
2278 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2279 mach_info->io_disable(); //close lcd out
2281 if(inf->cur_screen->standby)
2283 fbprintk(">>>>>> power down the screen! \n");
2284 inf->cur_screen->standby(1);
2287 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2288 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2290 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2291 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2292 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2294 if(!inf->in_suspend)
2296 fbprintk(">>>>>> diable the lcdc clk! \n");
2297 wake_lock(&idlelock);
2299 wake_unlock(&idlelock);
2300 clk_disable(inf->aclk_ddr_lcdc);
2301 clk_disable(inf->aclk_disp_matrix);
2302 clk_disable(inf->hclk_cpu_display);
2303 clk_disable(inf->clk);
2305 clk_disable(inf->dclk);
2308 clk_disable(inf->aclk);
2310 clk_disable(inf->pd_display);
2312 inf->in_suspend = 1;
2316 static void rk29fb_early_resume(struct early_suspend *h)
2318 struct suspend_info *info = container_of(h, struct suspend_info,
2321 struct rk29fb_inf *inf = info->inf;
2322 struct rk29fb_screen *screen = inf->cur_screen;
2323 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2325 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2327 printk("inf==0, rk29fb_resume fail! \n");
2333 inf->in_suspend = 0;
2334 fbprintk(">>>>>> enable the lcdc clk! \n");
2335 clk_enable(inf->pd_display);
2336 clk_enable(inf->aclk_disp_matrix);
2337 clk_enable(inf->hclk_cpu_display);
2338 clk_enable(inf->clk);
2339 clk_enable(inf->aclk_ddr_lcdc);
2342 clk_enable(inf->dclk);
2345 clk_enable(inf->aclk);
2349 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2350 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2351 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2353 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2354 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2356 if(inf->cur_screen->standby)
2358 fbprintk(">>>>>> power on the screen! \n");
2359 inf->cur_screen->standby(0);
2362 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2365 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2366 mach_info->io_enable(); //close lcd out
2370 static struct suspend_info suspend_info = {
2371 .early_suspend.suspend = rk29fb_early_suspend,
2372 .early_suspend.resume = rk29fb_early_resume,
2373 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2376 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2377 static int __init rk29fb_probe (struct platform_device *pdev)
2379 struct rk29fb_inf *inf = NULL;
2380 struct resource *res = NULL;
2381 struct resource *mem = NULL;
2382 struct rk29fb_info *mach_info = NULL;
2383 struct rk29fb_screen *screen = NULL;
2384 struct win0_par* par = NULL;
2388 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2390 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2391 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2392 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2395 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2397 goto release_drvdata;
2399 memset(inf, 0, sizeof(struct rk29fb_inf));
2400 platform_set_drvdata(pdev, inf);
2402 mach_info = pdev->dev.platform_data;
2403 /* Fill screen info and set current screen */
2404 fbprintk(">> Fill screen info and set current screen \n");
2405 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2406 hdmi_get_default_resolution(&inf->panel1_info);
2408 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2410 inf->cur_screen = &inf->panel1_info;
2411 screen = inf->cur_screen;
2412 if(SCREEN_NULL==screen->type)
2414 dev_err(&pdev->dev, ">> Please select a display device! \n");
2416 goto release_drvdata;
2419 /* get virtual basic address of lcdc register */
2420 fbprintk(">> get virtual basic address of lcdc register \n");
2421 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2424 dev_err(&pdev->dev, "failed to get memory registers\n");
2426 goto release_drvdata;
2428 inf->reg_phy_base = res->start;
2429 inf->len = (res->end - res->start) + 1;
2430 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2433 dev_err(&pdev->dev, "failed to get memory region\n");
2435 goto release_drvdata;
2437 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2438 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2439 if (inf->reg_vir_base == NULL)
2441 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2443 goto release_drvdata;
2445 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2447 /* Prepare win1 info */
2448 fbprintk(">> Prepare win1 info \n");
2449 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2452 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2455 goto release_win1fb;
2458 par = (struct win0_par*)inf->fb0->par;
2459 strcpy(inf->fb0->fix.id, "fb0");
2460 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2461 inf->fb0->fix.type_aux = 0;
2462 inf->fb0->fix.xpanstep = 1;
2463 inf->fb0->fix.ypanstep = 1;
2464 inf->fb0->fix.ywrapstep = 0;
2465 inf->fb0->fix.accel = FB_ACCEL_NONE;
2466 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2467 inf->fb0->fix.smem_len = 0;
2468 inf->fb0->fix.line_length = 0;
2469 inf->fb0->fix.smem_start = 0;
2471 inf->fb0->var.xres = screen->x_res;
2472 inf->fb0->var.yres = screen->y_res;
2473 inf->fb0->var.bits_per_pixel = 16;
2474 inf->fb0_color_deepth = 0;
2475 inf->fb0->var.xres_virtual = screen->x_res;
2476 inf->fb0->var.yres_virtual = screen->y_res;
2477 inf->fb0->var.width = screen->width;
2478 inf->fb0->var.height = screen->height;
2479 inf->fb0->var.pixclock = screen->pixclock;
2480 inf->fb0->var.left_margin = screen->left_margin;
2481 inf->fb0->var.right_margin = screen->right_margin;
2482 inf->fb0->var.upper_margin = screen->upper_margin;
2483 inf->fb0->var.lower_margin = screen->lower_margin;
2484 inf->fb0->var.vsync_len = screen->vsync_len;
2485 inf->fb0->var.hsync_len = screen->hsync_len;
2486 inf->fb0->var.red = def_rgb_16.red;
2487 inf->fb0->var.green = def_rgb_16.green;
2488 inf->fb0->var.blue = def_rgb_16.blue;
2489 inf->fb0->var.transp = def_rgb_16.transp;
2491 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2492 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2493 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2494 inf->fb0->var.accel_flags = 0;
2495 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2497 inf->fb0->fbops = &fb0_ops;
2498 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2499 inf->fb0->pseudo_palette = par->pseudo_pal;
2500 inf->fb0->screen_base = 0;
2502 memset(par, 0, sizeof(struct win0_par));
2504 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2508 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2510 /* alloc win1 buf */
2511 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2514 dev_err(&pdev->dev, "failed to get win1 memory \n");
2516 goto release_win1fb;
2518 inf->fb0->fix.smem_start = res->start;
2519 inf->fb0->fix.smem_len = res->end - res->start + 1;
2520 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2521 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2523 #ifdef CONFIG_FB_WORK_IPP
2524 /* alloc win1 ipp buf */
2525 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2528 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2530 goto release_win1fb;
2532 inf->fb0->fix.mmio_start = res->start;
2533 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2536 /* Prepare win0 info */
2537 fbprintk(">> Prepare win0 info \n");
2538 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2541 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2544 goto release_win0fb;
2547 par = (struct win0_par*)inf->fb1->par;
2549 strcpy(inf->fb1->fix.id, "fb1");
2550 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2551 inf->fb1->fix.type_aux = 0;
2552 inf->fb1->fix.xpanstep = 1;
2553 inf->fb1->fix.ypanstep = 1;
2554 inf->fb1->fix.ywrapstep = 0;
2555 inf->fb1->fix.accel = FB_ACCEL_NONE;
2556 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2557 inf->fb1->fix.smem_len = 0;
2558 inf->fb1->fix.line_length = 0;
2559 inf->fb1->fix.smem_start = 0;
2561 inf->fb1->var.xres = screen->x_res;
2562 inf->fb1->var.yres = screen->y_res;
2563 inf->fb1->var.bits_per_pixel = 16;
2564 inf->fb1->var.xres_virtual = screen->x_res;
2565 inf->fb1->var.yres_virtual = screen->y_res;
2566 inf->fb1->var.width = screen->width;
2567 inf->fb1->var.height = screen->height;
2568 inf->fb1->var.pixclock = screen->pixclock;
2569 inf->fb1->var.left_margin = screen->left_margin;
2570 inf->fb1->var.right_margin = screen->right_margin;
2571 inf->fb1->var.upper_margin = screen->upper_margin;
2572 inf->fb1->var.lower_margin = screen->lower_margin;
2573 inf->fb1->var.vsync_len = screen->vsync_len;
2574 inf->fb1->var.hsync_len = screen->hsync_len;
2575 inf->fb1->var.red = def_rgb_16.red;
2576 inf->fb1->var.green = def_rgb_16.green;
2577 inf->fb1->var.blue = def_rgb_16.blue;
2578 inf->fb1->var.transp = def_rgb_16.transp;
2580 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2581 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2582 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2583 inf->fb1->var.accel_flags = 0;
2584 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2586 inf->fb1->fbops = &fb1_ops;
2587 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2588 inf->fb1->pseudo_palette = par->pseudo_pal;
2589 inf->fb1->screen_base = 0;
2591 memset(par, 0, sizeof(struct win0_par));
2593 init_waitqueue_head(&par->wait);
2595 /* Init all lcdc and lcd before register_framebuffer. */
2596 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2597 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2598 init_lcdc(inf->fb0);
2600 #if 0 //def CONFIG_CPU_FREQ
2601 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2602 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2604 fbprintk("got clock\n");
2608 struct rk29_fb_setting_info fb_setting;
2609 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2611 fb_setting.data_num = 24;
2613 else if(OUT_P666 == inf->cur_screen->face )
2615 fb_setting.data_num = 18;
2619 fb_setting.data_num = 16;
2621 fb_setting.den_en = 1;
2622 fb_setting.vsync_en = 1;
2623 fb_setting.disp_on_en = 1;
2624 fb_setting.standby_en = 1;
2625 if( inf->cur_screen->mcu_usefmk )
2626 fb_setting.mcu_fmk_en =1;
2627 mach_info->io_init(&fb_setting);
2630 //set_lcd_pin(pdev, 1);
2633 inf->mcu_usetimer = 1;
2634 inf->mcu_fmksync = 0;
2635 load_screen(inf->fb0, 1);
2637 /* Register framebuffer(fb0 & fb1) */
2638 fbprintk(">> Register framebuffer(fb0) \n");
2639 ret = register_framebuffer(inf->fb0);
2642 printk(">> fb0 register_framebuffer fail!\n");
2644 goto release_win0fb;
2646 fbprintk(">> Register framebuffer(fb1) \n");
2648 ret = register_framebuffer(inf->fb1);
2651 printk(">> fb1 register_framebuffer fail!\n");
2653 goto unregister_win1fb;
2656 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2659 printk(">> fb1 dsp win0 info device_create_file err\n");
2662 #ifdef CONFIG_HAS_EARLYSUSPEND
2663 suspend_info.inf = inf;
2664 register_early_suspend(&suspend_info.early_suspend);
2667 /* get and request irq */
2668 fbprintk(">> get and request irq \n");
2669 irq = platform_get_irq(pdev, 0);
2671 dev_err(&pdev->dev, "no irq for device\n");
2673 goto unregister_win1fb;
2675 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2677 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2682 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2684 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2687 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2693 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2694 fb0_set_par(inf->fb0);
2695 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2696 /* Start display and show logo on boot */
2697 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2698 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2699 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2703 printk(" %s ok\n", __FUNCTION__);
2708 free_irq(irq, pdev);
2710 unregister_framebuffer(inf->fb0);
2713 framebuffer_release(inf->fb1);
2717 fb_dealloc_cmap(&inf->fb0->cmap);
2720 framebuffer_release(inf->fb0);
2723 if(inf && inf->reg_vir_base)
2724 iounmap(inf->reg_vir_base);
2726 release_mem_region(inf->reg_phy_base, inf->len);
2729 platform_set_drvdata(pdev, NULL);
2733 static int rk29fb_remove(struct platform_device *pdev)
2735 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2736 struct fb_info *info = NULL;
2738 struct rk29fb_info *mach_info = NULL;
2741 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2744 printk("inf==0, rk29_fb_remove fail! \n");
2747 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2749 irq = platform_get_irq(pdev, 0);
2752 free_irq(irq, pdev);
2755 mach_info = pdev->dev.platform_data;
2756 if(mach_info->mcu_fmk_pin)
2758 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2761 if(mach_info->io_disable)
2762 mach_info->io_disable(); //close lcd out
2766 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2768 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2771 //rk29fb_suspend(pdev, msg);
2772 // unmap memory and release framebuffer
2775 if (info->screen_base) {
2776 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2777 info->screen_base = 0;
2778 info->fix.smem_start = 0;
2779 info->fix.smem_len = 0;
2781 unregister_framebuffer(inf->fb1);
2782 framebuffer_release(inf->fb1);
2787 if (info->screen_base) {
2788 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2789 info->screen_base = 0;
2790 info->fix.smem_start = 0;
2791 info->fix.smem_len = 0;
2793 unregister_framebuffer(inf->fb0);
2794 framebuffer_release(inf->fb0);
2798 #if 0 //def CONFIG_CPU_FREQ
2799 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2806 clk_disable(inf->clk);
2812 clk_disable(inf->dclk);
2818 platform_set_drvdata(pdev, NULL);
2823 static void rk29fb_shutdown(struct platform_device *pdev)
2825 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2826 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
2828 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
2830 if(mach_info->io_disable)
2831 mach_info->io_disable(); //close lcd out
2833 if(!inf->in_suspend)
2835 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2836 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2837 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2839 clk_disable(inf->aclk_ddr_lcdc);
2840 clk_disable(inf->aclk_disp_matrix);
2841 clk_disable(inf->hclk_cpu_display);
2842 clk_disable(inf->clk);
2844 clk_disable(inf->dclk);
2847 clk_disable(inf->aclk);
2849 clk_disable(inf->pd_display);
2850 //pmu_set_power_domain(PD_DISPLAY, 0);
2851 inf->in_suspend = 1;
2856 static struct platform_driver rk29fb_driver = {
2857 .probe = rk29fb_probe,
2858 .remove = rk29fb_remove,
2861 .owner = THIS_MODULE,
2863 .shutdown = rk29fb_shutdown,
2866 static int __init rk29fb_init(void)
2868 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
2869 return platform_driver_register(&rk29fb_driver);
2872 static void __exit rk29fb_exit(void)
2874 platform_driver_unregister(&rk29fb_driver);
2877 fs_initcall(rk29fb_init);
2878 module_exit(rk29fb_exit);
2881 MODULE_AUTHOR(" zyw@rock-chips.com");
2882 MODULE_DESCRIPTION("Driver for rk29 fb device");
2883 MODULE_LICENSE("GPL");