Merge branch 'develop-3.0' of ssh://10.10.10.29/rk/kernel into develop-3.0
[firefly-linux-kernel-4.4.55.git] / drivers / video / rk29_fb.c
1 /*
2  * drivers/video/rk29_fb.c
3  *
4  * Copyright (C) 2010 ROCKCHIP, Inc.
5  *
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.
9  *
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.
14  */
15
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
20 #include <linux/mm.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
24 #include <linux/fb.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>
37
38 #include <asm/io.h>
39 #include <asm/div64.h>
40 #include <asm/uaccess.h>
41 #include <asm/cacheflush.h>
42
43 #include "rk29_fb.h"
44
45 #ifdef CONFIG_PM
46 #include <linux/pm.h>
47 #endif
48 #ifdef CONFIG_HDMI
49 #include <linux/completion.h>
50
51 #include <linux/hdmi.h>
52 #endif
53  
54
55 #include <mach/iomux.h>
56 #include <mach/gpio.h>
57 #include <mach/board.h>
58 #include <mach/rk29_iomap.h>
59 #include <mach/pmu.h>
60 #include <mach/rk29-ipp.h>
61 #include <mach/ddr.h>
62
63 #include "./display/screen/screen.h"
64
65 #ifdef CONFIG_MFD_RK610
66 #include "./display/lcd/rk610_lcd.h"
67 #endif
68 #define ANDROID_USE_THREE_BUFS  0       //android use three buffers to accelerate UI display in rgb plane
69 #define CURSOR_BUF_SIZE         256     //RK2818 cursor need 256B buf
70 int rk29_cursor_buf[CURSOR_BUF_SIZE];
71 char cursor_img[] = {
72 0x00,0x00,0x00,0x00,
73 0x00,0x00,0x00,0x00,
74 0x00,0x00,0x00,0x00,
75 0x00,0x00,0x00,0x00,
76 0x00,0x00,0x00,0x00,
77 0x00,0x20,0x00,0x00,
78 0x00,0x30,0x00,0x00,
79 0x00,0x28,0x00,0x00,
80 0x00,0x24,0x00,0x00,
81 0x00,0x22,0x00,0x00,
82 0x00,0x21,0x00,0x00,
83 0x00,0x20,0x80,0x00,
84 0x00,0x20,0x40,0x00,
85 0x00,0x20,0x20,0x00,
86 0x00,0x20,0x10,0x00,
87 0x00,0x20,0x08,0x00,
88 0x00,0x20,0x7C,0x00,
89 0x00,0x22,0x40,0x00,
90 0x00,0x26,0x40,0x00,
91 0x00,0x29,0x20,0x00,
92 0x00,0x31,0x20,0x00,
93 0x00,0x20,0x90,0x00,
94 0x00,0x00,0x90,0x00,
95 0x00,0x00,0x48,0x00,
96 0x00,0x00,0x48,0x00,
97 0x00,0x00,0x30,0x00,
98 0x00,0x00,0x00,0x00,
99 0x00,0x00,0x00,0x00,
100 0x00,0x00,0x00,0x00,
101 0x00,0x00,0x00,0x00,
102 0x00,0x00,0x00,0x00,
103 0x00,0x00,0x00,0x00
104 };
105
106 #if 0
107         #define fbprintk(msg...)        printk(msg);
108 #else
109         #define fbprintk(msg...)
110 #endif
111
112
113 #if 0
114         #define fbprintk2(msg...)       printk(msg);
115 #else
116         #define fbprintk2(msg...)
117 #endif
118
119 #define LcdReadBit(inf, addr, msk)      ((inf->regbak.addr=inf->preg->addr)&(msk))
120 #define LcdWrReg(inf, addr, val)        inf->preg->addr=inf->regbak.addr=(val)
121 #define LcdRdReg(inf, addr)             (inf->preg->addr)
122 #define LcdSetBit(inf, addr, msk)       inf->preg->addr=((inf->regbak.addr) |= (msk))
123 #define LcdClrBit(inf, addr, msk)       inf->preg->addr=((inf->regbak.addr) &= ~(msk))
124 #define LcdSetRegisterBit(inf, addr, msk)    inf->preg->addr=((inf->preg->addr) |= (msk))
125 #define LcdMskReg(inf, addr, msk, val)  (inf->regbak.addr)&=~(msk);   inf->preg->addr=(inf->regbak.addr|=(val))
126
127
128 #define IsMcuLandscape()                ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
129 #define IsMcuUseFmk()                   ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
130
131 #define CalScaleW0(x, y)                     (((u32)x*0x1000)/y)
132
133 struct rk29fb_rgb {
134         struct fb_bitfield      red;
135         struct fb_bitfield      green;
136         struct fb_bitfield      blue;
137         struct fb_bitfield      transp;
138 };
139
140 static struct rk29fb_rgb def_rgb_16 = {
141      red:    { offset: 11, length: 5, },
142      green:  { offset: 5,  length: 6, },
143      blue:   { offset: 0,  length: 5, },
144      transp: { offset: 0,  length: 0, },
145 };
146
147 struct win_set {
148         volatile u32 y_offset;
149         volatile u32 c_offset;
150 };
151
152 struct win0_par {
153     u32 refcount;
154     u32 pseudo_pal[16];
155     u32 y_offset;
156     u32 c_offset;
157     u32 xpos;         //size in panel
158     u32 ypos;
159     u32 xsize;        //start point in panel
160     u32 ysize;
161     u32 format;
162
163     wait_queue_head_t wait;
164     struct win_set mirror;
165     struct win_set displ;
166     struct win_set done;
167
168     u8 par_seted;
169     u8 addr_seted;
170 };
171
172 /*
173 struct win1_par {
174         u32 refcount;
175         u32     pseudo_pal[16];
176         int lstblank;
177     u32 xpos;
178     u32 ypos;
179     u32 xsize;
180     u32 ysize;
181     u32 format;
182     u32 addr_offset;
183 };
184 */
185
186 struct rk29fb_inf {
187     struct fb_info *fb1;
188     struct fb_info *fb0;
189
190     void __iomem *reg_vir_base;  // virtual basic address of lcdc register
191         u32 reg_phy_base;       // physical basic address of lcdc register
192         u32 len;               // physical map length of lcdc register
193     u32 video_mode;
194
195     struct clk      *clk;
196     struct clk      *dclk;            //lcdc dclk
197     struct clk      *aclk;   //lcdc share memory frequency
198     struct clk      *aclk_parent;     //lcdc aclk divider frequency source
199     struct clk      *aclk_ddr_lcdc;   //DDR LCDC AXI clock disable.
200     struct clk      *aclk_disp_matrix;  //DISPLAY matrix AXI clock disable.
201     struct clk      *hclk_cpu_display;  //CPU DISPLAY AHB bus clock disable.
202     struct clk      *pd_display;        // display power domain
203     unsigned long       dclk_rate;
204
205     /* lcdc reg base address and backup reg */
206     LCDC_REG *preg;
207     LCDC_REG regbak;
208
209         int in_suspend;
210     int fb0_color_deepth;
211     /* variable used in mcu panel */
212         int mcu_needflush;
213         int mcu_isrcnt;
214         u16 mcu_scandir;
215         struct timer_list mcutimer;
216         int mcu_status;
217         u8 mcu_fmksync;
218         int mcu_usetimer;
219         int mcu_stopflush;
220
221     int setFlag;
222     /* external memery */
223         char __iomem *screen_base2;
224     __u32 smem_len2;
225     unsigned long  smem_start2;
226
227     char __iomem *cursor_base;   /* cursor Virtual address*/
228     __u32 cursor_size;           /* Amount of ioremapped VRAM or 0 */
229     unsigned long  cursor_start;
230
231     struct rk29fb_screen panel1_info;         // 1st panel, it's lcd normally
232     struct rk29fb_screen panel2_info;         // 2nd panel
233     struct rk29fb_screen *cur_screen;
234 #if 0 //def CONFIG_CPU_FREQ
235     struct notifier_block freq_transition;
236 #endif
237
238 };
239 #ifdef CONFIG_BACKLIGHT_RK29_BL
240 /* drivers/video/backlight/rk29_backlight.c */
241 extern void rk29_backlight_set(bool on);
242 #else
243 void rk29_backlight_set(bool on)
244 {
245         /* please add backlight switching-related code here or on your backlight driver
246            parameter: on=1 ==> open spk 
247                                   on=0 ==> close spk
248         */
249 }
250 #endif
251 typedef enum _TRSP_MODE
252 {
253     TRSP_CLOSE = 0,
254     TRSP_FMREG,
255     TRSP_FMREGEX,
256     TRSP_FMRAM,
257     TRSP_FMRAMEX,
258     TRSP_MASK,
259     TRSP_INVAL
260 } TRSP_MODE;
261 #ifdef  FB_WIMO_FLAG
262 struct wimo_fb_info{
263         unsigned long bitperpixel;
264         unsigned long mode;
265         unsigned long xaff;
266         unsigned long yaff;
267         unsigned long xpos;
268         unsigned long ypos;
269         unsigned long xsize;
270         unsigned long ysize;
271         unsigned long src_y;
272         unsigned long src_uv;
273         unsigned long dst_width;
274         unsigned long dst_height;
275         //struct mutex fb_lock;
276         volatile unsigned long fb_lock;
277
278         
279 };
280 struct wimo_fb_info wimo_info;
281 unsigned char* ui_buffer;
282 unsigned char* ui_buffer_map;
283 //unsigned char* overlay_buffer;
284 //unsigned char* overlay_buffer_map;
285 #endif
286
287 struct platform_device *g_pdev = NULL;
288 //static int win1fb_set_par(struct fb_info *info);
289
290 #if 0
291 #define CHK_SUSPEND(inf)        \
292         if(inf->in_suspend)     {       \
293                 fbprintk(">>>>>> fb is in suspend! return! \n");        \
294                 return -EPERM;  \
295         }
296 #else
297 #define CHK_SUSPEND(inf)
298 #endif
299 static DECLARE_WAIT_QUEUE_HEAD(fb0_wait_queue);     
300 static volatile int idle_condition = 1;              //1:idel, 0:busy
301
302 static DECLARE_WAIT_QUEUE_HEAD(wq);
303 static int wq_condition = 0;
304 static int wq_condition2 = 0;
305 static int fb1_open_init = 0;
306 #if ANDROID_USE_THREE_BUFS
307 static int new_frame_seted = 1;
308 #endif
309 static struct wake_lock idlelock; /* only for fb */
310 #ifdef CONFIG_FB_ROTATE_VIDEO   
311 //add by zyc
312 static bool has_set_rotate; 
313 static u32 last_yuv_phy[2] = {0,0};
314 #endif
315 int fb0_first_buff_bits = 32;
316 int fb0_second_buff_bits = 32;
317 int fb_compose_layer_count = 0;
318 static BLOCKING_NOTIFIER_HEAD(rk29fb_notifier_list);
319 int rk29fb_register_notifier(struct notifier_block *nb)
320 {
321         int ret = 0;
322         if (g_pdev) {
323                 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
324                 if (inf) {
325                         if (inf->cur_screen && inf->cur_screen->type == SCREEN_HDMI)
326                                 nb->notifier_call(nb, RK29FB_EVENT_HDMI_ON, inf->cur_screen);
327                         if (inf->fb1 && inf->fb1->par) {
328                                 struct win0_par *par = inf->fb1->par;
329                                 if (par->refcount)
330                                         nb->notifier_call(nb, RK29FB_EVENT_FB1_ON, inf->cur_screen);
331                         }
332                 }
333         }
334         ret = blocking_notifier_chain_register(&rk29fb_notifier_list, nb);
335
336         return ret;
337 }
338
339 int rk29fb_unregister_notifier(struct notifier_block *nb)
340 {
341         return blocking_notifier_chain_unregister(&rk29fb_notifier_list, nb);
342 }
343
344 static int rk29fb_notify(struct rk29fb_inf *inf, unsigned long event)
345 {
346         return blocking_notifier_call_chain(&rk29fb_notifier_list, event, inf->cur_screen);
347 }
348
349 int mcu_do_refresh(struct rk29fb_inf *inf)
350 {
351     if(inf->mcu_stopflush)  return 0;
352
353     if(SCREEN_MCU!=inf->cur_screen->type)   return 0;
354
355     // use frame mark
356     if(IsMcuUseFmk())
357     {
358         inf->mcu_needflush = 1;
359         return 0;
360     }
361
362     // not use frame mark
363     if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
364     {
365         if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
366         {
367             inf->mcu_needflush = 1;
368         }
369         else
370         {
371             if(inf->cur_screen->refresh)    inf->cur_screen->refresh(REFRESH_PRE);
372             inf->mcu_needflush = 0;
373             inf->mcu_isrcnt = 0;
374             LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
375         }
376     }
377     return 0;
378 }
379
380
381 void mcutimer_callback(unsigned long arg)
382 {
383     struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
384     static int waitcnt = 0;
385
386     mod_timer(&inf->mcutimer, jiffies + HZ/10);
387
388     switch(inf->mcu_status)
389     {
390     case MS_IDLE:
391         inf->mcu_status = MS_MCU;
392         break;
393     case MS_MCU:
394         if(inf->mcu_usetimer)   mcu_do_refresh(inf);
395         break;
396     case MS_EWAITSTART:
397         inf->mcu_status = MS_EWAITEND;
398         waitcnt = 0;
399         break;
400     case MS_EWAITEND:
401         if(0==waitcnt) {
402             mcu_do_refresh(inf);
403         }
404         if(waitcnt++>14) {
405             inf->mcu_status = MS_EEND;
406         }
407         break;
408     case MS_EEND:
409         inf->mcu_status = MS_MCU;
410         break;
411     default:
412         inf->mcu_status = MS_MCU;
413         break;
414     }
415 }
416
417 int mcu_refresh(struct rk29fb_inf *inf)
418 {
419     static int mcutimer_inited = 0;
420
421     if(SCREEN_MCU!=inf->cur_screen->type)   return 0;
422
423     if(!mcutimer_inited)
424     {
425         mcutimer_inited = 1;
426         init_timer(&inf->mcutimer);
427         inf->mcutimer.function = mcutimer_callback;
428         inf->mcutimer.expires = jiffies + HZ/5;
429         inf->mcu_status = MS_IDLE;
430         add_timer(&inf->mcutimer);
431     }
432
433     if(MS_MCU==inf->mcu_status)     mcu_do_refresh(inf);
434
435     return 0;
436 }
437
438 int mcu_ioctl(unsigned int cmd, unsigned long arg)
439 {
440     struct rk29fb_inf *inf = NULL;
441     if(!g_pdev)     return -1;
442
443     inf = dev_get_drvdata(&g_pdev->dev);
444
445     switch(cmd)
446     {
447     case MCU_WRCMD:
448         LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
449         LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
450         LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
451         break;
452
453     case MCU_WRDATA:
454         LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
455         LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
456         break;
457
458     case MCU_SETBYPASS:
459         LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
460         LcdWrReg(inf, REG_CFG_DONE, 0x01);
461         break;
462
463     default:
464         break;
465     }
466
467     return 0;
468 }
469
470 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
471 {
472         struct platform_device *pdev = (struct platform_device*)dev_id;
473     struct rk29fb_inf *inf = platform_get_drvdata(pdev);
474     struct rk29fb_screen *screen;
475
476     if(!inf)    return IRQ_HANDLED;
477
478     screen = inf->cur_screen;
479
480     if(0==screen->mcu_usefmk) {
481         return IRQ_HANDLED;
482     }
483
484     if(inf->mcu_fmksync == 1)
485         return IRQ_HANDLED;
486
487     inf->mcu_fmksync = 1;
488     if(inf->mcu_needflush)
489     {
490         inf->mcu_needflush = 0;
491         inf->mcu_isrcnt = 0;
492         if(inf->cur_screen->refresh)
493            inf->cur_screen->refresh(REFRESH_PRE);
494         LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
495     }
496     inf->mcu_fmksync = 0;
497
498         return IRQ_HANDLED;
499 }
500
501 int init_lcdc(struct fb_info *info)
502 {
503     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
504     u32 msk=0, clr=0;
505
506         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
507
508     inf->clk = clk_get(NULL, "hclk_lcdc");
509     inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
510     inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
511     inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
512     inf->pd_display = clk_get(NULL, "pd_display");
513     if ((IS_ERR(inf->clk)) ||
514         (IS_ERR(inf->aclk_ddr_lcdc)) ||
515         (IS_ERR(inf->aclk_disp_matrix)) ||
516         (IS_ERR(inf->hclk_cpu_display)) ||
517         (IS_ERR(inf->pd_display)))
518     {
519         printk(KERN_ERR "failed to get lcdc_hclk source\n");
520         return PTR_ERR(inf->clk);
521     }
522     clk_enable(inf->aclk_disp_matrix);
523     clk_enable(inf->hclk_cpu_display);
524     clk_enable(inf->clk);
525     clk_enable(inf->pd_display);
526     //pmu_set_power_domain(PD_DISPLAY, 1);
527     clk_enable(inf->aclk_ddr_lcdc);
528
529         // set AHB access rule and disable all windows
530     LcdWrReg(inf, SYS_CONFIG, 0x60000000);
531     LcdWrReg(inf, SWAP_CTRL, 0);
532     LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
533     LcdWrReg(inf, AXI_MS_ID, 0x54321);
534
535         // and mcu holdmode; and set win1 top.
536     LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
537             v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
538
539     // disable blank out, black out, tristate out, yuv2rgb bypass
540     LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
541              m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
542              v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
543              v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
544              );
545
546     LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
547     LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
548
549     LcdWrReg(inf, DSP_CTRL1, 0);
550
551     // initialize all interrupt
552     clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
553
554     msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
555
556     LcdWrReg(inf, INT_STATUS, clr | msk);
557
558         // let above to take effect
559     LcdWrReg(inf, REG_CFG_DONE, 0x01);
560
561     return 0;
562 }
563
564 void load_screen(struct fb_info *info, bool initscreen)
565 {
566     int ret = -EINVAL;
567     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
568     struct rk29fb_screen *screen = inf->cur_screen;
569     u16 face;
570     u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
571     u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
572     u16 x_res = screen->x_res, y_res = screen->y_res;
573     u32 aclk_rate = 150000000;
574
575     if(!g_pdev){
576         printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
577         return;
578     }
579
580         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
581
582     // set the rgb or mcu
583     LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
584
585         // set out format and mcu timing
586     mcu_total  = (screen->mcu_wrperiod*150*1000)/1000000;
587     if(mcu_total>31)    mcu_total = 31;
588     if(mcu_total<3)     mcu_total = 3;
589     mcu_rwstart = (mcu_total+1)/4 - 1;
590     mcu_rwend = ((mcu_total+1)*3)/4 - 1;
591     mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
592     mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
593
594     fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
595         mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
596
597     LcdMskReg(inf, MCU_TIMING_CTRL,
598              m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
599              m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
600             v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
601             v_MCU_RW_END(mcu_rwend) |  v_MCU_WRITE_PERIOD(mcu_total) |
602             v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
603            );
604
605         // set synchronous pin polarity and data pin swap rule
606         switch (screen->face)
607         {
608         case OUT_P565:
609             face = OUT_P565;
610             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
611             break;
612         case OUT_P666:
613             face = OUT_P666;
614             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
615             break;
616         case OUT_D888_P565:
617             face = OUT_P888;
618             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
619             break;
620         case OUT_D888_P666:
621             face = OUT_P888;
622             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
623             break;
624         case OUT_P888:
625             face = OUT_P888;
626             LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
627             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
628             break;
629         default:
630             LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
631             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
632             face = screen->face;
633             break;
634     }
635
636      LcdMskReg(inf, DSP_CTRL0,
637         m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
638         m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
639         v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
640         v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
641         );
642
643      LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR,  v_BG_COLOR(0x000000) );
644
645      LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
646             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));
647
648         // set horizontal & vertical out timing
649         if(SCREEN_MCU==inf->cur_screen->type)
650     {
651             right_margin = x_res/6;
652         }
653
654     fbprintk("screen->hsync_len =%d,  screen->left_margin =%d, x_res =%d,  right_margin = %d \n",
655         screen->hsync_len , screen->left_margin , x_res , right_margin );
656     LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
657              v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
658     LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
659              v_BIT12HI(screen->hsync_len + screen->left_margin));
660
661     LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
662               v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
663     LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI,  v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
664               v_BIT11HI(screen->vsync_len + screen->upper_margin));
665
666     LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
667     LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
668
669         // let above to take effect
670     LcdWrReg(inf, REG_CFG_DONE, 0x01);
671
672     inf->dclk = clk_get(NULL, "dclk_lcdc");
673     if (IS_ERR(inf->dclk))
674     {
675         printk(KERN_ERR "failed to get lcd dclock source\n");
676         return ;
677     }
678
679     inf->aclk = clk_get(NULL, "aclk_lcdc");
680     if (IS_ERR(inf->aclk))
681     {
682         printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
683         return;
684     }
685     inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
686     if (IS_ERR(inf->aclk_parent))
687     {
688         printk(KERN_ERR "failed to get lcd clock parent source\n");
689         return ;
690     }
691
692     // set lcdc clk
693     if(SCREEN_MCU==screen->type)    screen->pixclock = 150000000; //mcu fix to 150 MHz
694
695     if(initscreen == 0)    //not init
696     {
697         clk_disable(inf->dclk);
698       //  clk_disable(inf->aclk);
699     }
700
701    // clk_disable(inf->aclk_ddr_lcdc);
702    // clk_disable(inf->aclk_disp_matrix);
703    // clk_disable(inf->hclk_cpu_display);
704
705    // clk_disable(inf->clk);
706     
707
708     fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
709
710     ret = clk_set_rate(inf->dclk, screen->pixclock);
711     if(ret)
712     {
713         printk(KERN_ERR ">>>>>> set lcdc dclk failed\n");
714     }
715     inf->fb0->var.pixclock = inf->fb1->var.pixclock = div_u64(1000000000000llu, clk_get_rate(inf->dclk));
716     if(initscreen)
717     {
718         ret = clk_set_parent(inf->aclk, inf->aclk_parent);
719         if(screen->lcdc_aclk){
720            aclk_rate = screen->lcdc_aclk;
721         }
722         ret = clk_set_rate(inf->aclk, aclk_rate);
723         if(ret){
724             printk(KERN_ERR ">>>>>> set lcdc aclk failed\n");
725         }
726         clk_enable(inf->aclk);
727     }
728   //  clk_enable(inf->aclk_ddr_lcdc);
729   //  clk_enable(inf->aclk_disp_matrix);
730   //  clk_enable(inf->hclk_cpu_display);       
731   //  clk_enable(inf->clk);
732     clk_enable(inf->dclk);
733
734     // init screen panel
735     if(screen->init)
736     {
737         screen->init();
738     }
739 }
740 #if 0 //def  CONFIG_CPU_FREQ
741 /*
742 * CPU clock speed change handler. We need to adjust the LCD timing
743 * parameters when the CPU clock is adjusted by the power management
744 * subsystem.
745 */
746 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
747
748 static int
749 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
750 {
751     struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
752     struct rk29fb_screen *screen = inf->cur_screen;
753     u32 dclk_rate = 0;
754
755     switch (val)
756     {
757     case CPUFREQ_PRECHANGE:
758           break;
759     case CPUFREQ_POSTCHANGE:
760         {
761          dclk_rate = screen->pixclock * 1000000;
762
763          fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
764
765          clk_set_rate(inf->dclk_divider, dclk_rate);
766          break;
767         }
768     }
769     return 0;
770 }
771 #endif
772
773 static inline unsigned int chan_to_field(unsigned int chan,
774                                          struct fb_bitfield *bf)
775 {
776         chan &= 0xffff;
777         chan >>= 16 - bf->length;
778         return chan << bf->offset;
779 }
780
781 static int fb_setcolreg(unsigned regno,
782                                unsigned red, unsigned green, unsigned blue,
783                                unsigned transp, struct fb_info *info)
784 {
785         unsigned int val;
786 //      fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
787
788         switch (info->fix.visual) {
789         case FB_VISUAL_TRUECOLOR:
790                 /* true-colour, use pseudo-palette */
791                 if (regno < 16) {
792                         u32 *pal = info->pseudo_palette;
793                         val  = chan_to_field(red,   &info->var.red);
794                         val |= chan_to_field(green, &info->var.green);
795                         val |= chan_to_field(blue,  &info->var.blue);
796                         pal[regno] = val;
797                 }
798                 break;
799         default:
800                 return -1;      /* unknown type */
801         }
802
803         return 0;
804 }
805
806 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
807 {
808     if (enable){
809         LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
810     }else{
811         LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
812         }
813         LcdWrReg(inf, REG_CFG_DONE, 0x01);
814         return 0;
815 }
816
817 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
818 {
819         struct rk29fb_screen *screen = inf->cur_screen;
820
821     /* set data */
822     if (x >= 0x800 || y >= 0x800 )
823         return -EINVAL;
824         //printk("%s: %08x,%08x \n",__func__, x, y);
825     x += (screen->left_margin + screen->hsync_len);
826     y += (screen->upper_margin + screen->vsync_len);
827     LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
828         LcdWrReg(inf, REG_CFG_DONE, 0x01);
829     return 0;
830 }
831
832
833 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
834 {
835         LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
836         LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
837         LcdWrReg(inf, REG_CFG_DONE, 0x01);
838     return 0;
839 }
840
841 #define RK29_CURSOR_WRITE_BIT(addr,mask,value)          (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
842 int rk29_set_cursor_img_transform(char *data)
843 {       int x, y;
844         char *pmsk = data;
845         char  *dst = (char*)rk29_cursor_buf;
846         unsigned char  dmsk = 0;
847         unsigned int   op,shift,offset;
848
849         /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
850          * clears it to transparent then combines the cursor
851          * shape plane with the colour plane to set the
852          * cursor */
853         for (y = 0; y < 32; y++)
854         {
855                 for (x = 0; x < 32; x++)
856                 {
857                         if ((x % 8) == 0) {
858                                 dmsk = *pmsk++;
859                         } else {
860                                 dmsk <<= 1;
861                         }
862                         op = (dmsk & 0x80) ? 2 : 3;
863                         shift = (x*2)%8;
864                         offset = x/4;
865                         RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
866                 }
867                 dst += 8;
868         }
869
870         return 0;
871 }
872
873
874
875 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
876 {
877     if(data)
878     {
879         rk29_set_cursor_img_transform(data);
880     }
881     else
882     {
883         rk29_set_cursor_img_transform(cursor_img);
884     }
885     LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
886     //LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
887     LcdSetBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
888     flush_cache_all();
889     LcdWrReg(inf, REG_CFG_DONE, 0x01);
890     return 0;
891 }
892
893
894 int rk29_set_cursor_test(struct fb_info *info)
895 {
896         struct rk29fb_inf *inf = dev_get_drvdata(info->device);
897         rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
898         rk29_set_cursor_pos(inf, 0, 0);
899         rk29_set_cursor_img(inf, 0);
900         rk29_set_cursor_en(inf, 1);
901         return 0;
902 }
903 #if 0
904
905 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
906 {
907     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
908
909     //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
910
911     /* check not being asked to exceed capabilities */
912
913     if (cursor->image.width > 32)
914         return -EINVAL;
915
916     if (cursor->image.height > 32)
917         return -EINVAL;
918
919     if (cursor->image.depth > 1)
920         return -EINVAL;
921
922     if (cursor->enable)
923         LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
924     else
925         LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
926
927     /* set data */
928     if (cursor->set & FB_CUR_SETPOS)
929     {
930         unsigned int x = cursor->image.dx;
931         unsigned int y = cursor->image.dy;
932
933         if (x >= 0x800 || y >= 0x800 )
934             return -EINVAL;
935         LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
936     }
937
938
939     if (cursor->set & FB_CUR_SETCMAP)
940     {
941         unsigned int bg_col = cursor->image.bg_color;
942         unsigned int fg_col = cursor->image.fg_color;
943
944         fbprintk("%s: update cmap (%08x,%08x)\n",
945             __func__, bg_col, fg_col);
946
947         LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
948                   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));
949
950         LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
951                          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));
952     }
953
954     if ((cursor->set & FB_CUR_SETSIZE ||
955         cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
956         && info->screen_base && info->fix.smem_start && info->fix.smem_len)
957     {
958         /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
959          * clears it to transparent then combines the cursor
960          * shape plane with the colour plane to set the
961          * cursor */
962         int x, y;
963         const unsigned char *pcol = cursor->image.data;
964         const unsigned char *pmsk = cursor->mask;
965         void __iomem   *dst;
966         unsigned long cursor_mem_start;
967         unsigned char  dcol = 0;
968         unsigned char  dmsk = 0;
969         unsigned int   op;
970
971         dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
972             cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
973
974         fbprintk("%s: setting shape (%d,%d)\n",
975             __func__, cursor->image.width, cursor->image.height);
976
977         memset(dst, 0, CURSOR_BUF_SIZE);
978
979         for (y = 0; y < cursor->image.height; y++)
980         {
981             for (x = 0; x < cursor->image.width; x++)
982             {
983                 if ((x % 8) == 0) {
984                     dcol = *pcol++;
985                     dmsk = *pmsk++;
986                 } else {
987                     dcol >>= 1;
988                     dmsk >>= 1;
989                 }
990
991                 if (dmsk & 1) {
992                     op = (dcol & 1) ? 1 : 3;
993                     op <<= ((x % 4) * 2);
994                     *(u8*)(dst+(x/4)) |= op;
995                 }
996             }
997             dst += (32*2)/8;
998         }
999         LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
1000         LcdWrReg(inf, HWC_MST, cursor_mem_start);
1001         // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1002         if(SCREEN_MCU == inf->cur_screen->type) {
1003             wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1004             wq_condition = 0;
1005         } else {
1006             wq_condition = 0;
1007             wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1008         }
1009         LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
1010     }
1011
1012     return 0;
1013 }
1014 #endif
1015 static int hdmi_get_fbscale(void)
1016 {
1017 #ifdef CONFIG_HDMI
1018         return hdmi_get_scale();
1019 #else
1020         return 100;
1021 #endif
1022 }
1023 static void hdmi_set_fbscale(struct fb_info *info)
1024 {
1025 #ifdef CONFIG_HDMI
1026     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1027     struct rk29fb_screen *screen = inf->cur_screen;
1028     struct win0_par *par = info->par;
1029         int scale;
1030         
1031         scale = hdmi_get_scale();
1032         if(scale == 100)
1033                 return;
1034         par->xpos += screen->x_res * (100-scale) / 200;
1035         par->ypos += screen->y_res * (100-scale) / 200;
1036         par->xsize = par->xsize *scale /100;
1037         par->ysize = par->ysize *scale /100;
1038 #endif
1039 }
1040 static int win0_blank(int blank_mode, struct fb_info *info)
1041 {
1042     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1043
1044     fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1045
1046         CHK_SUSPEND(inf);
1047
1048     switch(blank_mode)
1049     {
1050     case FB_BLANK_UNBLANK:
1051         LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1052             LcdWrReg(inf, REG_CFG_DONE, 0x01);
1053         break;
1054     case FB_BLANK_NORMAL:
1055          LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1056              break;
1057     default:
1058         LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1059             LcdWrReg(inf, REG_CFG_DONE, 0x01);
1060 #ifdef CONFIG_DDR_RECONFIG
1061         msleep(40);
1062 #endif
1063         break;
1064     }
1065
1066         mcu_refresh(inf);
1067     return 0;
1068 }
1069
1070 static int win0_set_par(struct fb_info *info)
1071 {
1072     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1073     struct rk29fb_screen *screen = inf->cur_screen;
1074     struct fb_var_screeninfo *var = &info->var;
1075     struct fb_fix_screeninfo *fix = &info->fix;
1076     struct win0_par *par = info->par;
1077         u32 xact, yact, xvir, yvir, xpos, ypos, ScaleYrgbX,ScaleYrgbY, ScaleCbrX, ScaleCbrY, y_addr,uv_addr;
1078         hdmi_set_fbscale(info);
1079         xact = var->xres;                           /* visible resolution               */
1080         yact = var->yres;
1081         xvir = var->xres_virtual;               /* virtual resolution           */
1082         yvir = var->yres_virtual;
1083         //u32 xact_st = var->xoffset;         /* offset from virtual to visible */
1084         //u32 yact_st = var->yoffset;         /* resolution                     */
1085     xpos = par->xpos;
1086     ypos = par->ypos;
1087
1088     ScaleYrgbX=0x1000;
1089         ScaleYrgbY=0x1000;
1090     ScaleCbrX=0x1000;
1091         ScaleCbrY=0x1000;
1092
1093     y_addr = 0;       //user alloc buf addr y
1094     uv_addr = 0;
1095
1096     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1097
1098         CHK_SUSPEND(inf);
1099
1100     if((var->rotate%360!=0)&& (inf->video_mode))
1101     {
1102       #ifdef CONFIG_FB_ROTATE_VIDEO  
1103         if(xact > screen->x_res)
1104         {
1105             xact = screen->x_res;       /* visible resolution       */
1106             yact = screen->y_res;
1107             xvir = screen->x_res;       /* virtual resolution       */
1108             yvir = screen->y_res;
1109         }   else   {            
1110             xact = var->xres;               /* visible resolution       */
1111             yact = var->yres;
1112             xvir = var->xres_virtual;       /* virtual resolution       */
1113             yvir = var->yres_virtual;
1114                         printk("xact=%d yact =%d \n",xact,yact);
1115         }
1116       #else //CONFIG_FB_ROTATE_VIDEO
1117         printk("LCDC not support rotate!\n");
1118         return -EINVAL;
1119       #endif
1120     }
1121     
1122         // calculate the display phy address
1123     y_addr = fix->smem_start + par->y_offset;
1124     uv_addr = fix->mmio_start + par->c_offset;
1125
1126     ScaleYrgbX = CalScaleW0(xact, par->xsize);
1127     ScaleYrgbY = CalScaleW0(yact, par->ysize);
1128
1129     switch (par->format)
1130     {
1131        case 2:// yuv422
1132            ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1133            ScaleCbrY =  CalScaleW0(yact, par->ysize);
1134            break;
1135        case 3: // yuv4200
1136        case 4: // yuv4201
1137            ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1138            ScaleCbrY =  CalScaleW0(yact/2, par->ysize);
1139            break;
1140        case 5:// yuv444
1141            ScaleCbrX= CalScaleW0(xact, par->xsize);
1142            ScaleCbrY =  CalScaleW0(yact, par->ysize);
1143            break;
1144        default:
1145            break;
1146     }
1147
1148     xpos += (screen->left_margin + screen->hsync_len);
1149     ypos += (screen->upper_margin + screen->vsync_len);
1150
1151     LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1152     LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1153
1154     LcdMskReg(inf, SYS_CONFIG,  m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1155
1156     LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1157     LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1158     LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1159     LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI,  v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1160     LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1161     LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1162
1163     switch(par->format)
1164     {
1165     case 0:  //rgb888
1166         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,
1167             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));
1168                 break;
1169     case 1:  //rgb565
1170         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,
1171             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));
1172         break;
1173     case 4:   //yuv4201
1174         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,
1175             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) |
1176             v_W0_YRGB_M8_SWAP(1) | v_W0_CBR_8_SWAP(0));
1177         break;
1178     default:
1179         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,
1180             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) );
1181                 break;
1182     }
1183
1184     LcdWrReg(inf, REG_CFG_DONE, 0x01);
1185
1186     return 0;
1187
1188 }
1189
1190 static int win0_pan( struct fb_info *info )
1191 {
1192     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1193    // struct fb_var_screeninfo *var0 = &info->var;
1194     struct fb_fix_screeninfo *fix0 = &info->fix;
1195     struct win0_par *par = info->par;
1196     u32 y_addr=0, uv_addr=0;
1197
1198     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1199
1200         CHK_SUSPEND(inf);
1201
1202     y_addr = fix0->smem_start +  par->y_offset;//y_offset;
1203     uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1204
1205     LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1206     LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1207     LcdWrReg(inf, REG_CFG_DONE, 0x01);
1208
1209      // enable win0 after the win0 addr is seted
1210         LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1211         mcu_refresh(inf);
1212
1213     return 0;
1214 }
1215
1216 static int win1_blank(int blank_mode, struct fb_info *info)
1217 {
1218     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1219
1220     fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1221
1222         CHK_SUSPEND(inf);
1223
1224         switch(blank_mode)
1225     {
1226     case FB_BLANK_UNBLANK:
1227         LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1228         LcdWrReg(inf, REG_CFG_DONE, 0x01);
1229         break;
1230     case FB_BLANK_NORMAL:
1231          LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1232              break;
1233     default:
1234         LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1235         LcdWrReg(inf, REG_CFG_DONE, 0x01);
1236         break;
1237     }
1238     
1239
1240         mcu_refresh(inf);
1241     return 0;
1242 }
1243
1244
1245 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC 
1246 static void win1_check_work_func(struct work_struct *work)
1247 {
1248     struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
1249     struct fb_info *fb0_inf = inf->fb0;
1250      struct fb_var_screeninfo *var = &fb0_inf->var;
1251     int i=0;
1252     int *p = NULL;
1253     int blank_data,total_data;
1254     int format = 0;
1255     u16 xres_virtual = fb0_inf->var.xres_virtual;      //virtual screen size
1256     u16 xpos_virtual = fb0_inf->var.xoffset;           //visiable offset in virtual screen
1257     u16 ypos_virtual = fb0_inf->var.yoffset;
1258
1259     int offset = 0;//(ypos_virtual*xres_virtual + xpos_virtual)*((inf->fb0_color_deepth || fb0_inf->var.bits_per_pixel==32)? 4:2)/4;  
1260     switch(var->bits_per_pixel)
1261     {
1262         case 16: 
1263             format = 1;
1264             offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1265             if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1266                 offset -= var->yres * var->xres *2;
1267             break;
1268         default:
1269             format = 0;
1270             offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;            
1271             if(ypos_virtual >= 2*var->yres)
1272             {
1273                 format = 1;
1274                 if(ypos_virtual == 3*var->yres)
1275                 {            
1276                     offset -= var->yres * var->xres *2;
1277                 }
1278             }
1279             break;
1280     }
1281     p = (u32)fb0_inf->screen_base + offset; 
1282     blank_data = (inf->fb0_color_deepth==32) ? 0xff000000 : 0;
1283     total_data = fb0_inf->var.xres * fb0_inf->var.yres / (format+1);
1284     
1285    // printk("var->bits_per_pixel=%d,ypos_virtual=%d, var->yres=%d,offset=%d,total_data=%d\n",var->bits_per_pixel,ypos_virtual,var->yres,offset,total_data);
1286     
1287     for(i=0; i < total_data; i++)
1288     {
1289         if(*p++ != blank_data) 
1290         {
1291             //printk("win1 have no 0 data in %d, total %d\n",i,total_data);
1292             return;
1293         }            
1294     }
1295
1296     win1_blank(FB_BLANK_POWERDOWN, fb0_inf);
1297    // printk("%s close win1!\n",__func__);
1298 }
1299 static DECLARE_DELAYED_WORK(rk29_win1_check_work, win1_check_work_func);
1300 #endif
1301 static int win1_set_par(struct fb_info *info)
1302 {
1303     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1304     struct fb_fix_screeninfo *fix = &info->fix;
1305     struct rk29fb_screen *screen = inf->cur_screen;
1306     struct win0_par *par = info->par;
1307     struct fb_var_screeninfo *var = &info->var;
1308         u32 addr;
1309         u16 xres_virtual,xpos,ypos;
1310         u8 trspval,trspmode;
1311  #ifdef CONFIG_CLOSE_WIN1_DYNAMIC   
1312     cancel_delayed_work_sync(&rk29_win1_check_work);
1313  #endif   
1314     if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1315             #ifndef     CONFIG_FB_SCALING_OSD_1080P
1316             && !((screen->x_res>1280) && (var->bits_per_pixel == 32))
1317                 #endif
1318                 )
1319     {
1320         hdmi_set_fbscale(info);
1321     }
1322                 #ifndef CONFIG_FB_SCALING_OSD_1080P
1323                 else  if(((screen->x_res==1920) ))
1324     {
1325         if(hdmi_get_fbscale() < 100)
1326                         par->ypos -=screen->y_res * (100-hdmi_get_fbscale()) / 200;
1327         }
1328                 #endif
1329     //u32 offset=0, addr=0, map_size=0, smem_len=0;
1330     addr=0;
1331     xres_virtual = 0;      //virtual screen size
1332
1333     //u16 xpos_virtual = var->xoffset;           //visiable offset in virtual screen
1334     //u16 ypos_virtual = var->yoffset;
1335
1336     xpos = par->xpos;                 //visiable offset in panel
1337     ypos = par->ypos;
1338
1339     trspmode = TRSP_CLOSE;
1340     trspval = 0;
1341
1342     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1343
1344    #ifdef CONFIG_FB_SCALING_OSD
1345     if(((screen->x_res != var->xres) || (screen->y_res != var->yres)) 
1346         #ifndef CONFIG_FB_SCALING_OSD_1080P
1347             && (screen->x_res<=1280)
1348                 #endif
1349                 )
1350     {
1351         addr = fix->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1352         xres_virtual = screen->x_res* hdmi_get_fbscale()/100;      //virtual screen size
1353     }
1354     else
1355    #endif
1356     {
1357         addr = fix->smem_start + par->y_offset;
1358         xres_virtual = var->xres_virtual;      //virtual screen size
1359     }
1360     LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(fb1_open_init?0:1)|v_W1_FORMAT(par->format));
1361
1362     xpos += (screen->left_margin + screen->hsync_len);
1363     ypos += (screen->upper_margin + screen->vsync_len);
1364
1365     LcdWrReg(inf, WIN1_YRGB_MST, addr);
1366
1367     LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1368     LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1369
1370     LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1371
1372     LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN |  m_W1_BLEND_FACTOR,
1373         v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1374
1375      // enable win1 color key and set the color to black(rgb=0)
1376     LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1377
1378     if(1==par->format) //rgb565
1379     {
1380         LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1381             v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1382     }
1383     else
1384     {
1385          LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1386                 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1387
1388          LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1389     }
1390
1391         LcdWrReg(inf, REG_CFG_DONE, 0x01);
1392     
1393 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC 
1394     schedule_delayed_work(&rk29_win1_check_work, msecs_to_jiffies(5000));
1395 #endif
1396
1397     return 0;
1398 }
1399
1400 static int win1_pan( struct fb_info *info )
1401 {
1402     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1403     struct fb_fix_screeninfo *fix1 = &info->fix;
1404     struct win0_par *par = info->par;
1405     u32 addr = 0;
1406
1407     #ifdef CONFIG_FB_SCALING_OSD
1408     struct rk29fb_screen *screen = inf->cur_screen;
1409     struct fb_var_screeninfo *var = &info->var;
1410     if(((screen->x_res != var->xres) || (screen->y_res != var->yres)) 
1411         #ifndef CONFIG_FB_SCALING_OSD_1080P
1412             && (screen->x_res<=1280)
1413                 #endif
1414                 )
1415     {
1416         addr = fix1->mmio_start + par->y_offset* hdmi_get_fbscale()/100;
1417     }
1418     else
1419     #endif
1420     {
1421         addr = fix1->smem_start + par->y_offset;
1422     }
1423
1424     //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1425
1426     LcdWrReg(inf, WIN1_YRGB_MST, addr);
1427     LcdWrReg(inf, REG_CFG_DONE, 0x01);
1428         mcu_refresh(inf);
1429
1430     return 0;
1431 }
1432
1433 static int fb0_blank(int blank_mode, struct fb_info *info)
1434 {
1435         struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1436
1437     if(inf->video_mode == 1)
1438     {
1439         win1_blank(blank_mode, info);
1440     }
1441     else
1442     {
1443         win0_blank(blank_mode, info);
1444     }
1445     return 0;
1446 }
1447
1448 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1449 {
1450     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1451     struct rk29fb_screen *screen = inf->cur_screen;
1452     u16 xpos = (var->nonstd>>8) & 0xfff;
1453     u16 ypos = (var->nonstd>>20) & 0xfff;
1454     u16 xlcd = screen->x_res;
1455     u16 ylcd = screen->y_res;
1456
1457     //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1458
1459         CHK_SUSPEND(inf);
1460
1461     if( 0==var->xres_virtual || 0==var->yres_virtual ||
1462         0==var->xres || 0==var->yres || var->xres<16 ||
1463         ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1464     {
1465         printk(">>>>>> fb0_check_var fail 1!!! \n");
1466         printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1467         printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1468         printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1469         return -EINVAL;
1470     }
1471
1472     if( (var->xoffset+var->xres)>var->xres_virtual ||
1473         (var->yoffset+var->yres)>var->yres_virtual*2 )
1474     {
1475         printk(">>>>>> fb0_check_var fail 2!!! \n");
1476         printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1477         printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1478         printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1479         return -EINVAL;
1480     }
1481
1482     if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1483     switch(var->bits_per_pixel)
1484     {
1485     case 16:    // rgb565
1486         var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1487         var->xres = (var->xres + 0x1) & (~0x1);
1488         var->xoffset = (var->xoffset) & (~0x1);
1489         break;
1490     default:    // rgb888
1491         var->bits_per_pixel = 32;
1492         break;
1493     }
1494
1495     return 0;
1496 }
1497
1498
1499 static int fb0_set_par(struct fb_info *info)
1500 {
1501     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1502     struct fb_var_screeninfo *var = &info->var;
1503     struct fb_fix_screeninfo *fix = &info->fix;
1504     struct rk29fb_screen *screen = inf->cur_screen;
1505     struct win0_par *par = info->par;
1506
1507     u32 offset=0,  smem_len=0;
1508     u16 xres_virtual = var->xres_virtual;      //virtual screen size
1509     u16 xpos_virtual = var->xoffset;           //visiable offset in virtual screen
1510     u16 ypos_virtual = var->yoffset;
1511
1512 #ifdef CONFIG_FB_SCALING_OSD
1513     struct rk29_ipp_req ipp_req;
1514     u32 dstoffset=0;
1515         memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1516 #endif
1517
1518     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1519         wait_event_interruptible(fb0_wait_queue, idle_condition);
1520         idle_condition = 0;
1521
1522     inf->setFlag = 0;
1523         CHK_SUSPEND(inf);
1524
1525     if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1526     #if !defined(CONFIG_FB_SCALING_OSD)
1527     if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1528     #endif
1529
1530     switch(var->bits_per_pixel)
1531     {
1532     case 16:    // rgb565
1533         par->format = 1;
1534          if( ypos_virtual == 0)
1535             fb0_first_buff_bits = 16;
1536         else
1537             fb0_second_buff_bits = 16;
1538
1539         //fix->line_length = 2 * xres_virtual;
1540         fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual;   //32bit and 16bit change
1541
1542         #ifdef CONFIG_FB_SCALING_OSD
1543         dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1544         ipp_req.src0.fmt = IPP_RGB_565;
1545         ipp_req.dst0.fmt = IPP_RGB_565;
1546         #endif
1547         offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1548         if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1549             offset -= var->yres * var->xres *2;
1550         break;
1551     case 32:    // rgb888
1552     default:
1553         par->format = 0;
1554          if( ypos_virtual == 0)
1555             fb0_first_buff_bits = 32;
1556         else
1557             fb0_second_buff_bits = 32;
1558         fix->line_length = 4 * xres_virtual;
1559         #ifdef CONFIG_FB_SCALING_OSD
1560         dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;       
1561
1562         ipp_req.src0.fmt = IPP_XRGB_8888;
1563         ipp_req.dst0.fmt = IPP_XRGB_8888;
1564         #endif
1565         offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1566         
1567         if(ypos_virtual >= 2*var->yres)
1568         {
1569             par->format = 1;
1570             #ifdef CONFIG_FB_SCALING_OSD
1571             dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1572             ipp_req.src0.fmt = IPP_RGB_565;
1573             ipp_req.dst0.fmt = IPP_RGB_565;
1574             #endif
1575             if(ypos_virtual == 3*var->yres)
1576             {            
1577                 offset -= var->yres * var->xres *2;
1578             }
1579         }
1580         break;
1581     }
1582
1583     smem_len = fix->line_length * var->yres_virtual;
1584     //map_size = PAGE_ALIGN(smem_len);
1585
1586     if (smem_len > fix->smem_len)     // buffer need realloc
1587     {
1588         printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1589         printk("line_length = %d, yres_virtual = %d, win1_buf only = %dB\n",fix->line_length,var->yres_virtual,fix->smem_len);
1590         printk("you can change buf size MEM_FB_SIZE in board-xxx.c \n");
1591     }
1592
1593
1594     par->addr_seted = 1;
1595 #if ANDROID_USE_THREE_BUFS
1596     if(0==new_frame_seted) {
1597         wq_condition = 0;
1598         wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1599     }
1600     new_frame_seted = 0;
1601 #endif
1602
1603     if(inf->video_mode == 1)
1604     {
1605         #ifdef CONFIG_FB_SCALING_OSD
1606         if(((screen->x_res != var->xres) || (screen->y_res != var->yres)) 
1607                 #ifndef CONFIG_FB_SCALING_OSD_1080P
1608             && (screen->x_res<=1280)
1609                 #endif
1610                 )
1611         {
1612             par->xpos = 0;
1613             par->ypos = 0;
1614             par->xsize = screen->x_res;
1615             par->ysize = screen->y_res;
1616             par->y_offset = dstoffset;
1617
1618             ipp_req.src0.YrgbMst = fix->smem_start + offset;
1619             ipp_req.src0.w = var->xres;
1620             ipp_req.src0.h = var->yres;
1621
1622             ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1623             ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1624             ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1625
1626             ipp_req.src_vir_w = ipp_req.src0.w;
1627             ipp_req.dst_vir_w = ipp_req.dst0.w;
1628             ipp_req.timeout = 100;
1629             ipp_req.flag = IPP_ROT_0;
1630             //ipp_do_blit(&ipp_req);
1631             ipp_blit_sync(&ipp_req);
1632         }else
1633         #endif
1634         {
1635             par->y_offset = offset;
1636             par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0;              //visiable offset in panel
1637             par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1638             par->xsize = var->xres;                                //visiable size in panel
1639             par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1640         }
1641         win1_set_par(info);
1642     }
1643     else
1644     {
1645         par->y_offset = offset;
1646         par->xpos = 0;
1647         par->ypos = 0;
1648         par->xsize = screen->x_res;
1649         par->ysize = screen->y_res;
1650         win0_set_par(info);
1651     }
1652     inf->setFlag = 1;
1653         idle_condition = 1;
1654         wake_up_interruptible_sync(&fb0_wait_queue);
1655     return 0;
1656 }
1657
1658 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1659 {
1660
1661     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1662     struct fb_var_screeninfo *var1 = &info->var;
1663     struct rk29fb_screen *screen = inf->cur_screen;
1664     struct win0_par *par = info->par;
1665
1666     u32 offset = 0;
1667     u16 ypos_virtual = var->yoffset;
1668     u16 xpos_virtual = var->xoffset;
1669    #ifdef CONFIG_FB_SCALING_OSD
1670     struct fb_fix_screeninfo *fix = &info->fix;
1671     struct rk29_ipp_req ipp_req;
1672     u32 dstoffset = 0;
1673         memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
1674    #endif
1675         //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1676
1677         CHK_SUSPEND(inf);
1678
1679     if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1680     #if !defined(CONFIG_FB_SCALING_OSD)
1681         if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1682     #endif
1683
1684     switch(var1->bits_per_pixel)
1685     {
1686     case 16:    // rgb565
1687         var->xoffset = (var->xoffset) & (~0x1);
1688         #ifdef CONFIG_FB_SCALING_OSD
1689         dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1690         ipp_req.src0.fmt = IPP_RGB_565;
1691         ipp_req.dst0.fmt = IPP_RGB_565;
1692         #endif
1693         offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1694         if(ypos_virtual == 3*var->yres && inf->fb0_color_deepth)
1695             offset -= var->yres * var->xres *2;
1696         break;
1697     case 32:    // rgb888
1698         #ifdef CONFIG_FB_SCALING_OSD
1699         dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1700         ipp_req.src0.fmt = IPP_XRGB_8888;
1701         ipp_req.dst0.fmt = IPP_XRGB_8888;
1702         #endif
1703         offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1704         if(ypos_virtual >= 2*var->yres)
1705         {
1706             par->format = 1;
1707             #ifdef CONFIG_FB_SCALING_OSD
1708                 dstoffset = (((ypos_virtual-2*var->yres)*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1709             ipp_req.src0.fmt = IPP_RGB_565;
1710             ipp_req.dst0.fmt = IPP_RGB_565;
1711             #endif
1712             if(ypos_virtual == 3*var->yres)
1713             {            
1714                 offset -= var->yres * var->xres *2;
1715             }
1716         }
1717         break;
1718     default:
1719         return -EINVAL;
1720     }
1721
1722     if(inf->video_mode == 1)
1723     {
1724         #ifdef CONFIG_FB_SCALING_OSD
1725         if(((screen->x_res != var->xres) || (screen->y_res != var->yres)) 
1726         #ifndef CONFIG_FB_SCALING_OSD_1080P
1727             && (screen->x_res<=1280)
1728                 #endif
1729                 )
1730         {
1731             par->y_offset = dstoffset;
1732
1733             ipp_req.src0.YrgbMst = fix->smem_start + offset;
1734             ipp_req.src0.w = var->xres;
1735             ipp_req.src0.h = var->yres;
1736
1737             ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset* hdmi_get_fbscale()/100;
1738             ipp_req.dst0.w = screen->x_res* hdmi_get_fbscale()/100;
1739             ipp_req.dst0.h = screen->y_res* hdmi_get_fbscale()/100;
1740
1741             ipp_req.src_vir_w = ipp_req.src0.w;
1742             ipp_req.dst_vir_w = ipp_req.dst0.w;
1743             ipp_req.timeout = 100;
1744             ipp_req.flag = IPP_ROT_0;
1745             //ipp_do_blit(&ipp_req);
1746             ipp_blit_sync(&ipp_req);
1747             win1_pan(info);
1748             return 0;
1749         }else
1750         #endif
1751             par->y_offset = offset;
1752         win1_pan(info);
1753     }
1754     else
1755     {
1756         par->y_offset = offset;
1757         win0_pan(info);
1758     }
1759         // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1760 #if !ANDROID_USE_THREE_BUFS
1761     // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1762     if(SCREEN_MCU == inf->cur_screen->type) {
1763         wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1764         wq_condition = 0;
1765     } else {
1766         wq_condition = 0;
1767         wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1768     }
1769 #endif
1770     return 0;
1771 }
1772
1773 #ifdef  FB_WIMO_FLAG
1774 unsigned long temp_vv;
1775 static int frame_num = 0;
1776 static int wimo_set_buff(struct fb_info *info,unsigned long *temp)
1777 {
1778         struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1779
1780         ui_buffer = temp[0];
1781         ui_buffer_map = ioremap(temp[0],temp[1]);
1782         if(ui_buffer_map == NULL)
1783         {
1784                 printk("can't map a buffer for ui\n");
1785                 return -EFAULT;
1786         }
1787
1788         printk("ui_buffer %x  ",ui_buffer_map);
1789         memset(&wimo_info,0,sizeof(wimo_info) );
1790  
1791       wimo_info.mode = inf->video_mode;
1792 //      wimo_info.bitperpixel = var->bits_per_pixel;            
1793     
1794
1795         wimo_info.dst_width = (temp[2] + 15) & 0xfff0;
1796         wimo_info.dst_height = (temp[3] + 15) & 0xfff0;
1797 }
1798 static int wimo_get_buff(struct fb_info *info)
1799 {
1800         
1801         struct rk29_ipp_req overlay_req;
1802         struct rk29_ipp_req overlay_req_1;
1803         struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1804         int ret;
1805         memset(&overlay_req, 0 , sizeof(overlay_req));
1806         memset(&overlay_req_1, 0 , sizeof(overlay_req_1));
1807         
1808         if(inf->video_mode == 0 )
1809         {
1810                 struct win0_par *par = info->par;
1811                 wimo_info.xpos = 0;
1812                 wimo_info.ypos = 0;
1813                 wimo_info.xsize = 0;
1814                 wimo_info.ysize = 0;
1815                 wimo_info.mode = 0;
1816                 if(par->format == 1)
1817                         wimo_info.bitperpixel = 16;
1818                 else
1819                         wimo_info.bitperpixel =32;// wimo_info.bitperpixel_fb1;
1820                 overlay_req.src0.YrgbMst = info->fix.smem_start + par->y_offset;//info->screen_base + par->y_offset;//info_buffer[8];
1821                 overlay_req.src0.CbrMst = info->fix.smem_start + par->y_offset + wimo_info.dst_width * wimo_info.dst_height;//dst_width*dst_height;//+ par->y_offset + dst_width*dst_height;//info_buffer[9];
1822                 overlay_req.src0.w = wimo_info.dst_width ;//dst_width;//info_buffer[2];
1823                 overlay_req.src0.h = wimo_info.dst_height ;//dst_height;//info_buffer[3];
1824                 overlay_req.src0.fmt = (wimo_info.bitperpixel == 16) ? 1 : 0;//3;
1825                 overlay_req.dst0.YrgbMst = ui_buffer;//overlay_buffer + info_buffer[4] + info_buffer[5] * dst_width;
1826                 overlay_req.dst0.CbrMst = ui_buffer + wimo_info.dst_width * wimo_info.dst_height;//dst_width*dst_height;//(unsigned char*) overlay_buffer + dst_width*dst_height +info_buffer[4] + (  info_buffer[5] * dst_width) / 2;// info_buffer[6] * info_buffer[7];
1827                 overlay_req.dst0.w = wimo_info.dst_width ;//dst_width;//info_buffer[6];
1828                 overlay_req.dst0.h = wimo_info.dst_height ;//dst_height;//info_buffer[7];
1829                 overlay_req.dst0.fmt = (wimo_info.bitperpixel== 16) ? 1 : 0;//3;3;
1830                 overlay_req.deinterlace_enable = 0;
1831                 overlay_req.timeout = 1000000;
1832                 overlay_req.src_vir_w = wimo_info.dst_width ;//dst_width;//info_buffer[2];
1833                 overlay_req.dst_vir_w = wimo_info.dst_width ;//dst_width;
1834                 overlay_req.flag = IPP_ROT_0;
1835                 ipp_blit_sync(&overlay_req);
1836                 
1837                 ret = 0;
1838         }       
1839         else
1840         {
1841
1842                 int err = 0;
1843                 static int wimo_time = 0;
1844                 unsigned long *overlay_buffer_map_temp;
1845                 unsigned long *map_temp;
1846                 unsigned long sign_memset = 0;
1847                 struct fb_var_screeninfo *var = &inf->fb1->var;
1848                 struct win0_par *par = inf->fb1->par;
1849                 wimo_info.mode = 1;
1850         //      printk("overlay setbuffer in\n");
1851         //      mutex_lock(&wimo_info.fb_lock);
1852                 wimo_info.fb_lock = 1;
1853                 {
1854                         wimo_info.xaff = var->xres;
1855                         wimo_info.yaff = var->yres;
1856                         if((wimo_info.xpos != par->xpos) ||(wimo_info.ypos != par->ypos)||(wimo_info.xsize != par->xsize) ||(wimo_info.ysize != par->ysize))
1857                         {
1858                                 wimo_info.xpos = par->xpos;
1859                                 wimo_info.ypos = par->ypos;
1860                                 wimo_info.xsize = par->xsize;
1861                                 wimo_info.ysize = par->ysize;
1862                                 sign_memset = 1;
1863                                 memset(ui_buffer_map,0,wimo_info.dst_height * wimo_info.dst_width);//dst_width*dst_height);
1864                                 memset(ui_buffer_map + wimo_info.dst_height * wimo_info.dst_width, 0x80,wimo_info.dst_height * wimo_info.dst_width / 2);//dst_width*dst_height,0x80,dst_width*dst_height/2);
1865                                 printk("wimo_info.xpos %d wimo_info.ypos %d wimo_info.xsize %d wimo_info.ysize %d\n",wimo_info.xpos, wimo_info.ypos, wimo_info.xsize, wimo_info.ysize );
1866                         }
1867                 }
1868                 //printk("wimo_info.xpos %d wimo_info.ypos %d wimo_info.xsize %d wimo_info.ysize %d\n",wimo_info.xpos, wimo_info.ypos, wimo_info.xsize, wimo_info.ysize );
1869                 if(wimo_info.xaff * 3 < wimo_info.xsize || wimo_info.yaff * 3 < wimo_info.ysize)// 3time or bigger scale up
1870                 {
1871                         unsigned long mid_width, mid_height;
1872                         struct rk29_ipp_req overlay_req_1;
1873                         if(wimo_info.xaff * 3 < wimo_info.xsize)
1874                                 mid_width = wimo_info.xaff * 3;
1875                         else
1876                                 mid_width = wimo_info.xsize;
1877                         
1878                         if(wimo_info.yaff * 3 < wimo_info.ysize)
1879                                 mid_height =  wimo_info.yaff * 3;
1880                         else
1881                                 mid_height = wimo_info.ysize;
1882                         overlay_req.src0.YrgbMst = wimo_info.src_y;//info_buffer[8];
1883                         overlay_req.src0.CbrMst = wimo_info.src_uv;//info_buffer[9];
1884                         overlay_req.src0.w = wimo_info.xaff;// info_buffer[2];
1885                         overlay_req.src0.h = wimo_info.yaff;// info_buffer[3];
1886                         overlay_req.src0.fmt = 3;
1887                         overlay_req.dst0.YrgbMst = ui_buffer + 2048000 ;//info_buffer[4] + info_buffer[5] * dst_width;   //С³ß´çƬԴÐèÒª2´Î·Å´ó£¬ËùÒÔ½«bufferµÄºó°ë¶ÎÓÃÓÚ»º´æ
1888                         overlay_req.dst0.CbrMst = (unsigned char*) ui_buffer + mid_height * mid_width + 2048000;
1889                 
1890                         overlay_req.dst0.w = mid_width;//info_buffer[6];
1891                         overlay_req.dst0.h = mid_height;//info_buffer[7];
1892                         overlay_req.dst0.fmt = 3;
1893                         overlay_req.timeout = 100000;
1894                         overlay_req.src_vir_w = wimo_info.xaff;//info_buffer[2];
1895                         overlay_req.dst_vir_w = mid_width;//dst_width;
1896                         overlay_req.flag = IPP_ROT_0;
1897
1898                         overlay_req_1.src0.YrgbMst = ui_buffer + 2048000;
1899                         overlay_req_1.src0.CbrMst = (unsigned char*) ui_buffer + mid_height * mid_width + 2048000;
1900                         overlay_req_1.src0.w = mid_width;
1901                         overlay_req_1.src0.h = mid_height;// info_buffer[3];
1902                         overlay_req_1.src0.fmt = 3;
1903                         overlay_req_1.dst0.YrgbMst = ui_buffer + ((wimo_info.xpos + 1)&0xfffe) + wimo_info.ypos * wimo_info.dst_width;//info_buffer[4] + info_buffer[5] * dst_width;
1904                         overlay_req_1.dst0.CbrMst =(unsigned char*) ui_buffer + wimo_info.dst_width * wimo_info.dst_height + ((wimo_info.xpos + 1)&0xfffe) + ( wimo_info.ypos  / 2)* wimo_info.dst_width ;
1905                         
1906                         overlay_req_1.dst0.w = wimo_info.xsize;//info_buffer[6];
1907                         overlay_req_1.dst0.h = wimo_info.ysize;//info_buffer[7];
1908                         overlay_req_1.dst0.fmt = 3;
1909                         overlay_req_1.timeout = 100000;
1910                         overlay_req_1.src_vir_w = mid_width;//info_buffer[2];
1911                         overlay_req_1.dst_vir_w = wimo_info.dst_width;//dst_width;
1912                         overlay_req_1.flag = IPP_ROT_0;
1913                         
1914
1915                         err = ipp_blit_sync(&overlay_req);
1916                         dmac_flush_range(ui_buffer_map,ui_buffer_map + wimo_info.dst_height * wimo_info.dst_width * 3/2);//dst_width*dst_height*3/2);
1917                         err = ipp_blit_sync(&overlay_req_1);
1918         
1919                 }
1920                 else
1921                 {
1922                         overlay_req.src0.YrgbMst = wimo_info.src_y;//info_buffer[8];
1923                         overlay_req.src0.CbrMst = wimo_info.src_uv;//info_buffer[9];
1924                         overlay_req.src0.w = wimo_info.xaff;// info_buffer[2];
1925                         overlay_req.src0.h = wimo_info.yaff;// info_buffer[3];
1926                         overlay_req.src0.fmt = 3;
1927                         overlay_req.dst0.YrgbMst = ui_buffer + ((wimo_info.xpos + 1)&0xfffe) + wimo_info.ypos * wimo_info.dst_width;//info_buffer[4] + info_buffer[5] * dst_width;
1928                         overlay_req.dst0.CbrMst =(unsigned char*) ui_buffer + wimo_info.dst_width * wimo_info.dst_height + ((wimo_info.xpos + 1)&0xfffe) + ( wimo_info.ypos  / 2)* wimo_info.dst_width ;
1929                         
1930                         overlay_req.dst0.w = wimo_info.xsize;//wimo_info.xsize;//wimo_info.xaff;// wimo_info.xsize;//info_buffer[6];
1931                         overlay_req.dst0.h = (wimo_info.ysize + 1) & 0xfffe;//(wimo_info.ysize + 1) & 0xfffe;//wimo_info.yaff;//(wimo_info.ysize + 1) & 0xfffe;//info_buffer[7];
1932                         overlay_req.dst0.fmt = 3;
1933                         overlay_req.timeout = 100000;
1934                         overlay_req.src_vir_w = wimo_info.xaff;//info_buffer[2];
1935                         overlay_req.dst_vir_w = wimo_info.dst_width;//wimo_info.dst_width;//wimo_info.yaff;//wimo_info.dst_width;//dst_width;
1936                         overlay_req.flag = IPP_ROT_0;
1937                         
1938                         dmac_flush_range(ui_buffer_map,ui_buffer_map + wimo_info.dst_height * wimo_info.dst_width * 3/2);//dst_width*dst_height*3/2);
1939                         err = ipp_blit_sync(&overlay_req);
1940                 
1941                 }
1942         //      printk("overlay setbuffer exit\n");
1943                 ret = 1;
1944                 wimo_info.fb_lock = 0;
1945         }
1946         
1947                 
1948         return ret;
1949 }
1950 #endif
1951 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1952 {
1953     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1954         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1955
1956         CHK_SUSPEND(inf);
1957
1958     switch(cmd)
1959     {
1960     case FB0_IOCTL_STOP_TIMER_FLUSH:    //stop timer flush mcu panel after android is runing
1961         if(1==arg)
1962         {
1963             inf->mcu_usetimer = 0;
1964         }
1965         break;
1966    case FBIOPUT_16OR32:
1967
1968         inf->fb0_color_deepth = arg;
1969
1970             break;
1971         case FBIOGET_16OR32:
1972             return  inf->fb0_color_deepth;
1973         case FBIOGET_IDLEFBUff_16OR32:
1974         if(info->var.yoffset == 0)
1975         {
1976             return fb0_second_buff_bits;
1977         }
1978         else
1979         {
1980             return fb0_first_buff_bits;
1981         }
1982     case FBIOSET_COMPOSE_LAYER_COUNTS:
1983         fb_compose_layer_count = arg;
1984         break;
1985
1986     case FBIOGET_COMPOSE_LAYER_COUNTS:
1987         
1988         return fb_compose_layer_count;
1989         
1990         case FBIOPUT_FBPHYADD:
1991         return info->fix.smem_start;
1992     case FBIOGET_OVERLAY_STATE:
1993         return inf->video_mode;
1994     case FBIOGET_SCREEN_STATE:
1995         return inf->cur_screen->type;
1996         
1997         case FBIOPUT_SET_CURSOR_EN:
1998                 {
1999                         int en;
2000                         if(copy_from_user(&en, (void*)arg, sizeof(int)))
2001                             return -EFAULT;
2002                         rk29_set_cursor_en(inf, en);
2003                 }
2004                 break;
2005         case FBIOPUT_SET_CURSOR_POS:
2006                 {
2007                         struct fbcurpos pos;
2008                         if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
2009                             return -EFAULT;
2010                         rk29_set_cursor_pos(inf, pos.x , pos.y);
2011                 }
2012                 break;
2013         case FBIOPUT_SET_CURSOR_IMG:
2014                 {
2015                         char cursor_buf[CURSOR_BUF_SIZE];
2016                         if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
2017                                 return -EFAULT;
2018                         rk29_set_cursor_img(inf, cursor_buf);
2019                 }
2020                 break;
2021         case FBIOPUT_SET_CURSOR_CMAP:
2022                 {
2023                         struct fb_image img;
2024                         if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
2025                             return -EFAULT;
2026                         rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
2027                 }
2028                 break;
2029         case FBIOPUT_GET_CURSOR_RESOLUTION:
2030                 {
2031             u32 panel_size[2];
2032                         //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2033              if((inf->fb1->var.rotate &0x1ff ) == 270) {
2034                 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
2035                 panel_size[1] = inf->cur_screen->x_res;
2036             } else {
2037                 panel_size[0] = inf->cur_screen->x_res;
2038                 panel_size[1] = inf->cur_screen->y_res;
2039             }
2040             if(copy_to_user((void*)arg, panel_size, 8))  return -EFAULT;
2041             break;
2042                 }
2043         case FBIOPUT_GET_CURSOR_EN:
2044                 {
2045             u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
2046             if(copy_to_user((void*)arg, &en, 4))  return -EFAULT;
2047             break;
2048                 }
2049 #ifdef  FB_WIMO_FLAG
2050         case FB0_IOCTL_SET_BUF:
2051                 {
2052                         unsigned long temp[4];
2053                         copy_from_user(temp, (void*)arg, 20);
2054                         wimo_set_buff( info,temp);
2055                         
2056                 }
2057                 break;
2058         case FB0_IOCTL_CLOSE_BUF:
2059                 {
2060                         if(ui_buffer != NULL && ui_buffer_map !=NULL )
2061                         {
2062                                 iounmap(ui_buffer_map);
2063                                 ui_buffer_map = 0;
2064                                 ui_buffer = 0;
2065                                 memset(&wimo_info,0,sizeof(wimo_info));
2066                         }
2067                         else
2068                                 printk("somethint wrong with wimo in close");
2069                                 
2070                 }
2071                 break;
2072         
2073         case FB0_IOCTL_COPY_CURBUF:
2074                 {
2075                         unsigned long temp_data[3];
2076                         copy_from_user(&temp_vv, (void*)arg, 4);
2077                         if(ui_buffer != NULL && ui_buffer_map !=NULL )
2078                         {
2079                                 temp_data[1] = wimo_get_buff(info);
2080                                 temp_data[0] = wimo_info.bitperpixel;
2081                                 
2082                         }
2083                         else
2084                         {
2085                                 temp_data[1] = 1;
2086                                 temp_data[0] = wimo_info.bitperpixel;
2087                                 printk("somethint wrong with wimo in getbuf");
2088                         }
2089                         temp_data[2] = frame_num++;
2090                         //printk("FB0_IOCTL_COPY_CURBUF %d %d %d\n",temp_data[0],temp_data[1],temp_data[2]);
2091                         copy_to_user((void*)arg, &temp_data, 12);
2092                         break;
2093                 }
2094 #endif
2095    default:
2096         break;
2097     }
2098     return 0;
2099 }
2100
2101 static int fb1_blank(int blank_mode, struct fb_info *info)
2102 {
2103     win0_blank(blank_mode, info);
2104     return 0;
2105 }
2106
2107 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
2108 {
2109     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2110     struct rk29fb_screen *screen = inf->cur_screen;
2111
2112     u32 ScaleYRGBY=0x1000;
2113     u16 xpos = (var->nonstd>>8) & 0xfff;   //offset in panel
2114     u16 ypos = (var->nonstd>>20) & 0xfff;
2115     u16 xsize = (var->grayscale>>8) & 0xfff;   //visiable size in panel
2116     u16 ysize = (var->grayscale>>20) & 0xfff;
2117     u16 xlcd = screen->x_res;        //size of panel
2118     u16 ylcd = screen->y_res;
2119     u16 yres = 0;
2120 #if 0
2121         struct hdmi *hdmi = get_hdmi_struct(0);
2122 #endif
2123
2124     if((var->rotate & 0x1ff) == 90 ||(var->rotate &0x1ff)== 270) {
2125       #ifdef CONFIG_FB_ROTATE_VIDEO
2126         xlcd = screen->y_res;
2127         ylcd = screen->x_res;
2128       #else //CONFIG_FB_ROTATE_VIDEO
2129         printk("LCDC not support rotate!\n");
2130         return -EINVAL;
2131       #endif
2132     }
2133
2134     xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2135     ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2136     xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2137     ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2138
2139     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2140
2141         CHK_SUSPEND(inf);
2142
2143     if( 0==var->xres_virtual || 0==var->yres_virtual ||
2144         0==var->xres || 0==var->yres || var->xres<16 ||
2145         0==xsize || 0==ysize || xsize<16 ||
2146         ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
2147     {
2148         printk(">>>>>> win0fb_check_var fail 1!!! \n");
2149                 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
2150                                 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
2151                         var->bits_per_pixel, var->bits_per_pixel);
2152         return -EINVAL;
2153     }
2154
2155     if( (var->xoffset+var->xres)>var->xres_virtual ||
2156         (var->yoffset+var->yres)>var->yres_virtual ||
2157         (xpos+xsize)>xlcd || (ypos+ysize)>ylcd  )
2158     {
2159         printk(">>>>>> win0fb_check_var fail 2!!! \n");
2160                 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
2161                                 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
2162                                 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);       
2163         return -EINVAL;
2164     }
2165
2166     switch(var->nonstd&0x0f)
2167     {
2168     case 0: // rgb
2169         switch(var->bits_per_pixel)
2170         {
2171         case 16:    // rgb565
2172             var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
2173             var->xres = (var->xres + 0x1) & (~0x1);
2174             var->xoffset = (var->xoffset) & (~0x1);
2175             break;
2176         default:    // rgb888
2177             var->bits_per_pixel = 32;
2178             break;
2179         }
2180         var->nonstd &= ~0xc0;  //not support I2P in this format
2181         break;
2182     case 1: // yuv422
2183         var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2184         var->xres = (var->xres + 0x3) & (~0x3);
2185         var->xoffset = (var->xoffset) & (~0x3);
2186         break;
2187     case 2: // yuv4200
2188         var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2189         var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
2190         var->xres = (var->xres + 0x3) & (~0x3);
2191         var->yres = (var->yres + 0x1) & (~0x1);
2192         var->xoffset = (var->xoffset) & (~0x3);
2193         var->yoffset = (var->yoffset) & (~0x1);
2194         break;
2195     case 3: // yuv4201
2196         var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2197         var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
2198         var->xres = (var->xres + 0x3) & (~0x3);
2199         var->yres = (var->yres + 0x1) & (~0x1);
2200         var->xoffset = (var->xoffset) & (~0x3);
2201         var->yoffset = (var->yoffset) & (~0x1);
2202         var->nonstd &= ~0xc0;   //not support I2P in this format
2203         break;
2204     case 4: // none
2205     case 5: // yuv444
2206         var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
2207         var->xres = (var->xres + 0x3) & (~0x3);
2208         var->xoffset = (var->xoffset) & (~0x3);
2209         var->nonstd &= ~0xc0;   //not support I2P in this format
2210         break;
2211     default:
2212         printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
2213         return -EINVAL;
2214     }
2215
2216     if((var->rotate & 0x1ff ) == 90 ||(var->rotate & 0x1ff ) == 270)
2217      {
2218          yres = var->xres;
2219      }
2220      else
2221      {
2222          yres = var->yres;
2223      }
2224
2225     ScaleYRGBY = CalScaleW0(yres, ysize);
2226
2227     if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
2228     {
2229         return -EINVAL;        // multiple of scale down or scale up can't exceed 8
2230     }
2231 #if 0
2232         if(inf->video_mode == 1) {
2233                 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
2234                 {
2235                         LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE,  v_BLACK_MODE(1));
2236                 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2237                         init_completion(&hdmi->complete);
2238                         hdmi->wait = 1;
2239                         wait_for_completion_interruptible_timeout(&hdmi->complete,
2240                                                                 msecs_to_jiffies(10000));
2241                 }
2242         }
2243 #endif
2244     return 0;
2245 }
2246
2247 static int fb1_set_par(struct fb_info *info)
2248 {
2249     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2250     struct rk29fb_screen *screen = inf->cur_screen;
2251     struct fb_var_screeninfo *var = &info->var;
2252     struct fb_fix_screeninfo *fix = &info->fix;
2253     struct win0_par *par = info->par;
2254
2255     u8 format = 0;
2256     u32 cblen=0, crlen=0, map_size=0, smem_len=0;
2257
2258         //u32 xact = var->xres;                     /* visible resolution               */
2259         //u32 yact = var->yres;
2260         u32 xvir = var->xres_virtual;           /* virtual resolution           */
2261         u32 yvir = var->yres_virtual;
2262         u32 xact_st = var->xoffset;                     /* offset from virtual to visible */
2263         u32 yact_st = var->yoffset;                     /* resolution                   */
2264
2265     u16 xpos = (var->nonstd>>8) & 0xfff;      //visiable pos in panel
2266     u16 ypos = (var->nonstd>>20) & 0xfff;
2267     u16 xsize = (var->grayscale>>8) & 0xfff;  //visiable size in panel
2268     u16 ysize = (var->grayscale>>20) & 0xfff;
2269
2270     //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
2271     //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
2272
2273     u8 data_format = var->nonstd&0x0f;
2274    // u32 win0_en = var->reserved[2];
2275    // u32 y_addr = var->reserved[3];       //user alloc buf addr y
2276    // u32 uv_addr = var->reserved[4];
2277
2278     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2279         CHK_SUSPEND(inf);
2280     if((var->rotate & 0x1ff ) == 90 || (var->rotate & 0x1ff ) == 270)
2281     {
2282         #ifdef CONFIG_FB_ROTATE_VIDEO
2283         xpos = (var->nonstd>>20) & 0xfff;      //visiable pos in panel
2284         ypos = (var->nonstd>>8) & 0xfff;
2285         xsize = (var->grayscale>>20) & 0xfff;  //visiable size in panel
2286         ysize = (var->grayscale>>8) & 0xfff;
2287         #else //CONFIG_FB_ROTATE_VIDEO
2288         printk("LCDC not support rotate!\n");
2289         return -EINVAL;
2290       #endif
2291     } else{
2292         xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
2293         ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
2294         xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
2295         ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
2296     }
2297         /* calculate y_offset,c_offset,line_length,cblen and crlen  */
2298     switch (data_format)
2299     {
2300     case 0: // rgb
2301         switch(var->bits_per_pixel)
2302         {
2303         case 16:    // rgb565
2304             format = 1;
2305             fix->line_length = 2 * xvir;
2306             par->y_offset = (yact_st*xvir + xact_st)*2;
2307             break;
2308         case 32:    // rgb888
2309             format = 0;
2310             fix->line_length = 4 * xvir;
2311             par->y_offset = (yact_st*xvir + xact_st)*4;
2312             break;
2313         default:
2314             return -EINVAL;
2315         }
2316         break;
2317     case 1: // yuv422
2318         format = 2;
2319         fix->line_length = xvir;
2320         cblen = crlen = (xvir*yvir)/2;
2321         par->y_offset = yact_st*xvir + xact_st;
2322         par->c_offset = yact_st*xvir + xact_st;
2323         break;
2324     case 2: // yuv4200
2325         format = 3;
2326         fix->line_length = xvir;
2327         cblen = crlen = (xvir*yvir)/4;
2328
2329         par->y_offset = yact_st*xvir + xact_st;
2330         par->c_offset = (yact_st/2)*xvir + xact_st;
2331
2332         break;
2333     case 3: // yuv4201
2334         format = 4;
2335         fix->line_length = xvir;
2336         par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
2337         par->c_offset = (yact_st/2)*xvir + xact_st;
2338         cblen = crlen = (xvir*yvir)/4;
2339         break;
2340     case 4: // none
2341     case 5: // yuv444
2342         format = 5;
2343         fix->line_length = xvir;
2344         par->y_offset = yact_st*xvir + xact_st;
2345         par->c_offset = yact_st*2*xvir + xact_st*2;
2346         cblen = crlen = (xvir*yvir);
2347         break;
2348     default:
2349         return -EINVAL;
2350     }
2351
2352     smem_len = fix->line_length * yvir + cblen + crlen;
2353     map_size = PAGE_ALIGN(smem_len);
2354
2355    // fix->smem_start = y_addr;
2356     fix->smem_len = smem_len;
2357   //  fix->mmio_start = uv_addr;
2358
2359  //   par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
2360     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);
2361
2362     par->format = format;
2363     par->xpos = xpos;
2364     par->ypos = ypos;
2365     par->xsize = xsize;
2366     par->ysize = ysize;
2367     win0_set_par(info);
2368
2369     if ( wq_condition2 == 0 ) {
2370         wait_event_interruptible_timeout(wq,  wq_condition2, HZ/20);
2371     }
2372     wq_condition2 = 0;
2373
2374 #ifdef CONFIG_FB_ROTATE_VIDEO
2375 //need refresh  ,zyc add                
2376         if((has_set_rotate == true) && (last_yuv_phy[0] != 0) && (last_yuv_phy[1] != 0))
2377         {
2378                 u32 yuv_phy[2];
2379                 struct rk29_ipp_req ipp_req;
2380                 static u32 dstoffset = 0;
2381                 static int fb_index = 0;
2382                 memset(&ipp_req, 0, sizeof(struct rk29_ipp_req));
2383                 yuv_phy[0] = last_yuv_phy[0];
2384                 yuv_phy[1] = last_yuv_phy[1];
2385                 yuv_phy[0] += par->y_offset;
2386                 yuv_phy[1] += par->c_offset;
2387         #if 0
2388                 if((var->rotate == 90) ||(var->rotate == 270))
2389         #else
2390         if(var->rotate%360 != 0)
2391         #endif
2392                         {
2393                 #ifdef CONFIG_FB_ROTATE_VIDEO 
2394                                 dstoffset = (dstoffset+1)%2;
2395                                 ipp_req.src0.fmt = 3;
2396                                 ipp_req.src0.YrgbMst = yuv_phy[0];
2397                                 ipp_req.src0.CbrMst = yuv_phy[1];
2398                                 ipp_req.src0.w = var->xres;
2399                                 ipp_req.src0.h = var->yres;
2400                                 
2401                                 ipp_req.src_vir_w= (var->xres + 15) & (~15);
2402                                 ipp_req.dst_vir_w=screen->x_res;
2403
2404                 ipp_req.dst0.fmt = 3;
2405                                 #ifdef CONFIG_FB_MIRROR_X_Y
2406                                 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2407                                 {
2408                                 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*4;
2409                                 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*5;
2410                                  }
2411                                 else
2412                                 {
2413                                         ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2414                                         ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2415
2416                                 }
2417                                 if(var->xres > screen->x_res)
2418                                    {
2419                                         ipp_req.dst0.w = screen->x_res;
2420                                         ipp_req.dst0.h = screen->y_res;
2421                                   }   else      {
2422                                           ipp_req.dst0.w = var->xres;
2423                                           ipp_req.dst0.h = var->yres;
2424                                    }
2425                                  ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2426                                 ipp_req.timeout = 100;
2427                                 if((var->rotate & 0x1ff) == 90)
2428                                         ipp_req.flag = IPP_ROT_90;
2429                 else if ((var->rotate & 0x1ff) == 180)
2430                                         ipp_req.flag = IPP_ROT_180;
2431                                 else if((var->rotate & 0x1ff) == 270)
2432                                         ipp_req.flag = IPP_ROT_270;
2433                                 else if((var->rotate & X_MIRROR) == X_MIRROR )
2434                                         ipp_req.flag = IPP_ROT_X_FLIP;
2435                                 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2436                                         ipp_req.flag = IPP_ROT_Y_FLIP;
2437                                 //ipp_do_blit(&ipp_req);
2438                                 ipp_blit_sync(&ipp_req);
2439                                 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2440                                 yuv_phy[1] = ipp_req.dst0.CbrMst;
2441                                 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2442                                 {
2443                                         memset(&ipp_req,0,sizeof(struct rk29_ipp_req));
2444                                         
2445                                         if((var->rotate & X_MIRROR) == X_MIRROR)
2446                                                 ipp_req.flag = IPP_ROT_X_FLIP;
2447                                         else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2448                                                 ipp_req.flag = IPP_ROT_Y_FLIP;
2449                                         else 
2450                                                 printk(">>>>>> %d rotate is not support!\n",var->rotate);
2451                                         
2452                                   if(var->xres > screen->x_res)
2453                                    {
2454                                         ipp_req.dst0.w = screen->x_res;
2455                                         ipp_req.dst0.h = screen->y_res;
2456                                   }   else      {
2457                                           ipp_req.dst0.w = var->xres;
2458                                           ipp_req.dst0.h = var->yres;
2459                                    }
2460                                         ipp_req.src0.fmt = 3;
2461                                         ipp_req.src0.YrgbMst = yuv_phy[0];
2462                                         ipp_req.src0.CbrMst = yuv_phy[1];
2463                                         ipp_req.src0.w = ipp_req.dst0.w;
2464                                         ipp_req.src0.h = ipp_req.dst0.h;
2465                                 
2466                                         ipp_req.src_vir_w= (ipp_req.dst0.w + 15) & (~15);
2467                                         ipp_req.dst_vir_w= (ipp_req.dst0.w + 15) & (~15);
2468
2469                                         ipp_req.dst0.fmt = 3;
2470                                         ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2471                                         ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2472
2473                                         ipp_req.timeout = 100;
2474                                         ipp_blit_sync(&ipp_req);
2475                                         yuv_phy[0] = ipp_req.dst0.YrgbMst;
2476                                         yuv_phy[1] = ipp_req.dst0.CbrMst;
2477                         }
2478                 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2479                                 #else
2480                                 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2481                 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2482                 if(var->xres > screen->x_res)
2483                 {
2484                     ipp_req.dst0.w = screen->x_res;
2485                     ipp_req.dst0.h = screen->y_res;
2486                 }   else  {
2487                                         ipp_req.dst0.w = var->xres;
2488                                         ipp_req.dst0.h = var->yres;
2489
2490                 }
2491                 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2492                 ipp_req.timeout = 100;
2493                 if(var->rotate == 90)
2494                     ipp_req.flag = IPP_ROT_90;
2495                 else if(var->rotate == 180)
2496                     ipp_req.flag = IPP_ROT_180;
2497                 else if(var->rotate == 270)
2498                     ipp_req.flag = IPP_ROT_270;
2499                 //ipp_do_blit(&ipp_req);
2500                 ipp_blit_sync(&ipp_req);
2501                                 
2502                 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2503                 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2504                 yuv_phy[1] = ipp_req.dst0.CbrMst; 
2505                                 #endif
2506                 fix->smem_start = yuv_phy[0];
2507                 fix->mmio_start = yuv_phy[1];
2508                 #else //CONFIG_FB_ROTATE_VIDEO
2509                 printk("LCDC not support rotate!\n");
2510                 #endif
2511             }
2512             else
2513                         {
2514                         
2515                                 fix->smem_start = yuv_phy[0];
2516                                 fix->mmio_start = yuv_phy[1];
2517                         }
2518                         
2519                 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2520                 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2521                 // enable win0 after the win0 par is seted
2522                 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2523                 par->addr_seted = 1;
2524                 LcdWrReg(inf, REG_CFG_DONE, 0x01);
2525                 if(par->addr_seted ) {
2526                 unsigned long flags;
2527
2528                 local_irq_save(flags);
2529                 par->mirror.y_offset = yuv_phy[0];
2530                 par->mirror.c_offset = yuv_phy[1];
2531                 local_irq_restore(flags);
2532
2533                 mcu_refresh(inf);
2534                 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2535                 }
2536
2537         }
2538
2539     has_set_rotate = false;
2540 #endif
2541     return 0;
2542 }
2543
2544 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
2545 {
2546     struct win0_par *par = info->par;
2547      // enable win0 after the win0 addr is seted
2548
2549     win0_pan(info);
2550     par->par_seted = 1;
2551     return 0;
2552 }
2553
2554 int fb1_open(struct fb_info *info, int user)
2555 {
2556     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2557     struct win0_par *par = info->par;
2558         struct rk29fb_screen *screen = inf->cur_screen;
2559
2560     fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2561
2562     par->par_seted = 0;
2563     par->addr_seted = 0;
2564     inf->video_mode = 1;
2565     wq_condition2 = 1;
2566 #ifdef CONFIG_FB_ROTATE_VIDEO
2567    //reinitialize  the var when open,zyc
2568     last_yuv_phy[0] = 0;
2569     last_yuv_phy[1] = 0;
2570     has_set_rotate = 0;
2571 #endif
2572     if(par->refcount) {
2573         printk(">>>>>> fb1 has opened! \n");
2574         return -EACCES;
2575     } else {
2576         par->refcount++;
2577         win0_blank(FB_BLANK_NORMAL, info);
2578                 if(screen->x_res>1280)
2579                 fb1_open_init=1;
2580         fb0_set_par(inf->fb0);
2581         fb1_open_init=0;
2582             rk29fb_notify(inf, RK29FB_EVENT_FB1_ON);
2583         return 0;
2584     }
2585 }
2586
2587 int fb1_release(struct fb_info *info, int user)
2588 {
2589     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2590     struct win0_par *par = info->par;
2591         struct fb_var_screeninfo *var0 = &info->var;
2592
2593     fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2594     if(inf->setFlag == 0)
2595     {
2596         wait_event_interruptible_timeout(wq, inf->setFlag, HZ*10);
2597     } 
2598     if(par->refcount) {
2599         par->refcount--;
2600         inf->video_mode = 0;
2601         par->par_seted = 0;
2602         par->addr_seted = 0;
2603         win1_blank(FB_BLANK_NORMAL, info);
2604
2605         //if(inf->cur_screen->type != SCREEN_HDMI)
2606             fb0_set_par(inf->fb0);
2607
2608         // unmap memory
2609         info->screen_base = 0;
2610         info->fix.smem_start = 0;
2611         info->fix.smem_len = 0;
2612                 // clean the var param
2613                 memset(var0, 0, sizeof(struct fb_var_screeninfo));
2614             rk29fb_notify(inf, RK29FB_EVENT_FB1_OFF);
2615         #ifdef CONFIG_CLOSE_WIN1_DYNAMIC   
2616          cancel_delayed_work_sync(&rk29_win1_check_work);
2617         #endif  
2618     }
2619
2620     return 0;
2621 }
2622
2623 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
2624 {
2625     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
2626     struct win0_par *par = info->par;
2627     struct fb_fix_screeninfo *fix0 = &info->fix;
2628     struct fb_var_screeninfo *var = &info->var;
2629     void __user *argp = (void __user *)arg;
2630     
2631 #ifdef CONFIG_FB_ROTATE_VIDEO   
2632      struct rk29fb_screen *screen = inf->cur_screen;
2633      struct rk29_ipp_req ipp_req;
2634      static u32 dstoffset = 0;
2635     memset(&ipp_req, 0, sizeof(struct rk29_ipp_req)); 
2636 #endif
2637
2638         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2639     fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
2640
2641         CHK_SUSPEND(inf);
2642
2643     switch(cmd)
2644     {
2645     case FB1_IOCTL_GET_PANEL_SIZE:    //get panel size
2646         {
2647             u32 panel_size[2];
2648              if((var->rotate & 0x1ff) == 270 ||(var->rotate & 0x1ff) == 90) {
2649                 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
2650                 panel_size[1] = inf->panel1_info.x_res;
2651             } else {
2652                 panel_size[0] = inf->panel1_info.x_res;
2653                 panel_size[1] = inf->panel1_info.y_res;
2654             }
2655
2656             if(copy_to_user(argp, panel_size, 8))  return -EFAULT;
2657         }
2658         break;
2659
2660     case FB1_IOCTL_SET_YUV_ADDR:    //set y&uv address to register direct
2661         {
2662             u32 yuv_phy[2];
2663 #ifdef  FB_WIMO_FLAG
2664         //      printk("FB1_IOCTL_SET_YUV_ADDR1 \n");
2665         //      while(wimo_info.fb_lock)
2666         //              {
2667         //              msleep(10);
2668         //              }
2669         //      printk("FB1_IOCTL_SET_YUV_ADDR 2\n");
2670 #endif
2671             if (copy_from_user(yuv_phy, argp, 8))
2672                             return -EFAULT;
2673 #ifdef CONFIG_FB_ROTATE_VIDEO 
2674                 //add by zyc
2675                 if(has_set_rotate == true)
2676                 break;
2677                 last_yuv_phy[0] = yuv_phy[0];
2678                 last_yuv_phy[1] = yuv_phy[1];
2679 #endif
2680
2681             fix0->smem_start = yuv_phy[0];
2682             fix0->mmio_start = yuv_phy[1];
2683             yuv_phy[0] += par->y_offset;
2684             yuv_phy[1] += par->c_offset;
2685 #ifdef  FB_WIMO_FLAG
2686               wimo_info.src_y = yuv_phy[0]; 
2687               wimo_info.src_uv = yuv_phy[1]; 
2688                 
2689 #endif
2690          
2691             #if 0
2692                 if((var->rotate == 90) ||(var->rotate == 270))
2693             #else
2694             if(var->rotate%360 != 0)
2695             #endif
2696             {
2697                 #ifdef CONFIG_FB_ROTATE_VIDEO 
2698                 dstoffset = (dstoffset+1)%2;
2699                 ipp_req.src0.fmt = 3;
2700                 ipp_req.src0.YrgbMst = yuv_phy[0];
2701                 ipp_req.src0.CbrMst = yuv_phy[1];
2702                     ipp_req.src0.w = var->xres ;
2703                 ipp_req.src0.h = var->yres ;
2704                         ipp_req.src_vir_w= (var->xres + 15) & (~15);
2705                         ipp_req.dst_vir_w=screen->x_res;
2706
2707                 ipp_req.dst0.fmt = 3;
2708                                 #ifdef CONFIG_FB_MIRROR_X_Y
2709                                 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2710                                 {
2711                                 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*4;
2712                                 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*5;
2713                                  }
2714                                 else
2715                                 {
2716                                         ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2717                                         ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2718
2719                                 }
2720                                 if(var->xres > screen->x_res)
2721                                    {
2722                                         ipp_req.dst0.w = screen->x_res;
2723                                         ipp_req.dst0.h = screen->y_res;
2724                                   }   else      {
2725                                           ipp_req.dst0.w = var->xres;
2726                                           ipp_req.dst0.h = var->yres;
2727                                    }
2728                                  ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2729                                 ipp_req.timeout = 100;
2730                                 if((var->rotate & 0x1ff) == 90)
2731                                         ipp_req.flag = IPP_ROT_90;
2732                 else if ((var->rotate & 0x1ff) == 180)
2733                                         ipp_req.flag = IPP_ROT_180;
2734                                 else if((var->rotate & 0x1ff) == 270)
2735                                         ipp_req.flag = IPP_ROT_270;
2736                                 else if((var->rotate & X_MIRROR) == X_MIRROR )
2737                                         ipp_req.flag = IPP_ROT_X_FLIP;
2738                                 else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2739                                         ipp_req.flag = IPP_ROT_Y_FLIP;
2740                                 //ipp_do_blit(&ipp_req);
2741                                 ipp_blit_sync(&ipp_req);
2742                                 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2743                                 yuv_phy[1] = ipp_req.dst0.CbrMst;
2744                                 if((var->rotate & 0x1ff)!=0 &&(var->rotate&(X_MIRROR|Y_MIRROR))!= 0 )
2745                                 {
2746                                         memset(&ipp_req,0,sizeof(struct rk29_ipp_req));
2747                                         
2748                                         if((var->rotate & X_MIRROR) == X_MIRROR)
2749                                                 ipp_req.flag = IPP_ROT_X_FLIP;
2750                                         else if((var->rotate & Y_MIRROR) == Y_MIRROR)
2751                                                 ipp_req.flag = IPP_ROT_Y_FLIP;
2752                                         else 
2753                                                 printk(">>>>>> %d rotate is not support!\n",var->rotate);
2754                                         
2755                                   if(var->xres > screen->x_res)
2756                                    {
2757                                         ipp_req.dst0.w = screen->x_res;
2758                                         ipp_req.dst0.h = screen->y_res;
2759                                   }   else      {
2760                                           ipp_req.dst0.w = var->xres;
2761                                           ipp_req.dst0.h = var->yres;
2762                                    }
2763                                         ipp_req.src0.fmt = 3;
2764                                         ipp_req.src0.YrgbMst = yuv_phy[0];
2765                                         ipp_req.src0.CbrMst = yuv_phy[1];
2766                                         ipp_req.src0.w = ipp_req.dst0.w;
2767                                         ipp_req.src0.h = ipp_req.dst0.h;
2768                                 
2769                                         ipp_req.src_vir_w= (ipp_req.dst0.w + 15) & (~15);
2770                                         ipp_req.dst_vir_w= (ipp_req.dst0.w + 15) & (~15);
2771
2772                                         ipp_req.dst0.fmt = 3;
2773                                         ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2774                                         ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2775
2776                                         ipp_req.timeout = 100;
2777                                         ipp_blit_sync(&ipp_req);
2778                                         yuv_phy[0] = ipp_req.dst0.YrgbMst;
2779                                         yuv_phy[1] = ipp_req.dst0.CbrMst;
2780                         }
2781                 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2782                                 #else
2783                                 ipp_req.dst0.YrgbMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*2*dstoffset;
2784                 ipp_req.dst0.CbrMst = inf->fb0->fix.mmio_start + screen->x_res*screen->y_res*(2*dstoffset+1);
2785                 if(var->xres > screen->x_res)
2786                 {
2787                     ipp_req.dst0.w = screen->x_res;
2788                     ipp_req.dst0.h = screen->y_res;
2789                 }   else  {
2790                                         ipp_req.dst0.w = var->xres;
2791                                         ipp_req.dst0.h = var->yres;
2792
2793                 }
2794                 ipp_req.dst_vir_w = (ipp_req.dst0.w + 15) & (~15);
2795                 ipp_req.timeout = 100;
2796                 if(var->rotate == 90)
2797                     ipp_req.flag = IPP_ROT_90;
2798                 else if(var->rotate == 180)
2799                     ipp_req.flag = IPP_ROT_180;
2800                 else if(var->rotate == 270)
2801                     ipp_req.flag = IPP_ROT_270;
2802                 //ipp_do_blit(&ipp_req);
2803                 ipp_blit_sync(&ipp_req);
2804                                 
2805                 fbprintk("yaddr=0x%x,uvaddr=0x%x\n",ipp_req.dst0.YrgbMst,ipp_req.dst0.CbrMst);
2806                 yuv_phy[0] = ipp_req.dst0.YrgbMst;
2807                 yuv_phy[1] = ipp_req.dst0.CbrMst; 
2808                                 #endif
2809                 fix0->smem_start = yuv_phy[0];
2810                 fix0->mmio_start = yuv_phy[1];
2811                 #else //CONFIG_FB_ROTATE_VIDEO
2812                 printk("LCDC not support rotate!\n");
2813                 #endif
2814             }
2815       
2816             LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
2817             LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
2818             // enable win0 after the win0 par is seted
2819             LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
2820             par->addr_seted = 1;
2821             LcdWrReg(inf, REG_CFG_DONE, 0x01);
2822             if(par->par_seted) {
2823                 unsigned long flags;
2824
2825                 local_irq_save(flags);
2826                 par->mirror.y_offset = yuv_phy[0];
2827                 par->mirror.c_offset = yuv_phy[1];
2828                 local_irq_restore(flags);
2829
2830                 mcu_refresh(inf);
2831                 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
2832             }
2833         }
2834         break;
2835
2836     case FB1_IOCTL_SET_ROTATE:    //change MCU panel scan direction
2837         fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
2838       #ifdef CONFIG_FB_ROTATE_VIDEO 
2839                 //zyc add
2840         has_set_rotate = true;
2841                 #ifdef CONFIG_FB_MIRROR_X_Y
2842         if( ((arg&0x1ff)%90) == 0 && ( arg&(~0xfff))==0 )
2843                         {
2844                         if( (arg&(  X_MIRROR | Y_MIRROR ) )== (X_MIRROR | Y_MIRROR) )
2845                                 var->rotate = ROTATE_180;
2846                         else if((arg&( ROTATE_90 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_90 | X_MIRROR | Y_MIRROR))
2847                                 var->rotate = ROTATE_270;
2848                         else if((arg&( ROTATE_180 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_180 | X_MIRROR | Y_MIRROR))
2849                                 var->rotate = ROTATE_90;
2850                         else if((arg&( ROTATE_270 | X_MIRROR | Y_MIRROR ) )== ( ROTATE_270 | X_MIRROR | Y_MIRROR))
2851                                 var->rotate = ROTATE_0;
2852                         else
2853                 #else 
2854                 if(arg == ROTATE_0 || arg==ROTATE_90 || arg == ROTATE_180 || arg==ROTATE_270)
2855                 {
2856                 #endif
2857                                 var->rotate = arg;
2858                 }
2859                 else
2860                         printk(">>>>>> %d rotate is not support!\n",(int)arg);
2861         
2862       #else //CONFIG_FB_ROTATE_VIDEO
2863         printk("LCDC not support rotate!\n");
2864       #endif
2865         break;
2866     case FB1_IOCTL_SET_WIN0_TOP:
2867         fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
2868         LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
2869         LcdWrReg(inf, REG_CFG_DONE, 0x01);
2870         break;
2871     default:
2872         break;
2873     }
2874     return 0;
2875 }
2876
2877 static struct fb_ops fb1_ops = {
2878         .owner          = THIS_MODULE,
2879         .fb_open    = fb1_open,
2880         .fb_release = fb1_release,
2881         .fb_check_var   = fb1_check_var,
2882         .fb_set_par     = fb1_set_par,
2883         .fb_blank       = fb1_blank,
2884     .fb_pan_display = fb1_pan_display,
2885     .fb_ioctl = fb1_ioctl,
2886         .fb_setcolreg   = fb_setcolreg,
2887         .fb_fillrect    = cfb_fillrect,
2888         .fb_copyarea    = cfb_copyarea,
2889         .fb_imageblit   = cfb_imageblit,
2890 };
2891
2892 static struct fb_ops fb0_ops = {
2893         .owner          = THIS_MODULE,
2894         .fb_check_var   = fb0_check_var,
2895         .fb_set_par = fb0_set_par,
2896         .fb_blank   = fb0_blank,
2897         .fb_pan_display = fb0_pan_display,
2898     .fb_ioctl = fb0_ioctl,
2899         .fb_setcolreg   = fb_setcolreg,
2900         .fb_fillrect    = cfb_fillrect,
2901         .fb_copyarea    = cfb_copyarea,
2902         .fb_imageblit   = cfb_imageblit,
2903         //.fb_cursor      = rk29_set_cursor,
2904 };
2905
2906 int fb_get_video_mode(void)
2907 {
2908         struct rk29fb_inf *inf;
2909         if(!g_pdev)
2910                 return 0;
2911         inf = platform_get_drvdata(g_pdev);
2912         return inf->video_mode;
2913 }
2914 /*
2915 enable: 1, switch to tv or hdmi; 0, switch to lcd
2916 */
2917 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2918 {
2919     struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2920    // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2921     struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2922
2923     memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2924
2925     if(enable)inf->cur_screen = &inf->panel2_info;
2926     else inf->cur_screen = &inf->panel1_info;
2927
2928     /* Black out, because some display device need clock to standby */
2929     //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2930    // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2931    // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2932     LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE,  v_BLACK_MODE(1));
2933     LcdWrReg(inf, REG_CFG_DONE, 0x01);
2934     wake_lock(&idlelock);
2935     msleep(20);
2936     wake_unlock(&idlelock);
2937
2938     if(inf->cur_screen->standby)    inf->cur_screen->standby(1);
2939     // operate the display_on pin to power down the lcd
2940 #ifdef CONFIG_HDMI_DUAL_DISP
2941     inf->panel1_info.sscreen_get(&inf->panel1_info,inf->panel2_info.hdmi_resolution);
2942     inf->panel1_info.sscreen_set(&inf->panel1_info,enable);
2943 #else
2944     if(enable && mach_info->io_disable)mach_info->io_disable();  //close lcd out
2945     else if (mach_info->io_enable)mach_info->io_enable();       //open lcd out
2946 #endif
2947     load_screen(inf->fb0, 0);
2948         mcu_refresh(inf);
2949
2950     fb1_set_par(inf->fb1);
2951     fb0_set_par(inf->fb0);
2952     LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE,  v_BLACK_MODE(0));
2953     LcdWrReg(inf, REG_CFG_DONE, 0x01);
2954
2955     rk29fb_notify(inf, enable ? RK29FB_EVENT_HDMI_ON : RK29FB_EVENT_HDMI_OFF);
2956     return 0;
2957 }
2958
2959 static ssize_t dsp_win0_info_read(struct device *device,
2960                             struct device_attribute *attr, char *buf)
2961 {
2962     //char * s = _buf;
2963     struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2964     struct rk29fb_screen *screen = inf->cur_screen;
2965
2966     u16 xpos=0,ypos=0,xsize=0,ysize=0;
2967
2968     fbprintk("%s\n",__FUNCTION__);
2969     xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2970     ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2971
2972     xpos -= (screen->left_margin + screen->hsync_len);
2973     ypos -= (screen->upper_margin + screen->vsync_len);
2974
2975     xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2976     ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2977     fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2978         rk29_set_cursor_test(inf->fb0);
2979
2980     return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2981 }
2982
2983 static ssize_t dsp_win0_info_write(struct device *device,
2984                            struct device_attribute *attr, const char *buf, size_t count)
2985 {
2986      printk("%s\n",__FUNCTION__);
2987      printk("%s %x \n",__FUNCTION__,*buf);
2988      return count;
2989 }
2990
2991 static DEVICE_ATTR(dsp_win0_info,  S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2992
2993 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2994 {
2995         struct platform_device *pdev = (struct platform_device*)dev_id;
2996     struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2997     struct win0_par *par = (struct win0_par *)inf->fb1->par;
2998     if(!inf)
2999         return IRQ_HANDLED;
3000
3001         //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
3002
3003     LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
3004
3005         if(SCREEN_MCU == inf->cur_screen->type)
3006         {
3007         inf->mcu_isrcnt = !inf->mcu_isrcnt;
3008         if(inf->mcu_isrcnt)
3009             return IRQ_HANDLED;
3010
3011         if(IsMcuUseFmk())
3012         {
3013             if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
3014             {
3015                 inf->mcu_fmksync = 1;
3016                  if(inf->cur_screen->refresh)
3017                    inf->cur_screen->refresh(REFRESH_END);
3018                 inf->mcu_fmksync = 0;
3019             }
3020             else
3021             {
3022                 return IRQ_HANDLED;
3023             }
3024         }
3025         else
3026         {
3027             if(inf->mcu_needflush) {
3028                 if(inf->cur_screen->refresh)
3029                     inf->cur_screen->refresh(REFRESH_PRE);
3030                 inf->mcu_needflush = 0;
3031                 inf->mcu_isrcnt = 0;
3032                 LcdSetRegisterBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
3033             } else {
3034                 if(inf->cur_screen->refresh)
3035                     inf->cur_screen->refresh(REFRESH_END);
3036             }
3037         }
3038         }
3039 #if ANDROID_USE_THREE_BUFS
3040     new_frame_seted = 1;
3041 #endif
3042
3043     if(waitqueue_active(&par->wait)) {
3044         if (par->mirror.c_offset == 0)
3045             printk("error: no new buffer to display\n");
3046
3047         par->done.y_offset = par->displ.y_offset;
3048         par->done.c_offset = par->displ.c_offset;
3049         par->displ.y_offset = par->mirror.y_offset;
3050         par->displ.c_offset = par->mirror.c_offset;
3051         par->mirror.y_offset = 0;
3052         par->mirror.c_offset = 0;
3053
3054         //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
3055         //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
3056         wake_up_interruptible(&par->wait);
3057     }
3058
3059     wq_condition2 = 1;
3060         wq_condition = 1;
3061         wake_up_interruptible(&wq);
3062
3063         rk29fb_irq_notify_ddr();
3064         return IRQ_HANDLED;
3065 }
3066
3067 #ifdef CONFIG_HAS_EARLYSUSPEND
3068
3069 struct suspend_info {
3070         struct early_suspend early_suspend;
3071         struct rk29fb_inf *inf;
3072 };
3073
3074 static void rk29fb_early_suspend(struct early_suspend *h)
3075 {
3076         struct suspend_info *info = container_of(h, struct suspend_info,
3077                                                 early_suspend);
3078
3079     struct rk29fb_inf *inf = info->inf;
3080     struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
3081
3082     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3083
3084     if(!inf) {
3085         printk("inf==0, rk29fb_suspend fail! \n");
3086         return;
3087     }
3088
3089 #ifdef CONFIG_CLOSE_WIN1_DYNAMIC   
3090      cancel_delayed_work_sync(&rk29_win1_check_work);
3091 #endif  
3092
3093     if((inf->cur_screen != &inf->panel2_info) && mach_info->io_disable)  // close lcd pwr when output screen is lcd
3094        mach_info->io_disable();  //close lcd out 
3095
3096         if(inf->cur_screen->standby)
3097         {
3098                 fbprintk(">>>>>> power down the screen! \n");
3099                 inf->cur_screen->standby(1);
3100         }
3101         LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE | m_W1_ENABLE, v_W0_ENABLE(0) | v_W1_ENABLE(0));
3102
3103     LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
3104        v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
3105
3106     LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3107     LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3108         LcdWrReg(inf, REG_CFG_DONE, 0x01);
3109
3110         if(!inf->in_suspend)
3111         {
3112                 fbprintk(">>>>>> diable the lcdc clk! \n");
3113                 wake_lock(&idlelock);
3114                 msleep(100);
3115                 wake_unlock(&idlelock);
3116         clk_disable(inf->aclk_ddr_lcdc);
3117         clk_disable(inf->aclk_disp_matrix);
3118         clk_disable(inf->hclk_cpu_display);
3119         clk_disable(inf->clk);
3120         if (inf->dclk){
3121             clk_disable(inf->dclk);
3122         }
3123         if(inf->clk){
3124             clk_disable(inf->aclk);
3125         }
3126         //clk_disable(inf->pd_display);
3127
3128                 inf->in_suspend = 1;
3129         }
3130 }
3131
3132 static void rk29fb_early_resume(struct early_suspend *h)
3133 {
3134         struct suspend_info *info = container_of(h, struct suspend_info,
3135                                         early_suspend);
3136
3137     struct rk29fb_inf *inf = info->inf;
3138     struct rk29fb_screen *screen = inf->cur_screen;
3139     struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
3140
3141     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3142     if(!inf) {
3143         printk("inf==0, rk29fb_resume fail! \n");
3144         return ;
3145     }
3146
3147     if(inf->in_suspend)
3148         {
3149             inf->in_suspend = 0;
3150         fbprintk(">>>>>> enable the lcdc clk! \n");
3151        // clk_enable(inf->pd_display);
3152         clk_enable(inf->aclk_disp_matrix);
3153         clk_enable(inf->hclk_cpu_display);
3154         clk_enable(inf->clk);
3155         clk_enable(inf->aclk_ddr_lcdc);
3156
3157         if (inf->dclk){
3158             clk_enable(inf->dclk);
3159         }
3160         if(inf->clk){
3161             clk_enable(inf->aclk);
3162         }
3163         usleep_range(100*1000, 100*1000);
3164         }
3165     LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
3166     LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
3167     LcdWrReg(inf, REG_CFG_DONE, 0x01);
3168
3169     LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
3170        v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
3171
3172         if(inf->cur_screen->standby)
3173         {
3174                 fbprintk(">>>>>> power on the screen! \n");
3175                 inf->cur_screen->standby(0);
3176         }
3177     usleep_range(10*1000, 10*1000);
3178     memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4);  //resume reg
3179     usleep_range(40*1000, 40*1000);
3180     
3181     if((inf->cur_screen != &inf->panel2_info) && mach_info->io_enable)  // open lcd pwr when output screen is lcd
3182        mach_info->io_enable();  //close lcd out 
3183         
3184 }
3185
3186 static struct suspend_info suspend_info = {
3187         .early_suspend.suspend = rk29fb_early_suspend,
3188         .early_suspend.resume = rk29fb_early_resume,
3189         .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
3190 };
3191 #endif
3192 struct fb_info *g_fb0_inf = NULL;  //add cym@rk 20101027 for charger logo
3193 static int __devinit rk29fb_probe (struct platform_device *pdev)
3194 {
3195     struct rk29fb_inf *inf = NULL;
3196     struct resource *res = NULL;
3197     struct resource *mem = NULL;
3198     struct rk29fb_info *mach_info = NULL;
3199     struct rk29fb_screen *screen = NULL;
3200     struct win0_par* par = NULL;
3201         int irq = 0;
3202     int ret = 0;
3203
3204     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3205
3206     /* Malloc rk29fb_inf and set it to pdev for drvdata */
3207     fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
3208     inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
3209     if(!inf)
3210     {
3211         dev_err(&pdev->dev, ">> inf kmalloc fail!");
3212         ret = -ENOMEM;
3213                 goto release_drvdata;
3214     }
3215     memset(inf, 0, sizeof(struct rk29fb_inf));
3216         platform_set_drvdata(pdev, inf);
3217
3218     mach_info = pdev->dev.platform_data;
3219     /* Fill screen info and set current screen */
3220     fbprintk(">> Fill screen info and set current screen \n");
3221    #ifdef CONFIG_DEFAULT_OUT_HDMI  // set hdmi for default output 
3222     hdmi_get_default_resolution(&inf->panel1_info);
3223    #else
3224     set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
3225    #endif
3226
3227     inf->cur_screen = &inf->panel1_info;
3228     screen = inf->cur_screen;
3229     if(SCREEN_NULL==screen->type)
3230     {
3231         dev_err(&pdev->dev, ">> Please select a display device! \n");
3232         ret = -EINVAL;
3233                 goto release_drvdata;
3234     }
3235
3236     /* get virtual basic address of lcdc register */
3237     fbprintk(">> get virtual basic address of lcdc register \n");
3238     res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
3239     if (res == NULL)
3240     {
3241         dev_err(&pdev->dev, "failed to get memory registers\n");
3242         ret = -ENOENT;
3243                 goto release_drvdata;
3244     }
3245     inf->reg_phy_base = res->start;
3246     inf->len = (res->end - res->start) + 1;
3247     mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
3248     if (mem == NULL)
3249     {
3250         dev_err(&pdev->dev, "failed to get memory region\n");
3251         ret = -ENOENT;
3252                 goto release_drvdata;
3253     }
3254     fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
3255     inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
3256     if (inf->reg_vir_base == NULL)
3257     {
3258         dev_err(&pdev->dev, "ioremap() of registers failed\n");
3259         ret = -ENXIO;
3260                 goto release_drvdata;
3261     }
3262     inf->preg = (LCDC_REG*)inf->reg_vir_base;
3263
3264     /* Prepare win1 info */
3265     fbprintk(">> Prepare win1 info \n");
3266         inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
3267     if(!inf->fb0)
3268     {
3269         dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
3270                 inf->fb0 = NULL;
3271         ret = -ENOMEM;
3272                 goto release_win1fb;
3273     }
3274
3275     par = (struct win0_par*)inf->fb0->par;
3276     strcpy(inf->fb0->fix.id, "fb0");
3277     inf->fb0->fix.type        = FB_TYPE_PACKED_PIXELS;
3278     inf->fb0->fix.type_aux    = 0;
3279     inf->fb0->fix.xpanstep    = 1;
3280     inf->fb0->fix.ypanstep    = 1;
3281     inf->fb0->fix.ywrapstep   = 0;
3282     inf->fb0->fix.accel       = FB_ACCEL_NONE;
3283     inf->fb0->fix.visual      = FB_VISUAL_TRUECOLOR;
3284     inf->fb0->fix.smem_len    = 0;
3285     inf->fb0->fix.line_length = 0;
3286     inf->fb0->fix.smem_start  = 0;
3287
3288     inf->fb0->var.xres = screen->x_res;
3289     inf->fb0->var.yres = screen->y_res;
3290     inf->fb0->var.bits_per_pixel = 16;
3291     inf->fb0_color_deepth = 0;
3292     inf->fb0->var.xres_virtual = screen->x_res;
3293     inf->fb0->var.yres_virtual = screen->y_res;
3294     inf->fb0->var.width = screen->width;
3295     inf->fb0->var.height = screen->height;
3296     //inf->fb0->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
3297     inf->fb0->var.left_margin = screen->left_margin;
3298     inf->fb0->var.right_margin = screen->right_margin;
3299     inf->fb0->var.upper_margin = screen->upper_margin;
3300     inf->fb0->var.lower_margin = screen->lower_margin;
3301     inf->fb0->var.vsync_len = screen->vsync_len;
3302     inf->fb0->var.hsync_len = screen->hsync_len;
3303     inf->fb0->var.red    = def_rgb_16.red;
3304     inf->fb0->var.green  = def_rgb_16.green;
3305     inf->fb0->var.blue   = def_rgb_16.blue;
3306     inf->fb0->var.transp = def_rgb_16.transp;
3307
3308     inf->fb0->var.nonstd      = 0;  //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
3309     inf->fb0->var.grayscale   = 0;  //win1 transprent mode & value(mode<<8 + value)
3310     inf->fb0->var.activate    = FB_ACTIVATE_NOW;
3311     inf->fb0->var.accel_flags = 0;
3312     inf->fb0->var.vmode       = FB_VMODE_NONINTERLACED;
3313
3314     inf->fb0->fbops           = &fb0_ops;
3315     inf->fb0->flags           = FBINFO_FLAG_DEFAULT;
3316     inf->fb0->pseudo_palette  = par->pseudo_pal;
3317     inf->fb0->screen_base     = 0;
3318
3319     memset(par, 0, sizeof(struct win0_par));
3320
3321         ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
3322         if (ret < 0)
3323                 goto release_cmap;
3324
3325         g_fb0_inf = inf->fb0; //add cym@rk 20101027
3326
3327     /* alloc win1 buf */
3328     res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
3329     if (res == NULL)
3330     {
3331         dev_err(&pdev->dev, "failed to get win1 memory \n");
3332         ret = -ENOENT;
3333         goto release_win1fb;
3334     }
3335     inf->fb0->fix.smem_start = res->start;
3336     inf->fb0->fix.smem_len = res->end - res->start + 1;
3337     inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
3338     memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
3339
3340     #ifdef CONFIG_FB_WORK_IPP
3341        /* alloc win1 ipp buf */
3342     res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
3343     if (res == NULL)
3344     {
3345         dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
3346         ret = -ENOENT;
3347         goto release_win1fb;
3348     }
3349     inf->fb0->fix.mmio_start = res->start;
3350     inf->fb0->fix.mmio_len = res->end - res->start + 1;
3351     #endif
3352
3353     /* Prepare win0 info */
3354     fbprintk(">> Prepare win0 info \n");
3355     inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
3356     if(!inf->fb1)
3357     {
3358         dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
3359                 inf->fb1 = NULL;
3360                 ret = -ENOMEM;
3361                 goto release_win0fb;
3362     }
3363
3364     par = (struct win0_par*)inf->fb1->par;
3365
3366     strcpy(inf->fb1->fix.id, "fb1");
3367         inf->fb1->fix.type            = FB_TYPE_PACKED_PIXELS;
3368         inf->fb1->fix.type_aux    = 0;
3369         inf->fb1->fix.xpanstep    = 1;
3370         inf->fb1->fix.ypanstep    = 1;
3371         inf->fb1->fix.ywrapstep   = 0;
3372         inf->fb1->fix.accel       = FB_ACCEL_NONE;
3373     inf->fb1->fix.visual      = FB_VISUAL_TRUECOLOR;
3374     inf->fb1->fix.smem_len    = 0;
3375     inf->fb1->fix.line_length = 0;
3376     inf->fb1->fix.smem_start  = 0;
3377
3378     inf->fb1->var.xres = screen->x_res;
3379     inf->fb1->var.yres = screen->y_res;
3380     inf->fb1->var.bits_per_pixel = 16;
3381     inf->fb1->var.xres_virtual = screen->x_res;
3382     inf->fb1->var.yres_virtual = screen->y_res;
3383     inf->fb1->var.width = screen->width;
3384     inf->fb1->var.height = screen->height;
3385     //inf->fb1->var.pixclock = div_u64(1000000000000llu, screen->pixclock);
3386     inf->fb1->var.left_margin = screen->left_margin;
3387     inf->fb1->var.right_margin = screen->right_margin;
3388     inf->fb1->var.upper_margin = screen->upper_margin;
3389     inf->fb1->var.lower_margin = screen->lower_margin;
3390     inf->fb1->var.vsync_len = screen->vsync_len;
3391     inf->fb1->var.hsync_len = screen->hsync_len;
3392     inf->fb1->var.red    = def_rgb_16.red;
3393     inf->fb1->var.green  = def_rgb_16.green;
3394     inf->fb1->var.blue   = def_rgb_16.blue;
3395     inf->fb1->var.transp = def_rgb_16.transp;
3396
3397     inf->fb1->var.nonstd      = 0;  //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
3398     inf->fb1->var.grayscale   = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
3399     inf->fb1->var.activate    = FB_ACTIVATE_NOW;
3400     inf->fb1->var.accel_flags = 0;
3401     inf->fb1->var.vmode       = FB_VMODE_NONINTERLACED;
3402
3403     inf->fb1->fbops           = &fb1_ops;
3404         inf->fb1->flags               = FBINFO_FLAG_DEFAULT;
3405         inf->fb1->pseudo_palette  = par->pseudo_pal;
3406         inf->fb1->screen_base     = 0;
3407
3408     memset(par, 0, sizeof(struct win0_par));
3409
3410         init_waitqueue_head(&par->wait);
3411
3412         /* Init all lcdc and lcd before register_framebuffer. */
3413         /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
3414         fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
3415     init_lcdc(inf->fb0);
3416
3417   #if 0 //def CONFIG_CPU_FREQ
3418    // inf->freq_transition.notifier_call = rk29fb_freq_transition;
3419    // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3420   #endif
3421         fbprintk("got clock\n");
3422
3423         if(mach_info)
3424     {
3425         struct rk29_fb_setting_info fb_setting;
3426         if( OUT_P888==inf->cur_screen->face )     // set lcdc iomux
3427         {
3428             fb_setting.data_num = 24;
3429         }
3430         else if(OUT_P666 == inf->cur_screen->face )
3431         {
3432             fb_setting.data_num = 18;
3433         }
3434         else
3435         {
3436             fb_setting.data_num = 16;
3437         }
3438         fb_setting.den_en = 1;
3439         fb_setting.vsync_en = 1;
3440         fb_setting.disp_on_en = 1;
3441         fb_setting.standby_en = 1;
3442         if( inf->cur_screen->mcu_usefmk )
3443             fb_setting.mcu_fmk_en =1;
3444         mach_info->io_init(&fb_setting);
3445     }
3446
3447         //set_lcd_pin(pdev, 1);
3448         mdelay(10);
3449         g_pdev = pdev;
3450         inf->mcu_usetimer = 1;
3451     inf->mcu_fmksync = 0;
3452         load_screen(inf->fb0, 1);
3453
3454     /* Register framebuffer(fb0 & fb1) */
3455     fbprintk(">> Register framebuffer(fb0) \n");
3456     ret = register_framebuffer(inf->fb0);
3457     if(ret<0)
3458     {
3459         printk(">> fb0 register_framebuffer fail!\n");
3460         ret = -EINVAL;
3461                 goto release_win0fb;
3462     }
3463     fbprintk(">> Register framebuffer(fb1) \n");
3464
3465     ret = register_framebuffer(inf->fb1);
3466     if(ret<0)
3467     {
3468         printk(">> fb1 register_framebuffer fail!\n");
3469         ret = -EINVAL;
3470                 goto unregister_win1fb;
3471     }
3472
3473     ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3474     if(ret)
3475     {
3476         printk(">> fb1 dsp win0 info device_create_file err\n");
3477         ret = -EINVAL;
3478     }
3479 #ifdef CONFIG_HAS_EARLYSUSPEND
3480         suspend_info.inf = inf;
3481         register_early_suspend(&suspend_info.early_suspend);
3482 #endif
3483
3484     /* get and request irq */
3485     fbprintk(">> get and request irq \n");
3486     irq = platform_get_irq(pdev, 0);
3487     if (irq < 0) {
3488         dev_err(&pdev->dev, "no irq for device\n");
3489         ret = -ENOENT;
3490         goto unregister_win1fb;
3491     }
3492     ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
3493     if (ret) {
3494         dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
3495         ret = -EBUSY;
3496         goto release_irq;
3497     }
3498
3499     if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
3500     {
3501         ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
3502         if (ret)
3503         {
3504             dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
3505             ret = -EBUSY;
3506             goto release_irq;
3507         }
3508     }
3509  #ifdef CONFIG_MFD_RK610
3510     rk610_lcd_scaler_set_param(&inf->panel1_info,0);
3511  #endif
3512 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
3513     fb0_set_par(inf->fb0);
3514     if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
3515         /* Start display and show logo on boot */
3516         fb_set_cmap(&inf->fb0->cmap, inf->fb0);
3517         fb_show_logo(inf->fb0, FB_ROTATE_UR);
3518         fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
3519     }
3520 #endif
3521
3522     printk(" %s ok\n", __FUNCTION__);
3523     return ret;
3524
3525 release_irq:
3526         if(irq>=0)
3527         free_irq(irq, pdev);
3528 unregister_win1fb:
3529     unregister_framebuffer(inf->fb0);
3530 release_win0fb:
3531         if(inf->fb1)
3532                 framebuffer_release(inf->fb1);
3533         inf->fb1 = NULL;
3534 release_cmap:
3535     if(&inf->fb0->cmap)
3536         fb_dealloc_cmap(&inf->fb0->cmap);
3537 release_win1fb:
3538         if(inf->fb0)
3539                 framebuffer_release(inf->fb0);
3540         inf->fb0 = NULL;
3541 release_drvdata:
3542         if(inf && inf->reg_vir_base)
3543         iounmap(inf->reg_vir_base);
3544         if(inf && mem)
3545         release_mem_region(inf->reg_phy_base, inf->len);
3546         if(inf)
3547         kfree(inf);
3548         platform_set_drvdata(pdev, NULL);
3549         return ret;
3550 }
3551
3552 static int __devexit rk29fb_remove(struct platform_device *pdev)
3553 {
3554     struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3555     struct fb_info *info = NULL;
3556         //pm_message_t msg;
3557     struct rk29fb_info *mach_info = NULL;
3558     int irq = 0;
3559
3560         fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
3561
3562     if(!inf) {
3563         printk("inf==0, rk29_fb_remove fail! \n");
3564         return -EINVAL;
3565     }
3566     device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
3567
3568     irq = platform_get_irq(pdev, 0);
3569     if (irq >0)
3570     {
3571     free_irq(irq, pdev);
3572     }
3573
3574     mach_info = pdev->dev.platform_data;
3575     if(mach_info->mcu_fmk_pin)
3576     {
3577         free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
3578     }
3579
3580     if(mach_info->io_disable)  
3581        mach_info->io_disable();  //close lcd out 
3582
3583     // blank the lcdc
3584     if(inf->fb1)
3585         fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
3586     if(inf->fb0)
3587         fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
3588
3589         // suspend the lcdc
3590         //rk29fb_suspend(pdev, msg);
3591     // unmap memory and release framebuffer
3592     if(inf->fb1) {
3593         info = inf->fb1;
3594         if (info->screen_base) {
3595                 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3596                 info->screen_base = 0;
3597                 info->fix.smem_start = 0;
3598                 info->fix.smem_len = 0;
3599         }
3600         unregister_framebuffer(inf->fb1);
3601         framebuffer_release(inf->fb1);
3602         inf->fb1 = NULL;
3603     }
3604     if(inf->fb0) {
3605         info = inf->fb0;
3606         if (info->screen_base) {
3607             //    dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
3608                 info->screen_base = 0;
3609                 info->fix.smem_start = 0;
3610                 info->fix.smem_len = 0;
3611         }
3612         unregister_framebuffer(inf->fb0);
3613         framebuffer_release(inf->fb0);
3614         inf->fb0 = NULL;
3615     }
3616
3617   #if 0 //def CONFIG_CPU_FREQ
3618    // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
3619   #endif
3620
3621     msleep(100);
3622
3623         if (inf->clk)
3624     {
3625                 clk_disable(inf->clk);
3626                 clk_put(inf->clk);
3627                 inf->clk = NULL;
3628         }
3629     if (inf->dclk)
3630     {
3631                 clk_disable(inf->dclk);
3632                 clk_put(inf->dclk);
3633                 inf->dclk = NULL;
3634         }
3635
3636     kfree(inf);
3637     platform_set_drvdata(pdev, NULL);
3638
3639     return 0;
3640 }
3641
3642 static void rk29fb_shutdown(struct platform_device *pdev)
3643 {
3644     struct rk29fb_inf *inf = platform_get_drvdata(pdev);
3645     struct rk29fb_info *mach_info = pdev->dev.platform_data;;
3646
3647         fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
3648
3649     if(mach_info->io_disable)  
3650        mach_info->io_disable();  //close lcd out 
3651        
3652     if(!inf->in_suspend)
3653     {
3654         LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
3655         LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
3656         LcdWrReg(inf, REG_CFG_DONE, 0x01);
3657         mdelay(100);
3658         clk_disable(inf->aclk_ddr_lcdc);
3659         clk_disable(inf->aclk_disp_matrix);
3660         clk_disable(inf->hclk_cpu_display);
3661         clk_disable(inf->clk);
3662         if(inf->dclk){
3663             clk_disable(inf->dclk);
3664         }
3665         if(inf->clk){
3666             clk_disable(inf->aclk);
3667         }
3668         clk_disable(inf->pd_display);
3669         //pmu_set_power_domain(PD_DISPLAY, 0);
3670                 inf->in_suspend = 1;
3671         }
3672
3673 }
3674
3675 static struct platform_driver rk29fb_driver = {
3676         .probe          = rk29fb_probe,
3677         .remove         = __devexit_p(rk29fb_remove),
3678         .driver         = {
3679                 .name   = "rk29-fb",
3680                 .owner  = THIS_MODULE,
3681         },
3682         .shutdown   = rk29fb_shutdown,
3683 };
3684
3685 static int __init rk29fb_init(void)
3686 {
3687         wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
3688     return platform_driver_register(&rk29fb_driver);
3689 }
3690
3691 static void __exit rk29fb_exit(void)
3692 {
3693     platform_driver_unregister(&rk29fb_driver);
3694 }
3695
3696 fs_initcall(rk29fb_init);
3697 module_exit(rk29fb_exit);
3698
3699
3700 MODULE_AUTHOR("  zyw@rock-chips.com");
3701 MODULE_DESCRIPTION("Driver for rk29 fb device");
3702 MODULE_LICENSE("GPL");
3703
3704