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, },
100 volatile u32 y_offset;
101 volatile u32 c_offset;
109 u32 xpos; //size in panel
111 u32 xsize; //start point in panel
115 struct rw_semaphore sem;
116 wait_queue_head_t wait;
117 struct win_set mirror;
118 struct win_set displ;
143 void __iomem *reg_vir_base; // virtual basic address of lcdc register
144 u32 reg_phy_base; // physical basic address of lcdc register
145 u32 len; // physical map length of lcdc register
149 struct clk *dclk; //lcdc dclk
150 struct clk *dclk_parent; //lcdc dclk divider frequency source
151 struct clk *dclk_divider; //lcdc demodulator divider frequency
152 struct clk *aclk; //lcdc share memory frequency
153 struct clk *aclk_parent; //lcdc aclk divider frequency source
154 unsigned long dclk_rate;
156 /* lcdc reg base address and backup reg */
162 /* variable used in mcu panel */
166 struct timer_list mcutimer;
172 /* external memery */
173 char __iomem *screen_base2;
175 unsigned long smem_start2;
177 char __iomem *cursor_base; /* cursor Virtual address*/
178 __u32 cursor_size; /* Amount of ioremapped VRAM or 0 */
179 unsigned long cursor_start;
181 struct rk29fb_screen panel1_info; // 1st panel, it's lcd normally
182 struct rk29fb_screen panel2_info; // 2nd panel
183 struct rk29fb_screen *cur_screen;
184 #ifdef CONFIG_CPU_FREQ
185 struct notifier_block freq_transition;
190 typedef enum _TRSP_MODE
202 struct platform_device *g_pdev = NULL;
203 //static int win1fb_set_par(struct fb_info *info);
206 #define CHK_SUSPEND(inf) \
207 if(inf->in_suspend) { \
208 fbprintk(">>>>>> fb is in suspend! return! \n"); \
212 #define CHK_SUSPEND(inf)
215 static DECLARE_WAIT_QUEUE_HEAD(wq);
216 static int wq_condition = 0;
217 #if ANDROID_USE_THREE_BUFS
218 static int new_frame_seted = 1;
221 void set_lcd_pin(struct platform_device *pdev, int enable)
223 struct rk29fb_info *mach_info = pdev->dev.platform_data;
225 unsigned display_on = mach_info->disp_on_pin;
226 unsigned lcd_standby = mach_info->standby_pin;
228 int display_on_pol = mach_info->disp_on_value;
229 int lcd_standby_pol = mach_info->standby_value;
231 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
232 fbprintk(">>>>>> display_on(%d) = %d \n", display_on, enable ? display_on_pol : !display_on_pol);
233 fbprintk(">>>>>> lcd_standby(%d) = %d \n", lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);
237 if(display_on != INVALID_GPIO)
239 gpio_direction_output(display_on, 0);
240 gpio_set_value(display_on, enable ? display_on_pol : !display_on_pol);
242 if(lcd_standby != INVALID_GPIO)
244 gpio_direction_output(lcd_standby, 0);
245 gpio_set_value(lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);
249 int mcu_do_refresh(struct rk29fb_inf *inf)
251 if(inf->mcu_stopflush) return 0;
253 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
258 inf->mcu_needflush = 1;
262 // not use frame mark
263 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT))
265 if(!LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLD_STATUS))
267 inf->mcu_needflush = 1;
271 if(inf->cur_screen->refresh) inf->cur_screen->refresh(REFRESH_PRE);
272 inf->mcu_needflush = 0;
274 LcdSetRegBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
281 void mcutimer_callback(unsigned long arg)
283 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
284 static int waitcnt = 0;
286 mod_timer(&inf->mcutimer, jiffies + HZ/10);
288 switch(inf->mcu_status)
291 inf->mcu_status = MS_MCU;
294 if(inf->mcu_usetimer) mcu_do_refresh(inf);
297 inf->mcu_status = MS_EWAITEND;
305 inf->mcu_status = MS_EEND;
309 inf->mcu_status = MS_MCU;
312 inf->mcu_status = MS_MCU;
317 int mcu_refresh(struct rk29fb_inf *inf)
319 static int mcutimer_inited = 0;
321 if(SCREEN_MCU!=inf->cur_screen->type) return 0;
326 init_timer(&inf->mcutimer);
327 inf->mcutimer.function = mcutimer_callback;
328 inf->mcutimer.expires = jiffies + HZ/5;
329 inf->mcu_status = MS_IDLE;
330 add_timer(&inf->mcutimer);
333 if(MS_MCU==inf->mcu_status) mcu_do_refresh(inf);
338 int mcu_ioctl(unsigned int cmd, unsigned long arg)
340 struct rk29fb_inf *inf = NULL;
341 if(!g_pdev) return -1;
343 inf = dev_get_drvdata(&g_pdev->dev);
348 LcdClrBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
349 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
350 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
354 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_RS_SELECT);
355 LcdWrReg(inf, MCU_BYPASS_WPORT, arg);
359 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_BYPASSMODE_SELECT, v_MCU_BYPASSMODE_SELECT(arg));
360 LcdWrReg(inf, REG_CFG_DONE, 0x01);
370 static irqreturn_t mcu_irqfmk(int irq, void *dev_id)
372 struct platform_device *pdev = (struct platform_device*)dev_id;
373 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
374 struct rk29fb_screen *screen;
376 if(!inf) return IRQ_HANDLED;
378 screen = inf->cur_screen;
380 if(0==screen->mcu_usefmk) {
384 if(inf->mcu_fmksync == 1)
387 inf->mcu_fmksync = 1;
388 if(inf->mcu_needflush)
390 inf->mcu_needflush = 0;
392 if(inf->cur_screen->refresh)
393 inf->cur_screen->refresh(REFRESH_PRE);
394 LcdSetBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
396 inf->mcu_fmksync = 0;
401 int init_lcdc(struct fb_info *info)
403 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
406 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
408 inf->clk = clk_get(NULL, "hclk_lcdc");
409 if (IS_ERR(inf->clk))
411 printk(KERN_ERR "failed to get lcdc_hclk source\n");
414 clk_enable(inf->clk);
416 // set AHB access rule and disable all windows
417 LcdWrReg(inf, SYS_CONFIG, 0x20000000);
418 LcdWrReg(inf, SWAP_CTRL, 0);
419 LcdWrReg(inf, FIFO_WATER_MARK, 0x00000860);
421 // and mcu holdmode; and set win1 top.
422 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST | m_MCU_BYPASSMODE_SELECT ,
423 v_MCU_HOLDMODE_SELECT(0)| v_MCU_HOLDMODE_FRAME_ST(0) |v_MCU_BYPASSMODE_SELECT(0));
425 // disable blank out, black out, tristate out, yuv2rgb bypass
426 LcdMskReg(inf, BLEND_CTRL,m_W2_BLEND_EN | m_W1_BLEND_EN | m_W0_BLEND_EN | m_HWC_BLEND_EN |
427 m_HWC_BLEND_FACTOR | m_W1_BLEND_FACTOR | m_W0_BLEND_FACTOR,
428 v_W2_BLEND_EN(0) |v_W1_BLEND_EN(0) | v_W0_BLEND_EN(0) | v_HWC_BLEND_EN(0) |
429 v_HWC_BLEND_FACTOR(0) | v_W2_BLEND_FACTOR(0) | v_W1_BLEND_FACTOR(0) | v_W0_BLEND_FACTOR(0)
432 LcdMskReg(inf, WIN0_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
433 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN, v_COLORKEY_EN(0));
435 LcdWrReg(inf, DSP_CTRL1, 0);
437 // initialize all interrupt
438 clr = v_HOR_STARTCLEAR(1) | v_FRM_STARTCLEAR(1) | v_SCANNING_CLEAR(1);
440 msk = v_HOR_STARTMASK(1) | v_FRM_STARTMASK(0) | v_SCANNING_MASK(1);
442 LcdWrReg(inf, INT_STATUS, clr | msk);
444 // let above to take effect
445 LcdWrReg(inf, REG_CFG_DONE, 0x01);
450 void load_screen(struct fb_info *info, bool initscreen)
453 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
454 struct rk29fb_screen *screen = inf->cur_screen;
456 u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend;
457 u16 right_margin = screen->right_margin, lower_margin = screen->lower_margin;
458 u16 x_res = screen->x_res, y_res = screen->y_res;
459 u32 aclk_rate = 150000000;
462 printk(">>>>>> %s : %s no g_pdev\n", __FILE__, __FUNCTION__);
466 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
468 // set the rgb or mcu
469 LcdMskReg(inf, MCU_TIMING_CTRL, m_MCU_OUTPUT_SELECT, v_MCU_OUTPUT_SELECT((SCREEN_MCU==screen->type)?(1):(0)));
471 // set out format and mcu timing
472 mcu_total = (screen->mcu_wrperiod*150*1000)/1000000;
473 if(mcu_total>31) mcu_total = 31;
474 if(mcu_total<3) mcu_total = 3;
475 mcu_rwstart = (mcu_total+1)/4 - 1;
476 mcu_rwend = ((mcu_total+1)*3)/4 - 1;
477 mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0);
478 mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend);
480 fbprintk(">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n",
481 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend);
483 LcdMskReg(inf, MCU_TIMING_CTRL,
484 m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END |
485 m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST,
486 v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) |
487 v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) |
488 v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)
491 // set synchronous pin polarity and data pin swap rule
492 switch (screen->face)
496 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
500 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
504 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0));
508 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1));
512 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1));
513 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
516 LcdMskReg(inf, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0));
517 LcdMskReg(inf, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0));
522 LcdMskReg(inf, DSP_CTRL0,
523 m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |
524 m_DCLK_POLARITY | m_COLOR_SPACE_CONVERSION,
525 v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) |
526 v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk) | v_COLOR_SPACE_CONVERSION(0)
529 LcdMskReg(inf, DSP_CTRL1, m_BG_COLOR, v_BG_COLOR(0x000000) );
531 LcdMskReg(inf, SWAP_CTRL, m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP,
532 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));
534 // set horizontal & vertical out timing
535 if(SCREEN_MCU==inf->cur_screen->type)
537 right_margin = x_res/6;
540 printk("screen->hsync_len =%d, screen->left_margin =%d, x_res =%d, right_margin = %d \n",
541 screen->hsync_len , screen->left_margin , x_res , right_margin );
542 LcdMskReg(inf, DSP_HTOTAL_HS_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len) |
543 v_BIT12HI(screen->hsync_len + screen->left_margin + x_res + right_margin));
544 LcdMskReg(inf, DSP_HACT_ST_END, m_BIT12LO | m_BIT12HI, v_BIT12LO(screen->hsync_len + screen->left_margin + x_res) |
545 v_BIT12HI(screen->hsync_len + screen->left_margin));
547 LcdMskReg(inf, DSP_VTOTAL_VS_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len) |
548 v_BIT11HI(screen->vsync_len + screen->upper_margin + y_res + lower_margin));
549 LcdMskReg(inf, DSP_VACT_ST_END, m_BIT11LO | m_BIT11HI, v_BIT11LO(screen->vsync_len + screen->upper_margin+y_res)|
550 v_BIT11HI(screen->vsync_len + screen->upper_margin));
552 LcdMskReg(inf, DSP_VS_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
553 LcdMskReg(inf, DSP_VACT_ST_END_F1, m_BIT11LO | m_BIT11HI, v_BIT11LO(0) | v_BIT11HI(0));
555 // let above to take effect
556 LcdWrReg(inf, REG_CFG_DONE, 0x01);
558 inf->dclk = clk_get(NULL, "dclk_lcdc");
559 if (IS_ERR(inf->dclk))
561 printk(KERN_ERR "failed to get lcd dclock source\n");
564 inf->dclk_divider= clk_get(NULL, "dclk_lcdc_div");
565 if (IS_ERR(inf->dclk_divider))
567 printk(KERN_ERR "failed to get lcd clock lcdc_divider source \n");
571 if(inf->cur_screen == &inf->panel1_info) {
572 inf->dclk_parent = clk_get(NULL, "periph_pll");
574 inf->dclk_parent = clk_get(NULL, "codec_pll");
575 clk_set_rate(inf->dclk_parent, 297000000);
578 if (IS_ERR(inf->dclk_parent))
580 printk(KERN_ERR "failed to get lcd dclock parent source\n");
584 inf->aclk = clk_get(NULL, "aclk_lcdc");
585 if (IS_ERR(inf->aclk))
587 printk(KERN_ERR "failed to get lcd clock clk_share_mem source \n");
590 inf->aclk_parent = clk_get(NULL, "periph_pll");
591 if (IS_ERR(inf->dclk_parent))
593 printk(KERN_ERR "failed to get lcd dclock parent source\n");
598 if(SCREEN_MCU==screen->type) screen->pixclock = 150000000; //mcu fix to 150 MHz
600 if(initscreen == 0) //not init
602 clk_disable(inf->dclk);
603 clk_disable(inf->aclk);
606 clk_set_parent(inf->dclk_divider, inf->dclk_parent);
607 clk_set_parent(inf->dclk, inf->dclk_divider);
608 clk_set_parent(inf->aclk, inf->aclk_parent);
610 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, screen->lcdc_aclk);
612 ret = clk_set_rate(inf->dclk_divider, screen->pixclock);
615 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
618 if(screen->lcdc_aclk){
619 aclk_rate = screen->lcdc_aclk;
621 ret = clk_set_rate(inf->aclk, aclk_rate);
623 printk(KERN_ERR ">>>>>> set lcdc dclk_divider faild \n ");
626 clk_enable(inf->dclk);
627 clk_enable(inf->aclk);
636 #ifdef CONFIG_CPU_FREQ
638 * CPU clock speed change handler. We need to adjust the LCD timing
639 * parameters when the CPU clock is adjusted by the power management
642 #define TO_INF(ptr,member) container_of(ptr,struct rk29fb_inf,member)
645 rk29fb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
647 struct rk29fb_inf *inf = TO_INF(nb, freq_transition);
648 struct rk29fb_screen *screen = inf->cur_screen;
653 case CPUFREQ_PRECHANGE:
655 case CPUFREQ_POSTCHANGE:
657 dclk_rate = screen->pixclock * 1000000;
659 fbprintk(">>>>>> set lcdc dclk need %d HZ, clk_parent = %d hz \n ", screen->pixclock, dclk_rate);
661 clk_set_rate(inf->dclk_divider, dclk_rate);
669 static inline unsigned int chan_to_field(unsigned int chan,
670 struct fb_bitfield *bf)
673 chan >>= 16 - bf->length;
674 return chan << bf->offset;
677 static int fb_setcolreg(unsigned regno,
678 unsigned red, unsigned green, unsigned blue,
679 unsigned transp, struct fb_info *info)
682 // fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
684 switch (info->fix.visual) {
685 case FB_VISUAL_TRUECOLOR:
686 /* true-colour, use pseudo-palette */
688 u32 *pal = info->pseudo_palette;
689 val = chan_to_field(red, &info->var.red);
690 val |= chan_to_field(green, &info->var.green);
691 val |= chan_to_field(blue, &info->var.blue);
696 return -1; /* unknown type */
703 int rk29_set_cursor(struct fb_info *info, struct fb_cursor *cursor)
705 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
707 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
709 /* check not being asked to exceed capabilities */
711 if (cursor->image.width > 32)
714 if (cursor->image.height > 32)
717 if (cursor->image.depth > 1)
721 LcdSetBit(inf, SYS_CONFIG, m_HWC_ENABLE);
723 LcdClrBit(inf, SYS_CONFIG, m_HWC_ENABLE);
726 if (cursor->set & FB_CUR_SETPOS)
728 unsigned int x = cursor->image.dx;
729 unsigned int y = cursor->image.dy;
731 if (x >= 0x800 || y >= 0x800 )
733 LcdWrReg(inf, HWC_DSP_ST, v_BIT11LO(x)|v_BIT11HI(y));
737 if (cursor->set & FB_CUR_SETCMAP)
739 unsigned int bg_col = cursor->image.bg_color;
740 unsigned int fg_col = cursor->image.fg_color;
742 fbprintk("%s: update cmap (%08x,%08x)\n",
743 __func__, bg_col, fg_col);
745 LcdMskReg(inf, HWC_COLOR_LUT0, m_HWC_R|m_HWC_G|m_HWC_B,
746 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));
748 LcdMskReg(inf, HWC_COLOR_LUT2, m_HWC_R|m_HWC_G|m_HWC_B,
749 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));
752 if ((cursor->set & FB_CUR_SETSIZE ||
753 cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE))
754 && info->screen_base && info->fix.smem_start && info->fix.smem_len)
756 /* rk29 cursor is a 2 bpp 32x32 bitmap this routine
757 * clears it to transparent then combines the cursor
758 * shape plane with the colour plane to set the
761 const unsigned char *pcol = cursor->image.data;
762 const unsigned char *pmsk = cursor->mask;
764 unsigned long cursor_mem_start;
765 unsigned char dcol = 0;
766 unsigned char dmsk = 0;
769 dst = info->screen_base + info->fix.smem_len - CURSOR_BUF_SIZE;
770 cursor_mem_start = info->fix.smem_start + info->fix.smem_len - CURSOR_BUF_SIZE;
772 fbprintk("%s: setting shape (%d,%d)\n",
773 __func__, cursor->image.width, cursor->image.height);
775 memset(dst, 0, CURSOR_BUF_SIZE);
777 for (y = 0; y < cursor->image.height; y++)
779 for (x = 0; x < cursor->image.width; x++)
790 op = (dcol & 1) ? 1 : 3;
791 op <<= ((x % 4) * 2);
792 *(u8*)(dst+(x/4)) |= op;
797 LcdSetBit(inf, SYS_CONFIG,m_HWC_RELOAD_EN);
798 LcdWrReg(inf, HWC_MST, cursor_mem_start);
799 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
800 if(SCREEN_MCU == inf->cur_screen->type) {
801 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
805 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
807 LcdClrBit(inf, SYS_CONFIG, m_HWC_RELOAD_EN);
814 static int win0_blank(int blank_mode, struct fb_info *info)
816 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
818 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
824 case FB_BLANK_UNBLANK:
825 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
828 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
831 LcdWrReg(inf, REG_CFG_DONE, 0x01);
837 static int win0_set_par(struct fb_info *info)
839 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
840 struct rk29fb_screen *screen = inf->cur_screen;
841 struct fb_var_screeninfo *var = &info->var;
842 struct fb_fix_screeninfo *fix = &info->fix;
843 struct win0_par *par = info->par;
845 u32 xact = var->xres; /* visible resolution */
846 u32 yact = var->yres;
847 u32 xvir = var->xres_virtual; /* virtual resolution */
848 u32 yvir = var->yres_virtual;
849 //u32 xact_st = var->xoffset; /* offset from virtual to visible */
850 //u32 yact_st = var->yoffset; /* resolution */
851 u32 xpos = par->xpos;
852 u32 ypos = par->ypos;
854 u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
855 u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
857 u32 y_addr = 0; //user alloc buf addr y
860 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
864 // calculate the display phy address
865 y_addr = fix->smem_start + par->y_offset;
866 uv_addr = fix->mmio_start + par->c_offset;
868 ScaleYrgbX = CalScaleW0(xact, par->xsize);
869 ScaleYrgbY = CalScaleW0(yact, par->ysize);
874 ScaleCbrX= CalScaleW0((xact/2), par->xsize);
875 ScaleCbrY = CalScaleW0(yact, par->ysize);
879 ScaleCbrX= CalScaleW0(xact/2, par->xsize);
880 ScaleCbrY = CalScaleW0(yact/2, par->ysize);
883 ScaleCbrX= CalScaleW0(xact, par->xsize);
884 ScaleCbrY = CalScaleW0(yact, par->ysize);
890 xpos += (screen->left_margin + screen->hsync_len);
891 ypos += (screen->upper_margin + screen->vsync_len);
893 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
894 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
896 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE | m_W0_FORMAT, v_W0_ENABLE(par->addr_seted) | v_W0_FORMAT(par->format));
898 LcdMskReg(inf, WIN0_VIR, m_WORDLO | m_WORDHI, v_VIRWIDTH(xvir) | v_VIRHEIGHT((yvir)) );
899 LcdMskReg(inf, WIN0_ACT_INFO, m_WORDLO | m_WORDHI, v_WORDLO(xact) | v_WORDHI(yact));
900 LcdMskReg(inf, WIN0_DSP_ST, m_BIT11LO | m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
901 LcdMskReg(inf, WIN0_DSP_INFO, m_BIT12LO | m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
902 LcdMskReg(inf, WIN0_SCL_FACTOR_YRGB, m_WORDLO | m_WORDHI, v_WORDLO(ScaleYrgbX) | v_WORDHI(ScaleYrgbY));
903 LcdMskReg(inf, WIN0_SCL_FACTOR_CBR, m_WORDLO | m_WORDHI, v_WORDLO(ScaleCbrX) | v_WORDHI(ScaleCbrY));
908 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,
909 v_W0_YRGB_8_SWAP(1) | v_W0_YRGB_16_SWAP(1) | v_W0_YRGB_R_SHIFT_SWAP(1) | v_W0_565_RB_SWAP(0) | v_W0_YRGB_M8_SWAP(0) | v_W0_CBR_8_SWAP(0));
912 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,
913 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));
916 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,
917 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) |
918 v_W0_YRGB_M8_SWAP((var->rotate==0)) | v_W0_CBR_8_SWAP(0));
921 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,
922 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) );
926 LcdWrReg(inf, REG_CFG_DONE, 0x01);
932 static int win0_pan( struct fb_info *info )
934 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
935 // struct fb_var_screeninfo *var0 = &info->var;
936 struct fb_fix_screeninfo *fix0 = &info->fix;
937 struct win0_par *par = info->par;
938 u32 y_addr=0, uv_addr=0;
940 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
944 y_addr = fix0->smem_start + par->y_offset;//y_offset;
945 uv_addr = fix0->mmio_start + par->c_offset ;//c_offset;
947 LcdWrReg(inf, WIN0_YRGB_MST, y_addr);
948 LcdWrReg(inf, WIN0_CBR_MST, uv_addr);
949 LcdWrReg(inf, REG_CFG_DONE, 0x01);
951 // enable win0 after the win0 addr is seted
952 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE((1==par->addr_seted)?(1):(0)));
958 static int win1_blank(int blank_mode, struct fb_info *info)
960 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
962 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
968 case FB_BLANK_UNBLANK:
969 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(1));
972 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
975 LcdWrReg(inf, REG_CFG_DONE, 0x01);
981 static int win1_set_par(struct fb_info *info)
983 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
984 struct fb_var_screeninfo *var = &info->var;
985 struct fb_fix_screeninfo *fix = &info->fix;
986 struct rk29fb_screen *screen = inf->cur_screen;
987 struct win0_par *par = info->par;
989 //u32 offset=0, addr=0, map_size=0, smem_len=0;
992 u16 xres_virtual = var->xres_virtual; //virtual screen size
994 //u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
995 //u16 ypos_virtual = var->yoffset;
997 u16 xpos = par->xpos; //visiable offset in panel
998 u16 ypos = par->ypos;
1000 u8 trspmode = TRSP_CLOSE;
1003 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1005 addr = fix->smem_start + par->y_offset;
1007 LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE|m_W1_FORMAT, v_W1_ENABLE(1)|v_W1_FORMAT(par->format));
1009 xpos += (screen->left_margin + screen->hsync_len);
1010 ypos += (screen->upper_margin + screen->vsync_len);
1012 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1014 LcdMskReg(inf, WIN1_DSP_ST, m_BIT11LO|m_BIT11HI, v_BIT11LO(xpos) | v_BIT11HI(ypos));
1015 LcdMskReg(inf, WIN1_DSP_INFO, m_BIT12LO|m_BIT12HI, v_BIT12LO(par->xsize) | v_BIT12HI(par->ysize));
1017 LcdMskReg(inf, WIN1_VIR, m_WORDLO , v_WORDLO(xres_virtual));
1019 LcdMskReg(inf, BLEND_CTRL, m_W1_BLEND_EN | m_W1_BLEND_FACTOR,
1020 v_W1_BLEND_EN((TRSP_FMREG==trspmode) || (TRSP_MASK==trspmode)) | v_W1_BLEND_FACTOR(trspval));
1022 // enable win1 color key and set the color to black(rgb=0)
1023 LcdMskReg(inf, WIN1_COLOR_KEY_CTRL, m_COLORKEY_EN | m_KEYCOLOR, v_COLORKEY_EN(1) | v_KEYCOLOR(0));
1025 if(1==par->format) //rgb565
1027 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1028 v_W1_8_SWAP(0) | v_W1_16_SWAP(0) | v_W1_R_SHIFT_SWAP(0) | v_W1_565_RB_SWAP(0) );
1032 LcdMskReg(inf, SWAP_CTRL, m_W1_8_SWAP | m_W1_16_SWAP | m_W1_R_SHIFT_SWAP | m_W1_565_RB_SWAP,
1033 v_W1_8_SWAP(1) | v_W1_16_SWAP(1) | v_W1_R_SHIFT_SWAP(1) | v_W1_565_RB_SWAP(0) );
1035 LcdMskReg(inf, DSP_CTRL0, m_W1_TRANSP_FROM, v_W1_TRANSP_FROM(TRSP_FMRAM==trspmode) );
1038 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1043 static int win1_pan( struct fb_info *info )
1045 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1046 //struct fb_var_screeninfo *var1 = &info->var;
1047 struct fb_fix_screeninfo *fix1 = &info->fix;
1048 struct win0_par *par = info->par;
1052 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1056 addr = fix1->smem_start + par->y_offset;
1058 //fbprintk("info->screen_base = %8x ; fix1->smem_len = %d , addr = %8x\n",(u32)info->screen_base, fix1->smem_len, addr);
1060 LcdWrReg(inf, WIN1_YRGB_MST, addr);
1061 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1067 static int fb0_blank(int blank_mode, struct fb_info *info)
1069 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1071 if(inf->video_mode == 1)
1073 win1_blank(blank_mode, info);
1077 win0_blank(blank_mode, info);
1082 static int fb0_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1084 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1085 struct rk29fb_screen *screen = inf->cur_screen;
1086 u16 xpos = (var->nonstd>>8) & 0xfff;
1087 u16 ypos = (var->nonstd>>20) & 0xfff;
1088 u16 xlcd = screen->x_res;
1089 u16 ylcd = screen->y_res;
1091 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1095 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1096 0==var->xres || 0==var->yres || var->xres<16 ||
1097 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1099 printk(">>>>>> win1fb_check_var fail 1!!! \n");
1100 printk(">>>>>> 0==%d || 0==%d ", var->xres_virtual,var->yres_virtual);
1101 printk("0==%d || 0==%d || %d<16 || ", var->xres,var->yres,var->xres<16);
1102 printk("bits_per_pixel=%d \n", var->bits_per_pixel);
1106 if( (var->xoffset+var->xres)>var->xres_virtual ||
1107 (var->yoffset+var->yres)>var->yres_virtual )
1109 printk(">>>>>> win1fb_check_var fail 2!!! \n");
1110 printk(">>>>>> (%d+%d)>%d || ", var->xoffset,var->xres,var->xres_virtual);
1111 printk("(%d+%d)>%d || ", var->yoffset,var->yres,var->yres_virtual);
1112 printk("(%d+%d)>%d || (%d+%d)>%d \n", xpos,var->xres,xlcd,ypos,var->yres,ylcd);
1116 switch(var->bits_per_pixel)
1119 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1120 var->xres = (var->xres + 0x1) & (~0x1);
1121 var->xoffset = (var->xoffset) & (~0x1);
1124 var->bits_per_pixel = 32;
1132 static int fb0_set_par(struct fb_info *info)
1134 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1135 struct fb_var_screeninfo *var = &info->var;
1136 struct fb_fix_screeninfo *fix = &info->fix;
1137 struct rk29fb_screen *screen = inf->cur_screen;
1138 struct win0_par *par = info->par;
1141 //u32 offset=0, addr=0, map_size=0, smem_len=0;
1142 u32 offset=0, smem_len=0;
1144 u16 xres_virtual = var->xres_virtual; //virtual screen size
1146 u16 xpos_virtual = var->xoffset; //visiable offset in virtual screen
1147 u16 ypos_virtual = var->yoffset;
1149 //u16 xpos = (screen->x_res - var->xres)/2; //visiable offset in panel
1150 //u16 ypos = (screen->y_res - var->yres)/2;
1151 //u16 xsize = screen->x_res; //visiable size in panel
1152 //u16 ysize = screen->y_res;
1153 //u8 trspmode = TRSP_CLOSE;
1156 //fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1160 switch(var->bits_per_pixel)
1164 fix->line_length = 2 * xres_virtual;
1165 offset = (ypos_virtual*xres_virtual + xpos_virtual)*2;
1170 fix->line_length = 4 * xres_virtual;
1171 offset = (ypos_virtual*xres_virtual + xpos_virtual)*4;
1175 smem_len = fix->line_length * var->yres_virtual;
1176 //map_size = PAGE_ALIGN(smem_len);
1178 if (smem_len > fix->smem_len) // buffer need realloc
1180 printk("%s sorry!!! win1 buf is not enough\n",__FUNCTION__);
1183 par->y_offset = offset;
1184 par->addr_seted = 1;
1185 #if ANDROID_USE_THREE_BUFS
1186 if(0==new_frame_seted) {
1188 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1190 new_frame_seted = 0;
1193 if(inf->video_mode == 1)
1195 par->xpos = (screen->x_res - var->xres)/2; //visiable offset in panel
1196 par->ypos = (screen->y_res - var->yres)/2;
1197 par->xsize = screen->x_res; //visiable size in panel
1198 par->ysize = screen->y_res;
1205 par->xsize = screen->x_res;
1206 par->ysize = screen->y_res;
1213 static int fb0_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1215 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1216 struct fb_var_screeninfo *var1 = &info->var;
1217 //struct fb_fix_screeninfo *fix1 = &info->fix;
1218 struct win0_par *par = info->par;
1222 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1226 switch(var1->bits_per_pixel)
1229 var->xoffset = (var->xoffset) & (~0x1);
1230 offset = (var->yoffset*var1->xres_virtual + var->xoffset)*2;
1233 offset = (var->yoffset*var1->xres_virtual + var->xoffset)*4;
1239 par->y_offset = offset;
1241 if(inf->video_mode == 1)
1249 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1250 #if !ANDROID_USE_THREE_BUFS
1251 // flush end when wq_condition=1 in mcu panel, but not in rgb panel
1252 if(SCREEN_MCU == inf->cur_screen->type) {
1253 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1257 wait_event_interruptible_timeout(wq, wq_condition, HZ/20);
1263 static int fb0_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1265 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1266 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1272 case FB0_IOCTL_STOP_TIMER_FLUSH: //stop timer flush mcu panel after android is runing
1275 inf->mcu_usetimer = 0;
1284 static int fb1_blank(int blank_mode, struct fb_info *info)
1286 win0_blank(blank_mode, info);
1290 static int fb1_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1292 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1293 struct rk29fb_screen *screen = inf->cur_screen;
1295 u32 ScaleYRGBY=0x1000;
1296 u16 xpos = (var->nonstd>>8) & 0xfff; //offset in panel
1297 u16 ypos = (var->nonstd>>20) & 0xfff;
1298 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1299 u16 ysize = (var->grayscale>>20) & 0xfff;
1300 u16 xlcd = screen->x_res; //size of panel
1301 u16 ylcd = screen->y_res;
1304 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1305 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1306 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1307 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1309 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1313 if( 0==var->xres_virtual || 0==var->yres_virtual ||
1314 0==var->xres || 0==var->yres || var->xres<16 ||
1315 0==xsize || 0==ysize || xsize<16 ||
1316 ((16!=var->bits_per_pixel)&&(32!=var->bits_per_pixel)) )
1318 printk(">>>>>> win0fb_check_var fail 1!!! \n");
1319 printk("0==%d || 0==%d || 0==%d || 0==%d || %d<16 \n ||0==%d || 0==%d || %d<16 ||((16!=%d)&&(32!=%d)) \n",
1320 var->xres_virtual, var->yres_virtual, var->xres, var->yres, var->xres, xsize, ysize, xsize,
1321 var->bits_per_pixel, var->bits_per_pixel);
1325 if( (var->xoffset+var->xres)>var->xres_virtual ||
1326 (var->yoffset+var->yres)>var->yres_virtual ||
1327 (xpos+xsize)>xlcd || (ypos+ysize)>ylcd )
1329 printk(">>>>>> win0fb_check_var fail 2!!! \n");
1330 printk("(%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d || (%d+%d)>%d \n ",
1331 var->xoffset, var->xres, var->xres_virtual, var->yoffset, var->yres,
1332 var->yres_virtual, xpos, xsize, xlcd, ypos, ysize, ylcd);
1336 switch(var->nonstd&0x0f)
1339 switch(var->bits_per_pixel)
1342 var->xres_virtual = (var->xres_virtual + 0x1) & (~0x1);
1343 var->xres = (var->xres + 0x1) & (~0x1);
1344 var->xoffset = (var->xoffset) & (~0x1);
1347 var->bits_per_pixel = 32;
1350 var->nonstd &= ~0xc0; //not support I2P in this format
1353 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1354 var->xres = (var->xres + 0x3) & (~0x3);
1355 var->xoffset = (var->xoffset) & (~0x3);
1358 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1359 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1360 var->xres = (var->xres + 0x3) & (~0x3);
1361 var->yres = (var->yres + 0x1) & (~0x1);
1362 var->xoffset = (var->xoffset) & (~0x3);
1363 var->yoffset = (var->yoffset) & (~0x1);
1366 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1367 var->yres_virtual = (var->yres_virtual + 0x1) & (~0x1);
1368 var->xres = (var->xres + 0x3) & (~0x3);
1369 var->yres = (var->yres + 0x1) & (~0x1);
1370 var->xoffset = (var->xoffset) & (~0x3);
1371 var->yoffset = (var->yoffset) & (~0x1);
1372 var->nonstd &= ~0xc0; //not support I2P in this format
1376 var->xres_virtual = (var->xres_virtual + 0x3) & (~0x3);
1377 var->xres = (var->xres + 0x3) & (~0x3);
1378 var->xoffset = (var->xoffset) & (~0x3);
1379 var->nonstd &= ~0xc0; //not support I2P in this format
1382 printk(">>>>>> fb1 var->nonstd=%d is invalid! \n", var->nonstd);
1388 ScaleYRGBY = CalScaleW0(yres, ysize);
1390 if((ScaleYRGBY>0x8000) || (ScaleYRGBY<0x200))
1392 return -EINVAL; // multiple of scale down or scale up can't exceed 8
1398 static int fb1_set_par(struct fb_info *info)
1400 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1401 struct rk29fb_screen *screen = inf->cur_screen;
1402 struct fb_var_screeninfo *var = &info->var;
1403 struct fb_fix_screeninfo *fix = &info->fix;
1404 struct win0_par *par = info->par;
1407 u32 cblen=0, crlen=0, map_size=0, smem_len=0;
1409 //u32 xact = var->xres; /* visible resolution */
1410 //u32 yact = var->yres;
1411 u32 xvir = var->xres_virtual; /* virtual resolution */
1412 u32 yvir = var->yres_virtual;
1413 u32 xact_st = var->xoffset; /* offset from virtual to visible */
1414 u32 yact_st = var->yoffset; /* resolution */
1416 u16 xpos = (var->nonstd>>8) & 0xfff; //visiable pos in panel
1417 u16 ypos = (var->nonstd>>20) & 0xfff;
1418 u16 xsize = (var->grayscale>>8) & 0xfff; //visiable size in panel
1419 u16 ysize = (var->grayscale>>20) & 0xfff;
1421 //u32 ScaleYrgbX=0x1000,ScaleYrgbY=0x1000;
1422 //u32 ScaleCbrX=0x1000, ScaleCbrY=0x1000;
1424 u8 data_format = var->nonstd&0x0f;
1425 u32 win0_en = var->reserved[2];
1426 u32 y_addr = var->reserved[3]; //user alloc buf addr y
1427 u32 uv_addr = var->reserved[4];
1429 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1433 xpos = (xpos * screen->x_res) / inf->panel1_info.x_res;
1434 ypos = (ypos * screen->y_res) / inf->panel1_info.y_res;
1435 xsize = (xsize * screen->x_res) / inf->panel1_info.x_res;
1436 ysize = (ysize * screen->y_res) / inf->panel1_info.y_res;
1438 /* calculate y_offset,c_offset,line_length,cblen and crlen */
1439 switch (data_format)
1442 switch(var->bits_per_pixel)
1446 fix->line_length = 2 * xvir;
1447 par->y_offset = (yact_st*xvir + xact_st)*2;
1451 fix->line_length = 4 * xvir;
1452 par->y_offset = (yact_st*xvir + xact_st)*4;
1460 fix->line_length = xvir;
1461 cblen = crlen = (xvir*yvir)/2;
1462 par->y_offset = yact_st*xvir + xact_st;
1463 par->c_offset = yact_st*xvir + xact_st;
1467 fix->line_length = xvir;
1468 cblen = crlen = (xvir*yvir)/4;
1470 par->y_offset = yact_st*xvir + xact_st;
1471 par->c_offset = (yact_st/2)*xvir + xact_st;
1476 fix->line_length = xvir;
1477 par->y_offset = (yact_st/2)*2*xvir + (xact_st)*2;
1478 par->c_offset = (yact_st/2)*xvir + xact_st;
1479 cblen = crlen = (xvir*yvir)/4;
1484 fix->line_length = xvir;
1485 par->y_offset = yact_st*xvir + xact_st;
1486 par->c_offset = yact_st*2*xvir + xact_st*2;
1487 cblen = crlen = (xvir*yvir);
1493 smem_len = fix->line_length * yvir + cblen + crlen;
1494 map_size = PAGE_ALIGN(smem_len);
1496 fix->smem_start = y_addr;
1497 fix->smem_len = smem_len;
1498 fix->mmio_start = uv_addr;
1500 par->addr_seted = ((-1==(int)y_addr) || (0==(int)y_addr) || (win0_en==0)) ? 0 : 1;
1501 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);
1503 par->format = format;
1513 static int fb1_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1515 struct win0_par *par = info->par;
1516 // enable win0 after the win0 addr is seted
1522 int fb1_open(struct fb_info *info, int user)
1524 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1525 struct win0_par *par = info->par;
1527 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1530 par->addr_seted = 0;
1531 inf->video_mode = 1;
1534 printk(">>>>>> fb1 has opened! \n");
1538 win0_blank(FB_BLANK_POWERDOWN, info);
1543 int fb1_release(struct fb_info *info, int user)
1545 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1546 struct win0_par *par = info->par;
1547 struct fb_var_screeninfo *var0 = &info->var;
1549 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1553 inf->video_mode = 0;
1555 win1_blank(FB_BLANK_POWERDOWN, info);
1556 // wait for lcdc stop access memory
1560 info->screen_base = 0;
1561 info->fix.smem_start = 0;
1562 info->fix.smem_len = 0;
1563 // clean the var param
1564 memset(var0, 0, sizeof(struct fb_var_screeninfo));
1570 static int fb1_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1572 struct rk29fb_inf *inf = dev_get_drvdata(info->device);
1573 struct win0_par *par = info->par;
1574 void __user *argp = (void __user *)arg;
1576 fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1577 fbprintk("win0fb_ioctl cmd = %8x, arg = %8x \n", (u32)cmd, (u32)arg);
1583 case FB1_IOCTL_GET_PANEL_SIZE: //get panel size
1586 if(inf->fb1->var.rotate == 270) {
1587 panel_size[0] = inf->panel1_info.y_res; //inf->cur_screen->y_res; change for hdmi video size
1588 panel_size[1] = inf->panel1_info.x_res;
1590 panel_size[0] = inf->panel1_info.x_res;
1591 panel_size[1] = inf->panel1_info.y_res;
1594 if(copy_to_user(argp, panel_size, 8)) return -EFAULT;
1598 case FB1_IOCTL_SET_YUV_ADDR: //set y&uv address to register direct
1602 if (copy_from_user(yuv_phy, argp, 8))
1605 yuv_phy[0] += par->y_offset;
1606 yuv_phy[1] += par->c_offset;
1608 LcdWrReg(inf, WIN0_YRGB_MST, yuv_phy[0]);
1609 LcdWrReg(inf, WIN0_CBR_MST, yuv_phy[1]);
1610 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1611 // enable win0 after the win0 par is seted
1612 par->addr_seted = 1;
1613 if(par->par_seted) {
1614 if (par->mirror.c_offset) {
1615 ret = wait_event_interruptible_timeout(par->wait,
1616 (0 == par->mirror.c_offset), HZ/20);
1621 down_write(&par->sem);
1622 LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(1));
1624 par->mirror.y_offset = yuv_phy[0];
1625 par->mirror.c_offset = yuv_phy[1];
1626 //printk("0x%.8x 0x%.8x mirror\n", par->mirror.y_offset, par->mirror.c_offset);
1627 up_write(&par->sem);
1632 case FB1_IOCTL_SET_ROTATE: //change MCU panel scan direction
1633 fbprintk(">>>>>> change lcdc direction(%d) \n", (int)arg);
1642 static struct fb_ops fb1_ops = {
1643 .owner = THIS_MODULE,
1644 .fb_open = fb1_open,
1645 .fb_release = fb1_release,
1646 .fb_check_var = fb1_check_var,
1647 .fb_set_par = fb1_set_par,
1648 .fb_blank = fb1_blank,
1649 .fb_pan_display = fb1_pan_display,
1650 .fb_ioctl = fb1_ioctl,
1651 .fb_setcolreg = fb_setcolreg,
1652 .fb_fillrect = cfb_fillrect,
1653 .fb_copyarea = cfb_copyarea,
1654 .fb_imageblit = cfb_imageblit,
1657 static struct fb_ops fb0_ops = {
1658 .owner = THIS_MODULE,
1659 .fb_check_var = fb0_check_var,
1660 .fb_set_par = fb0_set_par,
1661 .fb_blank = fb0_blank,
1662 .fb_pan_display = fb0_pan_display,
1663 .fb_ioctl = fb0_ioctl,
1664 .fb_setcolreg = fb_setcolreg,
1665 .fb_fillrect = cfb_fillrect,
1666 .fb_copyarea = cfb_copyarea,
1667 .fb_imageblit = cfb_imageblit,
1668 //.fb_cursor = rk29_set_cursor,
1672 enable: 1, switch to tv or hdmi; 0, switch to lcd
1674 int FB_Switch_Screen( struct rk29fb_screen *screen, u32 enable )
1676 struct rk29fb_inf *inf = platform_get_drvdata(g_pdev);
1677 // struct rk29fb_info *mach_info = g_pdev->dev.platform_data;
1679 memcpy(&inf->panel2_info, screen, sizeof( struct rk29fb_screen ));
1681 if(enable)inf->cur_screen = &inf->panel2_info;
1682 else inf->cur_screen = &inf->panel1_info;
1684 /* Black out, because some display device need clock to standby */
1685 //LcdMskReg(inf, DSP_CTRL_REG1, m_BLACK_OUT, v_BLACK_OUT(1));
1686 // LcdMskReg(inf, SYS_CONFIG, m_W0_ENABLE, v_W0_ENABLE(0));
1687 // LcdMskReg(inf, SYS_CONFIG, m_W1_ENABLE, v_W1_ENABLE(0));
1688 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(1));
1689 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1692 if(inf->cur_screen->standby) inf->cur_screen->standby(1);
1693 // operate the display_on pin to power down the lcd
1694 set_lcd_pin(g_pdev, (enable==0));
1696 load_screen(inf->fb0, 0);
1699 fb1_set_par(inf->fb1);
1700 fb0_set_par(inf->fb0);
1701 LcdMskReg(inf, DSP_CTRL1, m_BLACK_MODE, v_BLACK_MODE(0));
1702 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1707 static irqreturn_t rk29fb_irq(int irq, void *dev_id)
1709 struct platform_device *pdev = (struct platform_device*)dev_id;
1710 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
1711 struct win0_par *par = (struct win0_par *)inf->fb1->par;
1715 //fbprintk(">>>>>> %s : %s \n", __FILE__, __FUNCTION__);
1717 LcdMskReg(inf, INT_STATUS, m_FRM_STARTCLEAR, v_FRM_STARTCLEAR(1));
1719 if(SCREEN_MCU == inf->cur_screen->type)
1721 inf->mcu_isrcnt = !inf->mcu_isrcnt;
1727 if(LcdReadBit(inf, MCU_TIMING_CTRL, m_MCU_HOLD_STATUS) && (inf->mcu_fmksync == 0))
1729 inf->mcu_fmksync = 1;
1730 if(inf->cur_screen->refresh)
1731 inf->cur_screen->refresh(REFRESH_END);
1732 inf->mcu_fmksync = 0;
1741 if(inf->mcu_needflush) {
1742 if(inf->cur_screen->refresh)
1743 inf->cur_screen->refresh(REFRESH_PRE);
1744 inf->mcu_needflush = 0;
1745 inf->mcu_isrcnt = 0;
1746 LcdSetRegBit(inf, MCU_TIMING_CTRL, m_MCU_HOLDMODE_FRAME_ST);
1748 if(inf->cur_screen->refresh)
1749 inf->cur_screen->refresh(REFRESH_END);
1753 #if ANDROID_USE_THREE_BUFS
1754 new_frame_seted = 1;
1757 if(waitqueue_active(&par->wait)) {
1758 down_write(&par->sem);
1759 if (par->mirror.c_offset == 0)
1760 printk("error: no new buffer to display\n");
1762 par->done.y_offset = par->displ.y_offset;
1763 par->done.c_offset = par->displ.c_offset;
1764 par->displ.y_offset = par->mirror.y_offset;
1765 par->displ.c_offset = par->mirror.c_offset;
1766 par->mirror.y_offset = 0;
1767 par->mirror.c_offset = 0;
1769 //printk("0x%.8x 0x%.8x displaying\n", par->displ.y_offset, par->displ.c_offset);
1770 //printk("0x%.8x 0x%.8x done\n", par->done.y_offset, par->done.c_offset);
1772 up_write(&par->sem);
1773 wake_up_interruptible(&par->wait);
1777 wake_up_interruptible(&wq);
1782 #ifdef CONFIG_HAS_EARLYSUSPEND
1784 struct suspend_info {
1785 struct early_suspend early_suspend;
1786 struct rk29fb_inf *inf;
1789 void suspend(struct early_suspend *h)
1791 struct suspend_info *info = container_of(h, struct suspend_info,
1794 struct rk29fb_inf *inf = info->inf;
1796 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1799 printk("inf==0, rk29fb_suspend fail! \n");
1803 set_lcd_pin(g_pdev, 0);
1805 if(inf->cur_screen->standby)
1807 fbprintk(">>>>>> power down the screen! \n");
1808 inf->cur_screen->standby(1);
1811 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(1));
1812 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(1));
1813 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1815 if(!inf->in_suspend)
1817 fbprintk(">>>>>> diable the lcdc clk! \n");
1820 clk_disable(inf->dclk);
1823 clk_disable(inf->aclk);
1826 inf->in_suspend = 1;
1831 void resume(struct early_suspend *h)
1833 struct suspend_info *info = container_of(h, struct suspend_info,
1836 struct rk29fb_inf *inf = info->inf;
1838 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1840 printk("inf==0, rk29fb_resume fail! \n");
1846 inf->in_suspend = 0;
1847 fbprintk(">>>>>> enable the lcdc clk! \n");
1849 clk_enable(inf->dclk);
1852 clk_enable(inf->aclk);
1856 LcdMskReg(inf, DSP_CTRL1, m_BLANK_MODE , v_BLANK_MODE(0));
1857 LcdMskReg(inf, SYS_CONFIG, m_STANDBY, v_STANDBY(0));
1858 LcdWrReg(inf, REG_CFG_DONE, 0x01);
1860 if(inf->cur_screen->standby)
1862 fbprintk(">>>>>> power on the screen! \n");
1863 inf->cur_screen->standby(0);
1866 set_lcd_pin(g_pdev, 1);
1867 memcpy((u8*)inf->preg, (u8*)&inf->regbak, 0xa4); //resume reg
1870 struct suspend_info suspend_info = {
1871 .early_suspend.suspend = suspend,
1872 .early_suspend.resume = resume,
1873 .early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB,
1877 static int __init rk29fb_probe (struct platform_device *pdev)
1879 struct rk29fb_inf *inf = NULL;
1880 struct resource *res = NULL;
1881 struct resource *mem = NULL;
1882 struct rk29fb_info *mach_info = NULL;
1883 struct rk29fb_screen *screen = NULL;
1884 struct win0_par* par = NULL;
1888 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
1890 *(volatile u32 *)(RK29_GRF_BASE+0xac) = ((*(volatile u32 *)(RK29_GRF_BASE+0xac)) & ~0x3FF) | 0x246;
1892 /* Malloc rk29fb_inf and set it to pdev for drvdata */
1893 fbprintk(">> Malloc rk29fb_inf and set it to pdev for drvdata \n");
1894 inf = kmalloc(sizeof(struct rk29fb_inf), GFP_KERNEL);
1897 dev_err(&pdev->dev, ">> inf kmalloc fail!");
1899 goto release_drvdata;
1901 memset(inf, 0, sizeof(struct rk29fb_inf));
1902 platform_set_drvdata(pdev, inf);
1904 mach_info = pdev->dev.platform_data;
1905 /* Fill screen info and set current screen */
1906 fbprintk(">> Fill screen info and set current screen \n");
1907 set_lcd_info(&inf->panel1_info, mach_info->lcd_info);
1908 inf->cur_screen = &inf->panel1_info;
1909 screen = inf->cur_screen;
1910 if(SCREEN_NULL==screen->type)
1912 dev_err(&pdev->dev, ">> Please select a display device! \n");
1914 goto release_drvdata;
1917 /* get virtual basic address of lcdc register */
1918 fbprintk(">> get virtual basic address of lcdc register \n");
1919 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lcdc reg");
1922 dev_err(&pdev->dev, "failed to get memory registers\n");
1924 goto release_drvdata;
1926 inf->reg_phy_base = res->start;
1927 inf->len = (res->end - res->start) + 1;
1928 mem = request_mem_region(inf->reg_phy_base, inf->len, pdev->name);
1931 dev_err(&pdev->dev, "failed to get memory region\n");
1933 goto release_drvdata;
1935 fbprintk("inf->reg_phy_base = 0x%08x, inf->len = %d \n", inf->reg_phy_base, inf->len);
1936 inf->reg_vir_base = ioremap(inf->reg_phy_base, inf->len);
1937 if (inf->reg_vir_base == NULL)
1939 dev_err(&pdev->dev, "ioremap() of registers failed\n");
1941 goto release_drvdata;
1943 inf->preg = (LCDC_REG*)inf->reg_vir_base;
1945 /* Prepare win1 info */
1946 fbprintk(">> Prepare win1 info \n");
1947 inf->fb0 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
1950 dev_err(&pdev->dev, ">> fb0 framebuffer_alloc fail!");
1953 goto release_win1fb;
1956 par = (struct win0_par*)inf->fb0->par;
1957 strcpy(inf->fb0->fix.id, "fb0");
1958 inf->fb0->fix.type = FB_TYPE_PACKED_PIXELS;
1959 inf->fb0->fix.type_aux = 0;
1960 inf->fb0->fix.xpanstep = 1;
1961 inf->fb0->fix.ypanstep = 1;
1962 inf->fb0->fix.ywrapstep = 0;
1963 inf->fb0->fix.accel = FB_ACCEL_NONE;
1964 inf->fb0->fix.visual = FB_VISUAL_TRUECOLOR;
1965 inf->fb0->fix.smem_len = 0;
1966 inf->fb0->fix.line_length = 0;
1967 inf->fb0->fix.smem_start = 0;
1969 inf->fb0->var.xres = screen->x_res;
1970 inf->fb0->var.yres = screen->y_res;
1971 inf->fb0->var.bits_per_pixel = 16;
1972 inf->fb0->var.xres_virtual = screen->x_res;
1973 inf->fb0->var.yres_virtual = screen->y_res;
1974 inf->fb0->var.width = screen->width;
1975 inf->fb0->var.height = screen->height;
1976 inf->fb0->var.pixclock = screen->pixclock;
1977 inf->fb0->var.left_margin = screen->left_margin;
1978 inf->fb0->var.right_margin = screen->right_margin;
1979 inf->fb0->var.upper_margin = screen->upper_margin;
1980 inf->fb0->var.lower_margin = screen->lower_margin;
1981 inf->fb0->var.vsync_len = screen->vsync_len;
1982 inf->fb0->var.hsync_len = screen->hsync_len;
1983 inf->fb0->var.red = def_rgb_16.red;
1984 inf->fb0->var.green = def_rgb_16.green;
1985 inf->fb0->var.blue = def_rgb_16.blue;
1986 inf->fb0->var.transp = def_rgb_16.transp;
1988 inf->fb0->var.nonstd = 0; //win1 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
1989 inf->fb0->var.grayscale = 0; //win1 transprent mode & value(mode<<8 + value)
1990 inf->fb0->var.activate = FB_ACTIVATE_NOW;
1991 inf->fb0->var.accel_flags = 0;
1992 inf->fb0->var.vmode = FB_VMODE_NONINTERLACED;
1994 inf->fb0->fbops = &fb0_ops;
1995 inf->fb0->flags = FBINFO_FLAG_DEFAULT;
1996 inf->fb0->pseudo_palette = par->pseudo_pal;
1997 inf->fb0->screen_base = 0;
1999 memset(par, 0, sizeof(struct win0_par));
2001 ret = fb_alloc_cmap(&inf->fb0->cmap, 256, 0);
2005 /* alloc win1 buf */
2006 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "win1 buf");
2009 dev_err(&pdev->dev, "failed to get win1 memory \n");
2011 goto release_win1fb;
2013 inf->fb0->fix.smem_start = res->start;
2014 inf->fb0->fix.smem_len = res->end - res->start;
2015 inf->fb0->screen_base = ioremap(res->start, inf->fb0->fix.smem_len);
2016 memset(inf->fb0->screen_base, 0, inf->fb0->fix.smem_len);
2018 /* Prepare win0 info */
2019 fbprintk(">> Prepare win0 info \n");
2020 inf->fb1 = framebuffer_alloc(sizeof(struct win0_par), &pdev->dev);
2023 dev_err(&pdev->dev, ">> fb1 framebuffer_alloc fail!");
2026 goto release_win0fb;
2029 par = (struct win0_par*)inf->fb1->par;
2031 strcpy(inf->fb1->fix.id, "fb1");
2032 inf->fb1->fix.type = FB_TYPE_PACKED_PIXELS;
2033 inf->fb1->fix.type_aux = 0;
2034 inf->fb1->fix.xpanstep = 1;
2035 inf->fb1->fix.ypanstep = 1;
2036 inf->fb1->fix.ywrapstep = 0;
2037 inf->fb1->fix.accel = FB_ACCEL_NONE;
2038 inf->fb1->fix.visual = FB_VISUAL_TRUECOLOR;
2039 inf->fb1->fix.smem_len = 0;
2040 inf->fb1->fix.line_length = 0;
2041 inf->fb1->fix.smem_start = 0;
2043 inf->fb1->var.xres = screen->x_res;
2044 inf->fb1->var.yres = screen->y_res;
2045 inf->fb1->var.bits_per_pixel = 16;
2046 inf->fb1->var.xres_virtual = screen->x_res;
2047 inf->fb1->var.yres_virtual = screen->y_res;
2048 inf->fb1->var.width = screen->width;
2049 inf->fb1->var.height = screen->height;
2050 inf->fb1->var.pixclock = screen->pixclock;
2051 inf->fb1->var.left_margin = screen->left_margin;
2052 inf->fb1->var.right_margin = screen->right_margin;
2053 inf->fb1->var.upper_margin = screen->upper_margin;
2054 inf->fb1->var.lower_margin = screen->lower_margin;
2055 inf->fb1->var.vsync_len = screen->vsync_len;
2056 inf->fb1->var.hsync_len = screen->hsync_len;
2057 inf->fb1->var.red = def_rgb_16.red;
2058 inf->fb1->var.green = def_rgb_16.green;
2059 inf->fb1->var.blue = def_rgb_16.blue;
2060 inf->fb1->var.transp = def_rgb_16.transp;
2062 inf->fb1->var.nonstd = 0; //win0 format & ypos & xpos (ypos<<20 + xpos<<8 + format)
2063 inf->fb1->var.grayscale = ((inf->fb1->var.yres<<20)&0xfff00000) + ((inf->fb1->var.xres<<8)&0xfff00);//win0 xsize & ysize
2064 inf->fb1->var.activate = FB_ACTIVATE_NOW;
2065 inf->fb1->var.accel_flags = 0;
2066 inf->fb1->var.vmode = FB_VMODE_NONINTERLACED;
2068 inf->fb1->fbops = &fb1_ops;
2069 inf->fb1->flags = FBINFO_FLAG_DEFAULT;
2070 inf->fb1->pseudo_palette = par->pseudo_pal;
2071 inf->fb1->screen_base = 0;
2073 memset(par, 0, sizeof(struct win0_par));
2075 init_rwsem(&par->sem);
2076 init_waitqueue_head(&par->wait);
2078 /* Init all lcdc and lcd before register_framebuffer. */
2079 /* because after register_framebuffer, the win1fb_check_par and winfb_set_par execute immediately */
2080 fbprintk(">> Init all lcdc and lcd before register_framebuffer \n");
2081 init_lcdc(inf->fb0);
2083 #ifdef CONFIG_CPU_FREQ
2084 // inf->freq_transition.notifier_call = rk29fb_freq_transition;
2085 // cpufreq_register_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2087 fbprintk("got clock\n");
2091 struct rk29_fb_setting_info fb_setting;
2092 if( OUT_P888==inf->cur_screen->face ) // set lcdc iomux
2094 fb_setting.data_num = 24;
2096 else if(OUT_P666 == inf->cur_screen->face )
2098 fb_setting.data_num = 18;
2102 fb_setting.data_num = 16;
2104 fb_setting.den_en = 1;
2105 fb_setting.vsync_en = 1;
2106 fb_setting.disp_on_en = 1;
2107 fb_setting.standby_en = 1;
2108 if( inf->cur_screen->mcu_usefmk )
2109 fb_setting.mcu_fmk_en =1;
2110 mach_info->io_init(&fb_setting);
2113 set_lcd_pin(pdev, 1);
2116 inf->mcu_usetimer = 1;
2117 inf->mcu_fmksync = 0;
2118 load_screen(inf->fb0, 1);
2120 /* Register framebuffer(fb0 & fb1) */
2121 fbprintk(">> Register framebuffer(fb0) \n");
2122 ret = register_framebuffer(inf->fb0);
2125 printk(">> fb0 register_framebuffer fail!\n");
2127 goto release_win0fb;
2129 fbprintk(">> Register framebuffer(fb1) \n");
2131 ret = register_framebuffer(inf->fb1);
2134 printk(">> fb1 register_framebuffer fail!\n");
2136 goto unregister_win1fb;
2139 #ifdef CONFIG_HAS_EARLYSUSPEND
2140 suspend_info.inf = inf;
2141 register_early_suspend(&suspend_info.early_suspend);
2144 /* get and request irq */
2145 fbprintk(">> get and request irq \n");
2146 irq = platform_get_irq(pdev, 0);
2148 dev_err(&pdev->dev, "no irq for device\n");
2150 goto unregister_win1fb;
2152 ret = request_irq(irq, rk29fb_irq, IRQF_DISABLED, pdev->name, pdev);
2154 dev_err(&pdev->dev, "cannot get irq %d - err %d\n", irq, ret);
2159 if( inf->cur_screen->mcu_usefmk && (mach_info->mcu_fmk_pin != -1) )
2161 ret = request_irq(gpio_to_irq(mach_info->mcu_fmk_pin), mcu_irqfmk, GPIOEdgelFalling, pdev->name, pdev);
2164 dev_err(&pdev->dev, "cannot get fmk irq %d - err %d\n", irq, ret);
2170 printk(" %s ok\n", __FUNCTION__);
2175 free_irq(irq, pdev);
2177 unregister_framebuffer(inf->fb0);
2180 framebuffer_release(inf->fb1);
2184 fb_dealloc_cmap(&inf->fb0->cmap);
2187 framebuffer_release(inf->fb0);
2190 if(inf && inf->reg_vir_base)
2191 iounmap(inf->reg_vir_base);
2193 release_mem_region(inf->reg_phy_base, inf->len);
2196 platform_set_drvdata(pdev, NULL);
2200 static int rk29fb_remove(struct platform_device *pdev)
2202 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2203 struct fb_info *info = NULL;
2205 struct rk29fb_info *mach_info = NULL;
2208 fbprintk(">>>>>> %s : %s\n", __FILE__, __FUNCTION__);
2211 printk("inf==0, rk29_fb_remove fail! \n");
2215 irq = platform_get_irq(pdev, 0);
2218 free_irq(irq, pdev);
2221 mach_info = pdev->dev.platform_data;
2222 if(mach_info->mcu_fmk_pin)
2224 free_irq(gpio_to_irq(mach_info->mcu_fmk_pin), pdev);
2227 set_lcd_pin(pdev, 0);
2231 fb1_blank(FB_BLANK_POWERDOWN, inf->fb1);
2233 fb0_blank(FB_BLANK_POWERDOWN, inf->fb0);
2236 //rk29fb_suspend(pdev, msg);
2237 // unmap memory and release framebuffer
2240 if (info->screen_base) {
2241 //dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2242 info->screen_base = 0;
2243 info->fix.smem_start = 0;
2244 info->fix.smem_len = 0;
2246 unregister_framebuffer(inf->fb1);
2247 framebuffer_release(inf->fb1);
2252 if (info->screen_base) {
2253 // dma_free_writecombine(NULL, PAGE_ALIGN(info->fix.smem_len),info->screen_base, info->fix.smem_start);
2254 info->screen_base = 0;
2255 info->fix.smem_start = 0;
2256 info->fix.smem_len = 0;
2258 unregister_framebuffer(inf->fb0);
2259 framebuffer_release(inf->fb0);
2263 #ifdef CONFIG_CPU_FREQ
2264 // cpufreq_unregister_notifier(&inf->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
2269 clk_disable(inf->clk);
2275 clk_disable(inf->dclk);
2281 platform_set_drvdata(pdev, NULL);
2286 static void rk29fb_shutdown(struct platform_device *pdev)
2288 struct rk29fb_inf *inf = platform_get_drvdata(pdev);
2290 //printk("----------------------------rk29fb_shutdown----------------------------\n");
2291 set_lcd_pin(pdev, 0);
2294 clk_disable(inf->dclk);
2298 clk_disable(inf->clk);
2302 static struct platform_driver rk29fb_driver = {
2303 .probe = rk29fb_probe,
2304 .remove = rk29fb_remove,
2307 .owner = THIS_MODULE,
2309 .shutdown = rk29fb_shutdown,
2312 static int __init rk29fb_init(void)
2314 return platform_driver_register(&rk29fb_driver);
2317 static void __exit rk29fb_exit(void)
2319 platform_driver_unregister(&rk29fb_driver);
2322 //subsys_initcall(rk29fb_init);
2324 module_init(rk29fb_init);
2325 module_exit(rk29fb_exit);
2328 MODULE_AUTHOR(" zyw@rock-chips.com");
2329 MODULE_DESCRIPTION("Driver for rk29 fb device");
2330 MODULE_LICENSE("GPL");