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
863 var->xres_virtual = (var->xres_virtual + 0x7) & (~0x7);
864 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
865 var->xres = (var->xres + 0x7) & (~0x7);
866 var->yres = (var->yres + 0x1) & (~0x1);
867 var->xoffset = (var->xoffset) & (~0x7);
868 var->yoffset = (var->yoffset) & (~0x1);
869 var->nonstd &= ~0xc0; //not support I2P in this format
872 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
873 var->xres = (var->xres + 0x3) & (~0x3);
874 var->xoffset = (var->xoffset) & (~0x3);
875 var->nonstd &= ~0xc0; //not support I2P in this format
878 printk(">>>>>> win0fb var->nonstd=%d is invalid! \n", var->nonstd);
882 if(var->rotate == 270)
890 ScaleYRGBY = CalScaleW0(yres, ysize);
892 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
894 return -EINVAL; // multiple of scale down or scale up can't exceed 8
900 static int win0fb_set_par(struct fb_info *info)
902 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
903 struct rk29fb_screen *screen = inf->cur_screen;
904 struct fb_var_screeninfo *var = &info->var;
905 struct fb_fix_screeninfo *fix = &info->fix;
906 struct win0_par *par = info->par;
909 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
911 u32 xact = var->xres; /* visible resolution */
912 u32 yact = var->yres;
913 u32 xvir = var->xres_virtual; /* virtual resolution */
914 u32 yvir = var->yres_virtual;
915 u32 xact_st = var->xoffset; /* offset from virtual to visible */
916 u32 yact_st = var->yoffset; /* resolution */
918 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
919 u16 ypos = (var->nonstd>>20) & 0xfff;
920 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
921 u16 ysize = (var->grayscale>>20) & 0xfff;
923 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
924 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
926 u8 data_format = var->nonstd&0x0f;
927 u32 win0_en = var->reserved[2];
928 u32 y_addr = var->reserved[3]; //user alloc buf addr y
929 u32 uv_addr = var->reserved[4];
931 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
935 /* calculate y_offset,uv_offset,line_length,cblen and crlen */
939 switch(var->bits_per_pixel)
943 fix->line_length = 2 * xvir;
944 par->y_offset = (yact_st*xvir + xact_st)*2;
948 fix->line_length = 4 * xvir;
949 par->y_offset = (yact_st*xvir + xact_st)*4;
957 fix->line_length = xvir;
958 cblen = crlen = (xvir*yvir)/2;
959 par->y_offset = yact_st*xvir + xact_st;
960 par->uv_offset = yact_st*xvir + xact_st;
964 fix->line_length = xvir;
965 cblen = crlen = (xvir*yvir)/4;
967 par->y_offset = yact_st*xvir + xact_st;
968 par->uv_offset = (yact_st/2)*xvir + xact_st;
973 fix->line_length = xvir;
974 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
975 par->uv_offset = (yact_st/2)*xvir + xact_st;
976 cblen = crlen = (xvir*yvir)/4;
980 fix->line_length = xvir;
981 par->y_offset = (yact_st/2)*3*xvir + (xact_st)*3;
982 cblen = crlen = (xvir*yvir)/4;
986 fix->line_length = xvir;
987 par->y_offset = yact_st*xvir + xact_st;
988 par->uv_offset = yact_st*2*xvir + xact_st*2;
989 cblen = crlen = (xvir*yvir);
995 smem_len = fix->line_length * yvir + cblen + crlen;
996 map_size = PAGE_ALIGN(smem_len);
998 if (info->screen_base) {
999 printk(">>>>>> win0fb unmap memory(%d)! \n", info->fix.smem_len);
1000 dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
1001 info->screen_base = 0;
1003 fix->smem_start = y_addr;
1004 fix->smem_len = smem_len;
1005 fix->mmio_start = uv_addr;
1007 par->addr_seted = ((-1==(int)y_addr)&&(-1==(int)uv_addr)) ? 0 : 1;
1008 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);
1010 // calculate the display phy address
1011 y_addr = fix->smem_start + par->y_offset;
1012 uv_addr = fix->mmio_start + par->uv_offset;
1014 fbprintk("y_addr 0x%08x = 0x%08x + %d\n", y_addr, (u32)fix->smem_start, par->y_offset);
1015 fbprintk("uv_addr 0x%08x = 0x%08x + %d\n", uv_addr, (u32)fix->mmio_start , par->uv_offset);
1017 ScaleYrgbX = CalScaleW0(xact, xsize);
1018 ScaleYrgbY = CalScaleW0(yact, ysize);
1020 switch (data_format)
1023 ScaleCbrX= CalScaleW0((xact/2), xsize);
1024 ScaleCbrY = CalScaleW0(yact, ysize);
1029 ScaleCbrX= CalScaleW0(xact/2, xsize);
1030 ScaleCbrY = CalScaleW0(yact/2, ysize);
1033 ScaleCbrX= CalScaleW0(xact, xsize);
1034 ScaleCbrY = CalScaleW0(yact, ysize);
1038 xpos += (screen->left_margin + screen->hsync_len);
1039 ypos += (screen->upper_margin + screen->vsync_len);
1041 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1042 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1044 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE | m_W0_FORMAT, v_W0_ENABLE(win0_en) | v_W0_FORMAT(format));
1046 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
1047 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
1048 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1049 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT11LO | m_BIT11HI, v_BIT11LO(xsize) | v_BIT11HI(ysize));
1050 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
1051 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
1056 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,
1057 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));
1060 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,
1061 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) |
1062 v_W0_YRGB_M8_SWAP((var->rotate==0)) | v_W0_CBR_8_SWAP(0));
1065 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,
1066 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) );
1069 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1074 static int win0fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1076 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1077 // struct fb_var_screeninfo *var0 = &info->var;
1078 struct fb_fix_screeninfo *fix0 = &info->fix;
1079 struct win0_par *par = info->par;
1080 u32 y_addr=0, uv_addr=0;
1082 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1086 y_addr = fix0->smem_start + par->y_offset;//y_offset;
1087 uv_addr = fix0->mmio_start + par->uv_offset ;//uv_offset;
1089 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
1090 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
1091 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1093 // enable win0 after the win0 addr is seted
1095 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
1101 int win0fb_open(struct fb_info *info, int user)
1103 struct win0_par *par = info->par;
1105 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1108 par->addr_seted = 0;
1111 printk(">>>>>> win0fb has opened! \n");
1119 int win0fb_release(struct fb_info *info, int user)
1121 struct win0_par *par = info->par;
1122 struct fb_var_screeninfo *var0 = &info->var;
1124 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1129 win0fb_blank(FB_BLANK_POWERDOWN, info);
1130 // wait for lcdc stop access memory
1134 if (info->screen_base) {
1135 printk(">>>>>> win0fb unmap memory(%d)! \n", info->fix.smem_len);
1136 dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
1137 info->screen_base = 0;
1138 info->fix.smem_start = 0;
1139 info->fix.smem_len = 0;
1142 // clean the var param
1143 memset(var0, 0, sizeof(struct fb_var_screeninfo));
1149 static int win0fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1151 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1152 struct win0_par *par = info->par;
1153 void __user *argp = (void __user *)arg;
1155 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1156 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
1162 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
1165 if(inf->win0fb->var.rotate == 270) {
1166 panel_size[0] = inf->cur_screen->y_res;
1167 panel_size[1] = inf->cur_screen->x_res;
1169 panel_size[0] = inf->cur_screen->x_res;
1170 panel_size[1] = inf->cur_screen->y_res;
1173 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
1177 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
1180 if (copy_from_user(yuv_phy, argp, 8))
1183 yuv_phy[0] += par->y_offset;
1184 yuv_phy[1] += par->uv_offset;
1186 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
1187 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
1188 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1189 // enable win0 after the win0 par is seted
1190 par->addr_seted = 1;
1191 if(par->par_seted) {
1192 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1198 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
1199 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
1208 static struct fb_ops win0fb_ops = {
1209 .owner = THIS_MODULE,
1210 .fb_open = win0fb_open,
1211 .fb_release = win0fb_release,
1212 .fb_check_var = win0fb_check_var,
1213 .fb_set_par = win0fb_set_par,
1214 .fb_blank = win0fb_blank,
1215 .fb_pan_display = win0fb_pan_display,
1216 .fb_ioctl = win0fb_ioctl,
1217 .fb_setcolreg = fb_setcolreg,
1218 .fb_fillrect = cfb_fillrect,
1219 .fb_copyarea = cfb_copyarea,
1220 .fb_imageblit = cfb_imageblit,
1223 static int win1fb_blank(int blank_mode, struct fb_info *info)
1225 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1227 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1233 case FB_BLANK_UNBLANK:
1234 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
1237 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1240 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1246 static int win1fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1248 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1249 struct rk29fb_screen *screen = inf->cur_screen;
1250 u16 xpos = (var->nonstd>>8) & 0xfff;
1251 u16 ypos = (var->nonstd>>20) & 0xfff;
1252 u16 xlcd = screen->x_res;
1253 u16 ylcd = screen->y_res;
1254 u8 trspmode = (var->grayscale>>8) & 0xff;
1255 u8 trspval = (var->grayscale) & 0xff;
1257 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1261 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1262 0==var->xres || 0==var->yres || var->xres<16 ||
1263 trspmode>5 || trspval>16 ||
1264 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1266 printk(">>>>>> win1fb_check_var fail 1!!! \n");
1267 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1268 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1269 printk("%d>5 || %d>16 \n", trspmode,trspval);
1270 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1274 if( (var->xoffset+var->xres)>var->xres_virtual ||
1275 (var->yoffset+var->yres)>var->yres_virtual ||
1276 (xpos+var->xres)>xlcd || (ypos+var->yres)>ylcd )
1278 printk(">>>>>> win1fb_check_var fail 2!!! \n");
1279 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1280 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1281 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1285 switch(var->bits_per_pixel)
1288 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1289 var->xres = (var->xres + 0x1) & (~0x1);
1290 var->xoffset = (var->xoffset) & (~0x1);
1293 var->bits_per_pixel = 32;
1300 static int win1fb_set_par(struct fb_info *info)
1302 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1303 struct fb_var_screeninfo *var = &info->var;
1304 struct fb_fix_screeninfo *fix = &info->fix;
1305 struct rk29fb_screen *screen = inf->cur_screen;
1309 u32 offset=0, addr=0, map_size=0, smem_len=0;
1311 u16 xres_virtual = var->xres_virtual; //virtual screen size
1312 //u16 yres_virtual = var->yres_virtual;
1314 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1315 u16 ypos_virtual = var->yoffset;
1317 u16 xpos = 0; //visiable offset in panel
1319 u16 xsize = screen->x_res; //visiable size in panel
1320 u16 ysize = screen->y_res;
1321 u8 trspmode = TRSP_CLOSE;
1324 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1328 switch(var->bits_per_pixel)
1332 fix->line_length = 2 * xres_virtual;
1333 offset = (ypos_virtual*xres_virtual + xpos_virtual)*2;
1338 fix->line_length = 4 * xres_virtual;
1339 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1343 smem_len = fix->line_length * var->yres_virtual; //cursor buf also alloc here
1344 map_size = PAGE_ALIGN(smem_len);
1346 if (smem_len != fix->smem_len) // buffer need realloc
1348 fbprintk(">>>>>> win1 buffer size is change(%d->%d)! remap memory!\n",fix->smem_len, smem_len);
1349 fbprintk(">>>>>> smem_len %d = %d * %d \n", smem_len, fix->line_length, var->yres_virtual);
1350 fbprintk(">>>>>> map_size = %d\n", map_size);
1351 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1352 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1354 if (info->screen_base) {
1355 printk(">>>>>> win1fb unmap memory(%d)! \n", info->fix.smem_len);
1356 dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len), info->screen_base, info->fix.smem_start);
1357 info->screen_base = 0;
1358 fix->smem_start = 0;
1362 info->screen_base = dma_alloc_writecombine(NULL, map_size, &map_dma, GFP_KERNEL);
1363 if(!info->screen_base) {
1364 printk(">>>>>> win1fb dma_alloc_writecombine fail!\n");
1367 memset(info->screen_base, 0, map_size);
1368 fix->smem_start = map_dma;
1369 fix->smem_len = smem_len;
1370 fbprintk(">>>>>> alloc succ, mem=%08x, len=%d!\n", (u32)fix->smem_start, fix->smem_len);
1373 addr = fix->smem_start + offset;
1375 #if ANDROID_USE_THREE_BUFS
1376 if(0==new_frame_seted) {
1378 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1380 new_frame_seted = 0;
1383 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(format));
1385 xpos += (screen->left_margin + screen->hsync_len);
1386 ypos += (screen->upper_margin + screen->vsync_len);
1388 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1390 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1391 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT11LO|m_BIT11HI, v_BIT11LO(xsize) | v_BIT11HI(ysize));
1393 LcdMskReg(inf, WIN1_VIR, m_WORDLO | m_WORDHI , v_WORDLO(xres_virtual) | v_WORDHI(var->yres_virtual));
1395 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1396 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1398 // enable win1 color key and set the color to black(rgb=0)
1399 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1401 if(1==format) //rgb565
1403 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1404 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1408 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1409 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1411 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1414 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1419 static int win1fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1421 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1422 struct fb_var_screeninfo *var1 = &info->var;
1423 struct fb_fix_screeninfo *fix1 = &info->fix;
1425 u32 offset = 0, addr = 0;
1427 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1431 switch(var1->bits_per_pixel)
1434 var->xoffset = (var->xoffset) & (~0x1);
1435 offset = (var->yoffset*var1->xres_virtual + var->xoffset)*2;
1438 offset = (var->yoffset*var1->xres_virtual + var->xoffset)*4;
1444 addr = fix1->smem_start + offset;
1446 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1448 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1449 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1453 #if !ANDROID_USE_THREE_BUFS
1454 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1455 if(SCREEN_MCU == inf->cur_screen->type) {
1456 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1460 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1465 for(i=0;i<=(0xc0/4);i+=4)
1467 fbprintk("0x%02X: 0x%08X 0x%08X 0x%08X 0x%08X \n", i*4,
1468 *((u32*)inf->reg_vir_base+i),
1469 *((u32*)inf->reg_vir_base+i+1),
1470 *((u32*)inf->reg_vir_base+i+2),
1471 *((u32*)inf->reg_vir_base+i+3));
1479 static int win1fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1481 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1482 struct rk29fb_info *mach_info = info->device->platform_data;
1483 unsigned display_on;
1486 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1492 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1495 inf->mcu_usetimer = 0;
1499 case FB0_IOCTL_SET_PANEL:
1500 if(arg>7) return -1;
1502 /* Black out, because some display device need clock to standby */
1503 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
1504 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1505 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1506 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1507 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1510 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
1511 // operate the display_on pin to power down the lcd
1512 if(SCREEN_RGB==inf->cur_screen->type || SCREEN_MCU==inf->cur_screen->type)
1514 if(mach_info && mach_info->disp_on_pin)
1516 display_on = mach_info->disp_on_pin;
1517 display_on_pol = mach_info->disp_on_value;
1518 gpio_direction_output(display_on, 0);
1519 gpio_set_value(display_on, !display_on_pol);
1524 /* Load the new device's param */
1527 case 0: inf->cur_screen = &inf->lcd_info; break; //lcd
1528 case 1: inf->cur_screen = &inf->tv_info[0]; break; //tv ntsc cvbs
1529 case 2: inf->cur_screen = &inf->tv_info[1]; break; //tv pal cvbs
1530 case 3: inf->cur_screen = &inf->tv_info[2]; break; //tv 480 ypbpr
1531 case 4: inf->cur_screen = &inf->tv_info[3]; break; //tv 576 ypbpr
1532 case 5: inf->cur_screen = &inf->tv_info[4]; break; //tv 720 ypbpr
1533 case 6: inf->cur_screen = &inf->hdmi_info[0]; break; //hdmi 576
1534 case 7: inf->cur_screen = &inf->hdmi_info[1]; break; //hdmi 720
1537 load_screen(info, 1);
1547 static struct fb_ops win1fb_ops = {
1548 .owner = THIS_MODULE,
1549 .fb_check_var = win1fb_check_var,
1550 .fb_set_par = win1fb_set_par,
1551 .fb_blank = win1fb_blank,
1552 .fb_pan_display = win1fb_pan_display,
1553 .fb_ioctl = win1fb_ioctl,
1554 .fb_setcolreg = fb_setcolreg,
1555 .fb_fillrect = cfb_fillrect,
1556 .fb_copyarea = cfb_copyarea,
1557 .fb_imageblit = cfb_imageblit,
1558 //.fb_cursor = rk29_set_cursor,
1562 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
1564 struct platform_device *pdev = (struct platform_device*)dev_id;
1565 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
1569 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1571 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
1573 if(SCREEN_MCU == inf->cur_screen->type)
1575 inf->mcu_isrcnt = !inf->mcu_isrcnt;
1581 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLD_STATUS) && (inf->mcu_fmksync == 0))
1583 inf->mcu_fmksync = 1;
1584 if(inf->cur_screen->refresh)
1585 inf->cur_screen->refresh(REFRESH_END);
1586 inf->mcu_fmksync = 0;
1595 if(inf->mcu_needflush) {
1596 if(inf->cur_screen->refresh)
1597 inf->cur_screen->refresh(REFRESH_PRE);
1598 inf->mcu_needflush = 0;
1599 inf->mcu_isrcnt = 0;
1600 LcdSetRegBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
1602 if(inf->cur_screen->refresh)
1603 inf->cur_screen->refresh(REFRESH_END);
1608 #if ANDROID_USE_THREE_BUFS
1609 new_frame_seted = 1;
1613 wake_up_interruptible(&wq);
1618 #ifdef CONFIG_HAS_EARLYSUSPEND
1620 struct suspend_info {
1621 struct early_suspend early_suspend;
1622 struct rk29fb_inf *inf;
1625 void suspend(struct early_suspend *h)
1627 struct suspend_info *info = container_of(h, struct suspend_info,
1630 struct rk29fb_inf *inf = info->inf;
1632 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1635 printk("inf==0, rk29fb_suspend fail! \n");
1639 set_lcd_pin(g_pdev, 0);
1641 if(inf->cur_screen->standby)
1643 fbprintk(">>>>>> power down the screen! \n");
1644 inf->cur_screen->standby(1);
1647 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
1648 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
1649 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1651 if(!inf->in_suspend)
1653 fbprintk(">>>>>> diable the lcdc clk! \n");
1656 clk_disable(inf->dclk);
1659 clk_disable(inf->clk);
1662 inf->in_suspend = 1;
1667 void resume(struct early_suspend *h)
1669 struct suspend_info *info = container_of(h, struct suspend_info,
1672 struct rk29fb_inf *inf = info->inf;
1674 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1676 printk("inf==0, rk29fb_resume fail! \n");
1682 inf->in_suspend = 0;
1683 fbprintk(">>>>>> enable the lcdc clk! \n");
1685 clk_enable(inf->dclk);
1688 clk_enable(inf->clk);
1692 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
1693 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
1694 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1696 if(inf->cur_screen->standby)
1698 fbprintk(">>>>>> power on the screen! \n");
1699 inf->cur_screen->standby(0);
1702 set_lcd_pin(g_pdev, 1);
1703 memcpy(inf->preg, &inf->regbak, 0xa4); //resume reg
1706 struct suspend_info suspend_info = {
1707 .early_suspend.suspend = suspend,
1708 .early_suspend.resume = resume,
1709 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
1713 static int __init rk29fb_probe (struct platform_device *pdev)
1715 struct rk29fb_inf *inf = NULL;
1716 struct resource *res = NULL;
1717 struct resource *mem = NULL;
1718 struct rk29fb_info *mach_info = NULL;
1719 struct rk29fb_screen *screen = NULL;
1723 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1725 /* Malloc rk29fb_inf and set it to pdev for drvdata */
1726 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
1727 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
1730 dev_err(&pdev->dev, ">> inf kmalloc fail!");
1732 goto release_drvdata;
1734 memset(inf, 0, sizeof(struct rk29fb_inf));
1735 platform_set_drvdata(pdev, inf);
1737 mach_info = pdev->dev.platform_data;
1738 /* Fill screen info and set current screen */
1739 fbprintk(">> Fill screen info and set current screen \n");
1740 set_lcd_info(&inf->lcd_info, mach_info->lcd_info);
1741 set_tv_info(&inf->tv_info[0]);
1742 set_hdmi_info(&inf->hdmi_info[0]);
1743 inf->cur_screen = &inf->lcd_info;
1744 screen = inf->cur_screen;
1745 if(SCREEN_NULL==screen->type)
1747 dev_err(&pdev->dev, ">> Please select a display device! \n");
1749 goto release_drvdata;
1752 /* get virtual basic address of lcdc register */
1753 fbprintk(">> get virtual basic address of lcdc register \n");
1754 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1757 dev_err(&pdev->dev, "failed to get memory registers\n");
1759 goto release_drvdata;
1761 inf->reg_phy_base = res->start;
1762 inf->len = (res->end - res->start) + 1;
1763 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
1766 dev_err(&pdev->dev, "failed to get memory region\n");
1768 goto release_drvdata;
1770 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
1771 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
1772 if (inf->reg_vir_base == NULL)
1774 dev_err(&pdev->dev, "ioremap() of registers failed\n");
1776 goto release_drvdata;
1778 inf->preg = (LCDC_REG*)inf->reg_vir_base;
1780 /* Prepare win1 info */
1781 fbprintk(">> Prepare win1 info \n");
1782 inf->win1fb = framebuffer_alloc(sizeof(struct win1_par), &pdev->dev);
1785 dev_err(&pdev->dev, ">> win1fb framebuffer_alloc fail!");
1788 goto release_win1fb;
1791 strcpy(inf->win1fb->fix.id, "win1fb");
1792 inf->win1fb->fix.type = FB_TYPE_PACKED_PIXELS;
1793 inf->win1fb->fix.type_aux = 0;
1794 inf->win1fb->fix.xpanstep = 1;
1795 inf->win1fb->fix.ypanstep = 1;
1796 inf->win1fb->fix.ywrapstep = 0;
1797 inf->win1fb->fix.accel = FB_ACCEL_NONE;
1798 inf->win1fb->fix.visual = FB_VISUAL_TRUECOLOR;
1799 inf->win1fb->fix.smem_len = 0;
1800 inf->win1fb->fix.line_length = 0;
1801 inf->win1fb->fix.smem_start = 0;
1803 inf->win1fb->var.xres = screen->x_res;
1804 inf->win1fb->var.yres = screen->y_res;
1805 inf->win1fb->var.bits_per_pixel = 16;
1806 inf->win1fb->var.xres_virtual = screen->x_res;
1807 inf->win1fb->var.yres_virtual = screen->y_res;
1808 inf->win1fb->var.width = screen->x_res;
1809 inf->win1fb->var.height = screen->y_res;
1810 inf->win1fb->var.pixclock = screen->pixclock;
1811 inf->win1fb->var.left_margin = screen->left_margin;
1812 inf->win1fb->var.right_margin = screen->right_margin;
1813 inf->win1fb->var.upper_margin = screen->upper_margin;
1814 inf->win1fb->var.lower_margin = screen->lower_margin;
1815 inf->win1fb->var.vsync_len = screen->vsync_len;
1816 inf->win1fb->var.hsync_len = screen->hsync_len;
1817 inf->win1fb->var.red = def_rgb_16.red;
1818 inf->win1fb->var.green = def_rgb_16.green;
1819 inf->win1fb->var.blue = def_rgb_16.blue;
1820 inf->win1fb->var.transp = def_rgb_16.transp;
1822 inf->win1fb->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
1823 inf->win1fb->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
1824 inf->win1fb->var.activate = FB_ACTIVATE_NOW;
1825 inf->win1fb->var.accel_flags = 0;
1826 inf->win1fb->var.vmode = FB_VMODE_NONINTERLACED;
1828 inf->win1fb->fbops = &win1fb_ops;
1829 inf->win1fb->flags = FBINFO_FLAG_DEFAULT;
1830 inf->win1fb->pseudo_palette = ((struct win1_par*)inf->win1fb->par)->pseudo_pal;
1831 inf->win1fb->screen_base = 0;
1833 memset(inf->win1fb->par, 0, sizeof(struct win1_par));
1834 ret = fb_alloc_cmap(&inf->win1fb->cmap, 256, 0);
1838 /* Prepare win0 info */
1839 fbprintk(">> Prepare win0 info \n");
1840 inf->win0fb = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
1843 dev_err(&pdev->dev, ">> win0fb framebuffer_alloc fail!");
1846 goto release_win0fb;
1849 strcpy(inf->win0fb->fix.id, "win0fb");
1850 inf->win0fb->fix.type = FB_TYPE_PACKED_PIXELS;
1851 inf->win0fb->fix.type_aux = 0;
1852 inf->win0fb->fix.xpanstep = 1;
1853 inf->win0fb->fix.ypanstep = 1;
1854 inf->win0fb->fix.ywrapstep = 0;
1855 inf->win0fb->fix.accel = FB_ACCEL_NONE;
1856 inf->win0fb->fix.visual = FB_VISUAL_TRUECOLOR;
1857 inf->win0fb->fix.smem_len = 0;
1858 inf->win0fb->fix.line_length = 0;
1859 inf->win0fb->fix.smem_start = 0;
1861 inf->win0fb->var.xres = screen->x_res;
1862 inf->win0fb->var.yres = screen->y_res;
1863 inf->win0fb->var.bits_per_pixel = 16;
1864 inf->win0fb->var.xres_virtual = screen->x_res;
1865 inf->win0fb->var.yres_virtual = screen->y_res;
1866 inf->win0fb->var.width = screen->x_res;
1867 inf->win0fb->var.height = screen->y_res;
1868 inf->win0fb->var.pixclock = screen->pixclock;
1869 inf->win0fb->var.left_margin = screen->left_margin;
1870 inf->win0fb->var.right_margin = screen->right_margin;
1871 inf->win0fb->var.upper_margin = screen->upper_margin;
1872 inf->win0fb->var.lower_margin = screen->lower_margin;
1873 inf->win0fb->var.vsync_len = screen->vsync_len;
1874 inf->win0fb->var.hsync_len = screen->hsync_len;
1875 inf->win0fb->var.red = def_rgb_16.red;
1876 inf->win0fb->var.green = def_rgb_16.green;
1877 inf->win0fb->var.blue = def_rgb_16.blue;
1878 inf->win0fb->var.transp = def_rgb_16.transp;
1880 inf->win0fb->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
1881 inf->win0fb->var.grayscale = ((inf->win0fb->var.yres<<20)&0xfff00000) + ((inf->win0fb->var.xres<<8)&0xfff00);//win0 xsize & ysize
1882 inf->win0fb->var.activate = FB_ACTIVATE_NOW;
1883 inf->win0fb->var.accel_flags = 0;
1884 inf->win0fb->var.vmode = FB_VMODE_NONINTERLACED;
1886 inf->win0fb->fbops = &win0fb_ops;
1887 inf->win0fb->flags = FBINFO_FLAG_DEFAULT;
1888 inf->win0fb->pseudo_palette = ((struct win0_par*)inf->win0fb->par)->pseudo_pal;
1889 inf->win0fb->screen_base = 0;
1891 memset(inf->win0fb->par, 0, sizeof(struct win0_par));
1893 /* Init all lcdc and lcd before register_framebuffer. */
1894 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
1895 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
1896 init_lcdc(inf->win1fb);
1898 #ifdef CONFIG_CPU_FREQ
1899 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
1900 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
1902 fbprintk("got clock\n");
1906 struct rk29_fb_setting_info fb_setting;
1907 if( OUT_P888==inf->lcd_info.face ||
1908 OUT_P888==inf->tv_info[0].face ||
1909 OUT_P888==inf->hdmi_info[0].face ) // set lcdc iomux
1911 fb_setting.data_num = 24;
1913 else if(OUT_P666 == inf->lcd_info.face )
1915 fb_setting.data_num = 18;
1919 fb_setting.data_num = 16;
1921 fb_setting.den_en = 1;
1922 fb_setting.vsync_en = 1;
1923 fb_setting.disp_on_en = 1;
1924 fb_setting.standby_en = 1;
1925 if( inf->lcd_info.mcu_usefmk )
1926 fb_setting.mcu_fmk_en =1;
1927 mach_info->io_init(&fb_setting);
1930 set_lcd_pin(pdev, 1);
1933 inf->mcu_usetimer = 1;
1934 inf->mcu_fmksync = 0;
1935 load_screen(inf->win1fb, 1);
1937 /* Register framebuffer(win1fb & win0fb) */
1938 fbprintk(">> Register framebuffer(win1fb) \n");
1939 ret = register_framebuffer(inf->win1fb);
1942 printk(">> win1fb register_framebuffer fail!\n");
1944 goto release_win0fb;
1946 fbprintk(">> Register framebuffer(win0fb) \n");
1948 ret = register_framebuffer(inf->win0fb);
1951 printk(">> win0fb register_framebuffer fail!\n");
1953 goto unregister_win1fb;
1956 #ifdef CONFIG_HAS_EARLYSUSPEND
1957 suspend_info.inf = inf;
1958 register_early_suspend(&suspend_info.early_suspend);
1961 /* get and request irq */
1962 fbprintk(">> get and request irq \n");
1963 irq = platform_get_irq(pdev, 0);
1965 dev_err(&pdev->dev, "no irq for device\n");
1967 goto unregister_win1fb;
1969 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
1971 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
1976 if( inf->lcd_info.mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
1978 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
1981 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
1987 printk(" %s ok\n", __FUNCTION__);
1992 free_irq(irq, pdev);
1994 unregister_framebuffer(inf->win1fb);
1997 framebuffer_release(inf->win0fb);
2000 if(&inf->win1fb->cmap)
2001 fb_dealloc_cmap(&inf->win1fb->cmap);
2004 framebuffer_release(inf->win1fb);
2007 if(inf && inf->reg_vir_base)
2008 iounmap(inf->reg_vir_base);
2010 release_mem_region(inf->reg_phy_base, inf->len);
2013 platform_set_drvdata(pdev, NULL);
2017 static int rk29fb_remove(struct platform_device *pdev)
2019 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2020 struct fb_info *info = NULL;
2022 struct rk29fb_info *mach_info = NULL;
2025 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2028 printk("inf==0, rk29_fb_remove fail! \n");
2032 irq = platform_get_irq(pdev, 0);
2035 free_irq(irq, pdev);
2038 mach_info = pdev->dev.platform_data;
2039 if(mach_info->mcu_fmk_pin)
2041 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2044 set_lcd_pin(pdev, 0);
2048 win0fb_blank(FB_BLANK_POWERDOWN, inf->win0fb);
2050 win1fb_blank(FB_BLANK_POWERDOWN, inf->win1fb);
2053 //rk29fb_suspend(pdev, msg);
2054 // unmap memory and release framebuffer
2057 if (info->screen_base) {
2058 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2059 info->screen_base = 0;
2060 info->fix.smem_start = 0;
2061 info->fix.smem_len = 0;
2063 unregister_framebuffer(inf->win0fb);
2064 framebuffer_release(inf->win0fb);
2069 if (info->screen_base) {
2070 dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2071 info->screen_base = 0;
2072 info->fix.smem_start = 0;
2073 info->fix.smem_len = 0;
2075 unregister_framebuffer(inf->win1fb);
2076 framebuffer_release(inf->win1fb);
2080 #ifdef CONFIG_CPU_FREQ
2081 cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2086 clk_disable(inf->clk);
2092 clk_disable(inf->dclk);
2098 platform_set_drvdata(pdev, NULL);
2103 static void rk29fb_shutdown(struct platform_device *pdev)
2105 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2107 //printk("----------------------------rk29fb_shutdown----------------------------\n");
2108 set_lcd_pin(pdev, 0);
2111 clk_disable(inf->dclk);
2115 clk_disable(inf->clk);
2119 static struct platform_driver rk29fb_driver = {
2120 .probe = rk29fb_probe,
2121 .remove = rk29fb_remove,
2124 .owner = THIS_MODULE,
2126 .shutdown = rk29fb_shutdown,
2129 static int __init rk29fb_init(void)
2131 return platform_driver_register(&rk29fb_driver);
2134 static void __exit rk29fb_exit(void)
2136 platform_driver_unregister(&rk29fb_driver);
2139 //subsys_initcall(rk29fb_init);
2141 module_init(rk29fb_init);
2142 module_exit(rk29fb_exit);
2145 MODULE_AUTHOR(" zyw@rock-chips.com");
2146 MODULE_DESCRIPTION("Driver for rk29 fb device");
2147 MODULE_LICENSE("GPL");