//set lcdc according the screen info static int rk3188_load_screen(struct rk_lcdc_device_driver *dev_drv, bool initscreen) { int ret = -EINVAL; int fps; u16 face = 0; struct rk3188_lcdc_device *lcdc_dev = container_of(dev_drv,struct rk3188_lcdc_device,driver); rk_screen *screen = dev_drv->cur_screen; u16 right_margin = screen->right_margin; u16 left_margin = screen->left_margin; u16 lower_margin = screen->lower_margin; u16 upper_margin = screen->upper_margin; u16 x_res = screen->x_res; u16 y_res = screen->y_res; spin_lock(&lcdc_dev->reg_lock); if(likely(lcdc_dev->clk_on)) { if(screen->type==SCREEN_MCU) { printk("MUC¡¡screen not supported now!\n"); return -EINVAL; } switch (screen->face) { case OUT_P565: face = OUT_P565; //dither down to rgb565 lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE | m_DITHER_DOWN_SEL,v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0) | v_DITHER_DOWN_SEL(1)); break; case OUT_P666: face = OUT_P666; //dither down to rgb666 lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE | m_DITHER_DOWN_SEL, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1) | v_DITHER_DOWN_SEL(1)); break; case OUT_D888_P565: face = OUT_P888; lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE | m_DITHER_DOWN_SEL, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0) | v_DITHER_DOWN_SEL(1)); break; case OUT_D888_P666: face = OUT_P888; lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE | m_DITHER_DOWN_SEL, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1) | v_DITHER_DOWN_SEL(1)); break; case OUT_P888: face = OUT_P888; break; default: printk("unsupported display output interface!\n"); break; } //use default overlay,set vsyn hsync den dclk polarity lcdc_msk_reg(lcdc_dev, DSP_CTRL0,m_DSP_OUT_FORMAT | m_HSYNC_POL | m_VSYNC_POL | m_DEN_POL |m_DCLK_POL,v_DSP_OUT_FORMAT(face) | v_HSYNC_POL(screen->pin_hsync) | v_VSYNC_POL(screen->pin_vsync) | v_DEN_POL(screen->pin_den) | v_DCLK_POL(screen->pin_dclk)); //set background color to black,set swap according to the screen panel,disable blank mode lcdc_msk_reg(lcdc_dev, DSP_CTRL1, m_BG_COLOR| m_DSP_BG_SWAP | m_DSP_RB_SWAP | m_DSP_RG_SWAP | m_DSP_DELTA_SWAP | m_DSP_DUMMY_SWAP | m_BLANK_EN, v_BG_COLOR(0x000000) | v_DSP_BG_SWAP(screen->swap_gb) | v_DSP_RB_SWAP(screen->swap_rb) | v_DSP_RG_SWAP(screen->swap_rg) | v_DSP_DELTA_SWAP(screen->swap_delta) | v_DSP_DUMMY_SWAP(screen->swap_dumy) | v_BLANK_EN(0) | v_BLACK_EN(0)); lcdc_writel(lcdc_dev,DSP_HTOTAL_HS_END,v_HSYNC(screen->hsync_len) | v_HORPRD(screen->hsync_len + left_margin + x_res + right_margin)); lcdc_writel(lcdc_dev,DSP_HACT_ST_END,v_HAEP(screen->hsync_len + left_margin + x_res) | v_HASP(screen->hsync_len + left_margin)); lcdc_writel(lcdc_dev,DSP_VTOTAL_VS_END, v_VSYNC(screen->vsync_len) | v_VERPRD(screen->vsync_len + upper_margin + y_res + lower_margin)); lcdc_writel(lcdc_dev,DSP_VACT_ST_END,v_VAEP(screen->vsync_len + upper_margin+y_res)| v_VASP(screen->vsync_len + screen->upper_margin)); } spin_unlock(&lcdc_dev->reg_lock); ret = clk_set_rate(lcdc_dev->dclk, screen->pixclock); if(ret) { dev_err(dev_drv->dev,"set lcdc%d dclk failed\n",lcdc_dev->id); } lcdc_dev->driver.pixclock = lcdc_dev->pixclock = div_u64(1000000000000llu, clk_get_rate(lcdc_dev->dclk)); fps = rk_fb_calc_fps(screen,lcdc_dev->pixclock); screen->ft = 1000/fps; printk("%s: dclk:%lu>>fps:%d ",lcdc_dev->driver.name,clk_get_rate(lcdc_dev->dclk),fps); if(screen->init) { screen->init(); } if(screen->sscreen_set) { screen->sscreen_set(screen,!initscreen); } dev_info(dev_drv->dev,"%s for lcdc%d ok!\n",__func__,lcdc_dev->id); return 0; }
static int rk30_load_screen(struct rk_lcdc_device_driver *dev_drv, bool initscreen) { int ret = -EINVAL; struct rk30_lcdc_device *lcdc_dev = container_of(dev_drv,struct rk30_lcdc_device,driver); rk_screen *screen = dev_drv->cur_screen; u64 ft; int fps; u16 face; u16 mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend; u16 right_margin = screen->right_margin; u16 lower_margin = screen->lower_margin; u16 x_res = screen->x_res, y_res = screen->y_res; // set the rgb or mcu spin_lock(&lcdc_dev->reg_lock); if(likely(lcdc_dev->clk_on)) { if(screen->type==SCREEN_MCU) { lcdc_msk_reg(lcdc_dev, MCU_CTRL, m_MCU_OUTPUT_SELECT,v_MCU_OUTPUT_SELECT(1)); // set out format and mcu timing mcu_total = (screen->mcu_wrperiod*150*1000)/1000000; if(mcu_total>31) mcu_total = 31; if(mcu_total<3) mcu_total = 3; mcu_rwstart = (mcu_total+1)/4 - 1; mcu_rwend = ((mcu_total+1)*3)/4 - 1; mcu_csstart = (mcu_rwstart>2) ? (mcu_rwstart-3) : (0); mcu_csend = (mcu_rwend>15) ? (mcu_rwend-1) : (mcu_rwend); //DBG(1,">> mcu_total=%d, mcu_rwstart=%d, mcu_csstart=%d, mcu_rwend=%d, mcu_csend=%d \n", // mcu_total, mcu_rwstart, mcu_csstart, mcu_rwend, mcu_csend); // set horizontal & vertical out timing right_margin = x_res/6; screen->pixclock = 150000000; //mcu fix to 150 MHz lcdc_msk_reg(lcdc_dev, MCU_CTRL,m_MCU_CS_ST | m_MCU_CS_END| m_MCU_RW_ST | m_MCU_RW_END | m_MCU_WRITE_PERIOD | m_MCU_HOLDMODE_SELECT | m_MCU_HOLDMODE_FRAME_ST, v_MCU_CS_ST(mcu_csstart) | v_MCU_CS_END(mcu_csend) | v_MCU_RW_ST(mcu_rwstart) | v_MCU_RW_END(mcu_rwend) | v_MCU_WRITE_PERIOD(mcu_total) | v_MCU_HOLDMODE_SELECT((SCREEN_MCU==screen->type)?(1):(0)) | v_MCU_HOLDMODE_FRAME_ST(0)); } switch (screen->face) { case OUT_P565: face = OUT_P565; lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0)); break; case OUT_P666: face = OUT_P666; lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1)); break; case OUT_D888_P565: face = OUT_P888; lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(0)); break; case OUT_D888_P666: face = OUT_P888; lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(1) | v_DITHER_DOWN_MODE(1)); break; case OUT_P888: face = OUT_P888; lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(1)); lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0)); break; default: lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_UP_EN, v_DITHER_UP_EN(0)); lcdc_msk_reg(lcdc_dev, DSP_CTRL0, m_DITHER_DOWN_EN | m_DITHER_DOWN_MODE, v_DITHER_DOWN_EN(0) | v_DITHER_DOWN_MODE(0)); face = screen->face; break; } //use default overlay,set vsyn hsync den dclk polarity lcdc_msk_reg(lcdc_dev, DSP_CTRL0,m_DISPLAY_FORMAT | m_HSYNC_POLARITY | m_VSYNC_POLARITY | m_DEN_POLARITY |m_DCLK_POLARITY,v_DISPLAY_FORMAT(face) | v_HSYNC_POLARITY(screen->pin_hsync) | v_VSYNC_POLARITY(screen->pin_vsync) | v_DEN_POLARITY(screen->pin_den) | v_DCLK_POLARITY(screen->pin_dclk)); //set background color to black,set swap according to the screen panel,disable blank mode lcdc_msk_reg(lcdc_dev, DSP_CTRL1, m_BG_COLOR | m_OUTPUT_RB_SWAP | m_OUTPUT_RG_SWAP | m_DELTA_SWAP | m_DUMMY_SWAP | m_BLANK_MODE,v_BG_COLOR(0x000000) | 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) | v_BLACK_MODE(0)); lcdc_writel(lcdc_dev, DSP_HTOTAL_HS_END,v_HSYNC(screen->hsync_len) | v_HORPRD(screen->hsync_len + screen->left_margin + x_res + right_margin)); lcdc_writel(lcdc_dev, DSP_HACT_ST_END, v_HAEP(screen->hsync_len + screen->left_margin + x_res) | v_HASP(screen->hsync_len + screen->left_margin)); lcdc_writel(lcdc_dev, DSP_VTOTAL_VS_END, v_VSYNC(screen->vsync_len) | v_VERPRD(screen->vsync_len + screen->upper_margin + y_res + lower_margin)); lcdc_writel(lcdc_dev, DSP_VACT_ST_END, v_VAEP(screen->vsync_len + screen->upper_margin+y_res)| v_VASP(screen->vsync_len + screen->upper_margin)); // let above to take effect lcdc_cfg_done(lcdc_dev); } spin_unlock(&lcdc_dev->reg_lock); ret = clk_set_rate(lcdc_dev->dclk, screen->pixclock); if(ret) { printk(KERN_ERR ">>>>>> set lcdc%d dclk failed\n",lcdc_dev->id); } lcdc_dev->driver.pixclock = lcdc_dev->pixclock = div_u64(1000000000000llu, clk_get_rate(lcdc_dev->dclk)); ft = (u64)(screen->upper_margin + screen->lower_margin + screen->y_res +screen->vsync_len)* (screen->left_margin + screen->right_margin + screen->x_res + screen->hsync_len)* (dev_drv->pixclock); // one frame time ,(pico seconds) fps = div64_u64(1000000000000llu,ft); screen->ft = 1000/fps; printk("%s: dclk:%lu>>fps:%d ",lcdc_dev->driver.name,clk_get_rate(lcdc_dev->dclk),fps); if(screen->init) { screen->init(); } printk("%s for lcdc%d ok!\n",__func__,lcdc_dev->id); return 0; }