mt8735 andorid7.0 lcm Icn6202驱动(lk)

#include
#include  
#include
#include
#include "lcm_drv.h"


static struct mt_i2c_t icn6202_i2c;
static LCM_UTIL_FUNCS lcm_util;
#define MDELAY(n) (lcm_util.mdelay(n))


#define FRAME_WIDTH  (1024)
#define FRAME_HEIGHT (600)


#define LCM_I2C_ID  I2C1
#define LCM_I2C_ADDR    0x58
#define LCM_I2C_MODE    ST_MODE
#define LCM_I2C_SPEED   100


#define GPIO_LCD_PWR_EN (GPIO64 | 0x80000000)
#define GPIO_LCD_BL_EN (GPIO63 | 0x80000000)
#define GPIO_LCD_ICN6202_EN (GPIO55 | 0x80000000)


#define SET_RESET_PIN(v) (lcm_util.set_reset_pin((v)))
#define UDELAY(n) (lcm_util.udelay(n))
#define MDELAY(n) (lcm_util.mdelay(n))






static void lcm_set_util_funcs(const LCM_UTIL_FUNCS *util)
{
    memcpy(&lcm_util, util, sizeof(LCM_UTIL_FUNCS));
}


static int icn6202_reg_i2c_write(kal_uint8 addr, kal_uint8 value)
{
kal_int32 ret_code = I2C_OK;
kal_uint8 write_data[2];
kal_uint16 len;


write_data[0]= addr;
write_data[1] = value;


icn6202_i2c.id = LCM_I2C_ID;
icn6202_i2c.addr = (LCM_I2C_ADDR>>1);
icn6202_i2c.mode = LCM_I2C_MODE;
icn6202_i2c.speed = LCM_I2C_SPEED;
len = 2;


ret_code = i2c_write(&icn6202_i2c, write_data, len);
if (ret_code<0)
printf("[LCM][ERROR] %s: %d\n", __func__, ret_code);


return ret_code;
}


#define ICN6202_REG_WRITE(add, data) icn6202_reg_i2c_write(add, data)


static void lcm_set_power_pin(u32 pin, u32 out)
{
mt_set_gpio_mode(pin, GPIO_MODE_GPIO);
mt_set_gpio_dir(pin, GPIO_DIR_OUT);
mt_set_gpio_out(pin, out);
}


static void init_icn6202_registers(void)

ICN6202_REG_WRITE(0x20, 0x00);
ICN6202_REG_WRITE(0x21, 0x58);
ICN6202_REG_WRITE(0x22, 0x24);
ICN6202_REG_WRITE(0x23, 0xa0);
ICN6202_REG_WRITE(0x24, 0x0a);
ICN6202_REG_WRITE(0x25, 0xa0);
ICN6202_REG_WRITE(0x26, 0x00);
ICN6202_REG_WRITE(0x27, 0x0c);
ICN6202_REG_WRITE(0x28, 0x02);
ICN6202_REG_WRITE(0x29, 0x17);




ICN6202_REG_WRITE(0x34, 0x80);
ICN6202_REG_WRITE(0x36, 0xa0);
ICN6202_REG_WRITE(0xb5, 0xa0);
ICN6202_REG_WRITE(0x5c, 0xff);
ICN6202_REG_WRITE(0x13, 0x10);
ICN6202_REG_WRITE(0x56, 0x90);
ICN6202_REG_WRITE(0x51, 0x20);


ICN6202_REG_WRITE(0x6b, 0x21);
ICN6202_REG_WRITE(0x69, 0x1d);




ICN6202_REG_WRITE(0xb6, 0x20);
ICN6202_REG_WRITE(0x09, 0x10);
}


