2 * drivers/video/rk29_fb.c
4 * Copyright (C) 2010 ROCKCHIP, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
25 #include <linux/init.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/interrupt.h>
28 #include <linux/platform_device.h>
29 #include <linux/clk.h>
30 #include <linux/backlight.h>
31 #include <linux/timer.h>
32 #include <linux/time.h>
33 #include <linux/wait.h>
34 #include <linux/earlysuspend.h>
35 #include <linux/cpufreq.h>
36 #include <linux/wakelock.h>
39 #include <asm/div64.h>
40 #include <asm/uaccess.h>
48 #include <linux/completion.h>
50 #include <linux/hdmi.h>
53 #include <mach/iomux.h>
54 #include <mach/gpio.h>
55 #include <mach/board.h>
56 #include <mach/rk29_iomap.h>
58 #include <mach/rk29-ipp.h>
60 #include "./display/screen/screen.h"
62 #define ANDROID_USE_THREE_BUFS 0 //android use three buffers to accelerate UI display in rgb plane
63 #define CURSOR_BUF_SIZE 256 //RK2818 cursor need 256B buf
64 int rk29_cursor_buf[CURSOR_BUF_SIZE];
101 #define fbprintk(msg...) printk(msg);
103 #define fbprintk(msg...)
108 #define fbprintk2(msg...) printk(msg);
110 #define fbprintk2(msg...)
113 #define LcdReadBit(inf, addr, msk) ((inf->regbak.addr=inf->preg->addr)&(msk))
114 #define LcdWrReg(inf, addr, val) inf->preg->addr=inf->regbak.addr=(val)
115 #define LcdRdReg(inf, addr) (inf->preg->addr)
116 #define LcdSetBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) |= (msk))
117 #define LcdClrBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) &= ~(msk))
118 #define LcdSetRegisterBit(inf, addr, msk) inf->preg->addr=((inf->preg->addr) |= (msk))
119 #define LcdMskReg(inf, addr, msk, val) (inf->regbak.addr)&=~(msk); inf->preg->addr=(inf->regbak.addr|=(val))
122 #define IsMcuLandscape() ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
123 #define IsMcuUseFmk() ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
125 #define CalScaleW0(x, y) (((u32)x*0x1000)/y)
128 struct fb_bitfield red;
129 struct fb_bitfield green;
130 struct fb_bitfield blue;
131 struct fb_bitfield transp;
134 static struct rk29fb_rgb def_rgb_16 = {
135 red: { offset: 11, length: 5, },
136 green: { offset: 5, length: 6, },
137 blue: { offset: 0, length: 5, },
138 transp: { offset: 0, length: 0, },
142 volatile u32 y_offset;
143 volatile u32 c_offset;
151 u32 xpos; //size in panel
153 u32 xsize; //start point in panel
157 wait_queue_head_t wait;
158 struct win_set mirror;
159 struct win_set displ;
184 void __iomem *reg_vir_base; // virtual basic address of lcdc register
185 u32 reg_phy_base; // physical basic address of lcdc register
186 u32 len; // physical map length of lcdc register
190 struct clk *dclk; //lcdc dclk
191 struct clk *aclk; //lcdc share memory frequency
192 struct clk *aclk_parent; //lcdc aclk divider frequency source
193 struct clk *aclk_ddr_lcdc; //DDR LCDC AXI clock disable.
194 struct clk *aclk_disp_matrix; //DISPLAY matrix AXI clock disable.
195 struct clk *hclk_cpu_display; //CPU DISPLAY AHB bus clock disable.
196 struct clk *pd_display; // display power domain
197 unsigned long dclk_rate;
199 /* lcdc reg base address and backup reg */
204 int fb0_color_deepth;
205 /* variable used in mcu panel */
209 struct timer_list mcutimer;
215 /* external memery */
216 char __iomem *screen_base2;
218 unsigned long smem_start2;
220 char __iomem *cursor_base; /* cursor Virtual address*/
221 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
222 unsigned long cursor_start;
224 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
225 struct rk29fb_screen panel2_info; // 2nd panel
226 struct rk29fb_screen *cur_screen;
227 #if 0 //def CONFIG_CPU_FREQ
228 struct notifier_block freq_transition;
233 typedef enum _TRSP_MODE
245 struct platform_device *g_pdev = NULL;
246 //static int win1fb_set_par(struct fb_info *info);
249 #define CHK_SUSPEND(inf) \
250 if(inf->in_suspend) { \
251 fbprintk(">>>>>> fb is in suspend! return! \n"); \
255 #define CHK_SUSPEND(inf)
258 static DECLARE_WAIT_QUEUE_HEAD(wq);
259 static int wq_condition = 0;
260 static int wq_condition2 = 0;
261 #if ANDROID_USE_THREE_BUFS
262 static int new_frame_seted = 1;
264 static struct wake_lock idlelock; /* only for fb */
265 #ifdef CONFIG_FB_ROTATE_VIDEO
267 static bool has_set_rotate;
268 static u32 last_yuv_phy[2] = {0,0};
271 int mcu_do_refresh(struct rk29fb_inf *inf)
273 if(inf->mcu_stopflush) return 0;
275 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
280 inf->mcu_needflush = 1;
284 // not use frame mark
285 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
287 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
289 inf->mcu_needflush = 1;
293 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
294 inf->mcu_needflush = 0;
296 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
303 void mcutimer_callback(unsigned long arg)
305 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
306 static int waitcnt = 0;
308 mod_timer(&inf->mcutimer, jiffies + HZ/10);
310 switch(inf->mcu_status)
313 inf->mcu_status = MS_MCU;
316 if(inf->mcu_usetimer) mcu_do_refresh(inf);
319 inf->mcu_status = MS_EWAITEND;
327 inf->mcu_status = MS_EEND;
331 inf->mcu_status = MS_MCU;
334 inf->mcu_status = MS_MCU;
339 int mcu_refresh(struct rk29fb_inf *inf)
341 static int mcutimer_inited = 0;
343 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
348 init_timer(&inf->mcutimer);
349 inf->mcutimer.function = mcutimer_callback;
350 inf->mcutimer.expires = jiffies + HZ/5;
351 inf->mcu_status = MS_IDLE;
352 add_timer(&inf->mcutimer);
355 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
360 int mcu_ioctl(unsigned int cmd, unsigned long arg)
362 struct rk29fb_inf *inf = NULL;
363 if(!g_pdev) return -1;
365 inf = dev_get_drvdata(&g_pdev->dev);
370 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
371 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
372 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
376 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
377 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
381 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
382 LcdWrReg(inf, REG_CFG_DONE, 0x01);
392 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
394 struct platform_device *pdev = (struct platform_device*)dev_id;
395 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
396 struct rk29fb_screen *screen;
398 if(!inf) return IRQ_HANDLED;
400 screen = inf->cur_screen;
402 if(0==screen->mcu_usefmk) {
406 if(inf->mcu_fmksync == 1)
409 inf->mcu_fmksync = 1;
410 if(inf->mcu_needflush)
412 inf->mcu_needflush = 0;
414 if(inf->cur_screen->refresh)
415 inf->cur_screen->refresh(REFRESH_PRE);
416 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
418 inf->mcu_fmksync = 0;
423 int init_lcdc(struct fb_info *info)
425 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
428 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
430 inf->clk = clk_get(NULL, "hclk_lcdc");
431 inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
432 inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
433 inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
434 inf->pd_display = clk_get(NULL, "pd_display");
435 if ((IS_ERR(inf->clk)) ||
436 (IS_ERR(inf->aclk_ddr_lcdc)) ||
437 (IS_ERR(inf->aclk_disp_matrix)) ||
438 (IS_ERR(inf->hclk_cpu_display)) ||
439 (IS_ERR(inf->pd_display)))
441 printk(KERN_ERR "failed to get lcdc_hclk source\n");
442 return PTR_ERR(inf->clk);
444 clk_enable(inf->aclk_disp_matrix);
445 clk_enable(inf->hclk_cpu_display);
446 clk_enable(inf->clk);
447 clk_enable(inf->pd_display);
448 //pmu_set_power_domain(PD_DISPLAY, 1);
449 clk_enable(inf->aclk_ddr_lcdc);
451 // set AHB access rule and disable all windows
452 LcdWrReg(inf, SYS_CONFIG, 0x60000000);
453 LcdWrReg(inf, SWAP_CTRL, 0);
454 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
455 LcdWrReg(inf, AXI_MS_ID, 0x54321);
457 // and mcu holdmode; and set win1 top.
458 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
459 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
461 // disable blank out, black out, tristate out, yuv2rgb bypass
462 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
463 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
464 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
465 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
468 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
469 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
471 LcdWrReg(inf, DSP_CTRL1, 0);
473 // initialize all interrupt
474 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
476 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
478 LcdWrReg(inf, INT_STATUS, clr | msk);
480 // let above to take effect
481 LcdWrReg(inf, REG_CFG_DONE, 0x01);
486 void load_screen(struct fb_info *info, bool initscreen)
489 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
490 struct rk29fb_screen *screen = inf->cur_screen;
492 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
493 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
494 u16 x_res = screen->x_res, y_res = screen->y_res;
495 u32 aclk_rate = 150000000;
498 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
502 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
504 // set the rgb or mcu
505 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
507 // set out format and mcu timing
508 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
509 if(mcu_total>31) mcu_total = 31;
510 if(mcu_total<3) mcu_total = 3;
511 mcu_rwstart = (mcu_total+1)/4 - 1;
512 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
513 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
514 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
516 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
517 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
519 LcdMskReg(inf, MCU_TIMING_CTRL,
520 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
521 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
522 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
523 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
524 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
527 // set synchronous pin polarity and data pin swap rule
528 switch (screen->face)
532 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
536 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
540 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
544 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
548 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
549 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
552 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
553 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
558 LcdMskReg(inf, DSP_CTRL0,
559 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
560 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
561 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
562 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
565 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
567 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
568 v_OUTPUT_RB_SWAP(screen->swap_rb) | v_OUTPUT_RG_SWAP(screen->swap_rg) | v_DELTA_SWAP(screen->swap_delta) | v_DUMMY_SWAP(screen->swap_dumy));
570 // set horizontal & vertical out timing
571 if(SCREEN_MCU==inf->cur_screen->type)
573 right_margin = x_res/6;
576 fbprintk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
577 screen->hsync_len , screen->left_margin , x_res , right_margin );
578 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
579 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
580 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
581 v_BIT12HI(screen->hsync_len + screen->left_margin));
583 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
584 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
585 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
586 v_BIT11HI(screen->vsync_len + screen->upper_margin));
588 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
589 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
591 // let above to take effect
592 LcdWrReg(inf, REG_CFG_DONE, 0x01);
594 inf->dclk = clk_get(NULL, "dclk_lcdc");
595 if (IS_ERR(inf->dclk))
597 printk(KERN_ERR "failed to get lcd dclock source\n");
601 inf->aclk = clk_get(NULL, "aclk_lcdc");
602 if (IS_ERR(inf->aclk))
604 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
607 inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
608 if (IS_ERR(inf->aclk_parent))
610 printk(KERN_ERR "failed to get lcd clock parent source\n");
615 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
617 if(initscreen == 0) //not init
619 clk_disable(inf->dclk);
620 clk_disable(inf->aclk);
623 clk_disable(inf->aclk_ddr_lcdc);
624 clk_disable(inf->aclk_disp_matrix);
625 clk_disable(inf->hclk_cpu_display);
627 clk_disable(inf->clk);
628 ret = clk_set_parent(inf->aclk, inf->aclk_parent);
630 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
632 ret = clk_set_rate(inf->dclk, screen->pixclock);
635 printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
638 if(screen->lcdc_aclk){
639 aclk_rate = screen->lcdc_aclk;
641 ret = clk_set_rate(inf->aclk, aclk_rate);
643 printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
646 clk_enable(inf->aclk_ddr_lcdc);
647 clk_enable(inf->aclk_disp_matrix);
648 clk_enable(inf->hclk_cpu_display);
650 clk_enable(inf->aclk);
651 clk_enable(inf->clk);
652 clk_enable(inf->dclk);
660 #if 0 //def CONFIG_CPU_FREQ
662 * CPU clock speed change handler. We need to adjust the LCD timing
663 * parameters when the CPU clock is adjusted by the power management
666 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
669 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
671 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
672 struct rk29fb_screen *screen = inf->cur_screen;
677 case CPUFREQ_PRECHANGE:
679 case CPUFREQ_POSTCHANGE:
681 dclk_rate = screen->pixclock * 1000000;
683 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
685 clk_set_rate(inf->dclk_divider, dclk_rate);
693 static inline unsigned int chan_to_field(unsigned int chan,
694 struct fb_bitfield *bf)
697 chan >>= 16 - bf->length;
698 return chan << bf->offset;
701 static int fb_setcolreg(unsigned regno,
702 unsigned red, unsigned green, unsigned blue,
703 unsigned transp, struct fb_info *info)
706 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
708 switch (info->fix.visual) {
709 case FB_VISUAL_TRUECOLOR:
710 /* true-colour, use pseudo-palette */
712 u32 *pal = info->pseudo_palette;
713 val = chan_to_field(red, &info->var.red);
714 val |= chan_to_field(green, &info->var.green);
715 val |= chan_to_field(blue, &info->var.blue);
720 return -1; /* unknown type */
726 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
729 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
731 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
733 LcdWrReg(inf, REG_CFG_DONE, 0x01);
737 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
739 struct rk29fb_screen *screen = inf->cur_screen;
742 if (x >= 0x800 || y >= 0x800 )
744 //printk("%s: %08x,%08x \n",__func__, x, y);
745 x += (screen->left_margin + screen->hsync_len);
746 y += (screen->upper_margin + screen->vsync_len);
747 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
748 LcdWrReg(inf, REG_CFG_DONE, 0x01);
753 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
755 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
756 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
757 LcdWrReg(inf, REG_CFG_DONE, 0x01);
761 #define RK29_CURSOR_WRITE_BIT(addr,mask,value) (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
762 int rk29_set_cursor_img_transform(char *data)
765 char *dst = (char*)rk29_cursor_buf;
766 unsigned char dmsk = 0;
767 unsigned int op,shift,offset;
769 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
770 * clears it to transparent then combines the cursor
771 * shape plane with the colour plane to set the
773 for (y = 0; y < 32; y++)
775 for (x = 0; x < 32; x++)
782 op = (dmsk & 0x80) ? 2 : 3;
785 RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
795 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
799 rk29_set_cursor_img_transform(data);
803 rk29_set_cursor_img_transform(cursor_img);
805 LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
806 LcdSetRegisterBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
807 LcdWrReg(inf, REG_CFG_DONE, 0x01);
811 int rk29_set_cursor_test(struct fb_info *info)
813 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
814 rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
815 rk29_set_cursor_pos(inf, 0, 0);
816 rk29_set_cursor_img(inf, 0);
817 rk29_set_cursor_en(inf, 1);
822 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
824 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
826 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
828 /* check not being asked to exceed capabilities */
830 if (cursor->image.width > 32)
833 if (cursor->image.height > 32)
836 if (cursor->image.depth > 1)
840 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
842 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
845 if (cursor->set & FB_CUR_SETPOS)
847 unsigned int x = cursor->image.dx;
848 unsigned int y = cursor->image.dy;
850 if (x >= 0x800 || y >= 0x800 )
852 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
856 if (cursor->set & FB_CUR_SETCMAP)
858 unsigned int bg_col = cursor->image.bg_color;
859 unsigned int fg_col = cursor->image.fg_color;
861 fbprintk("%s: update cmap (%08x,%08x)\n",
862 __func__, bg_col, fg_col);
864 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
865 v_HWC_R(info->cmap.red[bg_col]>>8) | v_HWC_G(info->cmap.green[bg_col]>>8) | v_HWC_B(info->cmap.blue[bg_col]>>8));
867 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
868 v_HWC_R(info->cmap.red[fg_col]>>8) | v_HWC_G(info->cmap.green[fg_col]>>8) | v_HWC_B(info->cmap.blue[fg_col]>>8));
871 if ((cursor->set & FB_CUR_SETSIZE ||
872 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
873 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
875 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
876 * clears it to transparent then combines the cursor
877 * shape plane with the colour plane to set the
880 const unsigned char *pcol = cursor->image.data;
881 const unsigned char *pmsk = cursor->mask;
883 unsigned long cursor_mem_start;
884 unsigned char dcol = 0;
885 unsigned char dmsk = 0;
888 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
889 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
891 fbprintk("%s: setting shape (%d,%d)\n",
892 __func__, cursor->image.width, cursor->image.height);
894 memset(dst, 0, CURSOR_BUF_SIZE);
896 for (y = 0; y < cursor->image.height; y++)
898 for (x = 0; x < cursor->image.width; x++)
909 op = (dcol & 1) ? 1 : 3;
910 op <<= ((x % 4) * 2);
911 *(u8*)(dst+(x/4)) |= op;
916 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
917 LcdWrReg(inf, HWC_MST, cursor_mem_start);
918 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
919 if(SCREEN_MCU == inf->cur_screen->type) {
920 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
924 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
926 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
933 static int win0_blank(int blank_mode, struct fb_info *info)
935 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
937 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
943 case FB_BLANK_UNBLANK:
944 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
947 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
950 LcdWrReg(inf, REG_CFG_DONE, 0x01);
956 static int win0_set_par(struct fb_info *info)
958 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
959 struct rk29fb_screen *screen = inf->cur_screen;
960 struct fb_var_screeninfo *var = &info->var;
961 struct fb_fix_screeninfo *fix = &info->fix;
962 struct win0_par *par = info->par;
964 u32 xact = var->xres; /* visible resolution */
965 u32 yact = var->yres;
966 u32 xvir = var->xres_virtual; /* virtual resolution */
967 u32 yvir = var->yres_virtual;
968 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
969 //u32 yact_st = var->yoffset; /* resolution */
970 u32 xpos = par->xpos;
971 u32 ypos = par->ypos;
973 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
974 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
976 u32 y_addr = 0; //user alloc buf addr y
979 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
983 if(((var->rotate == 270)||(var->rotate == 90)) && (inf->video_mode))
985 #ifdef CONFIG_FB_ROTATE_VIDEO
986 // if(xact > screen->x_res)
988 xact = screen->x_res; /* visible resolution */
989 yact = screen->y_res;
990 xvir = screen->x_res; /* virtual resolution */
991 yvir = screen->y_res;
993 // xact = var->yres; /* visible resolution */
995 // xvir = var->yres_virtual; /* virtual resolution */
996 // yvir = var->xres_virtual;
998 #else //CONFIG_FB_ROTATE_VIDEO
999 printk("LCDC not support rotate!\n");
1004 // calculate the display phy address
1005 y_addr = fix->smem_start + par->y_offset;
1006 uv_addr = fix->mmio_start + par->c_offset;
1008 ScaleYrgbX = CalScaleW0(xact, par->xsize);
1009 ScaleYrgbY = CalScaleW0(yact, par->ysize);
1011 switch (par->format)
1014 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1015 ScaleCbrY = CalScaleW0(yact, par->ysize);
1019 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1020 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
1023 ScaleCbrX= CalScaleW0(xact, par->xsize);
1024 ScaleCbrY = CalScaleW0(yact, par->ysize);
1030 xpos += (screen->left_margin + screen->hsync_len);
1031 ypos += (screen->upper_margin + screen->vsync_len);
1033 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1034 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1036 LcdMskReg(inf, SYS_CONFIG, m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1038 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1039 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1040 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1041 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1042 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1043 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1048 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1049 v_W0_YRGB_8_SWAP(1) | v_W0_YRGB_16_SWAP(1) | v_W0_YRGB_R_SHIFT_SWAP(1) | v_W0_565_RB_SWAP(0) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0));
1052 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1053 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(0) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0));
1056 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1057 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(0) |
1058 v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1061 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1062 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(0) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0) );
1066 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1072 static int win0_pan( struct fb_info *info )
1074 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1075 // struct fb_var_screeninfo *var0 = &info->var;
1076 struct fb_fix_screeninfo *fix0 = &info->fix;
1077 struct win0_par *par = info->par;
1078 u32 y_addr=0, uv_addr=0;
1080 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1084 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1085 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1087 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1088 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1089 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1091 // enable win0 after the win0 addr is seted
1092 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1098 static int win1_blank(int blank_mode, struct fb_info *info)
1100 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1102 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1108 case FB_BLANK_UNBLANK:
1109 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1112 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1115 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1121 static int win1_set_par(struct fb_info *info)
1123 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1124 struct fb_fix_screeninfo *fix = &info->fix;
1125 struct rk29fb_screen *screen = inf->cur_screen;
1126 struct win0_par *par = info->par;
1127 struct fb_var_screeninfo *var = &info->var;
1129 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1131 u16 xres_virtual = 0; //virtual screen size
1133 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1134 //u16 ypos_virtual = var->yoffset;
1136 u16 xpos = par->xpos; //visiable offset in panel
1137 u16 ypos = par->ypos;
1139 u8 trspmode = TRSP_CLOSE;
1142 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1144 #ifdef CONFIG_FB_SCALING_OSD
1145 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1146 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1148 addr = fix->mmio_start + par->y_offset;
1149 xres_virtual = screen->x_res; //virtual screen size
1154 addr = fix->smem_start + par->y_offset;
1155 xres_virtual = var->xres_virtual; //virtual screen size
1157 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1159 xpos += (screen->left_margin + screen->hsync_len);
1160 ypos += (screen->upper_margin + screen->vsync_len);
1162 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1164 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1165 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1167 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1169 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1170 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1172 // enable win1 color key and set the color to black(rgb=0)
1173 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1175 if(1==par->format) //rgb565
1177 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1178 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1182 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1183 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1185 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1188 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1193 static int win1_pan( struct fb_info *info )
1195 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1196 struct fb_fix_screeninfo *fix1 = &info->fix;
1197 struct win0_par *par = info->par;
1200 #ifdef CONFIG_FB_SCALING_OSD
1201 struct rk29fb_screen *screen = inf->cur_screen;
1202 struct fb_var_screeninfo *var = &info->var;
1203 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1204 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1206 addr = fix1->mmio_start + par->y_offset;
1211 addr = fix1->smem_start + par->y_offset;
1214 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1216 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1217 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1223 static int fb0_blank(int blank_mode, struct fb_info *info)
1225 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1227 if(inf->video_mode == 1)
1229 win1_blank(blank_mode, info);
1233 win0_blank(blank_mode, info);
1238 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1240 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1241 struct rk29fb_screen *screen = inf->cur_screen;
1242 u16 xpos = (var->nonstd>>8) & 0xfff;
1243 u16 ypos = (var->nonstd>>20) & 0xfff;
1244 u16 xlcd = screen->x_res;
1245 u16 ylcd = screen->y_res;
1247 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1251 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1252 0==var->xres || 0==var->yres || var->xres<16 ||
1253 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1255 printk(">>>>>> fb0_check_var fail 1!!! \n");
1256 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1257 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1258 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1262 if( (var->xoffset+var->xres)>var->xres_virtual ||
1263 (var->yoffset+var->yres)>var->yres_virtual )
1265 printk(">>>>>> fb0_check_var fail 2!!! \n");
1266 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1267 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1268 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1272 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1273 switch(var->bits_per_pixel)
1276 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1277 var->xres = (var->xres + 0x1) & (~0x1);
1278 var->xoffset = (var->xoffset) & (~0x1);
1281 var->bits_per_pixel = 32;
1289 static int fb0_set_par(struct fb_info *info)
1291 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1292 struct fb_var_screeninfo *var = &info->var;
1293 struct fb_fix_screeninfo *fix = &info->fix;
1294 struct rk29fb_screen *screen = inf->cur_screen;
1295 struct win0_par *par = info->par;
1297 u32 offset=0, smem_len=0;
1298 u16 xres_virtual = var->xres_virtual; //virtual screen size
1299 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1300 u16 ypos_virtual = var->yoffset;
1302 #ifdef CONFIG_FB_SCALING_OSD
1303 struct rk29_ipp_req ipp_req;
1307 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1311 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1312 #if !defined(CONFIG_FB_SCALING_OSD)
1313 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1316 switch(var->bits_per_pixel)
1320 //fix->line_length = 2 * xres_virtual;
1321 fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual; //32bit and 16bit change
1323 #ifdef CONFIG_FB_SCALING_OSD
1324 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1325 ipp_req.src0.fmt = IPP_RGB_565;
1326 ipp_req.dst0.fmt = IPP_RGB_565;
1328 offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1333 fix->line_length = 4 * xres_virtual;
1334 #ifdef CONFIG_FB_SCALING_OSD
1335 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1336 ipp_req.src0.fmt = IPP_XRGB_8888;
1337 ipp_req.dst0.fmt = IPP_XRGB_8888;
1339 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1343 smem_len = fix->line_length * var->yres_virtual;
1344 //map_size = PAGE_ALIGN(smem_len);
1346 if (smem_len > fix->smem_len) // buffer need realloc
1348 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1349 printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1350 printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1354 par->addr_seted = 1;
1355 #if ANDROID_USE_THREE_BUFS
1356 if(0==new_frame_seted) {
1358 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1360 new_frame_seted = 0;
1363 if(inf->video_mode == 1)
1365 #ifdef CONFIG_FB_SCALING_OSD
1366 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1367 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1371 par->xsize = screen->x_res;
1372 par->ysize = screen->y_res;
1373 par->y_offset = dstoffset;
1375 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1376 ipp_req.src0.w = var->xres;
1377 ipp_req.src0.h = var->yres;
1379 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1380 ipp_req.dst0.w = screen->x_res;
1381 ipp_req.dst0.h = screen->y_res;
1383 ipp_req.src_vir_w = ipp_req.src0.w;
1384 ipp_req.dst_vir_w = ipp_req.dst0.w;
1385 ipp_req.timeout = 100;
1386 ipp_req.flag = IPP_ROT_0;
1387 ipp_do_blit(&ipp_req);
1391 par->y_offset = offset;
1392 par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0; //visiable offset in panel
1393 par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1394 par->xsize = var->xres; //visiable size in panel
1395 par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1401 par->y_offset = offset;
1404 par->xsize = screen->x_res;
1405 par->ysize = screen->y_res;
1412 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1415 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1416 struct fb_var_screeninfo *var1 = &info->var;
1417 struct rk29fb_screen *screen = inf->cur_screen;
1418 struct win0_par *par = info->par;
1421 u16 ypos_virtual = var->yoffset;
1422 u16 xpos_virtual = var->xoffset;
1423 #ifdef CONFIG_FB_SCALING_OSD
1424 struct fb_fix_screeninfo *fix = &info->fix;
1425 struct rk29_ipp_req ipp_req;
1428 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1432 if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1433 #if !defined(CONFIG_FB_SCALING_OSD)
1434 if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1437 switch(var1->bits_per_pixel)
1440 var->xoffset = (var->xoffset) & (~0x1);
1441 #ifdef CONFIG_FB_SCALING_OSD
1442 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1443 ipp_req.src0.fmt = IPP_RGB_565;
1444 ipp_req.dst0.fmt = IPP_RGB_565;
1446 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1449 #ifdef CONFIG_FB_SCALING_OSD
1450 dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1451 ipp_req.src0.fmt = IPP_XRGB_8888;
1452 ipp_req.dst0.fmt = IPP_XRGB_8888;
1454 offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1460 if(inf->video_mode == 1)
1462 #ifdef CONFIG_FB_SCALING_OSD
1463 if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1464 && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1466 par->y_offset = dstoffset;
1468 ipp_req.src0.YrgbMst = fix->smem_start + offset;
1469 ipp_req.src0.w = var->xres;
1470 ipp_req.src0.h = var->yres;
1472 ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1473 ipp_req.dst0.w = screen->x_res;
1474 ipp_req.dst0.h = screen->y_res;
1476 ipp_req.src_vir_w = ipp_req.src0.w;
1477 ipp_req.dst_vir_w = ipp_req.dst0.w;
1478 ipp_req.timeout = 100;
1479 ipp_req.flag = IPP_ROT_0;
1480 ipp_do_blit(&ipp_req);
1485 par->y_offset = offset;
1490 par->y_offset = offset;
1493 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1494 #if !ANDROID_USE_THREE_BUFS
1495 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1496 if(SCREEN_MCU == inf->cur_screen->type) {
1497 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1501 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1507 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1509 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1510 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1516 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1519 inf->mcu_usetimer = 0;
1522 case FBIOPUT_16OR32:
1524 inf->fb0_color_deepth = arg;
1527 case FBIOPUT_FBPHYADD:
1528 return info->fix.smem_start;
1529 case FBIOGET_OVERLAY_STATE:
1530 return inf->video_mode;
1531 case FBIOGET_SCREEN_STATE:
1532 return inf->cur_screen->type;
1534 case FBIOPUT_SET_CURSOR_EN:
1537 if(copy_from_user(&en, (void*)arg, sizeof(int)))
1539 rk29_set_cursor_en(inf, en);
1542 case FBIOPUT_SET_CURSOR_POS:
1544 struct fbcurpos pos;
1545 if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1547 rk29_set_cursor_pos(inf, pos.x , pos.y);
1550 case FBIOPUT_SET_CURSOR_IMG:
1552 char cursor_buf[CURSOR_BUF_SIZE];
1553 if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1555 rk29_set_cursor_img(inf, cursor_buf);
1558 case FBIOPUT_SET_CURSOR_CMAP:
1560 struct fb_image img;
1561 if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1563 rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1566 case FBIOPUT_GET_CURSOR_RESOLUTION:
1569 //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1570 if(inf->fb1->var.rotate == 270) {
1571 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1572 panel_size[1] = inf->cur_screen->x_res;
1574 panel_size[0] = inf->cur_screen->x_res;
1575 panel_size[1] = inf->cur_screen->y_res;
1577 if(copy_to_user((void*)arg, panel_size, 8)) return -EFAULT;
1580 case FBIOPUT_GET_CURSOR_EN:
1582 u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1583 if(copy_to_user((void*)arg, &en, 4)) return -EFAULT;
1592 static int fb1_blank(int blank_mode, struct fb_info *info)
1594 win0_blank(blank_mode, info);
1598 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1600 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1601 struct rk29fb_screen *screen = inf->cur_screen;
1603 u32 ScaleYRGBY=0x1000;
1604 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1605 u16 ypos = (var->nonstd>>20) & 0xfff;
1606 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1607 u16 ysize = (var->grayscale>>20) & 0xfff;
1608 u16 xlcd = screen->x_res; //size of panel
1609 u16 ylcd = screen->y_res;
1612 struct hdmi *hdmi = get_hdmi_struct(0);
1615 if((var->rotate == 270)||(var->rotate == 90)) {
1616 #ifdef CONFIG_FB_ROTATE_VIDEO
1617 xlcd = screen->y_res;
1618 ylcd = screen->x_res;
1619 #else //CONFIG_FB_ROTATE_VIDEO
1620 printk("LCDC not support rotate!\n");
1625 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1626 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1627 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1628 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1630 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1634 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1635 0==var->xres || 0==var->yres || var->xres<16 ||
1636 0==xsize || 0==ysize || xsize<16 ||
1637 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1639 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1640 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1641 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1642 var->bits_per_pixel, var->bits_per_pixel);
1646 if( (var->xoffset+var->xres)>var->xres_virtual ||
1647 (var->yoffset+var->yres)>var->yres_virtual ||
1648 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1650 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1651 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1652 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1653 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1657 switch(var->nonstd&0x0f)
1660 switch(var->bits_per_pixel)
1663 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1664 var->xres = (var->xres + 0x1) & (~0x1);
1665 var->xoffset = (var->xoffset) & (~0x1);
1668 var->bits_per_pixel = 32;
1671 var->nonstd &= ~0xc0; //not support I2P in this format
1674 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1675 var->xres = (var->xres + 0x3) & (~0x3);
1676 var->xoffset = (var->xoffset) & (~0x3);
1679 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1680 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1681 var->xres = (var->xres + 0x3) & (~0x3);
1682 var->yres = (var->yres + 0x1) & (~0x1);
1683 var->xoffset = (var->xoffset) & (~0x3);
1684 var->yoffset = (var->yoffset) & (~0x1);
1687 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1688 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1689 var->xres = (var->xres + 0x3) & (~0x3);
1690 var->yres = (var->yres + 0x1) & (~0x1);
1691 var->xoffset = (var->xoffset) & (~0x3);
1692 var->yoffset = (var->yoffset) & (~0x1);
1693 var->nonstd &= ~0xc0; //not support I2P in this format
1697 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1698 var->xres = (var->xres + 0x3) & (~0x3);
1699 var->xoffset = (var->xoffset) & (~0x3);
1700 var->nonstd &= ~0xc0; //not support I2P in this format
1703 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1707 if((var->rotate == 270)||(var->rotate == 90))
1716 ScaleYRGBY = CalScaleW0(yres, ysize);
1718 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1720 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1723 if(inf->video_mode == 1) {
1724 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1726 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1727 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1728 init_completion(&hdmi->complete);
1730 wait_for_completion_interruptible_timeout(&hdmi->complete,
1731 msecs_to_jiffies(10000));
1738 static int fb1_set_par(struct fb_info *info)
1740 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1741 struct rk29fb_screen *screen = inf->cur_screen;
1742 struct fb_var_screeninfo *var = &info->var;
1743 struct fb_fix_screeninfo *fix = &info->fix;
1744 struct win0_par *par = info->par;
1747 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1749 //u32 xact = var->xres; /* visible resolution */
1750 //u32 yact = var->yres;
1751 u32 xvir = var->xres_virtual; /* virtual resolution */
1752 u32 yvir = var->yres_virtual;
1753 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1754 u32 yact_st = var->yoffset; /* resolution */
1756 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1757 u16 ypos = (var->nonstd>>20) & 0xfff;
1758 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1759 u16 ysize = (var->grayscale>>20) & 0xfff;
1761 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1762 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1764 u8 data_format = var->nonstd&0x0f;
1765 // u32 win0_en = var->reserved[2];
1766 // u32 y_addr = var->reserved[3]; //user alloc buf addr y
1767 // u32 uv_addr = var->reserved[4];
1769 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1772 if((var->rotate == 270)||(var->rotate == 90))
1774 #ifdef CONFIG_FB_ROTATE_VIDEO
1775 xpos = (var->nonstd>>20) & 0xfff; //visiable pos in panel
1776 ypos = (var->nonstd>>8) & 0xfff;
1777 xsize = (var->grayscale>>20) & 0xfff; //visiable size in panel
1778 ysize = (var->grayscale>>8) & 0xfff;
1779 #else //CONFIG_FB_ROTATE_VIDEO
1780 printk("LCDC not support rotate!\n");
1784 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1785 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1786 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1787 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1789 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1790 switch (data_format)
1793 switch(var->bits_per_pixel)
1797 fix->line_length = 2 * xvir;
1798 par->y_offset = (yact_st*xvir + xact_st)*2;
1802 fix->line_length = 4 * xvir;
1803 par->y_offset = (yact_st*xvir + xact_st)*4;
1811 fix->line_length = xvir;
1812 cblen = crlen = (xvir*yvir)/2;
1813 par->y_offset = yact_st*xvir + xact_st;
1814 par->c_offset = yact_st*xvir + xact_st;
1818 fix->line_length = xvir;
1819 cblen = crlen = (xvir*yvir)/4;
1821 par->y_offset = yact_st*xvir + xact_st;
1822 par->c_offset = (yact_st/2)*xvir + xact_st;
1827 fix->line_length = xvir;
1828 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1829 par->c_offset = (yact_st/2)*xvir + xact_st;
1830 cblen = crlen = (xvir*yvir)/4;
1835 fix->line_length = xvir;
1836 par->y_offset = yact_st*xvir + xact_st;
1837 par->c_offset = yact_st*2*xvir + xact_st*2;
1838 cblen = crlen = (xvir*yvir);
1844 smem_len = fix->line_length * yvir + cblen + crlen;
1845 map_size = PAGE_ALIGN(smem_len);
1847 // fix->smem_start = y_addr;
1848 fix->smem_len = smem_len;
1849 // fix->mmio_start = uv_addr;
1851 // par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1852 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);
1854 par->format = format;
1861 if ( wq_condition2 == 0 ) {
1862 wait_event_interruptible_timeout(wq, wq_condition2, HZ/20);
1866 #ifdef CONFIG_FB_ROTATE_VIDEO
1867 //need refresh ,zyc add
1868 if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
1871 struct rk29_ipp_req ipp_req;
1872 static u32 dstoffset = 0;
1873 static int fb_index = 0;
1875 yuv_phy[0] = last_yuv_phy[0];
1876 yuv_phy[1] = last_yuv_phy[1];
1877 yuv_phy[0] += par->y_offset;
1878 yuv_phy[1] += par->c_offset;
1879 if((var->rotate == 90) ||(var->rotate == 270))
1881 dstoffset = (dstoffset+1)%2;
1882 ipp_req.src0.fmt = 3;
1883 ipp_req.src0.YrgbMst = yuv_phy[0];
1884 ipp_req.src0.CbrMst = yuv_phy[1];
1885 ipp_req.src0.w = var->xres;
1886 ipp_req.src0.h = var->yres;
1888 ipp_req.dst0.fmt = 3;
1889 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
1890 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
1891 // if(var->xres > screen->x_res)
1893 ipp_req.dst0.w = screen->x_res;
1894 ipp_req.dst0.h = screen->y_res;
1896 // ipp_req.dst0.w = var->yres;
1897 // ipp_req.dst0.h = var->xres;
1899 ipp_req.src_vir_w = ipp_req.src0.w;
1900 ipp_req.dst_vir_w = ipp_req.dst0.w;
1901 ipp_req.timeout = 100;
1902 if(var->rotate == 90)
1903 ipp_req.flag = IPP_ROT_90;
1904 else if(var->rotate == 270)
1905 ipp_req.flag = IPP_ROT_270;
1907 ipp_do_blit(&ipp_req);
1908 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
1909 yuv_phy[0] = ipp_req.dst0.YrgbMst;
1910 yuv_phy[1] = ipp_req.dst0.CbrMst;
1911 fix->smem_start = yuv_phy[0];
1912 fix->mmio_start = yuv_phy[1];
1917 fix->smem_start = yuv_phy[0];
1918 fix->mmio_start = yuv_phy[1];
1921 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
1922 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
1923 // enable win0 after the win0 par is seted
1924 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
1925 par->addr_seted = 1;
1926 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1927 if(par->addr_seted ) {
1928 unsigned long flags;
1930 local_irq_save(flags);
1931 par->mirror.y_offset = yuv_phy[0];
1932 par->mirror.c_offset = yuv_phy[1];
1933 local_irq_restore(flags);
1936 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
1941 has_set_rotate = false;
1946 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1948 struct win0_par *par = info->par;
1949 // enable win0 after the win0 addr is seted
1956 int fb1_open(struct fb_info *info, int user)
1958 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1959 struct win0_par *par = info->par;
1961 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1964 par->addr_seted = 0;
1965 inf->video_mode = 1;
1967 #ifdef CONFIG_FB_ROTATE_VIDEO
1968 //reinitialize the var when open,zyc
1969 last_yuv_phy[0] = 0;
1970 last_yuv_phy[1] = 0;
1974 printk(">>>>>> fb1 has opened! \n");
1978 fb0_set_par(inf->fb0);
1979 fb0_pan_display(&inf->fb0->var, inf->fb0);
1980 win0_blank(FB_BLANK_POWERDOWN, info);
1985 int fb1_release(struct fb_info *info, int user)
1987 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1988 struct win0_par *par = info->par;
1989 struct fb_var_screeninfo *var0 = &info->var;
1991 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1995 inf->video_mode = 0;
1997 par->addr_seted = 0;
1998 //win0_blank(FB_BLANK_POWERDOWN, info);
1999 fb0_set_par(inf->fb0);
2000 fb0_pan_display(&inf->fb0->var, inf->fb0);
2001 win1_blank(FB_BLANK_POWERDOWN, info);
2002 // wait for lcdc stop access memory
2006 info->screen_base = 0;
2007 info->fix.smem_start = 0;
2008 info->fix.smem_len = 0;
2009 // clean the var param
2010 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2016 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2018 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2019 struct win0_par *par = info->par;
2020 struct fb_fix_screeninfo *fix0 = &info->fix;
2021 struct fb_var_screeninfo *var = &info->var;
2022 void __user *argp = (void __user *)arg;
2024 #ifdef CONFIG_FB_ROTATE_VIDEO
2025 struct rk29fb_screen *screen = inf->cur_screen;
2026 struct rk29_ipp_req ipp_req;
2027 static u32 dstoffset = 0;
2031 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2032 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2038 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
2041 if((var->rotate == 270)||(var->rotate == 90)) {
2042 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2043 panel_size[1] = inf->panel1_info.x_res;
2045 panel_size[0] = inf->panel1_info.x_res;
2046 panel_size[1] = inf->panel1_info.y_res;
2049 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
2053 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
2056 if (copy_from_user(yuv_phy, argp, 8))
2058 #ifdef CONFIG_FB_ROTATE_VIDEO
2060 if(has_set_rotate == true)
2062 last_yuv_phy[0] = yuv_phy[0];
2063 last_yuv_phy[1] = yuv_phy[1];
2066 fix0->smem_start = yuv_phy[0];
2067 fix0->mmio_start = yuv_phy[1];
2068 yuv_phy[0] += par->y_offset;
2069 yuv_phy[1] += par->c_offset;
2071 if((var->rotate == 270)||(var->rotate == 90))
2073 #ifdef CONFIG_FB_ROTATE_VIDEO
2074 dstoffset = (dstoffset+1)%2;
2075 ipp_req.src0.fmt = 3;
2076 ipp_req.src0.YrgbMst = yuv_phy[0];
2077 ipp_req.src0.CbrMst = yuv_phy[1];
2078 ipp_req.src0.w = var->xres;
2079 ipp_req.src0.h = var->yres;
2081 ipp_req.dst0.fmt = 3;
2082 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2083 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2084 // if(var->xres > screen->x_res)
2086 ipp_req.dst0.w = screen->x_res;
2087 ipp_req.dst0.h = screen->y_res;
2089 // ipp_req.dst0.w = var->yres;
2090 // ipp_req.dst0.h = var->xres;
2092 ipp_req.src_vir_w = ipp_req.src0.w;
2093 ipp_req.dst_vir_w = ipp_req.dst0.w;
2094 ipp_req.timeout = 100;
2095 if(var->rotate == 90)
2096 ipp_req.flag = IPP_ROT_90;
2097 else if(var->rotate == 270)
2098 ipp_req.flag = IPP_ROT_270;
2099 ipp_do_blit(&ipp_req);
2100 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2101 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2102 yuv_phy[1] = ipp_req.dst0.CbrMst;
2103 fix0->smem_start = yuv_phy[0];
2104 fix0->mmio_start = yuv_phy[1];
2105 #else //CONFIG_FB_ROTATE_VIDEO
2106 printk("LCDC not support rotate!\n");
2110 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2111 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2112 // enable win0 after the win0 par is seted
2113 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2114 par->addr_seted = 1;
2115 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2116 if(par->par_seted) {
2117 unsigned long flags;
2119 local_irq_save(flags);
2120 par->mirror.y_offset = yuv_phy[0];
2121 par->mirror.c_offset = yuv_phy[1];
2122 local_irq_restore(flags);
2125 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2130 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
2131 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2132 #ifdef CONFIG_FB_ROTATE_VIDEO
2134 has_set_rotate = true;
2135 if(arg == 0 || arg==180)
2137 else if (arg == 90 || arg==270)
2139 #else //CONFIG_FB_ROTATE_VIDEO
2140 printk("LCDC not support rotate!\n");
2143 case FB1_IOCTL_SET_WIN0_TOP:
2144 fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2145 LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2146 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2154 static struct fb_ops fb1_ops = {
2155 .owner = THIS_MODULE,
2156 .fb_open = fb1_open,
2157 .fb_release = fb1_release,
2158 .fb_check_var = fb1_check_var,
2159 .fb_set_par = fb1_set_par,
2160 .fb_blank = fb1_blank,
2161 .fb_pan_display = fb1_pan_display,
2162 .fb_ioctl = fb1_ioctl,
2163 .fb_setcolreg = fb_setcolreg,
2164 .fb_fillrect = cfb_fillrect,
2165 .fb_copyarea = cfb_copyarea,
2166 .fb_imageblit = cfb_imageblit,
2169 static struct fb_ops fb0_ops = {
2170 .owner = THIS_MODULE,
2171 .fb_check_var = fb0_check_var,
2172 .fb_set_par = fb0_set_par,
2173 .fb_blank = fb0_blank,
2174 .fb_pan_display = fb0_pan_display,
2175 .fb_ioctl = fb0_ioctl,
2176 .fb_setcolreg = fb_setcolreg,
2177 .fb_fillrect = cfb_fillrect,
2178 .fb_copyarea = cfb_copyarea,
2179 .fb_imageblit = cfb_imageblit,
2180 //.fb_cursor = rk29_set_cursor,
2184 enable: 1, switch to tv or hdmi; 0, switch to lcd
2186 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2188 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2189 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2190 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2192 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2194 if(enable)inf->cur_screen = &inf->panel2_info;
2195 else inf->cur_screen = &inf->panel1_info;
2197 /* Black out, because some display device need clock to standby */
2198 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2199 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2200 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2201 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
2202 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2203 wake_lock(&idlelock);
2205 wake_unlock(&idlelock);
2207 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
2208 // operate the display_on pin to power down the lcd
2210 if(enable && mach_info->io_disable)mach_info->io_disable(); //close lcd out
2211 else if (mach_info->io_enable)mach_info->io_enable(); //open lcd out
2213 load_screen(inf->fb0, 0);
2216 fb1_set_par(inf->fb1);
2217 fb0_set_par(inf->fb0);
2218 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
2219 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2223 static ssize_t dsp_win0_info_read(struct device *device,
2224 struct device_attribute *attr, char *buf)
2227 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2228 struct rk29fb_screen *screen = inf->cur_screen;
2230 u16 xpos=0,ypos=0,xsize=0,ysize=0;
2232 fbprintk("%s\n",__FUNCTION__);
2233 xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2234 ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2236 xpos -= (screen->left_margin + screen->hsync_len);
2237 ypos -= (screen->upper_margin + screen->vsync_len);
2239 xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2240 ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2241 fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2242 rk29_set_cursor_test(inf->fb0);
2244 return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2247 static ssize_t dsp_win0_info_write(struct device *device,
2248 struct device_attribute *attr, const char *buf, size_t count)
2250 printk("%s\n",__FUNCTION__);
2251 printk("%s %x \n",__FUNCTION__,*buf);
2255 static DEVICE_ATTR(dsp_win0_info, S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2257 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2259 struct platform_device *pdev = (struct platform_device*)dev_id;
2260 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2261 struct win0_par *par = (struct win0_par *)inf->fb1->par;
2265 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2267 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2269 if(SCREEN_MCU == inf->cur_screen->type)
2271 inf->mcu_isrcnt = !inf->mcu_isrcnt;
2277 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2279 inf->mcu_fmksync = 1;
2280 if(inf->cur_screen->refresh)
2281 inf->cur_screen->refresh(REFRESH_END);
2282 inf->mcu_fmksync = 0;
2291 if(inf->mcu_needflush) {
2292 if(inf->cur_screen->refresh)
2293 inf->cur_screen->refresh(REFRESH_PRE);
2294 inf->mcu_needflush = 0;
2295 inf->mcu_isrcnt = 0;
2296 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2298 if(inf->cur_screen->refresh)
2299 inf->cur_screen->refresh(REFRESH_END);
2303 #if ANDROID_USE_THREE_BUFS
2304 new_frame_seted = 1;
2307 if(waitqueue_active(&par->wait)) {
2308 if (par->mirror.c_offset == 0)
2309 printk("error: no new buffer to display\n");
2311 par->done.y_offset = par->displ.y_offset;
2312 par->done.c_offset = par->displ.c_offset;
2313 par->displ.y_offset = par->mirror.y_offset;
2314 par->displ.c_offset = par->mirror.c_offset;
2315 par->mirror.y_offset = 0;
2316 par->mirror.c_offset = 0;
2318 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2319 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2320 wake_up_interruptible(&par->wait);
2325 wake_up_interruptible(&wq);
2330 #ifdef CONFIG_HAS_EARLYSUSPEND
2332 struct suspend_info {
2333 struct early_suspend early_suspend;
2334 struct rk29fb_inf *inf;
2337 static void rk29fb_early_suspend(struct early_suspend *h)
2339 struct suspend_info *info = container_of(h, struct suspend_info,
2342 struct rk29fb_inf *inf = info->inf;
2343 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2345 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2348 printk("inf==0, rk29fb_suspend fail! \n");
2352 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable) // close lcd pwr when output screen is lcd
2353 mach_info->io_disable(); //close lcd out
2355 if(inf->cur_screen->standby)
2357 fbprintk(">>>>>> power down the screen! \n");
2358 inf->cur_screen->standby(1);
2361 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2362 v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2364 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2365 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2366 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2368 if(!inf->in_suspend)
2370 fbprintk(">>>>>> diable the lcdc clk! \n");
2371 wake_lock(&idlelock);
2373 wake_unlock(&idlelock);
2374 clk_disable(inf->aclk_ddr_lcdc);
2375 clk_disable(inf->aclk_disp_matrix);
2376 clk_disable(inf->hclk_cpu_display);
2377 clk_disable(inf->clk);
2379 clk_disable(inf->dclk);
2382 clk_disable(inf->aclk);
2384 clk_disable(inf->pd_display);
2386 inf->in_suspend = 1;
2390 static void rk29fb_early_resume(struct early_suspend *h)
2392 struct suspend_info *info = container_of(h, struct suspend_info,
2395 struct rk29fb_inf *inf = info->inf;
2396 struct rk29fb_screen *screen = inf->cur_screen;
2397 struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2399 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2401 printk("inf==0, rk29fb_resume fail! \n");
2407 inf->in_suspend = 0;
2408 fbprintk(">>>>>> enable the lcdc clk! \n");
2409 clk_enable(inf->pd_display);
2410 clk_enable(inf->aclk_disp_matrix);
2411 clk_enable(inf->hclk_cpu_display);
2412 clk_enable(inf->clk);
2413 clk_enable(inf->aclk_ddr_lcdc);
2416 clk_enable(inf->dclk);
2419 clk_enable(inf->aclk);
2423 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2424 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2425 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2427 LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2428 v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2430 if(inf->cur_screen->standby)
2432 fbprintk(">>>>>> power on the screen! \n");
2433 inf->cur_screen->standby(0);
2436 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
2439 if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable) // open lcd pwr when output screen is lcd
2440 mach_info->io_enable(); //close lcd out
2444 static struct suspend_info suspend_info = {
2445 .early_suspend.suspend = rk29fb_early_suspend,
2446 .early_suspend.resume = rk29fb_early_resume,
2447 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2450 struct fb_info *g_fb0_inf = NULL; //add cym@rk 20101027 for charger logo
2451 static int __init rk29fb_probe (struct platform_device *pdev)
2453 struct rk29fb_inf *inf = NULL;
2454 struct resource *res = NULL;
2455 struct resource *mem = NULL;
2456 struct rk29fb_info *mach_info = NULL;
2457 struct rk29fb_screen *screen = NULL;
2458 struct win0_par* par = NULL;
2462 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2464 /* Malloc rk29fb_inf and set it to pdev for drvdata */
2465 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2466 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2469 dev_err(&pdev->dev, ">> inf kmalloc fail!");
2471 goto release_drvdata;
2473 memset(inf, 0, sizeof(struct rk29fb_inf));
2474 platform_set_drvdata(pdev, inf);
2476 mach_info = pdev->dev.platform_data;
2477 /* Fill screen info and set current screen */
2478 fbprintk(">> Fill screen info and set current screen \n");
2479 #ifdef CONFIG_DEFAULT_OUT_HDMI // set hdmi for default output
2480 hdmi_get_default_resolution(&inf->panel1_info);
2482 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2484 inf->cur_screen = &inf->panel1_info;
2485 screen = inf->cur_screen;
2486 if(SCREEN_NULL==screen->type)
2488 dev_err(&pdev->dev, ">> Please select a display device! \n");
2490 goto release_drvdata;
2493 /* get virtual basic address of lcdc register */
2494 fbprintk(">> get virtual basic address of lcdc register \n");
2495 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2498 dev_err(&pdev->dev, "failed to get memory registers\n");
2500 goto release_drvdata;
2502 inf->reg_phy_base = res->start;
2503 inf->len = (res->end - res->start) + 1;
2504 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2507 dev_err(&pdev->dev, "failed to get memory region\n");
2509 goto release_drvdata;
2511 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2512 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2513 if (inf->reg_vir_base == NULL)
2515 dev_err(&pdev->dev, "ioremap() of registers failed\n");
2517 goto release_drvdata;
2519 inf->preg = (LCDC_REG*)inf->reg_vir_base;
2521 /* Prepare win1 info */
2522 fbprintk(">> Prepare win1 info \n");
2523 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2526 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2529 goto release_win1fb;
2532 par = (struct win0_par*)inf->fb0->par;
2533 strcpy(inf->fb0->fix.id, "fb0");
2534 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
2535 inf->fb0->fix.type_aux = 0;
2536 inf->fb0->fix.xpanstep = 1;
2537 inf->fb0->fix.ypanstep = 1;
2538 inf->fb0->fix.ywrapstep = 0;
2539 inf->fb0->fix.accel = FB_ACCEL_NONE;
2540 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
2541 inf->fb0->fix.smem_len = 0;
2542 inf->fb0->fix.line_length = 0;
2543 inf->fb0->fix.smem_start = 0;
2545 inf->fb0->var.xres = screen->x_res;
2546 inf->fb0->var.yres = screen->y_res;
2547 inf->fb0->var.bits_per_pixel = 16;
2548 inf->fb0_color_deepth = 0;
2549 inf->fb0->var.xres_virtual = screen->x_res;
2550 inf->fb0->var.yres_virtual = screen->y_res;
2551 inf->fb0->var.width = screen->width;
2552 inf->fb0->var.height = screen->height;
2553 inf->fb0->var.pixclock = screen->pixclock;
2554 inf->fb0->var.left_margin = screen->left_margin;
2555 inf->fb0->var.right_margin = screen->right_margin;
2556 inf->fb0->var.upper_margin = screen->upper_margin;
2557 inf->fb0->var.lower_margin = screen->lower_margin;
2558 inf->fb0->var.vsync_len = screen->vsync_len;
2559 inf->fb0->var.hsync_len = screen->hsync_len;
2560 inf->fb0->var.red = def_rgb_16.red;
2561 inf->fb0->var.green = def_rgb_16.green;
2562 inf->fb0->var.blue = def_rgb_16.blue;
2563 inf->fb0->var.transp = def_rgb_16.transp;
2565 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2566 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
2567 inf->fb0->var.activate = FB_ACTIVATE_NOW;
2568 inf->fb0->var.accel_flags = 0;
2569 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
2571 inf->fb0->fbops = &fb0_ops;
2572 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
2573 inf->fb0->pseudo_palette = par->pseudo_pal;
2574 inf->fb0->screen_base = 0;
2576 memset(par, 0, sizeof(struct win0_par));
2578 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2582 g_fb0_inf = inf->fb0; //add cym@rk 20101027
2584 /* alloc win1 buf */
2585 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2588 dev_err(&pdev->dev, "failed to get win1 memory \n");
2590 goto release_win1fb;
2592 inf->fb0->fix.smem_start = res->start;
2593 inf->fb0->fix.smem_len = res->end - res->start + 1;
2594 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2595 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2597 #ifdef CONFIG_FB_WORK_IPP
2598 /* alloc win1 ipp buf */
2599 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2602 dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2604 goto release_win1fb;
2606 inf->fb0->fix.mmio_start = res->start;
2607 inf->fb0->fix.mmio_len = res->end - res->start + 1;
2610 /* Prepare win0 info */
2611 fbprintk(">> Prepare win0 info \n");
2612 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2615 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2618 goto release_win0fb;
2621 par = (struct win0_par*)inf->fb1->par;
2623 strcpy(inf->fb1->fix.id, "fb1");
2624 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2625 inf->fb1->fix.type_aux = 0;
2626 inf->fb1->fix.xpanstep = 1;
2627 inf->fb1->fix.ypanstep = 1;
2628 inf->fb1->fix.ywrapstep = 0;
2629 inf->fb1->fix.accel = FB_ACCEL_NONE;
2630 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2631 inf->fb1->fix.smem_len = 0;
2632 inf->fb1->fix.line_length = 0;
2633 inf->fb1->fix.smem_start = 0;
2635 inf->fb1->var.xres = screen->x_res;
2636 inf->fb1->var.yres = screen->y_res;
2637 inf->fb1->var.bits_per_pixel = 16;
2638 inf->fb1->var.xres_virtual = screen->x_res;
2639 inf->fb1->var.yres_virtual = screen->y_res;
2640 inf->fb1->var.width = screen->width;
2641 inf->fb1->var.height = screen->height;
2642 inf->fb1->var.pixclock = screen->pixclock;
2643 inf->fb1->var.left_margin = screen->left_margin;
2644 inf->fb1->var.right_margin = screen->right_margin;
2645 inf->fb1->var.upper_margin = screen->upper_margin;
2646 inf->fb1->var.lower_margin = screen->lower_margin;
2647 inf->fb1->var.vsync_len = screen->vsync_len;
2648 inf->fb1->var.hsync_len = screen->hsync_len;
2649 inf->fb1->var.red = def_rgb_16.red;
2650 inf->fb1->var.green = def_rgb_16.green;
2651 inf->fb1->var.blue = def_rgb_16.blue;
2652 inf->fb1->var.transp = def_rgb_16.transp;
2654 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2655 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2656 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2657 inf->fb1->var.accel_flags = 0;
2658 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2660 inf->fb1->fbops = &fb1_ops;
2661 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2662 inf->fb1->pseudo_palette = par->pseudo_pal;
2663 inf->fb1->screen_base = 0;
2665 memset(par, 0, sizeof(struct win0_par));
2667 init_waitqueue_head(&par->wait);
2669 /* Init all lcdc and lcd before register_framebuffer. */
2670 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2671 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2672 init_lcdc(inf->fb0);
2674 #if 0 //def CONFIG_CPU_FREQ
2675 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2676 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2678 fbprintk("got clock\n");
2682 struct rk29_fb_setting_info fb_setting;
2683 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2685 fb_setting.data_num = 24;
2687 else if(OUT_P666 == inf->cur_screen->face )
2689 fb_setting.data_num = 18;
2693 fb_setting.data_num = 16;
2695 fb_setting.den_en = 1;
2696 fb_setting.vsync_en = 1;
2697 fb_setting.disp_on_en = 1;
2698 fb_setting.standby_en = 1;
2699 if( inf->cur_screen->mcu_usefmk )
2700 fb_setting.mcu_fmk_en =1;
2701 mach_info->io_init(&fb_setting);
2704 //set_lcd_pin(pdev, 1);
2707 inf->mcu_usetimer = 1;
2708 inf->mcu_fmksync = 0;
2709 load_screen(inf->fb0, 1);
2711 /* Register framebuffer(fb0 & fb1) */
2712 fbprintk(">> Register framebuffer(fb0) \n");
2713 ret = register_framebuffer(inf->fb0);
2716 printk(">> fb0 register_framebuffer fail!\n");
2718 goto release_win0fb;
2720 fbprintk(">> Register framebuffer(fb1) \n");
2722 ret = register_framebuffer(inf->fb1);
2725 printk(">> fb1 register_framebuffer fail!\n");
2727 goto unregister_win1fb;
2730 ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2733 printk(">> fb1 dsp win0 info device_create_file err\n");
2736 #ifdef CONFIG_HAS_EARLYSUSPEND
2737 suspend_info.inf = inf;
2738 register_early_suspend(&suspend_info.early_suspend);
2741 /* get and request irq */
2742 fbprintk(">> get and request irq \n");
2743 irq = platform_get_irq(pdev, 0);
2745 dev_err(&pdev->dev, "no irq for device\n");
2747 goto unregister_win1fb;
2749 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2751 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2756 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2758 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2761 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2767 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2768 fb0_set_par(inf->fb0);
2769 if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2770 /* Start display and show logo on boot */
2771 fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2772 fb_show_logo(inf->fb0, FB_ROTATE_UR);
2773 fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2777 printk(" %s ok\n", __FUNCTION__);
2782 free_irq(irq, pdev);
2784 unregister_framebuffer(inf->fb0);
2787 framebuffer_release(inf->fb1);
2791 fb_dealloc_cmap(&inf->fb0->cmap);
2794 framebuffer_release(inf->fb0);
2797 if(inf && inf->reg_vir_base)
2798 iounmap(inf->reg_vir_base);
2800 release_mem_region(inf->reg_phy_base, inf->len);
2803 platform_set_drvdata(pdev, NULL);
2807 static int rk29fb_remove(struct platform_device *pdev)
2809 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2810 struct fb_info *info = NULL;
2812 struct rk29fb_info *mach_info = NULL;
2815 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2818 printk("inf==0, rk29_fb_remove fail! \n");
2821 device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2823 irq = platform_get_irq(pdev, 0);
2826 free_irq(irq, pdev);
2829 mach_info = pdev->dev.platform_data;
2830 if(mach_info->mcu_fmk_pin)
2832 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2835 if(mach_info->io_disable)
2836 mach_info->io_disable(); //close lcd out
2840 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2842 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2845 //rk29fb_suspend(pdev, msg);
2846 // unmap memory and release framebuffer
2849 if (info->screen_base) {
2850 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2851 info->screen_base = 0;
2852 info->fix.smem_start = 0;
2853 info->fix.smem_len = 0;
2855 unregister_framebuffer(inf->fb1);
2856 framebuffer_release(inf->fb1);
2861 if (info->screen_base) {
2862 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2863 info->screen_base = 0;
2864 info->fix.smem_start = 0;
2865 info->fix.smem_len = 0;
2867 unregister_framebuffer(inf->fb0);
2868 framebuffer_release(inf->fb0);
2872 #if 0 //def CONFIG_CPU_FREQ
2873 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2880 clk_disable(inf->clk);
2886 clk_disable(inf->dclk);
2892 platform_set_drvdata(pdev, NULL);
2897 static void rk29fb_shutdown(struct platform_device *pdev)
2899 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2900 struct rk29fb_info *mach_info = pdev->dev.platform_data;;
2902 fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
2904 if(mach_info->io_disable)
2905 mach_info->io_disable(); //close lcd out
2907 if(!inf->in_suspend)
2909 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2910 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2911 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2913 clk_disable(inf->aclk_ddr_lcdc);
2914 clk_disable(inf->aclk_disp_matrix);
2915 clk_disable(inf->hclk_cpu_display);
2916 clk_disable(inf->clk);
2918 clk_disable(inf->dclk);
2921 clk_disable(inf->aclk);
2923 clk_disable(inf->pd_display);
2924 //pmu_set_power_domain(PD_DISPLAY, 0);
2925 inf->in_suspend = 1;
2930 static struct platform_driver rk29fb_driver = {
2931 .probe = rk29fb_probe,
2932 .remove = rk29fb_remove,
2935 .owner = THIS_MODULE,
2937 .shutdown = rk29fb_shutdown,
2940 static int __init rk29fb_init(void)
2942 wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
2943 return platform_driver_register(&rk29fb_driver);
2946 static void __exit rk29fb_exit(void)
2948 platform_driver_unregister(&rk29fb_driver);
2951 fs_initcall(rk29fb_init);
2952 module_exit(rk29fb_exit);
2955 MODULE_AUTHOR(" zyw@rock-chips.com");
2956 MODULE_DESCRIPTION("Driver for rk29 fb device");
2957 MODULE_LICENSE("GPL");