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