static void lcm_get_params(LCM_PARAMS *params)
{
    memset(params, 0, sizeof(LCM_PARAMS));


    params->type = LCM_TYPE_DSI;
    params->width = FRAME_WIDTH;
    params->height = FRAME_HEIGHT;
    params->dsi.mode = SYNC_PULSE_VDO_MODE;// SYNC_PULSE_VDO_MODE;//BURST_VDO_MODE; //;
     
    // DSI
    /* Command mode setting */
    params->dsi.LANE_NUM = LCM_FOUR_LANE;
    //The following defined the fomat for data coming from LCD engine.
    
params->dsi.data_format.color_order = LCM_COLOR_ORDER_RGB;
params->dsi.data_format.trans_seq   = LCM_DSI_TRANS_SEQ_MSB_FIRST;
params->dsi.data_format.padding     = LCM_DSI_PADDING_ON_LSB;
    params->dsi.data_format.format =LCM_DSI_FORMAT_RGB888; //  LCM_DSI_FORMAT_RGB888; // LCM_DSI_FORMAT_RGB666; // 
        
    //params->dsi.cont_clock = 1;   
    params->dsi.packet_size=256;


// Video mode setting
params->dsi.intermediat_buffer_num = 2;  
      
    // Video mode setting
    params->dsi.PS =LCM_PACKED_PS_24BIT_RGB888;// LCM_PACKED_PS_24BIT_RGB888; //LCM_PACKED_PS_18BIT_RGB666;
    
    params->dsi.vertical_sync_active = 2;//10;
params->dsi.vertical_backporch = 23;//15;
params->dsi.vertical_frontporch = 12;//20;
params->dsi.vertical_active_line = FRAME_HEIGHT;


params->dsi.horizontal_sync_active = 10;//20;
params->dsi.horizontal_backporch = 160;//160;//80;
params->dsi.horizontal_frontporch = 160;//160;//80;
params->dsi.horizontal_active_pixel = FRAME_WIDTH;   
                                                       
   // params->dsi.PLL_CLOCK = 216;
#if 1
params->dsi.PLL_CLOCK = 156; //156;//260; //400; //260; //178;
params->dsi.pll_div1=1; // div1=0,1,2,3;div1_real=1,2,4,4 ----0: 546Mbps  1:273Mbps
params->dsi.pll_div2=0; // div2=0,1,2,3;div1_real=1,2,4,4
params->dsi.fbk_div =16;    // fref=26MHz, fvco=fref*(fbk_div+1)*2/(div1_real*div2_real)


/* ESD or noise interference recovery For video mode LCM only. */ // Send TE packet to LCM in a period of n frames and check the response.
params->dsi.lcm_int_te_monitor = 0;
params->dsi.lcm_int_te_period = 1; // Unit : frames


// Need longer FP for more opportunity to do int. TE monitor applicably.
if(params->dsi.lcm_int_te_monitor)
params->dsi.vertical_frontporch *= 2;


// Monitor external TE (or named VSYNC) from LCM once per 2 sec. (LCM VSYNC must be wired to baseband TE pin.)
params->dsi.lcm_ext_te_monitor = 0;
// Non-continuous clock
params->dsi.noncont_clock = 1;
params->dsi.noncont_clock_period = 2; // Unit : frames
#else
params->dsi.ssc_disable                         = 1;
params->dsi.cont_clock  = 1;
params->dsi.PLL_CLOCK = 156;
//params->dsi.clk_lp_per_line_enable    = 1;
params->dsi.edp_panel = 1;
#endif
}
static void lcm_init(void)
{
printf("lcm_init start\n"); 




  SET_RESET_PIN(0);
MDELAY(10);
SET_RESET_PIN(1);
MDELAY(20);




//lcm_set_power_pin(GPIO_LCD_PWR_EN,1);
//lcm_set_power_pin(GPIO_LCD_BL_EN,1);

lcm_set_power_pin(GPIO_LCD_ICN6202_EN,1);
init_icn6202_registers();
printf("lcm_init end\n");


}
static unsigned int lcm_compare_id(void)
{
    return 1;
}
static void lcm_suspend(void)
{
printf("[LK/LCM] lcm_suspend() enter\n");
}


static void lcm_resume(void)
{
MDELAY(300);


lcm_init(); 
}


LCM_DRIVER icn6202_wsvga_lvds_dsi_vdo_lcm_drv =
{



    .name             = "icn6202_dsi_lvds",
    .set_util_funcs   = lcm_set_util_funcs,
    .get_params       = lcm_get_params,
    .init             = lcm_init,
    .suspend          = lcm_suspend,
    .resume           = lcm_resume,
    .compare_id       = lcm_compare_id,    
};

你可能感兴趣的:(mt8735 andorid7.0 lcm Icn6202驱动(lk))