rk29: fb: support show logo without framebuffer console
[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
42 #include "rk29_fb.h"
43
44 #ifdef CONFIG_PM
45 #include <linux/pm.h>
46 #endif
47 #ifdef CONFIG_HDMI
48 #include <linux/completion.h>
49
50 #include <linux/hdmi.h>
51 #endif
52
53 #include <mach/iomux.h>
54 #include <mach/gpio.h>
55 #include <mach/board.h>
56 #include <mach/rk29_iomap.h>
57 #include <mach/pmu.h>
58 #include <mach/rk29-ipp.h>
59
60 #include "./display/screen/screen.h"
61
62 #define ANDROID_USE_THREE_BUFS  0       //android use three buffers to accelerate UI display in rgb plane
63 #define CURSOR_BUF_SIZE         256     //RK2818 cursor need 256B buf
64 int rk29_cursor_buf[CURSOR_BUF_SIZE];
65 char cursor_img[] = {
66 0x00,0x00,0x00,0x00,
67 0x00,0x00,0x00,0x00,
68 0x00,0x00,0x00,0x00,
69 0x00,0x00,0x00,0x00,
70 0x00,0x00,0x00,0x00,
71 0x00,0x20,0x00,0x00,
72 0x00,0x30,0x00,0x00,
73 0x00,0x28,0x00,0x00,
74 0x00,0x24,0x00,0x00,
75 0x00,0x22,0x00,0x00,
76 0x00,0x21,0x00,0x00,
77 0x00,0x20,0x80,0x00,
78 0x00,0x20,0x40,0x00,
79 0x00,0x20,0x20,0x00,
80 0x00,0x20,0x10,0x00,
81 0x00,0x20,0x08,0x00,
82 0x00,0x20,0x7C,0x00,
83 0x00,0x22,0x40,0x00,
84 0x00,0x26,0x40,0x00,
85 0x00,0x29,0x20,0x00,
86 0x00,0x31,0x20,0x00,
87 0x00,0x20,0x90,0x00,
88 0x00,0x00,0x90,0x00,
89 0x00,0x00,0x48,0x00,
90 0x00,0x00,0x48,0x00,
91 0x00,0x00,0x30,0x00,
92 0x00,0x00,0x00,0x00,
93 0x00,0x00,0x00,0x00,
94 0x00,0x00,0x00,0x00,
95 0x00,0x00,0x00,0x00,
96 0x00,0x00,0x00,0x00,
97 0x00,0x00,0x00,0x00
98 };
99
100 #if 0
101         #define fbprintk(msg...)        printk(msg);
102 #else
103         #define fbprintk(msg...)
104 #endif
105
106
107 #if 0
108         #define fbprintk2(msg...)       printk(msg);
109 #else
110         #define fbprintk2(msg...)
111 #endif
112
113 #define LcdReadBit(inf, addr, msk)      ((inf->regbak.addr=inf->preg->addr)&(msk))
114 #define LcdWrReg(inf, addr, val)        inf->preg->addr=inf->regbak.addr=(val)
115 #define LcdRdReg(inf, addr)             (inf->preg->addr)
116 #define LcdSetBit(inf, addr, msk)       inf->preg->addr=((inf->regbak.addr) |= (msk))
117 #define LcdClrBit(inf, addr, msk)       inf->preg->addr=((inf->regbak.addr) &= ~(msk))
118 #define LcdSetRegBit(inf, addr, msk)    inf->preg->addr=((inf->preg->addr) |= (msk))
119 #define LcdMskReg(inf, addr, msk, val)  (inf->regbak.addr)&=~(msk);   inf->preg->addr=(inf->regbak.addr|=(val))
120
121
122 #define IsMcuLandscape()                ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
123 #define IsMcuUseFmk()                   ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
124
125 #define CalScaleW0(x, y)                     (((u32)x*0x1000)/y)
126
127 struct rk29fb_rgb {
128         struct fb_bitfield      red;
129         struct fb_bitfield      green;
130         struct fb_bitfield      blue;
131         struct fb_bitfield      transp;
132 };
133
134 static struct rk29fb_rgb def_rgb_16 = {
135      red:    { offset: 11, length: 5, },
136      green:  { offset: 5,  length: 6, },
137      blue:   { offset: 0,  length: 5, },
138      transp: { offset: 0,  length: 0, },
139 };
140
141 struct win_set {
142         volatile u32 y_offset;
143         volatile u32 c_offset;
144 };
145
146 struct win0_par {
147     u32 refcount;
148     u32 pseudo_pal[16];
149     u32 y_offset;
150     u32 c_offset;
151     u32 xpos;         //size in panel
152     u32 ypos;
153     u32 xsize;        //start point in panel
154     u32 ysize;
155     u32 format;
156
157     wait_queue_head_t wait;
158     struct win_set mirror;
159     struct win_set displ;
160     struct win_set done;
161
162     u8 par_seted;
163     u8 addr_seted;
164 };
165
166 /*
167 struct win1_par {
168         u32 refcount;
169         u32     pseudo_pal[16];
170         int lstblank;
171     u32 xpos;
172     u32 ypos;
173     u32 xsize;
174     u32 ysize;
175     u32 format;
176     u32 addr_offset;
177 };
178 */
179
180 struct rk29fb_inf {
181     struct fb_info *fb1;
182     struct fb_info *fb0;
183
184     void __iomem *reg_vir_base;  // virtual basic address of lcdc register
185         u32 reg_phy_base;       // physical basic address of lcdc register
186         u32 len;               // physical map length of lcdc register
187     u32 video_mode;
188
189     struct clk      *clk;
190     struct clk      *dclk;            //lcdc dclk
191     struct clk      *dclk_parent;     //lcdc dclk divider frequency source
192     struct clk      *dclk_divider;    //lcdc demodulator divider frequency
193     struct clk      *aclk;   //lcdc share memory frequency
194     struct clk      *aclk_parent;     //lcdc aclk divider frequency source
195     struct clk      *aclk_ddr_lcdc;   //DDR LCDC AXI clock disable.
196     struct clk      *aclk_disp_matrix;  //DISPLAY matrix AXI clock disable.
197     struct clk      *hclk_cpu_display;  //CPU DISPLAY AHB bus clock disable.
198     struct clk      *pd_display;        // display power domain
199     unsigned long       dclk_rate;
200
201     /* lcdc reg base address and backup reg */
202     LCDC_REG *preg;
203     LCDC_REG regbak;
204
205         int in_suspend;
206     int fb0_color_deepth;
207     /* variable used in mcu panel */
208         int mcu_needflush;
209         int mcu_isrcnt;
210         u16 mcu_scandir;
211         struct timer_list mcutimer;
212         int mcu_status;
213         u8 mcu_fmksync;
214         int mcu_usetimer;
215         int mcu_stopflush;
216
217     /* external memery */
218         char __iomem *screen_base2;
219     __u32 smem_len2;
220     unsigned long  smem_start2;
221
222     char __iomem *cursor_base;   /* cursor Virtual address*/
223     __u32 cursor_size;           /* Amount of ioremapped VRAM or 0 */
224     unsigned long  cursor_start;
225
226     struct rk29fb_screen panel1_info;         // 1st panel, it's lcd normally
227     struct rk29fb_screen panel2_info;         // 2nd panel
228     struct rk29fb_screen *cur_screen;
229 #if 0 //def CONFIG_CPU_FREQ
230     struct notifier_block freq_transition;
231 #endif
232
233 };
234
235 typedef enum _TRSP_MODE
236 {
237     TRSP_CLOSE = 0,
238     TRSP_FMREG,
239     TRSP_FMREGEX,
240     TRSP_FMRAM,
241     TRSP_FMRAMEX,
242     TRSP_MASK,
243     TRSP_INVAL
244 } TRSP_MODE;
245
246
247 struct platform_device *g_pdev = NULL;
248 //static int win1fb_set_par(struct fb_info *info);
249
250 #if 0
251 #define CHK_SUSPEND(inf)        \
252         if(inf->in_suspend)     {       \
253                 fbprintk(">>>>>> fb is in suspend! return! \n");        \
254                 return -EPERM;  \
255         }
256 #else
257 #define CHK_SUSPEND(inf)
258 #endif
259
260 static DECLARE_WAIT_QUEUE_HEAD(wq);
261 static int wq_condition = 0;
262 static int wq_condition2 = 0;
263 #if ANDROID_USE_THREE_BUFS
264 static int new_frame_seted = 1;
265 #endif
266 static struct wake_lock idlelock; /* only for fb */
267
268 void set_lcd_pin(struct platform_device *pdev, int enable)
269 {
270         struct rk29fb_info *mach_info = pdev->dev.platform_data;
271
272         unsigned display_on = mach_info->disp_on_pin;
273         unsigned lcd_standby = mach_info->standby_pin;
274
275         int display_on_pol = mach_info->disp_on_value;
276         int lcd_standby_pol = mach_info->standby_value;
277
278         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
279         fbprintk(">>>>>> display_on(%d) = %d \n", display_on, enable ? display_on_pol : !display_on_pol);
280         fbprintk(">>>>>> lcd_standby(%d) = %d \n", lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);
281
282     // set display_on
283
284     if(display_on != INVALID_GPIO)
285     {
286         gpio_direction_output(display_on, 0);
287         gpio_set_value(display_on, enable ? display_on_pol : !display_on_pol);                          
288     }
289     if(lcd_standby != INVALID_GPIO)
290     {
291         gpio_direction_output(lcd_standby, 0);
292                                 gpio_set_value(lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);                         
293     }
294 }
295
296 int mcu_do_refresh(struct rk29fb_inf *inf)
297 {
298     if(inf->mcu_stopflush)  return 0;
299
300     if(SCREEN_MCU!=inf->cur_screen->type)   return 0;
301
302     // use frame mark
303     if(IsMcuUseFmk())
304     {
305         inf->mcu_needflush = 1;
306         return 0;
307     }
308
309     // not use frame mark
310     if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
311     {
312         if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST))
313         {
314             inf->mcu_needflush = 1;
315         }
316         else
317         {
318             if(inf->cur_screen->refresh)    inf->cur_screen->refresh(REFRESH_PRE);
319             inf->mcu_needflush = 0;
320             inf->mcu_isrcnt = 0;
321             LcdSetRegBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
322         }
323     }
324     return 0;
325 }
326
327
328 void mcutimer_callback(unsigned long arg)
329 {
330     struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
331     static int waitcnt = 0;
332
333     mod_timer(&inf->mcutimer, jiffies + HZ/10);
334
335     switch(inf->mcu_status)
336     {
337     case MS_IDLE:
338         inf->mcu_status = MS_MCU;
339         break;
340     case MS_MCU:
341         if(inf->mcu_usetimer)   mcu_do_refresh(inf);
342         break;
343     case MS_EWAITSTART:
344         inf->mcu_status = MS_EWAITEND;
345         waitcnt = 0;
346         break;
347     case MS_EWAITEND:
348         if(0==waitcnt) {
349             mcu_do_refresh(inf);
350         }
351         if(waitcnt++>14) {
352             inf->mcu_status = MS_EEND;
353         }
354         break;
355     case MS_EEND:
356         inf->mcu_status = MS_MCU;
357         break;
358     default:
359         inf->mcu_status = MS_MCU;
360         break;
361     }
362 }
363
364 int mcu_refresh(struct rk29fb_inf *inf)
365 {
366     static int mcutimer_inited = 0;
367
368     if(SCREEN_MCU!=inf->cur_screen->type)   return 0;
369
370     if(!mcutimer_inited)
371     {
372         mcutimer_inited = 1;
373         init_timer(&inf->mcutimer);
374         inf->mcutimer.function = mcutimer_callback;
375         inf->mcutimer.expires = jiffies + HZ/5;
376         inf->mcu_status = MS_IDLE;
377         add_timer(&inf->mcutimer);
378     }
379
380     if(MS_MCU==inf->mcu_status)     mcu_do_refresh(inf);
381
382     return 0;
383 }
384
385 int mcu_ioctl(unsigned int cmd, unsigned long arg)
386 {
387     struct rk29fb_inf *inf = NULL;
388     if(!g_pdev)     return -1;
389
390     inf = dev_get_drvdata(&g_pdev->dev);
391
392     switch(cmd)
393     {
394     case MCU_WRCMD:
395         LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
396         LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
397         LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
398         break;
399
400     case MCU_WRDATA:
401         LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
402         LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
403         break;
404
405     case MCU_SETBYPASS:
406         LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
407         LcdWrReg(inf, REG_CFG_DONE, 0x01);
408         break;
409
410     default:
411         break;
412     }
413
414     return 0;
415 }
416
417 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
418 {
419         struct platform_device *pdev = (struct platform_device*)dev_id;
420     struct rk29fb_inf *inf = platform_get_drvdata(pdev);
421     struct rk29fb_screen *screen;
422
423     if(!inf)    return IRQ_HANDLED;
424
425     screen = inf->cur_screen;
426
427     if(0==screen->mcu_usefmk) {
428         return IRQ_HANDLED;
429     }
430
431     if(inf->mcu_fmksync == 1)
432         return IRQ_HANDLED;
433
434     inf->mcu_fmksync = 1;
435     if(inf->mcu_needflush)
436     {
437         inf->mcu_needflush = 0;
438         inf->mcu_isrcnt = 0;
439         if(inf->cur_screen->refresh)
440            inf->cur_screen->refresh(REFRESH_PRE);
441         LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
442     }
443     inf->mcu_fmksync = 0;
444
445         return IRQ_HANDLED;
446 }
447
448 int init_lcdc(struct fb_info *info)
449 {
450     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
451     u32 msk=0, clr=0;
452
453         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
454
455     inf->clk = clk_get(NULL, "hclk_lcdc");
456     inf->aclk_ddr_lcdc = clk_get(NULL, "aclk_ddr_lcdc");
457     inf->aclk_disp_matrix = clk_get(NULL, "aclk_disp_matrix");
458     inf->hclk_cpu_display = clk_get(NULL, "hclk_cpu_display");
459     inf->pd_display = clk_get(NULL, "pd_display");
460     if ((IS_ERR(inf->clk)) ||
461         (IS_ERR(inf->aclk_ddr_lcdc)) ||
462         (IS_ERR(inf->aclk_disp_matrix)) ||
463         (IS_ERR(inf->hclk_cpu_display)) ||
464         (IS_ERR(inf->pd_display)))
465     {
466         printk(KERN_ERR "failed to get lcdc_hclk source\n");
467         return PTR_ERR(inf->clk);
468     }
469     clk_enable(inf->aclk_disp_matrix);
470     clk_enable(inf->hclk_cpu_display);
471     clk_enable(inf->clk);
472     clk_enable(inf->pd_display);
473     //pmu_set_power_domain(PD_DISPLAY, 1);
474     clk_enable(inf->aclk_ddr_lcdc);
475
476         // set AHB access rule and disable all windows
477     LcdWrReg(inf, SYS_CONFIG, 0x60000000);
478     LcdWrReg(inf, SWAP_CTRL, 0);
479     LcdWrReg(inf, FIFO_WATER_MARK, 0x00000862);//68
480     LcdWrReg(inf, AXI_MS_ID, 0x54321);
481
482         // and mcu holdmode; and set win1 top.
483     LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
484             v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
485
486     // disable blank out, black out, tristate out, yuv2rgb bypass
487     LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
488              m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
489              v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
490              v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
491              );
492
493     LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
494     LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
495
496     LcdWrReg(inf, DSP_CTRL1, 0);
497
498     // initialize all interrupt
499     clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
500
501     msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
502
503     LcdWrReg(inf, INT_STATUS, clr | msk);
504
505         // let above to take effect
506     LcdWrReg(inf, REG_CFG_DONE, 0x01);
507
508     return 0;
509 }
510
511 void load_screen(struct fb_info *info, bool initscreen)
512 {
513     int ret = -EINVAL;
514     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
515     struct rk29fb_screen *screen = inf->cur_screen;
516     u16 face;
517     u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
518     u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
519     u16 x_res = screen->x_res, y_res = screen->y_res;
520     u32 aclk_rate = 150000000;
521
522     if(!g_pdev){
523         printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
524         return;
525     }
526
527         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
528
529     // set the rgb or mcu
530     LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
531
532         // set out format and mcu timing
533     mcu_total  = (screen->mcu_wrperiod*150*1000)/1000000;
534     if(mcu_total>31)    mcu_total = 31;
535     if(mcu_total<3)     mcu_total = 3;
536     mcu_rwstart = (mcu_total+1)/4 - 1;
537     mcu_rwend = ((mcu_total+1)*3)/4 - 1;
538     mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
539     mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
540
541     fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
542         mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
543
544     LcdMskReg(inf, MCU_TIMING_CTRL,
545              m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
546              m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
547             v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
548             v_MCU_RW_END(mcu_rwend) |  v_MCU_WRITE_PERIOD(mcu_total) |
549             v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
550            );
551
552         // set synchronous pin polarity and data pin swap rule
553         switch (screen->face)
554         {
555         case OUT_P565:
556             face = OUT_P565;
557             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
558             break;
559         case OUT_P666:
560             face = OUT_P666;
561             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
562             break;
563         case OUT_D888_P565:
564             face = OUT_P888;
565             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
566             break;
567         case OUT_D888_P666:
568             face = OUT_P888;
569             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
570             break;
571         case OUT_P888:
572             face = OUT_P888;
573             LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
574             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
575             break;
576         default:
577             LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
578             LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
579             face = screen->face;
580             break;
581     }
582
583      LcdMskReg(inf, DSP_CTRL0,
584         m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
585         m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
586         v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
587         v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
588         );
589
590      LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR,  v_BG_COLOR(0x000000) );
591
592      LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
593             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));
594
595         // set horizontal & vertical out timing
596         if(SCREEN_MCU==inf->cur_screen->type)
597     {
598             right_margin = x_res/6;
599         }
600
601     fbprintk("screen->hsync_len =%d,  screen->left_margin =%d, x_res =%d,  right_margin = %d \n",
602         screen->hsync_len , screen->left_margin , x_res , right_margin );
603     LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
604              v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
605     LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
606              v_BIT12HI(screen->hsync_len + screen->left_margin));
607
608     LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
609               v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
610     LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI,  v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
611               v_BIT11HI(screen->vsync_len + screen->upper_margin));
612
613     LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
614     LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
615
616         // let above to take effect
617     LcdWrReg(inf, REG_CFG_DONE, 0x01);
618
619     inf->dclk = clk_get(NULL, "dclk_lcdc");
620     if (IS_ERR(inf->dclk))
621     {
622         printk(KERN_ERR "failed to get lcd dclock source\n");
623         return ;
624     }
625     inf->dclk_divider= clk_get(NULL, "dclk_lcdc_div");
626     if (IS_ERR(inf->dclk_divider))
627     {
628         printk(KERN_ERR "failed to get lcd clock lcdc_divider source \n");
629                 return ;
630     }
631
632     if((inf->cur_screen->type == SCREEN_HDMI) || (inf->cur_screen->type == SCREEN_TVOUT)){
633         inf->dclk_parent = clk_get(NULL, "codec_pll");
634                 clk_set_rate(inf->dclk_parent, 594000000);
635     }    else    {
636         inf->dclk_parent = clk_get(NULL, "general_pll");
637     }
638
639     if (IS_ERR(inf->dclk_parent))
640     {
641         printk(KERN_ERR "failed to get lcd dclock parent source\n");
642         return;
643     }
644
645     inf->aclk = clk_get(NULL, "aclk_lcdc");
646     if (IS_ERR(inf->aclk))
647     {
648         printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
649         return;
650     }
651     inf->aclk_parent = clk_get(NULL, "ddr_pll");//general_pll //ddr_pll
652     if (IS_ERR(inf->dclk_parent))
653     {
654         printk(KERN_ERR "failed to get lcd dclock parent source\n");
655         return ;
656     }
657
658     // set lcdc clk
659     if(SCREEN_MCU==screen->type)    screen->pixclock = 150000000; //mcu fix to 150 MHz
660
661     if(initscreen == 0)    //not init
662     {
663         clk_disable(inf->dclk);
664         clk_disable(inf->aclk);
665     }
666
667     clk_disable(inf->aclk_ddr_lcdc);
668     clk_disable(inf->aclk_disp_matrix);
669     clk_disable(inf->hclk_cpu_display);
670
671     clk_disable(inf->clk);
672     clk_set_parent(inf->dclk_divider, inf->dclk_parent);
673     clk_set_parent(inf->dclk, inf->dclk_divider);
674     ret = clk_set_parent(inf->aclk, inf->aclk_parent);
675
676     fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz ret =%d\n ", screen->pixclock, screen->lcdc_aclk, ret);
677
678     ret = clk_set_rate(inf->dclk_divider, screen->pixclock);
679     if(ret)
680     {
681         printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
682     }
683
684     if(screen->lcdc_aclk){
685         aclk_rate = screen->lcdc_aclk;
686     }
687     ret = clk_set_rate(inf->aclk, aclk_rate);
688     if(ret){
689         printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
690     }
691
692     clk_enable(inf->aclk_ddr_lcdc);
693     clk_enable(inf->aclk_disp_matrix);
694     clk_enable(inf->hclk_cpu_display);
695
696     clk_enable(inf->aclk);
697     clk_enable(inf->clk);
698     clk_enable(inf->dclk);
699
700     // init screen panel
701     if(screen->init)
702     {
703         screen->init();
704     }
705 }
706 #if 0 //def  CONFIG_CPU_FREQ
707 /*
708 * CPU clock speed change handler. We need to adjust the LCD timing
709 * parameters when the CPU clock is adjusted by the power management
710 * subsystem.
711 */
712 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
713
714 static int
715 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
716 {
717     struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
718     struct rk29fb_screen *screen = inf->cur_screen;
719     u32 dclk_rate = 0;
720
721     switch (val)
722     {
723     case CPUFREQ_PRECHANGE:
724           break;
725     case CPUFREQ_POSTCHANGE:
726         {
727          dclk_rate = screen->pixclock * 1000000;
728
729          fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
730
731          clk_set_rate(inf->dclk_divider, dclk_rate);
732          break;
733         }
734     }
735     return 0;
736 }
737 #endif
738
739 static inline unsigned int chan_to_field(unsigned int chan,
740                                          struct fb_bitfield *bf)
741 {
742         chan &= 0xffff;
743         chan >>= 16 - bf->length;
744         return chan << bf->offset;
745 }
746
747 static int fb_setcolreg(unsigned regno,
748                                unsigned red, unsigned green, unsigned blue,
749                                unsigned transp, struct fb_info *info)
750 {
751         unsigned int val;
752 //      fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
753
754         switch (info->fix.visual) {
755         case FB_VISUAL_TRUECOLOR:
756                 /* true-colour, use pseudo-palette */
757                 if (regno < 16) {
758                         u32 *pal = info->pseudo_palette;
759                         val  = chan_to_field(red,   &info->var.red);
760                         val |= chan_to_field(green, &info->var.green);
761                         val |= chan_to_field(blue,  &info->var.blue);
762                         pal[regno] = val;
763                 }
764                 break;
765         default:
766                 return -1;      /* unknown type */
767         }
768
769         return 0;
770 }
771
772 int rk29_set_cursor_en(struct rk29fb_inf *inf, int enable)
773 {
774     if (enable){
775         LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
776     }else{
777         LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
778         }
779         LcdWrReg(inf, REG_CFG_DONE, 0x01);
780         return 0;
781 }
782
783 int rk29_set_cursor_pos(struct rk29fb_inf *inf, int x, int y)
784 {
785         struct rk29fb_screen *screen = inf->cur_screen;
786
787     /* set data */
788     if (x >= 0x800 || y >= 0x800 )
789         return -EINVAL;
790         //printk("%s: %08x,%08x \n",__func__, x, y);
791     x += (screen->left_margin + screen->hsync_len);
792     y += (screen->upper_margin + screen->vsync_len);
793     LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
794         LcdWrReg(inf, REG_CFG_DONE, 0x01);
795     return 0;
796 }
797
798
799 int rk29_set_cursor_colour_map(struct rk29fb_inf *inf, int bg_col, int fg_col)
800 {
801         LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,bg_col);
802         LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,fg_col);
803         LcdWrReg(inf, REG_CFG_DONE, 0x01);
804     return 0;
805 }
806
807 #define RK29_CURSOR_WRITE_BIT(addr,mask,value)          (*((char*)addr)) = (((*((char*)addr))&(~((char)mask)))|((char)value))
808 int rk29_set_cursor_img_transform(char *data)
809 {       int x, y;
810         char *pmsk = data;
811         char  *dst = (char*)rk29_cursor_buf;
812         unsigned char  dmsk = 0;
813         unsigned int   op,shift,offset;
814
815         /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
816          * clears it to transparent then combines the cursor
817          * shape plane with the colour plane to set the
818          * cursor */
819         for (y = 0; y < 32; y++)
820         {
821                 for (x = 0; x < 32; x++)
822                 {
823                         if ((x % 8) == 0) {
824                                 dmsk = *pmsk++;
825                         } else {
826                                 dmsk <<= 1;
827                         }
828                         op = (dmsk & 0x80) ? 1 : 3;
829                         shift = (x*2)%8;
830                         offset = x/4;
831                         RK29_CURSOR_WRITE_BIT((dst+offset),(3<<shift),(op<<shift));
832                 }
833                 dst += 8;
834         }
835
836         return 0;
837 }
838
839
840
841 int rk29_set_cursor_img(struct rk29fb_inf *inf, char *data)
842 {
843         if(data)
844         {
845                 rk29_set_cursor_img_transform(data);
846     }
847         else
848         {
849                 rk29_set_cursor_img_transform(cursor_img);
850         }
851         LcdWrReg(inf, HWC_MST, __pa(rk29_cursor_buf));
852         LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
853         LcdWrReg(inf, REG_CFG_DONE, 0x01);
854     return 0;
855 }
856
857 int rk29_set_cursor_test(struct fb_info *info)
858 {
859         struct rk29fb_inf *inf = dev_get_drvdata(info->device);
860         rk29_set_cursor_colour_map(inf, 0x000000ff, 0x00ff0000);
861         rk29_set_cursor_pos(inf, 0, 0);
862         rk29_set_cursor_img(inf, 0);
863         rk29_set_cursor_en(inf, 1);
864         return 0;
865 }
866 #if 0
867
868 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
869 {
870     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
871
872     //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
873
874     /* check not being asked to exceed capabilities */
875
876     if (cursor->image.width > 32)
877         return -EINVAL;
878
879     if (cursor->image.height > 32)
880         return -EINVAL;
881
882     if (cursor->image.depth > 1)
883         return -EINVAL;
884
885     if (cursor->enable)
886         LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
887     else
888         LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
889
890     /* set data */
891     if (cursor->set & FB_CUR_SETPOS)
892     {
893         unsigned int x = cursor->image.dx;
894         unsigned int y = cursor->image.dy;
895
896         if (x >= 0x800 || y >= 0x800 )
897             return -EINVAL;
898         LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
899     }
900
901
902     if (cursor->set & FB_CUR_SETCMAP)
903     {
904         unsigned int bg_col = cursor->image.bg_color;
905         unsigned int fg_col = cursor->image.fg_color;
906
907         fbprintk("%s: update cmap (%08x,%08x)\n",
908             __func__, bg_col, fg_col);
909
910         LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
911                   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));
912
913         LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
914                          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));
915     }
916
917     if ((cursor->set & FB_CUR_SETSIZE ||
918         cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
919         && info->screen_base && info->fix.smem_start && info->fix.smem_len)
920     {
921         /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
922          * clears it to transparent then combines the cursor
923          * shape plane with the colour plane to set the
924          * cursor */
925         int x, y;
926         const unsigned char *pcol = cursor->image.data;
927         const unsigned char *pmsk = cursor->mask;
928         void __iomem   *dst;
929         unsigned long cursor_mem_start;
930         unsigned char  dcol = 0;
931         unsigned char  dmsk = 0;
932         unsigned int   op;
933
934         dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
935             cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
936
937         fbprintk("%s: setting shape (%d,%d)\n",
938             __func__, cursor->image.width, cursor->image.height);
939
940         memset(dst, 0, CURSOR_BUF_SIZE);
941
942         for (y = 0; y < cursor->image.height; y++)
943         {
944             for (x = 0; x < cursor->image.width; x++)
945             {
946                 if ((x % 8) == 0) {
947                     dcol = *pcol++;
948                     dmsk = *pmsk++;
949                 } else {
950                     dcol >>= 1;
951                     dmsk >>= 1;
952                 }
953
954                 if (dmsk & 1) {
955                     op = (dcol & 1) ? 1 : 3;
956                     op <<= ((x % 4) * 2);
957                     *(u8*)(dst+(x/4)) |= op;
958                 }
959             }
960             dst += (32*2)/8;
961         }
962         LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
963         LcdWrReg(inf, HWC_MST, cursor_mem_start);
964         // flush end when wq_condition=1 in mcu panel, but not in rgb panel
965         if(SCREEN_MCU == inf->cur_screen->type) {
966             wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
967             wq_condition = 0;
968         } else {
969             wq_condition = 0;
970             wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
971         }
972         LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
973     }
974
975     return 0;
976 }
977 #endif
978
979 static int win0_blank(int blank_mode, struct fb_info *info)
980 {
981     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
982
983     fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
984
985         CHK_SUSPEND(inf);
986
987     switch(blank_mode)
988     {
989     case FB_BLANK_UNBLANK:
990         LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
991         break;
992     default:
993         LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
994         break;
995     }
996     LcdWrReg(inf, REG_CFG_DONE, 0x01);
997
998         mcu_refresh(inf);
999     return 0;
1000 }
1001
1002 static int win0_set_par(struct fb_info *info)
1003 {
1004     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1005     struct rk29fb_screen *screen = inf->cur_screen;
1006     struct fb_var_screeninfo *var = &info->var;
1007     struct fb_fix_screeninfo *fix = &info->fix;
1008     struct win0_par *par = info->par;
1009
1010         u32 xact = var->xres;                       /* visible resolution               */
1011         u32 yact = var->yres;
1012         u32 xvir = var->xres_virtual;           /* virtual resolution           */
1013         u32 yvir = var->yres_virtual;
1014         //u32 xact_st = var->xoffset;         /* offset from virtual to visible */
1015         //u32 yact_st = var->yoffset;         /* resolution                     */
1016     u32 xpos = par->xpos;
1017     u32 ypos = par->ypos;
1018
1019     u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1020     u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1021
1022     u32 y_addr = 0;       //user alloc buf addr y
1023     u32 uv_addr = 0;
1024
1025     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1026
1027         CHK_SUSPEND(inf);
1028
1029         // calculate the display phy address
1030     y_addr = fix->smem_start + par->y_offset;
1031     uv_addr = fix->mmio_start + par->c_offset;
1032
1033     ScaleYrgbX = CalScaleW0(xact, par->xsize);
1034     ScaleYrgbY = CalScaleW0(yact, par->ysize);
1035
1036     switch (par->format)
1037     {
1038        case 2:// yuv422
1039            ScaleCbrX= CalScaleW0((xact/2), par->xsize);
1040            ScaleCbrY =  CalScaleW0(yact, par->ysize);
1041            break;
1042        case 3: // yuv4200
1043        case 4: // yuv4201
1044            ScaleCbrX= CalScaleW0(xact/2, par->xsize);
1045            ScaleCbrY =  CalScaleW0(yact/2, par->ysize);
1046            break;
1047        case 5:// yuv444
1048            ScaleCbrX= CalScaleW0(xact, par->xsize);
1049            ScaleCbrY =  CalScaleW0(yact, par->ysize);
1050            break;
1051        default:
1052            break;
1053     }
1054
1055     xpos += (screen->left_margin + screen->hsync_len);
1056     ypos += (screen->upper_margin + screen->vsync_len);
1057
1058     LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1059     LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1060
1061     LcdMskReg(inf, SYS_CONFIG,  m_W0_FORMAT , v_W0_FORMAT(par->format));//(inf->video_mode==0)
1062
1063     LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1064     LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1065     LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1066     LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI,  v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1067     LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1068     LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1069
1070     switch(par->format)
1071     {
1072     case 0:  //rgb888
1073         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,
1074             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));
1075                 break;
1076     case 1:  //rgb565
1077         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,
1078             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));
1079         break;
1080     case 4:   //yuv4201
1081         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,
1082             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) |
1083             v_W0_YRGB_M8_SWAP((var->rotate==0)) | v_W0_CBR_8_SWAP(0));
1084         break;
1085     default:
1086         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,
1087             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) );
1088                 break;
1089     }
1090
1091     LcdWrReg(inf, REG_CFG_DONE, 0x01);
1092
1093     return 0;
1094
1095 }
1096
1097 static int win0_pan( struct fb_info *info )
1098 {
1099     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1100    // struct fb_var_screeninfo *var0 = &info->var;
1101     struct fb_fix_screeninfo *fix0 = &info->fix;
1102     struct win0_par *par = info->par;
1103     u32 y_addr=0, uv_addr=0;
1104
1105     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1106
1107         CHK_SUSPEND(inf);
1108
1109     y_addr = fix0->smem_start +  par->y_offset;//y_offset;
1110     uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
1111
1112     LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1113     LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1114     LcdWrReg(inf, REG_CFG_DONE, 0x01);
1115
1116      // enable win0 after the win0 addr is seted
1117         LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1118         mcu_refresh(inf);
1119
1120     return 0;
1121 }
1122
1123 static int win1_blank(int blank_mode, struct fb_info *info)
1124 {
1125     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1126
1127     fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1128
1129         CHK_SUSPEND(inf);
1130
1131         switch(blank_mode)
1132     {
1133     case FB_BLANK_UNBLANK:
1134         LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1135         break;
1136     default:
1137         LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1138         break;
1139     }
1140     LcdWrReg(inf, REG_CFG_DONE, 0x01);
1141
1142         mcu_refresh(inf);
1143     return 0;
1144 }
1145
1146 static int win1_set_par(struct fb_info *info)
1147 {
1148     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1149     struct fb_fix_screeninfo *fix = &info->fix;
1150     struct rk29fb_screen *screen = inf->cur_screen;
1151     struct win0_par *par = info->par;
1152     struct fb_var_screeninfo *var = &info->var;
1153
1154     //u32 offset=0, addr=0, map_size=0, smem_len=0;
1155     u32 addr=0;
1156     u16 xres_virtual = 0;      //virtual screen size
1157
1158     //u16 xpos_virtual = var->xoffset;           //visiable offset in virtual screen
1159     //u16 ypos_virtual = var->yoffset;
1160
1161     u16 xpos = par->xpos;                 //visiable offset in panel
1162     u16 ypos = par->ypos;
1163
1164     u8 trspmode = TRSP_CLOSE;
1165     u8 trspval = 0;
1166
1167     //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1168
1169    #ifdef CONFIG_FB_WORK_IPP
1170     if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1171         && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1172     {
1173         addr = fix->mmio_start + par->y_offset;
1174         xres_virtual = screen->x_res;      //virtual screen size
1175     }
1176     else
1177    #endif
1178     {
1179         addr = fix->smem_start + par->y_offset;
1180         xres_virtual = var->xres_virtual;      //virtual screen size
1181     }
1182     LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1183
1184     xpos += (screen->left_margin + screen->hsync_len);
1185     ypos += (screen->upper_margin + screen->vsync_len);
1186
1187     LcdWrReg(inf, WIN1_YRGB_MST, addr);
1188
1189     LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1190     LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1191
1192     LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1193
1194     LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN |  m_W1_BLEND_FACTOR,
1195         v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1196
1197      // enable win1 color key and set the color to black(rgb=0)
1198     LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1199
1200     if(1==par->format) //rgb565
1201     {
1202         LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1203             v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1204     }
1205     else
1206     {
1207          LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1208                 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1209
1210          LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1211     }
1212
1213         LcdWrReg(inf, REG_CFG_DONE, 0x01);
1214
1215     return 0;
1216 }
1217
1218 static int win1_pan( struct fb_info *info )
1219 {
1220     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1221     struct fb_fix_screeninfo *fix1 = &info->fix;
1222     struct win0_par *par = info->par;
1223     u32 addr = 0;
1224
1225     #ifdef CONFIG_FB_WORK_IPP
1226     struct rk29fb_screen *screen = inf->cur_screen;
1227     struct fb_var_screeninfo *var = &info->var;
1228     if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1229         && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1230     {
1231         addr = fix1->mmio_start + par->y_offset;
1232     }
1233     else
1234     #endif
1235     {
1236         addr = fix1->smem_start + par->y_offset;
1237     }
1238
1239     //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1240
1241     LcdWrReg(inf, WIN1_YRGB_MST, addr);
1242     LcdWrReg(inf, REG_CFG_DONE, 0x01);
1243         mcu_refresh(inf);
1244
1245     return 0;
1246 }
1247
1248 static int fb0_blank(int blank_mode, struct fb_info *info)
1249 {
1250         struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1251
1252     if(inf->video_mode == 1)
1253     {
1254         win1_blank(blank_mode, info);
1255     }
1256     else
1257     {
1258         win0_blank(blank_mode, info);
1259     }
1260     return 0;
1261 }
1262
1263 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1264 {
1265     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1266     struct rk29fb_screen *screen = inf->cur_screen;
1267     u16 xpos = (var->nonstd>>8) & 0xfff;
1268     u16 ypos = (var->nonstd>>20) & 0xfff;
1269     u16 xlcd = screen->x_res;
1270     u16 ylcd = screen->y_res;
1271
1272     //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1273
1274         CHK_SUSPEND(inf);
1275
1276     if( 0==var->xres_virtual || 0==var->yres_virtual ||
1277         0==var->xres || 0==var->yres || var->xres<16 ||
1278         ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1279     {
1280         printk(">>>>>> win1fb_check_var fail 1!!! \n");
1281         printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1282         printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1283         printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1284         return -EINVAL;
1285     }
1286
1287     if( (var->xoffset+var->xres)>var->xres_virtual ||
1288         (var->yoffset+var->yres)>var->yres_virtual )
1289     {
1290         printk(">>>>>> win1fb_check_var fail 2!!! \n");
1291         printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1292         printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1293         printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1294         return -EINVAL;
1295     }
1296
1297     if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1298     switch(var->bits_per_pixel)
1299     {
1300     case 16:    // rgb565
1301         var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1302         var->xres = (var->xres + 0x1) & (~0x1);
1303         var->xoffset = (var->xoffset) & (~0x1);
1304         break;
1305     default:    // rgb888
1306         var->bits_per_pixel = 32;
1307         break;
1308     }
1309
1310     return 0;
1311 }
1312
1313
1314 static int fb0_set_par(struct fb_info *info)
1315 {
1316     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1317     struct fb_var_screeninfo *var = &info->var;
1318     struct fb_fix_screeninfo *fix = &info->fix;
1319     struct rk29fb_screen *screen = inf->cur_screen;
1320     struct win0_par *par = info->par;
1321
1322     u32 offset=0,  smem_len=0;
1323     u16 xres_virtual = var->xres_virtual;      //virtual screen size
1324     u16 xpos_virtual = var->xoffset;           //visiable offset in virtual screen
1325     u16 ypos_virtual = var->yoffset;
1326
1327 #ifdef CONFIG_FB_WORK_IPP
1328     struct rk29_ipp_req ipp_req;
1329     u32 dstoffset=0;
1330 #endif
1331
1332     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1333
1334         CHK_SUSPEND(inf);
1335
1336     if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1337     #if !defined(CONFIG_FB_WORK_IPP)
1338     if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1339     #endif
1340
1341     switch(var->bits_per_pixel)
1342     {
1343     case 16:    // rgb565
1344         par->format = 1;
1345         //fix->line_length = 2 * xres_virtual;
1346         fix->line_length = (inf->fb0_color_deepth ? 4:2) * xres_virtual;   //32bit and 16bit change
1347
1348         #ifdef CONFIG_FB_WORK_IPP
1349         dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*2;
1350         ipp_req.src0.fmt = IPP_RGB_565;
1351         ipp_req.dst0.fmt = IPP_RGB_565;
1352         #endif
1353         offset = (ypos_virtual*xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1354         break;
1355     case 32:    // rgb888
1356     default:
1357         par->format = 0;
1358         fix->line_length = 4 * xres_virtual;
1359         #ifdef CONFIG_FB_WORK_IPP
1360         dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1361         ipp_req.src0.fmt = IPP_XRGB_8888;
1362         ipp_req.dst0.fmt = IPP_XRGB_8888;
1363         #endif
1364         offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1365         break;
1366     }
1367
1368     smem_len = fix->line_length * var->yres_virtual;
1369     //map_size = PAGE_ALIGN(smem_len);
1370
1371     if (smem_len > fix->smem_len)     // buffer need realloc
1372     {
1373         printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1374     }
1375
1376
1377     par->addr_seted = 1;
1378 #if ANDROID_USE_THREE_BUFS
1379     if(0==new_frame_seted) {
1380         wq_condition = 0;
1381         wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1382     }
1383     new_frame_seted = 0;
1384 #endif
1385
1386     if(inf->video_mode == 1)
1387     {
1388         #ifdef CONFIG_FB_WORK_IPP
1389         if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1390         && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1391         {
1392             par->xpos = 0;
1393             par->ypos = 0;
1394             par->xsize = screen->x_res;
1395             par->ysize = screen->y_res;
1396             par->y_offset = dstoffset;
1397
1398             ipp_req.src0.YrgbMst = fix->smem_start + offset;
1399             ipp_req.src0.w = var->xres;
1400             ipp_req.src0.h = var->yres;
1401
1402             ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1403             ipp_req.dst0.w = screen->x_res;
1404             ipp_req.dst0.h = screen->y_res;
1405
1406             ipp_req.src_vir_w = ipp_req.src0.w;
1407             ipp_req.dst_vir_w = ipp_req.dst0.w;
1408             ipp_req.timeout = 100;
1409             ipp_req.flag = IPP_ROT_0;
1410             ipp_do_blit(&ipp_req);
1411         }else
1412         #endif
1413         {
1414             par->y_offset = offset;
1415             par->xpos = (screen->x_res >= var->xres)?((screen->x_res - var->xres)/2):0;              //visiable offset in panel
1416             par->ypos = (screen->y_res >= var->yres)?(screen->y_res - var->yres):0;
1417             par->xsize = var->xres;                                //visiable size in panel
1418             par->ysize = (screen->y_res >= var->yres) ? var->yres : screen->y_res;
1419         }
1420         win1_set_par(info);
1421     }
1422     else
1423     {
1424         par->y_offset = offset;
1425         par->xpos = 0;
1426         par->ypos = 0;
1427         par->xsize = screen->x_res;
1428         par->ysize = screen->y_res;
1429         win0_set_par(info);
1430     }
1431
1432     return 0;
1433 }
1434
1435 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1436 {
1437
1438     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1439     struct fb_var_screeninfo *var1 = &info->var;
1440     struct rk29fb_screen *screen = inf->cur_screen;
1441     struct win0_par *par = info->par;
1442
1443     u32 offset = 0;
1444     u16 ypos_virtual = var->yoffset;
1445     u16 xpos_virtual = var->xoffset;
1446    #ifdef CONFIG_FB_WORK_IPP
1447     struct fb_fix_screeninfo *fix = &info->fix;
1448     struct rk29_ipp_req ipp_req;
1449     u32 dstoffset = 0
1450    #endif
1451         //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1452
1453         CHK_SUSPEND(inf);
1454
1455     if(inf->fb0_color_deepth)var->bits_per_pixel=inf->fb0_color_deepth;
1456     #if !defined(CONFIG_FB_WORK_IPP)
1457         if((inf->video_mode == 1)&&(screen->y_res < var->yres))ypos_virtual += (var->yres-screen->y_res);
1458     #endif
1459
1460     switch(var1->bits_per_pixel)
1461     {
1462     case 16:    // rgb565
1463         var->xoffset = (var->xoffset) & (~0x1);
1464         #ifdef CONFIG_FB_WORK_IPP
1465         dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres) * 2;
1466         ipp_req.src0.fmt = IPP_RGB_565;
1467         ipp_req.dst0.fmt = IPP_RGB_565;
1468         #endif
1469         offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*(inf->fb0_color_deepth ? 4:2);
1470         break;
1471     case 32:    // rgb888
1472         #ifdef CONFIG_FB_WORK_IPP
1473         dstoffset = ((ypos_virtual*screen->y_res/var->yres) *screen->x_res + (xpos_virtual*screen->x_res)/var->xres )*4;
1474         ipp_req.src0.fmt = IPP_XRGB_8888;
1475         ipp_req.dst0.fmt = IPP_XRGB_8888;
1476         #endif
1477         offset = (ypos_virtual*var1->xres_virtual + xpos_virtual)*4;
1478         break;
1479     default:
1480         return -EINVAL;
1481     }
1482
1483     if(inf->video_mode == 1)
1484     {
1485         #ifdef CONFIG_FB_WORK_IPP
1486         if(((screen->x_res != var->xres) || (screen->y_res != var->yres))
1487         && !((screen->x_res>1280) && (var->bits_per_pixel == 32)))
1488         {
1489             par->y_offset = dstoffset;
1490
1491             ipp_req.src0.YrgbMst = fix->smem_start + offset;
1492             ipp_req.src0.w = var->xres;
1493             ipp_req.src0.h = var->yres;
1494
1495             ipp_req.dst0.YrgbMst = fix->mmio_start + dstoffset;
1496             ipp_req.dst0.w = screen->x_res;
1497             ipp_req.dst0.h = screen->y_res;
1498
1499             ipp_req.src_vir_w = ipp_req.src0.w;
1500             ipp_req.dst_vir_w = ipp_req.dst0.w;
1501             ipp_req.timeout = 100;
1502             ipp_req.flag = IPP_ROT_0;
1503             ipp_do_blit(&ipp_req);
1504             win1_pan(info);
1505             return 0;
1506         }else
1507         #endif
1508             par->y_offset = offset;
1509         win1_pan(info);
1510     }
1511     else
1512     {
1513         par->y_offset = offset;
1514         win0_pan(info);
1515     }
1516         // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1517 #if !ANDROID_USE_THREE_BUFS
1518     // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1519     if(SCREEN_MCU == inf->cur_screen->type) {
1520         wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1521         wq_condition = 0;
1522     } else {
1523         wq_condition = 0;
1524         wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1525     }
1526 #endif
1527     return 0;
1528 }
1529
1530 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1531 {
1532     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1533         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1534
1535         CHK_SUSPEND(inf);
1536
1537     switch(cmd)
1538     {
1539     case FB0_IOCTL_STOP_TIMER_FLUSH:    //stop timer flush mcu panel after android is runing
1540         if(1==arg)
1541         {
1542             inf->mcu_usetimer = 0;
1543         }
1544         break;
1545    case FBIOPUT_16OR32:
1546
1547         inf->fb0_color_deepth = arg;
1548
1549             break;
1550         case FBIOPUT_FBPHYADD:
1551         return info->fix.smem_start;
1552    case FBIOGET_OVERLAY_STATE:
1553         return inf->video_mode;
1554
1555         case FBIOPUT_SET_CURSOR_EN:
1556                 {
1557                         int en;
1558                         if(copy_from_user(&en, (void*)arg, sizeof(int)))
1559                             return -EFAULT;
1560                         rk29_set_cursor_en(inf, en);
1561                 }
1562                 break;
1563         case FBIOPUT_SET_CURSOR_POS:
1564                 {
1565                         struct fbcurpos pos;
1566                         if(copy_from_user(&pos, (void*)arg, sizeof(struct fbcurpos)))
1567                             return -EFAULT;
1568                         rk29_set_cursor_pos(inf, pos.x , pos.y);
1569                 }
1570                 break;
1571         case FBIOPUT_SET_CURSOR_IMG:
1572                 {
1573                         char cursor_buf[CURSOR_BUF_SIZE];
1574                         if(copy_from_user(cursor_buf, (void*)arg, CURSOR_BUF_SIZE))
1575                                 return -EFAULT;
1576                         rk29_set_cursor_img(inf, cursor_buf);
1577                 }
1578                 break;
1579         case FBIOPUT_SET_CURSOR_CMAP:
1580                 {
1581                         struct fb_image img;
1582                         if(copy_from_user(&img, (void*)arg, sizeof(struct fb_image)))
1583                             return -EFAULT;
1584                         rk29_set_cursor_colour_map(inf, img.bg_color, img.fg_color);
1585                 }
1586                 break;
1587         case FBIOPUT_GET_CURSOR_RESOLUTION:
1588                 {
1589             u32 panel_size[2];
1590                         //struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1591              if(inf->fb1->var.rotate == 270) {
1592                 panel_size[0] = inf->cur_screen->y_res; //inf->cur_screen->y_res; change for hdmi video size
1593                 panel_size[1] = inf->cur_screen->x_res;
1594             } else {
1595                 panel_size[0] = inf->cur_screen->x_res;
1596                 panel_size[1] = inf->cur_screen->y_res;
1597             }
1598             if(copy_to_user((void*)arg, panel_size, 8))  return -EFAULT;
1599             break;
1600                 }
1601         case FBIOPUT_GET_CURSOR_EN:
1602                 {
1603             u32 en = (inf->regbak.SYS_CONFIG & m_HWC_ENABLE);
1604             if(copy_to_user((void*)arg, &en, 4))  return -EFAULT;
1605             break;
1606                 }
1607    default:
1608         break;
1609     }
1610     return 0;
1611 }
1612
1613 static int fb1_blank(int blank_mode, struct fb_info *info)
1614 {
1615     win0_blank(blank_mode, info);
1616     return 0;
1617 }
1618
1619 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1620 {
1621     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1622     struct rk29fb_screen *screen = inf->cur_screen;
1623
1624     u32 ScaleYRGBY=0x1000;
1625     u16 xpos = (var->nonstd>>8) & 0xfff;   //offset in panel
1626     u16 ypos = (var->nonstd>>20) & 0xfff;
1627     u16 xsize = (var->grayscale>>8) & 0xfff;   //visiable size in panel
1628     u16 ysize = (var->grayscale>>20) & 0xfff;
1629     u16 xlcd = screen->x_res;        //size of panel
1630     u16 ylcd = screen->y_res;
1631     u16 yres = 0;
1632 #ifdef CONFIG_HDMI
1633         struct hdmi *hdmi = get_hdmi_struct(0);
1634 #endif
1635     xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1636     ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1637     xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1638     ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1639
1640     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1641
1642         CHK_SUSPEND(inf);
1643
1644     if( 0==var->xres_virtual || 0==var->yres_virtual ||
1645         0==var->xres || 0==var->yres || var->xres<16 ||
1646         0==xsize || 0==ysize || xsize<16 ||
1647         ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1648     {
1649         printk(">>>>>> win0fb_check_var fail 1!!! \n");
1650                 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1651                                 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1652                         var->bits_per_pixel, var->bits_per_pixel);
1653         return -EINVAL;
1654     }
1655
1656     if( (var->xoffset+var->xres)>var->xres_virtual ||
1657         (var->yoffset+var->yres)>var->yres_virtual ||
1658         (xpos+xsize)>xlcd || (ypos+ysize)>ylcd  )
1659     {
1660         printk(">>>>>> win0fb_check_var fail 2!!! \n");
1661                 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1662                                 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1663                                 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1664         return -EINVAL;
1665     }
1666
1667     switch(var->nonstd&0x0f)
1668     {
1669     case 0: // rgb
1670         switch(var->bits_per_pixel)
1671         {
1672         case 16:    // rgb565
1673             var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1674             var->xres = (var->xres + 0x1) & (~0x1);
1675             var->xoffset = (var->xoffset) & (~0x1);
1676             break;
1677         default:    // rgb888
1678             var->bits_per_pixel = 32;
1679             break;
1680         }
1681         var->nonstd &= ~0xc0;  //not support I2P in this format
1682         break;
1683     case 1: // yuv422
1684         var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1685         var->xres = (var->xres + 0x3) & (~0x3);
1686         var->xoffset = (var->xoffset) & (~0x3);
1687         break;
1688     case 2: // yuv4200
1689         var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1690         var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1691         var->xres = (var->xres + 0x3) & (~0x3);
1692         var->yres = (var->yres + 0x1) & (~0x1);
1693         var->xoffset = (var->xoffset) & (~0x3);
1694         var->yoffset = (var->yoffset) & (~0x1);
1695         break;
1696     case 3: // yuv4201
1697         var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1698         var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1699         var->xres = (var->xres + 0x3) & (~0x3);
1700         var->yres = (var->yres + 0x1) & (~0x1);
1701         var->xoffset = (var->xoffset) & (~0x3);
1702         var->yoffset = (var->yoffset) & (~0x1);
1703         var->nonstd &= ~0xc0;   //not support I2P in this format
1704         break;
1705     case 4: // none
1706     case 5: // yuv444
1707         var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1708         var->xres = (var->xres + 0x3) & (~0x3);
1709         var->xoffset = (var->xoffset) & (~0x3);
1710         var->nonstd &= ~0xc0;   //not support I2P in this format
1711         break;
1712     default:
1713         printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1714         return -EINVAL;
1715     }
1716
1717     yres = var->yres;
1718
1719     ScaleYRGBY = CalScaleW0(yres, ysize);
1720
1721     if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1722     {
1723         return -EINVAL;        // multiple of scale down or scale up can't exceed 8
1724     }
1725 #ifdef CONFIG_HDMI
1726         if(inf->video_mode == 1) {
1727                 if(hdmi_resolution_changed(hdmi,var->xres,var->yres, 1) == 1)
1728                 {
1729                         LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE,  v_BLACK_MODE(1));
1730                 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1731                         init_completion(&hdmi->complete);
1732                         hdmi->wait = 1;
1733                         wait_for_completion_interruptible_timeout(&hdmi->complete,
1734                                                                 msecs_to_jiffies(10000));
1735                 }
1736         }
1737 #endif
1738     return 0;
1739 }
1740
1741 static int fb1_set_par(struct fb_info *info)
1742 {
1743     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1744     struct rk29fb_screen *screen = inf->cur_screen;
1745     struct fb_var_screeninfo *var = &info->var;
1746     struct fb_fix_screeninfo *fix = &info->fix;
1747     struct win0_par *par = info->par;
1748
1749     u8 format = 0;
1750     u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1751
1752         //u32 xact = var->xres;                     /* visible resolution               */
1753         //u32 yact = var->yres;
1754         u32 xvir = var->xres_virtual;           /* virtual resolution           */
1755         u32 yvir = var->yres_virtual;
1756         u32 xact_st = var->xoffset;                     /* offset from virtual to visible */
1757         u32 yact_st = var->yoffset;                     /* resolution                   */
1758
1759     u16 xpos = (var->nonstd>>8) & 0xfff;      //visiable pos in panel
1760     u16 ypos = (var->nonstd>>20) & 0xfff;
1761     u16 xsize = (var->grayscale>>8) & 0xfff;  //visiable size in panel
1762     u16 ysize = (var->grayscale>>20) & 0xfff;
1763
1764     //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1765     //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1766
1767     u8 data_format = var->nonstd&0x0f;
1768    // u32 win0_en = var->reserved[2];
1769    // u32 y_addr = var->reserved[3];       //user alloc buf addr y
1770    // u32 uv_addr = var->reserved[4];
1771
1772     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1773
1774         CHK_SUSPEND(inf);
1775
1776     xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1777     ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1778     xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1779     ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1780
1781         /* calculate y_offset,c_offset,line_length,cblen and crlen  */
1782     switch (data_format)
1783     {
1784     case 0: // rgb
1785         switch(var->bits_per_pixel)
1786         {
1787         case 16:    // rgb565
1788             format = 1;
1789             fix->line_length = 2 * xvir;
1790             par->y_offset = (yact_st*xvir + xact_st)*2;
1791             break;
1792         case 32:    // rgb888
1793             format = 0;
1794             fix->line_length = 4 * xvir;
1795             par->y_offset = (yact_st*xvir + xact_st)*4;
1796             break;
1797         default:
1798             return -EINVAL;
1799         }
1800         break;
1801     case 1: // yuv422
1802         format = 2;
1803         fix->line_length = xvir;
1804         cblen = crlen = (xvir*yvir)/2;
1805         par->y_offset = yact_st*xvir + xact_st;
1806         par->c_offset = yact_st*xvir + xact_st;
1807         break;
1808     case 2: // yuv4200
1809         format = 3;
1810         fix->line_length = xvir;
1811         cblen = crlen = (xvir*yvir)/4;
1812
1813         par->y_offset = yact_st*xvir + xact_st;
1814         par->c_offset = (yact_st/2)*xvir + xact_st;
1815
1816         break;
1817     case 3: // yuv4201
1818         format = 4;
1819         fix->line_length = xvir;
1820         par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1821         par->c_offset = (yact_st/2)*xvir + xact_st;
1822         cblen = crlen = (xvir*yvir)/4;
1823         break;
1824     case 4: // none
1825     case 5: // yuv444
1826         format = 5;
1827         fix->line_length = xvir;
1828         par->y_offset = yact_st*xvir + xact_st;
1829         par->c_offset = yact_st*2*xvir + xact_st*2;
1830         cblen = crlen = (xvir*yvir);
1831         break;
1832     default:
1833         return -EINVAL;
1834     }
1835
1836     smem_len = fix->line_length * yvir + cblen + crlen;
1837     map_size = PAGE_ALIGN(smem_len);
1838
1839    // fix->smem_start = y_addr;
1840     fix->smem_len = smem_len;
1841   //  fix->mmio_start = uv_addr;
1842
1843  //   par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1844     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);
1845
1846     par->format = format;
1847     par->xpos = xpos;
1848     par->ypos = ypos;
1849     par->xsize = xsize;
1850     par->ysize = ysize;
1851     win0_set_par(info);
1852
1853     if ( wq_condition2 == 0 ) {
1854         wait_event_interruptible_timeout(wq,  wq_condition2, HZ/20);
1855     }
1856     wq_condition2 = 0;
1857
1858     return 0;
1859 }
1860
1861 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1862 {
1863     struct win0_par *par = info->par;
1864      // enable win0 after the win0 addr is seted
1865
1866     win0_pan(info);
1867     par->par_seted = 1;
1868     return 0;
1869 }
1870
1871 int fb1_open(struct fb_info *info, int user)
1872 {
1873     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1874     struct win0_par *par = info->par;
1875
1876     fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1877
1878     par->par_seted = 0;
1879     par->addr_seted = 0;
1880     inf->video_mode = 1;
1881     wq_condition2 = 1;
1882     if(par->refcount) {
1883         printk(">>>>>> fb1 has opened! \n");
1884         return -EACCES;
1885     } else {
1886         par->refcount++;
1887         win0_blank(FB_BLANK_POWERDOWN, info);
1888         return 0;
1889     }
1890 }
1891
1892 int fb1_release(struct fb_info *info, int user)
1893 {
1894     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1895     struct win0_par *par = info->par;
1896         struct fb_var_screeninfo *var0 = &info->var;
1897
1898     fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1899
1900     if(par->refcount) {
1901         par->refcount--;
1902         inf->video_mode = 0;
1903         par->par_seted = 0;
1904         par->addr_seted = 0;
1905         win0_blank(FB_BLANK_POWERDOWN, info);
1906         win1_blank(FB_BLANK_POWERDOWN, info);
1907         // wait for lcdc stop access memory
1908         //msleep(50);
1909
1910         // unmap memory
1911         info->screen_base = 0;
1912         info->fix.smem_start = 0;
1913         info->fix.smem_len = 0;
1914                 // clean the var param
1915                 memset(var0, 0, sizeof(struct fb_var_screeninfo));
1916     }
1917
1918     return 0;
1919 }
1920
1921 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1922 {
1923     struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1924     struct win0_par *par = info->par;
1925     struct fb_fix_screeninfo *fix0 = &info->fix;
1926     void __user *argp = (void __user *)arg;
1927
1928         fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1929     fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
1930
1931         CHK_SUSPEND(inf);
1932
1933     switch(cmd)
1934     {
1935     case FB1_IOCTL_GET_PANEL_SIZE:    //get panel size
1936         {
1937             u32 panel_size[2];
1938              if(inf->fb1->var.rotate == 270) {
1939                 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
1940                 panel_size[1] = inf->panel1_info.x_res;
1941             } else {
1942                 panel_size[0] = inf->panel1_info.x_res;
1943                 panel_size[1] = inf->panel1_info.y_res;
1944             }
1945
1946             if(copy_to_user(argp, panel_size, 8))  return -EFAULT;
1947         }
1948         break;
1949
1950     case FB1_IOCTL_SET_YUV_ADDR:    //set y&uv address to register direct
1951         {
1952             u32 yuv_phy[2];
1953             if (copy_from_user(yuv_phy, argp, 8))
1954                             return -EFAULT;
1955
1956             fix0->smem_start = yuv_phy[0];
1957             fix0->mmio_start = yuv_phy[1];
1958             yuv_phy[0] += par->y_offset;
1959             yuv_phy[1] += par->c_offset;
1960
1961             LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
1962             LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
1963             // enable win0 after the win0 par is seted
1964             LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(par->par_seted && par->addr_seted));
1965             par->addr_seted = 1;
1966             LcdWrReg(inf, REG_CFG_DONE, 0x01);
1967             if(par->par_seted) {
1968                 unsigned long flags;
1969 #if 0
1970                 if (par->mirror.c_offset) {
1971                     ret = wait_event_interruptible_timeout(par->wait,
1972                         (0 == par->mirror.c_offset), HZ/20);
1973                     if (ret <= 0)
1974                         break;
1975                 }
1976 #endif
1977
1978                 local_irq_save(flags);
1979                 par->mirror.y_offset = yuv_phy[0];
1980                 par->mirror.c_offset = yuv_phy[1];
1981                 local_irq_restore(flags);
1982
1983                 mcu_refresh(inf);
1984                 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
1985             }
1986         }
1987         break;
1988
1989     case FB1_IOCTL_SET_ROTATE:    //change MCU panel scan direction
1990         fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
1991         return -1;
1992         break;
1993     case FB1_IOCTL_SET_WIN0_TOP:
1994         fbprintk(">>>>>> FB1_IOCTL_SET_WIN0_TOP %d\n",arg);
1995         LcdMskReg(inf, DSP_CTRL0, m_W0_ON_TOP, v_W0_ON_TOP(arg));
1996         LcdWrReg(inf, REG_CFG_DONE, 0x01);
1997         break;
1998     default:
1999         break;
2000     }
2001     return 0;
2002 }
2003
2004 static struct fb_ops fb1_ops = {
2005         .owner          = THIS_MODULE,
2006         .fb_open    = fb1_open,
2007         .fb_release = fb1_release,
2008         .fb_check_var   = fb1_check_var,
2009         .fb_set_par     = fb1_set_par,
2010         .fb_blank       = fb1_blank,
2011     .fb_pan_display = fb1_pan_display,
2012     .fb_ioctl = fb1_ioctl,
2013         .fb_setcolreg   = fb_setcolreg,
2014         .fb_fillrect    = cfb_fillrect,
2015         .fb_copyarea    = cfb_copyarea,
2016         .fb_imageblit   = cfb_imageblit,
2017 };
2018
2019 static struct fb_ops fb0_ops = {
2020         .owner          = THIS_MODULE,
2021         .fb_check_var   = fb0_check_var,
2022         .fb_set_par = fb0_set_par,
2023         .fb_blank   = fb0_blank,
2024         .fb_pan_display = fb0_pan_display,
2025     .fb_ioctl = fb0_ioctl,
2026         .fb_setcolreg   = fb_setcolreg,
2027         .fb_fillrect    = cfb_fillrect,
2028         .fb_copyarea    = cfb_copyarea,
2029         .fb_imageblit   = cfb_imageblit,
2030         //.fb_cursor      = rk29_set_cursor,
2031 };
2032
2033 /*
2034 enable: 1, switch to tv or hdmi; 0, switch to lcd
2035 */
2036 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
2037 {
2038     struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2039    // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
2040
2041     memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
2042
2043     if(enable)inf->cur_screen = &inf->panel2_info;
2044     else inf->cur_screen = &inf->panel1_info;
2045
2046     /* Black out, because some display device need clock to standby */
2047     //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
2048    // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
2049    // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
2050     LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE,  v_BLACK_MODE(1));
2051     LcdWrReg(inf, REG_CFG_DONE, 0x01);
2052     wake_lock(&idlelock);
2053     msleep(20);
2054     wake_unlock(&idlelock);
2055
2056     if(inf->cur_screen->standby)    inf->cur_screen->standby(1);
2057     // operate the display_on pin to power down the lcd
2058     set_lcd_pin(g_pdev, (enable==0));
2059
2060     load_screen(inf->fb0, 0);
2061         mcu_refresh(inf);
2062
2063     fb1_set_par(inf->fb1);
2064     fb0_set_par(inf->fb0);
2065     LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE,  v_BLACK_MODE(0));
2066     LcdWrReg(inf, REG_CFG_DONE, 0x01);
2067         if(enable){
2068                 rk29_set_cursor_en(inf, enable);
2069         }else{
2070                 rk29_set_cursor_en(inf, enable);
2071         }
2072     return 0;
2073 }
2074
2075 static ssize_t dsp_win0_info_read(struct device *device,
2076                             struct device_attribute *attr, char *buf)
2077 {
2078     //char * s = _buf;
2079     struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
2080     struct rk29fb_screen *screen = inf->cur_screen;
2081
2082     u16 xpos=0,ypos=0,xsize=0,ysize=0;
2083
2084     fbprintk("%s\n",__FUNCTION__);
2085     xpos = LcdRdReg(inf, WIN0_DSP_ST) & 0xffff;
2086     ypos = (LcdRdReg(inf, WIN0_DSP_ST)>>16) & 0xffff;
2087
2088     xpos -= (screen->left_margin + screen->hsync_len);
2089     ypos -= (screen->upper_margin + screen->vsync_len);
2090
2091     xsize=LcdRdReg(inf, WIN0_DSP_INFO)& 0xffff;
2092     ysize=(LcdRdReg(inf, WIN0_DSP_INFO)>>16) & 0xffff;
2093     fbprintk("%s %d , %d, %d ,%d\n",__FUNCTION__,xpos,ypos,xsize,ysize);
2094         rk29_set_cursor_test(inf->fb0);
2095
2096     return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d\n", xpos,ypos,xsize,ysize);
2097 }
2098
2099 static ssize_t dsp_win0_info_write(struct device *device,
2100                            struct device_attribute *attr, const char *buf, size_t count)
2101 {
2102      printk("%s\n",__FUNCTION__);
2103      printk("%s %x \n",__FUNCTION__,*buf);
2104      return count;
2105 }
2106
2107 static DEVICE_ATTR(dsp_win0_info,  S_IRUGO|S_IWUSR, dsp_win0_info_read, dsp_win0_info_write);
2108
2109 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
2110 {
2111         struct platform_device *pdev = (struct platform_device*)dev_id;
2112     struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2113     struct win0_par *par = (struct win0_par *)inf->fb1->par;
2114     if(!inf)
2115         return IRQ_HANDLED;
2116
2117         //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
2118
2119     LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
2120
2121         if(SCREEN_MCU == inf->cur_screen->type)
2122         {
2123         inf->mcu_isrcnt = !inf->mcu_isrcnt;
2124         if(inf->mcu_isrcnt)
2125             return IRQ_HANDLED;
2126
2127         if(IsMcuUseFmk())
2128         {
2129             if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST) && (inf->mcu_fmksync == 0))
2130             {
2131                 inf->mcu_fmksync = 1;
2132                  if(inf->cur_screen->refresh)
2133                    inf->cur_screen->refresh(REFRESH_END);
2134                 inf->mcu_fmksync = 0;
2135             }
2136             else
2137             {
2138                 return IRQ_HANDLED;
2139             }
2140         }
2141         else
2142         {
2143             if(inf->mcu_needflush) {
2144                 if(inf->cur_screen->refresh)
2145                     inf->cur_screen->refresh(REFRESH_PRE);
2146                 inf->mcu_needflush = 0;
2147                 inf->mcu_isrcnt = 0;
2148                 LcdSetRegBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
2149             } else {
2150                 if(inf->cur_screen->refresh)
2151                     inf->cur_screen->refresh(REFRESH_END);
2152             }
2153         }
2154         }
2155 #if ANDROID_USE_THREE_BUFS
2156     new_frame_seted = 1;
2157 #endif
2158
2159     if(waitqueue_active(&par->wait)) {
2160         if (par->mirror.c_offset == 0)
2161             printk("error: no new buffer to display\n");
2162
2163         par->done.y_offset = par->displ.y_offset;
2164         par->done.c_offset = par->displ.c_offset;
2165         par->displ.y_offset = par->mirror.y_offset;
2166         par->displ.c_offset = par->mirror.c_offset;
2167         par->mirror.y_offset = 0;
2168         par->mirror.c_offset = 0;
2169
2170         //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
2171         //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
2172         wake_up_interruptible(&par->wait);
2173     }
2174
2175     wq_condition2 = 1;
2176         wq_condition = 1;
2177         wake_up_interruptible(&wq);
2178
2179         return IRQ_HANDLED;
2180 }
2181
2182 #ifdef CONFIG_HAS_EARLYSUSPEND
2183
2184 struct suspend_info {
2185         struct early_suspend early_suspend;
2186         struct rk29fb_inf *inf;
2187 };
2188
2189 static void rk29fb_early_suspend(struct early_suspend *h)
2190 {
2191         struct suspend_info *info = container_of(h, struct suspend_info,
2192                                                 early_suspend);
2193
2194     struct rk29fb_inf *inf = info->inf;
2195
2196     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2197
2198     if(!inf) {
2199         printk("inf==0, rk29fb_suspend fail! \n");
2200         return;
2201     }
2202
2203     set_lcd_pin(g_pdev, 0);
2204
2205         if(inf->cur_screen->standby)
2206         {
2207                 fbprintk(">>>>>> power down the screen! \n");
2208                 inf->cur_screen->standby(1);
2209         }
2210
2211     LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2212        v_HSYNC_POLARITY(1) | v_VSYNC_POLARITY(1) | v_DEN_POLARITY(1) );
2213
2214     LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2215     LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2216         LcdWrReg(inf, REG_CFG_DONE, 0x01);
2217
2218         if(!inf->in_suspend)
2219         {
2220                 fbprintk(">>>>>> diable the lcdc clk! \n");
2221                 wake_lock(&idlelock);
2222                 msleep(100);
2223                 wake_unlock(&idlelock);
2224         clk_disable(inf->aclk_ddr_lcdc);
2225         clk_disable(inf->aclk_disp_matrix);
2226         clk_disable(inf->hclk_cpu_display);
2227         clk_disable(inf->clk);
2228         if (inf->dclk){
2229             clk_disable(inf->dclk);
2230         }
2231         if(inf->clk){
2232             clk_disable(inf->aclk);
2233         }
2234         clk_disable(inf->pd_display);
2235
2236                 inf->in_suspend = 1;
2237         }
2238 }
2239
2240 static void rk29fb_early_resume(struct early_suspend *h)
2241 {
2242         struct suspend_info *info = container_of(h, struct suspend_info,
2243                                         early_suspend);
2244
2245     struct rk29fb_inf *inf = info->inf;
2246     struct rk29fb_screen *screen = inf->cur_screen;
2247
2248     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2249     if(!inf) {
2250         printk("inf==0, rk29fb_resume fail! \n");
2251         return ;
2252     }
2253
2254     if(inf->in_suspend)
2255         {
2256             inf->in_suspend = 0;
2257         fbprintk(">>>>>> enable the lcdc clk! \n");
2258         clk_enable(inf->pd_display);
2259         clk_enable(inf->aclk_disp_matrix);
2260         clk_enable(inf->hclk_cpu_display);
2261         clk_enable(inf->clk);
2262         clk_enable(inf->aclk_ddr_lcdc);
2263
2264         if (inf->dclk){
2265             clk_enable(inf->dclk);
2266         }
2267         if(inf->clk){
2268             clk_enable(inf->aclk);
2269         }
2270         msleep(100);
2271         }
2272     LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
2273     LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
2274     LcdWrReg(inf, REG_CFG_DONE, 0x01);
2275
2276     LcdMskReg(inf, DSP_CTRL0, m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY ,
2277        v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) );
2278
2279         if(inf->cur_screen->standby)
2280         {
2281                 fbprintk(">>>>>> power on the screen! \n");
2282                 inf->cur_screen->standby(0);
2283         }
2284     msleep(100);
2285     set_lcd_pin(g_pdev, 1);
2286         memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4);  //resume reg
2287 }
2288
2289 static struct suspend_info suspend_info = {
2290         .early_suspend.suspend = rk29fb_early_suspend,
2291         .early_suspend.resume = rk29fb_early_resume,
2292         .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
2293 };
2294 #endif
2295
2296 static int __init rk29fb_probe (struct platform_device *pdev)
2297 {
2298     struct rk29fb_inf *inf = NULL;
2299     struct resource *res = NULL;
2300     struct resource *mem = NULL;
2301     struct rk29fb_info *mach_info = NULL;
2302     struct rk29fb_screen *screen = NULL;
2303     struct win0_par* par = NULL;
2304         int irq = 0;
2305     int ret = 0;
2306
2307     fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2308
2309     /* Malloc rk29fb_inf and set it to pdev for drvdata */
2310     fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
2311     inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
2312     if(!inf)
2313     {
2314         dev_err(&pdev->dev, ">> inf kmalloc fail!");
2315         ret = -ENOMEM;
2316                 goto release_drvdata;
2317     }
2318     memset(inf, 0, sizeof(struct rk29fb_inf));
2319         platform_set_drvdata(pdev, inf);
2320
2321     mach_info = pdev->dev.platform_data;
2322     /* Fill screen info and set current screen */
2323     fbprintk(">> Fill screen info and set current screen \n");
2324     set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
2325     inf->cur_screen = &inf->panel1_info;
2326     screen = inf->cur_screen;
2327     if(SCREEN_NULL==screen->type)
2328     {
2329         dev_err(&pdev->dev, ">> Please select a display device! \n");
2330         ret = -EINVAL;
2331                 goto release_drvdata;
2332     }
2333
2334     /* get virtual basic address of lcdc register */
2335     fbprintk(">> get virtual basic address of lcdc register \n");
2336     res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
2337     if (res == NULL)
2338     {
2339         dev_err(&pdev->dev, "failed to get memory registers\n");
2340         ret = -ENOENT;
2341                 goto release_drvdata;
2342     }
2343     inf->reg_phy_base = res->start;
2344     inf->len = (res->end - res->start) + 1;
2345     mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
2346     if (mem == NULL)
2347     {
2348         dev_err(&pdev->dev, "failed to get memory region\n");
2349         ret = -ENOENT;
2350                 goto release_drvdata;
2351     }
2352     fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
2353     inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
2354     if (inf->reg_vir_base == NULL)
2355     {
2356         dev_err(&pdev->dev, "ioremap() of registers failed\n");
2357         ret = -ENXIO;
2358                 goto release_drvdata;
2359     }
2360     inf->preg = (LCDC_REG*)inf->reg_vir_base;
2361
2362     /* Prepare win1 info */
2363     fbprintk(">> Prepare win1 info \n");
2364         inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2365     if(!inf->fb0)
2366     {
2367         dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
2368                 inf->fb0 = NULL;
2369         ret = -ENOMEM;
2370                 goto release_win1fb;
2371     }
2372
2373     par = (struct win0_par*)inf->fb0->par;
2374     strcpy(inf->fb0->fix.id, "fb0");
2375     inf->fb0->fix.type        = FB_TYPE_PACKED_PIXELS;
2376     inf->fb0->fix.type_aux    = 0;
2377     inf->fb0->fix.xpanstep    = 1;
2378     inf->fb0->fix.ypanstep    = 1;
2379     inf->fb0->fix.ywrapstep   = 0;
2380     inf->fb0->fix.accel       = FB_ACCEL_NONE;
2381     inf->fb0->fix.visual      = FB_VISUAL_TRUECOLOR;
2382     inf->fb0->fix.smem_len    = 0;
2383     inf->fb0->fix.line_length = 0;
2384     inf->fb0->fix.smem_start  = 0;
2385
2386     inf->fb0->var.xres = screen->x_res;
2387     inf->fb0->var.yres = screen->y_res;
2388     inf->fb0->var.bits_per_pixel = 16;
2389     inf->fb0_color_deepth = 0;
2390     inf->fb0->var.xres_virtual = screen->x_res;
2391     inf->fb0->var.yres_virtual = screen->y_res;
2392     inf->fb0->var.width = screen->width;
2393     inf->fb0->var.height = screen->height;
2394     inf->fb0->var.pixclock = screen->pixclock;
2395     inf->fb0->var.left_margin = screen->left_margin;
2396     inf->fb0->var.right_margin = screen->right_margin;
2397     inf->fb0->var.upper_margin = screen->upper_margin;
2398     inf->fb0->var.lower_margin = screen->lower_margin;
2399     inf->fb0->var.vsync_len = screen->vsync_len;
2400     inf->fb0->var.hsync_len = screen->hsync_len;
2401     inf->fb0->var.red    = def_rgb_16.red;
2402     inf->fb0->var.green  = def_rgb_16.green;
2403     inf->fb0->var.blue   = def_rgb_16.blue;
2404     inf->fb0->var.transp = def_rgb_16.transp;
2405
2406     inf->fb0->var.nonstd      = 0;  //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2407     inf->fb0->var.grayscale   = 0;  //win1 transprent mode & value(mode<<8 + value)
2408     inf->fb0->var.activate    = FB_ACTIVATE_NOW;
2409     inf->fb0->var.accel_flags = 0;
2410     inf->fb0->var.vmode       = FB_VMODE_NONINTERLACED;
2411
2412     inf->fb0->fbops           = &fb0_ops;
2413     inf->fb0->flags           = FBINFO_FLAG_DEFAULT;
2414     inf->fb0->pseudo_palette  = par->pseudo_pal;
2415     inf->fb0->screen_base     = 0;
2416
2417     memset(par, 0, sizeof(struct win0_par));
2418
2419         ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2420         if (ret < 0)
2421                 goto release_cmap;
2422
2423     /* alloc win1 buf */
2424     res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2425     if (res == NULL)
2426     {
2427         dev_err(&pdev->dev, "failed to get win1 memory \n");
2428         ret = -ENOENT;
2429         goto release_win1fb;
2430     }
2431     inf->fb0->fix.smem_start = res->start;
2432     inf->fb0->fix.smem_len = res->end - res->start + 1;
2433     inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2434     memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2435
2436     #ifdef CONFIG_FB_WORK_IPP
2437        /* alloc win1 ipp buf */
2438     res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 ipp buf");
2439     if (res == NULL)
2440     {
2441         dev_err(&pdev->dev, "failed to get win1 ipp memory \n");
2442         ret = -ENOENT;
2443         goto release_win1fb;
2444     }
2445     inf->fb0->fix.mmio_start = res->start;
2446     inf->fb0->fix.mmio_len = res->end - res->start + 1;
2447     #endif
2448
2449     /* Prepare win0 info */
2450     fbprintk(">> Prepare win0 info \n");
2451     inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2452     if(!inf->fb1)
2453     {
2454         dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2455                 inf->fb1 = NULL;
2456                 ret = -ENOMEM;
2457                 goto release_win0fb;
2458     }
2459
2460     par = (struct win0_par*)inf->fb1->par;
2461
2462     strcpy(inf->fb1->fix.id, "fb1");
2463         inf->fb1->fix.type            = FB_TYPE_PACKED_PIXELS;
2464         inf->fb1->fix.type_aux    = 0;
2465         inf->fb1->fix.xpanstep    = 1;
2466         inf->fb1->fix.ypanstep    = 1;
2467         inf->fb1->fix.ywrapstep   = 0;
2468         inf->fb1->fix.accel       = FB_ACCEL_NONE;
2469     inf->fb1->fix.visual      = FB_VISUAL_TRUECOLOR;
2470     inf->fb1->fix.smem_len    = 0;
2471     inf->fb1->fix.line_length = 0;
2472     inf->fb1->fix.smem_start  = 0;
2473
2474     inf->fb1->var.xres = screen->x_res;
2475     inf->fb1->var.yres = screen->y_res;
2476     inf->fb1->var.bits_per_pixel = 16;
2477     inf->fb1->var.xres_virtual = screen->x_res;
2478     inf->fb1->var.yres_virtual = screen->y_res;
2479     inf->fb1->var.width = screen->width;
2480     inf->fb1->var.height = screen->height;
2481     inf->fb1->var.pixclock = screen->pixclock;
2482     inf->fb1->var.left_margin = screen->left_margin;
2483     inf->fb1->var.right_margin = screen->right_margin;
2484     inf->fb1->var.upper_margin = screen->upper_margin;
2485     inf->fb1->var.lower_margin = screen->lower_margin;
2486     inf->fb1->var.vsync_len = screen->vsync_len;
2487     inf->fb1->var.hsync_len = screen->hsync_len;
2488     inf->fb1->var.red    = def_rgb_16.red;
2489     inf->fb1->var.green  = def_rgb_16.green;
2490     inf->fb1->var.blue   = def_rgb_16.blue;
2491     inf->fb1->var.transp = def_rgb_16.transp;
2492
2493     inf->fb1->var.nonstd      = 0;  //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2494     inf->fb1->var.grayscale   = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2495     inf->fb1->var.activate    = FB_ACTIVATE_NOW;
2496     inf->fb1->var.accel_flags = 0;
2497     inf->fb1->var.vmode       = FB_VMODE_NONINTERLACED;
2498
2499     inf->fb1->fbops           = &fb1_ops;
2500         inf->fb1->flags               = FBINFO_FLAG_DEFAULT;
2501         inf->fb1->pseudo_palette  = par->pseudo_pal;
2502         inf->fb1->screen_base     = 0;
2503
2504     memset(par, 0, sizeof(struct win0_par));
2505
2506         init_waitqueue_head(&par->wait);
2507
2508         /* Init all lcdc and lcd before register_framebuffer. */
2509         /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2510         fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2511     init_lcdc(inf->fb0);
2512
2513   #if 0 //def CONFIG_CPU_FREQ
2514    // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2515    // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2516   #endif
2517         fbprintk("got clock\n");
2518
2519         if(mach_info)
2520     {
2521         struct rk29_fb_setting_info fb_setting;
2522         if( OUT_P888==inf->cur_screen->face )     // set lcdc iomux
2523         {
2524             fb_setting.data_num = 24;
2525         }
2526         else if(OUT_P666 == inf->cur_screen->face )
2527         {
2528             fb_setting.data_num = 18;
2529         }
2530         else
2531         {
2532             fb_setting.data_num = 16;
2533         }
2534         fb_setting.den_en = 1;
2535         fb_setting.vsync_en = 1;
2536         fb_setting.disp_on_en = 1;
2537         fb_setting.standby_en = 1;
2538         if( inf->cur_screen->mcu_usefmk )
2539             fb_setting.mcu_fmk_en =1;
2540         mach_info->io_init(&fb_setting);
2541     }
2542
2543         set_lcd_pin(pdev, 1);
2544         mdelay(10);
2545         g_pdev = pdev;
2546         inf->mcu_usetimer = 1;
2547     inf->mcu_fmksync = 0;
2548         load_screen(inf->fb0, 1);
2549
2550     /* Register framebuffer(fb0 & fb1) */
2551     fbprintk(">> Register framebuffer(fb0) \n");
2552     ret = register_framebuffer(inf->fb0);
2553     if(ret<0)
2554     {
2555         printk(">> fb0 register_framebuffer fail!\n");
2556         ret = -EINVAL;
2557                 goto release_win0fb;
2558     }
2559     fbprintk(">> Register framebuffer(fb1) \n");
2560
2561     ret = register_framebuffer(inf->fb1);
2562     if(ret<0)
2563     {
2564         printk(">> fb1 register_framebuffer fail!\n");
2565         ret = -EINVAL;
2566                 goto unregister_win1fb;
2567     }
2568
2569     ret = device_create_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2570     if(ret)
2571     {
2572         printk(">> fb1 dsp win0 info device_create_file err\n");
2573         ret = -EINVAL;
2574     }
2575 #ifdef CONFIG_HAS_EARLYSUSPEND
2576         suspend_info.inf = inf;
2577         register_early_suspend(&suspend_info.early_suspend);
2578 #endif
2579
2580     /* get and request irq */
2581     fbprintk(">> get and request irq \n");
2582     irq = platform_get_irq(pdev, 0);
2583     if (irq < 0) {
2584         dev_err(&pdev->dev, "no irq for device\n");
2585         ret = -ENOENT;
2586         goto unregister_win1fb;
2587     }
2588     ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2589     if (ret) {
2590         dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2591         ret = -EBUSY;
2592         goto release_irq;
2593     }
2594
2595     if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2596     {
2597         ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2598         if (ret)
2599         {
2600             dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2601             ret = -EBUSY;
2602             goto release_irq;
2603         }
2604     }
2605
2606 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
2607     fb0_set_par(inf->fb0);
2608     if (fb_prepare_logo(inf->fb0, FB_ROTATE_UR)) {
2609         /* Start display and show logo on boot */
2610         fb_set_cmap(&inf->fb0->cmap, inf->fb0);
2611         fb_show_logo(inf->fb0, FB_ROTATE_UR);
2612         fb0_blank(FB_BLANK_UNBLANK, inf->fb0);
2613     }
2614 #endif
2615
2616     printk(" %s ok\n", __FUNCTION__);
2617     return ret;
2618
2619 release_irq:
2620         if(irq>=0)
2621         free_irq(irq, pdev);
2622 unregister_win1fb:
2623     unregister_framebuffer(inf->fb0);
2624 release_win0fb:
2625         if(inf->fb1)
2626                 framebuffer_release(inf->fb1);
2627         inf->fb1 = NULL;
2628 release_cmap:
2629     if(&inf->fb0->cmap)
2630         fb_dealloc_cmap(&inf->fb0->cmap);
2631 release_win1fb:
2632         if(inf->fb0)
2633                 framebuffer_release(inf->fb0);
2634         inf->fb0 = NULL;
2635 release_drvdata:
2636         if(inf && inf->reg_vir_base)
2637         iounmap(inf->reg_vir_base);
2638         if(inf && mem)
2639         release_mem_region(inf->reg_phy_base, inf->len);
2640         if(inf)
2641         kfree(inf);
2642         platform_set_drvdata(pdev, NULL);
2643         return ret;
2644 }
2645
2646 static int rk29fb_remove(struct platform_device *pdev)
2647 {
2648     struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2649     struct fb_info *info = NULL;
2650         //pm_message_t msg;
2651     struct rk29fb_info *mach_info = NULL;
2652     int irq = 0;
2653
2654         fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2655
2656     if(!inf) {
2657         printk("inf==0, rk29_fb_remove fail! \n");
2658         return -EINVAL;
2659     }
2660     device_remove_file(inf->fb1->dev, &dev_attr_dsp_win0_info);
2661
2662     irq = platform_get_irq(pdev, 0);
2663     if (irq >0)
2664     {
2665     free_irq(irq, pdev);
2666     }
2667
2668     mach_info = pdev->dev.platform_data;
2669     if(mach_info->mcu_fmk_pin)
2670     {
2671         free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2672     }
2673
2674         set_lcd_pin(pdev, 0);
2675
2676     // blank the lcdc
2677     if(inf->fb1)
2678         fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2679     if(inf->fb0)
2680         fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2681
2682         // suspend the lcdc
2683         //rk29fb_suspend(pdev, msg);
2684     // unmap memory and release framebuffer
2685     if(inf->fb1) {
2686         info = inf->fb1;
2687         if (info->screen_base) {
2688                 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2689                 info->screen_base = 0;
2690                 info->fix.smem_start = 0;
2691                 info->fix.smem_len = 0;
2692         }
2693         unregister_framebuffer(inf->fb1);
2694         framebuffer_release(inf->fb1);
2695         inf->fb1 = NULL;
2696     }
2697     if(inf->fb0) {
2698         info = inf->fb0;
2699         if (info->screen_base) {
2700             //    dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2701                 info->screen_base = 0;
2702                 info->fix.smem_start = 0;
2703                 info->fix.smem_len = 0;
2704         }
2705         unregister_framebuffer(inf->fb0);
2706         framebuffer_release(inf->fb0);
2707         inf->fb0 = NULL;
2708     }
2709
2710   #if 0 //def CONFIG_CPU_FREQ
2711    // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2712   #endif
2713
2714     msleep(100);
2715
2716         if (inf->clk)
2717     {
2718                 clk_disable(inf->clk);
2719                 clk_put(inf->clk);
2720                 inf->clk = NULL;
2721         }
2722     if (inf->dclk)
2723     {
2724                 clk_disable(inf->dclk);
2725                 clk_put(inf->dclk);
2726                 inf->dclk = NULL;
2727         }
2728
2729     kfree(inf);
2730     platform_set_drvdata(pdev, NULL);
2731
2732     return 0;
2733 }
2734
2735 static void rk29fb_shutdown(struct platform_device *pdev)
2736 {
2737     struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2738
2739         fbprintk("----------------------------rk29fb_shutdown----------------------------\n");
2740
2741     set_lcd_pin(pdev, 0);
2742     if(!inf->in_suspend)
2743     {
2744         LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
2745         LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
2746         LcdWrReg(inf, REG_CFG_DONE, 0x01);
2747         mdelay(100);
2748         clk_disable(inf->aclk_ddr_lcdc);
2749         clk_disable(inf->aclk_disp_matrix);
2750         clk_disable(inf->hclk_cpu_display);
2751         clk_disable(inf->clk);
2752         if(inf->dclk){
2753             clk_disable(inf->dclk);
2754         }
2755         if(inf->clk){
2756             clk_disable(inf->aclk);
2757         }
2758         clk_disable(inf->pd_display);
2759         //pmu_set_power_domain(PD_DISPLAY, 0);
2760                 inf->in_suspend = 1;
2761         }
2762
2763 }
2764
2765 static struct platform_driver rk29fb_driver = {
2766         .probe          = rk29fb_probe,
2767         .remove         = rk29fb_remove,
2768         .driver         = {
2769                 .name   = "rk29-fb",
2770                 .owner  = THIS_MODULE,
2771         },
2772         .shutdown   = rk29fb_shutdown,
2773 };
2774
2775 static int __init rk29fb_init(void)
2776 {
2777         wake_lock_init(&idlelock, WAKE_LOCK_IDLE, "fb");
2778     return platform_driver_register(&rk29fb_driver);
2779 }
2780
2781 static void __exit rk29fb_exit(void)
2782 {
2783     platform_driver_unregister(&rk29fb_driver);
2784 }
2785
2786 fs_initcall(rk29fb_init);
2787 module_exit(rk29fb_exit);
2788
2789
2790 MODULE_AUTHOR("  zyw@rock-chips.com");
2791 MODULE_DESCRIPTION("Driver for rk29 fb device");
2792 MODULE_LICENSE("GPL");
2793
2794