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