2 * drivers/video/rk29_fb.c
4 * Copyright (C) 2010 ROCKCHIP, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
25 #include <linux/init.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/interrupt.h>
28 #include <linux/platform_device.h>
29 #include <linux/clk.h>
30 #include <linux/backlight.h>
31 #include <linux/timer.h>
32 #include <linux/time.h>
33 #include <linux/wait.h>
34 #include <linux/earlysuspend.h>
35 #include <linux/cpufreq.h>
39 #include <asm/div64.h>
40 #include <asm/uaccess.h>
48 #include <mach/iomux.h>
49 #include <mach/gpio.h>
50 #include <mach/board.h>
51 #include <mach/rk29_iomap.h>
52 //#include <asm/uaccess.h>
54 #include "./display/screen/screen.h"
56 #define ANDROID_USE_THREE_BUFS 0 //android use three buffers to accelerate UI display in rgb plane
59 #define fbprintk(msg...) printk(msg);
61 #define fbprintk(msg...)
66 #define fbprintk2(msg...) printk(msg);
68 #define fbprintk2(msg...)
71 #define LcdReadBit(inf, addr, msk) ((inf->regbak.addr=inf->preg->addr)&(msk))
72 #define LcdWrReg(inf, addr, val) inf->preg->addr=inf->regbak.addr=(val)
73 #define LcdRdReg(inf, addr) (inf->preg->addr)
74 #define LcdSetBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) |= (msk))
75 #define LcdClrBit(inf, addr, msk) inf->preg->addr=((inf->regbak.addr) &= ~(msk))
76 #define LcdSetRegBit(inf, addr, msk) inf->preg->addr=((inf->preg->addr) |= (msk))
77 #define LcdMskReg(inf, addr, msk, val) (inf->regbak.addr)&=~(msk); inf->preg->addr=(inf->regbak.addr|=(val))
80 #define IsMcuLandscape() ((SCREEN_MCU==inf->cur_screen->type) && (0==inf->mcu_scandir))
81 #define IsMcuUseFmk() ( (2==inf->cur_screen->mcu_usefmk) || (1==inf->cur_screen->mcu_usefmk))
83 #define CalScaleW0(x, y) (((u32)x*0x1000)/y)
86 struct fb_bitfield red;
87 struct fb_bitfield green;
88 struct fb_bitfield blue;
89 struct fb_bitfield transp;
92 static struct rk29fb_rgb def_rgb_16 = {
93 red: { offset: 11, length: 5, },
94 green: { offset: 5, length: 6, },
95 blue: { offset: 0, length: 5, },
96 transp: { offset: 0, length: 0, },
116 struct fb_info *win0fb;
117 struct fb_info *win1fb;
119 void __iomem *reg_vir_base; // virtual basic address of lcdc register
120 u32 reg_phy_base; // physical basic address of lcdc register
121 u32 len; // physical map length of lcdc register
124 struct clk *dclk; //lcdc dclk
125 struct clk *dclk_parent; //lcdc dclk divider frequency source
126 struct clk *dclk_divider; //lcdc demodulator divider frequency
127 struct clk *aclk; //lcdc share memory frequency
128 struct clk *aclk_parent; //lcdc aclk divider frequency source
129 unsigned long dclk_rate;
131 /* lcdc reg base address and backup reg */
137 /* variable used in mcu panel */
141 struct timer_list mcutimer;
147 /* external memery */
148 char __iomem *screen_base2;
150 unsigned long smem_start2;
152 char __iomem *cursor_base; /* cursor Virtual address*/
153 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
154 unsigned long cursor_start;
156 struct rk29fb_screen lcd_info;
157 struct rk29fb_screen tv_info[5];
158 struct rk29fb_screen hdmi_info[2];
159 struct rk29fb_screen *cur_screen;
160 #ifdef CONFIG_CPU_FREQ
161 struct notifier_block freq_transition;
166 typedef enum _TRSP_MODE
178 struct platform_device *g_pdev = NULL;
179 static int win1fb_set_par(struct fb_info *info);
182 #define CHK_SUSPEND(inf) \
183 if(inf->in_suspend) { \
184 fbprintk(">>>>>> fb is in suspend! return! \n"); \
188 #define CHK_SUSPEND(inf)
191 static DECLARE_WAIT_QUEUE_HEAD(wq);
192 static int wq_condition = 0;
194 #if ANDROID_USE_THREE_BUFS
195 static int new_frame_seted = 1;
198 void set_lcd_pin(struct platform_device *pdev, int enable)
200 struct rk29fb_info *mach_info = pdev->dev.platform_data;
202 unsigned display_on = mach_info->disp_on_pin;
203 unsigned lcd_standby = mach_info->standby_pin;
205 int display_on_pol = mach_info->disp_on_value;
206 int lcd_standby_pol = mach_info->standby_value;
208 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
209 fbprintk(">>>>>> display_on(%d) = %d \n", display_on, enable ? display_on_pol : !display_on_pol);
210 fbprintk(">>>>>> lcd_standby(%d) = %d \n", lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);
214 if(display_on != INVALID_GPIO)
216 gpio_direction_output(display_on, 0);
217 gpio_set_value(display_on, enable ? display_on_pol : !display_on_pol);
219 if(lcd_standby != INVALID_GPIO)
221 gpio_direction_output(lcd_standby, 0);
222 gpio_set_value(lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);
226 int mcu_do_refresh(struct rk29fb_inf *inf)
228 if(inf->mcu_stopflush) return 0;
230 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
235 inf->mcu_needflush = 1;
239 // not use frame mark
240 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
242 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLD_STATUS))
244 inf->mcu_needflush = 1;
248 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
249 inf->mcu_needflush = 0;
251 LcdSetRegBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
258 void mcutimer_callback(unsigned long arg)
260 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
261 static int waitcnt = 0;
263 mod_timer(&inf->mcutimer, jiffies + HZ/10);
265 switch(inf->mcu_status)
268 inf->mcu_status = MS_MCU;
271 if(inf->mcu_usetimer) mcu_do_refresh(inf);
274 inf->mcu_status = MS_EWAITEND;
282 inf->mcu_status = MS_EEND;
286 inf->mcu_status = MS_MCU;
289 inf->mcu_status = MS_MCU;
294 int mcu_refresh(struct rk29fb_inf *inf)
296 static int mcutimer_inited = 0;
298 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
303 init_timer(&inf->mcutimer);
304 inf->mcutimer.function = mcutimer_callback;
305 inf->mcutimer.expires = jiffies + HZ/5;
306 inf->mcu_status = MS_IDLE;
307 add_timer(&inf->mcutimer);
310 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
315 int mcu_ioctl(unsigned int cmd, unsigned long arg)
317 struct rk29fb_inf *inf = NULL;
318 if(!g_pdev) return -1;
320 inf = dev_get_drvdata(&g_pdev->dev);
325 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
326 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
327 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
331 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
332 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
336 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
337 LcdWrReg(inf, REG_CFG_DONE, 0x01);
347 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
349 struct platform_device *pdev = (struct platform_device*)dev_id;
350 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
351 struct rk29fb_screen *screen;
353 if(!inf) return IRQ_HANDLED;
355 screen = inf->cur_screen;
357 if(0==screen->mcu_usefmk) {
361 if(inf->mcu_fmksync == 1)
364 inf->mcu_fmksync = 1;
365 if(inf->mcu_needflush)
367 inf->mcu_needflush = 0;
369 if(inf->cur_screen->refresh)
370 inf->cur_screen->refresh(REFRESH_PRE);
371 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
373 inf->mcu_fmksync = 0;
378 int init_lcdc(struct fb_info *info)
380 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
383 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
385 // set AHB access rule and disable all windows
386 LcdWrReg(inf, SYS_CONFIG, 0x20000000);
387 LcdWrReg(inf, SWAP_CTRL, 0);
388 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000860);
390 // and mcu holdmode; and set win1 top.
391 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
392 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
394 // disable blank out, black out, tristate out, yuv2rgb bypass
395 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
396 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
397 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
398 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
401 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
402 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
404 LcdWrReg(inf, DSP_CTRL0, 0);
405 LcdWrReg(inf, DSP_CTRL1, 0);
407 // initialize all interrupt
408 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
410 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
412 LcdWrReg(inf, INT_STATUS, clr | msk);
414 // let above to take effect
415 LcdWrReg(inf, REG_CFG_DONE, 0x01);
420 void load_screen(struct fb_info *info, bool initscreen)
423 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
424 struct rk29fb_screen *screen = inf->cur_screen;
425 u16 face = screen->face;
426 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
427 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
428 u16 x_res = screen->x_res, y_res = screen->y_res;
431 u32 aclk_rate = 150000000;
433 if(!g_pdev) return -1;
435 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
437 // set the rgb or mcu
438 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
440 // set out format and mcu timing
441 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
442 if(mcu_total>31) mcu_total = 31;
443 if(mcu_total<3) mcu_total = 3;
444 mcu_rwstart = (mcu_total+1)/4 - 1;
445 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
446 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
447 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
449 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
450 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
452 LcdMskReg(inf, MCU_TIMING_CTRL,
453 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
454 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
455 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
456 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
457 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
460 // set synchronous pin polarity and data pin swap rule
461 LcdMskReg(inf, DSP_CTRL0,
462 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
463 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
464 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
465 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
468 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
470 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
471 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));
473 // set horizontal & vertical out timing
474 if(SCREEN_MCU==inf->cur_screen->type)
476 right_margin = x_res/6;
479 printk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
480 screen->hsync_len , screen->left_margin , x_res , right_margin );
481 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->hsync_len) |
482 v_BIT11HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
483 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->hsync_len + screen->left_margin + x_res) |
484 v_BIT11HI(screen->hsync_len + screen->left_margin));
486 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
487 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
488 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
489 v_BIT11HI(screen->vsync_len + screen->upper_margin));
491 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
492 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
494 // let above to take effect
495 LcdWrReg(inf, REG_CFG_DONE, 0x01);
497 inf->clk = clk_get(&g_pdev->dev, "hclk_lcdc");
498 if (!inf->clk || IS_ERR(inf->clk))
500 printk(KERN_ERR "failed to get lcdc_hclk source\n");
504 inf->dclk = clk_get(&g_pdev->dev, "dclk_lcdc");
505 if (!inf->dclk || IS_ERR(inf->dclk))
507 printk(KERN_ERR "failed to get lcd dclock source\n");
510 inf->dclk_divider= clk_get(&g_pdev->dev, "dclk_lcdc_div");
511 if (!inf->dclk_divider || IS_ERR(inf->dclk_divider))
513 printk(KERN_ERR "failed to get lcd clock lcdc_divider source \n");
517 if(inf->cur_screen == &inf->lcd_info) {
518 inf->dclk_parent = clk_get(&g_pdev->dev, "periph_pll");
520 inf->dclk_parent = clk_get(&g_pdev->dev, "codec_pll");
523 if (!inf->dclk_parent || IS_ERR(inf->dclk_parent))
525 printk(KERN_ERR "failed to get lcd dclock parent source\n");
529 inf->aclk = clk_get(&g_pdev->dev, "aclk_lcdc");
530 if (!inf->aclk || IS_ERR(inf->aclk))
532 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
535 inf->aclk_parent = clk_get(&g_pdev->dev, "periph_pll");
536 if (!inf->dclk_parent || IS_ERR(inf->dclk_parent))
538 printk(KERN_ERR "failed to get lcd dclock parent source\n");
543 if(SCREEN_MCU==screen->type) screen->pixclock = 150; //mcu fix to 150 MHz
545 clk_set_parent(inf->dclk_divider, inf->dclk_parent);
546 clk_set_parent(inf->dclk, inf->dclk_divider);
547 clk_set_parent(inf->aclk, inf->aclk_parent);
549 dclk_rate = screen->pixclock * 1000000;
551 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, clk_rate);
553 ret = clk_set_rate(inf->dclk_divider, dclk_rate);
556 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
558 if(screen->lcdc_aclk){
559 aclk_rate = screen->lcdc_aclk * 1000000;
561 ret = clk_set_rate(inf->aclk, aclk_rate);
563 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
566 clk_enable(inf->dclk);
567 clk_enable(inf->clk);
568 clk_enable(inf->aclk);
571 if(screen->init && initscreen)
577 #ifdef CONFIG_CPU_FREQ
579 * CPU clock speed change handler. We need to adjust the LCD timing
580 * parameters when the CPU clock is adjusted by the power management
583 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
586 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
588 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
589 struct rk29fb_screen *screen = inf->cur_screen;
594 case CPUFREQ_PRECHANGE:
596 case CPUFREQ_POSTCHANGE:
598 dclk_rate = screen->pixclock * 1000000;
600 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
602 clk_set_rate(inf->dclk_divider, dclk_rate);
610 static inline unsigned int chan_to_field(unsigned int chan,
611 struct fb_bitfield *bf)
614 chan >>= 16 - bf->length;
615 return chan << bf->offset;
618 static int fb_setcolreg(unsigned regno,
619 unsigned red, unsigned green, unsigned blue,
620 unsigned transp, struct fb_info *info)
623 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
625 switch (info->fix.visual) {
626 case FB_VISUAL_TRUECOLOR:
627 /* true-colour, use pseudo-palette */
629 u32 *pal = info->pseudo_palette;
630 val = chan_to_field(red, &info->var.red);
631 val |= chan_to_field(green, &info->var.green);
632 val |= chan_to_field(blue, &info->var.blue);
637 return -1; /* unknown type */
644 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
646 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
648 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
650 /* check not being asked to exceed capabilities */
652 if (cursor->image.width > 32)
655 if (cursor->image.height > 32)
658 if (cursor->image.depth > 1)
662 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
664 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
667 if (cursor->set & FB_CUR_SETPOS)
669 unsigned int x = cursor->image.dx;
670 unsigned int y = cursor->image.dy;
672 if (x >= 0x800 || y >= 0x800 )
674 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
678 if (cursor->set & FB_CUR_SETCMAP)
680 unsigned int bg_col = cursor->image.bg_color;
681 unsigned int fg_col = cursor->image.fg_color;
683 fbprintk("%s: update cmap (%08x,%08x)\n",
684 __func__, bg_col, fg_col);
686 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
687 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));
689 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
690 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));
693 if ((cursor->set & FB_CUR_SETSIZE ||
694 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
695 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
697 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
698 * clears it to transparent then combines the cursor
699 * shape plane with the colour plane to set the
702 const unsigned char *pcol = cursor->image.data;
703 const unsigned char *pmsk = cursor->mask;
705 unsigned long cursor_mem_start;
706 unsigned char dcol = 0;
707 unsigned char dmsk = 0;
710 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
711 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
713 fbprintk("%s: setting shape (%d,%d)\n",
714 __func__, cursor->image.width, cursor->image.height);
716 memset(dst, 0, CURSOR_BUF_SIZE);
718 for (y = 0; y < cursor->image.height; y++)
720 for (x = 0; x < cursor->image.width; x++)
731 op = (dcol & 1) ? 1 : 3;
732 op <<= ((x % 4) * 2);
733 *(u8*)(dst+(x/4)) |= op;
738 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
739 LcdWrReg(inf, HWC_MST, cursor_mem_start);
740 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
741 if(SCREEN_MCU == inf->cur_screen->type) {
742 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
746 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
748 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
755 static int win0fb_blank(int blank_mode, struct fb_info *info)
757 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
759 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
765 case FB_BLANK_UNBLANK:
766 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
769 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
772 LcdWrReg(inf, REG_CFG_DONE, 0x01);
778 static int win0fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
780 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
781 struct rk29fb_screen *screen = inf->cur_screen;
783 u32 ScaleYRGBY=0x1000;
784 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
785 u16 ypos = (var->nonstd>>20) & 0xfff;
786 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
787 u16 ysize = (var->grayscale>>20) & 0xfff;
788 u16 xlcd = screen->x_res; //size of panel
789 u16 ylcd = screen->y_res;
792 if(inf->win0fb->var.rotate == 270) {
793 xlcd = screen->y_res;
794 ylcd = screen->x_res;
797 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
801 if( 0==var->xres_virtual || 0==var->yres_virtual ||
802 0==var->xres || 0==var->yres || var->xres<16 ||
803 0==xsize || 0==ysize || xsize<16 ||
804 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
806 printk(">>>>>> win0fb_check_var fail 1!!! \n");
807 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
808 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
809 var->bits_per_pixel, var->bits_per_pixel);
813 if( (var->xoffset+var->xres)>var->xres_virtual ||
814 (var->yoffset+var->yres)>var->yres_virtual ||
815 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
817 printk(">>>>>> win0fb_check_var fail 2!!! \n");
818 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
819 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
820 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
824 switch(var->nonstd&0x0f)
827 switch(var->bits_per_pixel)
830 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
831 var->xres = (var->xres + 0x1) & (~0x1);
832 var->xoffset = (var->xoffset) & (~0x1);
835 var->bits_per_pixel = 32;
838 var->nonstd &= ~0xc0; //not support I2P in this format
841 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
842 var->xres = (var->xres + 0x3) & (~0x3);
843 var->xoffset = (var->xoffset) & (~0x3);
846 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
847 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
848 var->xres = (var->xres + 0x3) & (~0x3);
849 var->yres = (var->yres + 0x1) & (~0x1);
850 var->xoffset = (var->xoffset) & (~0x3);
851 var->yoffset = (var->yoffset) & (~0x1);
854 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
855 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
856 var->xres = (var->xres + 0x3) & (~0x3);
857 var->yres = (var->yres + 0x1) & (~0x1);
858 var->xoffset = (var->xoffset) & (~0x3);
859 var->yoffset = (var->yoffset) & (~0x1);
860 var->nonstd &= ~0xc0; //not support I2P in this format
864 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
865 var->xres = (var->xres + 0x3) & (~0x3);
866 var->xoffset = (var->xoffset) & (~0x3);
867 var->nonstd &= ~0xc0; //not support I2P in this format
870 printk(">>>>>> win0fb var->nonstd=%d is invalid! \n", var->nonstd);
874 if(var->rotate == 270)
882 ScaleYRGBY = CalScaleW0(yres, ysize);
884 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
886 return -EINVAL; // multiple of scale down or scale up can't exceed 8
892 static int win0fb_set_par(struct fb_info *info)
894 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
895 struct rk29fb_screen *screen = inf->cur_screen;
896 struct fb_var_screeninfo *var = &info->var;
897 struct fb_fix_screeninfo *fix = &info->fix;
898 struct win0_par *par = info->par;
901 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
903 u32 xact = var->xres; /* visible resolution */
904 u32 yact = var->yres;
905 u32 xvir = var->xres_virtual; /* virtual resolution */
906 u32 yvir = var->yres_virtual;
907 u32 xact_st = var->xoffset; /* offset from virtual to visible */
908 u32 yact_st = var->yoffset; /* resolution */
910 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
911 u16 ypos = (var->nonstd>>20) & 0xfff;
912 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
913 u16 ysize = (var->grayscale>>20) & 0xfff;
915 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
916 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
918 u8 data_format = var->nonstd&0x0f;
919 u32 win0_en = var->reserved[2];
920 u32 y_addr = var->reserved[3]; //user alloc buf addr y
921 u32 uv_addr = var->reserved[4];
923 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
927 /* calculate y_offset,uv_offset,line_length,cblen and crlen */
931 switch(var->bits_per_pixel)
935 fix->line_length = 2 * xvir;
936 par->y_offset = (yact_st*xvir + xact_st)*2;
940 fix->line_length = 4 * xvir;
941 par->y_offset = (yact_st*xvir + xact_st)*4;
949 fix->line_length = xvir;
950 cblen = crlen = (xvir*yvir)/2;
951 par->y_offset = yact_st*xvir + xact_st;
952 par->uv_offset = yact_st*xvir + xact_st;
956 fix->line_length = xvir;
957 cblen = crlen = (xvir*yvir)/4;
959 par->y_offset = yact_st*xvir + xact_st;
960 par->uv_offset = (yact_st/2)*xvir + xact_st;
965 fix->line_length = xvir;
966 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
967 par->uv_offset = (yact_st/2)*xvir + xact_st;
968 cblen = crlen = (xvir*yvir)/4;
973 fix->line_length = xvir;
974 par->y_offset = yact_st*xvir + xact_st;
975 par->uv_offset = yact_st*2*xvir + xact_st*2;
976 cblen = crlen = (xvir*yvir);
982 smem_len = fix->line_length * yvir + cblen + crlen;
983 map_size = PAGE_ALIGN(smem_len);
985 if (info->screen_base) {
986 printk(">>>>>> win0fb unmap memory(%d)! \n", info->fix.smem_len);
987 dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
988 info->screen_base = 0;
990 fix->smem_start = y_addr;
991 fix->smem_len = smem_len;
992 fix->mmio_start = uv_addr;
994 par->addr_seted = ((-1==(int)y_addr)&&(-1==(int)uv_addr)) ? 0 : 1;
995 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);
997 // calculate the display phy address
998 y_addr = fix->smem_start + par->y_offset;
999 uv_addr = fix->mmio_start + par->uv_offset;
1001 fbprintk("y_addr 0x%08x = 0x%08x + %d\n", y_addr, (u32)fix->smem_start, par->y_offset);
1002 fbprintk("uv_addr 0x%08x = 0x%08x + %d\n", uv_addr, (u32)fix->mmio_start , par->uv_offset);
1004 ScaleYrgbX = CalScaleW0(xact, xsize);
1005 ScaleYrgbY = CalScaleW0(yact, ysize);
1007 switch (data_format)
1010 ScaleCbrX= CalScaleW0((xact/2), xsize);
1011 ScaleCbrY = CalScaleW0(yact, ysize);
1015 ScaleCbrX= CalScaleW0(xact/2, xsize);
1016 ScaleCbrY = CalScaleW0(yact/2, ysize);
1020 ScaleCbrX= CalScaleW0(xact, xsize);
1021 ScaleCbrY = CalScaleW0(yact, ysize);
1025 xpos += (screen->left_margin + screen->hsync_len);
1026 ypos += (screen->upper_margin + screen->vsync_len);
1028 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1029 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1031 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE | m_W0_FORMAT, v_W0_ENABLE(win0_en) | v_W0_FORMAT(format));
1033 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1034 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1035 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1036 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT11LO | m_BIT11HI, v_BIT11LO(xsize) | v_BIT11HI(ysize));
1037 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1038 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1043 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,
1044 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(1) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0));
1047 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,
1048 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) |
1049 v_W0_YRGB_M8_SWAP((var->rotate==0)) | v_W0_CBR_8_SWAP(0));
1052 LcdMskReg(inf, SWAP_CTRL, m_W0_YRGB_8_SWAP | m_W0_YRGB_16_SWAP | m_W0_YRGB_R_SHIFT_SWAP | m_W0_565_RB_SWAP | m_W0_YRGB_M8_SWAP | m_W0_CBR_8_SWAP,
1053 v_W0_YRGB_8_SWAP(0) | v_W0_YRGB_16_SWAP(0) | v_W0_YRGB_R_SHIFT_SWAP(0) | v_W0_565_RB_SWAP(0) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0) );
1056 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1061 static int win0fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1063 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1064 // struct fb_var_screeninfo *var0 = &info->var;
1065 struct fb_fix_screeninfo *fix0 = &info->fix;
1066 struct win0_par *par = info->par;
1067 u32 y_addr=0, uv_addr=0;
1069 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1073 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1074 uv_addr = fix0->mmio_start + par->uv_offset ;//uv_offset;
1076 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1077 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1078 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1080 // enable win0 after the win0 addr is seted
1082 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1088 int win0fb_open(struct fb_info *info, int user)
1090 struct win0_par *par = info->par;
1092 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1095 par->addr_seted = 0;
1098 printk(">>>>>> win0fb has opened! \n");
1106 int win0fb_release(struct fb_info *info, int user)
1108 struct win0_par *par = info->par;
1109 struct fb_var_screeninfo *var0 = &info->var;
1111 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1116 win0fb_blank(FB_BLANK_POWERDOWN, info);
1117 // wait for lcdc stop access memory
1121 if (info->screen_base) {
1122 printk(">>>>>> win0fb unmap memory(%d)! \n", info->fix.smem_len);
1123 dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
1124 info->screen_base = 0;
1125 info->fix.smem_start = 0;
1126 info->fix.smem_len = 0;
1129 // clean the var param
1130 memset(var0, 0, sizeof(struct fb_var_screeninfo));
1136 static int win0fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1138 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1139 struct win0_par *par = info->par;
1140 void __user *argp = (void __user *)arg;
1142 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1143 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
1149 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
1152 if(inf->win0fb->var.rotate == 270) {
1153 panel_size[0] = inf->cur_screen->y_res;
1154 panel_size[1] = inf->cur_screen->x_res;
1156 panel_size[0] = inf->cur_screen->x_res;
1157 panel_size[1] = inf->cur_screen->y_res;
1160 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
1164 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
1167 if (copy_from_user(yuv_phy, argp, 8))
1170 yuv_phy[0] += par->y_offset;
1171 yuv_phy[1] += par->uv_offset;
1173 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
1174 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
1175 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1176 // enable win0 after the win0 par is seted
1177 par->addr_seted = 1;
1178 if(par->par_seted) {
1179 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1185 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
1186 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
1195 static struct fb_ops win0fb_ops = {
1196 .owner = THIS_MODULE,
1197 .fb_open = win0fb_open,
1198 .fb_release = win0fb_release,
1199 .fb_check_var = win0fb_check_var,
1200 .fb_set_par = win0fb_set_par,
1201 .fb_blank = win0fb_blank,
1202 .fb_pan_display = win0fb_pan_display,
1203 .fb_ioctl = win0fb_ioctl,
1204 .fb_setcolreg = fb_setcolreg,
1205 .fb_fillrect = cfb_fillrect,
1206 .fb_copyarea = cfb_copyarea,
1207 .fb_imageblit = cfb_imageblit,
1210 static int win1fb_blank(int blank_mode, struct fb_info *info)
1212 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1214 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1220 case FB_BLANK_UNBLANK:
1221 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1224 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1227 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1233 static int win1fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1235 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1236 struct rk29fb_screen *screen = inf->cur_screen;
1237 u16 xpos = (var->nonstd>>8) & 0xfff;
1238 u16 ypos = (var->nonstd>>20) & 0xfff;
1239 u16 xlcd = screen->x_res;
1240 u16 ylcd = screen->y_res;
1241 u8 trspmode = (var->grayscale>>8) & 0xff;
1242 u8 trspval = (var->grayscale) & 0xff;
1244 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1248 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1249 0==var->xres || 0==var->yres || var->xres<16 ||
1250 trspmode>5 || trspval>16 ||
1251 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1253 printk(">>>>>> win1fb_check_var fail 1!!! \n");
1254 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1255 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1256 printk("%d>5 || %d>16 \n", trspmode,trspval);
1257 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1261 if( (var->xoffset+var->xres)>var->xres_virtual ||
1262 (var->yoffset+var->yres)>var->yres_virtual ||
1263 (xpos+var->xres)>xlcd || (ypos+var->yres)>ylcd )
1265 printk(">>>>>> win1fb_check_var fail 2!!! \n");
1266 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1267 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1268 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1272 switch(var->bits_per_pixel)
1275 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1276 var->xres = (var->xres + 0x1) & (~0x1);
1277 var->xoffset = (var->xoffset) & (~0x1);
1280 var->bits_per_pixel = 32;
1287 static int win1fb_set_par(struct fb_info *info)
1289 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1290 struct fb_var_screeninfo *var = &info->var;
1291 struct fb_fix_screeninfo *fix = &info->fix;
1292 struct rk29fb_screen *screen = inf->cur_screen;
1296 u32 offset=0, addr=0, map_size=0, smem_len=0;
1298 u16 xres_virtual = var->xres_virtual; //virtual screen size
1299 //u16 yres_virtual = var->yres_virtual;
1301 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1302 u16 ypos_virtual = var->yoffset;
1304 u16 xpos = 0; //visiable offset in panel
1306 u16 xsize = screen->x_res; //visiable size in panel
1307 u16 ysize = screen->y_res;
1308 u8 trspmode = TRSP_CLOSE;
1311 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1315 switch(var->bits_per_pixel)
1319 fix->line_length = 2 * xres_virtual;
1320 offset = (ypos_virtual*xres_virtual + xpos_virtual)*2;
1325 fix->line_length = 4 * xres_virtual;
1326 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1330 smem_len = fix->line_length * var->yres_virtual; //cursor buf also alloc here
1331 map_size = PAGE_ALIGN(smem_len);
1333 if (smem_len != fix->smem_len) // buffer need realloc
1335 fbprintk(">>>>>> win1 buffer size is change(%d->%d)! remap memory!\n",fix->smem_len, smem_len);
1336 fbprintk(">>>>>> smem_len %d = %d * %d \n", smem_len, fix->line_length, var->yres_virtual);
1337 fbprintk(">>>>>> map_size = %d\n", map_size);
1338 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1339 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1341 if (info->screen_base) {
1342 printk(">>>>>> win1fb unmap memory(%d)! \n", info->fix.smem_len);
1343 dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len), info->screen_base, info->fix.smem_start);
1344 info->screen_base = 0;
1345 fix->smem_start = 0;
1349 info->screen_base = dma_alloc_writecombine(NULL, map_size, &map_dma, GFP_KERNEL);
1350 if(!info->screen_base) {
1351 printk(">>>>>> win1fb dma_alloc_writecombine fail!\n");
1354 memset(info->screen_base, 0, map_size);
1355 fix->smem_start = map_dma;
1356 fix->smem_len = smem_len;
1357 fbprintk(">>>>>> alloc succ, mem=%08x, len=%d!\n", (u32)fix->smem_start, fix->smem_len);
1360 addr = fix->smem_start + offset;
1362 #if ANDROID_USE_THREE_BUFS
1363 if(0==new_frame_seted) {
1365 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1367 new_frame_seted = 0;
1370 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(format));
1372 xpos += (screen->left_margin + screen->hsync_len);
1373 ypos += (screen->upper_margin + screen->vsync_len);
1375 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1377 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1378 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT11LO|m_BIT11HI, v_BIT11LO(xsize) | v_BIT11HI(ysize));
1380 LcdMskReg(inf, WIN1_VIR, m_WORDLO | m_WORDHI , v_WORDLO(xres_virtual) | v_WORDHI(var->yres_virtual));
1382 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1383 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1385 // enable win1 color key and set the color to black(rgb=0)
1386 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1388 if(1==format) //rgb565
1390 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1391 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1395 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1396 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1398 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1401 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1406 static int win1fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1408 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1409 struct fb_var_screeninfo *var1 = &info->var;
1410 struct fb_fix_screeninfo *fix1 = &info->fix;
1412 u32 offset = 0, addr = 0;
1414 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1418 switch(var1->bits_per_pixel)
1421 var->xoffset = (var->xoffset) & (~0x1);
1422 offset = (var->yoffset*var1->xres_virtual + var->xoffset)*2;
1425 offset = (var->yoffset*var1->xres_virtual + var->xoffset)*4;
1431 addr = fix1->smem_start + offset;
1433 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1435 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1436 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1440 #if !ANDROID_USE_THREE_BUFS
1441 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1442 if(SCREEN_MCU == inf->cur_screen->type) {
1443 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1447 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1452 for(i=0;i<=(0xc0/4);i+=4)
1454 fbprintk("0x%02X: 0x%08X 0x%08X 0x%08X 0x%08X \n", i*4,
1455 *((u32*)inf->reg_vir_base+i),
1456 *((u32*)inf->reg_vir_base+i+1),
1457 *((u32*)inf->reg_vir_base+i+2),
1458 *((u32*)inf->reg_vir_base+i+3));
1466 static int win1fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1468 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1469 struct rk29fb_info *mach_info = info->device->platform_data;
1470 unsigned display_on;
1473 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1479 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1482 inf->mcu_usetimer = 0;
1486 case FB0_IOCTL_SET_PANEL:
1487 if(arg>7) return -1;
1489 /* Black out, because some display device need clock to standby */
1490 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
1491 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1492 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1493 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1494 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1497 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
1498 // operate the display_on pin to power down the lcd
1499 if(SCREEN_RGB==inf->cur_screen->type || SCREEN_MCU==inf->cur_screen->type)
1501 if(mach_info && mach_info->disp_on_pin)
1503 display_on = mach_info->disp_on_pin;
1504 display_on_pol = mach_info->disp_on_value;
1505 gpio_direction_output(display_on, 0);
1506 gpio_set_value(display_on, !display_on_pol);
1511 /* Load the new device's param */
1514 case 0: inf->cur_screen = &inf->lcd_info; break; //lcd
1515 case 1: inf->cur_screen = &inf->tv_info[0]; break; //tv ntsc cvbs
1516 case 2: inf->cur_screen = &inf->tv_info[1]; break; //tv pal cvbs
1517 case 3: inf->cur_screen = &inf->tv_info[2]; break; //tv 480 ypbpr
1518 case 4: inf->cur_screen = &inf->tv_info[3]; break; //tv 576 ypbpr
1519 case 5: inf->cur_screen = &inf->tv_info[4]; break; //tv 720 ypbpr
1520 case 6: inf->cur_screen = &inf->hdmi_info[0]; break; //hdmi 576
1521 case 7: inf->cur_screen = &inf->hdmi_info[1]; break; //hdmi 720
1524 load_screen(info, 1);
1534 static struct fb_ops win1fb_ops = {
1535 .owner = THIS_MODULE,
1536 .fb_check_var = win1fb_check_var,
1537 .fb_set_par = win1fb_set_par,
1538 .fb_blank = win1fb_blank,
1539 .fb_pan_display = win1fb_pan_display,
1540 .fb_ioctl = win1fb_ioctl,
1541 .fb_setcolreg = fb_setcolreg,
1542 .fb_fillrect = cfb_fillrect,
1543 .fb_copyarea = cfb_copyarea,
1544 .fb_imageblit = cfb_imageblit,
1545 //.fb_cursor = rk29_set_cursor,
1549 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
1551 struct platform_device *pdev = (struct platform_device*)dev_id;
1552 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
1556 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1558 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
1560 if(SCREEN_MCU == inf->cur_screen->type)
1562 inf->mcu_isrcnt = !inf->mcu_isrcnt;
1568 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLD_STATUS) && (inf->mcu_fmksync == 0))
1570 inf->mcu_fmksync = 1;
1571 if(inf->cur_screen->refresh)
1572 inf->cur_screen->refresh(REFRESH_END);
1573 inf->mcu_fmksync = 0;
1582 if(inf->mcu_needflush) {
1583 if(inf->cur_screen->refresh)
1584 inf->cur_screen->refresh(REFRESH_PRE);
1585 inf->mcu_needflush = 0;
1586 inf->mcu_isrcnt = 0;
1587 LcdSetRegBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
1589 if(inf->cur_screen->refresh)
1590 inf->cur_screen->refresh(REFRESH_END);
1595 #if ANDROID_USE_THREE_BUFS
1596 new_frame_seted = 1;
1600 wake_up_interruptible(&wq);
1605 #ifdef CONFIG_HAS_EARLYSUSPEND
1607 struct suspend_info {
1608 struct early_suspend early_suspend;
1609 struct rk29fb_inf *inf;
1612 void suspend(struct early_suspend *h)
1614 struct suspend_info *info = container_of(h, struct suspend_info,
1617 struct rk29fb_inf *inf = info->inf;
1619 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1622 printk("inf==0, rk29fb_suspend fail! \n");
1626 set_lcd_pin(g_pdev, 0);
1628 if(inf->cur_screen->standby)
1630 fbprintk(">>>>>> power down the screen! \n");
1631 inf->cur_screen->standby(1);
1634 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
1635 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
1636 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1638 if(!inf->in_suspend)
1640 fbprintk(">>>>>> diable the lcdc clk! \n");
1643 clk_disable(inf->dclk);
1646 clk_disable(inf->clk);
1649 inf->in_suspend = 1;
1654 void resume(struct early_suspend *h)
1656 struct suspend_info *info = container_of(h, struct suspend_info,
1659 struct rk29fb_inf *inf = info->inf;
1661 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1663 printk("inf==0, rk29fb_resume fail! \n");
1669 inf->in_suspend = 0;
1670 fbprintk(">>>>>> enable the lcdc clk! \n");
1672 clk_enable(inf->dclk);
1675 clk_enable(inf->clk);
1679 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
1680 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
1681 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1683 if(inf->cur_screen->standby)
1685 fbprintk(">>>>>> power on the screen! \n");
1686 inf->cur_screen->standby(0);
1689 set_lcd_pin(g_pdev, 1);
1690 memcpy(inf->preg, &inf->regbak, 0xa4); //resume reg
1693 struct suspend_info suspend_info = {
1694 .early_suspend.suspend = suspend,
1695 .early_suspend.resume = resume,
1696 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
1700 static int __init rk29fb_probe (struct platform_device *pdev)
1702 struct rk29fb_inf *inf = NULL;
1703 struct resource *res = NULL;
1704 struct resource *mem = NULL;
1705 struct rk29fb_info *mach_info = NULL;
1706 struct rk29fb_screen *screen = NULL;
1710 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1712 /* Malloc rk29fb_inf and set it to pdev for drvdata */
1713 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
1714 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
1717 dev_err(&pdev->dev, ">> inf kmalloc fail!");
1719 goto release_drvdata;
1721 memset(inf, 0, sizeof(struct rk29fb_inf));
1722 platform_set_drvdata(pdev, inf);
1724 mach_info = pdev->dev.platform_data;
1725 /* Fill screen info and set current screen */
1726 fbprintk(">> Fill screen info and set current screen \n");
1727 set_lcd_info(&inf->lcd_info, mach_info->lcd_info);
1728 set_tv_info(&inf->tv_info[0]);
1729 set_hdmi_info(&inf->hdmi_info[0]);
1730 inf->cur_screen = &inf->lcd_info;
1731 screen = inf->cur_screen;
1732 if(SCREEN_NULL==screen->type)
1734 dev_err(&pdev->dev, ">> Please select a display device! \n");
1736 goto release_drvdata;
1739 /* get virtual basic address of lcdc register */
1740 fbprintk(">> get virtual basic address of lcdc register \n");
1741 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1744 dev_err(&pdev->dev, "failed to get memory registers\n");
1746 goto release_drvdata;
1748 inf->reg_phy_base = res->start;
1749 inf->len = (res->end - res->start) + 1;
1750 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
1753 dev_err(&pdev->dev, "failed to get memory region\n");
1755 goto release_drvdata;
1757 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
1758 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
1759 if (inf->reg_vir_base == NULL)
1761 dev_err(&pdev->dev, "ioremap() of registers failed\n");
1763 goto release_drvdata;
1765 inf->preg = (LCDC_REG*)inf->reg_vir_base;
1767 /* Prepare win1 info */
1768 fbprintk(">> Prepare win1 info \n");
1769 inf->win1fb = framebuffer_alloc(sizeof(struct win1_par), &pdev->dev);
1772 dev_err(&pdev->dev, ">> win1fb framebuffer_alloc fail!");
1775 goto release_win1fb;
1778 strcpy(inf->win1fb->fix.id, "win1fb");
1779 inf->win1fb->fix.type = FB_TYPE_PACKED_PIXELS;
1780 inf->win1fb->fix.type_aux = 0;
1781 inf->win1fb->fix.xpanstep = 1;
1782 inf->win1fb->fix.ypanstep = 1;
1783 inf->win1fb->fix.ywrapstep = 0;
1784 inf->win1fb->fix.accel = FB_ACCEL_NONE;
1785 inf->win1fb->fix.visual = FB_VISUAL_TRUECOLOR;
1786 inf->win1fb->fix.smem_len = 0;
1787 inf->win1fb->fix.line_length = 0;
1788 inf->win1fb->fix.smem_start = 0;
1790 inf->win1fb->var.xres = screen->x_res;
1791 inf->win1fb->var.yres = screen->y_res;
1792 inf->win1fb->var.bits_per_pixel = 16;
1793 inf->win1fb->var.xres_virtual = screen->x_res;
1794 inf->win1fb->var.yres_virtual = screen->y_res;
1795 inf->win1fb->var.width = screen->width;
1796 inf->win1fb->var.height = screen->height;
1797 inf->win1fb->var.pixclock = screen->pixclock;
1798 inf->win1fb->var.left_margin = screen->left_margin;
1799 inf->win1fb->var.right_margin = screen->right_margin;
1800 inf->win1fb->var.upper_margin = screen->upper_margin;
1801 inf->win1fb->var.lower_margin = screen->lower_margin;
1802 inf->win1fb->var.vsync_len = screen->vsync_len;
1803 inf->win1fb->var.hsync_len = screen->hsync_len;
1804 inf->win1fb->var.red = def_rgb_16.red;
1805 inf->win1fb->var.green = def_rgb_16.green;
1806 inf->win1fb->var.blue = def_rgb_16.blue;
1807 inf->win1fb->var.transp = def_rgb_16.transp;
1809 inf->win1fb->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
1810 inf->win1fb->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
1811 inf->win1fb->var.activate = FB_ACTIVATE_NOW;
1812 inf->win1fb->var.accel_flags = 0;
1813 inf->win1fb->var.vmode = FB_VMODE_NONINTERLACED;
1815 inf->win1fb->fbops = &win1fb_ops;
1816 inf->win1fb->flags = FBINFO_FLAG_DEFAULT;
1817 inf->win1fb->pseudo_palette = ((struct win1_par*)inf->win1fb->par)->pseudo_pal;
1818 inf->win1fb->screen_base = 0;
1820 memset(inf->win1fb->par, 0, sizeof(struct win1_par));
1821 ret = fb_alloc_cmap(&inf->win1fb->cmap, 256, 0);
1825 /* Prepare win0 info */
1826 fbprintk(">> Prepare win0 info \n");
1827 inf->win0fb = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
1830 dev_err(&pdev->dev, ">> win0fb framebuffer_alloc fail!");
1833 goto release_win0fb;
1836 strcpy(inf->win0fb->fix.id, "win0fb");
1837 inf->win0fb->fix.type = FB_TYPE_PACKED_PIXELS;
1838 inf->win0fb->fix.type_aux = 0;
1839 inf->win0fb->fix.xpanstep = 1;
1840 inf->win0fb->fix.ypanstep = 1;
1841 inf->win0fb->fix.ywrapstep = 0;
1842 inf->win0fb->fix.accel = FB_ACCEL_NONE;
1843 inf->win0fb->fix.visual = FB_VISUAL_TRUECOLOR;
1844 inf->win0fb->fix.smem_len = 0;
1845 inf->win0fb->fix.line_length = 0;
1846 inf->win0fb->fix.smem_start = 0;
1848 inf->win0fb->var.xres = screen->x_res;
1849 inf->win0fb->var.yres = screen->y_res;
1850 inf->win0fb->var.bits_per_pixel = 16;
1851 inf->win0fb->var.xres_virtual = screen->x_res;
1852 inf->win0fb->var.yres_virtual = screen->y_res;
1853 inf->win0fb->var.width = screen->width;
1854 inf->win0fb->var.height = screen->height;
1855 inf->win0fb->var.pixclock = screen->pixclock;
1856 inf->win0fb->var.left_margin = screen->left_margin;
1857 inf->win0fb->var.right_margin = screen->right_margin;
1858 inf->win0fb->var.upper_margin = screen->upper_margin;
1859 inf->win0fb->var.lower_margin = screen->lower_margin;
1860 inf->win0fb->var.vsync_len = screen->vsync_len;
1861 inf->win0fb->var.hsync_len = screen->hsync_len;
1862 inf->win0fb->var.red = def_rgb_16.red;
1863 inf->win0fb->var.green = def_rgb_16.green;
1864 inf->win0fb->var.blue = def_rgb_16.blue;
1865 inf->win0fb->var.transp = def_rgb_16.transp;
1867 inf->win0fb->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
1868 inf->win0fb->var.grayscale = ((inf->win0fb->var.yres<<20)&0xfff00000) + ((inf->win0fb->var.xres<<8)&0xfff00);//win0 xsize & ysize
1869 inf->win0fb->var.activate = FB_ACTIVATE_NOW;
1870 inf->win0fb->var.accel_flags = 0;
1871 inf->win0fb->var.vmode = FB_VMODE_NONINTERLACED;
1873 inf->win0fb->fbops = &win0fb_ops;
1874 inf->win0fb->flags = FBINFO_FLAG_DEFAULT;
1875 inf->win0fb->pseudo_palette = ((struct win0_par*)inf->win0fb->par)->pseudo_pal;
1876 inf->win0fb->screen_base = 0;
1878 memset(inf->win0fb->par, 0, sizeof(struct win0_par));
1880 /* Init all lcdc and lcd before register_framebuffer. */
1881 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
1882 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
1883 init_lcdc(inf->win1fb);
1885 #ifdef CONFIG_CPU_FREQ
1886 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
1887 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
1889 fbprintk("got clock\n");
1893 struct rk29_fb_setting_info fb_setting;
1894 if( OUT_P888==inf->lcd_info.face ||
1895 OUT_P888==inf->tv_info[0].face ||
1896 OUT_P888==inf->hdmi_info[0].face ) // set lcdc iomux
1898 fb_setting.data_num = 24;
1900 else if(OUT_P666 == inf->lcd_info.face )
1902 fb_setting.data_num = 18;
1906 fb_setting.data_num = 16;
1908 fb_setting.den_en = 1;
1909 fb_setting.vsync_en = 1;
1910 fb_setting.disp_on_en = 1;
1911 fb_setting.standby_en = 1;
1912 if( inf->lcd_info.mcu_usefmk )
1913 fb_setting.mcu_fmk_en =1;
1914 mach_info->io_init(&fb_setting);
1917 set_lcd_pin(pdev, 1);
1920 inf->mcu_usetimer = 1;
1921 inf->mcu_fmksync = 0;
1922 load_screen(inf->win1fb, 1);
1924 /* Register framebuffer(win1fb & win0fb) */
1925 fbprintk(">> Register framebuffer(win1fb) \n");
1926 ret = register_framebuffer(inf->win1fb);
1929 printk(">> win1fb register_framebuffer fail!\n");
1931 goto release_win0fb;
1933 fbprintk(">> Register framebuffer(win0fb) \n");
1935 ret = register_framebuffer(inf->win0fb);
1938 printk(">> win0fb register_framebuffer fail!\n");
1940 goto unregister_win1fb;
1943 #ifdef CONFIG_HAS_EARLYSUSPEND
1944 suspend_info.inf = inf;
1945 register_early_suspend(&suspend_info.early_suspend);
1948 /* get and request irq */
1949 fbprintk(">> get and request irq \n");
1950 irq = platform_get_irq(pdev, 0);
1952 dev_err(&pdev->dev, "no irq for device\n");
1954 goto unregister_win1fb;
1956 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
1958 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
1963 if( inf->lcd_info.mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
1965 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
1968 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
1974 printk(" %s ok\n", __FUNCTION__);
1979 free_irq(irq, pdev);
1981 unregister_framebuffer(inf->win1fb);
1984 framebuffer_release(inf->win0fb);
1987 if(&inf->win1fb->cmap)
1988 fb_dealloc_cmap(&inf->win1fb->cmap);
1991 framebuffer_release(inf->win1fb);
1994 if(inf && inf->reg_vir_base)
1995 iounmap(inf->reg_vir_base);
1997 release_mem_region(inf->reg_phy_base, inf->len);
2000 platform_set_drvdata(pdev, NULL);
2004 static int rk29fb_remove(struct platform_device *pdev)
2006 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2007 struct fb_info *info = NULL;
2009 struct rk29fb_info *mach_info = NULL;
2012 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2015 printk("inf==0, rk29_fb_remove fail! \n");
2019 irq = platform_get_irq(pdev, 0);
2022 free_irq(irq, pdev);
2025 mach_info = pdev->dev.platform_data;
2026 if(mach_info->mcu_fmk_pin)
2028 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2031 set_lcd_pin(pdev, 0);
2035 win0fb_blank(FB_BLANK_POWERDOWN, inf->win0fb);
2037 win1fb_blank(FB_BLANK_POWERDOWN, inf->win1fb);
2040 //rk29fb_suspend(pdev, msg);
2041 // unmap memory and release framebuffer
2044 if (info->screen_base) {
2045 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2046 info->screen_base = 0;
2047 info->fix.smem_start = 0;
2048 info->fix.smem_len = 0;
2050 unregister_framebuffer(inf->win0fb);
2051 framebuffer_release(inf->win0fb);
2056 if (info->screen_base) {
2057 dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2058 info->screen_base = 0;
2059 info->fix.smem_start = 0;
2060 info->fix.smem_len = 0;
2062 unregister_framebuffer(inf->win1fb);
2063 framebuffer_release(inf->win1fb);
2067 #ifdef CONFIG_CPU_FREQ
2068 cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2073 clk_disable(inf->clk);
2079 clk_disable(inf->dclk);
2085 platform_set_drvdata(pdev, NULL);
2090 static void rk29fb_shutdown(struct platform_device *pdev)
2092 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2094 //printk("----------------------------rk29fb_shutdown----------------------------\n");
2095 set_lcd_pin(pdev, 0);
2098 clk_disable(inf->dclk);
2102 clk_disable(inf->clk);
2106 static struct platform_driver rk29fb_driver = {
2107 .probe = rk29fb_probe,
2108 .remove = rk29fb_remove,
2111 .owner = THIS_MODULE,
2113 .shutdown = rk29fb_shutdown,
2116 static int __init rk29fb_init(void)
2118 return platform_driver_register(&rk29fb_driver);
2121 static void __exit rk29fb_exit(void)
2123 platform_driver_unregister(&rk29fb_driver);
2126 //subsys_initcall(rk29fb_init);
2128 module_init(rk29fb_init);
2129 module_exit(rk29fb_exit);
2132 MODULE_AUTHOR(" zyw@rock-chips.com");
2133 MODULE_DESCRIPTION("Driver for rk29 fb device");
2134 MODULE_LICENSE("GPL");